aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib
diff options
context:
space:
mode:
authorfrankiebee <frankie.diamond@gmail.com>2017-08-02 23:41:29 +0800
committerfrankiebee <frankie.diamond@gmail.com>2017-08-02 23:41:29 +0800
commit25cffd21f8defdf5a1bf139bdc2e3b1cfd08c220 (patch)
tree8e8f6225578722fb825ec0d98b2ff73b94f543d9 /app/scripts/lib
parentece9200c72cd0b53ee237263933b2b9a24ae5802 (diff)
parentd15e402ed87bf7533250c49a7972a7b1a12c99c2 (diff)
downloadtangerine-wallet-browser-25cffd21f8defdf5a1bf139bdc2e3b1cfd08c220.tar.gz
tangerine-wallet-browser-25cffd21f8defdf5a1bf139bdc2e3b1cfd08c220.tar.zst
tangerine-wallet-browser-25cffd21f8defdf5a1bf139bdc2e3b1cfd08c220.zip
Merge branch 'master' into transactionControllerRefractor
Diffstat (limited to 'app/scripts/lib')
-rw-r--r--app/scripts/lib/is-phish.js38
-rw-r--r--app/scripts/lib/nonce-tracker.js28
2 files changed, 57 insertions, 9 deletions
diff --git a/app/scripts/lib/is-phish.js b/app/scripts/lib/is-phish.js
new file mode 100644
index 000000000..68c09e4ac
--- /dev/null
+++ b/app/scripts/lib/is-phish.js
@@ -0,0 +1,38 @@
+const levenshtein = require('fast-levenshtein')
+const blacklistedMetaMaskDomains = ['metamask.com']
+let 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']
+
+
+// credit to @sogoiii and @409H for their help!
+// Return a boolean on whether or not a phish is detected.
+function isPhish({ hostname, updatedBlacklist = null }) {
+ var strCurrentTab = hostname
+
+ // check if the domain is part of the whitelist.
+ if (whitelistedDomains && whitelistedDomains.includes(strCurrentTab)) { return false }
+
+ // Allow updating of blacklist:
+ if (updatedBlacklist) {
+ blacklistedDomains = blacklistedDomains.concat(updatedBlacklist)
+ }
+
+ // check if the domain is part of the blacklist.
+ const isBlacklisted = blacklistedDomains && blacklistedDomains.includes(strCurrentTab)
+
+ // check for similar values.
+ let levenshteinMatched = false
+ var levenshteinForm = strCurrentTab.replace(/\./g, '')
+ LEVENSHTEIN_CHECKS.forEach((element) => {
+ if (levenshtein.get(element, levenshteinForm) <= LEVENSHTEIN_TOLERANCE) {
+ levenshteinMatched = true
+ }
+ })
+
+ return isBlacklisted || levenshteinMatched
+}
+
+module.exports = isPhish
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