import { argon2id } from 'hash-wasm'; import type { HashParams } from '@akrababul/shared'; export type WorkerRequest = { id: number; keyText: string; salt: string; params: HashParams }; export type WorkerResponse = { id: number; hash: string } | { id: number; error: string }; // tsconfig DOM lib'i ile çakışmamak için WebWorker lib'i eklenmez; worker kapsamı dar tiplenir. const ctx = self as unknown as { onmessage: ((e: MessageEvent) => void) | null; postMessage(m: WorkerResponse): void }; const enc = new TextEncoder(); ctx.onmessage = async (e: MessageEvent) => { const { id, keyText, salt, params } = e.data; try { const hash = await argon2id({ password: keyText, salt: enc.encode(salt), memorySize: params.memorySize, iterations: params.iterations, parallelism: params.parallelism, hashLength: params.hashLength, outputType: 'hex', }); ctx.postMessage({ id, hash: hash as string }); } catch (err) { ctx.postMessage({ id, error: err instanceof Error ? err.message : String(err) }); } };