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

crypto-mpc

v1.0.1

Published

2-party MPC (ECDSA, EdDSA, BIP32) compiled to WebAssembly with TypeScript bindings

Downloads

253

Readme

crypto-mpc

2-party MPC (ECDSA, EdDSA, BIP32) compiled to WebAssembly with TypeScript bindings.

Split blockchain wallet keys between two peers so the full private key never exists in one place. Based on the blockchain-crypto-mpc C++ library by Unbound Security.

Features

  • 2-party ECDSA (secp256k1) — key generation, signing, verification
  • 2-party EdDSA (ed25519) — key generation, signing, verification
  • BIP32 HD key derivation (hardened & normal)
  • Key refresh — re-split shares without changing the underlying key
  • Backup — zero-knowledge backup for EdDSA and ECDSA keys
  • Generic secrets — generate or import shared secrets
  • Private key reconstruction — combine both ECDSA shares to recover the full key
  • Works in Node.js, Bun, and browsers

Install

npm install crypto-mpc

Quick Start

import { load } from "crypto-mpc/load";

const { peer1, peer2 } = await load();

// Generate an EdDSA key pair (split between two peers)
const ctx1 = peer1.generateEddsaKey();
const ctx2 = peer2.generateEddsaKey();
MPCPeer.runProtocol(ctx1, ctx2);

const share1 = ctx1.getShare();
const share2 = ctx2.getShare();
ctx1.free();
ctx2.free();

// Sign a message
const message = new TextEncoder().encode("hello MPC");
const signCtx1 = peer1.signEddsa(share1, message);
const signCtx2 = peer2.signEddsa(share2, message);
MPCPeer.runProtocol(signCtx1, signCtx2);

const signature = peer1.getEddsaSignResult(signCtx1);
signCtx1.free();
signCtx2.free();

// Verify
const valid = peer1.verifyEddsa(
  peer1.getEddsaPublic(share1),
  message,
  signature,
);
console.log("valid:", valid); // true

Note: Import MPCPeer from "crypto-mpc" when using the class directly.

Loading

The crypto-mpc/load entry point auto-detects your environment:

import { load } from "crypto-mpc/load";

const { module, peer1, peer2, createPeer } = await load();

Returns:

  • module — raw Emscripten module
  • peer1 / peer2 — pre-configured MPCPeer instances
  • createPeer(peer) — create additional peer instances

For manual loading (e.g., custom WASM path in browser):

import { createPeer } from "crypto-mpc";

const createModule = await import("./wasm/mpc_crypto.js");
const wasmModule = await createModule.default();
const peer1 = createPeer(wasmModule, 1);
const peer2 = createPeer(wasmModule, 2);

Protocol Pattern

All MPC operations follow the same pattern:

  1. Both peers create a context for the operation
  2. Run the protocol (peers exchange messages until finished)
  3. Extract the result
  4. Free the contexts
// The static helper runs the full protocol locally:
MPCPeer.runProtocol(ctx1, ctx2);

// For network-separated peers, use step() manually:
let msg = null;
while (true) {
  const r1 = ctx1.step(msg);
  if (r1.finished) break;
  const r2 = ctx2.step(r1.message);
  if (r2.finished) break;
  msg = r2.message;
}

API Reference

MPCPeer

Key Generation

| Method | Description | |--------|-------------| | generateEddsaKey() | Start EdDSA (ed25519) key generation | | generateEcdsaKey() | Start ECDSA (secp256k1) key generation | | generateGenericSecret(bits) | Start generic shared secret generation | | importGenericSecret(key) | Import an existing secret into MPC shares |

Signing

| Method | Description | |--------|-------------| | signEddsa(share, data, refresh?) | Sign data with EdDSA (optionally refresh key) | | signEcdsa(share, data, refresh?) | Sign a 32-byte hash with ECDSA (optionally refresh key) |

Verification

| Method | Description | |--------|-------------| | verifyEddsa(pubKey, data, signature) | Verify an EdDSA signature | | verifyEcdsa(pubKey, data, signature) | Verify an ECDSA signature |

Key Operations

| Method | Description | |--------|-------------| | refreshKey(share) | Re-split share without changing the underlying key | | deriveBIP32(share, hardened, index) | Derive a BIP32 child key | | backupEddsaKey(share, pubBackupKey) | Create a zero-knowledge backup (EdDSA) | | backupEcdsaKey(share, pubBackupKey) | Create a zero-knowledge backup (ECDSA) |

Result Extraction

| Method | Description | |--------|-------------| | getEddsaSignResult(ctx) | Get 64-byte EdDSA signature | | getEcdsaSignResult(ctx) | Get ECDSA signature (DER-encoded) | | getDeriveBIP32Result(ctx) | Get derived child share | | getBackupEddsaResult(ctx) | Get EdDSA backup data | | getBackupEcdsaResult(ctx) | Get ECDSA backup data |

Info & Public Keys

| Method | Description | |--------|-------------| | getEddsaPublic(share) | Get 32-byte ed25519 public key | | getEcdsaPublic(share) | Get secp256k1 public key (DER-encoded) | | getShareInfo(share) | Get share metadata (uid, type) | | getBIP32Info(share) | Get BIP32 info (level, childNumber, chainCode, etc.) | | serializePubBIP32(share) | Get xpub string for an ECDSA share |

Reconstruction

| Method | Description | |--------|-------------| | reconstructEcdsaKey(share1, share2) | Reconstruct full ECDSA private key from both shares |

Context

| Method | Description | |--------|-------------| | step(inMessage) | Execute one protocol step | | getShare() | Get the updated share after protocol completes | | serialize() | Serialize context for storage/transmission | | free() | Release WASM memory |

StepResult

interface StepResult {
  finished: boolean;    // true when protocol is complete
  shareChanged: boolean; // true when share was updated (save it!)
  message: Uint8Array | null; // message to send to the other peer
}

Types

enum KeyType { EdDSA = 2, ECDSA = 3, GenericSecret = 4 }

interface ShareInfo { uid: bigint; type: KeyType }
interface BIP32Info {
  hardened: boolean;
  level: number;
  childNumber: number;
  parentFingerprint: number;
  chainCode: Uint8Array;
}

Browser Usage

<script type="module">
  import { MPCPeer } from "https://cdn.jsdelivr.net/npm/[email protected]/index.js";
  import { load } from "https://cdn.jsdelivr.net/npm/[email protected]/load.js";

  const { peer1, peer2 } = await load();

  // Generate an ECDSA key pair
  const ctx1 = peer1.generateEcdsaKey();
  const ctx2 = peer2.generateEcdsaKey();
  MPCPeer.runProtocol(ctx1, ctx2);

  const share1 = ctx1.getShare();
  const share2 = ctx2.getShare();
  ctx1.free();
  ctx2.free();

  console.log("Public key:", peer1.getEcdsaPublic(share1));
</script>

With a bundler (Vite, Webpack, etc.):

import { MPCPeer } from "crypto-mpc";
import { load } from "crypto-mpc/load";

const { peer1, peer2 } = await load();

Note: The WASM file (~3.3MB) is loaded automatically. The load() function uses import.meta.url to locate the wasm/ directory relative to the module.

2-of-3 Custody with Key Refresh

You can use key refresh to create a 2-of-3 scheme where any 2 of 3 parties can sign:

// Generate key: shares A1, B1
// Refresh once: shares A2, B2 (same underlying key)
// Refresh again: shares A3, B3

// Distribute:
// Party 1: A1 (as peer1), B2 (as peer2)
// Party 2: B1 (as peer2), A3 (as peer1)
// Party 3: A2 (as peer1), B3 (as peer2)

// Any pair of parties can sign together!

License

GPL-3.0-or-later