solveChallenge(token, options?) solves JWT challenge tokens synchronously. Use in tests and tooling — not in production request handlers.
solveChallenge() runs the same proof-of-work algorithm used by the browser widget, but synchronously in Node.js. It’s designed for automated testing of your challenge and verify endpoints — not for production use in request handlers.
Returns a ChallengeSolution ({ nonce: string; hash: string }) for a single token input, or ChallengeSolution[] for an array input. Returns undefined if any guardrail is hit or a token is invalid. When solving an array, undefined is returned as soon as any single token fails — no partial results are returned.
import { createChallenge, solveChallenge, verifySolution } from 'ribaunt';// Use low difficulty in tests for speedconst tokens = createChallenge(3, 2, 60);const solutions = solveChallenge(tokens);if (solutions) { const valid = await verifySolution(tokens, solutions); console.log('Valid:', valid); // true}
With guardrails:
const solution = solveChallenge(token, { maxDurationMs: 2000, maxIterations: 500_000,});if (!solution) { console.log('Solver gave up — difficulty too high or timeout reached');}
solveChallenge is synchronous and CPU-intensive. Never call it in a production HTTP request handler — it will block your Node.js event loop.
Use difficulty 3–4 in tests. Difficulty 5 will noticeably slow down your test suite.