mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-10-26 15:13:13 +03:00
feat: support safely input private key
This commit is contained in:
parent
6126189e59
commit
0466f9bdf0
22
Cargo.lock
generated
22
Cargo.lock
generated
@ -1442,6 +1442,7 @@ dependencies = [
|
||||
"rand_chacha",
|
||||
"rand_core",
|
||||
"reqwest",
|
||||
"rpassword",
|
||||
"rusty-hook",
|
||||
"self_update 0.39.0",
|
||||
"serde",
|
||||
@ -2194,6 +2195,27 @@ dependencies = [
|
||||
"windows-sys 0.48.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rpassword"
|
||||
version = "7.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "80472be3c897911d0137b2d2b9055faf6eeac5b14e324073d83bc17b191d7e3f"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"rtoolbox",
|
||||
"windows-sys 0.48.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rtoolbox"
|
||||
version = "0.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c247d24e63230cdb56463ae328478bd5eac8b8faa8c69461a77e8e323afac90e"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"windows-sys 0.48.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc-demangle"
|
||||
version = "0.1.23"
|
||||
|
@ -157,6 +157,9 @@ features = [ "fmt" ]
|
||||
[dependencies.zip]
|
||||
version = "^0.6"
|
||||
|
||||
[dependencies.rpassword]
|
||||
version = "7.3.1"
|
||||
|
||||
[target."cfg(windows)".dependencies.ansi_term]
|
||||
version = "0.12.1"
|
||||
|
||||
|
@ -178,4 +178,11 @@ create_messages!(
|
||||
msg: format!("Failed to write file.\nIO Error: {error}"),
|
||||
help: None,
|
||||
}
|
||||
|
||||
@backtraced
|
||||
failed_to_execute_account {
|
||||
args: (error: impl Display),
|
||||
msg: format!("Failed to execute the `account` command.\nSnarkVM Error: {error}"),
|
||||
help: None,
|
||||
}
|
||||
);
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
use super::*;
|
||||
use leo_package::root::Env;
|
||||
use snarkvm::prelude::{Address, PrivateKey, ViewKey};
|
||||
use snarkvm::prelude::{Address, FromStr, PrivateKey, ViewKey};
|
||||
|
||||
use rand::SeedableRng;
|
||||
use rand_chacha::ChaChaRng;
|
||||
@ -35,8 +35,6 @@ pub enum Account {
|
||||
},
|
||||
/// Derive an Aleo account from a private key.
|
||||
Import {
|
||||
/// Private key plaintext
|
||||
private_key: PrivateKey<CurrentNetwork>,
|
||||
/// Write the private key to the .env file.
|
||||
#[clap(short = 'w', long)]
|
||||
write: bool,
|
||||
@ -77,7 +75,9 @@ impl Command for Account {
|
||||
write_to_env_file(private_key, &ctx)?;
|
||||
}
|
||||
}
|
||||
Account::Import { private_key, write } => {
|
||||
Account::Import { write } => {
|
||||
let private_key_input = rpassword::prompt_password("Please enter your private key: ").unwrap();
|
||||
let private_key = FromStr::from_str(&private_key_input).map_err(CliError::failed_to_execute_account)?;
|
||||
// Derive the view key and address and print to stdout.
|
||||
print_keys(private_key)?;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user