public async Task <IActionResult> RegisterSchema() { var context = await _agentContextProvider.GetContextAsync(); var issuer = await _provisionService.GetProvisioningAsync(context.Wallet); var Trustee = await Did.CreateAndStoreMyDidAsync(context.Wallet, new { seed = "000000000000000000000000Steward1" }.ToJson()); await Ledger.SignAndSubmitRequestAsync(await context.Pool, context.Wallet, Trustee.Did, await Ledger.BuildNymRequestAsync(Trustee.Did, issuer.IssuerDid, issuer.IssuerVerkey, null, "ENDORSER")); var schemaId = await _schemaService.CreateSchemaAsync( context : context, issuerDid : issuer.IssuerDid, name : "degree-schema", version : "1.0", attributeNames : new[] { "name", "date", "degree", "age", "timestamp" }); await _schemaService.CreateCredentialDefinitionAsync(context, new CredentialDefinitionConfiguration { SchemaId = schemaId, Tag = "default", EnableRevocation = false, RevocationRegistrySize = 0, RevocationRegistryBaseUri = "", RevocationRegistryAutoScale = false, IssuerDid = issuer.IssuerDid }); return(RedirectToAction("CredentialsForm")); }
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); }
public async Task CanCreateAndResolveCredentialDefinitionAndSchema() { var issuer = await Did.CreateAndStoreMyDidAsync(_issuerWallet, new { seed = "000000000000000000000000Steward1" }.ToJson()); var schemaName = $"Test-Schema-{Guid.NewGuid().ToString()}"; var schemaVersion = "1.0"; var schemaAttrNames = new[] { "test_attr_1", "test_attr_2" }; //Create a dummy schema var schemaId = await _schemaService.CreateSchemaAsync(_pool, _issuerWallet, issuer.Did, schemaName, schemaVersion, schemaAttrNames); var credId = await _schemaService.CreateCredentialDefinitionAsync(_pool, _issuerWallet, schemaId, issuer.Did, false, 100, new Uri("http://mock/tails")); var credDef = await _schemaService.LookupCredentialDefinitionAsync(_pool, _issuerWallet, issuer.Did, credId); var resultCredId = JObject.Parse(credDef)["id"].ToString(); var schemaSequenceNo = JObject.Parse(credDef)["schemaId"]; Assert.Equal(credId, resultCredId); var result = await _schemaService.LookupSchemaFromCredentialDefinitionAsync(_pool, _issuerWallet, issuer.Did, credId); var resultSchemaName = JObject.Parse(result)["name"].ToString(); var resultSchemaVersion = JObject.Parse(result)["version"].ToString(); Assert.Equal(schemaName, resultSchemaName); Assert.Equal(schemaVersion, resultSchemaVersion); }
public static async Task <(string, string)> CreateDummySchemaAndNonRevokableCredDef(IAgentContext context, ISchemaService schemaService, string issuerDid, string[] attributeValues) { // Create a schema and credential definition for this issuer var schemaId = await schemaService.CreateSchemaAsync(context, issuerDid, $"Test-Schema-{Guid.NewGuid().ToString()}", "1.0", attributeValues); return(await schemaService.CreateCredentialDefinitionAsync(context, schemaId, issuerDid, "Tag", false, 100, new Uri("http://mock/tails")), schemaId); }
public async Task <IActionResult> SendCredDefToLedger(string id) { var agentContext = await _agentContextProvider.GetContextAsync(); await _schemaService.CreateCredentialDefinitionAsync(agentContext, id, "Tag", false, 0); return(RedirectToAction("Details", "Schema", new { id })); }
public async Task <IActionResult> CreateSchema() { var context = await _agentContextProvider.GetContextAsync(); var record = await _provisioningService.GetProvisioningAsync(context.Wallet); var schemaName = $"Rent-Credential"; var schemaVersion = "1.0"; var schemaAttrNames = new[] { "Name", "Rented" }; var schemaId = await _schemaService.CreateSchemaAsync(context, record.Endpoint.Did, schemaName, schemaVersion, schemaAttrNames); await Task.Delay(TimeSpan.FromSeconds(2)); string credId = await _schemaService.CreateCredentialDefinitionAsync(context, schemaId, record.Endpoint.Did, "Tag", false, 100, new Uri("http://mock/tails")); _logger.LogInformation("CREDDEFID ++++++++++++ {0}", credId); return(RedirectToAction("Index")); }
public static async Task <(string, string)> CreateDummySchemaAndNonRevokableCredDef(IAgentContext context, ISchemaService schemaService, string issuerDid, string[] attributeValues) { // Create a schema and credential definition for this issuer var schemaId = await schemaService.CreateSchemaAsync(context, issuerDid, $"Test-Schema-{Guid.NewGuid()}", "1.0", attributeValues); var credentialDefinitionConfiguration = new CredentialDefinitionConfiguration { SchemaId = schemaId, EnableRevocation = false, IssuerDid = issuerDid, Tag = "Tag", }; return ( await schemaService.CreateCredentialDefinitionAsync(context, credentialDefinitionConfiguration), schemaId ); }
public async Task <IActionResult> CreateCredentialDefinitionAsync(OperationBody body) { var context = await _agentContextProvider.GetContextAsync(); var issuer = await _provisionService.GetProvisioningAsync(context.Wallet); var credentialDefinition = body.Data; var schemaId = (string)credentialDefinition["schema_id"]; var tag = (string)credentialDefinition["tag"]; var supportRevocation = (bool)credentialDefinition["support_revocation"]; // Needed to construct credential definition id var schema = JObject.Parse(await _schemaService.LookupSchemaAsync(context, schemaId)); var schemaSeqNo = (string)schema["seqNo"]; var signatureType = "CL"; // TODO: can we make this variable? // The test client sends multiple create credential definition requests with // the same parameters. First check whether the credential definition already exists. var credentialDefinitionId = $"{issuer.IssuerDid}:3:{signatureType}:{schemaSeqNo}:{tag}"; var credentialDefinitionString = await this.LookupCredentialDefinitionByIdAsync(credentialDefinitionId); // If the credential defintion doesn't already exists, create it if (credentialDefinitionString == null) { await _schemaService.CreateCredentialDefinitionAsync(context, new CredentialDefinitionConfiguration { SchemaId = schemaId, Tag = tag, EnableRevocation = supportRevocation, IssuerDid = issuer.IssuerDid }); } return(Ok(new { credential_definition_id = credentialDefinitionId })); }
internal static async Task <(CredentialRecord issuerCredential, CredentialRecord holderCredential)> IssueCredentialAsync( ISchemaService schemaService, ICredentialService credentialService, IProducerConsumerCollection <IEnvelopeMessage> messages, string issuerConnectionId, Wallet issuerWallet, Wallet holderWallet, Pool pool, string proverMasterSecretId, bool revocable) { // Create an issuer DID/VK. Can also be created during provisioning var issuer = await Did.CreateAndStoreMyDidAsync(issuerWallet, new { seed = "000000000000000000000000Steward1" }.ToJson()); // Creata a schema and credential definition for this issuer var schemaId = await schemaService.CreateSchemaAsync(pool, issuerWallet, issuer.Did, $"Test-Schema-{Guid.NewGuid().ToString()}", "1.0", new[] { "first_name", "last_name" }); var definitionId = await schemaService.CreateCredentialDefinitionAsync(pool, issuerWallet, schemaId, issuer.Did, revocable, 100, new Uri("http://mock/tails")); var offerConfig = new DefaultCreateOfferConfiguration() { ConnectionId = issuerConnectionId, IssuerDid = issuer.Did, CredentialDefinitionId = definitionId }; // Send an offer to the holder using the established connection channel await credentialService.SendOfferAsync(issuerWallet, offerConfig); // Holder retrives message from their cloud agent var credentialOffer = FindContentMessage <CredentialOfferMessage>(messages); // Holder processes the credential offer by storing it var holderCredentialId = await credentialService.ProcessOfferAsync(holderWallet, credentialOffer); // Holder creates master secret. Will also be created during wallet agent provisioning await AnonCreds.ProverCreateMasterSecretAsync(holderWallet, proverMasterSecretId); // Holder accepts the credential offer and sends a credential request await credentialService.AcceptOfferAsync(holderWallet, pool, holderCredentialId, new Dictionary <string, string> { { "first_name", "Jane" }, { "last_name", "Doe" } }); // Issuer retrieves credential request from cloud agent var credentialRequest = FindContentMessage <CredentialRequestMessage>(messages); Assert.NotNull(credentialRequest); // Issuer processes the credential request by storing it var issuerCredentialId = await credentialService.ProcessCredentialRequestAsync(issuerWallet, credentialRequest); // Issuer accepts the credential requests and issues a credential await credentialService.IssueCredentialAsync(pool, issuerWallet, issuer.Did, issuerCredentialId); // Holder retrieves the credential from their cloud agent var credential = FindContentMessage <CredentialMessage>(messages); Assert.NotNull(credential); // Holder processes the credential by storing it in their wallet await credentialService.ProcessCredentialAsync(pool, holderWallet, credential); // Verify states of both credential records are set to 'Issued' var issuerCredential = await credentialService.GetAsync(issuerWallet, issuerCredentialId); var holderCredential = await credentialService.GetAsync(holderWallet, holderCredentialId); return(issuerCredential, holderCredential); }