aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/scripts/inpage.js2
-rw-r--r--app/scripts/keyring-controller.js16
-rw-r--r--app/scripts/lib/encryptor.js10
-rw-r--r--app/scripts/lib/idStore-migrator.js2
-rw-r--r--app/scripts/lib/idStore.js8
-rw-r--r--app/scripts/lib/inpage-provider.js10
-rw-r--r--app/scripts/metamask-controller.js16
7 files changed, 33 insertions, 31 deletions
diff --git a/app/scripts/inpage.js b/app/scripts/inpage.js
index 9d6fc96de..68c6165c8 100644
--- a/app/scripts/inpage.js
+++ b/app/scripts/inpage.js
@@ -50,7 +50,7 @@ endOfStream(pingStream, triggerReload)
// set web3 defaultAcount
inpageProvider.publicConfigStore.subscribe(function (state) {
- web3.eth.defaultAccount = state.selectedAddress
+ web3.eth.defaultAccount = state.selectedAccount
})
//
diff --git a/app/scripts/keyring-controller.js b/app/scripts/keyring-controller.js
index cb92af388..34d81ace3 100644
--- a/app/scripts/keyring-controller.js
+++ b/app/scripts/keyring-controller.js
@@ -9,7 +9,6 @@ const EventEmitter = require('events').EventEmitter
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
@@ -61,7 +60,6 @@ module.exports = class KeyringController extends EventEmitter {
transactions: this.configManager.getTxList(),
unconfMsgs: messageManager.unconfirmedMsgs(),
messages: messageManager.getMsgList(),
- selectedAddress: address,
selectedAccount: address,
shapeShiftTxList: this.configManager.getShapeShiftTxList(),
currentFiat: this.configManager.getCurrentFiat(),
@@ -76,8 +74,8 @@ module.exports = class KeyringController extends EventEmitter {
this.ethStore = ethStore
}
- createNewVaultAndKeychain (password, entropy, cb) {
- this.createNewVault(password, entropy, (err) => {
+ createNewVaultAndKeychain (password, cb) {
+ this.createNewVault(password, (err) => {
if (err) return cb(err)
this.createFirstKeyTree(password, cb)
})
@@ -94,7 +92,7 @@ module.exports = class KeyringController extends EventEmitter {
this.clearKeyrings()
- this.createNewVault(password, '', (err) => {
+ this.createNewVault(password, (err) => {
if (err) return cb(err)
this.addNewKeyring('HD Key Tree', {
mnemonic: seed,
@@ -121,7 +119,7 @@ module.exports = class KeyringController extends EventEmitter {
.then((derivedKey) => {
key = derivedKey
this.key = key
- return this.idStoreMigrator.oldSeedForPassword(password)
+ return this.idStoreMigrator.migratedVaultForPassword(password)
})
.then((serialized) => {
if (serialized && shouldMigrate) {
@@ -135,7 +133,7 @@ module.exports = class KeyringController extends EventEmitter {
})
}
- createNewVault (password, entropy, cb) {
+ createNewVault (password, cb) {
const configManager = this.configManager
const salt = this.encryptor.generateSalt()
configManager.setSalt(salt)
@@ -161,7 +159,7 @@ module.exports = class KeyringController extends EventEmitter {
this.configManager.setSelectedAccount(firstAccount)
this.placeSeedWords()
- autoFaucet(hexAccount)
+ this.emit('newAccount', hexAccount)
this.setupAccounts(accounts)
this.persistAllKeyrings()
.then(() => {
@@ -334,7 +332,7 @@ module.exports = class KeyringController extends EventEmitter {
}, [])
}
- setSelectedAddress (address, cb) {
+ setSelectedAccount (address, cb) {
var addr = normalize(address)
this.configManager.setSelectedAccount(addr)
cb(null, addr)
diff --git a/app/scripts/lib/encryptor.js b/app/scripts/lib/encryptor.js
index 2af2a1d2b..df72b62c0 100644
--- a/app/scripts/lib/encryptor.js
+++ b/app/scripts/lib/encryptor.js
@@ -1,5 +1,3 @@
-var ethUtil = require('ethereumjs-util')
-
module.exports = {
// Simple encryption methods:
@@ -101,10 +99,10 @@ function keyFromPassword (password) {
}
function serializeBufferFromStorage (str) {
- str = ethUtil.stripHexPrefix(str)
- var buf = new Uint8Array(str.length / 2)
- for (var i = 0; i < str.length; i += 2) {
- var seg = str.substr(i, 2)
+ var stripStr = (str.slice(0, 2) === '0x') ? str.slice(2) : str
+ var buf = new Uint8Array(stripStr.length / 2)
+ for (var i = 0; i < stripStr.length; i += 2) {
+ var seg = stripStr.substr(i, 2)
buf[i / 2] = parseInt(seg, 16)
}
return buf
diff --git a/app/scripts/lib/idStore-migrator.js b/app/scripts/lib/idStore-migrator.js
index 18134b677..40b08efee 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) {
+ migratedVaultForPassword (password) {
const hasOldVault = this.hasOldVault()
const configManager = this.configManager
diff --git a/app/scripts/lib/idStore.js b/app/scripts/lib/idStore.js
index b73652af5..e5861c0ca 100644
--- a/app/scripts/lib/idStore.js
+++ b/app/scripts/lib/idStore.js
@@ -44,7 +44,7 @@ function IdentityStore (opts = {}) {
// public
//
-IdentityStore.prototype.createNewVault = function (password, entropy, cb) {
+IdentityStore.prototype.createNewVault = function (password, cb) {
delete this._keyStore
var serializedKeystore = this.configManager.getWallet()
@@ -53,7 +53,7 @@ IdentityStore.prototype.createNewVault = function (password, entropy, cb) {
}
this.purgeCache()
- this._createVault(password, null, entropy, (err) => {
+ this._createVault(password, null, (err) => {
if (err) return cb(err)
this._autoFaucet()
@@ -77,7 +77,7 @@ IdentityStore.prototype.recoverSeed = function (cb) {
IdentityStore.prototype.recoverFromSeed = function (password, seed, cb) {
this.purgeCache()
- this._createVault(password, seed, null, (err) => {
+ this._createVault(password, seed, (err) => {
if (err) return cb(err)
this._loadIdentities()
@@ -497,7 +497,7 @@ IdentityStore.prototype.tryPassword = function (password, cb) {
})
}
-IdentityStore.prototype._createVault = function (password, seedPhrase, entropy, cb) {
+IdentityStore.prototype._createVault = function (password, seedPhrase, cb) {
const opts = {
password,
hdPathString: this.hdPathString,
diff --git a/app/scripts/lib/inpage-provider.js b/app/scripts/lib/inpage-provider.js
index 034812b6a..7179ae978 100644
--- a/app/scripts/lib/inpage-provider.js
+++ b/app/scripts/lib/inpage-provider.js
@@ -66,20 +66,20 @@ function MetamaskInpageProvider (connectionStream) {
MetamaskInpageProvider.prototype.send = function (payload) {
const self = this
- let selectedAddress
+ let selectedAccount
let result = null
switch (payload.method) {
case 'eth_accounts':
// read from localStorage
- selectedAddress = self.publicConfigStore.get('selectedAddress')
- result = selectedAddress ? [selectedAddress] : []
+ selectedAccount = self.publicConfigStore.get('selectedAddress')
+ result = selectedAccount ? [selectedAccount] : []
break
case 'eth_coinbase':
// read from localStorage
- selectedAddress = self.publicConfigStore.get('selectedAddress')
- result = selectedAddress || '0x0000000000000000000000000000000000000000'
+ selectedAccount = self.publicConfigStore.get('selectedAddress')
+ result = selectedAccount || '0x0000000000000000000000000000000000000000'
break
// throw not-supported Error
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index 168a1cf59..701046e76 100644
--- a/app/scripts/metamask-controller.js
+++ b/app/scripts/metamask-controller.js
@@ -7,6 +7,8 @@ const HostStore = require('./lib/remote-store.js').HostStore
const Web3 = require('web3')
const ConfigManager = require('./lib/config-manager')
const extension = require('./lib/extension')
+const autoFaucet = require('./lib/auto-faucet')
+
module.exports = class MetamaskController {
@@ -67,7 +69,7 @@ module.exports = class MetamaskController {
addNewKeyring: keyringController.addNewKeyring.bind(keyringController),
addNewAccount: keyringController.addNewAccount.bind(keyringController),
submitPassword: keyringController.submitPassword.bind(keyringController),
- setSelectedAddress: keyringController.setSelectedAddress.bind(keyringController),
+ setSelectedAccount: keyringController.setSelectedAccount.bind(keyringController),
approveTransaction: keyringController.approveTransaction.bind(keyringController),
cancelTransaction: keyringController.cancelTransaction.bind(keyringController),
signMessage: keyringController.signMessage.bind(keyringController),
@@ -125,8 +127,8 @@ module.exports = class MetamaskController {
rpcUrl: this.configManager.getCurrentRpcAddress(),
// account mgmt
getAccounts: (cb) => {
- var selectedAddress = this.configManager.getSelectedAccount()
- var result = selectedAddress ? [selectedAddress] : []
+ var selectedAccount = this.configManager.getSelectedAccount()
+ var result = selectedAccount ? [selectedAccount] : []
cb(null, result)
},
// tx signing
@@ -174,17 +176,21 @@ module.exports = class MetamaskController {
this.sendUpdate()
})
+ this.keyringController.on('newAccount', (account) => {
+ autoFaucet(account)
+ })
+
// keyringController substate
function keyringControllerToPublic (state) {
return {
- selectedAddress: state.selectedAddress,
+ selectedAccount: state.selectedAccount,
}
}
// config substate
function configToPublic (state) {
return {
provider: state.provider,
- selectedAddress: state.selectedAccount,
+ selectedAccount: state.selectedAccount,
}
}
// dump obj into store