From f3793783c96c2578e0e56593a0da43d267006778 Mon Sep 17 00:00:00 2001 From: Jonathan LEI Date: Sun, 15 Oct 2023 07:34:44 +0000 Subject: [PATCH] feat: option to disable private key warning Allows suppressing the warning message by setting the `STARKLI_NO_PLAIN_KEY_WARNING` environment variable. --- book/src/signers.md | 4 ++++ src/signer.rs | 20 ++++++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/book/src/signers.md b/book/src/signers.md index 4292a3a..a8081e2 100644 --- a/book/src/signers.md +++ b/book/src/signers.md @@ -50,3 +50,7 @@ starkli signer gen-keypair ``` For commands that expect a signer, you can then use the `--private-key ` option. Alternatively, you can set the `STARKNET_PRIVATE_KEY` environment variable to make command invocations easier. + +> ℹ️ **Note** +> +> Starkli shows a warning when you use plain-text private keys. If you know what you're doing, you can suppress this warning by setting the `STARKLI_NO_PLAIN_KEY_WARNING` to _anything_ but `false`. diff --git a/src/signer.rs b/src/signer.rs index 0721d08..b2f9feb 100644 --- a/src/signer.rs +++ b/src/signer.rs @@ -247,13 +247,21 @@ impl KeystoreTaskContent { impl PrivateKeyTaskContent { pub fn resolve(self) -> Result { + let print_warning = match std::env::var("STARKLI_NO_PLAIN_KEY_WARNING") { + Ok(value) => value == "false", + Err(_) => true, + }; + // TODO: change to recommend hardware wallets when they become available - eprintln!( - "{}", - "WARNING: using private key in plain text is highly insecure, and you should \ - ONLY do this for development. Consider using an encrypted keystore instead." - .bright_magenta() - ); + if print_warning { + eprintln!( + "{}", + "WARNING: using private key in plain text is highly insecure, and you should \ + ONLY do this for development. Consider using an encrypted keystore instead. \ + (Check out https://book.starkli.rs/signers on how to suppress this warning)" + .bright_magenta() + ); + } let private_key = FieldElement::from_hex_be(&self.key)?; let key = SigningKey::from_secret_scalar(private_key);