123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390 |
- /**
- * OTP secret key.
- */
- declare class Secret {
- /**
- * Converts a Latin-1 string to a Secret object.
- * @param {string} str Latin-1 string.
- * @returns {Secret} Secret object.
- */
- static fromLatin1(str: string): Secret;
- /**
- * Converts an UTF-8 string to a Secret object.
- * @param {string} str UTF-8 string.
- * @returns {Secret} Secret object.
- */
- static fromUTF8(str: string): Secret;
- /**
- * Converts a base32 string to a Secret object.
- * @param {string} str Base32 string.
- * @returns {Secret} Secret object.
- */
- static fromBase32(str: string): Secret;
- /**
- * Converts a hexadecimal string to a Secret object.
- * @param {string} str Hexadecimal string.
- * @returns {Secret} Secret object.
- */
- static fromHex(str: string): Secret;
- /**
- * Creates a secret key object.
- * @param {Object} [config] Configuration options.
- * @param {ArrayBufferLike} [config.buffer] Secret key buffer.
- * @param {number} [config.size=20] Number of random bytes to generate, ignored if 'buffer' is provided.
- */
- constructor({ buffer, size }?: {
- buffer?: ArrayBufferLike | undefined;
- size?: number | undefined;
- } | undefined);
- /**
- * Secret key.
- * @type {Uint8Array}
- * @readonly
- */
- readonly bytes: Uint8Array;
- /**
- * Secret key buffer.
- * @deprecated For backward compatibility, the "bytes" property should be used instead.
- * @type {ArrayBufferLike}
- */
- get buffer(): ArrayBufferLike;
- /**
- * Latin-1 string representation of secret key.
- * @type {string}
- */
- get latin1(): string;
- /**
- * UTF-8 string representation of secret key.
- * @type {string}
- */
- get utf8(): string;
- /**
- * Base32 string representation of secret key.
- * @type {string}
- */
- get base32(): string;
- /**
- * Hexadecimal string representation of secret key.
- * @type {string}
- */
- get hex(): string;
- }
- /**
- * HOTP: An HMAC-based One-time Password Algorithm.
- * @see [RFC 4226](https://tools.ietf.org/html/rfc4226)
- */
- declare class HOTP {
- /**
- * Default configuration.
- * @type {{
- * issuer: string,
- * label: string,
- * issuerInLabel: boolean,
- * algorithm: string,
- * digits: number,
- * counter: number
- * window: number
- * }}
- */
- static get defaults(): {
- issuer: string;
- label: string;
- issuerInLabel: boolean;
- algorithm: string;
- digits: number;
- counter: number;
- window: number;
- };
- /**
- * Generates an HOTP token.
- * @param {Object} config Configuration options.
- * @param {Secret} config.secret Secret key.
- * @param {string} [config.algorithm='SHA1'] HMAC hashing algorithm.
- * @param {number} [config.digits=6] Token length.
- * @param {number} [config.counter=0] Counter value.
- * @returns {string} Token.
- */
- static generate({ secret, algorithm, digits, counter, }: {
- secret: Secret;
- algorithm?: string | undefined;
- digits?: number | undefined;
- counter?: number | undefined;
- }): string;
- /**
- * Validates an HOTP token.
- * @param {Object} config Configuration options.
- * @param {string} config.token Token value.
- * @param {Secret} config.secret Secret key.
- * @param {string} [config.algorithm='SHA1'] HMAC hashing algorithm.
- * @param {number} config.digits Token length.
- * @param {number} [config.counter=0] Counter value.
- * @param {number} [config.window=1] Window of counter values to test.
- * @returns {number|null} Token delta or null if it is not found in the search window, in which case it should be considered invalid.
- */
- static validate({ token, secret, algorithm, digits, counter, window, }: {
- token: string;
- secret: Secret;
- algorithm?: string | undefined;
- digits: number;
- counter?: number | undefined;
- window?: number | undefined;
- }): number | null;
- /**
- * Creates an HOTP object.
- * @param {Object} [config] Configuration options.
- * @param {string} [config.issuer=''] Account provider.
- * @param {string} [config.label='OTPAuth'] Account label.
- * @param {boolean} [config.issuerInLabel=true] Include issuer prefix in label.
- * @param {Secret|string} [config.secret=Secret] Secret key.
- * @param {string} [config.algorithm='SHA1'] HMAC hashing algorithm.
- * @param {number} [config.digits=6] Token length.
- * @param {number} [config.counter=0] Initial counter value.
- */
- constructor({ issuer, label, issuerInLabel, secret, algorithm, digits, counter, }?: {
- issuer?: string | undefined;
- label?: string | undefined;
- issuerInLabel?: boolean | undefined;
- secret?: string | Secret | undefined;
- algorithm?: string | undefined;
- digits?: number | undefined;
- counter?: number | undefined;
- } | undefined);
- /**
- * Account provider.
- * @type {string}
- */
- issuer: string;
- /**
- * Account label.
- * @type {string}
- */
- label: string;
- /**
- * Include issuer prefix in label.
- * @type {boolean}
- */
- issuerInLabel: boolean;
- /**
- * Secret key.
- * @type {Secret}
- */
- secret: Secret;
- /**
- * HMAC hashing algorithm.
- * @type {string}
- */
- algorithm: string;
- /**
- * Token length.
- * @type {number}
- */
- digits: number;
- /**
- * Initial counter value.
- * @type {number}
- */
- counter: number;
- /**
- * Generates an HOTP token.
- * @param {Object} [config] Configuration options.
- * @param {number} [config.counter=this.counter++] Counter value.
- * @returns {string} Token.
- */
- generate({ counter }?: {
- counter?: number | undefined;
- } | undefined): string;
- /**
- * Validates an HOTP token.
- * @param {Object} config Configuration options.
- * @param {string} config.token Token value.
- * @param {number} [config.counter=this.counter] Counter value.
- * @param {number} [config.window=1] Window of counter values to test.
- * @returns {number|null} Token delta or null if it is not found in the search window, in which case it should be considered invalid.
- */
- validate({ token, counter, window }: {
- token: string;
- counter?: number | undefined;
- window?: number | undefined;
- }): number | null;
- /**
- * Returns a Google Authenticator key URI.
- * @returns {string} URI.
- */
- toString(): string;
- }
- /**
- * TOTP: Time-Based One-Time Password Algorithm.
- * @see [RFC 6238](https://tools.ietf.org/html/rfc6238)
- */
- declare class TOTP {
- /**
- * Default configuration.
- * @type {{
- * issuer: string,
- * label: string,
- * issuerInLabel: boolean,
- * algorithm: string,
- * digits: number,
- * period: number
- * window: number
- * }}
- */
- static get defaults(): {
- issuer: string;
- label: string;
- issuerInLabel: boolean;
- algorithm: string;
- digits: number;
- period: number;
- window: number;
- };
- /**
- * Generates a TOTP token.
- * @param {Object} config Configuration options.
- * @param {Secret} config.secret Secret key.
- * @param {string} [config.algorithm='SHA1'] HMAC hashing algorithm.
- * @param {number} [config.digits=6] Token length.
- * @param {number} [config.period=30] Token time-step duration.
- * @param {number} [config.timestamp=Date.now] Timestamp value in milliseconds.
- * @returns {string} Token.
- */
- static generate({ secret, algorithm, digits, period, timestamp }: {
- secret: Secret;
- algorithm?: string | undefined;
- digits?: number | undefined;
- period?: number | undefined;
- timestamp?: number | undefined;
- }): string;
- /**
- * Validates a TOTP token.
- * @param {Object} config Configuration options.
- * @param {string} config.token Token value.
- * @param {Secret} config.secret Secret key.
- * @param {string} [config.algorithm='SHA1'] HMAC hashing algorithm.
- * @param {number} config.digits Token length.
- * @param {number} [config.period=30] Token time-step duration.
- * @param {number} [config.timestamp=Date.now] Timestamp value in milliseconds.
- * @param {number} [config.window=1] Window of counter values to test.
- * @returns {number|null} Token delta or null if it is not found in the search window, in which case it should be considered invalid.
- */
- static validate({ token, secret, algorithm, digits, period, timestamp, window }: {
- token: string;
- secret: Secret;
- algorithm?: string | undefined;
- digits: number;
- period?: number | undefined;
- timestamp?: number | undefined;
- window?: number | undefined;
- }): number | null;
- /**
- * Creates a TOTP object.
- * @param {Object} [config] Configuration options.
- * @param {string} [config.issuer=''] Account provider.
- * @param {string} [config.label='OTPAuth'] Account label.
- * @param {boolean} [config.issuerInLabel=true] Include issuer prefix in label.
- * @param {Secret|string} [config.secret=Secret] Secret key.
- * @param {string} [config.algorithm='SHA1'] HMAC hashing algorithm.
- * @param {number} [config.digits=6] Token length.
- * @param {number} [config.period=30] Token time-step duration.
- */
- constructor({ issuer, label, issuerInLabel, secret, algorithm, digits, period, }?: {
- issuer?: string | undefined;
- label?: string | undefined;
- issuerInLabel?: boolean | undefined;
- secret?: string | Secret | undefined;
- algorithm?: string | undefined;
- digits?: number | undefined;
- period?: number | undefined;
- } | undefined);
- /**
- * Account provider.
- * @type {string}
- */
- issuer: string;
- /**
- * Account label.
- * @type {string}
- */
- label: string;
- /**
- * Include issuer prefix in label.
- * @type {boolean}
- */
- issuerInLabel: boolean;
- /**
- * Secret key.
- * @type {Secret}
- */
- secret: Secret;
- /**
- * HMAC hashing algorithm.
- * @type {string}
- */
- algorithm: string;
- /**
- * Token length.
- * @type {number}
- */
- digits: number;
- /**
- * Token time-step duration.
- * @type {number}
- */
- period: number;
- /**
- * Generates a TOTP token.
- * @param {Object} [config] Configuration options.
- * @param {number} [config.timestamp=Date.now] Timestamp value in milliseconds.
- * @returns {string} Token.
- */
- generate({ timestamp }?: {
- timestamp?: number | undefined;
- } | undefined): string;
- /**
- * Validates a TOTP token.
- * @param {Object} config Configuration options.
- * @param {string} config.token Token value.
- * @param {number} [config.timestamp=Date.now] Timestamp value in milliseconds.
- * @param {number} [config.window=1] Window of counter values to test.
- * @returns {number|null} Token delta or null if it is not found in the search window, in which case it should be considered invalid.
- */
- validate({ token, timestamp, window }: {
- token: string;
- timestamp?: number | undefined;
- window?: number | undefined;
- }): number | null;
- /**
- * Returns a Google Authenticator key URI.
- * @returns {string} URI.
- */
- toString(): string;
- }
- /**
- * HOTP/TOTP object/string conversion.
- * @see [Key URI Format](https://github.com/google/google-authenticator/wiki/Key-Uri-Format)
- */
- declare class URI {
- /**
- * Parses a Google Authenticator key URI and returns an HOTP/TOTP object.
- * @param {string} uri Google Authenticator Key URI.
- * @returns {HOTP|TOTP} HOTP/TOTP object.
- */
- static parse(uri: string): HOTP | TOTP;
- /**
- * Converts an HOTP/TOTP object to a Google Authenticator key URI.
- * @param {HOTP|TOTP} otp HOTP/TOTP object.
- * @returns {string} Google Authenticator Key URI.
- */
- static stringify(otp: HOTP | TOTP): string;
- }
- /**
- * Library version.
- * @type {string}
- */
- declare const version: string;
- export { HOTP, Secret, TOTP, URI, version };
|