Beispiel #1
0
        public async Task TestProverCreateProofWorksForUsingNotSatisfyClaim()
        {
            await InitCommonWallet();

            var claimsJson = await AnonCreds.ProverGetCredentialsAsync(commonWallet, "{}");

            var claims = JArray.Parse(claimsJson);

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

            var proofRequest = "{\"nonce\":\"123432421212\",\n" +
                               "               \"name\":\"proof_req_1\",\n" +
                               "               \"version\":\"0.1\",\n" +
                               "               \"requested_attrs\":{\"attr1_referent\":{\"name\":\"some_attr\",\"restrictions\":[{\"schema_seq_no\":1}]}},\n" +
                               "               \"requested_predicates\":{}\n" +
                               "              }";

            var requestedClaimsJson = string.Format("{{\"self_attested_attributes\":{{}},\n" +
                                                    "                                    \"requested_attrs\":{{\"attr1_referent\":[\"{0}\", true]}},\n" +
                                                    "                                    \"requested_predicates\":{{}}\n" +
                                                    "                                   }}", claimUuid);

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

            var ex = await Assert.ThrowsExceptionAsync <InvalidStructureException>(() =>
                                                                                   AnonCreds.ProverCreateProofAsync(commonWallet, proofRequest, requestedClaimsJson, schemasJson,
                                                                                                                    masterSecretName, claimDefsJson, revocRegsJson)
                                                                                   );
        }
        public async Task TestProverGetCredentialsWorksForInvalidFilterJson()
        {
            var filter = "{\"issuer_id\":1}";

            var ex = await Assert.ThrowsExceptionAsync <WalletInvalidQueryException>(() =>
                                                                                     AnonCreds.ProverGetCredentialsAsync(wallet, filter)
                                                                                     );
        }
        public async Task TestProverGetCredentialsWorksForEmptyFilter()
        {
            var credentials = await AnonCreds.ProverGetCredentialsAsync(wallet, "{}");

            var credentialsArray = JArray.Parse(credentials);

            Assert.AreEqual(3, credentialsArray.Count);
        }
        public async Task TestProverGetClaimsForProofRequestWorksForInvalidPredicateType()
        {
            await InitCommonWallet();

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

            var ex = await Assert.ThrowsExceptionAsync <InvalidStructureException>(() =>
                                                                                   AnonCreds.ProverGetCredentialsAsync(commonWallet, filter)
                                                                                   );
        }
        public async Task TestProverGetClaimsWorksForEmptyFilter()
        {
            await InitCommonWallet();

            var claims = await AnonCreds.ProverGetCredentialsAsync(commonWallet, "{}");

            var claimsArray = JArray.Parse(claims);

            Assert.AreEqual(1, claimsArray.Count);
        }
        public async Task TestProverGetCredentialsWorksForEmptyResult()
        {
            var filter = string.Format("{{\"issuer_id\":\"{0}a\"}}", issuerDid);

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

            var credentialsArray = JArray.Parse(credentials);

            Assert.AreEqual(0, credentialsArray.Count);
        }
        public async Task TestProverGetCredentialsWorksForFilterByCredDefId()
        {
            var filter = string.Format("{{\"cred_def_id\":\"{0}\"}}", issuer1gvtCredDefId);

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

            var credentialsArray = JArray.Parse(credentials);

            Assert.AreEqual(1, credentialsArray.Count);
        }
        public async Task TestProverGetCredentialsWorksForFilterBySchemaName()
        {
            var filter = "{\"schema_name\":\"gvt\"}";

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

            var credentialsArray = JArray.Parse(credentials);

            Assert.AreEqual(2, credentialsArray.Count);
        }
        public async Task TestProverGetCredentialsWorksForFilterBySchema()
        {
            var filter = string.Format("{{\"schema_id\":\"{0}\"}}", gvtSchemaId);

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

            var credentialsArray = JArray.Parse(credentials);

            Assert.AreEqual(2, credentialsArray.Count);
        }
        public async Task TestProverGetClaimsWorksForEmptyResult()
        {
            await InitCommonWallet();

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

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

            var claimsArray = JArray.Parse(claims);

            Assert.AreEqual(0, claimsArray.Count);
        }
        public async Task TestProverGetClaimsWorksForFilterByIssuerAndSchema()
        {
            await InitCommonWallet();

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

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

            var claimsArray = JArray.Parse(claims);

            Assert.AreEqual(1, claimsArray.Count);
        }
Beispiel #12
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();
        }