solveChallenge() — a synchronous, server-side solver — that makes it easy to write automated tests for your challenge and verify endpoints without a browser. Rather than standing up a headless browser or mocking internal state, you can drive the full challenge → solve → verify cycle directly from your test suite.
Using solveChallenge in tests
solveChallenge runs the same proof-of-work algorithm the browser executes, but synchronously and in Node.js. You can generate a challenge on your server, solve it as a client would, and then feed the result into verifySolution — all within a single test.
Testing with timeout guardrails
When you need a safety net against a runaway solver in CI, pass guardrail options tosolveChallenge. You can cap the wall-clock time, the number of hash attempts, or both.
solveChallenge returns undefined for that token. Your test should assert the return value is defined before passing it to verifySolution.
Testing replay protection
Ribaunt’s defaultlocal replay mode blocks any token from being verified more than once within the same process. You can confirm this behavior directly in your tests by submitting the same solution twice.
false because the challenge JTIs are consumed on first use.
Testing with disabled replay protection
Some unit tests need to reuse the same tokens across multiple assertions — for example, testing that a valid solution always passes your business logic regardless of replay state. You can disable replay protection for a singleverifySolution call.
Only use
replayPrevention: 'disabled' in tests. Never disable replay protection in your production verify endpoint, as it allows attackers to reuse intercepted solutions.Capturing verification warnings
When you want to assert why a verification failed — not just that it returnedfalse — use the onWarning callback. This is especially useful for testing edge cases like expired tokens or invalid solutions.
reason field on the warning object can be one of the following values:
| Reason | When it fires |
|---|---|
invalid-token | The JWT is malformed, tampered with, or uses an unknown secret |
expired-token | The challenge’s TTL has elapsed before the solution was submitted |
invalid-solution | The submitted nonce does not produce a hash with the required leading zeros |
replay-detected | The same token JTI has already been consumed by the replay store |
configuration-error | A required option (e.g. replayStore) is missing or misconfigured |