public async Task TestProverStoreClaimWorks()
        {
            await InitCommonWallet();

            await WalletUtils.CreateWallet(WALLET_NAME, WALLET_KEY);

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

            await AnonCreds.ProverCreateMasterSecretAsync(proverWallet, masterSecretName);

            var claimOffer = string.Format(claimOfferTemplate, issuerDid, 1);

            var claimRequest = await AnonCreds.ProverCreateCredentialReqAsync(proverWallet, proverDid, claimOffer, claimDef, masterSecretName);

            var claim = "{\"sex\":[\"male\",\"5944657099558967239210949258394887428692050081607692519917050011144233115103\"],\n" +
                        "                 \"name\":[\"Alex\",\"1139481716457488690172217916278103335\"],\n" +
                        "                 \"height\":[\"175\",\"175\"],\n" +
                        "                 \"age\":[\"28\",\"28\"]\n" +
                        "        }";

            // TODO var createClaimResult = await AnonCreds.IssuerCreateCredentialAsync(commonWallet, claimRequest, claim, -1);
            // var claimJson = createClaimResult.ClaimJson;

            // TODO await AnonCreds.ProverStoreClaimAsync(proverWallet, claimJson, createClaimResult.RevocRegUpdateJson);

            await proverWallet.CloseAsync();

            await WalletUtils.DeleteWallet(WALLET_NAME, WALLET_KEY);
        }
        public async Task Before()
        {
            StorageUtils.CleanupStorage();

            //1. Create Issuer wallet, get wallet handle
            await WalletUtils.CreateWallet(WALLET_NAME, WALLET_KEY);

            _issuerWallet = await WalletUtils.OpenWallet(WALLET_NAME, WALLET_KEY);

            //2. Issuer create claim definition
            IssuerCreateAndStoreCredentialDefResult result = await AnonCreds.IssuerCreateAndStoreCredentialDefAsync(_issuerWallet, issuerDid, schema, null, null, null);

            _claimDefJson = result.CredDefJson;

            //3. Issuer create revocation registry
            BlobStorageWriter tailsWriter = await BlobStorage.OpenWriterAsync("default", _tailsWriterConfig);

            await AnonCreds.IssuerCreateAndStoreRevocRegAsync(_issuerWallet, issuerDid, null, null, null, null, tailsWriter);

            //4. Prover create Master Secret
            await AnonCreds.ProverCreateMasterSecretAsync(_issuerWallet, masterSecretName);

            //5. Prover store Claim Offer received from Issuer
            var claimOfferJson = string.Format(claimOfferTemplate, issuerDid, 1);
            // TODO await AnonCreds.ProverStoreCredentialOfferAsync(_issuerWallet, claimOfferJson);

            //6. Prover create Claim Request
            var proverDid = "BzfFCYk";
            var claimReq  = await AnonCreds.ProverCreateCredentialReqAsync(
                _issuerWallet,
                proverDid,
                claimOfferJson,
                _claimDefJson,
                masterSecretName);

            //7. Issuer create Claim
            var claimJson = "{" +
                            "\"sex\":[\"male\",\"5944657099558967239210949258394887428692050081607692519917050011144233115103\"]," +
                            "\"name\":[\"Alex\",\"1139481716457488690172217916278103335\"]," +
                            "\"height\":[\"175\",\"175\"]," +
                            "\"age\":[\"28\",\"28\"]" +
                            "}";


            _claimResult = null; // TODO await AnonCreds.IssuerCreateCredentialAsync(_issuerWallet, claimReq, claimJson, _userRevocIndex);

            //8. Prover store received Claim
            // TODO await AnonCreds.ProverStoreClaimAsync(_issuerWallet, _claimResult.CredentialJson, _claimResult.RevocRegDeltaJson);
        }
        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);
        }
        public async Task TestGetClaimOffersForPlugged()
        {
            var type       = "proverInmem";
            var poolName   = "default";
            var walletName = "proverCustomWallet";

            await WalletUtils.CreateWallet(WALLET_NAME, WALLET_KEY);


            string claimOffers = string.Empty;
            Wallet wallet      = null;

            var claimOffer  = string.Format(claimOfferTemplate, issuerDid, 1);
            var claimOffer2 = string.Format(claimOfferTemplate, issuerDid, 2);
            var claimOffer3 = string.Format(claimOfferTemplate, issuerDid2, 2);

            try
            {
                wallet = await WalletUtils.OpenWallet(WALLET_NAME, WALLET_KEY);

                // TODO await AnonCreds.ProverStoreCredentialOfferAsync(wallet, claimOffer);
                // TODO await AnonCreds.ProverStoreCredentialOfferAsync(wallet, claimOffer2);
                // TODO await AnonCreds.ProverStoreCredentialOfferAsync(wallet, claimOffer3);

                var filter = string.Format("{{\"issuer_did\":\"{0}\"}}", issuerDid);

                // TODO claimOffers = await AnonCreds.ProverGetClaimOffersAsync(wallet, filter);
            }
            finally
            {
                if (wallet != null)
                {
                    await wallet.CloseAsync();
                }

                await WalletUtils.DeleteWallet(WALLET_NAME, WALLET_KEY);
            }

            var claimOffersArray = JArray.Parse(claimOffers);

            Assert.AreEqual(2, claimOffersArray.Count);
            Assert.IsTrue(claimOffers.Contains(claimOffer));
            Assert.IsTrue(claimOffers.Contains(claimOffer2));
        }
        protected async Task InitCommonWallet()
        {
            if (_walletOpened)
            {
                return;
            }

            StorageUtils.CleanupStorage();

            await WalletUtils.CreateWallet(WALLET_NAME, WALLET_KEY);

            commonWallet = await WalletUtils.OpenWallet(WALLET_NAME, WALLET_KEY);

            IssuerCreateAndStoreCredentialDefResult claimDefType = await AnonCreds.IssuerCreateAndStoreCredentialDefAsync(commonWallet, issuerDid, schema, null, null, null);

            claimDef = claimDefType.CredDefJson;

            await AnonCreds.ProverStoreCredentialAsync(commonWallet, string.Format(claimOfferTemplate, issuerDid, 1), null, null, null, null);

            // TODO await AnonCreds.ProverStoreCredentialOfferAsync(commonWallet, string.Format(claimOfferTemplate, issuerDid, 2), null, null, null, null);
            // TODO await AnonCreds.ProverStoreCredentialOfferAsync(commonWallet, string.Format(claimOfferTemplate, issuerDid2, 2), null, null, null, null);

            await AnonCreds.ProverCreateMasterSecretAsync(commonWallet, masterSecretName);

            var claimOffer = string.Format("{{\"issuer_did\":\"{0}\",\"schema_seq_no\":{1}}}", issuerDid, 1);

            var claimRequest = await AnonCreds.ProverCreateCredentialReqAsync(commonWallet, "CnEDk9HrMnmiHXEV1WFgbVCRteYnPqsJwrTdcZaNhFVW", claimOffer, claimDef, masterSecretName);

            var claim = "{\"sex\":[\"male\",\"5944657099558967239210949258394887428692050081607692519917050011144233115103\"],\n" +
                        "                 \"name\":[\"Alex\",\"1139481716457488690172217916278103335\"],\n" +
                        "                 \"height\":[\"175\",\"175\"],\n" +
                        "                 \"age\":[\"28\",\"28\"]\n" +
                        "        }";

            //TODO var createClaimResult = await AnonCreds.IssuerCreateCredentialAsync(commonWallet, claimRequest, claim, -1);

            //TODO var claimJson = createClaimResult.ClaimJson;

            //TODO await AnonCreds.ProverStoreClaimAsync(commonWallet, claimJson, createClaimResult.RevocRegUpdateJson);

            _walletOpened = true;
        }
示例#6
0
        public async Task TestSignAndSubmitRequestWorksForIncompatibleWalletAndPool()
        {
            var walletName = "incompatibleWallet";

            await WalletUtils.CreateWallet(walletName, "walletKey1");

            var wallet = await WalletUtils.OpenWallet(walletName, "walletKey1");

            var trusteeDidResult = await Did.CreateAndStoreMyDidAsync(wallet, TRUSTEE_IDENTITY_JSON);

            var trusteeDid = trusteeDidResult.Did;

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

            var myDid = myDidResult.Did;

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

            var ex = await Assert.ThrowsExceptionAsync <WrongWalletForPoolException>(() =>
                                                                                     Ledger.SignAndSubmitRequestAsync(pool, wallet, trusteeDid, nymRequest)
                                                                                     );
        }
示例#7
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();
        }
示例#8
0
        public async Task CreateWallet()
        {
            await WalletUtils.CreateWallet(WALLET_NAME, WALLET_KEY);

            _wallet = await WalletUtils.OpenWallet(WALLET_NAME, WALLET_KEY);
        }