aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2016-11-18 05:51:32 +0800
committerDan Finlay <dan@danfinlay.com>2016-11-18 05:51:32 +0800
commit4352c7031afb6f9a175b29d0addeb7ea48345676 (patch)
treeecb311d43d0f77d5f5f0e82a0014a09c6381f0ef /app
parentf229d32442f34859be169e38a42ffecdfb8fc48a (diff)
parent592b64a19fd7001d965aa1a1c329b24f55d2ea90 (diff)
downloadtangerine-wallet-browser-4352c7031afb6f9a175b29d0addeb7ea48345676.tar
tangerine-wallet-browser-4352c7031afb6f9a175b29d0addeb7ea48345676.tar.gz
tangerine-wallet-browser-4352c7031afb6f9a175b29d0addeb7ea48345676.tar.bz2
tangerine-wallet-browser-4352c7031afb6f9a175b29d0addeb7ea48345676.tar.lz
tangerine-wallet-browser-4352c7031afb6f9a175b29d0addeb7ea48345676.tar.xz
tangerine-wallet-browser-4352c7031afb6f9a175b29d0addeb7ea48345676.tar.zst
tangerine-wallet-browser-4352c7031afb6f9a175b29d0addeb7ea48345676.zip
Merge branch 'i328-MultiVault' of github.com:MetaMask/metamask-plugin into i328-MultiVault
Diffstat (limited to 'app')
-rw-r--r--app/manifest.json2
-rw-r--r--app/scripts/contentscript.js14
-rw-r--r--app/scripts/inpage.js2
-rw-r--r--app/scripts/keyring-controller.js125
-rw-r--r--app/scripts/keyrings/hd.js42
-rw-r--r--app/scripts/keyrings/simple.js19
-rw-r--r--app/scripts/lib/auto-reload.js5
-rw-r--r--app/scripts/lib/config-manager.js11
-rw-r--r--app/scripts/lib/encryptor.js12
-rw-r--r--app/scripts/lib/idStore-migrator.js6
-rw-r--r--app/scripts/lib/idStore.js32
-rw-r--r--app/scripts/lib/inpage-provider.js4
-rw-r--r--app/scripts/lib/is-popup-or-notification.js2
-rw-r--r--app/scripts/lib/notifications.js12
-rw-r--r--app/scripts/lib/sig-util.js5
-rw-r--r--app/scripts/metamask-controller.js33
-rw-r--r--app/scripts/popup-core.js4
-rw-r--r--app/scripts/popup.js2
18 files changed, 158 insertions, 174 deletions
diff --git a/app/manifest.json b/app/manifest.json
index e35f2918d..a21809ce8 100644
--- a/app/manifest.json
+++ b/app/manifest.json
@@ -1,7 +1,7 @@
{
"name": "MetaMask",
"short_name": "Metamask",
- "version": "2.13.6",
+ "version": "2.13.7",
"manifest_version": 2,
"author": "https://metamask.io",
"description": "Ethereum Browser Extension",
diff --git a/app/scripts/contentscript.js b/app/scripts/contentscript.js
index e2a968ac9..ab64dc9fa 100644
--- a/app/scripts/contentscript.js
+++ b/app/scripts/contentscript.js
@@ -6,7 +6,7 @@ const extension = require('./lib/extension')
const fs = require('fs')
const path = require('path')
-const inpageText = fs.readFileSync(path.join(__dirname + '/inpage.js')).toString()
+const inpageText = fs.readFileSync(path.join(__dirname, 'inpage.js')).toString()
// Eventually this streaming injection could be replaced with:
// https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Language_Bindings/Components.utils.exportFunction
@@ -20,9 +20,8 @@ if (shouldInjectWeb3()) {
setupStreams()
}
-function setupInjection(){
+function setupInjection () {
try {
-
// inject in-page script
var scriptTag = document.createElement('script')
scriptTag.src = extension.extension.getURL('scripts/inpage.js')
@@ -31,14 +30,12 @@ function setupInjection(){
var container = document.head || document.documentElement
// append as first child
container.insertBefore(scriptTag, container.children[0])
-
} catch (e) {
console.error('Metamask injection failed.', e)
}
}
-function setupStreams(){
-
+function setupStreams () {
// setup communication to page and plugin
var pageStream = new LocalMessageDuplexStream({
name: 'contentscript',
@@ -65,14 +62,13 @@ function setupStreams(){
mx.ignoreStream('provider')
mx.ignoreStream('publicConfig')
mx.ignoreStream('reload')
-
}
-function shouldInjectWeb3(){
+function shouldInjectWeb3 () {
return isAllowedSuffix(window.location.href)
}
-function isAllowedSuffix(testCase) {
+function isAllowedSuffix (testCase) {
var prohibitedTypes = ['xml', 'pdf']
var currentUrl = window.location.href
var currentRegex
diff --git a/app/scripts/inpage.js b/app/scripts/inpage.js
index 85dd70b4d..9d6fc96de 100644
--- a/app/scripts/inpage.js
+++ b/app/scripts/inpage.js
@@ -43,7 +43,7 @@ reloadStream.once('data', triggerReload)
var pingChannel = inpageProvider.multiStream.createStream('pingpong')
var pingStream = new PingStream({ objectMode: true })
// wait for first successful reponse
-metamaskStream.once('_data', function(){
+metamaskStream.once('_data', function () {
pingStream.pipe(pingChannel).pipe(pingStream)
})
endOfStream(pingStream, triggerReload)
diff --git a/app/scripts/keyring-controller.js b/app/scripts/keyring-controller.js
index 5b06de690..10d686e23 100644
--- a/app/scripts/keyring-controller.js
+++ b/app/scripts/keyring-controller.js
@@ -1,17 +1,17 @@
const async = require('async')
-const EventEmitter = require('events').EventEmitter
-const encryptor = require('./lib/encryptor')
-const messageManager = require('./lib/message-manager')
const ethUtil = require('ethereumjs-util')
const ethBinToOps = require('eth-bin-to-ops')
const EthQuery = require('eth-query')
-const BN = ethUtil.BN
-const Transaction = require('ethereumjs-tx')
-const autoFaucet = require('./lib/auto-faucet')
const bip39 = require('bip39')
+const Transaction = require('ethereumjs-tx')
+const EventEmitter = require('events').EventEmitter
-// TEMPORARY UNTIL FULL DEPRECATION:
+const normalize = require('./lib/sig-util').normalize
+const encryptor = require('./lib/encryptor')
+const messageManager = require('./lib/message-manager')
+const autoFaucet = require('./lib/auto-faucet')
const IdStoreMigrator = require('./lib/idStore-migrator')
+const BN = ethUtil.BN
// Keyrings:
const SimpleKeyring = require('./keyrings/simple')
@@ -27,7 +27,6 @@ module.exports = class KeyringController extends EventEmitter {
constructor (opts) {
super()
- this.web3 = opts.web3
this.configManager = opts.configManager
this.ethStore = opts.ethStore
this.encryptor = encryptor
@@ -39,7 +38,7 @@ module.exports = class KeyringController extends EventEmitter {
this._unconfTxCbs = {}
this._unconfMsgCbs = {}
- this.network = opts.network
+ this.getNetwork = opts.getNetwork
// TEMPORARY UNTIL FULL DEPRECATION:
this.idStoreMigrator = new IdStoreMigrator({
@@ -47,7 +46,7 @@ module.exports = class KeyringController extends EventEmitter {
})
}
- getState() {
+ getState () {
const configManager = this.configManager
const address = configManager.getSelectedAccount()
const wallet = configManager.getWallet() // old style vault
@@ -57,7 +56,7 @@ module.exports = class KeyringController extends EventEmitter {
seedWords: this.configManager.getSeedWords(),
isInitialized: (!!wallet || !!vault),
isUnlocked: !!this.key,
- isConfirmed: true, // AUDIT this.configManager.getConfirmed(),
+ isDisclaimerConfirmed: this.configManager.getConfirmedDisclaimer(), // AUDIT this.configManager.getConfirmedDisclaimer(),
unconfTxs: this.configManager.unconfirmedTxs(),
transactions: this.configManager.getTxList(),
unconfMsgs: messageManager.unconfirmedMsgs(),
@@ -73,18 +72,18 @@ module.exports = class KeyringController extends EventEmitter {
}
}
- setStore(ethStore) {
+ setStore (ethStore) {
this.ethStore = ethStore
}
- createNewVaultAndKeychain(password, entropy, cb) {
+ createNewVaultAndKeychain (password, entropy, cb) {
this.createNewVault(password, entropy, (err) => {
if (err) return cb(err)
this.createFirstKeyTree(password, cb)
})
}
- createNewVaultAndRestore(password, seed, cb) {
+ createNewVaultAndRestore (password, seed, cb) {
if (typeof password !== 'string') {
return cb('Password must be text.')
}
@@ -99,7 +98,7 @@ module.exports = class KeyringController extends EventEmitter {
if (err) return cb(err)
this.addNewKeyring('HD Key Tree', {
mnemonic: seed,
- n: 1,
+ numberOfAccounts: 1,
}, (err) => {
if (err) return cb(err)
const firstKeyring = this.keyrings[0]
@@ -110,12 +109,12 @@ module.exports = class KeyringController extends EventEmitter {
this.setupAccounts(accounts)
this.emit('update')
- cb(null, this.getState())
+ cb()
})
})
}
- migrateAndGetKey(password) {
+ migrateAndGetKey (password) {
let key
const shouldMigrate = !!this.configManager.getWallet() && !this.configManager.getVault()
@@ -135,7 +134,7 @@ module.exports = class KeyringController extends EventEmitter {
})
}
- createNewVault(password, entropy, cb) {
+ createNewVault (password, entropy, cb) {
const configManager = this.configManager
const salt = this.encryptor.generateSalt()
configManager.setSalt(salt)
@@ -145,28 +144,27 @@ module.exports = class KeyringController extends EventEmitter {
return this.persistAllKeyrings()
})
.then(() => {
- cb(null)
+ cb()
})
.catch((err) => {
cb(err)
})
}
- createFirstKeyTree(password, cb) {
+ createFirstKeyTree (password, cb) {
this.clearKeyrings()
- this.addNewKeyring('HD Key Tree', {n: 1}, (err) => {
- const firstKeyring = this.keyrings[0]
- const accounts = firstKeyring.getAccounts()
+ this.addNewKeyring('HD Key Tree', {numberOfAccounts: 1}, (err) => {
+ const accounts = this.keyrings[0].getAccounts()
const firstAccount = accounts[0]
const hexAccount = normalize(firstAccount)
- const seedWords = firstKeyring.serialize().mnemonic
this.configManager.setSelectedAccount(firstAccount)
- this.configManager.setSeedWords(seedWords)
+
+ this.placeSeedWords()
autoFaucet(hexAccount)
this.setupAccounts(accounts)
this.persistAllKeyrings()
.then(() => {
- cb(err, this.getState())
+ cb(err)
})
.catch((reason) => {
cb(reason)
@@ -174,13 +172,13 @@ module.exports = class KeyringController extends EventEmitter {
})
}
- placeSeedWords (cb) {
+ placeSeedWords () {
const firstKeyring = this.keyrings[0]
const seedWords = firstKeyring.serialize().mnemonic
this.configManager.setSeedWords(seedWords)
}
- submitPassword(password, cb) {
+ submitPassword (password, cb) {
this.migrateAndGetKey(password)
.then((key) => {
return this.unlockKeyrings(key)
@@ -197,7 +195,7 @@ module.exports = class KeyringController extends EventEmitter {
})
}
- loadKey(password) {
+ loadKey (password) {
const salt = this.configManager.getSalt() || this.encryptor.generateSalt()
return this.encryptor.keyFromPassword(password + salt)
.then((key) => {
@@ -207,7 +205,7 @@ module.exports = class KeyringController extends EventEmitter {
})
}
- addNewKeyring(type, opts, cb) {
+ addNewKeyring (type, opts, cb) {
const Keyring = this.getKeyringClassForType(type)
const keyring = new Keyring(opts)
const accounts = keyring.getAccounts()
@@ -216,42 +214,42 @@ module.exports = class KeyringController extends EventEmitter {
this.setupAccounts(accounts)
this.persistAllKeyrings()
.then(() => {
- cb(null, this.getState())
+ cb()
})
.catch((reason) => {
cb(reason)
})
}
- addNewAccount(keyRingNum = 0, cb) {
+ addNewAccount (keyRingNum = 0, cb) {
const ring = this.keyrings[keyRingNum]
const accounts = ring.addAccounts(1)
this.setupAccounts(accounts)
this.persistAllKeyrings()
.then(() => {
- cb(null, this.getState())
+ cb()
})
.catch((reason) => {
cb(reason)
})
}
- setupAccounts(accounts) {
+ setupAccounts (accounts) {
var arr = accounts || this.getAccounts()
arr.forEach((account) => {
- this.loadBalanceAndNickname(account)
+ this.getBalanceAndNickname(account)
})
}
// Takes an account address and an iterator representing
// the current number of named accounts.
- loadBalanceAndNickname(account) {
+ getBalanceAndNickname (account) {
const address = normalize(account)
this.ethStore.addAccount(address)
this.createNickname(address)
}
- createNickname(address) {
+ createNickname (address) {
const hexAddress = normalize(address)
var i = Object.keys(this.identities).length
const oldNickname = this.configManager.nicknameForWallet(address)
@@ -275,7 +273,7 @@ module.exports = class KeyringController extends EventEmitter {
}
}
- persistAllKeyrings() {
+ persistAllKeyrings () {
const serialized = this.keyrings.map((k) => {
return {
type: k.type,
@@ -290,7 +288,7 @@ module.exports = class KeyringController extends EventEmitter {
})
}
- unlockKeyrings(key) {
+ unlockKeyrings (key) {
const encryptedVault = this.configManager.getVault()
return this.encryptor.decryptWithKey(key, encryptedVault)
.then((vault) => {
@@ -299,7 +297,7 @@ module.exports = class KeyringController extends EventEmitter {
})
}
- restoreKeyring(serialized) {
+ restoreKeyring (serialized) {
const { type, data } = serialized
const Keyring = this.getKeyringClassForType(type)
const keyring = new Keyring()
@@ -312,7 +310,7 @@ module.exports = class KeyringController extends EventEmitter {
return keyring
}
- getKeyringClassForType(type) {
+ getKeyringClassForType (type) {
const Keyring = this.keyringTypes.reduce((res, kr) => {
if (kr.type() === type) {
return kr
@@ -323,7 +321,7 @@ module.exports = class KeyringController extends EventEmitter {
return Keyring
}
- getAccounts() {
+ getAccounts () {
const keyrings = this.keyrings || []
return keyrings.map(kr => kr.getAccounts())
.reduce((res, arr) => {
@@ -331,13 +329,13 @@ module.exports = class KeyringController extends EventEmitter {
}, [])
}
- setSelectedAddress(address, cb) {
+ setSelectedAddress (address, cb) {
var addr = normalize(address)
this.configManager.setSelectedAccount(addr)
cb(null, addr)
}
- addUnconfirmedTransaction(txParams, onTxDoneCb, cb) {
+ addUnconfirmedTransaction (txParams, onTxDoneCb, cb) {
var self = this
const configManager = this.configManager
@@ -345,13 +343,14 @@ module.exports = class KeyringController extends EventEmitter {
var time = (new Date()).getTime()
var txId = createId()
txParams.metamaskId = txId
- txParams.metamaskNetworkId = this.network
+ txParams.metamaskNetworkId = this.getNetwork()
var txData = {
id: txId,
txParams: txParams,
time: time,
status: 'unconfirmed',
gasMultiplier: configManager.getGasMultiplier() || 1,
+ metamaskNetworkId: this.getNetwork(),
}
@@ -369,7 +368,7 @@ module.exports = class KeyringController extends EventEmitter {
], didComplete)
// perform static analyis on the target contract code
- function analyzeForDelegateCall(cb){
+ function analyzeForDelegateCall (cb) {
if (txParams.to) {
query.getCode(txParams.to, function (err, result) {
if (err) return cb(err)
@@ -388,8 +387,8 @@ module.exports = class KeyringController extends EventEmitter {
}
}
- function estimateGas(cb){
- query.estimateGas(txParams, function(err, result){
+ function estimateGas (cb) {
+ query.estimateGas(txParams, function (err, result) {
if (err) return cb(err)
txData.estimatedGas = self.addGasBuffer(result)
cb()
@@ -406,7 +405,7 @@ module.exports = class KeyringController extends EventEmitter {
}
}
- addUnconfirmedMessage(msgParams, cb) {
+ addUnconfirmedMessage (msgParams, cb) {
// create txData obj with parameters and meta data
var time = (new Date()).getTime()
var msgId = createId()
@@ -428,7 +427,7 @@ module.exports = class KeyringController extends EventEmitter {
return msgId
}
- approveTransaction(txId, cb) {
+ approveTransaction (txId, cb) {
const configManager = this.configManager
var approvalCb = this._unconfTxCbs[txId] || noop
@@ -441,7 +440,7 @@ module.exports = class KeyringController extends EventEmitter {
this.emit('update')
}
- cancelTransaction(txId, cb) {
+ cancelTransaction (txId, cb) {
const configManager = this.configManager
var approvalCb = this._unconfTxCbs[txId] || noop
@@ -456,7 +455,7 @@ module.exports = class KeyringController extends EventEmitter {
}
}
- signTransaction(txParams, cb) {
+ signTransaction (txParams, cb) {
try {
const address = normalize(txParams.from)
const keyring = this.getKeyringForAccount(address)
@@ -492,7 +491,7 @@ module.exports = class KeyringController extends EventEmitter {
}
}
- signMessage(msgParams, cb) {
+ signMessage (msgParams, cb) {
try {
const keyring = this.getKeyringForAccount(msgParams.from)
const address = normalize(msgParams.from)
@@ -503,7 +502,7 @@ module.exports = class KeyringController extends EventEmitter {
}
}
- getKeyringForAccount(address) {
+ getKeyringForAccount (address) {
const hexed = normalize(address)
return this.keyrings.find((ring) => {
return ring.getAccounts()
@@ -512,19 +511,20 @@ module.exports = class KeyringController extends EventEmitter {
})
}
- cancelMessage(msgId, cb) {
+ cancelMessage (msgId, cb) {
if (cb && typeof cb === 'function') {
cb()
}
}
- setLocked(cb) {
+ setLocked (cb) {
this.key = null
this.keyrings = []
+ this.emit('update')
cb()
}
- exportAccount(address, cb) {
+ exportAccount (address, cb) {
try {
const keyring = this.getKeyringForAccount(address)
const privateKey = keyring.exportAccount(normalize(address))
@@ -534,19 +534,19 @@ module.exports = class KeyringController extends EventEmitter {
}
}
- addGasBuffer(gas) {
+ addGasBuffer (gas) {
const gasBuffer = new BN('100000', 10)
const bnGas = new BN(ethUtil.stripHexPrefix(gas), 16)
const correct = bnGas.add(gasBuffer)
return ethUtil.addHexPrefix(correct.toString(16))
}
- clearSeedWordCache(cb) {
+ clearSeedWordCache (cb) {
this.configManager.setSeedWords(null)
cb(null, this.configManager.getSelectedAccount())
}
- clearKeyrings() {
+ clearKeyrings () {
let accounts
try {
accounts = Object.keys(this.ethStore._currentState.accounts)
@@ -564,9 +564,4 @@ module.exports = class KeyringController extends EventEmitter {
}
-function normalize(address) {
- if (!address) return
- return ethUtil.addHexPrefix(address.toLowerCase())
-}
-
function noop () {}
diff --git a/app/scripts/keyrings/hd.js b/app/scripts/keyrings/hd.js
index 4bfc56c15..b98f29187 100644
--- a/app/scripts/keyrings/hd.js
+++ b/app/scripts/keyrings/hd.js
@@ -2,24 +2,25 @@ const EventEmitter = require('events').EventEmitter
const hdkey = require('ethereumjs-wallet/hdkey')
const bip39 = require('bip39')
const ethUtil = require('ethereumjs-util')
-const type = 'HD Key Tree'
const sigUtil = require('../lib/sig-util')
+const type = 'HD Key Tree'
+
const hdPathString = `m/44'/60'/0'/0`
module.exports = class HdKeyring extends EventEmitter {
- static type() {
+ static type () {
return type
}
- constructor(opts = {}) {
+ constructor (opts = {}) {
super()
this.type = type
this.deserialize(opts)
}
- deserialize(opts = {}) {
+ deserialize (opts = {}) {
this.opts = opts || {}
this.wallets = []
this.mnemonic = null
@@ -29,38 +30,38 @@ module.exports = class HdKeyring extends EventEmitter {
this.initFromMnemonic(opts.mnemonic)
}
- if ('n' in opts) {
- this.addAccounts(opts.n)
+ if ('numberOfAccounts' in opts) {
+ this.addAccounts(opts.numberOfAccounts)
}
}
- initFromMnemonic(mnemonic) {
+ initFromMnemonic (mnemonic) {
this.mnemonic = mnemonic
const seed = bip39.mnemonicToSeed(mnemonic)
this.hdWallet = hdkey.fromMasterSeed(seed)
this.root = this.hdWallet.derivePath(hdPathString)
}
- serialize() {
+ serialize () {
return {
mnemonic: this.mnemonic,
- n: this.wallets.length,
+ numberOfAccounts: this.wallets.length,
}
}
- exportAccount(address) {
+ exportAccount (address) {
const wallet = this.getWalletForAccount(address)
return wallet.getPrivateKey().toString('hex')
}
- addAccounts(n = 1) {
+ addAccounts (numberOfAccounts = 1) {
if (!this.root) {
this.initFromMnemonic(bip39.generateMnemonic())
}
const oldLen = this.wallets.length
const newWallets = []
- for (let i = oldLen; i < n + oldLen; i++) {
+ for (let i = oldLen; i < numberOfAccounts + oldLen; i++) {
const child = this.root.deriveChild(i)
const wallet = child.getWallet()
newWallets.push(wallet)
@@ -69,12 +70,12 @@ module.exports = class HdKeyring extends EventEmitter {
return newWallets.map(w => w.getAddress().toString('hex'))
}
- getAccounts() {
+ getAccounts () {
return this.wallets.map(w => w.getAddress().toString('hex'))
}
// tx is an instance of the ethereumjs-transaction class.
- signTransaction(address, tx) {
+ signTransaction (address, tx) {
const wallet = this.getWalletForAccount(address)
var privKey = wallet.getPrivateKey()
tx.sign(privKey)
@@ -82,7 +83,7 @@ module.exports = class HdKeyring extends EventEmitter {
}
// For eth_sign, we need to sign transactions:
- signMessage(withAccount, data) {
+ signMessage (withAccount, data) {
const wallet = this.getWalletForAccount(withAccount)
const message = ethUtil.removeHexPrefix(data)
var privKey = wallet.getPrivateKey()
@@ -91,17 +92,10 @@ module.exports = class HdKeyring extends EventEmitter {
return rawMsgSig
}
- getWalletForAccount(account) {
+ getWalletForAccount (account) {
return this.wallets.find((w) => {
const address = w.getAddress().toString('hex')
- return ((address === account) || (normalize(address) === account))
+ return ((address === account) || (sigUtil.normalize(address) === account))
})
}
-
-
-
-}
-
-function normalize(address) {
- return ethUtil.addHexPrefix(address.toLowerCase())
}
diff --git a/app/scripts/keyrings/simple.js b/app/scripts/keyrings/simple.js
index 9e832f274..ee743bc03 100644
--- a/app/scripts/keyrings/simple.js
+++ b/app/scripts/keyrings/simple.js
@@ -6,22 +6,22 @@ const sigUtil = require('../lib/sig-util')
module.exports = class SimpleKeyring extends EventEmitter {
- static type() {
+ static type () {
return type
}
- constructor(opts) {
+ constructor (opts) {
super()
this.type = type
this.opts = opts || {}
this.wallets = []
}
- serialize() {
+ serialize () {
return this.wallets.map(w => w.getPrivateKey().toString('hex'))
}
- deserialize(wallets = []) {
+ deserialize (wallets = []) {
this.wallets = wallets.map((w) => {
var b = new Buffer(w, 'hex')
const wallet = Wallet.fromPrivateKey(b)
@@ -29,7 +29,7 @@ module.exports = class SimpleKeyring extends EventEmitter {
})
}
- addAccounts(n = 1) {
+ addAccounts (n = 1) {
var newWallets = []
for (var i = 0; i < n; i++) {
newWallets.push(Wallet.generate())
@@ -38,12 +38,12 @@ module.exports = class SimpleKeyring extends EventEmitter {
return newWallets.map(w => w.getAddress().toString('hex'))
}
- getAccounts() {
+ getAccounts () {
return this.wallets.map(w => w.getAddress().toString('hex'))
}
// tx is an instance of the ethereumjs-transaction class.
- signTransaction(address, tx) {
+ signTransaction (address, tx) {
const wallet = this.getWalletForAccount(address)
var privKey = wallet.getPrivateKey()
tx.sign(privKey)
@@ -51,7 +51,7 @@ module.exports = class SimpleKeyring extends EventEmitter {
}
// For eth_sign, we need to sign transactions:
- signMessage(withAccount, data) {
+ signMessage (withAccount, data) {
const wallet = this.getWalletForAccount(withAccount)
const message = ethUtil.removeHexPrefix(data)
var privKey = wallet.getPrivateKey()
@@ -60,9 +60,8 @@ module.exports = class SimpleKeyring extends EventEmitter {
return rawMsgSig
}
- getWalletForAccount(account) {
+ getWalletForAccount (account) {
return this.wallets.find(w => w.getAddress().toString('hex') === account)
}
}
-
diff --git a/app/scripts/lib/auto-reload.js b/app/scripts/lib/auto-reload.js
index 3c90905db..1302df35f 100644
--- a/app/scripts/lib/auto-reload.js
+++ b/app/scripts/lib/auto-reload.js
@@ -18,17 +18,16 @@ function setupDappAutoReload (web3) {
return handleResetRequest
- function handleResetRequest() {
+ function handleResetRequest () {
resetWasRequested = true
// ignore if web3 was not used
if (!pageIsUsingWeb3) return
// reload after short timeout
setTimeout(triggerReset, 500)
}
-
}
// reload the page
function triggerReset () {
global.location.reload()
-} \ No newline at end of file
+}
diff --git a/app/scripts/lib/config-manager.js b/app/scripts/lib/config-manager.js
index f50d95c12..faf64bfdc 100644
--- a/app/scripts/lib/config-manager.js
+++ b/app/scripts/lib/config-manager.js
@@ -290,7 +290,7 @@ ConfigManager.prototype.getSalt = function () {
return ('salt' in data) && data.salt
}
-ConfigManager.prototype.setSalt = function(salt) {
+ConfigManager.prototype.setSalt = function (salt) {
var data = this.getData()
data.salt = salt
this.setData(data)
@@ -313,15 +313,15 @@ ConfigManager.prototype._emitUpdates = function (state) {
})
}
-ConfigManager.prototype.setConfirmed = function (confirmed) {
+ConfigManager.prototype.setConfirmedDisclaimer = function (confirmed) {
var data = this.getData()
- data.isConfirmed = confirmed
+ data.isDisclaimerConfirmed = confirmed
this.setData(data)
}
-ConfigManager.prototype.getConfirmed = function () {
+ConfigManager.prototype.getConfirmedDisclaimer = function () {
var data = this.getData()
- return ('isConfirmed' in data) && data.isConfirmed
+ return ('isDisclaimerConfirmed' in data) && data.isDisclaimerConfirmed
}
ConfigManager.prototype.setTOSHash = function (hash) {
@@ -358,7 +358,6 @@ ConfigManager.prototype.updateConversionRate = function () {
this.setConversionPrice(0)
this.setConversionDate('N/A')
})
-
}
ConfigManager.prototype.setConversionPrice = function (price) {
diff --git a/app/scripts/lib/encryptor.js b/app/scripts/lib/encryptor.js
index fe83b86dd..2af2a1d2b 100644
--- a/app/scripts/lib/encryptor.js
+++ b/app/scripts/lib/encryptor.js
@@ -26,7 +26,7 @@ module.exports = {
generateSalt,
}
-// Takes a Pojo, returns encrypted text.
+// Takes a Pojo, returns cypher text.
function encrypt (password, dataObj) {
return keyFromPassword(password)
.then(function (passwordDerivedKey) {
@@ -42,7 +42,7 @@ function encryptWithKey (key, dataObj) {
return global.crypto.subtle.encrypt({
name: 'AES-GCM',
iv: vector,
- }, key, dataBuffer).then(function(buf){
+ }, key, dataBuffer).then(function (buf) {
var buffer = new Uint8Array(buf)
var vectorStr = encodeBufferToBase64(vector)
var vaultStr = encodeBufferToBase64(buffer)
@@ -63,13 +63,13 @@ function decryptWithKey (key, text) {
const encryptedData = decodeBase64ToBuffer(parts[0])
const vector = decodeBase64ToBuffer(parts[1])
return crypto.subtle.decrypt({name: 'AES-GCM', iv: vector}, key, encryptedData)
- .then(function(result){
+ .then(function (result) {
const decryptedData = new Uint8Array(result)
const decryptedStr = convertArrayBufferViewtoString(decryptedData)
const decryptedObj = JSON.parse(decryptedStr)
return decryptedObj
})
- .catch(function(reason) {
+ .catch(function (reason) {
throw new Error('Incorrect password')
})
}
@@ -95,7 +95,7 @@ function convertArrayBufferViewtoString (buffer) {
function keyFromPassword (password) {
var passBuffer = convertStringToArrayBufferView(password)
return global.crypto.subtle.digest('SHA-256', passBuffer)
- .then(function (passHash){
+ .then(function (passHash) {
return global.crypto.subtle.importKey('raw', passHash, {name: 'AES-GCM'}, false, ['encrypt', 'decrypt'])
})
}
@@ -135,7 +135,7 @@ function encodeBufferToBase64 (buf) {
function decodeBase64ToBuffer (base64) {
var buf = new Uint8Array(atob(base64).split('')
- .map(function(c) {
+ .map(function (c) {
return c.charCodeAt(0)
}))
return buf
diff --git a/app/scripts/lib/idStore-migrator.js b/app/scripts/lib/idStore-migrator.js
index 2d1826641..818364720 100644
--- a/app/scripts/lib/idStore-migrator.js
+++ b/app/scripts/lib/idStore-migrator.js
@@ -11,7 +11,7 @@ module.exports = class IdentityStoreMigrator {
}
}
- oldSeedForPassword( password ) {
+ oldSeedForPassword (password) {
const hasOldVault = this.hasOldVault()
const configManager = this.configManager
@@ -35,7 +35,7 @@ module.exports = class IdentityStoreMigrator {
})
}
- serializeVault() {
+ serializeVault () {
const mnemonic = this.idStore._idmgmt.getSeed()
const n = this.idStore._getAddresses().length
@@ -45,7 +45,7 @@ module.exports = class IdentityStoreMigrator {
}
}
- hasOldVault() {
+ hasOldVault () {
const wallet = this.configManager.getWallet()
return wallet
}
diff --git a/app/scripts/lib/idStore.js b/app/scripts/lib/idStore.js
index ef2416cdf..d11c38be1 100644
--- a/app/scripts/lib/idStore.js
+++ b/app/scripts/lib/idStore.js
@@ -102,7 +102,7 @@ IdentityStore.prototype.getState = function () {
isInitialized: !!configManager.getWallet() && !seedWords,
isUnlocked: this._isUnlocked(),
seedWords: seedWords,
- isConfirmed: configManager.getConfirmed(),
+ isDisclaimerConfirmed: configManager.getConfirmedDisclaimer(),
unconfTxs: configManager.unconfirmedTxs(),
transactions: configManager.getTxList(),
unconfMsgs: messageManager.unconfirmedMsgs(),
@@ -243,10 +243,10 @@ IdentityStore.prototype.addUnconfirmedTransaction = function (txParams, onTxDone
], didComplete)
// perform static analyis on the target contract code
- function analyzeForDelegateCall(cb){
+ function analyzeForDelegateCall (cb) {
if (txParams.to) {
query.getCode(txParams.to, (err, result) => {
- if (err) return cb(err)
+ if (err) return cb(err.message || err)
var containsDelegateCall = self.checkForDelegateCall(result)
txData.containsDelegateCall = containsDelegateCall
cb()
@@ -256,16 +256,31 @@ IdentityStore.prototype.addUnconfirmedTransaction = function (txParams, onTxDone
}
}
- function estimateGas(cb){
- query.estimateGas(txParams, function(err, result){
- if (err) return cb(err)
+ function estimateGas (cb) {
+ var estimationParams = extend(txParams)
+ // 1 billion gas for estimation
+ var gasLimit = '0x3b9aca00'
+ estimationParams.gas = gasLimit
+ query.estimateGas(estimationParams, function (err, result) {
+ if (err) return cb(err.message || err)
+ if (result === estimationParams.gas) {
+ txData.simulationFails = true
+ query.getBlockByNumber('latest', true, function (err, block) {
+ if (err) return cb(err)
+ txData.estimatedGas = block.gasLimit
+ txData.txParams.gas = block.gasLimit
+ cb()
+ })
+ return
+ }
txData.estimatedGas = self.addGasBuffer(result)
+ txData.txParams.gas = txData.estimatedGas
cb()
})
}
function didComplete (err) {
- if (err) return cb(err)
+ if (err) return cb(err.message || err)
configManager.addTx(txData)
// signal update
self._didUpdate()
@@ -285,9 +300,10 @@ IdentityStore.prototype.checkForDelegateCall = function (codeHex) {
}
}
-const gasBuffer = new BN('100000', 10)
IdentityStore.prototype.addGasBuffer = function (gas) {
const bnGas = new BN(ethUtil.stripHexPrefix(gas), 16)
+ const five = new BN('5', 10)
+ const gasBuffer = bnGas.div(five)
const correct = bnGas.add(gasBuffer)
return ethUtil.addHexPrefix(correct.toString(16))
}
diff --git a/app/scripts/lib/inpage-provider.js b/app/scripts/lib/inpage-provider.js
index f1ba2e0ed..c9d617996 100644
--- a/app/scripts/lib/inpage-provider.js
+++ b/app/scripts/lib/inpage-provider.js
@@ -40,7 +40,7 @@ function MetamaskInpageProvider (connectionStream) {
self.idMap = {}
// handle sendAsync requests via asyncProvider
- self.sendAsync = function(payload, cb){
+ self.sendAsync = function (payload, cb) {
// rewrite request ids
var request = eachJsonMessage(payload, (message) => {
var newId = createRandomId()
@@ -49,7 +49,7 @@ function MetamaskInpageProvider (connectionStream) {
return message
})
// forward to asyncProvider
- asyncProvider.sendAsync(request, function(err, res){
+ asyncProvider.sendAsync(request, function (err, res) {
if (err) return cb(err)
// transform messages to original ids
eachJsonMessage(res, (message) => {
diff --git a/app/scripts/lib/is-popup-or-notification.js b/app/scripts/lib/is-popup-or-notification.js
index 5c38ac823..693fa8751 100644
--- a/app/scripts/lib/is-popup-or-notification.js
+++ b/app/scripts/lib/is-popup-or-notification.js
@@ -1,4 +1,4 @@
-module.exports = function isPopupOrNotification() {
+module.exports = function isPopupOrNotification () {
const url = window.location.href
if (url.match(/popup.html$/)) {
return 'popup'
diff --git a/app/scripts/lib/notifications.js b/app/scripts/lib/notifications.js
index cd7535232..3db1ac6b5 100644
--- a/app/scripts/lib/notifications.js
+++ b/app/scripts/lib/notifications.js
@@ -15,12 +15,9 @@ function show () {
if (err) throw err
if (popup) {
-
// bring focus to existing popup
extension.windows.update(popup.id, { focused: true })
-
} else {
-
// create new popup
extension.windows.create({
url: 'notification.html',
@@ -29,12 +26,11 @@ function show () {
width,
height,
})
-
}
})
}
-function getWindows(cb) {
+function getWindows (cb) {
// Ignore in test environment
if (!extension.windows) {
return cb()
@@ -45,14 +41,14 @@ function getWindows(cb) {
})
}
-function getPopup(cb) {
+function getPopup (cb) {
getWindows((err, windows) => {
if (err) throw err
cb(null, getPopupIn(windows))
})
}
-function getPopupIn(windows) {
+function getPopupIn (windows) {
return windows ? windows.find((win) => {
return (win && win.type === 'popup' &&
win.height === height &&
@@ -60,7 +56,7 @@ function getPopupIn(windows) {
}) : null
}
-function closePopup() {
+function closePopup () {
getPopup((err, popup) => {
if (err) throw err
if (!popup) return
diff --git a/app/scripts/lib/sig-util.js b/app/scripts/lib/sig-util.js
index f8748f535..193dda381 100644
--- a/app/scripts/lib/sig-util.js
+++ b/app/scripts/lib/sig-util.js
@@ -12,6 +12,11 @@ module.exports = {
return ethUtil.addHexPrefix(rStr.concat(sStr, vStr)).toString('hex')
},
+ normalize: function (address) {
+ if (!address) return
+ return ethUtil.addHexPrefix(address.toLowerCase())
+ },
+
}
function padWithZeroes (number, length) {
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index a165a2e2a..951918460 100644
--- a/app/scripts/metamask-controller.js
+++ b/app/scripts/metamask-controller.js
@@ -17,6 +17,7 @@ module.exports = class MetamaskController {
this.configManager = new ConfigManager(opts)
this.keyringController = new KeyringController({
configManager: this.configManager,
+ getNetwork: this.getStateNetwork.bind(this),
})
this.provider = this.initializeProvider(opts)
this.ethStore = new EthStore(this.provider)
@@ -86,23 +87,6 @@ module.exports = class MetamaskController {
}
onRpcRequest (stream, originDomain, request) {
-
- /* Commented out for Parity compliance
- * Parity does not permit additional keys, like `origin`,
- * and Infura is not currently filtering this key out.
- var payloads = Array.isArray(request) ? request : [request]
- payloads.forEach(function (payload) {
- // Append origin to rpc payload
- payload.origin = originDomain
- // Append origin to signature request
- if (payload.method === 'eth_sendTransaction') {
- payload.params[0].origin = originDomain
- } else if (payload.method === 'eth_sign') {
- payload.params.push({ origin: originDomain })
- }
- })
- */
-
// handle rpc request
this.provider.sendAsync(request, function onPayloadHandled (err, response) {
logger(err, request, response)
@@ -215,10 +199,8 @@ module.exports = class MetamaskController {
newUnsignedTransaction (txParams, onTxDoneCb) {
const keyringController = this.keyringController
-
- let err = this.enforceTxValidations(txParams)
+ const err = this.enforceTxValidations(txParams)
if (err) return onTxDoneCb(err)
-
keyringController.addUnconfirmedTransaction(txParams, onTxDoneCb, (err, txData) => {
if (err) return onTxDoneCb(err)
this.sendUpdate()
@@ -291,12 +273,11 @@ module.exports = class MetamaskController {
} catch (e) {
console.error('Error in checking TOS change.')
}
-
}
agreeToDisclaimer (cb) {
try {
- this.configManager.setConfirmed(true)
+ this.configManager.setConfirmedDisclaimer(true)
cb()
} catch (e) {
cb(e)
@@ -305,7 +286,7 @@ module.exports = class MetamaskController {
resetDisclaimer () {
try {
- this.configManager.setConfirmed(false)
+ this.configManager.setConfirmedDisclaimer(false)
} catch (e) {
console.error(e)
}
@@ -373,7 +354,7 @@ module.exports = class MetamaskController {
this.configManager.createShapeShiftTx(depositAddress, depositType)
}
- getNetwork(err) {
+ getNetwork (err) {
if (err) {
this.state.network = 'loading'
this.sendUpdate()
@@ -400,4 +381,8 @@ module.exports = class MetamaskController {
cb(e)
}
}
+
+ getStateNetwork () {
+ return this.state.network
+ }
}
diff --git a/app/scripts/popup-core.js b/app/scripts/popup-core.js
index 94413a1c4..0c97a5d19 100644
--- a/app/scripts/popup-core.js
+++ b/app/scripts/popup-core.js
@@ -9,7 +9,7 @@ const setupMultiplex = require('./lib/stream-utils.js').setupMultiplex
module.exports = initializePopup
-function initializePopup(connectionStream){
+function initializePopup (connectionStream) {
// setup app
connectToAccountManager(connectionStream, setupApp)
}
@@ -32,7 +32,7 @@ function setupWeb3Connection (connectionStream) {
}
function setupControllerConnection (connectionStream, cb) {
- // this is a really sneaky way of adding EventEmitter api
+ // this is a really sneaky way of adding EventEmitter api
// to a bi-directional dnode instance
var eventEmitter = new EventEmitter()
var accountManagerDnode = Dnode({
diff --git a/app/scripts/popup.js b/app/scripts/popup.js
index e6f149f96..62db68c10 100644
--- a/app/scripts/popup.js
+++ b/app/scripts/popup.js
@@ -18,7 +18,7 @@ var portStream = new PortStream(pluginPort)
startPopup(portStream)
-function closePopupIfOpen(name) {
+function closePopupIfOpen (name) {
if (name !== 'notification') {
notification.closePopup()
}