Esempio n. 1
0
        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 credentialDefinition = new CredentialDefinitionSchema()
            {
                SequenceNo = 1,
                Id         = "id",
                Name       = "name",
                Version    = "1.1",
                Tag        = "TAG"
            };

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

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

            Assert.IsNotNull(result);
            Assert.IsNotNull(result.SchemaId);
            Assert.IsNotNull(result.Tag);
            Assert.AreEqual(credentialDefinition.Tag, result.Tag);
            Assert.IsNotNull(result.Value);
            Assert.IsNotNull(result.Value.Primary);
            Assert.IsNotNull(result.Value.Primary.r);
            Assert.IsNotNull(result.Value.Primary.r.MasterSecret);
            Assert.AreEqual(credentialDefinition.AttributeNames.Count, result.Value.Primary.r.Attributes.Count);

            // clean up
            // Close and delete wallet
            // Close pool
            // Delete pool ledger config
            // SEE Cleanup() above
        }
        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
        }