Ledger: implement git-commit APDU
This commit is contained in:
parent
31d207f52e
commit
92715a005b
@ -139,14 +139,15 @@ module Ledger = struct
|
|||||||
type t = {
|
type t = {
|
||||||
device_info : Hidapi.device_info ;
|
device_info : Hidapi.device_info ;
|
||||||
version : Ledgerwallet_tezos.Version.t ;
|
version : Ledgerwallet_tezos.Version.t ;
|
||||||
|
git_commit : string option ;
|
||||||
of_curve : (Ledgerwallet_tezos.curve * (Signature.Public_key.t *
|
of_curve : (Ledgerwallet_tezos.curve * (Signature.Public_key.t *
|
||||||
Signature.Public_key_hash.t)) list ;
|
Signature.Public_key_hash.t)) list ;
|
||||||
of_pkh : (Signature.Public_key_hash.t * (Signature.Public_key.t *
|
of_pkh : (Signature.Public_key_hash.t * (Signature.Public_key.t *
|
||||||
Ledgerwallet_tezos.curve)) list ;
|
Ledgerwallet_tezos.curve)) list ;
|
||||||
}
|
}
|
||||||
|
|
||||||
let create ~device_info ~version ~of_curve ~of_pkh =
|
let create ?git_commit ~device_info ~version ~of_curve ~of_pkh () =
|
||||||
{ device_info ; version ; of_curve ; of_pkh }
|
{ device_info ; version ; git_commit ; of_curve ; of_pkh }
|
||||||
|
|
||||||
let curves { Ledgerwallet_tezos.Version.major ; minor ; patch ; _ } =
|
let curves { Ledgerwallet_tezos.Version.major ; minor ; patch ; _ } =
|
||||||
let open Ledgerwallet_tezos in
|
let open Ledgerwallet_tezos in
|
||||||
@ -156,7 +157,7 @@ module Ledger = struct
|
|||||||
[ Ed25519 ; Secp256k1 ; Secp256r1 ]
|
[ Ed25519 ; Secp256k1 ; Secp256r1 ]
|
||||||
|
|
||||||
let of_hidapi ?pkh device_info h =
|
let of_hidapi ?pkh device_info h =
|
||||||
let find_ledgers version =
|
let find_ledgers ?git_commit version =
|
||||||
fold_left_s begin fun (pkh_found, of_curve, of_pkh) curve ->
|
fold_left_s begin fun (pkh_found, of_curve, of_pkh) curve ->
|
||||||
get_public_key h curve [] >>|? fun pk ->
|
get_public_key h curve [] >>|? fun pk ->
|
||||||
let cur_pkh = Signature.Public_key.hash pk in
|
let cur_pkh = Signature.Public_key.hash pk in
|
||||||
@ -167,9 +168,12 @@ module Ledger = struct
|
|||||||
end (false, [], []) (curves version)
|
end (false, [], []) (curves version)
|
||||||
>>=? fun (pkh_found, of_curve, of_pkh) ->
|
>>=? fun (pkh_found, of_curve, of_pkh) ->
|
||||||
match pkh with
|
match pkh with
|
||||||
| None -> return (Some (create ~device_info ~version ~of_curve ~of_pkh))
|
| None ->
|
||||||
|
return (Some (create ?git_commit ~device_info ~version
|
||||||
|
~of_curve ~of_pkh ()))
|
||||||
| Some _ when pkh_found ->
|
| Some _ when pkh_found ->
|
||||||
return (Some (create ~device_info ~version ~of_curve ~of_pkh))
|
return (Some (create ?git_commit ~device_info ~version
|
||||||
|
~of_curve ~of_pkh ()))
|
||||||
| _ -> return None
|
| _ -> return None
|
||||||
in
|
in
|
||||||
let buf = Buffer.create 100 in
|
let buf = Buffer.create 100 in
|
||||||
@ -194,7 +198,15 @@ module Ledger = struct
|
|||||||
device_info.Hidapi.path
|
device_info.Hidapi.path
|
||||||
Ledgerwallet.Transport.pp_error e ;
|
Ledgerwallet.Transport.pp_error e ;
|
||||||
return None
|
return None
|
||||||
| Ok version -> find_ledgers version
|
| Ok ({ major; minor; patch; _ } as version) ->
|
||||||
|
begin
|
||||||
|
if (major, minor, patch) >= (1, 4, 0) then
|
||||||
|
wrap_ledger_cmd (fun pp ->
|
||||||
|
Ledgerwallet_tezos.get_git_commit ~pp h) >>=? fun c ->
|
||||||
|
return_some c
|
||||||
|
else return_none
|
||||||
|
end >>=? fun git_commit ->
|
||||||
|
find_ledgers ?git_commit version
|
||||||
end
|
end
|
||||||
|
|
||||||
let find_ledgers ?pkh () =
|
let find_ledgers ?pkh () =
|
||||||
@ -352,11 +364,12 @@ let commands =
|
|||||||
iter_s begin fun { Ledger.device_info = { Hidapi.path ;
|
iter_s begin fun { Ledger.device_info = { Hidapi.path ;
|
||||||
manufacturer_string ;
|
manufacturer_string ;
|
||||||
product_string ; _ } ;
|
product_string ; _ } ;
|
||||||
of_curve ; version ; _ } ->
|
of_curve ; version ; git_commit ; _ } ->
|
||||||
let manufacturer = Option.unopt ~default:"(none)" manufacturer_string in
|
let manufacturer = Option.unopt ~default:"(none)" manufacturer_string in
|
||||||
let product = Option.unopt ~default:"(none)" product_string in
|
let product = Option.unopt ~default:"(none)" product_string in
|
||||||
cctxt#message "Found a %a application running on %s %s at [%s]."
|
cctxt#message "Found a %a (commit %s) application running on %s %s at [%s]."
|
||||||
Ledgerwallet_tezos.Version.pp version
|
Ledgerwallet_tezos.Version.pp version
|
||||||
|
(match git_commit with None -> "unknown" | Some c -> c)
|
||||||
manufacturer product path >>= fun () ->
|
manufacturer product path >>= fun () ->
|
||||||
let of_curve = List.rev of_curve in
|
let of_curve = List.rev of_curve in
|
||||||
cctxt#message
|
cctxt#message
|
||||||
|
@ -55,6 +55,7 @@ end
|
|||||||
|
|
||||||
type ins =
|
type ins =
|
||||||
| Version
|
| Version
|
||||||
|
| Git_commit
|
||||||
| Authorize_baking
|
| Authorize_baking
|
||||||
| Get_public_key
|
| Get_public_key
|
||||||
| Prompt_public_key
|
| Prompt_public_key
|
||||||
@ -72,6 +73,7 @@ let int_of_ins = function
|
|||||||
| Sign_unsafe -> 0x05
|
| Sign_unsafe -> 0x05
|
||||||
| Reset_high_watermark -> 0x06
|
| Reset_high_watermark -> 0x06
|
||||||
| Query_high_watermark -> 0x08
|
| Query_high_watermark -> 0x08
|
||||||
|
| Git_commit -> 0x09
|
||||||
|
|
||||||
type curve =
|
type curve =
|
||||||
| Ed25519
|
| Ed25519
|
||||||
@ -91,6 +93,11 @@ let get_version ?pp ?buf h =
|
|||||||
Transport.apdu ~msg:"get_version" ?pp ?buf h apdu >>=
|
Transport.apdu ~msg:"get_version" ?pp ?buf h apdu >>=
|
||||||
Version.read
|
Version.read
|
||||||
|
|
||||||
|
let get_git_commit ?pp ?buf h =
|
||||||
|
let apdu = Apdu.create (wrap_ins Git_commit) in
|
||||||
|
Transport.apdu ~msg:"get_git_commit" ?pp ?buf h apdu >>|
|
||||||
|
Cstruct.to_string
|
||||||
|
|
||||||
let write_path cs path =
|
let write_path cs path =
|
||||||
ListLabels.fold_left path ~init:cs ~f:begin fun cs i ->
|
ListLabels.fold_left path ~init:cs ~f:begin fun cs i ->
|
||||||
Cstruct.BE.set_uint32 cs 0 i ;
|
Cstruct.BE.set_uint32 cs 0 i ;
|
||||||
|
@ -32,6 +32,12 @@ val get_version :
|
|||||||
(** [get_version ?pp ?buf ledger] is the version information of the
|
(** [get_version ?pp ?buf ledger] is the version information of the
|
||||||
Ledger app running at [ledger]. *)
|
Ledger app running at [ledger]. *)
|
||||||
|
|
||||||
|
val get_git_commit :
|
||||||
|
?pp:Format.formatter -> ?buf:Cstruct.t ->
|
||||||
|
Hidapi.t -> (string, Transport.error) result
|
||||||
|
(** [get_git_commit ?pp ?buf ledger] is the git commit information of
|
||||||
|
the Ledger app running at [ledger]. *)
|
||||||
|
|
||||||
val get_public_key :
|
val get_public_key :
|
||||||
?prompt:bool ->
|
?prompt:bool ->
|
||||||
?pp:Format.formatter ->
|
?pp:Format.formatter ->
|
||||||
|
Loading…
Reference in New Issue
Block a user