# Verena Presence: developer reference

Verena Presence proves that a real person is present on a real device, without a CAPTCHA. The visitor taps once on their phone, with Face ID or a fingerprint. It has two parts: a widget on your page, which gives you a proof token, and one API call on your server, which says whether the token is good.

- Human-readable docs: https://verena.se/docs
- Dashboard (keys and gates): https://verena.se/account/keys
- API base URL: `https://verena.se`
- Widget script: `https://widget.verena.se/js/verena.min.js`

## Instructions for AI agents integrating Verena Presence

Verena Presence proves that a real person is present on a real device, as a replacement for a CAPTCHA. It has two parts: a widget on the page, and one API call on the server. Follow these rules when you add it to an application.

### Integration

1. Load the widget with a script tag: `<script src="https://widget.verena.se/js/verena.min.js"></script>`. Do not install `@verena/js` from npm: it is not published.
2. Call `Verena.init({ siteKey, onVerified, onError })` once, then `Verena.mount(container)`. The whole client API is `init`, `mount`, `status` and `reset`. The only options are `siteKey`, `onVerified`, `onError`, `theme`, `gate`, `returnUrl` and `appClipRedirect`. There is no `Verena.verify()`, no modal, and no `onDismiss` or `externalStyles` option. Do not invent other functions or options.
3. The site key (`site_…`) goes in frontend code. The secret key (`sk_…`) goes only in a server-side environment variable, such as `VERENA_SECRET_KEY`: never in client code, logs or version control. If the user has no keys yet, tell them to create a key pair at https://verena.se/account/keys.
4. Pass `proof.token` from `onVerified` to the backend with the request it protects, as a form field or a header.
5. On the server, before acting on the request, `POST https://verena.se/v1/verify` with the header `Authorization: Bearer <secret key>` and the JSON body `{ "token": "<token>" }`. Proceed only if the status is 200 and the response has `"valid": true`. The response also has `scope`: `"personhood"` for a plain token, `"device-entry"` at a gate (see Gates below). When it isn't valid, `code` says why, such as `token_invalid` or `wrong_key`. Set a timeout on the call (about 10 seconds), and treat a network error, a timeout or a non-200 status as not verified: fail closed.
6. Never trust `onVerified`, `Verena.status()` or `sessionStorage` on the server. Only the answer from `/v1/verify` counts.
7. A plain token can be verified any number of times within its hour. If the action must happen once per check (a sign-up, a vote, a purchase), store the token, or its SHA-256 hash, after the first use and refuse it the second time.
8. Keep the protected submit button disabled until `onVerified` fires. To ask again, empty the container and call `Verena.mount` again.
9. Give the widget's container `min-height: 88px`, so the page doesn't shift while it loads. The widget is at most 380 px wide.

### Redirects

- In some cases the check sends the visitor away from the page and brings them back through a redirect to `returnUrl` (by default the current page), which can open in a **new tab**. The application must handle this.
- Mount the widget on the `returnUrl` page on load: it picks up the proof there and calls `onVerified(proof, { returned: true })`. Don't rely on the original tab receiving the proof.
- If the page has a form or other state, save it to `localStorage` on input and restore it in `onVerified` when `returned` is `true`, because the new tab starts empty. The saved state can be missing, since the visitor may return in a different browser: then keep the proof and ask the visitor to fill in the form again. Don't save passwords or other secrets.
- In a single-page app, make sure the router keeps the `verena_session` query parameter until the widget has read it.
- `returnUrl` must be on the page's own origin; other values are ignored.
- Leave `appClipRedirect` at its default; do not set it.

### Configuration

- If the site has a Content Security Policy, add `https://widget.verena.se` to `script-src` and `frame-src`. That is all the widget needs: it talks to Verena through a privacy relay from inside its own frame. Also add `https://verena.se` to `connect-src` and `frame-src`, so the widget keeps working when the relay can't be reached: it then falls back to a direct connection, which a stricter policy blocks.
- Every key needs at least one allowed origin, written as scheme and host, like `https://example.com`. For development, use a separate key with the dev origin, such as `http://localhost:3000`, or add that origin to the key. Tell the user to list the production origins on the key in the dashboard. Handle `onError` with `err.code === "origin_not_allowed"` by logging a clear message for the developer.

### Gates

- Use a gate only if the user wants to limit entries per device, such as a queue or a vote: one entry per device, unless the gate sets more (`maxUses`, up to 100). Any site key works. The user creates the gate under Gates in the dashboard (it works at once), or the app's setup does it with `POST /v1/gates` (see the reference).
- Pass the gate's slug as `gate` to both `Verena.init` and `/v1/verify`. Without it, `/v1/verify` would also accept a plain token from a page that left `gate` out; with it, such a token is refused with `not_gate_token`.
- A valid gate token answers `{ "valid": true, "scope": "device-entry", "gate": "<slug>", "entry": "<32 hex characters>", "repeat": <boolean> }`. `entry` is the id of one entry. With one entry per device it is the same every time the device comes back: use it to recognise that device. With more, each entry has its own id, and a device with none left gets its last one again. `repeat` is `true` when the token is for an entry made before.
- Gate tokens work once, and `/v1/verify` spends them before the app saves anything. So decide by the app's own records keyed by `entry` (with a unique index), not by `repeat`: if the save fails, a later check reports `repeat: true` with nothing stored. On a failed save, answer an error and have the page empty the widget's container and mount it again for a new token.
- In `onError`, `unknown_gate` means no gate with that slug is on this site key, and `bad_gate` means `gate` isn't a string. `/v1/verify` answers `unknown_gate` too, when the slug the server passed isn't on the key: the token stays unused.
- Gates were called events until December 2026. Don't use the old names (`event`, `/v1/events`, `unknown_event` and the like) in new code.

### Do not

- Do not self-host, proxy or bundle the widget script, wrap the widget in your own iframe, or call the `/widget/*` endpoints directly.
- Do not use the old hosts `api.verena.dev` or `cdn.verena.dev`.
- Do not try to decode the token. It is a random string with no claims.
- Do not add a fallback that skips verification when Verena can't be reached, unless the user asks for one.
- Do not collect personal data to go with the check: it doesn't need any.

Full reference: https://verena.se/docs.md

## Quickstart

1. Sign in at https://verena.se/login and create a key pair in the dashboard. You get a site key (`site_…`) for the page and a secret key (`sk_…`) for your server. The secret key is shown once.
2. Add the widget to the page.
3. Check the token on your server with `POST /v1/verify` before you act on the request.

```html
<div id="verena" style="min-height: 88px"></div>
<script src="https://widget.verena.se/js/verena.min.js"></script>
<script>
  Verena.init({
    siteKey: "site_your_key",
    onVerified: (proof) => {
      // Send proof.token with the request you want to protect
      form.elements.verenaToken.value = proof.token;
    },
  });
  Verena.mount("#verena");
</script>
```

```js
// Node.js (Express)
app.post("/signup", async (req, res) => {
  let valid = false;
  try {
    const check = await fetch("https://verena.se/v1/verify", {
      method: "POST",
      headers: {
        "Authorization": `Bearer ${process.env.VERENA_SECRET_KEY}`,
        "Content-Type": "application/json",
      },
      body: JSON.stringify({ token: req.body.verenaToken }),
      signal: AbortSignal.timeout(10_000),
    });
    valid = check.ok && (await check.json()).valid === true;
  } catch {
    // Network error or timeout: fail closed
  }
  if (!valid) return res.status(403).send("Verify you're human first.");
  // A real person is here: go ahead
});
```

```python
# Python (Flask)
@app.post("/signup")
def signup():
    try:
        check = requests.post(
            "https://verena.se/v1/verify",
            headers={"Authorization": f"Bearer {VERENA_SECRET_KEY}"},
            json={"token": request.form.get("verenaToken", "")},
            timeout=10,
        )
        valid = (check.status_code == 200
                 and check.json().get("valid") is True)
    except (requests.RequestException, ValueError):
        valid = False  # error or timeout: fail closed
    if not valid:
        return "Verify you're human first.", 403
```

Always check on the server. The widget's callback runs in the visitor's browser, and a bot can skip it.

## How a check works

- **1.** Your page calls `Verena.mount()`. The widget runs in a frame on Verena's domain.
- **2. The Verena check:** the visitor confirms with their device, Verena checks that interaction with local device attestation, and the widget gets a proof token.
- **3.** The widget calls your `onVerified(proof)`.
- **4.** Your page sends the token to your server with its request.
- **5.** Your server calls `POST /v1/verify` and gets `{ "valid": true }`.

Local device attestation means the device's own secure hardware vouches that a real person used it. How the check runs differs per platform and device, and can change over time; nothing in your integration depends on it.

The token is the same whichever way the visitor verified.

## Entering again

At a gate, Verena counts entries per device. Each gate has a number of **entries per device**: 1 unless you set another, up to 100 (`maxUses`).

- **Entries left:** the device enters again, with a new `entry` id and `repeat: false`.
- **None left:** the device isn't turned away. It gets a token for its last entry again: the same `entry` id, with `repeat: true`. Look that id up in your records and give the visitor their place back. With 1 entry per device, that is every return.
- **Another device** is another entry. Verena can't tell that two devices belong to one person.
- **Clear entries** on the gate's page starts the count over: every device can enter again, and keeps its `entry` ids.

Treat `entry`, not `repeat`, as the truth: if an earlier save on your side failed, the retry says `repeat: true` though you have nothing stored (see Gates).

## Widget

### Install

```html
<script src="https://widget.verena.se/js/verena.min.js"></script>
```

This defines a global `Verena`. The npm package `@verena/js` is not published yet. The widget is a 380 × 88 frame that fills its container up to 380 px wide. It works on HTTPS pages and on `localhost`.

### Verena.init(config)

Call once, before `mount`. Throws if `siteKey` is missing.

| Option | Type | Description |
|---|---|---|
| `siteKey` | string, required | Your public site key, `site_…`. |
| `onVerified` | `(proof, context) => void` | Called when the visitor has verified. `proof.token`: the token. `proof.expiresAt`: Unix seconds, one hour after issue. `proof.repeat`: at a gate, `true` when the device had entered before and gets that same entry back. `context.returned`: `true` when the visitor came back through a redirect, on a new tab (see Handling redirect URLs). |
| `onError` | `(error) => void` | Called with an `Error` when the widget can't start or the check fails. May carry a `code` (see Errors). |
| `theme` | `"light" \| "dark" \| "auto"` | Default `"light"`. `"auto"` follows the system. |
| `gate` | string | Slug of one of your gates, made on this site key. With it the check is an entry to that gate; without it, plain verification. Any key does both. |
| `returnUrl` | string | Where the visitor returns after verifying, when the check sends them away from your page, as on iPhone or in an in-app browser. Same origin as the page, or ignored. Default: the current page. |
| `appClipRedirect` | boolean | Default `true`. `false` keeps iPhones on a web form on which a new iPhone can't verify: for testing only. Ignored at gates. |

### Verena.mount(container)

Renders the widget into `container`, a CSS selector or an element. Throws if `init` wasn't called or the container doesn't exist. To ask again, empty the container and call `mount` again.

### Verena.status()

Returns `{ verified: boolean, expiresAt?: number }`: whether this tab holds an unexpired proof (kept in `sessionStorage`). Useful to skip the widget for a visitor who just verified. It doesn't return the token: keep the one from `onVerified` if a later request needs it. Not proof for your server.

### Verena.reset()

Forgets the stored proof. Tokens already issued stay valid on the server until they expire.

### Errors

`onError` receives an `Error` with a readable `message`. Setup problems are also logged to the console with the prefix `[verena]`.

| `code` | Meaning | Fix |
|---|---|---|
| `invalid_key` | The site key doesn't exist. | Check `siteKey`. |
| `origin_not_allowed` | The page's origin isn't in the key's allowed origins. | Add it in the dashboard. |
| `unknown_gate` | No gate with that slug on this key. | Check the slug, and that the gate is on the key in `siteKey`. |
| `bad_gate` | `gate` isn't a string. | Pass the slug as a string, or leave `gate` out. |

Errors without a `code` come from the check itself, like a cancelled fingerprint prompt. The widget shows them and lets the visitor retry.

### Content Security Policy

```
Content-Security-Policy:
  script-src 'self' https://widget.verena.se;
  frame-src https://widget.verena.se
```

No `connect-src` entry is needed: your page makes no requests to Verena. Only if the [relay](#relay) is unavailable does the widget fall back to `https://verena.se`; to allow that fallback, add it to `connect-src` and `frame-src`.

## Server API

### Authentication

Send the secret key as a bearer token: `Authorization: Bearer sk_…`. Each secret key belongs to one site key, and verifies only the tokens issued for it. A missing or wrong key returns `401` with `{ "valid": false, "error": "…" }`; a wrong key also has `"code": "invalid_secret"`.

### POST /v1/verify

Checks a proof token. A token that isn't valid returns `200` with `"valid": false` and an `error`. `401` and `400` mean the call itself was wrong. `503` means Verena couldn't answer: don't let the request through, and try again.

Body:

| Field | Type | Description |
|---|---|---|
| `token` | string, required | The token from `onVerified`. |
| `gate` | string | For gate tokens: the slug you expect. Always pass it when you expect an entry: a key gives plain tokens too, and with `gate` those are refused (`not_gate_token`). A token for another gate of the same key is refused and stays unused. |

Response:

| Field | Type | Description |
|---|---|---|
| `valid` | boolean | Whether to let the request through. |
| `scope` | `"personhood"` \| `"device-entry"` | `"device-entry"` for gate tokens. |
| `error` | string | Why not valid, in words. |
| `code` | string | The same, for code: `token_invalid` (unknown, expired, or a gate token already spent), `wrong_key` (issued for another site key), `not_gate_token` (you passed `gate`, the page didn't), `other_gate` (the token is for another gate of this key, and stays unused), `unknown_gate` (the `gate` you passed isn't a gate of this key: check the slug; the token stays unused), `token_used` (another call spent the token at the same moment). The gate's dashboard page counts each. |
| `gate` | string | Gate tokens: the gate's slug. |
| `entry` | string | Gate tokens: the id of this entry, 32 hex characters. The same every time the device comes back to it; at a gate with more than one entry per device, each entry has its own (see Entering again). Its page in the dashboard is `https://verena.se/account/entries/<entry>`. |
| `repeat` | boolean | Gate tokens: `true` when the token is for an entry the device made before, `false` for a new entry. |

```json
{ "valid": true, "scope": "personhood" }
```

```json
{ "valid": true, "scope": "device-entry", "gate": "spring-sale", "entry": "9b2e41c07d5fa3e8c16b0f42d97a5e13", "repeat": false }
```

```json
{ "valid": false, "code": "token_invalid", "error": "Token is invalid or expired." }
```

### Proof tokens

- A random 64-character hex string with no claims. Only `/v1/verify` can check it. Verena stores only its hash.
- Valid for one hour, and only with the secret key of the key pair it was issued for.
- A plain token can be verified any number of times until it expires. Mark it used on your side if an action should happen once.
- Gate tokens are spent by the first successful `/v1/verify`. Verifying again returns `valid: false`.
- No revocation: let tokens expire.

### Keys

What the dashboard does with keys and gates, for your server or a coding agent. It answers in JSON; an error has an `error` message and, for a missing or wrong credential, `401`.

- **An access token** (`pat_…`, made under Access tokens in the dashboard, https://verena.se/account/tokens) acts as you: all your keys and their gates. Keep it on your server or in your agent's secrets.
- **A key's secret key** (`sk_…`) reaches that key's gates only, not `/v1/keys`.

Send it in the `Authorization` header: `Authorization: Bearer pat_…` for an access token, `Authorization: Bearer sk_…` for a secret key.

| Request | Does |
|---|---|
| `GET /v1/keys` | Your keys: label, allowed origins, how many gates, when last used. |
| `POST /v1/keys` | Create a key: `{ "label", "allowed_origins" }`, with at least one origin. Returns the site key and the secret key, shown only this once. |
| `PATCH /v1/keys/:id` | Change `label` or `allowed_origins` (comma-separated; `example.com` is saved as `https://example.com`). |
| `DELETE /v1/keys/:id` | Delete a key. A key with gates can't be deleted: remove them first. |

```bash
curl https://verena.se/v1/keys \
  -H "Authorization: Bearer $VERENA_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"label": "Shop", "allowed_origins": "shop.example.com"}'
```

### Gates

Everything you do with gates (see the Gates guide below) in the dashboard, you can also do through the API: create a gate with a name, give it an image shown as people enter, read its counts and entries, clear it or remove it. That lets your server or a coding agent set up a gate without opening the dashboard.

Use the same credentials as for keys. With an access token, `POST /v1/gates` takes the `keyId` to make the gate on; with a secret key, the gate goes on that key.

| Request | Does |
|---|---|
| `GET /v1/gates` | The keys and their gates, with counts. With a secret key: that key only. |
| `POST /v1/gates` | Create a gate: `{ "slug", "name", "keyId"?, "maxUses"? }`. `maxUses` is the entries per device, 1 to 100 (default 1). Returns `{ "id" }`. |
| `GET /v1/gates/:id` | One gate: counts by day, week and month, by phone and over time, and how its checks went. |
| `GET /v1/gates/:id/entries` | The gate's entries, newest first, at most 500, with their `total`. Each has its `id` (the `entry` from `/v1/verify`), `enteredAt` and `platform`. |
| `GET /v1/gates/entries/:entry` | One entry by the `entry` id from `/v1/verify`, with its gate. |
| `PATCH /v1/gates/:id` | Change `name` or `maxUses`. The slug can't change. |
| `PUT /v1/gates/:id/image` | Set the image shown as people enter. The body is the file: PNG, JPEG or WebP, at most 512 KB. |
| `DELETE /v1/gates/:id/image` | Remove the image. |
| `POST /v1/gates/:id/clear` | Clear its entries: every device can enter again. |
| `DELETE /v1/gates/:id` | Remove the gate. Pages that name it stop working at once. |

```bash
curl https://verena.se/v1/gates \
  -H "Authorization: Bearer $VERENA_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"keyId": "<key id>", "slug": "spring-drop", "name": "Spring drop"}'

curl -X PUT https://verena.se/v1/gates/<id>/image \
  -H "Authorization: Bearer $VERENA_TOKEN" \
  -H "Content-Type: image/png" --data-binary @poster.png
```

## Guides

### Allowed origins

Each key has a list of allowed origins, set in the dashboard as a comma-separated list, like `https://example.com, https://www.example.com`. The widget then starts only on those origins, and anywhere else `onError` gets `origin_not_allowed`, with the origin it saw.

- Write an origin as scheme and host, plus a port if it isn't the default: `https://example.com`, `http://localhost:3000`. No path, no trailing slash.
- `https://example.com` also allows the same host on another port, but not subdomains: list `https://www.example.com` separately.
- The list is required: a key names at least one origin. An empty list is refused with `origins_required`.
- Use separate keys for production and for development, so their origins and traffic stay apart. Every key does plain verification and any of its gates.
- The first key's allowed origin defaults to the website given at sign-up. Change a key's origins any time with Edit in the dashboard.

### Handling redirect URLs

Most checks finish inside the widget, on your page. In some cases, depending on the device and on how the visitor moves through the check, Verena sends them back to your site through a redirect instead, and that can land in a **new tab**. Your site must handle it.

The two common cases:

- **iOS.** The check runs in the Verena App Clip, and when it's done, iOS opens your page again in a new Safari tab rather than returning to the one the visitor left.
- **In-app browsers**, the browser views inside apps like Instagram, TikTok or Gmail. The check can't finish there, so it continues in the device's regular browser, and the visitor comes back to your page in a new tab there, not in the app they started in.

1. The visitor leaves your page, for example to the App Clip, or from an in-app browser to the regular browser.
2. They verify, and Verena issues the token for the session.
3. They land on `returnUrl` (by default the page they came from), possibly in a new tab, with a `verena_session` query parameter.
4. The widget on that page picks up the proof, removes the parameter from the address bar, scrolls back to where the visitor was, shows as verified and calls `onVerified(proof, { returned: true })`.

What your site must do:

- Mount the widget on the `returnUrl` page, on load. Without it the proof isn't picked up, and the visitor has to verify again.
- Save what the visitor filled in before they verify, and restore it when `returned` is `true`: they come back in a new tab that starts empty. Save it in `localStorage` or on your server. `localStorage` stays in one browser, so it's gone when an in-app browser (Instagram, TikTok, Gmail) hands the visitor over to their regular browser. Only a copy on your server, such as under their account, survives that.
- Single-page apps: point `returnUrl` at a route that mounts the widget, and don't let the router drop `verena_session` before the widget reads it.
- Don't rely on the original tab. It may still be open, but it won't receive the proof.

`returnUrl` must be on the page's own origin; other values are ignored, so a session can't become an open redirect.

```js
const KEY = "signup-draft";
form.addEventListener("input", () => {
  const draft = Object.fromEntries(new FormData(form));
  delete draft.password; // never store secrets
  try {
    localStorage.setItem(KEY, JSON.stringify(draft));
  } catch {} // private mode or full: the fallback below covers it
});
form.addEventListener("submit", () => {
  localStorage.removeItem(KEY);
});

Verena.init({
  siteKey: "site_your_key",
  returnUrl: "/signup",
  onVerified(proof, { returned }) {
    form.elements.verenaToken.value = proof.token;
    if (!returned) return;
    let draft = null;
    try {
      draft = JSON.parse(localStorage.getItem(KEY));
    } catch {} // storage blocked, or not valid JSON
    if (draft) {
      for (const [k, v] of Object.entries(draft)) {
        if (form.elements[k]) form.elements[k].value = v;
      }
    } else {
      // Back in another browser, without the draft.
      // The proof still counts: ask for the form again.
      notice.textContent =
        "You're verified. Please fill in the form again.";
    }
  },
});
Verena.mount("#verena");
```

### Gates

A gate lets each device in a set number of times, once unless you choose more: a ticket queue, a drop, a vote, a sign-up. A device that comes back after that gets its same entry, so a visitor who reloads keeps their place instead of being turned away (see Entering again).

1. Create a gate under Gates in the dashboard. Name it, and the dashboard suggests the slug you pass as `gate`. Put it on any of your keys (they keep doing plain verification), or let the dashboard make a new one. You can give it an image (PNG, JPEG or WebP, up to 512 KB) that the App Clip shows as the visitor enters.
2. Pass `gate` to `Verena.init` and to `/v1/verify`. Store `entry`, and look it up in your own records to give a returning device its place back; `repeat: true` says the device got an earlier entry back.

Gates were called events until December 2026. The old names (`event`, `/v1/events`, codes such as `unknown_event`) still work for now, and will be removed.

```js
// Page
Verena.init({
  siteKey: "site_your_key",
  gate: "spring-sale",
  async onVerified(proof) {
    const res = await fetch("/signup", {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify({
        token: proof.token,
        ...Object.fromEntries(new FormData(form)),
      }),
      signal: AbortSignal.timeout(15_000),
    }).catch(() => null); // network error or timeout
    if (res?.ok) return showDone(await res.json());

    // Not saved. The token may be spent, so get a new one.
    // The server accepts the retry: it has no record of
    // this entry yet, whatever `repeat` says.
    notice.textContent = "That didn't go through. Verify again.";
    const box = document.querySelector("#verena");
    box.innerHTML = "";
    Verena.mount(box);
  },
});
Verena.mount("#verena");
```

```js
// Server (Node.js, Express)
// The /v1/verify call, failing closed. `unavailable`:
// Verena couldn't answer, so ask for a new check later.
async function verify(body) {
  try {
    const res = await fetch("https://verena.se/v1/verify", {
      method: "POST",
      headers: {
        "Authorization": `Bearer ${process.env.VERENA_SECRET_KEY}`,
        "Content-Type": "application/json",
      },
      body: JSON.stringify(body),
      signal: AbortSignal.timeout(10_000),
    });
    if (!res.ok) return { valid: false, unavailable: res.status >= 500 };
    return await res.json();
  } catch {
    return { valid: false, unavailable: true }; // network error, timeout
  }
}

app.post("/signup", async (req, res) => {
  const result = await verify({ token: req.body.token, gate: "spring-sale" });
  if (result.unavailable) return res.status(503).end();
  if (!result.valid) return res.status(403).end();

  // The token is now spent. Decide by your own record of
  // this entry, never by `repeat`: if an earlier save failed,
  // this retry says repeat: true and you have nothing stored.
  // signups.entry has a unique index.
  const saved = await signups.findByEntry(result.entry);
  if (saved) return res.json({ id: saved.id, already: true });
  try {
    const { id } = await signups.insert({ entry: result.entry, email: req.body.email });
    res.json({ id });
  } catch (e) {
    if (isUniqueViolation(e)) return res.json({ already: true }); // a parallel retry won
    console.error("signup not saved", e);
    res.status(503).end(); // the page asks for a new check, and we accept it
  }
});
```

- Gate tokens work once. A token for another gate of the same key is refused and stays unused.
- **A failed save.** `/v1/verify` spends the token before your app saves anything. If the save then fails, the visitor needs a new token, and that check reports `repeat: true` though you never recorded the sign-up. So look the `entry` up in your own records: none there means accept the retry, one there means they already signed up. Put a unique index on `entry`, so two retries at once save one row.
- **Timeouts and errors.** A timeout, a network error or a non-200 from `/v1/verify` is never a pass. Answer `503` and let the page ask for a new check.
- When nothing comes in, the gate's dashboard page shows each stage as Verena saw it, as counts only: checks your page started, refusals (`origin_not_allowed`, `unknown_gate`), QR handoffs no phone finished, phones turned away, and `/v1/verify` answers by `code`. It shows by platform and over time, never which device.

### Privacy relay

The widget never talks to Verena's servers directly. Its requests are encrypted with Oblivious HTTP (RFC 9458) and sent through an independent relay run by Oblivious Network (`relay.oblivious.network`).

- The relay sees the visitor's IP address, but only encrypted content.
- Verena sees the content, but only the relay's address.
- The widget's page and script load from `widget.verena.se`, a static host, so the page load doesn't reach Verena's servers either.
- Your page makes no requests to Verena at all. That is why a CSP needs only `script-src` and `frame-src`.
- If the relay can't be reached, or Verena switches it off, the widget falls back to a direct connection: your page then creates the session with `https://verena.se` and loads the widget from there. Under a CSP that doesn't allow that host in `connect-src` and `frame-src`, the fallback is blocked and the widget shows an error instead.
- On by default. For debugging only, `?verena_ohttp=0` in the page's address turns it off for that page load.

## Privacy and security

- Your site learns `valid: true`, and at gates an `entry` id. No name, email, device id or biometrics.
- For a standard check Verena learns that a registered device proved itself, not which one: the proof is zero-knowledge, over the set of all registered keys. The device looks up its place in that set with private information retrieval (PIR), so the lookup doesn't single it out either. Biometrics never leave the device.
- Every check answers a fresh, single-use challenge. The widget runs in a cross-origin frame that page scripts can't read or click. Tokens are bound to the key pair, expire after an hour and are stored as hashes.

## Testing

- The widget works on `http://localhost`. Add `http://localhost:3000` to the key's allowed origins, or use a separate key for development.
- Use a real phone: an iPhone, or an Android phone with Chrome. From a computer, scan the QR code with your phone.
- Test the server path with a real token from `onVerified`.
- See the live demos at https://verena.se/presence.
