public void ConvertsAttributeListToJsonSuccessfully()
        {
            AttributeValuesList list = new AttributeValuesList();

            list.Add(new AttributeWithValue()
            {
                Name       = "name_field",
                CheckValue = "check_value_field",
                Value      = "value_field"
            });

            string json         = list.ToJson();
            string expectedJson = "{\"name_field\":[\"value_field\",\"check_value_field\"]}";

            Assert.AreEqual(expectedJson, json, $"AttributeValuesList output is {json}");
        }
Example #2
0
        public IssuerCredential CreateCredential(IssuerCredentialOffer claimOffer, ProverCredentialRequest request, AttributeValuesList attributeValues, string revcationId = null, IBlobStorageReader reader = null)
        {
            string claimOfferJson        = claimOffer.ToJson();
            string credentialRequestJson = request.ToJson();
            string attributeValuesJson   = attributeValues.ToJson();

            //Logger.Info($"\n     claimOfferJson = {claimOfferJson}");
            //Logger.Info($"\n     credentialRequestJson = {credentialRequestJson}");
            //Logger.Info($"\n     attributeValuesJson = {attributeValuesJson}");

            IssuerCreateCredentialResult credentialResult = AnonCredsAsync.IssuerCreateCredentialAsync(_wallet, claimOfferJson, credentialRequestJson, attributeValuesJson, revcationId, reader).Result;

            /* here's what comes back.
             *  {
             *     "schema_id":"id",
             *     "cred_def_id":"Eo4fDS7JFYidRmCTYpxM8D:3:CL:1:TAG",
             *     "rev_reg_id":null,
             *     "values":{
             *        "height":{
             *           "raw":"175",
             *           "encoded":"175"
             *        },
             *        "sex":{
             *           "raw":"male",
             *           "encoded":"5944657099558967239210949258394887428692050081607692519917050011144233115103"
             *        },
             *        "age":{
             *           "raw":"27",
             *           "encoded":"27"
             *        },
             *        "name":{
             *           "raw":"Alex",
             *           "encoded":"99262857098057710338306967609588410025648622308394250666849665532448612202874"
             *        }
             *     },
             *     "signature":{
             *        "p_credential":{
             *           "m_2":"94141249536823555791556958352454414068832959837090304741968641158986385926676",
             *           "a":"8323332288664252783427676821045457475612521784608814011541341923485587617725984777235181184890142629699108349760164383728212528853028501250918088262532060211844075264206669140313009693546189699251574685560213711517469903818703879074476239039078328620548517525898491838522877250431561078064751213053410590410101165438102222417530659061266835969167075535437902735033653056560765994534497100821935622244615239416863701177712259395727362404400435334042457516385116244472976813842575355024925419592558950377852585171254701784306916491778197264072325586166244416062710740654823911714771843967643357713104583763825844898603",
             *           "e":"259344723055062059907025491480697571938277889515152306249728583105665800713306759149981690559193987143012367913206299323899696942213235956742930060377963820203874793638160040955661",
             *           "v":"7116791841216643605806132922471918810530603205786140082127764783074742665808976581706290333160205346320350030185475272873444992655573813271903498274011266552422799355150146028910550269789156481465993272118732907571755105523497865615124405921516267663927425203942212450068377170838210496716497180444061091115871500878332700682503775305328976077032880441319647645266911962057541572276963031632084026970709990182627506528636976756150219524414872482370127261485905272143924636368905355144297418919251181316158735155809349770598838182048801142221550337446605104694255022037751989156123955485144312728746052576135240009582908593503850082616242661870092365307275549192424180347189490756108891521166863564342684115685835430770088452510084201376851238193804825429138278441268162228679560852216513635610718052218265015819730207633"
             *        },
             *        "r_credential":null
             *     },
             *     "signature_correctness_proof":{
             *        "se":"23517870644417168860936261855438589759353852590514979104397219907457258591177640505267679875002557681226621144357025639497346325770337643878487434876918481104566146211961273713122104201084305014358893221548189880301875133901670782733835206189071592927729376377681150774201104957206749648815536075161399954687422481722324731447954411973815350341650706632300090301180877699820357354765338496900150492757655845500340545065384336816379076413150453608294683709404586326701685229371750634388046970171288371882157492599450010625859267329399571040938050507851344981041236819163797087069796101746522362854436506022481968440685",
             *        "c":"8496172404567780250403063769714240044570433755835923246846940171384309456027"
             *     },
             *     "rev_reg":null,
             *     "witness":null
             *  }
             */


            //Logger.Info($"\n ------- CreateCredential ----------- ");
            //Logger.Info($"\n     credentialJson = {credentialResult.CredentialJson}");
            //Logger.Info($"\n ------------------------------------ ");

            return(JsonConvert.DeserializeObject <IssuerCredential>(credentialResult.CredentialJson));
        }
        public void Demo()
        {
            // Initialization
            // 1. Creating a new local pool ledger configuration that can be used later to connect pool nodes.
            // 2. Open pool ledger and get the pool handle from libindy.
            // 3. Creates a new identity wallet
            // 4. Open identity wallet and get the wallet handle from libindy
            // SEE Initialize() above

            // 5. Generating and storing steward DID and Verkey
            IDid stewardDid = IndyDotNet.Did.Factory.CreateMyDid(_pool, _wallet, new IdentitySeed()
            {
                Seed = "000000000000000000000000Steward1"
            });

            // 6. Generating and storing Trust Anchor DID and Verkey
            IDid trustAnchor = IndyDotNet.Did.Factory.CreateMyDid(_pool, _wallet, null);

            // 7. Build NYM request to add Trust Anchor to the ledger
            INymLedger         nymLedger  = IndyDotNet.Ledger.Factory.CreateNymLedger();
            BuildRequestResult nymRequest = nymLedger.BuildRequest(stewardDid, trustAnchor, trustAnchor.VerKey, "", NymRoles.TrustAnchor);

            // 8. Sending the nym request to ledger
            SignAndSubmitRequestResponse nymResult = nymLedger.SignAndSubmitRequest(_pool, _wallet, stewardDid, nymRequest);

            // 9. build the schema definition request
            SchemaDefinition schemaDefinition = new SchemaDefinition()
            {
                Name    = "name",
                Version = "1.1",
                Id      = "id"
            };

            schemaDefinition.AttributeNames.Add("age");
            schemaDefinition.AttributeNames.Add("height");
            schemaDefinition.AttributeNames.Add("sex");
            schemaDefinition.AttributeNames.Add("name");

            ISchemaLedger     schemaLedger = IndyDotNet.Ledger.Factory.CreateSchemaLedger();
            BuildSchemaResult buildSchema  = schemaLedger.BuildSchemaRequest(stewardDid, schemaDefinition);

            // 10. Sending the SCHEMA request to the ledger
            SignAndSubmitRequestResponse signAndSubmitRequestResponse = schemaLedger.SignAndSubmitRequest(_pool, _wallet, stewardDid, buildSchema);

            // 11. Creating and storing CLAIM DEFINITION using anoncreds as Trust Anchor, for the given Schema
            IIssuerAnonCreds           issuer           = IndyDotNet.AnonCreds.Factory.GetIssuerAnonCreds(_wallet);
            CredentialDefinitionSchema credentialschema = new CredentialDefinitionSchema()
            {
                SequenceNo = 1,
                Id         = "id",
                Name       = "name",
                Version    = "1.1",
                Tag        = "TAG"
            };

            credentialschema.AttributeNames.Add("age");
            credentialschema.AttributeNames.Add("height");
            credentialschema.AttributeNames.Add("sex");
            credentialschema.AttributeNames.Add("name");

            IssuerCredentialDefinition credentialDefinition = issuer.CreateStoreCredentialDef(trustAnchor, credentialschema);

            // 12. Creating Prover wallet and opening it to get the handle
            WalletConfig config = new WalletConfig()
            {
                Id = "ProverIssueCredentialDemoWalletId"
            };

            _proverWallet = IndyDotNet.Wallet.Factory.GetWallet(config, _credentials);
            _proverWallet.Create();
            _proverWallet.Open();

            // 13. Prover is creating Master Secret
            IProverAnonCreds prover = IndyDotNet.AnonCreds.Factory.GetProverAnonCreds(_proverWallet);

            prover.CreateMasterSecret("master_secret");

            // 14. Issuer(Trust Anchor) is creating a Claim Offer for Prover
            IssuerCredentialOffer claimOffer = issuer.CreateCredentialOffer(credentialDefinition.Id);

            // 15. Prover creates Claim Request
            IDid proverDID = IndyDotNet.Did.Factory.CreateMyDid(_pool, _proverWallet, null);

            (ProverCredentialRequest credentialRequest, ProverCredentialRequestMetadata credentialRequestMetadata) = prover.CreateCredentialRequest(proverDID, claimOffer, credentialDefinition, "master_secret");

            Assert.AreEqual(credentialRequest.CredDefId, claimOffer.CredDefId);
            Assert.AreEqual(credentialRequest.ProverDid, proverDID.Did);

            // 16. Issuer(Trust Anchor) creates Claim for Claim Request
            AttributeValuesList attributes = new AttributeValuesList();

            attributes.Add(new AttributeWithValue()
            {
                Name       = "age",
                Value      = "27",
                CheckValue = "27"
            });
            attributes.Add(new AttributeWithValue()
            {
                Name       = "height",
                Value      = "175",
                CheckValue = "175"
            });
            attributes.Add(new AttributeWithValue()
            {
                Name       = "name",
                Value      = "Alex",
                CheckValue = "99262857098057710338306967609588410025648622308394250666849665532448612202874"
            });
            attributes.Add(new AttributeWithValue()
            {
                Name       = "sex",
                Value      = "male",
                CheckValue = "5944657099558967239210949258394887428692050081607692519917050011144233115103"
            });

            IssuerCredential issuerCredential = issuer.CreateCredential(claimOffer, credentialRequest, attributes);

            // 17. Prover processes and stores Claim
            string proverCredentialId = prover.SaveCredential(issuerCredential, credentialDefinition, credentialRequestMetadata);

            Assert.IsTrue(string.IsNullOrEmpty(proverCredentialId), "SaveCredential did not return proverCredentialId");

            // clean up
            // Close and delete wallet
            // Close pool
            // Delete pool ledger config
            // SEE Cleanup() above
        }