Signer/Ledger: improve tezos-client show ledger command

This commit is contained in:
Sebastien Mondet 2018-12-06 14:47:41 -05:00 committed by Benjamin Canou
parent 02b1d3e93d
commit 8b054deee3
No known key found for this signature in database
GPG Key ID: 73607948459DC5F8

View File

@ -522,12 +522,12 @@ let commands =
end ledgers) ; end ledgers) ;
Clic.command ~group Clic.command ~group
~desc: "Show BIP32 derivation at path for Ledger" ~desc: "Display version/public-key/address information for a Ledger URI"
no_options (args1 (switch ~doc:"Test signing operation" ~long:"test-sign" ()))
(prefixes [ "show" ; "ledger" ; "path" ] (prefixes [ "show" ; "ledger" ]
@@ Client_keys.sk_uri_param @@ Client_keys.sk_uri_param
@@ stop) @@ stop)
(fun () sk_uri (cctxt : Client_context.io_wallet) -> (fun test_sign sk_uri (cctxt : Client_context.io_wallet) ->
neuterize sk_uri >>=? fun pk_uri -> neuterize sk_uri >>=? fun pk_uri ->
id_of_pk_uri pk_uri >>=? fun id -> id_of_pk_uri pk_uri >>=? fun id ->
find_ledgers ~id () >>=? function find_ledgers ~id () >>=? function
@ -538,28 +538,55 @@ let commands =
Option.unopt ~default:"(none)" device_info.manufacturer_string in Option.unopt ~default:"(none)" device_info.manufacturer_string in
let product = let product =
Option.unopt ~default:"(none)" device_info.product_string in Option.unopt ~default:"(none)" device_info.product_string in
cctxt#message "Found a valid Tezos application running on %s %s at [%s]." cctxt#message
"Found a %a application running on a \
%s %s at [%s]."
Ledgerwallet_tezos.Version.pp version
manufacturer product device_info.path >>= fun () -> manufacturer product device_info.path >>= fun () ->
public_key pk_uri >>=? fun pk -> begin match id with
public_key_hash pk_uri >>=? fun (pkh, _) -> | (Pkh _ | Animals (_, Some _)) -> (* → Can public keys. *)
let pkh_bytes = Signature.Public_key_hash.to_bytes pkh in public_key pk_uri >>=? fun pk ->
match version.app_class with public_key_hash pk_uri >>=? fun (pkh, _) ->
| TezBake -> return_unit cctxt#message
| Tezos -> "@[<v 0>Tezos address at this path/curve: %a@,\
sign ~watermark:Generic_operation Corresponding full public key: %a@]"
sk_uri pkh_bytes >>=? fun signature -> Signature.Public_key_hash.pp pkh
match Signature.check ~watermark:Generic_operation Signature.Public_key.pp pk >>= fun () ->
pk signature pkh_bytes with begin match test_sign, version.app_class with
| false -> | true, Tezos ->
failwith "Fatal: Ledger cannot sign with %a" let pkh_bytes = Signature.Public_key_hash.to_bytes pkh in
Signature.Public_key_hash.pp pkh (* Signing requires validation on the device. *)
| true -> cctxt#message "Attempting a signature, please \
cctxt#message validate on the ledger." >>= fun () ->
"@[<v 0>Tezos address at this path: %a@,\ sign ~watermark:Generic_operation
Corresponding full public key: %a@]" sk_uri pkh_bytes >>=? fun signature ->
Signature.Public_key_hash.pp pkh begin match Signature.check ~watermark:Generic_operation
Signature.Public_key.pp pk >>= fun () -> pk signature pkh_bytes with
return_unit | false ->
failwith "Fatal: Ledger cannot sign with %a"
Signature.Public_key_hash.pp pkh
| true ->
cctxt#message "Tezos Wallet successfully signed."
>>= fun () ->
return_unit
end
| true, TezBake ->
failwith "Option --test-sign only works \
for the Tezos Wallet app."
| false, _ ->
return_unit
end
| Animals (_, None) when test_sign ->
failwith "Option --test-sign only works \
for the Tezos Wallet app with a \
curve/path specification."
| Animals (_, None) ->
cctxt#message "No curve was provided, \
there is no Tezos-address/public-key \
to show/test."
>>= fun () ->
return_unit
end
) ; ) ;
Clic.command ~group Clic.command ~group