get-keys.h (34198B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2014-2026 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/taler/taler-exchange/get-keys.h 18 * @brief C interface for GET /keys 19 * @author Christian Grothoff 20 */ 21 #ifndef _TALER_EXCHANGE__GET_KEYS_H 22 #define _TALER_EXCHANGE__GET_KEYS_H 23 24 #include <taler/taler-exchange/common.h> 25 26 /* ********************* /keys *********************** */ 27 28 29 /** 30 * @brief Exchange's signature key 31 */ 32 struct TALER_EXCHANGE_SigningPublicKey 33 { 34 /** 35 * The signing public key 36 */ 37 struct TALER_ExchangePublicKeyP key; 38 39 /** 40 * Signature over this signing key by the exchange's master signature. 41 */ 42 struct TALER_MasterSignatureP master_sig; 43 44 /** 45 * Validity start time 46 */ 47 struct GNUNET_TIME_Timestamp valid_from; 48 49 /** 50 * Validity expiration time (how long the exchange may use it). 51 */ 52 struct GNUNET_TIME_Timestamp valid_until; 53 54 /** 55 * Validity expiration time for legal disputes. 56 */ 57 struct GNUNET_TIME_Timestamp valid_legal; 58 }; 59 60 61 /** 62 * @brief Public information about a exchange's denomination key 63 */ 64 struct TALER_EXCHANGE_DenomPublicKey 65 { 66 /** 67 * The public key 68 */ 69 struct TALER_DenominationPublicKey key; 70 71 /** 72 * The hash of the public key. 73 */ 74 struct TALER_DenominationHashP h_key; 75 76 /** 77 * Exchange's master signature over this denomination record. 78 */ 79 struct TALER_MasterSignatureP master_sig; 80 81 /** 82 * Timestamp indicating when the denomination key becomes valid 83 */ 84 struct GNUNET_TIME_Timestamp valid_from; 85 86 /** 87 * Timestamp indicating when the denomination key can’t be used anymore to 88 * withdraw new coins. 89 */ 90 struct GNUNET_TIME_Timestamp withdraw_valid_until; 91 92 /** 93 * Timestamp indicating when coins of this denomination become invalid. 94 */ 95 struct GNUNET_TIME_Timestamp expire_deposit; 96 97 /** 98 * When do signatures with this denomination key become invalid? 99 * After this point, these signatures cannot be used in (legal) 100 * disputes anymore, as the Exchange is then allowed to destroy its side 101 * of the evidence. @e expire_legal is expected to be significantly 102 * larger than @e expire_deposit (by a year or more). 103 */ 104 struct GNUNET_TIME_Timestamp expire_legal; 105 106 /** 107 * The value of this denomination 108 */ 109 struct TALER_Amount value; 110 111 /** 112 * The applicable fees for this denomination 113 */ 114 struct TALER_DenomFeeSet fees; 115 116 /** 117 * Set to true if the private denomination key has been 118 * lost by the exchange and thus the key cannot be 119 * used for withdrawing at this time. 120 */ 121 bool lost; 122 123 /** 124 * Set to true if this denomination key has been 125 * revoked by the exchange. 126 */ 127 bool revoked; 128 129 }; 130 131 132 /** 133 * Information we track per denomination audited by the auditor. 134 */ 135 struct TALER_EXCHANGE_AuditorDenominationInfo 136 { 137 138 /** 139 * Signature by the auditor affirming that it is monitoring this 140 * denomination. 141 */ 142 struct TALER_AuditorSignatureP auditor_sig; 143 144 /** 145 * Offsets into the key's main `denom_keys` array identifying the 146 * denomination being audited by this auditor. 147 */ 148 unsigned int denom_key_offset; 149 150 }; 151 152 153 /** 154 * @brief Information we get from the exchange about auditors. 155 */ 156 struct TALER_EXCHANGE_AuditorInformation 157 { 158 /** 159 * Public key of the auditing institution. Wallets and merchants 160 * are expected to be configured with a set of public keys of 161 * auditors that they deem acceptable. These public keys are 162 * the roots of the Taler PKI. 163 */ 164 struct TALER_AuditorPublicKeyP auditor_pub; 165 166 /** 167 * URL of the auditing institution. Signed by the auditor's public 168 * key, this URL is a place where applications can direct users for 169 * additional information about the auditor. In the future, there 170 * should also be an auditor API for automated submission about 171 * claims of misbehaving exchange providers. 172 */ 173 char *auditor_url; 174 175 /** 176 * Name of the auditing institution (human-readable). 177 */ 178 char *auditor_name; 179 180 /** 181 * Array of length @a num_denom_keys with the denomination 182 * keys audited by this auditor. 183 */ 184 struct TALER_EXCHANGE_AuditorDenominationInfo *denom_keys; 185 186 /** 187 * Number of denomination keys audited by this auditor. 188 */ 189 unsigned int num_denom_keys; 190 }; 191 192 193 /** 194 * Global fees and options of an exchange for a given time period. 195 */ 196 struct TALER_EXCHANGE_GlobalFee 197 { 198 199 /** 200 * Signature affirming all of the data. 201 */ 202 struct TALER_MasterSignatureP master_sig; 203 204 /** 205 * Starting time of the validity period (inclusive). 206 */ 207 struct GNUNET_TIME_Timestamp start_date; 208 209 /** 210 * End time of the validity period (exclusive). 211 */ 212 struct GNUNET_TIME_Timestamp end_date; 213 214 /** 215 * Unmerged purses will be timed out after at most this time. 216 */ 217 struct GNUNET_TIME_Relative purse_timeout; 218 219 /** 220 * Account history is limited to this timeframe. 221 */ 222 struct GNUNET_TIME_Relative history_expiration; 223 224 /** 225 * Fees that apply globally, independent of denomination 226 * and wire method. 227 */ 228 struct TALER_GlobalFeeSet fees; 229 230 /** 231 * Number of free purses per account. 232 */ 233 uint32_t purse_account_limit; 234 }; 235 236 237 /** 238 * List sorted by @a start_date with fees to be paid for aggregate wire transfers. 239 */ 240 struct TALER_EXCHANGE_WireAggregateFees 241 { 242 /** 243 * This is a linked list. 244 */ 245 struct TALER_EXCHANGE_WireAggregateFees *next; 246 247 /** 248 * Fee to be paid whenever the exchange wires funds to the merchant. 249 */ 250 struct TALER_WireFeeSet fees; 251 252 /** 253 * Time when this fee goes into effect (inclusive) 254 */ 255 struct GNUNET_TIME_Timestamp start_date; 256 257 /** 258 * Time when this fee stops being in effect (exclusive). 259 */ 260 struct GNUNET_TIME_Timestamp end_date; 261 262 /** 263 * Signature affirming the above fee structure. 264 */ 265 struct TALER_MasterSignatureP master_sig; 266 }; 267 268 269 /** 270 * Information about wire fees by wire method. 271 */ 272 struct TALER_EXCHANGE_WireFeesByMethod 273 { 274 /** 275 * Wire method with the given @e fees. 276 */ 277 char *method; 278 279 /** 280 * Linked list of wire fees the exchange charges for 281 * accounts of the wire @e method. 282 */ 283 struct TALER_EXCHANGE_WireAggregateFees *fees_head; 284 285 }; 286 287 288 /** 289 * Information about a partner exchange for wallet-to-wallet transfers. 290 */ 291 struct TALER_EXCHANGE_WadPartner 292 { 293 /** 294 * Base URL of the partner exchange. 295 */ 296 char *partner_base_url; 297 298 /** 299 * Public master key of the partner exchange. 300 */ 301 struct TALER_MasterPublicKeyP partner_master_pub; 302 303 /** 304 * Per exchange-to-exchange transfer (wad) fee. 305 */ 306 struct TALER_Amount wad_fee; 307 308 /** 309 * Exchange-to-exchange wad (wire) transfer frequency. 310 */ 311 struct GNUNET_TIME_Relative wad_frequency; 312 313 /** 314 * When did this partnership begin (under these conditions)? 315 */ 316 struct GNUNET_TIME_Timestamp start_date; 317 318 /** 319 * How long is this partnership expected to last? 320 */ 321 struct GNUNET_TIME_Timestamp end_date; 322 323 /** 324 * Signature using the exchange's offline master key over 325 * TALER_WadPartnerSignaturePS with purpose 326 * TALER_SIGNATURE_MASTER_PARTNER_DETAILS. 327 */ 328 struct TALER_MasterSignatureP master_sig; 329 }; 330 331 332 /** 333 * Type of an account restriction. 334 */ 335 enum TALER_EXCHANGE_AccountRestrictionType 336 { 337 /** 338 * Invalid restriction. 339 */ 340 TALER_EXCHANGE_AR_INVALID = 0, 341 342 /** 343 * Account must not be used for this operation. 344 */ 345 TALER_EXCHANGE_AR_DENY = 1, 346 347 /** 348 * Other account must match given regular expression. 349 */ 350 TALER_EXCHANGE_AR_REGEX = 2 351 }; 352 353 /** 354 * Restrictions that apply to using a given exchange bank account. 355 */ 356 struct TALER_EXCHANGE_AccountRestriction 357 { 358 359 /** 360 * Type of the account restriction. 361 */ 362 enum TALER_EXCHANGE_AccountRestrictionType type; 363 364 /** 365 * Restriction details depending on @e type. 366 */ 367 union 368 { 369 /** 370 * Details if type is #TALER_EXCHANGE_AR_REGEX. 371 */ 372 struct 373 { 374 /** 375 * Regular expression that the normalized payto://-URI of the partner 376 * account must follow. The regular expression should follow 377 * posix-egrep, but without support for character classes, GNU 378 * extensions, back-references or intervals. See 379 * https://www.gnu.org/software/findutils/manual/html_node/find_html/posix_002degrep-regular-expression-syntax.html 380 * for a description of the posix-egrep syntax. Applications may support 381 * regexes with additional features, but exchanges must not use such 382 * regexes. 383 */ 384 char *posix_egrep; 385 386 /** 387 * Hint for a human to understand the restriction. 388 */ 389 char *human_hint; 390 391 /** 392 * Internationalizations for the @e human_hint. Map from IETF BCP 47 393 * language tax to localized human hints. 394 */ 395 json_t *human_hint_i18n; 396 } regex; 397 } details; 398 399 }; 400 401 402 /** 403 * Information about a wire account of the exchange. 404 */ 405 struct TALER_EXCHANGE_WireAccount 406 { 407 /** 408 * payto://-URI of the exchange. 409 */ 410 struct TALER_FullPayto fpayto_uri; 411 412 /** 413 * URL of a conversion service in case using this account is subject to 414 * currency conversion. NULL for no conversion needed. 415 */ 416 char *conversion_url; 417 418 /** 419 * Open banking gateway base URL for wallet-initiated wire 420 * transfers. NULL if not configured. 421 * @since protocol v33. 422 */ 423 char *open_banking_gateway; 424 425 /** 426 * Wire transfer gateway base URL for short wire transfer 427 * subjects. NULL if not configured. 428 * @since protocol v33. 429 */ 430 char *wire_transfer_gateway; 431 432 /** 433 * Array of restrictions that apply when crediting 434 * this account. 435 */ 436 struct TALER_EXCHANGE_AccountRestriction *credit_restrictions; 437 438 /** 439 * Array of restrictions that apply when debiting 440 * this account. 441 */ 442 struct TALER_EXCHANGE_AccountRestriction *debit_restrictions; 443 444 /** 445 * Length of the @e credit_restrictions array. 446 */ 447 unsigned int credit_restrictions_length; 448 449 /** 450 * Length of the @e debit_restrictions array. 451 */ 452 unsigned int debit_restrictions_length; 453 454 /** 455 * Signature of the exchange over the account (was checked by the API). 456 */ 457 struct TALER_MasterSignatureP master_sig; 458 459 /** 460 * Display label for the account, can be NULL. 461 */ 462 char *bank_label; 463 464 /** 465 * Priority for ordering the account in the display. 466 */ 467 int64_t priority; 468 469 }; 470 471 472 /** 473 * Applicable soft limits of zero for an account (or wallet). 474 * Clients should begin a KYC process before attempting 475 * these operations. 476 */ 477 struct TALER_EXCHANGE_ZeroLimitedOperation 478 { 479 480 /** 481 * Operation type for which the restriction applies. 482 */ 483 enum TALER_KYCLOGIC_KycTriggerEvent operation_type; 484 485 }; 486 487 488 /** 489 * Applicable limits for an account (or wallet). Exceeding these limits may 490 * trigger additional KYC requirements or be categorically verboten. 491 */ 492 struct TALER_EXCHANGE_AccountLimit 493 { 494 495 /** 496 * Operation type for which the restriction applies. 497 */ 498 enum TALER_KYCLOGIC_KycTriggerEvent operation_type; 499 500 /** 501 * Timeframe over which the @e threshold is computed. 502 */ 503 struct GNUNET_TIME_Relative timeframe; 504 505 /** 506 * The maximum amount transacted within the given @e timeframe for the 507 * specified @e operation_type. 508 */ 509 struct TALER_Amount threshold; 510 511 /** 512 * True if this is a soft limit and passing KYC checks 513 * or AML reviews may raise this limit. False if this 514 * is a hard limit that the exchange will not permit 515 * the client to exceed. 516 */ 517 bool soft_limit; 518 }; 519 520 521 /** 522 * @brief Information about keys from the exchange. 523 */ 524 struct TALER_EXCHANGE_Keys 525 { 526 527 /** 528 * Long-term offline signing key of the exchange. 529 */ 530 struct TALER_MasterPublicKeyP master_pub; 531 532 /** 533 * Signature over extension configuration data, if any. 534 */ 535 struct TALER_MasterSignatureP extensions_sig; 536 537 /** 538 * Array of the exchange's online signing keys. 539 */ 540 struct TALER_EXCHANGE_SigningPublicKey *sign_keys; 541 542 /** 543 * Array of the exchange's denomination keys. 544 */ 545 struct TALER_EXCHANGE_DenomPublicKey *denom_keys; 546 547 /** 548 * Array of the keys of the auditors of the exchange. 549 */ 550 struct TALER_EXCHANGE_AuditorInformation *auditors; 551 552 /** 553 * Array with the global fees of the exchange. 554 */ 555 struct TALER_EXCHANGE_GlobalFee *global_fees; 556 557 /** 558 * Configuration data for extensions. 559 */ 560 json_t *extensions; 561 562 /** 563 * Supported Taler protocol version by the exchange. 564 * String in the format current:revision:age using the 565 * semantics of GNU libtool. See 566 * https://www.gnu.org/software/libtool/manual/html_node/Versioning.html#Versioning 567 */ 568 char *version; 569 570 /** 571 * Supported currency of the exchange. 572 */ 573 char *currency; 574 575 /** 576 * What is the base URL of the exchange that returned 577 * these keys? 578 */ 579 char *exchange_url; 580 581 /** 582 * Asset type used by the exchange. Typical values 583 * are "fiat" or "crypto" or "regional" or "stock". 584 * Wallets should adjust their UI/UX based on this 585 * value. 586 */ 587 char *asset_type; 588 589 /** 590 * Shopping URL where users may find shops that accept 591 * digital cash from this exchange. NULL if not configured. 592 * @since protocol v21. 593 */ 594 char *shopping_url; 595 596 /** 597 * Bank-specific compliance language hint for wallets. 598 * NULL if not configured. 599 * @since protocol v24. 600 */ 601 char *bank_compliance_language; 602 603 /** 604 * Array of amounts a wallet is allowed to hold from 605 * this exchange before it must undergo further KYC checks. 606 * Length is given in @e wblwk_length. 607 */ 608 struct TALER_Amount *wallet_balance_limit_without_kyc; 609 610 /** 611 * Smallest amount that can likely be transferred to the exchange, 612 * used as the default for KYC authentication wire transfers. 613 * Only valid when @e tiny_amount_available is true. 614 * @since protocol v21. 615 */ 616 struct TALER_Amount tiny_amount; 617 618 /** 619 * Array of partner exchanges for wallet-to-wallet transfers. 620 * Length is given in @e num_wad_partners. 621 */ 622 struct TALER_EXCHANGE_WadPartner *wad_partners; 623 624 /** 625 * Array of accounts of the exchange. 626 */ 627 struct TALER_EXCHANGE_WireAccount *accounts; 628 629 /** 630 * Array of hard limits that apply at this exchange. 631 * All limits in this array will be hard limits. 632 */ 633 struct TALER_EXCHANGE_AccountLimit *hard_limits; 634 635 /** 636 * Array of operations with a default soft limit of zero 637 * that apply at this exchange. 638 * Clients should begin a KYC process before attempting 639 * these operations. 640 */ 641 struct TALER_EXCHANGE_ZeroLimitedOperation *zero_limits; 642 643 /** 644 * Array of wire fees by wire method. 645 */ 646 struct TALER_EXCHANGE_WireFeesByMethod *fees; 647 648 /** 649 * Currency rendering specification for this exchange. 650 */ 651 struct TALER_CurrencySpecification cspec; 652 653 /** 654 * How long after a reserve went idle will the exchange close it? 655 * This is an approximate number, not cryptographically signed by 656 * the exchange (advisory-only, may change anytime). 657 */ 658 struct GNUNET_TIME_Relative reserve_closing_delay; 659 660 /** 661 * Timestamp indicating the /keys generation. 662 */ 663 struct GNUNET_TIME_Timestamp list_issue_date; 664 665 /** 666 * When does this keys data expire? 667 */ 668 struct GNUNET_TIME_Timestamp key_data_expiration; 669 670 /** 671 * Timestamp indicating the creation time of the last 672 * denomination key in /keys. 673 * Used to fetch /keys incrementally. 674 */ 675 struct GNUNET_TIME_Timestamp last_denom_issue_date; 676 677 /** 678 * If age restriction is enabled on the exchange, we get an non-zero age_mask 679 */ 680 struct TALER_AgeMask age_mask; 681 682 /** 683 * Absolute STEFAN parameter. 684 */ 685 struct TALER_Amount stefan_abs; 686 687 /** 688 * Logarithmic STEFAN parameter. 689 */ 690 struct TALER_Amount stefan_log; 691 692 /** 693 * Linear STEFAN parameter. 694 */ 695 double stefan_lin; 696 697 /** 698 * Length of @e accounts array. 699 */ 700 unsigned int accounts_len; 701 702 /** 703 * Length of @e fees array. 704 */ 705 unsigned int fees_len; 706 707 /** 708 * Length of @e hard_limits array. 709 */ 710 unsigned int hard_limits_length; 711 712 /** 713 * Length of @e zero_limits array. 714 */ 715 unsigned int zero_limits_length; 716 717 /** 718 * Length of the @e wallet_balance_limit_without_kyc 719 * array. 720 */ 721 unsigned int wblwk_length; 722 723 /** 724 * Length of the @e global_fees array. 725 */ 726 unsigned int num_global_fees; 727 728 /** 729 * Length of the @e sign_keys array (number of valid entries). 730 */ 731 unsigned int num_sign_keys; 732 733 /** 734 * Length of the @e denom_keys array. 735 */ 736 unsigned int num_denom_keys; 737 738 /** 739 * Length of the @e auditors array. 740 */ 741 unsigned int num_auditors; 742 743 /** 744 * Actual length of the @e auditors array (size of allocation). 745 */ 746 unsigned int auditors_size; 747 748 /** 749 * Actual length of the @e denom_keys array (size of allocation). 750 */ 751 unsigned int denom_keys_size; 752 753 /** 754 * Reference counter for this structure. 755 * Freed when it reaches 0. 756 */ 757 unsigned int rc; 758 759 /** 760 * Length of the @e wad_partners array. 761 */ 762 unsigned int num_wad_partners; 763 764 /** 765 * Set to true if KYC is enabled at this exchange. 766 */ 767 bool kyc_enabled; 768 769 /** 770 * Set to true if the @e tiny_amount field is valid. 771 * @since protocol v21. 772 */ 773 bool tiny_amount_available; 774 775 /** 776 * Set to true if wallets should disable the direct deposit 777 * feature. Mainly used for regional/event currency deployments. 778 * @since protocol v30. 779 */ 780 bool disable_direct_deposit; 781 }; 782 783 784 /** 785 * How compatible are the protocol version of the exchange and this 786 * client? The bits (1,2,4) can be used to test if the exchange's 787 * version is incompatible, older or newer respectively. 788 */ 789 enum TALER_EXCHANGE_VersionCompatibility 790 { 791 792 /** 793 * The exchange runs exactly the same protocol version. 794 */ 795 TALER_EXCHANGE_VC_MATCH = 0, 796 797 /** 798 * The exchange is too old or too new to be compatible with this 799 * implementation (bit) 800 */ 801 TALER_EXCHANGE_VC_INCOMPATIBLE = 1, 802 803 /** 804 * The exchange is older than this implementation (bit) 805 */ 806 TALER_EXCHANGE_VC_OLDER = 2, 807 808 /** 809 * The exchange is too old to be compatible with 810 * this implementation. 811 */ 812 TALER_EXCHANGE_VC_INCOMPATIBLE_OUTDATED 813 = TALER_EXCHANGE_VC_INCOMPATIBLE 814 | TALER_EXCHANGE_VC_OLDER, 815 816 /** 817 * The exchange is more recent than this implementation (bit). 818 */ 819 TALER_EXCHANGE_VC_NEWER = 4, 820 821 /** 822 * The exchange is too recent for this implementation. 823 */ 824 TALER_EXCHANGE_VC_INCOMPATIBLE_NEWER 825 = TALER_EXCHANGE_VC_INCOMPATIBLE 826 | TALER_EXCHANGE_VC_NEWER, 827 828 /** 829 * We could not even parse the version data. 830 */ 831 TALER_EXCHANGE_VC_PROTOCOL_ERROR = 8 832 833 }; 834 835 836 /** 837 * Response from /keys. 838 */ 839 struct TALER_EXCHANGE_KeysResponse 840 { 841 /** 842 * HTTP response data 843 */ 844 struct TALER_EXCHANGE_HttpResponse hr; 845 846 /** 847 * Details depending on the HTTP status code. 848 */ 849 union 850 { 851 852 /** 853 * Details on #MHD_HTTP_OK. 854 */ 855 struct 856 { 857 /** 858 * Information about the various keys used by the exchange. 859 */ 860 const struct TALER_EXCHANGE_Keys *keys; 861 862 /** 863 * Protocol compatibility information 864 */ 865 enum TALER_EXCHANGE_VersionCompatibility compat; 866 } ok; 867 } details; 868 869 }; 870 871 872 /** 873 * Possible options we can set for the GET /keys request. 874 */ 875 enum TALER_EXCHANGE_GetKeysOption 876 { 877 /** 878 * End of list of options. 879 */ 880 TALER_EXCHANGE_GET_KEYS_OPTION_END = 0, 881 882 /** 883 * Perform incremental fetch using the given previous keys object. 884 * Defaults to NULL (no incremental fetch). 885 */ 886 TALER_EXCHANGE_GET_KEYS_OPTION_LAST_KEYS 887 888 }; 889 890 891 /** 892 * Value for an option for the GET /keys request. 893 */ 894 struct TALER_EXCHANGE_GetKeysOptionValue 895 { 896 /** 897 * Type of the option being set. 898 */ 899 enum TALER_EXCHANGE_GetKeysOption option; 900 901 /** 902 * Specific option value. 903 */ 904 union 905 { 906 /** 907 * Value if @e option is TALER_EXCHANGE_GET_KEYS_OPTION_LAST_KEYS. 908 * Previous keys object for incremental fetch. 909 */ 910 struct TALER_EXCHANGE_Keys *last_keys; 911 912 } details; 913 914 }; 915 916 917 /** 918 * @brief Handle for a GET /keys request. 919 */ 920 struct TALER_EXCHANGE_GetKeysHandle; 921 922 923 /** 924 * Terminate the list of options. 925 * 926 * @return the terminating object of struct TALER_EXCHANGE_GetKeysOptionValue 927 */ 928 #define TALER_EXCHANGE_get_keys_option_end_() \ 929 (const struct TALER_EXCHANGE_GetKeysOptionValue) \ 930 { \ 931 .option = TALER_EXCHANGE_GET_KEYS_OPTION_END \ 932 } 933 934 /** 935 * Set previous keys for incremental fetch. 936 * 937 * @param k previous keys object (may be NULL to request full fetch) 938 * @return representation of the option as a struct TALER_EXCHANGE_GetKeysOptionValue 939 */ 940 #define TALER_EXCHANGE_get_keys_option_last_keys(k) \ 941 (const struct TALER_EXCHANGE_GetKeysOptionValue) \ 942 { \ 943 .option = TALER_EXCHANGE_GET_KEYS_OPTION_LAST_KEYS, \ 944 .details.last_keys = (k) \ 945 } 946 947 948 #ifndef TALER_EXCHANGE_GET_KEYS_RESULT_CLOSURE 949 /** 950 * Type of the closure used by 951 * the #TALER_EXCHANGE_GetKeysCallback. 952 */ 953 #define TALER_EXCHANGE_GET_KEYS_RESULT_CLOSURE void 954 #endif /* TALER_EXCHANGE_GET_KEYS_RESULT_CLOSURE */ 955 956 /** 957 * Function called with information about who is auditing 958 * a particular exchange and what keys the exchange is using. 959 * The ownership over the @a keys object is passed to 960 * the callee, thus it is given explicitly and not 961 * (only) via @a kr. 962 * 963 * @param cls closure 964 * @param kr response from /keys 965 * @param[in] keys keys object passed to callback with 966 * reference counter of 1. Must be freed by callee 967 * using #TALER_EXCHANGE_keys_decref(). NULL on failure. 968 */ 969 typedef void 970 (*TALER_EXCHANGE_GetKeysCallback) ( 971 TALER_EXCHANGE_GET_KEYS_RESULT_CLOSURE *cls, 972 const struct TALER_EXCHANGE_KeysResponse *kr, 973 struct TALER_EXCHANGE_Keys *keys); 974 975 976 /** 977 * Set up GET /keys operation. 978 * Note that you must explicitly start the operation after 979 * possibly setting options. 980 * 981 * @param ctx the context 982 * @param url HTTP base URL for the exchange 983 * @return handle to operation, NULL on error 984 */ 985 struct TALER_EXCHANGE_GetKeysHandle * 986 TALER_EXCHANGE_get_keys_create ( 987 struct GNUNET_CURL_Context *ctx, 988 const char *url); 989 990 991 /** 992 * Set the requested options for the operation. 993 * 994 * If any option fails, other options may or may not be applied. 995 * 996 * @param gkh the request to set the options for 997 * @param num_options length of the @a options array 998 * @param options an array of options 999 * @return #GNUNET_OK on success, 1000 * #GNUNET_NO on failure, 1001 * #GNUNET_SYSERR on internal error 1002 */ 1003 enum GNUNET_GenericReturnValue 1004 TALER_EXCHANGE_get_keys_set_options_ ( 1005 struct TALER_EXCHANGE_GetKeysHandle *gkh, 1006 unsigned int num_options, 1007 const struct TALER_EXCHANGE_GetKeysOptionValue options[]); 1008 1009 1010 /** 1011 * Set the requested options for the operation. 1012 * 1013 * If any option fails, other options may or may not be applied. 1014 * 1015 * It should be used with helpers that create required options, for example: 1016 * 1017 * TALER_EXCHANGE_get_keys_set_options ( 1018 * gkh, 1019 * TALER_EXCHANGE_get_keys_option_last_keys (prev_keys)); 1020 * 1021 * @param gkh the request to set the options for 1022 * @param ... the list of options, each created by a 1023 * TALER_EXCHANGE_get_keys_option_NAME(VALUE) helper 1024 * @return #GNUNET_OK on success, 1025 * #GNUNET_NO on failure, 1026 * #GNUNET_SYSERR on internal error 1027 */ 1028 #define TALER_EXCHANGE_get_keys_set_options(gkh,...) \ 1029 TALER_EXCHANGE_get_keys_set_options_ ( \ 1030 gkh, \ 1031 TALER_EXCHANGE_COMMON_OPTIONS_ARRAY_MAX_SIZE, \ 1032 ((const struct TALER_EXCHANGE_GetKeysOptionValue[]) \ 1033 {__VA_ARGS__, TALER_EXCHANGE_get_keys_option_end_ () } \ 1034 )) 1035 1036 1037 /** 1038 * Start GET /keys operation. 1039 * 1040 * @param[in,out] gkh operation to start 1041 * @param cert_cb function to call with the exchange's certification information 1042 * @param cert_cb_cls closure for @a cert_cb 1043 * @return status code, #TALER_EC_NONE on success 1044 */ 1045 enum TALER_ErrorCode 1046 TALER_EXCHANGE_get_keys_start ( 1047 struct TALER_EXCHANGE_GetKeysHandle *gkh, 1048 TALER_EXCHANGE_GetKeysCallback cert_cb, 1049 TALER_EXCHANGE_GET_KEYS_RESULT_CLOSURE *cert_cb_cls); 1050 1051 1052 /** 1053 * Serialize the latest data from @a keys to be persisted 1054 * (for example, to be used as @a last_keys later). 1055 * 1056 * @param kd the key data to serialize 1057 * @return NULL on error; otherwise JSON object owned by the caller 1058 */ 1059 json_t * 1060 TALER_EXCHANGE_keys_to_json (const struct TALER_EXCHANGE_Keys *kd); 1061 1062 1063 /** 1064 * Deserialize keys data stored in @a j. 1065 * 1066 * @param j JSON keys data previously returned from #TALER_EXCHANGE_keys_to_json() 1067 * @return NULL on error (i.e. invalid JSON); otherwise 1068 * keys object with reference counter 1 owned by the caller 1069 */ 1070 struct TALER_EXCHANGE_Keys * 1071 TALER_EXCHANGE_keys_from_json (const json_t *j); 1072 1073 1074 /** 1075 * Cancel GET /keys operation. 1076 * 1077 * @param[in] gkh the GET /keys handle 1078 */ 1079 void 1080 TALER_EXCHANGE_get_keys_cancel (struct TALER_EXCHANGE_GetKeysHandle *gkh); 1081 1082 1083 /** 1084 * Increment reference counter for @a keys 1085 * 1086 * @param[in,out] keys object to increment reference counter for 1087 * @return keys, with incremented reference counter 1088 */ 1089 struct TALER_EXCHANGE_Keys * 1090 TALER_EXCHANGE_keys_incref (struct TALER_EXCHANGE_Keys *keys); 1091 1092 1093 /** 1094 * Decrement reference counter for @a keys. 1095 * Frees @a keys if reference counter becomes zero. 1096 * 1097 * @param[in,out] keys object to decrement reference counter for 1098 */ 1099 void 1100 TALER_EXCHANGE_keys_decref (struct TALER_EXCHANGE_Keys *keys); 1101 1102 1103 /** 1104 * Use STEFAN curve in @a keys to convert @a brut to @a net. Computes the 1105 * expected minimum (!) @a net amount that should for sure arrive in the 1106 * target amount at cost of @a brut to the wallet. Note that STEFAN curves by 1107 * design over-estimate actual fees and a wallet may be able to achieve the 1108 * same @a net amount with less fees --- or if the available coins are 1109 * abnormal in structure, it may take more. 1110 * 1111 * @param keys exchange key data 1112 * @param brut gross amount (actual cost including fees) 1113 * @param[out] net net amount (effective amount) 1114 * @return #GNUNET_OK on success, #GNUNET_NO if the 1115 * resulting @a net is zero (or lower) 1116 */ 1117 enum GNUNET_GenericReturnValue 1118 TALER_EXCHANGE_keys_stefan_b2n ( 1119 const struct TALER_EXCHANGE_Keys *keys, 1120 const struct TALER_Amount *brut, 1121 struct TALER_Amount *net); 1122 1123 1124 /** 1125 * Use STEFAN curve in @a keys to convert @a net to @a brut. Computes the 1126 * expected maximum (!) @a brut amount that should be needed in the wallet to 1127 * transfer @a net amount to the target account. Note that STEFAN curves by 1128 * design over-estimate actual fees and a wallet may be able to achieve the 1129 * same @a net amount with less fees --- or if the available coins are 1130 * abnormal in structure, it may take more. 1131 * 1132 * @param keys exchange key data 1133 * @param net net amount (effective amount) 1134 * @param[out] brut gross amount (actual cost including fees) 1135 * @return #GNUNET_OK on success, #GNUNET_NO if the 1136 * resulting @a brut is zero (only if @a net was zero) 1137 */ 1138 enum GNUNET_GenericReturnValue 1139 TALER_EXCHANGE_keys_stefan_n2b ( 1140 const struct TALER_EXCHANGE_Keys *keys, 1141 const struct TALER_Amount *net, 1142 struct TALER_Amount *brut); 1143 1144 1145 /** 1146 * Round brutto or netto value computed via STEFAN 1147 * curve to decimal places commonly used at the exchange. 1148 * 1149 * @param keys exchange keys response data 1150 * @param[in,out] val value to round 1151 */ 1152 void 1153 TALER_EXCHANGE_keys_stefan_round ( 1154 const struct TALER_EXCHANGE_Keys *keys, 1155 struct TALER_Amount *val); 1156 1157 1158 /** 1159 * Test if the given @a pub is a the current signing key from the exchange 1160 * according to @a keys. 1161 * 1162 * @param keys the exchange's key set 1163 * @param pub claimed current online signing key for the exchange 1164 * @return #GNUNET_OK if @a pub is (according to /keys) a current signing key 1165 */ 1166 enum GNUNET_GenericReturnValue 1167 TALER_EXCHANGE_test_signing_key ( 1168 const struct TALER_EXCHANGE_Keys *keys, 1169 const struct TALER_ExchangePublicKeyP *pub); 1170 1171 1172 /** 1173 * Check if a wire transfer is allowed between 1174 * @a account if the exchange and @a payto_uri. 1175 * 1176 * @param account exchange account to check 1177 * @param check_credit true for credit (sending money 1178 * to the exchange), false for debit (receiving money 1179 * from the exchange) 1180 * @param payto_uri other bank account (merchant, customer) 1181 * @return 1182 * #GNUNET_YES if the exchange would allow this 1183 * #GNUNET_NO if this is not allowed 1184 * #GNUNET_SYSERR if data in @a account is malformed 1185 * or we experienced internal errors 1186 */ 1187 enum GNUNET_GenericReturnValue 1188 TALER_EXCHANGE_test_account_allowed ( 1189 const struct TALER_EXCHANGE_WireAccount *account, 1190 bool check_credit, 1191 const struct TALER_NormalizedPayto payto_uri); 1192 1193 1194 /** 1195 * Check if a wire transfer is allowed between the exchange 1196 * and an account identified by @a payto_uri. 1197 * 1198 * @param keys exchange /keys response to check against 1199 * @param check_credit true for credit (sending money 1200 * to the exchange), false for debit (receiving money 1201 * from the exchange) 1202 * @param payto_uri other bank account (merchant, customer) 1203 * @return 1204 * #GNUNET_YES if the exchange would allow this 1205 * #GNUNET_NO if this is not allowed 1206 * #GNUNET_SYSERR if data in @a account is malformed 1207 * or we experienced internal errors 1208 */ 1209 enum GNUNET_GenericReturnValue 1210 TALER_EXCHANGE_keys_test_account_allowed ( 1211 const struct TALER_EXCHANGE_Keys *keys, 1212 bool check_credit, 1213 const struct TALER_NormalizedPayto payto_uri); 1214 1215 1216 /** 1217 * Check the hard limits in @a keys for the given 1218 * @a event and lower @a limit to the lowest applicable 1219 * limit independent (!) of the timeframe. Useful 1220 * to determine the absolute transaction limit. 1221 * 1222 * @param keys exchange keys to evaluate 1223 * @param event trigger type to evaluate 1224 * @param[in,out] limit to lower to the minimum limit 1225 * that applies to @a event 1226 */ 1227 void 1228 TALER_EXCHANGE_keys_evaluate_hard_limits ( 1229 const struct TALER_EXCHANGE_Keys *keys, 1230 enum TALER_KYCLOGIC_KycTriggerEvent event, 1231 struct TALER_Amount *limit); 1232 1233 1234 /** 1235 * Check if a (soft) limit of zero applies for the 1236 * given @a event under @a keys. 1237 * 1238 * @param keys exchange keys to evaluate 1239 * @param event trigger type to evaluate 1240 * @return true if the operation is soft-limited and 1241 * thus KYC is required before the operation may be 1242 * accepted at the exchange 1243 */ 1244 bool 1245 TALER_EXCHANGE_keys_evaluate_zero_limits ( 1246 const struct TALER_EXCHANGE_Keys *keys, 1247 enum TALER_KYCLOGIC_KycTriggerEvent event); 1248 1249 1250 /** 1251 * Obtain the denomination key details from the exchange. 1252 * 1253 * @param keys the exchange's key set 1254 * @param pk public key of the denomination to lookup 1255 * @return details about the given denomination key, NULL if the key is not 1256 * found 1257 */ 1258 const struct TALER_EXCHANGE_DenomPublicKey * 1259 TALER_EXCHANGE_get_denomination_key ( 1260 const struct TALER_EXCHANGE_Keys *keys, 1261 const struct TALER_DenominationPublicKey *pk); 1262 1263 1264 /** 1265 * Obtain the global fee details from the exchange. 1266 * 1267 * @param keys the exchange's key set 1268 * @param ts time for when to fetch the fees 1269 * @return details about the fees, NULL if no fees are known at @a ts 1270 */ 1271 const struct TALER_EXCHANGE_GlobalFee * 1272 TALER_EXCHANGE_get_global_fee ( 1273 const struct TALER_EXCHANGE_Keys *keys, 1274 struct GNUNET_TIME_Timestamp ts); 1275 1276 1277 /** 1278 * Create a copy of a denomination public key. 1279 * 1280 * @param key key to copy 1281 * @returns a copy, must be freed with #TALER_EXCHANGE_destroy_denomination_key() 1282 * @deprecated 1283 */ 1284 struct TALER_EXCHANGE_DenomPublicKey * 1285 TALER_EXCHANGE_copy_denomination_key ( 1286 const struct TALER_EXCHANGE_DenomPublicKey *key); 1287 1288 1289 /** 1290 * Destroy a denomination public key. 1291 * Should only be called with keys created by #TALER_EXCHANGE_copy_denomination_key(). 1292 * 1293 * @param key key to destroy. 1294 * @deprecated 1295 */ 1296 void 1297 TALER_EXCHANGE_destroy_denomination_key ( 1298 struct TALER_EXCHANGE_DenomPublicKey *key); 1299 1300 1301 /** 1302 * Obtain the denomination key details from the exchange. 1303 * 1304 * @param keys the exchange's key set 1305 * @param hc hash of the public key of the denomination to lookup 1306 * @return details about the given denomination key 1307 */ 1308 const struct TALER_EXCHANGE_DenomPublicKey * 1309 TALER_EXCHANGE_get_denomination_key_by_hash ( 1310 const struct TALER_EXCHANGE_Keys *keys, 1311 const struct TALER_DenominationHashP *hc); 1312 1313 1314 /** 1315 * Obtain meta data about an exchange (online) signing 1316 * key. 1317 * 1318 * @param keys from where to obtain the meta data 1319 * @param exchange_pub public key to lookup 1320 * @return NULL on error (@a exchange_pub not known) 1321 */ 1322 const struct TALER_EXCHANGE_SigningPublicKey * 1323 TALER_EXCHANGE_get_signing_key_info ( 1324 const struct TALER_EXCHANGE_Keys *keys, 1325 const struct TALER_ExchangePublicKeyP *exchange_pub); 1326 1327 1328 /* ********************* wire helpers *********************** */ 1329 1330 1331 /** 1332 * Parse array of @a accounts of the exchange into @a was. 1333 * 1334 * @param master_pub master public key of the exchange, NULL to not verify signatures 1335 * @param accounts array of accounts to parse 1336 * @param[out] was where to write the result (already allocated) 1337 * @param was_length length of the @a was array, must match the length of @a accounts 1338 * @return #GNUNET_OK if parsing @a accounts succeeded 1339 */ 1340 enum GNUNET_GenericReturnValue 1341 TALER_EXCHANGE_parse_accounts ( 1342 const struct TALER_MasterPublicKeyP *master_pub, 1343 const json_t *accounts, 1344 unsigned int was_length, 1345 struct TALER_EXCHANGE_WireAccount was[static was_length]); 1346 1347 1348 /** 1349 * Free data within @a was, but not @a was itself. 1350 * 1351 * @param was array of wire account data 1352 * @param was_len length of the @a was array 1353 */ 1354 void 1355 TALER_EXCHANGE_free_accounts ( 1356 unsigned int was_len, 1357 struct TALER_EXCHANGE_WireAccount was[static was_len]); 1358 1359 #endif