aboutsummaryrefslogtreecommitdiffstats
path: root/library/lib
diff options
context:
space:
mode:
authorkumavis <kumavis@users.noreply.github.com>2016-09-14 02:29:46 +0800
committerGitHub <noreply@github.com>2016-09-14 02:29:46 +0800
commitb13eaaa0cd201704a63e30f3601552c136c9278c (patch)
treea2b85fba2f42921ce2c9afb158f6bcad787f4ea0 /library/lib
parentb4344f2a02ac7b130fc69bbb772f68b4d042b49c (diff)
parent81d25d560f4920ee7a357881931e674bea97176c (diff)
downloadtangerine-wallet-browser-b13eaaa0cd201704a63e30f3601552c136c9278c.tar
tangerine-wallet-browser-b13eaaa0cd201704a63e30f3601552c136c9278c.tar.gz
tangerine-wallet-browser-b13eaaa0cd201704a63e30f3601552c136c9278c.tar.bz2
tangerine-wallet-browser-b13eaaa0cd201704a63e30f3601552c136c9278c.tar.lz
tangerine-wallet-browser-b13eaaa0cd201704a63e30f3601552c136c9278c.tar.xz
tangerine-wallet-browser-b13eaaa0cd201704a63e30f3601552c136c9278c.tar.zst
tangerine-wallet-browser-b13eaaa0cd201704a63e30f3601552c136c9278c.zip
Merge pull request #651 from MetaMask/library
MetaMask "Mascara" Library - initial PR
Diffstat (limited to 'library/lib')
-rw-r--r--library/lib/setup-iframe.js19
-rw-r--r--library/lib/setup-provider.js25
2 files changed, 44 insertions, 0 deletions
diff --git a/library/lib/setup-iframe.js b/library/lib/setup-iframe.js
new file mode 100644
index 000000000..db67163df
--- /dev/null
+++ b/library/lib/setup-iframe.js
@@ -0,0 +1,19 @@
+const Iframe = require('iframe')
+const IframeStream = require('iframe-stream').IframeStream
+
+module.exports = setupIframe
+
+
+function setupIframe(opts) {
+ opts = opts || {}
+ var frame = Iframe({
+ src: opts.zeroClientProvider || 'https://zero.metamask.io/',
+ container: opts.container || document.head,
+ sandboxAttributes: opts.sandboxAttributes || ['allow-scripts', 'allow-popups'],
+ })
+ var iframe = frame.iframe
+ iframe.style.setProperty('display', 'none')
+ var iframeStream = new IframeStream(iframe)
+
+ return iframeStream
+}
diff --git a/library/lib/setup-provider.js b/library/lib/setup-provider.js
new file mode 100644
index 000000000..9efd209cb
--- /dev/null
+++ b/library/lib/setup-provider.js
@@ -0,0 +1,25 @@
+const setupIframe = require('./setup-iframe.js')
+const MetamaskInpageProvider = require('../../app/scripts/lib/inpage-provider.js')
+
+module.exports = getProvider
+
+
+function getProvider(){
+
+ 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://127.0.0.1:9001',
+ sandboxAttributes: ['allow-scripts', 'allow-popups', 'allow-same-origin'],
+ container: document.body,
+ })
+
+ var inpageProvider = new MetamaskInpageProvider(iframeStream)
+ return inpageProvider
+
+}
+