diff --git a/CHANGELOG.md b/CHANGELOG.md index c8632cdee..288423913 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Current Master +- [#353](https://github.com/poanetwork/nifty-wallet/pull/353) - Fix synchronous eth_accounts request + ## 5.0.1 Mon Apr 06 2020 - [#347](https://github.com/poanetwork/nifty-wallet/pull/347) - Rollback custom dPath for RSK/ETC diff --git a/app/scripts/background.js b/app/scripts/background.js index c26ee6506..becb4320e 100644 --- a/app/scripts/background.js +++ b/app/scripts/background.js @@ -60,6 +60,7 @@ const isEdge = !isIE && !!window.StyleMedia let popupIsOpen = false let notificationIsOpen = false const openMetamaskTabsIDs = {} +const requestAccountTabIds = {} // state persistence const diskStore = new LocalStorageStore({ storageKey: STORAGE_KEY }) @@ -263,6 +264,9 @@ function setupController (initState, initLangCode) { initLangCode, // platform specific api platform, + getRequestAccountTabIds: () => { + return requestAccountTabIds + }, encryptor: isEdge ? new EdgeEncryptor() : undefined, }) global.metamaskController = controller @@ -328,6 +332,10 @@ function setupController (initState, initLangCode) { [ENVIRONMENT_TYPE_FULLSCREEN]: true, } + const metamaskBlacklistedPorts = [ + 'trezor-connect', + ] + const isClientOpenStatus = () => { return popupIsOpen || Boolean(Object.keys(openMetamaskTabsIDs).length) || notificationIsOpen } @@ -348,11 +356,15 @@ function setupController (initState, initLangCode) { const processName = remotePort.name const isMetaMaskInternalProcess = metamaskInternalProcessHash[processName] + if (metamaskBlacklistedPorts.includes(remotePort.name)) { + return false + } + if (isMetaMaskInternalProcess) { const portStream = new PortStream(remotePort) // communication with popup controller.isClientOpen = true - controller.setupTrustedCommunication(portStream, 'MetaMask') + controller.setupTrustedCommunication(portStream, remotePort.sender) if (processName === ENVIRONMENT_TYPE_POPUP) { popupIsOpen = true @@ -382,6 +394,17 @@ function setupController (initState, initLangCode) { }) } } else { + if (remotePort.sender && remotePort.sender.tab && remotePort.sender.url) { + const tabId = remotePort.sender.tab.id + const url = new URL(remotePort.sender.url) + const origin = url.hostname + + remotePort.onMessage.addListener((msg) => { + if (msg.data && msg.data.method === 'eth_requestAccounts') { + requestAccountTabIds[origin] = tabId + } + }) + } connectExternal(remotePort) } } diff --git a/app/scripts/controllers/permissions/enums.js b/app/scripts/controllers/permissions/enums.js index 745926484..3ecbec4b5 100644 --- a/app/scripts/controllers/permissions/enums.js +++ b/app/scripts/controllers/permissions/enums.js @@ -70,6 +70,7 @@ export const SAFE_METHODS = [ 'eth_signTypedData', 'eth_signTypedData_v1', 'eth_signTypedData_v3', + 'eth_signTypedData_v4', 'eth_submitHashrate', 'eth_submitWork', 'eth_syncing', diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 2b8e65076..d2919a0cf 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -440,7 +440,6 @@ module.exports = class MetamaskController extends EventEmitter { setUsePhishDetect: this.setUsePhishDetect.bind(this), setCurrentLocale: this.setCurrentLocale.bind(this), setDProvider: this.setDProvider.bind(this), - markAccountsFound: this.markAccountsFound.bind(this), markPasswordForgotten: this.markPasswordForgotten.bind(this), unMarkPasswordForgotten: this.unMarkPasswordForgotten.bind(this), getGasPrice: (cb) => cb(null, this.getGasPrice()), @@ -1380,8 +1379,8 @@ cancelEncryptionPublicKey (msgId, cb) { * @param {Object} msgParams - The params passed to eth_signTypedData. * @param {Function} cb - The callback function, called with the signature. */ - newUnsignedTypedMessage (msgParams, req) { - const promise = this.typedMessageManager.addUnapprovedMessageAsync(msgParams, req) + newUnsignedTypedMessage (msgParams, req, version) { + const promise = this.typedMessageManager.addUnapprovedMessageAsync(msgParams, req, version) this.sendUpdate() this.opts.showUnconfirmedMessage() return promise @@ -1392,7 +1391,7 @@ cancelEncryptionPublicKey (msgId, cb) { * Triggers the callback in newUnsignedTypedMessage. * * @param {Object} msgParams - The params passed to eth_signTypedData. - * @returns {Object} Full state update. + * @returns {Object} - Full state update. */ async signTypedMessage (msgParams) { log.info('MetaMaskController - eth_signTypedData') @@ -1434,64 +1433,6 @@ cancelEncryptionPublicKey (msgId, cb) { } } - // --------------------------------------------------------------------------- - // MetaMask Version 3 Migration Account Restauration Methods - - /** - * A legacy method (probably dead code) that was used when we swapped out our - * key management library that we depended on. - * - * Described in: - * https://medium.com/metamask/metamask-3-migration-guide-914b79533cdd - * - * @deprecated - * @param {} migratorOutput - */ - restoreOldVaultAccounts (migratorOutput) { - const { serialized } = migratorOutput - return this.keyringController.restoreKeyring(serialized) - .then(() => migratorOutput) - } - - /** - * A legacy method used to record user confirmation that they understand - * that some of their accounts have been recovered but should be backed up. - * This function no longer does anything and will be removed. - * - * @deprecated - * @param {Function} cb - A callback function called with a full state update. - */ - markAccountsFound (cb) { - // TODO Remove me - cb(null, this.getState()) - } - - /** - * An account object - * @typedef Account - * @property string privateKey - The private key of the account. - */ - - /** - * Probably no longer needed, related to the Version 3 migration. - * Imports a hash of accounts to private keys into the vault. - * - * Described in: - * https://medium.com/metamask/metamask-3-migration-guide-914b79533cdd - * - * Uses the array's private keys to create a new Simple Key Pair keychain - * and add it to the keyring controller. - * @deprecated - * @param {Account[]} lostAccounts - - * @returns {Keyring[]} An array of the restored keyrings. - */ - importLostAccounts ({ lostAccounts }) { - const privKeys = lostAccounts.map(acct => acct.privateKey) - return this.keyringController.restoreKeyring({ - type: 'Simple Key Pair', - data: privKeys, - }) - } //============================================================================= // END (VAULT / KEYRING RELATED METHODS) diff --git a/package-lock.json b/package-lock.json index d6a2ce531..d4e2f5f96 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11878,9 +11878,9 @@ } }, "eth-sig-util": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/eth-sig-util/-/eth-sig-util-2.3.0.tgz", - "integrity": "sha512-ugD1AvaggvKaZDgnS19W5qOfepjGc7qHrt7TrAaL54gJw9SHvgIXJ3r2xOMW30RWJZNP+1GlTOy5oye7yXA4xA==", + "version": "2.5.1", + "resolved": "https://registry.npmjs.org/eth-sig-util/-/eth-sig-util-2.5.1.tgz", + "integrity": "sha512-F5k+6gdSphUtHwCsj0QD59gwxxXoG+ZiFODgTiGS7xc53tPcjBSdBRuhcXdLwXGiytsjk+77oYQRRYeAKXIjBQ==", "requires": { "buffer": "^5.2.1", "elliptic": "^6.4.0", @@ -45006,54 +45006,18 @@ "dev": true }, "nifty-wallet-inpage-provider": { - "version": "github:poanetwork/nifty-wallet-inpage-provider#97f6cbf3ff1684382a3243e60a51f23d213259ca", - "from": "github:poanetwork/nifty-wallet-inpage-provider#1.4.0", + "version": "github:poanetwork/nifty-wallet-inpage-provider#77cc9859e40ecd9720e3c5cc690b0abf5693014b", + "from": "github:poanetwork/nifty-wallet-inpage-provider#1.5.0", "requires": { "eth-json-rpc-errors": "^2.0.2", "fast-deep-equal": "^2.0.1", - "json-rpc-engine": "^3.7.4", - "json-rpc-middleware-stream": "^2.0.0", + "json-rpc-engine": "^5.1.5", + "json-rpc-middleware-stream": "^2.1.1", "loglevel": "^1.6.1", "obj-multiplex": "^1.0.0", - "obs-store": "^3.0.0", + "obs-store": "^4.0.3", "pump": "^3.0.0", "safe-event-emitter": "^1.0.1" - }, - "dependencies": { - "babelify": { - "version": "7.3.0", - "resolved": "https://registry.npmjs.org/babelify/-/babelify-7.3.0.tgz", - "integrity": "sha1-qlau3nBn/XvVSWZu4W3ChQh+iOU=", - "requires": { - "babel-core": "^6.0.14", - "object-assign": "^4.0.0" - } - }, - "json-rpc-engine": { - "version": "3.8.0", - "resolved": "https://registry.npmjs.org/json-rpc-engine/-/json-rpc-engine-3.8.0.tgz", - "integrity": "sha512-6QNcvm2gFuuK4TKU1uwfH0Qd/cOSb9c1lls0gbnIhciktIUQJwz6NQNAW4B1KiGPenv7IKu97V222Yo1bNhGuA==", - "requires": { - "async": "^2.0.1", - "babel-preset-env": "^1.7.0", - "babelify": "^7.3.0", - "json-rpc-error": "^2.0.0", - "promise-to-callback": "^1.0.0", - "safe-event-emitter": "^1.0.1" - } - }, - "obs-store": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/obs-store/-/obs-store-3.0.2.tgz", - "integrity": "sha512-GzBr7KM2TYWoJSlF3sVo1cMIOeyxgXpEdegXLZyYONRpunFHsBdKwOba0ki17kN2stLaEwTNolJChGHafqM7Fw==", - "requires": { - "babel-preset-es2015": "^6.22.0", - "babelify": "^7.3.0", - "readable-stream": "^2.2.2", - "through2": "^2.0.3", - "xtend": "^4.0.1" - } - } } }, "nise": { diff --git a/package.json b/package.json index cc2f2b254..bc70fbedd 100644 --- a/package.json +++ b/package.json @@ -121,7 +121,7 @@ "eth-net-props": "^1.0.33", "eth-phishing-detect": "^1.1.4", "eth-query": "^2.1.2", - "eth-sig-util": "^2.3.0", + "eth-sig-util": "^2.5.1", "eth-token-watcher": "^1.1.7", "eth-trezor-keyring": "github:vbaranov/eth-trezor-keyring#0.4.0", "ethereumjs-abi": "^0.6.7", @@ -156,7 +156,7 @@ "mkdirp": "^0.5.1", "multihashes": "^0.4.12", "nanoid": "^2.1.6", - "nifty-wallet-inpage-provider": "github:poanetwork/nifty-wallet-inpage-provider#1.4.0", + "nifty-wallet-inpage-provider": "github:poanetwork/nifty-wallet-inpage-provider#1.5.0", "nonce-tracker": "^1.0.0", "number-to-bn": "^1.7.0", "obj-multiplex": "^1.0.0", diff --git a/test/unit/app/controllers/metamask-controller-test.js b/test/unit/app/controllers/metamask-controller-test.js index 13e6546f8..0bfbb5a75 100644 --- a/test/unit/app/controllers/metamask-controller-test.js +++ b/test/unit/app/controllers/metamask-controller-test.js @@ -933,14 +933,6 @@ describe('MetaMaskController', function () { }) }) - describe('#markAccountsFound', function () { - it('adds lost accounts to config manager data', function () { - metamaskController.markAccountsFound(noop) - const state = metamaskController.getState() - assert.deepEqual(state.lostAccounts, []) - }) - }) - describe('#markPasswordForgotten', function () { it('adds and sets forgottenPassword to config data to true', function () { metamaskController.markPasswordForgotten(noop)