Exemplo n.º 1
0
        /// <summary>
        /// Builds Indy request for doing tokens payment
        /// according to this payment method.
        ///
        /// This method consumes set of UTXO inputs and outputs.
        ///
        /// Format of inputs is specific for payment method. Usually it should reference payment transaction
        /// with at least one output that corresponds to payment address that user owns.
        ///
        /// Note this endpoint is EXPERIMENTAL. Function signature and behaviour may change
        /// in the future releases.
        /// </summary>
        /// <returns>Indy request for doing tokens payment</returns>
        /// <param name="wallet">Wallet.</param>
        /// <param name="submitterDid">Submitter did.</param>
        /// <param name="inputsJson">The list of UTXO inputs as json array:
        ///   ["input1", ...]
        ///   Note that each input should reference paymentAddress</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> BuildPaymentRequestAsync(Wallet wallet, string submitterDid, string inputsJson, string outputsJson, string extra)
        {
            ParamGuard.NotNull(wallet, "wallet");
            ParamGuard.NotNullOrWhiteSpace(inputsJson, "inputsJson");
            ParamGuard.NotNullOrWhiteSpace(outputsJson, "outputsJson");

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

            var result = NativeMethods.indy_build_payment_req(
                commandHandle,
                wallet.Handle,
                submitterDid,
                inputsJson,
                outputsJson,
                extra,
                BuildPaymentRequestCallback);

            CallbackHelper.CheckResult(result);

            return(taskCompletionSource.Task);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Signs the provided claim for using the key provided in the specified claim request.
        /// </summary>
        /// <remarks>
        /// <para>
        /// The <paramref name="claimReqJson"/> parameter must be passed a claim request that was previously
        /// created using the <see cref="ProverCreateAndStoreClaimReqAsync(Wallet, string, string, string, string)"/>
        /// method.  Usually the claim request will be received from another party that has performed this
        /// action.
        /// </para>
        /// <para>
        /// The claim to be signed is provided in the <paramref name="claimJson"/> parameter
        /// and the structure of the claim must conform to the schema from claim request provided in
        /// the <paramref name="claimReqJson"/> parameter.  Claims must be structured as a series of
        /// attributes, each of which has two values; a human readable value and a hex encoded value.
        /// <code>
        /// {
        ///      "attr1" : ["value1", "value1_as_int"],
        ///      "attr2" : ["value2", "value2_as_int"]
        /// }
        /// </code>
        /// For example:
        /// <code>
        /// {
        ///     'name': ['Alex', '1139481716457488690172217916278103335'],
        ///     'height': ['175', '175']
        /// }
        /// </code>
        /// </para>
        /// <para>
        /// This method results a revocation registry update JSON and a newly issued claim JSON.  The
        /// claim JSON contains the issued claim, the DID of the issuer (<c>issuer_did</c>),
        /// schema sequence number (<c>schema_seq_no</c>) and revocation registry sequence number (<c>
        /// revoc_reg_seq_no</c>) used for issuance:
        /// <code>
        /// {
        ///     "claim": &lt;see claim_json above&gt;,
        ///     "signature": &lt;signature&gt;,
        ///     "revoc_reg_seq_no", string,
        ///     "issuer_did", string,
        ///     "schema_seq_no", string,
        /// }
        /// </code>
        /// </para>
        /// </remarks>
        /// <param name="wallet">The wallet containing the keys to use for signing the claim.</param>
        /// <param name="claimReqJson">A claim request with a blinded secret.</param>
        /// <param name="claimJson">A claim containing attribute values for each of requested attribute names.</param>
        /// <param name="userRevocIndex">The index of a new user in the revocation registry or -1 if absentee.</param>
        /// <returns>An asynchronous <see cref="Task{T}"/> that, when the operation completes, resolves to
        /// an <see cref="IssuerCreateClaimResult"/>.</returns>
        public static Task <IssuerCreateClaimResult> IssuerCreateClaimAsync(Wallet wallet, string claimReqJson, string claimJson, int userRevocIndex)
        {
            ParamGuard.NotNull(wallet, "wallet");
            ParamGuard.NotNullOrWhiteSpace(claimReqJson, "claimReqJson");
            ParamGuard.NotNullOrWhiteSpace(claimJson, "claimJson");

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

            var commandResult = NativeMethods.indy_issuer_create_claim(
                commandHandle,
                wallet.Handle,
                claimReqJson,
                claimJson,
                userRevocIndex,
                _issuerCreateClaimCallback
                );

            CallbackHelper.CheckResult(commandResult);

            return(taskCompletionSource.Task);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Builds Indy request for setting 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 setting fees for transactions in the ledger</returns>
        /// <param name="wallet">Wallet.</param>
        /// <param name="submitterDid">Submitter did.</param>
        /// <param name="paymentMethod">Payment method.</param>
        /// <param name="feesJson">Fees json.
        /// {
        ///   txnType1: amount1,
        ///   txnType2: amount2,
        ///   .................
        ///   txnTypeN: amountN,
        /// }</param>
        public static Task <string> BuildSetTxnFeesRequestAsync(Wallet wallet, string submitterDid, string paymentMethod, string feesJson)
        {
            ParamGuard.NotNull(wallet, "wallet");
            ParamGuard.NotNullOrWhiteSpace(submitterDid, "submitterDid");
            ParamGuard.NotNullOrWhiteSpace(paymentMethod, "paymentMethod");
            ParamGuard.NotNullOrWhiteSpace(feesJson, "feesJson");

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

            var result = NativeMethods.indy_build_set_txn_fees_req(
                commandHandle,
                wallet.Handle,
                submitterDid,
                paymentMethod,
                feesJson,
                _buildSetTxnFeesReqCallback);

            CallbackHelper.CheckResult(result);

            return(taskCompletionSource.Task);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Decrypts a message encrypted using an anonymous-encryption scheme
        /// </summary>
        /// <remarks>
        /// <para>
        /// Sealed boxes are designed to a <c>sender</c> to anonymously send messages to a <c>recipient</c> using the
        /// recipient's public key.
        /// Only the recipient can decrypt these messages, using their private key.
        /// While the recipient can verify the integrity of the message, they cannot verify the identity of the sender.
        /// </para>
        /// <note type="note">
        /// To use DID keys with this method call the <see cref="Did.KeyForDidAsync(PoolApi.Pool, Wallet, string)"/> with the desired DID to get
        /// its verification key which can be used as the <paramref name="myVk"/> parameter when calling this method.
        /// </note>
        /// </remarks>
        /// <param name="wallet">The wallet containing the key-pair associated with the verification key specified in the <paramref name="myVk"/> parameter.</param>
        /// <param name="myVk">The verification key of the intended recipient of the encrypted message.</param>
        /// <param name="encryptedMessage">The encrypted message to decrypt.</param>
        /// <returns>An asynchronous <see cref="Task{T}"/> that resolves to a byte array containing the decrypted message.</returns>
        /// <exception cref="WalletValueNotFoundException">Thrown if <paramref name="myVk"/> is not present in the <paramref name="wallet"/>.</exception>
        /// <exception cref="InvalidStructureException">Thrown if <paramref name="myVk"/> was not used to encrypt <paramref name="encryptedMessage"/>.</exception>
        public static Task <byte[]> AnonDecryptAsync(Wallet wallet, string myVk, byte[] encryptedMessage)
        {
            ParamGuard.NotNull(wallet, "wallet");
            ParamGuard.NotNullOrWhiteSpace(myVk, "myVk");
            ParamGuard.NotNull(encryptedMessage, "encryptedMessage");

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

            var commandResult = NativeMethods.indy_crypto_anon_decrypt(
                commandHandle,
                wallet.Handle,
                myVk,
                encryptedMessage,
                encryptedMessage.Length,
                CryptoAnonDecryptCompletedCallback
                );

            CallbackHelper.CheckResult(commandResult);

            return(taskCompletionSource.Task);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Builds a GET_ATTRIB ledger request.
        /// </summary>
        /// <remarks>
        /// <para>
        /// Builds a request message that is suitable for requesting an attribute from the
        /// ledger.
        /// </para>
        /// </remarks>
        /// <param name="submitterDid">The DID of the submitter.</param>
        /// <param name="targetDid">The target DID.</param>
        /// <param name="raw">The name of the attribute to get.</param>
        /// <param name="hash"></param>
        /// <param name="enc"></param>
        /// <returns>An asynchronous <see cref="Task{T}"/> that resolves to a <see cref="string"/>
        /// containing the request JSON. </returns>
        public static Task <string> BuildGetAttribRequestAsync(string submitterDid, string targetDid, string raw, string hash, string enc)
        {
            ParamGuard.NotNullOrWhiteSpace(submitterDid, "submitterDid");
            ParamGuard.NotNullOrWhiteSpace(targetDid, "targetDid");

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

            var result = NativeMethods.indy_build_get_attrib_request(
                commandHandle,
                submitterDid,
                targetDid,
                raw,
                hash,
                enc,
                BuildRequestCallback
                );

            CallbackHelper.CheckResult(result);

            return(taskCompletionSource.Task);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Builds a GET_CLAIM_DEF ledger request.
        /// </summary>
        /// <remarks>
        /// Builds a request message that is suitable for getting a claim definition from a ledger.
        /// </remarks>
        /// <note type="note">The <paramref name="signatureType"/> parameter only accepts the value
        /// 'CL' at present.</note>
        /// <param name="submitterDid">The DID of the party that will submit the request.</param>
        /// <param name="xref">The sequence number of the schema the claim definition targets.</param>
        /// <param name="signatureType">The type of signature used in the claim definition.</param>
        /// <param name="origin">The DID of the issuer of the claim definition.</param>
        /// <returns>An asynchronous <see cref="Task{T}"/> that resolves to a <see cref="string"/>
        /// containing the request JSON. </returns>
        public static Task <string> BuildGetClaimDefTxnAsync(string submitterDid, int xref, string signatureType, string origin)
        {
            ParamGuard.NotNullOrWhiteSpace(submitterDid, "submitterDid");
            ParamGuard.NotNullOrWhiteSpace(signatureType, "signatureType");
            ParamGuard.NotNullOrWhiteSpace(origin, "origin");

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

            var result = NativeMethods.indy_build_get_claim_def_txn(
                commandHandle,
                submitterDid,
                xref,
                signatureType,
                origin,
                _buildRequestCallback
                );

            CallbackHelper.CheckResult(result);

            return(taskCompletionSource.Task);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Builds a ledger request to store a NYM.
        /// </summary>
        /// <remarks>
        /// <para>
        /// Builds a request message that is suitable for storing a NYM for the <paramref name="targetDid"/>
        /// on the ledger.
        /// </para>
        /// <para>
        /// Only the <paramref name="submitterDid"/> and <paramref name="targetDid"/> parameters
        /// are required, however the other parameters provide greater control over the process.  Normally
        /// the <paramref name="targetDid"/> and <paramref name="verKey"/> parameters would be from values
        /// generated by a prior call to <see cref="Did.CreateAndStoreMyDidAsync(Wallet, string)"/>.
        /// </para>
        /// <para>
        /// The <paramref name="role"/> parameter dictates what permissions the NYM will have - valid values
        /// are 'STEWARD' and 'TRUSTEE' and 'TRUST_ANCHOR'.
        /// </para>
        /// </remarks>
        /// <param name="submitterDid">The DID of the party who will submit the request to the ledger.</param>
        /// <param name="targetDid">The DID the NYM belongs to.</param>
        /// <param name="verKey">The verification key for the NYM.</param>
        /// <param name="alias">The alias for the NYM.</param>
        /// <param name="role">The role of the NYM.</param>
        /// <returns>An asynchronous <see cref="Task{T}"/> that resolves to a <see cref="string"/>
        /// containing the request JSON. </returns>
        public static Task <string> BuildNymRequestAsync(string submitterDid, string targetDid, string verKey, string alias, string role)
        {
            ParamGuard.NotNullOrWhiteSpace(submitterDid, "submitterDid");
            ParamGuard.NotNullOrWhiteSpace(targetDid, "targetDid");

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

            var result = NativeMethods.indy_build_nym_request(
                commandHandle,
                submitterDid,
                targetDid,
                verKey,
                alias,
                role,
                BuildRequestCallback
                );

            CallbackHelper.CheckResult(result);

            return(taskCompletionSource.Task);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Modifies Indy request by adding information how to pay fees for this transaction
        /// according to selected payment method.
        ///
        /// Payment selection is performed by looking to o
        ///
        /// This method consumes set of UTXO inputs and outputs. The difference between inputs balance
        /// and outputs balance is the fee for this transaction.
        ///
        /// Not that this method also produces correct fee signatures.
        ///
        /// Format of inputs is specific for payment method. Usually it should reference payment transaction
        /// with at least one output that corresponds to payment address that user owns.
        ///
        /// Note this endpoint is EXPERIMENTAL. Function signature and behaviour may change
        /// in the future releases.
        /// </summary>
        /// <returns>The request fees async.</returns>
        /// <param name="wallet">Wallet.</param>
        /// <param name="submitterDid">DID of request sender</param>
        /// <param name="reqJson">Initial transaction request as json</param>
        /// <param name="inputsJson">The list of UTXO inputs as json array:
        ///   ["input1", ...]
        ///   Notes:
        ///     - each input should reference paymentAddress
        ///     - this param will be used to determine payment_method
        /// </param>
        /// <param name="outputsJson">outputs_json: 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> AddRequestFeesAsync(Wallet wallet, string submitterDid, string reqJson, string inputsJson, string outputsJson, string extra)
        {
            ParamGuard.NotNull(wallet, "wallet");
            ParamGuard.NotNullOrWhiteSpace(submitterDid, "submitterDid");

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

            var result = NativeMethods.indy_add_request_fees(
                commandHandle,
                wallet.Handle,
                submitterDid,
                reqJson,
                inputsJson,
                outputsJson,
                extra,
                AddRequestFeesCallback);

            CallbackHelper.CheckResult(result);

            return(taskCompletionSource.Task);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Sets the endpoint details for the specified DID.
        /// </summary>
        /// <param name="wallet">The wallet containing the DID.</param>
        /// <param name="did">The DID to set the endpoint details on.</param>
        /// <param name="address">The address of the endpoint.</param>
        /// <param name="transportKey">The transport key.</param>
        /// <returns>An asynchronous <see cref="Task"/> that completes when the operation completes.</returns>
        /// <exception cref="InvalidStructureException">Thrown if the <paramref name="did"/> or <paramref name="transportKey"/> values are malformed.</exception>
        public static Task SetEndpointForDidAsync(Wallet wallet, string did, string address, string transportKey)
        {
            ParamGuard.NotNull(wallet, "wallet");
            ParamGuard.NotNullOrWhiteSpace(did, "did");
            ParamGuard.NotNullOrWhiteSpace(address, "address");
            ParamGuard.NotNullOrWhiteSpace(transportKey, "transportKey");

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

            var commandResult = NativeMethods.indy_set_endpoint_for_did(
                commandHandle,
                wallet.Handle,
                did,
                address,
                transportKey,
                CallbackHelper.TaskCompletingNoValueCallback
                );

            CallbackHelper.CheckResult(commandResult);

            return(taskCompletionSource.Task);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Verifies a message signature with a verification key.
        /// </summary>
        /// <note type="note">
        /// To use DID keys with this method call the <see cref="Did.KeyForDidAsync(PoolApi.Pool, Wallet, string)"/> with the desired DID to get
        /// its verification key which can be used as the <paramref name="theirVk"/> parameter when calling this method.
        /// </note>
        /// <param name="theirVk">The verification key belonging to the party that signed the message.</param>
        /// <param name="message">The message that was signed.</param>
        /// <param name="signature">The signature for the message.</param>
        /// <returns>An asynchronous <see cref="Task{T}"/> that, when the operation completes, resolves to true if the signature was valid, otherwise false.</returns>
        public static Task <bool> VerifyAsync(string theirVk, byte[] message, byte[] signature)
        {
            ParamGuard.NotNullOrWhiteSpace(theirVk, "theirVk");
            ParamGuard.NotNull(message, "message");
            ParamGuard.NotNull(signature, "signature");

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

            var commandResult = NativeMethods.indy_crypto_verify(
                commandHandle,
                theirVk,
                message,
                message.Length,
                signature,
                signature.Length,
                _cryptoVerifyCompletedCallback
                );

            CallbackHelper.CheckResult(commandResult);

            return(taskCompletionSource.Task);
        }
Exemplo n.º 11
0
        /// <summary>
        /// TODO: Issuers the create claim offer async.
        /// </summary>
        /// <returns>The create claim offer async.</returns>
        /// <param name="wallet">Wallet.</param>
        /// <param name="schemaJson">Schema json.</param>
        /// <param name="issuerDid">Issuer did.</param>
        /// <param name="proverDid">Prover did.</param>
        public static Task <string> IssuerCreateClaimOfferAsync(Wallet wallet, string schemaJson, string issuerDid, string proverDid)
        {
            ParamGuard.NotNull(wallet, "wallet");
            ParamGuard.NotNullOrWhiteSpace(schemaJson, "schemaJson");
            ParamGuard.NotNullOrWhiteSpace(issuerDid, "issuerDid");
            ParamGuard.NotNullOrWhiteSpace(proverDid, "proverDid");

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

            var commandResult = NativeMethods.indy_issuer_create_claim_offer(
                commandHandle,
                wallet.Handle,
                schemaJson,
                issuerDid,
                proverDid,
                _issuerCreateClaimOfferCallback
                );

            CallbackHelper.CheckResult(commandResult);

            return(taskCompletionSource.Task);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Prepares a message so that it can be securely sent to a recipient.
        /// </summary>
        /// <param name="wallet">The wallet containing the keys of the sender and the recipient.</param>
        /// <param name="senderKey">The public key of the sender.</param>
        /// <param name="recipientKey">The verification key of the intended recipient of the message.</param>
        /// <param name="message">The message content to prepare.</param>
        /// <returns>An asynchronous <see cref="Task{T}"/> that resolves to an array of bytes containing the prepared message.</returns>
        /// <exception cref="WalletValueNotFoundException">Thrown if the sender key does not exist in the <paramref name="wallet"/>.</exception>
        /// <exception cref="InvalidStructureException">Thrown if the <paramref name="recipientKey"/> is invalid.</exception>
        public static Task <byte[]> PrepMsgAsync(Wallet wallet, string senderKey, string recipientKey, byte[] message)
        {
            ParamGuard.NotNull(wallet, "wallet");
            ParamGuard.NotNullOrWhiteSpace(senderKey, "senderKey");
            ParamGuard.NotNullOrWhiteSpace(recipientKey, "recipientKey");
            ParamGuard.NotNull(message, "message");

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

            var result = NativeMethods.indy_prep_msg(
                commandHandle,
                wallet.Handle,
                senderKey,
                recipientKey,
                message,
                message.Length,
                _agentMessagePreparedCallback);

            CallbackHelper.CheckResult(result);

            return(taskCompletionSource.Task);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Signs and submits a request to the validator pool.
        /// </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 <paramref name="wallet"/> and sends the signed
        /// request message to the specified validator <paramref name="pool"/>.
        /// </remarks>
        /// <param name="pool">The validator pool to submit the request to.</param>
        /// <param name="wallet">The wallet containing the submitter keys to sign the request with.</param>
        /// <param name="submitterDid">The DID of the submitter identity.</param>
        /// <param name="requestJson">The request JSON to sign and submit.</param>
        /// <returns>An asynchronous <see cref="Task{T}"/> that resolves to a JSON <see cref="string"/>
        /// containing the result of submission when the operation completes.</returns>
        public static Task <string> SignAndSubmitRequestAsync(Pool pool, Wallet wallet, string submitterDid, string requestJson)
        {
            ParamGuard.NotNull(pool, "pool");
            ParamGuard.NotNull(wallet, "wallet");
            ParamGuard.NotNullOrWhiteSpace(submitterDid, "submitterDid");
            ParamGuard.NotNullOrWhiteSpace(requestJson, "requestJson");

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

            var result = NativeMethods.indy_sign_and_submit_request(
                commandHandle,
                pool.Handle,
                wallet.Handle,
                submitterDid,
                requestJson,
                SubmitRequestCallback
                );

            CallbackHelper.CheckResult(result);

            return(taskCompletionSource.Task);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Encrypts the provided message with the public key of the specified DID using the anonymous-encryption scheme.
        /// </summary>
        /// <remarks>
        /// <para>If the wallet specified in the <paramref name="wallet"/> parameter contains the public key
        /// associated with the DID specified in the <paramref name="did"/> parameter and the value has
        /// not expired then this key will be used for encryption.
        /// </para>
        /// <para>On the other hand, if the public key is not present in the wallet or has expired the public
        /// key will be read from the ledger in the node pool specified in the <paramref name="pool"/>
        /// parameter and the wallet will be updated with the new public key if required.
        /// </para>
        /// <para>For further information on registering a public key for a DID see the
        /// <see cref="StoreTheirDidAsync(Wallet, string)"/>method and for information on the expiry of
        /// values in a wallet see the <see cref="Wallet.CreateWalletAsync(string, string, string, string, string)"/>
        /// and <see cref="Wallet.OpenWalletAsync(string, string, string)"/> methods.
        /// </para>
        /// </remarks>
        /// <param name="wallet">The wallet containing the DID to use for encryption.</param>
        /// <param name="pool">The node pool to read the public key from if required.</param>
        /// <param name="did">The DID the message is to be encrypted for.</param>
        /// <param name="msg">The message to encrypt.</param>
        /// <returns>An asynchronous <see cref="Task{T}"/> that resolves to a byte array containing the encrypted message once encryption is complete.</returns>
        public static Task <byte[]> EncryptSealedAsync(Wallet wallet, Pool pool, string did, byte[] msg)
        {
            ParamGuard.NotNull(wallet, "wallet");
            ParamGuard.NotNull(pool, "pool");
            ParamGuard.NotNullOrWhiteSpace(did, "did");
            ParamGuard.NotNull(msg, "msg");

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

            var commandResult = NativeMethods.indy_encrypt_sealed(
                commandHandle,
                wallet.Handle,
                pool.Handle,
                did,
                msg,
                msg.Length,
                _encryptSealedCallback);

            CallbackHelper.CheckResult(commandResult);

            return(taskCompletionSource.Task);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Creates keys for the given schema and signature type.
        /// </summary>
        /// <remarks>
        /// <para>This method creates both primary and revocation keys for the given
        /// signature type and schema and stores them in the provided <paramref name="wallet"/>.
        /// The generated claim definition is returned as a JSON string containing information about the
        /// signature type, schema, the issuer's public key and the unique identifier of the public key
        /// in the wallet.
        /// </para>
        /// <note type="note">Currently the only signature type that is supported is 'CL'.</note>
        /// </remarks>
        /// <param name="wallet">The wallet into which the claim definition will be stored.</param>
        /// <param name="issuerDid">The DID of the issuer of the claim definition.</param>
        /// <param name="schemaJson">The JSON schema of the claim definition.</param>
        /// <param name="signatureType">The type of signature to use.</param>
        /// <param name="createNonRevoc">Whether to request non-revocation claim.</param>
        /// <returns>
        /// An asynchronous <see cref="Task{T}"/> that, when the operation completes, resolves to a
        /// JSON string containing the claim definition.</returns>
        public static Task <string> IssuerCreateAndStoreClaimDefAsync(Wallet wallet, string issuerDid, string schemaJson, string signatureType, bool createNonRevoc)
        {
            ParamGuard.NotNull(wallet, "wallet");
            ParamGuard.NotNullOrWhiteSpace(issuerDid, "issuerDid");
            ParamGuard.NotNullOrWhiteSpace(schemaJson, "schemaJson");

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

            var commandResult = NativeMethods.indy_issuer_create_and_store_claim_def(
                commandHandle,
                wallet.Handle,
                issuerDid,
                schemaJson,
                signatureType,
                createNonRevoc,
                _issuerCreateAndStoreClaimDefCallback
                );

            CallbackHelper.CheckResult(commandResult);

            return(taskCompletionSource.Task);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Encrypt a message by authenticated-encryption scheme.
        ///
        /// Sender can encrypt a confidential message specifically for Recipient, using Sender's public key.
        /// Using Recipient's public key, Sender can compute a shared secret key.
        /// Using Sender's public key and his secret key, Recipient can compute the exact same shared secret key.
        /// That shared secret key can be used to verify that the encrypted message was not tampered with,
        /// before eventually decrypting it.
        /// </summary>
        /// <remarks>Note to use DID keys with this function you can call indy_key_for_did to get key id (verkey)
        /// for specific DID.
        /// </remarks>
        /// <returns>The crypt async.</returns>
        /// <param name="wallet">The wallet containing the key-pair to sign with.</param>
        /// <param name="myVk"> id (verkey) of my key. The key must be created by calling indy_create_key or indy_create_and_store_my_did</param>
        /// <param name="theirVk">id (verkey) of their key</param>
        /// <param name="message">message data to be encrypted</param>
        public static Task <byte[]> AuthCryptAsync(IWallet wallet, string myVk, string theirVk, byte[] message)
        {
            ParamGuard.NotNull(wallet, "wallet");
            ParamGuard.NotNullOrWhiteSpace(theirVk, "myVk");
            ParamGuard.NotNullOrWhiteSpace(theirVk, "theirVk");
            ParamGuard.NotNull(message, "message");

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

            var commandResult = NativeMethods.indy_crypto_auth_crypt(
                commandHandle,
                (int)wallet.Handle,
                myVk,
                theirVk,
                message,
                message.Length,
                CryptoEncryptCompletedCallback
                );

            CallbackHelper.CheckResult(commandResult);

            return(taskCompletionSource.Task);
        }
Exemplo n.º 17
0
        public RCommand(IRobot robot)
        {
            ParamGuard.NotNull(robot, nameof(robot));

            this.robot = robot;
        }
Exemplo n.º 18
0
        public SimpleCommandParser(IRobot robot)
        {
            ParamGuard.NotNull(robot, nameof(robot));

            this.robot = robot;
        }