totp-native
Version:
High-performance TOTP library using native Web Crypto API
96 lines • 2.84 kB
TypeScript
/**
* TOTP Native - High-performance TOTP library using Web Crypto API
* RFC 6238 compliant implementation with TypeScript support
*/
export interface TotpConfig {
secret: string;
digits?: number;
period?: number;
algorithm?: 'SHA1' | 'SHA256' | 'SHA512';
skew?: number;
explicitZeroPad?: boolean;
timestamp?: number;
}
export declare class TotpError extends Error {
code?: string | undefined;
constructor(message: string, code?: string | undefined);
}
/**
* TOTP Generator class for repeated use with the same configuration
*/
export declare class TotpGenerator {
private config;
constructor(config: TotpConfig);
/**
* Generate TOTP token for current time
*/
generate(): Promise<string>;
/**
* Generate TOTP token for specific timestamp
*/
generateAt(timestamp: number): Promise<string>;
/**
* Verify TOTP token against current time
*/
verify(token: string): Promise<boolean>;
/**
* Verify TOTP token with custom skew tolerance
*/
verifyWithSkew(token: string, skew: number): Promise<boolean>;
/**
* Generate Google Authenticator compatible URI
*/
generateUri(issuer: string, accountName: string): string;
/**
* Generate random Base32 secret
*/
static generateSecret(length?: number): string;
/**
* Parse Google Authenticator URI
*/
static parseUri(uri: string): TotpConfig;
}
/**
* Static utility class for one-off TOTP operations
*/
export declare class Totp {
/**
* Generate TOTP token directly from secret
*/
static generate(secret: string, options?: Partial<TotpConfig>): Promise<string>;
/**
* Generate TOTP token for specific timestamp
*/
static generateAt(secret: string, timestamp: number, options?: Partial<TotpConfig>): Promise<string>;
/**
* Verify TOTP token directly
*/
static verify(secret: string, token: string, options?: Partial<TotpConfig>): Promise<boolean>;
/**
* Verify TOTP token with custom skew
*/
static verifyWithSkew(secret: string, token: string, skew: number, options?: Partial<TotpConfig>): Promise<boolean>;
/**
* Generate random secret
*/
static generateSecret(length?: number): string;
/**
* Parse URI to config
*/
static parseUri(uri: string): TotpConfig;
/**
* Create URI from config
*/
static createUri(secret: string, issuer: string, accountName: string, options?: Partial<TotpConfig>): string;
/**
* Get remaining time in current period
*/
static getRemainingTime(period?: number): number;
}
declare const _default: {
TotpGenerator: typeof TotpGenerator;
Totp: typeof Totp;
TotpError: typeof TotpError;
};
export default _default;
//# sourceMappingURL=index.d.ts.map