diff --git a/src/lib_signer_backends/ledger.ml b/src/lib_signer_backends/ledger.ml index ec09f9432f84909159492e715ea95937a8c5db4f..e8265e313694e373b7824a354924102c6cdcbafc 100644 --- a/src/lib_signer_backends/ledger.ml +++ b/src/lib_signer_backends/ledger.ml @@ -51,7 +51,7 @@ module Bip32_path = struct let pp_node ppf node = match is_hard node with - | true -> Fmt.pf ppf "%ld'" (unhard node) + | true -> Fmt.pf ppf "%ldh" (unhard node) | false -> Fmt.pf ppf "%ld" node let string_of_node = Fmt.to_to_string pp_node @@ -332,12 +332,12 @@ module Ledger_uri = struct type t = [ `Ledger of Ledger_id.t | `Ledger_account of Ledger_account.t ] - let int32_of_path_element_exn ?(allow_weak = false) x = + let int32_of_path_element_exn ~allow_weak x = let failf ppf = Printf.ksprintf Pervasives.failwith ppf in let len = String.length x in match String.get x (len - 1) with | exception _ -> failf "Empty path element" - | '\'' -> + | '\'' | 'h' -> let intpart = String.sub x 0 (len - 1) in begin match Int32.of_string_opt intpart with | Some i -> Bip32_path.hard i @@ -349,14 +349,18 @@ module Ledger_uri = struct | None -> failf "Path is not a non-hardened integer: %S" x end | _ -> - (* Future derivation schemes will support weak paths, not for now. *) - failf "Non-hardened paths are not allowed (%S)" x + failf "Non-hardened paths are not allowed for this derivation scheme (%S)" x let parse_animals animals = match String.split '-' animals with | [c; t; h; d] -> Some { Ledger_names.c ; t ; h ; d } | _ -> None + let derivation_supports_weak_paths = function + | Ledgerwallet_tezos.Ed25519 -> false + | Ledgerwallet_tezos.Secp256k1 -> true + | Ledgerwallet_tezos.Secp256r1 -> true + let parse ?allow_weak uri : t tzresult Lwt.t = let host = Uri.host uri in begin match Option.apply host @@ -375,9 +379,12 @@ module Ledger_uri = struct match Ledgerwallet_tezos.curve_of_string s with | Some curve -> curve, tl | None -> Ledger_id.curve, s :: tl in + let actually_allow_weak = match allow_weak with + | None -> derivation_supports_weak_paths curve + | Some x -> x in begin try return (List.map - (int32_of_path_element_exn ?allow_weak) + (int32_of_path_element_exn ~allow_weak:actually_allow_weak) more_path) with Failure s -> failwith "Failed to parse Curve/BIP32 path from %s (%s): %s" @@ -671,7 +678,7 @@ let generic_commands group = Clic.[ List.iter (fun curve -> fprintf ppf " tezos-client import secret key \ - ledger_%s \"ledger://%a/%a/0'/0'\"" + ledger_%s \"ledger://%a/%a/0h/0h\"" (Sys.getenv_opt "USER" |> Option.unopt ~default:"user") Ledger_id.pp ledger_id Ledgerwallet_tezos.pp_curve curve ;