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

@cryptforge/key-exchange

v0.2.1

Published

Peer-to-peer key exchange and device synchronization for CryptForge

Downloads

263

Readme

@cryptforge/key-exchange

Key exchange package for CryptForge SDK. Provides secure key exchange functionality across different environments: browser, Node.js server, and Electron.

Installation

npm install @cryptforge/key-exchange

Usage

This package provides separate entry points for different environments to ensure safe usage without mixing incompatible APIs.

Browser/Web Client

import { KeyTransportClient } from "@cryptforge/key-exchange";

const client = new KeyTransportClient("ws://localhost:3001");
const broadcastId = await client.enableBroadcast();

Node.js Server

import { KeyExchangeServer } from "@cryptforge/key-exchange/server";

const server = new KeyExchangeServer();
await server.start();

Electron

Electron has three separate contexts that must not be mixed:

Main Process (Node.js environment)

// In your main.js or main.ts
import {} from /* your exports */ "@cryptforge/key-exchange/electron-main";

// Main process code with access to Node.js and Electron APIs

Preload Script (Isolated context)

// In your preload.js or preload.ts
import {} from /* your exports */ "@cryptforge/key-exchange/electron-preload";

// Preload script that bridges main and renderer processes
// Use contextBridge to safely expose APIs to renderer

Renderer Process (Browser-like environment)

// In your renderer/app code
import {} from /* your exports */ "@cryptforge/key-exchange/electron-renderer";

// Renderer process code - browser-like environment

Architecture

Why Separate Entry Points?

Each environment has different capabilities and restrictions:

  • Browser (/): No Node.js APIs, WebSocket only
  • Server (/server): Full Node.js APIs, can use hyperswarm
  • Electron Main (/electron-main): Node.js + Electron main process APIs
  • Electron Preload (/electron-preload): Limited Node.js APIs in isolated context
  • Electron Renderer (/electron-renderer): Browser-like with IPC to main process

Mixing these would cause runtime errors or security issues.

Project Structure

src/
├── index.ts              # Browser/web client entry point
├── server.ts             # Node.js server entry point
├── electron-main.ts      # Electron main process entry point
├── electron-preload.ts   # Electron preload script entry point
├── electron-renderer.ts  # Electron renderer process entry point
├── client/               # Browser client implementation
├── server/               # Server implementation
├── electron/
│   ├── main/            # Electron main process code
│   ├── preload/         # Electron preload script code
│   └── renderer/        # Electron renderer process code
└── types/               # Shared TypeScript types

Features

  • Secure key exchange protocol
  • Browser and Node.js support
  • Full Electron support (main, preload, renderer)
  • TypeScript support with full type definitions
  • WebSocket-based communication for web/browser
  • Hyperswarm support for server-to-server

Vite Plugin (Electron Main Process)

When building Electron apps with Vite, native Node.js modules need to be externalized to prevent bundling errors. The package includes a Vite plugin that automatically handles this for you.

Usage

// vite.main.config.ts (for Electron main process)
import { defineConfig } from "vite";
import { cryptforgeMainPlugin } from "@cryptforge/key-exchange/vite";

export default defineConfig({
  plugins: [cryptforgeMainPlugin()],
  // ... rest of your config
});

What it does

The plugin automatically externalizes these native modules:

  • hyperswarm, hyperdht, udx-native, utp-native
  • sodium-native, hypercore, hypercore-crypto
  • random-access-file, compact-encoding, b4a
  • @cryptforge/key-exchange

Without the plugin

If you prefer manual configuration or need to customize, you can add externals manually:

export default defineConfig({
  build: {
    rollupOptions: {
      external: [
        "hyperswarm",
        "hyperdht",
        "udx-native",
        // ... other native modules
      ],
    },
  },
});

Important Notes

  • ⚠️ Only use this plugin for Electron main process builds
  • ✅ The plugin merges with your existing external configuration
  • ✅ Works with both array and function forms of external
  • ✅ Supports custom build tools that use Rollup

Additional Documentation

License

ISC