import { createHash } from "node:crypto"; import { createReadStream } from "node:fs"; import type { EmbedderConfig } from "./config"; export async function computeFingerprint( config: EmbedderConfig, runtimeBinary: string, modelFile: string, ): Promise { const hasher = createHash("sha256"); hasher.update(JSON.stringify(fingerprintConfig(config))); hasher.update(await sha256File(runtimeBinary)); hasher.update(await sha256File(modelFile)); return hasher.digest("hex"); } function fingerprintConfig(config: EmbedderConfig): Omit { const { vulkanDevice: _ignored, ...stableConfig } = config; return stableConfig; } async function sha256File(path: string): Promise { const hasher = createHash("sha256"); const stream = createReadStream(path); for await (const chunk of stream) { hasher.update(chunk); } return hasher.digest("hex"); }