UNPKG

micro-key-producer

Version:

Produces secure passwords & keys for WebCrypto, SSH, PGP, SLIP10, OTP and many others

69 lines 2.52 kB
/** 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. */ 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 otpauth URL is malformed or requests unsupported OTP 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('JBSWY3DPEHPK3PXP'); * totp(opts, 0); * ``` */ export declare function parse(otp: string): OTPOpts; /** * 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('JBSWY3DPEHPK3PXP'); * buildURL(opts); * ``` */ export declare function buildURL(opts: OTPOpts): 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 OTP configuration requests an unsupported hash algorithm. {@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('JBSWY3DPEHPK3PXP'); * hotp(opts, 0); * ``` */ export declare function hotp(opts: OTPOpts, 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 OTP configuration requests an unsupported hash algorithm. {@link Error} * @example * Generate a TOTP code for a specific timestamp. * ```ts * import { parse, totp } from 'micro-key-producer/otp.js'; * const opts = parse('JBSWY3DPEHPK3PXP'); * totp(opts, 0); * ``` */ export declare function totp(opts: OTPOpts, ts?: number): string; //# sourceMappingURL=otp.d.ts.map