or run

npx @tessl/cli init
Log in

Version

Files

docs

index-management.mdindex.mdlisting.mdreading.mdremoval.mdutilities.mdverification.mdwriting.md
tile.json

task.mdevals/scenario-8/

Verified Cache Integrity

Implement a tiny cache helper that writes and reads content while enforcing integrity digests, size limits, and allowed hashing algorithms. The helper must make it easy to reject corrupted data, reuse external hashing efforts, and confirm the algorithm that validated the content.

Capabilities

Writes reject bad integrity

  • Writing content with an expected digest rejects when bytes do not match and surfaces an integrity error. @test
  • When provided an integrity-aware emitter that already tracked the incoming bytes, writing returns the digest from that emitter without rehashing. @test

Reads enforce size and algorithms

  • Reading a stored item with a declared size mismatch throws a size error before returning data. @test
  • Reading with an allowed algorithms list accepts a cached variant that matches one of those algorithms and reports which digest was used. @test

Implementation

@generates

API

export interface CacheConfig {
  cachePath: string;
  algorithms?: string[];
}

export interface WriteOptions {
  expectedIntegrity?: string;
  size?: number;
  integrityEmitter?: import('events').EventEmitter;
}

export interface ReadOptions {
  expectedIntegrity?: string;
  size?: number;
  algorithms?: string[];
}

export interface CacheClient {
  write(key: string, data: Buffer | string, opts?: WriteOptions): Promise<{ integrity: string; size: number }>;
  read(key: string, opts?: ReadOptions): Promise<{ data: Buffer; integrity: string; size: number; algorithm: string }>;
}

export function createCacheClient(config: CacheConfig): CacheClient;

Dependencies { .dependencies }

cacache { .dependency }

Content-addressable cache with integrity and size enforcement features.