{"id":14188,"library":"uncrypto","title":"Uncrypto","description":"Uncrypto is a lightweight JavaScript library that provides a unified, cross-runtime API for cryptographic operations, abstracting the differences between the Web Crypto API in browsers and Node.js's native `crypto` module. Currently at version 0.1.3, it offers direct access to `SubtleCrypto` functionalities, `randomUUID`, and `getRandomValues` through a single import. The library leverages Node.js conditional exports to automatically adapt to the target environment (Node.js 15+ or modern browsers in secure contexts) without providing polyfills for older versions, thus maintaining a small footprint. Its primary differentiator is simplifying cryptographic development by eliminating environment-specific branching, allowing developers to write once and deploy across various JavaScript runtimes. The release cadence appears to be driven by feature enhancements and maintenance, reflecting its early-stage development and active development cycle.","status":"active","version":"0.1.3","language":"javascript","source_language":"en","source_url":"https://github.com/unjs/uncrypto","tags":["javascript","typescript"],"install":[{"cmd":"npm install uncrypto","lang":"bash","label":"npm"},{"cmd":"yarn add uncrypto","lang":"bash","label":"yarn"},{"cmd":"pnpm add uncrypto","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"For ESM environments, use named imports. CommonJS `require` is supported but primarily for older Node.js projects. Since v0.1.0, both ESM and CJS are explicitly supported via conditional exports.","wrong":"const { subtle } = require('uncrypto'); // Incorrect in pure ESM projects","symbol":"subtle","correct":"import { subtle } from 'uncrypto';"},{"note":"All public APIs are named exports, there is no default export.","wrong":"import randomUUID from 'uncrypto'; // Not a default export","symbol":"randomUUID","correct":"import { randomUUID } from 'uncrypto';"},{"note":"This function is available in both browser and Node.js environments through the unified API.","wrong":"const getRandomValues = require('uncrypto').getRandomValues;","symbol":"getRandomValues","correct":"import { getRandomValues } from 'uncrypto';"}],"quickstart":{"code":"import { subtle, randomUUID, getRandomValues } from 'uncrypto';\n\nasync function generateAndEncrypt() {\n  // Generate a random UUID\n  const uuid = randomUUID();\n  console.log('Generated UUID:', uuid);\n\n  // Generate cryptographically strong random values\n  const randomBuffer = new Uint8Array(16);\n  getRandomValues(randomBuffer);\n  console.log('Generated random values:', randomBuffer);\n\n  // Perform a simple AES-GCM encryption using subtle crypto\n  const algorithm = { name: 'AES-GCM', length: 256 };\n  const key = await subtle.generateKey(algorithm, true, ['encrypt', 'decrypt']);\n  const iv = getRandomValues(new Uint8Array(12));\n  const encoder = new TextEncoder();\n  const data = encoder.encode('Hello, Uncrypto!');\n\n  const encryptedData = await subtle.encrypt(\n    { name: 'AES-GCM', iv: iv },\n    key,\n    data\n  );\n\n  console.log('Encrypted data:', new Uint8Array(encryptedData));\n}\n\ngenerateAndEncrypt().catch(console.error);","lang":"typescript","description":"Demonstrates importing and using `subtle`, `randomUUID`, and `getRandomValues` to generate a UUID, secure random numbers, and perform a basic AES-GCM encryption operation."},"warnings":[{"fix":"Upgrade your Node.js environment to version 15 or newer. For projects that must support older Node.js, consider polyfilling `globalThis.crypto` manually or using a different library.","message":"uncrypto requires Node.js version 15 or higher. It does not provide polyfills for older Node.js environments, and attempts to use it on unsupported versions will result in runtime errors related to missing crypto APIs.","severity":"breaking","affected_versions":"<1.0.0"},{"fix":"Ensure your web application is served over HTTPS or accessed via `localhost` during development to enable the Web Crypto API.","message":"When used in browser environments, `uncrypto` relies on the Web Crypto API, which mandates a secure context (HTTPS or localhost). Operations will fail in insecure HTTP contexts.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"For unsupported runtimes, manually polyfill `globalThis.crypto` and `globalThis.crypto.subtle` according to the Web Crypto API specification or use a compatible polyfill library.","message":"This library does not provide its own polyfills for `globalThis.crypto`. If deploying to highly specialized or older JavaScript runtimes without a native `crypto` implementation, you must provide your own polyfill.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Pin to exact versions (`\"uncrypto\": \"0.1.3\"`) or use caret ranges (`\"^0.1.3\"`) with caution and regularly review release notes for updates.","message":"As of version 0.1.3, uncrypto is in an early development stage. While the API aims to be stable, minor versions may introduce breaking changes or significant modifications without a major version bump, as is common with pre-1.0 software.","severity":"gotcha","affected_versions":"<1.0.0"}],"env_vars":null,"search_vec":"'0.1.3':38 '15':67 'abstract':19 'access':42 'across':105 'activ':128 'adapt':61 'allow':98 'api':15,26 'appear':112 'automat':60 'branch':97 'browser':28,70 'cadenc':111 'condit':57 'context':73 'cross':13 'cross-runtim':12 'crypto':25,33 'cryptograph':17,90 'current':35 'cycl':130 'deploy':104 'develop':91,99,126,129 'differ':21 'differenti':87 'direct':41 'driven':115 'earli':124 'early-stag':123 'elimin':93 'enhanc':118 'environ':65,95 'environment-specif':94 'export':58 'featur':117 'footprint':84 'function':45 'getrandomvalu':48 'import':52 'javascript':6,107,131 'leverag':55 'librari':7,54 'lightweight':5 'maintain':81 'mainten':120 'modern':69 'modul':34 'nativ':32 'node.js':30,56,66 'offer':40 'older':78 'oper':18 'polyfil':76 'primari':86 'provid':9,75 'randomuuid':46 'reflect':121 'releas':110 'runtim':14,108 'secur':72 'simplifi':89 'singl':51 'small':83 'specif':96 'stage':125 'subtlecrypto':44 'target':64 'thus':80 'typescript':132 'uncrypto':1,2 'unifi':11 'various':106 'version':37,79 'web':24 'without':74 'write':101","created_at":"2026-04-20T01:58:23.525971+00:00","updated_at":"2026-04-20T01:58:23.525971+00:00","problems":[{"fix":"Change your import statements to use ESM syntax: `import { subtle } from 'uncrypto';` instead of `const { subtle } = require('uncrypto');`.","cause":"Attempting to use CommonJS `require()` syntax within a JavaScript file that is being treated as an ES module (e.g., `\"type\": \"module\"` in `package.json`).","error":"ReferenceError: require is not defined in ES module scope"},{"fix":"Ensure you are running in Node.js 15+ or a modern browser in a secure context. For other runtimes, you must manually polyfill `globalThis.crypto`.","cause":"The global `crypto` object is missing in the current JavaScript runtime environment. This can occur in unsupported Node.js versions (below 15), older browsers, or custom environments without a `crypto` implementation.","error":"Uncaught ReferenceError: crypto is not defined"},{"fix":"Serve your web application over HTTPS or access it via `localhost` during development to enable the secure context required by the Web Crypto API.","cause":"This error typically originates from the Web Crypto API in browsers when cryptographic operations are attempted in an insecure context (e.g., HTTP).","error":"DOMException: The operation is not supported in this context."}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/unjs/uncrypto","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/uncrypto","openapi_spec":null,"status_page":null,"smithery":null,"categories":["http-networking","auth-security"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-18","install_tag":null}}