protected async Task InitCommonWallet()
        {
            if (_walletOpened)
            {
                return;
            }

            StorageUtils.CleanupStorage();

            var walletName = "anoncredsCommonWallet";

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

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

            claimDef = await AnonCreds.IssuerCreateAndStoreClaimDefAsync(commonWallet, issuerDid, schema, null, false);

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

            await AnonCreds.ProverStoreClaimOfferAsync(commonWallet, string.Format(claimOfferTemplate, issuerDid, 2));

            await AnonCreds.ProverStoreClaimOfferAsync(commonWallet, string.Format(claimOfferTemplate, issuerDid2, 2));

            await AnonCreds.ProverCreateMasterSecretAsync(commonWallet, masterSecretName);

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

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

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

            var createClaimResult = await AnonCreds.IssuerCreateClaimAsync(commonWallet, claimRequest, claim, -1);

            var claimJson = createClaimResult.ClaimJson;

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

            _walletOpened = true;
        }
Exemple #2
0
        public async Task TestProverStoreClaimWorksForInvalidClaimJson()
        {
            await InitCommonWallet();

            var claimOffer = string.Format(_claimOfferTemplate, _issuerDid, 1);

            await AnonCreds.ProverCreateAndStoreClaimReqAsync(_commonWallet, _proverDid, claimOffer, _claimDef, _masterSecretName);

            var claimJson = "{\"claim\":{\"sex\":[\"male\",\"1\"],\"age\":[\"28\",\"28\"],\"name\":[\"Alex\",\"1\"],\"height\":[\"175\",\"175\"]},\n" +
                            "            \"issuer_did\":1,\"\n" +
                            "            \"revoc_reg_seq_no\":null,\n" +
                            "            \"schema_seq_no\":1}";

            var ex = await Assert.ThrowsExceptionAsync <IndyException>(() =>
                                                                       AnonCreds.ProverStoreClaimAsync(_commonWallet, claimJson)
                                                                       );

            Assert.AreEqual(ErrorCode.CommonInvalidStructure, ex.ErrorCode);
        }
        public async Task TestExerciseCustomWallet()
        {
            var walletName = "exerciseWalletTypeWorks";

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

            var wallet = await Wallet.OpenWalletAsync(walletName, null, null);

            Assert.IsNotNull(wallet);

            var claimDef = await AnonCreds.IssuerCreateAndStoreClaimDefAsync(wallet, _issuerDid, _schema, null, false);

            await AnonCreds.ProverStoreClaimOfferAsync(wallet, string.Format(_claimOfferTemplate, _issuerDid, 1));

            await AnonCreds.ProverStoreClaimOfferAsync(wallet, string.Format(_claimOfferTemplate, _issuerDid, 2));

            await AnonCreds.ProverStoreClaimOfferAsync(wallet, string.Format(_claimOfferTemplate, _issuerDid2, 2));

            await AnonCreds.ProverCreateMasterSecretAsync(wallet, _masterSecretName);

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

            var claimRequest = await AnonCreds.ProverCreateAndStoreClaimReqAsync(wallet, "CnEDk9HrMnmiHXEV1WFgbVCRteYnPqsJwrTdcZaNhFVW", claimOffer, claimDef, _masterSecretName);

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

            var createClaimResult = await AnonCreds.IssuerCreateClaimAsync(wallet, claimRequest, claim, -1);

            var claimJson = createClaimResult.ClaimJson;

            await AnonCreds.ProverStoreClaimAsync(wallet, claimJson);

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

            var claimOffers = await AnonCreds.ProverGetClaimOffersAsync(wallet, filter);

            await wallet.CloseAsync();
        }
        public async Task TestAnonCredsDemo()
        {
            //4. Issuer create ClaimDef
            var schemaJson = "{\n" +
                             "                    \"seqNo\":1,\n" +
                             "                    \"data\": {\n" +
                             "                        \"name\":\"gvt\",\n" +
                             "                        \"version\":\"1.0\",\n" +
                             "                        \"attr_names\":[\"age\",\"sex\",\"height\",\"name\"]\n" +
                             "                    }\n" +
                             "                }";
            var issuerDid = "NcYxiDXkpYi6ov5FcYDi1e";

            var claimDef = await AnonCreds.IssuerCreateAndStoreClaimDefAsync(_issuerWallet, issuerDid, schemaJson, null, false);

            Assert.IsNotNull(claimDef);

            //5. Prover create Master Secret
            var masterSecret = "masterSecretName";
            await AnonCreds.ProverCreateMasterSecretAsync(_proverWallet, masterSecret);

            //6. Prover store Claim Offer
            var claimOffer = string.Format("{{\"issuer_did\":\"{0}\", \"schema_seq_no\":{1}}}", issuerDid, 1);
            await AnonCreds.ProverStoreClaimOfferAsync(_proverWallet, claimOffer);

            //7. Prover get Claim Offers
            var claimOfferFilter = string.Format("{{\"issuer_did\":\"{0}\"}}", issuerDid);
            var claimOffersJson  = await AnonCreds.ProverGetClaimOffersAsync(_proverWallet, claimOfferFilter);

            var claimOffersObject = JArray.Parse(claimOffersJson);

            Assert.AreEqual(claimOffersObject.Count, 1);

            var claimOfferObject = (JObject)claimOffersObject[0];
            var claimOfferJson   = claimOfferObject.ToString();

            //8. Prover create ClaimReq
            var proverDid = "BzfFCYk";
            var claimReq  = await AnonCreds.ProverCreateAndStoreClaimReqAsync(_proverWallet, proverDid, claimOfferJson, claimDef, masterSecret);

            Assert.IsNotNull(claimReq);

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

            var createClaimResult = await AnonCreds.IssuerCreateClaimAsync(_issuerWallet, claimReq, claimAttributesJson, -1);

            Assert.IsNotNull(createClaimResult);
            var claimJson = createClaimResult.ClaimJson;

            //10. Prover store Claim
            await AnonCreds.ProverStoreClaimAsync(_proverWallet, claimJson);

            //11. Prover gets Claims for Proof Request
            var proofRequestJson = "{\n" +
                                   "                          \"nonce\":\"123432421212\",\n" +
                                   "                          \"name\":\"proof_req_1\",\n" +
                                   "                          \"version\":\"0.1\",\n" +
                                   "                          \"requested_attrs\":{\"attr1_referent\":{\"name\":\"name\",\"restrictions\":[{\"schema_seq_no\":1}]},\n" +
                                   "                                                \"attr2_referent\":{\"name\":\"sex\",\"restrictions\":[{\"schema_seq_no\":1}]}},\n" +
                                   "                          \"requested_predicates\":{\"predicate1_referent\":{\"attr_name\":\"age\",\"p_type\":\">=\",\"value\":18}}\n" +
                                   "                  }";

            var claimsForProofJson = await AnonCreds.ProverGetClaimsForProofReqAsync(_proverWallet, proofRequestJson);

            Assert.IsNotNull(claimsForProofJson);

            var claimsForProof      = JObject.Parse(claimsForProofJson);
            var claimsForAttribute1 = (JArray)claimsForProof["attrs"]["attr1_referent"];
            var claimsForAttribute2 = (JArray)claimsForProof["attrs"]["attr1_referent"];
            var claimsForPredicate  = (JArray)claimsForProof["predicates"]["predicate1_referent"];

            Assert.AreEqual(claimsForAttribute1.Count, 1);
            Assert.AreEqual(claimsForAttribute2.Count, 1);
            Assert.AreEqual(claimsForPredicate.Count, 1);

            var claimUuid = claimsForAttribute1[0].Value <string>("referent");

            //12. Prover create Proof
            var selfAttestedValue   = "yes";
            var requestedClaimsJson = string.Format("{{\n" +
                                                    "                                          \"self_attested_attributes\":{{\"self1\":\"{0}\"}},\n" +
                                                    "                                          \"requested_attrs\":{{\"attr1_referent\":[\"{1}\", true],\n" +
                                                    "                                                               \"attr2_referent\":[\"{2}\", false]}},\n" +
                                                    "                                          \"requested_predicates\":{{\"predicate1_referent\":\"{3}\"}}\n" +
                                                    "                                        }}", selfAttestedValue, claimUuid, claimUuid, claimUuid);

            var schemasJson   = string.Format("{{\"{0}\":{1}}}", claimUuid, schemaJson);
            var claimDefsJson = string.Format("{{\"{0}\":{1}}}", claimUuid, claimDef);
            var revocRegsJson = "{}";


            var proofJson = await AnonCreds.ProverCreateProofAsync(_proverWallet, proofRequestJson, requestedClaimsJson, schemasJson,
                                                                   masterSecret, claimDefsJson, revocRegsJson);

            Assert.IsNotNull(proofJson);

            var proof = JObject.Parse(proofJson);

            //13. Verifier verify Proof
            Assert.AreEqual("Alex",
                            proof["requested_proof"]["revealed_attrs"]["attr1_referent"][1]);

            Assert.IsNotNull(proof["requested_proof"]["unrevealed_attrs"].Value <string>("attr2_referent"));

            Assert.AreEqual(selfAttestedValue, proof["requested_proof"]["self_attested_attrs"].Value <string>("self1"));

            Boolean valid = await AnonCreds.VerifierVerifyProofAsync(proofRequestJson, proofJson, schemasJson, claimDefsJson, revocRegsJson);

            Assert.IsTrue(valid);
        }
        public async Task TestAnonCredsWorksForSingleIssuerSingleProverMultipleClaims()
        {
            var issuerDid = "NcYxiDXkpYi6ov5FcYDi1e";

            //1. Issuer create ClaimDef
            var gvtSchemaJson = "{\n" +
                                "                    \"seqNo\":1,\n" +
                                "                    \"data\": {\n" +
                                "                        \"name\":\"gvt\",\n" +
                                "                        \"version\":\"1.0\",\n" +
                                "                        \"attr_names\":[\"age\",\"sex\",\"height\",\"name\"]\n" +
                                "                    }\n" +
                                "                }";

            var gvtClaimDef = await AnonCreds.IssuerCreateAndStoreClaimDefAsync(_issuerWallet, issuerDid, gvtSchemaJson, null, false);

            //2. Issuer create ClaimDef
            var xyzSchemaJson = "{\n" +
                                "                    \"seqNo\":2,\n" +
                                "                    \"data\": {\n" +
                                "                        \"name\":\"xyz\",\n" +
                                "                        \"version\":\"1.0\",\n" +
                                "                        \"attr_names\":[\"status\",\"period\"]\n" +
                                "                    }\n" +
                                "                }";

            var xyzClaimDef = await AnonCreds.IssuerCreateAndStoreClaimDefAsync(_issuerWallet, issuerDid, xyzSchemaJson, null, false);

            //3. Prover create Master Secret
            var masterSecret = "masterSecretName";
            await AnonCreds.ProverCreateMasterSecretAsync(_proverWallet, masterSecret);

            //4. Prover store Claim Offer received from Issuer
            var claimOffer = string.Format("{{\"issuer_did\":\"{0}\", \"schema_seq_no\":{1}}}", issuerDid, 1);
            await AnonCreds.ProverStoreClaimOfferAsync(_proverWallet, claimOffer);

            //5. Prover store Claim Offer received from Issuer
            var claimOffer2 = string.Format("{{\"issuer_did\":\"{0}\", \"schema_seq_no\":{1}}}", issuerDid, 2);
            await AnonCreds.ProverStoreClaimOfferAsync(_proverWallet, claimOffer2);

            //6. Prover get Claim Offers
            var claimOffersJson = await AnonCreds.ProverGetClaimOffersAsync(_proverWallet, "{}");

            var claimOffersObject = JArray.Parse(claimOffersJson);

            Assert.AreEqual(2, claimOffersObject.Count);

            var claimOfferObj1 = claimOffersObject[0];
            var claimOfferObj2 = claimOffersObject[1];

            var gvtClaimOffer = claimOfferObj1.Value <int>("schema_seq_no") == 1 ? claimOfferObj1.ToString() : claimOfferObj2.ToString();
            var xyzClaimOffer = claimOfferObj1.Value <int>("schema_seq_no") == 2 ? claimOfferObj1.ToString() : claimOfferObj2.ToString();


            //7. Prover create ClaimReq for GVT Claim Offer
            var proverDid   = "BzfFCYk";
            var gvtClaimReq = await AnonCreds.ProverCreateAndStoreClaimReqAsync(_proverWallet, proverDid, gvtClaimOffer, gvtClaimDef, masterSecret);

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

            var gvtCreateClaimResult = await AnonCreds.IssuerCreateClaimAsync(_issuerWallet, gvtClaimReq, gvtClaimAttributesJson, -1);

            var gvtClaimJson = gvtCreateClaimResult.ClaimJson;

            //9. Prover store Claim
            await AnonCreds.ProverStoreClaimAsync(_proverWallet, gvtClaimJson);

            //10. Prover create ClaimReq for GVT Claim Offer
            var xyzClaimReq = await AnonCreds.ProverCreateAndStoreClaimReqAsync(_proverWallet, proverDid, xyzClaimOffer, xyzClaimDef, masterSecret);

            //11. Issuer create Claim
            var xyzClaimAttributesJson = "{\n" +
                                         "               \"status\":[\"partial\",\"51792877103171595686471452153480627530895\"],\n" +
                                         "               \"period\":[\"8\",\"8\"]\n" +
                                         "        }";

            var xyzCreateClaimResult = await AnonCreds.IssuerCreateClaimAsync(_issuerWallet, xyzClaimReq, xyzClaimAttributesJson, -1);

            var xyzClaimJson = xyzCreateClaimResult.ClaimJson;

            //12. Prover store Claim
            await AnonCreds.ProverStoreClaimAsync(_proverWallet, xyzClaimJson);

            //13. Prover gets Claims for Proof Request
            var proofRequestJson = "{\n" +
                                   "                          \"nonce\":\"123432421212\",\n" +
                                   "                          \"name\":\"proof_req_1\",\n" +
                                   "                          \"version\":\"0.1\",\n" +
                                   "                          \"requested_attrs\":{\"attr1_referent\":{\"name\":\"name\",\"restrictions\":[{\"schema_seq_no\":1}]}},\n" +
                                   "                          \"requested_predicates\":{\"predicate1_referent\":{\"attr_name\":\"age\",\"p_type\":\">=\",\"value\":18}," +
                                   "                                                    \"predicate2_referent\":{\"attr_name\":\"period\",\"p_type\":\">=\",\"value\":5}}\n" +
                                   "                  }";


            var claimsForProofJson = await AnonCreds.ProverGetClaimsForProofReqAsync(_proverWallet, proofRequestJson);

            Assert.IsNotNull(claimsForProofJson);

            var claimsForProof      = JObject.Parse(claimsForProofJson);
            var claimsForAttribute1 = (JArray)claimsForProof["attrs"]["attr1_referent"];
            var claimsForPredicate1 = (JArray)claimsForProof["predicates"]["predicate1_referent"];
            var claimsForPredicate2 = (JArray)claimsForProof["predicates"]["predicate2_referent"];

            Assert.AreEqual(claimsForAttribute1.Count, 1);
            Assert.AreEqual(claimsForPredicate1.Count, 1);
            Assert.AreEqual(claimsForPredicate2.Count, 1);

            var claimUuidForAttr1      = claimsForAttribute1[0].Value <string>("referent");
            var claimUuidForPredicate1 = claimsForPredicate1[0].Value <string>("referent");
            var claimUuidForPredicate2 = claimsForPredicate2[0].Value <string>("referent");

            //14. Prover create Proof
            var requestedClaimsJson = string.Format("{{\n" +
                                                    "                                          \"self_attested_attributes\":{{}},\n" +
                                                    "                                          \"requested_attrs\":{{\"attr1_referent\":[\"{0}\", true]}},\n" +
                                                    "                                          \"requested_predicates\":{{\"predicate1_referent\":\"{1}\"," +
                                                    "                                                                    \"predicate2_referent\":\"{2}\"}}\n" +
                                                    "                                        }}", claimUuidForAttr1, claimUuidForPredicate1, claimUuidForPredicate2);

            var schemasJson   = string.Format("{{\"{0}\":{1}, \"{2}\":{3}}}", claimUuidForAttr1, gvtSchemaJson, claimUuidForPredicate2, xyzSchemaJson);
            var claimDefsJson = string.Format("{{\"{0}\":{1}, \"{2}\":{3}}}", claimUuidForAttr1, gvtClaimDef, claimUuidForPredicate2, xyzClaimDef);

            var revocRegsJson = "{}";

            var proofJson = await AnonCreds.ProverCreateProofAsync(_proverWallet, proofRequestJson, requestedClaimsJson, schemasJson,
                                                                   masterSecret, claimDefsJson, revocRegsJson);

            Assert.IsNotNull(proofJson);

            var proof = JObject.Parse(proofJson);

            //15. Verifier verify Proof
            Assert.AreEqual("Alex",
                            proof["requested_proof"]["revealed_attrs"]["attr1_referent"][1]);

            var valid = await AnonCreds.VerifierVerifyProofAsync(proofRequestJson, proofJson, schemasJson, claimDefsJson, revocRegsJson);

            Assert.IsTrue(valid);
        }
Exemple #6
0
        public async Task TestVerifyProofWorksForProofDoesNotCorrespondToProofRequest()
        {
            //1. Issuer create ClaimDef
            var schemaJson = "{\n" +
                             "                    \"seqNo\":1,\n" +
                             "                    \"data\": {\n" +
                             "                        \"name\":\"gvt\",\n" +
                             "                        \"version\":\"1.0\",\n" +
                             "                        \"keys\":[\"age\",\"sex\",\"height\",\"name\"]\n" +
                             "                    }\n" +
                             "                }";
            var issuerDid = "NcYxiDXkpYi6ov5FcYDi1e";

            var claimDef = await AnonCreds.IssuerCreateAndStoreClaimDefAsync(_issuerWallet, issuerDid, schemaJson, null, false);

            Assert.IsNotNull(claimDef);

            //2. Prover create Master Secret
            var masterSecret = "masterSecretName";
            await AnonCreds.ProverCreateMasterSecretAsync(_proverWallet, masterSecret);

            //3. Prover store Claim Offer
            var claimOffer = string.Format("{{\"issuer_did\":\"{0}\", \"schema_seq_no\":{1}}}", issuerDid, 1);
            await AnonCreds.ProverStoreClaimOfferAsync(_proverWallet, claimOffer);

            //4. Prover get Claim Offers
            var claimOfferFilter = string.Format("{{\"issuer_did\":\"{0}\"}}", issuerDid);
            var claimOffersJson  = await AnonCreds.ProverGetClaimOffersAsync(_proverWallet, claimOfferFilter);

            var claimOffersObject = JArray.Parse(claimOffersJson);

            Assert.AreEqual(claimOffersObject.Count, 1);

            var claimOfferObject = claimOffersObject[0];
            var claimOfferJson   = claimOfferObject.ToString();

            //5. Prover create ClaimReq
            var proverDid = "BzfFCYk";
            var claimReq  = await AnonCreds.ProverCreateAndStoreClaimReqAsync(_proverWallet, proverDid, claimOfferJson, claimDef, masterSecret);

            Assert.IsNotNull(claimReq);

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

            var createClaimResult = await AnonCreds.IssuerCreateClaimAsync(_issuerWallet, claimReq, claimAttributesJson, -1);

            Assert.IsNotNull(createClaimResult);
            var claimJson = createClaimResult.ClaimJson;

            //7. Prover store Claim
            await AnonCreds.ProverStoreClaimAsync(_proverWallet, claimJson);

            //8. Prover gets Claims for Proof Request
            var proofRequestJson = "{\n" +
                                   "                          \"nonce\":\"123432421212\",\n" +
                                   "                          \"name\":\"proof_req_1\",\n" +
                                   "                          \"version\":\"0.1\",\n" +
                                   "                          \"requested_attrs\":{\"attr1_uuid\":{\"schema_seq_no\":1,\"name\":\"name\"}},\n" +
                                   "                          \"requested_predicates\":{}\n" +
                                   "                  }";

            var claimsForProofJson = await AnonCreds.ProverGetClaimsForProofReqAsync(_proverWallet, proofRequestJson);

            Assert.IsNotNull(claimsForProofJson);

            var claimsForProof      = JObject.Parse(claimsForProofJson);
            var claimsForAttribute1 = (JArray)claimsForProof["attrs"]["attr1_uuid"];


            Assert.AreEqual(claimsForAttribute1.Count, 1);

            var claimUuid = claimsForAttribute1[0].Value <string>("claim_uuid");

            //9. Prover create Proof
            var selfAttestedValue   = "yes";
            var requestedClaimsJson = string.Format("{{\n" +
                                                    "                                          \"self_attested_attributes\":{{\"self1\":\"{0}\"}},\n" +
                                                    "                                          \"requested_attrs\":{{\"attr1_uuid\":[\"{1}\", true]}},\n" +
                                                    "                                          \"requested_predicates\":{{}}\n" +
                                                    "                                        }}", selfAttestedValue, claimUuid);

            var schemasJson   = string.Format("{{\"{0}\":{1}}}", claimUuid, schemaJson);
            var claimDefsJson = string.Format("{{\"{0}\":{1}}}", claimUuid, claimDef);
            var revocRegsJson = "{}";

            //TODO: Not sure why this call is failing...
            var proofJson = await AnonCreds.ProverCreateProofAsync(_proverWallet, proofRequestJson, requestedClaimsJson, schemasJson,
                                                                   masterSecret, claimDefsJson, revocRegsJson);

            Assert.IsNotNull(proofJson);

            var proof = JObject.Parse(proofJson);

            //10. Verifier verify Proof
            Assert.AreEqual("Alex",
                            proof["requested_proof"]["revealed_attrs"]["attr1_uuid"][1]);


            Assert.AreEqual(selfAttestedValue, proof["requested_proof"]["self_attested_attrs"].Value <string>("self1"));

            proofRequestJson = "{\n" +
                               "                            \"nonce\":\"123432421212\",\n" +
                               "                        \"name\":\"proof_req_1\",\n" +
                               "                        \"version\":\"0.1\",\n" +
                               "                    \"requested_attrs\":{\"attr1_uuid\":{\"schema_seq_no\":1,\"name\":\"name\"}},\n" +
                               "                    \"requested_predicates\":{\"predicate1_uuid\":{\"attr_name\":\"age\",\"p_type\":\"GE\",\"value\":18}\n" +
                               "           }";

            var ex = await Assert.ThrowsExceptionAsync <IndyException>(() =>
                                                                       AnonCreds.VerifierVerifyProofAsync(proofRequestJson, proofJson, schemasJson, claimDefsJson, revocRegsJson)
                                                                       );

            Assert.AreEqual(ErrorCode.CommonInvalidStructure, ex.ErrorCode);
        }
Exemple #7
0
        public static async Task Execute()
        {
            var issuerWalletName = "issuerWallet";
            var proverWalletName = "proverWallet";

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

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

                //3. Prover Create and Open Wallet
                await WalletUtils.CreateWalleatAsync(PoolUtils.DEFAULT_POOL_NAME, proverWalletName, "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 issuerWallet = await Wallet.OpenWalletAsync(issuerWalletName, null, null))
                        using (var proverWallet = await Wallet.OpenWalletAsync(proverWalletName, null, null))
                        {
                            //5. Issuer create ClaimDef
                            var schemaJson = "{\n" +
                                             "   \"seqNo\":1,\n" +
                                             "   \"data\": {\n" +
                                             "       \"name\":\"gvt\",\n" +
                                             "       \"version\":\"1.0\",\n" +
                                             "       \"attr_names\":[\"age\",\"sex\",\"height\",\"name\"]\n" +
                                             "   }\n" +
                                             "}";
                            var issuerDid = "NcYxiDXkpYi6ov5FcYDi1e";

                            var claimDef = await AnonCreds.IssuerCreateAndStoreClaimDefAsync(issuerWallet, issuerDid, schemaJson, null, false);

                            //6. Prover create Master Secret
                            var masterSecret = "masterSecretName";
                            await AnonCreds.ProverCreateMasterSecretAsync(proverWallet, masterSecret);

                            //7. Prover store Claim Offer
                            var claimOffer = string.Format("{{\"issuer_did\":\"{0}\", \"schema_seq_no\":{1}}}", issuerDid, 1);
                            await AnonCreds.ProverStoreClaimOfferAsync(proverWallet, claimOffer);

                            //8. Prover get Claim Offers
                            var claimOfferFilter = string.Format("{{\"issuer_did\":\"{0}\"}}", issuerDid);
                            var claimOffersJson  = await AnonCreds.ProverGetClaimOffersAsync(proverWallet, claimOfferFilter);

                            var claimOffersObject = JArray.Parse(claimOffersJson);
                            Debug.Assert(claimOffersObject.Count == 1);

                            var claimOfferObject = (JObject)claimOffersObject[0];
                            var claimOfferJson   = claimOfferObject.ToString();

                            //9. Prover create ClaimReq
                            var proverDid = "BzfFCYk";
                            var claimReq  = await AnonCreds.ProverCreateAndStoreClaimReqAsync(proverWallet, proverDid, claimOfferJson, claimDef, masterSecret);

                            Debug.Assert(claimReq != null);

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

                            var createClaimResult = await AnonCreds.IssuerCreateClaimAsync(issuerWallet, claimReq, claimAttributesJson, -1);

                            var claimJson = createClaimResult.ClaimJson;

                            //11. Prover store Claim
                            await AnonCreds.ProverStoreClaimAsync(proverWallet, claimJson);

                            //12. Prover gets Claims for Proof Request
                            var proofRequestJson = "{\n" +
                                                   "   \"nonce\":\"123432421212\",\n" +
                                                   "   \"name\":\"proof_req_1\",\n" +
                                                   "   \"version\":\"0.1\",\n" +
                                                   "   \"requested_attrs\":{\"attr1_uuid\":{\"schema_seq_no\":1,\"name\":\"name\"},\n" +
                                                   "       \"attr2_uuid\":{\"schema_seq_no\":1,\"name\":\"sex\"}},\n" +
                                                   "   \"requested_predicates\":{\"predicate1_uuid\":{\"attr_name\":\"age\",\"p_type\":\"GE\",\"value\":18}}\n" +
                                                   "   }";

                            var claimsForProofJson = await AnonCreds.ProverGetClaimsForProofReqAsync(proverWallet, proofRequestJson);

                            var claimsForProof      = JObject.Parse(claimsForProofJson);
                            var claimsForAttribute1 = (JArray)claimsForProof["attrs"]["attr1_uuid"];
                            var claimsForAttribute2 = (JArray)claimsForProof["attrs"]["attr1_uuid"];
                            var claimsForPredicate  = (JArray)claimsForProof["predicates"]["predicate1_uuid"];

                            Debug.Assert(claimsForAttribute1.Count == 1);
                            Debug.Assert(claimsForAttribute2.Count == 1);
                            Debug.Assert(claimsForPredicate.Count == 1);

                            var claimUuid = claimsForAttribute1[0].Value <string>("claim_uuid");

                            //13. Prover create Proof
                            var selfAttestedValue   = "yes";
                            var requestedClaimsJson = string.Format("{{\n" +
                                                                    "   \"self_attested_attributes\":{{\"self1\":\"{0}\"}},\n" +
                                                                    "   \"requested_attrs\":{{\"attr1_uuid\":[\"{1}\", true],\n" +
                                                                    "   \"attr2_uuid\":[\"{2}\", false]}},\n" +
                                                                    "   \"requested_predicates\":{{\"predicate1_uuid\":\"{3}\"}}\n" +
                                                                    "}}", selfAttestedValue, claimUuid, claimUuid, claimUuid);

                            var schemasJson   = string.Format("{{\"{0}\":{1}}}", claimUuid, schemaJson);
                            var claimDefsJson = string.Format("{{\"{0}\":{1}}}", claimUuid, claimDef);
                            var revocRegsJson = "{}";


                            var proofJson = await AnonCreds.ProverCreateProofAsync(proverWallet, proofRequestJson, requestedClaimsJson, schemasJson,
                                                                                   masterSecret, claimDefsJson, revocRegsJson);

                            var proof = JObject.Parse(proofJson);

                            //14. Verifier verify Proof
                            Debug.Assert(string.Equals("Alex", proof["requested_proof"]["revealed_attrs"]["attr1_uuid"][1].ToString()));
                            Debug.Assert(proof["requested_proof"]["unrevealed_attrs"].Value <string>("attr2_uuid") != null);
                            Debug.Assert(string.Equals(selfAttestedValue, proof["requested_proof"]["self_attested_attrs"].Value <string>("self1")));

                            var valid = await AnonCreds.VerifierVerifyProofAsync(proofRequestJson, proofJson, schemasJson, claimDefsJson, revocRegsJson);

                            Debug.Assert(valid == true);

                            //15. Close wallets and pool
                            await issuerWallet.CloseAsync();

                            await proverWallet.CloseAsync();

                            await pool.CloseAsync();
                        }
            }
            finally
            {
                //16. Delete wallets and Pool ledger config
                await WalletUtils.DeleteWalletAsync(issuerWalletName, null);

                await WalletUtils.DeleteWalletAsync(proverWalletName, null);

                await PoolUtils.DeletePoolLedgerConfigAsync(PoolUtils.DEFAULT_POOL_NAME);
            }

            Console.WriteLine("Anoncreds sample -> completed");
        }
        public async Task TestProverCreateAndStoreClaimReqWorksForInvalidMasterSecret()
        {
            await InitCommonWallet();

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

            var ex = await Assert.ThrowsExceptionAsync <WalletValueNotFoundException>(() =>
                                                                                      AnonCreds.ProverCreateAndStoreClaimReqAsync(commonWallet, proverDid, claimOffer, claimDef, "other_master_secret")
                                                                                      );
        }