{"_id":"2fa-node","_rev":"5-3fc039558ae21cb1171447280ffa002f","name":"2fa-node","dist-tags":{"latest":"0.0.6"},"versions":{"0.0.1":{"name":"2fa-node","version":"0.0.1","keywords":["totp","hotp","otp","authenticator","one time password","google authenticator","authentication","2FA","2 factor","node","auth","2fa","mfa"],"author":{"name":"Lucas Lima Finoti","email":"lucas.finoti@protonmail.com"},"license":"MIT","_id":"2fa-node@0.0.1","maintainers":[{"name":"finotilucas","email":"lucas.finoti@protonmail.com"}],"dist":{"shasum":"7c49a59169b1ee7d612ba862e962d2ce43c01dd2","tarball":"https://registry.npmjs.org/2fa-node/-/2fa-node-0.0.1.tgz","fileCount":17,"integrity":"sha512-mUQgc6R072bNaklroD4oWSbqmGhZCPZg6mdHVFZUady68aDCuLoX7QbdErQOF//jztTV29bAxGKyR99Dtg5KfA==","signatures":[{"sig":"MEUCIQCQc3bnHXBvcon1drzXxoFagJPARKAmdp5QefQHKfRBMgIgRnLJ70n1bJVGm2txmyPoky9xjln00I1f24OzPXWx0VA=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":21502},"main":"dist/index.js","type":"module","types":"dist/index.d.ts","gitHead":"0d87834523c8d6de84e191445fb4e9ee58b571d6","scripts":{"lint":"npx eslint ./lib/**","test":"node --loader ts-node/esm --enable-source-maps bin/test.ts","build":"tsc","prepare":"npm run build","lint:fix":"npx eslint ./lib/** --fix","prepublishOnly":"npm test"},"_npmUser":{"name":"finotilucas","email":"lucas.finoti@protonmail.com"},"_npmVersion":"10.9.2","description":"Easy 2-Factor Integration For Node.js","directories":{},"_nodeVersion":"20.12.2","dependencies":{"otplib":"^12.0.1","qrcode":"^1.5.4"},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.19.2","eslint":"^9.17.0","globals":"^15.14.0","ts-node":"^10.9.2","prettier":"^3.4.2","@eslint/js":"^9.17.0","typescript":"^5.7.3","@types/node":"^22.10.5","@japa/assert":"^4.0.1","@japa/expect":"^3.0.3","@japa/runner":"^4.1.0","@types/qrcode":"^1.5.5","@japa/expect-type":"^2.0.3","typescript-eslint":"^8.19.1"},"_npmOperationalInternal":{"tmp":"tmp/2fa-node_0.0.1_1736535856417_0.6739559045345733","host":"s3://npm-registry-packages-npm-production"}},"0.0.2":{"name":"2fa-node","version":"0.0.2","keywords":["totp","hotp","otp","authenticator","one time password","google authenticator","authentication","2FA","2 factor","node","auth","2fa","mfa"],"author":{"name":"Lucas Lima Finoti","email":"lucas.finoti@protonmail.com"},"license":"MIT","_id":"2fa-node@0.0.2","maintainers":[{"name":"finotilucas","email":"lucas.finoti@protonmail.com"}],"dist":{"shasum":"f0237645da12629b446216d51d4fd10d8756dce8","tarball":"https://registry.npmjs.org/2fa-node/-/2fa-node-0.0.2.tgz","fileCount":14,"integrity":"sha512-39BH68zz1Z3BZvFahIARFUG/j3dvma6AvUVE6O+1yQhDOB6FsptcckFpeQzq71F7/g8ZzYSgd6HYQYyeVbo+mA==","signatures":[{"sig":"MEYCIQCITpnPP/INgNPFprJF3Crw4IzldxWHouWLUUKhErGRwQIhAKim3cmJjy3dGSo0mgCo2zXvwGglrMUzsMc81FJdOOU7","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":19333},"main":"dist/index.js","type":"module","types":"dist/index.d.ts","gitHead":"2a96032ccf9f583d4e43ad031dec22968e65c714","scripts":{"lint":"npx eslint ./lib/**","test":"node --loader ts-node/esm --enable-source-maps bin/test.ts","build":"rimraf dist && tsc","prepare":"npm run build","lint:fix":"npx eslint ./lib/** --fix","prepublishOnly":"npm test"},"_npmUser":{"name":"finotilucas","email":"lucas.finoti@protonmail.com"},"_npmVersion":"10.9.2","description":"Easy 2-Factor Integration For Node.js","directories":{},"_nodeVersion":"20.12.2","dependencies":{"otplib":"^12.0.1","qrcode":"^1.5.4"},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.19.2","eslint":"^9.17.0","rimraf":"^6.0.1","globals":"^15.14.0","ts-node":"^10.9.2","prettier":"^3.4.2","@eslint/js":"^9.17.0","typescript":"^5.7.3","@types/node":"^22.10.5","@japa/assert":"^4.0.1","@japa/expect":"^3.0.3","@japa/runner":"^4.1.0","@types/qrcode":"^1.5.5","@japa/expect-type":"^2.0.3","typescript-eslint":"^8.19.1"},"_npmOperationalInternal":{"tmp":"tmp/2fa-node_0.0.2_1736537643057_0.5526056686898642","host":"s3://npm-registry-packages-npm-production"}},"0.0.3":{"name":"2fa-node","version":"0.0.3","keywords":["totp","hotp","otp","authenticator","one time password","google authenticator","authentication","2FA","2 factor","node","auth","2fa","mfa"],"author":{"name":"Lucas Lima Finoti","email":"lucas.finoti@protonmail.com"},"license":"MIT","_id":"2fa-node@0.0.3","maintainers":[{"name":"finotilucas","email":"lucas.finoti@protonmail.com"}],"homepage":"https://github.com/FinotiLucas/2fa-node#readme","bugs":{"url":"https://github.com/FinotiLucas/2fa-node/issues"},"dist":{"shasum":"1a5872592a6d4b1312cf83157cfed28b8076396a","tarball":"https://registry.npmjs.org/2fa-node/-/2fa-node-0.0.3.tgz","fileCount":14,"integrity":"sha512-SJLOlg96ewiAKFBKvJ83HGakJw9CiA9n4xgU+ej9mI55okWCxq5mi58uVSlieJ/lKSHZkwYUlL48tNs1M+rfSw==","signatures":[{"sig":"MEQCIBu96xqn0Pn0vxsdroydCoijYyK6S9YJjUmDBSYaqnHtAiAEz3KRuXMU1JfP2Sie1vouFA6Eiy/MF95v+CbFy15F2w==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":19280},"main":"dist/index.js","type":"module","types":"dist/index.d.ts","gitHead":"7897c63526cae0b9d74468731ebeefbd9cf39f42","scripts":{"lint":"npx eslint ./lib/**","test":"node --loader ts-node/esm --enable-source-maps bin/test.ts","build":"rimraf dist && tsc","prepare":"npm run build","lint:fix":"npx eslint ./lib/** --fix","prepublishOnly":"npm test"},"_npmUser":{"name":"finotilucas","email":"lucas.finoti@protonmail.com"},"repository":{"url":"git+https://github.com/FinotiLucas/2fa-node.git","type":"git"},"_npmVersion":"10.9.2","description":"Easy 2-Factor Integration For Node.js","directories":{},"_nodeVersion":"20.12.2","dependencies":{"otplib":"^12.0.1","qrcode":"^1.5.4"},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.19.2","eslint":"^9.17.0","rimraf":"^6.0.1","globals":"^15.14.0","ts-node":"^10.9.2","prettier":"^3.4.2","@eslint/js":"^9.17.0","typescript":"^5.7.3","@types/node":"^22.10.5","@japa/assert":"^4.0.1","@japa/expect":"^3.0.3","@japa/runner":"^4.1.0","@types/qrcode":"^1.5.5","@japa/expect-type":"^2.0.3","typescript-eslint":"^8.19.1"},"_npmOperationalInternal":{"tmp":"tmp/2fa-node_0.0.3_1736540298596_0.04523150175367663","host":"s3://npm-registry-packages-npm-production"}},"0.0.4":{"name":"2fa-node","version":"0.0.4","keywords":["totp","hotp","otp","authenticator","one time password","google authenticator","authentication","2FA","2 factor","node","auth","2fa","mfa"],"author":{"name":"Lucas Lima Finoti","email":"lucas.finoti@protonmail.com"},"license":"MIT","_id":"2fa-node@0.0.4","maintainers":[{"name":"finotilucas","email":"lucas.finoti@protonmail.com"}],"homepage":"https://github.com/FinotiLucas/2fa-node#readme","bugs":{"url":"https://github.com/FinotiLucas/2fa-node/issues"},"dist":{"shasum":"b6c55dd7287308c94b48931deeba9e515207c212","tarball":"https://registry.npmjs.org/2fa-node/-/2fa-node-0.0.4.tgz","fileCount":20,"integrity":"sha512-Bs1krb3qWY6KUmOf8nyRTEhl3l/Tom9GwxN6VijIFT6aA9EPcvhDFgkOOoM//hK/poxUTKE4udPLE4us9YdTtA==","signatures":[{"sig":"MEYCIQCBT5ytf6PqQb2vqjs3i5f6hd2NgyTyUCsCZhl1CDmSPgIhAJTtJg/nnjmMECa3URS2uTRt/r+8qJ+41Ph3eaiCUvdb","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":22529},"main":"dist/index.js","type":"module","types":"dist/index.d.ts","gitHead":"9a9748b71961466f8fbb032985cc83a222dacd52","scripts":{"lint":"npx eslint ./lib/**","test":"node --loader ts-node/esm --enable-source-maps bin/test.ts","build":"rimraf dist && tsc","prepare":"npm run build","lint:fix":"npx eslint ./lib/** --fix","prepublishOnly":"npm test"},"_npmUser":{"name":"finotilucas","email":"lucas.finoti@protonmail.com"},"repository":{"url":"git+https://github.com/FinotiLucas/2fa-node.git","type":"git"},"_npmVersion":"10.8.3","description":"Easy 2-Factor Integration For Node.js","directories":{},"_nodeVersion":"20.15.0","dependencies":{"otplib":"^12.0.1","qrcode":"^1.5.4"},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.19.2","eslint":"^9.17.0","rimraf":"^6.0.1","globals":"^15.14.0","ts-node":"^10.9.2","prettier":"^3.4.2","@eslint/js":"^9.17.0","typescript":"^5.7.3","@types/node":"^22.10.5","@japa/assert":"^4.0.1","@japa/expect":"^3.0.3","@japa/runner":"^4.1.0","@types/qrcode":"^1.5.5","@japa/expect-type":"^2.0.3","typescript-eslint":"^8.19.1"},"_npmOperationalInternal":{"tmp":"tmp/2fa-node_0.0.4_1736611440986_0.4783231799724217","host":"s3://npm-registry-packages-npm-production"}},"0.0.5":{"name":"2fa-node","version":"0.0.5","keywords":["totp","hotp","otp","authenticator","one time password","google authenticator","authentication","2FA","2 factor","node","auth","2fa","mfa"],"author":{"name":"Lucas Lima Finoti","email":"lucas.finoti@protonmail.com"},"license":"MIT","_id":"2fa-node@0.0.5","maintainers":[{"name":"finotilucas","email":"lucas.finoti@protonmail.com"}],"homepage":"https://github.com/FinotiLucas/2fa-node#readme","bugs":{"url":"https://github.com/FinotiLucas/2fa-node/issues"},"dist":{"shasum":"989b3485fbc1b305466dbf7b07e0aba8497071a2","tarball":"https://registry.npmjs.org/2fa-node/-/2fa-node-0.0.5.tgz","fileCount":21,"integrity":"sha512-NOEaNyxo9jx2lSJBlxLK2eDX1EfELqI3zFeNAMrC8S+I+gl+Dkw1KG4hj8bD2YbKGYaE5wFOTtBNr67SCXtmUQ==","signatures":[{"sig":"MEUCIQC9KDMLjJQ0WEONomjr7CsiRTWwS7qjFYvj2M+rW4D9owIgSGrzR0/hjJzPO6q09ipkU65oFHs7zL/fOLE8yqaLygA=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":25039},"main":"dist/index.js","type":"module","types":"dist/index.d.ts","gitHead":"0d23979538d5f53d5d7f105282013e01e8a3d4ea","scripts":{"lint":"npx eslint ./lib/**","test":"node --loader ts-node/esm --enable-source-maps bin/test.ts","build":"rimraf dist && tsc","prepare":"npm run build","lint:fix":"npx eslint ./lib/** --fix","prepublishOnly":"npm test"},"_npmUser":{"name":"finotilucas","email":"lucas.finoti@protonmail.com"},"repository":{"url":"git+https://github.com/FinotiLucas/2fa-node.git","type":"git"},"_npmVersion":"10.8.3","description":"Easy 2-Factor Integration For Node.js","directories":{},"_nodeVersion":"20.15.0","dependencies":{"otplib":"^12.0.1","qrcode":"^1.5.4"},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.19.2","eslint":"^9.17.0","rimraf":"^6.0.1","globals":"^15.14.0","ts-node":"^10.9.2","prettier":"^3.4.2","@eslint/js":"^9.17.0","typescript":"^5.7.3","@types/node":"^22.10.5","@japa/assert":"^4.0.1","@japa/expect":"^3.0.3","@japa/runner":"^4.1.0","@types/qrcode":"^1.5.5","@japa/expect-type":"^2.0.3","typescript-eslint":"^8.19.1"},"_npmOperationalInternal":{"tmp":"tmp/2fa-node_0.0.5_1737129534860_0.9715178555486459","host":"s3://npm-registry-packages-npm-production"}},"0.0.6":{"name":"2fa-node","version":"0.0.6","main":"dist/index.js","types":"dist/index.d.ts","repository":{"type":"git","url":"git+https://github.com/FinotiLucas/2fa-node.git"},"scripts":{"build":"rimraf dist && tsc","prepare":"npm run build","prepublishOnly":"npm test","test":"node --loader ts-node/esm --enable-source-maps bin/test.ts","format":"prettier --write .","lint":"npx eslint ./lib/**","lint:fix":"npx eslint ./lib/** --fix","typecheck":"tsc --noEmit"},"keywords":["totp","hotp","otp","authenticator","one time password","google authenticator","authentication","2FA","2 factor","node","auth","2fa","mfa"],"author":{"name":"Lucas Lima Finoti","email":"lucas.finoti@protonmail.com"},"license":"MIT","description":"Easy 2-Factor Integration For Node.js","devDependencies":{"@eslint/js":"^9.18.0","@japa/assert":"^4.0.1","@japa/expect":"^3.0.3","@japa/expect-type":"^2.0.3","@japa/runner":"^4.1.0","@types/node":"^22.10.7","@types/qrcode":"^1.5.5","eslint":"^9.18.0","globals":"^15.14.0","prettier":"^3.4.2","rimraf":"^6.0.1","ts-node":"^10.9.2","tsx":"^4.19.2","typescript":"^5.7.3","typescript-eslint":"^8.21.0"},"type":"module","dependencies":{"otplib":"^12.0.1","qrcode":"^1.5.4"},"_id":"2fa-node@0.0.6","gitHead":"84304f3bdeceae00241d6761bda98d8f2e1302f1","bugs":{"url":"https://github.com/FinotiLucas/2fa-node/issues"},"homepage":"https://github.com/FinotiLucas/2fa-node#readme","_nodeVersion":"20.15.0","_npmVersion":"10.8.3","dist":{"integrity":"sha512-Qf/z8HKSqZiVLX+qzFhbRpaWmTNXXrnBNjaLabQI7OO/SnU4kjwwQ6r8k2INf9V+0xX8WzRaZl5yd6xfHyZiBg==","shasum":"5ea48520ccaefae8f346e4a019694ff2d7004d60","tarball":"https://registry.npmjs.org/2fa-node/-/2fa-node-0.0.6.tgz","fileCount":21,"unpackedSize":25368,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIHsTPvwzlGTZpYHXXCDQELHykzZLD0ik4eixL5CNVM0FAiB4GnDJjNGP7p8eSc8yJuLHJOivsw4AvtSzyX67g2OfYw=="}]},"_npmUser":{"name":"finotilucas","email":"lucas.finoti@protonmail.com"},"directories":{},"maintainers":[{"name":"finotilucas","email":"lucas.finoti@protonmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/2fa-node_0.0.6_1737541306651_0.2918604776106908"},"_hasShrinkwrap":false}},"time":{"created":"2025-01-10T19:04:16.416Z","modified":"2025-01-22T10:21:47.038Z","0.0.1":"2025-01-10T19:04:16.633Z","0.0.2":"2025-01-10T19:34:03.308Z","0.0.3":"2025-01-10T20:18:18.912Z","0.0.4":"2025-01-11T16:04:01.189Z","0.0.5":"2025-01-17T15:58:55.036Z","0.0.6":"2025-01-22T10:21:46.870Z"},"bugs":{"url":"https://github.com/FinotiLucas/2fa-node/issues"},"author":{"name":"Lucas Lima Finoti","email":"lucas.finoti@protonmail.com"},"license":"MIT","homepage":"https://github.com/FinotiLucas/2fa-node#readme","keywords":["totp","hotp","otp","authenticator","one time password","google authenticator","authentication","2FA","2 factor","node","auth","2fa","mfa"],"repository":{"type":"git","url":"git+https://github.com/FinotiLucas/2fa-node.git"},"description":"Easy 2-Factor Integration For Node.js","maintainers":[{"name":"finotilucas","email":"lucas.finoti@protonmail.com"}],"readme":"# 2FA NODE\n\nThis library provides a set of utilities to generate and verify time-based one-time passwords (TOTP) and HMAC-based one-time passwords (HOTP), allowing easy integration of two-factor authentication (2FA) in applications. It also supports generating QR codes for easy scanning with authenticator apps like Google Authenticator or Authy.\n\n## Features\n\n- **Generate Secret for 2FA**: Generates a secret key, a URI, and a QR code that can be used for integrating two-factor authentication with authenticator apps.\n- **Generate TOTP Token**: Generates a time-based one-time password (TOTP) using a secret key.\n- **Verify TOTP Token**: Verifies the validity of a TOTP token.\n- **Generate HOTP Token**: Generates a HMAC-based one-time password (HOTP) using a secret key and a counter.\n- **Verify HOTP Token**: Verifies the validity of a HOTP token using a secret key and a counter.\n\n## Installation\n\nTo install this library, run the following command:\n\n```bash\nnpm install 2fa-node\n```\n\n## Usage\n\n### Generate 2FA Secret\n\nThis function generates a secret key, a URI, and a QR code for 2FA integration. It returns a promise that resolves to an object containing the secret, URI, and the QR code as a data URL.\n\n### Generate TOTP Secret\n\n```typescript\nimport { generateSecret } from \"2fa-node\";\n\nconst payload = {\n  name: \"MyApp\", // Application name\n  account: \"user@example.com\", // User account (email or username)\n  numberOfSecretBytes: 20 // OPTIONAL\n};\n\nconst secret = await generateSecret(payload);\n\nconsole.log(secret);\n```\n\n### Generate HOTP Secret\n\n```typescript\nimport { generateSecret } from \"2fa-node\";\n\nconst options = {\n  name: \"MyApp\", // Application name\n  account: \"user@example.com\", // User account (email or username)\n  counter: 0, // ONLY WITH HOTP\n};\n\nconst secret = await generateSecret(option, \"HOTP\");\n\nconsole.log(secret);\n```\n\n### Generate TOTP Token\n\nThis function generates a time-based one-time password (TOTP) using the provided secret key.\n\n```typescript\nimport { generateToken } from \"2fa-node\";\n\nconst secret = \"JBSWY3DPEHPK3PXP\"; // Your pre-generated secret\nconst result = generateToken(secret);\n\nconsole.log(result.token); // The generated TOTP token\n```\n\n### Verify TOTP Token\n\nThis function verifies if a provided TOTP token is valid for the given secret key.\n\n```typescript\nimport { verifyToken } from \"2fa-node\";\n\nconst secret = \"JBSWY3DPEHPK3PXP\"; // The secret key used for verification\nconst token = \"123456\"; // The token to verify\n\nconst isValid = verifyToken(secret, token);\n\nconsole.log(isValid); // true if valid, false if invalid\n```\n\n### Generate HOTP Token\n\nThis function generates a HMAC-based one-time password (HOTP) token based on the provided secret key and counter value.\n\n```typescript\nimport { generateHOTPToken } from \"2fa-node\";\n\nconst secret = \"JBSWY3DPEHPK3PXP\"; // Your pre-generated secret\nconst counter = 1; // Optional counter (defaults to 0)\n\nconst result = generateHOTPToken(secret, counter);\n\nconsole.log(result.token); // The generated HOTP token\n```\n\n### Verify HOTP Token\n\nThis function verifies if a provided HOTP token is valid for the given secret key and counter value.\n\n```typescript\nimport { verifyHOTPToken } from \"2fa-node\";\n\nconst secret = \"JBSWY3DPEHPK3PXP\"; // The secret key used for verification\nconst token = \"123456\"; // The token to verify\nconst counter = 1; // The counter associated with the token\n\nconst isValid = verifyHOTPToken(secret, token, counter);\n\nconsole.log(isValid); // true if valid, false if invalid\n```\n\n## API Documentation\n\n### `generateSecret(options: Options): Promise<{ secret: string, uri: string, qr: string }>`\n\nGenerates a secret key, URI, and QR code for 2FA integration.\n\n- **Parameters**:\n  - `options`: An object with the following properties:\n    - `name`: The name of the application or service.\n    - `account`: The account identifier (e.g., email or username).\n- **Returns**: A Promise resolving to an object with:\n  - `secret`: The generated secret key.\n  - `uri`: The otpauth URI.\n  - `qr`: The Data URL for the QR code.\n\n### `generateToken(secret: string): { token: string } | null`\n\nGenerates a TOTP token.\n\n- **Parameters**:\n  - `secret`: The secret key used for generating the TOTP token.\n- **Returns**: An object containing the generated token, or `null` if the secret is invalid or missing.\n\n### `verifyToken(secret: string, token?: string): boolean | null`\n\nVerifies the validity of a TOTP token.\n\n- **Parameters**:\n  - `secret`: The secret key used for verification.\n  - `token`: The TOTP token to verify.\n- **Returns**: `true` if the token is valid, `false` if it's invalid, or `null` if the token is missing.\n\n### `generateHOTPToken(secret: string, counter: number = 0): { token: string } | null`\n\nGenerates an HOTP token.\n\n- **Parameters**:\n  - `secret`: The secret key used for generating the HOTP token.\n  - `counter`: The counter value used to generate the HOTP token (defaults to 0).\n- **Returns**: An object containing the generated token, or `null` if the secret is invalid or missing.\n\n### `verifyHOTPToken(secret: string, token?: string, counter: number = 0): boolean | null`\n\nVerifies the validity of an HOTP token.\n\n- **Parameters**:\n  - `secret`: The secret key used for verification.\n  - `token`: The HOTP token to verify.\n  - `counter`: The counter value associated with the HOTP token.\n- **Returns**: `true` if the token is valid, `false` if it's invalid, or `null` if the token is missing.\n\n## Dependencies\n\n- [otplib](https://www.npmjs.com/package/otplib) - A library for generating and verifying one-time passwords.\n- [qrcode](https://www.npmjs.com/package/qrcode) - A library for generating QR codes.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n","readmeFilename":"README.md"}