aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorFrankie <frankie.diamond@gmail.com>2016-12-24 04:48:36 +0800
committerFrankie <frankie.diamond@gmail.com>2016-12-24 04:48:36 +0800
commitfa3e708f34fce523601c39b3131bdbe858d2f85f (patch)
tree9cb3b8fb5622aa23d4856e21405f8939505d3271 /app
parentfde69ea0baf32b5d2a6932b73f4772e983aef552 (diff)
parent2ab34760b0e2e006c0b87722e8397c642eb86981 (diff)
downloadtangerine-wallet-browser-fa3e708f34fce523601c39b3131bdbe858d2f85f.tar
tangerine-wallet-browser-fa3e708f34fce523601c39b3131bdbe858d2f85f.tar.gz
tangerine-wallet-browser-fa3e708f34fce523601c39b3131bdbe858d2f85f.tar.bz2
tangerine-wallet-browser-fa3e708f34fce523601c39b3131bdbe858d2f85f.tar.lz
tangerine-wallet-browser-fa3e708f34fce523601c39b3131bdbe858d2f85f.tar.xz
tangerine-wallet-browser-fa3e708f34fce523601c39b3131bdbe858d2f85f.tar.zst
tangerine-wallet-browser-fa3e708f34fce523601c39b3131bdbe858d2f85f.zip
Merge branch 'dev' into TxManager
Diffstat (limited to 'app')
-rw-r--r--app/scripts/keyring-controller.js51
-rw-r--r--app/scripts/lib/config-manager.js2
-rw-r--r--app/scripts/lib/idStore-migrator.js7
-rw-r--r--app/scripts/lib/idStore.js3
-rw-r--r--app/scripts/lib/inpage-provider.js4
-rw-r--r--app/scripts/metamask-controller.js80
6 files changed, 94 insertions, 53 deletions
diff --git a/app/scripts/keyring-controller.js b/app/scripts/keyring-controller.js
index 6623419df..016740d88 100644
--- a/app/scripts/keyring-controller.js
+++ b/app/scripts/keyring-controller.js
@@ -6,7 +6,6 @@ const encryptor = require('browser-passworder')
const normalize = require('./lib/sig-util').normalize
const messageManager = require('./lib/message-manager')
-const IdStoreMigrator = require('./lib/idStore-migrator')
const BN = ethUtil.BN
// Keyrings:
@@ -40,11 +39,6 @@ module.exports = class KeyringController extends EventEmitter {
this._unconfMsgCbs = {}
this.getNetwork = opts.getNetwork
-
- // TEMPORARY UNTIL FULL DEPRECATION:
- this.idStoreMigrator = new IdStoreMigrator({
- configManager: this.configManager,
- })
}
// Set Store
@@ -107,7 +101,6 @@ module.exports = class KeyringController extends EventEmitter {
conversionDate: this.configManager.getConversionDate(),
keyringTypes: this.keyringTypes.map(krt => krt.type),
identities: this.identities,
- lostAccounts: this.configManager.getLostAccounts(),
}
}
@@ -215,10 +208,7 @@ module.exports = class KeyringController extends EventEmitter {
// Temporarily also migrates any old-style vaults first, as well.
// (Pre MetaMask 3.0.0)
submitPassword (password) {
- return this.migrateOldVaultIfAny(password)
- .then(() => {
- return this.unlockKeyrings(password)
- })
+ return this.unlockKeyrings(password)
.then((keyrings) => {
this.keyrings = keyrings
return this.fullUpdate()
@@ -420,41 +410,6 @@ module.exports = class KeyringController extends EventEmitter {
// THESE METHODS ARE ONLY USED INTERNALLY TO THE KEYRING-CONTROLLER
// AND SO MAY BE CHANGED MORE LIBERALLY THAN THE ABOVE METHODS.
- // Migrate Old Vault If Any
- // @string password
- //
- // returns Promise()
- //
- // Temporary step used when logging in.
- // Checks if old style (pre-3.0.0) Metamask Vault exists.
- // If so, persists that vault in the new vault format
- // with the provided password, so the other unlock steps
- // may be completed without interruption.
- migrateOldVaultIfAny (password) {
- const shouldMigrate = !!this.configManager.getWallet() && !this.configManager.getVault()
- if (!shouldMigrate) {
- return Promise.resolve()
- }
-
- return this.idStoreMigrator.migratedVaultForPassword(password)
- .then((result) => {
- this.password = password
-
- if (result && shouldMigrate) {
- const { serialized, lostAccounts } = result
- this.configManager.setLostAccounts(lostAccounts)
- return this.restoreKeyring(serialized)
- .then(keyring => keyring.getAccounts())
- .then((accounts) => {
- this.configManager.setSelectedAccount(accounts[0])
- return this.persistAllKeyrings()
- })
- } else {
- return Promise.resolve()
- }
- })
- }
-
// Create First Key Tree
// returns @Promise
//
@@ -575,6 +530,10 @@ module.exports = class KeyringController extends EventEmitter {
// initializing the persisted keyrings to RAM.
unlockKeyrings (password) {
const encryptedVault = this.configManager.getVault()
+ if (!encryptedVault) {
+ throw new Error('Cannot unlock without a previous vault.')
+ }
+
return this.encryptor.decrypt(password, encryptedVault)
.then((vault) => {
this.password = password
diff --git a/app/scripts/lib/config-manager.js b/app/scripts/lib/config-manager.js
index c723655fa..93501c859 100644
--- a/app/scripts/lib/config-manager.js
+++ b/app/scripts/lib/config-manager.js
@@ -118,7 +118,7 @@ ConfigManager.prototype.setVault = function (encryptedString) {
ConfigManager.prototype.getVault = function () {
var data = this.getData()
- return ('vault' in data) && data.vault
+ return data.vault
}
ConfigManager.prototype.getKeychains = function () {
diff --git a/app/scripts/lib/idStore-migrator.js b/app/scripts/lib/idStore-migrator.js
index 2e9418376..655aed0af 100644
--- a/app/scripts/lib/idStore-migrator.js
+++ b/app/scripts/lib/idStore-migrator.js
@@ -63,7 +63,12 @@ module.exports = class IdentityStoreMigrator {
return {
serialized,
- lostAccounts,
+ lostAccounts: lostAccounts.map((address) => {
+ return {
+ address,
+ privateKey: this.idStore.exportAccount(address),
+ }
+ }),
}
})
}
diff --git a/app/scripts/lib/idStore.js b/app/scripts/lib/idStore.js
index 5c0f8d7f7..e4cbca456 100644
--- a/app/scripts/lib/idStore.js
+++ b/app/scripts/lib/idStore.js
@@ -190,7 +190,8 @@ IdentityStore.prototype.submitPassword = function (password, cb) {
IdentityStore.prototype.exportAccount = function (address, cb) {
var privateKey = this._idmgmt.exportPrivateKey(address)
- cb(null, privateKey)
+ if (cb) cb(null, privateKey)
+ return privateKey
}
// private
diff --git a/app/scripts/lib/inpage-provider.js b/app/scripts/lib/inpage-provider.js
index 30fcbcb66..a64c745ce 100644
--- a/app/scripts/lib/inpage-provider.js
+++ b/app/scripts/lib/inpage-provider.js
@@ -72,13 +72,13 @@ MetamaskInpageProvider.prototype.send = function (payload) {
case 'eth_accounts':
// read from localStorage
- selectedAccount = self.publicConfigStore.get('selectedAddress')
+ selectedAccount = self.publicConfigStore.get('selectedAccount')
result = selectedAccount ? [selectedAccount] : []
break
case 'eth_coinbase':
// read from localStorage
- selectedAccount = self.publicConfigStore.get('selectedAddress')
+ selectedAccount = self.publicConfigStore.get('selectedAccount')
result = selectedAccount || '0x0000000000000000000000000000000000000000'
break
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index 4af5cd78d..5df10672a 100644
--- a/app/scripts/metamask-controller.js
+++ b/app/scripts/metamask-controller.js
@@ -11,6 +11,7 @@ const ConfigManager = require('./lib/config-manager')
const extension = require('./lib/extension')
const autoFaucet = require('./lib/auto-faucet')
const nodeify = require('./lib/nodeify')
+const IdStoreMigrator = require('./lib/idStore-migrator')
module.exports = class MetamaskController {
@@ -54,6 +55,11 @@ module.exports = class MetamaskController {
this.checkTOSChange()
this.scheduleConversionInterval()
+
+ // TEMPORARY UNTIL FULL DEPRECATION:
+ this.idStoreMigrator = new IdStoreMigrator({
+ configManager: this.configManager,
+ })
}
getState () {
@@ -63,7 +69,9 @@ module.exports = class MetamaskController {
this.configManager.getConfig(),
this.keyringController.getState(),
this.txManager.getState(),
- this.noticeController.getState()
+ this.noticeController.getState(), {
+ lostAccounts: this.configManager.getLostAccounts(),
+ }
)
}
@@ -83,6 +91,7 @@ module.exports = class MetamaskController {
setTOSHash: this.setTOSHash.bind(this),
checkTOSChange: this.checkTOSChange.bind(this),
setGasMultiplier: this.setGasMultiplier.bind(this),
+ markAccountsFound: this.markAccountsFound.bind(this),
// forward directly to keyringController
createNewVaultAndKeychain: nodeify(keyringController.createNewVaultAndKeychain).bind(keyringController),
@@ -90,7 +99,12 @@ module.exports = class MetamaskController {
placeSeedWords: nodeify(keyringController.placeSeedWords).bind(keyringController),
clearSeedWordCache: nodeify(keyringController.clearSeedWordCache).bind(keyringController),
setLocked: nodeify(keyringController.setLocked).bind(keyringController),
- submitPassword: nodeify(keyringController.submitPassword).bind(keyringController),
+ submitPassword: (password, cb) => {
+ this.migrateOldVaultIfAny(password)
+ .then(keyringController.submitPassword.bind(keyringController))
+ .then((newState) => { cb(null, newState) })
+ .catch((reason) => { cb(reason) })
+ },
addNewKeyring: nodeify(keyringController.addNewKeyring).bind(keyringController),
addNewAccount: nodeify(keyringController.addNewAccount).bind(keyringController),
setSelectedAccount: nodeify(keyringController.setSelectedAccount).bind(keyringController),
@@ -429,4 +443,66 @@ module.exports = class MetamaskController {
getStateNetwork () {
return this.state.network
}
+
+ markAccountsFound(cb) {
+ this.configManager.setLostAccounts([])
+ this.sendUpdate()
+ cb(null, this.getState())
+ }
+
+ // Migrate Old Vault If Any
+ // @string password
+ //
+ // returns Promise()
+ //
+ // Temporary step used when logging in.
+ // Checks if old style (pre-3.0.0) Metamask Vault exists.
+ // If so, persists that vault in the new vault format
+ // with the provided password, so the other unlock steps
+ // may be completed without interruption.
+ migrateOldVaultIfAny (password) {
+
+ if (!this.checkIfShouldMigrate()) {
+ return Promise.resolve(password)
+ }
+
+ const keyringController = this.keyringController
+
+ return this.idStoreMigrator.migratedVaultForPassword(password)
+ .then(this.restoreOldVaultAccounts.bind(this))
+ .then(this.restoreOldLostAccounts.bind(this))
+ .then(keyringController.persistAllKeyrings.bind(keyringController))
+ .then(() => password)
+ }
+
+ checkIfShouldMigrate() {
+ return !!this.configManager.getWallet() && !this.configManager.getVault()
+ }
+
+ restoreOldVaultAccounts(migratorOutput) {
+ const { serialized } = migratorOutput
+ return this.keyringController.restoreKeyring(serialized)
+ .then(() => migratorOutput)
+ }
+
+ restoreOldLostAccounts(migratorOutput) {
+ const { lostAccounts } = migratorOutput
+ if (lostAccounts) {
+ this.configManager.setLostAccounts(lostAccounts.map(acct => acct.address))
+ return this.importLostAccounts(migratorOutput)
+ }
+ return Promise.resolve(migratorOutput)
+ }
+
+ // IMPORT LOST ACCOUNTS
+ // @Object with key lostAccounts: @Array accounts <{ address, privateKey }>
+ // Uses the array's private keys to create a new Simple Key Pair keychain
+ // and add it to the keyring controller.
+ importLostAccounts ({ lostAccounts }) {
+ const privKeys = lostAccounts.map(acct => acct.privateKey)
+ return this.keyringController.restoreKeyring({
+ type: 'Simple Key Pair',
+ data: privKeys,
+ })
+ }
}