mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 09:57:02 +01:00
Merge pull request #13873 from MetaMask/Version-v10.11.1
Version v10.11.1 RC
This commit is contained in:
commit
d0b7acac2e
14
CHANGELOG.md
14
CHANGELOG.md
@ -6,6 +6,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [10.11.1]
|
||||
### Changed
|
||||
- Fixes GridPlus Lattice bugs by upgrading to `gridplus-sdk` v1.0.0, `eth-lattice-keyring` v0.5.0 and to compatibility with v0.14.0 ([#13834](https://github.com/MetaMask/metamask-extension/pull/13834))
|
||||
- Increases transaction data in state logs
|
||||
- Preserves fewer transactions with shared nonces across networks, decreasing number of old transactions that are not deleted ([#13669](https://github.com/MetaMask/metamask-extension/pull/13669))
|
||||
- Increase the number of transactions saved in state logs to 60 ([#13743](https://github.com/MetaMask/metamask-extension/pull/13743))
|
||||
|
||||
### Fixed
|
||||
- Ensure that MetaMask popup is shown when a user attempts to connect to a dapp they are already connected to ([#13840](https://github.com/MetaMask/metamask-extension/pull/13840))
|
||||
- Submit correct gas limit for Swaps Smart Transactions ([#13891](https://github.com/MetaMask/metamask-extension/pull/13891))
|
||||
|
||||
## [10.11.0]
|
||||
### Added
|
||||
- Swaps: Add support for Smart Transactions on Mainnet and Rinkeby ([#12676](https://github.com/MetaMask/metamask-extension/pull/12676))
|
||||
@ -2764,7 +2775,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
### Uncategorized
|
||||
- Added the ability to restore accounts from seed words.
|
||||
|
||||
[Unreleased]: https://github.com/MetaMask/metamask-extension/compare/v10.11.0...HEAD
|
||||
[Unreleased]: https://github.com/MetaMask/metamask-extension/compare/v10.11.1...HEAD
|
||||
[10.11.1]: https://github.com/MetaMask/metamask-extension/compare/v10.11.0...v10.11.1
|
||||
[10.11.0]: https://github.com/MetaMask/metamask-extension/compare/v10.10.2...v10.11.0
|
||||
[10.10.2]: https://github.com/MetaMask/metamask-extension/compare/v10.10.1...v10.10.2
|
||||
[10.10.1]: https://github.com/MetaMask/metamask-extension/compare/v10.10.0...v10.10.1
|
||||
|
@ -66,7 +66,7 @@
|
||||
"clipboardWrite",
|
||||
"http://localhost:8545/",
|
||||
"https://*.infura.io/",
|
||||
"https://wallet.gridplus.io/*",
|
||||
"https://lattice.gridplus.io/*",
|
||||
"activeTab",
|
||||
"webRequest",
|
||||
"*://*.eth/",
|
||||
|
@ -249,9 +249,9 @@ export default class TransactionStateManager extends EventEmitter {
|
||||
const txsToDelete = transactions
|
||||
.reverse()
|
||||
.filter((tx) => {
|
||||
const { nonce } = tx.txParams;
|
||||
const { nonce, from } = tx.txParams;
|
||||
const { chainId, metamaskNetworkId, status } = tx;
|
||||
const key = `${nonce}-${chainId ?? metamaskNetworkId}`;
|
||||
const key = `${nonce}-${chainId ?? metamaskNetworkId}-${from}`;
|
||||
if (nonceNetworkSet.has(key)) {
|
||||
return false;
|
||||
} else if (
|
||||
|
@ -72,7 +72,7 @@ async function requestEthereumAccountsHandler(
|
||||
// lock state when they were received.
|
||||
try {
|
||||
locks.add(origin);
|
||||
await getUnlockPromise();
|
||||
await getUnlockPromise(true);
|
||||
res.result = await getAccounts();
|
||||
end();
|
||||
} catch (error) {
|
||||
|
@ -11,10 +11,10 @@ const seedPhraseVerifier = {
|
||||
* - The keyring always creates the accounts in the same sequence.
|
||||
*
|
||||
* @param {Array} createdAccounts - The accounts to restore
|
||||
* @param {string} seedWords - The seed words to verify
|
||||
* @returns {Promise<void>} Promises undefined
|
||||
* @param {Buffer} seedPhrase - The seed words to verify, encoded as a Buffer
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async verifyAccounts(createdAccounts, seedWords) {
|
||||
async verifyAccounts(createdAccounts, seedPhrase) {
|
||||
if (!createdAccounts || createdAccounts.length < 1) {
|
||||
throw new Error('No created accounts defined.');
|
||||
}
|
||||
@ -22,7 +22,7 @@ const seedPhraseVerifier = {
|
||||
const keyringController = new KeyringController({});
|
||||
const Keyring = keyringController.getKeyringClassForType('HD Key Tree');
|
||||
const opts = {
|
||||
mnemonic: seedWords,
|
||||
mnemonic: seedPhrase,
|
||||
numberOfAccounts: createdAccounts.length,
|
||||
};
|
||||
|
||||
|
@ -671,7 +671,7 @@ export default class MetamaskController extends EventEmitter {
|
||||
this.networkController,
|
||||
),
|
||||
preferencesStore: this.preferencesController.store,
|
||||
txHistoryLimit: 40,
|
||||
txHistoryLimit: 60,
|
||||
signTransaction: this.keyringController.signTransaction.bind(
|
||||
this.keyringController,
|
||||
),
|
||||
@ -1792,13 +1792,16 @@ export default class MetamaskController extends EventEmitter {
|
||||
* Create a new Vault and restore an existent keyring.
|
||||
*
|
||||
* @param {string} password
|
||||
* @param {string} seed
|
||||
* @param {number[]} encodedSeedPhrase - The seed phrase, encoded as an array
|
||||
* of UTF-8 bytes.
|
||||
*/
|
||||
async createNewVaultAndRestore(password, seed) {
|
||||
async createNewVaultAndRestore(password, encodedSeedPhrase) {
|
||||
const releaseLock = await this.createVaultMutex.acquire();
|
||||
try {
|
||||
let accounts, lastBalance;
|
||||
|
||||
const seedPhraseAsBuffer = Buffer.from(encodedSeedPhrase);
|
||||
|
||||
const { keyringController } = this;
|
||||
|
||||
// clear known identities
|
||||
@ -1819,7 +1822,7 @@ export default class MetamaskController extends EventEmitter {
|
||||
// create new vault
|
||||
const vault = await keyringController.createNewVaultAndRestore(
|
||||
password,
|
||||
seed,
|
||||
seedPhraseAsBuffer,
|
||||
);
|
||||
|
||||
const ethQuery = new EthQuery(this.provider);
|
||||
@ -2279,7 +2282,8 @@ export default class MetamaskController extends EventEmitter {
|
||||
*
|
||||
* Called when the first account is created and on unlocking the vault.
|
||||
*
|
||||
* @returns {Promise<string>} Seed phrase to be confirmed by the user.
|
||||
* @returns {Promise<number[]>} The seed phrase to be confirmed by the user,
|
||||
* encoded as an array of UTF-8 bytes.
|
||||
*/
|
||||
async verifySeedPhrase() {
|
||||
const primaryKeyring = this.keyringController.getKeyringsByType(
|
||||
@ -2290,7 +2294,7 @@ export default class MetamaskController extends EventEmitter {
|
||||
}
|
||||
|
||||
const serialized = await primaryKeyring.serialize();
|
||||
const seedWords = serialized.mnemonic;
|
||||
const seedPhraseAsBuffer = Buffer.from(serialized.mnemonic);
|
||||
|
||||
const accounts = await primaryKeyring.getAccounts();
|
||||
if (accounts.length < 1) {
|
||||
@ -2298,8 +2302,8 @@ export default class MetamaskController extends EventEmitter {
|
||||
}
|
||||
|
||||
try {
|
||||
await seedPhraseVerifier.verifyAccounts(accounts, seedWords);
|
||||
return seedWords;
|
||||
await seedPhraseVerifier.verifyAccounts(accounts, seedPhraseAsBuffer);
|
||||
return Array.from(seedPhraseAsBuffer.values());
|
||||
} catch (err) {
|
||||
log.error(err.message);
|
||||
throw err;
|
||||
|
@ -1175,6 +1175,9 @@
|
||||
}
|
||||
},
|
||||
"bip39": {
|
||||
"globals": {
|
||||
"console.log": true
|
||||
},
|
||||
"packages": {
|
||||
"buffer": true,
|
||||
"create-hash": true,
|
||||
@ -1889,6 +1892,7 @@
|
||||
"eth-hd-keyring": {
|
||||
"packages": {
|
||||
"bip39": true,
|
||||
"buffer": true,
|
||||
"eth-sig-util": true,
|
||||
"eth-simple-keyring": true,
|
||||
"ethereumjs-wallet": true
|
||||
@ -1947,6 +1951,7 @@
|
||||
"packages": {
|
||||
"bip39": true,
|
||||
"browser-passworder": true,
|
||||
"buffer": true,
|
||||
"eth-hd-keyring": true,
|
||||
"eth-sig-util": true,
|
||||
"eth-simple-keyring": true,
|
||||
@ -2337,6 +2342,7 @@
|
||||
"gridplus-sdk": {
|
||||
"globals": {
|
||||
"console.error": true,
|
||||
"console.warn": true,
|
||||
"setTimeout": true
|
||||
},
|
||||
"packages": {
|
||||
@ -2350,6 +2356,7 @@
|
||||
"crc-32": true,
|
||||
"elliptic": true,
|
||||
"eth-eip712-util-browser": true,
|
||||
"hash.js": true,
|
||||
"js-sha3": true,
|
||||
"rlp-browser": true,
|
||||
"secp256k1": true,
|
||||
|
@ -1194,6 +1194,9 @@
|
||||
}
|
||||
},
|
||||
"bip39": {
|
||||
"globals": {
|
||||
"console.log": true
|
||||
},
|
||||
"packages": {
|
||||
"buffer": true,
|
||||
"create-hash": true,
|
||||
@ -1908,6 +1911,7 @@
|
||||
"eth-hd-keyring": {
|
||||
"packages": {
|
||||
"bip39": true,
|
||||
"buffer": true,
|
||||
"eth-sig-util": true,
|
||||
"eth-simple-keyring": true,
|
||||
"ethereumjs-wallet": true
|
||||
@ -1966,6 +1970,7 @@
|
||||
"packages": {
|
||||
"bip39": true,
|
||||
"browser-passworder": true,
|
||||
"buffer": true,
|
||||
"eth-hd-keyring": true,
|
||||
"eth-sig-util": true,
|
||||
"eth-simple-keyring": true,
|
||||
@ -2356,6 +2361,7 @@
|
||||
"gridplus-sdk": {
|
||||
"globals": {
|
||||
"console.error": true,
|
||||
"console.warn": true,
|
||||
"setTimeout": true
|
||||
},
|
||||
"packages": {
|
||||
@ -2369,6 +2375,7 @@
|
||||
"crc-32": true,
|
||||
"elliptic": true,
|
||||
"eth-eip712-util-browser": true,
|
||||
"hash.js": true,
|
||||
"js-sha3": true,
|
||||
"rlp-browser": true,
|
||||
"secp256k1": true,
|
||||
|
@ -1175,6 +1175,9 @@
|
||||
}
|
||||
},
|
||||
"bip39": {
|
||||
"globals": {
|
||||
"console.log": true
|
||||
},
|
||||
"packages": {
|
||||
"buffer": true,
|
||||
"create-hash": true,
|
||||
@ -1889,6 +1892,7 @@
|
||||
"eth-hd-keyring": {
|
||||
"packages": {
|
||||
"bip39": true,
|
||||
"buffer": true,
|
||||
"eth-sig-util": true,
|
||||
"eth-simple-keyring": true,
|
||||
"ethereumjs-wallet": true
|
||||
@ -1947,6 +1951,7 @@
|
||||
"packages": {
|
||||
"bip39": true,
|
||||
"browser-passworder": true,
|
||||
"buffer": true,
|
||||
"eth-hd-keyring": true,
|
||||
"eth-sig-util": true,
|
||||
"eth-simple-keyring": true,
|
||||
@ -2337,6 +2342,7 @@
|
||||
"gridplus-sdk": {
|
||||
"globals": {
|
||||
"console.error": true,
|
||||
"console.warn": true,
|
||||
"setTimeout": true
|
||||
},
|
||||
"packages": {
|
||||
@ -2350,6 +2356,7 @@
|
||||
"crc-32": true,
|
||||
"elliptic": true,
|
||||
"eth-eip712-util-browser": true,
|
||||
"hash.js": true,
|
||||
"js-sha3": true,
|
||||
"rlp-browser": true,
|
||||
"secp256k1": true,
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "metamask-crx",
|
||||
"version": "10.11.0",
|
||||
"version": "10.11.1",
|
||||
"private": true,
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -150,7 +150,7 @@
|
||||
"eth-json-rpc-infura": "^5.1.0",
|
||||
"eth-json-rpc-middleware": "^8.0.0",
|
||||
"eth-keyring-controller": "^6.2.0",
|
||||
"eth-lattice-keyring": "^0.4.0",
|
||||
"eth-lattice-keyring": "^0.5.0",
|
||||
"eth-method-registry": "^2.0.0",
|
||||
"eth-query": "^2.1.2",
|
||||
"eth-rpc-errors": "^4.0.2",
|
||||
|
99
patches/bip39+2.5.0.patch
Normal file
99
patches/bip39+2.5.0.patch
Normal file
@ -0,0 +1,99 @@
|
||||
diff --git a/node_modules/bip39/index.js b/node_modules/bip39/index.js
|
||||
index aa0f29f..bee8008 100644
|
||||
--- a/node_modules/bip39/index.js
|
||||
+++ b/node_modules/bip39/index.js
|
||||
@@ -48,7 +48,9 @@ function salt (password) {
|
||||
}
|
||||
|
||||
function mnemonicToSeed (mnemonic, password) {
|
||||
- var mnemonicBuffer = Buffer.from(unorm.nfkd(mnemonic), 'utf8')
|
||||
+ var mnemonicBuffer = typeof mnemonic === 'string'
|
||||
+ ? Buffer.from(unorm.nfkd(mnemonic), 'utf8')
|
||||
+ : mnemonic
|
||||
var saltBuffer = Buffer.from(salt(unorm.nfkd(password)), 'utf8')
|
||||
|
||||
return pbkdf2(mnemonicBuffer, saltBuffer, 2048, 64, 'sha512')
|
||||
@@ -61,12 +63,28 @@ function mnemonicToSeedHex (mnemonic, password) {
|
||||
function mnemonicToEntropy (mnemonic, wordlist) {
|
||||
wordlist = wordlist || DEFAULT_WORDLIST
|
||||
|
||||
- var words = unorm.nfkd(mnemonic).split(' ')
|
||||
+ var mnemonicAsBuffer = typeof mnemonic === 'string'
|
||||
+ ? Buffer.from(unorm.nfkd(mnemonic), 'utf8')
|
||||
+ : mnemonic
|
||||
+
|
||||
+ var words = [];
|
||||
+ var currentWord = [];
|
||||
+ for (const byte of mnemonicAsBuffer.values()) {
|
||||
+ // split at space or \u3000 (ideographic space, for Japanese wordlists)
|
||||
+ if (byte === 0x20 || byte === 0x3000) {
|
||||
+ words.push(Buffer.from(currentWord));
|
||||
+ currentWord = [];
|
||||
+ } else {
|
||||
+ currentWord.push(byte);
|
||||
+ }
|
||||
+ }
|
||||
+ words.push(Buffer.from(currentWord));
|
||||
+
|
||||
if (words.length % 3 !== 0) throw new Error(INVALID_MNEMONIC)
|
||||
|
||||
// convert word indices to 11 bit binary strings
|
||||
var bits = words.map(function (word) {
|
||||
- var index = wordlist.indexOf(word)
|
||||
+ var index = wordlist.indexOf(word.toString('utf8'))
|
||||
if (index === -1) throw new Error(INVALID_MNEMONIC)
|
||||
|
||||
return lpad(index.toString(2), '0', 11)
|
||||
@@ -104,12 +122,41 @@ function entropyToMnemonic (entropy, wordlist) {
|
||||
|
||||
var bits = entropyBits + checksumBits
|
||||
var chunks = bits.match(/(.{1,11})/g)
|
||||
- var words = chunks.map(function (binary) {
|
||||
+ var wordsAsBuffers = chunks.map(function (binary) {
|
||||
var index = binaryToByte(binary)
|
||||
- return wordlist[index]
|
||||
+ return Buffer.from(wordlist[index], 'utf8')
|
||||
})
|
||||
|
||||
- return wordlist === JAPANESE_WORDLIST ? words.join('\u3000') : words.join(' ')
|
||||
+ var bufferSize = wordsAsBuffers.reduce(function (bufferSize, wordAsBuffer, i) {
|
||||
+ var shouldAddSeparator = i < wordsAsBuffers.length - 1
|
||||
+ return (
|
||||
+ bufferSize +
|
||||
+ wordAsBuffer.length +
|
||||
+ (shouldAddSeparator ? 1 : 0)
|
||||
+ )
|
||||
+ }, 0)
|
||||
+ var separator = wordlist === JAPANESE_WORDLIST ? '\u3000' : ' '
|
||||
+ var result = wordsAsBuffers.reduce(function (result, wordAsBuffer, i) {
|
||||
+ var shouldAddSeparator = i < wordsAsBuffers.length - 1
|
||||
+ result.workingBuffer.set(wordAsBuffer, result.offset)
|
||||
+ if (shouldAddSeparator) {
|
||||
+ result.workingBuffer.write(
|
||||
+ separator,
|
||||
+ result.offset + wordAsBuffer.length,
|
||||
+ separator.length,
|
||||
+ 'utf8'
|
||||
+ )
|
||||
+ }
|
||||
+ return {
|
||||
+ workingBuffer: result.workingBuffer,
|
||||
+ offset: (
|
||||
+ result.offset +
|
||||
+ wordAsBuffer.length +
|
||||
+ (shouldAddSeparator ? 1 : 0)
|
||||
+ )
|
||||
+ }
|
||||
+ }, { workingBuffer: Buffer.alloc(bufferSize), offset: 0 })
|
||||
+ return result.workingBuffer;
|
||||
}
|
||||
|
||||
function generateMnemonic (strength, rng, wordlist) {
|
||||
@@ -124,6 +171,7 @@ function validateMnemonic (mnemonic, wordlist) {
|
||||
try {
|
||||
mnemonicToEntropy(mnemonic, wordlist)
|
||||
} catch (e) {
|
||||
+ console.log('could not validate mnemonic', e)
|
||||
return false
|
||||
}
|
||||
|
43
patches/eth-hd-keyring+3.6.0.patch
Normal file
43
patches/eth-hd-keyring+3.6.0.patch
Normal file
@ -0,0 +1,43 @@
|
||||
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)
|
||||
}
|
37
patches/eth-keyring-controller+6.2.1.patch
Normal file
37
patches/eth-keyring-controller+6.2.1.patch
Normal file
@ -0,0 +1,37 @@
|
||||
diff --git a/node_modules/eth-keyring-controller/index.js b/node_modules/eth-keyring-controller/index.js
|
||||
index 250ab98..38615aa 100644
|
||||
--- a/node_modules/eth-keyring-controller/index.js
|
||||
+++ b/node_modules/eth-keyring-controller/index.js
|
||||
@@ -84,15 +84,20 @@ class KeyringController extends EventEmitter {
|
||||
*
|
||||
* @emits KeyringController#unlock
|
||||
* @param {string} password - The password to encrypt the vault with
|
||||
- * @param {string} seed - The BIP44-compliant seed phrase.
|
||||
+ * @param {string|Array<number>} seedPhrase - The BIP39-compliant seed phrase,
|
||||
+ * either as a string or an array of UTF-8 bytes that represent the string.
|
||||
* @returns {Promise<Object>} A Promise that resolves to the state.
|
||||
*/
|
||||
- createNewVaultAndRestore (password, seed) {
|
||||
+ createNewVaultAndRestore(password, seedPhrase) {
|
||||
+ const seedPhraseAsBuffer = typeof seedPhrase === 'string'
|
||||
+ ? Buffer.from(seedPhrase, 'utf8')
|
||||
+ : Buffer.from(seedPhrase)
|
||||
+
|
||||
if (typeof password !== 'string') {
|
||||
return Promise.reject(new Error('Password must be text.'))
|
||||
}
|
||||
|
||||
- if (!bip39.validateMnemonic(seed)) {
|
||||
+ if (!bip39.validateMnemonic(seedPhraseAsBuffer)) {
|
||||
return Promise.reject(new Error('Seed phrase is invalid.'))
|
||||
}
|
||||
|
||||
@@ -101,7 +106,7 @@ class KeyringController extends EventEmitter {
|
||||
return this.persistAllKeyrings(password)
|
||||
.then(() => {
|
||||
return this.addNewKeyring('HD Key Tree', {
|
||||
- mnemonic: seed,
|
||||
+ mnemonic: seedPhraseAsBuffer,
|
||||
numberOfAccounts: 1,
|
||||
})
|
||||
})
|
@ -222,7 +222,7 @@
|
||||
overflow-wrap: break-word;
|
||||
border-bottom: 1px solid #d2d8dd;
|
||||
padding: 6px 18px 15px;
|
||||
white-space: pre;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
&__help-link {
|
||||
|
@ -915,6 +915,9 @@ export const signAndSendSwapsSmartTransaction = ({
|
||||
const smartTransactionFees = await dispatch(
|
||||
fetchSwapsSmartTransactionFees(unsignedTransaction),
|
||||
);
|
||||
unsignedTransaction.gas = `0x${decimalToHex(
|
||||
smartTransactionFees?.gasLimit || 0,
|
||||
)}`;
|
||||
const uuid = await dispatch(
|
||||
signAndSendSmartTransaction({
|
||||
unsignedTransaction,
|
||||
|
@ -82,20 +82,39 @@ export function tryUnlockMetamask(password) {
|
||||
};
|
||||
}
|
||||
|
||||
export function createNewVaultAndRestore(password, seed) {
|
||||
/**
|
||||
* Adds a new account where all data is encrypted using the given password and
|
||||
* where all addresses are generated from a given seed phrase.
|
||||
*
|
||||
* @param {string} password - The password.
|
||||
* @param {string} seedPhrase - The seed phrase.
|
||||
* @returns {Object} The updated state of the keyring controller.
|
||||
*/
|
||||
export function createNewVaultAndRestore(password, seedPhrase) {
|
||||
return (dispatch) => {
|
||||
dispatch(showLoadingIndication());
|
||||
log.debug(`background.createNewVaultAndRestore`);
|
||||
|
||||
// Encode the secret recovery phrase as an array of integers so that it is
|
||||
// serialized as JSON properly.
|
||||
const encodedSeedPhrase = Array.from(
|
||||
Buffer.from(seedPhrase, 'utf8').values(),
|
||||
);
|
||||
|
||||
let vault;
|
||||
return new Promise((resolve, reject) => {
|
||||
background.createNewVaultAndRestore(password, seed, (err, _vault) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
vault = _vault;
|
||||
resolve();
|
||||
});
|
||||
background.createNewVaultAndRestore(
|
||||
password,
|
||||
encodedSeedPhrase,
|
||||
(err, _vault) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
vault = _vault;
|
||||
resolve();
|
||||
},
|
||||
);
|
||||
})
|
||||
.then(() => dispatch(unMarkPasswordForgotten()))
|
||||
.then(() => {
|
||||
@ -117,8 +136,8 @@ export function createNewVaultAndGetSeedPhrase(password) {
|
||||
|
||||
try {
|
||||
await createNewVault(password);
|
||||
const seedWords = await verifySeedPhrase();
|
||||
return seedWords;
|
||||
const seedPhrase = await verifySeedPhrase();
|
||||
return seedPhrase;
|
||||
} catch (error) {
|
||||
dispatch(displayWarning(error.message));
|
||||
throw new Error(error.message);
|
||||
@ -134,9 +153,9 @@ export function unlockAndGetSeedPhrase(password) {
|
||||
|
||||
try {
|
||||
await submitPassword(password);
|
||||
const seedWords = await verifySeedPhrase();
|
||||
const seedPhrase = await verifySeedPhrase();
|
||||
await forceUpdateMetamaskState(dispatch);
|
||||
return seedWords;
|
||||
return seedPhrase;
|
||||
} catch (error) {
|
||||
dispatch(displayWarning(error.message));
|
||||
throw new Error(error.message);
|
||||
@ -185,17 +204,9 @@ export function verifyPassword(password) {
|
||||
});
|
||||
}
|
||||
|
||||
export function verifySeedPhrase() {
|
||||
return new Promise((resolve, reject) => {
|
||||
background.verifySeedPhrase((error, seedWords) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
return;
|
||||
}
|
||||
|
||||
resolve(seedWords);
|
||||
});
|
||||
});
|
||||
export async function verifySeedPhrase() {
|
||||
const encodedSeedPhrase = await promisifiedBackground.verifySeedPhrase();
|
||||
return Buffer.from(encodedSeedPhrase).toString('utf8');
|
||||
}
|
||||
|
||||
export function requestRevealSeedWords(password) {
|
||||
@ -205,11 +216,11 @@ export function requestRevealSeedWords(password) {
|
||||
|
||||
try {
|
||||
await verifyPassword(password);
|
||||
const seedWords = await verifySeedPhrase();
|
||||
return seedWords;
|
||||
const seedPhrase = await verifySeedPhrase();
|
||||
return seedPhrase;
|
||||
} catch (error) {
|
||||
dispatch(displayWarning(error.message));
|
||||
throw new Error(error.message);
|
||||
throw error;
|
||||
} finally {
|
||||
dispatch(hideLoadingIndication());
|
||||
}
|
||||
|
@ -111,7 +111,9 @@ describe('Actions', () => {
|
||||
|
||||
actions._setBackgroundConnection(background);
|
||||
|
||||
await store.dispatch(actions.createNewVaultAndRestore());
|
||||
await store.dispatch(
|
||||
actions.createNewVaultAndRestore('password', 'test'),
|
||||
);
|
||||
expect(createNewVaultAndRestore.callCount).toStrictEqual(1);
|
||||
});
|
||||
|
||||
@ -134,7 +136,9 @@ describe('Actions', () => {
|
||||
{ type: 'HIDE_LOADING_INDICATION' },
|
||||
];
|
||||
|
||||
await store.dispatch(actions.createNewVaultAndRestore());
|
||||
await store.dispatch(
|
||||
actions.createNewVaultAndRestore('password', 'test'),
|
||||
);
|
||||
|
||||
expect(store.getActions()).toStrictEqual(expectedActions);
|
||||
});
|
||||
@ -155,7 +159,7 @@ describe('Actions', () => {
|
||||
];
|
||||
|
||||
await expect(
|
||||
store.dispatch(actions.createNewVaultAndRestore()),
|
||||
store.dispatch(actions.createNewVaultAndRestore('password', 'test')),
|
||||
).rejects.toThrow('error');
|
||||
|
||||
expect(store.getActions()).toStrictEqual(expectedActions);
|
||||
@ -174,7 +178,7 @@ describe('Actions', () => {
|
||||
cb(),
|
||||
);
|
||||
const verifySeedPhrase = background.verifySeedPhrase.callsFake((cb) =>
|
||||
cb(),
|
||||
cb(null, Array.from(Buffer.from('test').values())),
|
||||
);
|
||||
|
||||
actions._setBackgroundConnection(background);
|
||||
|
39
yarn.lock
39
yarn.lock
@ -11084,16 +11084,16 @@ eth-keyring-controller@^6.2.0, eth-keyring-controller@^6.2.1:
|
||||
loglevel "^1.5.0"
|
||||
obs-store "^4.0.3"
|
||||
|
||||
eth-lattice-keyring@^0.4.0:
|
||||
version "0.4.9"
|
||||
resolved "https://registry.yarnpkg.com/eth-lattice-keyring/-/eth-lattice-keyring-0.4.9.tgz#327a41fa25ef28dfc9fe87f2ce11e95139adfd67"
|
||||
integrity sha512-ZflOgYrbuGJGPSDWgDA6PndCIlYRS2M+/bxKsJupbPgz/O8XwQdTGttszp0mHwOqPdvUULUmW08QCqd8trnuVg==
|
||||
eth-lattice-keyring@^0.5.0:
|
||||
version "0.5.0"
|
||||
resolved "https://registry.yarnpkg.com/eth-lattice-keyring/-/eth-lattice-keyring-0.5.0.tgz#19dbbc2de31008dfd576531fa44a5d34061e61c8"
|
||||
integrity sha512-+6iTQqrAqneUDfLR5aLVmYtys++a8C5N6F/9ibEtGT3YNYUE0NLZMI/DvFz/JhjpHhTjSXXtSb3yUajW6liAaQ==
|
||||
dependencies:
|
||||
"@ethereumjs/common" "^2.4.0"
|
||||
"@ethereumjs/tx" "^3.1.1"
|
||||
bignumber.js "^9.0.1"
|
||||
ethereumjs-util "^7.0.10"
|
||||
gridplus-sdk "^0.9.7"
|
||||
gridplus-sdk "^1.0.0"
|
||||
|
||||
eth-lib@0.2.8:
|
||||
version "0.2.8"
|
||||
@ -11405,10 +11405,10 @@ ethers@^4.0.20, ethers@^4.0.28:
|
||||
uuid "2.0.1"
|
||||
xmlhttprequest "1.8.0"
|
||||
|
||||
ethers@^5.0.8, ethers@^5.4.0, ethers@^5.4.1, ethers@^5.4.5:
|
||||
version "5.5.1"
|
||||
resolved "https://registry.yarnpkg.com/ethers/-/ethers-5.5.1.tgz#d3259a95a42557844aa543906c537106c0406fbf"
|
||||
integrity sha512-RodEvUFZI+EmFcE6bwkuJqpCYHazdzeR1nMzg+YWQSmQEsNtfl1KHGfp/FWZYl48bI/g7cgBeP2IlPthjiVngw==
|
||||
ethers@^5.0.8, ethers@^5.4.0, ethers@^5.4.1, ethers@^5.4.5, ethers@^5.5.1:
|
||||
version "5.5.4"
|
||||
resolved "https://registry.yarnpkg.com/ethers/-/ethers-5.5.4.tgz#e1155b73376a2f5da448e4a33351b57a885f4352"
|
||||
integrity sha512-N9IAXsF8iKhgHIC6pquzRgPBJEzc9auw3JoRkaKe+y4Wl/LFBtDDunNe7YmdomontECAcC5APaAgWZBiu1kirw==
|
||||
dependencies:
|
||||
"@ethersproject/abi" "5.5.0"
|
||||
"@ethersproject/abstract-provider" "5.5.1"
|
||||
@ -13456,10 +13456,22 @@ graphql-request@^1.8.2:
|
||||
dependencies:
|
||||
cross-fetch "2.2.2"
|
||||
|
||||
gridplus-sdk@^0.9.7:
|
||||
version "0.9.10"
|
||||
resolved "https://registry.yarnpkg.com/gridplus-sdk/-/gridplus-sdk-0.9.10.tgz#8835e8bc9a2ca7ae163520ddcc0b313350e67dd2"
|
||||
integrity sha512-CNvhyaz3F8UvlHqihFJlOt+FenmFkb2dFrbBTyRth/nlzD8Tm0HjW+uyY1W0ekDp45Exz9l0VY0EmdvjphBe1w==
|
||||
graphql-subscriptions@^1.1.0:
|
||||
version "1.2.1"
|
||||
resolved "https://registry.yarnpkg.com/graphql-subscriptions/-/graphql-subscriptions-1.2.1.tgz#2142b2d729661ddf967b7388f7cf1dd4cf2e061d"
|
||||
integrity sha512-95yD/tKi24q8xYa7Q9rhQN16AYj5wPbrb8tmHGM3WRc9EBmWrG/0kkMl+tQG8wcEuE9ibR4zyOM31p5Sdr2v4g==
|
||||
dependencies:
|
||||
iterall "^1.3.0"
|
||||
|
||||
"graphql@^14.0.2 || ^15.5":
|
||||
version "15.8.0"
|
||||
resolved "https://registry.yarnpkg.com/graphql/-/graphql-15.8.0.tgz#33410e96b012fa3bdb1091cc99a94769db212b38"
|
||||
integrity sha512-5gghUc24tP9HRznNpV2+FIoq3xKkj5dTQqf4v0CpdPbFVwFkWoxOM+o+2OC9ZSvjEMTjfmG9QT+gcvggTwW1zw==
|
||||
|
||||
gridplus-sdk@^1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/gridplus-sdk/-/gridplus-sdk-1.0.0.tgz#008a24a8ec5b50a6fdb8005723a77f5d24fc88cd"
|
||||
integrity sha512-vVyLyAY7Ockkf8hv+em1KkjPwvKkLmb7mYZFY2Vtt60+qpmPut1S2/WjrZGdNGGawWAKAmpw8WKdw5MSg2UkpA==
|
||||
dependencies:
|
||||
aes-js "^3.1.1"
|
||||
bech32 "^2.0.0"
|
||||
@ -13471,6 +13483,7 @@ gridplus-sdk@^0.9.7:
|
||||
crc-32 "^1.2.0"
|
||||
elliptic "6.5.4"
|
||||
eth-eip712-util-browser "^0.0.3"
|
||||
hash.js "^1.1.7"
|
||||
js-sha3 "^0.8.0"
|
||||
rlp-browser "^1.0.1"
|
||||
secp256k1 "4.0.2"
|
||||
|
Loading…
Reference in New Issue
Block a user