otpauth
    Preparing search index...

    Class TOTP

    TOTP: Time-Based One-Time Password Algorithm.

    Index

    Constructors

    • Creates a TOTP object.

      Parameters

      • Optionalconfig: {
            algorithm?: string;
            digits?: number;
            issuer?: string;
            issuerInLabel?: boolean;
            label?: string;
            period?: number;
            secret?: string | Secret;
        } = {}

        Configuration options.

        • Optionalalgorithm?: string

          HMAC hashing algorithm.

        • Optionaldigits?: number

          Token length.

        • Optionalissuer?: string

          Account provider.

        • OptionalissuerInLabel?: boolean

          Include issuer prefix in label.

        • Optionallabel?: string

          Account label.

        • Optionalperiod?: number

          Token time-step duration.

        • Optionalsecret?: string | Secret

          Secret key.

      Returns TOTP

    Properties

    algorithm: string

    HMAC hashing algorithm.

    digits: number

    Token length.

    issuer: string

    Account provider.

    issuerInLabel: boolean

    Include issuer prefix in label.

    label: string

    Account label.

    period: number

    Token time-step duration.

    secret: Secret

    Secret key.

    Accessors

    • get defaults(): {
          algorithm: string;
          digits: number;
          issuer: string;
          issuerInLabel: boolean;
          label: string;
          period: number;
          window: number;
      }

      Default configuration.

      Returns {
          algorithm: string;
          digits: number;
          issuer: string;
          issuerInLabel: boolean;
          label: string;
          period: number;
          window: number;
      }

    Methods

    • Calculates the counter. i.e. the number of periods since timestamp 0.

      Parameters

      • Optionalconfig: { timestamp?: number } = {}

        Configuration options.

        • Optionaltimestamp?: number

          Timestamp value in milliseconds.

      Returns number

      Counter.

    • Generates a TOTP token.

      Parameters

      • Optionalconfig: { timestamp?: number } = {}

        Configuration options.

        • Optionaltimestamp?: number

          Timestamp value in milliseconds.

      Returns string

      Token.

    • Calculates the remaining time in milliseconds until the next token is generated.

      Parameters

      • Optionalconfig: { timestamp?: number } = {}

        Configuration options.

        • Optionaltimestamp?: number

          Timestamp value in milliseconds.

      Returns number

      counter.

    • Returns a Google Authenticator key URI.

      Returns string

      URI.

    • Validates a TOTP token.

      Parameters

      • config: { timestamp?: number; token: string; window?: number }

        Configuration options.

        • Optionaltimestamp?: number

          Timestamp value in milliseconds.

        • token: string

          Token value.

        • Optionalwindow?: number

          Window of counter values to test.

      Returns null | number

      Token delta or null if it is not found in the search window, in which case it should be considered invalid.

    • Calculates the counter. i.e. the number of periods since timestamp 0.

      Parameters

      • Optionalconfig: { period?: number; timestamp?: number } = {}

        Configuration options.

        • Optionalperiod?: number

          Token time-step duration.

        • Optionaltimestamp?: number

          Timestamp value in milliseconds.

      Returns number

      Counter.

    • Generates a TOTP token.

      Parameters

      • config: {
            algorithm?: string;
            digits?: number;
            period?: number;
            secret: Secret;
            timestamp?: number;
        }

        Configuration options.

        • Optionalalgorithm?: string

          HMAC hashing algorithm.

        • Optionaldigits?: number

          Token length.

        • Optionalperiod?: number

          Token time-step duration.

        • secret: Secret

          Secret key.

        • Optionaltimestamp?: number

          Timestamp value in milliseconds.

      Returns string

      Token.

    • Calculates the remaining time in milliseconds until the next token is generated.

      Parameters

      • Optionalconfig: { period?: number; timestamp?: number } = {}

        Configuration options.

        • Optionalperiod?: number

          Token time-step duration.

        • Optionaltimestamp?: number

          Timestamp value in milliseconds.

      Returns number

      counter.

    • Validates a TOTP token.

      Parameters

      • config: {
            algorithm?: string;
            digits?: number;
            period?: number;
            secret: Secret;
            timestamp?: number;
            token: string;
            window?: number;
        }

        Configuration options.

        • Optionalalgorithm?: string

          HMAC hashing algorithm.

        • Optionaldigits?: number

          Token length.

        • Optionalperiod?: number

          Token time-step duration.

        • secret: Secret

          Secret key.

        • Optionaltimestamp?: number

          Timestamp value in milliseconds.

        • token: string

          Token value.

        • Optionalwindow?: number

          Window of counter values to test.

      Returns null | number

      Token delta or null if it is not found in the search window, in which case it should be considered invalid.