mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-23 02:10:12 +01:00
98f187c301
An array of integers is now used to represent the SRP in three cases: * In the import wallet flow, the UI uses it to pass the user-provided SRP to the background (which converts the array to a buffer). * In the create wallet flow, the UI uses it to retrieve the generated SRP from the background. * When persisting the wallet to state, the background uses it to serialize the SRP. Co-authored-by: Elliot Winkler <elliot.winkler@gmail.com>
44 lines
1.5 KiB
Diff
44 lines
1.5 KiB
Diff
diff --git a/node_modules/eth-hd-keyring/index.js b/node_modules/eth-hd-keyring/index.js
|
|
index 19d1d7f..350d6b8 100644
|
|
--- a/node_modules/eth-hd-keyring/index.js
|
|
+++ b/node_modules/eth-hd-keyring/index.js
|
|
@@ -17,8 +17,11 @@ class HdKeyring extends SimpleKeyring {
|
|
}
|
|
|
|
serialize () {
|
|
+ const mnemonicAsBuffer = typeof this.mnemonic === 'string'
|
|
+ ? Buffer.from(this.mnemonic, 'utf8')
|
|
+ : this.mnemonic
|
|
return Promise.resolve({
|
|
- mnemonic: this.mnemonic,
|
|
+ mnemonic: Array.from(mnemonicAsBuffer.values()),
|
|
numberOfAccounts: this.wallets.length,
|
|
hdPath: this.hdPath,
|
|
})
|
|
@@ -69,9 +72,22 @@ class HdKeyring extends SimpleKeyring {
|
|
|
|
/* PRIVATE METHODS */
|
|
|
|
- _initFromMnemonic (mnemonic) {
|
|
- this.mnemonic = mnemonic
|
|
- const seed = bip39.mnemonicToSeed(mnemonic)
|
|
+ /**
|
|
+ * Sets appropriate properties for the keyring based on the given
|
|
+ * BIP39-compliant mnemonic.
|
|
+ *
|
|
+ * @param {string|Array<number>|Buffer} mnemonic - A seed phrase represented
|
|
+ * as a string, an array of UTF-8 bytes, or a Buffer.
|
|
+ */
|
|
+ _initFromMnemonic(mnemonic) {
|
|
+ if (typeof mnemonic === 'string') {
|
|
+ this.mnemonic = Buffer.from(mnemonic, 'utf8')
|
|
+ } else if (Array.isArray(mnemonic)) {
|
|
+ this.mnemonic = Buffer.from(mnemonic)
|
|
+ } else {
|
|
+ this.mnemonic = mnemonic
|
|
+ }
|
|
+ const seed = bip39.mnemonicToSeed(this.mnemonic)
|
|
this.hdWallet = hdkey.fromMasterSeed(seed)
|
|
this.root = this.hdWallet.derivePath(this.hdPath)
|
|
}
|