@atlasauth/pca-ap2 0.3.0 → 0.4.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/dist/index.js CHANGED
@@ -1,359 +1,33 @@
1
1
  "use strict";
2
- /**
3
- * @atlasauth/pca-ap2 — an AP2-modelled (Agent Payments Protocol) mandate chain 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
- * That validation has now been run (see conformance.test.ts): the output does NOT conform to the current
37
- * official SD-JWT mandate schemas, so treat this as a PCA rendition of the concepts, not the AP2 wire format.
38
- * PCA-native terms that AP2 has no field for are carried in a namespaced `x_pca` extension so the chain
39
- * can round-trip back to PCA terms; those fields are non-standard by construction.
40
- */
41
- Object.defineProperty(exports, "__esModule", { value: true });
42
- exports.stripeSptSettlement = exports.x402Settlement = exports.AP2_CONTEXT = exports.AP2_VERSION = void 0;
43
- exports.signMandate = signMandate;
44
- exports.verifyMandate = verifyMandate;
45
- exports.mandateHash = mandateHash;
46
- exports.toAP2IntentMandate = toAP2IntentMandate;
47
- exports.toAP2CartMandate = toAP2CartMandate;
48
- exports.toAP2PaymentMandate = toAP2PaymentMandate;
49
- exports.fromAP2Mandate = fromAP2Mandate;
50
- exports.verifyAP2Chain = verifyAP2Chain;
51
- exports.chainMandates = chainMandates;
52
- const pca_1 = require("@atlasauth/pca");
53
- // ===================================================================================================
54
- // AP2 version pin
55
- // ===================================================================================================
56
- /** The AP2 shape this module models. See the HONEST CAVEAT above. */
57
- exports.AP2_VERSION = '0.2';
58
- /**
59
- * Illustrative JSON-LD contexts for the VDC envelope. The second entry is a placeholder for the AP2
60
- * context URL — replace with the canonical context from the AP2 repo before production.
61
- */
62
- exports.AP2_CONTEXT = [
63
- 'https://www.w3.org/2018/credentials/v1',
64
- 'https://ap2-protocol.org/context/v0.2',
65
- ];
66
- // ===================================================================================================
67
- // Signing / verification / hashing
68
- // ===================================================================================================
69
- /** Strip `proof` for canonical signing/verification (the signature covers everything else). */
70
- function proofless(vdc) {
71
- const { proof: _proof, ...rest } = vdc;
72
- void _proof;
73
- return rest;
74
- }
75
- /** Sign a VDC with the issuer's Ed25519 secret key, returning a copy carrying the `proof`. */
76
- function signMandate(vdc, secretKey) {
77
- const sig = (0, pca_1.sign)(secretKey, (0, pca_1.canonicalBytes)(proofless(vdc)));
78
- const proof = {
79
- type: 'Ed25519Signature2020',
80
- created: vdc.issuanceDate,
81
- verificationMethod: vdc.issuer,
82
- proofPurpose: 'assertionMethod',
83
- signatureValue: (0, pca_1.encodeSig)(sig),
84
- };
85
- return { ...vdc, proof };
86
- }
87
- /** Verify a VDC's detached signature. Returns false when unsigned or the signature does not verify. */
88
- function verifyMandate(vdc) {
89
- if (!vdc.proof)
90
- return false;
91
- // The proof must verify under the credential's own declared issuer (no key substitution).
92
- if (vdc.proof.verificationMethod !== vdc.issuer)
93
- return false;
94
- return (0, pca_1.verifyB64u)(vdc.issuer, (0, pca_1.canonicalBytes)(proofless(vdc)), vdc.proof.signatureValue);
95
- }
96
- /** Stable content hash of a VDC (used to bind one mandate to the next). */
97
- function mandateHash(vdc) {
98
- return (0, pca_1.hashCanonical)(vdc);
99
- }
100
- // ===================================================================================================
101
- // PCA → AP2 mapping (the narrowing chain)
102
- // ===================================================================================================
103
- const round2 = (n) => Math.round((n + Number.EPSILON) * 100) / 100;
104
- /** Normalize the two accepted inputs to `MandateTerms` (+ the goal commitment when a full mandate). */
105
- function termsOf(mandate) {
106
- if ('terms' in mandate)
107
- return { terms: mandate.terms, goalCommit: mandate.goalCommit };
108
- return { terms: mandate };
109
- }
110
- function describeTerms(terms) {
111
- const where = terms.merchants.length ? ` at [${terms.merchants.join(', ')}]` : '';
112
- return (`Purchase up to ${terms.perTransactionCap} ${terms.currency} per transaction` +
113
- ` (autonomous up to ${terms.autoApproveThreshold}, cumulative ${terms.cumulativeCap})${where}`);
114
- }
115
- /** Map a PCA payment mandate (or raw terms) to an AP2 Intent Mandate VDC. */
116
- function toAP2IntentMandate(mandate, opts) {
117
- const { terms, goalCommit } = termsOf(mandate);
118
- const now = Number.isFinite(opts.now) ? opts.now : Date.now();
119
- const x_pca = {
120
- auto_approve_threshold: terms.autoApproveThreshold,
121
- cumulative_cap: terms.cumulativeCap,
122
- per_transaction_cap: terms.perTransactionCap,
123
- period_start: terms.periodStart,
124
- ...(terms.periodEnd !== undefined ? { period_end: terms.periodEnd } : {}),
125
- ...(terms.maxTransactionsPerPeriod !== undefined
126
- ? { max_transactions_per_period: terms.maxTransactionsPerPeriod }
127
- : {}),
128
- ...(goalCommit !== undefined ? { goal_commit: goalCommit } : {}),
129
- };
130
- const contents = {
131
- natural_language_description: opts.naturalLanguageDescription ?? describeTerms(terms),
132
- merchants: terms.merchants.length ? [...terms.merchants] : null,
133
- skus: opts.skus ?? null,
134
- ...(terms.categories.length ? { categories: [...terms.categories] } : {}),
135
- max_amount: { currency: terms.currency, value: terms.perTransactionCap },
136
- required_refundability: true,
137
- user_cart_confirmation_required: opts.userCartConfirmationRequired ?? terms.autoApproveThreshold < terms.perTransactionCap,
138
- ...(terms.periodEnd !== undefined ? { intent_expiry: new Date(terms.periodEnd).toISOString() } : {}),
139
- x_pca,
140
- };
141
- const vdc = {
142
- '@context': exports.AP2_CONTEXT,
143
- type: ['VerifiableCredential', 'IntentMandate'],
144
- issuer: opts.issuerPublic,
145
- issuanceDate: new Date(now).toISOString(),
146
- ...(terms.periodEnd !== undefined ? { expirationDate: new Date(terms.periodEnd).toISOString() } : {}),
147
- credentialSubject: contents,
148
- };
149
- return opts.issuerSecret ? signMandate(vdc, opts.issuerSecret) : vdc;
150
- }
151
- /** Narrow an Intent Mandate into a concrete AP2 Cart Mandate VDC (items + committed total). */
152
- function toAP2CartMandate(intent, cart, opts) {
153
- const currency = cart.currency ?? intent.credentialSubject.max_amount.currency;
154
- const total = round2(cart.items.reduce((sum, it) => sum + it.quantity * it.unit_price.value, 0));
155
- const id = cart.id ?? `cart_${(0, pca_1.hashCanonical)({ merchant: cart.merchant, items: cart.items }).slice(0, 16)}`;
156
- const contents = {
157
- id,
158
- merchant: cart.merchant,
159
- items: cart.items.map((it) => ({ ...it, unit_price: { ...it.unit_price } })),
160
- total: { currency, value: total },
161
- intent_reference: mandateHash(intent),
162
- ...(cart.expiry !== undefined ? { cart_expiry: new Date(cart.expiry).toISOString() } : {}),
163
- };
164
- const vdc = {
165
- '@context': exports.AP2_CONTEXT,
166
- type: ['VerifiableCredential', 'CartMandate'],
167
- issuer: opts.issuerPublic,
168
- issuanceDate: new Date(Number.isFinite(cart.now) ? cart.now : Date.now()).toISOString(),
169
- ...(cart.expiry !== undefined ? { expirationDate: new Date(cart.expiry).toISOString() } : {}),
170
- credentialSubject: contents,
171
- };
172
- return opts.issuerSecret ? signMandate(vdc, opts.issuerSecret) : vdc;
173
- }
174
- /** Narrow a Cart Mandate into an AP2 Payment Mandate VDC (the payment authorization + modality). */
175
- function toAP2PaymentMandate(cart, opts) {
176
- const amount = opts.amount ?? { ...cart.credentialSubject.total };
177
- const humanPresent = opts.humanPresent ?? (opts.pcaTier !== undefined ? opts.pcaTier >= 3 : false);
178
- const contents = {
179
- cart_hash: mandateHash(cart),
180
- ...(opts.intent ? { intent_hash: mandateHash(opts.intent) } : {}),
181
- amount,
182
- payment_method: { ...opts.paymentMethod },
183
- human_present: humanPresent,
184
- ...(cart.credentialSubject.merchant ? { merchant: cart.credentialSubject.merchant } : {}),
185
- };
186
- const vdc = {
187
- '@context': exports.AP2_CONTEXT,
188
- type: ['VerifiableCredential', 'PaymentMandate'],
189
- issuer: opts.issuerPublic,
190
- issuanceDate: new Date(Number.isFinite(opts.now) ? opts.now : Date.now()).toISOString(),
191
- credentialSubject: contents,
192
- };
193
- return opts.issuerSecret ? signMandate(vdc, opts.issuerSecret) : vdc;
194
- }
195
- /** Parse an AP2 mandate VDC back toward PCA terms (lossless for an Intent minted with `x_pca`). */
196
- function fromAP2Mandate(vdc) {
197
- const kind = vdc.type[1];
198
- if (kind === 'IntentMandate') {
199
- const cs = vdc.credentialSubject;
200
- const x = cs.x_pca;
201
- return {
202
- type: 'IntentMandate',
203
- ...(cs.merchants ? { merchants: [...cs.merchants] } : {}),
204
- ...(cs.categories ? { categories: [...cs.categories] } : {}),
205
- currency: cs.max_amount.currency,
206
- perTransactionCap: x?.per_transaction_cap ?? cs.max_amount.value,
207
- ...(x ? { autoApproveThreshold: x.auto_approve_threshold, cumulativeCap: x.cumulative_cap } : {}),
208
- ...(x?.period_start !== undefined ? { periodStart: x.period_start } : {}),
209
- ...(x?.period_end !== undefined ? { periodEnd: x.period_end } : {}),
210
- ...(x?.max_transactions_per_period !== undefined
211
- ? { maxTransactionsPerPeriod: x.max_transactions_per_period }
212
- : {}),
213
- ...(x?.goal_commit !== undefined ? { goalCommit: x.goal_commit } : {}),
214
- };
215
- }
216
- if (kind === 'CartMandate') {
217
- const cs = vdc.credentialSubject;
218
- return { type: 'CartMandate', merchant: cs.merchant, amount: cs.total.value, currency: cs.total.currency };
219
- }
220
- const cs = vdc.credentialSubject;
221
- return {
222
- type: 'PaymentMandate',
223
- amount: cs.amount.value,
224
- currency: cs.amount.currency,
225
- humanPresent: cs.human_present,
226
- ...(cs.merchant ? { merchant: cs.merchant } : {}),
227
- };
228
- }
229
- /**
230
- * Verify an AP2 Intent→Cart→Payment chain: each VDC's signature, the hash bindings (cart→intent,
231
- * payment→cart), and that every step only RESTRICTS the one above (never amplifies). This mirrors
232
- * PCA's attenuation check: a child capability may narrow authority but never widen it.
233
- */
234
- function verifyAP2Chain(intent, cart, payment) {
235
- const reasons = [];
236
- // 1. Signatures (each mandate must be signed and verify under its own issuer).
237
- if (!verifyMandate(intent))
238
- reasons.push('intent signature invalid or missing');
239
- if (!verifyMandate(cart))
240
- reasons.push('cart signature invalid or missing');
241
- if (!verifyMandate(payment))
242
- reasons.push('payment signature invalid or missing');
243
- const i = intent.credentialSubject;
244
- const c = cart.credentialSubject;
245
- const p = payment.credentialSubject;
246
- // 2. Hash bindings (cart → intent, payment → cart).
247
- if (c.intent_reference !== mandateHash(intent))
248
- reasons.push('cart does not reference this intent');
249
- if (p.cart_hash !== mandateHash(cart))
250
- reasons.push('payment does not reference this cart');
251
- if (p.intent_hash !== undefined && p.intent_hash !== mandateHash(intent)) {
252
- reasons.push('payment intent_hash does not match this intent');
253
- }
254
- // 3. Currency consistency (no implicit FX across the chain).
255
- if (c.total.currency !== i.max_amount.currency)
256
- reasons.push('cart currency differs from intent');
257
- if (p.amount.currency !== c.total.currency)
258
- reasons.push('payment currency differs from cart');
259
- // 4. Non-amplifying narrowing of AMOUNT (the core attenuation check).
260
- if (c.total.value > i.max_amount.value) {
261
- reasons.push(`cart total ${c.total.value} exceeds intent cap ${i.max_amount.value} (amplifying)`);
262
- }
263
- if (p.amount.value > c.total.value) {
264
- reasons.push(`payment amount ${p.amount.value} exceeds cart total ${c.total.value} (amplifying)`);
265
- }
266
- // 5. Merchant allowlist narrowing (null intent.merchants ⇒ any merchant permitted).
267
- if (i.merchants !== null && !i.merchants.includes(c.merchant)) {
268
- reasons.push(`cart merchant '${c.merchant}' not in intent allowlist`);
269
- }
270
- return { ok: reasons.length === 0, reasons };
271
- }
272
- /** Assemble the signed Intent→Cart→Payment chain and attach its non-amplifying-narrowing verifier. */
273
- function chainMandates(intent, cart, payment) {
274
- return { intent, cart, payment, verify: () => verifyAP2Chain(intent, cart, payment) };
275
- }
276
- /**
277
- * Convert a decimal amount to an integer string of atomic units (`10 ** decimals` per unit). Throws on
278
- * anything that is not a finite, non-negative amount that fits exactly in a safe integer.
279
- */
280
- function toAtomicUnits(value, decimals) {
281
- if (!Number.isInteger(decimals) || decimals < 0 || decimals > 18) {
282
- throw new RangeError(`x402: decimals must be an integer in 0..18, got ${String(decimals)}`);
283
- }
284
- const atomic = Math.round(value * 10 ** decimals);
285
- if (!Number.isFinite(value) || value < 0 || !Number.isSafeInteger(atomic)) {
286
- throw new RangeError(`x402: amount ${String(value)} cannot be expressed in atomic units with ${decimals} decimals`);
287
- }
288
- return String(atomic);
289
- }
290
- /**
291
- * Coinbase x402 adapter: models the HTTP 402 `Payment Required` challenge (the server's `accepts`
292
- * payment requirements) plus the `X-PAYMENT` request header carrying the base64 payment payload the
293
- * client re-sends. Structural only — the real rail settles on-chain. (Field names follow the public
294
- * x402 shape and should be checked against the x402 spec before production.)
295
- */
296
- exports.x402Settlement = {
297
- rail: 'x402',
298
- settle(payment, ctx) {
299
- const cs = payment.credentialSubject;
300
- const network = ctx?.network ?? 'base-sepolia';
301
- const requirement = {
302
- scheme: 'exact',
303
- network,
304
- // x402 v1: `maxAmountRequired` is a string in ATOMIC token units, not a decimal amount.
305
- maxAmountRequired: toAtomicUnits(cs.amount.value, ctx?.decimals ?? 6),
306
- resource: ctx?.resourceUrl ?? '',
307
- description: `AP2 payment mandate ${cs.cart_hash}`,
308
- payTo: ctx?.payTo ?? cs.merchant ?? '',
309
- asset: ctx?.asset ?? cs.amount.currency,
310
- mimeType: 'application/json',
311
- maxTimeoutSeconds: ctx?.maxTimeoutSeconds ?? 60,
312
- };
313
- // x402 carries `X-PAYMENT` as STANDARD base64 (with padding) of the JSON PaymentPayload. This
314
- // envelope is a placeholder: a real client replaces `payload` with its signed authorization.
315
- const xPayment = Buffer.from(JSON.stringify({
316
- x402Version: 1,
317
- scheme: 'exact',
318
- network,
319
- payload: { cartHash: cs.cart_hash, humanPresent: cs.human_present, amount: cs.amount.value },
320
- }), 'utf8').toString('base64');
321
- return {
322
- rail: 'x402',
323
- amount: cs.amount,
324
- ...(cs.merchant ? { merchant: cs.merchant } : {}),
325
- payload: {
326
- httpStatus: 402,
327
- x402Version: 1,
328
- error: 'X-PAYMENT header is required',
329
- accepts: [requirement],
330
- header: { 'X-PAYMENT': xPayment },
331
- },
332
- };
333
- },
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
334
15
  };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.AP2_COMMIT = void 0;
335
18
  /**
336
- * Stripe Shared Payment Token adapter: models the SPT charge shape — a shared token the buyer's agent
337
- * grants the merchant to pull a bounded amount. Structural only — a real integration calls Stripe with
338
- * the token. Amount is converted to minor units (cents). (Check field names against Stripe's SPT docs
339
- * before production.)
19
+ * @atlasauth/pca-ap2: AP2 (Agent Payments Protocol) mandates as real SD-JWT credentials, bound to a PCA grant.
20
+ *
21
+ * PCA governs: it decides who may spend, how much, until when, and when a human must co-sign. AP2 is
22
+ * the mandate wire other parties verify. Settlement rails (x402, Stripe Shared Payment Tokens) move
23
+ * the value, fed by PCA's decision.
340
24
  */
341
- exports.stripeSptSettlement = {
342
- rail: 'stripe-spt',
343
- settle(payment, ctx) {
344
- const cs = payment.credentialSubject;
345
- return {
346
- rail: 'stripe-spt',
347
- amount: cs.amount,
348
- ...(cs.merchant ? { merchant: cs.merchant } : {}),
349
- payload: {
350
- shared_payment_token: cs.payment_method.token ?? '',
351
- amount: Math.round(cs.amount.value * 100),
352
- currency: cs.amount.currency.toLowerCase(),
353
- human_present: cs.human_present,
354
- ...(ctx?.payTo ? { on_behalf_of: ctx.payTo } : {}),
355
- },
356
- };
357
- },
358
- };
25
+ __exportStar(require("./sdjwt"), exports);
26
+ __exportStar(require("./mandates"), exports);
27
+ __exportStar(require("./constraints"), exports);
28
+ __exportStar(require("./chain"), exports);
29
+ __exportStar(require("./pca"), exports);
30
+ __exportStar(require("./settlement"), exports);
31
+ /** The AP2 repository commit whose schemas and documentation this package is checked against. */
32
+ exports.AP2_COMMIT = 'e1ea56db72a6385bce3e5c1112b3a56ce60acb43';
359
33
  //# sourceMappingURL=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CAAC,MAAM;YACjB,GAAG,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACjD,OAAO,EAAE;gBACP,oBAAoB,EAAE,EAAE,CAAC,cAAc,CAAC,KAAK,IAAI,EAAE;gBACnD,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,KAAK,GAAG,GAAG,CAAC;gBACzC,QAAQ,EAAE,EAAE,CAAC,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"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA;;;;;;GAMG;AACH,0CAAwB;AACxB,6CAA2B;AAC3B,gDAA8B;AAC9B,0CAAwB;AACxB,wCAAsB;AACtB,+CAA6B;AAE7B,iGAAiG;AACpF,QAAA,UAAU,GAAG,0CAA0C,CAAC"}
@@ -0,0 +1,140 @@
1
+ /**
2
+ * AP2 mandate claim shapes (Intent/Cart/Payment, closed and open) and their validators.
3
+ *
4
+ * The shapes follow the official AP2 JSON Schemas (`checkout_mandate`, `open_checkout_mandate`,
5
+ * `payment_mandate`, `open_payment_mandate` and `types/*`). The validators are hand-written, check at
6
+ * least what those schemas check (the test-suite runs both against the same documents) and are
7
+ * stricter in places where a lax reading would be unsafe (non-negative safe-integer amounts,
8
+ * well-formed JWKs).
9
+ */
10
+ import { type Json, type JsonObject, type P256Jwk } from './sdjwt';
11
+ export declare const VCT_CHECKOUT = "mandate.checkout.1";
12
+ export declare const VCT_CHECKOUT_OPEN = "mandate.checkout.open.1";
13
+ export declare const VCT_PAYMENT = "mandate.payment.1";
14
+ export declare const VCT_PAYMENT_OPEN = "mandate.payment.open.1";
15
+ /** Namespaced claim carrying PCA's own proof inside a mandate object (see `pca.ts`). */
16
+ export declare const PCA_CLAIM = "x_pca";
17
+ /** ISO 4217 minor-unit exponent for `currency` (2 for any code not in the 0/3/4-digit tables). */
18
+ export declare function currencyExponent(currency: string): number;
19
+ /**
20
+ * Convert a major-unit amount (e.g. `120.5` USD) to integer minor units (`12050`). Throws unless the
21
+ * amount is exactly representable with the currency's exponent: float drift (`0.1 + 0.2`) is refused
22
+ * rather than rounded away.
23
+ */
24
+ export declare function toMinorUnits(major: number, currency: string): number;
25
+ /** Integer minor units to the major-unit number PCA budgets use (exact for any safe integer). */
26
+ export declare function fromMinorUnits(minor: number, currency: string): number;
27
+ export interface Merchant {
28
+ id: string;
29
+ name: string;
30
+ website?: string;
31
+ }
32
+ export interface Amount {
33
+ /** Integer minor units per ISO 4217 (27999 = USD 279.99). */
34
+ amount: number;
35
+ currency: string;
36
+ }
37
+ export interface PaymentInstrument {
38
+ id: string;
39
+ type: string;
40
+ description?: string;
41
+ }
42
+ export interface Pisp {
43
+ legal_name: string;
44
+ brand_name: string;
45
+ domain_name: string;
46
+ }
47
+ export interface CheckoutItem {
48
+ id: string;
49
+ title: string;
50
+ }
51
+ export type Frequency = 'ON_DEMAND' | 'DAILY' | 'WEEKLY' | 'BIWEEKLY' | 'MONTHLY' | 'QUARTERLY' | 'ANNUALLY';
52
+ export declare const FREQUENCIES: readonly Frequency[];
53
+ export type PaymentConstraint = {
54
+ type: 'payment.agent_recurrence';
55
+ frequency: Frequency;
56
+ max_occurrences?: number;
57
+ } | {
58
+ type: 'payment.allowed_payees';
59
+ allowed: Merchant[];
60
+ } | {
61
+ type: 'payment.allowed_payment_instruments';
62
+ allowed: PaymentInstrument[];
63
+ } | {
64
+ type: 'payment.allowed_pisps';
65
+ allowed: Pisp[];
66
+ } | {
67
+ type: 'payment.amount_range';
68
+ currency: string;
69
+ max: number;
70
+ min?: number;
71
+ } | {
72
+ type: 'payment.budget';
73
+ currency: string;
74
+ max: number;
75
+ } | {
76
+ type: 'payment.execution_date';
77
+ not_before?: string;
78
+ not_after?: string;
79
+ } | {
80
+ type: 'payment.reference';
81
+ conditional_transaction_id: string;
82
+ };
83
+ export interface LineItemRequirement {
84
+ id: string;
85
+ acceptable_items: CheckoutItem[];
86
+ quantity: number;
87
+ }
88
+ export type CheckoutConstraint = {
89
+ type: 'checkout.allowed_merchants';
90
+ allowed: Merchant[];
91
+ } | {
92
+ type: 'checkout.line_items';
93
+ items: LineItemRequirement[];
94
+ };
95
+ interface Common {
96
+ iat?: number;
97
+ exp?: number;
98
+ [PCA_CLAIM]?: JsonObject;
99
+ }
100
+ export interface OpenPaymentMandateClaims extends Common {
101
+ vct: typeof VCT_PAYMENT_OPEN;
102
+ constraints: PaymentConstraint[];
103
+ cnf: {
104
+ jwk: P256Jwk;
105
+ };
106
+ payee?: Merchant;
107
+ payment_amount?: Amount;
108
+ payment_instrument?: PaymentInstrument;
109
+ pisp?: Pisp;
110
+ execution_date?: string;
111
+ risk_data?: JsonObject;
112
+ }
113
+ export interface PaymentMandateClaims extends Common {
114
+ vct: typeof VCT_PAYMENT;
115
+ transaction_id: string;
116
+ payee: Merchant;
117
+ payment_amount: Amount;
118
+ payment_instrument: PaymentInstrument;
119
+ pisp?: Pisp;
120
+ execution_date?: string;
121
+ risk_data?: JsonObject;
122
+ }
123
+ export interface OpenCheckoutMandateClaims extends Common {
124
+ vct: typeof VCT_CHECKOUT_OPEN;
125
+ constraints: CheckoutConstraint[];
126
+ cnf: {
127
+ jwk: P256Jwk;
128
+ };
129
+ }
130
+ export interface CheckoutMandateClaims extends Common {
131
+ vct: typeof VCT_CHECKOUT;
132
+ checkout_jwt: string;
133
+ checkout_hash: string;
134
+ }
135
+ export declare function openPaymentMandateProblems(v: unknown): string[];
136
+ export declare function paymentMandateProblems(v: unknown): string[];
137
+ export declare function openCheckoutMandateProblems(v: unknown): string[];
138
+ export declare function checkoutMandateProblems(v: unknown): string[];
139
+ export declare function assertValid<T>(v: unknown, problems: (v: unknown) => string[], what: string): T;
140
+ export type { Json };