diff options
author | kumavis <aaron@kumavis.me> | 2017-08-04 06:05:32 +0800 |
---|---|---|
committer | kumavis <aaron@kumavis.me> | 2017-08-04 06:05:32 +0800 |
commit | da16f396266daa5ab0acc8f0c04d3e25b98c39f0 (patch) | |
tree | 44fad3fc645ac8165e4832259d8c6fe43196bccb /app/scripts/controllers/blacklist.js | |
parent | da7471e0958d30b4465ef35090dbfa05b85471f0 (diff) | |
download | tangerine-wallet-browser-da16f396266daa5ab0acc8f0c04d3e25b98c39f0.tar.gz tangerine-wallet-browser-da16f396266daa5ab0acc8f0c04d3e25b98c39f0.tar.zst tangerine-wallet-browser-da16f396266daa5ab0acc8f0c04d3e25b98c39f0.zip |
Merge branch 'master' of github.com:MetaMask/metamask-extension into greenkeeper/initial
Diffstat (limited to 'app/scripts/controllers/blacklist.js')
-rw-r--r-- | app/scripts/controllers/blacklist.js | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/app/scripts/controllers/blacklist.js b/app/scripts/controllers/blacklist.js new file mode 100644 index 000000000..7e01fa386 --- /dev/null +++ b/app/scripts/controllers/blacklist.js @@ -0,0 +1,58 @@ +const ObservableStore = require('obs-store') +const extend = require('xtend') +const PhishingDetector = require('eth-phishing-detect/src/detector') + +// compute phishing lists +const PHISHING_DETECTION_CONFIG = require('eth-phishing-detect/src/config.json') +// every ten minutes +const POLLING_INTERVAL = 10 * 60 * 1000 + +class BlacklistController { + + constructor (opts = {}) { + const initState = extend({ + phishing: PHISHING_DETECTION_CONFIG, + }, opts.initState) + this.store = new ObservableStore(initState) + // phishing detector + this._phishingDetector = null + this._setupPhishingDetector(initState.phishing) + // polling references + this._phishingUpdateIntervalRef = null + } + + // + // PUBLIC METHODS + // + + checkForPhishing (hostname) { + if (!hostname) return false + const { result } = this._phishingDetector.check(hostname) + return result + } + + async updatePhishingList () { + const response = await fetch('https://api.infura.io/v2/blacklist') + const phishing = await response.json() + this.store.updateState({ phishing }) + this._setupPhishingDetector(phishing) + return phishing + } + + scheduleUpdates () { + if (this._phishingUpdateIntervalRef) return + this._phishingUpdateIntervalRef = setInterval(() => { + this.updatePhishingList() + }, POLLING_INTERVAL) + } + + // + // PRIVATE METHODS + // + + _setupPhishingDetector (config) { + this._phishingDetector = new PhishingDetector(config) + } +} + +module.exports = BlacklistController |