Skip to content

Commit

Permalink
Port f0fd46d795b795ab9cec474d52db32725b499277 from FuelLabs/fuel-core…
Browse files Browse the repository at this point in the history
  • Loading branch information
cr-fuel committed Oct 18, 2023
1 parent 5bf9932 commit 5178376
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 12 deletions.
1 change: 1 addition & 0 deletions forc-plugins/forc-crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
19 changes: 19 additions & 0 deletions forc-plugins/forc-crypto/src/keygen/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use clap::ValueEnum;
use std::io::{Read, Write};

pub mod new_key;
pub mod parse_secret;
Expand All @@ -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(())
}
17 changes: 11 additions & 6 deletions forc-plugins/forc-crypto/src/keygen/new_key.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down Expand Up @@ -57,9 +57,14 @@ pub fn handler(arg: Arg) -> Result<String> {
})
}
};
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())
}
17 changes: 11 additions & 6 deletions forc-plugins/forc-crypto/src/keygen/parse_secret.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -52,9 +52,14 @@ pub fn handler(arg: Arg) -> Result<String> {
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())
}

0 comments on commit 5178376

Please sign in to comment.