74 lines
1.8 KiB
OCaml
74 lines
1.8 KiB
OCaml
open Syntax
|
|
(*open Crypto*)
|
|
|
|
let keys content =
|
|
let open Api in
|
|
let open ExchangeKeysResponse in
|
|
let* v = Api.decode jsont content in
|
|
let* () =
|
|
if
|
|
Libtool_version.is_compatible
|
|
~implementation:Libtool_version.mte_protocol_version v.version
|
|
then Ok ()
|
|
else Fmt.error "version incompatible"
|
|
in
|
|
|
|
(* TODO need hash over json..
|
|
validate ExchangeWireAccount *)
|
|
let* () =
|
|
let open AggregateTransferFee in
|
|
v.wire_fees
|
|
|> String_map.bindings
|
|
|> List.concat_map (fun (wire_method, l) ->
|
|
List.map (fun item -> (wire_method, item)) l)
|
|
|> list_iter
|
|
(fun
|
|
(wire_method, { wire_fee; closing_fee; start_date; end_date; sig_ })
|
|
->
|
|
let open Signatures.MasterWireFee in
|
|
verify v.master_public_key sig_
|
|
{
|
|
h_wire_method= Hash.Cstring.H64.hash wire_method;
|
|
start_date;
|
|
end_date;
|
|
wire_fee;
|
|
closing_fee;
|
|
})
|
|
in
|
|
|
|
(* validate signkeys *)
|
|
(* validate exchange_pub *)
|
|
(* validate denominations *)
|
|
(* validate exchange_sig *)
|
|
(* validate global-fees *)
|
|
(* validate list_issue_date *)
|
|
(* validate auditors *)
|
|
Ok ()
|
|
|
|
(* --- *)
|
|
open Cmdliner
|
|
open Cmdliner.Term.Syntax
|
|
|
|
let keys_cmd =
|
|
let input =
|
|
let doc = "input file" in
|
|
Arg.(required & opt (some filepath) None & info [ "i"; "input" ] ~doc)
|
|
in
|
|
let doc = "validate a /keys JSON response" in
|
|
Cmd.make (Cmd.info "keys" ~doc)
|
|
@@
|
|
let+ input = input in
|
|
let* content =
|
|
Result.bind (Fpath.of_string input) Bos.OS.File.read |> unwrap_err_msg
|
|
in
|
|
keys content
|
|
|
|
let cli =
|
|
let info =
|
|
let doc = "Testing tool to validate exchange responses" in
|
|
Cmd.info "validate" ~doc
|
|
in
|
|
Cmd.group info [ keys_cmd ]
|
|
|
|
let main () = Cmd.eval_result cli
|
|
let () = if !Sys.interactive then () else exit (main ())
|