A library to generate TOTP and HOTP tokens.
import {totp} from "@bytekit/totp";
const result = await totp("JBSWY3DPEHPK3PXP");
console.log(result);
Example output of the above:
{
expires: 1736638440,
token: "482223",
previous: "534333",
next: "291802"
}
The totp
method generates a time-based one-time password along with expiration, previous, and next values.
totp(options)
options
An ITotpOptions object containing the key and other options used for generating the token.
Returns an ITotpToken object containing the token, expiration, next, and previous values.
import {totp} from "@bytekit/totp";
const result = await totp("JBSWY3DPEHPK3PXP");
console.log(result);
Example output of the above:
{
expires: 1736638440,
token: "482223",
previous: "534333",
next: "291802"
}
An object containing the key and other options used for generating TOTP tokens.
key
string | Uint8Array The key used to generate the token.
digits
number Optional. The number of digits to include in the token. Default is 6.
algorithm
string Optional. The hashing algorithm to use. Can be one of SHA-1
; SHA-256
; SHA-384
; or SHA-512
. Default is SHA-1
.
period
number Optional. The time period, in seconds, for token generation. Default is 30 seconds.
timestamp
number Optional. The unix epoch (seconds since Jan 1, 1970) to use for token generation. Default is the current unix epoch.
An object containing the token, expiration, next, and previous values from a call to the totp
method.
token
string The generated TOTP token.
expires
number The unix epoch at which point the token is no longer valid.
next
string The TOTP token that will be valid for the time period following the current time period.
previous
string The TOTP token that was valid for the time period preceding the current time period.