mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-24 02:58:09 +01:00
4cf1b606e4
Now old vaults are recognized as an "Initialized" MetaMask instance. Upon logging in, when fetching the initial password-derived key, if there is no new-style vault, but there is an old style vault, it is migrated to the new format before proceeding through the usual unlocking steps.
53 lines
1.1 KiB
JavaScript
53 lines
1.1 KiB
JavaScript
const IdentityStore = require('./idStore')
|
|
|
|
|
|
module.exports = class IdentityStoreMigrator {
|
|
|
|
constructor ({ configManager }) {
|
|
this.configManager = configManager
|
|
const hasOldVault = this.hasOldVault()
|
|
if (!hasOldVault) {
|
|
this.idStore = new IdentityStore({ configManager })
|
|
}
|
|
}
|
|
|
|
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)
|
|
}
|
|
})
|
|
})
|
|
}
|
|
|
|
serializeVault() {
|
|
const mnemonic = this.idStore._idmgmt.getSeed()
|
|
const n = this.idStore._getAddresses().length
|
|
|
|
return {
|
|
type: 'HD Key Tree',
|
|
data: { mnemonic, n },
|
|
}
|
|
}
|
|
|
|
hasOldVault() {
|
|
const wallet = this.configManager.getWallet()
|
|
return wallet
|
|
}
|
|
}
|