JSPM

dkls23-wasm

0.1.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 45
  • Score
    100M100P100Q73881F
  • License MIT OR Apache-2.0

WASM bindings for DKLs23 threshold cryptography (t-of-n DKG/DSG) supporting both web and Node.js environments

Package Exports

  • dkls23-wasm
  • dkls23-wasm/node
  • dkls23-wasm/web

Readme

dkls23-wasm

WASM-bindgen wrapper for DKLs23, implementing threshold distributed key generation (DKG) and distributed signing (DSG) for Ethereum-compatible cryptography. Supports t-of-n threshold schemes (e.g., 2-of-2, 2-of-3, 3-of-5, etc.). This project compiles Rust code to WebAssembly for use in web browsers and Node.js.

Installation

npm install dkls23-wasm

Usage

In Web Browser

import init, { 
  dkg_start, 
  dkg_handle, 
  sign_start, 
  sign_handle,
  evm_address_from_sec1_pubkey_uncompressed 
} from 'dkls23-wasm';

// Initialize WASM module
await init();

// Use the DKG/DSG functions
const dkgResult = dkg_start(/* parameters */);
// ... your code here

In Node.js

import pkg from 'dkls23-wasm';

// Direct usage - no init() needed for Node.js
const dkgResult = pkg.dkg_start(/* parameters */);
const signResult = pkg.sign_start(/* parameters */);
// ... your code here

Explicit Target Import

// Force web version
import init, { dkg_start } from 'dkls23-wasm/web';
await init();

// Force Node.js version  
import pkg from 'dkls23-wasm/node';
pkg.dkg_start(/* parameters */);

API Functions

  • dkg_start(partyId, threshold, parties, domainLabel) - Start DKG process
    • threshold: Number of parties required for signing (t)
    • parties: Total number of parties (n)
    • partyId: This party's identifier (0-based)
  • dkg_handle(stateBlobJson, peerMsgJson) - Handle DKG messages/rounds
  • sign_start(keyshareB64, digest32B64, chainPath) - Start DSG process
  • sign_handle(stateBlobJson, peerMsgJson) - Handle DSG messages/rounds
  • evm_address_from_sec1_pubkey_uncompressed() - Convert public key to EVM address
  • init_panic_hook() - Initialize panic hook for debugging
  • wasm_memory_info() - Get WASM memory usage information

Threshold Configuration Examples

// 2-of-2: Both parties needed for signing
const result = pkg.dkg_start(0, 2, 2, 'my-domain');

// 2-of-3: Any 2 of 3 parties can sign
const result = pkg.dkg_start(0, 2, 3, 'my-domain'); 

// 3-of-5: Any 3 of 5 parties can sign  
const result = pkg.dkg_start(0, 3, 5, 'my-domain');

// 5-of-7: Any 5 of 7 parties can sign
const result = pkg.dkg_start(0, 5, 7, 'my-domain');

Development

Building

# Build both targets
npm run build

# Or use the build script
./build.sh

# Build specific targets
npm run build:web    # Build for web browsers
npm run build:node   # Build for Node.js

Testing

# Run Rust tests
cargo test

# Run WASM tests in browser
wasm-pack test --chrome --headless

# Run WASM tests in Node.js
wasm-pack test --node

Documentation

Components

Core Features

DKG (Distributed Key Generation)

Multi-round protocol for generating shared keypairs in t-of-n threshold schemes. Supports any threshold configuration (2-of-2, 2-of-3, 3-of-5, etc.).

DSG (Distributed Signing)

Multi-round protocol for threshold ECDSA signatures using generated keypairs. Only requires t parties to cooperate for signing.

Publishing to npm

Prerequisites

  1. Create an account on npmjs.com
  2. Login via CLI: npm login
  3. Ensure the package name is available: check on npmjs.com or run npm view dkls23-wasm

Build and Publish

# 1. Build the package
./build.sh

# 2. Update version in package.json if needed
npm version patch  # or minor/major

# 3. Publish to npm
npm publish

Publishing Checklist

  • Update package version
  • Update repository URLs in package.json and Cargo.toml
  • Build both web and Node.js targets
  • Test the package locally: npm link and test in another project
  • Publish: npm publish
  • Verify publication: npm view dkls23-wasm

Local Testing

# Link the package locally
npm link

# In another project
npm link dkls23-wasm

# Test both environments
node -e "import('dkls23-wasm').then(console.log)"  # Node.js
# Import in browser and test web version

Package Structure

The published package supports dual environments through exports:

  • Default: Automatically chooses web or Node.js based on environment
  • Web: import from 'dkls23-wasm/web' - for browsers
  • Node: import from 'dkls23-wasm/node' - for Node.js

Files included in npm package:

  • pkg-web/ - Web-optimized WASM and JS bindings
  • pkg-node/ - Node.js-optimized WASM and JS bindings
  • TypeScript definitions for both environments

License

MIT OR Apache-2.0