Skip to content

Commit

Permalink
Add secret display
Browse files Browse the repository at this point in the history
  • Loading branch information
cr-fuel committed Oct 18, 2023
1 parent badbf54 commit b339ea1
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
28 changes: 28 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/keygen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
28 changes: 27 additions & 1 deletion crates/keygen/src/keygen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ use libp2p_identity::{
};
use serde_json::json;
use std::{
io::{
Read,
Write,
},
ops::Deref,
str::FromStr,
};
Expand Down Expand Up @@ -126,13 +130,35 @@ 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)
} else {
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(())
}

0 comments on commit b339ea1

Please sign in to comment.