diff --git a/Cargo.lock b/Cargo.lock index 597b157dd32..6c392206988 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2948,6 +2948,7 @@ dependencies = [ "fuel-core-types", "libp2p-identity 0.2.5", "serde_json", + "termion", ] [[package]] @@ -5412,6 +5413,12 @@ dependencies = [ "syn 2.0.38", ] +[[package]] +name = "numtoa" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef" + [[package]] name = "object" version = "0.32.1" @@ -6492,6 +6499,15 @@ dependencies = [ "bitflags 1.3.2", ] +[[package]] +name = "redox_termios" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8440d8acb4fd3d277125b4bd01a6f38aee8d814b3b5fc09b3f2b825d37d3fe8f" +dependencies = [ + "redox_syscall 0.2.16", +] + [[package]] name = "redox_users" version = "0.4.3" @@ -7808,6 +7824,18 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "termion" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "659c1f379f3408c7e5e84c7d0da6d93404e3800b6b9d063ba24436419302ec90" +dependencies = [ + "libc", + "numtoa", + "redox_syscall 0.2.16", + "redox_termios", +] + [[package]] name = "termtree" version = "0.4.1" diff --git a/crates/keygen/Cargo.toml b/crates/keygen/Cargo.toml index b470d770d7f..d81b7d21055 100644 --- a/crates/keygen/Cargo.toml +++ b/crates/keygen/Cargo.toml @@ -16,3 +16,4 @@ clap = { workspace = true, features = ["derive", "env"] } fuel-core-types = { workspace = true, features = ["serde", "random"] } libp2p-identity = { version = "0.2.4", features = ["secp256k1", "peerid"] } serde_json = { workspace = true, features = ["raw_value"] } +termion = "2.0.1" diff --git a/crates/keygen/src/keygen.rs b/crates/keygen/src/keygen.rs index 151461c16f7..89536a93562 100644 --- a/crates/keygen/src/keygen.rs +++ b/crates/keygen/src/keygen.rs @@ -20,6 +20,10 @@ use libp2p_identity::{ }; use serde_json::json; use std::{ + io::{ + Read, + Write, + }, ops::Deref, str::FromStr, }; @@ -126,6 +130,24 @@ impl ParseSecret { } } +fn wait_for_keypress() { + let mut single_key = [0u8]; + std::io::stdin().read_exact(&mut single_key).unwrap(); +} + +fn display_string_discreetly( + discreet_string: &str, + continue_message: &str, +) -> anyhow::Result<()> { + use termion::screen::IntoAlternateScreen; + let mut screen = std::io::stdout().into_alternate_screen()?; + writeln!(screen, "{discreet_string}")?; + screen.flush()?; + println!("{continue_message}"); + wait_for_keypress(); + Ok(()) +} + fn print_value(output: serde_json::Value, pretty: bool) -> anyhow::Result<()> { let output = if pretty { serde_json::to_string_pretty(&output) @@ -133,6 +155,10 @@ fn print_value(output: serde_json::Value, pretty: bool) -> anyhow::Result<()> { serde_json::to_string(&output) } .map_err(anyhow::Error::msg); - println!("{}", output?); + + let _ = display_string_discreetly( + &output?, + "### Do not share or lose this private key! Press any key to complete. ###", + ); Ok(()) }