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 support for BIP39 (Mnemonic Seed Phrases) #89

Merged
merged 32 commits into from
Mar 4, 2020

Conversation

fubuloubu
Copy link
Contributor

Split off commits related to BIP32 implemented from #87

Based off of #88

Copy link
Collaborator

@kclowes kclowes left a comment

Choose a reason for hiding this comment

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

@fubuloubu this is looking good to me. I left a few comments, the bulk of which point out that there are a bunch of methods that aren't getting used (I don't think), and I'd rather see them removed if we're not using them so they're not confusing for the next person. What do you think?

eth_account/hdaccount/mnemonic.py Outdated Show resolved Hide resolved
eth_account/hdaccount/mnemonic.py Outdated Show resolved Hide resolved
eth_account/hdaccount/mnemonic.py Outdated Show resolved Hide resolved
eth_account/hdaccount/mnemonic.py Outdated Show resolved Hide resolved
eth_account/hdaccount/mnemonic.py Outdated Show resolved Hide resolved
eth_account/hdaccount/mnemonic.py Outdated Show resolved Hide resolved
eth_account/hdaccount/mnemonic.py Outdated Show resolved Hide resolved
eth_account/hdaccount/mnemonic.py Show resolved Hide resolved
@fubuloubu
Copy link
Contributor Author

@kclowes @marcgarreau good to review!

Copy link
Collaborator

@kclowes kclowes left a comment

Choose a reason for hiding this comment

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

Thanks for the updates @fubuloubu! I left a few comments around testing, but overall looks good.

@pipermerriam want to take a look?

tests/core/test_mnemonic.py Outdated Show resolved Hide resolved
eth_account/hdaccount/mnemonic.py Outdated Show resolved Hide resolved
@fubuloubu
Copy link
Contributor Author

@kclowes thanks to this test, it helped me realize what the issue is with Chinese in #87

@fubuloubu
Copy link
Contributor Author

I ended up pulling the fix for it here, see bad39f5

@fubuloubu
Copy link
Contributor Author

@kclowes @marcgarreau @pipermerriam ready for review!

Copy link
Member

@wolovim wolovim left a comment

Choose a reason for hiding this comment

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

Thanks for putting in the work in @fubuloubu. I'm still learning this domain; what I see looks good, but couple questions/suggestions:

eth_account/hdaccount/mnemonic.py Outdated Show resolved Hide resolved
eth_account/hdaccount/mnemonic.py Outdated Show resolved Hide resolved
eth_account/hdaccount/mnemonic.py Show resolved Hide resolved
Copy link
Member

@pipermerriam pipermerriam left a comment

Choose a reason for hiding this comment

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

one thought I had was potentially exposing the various language APIs via something like.

from mnemonic.i10n.en import from_seed, validate_mnemonic, ...

This would give us unambiguous access to the individual language specific functions.

Then, we could have a top level version of these functions which was designed to do language detection, or to require the caller to explicitly provide the language (or maybe both in some cases where we can do detection, but where there is a potential for ambiguity at which point we want to allow the user to provide an override.

eth_account/hdaccount/mnemonic.py Outdated Show resolved Hide resolved
eth_account/hdaccount/mnemonic.py Outdated Show resolved Hide resolved
eth_account/hdaccount/mnemonic.py Outdated Show resolved Hide resolved

@combomethod
def list_languages(_Mnemonic):
return sorted(Path(f).stem for f in WORDLIST_DIR.rglob("*.txt"))
Copy link
Member

Choose a reason for hiding this comment

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

I'm fine with this pattern for now, but I want to suggest an alternative.

If we use a registry pattern then we can have a default registry which has the default wordlists. This allows for either extension via 3rd party wordlists, or even simpler testing via special wordlists... Also, it relies less on the filesystem as a database of the wordlists (though i think we would still store them as files, but register the parsed wordlists to eliminate the I/O component during runtime)

Copy link
Member

Choose a reason for hiding this comment

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

Another option would be to instantiate the class with the wordlist itself and just have instances of the class for each supported language....

Or to have subclasses with the wordlist as a class property.

I think any of these would be an improvement over what is currently in place with the __init__ method doing I/O and using the filesystem as a sort of database of the available wordlists.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, we can make that happen. TBH I think a lot of this stuff doesn't even need to live in a class, the mnemonic words are only used for validation, not seed generation

Copy link
Collaborator

Choose a reason for hiding this comment

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

@fubuloubu were you going to update this now or in a separate PR?

Copy link
Contributor Author

@fubuloubu fubuloubu Feb 27, 2020

Choose a reason for hiding this comment

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

I'd like to do it as a separate update, if that's okay. I think what we have here is fine for now, we're unlikely to restructure how the lists work or to define alternative lists, and adding new lists from the official BIP39 registry is fairly easy. I added caching for now.

eth_account/hdaccount/mnemonic.py Outdated Show resolved Hide resolved
eth_account/hdaccount/mnemonic.py Outdated Show resolved Hide resolved
eth_account/hdaccount/mnemonic.py Outdated Show resolved Hide resolved
setup.py Outdated Show resolved Hide resolved
tests/core/test_mnemonic.py Show resolved Hide resolved
tests/core/test_mnemonic.py Outdated Show resolved Hide resolved
@fubuloubu
Copy link
Contributor Author

fubuloubu commented Feb 19, 2020

@pipermerriam I resolved everything except your series of comments on wordlist classes and coming up with a better structure. Feel free to re-arrange or restructure as you see fit.

fubuloubu added a commit to fubuloubu/eth-account that referenced this pull request Feb 19, 2020
eth_account/hdaccount/mnemonic.py Outdated Show resolved Hide resolved
setup.py Outdated Show resolved Hide resolved
@fubuloubu
Copy link
Contributor Author

@pipermerriam #89 (comment) was resolved in 0f69fcb (I can't comment on it directly)

fubuloubu added a commit to fubuloubu/eth-account that referenced this pull request Feb 21, 2020
@fubuloubu
Copy link
Contributor Author

Any updates with this?

@kclowes
Copy link
Collaborator

kclowes commented Feb 26, 2020

@fubuloubu I'll give it one more look-over tomorrow (Thursday) morning!

Copy link
Collaborator

@kclowes kclowes left a comment

Choose a reason for hiding this comment

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

@fubuloubu I just added a couple last comments! Generally looks good! Thanks for adding all the testing!


@combomethod
def list_languages(_Mnemonic):
return sorted(Path(f).stem for f in WORDLIST_DIR.rglob("*.txt"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

@fubuloubu were you going to update this now or in a separate PR?

eth_account/hdaccount/mnemonic.py Show resolved Hide resolved
Copy link
Member

@wolovim wolovim left a comment

Choose a reason for hiding this comment

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

Thanks Bryant. Just a couple non-blocking comments/questions:

eth_account/hdaccount/mnemonic.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@kclowes kclowes left a comment

Choose a reason for hiding this comment

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

Added one more comment from manual testing... If we're lucky maybe we can get up to 90 comments on this PR!

eth_account/hdaccount/mnemonic.py Outdated Show resolved Hide resolved
@fubuloubu
Copy link
Contributor Author

fubuloubu commented Mar 3, 2020

@kclowes I merged it on down to 32 commits. There was a lot of suggestions in there, not sure how much more I should go down.

fubuloubu added a commit to fubuloubu/eth-account that referenced this pull request Mar 3, 2020
@kclowes
Copy link
Collaborator

kclowes commented Mar 4, 2020

LGTM! Thanks @fubuloubu!

@kclowes kclowes merged commit affc4c8 into ethereum:master Mar 4, 2020
fubuloubu added a commit to fubuloubu/eth-account that referenced this pull request Mar 4, 2020
fubuloubu added a commit to fubuloubu/eth-account that referenced this pull request Mar 19, 2020
fubuloubu added a commit to fubuloubu/eth-account that referenced this pull request Mar 20, 2020
fubuloubu added a commit to fubuloubu/eth-account that referenced this pull request Mar 20, 2020
fubuloubu added a commit to fubuloubu/eth-account that referenced this pull request Mar 20, 2020
fubuloubu added a commit to fubuloubu/eth-account that referenced this pull request Mar 20, 2020
fubuloubu added a commit to fubuloubu/eth-account that referenced this pull request Mar 20, 2020
@step21
Copy link

step21 commented Oct 22, 2020

Would this also work with newer bitarray?

@fubuloubu fubuloubu deleted the bip39 branch October 22, 2020 19:46
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.

5 participants