diff --git a/src/keys.ml b/src/keys.ml index cd5d3517..d6a93db2 100644 --- a/src/keys.ml +++ b/src/keys.ml @@ -179,7 +179,7 @@ module Make (Conn : Pg.CONN) = struct let find_denom h_pub = Pg.find_denom conn h_pub |> unwrap_err_caqti (* TODO check stamps definitions *) - let mk_future_sk pub start expire = + let make_future_sk ~pub ~start ~expire = let stamp_start = Timestamp.of_absolute start in let stamp_expire = Timestamp.of_absolute expire in let stamp_end = stamp_expire in @@ -194,13 +194,13 @@ module Make (Conn : Pg.CONN) = struct Api.FutureSignKey. { key= pub; stamp_start; stamp_expire; stamp_end; signkey_secmod_sig } - let _get_future_sk () = + let _get_future_signkeys () = Secmod_eddsa.keys () |> List.map (fun (pub, t1, t2) -> let* opt = find_signkey pub in match opt with | None -> - let future_sk = mk_future_sk pub t1 t2 in + let future_sk = make_future_sk ~pub ~start:t1 ~expire:t2 in Ok (Some future_sk) | Some sk -> ( match Timestamp.of_absolute t1 = sk.stamp_start with @@ -210,7 +210,24 @@ module Make (Conn : Pg.CONN) = struct (EddsaPublicKey.to_b32 pub) | true -> Ok None)) - let make_future_dn t ~section_name ~pub start _end_ = + let make_future_dn ~coin ~pub ~start = + let Config.Coin. + { + section_name; + value; + duration_withdraw; + duration_spend; + duration_legal; + fee_withdraw; + fee_deposit; + fee_refresh; + fee_refund; + cipher= _; + rsa_keysize= _; + age_restricted= _; + } = + coin + in let stamp_start = Timestamp.of_absolute start in let stamp_expire_withdraw = Timestamp.of_absolute @@ Time.Absolute.add start duration_withdraw @@ -221,7 +238,6 @@ module Make (Conn : Pg.CONN) = struct let stamp_expire_legal = Timestamp.of_absolute @@ Time.Absolute.add start duration_legal in - let priv, pub = RsaPrivateKey.generate ~bits:rsa_keysize () in let open Api in let rsa_denomination_key = RsaDenominationKey.{ age_mask= 0; rsa_pub= pub } @@ -255,14 +271,24 @@ module Make (Conn : Pg.CONN) = struct denom_secmod_sig; } - let _get_future_dn () = + let _get_future_denominations () = Secmod_rsa.keys () - |> List.map (fun (section_name, pub, t1, t2) -> + |> List.map (fun (section_name, pub, t1, _t2) -> let h_pub = DenominationHash.hash (RsaPublicKey.to_octets pub) in + (*?? let duration_withdraw = Time.Absolute.diff t1 t2 in*) let* opt = find_denom h_pub in match opt with | None -> - let future_dn = mk_future_dn ~section_name ~h_pub ~pub t1 t2 in + let* coin = + Config.Coin.all_coins + |> List.find_opt (fun coin -> + coin.Config.Coin.section_name = section_name) + |> function + | Some v -> Ok v + | None -> + Fmt.error "coin `%s` not found in configuration" section_name + in + let future_dn = make_future_dn ~coin ~pub ~start:t1 in Ok (Some future_dn) | Some sk -> ( match Timestamp.of_absolute t1 = sk.stamp_start with