taler-exchange-httpd_common_deposit.h (3575B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2022 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 taler-exchange-httpd_common_deposit.h 18 * @brief shared logic for handling deposited coins 19 * @author Christian Grothoff 20 */ 21 #ifndef TALER_EXCHANGE_HTTPD_COMMON_DEPOSIT_H 22 #define TALER_EXCHANGE_HTTPD_COMMON_DEPOSIT_H 23 24 #include <gnunet/gnunet_util_lib.h> 25 #include <gnunet/gnunet_json_lib.h> 26 #include <jansson.h> 27 #include <microhttpd.h> 28 #include "taler/taler_json_lib.h" 29 #include "taler/taler_mhd_lib.h" 30 31 32 /** 33 * Information about an individual coin being deposited. 34 */ 35 struct TEH_PurseDepositedCoin 36 { 37 /** 38 * Public information about the coin. 39 */ 40 struct TALER_CoinPublicInfo cpi; 41 42 /** 43 * Signature affirming spending the coin. 44 */ 45 struct TALER_CoinSpendSignatureP coin_sig; 46 47 /** 48 * Amount to be put into the purse from this coin. 49 */ 50 struct TALER_Amount amount; 51 52 /** 53 * Deposit fee applicable for this coin. 54 */ 55 struct TALER_Amount deposit_fee; 56 57 /** 58 * Amount to be put into the purse from this coin. 59 */ 60 struct TALER_Amount amount_minus_fee; 61 62 /** 63 * Age attestation provided, set if @e no_attest is false. 64 */ 65 struct TALER_AgeAttestationP attest; 66 67 /** 68 * Age commitment provided, set if @e cpi.no_age_commitment is false. 69 */ 70 struct TALER_AgeCommitment age_commitment; 71 72 /** 73 * ID of the coin in known_coins. 74 */ 75 uint64_t known_coin_id; 76 77 /** 78 * True if @e attest was not provided. 79 */ 80 bool no_attest; 81 82 }; 83 84 85 /** 86 * Parse a coin and check signature of the coin and the denomination 87 * signature over the coin. 88 * 89 * @param[in,out] connection our HTTP connection 90 * @param[out] coin coin to initialize 91 * @param jcoin coin to parse 92 * @return #GNUNET_OK on success, #GNUNET_NO if an error was returned, 93 * #GNUNET_SYSERR on failure and no error could be returned 94 */ 95 enum GNUNET_GenericReturnValue 96 TEH_common_purse_deposit_parse_coin ( 97 struct MHD_Connection *connection, 98 struct TEH_PurseDepositedCoin *coin, 99 const json_t *jcoin); 100 101 102 /** 103 * Check that the deposited @a coin is valid for @a purse_pub 104 * and has a valid age commitment for @a min_age. 105 * 106 * @param[in,out] connection our HTTP connection 107 * @param coin the coin to evaluate 108 * @param purse_pub public key of the purse the coin was deposited into 109 * @param min_age minimum age restriction expected for this purse 110 * @return #GNUNET_OK on success, #GNUNET_NO if an error was returned, 111 * #GNUNET_SYSERR on failure and no error could be returned 112 */ 113 enum GNUNET_GenericReturnValue 114 TEH_common_deposit_check_purse_deposit ( 115 struct MHD_Connection *connection, 116 const struct TEH_PurseDepositedCoin *coin, 117 const struct TALER_PurseContractPublicKeyP *purse_pub, 118 uint32_t min_age); 119 120 121 /** 122 * Release data structures of @a coin. Note that 123 * @a coin itself is NOT freed. 124 * 125 * @param[in] coin information to release 126 */ 127 void 128 TEH_common_purse_deposit_free_coin (struct TEH_PurseDepositedCoin *coin); 129 130 #endif