From 2254d39ca707e3fa001959ee1a53d6504efbc917 Mon Sep 17 00:00:00 2001 From: kviktorov Date: Thu, 3 Oct 2019 23:11:30 +0300 Subject: [PATCH 01/23] Implementation for "eth_decryptMessage". It allows using private user keys via keyring and decrypting messages that were encrypted via eth-sig-util. - Need to add translations for all languages, except en and ru - Need to fix issue with badges. The decrypt request does not influence on badges, although code for this part is present. The core team, please review this piece. eth-json-rpc-middleware has updated on 4.3.0 the new eth-keyring-controller version Added EncryptionPublicKey and decryptMsgInline features --- app/_locales/en/messages.json | 35 +- app/_locales/ru/messages.json | 48 ++- app/scripts/background.js | 13 +- .../network/createMetamaskMiddleware.js | 4 + .../permissions/permissions-safe-methods.json | 4 +- app/scripts/controllers/threebox.js | 15 + app/scripts/lib/decrypt-message-manager.js | 311 +++++++++++++++++ .../lib/encryption-public-key-manager.js | 304 ++++++++++++++++ app/scripts/metamask-controller.js | 159 +++++++++ package.json | 14 +- test/data/2-state.json | 2 + test/data/mock-state.json | 2 + ui/app/css/itcss/components/index.scss | 4 + .../components/request-decrypt-message.scss | 292 ++++++++++++++++ .../request-encryption-public-key.scss | 190 ++++++++++ ui/app/ducks/app/app.js | 4 +- ui/app/helpers/constants/routes.js | 4 + ui/app/helpers/constants/transactions.js | 2 + ui/app/helpers/utils/transactions.util.js | 10 +- .../confirm-decrypt-message.component.js | 324 ++++++++++++++++++ .../confirm-decrypt-message.container.js | 70 ++++ ui/app/pages/confirm-decrypt-message/index.js | 2 + ...confirm-encryption-public-key.component.js | 218 ++++++++++++ ...confirm-encryption-public-key.container.js | 59 ++++ .../confirm-encryption-public-key/index.js | 2 + .../confirm-transaction-switch.component.js | 10 +- .../confirm-transaction.component.js | 15 + .../send/tests/send-selectors-test-data.js | 4 + ui/app/selectors/confirm-transaction.js | 20 +- ui/app/selectors/selectors.js | 4 +- ui/app/selectors/tests/selectors-test-data.js | 4 + ui/app/selectors/transactions.js | 8 + ui/app/store/actions.js | 134 ++++++++ ui/index.js | 2 +- ui/lib/tx-helper.js | 12 +- yarn.lock | 115 ++++++- 36 files changed, 2386 insertions(+), 34 deletions(-) create mode 100644 app/scripts/lib/decrypt-message-manager.js create mode 100644 app/scripts/lib/encryption-public-key-manager.js create mode 100644 ui/app/css/itcss/components/request-decrypt-message.scss create mode 100644 ui/app/css/itcss/components/request-encryption-public-key.scss create mode 100644 ui/app/pages/confirm-decrypt-message/confirm-decrypt-message.component.js create mode 100644 ui/app/pages/confirm-decrypt-message/confirm-decrypt-message.container.js create mode 100644 ui/app/pages/confirm-decrypt-message/index.js create mode 100644 ui/app/pages/confirm-encryption-public-key/confirm-encryption-public-key.component.js create mode 100644 ui/app/pages/confirm-encryption-public-key/confirm-encryption-public-key.container.js create mode 100644 ui/app/pages/confirm-encryption-public-key/index.js diff --git a/app/_locales/en/messages.json b/app/_locales/en/messages.json index c6ce2b75c28e..386c53a15bd6 100644 --- a/app/_locales/en/messages.json +++ b/app/_locales/en/messages.json @@ -388,7 +388,7 @@ "message": "Custom Spend Limit" }, "dataBackupFoundInfo": { - "message": "Some of your account data was backed up during a previous installation of MetaMask. This could include your settings, contacts and tokens. Would you like to restore this data now?" + "message": "Some of your account data was backed up during a previous installation of MetaMask. This could include your settings, contacts, and tokens. Would you like to restore this data now?" }, "decimalsMustZerotoTen": { "message": "Decimals must be at least 0, and not over 36." @@ -1583,5 +1583,38 @@ }, "zeroGasPriceOnSpeedUpError": { "message": "Zero gas price on speed up" + }, + "decryptRequest" : { + "message": "Decrypt request" + }, + "yourDecryptRequest" : { + "message": "Data decrypt" + }, + "yourEncryptionPublicKeyRequest" : { + "message": "Request encryption public key" + }, + "decrypt" : { + "message": "Decrypt" + }, + "youDecrypt": { + "message": "You are decrypting" + }, + "decryptMessageNotice": { + "message": "$1 would like to read this message to complete your action" + }, + "decryptMetamask": { + "message": "Decrypt with Metamask" + }, + "decryptCopy": { + "message": "Copy encrypted message" + }, + "provide": { + "message": "Provide" + }, + "encryptionPublicKeyRequest": { + "message": "Request ecryption public key" + }, + "ecryptionPublickKeyNotice": { + "message": "By granted this encryption public key for Dapp you will allow to get encrypted messages and decrypt it via Metamask. This key can be used ONLY for encryption messages that decrypt via your private key. Dapp can't sign transaction or something else via this public key." } } diff --git a/app/_locales/ru/messages.json b/app/_locales/ru/messages.json index 43249d6bcdb8..b9b01319b81a 100644 --- a/app/_locales/ru/messages.json +++ b/app/_locales/ru/messages.json @@ -127,6 +127,9 @@ "customRPC": { "message": "Пользовательский RPC" }, + "dataBackupFoundInfo": { + "message": "Некоторые данные вашей учетной записи были экспортированы во время предыдущей установки MetaMask. Это может включать ваши настройки, контакты и токены. Вы хотите импортировать эти данные сейчас?" + }, "decimalsMustZerotoTen": { "message": "Количество десятичных разрядов должно быть минимум 0 и максимум 36." }, @@ -290,6 +293,9 @@ "loadingTokens": { "message": "Загрузка токенов..." }, + "localhost": { + "message": "Localhost 8545" + }, "login": { "message": "Вход" }, @@ -980,8 +986,11 @@ "noConversionRateAvailable": { "message": "Курсы валют недоступны" }, + "noThanks": { + "message": "Нет, спасибо" + }, "notEnoughGas": { - "message": "Нехватает газа" + "message": "Не хватает газа" }, "noWebcamFoundTitle": { "message": "Веб-камера не найдена" @@ -1064,6 +1073,10 @@ "restoreAccountWithSeed": { "message": "Восстановите свой аккаунт с помощью секретной фразы" }, + "restoreWalletPreferences": { + "message": "Были найдены данные экспортированные от $1. Вы желаете восстановить настройки вашего кошелька?", + "description": "$1 это дата в которую данные были экспортированы" + }, "requestsAwaitingAcknowledgement": { "message": "запросы, ожидающие подтверждения" }, @@ -1357,5 +1370,38 @@ }, "yourPrivateSeedPhrase": { "message": "Ваша сид-фраза" + }, + "decryptRequest" : { + "message": "Запрос расшифровки" + }, + "yourDecryptRequest" : { + "message": "Данные для расшифровки" + }, + "yourEncryptionPublicKeyRequest" : { + "message": "Запрос публичного ключа шифрования" + }, + "decrypt" : { + "message": "Расшифровать" + }, + "youDecrypt": { + "message": "Вы расшифровываете" + }, + "decryptMessageNotice": { + "message": "Для $1 необходимо прочитать это сообщение, чтобы завершить Ваше действие" + }, + "decryptMetamask": { + "message": "Расшифровать при помощи Metamask" + }, + "decryptCopy": { + "message": "Скопировать расшифрованное сообщение" + }, + "provide": { + "message": "Предоставить" + }, + "encryptionPublicKeyRequest": { + "message": "Запрос публичного ключа шифрования" + }, + "ecryptionPublickKeyNotice": { + "message": "Предоставив этот открытый ключ шифрования для Dapp, вы сможете получать зашифрованные сообщения и расшифровывать их с помощью Metamask. Этот ключ можно использовать ТОЛЬКО для шифрования сообщений, которые расшифровываются с помощью вашего личного ключа. Dapp не может подписать транзакцию или что-то еще через этот открытый ключ." } } diff --git a/app/scripts/background.js b/app/scripts/background.js index 7dd13e083e15..23e522a1e664 100644 --- a/app/scripts/background.js +++ b/app/scripts/background.js @@ -127,6 +127,8 @@ const { submitMeshMetricsEntry } = setupMetamaskMeshMetrics() * @property {number} unapprovedMsgCount - The number of messages in unapprovedMsgs. * @property {Object} unapprovedPersonalMsgs - An object of messages associated with the currently selected account, mapping a unique ID to the options. * @property {number} unapprovedPersonalMsgCount - The number of messages in unapprovedPersonalMsgs. + * @property {Object} unapprovedDecryptMsgs - An object of messages associated with the currently selected account, mapping a unique ID to the options. + * @property {number} unapprovedDecryptMsgCount - The number of messages in unapprovedDecryptMsgs. * @property {Object} unapprovedTypedMsgs - An object of messages associated with the currently selected account, mapping a unique ID to the options. * @property {number} unapprovedTypedMsgCount - The number of messages in unapprovedTypedMsgs. * @property {string[]} keyringTypes - An array of unique keyring identifying strings, representing available strategies for creating accounts. @@ -425,6 +427,8 @@ function setupController (initState, initLangCode) { controller.txController.on('update:badge', updateBadge) controller.messageManager.on('updateBadge', updateBadge) controller.personalMessageManager.on('updateBadge', updateBadge) + controller.decryptMessageManager.on('updateBadge', updateBadge) + controller.encryptionPublicKeyManager.on('updateBadge', updateBadge) controller.typedMessageManager.on('updateBadge', updateBadge) controller.permissionsController.permissions.subscribe(updateBadge) @@ -436,10 +440,13 @@ function setupController (initState, initLangCode) { let label = '' const unapprovedTxCount = controller.txController.getUnapprovedTxCount() const unapprovedMsgCount = controller.messageManager.unapprovedMsgCount - const unapprovedPersonalMsgs = controller.personalMessageManager.unapprovedPersonalMsgCount - const unapprovedTypedMsgs = controller.typedMessageManager.unapprovedTypedMessagesCount + const unapprovedPersonalMsgCount = controller.personalMessageManager.unapprovedPersonalMsgCount + const unapprovedDecryptMsgCount = controller.decryptMessageManager.unapprovedDecryptMsgCount + const unapprovedEncryptionPublicKeyMsgCount = controller.encryptionPublicKeyManager.unapprovedEncryptionPublicKeyMsgCount + const unapprovedTypedMessagesCount = controller.typedMessageManager.unapprovedTypedMessagesCount const pendingPermissionRequests = Object.keys(controller.permissionsController.permissions.state.permissionsRequests).length - const count = unapprovedTxCount + unapprovedMsgCount + unapprovedPersonalMsgs + unapprovedTypedMsgs + pendingPermissionRequests + const count = unapprovedTxCount + unapprovedMsgCount + unapprovedPersonalMsgCount + unapprovedDecryptMsgCount + unapprovedEncryptionPublicKeyMsgCount + + unapprovedTypedMessagesCount + pendingPermissionRequests if (count) { label = String(count) } diff --git a/app/scripts/controllers/network/createMetamaskMiddleware.js b/app/scripts/controllers/network/createMetamaskMiddleware.js index 58ccb95a1f02..2e4c0068fef9 100644 --- a/app/scripts/controllers/network/createMetamaskMiddleware.js +++ b/app/scripts/controllers/network/createMetamaskMiddleware.js @@ -13,6 +13,8 @@ function createMetamaskMiddleware ({ processTypedMessageV3, processTypedMessageV4, processPersonalMessage, + processDecryptMessage, + processEncryptionPublicKey, getPendingNonce, getPendingTransactionByHash, }) { @@ -30,6 +32,8 @@ function createMetamaskMiddleware ({ processTypedMessageV3, processTypedMessageV4, processPersonalMessage, + processDecryptMessage, + processEncryptionPublicKey, }), createPendingNonceMiddleware({ getPendingNonce }), createPendingTxMiddleware({ getPendingTransactionByHash }), diff --git a/app/scripts/controllers/permissions/permissions-safe-methods.json b/app/scripts/controllers/permissions/permissions-safe-methods.json index 17b46b531346..abae349cb462 100644 --- a/app/scripts/controllers/permissions/permissions-safe-methods.json +++ b/app/scripts/controllers/permissions/permissions-safe-methods.json @@ -45,5 +45,7 @@ "eth_submitHashrate", "eth_submitWork", "eth_syncing", - "eth_uninstallFilter" + "eth_uninstallFilter", + "encryption_public_key", + "eth_decryptMessage", ] \ No newline at end of file diff --git a/app/scripts/controllers/threebox.js b/app/scripts/controllers/threebox.js index 2dca7eea7aa5..88c1f921d90a 100644 --- a/app/scripts/controllers/threebox.js +++ b/app/scripts/controllers/threebox.js @@ -48,6 +48,21 @@ class ThreeBoxController { withAppKeyOrigin: 'wallet://3box.metamask.io', }) }, + processDecryptMessage: (msgParams) => { + return Promise.resolve(keyringController.decryptMessage(msgParams, { + withAppKeyOrigin: 'wallet://3box.metamask.io', + })) + }, + processEncryptionPublicKey: (msgParams) => { + return Promise.resolve(keyringController.encryptionPublicKey, (msgParams, { + withAppKeyOrigin: 'wallet://3box.metamask.io', + })) + }, + processDecryptMessage: (msgParams) => { + return Promise.resolve(keyringController.decryptMessage(msgParams, { + withAppKeyOrigin: 'wallet://3box.metamask.io', + })) + }, }) const initState = { diff --git a/app/scripts/lib/decrypt-message-manager.js b/app/scripts/lib/decrypt-message-manager.js new file mode 100644 index 000000000000..2e4815e58606 --- /dev/null +++ b/app/scripts/lib/decrypt-message-manager.js @@ -0,0 +1,311 @@ +const EventEmitter = require('events') +const ObservableStore = require('obs-store') +const ethUtil = require('ethereumjs-util') +const { ethErrors } = require('eth-json-rpc-errors') +const createId = require('./random-id') +const hexRe = /^[0-9A-Fa-f]+$/g +const log = require('loglevel') + +/** + * Represents, and contains data about, an 'eth_decryptMessage' type decryption request. These are created when a + * decryption for an eth_decryptMessage call is requested. + * + * @see {@link https://web3js.readthedocs.io/en/1.0/web3-eth-Decrypt.html#decrypt} + * + * @typedef {Object} DecryptMessage + * @property {number} id An id to track and identify the message object + * @property {Object} msgParams The parameters to pass to the decryptMessage method once the decryption request is + * approved. + * @property {Object} msgParams.metamaskId Added to msgParams for tracking and identification within MetaMask. + * @property {string} msgParams.data A hex string conversion of the raw buffer data of the decryption request + * @property {number} time The epoch time at which the this message was created + * @property {string} status Indicates whether the decryption request is 'unapproved', 'approved', 'decrypted' or 'rejected' + * @property {string} type The json-prc decryption method for which a decryption request has been made. A 'Message' will + * always have a 'eth_decryptMessage' type. + * + */ + +module.exports = class DecryptMessageManager extends EventEmitter { + /** + * Controller in charge of managing - storing, adding, removing, updating - DecryptMessage. + * + * @typedef {Object} DecryptMessageManager + * @param {Object} opts @deprecated + * @property {Object} memStore The observable store where DecryptMessage are saved with persistance. + * @property {Object} memStore.unapprovedDecryptMsgs A collection of all DecryptMessages in the 'unapproved' state + * @property {number} memStore.unapprovedDecryptMsgCount The count of all DecryptMessages in this.memStore.unapprobedMsgs + * @property {array} messages Holds all messages that have been created by this DecryptMessageManager + * + */ + constructor () { + super() + this.memStore = new ObservableStore({ + unapprovedDecryptMsgs: {}, + unapprovedDecryptMsgCount: 0, + }) + this.messages = [] + } + + /** + * A getter for the number of 'unapproved' DecryptMessages in this.messages + * + * @returns {number} The number of 'unapproved' DecryptMessages in this.messages + * + */ + get unapprovedDecryptMsgCount () { + return Object.keys(this.getUnapprovedMsgs()).length + } + + /** + * A getter for the 'unapproved' DecryptMessages in this.messages + * + * @returns {Object} An index of DecryptMessage ids to DecryptMessages, for all 'unapproved' DecryptMessages in + * this.messages + * + */ + getUnapprovedMsgs () { + return this.messages.filter(msg => msg.status === 'unapproved') + .reduce((result, msg) => { + result[msg.id] = msg; return result + }, {}) + } + + /** + * Creates a new DecryptMessage with an 'unapproved' status using the passed msgParams. this.addMsg is called to add + * the new DecryptMessage to this.messages, and to save the unapproved DecryptMessages from that list to + * this.memStore. + * + * @param {Object} msgParams The params for the eth_decryptMessage call to be made after the message is approved. + * @param {Object} req (optional) The original request object possibly containing the origin + * @returns {promise} When the message has been approved or rejected + * + */ + addUnapprovedMessageAsync (msgParams, req) { + return new Promise((resolve, reject) => { + if (!msgParams.from) { + reject(new Error('MetaMask Message for Decryption: from field is required.')) + } + const msgId = this.addUnapprovedMessage(msgParams, req) + this.once(`${msgId}:finished`, (data) => { + switch (data.status) { + case 'decrypted': + return resolve(data.rawData) + case 'rejected': + return reject(ethErrors.provider.userRejectedRequest('MetaMask Message for Decryption: User denied message decryption.')) + default: + return reject(new Error(`MetaMask Message for Decryption: Unknown problem: ${JSON.stringify(msgParams)}`)) + } + }) + }) + } + + /** + * Creates a new DecryptMessage with an 'unapproved' status using the passed msgParams. this.addMsg is called to add + * the new DecryptMessage to this.messages, and to save the unapproved DecryptMessages from that list to + * this.memStore. + * + * @param {Object} msgParams The params for the eth_decryptMsg call to be made after the message is approved. + * @param {Object} req (optional) The original request object possibly containing the origin + * @returns {number} The id of the newly created DecryptMessage. + * + */ + addUnapprovedMessage (msgParams, req) { + log.debug(`DecryptMessageManager addUnapprovedMessage: ${JSON.stringify(msgParams)}`) + // add origin from request + if (req) { + msgParams.origin = req.origin + } + msgParams.data = this.normalizeMsgData(msgParams.data) + // create txData obj with parameters and meta data + const time = (new Date()).getTime() + const msgId = createId() + const msgData = { + id: msgId, + msgParams: msgParams, + time: time, + status: 'unapproved', + type: 'eth_decryptMessage', + } + this.addMsg(msgData) + + // signal update + this.emit('update') + return msgId + } + + /** + * Adds a passed DecryptMessage to this.messages, and calls this._saveMsgList() to save the unapproved DecryptMessages from that + * list to this.memStore. + * + * @param {Message} msg The DecryptMessage to add to this.messages + * + */ + addMsg (msg) { + this.messages.push(msg) + this._saveMsgList() + } + + /** + * Returns a specified DecryptMessage. + * + * @param {number} msgId The id of the DecryptMessage to get + * @returns {DecryptMessage|undefined} The DecryptMessage with the id that matches the passed msgId, or undefined + * if no DecryptMessage has that id. + * + */ + getMsg (msgId) { + return this.messages.find(msg => msg.id === msgId) + } + + /** + * Approves a DecryptMessage. Sets the message status via a call to this.setMsgStatusApproved, and returns a promise + * with any the message params modified for proper decryption. + * + * @param {Object} msgParams The msgParams to be used when eth_decryptMsg is called, plus data added by MetaMask. + * @param {Object} msgParams.metamaskId Added to msgParams for tracking and identification within MetaMask. + * @returns {Promise} Promises the msgParams object with metamaskId removed. + * + */ + approveMessage (msgParams) { + this.setMsgStatusApproved(msgParams.metamaskId) + return this.prepMsgForDecryption(msgParams) + } + + /** + * Sets a DecryptMessage status to 'approved' via a call to this._setMsgStatus. + * + * @param {number} msgId The id of the DecryptMessage to approve. + * + */ + setMsgStatusApproved (msgId) { + this._setMsgStatus(msgId, 'approved') + } + + /** + * Sets a DecryptMessage status to 'decrypted' via a call to this._setMsgStatus and updates that DecryptMessage in + * this.messages by adding the raw decryption data of the decryption request to the DecryptMessage + * + * @param {number} msgId The id of the DecryptMessage to decrypt. + * @param {buffer} rawData The raw data of the message request + * + */ + setMsgStatusDecrypted (msgId, rawData) { + const msg = this.getMsg(msgId) + msg.rawData = rawData + this._updateMsg(msg) + this._setMsgStatus(msgId, 'decrypted') + } + + /** + * Removes the metamaskId property from passed msgParams and returns a promise which resolves the updated msgParams + * + * @param {Object} msgParams The msgParams to modify + * @returns {Promise} Promises the msgParams with the metamaskId property removed + * + */ + prepMsgForDecryption (msgParams) { + delete msgParams.metamaskId + return Promise.resolve(msgParams) + } + + /** + * Sets a DecryptMessage status to 'rejected' via a call to this._setMsgStatus. + * + * @param {number} msgId The id of the DecryptMessage to reject. + * + */ + rejectMsg (msgId) { + this._setMsgStatus(msgId, 'rejected') + } + + /** + * Sets a TypedMessage status to 'errored' via a call to this._setMsgStatus. + * + * @param {number} msgId The id of the TypedMessage to error + * + */ + errorMessage (msgId, error) { + const msg = this.getMsg(msgId) + msg.error = error + this._updateMsg(msg) + this._setMsgStatus(msgId, 'errored') + } + + /** + * Updates the status of a DecryptMessage in this.messages via a call to this._updateMsg + * + * @private + * @param {number} msgId The id of the DecryptMessage to update. + * @param {string} status The new status of the DecryptMessage. + * @throws A 'DecryptMessageManager - DecryptMessage not found for id: "${msgId}".' if there is no DecryptMessage + * in this.messages with an id equal to the passed msgId + * @fires An event with a name equal to `${msgId}:${status}`. The DecryptMessage is also fired. + * @fires If status is 'rejected' or 'decrypted', an event with a name equal to `${msgId}:finished` is fired along + * with the DecryptMessage + * + */ + _setMsgStatus (msgId, status) { + const msg = this.getMsg(msgId) + if (!msg) { + throw new Error('DecryptMessageManager - Message not found for id: "${msgId}".') + } + msg.status = status + this._updateMsg(msg) + this.emit(`${msgId}:${status}`, msg) + if (status === 'rejected' || status === 'decrypted') { + this.emit(`${msgId}:finished`, msg) + } + } + + /** + * Sets a DecryptMessage in this.messages to the passed DecryptMessage if the ids are equal. Then saves the + * unapprovedDecryptMsgs index to storage via this._saveMsgList + * + * @private + * @param {msg} DecryptMessage A DecryptMessage that will replace an existing DecryptMessage (with the same + * id) in this.messages + * + */ + _updateMsg (msg) { + const index = this.messages.findIndex((message) => message.id === msg.id) + if (index !== -1) { + this.messages[index] = msg + } + this._saveMsgList() + } + + /** + * Saves the unapproved DecryptMessages, and their count, to this.memStore + * + * @private + * @fires 'updateBadge' + * + */ + _saveMsgList () { + const unapprovedDecryptMsgs = this.getUnapprovedMsgs() + const unapprovedDecryptMsgCount = Object.keys(unapprovedDecryptMsgs).length + this.memStore.updateState({ unapprovedDecryptMsgs, unapprovedDecryptMsgCount }) + this.emit('updateBadge') + } + + /** + * A helper function that converts raw buffer data to a hex, or just returns the data if it is already formatted as a hex. + * + * @param {any} data The buffer data to convert to a hex + * @returns {string} A hex string conversion of the buffer data + * + */ + normalizeMsgData (data) { + try { + const stripped = ethUtil.stripHexPrefix(data) + if (stripped.match(hexRe)) { + return ethUtil.addHexPrefix(stripped) + } + } catch (e) { + log.debug(`Message was not hex encoded, interpreting as utf8.`) + } + + return ethUtil.bufferToHex(Buffer.from(data, 'utf8')) + } + +} diff --git a/app/scripts/lib/encryption-public-key-manager.js b/app/scripts/lib/encryption-public-key-manager.js new file mode 100644 index 000000000000..de588f3c04ec --- /dev/null +++ b/app/scripts/lib/encryption-public-key-manager.js @@ -0,0 +1,304 @@ +const EventEmitter = require('events') +const ObservableStore = require('obs-store') +const ethUtil = require('ethereumjs-util') +const { ethErrors } = require('eth-json-rpc-errors') +const createId = require('./random-id') +const hexRe = /^[0-9A-Fa-f]+$/g +const log = require('loglevel') + +/** + * Represents, and contains data about, an 'encryption_public_key' type request. These are created when + * an encryption_public_key call is requested. + * + * @typedef {Object} EncryptionPublicKey + * @property {number} id An id to track and identify the message object + * @property {Object} msgParams The parameters to pass to the encryptionPublicKey method once the request is + * approved. + * @property {Object} msgParams.metamaskId Added to msgParams for tracking and identification within MetaMask. + * @property {string} msgParams.data A hex string conversion of the raw buffer data of the request + * @property {number} time The epoch time at which the this message was created + * @property {string} status Indicates whether the request is 'unapproved', 'approved', 'received' or 'rejected' + * @property {string} type The json-prc method for which a request has been made. A 'Message' will + * always have a 'encryption_public_key' type. + * + */ + +module.exports = class EncryptionPublicKeyManager extends EventEmitter { + /** + * Controller in charge of managing - storing, adding, removing, updating - EncryptionPublicKey. + * + * @typedef {Object} EncryptionPublicKeyManager + * @param {Object} opts @deprecated + * @property {Object} memStore The observable store where EncryptionPublicKey are saved with persistance. + * @property {Object} memStore.unapprovedEncryptionPublicKeyMsgs A collection of all EncryptionPublicKeys in the 'unapproved' state + * @property {number} memStore.unapprovedEncryptionPublicKeyMsgCount The count of all EncryptionPublicKeys in this.memStore.unapprobedMsgs + * @property {array} messages Holds all messages that have been created by this EncryptionPublicKeyManager + * + */ + constructor () { + super() + this.memStore = new ObservableStore({ + unapprovedEncryptionPublicKeyMsgs: {}, + unapprovedEncryptionPublicKeyMsgCount: 0, + }) + this.messages = [] + } + + /** + * A getter for the number of 'unapproved' EncryptionPublicKeys in this.messages + * + * @returns {number} The number of 'unapproved' EncryptionPublicKeys in this.messages + * + */ + get unapprovedEncryptionPublicKeyMsgCount () { + return Object.keys(this.getUnapprovedMsgs()).length + } + + /** + * A getter for the 'unapproved' EncryptionPublicKeys in this.messages + * + * @returns {Object} An index of EncryptionPublicKey ids to EncryptionPublicKeys, for all 'unapproved' EncryptionPublicKeys in + * this.messages + * + */ + getUnapprovedMsgs () { + return this.messages.filter(msg => msg.status === 'unapproved') + .reduce((result, msg) => { + result[msg.id] = msg; return result + }, {}) + } + + /** + * Creates a new EncryptionPublicKey with an 'unapproved' status using the passed msgParams. this.addMsg is called to add + * the new EncryptionPublicKey to this.messages, and to save the unapproved EncryptionPublicKeys from that list to + * this.memStore. + * + * @param {Object} address The param for the encryption_public_key call to be made after the message is approved. + * @param {Object} req (optional) The original request object possibly containing the origin + * @returns {promise} When the message has been approved or rejected + * + */ + addUnapprovedMessageAsync (address, req) { + return new Promise((resolve, reject) => { + if (!address) { + reject(new Error('MetaMask Message for EncryptionPublicKey: address field is required.')) + } + const msgId = this.addUnapprovedMessage(address, req) + this.once(`${msgId}:finished`, (data) => { + switch (data.status) { + case 'received': + return resolve(data.rawData) + case 'rejected': + return reject(ethErrors.provider.userRejectedRequest('MetaMask Message for EncryptionPublicKey: User denied message EncryptionPublicKey.')) + default: + return reject(new Error(`MetaMask Message for EncryptionPublicKey: Unknown problem: ${JSON.stringify(address)}`)) + } + }) + }) + } + + /** + * Creates a new EncryptionPublicKey with an 'unapproved' status using the passed msgParams. this.addMsg is called to add + * the new EncryptionPublicKey to this.messages, and to save the unapproved EncryptionPublicKeys from that list to + * this.memStore. + * + * @param {Object} address The param for the encryption_public_key call to be made after the message is approved. + * @param {Object} _req (optional) The original request object possibly containing the origin + * @returns {number} The id of the newly created EncryptionPublicKey. + * + */ + addUnapprovedMessage (address, _req) { + log.debug(`EncryptionPublicKeyManager addUnapprovedMessage: address`) + // create txData obj with parameters and meta data + const time = (new Date()).getTime() + const msgId = createId() + const msgData = { + id: msgId, + msgParams: address, + time: time, + status: 'unapproved', + type: 'encryption_public_key', + } + this.addMsg(msgData) + + // signal update + this.emit('update') + return msgId + } + + /** + * Adds a passed EncryptionPublicKey to this.messages, and calls this._saveMsgList() to save the unapproved EncryptionPublicKeys from that + * list to this.memStore. + * + * @param {Message} msg The EncryptionPublicKey to add to this.messages + * + */ + addMsg (msg) { + this.messages.push(msg) + this._saveMsgList() + } + + /** + * Returns a specified EncryptionPublicKey. + * + * @param {number} msgId The id of the EncryptionPublicKey to get + * @returns {EncryptionPublicKey|undefined} The EncryptionPublicKey with the id that matches the passed msgId, or undefined + * if no EncryptionPublicKey has that id. + * + */ + getMsg (msgId) { + return this.messages.find(msg => msg.id === msgId) + } + + /** + * Approves a EncryptionPublicKey. Sets the message status via a call to this.setMsgStatusApproved, and returns a promise + * with any the message params modified for proper providing. + * + * @param {Object} msgParams The msgParams to be used when encryption_public_key is called, plus data added by MetaMask. + * @param {Object} msgParams.metamaskId Added to msgParams for tracking and identification within MetaMask. + * @returns {Promise} Promises the msgParams object with metamaskId removed. + * + */ + approveMessage (msgParams) { + this.setMsgStatusApproved(msgParams.metamaskId) + return this.prepMsgForEncryptionPublicKey(msgParams) + } + + /** + * Sets a EncryptionPublicKey status to 'approved' via a call to this._setMsgStatus. + * + * @param {number} msgId The id of the EncryptionPublicKey to approve. + * + */ + setMsgStatusApproved (msgId) { + this._setMsgStatus(msgId, 'approved') + } + + /** + * Sets a EncryptionPublicKey status to 'received' via a call to this._setMsgStatus and updates that EncryptionPublicKey in + * this.messages by adding the raw data of request to the EncryptionPublicKey + * + * @param {number} msgId The id of the EncryptionPublicKey. + * @param {buffer} rawData The raw data of the message request + * + */ + setMsgStatusReceived (msgId, rawData) { + const msg = this.getMsg(msgId) + msg.rawData = rawData + this._updateMsg(msg) + this._setMsgStatus(msgId, 'received') + } + + /** + * Removes the metamaskId property from passed msgParams and returns a promise which resolves the updated msgParams + * + * @param {Object} msgParams The msgParams to modify + * @returns {Promise} Promises the msgParams with the metamaskId property removed + * + */ + prepMsgForEncryptionPublicKey (msgParams) { + delete msgParams.metamaskId + return Promise.resolve(msgParams) + } + + /** + * Sets a EncryptionPublicKey status to 'rejected' via a call to this._setMsgStatus. + * + * @param {number} msgId The id of the EncryptionPublicKey to reject. + * + */ + rejectMsg (msgId) { + this._setMsgStatus(msgId, 'rejected') + } + + /** + * Sets a TypedMessage status to 'errored' via a call to this._setMsgStatus. + * + * @param {number} msgId The id of the TypedMessage to error + * + */ + errorMessage (msgId, error) { + const msg = this.getMsg(msgId) + msg.error = error + this._updateMsg(msg) + this._setMsgStatus(msgId, 'errored') + } + + /** + * Updates the status of a EncryptionPublicKey in this.messages via a call to this._updateMsg + * + * @private + * @param {number} msgId The id of the EncryptionPublicKey to update. + * @param {string} status The new status of the EncryptionPublicKey. + * @throws A 'EncryptionPublicKeyManager - EncryptionPublicKey not found for id: "${msgId}".' if there is no EncryptionPublicKey + * in this.messages with an id equal to the passed msgId + * @fires An event with a name equal to `${msgId}:${status}`. The EncryptionPublicKey is also fired. + * @fires If status is 'rejected' or 'received', an event with a name equal to `${msgId}:finished` is fired along + * with the EncryptionPublicKey + * + */ + _setMsgStatus (msgId, status) { + const msg = this.getMsg(msgId) + if (!msg) { + throw new Error('EncryptionPublicKeyManager - Message not found for id: "${msgId}".') + } + msg.status = status + this._updateMsg(msg) + this.emit(`${msgId}:${status}`, msg) + if (status === 'rejected' || status === 'received') { + this.emit(`${msgId}:finished`, msg) + } + } + + /** + * Sets a EncryptionPublicKey in this.messages to the passed EncryptionPublicKey if the ids are equal. Then saves the + * unapprovedEncryptionPublicKeyMsgs index to storage via this._saveMsgList + * + * @private + * @param {msg} EncryptionPublicKey A EncryptionPublicKey that will replace an existing EncryptionPublicKey (with the same + * id) in this.messages + * + */ + _updateMsg (msg) { + const index = this.messages.findIndex((message) => message.id === msg.id) + if (index !== -1) { + this.messages[index] = msg + } + this._saveMsgList() + } + + /** + * Saves the unapproved EncryptionPublicKeys, and their count, to this.memStore + * + * @private + * @fires 'updateBadge' + * + */ + _saveMsgList () { + const unapprovedEncryptionPublicKeyMsgs = this.getUnapprovedMsgs() + const unapprovedEncryptionPublicKeyMsgCount = Object.keys(unapprovedEncryptionPublicKeyMsgs).length + this.memStore.updateState({ unapprovedEncryptionPublicKeyMsgs, unapprovedEncryptionPublicKeyMsgCount }) + this.emit('updateBadge') + } + + /** + * A helper function that converts raw buffer data to a hex, or just returns the data if it is already formatted as a hex. + * + * @param {any} data The buffer data to convert to a hex + * @returns {string} A hex string conversion of the buffer data + * + */ + normalizeMsgData (data) { + try { + const stripped = ethUtil.stripHexPrefix(data) + if (stripped.match(hexRe)) { + return ethUtil.addHexPrefix(stripped) + } + } catch (e) { + log.debug(`Message was not hex encoded, interpreting as utf8.`) + } + + return ethUtil.bufferToHex(Buffer.from(data, 'utf8')) + } + +} diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 8f3fee4f81f0..22dfc8185a25 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -35,6 +35,8 @@ const RecentBlocksController = require('./controllers/recent-blocks') const IncomingTransactionsController = require('./controllers/incoming-transactions') const MessageManager = require('./lib/message-manager') const PersonalMessageManager = require('./lib/personal-message-manager') +const DecryptMessageManager = require('./lib/decrypt-message-manager') +const EncryptionPublicKeyManager = require('./lib/encryption-public-key-manager') const TypedMessageManager = require('./lib/typed-message-manager') const TransactionController = require('./controllers/transactions') const TokenRatesController = require('./controllers/token-rates') @@ -275,6 +277,8 @@ module.exports = class MetamaskController extends EventEmitter { this.networkController.lookupNetwork() this.messageManager = new MessageManager() this.personalMessageManager = new PersonalMessageManager() + this.decryptMessageManager = new DecryptMessageManager() + this.encryptionPublicKeyManager = new EncryptionPublicKeyManager() this.typedMessageManager = new TypedMessageManager({ networkController: this.networkController }) // ensure isClientOpenAndUnlocked is updated when memState updates @@ -310,6 +314,8 @@ module.exports = class MetamaskController extends EventEmitter { TokenRatesController: this.tokenRatesController.store, MessageManager: this.messageManager.memStore, PersonalMessageManager: this.personalMessageManager.memStore, + DecryptMessageManager: this.decryptMessageManager.memStore, + EncryptionPublicKeyManager: this.encryptionPublicKeyManager.memStore, TypesMessageManager: this.typedMessageManager.memStore, KeyringController: this.keyringController.memStore, PreferencesController: this.preferencesController.store, @@ -360,6 +366,8 @@ module.exports = class MetamaskController extends EventEmitter { processTypedMessageV3: this.newUnsignedTypedMessage.bind(this), processTypedMessageV4: this.newUnsignedTypedMessage.bind(this), processPersonalMessage: this.newUnsignedPersonalMessage.bind(this), + processDecryptMessage: this.newRequestDecryptMessage.bind(this), + processEncryptionPublicKey: this.newRequestEncryptionPublicKey.bind(this), getPendingNonce: this.getPendingNonce.bind(this), getPendingTransactionByHash: (hash) => this.txController.getFilteredTxList({ hash, status: 'submitted' })[0], } @@ -534,6 +542,15 @@ module.exports = class MetamaskController extends EventEmitter { signTypedMessage: nodeify(this.signTypedMessage, this), cancelTypedMessage: this.cancelTypedMessage.bind(this), + // decryptMessageManager + decryptMessage: nodeify(this.decryptMessage, this), + decryptMessageInline: nodeify(this.decryptMessageInline, this), + cancelDecryptMessage: this.cancelDecryptMessage.bind(this), + + // EncryptionPublicKeyManager + encryptionPublicKey: nodeify(this.encryptionPublicKey, this), + cancelEncryptionPublicKey: this.cancelEncryptionPublicKey.bind(this), + // onboarding controller setSeedPhraseBackedUp: nodeify(onboardingController.setSeedPhraseBackedUp, onboardingController), @@ -1146,6 +1163,148 @@ module.exports = class MetamaskController extends EventEmitter { } } + // eth_decryptMessage methods + + /** + * Called when a dapp uses the eth_decryptMessage method. + * + * @param {Object} msgParams - The params of the message to sign & return to the Dapp. + * @param {Function} cb - The callback function called with the signature. + * Passed back to the requesting Dapp. + */ + async newRequestDecryptMessage (msgParams, req) { + const promise = this.decryptMessageManager.addUnapprovedMessageAsync(msgParams, req) + this.sendUpdate() + this.opts.showUnconfirmedMessage() + return promise + } + + /** + * Only decypt message and don't touch transaction state + * + * @param {Object} msgParams - The params of the message to decrypt & return to the Dapp. + * @returns {Promise} - A full state update. + */ + decryptMessageInline (msgParams) { + log.info('MetaMaskController - decryptMessageInline') + const msgId = msgParams.metamaskId + const stripped = ethUtil.stripHexPrefix(msgParams.data) + const buff = Buffer.from(stripped, 'hex') + msgParams.data = JSON.parse(buff.toString('utf8')) + // decrypt the message inline + return this.keyringController.decryptMessage(msgParams).then((rawData) => { + const msg = this.decryptMessageManager.getMsg(msgId) + msg.rawData = rawData + this.decryptMessageManager._updateMsg(msg) + return this.getState() + }) + } + + /** + * Signifies a user's approval to decrypt a message in queue. + * Triggers decrypt, and the callback function from newUnsignedDecryptMessage. + * + * @param {Object} msgParams - The params of the message to decrypt & return to the Dapp. + * @returns {Promise} - A full state update. + */ + decryptMessage (msgParams) { + log.info('MetaMaskController - decryptMessage') + const msgId = msgParams.metamaskId + // sets the status op the message to 'approved' + // and removes the metamaskId for decryption + try { + return this.decryptMessageManager.approveMessage(msgParams) + .then((cleanMsgParams) => { + const stripped = ethUtil.stripHexPrefix(cleanMsgParams.data) + const buff = Buffer.from(stripped, 'hex') + cleanMsgParams.data = JSON.parse(buff.toString('utf8')) + // decrypt the message + return this.keyringController.decryptMessage(cleanMsgParams) + }) + .then((rawMess) => { + // tells the listener that the message has been decrypted + // and can be returned to the dapp + this.decryptMessageManager.setMsgStatusDecrypted(msgId, rawMess) + return this.getState() + }) + } catch (error) { + log.info('MetaMaskController - eth_decryptMessage failed.', error) + this.decryptMessageManager.errorMessage(msgId, error) + } + } + + /** + * Used to cancel a eth_decryptMessage type message. + * @param {string} msgId - The ID of the message to cancel. + * @param {Function} cb - The callback function called with a full state update. + */ + cancelDecryptMessage (msgId, cb) { + const messageManager = this.decryptMessageManager + messageManager.rejectMsg(msgId) + if (cb && typeof cb === 'function') { + cb(null, this.getState()) + } + } + + // encryption_public_key methods + + /** + * Called when a dapp uses the encryption_public_key method. + * + * @param {Object} msgParams - The params of the message to sign & return to the Dapp. + * @param {Function} cb - The callback function called with the signature. + * Passed back to the requesting Dapp. + */ + async newRequestEncryptionPublicKey (msgParams, req) { + const promise = this.encryptionPublicKeyManager.addUnapprovedMessageAsync(msgParams, req) + this.sendUpdate() + this.opts.showUnconfirmedMessage() + return promise + } + + /** + * Signifies a user's approval to receiving encryption public key in queue. + * Triggers receiving, and the callback function from newUnsignedEncryptionPublicKey. + * + * @param {Object} msgParams - The params of the message to receive & return to the Dapp. + * @returns {Promise} - A full state update. + */ + encryptionPublicKey (msgParams) { + log.info('MetaMaskController - encryptionPublicKey') + const msgId = msgParams.metamaskId + // sets the status op the message to 'approved' + // and removes the metamaskId for decryption + try { + return this.encryptionPublicKeyManager.approveMessage(msgParams) + .then((params) => { + // EncryptionPublicKey message + return this.keyringController.getEncryptionPublicKey(params.data) + }) + .then((publicKey) => { + // tells the listener that the message has been processed + // and can be returned to the dapp + this.encryptionPublicKeyManager.setMsgStatusReceived(msgId, publicKey) + return this.getState() + }) + } catch (error) { + log.info('MetaMaskController - encryption_public_key failed.', error) + this.encryptionPublicKeyManager.errorMessage(msgId, error) + } + } + + /** + * Used to cancel a encryption_public_key type message. + * @param {string} msgId - The ID of the message to cancel. + * @param {Function} cb - The callback function called with a full state update. + */ + cancelEncryptionPublicKey (msgId, cb) { + const messageManager = this.encryptionPublicKeyManager + messageManager.rejectMsg(msgId) + if (cb && typeof cb === 'function') { + cb(null, this.getState()) + } + } + // eth_signTypedData methods /** diff --git a/package.json b/package.json index adc34119ea7d..3de6a1a91dc7 100644 --- a/package.json +++ b/package.json @@ -92,10 +92,10 @@ "eth-contract-metadata": "^1.11.0", "eth-ens-namehash": "^2.0.8", "eth-json-rpc-errors": "^2.0.0", - "eth-json-rpc-filters": "^4.1.1", - "eth-json-rpc-infura": "^4.0.1", - "eth-json-rpc-middleware": "^4.2.0", - "eth-keyring-controller": "^5.3.0", + "eth-json-rpc-filters": "https://github.com/logvik/eth-json-rpc-filters", + "eth-json-rpc-infura": "https://github.com/logvik/eth-json-rpc-infura", + "eth-json-rpc-middleware": "https://github.com/MetaMask/eth-json-rpc-middleware", + "eth-keyring-controller": "https://github.com/logvik/KeyringController", "eth-ledger-bridge-keyring": "^0.2.0", "eth-method-registry": "^1.2.0", "eth-phishing-detect": "^1.1.4", @@ -117,7 +117,7 @@ "fast-deep-equal": "^2.0.1", "fast-json-patch": "^2.0.4", "fuse.js": "^3.2.0", - "gaba": "^1.9.0", + "gaba": "^1.9.1", "human-standard-token-abi": "^2.0.0", "jazzicon": "^1.2.0", "json-rpc-engine": "^5.1.5", @@ -214,7 +214,7 @@ "css-loader": "^2.1.1", "del": "^3.0.0", "deps-dump": "^1.1.0", - "envify": "^4.0.0", + "envify": "^4.1.0", "enzyme": "^3.10.0", "enzyme-adapter-react-16": "^1.15.1", "eslint": "^6.0.1", @@ -231,7 +231,7 @@ "ganache-core": "2.8.0", "geckodriver": "^1.16.2", "gh-pages": "^1.2.0", - "gulp": "^4.0.0", + "gulp": "^4.0.2", "gulp-autoprefixer": "^5.0.0", "gulp-babel": "^7.0.0", "gulp-debug": "^3.2.0", diff --git a/test/data/2-state.json b/test/data/2-state.json index 9d6dc9af524b..e7b49c0e4818 100644 --- a/test/data/2-state.json +++ b/test/data/2-state.json @@ -18,6 +18,8 @@ "unapprovedMsgCount": 0, "unapprovedPersonalMsgs": {}, "unapprovedPersonalMsgCount": 0, + "unapprovedDecryptMsgs": 0, + "unapprovedDecryptMsgCount": 0, "unapprovedTypedMessages": {}, "unapprovedTypedMessagesCount": 0, "isUnlocked": true, diff --git a/test/data/mock-state.json b/test/data/mock-state.json index 2db918522e8b..f5944b1851b7 100644 --- a/test/data/mock-state.json +++ b/test/data/mock-state.json @@ -136,6 +136,8 @@ "unapprovedMsgCount": 0, "unapprovedPersonalMsgs": {}, "unapprovedPersonalMsgCount": 0, + "unapprovedDecryptMsgs": {}, + "unapprovedDecryptMsgCount": 0, "unapprovedTypedMessages": {}, "unapprovedTypedMessagesCount": 0, "send": { diff --git a/ui/app/css/itcss/components/index.scss b/ui/app/css/itcss/components/index.scss index 01c913a1a1f0..c8cf1d903422 100644 --- a/ui/app/css/itcss/components/index.scss +++ b/ui/app/css/itcss/components/index.scss @@ -42,6 +42,10 @@ @import './request-signature.scss'; +@import './request-encryption-public-key.scss'; + +@import './request-decrypt-message.scss'; + @import './account-details-dropdown.scss'; @import './editable-label.scss'; diff --git a/ui/app/css/itcss/components/request-decrypt-message.scss b/ui/app/css/itcss/components/request-decrypt-message.scss new file mode 100644 index 000000000000..7b92ffd6e54d --- /dev/null +++ b/ui/app/css/itcss/components/request-decrypt-message.scss @@ -0,0 +1,292 @@ +.request-decrypt-message { + &__container { + width: 380px; + border-radius: 8px; + background-color: $white; + box-shadow: 0 2px 4px 0 rgba(0,0,0,0.08); + display: flex; + flex-flow: column nowrap; + z-index: 25; + align-items: center; + font-family: Roboto; + position: relative; + height: 100%; + + @media screen and (max-width: $break-small) { + width: 100%; + top: 0; + box-shadow: none; + } + + @media screen and (min-width: $break-large) { + height: 620px; + } + } + + &__typed-container { + padding: 17px; + + h1 { + font-weight: 900; + margin-bottom: 5px; + } + + * { + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + } + + > div { + margin-bottom: 10px; + } + } + + &__header { + height: 64px; + width: 100%; + position: relative; + display: flex; + flex-flow: column; + justify-content: center; + align-items: center; + flex: 0 0 auto; + } + + &__header-background { + position: absolute; + background-color: $athens-grey; + z-index: 2; + width: 100%; + height: 100%; + } + + &__header__text { + color: #5B5D67; + font-family: Roboto; + font-size: 22px; + line-height: 29px; + z-index: 3; + text-align: center; + } + + &__header__tip-container { + width: 100%; + display: flex; + justify-content: center; + } + + &__header__tip { + height: 25px; + width: 25px; + background: $athens-grey; + transform: rotate(45deg); + position: absolute; + bottom: -8px; + z-index: 1; + } + + &__account-info { + display: flex; + justify-content: space-between; + margin-top: 18px; + margin-bottom: 20px; + } + + &__account { + color: $dusty-gray; + margin-left: 17px; + } + + &__account-text { + font-size: 14px; + } + + &__account-item { + height: 22px; + background-color: $white; + font-family: Roboto; + line-height: 16px; + font-size: 12px; + width: 124px; + + .account-list-item { + margin-top: 6px; + } + + .account-list-item__account-name { + text-overflow: ellipsis; + overflow: hidden; + white-space: nowrap; + width: 80px; + } + + .account-list-item__top-row { + margin: 0; + } + } + + &__balance { + color: $dusty-gray; + margin-right: 17px; + width: 124px; + } + + &__balance-text { + text-align: right; + font-size: 14px; + } + + &__balance-value { + text-align: right; + margin-top: 2.5px; + } + + &__request-icon { + margin-top: 25px; + } + + &__body { + width: 100%; + height: 100%; + display: flex; + flex-flow: column; + flex: 1 1 auto; + height: 0; + } + + &__notice { + font-family: "Avenir Next"; + font-size: 14px; + line-height: 19px; + text-align: center; + margin-top: 15px; + margin-bottom: 11px; + width: 100%; + } + + &__message { + overflow-wrap: break-word; + margin: 20px; + overflow: hidden; + border: 1px solid #dedede; + padding: 5px; + border-radius: 5px; + position: relative; + + &-text { + font-size: 0.7em; + height: 115px; + } + + &-cover { + background-color: white; + opacity: 0.75; + position: absolute; + height: 100%; + width: 100%; + top: 0px; + } + + &-lock { + position: absolute; + height: 100%; + width: 100%; + top: 0px; + cursor: pointer; + img { + padding: 5px; + background-color: #fff; + left: calc(50% - 24px); + position: absolute; + top: calc(50% - 34px); + border-radius: 3px; + } + + &--pressed { + display: none; + } + } + + &-lock-text { + width: 200px; + font-size: 0.75em; + position: absolute; + top: calc(50% + 5px); + text-align: center; + left: calc(50% - 100px); + background-color: white; + line-height: 1em; + border-radius: 3px; + } + + &-copy { + font-size: 0.75em; + margin-left: 20px; + margin-right: 20px; + display: flex; + cursor: pointer; + } + + &-copy-text { + margin-right: 10px; + display: inline; + } + + &-copy-tooltip { + float: right; + } + } + + &__footer { + width: 100%; + display: flex; + align-items: center; + justify-content: center; + font-size: 22px; + position: relative; + flex: 0 0 auto; + border-top: 1px solid $geyser; + padding: 1.6rem; + + button { + width: 165px; + } + + &__cancel-button { + margin-right: 1.2rem; + } + } + + &__visual { + display: flex; + flex-direction: row; + justify-content: space-evenly; + position: relative; + margin: 0 20px; + + section { + display: flex; + flex-direction: column; + align-items: center; + flex: 1; + } + + &-identicon { + width: 48px; + height: 48px; + + &--default { + background-color: #777A87; + color: white; + width: 48px; + height: 48px; + border-radius: 24px; + display: flex; + align-items: center; + justify-content: center; + font-weight: bold; + } + } + } +} diff --git a/ui/app/css/itcss/components/request-encryption-public-key.scss b/ui/app/css/itcss/components/request-encryption-public-key.scss new file mode 100644 index 000000000000..f407037b4f99 --- /dev/null +++ b/ui/app/css/itcss/components/request-encryption-public-key.scss @@ -0,0 +1,190 @@ +.request-encryption-public-key { + &__container { + width: 380px; + border-radius: 8px; + background-color: $white; + box-shadow: 0 2px 4px 0 rgba(0,0,0,0.08); + display: flex; + flex-flow: column nowrap; + z-index: 25; + align-items: center; + font-family: Roboto; + position: relative; + height: 100%; + + @media screen and (max-width: $break-small) { + width: 100%; + top: 0; + box-shadow: none; + } + + @media screen and (min-width: $break-large) { + height: 620px; + } + } + + &__typed-container { + padding: 17px; + + h1 { + font-weight: 900; + margin-bottom: 5px; + } + + * { + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + } + + > div { + margin-bottom: 10px; + } + } + + &__header { + height: 64px; + width: 100%; + position: relative; + display: flex; + flex-flow: column; + justify-content: center; + align-items: center; + flex: 0 0 auto; + } + + &__header-background { + position: absolute; + background-color: $athens-grey; + z-index: 2; + width: 100%; + height: 100%; + } + + &__header__text { + color: #5B5D67; + font-family: Roboto; + font-size: 22px; + line-height: 29px; + z-index: 3; + text-align: center; + } + + &__header__tip-container { + width: 100%; + display: flex; + justify-content: center; + } + + &__header__tip { + height: 25px; + width: 25px; + background: $athens-grey; + transform: rotate(45deg); + position: absolute; + bottom: -8px; + z-index: 1; + } + + &__account-info { + display: flex; + justify-content: space-between; + margin-top: 18px; + margin-bottom: 20px; + } + + &__account { + color: $dusty-gray; + margin-left: 17px; + } + + &__account-text { + font-size: 14px; + } + + &__account-item { + height: 22px; + background-color: $white; + font-family: Roboto; + line-height: 16px; + font-size: 12px; + width: 124px; + + .account-list-item { + margin-top: 6px; + } + + .account-list-item__account-name { + text-overflow: ellipsis; + overflow: hidden; + white-space: nowrap; + width: 80px; + } + + .account-list-item__top-row { + margin: 0; + } + } + + &__balance { + color: $dusty-gray; + margin-right: 17px; + width: 124px; + } + + &__balance-text { + text-align: right; + font-size: 14px; + } + + &__balance-value { + text-align: right; + margin-top: 2.5px; + } + + &__request-icon { + margin-top: 25px; + } + + &__body { + width: 100%; + height: 100%; + display: flex; + flex-flow: column; + flex: 1 1 auto; + height: 0; + } + + &__notice { + font-family: "Avenir Next"; + font-size: 14px; + line-height: 19px; + text-align: center; + margin-top: 41px; + margin-bottom: 11px; + width: 100%; + padding-left: 20px; + padding-right: 20px; + color: $dusty-gray; + } + + &__footer { + width: 100%; + display: flex; + align-items: center; + justify-content: center; + font-size: 22px; + position: relative; + flex: 0 0 auto; + border-top: 1px solid $geyser; + padding: 1.6rem; + + button { + width: 165px; + } + + &__cancel-button { + margin-right: 1.2rem; + } + } +} diff --git a/ui/app/ducks/app/app.js b/ui/app/ducks/app/app.js index 9cd3915020cc..7fdd8d706891 100644 --- a/ui/app/ducks/app/app.js +++ b/ui/app/ducks/app/app.js @@ -531,9 +531,9 @@ function checkUnconfActions (state) { function getUnconfActionList (state) { const { unapprovedTxs, unapprovedMsgs, - unapprovedPersonalMsgs, unapprovedTypedMessages, network } = state.metamask + unapprovedPersonalMsgs, unapprovedDecryptMsgs, unapprovedEncryptionPublicKeyMsgs, unapprovedTypedMessages, network } = state.metamask - const unconfActionList = txHelper(unapprovedTxs, unapprovedMsgs, unapprovedPersonalMsgs, unapprovedTypedMessages, network) + const unconfActionList = txHelper(unapprovedTxs, unapprovedMsgs, unapprovedPersonalMsgs, unapprovedDecryptMsgs, unapprovedEncryptionPublicKeyMsgs, unapprovedTypedMessages, network) return unconfActionList } diff --git a/ui/app/helpers/constants/routes.js b/ui/app/helpers/constants/routes.js index 4a654bb4e5ce..d233b284f6ef 100644 --- a/ui/app/helpers/constants/routes.js +++ b/ui/app/helpers/constants/routes.js @@ -48,6 +48,8 @@ const CONFIRM_APPROVE_PATH = '/approve' const CONFIRM_TRANSFER_FROM_PATH = '/transfer-from' const CONFIRM_TOKEN_METHOD_PATH = '/token-method' const SIGNATURE_REQUEST_PATH = '/signature-request' +const DECRYPT_MESSAGE_REQUEST_PATH = '/decrypt-message-request' +const ENCRYPTION_PUBLIC_KEY_REQUEST_PATH = '/encryption-public-key-request' module.exports = { DEFAULT_ROUTE, @@ -81,6 +83,8 @@ module.exports = { CONFIRM_TRANSFER_FROM_PATH, CONFIRM_TOKEN_METHOD_PATH, SIGNATURE_REQUEST_PATH, + DECRYPT_MESSAGE_REQUEST_PATH, + ENCRYPTION_PUBLIC_KEY_REQUEST_PATH, INITIALIZE_METAMETRICS_OPT_IN_ROUTE, ADVANCED_ROUTE, SECURITY_ROUTE, diff --git a/ui/app/helpers/constants/transactions.js b/ui/app/helpers/constants/transactions.js index e91e56ddc4ca..e7e4c7fb26d2 100644 --- a/ui/app/helpers/constants/transactions.js +++ b/ui/app/helpers/constants/transactions.js @@ -18,6 +18,8 @@ export const APPROVE_ACTION_KEY = 'approve' export const SEND_TOKEN_ACTION_KEY = 'sentTokens' export const TRANSFER_FROM_ACTION_KEY = 'transferFrom' export const SIGNATURE_REQUEST_KEY = 'signatureRequest' +export const DECRYPT_REQUEST_KEY = 'decryptRequest' +export const ENCRYPTION_PUBLIC_KEY_REQUEST_KEY = 'encryptionPublicKeyRequest' export const CONTRACT_INTERACTION_KEY = 'contractInteraction' export const CANCEL_ATTEMPT_ACTION_KEY = 'cancelAttempt' export const DEPOSIT_TRANSACTION_KEY = 'deposit' diff --git a/ui/app/helpers/utils/transactions.util.js b/ui/app/helpers/utils/transactions.util.js index 1f8c6e952a50..201f4944e211 100644 --- a/ui/app/helpers/utils/transactions.util.js +++ b/ui/app/helpers/utils/transactions.util.js @@ -19,6 +19,8 @@ import { SEND_TOKEN_ACTION_KEY, TRANSFER_FROM_ACTION_KEY, SIGNATURE_REQUEST_KEY, + DECRYPT_REQUEST_KEY, + ENCRYPTION_PUBLIC_KEY_REQUEST_KEY, CONTRACT_INTERACTION_KEY, CANCEL_ATTEMPT_ACTION_KEY, DEPOSIT_TRANSACTION_KEY, @@ -132,7 +134,13 @@ export function getTransactionActionKey (transaction) { } if (msgParams) { - return SIGNATURE_REQUEST_KEY + if (type === 'eth_decryptMessage') { + return DECRYPT_REQUEST_KEY + } else if (type === 'encryption_public_key') { + return ENCRYPTION_PUBLIC_KEY_REQUEST_KEY + } else { + return SIGNATURE_REQUEST_KEY + } } if (isConfirmDeployContract(transaction)) { diff --git a/ui/app/pages/confirm-decrypt-message/confirm-decrypt-message.component.js b/ui/app/pages/confirm-decrypt-message/confirm-decrypt-message.component.js new file mode 100644 index 000000000000..35d56d7a2962 --- /dev/null +++ b/ui/app/pages/confirm-decrypt-message/confirm-decrypt-message.component.js @@ -0,0 +1,324 @@ +import React, { Component } from 'react' +import PropTypes from 'prop-types' +import Tooltip from '../../components/ui/tooltip-v2' +import copyToClipboard from 'copy-to-clipboard' +import classnames from 'classnames' + +import { ENVIRONMENT_TYPE_NOTIFICATION } from '../../../../app/scripts/lib/enums' +import { getEnvironmentType } from '../../../../app/scripts/lib/util' +import Identicon from '../../components/ui/identicon' +import AccountListItem from '../../pages/send/account-list-item/account-list-item.component' +import { conversionUtil } from '../../helpers/utils/conversion-util' +import Button from '../../components/ui/button' +import { DEFAULT_ROUTE } from '../../helpers/constants/routes' + +export default class ConfirmDecryptMessage extends Component { + static contextTypes = { + t: PropTypes.func.isRequired, + metricsEvent: PropTypes.func.isRequired, + } + + static propTypes = { + balance: PropTypes.string, + clearConfirmTransaction: PropTypes.func.isRequired, + cancelDecryptMessage: PropTypes.func.isRequired, + decryptMessage: PropTypes.func.isRequired, + decryptMessageInline: PropTypes.func.isRequired, + conversionRate: PropTypes.number, + history: PropTypes.object.isRequired, + requesterAddress: PropTypes.string, + selectedAccount: PropTypes.object, + txData: PropTypes.object, + approvedOrigins: PropTypes.object, + } + + state = { + selectedAccount: this.props.selectedAccount, + hasCopied: false, + copyToClipboardPressed: false, + } + + componentDidMount = () => { + if (getEnvironmentType(window.location.href) === ENVIRONMENT_TYPE_NOTIFICATION) { + window.addEventListener('beforeunload', this._beforeUnload) + } + } + + componentWillUnmount = () => { + this._removeBeforeUnload() + } + + _beforeUnload = (event) => { + const { clearConfirmTransaction, cancelDecryptMessage } = this.props + const { metricsEvent } = this.context + metricsEvent({ + eventOpts: { + category: 'Transactions', + action: 'Decrypt Message Request', + name: 'Cancel Decrypt Message Request Via Notification Close', + }, + }) + clearConfirmTransaction() + cancelDecryptMessage(event) + } + + _removeBeforeUnload = () => { + if (getEnvironmentType(window.location.href) === ENVIRONMENT_TYPE_NOTIFICATION) { + window.removeEventListener('beforeunload', this._beforeUnload) + } + } + + copyMessage = () => { + copyToClipboard(this.state.rawMessage) + this.context.metricsEvent({ + eventOpts: { + category: 'Transactions', + action: 'Decrypt Message Copy', + name: 'Copy', + }, + }) + this.setState({ hasCopied: true }) + setTimeout(() => this.setState({ hasCopied: false }), 3000) + } + + renderHeader = () => { + return ( +
+
+ +
+ { this.context.t('decryptRequest') } +
+ +
+
+
+
+ ) + } + + renderAccount = () => { + const { selectedAccount } = this.state + + return ( +
+
+ { `${this.context.t('account')}:` } +
+ +
+ +
+
+ ) + } + + renderBalance = () => { + const { balance, conversionRate } = this.props + + const balanceInEther = conversionUtil(balance, { + fromNumericBase: 'hex', + toNumericBase: 'dec', + fromDenomination: 'WEI', + numberOfDecimals: 6, + conversionRate, + }) + + return ( +
+
+ { `${this.context.t('balance')}:` } +
+
+ { `${balanceInEther} ETH` } +
+
+ ) + } + + renderRequestIcon = () => { + const { requesterAddress } = this.props + + return ( +
+ +
+ ) + } + + renderAccountInfo = () => { + return ( +
+ { this.renderAccount() } + { this.renderRequestIcon() } + { this.renderBalance() } +
+ ) + } + + renderBody = () => { + const { txData } = this.props + + const origin = this.props.domainMetadata[txData.msgParams.origin] + const notice = this.context.t('decryptMessageNotice', ['[' + origin.name + ']']) + + const { + hasCopied, + hasDecrypted, + rawMessage, + copyToClipboardPressed, + } = this.state + + return ( +
+ { this.renderAccountInfo() } +
+
+ {origin.icon ? ( + + ) : ( + + {origin.name.charAt(0).toUpperCase()} + + )} +
+ { notice } +
+
+
+
+
+ { !hasDecrypted ? txData.msgParams.data : rawMessage } +
+
+
+
{ + this.props.decryptMessageInline(txData, event).then((result, err) => { + if (!err) { + this.setState({ hasDecrypted: true, rawMessage: result.rawData}) + } else { + this.setState({ hasDecrypted: true, rawMessage: err}) + } + }) + }} + > + +
+ {this.context.t('decryptMetamask')} +
+
+
+
this.copyMessage()} + onMouseDown={() => this.setState({ copyToClipboardPressed: true })} + onMouseUp={() => this.setState({ copyToClipboardPressed: false })} + > + +
+ {this.context.t('decryptCopy')} +
+ +
+
+
+ ) + } + + renderFooter = () => { + const { txData } = this.props + + return ( +
+ + +
+ ) + } + + render = () => { + return ( +
+ { this.renderHeader() } + { this.renderBody() } + { this.renderFooter() } +
+ ) + } +} diff --git a/ui/app/pages/confirm-decrypt-message/confirm-decrypt-message.container.js b/ui/app/pages/confirm-decrypt-message/confirm-decrypt-message.container.js new file mode 100644 index 000000000000..5135025544e5 --- /dev/null +++ b/ui/app/pages/confirm-decrypt-message/confirm-decrypt-message.container.js @@ -0,0 +1,70 @@ +import { connect } from 'react-redux' +import { compose } from 'recompose' +import { withRouter } from 'react-router-dom' +const actions = require('../../store/actions') + +import { + getSelectedAccount, + getCurrentAccountWithSendEtherInfo, + getSelectedAddress, + conversionRateSelector, +} from '../../selectors/selectors.js' +import { clearConfirmTransaction } from '../../ducks/confirm-transaction/confirm-transaction.duck' +import ConfirmDecryptMessage from './confirm-decrypt-message.component' + +function mapStateToProps (state) { + const { confirmTransaction, + metamask: { domainMetadata = {} }, + } = state + + const { + txData = {}, + } = confirmTransaction + + return { + txData: txData, + domainMetadata: domainMetadata, + balance: getSelectedAccount(state).balance, + selectedAccount: getCurrentAccountWithSendEtherInfo(state), + selectedAddress: getSelectedAddress(state), + requester: null, + requesterAddress: null, + conversionRate: conversionRateSelector(state), + } +} + +function mapDispatchToProps (dispatch) { + return { + goHome: () => dispatch(actions.goHome()), + clearConfirmTransaction: () => dispatch(clearConfirmTransaction()), + decryptMessage: (msgData, event) => { + const params = msgData.msgParams + params.metamaskId = msgData.id + event.stopPropagation(event) + return dispatch(actions.decryptMsg(params)) + }, + cancelDecryptMessage: (msgData, event) => { + event.stopPropagation(event) + return dispatch(actions.cancelDecryptMsg(msgData)) + }, + decryptMessageInline: (msgData, event) => { + const params = msgData.msgParams + params.metamaskId = msgData.id + event.stopPropagation(event) + return dispatch(actions.decryptMsgInline(params)) + }, + } +} + +function mergeProps (stateProps, dispatchProps, ownProps) { + return { + ...ownProps, + ...stateProps, + ...dispatchProps, + } +} + +export default compose( + withRouter, + connect(mapStateToProps, mapDispatchToProps, mergeProps) +)(ConfirmDecryptMessage) diff --git a/ui/app/pages/confirm-decrypt-message/index.js b/ui/app/pages/confirm-decrypt-message/index.js new file mode 100644 index 000000000000..e7d072d2fd90 --- /dev/null +++ b/ui/app/pages/confirm-decrypt-message/index.js @@ -0,0 +1,2 @@ +export { default } from './confirm-decrypt-message.container' +export { default as ConfirmDecryptMessage } from './confirm-decrypt-message.component' diff --git a/ui/app/pages/confirm-encryption-public-key/confirm-encryption-public-key.component.js b/ui/app/pages/confirm-encryption-public-key/confirm-encryption-public-key.component.js new file mode 100644 index 000000000000..9947733cda39 --- /dev/null +++ b/ui/app/pages/confirm-encryption-public-key/confirm-encryption-public-key.component.js @@ -0,0 +1,218 @@ +import React, { Component } from 'react' +import PropTypes from 'prop-types' + +import { ENVIRONMENT_TYPE_NOTIFICATION } from '../../../../app/scripts/lib/enums' +import { getEnvironmentType } from '../../../../app/scripts/lib/util' +import Identicon from '../../components/ui/identicon' +import AccountListItem from '../../pages/send/account-list-item/account-list-item.component' +import { conversionUtil } from '../../helpers/utils/conversion-util' +import Button from '../../components/ui/button' +import { DEFAULT_ROUTE } from '../../helpers/constants/routes' + +export default class ConfirmEncryptionPublicKey extends Component { + static contextTypes = { + t: PropTypes.func.isRequired, + metricsEvent: PropTypes.func.isRequired, + } + + static propTypes = { + balance: PropTypes.string, + clearConfirmTransaction: PropTypes.func.isRequired, + cancelEncryptionPublicKey: PropTypes.func.isRequired, + encryptionPublicKey: PropTypes.func.isRequired, + conversionRate: PropTypes.number, + history: PropTypes.object.isRequired, + requesterAddress: PropTypes.string, + selectedAccount: PropTypes.object, + txData: PropTypes.object, + } + + state = { + selectedAccount: this.props.selectedAccount, + } + + componentDidMount = () => { + if (getEnvironmentType(window.location.href) === ENVIRONMENT_TYPE_NOTIFICATION) { + window.addEventListener('beforeunload', this._beforeUnload) + } + } + + componentWillUnmount = () => { + this._removeBeforeUnload() + } + + _beforeUnload = (event) => { + const { clearConfirmTransaction, cancelEncryptionPublicKey } = this.props + const { metricsEvent } = this.context + metricsEvent({ + eventOpts: { + category: 'Transactions', + action: 'Encryption public key Request', + name: 'Cancel Encryption public key Request Via Notification Close', + }, + }) + clearConfirmTransaction() + cancelEncryptionPublicKey(event) + } + + _removeBeforeUnload = () => { + if (getEnvironmentType(window.location.href) === ENVIRONMENT_TYPE_NOTIFICATION) { + window.removeEventListener('beforeunload', this._beforeUnload) + } + } + + renderHeader = () => { + return ( +
+
+ +
+ { this.context.t('encryptionPublicKeyRequest') } +
+ +
+
+
+
+ ) + } + + renderAccount = () => { + const { selectedAccount } = this.state + + return ( +
+
+ { `${this.context.t('account')}:` } +
+ +
+ +
+
+ ) + } + + renderBalance = () => { + const { balance, conversionRate } = this.props + + const balanceInEther = conversionUtil(balance, { + fromNumericBase: 'hex', + toNumericBase: 'dec', + fromDenomination: 'WEI', + numberOfDecimals: 6, + conversionRate, + }) + + return ( +
+
+ { `${this.context.t('balance')}:` } +
+
+ { `${balanceInEther} ETH` } +
+
+ ) + } + + renderRequestIcon = () => { + const { requesterAddress } = this.props + + return ( +
+ +
+ ) + } + + renderAccountInfo = () => { + return ( +
+ { this.renderAccount() } + { this.renderRequestIcon() } + { this.renderBalance() } +
+ ) + } + + renderBody = () => { + const notice = this.context.t('ecryptionPublickKeyNotice') + + return ( +
+ { this.renderAccountInfo() } +
+ { notice } +
+
+ ) + } + + renderFooter = () => { + const { txData } = this.props + + return ( +
+ + +
+ ) + } + + render = () => { + return ( +
+ { this.renderHeader() } + { this.renderBody() } + { this.renderFooter() } +
+ ) + } +} diff --git a/ui/app/pages/confirm-encryption-public-key/confirm-encryption-public-key.container.js b/ui/app/pages/confirm-encryption-public-key/confirm-encryption-public-key.container.js new file mode 100644 index 000000000000..11a7ca8959e1 --- /dev/null +++ b/ui/app/pages/confirm-encryption-public-key/confirm-encryption-public-key.container.js @@ -0,0 +1,59 @@ +import { connect } from 'react-redux' +import { compose } from 'recompose' +import { withRouter } from 'react-router-dom' +const actions = require('../../store/actions') + +import { + getSelectedAccount, + getCurrentAccountWithSendEtherInfo, + getSelectedAddress, + conversionRateSelector, +} from '../../selectors/selectors.js' +import { clearConfirmTransaction } from '../../ducks/confirm-transaction/confirm-transaction.duck' +import ConfirmEncryptionPublicKey from './confirm-encryption-public-key.component' + +function mapStateToProps (state) { + const { confirmTransaction } = state + const { + txData = {}, + } = confirmTransaction + + return { + txData: txData, + balance: getSelectedAccount(state).balance, + selectedAccount: getCurrentAccountWithSendEtherInfo(state), + selectedAddress: getSelectedAddress(state), + requester: null, + requesterAddress: null, + conversionRate: conversionRateSelector(state), + } +} + +function mapDispatchToProps (dispatch) { + return { + goHome: () => dispatch(actions.goHome()), + clearConfirmTransaction: () => dispatch(clearConfirmTransaction()), + encryptionPublicKey: (msgData, event) => { + const params = { data: msgData.msgParams, metamaskId: msgData.id} + event.stopPropagation() + return dispatch(actions.encryptionPublicKeyMsg(params)) + }, + cancelEncryptionPublicKey: (msgData, event) => { + event.stopPropagation() + return dispatch(actions.cancelEncryptionPublicKeyMsg(msgData)) + }, + } +} + +function mergeProps (stateProps, dispatchProps, ownProps) { + return { + ...ownProps, + ...stateProps, + ...dispatchProps, + } +} + +export default compose( + withRouter, + connect(mapStateToProps, mapDispatchToProps, mergeProps) +)(ConfirmEncryptionPublicKey) diff --git a/ui/app/pages/confirm-encryption-public-key/index.js b/ui/app/pages/confirm-encryption-public-key/index.js new file mode 100644 index 000000000000..2975fc1df2e4 --- /dev/null +++ b/ui/app/pages/confirm-encryption-public-key/index.js @@ -0,0 +1,2 @@ +export { default } from './confirm-encryption-public-key.container' +export { default as ConfirmEncryptionPublicKey } from './confirm-encryption-public-key.component' diff --git a/ui/app/pages/confirm-transaction-switch/confirm-transaction-switch.component.js b/ui/app/pages/confirm-transaction-switch/confirm-transaction-switch.component.js index 268751643be5..9cd329604bc2 100644 --- a/ui/app/pages/confirm-transaction-switch/confirm-transaction-switch.component.js +++ b/ui/app/pages/confirm-transaction-switch/confirm-transaction-switch.component.js @@ -11,6 +11,8 @@ import { CONFIRM_TRANSFER_FROM_PATH, CONFIRM_TOKEN_METHOD_PATH, SIGNATURE_REQUEST_PATH, + DECRYPT_MESSAGE_REQUEST_PATH, + ENCRYPTION_PUBLIC_KEY_REQUEST_PATH, } from '../../helpers/constants/routes' import { TOKEN_METHOD_TRANSFER, @@ -68,11 +70,15 @@ export default class ConfirmTransactionSwitch extends Component { render () { const { txData } = this.props - if (txData.txParams) { return this.redirectToTransaction() } else if (txData.msgParams) { - const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${txData.id}${SIGNATURE_REQUEST_PATH}` + let pathname = `${CONFIRM_TRANSACTION_ROUTE}/${txData.id}${SIGNATURE_REQUEST_PATH}` + if (txData.type === 'eth_decryptMessage') { + pathname = `${CONFIRM_TRANSACTION_ROUTE}/${txData.id}${DECRYPT_MESSAGE_REQUEST_PATH}` + } else if (txData.type === 'encryption_public_key') { + pathname = `${CONFIRM_TRANSACTION_ROUTE}/${txData.id}${ENCRYPTION_PUBLIC_KEY_REQUEST_PATH}` + } return } diff --git a/ui/app/pages/confirm-transaction/confirm-transaction.component.js b/ui/app/pages/confirm-transaction/confirm-transaction.component.js index ed25258f48d3..c174bb2d5168 100644 --- a/ui/app/pages/confirm-transaction/confirm-transaction.component.js +++ b/ui/app/pages/confirm-transaction/confirm-transaction.component.js @@ -10,6 +10,9 @@ import ConfirmDeployContract from '../confirm-deploy-contract' import ConfirmApprove from '../confirm-approve' import ConfirmTokenTransactionBase from '../confirm-token-transaction-base' import ConfTx from './conf-tx' +import ConfinmDecryptMessage from '../confirm-decrypt-message' +import ConfirmEncryptionPublicKey from '../confirm-encryption-public-key' + import { DEFAULT_ROUTE, CONFIRM_TRANSACTION_ROUTE, @@ -20,6 +23,8 @@ import { CONFIRM_TRANSFER_FROM_PATH, CONFIRM_TOKEN_METHOD_PATH, SIGNATURE_REQUEST_PATH, + DECRYPT_MESSAGE_REQUEST_PATH, + ENCRYPTION_PUBLIC_KEY_REQUEST_PATH, } from '../../helpers/constants/routes' export default class ConfirmTransaction extends Component { @@ -155,6 +160,16 @@ export default class ConfirmTransaction extends Component { path={`${CONFIRM_TRANSACTION_ROUTE}/:id?${SIGNATURE_REQUEST_PATH}`} component={ConfTx} /> + + ) diff --git a/ui/app/pages/send/tests/send-selectors-test-data.js b/ui/app/pages/send/tests/send-selectors-test-data.js index 91b96dd98e7c..25bad228eff3 100644 --- a/ui/app/pages/send/tests/send-selectors-test-data.js +++ b/ui/app/pages/send/tests/send-selectors-test-data.js @@ -130,6 +130,10 @@ module.exports = { 'unapprovedMsgCount': 0, 'unapprovedPersonalMsgs': {}, 'unapprovedPersonalMsgCount': 0, + 'unapprovedDecryptMsgs': {}, + 'unapprovedDecryptMsgCount': 0, + 'unapprovedEncryptionPublicKeyMsgs': {}, + 'unapprovedEncryptionPublicKeyMsgCount': 0, 'keyringTypes': [ 'Simple Key Pair', 'HD Key Tree', diff --git a/ui/app/selectors/confirm-transaction.js b/ui/app/selectors/confirm-transaction.js index 82df4e776999..a23541106c92 100644 --- a/ui/app/selectors/confirm-transaction.js +++ b/ui/app/selectors/confirm-transaction.js @@ -16,6 +16,8 @@ import { const unapprovedTxsSelector = state => state.metamask.unapprovedTxs const unapprovedMsgsSelector = state => state.metamask.unapprovedMsgs const unapprovedPersonalMsgsSelector = state => state.metamask.unapprovedPersonalMsgs +const unapprovedDecryptMsgsSelector = state => state.metamask.unapprovedDecryptMsgs +const unapprovedEncryptionPublicKeyMsgsSelector = state => state.metamask.unapprovedEncryptionPublicKeyMsgs const unapprovedTypedMessagesSelector = state => state.metamask.unapprovedTypedMessages const networkSelector = state => state.metamask.network @@ -23,18 +25,22 @@ export const unconfirmedTransactionsListSelector = createSelector( unapprovedTxsSelector, unapprovedMsgsSelector, unapprovedPersonalMsgsSelector, + unapprovedDecryptMsgsSelector, + unapprovedEncryptionPublicKeyMsgsSelector, unapprovedTypedMessagesSelector, networkSelector, ( unapprovedTxs = {}, unapprovedMsgs = {}, unapprovedPersonalMsgs = {}, + unapprovedDecryptMsgs = {}, unapprovedTypedMessages = {}, network ) => txHelper( unapprovedTxs, unapprovedMsgs, unapprovedPersonalMsgs, + unapprovedDecryptMsgs, unapprovedTypedMessages, network ) || [] @@ -44,12 +50,16 @@ export const unconfirmedTransactionsHashSelector = createSelector( unapprovedTxsSelector, unapprovedMsgsSelector, unapprovedPersonalMsgsSelector, + unapprovedDecryptMsgsSelector, + unapprovedEncryptionPublicKeyMsgsSelector, unapprovedTypedMessagesSelector, networkSelector, ( unapprovedTxs = {}, unapprovedMsgs = {}, unapprovedPersonalMsgs = {}, + unapprovedDecryptMsgs = {}, + unapprovedEncryptionPublicKeyMsgs = {}, unapprovedTypedMessages = {}, network ) => { @@ -68,6 +78,8 @@ export const unconfirmedTransactionsHashSelector = createSelector( ...filteredUnapprovedTxs, ...unapprovedMsgs, ...unapprovedPersonalMsgs, + ...unapprovedDecryptMsgs, + ...unapprovedEncryptionPublicKeyMsgs, ...unapprovedTypedMessages, } } @@ -75,18 +87,24 @@ export const unconfirmedTransactionsHashSelector = createSelector( const unapprovedMsgCountSelector = state => state.metamask.unapprovedMsgCount const unapprovedPersonalMsgCountSelector = state => state.metamask.unapprovedPersonalMsgCount +const unapprovedDecryptMsgCountSelector = state => state.metamask.unapprovedDecryptMsgCount +const unapprovedEncryptionPublicKeyMsgCountSelector = state => state.metamask.unapprovedEncryptionPublicKeyMsgCount const unapprovedTypedMessagesCountSelector = state => state.metamask.unapprovedTypedMessagesCount export const unconfirmedTransactionsCountSelector = createSelector( unapprovedTxsSelector, unapprovedMsgCountSelector, unapprovedPersonalMsgCountSelector, + unapprovedDecryptMsgCountSelector, + unapprovedEncryptionPublicKeyMsgCountSelector, unapprovedTypedMessagesCountSelector, networkSelector, ( unapprovedTxs = {}, unapprovedMsgCount = 0, unapprovedPersonalMsgCount = 0, + unapprovedDecryptMsgCount = 0, + unapprovedEncryptionPublicKeyMsgCount = 0, unapprovedTypedMessagesCount = 0, network ) => { @@ -96,7 +114,7 @@ export const unconfirmedTransactionsCountSelector = createSelector( }) return filteredUnapprovedTxIds.length + unapprovedTypedMessagesCount + unapprovedMsgCount + - unapprovedPersonalMsgCount + unapprovedPersonalMsgCount + unapprovedDecryptMsgCount + unapprovedEncryptionPublicKeyMsgCount } ) diff --git a/ui/app/selectors/selectors.js b/ui/app/selectors/selectors.js index 4b79cdf79bac..366a52f0b891 100644 --- a/ui/app/selectors/selectors.js +++ b/ui/app/selectors/selectors.js @@ -312,11 +312,13 @@ export function getTotalUnapprovedCount ({ metamask }) { unapprovedTxs = {}, unapprovedMsgCount, unapprovedPersonalMsgCount, + unapprovedDecryptMsgCount, + unapprovedEncryptionPublicKeyMsgCount, unapprovedTypedMessagesCount, } = metamask return Object.keys(unapprovedTxs).length + unapprovedMsgCount + unapprovedPersonalMsgCount + - unapprovedTypedMessagesCount + unapprovedTypedMessagesCount + unapprovedDecryptMsgCount + unapprovedEncryptionPublicKeyMsgCount } export function getIsMainnet (state) { diff --git a/ui/app/selectors/tests/selectors-test-data.js b/ui/app/selectors/tests/selectors-test-data.js index 4e0a06e3f0ec..1287f28dcc87 100644 --- a/ui/app/selectors/tests/selectors-test-data.js +++ b/ui/app/selectors/tests/selectors-test-data.js @@ -132,6 +132,10 @@ module.exports = { 'unapprovedMsgCount': 0, 'unapprovedPersonalMsgs': {}, 'unapprovedPersonalMsgCount': 0, + 'unapprovedDecryptMsgs': {}, + 'unapprovedDecryptMsgCount': 0, + 'unapprovedEncryptionPublicKeyMsgs': {}, + 'unapprovedEncryptionPublicKeyMsgCount': 0, 'keyringTypes': [ 'Simple Key Pair', 'HD Key Tree', diff --git a/ui/app/selectors/transactions.js b/ui/app/selectors/transactions.js index e25bb5be09e7..edcddee1f87f 100644 --- a/ui/app/selectors/transactions.js +++ b/ui/app/selectors/transactions.js @@ -33,23 +33,31 @@ export const incomingTxListSelector = state => { export const unapprovedMsgsSelector = state => state.metamask.unapprovedMsgs export const selectedAddressTxListSelector = state => state.metamask.selectedAddressTxList export const unapprovedPersonalMsgsSelector = state => state.metamask.unapprovedPersonalMsgs +export const unapprovedDecryptMsgsSelector = state => state.metamask.unapprovedDecryptMsgs +export const unapprovedEncryptionPublicKeyMsgsSelector = state => state.metamask.unapprovedEncryptionPublicKeyMsgs export const unapprovedTypedMessagesSelector = state => state.metamask.unapprovedTypedMessages export const networkSelector = state => state.metamask.network export const unapprovedMessagesSelector = createSelector( unapprovedMsgsSelector, unapprovedPersonalMsgsSelector, + unapprovedDecryptMsgsSelector, + unapprovedEncryptionPublicKeyMsgsSelector, unapprovedTypedMessagesSelector, networkSelector, ( unapprovedMsgs = {}, unapprovedPersonalMsgs = {}, + unapprovedDecryptMsgs = {}, + unapprovedEncryptionPublicKeyMsgs = {}, unapprovedTypedMessages = {}, network ) => txHelper( {}, unapprovedMsgs, unapprovedPersonalMsgs, + unapprovedDecryptMsgs, + unapprovedEncryptionPublicKeyMsgs, unapprovedTypedMessages, network ) || [] diff --git a/ui/app/store/actions.js b/ui/app/store/actions.js index eec289642dce..a8b9cc2d228f 100644 --- a/ui/app/store/actions.js +++ b/ui/app/store/actions.js @@ -124,7 +124,12 @@ const actions = { signMsg: signMsg, cancelMsg: cancelMsg, signPersonalMsg, + decryptMsg, + decryptMsgInline, + encryptionPublicKeyMsg, cancelPersonalMsg, + cancelDecryptMsg, + cancelEncryptionPublicKeyMsg, signTypedMsg, cancelTypedMsg, signTx: signTx, @@ -837,6 +842,89 @@ function signPersonalMsg (msgData) { } } +function decryptMsgInline (msgData) { + log.debug('action - decryptMsgInline') + return (dispatch) => { + window.onbeforeunload = null + return new Promise((resolve, reject) => { + log.debug(`actions calling background.decryptMessageInline`) + background.decryptMessageInline(msgData, (err, newState) => { + log.debug('decryptMsg called back') + dispatch(actions.updateMetamaskState(newState)) + msgData = newState.unapprovedDecryptMsgs[msgData.metamaskId] + if (err) { + log.error(err) + dispatch(actions.displayWarning(err.message)) + return reject(err) + } + return resolve(msgData) + }) + }) + } +} + +function decryptMsg (msgData) { + log.debug('action - decryptMsg') + return (dispatch, getState) => { + dispatch(actions.showLoadingIndication()) + window.onbeforeunload = null + return new Promise((resolve, reject) => { + log.debug(`actions calling background.decryptMessage`) + background.decryptMessage(msgData, (err, newState) => { + log.debug('decryptMsg called back') + dispatch(actions.updateMetamaskState(newState)) + dispatch(actions.hideLoadingIndication()) + + if (err) { + log.error(err) + dispatch(actions.displayWarning(err.message)) + return reject(err) + } + + dispatch(actions.completedTx(msgData.metamaskId)) + + if (global.METAMASK_UI_TYPE === ENVIRONMENT_TYPE_NOTIFICATION && + !hasUnconfirmedTransactions(getState())) { + return global.platform.closeCurrentWindow() + } + + return resolve(msgData) + }) + }) + } +} + +function encryptionPublicKeyMsg (msgData) { + log.debug('action - encryptionPublicKeyMsg') + return (dispatch, getState) => { + dispatch(actions.showLoadingIndication()) + window.onbeforeunload = null + return new Promise((resolve, reject) => { + log.debug(`actions calling background.encryptionPublicKey`) + background.encryptionPublicKey(msgData, (err, newState) => { + log.debug('encryptionPublicKeyMsg called back') + dispatch(actions.updateMetamaskState(newState)) + dispatch(actions.hideLoadingIndication()) + + if (err) { + log.error(err) + dispatch(actions.displayWarning(err.message)) + return reject(err) + } + + dispatch(actions.completedTx(msgData.metamaskId)) + + if (global.METAMASK_UI_TYPE === ENVIRONMENT_TYPE_NOTIFICATION && + !hasUnconfirmedTransactions(getState())) { + return global.platform.closeCurrentWindow() + } + + return resolve(msgData) + }) + }) + } +} + function signTypedMsg (msgData) { log.debug('action - signTypedMsg') return (dispatch) => { @@ -1201,6 +1289,52 @@ function cancelPersonalMsg (msgData) { } } +function cancelDecryptMsg (msgData) { + return (dispatch) => { + dispatch(actions.showLoadingIndication()) + window.onbeforeunload = null + return new Promise((resolve, reject) => { + const id = msgData.id + background.cancelDecryptMessage(id, (err, newState) => { + dispatch(actions.updateMetamaskState(newState)) + dispatch(actions.hideLoadingIndication()) + + if (err) { + return reject(err) + } + + dispatch(actions.completedTx(id)) + dispatch(closeCurrentNotificationWindow()) + + return resolve(msgData) + }) + }) + } +} + +function cancelEncryptionPublicKeyMsg (msgData) { + return (dispatch) => { + dispatch(actions.showLoadingIndication()) + window.onbeforeunload = null + return new Promise((resolve, reject) => { + const id = msgData.id + background.cancelEncryptionPublicKey(id, (err, newState) => { + dispatch(actions.updateMetamaskState(newState)) + dispatch(actions.hideLoadingIndication()) + + if (err) { + return reject(err) + } + + dispatch(actions.completedTx(id)) + dispatch(closeCurrentNotificationWindow()) + + return resolve(msgData) + }) + }) + } +} + function cancelTypedMsg (msgData) { return (dispatch) => { dispatch(actions.showLoadingIndication()) diff --git a/ui/index.js b/ui/index.js index 028aa3d051ef..9aff3c0726b2 100644 --- a/ui/index.js +++ b/ui/index.js @@ -61,7 +61,7 @@ async function startApp (metamaskState, backgroundConnection, opts) { }) // if unconfirmed txs, start on txConf page - const unapprovedTxsAll = txHelper(metamaskState.unapprovedTxs, metamaskState.unapprovedMsgs, metamaskState.unapprovedPersonalMsgs, metamaskState.unapprovedTypedMessages, metamaskState.network) + const unapprovedTxsAll = txHelper(metamaskState.unapprovedTxs, metamaskState.unapprovedMsgs, metamaskState.unapprovedPersonalMsgs, metamaskState.unapprovedDecryptMsgs, metamaskState.unapprovedEncryptionPublicKeyMsgs, metamaskState.unapprovedTypedMessages, metamaskState.network) const numberOfUnapprivedTx = unapprovedTxsAll.length if (numberOfUnapprivedTx > 0) { store.dispatch(actions.showConfTxPage({ diff --git a/ui/lib/tx-helper.js b/ui/lib/tx-helper.js index cdacc5ed7112..fadcaa288274 100644 --- a/ui/lib/tx-helper.js +++ b/ui/lib/tx-helper.js @@ -1,9 +1,9 @@ const valuesFor = require('../app/helpers/utils/util').valuesFor const log = require('loglevel') -module.exports = function (unapprovedTxs, unapprovedMsgs, personalMsgs, typedMessages, network) { +module.exports = function (unapprovedTxs, unapprovedMsgs, personalMsgs, decryptMsgs, encryptionPublicKeyMsgs, typedMessages, network) { log.debug('tx-helper called with params:') - log.debug({ unapprovedTxs, unapprovedMsgs, personalMsgs, typedMessages, network }) + log.debug({ unapprovedTxs, unapprovedMsgs, personalMsgs, decryptMsgs, encryptionPublicKeyMsgs, typedMessages, network }) const txValues = network ? valuesFor(unapprovedTxs).filter(txMeta => txMeta.metamaskNetworkId === network) : valuesFor(unapprovedTxs) log.debug(`tx helper found ${txValues.length} unapproved txs`) @@ -16,6 +16,14 @@ module.exports = function (unapprovedTxs, unapprovedMsgs, personalMsgs, typedMes log.debug(`tx helper found ${personalValues.length} unsigned personal messages`) allValues = allValues.concat(personalValues) + const decryptValues = valuesFor(decryptMsgs) + log.debug(`tx helper found ${decryptValues.length} decrypt requests`) + allValues = allValues.concat(decryptValues) + + const encryptionPublicKeyValues = valuesFor(encryptionPublicKeyMsgs) + log.debug(`tx helper found ${encryptionPublicKeyValues.length} encryptionPublicKey requests`) + allValues = allValues.concat(encryptionPublicKeyValues) + const typedValues = valuesFor(typedMessages) log.debug(`tx helper found ${typedValues.length} unsigned typed messages`) allValues = allValues.concat(typedValues) diff --git a/yarn.lock b/yarn.lock index e30d7570d9ce..ac3a02c7e7d4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9507,7 +9507,7 @@ env-paths@^1.0.0: resolved "https://registry.yarnpkg.com/env-paths/-/env-paths-1.0.0.tgz#4168133b42bb05c38a35b1ae4397c8298ab369e0" integrity sha1-QWgTO0K7BcOKNbGuQ5fIKYqzaeA= -envify@^4.0.0: +envify@^4.1.0: version "4.1.0" resolved "https://registry.yarnpkg.com/envify/-/envify-4.1.0.tgz#f39ad3db9d6801b4e6b478b61028d3f0b6819f7e" integrity sha512-IKRVVoAYr4pIx4yIWNsz9mOsboxlNXiu7TNBnem/K/uTHdkyzXWDzHCK7UTolqBbgaBz0tQHsD3YNls0uIIjiw== @@ -10265,9 +10265,9 @@ eth-ens-namehash@^1.0.2: js-sha3 "^0.5.7" eth-hd-keyring@^3.4.0: - version "3.4.0" - resolved "https://registry.yarnpkg.com/eth-hd-keyring/-/eth-hd-keyring-3.4.0.tgz#288e73041f2b3f047b4151fb4b5ab5ad5710b9a6" - integrity sha512-MMKSSwDWuEfItEM/826LHrs2HVjy57qQQfcgSxIYOCJY0vykw++LH8d6QJOBrGFe+xu/gtbHBRMURrFGdqfevw== + version "3.4.1" + resolved "https://registry.yarnpkg.com/eth-hd-keyring/-/eth-hd-keyring-3.4.1.tgz#c1b34b29bae57d90525dd1b7d3f349a30e0cee8a" + integrity sha512-oigRNw9lGRHvhkxZuREV147euMX9GH+0icc/MT0oaU+8hu6KCArg2fm78+uXcIvJvK66DZUS46/+hieXCXqwjw== dependencies: bip39 "^2.2.0" eth-sig-util "^2.4.4" @@ -10278,6 +10278,19 @@ eth-hd-keyring@^3.4.0: events "^1.1.1" xtend "^4.0.1" +"eth-hd-keyring@https://github.com/logvik/eth-hd-keyring": + version "3.5.1" + resolved "https://github.com/logvik/eth-hd-keyring#0a8ba3351a53e03ad7362714d71287a154f19e47" + dependencies: + bip39 "^2.2.0" + eth-sig-util "^2.4.4" + eth-simple-keyring "^3.5.0" + ethereumjs-abi "^0.6.5" + ethereumjs-util "^5.1.1" + ethereumjs-wallet "^0.6.0" + events "^1.1.1" + xtend "^4.0.1" + eth-json-rpc-errors@^1.0.1: version "1.1.0" resolved "https://registry.yarnpkg.com/eth-json-rpc-errors/-/eth-json-rpc-errors-1.1.0.tgz#2a4291fb20c0483c99b53286a814ed14ca4efb2e" @@ -10292,13 +10305,12 @@ eth-json-rpc-errors@^2.0.0: dependencies: fast-safe-stringify "^2.0.6" -eth-json-rpc-filters@^4.1.1: +eth-json-rpc-filters@^4.1.1, "eth-json-rpc-filters@https://github.com/logvik/eth-json-rpc-filters": version "4.1.1" - resolved "https://registry.yarnpkg.com/eth-json-rpc-filters/-/eth-json-rpc-filters-4.1.1.tgz#15277c66790236d85f798f4d7dc6bab99a798cd2" - integrity sha512-GkXb2h6STznD+AmMzblwXgm1JMvjdK9PTIXG7BvIkTlXQ9g0QOxuU1iQRYHoslF9S30BYBSoLSisAYPdLggW+A== + resolved "https://github.com/logvik/eth-json-rpc-filters#027447b83452a6f8b3e29bfa4b142657786f4d43" dependencies: await-semaphore "^0.1.3" - eth-json-rpc-middleware "^4.1.4" + eth-json-rpc-middleware "https://github.com/MetaMask/eth-json-rpc-middleware" eth-query "^2.1.2" json-rpc-engine "^5.1.3" lodash.flatmap "^4.5.0" @@ -10326,6 +10338,15 @@ eth-json-rpc-infura@^4.0.1: json-rpc-engine "^5.1.3" tape "^4.8.0" +"eth-json-rpc-infura@https://github.com/logvik/eth-json-rpc-infura": + version "4.0.2" + resolved "https://github.com/logvik/eth-json-rpc-infura#cd0443a59b50c1259dfa11c4b32cb974f2267967" + dependencies: + cross-fetch "^2.1.1" + eth-json-rpc-errors "^1.0.1" + eth-json-rpc-middleware "https://github.com/MetaMask/eth-json-rpc-middleware" + json-rpc-engine "^5.1.3" + eth-json-rpc-middleware@^1.5.0: version "1.6.0" resolved "https://registry.yarnpkg.com/eth-json-rpc-middleware/-/eth-json-rpc-middleware-1.6.0.tgz#5c9d4c28f745ccb01630f0300ba945f4bef9593f" @@ -10345,7 +10366,7 @@ eth-json-rpc-middleware@^1.5.0: promise-to-callback "^1.0.0" tape "^4.6.3" -eth-json-rpc-middleware@^4.1.4, eth-json-rpc-middleware@^4.1.5, eth-json-rpc-middleware@^4.2.0: +eth-json-rpc-middleware@^4.1.4, eth-json-rpc-middleware@^4.1.5: version "4.2.0" resolved "https://registry.yarnpkg.com/eth-json-rpc-middleware/-/eth-json-rpc-middleware-4.2.0.tgz#cfb77c5056cb8001548c6c7d54f4af5fce04d489" integrity sha512-90LljqRyJhkg7fOwKunh1lu1Mr5bspXMBDitaTGyGPPNiFTbMrhtfbf9fteYlXRFCbq+aIFWwl/X+P7nkrdkLg== @@ -10365,6 +10386,25 @@ eth-json-rpc-middleware@^4.1.4, eth-json-rpc-middleware@^4.1.5, eth-json-rpc-mid pify "^3.0.0" safe-event-emitter "^1.0.1" +"eth-json-rpc-middleware@https://github.com/MetaMask/eth-json-rpc-middleware": + version "4.3.0" + resolved "https://github.com/MetaMask/eth-json-rpc-middleware#8e7f0584affe78a009fdca8089edd12b9510215d" + dependencies: + btoa "^1.2.1" + clone "^2.1.1" + eth-json-rpc-errors "^1.0.1" + eth-query "^2.1.2" + eth-sig-util "^1.4.2" + ethereumjs-block "^1.6.0" + ethereumjs-tx "^1.3.7" + ethereumjs-util "^5.1.2" + ethereumjs-vm "^2.6.0" + fetch-ponyfill "^4.0.0" + json-rpc-engine "^5.1.3" + json-stable-stringify "^1.0.1" + pify "^3.0.0" + safe-event-emitter "^1.0.1" + eth-keyring-controller@^5.3.0: version "5.3.0" resolved "https://registry.yarnpkg.com/eth-keyring-controller/-/eth-keyring-controller-5.3.0.tgz#8d85a67b894360ab7d601222ca71df8ed5f456c6" @@ -10380,6 +10420,20 @@ eth-keyring-controller@^5.3.0: loglevel "^1.5.0" obs-store "^4.0.3" +"eth-keyring-controller@https://github.com/logvik/KeyringController": + version "5.3.1" + resolved "https://github.com/logvik/KeyringController#f0cec5b88e0b8955cef917bbf9bc45a0826570d0" + dependencies: + bip39 "^2.4.0" + bluebird "^3.5.0" + browser-passworder "^2.0.3" + eth-hd-keyring "https://github.com/logvik/eth-hd-keyring" + eth-sig-util "^1.4.0" + eth-simple-keyring "^3.5.0" + ethereumjs-util "^5.1.2" + loglevel "^1.5.0" + obs-store "^4.0.3" + eth-ledger-bridge-keyring@^0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/eth-ledger-bridge-keyring/-/eth-ledger-bridge-keyring-0.2.0.tgz#715de14da24496c35cdb433022a20bd21b984f7e" @@ -10493,6 +10547,18 @@ eth-simple-keyring@^3.4.0: events "^1.1.1" xtend "^4.0.1" +eth-simple-keyring@^3.5.0: + version "3.5.0" + resolved "https://registry.yarnpkg.com/eth-simple-keyring/-/eth-simple-keyring-3.5.0.tgz#c7fa285ca58d31ef44bc7db678b689f9ffd7b453" + integrity sha512-z9IPt9aoMWAw5Zc3Jk/HKbWPJNc7ivZ5ECNtl3ZoQUGRnwoWO71W5+liVPJtXFNacGOOGsBfqTqrXL9C4EnYYQ== + dependencies: + eth-sig-util "^2.5.0" + ethereumjs-abi "^0.6.5" + ethereumjs-util "^5.1.1" + ethereumjs-wallet "^0.6.0" + events "^1.1.1" + xtend "^4.0.1" + eth-token-tracker@^1.1.10: version "1.1.10" resolved "https://registry.yarnpkg.com/eth-token-tracker/-/eth-token-tracker-1.1.10.tgz#3899a33cc442c0405e3923e71e0eff530bd1258b" @@ -12384,7 +12450,7 @@ fuse.js@^3.4.4: resolved "https://registry.yarnpkg.com/fuse.js/-/fuse.js-3.4.5.tgz#8954fb43f9729bd5dbcb8c08f251db552595a7a6" integrity sha512-s9PGTaQIkT69HaeoTVjwGsLfb8V8ScJLx5XGFcKHg0MqLUH/UZ4EKOtqtXX9k7AFqCGxD1aJmYb8Q5VYDibVRQ== -gaba@^1.6.0, gaba@^1.9.0: +gaba@^1.6.0: version "1.9.0" resolved "https://registry.yarnpkg.com/gaba/-/gaba-1.9.0.tgz#ccd9f99c56687b5acd39f9e3ceb435b2a59b6aa1" integrity sha512-HoVreAdZssL0jNHuzZ7WP+YKZ0riu44jVDWxhQ9hsgPuzxbVEsz9fO/HDxqAdNZS1Cswayq6+ciZ3HSCFWMKbQ== @@ -12411,6 +12477,33 @@ gaba@^1.6.0, gaba@^1.9.0: web3 "^0.20.7" web3-provider-engine "^15.0.4" +gaba@^1.9.1: + version "1.9.1" + resolved "https://registry.yarnpkg.com/gaba/-/gaba-1.9.1.tgz#2e096889aca74eb5946b55a3922427314b5dca22" + integrity sha512-YsKG4+Ql3D6v4cnMgH7P8c9JqQb74y6gkIhySLd1BYwFZQTXn27u16cYfoxPtqeGfTFhus9h4CpxAr8s8bsvCA== + dependencies: + await-semaphore "^0.1.3" + eth-contract-metadata "^1.11.0" + eth-ens-namehash "^2.0.8" + eth-json-rpc-infura "^4.0.1" + eth-keyring-controller "^5.3.0" + eth-method-registry "1.1.0" + eth-phishing-detect "^1.1.13" + eth-query "^2.1.2" + eth-sig-util "^2.3.0" + ethereumjs-util "^6.1.0" + ethereumjs-wallet "0.6.0" + ethjs-query "^0.3.8" + human-standard-collectible-abi "^1.0.2" + human-standard-token-abi "^2.0.0" + isomorphic-fetch "^2.2.1" + jsonschema "^1.2.4" + percentile "^1.2.1" + single-call-balance-checker-abi "^1.0.0" + uuid "^3.3.2" + web3 "^0.20.7" + web3-provider-engine "^15.0.4" + ganache-cli@^6.4.4: version "6.4.4" resolved "https://registry.yarnpkg.com/ganache-cli/-/ganache-cli-6.4.4.tgz#9772bba8585d6e2049bd85adf24369c1cc165170" @@ -13402,7 +13495,7 @@ gulp-zip@^4.0.0: vinyl "^2.1.0" yazl "^2.1.0" -gulp@^4.0.0, gulp@^4.0.2: +gulp@^4.0.2: version "4.0.2" resolved "https://registry.yarnpkg.com/gulp/-/gulp-4.0.2.tgz#543651070fd0f6ab0a0650c6a3e6ff5a7cb09caa" integrity sha512-dvEs27SCZt2ibF29xYgmnwwCYZxdxhQ/+LFWlbAW8y7jt68L/65402Lz3+CKy0Ov4rOs+NERmDq7YlZaDqUIfA== From 0299e0cf02bbc6c396f6c315ef408126cadd228f Mon Sep 17 00:00:00 2001 From: kviktorov Date: Fri, 10 Jan 2020 21:03:28 +0300 Subject: [PATCH 02/23] npm version for eth-json-rpc-middleware --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3de6a1a91dc7..1ab83bfbf591 100644 --- a/package.json +++ b/package.json @@ -94,7 +94,7 @@ "eth-json-rpc-errors": "^2.0.0", "eth-json-rpc-filters": "https://github.com/logvik/eth-json-rpc-filters", "eth-json-rpc-infura": "https://github.com/logvik/eth-json-rpc-infura", - "eth-json-rpc-middleware": "https://github.com/MetaMask/eth-json-rpc-middleware", + "eth-json-rpc-middleware": "^4.4.0", "eth-keyring-controller": "https://github.com/logvik/KeyringController", "eth-ledger-bridge-keyring": "^0.2.0", "eth-method-registry": "^1.2.0", From 908d05485bc3206faaaf5d6973f8f7d2eec09517 Mon Sep 17 00:00:00 2001 From: kviktorov Date: Wed, 15 Jan 2020 14:27:05 +0300 Subject: [PATCH 03/23] merged with origin repository --- app/scripts/lib/decrypt-message-manager.js | 12 +++--- .../lib/encryption-public-key-manager.js | 33 +++------------ .../confirm-decrypt-message.container.js | 10 ++--- ...confirm-encryption-public-key.container.js | 8 ++-- ui/app/store/actions.js | 40 +++++++++---------- yarn.lock | 5 +-- 6 files changed, 43 insertions(+), 65 deletions(-) diff --git a/app/scripts/lib/decrypt-message-manager.js b/app/scripts/lib/decrypt-message-manager.js index 2e4815e58606..ff857a98d695 100644 --- a/app/scripts/lib/decrypt-message-manager.js +++ b/app/scripts/lib/decrypt-message-manager.js @@ -1,10 +1,10 @@ -const EventEmitter = require('events') -const ObservableStore = require('obs-store') -const ethUtil = require('ethereumjs-util') -const { ethErrors } = require('eth-json-rpc-errors') -const createId = require('./random-id') +import EventEmitter from 'events' +import ObservableStore from 'obs-store' +import ethUtil from 'ethereumjs-util' +import { ethErrors } from 'eth-json-rpc-errors' +import createId from './random-id' const hexRe = /^[0-9A-Fa-f]+$/g -const log = require('loglevel') +import log from 'loglevel' /** * Represents, and contains data about, an 'eth_decryptMessage' type decryption request. These are created when a diff --git a/app/scripts/lib/encryption-public-key-manager.js b/app/scripts/lib/encryption-public-key-manager.js index de588f3c04ec..64f38916469a 100644 --- a/app/scripts/lib/encryption-public-key-manager.js +++ b/app/scripts/lib/encryption-public-key-manager.js @@ -1,10 +1,9 @@ -const EventEmitter = require('events') -const ObservableStore = require('obs-store') -const ethUtil = require('ethereumjs-util') -const { ethErrors } = require('eth-json-rpc-errors') -const createId = require('./random-id') -const hexRe = /^[0-9A-Fa-f]+$/g -const log = require('loglevel') +import EventEmitter from 'events' +import ObservableStore from 'obs-store' +import ethUtil from 'ethereumjs-util' +import { ethErrors } from 'eth-json-rpc-errors' +import createId from './random-id' +import log from 'loglevel' /** * Represents, and contains data about, an 'encryption_public_key' type request. These are created when @@ -281,24 +280,4 @@ module.exports = class EncryptionPublicKeyManager extends EventEmitter { this.emit('updateBadge') } - /** - * A helper function that converts raw buffer data to a hex, or just returns the data if it is already formatted as a hex. - * - * @param {any} data The buffer data to convert to a hex - * @returns {string} A hex string conversion of the buffer data - * - */ - normalizeMsgData (data) { - try { - const stripped = ethUtil.stripHexPrefix(data) - if (stripped.match(hexRe)) { - return ethUtil.addHexPrefix(stripped) - } - } catch (e) { - log.debug(`Message was not hex encoded, interpreting as utf8.`) - } - - return ethUtil.bufferToHex(Buffer.from(data, 'utf8')) - } - } diff --git a/ui/app/pages/confirm-decrypt-message/confirm-decrypt-message.container.js b/ui/app/pages/confirm-decrypt-message/confirm-decrypt-message.container.js index 5135025544e5..c310abb60b06 100644 --- a/ui/app/pages/confirm-decrypt-message/confirm-decrypt-message.container.js +++ b/ui/app/pages/confirm-decrypt-message/confirm-decrypt-message.container.js @@ -1,7 +1,7 @@ import { connect } from 'react-redux' import { compose } from 'recompose' import { withRouter } from 'react-router-dom' -const actions = require('../../store/actions') +import { goHome, decryptMsg, cancelDecryptMsg, decryptMsgInline} from '../../store/actions' import { getSelectedAccount, @@ -35,23 +35,23 @@ function mapStateToProps (state) { function mapDispatchToProps (dispatch) { return { - goHome: () => dispatch(actions.goHome()), + goHome: () => dispatch(goHome()), clearConfirmTransaction: () => dispatch(clearConfirmTransaction()), decryptMessage: (msgData, event) => { const params = msgData.msgParams params.metamaskId = msgData.id event.stopPropagation(event) - return dispatch(actions.decryptMsg(params)) + return dispatch(decryptMsg(params)) }, cancelDecryptMessage: (msgData, event) => { event.stopPropagation(event) - return dispatch(actions.cancelDecryptMsg(msgData)) + return dispatch(cancelDecryptMsg(msgData)) }, decryptMessageInline: (msgData, event) => { const params = msgData.msgParams params.metamaskId = msgData.id event.stopPropagation(event) - return dispatch(actions.decryptMsgInline(params)) + return dispatch(decryptMsgInline(params)) }, } } diff --git a/ui/app/pages/confirm-encryption-public-key/confirm-encryption-public-key.container.js b/ui/app/pages/confirm-encryption-public-key/confirm-encryption-public-key.container.js index 11a7ca8959e1..48c569373fe4 100644 --- a/ui/app/pages/confirm-encryption-public-key/confirm-encryption-public-key.container.js +++ b/ui/app/pages/confirm-encryption-public-key/confirm-encryption-public-key.container.js @@ -1,7 +1,7 @@ import { connect } from 'react-redux' import { compose } from 'recompose' import { withRouter } from 'react-router-dom' -const actions = require('../../store/actions') +import { goHome, encryptionPublicKeyMsg, cancelEncryptionPublicKeyMsg } from '../../store/actions' import { getSelectedAccount, @@ -31,16 +31,16 @@ function mapStateToProps (state) { function mapDispatchToProps (dispatch) { return { - goHome: () => dispatch(actions.goHome()), + goHome: () => dispatch(goHome()), clearConfirmTransaction: () => dispatch(clearConfirmTransaction()), encryptionPublicKey: (msgData, event) => { const params = { data: msgData.msgParams, metamaskId: msgData.id} event.stopPropagation() - return dispatch(actions.encryptionPublicKeyMsg(params)) + return dispatch(encryptionPublicKeyMsg(params)) }, cancelEncryptionPublicKey: (msgData, event) => { event.stopPropagation() - return dispatch(actions.cancelEncryptionPublicKeyMsg(msgData)) + return dispatch(cancelEncryptionPublicKeyMsg(msgData)) }, } } diff --git a/ui/app/store/actions.js b/ui/app/store/actions.js index fa5ddb13e9a8..2bd096f08495 100644 --- a/ui/app/store/actions.js +++ b/ui/app/store/actions.js @@ -658,11 +658,11 @@ export function decryptMsgInline (msgData) { log.debug(`actions calling background.decryptMessageInline`) background.decryptMessageInline(msgData, (err, newState) => { log.debug('decryptMsg called back') - dispatch(actions.updateMetamaskState(newState)) + dispatch(updateMetamaskState(newState)) msgData = newState.unapprovedDecryptMsgs[msgData.metamaskId] if (err) { log.error(err) - dispatch(actions.displayWarning(err.message)) + dispatch(displayWarning(err.message)) return reject(err) } return resolve(msgData) @@ -674,22 +674,22 @@ export function decryptMsgInline (msgData) { export function decryptMsg (msgData) { log.debug('action - decryptMsg') return (dispatch, getState) => { - dispatch(actions.showLoadingIndication()) + dispatch(showLoadingIndication()) window.onbeforeunload = null return new Promise((resolve, reject) => { log.debug(`actions calling background.decryptMessage`) background.decryptMessage(msgData, (err, newState) => { log.debug('decryptMsg called back') - dispatch(actions.updateMetamaskState(newState)) - dispatch(actions.hideLoadingIndication()) + dispatch(updateMetamaskState(newState)) + dispatch(hideLoadingIndication()) if (err) { log.error(err) - dispatch(actions.displayWarning(err.message)) + dispatch(displayWarning(err.message)) return reject(err) } - dispatch(actions.completedTx(msgData.metamaskId)) + dispatch(completedTx(msgData.metamaskId)) if (global.METAMASK_UI_TYPE === ENVIRONMENT_TYPE_NOTIFICATION && !hasUnconfirmedTransactions(getState())) { @@ -705,22 +705,22 @@ export function decryptMsg (msgData) { export function encryptionPublicKeyMsg (msgData) { log.debug('action - encryptionPublicKeyMsg') return (dispatch, getState) => { - dispatch(actions.showLoadingIndication()) + dispatch(showLoadingIndication()) window.onbeforeunload = null return new Promise((resolve, reject) => { log.debug(`actions calling background.encryptionPublicKey`) background.encryptionPublicKey(msgData, (err, newState) => { log.debug('encryptionPublicKeyMsg called back') - dispatch(actions.updateMetamaskState(newState)) - dispatch(actions.hideLoadingIndication()) + dispatch(updateMetamaskState(newState)) + dispatch(hideLoadingIndication()) if (err) { log.error(err) - dispatch(actions.displayWarning(err.message)) + dispatch(displayWarning(err.message)) return reject(err) } - dispatch(actions.completedTx(msgData.metamaskId)) + dispatch(completedTx(msgData.metamaskId)) if (global.METAMASK_UI_TYPE === ENVIRONMENT_TYPE_NOTIFICATION && !hasUnconfirmedTransactions(getState())) { @@ -1099,19 +1099,19 @@ export function cancelPersonalMsg (msgData) { export function cancelDecryptMsg (msgData) { return (dispatch) => { - dispatch(actions.showLoadingIndication()) + dispatch(showLoadingIndication()) window.onbeforeunload = null return new Promise((resolve, reject) => { const id = msgData.id background.cancelDecryptMessage(id, (err, newState) => { - dispatch(actions.updateMetamaskState(newState)) - dispatch(actions.hideLoadingIndication()) + dispatch(updateMetamaskState(newState)) + dispatch(hideLoadingIndication()) if (err) { return reject(err) } - dispatch(actions.completedTx(id)) + dispatch(completedTx(id)) dispatch(closeCurrentNotificationWindow()) return resolve(msgData) @@ -1122,19 +1122,19 @@ export function cancelDecryptMsg (msgData) { export function cancelEncryptionPublicKeyMsg (msgData) { return (dispatch) => { - dispatch(actions.showLoadingIndication()) + dispatch(showLoadingIndication()) window.onbeforeunload = null return new Promise((resolve, reject) => { const id = msgData.id background.cancelEncryptionPublicKey(id, (err, newState) => { - dispatch(actions.updateMetamaskState(newState)) - dispatch(actions.hideLoadingIndication()) + dispatch(updateMetamaskState(newState)) + dispatch(hideLoadingIndication()) if (err) { return reject(err) } - dispatch(actions.completedTx(id)) + dispatch(completedTx(id)) dispatch(closeCurrentNotificationWindow()) return resolve(msgData) diff --git a/yarn.lock b/yarn.lock index 4ce4894ddf2f..e5685c2676e1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10465,10 +10465,9 @@ eth-json-rpc-middleware@^4.1.4, eth-json-rpc-middleware@^4.1.5: pify "^3.0.0" safe-event-emitter "^1.0.1" -eth-json-rpc-middleware@^4.4.0: +eth-json-rpc-middleware@^4.4.0, "eth-json-rpc-middleware@https://github.com/MetaMask/eth-json-rpc-middleware": version "4.4.0" - resolved "https://registry.yarnpkg.com/eth-json-rpc-middleware/-/eth-json-rpc-middleware-4.4.0.tgz#ef63b783b48dcbea9c1fe25c79e6ea01510e5877" - integrity sha512-IeOsil/XiHsybJO9nFf86+1+YIqGQWPPfiTEp3WLkpLZhJm97kw6tFM7GttIZXIcwtaO3zEXgY6PWAH1jkB3ag== + resolved "https://github.com/MetaMask/eth-json-rpc-middleware#a0f9d05b5f4e229621a9558c17fa4acb920de822" dependencies: btoa "^1.2.1" clone "^2.1.1" From b78fcb7e6ef7b29550526bc69d68627df8ea8f4b Mon Sep 17 00:00:00 2001 From: kviktorov Date: Wed, 15 Jan 2020 19:16:24 +0300 Subject: [PATCH 04/23] lint --- app/scripts/controllers/threebox.js | 5 ----- app/scripts/lib/decrypt-message-manager.js | 3 ++- app/scripts/lib/encryption-public-key-manager.js | 3 +-- .../confirm-decrypt-message.component.js | 8 ++++---- .../confirm-decrypt-message.container.js | 2 +- ui/app/pages/confirm-decrypt-message/index.js | 1 - .../confirm-encryption-public-key.component.js | 2 +- .../confirm-encryption-public-key.container.js | 2 +- ui/app/pages/confirm-encryption-public-key/index.js | 1 - 9 files changed, 10 insertions(+), 17 deletions(-) diff --git a/app/scripts/controllers/threebox.js b/app/scripts/controllers/threebox.js index b3e72b8de9c1..ebbe46701b14 100644 --- a/app/scripts/controllers/threebox.js +++ b/app/scripts/controllers/threebox.js @@ -60,11 +60,6 @@ class ThreeBoxController { withAppKeyOrigin: 'wallet://3box.metamask.io', })) }, - processDecryptMessage: (msgParams) => { - return Promise.resolve(keyringController.decryptMessage(msgParams, { - withAppKeyOrigin: 'wallet://3box.metamask.io', - })) - }, }) const initState = { diff --git a/app/scripts/lib/decrypt-message-manager.js b/app/scripts/lib/decrypt-message-manager.js index ff857a98d695..357e9a47661b 100644 --- a/app/scripts/lib/decrypt-message-manager.js +++ b/app/scripts/lib/decrypt-message-manager.js @@ -3,6 +3,7 @@ import ObservableStore from 'obs-store' import ethUtil from 'ethereumjs-util' import { ethErrors } from 'eth-json-rpc-errors' import createId from './random-id' + const hexRe = /^[0-9A-Fa-f]+$/g import log from 'loglevel' @@ -25,7 +26,7 @@ import log from 'loglevel' * */ -module.exports = class DecryptMessageManager extends EventEmitter { +export default class DecryptMessageManager extends EventEmitter { /** * Controller in charge of managing - storing, adding, removing, updating - DecryptMessage. * diff --git a/app/scripts/lib/encryption-public-key-manager.js b/app/scripts/lib/encryption-public-key-manager.js index 64f38916469a..e4b4fe3c2835 100644 --- a/app/scripts/lib/encryption-public-key-manager.js +++ b/app/scripts/lib/encryption-public-key-manager.js @@ -1,6 +1,5 @@ import EventEmitter from 'events' import ObservableStore from 'obs-store' -import ethUtil from 'ethereumjs-util' import { ethErrors } from 'eth-json-rpc-errors' import createId from './random-id' import log from 'loglevel' @@ -22,7 +21,7 @@ import log from 'loglevel' * */ -module.exports = class EncryptionPublicKeyManager extends EventEmitter { +export default class EncryptionPublicKeyManager extends EventEmitter { /** * Controller in charge of managing - storing, adding, removing, updating - EncryptionPublicKey. * diff --git a/ui/app/pages/confirm-decrypt-message/confirm-decrypt-message.component.js b/ui/app/pages/confirm-decrypt-message/confirm-decrypt-message.component.js index 35d56d7a2962..8765572ce7f3 100644 --- a/ui/app/pages/confirm-decrypt-message/confirm-decrypt-message.component.js +++ b/ui/app/pages/confirm-decrypt-message/confirm-decrypt-message.component.js @@ -7,7 +7,7 @@ import classnames from 'classnames' import { ENVIRONMENT_TYPE_NOTIFICATION } from '../../../../app/scripts/lib/enums' import { getEnvironmentType } from '../../../../app/scripts/lib/util' import Identicon from '../../components/ui/identicon' -import AccountListItem from '../../pages/send/account-list-item/account-list-item.component' +import AccountListItem from '../send/account-list-item/account-list-item.component' import { conversionUtil } from '../../helpers/utils/conversion-util' import Button from '../../components/ui/button' import { DEFAULT_ROUTE } from '../../helpers/constants/routes' @@ -29,7 +29,7 @@ export default class ConfirmDecryptMessage extends Component { requesterAddress: PropTypes.string, selectedAccount: PropTypes.object, txData: PropTypes.object, - approvedOrigins: PropTypes.object, + domainMetadata: PropTypes.object, } state = { @@ -222,9 +222,9 @@ export default class ConfirmDecryptMessage extends Component { onClick={(event) => { this.props.decryptMessageInline(txData, event).then((result, err) => { if (!err) { - this.setState({ hasDecrypted: true, rawMessage: result.rawData}) + this.setState({ hasDecrypted: true, rawMessage: result.rawData }) } else { - this.setState({ hasDecrypted: true, rawMessage: err}) + this.setState({ hasDecrypted: true, rawMessage: err }) } }) }} diff --git a/ui/app/pages/confirm-decrypt-message/confirm-decrypt-message.container.js b/ui/app/pages/confirm-decrypt-message/confirm-decrypt-message.container.js index c310abb60b06..ebdb00f53dea 100644 --- a/ui/app/pages/confirm-decrypt-message/confirm-decrypt-message.container.js +++ b/ui/app/pages/confirm-decrypt-message/confirm-decrypt-message.container.js @@ -1,7 +1,7 @@ import { connect } from 'react-redux' import { compose } from 'recompose' import { withRouter } from 'react-router-dom' -import { goHome, decryptMsg, cancelDecryptMsg, decryptMsgInline} from '../../store/actions' +import { goHome, decryptMsg, cancelDecryptMsg, decryptMsgInline } from '../../store/actions' import { getSelectedAccount, diff --git a/ui/app/pages/confirm-decrypt-message/index.js b/ui/app/pages/confirm-decrypt-message/index.js index e7d072d2fd90..9cc67168198f 100644 --- a/ui/app/pages/confirm-decrypt-message/index.js +++ b/ui/app/pages/confirm-decrypt-message/index.js @@ -1,2 +1 @@ export { default } from './confirm-decrypt-message.container' -export { default as ConfirmDecryptMessage } from './confirm-decrypt-message.component' diff --git a/ui/app/pages/confirm-encryption-public-key/confirm-encryption-public-key.component.js b/ui/app/pages/confirm-encryption-public-key/confirm-encryption-public-key.component.js index 9947733cda39..52051a32cdd2 100644 --- a/ui/app/pages/confirm-encryption-public-key/confirm-encryption-public-key.component.js +++ b/ui/app/pages/confirm-encryption-public-key/confirm-encryption-public-key.component.js @@ -4,7 +4,7 @@ import PropTypes from 'prop-types' import { ENVIRONMENT_TYPE_NOTIFICATION } from '../../../../app/scripts/lib/enums' import { getEnvironmentType } from '../../../../app/scripts/lib/util' import Identicon from '../../components/ui/identicon' -import AccountListItem from '../../pages/send/account-list-item/account-list-item.component' +import AccountListItem from '../send/account-list-item/account-list-item.component' import { conversionUtil } from '../../helpers/utils/conversion-util' import Button from '../../components/ui/button' import { DEFAULT_ROUTE } from '../../helpers/constants/routes' diff --git a/ui/app/pages/confirm-encryption-public-key/confirm-encryption-public-key.container.js b/ui/app/pages/confirm-encryption-public-key/confirm-encryption-public-key.container.js index 48c569373fe4..99895b30dbf2 100644 --- a/ui/app/pages/confirm-encryption-public-key/confirm-encryption-public-key.container.js +++ b/ui/app/pages/confirm-encryption-public-key/confirm-encryption-public-key.container.js @@ -34,7 +34,7 @@ function mapDispatchToProps (dispatch) { goHome: () => dispatch(goHome()), clearConfirmTransaction: () => dispatch(clearConfirmTransaction()), encryptionPublicKey: (msgData, event) => { - const params = { data: msgData.msgParams, metamaskId: msgData.id} + const params = { data: msgData.msgParams, metamaskId: msgData.id } event.stopPropagation() return dispatch(encryptionPublicKeyMsg(params)) }, diff --git a/ui/app/pages/confirm-encryption-public-key/index.js b/ui/app/pages/confirm-encryption-public-key/index.js index 2975fc1df2e4..9eb370e52ad1 100644 --- a/ui/app/pages/confirm-encryption-public-key/index.js +++ b/ui/app/pages/confirm-encryption-public-key/index.js @@ -1,2 +1 @@ export { default } from './confirm-encryption-public-key.container' -export { default as ConfirmEncryptionPublicKey } from './confirm-encryption-public-key.component' From 445c7ac3ef3d9e207cb3d702dbc9c7f8c8d2ef89 Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Wed, 15 Jan 2020 13:15:27 -0400 Subject: [PATCH 05/23] Use published versions of dependencies The latest published versions of `eth-keyring-controller`, `eth-json-rpc-infura`, and `eth-json-rpc-filters` are now used. They in turn are using the latest version of `eth-hd-keyring` and `eth-json-rpc-middleware` respectively. --- package.json | 6 ++--- yarn.lock | 66 ++++++++++++++-------------------------------------- 2 files changed, 21 insertions(+), 51 deletions(-) diff --git a/package.json b/package.json index 828322abb853..8f8ba6334ebd 100644 --- a/package.json +++ b/package.json @@ -94,10 +94,10 @@ "eth-contract-metadata": "^1.11.0", "eth-ens-namehash": "^2.0.8", "eth-json-rpc-errors": "^2.0.0", - "eth-json-rpc-filters": "https://github.com/logvik/eth-json-rpc-filters", - "eth-json-rpc-infura": "https://github.com/logvik/eth-json-rpc-infura", + "eth-json-rpc-filters": "^4.1.1", + "eth-json-rpc-infura": "^4.0.2", "eth-json-rpc-middleware": "^4.4.0", - "eth-keyring-controller": "https://github.com/logvik/KeyringController", + "eth-keyring-controller": "^5.4.0", "eth-ledger-bridge-keyring": "^0.2.0", "eth-method-registry": "^1.2.0", "eth-phishing-detect": "^1.1.4", diff --git a/yarn.lock b/yarn.lock index e5685c2676e1..c7e1a85c4c85 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10343,23 +10343,10 @@ eth-ens-namehash@^1.0.2: idna-uts46 "^1.0.1" js-sha3 "^0.5.7" -eth-hd-keyring@^3.4.0: - version "3.4.1" - resolved "https://registry.yarnpkg.com/eth-hd-keyring/-/eth-hd-keyring-3.4.1.tgz#c1b34b29bae57d90525dd1b7d3f349a30e0cee8a" - integrity sha512-oigRNw9lGRHvhkxZuREV147euMX9GH+0icc/MT0oaU+8hu6KCArg2fm78+uXcIvJvK66DZUS46/+hieXCXqwjw== - dependencies: - bip39 "^2.2.0" - eth-sig-util "^2.4.4" - eth-simple-keyring "^3.4.0" - ethereumjs-abi "^0.6.5" - ethereumjs-util "^5.1.1" - ethereumjs-wallet "^0.6.0" - events "^1.1.1" - xtend "^4.0.1" - -"eth-hd-keyring@https://github.com/logvik/eth-hd-keyring": - version "3.5.1" - resolved "https://github.com/logvik/eth-hd-keyring#0a8ba3351a53e03ad7362714d71287a154f19e47" +eth-hd-keyring@^3.4.0, eth-hd-keyring@^3.4.1: + version "3.5.0" + resolved "https://registry.yarnpkg.com/eth-hd-keyring/-/eth-hd-keyring-3.5.0.tgz#3976d83a27b24305481c389178f290d9264e839d" + integrity sha512-Ix1LcWYxHMxCCSIMz+TLXLtt50zF6ZDd/TRVXthdw91IwOk1ajuf7QHg3bCDcfeUpdf9oEpwIPbL3xjDqEEjYw== dependencies: bip39 "^2.2.0" eth-sig-util "^2.4.4" @@ -10384,12 +10371,13 @@ eth-json-rpc-errors@^2.0.0: dependencies: fast-safe-stringify "^2.0.6" -eth-json-rpc-filters@^4.1.1, "eth-json-rpc-filters@https://github.com/logvik/eth-json-rpc-filters": +eth-json-rpc-filters@^4.1.1: version "4.1.1" - resolved "https://github.com/logvik/eth-json-rpc-filters#027447b83452a6f8b3e29bfa4b142657786f4d43" + resolved "https://registry.yarnpkg.com/eth-json-rpc-filters/-/eth-json-rpc-filters-4.1.1.tgz#15277c66790236d85f798f4d7dc6bab99a798cd2" + integrity sha512-GkXb2h6STznD+AmMzblwXgm1JMvjdK9PTIXG7BvIkTlXQ9g0QOxuU1iQRYHoslF9S30BYBSoLSisAYPdLggW+A== dependencies: await-semaphore "^0.1.3" - eth-json-rpc-middleware "https://github.com/MetaMask/eth-json-rpc-middleware" + eth-json-rpc-middleware "^4.1.4" eth-query "^2.1.2" json-rpc-engine "^5.1.3" lodash.flatmap "^4.5.0" @@ -10417,13 +10405,14 @@ eth-json-rpc-infura@^4.0.1: json-rpc-engine "^5.1.3" tape "^4.8.0" -"eth-json-rpc-infura@https://github.com/logvik/eth-json-rpc-infura": +eth-json-rpc-infura@^4.0.2: version "4.0.2" - resolved "https://github.com/logvik/eth-json-rpc-infura#cd0443a59b50c1259dfa11c4b32cb974f2267967" + resolved "https://registry.yarnpkg.com/eth-json-rpc-infura/-/eth-json-rpc-infura-4.0.2.tgz#8af1a1a2e9a0a82aaa302bbc96fb1a4c15d69b83" + integrity sha512-dvgOrci9lZqpjpp0hoC3Zfedhg3aIpLFVDH0TdlKxRlkhR75hTrKTwxghDrQwE0bn3eKrC8RsN1m/JdnIWltpw== dependencies: cross-fetch "^2.1.1" eth-json-rpc-errors "^1.0.1" - eth-json-rpc-middleware "https://github.com/MetaMask/eth-json-rpc-middleware" + eth-json-rpc-middleware "^4.1.4" json-rpc-engine "^5.1.3" eth-json-rpc-middleware@^1.5.0: @@ -10445,27 +10434,7 @@ eth-json-rpc-middleware@^1.5.0: promise-to-callback "^1.0.0" tape "^4.6.3" -eth-json-rpc-middleware@^4.1.4, eth-json-rpc-middleware@^4.1.5: - version "4.2.0" - resolved "https://registry.yarnpkg.com/eth-json-rpc-middleware/-/eth-json-rpc-middleware-4.2.0.tgz#cfb77c5056cb8001548c6c7d54f4af5fce04d489" - integrity sha512-90LljqRyJhkg7fOwKunh1lu1Mr5bspXMBDitaTGyGPPNiFTbMrhtfbf9fteYlXRFCbq+aIFWwl/X+P7nkrdkLg== - dependencies: - btoa "^1.2.1" - clone "^2.1.1" - eth-json-rpc-errors "^1.0.1" - eth-query "^2.1.2" - eth-sig-util "^1.4.2" - ethereumjs-block "^1.6.0" - ethereumjs-tx "^1.3.7" - ethereumjs-util "^5.1.2" - ethereumjs-vm "^2.6.0" - fetch-ponyfill "^4.0.0" - json-rpc-engine "^5.1.3" - json-stable-stringify "^1.0.1" - pify "^3.0.0" - safe-event-emitter "^1.0.1" - -eth-json-rpc-middleware@^4.4.0, "eth-json-rpc-middleware@https://github.com/MetaMask/eth-json-rpc-middleware": +eth-json-rpc-middleware@^4.1.4, eth-json-rpc-middleware@^4.1.5, eth-json-rpc-middleware@^4.4.0: version "4.4.0" resolved "https://github.com/MetaMask/eth-json-rpc-middleware#a0f9d05b5f4e229621a9558c17fa4acb920de822" dependencies: @@ -10499,14 +10468,15 @@ eth-keyring-controller@^5.3.0: loglevel "^1.5.0" obs-store "^4.0.3" -"eth-keyring-controller@https://github.com/logvik/KeyringController": - version "5.3.1" - resolved "https://github.com/logvik/KeyringController#f0cec5b88e0b8955cef917bbf9bc45a0826570d0" +eth-keyring-controller@^5.4.0: + version "5.4.0" + resolved "https://registry.yarnpkg.com/eth-keyring-controller/-/eth-keyring-controller-5.4.0.tgz#c22711957c04af05bbd69801dbe38717430b27a9" + integrity sha512-nrMBo/nhZ1lDBH83JAklN28ci6hOP6XzhB+aQMasm9EddRSU6/dS4nCX5qtjyUA5Bm/UFrSHgZkG4k3eqdvKig== dependencies: bip39 "^2.4.0" bluebird "^3.5.0" browser-passworder "^2.0.3" - eth-hd-keyring "https://github.com/logvik/eth-hd-keyring" + eth-hd-keyring "^3.4.1" eth-sig-util "^1.4.0" eth-simple-keyring "^3.5.0" ethereumjs-util "^5.1.2" From 8630a22440be3ef621a0b7073d5dc01e4bd8632a Mon Sep 17 00:00:00 2001 From: kviktorov Date: Wed, 15 Jan 2020 21:45:23 +0300 Subject: [PATCH 06/23] fix for yarn, eth-json-rpc-middleware from NPM --- yarn.lock | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/yarn.lock b/yarn.lock index c7e1a85c4c85..ac9c21722ac7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10436,7 +10436,8 @@ eth-json-rpc-middleware@^1.5.0: eth-json-rpc-middleware@^4.1.4, eth-json-rpc-middleware@^4.1.5, eth-json-rpc-middleware@^4.4.0: version "4.4.0" - resolved "https://github.com/MetaMask/eth-json-rpc-middleware#a0f9d05b5f4e229621a9558c17fa4acb920de822" + resolved "https://registry.yarnpkg.com/eth-json-rpc-middleware/-/eth-json-rpc-middleware-4.4.0.tgz#ef63b783b48dcbea9c1fe25c79e6ea01510e5877" + integrity sha512-IeOsil/XiHsybJO9nFf86+1+YIqGQWPPfiTEp3WLkpLZhJm97kw6tFM7GttIZXIcwtaO3zEXgY6PWAH1jkB3ag== dependencies: btoa "^1.2.1" clone "^2.1.1" From b3e4c7c01c579666cfa211be29762dadce2e53cf Mon Sep 17 00:00:00 2001 From: kviktorov Date: Wed, 15 Jan 2020 22:18:55 +0300 Subject: [PATCH 07/23] fixes for i18n, mock-state, unapproved messages count --- app/_locales/en/messages.json | 15 +++------------ app/_locales/ru/messages.json | 15 +++------------ test/data/mock-state.json | 4 +++- ui/app/selectors/confirm-transaction.js | 2 ++ 4 files changed, 11 insertions(+), 25 deletions(-) diff --git a/app/_locales/en/messages.json b/app/_locales/en/messages.json index 873a672d8784..d445ed4696f0 100644 --- a/app/_locales/en/messages.json +++ b/app/_locales/en/messages.json @@ -1572,23 +1572,14 @@ "zeroGasPriceOnSpeedUpError": { "message": "Zero gas price on speed up" }, - "decryptRequest" : { + "decryptRequest": { "message": "Decrypt request" }, - "yourDecryptRequest" : { - "message": "Data decrypt" - }, - "yourEncryptionPublicKeyRequest" : { - "message": "Request encryption public key" - }, - "decrypt" : { + "decrypt": { "message": "Decrypt" }, - "youDecrypt": { - "message": "You are decrypting" - }, "decryptMessageNotice": { - "message": "$1 would like to read this message to complete your action" + "message": "$1 would like to read this message to complete your action" }, "decryptMetamask": { "message": "Decrypt with Metamask" diff --git a/app/_locales/ru/messages.json b/app/_locales/ru/messages.json index ae3776909e1f..c68f95b500c6 100644 --- a/app/_locales/ru/messages.json +++ b/app/_locales/ru/messages.json @@ -1359,23 +1359,14 @@ "yourPrivateSeedPhrase": { "message": "Ваша сид-фраза" }, - "decryptRequest" : { + "decryptRequest": { "message": "Запрос расшифровки" }, - "yourDecryptRequest" : { - "message": "Данные для расшифровки" - }, - "yourEncryptionPublicKeyRequest" : { - "message": "Запрос публичного ключа шифрования" - }, - "decrypt" : { + "decrypt": { "message": "Расшифровать" }, - "youDecrypt": { - "message": "Вы расшифровываете" - }, "decryptMessageNotice": { - "message": "Для $1 необходимо прочитать это сообщение, чтобы завершить Ваше действие" + "message": "Для $1 необходимо прочитать это сообщение, чтобы завершить Ваше действие" }, "decryptMetamask": { "message": "Расшифровать при помощи Metamask" diff --git a/test/data/mock-state.json b/test/data/mock-state.json index f5944b1851b7..6b4b732d6219 100644 --- a/test/data/mock-state.json +++ b/test/data/mock-state.json @@ -136,8 +136,10 @@ "unapprovedMsgCount": 0, "unapprovedPersonalMsgs": {}, "unapprovedPersonalMsgCount": 0, - "unapprovedDecryptMsgs": {}, + "unapprovedDecryptMsgs": {}, "unapprovedDecryptMsgCount": 0, + "unapprovedEncryptionPublicKeyMsgs": {}, + "unapprovedEncryptionPublicKeyMsgCount": 0, "unapprovedTypedMessages": {}, "unapprovedTypedMessagesCount": 0, "send": { diff --git a/ui/app/selectors/confirm-transaction.js b/ui/app/selectors/confirm-transaction.js index a23541106c92..3e1cdd2c0bb4 100644 --- a/ui/app/selectors/confirm-transaction.js +++ b/ui/app/selectors/confirm-transaction.js @@ -34,6 +34,7 @@ export const unconfirmedTransactionsListSelector = createSelector( unapprovedMsgs = {}, unapprovedPersonalMsgs = {}, unapprovedDecryptMsgs = {}, + unapprovedEncryptionPublicKeyMsgs = {}, unapprovedTypedMessages = {}, network ) => txHelper( @@ -41,6 +42,7 @@ export const unconfirmedTransactionsListSelector = createSelector( unapprovedMsgs, unapprovedPersonalMsgs, unapprovedDecryptMsgs, + unapprovedEncryptionPublicKeyMsgs, unapprovedTypedMessages, network ) || [] From 481656404a126c3fdc51862764b982991361ab22 Mon Sep 17 00:00:00 2001 From: kviktorov Date: Tue, 21 Jan 2020 19:04:47 +0300 Subject: [PATCH 08/23] updated version for eth-keyring-controller --- package.json | 2 +- yarn.lock | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 8f8ba6334ebd..554590d8e8f6 100644 --- a/package.json +++ b/package.json @@ -97,7 +97,7 @@ "eth-json-rpc-filters": "^4.1.1", "eth-json-rpc-infura": "^4.0.2", "eth-json-rpc-middleware": "^4.4.0", - "eth-keyring-controller": "^5.4.0", + "eth-keyring-controller": "^5.5.0", "eth-ledger-bridge-keyring": "^0.2.0", "eth-method-registry": "^1.2.0", "eth-phishing-detect": "^1.1.4", diff --git a/yarn.lock b/yarn.lock index 10d27d4ab8f1..11accf74a1dd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10348,7 +10348,7 @@ eth-ens-namehash@^1.0.2: idna-uts46 "^1.0.1" js-sha3 "^0.5.7" -eth-hd-keyring@^3.4.0, eth-hd-keyring@^3.4.1: +eth-hd-keyring@^3.4.0, eth-hd-keyring@^3.5.0: version "3.5.0" resolved "https://registry.yarnpkg.com/eth-hd-keyring/-/eth-hd-keyring-3.5.0.tgz#3976d83a27b24305481c389178f290d9264e839d" integrity sha512-Ix1LcWYxHMxCCSIMz+TLXLtt50zF6ZDd/TRVXthdw91IwOk1ajuf7QHg3bCDcfeUpdf9oEpwIPbL3xjDqEEjYw== @@ -10474,15 +10474,15 @@ eth-keyring-controller@^5.3.0: loglevel "^1.5.0" obs-store "^4.0.3" -eth-keyring-controller@^5.4.0: - version "5.4.0" - resolved "https://registry.yarnpkg.com/eth-keyring-controller/-/eth-keyring-controller-5.4.0.tgz#c22711957c04af05bbd69801dbe38717430b27a9" - integrity sha512-nrMBo/nhZ1lDBH83JAklN28ci6hOP6XzhB+aQMasm9EddRSU6/dS4nCX5qtjyUA5Bm/UFrSHgZkG4k3eqdvKig== +eth-keyring-controller@^5.5.0: + version "5.5.0" + resolved "https://registry.yarnpkg.com/eth-keyring-controller/-/eth-keyring-controller-5.5.0.tgz#f8b78f69a0b0005873af2d1a6b2c655d6de51351" + integrity sha512-kWaukiHLMYNYtB/1vZyj1r1G6wU8u+DIYVMq8QUyFAxwcBnemsKISVPIXgltgXkuUiB/t9oXsA54bWBredgrVg== dependencies: bip39 "^2.4.0" bluebird "^3.5.0" browser-passworder "^2.0.3" - eth-hd-keyring "^3.4.1" + eth-hd-keyring "^3.5.0" eth-sig-util "^1.4.0" eth-simple-keyring "^3.5.0" ethereumjs-util "^5.1.2" From 7499aede095383a34d5e4bfb3c99b13879fd0891 Mon Sep 17 00:00:00 2001 From: kviktorov Date: Tue, 21 Jan 2020 21:53:35 +0300 Subject: [PATCH 09/23] i18n issues are fixed --- app/_locales/en/messages.json | 6 +++--- app/_locales/ru/messages.json | 2 +- .../confirm-encryption-public-key.component.js | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/_locales/en/messages.json b/app/_locales/en/messages.json index d445ed4696f0..161142158469 100644 --- a/app/_locales/en/messages.json +++ b/app/_locales/en/messages.json @@ -1591,9 +1591,9 @@ "message": "Provide" }, "encryptionPublicKeyRequest": { - "message": "Request ecryption public key" + "message": "Request encryption public key" }, - "ecryptionPublickKeyNotice": { - "message": "By granted this encryption public key for Dapp you will allow to get encrypted messages and decrypt it via Metamask. This key can be used ONLY for encryption messages that decrypt via your private key. Dapp can't sign transaction or something else via this public key." + "encryptionPublicKeyNotice": { + "message": "Этот сайт запрашивает ваш открытый ключ шифрования. По согласованию, этот сайт сможет создавать для Вас зашифрованные сообщения." } } diff --git a/app/_locales/ru/messages.json b/app/_locales/ru/messages.json index c68f95b500c6..5e47c5ff6189 100644 --- a/app/_locales/ru/messages.json +++ b/app/_locales/ru/messages.json @@ -1380,7 +1380,7 @@ "encryptionPublicKeyRequest": { "message": "Запрос публичного ключа шифрования" }, - "ecryptionPublickKeyNotice": { + "encryptionPublicKeyNotice": { "message": "Предоставив этот открытый ключ шифрования для Dapp, вы сможете получать зашифрованные сообщения и расшифровывать их с помощью Metamask. Этот ключ можно использовать ТОЛЬКО для шифрования сообщений, которые расшифровываются с помощью вашего личного ключа. Dapp не может подписать транзакцию или что-то еще через этот открытый ключ." } } diff --git a/ui/app/pages/confirm-encryption-public-key/confirm-encryption-public-key.component.js b/ui/app/pages/confirm-encryption-public-key/confirm-encryption-public-key.component.js index 52051a32cdd2..871248f6780a 100644 --- a/ui/app/pages/confirm-encryption-public-key/confirm-encryption-public-key.component.js +++ b/ui/app/pages/confirm-encryption-public-key/confirm-encryption-public-key.component.js @@ -143,7 +143,7 @@ export default class ConfirmEncryptionPublicKey extends Component { } renderBody = () => { - const notice = this.context.t('ecryptionPublickKeyNotice') + const notice = this.context.t('encryptionPublicKeyNotice') return (
From c61033c874b7e34c89a36a735bdc8a67cd25eb6a Mon Sep 17 00:00:00 2001 From: kviktorov Date: Tue, 21 Jan 2020 22:12:28 +0300 Subject: [PATCH 10/23] the fix in wording --- app/_locales/en/messages.json | 2 +- app/_locales/ru/messages.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/_locales/en/messages.json b/app/_locales/en/messages.json index 161142158469..6e08f1bf2393 100644 --- a/app/_locales/en/messages.json +++ b/app/_locales/en/messages.json @@ -1594,6 +1594,6 @@ "message": "Request encryption public key" }, "encryptionPublicKeyNotice": { - "message": "Этот сайт запрашивает ваш открытый ключ шифрования. По согласованию, этот сайт сможет создавать для Вас зашифрованные сообщения." + "message": "This site would like your public encryption key. By consenting, this site will be able to compose encrypted messages to you." } } diff --git a/app/_locales/ru/messages.json b/app/_locales/ru/messages.json index 5e47c5ff6189..5b9349719694 100644 --- a/app/_locales/ru/messages.json +++ b/app/_locales/ru/messages.json @@ -1381,6 +1381,6 @@ "message": "Запрос публичного ключа шифрования" }, "encryptionPublicKeyNotice": { - "message": "Предоставив этот открытый ключ шифрования для Dapp, вы сможете получать зашифрованные сообщения и расшифровывать их с помощью Metamask. Этот ключ можно использовать ТОЛЬКО для шифрования сообщений, которые расшифровываются с помощью вашего личного ключа. Dapp не может подписать транзакцию или что-то еще через этот открытый ключ." + "message": "Этот сайт запрашивает ваш открытый ключ шифрования. По согласованию, этот сайт сможет создавать для Вас зашифрованные сообщения." } } From 774bc54f494c2f892696c403496895705b21ee94 Mon Sep 17 00:00:00 2001 From: kviktorov Date: Tue, 28 Jan 2020 19:41:10 +0300 Subject: [PATCH 11/23] fixed quotes for lint --- app/scripts/controllers/permissions/enums.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/scripts/controllers/permissions/enums.js b/app/scripts/controllers/permissions/enums.js index fe81fb54cd20..56cbf187f5d5 100644 --- a/app/scripts/controllers/permissions/enums.js +++ b/app/scripts/controllers/permissions/enums.js @@ -69,6 +69,6 @@ export const SAFE_METHODS = [ 'eth_uninstallFilter', 'metamask_watchAsset', 'wallet_watchAsset', - "encryption_public_key", - "eth_decryptMessage", + 'encryption_public_key', + 'eth_decryptMessage', ] From cb1dad92018609494c46a2c691e52e2decdc2b1d Mon Sep 17 00:00:00 2001 From: kviktorov Date: Wed, 29 Jan 2020 21:49:21 +0300 Subject: [PATCH 12/23] 1) fixed bug when the message for decryption is empty 2) coping decrypted message is available only after inline decryption 3) name of the requesting site on the public key request --- app/_locales/en/messages.json | 2 +- app/_locales/ru/messages.json | 2 +- .../lib/encryption-public-key-manager.js | 5 +++ .../request-encryption-public-key.scss | 32 ++++++++++++++ .../confirm-decrypt-message.component.js | 44 +++++++++++-------- ...confirm-encryption-public-key.component.js | 26 +++++++++-- ...confirm-encryption-public-key.container.js | 6 ++- ui/app/store/actions.js | 12 +++-- yarn.lock | 27 ------------ 9 files changed, 101 insertions(+), 55 deletions(-) diff --git a/app/_locales/en/messages.json b/app/_locales/en/messages.json index 075c0bff2823..43dc02b266f3 100644 --- a/app/_locales/en/messages.json +++ b/app/_locales/en/messages.json @@ -1620,6 +1620,6 @@ "message": "Request encryption public key" }, "encryptionPublicKeyNotice": { - "message": "This site would like your public encryption key. By consenting, this site will be able to compose encrypted messages to you." + "message": "$1 would like your public encryption key. By consenting, this site will be able to compose encrypted messages to you." } } diff --git a/app/_locales/ru/messages.json b/app/_locales/ru/messages.json index 515648f6196a..ac55e5e17995 100644 --- a/app/_locales/ru/messages.json +++ b/app/_locales/ru/messages.json @@ -1372,6 +1372,6 @@ "message": "Запрос публичного ключа шифрования" }, "encryptionPublicKeyNotice": { - "message": "Этот сайт запрашивает ваш открытый ключ шифрования. По согласованию, этот сайт сможет создавать для Вас зашифрованные сообщения." + "message": "$1 запрашивает ваш открытый ключ шифрования. По согласованию, этот сайт сможет создавать для Вас зашифрованные сообщения." } } diff --git a/app/scripts/lib/encryption-public-key-manager.js b/app/scripts/lib/encryption-public-key-manager.js index e4b4fe3c2835..4063887241df 100644 --- a/app/scripts/lib/encryption-public-key-manager.js +++ b/app/scripts/lib/encryption-public-key-manager.js @@ -117,6 +117,11 @@ export default class EncryptionPublicKeyManager extends EventEmitter { status: 'unapproved', type: 'encryption_public_key', } + + if (_req) { + msgData.origin = _req.origin + } + this.addMsg(msgData) // signal update diff --git a/ui/app/css/itcss/components/request-encryption-public-key.scss b/ui/app/css/itcss/components/request-encryption-public-key.scss index f407037b4f99..36865a147400 100644 --- a/ui/app/css/itcss/components/request-encryption-public-key.scss +++ b/ui/app/css/itcss/components/request-encryption-public-key.scss @@ -187,4 +187,36 @@ margin-right: 1.2rem; } } + + &__visual { + display: flex; + flex-direction: row; + justify-content: space-evenly; + position: relative; + margin: 0 20px; + + section { + display: flex; + flex-direction: column; + align-items: center; + flex: 1; + } + + &-identicon { + width: 48px; + height: 48px; + + &--default { + background-color: #777A87; + color: white; + width: 48px; + height: 48px; + border-radius: 24px; + display: flex; + align-items: center; + justify-content: center; + font-weight: bold; + } + } + } } diff --git a/ui/app/pages/confirm-decrypt-message/confirm-decrypt-message.component.js b/ui/app/pages/confirm-decrypt-message/confirm-decrypt-message.component.js index 8765572ce7f3..e907c600f597 100644 --- a/ui/app/pages/confirm-decrypt-message/confirm-decrypt-message.component.js +++ b/ui/app/pages/confirm-decrypt-message/confirm-decrypt-message.component.js @@ -237,28 +237,34 @@ export default class ConfirmDecryptMessage extends Component {
-
this.copyMessage()} - onMouseDown={() => this.setState({ copyToClipboardPressed: true })} - onMouseUp={() => this.setState({ copyToClipboardPressed: false })} - > - + { hasDecrypted ? + (
this.copyMessage()} + onMouseDown={() => this.setState({ copyToClipboardPressed: true })} + onMouseUp={() => this.setState({ copyToClipboardPressed: false })} > - {this.context.t('decryptCopy')} + +
+ {this.context.t('decryptCopy')} +
+ +
- -
-
+ ) + : +
+ }
) } diff --git a/ui/app/pages/confirm-encryption-public-key/confirm-encryption-public-key.component.js b/ui/app/pages/confirm-encryption-public-key/confirm-encryption-public-key.component.js index 871248f6780a..a9eafe2ef2d7 100644 --- a/ui/app/pages/confirm-encryption-public-key/confirm-encryption-public-key.component.js +++ b/ui/app/pages/confirm-encryption-public-key/confirm-encryption-public-key.component.js @@ -25,6 +25,7 @@ export default class ConfirmEncryptionPublicKey extends Component { requesterAddress: PropTypes.string, selectedAccount: PropTypes.object, txData: PropTypes.object, + domainMetadata: PropTypes.object, } state = { @@ -143,15 +144,34 @@ export default class ConfirmEncryptionPublicKey extends Component { } renderBody = () => { - const notice = this.context.t('encryptionPublicKeyNotice') + const { txData } = this.props + + const origin = this.props.domainMetadata[txData.origin] + const notice = this.context.t('encryptionPublicKeyNotice', ['[' + origin.name + ']']) return (
{ this.renderAccountInfo() }
- { notice } +
+ {origin.icon ? ( + + ) : ( + + {origin.name.charAt(0).toUpperCase()} + + )} +
+ { notice } +
+
) diff --git a/ui/app/pages/confirm-encryption-public-key/confirm-encryption-public-key.container.js b/ui/app/pages/confirm-encryption-public-key/confirm-encryption-public-key.container.js index 99895b30dbf2..0ee36f78907a 100644 --- a/ui/app/pages/confirm-encryption-public-key/confirm-encryption-public-key.container.js +++ b/ui/app/pages/confirm-encryption-public-key/confirm-encryption-public-key.container.js @@ -13,13 +13,17 @@ import { clearConfirmTransaction } from '../../ducks/confirm-transaction/confirm import ConfirmEncryptionPublicKey from './confirm-encryption-public-key.component' function mapStateToProps (state) { - const { confirmTransaction } = state + const { confirmTransaction, + metamask: { domainMetadata = {} }, + } = state + const { txData = {}, } = confirmTransaction return { txData: txData, + domainMetadata: domainMetadata, balance: getSelectedAccount(state).balance, selectedAccount: getCurrentAccountWithSendEtherInfo(state), selectedAddress: getSelectedAddress(state), diff --git a/ui/app/store/actions.js b/ui/app/store/actions.js index bcee6be9050a..a3ccbdfad3f3 100644 --- a/ui/app/store/actions.js +++ b/ui/app/store/actions.js @@ -652,9 +652,15 @@ export function decryptMsgInline (msgData) { return new Promise((resolve, reject) => { log.debug(`actions calling background.decryptMessageInline`) background.decryptMessageInline(msgData, (err, newState) => { - log.debug('decryptMsg called back') - dispatch(updateMetamaskState(newState)) - msgData = newState.unapprovedDecryptMsgs[msgData.metamaskId] + log.debug('decryptMsgInline called back') + if (newState) { + msgData = newState.unapprovedDecryptMsgs[msgData.metamaskId] + dispatch(updateMetamaskState(newState)) + } else { + log.error('Wrong data for decryptMessageInline') + dispatch(displayWarning('Wrong data')) + return reject({ 'message': 'Wrong data' }) + } if (err) { log.error(err) dispatch(displayWarning(err.message)) diff --git a/yarn.lock b/yarn.lock index 7facf190ce56..6192290822a9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -12835,33 +12835,6 @@ gaba@^1.6.0, gaba@^1.9.3: web3 "^0.20.7" web3-provider-engine "^15.0.4" -gaba@^1.9.1: - version "1.9.1" - resolved "https://registry.yarnpkg.com/gaba/-/gaba-1.9.1.tgz#2e096889aca74eb5946b55a3922427314b5dca22" - integrity sha512-YsKG4+Ql3D6v4cnMgH7P8c9JqQb74y6gkIhySLd1BYwFZQTXn27u16cYfoxPtqeGfTFhus9h4CpxAr8s8bsvCA== - dependencies: - await-semaphore "^0.1.3" - eth-contract-metadata "^1.11.0" - eth-ens-namehash "^2.0.8" - eth-json-rpc-infura "^4.0.1" - eth-keyring-controller "^5.3.0" - eth-method-registry "1.1.0" - eth-phishing-detect "^1.1.13" - eth-query "^2.1.2" - eth-sig-util "^2.3.0" - ethereumjs-util "^6.1.0" - ethereumjs-wallet "0.6.0" - ethjs-query "^0.3.8" - human-standard-collectible-abi "^1.0.2" - human-standard-token-abi "^2.0.0" - isomorphic-fetch "^2.2.1" - jsonschema "^1.2.4" - percentile "^1.2.1" - single-call-balance-checker-abi "^1.0.0" - uuid "^3.3.2" - web3 "^0.20.7" - web3-provider-engine "^15.0.4" - ganache-cli@^6.4.4: version "6.4.4" resolved "https://registry.yarnpkg.com/ganache-cli/-/ganache-cli-6.4.4.tgz#9772bba8585d6e2049bd85adf24369c1cc165170" From 4959c311624e0580491e5c3d34267be23e600ca0 Mon Sep 17 00:00:00 2001 From: kviktorov Date: Tue, 4 Feb 2020 11:17:24 +0300 Subject: [PATCH 13/23] removed unnecessary methods for 3box --- app/scripts/controllers/threebox.js | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/app/scripts/controllers/threebox.js b/app/scripts/controllers/threebox.js index ebbe46701b14..9bd1ede74737 100644 --- a/app/scripts/controllers/threebox.js +++ b/app/scripts/controllers/threebox.js @@ -50,16 +50,6 @@ class ThreeBoxController { withAppKeyOrigin: 'wallet://3box.metamask.io', }) }, - processDecryptMessage: (msgParams) => { - return Promise.resolve(keyringController.decryptMessage(msgParams, { - withAppKeyOrigin: 'wallet://3box.metamask.io', - })) - }, - processEncryptionPublicKey: (msgParams) => { - return Promise.resolve(keyringController.encryptionPublicKey, (msgParams, { - withAppKeyOrigin: 'wallet://3box.metamask.io', - })) - }, }) const initState = { From 5b99d09be4ceb977b308de60116d01e95e7d5d69 Mon Sep 17 00:00:00 2001 From: kviktorov Date: Tue, 4 Feb 2020 18:53:25 +0300 Subject: [PATCH 14/23] package.json and yarn.lock are given by the origin --- package.json | 2 +- yarn.lock | 61 +++++++++++++++++++--------------------------------- 2 files changed, 23 insertions(+), 40 deletions(-) diff --git a/package.json b/package.json index 8885e6d4f651..06794d9dcd97 100644 --- a/package.json +++ b/package.json @@ -220,7 +220,7 @@ "ganache-core": "2.8.0", "geckodriver": "^1.19.1", "get-port": "^5.1.0", - "gulp": "^4.0.2", + "gulp": "^4.0.0", "gulp-autoprefixer": "^5.0.0", "gulp-babel": "^7.0.0", "gulp-debug": "^3.2.0", diff --git a/yarn.lock b/yarn.lock index 31b6284b389e..aaf546002d81 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10565,16 +10565,6 @@ eth-json-rpc-infura@^4.0.1, eth-json-rpc-infura@^4.0.2: eth-json-rpc-middleware "^4.1.4" json-rpc-engine "^5.1.3" -eth-json-rpc-infura@^4.0.2: - version "4.0.2" - resolved "https://registry.yarnpkg.com/eth-json-rpc-infura/-/eth-json-rpc-infura-4.0.2.tgz#8af1a1a2e9a0a82aaa302bbc96fb1a4c15d69b83" - integrity sha512-dvgOrci9lZqpjpp0hoC3Zfedhg3aIpLFVDH0TdlKxRlkhR75hTrKTwxghDrQwE0bn3eKrC8RsN1m/JdnIWltpw== - dependencies: - cross-fetch "^2.1.1" - eth-json-rpc-errors "^1.0.1" - eth-json-rpc-middleware "^4.1.4" - json-rpc-engine "^5.1.3" - eth-json-rpc-middleware@^1.5.0: version "1.6.0" resolved "https://registry.yarnpkg.com/eth-json-rpc-middleware/-/eth-json-rpc-middleware-1.6.0.tgz#5c9d4c28f745ccb01630f0300ba945f4bef9593f" @@ -10594,7 +10584,27 @@ eth-json-rpc-middleware@^1.5.0: promise-to-callback "^1.0.0" tape "^4.6.3" -eth-json-rpc-middleware@^4.1.4, eth-json-rpc-middleware@^4.1.5, eth-json-rpc-middleware@^4.4.0: +eth-json-rpc-middleware@^4.1.4, eth-json-rpc-middleware@^4.1.5: + version "4.2.0" + resolved "https://registry.yarnpkg.com/eth-json-rpc-middleware/-/eth-json-rpc-middleware-4.2.0.tgz#cfb77c5056cb8001548c6c7d54f4af5fce04d489" + integrity sha512-90LljqRyJhkg7fOwKunh1lu1Mr5bspXMBDitaTGyGPPNiFTbMrhtfbf9fteYlXRFCbq+aIFWwl/X+P7nkrdkLg== + dependencies: + btoa "^1.2.1" + clone "^2.1.1" + eth-json-rpc-errors "^1.0.1" + eth-query "^2.1.2" + eth-sig-util "^1.4.2" + ethereumjs-block "^1.6.0" + ethereumjs-tx "^1.3.7" + ethereumjs-util "^5.1.2" + ethereumjs-vm "^2.6.0" + fetch-ponyfill "^4.0.0" + json-rpc-engine "^5.1.3" + json-stable-stringify "^1.0.1" + pify "^3.0.0" + safe-event-emitter "^1.0.1" + +eth-json-rpc-middleware@^4.4.0: version "4.4.0" resolved "https://registry.yarnpkg.com/eth-json-rpc-middleware/-/eth-json-rpc-middleware-4.4.0.tgz#ef63b783b48dcbea9c1fe25c79e6ea01510e5877" integrity sha512-IeOsil/XiHsybJO9nFf86+1+YIqGQWPPfiTEp3WLkpLZhJm97kw6tFM7GttIZXIcwtaO3zEXgY6PWAH1jkB3ag== @@ -10629,21 +10639,6 @@ eth-keyring-controller@^5.3.0, eth-keyring-controller@^5.5.0: loglevel "^1.5.0" obs-store "^4.0.3" -eth-keyring-controller@^5.5.0: - version "5.5.0" - resolved "https://registry.yarnpkg.com/eth-keyring-controller/-/eth-keyring-controller-5.5.0.tgz#f8b78f69a0b0005873af2d1a6b2c655d6de51351" - integrity sha512-kWaukiHLMYNYtB/1vZyj1r1G6wU8u+DIYVMq8QUyFAxwcBnemsKISVPIXgltgXkuUiB/t9oXsA54bWBredgrVg== - dependencies: - bip39 "^2.4.0" - bluebird "^3.5.0" - browser-passworder "^2.0.3" - eth-hd-keyring "^3.5.0" - eth-sig-util "^1.4.0" - eth-simple-keyring "^3.5.0" - ethereumjs-util "^5.1.2" - loglevel "^1.5.0" - obs-store "^4.0.3" - eth-ledger-bridge-keyring@^0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/eth-ledger-bridge-keyring/-/eth-ledger-bridge-keyring-0.2.0.tgz#715de14da24496c35cdb433022a20bd21b984f7e" @@ -10757,18 +10752,6 @@ eth-simple-keyring@^3.4.0, eth-simple-keyring@^3.5.0: events "^1.1.1" xtend "^4.0.1" -eth-simple-keyring@^3.5.0: - version "3.5.0" - resolved "https://registry.yarnpkg.com/eth-simple-keyring/-/eth-simple-keyring-3.5.0.tgz#c7fa285ca58d31ef44bc7db678b689f9ffd7b453" - integrity sha512-z9IPt9aoMWAw5Zc3Jk/HKbWPJNc7ivZ5ECNtl3ZoQUGRnwoWO71W5+liVPJtXFNacGOOGsBfqTqrXL9C4EnYYQ== - dependencies: - eth-sig-util "^2.5.0" - ethereumjs-abi "^0.6.5" - ethereumjs-util "^5.1.1" - ethereumjs-wallet "^0.6.0" - events "^1.1.1" - xtend "^4.0.1" - eth-token-tracker@^1.1.10: version "1.1.10" resolved "https://registry.yarnpkg.com/eth-token-tracker/-/eth-token-tracker-1.1.10.tgz#3899a33cc442c0405e3923e71e0eff530bd1258b" @@ -13684,7 +13667,7 @@ gulp-zip@^4.0.0: vinyl "^2.1.0" yazl "^2.1.0" -gulp@^4.0.2: +gulp@^4.0.0, gulp@^4.0.2: version "4.0.2" resolved "https://registry.yarnpkg.com/gulp/-/gulp-4.0.2.tgz#543651070fd0f6ab0a0650c6a3e6ff5a7cb09caa" integrity sha512-dvEs27SCZt2ibF29xYgmnwwCYZxdxhQ/+LFWlbAW8y7jt68L/65402Lz3+CKy0Ov4rOs+NERmDq7YlZaDqUIfA== From 895d83350f64ea0b9f126260574e165748ca38cf Mon Sep 17 00:00:00 2001 From: kviktorov Date: Tue, 4 Feb 2020 23:37:51 +0300 Subject: [PATCH 15/23] fixes after Gudahtt reviewing --- app/_locales/en/messages.json | 6 +- app/_locales/ru/messages.json | 8 ++- app/scripts/background.js | 2 + app/scripts/lib/decrypt-message-manager.js | 5 +- .../lib/encryption-public-key-manager.js | 3 +- app/scripts/metamask-controller.js | 55 +++++++++---------- 6 files changed, 38 insertions(+), 41 deletions(-) diff --git a/app/_locales/en/messages.json b/app/_locales/en/messages.json index 031ad461424b..89398605b35d 100644 --- a/app/_locales/en/messages.json +++ b/app/_locales/en/messages.json @@ -1611,7 +1611,8 @@ "message": "Decrypt" }, "decryptMessageNotice": { - "message": "$1 would like to read this message to complete your action" + "message": "$1 would like to read this message to complete your action", + "description": "$1 is website or dapp name" }, "decryptMetamask": { "message": "Decrypt with Metamask" @@ -1626,6 +1627,7 @@ "message": "Request encryption public key" }, "encryptionPublicKeyNotice": { - "message": "$1 would like your public encryption key. By consenting, this site will be able to compose encrypted messages to you." + "message": "$1 would like your public encryption key. By consenting, this site will be able to compose encrypted messages to you.", + "description": "$1 is website or dapp name" } } diff --git a/app/_locales/ru/messages.json b/app/_locales/ru/messages.json index ac55e5e17995..0877dab7f8a7 100644 --- a/app/_locales/ru/messages.json +++ b/app/_locales/ru/messages.json @@ -1054,7 +1054,7 @@ }, "restoreWalletPreferences": { "message": "Были найдены данные экспортированные от $1. Вы желаете восстановить настройки вашего кошелька?", - "description": "$1 это дата в которую данные были экспортированы" + "description": "$1 is the date at which the data was backed up" }, "requestsAwaitingAcknowledgement": { "message": "запросы, ожидающие подтверждения" @@ -1357,7 +1357,8 @@ "message": "Расшифровать" }, "decryptMessageNotice": { - "message": "Для $1 необходимо прочитать это сообщение, чтобы завершить Ваше действие" + "message": "Для $1 необходимо прочитать это сообщение, чтобы завершить Ваше действие", + "description": "$1 is website or dapp name" }, "decryptMetamask": { "message": "Расшифровать при помощи Metamask" @@ -1372,6 +1373,7 @@ "message": "Запрос публичного ключа шифрования" }, "encryptionPublicKeyNotice": { - "message": "$1 запрашивает ваш открытый ключ шифрования. По согласованию, этот сайт сможет создавать для Вас зашифрованные сообщения." + "message": "$1 запрашивает ваш открытый ключ шифрования. По согласованию, этот сайт сможет создавать для Вас зашифрованные сообщения.", + "description": "$1 is website or dapp name" } } diff --git a/app/scripts/background.js b/app/scripts/background.js index e67668465072..d1e93a9d9695 100644 --- a/app/scripts/background.js +++ b/app/scripts/background.js @@ -127,6 +127,8 @@ initialize().catch(log.error) * @property {number} unapprovedMsgCount - The number of messages in unapprovedMsgs. * @property {Object} unapprovedPersonalMsgs - An object of messages associated with the currently selected account, mapping a unique ID to the options. * @property {number} unapprovedPersonalMsgCount - The number of messages in unapprovedPersonalMsgs. + * @property {Object} EncryptionPublicKeyMsgs - An object of messages associated with the currently selected account, mapping a unique ID to the options. + * @property {number} unapprovedEncryptionPublicKeyMsgCount - The number of messages in EncryptionPublicKeyMsgs. * @property {Object} unapprovedDecryptMsgs - An object of messages associated with the currently selected account, mapping a unique ID to the options. * @property {number} unapprovedDecryptMsgCount - The number of messages in unapprovedDecryptMsgs. * @property {Object} unapprovedTypedMsgs - An object of messages associated with the currently selected account, mapping a unique ID to the options. diff --git a/app/scripts/lib/decrypt-message-manager.js b/app/scripts/lib/decrypt-message-manager.js index 357e9a47661b..812532ed78e7 100644 --- a/app/scripts/lib/decrypt-message-manager.js +++ b/app/scripts/lib/decrypt-message-manager.js @@ -11,8 +11,6 @@ import log from 'loglevel' * Represents, and contains data about, an 'eth_decryptMessage' type decryption request. These are created when a * decryption for an eth_decryptMessage call is requested. * - * @see {@link https://web3js.readthedocs.io/en/1.0/web3-eth-Decrypt.html#decrypt} - * * @typedef {Object} DecryptMessage * @property {number} id An id to track and identify the message object * @property {Object} msgParams The parameters to pass to the decryptMessage method once the decryption request is @@ -31,7 +29,6 @@ export default class DecryptMessageManager extends EventEmitter { * Controller in charge of managing - storing, adding, removing, updating - DecryptMessage. * * @typedef {Object} DecryptMessageManager - * @param {Object} opts @deprecated * @property {Object} memStore The observable store where DecryptMessage are saved with persistance. * @property {Object} memStore.unapprovedDecryptMsgs A collection of all DecryptMessages in the 'unapproved' state * @property {number} memStore.unapprovedDecryptMsgCount The count of all DecryptMessages in this.memStore.unapprobedMsgs @@ -78,7 +75,7 @@ export default class DecryptMessageManager extends EventEmitter { * * @param {Object} msgParams The params for the eth_decryptMessage call to be made after the message is approved. * @param {Object} req (optional) The original request object possibly containing the origin - * @returns {promise} When the message has been approved or rejected + * @returns {Promise} The raw decrypted message contents * */ addUnapprovedMessageAsync (msgParams, req) { diff --git a/app/scripts/lib/encryption-public-key-manager.js b/app/scripts/lib/encryption-public-key-manager.js index 4063887241df..d0016c7ca796 100644 --- a/app/scripts/lib/encryption-public-key-manager.js +++ b/app/scripts/lib/encryption-public-key-manager.js @@ -26,7 +26,6 @@ export default class EncryptionPublicKeyManager extends EventEmitter { * Controller in charge of managing - storing, adding, removing, updating - EncryptionPublicKey. * * @typedef {Object} EncryptionPublicKeyManager - * @param {Object} opts @deprecated * @property {Object} memStore The observable store where EncryptionPublicKey are saved with persistance. * @property {Object} memStore.unapprovedEncryptionPublicKeyMsgs A collection of all EncryptionPublicKeys in the 'unapproved' state * @property {number} memStore.unapprovedEncryptionPublicKeyMsgCount The count of all EncryptionPublicKeys in this.memStore.unapprobedMsgs @@ -73,7 +72,7 @@ export default class EncryptionPublicKeyManager extends EventEmitter { * * @param {Object} address The param for the encryption_public_key call to be made after the message is approved. * @param {Object} req (optional) The original request object possibly containing the origin - * @returns {promise} When the message has been approved or rejected + * @returns {Promise} The raw public key contents * */ addUnapprovedMessageAsync (address, req) { diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 58e0eed28dbc..0a41d61eaacd 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -1191,7 +1191,7 @@ export default class MetamaskController extends EventEmitter { * Called when a dapp uses the eth_decryptMessage method. * * @param {Object} msgParams - The params of the message to sign & return to the Dapp. - * @param {Function} cb - The callback function called with the signature. + * @param {Object} req - (optional) the original request, containing the origin * Passed back to the requesting Dapp. */ async newRequestDecryptMessage (msgParams, req) { @@ -1204,7 +1204,7 @@ export default class MetamaskController extends EventEmitter { /** * Only decypt message and don't touch transaction state * - * @param {Object} msgParams - The params of the message to decrypt & return to the Dapp. + * @param {Object} msgParams - The params of the message to decrypt. * @returns {Promise} - A full state update. */ decryptMessageInline (msgParams) { @@ -1229,26 +1229,23 @@ export default class MetamaskController extends EventEmitter { * @param {Object} msgParams - The params of the message to decrypt & return to the Dapp. * @returns {Promise} - A full state update. */ - decryptMessage (msgParams) { + async decryptMessage (msgParams) { log.info('MetaMaskController - decryptMessage') const msgId = msgParams.metamaskId // sets the status op the message to 'approved' // and removes the metamaskId for decryption try { - return this.decryptMessageManager.approveMessage(msgParams) - .then((cleanMsgParams) => { - const stripped = ethUtil.stripHexPrefix(cleanMsgParams.data) - const buff = Buffer.from(stripped, 'hex') - cleanMsgParams.data = JSON.parse(buff.toString('utf8')) - // decrypt the message - return this.keyringController.decryptMessage(cleanMsgParams) - }) - .then((rawMess) => { - // tells the listener that the message has been decrypted - // and can be returned to the dapp - this.decryptMessageManager.setMsgStatusDecrypted(msgId, rawMess) - return this.getState() - }) + const cleanMsgParams = await this.decryptMessageManager.approveMessage(msgParams) + + const stripped = ethUtil.stripHexPrefix(cleanMsgParams.data) + const buff = Buffer.from(stripped, 'hex') + cleanMsgParams.data = JSON.parse(buff.toString('utf8')) + + // decrypt the message + const rawMess = await this.keyringController.decryptMessage(cleanMsgParams) + // tells the listener that the message has been decrypted and can be returned to the dapp + this.decryptMessageManager.setMsgStatusDecrypted(msgId, rawMess) + return this.getState() } catch (error) { log.info('MetaMaskController - eth_decryptMessage failed.', error) this.decryptMessageManager.errorMessage(msgId, error) @@ -1274,7 +1271,7 @@ export default class MetamaskController extends EventEmitter { * Called when a dapp uses the encryption_public_key method. * * @param {Object} msgParams - The params of the message to sign & return to the Dapp. - * @param {Function} cb - The callback function called with the signature. + * @param {Object} req - (optional) the original request, containing the origin * Passed back to the requesting Dapp. */ async newRequestEncryptionPublicKey (msgParams, req) { @@ -1291,23 +1288,21 @@ export default class MetamaskController extends EventEmitter { * @param {Object} msgParams - The params of the message to receive & return to the Dapp. * @returns {Promise} - A full state update. */ - encryptionPublicKey (msgParams) { + async encryptionPublicKey (msgParams) { log.info('MetaMaskController - encryptionPublicKey') const msgId = msgParams.metamaskId // sets the status op the message to 'approved' // and removes the metamaskId for decryption try { - return this.encryptionPublicKeyManager.approveMessage(msgParams) - .then((params) => { - // EncryptionPublicKey message - return this.keyringController.getEncryptionPublicKey(params.data) - }) - .then((publicKey) => { - // tells the listener that the message has been processed - // and can be returned to the dapp - this.encryptionPublicKeyManager.setMsgStatusReceived(msgId, publicKey) - return this.getState() - }) + const params = await this.encryptionPublicKeyManager.approveMessage(msgParams) + + // EncryptionPublicKey message + const publicKey = await this.keyringController.getEncryptionPublicKey(params.data) + + // tells the listener that the message has been processed + // and can be returned to the dapp + this.encryptionPublicKeyManager.setMsgStatusReceived(msgId, publicKey) + return this.getState() } catch (error) { log.info('MetaMaskController - encryption_public_key failed.', error) this.encryptionPublicKeyManager.errorMessage(msgId, error) From 73c2aa109d14f8cbcf2ae3bea69b0d79392f3516 Mon Sep 17 00:00:00 2001 From: kviktorov Date: Wed, 5 Feb 2020 21:48:13 +0300 Subject: [PATCH 16/23] fix for the last review by Gudahtt --- app/_locales/en/messages.json | 6 ++-- app/_locales/ru/messages.json | 6 ++-- .../components/request-decrypt-message.scss | 1 + .../confirm-decrypt-message.component.js | 2 +- .../confirm-decrypt-message.container.js | 10 +----- ...confirm-encryption-public-key.component.js | 2 +- ...confirm-encryption-public-key.container.js | 10 +----- .../confirm-transaction.component.js | 4 +-- ui/app/store/actions.js | 33 ++++++------------- 9 files changed, 23 insertions(+), 51 deletions(-) diff --git a/app/_locales/en/messages.json b/app/_locales/en/messages.json index 89398605b35d..859867f29abc 100644 --- a/app/_locales/en/messages.json +++ b/app/_locales/en/messages.json @@ -1612,10 +1612,10 @@ }, "decryptMessageNotice": { "message": "$1 would like to read this message to complete your action", - "description": "$1 is website or dapp name" + "description": "$1 is website or dapp name" }, "decryptMetamask": { - "message": "Decrypt with Metamask" + "message": "Decrypt message" }, "decryptCopy": { "message": "Copy encrypted message" @@ -1628,6 +1628,6 @@ }, "encryptionPublicKeyNotice": { "message": "$1 would like your public encryption key. By consenting, this site will be able to compose encrypted messages to you.", - "description": "$1 is website or dapp name" + "description": "$1 is website or dapp name" } } diff --git a/app/_locales/ru/messages.json b/app/_locales/ru/messages.json index 0877dab7f8a7..7428fcb150fe 100644 --- a/app/_locales/ru/messages.json +++ b/app/_locales/ru/messages.json @@ -1358,10 +1358,10 @@ }, "decryptMessageNotice": { "message": "Для $1 необходимо прочитать это сообщение, чтобы завершить Ваше действие", - "description": "$1 is website or dapp name" + "description": "$1 is website or dapp name" }, "decryptMetamask": { - "message": "Расшифровать при помощи Metamask" + "message": "Расшифровать сообщение" }, "decryptCopy": { "message": "Скопировать расшифрованное сообщение" @@ -1374,6 +1374,6 @@ }, "encryptionPublicKeyNotice": { "message": "$1 запрашивает ваш открытый ключ шифрования. По согласованию, этот сайт сможет создавать для Вас зашифрованные сообщения.", - "description": "$1 is website or dapp name" + "description": "$1 is website or dapp name" } } diff --git a/ui/app/css/itcss/components/request-decrypt-message.scss b/ui/app/css/itcss/components/request-decrypt-message.scss index 7b92ffd6e54d..66acefa0c6df 100644 --- a/ui/app/css/itcss/components/request-decrypt-message.scss +++ b/ui/app/css/itcss/components/request-decrypt-message.scss @@ -221,6 +221,7 @@ } &-copy { + justify-content: space-evenly; font-size: 0.75em; margin-left: 20px; margin-right: 20px; diff --git a/ui/app/pages/confirm-decrypt-message/confirm-decrypt-message.component.js b/ui/app/pages/confirm-decrypt-message/confirm-decrypt-message.component.js index e907c600f597..10602138bfc3 100644 --- a/ui/app/pages/confirm-decrypt-message/confirm-decrypt-message.component.js +++ b/ui/app/pages/confirm-decrypt-message/confirm-decrypt-message.component.js @@ -166,7 +166,7 @@ export default class ConfirmDecryptMessage extends Component { const { txData } = this.props const origin = this.props.domainMetadata[txData.msgParams.origin] - const notice = this.context.t('decryptMessageNotice', ['[' + origin.name + ']']) + const notice = this.context.t('decryptMessageNotice', [origin.name]) const { hasCopied, diff --git a/ui/app/pages/confirm-decrypt-message/confirm-decrypt-message.container.js b/ui/app/pages/confirm-decrypt-message/confirm-decrypt-message.container.js index ebdb00f53dea..8bc561a3fc40 100644 --- a/ui/app/pages/confirm-decrypt-message/confirm-decrypt-message.container.js +++ b/ui/app/pages/confirm-decrypt-message/confirm-decrypt-message.container.js @@ -56,15 +56,7 @@ function mapDispatchToProps (dispatch) { } } -function mergeProps (stateProps, dispatchProps, ownProps) { - return { - ...ownProps, - ...stateProps, - ...dispatchProps, - } -} - export default compose( withRouter, - connect(mapStateToProps, mapDispatchToProps, mergeProps) + connect(mapStateToProps, mapDispatchToProps) )(ConfirmDecryptMessage) diff --git a/ui/app/pages/confirm-encryption-public-key/confirm-encryption-public-key.component.js b/ui/app/pages/confirm-encryption-public-key/confirm-encryption-public-key.component.js index a9eafe2ef2d7..d06305fd9493 100644 --- a/ui/app/pages/confirm-encryption-public-key/confirm-encryption-public-key.component.js +++ b/ui/app/pages/confirm-encryption-public-key/confirm-encryption-public-key.component.js @@ -147,7 +147,7 @@ export default class ConfirmEncryptionPublicKey extends Component { const { txData } = this.props const origin = this.props.domainMetadata[txData.origin] - const notice = this.context.t('encryptionPublicKeyNotice', ['[' + origin.name + ']']) + const notice = this.context.t('encryptionPublicKeyNotice', [origin.name]) return (
diff --git a/ui/app/pages/confirm-encryption-public-key/confirm-encryption-public-key.container.js b/ui/app/pages/confirm-encryption-public-key/confirm-encryption-public-key.container.js index 0ee36f78907a..b70d06b6a1ae 100644 --- a/ui/app/pages/confirm-encryption-public-key/confirm-encryption-public-key.container.js +++ b/ui/app/pages/confirm-encryption-public-key/confirm-encryption-public-key.container.js @@ -49,15 +49,7 @@ function mapDispatchToProps (dispatch) { } } -function mergeProps (stateProps, dispatchProps, ownProps) { - return { - ...ownProps, - ...stateProps, - ...dispatchProps, - } -} - export default compose( withRouter, - connect(mapStateToProps, mapDispatchToProps, mergeProps) + connect(mapStateToProps, mapDispatchToProps) )(ConfirmEncryptionPublicKey) diff --git a/ui/app/pages/confirm-transaction/confirm-transaction.component.js b/ui/app/pages/confirm-transaction/confirm-transaction.component.js index 78634d4ce0cb..334b6f585c7d 100644 --- a/ui/app/pages/confirm-transaction/confirm-transaction.component.js +++ b/ui/app/pages/confirm-transaction/confirm-transaction.component.js @@ -10,7 +10,7 @@ import ConfirmDeployContract from '../confirm-deploy-contract' import ConfirmApprove from '../confirm-approve' import ConfirmTokenTransactionBaseContainer from '../confirm-token-transaction-base' import ConfTx from './conf-tx' -import ConfinmDecryptMessage from '../confirm-decrypt-message' +import ConfirmDecryptMessage from '../confirm-decrypt-message' import ConfirmEncryptionPublicKey from '../confirm-encryption-public-key' import { @@ -163,7 +163,7 @@ export default class ConfirmTransaction extends Component { { - window.onbeforeunload = null return new Promise((resolve, reject) => { log.debug(`actions calling background.decryptMessageInline`) - background.decryptMessageInline(msgData, (err, newState) => { + background.decryptMessageInline(decryptedMsgData, (err, newState) => { log.debug('decryptMsgInline called back') if (newState) { - msgData = newState.unapprovedDecryptMsgs[msgData.metamaskId] + decryptedMsgData = newState.unapprovedDecryptMsgs[decryptedMsgData.metamaskId] dispatch(updateMetamaskState(newState)) } else { log.error('Wrong data for decryptMessageInline') @@ -666,20 +665,19 @@ export function decryptMsgInline (msgData) { dispatch(displayWarning(err.message)) return reject(err) } - return resolve(msgData) + return resolve(decryptedMsgData) }) }) } } -export function decryptMsg (msgData) { +export function decryptMsg (decryptedMsgData) { log.debug('action - decryptMsg') return (dispatch, getState) => { dispatch(showLoadingIndication()) - window.onbeforeunload = null return new Promise((resolve, reject) => { log.debug(`actions calling background.decryptMessage`) - background.decryptMessage(msgData, (err, newState) => { + background.decryptMessage(decryptedMsgData, (err, newState) => { log.debug('decryptMsg called back') dispatch(updateMetamaskState(newState)) dispatch(hideLoadingIndication()) @@ -690,14 +688,10 @@ export function decryptMsg (msgData) { return reject(err) } - dispatch(completedTx(msgData.metamaskId)) - - if (global.METAMASK_UI_TYPE === ENVIRONMENT_TYPE_NOTIFICATION && - !hasUnconfirmedTransactions(getState())) { - return global.platform.closeCurrentWindow() - } + dispatch(completedTx(decryptedMsgData.metamaskId)) + dispatch(closeCurrentNotificationWindow()) - return resolve(msgData) + return resolve(decryptedMsgData) }) }) } @@ -707,7 +701,6 @@ export function encryptionPublicKeyMsg (msgData) { log.debug('action - encryptionPublicKeyMsg') return (dispatch, getState) => { dispatch(showLoadingIndication()) - window.onbeforeunload = null return new Promise((resolve, reject) => { log.debug(`actions calling background.encryptionPublicKey`) background.encryptionPublicKey(msgData, (err, newState) => { @@ -722,11 +715,7 @@ export function encryptionPublicKeyMsg (msgData) { } dispatch(completedTx(msgData.metamaskId)) - - if (global.METAMASK_UI_TYPE === ENVIRONMENT_TYPE_NOTIFICATION && - !hasUnconfirmedTransactions(getState())) { - return global.platform.closeCurrentWindow() - } + dispatch(closeCurrentNotificationWindow()) return resolve(msgData) }) @@ -1101,7 +1090,6 @@ export function cancelPersonalMsg (msgData) { export function cancelDecryptMsg (msgData) { return (dispatch) => { dispatch(showLoadingIndication()) - window.onbeforeunload = null return new Promise((resolve, reject) => { const id = msgData.id background.cancelDecryptMessage(id, (err, newState) => { @@ -1124,7 +1112,6 @@ export function cancelDecryptMsg (msgData) { export function cancelEncryptionPublicKeyMsg (msgData) { return (dispatch) => { dispatch(showLoadingIndication()) - window.onbeforeunload = null return new Promise((resolve, reject) => { const id = msgData.id background.cancelEncryptionPublicKey(id, (err, newState) => { From 2ba61e71941be77543168af48559d3de2ee88683 Mon Sep 17 00:00:00 2001 From: kviktorov Date: Wed, 5 Feb 2020 22:13:14 +0300 Subject: [PATCH 17/23] fix for lint errors --- ui/app/store/actions.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ui/app/store/actions.js b/ui/app/store/actions.js index 8ef88e03850a..7e3722f181e3 100644 --- a/ui/app/store/actions.js +++ b/ui/app/store/actions.js @@ -673,7 +673,7 @@ export function decryptMsgInline (decryptedMsgData) { export function decryptMsg (decryptedMsgData) { log.debug('action - decryptMsg') - return (dispatch, getState) => { + return (dispatch) => { dispatch(showLoadingIndication()) return new Promise((resolve, reject) => { log.debug(`actions calling background.decryptMessage`) @@ -689,7 +689,7 @@ export function decryptMsg (decryptedMsgData) { } dispatch(completedTx(decryptedMsgData.metamaskId)) - dispatch(closeCurrentNotificationWindow()) + dispatch(closeCurrentNotificationWindow()) return resolve(decryptedMsgData) }) @@ -699,7 +699,7 @@ export function decryptMsg (decryptedMsgData) { export function encryptionPublicKeyMsg (msgData) { log.debug('action - encryptionPublicKeyMsg') - return (dispatch, getState) => { + return (dispatch) => { dispatch(showLoadingIndication()) return new Promise((resolve, reject) => { log.debug(`actions calling background.encryptionPublicKey`) @@ -715,7 +715,7 @@ export function encryptionPublicKeyMsg (msgData) { } dispatch(completedTx(msgData.metamaskId)) - dispatch(closeCurrentNotificationWindow()) + dispatch(closeCurrentNotificationWindow()) return resolve(msgData) }) From fda35a102e79d529a7c9984ffb8b32fa48d15fc4 Mon Sep 17 00:00:00 2001 From: kviktorov Date: Thu, 6 Feb 2020 18:50:42 +0300 Subject: [PATCH 18/23] better handling for edges cases --- app/_locales/en/messages.json | 4 +++ app/_locales/ru/messages.json | 4 +++ app/scripts/lib/decrypt-message-manager.js | 4 ++- app/scripts/metamask-controller.js | 30 +++++++++++-------- .../confirm-decrypt-message.component.js | 15 ++++++---- ui/app/store/actions.js | 14 ++++----- 6 files changed, 42 insertions(+), 29 deletions(-) diff --git a/app/_locales/en/messages.json b/app/_locales/en/messages.json index 859867f29abc..db68585db7c3 100644 --- a/app/_locales/en/messages.json +++ b/app/_locales/en/messages.json @@ -1620,6 +1620,10 @@ "decryptCopy": { "message": "Copy encrypted message" }, + "decryptInlineError": { + "message": "This message cannot be decrypted due to error: $1", + "description": "$1 is error message" + }, "provide": { "message": "Provide" }, diff --git a/app/_locales/ru/messages.json b/app/_locales/ru/messages.json index 7428fcb150fe..09313c81d149 100644 --- a/app/_locales/ru/messages.json +++ b/app/_locales/ru/messages.json @@ -1366,6 +1366,10 @@ "decryptCopy": { "message": "Скопировать расшифрованное сообщение" }, + "decryptInlineError": { + "message": "Это сообщение не может быть дешифровано из-за ошибки: $1", + "description": "$1 is error message" + }, "provide": { "message": "Предоставить" }, diff --git a/app/scripts/lib/decrypt-message-manager.js b/app/scripts/lib/decrypt-message-manager.js index 812532ed78e7..bd128381dff4 100644 --- a/app/scripts/lib/decrypt-message-manager.js +++ b/app/scripts/lib/decrypt-message-manager.js @@ -90,6 +90,8 @@ export default class DecryptMessageManager extends EventEmitter { return resolve(data.rawData) case 'rejected': return reject(ethErrors.provider.userRejectedRequest('MetaMask Message for Decryption: User denied message decryption.')) + case 'errored': + return reject(new Error('This message cannot be decrypted')) default: return reject(new Error(`MetaMask Message for Decryption: Unknown problem: ${JSON.stringify(msgParams)}`)) } @@ -250,7 +252,7 @@ export default class DecryptMessageManager extends EventEmitter { msg.status = status this._updateMsg(msg) this.emit(`${msgId}:${status}`, msg) - if (status === 'rejected' || status === 'decrypted') { + if (status === 'rejected' || status === 'decrypted' || status === 'errored') { this.emit(`${msgId}:finished`, msg) } } diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 0a41d61eaacd..c02e2c77ee45 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -1207,19 +1207,23 @@ export default class MetamaskController extends EventEmitter { * @param {Object} msgParams - The params of the message to decrypt. * @returns {Promise} - A full state update. */ - decryptMessageInline (msgParams) { + async decryptMessageInline (msgParams) { log.info('MetaMaskController - decryptMessageInline') - const msgId = msgParams.metamaskId - const stripped = ethUtil.stripHexPrefix(msgParams.data) - const buff = Buffer.from(stripped, 'hex') - msgParams.data = JSON.parse(buff.toString('utf8')) // decrypt the message inline - return this.keyringController.decryptMessage(msgParams).then((rawData) => { - const msg = this.decryptMessageManager.getMsg(msgId) - msg.rawData = rawData - this.decryptMessageManager._updateMsg(msg) - return this.getState() - }) + const msgId = msgParams.metamaskId + const msg = this.decryptMessageManager.getMsg(msgId) + try { + const stripped = ethUtil.stripHexPrefix(msgParams.data) + const buff = Buffer.from(stripped, 'hex') + msgParams.data = JSON.parse(buff.toString('utf8')) + + msg.rawData = await this.keyringController.decryptMessage(msgParams) + } catch (e) { + msg.error = e.message + } + this.decryptMessageManager._updateMsg(msg) + + return this.getState() } /** @@ -1245,11 +1249,11 @@ export default class MetamaskController extends EventEmitter { const rawMess = await this.keyringController.decryptMessage(cleanMsgParams) // tells the listener that the message has been decrypted and can be returned to the dapp this.decryptMessageManager.setMsgStatusDecrypted(msgId, rawMess) - return this.getState() } catch (error) { log.info('MetaMaskController - eth_decryptMessage failed.', error) this.decryptMessageManager.errorMessage(msgId, error) } + return this.getState() } /** @@ -1302,11 +1306,11 @@ export default class MetamaskController extends EventEmitter { // tells the listener that the message has been processed // and can be returned to the dapp this.encryptionPublicKeyManager.setMsgStatusReceived(msgId, publicKey) - return this.getState() } catch (error) { log.info('MetaMaskController - encryption_public_key failed.', error) this.encryptionPublicKeyManager.errorMessage(msgId, error) } + return this.getState() } /** diff --git a/ui/app/pages/confirm-decrypt-message/confirm-decrypt-message.component.js b/ui/app/pages/confirm-decrypt-message/confirm-decrypt-message.component.js index 10602138bfc3..18a6f28bfed1 100644 --- a/ui/app/pages/confirm-decrypt-message/confirm-decrypt-message.component.js +++ b/ui/app/pages/confirm-decrypt-message/confirm-decrypt-message.component.js @@ -171,7 +171,9 @@ export default class ConfirmDecryptMessage extends Component { const { hasCopied, hasDecrypted, + hasError, rawMessage, + errorMessage, copyToClipboardPressed, } = this.state @@ -205,26 +207,27 @@ export default class ConfirmDecryptMessage extends Component {
- { !hasDecrypted ? txData.msgParams.data : rawMessage } + { !hasDecrypted && !hasError ? txData.msgParams.data : rawMessage } + { !hasError ? '' : errorMessage }
{ - this.props.decryptMessageInline(txData, event).then((result, err) => { - if (!err) { + this.props.decryptMessageInline(txData, event).then((result) => { + if (!result.error) { this.setState({ hasDecrypted: true, rawMessage: result.rawData }) } else { - this.setState({ hasDecrypted: true, rawMessage: err }) + this.setState({ hasError: true, errorMessage: this.context.t('decryptInlineError', [result.error]) }) } }) }} diff --git a/ui/app/store/actions.js b/ui/app/store/actions.js index 7e3722f181e3..6de9f9d6177f 100644 --- a/ui/app/store/actions.js +++ b/ui/app/store/actions.js @@ -652,19 +652,15 @@ export function decryptMsgInline (decryptedMsgData) { log.debug(`actions calling background.decryptMessageInline`) background.decryptMessageInline(decryptedMsgData, (err, newState) => { log.debug('decryptMsgInline called back') - if (newState) { - decryptedMsgData = newState.unapprovedDecryptMsgs[decryptedMsgData.metamaskId] - dispatch(updateMetamaskState(newState)) - } else { - log.error('Wrong data for decryptMessageInline') - dispatch(displayWarning('Wrong data')) - return reject({ 'message': 'Wrong data' }) - } + dispatch(updateMetamaskState(newState)) + if (err) { log.error(err) dispatch(displayWarning(err.message)) return reject(err) } + + decryptedMsgData = newState.unapprovedDecryptMsgs[decryptedMsgData.metamaskId] return resolve(decryptedMsgData) }) }) @@ -690,7 +686,7 @@ export function decryptMsg (decryptedMsgData) { dispatch(completedTx(decryptedMsgData.metamaskId)) dispatch(closeCurrentNotificationWindow()) - + console.log(decryptedMsgData) return resolve(decryptedMsgData) }) }) From 74e99e98e643c86bdaec3fcf60c3afd35d579ecd Mon Sep 17 00:00:00 2001 From: kviktorov Date: Mon, 10 Feb 2020 20:58:51 +0300 Subject: [PATCH 19/23] fixes after jennypollack review --- app/scripts/lib/decrypt-message-manager.js | 2 +- test/data/2-state.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/scripts/lib/decrypt-message-manager.js b/app/scripts/lib/decrypt-message-manager.js index bd128381dff4..83a7b4e9a458 100644 --- a/app/scripts/lib/decrypt-message-manager.js +++ b/app/scripts/lib/decrypt-message-manager.js @@ -159,7 +159,7 @@ export default class DecryptMessageManager extends EventEmitter { /** * Approves a DecryptMessage. Sets the message status via a call to this.setMsgStatusApproved, and returns a promise - * with any the message params modified for proper decryption. + * with the message params modified for proper decryption. * * @param {Object} msgParams The msgParams to be used when eth_decryptMsg is called, plus data added by MetaMask. * @param {Object} msgParams.metamaskId Added to msgParams for tracking and identification within MetaMask. diff --git a/test/data/2-state.json b/test/data/2-state.json index e7b49c0e4818..8100b7e03d4c 100644 --- a/test/data/2-state.json +++ b/test/data/2-state.json @@ -18,7 +18,7 @@ "unapprovedMsgCount": 0, "unapprovedPersonalMsgs": {}, "unapprovedPersonalMsgCount": 0, - "unapprovedDecryptMsgs": 0, + "unapprovedDecryptMsgs": {}, "unapprovedDecryptMsgCount": 0, "unapprovedTypedMessages": {}, "unapprovedTypedMessagesCount": 0, From 2c32b689bbccc79a01d4395447402f7eae5c8b16 Mon Sep 17 00:00:00 2001 From: kviktorov Date: Thu, 13 Feb 2020 16:13:16 +0300 Subject: [PATCH 20/23] Fixes for the metric messages --- .../confirm-decrypt-message.component.js | 10 +++++----- .../confirm-encryption-public-key.component.js | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/ui/app/pages/confirm-decrypt-message/confirm-decrypt-message.component.js b/ui/app/pages/confirm-decrypt-message/confirm-decrypt-message.component.js index 18a6f28bfed1..6e6215362fa0 100644 --- a/ui/app/pages/confirm-decrypt-message/confirm-decrypt-message.component.js +++ b/ui/app/pages/confirm-decrypt-message/confirm-decrypt-message.component.js @@ -53,9 +53,9 @@ export default class ConfirmDecryptMessage extends Component { const { metricsEvent } = this.context metricsEvent({ eventOpts: { - category: 'Transactions', + category: 'Messages', action: 'Decrypt Message Request', - name: 'Cancel Decrypt Message Request Via Notification Close', + name: 'Cancel Via Notification Close', }, }) clearConfirmTransaction() @@ -72,7 +72,7 @@ export default class ConfirmDecryptMessage extends Component { copyToClipboard(this.state.rawMessage) this.context.metricsEvent({ eventOpts: { - category: 'Transactions', + category: 'Messages', action: 'Decrypt Message Copy', name: 'Copy', }, @@ -286,7 +286,7 @@ export default class ConfirmDecryptMessage extends Component { await this.props.cancelDecryptMessage(txData, event) this.context.metricsEvent({ eventOpts: { - category: 'Transactions', + category: 'Messages', action: 'Decrypt Message Request', name: 'Cancel', }, @@ -306,7 +306,7 @@ export default class ConfirmDecryptMessage extends Component { await this.props.decryptMessage(txData, event) this.context.metricsEvent({ eventOpts: { - category: 'Transactions', + category: 'Messages', action: 'Decrypt Message Request', name: 'Confirm', }, diff --git a/ui/app/pages/confirm-encryption-public-key/confirm-encryption-public-key.component.js b/ui/app/pages/confirm-encryption-public-key/confirm-encryption-public-key.component.js index d06305fd9493..20aae6cb692d 100644 --- a/ui/app/pages/confirm-encryption-public-key/confirm-encryption-public-key.component.js +++ b/ui/app/pages/confirm-encryption-public-key/confirm-encryption-public-key.component.js @@ -47,9 +47,9 @@ export default class ConfirmEncryptionPublicKey extends Component { const { metricsEvent } = this.context metricsEvent({ eventOpts: { - category: 'Transactions', + category: 'Messages', action: 'Encryption public key Request', - name: 'Cancel Encryption public key Request Via Notification Close', + name: 'Cancel Via Notification Close', }, }) clearConfirmTransaction() @@ -191,7 +191,7 @@ export default class ConfirmEncryptionPublicKey extends Component { await this.props.cancelEncryptionPublicKey(txData, event) this.context.metricsEvent({ eventOpts: { - category: 'Transactions', + category: 'Messages', action: 'Encryption public key Request', name: 'Cancel', }, @@ -211,7 +211,7 @@ export default class ConfirmEncryptionPublicKey extends Component { await this.props.encryptionPublicKey(txData, event) this.context.metricsEvent({ eventOpts: { - category: 'Transactions', + category: 'Messages', action: 'Encryption public key Request', name: 'Confirm', }, From b8099ca23dfa8aa8c1ebc625c733c3aaa7f32e7d Mon Sep 17 00:00:00 2001 From: kviktorov Date: Fri, 14 Feb 2020 15:10:58 +0300 Subject: [PATCH 21/23] fixes for names of decrypt/encrypt RPC methods --- app/scripts/controllers/permissions/enums.js | 4 +-- app/scripts/lib/decrypt-message-manager.js | 10 +++---- .../lib/encryption-public-key-manager.js | 14 +++++----- app/scripts/metamask-controller.js | 16 +++++------ package.json | 2 +- ui/app/helpers/utils/transactions.util.js | 4 +-- .../confirm-transaction-switch.component.js | 4 +-- yarn.lock | 27 +++---------------- 8 files changed, 30 insertions(+), 51 deletions(-) diff --git a/app/scripts/controllers/permissions/enums.js b/app/scripts/controllers/permissions/enums.js index 56cbf187f5d5..0d30827d6242 100644 --- a/app/scripts/controllers/permissions/enums.js +++ b/app/scripts/controllers/permissions/enums.js @@ -69,6 +69,6 @@ export const SAFE_METHODS = [ 'eth_uninstallFilter', 'metamask_watchAsset', 'wallet_watchAsset', - 'encryption_public_key', - 'eth_decryptMessage', + 'eth_getEncryptionPublicKey', + 'eth_decrypt', ] diff --git a/app/scripts/lib/decrypt-message-manager.js b/app/scripts/lib/decrypt-message-manager.js index 83a7b4e9a458..ded9117edbed 100644 --- a/app/scripts/lib/decrypt-message-manager.js +++ b/app/scripts/lib/decrypt-message-manager.js @@ -8,8 +8,8 @@ const hexRe = /^[0-9A-Fa-f]+$/g import log from 'loglevel' /** - * Represents, and contains data about, an 'eth_decryptMessage' type decryption request. These are created when a - * decryption for an eth_decryptMessage call is requested. + * Represents, and contains data about, an 'eth_decrypt' type decryption request. These are created when a + * decryption for an eth_decrypt call is requested. * * @typedef {Object} DecryptMessage * @property {number} id An id to track and identify the message object @@ -20,7 +20,7 @@ import log from 'loglevel' * @property {number} time The epoch time at which the this message was created * @property {string} status Indicates whether the decryption request is 'unapproved', 'approved', 'decrypted' or 'rejected' * @property {string} type The json-prc decryption method for which a decryption request has been made. A 'Message' will - * always have a 'eth_decryptMessage' type. + * always have a 'eth_decrypt' type. * */ @@ -73,7 +73,7 @@ export default class DecryptMessageManager extends EventEmitter { * the new DecryptMessage to this.messages, and to save the unapproved DecryptMessages from that list to * this.memStore. * - * @param {Object} msgParams The params for the eth_decryptMessage call to be made after the message is approved. + * @param {Object} msgParams The params for the eth_decrypt call to be made after the message is approved. * @param {Object} req (optional) The original request object possibly containing the origin * @returns {Promise} The raw decrypted message contents * @@ -124,7 +124,7 @@ export default class DecryptMessageManager extends EventEmitter { msgParams: msgParams, time: time, status: 'unapproved', - type: 'eth_decryptMessage', + type: 'eth_decrypt', } this.addMsg(msgData) diff --git a/app/scripts/lib/encryption-public-key-manager.js b/app/scripts/lib/encryption-public-key-manager.js index d0016c7ca796..b049a77cfe91 100644 --- a/app/scripts/lib/encryption-public-key-manager.js +++ b/app/scripts/lib/encryption-public-key-manager.js @@ -5,8 +5,8 @@ import createId from './random-id' import log from 'loglevel' /** - * Represents, and contains data about, an 'encryption_public_key' type request. These are created when - * an encryption_public_key call is requested. + * Represents, and contains data about, an 'eth_getEncryptionPublicKey' type request. These are created when + * an eth_getEncryptionPublicKey call is requested. * * @typedef {Object} EncryptionPublicKey * @property {number} id An id to track and identify the message object @@ -17,7 +17,7 @@ import log from 'loglevel' * @property {number} time The epoch time at which the this message was created * @property {string} status Indicates whether the request is 'unapproved', 'approved', 'received' or 'rejected' * @property {string} type The json-prc method for which a request has been made. A 'Message' will - * always have a 'encryption_public_key' type. + * always have a 'eth_getEncryptionPublicKey' type. * */ @@ -70,7 +70,7 @@ export default class EncryptionPublicKeyManager extends EventEmitter { * the new EncryptionPublicKey to this.messages, and to save the unapproved EncryptionPublicKeys from that list to * this.memStore. * - * @param {Object} address The param for the encryption_public_key call to be made after the message is approved. + * @param {Object} address The param for the eth_getEncryptionPublicKey call to be made after the message is approved. * @param {Object} req (optional) The original request object possibly containing the origin * @returns {Promise} The raw public key contents * @@ -99,7 +99,7 @@ export default class EncryptionPublicKeyManager extends EventEmitter { * the new EncryptionPublicKey to this.messages, and to save the unapproved EncryptionPublicKeys from that list to * this.memStore. * - * @param {Object} address The param for the encryption_public_key call to be made after the message is approved. + * @param {Object} address The param for the eth_getEncryptionPublicKey call to be made after the message is approved. * @param {Object} _req (optional) The original request object possibly containing the origin * @returns {number} The id of the newly created EncryptionPublicKey. * @@ -114,7 +114,7 @@ export default class EncryptionPublicKeyManager extends EventEmitter { msgParams: address, time: time, status: 'unapproved', - type: 'encryption_public_key', + type: 'eth_getEncryptionPublicKey', } if (_req) { @@ -156,7 +156,7 @@ export default class EncryptionPublicKeyManager extends EventEmitter { * Approves a EncryptionPublicKey. Sets the message status via a call to this.setMsgStatusApproved, and returns a promise * with any the message params modified for proper providing. * - * @param {Object} msgParams The msgParams to be used when encryption_public_key is called, plus data added by MetaMask. + * @param {Object} msgParams The msgParams to be used when eth_getEncryptionPublicKey is called, plus data added by MetaMask. * @param {Object} msgParams.metamaskId Added to msgParams for tracking and identification within MetaMask. * @returns {Promise} Promises the msgParams object with metamaskId removed. * diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index c02e2c77ee45..881250edb457 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -1185,10 +1185,10 @@ export default class MetamaskController extends EventEmitter { } } - // eth_decryptMessage methods + // eth_decrypt methods /** - * Called when a dapp uses the eth_decryptMessage method. + * Called when a dapp uses the eth_decrypt method. * * @param {Object} msgParams - The params of the message to sign & return to the Dapp. * @param {Object} req - (optional) the original request, containing the origin @@ -1250,14 +1250,14 @@ export default class MetamaskController extends EventEmitter { // tells the listener that the message has been decrypted and can be returned to the dapp this.decryptMessageManager.setMsgStatusDecrypted(msgId, rawMess) } catch (error) { - log.info('MetaMaskController - eth_decryptMessage failed.', error) + log.info('MetaMaskController - eth_decrypt failed.', error) this.decryptMessageManager.errorMessage(msgId, error) } return this.getState() } /** - * Used to cancel a eth_decryptMessage type message. + * Used to cancel a eth_decrypt type message. * @param {string} msgId - The ID of the message to cancel. * @param {Function} cb - The callback function called with a full state update. */ @@ -1269,10 +1269,10 @@ export default class MetamaskController extends EventEmitter { } } - // encryption_public_key methods + // eth_getEncryptionPublicKey methods /** - * Called when a dapp uses the encryption_public_key method. + * Called when a dapp uses the eth_getEncryptionPublicKey method. * * @param {Object} msgParams - The params of the message to sign & return to the Dapp. * @param {Object} req - (optional) the original request, containing the origin @@ -1307,14 +1307,14 @@ export default class MetamaskController extends EventEmitter { // and can be returned to the dapp this.encryptionPublicKeyManager.setMsgStatusReceived(msgId, publicKey) } catch (error) { - log.info('MetaMaskController - encryption_public_key failed.', error) + log.info('MetaMaskController - eth_getEncryptionPublicKey failed.', error) this.encryptionPublicKeyManager.errorMessage(msgId, error) } return this.getState() } /** - * Used to cancel a encryption_public_key type message. + * Used to cancel a eth_getEncryptionPublicKey type message. * @param {string} msgId - The ID of the message to cancel. * @param {Function} cb - The callback function called with a full state update. */ diff --git a/package.json b/package.json index d30da19e68fe..d021473daa4c 100644 --- a/package.json +++ b/package.json @@ -88,7 +88,7 @@ "eth-json-rpc-errors": "^2.0.2", "eth-json-rpc-filters": "^4.1.1", "eth-json-rpc-infura": "^4.0.2", - "eth-json-rpc-middleware": "^4.4.0", + "eth-json-rpc-middleware": "https://github.com/logvik/eth-json-rpc-middleware", "eth-keyring-controller": "^5.5.0", "eth-ledger-bridge-keyring": "^0.2.0", "eth-method-registry": "^1.2.0", diff --git a/ui/app/helpers/utils/transactions.util.js b/ui/app/helpers/utils/transactions.util.js index 201f4944e211..49f4f86c0ff9 100644 --- a/ui/app/helpers/utils/transactions.util.js +++ b/ui/app/helpers/utils/transactions.util.js @@ -134,9 +134,9 @@ export function getTransactionActionKey (transaction) { } if (msgParams) { - if (type === 'eth_decryptMessage') { + if (type === 'eth_decrypt') { return DECRYPT_REQUEST_KEY - } else if (type === 'encryption_public_key') { + } else if (type === 'eth_getEncryptionPublicKey') { return ENCRYPTION_PUBLIC_KEY_REQUEST_KEY } else { return SIGNATURE_REQUEST_KEY diff --git a/ui/app/pages/confirm-transaction-switch/confirm-transaction-switch.component.js b/ui/app/pages/confirm-transaction-switch/confirm-transaction-switch.component.js index 9cd329604bc2..2ed2ab1e684c 100644 --- a/ui/app/pages/confirm-transaction-switch/confirm-transaction-switch.component.js +++ b/ui/app/pages/confirm-transaction-switch/confirm-transaction-switch.component.js @@ -74,9 +74,9 @@ export default class ConfirmTransactionSwitch extends Component { return this.redirectToTransaction() } else if (txData.msgParams) { let pathname = `${CONFIRM_TRANSACTION_ROUTE}/${txData.id}${SIGNATURE_REQUEST_PATH}` - if (txData.type === 'eth_decryptMessage') { + if (txData.type === 'eth_decrypt') { pathname = `${CONFIRM_TRANSACTION_ROUTE}/${txData.id}${DECRYPT_MESSAGE_REQUEST_PATH}` - } else if (txData.type === 'encryption_public_key') { + } else if (txData.type === 'eth_getEncryptionPublicKey') { pathname = `${CONFIRM_TRANSACTION_ROUTE}/${txData.id}${ENCRYPTION_PUBLIC_KEY_REQUEST_PATH}` } return diff --git a/yarn.lock b/yarn.lock index 84ee387937db..82d852691b63 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10317,30 +10317,9 @@ eth-json-rpc-middleware@^1.5.0: promise-to-callback "^1.0.0" tape "^4.6.3" -eth-json-rpc-middleware@^4.1.4, eth-json-rpc-middleware@^4.1.5: - version "4.2.0" - resolved "https://registry.yarnpkg.com/eth-json-rpc-middleware/-/eth-json-rpc-middleware-4.2.0.tgz#cfb77c5056cb8001548c6c7d54f4af5fce04d489" - integrity sha512-90LljqRyJhkg7fOwKunh1lu1Mr5bspXMBDitaTGyGPPNiFTbMrhtfbf9fteYlXRFCbq+aIFWwl/X+P7nkrdkLg== - dependencies: - btoa "^1.2.1" - clone "^2.1.1" - eth-json-rpc-errors "^1.0.1" - eth-query "^2.1.2" - eth-sig-util "^1.4.2" - ethereumjs-block "^1.6.0" - ethereumjs-tx "^1.3.7" - ethereumjs-util "^5.1.2" - ethereumjs-vm "^2.6.0" - fetch-ponyfill "^4.0.0" - json-rpc-engine "^5.1.3" - json-stable-stringify "^1.0.1" - pify "^3.0.0" - safe-event-emitter "^1.0.1" - -eth-json-rpc-middleware@^4.4.0: - version "4.4.0" - resolved "https://registry.yarnpkg.com/eth-json-rpc-middleware/-/eth-json-rpc-middleware-4.4.0.tgz#ef63b783b48dcbea9c1fe25c79e6ea01510e5877" - integrity sha512-IeOsil/XiHsybJO9nFf86+1+YIqGQWPPfiTEp3WLkpLZhJm97kw6tFM7GttIZXIcwtaO3zEXgY6PWAH1jkB3ag== +eth-json-rpc-middleware@^4.1.4, eth-json-rpc-middleware@^4.1.5, "eth-json-rpc-middleware@https://github.com/logvik/eth-json-rpc-middleware": + version "4.4.1" + resolved "https://github.com/logvik/eth-json-rpc-middleware#9a4e93e3a37132932fa62f7a7fcb1b09847b4ed5" dependencies: btoa "^1.2.1" clone "^2.1.1" From 9b8c2dcc73996b2cbca7ae13067b12a1fc2e15e5 Mon Sep 17 00:00:00 2001 From: kviktorov Date: Sat, 15 Feb 2020 21:34:02 +0300 Subject: [PATCH 22/23] removed the link on the private npm package --- package.json | 2 +- yarn.lock | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index d021473daa4c..f2fb3f4c7e49 100644 --- a/package.json +++ b/package.json @@ -88,7 +88,7 @@ "eth-json-rpc-errors": "^2.0.2", "eth-json-rpc-filters": "^4.1.1", "eth-json-rpc-infura": "^4.0.2", - "eth-json-rpc-middleware": "https://github.com/logvik/eth-json-rpc-middleware", + "eth-json-rpc-middleware": "^4.4.1", "eth-keyring-controller": "^5.5.0", "eth-ledger-bridge-keyring": "^0.2.0", "eth-method-registry": "^1.2.0", diff --git a/yarn.lock b/yarn.lock index 82d852691b63..10ced1284836 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10317,9 +10317,10 @@ eth-json-rpc-middleware@^1.5.0: promise-to-callback "^1.0.0" tape "^4.6.3" -eth-json-rpc-middleware@^4.1.4, eth-json-rpc-middleware@^4.1.5, "eth-json-rpc-middleware@https://github.com/logvik/eth-json-rpc-middleware": +eth-json-rpc-middleware@^4.1.4, eth-json-rpc-middleware@^4.1.5, eth-json-rpc-middleware@^4.4.1: version "4.4.1" - resolved "https://github.com/logvik/eth-json-rpc-middleware#9a4e93e3a37132932fa62f7a7fcb1b09847b4ed5" + resolved "https://registry.yarnpkg.com/eth-json-rpc-middleware/-/eth-json-rpc-middleware-4.4.1.tgz#07d3dd0724c24a8d31e4a172ee96271da71b4228" + integrity sha512-yoSuRgEYYGFdVeZg3poWOwAlRI+MoBIltmOB86MtpoZjvLbou9EB/qWMOWSmH2ryCWLW97VYY6NWsmWm3OAA7A== dependencies: btoa "^1.2.1" clone "^2.1.1" From 7308af8a4d015b0864fd08ec0eee47d65998eacc Mon Sep 17 00:00:00 2001 From: kviktorov Date: Wed, 19 Feb 2020 14:43:33 +0300 Subject: [PATCH 23/23] fix for lint --- app/scripts/lib/decrypt-message-manager.js | 4 ++-- app/scripts/lib/encryption-public-key-manager.js | 4 ++-- .../confirm-decrypt-message.component.js | 4 ++-- .../confirm-encryption-public-key.component.js | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/scripts/lib/decrypt-message-manager.js b/app/scripts/lib/decrypt-message-manager.js index ded9117edbed..24b8e8dd77ea 100644 --- a/app/scripts/lib/decrypt-message-manager.js +++ b/app/scripts/lib/decrypt-message-manager.js @@ -62,7 +62,7 @@ export default class DecryptMessageManager extends EventEmitter { * */ getUnapprovedMsgs () { - return this.messages.filter(msg => msg.status === 'unapproved') + return this.messages.filter((msg) => msg.status === 'unapproved') .reduce((result, msg) => { result[msg.id] = msg; return result }, {}) @@ -154,7 +154,7 @@ export default class DecryptMessageManager extends EventEmitter { * */ getMsg (msgId) { - return this.messages.find(msg => msg.id === msgId) + return this.messages.find((msg) => msg.id === msgId) } /** diff --git a/app/scripts/lib/encryption-public-key-manager.js b/app/scripts/lib/encryption-public-key-manager.js index b049a77cfe91..4667330ed42b 100644 --- a/app/scripts/lib/encryption-public-key-manager.js +++ b/app/scripts/lib/encryption-public-key-manager.js @@ -59,7 +59,7 @@ export default class EncryptionPublicKeyManager extends EventEmitter { * */ getUnapprovedMsgs () { - return this.messages.filter(msg => msg.status === 'unapproved') + return this.messages.filter((msg) => msg.status === 'unapproved') .reduce((result, msg) => { result[msg.id] = msg; return result }, {}) @@ -149,7 +149,7 @@ export default class EncryptionPublicKeyManager extends EventEmitter { * */ getMsg (msgId) { - return this.messages.find(msg => msg.id === msgId) + return this.messages.find((msg) => msg.id === msgId) } /** diff --git a/ui/app/pages/confirm-decrypt-message/confirm-decrypt-message.component.js b/ui/app/pages/confirm-decrypt-message/confirm-decrypt-message.component.js index 6e6215362fa0..36bc135d467f 100644 --- a/ui/app/pages/confirm-decrypt-message/confirm-decrypt-message.component.js +++ b/ui/app/pages/confirm-decrypt-message/confirm-decrypt-message.component.js @@ -281,7 +281,7 @@ export default class ConfirmDecryptMessage extends Component { type="default" large className="request-decrypt-message__footer__cancel-button" - onClick={async event => { + onClick={async (event) => { this._removeBeforeUnload() await this.props.cancelDecryptMessage(txData, event) this.context.metricsEvent({ @@ -301,7 +301,7 @@ export default class ConfirmDecryptMessage extends Component { type="secondary" large className="request-decrypt-message__footer__sign-button" - onClick={async event => { + onClick={async (event) => { this._removeBeforeUnload() await this.props.decryptMessage(txData, event) this.context.metricsEvent({ diff --git a/ui/app/pages/confirm-encryption-public-key/confirm-encryption-public-key.component.js b/ui/app/pages/confirm-encryption-public-key/confirm-encryption-public-key.component.js index 20aae6cb692d..0b63b57d07d6 100644 --- a/ui/app/pages/confirm-encryption-public-key/confirm-encryption-public-key.component.js +++ b/ui/app/pages/confirm-encryption-public-key/confirm-encryption-public-key.component.js @@ -186,7 +186,7 @@ export default class ConfirmEncryptionPublicKey extends Component { type="default" large className="request-encryption-public-key__footer__cancel-button" - onClick={async event => { + onClick={async (event) => { this._removeBeforeUnload() await this.props.cancelEncryptionPublicKey(txData, event) this.context.metricsEvent({ @@ -206,7 +206,7 @@ export default class ConfirmEncryptionPublicKey extends Component { type="secondary" large className="request-encryption-public-key__footer__sign-button" - onClick={async event => { + onClick={async (event) => { this._removeBeforeUnload() await this.props.encryptionPublicKey(txData, event) this.context.metricsEvent({