import { Member, PlatformID } from '@digitaldefiance/ecies-lib'; import { BaseBlock } from '../blocks/base'; import { ConstituentBlockListBlock } from '../blocks/cbl'; import { BlockHandle } from '../blocks/handle'; import { InMemoryBlockTuple } from '../blocks/memoryTuple'; import { RandomBlock } from '../blocks/random'; import { WhitenedBlock } from '../blocks/whitened'; import { Readable } from '../browserStream'; import { BlockSize } from '../enumerations/blockSize'; import { IBaseBlock } from '../interfaces/blocks/base'; import { IEphemeralBlock } from '../interfaces/blocks/ephemeral'; import { PoolId } from '../interfaces/storage/pooledBlockStore'; import { CBLService } from './cblService'; import { ChecksumService } from './checksum.service'; /** * Options for pool-scoped tuple creation. * When poolId is provided, all blocks used in the tuple are validated * to belong to the specified pool, preventing cross-pool XOR dependencies. * * @see Requirements 3.3 */ export interface TuplePoolOptions { /** Pool that all blocks in the tuple must belong to */ poolId?: PoolId; } /** * TupleService provides utility functions for working with block tuples. * In the Owner Free Filesystem (OFF), tuples are used to: * 1. Store data blocks with random blocks for privacy * 2. Store parity blocks for error correction * 3. Store CBL blocks with their metadata * * @typeParam TID - The platform ID type, defaults to Uint8Array * * @see {@link BlockHandle} - Handle type for disk-based blocks * @see {@link InMemoryBlockTuple} - Tuple type for in-memory blocks * @see Requirements 3.1, 3.2 */ export declare class TupleService { private readonly checksumService; private readonly cblService; constructor(checksumService: ChecksumService, cblService: CBLService); /** * Wrap a block source callback with pool membership validation. * When a block is returned, checks that its metadata poolId matches the expected pool. * If the block has no poolId metadata, it passes through (backward compatible). * * @param source - The original block source callback * @param poolId - The expected pool for all blocks * @param blockType - Human-readable block type name for error messages * @returns A wrapped callback that validates pool membership * * @see Requirements 3.1, 3.2, 3.4, 3.5 */ private wrapWithPoolValidation; /** * Convert data to Uint8Array regardless of whether it's a Readable or Uint8Array */ private toUint8Array; /** * XOR a source block with whitening and random blocks * * @param sourceBlock The source block to XOR (any block type or block handle) * @param whiteners The whitening blocks to XOR with * @param randomBlocks The random blocks to XOR with * @returns A whitened block containing the XOR result * @throws {TupleError} If validation fails or XOR operation fails */ xorSourceToPrimeWhitened(sourceBlock: IBaseBlock | BlockHandle, whiteners: (WhitenedBlock | RandomBlock)[], randomBlocks: RandomBlock[]): Promise; /** * Create a tuple from a source block and its whitening/random blocks */ makeTupleFromSourceXor(sourceBlock: IBaseBlock | BlockHandle, whiteners: (WhitenedBlock | RandomBlock)[], randomBlocks: RandomBlock[]): Promise>; /** * XOR a whitened block with its whitening blocks to recover the original data * @param creator The member who created the block * @param primeWhitenedBlock The whitened block to recover * @param whiteners The whitening blocks used in the original XOR * @param randomBlocks Optional random blocks used in the original XOR * @returns An ephemeral block containing the recovered data * @throws {TupleError} If validation fails or XOR operation fails */ xorDestPrimeWhitenedToOwned(creator: Member, primeWhitenedBlock: WhitenedBlock, whiteners: WhitenedBlock[], randomBlocks?: RandomBlock[]): Promise>; /** * Create a tuple from a whitened block and its whitening blocks */ makeTupleFromDestXor(creator: Member, primeWhitenedBlock: WhitenedBlock, whiteners: WhitenedBlock[]): Promise; /** * XOR a whitened block with its whitening blocks to recover a CBL */ xorPrimeWhitenedToCbl(creator: Member, primeWhitened: WhitenedBlock, whiteners: WhitenedBlock[]): Promise; /** * XOR an encrypted whitened block with its whitening blocks and decrypt to recover a CBL */ xorPrimeWhitenedEncryptedToCbl(creator: Member, primeWhitened: WhitenedBlock, whiteners: WhitenedBlock[]): Promise>; /** * Process a data stream into tuples and create a CBL * @param creator The member creating the CBL * @param blockSize The block size to use * @param source The source data stream * @param sourceLength The length of the source data * @param whitenedBlockSource Function to get whitened blocks * @param randomBlockSource Function to get random blocks * @param persistTuple Function to persist each tuple * @returns A tuple containing the CBL * @throws {TupleError} If validation fails or processing fails */ dataStreamToPlaintextTuplesAndCBL(creator: Member, blockSize: BlockSize, source: Readable, sourceLength: number, whitenedBlockSource: () => WhitenedBlock | undefined, randomBlockSource: () => RandomBlock, persistTuple: (tuple: InMemoryBlockTuple) => Promise, poolOptions?: TuplePoolOptions): Promise; /** * Process a data stream into encrypted tuples and create an encrypted CBL * @param creator The member creating the CBL * @param blockSize The block size to use * @param source The source data stream * @param sourceLength The length of the source data * @param whitenedBlockSource Function to get whitened blocks * @param randomBlockSource Function to get random blocks * @param persistTuple Function to persist each tuple * @returns A tuple containing the encrypted CBL * @throws {TupleError} If validation fails or processing fails */ dataStreamToEncryptedTuplesAndCBL(creator: Member, blockSize: BlockSize, source: Readable, sourceLength: number, whitenedBlockSource: () => WhitenedBlock | undefined, randomBlockSource: () => RandomBlock, persistTuple: (tuple: InMemoryBlockTuple) => Promise, poolOptions?: TuplePoolOptions): Promise; /** * Get the number of random blocks needed for a tuple * @param dataLength - The length of the data * @returns The number of random blocks needed * Process a data stream into encrypted tuples and create an encrypted CBL */ getRandomBlockCount(dataLength: number): number; } //# sourceMappingURL=tuple.service.d.ts.map