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

Add API to Account for mnemonic seed phrases #87

Merged
merged 23 commits into from
Mar 20, 2020

Conversation

fubuloubu
Copy link
Contributor

@fubuloubu fubuloubu commented Feb 1, 2020

Fixes: #8 #24
Enables: #25 #37

How was it fixed?

Looked at the entire history of attempts at implementing this feature (#33 #34 etc...). Referencing those attempts, I lifted https://github.com/trezor/python-mnemonic (so as not to add a dependency) and implemented BIP32 (eth_account/hdaccount/deterministic.py) in a more readable fashion so it is specifically helpful to our scenario, and can be reused (currently only support private parent -> private child, but can be adopted to support public parent -> public child for #25 & #37)

Cute Animal Picture

studious monkey

@pipermerriam
Copy link
Member

A while back @davesque wrote https://github.com/davesque/py-hdwallet

If you're game I would be interested in removing the HD wallet implementation from this and leveraging the linked implementation (as a package dependency). Thoughts? I like keeping the crypto out of this library when possible so that we can have stable base libraries that implement the crypto which we rarely touch and then just use those public APIs to implement the high level functionality.

@fubuloubu
Copy link
Contributor Author

I think it makes sense that this should be a different library, to remove critical code from being built in here. I aimed for my hdwallet implementation to be as clear and concise as possible, and have no interdependencies on other parts of eth-account for that reason.

If py-hdwallet will be easier for you to maintain as a separate library and be able to fill the multiple roles required for the class (such as hardware wallets), then perhaps this does make sense, and I would be okay in working with you to integrate py-hdwallet. I do have to say though that I have sank a bit of time into this PR and I very much would like to see it through to production unlike the other attempts at adding this feature because I am needing it for a project of my own.

I know quite a few people who would like to use this, and I think it's time it gets done.

@fubuloubu fubuloubu force-pushed the hdaccount branch 2 times, most recently from b6428d2 to 83d1243 Compare February 2, 2020 04:11
@pipermerriam
Copy link
Member

👍 to moving forward with the local implementation and switching over to the py-hdwallet at a later time so as to not hold this up

@fubuloubu
Copy link
Contributor Author

fubuloubu commented Feb 2, 2020

@pipermerriam as far as testing goes, I have the official BIP32 and BIP39 test vectors of course, and I also lifted MetaMask's and Ganache's test cases from their repos (seed -> address). I've tested it with my own seed phrase and it works well. Was thinking the last steps would be perhaps to generate accounts from a couple popular wallets and put them in there too (tests/core/test_hdaccount.py)

@pipermerriam
Copy link
Member

Looking at the size of the diff I think this needs to get divided up a bit into smaller pieces. Can you see about carving this up into some smaller pieces?

@fubuloubu
Copy link
Contributor Author

fubuloubu commented Feb 3, 2020

@pipermerriam I can split this into 3 such pieces (but no more):

  1. BIP32 HDPath support (+217 lines, 1 test module)
  2. BIP39 Mnemonic support (+161 lines, 1 test module)
  3. API Change to Account (+40 lines, 1 test module)

Note that the diff is large because of the 2048 line english word file for BIP39

@pipermerriam
Copy link
Member

pipermerriam commented Feb 3, 2020 via email

@fubuloubu
Copy link
Contributor Author

@pipermerriam This branch is now based off the work in #89 and #88, please feel free to review those first

@fubuloubu fubuloubu force-pushed the hdaccount branch 2 times, most recently from 8195546 to 598323d Compare February 3, 2020 19:16
@fubuloubu fubuloubu changed the title Add support for mnemonic seed phrases Add API to Account for mnemonic seed phrases Feb 5, 2020
@fubuloubu fubuloubu force-pushed the hdaccount branch 6 times, most recently from f1be933 to e923663 Compare February 15, 2020 20:16
@fubuloubu fubuloubu force-pushed the hdaccount branch 3 times, most recently from e4711b3 to 6d0411a Compare March 20, 2020 01:00
@fubuloubu
Copy link
Contributor Author

@kclowes I narrowed it down to 22 commits, which is about as far as I could shrink it

fubuloubu and others added 10 commits March 19, 2020 21:03
Note: opt-in via Account.use_unaudited_hdwallet_features()
also made eth_account.hdaccount functions take no defaults
(except passphrase)

test: Fuzz HD path with new API
- Incorrect number of words
- Bad account path
- Unknown language
- Bad passphrase
Co-Authored-By: Marc Garreau <marcdgarreau@gmail.com>
@kclowes
Copy link
Collaborator

kclowes commented Mar 20, 2020

Thanks @fubuloubu! 🎉 🎉

@lil0uuu
Copy link

lil0uuu commented Dec 20, 2022

Thanks for the feature! I see in the docs that create_with_mnemonic() should be used with caution: "This feature is experimental, unaudited, and likely to change soon".

What are the risks in using this function? It's already 2y old - is there any plan to audit/change it soon?

@fubuloubu
Copy link
Contributor Author

Thanks for the feature! I see in the docs that create_with_mnemonic() should be used with caution: "This feature is experimental, unaudited, and likely to change soon".

What are the risks in using this function? It's already 2y old - is there any plan to audit/change it soon?

The feature is unaudited, but for the most common use case of obtaining private key material from an existing seed phrase it has so far worked pretty flawlessly. Let us know if you ever discover an issue with that use case.

As far as seed phrase generation, there may be risks that the master seed generation is handled inappropriately. There have been some examples where this has been problematic with other similar libraries, but again to the best of my knowledge there is no issue, and let us know if you find any.

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.

Support for HD and Mnemonic key derivation.
6 participants