> 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/issue-mandate-presentation.md). Agents can also search and read this documentation through its [MCP server](https://docs.cheqd.io/product/~gitbook/mcp).

# AP2: Issue a mandate presentation

Issue an Open Payment Mandate as a compact SD-JWT-VC, bound to a holder's key.

> **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.

An [AP2](https://github.com/google-agentic-commerce/AP2) Open Payment Mandate is issued as an SD-JWT-VC, then presented joined with a Key Binding JWT that proves the holder controls the key the mandate's `cnf` names, and binds the presentation to a specific transaction. This package supplies the hashing and `cnf`-verification pieces; the SD-JWT-VC construction itself uses [`@sd-jwt/core`](https://github.com/openwallet-foundation/sd-jwt-js) directly — this package does not reimplement it.

## Install

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

## 1. Issue the mandate

```typescript
import { SDJwtInstance } from '@sd-jwt/core';
import { sha256Hasher } from '@cheqd/agent-toolkit-ap2';

const issuerInstance = new SDJwtInstance({
  hasher: sha256Hasher,
  saltGenerator: (length) => /* your random base64url generator */,
  signer: issuerSigner, // signs with the issuer's private key
  signAlg: 'EdDSA',
});

const issued = await issuerInstance.issue({
  vct: 'mandate.payment.open.1', // OPEN_PAYMENT_MANDATE_VCT
  constraints: [{ type: 'payment.amount_range', currency: 'USD', max: 5000 }],
  cnf: { jwk: holderPublicJwk }, // the holder's key, not the issuer's
});
```

`vct` must be exactly `mandate.payment.open.1` (exported as `OPEN_PAYMENT_MANDATE_VCT`) for a payment mandate, or `mandate.checkout.open.1` (`OPEN_CHECKOUT_MANDATE_VCT`) for a checkout mandate — the verifier checks this explicitly, it is not advisory metadata.

## 2. Present it, bound to a specific transaction

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

const presenterInstance = new SDJwtInstance({
  hasher: sha256Hasher,
  saltGenerator: (length) => /* same generator as above */,
  kbSigner: holderSigner, // signs with the holder's private key — the one named in cnf
  kbSignAlg: 'EdDSA',
});

const token = await presenterInstance.present(issued, undefined, {
  kb: {
    payload: {
      iat: Math.floor(Date.now() / 1000),
      aud: 'did:web:merchant.example', // the verifier you're presenting to
      nonce: serverSuppliedNonce,
      transaction_data: [transactionDataHash(closedPaymentContent)],
    },
  },
});
```

`transactionDataHash` is an RFC 8785 (JCS) canonical hash of the actual closed-payment content — not a free-form string. The verifier recomputes this hash from its own copy of the transaction and compares; the two sides must serialise the exact same object for the hashes to agree (see `docs/design-decisions.md` D19, which found and fixed exactly this kind of mismatch between the TypeScript and Python ports).

`token` is the compact string you send: the issuer's SD-JWT-VC, `~`-joined with the Key Binding JWT.

## Next

[Verify a mandate presentation](https://docs.cheqd.io/product/sdk/agent-toolkit/verify-mandate-presentation.md) on the receiving side.


---

# 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/issue-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.
