offline tool: add enable/disable-auditor cmd

.
This commit is contained in:
swrup 2026-02-03 17:24:19 +01:00
parent ac4058df7e
commit 6ee1a994ad
14 changed files with 330 additions and 242 deletions

View file

@ -1,3 +1,6 @@
(* TODO
? have a currency agnostic amount_lib.ml and specialize amount.ml to Config.currency *)
type sign =
| Sign_plus
| Sign_minus

View file

@ -28,9 +28,8 @@ module EddsaPublicKey = struct
let* pub = of_octets octets in
Ok pub
let jsont =
let to_b32 t = B32.encode (to_octets t) in
Jsont.of_of_string ~kind:"EddsaPublicKey" of_b32 ~enc:to_b32
let to_b32 t = B32.encode (to_octets t)
let jsont = Jsont.of_of_string ~kind:"EddsaPublicKey" of_b32 ~enc:to_b32
let caqti =
Caqti_type.custom

View file

@ -194,7 +194,11 @@ let mk_keys ~db_conn (module Sm : Secmod.S) ~last_issue_date =
let* global_fees =
Pg.get_global_fees db_conn ~start_date:Timestamp.epoch |> unwrap_err_caqti
in
let auditors = (* TODO *) [] in
let* auditors =
(* TODO /auditors/$AUDITOR_PUB/$H_DENOM_PUB *)
(* does not contains auditor_keys with empty denomination_keys *)
Pg.get_auditor_keys db_conn
in
let extensions = None in
let extensions_sig = None in
Ok

View file

@ -308,12 +308,16 @@ module Auditors = struct
match last_date_opt with
| None ->
let+ () = Pg.insert_auditor db_conn v |> unwrap_err_caqti in
Logs.info (fun m -> m "enabled auditor");
()
| 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"
if cmp > 0 then
Error
"database has more recent auditor data for this auditor public key"
else
let+ () = Pg.update_auditor db_conn v |> unwrap_err_caqti in
Logs.info (fun m -> m "updated auditor");
()
let jsont = AuditorSetupMessage.jsont
@ -347,7 +351,9 @@ module Auditors_disable = struct
| None -> Error "auditor not found"
| Some last_date ->
let cmp = Timestamp.compare last_date validity_end |> Option.get in
if cmp > 0 then Error "more recent management auditor already present"
if cmp > 0 then
Error
"database has more recent auditor data for this auditor public key"
else
let+ () =
Pg.disable_auditor db_conn ~auditor_pub ~change_date:validity_end

View file

@ -11,7 +11,9 @@
transaction
should check validity of signatures got from db, for /management at least *)
should check validity of signatures got from db, for /management at least
clean up caqti error type *)
(* TODO time
fix comparison with timestamp footgun *)
@ -186,39 +188,21 @@ let insert_auditor_denom_sig =
fun (module Conn : CONN) ~auditor_pub ~h_denom_pub ~auditor_sig ->
Conn.exec insert_auditor_denom_sig (auditor_pub, h_denom_pub, auditor_sig)
let _get_auditors =
let get_auditors =
Caqti_type.(unit ->* t3 eddsa_pub string string)
"SELECT auditor_pub, auditor_url, auditor_name FROM auditors WHERE \
is_active"
in
fun (module Conn : CONN) () -> Conn.collect_list get_auditors ()
let _get_auditor_denoms =
let get_auditor_denoms =
let auditor_sig = Bin_sig.ExchangeKeyValidity.caqti in
Caqti_type.(unit ->* t3 eddsa_pub denomination_hash auditor_sig)
"SELECT auditors.auditor_pub, denominations.denom_pub_hash, \
auditor_denom_sigs.auditor_sig FROM auditor_denom_sigs JOIN auditors \
USING (auditor_uuid) JOIN denominations USING (denominations_serial) \
WHERE auditors.is_active"
in
fun (module Conn : CONN) () -> Conn.collect_list get_auditor_denoms ()
(* TODO
(* todo auditors
maybe check that url and name are unique/same for each auditor_pub
do the ht logic out of pg.ml *)
and do the ht logic out of pg.ml? *)
(* this does not return auditors that are not auditing any denom *)
let get_auditor_keys =
let get_auditor_keys =
let auditor_sig = Bin_sig.ExchangeKeyValidity.caqti in
Caqti_type.(
unit ->* t5 eddsa_pub string string denomination_hash auditor_sig)
"SELECT auditors.auditor_pub, auditors.url, auditors.name, \
denominations.denom_pub_hash, auditor_denom_sigs.auditor_sig FROM \
auditor_denom_sigs JOIN auditors USING (auditor_uuid) JOIN \
denominations USING (denominations_serial) WHERE auditors.is_active"
"SELECT a.auditor_pub, a.auditor_url, a.auditor_name, dn.denom_pub_hash, \
ads.auditor_sig FROM auditor_denom_sigs AS ads JOIN auditors AS a USING \
(auditor_uuid) JOIN denominations AS dn USING (denominations_serial) \
WHERE a.is_active"
in
fun (module Conn : CONN) () ->
fun (module Conn : CONN) ->
let open Syntax in
let* l = Conn.collect_list get_auditor_keys () |> unwrap_err_caqti in
let ht = Hashtbl.create 0xff in

View file

@ -19,8 +19,8 @@ module type S = sig
(* - management operations - *)
(* TODO
problem of keeping db and secmod state syncronized
do db interaction from secmod? *)
problem of keeping db and secmod state syncronized
do db interaction from secmod? *)
val add_signkey_master_signatures :
(eddsa_pub * Bin_sig.ExchangeSigningKeyValidity.t) list ->