Files
ERitors-Scribe-Desktop/electron/database/keyManager.ts
natreex 3bc30d42ad Remove Story model handling verbal styles and linguistic properties
- Delete `Story` model implementation including `getVerbesStyle` method and related properties.
- Cleanup unused interfaces and redundant logic from the codebase.
2025-11-17 21:32:42 -05:00

49 lines
1.3 KiB
TypeScript

import Store from 'electron-store';
/**
* Key Manager - Manages user encryption keys stored in electron-store
*/
const store = new Store({
encryptionKey: 'eritors-scribe-secure-key'
});
/**
* Get user encryption key from secure store
* @param userId - User ID
* @returns User's encryption key or null if not found
*/
export function getUserEncryptionKey(userId: string): string {
const key: string | undefined = store.get(`encryptionKey-${userId}`) as string | undefined;
if (key === undefined) {
throw new Error(`Unknown encryptionKey`);
}
return key;
}
/**
* Set user encryption key in secure store
* @param userId - User ID
* @param encryptionKey - Encryption key to store
*/
export function setUserEncryptionKey(userId: string, encryptionKey: string): void {
store.set(`encryptionKey-${userId}`, encryptionKey);
}
/**
* Check if user has an encryption key
* @param userId - User ID
* @returns True if key exists
*/
export function hasUserEncryptionKey(userId: string): boolean {
return store.has(`encryptionKey-${userId}`);
}
/**
* Delete user encryption key
* @param userId - User ID
*/
export function deleteUserEncryptionKey(userId: string): void {
store.delete(`encryptionKey-${userId}`);
}