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

81 lines
2.8 KiB
Go

package event
const (
SigningPublisherStream = "mpc-signing"
SigningConsumerStream = "mpc-signing-consumer"
SigningRequestTopic = "mpc.signing_request.*"
SigningResultTopic = "mpc.mpc_signing_result.*" // Pattern for subscribing (with wildcard)
SigningResultTopicBase = "mpc.mpc_signing_result" // Base topic for publishing (no wildcard)
SigningResultCompleteTopic = "mpc.mpc_signing_result.complete"
)
type SigningResultEvent struct {
ResultType ResultType `json:"result_type"`
ErrorCode ErrorCode `json:"error_code"`
ErrorReason string `json:"error_reason"`
IsTimeout bool `json:"is_timeout"`
NetworkInternalCode string `json:"network_internal_code"`
WalletID string `json:"wallet_id"`
TxID string `json:"tx_id"`
// ECDSA signature components (secp256k1)
R []byte `json:"r"`
S []byte `json:"s"`
SignatureRecovery []byte `json:"signature_recovery"`
// EdDSA signature (ed25519/Schnorr) - 64-byte combined signature
// For ECDSA, use R/S/SignatureRecovery fields above
// For EdDSA, use this Signature field
Signature []byte `json:"signature"`
}
func CreateSignSuccess(sessionID, walletID string, r, s []byte, recoveryByte byte, metadata map[string]any) SigningResultEvent {
return SigningResultEvent{
ResultType: ResultTypeSuccess,
ErrorCode: "",
WalletID: walletID,
TxID: sessionID,
R: r,
S: s,
SignatureRecovery: []byte{recoveryByte},
NetworkInternalCode: "",
}
}
func CreateSignFailure(sessionID, walletID string, metadata map[string]any) SigningResultEvent {
errorReason := ""
if err, ok := metadata["error"]; ok {
errorReason = err.(string)
}
return SigningResultEvent{
ResultType: ResultTypeError,
ErrorCode: ErrorCodeSigningFailure,
ErrorReason: errorReason,
WalletID: walletID,
TxID: sessionID,
NetworkInternalCode: "",
}
}
type SigningResultSuccessEvent struct {
NetworkInternalCode string `json:"network_internal_code"`
WalletID string `json:"wallet_id"`
TxID string `json:"tx_id"`
// ECDSA signature components (secp256k1)
R []byte `json:"r"`
S []byte `json:"s"`
SignatureRecovery []byte `json:"signature_recovery"`
// EdDSA signature (ed25519/Schnorr) - 64-byte combined signature
Signature []byte `json:"signature"`
}
type SigningResultErrorEvent struct {
NetworkInternalCode string `json:"network_internal_code"`
WalletID string `json:"wallet_id"`
TxID string `json:"tx_id"`
ErrorCode ErrorCode `json:"error_code"`
ErrorReason string `json:"error_reason"`
IsTimeout bool `json:"is_timeout"`
}