Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

refactor: fix typings for getCryptoKey

thecodrr47b2c0e43c0c
diff --git a/apps/web/src/interfaces/storage.ts b/apps/web/src/interfaces/storage.ts
index 7349e5701..89538cc97 100644
--- a/apps/web/src/interfaces/storage.ts
+++ b/apps/web/src/interfaces/storage.ts
@@ -56,15 +56,17 @@ async function deriveCryptoKey(name: string, credentials: SerializedKey) {
}
}
-async function getCryptoKey(name: string) {
+async function getCryptoKey(name: string): Promise<string | undefined> {
if (isIndexedDBSupported() && window?.crypto?.subtle) {
const pbkdfKey = await read<CryptoKey>(name);
- const cipheredKey = await read<EncryptedKey>(`${name}@_k`);
+ const cipheredKey = await read<EncryptedKey | string>(`${name}@_k`);
if (typeof cipheredKey === "string") return cipheredKey;
if (!pbkdfKey || !cipheredKey) return;
return await aesDecrypt(pbkdfKey, cipheredKey);
} else {
- return await read(`${name}@_k`);
+ const key = await read<string>(`${name}@_k`);
+ if (!key) return;
+ return key;
}
}