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

webopenssl

v0.1.2

Published

Web-based OpenSSL-like random key generator (WASM or min.js). Provides rand -base64 and -hex outputs using WebCrypto or optional OpenSSL-wasm.

Downloads

5

Readme

WebOpenSSL

Web-based OpenSSL-like random key generator that can be loaded as either:

  • A minified JavaScript library (dist/webopenssl.min.js)
  • With optional WASM provider (compiled OpenSSL via Emscripten) to use RAND_bytes

Purpose

Create random keys similar to openssl rand -base64 32, using secure system randomness:

  • WebCrypto (browser): crypto.getRandomValues, backed by OS CSPRNG
  • Node.js (min.js UMD): crypto.randomBytes
  • Optional OpenSSL WASM module: calls RAND_bytes from libcrypto compiled to WebAssembly

This matches OpenSSL's security model for randomness (OS-backed CSPRNG).

Files

  • src/index.js (ESM) — readable source
  • dist/webopenssl.min.js (UMD) — minified build for browser or Node
  • examples/index.html — simple usage in a web page
  • scripts/build-openssl-wasm.sh — builds OpenSSL libcrypto to WASM
  • src/wasm/openssl_rand_wrapper.c — small wrapper that exposes openssl_rand_bytes(...) for Emscripten

API

  • randBytes(length: number): Uint8Array
  • randBase64(length: number): string
  • randHex(length: number): string
  • setProvider(provider: { name: string; randBytes(length): Uint8Array })
  • setWasmModule(Module: EmscriptenModule) — configures OpenSSL WASM provider
  • getProviderName(): string
  • autoLoadOpenSSLWASM(options?: { url?: string; factoryGlobalName?: string }): Promise
  • When OpenSSL WASM provider is loaded (openssl-wasm), additional functions are available:
    • sha256(bytes: Uint8Array): Uint8Array (32 bytes)
    • sha512(bytes: Uint8Array): Uint8Array (64 bytes)
    • pbkdf2HmacSha256(password: Uint8Array, salt: Uint8Array, iterations: number, keyLen: number): Uint8Array
    • pbkdf2HmacSha512(password: Uint8Array, salt: Uint8Array, iterations: number, keyLen: number): Uint8Array
    • aes256GcmEncrypt(key: Uint8Array(32), iv: Uint8Array, aad: Uint8Array, plaintext: Uint8Array): { ciphertext: Uint8Array, tag: Uint8Array(16) }
    • aes256GcmDecrypt(key: Uint8Array(32), iv: Uint8Array, aad: Uint8Array, ciphertext: Uint8Array, tag: Uint8Array(16)): Uint8Array

Usage (Browser, min.js)

Include the minified UMD bundle:

<script src="./dist/webopenssl.min.js"></script>
<script>
  // Equivalent to: openssl rand -base64 32
  const keyB64 = WebOpenSSL.randBase64(32);
  console.log("base64 key:", keyB64);

  const keyHex = WebOpenSSL.randHex(32);
  console.log("hex key:", keyHex);

  console.log("provider:", WebOpenSSL.getProviderName()); // "webcrypto" (default) or "openssl-wasm" if configured
</script>

Auto-load OpenSSL WASM (Browser)

If you build the OpenSSL WASM module, you can auto-load it:

<script src="./dist/webopenssl.min.js"></script>
<script>
  WebOpenSSL.autoLoadOpenSSLWASM({ url: './dist/openssl-wasm/openssl_module.js' })
    .then((loaded) => {
      console.log("WASM loaded:", loaded);
      console.log("provider:", WebOpenSSL.getProviderName()); // "openssl-wasm" if loaded
    });
</script>

Usage (ESM)

import { randBase64, randHex, getProviderName, autoLoadOpenSSLWASM } from "./src/index.js";

console.log(randBase64(32));
console.log(randHex(32));
console.log(getProviderName()); // "webcrypto"

await autoLoadOpenSSLWASM({ url: "./dist/openssl-wasm/openssl_module.js" });
console.log(getProviderName()); // "openssl-wasm" if loaded

Build OpenSSL to WASM (Emscripten)

Prerequisites:

  • macOS/Linux with bash, curl, tar, make, perl
  • Emscripten SDK (emsdk) in PATH, or this script will fetch and activate a local copy

Steps:

  • Using npm script:
    • npm run build:wasm
  • Or directly:
    • bash scripts/build-openssl-wasm.sh

What the script does:

  • Downloads OpenSSL 3.5.3
  • Builds libcrypto with emconfigure/emmake (disables unsupported features in WASM)
  • Compiles a small wrapper (src/wasm/openssl_rand_wrapper.c) and links against libcrypto
  • Emits a modularized factory (OpenSSLModuleFactory) at dist/openssl-wasm/openssl_module.js with a .wasm sidecar
  • WebOpenSSL can auto-load it via autoLoadOpenSSLWASM or manually via setWasmModule

Manual wiring example

<script src="./dist/webopenssl.min.js"></script>
<script src="./dist/openssl-wasm/openssl_module.js"></script>
<script>
  OpenSSLModuleFactory().then((Module) => {
    WebOpenSSL.setWasmModule(Module);
    console.log("provider:", WebOpenSSL.getProviderName()); // "openssl-wasm"
    console.log(WebOpenSSL.randBase64(32));
  });
</script>

Deploy to Vercel

This repo includes an npm script that prepares a deployable folder (vercel-build) and deploys it to Vercel. It:

  • Builds a fresh WASM (npm run build:wasm)
  • Copies the entire project into vercel-build (excluding dev/build artifacts)
  • Moves examples/index.html to vercel-build/index.html
  • Rewrites relative paths so index.html references dist and src from vercel-build root
  • Deploys vercel-build with the Vercel CLI

Prerequisites (one-time):

  • Install Vercel CLI:
    npm i -g vercel
  • Login:
    vercel login
  • Link the deploy folder (must be done once before the first deployment):
    • Ensure the folder exists:
      mkdir -p vercel-build
    • Link vercel-build to a Vercel project:
      vercel link --cwd vercel-build
      Follow the prompts to create/select a project and scope.

Deploy

  • Run:
    npm run deploy:vercel
    The script will:
    • Build fresh WASM
    • Sync files into vercel-build
    • Move examples/index.html to vercel-build/index.html
    • Rewrite any ../dist/... and ../src/... references to dist/... and src/...
    • Deploy vercel-build to production with Vercel

Notes

  • If you relocate or rename examples/index.html, adjust the script at scripts/deploy-vercel.sh accordingly.
  • The script preserves vercel-build/.vercel, so you only need to run vercel link once.
  • You can view deployment logs and URLs in your Vercel dashboard.

Notes on Security

  • WebOpenSSL uses cryptographically secure randomness:
    • Browser: WebCrypto getRandomValues (OS CSPRNG)
    • Node.js: crypto.randomBytes (OS CSPRNG)
    • OpenSSL WASM: RAND_bytes via libcrypto (OpenSSL's CSPRNG)
  • Output length semantics mirror openssl rand:
    • randBase64(n) generates n random bytes and returns base64 encoding of those bytes.
    • randHex(n) generates n random bytes and returns hex encoding.

Limitations

  • This library focuses on secure random key generation. It is not a full re-implementation of OpenSSL.
  • Building OpenSSL to WASM can be environment-sensitive. The provided script targets modern Emscripten and OpenSSL 3.5.3.

License

MIT