UNPKG

adba

Version:
96 lines (95 loc) 3.28 kB
/** * Encrypt a string using AES-256-CBC. * * @param text - Plain text to encrypt. * @param password - Password used for key derivation. * @param ivString - Initialization vector in hex format. * @returns Object containing encrypted data and IV. * * @example * const { encryptedData, iv } = encrypt('hello', 'pass', ''); * const plain = decrypt(encryptedData, 'pass', iv); */ export declare function encrypt(text: string, password: string, ivString: string): { encryptedData: string; iv: string; }; /** * Decrypt data encrypted with {@link encrypt}. * * @param encryptedData - The hexadecimal encrypted string. * @param password - Password used for key derivation. * @param ivString - Initialization vector in hex format. * @returns The decrypted plain text. */ export declare function decrypt(encryptedData: string, password: string, ivString: string): string; /** * Generates a unique 6-digit code. * * @returns A 6-digit code as string. * * @example * const code = generateCode(); * console.log(code); // "482901" */ export declare function generateCode(): string; /** * Build a secure token that contains encrypted data. * * @param data - Payload to include in the token. * @param pass - Encryption key. * @param ivString - Initialization vector in hex format. * @param expiresIn - Expiration time for the JWT. * @returns URL-safe encrypted token string. * * @example * const token = buildToken({ payload: { foo: 'bar' } }, 'pass', iv, '1h'); */ export declare const buildToken: (data: { payload: any; }, pass: string, ivString: string, expiresIn: string) => string; /** * Decrypt a token created with {@link buildToken}. * * @param encryptedToken - The encrypted token. * @param pass - Decryption key. * @param ivString - Initialization vector in hex format. * @returns The decrypted payload or an Error instance. */ export declare const readToken: (encryptedToken: string, pass: string, ivString: string) => any; /** * Generate a bcrypt hash from a plain password. * * @param password - Password to hash. * @returns The hashed password or an Error. * * @example * const hash = await generatePasswordHash('secret'); */ export declare function generatePasswordHash(password: string): Promise<unknown>; /** * Verify a password against a bcrypt hash. * * @param password - Plain password to verify. * @param hash - Previously generated hash. * @returns True if the password matches, otherwise false or an Error. */ export declare function verifyPasswordHash(password: string, hash: string): Promise<unknown>; /** * Determine the client family from a user-agent string. * * @param userAgent - Raw user-agent header string. * @param device - Optional device hint. * @returns The detected client family (e.g. 'Chrome'). */ export declare function getClientType(userAgent: string, device?: string): string; declare const _default: { buildToken: (data: { payload: any; }, pass: string, ivString: string, expiresIn: string) => string; readToken: (encryptedToken: string, pass: string, ivString: string) => any; generatePasswordHash: typeof generatePasswordHash; verifyPasswordHash: typeof verifyPasswordHash; getClientType: typeof getClientType; }; export default _default;