예제 #1
0
        /// <summary>
        /// Builds Indy request for getting UTXO list for payment address
        /// according to this payment method.
        ///
        /// Note this endpoint is EXPERIMENTAL. Function signature and behaviour may change
        /// in the future releases.
        /// </summary>
        /// <returns>get_utxo_txn_json - Indy request for getting UTXO list for payment address
        /// payment_method</returns>
        /// <param name="wallet">Wallet.</param>
        /// <param name="submittedDid">DID of request sender</param>
        /// <param name="paymentAddress">target payment address</param>
        public static Task <PaymentResult> BuildGetPaymentSourcesAsync(Wallet wallet, string submittedDid, string paymentAddress)
        {
            ParamGuard.NotNullOrWhiteSpace(submittedDid, "submittedDid");
            ParamGuard.NotNullOrWhiteSpace(paymentAddress, "paymentAddress");

            var taskCompletionSource = new TaskCompletionSource <PaymentResult>();
            var commandHandle        = PendingCommands.Add(taskCompletionSource);

            var result = NativeMethods.indy_build_get_payment_sources_request(
                commandHandle,
                wallet.Handle,
                submittedDid,
                paymentAddress,
                BuildGetUtxoRequestCallback);

            CallbackHelper.CheckResult(result);

            return(taskCompletionSource.Task);
        }
예제 #2
0
        /// <summary>
        /// Deletes a wallet.
        /// </summary>
        /// <remarks>
        /// <para>Deletes a wallet created earlier using the <see cref="CreateWalletAsync(string, string)"/>
        /// by name.
        /// </para>
        /// <para>The <paramref name="credentials"/> parameter is unused in the default wallet at present,
        /// however the value can be used by custom wallet implementations; it is up to the custom wallet
        /// type implementer to interpret the value.
        /// </para>
        /// </remarks>
        /// <param name="config">The name of the wallet to delete.</param>
        /// <param name="credentials">The wallet credentials.</param>
        /// <returns>An asynchronous <see cref="Task"/> with no return value that completes when the operation completes.</returns>
        public static Task DeleteWalletAsync(string config, string credentials)
        {
            ParamGuard.NotNullOrWhiteSpace(config, "config");
            ParamGuard.NotNullOrWhiteSpace(credentials, "credentials");

            var taskCompletionSource = new TaskCompletionSource <bool>();
            var commandHandle        = PendingCommands.Add(taskCompletionSource);

            var result = NativeMethods.indy_delete_wallet(
                commandHandle,
                config,
                credentials,
                CallbackHelper.TaskCompletingNoValueCallback
                );

            CallbackHelper.CheckResult(result);

            return(taskCompletionSource.Task);
        }
예제 #3
0
        /// <summary>
        /// Builds a SCHEMA request. Request to add Credential's schema.
        /// </summary>
        /// <returns>The get schema request async.</returns>
        /// <param name="submitterDid">DID of the submitter stored in secured Wallet..</param>
        /// <param name="schemaId">Schema ID in ledger</param>
        public static Task <string> BuildGetSchemaRequestAsync(string submitterDid, string schemaId)
        {
            ParamGuard.NotNullOrWhiteSpace(submitterDid, "submitterDid");
            ParamGuard.NotNullOrWhiteSpace(schemaId, "schemaId");

            var taskCompletionSource = new TaskCompletionSource <string>();
            var commandHandle        = PendingCommands.Add(taskCompletionSource);

            var result = NativeMethods.indy_build_get_schema_request(
                commandHandle,
                submitterDid,
                schemaId,
                BuildRequestCallback
                );

            CallbackHelper.CheckResult(result);

            return(taskCompletionSource.Task);
        }
예제 #4
0
        /// <summary>
        /// Retrieves abbreviated verkey if it is possible otherwise return full verkey.
        /// </summary>
        /// <returns>The verkey async.</returns>
        /// <param name="did">Did.</param>
        /// <param name="fullVerkey">Full verkey.</param>
        public static Task <string> AbbreviateVerkeyAsync(string did, string fullVerkey)
        {
            ParamGuard.NotNullOrWhiteSpace(did, "did");
            ParamGuard.NotNullOrWhiteSpace(fullVerkey, "fullVerkey");

            var taskCompletionSource = new TaskCompletionSource <string>();
            var commandHandle        = PendingCommands.Add(taskCompletionSource);

            var commandResult = NativeMethods.indy_abbreviate_verkey(
                commandHandle,
                did,
                fullVerkey,
                AbbreviateVerkeyCompletedCallback
                );

            CallbackHelper.CheckResult(commandResult);

            return(taskCompletionSource.Task);
        }
예제 #5
0
        /// <summary>
        /// Get info about My DID in format: DID, verkey, metadata
        /// </summary>
        /// <returns>The my did with meta async.</returns>
        /// <param name="wallet">Wallet.</param>
        /// <param name="myDid">My did.</param>
        public static Task <string> GetMyDidWithMetaAsync(Wallet wallet, string myDid)
        {
            ParamGuard.NotNull(wallet, "wallet");
            ParamGuard.NotNullOrWhiteSpace(myDid, "myDid");

            var taskCompletionSource = new TaskCompletionSource <string>();
            var commandHandle        = PendingCommands.Add(taskCompletionSource);

            var commandResult = NativeMethods.indy_get_my_did_with_meta(
                commandHandle,
                wallet.Handle,
                myDid,
                GetMyDidWithMetaCompletedCallback
                );

            CallbackHelper.CheckResult(commandResult);

            return(taskCompletionSource.Task);
        }
예제 #6
0
        /// <summary>
        /// Gets the verification key for the specified DID.
        /// </summary>
        /// <remarks>
        /// This method will obtain the verification key associated with the specified <paramref name="did"/>from the provided <paramref name="wallet"/> but will
        /// not attempt to retrieve the key from the ledger if not present in the wallet, nor will it perform any freshness check against the ledger to determine
        /// if the key is up-to-date.  To ensure that the key is fresh use the <see cref="KeyForDidAsync(Pool, Wallet, string)"/> method instead.
        /// <note type="note">
        /// The <see cref="CreateAndStoreMyDidAsync(Wallet, string)"/> and <see cref="Crypto.CreateKeyAsync(Wallet, string)"/> methods both create
        /// similar wallet records so the returned verification key in all generic crypto and messaging functions.
        /// </note>
        /// </remarks>
        /// <param name="wallet">The wallet to resolve the DID from.</param>
        /// <param name="did">The DID to get the verification key for.</param>
        /// <returns>An asynchronous <see cref="Task{T}"/> that resolves to a string containing the verification key associated with the DID.</returns>
        /// <exception cref="WalletValueNotFoundException">Thrown if the DID could not be resolved from the <paramref name="wallet"/>.</exception>
        public static Task <string> KeyForLocalDidAsync(Wallet wallet, string did)
        {
            ParamGuard.NotNull(wallet, "wallet");
            ParamGuard.NotNullOrWhiteSpace(did, "did");

            var taskCompletionSource = new TaskCompletionSource <string>();
            var commandHandle        = PendingCommands.Add(taskCompletionSource);

            var commandResult = NativeMethods.indy_key_for_local_did(
                commandHandle,
                wallet.Handle,
                did,
                KeyForLocalDidCompletedCallback
                );

            CallbackHelper.CheckResult(commandResult);

            return(taskCompletionSource.Task);
        }
예제 #7
0
        /// <summary>
        /// Create the payment address for this payment method.
        ///
        /// This method generates private part of payment address
        /// and stores it in a secure place. Ideally it should be
        /// secret in libindy wallet (see crypto module).
        ///
        /// Note that payment method should be able to resolve this
        /// secret by fully resolvable payment address format.
        /// </summary>
        /// <returns>Public identifier of payment address in fully resolvable payment address format</returns>
        /// <param name="wallet">Wallet.</param>
        /// <param name="paymentMethod">Payment method to use (for example, 'sov')</param>
        /// <param name="config">
        /// <code>payment address config as json:
        ///   {
        ///     seed: &lt;str&gt;, // allows deterministic creation of payment address
        ///   }
        /// </code>
        /// </param>
        public static Task <string> CreatePaymentAddressAsync(Wallet wallet, string paymentMethod, string config)
        {
            ParamGuard.NotNull(wallet, "wallet");
            ParamGuard.NotNullOrWhiteSpace(paymentMethod, "paymentMethod");

            var taskCompletionSource = new TaskCompletionSource <string>();
            var commandHandle        = PendingCommands.Add(taskCompletionSource);

            var result = NativeMethods.indy_create_payment_address(
                commandHandle,
                wallet.Handle,
                paymentMethod,
                config,
                CreatePaymentAddressCallback);

            CallbackHelper.CheckResult(result);

            return(taskCompletionSource.Task);
        }
예제 #8
0
        /// <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)
        {
            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);
        }
예제 #9
0
        /// <summary>
        /// Search for wallet records.
        ///
        /// Note instead of immediately returning of fetched records
        /// this call returns wallet_search_handle that can be used later
        /// to fetch records by small batches (with indy_fetch_wallet_search_next_records).
        /// </summary>
        /// <returns>The search async.</returns>
        /// <param name="wallet">Wallet.</param>
        /// <param name="type">Type.</param>
        /// <param name="queryJson">
        /// MongoDB style query to wallet record tags:
        /// <code>
        ///  {
        ///    "tagName": "tagValue",
        ///    $or: {
        ///      "tagName2": { $regex: 'pattern' },
        ///      "tagName3": { $gte: '123' },
        ///    },
        ///  }
        /// </code>
        /// </param>
        /// <param name="optionsJson">
        /// <code>
        /// {
        ///    retrieveRecords: (optional, true by default) If false only "counts" will be calculated,
        ///    retrieveTotalCount: (optional, false by default) Calculate total count,
        ///    retrieveType: (optional, false by default) Retrieve record type,
        ///    retrieveValue: (optional, true by default) Retrieve record value,
        ///    retrieveTags: (optional, false by default) Retrieve record tags,
        ///  }
        /// </code></param>
        public static Task <WalletSearch> OpenSearchAsync(Wallet wallet, string type, string queryJson, string optionsJson)
        {
            ParamGuard.NotNull(wallet, "wallet");
            ParamGuard.NotNullOrWhiteSpace(type, "type");
            ParamGuard.NotNullOrWhiteSpace(queryJson, "queryJson");
            ParamGuard.NotNullOrWhiteSpace(optionsJson, "optionsJson");

            var taskCompletionSource = new TaskCompletionSource <WalletSearch>();
            var commandHandle        = PendingCommands.Add(taskCompletionSource);

            var result = NativeMethods.indy_open_wallet_search(
                commandHandle,
                wallet.Handle,
                type,
                queryJson,
                optionsJson,
                OpenSearchCallback);

            return(taskCompletionSource.Task);
        }
예제 #10
0
        /// <summary>
        /// Gets request requirements (with minimal price) correspondent to specific auth rule
        /// in case the requester can perform this action.
        ///
        /// EXPERIMENTAL
        ///
        /// If the requester does not match to the request constraints `TransactionNotAllowed` error will be thrown.
        /// </summary>
        /// <param name="getAuthRuleResponseJson">Response on `GET_AUTH_RULE` request returning action constraints set on the ledger.</param>
        /// <param name="requesterInfoJson">
        /// {
        ///     "role": string (optional) - role of a user which can sign a transaction.
        ///     "sig_count": u64 - number of signers.
        ///     "is_owner": bool (optional) - if user is an owner of transaction (false by default).
        ///     "is_off_ledger_signature": bool (optional) - if user did is unknow for ledger (false by default).
        /// }</param>
        /// <param name="feesJson">fees set on the ledger (result of <see cref="ParseGetTxnFeesResponseAsync" />).</param>
        /// <returns>
        /// request info if a requester match to the action constraints.
        /// {
        ///     "price": u64 - fee required for the action performing,
        ///     "requirements": [{
        ///         "role": string (optional) - role of users who should sign,
        ///         "sig_count": u64 - number of signers,
        ///         "need_to_be_owner": bool - if requester need to be owner,
        ///         "off_ledger_signature": bool - allow signature of unknow for ledger did (false by default).
        ///     }]
        /// }
        /// </returns>
        public static Task <string> GetRequestInfoAsync(string getAuthRuleResponseJson, string requesterInfoJson, string feesJson)
        {
            ParamGuard.NotNullOrWhiteSpace(getAuthRuleResponseJson, "getAuthRuleResponseJson");
            ParamGuard.NotNullOrWhiteSpace(requesterInfoJson, "requesterInfoJson");
            ParamGuard.NotNullOrWhiteSpace(feesJson, "feesJson");

            var taskCompletionSource = new TaskCompletionSource <string>();
            var commandHandle        = PendingCommands.Add(taskCompletionSource);

            var result = NativeMethods.indy_get_request_info(
                commandHandle,
                getAuthRuleResponseJson,
                requesterInfoJson,
                feesJson,
                GetRequestInfoDelegate);

            CallbackHelper.CheckResult(result);

            return(taskCompletionSource.Task);
        }
예제 #11
0
        /// <summary>
        /// Builds Indy request for doing tokens minting
        /// according to this payment method.
        ///
        /// Note this endpoint is EXPERIMENTAL. Function signature and behaviour may change
        /// in the future releases.
        /// </summary>
        /// <returns>Indy request for doing tokens minting.</returns>
        /// <param name="wallet">Wallet.</param>
        /// <param name="submitterDid">Submitter did.</param>
        /// <param name="outputsJson">The list of UTXO outputs as json array:
        ///   [{
        ///     paymentAddress: &lt;str>, // payment address used as output
        ///     amount: &lt;int>, // amount of tokens to transfer to this payment address
        ///     extra: &lt;str>, // optional data
        ///   }]</param>
        /// <param name="extra">Optional information for payment operation</param>
        public static Task <PaymentResult> BuildMintRequestAsync(Wallet wallet, string submitterDid, string outputsJson, string extra)
        {
            ParamGuard.NotNull(wallet, "wallet");
            ParamGuard.NotNullOrWhiteSpace(outputsJson, "outputsJson");

            var taskCompletionSource = new TaskCompletionSource <PaymentResult>();
            var commandHandle        = PendingCommands.Add(taskCompletionSource);

            var result = NativeMethods.indy_build_mint_req(
                commandHandle,
                wallet.Handle,
                submitterDid,
                outputsJson,
                extra,
                BuildMintRequestCallback);

            CallbackHelper.CheckResult(result);

            return(taskCompletionSource.Task);
        }
예제 #12
0
        /// <summary>
        /// Creates a proof for the provided proof request.
        /// </summary>
        /// <remarks>
        /// <para>
        /// Either a corresponding claim with optionally revealed attributes or self-attested attribute
        /// must be provided for each requested attribute - see the
        /// <see cref="ProverGetClaimsForProofReqAsync(Wallet, string)"/> method.
        /// A proof request may request multiple claims from different schema and different issuers.
        /// All required schema, public keys and revocation registries must be provided.
        /// The proof request also contains a nonce.
        /// The proof contains either proof or self-attested attribute value for each requested attribute.
        /// </para>
        /// <para>
        /// The <paramref name="proofReqJson"/> parameter expects a JSON string containing a proof request
        /// from the party that will verify the proof.  E.g.:
        /// <code>
        ///  {
        ///     "nonce": string,
        ///     "requested_attr1_uuid": &lt;attr_info&gt;,
        ///     "requested_attr2_uuid": &lt;attr_info&gt;,
        ///     "requested_attr3_uuid": &lt;attr_info&gt;,
        ///     "requested_predicate_1_uuid": &lt;predicate_info&gt;,
        ///     "requested_predicate_2_uuid": &lt;predicate_info&gt;,
        /// }
        /// </code>
        /// </para>
        /// <para>
        /// The <paramref name="requestedClaimsJson"/> parameter should contain either a claim or a
        /// self-attested attribute for each attribute requested in the proof request.  E.g.:
        /// <code>
        /// {
        ///     "requested_attr1_uuid": [claim1_uuid_in_wallet, true &lt;reveal_attr&gt;],
        ///     "requested_attr2_uuid": [self_attested_attribute],
        ///     "requested_attr3_uuid": [claim2_seq_no_in_wallet, false]
        ///     "requested_attr4_uuid": [claim2_seq_no_in_wallet, true]
        ///     "requested_predicate_1_uuid": [claim2_seq_no_in_wallet],
        ///     "requested_predicate_2_uuid": [claim3_seq_no_in_wallet],
        /// }
        /// </code>
        /// </para>
        /// <para>
        /// The <paramref name="schemasJson"/> parameter expects the JSON for each schema that participates
        /// in the proof request.  E.g.:
        /// <code>
        /// {
        ///     "claim1_uuid_in_wallet": &lt;schema1&gt;,
        ///     "claim2_uuid_in_wallet": &lt;schema2&gt;,
        ///     "claim3_uuid_in_wallet": &lt;schema3&gt;,
        /// }
        /// </code>
        /// </para>
        /// <para>
        /// The <paramref name="masterSecretName"/> specifies the name of the master secret stored in
        /// the wallet.
        /// </para>
        /// <para>
        /// The <paramref name="claimDefsJson"/> parameter expects the JSON for each claim definition
        /// participating in the proof request. E.g.:
        /// <code>
        /// {
        ///     "claim1_uuid_in_wallet": &lt;claim_def1&gt;,
        ///     "claim2_uuid_in_wallet": &lt;claim_def2&gt;,
        ///     "claim3_uuid_in_wallet": &lt;claim_def3&gt;,
        /// }
        /// </code>
        /// </para>
        /// <para>
        /// The <paramref name="revocRegsJson"/> parameter expects the JSON for each revocation registry
        /// participating in the proof request.  E.g.:
        /// <code>
        /// {
        ///     "claim1_uuid_in_wallet": &lt;revoc_reg1&gt;,
        ///     "claim2_uuid_in_wallet": &lt;revoc_reg2&gt;,
        ///     "claim3_uuid_in_wallet": &lt;revoc_reg3&gt;,
        /// }
        /// </code>
        /// </para>
        /// Upon successful completion the operation will return a JSON string.
        /// For each requested attribute either a proof (with optionally revealed attribute value) or
        /// self-attested attribute value is provided.
        /// Each proof is associated with a claim and corresponding schema_seq_no, issuer_did and revoc_reg_seq_no.
        /// There is also aggregated proof part common for all claim proofs.
        /// <code>
        /// {
        ///     "requested": {
        ///         "requested_attr1_id": [claim_proof1_uuid, revealed_attr1, revealed_attr1_as_int],
        ///         "requested_attr2_id": [self_attested_attribute],
        ///         "requested_attr3_id": [claim_proof2_uuid]
        ///         "requested_attr4_id": [claim_proof2_uuid, revealed_attr4, revealed_attr4_as_int],
        ///         "requested_predicate_1_uuid": [claim_proof2_uuid],
        ///         "requested_predicate_2_uuid": [claim_proof3_uuid],
        ///         }
        ///     "claim_proofs": {
        ///         "claim_proof1_uuid": [&lt;claim_proof&gt;, issuer_did, schema_seq_no, revoc_reg_seq_no],
        ///         "claim_proof2_uuid": [&lt;claim_proof&gt;, issuer_did, schema_seq_no, revoc_reg_seq_no],
        ///         "claim_proof3_uuid": [&lt;claim_proof&gt;, issuer_did, schema_seq_no, revoc_reg_seq_no]
        ///     },
        ///     "aggregated_proof": &lt;aggregated_proof&gt;
        /// }
        /// </code>
        /// </remarks>
        /// <param name="wallet">The target wallet.</param>
        /// <param name="proofReqJson">The proof request JSON.</param>
        /// <param name="requestedClaimsJson">The requested claims JSON.</param>
        /// <param name="schemasJson">The schema JSON.</param>
        /// <param name="masterSecretName">The master secret name.</param>
        /// <param name="claimDefsJson">The claim definitions JSON.</param>
        /// <param name="revocRegsJson">The revocation registries JSON.</param>
        /// <returns>An asynchronous <see cref="Task{T}"/> that, when the operation completes, resolves
        /// to a JSON string containing the proof.</returns>
        public static Task <string> ProverCreateProofAsync(Wallet wallet, string proofReqJson, string requestedClaimsJson, string schemasJson, string masterSecretName, string claimDefsJson, string revocRegsJson)
        {
            var taskCompletionSource = new TaskCompletionSource <string>();
            var commandHandle        = PendingCommands.Add(taskCompletionSource);

            var commandResult = IndyNativeMethods.indy_prover_create_proof(
                commandHandle,
                wallet.Handle,
                proofReqJson,
                requestedClaimsJson,
                schemasJson,
                masterSecretName,
                claimDefsJson,
                revocRegsJson,
                _proverCreateProofCallback);

            CallbackHelper.CheckResult(commandResult);

            return(taskCompletionSource.Task);
        }
예제 #13
0
        /// <summary>
        /// Updates and stores the provided claim in the specified wallet.
        /// </summary>
        /// <remarks>
        /// <para>
        /// This method updates the claim provided in the <paramref name="claimsJson"/> parameter
        /// with a blinded master secret and stores it in the wallet specified in the
        /// <paramref name="wallet"/> parameter.
        /// </para>
        /// <para>
        /// The claim JSON is typically structured as follows:
        /// <code>
        /// {
        ///     "claim": {attr1:[value, value_as_int]}
        ///     "signature": &lt;signature&gt;,
        ///     "schema_seq_no": string,
        ///     "revoc_reg_seq_no", string
        ///     "issuer_did", string
        /// }
        /// </code>
        /// It contains the information about the <c>schema_seq_no</c>, <c>issuer_did</c>
        /// and <c>revoc_reg_seq_no</c> - see the <see cref="IssuerCreateClaimAsync(Wallet, string, string, int)"/>
        /// method for details.
        /// </para>
        /// Seq_no is a sequence number of the corresponding transaction in the ledger.
        /// </remarks>
        /// <param name="wallet">The target wallet.</param>
        /// <param name="claimsJson">The claims JSON.</param>
        /// <param name="revRegJson">revocation registry json</param>
        /// <returns>An asynchronous <see cref="Task"/> that completes when the operation has completed.</returns>
        public static Task ProverStoreClaimAsync(Wallet wallet, string claimsJson, string revRegJson)
        {
            ParamGuard.NotNull(wallet, "wallet");
            ParamGuard.NotNullOrWhiteSpace(claimsJson, "claimsJson");

            var taskCompletionSource = new TaskCompletionSource <bool>();
            var commandHandle        = PendingCommands.Add(taskCompletionSource);

            var commandResult = NativeMethods.indy_prover_store_claim(
                commandHandle,
                wallet.Handle,
                claimsJson,
                revRegJson,
                CallbackHelper.TaskCompletingNoValueCallback
                );

            CallbackHelper.CheckResult(commandResult);

            return(taskCompletionSource.Task);
        }
예제 #14
0
        /// <summary>
        /// Send action to particular nodes of validator pool.
        /// </summary>
        /// <param name="pool">The validator pool to submit the request to.</param>
        /// <param name="requestJson">The request to submit.</param>
        /// <param name="nodes">A list of node names to send the request to.</param>
        /// <param name="timeout">The time in seconds to wait for a response from the nodes.</param>
        /// <remarks>
        /// The list of node names in the <paramref name="nodes"/> parameter is optional, however if provided it should conform
        /// to the format ["Node1", "Node2",...."NodeN"].  To use the default timeout provide the value -1 to the
        /// <paramref name="timeout"/> parameter.
        /// </remarks>
        /// <returns>An asynchronous <see cref="Task{T}"/> that resolves to a JSON <see cref="string"/>
        /// containing the results when the operation completes.</returns>
        public static Task <string> SubmitActionAsync(Pool pool, string requestJson, string nodes, int timeout)
        {
            ParamGuard.NotNull(pool, "pool");
            ParamGuard.NotNullOrWhiteSpace(requestJson, "requestJson");

            var taskCompletionSource = new TaskCompletionSource <string>();
            var commandHandle        = PendingCommands.Add(taskCompletionSource);

            var result = NativeMethods.indy_submit_action(
                commandHandle,
                pool.Handle,
                requestJson,
                nodes,
                timeout,
                SubmitRequestCallback);

            CallbackHelper.CheckResult(result);

            return(taskCompletionSource.Task);
        }
예제 #15
0
        /// <summary>
        /// Closes the connection.
        /// </summary>
        /// <remarks>
        /// Once closed a connection instance cannot be re-opened; a new connection instance must be
        /// created.
        /// </remarks>
        /// <returns>An asynchronous <see cref="Task"/> completes once the operation completes.</returns>
        public Task CloseAsync()
        {
            _requiresClose = false;

            var taskCompletionSource = new TaskCompletionSource <bool>();
            var commandHandle        = PendingCommands.Add(taskCompletionSource);

            var result = IndyNativeMethods.indy_agent_close_connection(
                commandHandle,
                Handle,
                CallbackHelper.TaskCompletingNoValueCallback
                );

            CallbackHelper.CheckResult(result);


            GC.SuppressFinalize(this);

            return(taskCompletionSource.Task);
        }
예제 #16
0
        /// <summary>
        /// Builds a GET_REVOC_REG_DELTA request. Request to get the delta of the accumulated state of the Revocation Registry.
        /// The Delta is defined by from and to timestamp fields.
        /// If from is not specified, then the whole state till to will be returned.
        /// </summary>
        /// <returns>Request result as json.</returns>
        /// <param name="submitterDid">DID of the read request sender.</param>
        /// <param name="revocRegDefId">ID of the corresponding Revocation Registry Definition in ledger.</param>
        /// <param name="from">Requested time represented as a total number of seconds from Unix Epoch.</param>
        /// <param name="to">Requested time represented as a total number of seconds from Unix Epoch.</param>
        public static Task <string> BuildGetRevocRegDeltaRequestAsync(string submitterDid, string revocRegDefId, long from, long to)
        {
            ParamGuard.NotNullOrWhiteSpace(submitterDid, "submitterDid");
            ParamGuard.NotNullOrWhiteSpace(revocRegDefId, "id");

            var taskCompletionSource = new TaskCompletionSource <string>();
            var commandHandle        = PendingCommands.Add(taskCompletionSource);

            var result = NativeMethods.indy_build_get_revoc_reg_delta_request(
                commandHandle,
                submitterDid,
                revocRegDefId,
                from,
                to,
                BuildRequestCallback);

            CallbackHelper.CheckResult(result);

            return(taskCompletionSource.Task);
        }
예제 #17
0
        /// <summary>
        /// Sets metadata for the specified DID.
        /// </summary>
        /// <remarks>
        /// Any existing metadata stored for the DID will be replaced.
        /// </remarks>
        /// <param name="wallet">The wallet containing the DID.</param>
        /// <param name="did">The DID to set the metadata on.</param>
        /// <param name="metadata">The metadata to store.</param>
        /// <returns>An asynchronous <see cref="Task"/> that completes when the operation completes.</returns>
        /// <exception cref="WalletItemNotFoundException">Thrown if the <paramref name="wallet"/> does not contain the specified <paramref name="did"/>.</exception>
        /// <exception cref="InvalidStructureException">Thrown if the value provided to the <paramref name="did"/> parameter is malformed.</exception>
        public static Task SetDidMetadataAsync(Wallet wallet, string did, string metadata)
        {
            ParamGuard.NotNull(wallet, "wallet");
            ParamGuard.NotNullOrWhiteSpace(did, "did");

            var taskCompletionSource = new TaskCompletionSource <bool>();
            var commandHandle        = PendingCommands.Add(taskCompletionSource);

            var commandResult = NativeMethods.indy_set_did_metadata(
                commandHandle,
                wallet.Handle,
                did,
                metadata,
                CallbackHelper.TaskCompletingNoValueCallback
                );

            CallbackHelper.CheckResult(commandResult);

            return(taskCompletionSource.Task);
        }
예제 #18
0
        /// <summary>
        /// Builds Indy request for information to verify the payment receipt
        /// </summary>
        /// <returns>Indy request for verification receipt.</returns>
        /// <param name="wallet">Wallet.</param>
        /// <param name="submitterDid">DID of request sender</param>
        /// <param name="receipt">Payment receipt to verify.</param>
        public static Task <PaymentResult> BuildVerifyPaymentRequestAsync(IWallet wallet, IDid submitterDid, string receipt)
        {
            ParamGuard.NotNull(wallet, "wallet");
            ParamGuard.NotNull(submitterDid, "submitterDid");
            ParamGuard.NotNullOrWhiteSpace(receipt, "receipt");

            var taskCompletionSource = new TaskCompletionSource <PaymentResult>();
            var commandHandle        = PendingCommands.Add(taskCompletionSource);

            var result = NativeMethods.indy_build_verify_payment_req(
                commandHandle,
                wallet.Handle,
                submitterDid.Did,
                receipt,
                BuildVerifyPaymentRequestCallback);

            CallbackHelper.CheckResult(result);

            return(taskCompletionSource.Task);
        }
예제 #19
0
        /// <summary>
        /// Signs a request message.
        /// </summary>
        /// <remarks>
        /// This method adds information associated with the submitter specified by the
        /// <paramref name="submitterDid"/> to the JSON provided in the <paramref name="requestJson"/> parameter
        /// then signs it with the submitter's signing key from the provided wallet.
        /// </remarks>
        /// <param name="wallet">The wallet to use for signing.</param>
        /// <param name="submitterDid">The DID of the submitter identity in the provided wallet.</param>
        /// <param name="requestJson">The request JSON to sign.</param>
        /// <returns>An asynchronous task that resolves to a <see cref="string"/> containing the signed
        /// message.</returns>
        public static Task <string> SignRequestAsync(Wallet wallet, string submitterDid, string requestJson)
        {
            ParamGuard.NotNull(wallet, "wallet");
            ParamGuard.NotNullOrWhiteSpace(submitterDid, "submitterDid");
            ParamGuard.NotNullOrWhiteSpace(requestJson, "requestJson");

            var taskCompletionSource = new TaskCompletionSource <string>();
            var commandHandle        = PendingCommands.Add(taskCompletionSource);

            int result = NativeMethods.indy_sign_request(
                commandHandle,
                wallet.Handle,
                submitterDid,
                requestJson,
                SignRequestCallback);

            CallbackHelper.CheckResult(result);

            return(taskCompletionSource.Task);
        }
예제 #20
0
        /// <summary>
        /// Generates new signing and encryption keys in the specified wallet for an existing DID owned by the caller
        /// </summary>
        /// <remarks>
        /// The developer has some control over the generation of the new keys through the value passed to
        /// the <paramref name="identityJson"/> parameter.  This parameter expects a valid JSON string
        /// with the following optional members:
        /// <code>
        /// {
        ///     "seed": string, (optional) Seed that allows deterministic key creation (if not set random one will be created).
        ///                                Can be UTF-8, base64 or hex string.
        ///     "crypto_type": string, (optional) if not set then ed25519 curve is used;
        ///               currently only 'ed25519' value is supported for this field)
        /// }
        /// </code>
        /// <para>The <c>seed</c> member controls the seed that will be used to generate they keys.
        /// If not provided a random one will be created.</para>
        /// <para>The <c>crypto_type</c> member specifies the type of cryptographic algorithm will be
        /// used to generate they keys.  If not provided then ed22519 curve will be used.
        /// <note type="note">The only value currently supported for this member is 'ed25519'.</note>
        /// </para>
        /// </remarks>
        /// <param name="wallet">The wallet the DID is stored in.</param>
        /// <param name="did">The did to replace the keys for.</param>
        /// <param name="identityJson">The identity information as JSON.</param>
        /// <returns>An asynchronous <see cref="Task{T}"/> that resolves to a string containing the new verification key when the operation completes.</returns>
        public static Task <string> ReplaceKeysStartAsync(Wallet wallet, string did, string identityJson)
        {
            ParamGuard.NotNull(wallet, "wallet");
            ParamGuard.NotNullOrWhiteSpace(did, "did");
            ParamGuard.NotNullOrWhiteSpace(identityJson, "identityJson");

            var taskCompletionSource = new TaskCompletionSource <string>();
            var commandHandle        = PendingCommands.Add(taskCompletionSource);

            var commandResult = NativeMethods.indy_replace_keys_start(
                commandHandle,
                wallet.Handle,
                did,
                identityJson,
                ReplaceKeysCallback);

            CallbackHelper.CheckResult(commandResult);

            return(taskCompletionSource.Task);
        }
예제 #21
0
        /// <summary>
        /// Encrypts a message by anonymous-encryption scheme.
        ///
        /// Sealed boxes are designed to anonymously send messages to a Recipient given its public key.
        /// Only the Recipient can decrypt these messages, using its private key.
        /// While the Recipient can verify the integrity of the message, it cannot verify the identity of the Sender.
        ///
        /// Note to use DID keys with this function you can call indy_key_for_did to get key id (verkey)
        /// for specific DID.
        /// </summary>
        /// <returns>The crypt async.</returns>
        /// <param name="theirVk">id (verkey) of their key</param>
        /// <param name="message">Message to be encrypted</param>
        public static Task <byte[]> AnonCryptAsync(string theirVk, byte[] message)
        {
            ParamGuard.NotNullOrWhiteSpace(theirVk, "theirVk");
            ParamGuard.NotNull(message, "message");

            var taskCompletionSource = new TaskCompletionSource <byte[]>();
            var commandHandle        = PendingCommands.Add(taskCompletionSource);

            var commandResult = NativeMethods.indy_crypto_anon_crypt(
                commandHandle,
                theirVk,
                message,
                message.Length,
                _cryptoEncryptCompletedCallback
                );

            CallbackHelper.CheckResult(commandResult);

            return(taskCompletionSource.Task);
        }
예제 #22
0
        /// <summary>
        /// Builds Indy get request for getting fees for transactions in the ledger
        ///
        /// Note this endpoint is EXPERIMENTAL. Function signature and behaviour may change
        /// in the future releases.
        /// </summary>
        /// <returns>Indy request for getting fees for transactions in the ledger.</returns>
        /// <param name="wallet">Wallet.</param>
        /// <param name="submitterDid">DID of request sender</param>
        /// <param name="paymentMethod">Payment method.</param>
        public static Task <string> BuildGetTxnFeesRequestAsync(IWallet wallet, IDid submitterDid, string paymentMethod)
        {
            ParamGuard.NotNull(wallet, "wallet");
            ParamGuard.NotNull(submitterDid, "submitterDid");
            ParamGuard.NotNullOrWhiteSpace(paymentMethod, "paymentMethod");

            var taskCompletionSource = new TaskCompletionSource <string>();
            var commandHandle        = PendingCommands.Add(taskCompletionSource);

            var result = NativeMethods.indy_build_get_txn_fees_req(
                commandHandle,
                wallet.Handle,
                submitterDid.Did,
                paymentMethod,
                BuildGetTxnFeesReqCallback);

            CallbackHelper.CheckResult(result);

            return(taskCompletionSource.Task);
        }
예제 #23
0
        /// <summary>
        /// Update a non-secret wallet record value
        /// </summary>
        /// <returns>The record async.</returns>
        /// <param name="wallet">Wallet.</param>
        /// <param name="type">Allows to separate different record types collections.</param>
        /// <param name="id">The id of record.</param>
        /// <param name="value">The value of record.</param>
        public static Task UpdateRecordValueAsync(Wallet wallet, string type, string id, string value)
        {
            ParamGuard.NotNull(wallet, "wallet");
            ParamGuard.NotNullOrWhiteSpace(type, "type");
            ParamGuard.NotNullOrWhiteSpace(id, "id");
            ParamGuard.NotNullOrWhiteSpace(value, "value");

            var taskCompletionSource = new TaskCompletionSource <bool>();
            var commandHandle        = PendingCommands.Add(taskCompletionSource);

            var result = NativeMethods.indy_update_wallet_record_value(
                commandHandle,
                wallet.Handle,
                type,
                id,
                value,
                CallbackHelper.TaskCompletingNoValueCallback);

            return(taskCompletionSource.Task);
        }
예제 #24
0
        /// <summary>
        /// Delete tags from the wallet record
        /// </summary>
        /// <returns>The record tags async.</returns>
        /// <param name="wallet">Wallet.</param>
        /// <param name="type">Allows to separate different record types collections.</param>
        /// <param name="id">The id of record.</param>
        /// <param name="tagsJson">the list of tag names to remove from the record as json array:
        /// <c>  ["tagName1", "tagName2", ...]</c></param>
        public static Task DeleteRecordTagsAsync(Wallet wallet, string type, string id, string tagsJson)
        {
            ParamGuard.NotNull(wallet, "wallet");
            ParamGuard.NotNullOrWhiteSpace(type, "type");
            ParamGuard.NotNullOrWhiteSpace(id, "id");
            ParamGuard.NotNullOrWhiteSpace(tagsJson, "tagsJson");

            var taskCompletionSource = new TaskCompletionSource <bool>();
            var commandHandle        = PendingCommands.Add(taskCompletionSource);

            var result = NativeMethods.indy_delete_wallet_record_tags(
                commandHandle,
                wallet.Handle,
                type,
                id,
                tagsJson,
                CallbackHelper.TaskCompletingNoValueCallback);

            return(taskCompletionSource.Task);
        }
예제 #25
0
        /// <summary>
        /// Sets user defined metadata for a key-pair in the specified wallet.
        /// </summary>
        /// <remarks>
        /// Any existing metadata stored for the key-pair will be replaced.
        /// </remarks>
        /// <param name="wallet">The wallet containing the key.</param>
        /// <param name="verKey">The verification key of the key pair.</param>
        /// <param name="metadata">The metadata to set.</param>
        /// <returns>An asynchronous <see cref="Task"/> that completes when the operation completes.</returns>
        /// <exception cref="WalletItemNotFoundException">Thrown if the wallet does not contain a key-pair matching the provided <paramref name="verKey"/>.</exception>
        public static Task SetKeyMetadataAsync(IWallet wallet, string verKey, string metadata)
        {
            ParamGuard.NotNull(wallet, "wallet");
            ParamGuard.NotNullOrWhiteSpace(verKey, "verKey");

            var taskCompletionSource = new TaskCompletionSource <bool>();
            var commandHandle        = PendingCommands.Add(taskCompletionSource);

            var commandResult = NativeMethods.indy_set_key_metadata(
                commandHandle,
                (int)wallet.Handle,
                verKey,
                metadata,
                CallbackHelper.TaskCompletingNoValueCallback
                );

            CallbackHelper.CheckResult(commandResult);

            return(taskCompletionSource.Task);
        }
예제 #26
0
        /// <summary>
        /// Creates a new AgentListener that listens for incoming connections on the specified endpoint.
        /// </summary>
        /// <remarks>
        /// The endpoint specified must be in the format <c>address:port</c> where <c>address</c> is
        /// an IP address or host address and <c>port</c> is a numeric port number.
        /// </remarks>
        /// <param name="endpoint">The endpoint on which the incoming connections will listened for.</param>
        /// <returns>An asynchronous <see cref="Task{T}"/> that resolves to an AgentListener instance
        /// once the listener has been created.</returns>
        public static Task <AgentListener> ListenAsync(string endpoint)
        {
            ParamGuard.NotNullOrWhiteSpace(endpoint, "endpoint");

            var listener = new AgentListener();

            var taskCompletionSource = new TaskCompletionSource <AgentListener>(listener);
            var commandHandle        = PendingCommands.Add(taskCompletionSource);

            var result = IndyNativeMethods.indy_agent_listen(
                commandHandle,
                endpoint,
                _listenerCreatedCallback,
                listener.ConnectionEstablishedCallback,
                listener.MessageReceivedCallback);

            CallbackHelper.CheckResult(result);

            return(taskCompletionSource.Task);
        }
예제 #27
0
        /// <summary>
        /// Removes an identity from the listener.
        /// </summary>
        /// <remarks>
        /// <para>Once an identity has been added to an AgentListner using the <see cref="AddIdentityAsync(Pool, Wallet, string)"/>
        /// it can be removed using this method. A <see cref="Wallet"/> lookup will be performed to find
        /// the identity information for the DID so the wallet containing the DID must be provided.
        /// </para>
        /// </remarks>
        /// <param name="wallet">The wallet that contains the identity for the DID.</param>
        /// <param name="did">The DID of the identity to remove. </param>
        /// <returns>An asynchronous <see cref="Task"/> completes once the operation completes.</returns>
        public Task RemoveIdentityAsync(Wallet wallet, string did)
        {
            ParamGuard.NotNull(wallet, "wallet");
            ParamGuard.NotNullOrWhiteSpace(did, "did");

            var taskCompletionSource = new TaskCompletionSource <bool>();
            var commandHandle        = PendingCommands.Add(taskCompletionSource);

            var result = IndyNativeMethods.indy_agent_remove_identity(
                commandHandle,
                Handle,
                wallet.Handle,
                did,
                CallbackHelper.TaskCompletingNoValueCallback
                );

            CallbackHelper.CheckResult(result);

            return(taskCompletionSource.Task);
        }
예제 #28
0
        /// <summary>
        /// Gets the endpoint details for the specified DID.
        /// </summary>
        /// <remarks>
        /// If the <paramref name="did"/> is present in the <paramref name="wallet"/> and is considered "fresh" then
        /// the endpoint will be resolved from the wallet.  If, on the other hand, the DID is not present in the wallet or
        /// is not fresh then the details will be resolved from the <paramref name="pool"/> and will be cached in the wallet.
        /// </remarks>
        /// <param name="wallet">The wallet containing the DID.</param>
        /// <param name="pool">The pool to resolve the endpoint data from if not present in the wallet.</param>
        /// <param name="did">The DID to get the endpoint data for.</param>
        /// <returns>An asynchronous <see cref="Task{T}"/> that resolves to an <see cref="EndpointForDidResult"/> containing the endpoint information
        /// associated with the DID.</returns>
        public static Task <EndpointForDidResult> GetEndpointForDidAsync(Wallet wallet, Pool pool, string did)
        {
            ParamGuard.NotNull(wallet, "wallet");
            ParamGuard.NotNull(pool, "pool");
            ParamGuard.NotNullOrWhiteSpace(did, "did");

            var taskCompletionSource = new TaskCompletionSource <EndpointForDidResult>();
            var commandHandle        = PendingCommands.Add(taskCompletionSource);

            var commandResult = NativeMethods.indy_get_endpoint_for_did(
                commandHandle,
                wallet.Handle,
                pool.Handle,
                did,
                GetEndpointForDidCompletedCallback
                );

            CallbackHelper.CheckResult(commandResult);

            return(taskCompletionSource.Task);
        }
예제 #29
0
        /// <summary>
        /// Creates a new wallet.
        /// </summary>
        /// <remarks>
        /// <para>Each created wallet is given a name which is then subsequently used to open it
        /// with the <see cref="OpenWalletAsync(string, string, string)"/> or delete it using the
        /// <see cref="DeleteWalletAsync(string, string)"/> static methods.
        /// <note type="note">Wallet names must be unique within a pool.</note>
        /// </para>
        /// <para>
        /// When creating a new Wallet the <paramref name="type"/> parameter can be null or "default" to
        /// use the default wallet implementation, or a type name specified in an earlier call to the
        /// <see cref="RegisterWalletTypeAsync(string, WalletType)"/> method to use a custom wallet implementation.
        /// Attempting to use a wallet type that hasn't previously been registered will result in an error.
        /// </para>
        /// <para>The <paramref name="config"/> parameter allows configuration values to be passed to the wallet
        /// when it is created.  When using the default wallet this value can be null to use the default
        /// wallet configuration or a JSON string with the following format can be used:
        /// <code>
        /// {
        ///     "freshness_time": int
        /// }
        /// </code>
        /// The value of the <c>freshness_time</c> key is an integer representing the number of seconds
        /// a value in the wallet will remain valid before expiring.  If not specified the default value
        /// for <c>freshness_time</c> is 24 * 60 seconds.
        /// </para>
        /// <para>If using a custom wallet type the content of the <paramref name="config"/> parameter can
        /// be any string value; it is up to the custom wallet type implementer to interpret the value.
        /// </para>
        /// <para>The <paramref name="credentials"/> parameter is unused in the default wallet at present,
        /// however the value can be used by custom wallet implementations; it is up to the custom wallet
        /// type implementer to interpret the value.</para>
        /// </remarks>
        /// <param name="poolName">The name of the pool the wallet is associated with.</param>
        /// <param name="name">The name of the wallet.</param>
        /// <param name="type">The type of the wallet. </param>
        /// <param name="config">The wallet configuration JSON.</param>
        /// <param name="credentials">The wallet credentials JSON or null to use the default credentials.</param>
        /// <returns>An asynchronous <see cref="Task"/> with no return value the completes when the operation has finished.</returns>
        public static Task CreateWalletAsync(string poolName, string name, string type, string config, string credentials)
        {
            ParamGuard.NotNullOrWhiteSpace(poolName, "poolName");
            ParamGuard.NotNullOrWhiteSpace(name, "name");

            var taskCompletionSource = new TaskCompletionSource <bool>();
            var commandHandle        = PendingCommands.Add(taskCompletionSource);

            var result = IndyNativeMethods.indy_create_wallet(
                commandHandle,
                poolName,
                name,
                type,
                config,
                credentials,
                CallbackHelper.TaskCompletingNoValueCallback);

            CallbackHelper.CheckResult(result);

            return(taskCompletionSource.Task);
        }
예제 #30
0
        /// <summary>
        /// Parses an encrypted message prepared by another party.
        /// </summary>
        /// <param name="wallet">The wallet containing the keys.</param>
        /// <param name="recipientKey">The verification key of the recipient.</param>
        /// <param name="encryptedMsg">The encrypted message to parse.</param>
        /// <returns>An asynchronous <see cref="Task{T}"/> that resolves to a <see cref="ParseMsgResult"/> containing the sender key and the parsed message
        /// content.</returns>
        /// <exception cref="InvalidStructureException">Thrown if the value passed to the <paramref name="recipientKey"/> parameter is malformed or the <paramref name="encryptedMsg"/> is invalid.</exception>
        /// <exception cref="WalletValueNotFoundException">Thrown if the <paramref name="recipientKey"/> does not exist in the <paramref name="wallet"/>.</exception>
        public static Task <ParseMsgResult> ParseMsgAsync(Wallet wallet, string recipientKey, byte[] encryptedMsg)
        {
            ParamGuard.NotNull(wallet, "wallet");
            ParamGuard.NotNullOrWhiteSpace(recipientKey, "recipientKey");
            ParamGuard.NotNull(encryptedMsg, "encryptedMsg");

            var taskCompletionSource = new TaskCompletionSource <ParseMsgResult>();
            var commandHandle        = PendingCommands.Add(taskCompletionSource);

            var result = NativeMethods.indy_parse_msg(
                commandHandle,
                wallet.Handle,
                recipientKey,
                encryptedMsg,
                encryptedMsg.Length,
                _agentMessageParsedCallback);

            CallbackHelper.CheckResult(result);

            return(taskCompletionSource.Task);
        }