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

Use rust-bip39 instead of tiny-bip39 #462

Merged
merged 4 commits into from
Nov 4, 2021

Conversation

rajarshimaitra
Copy link
Contributor

@rajarshimaitra rajarshimaitra commented Nov 1, 2021

Description

Fixes #399. This can solve the current version conflict issues of tiny-bip39 dependencies and replace that with rust-bip39.

Few small refactoring changes were required for that.

rust-bip39 doesn't have dedicated MnemonicType enum to denote mnemonic entropy (aka word count). To make the impl consistent with existing traits I have wrote a simple WordCount enum to capture that.

Notes to the reviewers

All previous tests are passing.

Checklists

All Submissions:

  • I've signed all my commits
  • I followed the contribution guidelines
  • I ran cargo fmt and cargo clippy before committing

dependency updated from tiny-bip39 to rust-bip39
@notmandatory
Copy link
Member

notmandatory commented Nov 1, 2021

Need to make a small fix in src/keys/mod.rs at line 463:

   Mnemonic::parse_in(
        Language::English, "jelly crash boy whisper mouse ecology tuna soccer memory million news short"       
   )?

Then all tests should pass.

@notmandatory
Copy link
Member

LGTM! just need to fix the little CI issue.

@rajarshimaitra rajarshimaitra force-pushed the bip39 branch 2 times, most recently from dc163d4 to 8f26d34 Compare November 2, 2021 10:18
Copy link
Member

@notmandatory notmandatory left a comment

Choose a reason for hiding this comment

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

ACK 8f26d34

Thanks!

@notmandatory
Copy link
Member

Ugh, sorry approved but then I noticed you should also be able to remove the backtrace dependency since it only had to be pinned because it was used in the tiny-bip39.

type Seed = [u8; 64];

/// Type describing entropy length (aka word count) in the mnemonic
pub enum WordCount {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason we don't want to name this MnemonicType?

Copy link
Contributor

Choose a reason for hiding this comment

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

I ask because it kind of used to exist earlier: https://docs.rs/bip39/0.5.1/bip39/enum.MnemonicType.html

Copy link
Contributor Author

@rajarshimaitra rajarshimaitra Nov 3, 2021

Choose a reason for hiding this comment

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

Right point. Reason is, WordCount seems more intuitive to me than MnemonicType. I had to look it up to see what it was doing.

MnemonicType is an enum used in tiny-bip39 which does more than simple word or entropy counting. It makes sense for the context of tiny-bip39 impls, but it seemed too much for rust-bip39 to use directly. It just takes an usize value as "word count".

So, I decided to make our own simple enum for it and it made sense to give it an easier name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

PS: I think it should be WordsCount instead of WordCount.

Copy link
Member

Choose a reason for hiding this comment

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

I agree with @artfuldev that MnemonicType is less of a code change for downstream users but if you want to change it to something more meaningful I like your original name WordCount better. If we're talking about how many words are in an article or book or something we generally say "the word count is 20" .. not "the words count is 20". See also: https://trends.google.com/trends/explore?q=%22words%20count%22,%22word%20count%22

Copy link
Member

Choose a reason for hiding this comment

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

oops, it's already merged. WordsCount will be fine. 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, thats a nice google trick to sort this kinda disputes.. 😂

My bad, I will sneak the change back in some future PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

BTW that reminds me that this is probably a downstream API change. Even if we kept the name MnemonicType the bip39 API still changes. Maybe we should better document the API change somewhere?

Copy link
Member

Choose a reason for hiding this comment

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

Since it does change the API we probably should mention it in the changelog. We can add that in another PR or when we make the next release branch we can add it then.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated in #464

@rajarshimaitra
Copy link
Contributor Author

@notmandatory thanks, yes that should be removed.

Updated..

Use rust-bip39 for mnemonic derivation everywhere.

This requires our own WordCount enum as rust-bip39 doesn't have
explicit mnemonic type definition.
@rajarshimaitra
Copy link
Contributor Author

Updated WordCount -> WordsCount

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.

Switch to a different BIP39 implementation
4 participants