From d4b4bf7b66f388cc2732a13c92d8528bdb3b511d Mon Sep 17 00:00:00 2001 From: forest Date: Thu, 25 Feb 2021 03:44:06 -0600 Subject: [PATCH] stpid eclipse ignoring delete side of moved files bug --- static/proofOfWorkerStub.js | 143 ------------------------------------ 1 file changed, 143 deletions(-) delete mode 100644 static/proofOfWorkerStub.js diff --git a/static/proofOfWorkerStub.js b/static/proofOfWorkerStub.js deleted file mode 100644 index a85748a..0000000 --- a/static/proofOfWorkerStub.js +++ /dev/null @@ -1,143 +0,0 @@ - -// IN ORDER FOR CHANGES TO THIS FILE TO "TAKE" AND BE USED IN THE APP, THE BUILD IN wasm_build HAS TO BE RE-RUN - -// scrypt and scryptPromise will be filled out by js code that gets appended below this script by the wasm_build process -let scrypt; -let scryptPromise; - -let working = false; -const batchSize = 8; - -onmessage = function(e) { - if(e.data.stop) { - working = false; - return; - } - - const challengeBase64 = e.data.challenge; - const workerId = e.data.workerId; - if(!challengeBase64) { - postMessage({ - type: "error", - challenge: challengeBase64, - message: `challenge was not provided` - }); - } - working = true; - let challengeJSON = null; - let challenge = null; - try { - challengeJSON = atob(challengeBase64); - } catch (err) { - postMessage({ - type: "error", - challenge: challengeBase64, - message: `couldn't decode challenge '${challengeBase64}' as base64: ${err}` - }); - } - try { - challenge = JSON.parse(challengeJSON); - } catch (err) { - postMessage({ - type: "error", - challenge: challengeBase64, - message: `couldn't parse challenge '${challengeJSON}' as json: ${err}` - }); - } - - challenge = { - cpuAndMemoryCost: challenge.N, - blockSize: challenge.r, - paralellization: challenge.p, - keyLength: challenge.klen, - preimage: challenge.i, - difficulty: challenge.d, - difficultyLevel: challenge.dl - } - - const probabilityOfFailurePerAttempt = 1-(1/Math.pow(2, challenge.difficultyLevel)); - - let i = workerId * Math.pow(2, challenge.difficulty.length) * 100; - const hexPreimage = base64ToHex(challenge.preimage); - let smallestHash = challenge.difficulty.split("").map(x => "f").join(""); - - postMessage({ - type: "progress", - challenge: challengeBase64, - attempts: 0, - smallestHash: smallestHash, - difficulty: challenge.difficulty, - probabilityOfFailurePerAttempt: probabilityOfFailurePerAttempt - }); - - const doWork = () => { - - var j = 0; - while(j < batchSize) { - j++; - i++; - - let nonceHex = i.toString(16); - if((nonceHex.length % 2) == 1) { - nonceHex = `0${nonceHex}`; - } - const hashHex = scrypt( - nonceHex, - hexPreimage, - challenge.cpuAndMemoryCost, - challenge.blockSize, - challenge.paralellization, - challenge.keyLength - ); - - //console.log(i.toString(16), hashHex); - - const endOfHash = hashHex.substring(hashHex.length-challenge.difficulty.length); - if(endOfHash < smallestHash) { - smallestHash = endOfHash - } - if(endOfHash <= challenge.difficulty) { - postMessage({ - type: "success", - challenge: challengeBase64, - nonce: i.toString(16), - smallestHash: endOfHash, - difficulty: challenge.difficulty - }); - break - } - } - - postMessage({ - type: "progress", - challenge: challengeBase64, - attempts: batchSize, - smallestHash: smallestHash, - difficulty: challenge.difficulty, - probabilityOfFailurePerAttempt: probabilityOfFailurePerAttempt - }); - - if(working) { - this.setTimeout(doWork, 1); - } - }; - - if(scrypt) { - doWork(); - } else { - scryptPromise.then(() => { - doWork(); - }); - } -} - -// https://stackoverflow.com/questions/39460182/decode-base64-to-hexadecimal-string-with-javascript -function base64ToHex(str) { - const raw = atob(str); - let result = ''; - for (let i = 0; i < raw.length; i++) { - const hex = raw.charCodeAt(i).toString(16); - result += (hex.length === 2 ? hex : '0' + hex); - } - return result; -}