MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / deriveCacheDigest

Function deriveCacheDigest

src/api/providers/fetchers/modelCache.ts:99–106  ·  view source on GitHub ↗

* Derive a short, irreversible, truncated digest of a cache input. * * The output is deliberately far smaller than the entropy of a real API key: collisions * across the handful of keys/servers a single user configures are negligible (birthday bound * ~ n^2 / 2^(8*bytes)), while the truncated ou

(value: string, bytes: number)

Source from the content-addressed store, hash-verified

97 * cache filename cannot be reversed to identify the API key it was derived from.
98 */
99function deriveCacheDigest(value: string, bytes: number): string {
100 const memoKey = `${bytes}:${value}`
101 const cached = cacheDigestCache.get(memoKey)
102 if (cached) return cached
103 const digest = pbkdf2Sync(value, CACHE_DIGEST_SALT, CACHE_DIGEST_ITERATIONS, bytes, "sha256").toString("hex")
104 cacheDigestCache.set(memoKey, digest)
105 return digest
106}
107
108// 4 bytes (8 hex chars) = 32 bits for the per-API-key discriminator embedded in the cache key.
109const API_KEY_DISCRIMINATOR_BYTES = 4

Callers 2

cacheKeyToFilenameFunction · 0.85

Calls 3

getMethod · 0.65
toStringMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected