Files
cap/wasm/test/node_odd_difficulty.js
tiago 894c9e6ab9 feat: speculative challenges, jwt challenge tokens, standalone
optimizations, format
releases widget@0.1.38; standalone@2.2.0
2026-03-01 13:20:48 +00:00

22 lines
610 B
JavaScript

import { createHash } from "node:crypto";
import { solve_pow } from "../src/node/cap_wasm.js";
// salt, target
const challenge = ["02679e6558", "eeffc"];
const [salt, target] = challenge;
const nonce = solve_pow(salt, target);
const actualHash = createHash("sha256").update(`${salt}${nonce}`).digest("hex");
console.log(`salt: ${salt}
target: ${target}
nonce: ${nonce}
sha256(${salt}${nonce})
should start with ${target}
is ${actualHash.slice(0, target.length)} (${actualHash})
${actualHash.slice(0, target.length) === target ? "✅ success!" : "❌ invalid"}`);