module Config_types = struct module Currency = struct type t = { enabled: [ `YES | `NO ]; code: string; name: string; fractional_input_digits: int; fractional_normal_digits: int; fractional_trailing_zero_digits: int; alt_unit_names: (int * string) list; } end module Coin = struct type t = { value: Amount.t; duration_withdraw: int; duration_spend: int; duration_legal: int; fee_withdraw: Amount.t; fee_deposit: Amount.t; fee_refresh: Amount.t; fee_refund: Amount.t; cipher: [ (* `CS |*) `RSA ]; rsa_keysize: int option (*only if `RSA *); age_restricted: [ (*`YES|*) `NO ]; } end end (* https://docs.taler.net/core/api-common.html#tsref-type-ErrorDetail *) module ErrorDetail = struct (* TODO GANA error codes https://git.gnunet.org/gana.git/tree/gnu-taler-error-codes/registry.rec *) type t = { code: int; hint: string option; } end (* TODO number - number is "float", but we probably want int everywhere instead - numeric values capped at 2^53 -1 inclusive because json - have a type for seconds/microseconds/..? *) module Timestamp = struct (* Seconds since epoch, or the special value "never" to represent an event that will never happen. *) type t = | Seconds of float | Never end module RelativeTime = struct (* Duration in microseconds or "forever" to represent an infinite duration. Numeric values are capped at 2^53 - 1 inclusive. *) type t = | Microseconds of float | Forever end module Amount = Amount (* TODO key format *) module EddsaPublicKey = struct (* EdDSA and ECDHE public keys always point on Curve25519 and represented using the standard 256 bits Ed25519 compact format, converted to Crockford Base32. *) type t = Mirage_crypto_ec.Ed25519.pub let of_string s = let open Mirage_crypto_ec in match B32.decode s with | Error _ as err -> err | Ok octets -> ( match Ed25519.pub_of_octets octets with | Error e -> Fmt.error "%a" pp_error e | Ok pub -> Ok pub) let to_string pub = pub |> Mirage_crypto_ec.Ed25519.pub_to_octets |> B32.encode end module EddsaSignature = struct (* EdDSA signatures are transmitted as 64-bytes base32 binary-encoded objects with just the R and S values (base32_ binary-only). They are signature over a c-struct like `TALER_xxxPS` + with a purpose *) type t = string (* TODO key format is it exactly like in GNU_CRYPTO? endianess issue? *) let sign ~key s = (* mirage_crypto: "The result is the concatenation of r and s, as specified in RFC 8032." *) Mirage_crypto_ec.Ed25519.sign ~key s end module RsaPublicKey = struct (* RSA public key converted to Crockford Base32. *) type t = Mirage_crypto_pk.Rsa.pub let of_string s = (* TODO bin - no [Bin.of_string] ? - what to do with the int ref? *) match B32.decode s with | Error _ as err -> err | Ok s -> ( let off = ref 0 in let v = Bin.decode Binary_formats.RsaPublicKey.bin s off in let res = Mirage_crypto_pk.Rsa.pub ~n:v.n ~e:v.e in match res with Error (`Msg e) -> Error e | Ok pub -> Ok pub) let to_string ({ n; e } : Mirage_crypto_pk.Rsa.pub) = let open Binary_formats.RsaPublicKey in let header = { n_len= Z.size n; e_len= Z.size e } in let v = { header; n; e } in let s = Bin.to_string bin v in let s = B32.encode s in s end module HashCode = struct (* 32-byte value representing a point on Curve25519. *) type cs25519Point = string end module RsaDenominationKey = struct type t = { age_mask: int; rsa_pub: string; (* Rsa.pub *) } end (* not implemented *) module CSDenominationKey = struct (* Clause Schnorr *) type t = { age_mask: int; cs_pub: string; } end module DenominationKey = struct type t = | Rsa of RsaDenominationKey.t | CS of CSDenominationKey.t end module FutureSignKey = struct type t = { (* The actual exchange's EdDSA signing public key *) key: EddsaPublicKey.t; (* Initial validity date for the signing key. *) stamp_start: Timestamp.t; (* Date when the exchange will stop using the signing key, allowed to overlap slightly with the next signing key's validity to allow for clock skew. *) stamp_expire: Timestamp.t; (* Date when all signatures made by the signing key expire and should henceforth no longer be considered valid in legal disputes. *) stamp_end: Timestamp.t; (* Signature over TALER_SigningKeyAnnouncementPS for this signing key by the signkey security module using purpose TALER_SIGNATURE_SM_SIGNING_KEY. *) signkey_secmod_sig: EddsaSignature.t; } end module FutureDenom = struct type t = { section_name: string; value: Amount.t; stamp_start: Timestamp.t; stamp_expire_withdraw: Timestamp.t; stamp_expire_deposit: Timestamp.t; stamp_expire_legal: Timestamp.t; denom_pub: DenominationKey.t; fee_withdraw: Amount.t; fee_deposit: Amount.t; fee_refresh: Amount.t; fee_refund: Amount.t; (* Signature by the denomination security module over TALER_DenominationKeyAnnouncementPS for this denomination with purpose TALER_SIGNATURE_SM_DENOMINATION_KEY. *) denom_secmod_sig: EddsaSignature.t; } end module FutureKeysResponse = struct type t = { future_denoms: FutureDenom.t list; future_signkeys: FutureSignKey.t list; master_pub: EddsaPublicKey.t; denom_secmod_public_key: EddsaPublicKey.t; signkey_secmod_public_key: EddsaPublicKey.t; } end