From 8cad56e312f0588dcd545a364d103431edbf3595 Mon Sep 17 00:00:00 2001 From: tamarafinogina Date: Tue, 20 Jan 2026 18:45:53 +0100 Subject: [PATCH] return keys too --- src/email-search/indexedDB.ts | 8 ++++---- src/keystore-crypto/emailEncryptionKey.ts | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/email-search/indexedDB.ts b/src/email-search/indexedDB.ts index dae96b5..99dcf9e 100644 --- a/src/email-search/indexedDB.ts +++ b/src/email-search/indexedDB.ts @@ -90,7 +90,7 @@ export const encryptAndStoreEmail = async ( esDB: MailDB, ): Promise => { try { - const aux = getAux(newEmailToStore.params); + const aux = getAux(newEmailToStore.params, false); const enc = await encryptEmailContentSymmetricallyWithKey(newEmailToStore.body, indexKey, aux, newEmailToStore.id); const encryptedEmail: StoredEmail = { enc, params: newEmailToStore.params, id: newEmailToStore.id }; await esDB.put(DB_LABEL, encryptedEmail); @@ -114,7 +114,7 @@ export const encryptAndStoreManyEmail = async ( try { const encryptedEmails = await Promise.all( newEmailsToStore.map(async (email: Email) => { - const aux = getAux(email.params); + const aux = getAux(email.params, false); const enc = await encryptEmailContentSymmetricallyWithKey(email.body, indexKey, aux, email.id); return { enc, params: email.params, id: email.id }; @@ -137,7 +137,7 @@ export const encryptAndStoreManyEmail = async ( */ const decryptEmail = async (indexKey: CryptoKey, encryptedEmail: StoredEmail): Promise => { try { - const aux = getAux(encryptedEmail.params); + const aux = getAux(encryptedEmail.params, false); const email = await decryptEmailSymmetrically(indexKey, aux, encryptedEmail.enc); return { body: email, params: encryptedEmail.params, id: encryptedEmail.id }; } catch (error) { @@ -178,7 +178,7 @@ export const getAndDecryptAllEmails = async (indexKey: CryptoKey, esDB: MailDB): const decryptedEmails = await Promise.all( encryptedEmails.map(async (encEmail) => { - const aux = getAux(encEmail.params); + const aux = getAux(encEmail.params, false); const body = await decryptEmailSymmetrically(indexKey, aux, encEmail.enc); return { body, params: encEmail.params, id: encEmail.id }; }), diff --git a/src/keystore-crypto/emailEncryptionKey.ts b/src/keystore-crypto/emailEncryptionKey.ts index f6caa5b..c8e847d 100644 --- a/src/keystore-crypto/emailEncryptionKey.ts +++ b/src/keystore-crypto/emailEncryptionKey.ts @@ -8,7 +8,7 @@ import { generateEmailKeys } from '../email-crypto'; * The main keystore encryption key is derived from the base key (stored in session storage) * The recovery keystore encryption key is derived from the recovery codes * - * @returns The encryption and recovery keystores + * @returns The encryption and recovery keystores, recovery codes and email keys */ export async function createEncryptionAndRecoveryKeystores( userEmail: string, @@ -17,6 +17,7 @@ export async function createEncryptionAndRecoveryKeystores( encryptionKeystore: EncryptedKeystore; recoveryKeystore: EncryptedKeystore; recoveryCodes: string; + keys: EmailKeys; }> { try { const keys = await generateEmailKeys(); @@ -28,7 +29,7 @@ export async function createEncryptionAndRecoveryKeystores( const recoveryKey = await deriveRecoveryKey(recoveryCodes); const recoveryKeystore = await encryptKeystoreContent(recoveryKey, keys, userEmail, KeystoreType.RECOVERY); - return { encryptionKeystore, recoveryKeystore, recoveryCodes }; + return { encryptionKeystore, recoveryKeystore, recoveryCodes, keys }; } catch (error) { throw new Error('Failed to create encryption and recovery keystores', { cause: error }); }