aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2016-10-29 17:29:25 +0800
committerDan Finlay <dan@danfinlay.com>2016-10-29 17:29:25 +0800
commit18e5173f061c2e21b5acb3e1b329343b5cffc558 (patch)
tree5da23547c31351ee4da5288c7c958804f6cc30e2 /app
parent331d9c91ee42f766fe56e2ebef1d1ad283d6c438 (diff)
downloadtangerine-wallet-browser-18e5173f061c2e21b5acb3e1b329343b5cffc558.tar
tangerine-wallet-browser-18e5173f061c2e21b5acb3e1b329343b5cffc558.tar.gz
tangerine-wallet-browser-18e5173f061c2e21b5acb3e1b329343b5cffc558.tar.bz2
tangerine-wallet-browser-18e5173f061c2e21b5acb3e1b329343b5cffc558.tar.lz
tangerine-wallet-browser-18e5173f061c2e21b5acb3e1b329343b5cffc558.tar.xz
tangerine-wallet-browser-18e5173f061c2e21b5acb3e1b329343b5cffc558.tar.zst
tangerine-wallet-browser-18e5173f061c2e21b5acb3e1b329343b5cffc558.zip
Now migrating old vaults to new DEN format
Diffstat (limited to 'app')
-rw-r--r--app/scripts/keyring-controller.js33
-rw-r--r--app/scripts/lib/idStore-migrator.js48
-rw-r--r--app/scripts/lib/idStore.js4
3 files changed, 79 insertions, 6 deletions
diff --git a/app/scripts/keyring-controller.js b/app/scripts/keyring-controller.js
index 3ac101ad8..b8066e303 100644
--- a/app/scripts/keyring-controller.js
+++ b/app/scripts/keyring-controller.js
@@ -9,6 +9,9 @@ const BN = ethUtil.BN
const Transaction = require('ethereumjs-tx')
const createId = require('web3-provider-engine/util/random-id')
+// TEMPORARY UNTIL FULL DEPRECATION:
+const IdStoreMigrator = require('./lib/idStore-migrator')
+
// Keyrings:
const SimpleKeyring = require('./keyrings/simple')
const HdKeyring = require('./keyrings/hd')
@@ -34,6 +37,11 @@ module.exports = class KeyringController extends EventEmitter {
this._unconfMsgCbs = {}
this.network = null
+
+ // TEMPORARY UNTIL FULL DEPRECATION:
+ this.idStoreMigrator = new IdStoreMigrator({
+ configManager: this.configManager,
+ })
}
getState() {
@@ -63,18 +71,32 @@ module.exports = class KeyringController extends EventEmitter {
createNewVault(password, entropy, cb) {
const salt = this.encryptor.generateSalt()
this.configManager.setSalt(salt)
- this.loadKey(password)
+
+ let serialized
+
+ this.idStoreMigrator.oldSeedForPassword(password)
+ .then((oldSerialized) => {
+ if (oldSerialized) {
+ serialized = oldSerialized
+ }
+ return this.loadKey(password)
+ })
.then((key) => {
- return this.encryptor.encryptWithKey(key, [])
+ const first = serialized ? [serialized] : []
+ return this.encryptor.encryptWithKey(key, first)
})
.then((encryptedString) => {
this.configManager.setVault(encryptedString)
- // TEMPORARY SINGLE-KEYRING CONFIG:
- this.addNewKeyring('HD Key Tree', null, cb)
+ if (!serialized) {
+ // TEMPORARY SINGLE-KEYRING CONFIG:
+ return this.addNewKeyring('HD Key Tree', null, cb)
+ } else {
+ return this.submitPassword(password, cb)
+ }
// NORMAL BEHAVIOR:
- // cb(null, this.getState())
+ // return cb(null, this.getState())
})
.catch((err) => {
cb(err)
@@ -99,6 +121,7 @@ module.exports = class KeyringController extends EventEmitter {
return this.encryptor.keyFromPassword(password + salt)
.then((key) => {
this.key = key
+ this.configManager.setSalt(salt)
return key
})
}
diff --git a/app/scripts/lib/idStore-migrator.js b/app/scripts/lib/idStore-migrator.js
new file mode 100644
index 000000000..f8f7cb51a
--- /dev/null
+++ b/app/scripts/lib/idStore-migrator.js
@@ -0,0 +1,48 @@
+const IdentityStore = require('./idStore')
+
+
+module.exports = class IdentityStoreMigrator {
+
+ constructor ({ configManager }) {
+ this.configManager = configManager
+ this.idStore = new IdentityStore({ configManager })
+ }
+
+ oldSeedForPassword( password ) {
+ const isOldVault = this.hasOldVault()
+ if (!isOldVault) {
+ console.log('does not seem to have old vault')
+ console.log('THE DATA:')
+ console.log(this.configManager.getData())
+ 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)
+ }
+ })
+ })
+ }
+
+ serializeVault() {
+ const mnemonic = this.idStore._idmgmt.getSeed()
+ console.dir(this.idStore._idmgmt)
+ const n = this.idStore._getAddresses().length
+
+ return {
+ type: 'HD Key Tree',
+ data: { mnemonic, n },
+ }
+ }
+
+ hasOldVault() {
+ const wallet = this.configManager.getWallet()
+ console.log('found old wallet: ' + wallet)
+ return wallet
+ }
+}
diff --git a/app/scripts/lib/idStore.js b/app/scripts/lib/idStore.js
index 14f25dd1d..8ee2b62dd 100644
--- a/app/scripts/lib/idStore.js
+++ b/app/scripts/lib/idStore.js
@@ -422,7 +422,9 @@ IdentityStore.prototype._loadIdentities = function () {
var addresses = this._getAddresses()
addresses.forEach((address, i) => {
// // add to ethStore
- this._ethStore.addAccount(ethUtil.addHexPrefix(address))
+ if (this._ethStore) {
+ this._ethStore.addAccount(ethUtil.addHexPrefix(address))
+ }
// add to identities
const defaultLabel = 'Wallet ' + (i + 1)
const nickname = configManager.nicknameForWallet(address)