public async Task TestProverStoreClaimOfferWorksForInvalidIssuerDid()
        {
            var claimOffer = "{\"issuer_did\":\"invalid_base58_string\",\"schema_seq_no\":1}";

            var ex = await Assert.ThrowsExceptionAsync <InvalidStructureException>(() =>
                                                                                   AnonCreds.ProverStoreCredentialOfferAsync(_wallet, claimOffer)
                                                                                   );
        }
        public async Task TestProverStoreClaimOfferWorksForInvalidJson()
        {
            var claimOffer = "{\"issuer_did\":\"NcYxiDXkpYi6ov5FcYDi1e\"}";

            var ex = await Assert.ThrowsExceptionAsync <InvalidStructureException>(() =>
                                                                                   AnonCreds.ProverStoreCredentialOfferAsync(_wallet, claimOffer)
                                                                                   );
        }
Esempio n. 3
0
        public async Task TestExerciseCustomWallet()
        {
            StorageUtils.CleanupStorage();

            var walletName = "exerciseWalletTypeWorks";

            await Wallet.CreateWalletAsync(POOL, walletName, _type, null, null);

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

            Assert.IsNotNull(wallet);

            var schema   = "{\"seqNo\":1,\"dest\":\"{}\",\"data\": {\"name\":\"gvt\",\"version\":\"1.0\",\"attr_names\":[\"age\",\"sex\",\"height\",\"name\"]}}";
            var claimDef = await AnonCreds.IssuerCreateAndStoreClaimDefAsync(wallet, DID1, schema, null, false);

            var claimOfferTemplate = "{{\"issuer_did\":\"{0}\",\"schema_seq_no\":{1}}}";

            await AnonCreds.ProverStoreCredentialOfferAsync(wallet, string.Format(claimOfferTemplate, DID1, 1));

            await AnonCreds.ProverStoreCredentialOfferAsync(wallet, string.Format(claimOfferTemplate, DID1, 2));

            var issuerDid2 = "CnEDk9HrMnmiHXEV1WFgbVCRteYnPqsJwrTdcZaNhFVW";
            await AnonCreds.ProverStoreCredentialOfferAsync(wallet, string.Format(claimOfferTemplate, issuerDid2, 2));

            string masterSecretName = "master_secret_name";
            await AnonCreds.ProverCreateMasterSecretAsync(wallet, masterSecretName);

            var claimOffer = string.Format("{{\"issuer_did\":\"{0}\",\"schema_seq_no\":{1}}}", DID1, 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, createClaimResult.RevocRegUpdateJson);

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

            var claims = await AnonCreds.ProverGetCredentialsAsync(wallet, filter);

            var claimsArray = JArray.Parse(claims);

            Assert.AreEqual(1, claimsArray.Count);

            await wallet.CloseAsync();
        }
Esempio n. 4
0
        public async Task TestGetClaimOffersForPlugged()
        {
            var type       = "proverInmem";
            var poolName   = "default";
            var walletName = "proverCustomWallet";

            await Wallet.RegisterWalletTypeAsync(type, new InMemWalletType());

            await Wallet.CreateWalletAsync(poolName, walletName, type, null, null);

            string claimOffers;
            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 Wallet.OpenWalletAsync(walletName, null, null);

                await AnonCreds.ProverStoreCredentialOfferAsync(wallet, claimOffer);

                await AnonCreds.ProverStoreCredentialOfferAsync(wallet, claimOffer2);

                await AnonCreds.ProverStoreCredentialOfferAsync(wallet, claimOffer3);

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

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

                await Wallet.DeleteWalletAsync(walletName, null);
            }

            var claimOffersArray = JArray.Parse(claimOffers);

            Assert.AreEqual(2, claimOffersArray.Count);
            Assert.IsTrue(claimOffers.Contains(claimOffer));
            Assert.IsTrue(claimOffers.Contains(claimOffer2));
        }
Esempio n. 5
0
        public async Task Before()
        {
            StorageUtils.CleanupStorage();

            //1. Create Issuer wallet, get wallet handle
            await Wallet.CreateWalletAsync("default", _walletName, "default", null, null);

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

            //2. Issuer create claim definition
            _claimDefJson = await AnonCreds.IssuerCreateAndStoreClaimDefAsync(_issuerWallet, issuerDid, schema, null, true);

            //3. Issuer create revocation registry
            await AnonCreds.IssuerCreateAndStoreRevocRegAsync(_issuerWallet, issuerDid, 1, 5);

            //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);
            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 = await AnonCreds.IssuerCreateCredentialAsync(_issuerWallet, claimReq, claimJson, _userRevocIndex);

            //8. Prover store received Claim
            await AnonCreds.ProverStoreClaimAsync(_issuerWallet, _claimResult.CredentialJson, _claimResult.RevocRegDeltaJson);
        }
        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.ProverStoreCredentialOfferAsync(commonWallet, string.Format(claimOfferTemplate, issuerDid, 1));

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

            await AnonCreds.ProverStoreCredentialOfferAsync(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.ProverCreateCredentialReqAsync(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.IssuerCreateCredentialAsync(commonWallet, claimRequest, claim, -1);

            var claimJson = createClaimResult.ClaimJson;

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

            _walletOpened = true;
        }
        public async Task TestProverStoreClaimOfferWorks()
        {
            var claimOffer = "{\"issuer_did\":\"NcYxiDXkpYi6ov5FcYDi1e\",\"schema_seq_no\":1 }";

            await AnonCreds.ProverStoreCredentialOfferAsync(_wallet, claimOffer);
        }
        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.ProverStoreCredentialOfferAsync(_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, createClaimResult.RevocRegUpdateJson);

            //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" +
                                   "                                                \"attr3_referent\":{\"phone\":\"sex\"}},\n" +
                                   "                          \"requested_predicates\":{\"predicate1_referent\":{\"attr_name\":\"age\",\"p_type\":\">=\",\"value\":18}}\n" +
                                   "                  }";

            var claimsForProofJson = await AnonCreds.ProverGetCredentialsForProofReqAsync(_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   = "8-800-200";
            var requestedClaimsJson = string.Format("{{\n" +
                                                    "                                          \"self_attested_attributes\":{{\"attr3_referent\":\"{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>("attr3_referent"));

            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.ProverStoreCredentialOfferAsync(_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.ProverStoreCredentialOfferAsync(_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, gvtCreateClaimResult.RevocRegUpdateJson);

            //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, xyzCreateClaimResult.RevocRegUpdateJson);

            //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.ProverGetCredentialsForProofReqAsync(_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);
        }