Client: adds check signature command
This commit is contained in:
parent
1b91d0929a
commit
f644d8f332
@ -134,6 +134,10 @@ let append ?watermark loc buf =
|
||||
sign ?watermark loc buf >>|? fun signature ->
|
||||
Signature.concat buf signature
|
||||
|
||||
let check ?watermark pk_uri signature buf =
|
||||
public_key pk_uri >>=? fun pk ->
|
||||
return (Signature.check ?watermark pk signature buf)
|
||||
|
||||
let register_key cctxt ?(force=false) (public_key_hash, pk_uri, sk_uri) name =
|
||||
Public_key.add ~force cctxt name pk_uri >>=? fun () ->
|
||||
Secret_key.add ~force cctxt name sk_uri >>=? fun () ->
|
||||
|
@ -48,6 +48,7 @@ module type SIGNER = sig
|
||||
sk_uri -> MBytes.t -> Signature.t tzresult Lwt.t
|
||||
(** [sign ?watermark sk data] is signature obtained by signing [data] with
|
||||
[sk]. *)
|
||||
|
||||
end
|
||||
|
||||
val register_signer : (module SIGNER) -> unit
|
||||
@ -70,6 +71,10 @@ val append :
|
||||
?watermark:Signature.watermark ->
|
||||
sk_uri -> MBytes.t -> MBytes.t tzresult Lwt.t
|
||||
|
||||
val check :
|
||||
?watermark:Signature.watermark ->
|
||||
pk_uri -> Signature.t -> MBytes.t -> bool tzresult Lwt.t
|
||||
|
||||
val register_key :
|
||||
#Client_context.wallet ->
|
||||
?force:bool ->
|
||||
|
@ -62,6 +62,15 @@ let commands () =
|
||||
Clic.parameter (fun _ data ->
|
||||
Lwt.return (Micheline_parser.no_parsing_error
|
||||
@@ Michelson_v1_parser.parse_expression data)) in
|
||||
let hash_parameter =
|
||||
Clic.parameter
|
||||
(fun _cctxt hash -> return @@ MBytes.of_string hash) in
|
||||
let signature_parameter =
|
||||
Clic.parameter
|
||||
(fun _cctxt s ->
|
||||
match Signature.of_b58check_opt s with
|
||||
| Some s -> return s
|
||||
| None -> failwith "Not given a valid signature") in
|
||||
[
|
||||
|
||||
command ~group ~desc: "Lists all programs in the library."
|
||||
@ -237,4 +246,31 @@ let commands () =
|
||||
cctxt#error "ill-formed data"
|
||||
end >>= return) ;
|
||||
|
||||
command ~group
|
||||
~desc: "Ask the node to check the signature of a hashed expression."
|
||||
(args1 (switch ~doc:"Use only exit codes" ~short:'q' ~long:"quiet" ()))
|
||||
(prefixes [ "check" ; "that" ]
|
||||
@@ Clic.param ~name:"hash" ~desc:"the hashed data"
|
||||
hash_parameter
|
||||
@@ prefixes [ "was" ; "signed" ; "by" ]
|
||||
@@ Client_keys.Public_key.alias_param
|
||||
~name:"key"
|
||||
@@ prefixes [ "to" ; "produce" ]
|
||||
@@ Clic.param ~name:"signature" ~desc:"the signature to check"
|
||||
signature_parameter
|
||||
@@ stop)
|
||||
(fun quiet hashed (_, key_locator) signature (cctxt : #Proto_alpha.full) ->
|
||||
Client_keys.check key_locator signature hashed >>=? fun res ->
|
||||
begin
|
||||
if quiet
|
||||
then if res
|
||||
then return ()
|
||||
else failwith "Not signed"
|
||||
else begin if res
|
||||
then cctxt#message "Signed with key"
|
||||
else cctxt#message "Not signed with key"
|
||||
end >>= return
|
||||
end
|
||||
) ;
|
||||
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user