UNPKG

mikrosafe

Version:

Encrypt and decrypt your LocalStorage data, simply and securely.

64 lines (62 loc) 1.58 kB
/** * @description Encrypt and decrypt your LocalStorage data, simply and securely. * * @example * // Create a storage instance with a custom password * const storage = new MikroSafe('my-secure-password'); * * // Store data * await storage.setItem('userProfile', { * name: 'John Doe', * email: 'john@example.com', * isActive: true * }); * * // Retrieve data * const profile = await storage.getItem('userProfile'); * * // Remove data * storage.removeItem('userProfile'); * * // Clear all data * storage.clear(); */ declare class MikroSafe { private readonly cryptoKey; private readonly salt; /** * @description Creates a new MikroSafe instance with the provided password. */ constructor(password: string, options?: { salt?: string | Uint8Array; }); /** * @description Store an encrypted value in localStorage. */ setItem<T>(key: string, value: T): Promise<void>; /** * @description Retrieve and decrypt a value from localStorage. */ getItem<T>(key: string): Promise<T | null>; /** * @description Remove an item from localStorage. */ removeItem(key: string): void; /** * @description Clear all items from localStorage. */ clear(): void; /** * @description Generate a cryptographic key from the password. */ private generateKey; /** * @description Encrypt a string using AES-GCM. */ private encrypt; /** * @description Decrypt a string using AES-GCM. */ private decrypt; } export { MikroSafe };