/// <summary> /// Creates a new outgoing connection. /// </summary> /// <remarks> /// <para>When establishing a connection two DIDs are required, one for the sender identity (who is /// initiating the connection) and the other for the receiver identity (who the connection is being /// established with). /// </para> /// <para>The <see cref="Wallet"/> provided when creating the connection must contain information about /// the sender identity which must have been added using the <see cref="Signus.CreateAndStoreMyDidAsync(Wallet, string)"/> /// method prior to attempting to create the connection. /// </para> /// <para>The identity information for the receiver can also be stored in the wallet using /// the <see cref="Signus.StoreTheirDidAsync(Wallet, string)"/> method, however if no record is /// present in the wallet the identity information will be established from the ledger in the /// provided node <see cref="Pool"/> and will automatically be cached in the provided wallet. /// </para> /// </remarks> /// <seealso cref="Pool"/> /// <seealso cref="Wallet"/> /// <seealso cref="Signus"/> /// <param name="pool">The node pool that the destination DID is registered on.</param> /// <param name="wallet">The wallet containing the sender (and optionally receiver) DID.</param> /// <param name="senderDid">The DID of the identity imitating the connection.</param> /// <param name="receiverDid">The DID of the identity the connection is to be established with.</param> /// <returns>An asynchronous <see cref="Task{T}"/> that resolves to an AgentConnection instance /// when the connection has been established.</returns> public static Task <AgentConnection> ConnectAsync(Pool pool, Wallet wallet, string senderDid, string receiverDid) { ParamGuard.NotNull(pool, "pool"); ParamGuard.NotNull(wallet, "wallet"); ParamGuard.NotNullOrWhiteSpace(senderDid, "senderDid"); ParamGuard.NotNullOrWhiteSpace(receiverDid, "receiverDid"); var connection = new AgentConnection(); var taskCompletionSource = new TaskCompletionSource <AgentConnection>(connection); var commandHandle = PendingCommands.Add(taskCompletionSource); var result = IndyNativeMethods.indy_agent_connect( commandHandle, pool.Handle, wallet.Handle, senderDid, receiverDid, _connectionEstablishedCallback, connection.MessageReceivedCallback); CallbackHelper.CheckResult(result); return(taskCompletionSource.Task); }
/// <summary> /// Creates a connection to an agent. /// </summary> /// <param name="pool">The ledger pool that the destination DID is registered on.</param> /// <param name="wallet">The wallet containing the keys for the DIDs.</param> /// <param name="senderDid">The DID to use when initiating the connection.</param> /// <param name="receiverDid">The DID of the target of the connection.</param> /// <param name="messageReceivedHandler">The observer that will receive message events from the connection.</param> /// <returns>An asynchronous task that returns a Connection result.</returns> public static Task <Connection> AgentConnectAsync(Pool pool, Wallet wallet, string senderDid, string receiverDid, MessageReceivedHandler messageReceivedHandler) { var taskCompletionSource = new TaskCompletionSource <Connection>(); var commandHandle = AddTaskCompletionSource(taskCompletionSource); AddMessageReceivedHandler(commandHandle, messageReceivedHandler); var result = IndyNativeMethods.indy_agent_connect( commandHandle, pool.Handle, wallet.Handle, senderDid, receiverDid, _connectionEstablishedCallback, _connectionMessageReceivedCallback); CheckResult(result); return(taskCompletionSource.Task); }