Skip to content

Commit

Permalink
QR show the nsec instead hex private key
Browse files Browse the repository at this point in the history
  • Loading branch information
mrtn28 committed Jan 29, 2023
1 parent 2689a0d commit 23def5b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rana"
version = "0.3.7"
version = "0.3.6"
edition = "2021"
license = "MIT"
authors = ["Francisco Calderón <[email protected]>"]
Expand Down
12 changes: 9 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ fn main() -> Result<(), Box<dyn Error>> {
iterations / max(1, now.elapsed().as_secs())
);
if qr {
print_qr(secret_key)
print_qr(secret_key).unwrap();
}
}
}
Expand Down Expand Up @@ -309,13 +309,19 @@ fn get_leading_zero_bits(bytes: &[u8]) -> u8 {
res
}

fn print_qr(secret_key: SecretKey) {
fn print_qr(secret_key: SecretKey) -> Result<(), Box<dyn Error>> {
let private_hex = secret_key.display_secret().to_string();
let code = QrCode::new(private_hex).unwrap();
let nsec = bech32::encode(
"nsec",
hex::decode(private_hex)?.to_base32(),
Variant::Bech32,
)?;
let code = QrCode::new(nsec).unwrap();
let qr = code
.render::<unicode::Dense1x2>()
.dark_color(unicode::Dense1x2::Light)
.light_color(unicode::Dense1x2::Dark)
.build();
println!("{qr}");
Ok(())
}

0 comments on commit 23def5b

Please sign in to comment.