diff --git a/web/shared-worker/worker/worker-crypto.js b/web/shared-worker/worker/worker-crypto.js --- a/web/shared-worker/worker/worker-crypto.js +++ b/web/shared-worker/worker/worker-crypto.js @@ -18,6 +18,7 @@ type EncryptedData, type OutboundSessionCreationResult, } from 'lib/types/crypto-types.js'; +import type { PlatformDetails } from 'lib/types/device-types.js'; import type { IdentityNewDeviceKeyUpload, IdentityExistingDeviceKeyUpload, @@ -334,6 +335,31 @@ }; } +function getNotifsPersistenceKeys( + cookie: ?string, + keyserverID: string, + platformDetails: PlatformDetails, +) { + if (hasMinCodeVersion(platformDetails, { majorDesktop: 12 })) { + return { + notifsOlmDataEncryptionKeyDBLabel: getOlmEncryptionKeyDBLabelForCookie( + cookie, + keyserverID, + ), + notifsOlmDataContentKey: getOlmDataContentKeyForCookie( + cookie, + keyserverID, + ), + }; + } else { + return { + notifsOlmDataEncryptionKeyDBLabel: + getOlmEncryptionKeyDBLabelForCookie(cookie), + notifsOlmDataContentKey: getOlmDataContentKeyForCookie(cookie), + }; + } +} + const olmAPI: OlmAPI = { async initializeCryptoAccount(): Promise { const sqliteQueryExecutor = getSQLiteQueryExecutor(); @@ -538,23 +564,8 @@ encryptionKey, ); - let notifsOlmDataContentKey; - let notifsOlmDataEncryptionKeyDBLabel; - - if (hasMinCodeVersion(platformDetails, { majorDesktop: 12 })) { - notifsOlmDataEncryptionKeyDBLabel = getOlmEncryptionKeyDBLabelForCookie( - cookie, - keyserverID, - ); - notifsOlmDataContentKey = getOlmDataContentKeyForCookie( - cookie, - keyserverID, - ); - } else { - notifsOlmDataEncryptionKeyDBLabel = - getOlmEncryptionKeyDBLabelForCookie(cookie); - notifsOlmDataContentKey = getOlmDataContentKeyForCookie(cookie); - } + const { notifsOlmDataContentKey, notifsOlmDataEncryptionKeyDBLabel } = + getNotifsPersistenceKeys(cookie, keyserverID, platformDetails); const persistEncryptionKeyPromise = (async () => { let cryptoKeyPersistentForm;