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.
66 lines
1.5 KiB
Go
66 lines
1.5 KiB
Go
package messaging
|
|
|
|
import (
|
|
"github.com/nats-io/nats.go"
|
|
|
|
"github.com/hanzoai/mpc/pkg/logger"
|
|
)
|
|
|
|
type Subscription interface {
|
|
Unsubscribe() error
|
|
}
|
|
|
|
type PubSub interface {
|
|
Publish(topic string, message []byte) error
|
|
PublishWithReply(topic, reply string, data []byte, headers map[string]string) error
|
|
Subscribe(topic string, handler func(msg *nats.Msg)) (Subscription, error)
|
|
}
|
|
|
|
type natsPubSub struct {
|
|
natsConn *nats.Conn
|
|
}
|
|
|
|
type natsSubscription struct {
|
|
subscription *nats.Subscription
|
|
}
|
|
|
|
func (ns *natsSubscription) Unsubscribe() error {
|
|
return ns.subscription.Unsubscribe()
|
|
}
|
|
|
|
func NewNATSPubSub(natsConn *nats.Conn) PubSub {
|
|
return &natsPubSub{natsConn}
|
|
}
|
|
|
|
func (n *natsPubSub) Publish(topic string, message []byte) error {
|
|
logger.Debug("[NATS] Publishing message", "topic", topic)
|
|
return n.natsConn.Publish(topic, message)
|
|
}
|
|
|
|
func (n *natsPubSub) PublishWithReply(topic, reply string, data []byte, headers map[string]string) error {
|
|
msg := &nats.Msg{
|
|
Subject: topic,
|
|
Reply: reply,
|
|
Data: data,
|
|
Header: nats.Header{},
|
|
}
|
|
for k, v := range headers {
|
|
msg.Header.Set(k, v)
|
|
}
|
|
err := n.natsConn.PublishMsg(msg)
|
|
return err
|
|
}
|
|
|
|
func (n *natsPubSub) Subscribe(topic string, handler func(msg *nats.Msg)) (Subscription, error) {
|
|
// Subscribe and forward the full nats.Msg to the handler
|
|
// Handler receives complete message including Subject, Reply, Data, Header fields
|
|
sub, err := n.natsConn.Subscribe(topic, func(msg *nats.Msg) {
|
|
handler(msg)
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &natsSubscription{subscription: sub}, nil
|
|
}
|