Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file remote.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)(* *)(* Permission is hereby granted, free of charge, to any person obtaining a *)(* copy of this software and associated documentation files (the "Software"),*)(* to deal in the Software without restriction, including without limitation *)(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *)(* and/or sell copies of the Software, and to permit persons to whom the *)(* Software is furnished to do so, subject to the following conditions: *)(* *)(* The above copyright notice and this permission notice shall be included *)(* in all copies or substantial portions of the Software. *)(* *)(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*)(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *)(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *)(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*)(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *)(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *)(* DEALINGS IN THE SOFTWARE. *)(* *)(*****************************************************************************)openClient_keysletscheme="remote"moduleMake(RPC_client:RPC_client.S)(S:sigvaldefault:Uri.tvalauthenticate:Tezos_crypto.Signature.Public_key_hash.tlist->Bytes.t->Tezos_crypto.Signature.ttzresultLwt.tvallogger:RPC_client.loggerend)=structletscheme=schemelettitle="Built-in tezos-signer using remote wallet."letdescription="Valid locators are of the form\n\
\ - remote://tz1...\n\
The key will be queried to current remote signer, which can be configured \
with the `--remote-signer` or `-R` options, or by defining the following \
environment variables:\n\
\ - $TEZOS_SIGNER_UNIX_PATH,\n\
\ - $TEZOS_SIGNER_TCP_HOST and $TEZOS_SIGNER_TCP_PORT (default: 7732),\n\
\ - $TEZOS_SIGNER_HTTP_HOST and $TEZOS_SIGNER_HTTP_PORT (default: 6732),\n\
\ - $TEZOS_SIGNER_HTTPS_HOST and $TEZOS_SIGNER_HTTPS_PORT (default: 443)."includeClient_keys.Signature_typemoduleSocket=Socket.Make(S)moduleHttp=Http.Make(RPC_client)(S)moduleHttps=Https.Make(RPC_client)(S)letget_remote()=matchUri.schemeS.defaultwith|Some"unix"->(moduleSocket.Unix:SIGNER)|Some"tcp"->(moduleSocket.Tcp:SIGNER)|Some"http"->(moduleHttp:SIGNER)|Some"https"->(moduleHttps:SIGNER)|_->assertfalsemoduleRemote=(valget_remote():SIGNER)letkey=matchUri.schemeS.defaultwith|Some"unix"->funuri->letkey=Uri.pathuriinUri.add_query_param'S.default("pkh",key)|Some"tcp"->funuri->letkey=Uri.pathuriinUri.with_pathS.defaultkey|Some("https"|"http")->(funuri->letkey=Uri.pathuriinmatchUri.pathS.defaultwith|""->Uri.with_pathS.defaultkey|path->Uri.with_pathS.default(path^"/"^key))|_->assertfalseletpublic_keypk_uri=letopenLwt_result_syntaxinlet*?v=Client_keys.make_pk_uri(key(pk_uri:pk_uri:>Uri.t))inRemote.public_keyvletpublic_key_hashpk_uri=letopenLwt_result_syntaxinlet*?v=Client_keys.make_pk_uri(key(pk_uri:pk_uri:>Uri.t))inRemote.public_key_hashvletimport_secret_key~io:_=public_key_hashletneuterizesk_uri=letopenLwt_result_syntaxinlet*?v=Client_keys.make_pk_uri(sk_uri:sk_uri:>Uri.t)inreturnvletsign?watermarksk_urimsg=letopenLwt_result_syntaxinlet*?sk_uri=Client_keys.make_sk_uri(key(sk_uri:sk_uri:>Uri.t))inRemote.sign?watermarksk_urimsgletdeterministic_noncesk_urimsg=letopenLwt_result_syntaxinlet*?sk_uri=Client_keys.make_sk_uri(key(sk_uri:sk_uri:>Uri.t))inRemote.deterministic_noncesk_urimsgletdeterministic_nonce_hashsk_urimsg=letopenLwt_result_syntaxinlet*?sk_uri=Client_keys.make_sk_uri(key(sk_uri:sk_uri:>Uri.t))inRemote.deterministic_nonce_hashsk_urimsgletsupports_deterministic_noncessk_uri=letopenLwt_result_syntaxinlet*?v=Client_keys.make_sk_uri(key(sk_uri:sk_uri:>Uri.t))inRemote.supports_deterministic_noncesvendletmake_sksk=Client_keys.make_sk_uri(Uri.make~scheme~path:(Tezos_crypto.Signature.Secret_key.to_b58checksk)())letmake_pkpk=Client_keys.make_pk_uri(Uri.make~scheme~path:(Tezos_crypto.Signature.Public_key.to_b58checkpk)())letread_base_uri_from_env()=letopenLwt_result_syntaxinmatch(Sys.getenv_opt"TEZOS_SIGNER_UNIX_PATH",Sys.getenv_opt"TEZOS_SIGNER_TCP_HOST",Sys.getenv_opt"TEZOS_SIGNER_HTTP_HOST",Sys.getenv_opt"TEZOS_SIGNER_HTTPS_HOST")with|None,None,None,None->return_none|Somepath,None,None,None->return_some(Socket.make_unix_basepath)|None,Somehost,None,None->(tryletport=matchSys.getenv_opt"TEZOS_SIGNER_TCP_PORT"with|None->7732|Someport->int_of_stringportinreturn_some(Socket.make_tcp_basehostport)withInvalid_argument_->failwith"Failed to parse TEZOS_SIGNER_TCP_PORT.@.")|None,None,Somehost,None->(tryletport=matchSys.getenv_opt"TEZOS_SIGNER_HTTP_PORT"with|None->6732|Someport->int_of_stringportinreturn_some(Http.make_basehostport)withInvalid_argument_->failwith"Failed to parse TEZOS_SIGNER_HTTP_PORT.@.")|None,None,None,Somehost->(tryletport=matchSys.getenv_opt"TEZOS_SIGNER_HTTPS_PORT"with|None->443|Someport->int_of_stringportinreturn_some(Https.make_basehostport)withInvalid_argument_->failwith"Failed to parse TEZOS_SIGNER_HTTPS_PORT.@.")|_,_,_,_->failwith"Only one the following environment variable must be defined: \
TEZOS_SIGNER_UNIX_PATH, TEZOS_SIGNER_TCP_HOST, \
TEZOS_SIGNER_HTTP_HOST, TEZOS_SIGNER_HTTPS_HOST@."typeerror+=Invalid_remote_signerofstringlet()=register_error_kind`Branch~id:"invalid_remote_signer"~title:"Unexpected URI fot remote signer"~description:"The provided remote signer is invalid."~pp:(funppfs->Format.fprintfppf"@[<v 0>Value '%s' is not a valid URI for a remote signer.@,\
Supported URIs for remote signers are of the form:@,\
\ - unix:///path/to/socket/file@,\
\ - tcp://host:port@,\
\ - http://host[:port][/prefix]@,\
\ - https://host[:port][/prefix]@]"s)Data_encoding.(obj1(req"uri"string))(functionInvalid_remote_signers->Somes|_->None)(funs->Invalid_remote_signers)letparse_base_uris=(* FIXME: documentation for [Uri.of_string] doesn't mention any exception.
However, from reading the code it seems like [Not_found] can be raised
(via some internal call to [Re.exec]. *)matchUri.of_stringswith(* We keep [Invalid_argument] but this needs investigation because of the
above comment *)|exceptionInvalid_argumentmsg->error_with"Malformed URI: %s"msg|exceptionNot_found->error_with"Malformed URI"|uri->(matchUri.schemeuriwith|Some"http"->Okuri|Some"https"->Okuri|Some"tcp"->Okuri|Some"unix"->Okuri|Somescheme->error_with"Unknown scheme: %s"scheme|None->error_with"Unknown scheme: <empty>")letparse_base_uris=parse_base_uris|>record_trace(Invalid_remote_signers)|>Lwt.return