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

@loomantix/web-crypto

v0.3.1

Published

At-rest AES-256-GCM encryption helpers for browsers (WebCrypto + non-extractable CryptoKey persisted in IndexedDB, factory API).

Readme

@loomantix/web-crypto

At-rest AES-256-GCM encryption helpers for browser apps. Uses native WebCrypto for the cipher and stores a non-extractable CryptoKey in IndexedDB via structured clone. Zero runtime dependencies.

API shape mirrors @loomantix/mobile-crypto for consumer ergonomic consistency — a caller dispatching at build time between the two packages can share the encrypt/decrypt/hasMagic/deleteKey call sites. The wire format (LMX\x01 magic + 12-byte nonce + AES-GCM auth tag) is also byte-identical, but this is a convention not a security boundary: mobile and web have independent vulnerability surfaces (OpenSSL-via- quick-crypto vs. browser WebCrypto) and CVEs are patched per-package. getOrCreateKey deliberately diverges (web returns an opaque CryptoKey; mobile returns raw Uint8Array bytes) — don't call it from shared code paths.

Install

pnpm add @loomantix/web-crypto

Published with npm provenance under Apache 2.0.

Usage

import { createCrypto } from '@loomantix/web-crypto';

const crypto = createCrypto({
  // Product- and purpose-scoped IndexedDB record key for the per-browser-
  // profile AES-GCM key. Pick a unique value per app + purpose
  // (e.g. `com.example.web-buffer.v1`, `com.example.web-queue.v1`).
  keyAlias: 'com.example.web-buffer.v1',
});

const ciphertext = await crypto.encryptString('plaintext'); // Uint8Array
const plaintext = await crypto.decryptString(ciphertext); // string | null

decryptString returns null for payloads with a missing magic prefix, truncation below the minimum length, or an auth-tag mismatch — callers should treat that as "record is unrecoverable, delete it". Throws on IndexedDB load errors (treat as transient; do not delete the record, retry later). The split is deliberate: conflating the two cases lets a transient IDB hiccup masquerade as terminal corruption, which a caller will then "clean up" by deleting still-recoverable data.

See src/crypto.ts for the full factory contract.

Lifecycle on logout

deleteKey() silently destroys the per-browser-profile key. Any ciphertext still on disk encrypted under it becomes unrecoverable — there is no second chance. web-crypto is a primitive and has no visibility into what records depend on the key, so consumers that persist encrypted data are responsible for:

  1. Checking their own buffer/store for pending records before calling deleteKey().
  2. If records exist and are salvageable (e.g. just need the network / a fresh auth token to flush), surfacing a "we're still trying to save N items — [keep trying] / [give up and sign out]" UX to the user rather than silently orphaning their work.
  3. Only calling deleteKey() after the buffer is empty OR the user has explicitly confirmed they accept the loss.

This contract exists because it's the only way to honor the user's work while still giving them a clean escape hatch on sign-out.

Threat model

  • Non-extractable CryptoKey. The AES-GCM key is generated with extractable: false, so even scripts with origin-level access cannot call crypto.subtle.exportKey on it — they can only invoke encrypt / decrypt through this package's API, which is the same power the application itself has.
  • THIS_BROWSER_PROFILE_ONLY. The key lives in the browser profile's IndexedDB. It is not synced across devices, not restored from a browser backup, and is wiped when the user clears site data. That matches @loomantix/mobile-crypto's THIS_DEVICE_ONLY keychain semantics: a user restoring to a new browser profile loses the ciphertext's decryptability (acceptable trade-off for short-TTL offline buffers).
  • Structured clone preserves non-extractability. Browsers (and fake-indexeddb in tests) serialize CryptoKey as an opaque handle, not raw bytes, so the key material never reaches IDB as plaintext on disk.
  • No defence against XSS. A script that runs in the origin can invoke encrypt / decrypt directly; there is no mitigation at the crypto layer. CSP + dependency hygiene are the right tools for that.

Security

See the repository's SECURITY.md for the responsible-disclosure process.