+ wip get_future_xx
This commit is contained in:
parent
d9f8e3c558
commit
07659222dc
2 changed files with 124 additions and 0 deletions
123
src/keys.ml
123
src/keys.ml
|
|
@ -175,6 +175,129 @@ module Make (Conn : Pg.CONN) = struct
|
||||||
| None -> Fmt.error "Keys: denomination data not found in database"
|
| None -> Fmt.error "Keys: denomination data not found in database"
|
||||||
| Some dn_data -> Ok dn_data
|
| Some dn_data -> Ok dn_data
|
||||||
|
|
||||||
|
let find_signkey pub = Pg.find_signkey conn pub |> unwrap_err_caqti
|
||||||
|
let find_denom h_pub = Pg.find_denom conn h_pub |> unwrap_err_caqti
|
||||||
|
|
||||||
|
(* TODO check stamps definitions *)
|
||||||
|
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
|
||||||
|
let signkey_secmod_sig =
|
||||||
|
let open Signatures.SigningKeyAnnouncement in
|
||||||
|
let exchange_pub = pub in
|
||||||
|
let anchor_time = stamp_start in
|
||||||
|
let duration = Timestamp.diff stamp_start stamp_expire in
|
||||||
|
sign_f ~f:Secmod_eddsa.sign_with_sm_key
|
||||||
|
{ exchange_pub; anchor_time; duration }
|
||||||
|
in
|
||||||
|
Api.FutureSignKey.
|
||||||
|
{ key= pub; stamp_start; stamp_expire; stamp_end; signkey_secmod_sig }
|
||||||
|
|
||||||
|
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 = make_future_sk ~pub ~start:t1 ~expire:t2 in
|
||||||
|
Ok (Some future_sk)
|
||||||
|
| Some sk -> (
|
||||||
|
match Timestamp.of_absolute t1 = sk.stamp_start with
|
||||||
|
| false ->
|
||||||
|
Fmt.error
|
||||||
|
"secmod/database stamp_start mismatch for signkey `%s`"
|
||||||
|
(EddsaPublicKey.to_b32 pub)
|
||||||
|
| true -> Ok None))
|
||||||
|
|
||||||
|
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
|
||||||
|
in
|
||||||
|
let stamp_expire_deposit =
|
||||||
|
Timestamp.of_absolute @@ Time.Absolute.add start duration_spend
|
||||||
|
in
|
||||||
|
let stamp_expire_legal =
|
||||||
|
Timestamp.of_absolute @@ Time.Absolute.add start duration_legal
|
||||||
|
in
|
||||||
|
let open Api in
|
||||||
|
let rsa_denomination_key =
|
||||||
|
RsaDenominationKey.{ age_mask= 0; rsa_pub= pub }
|
||||||
|
in
|
||||||
|
let denom_pub = DenominationKey.Rsa rsa_denomination_key in
|
||||||
|
let h_pub = DenominationHash.hash (RsaPublicKey.to_octets pub) in
|
||||||
|
let denom_secmod_sig =
|
||||||
|
let open Signatures.DenominationKeyAnnouncement in
|
||||||
|
let h_denom_pub = h_pub in
|
||||||
|
let h_section_name = Hash.Cstring.H64.hash section_name in
|
||||||
|
let anchor_time = stamp_start in
|
||||||
|
let duration_withdraw =
|
||||||
|
Timestamp.diff stamp_start stamp_expire_withdraw
|
||||||
|
in
|
||||||
|
sign_f ~f:Secmod_rsa.sign_with_sm_key
|
||||||
|
{ h_denom_pub; h_section_name; anchor_time; duration_withdraw }
|
||||||
|
in
|
||||||
|
FutureDenom.
|
||||||
|
{
|
||||||
|
section_name;
|
||||||
|
value;
|
||||||
|
stamp_start;
|
||||||
|
stamp_expire_withdraw;
|
||||||
|
stamp_expire_deposit;
|
||||||
|
stamp_expire_legal;
|
||||||
|
denom_pub;
|
||||||
|
fee_withdraw;
|
||||||
|
fee_deposit;
|
||||||
|
fee_refresh;
|
||||||
|
fee_refund;
|
||||||
|
denom_secmod_sig;
|
||||||
|
}
|
||||||
|
|
||||||
|
let _get_future_denominations () =
|
||||||
|
Secmod_rsa.keys ()
|
||||||
|
|> 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* 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
|
||||||
|
| false ->
|
||||||
|
Fmt.error
|
||||||
|
"secmod/database stamp_start mismatch for denomination `%s`"
|
||||||
|
section_name
|
||||||
|
| true -> Ok None))
|
||||||
|
|
||||||
let list_to_ht l = Hashtbl.of_seq (List.to_seq l)
|
let list_to_ht l = Hashtbl.of_seq (List.to_seq l)
|
||||||
|
|
||||||
let load () =
|
let load () =
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,7 @@ module Timestamp : sig
|
||||||
val of_absolute : Absolute.t -> t
|
val of_absolute : Absolute.t -> t
|
||||||
val of_ptime : Ptime.t -> t
|
val of_ptime : Ptime.t -> t
|
||||||
|
|
||||||
|
(* TODO add pp *)
|
||||||
(* - *)
|
(* - *)
|
||||||
val bin : t Bin.t
|
val bin : t Bin.t
|
||||||
val bin_nbo : t Bin.t
|
val bin_nbo : t Bin.t
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue