postMessage(new ArrayBuffer(0))
} else {
find(d.hash, d.threshold ?? SEND_THRESHOLD).then(nonce => {
- console.log(`pow found: ${nonce}`)
d.work = nonce
const buf = new TextEncoder().encode(JSON.stringify(data)).buffer
//@ts-expect-error
})
async function find (hash: string, threshold: string = SEND_THRESHOLD): Promise<void> {
- console.log(`hash: ${hash}`)
return new Promise(resolve => {
- calculate(hash, resolve, console.log, threshold)
+ calculate(hash, resolve, undefined, threshold)
})
- // let result = null
- // let count = 0
- // do {
- // count++
- // const nonce: Uint8Array = new Uint8Array(NONCE_BYTES)
- // crypto.getRandomValues(nonce)
- // const test: string = new Blake2b(NONCE_BYTES)
- // .update(nonce)
- // .update(parseHex(hash))
- // .digest('hex') as string
- // if (count % 1000 === 0) console.log(`${count} hashes...`)
- // if (BigInt(`0x${test}`) >= BigInt(`0x${threshold}`)) {
- // result = nonce
- // }
- // } while (result == null)
- // return result
}
/**