Skip to content

Commit

Permalink
include error when simple regex include non bench32 chars
Browse files Browse the repository at this point in the history
  • Loading branch information
antonioconselheiro committed Nov 3, 2024
1 parent f641b01 commit 7ad731c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 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 = "eschanostr"
version = "0.1.0"
version = "1.0.1"
edition = "2021"

[dependencies]
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Convert electricity into read friendly nostr npub.
## Install

```sh
sudo wget -O /usr/bin/eschanostr https://github.com/antonioconselheiro/eschanostr/releases/download/1.0.0/eschanostr;
sudo wget -O /usr/bin/eschanostr https://github.com/antonioconselheiro/eschanostr/releases/download/1.0.1/eschanostr;
sudo chmod +x /usr/bin/eschanostr
```

Expand All @@ -22,23 +22,23 @@ Or just download the last version in releases page.

**Basic run:**

`eschanostr --nregex "horses" --npassword "jesusteama"`
`eschanostr --nregex "deep" --npassword "jesusteama"`

or

`eschanostr -r "libs" -p "reijesus"`
`eschanostr -r "h0ney" -p "reijesus"`

**Complex regexes:**

`eschanostr --nregex ".*h[o0]rs[e3]s?" --npassword "jesusteama"`
`eschanostr --nregex ".*pl[a4]c[e3]" --npassword "jesusteama"`

You can compose your regex using [this tool](https://jex.im/regulex/#!flags=&re=.*h%5Bo0%5Drs%5Be3%5Ds%3F).

The algorithm use brute-force search, so if you should fill the regex with all your read-friendly npub expectations, this way you can do it only one time.

**Dev run**

`cargo run -- --nregex "shop" --npassword "jesuslindo"`
`cargo run -- --nregex "sh0p" --npassword "jesuslindo"`

See more in [CONTRIBUTE.md](./CONTRIBUTE.md).

Expand Down
18 changes: 14 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use std::io::{stdout, Write};
use ctrlc;

#[derive(Parser)]
#[clap(name = "eschanostr", version = "1.0", about = "convert electricity into read friendly nostr npub")]
#[clap(name = "eschanostr", version = "1.0.1", about = "convert electricity into read friendly nostr npub")]
struct Cli {

#[arg(short = 'r', long, help = "mandatory regular expression with the desired pattern in your npub")]
Expand Down Expand Up @@ -122,16 +122,26 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let npassword = args.npassword.unwrap_or("".to_string());
let ndancing = args.ndancing.unwrap_or(true);

let full_regex_pattern = format!(r"^npub1({})", args.nregex);
// set offset
let spacing;
if ndancing {
spacing = "\r ";
} else {
spacing = "";
}

println!("{}:: STARTING", spacing);
// validate and build regex
let nregex = args.nregex.clone();
let is_alpha_numerical = Regex::new("^[a-zA-Z\\d]+$")?;
let is_bench32_compatible = Regex::new("^[023456789acdefghjklmnpqrstuvwxyz]+$")?;

if is_alpha_numerical.is_match(&nregex) && !is_bench32_compatible.is_match(&nregex) {
println!("{}:: Chars that occurs in npub1: 023456789acdefghjklmnpqrstuvwxyz", spacing);
panic!("{}:: Error: some characteres in \"{}\" will never occur in npub1 string", spacing, nregex);
}
let full_regex_pattern = format!(r"^npub1({})", nregex);

// subscribe ctrlc listener
let mut ctrlc_calls = 0;
let ctrlc_can_be_not_instantly = [
"user triggered close command",
Expand Down Expand Up @@ -159,7 +169,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
"yeah I known",
];

// listen user close command
let running: Arc<AtomicBool> = Arc::new(AtomicBool::new(true));
let running_clone = running.clone();
ctrlc::set_handler(move || {
Expand All @@ -176,6 +185,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
running_clone.store(false, Ordering::SeqCst);
})?;

println!("{}:: STARTING", spacing);
if ndancing {
println!("");
println!("{}▓█████ ██████ ▄████▄ ██░ ██ ▄▄▄ ███▄ █ ▒█████ ██████ ▄▄▄█████▓ ██▀███ ", spacing);
Expand Down

0 comments on commit 7ad731c

Please sign in to comment.