diff --git a/cjs/dist/worker.js b/cjs/dist/worker.js index b6715b3..c3fd6b9 100644 --- a/cjs/dist/worker.js +++ b/cjs/dist/worker.js @@ -9,8 +9,8 @@ onmessage = async (message) => { controller = undefined; } else if (type === 'work') { - const { alg, challenge, max, salt, start } = payload || {}; - const result = (0, index_js_1.solveChallenge)(challenge, salt, alg, max, start); + const { algorithm, challenge, max, salt, start } = payload || {}; + const result = (0, index_js_1.solveChallenge)(challenge, salt, algorithm, max, start); controller = result.controller; result.promise.then((solution) => { self.postMessage(solution ? { ...solution, worker: true } : solution); diff --git a/deno_dist/worker.ts b/deno_dist/worker.ts index 043be7e..d03e6dc 100644 --- a/deno_dist/worker.ts +++ b/deno_dist/worker.ts @@ -8,8 +8,8 @@ onmessage = async (message) => { controller?.abort(); controller = undefined; } else if (type === 'work') { - const { alg, challenge, max, salt, start } = payload || {}; - const result = solveChallenge(challenge, salt, alg, max, start); + const { algorithm, challenge, max, salt, start } = payload || {}; + const result = solveChallenge(challenge, salt, algorithm, max, start); controller = result.controller; result.promise.then((solution) => { self.postMessage(solution ? { ...solution, worker: true } : solution); diff --git a/dist/worker.js b/dist/worker.js index 72124ae..da2d679 100644 --- a/dist/worker.js +++ b/dist/worker.js @@ -7,8 +7,8 @@ onmessage = async (message) => { controller = undefined; } else if (type === 'work') { - const { alg, challenge, max, salt, start } = payload || {}; - const result = solveChallenge(challenge, salt, alg, max, start); + const { algorithm, challenge, max, salt, start } = payload || {}; + const result = solveChallenge(challenge, salt, algorithm, max, start); controller = result.controller; result.promise.then((solution) => { self.postMessage(solution ? { ...solution, worker: true } : solution); diff --git a/lib/worker.ts b/lib/worker.ts index 0e01325..08b272f 100644 --- a/lib/worker.ts +++ b/lib/worker.ts @@ -8,8 +8,8 @@ onmessage = async (message) => { controller?.abort(); controller = undefined; } else if (type === 'work') { - const { alg, challenge, max, salt, start } = payload || {}; - const result = solveChallenge(challenge, salt, alg, max, start); + const { algorithm, challenge, max, salt, start } = payload || {}; + const result = solveChallenge(challenge, salt, algorithm, max, start); controller = result.controller; result.promise.then((solution) => { self.postMessage(solution ? { ...solution, worker: true } : solution); diff --git a/tests/challenge.test.ts b/tests/challenge.test.ts index 54c3a67..9ca8cb1 100644 --- a/tests/challenge.test.ts +++ b/tests/challenge.test.ts @@ -11,7 +11,7 @@ import { Challenge } from '../lib/types.js'; import { hash, hmacHex } from '../lib/helpers.js'; if (!('crypto' in globalThis)) { - // eslint-disable-next-line @typescript-eslint/no-var-requires + // eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports globalThis.crypto = require('node:crypto').webcrypto; } @@ -404,6 +404,22 @@ describe('challenge', () => { const result = await promise; expect(result?.number).toEqual(number); }); + + it('should solve challenge with non-default algorithm (SHA-512)', async () => { + const number = 100; + const challenge = await createChallenge({ + algorithm: 'SHA-512', + number, + hmacKey, + }); + const { promise } = solveChallenge( + challenge.challenge, + challenge.salt, + challenge.algorithm + ); + const result = await promise; + expect(result?.number).toEqual(number); + }); }); describe.skipIf(!('Worker' in globalThis))('solveChallengeWorkers', () => { @@ -425,5 +441,25 @@ describe('challenge', () => { ); expect(result?.number).toEqual(number); }); + + it('should solve challenge using workers with non-default algorithm (SHA-512)', async () => { + const number = 100; + const challenge = await createChallenge({ + algorithm: 'SHA-512', + number, + hmacKey, + }); + const result = await solveChallengeWorkers( + () => + new Worker('./lib/worker.ts', { + type: 'module', + }), + 4, + challenge.challenge, + challenge.salt, + challenge.algorithm + ); + expect(result?.number).toEqual(number); + }); }); });