import { ChecksumString } from '@digitaldefiance/ecies-lib'; import { BlockMetadata } from '../blockMetadata'; import { Readable } from '../browserStream'; import { BlockDataType } from '../enumerations/blockDataType'; import { BlockSize } from '../enumerations/blockSize'; import { BlockType } from '../enumerations/blockType'; import { IBaseBlock } from '../interfaces/blocks/base'; import { Checksum } from '../types/checksum'; /** * BaseBlock provides core block functionality. * All blocks in the Owner Free File System derive from this. * * Block Structure: * [Base Header][Layer Headers][Layer Data][Padding] * * Base Header: * - Block Type * - Block Size * - Data Type * - Checksum * - Date Created * * **Immutability Contract:** * All blocks are immutable after construction. The underlying data buffer * should not be modified after the block is created. This ensures: * - Cache consistency: Cached values remain valid throughout the block's lifetime * - Thread safety: Blocks can be safely shared across contexts * - Data integrity: Block checksums remain valid * * While TypeScript/JavaScript cannot enforce true immutability on Uint8Array, * the block system is designed with the expectation that: * 1. Block data is never modified after construction * 2. Cached values (encryption details, address counts) are computed once * 3. All getters return consistent values across multiple calls * * Modifying block data after construction will result in: * - Invalid checksums * - Stale cached values * - Undefined behavior in validation and encryption operations * * @see Requirements 6.3, 6.4 */ export declare abstract class BaseBlock implements IBaseBlock { protected readonly _blockSize: BlockSize; protected readonly _blockType: BlockType; protected readonly _blockDataType: BlockDataType; protected readonly _checksum: Checksum; protected readonly _dateCreated: Date; protected readonly _metadata: BlockMetadata; protected readonly _canRead: boolean; protected readonly _canPersist: boolean; protected readonly _lengthBeforeEncryption: number; /** * Constructs a block. * All derived constructors should trust the data being passed in as relevant to the type of block. * Blocks types that can validate the data are welcome to do so. * @param type Block type * @param dataType Data type * @param checksum Checksum * @param metadata Metadata * @param canRead Whether the block can be read * @param canPersist Whether the block can be persisted */ protected constructor(type: BlockType, dataType: BlockDataType, checksum: Checksum, metadata: BlockMetadata, canRead?: boolean, canPersist?: boolean); /** * The size category of the block */ get blockSize(): BlockSize; /** * The type of block (raw, encrypted, CBL, etc) */ get blockType(): BlockType; /** * The type of data contained in the block */ get blockDataType(): BlockDataType; /** * The block's unique identifier/checksum */ get idChecksum(): Checksum; /** * The block's checksum as a string */ get checksumString(): ChecksumString; /** * When the block was created */ get dateCreated(): Date; /** * Block metadata for storage */ get metadata(): BlockMetadata; /** * Whether the block can be read */ get canRead(): boolean; /** * Whether the block can be persisted */ get canPersist(): boolean; /** * Asynchronously validate the block's checksum and data integrity * @throws {ChecksumMismatchError} If validation fails due to checksum mismatch */ abstract validateAsync(): Promise; /** * Synchronously validate the block's checksum and data integrity * @throws {ChecksumMismatchError} If validation fails due to checksum mismatch */ abstract validateSync(): void; /** * Alias for validateSync() to maintain compatibility * @throws {ChecksumMismatchError} If validation fails due to checksum mismatch */ validate(): void; /** * Get the complete block data including headers and payload */ abstract get data(): Uint8Array | Readable; /** * Get this layer's header data size */ abstract get layerOverheadSize(): number; /** * Get this layer's header data */ abstract get layerHeaderData(): Uint8Array; /** * Get this layer's data (including headers) */ abstract get layerData(): Uint8Array; /** * Get the payload data (excluding headers) */ abstract get layerPayload(): Uint8Array; /** * Get the length of the payload */ abstract get layerPayloadSize(): number; /** * Get all layers in the inheritance chain * This represents the class hierarchy, not instance relationships. * Used for calculating total overhead from all block types in the hierarchy. */ get layers(): IBaseBlock[]; /** * Get the total header size of all layers below this one */ get lowerLayerHeaderSize(): number; /** * Get the parent layer in the inheritance chain * Returns null as we don't track parent instances in the current architecture. */ get parent(): IBaseBlock | null; /** * Get the total header overhead from all layers */ get totalOverhead(): number; /** * Get the complete header data from all layers */ get fullHeaderData(): Uint8Array; } //# sourceMappingURL=base.d.ts.map