
Product
Introducing Custom Pull Request Alert Comment Headers
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
A time-based One-time Password generator that uses current time as a source of uniqueness, following RFC 6238.
Time-based One-Time Password (TOTP) is an algorithm that generates a one-time password based on the current time. TOTP is an extension of the HMAC-based One-Time Password (HOTP) algorithm and is standardized in RFC 6238. For more details, see Wikipedia.
You can install gen-totp
via npm or yarn:
npm install gen-totp
# or
yarn add gen-totp
import genTOTP from 'gen-totp';
const otp = genTOTP('test-key');
// Returns a 6-digit OTP by default
console.log(otp);
import genTOTP from 'gen-totp';
const otp = genTOTP('test-key', { digits: 4 });
// Returns a 4-digit OTP
console.log(otp);
The genTOTP function accepts two parameters:
key
: A string containing the base32-encoded secret key. It can include numbers, uppercase letters, _
, and -
.options
: An optional object to customize the OTP generation. The available options
are detailed in the table below:Option | Type | Default | Description |
---|---|---|---|
digits | number | 6 | The number of digits in the generated OTP. |
period | number | 30 | The time period (in seconds) after which a new OTP is generated. |
algorithm | string | 'SHA-1' | The hashing algorithm used to generate the OTP. Supported algorithms include: |
- SHA-1 | |||
- SHA-224 | |||
- SHA-256 | |||
- SHA-384 | |||
- SHA-512 | |||
- SHA3-224 | |||
- SHA3-256 | |||
- SHA3-384 | |||
- SHA3-512 | |||
For more details, refer to the JsSHA documentation. |
When providing a key to the genTOTP function, you can use different encodings specified by the encoding option:
UTF-8 Encoding (default):
Hex Encoding :
Base32 Encoding :
For more detailed documentation, visit the Official Documentation .
Contributions are welcome! If you have any bug reports, suggestions, or feature requests, please open an issue on GitHub.
To contribute:
FAQs
A time-based One-time Password generator that uses current time as a source of uniqueness, following RFC 6238.
The npm package gen-totp receives a total of 4,538 weekly downloads. As such, gen-totp popularity was classified as popular.
We found that gen-totp demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.