Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a Dockerfile for giggles and a verbosity flag to print out any non-matching public keys just because it's pretty and slightly fun to watch. #47

Merged
merged 6 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM rust:1.76 as builder
WORKDIR /app
COPY . .
RUN cargo install --path .

FROM debian:bookworm-slim
RUN apt-get update
RUN apt-get -y install libc6
COPY --from=builder /app /app
ENTRYPOINT [ "/rana" ]
CMD [ "" ]
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ Options:
Passphrase used for restoring mnemonic to keypair
-q, --qr
Print QR code of the private key
-w, --verbose_output
Print verbose ouput of non-matching public keys
```

Examples:
Expand All @@ -78,7 +80,7 @@ $ cargo run --release -- --vanity=dead

$ cargo run --release -- --vanity-n-prefix=rana

$ cargo run --release -- --vanity-n=rana,h0dl,n0strfan
$ cargo run --release -- --vanity-n-prefix=rana,h0dl,n0strfan

$ cargo run --release -- -n=rana,h0dl,n0strfan

Expand Down
9 changes: 9 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ targets as a comma-separated list."
help = "Print QR code of the private key"
)]
pub qr: bool,

#[arg(
short = 'w',
long = "verbose-output",
required = false,
default_value_t = false,
help = "Print verbose ouput on non-matching public keys"
)]
pub verbose_output: bool,
}

pub fn check_args(
Expand Down
12 changes: 10 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use colored::Colorize;
use std::cmp::max;
use std::sync::atomic::{AtomicU64, AtomicU8, Ordering};
use std::sync::Arc;
use std::sync::{Arc, Mutex};
use std::thread;
use std::time::{Duration, Instant};

Expand Down Expand Up @@ -30,6 +30,7 @@ fn main() -> Result<()> {
let mut vanity_npub_suffixes: Vec<String> = Vec::new();
let num_cores: usize = parsed_args.num_cores;
let qr: bool = parsed_args.qr;
let verbose_output: bool = parsed_args.verbose_output;

for vanity_npub_pre in parsed_args.vanity_npub_prefixes_raw_input.split(',') {
if !vanity_npub_pre.is_empty() {
Expand Down Expand Up @@ -214,8 +215,10 @@ fn main() -> Result<()> {
}

// if one of the required conditions is satisfied
let shared_output = Arc::new(Mutex::new(std::io::stdout()));
if is_valid_pubkey {
println!("{}", print_divider(20).bright_cyan());
let _guard = shared_output.lock().unwrap();
println!("{}", print_divider(30).bright_cyan());
print_keys(&keys, vanity_npub, leading_zeroes, uses_mnemonic).unwrap();
let iterations = iterations.load(Ordering::Relaxed);
let iter_string = format!("{iterations}");
Expand All @@ -232,6 +235,11 @@ fn main() -> Result<()> {
if qr {
print_qr(keys.secret_key().unwrap()).unwrap();
}
std::io::Write::flush(&mut std::io::stdout()).expect("Failed to flush stdout");
} else if verbose_output {
let non_matching_key = keys.public_key().to_string();
print!("Non-matching public key generated: {}\r", non_matching_key.red());
std::io::Write::flush(&mut std::io::stdout()).expect("Failed to flush stdout");
}
}
});
Expand Down
Loading