diff options
author | Frankie <frankie.diamond@gmail.com> | 2017-04-05 15:30:07 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-05 15:30:07 +0800 |
commit | dd6b4505f41b80a4f4cd3654412349b262c3cd76 (patch) | |
tree | 571a16459cffbe85f757e35df9c81a601959756b /mascara | |
parent | 5d967eeebb9f3cf4c2d3fcfe0b74cf6e8440c3cb (diff) | |
parent | 1aac162b462424f5b6ce6685f337670368bd10b5 (diff) | |
download | tangerine-wallet-browser-dd6b4505f41b80a4f4cd3654412349b262c3cd76.tar tangerine-wallet-browser-dd6b4505f41b80a4f4cd3654412349b262c3cd76.tar.gz tangerine-wallet-browser-dd6b4505f41b80a4f4cd3654412349b262c3cd76.tar.bz2 tangerine-wallet-browser-dd6b4505f41b80a4f4cd3654412349b262c3cd76.tar.lz tangerine-wallet-browser-dd6b4505f41b80a4f4cd3654412349b262c3cd76.tar.xz tangerine-wallet-browser-dd6b4505f41b80a4f4cd3654412349b262c3cd76.tar.zst tangerine-wallet-browser-dd6b4505f41b80a4f4cd3654412349b262c3cd76.zip |
Merge pull request #1309 from MetaMask/mascara2
Mascara - various fixes
Diffstat (limited to 'mascara')
-rw-r--r-- | mascara/example/app.js (renamed from mascara/example/index.js) | 0 | ||||
-rw-r--r-- | mascara/example/app/index.html (renamed from mascara/example/index.html) | 4 | ||||
-rw-r--r-- | mascara/example/server.js | 31 | ||||
-rw-r--r-- | mascara/proxy/index.html (renamed from mascara/server/index.html) | 2 | ||||
-rw-r--r-- | mascara/server.js | 103 | ||||
-rw-r--r-- | mascara/server/index.js | 32 | ||||
-rw-r--r-- | mascara/server/util.js | 45 | ||||
-rw-r--r-- | mascara/src/background.js | 8 | ||||
-rw-r--r-- | mascara/src/lib/setup-provider.js | 4 | ||||
-rw-r--r-- | mascara/src/mascara.js | 15 | ||||
-rw-r--r-- | mascara/src/proxy.js (renamed from mascara/src/dapp-connection.js) | 2 | ||||
-rw-r--r-- | mascara/src/ui.js (renamed from mascara/src/popup.js) | 9 | ||||
-rw-r--r-- | mascara/ui/index.html | 11 |
13 files changed, 149 insertions, 117 deletions
diff --git a/mascara/example/index.js b/mascara/example/app.js index aae7ccd19..aae7ccd19 100644 --- a/mascara/example/index.js +++ b/mascara/example/app.js diff --git a/mascara/example/index.html b/mascara/example/app/index.html index 47d6da34f..02323e5f9 100644 --- a/mascara/example/index.html +++ b/mascara/example/app/index.html @@ -3,15 +3,13 @@ <html lang="en"> <head> <meta charset="utf-8"> - <title>MetaMask ZeroClient Example</title> - + <script src="http://localhost:9001/metamascara.js"></script> </head> <body> <button class="action-button-1">SYNC TX</button> <button class="action-button-2">ASYNC TX</button> - <script src="./zero.js"></script> <script src="./app.js"></script> </body> </html>
\ No newline at end of file diff --git a/mascara/example/server.js b/mascara/example/server.js new file mode 100644 index 000000000..d39c19600 --- /dev/null +++ b/mascara/example/server.js @@ -0,0 +1,31 @@ +const express = require('express') +const createMetamascaraServer = require('../server/') +const createBundle = require('../server/util').createBundle +const serveBundle = require('../server/util').serveBundle + +// +// Iframe Server +// + +const mascaraServer = createMetamascaraServer() + +// start the server +const mascaraPort = 9001 +mascaraServer.listen(mascaraPort) +console.log(`Mascara service listening on port ${mascaraPort}`) + + +// +// Dapp Server +// + +const dappServer = express() + +// serve dapp bundle +serveBundle(dappServer, '/app.js', createBundle(require.resolve('./app.js'))) +dappServer.use(express.static(__dirname + '/app/')) + +// start the server +const dappPort = '9002' +dappServer.listen(dappPort) +console.log(`Dapp listening on port ${dappPort}`) diff --git a/mascara/server/index.html b/mascara/proxy/index.html index 2308dd98b..b83fc41af 100644 --- a/mascara/server/index.html +++ b/mascara/proxy/index.html @@ -15,6 +15,6 @@ <body> Hello! I am the MetaMask iframe. - <script src="/controller.js"></script> + <script src="./proxy.js"></script> </body> </html>
\ No newline at end of file diff --git a/mascara/server.js b/mascara/server.js deleted file mode 100644 index 67c89f11b..000000000 --- a/mascara/server.js +++ /dev/null @@ -1,103 +0,0 @@ -const express = require('express') -const browserify = require('browserify') -const watchify = require('watchify') -const babelify = require('babelify') - -const zeroBundle = createBundle('./src/mascara.js') -const controllerBundle = createBundle('./src/dapp-connection.js') -const popupBundle = createBundle('./src/popup.js') -const swBuild = createBundle('./src/background.js') - -const appBundle = createBundle('./example/index.js') - -// -// Iframe Server -// - -const iframeServer = express() - -// serve popup window -iframeServer.get('/popup/scripts/popup.js', function(req, res){ - res.send(popupBundle.latest) -}) -iframeServer.use('/popup', express.static('../dist/chrome')) - -// serve controller bundle -iframeServer.get('/controller.js', function(req, res){ - res.send(controllerBundle.latest) -}) -iframeServer.get('/popup/sw-build.js', function(req, res){ - console.log('/sw-build.js') - res.setHeader('Content-Type', 'application/javascript') - res.send(swBuild.latest) -}) - -// serve background controller -iframeServer.use(express.static('./server')) - -// start the server -const mascaraPort = 9001 -iframeServer.listen(mascaraPort) -console.log(`Mascara service listening on port ${mascaraPort}`) - - -// -// Dapp Server -// - -const dappServer = express() - -// serve metamask-lib bundle -dappServer.get('/zero.js', function(req, res){ - res.send(zeroBundle.latest) -}) - -// serve dapp bundle -dappServer.get('/app.js', function(req, res){ - res.send(appBundle.latest) -}) - -// serve static -dappServer.use(express.static('./example')) - -// start the server -const dappPort = '9002' -dappServer.listen(dappPort) -console.log(`Dapp listening on port ${dappPort}`) - -// -// util -// - -function serveBundle(entryPoint){ - const bundle = createBundle(entryPoint) - return function(req, res){ - res.send(bundle.latest) - } -} - -function createBundle(entryPoint){ - - var bundleContainer = {} - - var bundler = browserify({ - entries: [entryPoint], - cache: {}, - packageCache: {}, - plugin: [watchify], - }) - - bundler.on('update', bundle) - bundle() - - return bundleContainer - - function bundle() { - bundler.bundle(function(err, result){ - if (err) throw err - console.log(`Bundle updated! (${entryPoint})`) - bundleContainer.latest = result.toString() - }) - } - -} diff --git a/mascara/server/index.js b/mascara/server/index.js new file mode 100644 index 000000000..9fd664eee --- /dev/null +++ b/mascara/server/index.js @@ -0,0 +1,32 @@ +const express = require('express') +const createBundle = require('./util').createBundle +const serveBundle = require('./util').serveBundle + +module.exports = createMetamascaraServer + + +function createMetamascaraServer(){ + + // start bundlers + const metamascaraBundle = createBundle('./src/mascara.js') + const proxyBundle = createBundle('./src/proxy.js') + const uiBundle = createBundle('./src/ui.js') + const backgroundBuild = createBundle('./src/background.js') + + // serve bundles + const server = express() + // ui window + serveBundle(server, '/ui.js', uiBundle) + server.use(express.static(__dirname+'/../ui/')) + server.use(express.static(__dirname+'/../../dist/chrome')) + // metamascara + serveBundle(server, '/metamascara.js', metamascaraBundle) + // proxy + serveBundle(server, '/proxy/proxy.js', proxyBundle) + server.use('/proxy/', express.static(__dirname+'/../proxy')) + // background + serveBundle(server, '/background.js', backgroundBuild) + + return server + +} diff --git a/mascara/server/util.js b/mascara/server/util.js new file mode 100644 index 000000000..6e25b35d8 --- /dev/null +++ b/mascara/server/util.js @@ -0,0 +1,45 @@ +const browserify = require('browserify') +const watchify = require('watchify') + +module.exports = { + serveBundle, + createBundle, +} + + +function serveBundle(server, path, bundle){ + server.get(path, function(req, res){ + res.setHeader('Content-Type', 'application/javascript; charset=UTF-8') + res.send(bundle.latest) + }) +} + +function createBundle(entryPoint){ + + var bundleContainer = {} + + var bundler = browserify({ + entries: [entryPoint], + cache: {}, + packageCache: {}, + plugin: [watchify], + }) + + bundler.on('update', bundle) + bundle() + + return bundleContainer + + function bundle() { + bundler.bundle(function(err, result){ + if (err) { + console.log(`Bundle failed! (${entryPoint})`) + console.error(err) + return + } + console.log(`Bundle updated! (${entryPoint})`) + bundleContainer.latest = result.toString() + }) + } + +} diff --git a/mascara/src/background.js b/mascara/src/background.js index 6f9fb3d13..957570050 100644 --- a/mascara/src/background.js +++ b/mascara/src/background.js @@ -8,6 +8,7 @@ const PortStream = require('../../app/scripts/lib/port-stream.js') const DbController = require('./lib/index-db-controller') +const SwPlatform = require('../../app/scripts/platforms/sw') const MetamaskController = require('../../app/scripts/metamask-controller') const extension = {} //require('../../app/scripts/lib/extension') @@ -17,7 +18,8 @@ const migrations = require('../../app/scripts/migrations/') const firstTimeState = require('../../app/scripts/first-time-state') const STORAGE_KEY = 'metamask-config' -const METAMASK_DEBUG = 'GULP_METAMASK_DEBUG' +// const METAMASK_DEBUG = 'GULP_METAMASK_DEBUG' +const METAMASK_DEBUG = true let popupIsOpen = false const log = require('loglevel') @@ -70,7 +72,11 @@ function setupController (initState, client) { // MetaMask Controller // + const platform = new SwPlatform() + const controller = new MetamaskController({ + // platform specific implementation + platform, // User confirmation callbacks: showUnconfirmedMessage: noop, unlockAccountMessage: noop, diff --git a/mascara/src/lib/setup-provider.js b/mascara/src/lib/setup-provider.js index 4f2432ae4..62335b18d 100644 --- a/mascara/src/lib/setup-provider.js +++ b/mascara/src/lib/setup-provider.js @@ -4,14 +4,14 @@ const MetamaskInpageProvider = require('../../../app/scripts/lib/inpage-provider module.exports = getProvider -function getProvider(){ +function getProvider(opts){ if (global.web3) { console.log('MetaMask ZeroClient - using environmental web3 provider') return global.web3.currentProvider } console.log('MetaMask ZeroClient - injecting zero-client iframe!') var iframeStream = setupIframe({ - zeroClientProvider: 'http://localhost:9001', + zeroClientProvider: opts.mascaraUrl, sandboxAttributes: ['allow-scripts', 'allow-popups', 'allow-same-origin'], container: document.body, }) diff --git a/mascara/src/mascara.js b/mascara/src/mascara.js index 759353c1b..f9bed7e52 100644 --- a/mascara/src/mascara.js +++ b/mascara/src/mascara.js @@ -1,15 +1,22 @@ const Web3 = require('web3') const setupProvider = require('./lib/setup-provider.js') +const MASACARA_DOMAIN = 'http://localhost:9001' + // // setup web3 // -var provider = setupProvider() -hijackProvider(provider) + +var provider = setupProvider({ + mascaraUrl: MASACARA_DOMAIN + '/proxy/', +}) +instrumentForUserInteractionTriggers(provider) + var web3 = new Web3(provider) web3.setProvider = function(){ console.log('MetaMask - overrode web3.setProvider') } + // // // export web3 @@ -25,12 +32,12 @@ var shouldPop = false window.addEventListener('click', function(){ if (!shouldPop) return shouldPop = false - window.open('http://localhost:9001/popup/popup.html', '', 'width=360 height=500') + window.open(MASACARA_DOMAIN, '', 'width=360 height=500') console.log('opening window...') }) -function hijackProvider(provider){ +function instrumentForUserInteractionTriggers(provider){ var _super = provider.sendAsync.bind(provider) provider.sendAsync = function(payload, cb){ if (payload.method === 'eth_sendTransaction') { diff --git a/mascara/src/dapp-connection.js b/mascara/src/proxy.js index 30680c9d7..e580076c1 100644 --- a/mascara/src/dapp-connection.js +++ b/mascara/src/proxy.js @@ -4,7 +4,7 @@ const SwStream = require('sw-stream/lib/sw-stream.js') const SetupUntrustedComunication = ('./lib/setup-untrusted-connection.js') const background = new SWcontroller({ - fileName: '/popup/sw-build.js', + fileName: '/background.js', }) const pageStream = new ParentStream() diff --git a/mascara/src/popup.js b/mascara/src/ui.js index ef7759a81..c4866867b 100644 --- a/mascara/src/popup.js +++ b/mascara/src/ui.js @@ -4,8 +4,13 @@ const SwStream = require('sw-stream/lib/sw-stream.js') const MetaMaskUiCss = require('../../ui/css') const setupIframe = require('./lib/setup-iframe.js') const MetamaskInpageProvider = require('../../app/scripts/lib/inpage-provider.js') +const MetamascaraPlatform = require('../../app/scripts/platforms/window') const startPopup = require('../../app/scripts/popup-core') +// create platform global +global.platform = new MetamascaraPlatform() + + var css = MetaMaskUiCss() injectCss(css) const container = document.getElementById('app-content') @@ -14,7 +19,7 @@ var name = 'popup' window.METAMASK_UI_TYPE = name const background = new SWcontroller({ - fileName: '/popup/sw-build.js', + fileName: '/background.js', }) // Setup listener for when the service worker is read @@ -33,4 +38,4 @@ background.on('ready', (readSw) => { }) background.startWorker() -console.log('hello from /library/popup.js') +console.log('hello from MetaMascara ui!') diff --git a/mascara/ui/index.html b/mascara/ui/index.html new file mode 100644 index 000000000..c5eeb05ef --- /dev/null +++ b/mascara/ui/index.html @@ -0,0 +1,11 @@ +<!doctype html> +<html> + <head> + <meta charset="utf-8"> + <title>MetaMask Plugin</title> + </head> + <body> + <div id="app-content"></div> + <script src="./ui.js" type="text/javascript" charset="utf-8"></script> + </body> +</html>
\ No newline at end of file |