Skip to content

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): VerificationState

Checks whether the incoming request carries a valid access token.

How it works:

  1. Reads session_id and access_token from the request's query string.
  2. If both are present, the session_id exists in activeSessions, and the token matches the stored value - the session is consumed and { type: 'verified' } is returned.
  3. Otherwise, a new sessionId is generated, added to activeSessions, 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.

RequestHandled path
GET/sse
POST/verify/self
POST/verify/zk

Returns a 404 response for any unrecognised path.

Note: The verify handler expects the URL's pathname to be relative to basePath. 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/*