/// <summary>
        /// Create and provision agent, wallet, etc.
        /// </summary>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        protected async Task ProvisionAsync(CancellationToken cancellationToken)
        {
            // Create agent wallet
            await _walletService.CreateWalletAsync(
                configuration : _walletOptions.WalletConfiguration,
                credentials : _walletOptions.WalletCredentials);

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

            if (_agentOptions.AgentKeySeed == null)
            {
                _agentOptions.AgentKeySeed = CryptoUtils.GetUniqueKey(32);
            }

            // 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 : wallet,
                        didJson : new
                    {
                        seed = _agentOptions.AgentKeySeed,
                        did  = _agentOptions.AgentDid
                    }.ToJson());

                    endpoint.Did    = agent.Did;
                    endpoint.Verkey = agent.VerKey;
                }
                else if (_agentOptions.AgentDid != null && _agentOptions.AgentKey != null)
                {
                    endpoint.Did    = _agentOptions.AgentDid;
                    endpoint.Verkey = _agentOptions.AgentKey;
                }
            }

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

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

            record.SetTag("AgentKeySeed", _agentOptions.AgentKeySeed);
            await _recordService.AddAsync(wallet, record);
        }
        public async Task <CreateCredentialDefinitionResponse> Handle
        (
            CreateCredentialDefinitionRequest aCreateCredentialDefinitionRequest,
            CancellationToken aCancellationToken
        )
        {
            IAgentContext agentContext = await AgentProvider.GetContextAsync();

            ProvisioningRecord issuerProvisioningRecord = await ProvisioningService.GetProvisioningAsync(agentContext.Wallet);

            string credentialDefinitionId =
                await SchemaService.CreateCredentialDefinitionAsync
                (
                    agentContext,
                    new CredentialDefinitionConfiguration
            {
                SchemaId                    = aCreateCredentialDefinitionRequest.SchemaId,
                Tag                         = aCreateCredentialDefinitionRequest.Tag,
                EnableRevocation            = aCreateCredentialDefinitionRequest.EnableRevocation,
                RevocationRegistrySize      = aCreateCredentialDefinitionRequest.RevocationRegistrySize,
                RevocationRegistryBaseUri   = aCreateCredentialDefinitionRequest.RevocationRegistryBaseUri?.ToString(),
                RevocationRegistryAutoScale = aCreateCredentialDefinitionRequest.RevocationRegistryAutoScale,
                IssuerDid                   = issuerProvisioningRecord.IssuerDid
            }
                );

            var response = new CreateCredentialDefinitionResponse(aCreateCredentialDefinitionRequest.CorrelationId, credentialDefinitionId);

            return(response);
        }
Esempio n. 3
0
        public async Task <OfferCredentialResponse> Handle
        (
            OfferCredentialRequest aOfferCredentialRequest,
            CancellationToken aCancellationToken
        )
        {
            IAgentContext agentContext = await AgentProvider.GetContextAsync();

            ProvisioningRecord provisioningRecord = await ProvisioningService.GetProvisioningAsync(agentContext.Wallet);

            ConnectionRecord connectionRecord = await ConnectionService.GetAsync(agentContext, aOfferCredentialRequest.ConnectionId);

            (CredentialOfferMessage credentialOfferMessage, _) =
                await CredentialService.CreateOfferAsync
                (
                    agentContext,
                    new OfferConfiguration
            {
                CredentialDefinitionId = aOfferCredentialRequest.CredentialDefinitionId,
                IssuerDid = provisioningRecord.IssuerDid,
                CredentialAttributeValues = aOfferCredentialRequest.CredentialPreviewAttributes
            }
                );

            await MessageService.SendAsync(agentContext.Wallet, credentialOfferMessage, connectionRecord);

            var response = new OfferCredentialResponse(aOfferCredentialRequest.CorrelationId);

            return(response);
        }
Esempio n. 4
0
        /// <summary>
        /// Constructs my DID doc in a pairwise relationship from a connection record and the agents provisioning record.
        /// </summary>
        /// <param name="connection">Connection record.</param>
        /// <param name="provisioningRecord">Provisioning record.</param>
        /// <returns>DID Doc</returns>
        public static DidDoc MyDidDoc(this ConnectionRecord connection, ProvisioningRecord provisioningRecord)
        {
            var doc = new DidDoc
            {
                Keys = new List <DidDocKey>
                {
                    new DidDocKey
                    {
                        Id              = $"{connection.MyDid}#keys-1",
                        Type            = DefaultKeyType,
                        Controller      = connection.MyDid,
                        PublicKeyBase58 = connection.MyVk
                    }
                }
            };

            if (!string.IsNullOrEmpty(provisioningRecord.Endpoint.Uri))
            {
                doc.Services = new List <IDidDocServiceEndpoint>
                {
                    new IndyAgentDidDocService
                    {
                        Id = $"{connection.MyDid};indy",
                        ServiceEndpoint = provisioningRecord.Endpoint.Uri,
                        RecipientKeys   = connection.MyVk != null ? new[] { connection.MyVk } : new string[0],
                        RoutingKeys     = provisioningRecord.Endpoint?.Verkey != null ? new[] { provisioningRecord.Endpoint.Verkey } : new string[0]
                    }
                };
            }

            return(doc);
        }
Esempio n. 5
0
        /// <inheritdoc />
        public virtual async Task ProvisionAgentAsync(Wallet wallet, ProvisioningConfiguration provisioningConfiguration)
        {
            if (provisioningConfiguration == null)
            {
                throw new ArgumentNullException(nameof(provisioningConfiguration));
            }
            if (provisioningConfiguration.EndpointUri == null)
            {
                throw new ArgumentNullException(nameof(provisioningConfiguration.EndpointUri));
            }

            var record = await GetProvisioningAsync(wallet);

            if (record != null)
            {
                throw new WalletAlreadyProvisionedException();
            }

            var agent = await Did.CreateAndStoreMyDidAsync(wallet,
                                                           provisioningConfiguration.AgentSeed != null
                                                           ?new { seed = provisioningConfiguration.AgentSeed }.ToJson()
                                                               : "{}");

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

            record = new ProvisioningRecord
            {
                IssuerSeed     = provisioningConfiguration.IssuerSeed,
                AgentSeed      = provisioningConfiguration.AgentSeed,
                MasterSecretId = masterSecretId,
                Endpoint       =
                {
                    Uri    = provisioningConfiguration.EndpointUri.ToString(),
                    Did    = agent.Did,
                    Verkey = agent.VerKey
                },
                Owner =
                {
                    Name     = provisioningConfiguration.OwnerName,
                    ImageUrl = provisioningConfiguration.OwnerImageUrl
                },
                TailsBaseUri = provisioningConfiguration.TailsBaseUri.ToString()
            };

            if (provisioningConfiguration.CreateIssuer)
            {
                var issuer = await Did.CreateAndStoreMyDidAsync(wallet,
                                                                provisioningConfiguration.IssuerSeed != null
                                                                ?new { seed = provisioningConfiguration.IssuerSeed }.ToJson()
                                                                    : "{}");

                record.IssuerDid    = issuer.Did;
                record.IssuerVerkey = issuer.VerKey;
            }

            await RecordService.AddAsync(wallet, record);
        }
Esempio n. 6
0
 /// <summary>
 /// Get a service decorator representation for this provisioning record
 /// </summary>
 /// <param name="record"></param>
 /// <param name="useDidKeyFormat"></param>
 /// <returns></returns>
 public static ServiceDecorator ToServiceDecorator(this ProvisioningRecord record, bool useDidKeyFormat = false)
 {
     return(new ServiceDecorator
     {
         ServiceEndpoint = record.Endpoint.Uri,
         RoutingKeys = useDidKeyFormat ? record.Endpoint.Verkey.Select(DidUtils.ConvertVerkeyToDidKey) : record.Endpoint.Verkey,
         RecipientKeys = new [] { useDidKeyFormat?DidUtils.ConvertVerkeyToDidKey(record.IssuerVerkey) : record.IssuerVerkey }
     });
 }
 /// <summary>
 /// Get a service decorator representation for this provisioning record
 /// </summary>
 /// <param name="record"></param>
 /// <returns></returns>
 public static ServiceDecorator ToServiceDecorator(this ProvisioningRecord record)
 {
     return(new ServiceDecorator
     {
         ServiceEndpoint = record.Endpoint.Uri,
         RoutingKeys = new [] { record.Endpoint.Verkey },
         RecipientKeys = new [] { record.IssuerVerkey }
     });
 }
Esempio n. 8
0
        /// <summary>
        /// Configures the agent wallet with issuer configuration
        /// </summary>
        /// <returns>The async.</returns>
        /// <param name="record">Record.</param>
        /// <param name="context">Context.</param>
        public override async Task ConfigureAsync(ProvisioningRecord record, IAgentContext context)
        {
            var issuer = await Did.CreateAndStoreMyDidAsync(
                context.Wallet, IssuerSeed != null?new { seed = IssuerSeed }.ToJson() : "{}");

            record.IssuerDid    = issuer.Did;
            record.IssuerVerkey = issuer.VerKey;
            record.TailsBaseUri = TailsBaseUri?.ToString();
        }
        public virtual async Task ProvisionAgentAsync(Wallet wallet, ProvisioningConfiguration provisioningConfiguration)
        {
            if (provisioningConfiguration == null)
            {
                throw new ArgumentNullException(nameof(provisioningConfiguration));
            }
            if (provisioningConfiguration.EndpointUri == null)
            {
                throw new ArgumentNullException(nameof(provisioningConfiguration.EndpointUri));
            }

            ProvisioningRecord record = null;

            try
            {
                record = await GetProvisioningAsync(wallet);
            }
            catch (AgentFrameworkException e) when(e.ErrorCode == ErrorCode.RecordNotFound)
            {
            }

            if (record != null)
            {
                throw new AgentFrameworkException(ErrorCode.WalletAlreadyProvisioned);
            }

            var agent = await Did.CreateAndStoreMyDidAsync(wallet,
                                                           provisioningConfiguration.AgentSeed != null
                                                           ?new { seed = provisioningConfiguration.AgentSeed }.ToJson()
                                                               : "{}");

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

            record = new ProvisioningRecord
            {
                MasterSecretId = masterSecretId,
                Endpoint       =
                {
                    Uri    = provisioningConfiguration.EndpointUri.ToString(),
                    Did    = agent.Did,
                    Verkey = agent.VerKey
                },
                Owner =
                {
                    Name     = provisioningConfiguration.OwnerName,
                    ImageUrl = provisioningConfiguration.OwnerImageUrl
                }
            };

            await provisioningConfiguration.ConfigureAsync(record, new DefaultAgentContext { Wallet = wallet });

            await RecordService.AddAsync(wallet, record);
        }
        public async Task <GetWalletResponse> Handle
        (
            GetWalletRequest aGetWalletRequest,
            CancellationToken aCancellationToken
        )
        {
            Wallet wallet =
                await WalletService.GetWalletAsync(AgentOptions.WalletConfiguration, AgentOptions.WalletCredentials);

            ProvisioningRecord provisioningRecord = await ProvisioningService.GetProvisioningAsync(wallet);

            var getWalletResponse = new GetWalletResponse(aGetWalletRequest.CorrelationId, provisioningRecord);

            return(getWalletResponse);
        }
Esempio n. 11
0
        public async Task InitializeAgentInfo()
        {
            var context = await _agentContextProvider.GetContextAsync();

            _provisioningRecord = await _provisioningService.GetProvisioningAsync(context.Wallet);

            AgentName           = _provisioningRecord.Owner.Name;
            AgentImageSource    = Base64StringToImageSource.Base64StringToImage(_provisioningRecord.Owner.ImageUrl);
            MediatorEndpointUrl = _provisioningRecord.Endpoint.Uri;
            if (Preferences.ContainsKey(AppConstant.MediatorConnectionIdTagName))
            {
                var mediatorConnection = await _walletRecordService.GetAsync <ConnectionRecord>(context.Wallet, Preferences.Get(AppConstant.MediatorConnectionIdTagName, string.Empty));

                MediatorConnectionState = mediatorConnection.State.ToString();
            }
        }
Esempio n. 12
0
 public ProfileNamePopupViewModel
 (
     IUserDialogs userDialogs,
     INavigationService navigationService,
     IAgentProvider agentContextProvider,
     IWalletRecordService walletRecordService,
     IEventAggregator eventAggregator,
     ProvisioningRecord record
 ) : base
     (
         nameof(ProfileNamePopupViewModel),
         userDialogs,
         navigationService
     )
 {
     _walletRecordService  = walletRecordService;
     _agentContextProvider = agentContextProvider;
     _eventAggregator      = eventAggregator;
     _provisioningRecord   = record;
     _agentName            = record.Owner.Name;
 }
Esempio n. 13
0
        public async Task <CreateSchemaResponse> Handle
        (
            CreateSchemaRequest aCreateSchemaRequest,
            CancellationToken aCancellationToken
        )
        {
            IAgentContext agentContext = await AgentProvider.GetContextAsync();

            ProvisioningRecord issuerProvisioningRecord = await ProvisioningService.GetProvisioningAsync(agentContext.Wallet);

            string schemaId =
                await SchemaService.CreateSchemaAsync
                (
                    agentContext,
                    issuerDid : issuerProvisioningRecord.IssuerDid,
                    aCreateSchemaRequest.Name,
                    aCreateSchemaRequest.Version,
                    aCreateSchemaRequest.AttributeNames.ToArray()
                );

            var response = new CreateSchemaResponse(aCreateSchemaRequest.CorrelationId, schemaId);

            return(response);
        }
Esempio n. 14
0
 /// <summary>
 /// Set the Initial State
 /// </summary>
 public override void Initialize()
 {
     IsCached           = false;
     ProvisioningRecord = null;
 }
 /// <summary>
 /// Configures the agent wallet.
 /// </summary>
 /// <returns>The async.</returns>
 /// <param name="record">Record.</param>
 /// <param name="context">Context.</param>
 public abstract Task ConfigureAsync(ProvisioningRecord record, IAgentContext context);
Esempio n. 16
0
 /// <summary>
 /// Configures the agent wallet with basic configuration
 /// </summary>
 /// <returns>The async.</returns>
 /// <param name="record">Record.</param>
 /// <param name="context">Context.</param>
 public override Task ConfigureAsync(ProvisioningRecord record, IAgentContext context)
 {
     return(Task.CompletedTask);
 }
 /// <summary>
 /// Configures the agent wallet.
 /// </summary>
 /// <returns>The async.</returns>
 /// <param name="record">Record.</param>
 /// <param name="context">Context.</param>
 public virtual Task ConfigureAsync(ProvisioningRecord record, IAgentContext context) => Task.CompletedTask;
 public GetWalletResponse(Guid aRequestId, ProvisioningRecord aProvisioningRecord) : base(aRequestId)
 {
     ProvisioningRecord = aProvisioningRecord;
 }
        /// <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);
        }