public static async Task Execute() { Console.WriteLine("Wallet sample -> started"); var firstWalletConfig = "{\"id\":\"my_wallet\"}"; var secondWalletConfig = "{\"id\":\"their_wallet\"}"; var firstWalletCredentials = "{\"key\":\"my_wallet_key\"}"; var secondWalletCredentials = "{\"key\":\"their_wallet_key\"}"; try { // Create and Open First Wallet await WalletUtils.CreateWalletAsync(firstWalletConfig, firstWalletCredentials); using (var firstWallet = await Wallet.OpenWalletAsync(firstWalletConfig, firstWalletCredentials)) { // Create a DID that we will retrieve and compare from imported wallet var myDid = await Did.CreateAndStoreMyDidAsync(firstWallet, "{}"); var path = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); var exportConfig = JsonConvert.SerializeObject(new { path = path, key = Guid.NewGuid().ToString() }); await firstWallet.ExportAsync(exportConfig); // Import the exported wallet into a new wallet await Wallet.ImportAsync(secondWalletConfig, secondWalletCredentials, exportConfig); // Open the second wallet using (var secondWallet = await Wallet.OpenWalletAsync(secondWalletConfig, secondWalletCredentials)) { // Retrieve stored key var myKey = await Did.KeyForLocalDidAsync(secondWallet, myDid.Did); // Compare the two keys Debug.Assert(myKey == myDid.VerKey); await secondWallet.CloseAsync(); } // Close wallets await firstWallet.CloseAsync(); File.Delete(path); } } finally { // 11. Delete wallets and Pool ledger config await WalletUtils.DeleteWalletAsync(firstWalletConfig, firstWalletCredentials); await WalletUtils.DeleteWalletAsync(secondWalletConfig, secondWalletCredentials); } Console.WriteLine("Wallet sample -> completed"); }
public static async Task Execute() { Console.Write("Executing non-secrets sample... "); var myWalletConfig = "{\"id\":\"my_wallet\"}"; var myWalletCredentials = "{\"key\":\"my_wallet_key\"}"; try { // Create and Open First Wallet await WalletUtils.CreateWalletAsync(myWalletConfig, myWalletCredentials); using (var myWallet = await Wallet.OpenWalletAsync(myWalletConfig, myWalletCredentials)) { var id = "myRecordId"; var value = "myRecordValue"; var type = "record_type"; var tagsJson = JsonConvert.SerializeObject(new { tagName = "tagValue", tagName2 = "tagValue2" }); var queryJson = JsonConvert.SerializeObject(new { tagName = "tagValue" }); // Add a new record to the wallet await NonSecrets.AddRecordAsync(myWallet, type, id, value, tagsJson); // Retrieve the record by type and id var recordJson = await NonSecrets.GetRecordAsync(myWallet, type, id, "{}"); var record = JObject.Parse(recordJson); Debug.Assert(record["id"].ToObject <string>() == id); Debug.Assert(record["value"].ToObject <string>() == value); // Open wallet search inside using statement to properly dispose and close the search handle using (var walletSearch = await NonSecrets.OpenSearchAsync(myWallet, type, queryJson, "{}")) { // Invoke fetch next records var searchJson = await walletSearch.NextAsync(myWallet, 5); var search = JObject.Parse(searchJson); // There should be one record returned Debug.Assert(search["records"].ToObject <JObject[]>().Length == 1); } // Close wallets await myWallet.CloseAsync(); } Console.WriteLine("OK", Color.Green); } catch (Exception e) { Console.WriteLine($"Error: {e.Message}", Color.Red); } finally { // Delete wallets await WalletUtils.DeleteWalletAsync(myWalletConfig, myWalletCredentials); } }
public async Task Initialize() { // 1. Create ledger config from genesis txn file await PoolUtils.CreatePoolLedgerConfig(); // 2. Create and Open My Wallet await WalletUtils.CreateWalletAsync(PoolUtils.DEFAULT_POOL_NAME, myWalletName, "default", null, null); //3. Open pool and wallets in using statements to ensure they are closed when finished. pool = await Pool.OpenPoolLedgerAsync(PoolUtils.DEFAULT_POOL_NAME, "{}"); wallet = await Wallet.OpenWalletAsync(myWalletName, null, null); Console.WriteLine($"Wallet and pool opened: {pool} {wallet}"); }
public static async Task Execute() { Console.WriteLine("Anoncreds Revocation sample -> started"); var issuerWalletName = "issuerWallet"; var proverWalletName = "proverWallet"; var issuerWalletCredentials = "{\"key\":\"issuer_wallet_key\"}"; var proverWalletCredentials = "{\"key\":\"prover_wallet_key\"}"; var issuerDid = "NcYxiDXkpYi6ov5FcYDi1e"; var proverDid = "VsKV7grR1BUE29mG2Fm2kX"; try { //1. Create and Open Pool await PoolUtils.CreatePoolLedgerConfig(); //2. Issuer Create and Open Wallet await WalletUtils.CreateWalletAsync(PoolUtils.DEFAULT_POOL_NAME, issuerWalletName, "default", null, issuerWalletCredentials); //3. Prover Create and Open Wallet await WalletUtils.CreateWalletAsync(PoolUtils.DEFAULT_POOL_NAME, proverWalletName, "default", null, proverWalletCredentials); // Open pool and wallets in using statements to ensure they are closed when finished. using (var pool = await Pool.OpenPoolLedgerAsync(PoolUtils.DEFAULT_POOL_NAME, "{}")) using (var issuerWallet = await Wallet.OpenWalletAsync(issuerWalletName, null, issuerWalletCredentials)) using (var proverWallet = await Wallet.OpenWalletAsync(proverWalletName, null, proverWalletCredentials)) { //4. Issuer Creates Credential Schema var schemaName = "gvt"; var schemaVersion = "1.0"; var schemaAttributes = "[\"name\", \"age\", \"sex\", \"height\"]"; var createSchemaResult = await AnonCreds.IssuerCreateSchemaAsync(issuerDid, schemaName, schemaVersion, schemaAttributes); var schemaId = createSchemaResult.SchemaId; var schemaJson = createSchemaResult.SchemaJson; //5. Issuer create Credential Definition var credDefTag = "Tag1"; var credDefConfigJson = "{\"support_revocation\":true}"; var createCredDefResult = await AnonCreds.IssuerCreateAndStoreCredentialDefAsync(issuerWallet, issuerDid, schemaJson, credDefTag, null, credDefConfigJson); var credDefId = createCredDefResult.CredDefId; var credDefJson = createCredDefResult.CredDefJson; //6. Issuer create Revocation Registry var revRegDefConfig = "{\"issuance_type\":\"ISSUANCE_ON_DEMAND\",\"max_cred_num\":5}"; var tailsWriterConfig = string.Format("{{\"base_dir\":\"{0}\", \"uri_pattern\":\"\"}}", EnvironmentUtils.GetIndyHomePath("tails")).Replace('\\', '/'); var tailsWriter = await BlobStorage.OpenWriterAsync("default", tailsWriterConfig); var revRegDefTag = "Tag2"; var createRevRegResult = await AnonCreds.IssuerCreateAndStoreRevocRegAsync(issuerWallet, issuerDid, null, revRegDefTag, credDefId, revRegDefConfig, tailsWriter); var revRegId = createRevRegResult.RevRegId; var revRegDefJson = createRevRegResult.RevRegDefJson; //7. Prover create Master Secret var masterSecretId = await AnonCreds.ProverCreateMasterSecretAsync(proverWallet, null); //8. Issuer Creates Credential Offer var credOffer = await AnonCreds.IssuerCreateCredentialOfferAsync(issuerWallet, credDefId); //9. Prover Creates Credential Request var createCredReqResult = await AnonCreds.ProverCreateCredentialReqAsync(proverWallet, proverDid, credOffer, credDefJson, masterSecretId); var credReqJson = createCredReqResult.CredentialRequestJson; var credReqMetadataJson = createCredReqResult.CredentialRequestMetadataJson; //10. Issuer open Tails Reader var blobStorageReaderCfg = await BlobStorage.OpenReaderAsync("default", tailsWriterConfig); //11. Issuer create Credential var credValuesJson = "{\n" + " \"sex\": {\"raw\": \"male\", \"encoded\": \"594465709955896723921094925839488742869205008160769251991705001\"},\n" + " \"name\": {\"raw\": \"Alex\", \"encoded\": \"1139481716457488690172217916278103335\"},\n" + " \"height\": {\"raw\": \"175\", \"encoded\": \"175\"},\n" + " \"age\": {\"raw\": \"28\", \"encoded\": \"28\"}\n" + " }"; var createCredentialResult = await AnonCreds.IssuerCreateCredentialAsync(issuerWallet, credOffer, credReqJson, credValuesJson, revRegId, blobStorageReaderCfg); var credential = createCredentialResult.CredentialJson; var revRegDeltaJson = createCredentialResult.RevocRegDeltaJson; var credRevId = createCredentialResult.RevocId; //12. Prover Stores Credential await AnonCreds.ProverStoreCredentialAsync(proverWallet, null, credReqMetadataJson, credential, credDefJson, revRegDefJson); //13. Prover Gets Credentials for Proof Request var proofRequestJson = "{\n" + " \"nonce\":\"123432421212\",\n" + " \"name\":\"proof_req_1\",\n" + " \"version\":\"0.1\", " + " \"requested_attributes\":{" + " \"attr1_referent\":{\"name\":\"name\"}" + " },\n" + " \"requested_predicates\":{" + " \"predicate1_referent\":{\"name\":\"age\",\"p_type\":\">=\",\"p_value\":18}" + " }" + " }"; var credentialsForProofJson = await AnonCreds.ProverGetCredentialsForProofReqAsync(proverWallet, proofRequestJson); var credentials = JObject.Parse(credentialsForProofJson); var credentialsForAttr1 = (JArray)credentials["attrs"]["attr1_referent"]; var credentialsForPredicate1 = (JArray)credentials["predicates"]["predicate1_referent"]; var credIdForAttr1 = credentialsForAttr1[0]["cred_info"]["referent"].ToObject <string>(); var credIdForPred1 = credentialsForPredicate1[0]["cred_info"]["referent"].ToObject <string>(); //14. Prover create RevocationState long timestamp = 100; var revStateJson = await AnonCreds.CreateRevocationStateAsync(blobStorageReaderCfg, revRegDefJson, revRegDeltaJson, timestamp, credRevId); //15. Prover Creates Proof var requestedCredentialsJson = string.Format("{{" + "\"self_attested_attributes\":{{}}," + "\"requested_attributes\":{{\"attr1_referent\":{{\"cred_id\":\"{0}\", \"revealed\":true, \"timestamp\":{1} }}}}," + "\"requested_predicates\":{{\"predicate1_referent\":{{\"cred_id\":\"{2}\", \"timestamp\":{3}}}}}" + "}}", credIdForAttr1, timestamp, credIdForPred1, timestamp); var schemas = string.Format("{{\"{0}\":{1}}}", schemaId, schemaJson); var credentialDefs = string.Format("{{\"{0}\":{1}}}", credDefId, credDefJson); var revStates = string.Format("{{\"{0}\": {{ \"{1}\":{2} }}}}", revRegId, timestamp, revStateJson); var proofJson = await AnonCreds.ProverCreateProofAsync(proverWallet, proofRequestJson, requestedCredentialsJson, masterSecretId, schemas, credentialDefs, revStates); var proof = JObject.Parse(proofJson); //16. Verifier verify Proof var revealedAttr1 = proof["requested_proof"]["revealed_attrs"]["attr1_referent"]; Debug.Assert("Alex" == revealedAttr1["raw"].ToObject <string>()); var revRegDefs = string.Format("{{\"{0}\":{1}}}", revRegId, revRegDefJson); var revRegs = string.Format("{{\"{0}\": {{ \"{1}\":{2} }}}}", revRegId, timestamp, revRegDeltaJson); var valid = await AnonCreds.VerifierVerifyProofAsync(proofRequestJson, proofJson, schemas, credentialDefs, revRegDefs, revRegs); Debug.Assert(valid); await issuerWallet.CloseAsync(); await proverWallet.CloseAsync(); await pool.CloseAsync(); } } finally { //17. Delete wallets and Pool ledger config await WalletUtils.DeleteWalletAsync(issuerWalletName, issuerWalletCredentials); await WalletUtils.DeleteWalletAsync(proverWalletName, proverWalletCredentials); await PoolUtils.DeletePoolLedgerConfigAsync(PoolUtils.DEFAULT_POOL_NAME); } Console.WriteLine("Anoncreds Revocation sample -> completed"); }
public static async Task Execute() { Console.WriteLine("Ledger sample -> started"); var myWalletName = "myWallet"; var theirWalletName = "theirWallet"; var trusteeSeed = "000000000000000000000000Trustee1"; try { // 1. Create ledger config from genesis txn file await PoolUtils.CreatePoolLedgerConfig(); // 2. Create and Open My Wallet await WalletUtils.CreateWalletAsync(PoolUtils.DEFAULT_POOL_NAME, myWalletName, "default", null, null); // 3. Create and Open Trustee Wallet await WalletUtils.CreateWalletAsync(PoolUtils.DEFAULT_POOL_NAME, theirWalletName, "default", null, null); //4. Open pool and wallets in using statements to ensure they are closed when finished. using (var pool = await Pool.OpenPoolLedgerAsync(PoolUtils.DEFAULT_POOL_NAME, "{}")) using (var myWallet = await Wallet.OpenWalletAsync(myWalletName, null, null)) using (var trusteeWallet = await Wallet.OpenWalletAsync(theirWalletName, null, null)) { //5. Create My Did var createMyDidResult = await Did.CreateAndStoreMyDidAsync(myWallet, "{}"); var myDid = createMyDidResult.Did; var myVerkey = createMyDidResult.VerKey; //6. Create Did from Trustee1 seed var theirDidJson = string.Format("{{\"seed\":\"{0}\"}}", trusteeSeed); var createTheirDidResult = await Did.CreateAndStoreMyDidAsync(trusteeWallet, theirDidJson); var trusteeDid = createTheirDidResult.Did; //7. Build Nym Request var nymRequest = await Ledger.BuildNymRequestAsync(trusteeDid, myDid, myVerkey, null, null); //8. Trustee Sign Nym Request var nymResponseJson = await Ledger.SignAndSubmitRequestAsync(pool, trusteeWallet, trusteeDid, nymRequest); var nymResponse = JObject.Parse(nymResponseJson); Debug.Assert(string.Equals(myDid, nymResponse["result"].Value <string>("dest"))); Debug.Assert(string.Equals(myVerkey, nymResponse["result"].Value <string>("verkey"))); //9. Close wallets and pool await myWallet.CloseAsync(); await trusteeWallet.CloseAsync(); await pool.CloseAsync(); } } finally { //10. Delete wallets and Pool ledger config await WalletUtils.DeleteWalletAsync(myWalletName, null); await WalletUtils.DeleteWalletAsync(theirWalletName, null); await PoolUtils.DeletePoolLedgerConfigAsync(PoolUtils.DEFAULT_POOL_NAME); } Console.WriteLine("Ledger sample -> completed"); }
public static async Task Execute() { Console.WriteLine("Anoncreds sample -> started"); var issuerWalletName = "issuerWallet"; var proverWalletName = "proverWallet"; var issuerWalletCredentials = "{\"key\":\"issuer_wallet_key\"}"; var proverWalletCredentials = "{\"key\":\"prover_wallet_key\"}"; var issuerDid = "NcYxiDXkpYi6ov5FcYDi1e"; var proverDid = "VsKV7grR1BUE29mG2Fm2kX"; try { //1. Create and Open Pool await PoolUtils.CreatePoolLedgerConfig(); //2. Issuer Create and Open Wallet await WalletUtils.CreateWalletAsync(PoolUtils.DEFAULT_POOL_NAME, issuerWalletName, "default", null, issuerWalletCredentials); //3. Prover Create and Open Wallet await WalletUtils.CreateWalletAsync(PoolUtils.DEFAULT_POOL_NAME, proverWalletName, "default", null, proverWalletCredentials); // Open pool and wallets in using statements to ensure they are closed when finished. using (var pool = await Pool.OpenPoolLedgerAsync(PoolUtils.DEFAULT_POOL_NAME, "{}")) using (var issuerWallet = await Wallet.OpenWalletAsync(issuerWalletName, null, issuerWalletCredentials)) using (var proverWallet = await Wallet.OpenWalletAsync(proverWalletName, null, proverWalletCredentials)) { //4. Issuer Creates Credential Schema var schemaName = "gvt"; var schemaVersion = "1.0"; var schemaAttributes = "[\"name\", \"age\", \"sex\", \"height\"]"; var createSchemaResult = await AnonCreds.IssuerCreateSchemaAsync(issuerDid, schemaName, schemaVersion, schemaAttributes); var schemaId = createSchemaResult.SchemaId; var schemaJson = createSchemaResult.SchemaJson; //5. Issuer create Credential Definition var credDefTag = "Tag1"; var credDefConfigJson = "{\"support_revocation\":false}"; var createCredDefResult = await AnonCreds.IssuerCreateAndStoreCredentialDefAsync(issuerWallet, issuerDid, schemaJson, credDefTag, null, credDefConfigJson); var credDefId = createCredDefResult.CredDefId; var credDefJson = createCredDefResult.CredDefJson; //6. Prover create Master Secret var masterSecretId = await AnonCreds.ProverCreateMasterSecretAsync(proverWallet, null); //7. Issuer Creates Credential Offer var credOffer = await AnonCreds.IssuerCreateCredentialOfferAsync(issuerWallet, credDefId); //8. Prover Creates Credential Request var createCredReqResult = await AnonCreds.ProverCreateCredentialReqAsync(proverWallet, proverDid, credOffer, credDefJson, masterSecretId); var credReqJson = createCredReqResult.CredentialRequestJson; var credReqMetadataJson = createCredReqResult.CredentialRequestMetadataJson; //9. Issuer create Credential var credValuesJson = "{\n" + " \"sex\": {\"raw\": \"male\", \"encoded\": \"594465709955896723921094925839488742869205008160769251991705001\"},\n" + " \"name\": {\"raw\": \"Alex\", \"encoded\": \"1139481716457488690172217916278103335\"},\n" + " \"height\": {\"raw\": \"175\", \"encoded\": \"175\"},\n" + " \"age\": {\"raw\": \"28\", \"encoded\": \"28\"}\n" + " }"; var createCredentialResult = await AnonCreds.IssuerCreateCredentialAsync(issuerWallet, credOffer, credReqJson, credValuesJson, null, null); var credential = createCredentialResult.CredentialJson; //10. Prover Stores Credential await AnonCreds.ProverStoreCredentialAsync(proverWallet, null, credReqJson, credReqMetadataJson, credential, credDefJson, null); //11. Prover Gets Credentials for Proof Request var proofRequestJson = "{" + " \"nonce\":\"123432421212\",\n" + " \"name\":\"proof_req_1\",\n" + " \"version\":\"0.1\", " + " \"requested_attributes\": {" + " \"attr1_referent\":{\"name\":\"name\"}," + " \"attr2_referent\":{\"name\":\"sex\"}," + " \"attr3_referent\":{\"name\":\"phone\"}" + " }," + " \"requested_predicates\":{" + " \"predicate1_referent\":{\"name\":\"age\",\"p_type\":\">=\",\"p_value\":18}" + " }" + " }"; var credentialsForProofJson = await AnonCreds.ProverGetCredentialsForProofReqAsync(proverWallet, proofRequestJson); var credentialsForProof = JObject.Parse(credentialsForProofJson); var credentialsForAttribute1 = (JArray)credentialsForProof["attrs"]["attr1_referent"]; var credentialsForAttribute2 = (JArray)credentialsForProof["attrs"]["attr2_referent"]; var credentialsForAttribute3 = (JArray)credentialsForProof["attrs"]["attr3_referent"]; var credentialsForPredicate = (JArray)credentialsForProof["predicates"]["predicate1_referent"]; Debug.Assert(credentialsForAttribute1.Count == 1); Debug.Assert(credentialsForAttribute2.Count == 1); Debug.Assert(credentialsForAttribute3.Count == 0); Debug.Assert(credentialsForPredicate.Count == 1); var credentialId = credentialsForAttribute1[0]["cred_info"]["referent"].ToObject <string>(); //12. Prover Creates Proof var selfAttestedValue = "8-800-300"; var requestedCredentialsJson = string.Format( "{{\n" + " \"self_attested_attributes\":{{\"attr3_referent\":\"{0}\"}},\n" + " \"requested_attributes\":{{\"attr1_referent\":{{\"cred_id\":\"{1}\", \"revealed\":true}},\n" + " \"attr2_referent\":{{\"cred_id\":\"{2}\", \"revealed\":false}}}},\n" + " \"requested_predicates\":{{\"predicate1_referent\":{{\"cred_id\":\"{3}\"}}}}\n" + " }}", selfAttestedValue, credentialId, credentialId, credentialId); var schemas = string.Format("{{\"{0}\":{1}}}", schemaId, schemaJson); var credentialDefs = string.Format("{{\"{0}\":{1}}}", credDefId, credDefJson); var revocStates = "{}"; var proofJson = await AnonCreds.ProverCreateProofAsync(proverWallet, proofRequestJson, requestedCredentialsJson, masterSecretId, schemas, credentialDefs, revocStates); var proof = JObject.Parse(proofJson); //13. Verifier verify Proof var revealedAttr1 = proof["requested_proof"]["revealed_attrs"]["attr1_referent"]; Debug.Assert("Alex" == revealedAttr1["raw"].ToObject <string>()); Debug.Assert(null != proof["requested_proof"]["unrevealed_attrs"]["attr2_referent"]["sub_proof_index"]); Debug.Assert(selfAttestedValue == proof["requested_proof"]["self_attested_attrs"]["attr3_referent"].ToObject <string>()); var revocRegDefs = "{}"; var revocRegs = "{}"; var valid = await AnonCreds.VerifierVerifyProofAsync(proofRequestJson, proofJson, schemas, credentialDefs, revocRegDefs, revocRegs); Debug.Assert(valid); //14. Close wallets and pool await issuerWallet.CloseAsync(); await proverWallet.CloseAsync(); await pool.CloseAsync(); } } finally { //15. Delete wallets and Pool ledger config await WalletUtils.DeleteWalletAsync(issuerWalletName, issuerWalletCredentials); await WalletUtils.DeleteWalletAsync(proverWalletName, proverWalletCredentials); await PoolUtils.DeletePoolLedgerConfigAsync(PoolUtils.DEFAULT_POOL_NAME); } Console.WriteLine("Anoncreds sample -> completed"); }
public static async Task Execute() { Console.WriteLine("Crypto sample -> started"); var myWalletName = "myWallet"; var theirWalletName = "theirWallet"; var myWalletCredentials = "{\"key\":\"issuer_wallet_key\"}"; var theirWalletCredentials = "{\"key\":\"prover_wallet_key\"}"; try { //1. Create and Open Pool await PoolUtils.CreatePoolLedgerConfig(); //2. Create and Open My Wallet await WalletUtils.CreateWalletAsync(PoolUtils.DEFAULT_POOL_NAME, myWalletName, "default", null, myWalletCredentials); // 3. Create and Open Trustee Wallet await WalletUtils.CreateWalletAsync(PoolUtils.DEFAULT_POOL_NAME, theirWalletName, "default", null, theirWalletCredentials); //4. Open pool and wallets in using statements to ensure they are closed when finished. using (var pool = await Pool.OpenPoolLedgerAsync(PoolUtils.DEFAULT_POOL_NAME, "{}")) using (var myWallet = await Wallet.OpenWalletAsync(myWalletName, null, myWalletCredentials)) using (var theirWallet = await Wallet.OpenWalletAsync(theirWalletName, null, theirWalletCredentials)) { //5. Create My Did var createMyDidResult = await Did.CreateAndStoreMyDidAsync(myWallet, "{}"); //6. Create Their Did var createTheirDidResult = await Did.CreateAndStoreMyDidAsync(theirWallet, "{}"); var theirDid = createTheirDidResult.Did; var theirVerkey = createTheirDidResult.VerKey; //7. Store Their DID var identityJson = string.Format("{{\"did\":\"{0}\", \"verkey\":\"{1}\"}}", theirDid, theirVerkey); await Did.StoreTheirDidAsync(myWallet, identityJson); //8. Their sign message var msgBytes = Encoding.UTF8.GetBytes("{\n" + " \"reqId\":1495034346617224651,\n" + " \"identifier\":\"GJ1SzoWzavQYfNL9XkaJdrQejfztN4XqdsiV4ct3LXKL\",\n" + " \"operation\":{\n" + " \"type\":\"1\",\n" + " \"dest\":\"4efZu2SXufS556yss7W5k6Po37jt4371RM4whbPKBKdB\"\n" + " }\n" + "}"); var signatureBytes = await Crypto.SignAsync(theirWallet, theirVerkey, msgBytes); //9. Verify message var valid = await Crypto.VerifyAsync(theirVerkey, msgBytes, signatureBytes); Debug.Assert(valid == true); //10. Close wallets and pool await myWallet.CloseAsync(); await theirWallet.CloseAsync(); await pool.CloseAsync(); } } finally { // 11. Delete wallets and Pool ledger config await WalletUtils.DeleteWalletAsync(myWalletName, myWalletCredentials); await WalletUtils.DeleteWalletAsync(theirWalletName, theirWalletCredentials); await PoolUtils.DeletePoolLedgerConfigAsync(PoolUtils.DEFAULT_POOL_NAME); } Console.WriteLine("Crypto sample -> completed"); }
public static async Task Execute() { Console.Write("Executing ledger sample (requires local pool node)... "); var myWalletConfig = "{\"id\":\"my_wallet\"}"; var theirWalletConfig = "{\"id\":\"their_wallet\"}"; var trusteeSeed = "000000000000000000000000Trustee1"; var myWalletCredentials = "{\"key\":\"issuer_wallet_key\"}"; var theirWalletCredentials = "{\"key\":\"prover_wallet_key\"}"; try { // 1. Create ledger config from genesis txn file await PoolUtils.CreatePoolLedgerConfig(); //2. Create and Open My Wallet await WalletUtils.CreateWalletAsync(myWalletConfig, myWalletCredentials); // 3. Create and Open Trustee Wallet await WalletUtils.CreateWalletAsync(theirWalletConfig, theirWalletCredentials); //4. Open pool and wallets in using statements to ensure they are closed when finished. using (var pool = await Pool.OpenPoolLedgerAsync(PoolUtils.DEFAULT_POOL_NAME, "{}")) using (var myWallet = await Wallet.OpenWalletAsync(myWalletConfig, myWalletCredentials)) using (var trusteeWallet = await Wallet.OpenWalletAsync(theirWalletConfig, theirWalletCredentials)) { //5. Create My Did var createMyDidResult = await Did.CreateAndStoreMyDidAsync(myWallet, "{}"); var myDid = createMyDidResult.Did; var myVerkey = createMyDidResult.VerKey; //6. Create Did from Trustee1 seed var theirDidJson = string.Format("{{\"seed\":\"{0}\"}}", trusteeSeed); var createTheirDidResult = await Did.CreateAndStoreMyDidAsync(trusteeWallet, theirDidJson); var trusteeDid = createTheirDidResult.Did; //7. Build Nym Request var nymRequest = await Ledger.BuildNymRequestAsync(trusteeDid, myDid, myVerkey, null, null); //8. Trustee Sign Nym Request var nymResponseJson = await Ledger.SignAndSubmitRequestAsync(pool, trusteeWallet, trusteeDid, nymRequest); var nymResponse = JObject.Parse(nymResponseJson); Debug.Assert(string.Equals(myDid, nymResponse["result"]["txn"]["data"]["dest"].ToObject <string>())); Debug.Assert(string.Equals(myVerkey, nymResponse["result"]["txn"]["data"]["verkey"].ToObject <string>())); //9. Close wallets and pool await myWallet.CloseAsync(); await trusteeWallet.CloseAsync(); await pool.CloseAsync(); } Console.WriteLine("OK", Color.Green); } catch (Exception e) { Console.WriteLine($"Error: {e.Message}", Color.Red); } finally { //10. Delete wallets and Pool ledger config await WalletUtils.DeleteWalletAsync(myWalletConfig, myWalletCredentials); await WalletUtils.DeleteWalletAsync(theirWalletConfig, theirWalletCredentials); await PoolUtils.DeletePoolLedgerConfigAsync(PoolUtils.DEFAULT_POOL_NAME); } }