This package provides comprehensive utilities for generating and verifying One-Time Passwords (OTP), adhering to both HOTP (HMAC-Based One-Time Password Algorithm) as defined in RFC 4226 and TOTP (Time-Based One-Time Password Algorithm) as defined in RFC 6238. It is designed to be compatible with popular OTP mechanisms like Google Authenticator. The current stable version is 2.0.1, indicating active development and maintenance. The library differentiates itself by offering direct support for generating Google Authenticator-compatible URLs, parsing existing OTP URLs or base32-encoded secrets, and including a JSON reviver for seamless serialization and deserialization of OTP objects. While a specific release cadence is not formally stated, significant refactors, such as the TypeScript conversion in v1.0.0, highlight ongoing efforts to modernize and improve the codebase.
npm install otpVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize the OTP class with a secret, generate both Time-Based One-Time Passwords (TOTP) and HMAC-Based One-Time Passwords (HOTP), generate Google Authenticator-compatible URLs, parse existing OTP URLs, and utilize the provided JSON reviver for object serialization.
Review your import statements to ensure they align with ESM patterns (e.g., `import OTP from 'otp';`). Verify secret handling, ensuring it's a Base32 string or Buffer as expected by the new API.
Always use `await` when calling `otpInstance.hotp(counter)` or `otpInstance.totp()` within an `async` function, or handle the Promise using `.then()`.
Store secrets securely in environment variables, secret management services, or encrypted databases. Transmit them only over secure, encrypted connections (HTTPS/TLS).
Implement robust server-side storage and atomic incrementation for each user's HOTP counter. Never reset the counter unless absolutely necessary (e.g., re-provisioning).
Generate secrets that decode to 64-bit (8 bytes) or 128-bit (16 bytes) lengths. Typically, longer keys (e.g., 128-bit / 16 bytes base32 encoded) are recommended for stronger security.
Use the correct ESM default import: `import OTP from 'otp';` Ensure your environment supports ESM modules (e.g., Node.js with `"type": "module"` in `package.json` or transpilation).
Always `await` the asynchronous OTP generation methods: `const code = await otpInstance.totp();`
Ensure your secret (either a Buffer or Base32-encoded string) corresponds to a decoded length of 8 bytes (64 bits) or 16 bytes (128 bits). Adjust `keySize` option if using a non-default length.
Verify that the URL string conforms to the `otpauth://` scheme, including type, label, and parameters like `secret` and `issuer`.
No dependency data recorded yet.