public async Task InitializeAsync()
        {
            try
            {
                await Wallet.CreateWalletAsync(IssuerConfig, Credentials);
            }
            catch (WalletExistsException)
            {
                // OK
            }

            try
            {
                await Wallet.CreateWalletAsync(HolderConfig, Credentials);
            }
            catch (WalletExistsException)
            {
                // OK
            }

            _issuerWallet = await Wallet.OpenWalletAsync(IssuerConfig, Credentials);

            _holderWallet = await Wallet.OpenWalletAsync(HolderConfig, Credentials);

            try
            {
                await _poolService.CreatePoolAsync(PoolName, Path.GetFullPath("pool_genesis.txn"), 2);
            }
            catch (PoolLedgerConfigExistsException)
            {
                // OK
            }
            _pool = await _poolService.GetPoolAsync(PoolName, 2);
        }
Exemple #2
0
 /// <inheritdoc />
 public virtual async Task <IAgentContext> GetContextAsync(string agentId = null)
 {
     return(new DefaultAgentContext
     {
         Wallet = await _walletService.GetWalletAsync(_walletOptions.WalletConfiguration,
                                                      _walletOptions.WalletCredentials),
         Pool = new PoolAwaitable(() => _poolService.GetPoolAsync(
                                      _poolOptions.PoolName, _poolOptions.ProtocolVersion))
     });
 }
Exemple #3
0
        /// <inheritdoc />
        public async Task <IAgentContext> GetContextAsync(params object[] args)
        {
            var agent = await GetAgentAsync(args);

            return(new DefaultAgentContext
            {
                Wallet = await _walletService.GetWalletAsync(_walletOptions.WalletConfiguration,
                                                             _walletOptions.WalletCredentials),
                Pool = new PoolAwaitable(() => _poolService.GetPoolAsync(
                                             _poolOptions.PoolName, _poolOptions.ProtocolVersion)),
                SupportedMessages = agent.GetSupportedMessageTypes()
            });
        }
        public static async Task <Pool> GetPoolAsync()
        {
            if (pool != null)
            {
                return(pool);
            }

            try
            {
                await poolService.CreatePoolAsync("LocalTestPool", Path.GetFullPath("pool_genesis.txn"));
            }
            catch (PoolLedgerConfigExistsException)
            {
                // OK
            }
            return(pool = await poolService.GetPoolAsync("LocalTestPool", 2));
        }
        public async Task <IAgentContext> GetContextAsync(params object[] args)
        {
            var configurationName = Preferences.Get(Constants.PoolConfigurationName, "sovrin-staging");

            try
            {
                var agentContext = new DefaultAgentContext
                {
                    SupportedMessages = _agent.GetSupportedMessageTypes(),
                    Wallet            = await _walletService.GetWalletAsync(
                        configuration : new WalletConfiguration
                    {
                        Id = Constants.LocalWalletIdKey,
                        StorageConfiguration = new WalletConfiguration.WalletStorageConfiguration
                        {
                            Path = Path.Combine(
                                FileSystem.AppDataDirectory,
                                ".indy_client",
                                "wallets")
                        }
                    },
                        credentials : new WalletCredentials
                    {
                        Key = await SyncedSecureStorage.GetAsync(Constants.LocalWalletCredentialKey)
                    }),

                    Pool  = new PoolAwaitable(async() => await _poolService.GetPoolAsync(configurationName, 2)),
                    Agent = _agent
                };
                return(agentContext);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
                return(null);
            }
        }
        public async Task InvokeAsync(HttpContext context)
        {
            if (!context.Request.Method.Equals("POST", StringComparison.OrdinalIgnoreCase))
            {
                await _next(context);

                return;
            }

            var wallet = await _walletService.GetWalletAsync(_walletOptions.WalletConfiguration,
                                                             _walletOptions.WalletCredentials);

            var endpoint = await _provisioningService.GetProvisioningAsync(wallet);

            if (context.Request.ContentLength != null)
            {
                var body = new byte[(int)context.Request.ContentLength];

                await context.Request.Body.ReadAsync(body, 0, body.Length);

                var decrypted =
                    await _messageSerializer.UnpackAsync <IEnvelopeMessage>(body, wallet, endpoint.Endpoint.Verkey);

                var decoded = JsonConvert.DeserializeObject <IContentMessage>(decrypted.Content);

                switch (decoded)
                {
                case ConnectionRequestMessage request:
                    await _connectionService.ProcessRequestAsync(wallet, request);

                    break;

                case ConnectionResponseMessage response:
                    await _connectionService.ProcessResponseAsync(wallet, response);

                    break;

                case CredentialOfferMessage offer:
                    await _credentialService.ProcessOfferAsync(wallet, offer);

                    break;

                case CredentialRequestMessage request:
                    await _credentialService.ProcessCredentialRequestAsync(wallet, request);

                    break;

                case CredentialMessage credential:
                    var pool = await _poolService.GetPoolAsync(_poolOptions.PoolName, _poolOptions.ProtocolVersion);

                    await _credentialService.ProcessCredentialAsync(pool, wallet, credential);

                    break;

                case ProofMessage _:
                    break;
                }

                context.Response.StatusCode = 200;
                await context.Response.WriteAsync(string.Empty);

                return;
            }

            throw new Exception("Empty content length");
        }