public async Task Before()
        {
            StorageUtils.CleanupStorage();

            //1. Create Issuer wallet, get wallet handle
            await WalletUtils.CreateWallet(WALLET_NAME, WALLET_KEY);

            _issuerWallet = await WalletUtils.OpenWallet(WALLET_NAME, WALLET_KEY);

            //2. Issuer create claim definition
            IssuerCreateAndStoreCredentialDefResult result = await AnonCreds.IssuerCreateAndStoreCredentialDefAsync(_issuerWallet, issuerDid, schema, null, null, null);

            _claimDefJson = result.CredDefJson;

            //3. Issuer create revocation registry
            BlobStorageWriter tailsWriter = await BlobStorage.OpenWriterAsync("default", _tailsWriterConfig);

            await AnonCreds.IssuerCreateAndStoreRevocRegAsync(_issuerWallet, issuerDid, null, null, null, null, tailsWriter);

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

            //8. Prover store received Claim
            // TODO await AnonCreds.ProverStoreClaimAsync(_issuerWallet, _claimResult.CredentialJson, _claimResult.RevocRegDeltaJson);
        }
        public async Task TestIssuerCreateAndStoreClaimDefWorksForCorrectCryptoType()
        {
            IssuerCreateAndStoreCredentialDefResult claimDefType = await AnonCreds.IssuerCreateAndStoreCredentialDefAsync(_wallet, _issuerDid, _gvtSchemaJson, DEFAULT_SIGNATURE_TYPE, null, null);

            Assert.IsNotNull(claimDefType);

            var claimDefObject = JObject.Parse(claimDefType.CredDefJson);
            var primary        = claimDefObject["value"]["primary"];

            Assert.AreEqual(((JObject)primary["r"]).Count, 5, "length of primary.r didn't match");
            Assert.IsTrue(primary.Value <string>("n").Length > 0, "n had zero length");
            Assert.IsTrue(primary.Value <string>("s").Length > 0, "s had zero length");
            Assert.IsTrue(primary.Value <string>("z").Length > 0, "z had zero length");
            Assert.IsTrue(primary.Value <string>("rctxt").Length > 0, "rctxt had zero length");
        }
Ejemplo n.º 3
0
        public IssuerCredentialDefinition CreateStoreCredentialDef(IDid issuerDid, CredentialDefinitionSchema definition)
        {
            string schemaJson    = definition.ToJson();
            string tag           = definition.Tag;
            string configJson    = definition.Config.ToJson();
            string signatureType = definition.SignatureType;

            //Logger.Info($"     schemaJson = {schemaJson}");
            //Logger.Info($"     configJson = {configJson}");
            //Logger.Info($"     tag = {tag}");
            //Logger.Info($"     signatureType = {signatureType}");

            IssuerCreateAndStoreCredentialDefResult result = AnonCredsAsync.IssuerCreateAndStoreCredentialDefAsync(_wallet, issuerDid, schemaJson, tag, signatureType, configJson).Result;

            return(JsonConvert.DeserializeObject <IssuerCredentialDefinition>(result.CredDefJson));
        }
        protected async Task InitCommonWallet()
        {
            if (_walletOpened)
            {
                return;
            }

            StorageUtils.CleanupStorage();

            await WalletUtils.CreateWallet(WALLET_NAME, WALLET_KEY);

            commonWallet = await WalletUtils.OpenWallet(WALLET_NAME, WALLET_KEY);

            IssuerCreateAndStoreCredentialDefResult claimDefType = await AnonCreds.IssuerCreateAndStoreCredentialDefAsync(commonWallet, issuerDid, schema, null, null, null);

            claimDef = claimDefType.CredDefJson;

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

            // TODO await AnonCreds.ProverStoreCredentialOfferAsync(commonWallet, string.Format(claimOfferTemplate, issuerDid, 2), null, null, null, null);
            // TODO await AnonCreds.ProverStoreCredentialOfferAsync(commonWallet, string.Format(claimOfferTemplate, issuerDid2, 2), null, null, null, null);

            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" +
                        "        }";

            //TODO var createClaimResult = await AnonCreds.IssuerCreateCredentialAsync(commonWallet, claimRequest, claim, -1);

            //TODO var claimJson = createClaimResult.ClaimJson;

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

            _walletOpened = true;
        }