aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/metamask-controller.js
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2016-12-22 09:21:10 +0800
committerDan Finlay <dan@danfinlay.com>2016-12-22 09:21:10 +0800
commitebeaf3b3d6cf79e2e0f251b9b2da765f0fe6d0e1 (patch)
treed27efd999dc02b84d077847150e5815ac481d50a /app/scripts/metamask-controller.js
parenta3a64afdd5b2ed6bbed8c8dba5cc0f14d4a1ad99 (diff)
downloadtangerine-wallet-browser-ebeaf3b3d6cf79e2e0f251b9b2da765f0fe6d0e1.tar
tangerine-wallet-browser-ebeaf3b3d6cf79e2e0f251b9b2da765f0fe6d0e1.tar.gz
tangerine-wallet-browser-ebeaf3b3d6cf79e2e0f251b9b2da765f0fe6d0e1.tar.bz2
tangerine-wallet-browser-ebeaf3b3d6cf79e2e0f251b9b2da765f0fe6d0e1.tar.lz
tangerine-wallet-browser-ebeaf3b3d6cf79e2e0f251b9b2da765f0fe6d0e1.tar.xz
tangerine-wallet-browser-ebeaf3b3d6cf79e2e0f251b9b2da765f0fe6d0e1.tar.zst
tangerine-wallet-browser-ebeaf3b3d6cf79e2e0f251b9b2da765f0fe6d0e1.zip
Restructured migration
Migrator now returns a lostAccount array that includes objects these objects include keys of address and privateKey, this allows the MetamaskController to restore the lost accounts even without customizing the idStore or the KeyringController. Also includes a patch that allows idStore to synchronously export private keys.
Diffstat (limited to 'app/scripts/metamask-controller.js')
-rw-r--r--app/scripts/metamask-controller.js62
1 files changed, 43 insertions, 19 deletions
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index 0c772536d..493ee661a 100644
--- a/app/scripts/metamask-controller.js
+++ b/app/scripts/metamask-controller.js
@@ -67,7 +67,6 @@ 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()) },
@@ -89,10 +88,10 @@ module.exports = class MetamaskController {
clearSeedWordCache: nodeify(keyringController.clearSeedWordCache).bind(keyringController),
setLocked: nodeify(keyringController.setLocked).bind(keyringController),
submitPassword: (password, cb) => {
- this.migrateOldVaultIfAny()
- .then(submitPassword)
- .then((newState) => { cb(null, newState) })
- .catch((reason) => { cb(reason) })
+ this.migrateOldVaultIfAny(password)
+ .then(keyringController.submitPassword.bind(keyringController))
+ .then((newState) => { console.log('succeeded submitting!'); cb(null, newState) })
+ .catch((reason) => { console.error(reason); cb(reason) })
},
addNewKeyring: nodeify(keyringController.addNewKeyring).bind(keyringController),
addNewAccount: nodeify(keyringController.addNewAccount).bind(keyringController),
@@ -456,21 +455,46 @@ module.exports = class MetamaskController {
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)
+
+ this.keyringController.password = password
+ const { serialized, lostAccounts } = result
+
+ // Restore the correct accounts first:
+ return this.keyringController.restoreKeyring(serialized)
+ .then(keyring => keyring.getAccounts())
+ .then((accounts) => {
+ this.configManager.setSelectedAccount(accounts[0])
+ return result
+ })
+
+ }).then((result) => {
+
+ // Now we restore any lost accounts:
+ const { serialized, lostAccounts } = result
+ if (result && lostAccounts) {
+ this.configManager.setLostAccounts(lostAccounts.map((acct) => acct.address))
+ return this.importLostAccounts(result)
}
- })
- }
+ return Promise.resolve(result)
+ }).then(() => {
+
+ // Persist all these newly restored items to disk:
+ return this.keyringController.persistAllKeyrings()
+ // Ultimately pass the password back for normal unlocking:
+ }).then((result) => password)
+ }
+ // 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 (result) {
+ const { serialized, lostAccounts } = result
+ const privKeys = lostAccounts.map(acct => acct.privateKey)
+ return this.keyringController.restoreKeyring({
+ type: 'Simple Key Pair',
+ data: privKeys,
+ })
+ }
}