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

@vollcrypt/db-guard

v0.1.2

Published

Database field-level encryption integrations for Vollcrypt (Prisma, Mongoose, Drizzle, TypeORM)

Downloads

448

Readme

db-guard

Application-level, field-level encryption integrations for ORMs (Prisma, Mongoose, Drizzle, TypeORM, Diesel, SeaORM) powered by FIPS-compliant cryptography.

db-guard secures sensitive database columns (SSN, credit card numbers, addresses, personal data) by encrypting them before they hit the database. It prevents data leakage from compromised database dumps, unauthorized database connections, or compromised database administrators (DBAs).


Key Features

  • Multi-ORM Support: Integrations for Node.js (Prisma, Mongoose, Drizzle, TypeORM) and Rust (Diesel, SeaORM).
  • Dynamic Multi-Tenant Routing: Dynamically resolves distinct KMS keys or database configurations per request context using AsyncLocalStorage.
  • Secure Key Cache: Protects memory from dumps using an ephemeral master key generated randomly at boot. Plaint-text DEKs are wrapped with AES-256-KW and cached with automated TTL eviction and zeroization.
  • Schema Evolution & Crypto-Agility: Features backward-compatible prefixes for smooth algorithm transitions without database downtime.
  • M-of-N Break-Glass Protocol: Emergency KMS bypass via threshold Ed25519 signature verification.
  • Compliance Scorecard CLI: Built-in CLI scans configuration and outputs compliance scorecards for GDPR Article 32, KVKK Article 12, and PCI-DSS v4.0.
  • Supply Chain Security (SLSA Level 4): Build pipeline automatically compiles CycloneDX SBOM and SLSA Level 4 Provenance files, cryptographically signed with Ed25519.
  • FIPS 140-3 & Post-Quantum Hybrid Transition: Conforms to FIPS 140-3 logical and physical boundaries with NIST FIPS 203 (ML-KEM) lattice-based algorithms registered for hybrid key exchange.
  • Hardened Blind Indexing: Allows exact-match querying on encrypted columns via HKDF-SHA256 shadow columns, avoiding frequency analysis vulnerabilities.
  • RAM Security: Aggressive memory zeroization (null-byte writing) for keys and plaintext buffers in memory.
  • Batch Migration CLI: Built-in CLI tool to perform chunked shadow database migrations in the background.

Installation

For Node.js (Prisma, Mongoose, Drizzle, TypeORM):

npm install @vollcrypt/db-guard

For Rust (Diesel, SeaORM):

# Cargo.toml
[dependencies]
vollcrypt-db-guard = { path = "db-guard/rust", features = ["sqlite", "sea-orm"] }

Configuration & Usage

1. Prisma ORM (TypeScript)

Register prismaDbGuard extension on your client:

import { PrismaClient } from '@prisma/client';
import { prismaDbGuard } from '@vollcrypt/db-guard';

const key = Buffer.from('your-secure-32-byte-encryption-key-here');

const basePrisma = new PrismaClient();
export const prisma = basePrisma.$extends(
  prismaDbGuard({
    key,
    models: {
      User: ['credit_card', 'ssn'],
    },
  })
);

2. Mongoose (TypeScript)

Register mongooseDbGuard as a schema plugin:

import { Schema, model } from 'mongoose';
import { mongooseDbGuard } from '@vollcrypt/db-guard';

const key = Buffer.from('your-secure-32-byte-encryption-key-here');

const UserSchema = new Schema({
  name: String,
  credit_card: String,
});

UserSchema.plugin(mongooseDbGuard, {
  key,
  fields: ['credit_card'],
});

export const User = model('User', UserSchema);

3. Drizzle ORM (TypeScript)

Use the createDrizzleGuard factory to declare encrypted text columns:

import { pgTable, serial } from 'drizzle-orm/pg-core';
import { createDrizzleGuard } from '@vollcrypt/db-guard';

const guard = createDrizzleGuard({
  key: Buffer.from('your-secure-32-byte-encryption-key-here'),
});

export const users = pgTable('users', {
  id: serial('id').primaryKey(),
  creditCard: guard.pgText('credit_card'), // Automatically encrypted/decrypted
});

4. TypeORM (TypeScript)

Define your entity subscribers using createTypeOrmSubscriber:

import { DataSource } from 'typeorm';
import { createTypeOrmSubscriber } from '@vollcrypt/db-guard';

const key = Buffer.from('your-secure-32-byte-encryption-key-here');

const VollcryptSubscriber = createTypeOrmSubscriber({
  key,
  entities: {
    User: ['credit_card', 'ssn'],
  },
});

export const AppDataSource = new DataSource({
  subscribers: [VollcryptSubscriber],
});

5. Diesel (Rust)

Use EncryptedString in your schema and models:

use diesel::prelude::*;
use vollcrypt_db_guard::diesel_impl::EncryptedString;

#[derive(Queryable, Selectable, Insertable)]
#[diesel(table_name = users)]
pub struct User {
    pub id: i32,
    pub name: String,
    pub credit_card: EncryptedString,
}

6. SeaORM (Rust)

Use the SeaORM-compatible EncryptedString type wrapper:

use sea_orm::entity::prelude::*;
use vollcrypt_db_guard::seaorm_impl::EncryptedString;

#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "users")]
pub struct Model {
    #[sea_orm(primary_key)]
    pub id: i32,
    pub name: String,
    pub credit_card: EncryptedString,
}

Initialize your keys at application boot for Rust:

use vollcrypt_db_guard::{set_key, set_active_version};

fn main() {
    let key = [0u8; 32]; // Secure 32-byte key
    set_key("1", &key);
    set_active_version("1").unwrap();
}

Cloud & On-Premises KMS Providers

db-guard supports multiple key management systems (KMS) and hardware security modules (HSM) to resolve keys dynamically for envelope encryption.

1. Node.js KMS Providers

We provide several KmsProvider implementations:

  • AwsKmsProvider: Resolves keys using AWS KMS.
  • GcpKmsProvider: Resolves keys using Google Cloud KMS.
  • VaultKmsProvider: Resolves keys using HashiCorp Vault.
  • Pkcs11KmsProvider: Interacts with physical or virtual HSMs (YubiHSM2, Thales, Nitrokey, SoftHSM2, etc.) using the standard PKCS#11 protocol.

Node.js PKCS#11 Configuration Example:

import { Pkcs11KmsProvider } from '@vollcrypt/db-guard';

const kmsProvider = new Pkcs11KmsProvider({
  libraryPath: '/usr/local/lib/softhsm/libsofthsm2.so', // Path to vendor PKCS#11 library
  pin: '123456',                                      // Slot/Token PIN
  slotId: 0,                                          // Target Slot Index (optional, default: 0)
  keyId: '000102',                                    // Hex-encoded CKA_ID of the AES-256 key in HSM
});

// Decrypt wrapped key (DEK) inside HSM
const decryptedKey = await kmsProvider.decrypt(wrappedKeyBuffer);

2. Rust PKCS#11 Support

To use PKCS#11 in Rust, enable the pkcs11 feature:

# Cargo.toml
[dependencies]
vollcrypt-db-guard = { path = "db-guard/rust", features = ["sqlite", "pkcs11"] }

You can then decrypt wrapped keys directly inside your HSM:

use vollcrypt_db_guard::pkcs11_impl::decrypt_with_hsm;

let decrypted = decrypt_with_hsm(
    "/usr/local/lib/softhsm/libsofthsm2.so", // Path to PKCS#11 module
    "123456",                               // PIN
    Some(0),                                // Slot ID
    "010203",                               // Hex CKA_ID
    &wrapped_data,                          // Ciphertext containing wrapped DEK
).unwrap();

CLI Commands

The package includes a dual-purpose CLI tool for database migrations and compliance auditing.

1. Database Migrations (migrate)

Encrypts existing plaintext records in a live database using batch processing:

# Run PostgreSQL migration
npx vollcrypt-db-guard migrate \
  --db-type postgres \
  --db-url "postgres://user:pass@localhost:5432/db" \
  --table users \
  --column credit_card \
  --key "your_32_byte_hex_key_here" \
  --chunk-size 100 \
  --id-col id

# Run MongoDB migration
npx vollcrypt-db-guard migrate \
  --db-type mongodb \
  --db-url "mongodb://localhost:27017/db" \
  --table users \
  --column credit_card \
  --key "your_32_byte_hex_key_here" \
  --chunk-size 100 \
  --id-col _id

2. Compliance Scorecard Generator (compliance)

Scans cryptographic configurations and generates an auditor-ready HTML compliance report:

npx vollcrypt-db-guard compliance \
  --config compliance-config.json \
  --output compliance-report.html

Supply Chain & Compliance Verification

Refer to the following standalone validation documentation for formal verification processes:

  • Supply Chain Artifacts: Signed CycloneDX SBOM and SLSA Level 4 Provenance are located in dist/sbom.json and dist/provenance.json post-build.
  • FIPS 140-3 Boundaries: Detailed logical boundaries, Approved algorithm registries, and post-quantum hybrid structures are defined in FIPS_VALIDATION.md.