switch pow to argon2id
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { argon2id } from "https://esm.sh/hash-wasm@4.12.0";
|
||||
|
||||
function hasLeadingZeroBits(bytes, requiredBits) {
|
||||
const whole = Math.floor(requiredBits / 8);
|
||||
const remaining = requiredBits % 8;
|
||||
@@ -15,9 +17,19 @@ self.onmessage = async ({ data }) => {
|
||||
console.log(`[PoW] Difficulty: ${difficulty}, Starting Nonce: ${startNonce}, Challenge: ${challenge}`)
|
||||
const startTime = performance.now();
|
||||
const encoder = new TextEncoder();
|
||||
const input = encoder.encode(challenge);
|
||||
for (let nonce = startNonce; ; nonce++) {
|
||||
const input = encoder.encode(`${challenge}${nonce}`);
|
||||
const digest = new Uint8Array(await crypto.subtle.digest("SHA-256", input));
|
||||
const salt = new Uint8Array(8);
|
||||
new DataView(salt.buffer).setBigUint64(0, BigInt(nonce), true);
|
||||
const digest = await argon2id({
|
||||
password: input,
|
||||
salt,
|
||||
parallelism: 1,
|
||||
iterations: 2,
|
||||
memorySize: 4096,
|
||||
hashLength: 32,
|
||||
outputType: "binary"
|
||||
});
|
||||
if (hasLeadingZeroBits(digest, difficulty)) {
|
||||
const hashHex = Array.from(digest).map((b) => b.toString(16).padStart(2, "0")).join("");
|
||||
const elapsed = performance.now() - startTime;
|
||||
|
||||
Reference in New Issue
Block a user