aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorAlexander Tseung <alextsg@gmail.com>2018-04-05 09:21:35 +0800
committerAlexander Tseung <alextsg@gmail.com>2018-04-05 09:21:35 +0800
commit5b2ace3b802f6e120cd72a4d633299aa78b5cae8 (patch)
treefb61667ad8a2d77a2c54c5c3274740cc52e73293 /app
parent037d6e66248d2fc13a9d97a52ce667afe1aa2ae8 (diff)
parent1153120fe84e9d4cde47a7e416028be0fec3c61c (diff)
downloadtangerine-wallet-browser-5b2ace3b802f6e120cd72a4d633299aa78b5cae8.tar
tangerine-wallet-browser-5b2ace3b802f6e120cd72a4d633299aa78b5cae8.tar.gz
tangerine-wallet-browser-5b2ace3b802f6e120cd72a4d633299aa78b5cae8.tar.bz2
tangerine-wallet-browser-5b2ace3b802f6e120cd72a4d633299aa78b5cae8.tar.lz
tangerine-wallet-browser-5b2ace3b802f6e120cd72a4d633299aa78b5cae8.tar.xz
tangerine-wallet-browser-5b2ace3b802f6e120cd72a4d633299aa78b5cae8.tar.zst
tangerine-wallet-browser-5b2ace3b802f6e120cd72a4d633299aa78b5cae8.zip
Merge branch 'master' of https://github.com/MetaMask/metamask-extension into cb-254
Diffstat (limited to 'app')
-rw-r--r--app/manifest.json2
-rw-r--r--app/scripts/contentscript.js6
-rw-r--r--app/scripts/controllers/transactions.js59
-rw-r--r--app/scripts/lib/tx-gas-utils.js35
-rw-r--r--app/scripts/lib/tx-state-manager.js2
-rw-r--r--app/scripts/migrations/024.js45
-rw-r--r--app/scripts/migrations/index.js1
7 files changed, 111 insertions, 39 deletions
diff --git a/app/manifest.json b/app/manifest.json
index 99305f20e..61d2c5b5e 100644
--- a/app/manifest.json
+++ b/app/manifest.json
@@ -1,7 +1,7 @@
{
"name": "__MSG_appName__",
"short_name": "__MSG_appName__",
- "version": "4.5.1",
+ "version": "4.5.3",
"manifest_version": 2,
"author": "https://metamask.io",
"description": "__MSG_appDescription__",
diff --git a/app/scripts/contentscript.js b/app/scripts/contentscript.js
index 2098fae27..fe1766273 100644
--- a/app/scripts/contentscript.js
+++ b/app/scripts/contentscript.js
@@ -131,7 +131,11 @@ function documentElementCheck () {
}
function blacklistedDomainCheck () {
- var blacklistedDomains = ['uscourts.gov', 'dropbox.com']
+ var blacklistedDomains = [
+ 'uscourts.gov',
+ 'dropbox.com',
+ 'webbyawards.com',
+ ]
var currentUrl = window.location.href
var currentRegex
for (let i = 0; i < blacklistedDomains.length; i++) {
diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js
index 31e53554d..a73a8b36d 100644
--- a/app/scripts/controllers/transactions.js
+++ b/app/scripts/controllers/transactions.js
@@ -185,7 +185,8 @@ module.exports = class TransactionController extends EventEmitter {
async addUnapprovedTransaction (txParams) {
// validate
- await this.txGasUtil.validateTxParams(txParams)
+ this._validateTxParams(txParams)
+ this._normalizeTxParams(txParams)
// construct txMeta
let txMeta = this.txStateManager.generateTxMeta({txParams})
this.addTx(txMeta)
@@ -215,7 +216,6 @@ module.exports = class TransactionController extends EventEmitter {
}
txParams.gasPrice = ethUtil.addHexPrefix(gasPrice.toString(16))
txParams.value = txParams.value || '0x0'
- if (txParams.to === null) delete txParams.to
// set gasLimit
return await this.txGasUtil.analyzeGasUsage(txMeta)
}
@@ -314,6 +314,61 @@ module.exports = class TransactionController extends EventEmitter {
// PRIVATE METHODS
//
+ _normalizeTxParams (txParams) {
+ delete txParams.chainId
+
+ if ( !txParams.to ) {
+ delete txParams.to
+ } else {
+ txParams.to = ethUtil.addHexPrefix(txParams.to)
+ }
+ txParams.from = ethUtil.addHexPrefix(txParams.from).toLowerCase()
+
+ if (!txParams.data) {
+ delete txParams.data
+ } else {
+ txParams.data = ethUtil.addHexPrefix(txParams.data)
+ }
+
+ if (txParams.value) txParams.value = ethUtil.addHexPrefix(txParams.value)
+
+ if (txParams.gas) txParams.gas = ethUtil.addHexPrefix(txParams.gas)
+ if (txParams.gasPrice) txParams.gas = ethUtil.addHexPrefix(txParams.gas)
+ }
+
+ _validateTxParams (txParams) {
+ this._validateFrom(txParams)
+ this._validateRecipient(txParams)
+ if ('value' in txParams) {
+ const value = txParams.value.toString()
+ if (value.includes('-')) {
+ throw new Error(`Invalid transaction value of ${txParams.value} not a positive number.`)
+ }
+
+ if (value.includes('.')) {
+ throw new Error(`Invalid transaction value of ${txParams.value} number must be in wei`)
+ }
+ }
+ }
+
+ _validateFrom (txParams) {
+ if ( !(typeof txParams.from === 'string') ) throw new Error(`Invalid from address ${txParams.from} not a string`)
+ if (!ethUtil.isValidAddress(txParams.from)) throw new Error('Invalid from address')
+ }
+
+ _validateRecipient (txParams) {
+ if (txParams.to === '0x' || txParams.to === null ) {
+ if (txParams.data) {
+ delete txParams.to
+ } else {
+ throw new Error('Invalid recipient address')
+ }
+ } else if ( txParams.to !== undefined && !ethUtil.isValidAddress(txParams.to) ) {
+ throw new Error('Invalid recipient address')
+ }
+ return txParams
+ }
+
_markNonceDuplicatesDropped (txId) {
this.txStateManager.setTxStatusConfirmed(txId)
// get the confirmed transactions nonce and from address
diff --git a/app/scripts/lib/tx-gas-utils.js b/app/scripts/lib/tx-gas-utils.js
index 829b4c421..c579e462a 100644
--- a/app/scripts/lib/tx-gas-utils.js
+++ b/app/scripts/lib/tx-gas-utils.js
@@ -4,7 +4,7 @@ const {
BnMultiplyByFraction,
bnToHex,
} = require('./util')
-const { addHexPrefix, isValidAddress } = require('ethereumjs-util')
+const { addHexPrefix } = require('ethereumjs-util')
const SIMPLE_GAS_COST = '0x5208' // Hex for 21000, cost of a simple send.
/*
@@ -100,37 +100,4 @@ module.exports = class TxGasUtil {
// otherwise use blockGasLimit
return bnToHex(upperGasLimitBn)
}
-
- async validateTxParams (txParams) {
- this.validateFrom(txParams)
- this.validateRecipient(txParams)
- if ('value' in txParams) {
- const value = txParams.value.toString()
- if (value.includes('-')) {
- throw new Error(`Invalid transaction value of ${txParams.value} not a positive number.`)
- }
-
- if (value.includes('.')) {
- throw new Error(`Invalid transaction value of ${txParams.value} number must be in wei`)
- }
- }
- }
-
- validateFrom (txParams) {
- if ( !(typeof txParams.from === 'string') ) throw new Error(`Invalid from address ${txParams.from} not a string`)
- if (!isValidAddress(txParams.from)) throw new Error('Invalid from address')
- }
-
- validateRecipient (txParams) {
- if (txParams.to === '0x' || txParams.to === null ) {
- if (txParams.data) {
- delete txParams.to
- } else {
- throw new Error('Invalid recipient address')
- }
- } else if ( txParams.to !== undefined && !isValidAddress(txParams.to) ) {
- throw new Error('Invalid recipient address')
- }
- return txParams
- }
} \ No newline at end of file
diff --git a/app/scripts/lib/tx-state-manager.js b/app/scripts/lib/tx-state-manager.js
index 9e597ef37..2ab24d6a0 100644
--- a/app/scripts/lib/tx-state-manager.js
+++ b/app/scripts/lib/tx-state-manager.js
@@ -143,7 +143,7 @@ module.exports = class TransactionStateManager extends EventEmitter {
// validate types
switch (key) {
case 'chainId':
- if (typeof value !== 'number') throw new Error(`${key} in txParams is not a Number. got: (${value})`)
+ if (typeof value !== 'number' && typeof value !== 'string') throw new Error(`${key} in txParams is not a Number or hex string. got: (${value})`)
break
default:
if (typeof value !== 'string') throw new Error(`${key} in txParams is not a string. got: (${value})`)
diff --git a/app/scripts/migrations/024.js b/app/scripts/migrations/024.js
new file mode 100644
index 000000000..7a0391805
--- /dev/null
+++ b/app/scripts/migrations/024.js
@@ -0,0 +1,45 @@
+
+const version = 24
+
+/*
+
+This migration ensures that the from address in txParams is to lower case for
+all unapproved transactions
+
+*/
+
+const clone = require('clone')
+
+module.exports = {
+ version,
+
+ migrate: function (originalVersionedData) {
+ const versionedData = clone(originalVersionedData)
+ versionedData.meta.version = version
+ try {
+ const state = versionedData.data
+ const newState = transformState(state)
+ versionedData.data = newState
+ } catch (err) {
+ console.warn(`MetaMask Migration #${version}` + err.stack)
+ }
+ return Promise.resolve(versionedData)
+ },
+}
+
+function transformState (state) {
+ const newState = state
+ const transactions = newState.TransactionController.transactions
+
+ newState.TransactionController.transactions = transactions.map((txMeta, _, txList) => {
+ if (
+ txMeta.status === 'unapproved' &&
+ txMeta.txParams &&
+ txMeta.txParams.from
+ ) {
+ txMeta.txParams.from = txMeta.txParams.from.toLowerCase()
+ }
+ return txMeta
+ })
+ return newState
+}
diff --git a/app/scripts/migrations/index.js b/app/scripts/migrations/index.js
index 811e06b6b..7e4542740 100644
--- a/app/scripts/migrations/index.js
+++ b/app/scripts/migrations/index.js
@@ -34,4 +34,5 @@ module.exports = [
require('./021'),
require('./022'),
require('./023'),
+ require('./024'),
]