get-keys.h (34388B)
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/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/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 *prepared_transfer_url; 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 * Array of the exchange's online signing keys. 534 */ 535 struct TALER_EXCHANGE_SigningPublicKey *sign_keys; 536 537 /** 538 * Array of the exchange's denomination keys. 539 */ 540 struct TALER_EXCHANGE_DenomPublicKey *denom_keys; 541 542 /** 543 * Array of the keys of the auditors of the exchange. 544 */ 545 struct TALER_EXCHANGE_AuditorInformation *auditors; 546 547 /** 548 * Array with the global fees of the exchange. 549 */ 550 struct TALER_EXCHANGE_GlobalFee *global_fees; 551 552 /** 553 * Supported Taler protocol version by the exchange. 554 * String in the format current:revision:age using the 555 * semantics of GNU libtool. See 556 * https://www.gnu.org/software/libtool/manual/html_node/Versioning.html#Versioning 557 */ 558 char *version; 559 560 /** 561 * Supported currency of the exchange. 562 */ 563 char *currency; 564 565 /** 566 * What is the base URL of the exchange that returned 567 * these keys? 568 */ 569 char *exchange_url; 570 571 /** 572 * Asset type used by the exchange. Typical values 573 * are "fiat" or "crypto" or "regional" or "stock". 574 * Wallets should adjust their UI/UX based on this 575 * value. 576 */ 577 char *asset_type; 578 579 /** 580 * Shopping URL where users may find shops that accept 581 * digital cash from this exchange. NULL if not configured. 582 * @since protocol v21. 583 */ 584 char *shopping_url; 585 586 /** 587 * Bank-specific compliance language hint for wallets. 588 * NULL if not configured. 589 * @since protocol v24. 590 */ 591 char *bank_compliance_language; 592 593 /** 594 * Array of amounts a wallet is allowed to hold from 595 * this exchange before it must undergo further KYC checks. 596 * Length is given in @e wblwk_length. 597 */ 598 struct TALER_Amount *wallet_balance_limit_without_kyc; 599 600 /** 601 * Smallest amount that can likely be transferred to the exchange, 602 * used as the default for KYC authentication wire transfers. 603 * Only valid when @e tiny_amount_available is true. 604 * @since protocol v21. 605 */ 606 struct TALER_Amount tiny_amount; 607 608 /** 609 * Array of partner exchanges for wallet-to-wallet transfers. 610 * Length is given in @e num_wad_partners. 611 */ 612 struct TALER_EXCHANGE_WadPartner *wad_partners; 613 614 /** 615 * Array of accounts of the exchange. 616 */ 617 struct TALER_EXCHANGE_WireAccount *accounts; 618 619 /** 620 * Array of hard limits that apply at this exchange. 621 * All limits in this array will be hard limits. 622 */ 623 struct TALER_EXCHANGE_AccountLimit *hard_limits; 624 625 /** 626 * Array of operations with a default soft limit of zero 627 * that apply at this exchange. 628 * Clients should begin a KYC process before attempting 629 * these operations. 630 */ 631 struct TALER_EXCHANGE_ZeroLimitedOperation *zero_limits; 632 633 /** 634 * Array of wire fees by wire method. 635 */ 636 struct TALER_EXCHANGE_WireFeesByMethod *fees; 637 638 /** 639 * Currency rendering specification for this exchange. 640 */ 641 struct TALER_CurrencySpecification cspec; 642 643 /** 644 * How long after a reserve went idle will the exchange close it? 645 * This is an approximate number, not cryptographically signed by 646 * the exchange (advisory-only, may change anytime). 647 */ 648 struct GNUNET_TIME_Relative reserve_closing_delay; 649 650 /** 651 * Timestamp indicating the /keys generation. 652 */ 653 struct GNUNET_TIME_Timestamp list_issue_date; 654 655 /** 656 * When does this keys data expire? 657 */ 658 struct GNUNET_TIME_Timestamp key_data_expiration; 659 660 /** 661 * Timestamp indicating the creation time of the last 662 * denomination key in /keys. 663 * Used to fetch /keys incrementally. 664 */ 665 struct GNUNET_TIME_Timestamp last_denom_issue_date; 666 667 /** 668 * If age restriction is enabled on the exchange, we get an non-zero age_mask 669 */ 670 struct TALER_AgeMask age_mask; 671 672 /** 673 * Absolute STEFAN parameter. 674 */ 675 struct TALER_Amount stefan_abs; 676 677 /** 678 * Logarithmic STEFAN parameter. 679 */ 680 struct TALER_Amount stefan_log; 681 682 /** 683 * Linear STEFAN parameter. 684 */ 685 double stefan_lin; 686 687 /** 688 * Length of @e accounts array. 689 */ 690 unsigned int accounts_len; 691 692 /** 693 * Length of @e fees array. 694 */ 695 unsigned int fees_len; 696 697 /** 698 * Length of @e hard_limits array. 699 */ 700 unsigned int hard_limits_length; 701 702 /** 703 * Length of @e zero_limits array. 704 */ 705 unsigned int zero_limits_length; 706 707 /** 708 * Length of the @e wallet_balance_limit_without_kyc 709 * array. 710 */ 711 unsigned int wblwk_length; 712 713 /** 714 * Length of the @e global_fees array. 715 */ 716 unsigned int num_global_fees; 717 718 /** 719 * Length of the @e sign_keys array (number of valid entries). 720 */ 721 unsigned int num_sign_keys; 722 723 /** 724 * Length of the @e denom_keys array. 725 */ 726 unsigned int num_denom_keys; 727 728 /** 729 * Length of the @e auditors array. 730 */ 731 unsigned int num_auditors; 732 733 /** 734 * Actual length of the @e auditors array (size of allocation). 735 */ 736 unsigned int auditors_size; 737 738 /** 739 * Actual length of the @e denom_keys array (size of allocation). 740 */ 741 unsigned int denom_keys_size; 742 743 /** 744 * Reference counter for this structure. 745 * Freed when it reaches 0. 746 */ 747 unsigned int rc; 748 749 /** 750 * Length of the @e wad_partners array. 751 */ 752 unsigned int num_wad_partners; 753 754 /** 755 * Set to true if KYC is enabled at this exchange. 756 */ 757 bool kyc_enabled; 758 759 /** 760 * Set to true to signal to the merchant backend that 761 * it should swap the terms-of-service and KYC auth 762 * authentication steps in the user experience. 763 * Defaults to false if not provided by the exchange. 764 */ 765 bool kyc_swap_tos_acceptance; 766 767 /** 768 * Set to true if the @e tiny_amount field is valid. 769 * @since protocol v21. 770 */ 771 bool tiny_amount_available; 772 773 /** 774 * Set to true if wallets should disable the direct deposit 775 * feature. Mainly used for regional/event currency deployments. 776 * @since protocol v30. 777 */ 778 bool disable_direct_deposit; 779 780 /** 781 * How long should a P2P push payment be valid by default. 782 */ 783 struct GNUNET_TIME_Relative default_p2p_push_expiration; 784 785 786 }; 787 788 789 /** 790 * How compatible are the protocol version of the exchange and this 791 * client? The bits (1,2,4) can be used to test if the exchange's 792 * version is incompatible, older or newer respectively. 793 */ 794 enum TALER_EXCHANGE_VersionCompatibility 795 { 796 797 /** 798 * The exchange runs exactly the same protocol version. 799 */ 800 TALER_EXCHANGE_VC_MATCH = 0, 801 802 /** 803 * The exchange is too old or too new to be compatible with this 804 * implementation (bit) 805 */ 806 TALER_EXCHANGE_VC_INCOMPATIBLE = 1, 807 808 /** 809 * The exchange is older than this implementation (bit) 810 */ 811 TALER_EXCHANGE_VC_OLDER = 2, 812 813 /** 814 * The exchange is too old to be compatible with 815 * this implementation. 816 */ 817 TALER_EXCHANGE_VC_INCOMPATIBLE_OUTDATED 818 = TALER_EXCHANGE_VC_INCOMPATIBLE 819 | TALER_EXCHANGE_VC_OLDER, 820 821 /** 822 * The exchange is more recent than this implementation (bit). 823 */ 824 TALER_EXCHANGE_VC_NEWER = 4, 825 826 /** 827 * The exchange is too recent for this implementation. 828 */ 829 TALER_EXCHANGE_VC_INCOMPATIBLE_NEWER 830 = TALER_EXCHANGE_VC_INCOMPATIBLE 831 | TALER_EXCHANGE_VC_NEWER, 832 833 /** 834 * We could not even parse the version data. 835 */ 836 TALER_EXCHANGE_VC_PROTOCOL_ERROR = 8 837 838 }; 839 840 841 /** 842 * Response from /keys. 843 */ 844 struct TALER_EXCHANGE_KeysResponse 845 { 846 /** 847 * HTTP response data 848 */ 849 struct TALER_EXCHANGE_HttpResponse hr; 850 851 /** 852 * Details depending on the HTTP status code. 853 */ 854 union 855 { 856 857 /** 858 * Details on #MHD_HTTP_OK. 859 */ 860 struct 861 { 862 /** 863 * Information about the various keys used by the exchange. 864 */ 865 const struct TALER_EXCHANGE_Keys *keys; 866 867 /** 868 * Protocol compatibility information 869 */ 870 enum TALER_EXCHANGE_VersionCompatibility compat; 871 } ok; 872 } details; 873 874 }; 875 876 877 /** 878 * Possible options we can set for the GET /keys request. 879 */ 880 enum TALER_EXCHANGE_GetKeysOption 881 { 882 /** 883 * End of list of options. 884 */ 885 TALER_EXCHANGE_GET_KEYS_OPTION_END = 0, 886 887 /** 888 * Perform incremental fetch using the given previous keys object. 889 * Defaults to NULL (no incremental fetch). 890 */ 891 TALER_EXCHANGE_GET_KEYS_OPTION_LAST_KEYS 892 893 }; 894 895 896 /** 897 * Value for an option for the GET /keys request. 898 */ 899 struct TALER_EXCHANGE_GetKeysOptionValue 900 { 901 /** 902 * Type of the option being set. 903 */ 904 enum TALER_EXCHANGE_GetKeysOption option; 905 906 /** 907 * Specific option value. 908 */ 909 union 910 { 911 /** 912 * Value if @e option is TALER_EXCHANGE_GET_KEYS_OPTION_LAST_KEYS. 913 * Previous keys object for incremental fetch. 914 */ 915 struct TALER_EXCHANGE_Keys *last_keys; 916 917 } details; 918 919 }; 920 921 922 /** 923 * @brief Handle for a GET /keys request. 924 */ 925 struct TALER_EXCHANGE_GetKeysHandle; 926 927 928 /** 929 * Terminate the list of options. 930 * 931 * @return the terminating object of struct TALER_EXCHANGE_GetKeysOptionValue 932 */ 933 #define TALER_EXCHANGE_get_keys_option_end_() \ 934 (const struct TALER_EXCHANGE_GetKeysOptionValue) \ 935 { \ 936 .option = TALER_EXCHANGE_GET_KEYS_OPTION_END \ 937 } 938 939 /** 940 * Set previous keys for incremental fetch. 941 * 942 * @param k previous keys object (may be NULL to request full fetch) 943 * @return representation of the option as a struct TALER_EXCHANGE_GetKeysOptionValue 944 */ 945 #define TALER_EXCHANGE_get_keys_option_last_keys(k) \ 946 (const struct TALER_EXCHANGE_GetKeysOptionValue) \ 947 { \ 948 .option = TALER_EXCHANGE_GET_KEYS_OPTION_LAST_KEYS, \ 949 .details.last_keys = (k) \ 950 } 951 952 953 #ifndef TALER_EXCHANGE_GET_KEYS_RESULT_CLOSURE 954 /** 955 * Type of the closure used by 956 * the #TALER_EXCHANGE_GetKeysCallback. 957 */ 958 #define TALER_EXCHANGE_GET_KEYS_RESULT_CLOSURE void 959 #endif /* TALER_EXCHANGE_GET_KEYS_RESULT_CLOSURE */ 960 961 /** 962 * Function called with information about who is auditing 963 * a particular exchange and what keys the exchange is using. 964 * The ownership over the @a keys object is passed to 965 * the callee, thus it is given explicitly and not 966 * (only) via @a kr. 967 * 968 * @param cls closure 969 * @param kr response from /keys 970 * @param[in] keys keys object passed to callback with 971 * reference counter of 1. Must be freed by callee 972 * using #TALER_EXCHANGE_keys_decref(). NULL on failure. 973 */ 974 typedef void 975 (*TALER_EXCHANGE_GetKeysCallback) ( 976 TALER_EXCHANGE_GET_KEYS_RESULT_CLOSURE *cls, 977 const struct TALER_EXCHANGE_KeysResponse *kr, 978 struct TALER_EXCHANGE_Keys *keys); 979 980 981 /** 982 * Set up GET /keys operation. 983 * Note that you must explicitly start the operation after 984 * possibly setting options. 985 * 986 * @param ctx the context 987 * @param url HTTP base URL for the exchange 988 * @return handle to operation, NULL on error 989 */ 990 struct TALER_EXCHANGE_GetKeysHandle * 991 TALER_EXCHANGE_get_keys_create ( 992 struct GNUNET_CURL_Context *ctx, 993 const char *url); 994 995 996 /** 997 * Set the requested options for the operation. 998 * 999 * If any option fails, other options may or may not be applied. 1000 * 1001 * @param gkh the request to set the options for 1002 * @param num_options length of the @a options array 1003 * @param options an array of options 1004 * @return #GNUNET_OK on success, 1005 * #GNUNET_NO on failure, 1006 * #GNUNET_SYSERR on internal error 1007 */ 1008 enum GNUNET_GenericReturnValue 1009 TALER_EXCHANGE_get_keys_set_options_ ( 1010 struct TALER_EXCHANGE_GetKeysHandle *gkh, 1011 unsigned int num_options, 1012 const struct TALER_EXCHANGE_GetKeysOptionValue options[]); 1013 1014 1015 /** 1016 * Set the requested options for the operation. 1017 * 1018 * If any option fails, other options may or may not be applied. 1019 * 1020 * It should be used with helpers that create required options, for example: 1021 * 1022 * TALER_EXCHANGE_get_keys_set_options ( 1023 * gkh, 1024 * TALER_EXCHANGE_get_keys_option_last_keys (prev_keys)); 1025 * 1026 * @param gkh the request to set the options for 1027 * @param ... the list of options, each created by a 1028 * TALER_EXCHANGE_get_keys_option_NAME(VALUE) helper 1029 * @return #GNUNET_OK on success, 1030 * #GNUNET_NO on failure, 1031 * #GNUNET_SYSERR on internal error 1032 */ 1033 #define TALER_EXCHANGE_get_keys_set_options(gkh,...) \ 1034 TALER_EXCHANGE_get_keys_set_options_ ( \ 1035 gkh, \ 1036 TALER_EXCHANGE_COMMON_OPTIONS_ARRAY_MAX_SIZE, \ 1037 ((const struct TALER_EXCHANGE_GetKeysOptionValue[]) \ 1038 {__VA_ARGS__, TALER_EXCHANGE_get_keys_option_end_ () } \ 1039 )) 1040 1041 1042 /** 1043 * Start GET /keys operation. 1044 * 1045 * @param[in,out] gkh operation to start 1046 * @param cert_cb function to call with the exchange's certification information 1047 * @param cert_cb_cls closure for @a cert_cb 1048 * @return status code, #TALER_EC_NONE on success 1049 */ 1050 enum TALER_ErrorCode 1051 TALER_EXCHANGE_get_keys_start ( 1052 struct TALER_EXCHANGE_GetKeysHandle *gkh, 1053 TALER_EXCHANGE_GetKeysCallback cert_cb, 1054 TALER_EXCHANGE_GET_KEYS_RESULT_CLOSURE *cert_cb_cls); 1055 1056 1057 /** 1058 * Serialize the latest data from @a keys to be persisted 1059 * (for example, to be used as @a last_keys later). 1060 * 1061 * @param kd the key data to serialize 1062 * @return NULL on error; otherwise JSON object owned by the caller 1063 */ 1064 json_t * 1065 TALER_EXCHANGE_keys_to_json (const struct TALER_EXCHANGE_Keys *kd); 1066 1067 1068 /** 1069 * Deserialize keys data stored in @a j. 1070 * 1071 * @param j JSON keys data previously returned from #TALER_EXCHANGE_keys_to_json() 1072 * @return NULL on error (i.e. invalid JSON); otherwise 1073 * keys object with reference counter 1 owned by the caller 1074 */ 1075 struct TALER_EXCHANGE_Keys * 1076 TALER_EXCHANGE_keys_from_json (const json_t *j); 1077 1078 1079 /** 1080 * Cancel GET /keys operation. 1081 * 1082 * @param[in] gkh the GET /keys handle 1083 */ 1084 void 1085 TALER_EXCHANGE_get_keys_cancel (struct TALER_EXCHANGE_GetKeysHandle *gkh); 1086 1087 1088 /** 1089 * Increment reference counter for @a keys 1090 * 1091 * @param[in,out] keys object to increment reference counter for 1092 * @return keys, with incremented reference counter 1093 */ 1094 struct TALER_EXCHANGE_Keys * 1095 TALER_EXCHANGE_keys_incref (struct TALER_EXCHANGE_Keys *keys); 1096 1097 1098 /** 1099 * Decrement reference counter for @a keys. 1100 * Frees @a keys if reference counter becomes zero. 1101 * 1102 * @param[in,out] keys object to decrement reference counter for 1103 */ 1104 void 1105 TALER_EXCHANGE_keys_decref (struct TALER_EXCHANGE_Keys *keys); 1106 1107 1108 /** 1109 * Use STEFAN curve in @a keys to convert @a brut to @a net. Computes the 1110 * expected minimum (!) @a net amount that should for sure arrive in the 1111 * target amount at cost of @a brut to the wallet. Note that STEFAN curves by 1112 * design over-estimate actual fees and a wallet may be able to achieve the 1113 * same @a net amount with less fees --- or if the available coins are 1114 * abnormal in structure, it may take more. 1115 * 1116 * @param keys exchange key data 1117 * @param brut gross amount (actual cost including fees) 1118 * @param[out] net net amount (effective amount) 1119 * @return #GNUNET_OK on success, #GNUNET_NO if the 1120 * resulting @a net is zero (or lower) 1121 */ 1122 enum GNUNET_GenericReturnValue 1123 TALER_EXCHANGE_keys_stefan_b2n ( 1124 const struct TALER_EXCHANGE_Keys *keys, 1125 const struct TALER_Amount *brut, 1126 struct TALER_Amount *net); 1127 1128 1129 /** 1130 * Use STEFAN curve in @a keys to convert @a net to @a brut. Computes the 1131 * expected maximum (!) @a brut amount that should be needed in the wallet to 1132 * transfer @a net amount to the target account. Note that STEFAN curves by 1133 * design over-estimate actual fees and a wallet may be able to achieve the 1134 * same @a net amount with less fees --- or if the available coins are 1135 * abnormal in structure, it may take more. 1136 * 1137 * @param keys exchange key data 1138 * @param net net amount (effective amount) 1139 * @param[out] brut gross amount (actual cost including fees) 1140 * @return #GNUNET_OK on success, #GNUNET_NO if the 1141 * resulting @a brut is zero (only if @a net was zero) 1142 */ 1143 enum GNUNET_GenericReturnValue 1144 TALER_EXCHANGE_keys_stefan_n2b ( 1145 const struct TALER_EXCHANGE_Keys *keys, 1146 const struct TALER_Amount *net, 1147 struct TALER_Amount *brut); 1148 1149 1150 /** 1151 * Round brutto or netto value computed via STEFAN 1152 * curve to decimal places commonly used at the exchange. 1153 * 1154 * @param keys exchange keys response data 1155 * @param[in,out] val value to round 1156 */ 1157 void 1158 TALER_EXCHANGE_keys_stefan_round ( 1159 const struct TALER_EXCHANGE_Keys *keys, 1160 struct TALER_Amount *val); 1161 1162 1163 /** 1164 * Test if the given @a pub is a the current signing key from the exchange 1165 * according to @a keys. 1166 * 1167 * @param keys the exchange's key set 1168 * @param pub claimed current online signing key for the exchange 1169 * @return #GNUNET_OK if @a pub is (according to /keys) a current signing key 1170 */ 1171 enum GNUNET_GenericReturnValue 1172 TALER_EXCHANGE_test_signing_key ( 1173 const struct TALER_EXCHANGE_Keys *keys, 1174 const struct TALER_ExchangePublicKeyP *pub); 1175 1176 1177 /** 1178 * Check if a wire transfer is allowed between 1179 * @a account if the exchange and @a payto_uri. 1180 * 1181 * @param account exchange account to check 1182 * @param check_credit true for credit (sending money 1183 * to the exchange), false for debit (receiving money 1184 * from the exchange) 1185 * @param payto_uri other bank account (merchant, customer) 1186 * @return 1187 * #GNUNET_YES if the exchange would allow this 1188 * #GNUNET_NO if this is not allowed 1189 * #GNUNET_SYSERR if data in @a account is malformed 1190 * or we experienced internal errors 1191 */ 1192 enum GNUNET_GenericReturnValue 1193 TALER_EXCHANGE_test_account_allowed ( 1194 const struct TALER_EXCHANGE_WireAccount *account, 1195 bool check_credit, 1196 const struct TALER_NormalizedPayto payto_uri); 1197 1198 1199 /** 1200 * Check if a wire transfer is allowed between the exchange 1201 * and an account identified by @a payto_uri. 1202 * 1203 * @param keys exchange /keys response to check against 1204 * @param check_credit true for credit (sending money 1205 * to the exchange), false for debit (receiving money 1206 * from the exchange) 1207 * @param payto_uri other bank account (merchant, customer) 1208 * @return 1209 * #GNUNET_YES if the exchange would allow this 1210 * #GNUNET_NO if this is not allowed 1211 * #GNUNET_SYSERR if data in @a account is malformed 1212 * or we experienced internal errors 1213 */ 1214 enum GNUNET_GenericReturnValue 1215 TALER_EXCHANGE_keys_test_account_allowed ( 1216 const struct TALER_EXCHANGE_Keys *keys, 1217 bool check_credit, 1218 const struct TALER_NormalizedPayto payto_uri); 1219 1220 1221 /** 1222 * Check the hard limits in @a keys for the given 1223 * @a event and lower @a limit to the lowest applicable 1224 * limit independent (!) of the timeframe. Useful 1225 * to determine the absolute transaction limit. 1226 * 1227 * @param keys exchange keys to evaluate 1228 * @param event trigger type to evaluate 1229 * @param[in,out] limit to lower to the minimum limit 1230 * that applies to @a event 1231 */ 1232 void 1233 TALER_EXCHANGE_keys_evaluate_hard_limits ( 1234 const struct TALER_EXCHANGE_Keys *keys, 1235 enum TALER_KYCLOGIC_KycTriggerEvent event, 1236 struct TALER_Amount *limit); 1237 1238 1239 /** 1240 * Check if a (soft) limit of zero applies for the 1241 * given @a event under @a keys. 1242 * 1243 * @param keys exchange keys to evaluate 1244 * @param event trigger type to evaluate 1245 * @return true if the operation is soft-limited and 1246 * thus KYC is required before the operation may be 1247 * accepted at the exchange 1248 */ 1249 bool 1250 TALER_EXCHANGE_keys_evaluate_zero_limits ( 1251 const struct TALER_EXCHANGE_Keys *keys, 1252 enum TALER_KYCLOGIC_KycTriggerEvent event); 1253 1254 1255 /** 1256 * Obtain the denomination key details from the exchange. 1257 * 1258 * @param keys the exchange's key set 1259 * @param pk public key of the denomination to lookup 1260 * @return details about the given denomination key, NULL if the key is not 1261 * found 1262 */ 1263 const struct TALER_EXCHANGE_DenomPublicKey * 1264 TALER_EXCHANGE_get_denomination_key ( 1265 const struct TALER_EXCHANGE_Keys *keys, 1266 const struct TALER_DenominationPublicKey *pk); 1267 1268 1269 /** 1270 * Obtain the global fee details from the exchange. 1271 * 1272 * @param keys the exchange's key set 1273 * @param ts time for when to fetch the fees 1274 * @return details about the fees, NULL if no fees are known at @a ts 1275 */ 1276 const struct TALER_EXCHANGE_GlobalFee * 1277 TALER_EXCHANGE_get_global_fee ( 1278 const struct TALER_EXCHANGE_Keys *keys, 1279 struct GNUNET_TIME_Timestamp ts); 1280 1281 1282 /** 1283 * Create a copy of a denomination public key. 1284 * 1285 * @param key key to copy 1286 * @returns a copy, must be freed with #TALER_EXCHANGE_destroy_denomination_key() 1287 * @deprecated 1288 */ 1289 struct TALER_EXCHANGE_DenomPublicKey * 1290 TALER_EXCHANGE_copy_denomination_key ( 1291 const struct TALER_EXCHANGE_DenomPublicKey *key); 1292 1293 1294 /** 1295 * Destroy a denomination public key. 1296 * Should only be called with keys created by #TALER_EXCHANGE_copy_denomination_key(). 1297 * 1298 * @param key key to destroy. 1299 * @deprecated 1300 */ 1301 void 1302 TALER_EXCHANGE_destroy_denomination_key ( 1303 struct TALER_EXCHANGE_DenomPublicKey *key); 1304 1305 1306 /** 1307 * Obtain the denomination key details from the exchange. 1308 * 1309 * @param keys the exchange's key set 1310 * @param hc hash of the public key of the denomination to lookup 1311 * @return details about the given denomination key 1312 */ 1313 const struct TALER_EXCHANGE_DenomPublicKey * 1314 TALER_EXCHANGE_get_denomination_key_by_hash ( 1315 const struct TALER_EXCHANGE_Keys *keys, 1316 const struct TALER_DenominationHashP *hc); 1317 1318 1319 /** 1320 * Obtain meta data about an exchange (online) signing 1321 * key. 1322 * 1323 * @param keys from where to obtain the meta data 1324 * @param exchange_pub public key to lookup 1325 * @return NULL on error (@a exchange_pub not known) 1326 */ 1327 const struct TALER_EXCHANGE_SigningPublicKey * 1328 TALER_EXCHANGE_get_signing_key_info ( 1329 const struct TALER_EXCHANGE_Keys *keys, 1330 const struct TALER_ExchangePublicKeyP *exchange_pub); 1331 1332 1333 /* ********************* wire helpers *********************** */ 1334 1335 1336 /** 1337 * Parse array of @a accounts of the exchange into @a was. 1338 * 1339 * @param master_pub master public key of the exchange, NULL to not verify signatures 1340 * @param accounts array of accounts to parse 1341 * @param[out] was where to write the result (already allocated) 1342 * @param was_length length of the @a was array, must match the length of @a accounts 1343 * @return #GNUNET_OK if parsing @a accounts succeeded 1344 */ 1345 enum GNUNET_GenericReturnValue 1346 TALER_EXCHANGE_parse_accounts ( 1347 const struct TALER_MasterPublicKeyP *master_pub, 1348 const json_t *accounts, 1349 unsigned int was_length, 1350 struct TALER_EXCHANGE_WireAccount was[static was_length]); 1351 1352 1353 /** 1354 * Free data within @a was, but not @a was itself. 1355 * 1356 * @param was array of wire account data 1357 * @param was_len length of the @a was array 1358 */ 1359 void 1360 TALER_EXCHANGE_free_accounts ( 1361 unsigned int was_len, 1362 struct TALER_EXCHANGE_WireAccount was[static was_len]); 1363 1364 #endif