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
} | ^27.1.0 | development |
eslintEnvironment{
"local_name": "eslint",
"alias": false,
"peer_metadata": null
} | ^7.32.0 | development |
lodashEnvironment{
"local_name": "lodash",
"alias": false,
"peer_metadata": null
} | ^4.17.21 | development |
codecovEnvironment{
"local_name": "codecov",
"alias": false,
"peer_metadata": null
} | ^3.8.3 | development |
ts-jestEnvironment{
"local_name": "ts-jest",
"alias": false,
"peer_metadata": null
} | ^27.0.5 | development |
typescriptEnvironment{
"local_name": "typescript",
"alias": false,
"peer_metadata": null
} | ^4.4.2 | development |
@types/jestEnvironment{
"local_name": "@types/jest",
"alias": false,
"peer_metadata": null
} | ^27.0.1 | development |
@types/nodeEnvironment{
"local_name": "@types/node",
"alias": false,
"peer_metadata": null
} | ^16.7.10 | development |
@typescript-eslint/parserEnvironment{
"local_name": "@typescript-eslint/parser",
"alias": false,
"peer_metadata": null
} | ^4.30.0 | development |
@typescript-eslint/eslint-pluginEnvironment{
"local_name": "@typescript-eslint/eslint-plugin",
"alias": false,
"peer_metadata": null
} | ^4.30.0 | development |
Source distribution
{
"shasum": "3478b0446110304ecb1c72960ff724ffe3e2c1e0",
"tarball": "https://registry.npmjs.org/2fa-utils/-/2fa-utils-1.2.3.tgz",
"fileCount": 6,
"integrity": "sha512-qMj5ksG837CFgJcTJ5xpiOQmbyXvGqSUudxUmGeRkk+Rggap9hejQgdGFUNNoPW6DFnnkc1pbwmZcQsKiUyEWg==",
"signatures": [
{
"sig": "MEUCIQDUJR2ItJ5v/HiUDviMG95IwuHgpZvPooN4FwxN0vc9FQIgdqlfK6kcr5UL/ZLWSHauqJoekwFBq6W1AQdsyKvBA+g=",
"keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"
}
],
"unpackedSize": 15221,
"npm-signature": "-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiGRp1ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrgJxAAod2pr01Fm9+BQ4zxuhKcqdWcuTve9rPFggALyVyrfjZYI0Ji\r\n5tCETBo2qxhL8wjKpnM2rm9wmkqm7W1QHQKmxP5WOXmR1CiicCHudoGu9ZRI\r\ny06XxnfJuPpSAw64h6LnmKoxGnI6KisySdXy/SQd3EG61ayFC14Y5wFA6Q6s\r\nzH4WKbBIOoGDnMuBJ5YpOjpWNX9CYb1g6dck4c5ZmajMS8LERORKlM6Su6DC\r\n14jkpCvGB2DP00VhwP6TLb5BPOUSBpwm/vzrecT6yArZ2SXtxDzU2C4sNtyG\r\n8Ze/sP6invVSLSDyBhN6LsHM4PKE/0si++cw6gMAqmW4XlGqDYq9ePwwTa6R\r\noKz02JhKKYVhAmeOgJmhuZbmxw3LG0YPRG2kHmOUeJaQ6UPWCilhqw3D6pd9\r\nyySNzzM8JMBzJvpAjpQ+R1v8Ud6safqADwMER+POTAYre3eMUwcXkGrdVjYl\r\nvRdO8aqAug8NdfkbQ3mqREpBTbBwWOTF98dFqsr4pyyunQR6erhxXF6tZcqA\r\n9tnSvehWC+gFuF7fmVJ20PcP6kHihT8552JV0Zz0UD1mXPeqcObjkQnYi1GW\r\npV7yyFK8qnjIl161DuMj455gF8rhyyW2S7jos5Uz/xphgY7TcOf3w3Pi2riF\r\nFnR00pMGBX8pCEknBRhDsYnMwqythUT8pQ4=\r\n=jqh5\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:c3c42bb6391bb238ba924c72fcf3ca24a4f258ae2fcad2457be75f0d0c479ecb