Skip to content

Commit

Permalink
feat: option to disable private key warning
Browse files Browse the repository at this point in the history
Allows suppressing the warning message by setting the
`STARKLI_NO_PLAIN_KEY_WARNING` environment variable.
  • Loading branch information
xJonathanLEI committed Oct 15, 2023
1 parent 640b76f commit f379378
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
4 changes: 4 additions & 0 deletions book/src/signers.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,7 @@ starkli signer gen-keypair
```

For commands that expect a signer, you can then use the `--private-key <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`.
20 changes: 14 additions & 6 deletions src/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,21 @@ impl KeystoreTaskContent {

impl PrivateKeyTaskContent {
pub fn resolve(self) -> Result<AnySigner> {
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);
Expand Down

0 comments on commit f379378

Please sign in to comment.