@haggles/server provides drop-in middleware adapters for Hono (@haggles/server/hono) and Express (@haggles/server/express).
Built-In Safety Guarantees
- Startup Price Validation: Route prices are validated via
parseMoneywhen the server boots. An invalid price ("0.00"or"9.99") throwsInvalidMoneyErrorimmediately. - Local JWKS Pre-Verification: Before calling
POST /v1/payments/:id/redeem, the middleware verifies the Ed25519 JWS signature,exp,aud(sellerId),mth, canonicalurl, andamtlocally against the cached/.well-known/jwks.json. - Fail-Closed: If the facilitator is unreachable, the middleware responds with
503 Service UnavailableandRetry-After: 5. - Automatic 5xx Refund: When
refundOnError: true(default), if your downstream handler throws or responds withHTTP >= 500, the middleware automatically callsPOST /v1/payments/:id/refundin the background.