+ Move your API keys from data.json{" "}
+ to this device's{" "}
+ Obsidian Keychain.{" "}
+ data.json will be stripped of API keys after migration.
+
+ Unable to decrypt this key on the current device. Please re-enter the key. +
+ )} ); } diff --git a/src/constants.ts b/src/constants.ts index 394d9d1d..d9a37c00 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -942,7 +942,6 @@ export const DEFAULT_SETTINGS: CopilotSettings = { chatNoteContextTags: [], enableIndexSync: true, debug: false, - enableEncryption: false, maxSourceChunks: DEFAULT_MAX_SOURCE_CHUNKS, enableInlineCitations: true, groqApiKey: "", diff --git a/src/encryptionService.test.ts b/src/encryptionService.test.ts index 5de6d3f0..78b6046b 100644 --- a/src/encryptionService.test.ts +++ b/src/encryptionService.test.ts @@ -19,137 +19,272 @@ window.TextEncoder = TextEncoder; window.TextDecoder = TextDecoder as unknown as typeof window.TextDecoder; // Now we can import our modules -import { encryptAllKeys, getDecryptedKey, getEncryptedKey } from "@/encryptionService"; -import { type CopilotSettings } from "@/settings/model"; -import { Platform } from "obsidian"; +import { getDecryptedKey, isEncryptedValue, isSensitiveKey } from "@/encryptionService"; import { Buffer } from "buffer"; -// Mock window.btoa and window.atob for base64 encoding/decoding -window.btoa = jest.fn().mockImplementation((str: string) => Buffer.from(str).toString("base64")); -window.atob = jest.fn().mockImplementation((str: string) => Buffer.from(str, "base64").toString()); +// Mock btoa/atob for base64 encoding/decoding (binary-safe). jsdom's defaults +// are not binary-safe and break the legacy encrypted-payload round-trips below. +window.btoa = jest + .fn() + .mockImplementation((str: string) => Buffer.from(str, "latin1").toString("base64")); +window.atob = jest + .fn() + .mockImplementation((str: string) => Buffer.from(str, "base64").toString("latin1")); + +/** + * Ensure `window.localStorage` is usable for tests. + */ +function ensureTestLocalStorage(): { clear: () => void } { + try { + const storage = window.localStorage; + storage.setItem("__copilot_test__", "1"); + storage.removeItem("__copilot_test__"); + return { clear: () => window.localStorage.clear() }; + } catch { + const data = new Map