shwap

package
v0.28.4 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2025 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const EdsIDSize = 8

EdsIDSize defines the byte size of the EdsID.

View Source
const NamespaceDataIDSize = EdsIDSize + libshare.NamespaceSize

NamespaceDataIDSize defines the total size of a NamespaceDataID in bytes, combining the size of a EdsID and the size of a Namespace.

View Source
const RangeNamespaceDataIDSize = EdsIDSize + 4

RangeNamespaceDataIDSize defines the size of the RangeNamespaceDataIDSize in bytes, combining EdsIDSize size and 4 additional bytes for the start and end ODS indexes of share of the range.

View Source
const RowIDSize = EdsIDSize + 2

RowIDSize defines the size in bytes of RowID, consisting of the size of EdsID and 2 bytes for RowIndex.

View Source
const RowName = "row_v0"

RowName is the name identifier for the row container.

View Source
const RowNamespaceDataIDSize = RowIDSize + libshare.NamespaceSize

RowNamespaceDataIDSize defines the total size of a RowNamespaceDataID in bytes, combining the size of a RowID and the size of a Namespace.

View Source
const RowNamespaceDataName = "rnd_v0"

RowNamespaceDataName is the name identifier for the row namespace data container.

View Source
const SampleIDSize = RowIDSize + 2

SampleIDSize defines the size of the SampleID in bytes, combining RowID size and 2 additional bytes for the ShareIndex.

View Source
const SampleName = "sample_v0"

SampleName is the name identifier for the sample container.

Variables

View Source
var (
	// ErrOperationNotSupported is used to indicate that the operation is not supported by the
	// implementation of the getter interface.
	ErrOperationNotSupported = errors.New("operation is not supported")
	// ErrNotFound is used to indicate that requested data could not be found.
	ErrNotFound = errors.New("data not found")
	// ErrInvalidID is used to indicate that an ID failed validation.
	ErrInvalidID = errors.New("invalid shwap ID")
	// ErrOutOfBounds is used to indicate that a passed row or column index is out of bounds of the
	// square size.
	ErrOutOfBounds = fmt.Errorf("index out of bounds: %w", ErrInvalidID)
	// ErrNoSampleIndicies is used to indicate that no indicies where given to process.
	ErrNoSampleIndicies = errors.New("no sample indicies to fetch")
)
View Source
var ErrFailedVerification = errors.New("failed to verify inclusion")

ErrFailedVerification is returned when inclusion proof verification fails. It is returned when the data and the proof do not match trusted data root.

View Source
var ErrNamespaceOutsideRange = errors.New("target namespace is outside of namespace range for the given root")

ErrNamespaceOutsideRange is returned by RowNamespaceDataFromShares when the target namespace is outside of the namespace range for the given row. In this case, the implementation cannot return the non-inclusion proof and will return ErrNamespaceOutsideRange.

Functions

func GenerateSharesProofs added in v0.25.3

func GenerateSharesProofs(
	row, fromCol, toCol, size int,
	rowShares []libshare.Share,
) (*nmt.Proof, error)

GenerateSharesProofs generates a nmt proof for a range of shares within a specific row. It builds a Namespaced Merkle Tree from the provided row shares and creates a proof that the shares in the specified column range are valid

Parameters:

  • row: the row index in the data square
  • fromCol: the starting column index (inclusive) for the proof range
  • toCol: the ending column index (exclusive) for the proof range
  • size: the size of the original data in th row.
  • rowShares: slice of shares representing the complete row data

Returns a nmt proof that can be used to verify that shares in were included in the specified row.

Returns an error if:

  • tree construction fails when pushing any share
  • proof generation fails for the specified range.

func ParseNamespace added in v0.25.3

func ParseNamespace(rawShares [][]libshare.Share, startShare, endShare int) (libshare.Namespace, error)

ParseNamespace validates the share range, checks if it only contains one namespace and returns that namespace. The provided range, defined by startShare and endShare, is end-exclusive.

func RangeCoordsFromIdx added in v0.25.3

func RangeCoordsFromIdx(edsIndex, length, edsSize int) (SampleCoords, SampleCoords, error)

RangeCoordsFromIdx accepts the start index and the length of the range and computes `shwap.SampleCoords` of the first and the last sample of this range. * edsIndex is the index of the first sample inside the eds; * length is the amount of *ORIGINAL* samples that are expected to get(including the first sample);

func SampleCoordsAs1DIndex added in v0.20.4

func SampleCoordsAs1DIndex(idx SampleCoords, edsSize int) (int, error)

func ShareFromProto

func ShareFromProto(s *pb.Share) (libshare.Share, error)

ShareFromProto converts a protobuf Share object to the application's internal share representation. It returns nil if the input protobuf Share is nil, ensuring safe handling of nil values.

func SharesFromProto

func SharesFromProto(shrs []*pb.Share) ([]libshare.Share, error)

SharesFromProto converts a slice of protobuf Share objects to the application's internal slice of Shares. It ensures that each Share is correctly transformed using the ShareFromProto function.

func SharesToProto

func SharesToProto(shrs []libshare.Share) []*pb.Share

SharesToProto converts a slice of Shares from the application's internal representation to a slice of protobuf Share objects. This function allocates memory for the protobuf objects and copies data from the input slice.

Types

type Accessor added in v0.26.4

type Accessor interface {
	AxisRoots(context.Context) (*share.AxisRoots, error)
	RowNamespaceData(context.Context, libshare.Namespace, int) (RowNamespaceData, error)
	Reader() (io.Reader, error)
}

Accessor is used to access the data from the shwap containers.

type AxisHalf added in v0.26.4

type AxisHalf struct {
	Shares []libshare.Share
	// IsParity indicates whether the half is parity or data.
	IsParity bool
}

AxisHalf represents a half of data for a row or column in the EDS.

func (AxisHalf) Extended added in v0.26.4

func (a AxisHalf) Extended() ([]libshare.Share, error)

Extended returns full axis shares from half axis shares.

func (AxisHalf) ToRow added in v0.26.4

func (a AxisHalf) ToRow() Row

ToRow converts the AxisHalf to a shwap.Row.

type EdsID

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

EdsID represents a unique identifier for a row, using the height of the block to identify the data square in the chain.

func EdsIDFromBinary

func EdsIDFromBinary(data []byte) (EdsID, error)

EdsIDFromBinary decodes a byte slice into an EdsID, validating the length of the data. It returns an error if the data slice does not match the expected size of an EdsID.

func NewEdsID

func NewEdsID(height uint64) (EdsID, error)

NewEdsID creates a new EdsID using the given height.

func (EdsID) AppendBinary added in v0.21.9

func (eid EdsID) AppendBinary(data []byte) ([]byte, error)

AppendBinary helps in the binary encoding of EdsID by appending the binary form of Height to the given byte slice.

func (*EdsID) Equals

func (eid *EdsID) Equals(other EdsID) bool

Equals checks equality of EdsIDs.

func (EdsID) Height

func (eid EdsID) Height() uint64

func (EdsID) MarshalBinary

func (eid EdsID) MarshalBinary() ([]byte, error)

MarshalBinary encodes an EdsID into its binary form, primarily for storage or network transmission.

func (EdsID) Name added in v0.26.4

func (eid EdsID) Name() string

func (*EdsID) ReadFrom

func (eid *EdsID) ReadFrom(r io.Reader) (int64, error)

ReadFrom reads the binary form of EdsID from the provided reader.

func (EdsID) ResponseReader added in v0.26.4

func (eid EdsID) ResponseReader(_ context.Context, acc Accessor) (io.Reader, error)

func (EdsID) Validate

func (eid EdsID) Validate() error

Validate checks the integrity of an EdsID's fields against the provided Root. It ensures that the EdsID is not constructed with a zero Height and that the root is not nil.

func (EdsID) WriteTo

func (eid EdsID) WriteTo(w io.Writer) (int64, error)

WriteTo writes the binary form of EdsID to the provided writer.

type Getter

type Getter interface {
	// GetSamples retrieves multiple shares from the Extended Data Square (EDS) at the specified
	// coordinates. The coordinates are provided as a slice of SampleCoords, and the method returns
	// a slice of samples in the same order as the requested coordinates. If some samples cannot be
	// found, the corresponding positions in the returned slice will be empty, but the method will
	// still return the available samples without error.
	GetSamples(
		ctx context.Context,
		header *header.ExtendedHeader,
		indices []SampleCoords,
	) ([]Sample, error)

	// GetEDS retrieves the complete Extended Data Square (EDS) identified by the given header.
	// The EDS contains all shares organized in a 2D matrix format with erasure coding.
	// This method is useful when full access to all shares in the square is required.
	GetEDS(
		ctx context.Context,
		header *header.ExtendedHeader,
	) (*rsmt2d.ExtendedDataSquare, error)

	// GetRow retrieves all shares from a specific row in the Extended Data Square (EDS).
	// The row is identified by its index (rowIdx) and the header. This method is useful
	// for operations that need to process all shares in a particular row of the EDS.
	GetRow(
		ctx context.Context,
		header *header.ExtendedHeader,
		rowIdx int,
	) (Row, error)

	// GetNamespaceData retrieves all shares that belong to the specified namespace within
	// the Extended Data Square (EDS). The shares are returned in a row-by-row order,
	// maintaining the original layout if the namespace spans multiple rows. The returned
	// data can be verified for inclusion using the Verify method on NamespacedShares.
	// If no shares are found for the target namespace, non-inclusion can be verified
	// using the same Verify method.
	GetNamespaceData(
		ctx context.Context,
		header *header.ExtendedHeader,
		namespace libshare.Namespace,
	) (NamespaceData, error)

	// GetRangeNamespaceData retrieves a range of shares within a specific namespace in the
	// Extended Data Square (EDS). The range is defined by from and to indexes, which
	// specify the start and end points of the desired range, where `from` is inclusive
	// and `to` is exclusive indexes. The shares are returned in a row-by-row order
	// if the range spans multiple rows.
	GetRangeNamespaceData(
		ctx context.Context,
		header *header.ExtendedHeader,
		from, to int,
	) (RangeNamespaceData, error)
}

Getter interface provides a set of accessors for shares by the Root. Automatically verifies integrity of shares(exceptions possible depending on the implementation).

type NamespaceData

type NamespaceData []RowNamespaceData

NamespaceData stores collections of RowNamespaceData, each representing shares and their proofs within a namespace. NOTE: NamespaceData does not have it protobuf Container representation and its only *streamed* as RowNamespaceData. The protobuf might be added as need comes.

func (NamespaceData) Flatten

func (nd NamespaceData) Flatten() []libshare.Share

Flatten combines all shares from all rows within the namespace into a single slice.

func (*NamespaceData) ReadFrom

func (nd *NamespaceData) ReadFrom(reader io.Reader) (int64, error)

ReadFrom reads NamespaceData from the provided reader implementing io.ReaderFrom. It reads series of length-delimited RowNamespaceData until EOF draining the stream.

func (NamespaceData) Verify

func (nd NamespaceData) Verify(root *share.AxisRoots, namespace libshare.Namespace) error

Verify checks the integrity of the NamespaceData against a provided root and namespace.

func (NamespaceData) WriteTo

func (nd NamespaceData) WriteTo(writer io.Writer) (int64, error)

WriteTo writes the length-delimited protobuf of NamespaceData to the provided writer. implementing io.WriterTo.

type NamespaceDataID

type NamespaceDataID struct {
	// Embedding EdsID to include the block height.
	EdsID
	// DataNamespace will be used to identify the data within the EDS.
	DataNamespace libshare.Namespace
}

NamespaceDataID filters the data in the EDS by a specific namespace.

func NamespaceDataIDFromBinary

func NamespaceDataIDFromBinary(data []byte) (NamespaceDataID, error)

NamespaceDataIDFromBinary deserializes a NamespaceDataID from its binary form. It returns an error if the binary data's length does not match the expected size.

func NewNamespaceDataID

func NewNamespaceDataID(height uint64, namespace libshare.Namespace) (NamespaceDataID, error)

NewNamespaceDataID creates a new NamespaceDataID with the specified parameters. It validates the namespace and returns an error if it is invalid.

func (NamespaceDataID) AppendBinary added in v0.21.9

func (ndid NamespaceDataID) AppendBinary(data []byte) ([]byte, error)

AppendBinary helps in appending the binary form of DataNamespace to the serialized RowID data.

func (*NamespaceDataID) Equals

func (ndid *NamespaceDataID) Equals(other NamespaceDataID) bool

Equals checks equality of NamespaceDataID.

func (NamespaceDataID) MarshalBinary

func (ndid NamespaceDataID) MarshalBinary() ([]byte, error)

MarshalBinary encodes NamespaceDataID into binary form. NOTE: Proto is avoided because * Its size is not deterministic which is required for IPLD. * No support for uint16

func (NamespaceDataID) Name added in v0.26.4

func (ndid NamespaceDataID) Name() string

func (*NamespaceDataID) ReadFrom

func (ndid *NamespaceDataID) ReadFrom(r io.Reader) (int64, error)

ReadFrom reads the binary form of NamespaceDataID from the provided reader.

func (NamespaceDataID) ResponseReader added in v0.26.4

func (ndid NamespaceDataID) ResponseReader(ctx context.Context, acc Accessor) (io.Reader, error)

func (NamespaceDataID) Validate

func (ndid NamespaceDataID) Validate() error

Validate checks if the NamespaceDataID is valid. It checks the validity of the EdsID and the DataNamespace.

func (NamespaceDataID) WriteTo

func (ndid NamespaceDataID) WriteTo(w io.Writer) (int64, error)

WriteTo writes the binary form of NamespaceDataID to the provided writer.

type RangeNamespaceData added in v0.25.3

type RangeNamespaceData struct {
	Shares                  [][]libshare.Share `json:"shares,omitempty"`
	FirstIncompleteRowProof *nmt.Proof         `json:"first_row_proof,omitempty"`
	LastIncompleteRowProof  *nmt.Proof         `json:"last_row_proof,omitempty"`
}

RangeNamespaceData represents a contiguous segment of shares from an original part of the data square (ODS) that belong to a specific namespace. It encapsulates both the share data and the cryptographic proofs for the incomplete rows necessary to verify the shares' inclusion to the respective row roots.

This structure is typically constructed using RangeNamespaceDataFromShares, which extracts a rectangular subset of shares from the EDS and populates minimal proof information.

Fields:

  • Shares: A 2D slice of shares where each inner slice represents a row. The shares must all belong to the same namespace and fall within the [from, to] coordinate range.
  • FirstIncompleteRowProof: A Proof object (contains proofs for the first row of a data range)
  • LastIncompleteRowProof: A Proof object (contains proofs for the last row of a data range)

Notes:

  • Consumers of this struct should ensure that Verify() is called to validate the data against the respective row roots using the populated or generated proofs.
  • This structure is commonly used in blob availability proofs, light client verification, and namespace-scoped retrieval over the shwap or DAS interfaces.
  • FirstIncompleteRowProof, LastIncompleteRowProof can be empty

func RangeNamespaceDataFromProto added in v0.25.3

func RangeNamespaceDataFromProto(nd *pb.RangeNamespaceData) (RangeNamespaceData, error)

func RangeNamespaceDataFromShares added in v0.25.3

func RangeNamespaceDataFromShares(
	extendedRowShares [][]libshare.Share,
	from, to SampleCoords,
) (RangeNamespaceData, error)

RangeNamespaceDataFromShares constructs a RangeNamespaceData structure from a selection of namespaced shares within an ODS.

Parameters:

  • shares: A 2D slice of shares grouped by rows (each inner slice represents a row). These shares should cover the range between the 'from' and 'to' coordinates, inclusive.
  • from: The starting coordinate (row, column) of the range within the ODS.
  • to: The ending coordinate (row, column) of the range (inclusive).

Returns:

  • A RangeNamespaceData containing the shares and Merkle proofs for the incomplete rows.
  • An error if the range is invalid or extraction fails.

func (*RangeNamespaceData) Flatten added in v0.25.3

func (rngdata *RangeNamespaceData) Flatten() []libshare.Share

Flatten returns a single slice containing all shares from all rows within the namespace.

If the RangeNamespaceData is empty (i.e., contains no shares), Flatten returns nil. Otherwise, it returns a flattened slice of libshare.Share combining shares from all rows.

func (*RangeNamespaceData) IsEmpty added in v0.25.3

func (rngdata *RangeNamespaceData) IsEmpty() bool

func (*RangeNamespaceData) ToProto added in v0.25.3

func (rngdata *RangeNamespaceData) ToProto() *pb.RangeNamespaceData

func (*RangeNamespaceData) VerifyInclusion added in v0.25.3

func (rngdata *RangeNamespaceData) VerifyInclusion(
	from SampleCoords,
	to SampleCoords,
	odsSize int,
	roots [][]byte,
) error

VerifyInclusion checks whether the shares stored within the RangeNamespaceData (`rngdata.Shares`) are valid and provably included in the provided rowRoots.

func (*RangeNamespaceData) VerifyNamespace added in v0.25.3

func (rngdata *RangeNamespaceData) VerifyNamespace(
	from SampleCoords,
	to SampleCoords,
	odsSize int,
	roots [][]byte,
) error

VerifyNamespace checks whether the shares stored within the RangeNamespaceData (`rngdata.Shares`) are valid and provably included in the provided rowRoots. It does exactly the same as `VerifyInclusion` with 1 extra condition: it checks whether the provided data are complete under the namespace.

type RangeNamespaceDataID added in v0.25.3

type RangeNamespaceDataID struct {
	EdsID
	// From specifies the index of the first share in the range.
	From int
	// To specifies the index of the last share in the range(exclusively).
	To int
}

RangeNamespaceDataID uniquely identifies a continuous range of shares within an Original DataSquare (ODS) The range is defined by the indexes of the first (`From`) and last (`To`) (exclusively) shares in the range. This struct is used to reference and verify a subset of shares (e.g., for a blob or a namespace proof) within the ODS.

Fields:

  • EdsID: to identify the height
  • From: The index of the first share in the range.
  • To: The index of the last share in the range(exclusively).

Example usage:

id := RangeNamespaceDataID{
  EdsID: ...,
  From: 0,
  To:   4,
}

func NewRangeNamespaceDataID added in v0.25.3

func NewRangeNamespaceDataID(
	edsID EdsID,
	from, to, odsSize int,
) (RangeNamespaceDataID, error)

func RangeNamespaceDataIDFromBinary added in v0.25.3

func RangeNamespaceDataIDFromBinary(data []byte) (RangeNamespaceDataID, error)

RangeNamespaceDataIDFromBinary deserializes a RangeNamespaceDataID from its binary form.

func (*RangeNamespaceDataID) Equals added in v0.25.3

func (rngid *RangeNamespaceDataID) Equals(other RangeNamespaceDataID) bool

Equals checks equality of RangeNamespaceDataID.

func (RangeNamespaceDataID) MarshalBinary added in v0.25.3

func (rngid RangeNamespaceDataID) MarshalBinary() ([]byte, error)

MarshalBinary encodes RangeNamespaceDataID into binary form.

func (*RangeNamespaceDataID) ReadFrom added in v0.25.3

func (rngid *RangeNamespaceDataID) ReadFrom(r io.Reader) (int64, error)

ReadFrom reads the binary form of RangeNamespaceDataID from the provided reader.

func (RangeNamespaceDataID) Validate added in v0.25.3

func (rngid RangeNamespaceDataID) Validate() error

Validate performs basic fields validation.

func (RangeNamespaceDataID) Verify added in v0.25.3

func (rngid RangeNamespaceDataID) Verify(odsSize int) error

Verify validates the RangeNamespaceDataID fields and verifies that number of the requested shares does not exceed the number of shares inside the ODS.

func (RangeNamespaceDataID) WriteTo added in v0.25.3

func (rngid RangeNamespaceDataID) WriteTo(w io.Writer) (int64, error)

WriteTo writes the binary form of RangeNamespaceDataID to the provided writer.

type Row

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

Row represents a portion of a row in an EDS, either left or right half.

func NewRow

func NewRow(shares []libshare.Share, side RowSide) Row

NewRow creates a new Row with the specified shares and side.

func RowFromEDS added in v0.21.5

func RowFromEDS(eds *rsmt2d.ExtendedDataSquare, rowIdx int, side RowSide) (Row, error)

RowFromEDS constructs a new Row from an EDS based on the specified row index and side.

func RowFromProto

func RowFromProto(r *pb.Row) (Row, error)

RowFromProto converts a protobuf Row to a Row structure.

func (Row) IsEmpty

func (r Row) IsEmpty() bool

IsEmpty reports whether the Row is empty, i.e. doesn't contain any shares.

func (Row) MarshalJSON added in v0.21.5

func (r Row) MarshalJSON() ([]byte, error)

MarshalJSON encodes row to the json encoded bytes.

func (*Row) Shares

func (r *Row) Shares() ([]libshare.Share, error)

Shares reconstructs the complete row shares from the half provided, using RSMT2D for data recovery if needed. It caches the reconstructed shares for future use and converts Row to Both side.

func (Row) ToProto

func (r Row) ToProto() *pb.Row

ToProto converts the Row to its protobuf representation.

func (*Row) UnmarshalJSON added in v0.21.5

func (r *Row) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes json bytes to the row.

func (*Row) Verify

func (r *Row) Verify(roots *share.AxisRoots, idx int) error

Verify checks if the row's shares match the expected number from the root data and validates the side of the row.

type RowID

type RowID struct {
	EdsID        // Embedding EdsID to include the block height in RowID.
	RowIndex int // RowIndex specifies the position of the row within the data share.
}

RowID uniquely identifies a row in the data square of a blockchain block, combining block height with the row's index.

func NewRowID

func NewRowID(height uint64, rowIdx, edsSize int) (RowID, error)

NewRowID creates a new RowID with the specified block height, row index, and EDS size. It returns an error if the validation fails, ensuring the RowID conforms to expected constraints.

func RowIDFromBinary

func RowIDFromBinary(data []byte) (RowID, error)

RowIDFromBinary decodes a RowID from its binary representation. It returns an error if the input data does not conform to the expected size or content format.

func (RowID) AppendBinary added in v0.21.9

func (rid RowID) AppendBinary(data []byte) ([]byte, error)

AppendBinary assists in binary encoding of RowID by appending the encoded fields to the given byte slice.

func (*RowID) Equals

func (rid *RowID) Equals(other RowID) bool

Equals checks equality of RowID.

func (RowID) MarshalBinary

func (rid RowID) MarshalBinary() ([]byte, error)

MarshalBinary encodes the RowID into a binary form for storage or network transmission.

func (*RowID) ReadFrom

func (rid *RowID) ReadFrom(r io.Reader) (int64, error)

ReadFrom reads the binary form of RowID from the provided reader.

func (RowID) Validate

func (rid RowID) Validate() error

Validate performs basic field validation.

func (RowID) Verify

func (rid RowID) Verify(edsSize int) error

Verify validates the RowID fields and verifies that RowIndex is within the bounds of the square size

func (RowID) WriteTo

func (rid RowID) WriteTo(w io.Writer) (int64, error)

WriteTo writes the binary form of RowID to the provided writer.

type RowNamespaceData

type RowNamespaceData struct {
	Shares []libshare.Share `json:"shares"` // Shares within the namespace.
	Proof  *nmt.Proof       `json:"proof"`  // Proof of the shares' inclusion in the namespace.
}

RowNamespaceData holds shares and their corresponding proof for a single row within a namespace.

func RowNamespaceDataFromProto

func RowNamespaceDataFromProto(row *pb.RowNamespaceData) (RowNamespaceData, error)

RowNamespaceDataFromProto constructs RowNamespaceData out of its protobuf representation.

func RowNamespaceDataFromShares

func RowNamespaceDataFromShares(
	shares []libshare.Share,
	namespace libshare.Namespace,
	rowIndex int,
) (RowNamespaceData, error)

RowNamespaceDataFromShares extracts and constructs a RowNamespaceData from shares within the specified namespace.

func (RowNamespaceData) IsEmpty

func (rnd RowNamespaceData) IsEmpty() bool

IsEmpty reports whether the RowNamespaceData is empty, i.e. doesn't contain a proof.

func (*RowNamespaceData) ReadFrom

func (rnd *RowNamespaceData) ReadFrom(reader io.Reader) (int64, error)

ReadFrom reads length-delimited protobuf representation of RowNamespaceData implementing io.ReaderFrom.

func (RowNamespaceData) ToProto

func (rnd RowNamespaceData) ToProto() *pb.RowNamespaceData

ToProto converts RowNamespaceData to its protobuf representation for serialization.

func (RowNamespaceData) Verify

func (rnd RowNamespaceData) Verify(roots *share.AxisRoots, namespace libshare.Namespace, rowIdx int) error

Verify checks validity of the RowNamespaceData against the AxisRoots, Namespace and Row index.

func (RowNamespaceData) WriteTo

func (rnd RowNamespaceData) WriteTo(writer io.Writer) (int64, error)

WriteTo writes length-delimited protobuf representation of RowNamespaceData. implementing io.WriterTo.

type RowNamespaceDataID

type RowNamespaceDataID struct {
	RowID // Embedded RowID representing the specific row in the EDS.
	// DataNamespace is used to facilitate comparisons.
	DataNamespace libshare.Namespace
}

RowNamespaceDataID uniquely identifies a piece of namespaced data within a row of an Extended Data Square (EDS).

func NewRowNamespaceDataID

func NewRowNamespaceDataID(
	height uint64,
	rowIdx int,
	namespace libshare.Namespace,
	edsSize int,
) (RowNamespaceDataID, error)

NewRowNamespaceDataID creates a new RowNamespaceDataID with the specified parameters. It validates the RowNamespaceDataID against the provided EDS size.

func RowNamespaceDataIDFromBinary

func RowNamespaceDataIDFromBinary(data []byte) (RowNamespaceDataID, error)

RowNamespaceDataIDFromBinary deserializes a RowNamespaceDataID from its binary form. It returns an error if the binary data's length does not match the expected size.

func (RowNamespaceDataID) AppendBinary added in v0.21.9

func (rndid RowNamespaceDataID) AppendBinary(data []byte) ([]byte, error)

AppendBinary helps in appending the binary form of DataNamespace to the serialized RowID data.

func (*RowNamespaceDataID) Equals

func (rndid *RowNamespaceDataID) Equals(other RowNamespaceDataID) bool

Equals checks equality of RowNamespaceDataID.

func (RowNamespaceDataID) MarshalBinary

func (rndid RowNamespaceDataID) MarshalBinary() ([]byte, error)

MarshalBinary encodes RowNamespaceDataID into binary form. NOTE: Proto is avoided because * Its size is not deterministic which is required for IPLD. * No support for uint16

func (*RowNamespaceDataID) ReadFrom

func (rndid *RowNamespaceDataID) ReadFrom(r io.Reader) (int64, error)

ReadFrom reads the binary form of RowNamespaceDataID from the provided reader.

func (RowNamespaceDataID) Validate

func (rndid RowNamespaceDataID) Validate() error

Validate performs basic field validation.

func (RowNamespaceDataID) Verify

func (rndid RowNamespaceDataID) Verify(edsSize int) error

Verify validates the RowNamespaceDataID and verifies the embedded RowID.

func (RowNamespaceDataID) WriteTo

func (rndid RowNamespaceDataID) WriteTo(w io.Writer) (int64, error)

WriteTo writes the binary form of RowNamespaceDataID to the provided writer.

type RowSide

type RowSide int

RowSide enumerates the possible sides of a row within an Extended Data Square (EDS).

const (
	Left  RowSide = iota // Left side of the row.
	Right                // Right side of the row.
	Both                 // Both sides of the row.
)

func (RowSide) String added in v0.21.5

func (s RowSide) String() string

func (RowSide) ToProto

func (s RowSide) ToProto() pb.Row_HalfSide

ToProto converts a RowSide to its protobuf representation.

type Sample

type Sample struct {
	libshare.Share             // Embeds the Share which includes the data with namespace.
	Proof          *nmt.Proof  // Proof is the Merkle Proof validating the share's inclusion.
	ProofType      rsmt2d.Axis // ProofType indicates whether the proof is against a row or a column.
}

Sample represents a data share along with its Merkle proof, used to validate the share's inclusion in a data square.

func SampleFromProto

func SampleFromProto(s *pb.Sample) (Sample, error)

SampleFromProto converts a protobuf Sample back into its domain model equivalent.

func SampleFromShares

func SampleFromShares(shares []libshare.Share, proofType rsmt2d.Axis, idx SampleCoords) (Sample, error)

SampleFromShares creates a Sample from a list of shares, using the specified proof type and the share index to be included in the sample.

func (Sample) IsEmpty

func (s Sample) IsEmpty() bool

IsEmpty reports whether the Sample is empty, i.e. doesn't contain a proof.

func (Sample) MarshalJSON added in v0.21.5

func (s Sample) MarshalJSON() ([]byte, error)

MarshalJSON encodes sample to the json encoded bytes.

func (Sample) ToProto

func (s Sample) ToProto() *pb.Sample

ToProto converts a Sample into its protobuf representation for serialization purposes.

func (*Sample) UnmarshalJSON added in v0.21.5

func (s *Sample) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes bytes to the Sample.

func (Sample) Verify

func (s Sample) Verify(roots *share.AxisRoots, rowIdx, colIdx int) error

Verify checks the inclusion of the share using its Merkle proof under the specified AxisRoots. Returns an error if the proof is invalid or does not correspond to the indicated proof type.

type SampleCoords added in v0.20.4

type SampleCoords struct {
	Row int `json:"row"`
	Col int `json:"col"`
}

func SampleCoordsFrom1DIndex added in v0.20.4

func SampleCoordsFrom1DIndex(idx, squareSize int) (SampleCoords, error)

func (SampleCoords) String added in v0.25.3

func (s SampleCoords) String() string

type SampleID

type SampleID struct {
	RowID          // Embeds RowID to incorporate block height and row index.
	ShareIndex int // ShareIndex specifies the index of the sample within the row.
}

SampleID uniquely identifies a specific sample within a row of an Extended Data Square (EDS).

func NewSampleID

func NewSampleID(height uint64, idx SampleCoords, edsSize int) (SampleID, error)

NewSampleID constructs a new SampleID using the provided block height, sample index, and EDS size. It calculates the row and share index based on the sample index and EDS size.

func SampleIDFromBinary

func SampleIDFromBinary(data []byte) (SampleID, error)

SampleIDFromBinary deserializes a SampleID from binary data, ensuring the data length matches the expected size.

func (SampleID) AppendBinary added in v0.21.9

func (sid SampleID) AppendBinary(data []byte) ([]byte, error)

AppendBinary helps in constructing the binary representation by appending the encoded ShareIndex to the serialized RowID.

func (*SampleID) Equals

func (sid *SampleID) Equals(other SampleID) bool

Equals checks equality of SampleID.

func (SampleID) MarshalBinary

func (sid SampleID) MarshalBinary() ([]byte, error)

MarshalBinary encodes SampleID into binary form. NOTE: Proto is avoided because * Its size is not deterministic which is required for IPLD. * No support for uint16

func (*SampleID) ReadFrom

func (sid *SampleID) ReadFrom(r io.Reader) (int64, error)

ReadFrom reads the binary form of SampleID from the provided reader.

func (SampleID) Validate

func (sid SampleID) Validate() error

Validate performs basic field validation.

func (SampleID) Verify

func (sid SampleID) Verify(edsSize int) error

Verify validates the SampleID and verifies that the ShareIndex is within the bounds of the square size.

func (SampleID) WriteTo

func (sid SampleID) WriteTo(w io.Writer) (int64, error)

WriteTo writes the binary form of SampleID to the provided writer.

Directories

Path Synopsis
mock
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.
p2p
shrex
Package shrex provides functionality that powers the share exchange protocols used by celestia-node.
Package shrex provides functionality that powers the share exchange protocols used by celestia-node.
shrex/peers
Package peers provides a peer manager that handles peer discovery and peer selection for the shrex getter.
Package peers provides a peer manager that handles peer discovery and peer selection for the shrex getter.
shrex/shrexsub
This package defines a protocol that is used to broadcast shares to peers over a pubsub network.
This package defines a protocol that is used to broadcast shares to peers over a pubsub network.

Jump to

Keyboard shortcuts

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