public async Task TestProverCreateProofWorksForInvalidMasterSecret() { await InitCommonWallet(); var proofRequest = "{\"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 claimsJson = await AnonCreds.ProverGetClaimsForProofReqAsync(commonWallet, proofRequest); var claims = JObject.Parse(claimsJson); var claimForAttribute = claims["attrs"]["attr1_uuid"][0]; var claimUuid = claimForAttribute.Value <string>("claim_uuid"); var requestedClaimsJson = string.Format("{{\n" + " \"self_attested_attributes\":{{}},\n" + " \"requested_attrs\":{{\"attr1_uuid\":[\"{0}\", true]}},\n" + " \"requested_predicates\":{{\"predicate1_uuid\":\"{1}\"}}\n" + " }}", claimUuid, claimUuid); var schemasJson = string.Format("{{\"{0}\":{1}}}", claimUuid, schema); var claimDefsJson = string.Format("{{\"{0}\":{1}}}", claimUuid, claimDef); var revocRegsJson = "{}"; var ex = await Assert.ThrowsExceptionAsync <WalletValueNotFoundException>(() => AnonCreds.ProverCreateProofAsync(commonWallet, proofRequest, requestedClaimsJson, schemasJson, "wrong_master_secret", claimDefsJson, revocRegsJson) ); }
public async Task TestAnoncredsWorksForClaimRevokedBeforeProofCreated() { //9. Issuer revoke claim var revocRegUpdateJson = await AnonCreds.IssuerRevokeClaimAsync( _issuerWallet, issuerDid, 1, 1); //10. Prover gets Claims for Proof Request var claimsJson = await AnonCreds.ProverGetClaimsForProofReqAsync(_issuerWallet, _proofReqJson); var claims = JObject.Parse(claimsJson); var claimsForAttr1 = claims["attrs"]["attr1_referent"]; var claim = claimsForAttr1[0]; var claimUuid = claim.Value <string>("referent"); //11. Prover create Proof var requestedClaimsJson = string.Format(_requestedClaimsJsonTemplate, claimUuid); var schemasJson = string.Format("{{\"{0}\":{1}}}", claimUuid, schema); var claimDefsJson = string.Format("{{\"{0}\":{1}}}", claimUuid, _claimDefJson); var revocRegsJsons = string.Format("{{\"{0}\":{1}}}", claimUuid, revocRegUpdateJson); var ex = await Assert.ThrowsExceptionAsync <ClaimRevokedException>(() => AnonCreds.ProverCreateProofAsync( _issuerWallet, _proofReqJson, requestedClaimsJson, schemasJson, masterSecretName, claimDefsJson, revocRegsJsons) ); }
public async Task TestProverCreateProofWorks() { await InitCommonWallet(); var proofRequest = "{\"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}}\n" + " }"; var claimsJson = await AnonCreds.ProverGetClaimsForProofReqAsync(commonWallet, proofRequest); var claims = JObject.Parse(claimsJson); var claimForAttribute = claims["attrs"]["attr1_referent"][0]; var claimUuid = claimForAttribute.Value <string>("referent"); var requestedClaimsJson = string.Format("{{\n" + " \"self_attested_attributes\":{{}},\n" + " \"requested_attrs\":{{\"attr1_referent\":[\"{0}\", true]}},\n" + " \"requested_predicates\":{{\"predicate1_referent\":\"{1}\"}}\n" + " }}", claimUuid, claimUuid); var schemasJson = string.Format("{{\"{0}\":{1}}}", claimUuid, schema); var claimDefsJson = string.Format("{{\"{0}\":{1}}}", claimUuid, claimDef); var revocRegsJson = "{}"; var proofJson = await AnonCreds.ProverCreateProofAsync(commonWallet, proofRequest, requestedClaimsJson, schemasJson, masterSecretName, claimDefsJson, revocRegsJson); Assert.IsNotNull(proofJson); }
public async Task TestProverGetClaimsForProofRequestWorksForInvalidProofRequest() { await InitCommonWallet(); var proofRequest = "{\"nonce\":\"123432421212\",\n" + " \"name\":\"proof_req_1\",\n" + " \"version\":\"0.1\",\n" + " \"requested_predicates\":{}\n" + " }"; var ex = await Assert.ThrowsExceptionAsync <InvalidStructureException>(() => AnonCreds.ProverGetClaimsForProofReqAsync(commonWallet, proofRequest) ); }
public async Task TestProverGetClaimsForProofRequestWorksForInvalidPredicateType() { await InitCommonWallet(); var proofRequest = "{\"nonce\":\"123432421212\",\n" + " \"name\":\"proof_req_1\",\n" + " \"version\":\"0.1\",\n" + " \"requested_attrs\":{},\n" + " \"requested_predicates\":{\"predicate1_uuid\":{\"attr_name\":\"age\",\"p_type\":\"LE\",\"value\":18}}\n" + " }"; var ex = await Assert.ThrowsExceptionAsync <IndyException>(() => AnonCreds.ProverGetClaimsForProofReqAsync(_commonWallet, proofRequest) ); Assert.AreEqual(ErrorCode.CommonInvalidStructure, ex.ErrorCode); }
public async Task TestAnoncredsWorksForClaimRevokedAfterProofCreated() { //9. Prover gets Claims for Proof Request var claimsJson = await AnonCreds.ProverGetClaimsForProofReqAsync(_issuerWallet, _proofReqJson); var claims = JObject.Parse(claimsJson); var claimsForAttr1 = claims["attrs"]["attr1_referent"]; var claim = claimsForAttr1[0]; var claimUuid = claim.Value <string>("referent"); //10. Prover create Proof var requestedClaimsJson = string.Format(_requestedClaimsJsonTemplate, claimUuid); var schemasJson = string.Format("{{\"{0}\":{1}}}", claimUuid, schema); var claimDefsJson = string.Format("{{\"{0}\":{1}}}", claimUuid, _claimDefJson); var revocRegsJsons = string.Format("{{\"{0}\":{1}}}", claimUuid, _claimResult.RevocRegUpdateJson); var proofJson = await AnonCreds.ProverCreateProofAsync( _issuerWallet, _proofReqJson, requestedClaimsJson, schemasJson, masterSecretName, claimDefsJson, revocRegsJsons); //11. Issuer revoke prover claim var revocRegUpdateJson = await AnonCreds.IssuerRevokeClaimAsync( _issuerWallet, issuerDid, 1, 1); //12. Verifier verify proof var updatedRevocRegsJsons = string.Format("{{\"{0}\":{1}}}", claimUuid, revocRegUpdateJson); var valid = await AnonCreds.VerifierVerifyProofAsync( _proofReqJson, proofJson, schemasJson, claimDefsJson, updatedRevocRegsJsons); Assert.IsFalse(valid); }
public async Task TestProverGetClaimsForProofRequestWorksForEmptyRequest() { await InitCommonWallet(); var proofRequest = "{\"nonce\":\"123432421212\",\n" + " \"name\":\"proof_req_1\",\n" + " \"version\":\"0.1\",\n" + " \"requested_attrs\":{},\n" + " \"requested_predicates\":{}\n" + " }"; var claimsJson = await AnonCreds.ProverGetClaimsForProofReqAsync(commonWallet, proofRequest); var claims = JObject.Parse(claimsJson); Assert.AreEqual(0, ((JObject)claims["attrs"]).Count); Assert.AreEqual(0, ((JObject)claims["predicates"]).Count); }
public async Task TestProverGetClaimsForProofRequestWorksForNotFoundAttribute() { await InitCommonWallet(); var proofRequest = "{\"nonce\":\"123432421212\",\n" + " \"name\":\"proof_req_1\",\n" + " \"version\":\"0.1\",\n" + " \"requested_attrs\":{\"attr1_referent\":{\"name\":\"attribute\",\"restrictions\":[{\"schema_seq_no\":1}]}},\n" + " \"requested_predicates\":{}\n" + " }"; var claimsJson = await AnonCreds.ProverGetClaimsForProofReqAsync(commonWallet, proofRequest); var claims = JObject.Parse(claimsJson); var claimsForAttribute1 = (JArray)claims["attrs"]["attr1_referent"]; Assert.AreEqual(0, claimsForAttribute1.Count); }
public async Task TestProverGetClaimsForProofRequestWorksForSatisfyPredicateByIssuerAndSchema() { await InitCommonWallet(); var proofRequest = "{\"nonce\":\"123432421212\",\n" + " \"name\":\"proof_req_1\",\n" + " \"version\":\"0.1\",\n" + " \"requested_attrs\":{},\n" + " \"requested_predicates\":{\"predicate1_referent\":{\"attr_name\":\"age\",\"p_type\":\">=\",\"value\":18,\"restrictions\":[{\"issuer_did\":\"cYxiDXkpYi6ov5FcYDi1\"}]}}\n" + " }"; var claimsJson = await AnonCreds.ProverGetClaimsForProofReqAsync(commonWallet, proofRequest); var claims = JObject.Parse(claimsJson); var claimsForAttribute1 = (JArray)claims["predicates"]["predicate1_referent"]; Assert.AreEqual(1, claimsForAttribute1.Count); }
public async Task TestProverGetClaimsForProofRequestWorksForRevealedAttributeBySpecificIssuer() { await InitCommonWallet(); var proofRequest = "{\"nonce\":\"123432421212\",\n" + " \"name\":\"proof_req_1\",\n" + " \"version\":\"0.1\",\n" + " \"requested_attrs\":{\"attr1_uuid\":{\"issuer_did\":\"NcYxiDXkpYi6ov5FcYDi1e\",\"name\":\"name\"}},\n" + " \"requested_predicates\":{}\n" + " }"; var claimsJson = await AnonCreds.ProverGetClaimsForProofReqAsync(commonWallet, proofRequest); var claims = JObject.Parse(claimsJson); var claimsForAttribute1 = (JArray)claims["attrs"]["attr1_uuid"]; Assert.AreEqual(1, claimsForAttribute1.Count); }
public async Task TestProverGetClaimsForProofRequestWorksForNotSatisfyPredicate() { await InitCommonWallet(); var proofRequest = "{\"nonce\":\"123432421212\",\n" + " \"name\":\"proof_req_1\",\n" + " \"version\":\"0.1\",\n" + " \"requested_attrs\":{},\n" + " \"requested_predicates\":{\"predicate1_referent\":{\"attr_name\":\"age\",\"p_type\":\">=\",\"value\":58}}\n" + " }"; var claimsJson = await AnonCreds.ProverGetClaimsForProofReqAsync(commonWallet, proofRequest); var claims = JObject.Parse(claimsJson); var claimsForAttribute1 = (JArray)claims["predicates"]["predicate1_referent"]; Assert.AreEqual(0, claimsForAttribute1.Count); }
public async Task TestProverGetClaimsForProofRequestWorksForRevealedAttributeWithOtherSchema() { await InitCommonWallet(); var proofRequest = "{\"nonce\":\"123432421212\",\n" + " \"name\":\"proof_req_1\",\n" + " \"version\":\"0.1\",\n" + " \"requested_attrs\":{\"attr1_uuid\":{\"schema_seq_no\":2, \"name\":\"name\"}},\n" + " \"requested_predicates\":{}\n" + " }"; var claimsJson = await AnonCreds.ProverGetClaimsForProofReqAsync(_commonWallet, proofRequest); var claims = JObject.Parse(claimsJson); var claimsForAttribute1 = (JArray)claims["attrs"]["attr1_uuid"]; Assert.AreEqual(0, claimsForAttribute1.Count); }
public async Task TestProverGetClaimsForProofRequestWorksForMultipleAttributesAndPredicates() { await InitCommonWallet(); var proofRequest = "{\"nonce\":\"123432421212\",\n" + " \"name\":\"proof_req_1\",\n" + " \"version\":\"0.1\",\n" + " \"requested_attrs\":{\n" + " \"attr1_referent\":{\"name\":\"name\",\"restrictions\":[{\"schema_seq_no\":1}]},\n" + " \"attr2_referent\":{\"name\":\"sex\",\"restrictions\":[{\"schema_seq_no\":1}]}\n" + " },\n" + " \"requested_predicates\":{\n" + " \"predicate1_referent\":{\"attr_name\":\"age\",\"p_type\":\">=\",\"value\":18},\n" + " \"predicate2_referent\":{\"attr_name\":\"height\",\"p_type\":\">=\",\"value\":160}\n" + " }}"; var claimsJson = await AnonCreds.ProverGetClaimsForProofReqAsync(commonWallet, proofRequest); var claims = JObject.Parse(claimsJson); var claimsForAttribute1 = (JArray)claims["attrs"]["attr1_referent"]; Assert.AreEqual(1, claimsForAttribute1.Count); var claimsForAttribute2 = (JArray)claims["attrs"]["attr2_referent"]; Assert.AreEqual(1, claimsForAttribute2.Count); var claimsForPredicate1 = (JArray)claims["predicates"]["predicate1_referent"]; Assert.AreEqual(1, claimsForPredicate1.Count); var claimsForPredicate2 = (JArray)claims["predicates"]["predicate2_referent"]; Assert.AreEqual(1, claimsForPredicate2.Count); }
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); }
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 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); }