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}`);
from provenanceauth_verify import fetch_jwks
from provenanceauth_verify.mandates import verify_mandate
jwks = fetch_jwks(os.environ["PROVENANCE_API"])
r = verify_mandate(mandate_token, jwks, need={"amount": 25, "action_type": "quote", "counterparty": "paper.example"})
if not r.valid:
raise PermissionError(r.reason)
r := provenanceverify.VerifyMandate(mandateToken, jwks, &provenanceverify.MandateNeed{Amount: &amount, ActionType: &actionType}, 0)
if !r.Valid {
return fmt.Errorf("not authorized: %s", r.Reason)
}
The result says:
| Field | What it is |
|---|---|
root_ | Who granted the root: a pairwise subject, never a name or an email. |
chain | Each level from the person's grant down, with the registered agent ({ id, name }, or null) and its purpose. |
depth, parent | How far below the person's grant this one is, and the grant it was delegated from. |
purpose, root_ | What this agent is working on, and the person's task. |
authority | The limits as values: max_, budget_, budget_, allowed_, allowed_, expires_. |
A refusal carries a reason:
| Reason | What it means |
|---|---|
token_, token_ | The signature doesn't verify against the JWKS, or the token expired. |
not_ | It's another kind of token. |
amount_, action_, counterparty_ | The request is outside the grant's limits. |
grant_ | The 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 /:
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
const r = await verifyMandate(mandateToken, { jwks, need, online: true, apiBase: process.env.PROVENANCE_API });
r = verify_mandate(mandate_token, jwks, need=need, online=True, api_base=os.environ["PROVENANCE_API"])
{
"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
| Code | What to do |
|---|---|
resource_ | No such grant. verifyMandate reads a 404 as grant_. |
rate_ | Wait and retry, or cache an active answer for a few seconds. |