gnablib
Version:
A lean, zero dependency library to provide a useful base for your project.
40 lines (39 loc) • 1.91 kB
TypeScript
/*! Copyright 2026 the gnablib contributors MPL-1.1 */
import { ParseProblem } from '../../error/probs/ParseProblem.js';
import { U64, U64Mut } from '../../primitive/number/U64.js';
import { IHash } from '../interfaces/IHash.js';
declare class Otp {
private readonly _a8;
protected readonly _c: U64Mut;
readonly digits: number;
private readonly _mod;
private readonly _hashAlgo;
private _h;
protected constructor(key: Uint8Array, digits: number, algo: IHash);
get counter(): U64;
protected _truncate(hashResult: Uint8Array): number;
generate(_nop?: boolean): number;
validate(tok: number, backWindow?: number, forwardWindow?: number): boolean;
protected _uriBase(iss: string, user: string, key: string | Uint8Array): string;
protected static _parseUri(uri: string, type: string): [string, string, Uint8Array, IHash | undefined, number, number, number] | ParseProblem;
static randomKey(size?: number): Uint8Array;
}
export declare class Hotp extends Otp {
createUri(iss: string, user: string, key: string | Uint8Array): string;
consume(): void;
static newWithKey(key: Uint8Array, digits?: number, algo?: IHash, counter?: U64): Hotp;
static parseUri(uri: string): [Hotp, string, string] | ParseProblem;
}
export declare class Totp extends Otp {
private readonly _x;
protected constructor(key: Uint8Array, timeStep: number, digits: number, algo: IHash);
get timeStep(): number;
private _setNow;
setUtime(utime: U64): void;
generate(liveTime?: boolean): number;
validate(tok: number, backWindow?: number, forwardWindow?: number, liveTime?: boolean): boolean;
createUri(iss: string, user: string, key: string | Uint8Array): string;
static newWithKey(key: Uint8Array, timeStep?: number, digits?: number, algo?: IHash): Totp;
static parseUri(uri: string): [Totp, string, string] | ParseProblem;
}
export {};