vanity

Use the notifyr bot to generate vanity addresses and get notified by DM when they are done.

Finding vanity addresses

Here is an interesting article by Kris Constable about vanity addresses. This is a great usecase for our notifyr decorator because calculating vanity addresses can be quite slow if we are looking for long words.

This module will let you look for an npub or a hex vanity address that starts with a particular pattern.

making guesses

In this module you will find a guess_npub and guess_hex methods that are created from _guess_vanity. We are going directly back to the bits to get the best perfomance possible - this code is very similar to the code used to generate private keys in the nostr.PrivateKey class from python-nostr

privkey_hex, npub = guess_bech32()
assert PrivateKey.from_hex(privkey_hex).public_key.bech32() == npub
privkey_hex, pubkey_hex = guess_hex()
assert PrivateKey.from_hex(privkey_hex).public_key.hex() == pubkey_hex

checking computer hashrate

We can make some functions to check the guess rate (hashrate)

f'We estimate a hash rate of {1/_get_guess_time(guess_hex)} guesses per second'
'We estimate a hash rate of 12579.831850745017 guesses per second'
f'We estimate a hash rate of {1/_get_guess_time(_guess_vanity_slow)} guesses per second'
'We estimate a hash rate of 6391.511961143656 guesses per second'
f'We estimate a hash rate of {1/_get_guess_time(guess_bech32)} guesses per second'
'We estimate a hash rate of 4996.315606723534 guesses per second'

And use our hashrate to make some estimates of how quickly we can find certain vanity addresses


source

expected_performance

 expected_performance ()
expected_performance()
This is a random guessing process - estimations are an average, but the actual
        time it takes to find a key could be significantly more or less than the estimate!
        Please keep that in mind when choosing an option.
        
hex:
In one second you can expect to get 3.325667183387504 characters on average
In one minute you can expect to get 4.8023898322896335 characters on average
In one hour you can expect to get 6.2791124811917625 characters on average
In one day you can expect to get 7.425353106372053 characters on average
In one month you can expect to get 8.658037440762774 characters on average


1 characters: it might take 0.0015834985552821308 seconds
2 characters: it might take 0.025335976884514094 seconds
3 characters: it might take 0.4053756301522255 seconds
4 characters: it might take 6.486010082435608 seconds
5 characters: it might take 103.77616131896973 seconds
6 characters: it might take 1660.4185811035156 seconds
7 characters: it might take 26566.69729765625 seconds
8 characters: it might take 425067.1567625 seconds
9 characters: it might take 6801074.5082 seconds
10 characters: it might take 108817192.1312 seconds
11 characters: it might take 1741075074.0992 seconds
12 characters: it might take 27857201185.5872 seconds
13 characters: it might take 445715218969.3952 seconds
14 characters: it might take 7131443503510.323 seconds
15 characters: it might take 114103096056165.17 seconds
16 characters: it might take 1825649536898642.8 seconds
17 characters: it might take 2.9210392590378284e+16 seconds
18 characters: it might take 4.6736628144605254e+17 seconds
19 characters: it might take 7.477860503136841e+18 seconds
20 characters: it might take 1.1964576805018945e+20 seconds


npub:
In one second you can expect to get 2.383159533953474 characters on average
In one minute you can expect to get 3.564537653075178 characters on average
In one hour you can expect to get 4.745915772196882 characters on average
In one day you can expect to get 5.662908272341113 characters on average
In one month you can expect to get 6.64905573985369 characters on average


1 characters: it might take 0.008282042550842743 seconds
2 characters: it might take 0.26502536162696777 seconds
3 characters: it might take 8.480811572062969 seconds
4 characters: it might take 271.385970306015 seconds
5 characters: it might take 8684.35104979248 seconds
6 characters: it might take 277899.23359335936 seconds
7 characters: it might take 8892775.4749875 seconds
8 characters: it might take 284568815.1996 seconds
9 characters: it might take 9106202086.3872 seconds
10 characters: it might take 291398466764.3904 seconds
11 characters: it might take 9324750936460.492 seconds
12 characters: it might take 298392029966735.75 seconds
13 characters: it might take 9548544958935544.0 seconds
14 characters: it might take 3.055534386859374e+17 seconds
15 characters: it might take 9.777710037949997e+18 seconds
16 characters: it might take 3.128867212143999e+20 seconds
17 characters: it might take 1.0012375078860797e+22 seconds
18 characters: it might take 3.203960025235455e+23 seconds
19 characters: it might take 1.0252672080753456e+25 seconds
20 characters: it might take 3.280855065841106e+26 seconds

Lets make the function…


source

gen_vanity_pubkey

 gen_vanity_pubkey (startswith:str, style='hex')

randomly generate private keys until one matches the desire startswith for an npub or hex

Type Default Details
startswith str characters that the public key should start with. More chars
means longer run time
style str hex ‘npub’ or ‘hex’ - npub is more commonly displayed on apps
while hex is the true base private key with no encoding,
by default ‘hex’
Returns PrivateKey returns a private key object
from fastcore.test import test_fail

Make sure we don’t allow characters that will never happen - test that these cases fail

fail = lambda _: gen_vanity_pubkey(startswith='b', style='npub')
test_fail(fail)
fail = lambda _: gen_vanity_pubkey(startswith='g', style='hex')
test_fail(fail)

Generate a couple npubs!

vanity_private_key_npub = gen_vanity_pubkey(startswith='23', style='npub')
vanity_private_key_hex = gen_vanity_pubkey(startswith='23', style='hex')
It might take 0 seconds to find a npub pubkey that starts with npub123. Note that this is a very rough estimate and due to the random nature of finding vanity keys it could take MUCH longer.
It might take 0 seconds to find a hex pubkey that starts with 23. Note that this is a very rough estimate and due to the random nature of finding vanity keys it could take MUCH longer.

And make sure it worked…

assert vanity_private_key_npub.public_key.bech32().startswith('npub123')
assert vanity_private_key_hex.public_key.hex().startswith('23')

Now we can also make a version of this that notifies you.

Remember that if you want a vanity notifyr that will go to a different address than the one you find in vanity_notifyr.notifyr_privkey_hex you can create your own notifyr like so:

new_vanity_notifyr = notifyr(gen_vanity_pubkey, recipient_address=your_address)