Created
February 14, 2024 08:18
-
-
Save Fweak/d101137cd4b909b9694457a7b1debb7c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// exact same package they use for sha256, just not minified/"web-ified" | |
const sha256 = require('js-sha256') | |
let hashDifficulty = function (arg1) { | |
return ( | |
0x10000000000000 / (Number('0x'['concat'](arg1['slice'](0x0, 0xd))) + 0x1) | |
) | |
} | |
let __ = (inputs, timestamp, secret) => { | |
var initialHash = sha256.sha256( | |
`${inputs.platformInputs}, ${timestamp}, ${secret}` | |
) | |
var subchallengeDifficulty = inputs.difficulty / inputs.subchallengeCount | |
var subchallengeResults = [] | |
for (var i = 0; i < inputs.subchallengeCount; i++) { | |
var nonce = 1 | |
while (true) { | |
var currentHash = sha256.sha256(`${nonce}, ${initialHash}`) | |
if (hashDifficulty(currentHash) >= subchallengeDifficulty) { | |
subchallengeResults.push(nonce) | |
initialHash = currentHash | |
break | |
} | |
nonce++ | |
} | |
} | |
return { | |
answers: subchallengeResults, | |
finalHash: initialHash | |
} | |
} | |
let makeId = function () { | |
let result = '' | |
for (let i = 0; i < 32; i++) { | |
result += '0123456789abcdef'[Math.floor(16 * Math.random())] | |
} | |
return result | |
} | |
let startTime = Date.now() | |
let response = __( | |
{ | |
platformInputs: 'tp-v2-input', | |
difficulty: 10, | |
subchallengeCount: 2 | |
}, // challenge-config : not changed | |
startTime, // challenge-st(starttime) : yes | |
makeId() // random id to check for hashing | |
) | |
console.log(response) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
x-kpsdk-cd
:{"workTime":1707645962556,"id":"e4369e98db038a24585a4e76a3fdcb1d","answers":[13,1],"duration":3.4,"d":3388,"st":1707644948142,"rst":1707644951530}