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

102 lines
2.9 KiB
Go

package main
import (
"fmt"
"log"
"os"
"github.com/spf13/viper"
"github.com/hanzoai/mpc/pkg/kms"
)
func main() {
// Initialize viper config
viper.SetConfigName("config")
viper.SetConfigType("yaml")
viper.AddConfigPath("..")
viper.AutomaticEnv()
if err := viper.ReadInConfig(); err != nil {
log.Printf("Warning: Could not read config file: %v", err)
}
// Create Lux KMS client
config := kms.KMSConfig{
ClientID: viper.GetString("kms.client_id"),
ClientSecret: viper.GetString("kms.client_secret"),
ProjectID: viper.GetString("kms.project_id"),
Environment: viper.GetString("kms.environment"),
SecretPath: viper.GetString("kms.secret_path"),
SiteURL: viper.GetString("kms.site_url"),
}
// Check environment variable fallback
if config.ProjectID == "" {
config.ProjectID = os.Getenv("KMS_PROJECT_ID")
}
fmt.Printf("Lux KMS Configuration:\n")
fmt.Printf(" Site URL: %s\n", config.SiteURL)
fmt.Printf(" Project ID: %s\n", config.ProjectID)
fmt.Printf(" Environment: %s\n", config.Environment)
fmt.Printf(" Secret Path: %s\n", config.SecretPath)
fmt.Printf(" Has Universal Auth: %v\n", config.ClientID != "")
fmt.Printf(" Has Service Token: %v\n", os.Getenv("KMS_TOKEN") != "")
client, err := kms.NewKMSClient(config)
if err != nil {
log.Fatalf("Failed to create Lux KMS client: %v", err)
}
fmt.Println("\n✅ Successfully connected to Lux KMS!")
// Test storing a dummy key share
testNodeID := "test-node"
testWalletID := "test-wallet"
testKeyType := "ecdsa"
testKeyData := []byte(`{"test": "data", "key": "12345"}`)
fmt.Printf("\nTesting key storage...\n")
if err := client.StoreMPCKeyShare(testNodeID, testWalletID, testKeyType, testKeyData); err != nil {
log.Fatalf("Failed to store test key: %v", err)
}
fmt.Println("✅ Successfully stored test key!")
// Test retrieving the key
fmt.Printf("\nTesting key retrieval...\n")
retrievedData, err := client.RetrieveMPCKeyShare(testNodeID, testWalletID, testKeyType)
if err != nil {
log.Fatalf("Failed to retrieve test key: %v", err)
}
if string(retrievedData) == string(testKeyData) {
fmt.Println("✅ Successfully retrieved test key with correct data!")
} else {
fmt.Printf("⚠️ Retrieved data doesn't match: got %s, want %s\n", string(retrievedData), string(testKeyData))
}
// List all keys
fmt.Printf("\nListing all keys...\n")
keys, err := client.ListKeys()
if err != nil {
log.Fatalf("Failed to list keys: %v", err)
}
fmt.Printf("Found %d keys:\n", len(keys))
for _, key := range keys {
fmt.Printf(" - %s\n", key)
}
// Clean up test key
fmt.Printf("\nCleaning up test key...\n")
secretName := fmt.Sprintf("mpc_%s_%s_%s", testNodeID, testWalletID, testKeyType)
if err := client.DeleteKey(secretName); err != nil {
log.Printf("Warning: Failed to delete test key: %v", err)
} else {
fmt.Println("✅ Successfully cleaned up test key!")
}
fmt.Println("\n🎉 All tests passed! Lux KMS integration is working correctly.")
}