private async Task <Action> OnApplicationStartedAsync(IVerifiableCredentialClient _verifiableCredentialClient) { var issuerDid = await _verifiableCredentialClient.GetIssuerDidAsync(); var schemaId = await _verifiableCredentialClient.GetSchemaId(issuerDid); if (schemaId == null) { schemaId = await _verifiableCredentialClient.CreateSchemaAsync(); } var credentialDefinitionId = await _verifiableCredentialClient.GetCredentialDefinitionIdAsync(schemaId); if (credentialDefinitionId == null) { credentialDefinitionId = await _verifiableCredentialClient.CreateCredentialDefinitionAsync(schemaId); } return(null); }
public async Task <string> IssueCredentialsAsync(Patient patient, List <Identifier> identifiers) { var connectionActive = true; var connection = await _context.Connections .Where(c => c.AcceptedConnectionDate != null) .OrderByDescending(c => c.AcceptedConnectionDate) .FirstOrDefaultAsync(c => c.PatientId == patient.Id); if (connection == null) { // Create connection and wait for connection to be accepted before issuing credentials connection = await CreateConnectionAsync(patient); connectionActive = false; } var alias = patient.Id.ToString(); var issuerDid = await _verifiableCredentialClient.GetIssuerDidAsync(); var schemaId = await _verifiableCredentialClient.GetSchemaId(issuerDid); if (schemaId == null) { schemaId = await _verifiableCredentialClient.CreateSchemaAsync(); } var credentialDefinitionId = await _verifiableCredentialClient.GetCredentialDefinitionIdAsync(schemaId); if (credentialDefinitionId == null) { credentialDefinitionId = await _verifiableCredentialClient.CreateCredentialDefinitionAsync(schemaId); } var credentials = new List <Credential>(); foreach (var identifier in identifiers) { var newCredential = new Credential { ConnectionId = connection.Id, SchemaId = schemaId, CredentialDefinitionId = credentialDefinitionId, Identifier = new Identifier { Guid = identifier.Guid, Uri = identifier.Uri } }; credentials.Add(newCredential); } await _context.Credentials.AddRangeAsync(credentials); var created = await _context.SaveChangesAsync(); if (created < 1) { throw new InvalidOperationException("Could not store credentials."); } if (connectionActive) { // Issue credentials if connection already active foreach (var credential in credentials) { _logger.LogInformation("Issuing a credential with this connection_id: {connectionId}", connection.ConnectionId); // Assumed that when a connection invitation has been sent and accepted await IssueCredential(credential, connection.ConnectionId, credential.Identifier.Guid); _logger.LogInformation("Credential has been issued for connection_id: {connectionId}", connection.ConnectionId); } return(null); } return(connection.Base64QRCode); }