aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2017-07-28 06:10:02 +0800
committerDan Finlay <dan@danfinlay.com>2017-07-28 06:10:02 +0800
commitf8cadbcb323f2d41d6a2cad78479917f20b113bd (patch)
tree3f1dc1e4d399b26ef929d4a0d51ded3c11c814fc /app
parent8ba32d5ea8cbd30b85cade9fccaaa6c0f3f5cd04 (diff)
parente3b5bb2052d59afbf9c2761af883de719261062e (diff)
downloadtangerine-wallet-browser-f8cadbcb323f2d41d6a2cad78479917f20b113bd.tar
tangerine-wallet-browser-f8cadbcb323f2d41d6a2cad78479917f20b113bd.tar.gz
tangerine-wallet-browser-f8cadbcb323f2d41d6a2cad78479917f20b113bd.tar.bz2
tangerine-wallet-browser-f8cadbcb323f2d41d6a2cad78479917f20b113bd.tar.lz
tangerine-wallet-browser-f8cadbcb323f2d41d6a2cad78479917f20b113bd.tar.xz
tangerine-wallet-browser-f8cadbcb323f2d41d6a2cad78479917f20b113bd.tar.zst
tangerine-wallet-browser-f8cadbcb323f2d41d6a2cad78479917f20b113bd.zip
Merge branch 'master' into NewUI
Diffstat (limited to 'app')
-rw-r--r--app/manifest.json2
-rw-r--r--app/scripts/blacklister.js44
-rw-r--r--app/scripts/controllers/network.js5
-rw-r--r--app/scripts/controllers/transactions.js51
-rw-r--r--app/scripts/lib/nonce-tracker.js28
-rw-r--r--app/scripts/lib/util.js8
6 files changed, 104 insertions, 34 deletions
diff --git a/app/manifest.json b/app/manifest.json
index eadd99590..55e1eb5b1 100644
--- a/app/manifest.json
+++ b/app/manifest.json
@@ -1,7 +1,7 @@
{
"name": "MetaMask",
"short_name": "Metamask",
- "version": "3.9.1",
+ "version": "3.9.2",
"manifest_version": 2,
"author": "https://metamask.io",
"description": "Ethereum Browser Extension",
diff --git a/app/scripts/blacklister.js b/app/scripts/blacklister.js
index a45265a75..9337599cc 100644
--- a/app/scripts/blacklister.js
+++ b/app/scripts/blacklister.js
@@ -1,13 +1,41 @@
-const blacklistedDomains = require('etheraddresslookup/blacklists/domains.json')
+const levenshtein = require('fast-levenshtein')
+const blacklistedMetaMaskDomains = ['metamask.com']
+const blacklistedDomains = require('etheraddresslookup/blacklists/domains.json').concat(blacklistedMetaMaskDomains)
+const whitelistedMetaMaskDomains = ['metamask.io', 'www.metamask.io']
+const whitelistedDomains = require('etheraddresslookup/whitelists/domains.json').concat(whitelistedMetaMaskDomains)
+const LEVENSHTEIN_TOLERANCE = 4
+const LEVENSHTEIN_CHECKS = ['myetherwallet', 'myetheroll', 'ledgerwallet', 'metamask']
-function detectBlacklistedDomain() {
- var strCurrentTab = window.location.hostname
- if (blacklistedDomains && blacklistedDomains.includes(strCurrentTab)) {
- window.location.href = 'https://metamask.io/phishing.html'
- }
+
+// credit to @sogoiii and @409H for their help!
+// Return a boolean on whether or not a phish is detected.
+function isPhish(hostname) {
+ var strCurrentTab = hostname
+
+ // check if the domain is part of the whitelist.
+ if (whitelistedDomains && whitelistedDomains.includes(strCurrentTab)) { return false }
+
+ // check if the domain is part of the blacklist.
+ var isBlacklisted = blacklistedDomains && blacklistedDomains.includes(strCurrentTab)
+
+ // check for similar values.
+ var levenshteinMatched = false
+ var levenshteinForm = strCurrentTab.replace(/\./g, '')
+ LEVENSHTEIN_CHECKS.forEach((element) => {
+ if (levenshtein.get(element, levenshteinForm) < LEVENSHTEIN_TOLERANCE) {
+ levenshteinMatched = true
+ }
+ })
+
+ return isBlacklisted || levenshteinMatched
}
-window.addEventListener('load', function() {
- detectBlacklistedDomain()
+window.addEventListener('load', function () {
+ var hostnameToCheck = window.location.hostname
+ if (isPhish(hostnameToCheck)) {
+ // redirect to our phishing warning page.
+ window.location.href = 'https://metamask.io/phishing.html'
+ }
})
+module.exports = isPhish
diff --git a/app/scripts/controllers/network.js b/app/scripts/controllers/network.js
index c07f13b8d..0a3e5e26b 100644
--- a/app/scripts/controllers/network.js
+++ b/app/scripts/controllers/network.js
@@ -28,9 +28,9 @@ module.exports = class NetworkController extends EventEmitter {
this._provider = provider
}
- initializeProvider (opts) {
+ initializeProvider (opts, providerContructor = MetaMaskProvider) {
this.providerInit = opts
- this._provider = MetaMaskProvider(opts)
+ this._provider = providerContructor(opts)
this._proxy = new Proxy(this._provider, {
get: (obj, name) => {
if (name === 'on') return this._on.bind(this)
@@ -38,6 +38,7 @@ module.exports = class NetworkController extends EventEmitter {
},
set: (obj, name, value) => {
this._provider[name] = value
+ return value
},
})
this.provider.on('block', this._logBlock.bind(this))
diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js
index 5f3d84ebe..f71659042 100644
--- a/app/scripts/controllers/transactions.js
+++ b/app/scripts/controllers/transactions.js
@@ -1,10 +1,12 @@
const EventEmitter = require('events')
const async = require('async')
const extend = require('xtend')
+const clone = require('clone')
const ObservableStore = require('obs-store')
const ethUtil = require('ethereumjs-util')
const pify = require('pify')
const TxProviderUtil = require('../lib/tx-utils')
+const getStack = require('../lib/util').getStack
const createId = require('../lib/random-id')
const NonceTracker = require('../lib/nonce-tracker')
@@ -22,7 +24,6 @@ module.exports = class TransactionController extends EventEmitter {
this.blockTracker = opts.blockTracker
this.nonceTracker = new NonceTracker({
provider: this.provider,
- blockTracker: this.provider._blockTracker,
getPendingTransactions: (address) => {
return this.getFilteredTxList({
from: address,
@@ -117,6 +118,17 @@ module.exports = class TransactionController extends EventEmitter {
//
updateTx (txMeta) {
+ // create txMeta snapshot for history
+ const txMetaForHistory = clone(txMeta)
+ // dont include previous history in this snapshot
+ delete txMetaForHistory.history
+ // add stack to help understand why tx was updated
+ txMetaForHistory.stack = getStack()
+ // add snapshot to tx history
+ if (!txMeta.history) txMeta.history = []
+ txMeta.history.push(txMetaForHistory)
+
+ // update the tx
var txId = txMeta.id
var txList = this.getFullTxList()
var index = txList.findIndex(txData => txData.id === txId)
@@ -134,7 +146,7 @@ module.exports = class TransactionController extends EventEmitter {
}
addUnapprovedTransaction (txParams, done) {
- let txMeta
+ let txMeta = {}
async.waterfall([
// validate
(cb) => this.txProviderUtils.validateTxParams(txParams, cb),
@@ -146,6 +158,7 @@ module.exports = class TransactionController extends EventEmitter {
status: 'unapproved',
metamaskNetworkId: this.getNetwork(),
txParams: txParams,
+ history: [],
}
cb()
},
@@ -165,6 +178,7 @@ module.exports = class TransactionController extends EventEmitter {
txParams.value = txParams.value || '0x0'
if (!txParams.gasPrice) {
this.query.gasPrice((err, gasPrice) => {
+
if (err) return cb(err)
// set gasPrice
txParams.gasPrice = gasPrice
@@ -191,8 +205,12 @@ module.exports = class TransactionController extends EventEmitter {
// get next nonce
const txMeta = this.getTx(txId)
const fromAddress = txMeta.txParams.from
+ // wait for a nonce
nonceLock = await this.nonceTracker.getNonceLock(fromAddress)
+ // add nonce to txParams
txMeta.txParams.nonce = nonceLock.nextNonce
+ // add nonce debugging information to txMeta
+ txMeta.nonceDetails = nonceLock.nonceDetails
this.updateTx(txMeta)
// sign transaction
const rawTx = await this.signTransaction(txId)
@@ -201,6 +219,7 @@ module.exports = class TransactionController extends EventEmitter {
nonceLock.releaseLock()
} catch (err) {
this.setTxStatusFailed(txId, {
+ stack: err.stack || err.message,
errCode: err.errCode || err,
message: err.message || 'Transaction failed during approval',
})
@@ -364,11 +383,11 @@ module.exports = class TransactionController extends EventEmitter {
var txId = txMeta.id
if (!txHash) {
- const errReason = {
+ return this.setTxStatusFailed(txId, {
+ stack: 'checkForTxInBlock: custom tx-controller error message',
errCode: 'No hash was provided',
message: 'We had an error while submitting this transaction, please try again.',
- }
- return this.setTxStatusFailed(txId, errReason)
+ })
}
block.transactions.forEach((tx) => {
@@ -452,13 +471,14 @@ module.exports = class TransactionController extends EventEmitter {
if (isKnownTx) return
// encountered real error - transition to error state
this.setTxStatusFailed(txMeta.id, {
+ stack: err.stack || err.message,
errCode: err.errCode || err,
message: err.message,
})
}))
}
- async _resubmitTx (txMeta, cb) {
+ async _resubmitTx (txMeta) {
const address = txMeta.txParams.from
const balance = this.ethStore.getState().accounts[address].balance
if (!('retryCount' in txMeta)) txMeta.retryCount = 0
@@ -466,18 +486,21 @@ module.exports = class TransactionController extends EventEmitter {
// if the value of the transaction is greater then the balance, fail.
if (!this.txProviderUtils.sufficientBalance(txMeta.txParams, balance)) {
const message = 'Insufficient balance.'
- this.setTxStatusFailed(txMeta.id, { message })
- cb()
- return log.error(message)
+ this.setTxStatusFailed(txMeta.id, {
+ stack: '_resubmitTx: custom tx-controller error',
+ message,
+ })
+ log.error(message)
+ return
}
// Only auto-submit already-signed txs:
- if (!('rawTx' in txMeta)) return cb()
+ if (!('rawTx' in txMeta)) return
// Increment a try counter.
txMeta.retryCount++
const rawTx = txMeta.rawTx
- return await this.txProviderUtils.publishTransaction(rawTx, cb)
+ return await this.txProviderUtils.publishTransaction(rawTx)
}
// checks the network for signed txs and
@@ -501,11 +524,11 @@ module.exports = class TransactionController extends EventEmitter {
// extra check in case there was an uncaught error during the
// signature and submission process
if (!txHash) {
- const errReason = {
+ this.setTxStatusFailed(txId, {
+ stack: '_checkPendingTxs: custom tx-controller error message',
errCode: 'No hash was provided',
message: 'We had an error while submitting this transaction, please try again.',
- }
- this.setTxStatusFailed(txId, errReason)
+ })
return
}
// get latest transaction status
diff --git a/app/scripts/lib/nonce-tracker.js b/app/scripts/lib/nonce-tracker.js
index b76dac4e8..8328e81ec 100644
--- a/app/scripts/lib/nonce-tracker.js
+++ b/app/scripts/lib/nonce-tracker.js
@@ -4,8 +4,8 @@ const Mutex = require('await-semaphore').Mutex
class NonceTracker {
- constructor ({ blockTracker, provider, getPendingTransactions }) {
- this.blockTracker = blockTracker
+ constructor ({ provider, getPendingTransactions }) {
+ this.provider = provider
this.ethQuery = new EthQuery(provider)
this.getPendingTransactions = getPendingTransactions
this.lockMap = {}
@@ -31,21 +31,25 @@ class NonceTracker {
const currentBlock = await this._getCurrentBlock()
const pendingTransactions = this.getPendingTransactions(address)
const pendingCount = pendingTransactions.length
- assert(Number.isInteger(pendingCount), 'nonce-tracker - pendingCount is an integer')
+ assert(Number.isInteger(pendingCount), `nonce-tracker - pendingCount is not an integer - got: (${typeof pendingCount}) "${pendingCount}"`)
const baseCountHex = await this._getTxCount(address, currentBlock)
const baseCount = parseInt(baseCountHex, 16)
- assert(Number.isInteger(baseCount), 'nonce-tracker - baseCount is an integer')
+ assert(Number.isInteger(baseCount), `nonce-tracker - baseCount is not an integer - got: (${typeof baseCount}) "${baseCount}"`)
const nextNonce = baseCount + pendingCount
- assert(Number.isInteger(nextNonce), 'nonce-tracker - nextNonce is an integer')
- // return next nonce and release cb
- return { nextNonce, releaseLock }
+ assert(Number.isInteger(nextNonce), `nonce-tracker - nextNonce is not an integer - got: (${typeof nextNonce}) "${nextNonce}"`)
+ // collect the numbers used to calculate the nonce for debugging
+ const blockNumber = currentBlock.number
+ const nonceDetails = { blockNumber, baseCount, baseCountHex, pendingCount }
+ // return nonce and release cb
+ return { nextNonce, nonceDetails, releaseLock }
}
async _getCurrentBlock () {
- const currentBlock = this.blockTracker.getCurrentBlock()
+ const blockTracker = this._getBlockTracker()
+ const currentBlock = blockTracker.getCurrentBlock()
if (currentBlock) return currentBlock
return await Promise((reject, resolve) => {
- this.blockTracker.once('latest', resolve)
+ blockTracker.once('latest', resolve)
})
}
@@ -79,6 +83,12 @@ class NonceTracker {
return mutex
}
+ // this is a hotfix for the fact that the blockTracker will
+ // change when the network changes
+ _getBlockTracker () {
+ return this.provider._blockTracker
+ }
+
}
module.exports = NonceTracker
diff --git a/app/scripts/lib/util.js b/app/scripts/lib/util.js
new file mode 100644
index 000000000..bddd60ee8
--- /dev/null
+++ b/app/scripts/lib/util.js
@@ -0,0 +1,8 @@
+module.exports = {
+ getStack,
+}
+
+function getStack () {
+ const stack = new Error('Stack trace generator - not an error').stack
+ return stack
+}