Documentation
¶
Index ¶
- Constants
- Variables
- func AddUint64(a, b uint64) (uint64, error)
- func AggregateSignatures(signatures []*bls.Signature) (*bls.Signature, error)
- func ChainIDToHash(chainID ids.ID) common.Hash
- func CheckMulDoesNotOverflow(a, b uint64) error
- func ComputeHash256(data []byte) []byte
- func ComputeHash256Array(data []byte) [32]byte
- func MarshalSignatureRequest(req *SignatureRequest) ([]byte, error)
- func MarshalSignatureResponse(signature []byte) ([]byte, error)
- func ParsePublicKey(publicKeyBytes []byte) (*bls.PublicKey, error)
- func SerializePublicKey(publicKey *bls.PublicKey) []byte
- func Sign(msg []byte, sk *bls.SecretKey) (*bls.Signature, error)
- func ValidateValidatorSet(validators []*Validator) error
- func ValidatorSetToMap(validators []*Validator) map[ids.NodeID]*Validator
- func VerifyMessage(msg *Message, networkID uint32, validatorState ValidatorState, ...) error
- func VerifyWeight(signedWeight, totalWeight, quorumNum, quorumDen uint64) error
- type BitSetSignature
- type Bits
- func (b *Bits) Add(i int)
- func (b Bits) BitLen() int
- func (b *Bits) Clear()
- func (b Bits) Contains(i int) bool
- func (b Bits) Difference(other Bits) Bits
- func (b Bits) Equal(other Bits) bool
- func (b Bits) HighestSetBit() int
- func (b Bits) Intersection(other Bits) Bits
- func (b Bits) Len() int
- func (b Bits) String() string
- func (b Bits) Union(other Bits) Bits
- type CachedSignatureHandler
- type CanonicalValidatorSet
- type CodecImpl
- type Error
- type FakeSender
- func (FakeSender) SendError(context.Context, ids.NodeID, uint32, int32, string) error
- func (FakeSender) SendGossip(context.Context, SendConfig, []byte) error
- func (FakeSender) SendRequest(context.Context, set.Set[ids.NodeID], uint32, []byte) error
- func (FakeSender) SendResponse(context.Context, ids.NodeID, uint32, []byte) error
- type Handler
- type Message
- func (m *Message) Bytes() []byte
- func (m *Message) DecodeRLP(s *rlp.Stream) error
- func (m *Message) EncodeRLP(w io.Writer) error
- func (m *Message) Equal(other *Message) bool
- func (m *Message) GetSourceChainID() ids.ID
- func (m *Message) ID() ids.ID
- func (m *Message) SourceChainIDHash() common.Hash
- func (m *Message) Verify() error
- type NoOpSignatureHandler
- type SendConfig
- type Sender
- type Signature
- type SignatureAggregator
- type SignatureCacher
- type SignatureHandler
- type SignatureHandlerAdapter
- type SignatureRequest
- type SignatureResponse
- type Signer
- type UnsignedMessage
- type Validator
- type ValidatorState
- type Verifier
Constants ¶
const ( CodecVersion = 0 MaxMessageSize = 256 * KiB )
const ( // KiB is 1024 bytes KiB = 1024 // SignatureLen is the length of a BLS signature SignatureLen = 96 // PublicKeyLen is the length of a BLS public key PublicKeyLen = 48 )
Constants
const SignatureHandlerID = 0x12345678
SignatureHandlerID is the protocol ID for warp signature handling
Variables ¶
var ( ErrUnexpected = p2p.ErrUnexpected ErrUnregisteredHandler = p2p.ErrUnregisteredHandler ErrNotValidator = p2p.ErrNotValidator ErrThrottled = p2p.ErrThrottled )
Standard errors re-exported from p2p
var ( ErrInvalidSignature = errors.New("invalid signature") ErrInvalidMessage = errors.New("invalid message") ErrUnknownValidator = errors.New("unknown validator") ErrInsufficientWeight = errors.New("insufficient weight") )
var ( ErrWrongSourceChainID = errors.New("wrong SourceChainID") ErrWrongNetworkID = errors.New("wrong networkID") )
var Codec = &CodecImpl{}
Codec is the default codec instance
Functions ¶
func AggregateSignatures ¶
AggregateSignatures aggregates multiple signatures into one
func ChainIDToHash ¶
ChainIDToHash converts a chain ID to a common.Hash
func CheckMulDoesNotOverflow ¶
CheckMulDoesNotOverflow checks if a * b would overflow uint64
func ComputeHash256Array ¶ added in v1.5.0
ComputeHash256Array computes SHA256 hash and returns as fixed-size array
func MarshalSignatureRequest ¶ added in v1.5.0
func MarshalSignatureRequest(req *SignatureRequest) ([]byte, error)
MarshalSignatureRequest marshals a signature request to bytes
func MarshalSignatureResponse ¶ added in v1.5.0
MarshalSignatureResponse marshals a signature response to bytes
func ParsePublicKey ¶
ParsePublicKey parses a BLS public key from bytes
func SerializePublicKey ¶
SerializePublicKey serializes a BLS public key to bytes
func ValidateValidatorSet ¶
ValidateValidatorSet performs validation on a validator set
func ValidatorSetToMap ¶
ValidatorSetToMap converts a validator slice to a map keyed by node ID
func VerifyMessage ¶
func VerifyMessage( msg *Message, networkID uint32, validatorState ValidatorState, quorumNum uint64, quorumDen uint64, ) error
VerifyMessage verifies a message against a validator set
func VerifyWeight ¶
VerifyWeight verifies that the signed weight meets the quorum threshold
Types ¶
type BitSetSignature ¶
type BitSetSignature struct {
Signers Bits `serialize:"true"`
Signature [bls.SignatureLen]byte `serialize:"true"`
}
BitSetSignature is a signature that uses a bit set to indicate which validators signed
func NewBitSetSignature ¶
func NewBitSetSignature(signers Bits, signature [bls.SignatureLen]byte) *BitSetSignature
NewBitSetSignature creates a new bit set signature
func (*BitSetSignature) Bytes ¶ added in v0.1.2
func (s *BitSetSignature) Bytes() []byte
Bytes returns the bytes representation of the signature
func (*BitSetSignature) Equal ¶
func (s *BitSetSignature) Equal(other Signature) bool
Equal returns true if two signatures are equal
func (*BitSetSignature) GetSignedWeight ¶
func (s *BitSetSignature) GetSignedWeight(validators []*Validator) (uint64, error)
GetSignedWeight returns the total weight of validators that signed
type Bits ¶
type Bits []byte
Bits represents a bit set
func (Bits) Difference ¶
Difference returns the difference of two bit sets (elements in b but not in other)
func (Bits) HighestSetBit ¶ added in v1.4.2
HighestSetBit returns the highest bit index that is set + 1 Returns 0 if no bits are set
func (Bits) Intersection ¶
Intersection returns the intersection of two bit sets
type CachedSignatureHandler ¶ added in v1.5.0
type CachedSignatureHandler struct {
// contains filtered or unexported fields
}
CachedSignatureHandler implements a cached handler for warp signatures
type CanonicalValidatorSet ¶
type CanonicalValidatorSet struct {
// contains filtered or unexported fields
}
CanonicalValidatorSet represents the canonical ordering of validators
func NewCanonicalValidatorSet ¶
func NewCanonicalValidatorSet(validators []*Validator) (*CanonicalValidatorSet, error)
NewCanonicalValidatorSet creates a new canonical validator set
func (*CanonicalValidatorSet) GetValidator ¶
func (c *CanonicalValidatorSet) GetValidator(index int) (*Validator, error)
GetValidator returns the validator at the given index
func (*CanonicalValidatorSet) Len ¶
func (c *CanonicalValidatorSet) Len() int
Len returns the number of validators
func (*CanonicalValidatorSet) TotalWeight ¶
func (c *CanonicalValidatorSet) TotalWeight() uint64
TotalWeight returns the total weight of all validators
func (*CanonicalValidatorSet) Validators ¶
func (c *CanonicalValidatorSet) Validators() []*Validator
Validators returns the validators in canonical order
type CodecImpl ¶
type CodecImpl struct{}
CodecImpl is used for serializing/deserializing warp messages
func (*CodecImpl) RegisterType ¶
RegisterType is a no-op for RLP codec
type FakeSender ¶ added in v1.4.2
type FakeSender struct{}
FakeSender is a test implementation of Sender that does nothing.
func (FakeSender) SendGossip ¶ added in v1.4.2
func (FakeSender) SendGossip(context.Context, SendConfig, []byte) error
func (FakeSender) SendRequest ¶ added in v1.4.2
func (FakeSender) SendResponse ¶ added in v1.4.2
type Handler ¶ added in v1.4.2
type Handler interface {
// Request handles an incoming request and returns a response or error
Request(ctx context.Context, nodeID ids.NodeID, requestID uint32, deadline time.Time, msg []byte) ([]byte, *p2p.Error)
// Response handles an incoming response to a previous request
Response(ctx context.Context, nodeID ids.NodeID, requestID uint32, msg []byte) error
// Gossip handles an incoming gossip message
Gossip(ctx context.Context, nodeID ids.NodeID, msg []byte) error
// RequestFailed is called when a request fails
RequestFailed(ctx context.Context, nodeID ids.NodeID, requestID uint32, err *p2p.Error) error
}
Handler handles messages between nodes. This is the primary interface for receiving cross-node messages used by VMs. For simple request/response handlers, use p2p.Handler directly.
type Message ¶
type Message struct {
UnsignedMessage *UnsignedMessage `serialize:"true"`
Signature Signature `serialize:"true"`
}
Message is a signed warp message
func NewMessage ¶
func NewMessage(unsigned *UnsignedMessage, signature Signature) (*Message, error)
NewMessage creates a new signed message
func ParseMessage ¶
ParseMessage parses a message from bytes
func SignMessage ¶
func SignMessage( msg *UnsignedMessage, signers []*bls.SecretKey, validators []*Validator, ) (*Message, error)
SignMessage signs a warp message with a set of signers
func (*Message) GetSourceChainID ¶ added in v1.5.0
GetSourceChainID returns the source chain ID
func (*Message) SourceChainIDHash ¶ added in v1.5.0
SourceChainIDHash returns the source chain ID as a common.Hash (for EVM compatibility)
type NoOpSignatureHandler ¶ added in v1.5.0
type NoOpSignatureHandler struct{}
NoOpSignatureHandler is a no-op implementation of SignatureHandler
type SendConfig ¶ added in v1.4.2
type SendConfig = p2p.SendConfig
SendConfig is an alias for p2p.SendConfig for backward compatibility
type Signature ¶
type Signature interface {
// Verify verifies the signature against the message and validator set
Verify(msg []byte, validators []*Validator) error
// GetSignedWeight returns the total weight of validators that signed
GetSignedWeight(validators []*Validator) (uint64, error)
// Equal returns true if two signatures are equal
Equal(other Signature) bool
// Bytes returns the bytes representation of the signature
Bytes() []byte
}
Signature is an interface for warp message signatures
type SignatureAggregator ¶ added in v1.5.0
type SignatureAggregator struct {
// contains filtered or unexported fields
}
SignatureAggregator aggregates validator signatures for warp messages
func NewSignatureAggregator ¶ added in v1.5.0
func NewSignatureAggregator(log log.Logger, client *p2p.Client) *SignatureAggregator
NewSignatureAggregator returns an instance of SignatureAggregator
func (*SignatureAggregator) AggregateSignatures ¶ added in v1.5.0
func (s *SignatureAggregator) AggregateSignatures( ctx context.Context, message *Message, justification []byte, validators []*Validator, quorumNum uint64, quorumDen uint64, ) ( _ *Message, aggregatedStake *big.Int, totalStake *big.Int, _ error, )
AggregateSignatures blocks until quorumNum/quorumDen signatures from validators are requested to be aggregated into a warp message or the context is canceled. Returns the signed message and the amount of stake that signed the message. Caller is responsible for providing a well-formed canonical validator set corresponding to the signer bitset in the message.
type SignatureCacher ¶ added in v1.5.0
type SignatureCacher[K comparable, V any] interface { Get(key K) (V, bool) Put(key K, value V) }
SignatureCacher provides caching for signature responses
type SignatureHandler ¶ added in v1.5.0
type SignatureHandler interface {
// Request handles an incoming signature request
Request(ctx context.Context, nodeID ids.NodeID, deadline time.Time, request []byte) ([]byte, error)
}
SignatureHandler handles warp signature requests
func NewCachedSignatureHandler ¶ added in v1.5.0
func NewCachedSignatureHandler(cache SignatureCacher[ids.ID, []byte], backend interface{}, signer Signer) SignatureHandler
NewCachedSignatureHandler creates a new cached signature handler
type SignatureHandlerAdapter ¶ added in v1.5.0
type SignatureHandlerAdapter struct {
// contains filtered or unexported fields
}
SignatureHandlerAdapter adapts a SignatureHandler to the p2p.Handler interface. This allows warp signature handlers to be registered with the p2p router.
func NewSignatureHandlerAdapter ¶ added in v1.5.0
func NewSignatureHandlerAdapter(handler SignatureHandler) *SignatureHandlerAdapter
NewSignatureHandlerAdapter creates a new adapter that wraps a SignatureHandler and implements the p2p.Handler interface.
type SignatureRequest ¶ added in v1.5.0
SignatureRequest represents a request for a warp signature
func UnmarshalSignatureRequest ¶ added in v1.5.0
func UnmarshalSignatureRequest(data []byte) (*SignatureRequest, error)
UnmarshalSignatureRequest unmarshals bytes to a signature request
type SignatureResponse ¶ added in v1.5.0
type SignatureResponse struct {
Signature []byte
}
SignatureResponse represents a warp signature response
func UnmarshalSignatureResponse ¶ added in v1.5.0
func UnmarshalSignatureResponse(data []byte) (*SignatureResponse, error)
UnmarshalSignatureResponse unmarshals bytes to a signature response
type Signer ¶ added in v1.4.2
type Signer interface {
Sign(msg *UnsignedMessage) ([]byte, error)
}
Signer signs warp messages
type UnsignedMessage ¶
type UnsignedMessage struct {
NetworkID uint32 `serialize:"true"`
SourceChainID ids.ID `serialize:"true"`
Payload []byte `serialize:"true"`
}
UnsignedMessage is an unsigned warp message
func NewUnsignedMessage ¶
func NewUnsignedMessage(networkID uint32, sourceChainID ids.ID, payload []byte) (*UnsignedMessage, error)
NewUnsignedMessage creates a new unsigned message
func ParseUnsignedMessage ¶
func ParseUnsignedMessage(b []byte) (*UnsignedMessage, error)
ParseUnsignedMessage parses an unsigned message from bytes
func (*UnsignedMessage) Bytes ¶
func (u *UnsignedMessage) Bytes() []byte
Bytes returns the byte representation of the unsigned message
func (*UnsignedMessage) ID ¶
func (u *UnsignedMessage) ID() ids.ID
ID returns the hash of the unsigned message
func (*UnsignedMessage) Verify ¶
func (u *UnsignedMessage) Verify() error
Verify verifies the unsigned message
type Validator ¶
type Validator struct {
PublicKey *bls.PublicKey
PublicKeyBytes []byte
Weight uint64
NodeID ids.NodeID
}
Validator represents a validator in the network
func GetCanonicalValidatorSet ¶
func GetCanonicalValidatorSet( validatorState ValidatorState, chainID ids.ID, ) ([]*Validator, uint64, error)
GetCanonicalValidatorSet retrieves and canonicalizes the validator set
type ValidatorState ¶
type ValidatorState interface {
// GetValidatorSet returns the validator set for a given chain ID at a given height
GetValidatorSet(chainID ids.ID, height uint64) (map[ids.NodeID]*Validator, error)
// GetCurrentHeight returns the current height
GetCurrentHeight() (uint64, error)
}
ValidatorState is an interface for retrieving validator sets
type Verifier ¶ added in v1.5.0
type Verifier interface {
// Verify verifies an unsigned warp message with justification.
// Returns nil on success, or an error if verification fails.
Verify(ctx context.Context, unsignedMessage *UnsignedMessage, justification []byte) error
}
Verifier verifies warp messages before signing
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
plugin
Package warp provides cross-chain messaging functionality for the Lux CLI
|
Package warp provides cross-chain messaging functionality for the Lux CLI |
|
warpcli
command
|
|
|
crypto
|
|
|
fhe
Package fhe provides Fully Homomorphic Encryption interfaces for private messaging.
|
Package fhe provides Fully Homomorphic Encryption interfaces for private messaging. |
|
ringtail
Package ringtail implements random ringtail validation for post-quantum safety.
|
Package ringtail implements random ringtail validation for post-quantum safety. |
|
signature
Package signature provides modular signature verification for Warp messages.
|
Package signature provides modular signature verification for Warp messages. |
|
messages
|
|
|
relayer
|
|
|
signature-aggregator
|
|
|
Package types defines the core interfaces for the Warp message format.
|
Package types defines the core interfaces for the Warp message format. |