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

Added mnemonic generation of keys and recover from mnemonic to keypair #24

Merged
merged 15 commits into from
Feb 1, 2023

Conversation

schlunsen
Copy link
Contributor

No description provided.

@schlunsen
Copy link
Contributor Author

schlunsen commented Jan 23, 2023

Will need to do some more work on this one regards of better error handling and adding tests, but is this something that would have interest to merge?

@grunch
Copy link
Owner

grunch commented Jan 26, 2023

Hi @schlunsen I'm sorry for the delay, this can be implemented without adding more complexity to Rana? I mean, with this functionality the program will keep working as is working now?

@schlunsen
Copy link
Contributor Author

Yes the current functionality will stay intact. This just adds the possibility of generating keys with a mnemonic and to convert a mnemonic into a keypair

@grunch
Copy link
Owner

grunch commented Jan 26, 2023

Great! go for it 😃

@schlunsen
Copy link
Contributor Author

Ready to merge!

Copy link
Owner

@grunch grunch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update nostr-sdk to 0.16.2 ?

@grunch
Copy link
Owner

grunch commented Jan 26, 2023

I did this

cargo run -- -g 12 -n epale,hola

But it ignored the -n argument 😢

@grunch
Copy link
Owner

grunch commented Jan 26, 2023

When running the mnemonic with vanity n together I expected something like this:

cargo run -- -n epale,h0la
    Finished dev [unoptimized + debuginfo] target(s) in 0.07s
     Running `target/debug/rana -n epale,h0la`
Started mining process for vanity bech32 prefix[es]: 'npub1["epale", "h0la"]' (estimated pow: 20)
Benchmarking of cores disabled for vanity npub key upon proper calculation.
Mining using 16 cores...
==============================================
Vanity npub found:         epale
Found matching public key: c87bfc931f58c7145a0ad067d48c466d985fbba427f686eb5faaca00da58c173
Nostr private key:         00dc48a713e6b6aebc7320939787d41f44175bbd76532f0ed0332b349250c8c0
Nostr public key (npub):   npub1epaleycltrr3gks26pnafrzxdkv9lwayylmgd66l4t9qpkjcc9eszfywah
Nostr private key (nsec):  nsec1qrwy3fcnu6m2a0rnyzfe0p75razpwkaawefj7rksxv4nfyjserqqqdpmzn
Mnemonic: matter soda stage flash machine cash obtain shaft arrange moment power school
1307731 iterations (about 1x10^6 hashes) in 15 seconds. Avg rate 87182 hashes/second
==============================================
Vanity npub found:         h0la
Found matching public key: bbffda9d876de4e33a41403b386c5ce7976887da95aec01f637e8028b1a517c5
Nostr private key:         cf767f8a16ee52434df6e2dd911d30614b3dd9cd90b5d4b7d6fbef6832c3ce52
Nostr public key (npub):   npub1h0la48v8dhjwxwjpgqansmzuu7tk3p76jkhvq8mr06qz3vd9zlzsenlzge
Nostr private key (nsec):  nsec1eam8lzskaefyxn0kutwez8fsv99nmkwdjz6afd7kl0hksvkreefq3v9pza
Mnemonic: sudden rare midnight airport lake machine note edge fun tribe panther can
1311402 iterations (about 1x10^6 hashes) in 15 seconds. Avg rate 87426 hashes/second

mnemonics also for vanity key and difficulty

* If mnemonic is set rana will work as before and search for a vanity
  key or difficulta etc.y
* Added bip39 crate
* Refactored helper functions into utils.rs
@schlunsen schlunsen requested a review from grunch January 27, 2023 13:54
Copy link
Owner

@grunch grunch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR decreases performance dramatically, here a test like the one above

cargo run -- -n epale,h0la   
    Finished dev [unoptimized + debuginfo] target(s) in 0.08s
     Running `target/debug/rana -n epale,h0la`
Started mining process for vanity bech32 prefix[es]: 'npub1["epale", "h0la"]' (estimated pow: 20)
Benchmarking of cores disabled for vanity npub key upon proper calculation.
Mining using 16 cores...
==============================================
Vanity npub found:         h0la
Found matching public key: bbffd6f976714c77722d252db886139b94f34787c86aee4192a06e2c16f0dc94
Nostr private key:         a52749475a271280108ca11d79706a0548abe26314712a2eb05c01778ef466d0
Nostr public key (npub):   npub1h0lad7tkw9x8wu3dy5km3psnnw20x3u8ep4wusvj5phzc9hsmj2ql57p4u
Nostr private key (nsec):  nsec155n5j366yufgqyyv5ywhjur2q4y2hcnrz3cj5t4stsqh0rh5vmgqs87gdv
56253 iterations (about 5x10^4 hashes) in 0 seconds. Avg rate 56253 hashes/second

We need to keep performance, which is a very important feature of Rana, can you please fix it?

Copy link
Owner

@grunch grunch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm testing the passphrase this way but I don't have the same keys, am I doing it wrong?

target/release/rana -g 12 -p test01
Mnemonic: pumpkin rich boost involve wrist monster drum attend fat ask ill skin
Public key: npub15rz0dcdvpy4tjrfu68lfmzj5ts0a3tdnru0twk992nt4x96g5mnq8nv64a
Private key: nsec1njaaue55ey5m7pjeesn5nvj7968sfkgz6rxwvudpfe5ahmuf7gyqgq0sf0

target/release/rana -r "pumpkin rich boost involve wrist monster drum attend fat ask ill skin" -p test01
Public key: npub1a3nxq9hzylv9g2y5papgqjj69p283tf7srv5dyymmec3ygv93szqg7egl0
Private key: nsec173t9hwt20ekvsttzkc0a72m0cum4sf3qmzgjrghzks0ft526t4jqnjd8jc

src/utils.rs Outdated Show resolved Hide resolved
@schlunsen
Copy link
Contributor Author

There is a bug with passphrase not being passed on to the loop. Will look into fixing it, but I'm currently fighting the borrow checker

@schlunsen
Copy link
Contributor Author

New changes with vanity suffix and qr has been merged into this branch and passphrase combined with mnemonic bug has been fixed

@schlunsen
Copy link
Contributor Author

This should close #10

@schlunsen
Copy link
Contributor Author

schlunsen commented Jan 31, 2023

Using mnemonic for generation is much slower and I'm currently only processing with an Avg rate 279 hashes/second, but it works :). Performance should be intact if mnemonic is not used

@schlunsen schlunsen requested a review from grunch February 1, 2023 07:42
Copy link
Owner

@grunch grunch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK

It works like a charm!!!

Thanks for this contribution

@grunch grunch merged commit cec1c59 into grunch:main Feb 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants