コード例 #1
0
        private async Task <CreateInboxResponseMessage> CreateInboxAsync(IAgentContext agentContext, ConnectionRecord connection, CreateInboxMessage createInboxMessage)
        {
            if (connection.State != ConnectionState.Connected)
            {
                throw new InvalidOperationException("Can't create inbox if connection is not in final state");
            }

            var inboxId  = $"Edge{Guid.NewGuid().ToString("N")}";
            var inboxKey = Guid.NewGuid().ToString();

            var inboxRecord = new InboxRecord
            {
                Id = inboxId,
                WalletConfiguration = new WalletConfiguration
                {
                    Id          = inboxId,
                    StorageType = options.WalletConfiguration?.StorageType ?? "default"
                },
                WalletCredentials = new WalletCredentials {
                    Key = inboxKey
                }
            };

            connection.SetTag("InboxId", inboxId);

            await walletService.CreateWalletAsync(
                configuration : inboxRecord.WalletConfiguration,
                credentials : inboxRecord.WalletCredentials);

            await recordService.AddAsync(agentContext.Wallet, inboxRecord);

            await recordService.UpdateAsync(agentContext.Wallet, connection);

            return(new CreateInboxResponseMessage
            {
                InboxId = inboxId,
                InboxKey = inboxKey
            });
        }
コード例 #2
0
        private async void RegisterNewUser(RegisterNewUserCommand command, RegisterNewUserReponse response)
        {
            try
            {
                _newUser = AdapterCommantToEntity(command, response);
                if (response.HasError)
                {
                    return;
                }

                await _userRepository.CreateAsync(_newUser);

                await _walletService.CreateWalletAsync(_newUser);

                _logger.LogInformation($"Usuário {_newUser.UserName}, email {_newUser.Email}, documento {_newUser.DocumentNumber} registrado com sucesso.");
            }
            catch (Exception ex)
            {
                var message = $"Problemas ao salvar o usuário {command.UserName} - {ex.Message}";

                _logger.LogError(ex, message);
                response.AddError(message);
            }
        }
コード例 #3
0
        /// <inheritdoc />
        public async Task ProvisionAgentAsync(AgentOptions agentOptions)
        {
            if (agentOptions is null)
            {
                throw new ArgumentNullException(nameof(agentOptions));
            }

            // Create agent wallet
            await WalletService.CreateWalletAsync(
                configuration : agentOptions.WalletConfiguration,
                credentials : agentOptions.WalletCredentials);

            var wallet = await WalletService.GetWalletAsync(
                configuration : agentOptions.WalletConfiguration,
                credentials : agentOptions.WalletCredentials);

            // Configure agent endpoint
            AgentEndpoint endpoint = null;

            if (agentOptions.EndpointUri != null)
            {
                endpoint = new AgentEndpoint {
                    Uri = agentOptions.EndpointUri.ToString()
                };
                if (agentOptions.AgentKeySeed != null)
                {
                    var agent = await Did.CreateAndStoreMyDidAsync(wallet, new { seed = agentOptions.AgentKeySeed }.ToJson());

                    endpoint.Did    = agent.Did;
                    endpoint.Verkey = agent.VerKey;
                }
                else if (agentOptions.AgentKey != null)
                {
                    endpoint.Did    = agentOptions.AgentDid;
                    endpoint.Verkey = agentOptions.AgentKey;
                }
                else
                {
                    var agent = await Did.CreateAndStoreMyDidAsync(wallet, "{}");

                    endpoint.Did    = agent.Did;
                    endpoint.Verkey = agent.VerKey;
                }
            }
            var masterSecretId = await AnonCreds.ProverCreateMasterSecretAsync(wallet, null);

            var record = new ProvisioningRecord
            {
                MasterSecretId = masterSecretId,
                Endpoint       = endpoint,
                Owner          =
                {
                    Name     = agentOptions.AgentName,
                    ImageUrl = agentOptions.AgentImageUri
                }
            };

            // Issuer Configuration
            if (agentOptions.IssuerKeySeed == null)
            {
                agentOptions.IssuerKeySeed = CryptoUtils.GetUniqueKey(32);
            }

            var issuer = await Did.CreateAndStoreMyDidAsync(
                wallet : wallet,
                didJson : new
            {
                did  = agentOptions.IssuerDid,
                seed = agentOptions.IssuerKeySeed
            }.ToJson());

            record.IssuerSeed   = agentOptions.IssuerKeySeed;
            record.IssuerDid    = issuer.Did;
            record.IssuerVerkey = issuer.VerKey;

            record.SetTag("AgentKeySeed", agentOptions.AgentKeySeed);
            record.SetTag("IssuerKeySeed", agentOptions.IssuerKeySeed);

            // Add record to wallet
            await RecordService.AddAsync(wallet, record);
        }
コード例 #4
0
        /// <inheritdoc />
        public virtual async Task ProvisionAgentAsync(ProvisioningConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }
            if (configuration.WalletConfiguration == null ||
                configuration.WalletCredentials == null)
            {
                throw new ArgumentNullException(nameof(configuration),
                                                "Wallet configuration and credentials must be specified");
            }

            // Create agent wallet
            await WalletService.CreateWalletAsync(configuration.WalletConfiguration, configuration.WalletCredentials);

            var wallet =
                await WalletService.GetWalletAsync(configuration.WalletConfiguration, configuration.WalletCredentials);

            // Configure agent endpoint
            AgentEndpoint endpoint = null;

            if (configuration.EndpointUri != null)
            {
                endpoint = new AgentEndpoint {
                    Uri = configuration.EndpointUri?.ToString()
                };
                if (configuration.AgentSeed != null)
                {
                    var agent = await Did.CreateAndStoreMyDidAsync(wallet, new { seed = configuration.AgentSeed }.ToJson());

                    endpoint.Did    = agent.Did;
                    endpoint.Verkey = agent.VerKey;
                }
                else if (configuration.AgentDid != null && configuration.AgentVerkey != null)
                {
                    endpoint.Did    = configuration.AgentDid;
                    endpoint.Verkey = configuration.AgentVerkey;
                }
                else
                {
                    var agent = await Did.CreateAndStoreMyDidAsync(wallet, "{}");

                    endpoint.Did    = agent.Did;
                    endpoint.Verkey = agent.VerKey;
                }
            }

            var masterSecretId = await AnonCreds.ProverCreateMasterSecretAsync(wallet, null);

            var record = new ProvisioningRecord
            {
                MasterSecretId = masterSecretId,
                Endpoint       = endpoint,
                Owner          =
                {
                    Name     = configuration.OwnerName,
                    ImageUrl = configuration.OwnerImageUrl
                },
                PassCode = configuration.PassCode
            };

            // Populate initial tags if any passed
            if (configuration.Tags != null && configuration.Tags.Any())
            {
                foreach (var item in configuration.Tags)
                {
                    record.Tags.Add(item.Key, item.Value);
                }
            }

            // Create issuer
            await configuration.ConfigureAsync(record, new DefaultAgentContext { Wallet = wallet });

            await RecordService.AddAsync(wallet, record);
        }