Utils
Utils
Modular TypeScript utilities for cryptography, auth & system operations
Type-safe, framework-agnostic helper suite for hashing, JWT, OTP generation, environment parsing, and email delivery.
Overview
Utils is a lightweight, framework-agnostic utility library designed for modern TypeScript and JavaScript applications.
It provides production-ready helpers for common backend and shared logic needs such as authentication, cryptography, environment handling, and transactional messaging — with a strong focus on correctness, security, and long-term maintainability.
Core Modules
- Authentication & Cryptography: Secure PBKDF2/bcrypt-compatible password hashing, JSON Web Token (JWT) signing and verification, and cryptographic OTP generation.
- Environment Handling: Strict schema-validated environment variable parsing with type inference and missing key diagnostics.
- Transactional Messaging: Clean, reliable email sending helpers engineered for ZeptoMail / transactional SMTP.
- Identifiers: High-entropy UUID v4 generation and validation.
- TypeScript-First: Zero
anyleakage, exhaustive type definitions, and ESM-first packaging.
Quick Example
tsx
import {
generateOTP,
hashPassword,
verifyPassword,
signJWT,
verifyJWT
} from '@nofinite/utils';
// 1. Generate a 6-digit numeric OTP with 5-minute expiry
const otp = generateOTP(6);
// 2. Hash and verify passwords with constant-time comparison
const hash = await hashPassword('super-secret-password');
const isValid = await verifyPassword('super-secret-password', hash);
// 3. Sign and verify JWTs with typed payload
const token = await signJWT({ userId: 'usr_123', role: 'admin' }, process.env.JWT_SECRET!, { expiresIn: '1h' });
const payload = await verifyJWT(token, process.env.JWT_SECRET!);Module Catalog
| Module | Primary Exports | Purpose |
|---|---|---|
auth-and-crypto | hashPassword, verifyPassword, signJWT, verifyJWT, generateOTP | Secure credential hashing, token lifecycle, and two-factor passcodes |
system-and-mail | parseEnv, sendEmail, generateUUID | Environment parsing, UUIDs, and transactional email delivery |
Next Steps
- Follow the Installation Guide to install the package.
- Explore Authentication & Cryptography for detailed crypto signatures and security parameters.
- Explore System & Email for environment schemas and ZeptoMail integration.