aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib
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/lib
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/lib')
-rw-r--r--app/scripts/lib/config-manager.js11
-rw-r--r--app/scripts/lib/idStore-migrator.js43
2 files changed, 44 insertions, 10 deletions
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