createChallenge() is imported from ribaunt and called server-side to generate one or more proof-of-work challenge tokens. Each token is a signed JWT that the browser solver decodes and works against.
Import
Signature
Parameters
Number of leading zero hex digits required in the SHA-256 hash. Each increment roughly doubles solve time. Values above 6 may cause browsers to hang.
Number of challenge tokens to generate. More challenges increase total proof-of-work but also increase network bandwidth.
Challenge token lifetime in seconds. Tokens submitted after expiry are rejected by
verifySolution.Return value
ReturnsChallengeToken[] — an array of signed JWT strings. Send this array to the browser as { challenges: tokens }.
Example
Recommended settings
| Use case | Difficulty | Amount | TTL |
|---|---|---|---|
| Fast / background | 4 | 4 | 30 |
| Moderate / form submission | 5 | 4 | 60 |
| High / sensitive actions | 5 | 8 | 120 |
Validation
createChallenge() validates all three parameters at runtime and throws if any value is invalid:
difficulty— must be a finite number and at least1. Fractional values are rounded down withMath.floor().amount— must be a finite number and at least1. Fractional values are rounded down withMath.floor().ttlSeconds— must be a finite number and at least1. Fractional values are rounded down withMath.floor().
Requires
RIBAUNT_SECRET to be set as an environment variable. createChallenge() will throw if the secret is missing.