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.5.4 | development |
eslintEnvironment{
"local_name": "eslint",
"alias": false,
"peer_metadata": null
} | ^6.8.0 | development |
lodashEnvironment{
"local_name": "lodash",
"alias": false,
"peer_metadata": null
} | ^4.17.20 | development |
codecovEnvironment{
"local_name": "codecov",
"alias": false,
"peer_metadata": null
} | ^3.7.2 | development |
ts-jestEnvironment{
"local_name": "ts-jest",
"alias": false,
"peer_metadata": null
} | ^25.5.1 | development |
typedocEnvironment{
"local_name": "typedoc",
"alias": false,
"peer_metadata": null
} | ^0.17.8 | development |
typescriptEnvironment{
"local_name": "typescript",
"alias": false,
"peer_metadata": null
} | ^3.9.7 | development |
@types/jestEnvironment{
"local_name": "@types/jest",
"alias": false,
"peer_metadata": null
} | ^25.2.3 | development |
@types/nodeEnvironment{
"local_name": "@types/node",
"alias": false,
"peer_metadata": null
} | ^13.13.21 | development |
eslint-plugin-jestEnvironment{
"local_name": "eslint-plugin-jest",
"alias": false,
"peer_metadata": null
} | ^23.20.0 | development |
eslint-plugin-importEnvironment{
"local_name": "eslint-plugin-import",
"alias": false,
"peer_metadata": null
} | ^2.22.1 | development |
@typescript-eslint/parserEnvironment{
"local_name": "@typescript-eslint/parser",
"alias": false,
"peer_metadata": null
} | ^2.34.0 | development |
eslint-config-airbnb-baseEnvironment{
"local_name": "eslint-config-airbnb-base",
"alias": false,
"peer_metadata": null
} | ^14.2.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.34.0 | development |
Source distribution
{
"shasum": "efac698122149ba72a65334c2c230994c62d572a",
"tarball": "https://registry.npmjs.org/2fa-utils/-/2fa-utils-1.1.8.tgz",
"fileCount": 8,
"integrity": "sha512-R2PTPbJ6kLzYb/kvSlM6qggYmIW+bLSVes5NpLdF7tmEiabP/CpFrECG27YWle2o+K38hIyeJioxNxf9WeeBvQ==",
"signatures": [
{
"sig": "MEQCIG0hG5Vyy1d5c4jbwKprJVqvhmoHfqKZ+sjefO5TfhFIAiAlrbS/wFmOsz7yOrG/Qy7dh6IJO2nEycmc1y41juV/7w==",
"keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"
}
],
"unpackedSize": 17158,
"npm-signature": "-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJglmlpCRA9TVsSAnZWagAAe2IQAJu/BVw0PRh74ma4vbvk\ngUFdmjXV5Jq0qzd9g8izDd9HiJG8ORp4zrpFeUsN+8S/sTMxE6h3MU+JLSx6\nZg5WhjoPyBSq49cl+MxRN4Q3u8DEl5AvkjPck+NJYM78aFM270C4f4+Gcn9K\n2aSH0Iww9FTmHWhqwQQ9x92HwkEYE2ZoQKEGJ6fRzFp92qBIP7z9oWSRRcIv\n1XMG1fUu3ohC2pk3+XRjCN5idNLdquppT7Z0gWxsOEp5IkVIERtXL1sHEs2g\nroNqedyVCpUggF5gv43J4Qp2hSAglGm3OtDYakhPq0K+qmtroUlDPgxzgjS+\nSRZNji4UXOuELxnnhrXf9zl3VO6S8qPvghjleAlAD8kt8O12S717JWc6imie\nX/Io7m/TFVICD1R+KHdgo3Y7ABRY6qhYlla8ho/qrjv5m+5HcYgS8jTbk+of\nE0jqfFPKgxxHrIeDYyJt5Chu63jzPY56l9K8I23ZdU2BSj3C/CUKLx9QP1nR\nQitQKb9+K9kseJ9q4WQlpSv81ZBjDP40ghADJwuObZ6xNxooDCGYUvyb2+Bs\nPlpTy3ALFOQaEy8sh6FuN7w8jj6bTyPE5g4LwNNMeYa4wNyzK8EXx1TriCfj\n1a+W39qU8UnPMzY6GVbTfSjt7nRCzXip+azT6gpkgFgBd9zcDqnxi3E/BAbr\nJpj9\r\n=qbtr\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:af5cc7cf20879d4b10c32b94c945f05eebd23ed04bae484dbf9326ec0b4ea1b4