x511(config)
Factory function that creates a verification gateway instance.
Signature
ts
function x511(config: X511Config): {
verified: (req: Request) => VerificationState
verify: (req: Request) => Promise<Response>
}Parameters
config
Type: X511Config
See the configuration reference for the full list of options.
Return Value
An object with two methods:
verified(req)
ts
verified(req: Request): VerificationStateChecks whether the incoming request carries a valid access token.
How it works:
- Reads
session_idandaccess_tokenfrom the request's query string. - If both are present, the
session_idexists inactiveSessions, and the token matches the stored value - the session is consumed and{ type: 'verified' }is returned. - Otherwise, a new
sessionIdis generated, added toactiveSessions, and a{ type: 'pending', ... }state is returned with the provider payload needed to render the 511 page.
Returns: VerificationState
verify(req)
ts
verify(req: Request): Promise<Response>Handles all internal X511 sub-routes. Mount this on your router under basePath.
| Request | Handled path |
|---|---|
GET | /sse |
POST | /verify/self |
POST | /verify/zk |
Returns a 404 response for any unrecognised path.
Note: The
verifyhandler expects the URL's pathname to be relative tobasePath. Strip the base path prefix before passing the request, or mount the handler on a sub-router that strips it automatically.
Example
ts
const gate = x511({
domain: 'https://example.com',
basePath: '/x511',
providers: ['self', 'zkpassport'],
disclousures: { minAge: 18 },
})
// gate.verified - use with toHono() or call directly
// gate.verify - mount on /x511/*