diff --git a/forc-plugins/forc-crypto/Cargo.toml b/forc-plugins/forc-crypto/Cargo.toml index 61dfb72597f..47c8d2dbff5 100644 --- a/forc-plugins/forc-crypto/Cargo.toml +++ b/forc-plugins/forc-crypto/Cargo.toml @@ -24,5 +24,6 @@ rand = "0.8" serde = "1.0" serde_json = "1" sha3 = "0.10.8" +termion = "2.0.1" tokio = { version = "1.8", features = ["macros", "rt-multi-thread", "process"] } tracing = "0.1" diff --git a/forc-plugins/forc-crypto/src/keygen/mod.rs b/forc-plugins/forc-crypto/src/keygen/mod.rs index dcb18b7549d..c234f51b690 100644 --- a/forc-plugins/forc-crypto/src/keygen/mod.rs +++ b/forc-plugins/forc-crypto/src/keygen/mod.rs @@ -1,4 +1,5 @@ use clap::ValueEnum; +use std::io::{Read, Write}; pub mod new_key; pub mod parse_secret; @@ -12,3 +13,21 @@ pub enum KeyType { BlockProduction, Peering, } + +fn wait_for_keypress() { + let mut single_key = [0u8]; + std::io::stdin().read_exact(&mut single_key).unwrap(); +} + +pub(crate) 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(()) +} diff --git a/forc-plugins/forc-crypto/src/keygen/new_key.rs b/forc-plugins/forc-crypto/src/keygen/new_key.rs index 797adeb8f54..10a0bc2540a 100644 --- a/forc-plugins/forc-crypto/src/keygen/new_key.rs +++ b/forc-plugins/forc-crypto/src/keygen/new_key.rs @@ -1,6 +1,6 @@ //! This file will be hosted here until //! https://github.com/FuelLabs/sway/issues/5170 is fixed -use super::{KeyType, BLOCK_PRODUCTION, P2P}; +use super::{display_string_discreetly, KeyType, BLOCK_PRODUCTION, P2P}; use anyhow::Result; use fuel_core_types::{ fuel_crypto::{ @@ -57,9 +57,14 @@ pub fn handler(arg: Arg) -> Result { }) } }; - Ok(if arg.pretty { - serde_json::to_string_pretty(&output) - } else { - serde_json::to_string(&output) - }?) + display_string_discreetly( + &(if arg.pretty { + serde_json::to_string_pretty(&output) + } else { + serde_json::to_string(&output) + })?, + "### Do not share or lose this private key! Press any key to complete. ###", + )?; + + Ok("".to_owned()) } diff --git a/forc-plugins/forc-crypto/src/keygen/parse_secret.rs b/forc-plugins/forc-crypto/src/keygen/parse_secret.rs index a237dd1df92..f47acf8d80c 100644 --- a/forc-plugins/forc-crypto/src/keygen/parse_secret.rs +++ b/forc-plugins/forc-crypto/src/keygen/parse_secret.rs @@ -1,6 +1,6 @@ //! This file will be hosted here until //! https://github.com/FuelLabs/sway/issues/5170 is fixed -use super::{KeyType, BLOCK_PRODUCTION, P2P}; +use super::{display_string_discreetly, KeyType, BLOCK_PRODUCTION, P2P}; use anyhow::Result; use fuel_core_types::{fuel_crypto::SecretKey, fuel_tx::Input}; use libp2p_identity::{secp256k1, Keypair, PeerId}; @@ -52,9 +52,14 @@ pub fn handler(arg: Arg) -> Result { output } }; - Ok(if arg.pretty { - serde_json::to_string_pretty(&output) - } else { - serde_json::to_string(&output) - }?) + display_string_discreetly( + &(if arg.pretty { + serde_json::to_string_pretty(&output) + } else { + serde_json::to_string(&output) + })?, + "### Do not share or lose this private key! Press any key to complete. ###", + )?; + + Ok("".to_owned()) }