wip: clean up module mess

This commit is contained in:
swrup 2025-11-21 20:05:05 +01:00
parent d2f334f4b1
commit 8c0e8b2c6d

View file

@ -47,7 +47,7 @@ let int64_size = 8
(* microseconds since the UNIX Epoch (* microseconds since the UNIX Epoch
UINT64_MAX represents "never" *) UINT64_MAX represents "never" *)
module MK_TIME () = struct module TIME = struct
type t = { v: int64 } type t = { v: int64 }
(* not BE (?) *) (* not BE (?) *)
@ -56,7 +56,7 @@ module MK_TIME () = struct
record (fun v -> { v }) |+ field neint64 (fun t -> t.v) |> sealr record (fun v -> { v }) |+ field neint64 (fun t -> t.v) |> sealr
end end
module MK_TIME_NBO () = struct module TIME_NBO = struct
type t = { v: int64 } type t = { v: int64 }
let bin = let bin =
@ -64,31 +64,21 @@ module MK_TIME_NBO () = struct
record (fun v -> { v }) |+ field beint64 (fun t -> t.v) |> sealr record (fun v -> { v }) |+ field beint64 (fun t -> t.v) |> sealr
end end
module TimeAbsolute = MK_TIME () module TimeAbsolute = TIME
module TimeAbsoluteNBO = MK_TIME_NBO () module TimeAbsoluteNBO = TIME_NBO
module TimeRelative = MK_TIME () module TimeRelative = TIME
module TimeRelativeNBO = MK_TIME_NBO () module TimeRelativeNBO = TIME_NBO
module Timestamp = MK_TIME () module Timestamp = TIME
module TimestampNBO = MK_TIME_NBO () module TimestampNBO = TIME_NBO
(* TODO clean up (* TODO clean up
? rm all of UTIL ? rm all of UTIL
? Bin.map int64 to Ptime.t here *) ? Bin.map int64 to Ptime.t here *)
module UTIL = struct module UTIL = struct
module type Bytes_sig = sig (* taler doc:
type t = { v: string }
val of_octets : string -> t
val bin : t Bin.t
end
(* MK_XX functor for structs like:
struct Foo { uint8t thing[XX]; }
MK_HASH_XX for hashed value
taler doc:
- Taler uses 512-bit hash codes (64 bytes). - Taler uses 512-bit hash codes (64 bytes).
- usually SHA-512 *) - usually SHA-512 *)
module MK_32 () : Bytes_sig = struct module Bytes_32 = struct
type t = { v: string } type t = { v: string }
let of_octets v = let of_octets v =
@ -101,7 +91,7 @@ module UTIL = struct
record (fun v -> { v }) |+ field (bytes 32) (fun t -> t.v) |> sealr record (fun v -> { v }) |+ field (bytes 32) (fun t -> t.v) |> sealr
end end
module MK_64 () : Bytes_sig = struct module Bytes_64 = struct
type t = { v: string } type t = { v: string }
let of_octets v = let of_octets v =
@ -114,17 +104,7 @@ module UTIL = struct
record (fun v -> { v }) |+ field (bytes 64) (fun t -> t.v) |> sealr record (fun v -> { v }) |+ field (bytes 64) (fun t -> t.v) |> sealr
end end
module Bytes_32 = MK_32 () module HHH_64 = struct
module Bytes_64 = MK_64 ()
module type H_sig = sig
type t
val hash : string -> t
val bin : t Bin.t
end
module HHH_64 : H_sig = struct
type t = { hash: Digestif.SHA512.t } type t = { hash: Digestif.SHA512.t }
let hash s = let hash s =
@ -141,7 +121,7 @@ module UTIL = struct
end end
(* sha512 with string size check *) (* sha512 with string size check *)
module Hash_64 : H_sig = struct module Hash_64 = struct
include HHH_64 include HHH_64
let hash s = let hash s =
@ -154,7 +134,7 @@ module UTIL = struct
this is "HashCode" in GNU TALER this is "HashCode" in GNU TALER
todo: maybe need to have a cstring.ml *) todo: maybe need to have a cstring.ml *)
module Cstring_hash_64 : H_sig = struct module Cstring_hash_64 = struct
include HHH_64 include HHH_64
let hash s = let hash s =
@ -162,11 +142,11 @@ module UTIL = struct
hash s hash s
end end
module MK_HASH_64 () : H_sig = struct module MK_HASH_64 () = struct
include HHH_64 include HHH_64
end end
module HHH_32 : H_sig = struct module HHH_32 = struct
type t = { hash: Digestif.SHA256.t } type t = { hash: Digestif.SHA256.t }
let hash s = let hash s =
@ -183,7 +163,7 @@ module UTIL = struct
end end
(* sha256 with string size check *) (* sha256 with string size check *)
module Hash_32 : H_sig = struct module Hash_32 = struct
include HHH_32 include HHH_32
let hash s = let hash s =
@ -198,7 +178,7 @@ module UTIL = struct
this is "HashCode" in GNU TALER this is "HashCode" in GNU TALER
todo: maybe need to have a cstring.ml *) todo: maybe need to have a cstring.ml *)
module Cstring_hash_32 : H_sig = struct module Cstring_hash_32 = struct
include HHH_32 include HHH_32
let hash s = let hash s =
@ -206,7 +186,7 @@ module UTIL = struct
hash s hash s
end end
module MK_HASH_32 () : H_sig = struct module MK_HASH_32 () = struct
include HHH_32 include HHH_32
end end
@ -297,35 +277,35 @@ module HashPlanchetsP = MK_HASH_64 ()
(* --- Keys --- *) (* --- Keys --- *)
module PursePublicKey = MK_32 () (* missing doc *) module PursePublicKey = Bytes_32 (* missing doc *)
module AuditorPublicKeyP = MK_32 () (* missing doc *) module AuditorPublicKeyP = Bytes_32 (* missing doc *)
module BlindingMasterSeed = MK_32 () module BlindingMasterSeed = Bytes_32
module BlindingMasterSecret = MK_32 () module BlindingMasterSecret = Bytes_32
module ReservePublicKeyP = MK_32 () module ReservePublicKeyP = Bytes_32
module ReservePrivateKeyP = MK_32 () module ReservePrivateKeyP = Bytes_32
module MerchantPublicKeyP = MK_32 () module MerchantPublicKeyP = Bytes_32
module MerchantPrivateKeyP = MK_32 () module MerchantPrivateKeyP = Bytes_32
module TransferPublicKeyP = MK_32 () module TransferPublicKeyP = Bytes_32
module TransferPrivateKeyP = MK_32 () module TransferPrivateKeyP = Bytes_32
module AmlOfficerPublicKeyP = MK_32 () module AmlOfficerPublicKeyP = Bytes_32
module AmlOfficerPrivateKeyP = MK_32 () module AmlOfficerPrivateKeyP = Bytes_32
(*module ExchangePublicKeyP = MK_32 ()*) (*module ExchangePublicKeyP = Bytes_32*)
module ExchangePrivateKeyP = MK_32 () module ExchangePrivateKeyP = Bytes_32
module MasterPublicKeyP = MK_32 () module MasterPublicKeyP = Bytes_32
module MasterPrivateKeyP = MK_32 () module MasterPrivateKeyP = Bytes_32
module WireTransferIdentifierRawP = MK_32 () module WireTransferIdentifierRawP = Bytes_32
module CoinSpendPublicKeyP = MK_32 () (* union *) module CoinSpendPublicKeyP = Bytes_32 (* union *)
module CoinSpendPrivateKeyP = MK_32 () (* union *) module CoinSpendPrivateKeyP = Bytes_32 (* union *)
module TokenPublicKeyP = MK_32 () (* union *) module TokenPublicKeyP = Bytes_32 (* union *)
module PublicRefreshCoinNonceP = MK_64 () (* missing doc *) module PublicRefreshCoinNonceP = Bytes_64 (* missing doc *)
module ReserveSignatureP = MK_64 () module ReserveSignatureP = Bytes_64
module ExchangeSignatureP = MK_64 () module ExchangeSignatureP = Bytes_64
module MasterSignatureP = MK_64 () module MasterSignatureP = Bytes_64
module CoinSpendSignatureP = MK_64 () module CoinSpendSignatureP = Bytes_64
module TransferSecretP = MK_64 () module TransferSecretP = Bytes_64
module LinkSecretP = MK_64 () module LinkSecretP = Bytes_64
module EncryptedLinkSecretP = MK_64 () module EncryptedLinkSecretP = Bytes_64
(* TODO ? need to use/save a specific nonce for cryptographic blinding *) (* TODO ? need to use/save a specific nonce for cryptographic blinding *)
(* Secret for blinding/unblinding. (* Secret for blinding/unblinding.
@ -333,11 +313,11 @@ module EncryptedLinkSecretP = MK_64 ()
a 256-bit nonce, converted to Crockford `Base32`. a 256-bit nonce, converted to Crockford `Base32`.
type DenominationBlindingKeyP = string; *) type DenominationBlindingKeyP = string; *)
module DenominationBlindingKeyP = MK_32 () module DenominationBlindingKeyP = Bytes_32
(* --- Various --- *) (* --- Various --- *)
module RefreshCommitmentP = MK_64 () module RefreshCommitmentP = Bytes_64
module UUID = struct module UUID = struct
(* uint32t value[4]; *) (* uint32t value[4]; *)