# Verify agent checkouts

Verify the signed approval a shopping agent presents at your checkout, offline against Provenance's published keys plus one keyless revocation check, and route orders without one to your existing bot rules.

A shopping agent can carry a signed approval from the person it shops for: an intent token [bound to the exact cart](https://provenanceauth.com/docs/mandate/guides/execution-binding.md), and sometimes a [grant](https://provenanceauth.com/docs/mandate/concepts/grants.md) with a spending limit. Use `verifyAgentCheckout` from `@provenanceauth/rails/checkout` to check it on your own checkout before you accept the order. You need no Provenance account: the keys are public, and the revocation check is keyless.

Three guides cover agent orders. Pick the one that matches your job:

| You want to | Guide |
| --- | --- |
| Check one intent token or receipt you received, offline against the published keys or with `POST /v1/verify` | [Verify a token](https://provenanceauth.com/docs/authorize/guides/verify-tokens.md) |
| Get one outcome per agent order (approved, challenged or rejected) from your own checkout rules, shaped like a 3-D Secure result | [Assess an agent checkout](https://provenanceauth.com/docs/authorize/guides/assess-checkouts.md) |
| Check the cart-bound token and grant a shopping agent presents at your own checkout, with the `verifyAgentCheckout` helper | [Verify agent checkouts](https://provenanceauth.com/docs/authorize/guides/verify-agent-checkout.md) |

**Before you begin:** install the rails package and set the issuer's API URL.

```bash
export PROVENANCE_API=https://sandbox-api.provenanceauth.com
export PROVENANCE_KEY=prv_test_full_K7mN3xQp9RbT2vWm8sYd4cFjLhXn6gAe
```

**This package isn't on npm yet.** Until then, every request in these docs runs over HTTP against the [sandbox](https://provenanceauth.com/docs/get-started/sandbox.md).

With access to the private Provenance repository, which your Provenance contact grants, install from it:

```bash
git clone https://github.com/michaelnbane-jpg/provenance.git provenance
cd provenance && pnpm install && pnpm build
node scripts/check-publishable.mjs --out ../provenance-packs
cd ../your-project
npm install ../provenance-packs/provenanceauth-sdk-1.0.0.tgz ../provenance-packs/provenanceauth-rails-1.0.0.tgz
```

To check coverage, the agent and your own checkout rules in one call, with one outcome to log, use an [assessment](https://provenanceauth.com/docs/authorize/guides/assess-checkouts.md) instead.

`PROVENANCE_KEY` is for the paid check (`require.biometric`, `require.minTier`) and for minting a test token in the sandbox; the offline checks and the revocation check need no key.

**Availability:** `@provenanceauth/rails` is available to beta customers. The checkout verifier runs in Node 20 and later; for Python, verify the token with `verify_intent_token_offline` and compare its `payload_hash` yourself (step 3).

A verified approval shows that a person on an enrolled device approved this exact order. Keep your purchase limits and fraud checks: a person can approve their own bulk orders.

## 1. Fetch and cache the issuer's keys

Tokens are ES256 signatures, checked against the keys at [`GET /.well-known/jwks.json`](https://provenanceauth.com/docs/api/public-keys.md#get-well-known-jwks-json):

**curl**

```bash
curl -s $PROVENANCE_API/.well-known/jwks.json
```

**Node**

```ts
const jwks = await (await fetch(`${process.env.PROVENANCE_API}/.well-known/jwks.json`)).json();
```

**Python**

```python
import os, httpx

jwks = httpx.get(f"{os.environ['PROVENANCE_API']}/.well-known/jwks.json").json()
```

```json
{ "keys": [{ "kty": "EC", "crv": "P-256", "alg": "ES256", "use": "sig", "kid": "…", "x": "…", "y": "…" }] }
```

`loadJwks` caches them for ten minutes and keeps the last good copy if a refresh fails. With no copy at all it throws `JwksUnavailableError`, so a checkout never accepts an approval it couldn't check:

```ts
import { loadJwks } from "@provenanceauth/rails/checkout";

const keys = loadJwks(process.env.PROVENANCE_API!);
const jwks = await keys.get();
```

## 2. Rebuild the order from your own record

The approval binds the hash of one object: the order id, the total in minor units, the currency, your merchant id, your store's origin and, when present, the cart lines and a shipping-address digest. Build it from your own order record, never from the request:

```ts
import { checkoutBinding } from "@provenanceauth/rails/checkout";

const expected = checkoutBinding({
  order_id: order.id,
  total: 3800, // $38.00 in minor units
  currency: "usd",
  merchant_id: "quillstack",
  origin: "https://quillstack.example",
  items: [{ sku: "linen-a5", name: "Linen notebook, A5", quantity: 2, unit_amount: 1900 }],
});
```

`origin` makes an approval for one store fail at another that uses the same `merchant_id`. To bind the shipping address without sending it, add `fulfillment_digest: await fulfillmentDigest(address)`, a SHA-256 over the canonical address object; the agent computes the same value from the address the person confirmed.

## 3. Verify the Provenance-Intent header

The agent sends the intent token in the `Provenance-Intent` header, and its grant, if it has one, in `Provenance-Mandate`. `verifyAgentCheckout` checks the signature and expiry, the order binding, the approval strength you require, the grant's limits, and the revocation and approval status, in that order:

**Node**

```ts
import { verifyAgentCheckout, publicVerify } from "@provenanceauth/rails/checkout";
import { Provenance } from "@provenanceauth/sdk";

const provenance = new Provenance(process.env.PROVENANCE_KEY!);

const result = await verifyAgentCheckout(req.headers.get("provenance-intent"), {
  jwks,
  expected,
  mandate: req.headers.get("provenance-mandate"),
  require: { biometric: true },
  authorize: provenance.authorize, // how the person approved comes from your paid check
  onlineStatus: publicVerify(process.env.PROVENANCE_API!),
});

if (result.accepted) return confirmOrder(order, result.source);
if (result.reason === "no_intent") return runBotRules(req); // your existing checks
return rejectOrder(result.reason);
```

**Python**

```python
import os, httpx
from provenanceauth import fetch_jwks, verify_intent_token_offline, canonical_sha256_hex

issuer = os.environ["PROVENANCE_API"]
jwks = fetch_jwks(issuer)

def accept(token: str, expected: dict) -> bool:
    result = verify_intent_token_offline(token, jwks)
    if not result.valid or result.payload.get("payload_hash") != canonical_sha256_hex(expected):
        return False
    status = httpx.post(f"{issuer}/v1/verify", json={"token": token, "surface": "checkout"}).json()
    return status["valid"]
```

Build `expected` in Python the same way as `checkoutBinding`: lowercase the currency, reduce `origin` to `scheme://host[:port]`, and sort `items` by `sku`.

Set `require.minTier` to the weakest device tier you accept (tee, strongbox or sep). It is compared with the approving device's tier, which the server assigns from attestation evidence. How the person approved (the method, the biometric and the tier) isn't in the token, so `require.biometric` and `require.minTier` read it from [`POST /v1/authorize/verifications`](https://provenanceauth.com/docs/api/verifications.md#post-v1-authorize-verifications) with your key, passed as `authorize`.

## 4. Read what the approval tells you

An accepted result carries a `source` with what you can show your team or keep with the order:

| Field | Means |
| --- | --- |
| `source.agent` | The registered agent's `name` |
| `source.approved` | When the person said yes (`at`) and how (`via`: `approval` for this order, `grant` for standing permission); both null when a rule alone allowed it |
| `source.order` | The exact order the approval binds: your record, normalized |
| `source.permissions` | When a grant came along: `max_amount` per order, `budget_amount` and `budget_window`, `allowed_counterparties` and `expires_at` |

Tokens carry no personal data about the person: no name, email, IP address, location or account id. Use your own account login when you need the shopper's identity. The approval detail (the method, the device tier, the agent's id and integration) is in your paid check, [`POST /v1/authorize/verifications`](https://provenanceauth.com/docs/api/verifications.md#post-v1-authorize-verifications).

## 5. Check revocation and approval

A person or the agent's owner can revoke an approval before it expires, and only an online check sees that. The online check also sees an approval the agent's rules opened and the person hasn't answered: the token is signed, but it answers `valid: false` with `approval_pending` until the person approves, and `approval_denied` or `approval_expired` if they don't ([approval holds](https://provenanceauth.com/docs/authorize/guides/verify-tokens.md#approval-holds)). `publicVerify` calls the free [`POST /v1/verify`](https://provenanceauth.com/docs/api/verify.md#post-v1-verify) with the token and `surface: "checkout"`, and needs no key:

**curl**

```bash
# A sandbox token to try it with (the agent mints the real one).
export INTENT_TOKEN=$(curl -s -X POST "$PROVENANCE_API/v1/mandate/intents" \
  -H "Authorization: Bearer $PROVENANCE_KEY" -H "Content-Type: application/json" \
  -d '{"action_description":"Buy 2 x House Blend","agent_session_id":"sess_checkout","device_id":"dev_00000000000000000000000000000001"}' | jq -r .intent_token)
curl -s -X POST "$PROVENANCE_API/v1/verify" \
  -H "Content-Type: application/json" \
  -d "{\"token\":\"$INTENT_TOKEN\",\"surface\":\"checkout\"}"
```

**Node**

```ts
const res = await fetch(`${process.env.PROVENANCE_API}/v1/verify`, {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ token, surface: "checkout" }),
});
const { valid, revoked } = await res.json();
```

**Python**

```python
import os, httpx

result = httpx.post(f"{os.environ['PROVENANCE_API']}/v1/verify", json={"token": token, "surface": "checkout"}).json()
revoked = result["revoked"]
```

```json
{ "object": "verification_result", "valid": true, "reason": null, "kind": "intent", "binding": "not_checked", "revoked": false, "confirmed": null }
```

With `onlineStatus`, `verifyAgentCheckout` rejects a held token with the hold's reason, listed under [approval holds](https://provenanceauth.com/docs/authorize/guides/verify-tokens.md#approval-holds). If the check fails on the network, the result is `status_unavailable` and the order isn't accepted. Pass `onStatusError: "accept_offline"` to accept on the offline checks alone; the result then has `status_checked: false`.

### Require a person's yes

An agent whose rules never ask a person, or that never calls its own decision, presents a token no approval holds. To accept only orders a person said yes to, set `require.confirmed`:

```ts
const result = await verifyAgentCheckout(req.headers.get("provenance-intent"), {
  jwks,
  expected,
  require: { confirmed: true }, // or "approval": a standing grant doesn't count
  onlineStatus: publicVerify(process.env.PROVENANCE_API!),
});
```

`true` accepts an approval of this order or a live standing grant; `"approval"` accepts an approval of this order only. An order without one is rejected with `approval_missing`. It needs `onlineStatus`, because a person can approve after the token was minted and only the online check knows: `source.approved` then carries that approval's time. With checkout assessments, write the same rule on the `checkout.confirmed` fact.

## 6. Send orders without an approval to your bot rules

`no_intent` means the request had no `Provenance-Intent` header, and `source` is `null`. Treat it as any other automated order: run your existing bot checks, purchase limits and challenges.

### Ask the shopper to approve

When your bot rules would otherwise turn an agent away, ask the shopper to approve this exact order instead. Answer the checkout with `approvalChallenge`: a `401` with `WWW-Authenticate: ProvenanceIntent` and an RFC 9457 body carrying an `approval_request`. Keep any challenges of your own beside it.

```ts
import { approvalChallenge } from "@provenanceauth/rails/checkout";

if (result.reason === "no_intent" && wantsApproval(order)) {
  const c = approvalChallenge(order, {
    merchantName: "Quillstack",
    shipsTo: { city: "Portland", region: "OR", country: "US" },
    require: { biometric: true },
    ttlSeconds: 600,
    retryUrl: "https://quillstack.example/checkout",
  });
  return res.status(c.status).set(c.headers).send(c.body);
}
```

The agent's own operator relays the request to its person. To hand the agent a link it shows its person instead, or to send the link to a customer you already know, create the approval with Provenance: see [ask your own customer](https://provenanceauth.com/docs/authorize/guides/ask-your-own-customer.md). To show variants, pictures, shipping and tax, see [show the full cart](https://provenanceauth.com/docs/authorize/guides/show-the-full-cart.md).

The person sees your origin first, the name you give, the items, the total and the coarse ships-to line, then approves with face, fingerprint or passkey. The agent retries the same request with a fresh `Provenance-Intent` token bound to that order: verify it with the same `require`. `source.approved` then carries `approval_id` and `method` (`device_biometric` or `passkey`).

| Field | What it holds |
| --- | --- |
| `binding` | Exactly `checkoutBinding(order)`; the token's `payload_hash` is its canonical hash |
| `display.merchant_name` | Your store's name, at most 80 characters, shown as "calls itself …" |
| `display.ships_to` | City, region and country only. Bind the full address with `fulfillment_digest` |
| `require` | `biometric` and `min_tier`, as in step 3. A passkey approval has no device tier |
| `expires_at` | When the challenge lapses; the person's approval window is the shorter of this and 10 minutes |

A declined, expired or muted request shows up as an abandoned checkout: the agent doesn't retry with a token, and Provenance tells you nothing about the person's choice. Reject an approval older than your cart hold by reading `source.approved.at`. The challenge format, with a 20-line parser for your own clients, is on [the ProvenanceIntent challenge](https://provenanceauth.com/docs/authorize/concepts/approval-challenge.md).

On ACP, send `acpApprovalRequired(session, opts)` from `@provenanceauth/rails/acp`: a `messages[]` entry with code `approval_required` and resolution `requires_buyer_review`, plus the `provenance_approval_request` extension field. The agent completes with `provenance_intent.token` as usual; pass the same `origin` and `items` in `verifyAcpCompletion`'s `expected`.

To tell agents your rules when they reach checkout, pass `profileUrl: discoveryFields(profile).checkout.profileUrl` to `approvalChallenge`. The challenge's `approval_request` then carries `profile_url`, your signed discovery profile ([Be findable by agents](https://provenanceauth.com/docs/authorize/guides/be-findable-by-agents.md)).

## Verify ACP and x402 checkouts

The same approval rides on the ACP checkout completion and in the x402 payment header. `verifyAcpCompletion` and `verifyX402Payment` take the same `onlineStatus` callback, and the ACP binding takes the same `origin`. See [agent payments](https://provenanceauth.com/docs/authorize/guides/agent-payments.md).

## Attach the approval from the agent

On the agent's side, authorize with the order the merchant will rebuild as the `action_payload`, then send the headers:

```ts
import { checkoutBinding, checkoutHeaders } from "@provenanceauth/rails/checkout";

const { intentToken } = await prov.mandate.intents.create({
  actionDescription: "Buy 2 × Linen notebook, A5 for $38.00 at quillstack.example",
  actionPayload: checkoutBinding(order),
  agentSessionId,
  deviceId,
  mandateToken,
});
await fetch("https://quillstack.example/checkout", { method: "POST", headers: checkoutHeaders(intentToken, mandateToken), body });
```

When the store answers with a `ProvenanceIntent` challenge instead, `stepUpFetch` (or `checkoutFetch` in the framework packages) authorizes the order it names with `approval`, taking the store origin from the URL called. It throws a pending `StepUpError` until the person approves, then replays the request with the new token:

```ts
import { stepUpFetch, authorizeChallenge } from "@provenanceauth/rails/checkout";

const shopFetch = stepUpFetch(fetch, { authorize: authorizeChallenge(prov.intent, { deviceId, agentSessionId }) });
await shopFetch("https://quillstack.example/checkout", { method: "POST", body });
```

Gate agent tools with Authorize in MCP, the Vercel AI SDK, LangChain or your own tool loop, using our TypeScript and Python SDKs. Packages are available to beta customers; see [framework integrations](https://provenanceauth.com/docs/mandate/guides/framework-integrations.md).

## Verify first, ask only when nothing valid is attached

Before your checkout asks the person, verify what the agent attached. A valid token for this exact order is the person's yes: take the order. Only when nothing valid is attached, create a cart approval, and pass the header value as `intent_token` so a valid token still comes back without a prompt. See [ask once](https://provenanceauth.com/docs/authorize/guides/ask-once.md).

## Errors you might see

| Symptom | Cause | Fix |
| --- | --- | --- |
| `payload_hash_mismatch` | The items, total, currency, merchant, origin or address digest differ from what the person approved | Ask the agent to authorize the current cart again. |
| `payload_unbound` | The token binds no order | Ask the agent to authorize with `checkoutBinding(order)` as the action payload. |
| `token_invalid`, detail `unknown kid` | Your cached keys predate a key rotation | Call `keys.get({ refresh: true })` and verify again. |
| `token_expired` | Intent tokens last four hours | Ask the agent for a fresh approval. |
| `approval_too_weak` | You required a biometric or a device tier the approval lacks; a passkey approval has no hardware tier | Lower the requirement for this order, or ask for a new approval. |
| `mandate_constraint` | The order is over the grant's per-order cap, your merchant id isn't in its allowed merchants, or the grant has expired | Decline the order, or ask the person for a new grant. |
| `token_revoked` | The approval was revoked after it was given | Decline the order. |
| `approval_pending` | The agent's rules asked its person, who hasn't answered yet | Hold the order; verify again after the person answers. |
| `approval_denied`, `approval_expired` | The person declined, or nobody answered in time | Decline the order. |
| `approval_missing` | You set `require.confirmed`, and no person said yes to this order | Decline it, or ask the shopper to approve. |
| `status_unavailable` | The revocation check couldn't reach the issuer | Retry, or set `onStatusError: "accept_offline"` for low-value orders. |
| `stepup_delivery_not_configured` (503, agent side) | The agent's operator has no `mandate.approval.created` webhook and routed to no approver link | The operator subscribes a webhook endpoint and shows the approval embed, or routes to an approver link. |
| `rate_limit_exceeded` (429, agent side) | One person already has a pending approval from your store, or hit 5 an hour or 20 a day | The agent treats the checkout as declined; don't challenge on every request. |
| `JwksUnavailableError` thrown | The keys couldn't be fetched and none are cached | Retry; don't accept the order until the keys load. |

## See also

- [Verify tokens offline](https://provenanceauth.com/docs/authorize/guides/verify-tokens.md)
- [The ProvenanceIntent challenge](https://provenanceauth.com/docs/authorize/concepts/approval-challenge.md)
- [Agent payments](https://provenanceauth.com/docs/authorize/guides/agent-payments.md)
- [Grants](https://provenanceauth.com/docs/mandate/concepts/grants.md)
- [Show the full cart](https://provenanceauth.com/docs/authorize/guides/show-the-full-cart.md)
- [Ask your own customer](https://provenanceauth.com/docs/authorize/guides/ask-your-own-customer.md)
- [AP2 without a grant](https://provenanceauth.com/docs/authorize/guides/ap2-without-mandate.md)
- [3-D Secure for agentic commerce](https://provenanceauth.com/docs/authorize/guides/assess-checkouts.md)
