Skip to content

otplib API Documentation / @otplib/totp / TOTPOptions

Type Alias: TOTPOptions

TOTPOptions = object

Defined in: totp/src/types.ts:23

TOTP configuration options

All properties are optional for flexible class-based configuration. Use TOTPGenerateOptions or TOTPVerifyOptions for function parameters where certain fields are required.

Properties

algorithm?

readonly optional algorithm?: HashAlgorithm

Defined in: totp/src/types.ts:40

Hash algorithm to use (default: 'sha1')


base32?

readonly optional base32?: Base32Plugin

Defined in: totp/src/types.ts:46

Base32 plugin to decode string secrets (required if secret is a string)


crypto?

readonly optional crypto?: CryptoPlugin

Defined in: totp/src/types.ts:44

Crypto plugin to use for HMAC operations


digits?

readonly optional digits?: Digits

Defined in: totp/src/types.ts:42

Number of digits in the OTP code (default: 6)


epoch?

readonly optional epoch?: number

Defined in: totp/src/types.ts:27

Current Unix epoch timestamp in seconds (default: Date.now() / 1000)


guardrails?

readonly optional guardrails?: OTPGuardrails

Defined in: totp/src/types.ts:56

Custom guardrails to override validation limits Must be created via createGuardrails() factory Use this carefully - see danger-zone documentation


hooks?

readonly optional hooks?: OTPHooks

Defined in: totp/src/types.ts:62

Hooks for customizing token encoding and validation. Allows non-standard OTP variants (e.g., Steam Guard) to replace the default numeric encoding with custom schemes.


issuer?

readonly optional issuer?: string

Defined in: totp/src/types.ts:48

Service provider name (for URI generation)


label?

readonly optional label?: string

Defined in: totp/src/types.ts:50

User identifier/email/username (for URI generation)


period?

readonly optional period?: number

Defined in: totp/src/types.ts:38

Time step in seconds (default: 30)


secret?

readonly optional secret?: string | Uint8Array

Defined in: totp/src/types.ts:25

The shared secret key (Base32-encoded string or raw bytes)


t0?

readonly optional t0?: number

Defined in: totp/src/types.ts:36

Initial Unix time to start counting time steps (default: 0)

Per RFC 6238, T0 is the Unix time from which to start counting. Most implementations use 0, but some systems may use a different start time.

Formula: counter = floor((epoch - t0) / period)

Released under the MIT License.