2024-02-12 15:35:23 +01:00
|
|
|
from dataclasses import dataclass
|
2025-05-21 13:17:05 +03:00
|
|
|
from hashlib import blake2b
|
2024-03-15 11:34:43 +01:00
|
|
|
from itertools import chain, zip_longest, compress
|
|
|
|
|
from typing import List, Generator, Self, Sequence
|
2024-03-13 14:59:27 +01:00
|
|
|
|
|
|
|
|
from eth2spec.eip7594.mainnet import Bytes32, KZGCommitment as Commitment
|
2024-05-27 12:38:18 +03:00
|
|
|
from py_ecc.bls import G2ProofOfPossession
|
2024-02-12 15:35:23 +01:00
|
|
|
|
2025-01-29 10:42:53 +00:00
|
|
|
type BlobId = bytes
|
|
|
|
|
|
2024-02-12 15:35:23 +01:00
|
|
|
class NodeId(Bytes32):
|
|
|
|
|
pass
|
|
|
|
|
|
2024-03-13 14:59:27 +01:00
|
|
|
|
2024-03-20 11:03:39 +01:00
|
|
|
class Chunk(bytes):
|
2024-02-12 15:35:23 +01:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
2024-03-08 14:16:14 +01:00
|
|
|
class Column(List[Bytes32]):
|
|
|
|
|
def as_bytes(self) -> bytes:
|
|
|
|
|
return bytes(chain.from_iterable(self))
|
2024-02-12 15:35:23 +01:00
|
|
|
|
|
|
|
|
|
2024-03-08 14:16:14 +01:00
|
|
|
class Row(List[Bytes32]):
|
|
|
|
|
def as_bytes(self) -> bytes:
|
|
|
|
|
return bytes(chain.from_iterable(self))
|
2024-02-12 15:35:23 +01:00
|
|
|
|
|
|
|
|
|
2024-03-08 14:16:14 +01:00
|
|
|
class ChunksMatrix(List[Row | Column]):
|
|
|
|
|
@property
|
2024-02-12 15:35:23 +01:00
|
|
|
def columns(self) -> Generator[List[Chunk], None, None]:
|
2024-03-08 14:16:14 +01:00
|
|
|
yield from map(Column, zip_longest(*self, fillvalue=b""))
|
|
|
|
|
|
|
|
|
|
def transposed(self) -> Self:
|
|
|
|
|
return ChunksMatrix(self.columns)
|
2024-02-12 15:35:23 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-03-14 12:20:46 +01:00
|
|
|
class Bitfield(List[bool]):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
2025-05-20 13:45:53 +03:00
|
|
|
def build_blob_id(row_commitments: Sequence[Commitment]) -> BlobId:
|
2025-05-21 13:17:05 +03:00
|
|
|
hasher = blake2b(digest_size=32)
|
2024-03-15 11:34:43 +01:00
|
|
|
for c in row_commitments:
|
|
|
|
|
hasher.update(bytes(c))
|
2024-03-22 13:01:13 +02:00
|
|
|
return hasher.digest()
|
2024-05-27 12:38:18 +03:00
|
|
|
|
2025-05-22 13:41:45 +03:00
|
|
|
|
2024-05-27 12:38:18 +03:00
|
|
|
class NomosDaG2ProofOfPossession(G2ProofOfPossession):
|
|
|
|
|
# Domain specific tag for Nomos DA protocol
|
|
|
|
|
DST = b"NOMOS_DA_AVAIL"
|