mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Improve refactor
Replace config-manager-singleton with one that is instantiated within the `background-controller`, and takes its persistence callbacks from its instantiated options. Replaced class getters with more familiar get___() functions.
This commit is contained in:
parent
9ed3c676ec
commit
b2b3f4b26b
@ -2,19 +2,18 @@ const extend = require('xtend')
|
|||||||
const EthStore = require('eth-store')
|
const EthStore = require('eth-store')
|
||||||
const MetaMaskProvider = require('web3-provider-engine/zero.js')
|
const MetaMaskProvider = require('web3-provider-engine/zero.js')
|
||||||
const IdentityStore = require('./lib/idStore')
|
const IdentityStore = require('./lib/idStore')
|
||||||
const configManager = require('./lib/config-manager-singleton')
|
|
||||||
const messageManager = require('./lib/message-manager')
|
const messageManager = require('./lib/message-manager')
|
||||||
const HostStore = require('./lib/remote-store.js').HostStore
|
const HostStore = require('./lib/remote-store.js').HostStore
|
||||||
const Web3 = require('web3')
|
const Web3 = require('web3')
|
||||||
|
const ConfigManager = require('./lib/config-manager')
|
||||||
|
|
||||||
module.exports = BackgroundController
|
module.exports = BackgroundController
|
||||||
|
|
||||||
class BackgroundController {
|
class BackgroundController {
|
||||||
|
|
||||||
constructor (opts) {
|
constructor (opts) {
|
||||||
this.idStore = new IdentityStore()
|
this.configManager = new ConfigManager(opts)
|
||||||
this.configManager = configManager
|
this.idStore = new IdentityStore({ configManager })
|
||||||
this.messageManager = messageManager
|
this.messageManager = messageManager
|
||||||
this.provider = this.initializeProvider(opts)
|
this.provider = this.initializeProvider(opts)
|
||||||
this.ethStore = new EthStore(this.provider)
|
this.ethStore = new EthStore(this.provider)
|
||||||
@ -22,7 +21,7 @@ class BackgroundController {
|
|||||||
this.publicConfigStore = this.initPublicConfigStore()
|
this.publicConfigStore = this.initPublicConfigStore()
|
||||||
}
|
}
|
||||||
|
|
||||||
get state () {
|
getState () {
|
||||||
return extend(
|
return extend(
|
||||||
this.ethStore.getState(),
|
this.ethStore.getState(),
|
||||||
this.idStore.getState(),
|
this.idStore.getState(),
|
||||||
@ -30,15 +29,15 @@ class BackgroundController {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
get api () {
|
getApi () {
|
||||||
const idStore = this.idStore
|
const idStore = this.idStore
|
||||||
|
|
||||||
return {
|
return {
|
||||||
getState: function (cb) { cb(null, this.state) },
|
getState: function (cb) { cb(null, this.getState()) },
|
||||||
setRpcTarget: setRpcTarget,
|
setRpcTarget: this.setRpcTarget.bind(this),
|
||||||
setProviderType: setProviderType,
|
setProviderType: this.setProviderType.bind(this),
|
||||||
useEtherscanProvider: useEtherscanProvider,
|
useEtherscanProvider: this.useEtherscanProvider.bind(this),
|
||||||
agreeToDisclaimer: agreeToDisclaimer,
|
agreeToDisclaimer: this.agreeToDisclaimer.bind(this),
|
||||||
// forward directly to idStore
|
// forward directly to idStore
|
||||||
createNewVault: idStore.createNewVault.bind(idStore),
|
createNewVault: idStore.createNewVault.bind(idStore),
|
||||||
recoverFromSeed: idStore.recoverFromSeed.bind(idStore),
|
recoverFromSeed: idStore.recoverFromSeed.bind(idStore),
|
||||||
@ -98,14 +97,14 @@ class BackgroundController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sendUpdate () {
|
sendUpdate () {
|
||||||
this.remote.sendUpdate(this.state)
|
this.remote.sendUpdate(this.getState())
|
||||||
}
|
}
|
||||||
|
|
||||||
initializeProvider (opts) {
|
initializeProvider (opts) {
|
||||||
const idStore = this.idStore
|
const idStore = this.idStore
|
||||||
|
|
||||||
var providerOpts = {
|
var providerOpts = {
|
||||||
rpcUrl: configManager.getCurrentRpcAddress(),
|
rpcUrl: this.configManager.getCurrentRpcAddress(),
|
||||||
// account mgmt
|
// account mgmt
|
||||||
getAccounts: function (cb) {
|
getAccounts: function (cb) {
|
||||||
var selectedAddress = idStore.getSelectedAddress()
|
var selectedAddress = idStore.getSelectedAddress()
|
||||||
@ -188,7 +187,7 @@ class BackgroundController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
newUnsignedMessage(msgParams, cb) {
|
newUnsignedMessage (msgParams, cb) {
|
||||||
var state = this.idStore.getState()
|
var state = this.idStore.getState()
|
||||||
if (!state.isUnlocked) {
|
if (!state.isUnlocked) {
|
||||||
this.opts.unlockAccountMessage()
|
this.opts.unlockAccountMessage()
|
||||||
@ -212,7 +211,7 @@ class BackgroundController {
|
|||||||
processBlock (block) {
|
processBlock (block) {
|
||||||
console.log(`BLOCK CHANGED: #${block.number.toString('hex')} 0x${block.hash.toString('hex')}`)
|
console.log(`BLOCK CHANGED: #${block.number.toString('hex')} 0x${block.hash.toString('hex')}`)
|
||||||
this.verifyNetwork()
|
this.verifyNetwork()
|
||||||
}
|
}
|
||||||
|
|
||||||
verifyNetwork () {
|
verifyNetwork () {
|
||||||
// Check network when restoring connectivity:
|
// Check network when restoring connectivity:
|
||||||
@ -220,36 +219,37 @@ class BackgroundController {
|
|||||||
this.idStore.getNetwork()
|
this.idStore.getNetwork()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// config
|
// config
|
||||||
//
|
//
|
||||||
|
|
||||||
function agreeToDisclaimer (cb) {
|
function agreeToDisclaimer (cb) {
|
||||||
try {
|
try {
|
||||||
configManager.setConfirmed(true)
|
this.configManager.setConfirmed(true)
|
||||||
cb()
|
cb()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
cb(e)
|
cb(e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// called from popup
|
// called from popup
|
||||||
function setRpcTarget (rpcTarget) {
|
function setRpcTarget (rpcTarget) {
|
||||||
configManager.setRpcTarget(rpcTarget)
|
this.configManager.setRpcTarget(rpcTarget)
|
||||||
chrome.runtime.reload()
|
chrome.runtime.reload()
|
||||||
idStore.getNetwork()
|
idStore.getNetwork()
|
||||||
}
|
}
|
||||||
|
|
||||||
function setProviderType (type) {
|
function setProviderType (type) {
|
||||||
configManager.setProviderType(type)
|
this.configManager.setProviderType(type)
|
||||||
chrome.runtime.reload()
|
chrome.runtime.reload()
|
||||||
idStore.getNetwork()
|
idStore.getNetwork()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function useEtherscanProvider () {
|
||||||
|
this.configManager.useEtherscanProvider()
|
||||||
|
chrome.runtime.reload()
|
||||||
|
}
|
||||||
|
|
||||||
function useEtherscanProvider () {
|
|
||||||
configManager.useEtherscanProvider()
|
|
||||||
chrome.runtime.reload()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function noop () {}
|
function noop () {}
|
||||||
|
@ -5,16 +5,20 @@ const PortStream = require('./lib/port-stream.js')
|
|||||||
const createUnlockRequestNotification = require('./lib/notifications.js').createUnlockRequestNotification
|
const createUnlockRequestNotification = require('./lib/notifications.js').createUnlockRequestNotification
|
||||||
const createTxNotification = require('./lib/notifications.js').createTxNotification
|
const createTxNotification = require('./lib/notifications.js').createTxNotification
|
||||||
const createMsgNotification = require('./lib/notifications.js').createMsgNotification
|
const createMsgNotification = require('./lib/notifications.js').createMsgNotification
|
||||||
const configManager = require('./lib/config-manager-singleton')
|
|
||||||
const messageManager = require('./lib/message-manager')
|
const messageManager = require('./lib/message-manager')
|
||||||
const setupMultiplex = require('./lib/stream-utils.js').setupMultiplex
|
const setupMultiplex = require('./lib/stream-utils.js').setupMultiplex
|
||||||
|
|
||||||
const BackgroundController = require('./background-controller')
|
const BackgroundController = require('./background-controller')
|
||||||
|
|
||||||
|
const STORAGE_KEY = 'metamask-config'
|
||||||
|
|
||||||
const controller = new BackgroundController({
|
const controller = new BackgroundController({
|
||||||
|
// User confirmation callbacks:
|
||||||
showUnconfirmedMessage,
|
showUnconfirmedMessage,
|
||||||
unlockAccountMessage,
|
unlockAccountMessage,
|
||||||
showUnconfirmedTx,
|
showUnconfirmedTx,
|
||||||
|
// Persistence Methods:
|
||||||
|
setData,
|
||||||
|
loadData,
|
||||||
})
|
})
|
||||||
const idStore = controller.idStore
|
const idStore = controller.idStore
|
||||||
|
|
||||||
@ -82,7 +86,7 @@ function setupTrustedCommunication (connectionStream, originDomain) {
|
|||||||
|
|
||||||
function setupControllerConnection (stream) {
|
function setupControllerConnection (stream) {
|
||||||
controller.stream = stream
|
controller.stream = stream
|
||||||
var api = controller.api
|
var api = controller.getApi()
|
||||||
var dnode = Dnode(api)
|
var dnode = Dnode(api)
|
||||||
stream.pipe(dnode).pipe(stream)
|
stream.pipe(dnode).pipe(stream)
|
||||||
dnode.on('remote', function() {
|
dnode.on('remote', function() {
|
||||||
@ -106,7 +110,7 @@ idStore.on('update', updateBadge)
|
|||||||
|
|
||||||
function updateBadge (state) {
|
function updateBadge (state) {
|
||||||
var label = ''
|
var label = ''
|
||||||
var unconfTxs = configManager.unconfirmedTxs()
|
var unconfTxs = controller.configManager.unconfirmedTxs()
|
||||||
var unconfTxLen = Object.keys(unconfTxs).length
|
var unconfTxLen = Object.keys(unconfTxs).length
|
||||||
var unconfMsgs = messageManager.unconfirmedMsgs()
|
var unconfMsgs = messageManager.unconfirmedMsgs()
|
||||||
var unconfMsgLen = Object.keys(unconfMsgs).length
|
var unconfMsgLen = Object.keys(unconfMsgs).length
|
||||||
@ -118,4 +122,54 @@ function updateBadge (state) {
|
|||||||
chrome.browserAction.setBadgeBackgroundColor({ color: '#506F8B' })
|
chrome.browserAction.setBadgeBackgroundColor({ color: '#506F8B' })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function loadData () {
|
||||||
|
var oldData = getOldStyleData()
|
||||||
|
var newData
|
||||||
|
try {
|
||||||
|
newData = JSON.parse(window.localStorage[STORAGE_KEY])
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
|
var data = extend({
|
||||||
|
meta: {
|
||||||
|
version: 0,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
config: {
|
||||||
|
provider: {
|
||||||
|
type: 'testnet',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}, oldData || null, newData || null)
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
|
function getOldStyleData () {
|
||||||
|
var config, wallet, seedWords
|
||||||
|
|
||||||
|
var result = {
|
||||||
|
meta: { version: 0 },
|
||||||
|
data: {},
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
config = JSON.parse(window.localStorage['config'])
|
||||||
|
result.data.config = config
|
||||||
|
} catch (e) {}
|
||||||
|
try {
|
||||||
|
wallet = JSON.parse(window.localStorage['lightwallet'])
|
||||||
|
result.data.wallet = wallet
|
||||||
|
} catch (e) {}
|
||||||
|
try {
|
||||||
|
seedWords = window.localStorage['seedWords']
|
||||||
|
result.data.seedWords = seedWords
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
function setData (data) {
|
||||||
|
window.localStorage[STORAGE_KEY] = JSON.stringify(data)
|
||||||
|
}
|
||||||
|
|
||||||
function noop () {}
|
function noop () {}
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
var ConfigManager = require('./config-manager')
|
|
||||||
|
|
||||||
module.exports = new ConfigManager()
|
|
@ -3,7 +3,6 @@ const extend = require('xtend')
|
|||||||
const MetamaskConfig = require('../config.js')
|
const MetamaskConfig = require('../config.js')
|
||||||
const migrations = require('./migrations')
|
const migrations = require('./migrations')
|
||||||
|
|
||||||
const STORAGE_KEY = 'metamask-config'
|
|
||||||
const TESTNET_RPC = MetamaskConfig.network.testnet
|
const TESTNET_RPC = MetamaskConfig.network.testnet
|
||||||
const MAINNET_RPC = MetamaskConfig.network.mainnet
|
const MAINNET_RPC = MetamaskConfig.network.mainnet
|
||||||
|
|
||||||
@ -15,7 +14,7 @@ const MAINNET_RPC = MetamaskConfig.network.mainnet
|
|||||||
* particular portions of the state.
|
* particular portions of the state.
|
||||||
*/
|
*/
|
||||||
module.exports = ConfigManager
|
module.exports = ConfigManager
|
||||||
function ConfigManager () {
|
function ConfigManager (opts) {
|
||||||
// ConfigManager is observable and will emit updates
|
// ConfigManager is observable and will emit updates
|
||||||
this._subs = []
|
this._subs = []
|
||||||
|
|
||||||
@ -37,12 +36,10 @@ function ConfigManager () {
|
|||||||
|
|
||||||
// How to load initial config.
|
// How to load initial config.
|
||||||
// Includes step on migrating pre-pojo-migrator data.
|
// Includes step on migrating pre-pojo-migrator data.
|
||||||
loadData: loadData,
|
loadData: opts.loadData,
|
||||||
|
|
||||||
// How to persist migrated config.
|
// How to persist migrated config.
|
||||||
setData: function (data) {
|
setData: opts.setData,
|
||||||
window.localStorage[STORAGE_KEY] = JSON.stringify(data)
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -280,49 +277,3 @@ ConfigManager.prototype.getConfirmed = function () {
|
|||||||
return ('isConfirmed' in data) && data.isConfirmed
|
return ('isConfirmed' in data) && data.isConfirmed
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadData () {
|
|
||||||
var oldData = getOldStyleData()
|
|
||||||
var newData
|
|
||||||
try {
|
|
||||||
newData = JSON.parse(window.localStorage[STORAGE_KEY])
|
|
||||||
} catch (e) {}
|
|
||||||
|
|
||||||
var data = extend({
|
|
||||||
meta: {
|
|
||||||
version: 0,
|
|
||||||
},
|
|
||||||
data: {
|
|
||||||
config: {
|
|
||||||
provider: {
|
|
||||||
type: 'testnet',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}, oldData || null, newData || null)
|
|
||||||
return data
|
|
||||||
}
|
|
||||||
|
|
||||||
function getOldStyleData () {
|
|
||||||
var config, wallet, seedWords
|
|
||||||
|
|
||||||
var result = {
|
|
||||||
meta: { version: 0 },
|
|
||||||
data: {},
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
config = JSON.parse(window.localStorage['config'])
|
|
||||||
result.data.config = config
|
|
||||||
} catch (e) {}
|
|
||||||
try {
|
|
||||||
wallet = JSON.parse(window.localStorage['lightwallet'])
|
|
||||||
result.data.wallet = wallet
|
|
||||||
} catch (e) {}
|
|
||||||
try {
|
|
||||||
seedWords = window.localStorage['seedWords']
|
|
||||||
result.data.seedWords = seedWords
|
|
||||||
} catch (e) {}
|
|
||||||
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
const ethUtil = require('ethereumjs-util')
|
const ethUtil = require('ethereumjs-util')
|
||||||
const Transaction = require('ethereumjs-tx')
|
const Transaction = require('ethereumjs-tx')
|
||||||
const configManager = require('./config-manager-singleton')
|
|
||||||
|
|
||||||
module.exports = IdManagement
|
module.exports = IdManagement
|
||||||
|
|
||||||
@ -9,6 +8,7 @@ function IdManagement (opts) {
|
|||||||
|
|
||||||
this.keyStore = opts.keyStore
|
this.keyStore = opts.keyStore
|
||||||
this.derivedKey = opts.derivedKey
|
this.derivedKey = opts.derivedKey
|
||||||
|
this.configManager = opts.configManager
|
||||||
this.hdPathString = "m/44'/60'/0'/0"
|
this.hdPathString = "m/44'/60'/0'/0"
|
||||||
|
|
||||||
this.getAddresses = function () {
|
this.getAddresses = function () {
|
||||||
@ -32,9 +32,9 @@ function IdManagement (opts) {
|
|||||||
|
|
||||||
// Add the tx hash to the persisted meta-tx object
|
// Add the tx hash to the persisted meta-tx object
|
||||||
var txHash = ethUtil.bufferToHex(tx.hash())
|
var txHash = ethUtil.bufferToHex(tx.hash())
|
||||||
var metaTx = configManager.getTx(txParams.metamaskId)
|
var metaTx = this.configManager.getTx(txParams.metamaskId)
|
||||||
metaTx.hash = txHash
|
metaTx.hash = txHash
|
||||||
configManager.updateTx(metaTx)
|
this.configManager.updateTx(metaTx)
|
||||||
|
|
||||||
// return raw serialized tx
|
// return raw serialized tx
|
||||||
var rawTx = ethUtil.bufferToHex(tx.serialize())
|
var rawTx = ethUtil.bufferToHex(tx.serialize())
|
||||||
|
@ -7,7 +7,6 @@ const extend = require('xtend')
|
|||||||
const createId = require('web3-provider-engine/util/random-id')
|
const createId = require('web3-provider-engine/util/random-id')
|
||||||
const ethBinToOps = require('eth-bin-to-ops')
|
const ethBinToOps = require('eth-bin-to-ops')
|
||||||
const autoFaucet = require('./auto-faucet')
|
const autoFaucet = require('./auto-faucet')
|
||||||
const configManager = require('./config-manager-singleton')
|
|
||||||
const messageManager = require('./message-manager')
|
const messageManager = require('./message-manager')
|
||||||
const DEFAULT_RPC = 'https://testrpc.metamask.io/'
|
const DEFAULT_RPC = 'https://testrpc.metamask.io/'
|
||||||
const IdManagement = require('./id-management')
|
const IdManagement = require('./id-management')
|
||||||
@ -20,6 +19,7 @@ function IdentityStore (opts = {}) {
|
|||||||
|
|
||||||
// we just use the ethStore to auto-add accounts
|
// we just use the ethStore to auto-add accounts
|
||||||
this._ethStore = opts.ethStore
|
this._ethStore = opts.ethStore
|
||||||
|
this.configManager = opts.configManager
|
||||||
// lightwallet key store
|
// lightwallet key store
|
||||||
this._keyStore = null
|
this._keyStore = null
|
||||||
// lightwallet wrapper
|
// lightwallet wrapper
|
||||||
@ -43,7 +43,7 @@ function IdentityStore (opts = {}) {
|
|||||||
|
|
||||||
IdentityStore.prototype.createNewVault = function (password, entropy, cb) {
|
IdentityStore.prototype.createNewVault = function (password, entropy, cb) {
|
||||||
delete this._keyStore
|
delete this._keyStore
|
||||||
configManager.clearWallet()
|
this.configManager.clearWallet()
|
||||||
this._createIdmgmt(password, null, entropy, (err) => {
|
this._createIdmgmt(password, null, entropy, (err) => {
|
||||||
if (err) return cb(err)
|
if (err) return cb(err)
|
||||||
|
|
||||||
@ -51,14 +51,14 @@ IdentityStore.prototype.createNewVault = function (password, entropy, cb) {
|
|||||||
this._didUpdate()
|
this._didUpdate()
|
||||||
this._autoFaucet()
|
this._autoFaucet()
|
||||||
|
|
||||||
configManager.setShowSeedWords(true)
|
this.configManager.setShowSeedWords(true)
|
||||||
var seedWords = this._idmgmt.getSeed()
|
var seedWords = this._idmgmt.getSeed()
|
||||||
cb(null, seedWords)
|
cb(null, seedWords)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
IdentityStore.prototype.recoverSeed = function (cb) {
|
IdentityStore.prototype.recoverSeed = function (cb) {
|
||||||
configManager.setShowSeedWords(true)
|
this.configManager.setShowSeedWords(true)
|
||||||
if (!this._idmgmt) return cb(new Error('Unauthenticated. Please sign in.'))
|
if (!this._idmgmt) return cb(new Error('Unauthenticated. Please sign in.'))
|
||||||
var seedWords = this._idmgmt.getSeed()
|
var seedWords = this._idmgmt.getSeed()
|
||||||
cb(null, seedWords)
|
cb(null, seedWords)
|
||||||
@ -79,11 +79,13 @@ IdentityStore.prototype.setStore = function (store) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
IdentityStore.prototype.clearSeedWordCache = function (cb) {
|
IdentityStore.prototype.clearSeedWordCache = function (cb) {
|
||||||
|
const configManager = this.configManager
|
||||||
configManager.setShowSeedWords(false)
|
configManager.setShowSeedWords(false)
|
||||||
cb(null, configManager.getSelectedAccount())
|
cb(null, configManager.getSelectedAccount())
|
||||||
}
|
}
|
||||||
|
|
||||||
IdentityStore.prototype.getState = function () {
|
IdentityStore.prototype.getState = function () {
|
||||||
|
const configManager = this.configManager
|
||||||
var seedWords = this.getSeedIfUnlocked()
|
var seedWords = this.getSeedIfUnlocked()
|
||||||
return clone(extend(this._currentState, {
|
return clone(extend(this._currentState, {
|
||||||
isInitialized: !!configManager.getWallet() && !seedWords,
|
isInitialized: !!configManager.getWallet() && !seedWords,
|
||||||
@ -99,6 +101,7 @@ IdentityStore.prototype.getState = function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
IdentityStore.prototype.getSeedIfUnlocked = function () {
|
IdentityStore.prototype.getSeedIfUnlocked = function () {
|
||||||
|
const configManager = this.configManager
|
||||||
var showSeed = configManager.getShouldShowSeedWords()
|
var showSeed = configManager.getShouldShowSeedWords()
|
||||||
var idmgmt = this._idmgmt
|
var idmgmt = this._idmgmt
|
||||||
var shouldShow = showSeed && !!idmgmt
|
var shouldShow = showSeed && !!idmgmt
|
||||||
@ -107,10 +110,12 @@ IdentityStore.prototype.getSeedIfUnlocked = function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
IdentityStore.prototype.getSelectedAddress = function () {
|
IdentityStore.prototype.getSelectedAddress = function () {
|
||||||
|
const configManager = this.configManager
|
||||||
return configManager.getSelectedAccount()
|
return configManager.getSelectedAccount()
|
||||||
}
|
}
|
||||||
|
|
||||||
IdentityStore.prototype.setSelectedAddress = function (address, cb) {
|
IdentityStore.prototype.setSelectedAddress = function (address, cb) {
|
||||||
|
const configManager = this.configManager
|
||||||
if (!address) {
|
if (!address) {
|
||||||
var addresses = this._getAddresses()
|
var addresses = this._getAddresses()
|
||||||
address = addresses[0]
|
address = addresses[0]
|
||||||
@ -123,6 +128,7 @@ IdentityStore.prototype.setSelectedAddress = function (address, cb) {
|
|||||||
IdentityStore.prototype.revealAccount = function (cb) {
|
IdentityStore.prototype.revealAccount = function (cb) {
|
||||||
const derivedKey = this._idmgmt.derivedKey
|
const derivedKey = this._idmgmt.derivedKey
|
||||||
const keyStore = this._keyStore
|
const keyStore = this._keyStore
|
||||||
|
const configManager = this.configManager
|
||||||
|
|
||||||
keyStore.setDefaultHdDerivationPath(this.hdPathString)
|
keyStore.setDefaultHdDerivationPath(this.hdPathString)
|
||||||
keyStore.generateNewAddress(derivedKey, 1)
|
keyStore.generateNewAddress(derivedKey, 1)
|
||||||
@ -158,6 +164,7 @@ IdentityStore.prototype.setLocked = function (cb) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
IdentityStore.prototype.submitPassword = function (password, cb) {
|
IdentityStore.prototype.submitPassword = function (password, cb) {
|
||||||
|
const configManager = this.configManager
|
||||||
this.tryPassword(password, (err) => {
|
this.tryPassword(password, (err) => {
|
||||||
if (err) return cb(err)
|
if (err) return cb(err)
|
||||||
// load identities before returning...
|
// load identities before returning...
|
||||||
@ -177,6 +184,7 @@ IdentityStore.prototype.exportAccount = function (address, cb) {
|
|||||||
|
|
||||||
// comes from dapp via zero-client hooked-wallet provider
|
// comes from dapp via zero-client hooked-wallet provider
|
||||||
IdentityStore.prototype.addUnconfirmedTransaction = function (txParams, onTxDoneCb, cb) {
|
IdentityStore.prototype.addUnconfirmedTransaction = function (txParams, onTxDoneCb, cb) {
|
||||||
|
const configManager = this.configManager
|
||||||
var self = this
|
var self = this
|
||||||
// create txData obj with parameters and meta data
|
// create txData obj with parameters and meta data
|
||||||
var time = (new Date()).getTime()
|
var time = (new Date()).getTime()
|
||||||
@ -227,6 +235,7 @@ IdentityStore.prototype.addUnconfirmedTransaction = function (txParams, onTxDone
|
|||||||
|
|
||||||
// comes from metamask ui
|
// comes from metamask ui
|
||||||
IdentityStore.prototype.approveTransaction = function (txId, cb) {
|
IdentityStore.prototype.approveTransaction = function (txId, cb) {
|
||||||
|
const configManager = this.configManager
|
||||||
var approvalCb = this._unconfTxCbs[txId] || noop
|
var approvalCb = this._unconfTxCbs[txId] || noop
|
||||||
|
|
||||||
// accept tx
|
// accept tx
|
||||||
@ -240,6 +249,7 @@ IdentityStore.prototype.approveTransaction = function (txId, cb) {
|
|||||||
|
|
||||||
// comes from metamask ui
|
// comes from metamask ui
|
||||||
IdentityStore.prototype.cancelTransaction = function (txId) {
|
IdentityStore.prototype.cancelTransaction = function (txId) {
|
||||||
|
const configManager = this.configManager
|
||||||
var approvalCb = this._unconfTxCbs[txId] || noop
|
var approvalCb = this._unconfTxCbs[txId] || noop
|
||||||
|
|
||||||
// reject tx
|
// reject tx
|
||||||
@ -347,6 +357,7 @@ IdentityStore.prototype._isUnlocked = function () {
|
|||||||
|
|
||||||
// load identities from keyStoreet
|
// load identities from keyStoreet
|
||||||
IdentityStore.prototype._loadIdentities = function () {
|
IdentityStore.prototype._loadIdentities = function () {
|
||||||
|
const configManager = this.configManager
|
||||||
if (!this._isUnlocked()) throw new Error('not unlocked')
|
if (!this._isUnlocked()) throw new Error('not unlocked')
|
||||||
|
|
||||||
var addresses = this._getAddresses()
|
var addresses = this._getAddresses()
|
||||||
@ -367,6 +378,7 @@ IdentityStore.prototype._loadIdentities = function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
IdentityStore.prototype.saveAccountLabel = function (account, label, cb) {
|
IdentityStore.prototype.saveAccountLabel = function (account, label, cb) {
|
||||||
|
const configManager = this.configManager
|
||||||
configManager.setNicknameForWallet(account, label)
|
configManager.setNicknameForWallet(account, label)
|
||||||
this._loadIdentities()
|
this._loadIdentities()
|
||||||
cb(null, label)
|
cb(null, label)
|
||||||
@ -379,6 +391,7 @@ IdentityStore.prototype.saveAccountLabel = function (account, label, cb) {
|
|||||||
// If there is no balance and it mayBeFauceting,
|
// If there is no balance and it mayBeFauceting,
|
||||||
// then it is in fact fauceting.
|
// then it is in fact fauceting.
|
||||||
IdentityStore.prototype._mayBeFauceting = function (i) {
|
IdentityStore.prototype._mayBeFauceting = function (i) {
|
||||||
|
const configManager = this.configManager
|
||||||
var config = configManager.getProvider()
|
var config = configManager.getProvider()
|
||||||
if (i === 0 &&
|
if (i === 0 &&
|
||||||
config.type === 'rpc' &&
|
config.type === 'rpc' &&
|
||||||
@ -397,6 +410,7 @@ IdentityStore.prototype.tryPassword = function (password, cb) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
IdentityStore.prototype._createIdmgmt = function (password, seed, entropy, cb) {
|
IdentityStore.prototype._createIdmgmt = function (password, seed, entropy, cb) {
|
||||||
|
const configManager = this.configManager
|
||||||
var keyStore = null
|
var keyStore = null
|
||||||
LightwalletKeyStore.deriveKeyFromPassword(password, (err, derivedKey) => {
|
LightwalletKeyStore.deriveKeyFromPassword(password, (err, derivedKey) => {
|
||||||
if (err) return cb(err)
|
if (err) return cb(err)
|
||||||
@ -425,6 +439,7 @@ IdentityStore.prototype._createIdmgmt = function (password, seed, entropy, cb) {
|
|||||||
keyStore: keyStore,
|
keyStore: keyStore,
|
||||||
derivedKey: derivedKey,
|
derivedKey: derivedKey,
|
||||||
hdPathSTring: this.hdPathString,
|
hdPathSTring: this.hdPathString,
|
||||||
|
this.configManager,
|
||||||
})
|
})
|
||||||
|
|
||||||
cb()
|
cb()
|
||||||
@ -432,6 +447,7 @@ IdentityStore.prototype._createIdmgmt = function (password, seed, entropy, cb) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
IdentityStore.prototype._restoreFromSeed = function (password, seed, derivedKey) {
|
IdentityStore.prototype._restoreFromSeed = function (password, seed, derivedKey) {
|
||||||
|
const configManager = this.configManager
|
||||||
var keyStore = new LightwalletKeyStore(seed, derivedKey, this.hdPathString)
|
var keyStore = new LightwalletKeyStore(seed, derivedKey, this.hdPathString)
|
||||||
keyStore.addHdDerivationPath(this.hdPathString, derivedKey, {curve: 'secp256k1', purpose: 'sign'})
|
keyStore.addHdDerivationPath(this.hdPathString, derivedKey, {curve: 'secp256k1', purpose: 'sign'})
|
||||||
keyStore.setDefaultHdDerivationPath(this.hdPathString)
|
keyStore.setDefaultHdDerivationPath(this.hdPathString)
|
||||||
@ -443,6 +459,7 @@ IdentityStore.prototype._restoreFromSeed = function (password, seed, derivedKey)
|
|||||||
}
|
}
|
||||||
|
|
||||||
IdentityStore.prototype._createFirstWallet = function (entropy, derivedKey) {
|
IdentityStore.prototype._createFirstWallet = function (entropy, derivedKey) {
|
||||||
|
const configManager = this.configManager
|
||||||
var secretSeed = LightwalletKeyStore.generateRandomSeed(entropy)
|
var secretSeed = LightwalletKeyStore.generateRandomSeed(entropy)
|
||||||
var keyStore = new LightwalletKeyStore(secretSeed, derivedKey, this.hdPathString)
|
var keyStore = new LightwalletKeyStore(secretSeed, derivedKey, this.hdPathString)
|
||||||
keyStore.addHdDerivationPath(this.hdPathString, derivedKey, {curve: 'secp256k1', purpose: 'sign'})
|
keyStore.addHdDerivationPath(this.hdPathString, derivedKey, {curve: 'secp256k1', purpose: 'sign'})
|
||||||
|
Loading…
Reference in New Issue
Block a user