exchange_api_refresh_common.h (6340B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2015-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 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 General Public License for more details. 12 13 You should have received a copy of the GNU General Public License along with 14 TALER; see the file COPYING. If not, see 15 <http://www.gnu.org/licenses/> 16 */ 17 /** 18 * @file lib/exchange_api_refresh_common.h 19 * @brief shared (serialization) logic for refresh protocol 20 * @author Christian Grothoff 21 */ 22 #ifndef REFRESH_COMMON_H 23 #define REFRESH_COMMON_H 24 #include <jansson.h> 25 #include "taler/taler_json_lib.h" 26 #include "taler/taler_exchange_service.h" /* UNNECESSARY? */ 27 #include "taler/taler_signatures.h" /* UNNECESSARY? */ 28 29 30 /** 31 * Information about a coin we are melting. 32 */ 33 struct MeltedCoin 34 { 35 /** 36 * Private key of the coin. 37 */ 38 struct TALER_CoinSpendPrivateKeyP coin_priv; 39 40 /** 41 * Amount this coin contributes to the melt, including fee. 42 */ 43 struct TALER_Amount melt_amount_with_fee; 44 45 /** 46 * The applicable fee for melting a coin of this denomination 47 */ 48 struct TALER_Amount fee_melt; 49 50 /** 51 * The original value of the coin. 52 */ 53 struct TALER_Amount original_value; 54 55 /** 56 * The original age commitment, its proof and its hash. MUST be NULL if no 57 * age commitment was set. 58 */ 59 const struct TALER_AgeCommitmentProof *age_commitment_proof; 60 const struct TALER_AgeCommitmentHashP *h_age_commitment; 61 62 /** 63 * Timestamp indicating when coins of this denomination become invalid. 64 */ 65 struct GNUNET_TIME_Timestamp expire_deposit; 66 67 /** 68 * Denomination key of the original coin. 69 */ 70 struct TALER_DenominationPublicKey pub_key; 71 72 /** 73 * Exchange's signature over the coin. 74 */ 75 struct TALER_DenominationSignature sig; 76 77 }; 78 79 80 /** 81 * Data we keep for each fresh coin created in the 82 * melt process. 83 */ 84 struct FreshCoinData 85 { 86 /** 87 * Denomination public key of the coin. 88 */ 89 struct TALER_DenominationPublicKey fresh_pk; 90 91 /** 92 * Array of planchet secrets for the coins, depending 93 * on the cut-and-choose. 94 */ 95 struct TALER_PlanchetMasterSecretP ps[TALER_CNC_KAPPA]; 96 97 /** 98 * Private key of the coin. 99 */ 100 struct TALER_CoinSpendPrivateKeyP coin_priv; 101 102 /** 103 * Arrays of age commitments and proofs to be created, one for each 104 * cut-and-choose dimension. NULL if age restriction is not applicable. 105 */ 106 struct TALER_AgeCommitmentProof *age_commitment_proofs[TALER_CNC_KAPPA]; 107 108 /** 109 * Blinding key secrets for the coins, depending on the 110 * cut-and-choose. 111 */ 112 union GNUNET_CRYPTO_BlindingSecretP bks[TALER_CNC_KAPPA]; 113 114 }; 115 116 117 /** 118 * Melt data in non-serialized format for convenient processing. 119 */ 120 struct MeltData 121 { 122 123 /** 124 * Hash over the committed data during refresh operation. 125 */ 126 struct TALER_RefreshCommitmentP rc; 127 128 /** 129 * Version of the refresh commitment @e rc. 130 */ 131 enum TALER_RefreshCommitmentVersion rc_version; 132 133 /** 134 * Information about the melted coin. 135 */ 136 struct MeltedCoin melted_coin; 137 138 /** 139 * Number of coins we are creating 140 */ 141 uint16_t num_fresh_coins; 142 143 /** 144 * If true, no blinding seed is used in the melt request 145 */ 146 bool no_blinding_seed; 147 148 /** 149 * The seed for blinding, derived from the refresh master secret; 150 */ 151 struct TALER_BlindingMasterSeedP blinding_seed; 152 153 /** 154 * The master seed from which we derive the kappa nonces for 155 * for signing with the @e melted_coin. 156 * The seed itself is derived from the refresh master secret; 157 */ 158 struct TALER_PublicRefreshMasterSeedP refresh_seed; 159 160 /** 161 * The tuple of kappa batch seeds, derived from the @a refresh_seed 162 * and the coin's private key. 163 */ 164 struct TALER_KappaPrivateRefreshBatchSeedsP kappa_batch_seeds; 165 166 /** 167 * Array of length @e num_fresh_coins with information 168 * about each fresh coin. 169 */ 170 struct FreshCoinData *fcds; 171 172 /** 173 * Array of @e num_fresh_coins denominations of the fresh coins. 174 */ 175 const struct TALER_DenominationPublicKey **denom_pubs; 176 177 /** 178 * Array of @e num_fresh_coins of hashes of the public key of the denominations. 179 */ 180 struct TALER_DenominationHashP *denoms_h; 181 182 /** 183 * kappa many arrays fo @e num_fresh_coins transfer public keys that are 184 * derived from the @e kappa_batch_seeds and the private key of the coin. 185 * This will be sent to the exchange during the melt request. 186 */ 187 struct TALER_TransferPublicKeyP *kappa_transfer_pubs[TALER_CNC_KAPPA]; 188 189 /** 190 * Blinded planchets of the fresh coins, depending on the cut-and-choose. 191 * Array of length @e num_fresh_coins. 192 */ 193 struct TALER_BlindedPlanchet *kappa_blinded_planchets[TALER_CNC_KAPPA]; 194 }; 195 196 /** 197 * Compute the melt data from the refresh data and secret 198 * for v27 of the protocol. 199 * 200 * @param rms public seed of the refresh-reveal operation 201 * @param rd refresh data with the characteristics of the operation 202 * @param blinding_seed seed for blinding in case of CS denominations, can be NULL 203 * @param alg_values contributions from the exchange into the melt 204 * @param rc_version version of the refresh commitment to compute, 205 * #TALER_REFRESH_COMMITMENT_VERSION_LEGACY_V27 is not supported 206 * @param[out] md where to write the derived melt data 207 */ 208 enum GNUNET_GenericReturnValue 209 TALER_EXCHANGE_get_melt_data ( 210 const struct TALER_PublicRefreshMasterSeedP *rms, 211 const struct TALER_EXCHANGE_MeltInput *rd, 212 const struct TALER_BlindingMasterSeedP *blinding_seed, 213 const struct TALER_ExchangeBlindingValues *alg_values, 214 enum TALER_RefreshCommitmentVersion rc_version, 215 struct MeltData *md); 216 217 218 /** 219 * Free all information associated with a melting session. Note 220 * that we allow the melting session to be only partially initialized, 221 * as we use this function also when freeing melt data that was not 222 * fully initialized. 223 * 224 * @param[in] md melting data to release, the pointer itself is NOT 225 * freed (as it is typically not allocated by itself) 226 */ 227 void 228 TALER_EXCHANGE_free_melt_data (struct MeltData *md); 229 230 #endif