import { type TArg, type TRet } from '@scure/base'; /** HOTP/TOTP configuration. */ export type OTPOpts = { /** HMAC hash name: `sha1`, `sha256`, or `sha512`. */ algorithm: string; /** Number of digits to keep from the generated OTP code (6 through 16). */ digits: number; /** TOTP step size in seconds. */ interval: number; /** Decoded OTP secret bytes. */ secret: Uint8Array; }; /** * Parses a raw base32 secret or `otpauth://totp/...` URL. * @param otp - Base32 secret or otpauth URL. * @returns Normalized OTP settings. * @throws If the secret is shorter than 128 bits or the URL requests unsupported settings. {@link Error} * @example * Parse either a base32 secret or an otpauth URL before generating codes. * ```ts * import { parse, totp } from 'micro-key-producer/otp.js'; * const opts = parse('ZYTYYE5FOAGW5ML7LRWUL4WTZLNJAMZS'); * totp(opts, 0); * ``` */ export declare function parse(otp: string): TRet; /** * Serializes OTP settings into an `otpauth://totp/...` URL. * @param opts - Parsed OTP settings. See {@link OTPOpts}. * @returns OTP URL string. * @example * Rebuild the otpauth URL after normalizing or editing the parsed settings. * ```ts * import { parse, buildURL } from 'micro-key-producer/otp.js'; * const opts = parse('ZYTYYE5FOAGW5ML7LRWUL4WTZLNJAMZS'); * buildURL(opts); * ``` */ export declare function buildURL(opts: TArg): string; /** * Computes an HOTP code for the supplied moving factor. * @param opts - OTP settings and secret. See {@link OTPOpts}. * @param counter - HOTP counter value. * @returns Numeric HOTP code as a zero-padded string. * @throws If the secret is shorter than 128 bits or the configuration is unsupported. {@link Error} * @example * Generate an HOTP code for an explicit moving counter value. * ```ts * import { parse, hotp } from 'micro-key-producer/otp.js'; * const opts = parse('ZYTYYE5FOAGW5ML7LRWUL4WTZLNJAMZS'); * hotp(opts, 0); * ``` */ export declare function hotp(opts: TArg, counter: number | bigint): string; /** * Computes a TOTP code for the supplied timestamp. * @param opts - OTP settings and secret. See {@link OTPOpts}. * @param ts - UNIX time in milliseconds. * @returns Numeric TOTP code as a zero-padded string. * @throws If the secret is shorter than 128 bits or the configuration is unsupported. {@link Error} * @example * Generate a TOTP code for a specific timestamp. * ```ts * import { parse, totp } from 'micro-key-producer/otp.js'; * const opts = parse('ZYTYYE5FOAGW5ML7LRWUL4WTZLNJAMZS'); * totp(opts, 0); * ``` */ export declare function totp(opts: TArg, ts?: number): string;