aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2015-08-01 14:05:04 +0800
committerkumavis <aaron@kumavis.me>2015-08-01 14:05:04 +0800
commitd352a6c7d8a1c81b207d0362106cb5606e21da36 (patch)
treea958866ddb1f69fcfba6f4ca7113305169bf85d4 /app
parent500a95a70492fc319ad1984da36773952a2086e6 (diff)
downloadtangerine-wallet-browser-d352a6c7d8a1c81b207d0362106cb5606e21da36.tar
tangerine-wallet-browser-d352a6c7d8a1c81b207d0362106cb5606e21da36.tar.gz
tangerine-wallet-browser-d352a6c7d8a1c81b207d0362106cb5606e21da36.tar.bz2
tangerine-wallet-browser-d352a6c7d8a1c81b207d0362106cb5606e21da36.tar.lz
tangerine-wallet-browser-d352a6c7d8a1c81b207d0362106cb5606e21da36.tar.xz
tangerine-wallet-browser-d352a6c7d8a1c81b207d0362106cb5606e21da36.tar.zst
tangerine-wallet-browser-d352a6c7d8a1c81b207d0362106cb5606e21da36.zip
metamask provider skeleton
Diffstat (limited to 'app')
-rw-r--r--app/.DS_Storebin0 -> 6148 bytes
-rw-r--r--app/images/.DS_Storebin0 -> 6148 bytes
-rw-r--r--app/images/icon-128.pngbin5356 -> 11952 bytes
-rw-r--r--app/images/icon-16.pngbin758 -> 1720 bytes
-rw-r--r--app/images/icon-19.pngbin1967 -> 1720 bytes
-rw-r--r--app/images/icon-38.pngbin4265 -> 2769 bytes
-rw-r--r--app/manifest.json4
-rw-r--r--app/scripts/contentscript.js7
-rw-r--r--app/scripts/metamask-provider.js122
-rw-r--r--app/scripts/web3.js14
10 files changed, 139 insertions, 8 deletions
diff --git a/app/.DS_Store b/app/.DS_Store
new file mode 100644
index 000000000..9f45b9329
--- /dev/null
+++ b/app/.DS_Store
Binary files differ
diff --git a/app/images/.DS_Store b/app/images/.DS_Store
new file mode 100644
index 000000000..5008ddfcf
--- /dev/null
+++ b/app/images/.DS_Store
Binary files differ
diff --git a/app/images/icon-128.png b/app/images/icon-128.png
index 75c023a53..a2f989156 100644
--- a/app/images/icon-128.png
+++ b/app/images/icon-128.png
Binary files differ
diff --git a/app/images/icon-16.png b/app/images/icon-16.png
index 7df748fba..8c644d26a 100644
--- a/app/images/icon-16.png
+++ b/app/images/icon-16.png
Binary files differ
diff --git a/app/images/icon-19.png b/app/images/icon-19.png
index 20c54d41f..8c644d26a 100644
--- a/app/images/icon-19.png
+++ b/app/images/icon-19.png
Binary files differ
diff --git a/app/images/icon-38.png b/app/images/icon-38.png
index c453adcc1..c2f05e911 100644
--- a/app/images/icon-38.png
+++ b/app/images/icon-38.png
Binary files differ
diff --git a/app/manifest.json b/app/manifest.json
index f053ef594..bc7518691 100644
--- a/app/manifest.json
+++ b/app/manifest.json
@@ -1,6 +1,6 @@
{
"name": "__MSG_appName__",
- "version": "0.0.1",
+ "version": "0.0.17",
"manifest_version": 2,
"description": "__MSG_appDescription__",
"icons": {
@@ -38,4 +38,4 @@
"web_accessible_resources": [
"scripts/web3.js"
]
-}
+} \ No newline at end of file
diff --git a/app/scripts/contentscript.js b/app/scripts/contentscript.js
index 30cf50ef9..23df227b4 100644
--- a/app/scripts/contentscript.js
+++ b/app/scripts/contentscript.js
@@ -1,8 +1,5 @@
-console.log('\'Allo \'Allo! Content script')
-
var scriptTag = document.createElement('script')
-// TODO: add "script.js" to web_accessible_resources in manifest.json
scriptTag.src = chrome.extension.getURL('scripts/web3.js')
-// scriptTag.onload = function() { this.parentNode.removeChild(this) }
-;(document.head||document.documentElement).appendChild(scriptTag) \ No newline at end of file
+scriptTag.onload = function() { debugger; this.parentNode.removeChild(this) }
+;(document.head||document.documentElement).appendChild(scriptTag)
diff --git a/app/scripts/metamask-provider.js b/app/scripts/metamask-provider.js
new file mode 100644
index 000000000..c52de82b4
--- /dev/null
+++ b/app/scripts/metamask-provider.js
@@ -0,0 +1,122 @@
+var HttpProvider = require('web3/lib/web3/httpprovider.js')
+var ethUtils = require('ethereumjs-util')
+var async = require('async')
+
+module.exports = MetamaskProvider
+
+
+function MetamaskProvider(forwardPayload, host) {
+ this.handlers = []
+ this.forwardPayload = forwardPayload
+ this.http = new HttpProvider(host)
+}
+
+MetamaskProvider.prototype.send = function (payload) {
+ if (Array.isArray(payload)) {
+ return payload.map( this.handlePayload.bind(this) )
+ } else {
+ return this.handlePayload( payload )
+ }
+}
+
+MetamaskProvider.prototype.sendAsync = function (payload, cb) {
+ if (Array.isArray(payload)) {
+ async.map( payload, this.handlePayload.bind(this), cb )
+ } else {
+ this.handlePayload( payload, cb )
+ }
+}
+
+MetamaskProvider.prototype.handlePayload = function (payload, cb) {
+ var _this = this
+ var isSync = !cb
+ var resolvedSync = true
+ var result = undefined
+
+ // TODO - this should be injected from Vapor dapp starts
+ var exposedAccounts = ['0xa06ef3ed1ce41ade87f764de6ce8095c569d6d57']
+
+ switch (payload.method) {
+
+ case 'web3_sha3':
+ var inputHex = stripHexStringPrefix(payload.params[0])
+ var hash = '0x'+ethUtils.sha3(new Buffer(inputHex, 'hex')).toString('hex')
+ return handleResult(null, wrapResponse(payload, hash))
+
+ case 'eth_sendTransaction':
+ this.forwardPayload(payload)
+ return handleResult(null, wrapResponse(payload, ''))
+
+ case 'eth_coinbase':
+ var currentAddress = exposedAccounts[0]
+ return handleResult(null, wrapResponse(payload, currentAddress))
+
+ case 'eth_accounts':
+ return handleResult(null, wrapResponse(payload, exposedAccounts))
+
+ case 'eth_gasPrice':
+ // TODO - this should be dynamically set somehow
+ var gasPrice = '0x01'
+ return handleResult(null, wrapResponse(payload, [gasPrice]))
+
+ case 'eth_call':
+ var params = payload.params
+ // default 'from' to default account
+ var args = params[0]
+ if (!args.from) {
+ var currentAddress = exposedAccounts[0]
+ args.from = currentAddress
+ }
+ // default block to latest
+ params[1] = params[1] || 'latest'
+ // turn on debug trace
+ params[2] = global.DEBUG_RPC
+ return handleNormally()
+
+ default:
+ return handleNormally()
+ }
+
+ resolvedSync = false
+
+ function handleNormally(){
+ if (isSync) {
+ return handleResult(null, _this.http.send(payload))
+ } else {
+ _this.http.sendAsync(payload, handleResult)
+ }
+ }
+
+ // helper for normalizing handling of sync+async responses
+ function handleResult(err, resp) {
+ if (isSync) {
+ return resp
+ } else {
+ if (resolvedSync) {
+ process.nextTick(cb.bind(null, err, resp))
+ } else {
+ cb(err, resp)
+ }
+ }
+ }
+}
+
+function wrapResponse(payload, result){
+ return {
+ jsonrpc: payload.jsonrpc,
+ id: payload.id,
+ result: result,
+ }
+}
+
+function stripHexStringPrefix(hex) {
+ if (!hex) {
+ return hex
+ }
+
+ if (hex.slice(0, 2) === '0x') {
+ return hex.slice(2);
+ } else {
+ return hex;
+ }
+} \ No newline at end of file
diff --git a/app/scripts/web3.js b/app/scripts/web3.js
index 2bbf95ac3..f0fec7b06 100644
--- a/app/scripts/web3.js
+++ b/app/scripts/web3.js
@@ -1,2 +1,14 @@
+const web3 = require('web3')
+const MetamaskProvider = require('./metamask-provider.js')
+
+
+var provider = new MetamaskProvider(forwardPayload, 'https://rpc.metamask.io')
+web3.setProvider(provider)
+
console.log('injecting web3....')
-window.web3 = {} \ No newline at end of file
+window.web3 = web3
+
+
+function forwardPayload(){
+ debugger
+} \ No newline at end of file