Example #1
0
        public async Task TestClaimDefRequestWorksWithoutSignature()
        {
            var trusteeJson = "{\"seed\":\"000000000000000000000000Trustee1\"}";

            var trusteeDidResult = await Signus.CreateAndStoreMyDidAsync(_wallet, trusteeJson);

            var trusteeDid = trusteeDidResult.Did;

            var myJson = "{}";

            var myDidResult = await Signus.CreateAndStoreMyDidAsync(_wallet, myJson);

            var myDid    = myDidResult.Did;
            var myVerkey = myDidResult.VerKey;

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

            await Ledger.SignAndSubmitRequestAsync(_pool, _wallet, trusteeDid, nymRequest);

            var schemaData = "{\"name\":\"gvt2\",\"version\":\"2.0\",\"attr_names\": [\"name\", \"male\"]}";

            var schemaRequest = await Ledger.BuildSchemaRequestAsync(myDid, schemaData);

            var schemaResponse = await Ledger.SignAndSubmitRequestAsync(_pool, _wallet, myDid, schemaRequest);

            var schemaObj = JObject.Parse(schemaResponse);

            int schemaSeqNo = (int)schemaObj["result"]["seqNo"];

            var claimDef = string.Format(_claimDefTemplate, schemaSeqNo, myDid);

            var claimDefObj = JObject.Parse(claimDef);

            var claimDefJson = claimDefObj["data"].ToString();

            var claimDefRequest = await Ledger.BuildClaimDefTxnAsync(myDid, schemaSeqNo, _signatureType, claimDefJson);

            var ex = await Assert.ThrowsExceptionAsync <IndyException>(() =>
                                                                       Ledger.SubmitRequestAsync(_pool, claimDefRequest)
                                                                       );

            Assert.AreEqual(ErrorCode.LedgerInvalidTransaction, ex.ErrorCode);
        }
        public async Task TestBuildClaimDefRequestWorks()
        {
            var dataTemplate = "{{\"primary\":{{\"n\":\"1\",\"s\":\"2\",\"rms\":\"3\",\"r\":{{\"name\":\"1\"}},\"rctxt\":\"1\",\"z\":\"1\"}}{0}}}";
            var data         = string.Format(dataTemplate, string.Empty);

            var expectedData = string.Format(dataTemplate, ",\"revocation\":{}");

            var expectedResult = string.Format("\"identifier\":\"{0}\"," +
                                               "\"operation\":{{" +
                                               "\"ref\":{1}," +
                                               "\"data\":{2}," +
                                               "\"type\":\"102\"," +
                                               "\"signature_type\":\"{3}\"" +
                                               "}}", DID1, _seqNo, expectedData, _signatureType);

            var claimDefRequest = await Ledger.BuildClaimDefTxnAsync(DID1, _seqNo, _signatureType, data);


            Assert.IsTrue(claimDefRequest.Replace("\\", "").Contains(expectedResult));
        }
Example #3
0
        public async Task TestClaimDefRequestWorks()
        {
            var trusteeJson = "{\"seed\":\"000000000000000000000000Trustee1\"}";

            var trusteeDidResult = await Signus.CreateAndStoreMyDidAsync(_wallet, trusteeJson);

            var trusteeDid = trusteeDidResult.Did;

            var myJson = "{}";

            var myDidResult = await Signus.CreateAndStoreMyDidAsync(_wallet, myJson);

            var myDid    = myDidResult.Did;
            var myVerkey = myDidResult.VerKey;

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

            await Ledger.SignAndSubmitRequestAsync(_pool, _wallet, trusteeDid, nymRequest);

            var schemaData = "{\"name\":\"gvt2\",\"version\":\"2.0\",\"attr_names\": [\"name\", \"male\"]}";

            var schemaRequest = await Ledger.BuildSchemaRequestAsync(myDid, schemaData);

            await Ledger.SignAndSubmitRequestAsync(_pool, _wallet, myDid, schemaRequest);

            var getSchemaData    = "{\"name\":\"gvt2\",\"version\":\"2.0\"}";
            var getSchemaRequest = await Ledger.BuildGetSchemaRequestAsync(myDid, myDid, getSchemaData);

            var getSchemaResponse = await Ledger.SubmitRequestAsync(_pool, getSchemaRequest);

            var schemaObj = JObject.Parse(getSchemaResponse);

            var schemaSeqNo = (int)schemaObj["result"]["seqNo"];

            var claimDef = string.Format(_claimDefTemplate, schemaSeqNo, myDid);

            var claimDefObj = JObject.Parse(claimDef);

            var claimDefJson = claimDefObj["data"];

            var claimDefRequest = await Ledger.BuildClaimDefTxnAsync(myDid, schemaSeqNo, _signatureType, claimDefObj["data"].ToString());

            var claimDefResponse = await Ledger.SignAndSubmitRequestAsync(_pool, _wallet, myDid, claimDefRequest);

            var getClaimDefRequest = await Ledger.BuildGetClaimDefTxnAsync(myDid, schemaSeqNo, _signatureType, claimDefObj["origin"].ToString());

            var getClaimDefResponse = await Ledger.SubmitRequestAsync(_pool, getClaimDefRequest);

            var getClaimDefResponseObj = JObject.Parse(getClaimDefResponse);

            var expectedClaimDef = claimDefObj["data"]["primary"];
            var actualClaimDef   = getClaimDefResponseObj["result"]["data"]["primary"];

            Assert.AreEqual(expectedClaimDef["n"], actualClaimDef["n"]);
            Assert.AreEqual(expectedClaimDef["rms"], actualClaimDef["rms"]);
            Assert.AreEqual(expectedClaimDef["rctxt"], actualClaimDef["rctxt"]);
            Assert.AreEqual(expectedClaimDef["z"], actualClaimDef["z"]);
            Assert.AreEqual(expectedClaimDef["n"], actualClaimDef["n"]);

            //TODO: Check reworked asserts are correct.
            //JSON.NET does not guarantee the order of nodes in an object when serialized so the original test failed.

            var expectedR = (JObject)expectedClaimDef["r"];
            var actualR   = (JObject)actualClaimDef["r"];

            Assert.AreEqual(expectedR.Value <string>("age"), actualR.Value <string>("age"));
            Assert.AreEqual(expectedR.Value <string>("sex"), actualR.Value <string>("sex"));
            Assert.AreEqual(expectedR.Value <string>("height"), actualR.Value <string>("height"));
            Assert.AreEqual(expectedR.Value <string>("name"), actualR.Value <string>("name"));
        }