> For the complete documentation index, see [llms.txt](https://docs.metamynd.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.metamynd.ai/agent-controls-agentsafe/request-signing-and-message-format.md). Agents can also search and read this documentation through its [MCP server](https://docs.metamynd.ai/~gitbook/mcp).

# Request Signing & Message Format

How agents sign authorize requests with Ed25519: the canonical message, the mistakes behind most SIGNATURE\_INVALID errors, and related signatures.

Every call to the authorize gate is authenticated with an **Ed25519** signature by the agent's own key. Getting this exactly right matters — the three footgun clauses below account for most `SIGNATURE_INVALID` errors integrators hit.

Three more signatures sit around that core, and this page covers all of them:

| Signature                            | Who signs                            | Message domain                                                                                      | Required?                                     |
| ------------------------------------ | ------------------------------------ | --------------------------------------------------------------------------------------------------- | --------------------------------------------- |
| The **authorize** signature          | the agent                            | the eight-field canonical message (v1), or the v2 message when the request carries a `jurisdiction` | always                                        |
| **Payload binding**                  | the agent                            | `MAGP-PAYLOAD-v1` (at authorize) / `MAGP-PAYLOAD-REBIND-v1` (late binding)                          | optional; an owner can require it             |
| **Envelope signature**               | the agent                            | the GovernanceEnvelope hash                                                                         | optional                                      |
| **Service (counterparty) signature** | the service that executes the action | `MAGP-SERVICE-v1`                                                                                   | recommended; required to claim a mainnet hold |

The settlement calls (claim, capture, void, …) are **not** agent-signed: they are made by the executing service, either signed with its own identity or anonymously with a claim token (see [Service signature](https://docs.metamynd.ai/agent-protocol/request-signing-and-message-format#service-counterparty-signature) below and [Settlement & Settlement Evidence](https://docs.metamynd.ai/agent-protocol/settlement-and-settlement-evidence)).

#### The canonical message

The signed message is the UTF-8 string formed by joining exactly **eight** fields with `|` (U+007C), in this fixed order, substituting an empty string for an absent `merchant` or `resource`:

```
agentDid | action | amount | currency | merchant | resource | nonce | issuedAt
```

Example:

```
did:hedera:testnet:zEEZ…|flight-purchase|150|USD|skyward-air||9f2c…|2026-07-10T05:12:00Z
```

The signature itself travels as a **body field**, not an HTTP header:

```json
{
  "agentDid": "did:hedera:testnet:zEEZ…",
  "action": "flight-purchase",
  "amount": 150,
  "currency": "USD",
  "merchant": "skyward-air",
  "resource": "booking-db",
  "itinerary": { "tool": "book-flight", "riskLevel": "low" },
  "nonce": "9f2c…",
  "issuedAt": "2026-07-10T05:12:00Z",
  "signature": "<hex Ed25519 signature>"
}
```

A verifier **must** reconstruct this message itself from the received fields — never trust a client-supplied message string — and verify it against the key resolved from `agentDid` via DID resolution (`GET /did/:did`), not from key material carried in the request.

> `itinerary` (tool, riskLevel, …) and the optional `trace` object are **unsigned** context — the agent's own claims, which the gate ranks by provenance rather than believes (see [Context Provenance & Risk Floors](https://docs.metamynd.ai/core-concepts/context-provenance-and-risk-floors)). `resource` **is** signed: a mandate's `{leftOperand:'resource'}` scope constraint is cryptographically committed the same way `merchant` is, not merely asserted — a compromised counterparty relaying a signed request can't swap in a different resource without invalidating the signature. A jurisdiction placed in the `itinerary` is ignored by the gate; to have one enforced, sign it (below).

`amount` and `currency` may be omitted together for a non-financial action (a mandate that carries a spend constraint still requires a real amount). `nonce` is 8–128 characters and single-use; `issuedAt` must fall inside the gate's freshness window.

#### Signed jurisdiction (message v2)

A request **may** carry a top-level `jurisdiction`: an ISO 3166-1 alpha-2 code, sent upper-case. A request that carries it is signed over the **v2** message: the eight fields above, then the literal tag `MAGP-AUTH-v2`, then the jurisdiction exactly as transmitted, each escaped the same way:

```
agentDid | action | amount | currency | merchant | resource | nonce | issuedAt | MAGP-AUTH-v2 | jurisdiction
```

```
did:hedera:testnet:zEEZ…|flight-purchase|150|USD|skyward-air|booking-db|9f2c…|2026-07-10T05:12:00Z|MAGP-AUTH-v2|SG
```

* **Absent = v1, byte for byte.** A request without the field is signed exactly as before; every existing client keeps verifying.
* **The request picks the message.** A verifier builds v2 when `jurisdiction` is present and v1 when it is absent, and never tries the other. Adding the field to a v1-signed request, changing it, or stripping it from a v2-signed one fails `SIGNATURE_INVALID`. A value that isn't two ASCII letters is `MALFORMED_REQUEST`.
* **SDKs:** `@metamynd/agentsafe-guard` ≥ 0.16.0 (`jurisdiction: 'SG'`), `metamynd-client` ≥ 0.6.0 (`jurisdiction="SG"`), daemon signing with `@metamynd/agentsafe-signer` ≥ 0.18.0 (an older daemon is refused `JURISDICTION_SIGNING_UNSUPPORTED` by the client before anything is sent). Verifiers: `@metamynd/agentsafe-mcp-guard` ≥ 0.16.0, `@metamynd/agentsafe-a2a-guard` ≥ 0.10.0.
* **What the gate enforces** is the *effective* jurisdiction: the country the owner registered for the payee when there is one (a differing signed value is `JURISDICTION_MISMATCH`), else the signed value. See [Restrict Jurisdictions](https://docs.metamynd.ai/guides/restrict-jurisdictions).
* **Vectors:** `authorize-v2-vectors.json` in the [public protocol folder](https://github.com/Metamynd/agentsafe-guard/tree/main/docs/protocol), under the same test key as the eight-field vectors, in a separate file so a client pinned to the v1 vectors keeps passing until it implements v2.

#### Three footgun clauses

These are the exact rules, because they're easy to get subtly wrong and every failure surfaces only as `SIGNATURE_INVALID`:

1. **Private key encoding.** Managed provisioning issues hex-encoded **DER PKCS#8** (ASN.1 SEQUENCE tag `30`), not a raw 32-byte seed. Implementations *should* accept either but must not assume raw.
2. **Number stringification.** `amount` is signed as text using canonical ECMAScript `String(n)` rendering. The usual traps:

   * an integral value carries no fractional part: `150.0` → `"150"`, not `"150.0"`;
   * outside `1e-6 ≤ |n| < 1e21` ECMAScript uses exponent form with its own spelling: `5e-7` → `"5e-7"`, `1e21` → `"1e+21"`;
   * below `1e-4` a language's default may already differ: Python's `repr(0.00005)` is `"5e-05"`, where ECMAScript writes `"0.00005"`;
   * the verifier rebuilds the text from the JSON number it parsed, so an integer beyond 2^53 is signed as the double a JSON parser holds, not as its exact digits.

   Values ≥ `1e21` should not be sent.
3. **Field identity.** Every field is signed as the literal string transmitted. `issuedAt` may use any RFC 3339 rendering a verifier can parse, but the signed and transmitted renderings **must be byte-identical** — format the timestamp once, not twice with different code paths.

Fields are escaped for `\` and `|` before joining, so a literal pipe inside a field cannot shift the field boundaries.

A verifier *may* attach a non-normative `hint` to a `SIGNATURE_INVALID` verdict citing which of these three is the likely cause, but the hint must never enter digested decision content. The reference gate returns it as `data.hint`.

> **Protocol version note:** a client still signing the older 7-field message (no `resource`) will genuinely fail this check — but the gate can tell that apart from a broken or rotated key. A request that verifies against the old 7-field message gets `CLIENT_PROTOCOL_VERSION_UNSUPPORTED` instead of `SIGNATURE_INVALID`, so the fix is upgrading the client, not rotating a key that was never the problem. See [Reason Code Registry](https://docs.metamynd.ai/agent-protocol/reason-code-registry).

#### Conformance vectors

The specification defines **known-answer vectors** for the signed message ([MAGP §8.3.8](https://metamynd.ai/developers/spec)): for each case, the eight input fields, the exact message, and the Ed25519 signature a fixed public test key produces over it. Ed25519 is deterministic, so every implementation must reproduce the same bytes. The vectors cover the cases that have each broken a real client — an integral float (`150.0` → `150`), a fractional amount, a sub-cent amount (`0.00005`), the exponent forms (`1.5e-7`, `1e+21`), an integer beyond 2^53, an amount near `1e21`, an absent merchant and resource, `resource` alone, a literal `|` and `\` in a field, and non-ASCII text. The reference gate and the reference Python client both check themselves against the same vectors, so a message-format change in one place and not the other fails a test instead of shipping.

> **Debugging tip**: the Python client ([`metamynd-client`](https://pypi.org/project/metamynd-client/)) ships a `python -m metamynd_client --selftest` command that checks key encoding, number stringification and timestamp-shape parity with the reference implementation entirely offline — run it before assuming the backend is wrong.

#### Payload binding (optional)

The eight signed fields do not cover a payee, an account number, a passenger list, a route — every other field a real tool takes. An agent that wants the **whole** payload held to what it authorized also signs a digest of it, sent as two optional top-level request fields, **both or neither**:

```
payloadDigest    = "sha256:" + lower-case-hex( SHA-256( UTF-8( JCS(payload) ) ) )
payloadSignature = Ed25519( UTF-8( MAGP-PAYLOAD-v1 | agentDid | action | nonce | issuedAt | payloadDigest ) )
```

* `JCS` is RFC 8785 JSON Canonicalization: keys sorted by UTF-16 code unit, no insignificant whitespace, ECMAScript number and string serialisation (footgun 2 applies to every number in the payload). The digest is of the JSON the **executing side receives**.
* Refused, not normalised: `undefined`, `NaN`, `Infinity`, functions, BigInt, an unpaired surrogate, nesting deeper than 32 levels, and a payload larger than 256 KiB once canonical. Two languages would normalise these differently, and a digest they compute differently is a binding that silently never matches.
* These are **not** a ninth signed field. The eight-field message is unchanged, and a request carrying neither field is exactly what it always was. The `MAGP-PAYLOAD-v1` message is domain-separated from the authorize message and from the service messages, and it names the agent, action, nonce and `issuedAt` of this request, so a digest cannot be lifted onto another authorization.
* The gate verifies the binding **immediately after the main signature** (check 5). A digest without a signature, a signature without a digest, a malformed digest, or a signature that does not verify is `PAYLOAD_BINDING_INVALID`. If the owner set `requirePayloadBinding` on the mandate and the request carries no binding, it is `PAYLOAD_BINDING_REQUIRED` — checked after the signature, so only the agent learns the setting.
* **Acknowledgement.** An `allow`, `observe` or `escalate` verdict for a request that carried a binding states the digest the authorization is bound to in `data.payloadDigest` (outside the digested decision content; `null` for an unbound one). An agent that sent a digest **must** treat a permit whose `payloadDigest` is not the one it sent — including an absent field — as **not bound**: refuse it (`PAYLOAD_BINDING_NOT_CONFIRMED`) and release the hold. That makes a proxy that strips the fields, or an issuer that predates payload binding, a loud failure.

The comparison that gives the binding its force happens later, at the **claim**: the executor states the digest of what it is about to run, and the issuer refuses a claim whose digest differs from the stored one. See [Payload Binding](https://docs.metamynd.ai/core-concepts/payload-binding) and [Settlement & Settlement Evidence](https://docs.metamynd.ai/agent-protocol/settlement-and-settlement-evidence).

SDK support: `@metamynd/agentsafe-guard` — pass `payload` to `authorize()` / `buildSignedRequest()` (or return it from `guardTool`'s `mapArgs`); Python `metamynd-client` — see the [Python client](https://docs.metamynd.ai/sdks/metamynd-client-python) page.

#### Late binding (a hold that already exists)

A reviewer's **MODIFY** decision changes the action the agent signed, so the hold minted for the modified action carries **no** digest. The agent binds the payload of the action that will actually run with:

```
POST /policy/mandate/authorize/{authorizationId}/payload-binding
{ "agentDid", "action", "nonce", "issuedAt", "payloadDigest", "payloadSignature" }

payloadSignature = Ed25519( UTF-8( MAGP-PAYLOAD-REBIND-v1 | agentDid | action | authorizationId | nonce | issuedAt | payloadDigest ) )
```

The endpoint is public — the agent's signature is the credential — and IP rate-limited. The gate checks the signature **before** it says anything about the hold, then containment, then that the hold is this agent's and this action's, then freshness and the nonce. It applies the digest with one conditional update, only while the hold is live, unclaimed and carries no digest; a digest is never overwritten.

| Refusal                                                                            | HTTP | Meaning                                                                 |
| ---------------------------------------------------------------------------------- | ---- | ----------------------------------------------------------------------- |
| `AUTHORIZATION_NOT_FOUND`                                                          | 404  | no such hold                                                            |
| `AUTHORIZATION_AGENT_MISMATCH` · `AUTHORIZATION_ACTION_MISMATCH`                   | 403  | the hold is another agent's, or for another action                      |
| `PAYLOAD_BINDING_INVALID`                                                          | 403  | malformed digest, unresolvable key, or a signature that does not verify |
| `AGENT_SUSPENDED` · `AGENT_QUARANTINED` · `AGENT_DECOMMISSIONED`                   | 403  | the agent is contained                                                  |
| `REQUEST_EXPIRED`                                                                  | 403  | `issuedAt` outside the freshness window                                 |
| `REPLAY_DETECTED`                                                                  | 409  | the nonce was already used                                              |
| `RATE_LIMIT_EXCEEDED`                                                              | 429  | the agent's own rate window (when enabled)                              |
| `PAYLOAD_ALREADY_BOUND`                                                            | 409  | the hold already carries a **different** digest                         |
| `AUTHORIZATION_ALREADY_CLAIMED` · `AUTHORIZATION_VOIDED` · `AUTHORIZATION_EXPIRED` | 409  | the hold is no longer unclaimed and live                                |

The same digest already on the hold is an idempotent success (`200`, `alreadyBound: true`). A success echoes the digest in `data.payloadDigest`; an agent must treat a success that does not echo its digest as not bound. SDK helpers: `guard.bindPayload({ authorizationId, action, payload })` (agentsafe-guard) and `client.bind_payload(authorization_id, action, payload)` (Python).

#### Envelope signature (optional)

An agent may also sign the **GovernanceEnvelope hash** — a canonical hash over the whole request, context included — and send it as `envelopeSignature`. It binds the agent's key to the *context* it submitted, not just the eight signed fields. The gate checks it right after the main signature; a signature that does not verify is `CONTEXT_SIGNATURE_INVALID`. Absent, behaviour is unchanged. The verdict returns `envelopeId` and `envelopeHash` so a caller can bind a decision to the exact action submitted.

#### Service (counterparty) signature

The service that **executes** an authorized action — an MCP server, an HTTP gateway, an A2A agent — should prove who it is on every settlement call instead of relying on a bearer claim token. It signs with a `did:key` or `did:hedera` identity it controls:

```
MAGP-SERVICE-v1 | action | authorizationId | field… | nonce | issuedAt
```

carried in four headers:

```
x-magp-service-did:        did:key:z6Mk…      (the key must be the one the DID commits to)
x-magp-service-nonce:      <8–128 chars, single-use>
x-magp-service-issued-at:  <RFC 3339; at most 5 minutes old, at most 30 s in the future>
x-magp-service-signature:  <hex Ed25519>
```

| Call                                | `action`     | Signed fields (in order)                                                                                             |
| ----------------------------------- | ------------ | -------------------------------------------------------------------------------------------------------------------- |
| Claim — `POST …/effect/dispatching` | `claim`      | the `Idempotency-Key` header value when one is sent, then `payload=<digest>` when an `x-magp-payload-digest` is sent |
| `POST …/effect/dispatched`          | `dispatched` | `remoteRef`                                                                                                          |
| `POST …/effect/unknown`             | `unknown`    | `reason`                                                                                                             |
| `POST …/capture`                    | `capture`    | `amountCharged` (stringified as in footgun 2), `bookingRef`, `settlementTxHash`                                      |
| `POST …/void`                       | `void`       | `reason`                                                                                                             |
| `POST …/refund`                     | `refund`     | `amount` (stringified as in footgun 2; the empty string for a full refund), `reason` (empty string when absent)      |
| `POST …/effect/reconcile`           | `reconcile`  | *(none)*                                                                                                             |

An absent field is signed as the empty string, and every field is escaped for `\` and `|`. The body fields **`payTo`**, **`claimToken`** and **`x402`** are **not** signed fields. `payTo` is only ever read after the caller has already proven it is the claimer; see [Settlement & Settlement Evidence](https://docs.metamynd.ai/agent-protocol/settlement-and-settlement-evidence).

The gate checks the signature against the key the DID itself commits to, rejects a stale or future `issuedAt`, and consumes the nonce once. A malformed, unsupported, expired, replayed or badly signed identity is refused with HTTP `401` and a `COUNTERPARTY_*` code (`COUNTERPARTY_AUTH_MALFORMED`, `COUNTERPARTY_DID_UNSUPPORTED`, `COUNTERPARTY_REQUEST_EXPIRED`, `COUNTERPARTY_SIGNATURE_INVALID`, `COUNTERPARTY_REPLAY_DETECTED`) — it is never downgraded to an anonymous call. The identity that signs the claim is recorded as the **claimer**; only that identity may later settle the hold lower, release it, or mark it unknown, and no claim token is issued to it. Whether that identity may claim at all is the owner's decision: see [Trusted Counterparties & Payee Directory](https://docs.metamynd.ai/core-concepts/trusted-counterparties-and-payee-directory).

SDK support: `@metamynd/agentsafe-mcp-guard`, `@metamynd/agentsafe-a2a-guard` and `@metamynd/agentsafe-http-gateway` sign these calls when given a `serviceDid` plus a signing key.

Full normative text: [MAGP §8.3 and §8.7.6](https://metamynd.ai/developers/spec).


---

# 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.metamynd.ai/agent-controls-agentsafe/request-signing-and-message-format.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.
