Documentation
¶
Overview ¶
Package protocol provides context utilities for threshold signature protocols
Package protocol provides the ultimate optimized protocol handler with Lux integration ¶
Package protocol provides unified interfaces for threshold signature protocols.
Index ¶
- func Group(ctx context.Context) curve.Curve
- func Parties(ctx context.Context) []party.ID
- func Protocol(ctx context.Context) string
- func Self(ctx context.Context) party.ID
- func SessionID(ctx context.Context) []byte
- func Threshold(ctx context.Context) int
- func WithSession(ctx context.Context, info SessionInfo) context.Context
- type Config
- type Context
- type Error
- type Handler
- type KeyID
- type Message
- type MessageStore
- type Metrics
- type MultiHandler
- type ProtocolAdapter
- type ReshareableProtocol
- type SessionInfo
- type SignatureScheme
- type StartFunc
- type ThresholdConfig
- type ThresholdProtocol
- type ThresholdSigner
- type TwoPartyHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithSession ¶ added in v1.1.0
func WithSession(ctx context.Context, info SessionInfo) context.Context
WithSession sets session info in context (call once at protocol start)
Types ¶
type Config ¶ added in v1.0.1
type Config struct {
// Worker pools
Workers int // CPU cores * 2 by default
PriorityWorkers int // 4 by default
// Channels
BufferSize int // 10000 by default
PriorityBuffer int // 1000 by default
// Timeouts
MessageTimeout time.Duration // 30s by default
RoundTimeout time.Duration // 60s by default
ProtocolTimeout time.Duration // 5m by default
// Performance
EnableBatching bool // true by default
BatchSize int // 100 by default
BatchTimeout time.Duration // 10ms by default
EnableCompression bool // true for large messages
CompressionThreshold int // 1KB by default
// Memory
EnablePooling bool // true by default
MaxMessageSize int // 10MB by default
// Reliability
RetryAttempts int // 3 by default
RetryBackoff time.Duration // 1s by default
}
Config for handler - optimized for maximum performance
func DefaultConfig ¶ added in v1.0.1
func DefaultConfig() *Config
DefaultConfig returns the perfect configuration
type Context ¶ added in v1.1.0
Context is just an alias for standard context.Context for cleaner call sites
type Error ¶
type Error struct {
// Culprit is empty if the identity of the misbehaving party cannot be known.
Culprits []party.ID
// Err is the underlying error.
Err error
}
Error is a custom error for protocols which contains information about the responsible round in which it occurred, and the party responsible.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler is the ONLY handler for threshold protocols - optimized for perfection
func NewHandler ¶ added in v1.0.1
func NewHandler( ctx context.Context, logger log.Logger, registry prometheus.Registerer, create StartFunc, sessionID []byte, config *Config, ) (*Handler, error)
NewHandler creates the perfect protocol handler
func NewMultiHandler ¶
NewMultiHandler creates a handler with default config (temporary compatibility)
func (*Handler) WaitForResult ¶ added in v1.0.1
WaitForResult blocks until the protocol completes or times out
type KeyID ¶ added in v1.0.1
type KeyID struct {
// ProtocolID identifies the protocol (e.g., "cmp/keygen", "frost/keygen")
ProtocolID string
// Group is the elliptic curve group being used
Group curve.Curve
// PublicKey is the shared public key (if available)
PublicKey curve.Point
// PartyIDs is the canonical ordered list of all parties
PartyIDs []party.ID
// Threshold is the threshold parameter
Threshold int
// Generation is an optional generation counter for key refresh
Generation uint32
}
KeyID represents a stable, phase-independent identifier for a key generation context. This is used for cross-phase cryptographic commitments and verification.
Unlike sessionID which changes per phase for anti-replay, KeyID remains constant across all phases (keygen, presign, sign) to ensure cryptographic bindings remain valid.
func NewKeyID ¶ added in v1.0.1
func NewKeyID(protocolID string, group curve.Curve, publicKey curve.Point, partyIDs []party.ID, threshold int, generation uint32) *KeyID
NewKeyID creates a new KeyID for a key generation context. The partyIDs will be canonically sorted to ensure consistency.
type Message ¶
type Message struct {
// SSID is a byte string which uniquely identifies the session this message belongs to.
SSID []byte
// From is the party.ID of the sender
From party.ID
// To is the intended recipient for this message. If To == "", then the message should be sent to all.
To party.ID
// Protocol identifies the protocol this message belongs to
Protocol string
// RoundNumber is the index of the round this message belongs to
RoundNumber round.Number
// Data is the actual content consumed by the round.
Data []byte
// Broadcast indicates whether this message should be reliably broadcast to all participants.
Broadcast bool
// BroadcastVerification is the hash of all messages broadcast by the parties,
// and is included in all messages in the round following a broadcast round.
BroadcastVerification []byte
// Compressed indicates whether the Data field is compressed
Compressed bool
}
func (*Message) Hash ¶
Hash returns a 64 byte hash of the message content, including the headers. Can be used to produce a signature for the message.
func (*Message) MarshalBinary ¶
func (*Message) UnmarshalBinary ¶
type MessageStore ¶ added in v1.0.1
type MessageStore struct {
// contains filtered or unexported fields
}
MessageStore provides zero-contention sharded message storage
type Metrics ¶ added in v1.0.1
type Metrics struct {
// contains filtered or unexported fields
}
Metrics for Prometheus monitoring
type MultiHandler ¶
type MultiHandler = Handler
MultiHandler is an alias for Handler for temporary compatibility
type ProtocolAdapter ¶ added in v1.0.1
type ProtocolAdapter[C ThresholdConfig] struct { // contains filtered or unexported fields }
ProtocolAdapter wraps a specific protocol implementation to provide a unified interface
func NewProtocolAdapter ¶ added in v1.0.1
func NewProtocolAdapter[C ThresholdConfig](protocol ThresholdProtocol, config C) *ProtocolAdapter[C]
NewProtocolAdapter creates a new adapter for a specific protocol
func (*ProtocolAdapter[C]) Execute ¶ added in v1.0.1
func (a *ProtocolAdapter[C]) Execute(operation func(ThresholdConfig) (StartFunc, error)) (StartFunc, error)
Execute runs a protocol operation with the wrapped configuration
type ReshareableProtocol ¶ added in v1.0.1
type ReshareableProtocol interface {
ThresholdProtocol
Reshare(config ThresholdConfig, newParticipants []party.ID, newThreshold int) (StartFunc, error)
AddParties(config ThresholdConfig, newParties []party.ID) (StartFunc, error)
RemoveParties(config ThresholdConfig, partiesToRemove []party.ID) (StartFunc, error)
}
ReshareableProtocol extends ThresholdProtocol with resharing capabilities
type SessionInfo ¶ added in v1.1.0
type SessionInfo struct {
SessionID []byte
SelfID party.ID
PartyIDs []party.ID
Threshold int
Group curve.Curve
Protocol string // "cmp", "frost", "lss", etc.
}
SessionInfo holds immutable protocol session information
func MustSession ¶ added in v1.1.0
func MustSession(ctx context.Context) SessionInfo
MustSession panics if session info is missing (fail-fast pattern)
type SignatureScheme ¶ added in v1.0.1
type SignatureScheme int
SignatureScheme represents the type of signature that can be produced
const ( ECDSA SignatureScheme = iota Schnorr EdDSA )
type ThresholdConfig ¶ added in v1.0.1
type ThresholdConfig interface {
// Core identity and parameters
GetID() party.ID
GetThreshold() int
GetGroup() curve.Curve
// Key material
GetPublicKey() (curve.Point, error)
// Protocol-specific data
GetChainKey() []byte
GetRID() []byte
// Validation
Validate() error
IsCompatible(other ThresholdConfig) bool
}
ThresholdConfig is a unified interface for all threshold protocol configurations. This allows LSS to work with any underlying protocol (CMP, FROST, etc.)
type ThresholdProtocol ¶ added in v1.0.1
type ThresholdProtocol interface {
// Keygen creates a new distributed key
Keygen(group curve.Curve, selfID party.ID, participants []party.ID, threshold int) (StartFunc, error)
// Sign creates a signature with the given signers
Sign(config ThresholdConfig, signers []party.ID, message []byte) (StartFunc, error)
// Refresh updates shares without changing the key
Refresh(config ThresholdConfig) (StartFunc, error)
// GetScheme returns the signature scheme this protocol implements
GetScheme() SignatureScheme
// SupportsResharing indicates if the protocol supports dynamic resharing
SupportsResharing() bool
}
ThresholdProtocol defines operations that any threshold protocol must support
type ThresholdSigner ¶ added in v1.0.1
type ThresholdSigner[S any] interface { // Sign produces a signature of type S Sign(config ThresholdConfig, signers []party.ID, message []byte) (S, error) // Verify checks if a signature is valid Verify(signature S, publicKey curve.Point, message []byte) bool }
ThresholdSigner is a generic interface for signature generation
type TwoPartyHandler ¶
type TwoPartyHandler struct {
// contains filtered or unexported fields
}
TwoPartyHandler represents a restriction of the Handler for 2 party protocols.
func NewTwoPartyHandler ¶
func NewTwoPartyHandler(create StartFunc, sessionID []byte, leader bool) (*TwoPartyHandler, error)
func (*TwoPartyHandler) Accept ¶
func (h *TwoPartyHandler) Accept(msg *Message)
func (*TwoPartyHandler) CanAccept ¶
func (h *TwoPartyHandler) CanAccept(msg *Message) bool
func (*TwoPartyHandler) Listen ¶
func (h *TwoPartyHandler) Listen() <-chan *Message
func (*TwoPartyHandler) Result ¶
func (h *TwoPartyHandler) Result() (interface{}, error)
func (*TwoPartyHandler) Stop ¶
func (h *TwoPartyHandler) Stop()
func (*TwoPartyHandler) String ¶
func (h *TwoPartyHandler) String() string