Edge-runtime cryptographic operations using the Web Crypto API, optimized for Cloudflare Workers, Vercel Edge, and Deno.
Getting started
The Crypto Service ecosystem
Package reference
Operational
pnpm add @sebastienrousseau/crypto-edge
# or
npm install @sebastienrousseau/crypto-edge
# or
yarn add @sebastienrousseau/crypto-edge
^22.0.0 or >=24.0.0 (active and maintenance LTS releases)pnpm >=9 (recommended) or npm >=10>=5.0 (when compiling with TypeScript)import { hash, detectRuntime } from "@sebastienrousseau/crypto-edge";
console.log("Running on:", detectRuntime());
const digest = await hash("SHA-256", "hello world");
console.log(digest);
// b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9
Crypto Service provides a complete cryptography stack across 14 specialized packages:
| Package | Role | Description |
|---|---|---|
@sebastienrousseau/crypto-api |
API Schemas | Shared TypeScript types and utilities for the Crypto Service Suite, defining the canonical API surface. |
@sebastienrousseau/crypto-cli |
Terminal CLI | An interactive command-line interface for cryptographic operations, supporting both legacy OpenPGP and modern post-quantum algorithms. |
@sebastienrousseau/crypto-edge (this package) |
Edge Runtime | Edge-runtime cryptographic operations using the Web Crypto API, optimized for Cloudflare Workers, Vercel Edge, and Deno. |
@sebastienrousseau/crypto-kms |
Cloud KMS | Unified Key Management Service interface for AWS KMS, GCP Cloud KMS, Azure Key Vault, and HashiCorp Vault. |
@sebastienrousseau/crypto-lib |
Core Library | A modern cryptographic library for TypeScript, with post-quantum support, zero unsafe dependencies, and 100% test coverage. |
@sebastienrousseau/crypto-middleware |
Middleware | Framework-agnostic cryptographic middleware for Express, Fastify, and Koa applications. |
@sebastienrousseau/crypto-prisma |
ORM Adapter | Transparent field-level encryption extension for Prisma Client, powered by AES-256-GCM. |
@sebastienrousseau/crypto-react |
React Hooks | React hooks and context provider for client-side cryptographic operations with zero boilerplate. |
@sebastienrousseau/crypto-sdk |
Client SDK | A zero-dependency, typed HTTP client for the Crypto Service REST API, with full post-quantum support. |
@sebastienrousseau/crypto-server |
HTTP API | A hardened Fastify REST API for cryptographic operations, with rate limiting, OpenAPI schemas, and post-quantum endpoints. |
@sebastienrousseau/crypto-testing |
Test Support | Deterministic keys, fast mocks, and test fixtures for crypto-lib |
@sebastienrousseau/crypto-typeorm |
ORM Adapter | TypeORM column-level encryption with a single decorator, powered by crypto-lib. |
@sebastienrousseau/crypto-vue |
Vue Composables | Vue 3 composables for client-side cryptography |
@sebastienrousseau/crypto-wasm |
Acceleration | WebAssembly performance accelerator for crypto-lib |
crypto-edge adapts the Crypto Service Suite for edge and serverless runtimes. It provides runtime detection, a Web Crypto wrapper for hashing, AES-GCM encryption, HMAC signing, and key generation, plus polyfills for minimal environments. All functions use only the standard Web Crypto API -- no Node.js built-ins are imported.
## Supported Runtimes| Runtime | Identifier | Web Crypto | Notes |
|---|---|---|---|
| Cloudflare Workers | cloudflare-workers |
Yes | Full support |
| Vercel Edge | vercel-edge |
Yes | Full support |
| Deno | deno |
Yes | Full support |
| Bun | bun |
Yes | Full support |
| Browsers | browser |
Yes | Modern browsers (Chrome 37+) |
| Node.js | node |
Yes | Node >= 15 (globalThis.crypto) |
| Unknown | unknown |
Varies | Use getCapabilities() to check |
import {
detectRuntime,
getCapabilities,
isEdgeCryptoAvailable,
} from "@sebastienrousseau/crypto-edge";
const runtime = detectRuntime();
const caps = getCapabilities();
if (isEdgeCryptoAvailable()) {
// Safe to call hash(), encrypt(), etc.
}
import {
hash,
generateKey,
encrypt,
decrypt,
} from "@sebastienrousseau/crypto-edge";
// Hashing
const sha256 = await hash("SHA-256", "hello");
// Encryption / Decryption (AES-GCM)
const key = await generateKey({ algorithm: "AES-GCM", length: 256 });
const { ciphertext } = await encrypt({
key,
plaintext: new TextEncoder().encode("secret"),
});
const plaintext = await decrypt({ key, ciphertext });
Call installPolyfills() once at startup for minimal runtimes
missing standard globals:
import { installPolyfills } from "@sebastienrousseau/crypto-edge";
const installed = installPolyfills();
Polyfills provided: TextEncoder, TextDecoder, btoa, atob,
and a Math.random-based crypto.getRandomValues (testing only --
not cryptographically secure).
All examples are self-contained TypeScript files in the examples/
directory. Run any example with:
npx ts-node examples/<name>.ts
| Category | Example | Purpose |
|---|---|---|
| Detection | detect.ts | Runtime detection |
| Hashing | hash.ts | Edge-compatible hashing |
| Encryption | encrypt.ts | AES-GCM encrypt and decrypt |
| Workers | workers.ts | Cloudflare Workers usage |
| Vercel | vercel.ts | Vercel Edge Function usage |
| Browser | browser.ts | Browser usage |
| Polyfills | polyfill.ts | Polyfill installation |
pnpm --filter @sebastienrousseau/crypto-edge run build
pnpm --filter @sebastienrousseau/crypto-edge run test
pnpm --filter @sebastienrousseau/crypto-edge run lint
pnpm --filter @sebastienrousseau/crypto-edge run format
All 14 packages in the Crypto Service workspace maintain a 100% coverage floor across statements, branches, functions, and lines.
Report vulnerabilities privately via GitHub Security Advisories or according to SECURITY.md. Never report security issues publicly.
All cryptographic operations leverage audited primitives, enforce constant-time execution where applicable, and zero sensitive key material upon disposal.
Versions advance strictly one step at a time on the 0.0.x line (v0.0.1 → v0.0.2 → v0.0.3 ... → v0.0.999 → v0.1.0). Work for every release iteration begins on a dedicated feat/v<version> branch.
All 14 packages in the workspace move in lockstep. Public API signatures, cipher output formats, and serialization schemas are strictly versioned. Breaking changes to serialized formats or algorithm defaults are considered major breaking changes. Minimum toolchain upgrades (e.g. Node.js LTS floor) are governed by POLICIES.md.
Dual-licensed under Apache 2.0 or MIT, at your option.
Copyright (c) 2022-2026 Sebastien Rousseau and The Crypto Service Suite contributors.