2020-01-09 04:34:58 +01:00
|
|
|
import querystring from 'querystring'
|
|
|
|
import { EventEmitter } from 'events'
|
2020-08-18 21:18:25 +02:00
|
|
|
import dnode from 'dnode'
|
2020-01-09 04:34:58 +01:00
|
|
|
import PortStream from 'extension-port-stream'
|
|
|
|
import extension from 'extensionizer'
|
2020-08-14 13:46:45 +02:00
|
|
|
import { setupMultiplex } from './lib/stream-utils'
|
2020-01-09 04:34:58 +01:00
|
|
|
import { getEnvironmentType } from './lib/util'
|
|
|
|
import ExtensionPlatform from './platforms/extension'
|
2018-10-02 02:00:40 +02:00
|
|
|
|
|
|
|
document.addEventListener('DOMContentLoaded', start)
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
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-11-03 00:41:28 +01: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)
|
2020-11-03 00:41:28 +01:00
|
|
|
setupControllerConnection(
|
|
|
|
mx.createStream('controller'),
|
|
|
|
(err, metaMaskController) => {
|
|
|
|
if (err) {
|
|
|
|
return
|
|
|
|
}
|
2018-10-02 02:00:40 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
const continueLink = document.getElementById('unsafe-continue')
|
|
|
|
continueLink.addEventListener('click', () => {
|
|
|
|
metaMaskController.safelistPhishingDomain(suspect.hostname)
|
|
|
|
window.location.href = suspect.href
|
|
|
|
})
|
|
|
|
},
|
|
|
|
)
|
2018-10-02 02:00:40 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
function setupControllerConnection(connectionStream, cb) {
|
2018-10-02 02:00:40 +02:00
|
|
|
const eventEmitter = new EventEmitter()
|
2019-07-10 21:01:48 +02:00
|
|
|
const metaMaskControllerDnode = dnode({
|
2020-11-03 00:41:28 +01:00
|
|
|
sendUpdate(state) {
|
2018-10-02 02:00:40 +02:00
|
|
|
eventEmitter.emit('update', state)
|
|
|
|
},
|
|
|
|
})
|
2019-07-10 21:01:48 +02:00
|
|
|
connectionStream.pipe(metaMaskControllerDnode).pipe(connectionStream)
|
2020-11-03 00:41:28 +01:00
|
|
|
metaMaskControllerDnode.once('remote', (backgroundConnection) =>
|
|
|
|
cb(null, backgroundConnection),
|
|
|
|
)
|
2018-10-02 02:00:40 +02:00
|
|
|
}
|