Fix old key overwrites new key (#2290)
This commit is contained in:
parent
f7be43d3af
commit
075934e20b
@ -152,16 +152,11 @@ export function useKeyInit () {
|
|||||||
try {
|
try {
|
||||||
// TODO(wallet-v2): remove migration code
|
// TODO(wallet-v2): remove migration code
|
||||||
// and delete the old IndexedDB after wallet v2 has been released for some time
|
// and delete the old IndexedDB after wallet v2 has been released for some time
|
||||||
const oldKeyAndHash = await loadOldKey()
|
|
||||||
if (oldKeyAndHash) {
|
|
||||||
// return key found in old db and save it to new db
|
|
||||||
await setKey(oldKeyAndHash)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// create random key before opening transaction in case we need it
|
// load old key and create random key before opening transaction in case we need them
|
||||||
// and because we can't run async code in a transaction because it will close the transaction
|
// because we can't run async code in a transaction because it will close the transaction
|
||||||
// see https://javascript.info/indexeddb#transactions-autocommit
|
// see https://javascript.info/indexeddb#transactions-autocommit
|
||||||
|
const oldKeyAndHash = await loadOldKey()
|
||||||
const { key: randomKey, hash: randomHash } = await generateRandomKey()
|
const { key: randomKey, hash: randomHash } = await generateRandomKey()
|
||||||
|
|
||||||
// run read and write in one transaction to avoid race conditions
|
// run read and write in one transaction to avoid race conditions
|
||||||
@ -179,6 +174,11 @@ export function useKeyInit () {
|
|||||||
return resolve(read.result)
|
return resolve(read.result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (oldKeyAndHash) {
|
||||||
|
// return key+hash found in old db
|
||||||
|
return resolve(oldKeyAndHash)
|
||||||
|
}
|
||||||
|
|
||||||
// no key found, write and return generated random key
|
// no key found, write and return generated random key
|
||||||
const write = tx.objectStore('vault').put({ key: randomKey, hash: randomHash }, 'key')
|
const write = tx.objectStore('vault').put({ key: randomKey, hash: randomHash }, 'key')
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user