2020-01-09 04:34:58 +01:00
|
|
|
import querystring from 'querystring'
|
|
|
|
import dnode from 'dnode'
|
|
|
|
import { EventEmitter } from 'events'
|
|
|
|
import PortStream from 'extension-port-stream'
|
|
|
|
import extension from 'extensionizer'
|
|
|
|
import { setupMultiplex } from './lib/stream-utils.js'
|
|
|
|
import { getEnvironmentType } from './lib/util'
|
|
|
|
import ExtensionPlatform from './platforms/extension'
|
2018-10-02 02:00:40 +02:00
|
|
|
|
|
|
|
document.addEventListener('DOMContentLoaded', start)
|
|
|
|
|
|
|
|
function start () {
|
2018-12-13 15:37:21 +01:00
|
|
|
const hash = window.location.hash.substring(1)
|
|
|
|
const suspect = querystring.parse(hash)
|
|
|
|
|
2020-02-03 21:15:53 +01:00
|
|
|
document.getElementById('csdbLink').href = `https://cryptoscamdb.org/search`
|
2018-10-02 02:00:40 +02:00
|
|
|
|
|
|
|
global.platform = new ExtensionPlatform()
|
|
|
|
|
2020-04-02 00:28:10 +02:00
|
|
|
const extensionPort = extension.runtime.connect({ name: getEnvironmentType() })
|
2018-10-02 02:00:40 +02:00
|
|
|
const connectionStream = new PortStream(extensionPort)
|
|
|
|
const mx = setupMultiplex(connectionStream)
|
|
|
|
setupControllerConnection(mx.createStream('controller'), (err, metaMaskController) => {
|
|
|
|
if (err) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
const continueLink = document.getElementById('unsafe-continue')
|
|
|
|
continueLink.addEventListener('click', () => {
|
2020-06-08 20:06:37 +02:00
|
|
|
metaMaskController.safelistPhishingDomain(suspect.hostname)
|
2018-12-13 15:37:21 +01:00
|
|
|
window.location.href = suspect.href
|
2018-10-02 02:00:40 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function setupControllerConnection (connectionStream, cb) {
|
|
|
|
const eventEmitter = new EventEmitter()
|
2019-07-10 21:01:48 +02:00
|
|
|
const metaMaskControllerDnode = dnode({
|
2018-10-02 02:00:40 +02:00
|
|
|
sendUpdate (state) {
|
|
|
|
eventEmitter.emit('update', state)
|
|
|
|
},
|
|
|
|
})
|
2019-07-10 21:01:48 +02:00
|
|
|
connectionStream.pipe(metaMaskControllerDnode).pipe(connectionStream)
|
|
|
|
metaMaskControllerDnode.once('remote', (backgroundConnection) => cb(null, backgroundConnection))
|
2018-10-02 02:00:40 +02:00
|
|
|
}
|