import { ECIESService, Member, PlatformID, SignatureUint8Array, TypedIdProviderWrapper } from '@digitaldefiance/ecies-lib'; import { BlockEncryptionType } from '../enumerations/blockEncryptionType'; import { BlockSize } from '../enumerations/blockSize'; import { MessageEncryptionScheme } from '../enumerations/messaging/messageEncryptionScheme'; import { MessagePriority } from '../enumerations/messaging/messagePriority'; import { IBlockCapacityCalculator } from '../interfaces/blockCapacity'; import { IConstituentBlockListBlockHeader } from '../interfaces/blocks/headers/cblHeader'; import { IExtendedConstituentBlockListBlockHeader } from '../interfaces/blocks/headers/ecblHeader'; import { IMessageConstituentBlockListBlockHeader } from '../interfaces/blocks/headers/messageCblHeader'; import { ISuperConstituentBlockListBlockHeader } from '../interfaces/blocks/headers/superCblHeader'; import { Checksum } from '../types/checksum'; import { ChecksumService } from './checksum.service'; /** * Service for creating and verifying CBL blocks. * * This service provides functionality for: * - Creating CBL headers with proper validation * - Parsing CBL headers from data * - Validating file names and MIME types * - Calculating CBL address capacity * * @remarks * - All methods validate inputs before processing * - Errors are wrapped in CblError or ExtendedCblError with appropriate context * - The service supports both standard and extended CBL blocks * * @see Requirements 5.1, 5.2, 5.3, 12.1, 12.2, 12.7 */ export declare class CBLService { private readonly checksumService; private readonly eciesService; private readonly enhancedProvider; /** * Get the enhanced ID provider for this service */ get idProvider(): TypedIdProviderWrapper; constructor(checksumService: ChecksumService, eciesService: ECIESService, enhancedProvider: TypedIdProviderWrapper); /** Create safe buffers for common operations */ private createArrays; /** * Length of the structured block header prefix (magic, type, version, CRC8) */ static readonly StructuredPrefixSize: number; /** * Length of the creator field in the header (dynamic based on provider) */ get creatorLength(): number; /** * Length of the date field in the header * Date consists of two 32-bit unsigned integers (high/low) */ static readonly DateSize: number; /** * Length of the address count field in the header */ static readonly AddressCountSize: number; /** * Length of the tuple size field in the header */ static readonly TupleSizeSize: number; /** * Length of the original data length field in the header */ static readonly DataLengthSize: number; /** * Length of the data checksum field in the header */ static readonly DataChecksumSize: number; /** * Length of the is extended header field in the header */ static readonly IsExtendedHeaderSize: number; /** * Length of the creator signature field in the header */ static readonly CreatorSignatureSize: number; /** * Length of the creator ID field (GUID size) - static default for backward compatibility * @deprecated Use instance method creatorLength instead for dynamic provider support */ static readonly CreatorIdLength: number; /** * Offset of the creator ID field in the header (after structured prefix) */ get creatorIdOffset(): number; /** * Offset of the date field in the header (instance method for dynamic provider support) */ get dateCreatedOffset(): number; /** * Offset of the date field in the header (static for backward compatibility) * @deprecated Use instance method dateCreatedOffset instead */ static get DateCreatedOffset(): number; /** * Offset of the address count field in the header (instance method) */ get cblAddressCountOffset(): number; /** * Offset of the address count field in the header (static for backward compatibility) * @deprecated Use instance method cblAddressCountOffset instead */ static get CblAddressCountOffset(): number; /** * Offset of the tuple size field in the header (instance method) */ get tupleSizeOffset(): number; /** * Offset of the tuple size field in the header (static for backward compatibility) * @deprecated Use instance method tupleSizeOffset instead */ static get TupleSizeOffset(): number; /** * Offset of the original data length field in the header (instance method) */ get originalDataLengthOffset(): number; /** * Offset of the original data length field in the header (static for backward compatibility) * @deprecated Use instance method originalDataLengthOffset instead */ static get OriginalDataLengthOffset(): number; /** * Offset of the original checksum field in the header (instance method) */ get originalChecksumOffset(): number; /** * Static offset for backward compatibility * @deprecated Use instance method originalChecksumOffset instead */ static get OriginalChecksumOffset(): number; /** * Offset of the is extended header field in the header (instance method) */ get isExtendedHeaderOffset(): number; /** * Offset of the is extended header field in the header (static for backward compatibility) * @deprecated Use instance method isExtendedHeaderOffset instead */ static get IsExtendedHeaderOffset(): number; /** * Offset of the creator signature field in the header (instance method) */ get baseHeaderCreatorSignatureOffset(): number; /** * Offset of the creator signature field in the header (static for backward compatibility) * @deprecated Use instance method baseHeaderCreatorSignatureOffset instead */ static get BaseHeaderCreatorSignatureOffset(): number; /** * Length of the base header with signature (instance method) */ get baseHeaderSize(): number; /** * Length of the base header with signature (static for backward compatibility) * @deprecated Use instance method baseHeaderSize instead */ static get BaseHeaderSize(): number; /** * Offset of the file name length field in the header (instance method) */ get fileNameLengthOffset(): number; /** * Offset of the file name length field in the header (static for backward compatibility) * @deprecated Use instance method fileNameLengthOffset instead */ static get FileNameLengthOffset(): number; /** * Length of the file name length field in the header */ static readonly FileNameLengthSize: number; /** * Length of the mime type length field in the header */ static readonly MimeTypeLengthSize: number; /** * Length of the sub-CBL count field in SuperCBL header */ static readonly SuperCblSubCblCountSize: number; /** * Length of the total block count field in SuperCBL header */ static readonly SuperCblTotalBlockCountSize: number; /** * Length of the depth field in SuperCBL header */ static readonly SuperCblDepthSize: number; /** * Offset of the sub-CBL count field in SuperCBL header (after date) */ get superCblSubCblCountOffset(): number; /** * Offset of the total block count field in SuperCBL header */ get superCblTotalBlockCountOffset(): number; /** * Offset of the depth field in SuperCBL header */ get superCblDepthOffset(): number; /** * Offset of the original data length field in SuperCBL header */ get superCblOriginalDataLengthOffset(): number; /** * Offset of the original checksum field in SuperCBL header */ get superCblOriginalChecksumOffset(): number; /** * Offset of the creator signature field in SuperCBL header */ get superCblCreatorSignatureOffset(): number; /** * Length of the SuperCBL header (without address data) */ get superCblHeaderSize(): number; /** * Get SuperCBL header offsets */ get superCblHeaderOffsets(): { StructuredPrefix: number; CreatorId: number; DateCreated: number; SubCblCount: number; TotalBlockCount: number; Depth: number; OriginalDataLength: number; OriginalDataChecksum: number; CreatorSignature: number; }; /** * Instance offsets for dynamic provider support */ get headerOffsets(): { StructuredPrefix: number; CreatorId: number; DateCreated: number; CblAddressCount: number; TupleSize: number; OriginalDataLength: number; OriginalDataChecksum: number; CreatorSignature: number; IsExtendedHeader: number; FileNameLength: number; }; /** * Static offsets for backward compatibility * @deprecated Use instance method headerOffsets instead */ static get HeaderOffsets(): { StructuredPrefix: number; CreatorId: number; DateCreated: number; CblAddressCount: number; TupleSize: number; OriginalDataLength: number; OriginalDataChecksum: number; CreatorSignature: number; IsExtendedHeader: number; FileNameLength: number; }; /** * Check if the data is encrypted * @param data The data to check * @returns True if the data is encrypted, false otherwise */ isEncrypted(data: Uint8Array): boolean; /** * Check if the header is a message CBL */ isMessageHeader(header: Uint8Array): boolean; /** * Get message header offsets */ private getMessageHeaderOffsets; /** * Helper function to check if a string contains control characters * @param str The string to check * @returns True if the string contains control characters, false otherwise */ hasControlChars(str: string): boolean; /** * Get the creator ID from the header */ getCreatorId(header: Uint8Array): TID; /** * Get the date created from the header */ getDateCreated(header: Uint8Array): Date; /** * Get the Cbl address count from the header */ getCblAddressCount(header: Uint8Array): number; /** * Get the tuple size from the header */ getTupleSize(header: Uint8Array): number; /** * Get the original data length from the header */ getOriginalDataLength(header: Uint8Array): number; /** * Get the original data checksum from the header * @param header - The header to get the checksum from * @returns The original data checksum */ getOriginalDataChecksum(header: Uint8Array): Checksum; /** * Get the is extended header from the header */ isExtendedHeader(header: Uint8Array): boolean; /** * Get cached extended header information */ private getExtendedHeaderOffsets; /** * Get the length of the file name from the header */ getFileNameLength(header: Uint8Array): number; /** * Get the file name from the header */ getFileName(header: Uint8Array): string; /** * Get the length of the mime type from the header */ getMimeTypeLength(header: Uint8Array): number; /** * Get the mime type from the header */ getMimeType(header: Uint8Array): string; /** * Get the creator signature from the header */ getSignature(header: Uint8Array): SignatureUint8Array; /** * Get the length of the header */ getHeaderLength(data: Uint8Array): number; /** * Get the length of the block without padding */ getBlockDataLength(data: Uint8Array): number; /** * Get the address data from the CBL */ getAddressData(data: Uint8Array): Uint8Array; /** * Get the addresses from the CBL */ addressDataToAddresses(data: Uint8Array): Checksum[]; /** * Validate the signature of a CBL * @param data The CBL data * @param creator The creator of the CBL * @param blockSize The block size to use for validation (optional, defaults to calculated from data length) * @returns True if the signature is valid, false otherwise */ validateSignature(data: Uint8Array, creator: Member, blockSize?: BlockSize): boolean; /** * Validate the file name format * @param fileName - The file name to validate * @throws ExtendedCblError if the file name is invalid */ validateFileNameFormat(fileName: string): void; /** * Validates the format of a MIME type. */ validateMimeTypeFormat(mimeType: string): void; /** * Calculates the size of the extended header for CBL, given the file name and MIME type. * @param fileName File name * @param mimeType Mime type * @returns Size of the extended header */ calculateExtendedHeaderSize(fileName: string, mimeType: string): number; /** * Create message CBL header extension */ makeMessageHeader(messageType: string, senderId: string, recipients: string[], priority: MessagePriority, encryptionScheme: MessageEncryptionScheme): Uint8Array; /** * Create an extended header for CBL * @param lax - If true, skip file name validation (for special cases like VCBL) */ makeExtendedHeader(fileName: string, mimeType: string, lax?: boolean): Uint8Array; /** * Parse message CBL header */ parseMessageHeader(data: Uint8Array, creatorForValidation?: Member): IMessageConstituentBlockListBlockHeader; /** * Create a CBL header. * * @param creator - The member creating the CBL * @param dateCreated - The creation date * @param cblAddressCount - Number of addresses in the CBL * @param fileDataLength - Length of the original file data * @param addressList - The list of block addresses * @param blockSize - The block size * @param encryptionType - The encryption type * @param extendedCBL - Optional extended CBL data (fileName, mimeType) * @param tupleSize - The tuple size (defaults to TUPLE.SIZE) * @param lax - If true, skip file name validation (for special cases like VCBL) * @returns Object containing headerData and signature * @throws {EnhancedValidationError} If block size or encryption type is invalid * @throws {CblError} If CBL-specific validation fails * * @see Requirements 5.1, 5.2, 5.3, 12.1, 12.2, 12.7, 9.1, 9.2, 9.4, 9.5, 10.1, 10.2, 12.4 */ makeCblHeader(creator: Member, dateCreated: Date, cblAddressCount: number, fileDataLength: number, addressList: Uint8Array, blockSize: BlockSize, encryptionType: BlockEncryptionType, extendedCBL?: { fileName: string; mimeType: string; }, tupleSize?: number, lax?: boolean): { headerData: Uint8Array; signature: SignatureUint8Array; }; /** * Parse the header of a constituent block list block * @param data The data to parse * @param creatorForValidation The creator of the block for validation * @returns The parsed header */ parseBaseHeader(data: Uint8Array, creatorForValidation?: Member): IConstituentBlockListBlockHeader; /** * Parse the header from the data * @param data The data to parse * @param creatorForValidation The creator to validate against * @returns The parsed header */ parseExtendedHeader(data: Uint8Array, creatorForValidation?: Member): IExtendedConstituentBlockListBlockHeader; /** * Parse the header from the data * @param data The data to parse * @param creatorForValidation The creator to validate against * @returns The parsed header */ parseHeader(data: Uint8Array, creatorForValidation?: Member): IConstituentBlockListBlockHeader | IExtendedConstituentBlockListBlockHeader; /** * Calculate the capacity of a CBL address block in terms of the number of addresses it can hold. * @param blockSiz The block size * @param allowEncryption Whether encryption is allowed * @param fileName The file name * @param mimeType The mime type * @returns number of addresses that can fit in the block */ calculateCBLAddressCapacity(blockSize: BlockSize, encryptedBlockType: BlockEncryptionType, cbl?: { fileName: string; mimeType: string; }, blockCapacityCalculator?: IBlockCapacityCalculator): number; /** * Check if the data is a SuperCBL * @param data The data to check * @returns True if the data is a SuperCBL, false otherwise */ isSuperCbl(data: Uint8Array): boolean; /** * Get the sub-CBL count from a SuperCBL header * @param header The SuperCBL header data * @returns The number of sub-CBL references */ getSuperCblSubCblCount(header: Uint8Array): number; /** * Get the total block count from a SuperCBL header * @param header The SuperCBL header data * @returns The total number of blocks across all sub-CBLs */ getSuperCblTotalBlockCount(header: Uint8Array): number; /** * Get the depth from a SuperCBL header * @param header The SuperCBL header data * @returns The hierarchy depth */ getSuperCblDepth(header: Uint8Array): number; /** * Get the original data length from a SuperCBL header * @param header The SuperCBL header data * @returns The original file size */ getSuperCblOriginalDataLength(header: Uint8Array): number; /** * Get the original data checksum from a SuperCBL header * @param header The SuperCBL header data * @returns The SHA3-512 checksum of the original data */ getSuperCblOriginalDataChecksum(header: Uint8Array): Checksum; /** * Get the creator signature from a SuperCBL header * @param header The SuperCBL header data * @returns The ECDSA signature */ getSuperCblSignature(header: Uint8Array): SignatureUint8Array; /** * Get the sub-CBL checksums from a SuperCBL * @param data The SuperCBL data (header + address data) * @returns Array of sub-CBL checksums */ getSuperCblSubCblChecksums(data: Uint8Array): Checksum[]; /** * Create a SuperCBL header. * * @param creator - The member creating the SuperCBL * @param dateCreated - The creation date * @param subCblCount - Number of sub-CBL references * @param totalBlockCount - Total blocks across all sub-CBLs * @param depth - Hierarchy depth * @param originalDataLength - Original file size * @param originalDataChecksum - SHA3-512 checksum of original data * @param subCblChecksums - Array of sub-CBL checksums * @param blockSize - The block size * @returns Object containing headerData and signature * @throws {CblError} If validation fails * * @see Requirements 11.1, 11.2, 11.3, 11.4, 11.5 */ makeSuperCblHeader(creator: Member, dateCreated: Date, subCblCount: number, totalBlockCount: number, depth: number, originalDataLength: number, originalDataChecksum: Checksum, subCblChecksums: Checksum[], blockSize: BlockSize): { headerData: Uint8Array; signature: SignatureUint8Array; }; /** * Validate the signature of a SuperCBL. * * @param data - The SuperCBL data (header + address data) * @param creator - The creator of the SuperCBL * @param blockSize - The block size (optional, defaults to calculated from data length) * @returns True if the signature is valid, false otherwise * @throws {CblError} If the data is encrypted or not a SuperCBL * * @see Requirements 11.4, 11.6 */ validateSuperCblSignature(data: Uint8Array, creator: Member, blockSize?: BlockSize): boolean; /** * Parse a SuperCBL header from data. * * @param data - The SuperCBL data (header + address data) * @param creatorForValidation - Optional creator to validate signature against * @param blockSize - Optional block size for signature validation (required if validating signature) * @returns The parsed SuperCBL header * @throws {CblError} If the data is encrypted, not a SuperCBL, or validation fails * * @see Requirements 11.1, 11.2 */ parseSuperCblHeader(data: Uint8Array, creatorForValidation?: Member, blockSize?: BlockSize): ISuperConstituentBlockListBlockHeader; } //# sourceMappingURL=cblService.d.ts.map