mirror of
https://gitgud.io/fatchan/haproxy-protection.git
synced 2025-05-09 02:05:37 +00:00
- 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
23 lines
659 B
JavaScript
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;
|
|
}
|
|
}
|