btc-vanity is A Bitcoin vanity address generator written with the Rust programming language.
See the documentation or crates.io page.
What is a vanity address?
A Vanity Address is a special address that contains a specific pattern or word. For example, the Vanity Address of a Bitcoin belonging to a user may contain a pattern or word such as “1BTC” or “1Emiv”. Vanity Addresses are often used personally or for promotional purposes.
What btc-vanity can do?
With btc-vanity, you can find a private key that has a compressed Bitcoin pay address that has a custom prefix, suffix, or a string at somewhere in the address.
You can easily run the btc-vanity terminal application locally or use it as a library to create your vanity keypair securely.
btc-vanity implementation
src
|- lib.rs
|- main.rs
|- cli.rs
|- decoration.rs
|- error.rs
|- file.rs
|- flags.rs
|- keys_and_addresses.rs
|- vanity_addr_generator.rs
despite there are a lot of files, the real magic happens in keys_and_addresses.rs
and vanity_addr_generator.rs
, and others that serve CLI operations.
let’s dive into some core implementations.
keys_and_addresses.rs
secp256k1 refers to the parameters of the elliptic curve used in Bitcoin’s public-key cryptography. Currently, Bitcoin uses secp256k1. So we also need to use it. The main struct used in keys_and_addresses.rs
is KeysAndAdress
struct. Here we use bitcoin::crypto::key
for storing keys and normal good old friend String
for our compressed address that will have out vanity string.
To generate a random Key pair and their address, you need to initialize a bitcoin::secp256k1::Secp256k1
to pass it generate method of KeysAndAddress, or just call KeysAndAddress::generate_random_heavy()
if you’re not going to use secp256k1 anywhere else. Here is how genereate_random()
is implemented
You can also within a certain range by using KeysAndAddress::generate_within_range()
. Refer to docs for further information; I’ll stop here to keep it simple.
vanity_addr_generator.rs
All of the other files are helpers of this file, this is the place where the real magic happens. The main struct used in vanity_addr_generator.rs
is VanityAddr
struct. Here is how VanityAddr::generate()
implemented
as it is quite self-explanatory, you pass some parameters, it checks it first, then searches your vanity string for you.
Another important struct in the file is SearchEngines
. Real work is done by SearchEngines
struct. VanityAddr
’s main purpose is to provide a safe wrapper for finding a vanity address. Refer to docs or GitHub repository for complete implementation. However, I’ll give the overall steps on how the magic happens.
1- create a mpsc::channel()
2- clone sender
and the flags as many as requested.
3- now each thread will generate a randomly generated KeysAndAdress
struct and check if it satisfies the flags
4- if a thread finds a KeysAndAdress
that meets the needs, it sends it via the sender
. When a thread sends a KeysAndAdress
, the other threads are killed.
5- during this time receiver is trying to receive with .try_recv()
in a loop, when a thread finds a keypair, this will catch it and return it.
Calling btc-vanity as a library
let’s find a vanity address
incase you need to look for certain range, we also got you covered. Here is an example to look for a certain private key range
Examples of usage from terminal
install btc-vanity with cargo
cargo install btc-vanity
and then you can see possible usage with command
btc-vanity -h
here are some example screenshots
Thanks for reading till the end. I hope you like the project. If you would like to test btc-vanity, before using it please read the DISCLAIMER for your good.