import { type BinaryToTextEncoding } from 'node:crypto'; import { type Duration } from '@alwatr/parse-duration'; import type { CryptoAlgorithm } from './type.js'; export type TokenValidity = 'valid' | 'invalid' | 'expired'; /** * Represents the configuration for a token generator. */ export interface TokenGeneratorConfig { /** * The prefix to be added to the generated hash. */ prefix: string; /** * The algorithm used for hashing. */ algorithm: CryptoAlgorithm; /** * The encoding used for the generated hash. */ encoding: BinaryToTextEncoding; /** * The secret used for encryption and decryption tokens. */ secret: string; /** * The duration for which the token is valid. */ duration: Duration | 'infinite'; } /** * Secure authentication HOTP token generator (HMAC-based One-Time Password algorithm). */ export declare class AlwatrTokenGenerator { config: TokenGeneratorConfig; private _duration; /** * The current epoch based on the configured duration. */ protected get _epoch(): number; /** * Creates a new instance of AlwatrTokenGenerator. * @param config The configuration for the token generator. */ constructor(config: TokenGeneratorConfig); /** * Generates a HOTP token based on the provided data for special duration. * @param data The data to generate the token from. * @returns The generated token. * @example * ```typescript * user.auth = tokenGenerator.generate(`${user.id}-${user.role}`); * ``` */ generate(data: string): string; /** * Verifies if a token is valid. * @param data The data used to generate the token. * @param token The token to verify. * @returns The validity of the token. * @example * ```typescript * const validateStatus = tokenGenerator.verify([user.id,user.role].join(), user.auth); * ``` */ verify(data: string, token: string): TokenValidity; /** * Generates a cryptographic token based on the provided data and epoch. * @param data - The data to be used in the token generation. * @param epoch - The epoch value to be used in the token generation. * @returns The generated cryptographic token. */ protected _generate(data: string, epoch: number): string; } //# sourceMappingURL=token.d.ts.map