public async Task DisposeCanBeCalledRepeatedly()
        {
            var connection = await AgentConnection.ConnectAsync(_pool, _wallet, myDid.Did, myDid.Did);

            connection.Dispose();
            connection.Dispose();
        }
 public async Task CanDisposeClosedConnection()
 {
     using (var connection = await AgentConnection.ConnectAsync(_pool, _wallet, myDid.Did, myDid.Did))
     {
         await connection.CloseAsync();
     }
 }
        public async Task TestAgentCloseConnectionWorksForIncoming()
        {
            var endpoint = "127.0.0.1:9613";

            var 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);

            var activeListener = await AgentListener.ListenAsync(endpoint);

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

            var connection = await AgentConnection.ConnectAsync(_pool, _wallet, myDid.Did, myDid.Did);

            var connectionEvent = await activeListener.WaitForConnection();

            var serverToClientConnection = connectionEvent.Connection;

            await serverToClientConnection.CloseAsync();

            var ex = await Assert.ThrowsExceptionAsync <IndyException>(() =>
                                                                       serverToClientConnection.SendAsync("msg")
                                                                       );

            Assert.AreEqual(ErrorCode.CommonInvalidStructure, ex.ErrorCode);
        }
Beispiel #4
0
        [Ignore] //Wait until proper error is implemented in SDK and handle.
        public async Task CanCloseAfterDispose()
        {
            await PrepareForConnection("127.0.0.1:9618");

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

            connection.Dispose();
            await connection.CloseAsync();
        }
Beispiel #5
0
        public async Task DisposeCanBeCalledRepeatedly()
        {
            await PrepareForConnection("127.0.0.1:9611");

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

            connection.Dispose();
            connection.Dispose();
        }
Beispiel #6
0
        public async Task CanDisposeClosedConnection()
        {
            await PrepareForConnection("127.0.0.1:9610");

            using (var connection = await AgentConnection.ConnectAsync(pool, wallet, _myDid, _myDid))
            {
                await connection.CloseAsync();
            }
        }
        public async Task CanCloseAfterDispose()
        {
            var connection = await AgentConnection.ConnectAsync(_pool, _wallet, myDid.Did, myDid.Did);

            connection.Dispose();

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

            Assert.AreEqual(ErrorCode.CommonInvalidStructure, ex.ErrorCode);
        }
        [Ignore] //Appears endpoint cannot be re-connected to.  Requires further testing.
        public async Task EndpointCanBeReUsedAfterDispose()
        {
            var connection = await AgentConnection.ConnectAsync(_pool, _wallet, myDid.Did, myDid.Did);

            await connection.CloseAsync();

            connection.Dispose();

            using (var newConnection = await AgentConnection.ConnectAsync(_pool, _wallet, myDid.Did, myDid.Did))
            {
            }
        }
Beispiel #9
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);
        }
Beispiel #10
0
        [Ignore] //Appears endpoint cannot be re-connected to.  Requires further testing.
        public async Task EndpointCanBeReUsedAfterDispose()
        {
            await PrepareForConnection("127.0.0.1:9612");

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

            await connection.CloseAsync();

            connection.Dispose();

            using (var newConnection = await AgentConnection.ConnectAsync(pool, wallet, _myDid, _myDid))
            {
            }
        }
Beispiel #11
0
        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);
        }
Beispiel #12
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);
        }
Beispiel #13
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);
        }
Beispiel #14
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")
                                                                                   );
        }
Beispiel #15
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();
        }
Beispiel #16
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");
        }