UNPKG

totpify

Version:

Advanced TOTP Library with enhanced security features and algorithm support

31 lines (30 loc) 1.49 kB
import { TOTPOptions, VerifyResult, QRCodeOptions } from './types'; /** * Generates a Time-Based One-Time Password (TOTP) according to RFC 623 * @param secret The secret key as a string (Base32 encoded) or a Uint8Array * @param options Options for TOTP generation * @returns The generated TOTP code */ export declare function generateTOTP(secret: string | Uint8Array, options?: TOTPOptions): string; /** * Verifies a Time-Based One-Time Password (TOTP) allowing for time skew * @param token The TOTP code to verify * @param secret The secret key as a string (Base32 encoded) or a Uint8Array * @param options Options for TOTP verification * @returns Result object with valid flag and time drift information */ export declare function verifyTOTP(token: string, secret: string | Uint8Array, options?: TOTPOptions): VerifyResult; /** * Generates a QR code for easy TOTP setup with authenticator apps. * The QR code follows the 'otpauth://' URI format. * @param secret The secret key (Base32 encoded) * @param options Options for QR code generation * @returns Promise resolving to a data URL containing the QR code */ export declare function generateQRCode(secret: string, options?: QRCodeOptions): Promise<string>; /** * Generates a random secret key in Base32 format for use with TOTP * @param length The length of the secret key in bytes (default: 20) * @returns Base32 encoded random secret */ export declare function generateRandomSecret(length?: number): string;