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 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 IotaWalletManager(WalletConfiguration walletConfiguration, ISelectedChanged selectedChanged) { this.walletConfiguration = walletConfiguration; this.selectedChanged = selectedChanged; addressesButtons = OpenAddressesButtons().ToArray(); commandGroup = new ActionCommandGroup(addressesButtons.Select(b => b.ButtonClick).ToArray()); addressesModel = new ContentCollectionModel <AddressItemModel>(addressesButtons); bundlesModel = new ContentListModel <BundleItemModel>(addressesButtons.First()); transactionCollection = new ObservableCollection <TransactionItemModel>(); transactionManager = new IotaWalletTransactionManager(transactionCollection, bundlesModel.ContentItems); var balanceItems = CreateBalanceItems().ToArray(); var menuItems = CreateMenuItems().ToArray(); var balanceStatsModel = new BalanceStatsModel(balanceItems); walletModel = new WalletModel(this, balanceStatsModel, menuItems); walletModel.NewSend += WalletModel_NewSend; menuItems.First().IsSelected = true; this.selectedChanged.SelectedChanged += SelectedChanged_SelectedChanged; bundlesModel.ContentItems.CollectionChanged += ContentItems_CollectionChanged; }
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); }
/// <inheritdoc /> public virtual async Task CreateWalletAsync(WalletConfiguration configuration, WalletCredentials credentials) { await Wallet.CreateWalletAsync(configuration.ToJson(), credentials.ToJson()); // Create master secret. This should later be moved to a credential related context await AnonCreds.ProverCreateMasterSecretAsync(await GetWalletAsync(configuration, credentials), MasterSecretName); }
/// <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 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)); }
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)); }
/// <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 <Wallet> GetWalletAsync(WalletConfiguration configuration, WalletCredentials credentials) { if (Wallets.TryGetValue(configuration.Id, out var wallet)) { return(wallet); } wallet = await Wallet.OpenWalletAsync(configuration.ToJson(), credentials.ToJson()); Wallets.TryAdd(configuration.Id, wallet); return(wallet); }
private Wallet GetWalletFromCache(WalletConfiguration configuration) { if (Wallets.TryGetValue(configuration.Id, out var wallet)) { if (wallet.IsOpen) { return(wallet); } Wallets.TryRemove(configuration.Id, out wallet); } return(null); }
private async Task Create() { if (tcs.Task.Status == TaskStatus.WaitingForActivation) { var walletStringKey = walletKey.GetString(); var isImporting = defaultWalletKey.GetString() != walletStringKey; var walletConfiguration = new WalletConfiguration() { PrivateKey = walletStringKey, WalletType = WalletType.Iota, IsImported = isImporting, Name = name }; tcs.TrySetResult(walletConfiguration); } }
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 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 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); }
static IServiceProvider ConfigureServices() { var configuration = BindConfiguration(); var services = new ServiceCollection(); services.AddLogging(opt => { opt.AddConsole(); opt.SetMinimumLevel(LogLevel.Trace); }); var walletConfig = new WalletConfiguration(); configuration.GetSection("Wallet").Bind(walletConfig); services.AddWallet(walletConfig); services.Configure <DicingConfiguration>(configuration.GetSection("Dicing")); services.AddSingleton <WalletOutputsDicer>(); return(services.BuildServiceProvider()); }
public static void LoadPostGressPlugin(WalletConfiguration config) { if (!Loaded) { Console.WriteLine(System.Environment.GetEnvironmentVariable("RUST_LOG")); Console.WriteLine("Initializing postgres wallet"); var result = postgresstorage_init(); if (result != 0) { Console.WriteLine("Error loading library : {0}", result); throw new Exception("Error load library"); } result = init_storagetype(config.StorageConfiguration.ToJson(), config.StorageCredential.ToJson()); if (result != 0) { Console.WriteLine("Error unable to configure postgres stg: {0}", result); throw new Exception($"Error unable to configure postgres stg: { result }"); } } }
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)); }
/// <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); }
/// <inheritdoc /> public virtual async Task CreateWalletAsync(WalletConfiguration configuration, WalletCredentials credentials) { await Wallet.CreateWalletAsync(configuration.ToJson(), credentials.ToJson()); }