Signer: add proper documentation to signer

This commit is contained in:
Grégoire Henry 2018-05-27 12:31:52 +02:00
parent f644d8f332
commit 1f662dd53b
7 changed files with 67 additions and 58 deletions

View File

@ -8,6 +8,7 @@
(**************************************************************************) (**************************************************************************)
type error += Unregistered_key_scheme of string type error += Unregistered_key_scheme of string
type error += Invalid_uri of Uri.t
let () = let () =
register_error_kind `Permanent register_error_kind `Permanent
@ -20,7 +21,17 @@ let () =
Format.fprintf ppf "No matching plugin for key scheme %s" s) Format.fprintf ppf "No matching plugin for key scheme %s" s)
Data_encoding.(obj1 (req "value" string)) Data_encoding.(obj1 (req "value" string))
(function Unregistered_key_scheme s -> Some s | _ -> None) (function Unregistered_key_scheme s -> Some s | _ -> None)
(fun s -> Unregistered_key_scheme s) (fun s -> Unregistered_key_scheme s) ;
register_error_kind `Permanent
~id: "cli.key.invalid_uri"
~title: "Invalid key uri"
~description: "A key has been provided with an invalid uri."
~pp:
(fun ppf s ->
Format.fprintf ppf "Cannot parse the key uri: %s" s)
Data_encoding.(obj1 (req "value" string))
(function Invalid_uri s -> Some (Uri.to_string s) | _ -> None)
(fun s -> Invalid_uri (Uri.of_string s))
module Public_key_hash = Client_aliases.Alias (struct module Public_key_hash = Client_aliases.Alias (struct
type t = Signature.Public_key_hash.t type t = Signature.Public_key_hash.t

View File

@ -12,6 +12,9 @@
type pk_uri = private Uri.t type pk_uri = private Uri.t
type sk_uri = private Uri.t type sk_uri = private Uri.t
type error += Unregistered_key_scheme of string
type error += Invalid_uri of Uri.t
module Public_key_hash : module Public_key_hash :
Client_aliases.Alias with type t = Signature.Public_key_hash.t Client_aliases.Alias with type t = Signature.Public_key_hash.t
module Public_key : module Public_key :

View File

@ -11,18 +11,28 @@ open Client_keys
let scheme = "https" let scheme = "https"
let title = "..." let title =
"Built-in tezos-signer using remote signer through hardcoded https requests."
let description = "..." let description =
"Valid locators are of this form:\n\
\ - https://host/tz1...\n\
\ - https://host:port/path/to/service/tz1...\n"
let parse uri = let parse uri =
let path = String.split '/' (Uri.path uri) in (* extract `tz1..` from the last component of the path *)
match List.rev path with assert (Uri.scheme uri = Some scheme) ;
| [] -> invalid_arg "..." let path = Uri.path uri in
| key :: rev_path -> let base, pkh =
Lwt.return (Signature.Public_key_hash.of_b58check key) >>=? fun key -> match String.rindex_opt path '/' with
return (Uri.with_path uri (String.concat "/" (List.rev rev_path)), | None ->
key) Uri.with_path uri "", path
| Some i ->
let pkh = String.sub path i (String.length path - i) in
let path = String.sub path 0 i in
Uri.with_path uri path, pkh in
Lwt.return (Signature.Public_key_hash.of_b58check pkh) >>=? fun pkh ->
return (base, pkh)
let public_key uri = let public_key uri =
parse (uri : pk_uri :> Uri.t) >>=? fun (base, pkh) -> parse (uri : pk_uri :> Uri.t) >>=? fun (base, pkh) ->

View File

@ -19,18 +19,9 @@ module Make(S : sig val default : Uri.t end) = struct
"Built-in tezos-signer using remote wallet." "Built-in tezos-signer using remote wallet."
let description = let description =
"Valid locators are one of these two forms:\n\ "Valid locators are of this form: remote://tz1...\n\
\ - unix [path to local signer socket] <remote key alias>\n\ The key will be queried to current remote signer, which can be \
\ - tcp [host] [port] <remote key alias>\n\ configured with the `--remote-signer` or `-R` options"
\ - https [host] [port] <remote key alias>\n\
All fields except the key can be of the form '$VAR', \
in which case their value is taken from environment variable \
VAR each time the key is accessed.\n\
Not specifiyng fields sets them to $TEZOS_SIGNER_UNIX_PATH, \
$TEZOS_SIGNER_TCP_HOST and $TEZOS_SIGNER_TCP_PORT, \
$TEZOS_SIGNER_HTTPS_HOST and $TEZOS_SIGNER_HTTPS_PORT, \
that get evaluated to default values '$HOME/.tezos-signer-socket', \
localhost and 6732, and can be set later on."
let get_remote () = let get_remote () =
match Uri.scheme S.default with match Uri.scheme S.default with
@ -42,10 +33,14 @@ module Make(S : sig val default : Uri.t end) = struct
module Remote = (val get_remote () : SIGNER) module Remote = (val get_remote () : SIGNER)
let key = let key =
match Uri.scheme S.default with match Uri.scheme S.default with
| Some "unix" | Some "tcp" -> | Some "unix" ->
(fun uri -> (fun uri ->
let key = Uri.path uri in let key = Uri.path uri in
Uri.add_query_param S.default ("key", [key])) Uri.add_query_param' S.default ("pkh", key))
| Some "tcp" ->
(fun uri ->
let key = Uri.path uri in
Uri.with_path S.default key)
| Some "https" -> | Some "https" ->
(fun uri -> (fun uri ->
let key = Uri.path uri in let key = Uri.path uri in
@ -63,8 +58,7 @@ module Make(S : sig val default : Uri.t end) = struct
(Client_keys.make_pk_uri (key (pk_uri : pk_uri :> Uri.t))) (Client_keys.make_pk_uri (key (pk_uri : pk_uri :> Uri.t)))
let neuterize sk_uri = let neuterize sk_uri =
Remote.neuterize return (Client_keys.make_pk_uri (sk_uri : sk_uri :> Uri.t))
(Client_keys.make_sk_uri (key (sk_uri : sk_uri :> Uri.t)))
let sign ?watermark sk_uri msg = let sign ?watermark sk_uri msg =
Remote.sign Remote.sign

View File

@ -38,13 +38,17 @@ module Unix = struct
let scheme = "unix" let scheme = "unix"
let title = "..." let title =
"Built-in tezos-signer using remote signer through hardcoded unix socket."
let description = "..." let description =
"Valid locators are of this form: unix:///path/to/socket?pkh=tz1..."
let parse uri = let parse uri =
match Uri.get_query_param uri "key" with assert (Uri.scheme uri = Some scheme) ;
| None -> invalid_arg "... FIXME ... B" trace (Invalid_uri uri) @@
match Uri.get_query_param uri "pkh" with
| None -> failwith "Missing the query parameter: 'pkh=tz1...'"
| Some key -> | Some key ->
Lwt.return (Signature.Public_key_hash.of_b58check key) >>=? fun key -> Lwt.return (Signature.Public_key_hash.of_b58check key) >>=? fun key ->
return (Lwt_utils_unix.Socket.Unix (Uri.path uri), key) return (Lwt_utils_unix.Socket.Unix (Uri.path uri), key)
@ -70,22 +74,24 @@ module Tcp = struct
let scheme = "tcp" let scheme = "tcp"
let title = "..." let title =
"Built-in tezos-signer using remote signer through hardcoded tcp socket."
let description = "..." let description =
"Valid locators are of this form: tcp://host:port/tz1..."
(* let init _cctxt = return () *)
let parse uri = let parse uri =
match Uri.get_query_param uri "key" with assert (Uri.scheme uri = Some scheme) ;
| None -> invalid_arg "... FIXME ... C" trace (Invalid_uri uri) @@
| Some key -> match Uri.host uri, Uri.port uri with
Lwt.return (Signature.Public_key_hash.of_b58check key) >>=? fun key -> | None, _ ->
match Uri.host uri, Uri.port uri with failwith "Missing host address"
| None, _ | _, None -> | _, None ->
invalid_arg "... FIXME ... C2" failwith "Missing host port"
| Some path, Some port -> | Some path, Some port ->
return (Lwt_utils_unix.Socket.Tcp (path, port), key) Lwt.return
(Signature.Public_key_hash.of_b58check (Uri.path uri)) >>=? fun pkh ->
return (Lwt_utils_unix.Socket.Tcp (path, port), pkh)
let public_key uri = let public_key uri =
parse (uri : pk_uri :> Uri.t) >>=? fun (path, pkh) -> parse (uri : pk_uri :> Uri.t) >>=? fun (path, pkh) ->

View File

@ -7,19 +7,6 @@
(* *) (* *)
(**************************************************************************) (**************************************************************************)
type error += Unknown_alias_key of string
let () =
register_error_kind `Permanent
~id: "signer.unknown_alias_key"
~title: "Unkwnon_alias_key"
~description: "A remote key does not exists"
~pp: (fun ppf s ->
Format.fprintf ppf "The key %s does not is not known on the remote signer" s)
Data_encoding.(obj1 (req "value" string))
(function Unknown_alias_key s -> Some s | _ -> None)
(fun s -> Unknown_alias_key s)
module Sign = struct module Sign = struct
module Request = struct module Request = struct

View File

@ -7,8 +7,6 @@
(* *) (* *)
(**************************************************************************) (**************************************************************************)
type error += Unknown_alias_key of string
module Sign : sig module Sign : sig
module Request : sig module Request : sig