mirror of
https://github.com/hanzoai/mpc.git
synced 2026-10-30 19:45:28 +00:00
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.
73 lines
1.8 KiB
Go
73 lines
1.8 KiB
Go
package eventconsumer
|
||
|
||
import "encoding/json"
|
||
|
||
type KeyType string
|
||
|
||
const (
|
||
KeyTypeSecp256k1 KeyType = "secp256k1"
|
||
KeyTypeEd25519 KeyType = "ed25519"
|
||
)
|
||
|
||
// InitiatorMessage is anything that carries a payload to verify and its signature.
|
||
type InitiatorMessage interface {
|
||
// Raw returns the canonical byte‐slice that was signed.
|
||
Raw() ([]byte, error)
|
||
// Sig returns the signature over Raw().
|
||
Sig() []byte
|
||
// InitiatorID returns the ID whose public key we have to look up.
|
||
InitiatorID() string
|
||
}
|
||
|
||
type GenerateKeyMessage struct {
|
||
WalletID string `json:"wallet_id"`
|
||
Signature []byte `json:"signature"`
|
||
}
|
||
|
||
type SignTxMessage struct {
|
||
KeyType KeyType `json:"key_type"`
|
||
WalletID string `json:"wallet_id"`
|
||
NetworkInternalCode string `json:"network_internal_code"`
|
||
TxID string `json:"tx_id"`
|
||
Tx []byte `json:"tx"`
|
||
Signature []byte `json:"signature"`
|
||
}
|
||
|
||
func (m *SignTxMessage) Raw() ([]byte, error) {
|
||
// omit the Signature field itself when computing the signed‐over data
|
||
payload := struct {
|
||
KeyType KeyType `json:"key_type"`
|
||
WalletID string `json:"wallet_id"`
|
||
NetworkInternalCode string `json:"network_internal_code"`
|
||
TxID string `json:"tx_id"`
|
||
Tx []byte `json:"tx"`
|
||
}{
|
||
KeyType: m.KeyType,
|
||
WalletID: m.WalletID,
|
||
NetworkInternalCode: m.NetworkInternalCode,
|
||
TxID: m.TxID,
|
||
Tx: m.Tx,
|
||
}
|
||
return json.Marshal(payload)
|
||
}
|
||
|
||
func (m *SignTxMessage) Sig() []byte {
|
||
return m.Signature
|
||
}
|
||
|
||
func (m *SignTxMessage) InitiatorID() string {
|
||
return m.TxID
|
||
}
|
||
|
||
func (m *GenerateKeyMessage) Raw() ([]byte, error) {
|
||
return []byte(m.WalletID), nil
|
||
}
|
||
|
||
func (m *GenerateKeyMessage) Sig() []byte {
|
||
return m.Signature
|
||
}
|
||
|
||
func (m *GenerateKeyMessage) InitiatorID() string {
|
||
return m.WalletID
|
||
}
|