commit
a8b4f05b58
@ -1,3 +0,0 @@ |
||||
{ |
||||
"presets": ["env"] |
||||
} |
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
@ -1,67 +0,0 @@ |
||||
const gulp = require('gulp'), |
||||
babelify = require('babelify'), |
||||
browserify = require('browserify'), |
||||
buffer = require('vinyl-buffer'), |
||||
del = require('del'), |
||||
minify = require('gulp-minify'), |
||||
runSequence = require('run-sequence'), |
||||
size = require('gulp-size'), |
||||
source = require('vinyl-source-stream'), |
||||
config = { |
||||
name: 'trust', |
||||
fileTypes: { |
||||
all: '**/*', |
||||
js: '**/*.js', |
||||
main: 'index.js' |
||||
}, |
||||
source: { |
||||
baseDir: 'src' |
||||
}, |
||||
staging: { |
||||
baseDir: 'staging' |
||||
}, |
||||
distribution: { |
||||
baseDir: 'dist', |
||||
javascript: 'js' |
||||
} |
||||
}; |
||||
|
||||
gulp.task('clean', function (callback) { |
||||
runSequence('clean:dist', 'clean:stage', callback); |
||||
}); |
||||
|
||||
gulp.task('clean:stage', function () { |
||||
let stagingDir = `${config.staging.baseDir}/${config.fileTypes.all}`; |
||||
return del.sync(stagingDir); |
||||
}); |
||||
|
||||
gulp.task('clean:dist', function () { |
||||
let distributionDir = `${config.distribution.baseDir}/${config.fileTypes.all}`; |
||||
return del.sync(distributionDir); |
||||
}); |
||||
|
||||
gulp.task('javascript', function () { |
||||
let sourceDir = `${config.source.baseDir}/${config.fileTypes.js}`, |
||||
stagingDir = `${config.staging.baseDir}`; |
||||
return gulp.src(sourceDir) |
||||
.pipe(gulp.dest(stagingDir)); |
||||
}); |
||||
|
||||
gulp.task('bundle:javascript', ['javascript', ], function () { |
||||
let mainFile = `${config.staging.baseDir}/${config.fileTypes.main}`, |
||||
distributionDir = `${config.distribution.baseDir}`; |
||||
return browserify(mainFile) |
||||
.transform(babelify, { presets: ['env'] }) |
||||
.bundle() |
||||
.pipe(source(config.name + '.js')) |
||||
.pipe(buffer()) |
||||
.pipe(minify()) |
||||
.pipe(size()) |
||||
.pipe(gulp.dest(distributionDir)); |
||||
}); |
||||
|
||||
gulp.task('build', function (callback) { |
||||
runSequence('clean:dist', 'clean:stage', ['bundle:javascript'], |
||||
callback); |
||||
}); |
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,46 +0,0 @@ |
||||
{ |
||||
"name": "trust-wallet", |
||||
"version": "0.0.1", |
||||
"description": "web3 injection", |
||||
"main": "index.js", |
||||
"scripts": { |
||||
"test": "test" |
||||
}, |
||||
"repository": { |
||||
"type": "git", |
||||
"url": "git+ssh://git@github.com/TrustWallet/trust-wallet-ios.git" |
||||
}, |
||||
"keywords": [ |
||||
"ethereum", |
||||
"swift", |
||||
"blockchain", |
||||
"wallet", |
||||
"ethereum-dapps", |
||||
"dapps" |
||||
], |
||||
"author": "Trust <support@trustwalletapp.com>", |
||||
"license": "GPL-3.0", |
||||
"bugs": { |
||||
"url": "https://github.com/TrustWallet/trust-wallet-ios/issues" |
||||
}, |
||||
"homepage": "https://github.com/TrustWallet/trust-wallet-ios#readme", |
||||
"devDependencies": { |
||||
"babel-preset-env": "^1.6.1", |
||||
"babel-preset-es2015": "^6.24.1", |
||||
"babelify": "^8.0.0", |
||||
"browserify": "^15.2.0", |
||||
"del": "^3.0.0", |
||||
"gulp": "^3.9.1", |
||||
"gulp-minify": "^2.1.0", |
||||
"gulp-rename": "^1.2.2", |
||||
"gulp-size": "^3.0.0", |
||||
"run-sequence": "^2.2.1", |
||||
"vinyl-buffer": "^1.0.1", |
||||
"vinyl-source-stream": "^2.0.0" |
||||
}, |
||||
"dependencies": { |
||||
"babel-core": "^6.26.0", |
||||
"web3": "^0.20.4", |
||||
"web3-provider-engine": "^13.6.0" |
||||
} |
||||
} |
@ -1,100 +0,0 @@ |
||||
const Web3 = require('web3') |
||||
const ProviderEngine = require('web3-provider-engine') |
||||
const HookedWalletSubprovider = require('web3-provider-engine/subproviders/hooked-wallet.js') |
||||
const FilterSubprovider = require('web3-provider-engine/subproviders/filters.js') |
||||
const Web3Subprovider = require("web3-provider-engine/subproviders/web3.js") |
||||
|
||||
const context = window || global |
||||
|
||||
context.chrome = { webstore: true } |
||||
context.Web3 = Web3 |
||||
|
||||
let callbacks = {} |
||||
let hookedSubProvider |
||||
let globalSyncOptions = {} |
||||
|
||||
const Trust = { |
||||
init (rpcUrl, options, syncOptions) {
|
||||
const engine = new ProviderEngine() |
||||
const web3 = new Web3(engine) |
||||
context.web3 = web3 |
||||
globalSyncOptions = syncOptions |
||||
|
||||
engine.addProvider(hookedSubProvider = new HookedWalletSubprovider(options)) |
||||
engine.addProvider(new FilterSubprovider()) |
||||
engine.addProvider(new Web3Subprovider(new Web3.providers.HttpProvider(rpcUrl))) |
||||
|
||||
engine.on('error', err => console.error(err.stack)) |
||||
engine.isTrust = true |
||||
engine.start() |
||||
|
||||
return engine |
||||
}, |
||||
addCallback (id, cb, isRPC) { |
||||
cb.isRPC = isRPC |
||||
callbacks[id] = cb |
||||
}, |
||||
executeCallback (id, error, value) { |
||||
console.log(`executing callback: \nid: ${id}\nvalue: ${value}\nerror: ${error}\n`) |
||||
|
||||
let callback = callbacks[id] |
||||
|
||||
if (callback.isRPC) { |
||||
const response = {'id': id, jsonrpc: '2.0', result: value, error: {message: error} } |
||||
|
||||
if (error) { |
||||
callback(response, null) |
||||
} else { |
||||
callback(null, response) |
||||
} |
||||
} else { |
||||
callback(error, value) |
||||
} |
||||
delete callbacks[id] |
||||
} |
||||
} |
||||
|
||||
if (typeof context.Trust === 'undefined') { |
||||
context.Trust = Trust |
||||
} |
||||
|
||||
ProviderEngine.prototype.send = function (payload) { |
||||
const self = this |
||||
|
||||
let result = null |
||||
switch (payload.method) { |
||||
|
||||
case 'eth_accounts': |
||||
let address = globalSyncOptions.address |
||||
result = address ? [address] : [] || null |
||||
break |
||||
|
||||
case 'eth_coinbase': |
||||
result = globalSyncOptions.address || null |
||||
break |
||||
|
||||
case 'eth_uninstallFilter': |
||||
self.sendAsync(payload, noop) |
||||
result = true |
||||
break |
||||
|
||||
case 'net_version': |
||||
result = globalSyncOptions.networkVersion || null |
||||
break |
||||
|
||||
// throw not-supported Error
|
||||
default: |
||||
var link = 'https://github.com/MetaMask/faq/blob/master/DEVELOPERS.md#dizzy-all-async---think-of-metamask-as-a-light-client' |
||||
var message = `The MetaMask Web3 object does not support synchronous methods like ${payload.method} without a callback parameter. See ${link} for details.` |
||||
throw new Error(message) |
||||
} |
||||
// return the result
|
||||
return { |
||||
id: payload.id, |
||||
jsonrpc: payload.jsonrpc, |
||||
result: result, |
||||
} |
||||
} |
||||
|
||||
module.exports = Trust |
||||
|
Loading…
Reference in new issue