unencrypt seed backup
This commit is contained in:
parent
6b6e7ce240
commit
07dc27e2b4
1 changed files with 9 additions and 6 deletions
|
|
@ -1236,21 +1236,24 @@ let currentSeedBackup = null
|
||||||
/**
|
/**
|
||||||
* @param {(seedBackup: string|null) => void} cb
|
* @param {(seedBackup: string|null) => void} cb
|
||||||
* @param {UserGUNNode} user
|
* @param {UserGUNNode} user
|
||||||
|
* @param {ISEA} SEA
|
||||||
* @throws {Error} If user hasn't been auth.
|
* @throws {Error} If user hasn't been auth.
|
||||||
* @returns {void}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
const onSeedBackup = (cb, user) => {
|
const onSeedBackup = async (cb, user, SEA) => {
|
||||||
if (!user.is) {
|
if (!user.is) {
|
||||||
throw new Error(ErrorCode.NOT_AUTH)
|
throw new Error(ErrorCode.NOT_AUTH)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const mySecret = await SEA.secret(user._.sea.epub, user._.sea)
|
||||||
|
|
||||||
const callb = debounce(cb, DEBOUNCE_WAIT_TIME)
|
const callb = debounce(cb, DEBOUNCE_WAIT_TIME)
|
||||||
callb(currentSeedBackup)
|
callb(currentSeedBackup)
|
||||||
|
|
||||||
user.get(Key.SEED_BACKUP).on(seedBackup => {
|
user.get(Key.SEED_BACKUP).on(async seedBackup => {
|
||||||
if (typeof seedBackup === 'string' || seedBackup === null) {
|
if (typeof seedBackup === 'string') {
|
||||||
currentSeedBackup = seedBackup
|
currentSeedBackup = await SEA.decrypt(seedBackup, mySecret)
|
||||||
callb(seedBackup)
|
callb(currentSeedBackup)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue