From 50f367e27bebf7bdafc7356a918cce0e71910566 Mon Sep 17 00:00:00 2001 From: Vincent Bernardoff Date: Thu, 4 Oct 2018 19:34:51 +0800 Subject: [PATCH] Vendors/ledgerwallet: curve parsers and pretty-printers --- .../src/ledgerwallet_tezos.ml | 17 +++++++++++++++++ .../src/ledgerwallet_tezos.mli | 4 ++++ 2 files changed, 21 insertions(+) diff --git a/vendors/ocaml-ledger-wallet/src/ledgerwallet_tezos.ml b/vendors/ocaml-ledger-wallet/src/ledgerwallet_tezos.ml index 0b5bc8043..61efe165e 100644 --- a/vendors/ocaml-ledger-wallet/src/ledgerwallet_tezos.ml +++ b/vendors/ocaml-ledger-wallet/src/ledgerwallet_tezos.ml @@ -82,6 +82,23 @@ type curve = | Secp256k1 | Secp256r1 +let pp_curve ppf = function + | Ed25519 -> Format.pp_print_string ppf "ed25519" + | Secp256k1 -> Format.pp_print_string ppf "secp256k1" + | Secp256r1 -> Format.pp_print_string ppf "P-256" + +let pp_curve_short ppf = function + | Ed25519 -> Format.pp_print_string ppf "ed" + | Secp256k1 -> Format.pp_print_string ppf "secp" + | Secp256r1 -> Format.pp_print_string ppf "p2" + +let curve_of_string str = + match String.lowercase_ascii str with + | "ed" | "ed25519" -> Some Ed25519 + | "secp256k1" -> Some Secp256k1 + | "p256" | "p-256" | "secp256r1" -> Some Secp256r1 + | _ -> None + let int_of_curve = function | Ed25519 -> 0x00 | Secp256k1 -> 0x01 diff --git a/vendors/ocaml-ledger-wallet/src/ledgerwallet_tezos.mli b/vendors/ocaml-ledger-wallet/src/ledgerwallet_tezos.mli index b648e4d9a..579121336 100644 --- a/vendors/ocaml-ledger-wallet/src/ledgerwallet_tezos.mli +++ b/vendors/ocaml-ledger-wallet/src/ledgerwallet_tezos.mli @@ -26,6 +26,10 @@ type curve = | Secp256k1 | Secp256r1 +val curve_of_string : string -> curve option +val pp_curve : Format.formatter -> curve -> unit +val pp_curve_short : Format.formatter -> curve -> unit + val get_version : ?pp:Format.formatter -> ?buf:Cstruct.t -> Hidapi.t -> (Version.t, Transport.error) result