aboutsummaryrefslogtreecommitdiffstats
path: root/library/frame.js
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2016-08-27 02:08:23 +0800
committerkumavis <aaron@kumavis.me>2016-08-27 02:08:23 +0800
commit23a144fb8b0b214b9c352ee523405d5ecd03046e (patch)
tree43e464ffc4eac01ecba092e758aee3e9b03c8b17 /library/frame.js
parentbbb684309e04030dbf288f3e933222b3d27d9b54 (diff)
downloadtangerine-wallet-browser-23a144fb8b0b214b9c352ee523405d5ecd03046e.tar
tangerine-wallet-browser-23a144fb8b0b214b9c352ee523405d5ecd03046e.tar.gz
tangerine-wallet-browser-23a144fb8b0b214b9c352ee523405d5ecd03046e.tar.bz2
tangerine-wallet-browser-23a144fb8b0b214b9c352ee523405d5ecd03046e.tar.lz
tangerine-wallet-browser-23a144fb8b0b214b9c352ee523405d5ecd03046e.tar.xz
tangerine-wallet-browser-23a144fb8b0b214b9c352ee523405d5ecd03046e.tar.zst
tangerine-wallet-browser-23a144fb8b0b214b9c352ee523405d5ecd03046e.zip
library - popup handler demo
Diffstat (limited to 'library/frame.js')
-rw-r--r--library/frame.js67
1 files changed, 67 insertions, 0 deletions
diff --git a/library/frame.js b/library/frame.js
new file mode 100644
index 000000000..db5baf36a
--- /dev/null
+++ b/library/frame.js
@@ -0,0 +1,67 @@
+const ZeroClientProvider = require('web3-provider-engine/zero')
+const ParentStream = require('iframe-stream').ParentStream
+const handleRequestsFromStream = require('web3-stream-provider/handler')
+const Streams = require('mississippi')
+const ObjectMultiplex = require('../app/scripts/lib/obj-multiplex')
+
+console.log('yes, this is iframe')
+
+initializeZeroClient()
+
+
+function initializeZeroClient() {
+
+ var provider = ZeroClientProvider({
+ // rpcUrl: configManager.getCurrentRpcAddress(),
+ rpcUrl: 'https://morden.infura.io/',
+ // account mgmt
+ // getAccounts: function(cb){
+ // var selectedAddress = idStore.getSelectedAddress()
+ // var result = selectedAddress ? [selectedAddress] : []
+ // cb(null, result)
+ // },
+ getAccounts: function(cb){
+ cb(null, ['0x8F331A98aC5C9431d04A5d6Bf8Fa84ed7Ed439f3'.toLowerCase()])
+ },
+ // tx signing
+ // approveTransaction: addUnconfirmedTx,
+ // signTransaction: idStore.signTransaction.bind(idStore),
+ signTransaction: function(txParams, cb){
+ var privKey = new Buffer('7ef33e339ba5a5af0e57fa900ad0ae53deaa978c21ef30a0947532135eb639a8', 'hex')
+ var Transaction = require('ethereumjs-tx')
+ console.log('signing tx:', txParams)
+ txParams.gasLimit = txParams.gas
+ var tx = new Transaction(txParams)
+ tx.sign(privKey)
+ var serialiedTx = '0x'+tx.serialize().toString('hex')
+ cb(null, serialiedTx)
+ },
+ // msg signing
+ // approveMessage: addUnconfirmedMsg,
+ // signMessage: idStore.signMessage.bind(idStore),
+ })
+
+ provider.on('block', function(block){
+ console.log('BLOCK CHANGED:', '#'+block.number.toString('hex'), '0x'+block.hash.toString('hex'))
+ })
+
+ var connectionStream = new ParentStream()
+ // setup connectionStream multiplexing
+ var multiStream = ObjectMultiplex()
+ Streams.pipe(connectionStream, multiStream, connectionStream, function(err){
+ console.warn('MetamaskIframe - lost connection to Dapp')
+ if (err) throw err
+ })
+
+ var providerStream = multiStream.createStream('provider')
+ handleRequestsFromStream(providerStream, provider, logger)
+
+ function logger(err, request, response){
+ if (err) return console.error(err.stack)
+ if (!request.isMetamaskInternal) {
+ console.log('MetaMaskIframe - RPC complete:', request, '->', response)
+ if (response.error) console.error('Error in RPC response:\n'+response.error.message)
+ }
+ }
+
+} \ No newline at end of file