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

# Setup

Configure DID resolution and Agent Card verification, shared by both bindings.

> **Draft tutorial** — walks through `@cheqd/agent-toolkit`'s current, real API. Not yet externally reviewed; the API may change before a stable release.

Both the [A2A](https://docs.cheqd.io/product/sdk/agent-toolkit/sign-outgoing-requests.md) and [AP2](https://docs.cheqd.io/product/sdk/agent-toolkit/issue-mandate-presentation.md) bindings resolve the keys behind a DID through this package. This page sets that part up once.

## Install

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

## Resolve `did:cheqd` keys

`createDidCheqdResolver` builds a resolver function against a universal-resolver-shaped endpoint (the public `resolver.cheqd.net`, or your own):

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

const resolveDidCheqd = createDidCheqdResolver({
  resolverUrl: 'https://resolver.cheqd.net/1.0/identifiers',
});

const document = await resolveDidCheqd('did:cheqd:testnet:z6Mk...');
```

This fails closed: a non-200 response, invalid JSON, a document missing `id`, or a document whose `id` doesn't match the DID you asked for all resolve to `null`, never throw. A deactivated DID resolves successfully but comes back with `deactivated: true` on the document — its keys are then refused downstream, not silently trusted.

If you resolve `did:cheqd` documents some other way (for example through a Credo agent's own `DidsApi`), copy `didDocumentMetadata.deactivated` onto the document yourself — the key-resolution functions below rely on that flag being present, not on re-deriving it.

## Resolve the key behind a signature

`createRetrievePublicKey` builds the callback `@a2a-js/sdk`'s `verifyAgentCardSignature` expects, resolving `did:web` and `did:key` natively and `did:cheqd` through the resolver above:

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

const retrievePublicKey = createRetrievePublicKey({
  // Reject any kid whose DID doesn't match the agent you expect to be talking to.
  expectedDid: 'did:cheqd:testnet:z6Mk...',
  resolveDidCheqd,
});
```

`expectedDid` matters: without it, a signature claiming to be from *any* DID verifies as long as its own key checks out — pin it to the DID you actually expect, not just whatever the message claims.

## Next steps

* [A2A: Sign outgoing requests](https://docs.cheqd.io/product/sdk/agent-toolkit/sign-outgoing-requests.md) and [verify incoming requests](https://docs.cheqd.io/product/sdk/agent-toolkit/verify-incoming-requests.md)
* [AP2: Issue](https://docs.cheqd.io/product/sdk/agent-toolkit/issue-mandate-presentation.md) and [verify](https://docs.cheqd.io/product/sdk/agent-toolkit/verify-mandate-presentation.md) a mandate presentation


---

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