add /management/auditors (untested)

This commit is contained in:
swrup 2025-12-11 04:20:09 +01:00
parent 399a977c2d
commit a7b205b33e
6 changed files with 119 additions and 17 deletions

View file

@ -182,15 +182,9 @@ let check_master_signatures_update ~db_conn ~sm_denom =
match opt with None -> error | Some v -> Ok v
in
let check = function false -> error | true -> Ok () in
(* TODO time *)
let timestamp_equal a b =
let timestamp_to_int64 = function
| None -> None
| Some v -> v |> Ptime.to_float_s |> Int64.of_float |> Option.some
in
timestamp_to_int64 a = timestamp_to_int64 b
let* () =
check (Timestamp.compare valid_from denom.stamp_start = Some 0)
in
let* () = check (timestamp_equal valid_from denom.stamp_start) in
let* () = check (coin = denom.value) in
let* () = check (fee_refund = denom.fee_refund) in
let* () = check (age_mask = denom.age_mask) in
@ -243,3 +237,43 @@ let update_signkey_revocation ~db_conn ~sm_signkey exchange_pub
|> unwrap_err_caqti
in
Ok ()
let verify_auditor_add_sig
AuditorSetupMessage.
{ auditor_url; auditor_name= _; auditor_pub; master_sig; validity_start }
=
let open Bin_sig.MasterAddAuditor in
verify ~key:Config.Exchange.master_public_key master_sig
{
start_date= validity_start;
auditor_pub;
h_auditor_url= Bin_type.Hash_64_cstr.hash auditor_url;
}
(* todo: there is something about use of monotonic time + protection against replay attack that I don't understand *)
let update_auditor ~db_conn
AuditorSetupMessage.
{ auditor_url; auditor_name; auditor_pub; master_sig= _; validity_start }
=
let open Syntax in
let* last_date_opt =
Pg.lookup_auditor_timestamp db_conn auditor_pub |> unwrap_err_caqti
in
match last_date_opt with
| None ->
let+ () =
Pg.insert_auditor db_conn ~auditor_pub ~auditor_url ~auditor_name
~start_date:validity_start
|> unwrap_err_caqti
in
()
| Some last_date ->
let cmp = Timestamp.compare last_date validity_start |> Option.get in
if cmp > 0 then Error "more recent management auditor already present"
else
let+ () =
Pg.update_auditor db_conn ~auditor_pub ~auditor_url ~auditor_name
~enabled:true ~change_date:validity_start
|> unwrap_err_caqti
in
()