예제 #1
0
        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
            });
        }
예제 #2
0
        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);
        }
예제 #3
0
        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;
        }
예제 #4
0
        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);
        }
예제 #5
0
        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);
        }
예제 #6
0
        /// <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);
        }
예제 #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AgentOptions" /> class.
 /// </summary>
 public AgentOptions()
 {
     WalletConfiguration = new WalletConfiguration {
         Id = "DefaultWallet"
     };
     WalletCredentials = new WalletCredentials {
         Key = "DefaultKey"
     };
 }
예제 #8
0
        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));
        }
예제 #9
0
        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());
        }
예제 #11
0
        /// <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);
        }
예제 #13
0
 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);
     }
 }
예제 #14
0
        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);
        }
예제 #15
0
        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);
        }
예제 #16
0
        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);
        }
예제 #17
0
        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());
        }
예제 #18
0
        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 }");
                }
            }
        }
예제 #19
0
        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());
 }