rm HashCode, use DenominationHash directly

This commit is contained in:
swrup 2025-12-21 22:13:35 +01:00
parent dfb0b476c0
commit 99d2ee6194
6 changed files with 77 additions and 39 deletions

View file

@ -29,6 +29,8 @@ let encode_exn jsont v = Jsont_bytesrw.encode_string jsont v |> Result.get_ok
let encode jsont v = Jsont_bytesrw.encode_string jsont v
let decode jsont v = Jsont_bytesrw.decode_string jsont v
module DenominationHash = Bin_type.DenominationHash
module Account_operation = struct
type t =
| Withdraw
@ -70,26 +72,6 @@ module B32 = struct
~decode:B32.decode Caqti_type.string
end
module HashCode : sig
type t
val hash : string -> t
val of_b32 : B32.t -> (t, string) result
val to_denomination_hash : t -> Bin_type.DenominationHash.t
val jsont : t Jsont.t
end = struct
type t = B32.t
let to_denomination_hash s = Bin_type.DenominationHash.of_octets s
let hash s =
let open Digestif.SHA512 in
s |> digest_string |> to_raw_string
let of_b32 = B32.decode
let jsont = B32.jsont
end
(* TODO error response
- use GANA error codes
https://git.gnunet.org/gana.git/tree/gnu-taler-error-codes/registry.rec *)
@ -442,7 +424,7 @@ end
module DenomSignature = struct
type t = {
h_denom_pub: HashCode.t;
h_denom_pub: DenominationHash.t;
master_sig: DenominationKeyValidity.t;
}
@ -451,7 +433,7 @@ module DenomSignature = struct
let h_denom_pub v = v.h_denom_pub in
let master_sig v = v.master_sig in
map ~kind:"DenomSignature" make
|> mem "h_denom_pub" HashCode.jsont ~enc:h_denom_pub
|> mem "h_denom_pub" DenominationHash.jsont ~enc:h_denom_pub
|> mem "master_sig" DenominationKeyValidity.jsont ~enc:master_sig
|> finish
end
@ -883,7 +865,7 @@ end
module AuditorDenominationKey = struct
type t = {
denom_pub_h: HashCode.t;
denom_pub_h: DenominationHash.t;
auditor_sig: ExchangeKeyValidity.t;
}
@ -892,7 +874,7 @@ module AuditorDenominationKey = struct
let denom_pub_h v = v.denom_pub_h in
let auditor_sig v = v.auditor_sig in
map ~kind:"AuditorDenominationKey" make
|> mem "denom_pub_h" HashCode.jsont ~enc:denom_pub_h
|> mem "denom_pub_h" DenominationHash.jsont ~enc:denom_pub_h
|> mem "auditor_sig" ExchangeKeyValidity.jsont ~enc:auditor_sig
|> finish
end
@ -951,13 +933,13 @@ module SignKey = struct
end
module RecoupDenoms = struct
type t = { h_denom_pub: HashCode.t }
type t = { h_denom_pub: DenominationHash.t }
let jsont =
let make h_denom_pub = { h_denom_pub } in
let h_denom_pub v = v.h_denom_pub in
map ~kind:"RecoupDenoms" make
|> mem "h_denom_pub" HashCode.jsont ~enc:h_denom_pub
|> mem "h_denom_pub" DenominationHash.jsont ~enc:h_denom_pub
|> finish
end