-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #852 from Portkey-Wallet/feature/tg-login-opt
TG login process Optimization
- Loading branch information
Showing
27 changed files
with
4,647 additions
and
3,578 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/CAServer.Application.Contracts/CAAccount/Dtos/ManagerCacheDto.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace CAServer.CAAccount.Dtos; | ||
|
||
public class ManagerCacheDto | ||
{ | ||
public string CaHash { get; set; } | ||
public string CaAddress { get; set; } | ||
} |
7 changes: 7 additions & 0 deletions
7
src/CAServer.Application.Contracts/CAAccount/Dtos/ManagerDto.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace CAServer.CAAccount.Dtos; | ||
|
||
public class ManagerDto | ||
{ | ||
public string Address { get; set; } | ||
public string ExtraData { get; set; } | ||
} |
6 changes: 6 additions & 0 deletions
6
src/CAServer.Application.Contracts/CAAccount/Dtos/ProverResponse.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace CAServer.CAAccount.Dtos; | ||
|
||
public class ProverResponse | ||
{ | ||
public bool Valid { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/CAServer.Application.Contracts/CAAccount/Dtos/VerificationDocInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using AElf.Types; | ||
|
||
namespace CAServer.CAAccount.Dtos; | ||
|
||
public class VerificationDocInfo | ||
{ | ||
public string GuardianType { get; set; } | ||
public Hash IdentifierHash { get; set; } | ||
public string VerificationTime { get; set; } | ||
public Address VerifierAddress { get; set; } | ||
public string Salt { get; set; } | ||
public string OperationType { get; set; } | ||
} |
17 changes: 17 additions & 0 deletions
17
src/CAServer.Application.Contracts/CAAccount/Enums/OperationTypeInContract.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace CAServer.CAAccount.Enums; | ||
|
||
public enum OperationTypeInContract | ||
{ | ||
Unknown = 0, | ||
CreateCAHolder = 1, | ||
SocialRecovery = 2, | ||
AddGuardian = 3, | ||
RemoveGuardian = 4, | ||
UpdateGuardian = 5, | ||
RemoveOtherManagerInfo = 6, | ||
SetLoginAccount = 7, | ||
Approve = 8, | ||
ModifyTransferLimit = 9, | ||
GuardianApproveTransfer = 10, | ||
UnSetLoginAccount = 11, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/CAServer.Application.Contracts/CAAccount/IPreValidationProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using CAServer.Account; | ||
using CAServer.CAAccount.Dtos; | ||
|
||
namespace CAServer.CAAccount; | ||
|
||
public interface IPreValidationProvider | ||
{ | ||
public Task<bool> ValidateSocialRecovery(RequestSource source, string caHash, | ||
string chainId, string manager, List<GuardianInfo> guardiansApproved, List<ManagerDto> existedManagers); | ||
|
||
public Task SaveManagerInCache(string manager, string caHash, string caAddress); | ||
|
||
public Task<ManagerCacheDto> GetManagerFromCache(string manager); | ||
} |
9 changes: 9 additions & 0 deletions
9
src/CAServer.Application.Contracts/CAAccount/PreValidationType.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace CAServer.CAAccount; | ||
|
||
public enum PreValidationType | ||
{ | ||
Signature = 0, | ||
ZkLogin = 1, | ||
TonWallet = 2, | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
src/CAServer.Application.Contracts/CAAccount/RequestSource.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace CAServer.CAAccount; | ||
|
||
public enum RequestSource | ||
{ | ||
UnKnown = 0, | ||
Android = 1, | ||
Ios = 2, | ||
Web = 3, | ||
Sdk = 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6,198 changes: 2,841 additions & 3,357 deletions
6,198
src/CAServer.Application.Contracts/Contracts/CaContract.g.cs
Large diffs are not rendered by default.
Oops, something went wrong.
244 changes: 136 additions & 108 deletions
244
src/CAServer.Application.Contracts/Contracts/CaContractImpl.c.cs
Large diffs are not rendered by default.
Oops, something went wrong.
1,282 changes: 1,186 additions & 96 deletions
1,282
src/CAServer.Application.Contracts/Contracts/CaContractImpl.g.cs
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/CAServer.Application/CAAccount/Provider/PreValidation/IPreValidationStrategy.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System.Threading.Tasks; | ||
using CAServer.Account; | ||
using CAServer.Dtos; | ||
|
||
namespace CAServer.CAAccount.Provider; | ||
|
||
public interface IPreValidationStrategy | ||
{ | ||
public PreValidationType Type { get; } | ||
|
||
public bool ValidateParameters(GuardianInfo guardian); | ||
|
||
public Task<bool> PreValidateGuardian(string chainId, string caHash, string manager, GuardianInfo guardian); | ||
} |
99 changes: 99 additions & 0 deletions
99
src/CAServer.Application/CAAccount/Provider/PreValidation/PreValidationProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using CAServer.Account; | ||
using CAServer.CAAccount.Dtos; | ||
using Microsoft.Extensions.Caching.Distributed; | ||
using Microsoft.Extensions.Logging; | ||
using Newtonsoft.Json; | ||
using Volo.Abp; | ||
using Volo.Abp.Auditing; | ||
using Volo.Abp.Caching; | ||
|
||
namespace CAServer.CAAccount.Provider; | ||
|
||
[RemoteService(false)] | ||
[DisableAuditing] | ||
public class PreValidationProvider : CAServerAppService, IPreValidationProvider | ||
{ | ||
private readonly IEnumerable<IPreValidationStrategy> _preValidationStrategies; | ||
private readonly IDistributedCache<string> _distributedCache; | ||
private readonly ILogger<PreValidationProvider> _logger; | ||
|
||
public PreValidationProvider(IEnumerable<IPreValidationStrategy> preValidationStrategies, | ||
IDistributedCache<string> distributedCache, | ||
ILogger<PreValidationProvider> logger) | ||
{ | ||
_preValidationStrategies = preValidationStrategies; | ||
_distributedCache = distributedCache; | ||
_logger = logger; | ||
} | ||
|
||
public async Task<bool> ValidateSocialRecovery(RequestSource source, string caHash, | ||
string chainId, string manager, List<GuardianInfo> guardiansApproved, List<ManagerDto> existedManagers) | ||
{ | ||
if (!RequestSource.Sdk.Equals(source)) | ||
{ | ||
return true; | ||
} | ||
var sw = new Stopwatch(); | ||
sw.Start(); | ||
//1 manager check | ||
if (!existedManagers.IsNullOrEmpty() && existedManagers.Any(mg => mg.Address.Equals(manager))) | ||
{ | ||
_logger.LogWarning("manager exists error. chainId:{0} caHash:{1} manager:{2}", chainId, caHash, manager); | ||
return false; | ||
} | ||
//2 guardian check | ||
foreach (var guardianInfo in guardiansApproved) | ||
{ | ||
foreach (var preValidationStrategy in _preValidationStrategies) | ||
{ | ||
if (!preValidationStrategy.ValidateParameters(guardianInfo)) | ||
{ | ||
continue; | ||
} | ||
|
||
var result = await preValidationStrategy.PreValidateGuardian(chainId, caHash, manager, guardianInfo); | ||
if (result) | ||
{ | ||
continue; | ||
} | ||
|
||
_logger.LogInformation("preValidationStrategy failed type:{0} chainId:{1} caHash:{2} manager:{3} guardianInfo:{4}", | ||
preValidationStrategy.Type, chainId, caHash, manager, JsonConvert.SerializeObject(guardianInfo)); | ||
return false; | ||
} | ||
} | ||
sw.Stop(); | ||
_logger.LogInformation("ValidateSocialRecovery cost:{0}ms", sw.ElapsedMilliseconds); | ||
return true; | ||
} | ||
|
||
public async Task SaveManagerInCache(string manager, string caHash, string caAddress) | ||
{ | ||
var managerCacheDto = new ManagerCacheDto() | ||
{ | ||
CaHash = caHash, | ||
CaAddress = caAddress | ||
}; | ||
await _distributedCache.SetAsync(GetCacheKey(manager), JsonConvert.SerializeObject(managerCacheDto), new DistributedCacheEntryOptions { AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(1) }); | ||
} | ||
|
||
public async Task<ManagerCacheDto> GetManagerFromCache(string manager) | ||
{ | ||
var result = await _distributedCache.GetAsync(GetCacheKey(manager)); | ||
if (result.IsNullOrEmpty()) | ||
{ | ||
return null; | ||
} | ||
return JsonConvert.DeserializeObject<ManagerCacheDto>(result); | ||
} | ||
|
||
private string GetCacheKey(string manager) | ||
{ | ||
return "Portkey:SocialRecover:" + manager; | ||
} | ||
} |
Oops, something went wrong.