import { BlobRefMetadata, BlobRef } from '@korajs/core'; /** * Thrown when a blob read fails its integrity check: the bytes stored under a * hash do not actually hash to that value (corruption or tampering). */ declare class BlobIntegrityError extends Error { readonly expectedHash: string; readonly actualHash: string; constructor(expectedHash: string, actualHash: string); } /** * A content-addressed store for the bytes behind `blob` fields. * * Blobs are keyed by the SHA-256 hash of their content, so identical content is * stored exactly once (deduplication) and a peer never needs to transfer bytes * it already holds. Reads are integrity-checked: the returned bytes are verified * to hash to the requested key. */ interface ContentAddressedBlobStore { /** * Whether stored blobs survive a reload of the page or restart of the process (OPFS and * filesystem stores: true; the in-memory store: false). Offline readiness reads it: a pin * that keeps files is not `ready` on a store that forgets them (`storage-non-durable`). * Optional so a custom store written before this field existed still compiles; a store that * does not say (or cannot vouch for its bytes) is treated as not durable, so declare * `readonly durable = true` on a store whose bytes survive a restart. */ readonly durable?: boolean; /** * Store bytes and return their content-addressed reference. Storing content * that already exists is a no-op that returns the same reference (dedup). */ put(bytes: Uint8Array, metadata?: BlobRefMetadata): Promise; /** * Retrieve the bytes for a hash, or null if absent. The returned bytes are * verified to hash to the requested value; a mismatch throws * {@link BlobIntegrityError} rather than returning corrupt data. */ get(hash: string): Promise; /** Whether the store holds content for the given hash. */ has(hash: string): Promise; /** Remove the content for a hash. Returns whether anything was removed. */ delete(hash: string): Promise; /** Number of distinct blobs held. */ size(): Promise; /** * List the hashes of every blob currently held. Used by garbage collection to * find content no live reference points to. Order is unspecified. */ list(): Promise; } /** * In-memory {@link ContentAddressedBlobStore}. The reference backend used for * tests and for environments without a persistent blob backend yet. Persistent * backends (OPFS client-side, filesystem/S3 server-side) implement the same * interface. */ declare class MemoryBlobStore implements ContentAddressedBlobStore { readonly durable = false; private readonly blobs; put(bytes: Uint8Array, metadata?: BlobRefMetadata): Promise; get(hash: string): Promise; has(hash: string): Promise; delete(hash: string): Promise; size(): Promise; list(): Promise; } export { BlobIntegrityError as B, type ContentAddressedBlobStore as C, MemoryBlobStore as M };