mascara - remove from project (#6283)
parent
70e7e592ae
commit
48047f8194
@ -1,25 +0,0 @@ |
||||
FROM node:7 |
||||
MAINTAINER kumavis |
||||
|
||||
# setup app dir |
||||
RUN mkdir -p /www/ |
||||
WORKDIR /www/ |
||||
|
||||
# install dependencies |
||||
COPY ./package.json /www/package.json |
||||
# RUN npm install -g node-gyp |
||||
RUN npm install >> npm_log 2>> npm_err || true |
||||
|
||||
RUN cat npm_log && cat npm_err |
||||
|
||||
# copy over app dir |
||||
COPY ./ /www/ |
||||
|
||||
# run tests |
||||
# RUN npm test |
||||
|
||||
# build app |
||||
RUN npm run dist |
||||
|
||||
# start server |
||||
CMD node mascara/example/server.js |
@ -1,11 +0,0 @@ |
||||
metamascara: |
||||
build: ./ |
||||
restart: always |
||||
ports: |
||||
- "9001" |
||||
environment: |
||||
MASCARA_ORIGIN: "https://wallet.metamask.io" |
||||
VIRTUAL_PORT: "9001" |
||||
VIRTUAL_HOST: "wallet.metamask.io" |
||||
LETSENCRYPT_HOST: "wallet.metamask.io" |
||||
LETSENCRYPT_EMAIL: "admin@metamask.io" |
@ -1,33 +0,0 @@ |
||||
start the dual servers (dapp + mascara) |
||||
``` |
||||
npm run mascara |
||||
``` |
||||
|
||||
### First time use: |
||||
|
||||
- navigate to: http://localhost:9001 |
||||
- Create an Account |
||||
- go back to http://localhost:9002 |
||||
- open devTools |
||||
- click Sync Tx |
||||
|
||||
### Tests: |
||||
|
||||
``` |
||||
npm run testMascara |
||||
``` |
||||
|
||||
Test will run in browser, you will have to have these browsers installed: |
||||
|
||||
- Chrome |
||||
- Firefox |
||||
- Opera |
||||
|
||||
|
||||
### Deploy: |
||||
|
||||
Will build and deploy mascara via docker |
||||
|
||||
``` |
||||
docker-compose build && docker-compose stop && docker-compose up -d && docker-compose logs --tail 200 -f |
||||
``` |
@ -1,38 +0,0 @@ |
||||
const EthQuery = require('ethjs-query') |
||||
|
||||
window.addEventListener('load', loadProvider) |
||||
window.addEventListener('message', console.warn) |
||||
|
||||
async function loadProvider () { |
||||
const ethereumProvider = window.metamask.createDefaultProvider({ host: 'http://localhost:9001' }) |
||||
const ethQuery = new EthQuery(ethereumProvider) |
||||
const accounts = await ethQuery.accounts() |
||||
window.METAMASK_ACCOUNT = accounts[0] || 'locked' |
||||
logToDom(accounts.length ? accounts[0] : 'LOCKED or undefined', 'account') |
||||
setupButtons(ethQuery) |
||||
} |
||||
|
||||
|
||||
function logToDom (message, context) { |
||||
document.getElementById(context).innerText = message |
||||
console.log(message) |
||||
} |
||||
|
||||
function setupButtons (ethQuery) { |
||||
const accountButton = document.getElementById('action-button-1') |
||||
accountButton.addEventListener('click', async () => { |
||||
const accounts = await ethQuery.accounts() |
||||
window.METAMASK_ACCOUNT = accounts[0] || 'locked' |
||||
logToDom(accounts.length ? accounts[0] : 'LOCKED or undefined', 'account') |
||||
}) |
||||
const txButton = document.getElementById('action-button-2') |
||||
txButton.addEventListener('click', async () => { |
||||
if (!window.METAMASK_ACCOUNT || window.METAMASK_ACCOUNT === 'locked') return |
||||
const txHash = await ethQuery.sendTransaction({ |
||||
from: window.METAMASK_ACCOUNT, |
||||
to: window.METAMASK_ACCOUNT, |
||||
data: '', |
||||
}) |
||||
logToDom(txHash, 'cb-value') |
||||
}) |
||||
} |
@ -1,17 +0,0 @@ |
||||
<!doctype html> |
||||
|
||||
<html lang="en"> |
||||
<head> |
||||
<meta charset="utf-8"> |
||||
<script src="http://localhost:9001/metamascara.js"></script> |
||||
<title>MetaMask ZeroClient Example</title> |
||||
</head> |
||||
|
||||
<body> |
||||
<button id="action-button-1">GET ACCOUNT</button> |
||||
<div id="account"></div> |
||||
<button id="action-button-2">SEND TRANSACTION</button> |
||||
<div id="cb-value" ></div> |
||||
<script src="./app.js"></script> |
||||
</body> |
||||
</html> |
@ -1,31 +0,0 @@ |
||||
const express = require('express') |
||||
const path = require('path') |
||||
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(path.join(__dirname, '/app/'))) |
||||
|
||||
// start the server
|
||||
const dappPort = '9002' |
||||
dappServer.listen(dappPort) |
||||
console.log(`Dapp listening on port ${dappPort}`) |
@ -1,20 +0,0 @@ |
||||
<!doctype html> |
||||
|
||||
<html lang="en"> |
||||
<head> |
||||
<meta charset="utf-8"> |
||||
|
||||
<title>MetaMask ZeroClient Iframe</title> |
||||
<meta name="description" content="MetaMask ZeroClient"> |
||||
<meta name="author" content="MetaMask"> |
||||
|
||||
<!--[if lt IE 9]> |
||||
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> |
||||
<![endif]--> |
||||
</head> |
||||
|
||||
<body> |
||||
Hello! I am the MetaMask iframe. |
||||
<script src="./proxy.js"></script> |
||||
</body> |
||||
</html> |
@ -1,21 +0,0 @@ |
||||
const path = require('path') |
||||
const express = require('express') |
||||
const compression = require('compression') |
||||
|
||||
module.exports = createMetamascaraServer |
||||
|
||||
|
||||
function createMetamascaraServer () { |
||||
|
||||
// setup server
|
||||
const server = express() |
||||
server.use(compression()) |
||||
|
||||
// serve assets
|
||||
server.use(express.static(path.join(__dirname, '/../ui/'), { setHeaders: (res) => res.set('X-Frame-Options', 'DENY') })) |
||||
server.use(express.static(path.join(__dirname, '/../../dist/mascara'))) |
||||
server.use(express.static(path.join(__dirname, '/../proxy'))) |
||||
|
||||
return server |
||||
|
||||
} |
@ -1,47 +0,0 @@ |
||||
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], |
||||
}) |
||||
.transform('babelify') |
||||
.transform('uglifyify', { global: true }) |
||||
|
||||
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() |
||||
}) |
||||
} |
||||
|
||||
} |
@ -1,134 +0,0 @@ |
||||
global.window = global |
||||
|
||||
const SwGlobalListener = require('sw-stream/lib/sw-global-listener.js') |
||||
const connectionListener = new SwGlobalListener(global) |
||||
const setupMultiplex = require('../../app/scripts/lib/stream-utils.js').setupMultiplex |
||||
|
||||
const DbController = require('idb-global') |
||||
|
||||
const SwPlatform = require('../../app/scripts/platforms/sw') |
||||
const MetamaskController = require('../../app/scripts/metamask-controller') |
||||
|
||||
const Migrator = require('../../app/scripts/lib/migrator/') |
||||
const migrations = require('../../app/scripts/migrations/') |
||||
const firstTimeState = require('../../app/scripts/first-time-state') |
||||
|
||||
const STORAGE_KEY = 'metamask-config' |
||||
const METAMASK_DEBUG = process.env.METAMASK_DEBUG |
||||
global.metamaskPopupIsOpen = false |
||||
|
||||
const log = require('loglevel') |
||||
global.log = log |
||||
log.setDefaultLevel(METAMASK_DEBUG ? 'debug' : 'warn') |
||||
|
||||
global.addEventListener('install', function (event) { |
||||
event.waitUntil(global.skipWaiting()) |
||||
}) |
||||
global.addEventListener('activate', function (event) { |
||||
event.waitUntil(global.clients.claim()) |
||||
}) |
||||
|
||||
log.debug('inside:open') |
||||
|
||||
// state persistence
|
||||
const dbController = new DbController({ |
||||
key: STORAGE_KEY, |
||||
}) |
||||
|
||||
start().catch(log.error) |
||||
|
||||
async function start () { |
||||
log.debug('MetaMask initializing...') |
||||
const initState = await loadStateFromPersistence() |
||||
await setupController(initState) |
||||
log.debug('MetaMask initialization complete.') |
||||
} |
||||
|
||||
//
|
||||
// State and Persistence
|
||||
//
|
||||
async function loadStateFromPersistence () { |
||||
// migrations
|
||||
const migrator = new Migrator({ migrations }) |
||||
const initialState = migrator.generateInitialState(firstTimeState) |
||||
dbController.initialState = initialState |
||||
const versionedData = await dbController.open() |
||||
const migratedData = await migrator.migrateData(versionedData) |
||||
await dbController.put(migratedData) |
||||
return migratedData.data |
||||
} |
||||
|
||||
async 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, |
||||
showUnapprovedTx: noop, |
||||
// initial state
|
||||
initState, |
||||
}) |
||||
global.metamaskController = controller |
||||
|
||||
controller.store.subscribe(async (state) => { |
||||
try { |
||||
const versionedData = await versionifyData(state) |
||||
await dbController.put(versionedData) |
||||
} catch (e) { console.error('METAMASK Error:', e) } |
||||
}) |
||||
|
||||
async function versionifyData (state) { |
||||
const rawData = await dbController.get() |
||||
return { |
||||
data: state, |
||||
meta: rawData.meta, |
||||
} |
||||
} |
||||
|
||||
//
|
||||
// connect to other contexts
|
||||
//
|
||||
|
||||
connectionListener.on('remote', (portStream, messageEvent) => { |
||||
log.debug('REMOTE CONECTION FOUND***********') |
||||
connectRemote(portStream, messageEvent.data.context) |
||||
}) |
||||
|
||||
function connectRemote (connectionStream, context) { |
||||
var isMetaMaskInternalProcess = (context === 'popup') |
||||
if (isMetaMaskInternalProcess) { |
||||
// communication with popup
|
||||
controller.setupTrustedCommunication(connectionStream, 'MetaMask') |
||||
global.metamaskPopupIsOpen = true |
||||
} else { |
||||
// communication with page
|
||||
setupUntrustedCommunication(connectionStream, context) |
||||
} |
||||
} |
||||
|
||||
function setupUntrustedCommunication (connectionStream, originDomain) { |
||||
// setup multiplexing
|
||||
var mx = setupMultiplex(connectionStream) |
||||
// connect features
|
||||
controller.setupProviderConnection(mx.createStream('provider'), originDomain) |
||||
controller.setupPublicConfig(mx.createStream('publicConfig')) |
||||
} |
||||
} |
||||
// // this will be useful later but commented out for linting for now (liiiinting)
|
||||
// function sendMessageToAllClients (message) {
|
||||
// global.clients.matchAll().then(function (clients) {
|
||||
// clients.forEach(function (client) {
|
||||
// client.postMessage(message)
|
||||
// })
|
||||
// })
|
||||
// }
|
||||
|
||||
function noop () {} |
@ -1 +0,0 @@ |
||||
global.metamask = require('metamascara') |
@ -1,25 +0,0 @@ |
||||
const createParentStream = require('iframe-stream').ParentStream |
||||
const SwController = require('sw-controller') |
||||
const SwStream = require('sw-stream/lib/sw-stream.js') |
||||
|
||||
const keepAliveDelay = Math.floor(Math.random() * (30000 - 1000)) + 1000 |
||||
const background = new SwController({ |
||||
fileName: './scripts/background.js', |
||||
keepAlive: true, |
||||
keepAliveInterval: 30000, |
||||
keepAliveDelay, |
||||
}) |
||||
|
||||
const pageStream = createParentStream() |
||||
background.on('ready', () => { |
||||
const swStream = SwStream({ |
||||
serviceWorker: background.controller, |
||||
context: 'dapp', |
||||
}) |
||||
pageStream.pipe(swStream).pipe(pageStream) |
||||
|
||||
}) |
||||
background.on('updatefound', () => window.location.reload()) |
||||
|
||||
background.on('error', console.error) |
||||
background.startWorker() |
@ -1,73 +0,0 @@ |
||||
const injectCss = require('inject-css') |
||||
const SwController = require('sw-controller') |
||||
const SwStream = require('sw-stream') |
||||
const MetaMaskUiCss = require('../../ui/css') |
||||
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') |
||||
|
||||
const name = 'popup' |
||||
window.METAMASK_UI_TYPE = name |
||||
window.METAMASK_PLATFORM_TYPE = 'mascara' |
||||
|
||||
const keepAliveDelay = Math.floor(Math.random() * (30000 - 1000)) + 1000 |
||||
|
||||
const swController = new SwController({ |
||||
fileName: './background.js', |
||||
keepAlive: true, |
||||
keepAliveDelay, |
||||
keepAliveInterval: 20000, |
||||
}) |
||||
|
||||
swController.once('updatefound', windowReload) |
||||
swController.once('ready', async () => { |
||||
try { |
||||
swController.removeListener('updatefound', windowReload) |
||||
console.log('swController ready') |
||||
await timeout(1000) |
||||
console.log('connecting to app') |
||||
await connectApp() |
||||
console.log('app connected') |
||||
} catch (err) { |
||||
console.error(err) |
||||
} |
||||
}) |
||||
|
||||
console.log('starting service worker') |
||||
swController.startWorker() |
||||
|
||||
// Setup listener for when the service worker is read
|
||||
function connectApp () { |
||||
const connectionStream = SwStream({ |
||||
serviceWorker: swController.getWorker(), |
||||
context: name, |
||||
}) |
||||
return new Promise((resolve, reject) => { |
||||
startPopup({ container, connectionStream }, (err, store) => { |
||||
console.log('hello from MetaMascara ui!') |
||||
if (err) reject(err) |
||||
store.subscribe(() => { |
||||
const state = store.getState() |
||||
if (state.appState.shouldClose) window.close() |
||||
}) |
||||
resolve() |
||||
}) |
||||
}) |
||||
} |
||||
|
||||
function windowReload () { |
||||
if (window.METAMASK_SKIP_RELOAD) return |
||||
window.location.reload() |
||||
} |
||||
|
||||
function timeout (time) { |
||||
return new Promise((resolve) => { |
||||
setTimeout(resolve, time || 1500) |
||||
}) |
||||
} |
@ -1,7 +0,0 @@ |
||||
export default function wait (time) { |
||||
return new Promise(function (resolve, reject) { |
||||
setTimeout(function () { |
||||
resolve() |
||||
}, time * 3 || 1500) |
||||
}) |
||||
} |
@ -1,22 +0,0 @@ |
||||
var fs = require('fs') |
||||
var path = require('path') |
||||
var browserify = require('browserify') |
||||
var tests = fs.readdirSync(path.join(__dirname, 'lib')) |
||||
var bundlePath = path.join(__dirname, 'test-bundle.js') |
||||
var b = browserify() |
||||
|
||||
// Remove old bundle
|
||||
try { |
||||
fs.unlinkSync(bundlePath) |
||||
} catch (e) { |
||||
console.error(e) |
||||
} |
||||
|
||||
var writeStream = fs.createWriteStream(bundlePath) |
||||
|
||||
tests.forEach(function (fileName) { |
||||
b.add(path.join(__dirname, 'lib', fileName)) |
||||
}) |
||||
|
||||
b.bundle().pipe(writeStream) |
||||
|
File diff suppressed because one or more lines are too long
@ -1,10 +0,0 @@ |
||||
window.addEventListener('load', () => { |
||||
window.METAMASK_SKIP_RELOAD = true |
||||
// inject app container
|
||||
const body = document.body |
||||
const container = document.createElement('div') |
||||
container.id = 'app-content' |
||||
body.appendChild(container) |
||||
// start ui
|
||||
require('../src/ui.js') |
||||
}) |
@ -1,42 +0,0 @@ |
||||
const EventEmitter = require('events') |
||||
const IDB = require('idb-global') |
||||
const KEY = 'metamask-test-config' |
||||
module.exports = class Helper extends EventEmitter { |
||||
|
||||
tryToCleanContext () { |
||||
this.unregister() |
||||
.then(() => this.clearDb()) |
||||
.then(() => super.emit('complete')) |
||||
.catch((err) => { |
||||
if (err) { |
||||
super.emit('complete') |
||||
} |
||||
}) |
||||
} |
||||
|
||||
unregister () { |
||||
return global.navigator.serviceWorker.getRegistration() |
||||
.then((registration) => { |
||||
if (registration) { |
||||
return registration.unregister() |
||||
.then((b) => b ? Promise.resolve() : Promise.reject()) |
||||
} else return Promise.resolve() |
||||
}) |
||||
} |
||||
clearDb () { |
||||
return new Promise((resolve, reject) => { |
||||
const deleteRequest = global.indexDB.deleteDatabase(KEY) |
||||
deleteRequest.addEventListener('success', resolve) |
||||
deleteRequest.addEventListener('error', reject) |
||||
}) |
||||
|
||||
} |
||||
mockState (state) { |
||||
const db = new IDB({ |
||||
version: 2, |
||||
key: KEY, |
||||
initialState: state, |
||||
}) |
||||
return db.open() |
||||
} |
||||
} |
@ -1,12 +0,0 @@ |
||||
<!doctype html> |
||||
<html> |
||||
<head> |
||||
<meta charset="utf-8"> |
||||
<title>MetaMascara Alpha</title> |
||||
<meta name="viewport" content="width=device-width, initial-scale=1"> |
||||
</head> |
||||
<body> |
||||
<div id="app-content"></div> |
||||
<script src="./scripts/ui.js" type="text/javascript" charset="utf-8"></script> |
||||
</body> |
||||
</html> |
@ -1,17 +0,0 @@ |
||||
const getBaseConfig = require('./base.conf.js') |
||||
|
||||
module.exports = function (config) { |
||||
const settings = getBaseConfig(config) |
||||
|
||||
// ui and tests
|
||||
settings.files.push('dist/mascara/ui.js') |
||||
settings.files.push('dist/mascara/tests.js') |
||||
// service worker background
|
||||
settings.files.push({ pattern: 'dist/mascara/background.js', watched: false, included: false, served: true }) |
||||
settings.proxies['/background.js'] = '/base/dist/mascara/background.js' |
||||
|
||||
// use this to keep the browser open for debugging
|
||||
settings.browserNoActivityTimeout = 10000000 |
||||
|
||||
config.set(settings) |
||||
} |
Loading…
Reference in new issue