2018-05-26 15:41:16 +04:00
|
|
|
(**************************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* Copyright (c) 2014 - 2018. *)
|
|
|
|
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
|
|
|
|
(* *)
|
|
|
|
(* All rights reserved. No warranty, explicit or implicit, provided. *)
|
|
|
|
(* *)
|
|
|
|
(**************************************************************************)
|
|
|
|
|
|
|
|
open Client_keys
|
|
|
|
|
|
|
|
let scheme = "remote"
|
|
|
|
|
|
|
|
module Make(S : sig val default : Uri.t end) = struct
|
|
|
|
|
|
|
|
let scheme = scheme
|
|
|
|
|
|
|
|
let title =
|
|
|
|
"Built-in tezos-signer using remote wallet."
|
|
|
|
|
|
|
|
let description =
|
2018-05-27 14:31:52 +04:00
|
|
|
"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"
|
2018-05-26 15:41:16 +04:00
|
|
|
|
|
|
|
let get_remote () =
|
|
|
|
match Uri.scheme S.default with
|
|
|
|
| Some "unix" -> (module Socket.Unix : SIGNER)
|
|
|
|
| Some "tcp" -> (module Socket.Tcp : SIGNER)
|
|
|
|
| Some "https" -> (module Https : SIGNER)
|
|
|
|
| _ -> assert false
|
|
|
|
|
|
|
|
module Remote = (val get_remote () : SIGNER)
|
|
|
|
let key =
|
|
|
|
match Uri.scheme S.default with
|
2018-05-27 14:31:52 +04:00
|
|
|
| Some "unix" ->
|
2018-05-26 15:41:16 +04:00
|
|
|
(fun uri ->
|
|
|
|
let key = Uri.path uri in
|
2018-05-27 14:31:52 +04:00
|
|
|
Uri.add_query_param' S.default ("pkh", key))
|
|
|
|
| Some "tcp" ->
|
|
|
|
(fun uri ->
|
|
|
|
let key = Uri.path uri in
|
|
|
|
Uri.with_path S.default key)
|
2018-05-26 15:41:16 +04:00
|
|
|
| Some "https" ->
|
|
|
|
(fun uri ->
|
|
|
|
let key = Uri.path uri in
|
|
|
|
match Uri.path S.default with
|
|
|
|
| "" -> Uri.with_path S.default key
|
|
|
|
| path -> Uri.with_path S.default (path ^ "/" ^ key))
|
|
|
|
| _ -> assert false
|
|
|
|
|
|
|
|
let public_key pk_uri =
|
|
|
|
Remote.public_key
|
|
|
|
(Client_keys.make_pk_uri (key (pk_uri : pk_uri :> Uri.t)))
|
|
|
|
|
|
|
|
let public_key_hash pk_uri =
|
|
|
|
Remote.public_key_hash
|
|
|
|
(Client_keys.make_pk_uri (key (pk_uri : pk_uri :> Uri.t)))
|
|
|
|
|
|
|
|
let neuterize sk_uri =
|
2018-05-27 14:31:52 +04:00
|
|
|
return (Client_keys.make_pk_uri (sk_uri : sk_uri :> Uri.t))
|
2018-05-26 15:41:16 +04:00
|
|
|
|
|
|
|
let sign ?watermark sk_uri msg =
|
|
|
|
Remote.sign
|
|
|
|
?watermark
|
|
|
|
(Client_keys.make_sk_uri (key (sk_uri : sk_uri :> Uri.t)))
|
|
|
|
msg
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
let make_sk sk =
|
|
|
|
Client_keys.make_sk_uri
|
|
|
|
(Uri.make ~scheme ~path:(Signature.Secret_key.to_b58check sk) ())
|
|
|
|
|
|
|
|
let make_pk pk =
|
|
|
|
Client_keys.make_pk_uri
|
|
|
|
(Uri.make ~scheme ~path:(Signature.Public_key.to_b58check pk) ())
|