From d2a0ff93dc595cebc593ed507cb80725d5ec2c09 Mon Sep 17 00:00:00 2001 From: swrup Date: Thu, 5 Feb 2026 17:57:27 +0100 Subject: [PATCH] --- src/hash.ml | 74 +++++++++++++++++++++++++++-------------------------- 1 file changed, 38 insertions(+), 36 deletions(-) diff --git a/src/hash.ml b/src/hash.ml index 0776027b..317ae2b1 100644 --- a/src/hash.ml +++ b/src/hash.ml @@ -8,6 +8,18 @@ open Digestif +module type S = sig + type t + + val bin : t Bin.t + val caqti : t Caqti_type.t + val jsont : t Jsont.t + val hash : string -> t + val of_octets : string -> t + val to_octets : t -> string + val of_b32 : B32.t -> (t, string) result +end + module H32 = struct type t = SHA256.t @@ -74,42 +86,32 @@ module H64 = struct end (* Hash over string + '\0' *) -module H32_cstr = struct - include H32 +module Cstring = struct + module H32 = struct + include H32 - let hash s = - let s = s ^ "\x00" in - SHA256.(digest_string s) + let hash s = + let s = s ^ "\x00" in + hash s + end + + module H64 = struct + include H64 + + let hash s = + let s = s ^ "\x00" in + hash s + end end -module H64_cstr = struct - include H64 - - let hash s = - let s = s ^ "\x00" in - SHA512.(digest_string s) -end - -module type Hash_S = sig - type t - - val bin : t Bin.t - val caqti : t Caqti_type.t - val jsont : t Jsont.t - val hash : string -> t - val of_octets : string -> t - val to_octets : t -> string - val of_b32 : B32.t -> (t, string) result -end - -module FullPaytoHash : Hash_S = H32 -module NormalizedPaytoHash : Hash_S = H32 -module DenominationHash : Hash_S = H64 -module PrivateContractHash : Hash_S = H64 -module ExtensionsPolicyHash : Hash_S = H64 -module MerchantWireHash : Hash_S = H64 -module AgeCommitmentHash : Hash_S = H64 -module BlindedCoinHash : Hash_S = H64 -module CoinPubHash : Hash_S = H64 -module OutputCommitmentHash : Hash_S = H64 -module HashPlanchetsP : Hash_S = H64 +module FullPaytoHash : S = H32 +module NormalizedPaytoHash : S = H32 +module DenominationHash : S = H64 +module PrivateContractHash : S = H64 +module ExtensionsPolicyHash : S = H64 +module MerchantWireHash : S = H64 +module AgeCommitmentHash : S = H64 +module BlindedCoinHash : S = H64 +module CoinPubHash : S = H64 +module OutputCommitmentHash : S = H64 +module HashPlanchetsP : S = H64