aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/migrations/_multi-keyring.js
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2017-02-16 08:09:16 +0800
committerDan Finlay <dan@danfinlay.com>2017-02-16 08:09:16 +0800
commit6d103dc1e7eeb9a1f55e4387fcc1fe194c7eb4cf (patch)
tree47906b974dee789ffd544b4c85da67e6f2323016 /app/scripts/migrations/_multi-keyring.js
parent245e779f37763ce0633119c257877706d0bf3554 (diff)
parent943bcec0d702b2c70b323000ed25d3c425e2a44f (diff)
downloadtangerine-wallet-browser-6d103dc1e7eeb9a1f55e4387fcc1fe194c7eb4cf.tar
tangerine-wallet-browser-6d103dc1e7eeb9a1f55e4387fcc1fe194c7eb4cf.tar.gz
tangerine-wallet-browser-6d103dc1e7eeb9a1f55e4387fcc1fe194c7eb4cf.tar.bz2
tangerine-wallet-browser-6d103dc1e7eeb9a1f55e4387fcc1fe194c7eb4cf.tar.lz
tangerine-wallet-browser-6d103dc1e7eeb9a1f55e4387fcc1fe194c7eb4cf.tar.xz
tangerine-wallet-browser-6d103dc1e7eeb9a1f55e4387fcc1fe194c7eb4cf.tar.zst
tangerine-wallet-browser-6d103dc1e7eeb9a1f55e4387fcc1fe194c7eb4cf.zip
Merge branch 'kumavis-patch-1' of github.com:MetaMask/metamask-plugin into kumavis-patch-1
Diffstat (limited to 'app/scripts/migrations/_multi-keyring.js')
-rw-r--r--app/scripts/migrations/_multi-keyring.js51
1 files changed, 51 insertions, 0 deletions
diff --git a/app/scripts/migrations/_multi-keyring.js b/app/scripts/migrations/_multi-keyring.js
new file mode 100644
index 000000000..04c966d4d
--- /dev/null
+++ b/app/scripts/migrations/_multi-keyring.js
@@ -0,0 +1,51 @@
+const version = 5
+
+/*
+
+This is an incomplete migration bc it requires post-decrypted data
+which we dont have access to at the time of this writing.
+
+*/
+
+const ObservableStore = require('obs-store')
+const ConfigManager = require('../../app/scripts/lib/config-manager')
+const IdentityStoreMigrator = require('../../app/scripts/lib/idStore-migrator')
+const KeyringController = require('../../app/scripts/lib/keyring-controller')
+
+const password = 'obviously not correct'
+
+module.exports = {
+ version,
+
+ migrate: function (versionedData) {
+ versionedData.meta.version = version
+
+ let store = new ObservableStore(versionedData.data)
+ let configManager = new ConfigManager({ store })
+ let idStoreMigrator = new IdentityStoreMigrator({ configManager })
+ let keyringController = new KeyringController({
+ configManager: configManager,
+ })
+
+ // attempt to migrate to multiVault
+ return idStoreMigrator.migratedVaultForPassword(password)
+ .then((result) => {
+ // skip if nothing to migrate
+ if (!result) return Promise.resolve(versionedData)
+ delete versionedData.data.wallet
+ // create new keyrings
+ const privKeys = result.lostAccounts.map(acct => acct.privateKey)
+ return Promise.all([
+ keyringController.restoreKeyring(result.serialized),
+ keyringController.restoreKeyring({ type: 'Simple Key Pair', data: privKeys }),
+ ]).then(() => {
+ return keyringController.persistAllKeyrings(password)
+ }).then(() => {
+ // copy result on to state object
+ versionedData.data = store.get()
+ return Promise.resolve(versionedData)
+ })
+ })
+
+ },
+}