AI
v2.0.0
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

Nofinite Utils is a secure, lightweight, and 100% framework-agnostic utility library designed for modern TypeScript, Node.js, and Edge runtimes.

It provides production-hardened helpers for critical backend infrastructure: Argon2id password hashing, jose-based JSON Web Token (JWT) lifecycle, high-entropy cryptographic OTPs, UUID v4 generation, strict environment variable parsing, and ZeptoMail transactional messaging.


Architectural Invariants

  • 100% Framework Agnostic: Zero dependencies on React, Vue, or any frontend DOM layer. Runs seamlessly on Node.js (>= 18), Cloudflare Workers, Fastify, Express, Hono, NestJS, and Next.js Route Handlers.
  • Argon2id Password Security: Leverages the state-of-the-art Argon2id cryptographic hashing algorithm (winner of the Password Hashing Competition) with automated salt generation.
  • JOSE Standards-Compliant JWTs: Powered by the battle-tested jose library with HS256/RS256 algorithm support and strict clock skew verification.
  • Modular Subpath Exports: Import only what you need via tree-shakeable subpaths: @nofinite/utils/password, @nofinite/utils/jwt, @nofinite/utils/otp, @nofinite/utils/uuid, @nofinite/utils/env, and @nofinite/utils/email.

Core Capabilities

  • Password Hashing (/password): High-entropy Argon2id password hashing and constant-time verification.
  • JWT Authentication (/jwt): Type-safe token signing, verification, and claims decoding with configurable expiration.
  • One-Time Passwords (/otp): Cryptographic numeric passcodes with expiry checks and brute-force attempt limits.
  • Environment Handling (/env): Strictly typed environment variable getters with fallback and required validation.
  • Unique Identifiers (/uuid): UUID v4 generation, binary buffer conversion, and validation.
  • Transactional Messaging (/email): High-throughput transactional email delivery via ZeptoMail SMTP/API.

Quick Example

typescript
import { 
  hashPassword, 
  verifyPassword, 
  signToken, 
  verifyToken, 
  generateOTP,
  requireEnv 
} from '@nofinite/utils';

// 1. Password Security with Argon2id
const passwordHash = await hashPassword('super-secret-user-password');
const isValid = await verifyPassword(passwordHash, 'super-secret-user-password');
console.log('Password valid:', isValid); // true

// 2. JWT Signing & Verification
const token = await signToken(
  { sub: 'usr_9482', role: 'admin' },
  { expiresIn: '2h' }
);
const decoded = await verifyToken(token);
console.log('User ID:', decoded.sub);

// 3. Cryptographic OTP Generation
const { otp, expiresAt } = generateOTP(6, { ttlMinutes: 10 });
console.log(`Generated OTP: ${otp}, expires at: ${expiresAt}`);

// 4. Strict Environment Variable Validation
const databaseUrl = requireEnv('DATABASE_URL');

Module Catalog

ModuleSubpath ExportPrimary Functions
Auth & Crypto@nofinite/utils/password
@nofinite/utils/jwt
@nofinite/utils/otp
hashPassword, verifyPassword, signToken, verifyToken, generateOTP, verifyOTP
System & Mail@nofinite/utils/env
@nofinite/utils/uuid
@nofinite/utils/email
getEnv, requireEnv, getEnvBoolean, generateUUID, sendMail, sendBatchMail

Next Steps