warp

package
v0.8.24 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 29, 2025 License: GPL-3.0, LGPL-3.0 Imports: 21 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ParseErrCode = iota + 1
	VerifyErrCode
)

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API struct {
	// contains filtered or unexported fields
}

API introduces chain specific functionality to the evm

func NewAPI

func NewAPI(chainCtx context.Context, backend Backend, signatureAggregator interface{}, requirePrimaryNetworkSigners func() bool) *API

func (*API) GetBlockAggregateSignature

func (a *API) GetBlockAggregateSignature(ctx context.Context, blockID ids.ID, quorumNum uint64, chainIDStr string) (signedMessageBytes hexutil.Bytes, err error)

GetBlockAggregateSignature fetches the aggregate signature for the requested [blockID]

func (*API) GetBlockSignature

func (a *API) GetBlockSignature(ctx context.Context, blockID ids.ID) (hexutil.Bytes, error)

GetBlockSignature returns the BLS signature associated with a blockID.

func (*API) GetMessage

func (a *API) GetMessage(ctx context.Context, messageID ids.ID) (hexutil.Bytes, error)

GetMessage returns the Warp message associated with a messageID.

func (*API) GetMessageAggregateSignature

func (a *API) GetMessageAggregateSignature(ctx context.Context, messageID ids.ID, quorumNum uint64, chainIDStr string) (signedMessageBytes hexutil.Bytes, err error)

GetMessageAggregateSignature fetches the aggregate signature for the requested [messageID]

func (*API) GetMessageSignature

func (a *API) GetMessageSignature(ctx context.Context, messageID ids.ID) (hexutil.Bytes, error)

GetMessageSignature returns the BLS signature associated with a messageID.

type AppError added in v0.8.8

type AppError struct {
	Code    int
	Message string
}

AppError represents an application-level error with a code

func (*AppError) Error added in v0.8.8

func (e *AppError) Error() string

Error implements the error interface

type Backend

type Backend interface {
	// AddMessage signs [unsignedMessage] and adds it to the warp backend database
	AddMessage(unsignedMessage *warp.UnsignedMessage) error

	// GetMessageSignature validates the message and returns the signature of the requested message.
	GetMessageSignature(ctx context.Context, message *warp.UnsignedMessage) ([]byte, error)

	// GetBlockSignature returns the signature of a hash payload containing blockID if it's the ID of an accepted block.
	GetBlockSignature(ctx context.Context, blockID ids.ID) ([]byte, error)

	// GetMessage retrieves the [unsignedMessage] from the warp backend database if available
	GetMessage(messageHash ids.ID) (*warp.UnsignedMessage, error)

	// Verify verifies the signature of the message
	Verify(ctx context.Context, unsignedMessage *warp.UnsignedMessage, _ []byte) error
}

Backend tracks signature-eligible warp messages and provides an interface to fetch them. The backend is also used to query for warp message signatures by the signature request handler.

func NewBackend

func NewBackend(
	networkID uint32,
	sourceChainID ids.ID,
	warpSigner warp.Signer,
	blockClient BlockClient,
	validatorReader interfaces.ValidatorReader,
	db database.Database,
	signatureCache cache.Cacher[ids.ID, []byte],
	offchainMessages [][]byte,
) (Backend, error)

NewBackend creates a new Backend, and initializes the signature cache and message tracking database.

type BlockClient

type BlockClient interface {
	GetAcceptedBlock(ctx context.Context, blockID ids.ID) (chain.Block, error)
}

type Client

type Client interface {
	GetMessage(ctx context.Context, messageID ids.ID) ([]byte, error)
	GetMessageSignature(ctx context.Context, messageID ids.ID) ([]byte, error)
	GetMessageAggregateSignature(ctx context.Context, messageID ids.ID, quorumNum uint64, chainIDStr string) ([]byte, error)
	GetBlockSignature(ctx context.Context, blockID ids.ID) ([]byte, error)
	GetBlockAggregateSignature(ctx context.Context, blockID ids.ID, quorumNum uint64, chainIDStr string) ([]byte, error)
}

func NewClient

func NewClient(uri, chain string) (Client, error)

NewClient returns a Client for interacting with EVM chain

type LocalSignatureGetter added in v0.8.8

type LocalSignatureGetter struct {
	// contains filtered or unexported fields
}

LocalSignatureGetter implements SignatureGetter using local backend

func NewLocalSignatureGetter added in v0.8.8

func NewLocalSignatureGetter(backend Backend) *LocalSignatureGetter

NewLocalSignatureGetter creates a signature getter using the local backend

func (*LocalSignatureGetter) GetSignature added in v0.8.8

func (g *LocalSignatureGetter) GetSignature(ctx context.Context, nodeID ids.NodeID, unsignedMessage *warp.UnsignedMessage) ([]byte, error)

GetSignature gets a signature from the local backend (this node)

type LocalSigner added in v0.8.8

type LocalSigner struct {
	// contains filtered or unexported fields
}

LocalSigner implements signing with luxfi/crypto/bls

func NewLocalSigner added in v0.8.8

func NewLocalSigner(sk *bls.SecretKey) *LocalSigner

NewLocalSigner creates a new local signer using luxfi/crypto/bls

func (*LocalSigner) GetPublicKey added in v0.8.8

func (s *LocalSigner) GetPublicKey() *bls.PublicKey

GetPublicKey returns the public key

func (*LocalSigner) NodeID added in v0.8.8

func (s *LocalSigner) NodeID() ids.NodeID

NodeID returns the node ID derived from the public key

func (*LocalSigner) PublicKey added in v0.8.8

func (s *LocalSigner) PublicKey() []byte

PublicKey returns the public key as compressed bytes (48 bytes)

func (*LocalSigner) Sign added in v0.8.8

func (s *LocalSigner) Sign(msg []byte) ([]byte, error)

Sign signs the message with the private key

func (*LocalSigner) SignUnsignedMessage added in v0.8.8

func (s *LocalSigner) SignUnsignedMessage(unsignedMsg *warp.UnsignedMessage) ([]byte, error)

SignUnsignedMessage signs an unsigned warp message

type NetworkSignatureGetter added in v0.8.8

type NetworkSignatureGetter struct {
	// contains filtered or unexported fields
}

NetworkSignatureGetter implements SignatureGetter by fetching from network peers

func NewNetworkSignatureGetter added in v0.8.8

func NewNetworkSignatureGetter(client RequestClient) *NetworkSignatureGetter

NewNetworkSignatureGetter creates a signature getter that fetches from network

func (*NetworkSignatureGetter) GetSignature added in v0.8.8

func (g *NetworkSignatureGetter) GetSignature(ctx context.Context, nodeID ids.NodeID, unsignedMessage *warp.UnsignedMessage) ([]byte, error)

GetSignature fetches a signature from a network peer

type RequestClient added in v0.8.11

type RequestClient interface {
	// SendRequest sends a request to a peer and waits for response
	SendRequest(ctx context.Context, nodeID ids.NodeID, request []byte) ([]byte, error)
}

RequestClient sends requests to peers

type SignatureAggregator added in v0.8.8

type SignatureAggregator struct {
	// contains filtered or unexported fields
}

SignatureAggregator aggregates BLS signatures from validators

func NewSignatureAggregator added in v0.8.8

func NewSignatureAggregator(signatureGetter SignatureGetter) *SignatureAggregator

NewSignatureAggregator creates a new signature aggregator

func (*SignatureAggregator) AggregateSignatures added in v0.8.8

func (a *SignatureAggregator) AggregateSignatures(
	ctx context.Context,
	unsignedMessage *warp.UnsignedMessage,
	validators []*ValidatorInfo,
	quorumNum uint64,
	quorumDen uint64,
) ([]byte, error)

AggregateSignatures collects signatures from validators and aggregates them Returns the signed message bytes if successful

type SignatureGetter added in v0.8.8

type SignatureGetter interface {
	// GetSignature fetches a signature for the message from the given node
	GetSignature(ctx context.Context, nodeID ids.NodeID, unsignedMessage *warp.UnsignedMessage) ([]byte, error)
}

SignatureGetter fetches a signature for a warp message from a specific validator

type SignerAdapter added in v0.8.18

type SignerAdapter struct {
	// contains filtered or unexported fields
}

SignerAdapter adapts a LocalSigner to the warp.Signer interface

func NewSignerAdapter added in v0.8.18

func NewSignerAdapter(signer *LocalSigner) *SignerAdapter

NewSignerAdapter creates a new adapter

func (*SignerAdapter) Sign added in v0.8.18

func (a *SignerAdapter) Sign(unsignedMsg *warp.UnsignedMessage) ([]byte, error)

Sign implements the warp.Signer interface

type ValidatorInfo added in v0.8.8

type ValidatorInfo struct {
	NodeID    ids.NodeID
	PublicKey *bls.PublicKey
	Weight    uint64
	Index     int
}

ValidatorInfo contains validator information for signature aggregation

Directories

Path Synopsis
warptest exposes common functionality for testing the warp package.
warptest exposes common functionality for testing the warp package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL