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