donau

Donation authority for GNU Taler (experimental)
Log | Files | Refs | Submodules | README | LICENSE

donau_service.h (36852B)


      1 /*
      2    This file is part of TALER
      3    Copyright (C) 2023 Taler Systems SA
      4 
      5    TALER is free software; you can redistribute it and/or modify it under the
      6    terms of the GNU Affero General Public License as published by the Free Software
      7    Foundation; either version 3, or (at your option) any later version.
      8 
      9    TALER is distributed in the hope that it will be useful, but WITHOUT ANY
     10    WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     11    A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more details.
     12 
     13    You should have received a copy of the GNU Affero General Public License along with
     14    TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
     15  */
     16 /**
     17  * @file include/donau_service.h
     18  * @brief C interface of libdonau, a C library to use donau's HTTP API
     19  * @author Sree Harsha Totakura <sreeharsha@totakura.in>
     20  * @author Christian Grothoff
     21  * @author Özgür Kesim
     22  * @author Lukas Matyja
     23  */
     24 #ifndef _DONAU_SERVICE_H
     25 #define _DONAU_SERVICE_H
     26 
     27 #include <jansson.h>
     28 #include <taler/taler_util.h>
     29 #include "donau_util.h"
     30 #include <taler/taler_error_codes.h>
     31 #include <gnunet/gnunet_curl_lib.h>
     32 
     33 
     34 /* *********************  /keys *********************** */
     35 
     36 
     37 /**
     38  * @brief Donau's statement signing public key
     39  */
     40 struct DONAU_SigningPublicKeyAndValidity
     41 {
     42   /**
     43    * The signing public key
     44    */
     45   struct DONAU_DonauPublicKeyP key;
     46 
     47   /**
     48    * Start time of the validity period for this key.
     49    */
     50   struct GNUNET_TIME_Timestamp valid_from;
     51 
     52   /**
     53    * The donau will sign messages with this key between @e start and this time.
     54    */
     55   struct GNUNET_TIME_Timestamp expire_sign;
     56 
     57 };
     58 
     59 /**
     60  * @brief Public information about a donau's donation unit signing key
     61  */
     62 struct DONAU_DonationUnitInformation
     63 {
     64   /**
     65    * The public key
     66    */
     67   struct DONAU_DonationUnitPublicKey key;
     68 
     69   /**
     70    * amount of the donation
     71    */
     72   struct TALER_Amount value;
     73 
     74   /**
     75    * Year of validity
     76    */
     77   uint64_t year;
     78 
     79   /**
     80    * Set to true if the private donation unit key has been
     81    * lost by the donau and thus the key cannot be
     82    * used for issuing receipts at this time.
     83    */
     84   bool lost;
     85 };
     86 
     87 
     88 /**
     89  * @brief Information about keys from the donau.
     90  */
     91 struct DONAU_Keys
     92 {
     93 
     94   /**
     95    * Array of the donau's online signing keys.
     96    */
     97   struct DONAU_SigningPublicKeyAndValidity *sign_keys;
     98 
     99   /**
    100    * Array of the donau's donation unit keys.
    101    */
    102   struct DONAU_DonationUnitInformation *donation_unit_keys;
    103 
    104   /**
    105    * Supported protocol version by the donau.
    106    * String in the format current:revision:age using the
    107    * semantics of GNU libtool.  See
    108    * https://www.gnu.org/software/libtool/manual/html_node/Versioning.html#Versioning
    109    */
    110   char *version;
    111 
    112   /**
    113    * Financial domain.
    114    */
    115   char *domain;
    116 
    117   /**
    118    * Supported currency of the donau.
    119    */
    120   char *currency;
    121 
    122   /**
    123    * What is the base URL of the donau that returned
    124    * these keys?
    125    */
    126   char *donau_url;
    127 
    128   /**
    129    * Specifies how an amount's fractional digits should be rendered.
    130    * More details in DD51.
    131    */
    132   struct TALER_CurrencySpecification currency_specification;
    133 
    134   /**
    135    * Length of the @e sign_keys array (number of valid entries).
    136    */
    137   unsigned int num_sign_keys;
    138 
    139   /**
    140    * Length of the @e donation_unit_keys array.
    141    */
    142   unsigned int num_donation_unit_keys;
    143 
    144   /**
    145    * Reference counter for this structure.
    146    * Freed when it reaches 0.
    147    */
    148   unsigned int rc;
    149 
    150 };
    151 
    152 
    153 /**
    154  * How compatible are the protocol version of the donau and this
    155  * client?  The bits (1,2,4) can be used to test if the donau's
    156  * version is incompatible, older or newer respectively.
    157  */
    158 enum DONAU_VersionCompatibility
    159 {
    160 
    161   /**
    162    * The donau runs exactly the same protocol version.
    163    */
    164   DONAU_VC_MATCH = 0,
    165 
    166   /**
    167    * The donau is too old or too new to be compatible with this
    168    * implementation (bit)
    169    */
    170   DONAU_VC_INCOMPATIBLE = 1,
    171 
    172   /**
    173    * The donau is older than this implementation (bit)
    174    */
    175   DONAU_VC_OLDER = 2,
    176 
    177   /**
    178    * The donau is too old to be compatible with
    179    * this implementation.
    180    */
    181   DONAU_VC_INCOMPATIBLE_OUTDATED
    182     = DONAU_VC_INCOMPATIBLE
    183       | DONAU_VC_OLDER,
    184 
    185   /**
    186    * The donau is more recent than this implementation (bit).
    187    */
    188   DONAU_VC_NEWER = 4,
    189 
    190   /**
    191    * The donau is too recent for this implementation.
    192    */
    193   DONAU_VC_INCOMPATIBLE_NEWER
    194     = DONAU_VC_INCOMPATIBLE
    195       | DONAU_VC_NEWER,
    196 
    197   /**
    198    * We could not even parse the version data.
    199    */
    200   DONAU_VC_PROTOCOL_ERROR = 8
    201 
    202 };
    203 
    204 
    205 /**
    206  * General information about the HTTP response we obtained
    207  * from the donau for a request.
    208  */
    209 struct DONAU_HttpResponse
    210 {
    211 
    212   /**
    213    * The complete JSON reply. NULL if we failed to parse the
    214    * reply (too big, invalid JSON).
    215    */
    216   const json_t *reply;
    217 
    218   /**
    219    * Set to the human-readable 'hint' that is optionally
    220    * provided by the donau together with errors. NULL
    221    * if no hint was provided or if there was no error.
    222    */
    223   const char *hint;
    224 
    225   /**
    226    * HTTP status code for the response.  0 if the
    227    * HTTP request failed and we did not get any answer, or
    228    * if the answer was invalid and we set @a ec to a
    229    * client-side error code.
    230    */
    231   unsigned int http_status;
    232 
    233   /**
    234    * Taler error code.  #TALER_EC_NONE if everything was
    235    * OK.  Usually set to the "code" field of an error
    236    * response, but may be set to values created at the
    237    * client side, for example when the response was
    238    * not in JSON format or was otherwise ill-formed.
    239    */
    240   enum TALER_ErrorCode ec;
    241 
    242 };
    243 
    244 
    245 /**
    246  * Response from /keys.
    247  */
    248 struct DONAU_KeysResponse
    249 {
    250   /**
    251    * HTTP response dataclosure
    252    */
    253   struct DONAU_HttpResponse hr;
    254 
    255   /**
    256    * Details depending on the HTTP status code.
    257    */
    258   union
    259   {
    260 
    261     /**
    262      * Details on #MHD_HTTP_OK.
    263      */
    264     struct
    265     {
    266       /**
    267        * Information about the various keys used by the donau.
    268        */
    269       const struct DONAU_Keys *keys;
    270 
    271       /**
    272        * Protocol compatibility information
    273        */
    274       enum DONAU_VersionCompatibility compat;
    275     } ok;
    276   } details;
    277 
    278 };
    279 
    280 
    281 /**
    282  * Function called with information about
    283  * a particular donau and what keys the donau is using.
    284  * The ownership over the @a keys object is passed to
    285  * the callee, thus it is given explicitly and not
    286  * (only) via @a kr.
    287  *
    288  * @param cls closure
    289  * @param kr response from /keys
    290  * @param[in] keys keys object passed to callback with
    291  *  reference counter of 1. Must be freed by callee
    292  *  using #DONAU_keys_decref(). NULL on failure.
    293  */
    294 #ifndef DONAU_GET_KEYS_RESULT_CLOSURE
    295 /**
    296  * Type of the closure used by the #DONAU_GetKeysCallback.
    297  */
    298 #define DONAU_GET_KEYS_RESULT_CLOSURE void
    299 #endif
    300 typedef void
    301 (*DONAU_GetKeysCallback) (
    302   DONAU_GET_KEYS_RESULT_CLOSURE *cls,
    303   const struct DONAU_KeysResponse *kr,
    304   struct DONAU_Keys *keys);
    305 
    306 
    307 /**
    308  * @brief Handle for a GET /keys request.
    309  */
    310 struct DONAU_GetKeysHandle;
    311 
    312 
    313 /**
    314  * Fetch the main /keys resources from an donau.  The obtained
    315  * information will be passed to the @a cert_cb.
    316  *
    317  * @param ctx the context
    318  * @param url HTTP base URL for the donau
    319  * @param cert_cb function to call with the donau's certification information,
    320  *                possibly called repeatedly if the information changes
    321  * @param cert_cb_cls closure for @a cert_cb
    322  * @return the donau handle; NULL upon error
    323  */
    324 struct DONAU_GetKeysHandle *
    325 DONAU_get_keys (
    326   struct GNUNET_CURL_Context *ctx,
    327   const char *url,
    328   DONAU_GetKeysCallback cert_cb,
    329   DONAU_GET_KEYS_RESULT_CLOSURE *cert_cb_cls);
    330 
    331 
    332 /**
    333  * Serialize the latest data from @a keys to be persisted
    334  * (for example, to be used as @a last_keys later).
    335  *
    336  * @param kd the key data to serialize
    337  * @return NULL on error; otherwise JSON object owned by the caller
    338  */
    339 json_t *
    340 DONAU_keys_to_json (const struct DONAU_Keys *kd);
    341 
    342 
    343 /**
    344  * Deserialize keys data stored in @a j.
    345  *
    346  * @param j JSON keys data previously returned from #DONAU_keys_to_json()
    347  * @return NULL on error (i.e. invalid JSON); otherwise
    348  *         keys object with reference counter 1 owned by the caller
    349  */
    350 struct DONAU_Keys *
    351 DONAU_keys_from_json (const json_t *j);
    352 
    353 
    354 /**
    355  * Cancel GET /keys operation.
    356  *
    357  * @param[in] gkh the GET /keys handle
    358  */
    359 void
    360 DONAU_get_keys_cancel (struct DONAU_GetKeysHandle *gkh);
    361 
    362 
    363 /**
    364  * Increment reference counter for @a keys
    365  *
    366  * @param[in,out] keys object to increment reference counter for
    367  * @return keys, with incremented reference counter
    368  */
    369 struct DONAU_Keys *
    370 DONAU_keys_incref (struct DONAU_Keys *keys);
    371 
    372 
    373 /**
    374  * Decrement reference counter for @a keys.
    375  * Frees @a keys if reference counter becomes zero.
    376  *
    377  * @param[in,out] keys object to decrement reference counter for
    378  */
    379 void
    380 DONAU_keys_decref (struct DONAU_Keys *keys);
    381 
    382 /**
    383  * Obtain the donation unit key details from the donau.
    384  *
    385  * @param keys the donau's key set
    386  * @param pk public key of the donation unit to lookup
    387  * @return details about the given donation unit key, NULL if the key is not
    388  * found
    389  */
    390 const struct DONAU_DonationUnitInformation *
    391 DONAU_get_donation_unit_key (
    392   const struct DONAU_Keys *keys,
    393   const struct DONAU_DonationUnitPublicKey *pk);
    394 
    395 
    396 /**
    397  * Compute the salted donor tax-id hash (SHA-512).
    398  *
    399  * @param donor_tax_id  cleartext donor tax id (ASCII/UTF-8)
    400  * @param salt          ASCII/UTF-8 salt
    401  * @param[out] out_hash buffer of size 512/8 bytes
    402  * @return true on success, false on invalid inputs
    403  */
    404 bool
    405   DONAU_compute_salted_tax_id_hash (const char *donor_tax_id,
    406                                     const char *salt,
    407                                     unsigned char out_hash[512 / 8]);
    408 
    409 
    410 /**
    411  * Greedily build a multiset of donation-unit public keys that sums EXACTLY to
    412  * @a requested_amount, using donation units from @a keys for the given @a year.
    413  *
    414  * @param keys              Donau keys (must match requested_amount currency)
    415  * @param requested_amount  target amount
    416  * @param year              only consider donation units for this year
    417  * @param[out] out_keys     array of selected public keys (owned by caller)
    418  * @param[out] out_len      length of @a out_keys
    419  * @return #GNUNET_OK on exact match;
    420  *         #GNUNET_NO if exact match not possible;
    421  *         #GNUNET_SYSERR on invalid input/currency mismatch.
    422  */
    423 enum GNUNET_GenericReturnValue
    424 DONAU_select_donation_unit_keys_for_amount (
    425   const struct DONAU_Keys *keys,
    426   const struct TALER_Amount *requested_amount,
    427   uint64_t year,
    428   struct DONAU_DonationUnitPublicKey **out_keys,
    429   size_t *out_len);
    430 
    431 
    432 /**
    433  * Obtain the donation unit key details from the donau.
    434  *
    435  * @param keys the donau's key set
    436  * @param hc hash of the public key of the donation unit to lookup
    437  * @return details about the given donation unit key, returns NULL
    438  * if the key is not available or deprecated.
    439  */
    440 const struct DONAU_DonationUnitInformation *
    441 DONAU_get_donation_unit_key_by_hash (
    442   const struct DONAU_Keys *keys,
    443   const struct DONAU_DonationUnitHashP *hc);
    444 
    445 
    446 /**
    447  * Obtain the donation amount for the given array of #DONAU_BlindedUniqueDonorIdentifierKeyPair
    448  *
    449  * @param keys the donau's key set
    450  * @param bkps array of blinded unique donor identifiers
    451  * @param num_bkps length of the @a bkps array
    452  * @param year year of the donation
    453  * @param[out] sum_out result amount (initialized to zero in @a keys->currency)
    454  * @return #GNUNET_OK on success;
    455  *         #GNUNET_NO on invalid input, duplication, year mismatch;
    456  *         #GNUNET_SYSERR on math errors.
    457  */
    458 enum GNUNET_GenericReturnValue
    459 DONAU_get_donation_amount_from_bkps (
    460   const struct DONAU_Keys *keys,
    461   const struct DONAU_BlindedUniqueDonorIdentifierKeyPair *bkps,
    462   size_t num_bkps,
    463   uint64_t year,
    464   struct TALER_Amount *sum_out);
    465 
    466 
    467 /**
    468  * Get confirmation that the given array of the #DONAU_BlindedUniqueDonorIdentifierKeyPair
    469  * does not contain duplicates.
    470  *
    471  * @return #GNUNET_OK if the @a bkps array does not contain duplicates
    472  */
    473 bool
    474 DONAU_check_bkps_duplication (
    475   const struct DONAU_BlindedUniqueDonorIdentifierKeyPair *bkps,
    476   const size_t num_bkps
    477   );
    478 
    479 
    480 /**
    481  * Obtain meta data about an donau (online) signing
    482  * key.
    483  *
    484  * @param keys from where to obtain the meta data
    485  * @param donau_pub public key to lookup
    486  * @return NULL on error (@a donau_pub not known)
    487  */
    488 const struct DONAU_SigningPublicKeyAndValidity *
    489 DONAU_get_signing_key_info (
    490   const struct DONAU_Keys *keys,
    491   const struct DONAU_DonauPublicKeyP *donau_pub);
    492 
    493 
    494 /* ********************* POST / issue receipt  *********************** */
    495 
    496 
    497 /**
    498  * @brief A Batch Submit Handle
    499  */
    500 struct DONAU_BatchIssueReceiptHandle;
    501 
    502 /**
    503  * Structure with information about a batch
    504  * of issue receipts.
    505  */
    506 struct DONAU_BatchIssueResponse
    507 {
    508   /**
    509    * HTTP response data
    510    */
    511   struct DONAU_HttpResponse hr;
    512 
    513   union
    514   {
    515 
    516     /**
    517      * Information returned if the HTTP status is
    518      * #MHD_HTTP_OK.
    519      */
    520     struct
    521     {
    522 
    523       /**
    524        * Blind signature provided by the donau
    525        */
    526       struct DONAU_BlindedDonationUnitSignature *blinded_sigs;
    527 
    528       /**
    529        * Number of blinded signatures in @a blinded_sigs.
    530        */
    531       size_t num_blinded_sigs;
    532 
    533       /**
    534        * total issued amount over all donation receipts of a donation specified
    535        * by the request (confirmation).
    536        */
    537       struct TALER_Amount issued_amount;
    538 
    539     } ok;
    540 
    541     struct
    542     {
    543       /* FIXME: returning full details is not implemented */
    544     } conflict;
    545 
    546   } details;
    547 };
    548 
    549 
    550 /**
    551  * Callbacks of this type are used to serve the result of submitting a
    552  *  permission request to a donau.
    553  *
    554  * @param cls closure
    555  * @param dr  response details
    556  */
    557 #ifndef DONAU_BATCH_ISSUE_RECEIPTS_RESULT_CLOSURE
    558 /**
    559  * Type of the closure used by the #DONAU_BatchIssueReceiptsCallback.
    560  */
    561 #define DONAU_BATCH_ISSUE_RECEIPTS_RESULT_CLOSURE void
    562 #endif
    563 typedef void
    564 (*DONAU_BatchIssueReceiptsCallback) (
    565   DONAU_BATCH_ISSUE_RECEIPTS_RESULT_CLOSURE *cls,
    566   const struct DONAU_BatchIssueResponse*dr);
    567 
    568 
    569 /**
    570  * Submit a batch of issue receipts to the donau and get the
    571  * donau's response. This API is typically used by a charity. Note that
    572  * while we return the response verbatim to the caller for further processing,
    573  * we do already verify that the response is well-formed. If the donau's reply is not
    574  * well-formed, we return an HTTP status code of zero to @a cb.
    575  *
    576  * We also verify that the signature of the charity is valid for this
    577  * request. Also, the donau must be ready to operate (i.e.  have
    578  * finished processing the /keys reply). If either check fails, we do
    579  * NOT initiate the receipts with the donau and instead return NULL.
    580  *
    581  * @param ctx curl context
    582  * @param url donau base URL
    583  * @param charity_priv private key of the charity
    584  * @param charity_id unique (row ID) of the charity at the DONAU
    585  * @param year donation year for which receipts are issued
    586  * @param num_bkp length of the @a bkp array
    587  * @param bkp array with details about the blinded donation envelopes
    588  * @param cb the callback to call when a reply for this request is available
    589  * @param cb_cls closure for the above callback
    590  * @return a handle for this request; NULL if the inputs are invalid (i.e.
    591  *         signatures fail to verify).  In this case, the callback is not called.
    592  */
    593 struct DONAU_BatchIssueReceiptHandle *
    594 DONAU_charity_issue_receipt (
    595   struct GNUNET_CURL_Context *ctx,
    596   const char *url,
    597   const struct DONAU_CharityPrivateKeyP *charity_priv,
    598   uint64_t charity_id,
    599   uint64_t year,
    600   size_t num_bkp,
    601   const struct DONAU_BlindedUniqueDonorIdentifierKeyPair *bkp,
    602   DONAU_BatchIssueReceiptsCallback cb,
    603   DONAU_BATCH_ISSUE_RECEIPTS_RESULT_CLOSURE *cb_cls);
    604 
    605 /**
    606  * Cancel a batch issue receipt request. This function cannot be used
    607  * on a request handle if a response is already served for it.
    608  *
    609  * @param[in] birh the issue receipt request handle
    610  */
    611 void
    612 DONAU_charity_issue_receipt_cancel (
    613   struct DONAU_BatchIssueReceiptHandle *birh);
    614 
    615 
    616 /* ********************* POST / submit receipts  *********************** */
    617 
    618 
    619 /**
    620  * @brief A Batch Submit receipts Handle
    621  */
    622 struct DONAU_DonorReceiptsToStatementHandle;
    623 
    624 
    625 /**
    626  * Structure with information about a batch
    627  * operation's result.
    628  */
    629 struct DONAU_DonorReceiptsToStatementResult
    630 {
    631   /**
    632    * HTTP response data
    633    */
    634   struct DONAU_HttpResponse hr;
    635 
    636 };
    637 
    638 
    639 /**
    640  * Callbacks of this type are used to serve the result of submitting a
    641  *  permission request to a donau.
    642  *
    643  * @param cls closure
    644  * @param dr  response details
    645  */
    646 #ifndef DONAU_SUBMIT_RECEIPTS_RESULT_CLOSURE
    647 /**
    648  * Type of the closure used by the
    649  * #DONAU_DonorReceiptsToStatementResultCallback.
    650  */
    651 #define DONAU_SUBMIT_RECEIPTS_RESULT_CLOSURE void
    652 #endif
    653 typedef void
    654 (*DONAU_DonorReceiptsToStatementResultCallback) (
    655   DONAU_SUBMIT_RECEIPTS_RESULT_CLOSURE *cls,
    656   const struct DONAU_DonorReceiptsToStatementResult *dr);
    657 
    658 
    659 /**
    660  * Submit a batch of receipts to the donau and get the
    661  * donau's response. This API is typically used by a donor. Note that
    662  * while we return the response verbatim to the caller for further processing,
    663  * we do already verify that the response is well-formed. If the donau's reply is not
    664  * well-formed, we return an HTTP status code of zero to @a cb.
    665  *
    666  * We also verify that the signature of the charity is valid for this
    667  * request. Also, the @a donau must be ready to operate (i.e.  have
    668  * finished processing the /keys reply). If either check fails, we do
    669  * NOT initiate the receipts with the donau and instead return NULL.
    670  *
    671  * @param ctx curl context
    672  * @param url donau base URL
    673  * @param num_drs length of the @a drs array
    674  * @param drs array with details about the donation receipts
    675  * @param year corresponding year
    676  * @param h_donor_tax_id salted and hashed tax id
    677  * @param cb the callback to call when a reply for this request is available
    678  * @param cls closure for the above callback
    679  * @return a handle for this request; NULL if the inputs are invalid (i.e.
    680  *         signatures fail to verify). In this case, the callback is not called.
    681  */
    682 struct DONAU_DonorReceiptsToStatementHandle *
    683 DONAU_donor_receipts_to_statement (
    684   struct GNUNET_CURL_Context *ctx,
    685   const char *url,
    686   const size_t num_drs,
    687   const struct DONAU_DonationReceipt drs[num_drs],
    688   const uint64_t year,
    689   const struct DONAU_HashDonorTaxId *h_donor_tax_id,
    690   DONAU_DonorReceiptsToStatementResultCallback cb,
    691   DONAU_SUBMIT_RECEIPTS_RESULT_CLOSURE *cls);
    692 
    693 /**
    694  * Cancel a batch  permission request. This function cannot be used
    695  * on a request handle if a response is already served for it.
    696  *
    697  * @param[in] drsh the Batch Submit receipts handle
    698  */
    699 void
    700 DONAU_donor_receipts_to_statement_cancel (
    701   struct DONAU_DonorReceiptsToStatementHandle *drsh);
    702 
    703 
    704 /* ********************* GET /donation-statement *********************** */
    705 
    706 
    707 /**
    708  * @brief A get donation statement Handle
    709  */
    710 struct DONAU_DonationStatementGetHandle;
    711 
    712 
    713 /**
    714  * Structure with information about a
    715  * operation's result.
    716  */
    717 struct DONAU_DonationStatementResponse
    718 {
    719   /**
    720    * HTTP response data
    721    */
    722   struct DONAU_HttpResponse hr;
    723 
    724   union
    725   {
    726 
    727     /**
    728      * Information returned if the HTTP status is
    729      * #MHD_HTTP_OK.
    730      */
    731     struct
    732     {
    733       /**
    734        * total amount of the donation statement for the requested year
    735        */
    736       struct TALER_Amount total_amount;
    737 
    738       /**
    739        * The donation statement for a requested year. Signature over the total amount,
    740        * the year, the unique identifier hash
    741        */
    742       struct DONAU_DonauSignatureP donation_statement_sig;
    743 
    744       /**
    745        * The donau public to verify the signature.
    746        */
    747       struct DONAU_DonauPublicKeyP donau_pub;
    748 
    749     } ok;
    750 
    751   } details;
    752 };
    753 
    754 
    755 /**
    756  * Callbacks of this type are used to serve the result of submitting a
    757  *  permission request to a donau.
    758  *
    759  * @param cls closure
    760  * @param dr  response details
    761  */
    762 #ifndef DONAU_GET_DONATION_STATEMENT_RESULT_CLOSURE
    763 /**
    764  * Type of the closure used by the
    765  * #DONAU_GetDonationStatmentResponseCallback.
    766  */
    767 #define DONAU_GET_DONATION_STATEMENT_RESULT_CLOSURE void
    768 #endif
    769 typedef void
    770 (*DONAU_GetDonationStatmentResponseCallback) (
    771   DONAU_GET_DONATION_STATEMENT_RESULT_CLOSURE *cls,
    772   const struct DONAU_DonationStatementResponse *dr);
    773 
    774 
    775 /**
    776  * Get a specific donation statement from the donau. This API is typically used by a donor.
    777  * Note that while we return the response verbatim to the caller for further processing,
    778  * we do already verify that the response is well-formed. If the donau's reply is not
    779  * well-formed, we return an HTTP status code of zero to @a cb.
    780  *
    781  * @param ctx curl context
    782  * @param url donau base URL
    783  * @param year corresponding year
    784  * @param h_donor_tax_id salted and hashed tax id
    785  * @param cb the callback to call when a reply for this request is available
    786  * @param cb_cls closure for the above callback
    787  * @return a handle for this request; NULL if the inputs are invalid (i.e.
    788  *         signatures fail to verify). In this case, the callback is not called.
    789  */
    790 struct DONAU_DonationStatementGetHandle *
    791 DONAU_donation_statement_get (
    792   struct GNUNET_CURL_Context *ctx,
    793   const char *url,
    794   const uint64_t year,
    795   const struct DONAU_HashDonorTaxId *h_donor_tax_id,
    796   DONAU_GetDonationStatmentResponseCallback cb,
    797   DONAU_GET_DONATION_STATEMENT_RESULT_CLOSURE *cb_cls);
    798 
    799 /**
    800  * Cancel a batch  permission request. This function cannot be used
    801  * on a request handle if a response is already served for it.
    802  *
    803  * @param[in] dsgh the Batch Submit receipts handle
    804  */
    805 void
    806 DONAU_donation_statement_get_cancel (
    807   struct DONAU_DonationStatementGetHandle *dsgh);
    808 
    809 
    810 /* ********************* POST /csr batch-issue *********************** */
    811 
    812 
    813 /**
    814  * @brief A /csr-batch-issue Handle
    815  */
    816 struct DONAU_CsRBatchIssueHandle;
    817 
    818 
    819 /**
    820  * Details about a response for a CS R request.
    821  */
    822 struct DONAU_CsRBatchIssueResponse
    823 {
    824   /**
    825    * HTTP response data.
    826    */
    827   struct DONAU_HttpResponse hr;
    828 
    829   /**
    830    * Details about the response.
    831    */
    832   union
    833   {
    834     /**
    835      * Details if the status is #MHD_HTTP_OK.
    836      */
    837     struct
    838     {
    839       /**
    840        * Values contributed by the donau for the
    841        * respective donation receipts's batch-issue operation.
    842        */
    843       struct DONAU_BatchIssueValues alg_values;
    844 
    845     } ok;
    846 
    847     /**
    848      * Details if the status is #MHD_HTTP_GONE.
    849      */
    850     struct
    851     {
    852       /* FIXME: returning full details is not implemented */
    853     } gone;
    854 
    855   } details;
    856 };
    857 
    858 
    859 /**
    860  * Callbacks of this type are used to serve the result of submitting a
    861  * CS R batch-issue request to a donau.
    862  *
    863  * @param cls closure
    864  * @param csrr response details
    865  */
    866 #ifndef DONAU_CSR_BATCH_ISSUE_RESULT_CLOSURE
    867 /**
    868  * Type of the closure used by the #DONAU_CsRBatchIssueCallback.
    869  */
    870 #define DONAU_CSR_BATCH_ISSUE_RESULT_CLOSURE void
    871 #endif
    872 typedef void
    873 (*DONAU_CsRBatchIssueCallback) (
    874   DONAU_CSR_BATCH_ISSUE_RESULT_CLOSURE *cls,
    875   const struct DONAU_CsRBatchIssueResponse *csrr);
    876 
    877 
    878 /**
    879  * Get a CS R using a /csr-batch-issue request.
    880  *
    881  * @param ctx The curl context to use for the requests
    882  * @param url Base-URL to the donau
    883  * @param pk Which donation unit key is the /csr request for
    884  * @param nonce client nonce for the request
    885  * @param cb the callback to call when the final result for this request is available
    886  * @param cb_cls closure for the above callback
    887  * @return handle for the operation on success, NULL on error, i.e.
    888  *         if the inputs are invalid (i.e.donation unit key not with this donau).
    889  *         In this case, the callback is not called.
    890  */
    891 struct DONAU_CsRBatchIssueHandle *
    892 DONAU_csr_issue (
    893   struct GNUNET_CURL_Context *ctx,
    894   const char *url,
    895   const struct DONAU_DonationUnitPublicKey *pk,
    896   const struct GNUNET_CRYPTO_CsSessionNonce *nonce,
    897   DONAU_CsRBatchIssueCallback cb,
    898   DONAU_CSR_BATCH_ISSUE_RESULT_CLOSURE *cb_cls);
    899 
    900 
    901 /**
    902  *
    903  * Cancel a CS R batch-issue request.  This function cannot be used
    904  * on a request handle if a response is already served for it.
    905  *
    906  * @param csrh the batch-issue handle
    907  */
    908 void
    909 DONAU_csr_cancel (
    910   struct DONAU_CsRBatchIssueHandle *csrh);
    911 
    912 
    913 /* ********************* GET /charities/ *********************** */
    914 
    915 /**
    916  *  A Charity
    917  */
    918 struct DONAU_CharitySummary
    919 {
    920   /**
    921    * charity id
    922    */
    923   uint64_t charity_id;
    924 
    925   /**
    926    * charity name
    927    */
    928   const char *name;
    929 
    930   /**
    931    * Max donation amount for this charitiy and year.
    932    */
    933   struct TALER_Amount max_per_year;
    934 
    935   /**
    936    * Current donation amount for this charity and year.
    937    */
    938   struct TALER_Amount receipts_to_date;
    939 
    940 };
    941 
    942 
    943 /**
    944  * @brief A /charities/ GET Handle
    945  */
    946 struct DONAU_CharitiesGetHandle;
    947 
    948 
    949 /**
    950  * @brief summary of every charity
    951  */
    952 struct DONAU_GetCharitiesResponse
    953 {
    954 
    955   /**
    956    * High-level HTTP response details.
    957    */
    958   struct DONAU_HttpResponse hr;
    959 
    960   /**
    961    * Details depending on @e hr.http_status.
    962    */
    963   union
    964   {
    965 
    966     /**
    967      * Information returned on success, if
    968      * @e hr.http_status is #MHD_HTTP_OK
    969      */
    970     struct
    971     {
    972 
    973       /**
    974        * Charity status information.
    975        */
    976       struct DONAU_CharitySummary *charities;
    977 
    978       /**
    979        * Length of the @e charities array.
    980        */
    981       size_t num_charities;
    982 
    983     } ok;
    984 
    985   } details;
    986 
    987 };
    988 
    989 
    990 /**
    991  * Callbacks of this type are used to serve the result of
    992  * charities status request to a donau.
    993  *
    994  * @param cls closure
    995  * @param rs HTTP response data
    996  */
    997 #ifndef DONAU_GET_CHARITIES_RESULT_CLOSURE
    998 /**
    999  * Type of the closure used by the #DONAU_GetCharitiesResponseCallback.
   1000  */
   1001 #define DONAU_GET_CHARITIES_RESULT_CLOSURE void
   1002 #endif
   1003 typedef void
   1004 (*DONAU_GetCharitiesResponseCallback) (
   1005   DONAU_GET_CHARITIES_RESULT_CLOSURE *cls,
   1006   const struct DONAU_GetCharitiesResponse *rs);
   1007 
   1008 
   1009 /**
   1010  * Submit a request to obtain the transaction history of a charity
   1011  * from the donau. Note that while we return the full response to the
   1012  * caller for further processing, we do already verify that the
   1013  * response is well-formed. If the donau's reply is not well-formed,
   1014  * we return an HTTP status code of zero to @a cb.
   1015  *
   1016  * @param ctx curl context
   1017  * @param url donau base URL
   1018  * @param bearer for authorization
   1019  * @param cb the callback to call when a reply for this request is available
   1020  * @param cb_cls closure for the above callback
   1021  * @return a handle for this request; NULL if the inputs are invalid (i.e.
   1022  *         signatures fail to verify). In this case, the callback is not called.
   1023  */
   1024 struct DONAU_CharitiesGetHandle *
   1025 DONAU_charities_get (
   1026   struct GNUNET_CURL_Context *ctx,
   1027   const char *url,
   1028   const struct DONAU_BearerToken *bearer,
   1029   DONAU_GetCharitiesResponseCallback cb,
   1030   DONAU_GET_CHARITIES_RESULT_CLOSURE *cb_cls);
   1031 
   1032 
   1033 /**
   1034  * Cancel a charity GET request.  This function cannot be used
   1035  * on a request handle if a response is already served for it.
   1036  *
   1037  * @param rgh the charity request handle
   1038  */
   1039 void
   1040 DONAU_charities_get_cancel (
   1041   struct DONAU_CharitiesGetHandle *rgh);
   1042 
   1043 
   1044 /* ********************* GET /charities/$CHARITY_ID *********************** */
   1045 
   1046 /**
   1047  * Information about a charity
   1048  */
   1049 struct DONAU_Charity
   1050 {
   1051   /**
   1052    * name of the charity
   1053    */
   1054   const char *name;
   1055 
   1056   /**
   1057    * charity url
   1058    */
   1059   const char *charity_url;
   1060 
   1061   /**
   1062    * public key of the charity
   1063    */
   1064   struct DONAU_CharityPublicKeyP charity_pub;
   1065 
   1066   /**
   1067     * Max donation amount for this charitiy and @e current_year.
   1068     */
   1069   struct TALER_Amount max_per_year;
   1070 
   1071   /**
   1072    * Current amount of donation receipts for @e current_year.
   1073    */
   1074   struct TALER_Amount receipts_to_date;
   1075 
   1076   /**
   1077    * current year
   1078    */
   1079   uint64_t current_year;
   1080 
   1081 };
   1082 
   1083 
   1084 /**
   1085  * @brief A /charities/$CHARITY_ID GET Handle
   1086  */
   1087 struct DONAU_CharityGetHandle;
   1088 
   1089 
   1090 /**
   1091  * @brief summary of a charity
   1092  */
   1093 struct DONAU_GetCharityResponse
   1094 {
   1095 
   1096   /**
   1097    * High-level HTTP response details.
   1098    */
   1099   struct DONAU_HttpResponse hr;
   1100 
   1101   /**
   1102    * Details depending on @e hr.http_status.
   1103    */
   1104   union
   1105   {
   1106 
   1107     /**
   1108      * Information returned on success, if
   1109      * @e hr.http_status is #MHD_HTTP_OK
   1110      */
   1111     struct
   1112     {
   1113 
   1114       /**
   1115        * Charity status information.
   1116        */
   1117       struct DONAU_Charity charity;
   1118 
   1119 
   1120     } ok;
   1121 
   1122   } details;
   1123 
   1124 };
   1125 
   1126 
   1127 /**
   1128  * Callbacks of this type are used to serve the result of a
   1129  * charity status request to a donau.
   1130  *
   1131  * @param cls closure
   1132  * @param rs HTTP response data
   1133  */
   1134 #ifndef DONAU_GET_CHARITY_RESULT_CLOSURE
   1135 /**
   1136  * Type of the closure used by the #DONAU_GetCharityResponseCallback.
   1137  */
   1138 #define DONAU_GET_CHARITY_RESULT_CLOSURE void
   1139 #endif
   1140 typedef void
   1141 (*DONAU_GetCharityResponseCallback) (
   1142   DONAU_GET_CHARITY_RESULT_CLOSURE *cls,
   1143   const struct DONAU_GetCharityResponse *rs);
   1144 
   1145 
   1146 /**
   1147  * Submit a GET request to obtain the information about a single charity
   1148  * from the donau. Note that while we return the full response to the
   1149  * caller for further processing, we do already verify that the
   1150  * response is well-formed. If the donau's reply is not well-formed,
   1151  * we return an HTTP status code of zero to @a cb.
   1152  *
   1153  * @param ctx curl context
   1154  * @param url donau base URL
   1155  * @param id of the requested charity
   1156  * @param charity_priv private key of the charity, for authorization
   1157  * @param cb the callback to call when a reply for this request is available
   1158  * @param cb_cls closure for the above callback
   1159  * @return a handle for this request; NULL if the inputs are invalid (i.e.
   1160  *         signatures fail to verify).  In this case, the callback is not called.
   1161  */
   1162 struct DONAU_CharityGetHandle *
   1163 DONAU_charity_get (
   1164   struct GNUNET_CURL_Context *ctx,
   1165   const char *url,
   1166   uint64_t id,
   1167   const struct DONAU_CharityPrivateKeyP *charity_priv,
   1168   DONAU_GetCharityResponseCallback cb,
   1169   DONAU_GET_CHARITY_RESULT_CLOSURE *cb_cls);
   1170 
   1171 
   1172 /**
   1173  * Cancel a charity GET request. This function cannot be used
   1174  * on a request handle if a response is already served for it.
   1175  *
   1176  * @param rgh the charity request handle
   1177  */
   1178 void
   1179 DONAU_charity_get_cancel (
   1180   struct DONAU_CharityGetHandle *rgh);
   1181 
   1182 
   1183 /* ********************* POST /charities/ *********************** */
   1184 
   1185 /**
   1186  * @brief A /charities Post Handle
   1187  */
   1188 struct DONAU_CharityPostHandle;
   1189 
   1190 
   1191 /**
   1192  * @brief new charity ID Response
   1193  */
   1194 struct DONAU_PostCharityResponse
   1195 {
   1196 
   1197   /**
   1198    * High-level HTTP response details.
   1199    */
   1200   struct DONAU_HttpResponse hr;
   1201 
   1202   /**
   1203    * Details depending on @e hr.http_status.
   1204    */
   1205   union
   1206   {
   1207 
   1208     /**
   1209      * Information returned on success, if
   1210      * @e hr.http_status is #MHD_HTTP_CREATED
   1211      */
   1212     struct
   1213     {
   1214 
   1215       /**
   1216        * charity id
   1217        */
   1218       uint64_t charity_id;
   1219 
   1220     } ok;
   1221 
   1222   } details;
   1223 
   1224 };
   1225 
   1226 
   1227 /**
   1228  * Callbacks of this type are used to serve the result of a
   1229  * charity post request to a donau.
   1230  *
   1231  * @param cls closure
   1232  * @param rs HTTP response data
   1233  */
   1234 #ifndef DONAU_POST_CHARITY_RESULT_CLOSURE
   1235 /**
   1236  * Type of the closure used by the #DONAU_PostCharityResponseCallback.
   1237  */
   1238 #define DONAU_POST_CHARITY_RESULT_CLOSURE void
   1239 #endif
   1240 typedef void
   1241 (*DONAU_PostCharityResponseCallback) (
   1242   DONAU_POST_CHARITY_RESULT_CLOSURE *cls,
   1243   const struct DONAU_PostCharityResponse *rs);
   1244 
   1245 
   1246 /**
   1247  * Submit a POST request to add a new charity to the donau. Note that
   1248  * while we return the full response to the caller for further processing,
   1249  * we do already verify that the response is well-formed (i.e. that
   1250  * signatures included in the response are all valid).  If the donau's
   1251  * reply is not well-formed, we return an HTTP status code of zero to
   1252  * @a cb.
   1253  *
   1254  * @param ctx curl context
   1255  * @param url donau base URL
   1256  * @param charity_name human readable name of the charity
   1257  * @param charity_url Web site of the charity
   1258  * @param max_per_year max donation amount allowed for the charity per year
   1259  * @param charity_pub public key of the charity
   1260  * @param bearer for authorization
   1261  * @param cb the callback to call when a reply for this request is available
   1262  * @param cb_cls closure for the above callback
   1263  * @return a handle for this request; NULL if the inputs are invalid (i.e.
   1264  *         signatures fail to verify).  In this case, the callback is not called.
   1265  */
   1266 struct DONAU_CharityPostHandle *
   1267 DONAU_charity_post (
   1268   struct GNUNET_CURL_Context *ctx,
   1269   const char *url,
   1270   const char *charity_name,
   1271   const char *charity_url,
   1272   const struct TALER_Amount *max_per_year,
   1273   const struct DONAU_CharityPublicKeyP *charity_pub,
   1274   const struct DONAU_BearerToken *bearer,
   1275   DONAU_PostCharityResponseCallback cb,
   1276   DONAU_POST_CHARITY_RESULT_CLOSURE *cb_cls);
   1277 
   1278 /**
   1279  * Cancel a charity Post request. This function cannot be used
   1280  * on a request handle if a response is already served for it.
   1281  *
   1282  * @param rgh the charity post handle
   1283  */
   1284 void
   1285 DONAU_charity_post_cancel (
   1286   struct DONAU_CharityPostHandle *rgh);
   1287 
   1288 
   1289 /* ********************* PATCH /charities/$CHARITY_ID *********************** */
   1290 
   1291 
   1292 /**
   1293  * @brief A /charities/$CHARITY_ID Patch Handle
   1294  */
   1295 struct DONAU_CharityPatchHandle;
   1296 
   1297 
   1298 /**
   1299  * @brief charity patch response
   1300  */
   1301 struct DONAU_PatchCharityResponse
   1302 {
   1303 
   1304   /**
   1305    * High-level HTTP response details.
   1306    */
   1307   struct DONAU_HttpResponse hr;
   1308 
   1309 };
   1310 
   1311 
   1312 /**
   1313  * Callbacks of this type are used to serve the result of a
   1314  * charity post request to a donau.
   1315  *
   1316  * @param cls closure
   1317  * @param rs HTTP response data
   1318  */
   1319 #ifndef DONAU_PATCH_CHARITY_RESULT_CLOSURE
   1320 /**
   1321  * Type of the closure used by the #DONAU_PatchCharityResponseCallback.
   1322  */
   1323 #define DONAU_PATCH_CHARITY_RESULT_CLOSURE void
   1324 #endif
   1325 typedef void
   1326 (*DONAU_PatchCharityResponseCallback) (
   1327   DONAU_PATCH_CHARITY_RESULT_CLOSURE *cls,
   1328   const struct DONAU_PatchCharityResponse *rs);
   1329 
   1330 
   1331 /**
   1332  * Submit a PATCH request to change data about a charity
   1333  * from the donau. Note that while we return the full response to the
   1334  * caller for further processing, we do already verify that the
   1335  * response is well-formed. If the donau's reply is not well-formed,
   1336  * we return an HTTP status code of zero to @a cb.
   1337  *
   1338  * @param ctx curl context
   1339  * @param url donau base URL
   1340  * @param charity_id of the charity
   1341  * @param charity_name human readable name of the charity
   1342  * @param charity_url Web site of the charity
   1343  * @param max_per_year max donation amount allowed for the charity per year
   1344  * @param charity_pub public key of the charity
   1345  * @param bearer bearer token authorizing the request
   1346  * @param cb the callback to call when a reply for this request is available
   1347  * @param cb_cls closure for the above callback
   1348  * @return a handle for this request; NULL if the inputs are invalid (i.e.
   1349  *         signatures fail to verify).  In this case, the callback is not called.
   1350  */
   1351 struct DONAU_CharityPatchHandle *
   1352 DONAU_charity_patch (
   1353   struct GNUNET_CURL_Context *ctx,
   1354   const char *url,
   1355   const uint64_t charity_id,
   1356   const char *charity_name,
   1357   const char *charity_url,
   1358   const struct TALER_Amount *max_per_year,
   1359   const struct DONAU_CharityPublicKeyP *charity_pub,
   1360   const struct DONAU_BearerToken *bearer,
   1361   DONAU_PatchCharityResponseCallback cb,
   1362   DONAU_PATCH_CHARITY_RESULT_CLOSURE *cb_cls);
   1363 
   1364 /**
   1365  * Cancel a charity Patch request. This function cannot be used
   1366  * on a request handle if a response is already served for it.
   1367  *
   1368  * @param rgh the charity patch handle
   1369  */
   1370 void
   1371 DONAU_charity_patch_cancel (
   1372   struct DONAU_CharityPatchHandle *rgh);
   1373 
   1374 
   1375 /* ********************* DELETE /charities/$CHARITY_ID *********************** */
   1376 
   1377 /**
   1378  * @brief A /charities/$CHARITY_ID Delete Handle
   1379  */
   1380 struct DONAU_CharityDeleteHandle;
   1381 
   1382 
   1383 /**
   1384  * @brief new charity ID Response
   1385  */
   1386 struct DONAU_DeleteCharityResponse
   1387 {
   1388 
   1389   /**
   1390    * High-level HTTP response details.
   1391    */
   1392   struct DONAU_HttpResponse hr;
   1393 
   1394 };
   1395 
   1396 
   1397 /**
   1398  * Callbacks of this type are used to serve the result of a
   1399  * charity post request to a donau.
   1400  *
   1401  * @param cls closure
   1402  * @param rs HTTP response data
   1403  */
   1404 #ifndef DONAU_DELETE_CHARITY_RESULT_CLOSURE
   1405 /**
   1406  * Type of the closure used by the #DONAU_DeleteCharityResponseCallback.
   1407  */
   1408 #define DONAU_DELETE_CHARITY_RESULT_CLOSURE void
   1409 #endif
   1410 typedef void
   1411 (*DONAU_DeleteCharityResponseCallback) (
   1412   DONAU_DELETE_CHARITY_RESULT_CLOSURE *cls,
   1413   const struct DONAU_DeleteCharityResponse *rs);
   1414 
   1415 
   1416 /**
   1417  * Submit a DELETE request to delete a charity
   1418  * from the donau. Note that while we return the full response to the
   1419  * caller for further processing, we do already verify that the
   1420  * response is well-formed. If the donau's reply is not well-formed,
   1421  * we return an HTTP status code of zero to @a cb.
   1422  *
   1423  * @param ctx curl context
   1424  * @param url donau base URL
   1425  * @param id of the charity
   1426  * @param bearer for authorization
   1427  * @param cb the callback to call when a reply for this request is available
   1428  * @param cb_cls closure for the above callback
   1429  * @return a handle for this request; NULL if the inputs are invalid (i.e.
   1430  *         signatures fail to verify). In this case, the callback is not called.
   1431  */
   1432 struct DONAU_CharityDeleteHandle *
   1433 DONAU_charity_delete (
   1434   struct GNUNET_CURL_Context *ctx,
   1435   const char *url,
   1436   const uint64_t id,
   1437   const struct DONAU_BearerToken *bearer,
   1438   DONAU_DeleteCharityResponseCallback cb,
   1439   DONAU_DELETE_CHARITY_RESULT_CLOSURE *cb_cls);
   1440 
   1441 /**
   1442  * Cancel a charity Delete request. This function cannot be used
   1443  * on a request handle if a response is already served for it.
   1444  *
   1445  * @param rgh the charity request handle
   1446  */
   1447 void
   1448 DONAU_charity_delete_cancel (
   1449   struct DONAU_CharityDeleteHandle *rgh);
   1450 
   1451 #endif