Documentation
¶
Index ¶
- Variables
- func AddUint[T marshalUints](w *Wrapper, i T)
- func AppendUint[T appendUints](h *Hasher, i T)
- func CalculateLimit(maxCapacity, numItems, size uint64) uint64
- func DecodeBool(src []byte) (bool, error)
- func DecodeDynamicLength(buf []byte, maxSize int) (int, error)
- func DivideInt(a, b int) (int, bool)
- func DivideInt2(a, b, max int) (int, error)
- func ErrBytesLengthFn(name string, found, expected int) error
- func ErrListTooBigFn(name string, found, max int) error
- func ErrVectorLengthFn(name string, found, expected int) error
- func ExtendUint[T uints](b []T, needLen int) []T
- func ExtendUint8(b []uint8, needLen int) []uint8deprecated
- func ExtendUint16(b []uint16, needLen int) []uint16deprecated
- func ExtendUint64(b []uint64, needLen int) []uint64deprecated
- func HashWithDefaultHasher(v HashRoot) ([32]byte, error)
- func MarshalBool(dst []byte, b bool) []byte
- func MarshalSSZ(m Marshaler) ([]byte, error)
- func MarshalUint[T marshalUints](dst []byte, i T) []byte
- func MarshalUint8(dst []byte, i uint8) []bytedeprecated
- func MarshalUint16(dst []byte, i uint16) []bytedeprecated
- func MarshalUint32(dst []byte, i uint32) []bytedeprecated
- func MarshalUint64(dst []byte, i uint64) []bytedeprecated
- func PutUint[T appendUints](h *Hasher, i T)
- func ReadOffset(buf []byte) uint64
- func UnmarshalBool(src []byte) bool
- func UnmarshalDynamic(src []byte, length int, f func(indx int, b []byte) error) error
- func UnmarshalSSZTest(content []byte, result interface{}) error
- func UnmarshallUint[T unmarshallUints](src []byte) T
- func UnmarshallUint8(src []byte) uint8deprecated
- func UnmarshallUint16(src []byte) uint16deprecated
- func UnmarshallUint32(src []byte) uint32deprecated
- func UnmarshallUint64(src []byte) uint64deprecated
- func ValidateBitlist(buf []byte, bitLimit uint64) error
- func VerifyMultiproof(root []byte, proof [][]byte, leaves [][]byte, indices []int) (bool, error)
- func VerifyProof(root []byte, proof *Proof) (bool, error)
- func WriteOffset(dst []byte, i int) []byte
- type CompressedMultiproof
- type HashRoot
- type Hasher
- func (h *Hasher) Append(i []byte)
- func (h *Hasher) AppendBytes32(b []byte)
- func (h *Hasher) AppendUint8(i uint8)deprecated
- func (h *Hasher) AppendUint64(i uint64)deprecated
- func (h *Hasher) FillUpTo32()
- func (h *Hasher) HashRoot() (res [32]byte, err error)
- func (h *Hasher) Index() int
- func (h *Hasher) Merkleize(indx int)
- func (h *Hasher) MerkleizeWithMixin(indx int, num, limit uint64)
- func (h *Hasher) PutBitlist(bb []byte, maxSize uint64)
- func (h *Hasher) PutBool(b bool)
- func (h *Hasher) PutBytes(b []byte)
- func (h *Hasher) PutRootVector(b [][]byte, maxCapacity ...uint64) error
- func (h *Hasher) PutUint8(i uint8)deprecated
- func (h *Hasher) PutUint16(i uint16)deprecated
- func (h *Hasher) PutUint32(i uint32)deprecated
- func (h *Hasher) PutUint64(i uint64)deprecated
- func (h *Hasher) PutUint64Array(b []uint64, maxCapacity ...uint64)
- func (h *Hasher) Reset()
- type HasherPool
- type Marshaler
- type Multiproof
- type Node
- func EmptyLeaf() *Node
- func LeafFromBool(b bool) *Node
- func LeafFromBytes(b []byte) *Node
- func LeafFromUint[T marshalUints](i T) *Node
- func LeafFromUint8(i uint8) *Nodedeprecated
- func LeafFromUint16(i uint16) *Nodedeprecated
- func LeafFromUint32(i uint32) *Nodedeprecated
- func LeafFromUint64(i uint64) *Nodedeprecated
- func LeavesFromUint64(items []uint64) []*Node
- func NewNodeWithLR(left, right *Node) *Node
- func NewNodeWithValue(value []byte) *Node
- func TreeFromChunks(chunks [][]byte) (*Node, error)
- func TreeFromNodes(leaves []*Node) (*Node, error)
- func TreeFromNodesWithMixin(leaves []*Node, num, limit int) (*Node, error)
- type Proof
- type Unmarshaler
- type Wrapper
- func (w *Wrapper) AddBytes(b []byte)
- func (w *Wrapper) AddEmpty()
- func (w *Wrapper) AddNode(n *Node)
- func (w *Wrapper) AddUint8(i uint8)deprecated
- func (w *Wrapper) AddUint16(i uint16)deprecated
- func (w *Wrapper) AddUint32(i uint32)deprecated
- func (w *Wrapper) AddUint64(i uint64)deprecated
- func (w *Wrapper) Commit(i int)
- func (w *Wrapper) CommitWithMixin(i, num, limit int)
- func (w *Wrapper) Indx() int
- func (w *Wrapper) Node() *Node
Constants ¶
This section is empty.
Variables ¶
var ( ErrOffsetExceedsSize = errors.New("offset exceeds size of buffer") ErrOffsetOrdering = errors.New("offset is less than previous offset") ErrDynamicLengthTooShort = errors.New("buffer too small to hold an offset") ErrDynamicLengthNotOffsetSized = errors.New("list offsets must be multiples of the offset size (4)") ErrDynamicLengthExceedsMax = errors.New("list length longer than ssz max length for the type") ErrInvalidEncoding = errors.New("invalid encoding") )
var ( ErrOffset = fmt.Errorf("incorrect offset") ErrSize = fmt.Errorf("incorrect size") ErrBytesLength = fmt.Errorf("bytes array does not have the correct length") ErrVectorLength = fmt.Errorf("vector does not have the correct length") ErrListTooBig = fmt.Errorf("list length is higher than max value") ErrEmptyBitlist = fmt.Errorf("bitlist is empty") ErrInvalidVariableOffset = fmt.Errorf("invalid ssz encoding. first variable element offset indexes into fixed value data") )
var ( // ErrIncorrectByteSize means that the byte size is incorrect ErrIncorrectByteSize = fmt.Errorf("incorrect byte size") // ErrIncorrectListSize means that the size of the list is incorrect ErrIncorrectListSize = fmt.Errorf("incorrect list size") ErrRootSizeInvalid = errors.New("root must be 32 bytes") )
Functions ¶
func AddUint ¶
func AddUint[T marshalUints](w *Wrapper, i T)
AddUint adds a uint8, uint16, uint32, or uint64 leaf node.
func AppendUint ¶
func AppendUint[T appendUints](h *Hasher, i T)
AppendUint appends a uint8, uint16, uint32, or uint64 value without 32-byte padding.
func CalculateLimit ¶
func DecodeBool ¶
func DecodeDynamicLength ¶
DecodeDynamicLength decodes the length from the dynamic input
func DivideInt2 ¶
func ErrBytesLengthFn ¶
func ErrListTooBigFn ¶
func ErrVectorLengthFn ¶
func ExtendUint ¶
func ExtendUint[T uints](b []T, needLen int) []T
ExtendUint extends an unsigned integer buffer to a given size.
func ExtendUint8
deprecated
func ExtendUint16
deprecated
func ExtendUint64
deprecated
func HashWithDefaultHasher ¶
HashWithDefaultHasher hashes a HashRoot object with a Hasher from the default HasherPool
func MarshalBool ¶
MarshalBool marshals a boolean to dst
func MarshalUint ¶
MarshalUint marshals a little endian uint8, uint16, uint32, or uint64 to dst.
func MarshalUint8
deprecated
func MarshalUint16
deprecated
func MarshalUint32
deprecated
func MarshalUint64
deprecated
func PutUint ¶
func PutUint[T appendUints](h *Hasher, i T)
PutUint appends a uint8, uint16, uint32, or uint64 in 32 bytes.
func UnmarshalBool ¶
UnmarshalBool unmarshals a boolean from the src input
func UnmarshalDynamic ¶
UnmarshalDynamic unmarshals the dynamic items from the input
func UnmarshalSSZTest ¶
func UnmarshallUint ¶
func UnmarshallUint[T unmarshallUints](src []byte) T
UnmarshallUint unmarshals a little endian uint8, uint16, uint32, or uint64 from the src input.
func UnmarshallUint8
deprecated
func UnmarshallUint16
deprecated
func UnmarshallUint32
deprecated
func UnmarshallUint64
deprecated
func ValidateBitlist ¶
ValidateBitlist validates that the bitlist is correct
func VerifyMultiproof ¶
VerifyMultiproof verifies a proof for multiple leaves against the given root.
func VerifyProof ¶
VerifyProof verifies a single merkle branch. It's more efficient than VerifyMultiproof for proving one leaf.
Types ¶
type CompressedMultiproof ¶
type CompressedMultiproof struct {
Indices []int
Leaves [][]byte
Hashes [][]byte
ZeroLevels []int // Stores the level for every omitted zero hash in the proof
}
CompressedMultiproof represents a compressed merkle proof of several leaves. Compression is achieved by omitting zero hashes (and their hashes). `ZeroLevels` contains information which helps the verifier fill in those hashes.
func (*CompressedMultiproof) Decompress ¶
func (c *CompressedMultiproof) Decompress() *Multiproof
Decompress returns a new multiproof, filling in the omitted zero hashes. See `CompressedMultiProof` for more info.
type Hasher ¶
type Hasher struct {
// contains filtered or unexported fields
}
Hasher is a utility tool to hash SSZ structs
func NewHasherWithHash ¶
NewHasher creates a new Hasher object with a custom hash function
func (*Hasher) AppendBytes32 ¶
func (*Hasher) AppendUint8
deprecated
func (*Hasher) AppendUint64
deprecated
func (*Hasher) FillUpTo32 ¶
func (h *Hasher) FillUpTo32()
func (*Hasher) MerkleizeWithMixin ¶
MerkleizeWithMixin is used to merkleize the last group of the hasher
func (*Hasher) PutBitlist ¶
PutBitlist appends a ssz bitlist
func (*Hasher) PutRootVector ¶
PutRootVector appends an array of roots
func (*Hasher) PutUint64Array ¶
PutUint64Array appends an array of uint64
type HasherPool ¶
type HasherPool struct {
// contains filtered or unexported fields
}
HasherPool may be used for pooling Hashers for similarly typed SSZs.
var DefaultHasherPool HasherPool
DefaultHasherPool is a default hasher pool
type Marshaler ¶
type Marshaler interface {
MarshalSSZTo(dst []byte) ([]byte, error)
MarshalSSZ() ([]byte, error)
SizeSSZ() int
}
Marshaler is the interface implemented by types that can marshal themselves into valid SZZ.
type Multiproof ¶
Multiproof represents a merkle proof of several leaves.
func (*Multiproof) Compress ¶
func (p *Multiproof) Compress() *CompressedMultiproof
Compress returns a new proof with zero hashes omitted. See `CompressedMultiproof` for more info.
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node represents a node in the tree backing of a SSZ object.
func LeafFromBool ¶
func LeafFromBytes ¶
func LeafFromUint ¶
func LeafFromUint[T marshalUints](i T) *Node
LeafFromUint returns a leaf node from a uint8, uint16, uint32, or uint64 value.
func LeafFromUint8
deprecated
func LeafFromUint16
deprecated
func LeafFromUint32
deprecated
func LeafFromUint64
deprecated
func LeavesFromUint64 ¶
func NewNodeWithLR ¶
NewNodeWithLR initializes a branch node.
func NewNodeWithValue ¶
NewNodeWithValue initializes a leaf node.
func TreeFromChunks ¶
TreeFromChunks constructs a tree from leaf values. The number of leaves should be a power of 2.
func TreeFromNodes ¶
TreeFromNodes constructs a tree from leaf nodes. This is useful for merging subtrees. The number of leaves should be a power of 2.
func TreeFromNodesWithMixin ¶
func (*Node) Hash ¶
Hash returns the hash of the subtree with the given Node as its root. If root has no children, it returns root's value (not its hash).
func (*Node) Prove ¶
Prove returns a list of sibling values and hashes needed to compute the root hash for a given general index.
func (*Node) ProveMulti ¶
func (n *Node) ProveMulti(indices []int) (*Multiproof, error)
type Unmarshaler ¶
Unmarshaler is the interface implemented by types that can unmarshal a SSZ description of themselves
type Wrapper ¶
type Wrapper struct {
// contains filtered or unexported fields
}