public async Task CanCloseAfterDispose()
        {
            var listener = await AgentListener.ListenAsync(endpoint);

            listener.Dispose();

            var ex = await Assert.ThrowsExceptionAsync <IndyException>(() =>
                                                                       listener.CloseAsync()
                                                                       );

            Assert.AreEqual(ErrorCode.WalletAlreadyExistsError, ex.ErrorCode);
        }
Exemple #2
0
        public async Task TestAgentConnectWorksForRemoteData()
        {
            var endpoint           = "127.0.0.1:9605";
            var listenerWalletName = "listenerWallet";
            var trusteeWalletName  = "trusteeWallet";

            await Wallet.CreateWalletAsync(_poolName, listenerWalletName, "default", null, null);

            var listenerWallet = await Wallet.OpenWalletAsync(listenerWalletName, null, null);

            await Wallet.CreateWalletAsync(_poolName, trusteeWalletName, "default", null, null);

            var trusteeWallet = await Wallet.OpenWalletAsync(trusteeWalletName, null, null);

            var senderWallet = trusteeWallet;

            var createMyDidResult = await Signus.CreateAndStoreMyDidAsync(listenerWallet, "{}");

            var listenerDid    = createMyDidResult.Did;
            var listenerVerkey = createMyDidResult.VerKey;
            var listenerPk     = createMyDidResult.Pk;

            var trusteeDidJson = "{\"seed\":\"000000000000000000000000Trustee1\"}";

            var trusteeDidResult = await Signus.CreateAndStoreMyDidAsync(trusteeWallet, trusteeDidJson);

            var trusteeDid = trusteeDidResult.Did;
            var senderDid  = trusteeDid;

            var nymRequest = await Ledger.BuildNymRequestAsync(trusteeDid, listenerDid, listenerVerkey, null, null);

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

            var attribRequest = await Ledger.BuildAttribRequestAsync(listenerDid, listenerDid, null,
                                                                     string.Format("{{\"endpoint\":{{\"ha\":\"{0}\",\"verkey\":\"{1}\"}}}}", endpoint, listenerPk), null);

            await Ledger.SignAndSubmitRequestAsync(_pool, listenerWallet, listenerDid, attribRequest);

            var activeListener = await AgentListener.ListenAsync(endpoint);

            await activeListener.AddIdentityAsync(_pool, listenerWallet, listenerDid);

            await AgentConnection.ConnectAsync(_pool, senderWallet, senderDid, listenerDid);

            await listenerWallet.CloseAsync();

            await Wallet.DeleteWalletAsync(listenerWalletName, null);

            await trusteeWallet.CloseAsync();

            await Wallet.DeleteWalletAsync(trusteeWalletName, null);
        }
Exemple #3
0
        public async Task PrepareForConnection(string endpoint)
        {
            var myDidResult = await Signus.CreateAndStoreMyDidAsync(wallet, "{}");

            _myDid = myDidResult.Did;

            var identityJson = string.Format(AGENT_IDENTITY_JSON_TEMPLATE, _myDid, myDidResult.Pk, myDidResult.VerKey, endpoint);
            await Signus.StoreTheirDidAsync(wallet, identityJson);

            _activeListener = await AgentListener.ListenAsync(endpoint);

            await _activeListener.AddIdentityAsync(pool, wallet, _myDid);
        }
Exemple #4
0
        public async Task TestAgentListenWorks()
        {
            var endpoint = "127.0.0.1:9607";

            var didJson = "{\"seed\":\"indy_agent_connect_works_for_aaa\"}";

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

            var identityJson = string.Format("{{\"did\":\"{0}\", \"pk\":\"{1}\", \"verkey\":\"{2}\", \"endpoint\":\"{3}\"}}",
                                             myDidResult.Did, myDidResult.Pk, myDidResult.VerKey, endpoint);
            await Signus.StoreTheirDidAsync(_wallet, identityJson);

            await AgentListener.ListenAsync(endpoint);
        }
Exemple #5
0
        [Ignore]//Appears endpoint cannot be re-connected to.  Requires further testing.
        public async Task EndpointCanBeReUsedAfterDispose()
        {
            var endpoint = "127.0.0.1:9616";

            await PrepareForListener(endpoint);

            var listener = await AgentListener.ListenAsync(endpoint);

            listener.Dispose();

            using (var newListener = await AgentListener.ListenAsync(endpoint))
            {
            }
        }
        public async Task TestAgentConnectWorksForAllDataInWalletPresent()
        {
            var endpoint = "127.0.0.1:9606";

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

            var identityJson = string.Format(AGENT_IDENTITY_JSON_TEMPLATE, myDidResult.Did, myDidResult.Pk, myDidResult.VerKey, endpoint);
            await Signus.StoreTheirDidAsync(wallet, identityJson);

            var activeListener = await AgentListener.ListenAsync(endpoint);

            await activeListener.AddIdentityAsync(pool, wallet, myDidResult.Did);

            await AgentConnection.ConnectAsync(pool, wallet, myDidResult.Did, myDidResult.Did);
        }
        public async Task PrepareForConnection()
        {
            var endpoint = "127.0.0.1:9603";

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

            var identityJson = string.Format("{{\"did\":\"{0}\", \"pk\":\"{1}\", \"verkey\":\"{2}\", \"endpoint\":\"{3}\"}}",
                                             myDid.Did, myDid.Pk, myDid.VerKey, endpoint);

            await Signus.StoreTheirDidAsync(_wallet, identityJson);

            activeListener = await AgentListener.ListenAsync(endpoint);

            await activeListener.AddIdentityAsync(_pool, _wallet, myDid.Did);
        }
Exemple #8
0
        public async Task TestAgentConnectWorksForAllDataInWalletPresent()
        {
            var endpoint = "127.0.0.1:9606";

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

            var identityJson = string.Format("{{\"did\":\"{0}\", \"pk\":\"{1}\", \"verkey\":\"{2}\", \"endpoint\":\"{3}\"}}",
                                             myDidResult.Did, myDidResult.Pk, myDidResult.VerKey, endpoint);
            await Signus.StoreTheirDidAsync(_wallet, identityJson);

            var activeListener = await AgentListener.ListenAsync(endpoint);

            await activeListener.AddIdentityAsync(_pool, _wallet, myDidResult.Did);

            await AgentConnection.ConnectAsync(_pool, _wallet, myDidResult.Did, myDidResult.Did);
        }
        public async Task TestAgentAddIdentityWorksForMultiplyKeys()
        {
            var endpoint = "127.0.0.1:9602";

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

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

            CreateAndStoreMyDidResult[] didResults = { myDid1, myDid2 };

            var activeListener = await AgentListener.ListenAsync(endpoint);

            foreach (var didResult in didResults)
            {
                await activeListener.AddIdentityAsync(_pool, _wallet, didResult.Did);
            }
        }
Exemple #10
0
        public async Task TestAgentSendWorks()
        {
            var endpoint = "127.0.0.1:9609";

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

            var identityJson = string.Format("{{\"did\":\"{0}\", \"pk\":\"{1}\", \"verkey\":\"{2}\", \"endpoint\":\"{3}\"}}",
                                             myDidResult.Did, myDidResult.Pk, myDidResult.VerKey, endpoint);
            await Signus.StoreTheirDidAsync(_wallet, identityJson);

            var listener = await AgentListener.ListenAsync(endpoint);

            await listener.AddIdentityAsync(_pool, _wallet, myDidResult.Did);

            var clientConnection = await AgentConnection.ConnectAsync(_pool, _wallet, myDidResult.Did, myDidResult.Did);

            var connectionEvent = await listener.WaitForConnection();

            var serverConnection = connectionEvent.Connection;

            var waitListenerConnectionTask = listener.WaitForConnection(); //Start waiting for additional connections - we'll never get one in this test, however.

            var clientToServerMessage = "msg_from_client";
            var serverToClientMessage = "msg_from_server";

            await clientConnection.SendAsync(clientToServerMessage);

            var waitServerMessageTask = serverConnection.WaitForMessage();

            var completedTask = await Task.WhenAny(waitListenerConnectionTask, waitServerMessageTask); //Wait for either an additional connection or message and proceed when one has arrived.

            Assert.AreEqual(completedTask, waitServerMessageTask);

            var serverMessageEvent = await waitServerMessageTask;

            Assert.AreEqual(clientToServerMessage, serverMessageEvent.Message);

            await serverConnection.SendAsync(serverToClientMessage);

            var clientMessageEvent = await clientConnection.WaitForMessage();

            Assert.AreEqual(serverToClientMessage, clientMessageEvent.Message);
        }
Exemple #11
0
        public async Task TestAgentCloseConnectionWorksForOutgoing()
        {
            var endpoint = "127.0.0.1:9603";

            var myDid = await Signus.CreateAndStoreMyDidAsync(wallet, "{}");

            var identityJson = string.Format(AGENT_IDENTITY_JSON_TEMPLATE, myDid.Did, myDid.Pk, myDid.VerKey, endpoint);
            await Signus.StoreTheirDidAsync(wallet, identityJson);

            var activeListener = await AgentListener.ListenAsync(endpoint);

            await activeListener.AddIdentityAsync(pool, wallet, myDid.Did);

            var connection = await AgentConnection.ConnectAsync(pool, wallet, myDid.Did, myDid.Did);

            await connection.CloseAsync();

            var ex = await Assert.ThrowsExceptionAsync <InvalidStructureException>(() =>
                                                                                   connection.SendAsync("msg")
                                                                                   );
        }
Exemple #12
0
        public async Task TestAgentDemo()
        {
            var endpoint           = "127.0.0.1:9801";
            var listenerWalletName = "listenerWallet";
            var trusteeWalletName  = "trusteeWallet";
            var message            = "test";

            //1. Create and Open Pool
            var poolName = PoolUtils.CreatePoolLedgerConfig();
            var pool     = await Pool.OpenPoolLedgerAsync(poolName, "{}");

            //2. Create and Open Listener Wallet
            await Wallet.CreateWalletAsync(poolName, listenerWalletName, "default", null, null);

            var listenerWallet = await Wallet.OpenWalletAsync(listenerWalletName, null, null);

            //3. Create and Open Trustee Wallet
            await Wallet.CreateWalletAsync(poolName, trusteeWalletName, "default", null, null);

            var trusteeWallet = await Wallet.OpenWalletAsync(trusteeWalletName, null, null);

            var senderWallet = trusteeWallet;

            //4. Create My Did
            var createMyDidResult = await Signus.CreateAndStoreMyDidAsync(listenerWallet, "{}");

            var listenerDid    = createMyDidResult.Did;
            var listenerVerkey = createMyDidResult.VerKey;
            var listenerPk     = createMyDidResult.Pk;

            //5. Create Their Did from Trustee seed
            var trusteeDidJson = "{\"seed\":\"000000000000000000000000Trustee1\"}";

            var trusteeDidResult = await Signus.CreateAndStoreMyDidAsync(trusteeWallet, trusteeDidJson);

            var trusteeDid = trusteeDidResult.Did;
            var senderDid  = trusteeDid;

            // 6. Prepare and Send NYM request with signing
            var nymRequest = await Ledger.BuildNymRequestAsync(trusteeDid, listenerDid, listenerVerkey, null, null);

            await Ledger.SignAndSubmitRequestAsync(pool, trusteeWallet, trusteeDid, nymRequest);

            // 7. Prepare and Send Attrib for listener (will be requested from ledger and used by sender at start connection)
            var rawJson       = string.Format("{{\"endpoint\":{{\"ha\":\"{0}\",\"verkey\":\"{1}\"}}}}", endpoint, listenerPk);
            var attribRequest = await Ledger.BuildAttribRequestAsync(listenerDid, listenerDid, null, rawJson, null);

            await Ledger.SignAndSubmitRequestAsync(pool, listenerWallet, listenerDid, attribRequest);

            // 8. start listener on endpoint
            var activeListener = await AgentListener.ListenAsync(endpoint);

            // 9. Allow listener accept incoming connection for specific DID (listener_did)
            await activeListener.AddIdentityAsync(pool, listenerWallet, listenerDid);

            // 10. Initiate connection from sender to listener
            var connection = await AgentConnection.ConnectAsync(pool, senderWallet, senderDid, listenerDid);

            // 11. Send test message from sender to listener
            await connection.SendAsync("test");

            var serverConnectionEvent = await activeListener.WaitForConnection();

            var serverConnection = serverConnectionEvent.Connection;
            var messageEvent     = await serverConnection.WaitForMessage();

            Assert.AreEqual(message, messageEvent.Message);

            // 12. Close connection
            await connection.CloseAsync();

            // 13. Close listener
            await activeListener.CloseAsync();

            // 14. Close and delete Issuer Wallet
            await listenerWallet.CloseAsync();

            await Wallet.DeleteWalletAsync(listenerWalletName, null);

            // 15. Close and delete Prover Wallet
            await trusteeWallet.CloseAsync();

            await Wallet.DeleteWalletAsync(trusteeWalletName, null);

            //16. Close Pool
            await pool.CloseAsync();
        }
Exemple #13
0
        public static async Task Execute()
        {
            Console.WriteLine("Agent sample -> started");

            var listenerWalletName = "listenerWallet";
            var trusteeWalletName  = "trusteeWallet";
            var endpoint           = "127.0.0.1:9801";
            var message            = "test";
            var trusteeSeed        = "000000000000000000000000Trustee1";

            try
            {
                //1. Create Pool
                await PoolUtils.CreatePoolLedgerConfig();

                //2. Create Listener Wallet
                await WalletUtils.CreateWalleatAsync(PoolUtils.DEFAULT_POOL_NAME, listenerWalletName, "default", null, null);

                //3. Create Trustee Wallet
                await WalletUtils.CreateWalleatAsync(PoolUtils.DEFAULT_POOL_NAME, trusteeWalletName, "default", null, null);

                //4. Open pool and wallets in using statements to ensure they are closed when finished.
                using (var pool = await Pool.OpenPoolLedgerAsync(PoolUtils.DEFAULT_POOL_NAME, "{}"))
                    using (var listenerWallet = await Wallet.OpenWalletAsync(listenerWalletName, null, null))
                        using (var trusteeWallet = await Wallet.OpenWalletAsync(trusteeWalletName, null, null))
                        {
                            var senderWallet = trusteeWallet;

                            //5. Create My Did
                            var createMyDidResult = await Signus.CreateAndStoreMyDidAsync(listenerWallet, "{}");

                            var listenerDid    = createMyDidResult.Did;
                            var listenerVerkey = createMyDidResult.VerKey;
                            var listenerPk     = createMyDidResult.Pk;

                            //6. Create Their Did from Trustee seed
                            var trusteeDidJson = string.Format("{{\"seed\":\"{0}\"}}", trusteeSeed);

                            var trusteeDidResult = await Signus.CreateAndStoreMyDidAsync(trusteeWallet, trusteeDidJson);

                            var trusteeDid = trusteeDidResult.Did;
                            var senderDid  = trusteeDid;

                            //7. Prepare and Send NYM request with signing
                            var nymRequest = await Ledger.BuildNymRequestAsync(trusteeDid, listenerDid, listenerVerkey, null, null);

                            await Ledger.SignAndSubmitRequestAsync(pool, trusteeWallet, trusteeDid, nymRequest);

                            //8. Prepare and Send Attrib for listener (will be requested from ledger and used by sender at start connection)
                            var rawAttribJson = string.Format("{{\"endpoint\":{{\"ha\":\"{0}\",\"verkey\":\"{1}\"}}}}", endpoint, listenerPk);
                            var attribRequest = await Ledger.BuildAttribRequestAsync(listenerDid, listenerDid, null, rawAttribJson, null);

                            await Ledger.SignAndSubmitRequestAsync(pool, listenerWallet, listenerDid, attribRequest);

                            //9. start listener on endpoint
                            var activeListener = await AgentListener.ListenAsync(endpoint);

                            //10. Allow listener accept incoming connection for specific DID (listener_did)
                            await activeListener.AddIdentityAsync(pool, listenerWallet, listenerDid);

                            //11. Initiate connection from sender to listener
                            var sendingConnection = await AgentConnection.ConnectAsync(pool, senderWallet, senderDid, listenerDid);

                            var connectionEvent = await activeListener.WaitForConnectionAsync();

                            var receivingConnection = connectionEvent.Connection;

                            //12. Send test message from sender to listener
                            await sendingConnection.SendAsync(message);

                            var messageEvent = await receivingConnection.WaitForMessageAsync();

                            Debug.Assert(string.Equals(message, messageEvent.Message));

                            //13. Close connection
                            await sendingConnection.CloseAsync();

                            //14. Close listener
                            await activeListener.CloseAsync();

                            //15. Close wallets and pool
                            await listenerWallet.CloseAsync();

                            await trusteeWallet.CloseAsync();

                            await pool.CloseAsync();
                        }
            }
            finally
            {
                // 16. Delete Pool ledger config and wallets
                await PoolUtils.DeletePoolLedgerConfigAsync(PoolUtils.DEFAULT_POOL_NAME);

                await WalletUtils.DeleteWalletAsync(listenerWalletName, null);

                await WalletUtils.DeleteWalletAsync(trusteeWalletName, null);
            }

            Console.WriteLine("Agent sample -> completed");
        }