Skip to main content
Wire-format adapter between Glide’s internal grant model and the Agent Payments Protocol (AP2), a three-mandate Verifiable Digital Credential (VDC) framework co-authored by Google with 60+ endorsing partners including AmEx, Mastercard, PayPal, Adyen, Coinbase, and Shopify. The three mandate types are IntentMandate (user authorizes agent), CartMandate (agent proposes a basket), and PaymentMandate (user instructs settlement). This package is a wire-format adapter, not a re-implementation of the AP2 spec. When AP2 ships v0.2 or any breaking wire change, a new minor is published, AP2_SPEC_VERSION is bumped in the same PR, and the round-trip property tests are re-run. The @glideco/schemas AgentPolicyEnvelope (14-axis) is a strict superset of what AP2 0.1 can express; axes that have no AP2 vocabulary are preserved under the glide: extension namespace.

Install

npmjs.com/package/@glideco/ap2-adapter

Why a thin encoder rather than a native AP2 library?

Glide’s agent_grants + AgentPolicyEnvelope predates AP2 and covers counterparty allowlists, velocity multipliers, per-tx step-up thresholds, and MCC blocklists that AP2 0.1 has no vocabulary for. Rewriting around AP2 primitives would lose that expressiveness. Instead the encoder is deliberately lossy at the AP2 layer: standard axes map 1:1, and extended axes flow into the glide:policyEnvelope extension field. A vanilla AP2 verifier validates the core mandate; a Glide verifier round-trips losslessly. The decoders go the other direction: when a third-party agent (Google Sidekick, an Adyen orchestrator) presents an inbound AP2 IntentMandate, decodeIntentMandate parses and validates it. Proof verification is not performed here — that is the caller’s responsibility via @glideco/kms-signer or a generic JWS library.

Spec version

Pinned to AP2 v0.1-alpha — exported as AP2_SPEC_VERSION = '0.1-alpha'. The AP2 JSON-LD @context URL is https://agent-payments.googleapis.com/2025/v1/credentials.jsonld. Using a wrong context URL means every mandate term (allowedMerchantCategories, spendingLimit, etc.) resolves to undefined in a JSON-LD verifier — the credential becomes effectively unparseable.

API surface

Encoding a Glide grant as an IntentMandate

The encoder picks the tightest spending cap (per-charge beats per-day beats lifetime) for AP2’s single spendingLimit slot and stashes the full envelope under glide:policyEnvelope for lossless round-trip on Glide verifiers.

Encoding a cart + payment mandate

Validating an inbound mandate chain

Common pitfalls

Currency case. AP2 0.1 requires ISO 4217 uppercase. The schemas enforce this via regex (/^[A-Z]{3}$/). Lowercase 'usd' throws at parse time. Amount format. All amount fields are decimal strings — no floats, no thousand separators, no exponential notation. The regex is /^-?\d+(\.\d{1,4})?$/. Passing a JavaScript number throws. Proof block. All three encoders return a VDC with proof omitted. Do not transmit the mandate without attaching a proof — receiving verifiers will reject unsigned credentials.

Reading list