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

Conversation

@adonesky1
Copy link
Contributor

@adonesky1 adonesky1 commented Dec 14, 2022

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 adonesky1 force-pushed the integrating-new-eth-hd-keyring/@metamask/scure-bip39 branch 2 times, most recently from b458c72 to 016f28c Compare December 14, 2022 16:05
@adonesky1 adonesky1 force-pushed the integrating-new-eth-hd-keyring/@metamask/scure-bip39 branch 2 times, most recently from 028f4b8 to 243c027 Compare December 14, 2022 18:01
@adonesky1 adonesky1 force-pushed the integrating-new-eth-hd-keyring/@metamask/scure-bip39 branch from 243c027 to 55807bc Compare December 14, 2022 18:02
index.js Outdated
return new Uint8Array(new Uint16Array(indices).buffer);
}

_mnemonicToUint8Array(mnemonic) {
Copy link
Contributor Author

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
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
Contributor Author

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
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
Contributor Author

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
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
Contributor Author

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 requested a review from Gudahtt December 14, 2022 18:16
@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 owner December 14, 2022 18:16
index.js Outdated
)
) {
throw new Error('Seed phrase is invalid.');
if (!bip39.validateMnemonic(encodedSeedPhrase, wordlist)) {
Copy link
Contributor Author

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 adonesky1 force-pushed the integrating-new-eth-hd-keyring/@metamask/scure-bip39 branch from 858c7e0 to 4eb0812 Compare December 14, 2022 19:51
index.js Outdated
)
) {
throw new Error('Seed phrase is invalid.');
if (!bip39.validateMnemonic(seedPhraseUint8Array, wordlist)) {
Copy link
Contributor Author

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
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
Contributor Author

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
Member

Choose a reason for hiding this comment

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

Great, thanks!

@adonesky1 adonesky1 requested a review from kumavis December 14, 2022 20:29
},
);
const [firstAccount] = await firstKeyring.getAccounts();
await this.clearKeyrings();
Copy link
Member

@Gudahtt Gudahtt Dec 14, 2022

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.

@adonesky1 adonesky1 changed the title Integrating new eth hd keyring/@metamask/scure bip39 Remove bip39 dependency Dec 14, 2022
Copy link
Member

@Gudahtt Gudahtt left a comment

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 main Dec 14, 2022
@adonesky1 adonesky1 deleted the integrating-new-eth-hd-keyring/@metamask/scure-bip39 branch December 14, 2022 21:46
Sign up for free to 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.

3 participants