Skip to content
This repository was archived by the owner on Oct 7, 2024. It is now read-only.

Remove bip39 dependency - #179

Merged
adonesky1 merged 7 commits into
mainfrom
integrating-new-eth-hd-keyring/@metamask/scure-bip39
Dec 14, 2022
Merged

Remove bip39 dependency#179
adonesky1 merged 7 commits into
mainfrom
integrating-new-eth-hd-keyring/@metamask/scure-bip39

Conversation

@adonesky1

@adonesky1adonesky1 commented Dec 14, 2022

Copy link
Copy Markdown
Contributor

Remove bip39 dependency. The validation removed here is now taken care of in @metamask/eth-hd-keyring: https://github.com/MetaMask/eth-hd-keyring/blob/main/index.js#L284

@adonesky1
adonesky1force-pushed the integrating-new-eth-hd-keyring/@metamask/scure-bip39 branch 2 times, most recently from b458c72 to 016f28cCompareDecember 14, 2022 16:05
@adonesky1
adonesky1force-pushed the integrating-new-eth-hd-keyring/@metamask/scure-bip39 branch 2 times, most recently from 028f4b8 to 243c027CompareDecember 14, 2022 18:01
@adonesky1
adonesky1force-pushed the integrating-new-eth-hd-keyring/@metamask/scure-bip39 branch from 243c027 to 55807bcCompareDecember 14, 2022 18:02
Comment threadindex.js Outdated
return new Uint8Array(new Uint16Array(indices).buffer);
}

_mnemonicToUint8Array(mnemonic) {

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Suppose it could be useful to go back and make this a public static method on eth-hd-keyring to avoid this duplication. cc @Gudahtt

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Good point. It would be ideal to eliminate this duplication.

If we're using this code in both places, maybe it would be better to move this to a third place? e.g. https://github.com/MetaMask/utils or @metamask/scure-bip39. Just a thought; eth-hd-keyring would suffice for now.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

yeah maybe @metamask/scure-bip39 may make the most sense?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Or we could drop this validation step. It seems to be redundant; eth-hd-keyring is doing it already here: https://github.com/MetaMask/eth-hd-keyring/blob/main/index.js#L284

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

lol true. In which case KeyringController needn't depend directly on @metamask/scure-bip39 at all!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh! That would be good as well

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Removed bip39 dependency altogether in latest commit: dea4b70

@adonesky1
adonesky1 marked this pull request as ready for review December 14, 2022 18:16
@adonesky1
adonesky1 requested a review from a team as a code ownerDecember 14, 2022 18:16
Comment threadindex.js Outdated
)
) {
throw new Error('Seed phrase is invalid.');
if (!bip39.validateMnemonic(encodedSeedPhrase, wordlist)) {

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

We no longer validate against every wordlist.

@adonesky1
adonesky1force-pushed the integrating-new-eth-hd-keyring/@metamask/scure-bip39 branch from 858c7e0 to 4eb0812CompareDecember 14, 2022 19:51
Comment threadindex.js Outdated
)
) {
throw new Error('Seed phrase is invalid.');
if (!bip39.validateMnemonic(seedPhraseUint8Array, wordlist)) {

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

we only validate against the english wordlist now.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Makes sense.

For the changelog, is this a breaking change? i.e. did eth-hd-keyring ever support non-english mnemonics?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

No it did not. Back when we were using bitcoinjs/bip39 and our fork we would validate against the default wordlist which was [set to english by default].(https://github.com/bitcoinjs/bip39/blob/f88d0dd4db96b3ccbba1c8bd6ec87bff54025949/src/_wordlists.js#L57).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Great, thanks!

Comment threadindex.js
},
);
const [firstAccount] = await firstKeyring.getAccounts();
await this.clearKeyrings();

@GudahttGudahttDec 14, 2022

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Interesting, another async call without an await. In this case the function wasn't doing anything async, so this should result in no functional change.

@adonesky1adonesky1 changed the title Integrating new eth hd keyring/@metamask/scure bip39Remove bip39 dependencyDec 14, 2022

@GudahttGudahtt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

@adonesky1
adonesky1 merged commit e2ebefb into mainDec 14, 2022
@adonesky1
adonesky1 deleted the integrating-new-eth-hd-keyring/@metamask/scure-bip39 branch December 14, 2022 21:46
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@adonesky1@Gudahtt