Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Refactor, cleanup and doc
  • Loading branch information
Will committed Nov 2, 2018
commit 87ccfd967a2340d3a8e82dfcce6f9b9b209fbf76
1 change: 0 additions & 1 deletion Cargo.lock

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

1 change: 0 additions & 1 deletion subkey/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ authors = ["Parity Technologies <[email protected]>"]
substrate-primitives = { version = "*", path = "../core/primitives" }
rand = "0.4"
clap = { version = "~2.32", features = ["yaml"] }
ansi_term = "0.11"
num_cpus = "1.8.0"
pbr = "1.0.1"
ctrlc = "3.1.1"
Expand Down
21 changes: 11 additions & 10 deletions subkey/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ A key generation utility with vanity address support.
== vanity addresses

USAGE:
subkey vanity [FLAGS] [OPTIONS] [pattern]
subkey vanity [FLAGS] [OPTIONS] [pattern]

FLAGS:
-c, --case-sensitive Whether the patten case is important or not
-h, --help Prints help information
-p, --paranoiac Sacrifice speed for better randomness
-p, --paranoiac Sacrifice speed for better randomness (\~7% slower)
-V, --version Prints version information

OPTIONS:
-f, --format <format> Format of the generated output (stdout|csv) [default: stdout]
-m, --minscore <minscore> Minimum score for the results (between 0 and 100) [default: 75]
-n, --number <number> Number of keys to generate [default: 1]

Expand All @@ -41,18 +42,18 @@ The following command generates 3 vanity addresses containing `sub`, with a mini

returns:

Found match with a score of 86.24%
- Address : 5D7d6gfCYrbXAa6fRKspJJzSpKiZsubT9UVrPsVUqsuYVQGb
- Hex seed : 0x2e75f39eabd3a94eab235d0a1e29a34b6550cce9bc38a858e83e581bfe9872cd
- Seed : b2a7b571d580180dff551352558c8b55a68f3448388218f0eb5a48dc38a0aaf8
Found match with a score of 88.89%
- Address : 5CaBqxamFdJYFAEipjnJ7ibsubwZhCiuhKRFEHJoHZKWfSgC
- Hex seed : 0x167c54fa2c5f4228653a12b5d2f075e28b1b0abfc2d13e373e39b0ab90400737
- Seed : 4db70e51cf384fa5f65c56fb28210acb8f36edcb4b48072260c4357f1625bf6c
Found match with a score of 92.06%
- Address : 5DHsZCnuPqzHnXFW1subSTgnLD3zcFbJ3Q2bFcZ1Bmj5xFMw
- Hex seed : 0x364712b4a74784c605d01547f4cec951049e280d5a47aad2c7e9f06b2f7ad321
- Seed : 1c328aea576a252c80a91a2b1c08312c095320b04f2f6d264eeb50b9d544fd4d
Found match with a score of 88.89%
- Address : 5CaBqxamFdJYFAEipjnJ7ibsubwZhCiuhKRFEHJoHZKWfSgC
- Hex seed : 0x167c54fa2c5f4228653a12b5d2f075e28b1b0abfc2d13e373e39b0ab90400737
- Seed : 4db70e51cf384fa5f65c56fb28210acb8f36edcb4b48072260c4357f1625bf6c
Found match with a score of 86.24%
- Address : 5D7d6gfCYrbXAa6fRKspJJzSpKiZsubT9UVrPsVUqsuYVQGb
- Hex seed : 0x2e75f39eabd3a94eab235d0a1e29a34b6550cce9bc38a858e83e581bfe9872cd
- Seed : b2a7b571d580180dff551352558c8b55a68f3448388218f0eb5a48dc38a0aaf8

== Running forever until your favorite key shows up

Expand Down
13 changes: 13 additions & 0 deletions subkey/src/cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,16 @@ subcommands:
long: paranoiac
help: Sacrifice speed for better randomness (~7% slower)
takes_value: false
- format:
short: f
long: format
help: Format of the generated output (stdout|csv)
takes_value: true
default_value: stdout
- threads:
short: t
long: threads
help: Force the number of threads to be used (0= number of cpus x 2)
takes_value: true
default_value: "0"

36 changes: 36 additions & 0 deletions subkey/src/keypair.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use substrate_primitives::{ed25519::Pair, hexdisplay::HexDisplay};
use std::fmt;

/// A structure used to carry both Pair and seed.
/// This should usually NOT been used. If unsure, use Pair.
pub struct KeyPair {
pub pair: Pair,
pub seed: [u8; 32],
pub score: f32,
}

// Display to stdout
impl fmt::Display for KeyPair {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, r#"Found match with a score of {:4.2}%
- Address : {}
- Hex seed : 0x{}
- Seed : {}"#,
self.score ,
self.pair.public().to_ss58check(),
HexDisplay::from(&self.pair.public().0),
HexDisplay::from(&self.seed))
}
}


// Display in a CSV friendly format
impl KeyPair {
pub fn print_csv(&self) {
println!("{:5.2}%\t{}\t{}\t{}",
self.score ,
self.pair.public().to_ss58check(),
HexDisplay::from(&self.pair.public().0),
HexDisplay::from(&self.seed));
}
}
22 changes: 22 additions & 0 deletions subkey/src/keyspecs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use std::fmt;

#[derive(Debug, Clone)]
pub struct KeySpecs {
pub desired_pattern: String,
pub case_sensitive: bool,
pub paranoiac: bool,
pub minscore: f32,
}

impl fmt::Display for KeySpecs {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, r#"Key specifications:
- Pattern: {}
- Case sensitive: {}
- Paranoiac: {}
- Min. Score: {}"#,
self.desired_pattern,
self.case_sensitive,
self.paranoiac, self.minscore)
}
}
45 changes: 23 additions & 22 deletions subkey/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,44 +26,46 @@
extern crate test;
extern crate substrate_primitives;
extern crate rand;
extern crate ansi_term;
extern crate num_cpus;
extern crate ctrlc;

#[macro_use]
extern crate clap;
extern crate pbr;

use vanity::OutputFormat;
use keyspecs::KeySpecs;
use substrate_primitives::{ed25519::Pair, hexdisplay::HexDisplay};

mod vanity;
mod keypair;
mod keyspecs;

fn main() {
let yaml = load_yaml!("cli.yml");
let matches = clap::App::from_yaml(yaml).get_matches();

match matches.subcommand() {
("vanity", Some(matches)) => {
let desired_pattern:String = matches.value_of("pattern").map(str::to_string).unwrap_or_default();
let number: u32 = matches.value_of("number").map(str::to_string).unwrap_or_default().parse::<u32>().unwrap();
let minscore: u8 = matches.value_of("minscore").map(str::to_string).unwrap_or_default().parse::<u8>().unwrap();
let case_sensitive: bool = matches.is_present("case_sensitive");
let paranoiac: bool = matches.is_present("paranoiac");

let minscore = match minscore {
0...100 => minscore,
m if m >= 100 => 100,
_ => 75,
};

let keys = vanity::generate_keys(
desired_pattern,
case_sensitive,
paranoiac,
minscore as f32,
number as usize);
vanity::print_keys(keys);
}
let number: u32 = matches.value_of("number").map(str::to_string).unwrap_or_default().parse::<u32>().unwrap();
let threads: u8 = matches.value_of("threads").map(str::to_string).unwrap_or_default().parse::<u8>().unwrap();
let format: OutputFormat = match matches.value_of("format").unwrap_or_default() {
"csv" => OutputFormat::Csv,
_ => OutputFormat::Stdout,
};
let key_specs = KeySpecs {
desired_pattern: matches.value_of("pattern").map(str::to_string).unwrap_or_default(),
case_sensitive: matches.is_present("case_sensitive"),
paranoiac: matches.is_present("paranoiac"),
minscore: match matches.value_of("minscore").map(str::to_string).unwrap_or_default().parse::<u8>().unwrap() {
m @ 0...100 => m as f32,
_ => 100_f32,
},
};

let keys = vanity::generate_keys(key_specs, number as usize, threads);
vanity::print_keys(keys, format);
}

("restore", Some(matches)) => {
let mut raw_seed = matches.value_of("seed")
Expand All @@ -89,7 +91,6 @@ fn main() {
);
},
_ => print_usage(&matches),

}
}

Expand Down
Loading