UNPKG

@colingreybosh/otp-lib

Version:

A TypeScript library for generating, validating, and managing one-time passwords (OTP) for authentication purposes.

31 lines 1.02 kB
export type OTPAlgorithm = 'SHA1' | 'SHA256' | 'SHA512'; export type SecretLength = 20 | 32 | 64; export interface OTPConfig { readonly secret: string; readonly algorithm: OTPAlgorithm; readonly digits: number; readonly period?: number; readonly counter?: number; } export interface TOTPConfig extends Omit<OTPConfig, 'counter'> { readonly period: number; } export interface HOTPConfig extends Omit<OTPConfig, 'period'> { readonly counter: number; } export interface OTPResult { readonly token: string; readonly remainingTime: number; } export type ValidationResult = { readonly isValid: true; readonly delta: number; } | { readonly isValid: false; }; export type OTPError = 'INVALID_SECRET' | 'INVALID_ALGORITHM' | 'INVALID_DIGITS' | 'INVALID_PERIOD' | 'INVALID_COUNTER' | 'INVALID_TOKEN' | 'EXPIRED_TOKEN'; export declare class OTPException extends Error { readonly code: OTPError; constructor(code: OTPError, message: string); } //# sourceMappingURL=index.d.ts.map