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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@enterprise_search/storage_crypto

v0.8.137

Published

Crypto for storage: ensuring each user only sees their own data

Readme

Storage Crypto

Problem

  • Container-level RBAC in blob storage can’t restrict access per user.
  • We need “crypto boxes” so only the creator or admin can decrypt each blob.

Features

  • A single 'current' global secret with key derivation allows for cryptographically strong keys for each id
  • While only one global secret is 'active' for writing, multiple reads are allowed, which means we don't have an outage when we change global keys
  • Each record can only be decrypted by the user or the admin
  • All the metadata (apart from the secret) needed to decrypt the blob is stored in parallel to the blob
  • Very resiliant to crypto attacks: even if a single blob is 'hacked' and the key found, this key does not help find the global secret, and is not similar to other keys for the same user, so is of no help when decypting other

Components

  • Global secrets → derive per-ID wrap keys via HKDF + salt
  • Client ops: DEK generation, wrapping, payload encryption, metadata headers
  • API: holds master secrets, validates JWT, exposes wrap/unwrap endpoints
  • Storage: blob body + user-metadata (x-ms-meta-…)

Encryption Flow

  1. Generate random DEK & payload IV.
  2. Generate salt.
  3. HKDF-derive user wrap-key (info = userId) and admin wrap-key (info = "admin").
  4. AES-GCM wrap DEK under each key (stores salt+IV+wrappedDEK in metadata).
  5. AES-GCM encrypt payload with DEK (store in blob).

Decryption Flow

  1. Read blob metadata & body.
  2. HKDF-derive wrap-key for user or admin.
  3. AES-GCM decrypt wrapped DEK.
  4. AES-GCM decrypt payload.

Example code to encrypt:

//setup
const globalSecret1 = '12345678123123123123321123' // probably injected via env variables.
const globalSecret2 = 'ffffffffff3123123123321123'

const cryptoConfig = cryptoConfig({
    globalSecrets: {'one': globalSecret1, 'two': globalSecret2}, //First one is used to write, any can be used to read
    adminName: 'admin'
})
const encryptor = defaultStorageEncodeFn(config1)
const decryptor = defaultStorageDecodeFn(config1)

//To encrypt
const {metadata, encoded} = await encryptor('someUserId', 'someplaintext')

//to decypt for a user or admin
const plainTextForUser = await decryptor(metadata, {userId: 'someUserId'}, encoded)
const plainTextForAdmin = await decryptor(metadata, 'admin', encoded)