1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-23 03:36:18 +02:00
metamask-extension/app/scripts/lib/idStore-migrator.js

53 lines
1.1 KiB
JavaScript
Raw Normal View History

const IdentityStore = require('./idStore')
module.exports = class IdentityStoreMigrator {
constructor ({ configManager }) {
this.configManager = configManager
const hasOldVault = this.hasOldVault()
if (!hasOldVault) {
this.idStore = new IdentityStore({ configManager })
}
}
2016-11-11 19:26:12 +01:00
oldSeedForPassword (password) {
const hasOldVault = this.hasOldVault()
const configManager = this.configManager
if (!this.idStore) {
this.idStore = new IdentityStore({ configManager })
}
if (!hasOldVault) {
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)
}
})
})
}
2016-11-11 19:26:12 +01:00
serializeVault () {
const mnemonic = this.idStore._idmgmt.getSeed()
const n = this.idStore._getAddresses().length
return {
type: 'HD Key Tree',
data: { mnemonic, n },
}
}
2016-11-11 19:26:12 +01:00
hasOldVault () {
const wallet = this.configManager.getWallet()
return wallet
}
}