aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts
diff options
context:
space:
mode:
authorDan Finlay <somniac@me.com>2016-12-21 03:50:26 +0800
committerGitHub <noreply@github.com>2016-12-21 03:50:26 +0800
commit674b2689826c770092a3dfee7fe76fb83c0b444a (patch)
tree96dd32380a338c361131aae49a8f664308a591f0 /app/scripts
parent4fbea1c7b4e3ca13b76aa49c7a349a3dc2366910 (diff)
parent20d2204ce6a9e8dcd3269c588b2f4ce6ff93408b (diff)
downloadtangerine-wallet-browser-674b2689826c770092a3dfee7fe76fb83c0b444a.tar
tangerine-wallet-browser-674b2689826c770092a3dfee7fe76fb83c0b444a.tar.gz
tangerine-wallet-browser-674b2689826c770092a3dfee7fe76fb83c0b444a.tar.bz2
tangerine-wallet-browser-674b2689826c770092a3dfee7fe76fb83c0b444a.tar.lz
tangerine-wallet-browser-674b2689826c770092a3dfee7fe76fb83c0b444a.tar.xz
tangerine-wallet-browser-674b2689826c770092a3dfee7fe76fb83c0b444a.tar.zst
tangerine-wallet-browser-674b2689826c770092a3dfee7fe76fb83c0b444a.zip
Merge pull request #916 from MetaMask/i894-DetectBadAccounts
I894 detect bad accounts
Diffstat (limited to 'app/scripts')
-rw-r--r--app/scripts/keyring-controller.js11
-rw-r--r--app/scripts/keyrings/hd.js8
-rw-r--r--app/scripts/lib/config-manager.js11
-rw-r--r--app/scripts/lib/idStore-migrator.js43
4 files changed, 57 insertions, 16 deletions
diff --git a/app/scripts/keyring-controller.js b/app/scripts/keyring-controller.js
index 58366c26f..2888e58a9 100644
--- a/app/scripts/keyring-controller.js
+++ b/app/scripts/keyring-controller.js
@@ -114,6 +114,7 @@ module.exports = class KeyringController extends EventEmitter {
conversionDate: this.configManager.getConversionDate(),
keyringTypes: this.keyringTypes.map(krt => krt.type),
identities: this.identities,
+ lostAccounts: this.configManager.getLostAccounts(),
}
}
@@ -622,11 +623,17 @@ module.exports = class KeyringController extends EventEmitter {
// 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((serialized) => {
+ .then((result) => {
this.password = password
- if (serialized && shouldMigrate) {
+ if (result && shouldMigrate) {
+ const { serialized, lostAccounts } = result
+ this.configManager.setLostAccounts(lostAccounts)
return this.restoreKeyring(serialized)
.then(keyring => keyring.getAccounts())
.then((accounts) => {
diff --git a/app/scripts/keyrings/hd.js b/app/scripts/keyrings/hd.js
index cfec56561..80b713b58 100644
--- a/app/scripts/keyrings/hd.js
+++ b/app/scripts/keyrings/hd.js
@@ -33,15 +33,15 @@ class HdKeyring extends EventEmitter {
this.mnemonic = null
this.root = null
- if ('mnemonic' in opts) {
+ if (opts.mnemonic) {
this._initFromMnemonic(opts.mnemonic)
}
- if ('numberOfAccounts' in opts) {
- this.addAccounts(opts.numberOfAccounts)
+ if (opts.numberOfAccounts) {
+ return this.addAccounts(opts.numberOfAccounts)
}
- return Promise.resolve()
+ return Promise.resolve([])
}
addAccounts (numberOfAccounts = 1) {
diff --git a/app/scripts/lib/config-manager.js b/app/scripts/lib/config-manager.js
index 59cc2b63c..d36ccf0db 100644
--- a/app/scripts/lib/config-manager.js
+++ b/app/scripts/lib/config-manager.js
@@ -432,3 +432,14 @@ ConfigManager.prototype.setGasMultiplier = function (gasMultiplier) {
data.gasMultiplier = gasMultiplier
this.setData(data)
}
+
+ConfigManager.prototype.setLostAccounts = function (lostAccounts) {
+ var data = this.getData()
+ data.lostAccounts = lostAccounts
+ this.setData(data)
+}
+
+ConfigManager.prototype.getLostAccounts = function () {
+ var data = this.getData()
+ return data.lostAccounts || []
+}
diff --git a/app/scripts/lib/idStore-migrator.js b/app/scripts/lib/idStore-migrator.js
index 40b08efee..2e9418376 100644
--- a/app/scripts/lib/idStore-migrator.js
+++ b/app/scripts/lib/idStore-migrator.js
@@ -1,5 +1,8 @@
const IdentityStore = require('./idStore')
-
+const HdKeyring = require('../keyrings/hd')
+const sigUtil = require('./sig-util')
+const normalize = sigUtil.normalize
+const denodeify = require('denodeify')
module.exports = class IdentityStoreMigrator {
@@ -23,15 +26,13 @@ module.exports = class IdentityStoreMigrator {
return Promise.resolve(null)
}
- return new Promise((resolve, reject) => {
- this.idStore.submitPassword(password, (err) => {
- if (err) return reject(err)
- try {
- resolve(this.serializeVault())
- } catch (e) {
- reject(e)
- }
- })
+ const idStore = this.idStore
+ const submitPassword = denodeify(idStore.submitPassword.bind(idStore))
+
+ return submitPassword(password)
+ .then(() => {
+ const serialized = this.serializeVault()
+ return this.checkForLostAccounts(serialized)
})
}
@@ -45,6 +46,28 @@ module.exports = class IdentityStoreMigrator {
}
}
+ checkForLostAccounts (serialized) {
+ const hd = new HdKeyring()
+ return hd.deserialize(serialized.data)
+ .then((hexAccounts) => {
+ const newAccounts = hexAccounts.map(normalize)
+ const oldAccounts = this.idStore._getAddresses().map(normalize)
+ const lostAccounts = oldAccounts.reduce((result, account) => {
+ if (newAccounts.includes(account)) {
+ return result
+ } else {
+ result.push(account)
+ return result
+ }
+ }, [])
+
+ return {
+ serialized,
+ lostAccounts,
+ }
+ })
+ }
+
hasOldVault () {
const wallet = this.configManager.getWallet()
return wallet