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.
61 lines
1.3 KiB
Go
61 lines
1.3 KiB
Go
package messaging
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/avast/retry-go"
|
|
"github.com/nats-io/nats.go"
|
|
|
|
"github.com/hanzoai/mpc/pkg/logger"
|
|
)
|
|
|
|
type DirectMessaging interface {
|
|
Listen(target string, handler func(data []byte)) (Subscription, error)
|
|
Send(target string, data []byte) error
|
|
}
|
|
|
|
type natsDirectMessaging struct {
|
|
natsConn *nats.Conn
|
|
}
|
|
|
|
func NewNatsDirectMessaging(natsConn *nats.Conn) DirectMessaging {
|
|
return &natsDirectMessaging{
|
|
natsConn: natsConn,
|
|
}
|
|
}
|
|
|
|
func (d *natsDirectMessaging) Send(id string, message []byte) error {
|
|
var retryCount = 0
|
|
err := retry.Do(
|
|
func() error {
|
|
_, err := d.natsConn.Request(id, message, 3*time.Second)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
},
|
|
retry.Attempts(3),
|
|
retry.Delay(50*time.Millisecond),
|
|
retry.DelayType(retry.FixedDelay),
|
|
retry.OnRetry(func(n uint, err error) {
|
|
logger.Error("Failed to send direct message message", err, "retryCount", retryCount)
|
|
}),
|
|
)
|
|
|
|
return err
|
|
}
|
|
|
|
func (d *natsDirectMessaging) Listen(id string, handler func(data []byte)) (Subscription, error) {
|
|
sub, err := d.natsConn.Subscribe(id, func(m *nats.Msg) {
|
|
handler(m.Data)
|
|
if err := m.Respond([]byte("OK")); err != nil {
|
|
logger.Error("Failed to respond to message", err)
|
|
}
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &natsSubscription{subscription: sub}, nil
|
|
}
|