aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib/idStore-migrator.js
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2016-12-09 06:22:02 +0800
committerDan Finlay <dan@danfinlay.com>2016-12-09 06:22:02 +0800
commitab9e15b782620002c0a2477829db3e56a25a7d5c (patch)
treef35f27db6ecd1dc04649a4d9c13625580e4b98e5 /app/scripts/lib/idStore-migrator.js
parent9e3fa3cfba20299413df87d18158180c7798d2ac (diff)
downloadtangerine-wallet-browser-ab9e15b782620002c0a2477829db3e56a25a7d5c.tar
tangerine-wallet-browser-ab9e15b782620002c0a2477829db3e56a25a7d5c.tar.gz
tangerine-wallet-browser-ab9e15b782620002c0a2477829db3e56a25a7d5c.tar.bz2
tangerine-wallet-browser-ab9e15b782620002c0a2477829db3e56a25a7d5c.tar.lz
tangerine-wallet-browser-ab9e15b782620002c0a2477829db3e56a25a7d5c.tar.xz
tangerine-wallet-browser-ab9e15b782620002c0a2477829db3e56a25a7d5c.tar.zst
tangerine-wallet-browser-ab9e15b782620002c0a2477829db3e56a25a7d5c.zip
Mostly added bad account detection
Currently riddled with logs, because the migrator is inexplicably returning before generating the new style accounts for comparison.
Diffstat (limited to 'app/scripts/lib/idStore-migrator.js')
-rw-r--r--app/scripts/lib/idStore-migrator.js55
1 files changed, 49 insertions, 6 deletions
diff --git a/app/scripts/lib/idStore-migrator.js b/app/scripts/lib/idStore-migrator.js
index 40b08efee..c13015b96 100644
--- a/app/scripts/lib/idStore-migrator.js
+++ b/app/scripts/lib/idStore-migrator.js
@@ -1,5 +1,7 @@
const IdentityStore = require('./idStore')
-
+const HdKeyring = require('../keyrings/hd')
+const sigUtil = require('./sig-util')
+const normalize = sigUtil.normalize
module.exports = class IdentityStoreMigrator {
@@ -12,25 +14,34 @@ module.exports = class IdentityStoreMigrator {
}
migratedVaultForPassword (password) {
+ console.log('migrating vault for password')
const hasOldVault = this.hasOldVault()
const configManager = this.configManager
if (!this.idStore) {
+ console.log('initializing id store')
this.idStore = new IdentityStore({ configManager })
+ console.log('initialized')
}
if (!hasOldVault) {
+ console.log('no old vault recognized')
return Promise.resolve(null)
}
+ console.log('returning new promise')
return new Promise((resolve, reject) => {
+ console.log('submitting password to idStore')
this.idStore.submitPassword(password, (err) => {
+ console.log('returned ' + err)
if (err) return reject(err)
- try {
- resolve(this.serializeVault())
- } catch (e) {
- reject(e)
- }
+ console.log('serializing vault')
+ const serialized = this.serializeVault()
+ console.log('migrated and serialized into')
+ console.dir(serialized)
+ this.checkForErrors(serialized)
+ .then(resolve)
+ .catch(reject)
})
})
}
@@ -45,6 +56,38 @@ module.exports = class IdentityStoreMigrator {
}
}
+ checkForErrors (serialized) {
+ console.log('checking for errors, first making hd wallet')
+ const hd = new HdKeyring()
+ return hd.deserialize(serialized)
+ .then(() => {
+ console.log('deserialized, now getting accounts')
+ console.dir(arguments)
+ return hd.getAccounts()
+ })
+ .then((hexAccounts) => {
+ console.log('hd returned accounts', 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
+ }
+ }, [])
+
+ console.log('migrator has')
+ console.dir({ newAccounts, oldAccounts, lostAccounts, hexAccounts })
+
+ return {
+ serialized,
+ lostAccounts,
+ }
+ })
+ }
+
hasOldVault () {
const wallet = this.configManager.getWallet()
return wallet