uncrypto
A single, isomorphic Web Crypto API that works identically in Node.js, browsers, and edge runtimes
Repository Health
Technical Analysis
uncrypto is a small utility from the UnJS ecosystem that exposes one consistent crypto API — subtle, randomUUID, and getRandomValues — regardless of whether the calling code executes in Node.js, a browser, or a modern edge/worker runtime such as Deno, Bun, or Cloudflare Workers.
Rather than branching at runtime, it relies entirely on Node.js conditional package exports: a crypto.node.ts implementation wraps node:crypto’s webcrypto module, while a crypto.web.ts implementation reads directly from globalThis.crypto, and the bundler or runtime resolves to the correct one automatically based on the node, browser, deno, bun, workerd, edge-light, and other export conditions declared in package.json. The result is a zero-dependency, drop-in replacement for the native Crypto interface that library and framework authors can import without writing their own environment-detection code.
What You Get
- A default export plus named
subtle,randomUUID, andgetRandomValuesbindings that match the standardCryptointerface - Automatic resolution to
node:crypto’swebcryptomodule on Node.js and toglobalThis.cryptoeverywhere else, via package.json export conditions - Pre-built ESM and CommonJS bundles with TypeScript declaration files for both the Node and web targets
- Export conditions pre-wired for Bun, Deno, Workerd, Netlify Edge, edge-light, and React Native so bundlers pick the right build automatically
Common Use Cases
- Generating cryptographically secure UUIDs in isomorphic libraries
- Implementing hashing/signing utilities that must run identically server-side and client-side
- Building edge-compatible middleware that needs Web Crypto without hand-written runtime detection
- Avoiding Node-only
cryptoimports that break browser or edge bundling in shared packages
Under The Hood
Architecture
The package has no shared internal abstraction layer — instead, src/crypto.node.ts and src/crypto.web.ts are two independent, thin implementations of the same Crypto shape (subtle, randomUUID, getRandomValues, plus a default object combining them), and the correct one is selected entirely by package.json’s conditional exports map (node vs browser/deno/bun/workerd/etc.) rather than by any runtime typeof window check in the code itself. This keeps the architecture trivial to reason about, but it does mean correctness depends on the two files staying behaviorally identical, since nothing in the codebase enforces that beyond the shared test suite.
Tech Stack
Written in strict TypeScript and built with unbuild (the UnJS build tool) to emit both ESM and CommonJS output with .d.ts declarations for each target. Testing uses Vitest with the @vitest/coverage-v8 provider, linting uses ESLint with eslint-config-unjs plus Prettier for formatting, and releases are cut with changelogen. The package has zero runtime dependencies, relying only on Node’s built-in node:crypto module and the platform-provided globalThis.crypto.
Code Quality
A single test file (test/index.test.ts) runs an identical assertion suite — randomUUID format, getRandomValues population, and subtle’s shape — against both the Node and web implementations via a shared runTests() helper, giving reasonable parity coverage despite the codebase’s small size. Strict TypeScript is enabled project-wide, ESLint and Prettier are enforced in CI alongside the test run, and coverage is uploaded to Codecov, though the overall surface area being tested is limited by how little code the package actually contains.
API Design
The public API is deliberately minimal and mirrors the standard browser Crypto interface exactly, so consumers already familiar with Web Crypto need no new mental model or documentation beyond “same interface, works everywhere.” Getting started requires a single import with no configuration, though the tradeoff is that it offers no shims, polyfills, or extended convenience methods beyond what the native APIs already expose.
Used by 2 apps in this directory
NewsNow
Bookmarks Archiving
Self-hostable news aggregator with an elegant column layout, GitHub OAuth, adaptive scraping intervals, and seamless Cloudflare D1 or SQLite persistence.
Trigger.dev
Automation · AI Development · Developer Tools
Build and deploy fully-managed AI agents and background jobs in TypeScript — with no timeouts, durable retries, real-time observability, and elastic scaling built in.