Skip to content

Commit 5cfae33

Browse files
committed
Port f0fd46d795b795ab9cec474d52db32725b499277 from FuelLabs/fuel-core#1426
1 parent 5bf9932 commit 5cfae33

File tree

5 files changed

+43
-12
lines changed

5 files changed

+43
-12
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

forc-plugins/forc-crypto/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@ rand = "0.8"
2424
serde = "1.0"
2525
serde_json = "1"
2626
sha3 = "0.10.8"
27+
termion = "2.0.1"
2728
tokio = { version = "1.8", features = ["macros", "rt-multi-thread", "process"] }
2829
tracing = "0.1"

forc-plugins/forc-crypto/src/keygen/mod.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use clap::ValueEnum;
2+
use std::io::{Read, Write};
23

34
pub mod new_key;
45
pub mod parse_secret;
@@ -12,3 +13,21 @@ pub enum KeyType {
1213
BlockProduction,
1314
Peering,
1415
}
16+
17+
fn wait_for_keypress() {
18+
let mut single_key = [0u8];
19+
std::io::stdin().read_exact(&mut single_key).unwrap();
20+
}
21+
22+
pub(crate) fn display_string_discreetly(
23+
discreet_string: &str,
24+
continue_message: &str,
25+
) -> anyhow::Result<()> {
26+
use termion::screen::IntoAlternateScreen;
27+
let mut screen = std::io::stdout().into_alternate_screen()?;
28+
writeln!(screen, "{discreet_string}")?;
29+
screen.flush()?;
30+
println!("{continue_message}");
31+
wait_for_keypress();
32+
Ok(())
33+
}

forc-plugins/forc-crypto/src/keygen/new_key.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! This file will be hosted here until
22
//! https://github.com/FuelLabs/sway/issues/5170 is fixed
3-
use super::{KeyType, BLOCK_PRODUCTION, P2P};
3+
use super::{display_string_discreetly, KeyType, BLOCK_PRODUCTION, P2P};
44
use anyhow::Result;
55
use fuel_core_types::{
66
fuel_crypto::{
@@ -57,9 +57,14 @@ pub fn handler(arg: Arg) -> Result<String> {
5757
})
5858
}
5959
};
60-
Ok(if arg.pretty {
61-
serde_json::to_string_pretty(&output)
62-
} else {
63-
serde_json::to_string(&output)
64-
}?)
60+
display_string_discreetly(
61+
&(if arg.pretty {
62+
serde_json::to_string_pretty(&output)
63+
} else {
64+
serde_json::to_string(&output)
65+
})?,
66+
"### Do not share or lose this private key! Press any key to complete. ###",
67+
)?;
68+
69+
Ok("".to_owned())
6570
}

forc-plugins/forc-crypto/src/keygen/parse_secret.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! This file will be hosted here until
22
//! https://github.com/FuelLabs/sway/issues/5170 is fixed
3-
use super::{KeyType, BLOCK_PRODUCTION, P2P};
3+
use super::{display_string_discreetly, KeyType, BLOCK_PRODUCTION, P2P};
44
use anyhow::Result;
55
use fuel_core_types::{fuel_crypto::SecretKey, fuel_tx::Input};
66
use libp2p_identity::{secp256k1, Keypair, PeerId};
@@ -52,9 +52,14 @@ pub fn handler(arg: Arg) -> Result<String> {
5252
output
5353
}
5454
};
55-
Ok(if arg.pretty {
56-
serde_json::to_string_pretty(&output)
57-
} else {
58-
serde_json::to_string(&output)
59-
}?)
55+
display_string_discreetly(
56+
&(if arg.pretty {
57+
serde_json::to_string_pretty(&output)
58+
} else {
59+
serde_json::to_string(&output)
60+
})?,
61+
"### Do not share or lose this private key! Press any key to complete. ###",
62+
)?;
63+
64+
Ok("".to_owned())
6065
}

0 commit comments

Comments
 (0)