View as Markdown

Identify · Guide

Accept AP2, ACP and x402

Accept the agents you can recognize, and ask for a person when you can't. Identify reads a payment-protocol object on the request, verifies it, and reports it in the verdict's protocol field. Your traffic policy then allows it, or answers with the same ProvenanceIntent challenge a checkout step-up uses, so the person approves the exact cart.

Before you begin: run the middleware with a route map that names checkout, and read require a human.

ProtocolWhat Identify readsVerified by
AP2 (maps to AP2 0.2)A closed Checkout or Payment Mandate (SD-JWT), in the header you name or the body field checkout_mandate / payment_mandateYour AP2 stack checks the SD-JWT signature through a hook; Identify then checks the mandate's content and its Provenance intent claim
ACPA checkout session completion with provenance_intentThe intent token, bound to your session's id, total, currency and merchant
x402 v2PAYMENT-SIGNATUREThe intent token in extensions["com.provenanceauth.intent"], bound to the payment you advertised

Unsigned traffic still runs through your rules, and protocol: null is the normal case.

1. Turn on protocols in the middleware

import { Identify } from "@provenanceauth/identify";

const identify = new Identify({
  apiKey: process.env.PROVENANCE_KEY,
  protocols: {
    routes: ["/checkout*"],                 // bodies are read on these routes only, at most 64 KB
    ap2: {
      header: "AP2-Mandate",
      verify: (sdJwt) => myAp2Stack.verifyClosedMandate(sdJwt), // returns the mandate content, or throws
      expected: (req) => myCheckoutFacts(req),                   // needed for a Checkout Mandate
    },
    x402: { expected: (req) => myAdvertisedPayment(req) },
  },
});

The AP2 SD-JWT signature is your AP2 stack's to verify, because its trust roots are yours. Without the verify hook every AP2 object is unverified, never verified. A hook that throws marks it invalid; one that throws an error with code: "unavailable" leaves it unverified.

For ACP, Identify checks the token against the order you pass with orderFor (checkout_session_id is the order id), or against acp.expected.

2. Read the verdict

{
  "protocol": {
    "name": "ap2",
    "kind": "payment_mandate",
    "status": "verified",
    "amount": 9600,
    "currency": "usd",
    "payee": "quillstack",
    "provenance_intent": true
  }
}
FieldMeaning
statusverified, unverified (no verifier, no claim to check, or missing facts) or invalid (it failed a check)
reasonWhy it isn't verified: ap2_verifier_not_configured, no_expected_checkout, no_intent, payload_hash_mismatch, …
amount, currency, payeeReported for a verified object only, so a rule never reads an unverified amount
provenance_intentThe object carries a Provenance intent claim; a valid one also fills human

A protocol object names no agent identity on its own: class comes from the Web Bot Auth signature and the detection rules.

3. Use the template

accept_verified_protocols allows a verified object up to an amount of 50000 in minor units and asks for a person over that, or when an object at checkout is unverified or invalid:

{
  "rules": [
    { "id": "protocol-over-threshold", "when": [{ "fact": "protocol_status", "op": "eq", "value": "verified" }, { "fact": "protocol_amount", "op": "gt", "value": 50000 }], "then": { "action": "require_intent", "binding": "order" } },
    { "id": "accept-verified-protocols", "when": [{ "fact": "protocol_status", "op": "eq", "value": "verified" }], "then": { "action": "allow" } },
    { "id": "protocol-unverified-checkout", "when": [{ "fact": "protocol_status", "op": "in", "value": ["unverified", "invalid"] }, { "fact": "action", "op": "eq", "value": "checkout" }], "then": { "action": "require_intent", "binding": "order" } }
  ]
}

Change 50000 to your threshold in minor units. To require a listed payee, add a rule on protocol_payee with not_in_list.

4. Ask for a person on an AP2 checkout

When an AP2 checkout fails a rule and you passed no order of your own, Identify builds the challenge's order from the mandate's checkout: order_id is the Checkout's hash, with the amount, currency and payee. The agent asks its person through Authorize, they approve the cart, and the agent replays the same request with Provenance-Intent. Identify verifies the mandate again and checks the token against that order; pass orderFor and it checks against your own order instead.

x402 payments have no step-up: a payment that doesn't verify is your facilitator's to refuse.

5. Use the hosted check

POST /v1/identify/assessments takes the same objects. Send the body in request.body (at most 64 KB) and your own facts in protocols:

curl -s -X PUT "$PROVENANCE_API/v1/identify/settings/site" \
  -H "Authorization: Bearer $PROVENANCE_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "protocols": { "routes": ["/checkout*"] } }'

For AP2 in the hosted check, set protocols.ap2.verify_url to your own AP2 verifier (HTTPS) and protocols.ap2.secret. Identify posts {"object": "ap2_verify_request", "sd_jwt": "…"} signed with that secret in Provenance-Signature (the same scheme as webhooks), and your verifier answers {"content": {…}} with the closed mandate it verified, or a 4xx to reject it. The secret is encrypted at rest and only its last four characters are ever returned.

Errors you might see

SymptomCauseFix
reason: "ap2_verifier_not_configured"No ap2.verify hook (or hosted verify_url)Plug in your AP2 stack's verifier.
reason: "no_expected_checkout"A Checkout Mandate, and no Checkout facts to check it againstReturn them from ap2.expected, or pass protocols.ap2_expected to the hosted check.
reason: "no_expected_order"An ACP completion with no orderPass orderFor, or acp.expected.
reason: "payload_hash_mismatch"The object's amount or payee isn't what the token bindsTreat it as tampered.
protocol: null on a body you expectedThe route isn't in routes, or the body is over 64 KBAdd the route; keep protocol bodies small.

See also