Package Exports
- @colingreybosh/otp-lib
- @colingreybosh/otp-lib/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@colingreybosh/otp-lib) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
OTP Library
A TypeScript library for generating, validating, and managing one-time passwords (OTP) for authentication purposes.
Features
- TOTP (Time-based OTP): Generate and validate time-based OTPs based on RFC 6238
- HOTP (HMAC-based OTP): Generate and validate HMAC-based OTPs based on RFC 4226
- Multiple algorithms: Support for SHA1, SHA256, and SHA512
- Customizable: Configure OTP parameters such as secret, algorithm, digits, period, and counter
- TypeScript: Full TypeScript support with type definitions
- Secure: Cryptographically secure secret generation using Node.js crypto module
- RFC compliant: Implements RFC 6238 (TOTP) and RFC 4226 (HOTP) specifications
Installation
npm install @colingreybosh/otp-libQuick Start
import { TOTP, generateSecret } from '@colingreybosh/otp-lib';
// Generate a secure secret
const secret = generateSecret();
// Create TOTP instance
const totp = new TOTP({
secret,
algorithm: 'SHA1',
digits: 6,
period: 30,
});
// Generate a token
const token = totp.generate();
console.log(`Current token: ${token.token}`);
// Validate a token
const validation = totp.validate(token.token);
console.log(`Valid: ${validation.valid}`);