View as Markdown

Mandate · Guide

Check an agent's grant

Use this when another agent asks yours to do something on someone's behalf: quote a price, book a slot, run a task. The asking agent sends its grant token. You check the signature against Provenance's published keys, check that the request fits the grant's limits, and, for anything that matters, ask Provenance whether the grant or anything above it has been revoked since the token was signed.

Before you begin: cache Provenance's JWKS (GET /.well-known/jwks.json, see verify tokens offline). The check is free and needs no API key.

1. Ask for the grant token

Ask the agent to send the mandate_token it was given, in your protocol's request or a header of your choosing. A subagent's token carries its whole chain: the grant ids from the person's down, the registered agents holding each level, and each level's purpose.

2. Check it offline

verifyMandate checks the signature and expiry, and that what you were asked to do (need) fits the limits:

import { fetchJwks } from "@provenanceauth/sdk";
import { verifyMandate } from "@provenanceauth/rails/mandates";

const jwks = await fetchJwks(process.env.PROVENANCE_API!);
const r = await verifyMandate(mandateToken, {
  jwks,
  need: { amount: 25, action_type: "quote", counterparty: "paper.example" },
});
if (!r.valid) throw new Error(`Not authorized: ${r.reason}`);

The result says:

FieldWhat it is
root_subjectWho granted the root: a pairwise subject, never a name or an email.
chainEach level from the person's grant down, with the registered agent ({ id, name }, or null) and its purpose.
depth, parentHow far below the person's grant this one is, and the grant it was delegated from.
purpose, root_purposeWhat this agent is working on, and the person's task.
authorityThe limits as values: max_amount, budget_amount, budget_window, allowed_action_types, allowed_counterparties, expires_at.

A refusal carries a reason:

ReasonWhat it means
token_invalid, token_expiredThe signature doesn't verify against the JWKS, or the token expired.
not_a_mandateIt's another kind of token.
amount_over_max, action_type_not_allowed, counterparty_not_allowedThe request is outside the grant's limits.
grant_expiredThe grant's own expiry passed.

3. Check its status online

A token is a snapshot. Revoking a grant revokes everything delegated below it, so for anything that costs money or can't be undone, add online: true. It calls the keyless GET /v1/public/grants/{id}/status:

curl -s $PROVENANCE_API/v1/mandate/grants \
  -H "Authorization: Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5" \
  -H "Content-Type: application/json" \
  -d '{ "device_id": "dev_00000000000000000000000000000001", "purpose": "Restock printer paper", "constraints": { "max_amount": 80, "expires_at": "2027-12-31T23:59:59Z" } }' | tee m.json
curl -s $PROVENANCE_API/v1/public/grants/$(jq -r .id m.json)/status
{
  "object": "grant_status",
  "status": "active"
}

The status is active, suspended (a missed check-in), revoked or expired. When a grant above it stops it, stopped_by names that grant. Nothing else is returned: no limits, spend, account or agent. A status call that fails returns status_unavailable, never a pass. The endpoint allows 300 checks a minute per IP.

Budget left isn't part of either check. The person's grant and every level debit at verify, on the asking agent's side.

Errors you might see

CodeWhat to do
resource_missingNo such grant. verifyMandate reads a 404 as grant_revoked.
rate_limit_exceededWait and retry, or cache an active answer for a few seconds.

See also