예제 #1
0
        public async Task ClosingDisposedPoolStillProvidesSDKError()
        {
            var poolName = PoolUtils.CreatePoolLedgerConfig();

            var pool = await Pool.OpenPoolLedgerAsync(poolName, null);

            pool.Dispose();

            var ex = await Assert.ThrowsExceptionAsync <InvalidPoolException>(() =>
                                                                              pool.CloseAsync()
                                                                              );
        }
예제 #2
0
        public async Task TestOpenPoolWorksForTwice()
        {
            var poolName = PoolUtils.CreatePoolLedgerConfig();
            var pool     = await Pool.OpenPoolLedgerAsync(poolName, null);

            Assert.IsNotNull(pool);
            openedPools.Add(pool);

            var ex = await Assert.ThrowsExceptionAsync <InvalidPoolException>(() =>
                                                                              Pool.OpenPoolLedgerAsync(poolName, null)
                                                                              );
        }
예제 #3
0
        public async Task PoolWithSameNameCanBeOpenedAfterDispose()
        {
            var poolName = PoolUtils.CreatePoolLedgerConfig();

            var pool = await Pool.OpenPoolLedgerAsync(poolName, null);

            pool.Dispose();

            using (var newPool = await Pool.OpenPoolLedgerAsync(poolName, null))
            {
            }
        }
예제 #4
0
        public async Task TestDeletePoolWorksForOpened()
        {
            Pool.SetProtocolVersionAsync(PoolUtils.PROTOCOL_VERSION).Wait();
            var poolName = PoolUtils.CreatePoolLedgerConfig();
            var pool     = await Pool.OpenPoolLedgerAsync(poolName, null);

            Assert.IsNotNull(pool);
            openedPools.Add(pool);

            var ex = await Assert.ThrowsExceptionAsync <InvalidStateException>(() =>
                                                                               Pool.DeletePoolLedgerConfigAsync(poolName)
                                                                               );
        }
예제 #5
0
        public async Task TestAutoCloseWorks()
        {
            var poolName = PoolUtils.CreatePoolLedgerConfig();

            using (var autoClosePool = await Pool.OpenPoolLedgerAsync(poolName, null))
            {
                Assert.IsNotNull(autoClosePool);
            }

            var pool = await Pool.OpenPoolLedgerAsync(poolName, null);

            openedPools.Add(pool);
        }
예제 #6
0
        public async Task TestCreatePoolWorksForEmptyName()
        {
            var genesisTxnFile = PoolUtils.CreateGenesisTxnFile("genesis.txn");
            var path           = Path.GetFullPath(genesisTxnFile).Replace('\\', '/');

            var configJson = string.Format("{{\"genesis_txn\":\"{0}\"}}", path);

            var ex = await Assert.ThrowsExceptionAsync <IndyException>(() =>
                                                                       Pool.CreatePoolLedgerConfigAsync("", configJson)
                                                                       );

            Assert.AreEqual(ErrorCode.CommonInvalidParam2, ex.ErrorCode);
        }
예제 #7
0
        public async Task TestRevocRegRequestsWorks()
        {
            await PostEntitiesAsync();

            var getRevRegDefRequest = await Ledger.BuildGetRevocRegDefRequestAsync(DID, revRegDefId);

            var getRevRegDefResponse = await PoolUtils.EnsurePreviousRequestAppliedAsync(pool, getRevRegDefRequest, response => {
                var responseObject = JObject.Parse(response);
                return(responseObject["result"]["seqNo"] != null);
            });

            await Ledger.ParseGetRevocRegDefResponseAsync(getRevRegDefResponse);
        }
예제 #8
0
        public async Task TestClosePoolWorksForReopenAfterClose()
        {
            var poolName = PoolUtils.CreatePoolLedgerConfig();
            var pool     = await Pool.OpenPoolLedgerAsync(poolName, null);

            Assert.IsNotNull(pool);

            await pool.CloseAsync();

            pool = await Pool.OpenPoolLedgerAsync(poolName, null);

            openedPools.Add(pool);
        }
예제 #9
0
        public async Task TestCreatePoolWorksForTwice()
        {
            var genesisTxnFile = PoolUtils.CreateGenesisTxnFile("genesis.txn");
            var path           = Path.GetFullPath(genesisTxnFile.Name).Replace('\\', '/');

            var configJson = string.Format("{{\"genesis_txn\":\"{0}\"}}", path);

            await Pool.CreatePoolLedgerConfigAsync("pool1", configJson);

            var ex = await Assert.ThrowsExceptionAsync <PoolLedgerConfigExistsException>(() =>
                                                                                         Pool.CreatePoolLedgerConfigAsync("pool1", configJson)
                                                                                         );;
        }
예제 #10
0
        public async Task TestDeletePoolWorksForOpened()
        {
            var poolName = PoolUtils.CreatePoolLedgerConfig();
            var pool     = await Pool.OpenPoolLedgerAsync(poolName, null);

            Assert.IsNotNull(pool);
            _openedPools.Add(pool);

            var ex = await Assert.ThrowsExceptionAsync <IndyException>(() =>
                                                                       Pool.DeletePoolLedgerConfigAsync(poolName)
                                                                       );

            Assert.AreEqual(ErrorCode.CommonInvalidState, ex.ErrorCode);
        }
예제 #11
0
        public async Task TestOpenPoolWorksForTwice()
        {
            var poolName = PoolUtils.CreatePoolLedgerConfig();
            var pool     = await Pool.OpenPoolLedgerAsync(poolName, null);

            Assert.IsNotNull(pool);
            _openedPools.Add(pool);

            var ex = await Assert.ThrowsExceptionAsync <IndyException>(() =>
                                                                       Pool.OpenPoolLedgerAsync(poolName, null)
                                                                       );

            Assert.AreEqual(ErrorCode.PoolLedgerInvalidPoolHandle, ex.ErrorCode);
        }
예제 #12
0
        public async Task TestOpenPoolWorksForIncompatibleProtocolVersion()
        {
            await Pool.SetProtocolVersionAsync(PROTOCOL_VERSION);

            var poolName = PoolUtils.CreatePoolLedgerConfig();
            var pool     = await Pool.OpenPoolLedgerAsync(poolName, null);

            Assert.IsNotNull(pool);
            openedPools.Add(pool);

            var ex = await Assert.ThrowsExceptionAsync <PoolIncompatibleProtocolVersionException>(() =>
                                                                                                  Pool.SetProtocolVersionAsync(10)
                                                                                                  );
        }
예제 #13
0
        public async Task TestClosePoolWorksForTwice()
        {
            var pool = await PoolUtils.CreateAndOpenPoolLedgerAsync();

            Assert.IsNotNull(pool);
            openedPools.Add(pool);

            await pool.CloseAsync();

            openedPools.Remove(pool);

            var ex = await Assert.ThrowsExceptionAsync <InvalidPoolException>(() =>
                                                                              pool.CloseAsync()
                                                                              );
        }
        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}");
        }
예제 #15
0
        public void ListPoolTest()
        {
            string file = PoolUtils.GenerateGenesisFile();

            IPool pool = Factory.GetPool("ListPool", file);

            pool.Create();

            List <IPool> pools = Factory.ListPools();

            Assert.IsNotNull(pools);
            pool.Delete();

            Assert.IsTrue(0 < pools.Count, "expected to find at least one pool");
        }
예제 #16
0
        public async Task InitializeAsync()
        {
            try
            {
                await Wallet.CreateWalletAsync(_issuerConfig, Credentials);
            }
            catch (WalletExistsException)
            {
                // OK
            }

            _issuerWallet = await Wallet.OpenWalletAsync(_issuerConfig, Credentials);

            _pool = await PoolUtils.GetPoolAsync();
        }
        public async Task SetUp()
        {
            await InitHelper.InitAsync();

            StorageUtils.CleanupStorage();

            _poolName = PoolUtils.CreatePoolLedgerConfig();

            var config2 = "{}";

            _pool = await Pool.OpenPoolLedgerAsync(_poolName, config2);

            await Wallet.CreateWalletAsync(_poolName, _walletName, "default", null, null);

            _wallet = await Wallet.OpenWalletAsync(_walletName, null, null);
        }
예제 #18
0
        public async Task TestRevocRegRequestsDeltaWorks()
        {
            await PostEntitiesAsync();

            var timespan = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc));
            var to       = (long)timespan.TotalSeconds + 100;

            var getRevRegRequest = await Ledger.BuildGetRevocRegDeltaRequestAsync(DID, revRegDefId, -1, to);

            var getRevRegResponse = await PoolUtils.EnsurePreviousRequestAppliedAsync(pool, getRevRegRequest, response => {
                var responseObject = JObject.Parse(response);
                return(responseObject["result"]["seqNo"] != null);
            });

            await Ledger.ParseGetRevocRegDeltaResponseAsync(getRevRegResponse);
        }
예제 #19
0
        public async Task CreateWallet()
        {
            //1. Create and Open Pool
            _poolName = PoolUtils.CreatePoolLedgerConfig();

            _pool = await Pool.OpenPoolLedgerAsync(_poolName, "{}");

            //2. Issuer Create and Open Wallet
            await Wallet.CreateWalletAsync(_poolName, "issuerWallet", TYPE, null, null);

            _issuerWallet = await Wallet.OpenWalletAsync("issuerWallet", null, null);

            //3. Prover Create and Open Wallet
            await Wallet.CreateWalletAsync(_poolName, "proverWallet", TYPE, null, null);

            _proverWallet = await Wallet.OpenWalletAsync("proverWallet", null, null);
        }
예제 #20
0
        public async Task CreateWallet()
        {
            //1. Create and Open Pool
            _poolName = PoolUtils.CreatePoolLedgerConfig();

            _pool = await Pool.OpenPoolLedgerAsync(_poolName, "{}");

            //2. Issuer Create and Open Wallet
            await WalletUtils.CreateWallet(ISSUER_WALLET, ISSUER_WALLET_KEY);

            _issuerWallet = await WalletUtils.OpenWallet(ISSUER_WALLET, ISSUER_WALLET_KEY);

            //3. Prover Create and Open Wallet
            await WalletUtils.CreateWallet(PROVER_WALLET, PROVER_WALLET_KEY);

            _proverWallet = await WalletUtils.OpenWallet(PROVER_WALLET, PROVER_WALLET_KEY);
        }
예제 #21
0
        public async Task TestClosePoolWorksForTwice()
        {
            var pool = await PoolUtils.CreateAndOpenPoolLedgerAsync();

            Assert.IsNotNull(pool);
            _openedPools.Add(pool);

            await pool.CloseAsync();

            _openedPools.Remove(pool);

            var ex = await Assert.ThrowsExceptionAsync <IndyException>(() =>
                                                                       pool.CloseAsync()
                                                                       );

            Assert.AreEqual(ErrorCode.PoolLedgerInvalidPoolHandle, ex.ErrorCode);
        }
예제 #22
0
        public async Task CreateWalletWithDid()
        {
            var poolName = PoolUtils.CreatePoolLedgerConfig();

            _pool = await Pool.OpenPoolLedgerAsync(poolName, "{}");

            await Wallet.CreateWalletAsync(poolName, walletName, "default", null, null);

            _wallet = await Wallet.OpenWalletAsync(walletName, null, null);

            var json = "{\"seed\":\"000000000000000000000000Trustee1\",\"cid\":false}";

            var result = await Signus.CreateAndStoreMyDidAsync(_wallet, json);

            Assert.IsNotNull(result);

            _trusteeDid    = result.Did;
            _trusteeVerkey = result.VerKey;
        }
예제 #23
0
        public async Task CreateWallet()
        {
            // Set protocol version
            await Pool.SetProtocolVersionAsync(PROTOCOL_VERSION);

            // Create and Open Pool
            var poolName = PoolUtils.CreatePoolLedgerConfig();

            pool = await Pool.OpenPoolLedgerAsync(poolName, "{}");

            // Issuer Create and Open Wallet
            await Wallet.CreateWalletAsync(issuerWalletConfig, WALLET_CREDENTIALS);

            issuerWallet = await Wallet.OpenWalletAsync(issuerWalletConfig, WALLET_CREDENTIALS);

            // Prover Create and Open Wallet
            await Wallet.CreateWalletAsync(proverWalletConfig, WALLET_CREDENTIALS);

            proverWallet = await Wallet.OpenWalletAsync(proverWalletConfig, WALLET_CREDENTIALS);
        }
예제 #24
0
        public async Task TestNymRequestsWorks()
        {
            var trusteeDidResult = await Did.CreateAndStoreMyDidAsync(wallet, TRUSTEE_IDENTITY_JSON);

            var trusteeDid = trusteeDidResult.Did;

            var myDidResult = await Did.CreateAndStoreMyDidAsync(wallet, "{}");

            var myDid    = myDidResult.Did;
            var myVerKey = myDidResult.VerKey;

            var nymRequest = await Ledger.BuildNymRequestAsync(trusteeDid, myDid, myVerKey, null, null);

            await Ledger.SignAndSubmitRequestAsync(pool, wallet, trusteeDid, nymRequest);

            var getNymRequest = await Ledger.BuildGetNymRequestAsync(myDid, myDid);

            var getNymResponse = PoolUtils.EnsurePreviousRequestAppliedAsync(pool, getNymRequest, response => { return(CompareResponseType(response, "REPLY")); });

            Assert.IsNotNull(getNymResponse);
        }
        public async Task CreateCredentialSchemaAsync(string userId, string name, string version, string[] attributes)
        {
            var walletData = await GetDefaultWalletDataAsync(userId);

            var schema = new { name, version, attr_names = attributes };
            var wallet = await Wallet.OpenWalletAsync(walletData.Name, null, null);

            try
            {
                using (var pool = await PoolUtils.CreateAndOpenPoolLedgerAsync())
                {
                    var schemaRequest = await Ledger.BuildSchemaRequestAsync(walletData.Did, JsonConvert.SerializeObject(schema));

                    var result = await Ledger.SignAndSubmitRequestAsync(pool, wallet, walletData.Did, schemaRequest);

                    Console.WriteLine("=============Schema Request Result===========");
                    Console.WriteLine(result);

                    var schemaData = new CredentialSchema
                    {
                        Id             = Guid.NewGuid(),
                        AttributeArray = attributes,
                        Name           = name,
                        Version        = version,
                        UserId         = userId
                    };

                    _dbContext.CredentialSchemas.Add(schemaData);
                    await _dbContext.SaveChangesAsync();
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                await wallet.CloseAsync();
            }
        }
예제 #26
0
        public async Task CreateWalletWithDid()
        {
            var poolName = PoolUtils.CreatePoolLedgerConfig();

            _pool = await Pool.OpenPoolLedgerAsync(poolName, "{}");

            await Wallet.CreateWalletAsync(poolName, _walletName, "default", null, null);

            _wallet = await Wallet.OpenWalletAsync(_walletName, null, null);

            var trusteeJson = "{\"seed\":\"000000000000000000000000Trustee1\"}";

            var trusteeNym = await Signus.CreateAndStoreMyDidAsync(_wallet, trusteeJson);

            _trusteeDid    = trusteeNym.Did;
            _trusteeVerkey = trusteeNym.VerKey;

            var otherDid = "{\"seed\":\"00000000000000000000000000000My1\"}";

            var myNym = await Signus.CreateAndStoreMyDidAsync(_wallet, otherDid);

            _myDid    = myNym.Did;
            _myVerkey = myNym.VerKey;
        }
예제 #27
0
        public static async Task Execute()
        {
            Console.WriteLine("Ledger sample -> started");

            var myWalletName    = "myWallet";
            var theirWalletName = "theirWallet";

            try
            {
                //1. Create and Open Pool
                await PoolUtils.CreatePoolLedgerConfig();

                //2. Create and Open My Wallet
                await WalletUtils.CreateWalleatAsync(PoolUtils.DEFAULT_POOL_NAME, myWalletName, "default", null, null);

                // 3. Create and Open Trustee Wallet
                await WalletUtils.CreateWalleatAsync(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 theirWallet = await Wallet.OpenWalletAsync(theirWalletName, null, null))
                        {
                            //5. Create My Did
                            var createMyDidResult = await Signus.CreateAndStoreMyDidAsync(myWallet, "{}");

                            //6. Create Their Did
                            var createTheirDidResult = await Signus.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 Signus.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 Signus.SignAsync(theirWallet, theirDid, msgBytes);

                            //9. Verify message
                            var valid = await Signus.VerifySignatureAsync(myWallet, pool, theirDid, msgBytes, signatureBytes);

                            Debug.Assert(valid == true);

                            //10. Close wallets and pool
                            await myWallet.CloseAsync();

                            await theirWallet.CloseAsync();

                            await pool.CloseAsync();
                        }
            }
            finally
            {
                // 12. 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");
        }
예제 #28
0
        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");
        }
예제 #29
0
        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");
        }
예제 #30
0
        public async Task TestLedgerDemo()
        {
            // 1. Create ledger config from genesis txn file
            Pool.SetProtocolVersionAsync(PoolUtils.PROTOCOL_VERSION);

            var poolName = PoolUtils.CreatePoolLedgerConfig();
            var pool     = await Pool.OpenPoolLedgerAsync(poolName, "{}");

            // 2. Create and Open My Wallet
            await WalletUtils.CreateWallet(WALLET_NAME, WALLET_KEY);

            var myWallet = await WalletUtils.OpenWallet(WALLET_NAME, WALLET_KEY);

            // 3. Create and Open Trustee Wallet
            await WalletUtils.CreateWallet(TRUSTEE_WALLET_NAME, TRUSTEE_WALLET_KEY);

            var trusteeWallet = await WalletUtils.OpenWallet(TRUSTEE_WALLET_NAME, TRUSTEE_WALLET_KEY);

            // 4. Create My Did
            var createMyDidResult = await Did.CreateAndStoreMyDidAsync(myWallet, "{}");

            Assert.IsNotNull(createMyDidResult);
            var myDid    = createMyDidResult.Did;
            var myVerkey = createMyDidResult.VerKey;

            // 5. Create Did from Trustee1 seed
            var createTheirDidResult = await Did.CreateAndStoreMyDidAsync(trusteeWallet, TRUSTEE_IDENTITY_JSON);

            Assert.IsNotNull(createTheirDidResult);
            var trusteeDid = createTheirDidResult.Did;

            // 6. Build Nym Request
            var nymRequest = await Ledger.BuildNymRequestAsync(trusteeDid, myDid, myVerkey, null, null);

            Assert.IsNotNull(nymRequest);

            // 7. Trustee Sign Nym Request
            var nymResponseJson = await Ledger.SignAndSubmitRequestAsync(pool, trusteeWallet, trusteeDid, nymRequest);

            Assert.IsNotNull(nymResponseJson, "SignAndSubmitRequestAsync response is null");

            /*
             * The format of SignAndSubmitRequestAsync response is like this.
             *
             *  {"result":{
             *      "reqSignature":{
             *          "type":"ED25519",
             *          "values":[{"value":"7kDrVBrmrKAvSs1QoQWYq6F774ZN3bRXx5e3aaUFiNvmh4F1yNqQw1951Az35nfrnGjZ99vtCmSFXZ5GqS1zLiG","from":"V4SGRU86Z58d6TV7PBUe6f"}]
             *      },
             *      "txnMetadata":{
             *          "txnTime":1536876204,
             *          "seqNo":36,
             *          "txnId":"5d38ac6a242239c97ee28884c2b5cadec62248b2256bce51afd814c7847a853e"
             *      },
             *      "ver":"1",
             *      "auditPath":["DATtzSu9AMrArv8C2oribQh4wJ6TaD2K9o76t7EL2N7G","AbGuM7s9MudnT8M2eZe1yaG2EGUGxggMXSSbXCm4DFDx","3fjMoUdsbNrRfG5ZneHaQuX994oA4Z2pYPZtRRPmkngw"],
             *      "rootHash":"A9LirjLuoBT59JJTJYvUgfQyEJA32Wb7njrbD9XqT2wc",
             *      "txn":{
             *          "data":{
             *              "dest":"KQRpY4EmSG4MwH7md8gMoN","verkey":"B2nW4JfqZ2omHksoCmwD8zXXmtBsvbQk6WVSboazd8QB"
             *          },
             *          "protocolVersion":2,
             *          "type":"1",
             *          "metadata":{
             *              "digest":"14594e0b31f751faf72d4bf4abdc6f54af34dab855fe1a0c67fe651b47bb93b5","reqId":1536876205519496000,"from":"V4SGRU86Z58d6TV7PBUe6f"
             *          }
             *      }
             *  },
             *  "op":"REPLY"}
             */

            var nymResponse = JObject.Parse(nymResponseJson);

            Assert.AreEqual(myDid, nymResponse["result"].Value <JObject>("txn").Value <JObject>("data").Value <string>("dest"));
            Assert.AreEqual(myVerkey, nymResponse["result"].Value <JObject>("txn").Value <JObject>("data").Value <string>("verkey"));

            // 8. Close and delete My Wallet
            await myWallet.CloseAsync();

            await WalletUtils.DeleteWallet(WALLET_NAME, WALLET_KEY);

            // 9. Close and delete Their Wallet
            await trusteeWallet.CloseAsync();

            await WalletUtils.DeleteWallet(TRUSTEE_WALLET_NAME, TRUSTEE_WALLET_KEY);

            // 10. Close Pool
            await pool.CloseAsync();
        }