uncrypto

A single, isomorphic Web Crypto API that works identically in Node.js, browsers, and edge runtimes

Library
npm
v0.1.3
259stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
46/100Fair
Development Activity52
Maintenance20
Community32
Maturity52
Momentum28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
53/100Fair
Architecture60
Code Quality70
Innovation45
Learning Curve35

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, and getRandomValues bindings that match the standard Crypto interface
  • Automatic resolution to node:crypto’s webcrypto module on Node.js and to globalThis.crypto everywhere 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 crypto imports 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.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search