From d3254bf766a3a748179cc9dc4705e4b421caa4f2 Mon Sep 17 00:00:00 2001 From: Michele Esposito Date: Tue, 1 Aug 2023 13:19:50 +0200 Subject: [PATCH] refactor: apply @mcmire suggestion --- app/scripts/metamask-controller.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 4a60a2f8f4e7..7c694d19b239 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -2931,7 +2931,7 @@ export default class MetamaskController extends EventEmitter { // create new vault const vault = await this.coreKeyringController.createNewVaultAndRestore( password, - this._bufferToUint8Array(seedPhraseAsBuffer), + this._convertMnemonicToWordlistIndices(seedPhraseAsBuffer), ); const ethQuery = new EthQuery(this.provider); @@ -2974,17 +2974,17 @@ export default class MetamaskController extends EventEmitter { } /** - * Get a Uint8Array mnemonic from Buffer. + * Encodes a BIP-39 mnemonic as the indices of words in the English BIP-39 wordlist. * - * @param {Buffer} mnemonic - The mnemonic phrase as a Buffer - * @returns {Uint8Array} The mnemonic phrase as a Uint8Array + * @param {Buffer} mnemonic - The BIP-39 mnemonic. + * @returns {Buffer} The Unicode code points for the seed phrase formed from the words in the wordlist. */ - _bufferToUint8Array(mnemonic) { + _convertMnemonicToWordlistIndices(mnemonic) { const indices = mnemonic .toString() .split(' ') .map((word) => wordlist.indexOf(word)); - return new Uint8Array(new Uint16Array(indices).buffer); + return new Uint8Array(indices); } /**