donau

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

donau_service.h (36103B)


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