Skip to main content
solveChallenge() runs the same proof-of-work algorithm used by the browser widget, but synchronously in Node.js. It is designed for automated testing of your challenge and verify endpoints — not for production use in request handlers. solveChallenge() supports SHA-256 tokens only and returns undefined for argon2id tokens. Use solveChallengeAsync() to solve both algorithms.

Import

Signature

Parameters

ChallengeToken | ChallengeToken[]
required
A single JWT challenge token or an array of tokens from createChallenge().
SolveChallengeOptions
Optional guardrails to prevent long-running synchronous solves.

Return value

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, a token is invalid, or a token uses argon2id. When solving an array, undefined is returned as soon as any single token fails — no partial results are returned.

Example

With guardrails:
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.

solveChallengeAsync

solveChallengeAsync() is the asynchronous variant. It reads the algorithm from each token and solves SHA-256 and argon2id tokens alike, so use it when your tests cover Argon2id challenges or mixed batches. It accepts the same SolveChallengeOptions guardrails and returns undefined under the same conditions.
Argon2id hashes take milliseconds each, so keep test difficulty at 1 and amounts small to keep suites fast.