Commit 1f662dd5 authored by Grégoire Henry's avatar Grégoire Henry

Signer: add proper documentation to signer

parent f644d8f3
......@@ -8,6 +8,7 @@
(**************************************************************************)
type error += Unregistered_key_scheme of string
type error += Invalid_uri of Uri.t
let () =
register_error_kind `Permanent
......@@ -20,7 +21,17 @@ let () =
Format.fprintf ppf "No matching plugin for key scheme %s" s)
Data_encoding.(obj1 (req "value" string))
(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
type t = Signature.Public_key_hash.t
......
......@@ -12,6 +12,9 @@
type pk_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 :
Client_aliases.Alias with type t = Signature.Public_key_hash.t
module Public_key :
......
......@@ -11,18 +11,28 @@ open Client_keys
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 path = String.split '/' (Uri.path uri) in
match List.rev path with
| [] -> invalid_arg "..."
| key :: rev_path ->
Lwt.return (Signature.Public_key_hash.of_b58check key) >>=? fun key ->
return (Uri.with_path uri (String.concat "/" (List.rev rev_path)),
key)
(* extract `tz1..` from the last component of the path *)
assert (Uri.scheme uri = Some scheme) ;
let path = Uri.path uri in
let base, pkh =
match String.rindex_opt path '/' with
| None ->
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 =
parse (uri : pk_uri :> Uri.t) >>=? fun (base, pkh) ->
......
......@@ -19,18 +19,9 @@ module Make(S : sig val default : Uri.t end) = struct
"Built-in tezos-signer using remote wallet."
let description =
"Valid locators are one of these two forms:\n\
\ - unix [path to local signer socket] <remote key alias>\n\
\ - tcp [host] [port] <remote key alias>\n\
\ - 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."
"Valid locators are of this form: remote://tz1...\n\
The key will be queried to current remote signer, which can be \
configured with the `--remote-signer` or `-R` options"
let get_remote () =
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)
let key =
match Uri.scheme S.default with
| Some "unix" | Some "tcp" ->
| Some "unix" ->
(fun uri ->
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" ->
(fun uri ->
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)))
let neuterize sk_uri =
Remote.neuterize
(Client_keys.make_sk_uri (key (sk_uri : sk_uri :> Uri.t)))
return (Client_keys.make_pk_uri (sk_uri : sk_uri :> Uri.t))
let sign ?watermark sk_uri msg =
Remote.sign
......
......@@ -38,13 +38,17 @@ module Unix = struct
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 =
match Uri.get_query_param uri "key" with
| None -> invalid_arg "... FIXME ... B"
assert (Uri.scheme uri = Some scheme) ;
trace (Invalid_uri uri) @@
match Uri.get_query_param uri "pkh" with
| None -> failwith "Missing the query parameter: 'pkh=tz1...'"
| Some key ->
Lwt.return (Signature.Public_key_hash.of_b58check key) >>=? fun key ->
return (Lwt_utils_unix.Socket.Unix (Uri.path uri), key)
......@@ -70,22 +74,24 @@ module Tcp = struct
let scheme = "tcp"
let title = "..."
let title =
"Built-in tezos-signer using remote signer through hardcoded tcp socket."
let description = "..."
(* let init _cctxt = return () *)
let description =
"Valid locators are of this form: tcp://host:port/tz1..."
let parse uri =
match Uri.get_query_param uri "key" with
| None -> invalid_arg "... FIXME ... C"
| Some key ->
Lwt.return (Signature.Public_key_hash.of_b58check key) >>=? fun key ->
match Uri.host uri, Uri.port uri with
| None, _ | _, None ->
invalid_arg "... FIXME ... C2"
| Some path, Some port ->
return (Lwt_utils_unix.Socket.Tcp (path, port), key)
assert (Uri.scheme uri = Some scheme) ;
trace (Invalid_uri uri) @@
match Uri.host uri, Uri.port uri with
| None, _ ->
failwith "Missing host address"
| _, None ->
failwith "Missing host port"
| Some path, Some port ->
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 =
parse (uri : pk_uri :> Uri.t) >>=? fun (path, pkh) ->
......
......@@ -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 Request = struct
......
......@@ -7,8 +7,6 @@
(* *)
(**************************************************************************)
type error += Unknown_alias_key of string
module Sign : sig
module Request : sig
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment