mte/src/types.ml

135 lines
3.9 KiB
OCaml
Raw Normal View History

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
- have a type for seconds/microseconds/..? *)
2025-10-01 20:22:32 +02:00
module Timestamp = struct
(* Seconds since epoch, or the special
value "never" to represent an event that will
never happen. *)
2025-10-03 18:35:21 +02:00
type t =
| Seconds of float
| Never
end
2025-10-07 15:08:35 +02:00
module RelativeTime = struct
2025-10-03 18:35:21 +02:00
(* 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
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
match Base_32.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)
2025-10-13 00:02:35 +02:00
let to_string pub =
2025-10-03 21:24:02 +02:00
pub |> Mirage_crypto_ec.Ed25519.pub_to_octets |> Base_32.encode
2025-10-13 00:02:35 +02:00
end
2025-10-03 21:24:02 +02:00
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-03 21:24:02 +02:00
type pub = Mirage_crypto_pk.Rsa.pub
2025-10-13 00:02:35 +02:00
let pub_of_string s =
(* TODO bin
- no [Bin.of_string] ?
- what to do with the int ref? *)
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 pub_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
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;
rsa_pub: string; (* Rsa.pub *)
2025-10-06 19:51:56 +02:00
}
end
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