UNPKG

system-secured-storage

Version:

A Node.js project that allows users to store encrypted key-value data locally on their system. This project serves as an alternate storage solution to SQLite but with enhanced security features, leveraging AES encryption to ensure the confidentiality and

112 lines (111 loc) 3.08 kB
import { SystemSecuredStorageOptions } from '../types/types'; /** * Securely store data on you system. * * @exports * @class SystemSecuredStorage * * ``` * // Example * import SystemSecuredStorage from 'system-secured-storage'; * * const storage = new SystemSecuredStorage(options) * * // Encrypt and store the key-value pair * storage.storeData('myKey', 'mySensitiveData'); * * // Retrieve and decrypt the data using the key * const decryptedData = storage.retrieveData('myKey'); * ``` */ export declare class SystemSecuredStorage { private fileDirectory; private encryptionService; /** * Create an instance of the SystemSecuredStorage. * * @param {SystemSecuredStorageOptions} options - Options */ constructor({ directory, encryptionKey, ivKey }: SystemSecuredStorageOptions); /** * Retrieve all stored data. * * @returns */ retrieveAll: <T = { [key: string]: any; }>() => T | undefined; /** * Asynchronously retrieve all stored data. * * @param {void} callback - Callback function. * @returns */ retrieveAllAsync: <T = { [key: string]: any; }>(callback: (error: any | null, data: T | undefined) => void) => void; /** * Encrypt data. * * @param storedData - The stored data locally. * @param {string} key - The key of the data to add. * @param {string} data - The data. * @returns */ private encryptData; /** * Store data. * * @param {string} key - The key. * @param {string} data - The data. */ storeData(key: string, data: any): void; /** * Asynchronously store data. * * @param {string} key - The key. * @param {string} data - The data. * @param {void} callback - Callback function. */ storeDataAsync(key: string, data: any, callback: (error: any) => void): void; /** * Retrieve store data. * * @param {string} key - The key the data stored in. * @returns {T} The data stored. */ retrieveData<T>(key: string): T | undefined; /** * Asynchronously retrieve store data. * * @param {string} key - The key the data stored in. * @param {void} callback - Callback function. * @returns {T} The data stored. */ retrieveDataAsync<T>(key: string, callback: (error: any | null, data: T | undefined) => void): void; /** * Delete stored data. * * @param {string} key - The key the data stored in. * @returns */ deleteData(key: string): void; /** * Asynchronously delete stored data. * * @param {string} key - The key the data stored in. * @param {void} callback - Callback function. * @returns */ deleteDataAsync(key: string, callback: (error: any) => void): void; /** * Reset storage. */ reset(): void; /** * Asynchronously reset storage. * * @param {void} callback - Callback function. */ resetAsync(callback: (error: any) => void): void; }