better DenominationKey

This commit is contained in:
swrup 2025-11-30 22:44:36 +01:00
parent 4568b1bd4c
commit d4c1181946
3 changed files with 17 additions and 43 deletions

View file

@ -90,40 +90,23 @@ module RsaDenominationKey = struct
|> Jsont.Object.finish
end
(* not acctually implemented *)
module CSDenominationKey = struct
(* Clause Schnorr *)
type t = {
age_mask: int;
cs_pub: string;
}
let jsont =
let make age_mask cs_pub = { age_mask; cs_pub } in
let age_mask v = v.age_mask in
let cs_pub v = v.cs_pub in
Jsont.Object.map ~kind:"CSDenominationKey" make
|> Jsont.Object.mem "age_mask" Jsont.int ~enc:age_mask
|> Jsont.Object.mem "cs_pub" Jsont.string ~enc:cs_pub
|> Jsont.Object.finish
end
(* Clause Schnorr cipher is not supported *)
module DenominationKey = struct
type t =
| Rsa of RsaDenominationKey.t
| CS of CSDenominationKey.t
type t = Rsa of RsaDenominationKey.t
(*| CS of CSDenominationKey.t*)
let rsa v = Rsa v
let cs v = CS v
let to_octets = function Rsa denom -> RsaPublicKey.to_octets denom.rsa_pub
let of_cs _v =
Jsont.Error.msg Jsont.Meta.none "CSDenominationKey are not supported"
let of_rsa v = Rsa v
let jsont =
let open Jsont.Object in
let rsa = Case.map "RSA" RsaDenominationKey.jsont ~dec:rsa in
let cs = Case.map "CS" CSDenominationKey.jsont ~dec:cs in
let enc_case = function
| Rsa v -> Case.value rsa v
| CS v -> Case.value cs v
in
let rsa = Case.map "RSA" RsaDenominationKey.jsont ~dec:of_rsa in
let cs = Case.map "CS" Jsont.string ~dec:of_cs in
let enc_case = function Rsa v -> Case.value rsa v in
let cases = Case.[ make rsa; make cs ] in
map ~kind:"DenominationKey" Fun.id
|> case_mem "cipher" Jsont.string ~enc:Fun.id ~enc_case cases

View file

@ -21,13 +21,12 @@ let mk_future_denom denom_key_signf
} :
Denomination.t) =
let denom_pub =
DenominationKey.Rsa RsaDenominationKey.{ age_mask; rsa_pub= pub }
DenominationKey.of_rsa RsaDenominationKey.{ age_mask; rsa_pub= pub }
in
let denom_secmod_sig =
let open Bin_type in
let open Bin_signature.DenominationKeyAnnouncementPS in
let h_denom_pub = h_pub in
let h_section_name = Hash_64_cstr.hash section_name in
let h_section_name = Bin_type.Hash_64_cstr.hash section_name in
let anchor_time = stamp_start in
let duration_withdraw =
Timestamp.diff stamp_start stamp_expire_withdraw |> Timestamp.of_span_exn

View file

@ -19,20 +19,12 @@ let denom_signature ~master_key
(* TODO check sigs *)
denom_secmod_sig= _;
} =
let pub_octets =
let denom_pub =
match denom_pub with
| Rsa v -> v
| CS _ -> Fmt.failwith "CS key types are not supported."
in
let pub = denom_pub.RsaDenominationKey.rsa_pub in
RsaPublicKey.to_octets pub
in
let h_denom_pub = HashCode.hash pub_octets in
let octets = DenominationKey.to_octets denom_pub in
let h_denom_pub = HashCode.hash octets in
let master_sig =
let open Bin_signature.DenominationKeyValidityPS in
let master = EddsaPrivateKey.(pub_of_priv master_key) in
let denom_hash = DenominationHash.hash pub_octets in
let denom_hash = DenominationHash.hash octets in
{
master;
start= stamp_start;