-
Notifications
You must be signed in to change notification settings - Fork 6
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
metamask patch init #1
Conversation
8ce8f62
to
f378402
Compare
Seems fine. I am actually considering adding this feature upstream. Of course, without |
Before,
|
Clarification: your current approach takes If you switch to the new way, which is coded in this pull request as a first |
Yes this was the primary concern. But I agree keeping the API lightweight makes sense.
Think I've got it ☝️ 👍 |
@paulmillr is there some trick to the test suite? I can't seem to get the err in |
entropy = getCoder(wordlist).decode( | ||
Array.from(new Uint16Array(mnemonic.buffer)).map((i) => wordlist[i]) | ||
); | ||
} | ||
assertEntropy(entropy); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking much better now!
Thinking about it, maybe we should just number[]
a.k.a. array of indexes instead of Uint8Array
? It would become:
entropy = getCoder(wordlist).decode(mnemonic.map((i) => wordlist[i]));
Having number[]
is even better: it clearly says "I am waiting for array of numbers". If we keep Uint8Array, that would mean "we are waiting for some buffer, which is not really a buffer, but an array of numbers".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think for now we will keep Uint8Array
for uniformity and flexibility and consider migrating all to number[]
at some point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Understood, I will probably add the number[]
to the main library and you won't need to maintain the fork when you'll decide to go number[]
way.
@@ -96,16 +104,21 @@ export function mnemonicToEntropy(mnemonic: string, wordlist: string[]): Uint8Ar | |||
* entropyToMnemonic(ent, wordlist); | |||
* // 'legal winner thank year wave sausage worth useful legal winner thank yellow' | |||
*/ | |||
export function entropyToMnemonic(entropy: Uint8Array, wordlist: string[]): string { | |||
export function entropyToMnemonic(entropy: Uint8Array, wordlist: string[]): Uint8Array { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe keep the method as-is, and create a new one:
export function entropyToMnemonicIndexes(entropy: Uint8Array, wordlist: string[]): number[] {
assertEntropy(entropy);
const words = getCoder(wordlist).encode(entropy);
return words.map((word) => wordlist.indexOf(word));
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure we can do this, though we won't be using the old one with this fork...
Also "indexes" and "indices" both seem to be correct. |
Any ideas on this @paulmillr ? |
eef6c67
to
f8bd3f5
Compare
Not sure what's the problem here. Assuming you're running built-in nodejs assertion library? |
yes indeed |
|
Where? It's sync in docs |
no I meant your implementation of |
9d1a513
to
a45888b
Compare
Sorry - not sure how i've missed async function. Removing Still suggesting to change update: saw your comment, all cool |
@paulmillr thanks for all your help with this 🤝 |
Metamask-extension currently uses a fork of bitcoinjs/bip39 (its used in eth-hd-keyring which is used by eth-keyring-controller which is used in the extension.
While seeking to remove extraneous wordlists from the extension bundle as part of the MV3 effort, I recalled that we had discussed switching our BIP39 library from
bitcoinjs/bip39
to@scure/bip39
.This PR applies the required patches to this new MetaMask owned fork of
@scure/bip39
to preserve the security requirement that we store and pass mnemonics in a format other than plain-text/string. As part of the transition to this implementation, mnemonics will be stored/passed asUint8Array
s instead ofBuffer
s. I have POC/tested this new interface in a string of PRs along the dependency tree back to the extension: this pr -> eth-hd-keyring -> eth-keyring-controller -> extension.