public async Task TestNymRequestsWorks()
        {
            var trusteeDidResult = await Did.CreateAndStoreMyDidAsync(wallet, TRUSTEE_IDENTITY_JSON);

            var trusteeDid = trusteeDidResult.Did;

            var myDidResult = await Did.CreateAndStoreMyDidAsync(wallet, "{}");

            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 getNymRequest = await Ledger.BuildGetNymRequestAsync(myDid, myDid);

            var getNymResponse = await Ledger.SubmitRequestAsync(pool, getNymRequest);

            var getNymResponseObj = JObject.Parse(getNymResponse);

            Assert.AreEqual("REPLY", (string)getNymResponseObj["op"]);
            Assert.AreEqual("105", (string)getNymResponseObj["result"]["type"]);
            Assert.AreEqual(myDid, (string)getNymResponseObj["result"]["dest"]);
        }
        public async Task TestNymRequestsWorks()
        {
            var trusteeDidJson   = "{\"seed\":\"000000000000000000000000Trustee1\"}";
            var trusteeDidResult = await Signus.CreateAndStoreMyDidAsync(_wallet, trusteeDidJson);

            var trusteeDid = trusteeDidResult.Did;

            var myDidResult = await Signus.CreateAndStoreMyDidAsync(_wallet, "{}");

            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 getNymRequest = await Ledger.BuildGetNymRequestAsync(myDid, myDid);

            var getNymResponse = await Ledger.SubmitRequestAsync(_pool, getNymRequest);

            var getNymResponseObj = JObject.Parse(getNymResponse);

            Assert.AreEqual("REPLY", (string)getNymResponseObj["op"]);
            Assert.AreEqual("105", (string)getNymResponseObj["result"]["type"]);
            Assert.AreEqual(myDid, (string)getNymResponseObj["result"]["dest"]);
        }
        public async Task TestBuildGetNymRequestWorks()
        {
            var expectedResult = String.Format("\"identifier\":\"{0}\",\"operation\":{{\"type\":\"105\",\"dest\":\"{1}\"}}", DID1, _dest);

            var nymRequest = await Ledger.BuildGetNymRequestAsync(DID1, _dest);

            Assert.IsTrue(nymRequest.Contains(expectedResult));
        }
        /// <inheritdoc />
        public async Task <string> LookupNymAsync(Pool pool, string did)
        {
            var req = await Ledger.BuildGetNymRequestAsync(null, did);

            var res = await Ledger.SubmitRequestAsync(pool, req);

            EnsureSuccessResponse(res);

            return(res);
        }
        public async Task TestGetNymRequestWorks()
        {
            var didResult = await Did.CreateAndStoreMyDidAsync(wallet, TRUSTEE_IDENTITY_JSON);

            var did = didResult.Did;

            var getNymRequest = await Ledger.BuildGetNymRequestAsync(did, did);

            var getNymResponse = await Ledger.SubmitRequestAsync(pool, getNymRequest);

            var getNymResponseObj = JObject.Parse(getNymResponse);

            Assert.AreEqual(did, (string)getNymResponseObj["result"]["dest"]);
        }
        public async Task TestGetNymRequestWorks()
        {
            var didJson   = "{\"seed\":\"000000000000000000000000Trustee1\"}";
            var didResult = await Signus.CreateAndStoreMyDidAsync(_wallet, didJson);

            var did = didResult.Did;

            var getNymRequest = await Ledger.BuildGetNymRequestAsync(did, did);

            var getNymResponse = await Ledger.SubmitRequestAsync(_pool, getNymRequest);

            var getNymResponseObj = JObject.Parse(getNymResponse);

            Assert.AreEqual(did, (string)getNymResponseObj["result"]["dest"]);
        }
Exemple #7
0
        public async Task TestNymRequestsWorks()
        {
            var trusteeDidResult = await Did.CreateAndStoreMyDidAsync(wallet, TRUSTEE_IDENTITY_JSON);

            var trusteeDid = trusteeDidResult.Did;

            var myDidResult = await Did.CreateAndStoreMyDidAsync(wallet, "{}");

            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 getNymRequest = await Ledger.BuildGetNymRequestAsync(myDid, myDid);

            var getNymResponse = PoolUtils.EnsurePreviousRequestAppliedAsync(pool, getNymRequest, response => { return(CompareResponseType(response, "REPLY")); });

            Assert.IsNotNull(getNymResponse);
        }
    public static void Demo()
    {
        Console.WriteLine("Step 1 -- set up some constants");

        string walletName  = "myWallet";
        string poolName    = "pool";
        string stewardSeed = "000000000000000000000000Steward1";
        string poolConfig  = "{\"genesis_txn\": \"/home/vagrant/code/evernym/indy-sdk/cli/docker_pool_transactions_genesis\"}";


        // Step 2
        // Tell SDK which pool you are going to use. You should have already started
        // this pool using docker compose or similar.
        Console.WriteLine("Step 2 -- Creating a new local pool ledger configuration that can be used later to connect pool nodes.");
        Pool.CreatePoolLedgerConfigAsync(poolName, poolConfig);

        Console.WriteLine("          Open pool ledger and get the pool handle from libindy.");
        Pool pool = Pool.OpenPoolLedgerAsync(poolName, poolConfig).Result;

        Console.WriteLine("          Creates a new identity wallet.");
        Wallet.CreateWalletAsync(poolName, walletName, "default", string.Empty, string.Empty);

        Console.WriteLine("          Open identity wallet and get the wallet handle from libindy.");
        Wallet wallet = Wallet.OpenWalletAsync(walletName, string.Empty, string.Empty).Result;


        // Step 3
        // First, put a steward DID and its keypair in the wallet. This doesn't write anything to the ledger,
        // but it gives us a key that we can use to sign a ledger transaction that we're going to submit later.
        Console.WriteLine("Step 3 -- Generating and storing steward DID and Verkey.");

        // The DID and public verkey for this steward key are already in the ledger; they were part of the genesis
        // transactions we told the SDK to start with in the previous step. But we have to also put the DID, verkey,
        // and private signing key into our wallet, so we can use the signing key to submit an acceptably signed
        // transaction to the ledger, creating our *next* DID (which is truly new). This is why we use a hard-coded seed
        // when creating this DID--it guarantees that the same DID and key material are created that the genesis txns
        // expect.
        string didJson = "{\"seed\": \"" + stewardSeed + "\"}";
        CreateAndStoreMyDidResult stewardResult = Did.CreateAndStoreMyDidAsync(wallet, didJson).Result;
        string defaultStewardDid = stewardResult.Did;

        Console.WriteLine("          Steward DID    : {0}", defaultStewardDid);
        Console.WriteLine("          Steward VerKey : {0}", stewardResult.VerKey);

        // Now, create a new DID and verkey for a trust anchor, and store it in our wallet as well.Don't use a seed;
        // this DID and its keyas are secure and random. Again, we're not writing to the ledger yet.
        Console.WriteLine("          Generating and storing Trust Anchor DID and Verkey");
        CreateAndStoreMyDidResult trustAnchorResult = Did.CreateAndStoreMyDidAsync(wallet, "{}").Result;
        string trustAnchorDID    = trustAnchorResult.Did;
        string trustAnchorVerkey = trustAnchorResult.VerKey;

        Console.WriteLine("          Trust Anchor DID    : {0}", trustAnchorDID);
        Console.WriteLine("          Trust Anchor VerKey : {0}", trustAnchorVerkey);



        // Step 4
        // Here, we are building the transaction payload that we'll send to write the Trust Anchor identity to the ledger.
        // We submit this transaction under the authority of the steward DID that the ledger already recognizes.
        // This call will look up the private key of the steward DID in our wallet, and use it to sign the transaction.
        Console.WriteLine("Step 4 -- Build NYM request to add Trust Anchor to the ledger");
        string nymRequest = Ledger.BuildNymRequestAsync(defaultStewardDid, trustAnchorDID, trustAnchorVerkey, null, "TRUST_ANCHOR").Result;

        Console.WriteLine("          Nym Request JSON : {0}", nymRequest);

        // Now that we have the transaction ready, send it. The building and the sending are separate steps because some
        // clients may want to prepare transactions in one piece of code (e.g., that has access to privileged backend systems),
        // and communicate with the ledger in a different piece of code (e.g., that lives outside the safe internal
        // network).
        Console.WriteLine("          Build NYM request to add Trust Anchor to the ledger");
        String nymResponseJson = Ledger.SignAndSubmitRequestAsync(pool, wallet, defaultStewardDid, nymRequest).Result;

        Console.WriteLine("          NYM transaction response : {0}", nymResponseJson);

        // At this point, we have successfully written a new identity to the ledger. Our next step will be to query it.



        // Step 5
        // Here we are creating a third DID. This one is never written to the ledger, but we do have to have it in the
        // wallet, because every request to the ledger has to be signed by some requester. By creating a DID here, we
        // are forcing the wallet to allocate a keypair and identity that we can use to sign the request that's going
        // to read the trust anchor's info from the ledger.
        Console.WriteLine("Step 5 -- Generating and storing DID and Verkey to query the ledger with");
        CreateAndStoreMyDidResult clientResult = Did.CreateAndStoreMyDidAsync(wallet, "{}").Result;
        string clientDID    = trustAnchorResult.Did;
        string clientVerkey = trustAnchorResult.VerKey;

        Console.WriteLine("          Client DID    : {0}", clientDID);
        Console.WriteLine("          Client VerKey : {0}", clientVerkey);

        Console.WriteLine("          Building the GET_NYM request to query Trust Anchor's Verkey as the Client");
        string getNymRequest = Ledger.BuildGetNymRequestAsync(clientDID, trustAnchorDID).Result;

        Console.WriteLine("          GET_NYM request json : {0}", getNymRequest);

        Console.WriteLine("          Sending the GET_NYM request to the ledger");
        string getNymResponse = Ledger.SubmitRequestAsync(pool, getNymRequest).Result;

        Console.WriteLine("          GET_NYM result json : {0}", getNymResponse);

        // See whether we received the same info that we wrote the ledger in step 4.
        Console.WriteLine("          Comparing Trust Anchor Verkey as written by Steward and as retrieved in Client's query");
        var    getNymResponseObj = JObject.Parse(getNymResponse);
        string getNymVerKey      = getNymResponseObj["verKey"].ToString();

        Console.WriteLine("          Written by Steward  : {0}", trustAnchorVerkey);
        Console.WriteLine("          Queried from Ledger : {0}", getNymVerKey);
        Console.WriteLine("          Matching            : {0}", (string.Compare(getNymVerKey, trustAnchorVerkey) == 0, true, false));

        // Do some cleanup.
        Console.WriteLine("          Close and delete wallet");
        wallet.CloseAsync();

        Console.WriteLine("          Close pool");
        pool.CloseAsync();

        Console.WriteLine("          Delete pool ledger config");
        Pool.DeletePoolLedgerConfigAsync(poolName);
    }
Exemple #9
0
 public async Task TestBuildGetNymRequestWorksForDefaultSubmitter()
 {
     await Ledger.BuildGetNymRequestAsync(null, _dest);
 }