aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/metamask-controller.js
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2016-12-22 03:01:04 +0800
committerDan Finlay <dan@danfinlay.com>2016-12-22 03:02:04 +0800
commit48f2ae2154b6e804ee60cfc1235025c128a6cfa8 (patch)
tree29f1f553e758d8499156fc02ef7da813427c97bb /app/scripts/metamask-controller.js
parentb3533f9bf7bc28988d2f2f280ab6ebc04cf66161 (diff)
downloadtangerine-wallet-browser-48f2ae2154b6e804ee60cfc1235025c128a6cfa8.tar
tangerine-wallet-browser-48f2ae2154b6e804ee60cfc1235025c128a6cfa8.tar.gz
tangerine-wallet-browser-48f2ae2154b6e804ee60cfc1235025c128a6cfa8.tar.bz2
tangerine-wallet-browser-48f2ae2154b6e804ee60cfc1235025c128a6cfa8.tar.lz
tangerine-wallet-browser-48f2ae2154b6e804ee60cfc1235025c128a6cfa8.tar.xz
tangerine-wallet-browser-48f2ae2154b6e804ee60cfc1235025c128a6cfa8.tar.zst
tangerine-wallet-browser-48f2ae2154b6e804ee60cfc1235025c128a6cfa8.zip
Move old keystore migration code to metamask controller
Allows keyring controller to be more generic, less opinionated, and who knows, maybe sooner publishable as its own thing.
Diffstat (limited to 'app/scripts/metamask-controller.js')
-rw-r--r--app/scripts/metamask-controller.js50
1 files changed, 49 insertions, 1 deletions
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index edb25d300..0c772536d 100644
--- a/app/scripts/metamask-controller.js
+++ b/app/scripts/metamask-controller.js
@@ -10,6 +10,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 {
@@ -44,6 +45,11 @@ module.exports = class MetamaskController {
this.checkTOSChange()
this.scheduleConversionInterval()
+
+ // TEMPORARY UNTIL FULL DEPRECATION:
+ this.idStoreMigrator = new IdStoreMigrator({
+ configManager: this.configManager,
+ })
}
getState () {
@@ -61,6 +67,7 @@ module.exports = class MetamaskController {
getApi () {
const keyringController = this.keyringController
const noticeController = this.noticeController
+ const submitPassword = keyringController.submitPassword.bind(keyringController)
return {
getState: (cb) => { cb(null, this.getState()) },
@@ -81,7 +88,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()
+ .then(submitPassword)
+ .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),
@@ -425,4 +437,40 @@ module.exports = class MetamaskController {
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) {
+ const shouldMigrate = !!this.configManager.getWallet() && !this.configManager.getVault()
+ if (!shouldMigrate) {
+ return Promise.resolve(password)
+ }
+
+ return this.idStoreMigrator.migratedVaultForPassword(password)
+ .then((result) => {
+ if (result && shouldMigrate) {
+ const { serialized, lostAccounts } = result
+ this.configManager.setLostAccounts(lostAccounts)
+ return this.keyringController.restoreKeyring(serialized)
+ .then(keyring => keyring.getAccounts())
+ .then((accounts) => {
+ this.configManager.setSelectedAccount(accounts[0])
+ return this.keyringController.persistAllKeyrings()
+ .then(() => password)
+ })
+ } else {
+ return Promise.resolve(password)
+ }
+ })
+ }
+
+
}