From: Chris Duncan Date: Mon, 22 Jun 2026 22:18:49 +0000 (-0700) Subject: Use generic strict equality hash comparison on cache functions to allow string or... X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=007ebe9e4c022008562c11f951b693cd5e6f8a90;p=nano-pow.git Use generic strict equality hash comparison on cache functions to allow string or bigint comparisons. --- diff --git a/src/utils/cache.ts b/src/utils/cache.ts index 0d3b643..0490a6a 100644 --- a/src/utils/cache.ts +++ b/src/utils/cache.ts @@ -28,22 +28,22 @@ export const Cache = { clear (): void { storage.removeItem(STORAGE_KEY) }, - delete (hash: bigint): void { + delete (hash: unknown): void { const item = storage.getItem(STORAGE_KEY) if (item == null) return const cache = JSON.parse(item) as WorkGenerateResponse[] for (let i = 0; i < cache.length; i++) { - if (eq(cache[i].hash, hash)) { + if (cache[i].hash === hash) { cache.splice(i, 1) } } storage.setItem(STORAGE_KEY, JSON.stringify(cache)) }, - search (hash: bigint, difficulty: bigint): WorkGenerateResponse | null { + search (hash: unknown, difficulty: bigint): WorkGenerateResponse | null { const item = storage.getItem(STORAGE_KEY) if (item == null) return null const cache: WorkGenerateResponse[] = JSON.parse(item) - const match = cache.find(c => eq(c.hash, hash) && eq(c.difficulty, difficulty)) + const match = cache.find(c => c.hash === hash && eq(c.difficulty, difficulty)) return match ?? null }, store (result: WorkGenerateResponse): WorkGenerateResponse {