11const ObservableStore = require ( 'obs-store' )
22const extend = require ( 'xtend' )
3- const communityBlacklistedDomains = require ( 'etheraddresslookup/blacklists/domains.json' )
4- const communityWhitelistedDomains = require ( 'etheraddresslookup/whitelists/domains.json' )
5- const checkForPhishing = require ( '../lib/is-phish' )
3+ const PhishingDetector = require ( 'eth-phishing-detect/src/detector' )
64
75// compute phishing lists
8- const PHISHING_BLACKLIST = communityBlacklistedDomains . concat ( [ 'metamask.com' ] )
9- const PHISHING_WHITELIST = communityWhitelistedDomains . concat ( [ 'metamask.io' , 'www.metamask.io' ] )
10- const PHISHING_FUZZYLIST = [ 'myetherwallet' , 'myetheroll' , 'ledgerwallet' , 'metamask' ]
6+ const PHISHING_DETECTION_CONFIG = require ( 'eth-phishing-detect/src/config.json' )
117// every ten minutes
128const POLLING_INTERVAL = 10 * 60 * 1000
139
1410class BlacklistController {
1511
1612 constructor ( opts = { } ) {
1713 const initState = extend ( {
18- phishing : PHISHING_BLACKLIST ,
14+ phishing : PHISHING_DETECTION_CONFIG ,
1915 } , opts . initState )
2016 this . store = new ObservableStore ( initState )
17+ // phishing detector
18+ this . _phishingDetector = null
19+ this . _setupPhishingDetector ( initState . phishing )
2120 // polling references
2221 this . _phishingUpdateIntervalRef = null
2322 }
@@ -28,14 +27,15 @@ class BlacklistController {
2827
2928 checkForPhishing ( hostname ) {
3029 if ( ! hostname ) return false
31- const { blacklist } = this . store . getState ( )
32- return checkForPhishing ( { hostname , blacklist , whitelist : PHISHING_WHITELIST , fuzzylist : PHISHING_FUZZYLIST } )
30+ const { result } = this . _phishingDetector . check ( hostname )
31+ return result
3332 }
3433
3534 async updatePhishingList ( ) {
36- const response = await fetch ( 'https://api.infura.io/v1 /blacklist' )
35+ const response = await fetch ( 'https://api.infura.io/v2 /blacklist' )
3736 const phishing = await response . json ( )
3837 this . store . updateState ( { phishing } )
38+ this . _setupPhishingDetector ( phishing )
3939 return phishing
4040 }
4141
@@ -45,6 +45,14 @@ class BlacklistController {
4545 this . updatePhishingList ( )
4646 } , POLLING_INTERVAL )
4747 }
48+
49+ //
50+ // PRIVATE METHODS
51+ //
52+
53+ _setupPhishingDetector ( config ) {
54+ this . _phishingDetector = new PhishingDetector ( config )
55+ }
4856}
4957
5058module . exports = BlacklistController
0 commit comments