blob: 2d1826641e06cbd2eb2424e1459ef8c4389b8594 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
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
}
}
|