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

@haneinfo/credential-crypto

v0.1.0

Published

Pure Node AES-256-GCM encryption helpers for application-owned credentials.

Readme

@haneinfo/credential-crypto

Pure Node.js AES-256-GCM helpers for application-owned credentials. The package uses only node:crypto; it does not read environment variables or depend on NestJS, Prisma, or settings. Applications read their own configuration and pass canonical base64 keys to this package.

import {
  createCredentialKeyRing,
  decryptCredential,
  encryptCredential,
  parsePreviousCredentialKeys,
} from '@haneinfo/credential-crypto';

// Both calls throw CREDENTIAL_ENCRYPTION_UNAVAILABLE for a missing or invalid key or key list.
const ring = createCredentialKeyRing({
  active: process.env.REPORTS_CONNECTION_ENCRYPTION_KEY ?? '',
  previous: parsePreviousCredentialKeys(process.env.REPORTS_CONNECTION_PREVIOUS_KEYS),
});
const envelope = encryptCredential(ring, ['connection-id', 'password'], 'secret');
const secret = decryptCredential(ring, ['connection-id', 'password'], envelope);

CommonJS applications can load the same API with require('@haneinfo/credential-crypto'). The package is built as CommonJS and exposes TypeScript declarations for both module styles.

API

  • parseCredentialKey(raw) validates canonical base64 for exactly 32 bytes.
  • parsePreviousCredentialKeys(json) parses an optional JSON array of at most ten key strings.
  • credentialKeyId(key) returns the first 32 lowercase hex characters of SHA-256(key).
  • createCredentialKeyRing({ active, previous? }) validates the active and previous keys. Previous keys must be unique and different from the active key. The returned opaque ring keeps key bytes private and refuses JSON serialization.
  • encryptCredential(ring, aad, plaintext) encrypts with the active key. aad must be a nonempty string array and is encoded as JSON.stringify(aad).
  • decryptCredential(ring, aad, envelope, options?) decrypts current envelopes. Legacy envelopes are considered only when options.legacyAad is supplied; that byte sequence is used as their AAD.
  • inspectCredential(envelope) checks the envelope structure without decrypting and returns its format and current key id, or null for malformed input.
  • reencryptCredential(ring, aad, envelope, options?) re-encrypts legacy or previous-key data with the active key. It returns { changed: false } for a structurally valid current envelope already using the active key.

Invalid/missing active keys throw CREDENTIAL_ENCRYPTION_UNAVAILABLE. Invalid envelopes, AAD, unknown key ids, or authentication failures throw CREDENTIAL_DECRYPTION_FAILED; errors do not include the supplied key, AAD, plaintext, or envelope.

Envelope formats

New ciphertext uses five colon-separated fields:

v1:<key-id>:<nonce-base64>:<tag-base64>:<ciphertext-base64>

The nonce is 12 random bytes, the authentication tag is 16 bytes, and all base64 fields must be canonical. The cipher is AES-256-GCM with a 16-byte authentication tag. Reports AAD remains [connectionId, field].

The esign legacy format has four fields and no key id:

v1:<nonce-base64>:<tag-base64>:<ciphertext-base64>

It is read only when the caller supplies the original credential id bytes as legacyAad. New writes always use the five-field format.

Key rotation

  1. Generate a new 32-byte key and make it active. Keep the previous active key in previous.
  2. Deploy the application with both keys configured. Reads accept either key; writes use only the active key.
  3. Use inspectCredential to count key ids without decrypting, then call reencryptCredential in the application's transactionally safe maintenance workflow for each stored value.
  4. Confirm the old key count is zero, then remove it from the previous-key list.

The package does not provide persistence or a database migration script. Each application owns its transaction boundaries, maintenance controls, and secret backup procedure.

Settings boundary

This package does not use @haneinfo/settings. Settings are for runtime-adjustable nonsecret values; credential keys and connection secrets stay in the application's secret configuration and storage.