Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature/2.6.0-union' into featur…
Browse files Browse the repository at this point in the history
…e/2.6.0-union
  • Loading branch information
felix-zhaolei committed Dec 5, 2024
2 parents 2a902a1 + 7ac0d6e commit a4d2243
Show file tree
Hide file tree
Showing 19 changed files with 45 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public class AppleAuthOptions

public class ExtensionConfig
{
public string PrivateKey { get; set; }
public string TeamId { get; set; }
public string ClientId { get; set; }
public string KeyId { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using AElf;
using AElf.Cryptography;

namespace CAServer.Commons;

public static class SignatureKeyHelp
{
public static string CommonPrivateKeyForCallTx { get; set; } = CryptoHelper.GenerateKeyPair().PrivateKey.ToHex();
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ public static string GetSignature(string primaryKey, object data)
return GetSignature(primaryKey, rawData);
}

public static string GetRawData( object data)
{
return ThirdPartHelper.ConvertObjectToSortedString(data, SignatureField);
}

public static string GetSignature(string privateKey, string rawData)
{
var privateKeyByte = ByteArrayHelper.HexStringToByteArray(privateKey);
Expand Down
1 change: 0 additions & 1 deletion src/CAServer.Application/CAServerApplicationModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ public override void ConfigureServices(ServiceConfigurationContext context)
Configure<ClaimTokenWhiteListAddressesOptions>(configuration.GetSection("ClaimTokenWhiteListAddresses"));
Configure<ClaimTokenInfoOptions>(configuration.GetSection("ClaimTokenInfo"));
Configure<CmsConfigOptions>(configuration.GetSection("CmsConfig"));
Configure<ContractOptions>(configuration.GetSection("ContractOptions"));
Configure<EsIndexBlacklistOptions>(configuration.GetSection("EsIndexBlacklist"));
Configure<AwsThumbnailOptions>(configuration.GetSection("AWSThumbnail"));
Configure<ActivityOptions>(configuration.GetSection("ActivityOptions"));
Expand Down
8 changes: 3 additions & 5 deletions src/CAServer.Application/Common/ContractProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public class ContractProvider : IContractProvider, ISingletonDependency
private readonly ILogger<ContractProvider> _logger;
private readonly ClaimTokenInfoOptions _claimTokenInfoOption;
private readonly ISignatureProvider _signatureProvider;
private readonly ContractOptions _contractOptions;
private readonly IClusterClient _clusterClient;
private readonly IIndicatorScope _indicatorScope;
private readonly ContractServiceProxy _contractServiceProxy;
Expand All @@ -67,7 +66,7 @@ public class ContractProvider : IContractProvider, ISingletonDependency
public ContractProvider(IOptionsMonitor<ChainOptions> chainOptions, ILogger<ContractProvider> logger,
IClusterClient clusterClient,
ISignatureProvider signatureProvider, IOptionsSnapshot<ClaimTokenInfoOptions> claimTokenInfoOption,
IOptionsSnapshot<ContractOptions> contractOptions, IIndicatorScope indicatorScope,
IIndicatorScope indicatorScope,
ContractServiceProxy contractServiceProxy)
{
_chainOptions = chainOptions.CurrentValue;
Expand All @@ -77,7 +76,6 @@ public ContractProvider(IOptionsMonitor<ChainOptions> chainOptions, ILogger<Cont
_indicatorScope = indicatorScope;
_contractServiceProxy = contractServiceProxy;
_clusterClient = clusterClient;
_contractOptions = contractOptions.Value;
}

public async Task<TransactionResultDto> AuthorizeDelegateAsync(AssignProjectDelegateeDto assignProjectDelegateeDto)
Expand Down Expand Up @@ -111,7 +109,7 @@ private async Task<T> CallTransactionAsync<T>(string methodName, IMessage param,
var client = new AElfClient(chainInfo.BaseUrl);
await client.IsConnectedAsync();

string addressFromPrivateKey = client.GetAddressFromPrivateKey(_contractOptions.CommonPrivateKeyForCallTx);
string addressFromPrivateKey = client.GetAddressFromPrivateKey(SignatureKeyHelp.CommonPrivateKeyForCallTx);
var generateIndicator = _indicatorScope.Begin(MonitorTag.AelfClient,
MonitorAelfClientType.GenerateTransactionAsync.ToString());
var transaction =
Expand All @@ -120,7 +118,7 @@ private async Task<T> CallTransactionAsync<T>(string methodName, IMessage param,

_logger.LogDebug("Call tx methodName is: {methodName} param is: {transaction}", methodName, transaction);

var txWithSign = client.SignTransaction(_contractOptions.CommonPrivateKeyForCallTx, transaction);
var txWithSign = client.SignTransaction(SignatureKeyHelp.CommonPrivateKeyForCallTx, transaction);

var interIndicator = _indicatorScope.Begin(MonitorTag.AelfClient,
MonitorAelfClientType.ExecuteTransactionAsync.ToString());
Expand Down
6 changes: 0 additions & 6 deletions src/CAServer.Application/Options/ContractOptions.cs

This file was deleted.

1 change: 0 additions & 1 deletion src/CAServer.Application/Options/ThirdPartOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,5 @@ public MerchantItem GetOption(string merchantName)
public class MerchantItem
{
public string PublicKey { get; set; }
public string DidPrivateKey { get; set; }
public string ReceivingAddress { get; set; }
}
1 change: 1 addition & 0 deletions src/CAServer.Application/Search/ISearchService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ public AccountRecoverySearchService(INESTRepository<AccountRecoverIndex, Guid> n
IOptionsSnapshot<IndexSettingOptions> indexSettingOptions) : base(nestRepository)
{
_indexSettingOptions = indexSettingOptions.Value;
_businessAlertProvider = businessAlertProvider;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AElf;
using AElf.Client.Service;
using AElf.Indexing.Elasticsearch;
using CAServer.Common;
using CAServer.Commons;
using CAServer.Entities.Es;
using CAServer.Options;
using CAServer.Search;
using CAServer.Signature.Provider;
using CAServer.ThirdPart.Dtos;
using CAServer.ThirdPart.Dtos.Order;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -36,14 +39,17 @@ public class ThirdPartOrderProvider : IThirdPartOrderProvider, ISingletonDepende
private readonly INESTRepository<OrderSettlementIndex, Guid> _orderSettlementRepository;
private readonly IObjectMapper _objectMapper;
private readonly IOptionsMonitor<ThirdPartOptions> _thirdPartOptions;

private readonly ISignatureProvider _signatureProvider;
private readonly ChainOptions _chainOptions;

public ThirdPartOrderProvider(
INESTRepository<RampOrderIndex, Guid> orderRepository,
IObjectMapper objectMapper,
IOptionsMonitor<ThirdPartOptions> thirdPartOptions,
INESTRepository<NftOrderIndex, Guid> nftOrderRepository,
ILogger<ThirdPartOrderProvider> logger, INESTRepository<OrderStatusInfoIndex, string> orderStatusInfoRepository,
INESTRepository<OrderSettlementIndex, Guid> orderSettlementRepository)
INESTRepository<OrderSettlementIndex, Guid> orderSettlementRepository, ISignatureProvider signatureProvider,
IOptionsSnapshot<ChainOptions> chainOptions)
{
_orderRepository = orderRepository;
_objectMapper = objectMapper;
Expand All @@ -52,6 +58,8 @@ public ThirdPartOrderProvider(
_orderStatusInfoRepository = orderStatusInfoRepository;
_orderSettlementRepository = orderSettlementRepository;
_thirdPartOptions = thirdPartOptions;
_signatureProvider = signatureProvider;
_chainOptions = chainOptions.Value;
}

public async Task<RampOrderIndex> GetThirdPartOrderIndexAsync(string orderId)
Expand Down Expand Up @@ -333,12 +341,19 @@ private void MergeOrderStatusSection(PagedResultDto<OrderDto> orderPager,
}


public void SignMerchantDto(NftMerchantBaseDto input)
public async void SignMerchantDto(NftMerchantBaseDto input)
{
var merchantOption = _thirdPartOptions.CurrentValue.Merchant.GetOption(input.MerchantName);
AssertHelper.NotEmpty(merchantOption?.DidPrivateKey, "Merchant {Merchant} did private key empty",
input.MerchantName);
input.Signature = MerchantSignatureHelper.GetSignature(merchantOption?.DidPrivateKey, input);
if (!_chainOptions.ChainInfos.TryGetValue(CommonConstant.MainChainId, out var chainInfo))
{
return;
}

var client = new AElfClient(chainInfo.BaseUrl);
await client.IsConnectedAsync();
var ownAddress = client.GetAddressFromPubKey(chainInfo.PublicKey);
var txWithSign = await _signatureProvider.SignTxMsg(ownAddress, MerchantSignatureHelper.GetRawData(input));

input.Signature = ByteStringHelper.FromHexString(txWithSign).ToString();
}

public void VerifyMerchantSignature(NftMerchantBaseDto input)
Expand Down
4 changes: 0 additions & 4 deletions src/CAServer.BackGround/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@
"Merchants": {
"SymbolMarket": {
"PublicKey": "xxx",
"DidPrivateKey": "xxx",
"DefaultReceivingAddress": ""
}
}
Expand Down Expand Up @@ -139,9 +138,6 @@
"Settings": {
"Abp.Account.IsSelfRegistrationEnabled": false
},
"ContractOptions": {
"CommonPrivateKeyForCallTx": "***"
},
"Transaction": {
"SendToChainId": "AELF",
"DelayTime": 2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,13 @@ public class ChainHeightService : IChainHeightService, ISingletonDependency
private readonly ILogger<ChainHeightService> _logger;
private readonly IDistributedCache<ChainHeightCache> _distributedCache;
private readonly ChainOptions _chainOptions;
private readonly ContractOptions _contractOptions;

public ChainHeightService(ILogger<ChainHeightService> logger, IDistributedCache<ChainHeightCache> distributedCache,
IOptions<ChainOptions> chainOptions,
IOptions<ContractOptions> contractOptions)
IOptions<ChainOptions> chainOptions)
{
_logger = logger;
_distributedCache = distributedCache;
_chainOptions = chainOptions.Value;
_contractOptions = contractOptions.Value;
}

public async Task SetChainHeightAsync()
Expand Down Expand Up @@ -98,11 +95,11 @@ private async Task<T> CallTransactionAsync<T>(string methodName, IMessage param,
var client = new AElfClient(chainInfo.BaseUrl);
await client.IsConnectedAsync();

var addressFromPrivateKey = client.GetAddressFromPrivateKey(_contractOptions.CommonPrivateKeyForCallTx);
var addressFromPrivateKey = client.GetAddressFromPrivateKey(SignatureKeyHelp.CommonPrivateKeyForCallTx);
var transaction =
await client.GenerateTransactionAsync(addressFromPrivateKey, contractAddress, methodName, param);

var txWithSign = client.SignTransaction(_contractOptions.CommonPrivateKeyForCallTx, transaction);
var txWithSign = client.SignTransaction(SignatureKeyHelp.CommonPrivateKeyForCallTx, transaction);
var result = await client.ExecuteTransactionAsync(new ExecuteTransactionDto
{
RawTransaction = txWithSign.ToByteArray().ToHex()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,13 @@ public class SyncTokenService : ISyncTokenService, ISingletonDependency
private readonly ContractServiceOptions _contractServiceOptions;
private readonly PayRedPackageAccount _packageAccount;
private readonly ILogger<SyncTokenService> _logger;
private readonly ContractOptions _contractOptions;
private readonly INESTRepository<FreeMintNftSyncIndex, string> _freeMintNftSyncRepository;
private readonly IDistributedCache<ChainHeightCache> _distributedCache;
private readonly IndexOptions _indexOptions;

public SyncTokenService(ISignatureProvider signatureProvider,
IOptionsSnapshot<ChainOptions> chainOptions,
IOptionsSnapshot<ContractServiceOptions> contractGrainOptions,
IOptionsSnapshot<ContractOptions> contractOptions,
IOptionsSnapshot<IndexOptions> indexOptions,
IOptionsSnapshot<PayRedPackageAccount> packageAccount, ILogger<SyncTokenService> logger,
INESTRepository<FreeMintNftSyncIndex, string> freeMintNftSyncRepository,
Expand All @@ -59,7 +57,6 @@ public SyncTokenService(ISignatureProvider signatureProvider,
_chainOptions = chainOptions.Value;
_contractServiceOptions = contractGrainOptions.Value;
_packageAccount = packageAccount.Value;
_contractOptions = contractOptions.Value;
_indexOptions = indexOptions.Value;
}

Expand Down Expand Up @@ -258,14 +255,14 @@ private async Task<T> CallTransactionAsync<T>(string methodName, IMessage param,
var client = new AElfClient(chainInfo.BaseUrl);
await client.IsConnectedAsync();

string addressFromPrivateKey = client.GetAddressFromPrivateKey(_contractOptions.CommonPrivateKeyForCallTx);
string addressFromPrivateKey = client.GetAddressFromPrivateKey(SignatureKeyHelp.CommonPrivateKeyForCallTx);

var transaction =
await client.GenerateTransactionAsync(addressFromPrivateKey, contractAddress, methodName, param);
_logger.LogDebug("[SyncToken] Call tx methodName is: {methodName} param is: {transaction}", methodName,
transaction);

var txWithSign = client.SignTransaction(_contractOptions.CommonPrivateKeyForCallTx, transaction);
var txWithSign = client.SignTransaction(SignatureKeyHelp.CommonPrivateKeyForCallTx, transaction);

var result = await client.ExecuteTransactionAsync(new ExecuteTransactionDto
{
Expand Down
3 changes: 0 additions & 3 deletions src/CAServer.ContractEventHandler/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,6 @@
"SignatureServer": {
"BaseUrl": "http://127.0.0.1:18080/api/app/signature"
},
"ContractOptions": {
"CommonPrivateKeyForCallTx": "aee9944b684505b51c2eefc54b6735453160a74f27c158df65d2783fafa81e57"
},
"ElasticUris": {
"Uris": [
"http://127.0.0.1:9200"
Expand Down
3 changes: 0 additions & 3 deletions src/CAServer.EntityEventHandler/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@
"SyncOriginChainId": {
"CheckUserRegistrationTimestamp": 2694597053000
},
"ContractOptions": {
"CommonPrivateKeyForCallTx": "36bc3f264aa340d44aada5759a5a86aac6d734f19932397e551d9e69edffe0d2"
},
"MessagePush": {
"BaseUrl": "http://192.168.66.240:5577",
"AppId": "PortKey",
Expand Down
8 changes: 0 additions & 8 deletions src/CAServer.HttpApi.Host/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@
"CrossChainContractAddress": "2SQ9LeGZYSWmfJcYuQkDQxgd3HzwjamAaaL4Tge2eFSXw2cseq",
"RedPackageContractAddress": "2sFCkQs61YKVkHpN3AT7887CLfMvzzXnMkNYYM431RK5tbKQS9",
"PublicKey": "0438ad713d76220ddfdac35e2b978f645cf254946d310b0e891201a7d8d36ef3341077d8a40b2fd79b1cfa91b3f3d675933d2ef761af9fa693cf2e36903404a32e",
"PrivateKey": "36bc3f264aa340d44aada5759a5a86aac6d734f19932397e551d9e69edffe0d2",
"IsMainChain": true
},
"tDVW": {
Expand All @@ -180,7 +179,6 @@
"CrossChainContractAddress": "2snHc8AMh9QMbCAa7XXmdZZVM5EBZUUPDdLjemwUJkBnL6k8z9",
"RedPackageContractAddress": "2d9wJKt3a2xszgYiDTPBRPZpKttU58uL8CvUvZxhXqsdfV1SGK",
"PublicKey": "0438ad713d76220ddfdac35e2b978f645cf254946d310b0e891201a7d8d36ef3341077d8a40b2fd79b1cfa91b3f3d675933d2ef761af9fa693cf2e36903404a32e",
"PrivateKey": "36bc3f264aa340d44aada5759a5a86aac6d734f19932397e551d9e69edffe0d2",
"IsMainChain": false
}
}
Expand Down Expand Up @@ -282,7 +280,6 @@
"RedirectUrl": "https://portkey-website-dev.vercel.app/apple-auth",
"BingoRedirectUrl": "https://portkey-bingo-game-sand.vercel.app",
"ExtensionConfig": {
"PrivateKey": "MIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgboqIuiK64B0UdWv8\nA2H1N9Sud2ckv0hUBs6gRMm69ZqgCgYIKoZIzj0DAQehRANCAAT8VPtX//8Vsygp\n9tILGbB31ItuexZfF4oPM3yg2nyV0OANIt2ySOdyvvBUQqjR/0h9DCMCoEZwvSCL\nMTKIga+Y",
"TeamId": "956XWQ54U7",
"ClientId": "did.portkey",
"KeyId": "VHLNFZRS9F"
Expand Down Expand Up @@ -326,7 +323,6 @@
"Merchants": {
"SymbolMarket": {
"PublicKey": "042dc50fd7d211f16bf4ad870f7790d4f9d98170f3712038c45830947f7d96c691ef2d1ab4880eeeeafb63ab77571be6cbe6bed89d5f89844b0fb095a7015713c8",
"DidPrivateKey": "5945c176c4269dc2aa7daf7078bc63b952832e880da66e5f2237cdf79bc59c5f",
"DefaultReceivingAddress": ""
}
}
Expand Down Expand Up @@ -392,7 +388,6 @@
},
"ClaimTokenInfo": {
"ChainId": "AELF",
"PrivateKey": "3a3bf1c63ae8bcc855890e9b09585b93d18a3402d84b47102fd53b4a5b78dcac",
"ClaimTokenAddress": "2UM9eusxdRyCztbmMZadGXzwgwKfFdk8pF4ckw58D769ehaPSR",
"ExpireTime": 1,
"ClaimTokenAmount": 10000000000,
Expand Down Expand Up @@ -433,9 +428,6 @@
"SignatureServer": {
"BaseUrl": "http://192.168.66.203:6001/api/app/signature"
},
"ContractOptions": {
"CommonPrivateKeyForCallTx": ""
},
"EsIndexBlacklist": {
"Indexes": [
"guardianindex",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ private IOptionsSnapshot<AppleAuthOptions> GetMockAppleAuthOptions()
{
ClientId = "test",
KeyId = "test",
PrivateKey = pkcs8PrivateKey,
TeamId = "test"
}
});
Expand Down
2 changes: 0 additions & 2 deletions test/CAServer.Application.Tests/AppleAuth/AppleAuthTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ public async Task Receive_Invalid_Params_Test()
UnifyRedirectUrl = string.Empty,
ExtensionConfig = new ExtensionConfig
{
PrivateKey = string.Empty,
TeamId = string.Empty,
ClientId = string.Empty,
KeyId = string.Empty
Expand Down Expand Up @@ -205,7 +204,6 @@ private IOptions<AppleAuthOptions> GetMockAppleAuthOptions()
{
ClientId = "test",
KeyId = "test",
PrivateKey = pkcs8PrivateKey,
TeamId = "test"
}
});
Expand Down
12 changes: 0 additions & 12 deletions test/CAServer.Application.Tests/ChainInfo/ChainInfoTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ protected override void AfterAddApplication(IServiceCollection services)
{
base.AfterAddApplication(services);
services.AddSingleton(MockChainOptions());
services.AddSingleton(GetContractOption());
services.AddSingleton(GetSignatureServerOptions());
}

Expand Down Expand Up @@ -123,17 +122,6 @@ private IOptions<ChainOptions> MockChainOptions()
return mockOptions.Object;
}

private IOptionsSnapshot<ContractOptions> GetContractOption()
{
var mockOptionsSnapshot = new Mock<IOptionsSnapshot<ContractOptions>>();
mockOptionsSnapshot.Setup(t => t.Value).Returns(new ContractOptions()
{
CommonPrivateKeyForCallTx = "aee9944b684505b51c2eefc54b6735453160a74f27c158df65d2783fafa81e57"
});

return mockOptionsSnapshot.Object;
}

private IOptionsSnapshot<SignatureServerOptions> GetSignatureServerOptions()
{
var options = new Mock<IOptionsSnapshot<SignatureServerOptions>>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ protected static IOptionsMonitor<ThirdPartOptions> MockThirdPartOptions()
{
PublicKey =
"042dc50fd7d211f16bf4ad870f7790d4f9d98170f3712038c45830947f7d96c691ef2d1ab4880eeeeafb63ab77571be6cbe6bed89d5f89844b0fb095a7015713c8",
DidPrivateKey = "5945c176c4269dc2aa7daf7078bc63b952832e880da66e5f2237cdf79bc59c5f"
}
}
}
Expand Down

0 comments on commit a4d2243

Please sign in to comment.