Skip to content

Commit

Permalink
handle when crypto key is possibly null
Browse files Browse the repository at this point in the history
  • Loading branch information
joetannenbaum committed Oct 10, 2024
1 parent ee300ef commit adb45a9
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/core/src/encryption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ export const encryptHistory = async (data: any): Promise<ArrayBuffer> => {
const iv = getIv()
const storedKey = await getKeyFromSessionStorage()
const key = await getOrCreateKey(storedKey)

if (!key) {
throw new Error('Unable to encrypt history')
}

const encrypted = await encryptData(iv, key, data)

return encrypted
Expand Down Expand Up @@ -125,6 +130,10 @@ const getOrCreateKey = async (key: CryptoKey | null) => {

const newKey = await createKey()

if (!newKey) {
return null
}

await saveKey(newKey)

return newKey
Expand Down

0 comments on commit adb45a9

Please sign in to comment.