- 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
This commit is contained in:
Thomas Lynch
2022-09-16 21:50:22 +10:00
parent 7dbc14feb3
commit 598790cb4f
12 changed files with 3323 additions and 443 deletions

View File

@ -5,19 +5,14 @@ async function hash(data, method) {
}
onmessage = async function(e) {
const [challenge, difficulty, id, threads] = e.data;
console.log('Worker thread', id,'got challenge', challenge, 'with difficulty', difficulty);
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-1');
let middle = true;
for(let imiddle = 1; imiddle <= difficulty; imiddle++) {
middle = (middle && (result[challengeIndex+imiddle] === 0x00));
}
if(result[challengeIndex] === 0xb0
&& middle === true
&& result[challengeIndex+difficulty+1] === 0x0b){
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;