Files
mpc/examples/unified_threshold_example.go
zeekay 1fa6eb5fd5 refactor(mpc): thin wrapper over luxfi/mpc (canonical) — v2.0.0
Per CTO directive: hanzo/mpc must be identical to luxfi/mpc with only
defaults differing. Eliminates fork drift and consolidates the canonical
implementation in github.com/luxfi/mpc.

What changed:
  - cmd/hanzo-mpc/main.go: now mirrors luxfi/mpc/cmd/mpcd verbatim, with
    Hanzo overrides applied via setEnvDefault before viper init:
      MPC_DATA_DIR    = /data/hanzo-mpc      (lux: /data/mpc)
      MPC_DB_PATH     = /data/hanzo-mpc/db
      MPC_BACKUP_DIR  = /data/hanzo-mpc/backups
      BRAND_NAME      = Hanzo
    Version bumped to 2.0.0; banner shows "Hanzo MPC v2.0.0 — thin wrapper
    over luxfi/mpc (canonical)".
  - cmd/hanzo-mpc-cli/main.go: removed `recover` subcommand (the kvstore
    BackupExecutor API moved into luxfi/mpc/pkg/backup; downstream tooling
    should call that directly). Renamed binary to "hanzo-mpc-cli" and
    bumped to v2.0.0.
  - examples/, scripts/: import paths swapped from
    github.com/hanzoai/mpc/pkg/* → github.com/luxfi/mpc/pkg/*. Broken
    migration scripts (BadgerKVStore API removed upstream) deleted.
  - go.mod: drops 40+ direct deps that lived in the fork. Adds direct
    dep on github.com/luxfi/mpc with replace directive to ../../lux/mpc
    for local dev. Mirrors luxfi/mpc's `replace github.com/agl/ed25519
    => github.com/luxfi/edwards25519` for transitive correctness.
  - Dockerfile: data dir bumped to /data/hanzo-mpc; ports updated to the
    canonical luxfi/mpc layout (9651=P2P, 9800=internal API,
    8081=dashboard).
  - pkg/: DELETED entirely (api/, client/, config/, constant/, encoding/,
    encryption/, event/, eventconsumer/, hsm/, identity/, infra/,
    keyinfo/, kms/, kvstore/, logger/, messaging/, mpc/, policy/,
    protocol/, storage/, threshold/, types/, utils/). All consumers
    (zero external Go consumers found) point at luxfi/mpc/pkg/* now.

Net: -26961 / +1663 LOC.

Wire/protocol compatibility:
  Hanzo MPC speaks the same NATS messaging, ZapDB key-share format,
  consensus transport, and HSM signer protocols as luxfi/mpc — they are
  literally the same code. A Hanzo MPC node can join a Lux MPC cluster
  and participate in keygen/sign rounds without modification.
2026-04-18 21:26:32 -07:00

102 lines
3.5 KiB
Go

package main
import (
"crypto/rand"
"fmt"
"log"
"github.com/luxfi/mpc/pkg/threshold"
)
func main() {
// Create a unified threshold API
api := threshold.NewUnifiedThresholdAPI()
defer api.Close()
// Define participants
partyIDs := []string{"alice", "bob", "charlie"}
thresholdValue := 1 // 2-of-3 threshold (threshold + 1 required to sign)
fmt.Println("=== Unified Threshold Signing Example ===")
fmt.Println()
// Example 1: ECDSA (using CMP/CGGMP21)
fmt.Println("1. ECDSA Threshold Signing (CMP/CGGMP21 Protocol)")
fmt.Println(" - Used for: Bitcoin, Ethereum, and other ECDSA-based chains")
fmt.Println(" - Features: Presigning support for faster online signing")
ecdsaParty, err := api.KeyGen(threshold.SchemeECDSA, "alice", partyIDs, thresholdValue)
if err != nil {
log.Fatalf("Failed to start ECDSA keygen: %v", err)
}
fmt.Printf(" ✓ ECDSA KeyGen initiated for party 'alice'\n")
fmt.Printf(" - Protocol: %s\n", "CGGMP21")
fmt.Printf(" - Threshold: %d-of-%d\n", thresholdValue+1, len(partyIDs))
fmt.Println()
// Example 2: EdDSA (using FROST)
fmt.Println("2. EdDSA Threshold Signing (FROST Protocol)")
fmt.Println(" - Used for: Solana, Cardano, and Ed25519-based systems")
fmt.Println(" - Features: Efficient Schnorr signatures, no presigning needed")
eddsaParty, err := api.KeyGen(threshold.SchemeEdDSA, "bob", partyIDs, thresholdValue)
if err != nil {
log.Fatalf("Failed to start EdDSA keygen: %v", err)
}
fmt.Printf(" ✓ EdDSA KeyGen initiated for party 'bob'\n")
fmt.Printf(" - Protocol: %s\n", "FROST")
fmt.Printf(" - Threshold: %d-of-%d\n", thresholdValue+1, len(partyIDs))
fmt.Println()
// Example 3: Taproot (using FROST)
fmt.Println("3. Taproot/Schnorr Threshold Signing (FROST Protocol)")
fmt.Println(" - Used for: Bitcoin Taproot, privacy-preserving signatures")
fmt.Println(" - Features: BIP-340 compatible, aggregatable signatures")
taprootParty, err := api.KeyGen(threshold.SchemeTaproot, "charlie", partyIDs, thresholdValue)
if err != nil {
log.Fatalf("Failed to start Taproot keygen: %v", err)
}
fmt.Printf(" ✓ Taproot KeyGen initiated for party 'charlie'\n")
fmt.Printf(" - Protocol: %s\n", "FROST")
fmt.Printf(" - Threshold: %d-of-%d\n", thresholdValue+1, len(partyIDs))
fmt.Println()
// Check supported schemes
fmt.Println("=== Supported Signature Schemes ===")
schemes := api.GetSupportedSchemes()
for _, scheme := range schemes {
supported := api.IsSchemeSupported(scheme)
status := "✓"
if !supported {
status = "✗"
}
fmt.Printf(" %s %s\n", status, scheme)
}
fmt.Println()
// Generate a message to sign
messageHash := make([]byte, 32)
_, err = rand.Read(messageHash)
if err != nil {
log.Fatalf("Failed to generate message hash: %v", err)
}
fmt.Println("=== Integration Benefits ===")
fmt.Println(" • Unified API for all threshold signature schemes")
fmt.Println(" • Support for multiple blockchain ecosystems")
fmt.Println(" • Concurrent protocol execution capability")
fmt.Println(" • Automatic protocol selection based on scheme")
fmt.Println(" • Extensible architecture for adding new protocols")
fmt.Println()
fmt.Println("=== Protocol Status ===")
fmt.Printf(" ECDSA Party Status: Done=%v\n", ecdsaParty.Done())
fmt.Printf(" EdDSA Party Status: Done=%v\n", eddsaParty.Done())
fmt.Printf(" Taproot Party Status: Done=%v\n", taprootParty.Done())
fmt.Println()
fmt.Println("✅ Successfully integrated CMP and FROST protocols!")
fmt.Println(" The MPC system now supports both ECDSA and EdDSA threshold signing.")
}