ssz package
Subpackages
- ssz.cache package
- ssz.sedes package
- Submodules
- ssz.sedes.base module
- ssz.sedes.basic module
- ssz.sedes.bitlist module
- ssz.sedes.bitvector module
- ssz.sedes.boolean module
- ssz.sedes.byte module
- ssz.sedes.byte_list module
- ssz.sedes.byte_vector module
- ssz.sedes.container module
Container
Container.chunk_count
Container.deserialize_fixed_size_parts()
Container.deserialize_variable_size_parts()
Container.get_element_sedes()
Container.get_fixed_size()
Container.get_hash_tree_root()
Container.get_hash_tree_root_and_leaves()
Container.get_sedes_id()
Container.is_fixed_sized
Container.is_packing
Container.serialize()
- ssz.sedes.list module
- ssz.sedes.serializable module
- ssz.sedes.signed_serializable module
- ssz.sedes.uint module
- ssz.sedes.vector module
- Module contents
- ssz.tools package
Submodules
ssz.abc module
- class ssz.abc.HashableStructureAPI(*args, **kwds)
-
- abstract property chunks: PVector[Hash32]
- abstract property elements: PVector[TElement]
- abstract evolver() HashableStructureEvolverAPI[TStructure, TElement]
- abstract classmethod from_iterable_and_sedes(iterable: Iterable[TElement], sedes: BaseProperCompositeSedes, max_length: int | None)
- abstract property hash_tree_root: Hash32
- abstract property raw_root: Hash32
- abstract transform(*transformations)
- class ssz.abc.HashableStructureEvolverAPI(hashable_structure: TStructure)
Bases:
ABC
,Generic
[TStructure
,TElement
]- abstract persistent() TStructure
- class ssz.abc.ResizableHashableStructureAPI(*args, **kwds)
Bases:
HashableStructureAPI
[TElement
]- abstract append(value: TElement) TStructure
- abstract evolver() ResizableHashableStructureEvolverAPI[TStructure, TElement]
ssz.codec module
- ssz.codec.decode(ssz, sedes)
Decode a SSZ encoded object.
- ssz.codec.encode(value, sedes=None)
Encode object in SSZ format. sedes needs to be explicitly mentioned for encode/decode of integers(as of now). sedes parameter could be given as a string or as the actual sedes object itself.
ssz.constants module
ssz.exceptions module
- exception ssz.exceptions.DeserializationError
Bases:
SSZException
Exception raised if deserialization fails.
- exception ssz.exceptions.SSZException
Bases:
Exception
Base class for exceptions raised by this package.
- exception ssz.exceptions.SerializationError
Bases:
SSZException
Exception raised if serialization fails.
ssz.hash module
ssz.hash_tree module
- class ssz.hash_tree.HashTree(raw_hash_tree: PVector[PVector[Hash32]], chunk_count: int | None = None)
Bases:
PVector
[Hash32
]- property chunks: PVector[Hash32]
- count(value) integer -- return number of occurrences of value
- evolver()
- index(value[, start[, stop]]) integer -- return first index of value.
Raises ValueError if the value is not present.
Supporting start and stop arguments is optional, but recommended.
- property root: Hash32
- transform(*transformations)
- class ssz.hash_tree.HashTreeEvolver(hash_tree: HashTree)
Bases:
object
- delete(index, stop=None)
- remove(value)
- ssz.hash_tree.append_chunk_to_tree(hash_tree: PVector[PVector[Hash32]], chunk: Hash32) PVector[PVector[Hash32]]
- ssz.hash_tree.compute_hash_tree(chunks: Iterable[Hash32], chunk_count: int | None = None) PVector[PVector[Hash32]]
- ssz.hash_tree.generate_chunk_tree_padding(unpadded_chunk_tree: PVector[Hash32], chunk_count: int | None) Generator[Hash32, None, None]
- ssz.hash_tree.generate_hash_tree_layers(chunks: PVector[Hash32]) Generator[PVector[Hash32], None, None]
- ssz.hash_tree.pad_hash_tree(unpadded_chunk_tree: PVector[PVector[Hash32]], chunk_count: int | None = None) PVector[PVector[Hash32]]
- ssz.hash_tree.recompute_hash_in_tree(hash_tree: PVector[PVector[Hash32]], layer_index: int, hash_index: int) PVector[PVector[Hash32]]
ssz.hashable_container module
- class ssz.hashable_container.FieldDescriptor(name: str)
Bases:
object
Descriptor translating from __getattr__ to __getitem__ calls for a given attribute.
- ssz.hashable_container.GenericMetaHashableContainer
alias of
MetaHashableContainer
- ssz.hashable_container.GenericMetaSignedHashableContainer
alias of
MetaSignedHashableContainer
- class ssz.hashable_container.HashableContainer(*args, **kwargs)
Bases:
BaseHashableStructure
[TElement
]Base class for hashable containers.
- evolver() HashableContainerEvolver[TStructure, TElement]
- property hash_tree_root: Hash32
- class ssz.hashable_container.HashableContainerEvolver(hashable_structure: TStructure)
Bases:
HashableStructureEvolver
[TStructure
,TElement
]Base class for evolvers for hashable containers.
Subclasses (created dynamically by MetaHashableContainer when creating the corresponding HashableContainer) should add settable field descriptors for all fields.
- class ssz.hashable_container.Meta(fields, field_names, field_names_to_element_indices, container_sedes, evolver_class)
Bases:
tuple
- evolver_class: Type[HashableContainerEvolver]
Alias for field number 4
- class ssz.hashable_container.MetaHashableContainer(name: str, bases: Tuple[Type, ...], namespace: Dict[str, Any])
Bases:
ABCMeta
Metaclass which creates HashableContainers.
- deserialize(data)
- get_fixed_size()
- get_hash_tree_root(value)
- get_hash_tree_root_and_leaves(value, cache)
- get_key(value)
- get_sedes_id()
- property is_fixed_sized
- serialize(value)
- class ssz.hashable_container.MetaSignedHashableContainer(name, bases, namespace)
Bases:
MetaHashableContainer
- class ssz.hashable_container.SettableFieldDescriptor(name: str)
Bases:
FieldDescriptor
Settable variant of FieldDescriptor for evolver.
- class ssz.hashable_container.SignedHashableContainer(*args, **kwargs)
Bases:
HashableContainer
[TElement
]- property signing_root: Hash32
- ssz.hashable_container.get_field_sedes_from_fields(fields: Sequence[Tuple[str, BaseSedes]]) Generator[BaseSedes, None, None]
- ssz.hashable_container.get_meta_from_bases(bases: Tuple[Type, ...]) Meta | None
Return the meta object defined by one of the given base classes.
Returns None if no base defines a meta object. Raises a TypeError if more than one do.
ssz.hashable_list module
- class ssz.hashable_list.HashableList(elements: PVector[TElement], hash_tree: HashTree, sedes: BaseProperCompositeSedes, max_length: int | None = None)
Bases:
BaseResizableHashableStructure
[TElement
],Sequence
[TElement
]- property hash_tree_root: Hash32
ssz.hashable_structure module
- class ssz.hashable_structure.BaseHashableStructure(elements: PVector[TElement], hash_tree: HashTree, sedes: BaseProperCompositeSedes, max_length: int | None = None)
Bases:
HashableStructureAPI
[TElement
]- property chunks: PVector[Hash32]
- property elements: PVector[TElement]
- evolver() HashableStructureEvolverAPI[TStructure, TElement]
- classmethod from_iterable_and_sedes(iterable: Iterable[TElement], sedes: BaseProperCompositeSedes, max_length: int | None = None)
- property raw_root: Hash32
- property sedes: BaseProperCompositeSedes
- transform(*transformations)
- class ssz.hashable_structure.BaseResizableHashableStructure(elements: PVector[TElement], hash_tree: HashTree, sedes: BaseProperCompositeSedes, max_length: int | None = None)
Bases:
BaseHashableStructure
,ResizableHashableStructureAPI
[TElement
]- append(value: TElement) TResizableStructure
- evolver() ResizableHashableStructureEvolverAPI[TResizableStructure, TElement]
- class ssz.hashable_structure.HashableStructureEvolver(hashable_structure: TStructure)
Bases:
HashableStructureEvolverAPI
[TStructure
,TElement
]- persistent() TStructure
- class ssz.hashable_structure.ResizableHashableStructureEvolver(hashable_structure: TStructure)
Bases:
HashableStructureEvolver
,ResizableHashableStructureEvolverAPI
[TStructure
,TElement
]
- ssz.hashable_structure.get_appended_chunks(*, appended_elements: Sequence[bytes], element_size: int, num_padding_elements: int) Generator[Hash32, None, None]
Get the sequence of appended chunks.
- ssz.hashable_structure.get_num_padding_elements(*, num_original_elements: int, num_original_chunks: int, element_size: int) int
Compute the number of elements that would still fit in the empty space of the last chunk.
- ssz.hashable_structure.get_updated_chunks(*, updated_elements: Dict[int, bytes], appended_elements: Sequence[bytes], original_chunks: Sequence[Hash32], element_size: int, num_original_elements: int, num_padding_elements: int) Generator[Tuple[int, Hash32], None, None]
For an element changeset, compute the updates that have to be applied to the existing chunks.
The changeset is given as a dictionary of element indices to updated elements and a sequence of appended elements. Note that appended elements that do not affect existing chunks are ignored.
The pre-existing state is given by the sequence of original chunks and the number of elements represented by these chunks.
The return value is a dictionary mapping chunk indices to chunks.
- ssz.hashable_structure.update_element_in_chunk(original_chunk: Hash32, index: int, element: bytes) Hash32
Replace part of a chunk with a given element.
The chunk is interpreted as a concatenated sequence of equally sized elements. This function replaces the element given by its index in the chunk with the given data.
If the length of the element is zero or not a divisor of the chunk size, a ValueError is raised. If the index is out of range, an IndexError is raised.
>>> from ssz.hashable_structure import update_element_in_chunk >>> update_element_in_chunk(b"aabbcc", 1, b"xx") b'aaxxcc'
- ssz.hashable_structure.update_elements_in_chunk(original_chunk: Hash32, updated_elements: Dict[int, bytes]) Hash32
Update multiple elements in a chunk.
The set of updates is given by a dictionary mapping indices to elements. The items of the dictionary will be passed one by one to update_element_in_chunk.
ssz.hashable_vector module
- class ssz.hashable_vector.HashableVector(elements: PVector[TElement], hash_tree: HashTree, sedes: BaseProperCompositeSedes, max_length: int | None = None)
Bases:
BaseHashableStructure
[TElement
],Sequence
[TElement
]- property hash_tree_root: Hash32
ssz.tree_hash module
ssz.typing module
ssz.utils module
- ssz.utils.get_duplicates(values)
- ssz.utils.get_serialized_bytearray(value: Sequence[bool], bit_count: int, extra_byte: bool) bytearray