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

@wataruoguchi/emmett-crypto-shredding-kysely

v2.2.9

Published

Kysely adapters for Emmett Crypto Shredding

Downloads

572

Readme

@wataruoguchi/emmett-crypto-shredding-kysely

Kysely adapters for Emmett Crypto Shredding, providing PostgreSQL implementations for key storage and policy storage.

📚 Documentation

👉 View Complete Documentation →

What This Package Does

This package provides Kysely-specific database adapters for:

  • Key Storage - PostgreSQL implementation of the KeyStorage interface
  • Policy Storage - PostgreSQL implementation of the PolicyStorage interface
  • Policy Management - Utilities for managing encryption policies in the database

The actual encryption/decryption logic, key rotation, and crypto shredding functionality are provided by @wataruoguchi/emmett-crypto-shredding.

Installation

npm install @wataruoguchi/emmett-crypto-shredding-kysely @wataruoguchi/emmett-crypto-shredding kysely pg

Quick Start

1. Run Database Migration

Copy the migration file from database/migrations/1761627233034_crypto_shredding.ts to your migrations directory and run it.

2. Create Encryption Policies

⚠️ Important: Create policies before encrypting events (typically during tenant onboarding):

import { createPolicies } from '@wataruoguchi/emmett-crypto-shredding-kysely';

// Example: During tenant onboarding
await createPolicies(db, [
  {
    policyId: `${tenantId}-generator`,
    partition: tenantId,
    streamTypeClass: 'generator', // Stream type to encrypt
    encryptionAlgorithm: 'AES-GCM',
    keyRotationIntervalDays: 180,
    keyScope: 'stream', // 'stream' or 'type'
  },
]);

Or use default policies:

import { createDefaultPolicies } from '@wataruoguchi/emmett-crypto-shredding-kysely';

// Creates policies for 'user-data' and 'audit-log' stream types
await createDefaultPolicies(db, tenantId);

3. Create Encrypted Event Store

Wire up the crypto event store in your module:

import { 
  createCryptoEventStore,
  createWebCryptoProvider,
} from '@wataruoguchi/emmett-crypto-shredding';
import {
  createKeyManagement,
  createPolicyResolver,
} from '@wataruoguchi/emmett-crypto-shredding-kysely';
import { getKyselyEventStore } from '@wataruoguchi/emmett-event-store-kysely';

export function createMyModule({ db, logger }) {
  const eventStore = createCryptoEventStore(
    getKyselyEventStore({ db, logger }),
    {
      policy: createPolicyResolver(db, logger),
      keys: createKeyManagement(db),
      crypto: createWebCryptoProvider(),
      buildAAD: ({ partition, streamId }) =>
        new TextEncoder().encode(`${partition}:${streamId}`),
      logger,
    },
  );
  
  // Use eventStore with your event handlers...
}

API Reference

Key Management

createKeyManagement(db: Kysely<any> | any): KeyManagement

Creates a key management service backed by PostgreSQL.

createKeyStorage(db: Kysely<any> | any): KeyStorage

Creates a lower-level key storage adapter (if you need direct access).

Policy Resolution

createPolicyResolver(db: Kysely<any> | any, logger?: Logger): EncryptionPolicyResolver

Creates a policy resolver backed by PostgreSQL.

createPolicyStorage(db: Kysely<any> | any, logger?: Logger): PolicyStorage

Creates a lower-level policy storage adapter.

Policy Management

createPolicies(db: Kysely<any> | any, policies: DatabasePolicyConfig[]): Promise<void>

Create multiple encryption policies in a single batch operation.

createDefaultPolicies(db: Kysely<any> | any, partition: string): Promise<void>

Create default encryption policies for a partition using the default policy configuration.

updatePolicy(db: Kysely<any> | any, policyId: string, partition: string, updates: {...}): Promise<void>

Update an existing encryption policy.

deletePolicy(db: Kysely<any> | any, policyId: string, partition: string): Promise<void>

Delete an encryption policy.

listPolicies(db: Kysely<any> | any, partition: string): Promise<PolicyRecord[]>

List all policies for a partition.

See Also

License

MIT