123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179(*****************************************************************************)(* *)(* 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(cctxt:#Client_context.full)s->letopenLwt_result_syntaxinletbytes_opt=`Hexs|>Hex.to_bytesinletenc=Protocol.Alpha_context.Block_header.unsigned_encodinginOption.bindbytes_opt(Data_encoding.Binary.of_bytes_optenc)|>function|Somes->returns|None->(letopenData_encoding.Jsoninleterror="Cannot decode unsigned block header: is it valid JSON or \
hexadecimal?"infrom_strings|>function|Error_->cctxt#error"%s"error|Okjson->(trydestructencjson|>returnwith_->cctxt#error"%s"error)))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.Secret_key.source_param~name:"src"~desc:"name of the signer contract"@@stop)(funblock_headmessagesrc_skcctxt->letopenLwt_result_syntaxinlet*block=Shell_services.Blocks.hashcctxt~chain:cctxt#chain~block:block_head()inlet*signature=sign_messagecctxt~src_sk~block~messageinlet*!()=cctxt#message"Signature: %a"Signature.ppsignatureinreturn_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.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)->letopenLwt_result_syntaxinlet*block=Shell_services.Blocks.hashcctxt~chain:cctxt#chain~block:block_head()inlet*check=check_messagecctxt~key_locator~block~quiet~message~signatureinifcheckthenifquietthenreturn_unitelselet*!()=cctxt#message"Signature check successful"inreturn_unitelsecctxt#error"invalid signature");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.Public_key_hash.source_param~name:"delegate"~desc:"signing delegate"@@stop)(fun()unsigned_block_headerdelegate(cctxt:#Protocol_client_context.full)->letopenLwt_result_syntaxinletunsigned_header=Data_encoding.Binary.to_bytes_exnProtocol.Alpha_context.Block_header.unsigned_encodingunsigned_block_headerinlet*chain_id=Shell_services.Chain.chain_idcctxt~chain:cctxt#chain()inlet*_,_,sk=Client_keys.get_keycctxtdelegateinlet*s=Client_keys.signcctxt~watermark:(Protocol.Alpha_context.Block_header.to_watermark(Block_headerchain_id))skunsigned_headerinlet*!()=cctxt#message"%a"Hex.pp(Signature.to_hexs)inreturn_unit);]