use exchange_pub valid at this time

This commit is contained in:
swrup 2026-02-26 17:04:48 +01:00
parent a376fc584f
commit a21ea0116a
5 changed files with 25 additions and 8 deletions

View file

@ -68,7 +68,7 @@ let mk_keys ~db_conn (module Keys : Keys.S) ~last_issue_date =
| Some timestamp -> | Some timestamp ->
List.find_map List.find_map
(fun v -> (fun v ->
if Timestamp.compare v.Denomination.stamp_start timestamp = 0 then if Timestamp.equal v.Denomination.stamp_start timestamp then
Some v.stamp_start Some v.stamp_start
else None) else None)
denom_l denom_l
@ -77,20 +77,24 @@ let mk_keys ~db_conn (module Keys : Keys.S) ~last_issue_date =
| None -> denom_l | None -> denom_l
| Some timestamp -> | Some timestamp ->
List.filter List.filter
(fun v -> Timestamp.compare v.Denomination.stamp_start timestamp >= 0) (fun v -> Timestamp.geq v.Denomination.stamp_start timestamp)
denom_l denom_l
in in
let* denominations = Denomination.make_denom_group_sorted denom_l in let* denominations = Denomination.make_denom_group_sorted denom_l in
let* signkeys = Keys.signkeys () in let* signkeys = Keys.signkeys () in
let signkeys = List.map Api.SignKey.of_signkey signkeys in
(* the eddsa pub key used to sign exchange_sig *) (* the eddsa pub key used to sign exchange_sig *)
let* exchange_pub = let* exchange_pub =
match signkeys with let now = Timestamp.of_ptime (Ptime_clock.now ()) in
| [] -> Fmt.error "exchange has no active signkey" let opt =
| sk :: _ -> Ok sk.SignKey.key List.find_opt (fun sk -> Signkey.is_valid_at ~timestamp:now sk) signkeys
in in
match opt with
| None -> Fmt.error "exchange has no active signkey"
| Some sk -> Ok sk.pub
in
let signkeys = List.map Api.SignKey.of_signkey signkeys in
(* ! depends on denominations order *) (* ! depends on denominations order *)
let exchange_sig = let exchange_sig =

View file

@ -164,7 +164,7 @@ module Auditors = struct
Logs.info (fun m -> m "enabled auditor"); Logs.info (fun m -> m "enabled auditor");
() ()
| Some auditor -> | Some auditor ->
if Timestamp.compare auditor.last_change validity_start > 0 then if Timestamp.geq auditor.last_change validity_start then
Error Error
"database has more recent auditor data for this auditor public key" "database has more recent auditor data for this auditor public key"
else else
@ -200,7 +200,7 @@ module Auditors_disable = struct
match opt with match opt with
| None -> Error "auditor not found" | None -> Error "auditor not found"
| Some auditor -> ( | Some auditor -> (
match Timestamp.compare auditor.last_change validity_end > 0 with match Timestamp.geq auditor.last_change validity_end with
| true -> | true ->
Error Error
"database has more recent auditor data for this auditor public \ "database has more recent auditor data for this auditor public \

View file

@ -7,3 +7,6 @@ type t = {
stamp_end: Timestamp.t; stamp_end: Timestamp.t;
master_sig: Signatures.ExchangeSigningKeyValidity.t; master_sig: Signatures.ExchangeSigningKeyValidity.t;
} }
let is_valid_at ~timestamp sk =
Timestamp.geq sk.stamp_start timestamp && Timestamp.lt timestamp sk.stamp_end

View file

@ -97,6 +97,11 @@ module Timestamp = struct
let never = uint64_max let never = uint64_max
let zero = 0L let zero = 0L
let compare = Int64.unsigned_compare let compare = Int64.unsigned_compare
let gt a b = compare a b > 0
let geq a b = compare a b >= 0
let lt a b = compare a b < 0
let leq a b = compare a b <= 0
let equal a b = compare a b = 0
let min a b = if compare a b < 0 then a else b let min a b = if compare a b < 0 then a else b
let max a b = if compare a b > 0 then a else b let max a b = if compare a b > 0 then a else b

View file

@ -37,6 +37,11 @@ module Timestamp : sig
val never : t val never : t
val zero : t val zero : t
val compare : t -> t -> int val compare : t -> t -> int
val gt : t -> t -> bool
val geq : t -> t -> bool
val lt : t -> t -> bool
val leq : t -> t -> bool
val equal : t -> t -> bool
val min : t -> t -> t val min : t -> t -> t
val max : t -> t -> t val max : t -> t -> t
val diff : t -> t -> TimeRelative.t val diff : t -> t -> TimeRelative.t