mte/src/types.ml

202 lines
5.5 KiB
OCaml
Raw Normal View History

2025-10-16 08:23:40 +02:00
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 = {
2025-10-16 10:18:22 +02:00
(* section_name: Name in the configuration file that defines this denomination *)
section_name: string;
2025-10-16 08:23:40 +02:00
value: Amount.t;
2025-10-17 15:09:47 +02:00
duration_withdraw: Ptime.Span.t;
duration_spend: Ptime.Span.t;
duration_legal: Ptime.Span.t;
2025-10-16 08:23:40 +02:00
fee_withdraw: Amount.t;
fee_deposit: Amount.t;
fee_refresh: Amount.t;
fee_refund: Amount.t;
cipher: [ (* `CS |*) `RSA ];
2025-10-17 15:09:47 +02:00
rsa_keysize: int; (* : int option (only if `RSA) *)
2025-10-16 08:23:40 +02:00
age_restricted: [ (*`YES|*) `NO ];
}
end
end
2025-10-01 17:26:50 +02:00
(* https://docs.taler.net/core/api-common.html#tsref-type-ErrorDetail *)
2025-10-07 15:08:35 +02:00
module ErrorDetail = struct
2025-10-01 17:26:50 +02:00
(* TODO GANA error codes
2025-10-01 19:34:42 +02:00
https://git.gnunet.org/gana.git/tree/gnu-taler-error-codes/registry.rec *)
2025-10-03 18:35:21 +02:00
type t = {
code: int;
hint: string option;
2025-10-03 18:35:21 +02:00
}
2025-10-01 17:26:50 +02:00
end
2025-10-01 20:22:32 +02:00
2025-10-03 18:35:21 +02:00
(* TODO number
- number is "float", but we probably want int everywhere instead
- numeric values capped at 2^53 -1 inclusive because json
2025-10-17 15:09:47 +02:00
*)
(* TODO time
- int64 instead of float/int (binary format time in int64 us)
? make api types take in Ptime.t instead of Timestamp.t
? issues with "never" = uint64_max *)
2025-10-01 20:22:32 +02:00
module Timestamp = struct
2025-10-03 18:35:21 +02:00
type t =
| Seconds of float
| Never
2025-10-17 15:09:47 +02:00
let of_ptime p = Seconds (Ptime.to_float_s p)
2025-10-03 18:35:21 +02:00
end
2025-10-07 15:08:35 +02:00
module RelativeTime = struct
2025-10-03 18:35:21 +02:00
type t =
| Microseconds of float
| Forever
2025-10-01 20:22:32 +02:00
end
2025-10-13 00:02:35 +02:00
module Amount = Amount
2025-10-01 20:22:32 +02:00
2025-10-13 00:02:35 +02:00
(* TODO key format *)
module EddsaPublicKey = struct
2025-10-01 20:22:32 +02:00
(* EdDSA and ECDHE public keys always point on Curve25519
and represented using the standard 256 bits Ed25519 compact format,
converted to Crockford Base32. *)
2025-10-13 00:02:35 +02:00
type t = Mirage_crypto_ec.Ed25519.pub
2025-10-01 20:22:32 +02:00
2025-10-13 00:02:35 +02:00
let of_string s =
2025-10-03 21:24:02 +02:00
let open Mirage_crypto_ec in
2025-10-16 08:23:40 +02:00
match B32.decode s with
2025-10-03 21:24:02 +02:00
| 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)
2025-10-13 00:02:35 +02:00
let to_string pub =
2025-10-16 08:23:40 +02:00
pub |> Mirage_crypto_ec.Ed25519.pub_to_octets |> B32.encode
2025-10-13 00:02:35 +02:00
end
2025-10-03 21:24:02 +02:00
2025-10-16 10:18:22 +02:00
(* TODO sig type
abstract type
same for RsaSignature *)
2025-10-13 00:02:35 +02:00
module EddsaSignature = struct
2025-10-01 20:22:32 +02:00
(* EdDSA signatures are transmitted as 64-bytes base32
2025-10-06 22:20:09 +02:00
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 *)
2025-10-13 00:02:35 +02:00
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
2025-10-01 20:22:32 +02:00
end
2025-10-13 00:02:35 +02:00
module RsaPublicKey = struct
2025-10-01 20:22:32 +02:00
(* RSA public key converted to Crockford Base32. *)
2025-10-16 08:23:40 +02:00
type t = Mirage_crypto_pk.Rsa.pub
2025-10-03 21:24:02 +02:00
2025-10-16 08:23:40 +02:00
let of_string s =
2025-10-17 15:25:10 +02:00
let open Syntax in
let* s = B32.decode s in
let* v = Util.bin_of_string Binary_formats.RsaPublicKey.bin s in
let+ v = Mirage_crypto_pk.Rsa.pub ~n:v.n ~e:v.e |> unwrap_err_msg in
v
2025-10-13 00:02:35 +02:00
2025-10-16 08:23:40 +02:00
let to_string ({ n; e } : Mirage_crypto_pk.Rsa.pub) =
2025-10-13 00:02:35 +02:00
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
2025-10-16 08:23:40 +02:00
let s = B32.encode s in
2025-10-13 00:02:35 +02:00
s
2025-10-01 20:22:32 +02:00
end
2025-10-07 15:08:35 +02:00
module HashCode = struct
2025-10-01 20:22:32 +02:00
(* 32-byte value representing a point on Curve25519. *)
type cs25519Point = string
end
2025-10-06 19:51:56 +02:00
2025-10-07 15:08:35 +02:00
module RsaDenominationKey = struct
2025-10-06 19:51:56 +02:00
type t = {
age_mask: int;
2025-10-16 10:18:22 +02:00
rsa_pub: RsaPublicKey.t;
2025-10-06 19:51:56 +02:00
}
end
2025-10-13 00:02:35 +02:00
(* not implemented *)
2025-10-07 15:08:35 +02:00
module CSDenominationKey = struct
2025-10-06 19:51:56 +02:00
(* Clause Schnorr *)
type t = {
age_mask: int;
cs_pub: string;
2025-10-06 19:51:56 +02:00
}
end
2025-10-07 15:08:35 +02:00
module DenominationKey = struct
2025-10-06 19:51:56 +02:00
type t =
2025-10-07 15:08:35 +02:00
| Rsa of RsaDenominationKey.t
| CS of CSDenominationKey.t
2025-10-06 19:51:56 +02:00
end
2025-10-07 15:08:35 +02:00
module FutureSignKey = struct
type t = {
(* The actual exchange's EdDSA signing public key *)
2025-10-13 00:02:35 +02:00
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. *)
2025-10-13 00:02:35 +02:00
signkey_secmod_sig: EddsaSignature.t;
}
end
2025-10-16 08:23:40 +02:00
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