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

dkey-lib

v1.2.0

Published

DKey library for encrypted file sharing with zero-knowledge proofs

Readme

dkey-lib

A TypeScript library for encrypted file sharing with zero-knowledge proofs on blockchain. Enables secure, decentralized file distribution with cryptographic access control.

Features

  • 🔐 Encrypted File Sharing: Encrypt files using BN254 elliptic curve cryptography
  • 🔑 Zero-Knowledge Proofs: Generate and verify ZK proofs for secure key distribution
  • 📦 IPFS Integration: Store encrypted files and metadata on IPFS
  • ⛓️ Blockchain Integration: Deploy listings, place bids, and manage DKeys on Ethereum-compatible chains
  • 🔄 Profile Management: Serialize and encrypt user profiles for secure storage
  • 🎯 TypeScript Support: Full TypeScript definitions included

Installation

npm install dkey-lib

Prerequisites

  • Node.js 18+
  • A wagmi config for blockchain interactions
  • Access to supported blockchain networks (Base, Ethereum, etc.)

Browser bundle

For plain JS/HTML/CSS frontends without a bundler, use the browser build. Load it with a script tag:

<!-- From node_modules (if you npm install dkey-lib) -->
<script src="node_modules/dkey-lib/dist/dkey-lib.browser.js"></script>

The API is exposed on window.dkeyLib:

  • Default export (the dkey object): window.dkeyLib.default or window.dkeyLib.dkey
  • Named exports: window.dkeyLib.DkeyUserProfile, window.dkeyLib.Listing, window.dkeyLib.ListingMetadata, window.dkeyLib.Bid, window.dkeyLib.DKey, window.dkeyLib.RESULTS, window.dkeyLib.BidLite

You must still copy the circuits folder from node_modules/dkey-lib/circuits to your public directory and configure paths:

<script>
  window.dkeyLib.dkey.configureCircuits('/circuits');
</script>

To build the browser bundle locally (e.g. after cloning the repo), run:

npm run build:browser

Quick Start

import dkey, { DkeyUserProfile, ListingMetadata } from 'dkey-lib';
import { createConfig } from '@wagmi/core';

// IMPORTANT: Copy the circuits folder from 'node_modules/dkey-lib/circuits'
// to your public/static directory, then configure the paths:
dkey.configureCircuits('/circuits'); // or './circuits' depending on your setup

// Initialize wagmi config
const config = createConfig({ /* your config */ });

// Create a user profile
const profile = new DkeyUserProfile(
  { fid: 123, fname: 'user' },
  {},
  {},
  {},
  {},
  config
);

// Create a listing
const metadata = new ListingMetadata(
  { fid: 123 },
  'example.pdf',
  'My file description',
  1024,
  0.1,
  'bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi',
  'https://example.com/cover.jpg',
  [8453], // Base chain
  1000
);

const result = await profile.createListing(
  ipfsCID,
  metadata,
  fileSecretKey,
  10, // howManyDKeysForSale
  5,  // royaltyPercentage
  address
);

Core Concepts

DkeyUserProfile

The main class for managing user interactions with the DKey protocol. Handles:

  • Creating and managing listings
  • Placing and managing bids
  • Acquiring and managing DKeys
  • Profile serialization/encryption

Listing

Represents a file listing on the blockchain. Contains:

  • IPFS CID of the encrypted file
  • File metadata
  • Encryption keys
  • Sales information

Bid

Represents a user's bid on a listing. Contains:

  • Bid amount
  • Public key for decryption
  • Bid status

DKey

Represents an acquired decryption key. Contains:

  • Encrypted file secret key
  • Decryption methods
  • Ownership information

API Reference

Main Exports

// Default export - utility functions
import dkey from 'dkey-lib';

// Named exports - classes and types
import {
  DkeyUserProfile,
  Listing,
  ListingMetadata,
  Bid,
  DKey,
  BidLite,
  RESULTS
} from 'dkey-lib';

Utility Functions

dkey.createKeyAndEncryptFile(data: ArrayBuffer)

Encrypts a file and generates encryption keys.

const { encryptedData, secretKeyX, secretKeyY } = 
  await dkey.createKeyAndEncryptFile(fileBuffer);

dkey.formatCID(cid: string)

Formats an IPFS CID into multiple representations.

const formatted = dkey.formatCID('bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi');
// Returns: { ipfsCIDBytes, ipfsCIDBytesString, hashedCid0xString, hashedCidString }

dkey.fetchListingDetails(ipfsCID, metadata, config)

Fetches listing details from the blockchain.

const details = await dkey.fetchListingDetails(ipfsCID, metadata, config);

dkey.configureCircuits(basePath?)

Configures circuit file paths for your environment. Call this once after importing the library.

import dkey from 'dkey-lib';

// Configure circuits to match where you serve them
dkey.configureCircuits('/public/circuits');
// or
dkey.configureCircuits('./circuits');

dkey.loadSnarkJS()

Dynamically loads the SnarkJS script in the browser environment.

await dkey.loadSnarkJS();

DkeyUserProfile Methods

createListing(...)

Creates a new file listing on the blockchain.

makeBid(...)

Places a bid on a listing.

fillBid(...)

Fills a bid (seller only).

sellDkey(...)

Sells an acquired DKey to another user.

checkIfDKeysCanBeSold(chainId)

Checks if DKeys are eligible for resale.

serialize() / deserialize()

Serialize/deserialize profile data.

toEncryptedProfileData(password) / fromEncryptedProfileData(...)

Encrypt/decrypt profile data for storage.

Supported Chains

  • Base (Chain ID: 8453)
  • Arbitrum (Chain ID: 42161)

Circuit Files

The library requires circuit files (.wasm, .zkey) to be accessible. By default, they're expected at:

./circuits/encryptAndHash_js/

When using this library, ensure the circuits/ folder is:

  • Copied to your public/static directory, or
  • Configured in your bundler to copy these assets

Then configure the paths to match your setup:

import dkey from 'dkey-lib';

// Configure circuit paths (call once after import)
dkey.configureCircuits('/public/circuits'); // or wherever you serve them

Development

# Install dependencies
npm install

# Build the library
npm run build

# Run tests
npm test

# Run tests in watch mode
npm run test:watch

# Run tests with coverage
npm run test:coverage

TypeScript

Full TypeScript support is included. The library exports type definitions in dist/index.d.ts.

License

MIT

Contributing

Contributions are welcome - shoot Noad an email at [email protected]!

Links