npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@hua-labs/security

v1.0.0-alpha.0

Published

HUA Labs Security - Encryption, Rate Limiting, Abuse Detection, and more

Readme

@hua-labs/security

Unified security toolkit with Free/Pro tiers. Free tier provides encryption (AES-256-GCM, PBKDF2), rate limiting (memory + Redis), password validation, and key management with zero external dependencies. Pro tier adds KMS envelope encryption, abuse pattern detection, and token estimation.

npm version npm downloads license TypeScript

Features

  • Envelope encryption — KMS-managed keys with AES-256-GCM + PBKDF2 fallback
  • Smart detection — Auto-detects KMS (v2) and legacy PBKDF2 formats
  • Rate limiting — Memory + Storage-backed (Redis), with built-in presets
  • Password validation — Strength checks with bilingual error messages
  • Client identity — Framework-agnostic IP/UA extraction and bot detection
  • Key management — Config-based key rotation without app dependencies
  • Abuse detection — Jailbreak/injection pattern matching engine
  • Token estimation — LLM operation cost estimation
  • Invisible CAPTCHA — Behavioral bot detection (browser-only)

Installation

pnpm add @hua-labs/security

Peer dependencies: @google-cloud/kms ^4.5.0, next >=14.0.0

Quick Start

import {
  encryptSmart, decryptSmart,
  createMemoryRateLimiter, createStorageRateLimiter,
  RATE_LIMIT_PRESETS,
} from '@hua-labs/security';
import { createRedisAdapter } from '@hua-labs/security/adapters';

// Encrypt (uses KMS if available, otherwise PBKDF2)
const encrypted = await encryptSmart('sensitive data');
const decrypted = await decryptSmart(encrypted);

// Rate limiting (in-memory)
const limiter = createMemoryRateLimiter();
const result = await limiter.checkRateLimit('user-123', '1.2.3.4', RATE_LIMIT_PRESETS.auth);

// Rate limiting (Redis-backed)
const adapter = createRedisAdapter({ client: redis });
const distributed = createStorageRateLimiter(adapter);
const res = await distributed.checkRateLimit('user-123', '1.2.3.4', RATE_LIMIT_PRESETS.analyze);

API

| Export | Type | Description | |--------|------|-------------| | ENCRYPTION_CONSTANTS | component | | | encryptSmart | function | Encrypt with best available method (KMS or PBKDF2) | | decryptSmart | function | Decrypt with auto-format detection | | getEncryptionMethod | function | | | pbkdf2Encrypt | function | | | pbkdf2Decrypt | function | | | isPBKDF2Format | function | | | generateSecureKey | function | | | checkKeyStrength | function | | | hashSHA256 | function | | | hashSHA512 | function | | | createHMAC | function | | | verifyHMAC | function | | | secureCompare | function | | | hashUserData | function | | | isKMSEnabled | function | | | envelopeEncrypt | function | Direct KMS envelope encryption | | envelopeDecrypt | function | Direct KMS envelope decryption | | isEnvelopeFormat | function | | | resetKMSClient | function | | | createMemoryRateLimiter | function | Create in-memory rate limiter instance | | RateLimitExceededError | component | | | createStorageRateLimiter | function | Create storage-backed rate limiter (Redis, DB) | | RATE_LIMIT_PRESETS | const | Built-in presets (default, auth, diary, search, analyze, sensitive) | | validatePassword | function | Validate password strength with bilingual messages | | getClientIP | function | Extract client IP from request headers | | getUserAgent | function | Extract user agent from request headers | | isAllowedBot | function | | | isNormalMobileUserAgent | function | | | isSuspiciousUserAgent | function | | | KeyManager | class | Config-based encryption key manager | | EncryptionConfig | type | | | EncryptedPayload | type | | | RateLimitResult | type | | | MemoryRateLimiterConfig | type | | | RateLimitPreset | type | | | RateLimitPresetName | type | | | RequestWithHeaders | type | | | KeyType | type | | | KeyInfo | type | | | KeyManagerConfig | type | |

Related Packages

License

MIT — HUA Labs