123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2020 Metastate AG <hello@metastate.ch> *)(* *)(* 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_proto_utilsletgroup={Tezos_clic.name="utilities";title="Utility Commands"}letunsigned_block_header_param=letopenTezos_clicinparam~name:"unsigned block header"~desc:"A hex or JSON encoded unsigned block header"@@parameter(fun_s->letbytes_opt=`Hexs|>Hex.to_bytesinletenc=Protocol.Alpha_context.Block_header.unsigned_encodinginOption.bindbytes_opt(Data_encoding.Binary.of_bytes_optenc)|>function|Somes->returns|None->(leterror=Exn(Failure"Cannot decode unsigned block header: is it valid JSON or \
hexadecimal?")inletopenData_encoding.Jsoninfrom_strings|>function|Error_->failerror|Okjson->(trydestructencjson|>returnwith_->failerror)))letcommands()=letopenTezos_clicinletstring_param~name~desc=param~name~descClient_proto_args.string_parameterinletblock_arg=default_arg~long:"branch"~short:'b'~placeholder:"hash|tag"~doc:"Block hash used to create the no-op operation to sign (possible tags \
are 'head' and 'genesis'). Defaults to 'genesis'. Note that the the \
genesis block hash is network-dependent."~default:(Block_services.to_string`Genesis)(Client_config.block_parameter())in[command~group~desc:"Sign a message and display it using the failing_noop operation. This \
operation is not executable in the protocol. Please note that \
signing/checking an arbitrary message in itself is not sufficient to \
verify a key ownership"(args1block_arg)(prefixes["sign";"message"]@@string_param~name:"message"~desc:"message to sign"@@prefixes["for"]@@Client_keys_v0.Secret_key.source_param~name:"src"~desc:"name of the signer contract"@@stop)(funblock_headmessagesrc_skcctxt->Shell_services.Blocks.hashcctxt~chain:cctxt#chain~block:block_head()>>=?funblock->sign_messagecctxt~src_sk~block~message>>=?funsignature->cctxt#message"Signature: %a"Tezos_crypto.Signature.V0.ppsignature>>=fun()->return_unit);command~group~desc:"Check the signature of an arbitrary message using the failing_noop \
operation. Please note that signing/checking an arbitrary message in \
itself is not sufficient to verify a key ownership."(args2block_arg(switch~doc:"Use only exit codes"~short:'q'~long:"quiet"()))(prefixes["check";"that";"message"]@@string_param~name:"message"~desc:"signed message"@@prefixes["was";"signed";"by"]@@Client_keys_v0.Public_key.alias_param~name:"signer"~desc:"name of the signer contract"@@prefixes["to";"produce"]@@param~name:"signature"~desc:"the signature to check"Client_proto_args.signature_parameter@@stop)(fun(block_head,quiet)message(_,(key_locator,_))signature(cctxt:#Protocol_client_context.full)->Shell_services.Blocks.hashcctxt~chain:cctxt#chain~block:block_head()>>=?funblock->check_messagecctxt~key_locator~block~quiet~message~signature>>=?function|false->cctxt#error"invalid signature"|true->ifquietthenreturn_unitelsecctxt#message"Signature check successful">>=fun()->return_unit);command~group~desc:"Sign an arbitrary unsigned block header for a given delegate and \
return the signed block."no_options(prefixes["sign";"block"]@@unsigned_block_header_param@@prefixes["for"]@@Client_keys_v0.Public_key_hash.source_param~name:"delegate"~desc:"signing delegate"@@stop)(fun()unsigned_block_headerdelegate(cctxt:#Protocol_client_context.full)->letunsigned_header=Data_encoding.Binary.to_bytes_exnProtocol.Alpha_context.Block_header.unsigned_encodingunsigned_block_headerinShell_services.Chain.chain_idcctxt~chain:cctxt#chain()>>=?funchain_id->Client_keys_v0.get_keycctxtdelegate>>=?fun(_,_,sk)->Client_keys_v0.signcctxt~watermark:(Protocol.Alpha_context.Block_header.to_watermark(Block_headerchain_id))skunsigned_header>>=?funs->cctxt#message"%a"Hex.pp(Tezos_crypto.Signature.V0.to_hexs)>>=return);]