diff --git a/lib/flow-typed/web-crypto-common.js b/lib/flow-typed/web-crypto-common.js --- a/lib/flow-typed/web-crypto-common.js +++ b/lib/flow-typed/web-crypto-common.js @@ -20,7 +20,16 @@ | 'wrapKey' | 'unwrapKey'; -declare type CryptoKey = SubtleCrypto$JsonWebKey; +declare type CryptoKey = { + +algorithm: + | SubtleCrypto$AesKeyGenParams + | SubtleCrypto$RsaHashedKeyGenParams + | SubtleCrypto$EcKeyGenParams + | SubtleCrypto$HmacKeyGenParams, + +extractable: boolean, + +type: CryptoKey$Type, + +usages: $ReadOnlyArray, +}; type SubtleCrypto$KeyFormatWithoutJwk = 'pkcs8' | 'raw' | 'spki'; type SubtleCrypto$KeyFormat = 'jwk' | SubtleCrypto$KeyFormatWithoutJwk; diff --git a/web/account/account-hooks.js b/web/account/account-hooks.js --- a/web/account/account-hooks.js +++ b/web/account/account-hooks.js @@ -229,11 +229,13 @@ ); const persistEncryptionKeyPromise = (async () => { - let cryptoKeyPersistentForm = encryptionKey; + let cryptoKeyPersistentForm; if (isDesktopSafari) { // Safari doesn't support structured clone algorithm in service // worker context so we have to store CryptoKey as JSON cryptoKeyPersistentForm = await exportKeyToJWK(encryptionKey); + } else { + cryptoKeyPersistentForm = encryptionKey; } await localforage.setItem( diff --git a/web/push-notif/notif-crypto-utils.js b/web/push-notif/notif-crypto-utils.js --- a/web/push-notif/notif-crypto-utils.js +++ b/web/push-notif/notif-crypto-utils.js @@ -52,15 +52,21 @@ const { id, encryptedPayload } = encryptedNotification; const retrieveEncryptionKeyPromise: Promise = (async () => { - const persistedCryptoKey = await localforage.getItem( - NOTIFICATIONS_OLM_DATA_ENCRYPTION_KEY, - ); - if (isDesktopSafari && persistedCryptoKey) { - // Safari doesn't support structured clone algorithm in service - // worker context so we have to store CryptoKey as JSON - return await importJWKKey(persistedCryptoKey); + if (!isDesktopSafari) { + return await localforage.getItem( + NOTIFICATIONS_OLM_DATA_ENCRYPTION_KEY, + ); + } + // Safari doesn't support structured clone algorithm in service + // worker context so we have to store CryptoKey as JSON + const persistedCryptoKey = + await localforage.getItem( + NOTIFICATIONS_OLM_DATA_ENCRYPTION_KEY, + ); + if (!persistedCryptoKey) { + return null; } - return persistedCryptoKey; + return await importJWKKey(persistedCryptoKey); })(); const [encryptedOlmData, encryptionKey, utilsData] = await Promise.all([