From 9f3445252c766053b7a773d75dceb1c1bbfdc6f5 Mon Sep 17 00:00:00 2001 From: frankiebee Date: Thu, 9 Mar 2017 18:24:41 -0800 Subject: put background in service worker --- library/controller.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'library/controller.js') diff --git a/library/controller.js b/library/controller.js index 5823287cc..ba97da93c 100644 --- a/library/controller.js +++ b/library/controller.js @@ -1,3 +1,4 @@ +/* const urlUtil = require('url') const extend = require('xtend') const Dnode = require('dnode') @@ -157,3 +158,24 @@ function initializeZeroClient() { } } + +*/ +const SWcontroller = require('./sw-controller') +console.log('outside:open') +const background = new SWcontroller({ + fileName: 'sw-build.js', + registerOpts: { + scope: './', + } +}) + +background.startWorker() +.then(registerdWorker => { + return background.sendMessage('connect') +}) +.then((port) => { + debugger +}) +.catch(err => { + console.error(`SW Controller: ${err}`) +}) -- cgit v1.2.3 From 60f00a950cbe90edda4d9de4a67c3e0c528f6638 Mon Sep 17 00:00:00 2001 From: frankiebee Date: Thu, 9 Mar 2017 21:53:49 -0800 Subject: notes and clean up --- library/controller.js | 162 -------------------------------------------------- 1 file changed, 162 deletions(-) (limited to 'library/controller.js') diff --git a/library/controller.js b/library/controller.js index ba97da93c..bad8d33cd 100644 --- a/library/controller.js +++ b/library/controller.js @@ -1,165 +1,3 @@ -/* -const urlUtil = require('url') -const extend = require('xtend') -const Dnode = require('dnode') -const eos = require('end-of-stream') -const ParentStream = require('iframe-stream').ParentStream -const PortStream = require('../app/scripts/lib/port-stream.js') -const notification = require('../app/scripts/lib/notifications.js') -const messageManager = require('../app/scripts/lib/message-manager') -const setupMultiplex = require('../app/scripts/lib/stream-utils.js').setupMultiplex -const MetamaskController = require('../app/scripts/metamask-controller') -const extension = require('../app/scripts/lib/extension') - -const STORAGE_KEY = 'metamask-config' - - -initializeZeroClient() - -function initializeZeroClient() { - - const controller = new MetamaskController({ - // User confirmation callbacks: - showUnconfirmedMessage, - unlockAccountMessage, - showUnapprovedTx, - // Persistence Methods: - setData, - loadData, - }) - const idStore = controller.idStore - - function unlockAccountMessage () { - console.log('notif stub - unlockAccountMessage') - } - - function showUnconfirmedMessage (msgParams, msgId) { - console.log('notif stub - showUnconfirmedMessage') - } - - function showUnapprovedTx (txParams, txData, onTxDoneCb) { - console.log('notif stub - showUnapprovedTx') - } - - // - // connect to other contexts - // - - var connectionStream = new ParentStream() - - connectRemote(connectionStream, getParentHref()) - - function connectRemote (connectionStream, originDomain) { - var isMetaMaskInternalProcess = (originDomain === '127.0.0.1:9001') - if (isMetaMaskInternalProcess) { - // communication with popup - setupTrustedCommunication(connectionStream, 'MetaMask') - } else { - // communication with page - setupUntrustedCommunication(connectionStream, originDomain) - } - } - - function setupUntrustedCommunication (connectionStream, originDomain) { - // setup multiplexing - var mx = setupMultiplex(connectionStream) - // connect features - controller.setupProviderConnection(mx.createStream('provider'), originDomain) - controller.setupPublicConfig(mx.createStream('publicConfig')) - } - - function setupTrustedCommunication (connectionStream, originDomain) { - // setup multiplexing - var mx = setupMultiplex(connectionStream) - // connect features - setupControllerConnection(mx.createStream('controller')) - controller.setupProviderConnection(mx.createStream('provider'), originDomain) - } - - // - // remote features - // - - function setupControllerConnection (stream) { - controller.stream = stream - var api = controller.getApi() - var dnode = Dnode(api) - stream.pipe(dnode).pipe(stream) - dnode.on('remote', (remote) => { - // push updates to popup - controller.ethStore.on('update', controller.sendUpdate.bind(controller)) - controller.listeners.push(remote) - idStore.on('update', controller.sendUpdate.bind(controller)) - - // teardown on disconnect - eos(stream, () => { - controller.ethStore.removeListener('update', controller.sendUpdate.bind(controller)) - }) - }) - } - - function loadData () { - var oldData = getOldStyleData() - var newData - try { - newData = JSON.parse(window.localStorage[STORAGE_KEY]) - } catch (e) {} - - var data = extend({ - meta: { - version: 0, - }, - data: { - config: { - provider: { - type: 'testnet', - }, - }, - }, - }, oldData || null, newData || null) - return data - } - - function getOldStyleData () { - var config, wallet, seedWords - - var result = { - meta: { version: 0 }, - data: {}, - } - - try { - config = JSON.parse(window.localStorage['config']) - result.data.config = config - } catch (e) {} - try { - wallet = JSON.parse(window.localStorage['lightwallet']) - result.data.wallet = wallet - } catch (e) {} - try { - seedWords = window.localStorage['seedWords'] - result.data.seedWords = seedWords - } catch (e) {} - - return result - } - - function setData (data) { - window.localStorage[STORAGE_KEY] = JSON.stringify(data) - } - - function getParentHref(){ - try { - var parentLocation = window.parent.location - return parentLocation.hostname + ':' + parentLocation.port - } catch (err) { - return 'unknown' - } - } - -} - -*/ const SWcontroller = require('./sw-controller') console.log('outside:open') const background = new SWcontroller({ -- cgit v1.2.3 From 45ab81fb45ec1043d617f66c308e2e7911c8e0ad Mon Sep 17 00:00:00 2001 From: frankiebee Date: Thu, 23 Mar 2017 11:06:38 -0700 Subject: WIP: streams->indexdb --- library/controller.js | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) (limited to 'library/controller.js') diff --git a/library/controller.js b/library/controller.js index bad8d33cd..f0aa7172c 100644 --- a/library/controller.js +++ b/library/controller.js @@ -1,19 +1,13 @@ -const SWcontroller = require('./sw-controller') -console.log('outside:open') -const background = new SWcontroller({ - fileName: 'sw-build.js', - registerOpts: { - scope: './', - } -}) +// const SWcontroller = require('./sw-controller') +// const SwStream = require('sw-stream/lib/sw-stream.js') +// const startPopup = require('../app/scripts/popup-core') -background.startWorker() -.then(registerdWorker => { - return background.sendMessage('connect') -}) -.then((port) => { - debugger -}) -.catch(err => { - console.error(`SW Controller: ${err}`) -}) +// console.log('outside:open') +// const background = new SWcontroller({ +// fileName: 'sw-build.js', +// }) +// background.on('ready', (readSw) => { +// startPopup(SwStream(background.controller)) +// }) +// background.startWorker() +console.log('hello from controller') -- cgit v1.2.3 From 79248ae5cd3fb1314c5a7ff71c05f9dbe7b3a4cd Mon Sep 17 00:00:00 2001 From: frankiebee Date: Tue, 28 Mar 2017 18:02:08 -0700 Subject: WIP: Untrusted external connections eg: dapps --- library/controller.js | 192 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 180 insertions(+), 12 deletions(-) (limited to 'library/controller.js') diff --git a/library/controller.js b/library/controller.js index f0aa7172c..cbba9584a 100644 --- a/library/controller.js +++ b/library/controller.js @@ -1,13 +1,181 @@ -// const SWcontroller = require('./sw-controller') -// const SwStream = require('sw-stream/lib/sw-stream.js') -// const startPopup = require('../app/scripts/popup-core') - -// console.log('outside:open') -// const background = new SWcontroller({ -// fileName: 'sw-build.js', -// }) -// background.on('ready', (readSw) => { -// startPopup(SwStream(background.controller)) -// }) -// background.startWorker() +const ParentStream = require('iframe-stream').ParentStream +const SWcontroller = require('./sw-controller') +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', +}) + +background.on('ready', (readSw) => { + // var inpageProvider = new MetamaskInpageProvider(SwStream(background.controller)) + let pageStream = new ParentStream() + let swStream = SwStream(background.controller) + pageStream.pipe(swStream).pipe(pageStream) +}) + +background.on('error', console.error) +background.startWorker() + console.log('hello from controller') +/* +const urlUtil = require('url') +const extend = require('xtend') +const Dnode = require('dnode') +const eos = require('end-of-stream') +const ParentStream = require('iframe-stream').ParentStream +const PortStream = require('../app/scripts/lib/port-stream.js') +const notification = require('../app/scripts/lib/notifications.js') +const messageManager = require('../app/scripts/lib/message-manager') +const setupMultiplex = require('../app/scripts/lib/stream-utils.js').setupMultiplex +const MetamaskController = require('../app/scripts/metamask-controller') +const extension = require('../app/scripts/lib/extension') + +const STORAGE_KEY = 'metamask-config' + + +initializeZeroClient() + +function initializeZeroClient() { + + const controller = new MetamaskController({ + // User confirmation callbacks: + showUnconfirmedMessage, + unlockAccountMessage, + showUnapprovedTx, + // Persistence Methods: + setData, + loadData, + }) + const idStore = controller.idStore + + function unlockAccountMessage () { + console.log('notif stub - unlockAccountMessage') + } + + function showUnconfirmedMessage (msgParams, msgId) { + console.log('notif stub - showUnconfirmedMessage') + } + + function showUnapprovedTx (txParams, txData, onTxDoneCb) { + console.log('notif stub - showUnapprovedTx') + } + + // + // connect to other contexts + // + + var connectionStream = new ParentStream() + + connectRemote(connectionStream, getParentHref()) + + function connectRemote (connectionStream, originDomain) { + var isMetaMaskInternalProcess = (originDomain === '127.0.0.1:9001') + if (isMetaMaskInternalProcess) { + // communication with popup + setupTrustedCommunication(connectionStream, 'MetaMask') + } else { + // communication with page + setupUntrustedCommunication(connectionStream, originDomain) + } + } + + function setupUntrustedCommunication (connectionStream, originDomain) { + // setup multiplexing + var mx = setupMultiplex(connectionStream) + // connect features + controller.setupProviderConnection(mx.createStream('provider'), originDomain) + controller.setupPublicConfig(mx.createStream('publicConfig')) + } + + function setupTrustedCommunication (connectionStream, originDomain) { + // setup multiplexing + var mx = setupMultiplex(connectionStream) + // connect features + setupControllerConnection(mx.createStream('controller')) + controller.setupProviderConnection(mx.createStream('provider'), originDomain) + } + + // + // remote features + // + + function setupControllerConnection (stream) { + controller.stream = stream + var api = controller.getApi() + var dnode = Dnode(api) + stream.pipe(dnode).pipe(stream) + dnode.on('remote', (remote) => { + // push updates to popup + controller.ethStore.on('update', controller.sendUpdate.bind(controller)) + controller.listeners.push(remote) + idStore.on('update', controller.sendUpdate.bind(controller)) + + // teardown on disconnect + eos(stream, () => { + controller.ethStore.removeListener('update', controller.sendUpdate.bind(controller)) + }) + }) + } + + function loadData () { + var oldData = getOldStyleData() + var newData + try { + newData = JSON.parse(window.localStorage[STORAGE_KEY]) + } catch (e) {} + + var data = extend({ + meta: { + version: 0, + }, + data: { + config: { + provider: { + type: 'testnet', + }, + }, + }, + }, oldData || null, newData || null) + return data + } + + function getOldStyleData () { + var config, wallet, seedWords + + var result = { + meta: { version: 0 }, + data: {}, + } + + try { + config = JSON.parse(window.localStorage['config']) + result.data.config = config + } catch (e) {} + try { + wallet = JSON.parse(window.localStorage['lightwallet']) + result.data.wallet = wallet + } catch (e) {} + try { + seedWords = window.localStorage['seedWords'] + result.data.seedWords = seedWords + } catch (e) {} + + return result + } + + function setData (data) { + window.localStorage[STORAGE_KEY] = JSON.stringify(data) + } + + function getParentHref(){ + try { + var parentLocation = window.parent.location + return parentLocation.hostname + ':' + parentLocation.port + } catch (err) { + return 'unknown' + } + } + +} + +*/ -- cgit v1.2.3 From 84b3415b4479eb849b69d77a7e178c67fcaaf3fb Mon Sep 17 00:00:00 2001 From: frankiebee Date: Wed, 29 Mar 2017 10:53:43 -0700 Subject: WIP: lost enital call from dapp to getAccounts --- library/controller.js | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) (limited to 'library/controller.js') diff --git a/library/controller.js b/library/controller.js index cbba9584a..c3f2fa5fa 100644 --- a/library/controller.js +++ b/library/controller.js @@ -6,17 +6,17 @@ const background = new SWcontroller({ fileName: '/popup/sw-build.js', }) -background.on('ready', (readSw) => { +background.on('ready', (_) => { // var inpageProvider = new MetamaskInpageProvider(SwStream(background.controller)) let pageStream = new ParentStream() let swStream = SwStream(background.controller) pageStream.pipe(swStream).pipe(pageStream) + console.log('********************WOOP*********************') }) background.on('error', console.error) background.startWorker() -console.log('hello from controller') /* const urlUtil = require('url') const extend = require('xtend') @@ -167,14 +167,6 @@ function initializeZeroClient() { window.localStorage[STORAGE_KEY] = JSON.stringify(data) } - function getParentHref(){ - try { - var parentLocation = window.parent.location - return parentLocation.hostname + ':' + parentLocation.port - } catch (err) { - return 'unknown' - } - } } -- cgit v1.2.3 From 2b1a9c5ae880afe1a5bf2d11eefbbdf26dc6e27c Mon Sep 17 00:00:00 2001 From: frankiebee Date: Wed, 29 Mar 2017 11:02:50 -0700 Subject: Create a Transaction from within the dapp --- library/controller.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'library/controller.js') diff --git a/library/controller.js b/library/controller.js index c3f2fa5fa..126e972c8 100644 --- a/library/controller.js +++ b/library/controller.js @@ -6,9 +6,9 @@ const background = new SWcontroller({ fileName: '/popup/sw-build.js', }) +const pageStream = new ParentStream() background.on('ready', (_) => { // var inpageProvider = new MetamaskInpageProvider(SwStream(background.controller)) - let pageStream = new ParentStream() let swStream = SwStream(background.controller) pageStream.pipe(swStream).pipe(pageStream) console.log('********************WOOP*********************') -- cgit v1.2.3 From 4cf3beda25e7883aac37ee188d3bb102dea4afa3 Mon Sep 17 00:00:00 2001 From: frankiebee Date: Wed, 29 Mar 2017 15:19:46 -0700 Subject: Bump sw-stream and setup "untrusted and trusted comunication" --- library/controller.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'library/controller.js') diff --git a/library/controller.js b/library/controller.js index 126e972c8..d4a76d316 100644 --- a/library/controller.js +++ b/library/controller.js @@ -9,7 +9,10 @@ const background = new SWcontroller({ const pageStream = new ParentStream() background.on('ready', (_) => { // var inpageProvider = new MetamaskInpageProvider(SwStream(background.controller)) - let swStream = SwStream(background.controller) + let swStream = SwStream({ + serviceWorker: background.controller, + context: 'dapp', + }) pageStream.pipe(swStream).pipe(pageStream) console.log('********************WOOP*********************') }) -- cgit v1.2.3 From 29a602a89b176e7af3f15297c2f586a4ece0a726 Mon Sep 17 00:00:00 2001 From: frankiebee Date: Thu, 30 Mar 2017 11:28:22 -0700 Subject: Clean up --- library/controller.js | 157 +------------------------------------------------- 1 file changed, 1 insertion(+), 156 deletions(-) (limited to 'library/controller.js') diff --git a/library/controller.js b/library/controller.js index d4a76d316..1e9bc84d2 100644 --- a/library/controller.js +++ b/library/controller.js @@ -14,163 +14,8 @@ background.on('ready', (_) => { context: 'dapp', }) pageStream.pipe(swStream).pipe(pageStream) - console.log('********************WOOP*********************') + }) background.on('error', console.error) background.startWorker() - -/* -const urlUtil = require('url') -const extend = require('xtend') -const Dnode = require('dnode') -const eos = require('end-of-stream') -const ParentStream = require('iframe-stream').ParentStream -const PortStream = require('../app/scripts/lib/port-stream.js') -const notification = require('../app/scripts/lib/notifications.js') -const messageManager = require('../app/scripts/lib/message-manager') -const setupMultiplex = require('../app/scripts/lib/stream-utils.js').setupMultiplex -const MetamaskController = require('../app/scripts/metamask-controller') -const extension = require('../app/scripts/lib/extension') - -const STORAGE_KEY = 'metamask-config' - - -initializeZeroClient() - -function initializeZeroClient() { - - const controller = new MetamaskController({ - // User confirmation callbacks: - showUnconfirmedMessage, - unlockAccountMessage, - showUnapprovedTx, - // Persistence Methods: - setData, - loadData, - }) - const idStore = controller.idStore - - function unlockAccountMessage () { - console.log('notif stub - unlockAccountMessage') - } - - function showUnconfirmedMessage (msgParams, msgId) { - console.log('notif stub - showUnconfirmedMessage') - } - - function showUnapprovedTx (txParams, txData, onTxDoneCb) { - console.log('notif stub - showUnapprovedTx') - } - - // - // connect to other contexts - // - - var connectionStream = new ParentStream() - - connectRemote(connectionStream, getParentHref()) - - function connectRemote (connectionStream, originDomain) { - var isMetaMaskInternalProcess = (originDomain === '127.0.0.1:9001') - if (isMetaMaskInternalProcess) { - // communication with popup - setupTrustedCommunication(connectionStream, 'MetaMask') - } else { - // communication with page - setupUntrustedCommunication(connectionStream, originDomain) - } - } - - function setupUntrustedCommunication (connectionStream, originDomain) { - // setup multiplexing - var mx = setupMultiplex(connectionStream) - // connect features - controller.setupProviderConnection(mx.createStream('provider'), originDomain) - controller.setupPublicConfig(mx.createStream('publicConfig')) - } - - function setupTrustedCommunication (connectionStream, originDomain) { - // setup multiplexing - var mx = setupMultiplex(connectionStream) - // connect features - setupControllerConnection(mx.createStream('controller')) - controller.setupProviderConnection(mx.createStream('provider'), originDomain) - } - - // - // remote features - // - - function setupControllerConnection (stream) { - controller.stream = stream - var api = controller.getApi() - var dnode = Dnode(api) - stream.pipe(dnode).pipe(stream) - dnode.on('remote', (remote) => { - // push updates to popup - controller.ethStore.on('update', controller.sendUpdate.bind(controller)) - controller.listeners.push(remote) - idStore.on('update', controller.sendUpdate.bind(controller)) - - // teardown on disconnect - eos(stream, () => { - controller.ethStore.removeListener('update', controller.sendUpdate.bind(controller)) - }) - }) - } - - function loadData () { - var oldData = getOldStyleData() - var newData - try { - newData = JSON.parse(window.localStorage[STORAGE_KEY]) - } catch (e) {} - - var data = extend({ - meta: { - version: 0, - }, - data: { - config: { - provider: { - type: 'testnet', - }, - }, - }, - }, oldData || null, newData || null) - return data - } - - function getOldStyleData () { - var config, wallet, seedWords - - var result = { - meta: { version: 0 }, - data: {}, - } - - try { - config = JSON.parse(window.localStorage['config']) - result.data.config = config - } catch (e) {} - try { - wallet = JSON.parse(window.localStorage['lightwallet']) - result.data.wallet = wallet - } catch (e) {} - try { - seedWords = window.localStorage['seedWords'] - result.data.seedWords = seedWords - } catch (e) {} - - return result - } - - function setData (data) { - window.localStorage[STORAGE_KEY] = JSON.stringify(data) - } - - -} - -*/ -- cgit v1.2.3 From 8d49d519c090d287484008346aba1df6d7ad77e7 Mon Sep 17 00:00:00 2001 From: frankiebee Date: Sun, 2 Apr 2017 22:01:44 -0700 Subject: Rename and move around files --- library/controller.js | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 library/controller.js (limited to 'library/controller.js') diff --git a/library/controller.js b/library/controller.js deleted file mode 100644 index 1e9bc84d2..000000000 --- a/library/controller.js +++ /dev/null @@ -1,21 +0,0 @@ -const ParentStream = require('iframe-stream').ParentStream -const SWcontroller = require('./sw-controller') -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', -}) - -const pageStream = new ParentStream() -background.on('ready', (_) => { - // var inpageProvider = new MetamaskInpageProvider(SwStream(background.controller)) - let swStream = SwStream({ - serviceWorker: background.controller, - context: 'dapp', - }) - pageStream.pipe(swStream).pipe(pageStream) - -}) - -background.on('error', console.error) -background.startWorker() -- cgit v1.2.3