refacto verify_denomination/signkey
This commit is contained in:
parent
cbf54c16df
commit
5313ada570
6 changed files with 120 additions and 170 deletions
|
|
@ -34,30 +34,21 @@ let keys content =
|
|||
closing_fee;
|
||||
})
|
||||
in
|
||||
(*Fmt.pr "OK wire_fees@.";*)
|
||||
|
||||
let sk_l = List.map SignKey.to_signkey v.signkeys in
|
||||
let* () =
|
||||
let open SignKey in
|
||||
v.signkeys
|
||||
sk_l
|
||||
|> list_iter
|
||||
(fun { key; stamp_start; stamp_expire; stamp_end; master_sig } ->
|
||||
let open Signatures.ExchangeSigningKeyValidity in
|
||||
verify v.master_public_key master_sig
|
||||
{
|
||||
R.start= stamp_start;
|
||||
expire= stamp_expire;
|
||||
end_= stamp_end;
|
||||
signkey_pub= key;
|
||||
})
|
||||
(Signkey.verify_exchange_signing_key_validity ~key:v.master_public_key)
|
||||
in
|
||||
(*Fmt.pr "OK signkeys@.";*)
|
||||
|
||||
let* () =
|
||||
let opt =
|
||||
List.find_opt (fun sk -> sk.SignKey.key = v.exchange_pub) v.signkeys
|
||||
in
|
||||
let opt = List.find_opt (fun sk -> sk.Signkey.pub = v.exchange_pub) sk_l in
|
||||
match opt with
|
||||
| None -> Fmt.error "exchange_pub is not in signkeys list"
|
||||
| Some sk ->
|
||||
let sk = SignKey.to_signkey sk in
|
||||
(* TODO will need to fake time to validate expired data *)
|
||||
let now = Timestamp.of_ptime (Ptime_clock.now ()) in
|
||||
if Signkey.is_valid_at ~timestamp:now sk then Ok ()
|
||||
|
|
@ -72,27 +63,13 @@ let keys content =
|
|||
hc= Denomination.hash_over_master_sigs v.denominations;
|
||||
}
|
||||
in
|
||||
(*Fmt.pr "OK exchange_pub@.";*)
|
||||
|
||||
let denom_l = v.denominations |> Denomination.denoms_of_denomgroups in
|
||||
let* () =
|
||||
let open Denomination in
|
||||
denom_l
|
||||
|> list_iter (fun dn ->
|
||||
let open Signatures.DenominationKeyValidity in
|
||||
verify v.master_public_key dn.master_sig
|
||||
{
|
||||
R.master= v.master_public_key;
|
||||
start= dn.stamp_start;
|
||||
expire_withdraw= dn.stamp_expire_withdraw;
|
||||
expire_spend= dn.stamp_expire_deposit;
|
||||
expire_legal= dn.stamp_expire_legal;
|
||||
value= dn.value;
|
||||
fee_withdraw= dn.fee_withdraw;
|
||||
fee_deposit= dn.fee_deposit;
|
||||
fee_refresh= dn.fee_refresh;
|
||||
fee_refund= dn.fee_refund;
|
||||
denom_hash= dn.h_pub;
|
||||
})
|
||||
|> list_iter
|
||||
(Denomination.verify_denomination_key_validity ~key:v.master_public_key)
|
||||
in
|
||||
let* () =
|
||||
let last_issue_date =
|
||||
|
|
@ -103,73 +80,51 @@ let keys content =
|
|||
if last_issue_date = v.list_issue_date then Ok ()
|
||||
else Fmt.error "list_issue_date is wrong"
|
||||
in
|
||||
(*Fmt.pr "OK denominations@.";*)
|
||||
|
||||
let* () =
|
||||
v.global_fees
|
||||
|> list_iter
|
||||
(fun
|
||||
GlobalFees.
|
||||
{
|
||||
start_date;
|
||||
end_date;
|
||||
history_fee;
|
||||
account_fee;
|
||||
purse_fee;
|
||||
history_expiration;
|
||||
purse_account_limit;
|
||||
purse_timeout;
|
||||
master_sig;
|
||||
}
|
||||
->
|
||||
let open Signatures.GlobalFees in
|
||||
verify v.master_public_key master_sig
|
||||
{
|
||||
start_date;
|
||||
end_date;
|
||||
purse_timeout;
|
||||
history_expiration;
|
||||
history_fee;
|
||||
account_fee;
|
||||
purse_fee;
|
||||
purse_account_limit;
|
||||
})
|
||||
|> list_iter (GlobalFees.verify_global_fees ~key:v.master_public_key)
|
||||
in
|
||||
(*Fmt.pr "OK global_fees@.";*)
|
||||
|
||||
let* () =
|
||||
(* TODO O(n^2) *)
|
||||
v.auditors
|
||||
|> list_iter
|
||||
|> List.concat_map
|
||||
(fun
|
||||
AuditorKeys.
|
||||
{ auditor_pub; auditor_url; auditor_name= _; denomination_keys }
|
||||
->
|
||||
let auditor_url_hash = Hash.H64.hash auditor_url in
|
||||
denomination_keys
|
||||
|> list_iter
|
||||
|> List.map
|
||||
(fun AuditorDenominationKey.{ denom_pub_h; auditor_sig } ->
|
||||
let open Denomination in
|
||||
let opt =
|
||||
denom_l |> List.find_opt (fun dn -> dn.h_pub = denom_pub_h)
|
||||
in
|
||||
match opt with
|
||||
| None -> Fmt.error "auditor denomination key not found"
|
||||
| Some dn ->
|
||||
let open Signatures.ExchangeKeyValidity in
|
||||
verify auditor_pub auditor_sig
|
||||
{
|
||||
auditor_url_hash;
|
||||
master= auditor_pub;
|
||||
start= dn.stamp_start;
|
||||
expire_withdraw= dn.stamp_expire_withdraw;
|
||||
expire_spend= dn.stamp_expire_deposit;
|
||||
expire_legal= dn.stamp_expire_legal;
|
||||
value= dn.value;
|
||||
fee_withdraw= dn.fee_withdraw;
|
||||
fee_deposit= dn.fee_deposit;
|
||||
fee_refresh= dn.fee_refresh;
|
||||
denom_hash= denom_pub_h;
|
||||
}))
|
||||
(denom_pub_h, auditor_url_hash, auditor_pub, auditor_sig)))
|
||||
|> list_iter
|
||||
(fun (denom_pub_h, auditor_url_hash, auditor_pub, auditor_sig) ->
|
||||
let open Denomination in
|
||||
denom_l |> List.find_opt (fun dn -> dn.h_pub = denom_pub_h)
|
||||
|> function
|
||||
| None -> Fmt.error "auditor denomination key not found"
|
||||
| Some dn ->
|
||||
let open Signatures.ExchangeKeyValidity in
|
||||
verify auditor_pub auditor_sig
|
||||
{
|
||||
auditor_url_hash;
|
||||
master= auditor_pub;
|
||||
start= dn.stamp_start;
|
||||
expire_withdraw= dn.stamp_expire_withdraw;
|
||||
expire_spend= dn.stamp_expire_deposit;
|
||||
expire_legal= dn.stamp_expire_legal;
|
||||
value= dn.value;
|
||||
fee_withdraw= dn.fee_withdraw;
|
||||
fee_deposit= dn.fee_deposit;
|
||||
fee_refresh= dn.fee_refresh;
|
||||
denom_hash= dn.h_pub;
|
||||
})
|
||||
in
|
||||
(*Fmt.pr "OK auditors@.";*)
|
||||
|
||||
Ok ()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue