@atlasauth/pca-ap2 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,69 @@
1
- # Temporary Holding Version
1
+ # @atlasauth/pca-ap2
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ AP2 (Agent Payments Protocol) wire-compatibility for PCA. AP2 — donated to the FIDO Alliance, v0.2 shape (2026-04-28) — models agentic payments as a chain of signed Verifiable Digital Credentials: **IntentMandate → CartMandate → PaymentMandate**. That chain is a near-isomorphism of PCA's attenuating capability chain, so this package bridges the two.
4
+
5
+ **PCA governs. AP2 is the payment-mandate wire. x402 / Stripe Shared Payment Tokens settle. Compose them.**
6
+
7
+ - **PCA** (`@atlasauth/pca`, `@atlasauth/pca-payments`) = the authority / budget layer: who may spend, how much, until when, and when a human must co-sign.
8
+ - **AP2** = the Intent→Cart→Payment VDC chain other parties verify.
9
+ - **x402 / Stripe SPT** = the settlement rails that actually move value, fed by PCA's governance.
10
+
11
+ This is a bridge, not a replacement.
12
+
13
+ ## ⚠️ Verify against the AP2 schemas before production
14
+
15
+ AP2 is a moving target and its mandate field-level signing roles differ between secondary sources (e.g. whether a cart is co-signed by both merchant and user, and whether the step is called "Cart" or "Checkout"), and it layers over UCP (`ucp.dev`), whose dated releases move the payment token between `payment_data.token` and `payment.instruments[*].credential.token`. This package models the v0.2 Intent/Cart/Payment chain **to the best public understanding** and **must be validated against the AP2 repository `schemas/` and the official spec at [ap2-protocol.org](https://ap2-protocol.org) before any production wire use.** PCA-native terms that AP2 has no field for are carried in a namespaced `x_pca` extension (so the chain round-trips back to PCA terms); those fields are non-standard by construction.
16
+
17
+ ## Usage
18
+
19
+ ```ts
20
+ import { buildPaymentMandate, authorizeCharge } from '@atlasauth/pca-payments';
21
+ import {
22
+ toAP2IntentMandate, toAP2CartMandate, toAP2PaymentMandate,
23
+ chainMandates, fromAP2Mandate, x402Settlement, stripeSptSettlement,
24
+ } from '@atlasauth/pca-ap2';
25
+
26
+ // 1. A PCA payment mandate (the authority layer).
27
+ const mandate = buildPaymentMandate({
28
+ principalSecret, principalPublic, agentPublic,
29
+ merchants: ['acme'], currency: 'USD',
30
+ perTransactionCap: 500, autoApproveThreshold: 50, cumulativeCap: 1000,
31
+ });
32
+
33
+ // 2. Map it down the AP2 VDC chain (each step narrows, never amplifies).
34
+ const intent = toAP2IntentMandate(mandate, { issuerPublic, issuerSecret }); // user signs
35
+ const cart = toAP2CartMandate(intent,
36
+ { merchant: 'acme', items: [{ name: 'Seat', quantity: 1, unit_price: { currency: 'USD', value: 120 } }] },
37
+ { issuerPublic: merchantPublic, issuerSecret: merchantSecret }); // merchant signs
38
+
39
+ // The human-present signal maps from the PCA decision: tier-3 human step-up ⇒ human_present = true.
40
+ const decision = authorizeCharge(mandate, { merchant: 'acme', amount: 120, currency: 'USD' });
41
+ const payment = toAP2PaymentMandate(cart, {
42
+ issuerPublic: payerPublic, issuerSecret: payerSecret,
43
+ paymentMethod: { type: 'card' }, pcaTier: decision.t, intent,
44
+ });
45
+
46
+ // 3. Assemble + verify the chain is a non-amplifying narrowing (mirrors PCA attenuation).
47
+ const chain = chainMandates(intent, cart, payment);
48
+ chain.verify(); // { ok: true, reasons: [] }
49
+
50
+ // 4. Parse back toward PCA terms.
51
+ fromAP2Mandate(intent); // { type: 'IntentMandate', merchants: ['acme'], perTransactionCap: 500, ... }
52
+
53
+ // 5. Hand the verified payment mandate to a settlement rail (structural; no network here).
54
+ x402Settlement.settle(payment, { resourceUrl, payTo, network: 'base' });
55
+ stripeSptSettlement.settle(payment, { payTo: 'acct_merchant' });
56
+ ```
57
+
58
+ ### Human-present mapping
59
+
60
+ | PCA decision | AP2 `human_present` |
61
+ | --------------------------------------------- | ------------------- |
62
+ | tier 1 — autonomous (amount ≤ Y, budget OK) | `false` (human-not-present) |
63
+ | tier 3 — human step-up / co-sign required | `true` (human-present) |
64
+
65
+ ### Settlement backends
66
+
67
+ `x402Settlement` and `stripeSptSettlement` implement `SettlementBackend` and are **structural only** — they turn a (presumed-verified) Payment Mandate into the rail's wire shape (x402's HTTP-402 challenge + `X-PAYMENT` header; Stripe's Shared-Payment-Token charge in minor units). They perform no network I/O; they are the hooks a real integration fills in, fed by PCA's governance decision.
68
+
69
+ Part of Proof-Carrying Authority — see `@atlasauth/pca`.
@@ -0,0 +1,317 @@
1
+ /**
2
+ * @atlasauth/pca-ap2 — AP2 (Agent Payments Protocol) wire-compatibility for PCA.
3
+ *
4
+ * ┌──────────────────────────────────────────────────────────────────────────────────────────────┐
5
+ * │ PCA GOVERNS. AP2 is the payment-MANDATE wire. x402 / Stripe Shared-Payment-Tokens SETTLE. │
6
+ * └──────────────────────────────────────────────────────────────────────────────────────────────┘
7
+ *
8
+ * AP2 (donated to the FIDO Alliance, v0.2 shape, 2026-04-28) standardizes agentic payments as a chain
9
+ * of signed Verifiable Digital Credentials (VDCs):
10
+ *
11
+ * IntentMandate → CartMandate → PaymentMandate
12
+ * (the user's (the merchant's (the payment authorization +
13
+ * goal + caps) concrete cart) human-present / not-present signal)
14
+ *
15
+ * This is a near-isomorphism of PCA's attenuating capability chain: the Root Intent Grant bounds the
16
+ * authority; each narrowing step may only RESTRICT it, never amplify it. PCA's trust-budget + risk
17
+ * policy (`@atlasauth/pca-payments`) decide WHETHER a charge is autonomous (tier 1) or needs a human
18
+ * co-sign (tier 3); AP2 carries that decision on the wire; the settlement rail moves the money.
19
+ *
20
+ * This is a BRIDGE, not a replacement:
21
+ * - PCA = the authority / budget layer (who may spend, how much, until when, before a human co-sign).
22
+ * - AP2 = the payment-mandate wire (the Intent→Cart→Payment VDC chain other parties verify).
23
+ * - x402 / Stripe SPT = the settlement rails that actually move value, fed by PCA's governance.
24
+ * Compose them; do not fold one into another.
25
+ *
26
+ * ────────────────────────────────────────────────────────────────────────────────────────────────
27
+ * HONEST CAVEAT — VERIFY BEFORE PRODUCTION WIRE USE
28
+ * ────────────────────────────────────────────────────────────────────────────────────────────────
29
+ * AP2 is a moving target and its mandate field-level signing roles differ between secondary sources
30
+ * (e.g. whether a cart is co-signed by both merchant and user, and whether the step is called "Cart"
31
+ * or "Checkout"). The spec also layers over UCP (ucp.dev) whose dated releases move the payment token
32
+ * between `payment_data.token` and `payment.instruments[*].credential.token`. This module models the
33
+ * v0.2 Intent/Cart/Payment chain to the best public understanding; it MUST be validated against the
34
+ * AP2 repository `schemas/` (and the official spec at ap2-protocol.org) before any production wire use.
35
+ * PCA-native terms that AP2 has no field for are carried in a namespaced `x_pca` extension so the chain
36
+ * can round-trip back to PCA terms; those fields are non-standard by construction.
37
+ */
38
+ import type { MandateTerms, PaymentMandate as PcaPaymentMandate } from '@atlasauth/pca-payments';
39
+ /** The AP2 shape this module models. See the HONEST CAVEAT above. */
40
+ export declare const AP2_VERSION: "0.2";
41
+ /**
42
+ * Illustrative JSON-LD contexts for the VDC envelope. The second entry is a placeholder for the AP2
43
+ * context URL — replace with the canonical context from the AP2 repo before production.
44
+ */
45
+ export declare const AP2_CONTEXT: readonly string[];
46
+ /** ISO-4217 currency + decimal value (use minor units in production to avoid float drift). */
47
+ export interface MonetaryAmount {
48
+ currency: string;
49
+ value: number;
50
+ }
51
+ export type AP2MandateType = 'IntentMandate' | 'CartMandate' | 'PaymentMandate';
52
+ /**
53
+ * A detached signature over the canonicalized credential body (everything except `proof`). Structural
54
+ * analogue of a JWS / Data-Integrity proof; signed with the issuer's Ed25519 key (PCA's own `sign`).
55
+ */
56
+ export interface AP2Proof {
57
+ type: 'Ed25519Signature2020';
58
+ /** ISO timestamp the proof was created. */
59
+ created: string;
60
+ /** The issuer public key (b64u) the signature verifies under; equals the VDC `issuer`. */
61
+ verificationMethod: string;
62
+ proofPurpose: 'assertionMethod';
63
+ /** b64u Ed25519 signature over `canonicalBytes(<credential without proof>)`. */
64
+ signatureValue: string;
65
+ }
66
+ /** A signed (or signable) Verifiable Digital Credential carrying one AP2 mandate. */
67
+ export interface VerifiableDigitalCredential<T extends AP2MandateType, S> {
68
+ '@context': readonly string[];
69
+ type: readonly ['VerifiableCredential', T];
70
+ /** Issuer public key (b64u). Intent: the user/principal. Cart: the merchant. Payment: the payer. */
71
+ issuer: string;
72
+ /** ISO issuance time. */
73
+ issuanceDate: string;
74
+ /** ISO expiry, when the mandate names one. */
75
+ expirationDate?: string;
76
+ credentialSubject: S;
77
+ /** Present once signed (see {@link signMandate}). */
78
+ proof?: AP2Proof;
79
+ }
80
+ /**
81
+ * PCA-native extension carried inside an Intent Mandate so the VDC chain can round-trip back to the
82
+ * attenuating PCA terms AP2 has no standard field for. NON-STANDARD by construction (namespaced).
83
+ */
84
+ export interface PcaIntentExtension {
85
+ /** Y — at/under ⇒ autonomous (human_present can be false); over ⇒ human co-sign (tier 3). */
86
+ auto_approve_threshold: number;
87
+ /** bMax — total autonomous spend between human co-signs. */
88
+ cumulative_cap: number;
89
+ /** X — hard per-transaction ceiling (mirrors `max_amount.value`). */
90
+ per_transaction_cap: number;
91
+ period_start?: number;
92
+ period_end?: number;
93
+ max_transactions_per_period?: number;
94
+ /** The PCA grant's salted goal commitment, if the source was a full PaymentMandate. */
95
+ goal_commit?: string;
96
+ }
97
+ /** IntentMandate: the user's natural-language/structured intent + the constraints the agent must obey. */
98
+ export interface IntentMandateContents {
99
+ natural_language_description: string;
100
+ /** Allowlisted merchant ids; `null` = any merchant (AP2 uses null for "unconstrained"). */
101
+ merchants: string[] | null;
102
+ /** Allowlisted SKUs; `null` = any. */
103
+ skus: string[] | null;
104
+ /** Allowlisted MCC categories; omitted = any. */
105
+ categories?: string[];
106
+ /** The ceiling a single purchase under this intent may reach (PCA's hard per-transaction cap X). */
107
+ max_amount: MonetaryAmount;
108
+ /** Whether purchases must be refundable/bonded (PCA mints charges in the `reversible` class ⇒ true). */
109
+ required_refundability: boolean;
110
+ /** Whether the user must confirm the concrete cart before payment (maps from PCA Y < X). */
111
+ user_cart_confirmation_required: boolean;
112
+ /** ISO expiry of the intent, if any. */
113
+ intent_expiry?: string;
114
+ /** PCA-native round-trip extension (non-standard). */
115
+ x_pca?: PcaIntentExtension;
116
+ }
117
+ /** A concrete line item the merchant commits to in a cart. */
118
+ export interface CartItem {
119
+ sku?: string;
120
+ name: string;
121
+ quantity: number;
122
+ unit_price: MonetaryAmount;
123
+ }
124
+ /** CartMandate: the concrete items/amounts the merchant commits, bound to the intent it fulfils. */
125
+ export interface CartMandateContents {
126
+ /** Stable cart id. */
127
+ id: string;
128
+ /** The merchant this cart is with (matched against the intent allowlist). */
129
+ merchant: string;
130
+ items: CartItem[];
131
+ /** The committed total (Σ quantity · unit_price). */
132
+ total: MonetaryAmount;
133
+ /** Hash of the IntentMandate VDC this cart fulfils — binds cart → intent. */
134
+ intent_reference?: string;
135
+ /** ISO expiry of the cart quote, if any. */
136
+ cart_expiry?: string;
137
+ }
138
+ /** The payment instrument a payment mandate authorizes. */
139
+ export interface PaymentMethod {
140
+ /** e.g. `card`, `crypto`, `shared_payment_token`, `x402`. */
141
+ type: string;
142
+ display?: string;
143
+ /** Opaque token (e.g. a Stripe Shared Payment Token id); never a raw PAN. */
144
+ token?: string;
145
+ }
146
+ /**
147
+ * PaymentMandate: the minimal payment authorization derived from the cart. Carries the human-present /
148
+ * human-not-present modality signal and binds to the cart (and intent) by hash — WITHOUT re-exposing
149
+ * the full cart contents.
150
+ */
151
+ export interface PaymentMandateContents {
152
+ /** Hash of the CartMandate VDC — binds payment → cart. */
153
+ cart_hash: string;
154
+ /** Hash of the IntentMandate VDC — binds payment → intent (optional but recommended). */
155
+ intent_hash?: string;
156
+ amount: MonetaryAmount;
157
+ payment_method: PaymentMethod;
158
+ /**
159
+ * The AP2 modality signal. MAPPING: PCA tier-3 human step-up ⇒ `human_present = true`; a tier-1
160
+ * autonomous charge (amount ≤ Y, budget available) ⇒ `human_present = false` (human-not-present).
161
+ */
162
+ human_present: boolean;
163
+ merchant?: string;
164
+ }
165
+ export type IntentMandate = VerifiableDigitalCredential<'IntentMandate', IntentMandateContents>;
166
+ export type CartMandate = VerifiableDigitalCredential<'CartMandate', CartMandateContents>;
167
+ /** AP2's Payment Mandate VDC (NOT the PCA `PaymentMandate` grant from `@atlasauth/pca-payments`). */
168
+ export type PaymentMandate = VerifiableDigitalCredential<'PaymentMandate', PaymentMandateContents>;
169
+ export type AnyAP2Mandate = IntentMandate | CartMandate | PaymentMandate;
170
+ /** Sign a VDC with the issuer's Ed25519 secret key, returning a copy carrying the `proof`. */
171
+ export declare function signMandate<T extends AP2MandateType, S>(vdc: VerifiableDigitalCredential<T, S>, secretKey: Uint8Array): VerifiableDigitalCredential<T, S>;
172
+ /** Verify a VDC's detached signature. Returns false when unsigned or the signature does not verify. */
173
+ export declare function verifyMandate(vdc: AnyAP2Mandate): boolean;
174
+ /** Stable content hash of a VDC (used to bind one mandate to the next). */
175
+ export declare function mandateHash(vdc: AnyAP2Mandate): string;
176
+ export interface IntentMapOptions {
177
+ /** Issuer (user/principal) public key, b64u. */
178
+ issuerPublic: string;
179
+ /** If present, the Intent VDC is signed with this Ed25519 secret key. */
180
+ issuerSecret?: Uint8Array;
181
+ /** Override the natural-language description (else derived from the terms). */
182
+ naturalLanguageDescription?: string;
183
+ /** Allowlisted SKUs, or null for any (default null). */
184
+ skus?: string[] | null;
185
+ /** Override `user_cart_confirmation_required` (default: Y < X ⇒ true). */
186
+ userCartConfirmationRequired?: boolean;
187
+ /** Issuance clock (ms). Default `Date.now()`. */
188
+ now?: number;
189
+ }
190
+ /** Map a PCA payment mandate (or raw terms) to an AP2 Intent Mandate VDC. */
191
+ export declare function toAP2IntentMandate(mandate: PcaPaymentMandate | MandateTerms, opts: IntentMapOptions): IntentMandate;
192
+ export interface CartInput {
193
+ merchant: string;
194
+ items: CartItem[];
195
+ /** Currency; defaults to the intent's `max_amount.currency`. */
196
+ currency?: string;
197
+ /** Stable cart id; derived from the item digest when omitted. */
198
+ id?: string;
199
+ /** Cart-quote expiry (ms). */
200
+ expiry?: number;
201
+ now?: number;
202
+ }
203
+ export interface CartMapOptions {
204
+ /** Issuer (merchant) public key, b64u. */
205
+ issuerPublic: string;
206
+ /** If present, the Cart VDC is signed with this Ed25519 secret key. */
207
+ issuerSecret?: Uint8Array;
208
+ }
209
+ /** Narrow an Intent Mandate into a concrete AP2 Cart Mandate VDC (items + committed total). */
210
+ export declare function toAP2CartMandate(intent: IntentMandate, cart: CartInput, opts: CartMapOptions): CartMandate;
211
+ export interface PaymentMapOptions {
212
+ /** Issuer (payer/user agent) public key, b64u. */
213
+ issuerPublic: string;
214
+ /** If present, the Payment VDC is signed with this Ed25519 secret key. */
215
+ issuerSecret?: Uint8Array;
216
+ paymentMethod: PaymentMethod;
217
+ /** Amount to authorize; defaults to the cart total (and must not exceed it to stay a narrowing). */
218
+ amount?: MonetaryAmount;
219
+ /**
220
+ * The human-present modality. If omitted, derived from `pcaTier` (tier 3 ⇒ true); if that is also
221
+ * omitted, defaults to `false` (human-not-present).
222
+ */
223
+ humanPresent?: boolean;
224
+ /** PCA required-threshold tier for this charge (1 autonomous … 3 human co-sign). */
225
+ pcaTier?: number;
226
+ /** The Intent Mandate, if available — lets the payment also bind to the intent by hash. */
227
+ intent?: IntentMandate;
228
+ now?: number;
229
+ }
230
+ /** Narrow a Cart Mandate into an AP2 Payment Mandate VDC (the payment authorization + modality). */
231
+ export declare function toAP2PaymentMandate(cart: CartMandate, opts: PaymentMapOptions): PaymentMandate;
232
+ /** The PCA-facing view recovered from an AP2 mandate (fields depend on the mandate type). */
233
+ export interface ParsedAP2Mandate {
234
+ type: AP2MandateType;
235
+ /** Intent: the allowlist (absent/null ⇒ any). */
236
+ merchants?: string[];
237
+ categories?: string[];
238
+ currency?: string;
239
+ /** Intent: X (from `max_amount`); also recovered from `x_pca`. */
240
+ perTransactionCap?: number;
241
+ /** Intent: Y (from `x_pca`). */
242
+ autoApproveThreshold?: number;
243
+ /** Intent: bMax (from `x_pca`). */
244
+ cumulativeCap?: number;
245
+ periodStart?: number;
246
+ periodEnd?: number;
247
+ maxTransactionsPerPeriod?: number;
248
+ goalCommit?: string;
249
+ /** Cart/Payment: the concrete amount. */
250
+ amount?: number;
251
+ /** Cart/Payment: the concrete merchant. */
252
+ merchant?: string;
253
+ /** Payment: the modality signal. */
254
+ humanPresent?: boolean;
255
+ }
256
+ /** Parse an AP2 mandate VDC back toward PCA terms (lossless for an Intent minted with `x_pca`). */
257
+ export declare function fromAP2Mandate(vdc: AnyAP2Mandate): ParsedAP2Mandate;
258
+ export interface ChainVerification {
259
+ ok: boolean;
260
+ reasons: string[];
261
+ }
262
+ export interface AP2MandateChain {
263
+ intent: IntentMandate;
264
+ cart: CartMandate;
265
+ payment: PaymentMandate;
266
+ /** Verify the signatures, the hash bindings, and that each step is a non-amplifying narrowing. */
267
+ verify(): ChainVerification;
268
+ }
269
+ /**
270
+ * Verify an AP2 Intent→Cart→Payment chain: each VDC's signature, the hash bindings (cart→intent,
271
+ * payment→cart), and that every step only RESTRICTS the one above (never amplifies). This mirrors
272
+ * PCA's attenuation check: a child capability may narrow authority but never widen it.
273
+ */
274
+ export declare function verifyAP2Chain(intent: IntentMandate, cart: CartMandate, payment: PaymentMandate): ChainVerification;
275
+ /** Assemble the signed Intent→Cart→Payment chain and attach its non-amplifying-narrowing verifier. */
276
+ export declare function chainMandates(intent: IntentMandate, cart: CartMandate, payment: PaymentMandate): AP2MandateChain;
277
+ /** Context the caller supplies for building a rail-specific settlement payload. */
278
+ export interface SettlementContext {
279
+ /** Protected resource URL (x402). */
280
+ resourceUrl?: string;
281
+ /** Payee address / account (x402 `payTo`, Stripe `on_behalf_of`). */
282
+ payTo?: string;
283
+ /** Rail network, e.g. an x402 chain id like `base-sepolia`. */
284
+ network?: string;
285
+ }
286
+ /** A rail-specific settlement payload shape. No network is performed; this is the wire shape only. */
287
+ export interface SettlementInstruction {
288
+ rail: string;
289
+ amount: MonetaryAmount;
290
+ merchant?: string;
291
+ /** The rail-specific payload (structural). */
292
+ payload: Readonly<Record<string, unknown>>;
293
+ }
294
+ /**
295
+ * A settlement rail PCA's governance feeds. PCA + AP2 decide WHETHER a charge is authorized and carry
296
+ * the signed mandate; a `SettlementBackend` turns a verified Payment Mandate into the rail's wire shape.
297
+ * It never moves money here — it is the hook a real integration fills in.
298
+ */
299
+ export interface SettlementBackend {
300
+ readonly rail: string;
301
+ /** Build the rail payload for a (presumed-verified) Payment Mandate. Pure; no network. */
302
+ settle(payment: PaymentMandate, ctx?: SettlementContext): SettlementInstruction;
303
+ }
304
+ /**
305
+ * Coinbase x402 adapter: models the HTTP 402 `Payment Required` challenge (the server's `accepts`
306
+ * payment requirements) plus the `X-PAYMENT` request header carrying the base64 payment payload the
307
+ * client re-sends. Structural only — the real rail settles on-chain. (Field names follow the public
308
+ * x402 shape and should be checked against the x402 spec before production.)
309
+ */
310
+ export declare const x402Settlement: SettlementBackend;
311
+ /**
312
+ * Stripe Shared Payment Token adapter: models the SPT charge shape — a shared token the buyer's agent
313
+ * grants the merchant to pull a bounded amount. Structural only — a real integration calls Stripe with
314
+ * the token. Amount is converted to minor units (cents). (Check field names against Stripe's SPT docs
315
+ * before production.)
316
+ */
317
+ export declare const stripeSptSettlement: SettlementBackend;
package/dist/index.js ADDED
@@ -0,0 +1,338 @@
1
+ "use strict";
2
+ /**
3
+ * @atlasauth/pca-ap2 — AP2 (Agent Payments Protocol) wire-compatibility for PCA.
4
+ *
5
+ * ┌──────────────────────────────────────────────────────────────────────────────────────────────┐
6
+ * │ PCA GOVERNS. AP2 is the payment-MANDATE wire. x402 / Stripe Shared-Payment-Tokens SETTLE. │
7
+ * └──────────────────────────────────────────────────────────────────────────────────────────────┘
8
+ *
9
+ * AP2 (donated to the FIDO Alliance, v0.2 shape, 2026-04-28) standardizes agentic payments as a chain
10
+ * of signed Verifiable Digital Credentials (VDCs):
11
+ *
12
+ * IntentMandate → CartMandate → PaymentMandate
13
+ * (the user's (the merchant's (the payment authorization +
14
+ * goal + caps) concrete cart) human-present / not-present signal)
15
+ *
16
+ * This is a near-isomorphism of PCA's attenuating capability chain: the Root Intent Grant bounds the
17
+ * authority; each narrowing step may only RESTRICT it, never amplify it. PCA's trust-budget + risk
18
+ * policy (`@atlasauth/pca-payments`) decide WHETHER a charge is autonomous (tier 1) or needs a human
19
+ * co-sign (tier 3); AP2 carries that decision on the wire; the settlement rail moves the money.
20
+ *
21
+ * This is a BRIDGE, not a replacement:
22
+ * - PCA = the authority / budget layer (who may spend, how much, until when, before a human co-sign).
23
+ * - AP2 = the payment-mandate wire (the Intent→Cart→Payment VDC chain other parties verify).
24
+ * - x402 / Stripe SPT = the settlement rails that actually move value, fed by PCA's governance.
25
+ * Compose them; do not fold one into another.
26
+ *
27
+ * ────────────────────────────────────────────────────────────────────────────────────────────────
28
+ * HONEST CAVEAT — VERIFY BEFORE PRODUCTION WIRE USE
29
+ * ────────────────────────────────────────────────────────────────────────────────────────────────
30
+ * AP2 is a moving target and its mandate field-level signing roles differ between secondary sources
31
+ * (e.g. whether a cart is co-signed by both merchant and user, and whether the step is called "Cart"
32
+ * or "Checkout"). The spec also layers over UCP (ucp.dev) whose dated releases move the payment token
33
+ * between `payment_data.token` and `payment.instruments[*].credential.token`. This module models the
34
+ * v0.2 Intent/Cart/Payment chain to the best public understanding; it MUST be validated against the
35
+ * AP2 repository `schemas/` (and the official spec at ap2-protocol.org) before any production wire use.
36
+ * PCA-native terms that AP2 has no field for are carried in a namespaced `x_pca` extension so the chain
37
+ * can round-trip back to PCA terms; those fields are non-standard by construction.
38
+ */
39
+ Object.defineProperty(exports, "__esModule", { value: true });
40
+ exports.stripeSptSettlement = exports.x402Settlement = exports.AP2_CONTEXT = exports.AP2_VERSION = void 0;
41
+ exports.signMandate = signMandate;
42
+ exports.verifyMandate = verifyMandate;
43
+ exports.mandateHash = mandateHash;
44
+ exports.toAP2IntentMandate = toAP2IntentMandate;
45
+ exports.toAP2CartMandate = toAP2CartMandate;
46
+ exports.toAP2PaymentMandate = toAP2PaymentMandate;
47
+ exports.fromAP2Mandate = fromAP2Mandate;
48
+ exports.verifyAP2Chain = verifyAP2Chain;
49
+ exports.chainMandates = chainMandates;
50
+ const pca_1 = require("@atlasauth/pca");
51
+ // ===================================================================================================
52
+ // AP2 version pin
53
+ // ===================================================================================================
54
+ /** The AP2 shape this module models. See the HONEST CAVEAT above. */
55
+ exports.AP2_VERSION = '0.2';
56
+ /**
57
+ * Illustrative JSON-LD contexts for the VDC envelope. The second entry is a placeholder for the AP2
58
+ * context URL — replace with the canonical context from the AP2 repo before production.
59
+ */
60
+ exports.AP2_CONTEXT = [
61
+ 'https://www.w3.org/2018/credentials/v1',
62
+ 'https://ap2-protocol.org/context/v0.2',
63
+ ];
64
+ // ===================================================================================================
65
+ // Signing / verification / hashing
66
+ // ===================================================================================================
67
+ /** Strip `proof` for canonical signing/verification (the signature covers everything else). */
68
+ function proofless(vdc) {
69
+ const { proof: _proof, ...rest } = vdc;
70
+ void _proof;
71
+ return rest;
72
+ }
73
+ /** Sign a VDC with the issuer's Ed25519 secret key, returning a copy carrying the `proof`. */
74
+ function signMandate(vdc, secretKey) {
75
+ const sig = (0, pca_1.sign)(secretKey, (0, pca_1.canonicalBytes)(proofless(vdc)));
76
+ const proof = {
77
+ type: 'Ed25519Signature2020',
78
+ created: vdc.issuanceDate,
79
+ verificationMethod: vdc.issuer,
80
+ proofPurpose: 'assertionMethod',
81
+ signatureValue: (0, pca_1.encodeSig)(sig),
82
+ };
83
+ return { ...vdc, proof };
84
+ }
85
+ /** Verify a VDC's detached signature. Returns false when unsigned or the signature does not verify. */
86
+ function verifyMandate(vdc) {
87
+ if (!vdc.proof)
88
+ return false;
89
+ // The proof must verify under the credential's own declared issuer (no key substitution).
90
+ if (vdc.proof.verificationMethod !== vdc.issuer)
91
+ return false;
92
+ return (0, pca_1.verifyB64u)(vdc.issuer, (0, pca_1.canonicalBytes)(proofless(vdc)), vdc.proof.signatureValue);
93
+ }
94
+ /** Stable content hash of a VDC (used to bind one mandate to the next). */
95
+ function mandateHash(vdc) {
96
+ return (0, pca_1.hashCanonical)(vdc);
97
+ }
98
+ // ===================================================================================================
99
+ // PCA → AP2 mapping (the narrowing chain)
100
+ // ===================================================================================================
101
+ const round2 = (n) => Math.round((n + Number.EPSILON) * 100) / 100;
102
+ /** Normalize the two accepted inputs to `MandateTerms` (+ the goal commitment when a full mandate). */
103
+ function termsOf(mandate) {
104
+ if ('terms' in mandate)
105
+ return { terms: mandate.terms, goalCommit: mandate.goalCommit };
106
+ return { terms: mandate };
107
+ }
108
+ function describeTerms(terms) {
109
+ const where = terms.merchants.length ? ` at [${terms.merchants.join(', ')}]` : '';
110
+ return (`Purchase up to ${terms.perTransactionCap} ${terms.currency} per transaction` +
111
+ ` (autonomous up to ${terms.autoApproveThreshold}, cumulative ${terms.cumulativeCap})${where}`);
112
+ }
113
+ /** Map a PCA payment mandate (or raw terms) to an AP2 Intent Mandate VDC. */
114
+ function toAP2IntentMandate(mandate, opts) {
115
+ const { terms, goalCommit } = termsOf(mandate);
116
+ const now = Number.isFinite(opts.now) ? opts.now : Date.now();
117
+ const x_pca = {
118
+ auto_approve_threshold: terms.autoApproveThreshold,
119
+ cumulative_cap: terms.cumulativeCap,
120
+ per_transaction_cap: terms.perTransactionCap,
121
+ period_start: terms.periodStart,
122
+ ...(terms.periodEnd !== undefined ? { period_end: terms.periodEnd } : {}),
123
+ ...(terms.maxTransactionsPerPeriod !== undefined
124
+ ? { max_transactions_per_period: terms.maxTransactionsPerPeriod }
125
+ : {}),
126
+ ...(goalCommit !== undefined ? { goal_commit: goalCommit } : {}),
127
+ };
128
+ const contents = {
129
+ natural_language_description: opts.naturalLanguageDescription ?? describeTerms(terms),
130
+ merchants: terms.merchants.length ? [...terms.merchants] : null,
131
+ skus: opts.skus ?? null,
132
+ ...(terms.categories.length ? { categories: [...terms.categories] } : {}),
133
+ max_amount: { currency: terms.currency, value: terms.perTransactionCap },
134
+ required_refundability: true,
135
+ user_cart_confirmation_required: opts.userCartConfirmationRequired ?? terms.autoApproveThreshold < terms.perTransactionCap,
136
+ ...(terms.periodEnd !== undefined ? { intent_expiry: new Date(terms.periodEnd).toISOString() } : {}),
137
+ x_pca,
138
+ };
139
+ const vdc = {
140
+ '@context': exports.AP2_CONTEXT,
141
+ type: ['VerifiableCredential', 'IntentMandate'],
142
+ issuer: opts.issuerPublic,
143
+ issuanceDate: new Date(now).toISOString(),
144
+ ...(terms.periodEnd !== undefined ? { expirationDate: new Date(terms.periodEnd).toISOString() } : {}),
145
+ credentialSubject: contents,
146
+ };
147
+ return opts.issuerSecret ? signMandate(vdc, opts.issuerSecret) : vdc;
148
+ }
149
+ /** Narrow an Intent Mandate into a concrete AP2 Cart Mandate VDC (items + committed total). */
150
+ function toAP2CartMandate(intent, cart, opts) {
151
+ const currency = cart.currency ?? intent.credentialSubject.max_amount.currency;
152
+ const total = round2(cart.items.reduce((sum, it) => sum + it.quantity * it.unit_price.value, 0));
153
+ const id = cart.id ?? `cart_${(0, pca_1.hashCanonical)({ merchant: cart.merchant, items: cart.items }).slice(0, 16)}`;
154
+ const contents = {
155
+ id,
156
+ merchant: cart.merchant,
157
+ items: cart.items.map((it) => ({ ...it, unit_price: { ...it.unit_price } })),
158
+ total: { currency, value: total },
159
+ intent_reference: mandateHash(intent),
160
+ ...(cart.expiry !== undefined ? { cart_expiry: new Date(cart.expiry).toISOString() } : {}),
161
+ };
162
+ const vdc = {
163
+ '@context': exports.AP2_CONTEXT,
164
+ type: ['VerifiableCredential', 'CartMandate'],
165
+ issuer: opts.issuerPublic,
166
+ issuanceDate: new Date(Number.isFinite(cart.now) ? cart.now : Date.now()).toISOString(),
167
+ ...(cart.expiry !== undefined ? { expirationDate: new Date(cart.expiry).toISOString() } : {}),
168
+ credentialSubject: contents,
169
+ };
170
+ return opts.issuerSecret ? signMandate(vdc, opts.issuerSecret) : vdc;
171
+ }
172
+ /** Narrow a Cart Mandate into an AP2 Payment Mandate VDC (the payment authorization + modality). */
173
+ function toAP2PaymentMandate(cart, opts) {
174
+ const amount = opts.amount ?? { ...cart.credentialSubject.total };
175
+ const humanPresent = opts.humanPresent ?? (opts.pcaTier !== undefined ? opts.pcaTier >= 3 : false);
176
+ const contents = {
177
+ cart_hash: mandateHash(cart),
178
+ ...(opts.intent ? { intent_hash: mandateHash(opts.intent) } : {}),
179
+ amount,
180
+ payment_method: { ...opts.paymentMethod },
181
+ human_present: humanPresent,
182
+ ...(cart.credentialSubject.merchant ? { merchant: cart.credentialSubject.merchant } : {}),
183
+ };
184
+ const vdc = {
185
+ '@context': exports.AP2_CONTEXT,
186
+ type: ['VerifiableCredential', 'PaymentMandate'],
187
+ issuer: opts.issuerPublic,
188
+ issuanceDate: new Date(Number.isFinite(opts.now) ? opts.now : Date.now()).toISOString(),
189
+ credentialSubject: contents,
190
+ };
191
+ return opts.issuerSecret ? signMandate(vdc, opts.issuerSecret) : vdc;
192
+ }
193
+ /** Parse an AP2 mandate VDC back toward PCA terms (lossless for an Intent minted with `x_pca`). */
194
+ function fromAP2Mandate(vdc) {
195
+ const kind = vdc.type[1];
196
+ if (kind === 'IntentMandate') {
197
+ const cs = vdc.credentialSubject;
198
+ const x = cs.x_pca;
199
+ return {
200
+ type: 'IntentMandate',
201
+ ...(cs.merchants ? { merchants: [...cs.merchants] } : {}),
202
+ ...(cs.categories ? { categories: [...cs.categories] } : {}),
203
+ currency: cs.max_amount.currency,
204
+ perTransactionCap: x?.per_transaction_cap ?? cs.max_amount.value,
205
+ ...(x ? { autoApproveThreshold: x.auto_approve_threshold, cumulativeCap: x.cumulative_cap } : {}),
206
+ ...(x?.period_start !== undefined ? { periodStart: x.period_start } : {}),
207
+ ...(x?.period_end !== undefined ? { periodEnd: x.period_end } : {}),
208
+ ...(x?.max_transactions_per_period !== undefined
209
+ ? { maxTransactionsPerPeriod: x.max_transactions_per_period }
210
+ : {}),
211
+ ...(x?.goal_commit !== undefined ? { goalCommit: x.goal_commit } : {}),
212
+ };
213
+ }
214
+ if (kind === 'CartMandate') {
215
+ const cs = vdc.credentialSubject;
216
+ return { type: 'CartMandate', merchant: cs.merchant, amount: cs.total.value, currency: cs.total.currency };
217
+ }
218
+ const cs = vdc.credentialSubject;
219
+ return {
220
+ type: 'PaymentMandate',
221
+ amount: cs.amount.value,
222
+ currency: cs.amount.currency,
223
+ humanPresent: cs.human_present,
224
+ ...(cs.merchant ? { merchant: cs.merchant } : {}),
225
+ };
226
+ }
227
+ /**
228
+ * Verify an AP2 Intent→Cart→Payment chain: each VDC's signature, the hash bindings (cart→intent,
229
+ * payment→cart), and that every step only RESTRICTS the one above (never amplifies). This mirrors
230
+ * PCA's attenuation check: a child capability may narrow authority but never widen it.
231
+ */
232
+ function verifyAP2Chain(intent, cart, payment) {
233
+ const reasons = [];
234
+ // 1. Signatures (each mandate must be signed and verify under its own issuer).
235
+ if (!verifyMandate(intent))
236
+ reasons.push('intent signature invalid or missing');
237
+ if (!verifyMandate(cart))
238
+ reasons.push('cart signature invalid or missing');
239
+ if (!verifyMandate(payment))
240
+ reasons.push('payment signature invalid or missing');
241
+ const i = intent.credentialSubject;
242
+ const c = cart.credentialSubject;
243
+ const p = payment.credentialSubject;
244
+ // 2. Hash bindings (cart → intent, payment → cart).
245
+ if (c.intent_reference !== mandateHash(intent))
246
+ reasons.push('cart does not reference this intent');
247
+ if (p.cart_hash !== mandateHash(cart))
248
+ reasons.push('payment does not reference this cart');
249
+ if (p.intent_hash !== undefined && p.intent_hash !== mandateHash(intent)) {
250
+ reasons.push('payment intent_hash does not match this intent');
251
+ }
252
+ // 3. Currency consistency (no implicit FX across the chain).
253
+ if (c.total.currency !== i.max_amount.currency)
254
+ reasons.push('cart currency differs from intent');
255
+ if (p.amount.currency !== c.total.currency)
256
+ reasons.push('payment currency differs from cart');
257
+ // 4. Non-amplifying narrowing of AMOUNT (the core attenuation check).
258
+ if (c.total.value > i.max_amount.value) {
259
+ reasons.push(`cart total ${c.total.value} exceeds intent cap ${i.max_amount.value} (amplifying)`);
260
+ }
261
+ if (p.amount.value > c.total.value) {
262
+ reasons.push(`payment amount ${p.amount.value} exceeds cart total ${c.total.value} (amplifying)`);
263
+ }
264
+ // 5. Merchant allowlist narrowing (null intent.merchants ⇒ any merchant permitted).
265
+ if (i.merchants !== null && !i.merchants.includes(c.merchant)) {
266
+ reasons.push(`cart merchant '${c.merchant}' not in intent allowlist`);
267
+ }
268
+ return { ok: reasons.length === 0, reasons };
269
+ }
270
+ /** Assemble the signed Intent→Cart→Payment chain and attach its non-amplifying-narrowing verifier. */
271
+ function chainMandates(intent, cart, payment) {
272
+ return { intent, cart, payment, verify: () => verifyAP2Chain(intent, cart, payment) };
273
+ }
274
+ /**
275
+ * Coinbase x402 adapter: models the HTTP 402 `Payment Required` challenge (the server's `accepts`
276
+ * payment requirements) plus the `X-PAYMENT` request header carrying the base64 payment payload the
277
+ * client re-sends. Structural only — the real rail settles on-chain. (Field names follow the public
278
+ * x402 shape and should be checked against the x402 spec before production.)
279
+ */
280
+ exports.x402Settlement = {
281
+ rail: 'x402',
282
+ settle(payment, ctx) {
283
+ const cs = payment.credentialSubject;
284
+ const network = ctx?.network ?? 'base-sepolia';
285
+ const requirement = {
286
+ scheme: 'exact',
287
+ network,
288
+ maxAmountRequired: String(cs.amount.value),
289
+ resource: ctx?.resourceUrl ?? '',
290
+ description: `AP2 payment mandate ${cs.cart_hash}`,
291
+ payTo: ctx?.payTo ?? cs.merchant ?? '',
292
+ asset: cs.amount.currency,
293
+ mimeType: 'application/json',
294
+ };
295
+ const xPayment = (0, pca_1.b64u)((0, pca_1.utf8)(JSON.stringify({
296
+ x402Version: 1,
297
+ scheme: 'exact',
298
+ network,
299
+ payload: { cartHash: cs.cart_hash, humanPresent: cs.human_present, amount: cs.amount.value },
300
+ })));
301
+ return {
302
+ rail: 'x402',
303
+ amount: cs.amount,
304
+ ...(cs.merchant ? { merchant: cs.merchant } : {}),
305
+ payload: {
306
+ httpStatus: 402,
307
+ x402Version: 1,
308
+ accepts: [requirement],
309
+ header: { 'X-PAYMENT': xPayment },
310
+ },
311
+ };
312
+ },
313
+ };
314
+ /**
315
+ * Stripe Shared Payment Token adapter: models the SPT charge shape — a shared token the buyer's agent
316
+ * grants the merchant to pull a bounded amount. Structural only — a real integration calls Stripe with
317
+ * the token. Amount is converted to minor units (cents). (Check field names against Stripe's SPT docs
318
+ * before production.)
319
+ */
320
+ exports.stripeSptSettlement = {
321
+ rail: 'stripe-spt',
322
+ settle(payment, ctx) {
323
+ const cs = payment.credentialSubject;
324
+ return {
325
+ rail: 'stripe-spt',
326
+ amount: cs.amount,
327
+ ...(cs.merchant ? { merchant: cs.merchant } : {}),
328
+ payload: {
329
+ shared_payment_token: cs.payment_method.token ?? '',
330
+ amount: Math.round(cs.amount.value * 100),
331
+ currency: cs.amount.currency.toLowerCase(),
332
+ human_present: cs.human_present,
333
+ ...(ctx?.payTo ? { on_behalf_of: ctx.payTo } : {}),
334
+ },
335
+ };
336
+ },
337
+ };
338
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;;;AAyLH,kCAaC;AAGD,sCAKC;AAGD,kCAEC;AAsCD,gDAyCC;AAsBD,4CAyBC;AAuBD,kDAsBC;AAgCD,wCAgCC;AAwBD,wCAyCC;AAGD,sCAMC;AAtgBD,wCAQwB;AAGxB,sGAAsG;AACtG,kBAAkB;AAClB,sGAAsG;AAEtG,qEAAqE;AACxD,QAAA,WAAW,GAAG,KAAc,CAAC;AAE1C;;;GAGG;AACU,QAAA,WAAW,GAAsB;IAC5C,wCAAwC;IACxC,uCAAuC;CACxC,CAAC;AAkJF,sGAAsG;AACtG,mCAAmC;AACnC,sGAAsG;AAEtG,+FAA+F;AAC/F,SAAS,SAAS,CAAiC,GAAM;IACvD,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,GAAG,CAAC;IACvC,KAAK,MAAM,CAAC;IACZ,OAAO,I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AC,MAAM,CAAC,QAAQ,CAAC,WAAW,EAAE;gBAC1C,aAAa,EAAE,EAAE,CAAC,aAAa;gBAC/B,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aACnD;SACF,CAAC;IACJ,CAAC;CACF,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,34 @@
1
1
  {
2
2
  "name": "@atlasauth/pca-ap2",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "AP2 (Agent Payments Protocol, FIDO) wire-compatibility for PCA: map the grant/budget to Intent/Cart/Payment mandate VDCs; PCA governs, x402 / Stripe Shared-Payment-Tokens settle.",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "default": "./dist/index.js"
11
+ },
12
+ "./package.json": "./package.json"
13
+ },
14
+ "dependencies": {
15
+ "@atlasauth/pca": "0.1.0",
16
+ "@atlasauth/pca-payments": "0.1.0"
17
+ },
18
+ "devDependencies": {
19
+ "typescript": "^5.6.3",
20
+ "vitest": "^2.1.4"
21
+ },
22
+ "files": [
23
+ "dist",
24
+ "README.md"
25
+ ],
26
+ "publishConfig": {
27
+ "access": "public"
28
+ },
29
+ "scripts": {
30
+ "build": "tsc -p tsconfig.build.json",
31
+ "typecheck": "tsc -p tsconfig.json --noEmit",
32
+ "test": "vitest run"
33
+ }
6
34
  }