blob: 11e26d5b2582fbad3c550e12fd29acfb910d3fc6 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
const ObservableStore = require('obs-store')
const extend = require('xtend')
const communityBlacklistedDomains = require('etheraddresslookup/blacklists/domains.json')
const communityWhitelistedDomains = require('etheraddresslookup/whitelists/domains.json')
const checkForPhishing = require('../lib/is-phish')
// compute phishing lists
const PHISHING_BLACKLIST = communityBlacklistedDomains.concat(['metamask.com'])
const PHISHING_WHITELIST = communityWhitelistedDomains.concat(['metamask.io', 'www.metamask.io'])
const PHISHING_FUZZYLIST = ['myetherwallet', 'myetheroll', 'ledgerwallet', 'metamask']
// every ten minutes
const POLLING_INTERVAL = 10 * 60 * 1000
class BlacklistController {
constructor (opts = {}) {
const initState = extend({
phishing: PHISHING_BLACKLIST,
}, opts.initState)
this.store = new ObservableStore(initState)
// polling references
this._phishingUpdateIntervalRef = null
}
//
// PUBLIC METHODS
//
checkForPhishing (hostname) {
if (!hostname) return false
const { blacklist } = this.store.getState()
return checkForPhishing({ hostname, blacklist, whitelist: PHISHING_WHITELIST, fuzzylist: PHISHING_FUZZYLIST })
}
async updatePhishingList () {
const response = await fetch('https://api.infura.io/v1/blacklist')
const phishing = await response.json()
this.store.updateState({ phishing })
return phishing
}
scheduleUpdates () {
if (this._phishingUpdateIntervalRef) return
this._phishingUpdateIntervalRef = setInterval(() => {
this.updatePhishingList()
}, POLLING_INTERVAL)
}
}
module.exports = BlacklistController
|