From 9f5ebc659e70a1c5313fe20d563a472f8ffd0f7a Mon Sep 17 00:00:00 2001 From: Vincent Bernardoff Date: Sat, 17 Nov 2018 23:07:53 +0100 Subject: [PATCH] Client: add `encrypt secret key` client command --- src/lib_client_commands/client_keys_commands.ml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/lib_client_commands/client_keys_commands.ml b/src/lib_client_commands/client_keys_commands.ml index ab9e2b646..fe8a43451 100644 --- a/src/lib_client_commands/client_keys_commands.ml +++ b/src/lib_client_commands/client_keys_commands.ml @@ -271,6 +271,23 @@ let commands version : Client_context.io_wallet Clic.command list = gen_keys_containing ~encrypted ~force ~prefix ~containing ~name cctxt) end ; + command ~group ~desc: "Encrypt an unencrypted secret key." + no_options + (prefixes [ "encrypt" ; "secret" ; "key" ] + @@ stop) + (fun () (cctxt : Client_context.io_wallet) -> + cctxt#prompt_password "Enter unencrypted secret key: " >>=? fun sk_uri -> + let sk_uri = Uri.of_string (MBytes.to_string sk_uri) in + begin match Uri.scheme sk_uri with + | None | Some "unencrypted" -> return_unit + | _ -> failwith "This command can only be used with the \"unencrypted\" scheme" + end >>=? fun () -> + Lwt.return (Signature.Secret_key.of_b58check (Uri.path sk_uri)) >>=? fun sk -> + Tezos_signer_backends.Encrypted.encrypt cctxt sk >>=? fun sk_uri -> + cctxt#message "Encrypted secret key %a" Uri.pp_hum (sk_uri :> Uri.t) >>= fun () -> + return_unit + ) ; + command ~group ~desc: "Add a secret key to the wallet." (args1 (Secret_key.force_switch ())) (prefix "import"