diff --git a/src/binary_formats.ml b/src/binary_formats.ml index 9bb7f255..fd9cafe2 100644 --- a/src/binary_formats.ml +++ b/src/binary_formats.ml @@ -308,14 +308,96 @@ module Age_mask = struct record (fun mask -> { mask }) |+ field beint32 (fun t -> t.mask) |> sealr end -(* TODO not in doc - dummy impl - struct TALER_BlindingMasterSecretP blinding_seed; *) -module Blinding_master_secret_p = MAKE_H (Hash_code) +(* TODO TALER doc + should be in doc + found in src/include/taler/taler_amount_lib.h -(* TODO not in doc - struct TALER_Amount amount; *) -module Amount = MAKE_H (Hash_code) + why is the non-NBO version only used in TALER_WithdrawRequestPS? + GNUNET_PACKED? + + can be set to "invalid" if currency = all 0 *) +(* +/** + * @brief Number of characters (plus 1 for 0-termination) we use to + * represent currency names (i.e. EUR, USD, etc.). We use 8+4 for + * alignment in the `struct TALER_Amount`. The amount is typically an + * ISO 4217 currency code when an alphanumeric 3-digit code is used. + * For regional currencies, the first character should be a "*" followed + * by a region-specific name (i.e. "*BRETAGNEFR"). + */ +#define TALER_CURRENCY_LEN 12 + +struct TALER_AmountNBO +{ + /** + * Value in the main currency, in NBO. + */ + uint64_t value GNUNET_PACKED; + + /** + * Fraction (integer multiples of #TALER_AMOUNT_FRAC_BASE), in NBO. + */ + uint32_t fraction GNUNET_PACKED; + + /** + * Type of the currency being represented. + */ + char currency[TALER_CURRENCY_LEN]; +}; + +struct TALER_Amount +{ + /** + * Value (numerator of fraction) + */ + uint64_t value; + + /** + * Fraction (integer multiples of #TALER_AMOUNT_FRAC_BASE). + */ + uint32_t fraction; + + /** + * Currency string, left adjusted and padded with zeros. All zeros + * for "invalid" values. + */ + char currency[TALER_CURRENCY_LEN]; +}; +*) +let currency_len = 12 + +module Amount = struct + type t = { + value: int64; + fraction: int32; + currency: string; + } + + (* TODO BE here? *) + let bin = + let open Bin in + record (fun value fraction currency -> { value; fraction; currency }) + |+ field beint64 (fun t -> t.value) + |+ field beint32 (fun t -> t.fraction) + |+ field (bytes currency_len) (fun t -> t.currency) + |> sealr +end + +module AmountNBO = struct + type t = { + value: int64; + fraction: int32; + currency: string; + } + + let bin = + let open Bin in + record (fun value fraction currency -> { value; fraction; currency }) + |+ field beint64 (fun t -> t.value) + |+ field beint32 (fun t -> t.fraction) + |+ field (bytes currency_len) (fun t -> t.currency) + |> sealr +end (* Format used for to generate the signature on a request to withdraw coins from a reserve. *) @@ -348,7 +430,9 @@ module Withdraw_request_ps = struct h_planchets: Hash_planchets_p.t; (* The master seed that was used in the call to /blinding-prepare blinding, or all zeros, if no denomination of cipher type Clause-Schnorr is used. *) - blinding_seed: Blinding_master_secret_p.t; + (* TODO TALER doc + `TALER_BlindingMasterSecretP` in doc, but probably TALER_BlindingMasterSeed *) + blinding_seed: string; (* If age restriction proof is required, the maximum age _group_ to commit to, 0 otherwise. Note that in this case, all denominations for all coins MUST support age restriction. @@ -379,8 +463,38 @@ module Withdraw_request_ps = struct |+ field Amount.bin (fun t -> t.amount) |+ field Amount.bin (fun t -> t.fee) |+ field Hash_planchets_p.bin (fun t -> t.h_planchets) - |+ field Blinding_master_secret_p.bin (fun t -> t.blinding_seed) + |+ field cstring (fun t -> t.blinding_seed) |+ field beint32 (fun t -> t.max_age_group) |+ field Age_mask.bin (fun t -> t.mask) |> sealr end + +module Withdraw_confirmation_ps = struct + type t = { + (* Purpose is #TALER_SIGNATURE_EXCHANGE_CONFIRM_WITHDRAW. + Signed by a `struct TALER_ExchangePrivateKeyP` using EdDSA. *) + purpose: Ecc_signature_purpose.t; + (* Commitment made in the /withdraw request. + Also needed for the /reveal-withdraw endpoint (in case + of required proof of age restriction) and for /recoup *) + (* TODO TALER doc + missing TALER_HashBlindedPlanchetsP*) + h_planchets: Hash_planchets_p.t; + (* If proof of age restriction is not required for to this + withdrawal, (i.e. max_age was not set during the request) + MUST be 0xFFFFFFFF. + Otherwise (i.e. proof of age restriction required): + index that the client will not have to reveal, in NBO, + MUST be smaller than #TALER_CNC_KAPPA. *) + noreveal_index: int32; + } + + let bin = + let open Bin in + record (fun purpose h_planchets noreveal_index -> + { purpose; h_planchets; noreveal_index }) + |+ field Ecc_signature_purpose.bin (fun t -> t.purpose) + |+ field Hash_planchets_p.bin (fun t -> t.h_planchets) + |+ field beint32 (fun t -> t.noreveal_index) + |> sealr +end