(* 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 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)
let to_string pub =
pub |> Mirage_crypto_ec.Ed25519.pub_to_octets |> Base_32.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 pub = Mirage_crypto_pk.Rsa.pub
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
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