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

@prairielearn/encrypted-storage

v1.1.4

Published

Readme

@prairielearn/encrypted-storage

Utilities for application-level encryption of values stored in a database. Applications provide their ciphertext format so existing PrairieLearn and PrairieTest data remains compatible.

The first configured key encrypts new values. Decryption tries every configured key in order, and values encrypted with a fallback key can be re-encrypted with the primary key.

import { createStorageCipher, prairieLearnCiphertextFormat } from '@prairielearn/encrypted-storage';

const cipher = createStorageCipher({
  keyRing: [newKey, oldKey],
  format: prairieLearnCiphertextFormat,
});

const ciphertext = cipher.encrypt('secret');
const plaintext = cipher.decrypt(ciphertext);
const replacement = cipher.rotate(oldCiphertext);

prairieLearnCiphertextFormat uses base64(12-byte IV + ciphertext + 16-byte authentication tag). prairieTestCiphertextFormat uses hex(ciphertext):hex(16-byte IV):hex(16-byte authentication tag). Both use AES-256-GCM without additional authenticated data.

Postgres rotation

Applications using @prairielearn/postgres can inspect or rotate a ciphertext column with a single-column primary key:

import { runPostgresEncryptedColumnOperation } from '@prairielearn/encrypted-storage';

const result = await runPostgresEncryptedColumnOperation({
  mode: 'rotate',
  cipher,
  tableName: 'example_credentials',
  primaryKeyColumnName: 'id',
  ciphertextColumnName: 'encrypted_secret',
  nullable: false,
});

The operation validates the primary key, escapes every identifier, parameterizes every value, reads bounded batches in primary-key order, and uses compare-and-swap updates so concurrent writes are not overwritten. Set nullable: true to exclude nulls from the encrypted-value count and rotation; when it is false, an unexpected null fails validation. Rotation retries conflicts and refuses to report success unless a final scan authenticates every value with the primary key.

Applications should use a database-backed lock to serialize rotation commands. The shared operation cannot inspect the configuration of other deployed writers or prevent ordinary writes, so operators must ensure every writer uses the new primary key before rotation. Keep the fallback key configured until rotation and verification are complete.