Files
haproxy-protection/haproxy/js/worker.js
Thomas Lynch 598790cb4f - Fix some docker-compose issues close #14
- Move to new scheme with some hashing, sigs, and a random user key. close #13
- Change to sha256 rather than sha1 (temporary, but i guess its slightly more secure which is nice for now) ref #10
- Change POW output checked value
- Add lib for randombytes, udpate lua sha lib
- Remove outdated difficulty checks in frontend (was hardcoded 0 anyway) and since algo change is coming soon, there is no need to keep it
2022-09-17 02:45:27 +10:00

23 lines
659 B
JavaScript

async function hash(data, method) {
const buffer = new TextEncoder('utf-8').encode(data);
const hashBuffer = await crypto.subtle.digest(method, buffer)
return Array.from(new Uint8Array(hashBuffer));
}
onmessage = async function(e) {
const [challenge, id, threads] = e.data;
console.log('Worker thread', id,'got challenge', challenge);
let i = id;
let challengeIndex = parseInt(challenge[0], 16);
while(true) {
let result = await hash(challenge+i, 'sha-256');
if(result[challengeIndex] === 0x00
&& result[challengeIndex+1] === 0x41){
console.log('Worker thread found solution:', i);
postMessage([id, i]);
break;
}
i+=threads;
}
}