diff --git a/src/utils/encryption-utils.ts b/src/utils/encryption-utils.ts index 823b967..b047345 100644 --- a/src/utils/encryption-utils.ts +++ b/src/utils/encryption-utils.ts @@ -7,6 +7,16 @@ try { console.warn('Electron safeStorage not available, API keys will be stored in plaintext'); } +/** + * Checks if encryption is available on the current platform + * @returns true if safeStorage encryption is available + */ +export function isEncryptionAvailable(): boolean { + return safeStorage !== null && + typeof safeStorage.isEncryptionAvailable === 'function' && + safeStorage.isEncryptionAvailable(); +} + /** * Encrypts an API key using Electron's safeStorage API * Falls back to plaintext if encryption is not available (e.g., Linux without keyring) @@ -19,7 +29,7 @@ export function encryptApiKey(apiKey: string): string { } // Check if safeStorage is available and encryption is enabled - if (!safeStorage || !safeStorage.isEncryptionAvailable()) { + if (!isEncryptionAvailable()) { console.warn('Encryption not available, storing API key in plaintext'); return apiKey; } @@ -64,13 +74,3 @@ export function decryptApiKey(stored: string): string { throw new Error('Failed to decrypt API key. You may need to regenerate it.'); } } - -/** - * Checks if encryption is available on the current platform - * @returns true if safeStorage encryption is available - */ -export function isEncryptionAvailable(): boolean { - return safeStorage !== null && - typeof safeStorage.isEncryptionAvailable === 'function' && - safeStorage.isEncryptionAvailable(); -}