Observed since 20 Oct, 19:12 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
2fa-utils
TOTP and HOTP utilities.
Using the algorithm provided in RFC 4226, can generate and verify HMAC-based one-time password (HOTP) and time-based one-time password (TOTP).
For each account, a secret must be generated and shared between the server and the client. This secret will be used to create and verify HOTPs.
const secret = twoFA.generateSecret();
HOTP requires a base32-encoded secret and a counter with time-step.
// Generate base32 secret
const secret = twoFA.generateSecret();
// Create counter with 30 seconds interval
const counter = Math.floor(Date.now() / 30000);
const hotp = twoFA.generateHOTP(secret, counter, 6)
Generating TOTP allows you to get a HOTP in a specific time window.
const secret = twoFA.generateSecret();
// Get the current time window's token
const currentTotp = twoFA.generateTOTP(secret, 0);
// Get the future time window's token (1 window ahead)
const futureTotp = twoFA.generateTOTP(secret, 1);
// Get the past time window's token (1 window behind)
const pastTotp = twoFA.generateTOTP(secret, -1);
Verify tokens supplied via user input.
function verifyHOTP(inputToken) {
const secret = twoFA.generateSecret();
const counter = Math.floor(Date.now() / 30000);
// Actual token generated by the server
const actualToken = twoFA.generateHOTP(secret, counter)
if (inputToken === actualToken) return true;
return false
}
Verify tokens supploed via user input with a time tolerance.
const secret = twoFA.generateSecret();
const inputToken = '111111';
/* This will return true if the input token
- is currently valid,
- was previously valid in the last window,
- will be valid in the next window.
*/
const isTokenValid = twoFA.verifyTOTP(inputToken, secret, 1);
This project is licensed under the MIT License - see the LICENSE file for details.
Download counts and popularity will appear here as the collector receives them.
| Package / target | Requirement | Relationship |
|---|---|---|
hi-base32Environment{
"local_name": "hi-base32",
"alias": false,
"peer_metadata": null
} | ^0.5.0 | runtime |
jestEnvironment{
"local_name": "jest",
"alias": false,
"peer_metadata": null
} | ^25.3.0 | development |
eslintEnvironment{
"local_name": "eslint",
"alias": false,
"peer_metadata": null
} | ^6.8.0 | development |
codecovEnvironment{
"local_name": "codecov",
"alias": false,
"peer_metadata": null
} | ^3.6.5 | development |
ts-jestEnvironment{
"local_name": "ts-jest",
"alias": false,
"peer_metadata": null
} | ^25.3.1 | development |
typedocEnvironment{
"local_name": "typedoc",
"alias": false,
"peer_metadata": null
} | ^0.17.3 | development |
typescriptEnvironment{
"local_name": "typescript",
"alias": false,
"peer_metadata": null
} | ^3.8.3 | development |
@types/jestEnvironment{
"local_name": "@types/jest",
"alias": false,
"peer_metadata": null
} | ^25.2.1 | development |
@types/nodeEnvironment{
"local_name": "@types/node",
"alias": false,
"peer_metadata": null
} | ^13.11.0 | development |
eslint-plugin-jestEnvironment{
"local_name": "eslint-plugin-jest",
"alias": false,
"peer_metadata": null
} | ^23.8.2 | development |
eslint-plugin-importEnvironment{
"local_name": "eslint-plugin-import",
"alias": false,
"peer_metadata": null
} | ^2.20.2 | development |
@typescript-eslint/parserEnvironment{
"local_name": "@typescript-eslint/parser",
"alias": false,
"peer_metadata": null
} | ^2.26.0 | development |
eslint-config-airbnb-baseEnvironment{
"local_name": "eslint-config-airbnb-base",
"alias": false,
"peer_metadata": null
} | ^14.1.0 | development |
eslint-config-airbnb-typescriptEnvironment{
"local_name": "eslint-config-airbnb-typescript",
"alias": false,
"peer_metadata": null
} | ^7.2.0 | development |
@typescript-eslint/eslint-pluginEnvironment{
"local_name": "@typescript-eslint/eslint-plugin",
"alias": false,
"peer_metadata": null
} | ^2.26.0 | development |
Source distribution
{
"shasum": "4a7bfc7be73c15ece783277bfa151bf40dca3d80",
"tarball": "https://registry.npmjs.org/2fa-utils/-/2fa-utils-1.1.1.tgz",
"fileCount": 12,
"integrity": "sha512-BJuXt5FnN0oqxJDvyyjLlqBePvUkOHCkoBgRpX5xPsT+ft5mrueqFm1jCNCvwOJ9iozzJpqfBxGfbOcxXCqBHg==",
"signatures": [
{
"sig": "MEUCIQCSnNL3DE6wtPpOX966H26lntgcXzX7FLAbyLKGgfOs4gIgd3hPfMVaOW0FKTISl6VbfHT19sn5xH4K+Vz4CAuhHyw=",
"keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"
}
],
"unpackedSize": 20179,
"npm-signature": "-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJenGdsCRA9TVsSAnZWagAA4P8P/jxGfLrrfDrZEUjqwgPf\nPiY0XDiNGJbxkEOfPaYC9pA8vOpwpzt1+73QyjEEu9kHOYLIWSOWBVDULYxY\ni/r8LZln6yak2fT/x+ogFUflZmANyDpQvCPt4vbQighBckRZ0AfET0wUNzpW\n9DTyblnkP2iU99QomeoI1Tr8NKc0ldV0P/n7jexKiTvi9jm3YQyEryktaPW2\nQ6LLUB+TJ1NHTDuBd/HDfF3wRWLjEkak2xHezupS3HB6ybVIa6zXlBmO4eaI\ntxOBtyblXWi9vP5BTlVMKzjcRkFQ5+SBQGz8Mxtm32okuWhrtk2p8qQ+agk4\n8GluIfjvUj3QfzTDGvMtN4fP5Sjtdlaxezh02yScei2nVtakPlQrEjTWYUx0\ncwnitfxCHrSNYm5vYazqXFaZLJYl1xF2Ffu3yCjZoixhN7eQBTTLdLm1NFCf\n8+vB+uHSKNmQf9CMsTM6+JAuM8kVmvEVMgGO/g8wql9eMmPSUjyv8gmWd7Hw\n86lXdBBwIZWTEbUsLbZTMwpNNdAxzlCIm/l8xgRllqy0yaX6z5bGy1A6GDTZ\n5UL7rGseixa/V2N1Xu/yooRjaGXOd7Za+mbPntRQmZdxEW8sA9WLTFQ6jCTk\nRoxmYB4zbhjNuBQT1F8Q5reWcLPuYRo/GyjJRSSUcoDuDygH/rroB6tur4jw\ns42P\r\n=Ofki\r\n-----END PGP SIGNATURE-----\r\n"
}Shared repository data · GitHub
Public sponsor counts have not been collected. These signals belong to the repository owner.
github · 1 observations shown. Missing days are unknown.
| Date / source period | Value | Observed at |
|---|---|---|
| 2026-10-21 | 3 | 2026-10-21T11:29:11.1849273Z |
Observed since 20 Oct, 19:12 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package_version:60b735972d29318f8a38f9e431dffbcd66307ec83028339a397c2a7fb9c471be