switch pow to argon2id

This commit is contained in:
2026-11-22 13:52:29 -05:00
parent 80ad8a62ae
commit 8730b968b5
8 changed files with 41 additions and 16 deletions
+14 -2
View File
@@ -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;