> For the complete documentation index, see [llms.txt](https://docs.cheqd.io/product/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cheqd.io/product/sdk/agent-toolkit/verify-mandate-presentation.md). Agents can also search and read this documentation through its [MCP server](https://docs.cheqd.io/product/~gitbook/mcp).

# AP2: Verify a mandate presentation

Verify a presented mandate, its key binding, and that it covers the transaction actually being made.

> **Draft tutorial** — walks through `@cheqd/agent-toolkit-ap2`'s current, real API, the same wire format proven cross-language-conformant with the Python port in `conformance/cross-language-ap2-sd-jwt.mjs`. Not yet externally reviewed; the API may change before a stable release.

Verifying a presented [AP2](https://github.com/google-agentic-commerce/AP2) mandate is two separate checks, both required: that the presentation itself is valid (correctly signed, fresh, bound to the right audience and nonce), and that it's bound to *this* transaction, not a different one with the same mandate replayed.

## Install

```bash
npm install @cheqd/agent-toolkit-ap2@beta
```

## 1. Verify the presentation

```typescript
import { verifyOpenPaymentMandatePresentation } from '@cheqd/agent-toolkit-ap2';

const result = await verifyOpenPaymentMandatePresentation({
  token, // the compact SD-JWT-VC ~ KB-JWT string you received
  issuerPublicJwk, // the issuer's key, resolved and pinned by you — not read from the token
  expectedAudience: 'did:web:merchant.example', // your own DID
  expectedNonce: nonceYouIssued,
});
```

This checks the issuer's signature over the SD-JWT-VC, the holder's Key Binding JWT signature against the mandate's own `cnf.jwk`, and that `aud`/`nonce` match what you expected — not just that *some* signature verifies. `result.cnfJwk` is the holder key the presentation was actually bound to; compare it against whatever key you expected the holder to use, if that matters to your flow.

Use `verifyOpenCheckoutMandatePresentation` instead for a `mandate.checkout.open.1` mandate — same shape, different `vct`.

## 2. Verify it covers the transaction you're actually processing

A valid presentation proves the holder signed *some* transaction binding — not necessarily the one you think you're processing:

```typescript
import { verifyTransactionDataBinding } from '@cheqd/agent-toolkit-ap2';

const ok = verifyTransactionDataBinding(result.keyBinding, closedPaymentContent);
if (!ok) {
  throw new Error('transaction_data_binding_failed');
}
```

`closedPaymentContent` here must be byte-for-byte the same object (same keys, same values) the issuing side hashed in [Issue a mandate presentation](https://docs.cheqd.io/product/sdk/agent-toolkit/issue-mandate-presentation.md) — `verifyTransactionDataBinding` recomputes the same RFC 8785 canonical hash and compares it against what's in the presentation's `transaction_data`. A mismatch means the holder bound their signature to a different transaction than the one you're about to act on; treat it as a hard failure, not a warning.

## Next

If you also need to confirm the holder's key is authorised to spend under a DID-anchored policy (not just that the mandate chain is internally consistent), see `verifyAgentPaymentKeyCredential` and `verifySameKeyContinuity`/`verifyCnfContinuity` in the package's own README.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.cheqd.io/product/sdk/agent-toolkit/verify-mandate-presentation.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
