View as Markdown

Mandate · Guide

Bind a grant to its holder

Use this when a grant leaves your hands: you pass it to an agent you don't run, or to one whose tokens could be logged or forwarded. A plain grant token works for whoever holds a copy. A bound grant names one key, and works only for the agent that holds that key.

The grant carries the key's thumbprint as cnf.jkt (RFC 7800). The agent signs a short DPoP proof (RFC 9449) for each request with that key. Provenance's API, POST /v1/verify and the offline verifiers in TypeScript, Python and Go all check the proof. Binding is free on every plan.

Before you begin: the agent that will hold the grant needs a P-256 key pair. generateHolderKey in @provenanceauth/rails/mandates makes one; keep the private key with the agent and send only the public key.

1. Make the holder's key

The agent makes its key once and gives you the public half:

import { generateHolderKey } from "@provenanceauth/rails/mandates";

const holder = await generateHolderKey();
// holder.publicJwk goes to whoever grants; holder.privateJwk stays with the agent.

2. Grant with holder_key

Pass the public key as holder_key on POST /v1/mandate/grants, or on a delegation (POST /v1/mandate/grants/{id}/delegate) to bind a child to its own holder:

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": "Hold a seat on the Lisbon flight", "constraints": { "max_amount": 300, "expires_at": "2027-12-31T23:59:59Z" }, "holder_key": { "kty": "EC", "crv": "P-256", "x": "NeVHu4qeD40iEEgSDcTm26Y0xApkjq41T6BuENVl0js", "y": "qS59-GAPcl0bJ-yYFvPJA3omsU9DJFedMw4rou5cXo8" } }'

The grant names the key's thumbprint in holder_jkt, and its mandate_token carries the same value as cnf.jkt. Only the thumbprint is stored. A grant without holder_key is a bearer grant: it works for whoever holds the token.

3. Sign a proof for each request

The agent signs one proof per request, naming the method, the URL, the time and the grant token, and sends it in the DPoP header:

import { signHolderProof } from "@provenanceauth/rails/mandates";

const url = "https://api.provenanceauth.com/v1/mandate/intents";
const dpop = await signHolderProof(holder.privateJwk, { method: "POST", url, token: mandateToken });
await provenance.mandate.intents.create({ actionDescription: "Hold seat 14C", agentSessionId, deviceId, mandateToken }, { dpop });

A proof is good for one request and 60 seconds. Sign a new one for every call, retries included. When a request names the grant by id (grant_id on a deal or a tab), sign the proof without token.

4. Check the proof where you receive the grant

An agent or a store that receives a bound grant checks the proof that came with it. Pass the DPoP header and the request it came on:

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

const seen = new Map<string, number>();
const r = await verifyMandate(mandateToken, {
  jwks,
  need: { amount: 120, action_type: "purchase" },
  holder: {
    proof: req.headers.get("dpop") ?? "",
    method: req.method,
    url: req.url,
    seen: (jti, until) => (seen.has(jti) ? false : (seen.set(jti, until), true)),
  },
});
if (!r.valid) throw new Error(`Not authorized: ${r.reason}`);

seen records each proof's jti until its window closes, so a proof can't be replayed. Without a store of your own, check online: pass the proof and its request as presenter to POST /v1/verify, which records the jti for you. A checkout assessment reads the proof from the DPoP header in the request you forward.

The result's holder_bound and holder_jkt say whether the grant names a key. A bearer grant passes with no proof.

ReasonWhat it means
dpop_proof_requiredThe grant is bound and no proof came with it. Treat the token as a copy.
dpop_proof_invalidThe proof doesn't check: wrong typ or algorithm, a bad signature, another method or URL, an iat more than 60 seconds off, or an ath for another token.
dpop_proof_replayedThe proof was already used.
holder_mismatchThe proof is signed by another key than the one the grant names.

Errors you might see

CodeWhat to do
dpop_proof_requiredSend the proof in the DPoP header with every request that uses the grant.
dpop_proof_invalidSign the proof for this exact request: htm the method, htu the URL without its query, iat now, ath the grant token's hash.
dpop_proof_replayedSign a new proof with a fresh jti.
holder_mismatchSign with the private key whose public key was given as holder_key.
invalid_field_value (holder_key)Send a P-256 public key as a JWK, without d.

See also