Files
zeekay 19b49809fd Implement threshold MPC signing with CGGMP21, FROST, and LSS protocols
This commit adds complete multi-party computation (MPC) threshold signing
for multiple cryptographic protocols:

CGGMP21 (ECDSA/secp256k1):
- Key generation for Bitcoin/Ethereum/EVM chains
- Threshold signing with t-of-n security
- Recovery byte calculation for Ethereum compatibility

FROST/Taproot (EdDSA/BIP-340):
- EdDSA key generation for Solana/Sui/Polkadot
- BIP-340 compatible Schnorr signatures (64 bytes)
- CBOR serialization for TaprootConfig crypto types

LSS (Linear Secret Sharing):
- Dynamic resharing support (change participants)
- ECDSA signing with blinding protocol
- Protocol adapter for unified interface

Key fixes:
- Use MarshalBinary/UnmarshalBinary for protocol messages
- CBOR serialization for FROST TaprootConfig (not JSON)
- Correct type assertion for taproot.Signature ([]byte)
- Sorted party IDs for deterministic ordering

E2E tests pass for both ECDSA and EdDSA signing.
2026-01-24 23:41:43 -08:00

77 lines
1.8 KiB
Go

package main
import (
"fmt"
"log"
"strings"
"github.com/hashicorp/consul/api"
"github.com/hanzoai/mpc/pkg/config"
"github.com/hanzoai/mpc/pkg/logger"
)
// script to add key type prefix ecdsa for existing keys
func main() {
config.InitViperConfig()
logger.Init("production", false)
appConfig := config.LoadConfig()
logger.Info("App config", "config", appConfig)
consulClient := NewConsulClient(appConfig.Consul.Address)
kv := consulClient.KV()
// Get a handle to the KV API
// List all keys with the specified prefix
prefix := "threshold_keyinfo"
keys, _, err := kv.Keys(prefix, "", nil)
if err != nil {
log.Fatal(err)
}
// Print the keys
// fmt.Printf("Keys with prefix \"%s\":\n", prefix)
for _, key := range keys {
if !strings.Contains(key, "ecdsa") && !strings.Contains(key, "eddsa") {
pair, _, err := kv.Get(key, nil)
if err != nil {
log.Fatal(err)
}
// Define variables to store the extracted values
var walletID string
// Use fmt.Sscanf to extract the values
_, err = fmt.Sscanf(key, "threshold_keyinfo/%s", &walletID)
if err != nil {
fmt.Println("Error:", err)
return
}
if walletID != "" {
if _, err := kv.Put(&api.KVPair{Key: fmt.Sprintf("threshold_keyinfo/ecdsa:%s", walletID), Value: pair.Value}, nil); err != nil {
log.Printf("Failed to put key for wallet %s: %v", walletID, err)
}
if _, err := kv.Delete(key, nil); err != nil {
log.Printf("Failed to delete key %s: %v", key, err)
}
}
}
fmt.Println(key)
}
}
func NewConsulClient(addr string) *api.Client {
// Create a new Consul client
consulConfig := api.DefaultConfig()
consulConfig.Address = addr
consulClient, err := api.NewClient(consulConfig)
if err != nil {
logger.Fatal("Failed to create consul client", err)
}
logger.Info("Connected to consul!")
return consulClient
}