public void Initialize() { string file = PoolUtils.GenerateGenesisFile(); _filesCreated.Add(file); _pool = IndyDotNet.Pool.Factory.GetPool("AllPaymentsTestsPool", file); _pool.Create(); _pool.Open(); WalletConfig config = new WalletConfig() { Id = "AllPaymentsTestWalletId" }; WalletCredentials credentials = new WalletCredentials() { Key = "8dvfYSt5d1taSd6yJdpjq4emkwsPDDLYxkNFysFD2cZY", KeyDerivationMethod = KeyDerivationMethod.RAW }; _wallet = IndyDotNet.Wallet.Factory.GetWallet(config, credentials); _wallet.Create(); _wallet.Open(); }
public async Task ConcurrentWalletAccess() { var walletService = new DefaultWalletService(); var config = new WalletConfiguration { Id = Guid.NewGuid().ToString() }; var creds = new WalletCredentials { Key = "1" }; await walletService.CreateWalletAsync(config, creds); Task <Wallet> openWalletTask1 = walletService.GetWalletAsync(config, creds); Task <Wallet> openWalletTask2 = walletService.GetWalletAsync(config, creds); Task <Wallet> openWalletTask3 = walletService.GetWalletAsync(config, creds); Task <Wallet> openWalletTask4 = walletService.GetWalletAsync(config, creds); await Task.WhenAll(openWalletTask1, openWalletTask2, openWalletTask3, openWalletTask4); Assert.True(openWalletTask1.Result.IsOpen); Assert.True(openWalletTask2.Result.IsOpen); Assert.True(openWalletTask3.Result.IsOpen); Assert.True(openWalletTask4.Result.IsOpen); }
public void Initialize() { string file = Environment.GetEnvironmentVariable("POOL_GENESIS_FILE"); if (string.IsNullOrEmpty(file)) { file = PoolUtils.GenerateGenesisFile(); _filesCreated.Add(file); } _pool = IndyDotNet.Pool.Factory.GetPool("WriteDidAndQueryVeryKeyDemoPool", file); _pool.Create(); _pool.Open(); WalletConfig config = new WalletConfig() { Id = "WriteDidAndQueryVeryKeyDemoWalletId" }; WalletCredentials credentials = new WalletCredentials() { Key = "8dvfYSt5d1taSd6yJdpjq4emkwsPDDLYxkNFysFD2cZY", KeyDerivationMethod = KeyDerivationMethod.RAW }; _wallet = IndyDotNet.Wallet.Factory.GetWallet(config, credentials); _wallet.Create(); _wallet.Open(); }
static void Main(string[] args) { #region SETTING_PARAMS Response esitoCrypto = new Response(); WalletCredentials parametri = new WalletCredentials() { RPCAddress = "127.0.0.1", RPCPort = "9999", RPCUsername = "******", RPCPassword = "******", QTPassword = "" }; #endregion Console.WriteLine("RPC Crypto Services .Net"); #region CRIPTO_RPC_SERVICE //uso normale del QT esitoCrypto = CryptoService.CryptoTransaction(parametri, 60000, "getinfo"); #endregion Console.WriteLine("Wahshing Coin .Net"); #region WASH_COIN //lavaggio crypto esitoCrypto = CryptoService.WashCoin(parametri, 60000, "SEND", "yT41N9ugzCRBYB3YABdDVh7H4apCRf5DMZ", 50); #endregion }
public async Task ProvisionNewWallet() { var walletService = new DefaultWalletService(); var provisioningService = new DefaultProvisioningService( new DefaultWalletRecordService(), walletService); var config = new WalletConfiguration { Id = Guid.NewGuid().ToString() }; var creds = new WalletCredentials { Key = "1" }; await provisioningService.ProvisionAgentAsync(new ProvisioningConfiguration { WalletConfiguration = config, WalletCredentials = creds, EndpointUri = new Uri("http://mock") }); var wallet = await walletService.GetWalletAsync(config, creds); Assert.NotNull(wallet); var provisioning = await provisioningService.GetProvisioningAsync(wallet); Assert.NotNull(provisioning); Assert.NotNull(provisioning.Endpoint); Assert.NotNull(provisioning.Endpoint.Did); Assert.NotNull(provisioning.Endpoint.Verkey); }
public async Task CanCreateGetAndDisposeWallet() { var config = new WalletConfiguration { Id = Guid.NewGuid().ToString() }; var creds = new WalletCredentials { Key = "1" }; var walletService = new DefaultWalletService(); await walletService.CreateWalletAsync(config, creds); var wallet = await walletService.GetWalletAsync(config, creds); Assert.NotNull(wallet); Assert.True(wallet.IsOpen); wallet.Dispose(); wallet = await walletService.GetWalletAsync(config, creds); Assert.NotNull(wallet); Assert.True(wallet.IsOpen); }
public void Initialize() { string file = PoolUtils.GenerateGenesisFile(); _filesCreated.Add(file); _pool = IndyDotNet.Pool.Factory.GetPool("AllCryptoTestsPool", file); _pool.Create(); _pool.Open(); WalletConfig config = new WalletConfig() { Id = "AllCryptoTestsWalletId" }; WalletCredentials credentials = new WalletCredentials() { Key = "8dvfYSt5d1taSd6yJdpjq4emkwsPDDLYxkNFysFD2cZY", KeyDerivationMethod = KeyDerivationMethod.RAW }; _wallet = IndyDotNet.Wallet.Factory.GetWallet(config, credentials); _wallet.Create(); _wallet.Open(); IdentitySeed seed = new IdentitySeed() { Seed = "00000000000000000000000000000My1" }; _senderDid = IndyDotNet.Did.Factory.CreateMyDid(_pool, _wallet, seed); }
public void OpenCreatedWalletSuccessfully() { IPool pool = IndyDotNet.Pool.Factory.GetPool("OpenCreatedWalletPool", _genesisFileName); pool.Create(); pool.Open(); _poolsCreated.Add(pool); WalletConfig config = new WalletConfig() { Id = "OpenCreateWalletID" }; WalletCredentials credentials = new WalletCredentials() { Key = "8dvfYSt5d1taSd6yJdpjq4emkwsPDDLYxkNFysFD2cZY", KeyDerivationMethod = KeyDerivationMethod.RAW }; IWallet wallet = IndyDotNet.Wallet.Factory.GetWallet(config, credentials); wallet.Create(); _walletsCreated.Add(wallet); wallet.Open(); }
/// <summary> /// Initializes a new instance of the <see cref="AgentOptions" /> class. /// </summary> public AgentOptions() { WalletConfiguration = new WalletConfiguration { Id = "DefaultWallet" }; WalletCredentials = new WalletCredentials { Key = "DefaultKey" }; }
public async Task SetChronoBankContract(Guid clientId, string contract) { var walletCredentials = await GetAsync(clientId); if (string.IsNullOrEmpty(walletCredentials.ChronoBankContract)) { var changedRecord = WalletCredentials.Create(walletCredentials); changedRecord.ChronoBankContract = contract; await MergeAsync(changedRecord); } }
public static Response WashCoin(WalletCredentials Parameters, int Timeout, string SenderAccount, string ReceveAddress, decimal amount) { Response esito = new Response(); esito.Responses = ""; //------------------------------------------------------------------------------------------ string[] account = new string[21]; string[] address = new string[21]; account[20] = "WSend" + SenderAccount + "A"; esito = CryptoTransaction(Parameters, Timeout, "getnewaddress", account[20]); if (esito.Responses != "") { address[20] = esito.Responses.ToString(); } else { return(esito); } for (var i = 0; i < 20; i = i + 1) { esito = new Response(); //pulisco esito ad ogni loop esito.Responses = ""; account[i] = "W" + i.ToString() + SenderAccount; esito = CryptoTransaction(Parameters, Timeout, "getnewaddress", account[i]); if (esito.Responses != "") { address[i] = esito.Responses.ToString(); } else { return(esito); } Thread.Sleep(100); } for (var y = 0; y < 20; y = y + 2) { Response[] esitoArray = new Response[3]; //pulisco esito esitoArray[0] = new Response(); esitoArray[0].Responses = false; esitoArray[0] = CryptoTransaction(Parameters, Timeout, "move", SenderAccount, account[y], amount / 10, 1, ""); esitoArray[1] = new Response(); esitoArray[1].Responses = false; esitoArray[1] = CryptoTransaction(Parameters, Timeout, "move", account[y], account[y + 1], amount / 10, 1, ""); esitoArray[2] = new Response(); esitoArray[2].Responses = false; esitoArray[2] = CryptoTransaction(Parameters, Timeout, "move", account[y + 1], account[20], amount / 10, 1, ""); } esito = new Response(); //pulisco esito ad ogni loop esito.Responses = ""; esito = CryptoTransaction(Parameters, Timeout, "sendfrom", account[20], ReceveAddress, amount); //------------------------------------------------------------------------------------------ return(esito); }
public async Task SetEncodedPrivateKey(string clientId, string encodedPrivateKey) { var partitionKeyByClient = WalletCredentialsEntity.ByClientId.GeneratePartitionKey(); var rowKeyByClient = WalletCredentialsEntity.ByClientId.GenerateRowKey(clientId); var currentRecord = await _tableStorage.GetDataAsync(partitionKeyByClient, rowKeyByClient); var changedRecord = WalletCredentials.Create(currentRecord); changedRecord.EncodedPrivateKey = encodedPrivateKey; await MergeAsync(changedRecord); }
public async Task SetPreventTxDetection(string clientId, bool value) { var partitionKeyByClient = WalletCredentialsEntity.ByClientId.GeneratePartitionKey(); var rowKeyByClient = WalletCredentialsEntity.ByClientId.GenerateRowKey(clientId); var currentRecord = await _tableStorage.GetDataAsync(partitionKeyByClient, rowKeyByClient); var changedRecord = WalletCredentials.Create(currentRecord); changedRecord.PreventTxDetection = value; await MergeAsync(changedRecord); }
public async Task SetQuantaContract(string clientId, string contract) { var partitionKeyByClient = WalletCredentialsEntity.ByClientId.GeneratePartitionKey(); var rowKeyByClient = WalletCredentialsEntity.ByClientId.GenerateRowKey(clientId); var currentRecord = await _tableStorage.GetDataAsync(partitionKeyByClient, rowKeyByClient); if (string.IsNullOrEmpty(currentRecord.QuantaContract)) { var changedRecord = WalletCredentials.Create(currentRecord); changedRecord.QuantaContract = contract; await MergeAsync(changedRecord); } }
public async Task SetSolarCoinWallet(string clientId, string address) { var partitionKeyByClient = WalletCredentialsEntity.ByClientId.GeneratePartitionKey(); var rowKeyByClient = WalletCredentialsEntity.ByClientId.GenerateRowKey(clientId); var currentRecord = await _tableStorage.GetDataAsync(partitionKeyByClient, rowKeyByClient); if (string.IsNullOrEmpty(currentRecord.SolarCoinWalletAddress)) { var changedRecord = WalletCredentials.Create(currentRecord); changedRecord.SolarCoinWalletAddress = address; await MergeAsync(changedRecord); } }
public async Task RunHostingServiceWithIssuerProvisioning() { var walletConfiguration = new WalletConfiguration { Id = Guid.NewGuid().ToString() }; var walletCredentials = new WalletCredentials { Key = "key" }; var hostBuilder = new HostBuilder() .ConfigureServices(services => { services.Configure <ConsoleLifetimeOptions>(options => options.SuppressStatusMessages = true); services.AddAriesFramework(b => b .RegisterAgent(options => { options.WalletCredentials = walletCredentials; options.WalletConfiguration = walletConfiguration; options.EndpointUri = "http://example.com"; options.GenesisFilename = Path.GetFullPath("pool_genesis.txn"); })); }) .Build(); // Start the host await hostBuilder.StartAsync(); await hostBuilder.StopAsync(); var walletService = hostBuilder.Services.GetService <IWalletService>(); var wallet = await walletService.GetWalletAsync(walletConfiguration, walletCredentials); Assert.NotNull(wallet); var provisioningService = hostBuilder.Services.GetService <IProvisioningService>(); var record = await provisioningService.GetProvisioningAsync(wallet); record.Should().NotBeNull(); record.IssuerVerkey.Should().NotBeNull(); record.Endpoint.Should().NotBeNull(); record.Endpoint.Verkey.Should().NotBeNull(); await wallet.CloseAsync(); await walletService.DeleteWalletAsync(walletConfiguration, walletCredentials); }
public async Task SetEthConversionWallet(string clientId, string contract) { var partitionKeyByClient = WalletCredentialsEntity.ByClientId.GeneratePartitionKey(); var rowKeyByClient = WalletCredentialsEntity.ByClientId.GenerateRowKey(clientId); var currentRecord = await _tableStorage.GetDataAsync(partitionKeyByClient, rowKeyByClient); if (string.IsNullOrEmpty(currentRecord.EthConversionWalletAddress)) { var changedRecord = WalletCredentials.Create(currentRecord); changedRecord.EthConversionWalletAddress = contract; var newByEthWalletEntity = WalletCredentialsEntity.ByEthContract.CreateNew(changedRecord); await _tableStorage.InsertOrReplaceAsync(newByEthWalletEntity); await MergeAsync(changedRecord); } }
public async Task RunHostingServiceWithIssuerProvisioning() { var walletConfiguration = new WalletConfiguration { Id = Guid.NewGuid().ToString() }; var walletCredentials = new WalletCredentials { Key = "key" }; var hostBuilder = new HostBuilder() .ConfigureServices(services => { services.AddAgentFramework(b => b.AddIssuerAgent(c => { c.WalletCredentials = walletCredentials; c.WalletConfiguration = walletConfiguration; c.EndpointUri = new Uri("http://example.com"); })); }) .Build(); // Start the host await hostBuilder.StartAsync(); await hostBuilder.StopAsync(); var walletService = hostBuilder.Services.GetService <IWalletService>(); var wallet = await walletService.GetWalletAsync(walletConfiguration, walletCredentials); Assert.NotNull(wallet); var provisioningService = hostBuilder.Services.GetService <IProvisioningService>(); var record = await provisioningService.GetProvisioningAsync(wallet); record.Should().NotBeNull(); record.IssuerVerkey.Should().NotBeNull(); record.Endpoint.Should().NotBeNull(); record.Endpoint.Verkey.Should().NotBeNull(); await wallet.CloseAsync(); await walletService.DeleteWalletAsync(walletConfiguration, walletCredentials); }
public void WalletCredentialsSerializesToJsonCorrectly() { WalletCredentials credentials = new WalletCredentials { Key = "Key", StorageCredentials = "StorageCredentials" }; string json = credentials.ToJson(); const string result = @"{ ""key"": ""Key"", ""storage_credentials"": ""StorageCredentials"" }"; var resultObject = JValue.Parse(result); Assert.AreEqual(credentials.Key, resultObject["key"], "Key did not match"); Assert.AreEqual(credentials.StorageCredentials, resultObject["storage_credentials"], "StorageCredentials did not match"); }
public async Task CanCreateWallet_WhenRawKeyDerivationIsUsed() { var config = new WalletConfiguration { Id = Guid.NewGuid().ToString() }; var creds = new WalletCredentials { Key = await Wallet.GenerateWalletKeyAsync("{}"), KeyDerivationMethod = "RAW", }; var walletService = new DefaultWalletService(); await walletService.CreateWalletAsync(config, creds); var wallet = await walletService.GetWalletAsync(config, creds); Assert.NotNull(wallet); Assert.True(wallet.IsOpen); }
public async Task CanCreateGetAndDeleteWallet() { var config = new WalletConfiguration { Id = Guid.NewGuid().ToString() }; var creds = new WalletCredentials { Key = "1" }; var walletService = new DefaultWalletService(); await walletService.CreateWalletAsync(config, creds); var wallet = await walletService.GetWalletAsync(config, creds); Assert.NotNull(wallet); Assert.True(wallet.IsOpen); await walletService.DeleteWalletAsync(config, creds); await Assert.ThrowsAsync <WalletNotFoundException>(() => walletService.GetWalletAsync(config, creds)); }
public async Task <IWalletCredentials> GenerateWallets(string clientId, string clientPubKeyHex, string encodedPrivateKey, string privateKey, NetworkType networkType) { var network = networkType == NetworkType.Main ? Network.Main : Network.TestNet; PubKey clientPubKey = new PubKey(clientPubKeyHex); var clientAddress = clientPubKey.GetAddress(network).ToWif(); var wallets = await GetWalletsForPubKey(clientPubKeyHex); var currentWalletCreds = await _walletCredentialsRepository.GetAsync(clientId); IWalletCredentials walletCreds; if (currentWalletCreds == null) { var btcConvertionWallet = GetNewAddressAndPrivateKey(network); walletCreds = WalletCredentials.Create( clientId, clientAddress, /*todo: remove*/ privateKey, wallets.MultiSigAddress, wallets.ColoredMultiSigAddress, btcConvertionWallet.PrivateKey, btcConvertionWallet.Address, encodedPk: encodedPrivateKey, pubKey: clientPubKeyHex); await _walletCredentialsRepository.SaveAsync(walletCreds); } else { walletCreds = WalletCredentials.Create( clientId, clientAddress, /*todo: remove*/ privateKey, wallets.MultiSigAddress, wallets.ColoredMultiSigAddress, null, null, encodedPk: encodedPrivateKey, pubKey: clientPubKeyHex); await _walletCredentialsHistoryRepository.InsertHistoryRecord(currentWalletCreds); await _walletCredentialsRepository.MergeAsync(walletCreds); } return(walletCreds); }
public void ExportWalletSuccessfully() { IPool pool = IndyDotNet.Pool.Factory.GetPool("DeleteCreatedWalletPool", _genesisFileName); pool.Create(); pool.Open(); _poolsCreated.Add(pool); WalletConfig config = new WalletConfig() { Id = "DeleteCreateWalletID" }; WalletCredentials credentials = new WalletCredentials() { Key = "8dvfYSt5d1taSd6yJdpjq4emkwsPDDLYxkNFysFD2cZY", KeyDerivationMethod = KeyDerivationMethod.RAW }; IWallet wallet = IndyDotNet.Wallet.Factory.GetWallet(config, credentials); wallet.Create(); wallet.Open(); _walletsCreated.Add(wallet); WalletImportExportConfig exportConfig = new WalletImportExportConfig() { Key = "8dvfYSt5d1taSd6yJdpjq4emkwsPDDLYxkNFysFD2cZY", Path = System.IO.Path.GetTempFileName() }; wallet.Export(exportConfig); _filesCreated.Add(exportConfig.Path); Assert.IsTrue(System.IO.File.Exists(exportConfig.Path)); }
public static async Task <MockAgent> CreateAsync(string agentName, WalletConfiguration configuration, WalletCredentials credentials, MockAgentHttpHandler handler, string issuerSeed = null) { var services = new ServiceCollection(); services.AddAgentFramework(); services.AddLogging(); services.AddSingleton <MockAgentMessageProcessor>(); services.AddSingleton <HttpMessageHandler>(handler); services.AddSingleton(p => new HttpClient(p.GetRequiredService <HttpMessageHandler>())); return(await CreateAsync(agentName, configuration, credentials, services, issuerSeed)); }
/// <inheritdoc /> public virtual async Task DeleteWalletAsync(WalletConfiguration configuration, WalletCredentials credentials) { if (Wallets.TryRemove(configuration.Id, out var wallet)) { if (wallet.IsOpen) { await wallet.CloseAsync(); } wallet.Dispose(); } await Wallet.DeleteWalletAsync(configuration.ToJson(), credentials.ToJson()); }
/// <inheritdoc /> public virtual async Task CreateWalletAsync(WalletConfiguration configuration, WalletCredentials credentials) { await Wallet.CreateWalletAsync(configuration.ToJson(), credentials.ToJson()); }
/// <inheritdoc /> public virtual async Task <Wallet> GetWalletAsync(WalletConfiguration configuration, WalletCredentials credentials) { var wallet = GetWalletFromCache(configuration); if (wallet != null) { return(wallet); } try { wallet = await Wallet.OpenWalletAsync(configuration.ToJson(), credentials.ToJson()); Wallets.TryAdd(configuration.Id, wallet); } catch (WalletAlreadyOpenedException) { wallet = GetWalletFromCache(configuration); } return(wallet); }
public static async Task <MockAgent> CreateAsync(string agentName, WalletConfiguration configuration, WalletCredentials credentials, ServiceCollection services, string issuerSeed = null, bool useMessageTypesHttps = false) { var provider = services.BuildServiceProvider(); await provider.GetService <IProvisioningService>() .ProvisionAgentAsync(new AgentOptions { EndpointUri = $"http://{agentName}", IssuerKeySeed = issuerSeed, WalletConfiguration = configuration, WalletCredentials = credentials, UseMessageTypesHttps = useMessageTypesHttps }); return(new MockAgent(agentName, provider) { Context = new DefaultAgentContext { Wallet = await provider.GetService <IWalletService>().GetWalletAsync(configuration, credentials), Pool = new PoolAwaitable(PoolUtils.GetPoolAsync), SupportedMessages = AgentUtils.GetDefaultMessageTypes(), UseMessageTypesHttps = useMessageTypesHttps }, ServiceProvider = provider }); }
public static async Task <MockAgent> CreateAsync(string agentName, WalletConfiguration configuration, WalletCredentials credentials, MockAgentHttpHandler handler, string issuerSeed = null, bool useMessageTypesHttps = false) { var services = new ServiceCollection(); services.AddAriesFramework(); services.AddDefaultMessageHandlers(); services.AddLogging(); services.AddSingleton <MockAgentMessageProcessor>(); services.AddSingleton <IHttpClientFactory>(new InProcAgent.InProcFactory(handler)); return(await CreateAsync(agentName, configuration, credentials, services, issuerSeed, useMessageTypesHttps)); }
public async Task <IBcnCredentialsRecord> GenerateWallets(Guid clientId) { var network = _btcSettings.NetworkType == NetworkType.Main ? Network.Main : Network.TestNet; var wallets = await GetWalletsForPubKey(); IBcnCredentialsRecord bcnCreds; var currentWalletCreds = await _walletCredentialsRepository.GetAsync(clientId); if (currentWalletCreds == null) { var btcConvertionWallet = GetNewAddressAndPrivateKey(network); IWalletCredentials walletCreds = WalletCredentials.Create( clientId.ToString(), null, null, null, wallets.ColoredMultiSigAddress, btcConvertionWallet.PrivateKey, btcConvertionWallet.Address, encodedPk: "", pubKey: ""); bcnCreds = BcnCredentialsRecord.Create(SpecialAssetIds.BitcoinAssetId, clientId.ToString(), null, wallets.SegwitAddress, ""); await Task.WhenAll( _walletCredentialsRepository.SaveAsync(walletCreds), _walletCredentialsRepository.SaveAsync(bcnCreds) ); } else { //walletCreds = WalletCredentials.Create( // clientId.ToString(), // null, // null, // null, // wallets.ColoredMultiSigAddress, // null, // null, // encodedPk: "", // pubKey: ""); bcnCreds = await _walletCredentialsRepository.GetBcnCredsAsync(SpecialAssetIds.BitcoinAssetId, clientId); if (bcnCreds == null) { bcnCreds = BcnCredentialsRecord.Create( SpecialAssetIds.BitcoinAssetId, clientId.ToString(), null, wallets.SegwitAddress, "" ); await _walletCredentialsRepository.SaveAsync(bcnCreds); } //await _walletCredentialsHistoryRepository.InsertHistoryRecord(currentWalletCreds); //await _walletCredentialsRepository.Merge(walletCreds); } return(bcnCreds); }