Files
altcha-lib/cjs/dist/worker.js
Daniel Regeci 281380aaf4 0.1.3
2024-04-05 21:27:24 -03:00

20 lines
696 B
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const index_js_1 = require("./index.js");
let controller = undefined;
onmessage = async (message) => {
const { type, payload } = message.data;
if (type === 'abort') {
controller?.abort();
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);
controller = result.controller;
result.promise.then((solution) => {
self.postMessage(solution ? { ...solution, worker: true } : solution);
});
}
};