refacto verify_denomination/signkey
This commit is contained in:
parent
d2e546571c
commit
368e595d44
6 changed files with 114 additions and 169 deletions
|
|
@ -35,29 +35,18 @@ let keys content =
|
|||
})
|
||||
in
|
||||
|
||||
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.exchange_pub)
|
||||
in
|
||||
|
||||
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 ()
|
||||
|
|
@ -75,24 +64,10 @@ let keys content =
|
|||
|
||||
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;
|
||||
})
|
||||
Denomination.verify_denomination_key_validity ~key:v.master_public_key
|
||||
dn)
|
||||
in
|
||||
let* () =
|
||||
let last_issue_date =
|
||||
|
|
@ -106,69 +81,44 @@ let keys content =
|
|||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
Ok ()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue