diff options
| author | Özgür Kesim <oec-taler@kesim.org> | 2023-07-03 16:18:40 +0200 | 
|---|---|---|
| committer | Özgür Kesim <oec-taler@kesim.org> | 2023-07-03 16:18:40 +0200 | 
| commit | 40629e89920267dadba39f5f7f2ab3d844088a0e (patch) | |
| tree | 0c10bc6e983ed628f7a7ce1c9aa5d166733e0118 /src/include | |
| parent | 9c3ddcbc183a9a96f10cdb14f28258ea61f5f7c5 (diff) | |
[age-withdraw] added library function for age-withdraw
- Added TALER_EXCHANGE_age_withdraw
- Also: Change TALER_EXCHANGE_batch_withdraw and related functions to
  use GNUNET_CURL_ctx, TALER_EXCHANGE_keys and const char *echange_url
Diffstat (limited to 'src/include')
| -rw-r--r-- | src/include/taler_crypto_lib.h | 23 | ||||
| -rw-r--r-- | src/include/taler_exchange_service.h | 154 | ||||
| -rw-r--r-- | src/include/taler_exchangedb_plugin.h | 3 | 
3 files changed, 164 insertions, 16 deletions
| diff --git a/src/include/taler_crypto_lib.h b/src/include/taler_crypto_lib.h index 3af5d326..3ad441cb 100644 --- a/src/include/taler_crypto_lib.h +++ b/src/include/taler_crypto_lib.h @@ -439,7 +439,9 @@ struct TALER_AgeCommitmentPublicKeyP  /* - * @brief Hash to represent the commitment to n*kappa blinded keys during a age-withdrawal. + * @brief Hash to represent the commitment to n*kappa blinded keys during a + * age-withdrawal. It is the running SHA512 hash over the hashes of the blinded + * envelopes of n*kappa coins.   */  struct TALER_AgeWithdrawCommitmentHashP  { @@ -3726,7 +3728,7 @@ TALER_wallet_withdraw_verify (  /**   * Sign age-withdraw request.   * - * @param h_commitment hash all n*kappa blinded coins in the commitment for the age-withdraw + * @param h_commitment hash over all n*kappa blinded coins in the commitment for the age-withdraw   * @param amount_with_fee amount to debit the reserve for   * @param mask the mask that defines the age groups   * @param max_age maximum age from which the age group is derived, that the withdrawn coins must be restricted to. @@ -3762,7 +3764,6 @@ TALER_wallet_age_withdraw_verify (    const struct TALER_ReservePublicKeyP *reserve_pub,    const struct TALER_ReserveSignatureP *reserve_sig); -  /**   * Verify exchange melt confirmation.   * @@ -4871,6 +4872,22 @@ TALER_exchange_online_age_withdraw_confirmation_sign (    struct TALER_ExchangeSignatureP *sig); +/** + * Verfiy an exchange age-withdraw confirmation + * + * @param h_commitment Commitment over all n*kappa coin candidates from the original request to age-withdraw + * @param noreveal_index The index returned by the exchange + * @param exchange_pub The public key used for signing + * @param exchange_sig The signature from the exchange + */ +enum GNUNET_GenericReturnValue +TALER_exchange_online_age_withdraw_confirmation_verify ( +  const struct TALER_AgeWithdrawCommitmentHashP *h_commitment, +  uint32_t noreveal_index, +  const struct TALER_ExchangePublicKeyP *exchange_pub, +  const struct TALER_ExchangeSignatureP *exchange_sig); + +  /* ********************* offline signing ************************** */ diff --git a/src/include/taler_exchange_service.h b/src/include/taler_exchange_service.h index bc6a230b..d4efc15d 100644 --- a/src/include/taler_exchange_service.h +++ b/src/include/taler_exchange_service.h @@ -18,6 +18,7 @@   * @brief C interface of libtalerexchange, a C library to use exchange's HTTP API   * @author Sree Harsha Totakura <sreeharsha@totakura.in>   * @author Christian Grothoff + * @author Özgür Kesim   */  #ifndef _TALER_EXCHANGE_SERVICE_H  #define _TALER_EXCHANGE_SERVICE_H @@ -1618,7 +1619,8 @@ typedef void  /**   * Get a CS R using a /csr-withdraw request.   * - * @param exchange the exchange handle; the exchange must be ready to operate + * @param curl_ctx The curl context to use for the requests + * @param exchange_url Base-URL to the excnange   * @param pk Which denomination key is the /csr request for   * @param nonce client nonce for the request   * @param res_cb the callback to call when the final result for this request is available @@ -1629,7 +1631,8 @@ typedef void   */  struct TALER_EXCHANGE_CsRWithdrawHandle *  TALER_EXCHANGE_csr_withdraw ( -  struct TALER_EXCHANGE_Handle *exchange, +  struct GNUNET_CURL_Context *curl_ctx, +  const char *exchange_url,    const struct TALER_EXCHANGE_DenomPublicKey *pk,    const struct TALER_CsNonce *nonce,    TALER_EXCHANGE_CsRWithdrawCallback res_cb, @@ -2448,7 +2451,9 @@ typedef void   * disk before calling, and be ready to repeat the request with the   * same arguments in case of failures.   * - * @param exchange the exchange handle; the exchange must be ready to operate + * @param curl_ctx The curl context to use + * @param exchange_url The base-URL of the exchange + * @param keys The /keys material from the exchange   * @param reserve_priv private key of the reserve to withdraw from   * @param wci inputs that determine the planchet   * @param res_cb the callback to call when the final result for this request is available @@ -2459,7 +2464,9 @@ typedef void   */  struct TALER_EXCHANGE_WithdrawHandle *  TALER_EXCHANGE_withdraw ( -  struct TALER_EXCHANGE_Handle *exchange, +  struct GNUNET_CURL_Context *curl_ctx, +  const char *exchange_url, +  struct TALER_EXCHANGE_Keys *keys,    const struct TALER_ReservePrivateKeyP *reserve_priv,    const struct TALER_EXCHANGE_WithdrawCoinInput *wci,    TALER_EXCHANGE_WithdrawCallback res_cb, @@ -2575,7 +2582,9 @@ typedef void   * disk before calling, and be ready to repeat the request with the   * same arguments in case of failures.   * - * @param exchange the exchange handle; the exchange must be ready to operate + * @param curl_ctx The curl context to use + * @param exchange_url The base-URL of the exchange + * @param keys The /keys material from the exchange   * @param reserve_priv private key of the reserve to withdraw from   * @param wcis inputs that determine the planchets   * @param wci_length number of entries in @a wcis @@ -2587,7 +2596,9 @@ typedef void   */  struct TALER_EXCHANGE_BatchWithdrawHandle *  TALER_EXCHANGE_batch_withdraw ( -  struct TALER_EXCHANGE_Handle *exchange, +  struct GNUNET_CURL_Context *curl_ctx, +  const char *exchange_url, +  const struct TALER_EXCHANGE_Keys *keys,    const struct TALER_ReservePrivateKeyP *reserve_priv,    const struct TALER_EXCHANGE_WithdrawCoinInput *wcis,    unsigned int wci_length, @@ -2668,7 +2679,9 @@ struct TALER_EXCHANGE_Withdraw2Handle;   * disk before calling, and be ready to repeat the request with the   * same arguments in case of failures.   * - * @param exchange the exchange handle; the exchange must be ready to operate + * @param curl_ctx The curl-context to use + * @param exchange_url The base-URL of the exchange + * @param keys The /keys material from the exchange   * @param pd planchet details of the planchet to withdraw   * @param reserve_priv private key of the reserve to withdraw from   * @param res_cb the callback to call when the final result for this request is available @@ -2679,7 +2692,9 @@ struct TALER_EXCHANGE_Withdraw2Handle;   */  struct TALER_EXCHANGE_Withdraw2Handle *  TALER_EXCHANGE_withdraw2 ( -  struct TALER_EXCHANGE_Handle *exchange, +  struct GNUNET_CURL_Context *curl_ctx, +  const char *exchange_url, +  struct TALER_EXCHANGE_Keys *keys,    const struct TALER_PlanchetDetail *pd,    const struct TALER_ReservePrivateKeyP *reserve_priv,    TALER_EXCHANGE_Withdraw2Callback res_cb, @@ -2765,7 +2780,9 @@ struct TALER_EXCHANGE_BatchWithdraw2Handle;   * disk before calling, and be ready to repeat the request with the   * same arguments in case of failures.   * - * @param exchange the exchange handle; the exchange must be ready to operate + * @param curl_ctx The curl context to use + * @param exchange_url The base-URL of the exchange + * @param keys The /keys material from the exchange   * @param pds array of planchet details of the planchet to withdraw   * @param pds_length number of entries in the @a pds array   * @param reserve_priv private key of the reserve to withdraw from @@ -2777,7 +2794,9 @@ struct TALER_EXCHANGE_BatchWithdraw2Handle;   */  struct TALER_EXCHANGE_BatchWithdraw2Handle *  TALER_EXCHANGE_batch_withdraw2 ( -  struct TALER_EXCHANGE_Handle *exchange, +  struct GNUNET_CURL_Context *curl_ctx, +  const char *exchange_url, +  const struct TALER_EXCHANGE_Keys *keys,    const struct TALER_ReservePrivateKeyP *reserve_priv,    const struct TALER_PlanchetDetail *pds,    unsigned int pds_length, @@ -2796,6 +2815,119 @@ TALER_EXCHANGE_batch_withdraw2_cancel (    struct TALER_EXCHANGE_BatchWithdraw2Handle *wh); +/* ********************* /reserve/$RESERVE_PUB/age-withdraw *************** */ + +/** + * @brief Information needed to withdraw age restricted coins. + */ +struct TALER_EXCHANGE_AgeWithdrawCoinInput +{ +  /* The master secret from which we derive all other relevant values for +   * the coin: private key, nonces (if applicable) and age restriction +   */ +  const struct TALER_PlanchetMasterSecretP secret[TALER_CNC_KAPPA]; + +  /* The denomination of the coin.  Must support age restriction, i.e +   * its .keys.age_mask MUST not be 0 */ +  const struct TALER_EXCHANGE_DenomPublicKey *denom_pub; +}; + +/** + * @brief A handle to a /reserves/$RESERVE_PUB/age-withdraw request + */ +struct TALER_EXCHANGE_AgeWithdrawHandle; + +/** + * @brief Details about the response for a age withdraw request. + */ +struct TALER_EXCHANGE_AgeWithdrawResponse +{ +  /** +   * HTTP response data. +   */ +  struct TALER_EXCHANGE_HttpResponse hr; + +  /** +   * Details about the response +   */ +  union +  { +    /** +     * Details if the status is #MHD_HTTP_OK. +     */ +    struct +    { +      /** +       * Index that should not be revealed during the age-withdraw reveal phase. +       * The struct TALER_PlanchetMasterSecretP * from the request +       * with this index are the ones to keep. +       */ +      uint8_t noreveal_index; + +      /** +       * Signature of the exchange over the origina TALER_AgeWithdrawRequestPS +       */ +      struct TALER_ExchangeSignatureP exchange_sig; + +      /** +       * Key used by the exchange for @e exchange_sig +       */ +      struct TALER_ExchangePublicKeyP exchange_pub; + +    } ok; +    /* FIXME[oec]: error cases */ +  } details; +}; + +typedef void +(*TALER_EXCHANGE_AgeWithdrawCallback)( +  void *cls, +  const struct TALER_EXCHANGE_AgeWithdrawResponse *awr); + +/** + * Submit an age-withdraw request to the exchange and get the exchange's + * response. + * + * This API is typically used by a wallet.  Note that to ensure that + * no money is lost in case of hardware failures, the provided + * argument @a rd should be committed to persistent storage + * prior to calling this function. + * + * @param curl_ctx The curl context + * @param exchange_url The base url of the exchange + * @parm keys The denomination keys from the exchange + * @param reserve_priv The pivate key to the reserve + * @param coin_inputs The input for the coins to withdraw + * @param num_coins The number of elements in @e coin_inputs + * @param max_age The maximum age we commit to. + * @param res_cb A callback for the result, maybe NULL + * @param res_cb_cls A closure for @e res_cb, maybe NULL + * @return a handle for this request; NULL if the argument was invalid. + *         In this case, the callback will not be called. + */ +struct TALER_EXCHANGE_AgeWithdrawHandle * +TALER_EXCHANGE_age_withdraw ( +  struct GNUNET_CURL_Context *curl_ctx, +  const char *exchange_url, +  struct TALER_EXCHANGE_Keys *keys, +  const struct TALER_ReservePrivateKeyP *reserve_priv, +  const struct TALER_EXCHANGE_AgeWithdrawCoinInput *coin_inputs, +  size_t num_coins, +  uint8_t max_age, +  TALER_EXCHANGE_AgeWithdrawCallback res_cb, +  void *res_cb_cls); + +/** + * Cancel a age-withdraw request.  This function cannot be used + * on a request handle if a response is already served for it. + * + * @param awh the age-withdraw handle + */ +void +TALER_EXCHANGE_age_withdraw_cancel ( +  struct TALER_EXCHANGE_AgeWithdrawHandle *awh); + +  /* ********************* /refresh/melt+reveal ***************************** */ @@ -3565,7 +3697,7 @@ TALER_EXCHANGE_verify_coin_history (   */  enum GNUNET_GenericReturnValue  TALER_EXCHANGE_parse_reserve_history ( -  struct TALER_EXCHANGE_Keys *keys, +  const struct TALER_EXCHANGE_Keys *keys,    const json_t *history,    const struct TALER_ReservePublicKeyP *reserve_pub,    const char *currency, diff --git a/src/include/taler_exchangedb_plugin.h b/src/include/taler_exchangedb_plugin.h index c4fcad56..1b1a657c 100644 --- a/src/include/taler_exchangedb_plugin.h +++ b/src/include/taler_exchangedb_plugin.h @@ -1215,8 +1215,7 @@ struct TALER_EXCHANGEDB_AgeWithdraw    /**     * Signature confirming the age withdrawal commitment, matching @e -   * reserve_pub, @e maximum_age_group and @e h_commitment and @e -   * total_amount_with_fee. +   * reserve_pub, @e max_age and @e h_commitment and @e amount_with_fee.     */    struct TALER_ReserveSignatureP reserve_sig; | 
