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-wasmUsage
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 hereIn 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 hereExplicit 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 processthreshold: 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/roundssign_start(keyshareB64, digest32B64, chainPath)- Start DSG processsign_handle(stateBlobJson, peerMsgJson)- Handle DSG messages/roundsevm_address_from_sec1_pubkey_uncompressed()- Convert public key to EVM addressinit_panic_hook()- Initialize panic hook for debuggingwasm_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.jsTesting
# Run Rust tests
cargo test
# Run WASM tests in browser
wasm-pack test --chrome --headless
# Run WASM tests in Node.js
wasm-pack test --nodeDocumentation
- Project Overview & Architecture - Detailed technical documentation
- Analysis - Implementation analysis and notes
- Diagnosis - Known issues and debugging information
Components
- Tests - Integration and unit tests
- Benchmarks - Performance benchmarks
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
- Create an account on npmjs.com
- Login via CLI:
npm login - 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 publishPublishing 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 linkand 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 versionPackage 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 bindingspkg-node/- Node.js-optimized WASM and JS bindings- TypeScript definitions for both environments
License
MIT OR Apache-2.0