@atlasauth/pca-ap2 0.3.0 → 0.4.1
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 +36 -60
- package/dist/chain.d.ts +217 -0
- package/dist/chain.js +366 -0
- package/dist/chain.js.map +1 -0
- package/dist/constraints.d.ts +61 -0
- package/dist/constraints.js +271 -0
- package/dist/constraints.js.map +1 -0
- package/dist/index.d.ts +14 -324
- package/dist/index.js +28 -354
- package/dist/index.js.map +1 -1
- package/dist/mandates.d.ts +140 -0
- package/dist/mandates.js +279 -0
- package/dist/mandates.js.map +1 -0
- package/dist/pca.d.ts +147 -0
- package/dist/pca.js +313 -0
- package/dist/pca.js.map +1 -0
- package/dist/sdjwt.d.ts +129 -0
- package/dist/sdjwt.js +394 -0
- package/dist/sdjwt.js.map +1 -0
- package/dist/settlement.d.ts +47 -0
- package/dist/settlement.js +91 -0
- package/dist/settlement.js.map +1 -0
- package/package.json +4 -4
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.merchantMatches = merchantMatches;
|
|
4
|
+
exports.checkPaymentConstraints = checkPaymentConstraints;
|
|
5
|
+
exports.projectCheckout = projectCheckout;
|
|
6
|
+
exports.checkoutTotal = checkoutTotal;
|
|
7
|
+
exports.checkCheckoutConstraints = checkCheckoutConstraints;
|
|
8
|
+
const mandates_1 = require("./mandates");
|
|
9
|
+
const sdjwt_1 = require("./sdjwt");
|
|
10
|
+
function merchantMatches(candidate, target) {
|
|
11
|
+
if (candidate.id && target.id)
|
|
12
|
+
return candidate.id === target.id;
|
|
13
|
+
return !!candidate.name && !!candidate.website && candidate.name === target.name && candidate.website === target.website;
|
|
14
|
+
}
|
|
15
|
+
const sameJson = (a, b) => JSON.stringify(sortKeys(a)) === JSON.stringify(sortKeys(b));
|
|
16
|
+
function sortKeys(v) {
|
|
17
|
+
if (Array.isArray(v))
|
|
18
|
+
return v.map(sortKeys);
|
|
19
|
+
if ((0, sdjwt_1.isObject)(v))
|
|
20
|
+
return Object.fromEntries(Object.keys(v).sort().map((k) => [k, sortKeys(v[k])]));
|
|
21
|
+
return v;
|
|
22
|
+
}
|
|
23
|
+
function parseInstant(s) {
|
|
24
|
+
const t = Date.parse(s);
|
|
25
|
+
return Number.isFinite(t) ? t : undefined;
|
|
26
|
+
}
|
|
27
|
+
/** Start (epoch ms, UTC) of the calendar period of `frequency` that contains `ms`. */
|
|
28
|
+
function periodStart(ms, frequency) {
|
|
29
|
+
const d = new Date(ms);
|
|
30
|
+
const day = Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate());
|
|
31
|
+
const DAY = 86_400_000;
|
|
32
|
+
switch (frequency) {
|
|
33
|
+
case 'ON_DEMAND':
|
|
34
|
+
return 0;
|
|
35
|
+
case 'DAILY':
|
|
36
|
+
return day;
|
|
37
|
+
case 'WEEKLY':
|
|
38
|
+
return day - ((d.getUTCDay() + 6) % 7) * DAY; // Monday
|
|
39
|
+
case 'BIWEEKLY': {
|
|
40
|
+
const weekStart = day - ((d.getUTCDay() + 6) % 7) * DAY;
|
|
41
|
+
const WEEK = 7 * DAY;
|
|
42
|
+
const epochMonday = -3 * DAY; // 1970-01-01 was a Thursday; the Monday before is -3 days
|
|
43
|
+
return epochMonday + Math.floor((weekStart - epochMonday) / (2 * WEEK)) * 2 * WEEK;
|
|
44
|
+
}
|
|
45
|
+
case 'MONTHLY':
|
|
46
|
+
return Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), 1);
|
|
47
|
+
case 'QUARTERLY':
|
|
48
|
+
return Date.UTC(d.getUTCFullYear(), Math.floor(d.getUTCMonth() / 3) * 3, 1);
|
|
49
|
+
case 'ANNUALLY':
|
|
50
|
+
return Date.UTC(d.getUTCFullYear(), 0, 1);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function evaluatePayment(c, closed, o) {
|
|
54
|
+
const amt = closed.payment_amount;
|
|
55
|
+
switch (c.type) {
|
|
56
|
+
case 'payment.amount_range': {
|
|
57
|
+
const v = [];
|
|
58
|
+
if (amt.currency !== c.currency)
|
|
59
|
+
v.push(`currency mismatch: expected ${c.currency}, got ${amt.currency}`);
|
|
60
|
+
if (c.min !== undefined && amt.amount < c.min)
|
|
61
|
+
v.push(`amount ${amt.amount} below minimum ${c.min}`);
|
|
62
|
+
if (amt.amount > c.max)
|
|
63
|
+
v.push(`amount ${amt.amount} exceeds maximum ${c.max}`);
|
|
64
|
+
return v;
|
|
65
|
+
}
|
|
66
|
+
case 'payment.allowed_payees':
|
|
67
|
+
return c.allowed.some((m) => merchantMatches(m, closed.payee)) ? [] : [`payee ${closed.payee.name} is not in the allowed list`];
|
|
68
|
+
case 'payment.allowed_payment_instruments':
|
|
69
|
+
return c.allowed.some((i) => i.id === closed.payment_instrument.id) ? [] : [`payment instrument ${closed.payment_instrument.id} is not in the allowed list`];
|
|
70
|
+
case 'payment.allowed_pisps': {
|
|
71
|
+
const p = closed.pisp;
|
|
72
|
+
if (!p)
|
|
73
|
+
return ['missing PISP in the closed mandate'];
|
|
74
|
+
return c.allowed.some((a) => a.legal_name === p.legal_name && a.brand_name === p.brand_name && a.domain_name === p.domain_name) ? [] : ['PISP is not in the allowed list'];
|
|
75
|
+
}
|
|
76
|
+
case 'payment.reference': {
|
|
77
|
+
if (!o.openCheckoutHash)
|
|
78
|
+
return ['openCheckoutHash is required to evaluate a payment.reference constraint'];
|
|
79
|
+
return o.openCheckoutHash === c.conditional_transaction_id ? [] : ['payment.reference does not match the open checkout mandate hash'];
|
|
80
|
+
}
|
|
81
|
+
case 'payment.budget': {
|
|
82
|
+
if (amt.currency !== c.currency)
|
|
83
|
+
return [`budget currency mismatch: expected ${c.currency}, got ${amt.currency}`];
|
|
84
|
+
// The official SDK converts the budget with `int(max * 100)`; any other exponent would be read differently by it.
|
|
85
|
+
if ((0, mandates_1.currencyExponent)(c.currency) !== 2)
|
|
86
|
+
return [`budget in ${c.currency} is unsupported: budget.max is converted with a fixed x100 factor`];
|
|
87
|
+
if (!o.context)
|
|
88
|
+
return ['mandate context is required to evaluate a budget'];
|
|
89
|
+
const scaled = c.max * 100;
|
|
90
|
+
const maxMinor = Math.round(scaled);
|
|
91
|
+
if (Math.abs(scaled - maxMinor) > 1e-6)
|
|
92
|
+
return ['budget.max is not a whole number of minor units'];
|
|
93
|
+
const spend = o.context.totalAmount + amt.amount;
|
|
94
|
+
return spend > maxMinor ? [`cumulative spend ${spend} exceeds budget ${maxMinor} (past spend ${o.context.totalAmount})`] : [];
|
|
95
|
+
}
|
|
96
|
+
case 'payment.agent_recurrence': {
|
|
97
|
+
const v = [];
|
|
98
|
+
if (c.max_occurrences !== undefined) {
|
|
99
|
+
if (!o.context)
|
|
100
|
+
return ['mandate context is required to evaluate recurrence limits'];
|
|
101
|
+
if (o.context.totalUses >= c.max_occurrences)
|
|
102
|
+
v.push(`maximum occurrences exceeded: ${o.context.totalUses} >= ${c.max_occurrences}`);
|
|
103
|
+
}
|
|
104
|
+
if (c.frequency !== 'ON_DEMAND') {
|
|
105
|
+
if (!o.context)
|
|
106
|
+
return ['mandate context is required to evaluate recurrence frequency'];
|
|
107
|
+
const last = o.context.lastUsedDate;
|
|
108
|
+
if (last !== undefined && last * 1000 >= periodStart(o.now * 1000, c.frequency))
|
|
109
|
+
v.push(`already used in the current ${c.frequency} period`);
|
|
110
|
+
}
|
|
111
|
+
return v;
|
|
112
|
+
}
|
|
113
|
+
case 'payment.execution_date': {
|
|
114
|
+
const at = closed.execution_date !== undefined ? parseInstant(closed.execution_date) : o.now * 1000;
|
|
115
|
+
if (at === undefined)
|
|
116
|
+
return [`execution_date ${String(closed.execution_date)} is not a valid instant`];
|
|
117
|
+
const v = [];
|
|
118
|
+
for (const [key, bound, before] of [['not_before', c.not_before, true], ['not_after', c.not_after, false]]) {
|
|
119
|
+
if (bound === undefined)
|
|
120
|
+
continue;
|
|
121
|
+
const b = parseInstant(bound);
|
|
122
|
+
if (b === undefined)
|
|
123
|
+
v.push(`${key} ${bound} is not a valid instant`);
|
|
124
|
+
else if (before ? at < b : at > b)
|
|
125
|
+
v.push(`execution date is ${before ? 'before' : 'after'} the allowed window (${key} ${bound})`);
|
|
126
|
+
}
|
|
127
|
+
return v;
|
|
128
|
+
}
|
|
129
|
+
default:
|
|
130
|
+
return [`unknown constraint type ${String(c.type)}`];
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/** Violations of the open payment mandate's constraints and pre-set claims by `closed` (empty = satisfied). */
|
|
134
|
+
function checkPaymentConstraints(open, closed, o) {
|
|
135
|
+
const v = [];
|
|
136
|
+
if (open.payee !== undefined && !merchantMatches(open.payee, closed.payee))
|
|
137
|
+
v.push(`pre-set payee mismatch: expected ${open.payee.name}, got ${closed.payee.name}`);
|
|
138
|
+
if (open.payment_amount !== undefined && !sameJson(open.payment_amount, closed.payment_amount))
|
|
139
|
+
v.push('pre-set payment_amount mismatch');
|
|
140
|
+
if (open.payment_instrument !== undefined && !sameJson(open.payment_instrument, closed.payment_instrument))
|
|
141
|
+
v.push('pre-set payment_instrument mismatch');
|
|
142
|
+
if (open.pisp !== undefined && !sameJson(open.pisp, closed.pisp))
|
|
143
|
+
v.push('pre-set pisp mismatch');
|
|
144
|
+
if (open.execution_date !== undefined && open.execution_date !== closed.execution_date)
|
|
145
|
+
v.push('pre-set execution_date mismatch');
|
|
146
|
+
const types = new Set(open.constraints.map((c) => c.type));
|
|
147
|
+
if (types.has('payment.agent_recurrence')) {
|
|
148
|
+
if (!types.has('payment.amount_range'))
|
|
149
|
+
v.push('payment.agent_recurrence requires a payment.amount_range constraint');
|
|
150
|
+
if (!types.has('payment.budget'))
|
|
151
|
+
v.push('payment.agent_recurrence requires a payment.budget constraint');
|
|
152
|
+
}
|
|
153
|
+
for (const c of open.constraints)
|
|
154
|
+
v.push(...evaluatePayment(c, closed, o));
|
|
155
|
+
return v;
|
|
156
|
+
}
|
|
157
|
+
/** Validate and project the checkout payload; throws a descriptive message when malformed. */
|
|
158
|
+
function projectCheckout(payload) {
|
|
159
|
+
const bad = (m) => {
|
|
160
|
+
throw new Error(`checkout_jwt payload: ${m}`);
|
|
161
|
+
};
|
|
162
|
+
if (typeof payload.id !== 'string' || !payload.id)
|
|
163
|
+
bad('id is required');
|
|
164
|
+
if (typeof payload.currency !== 'string' || !/^[A-Z]{3}$/.test(payload.currency))
|
|
165
|
+
bad('currency must be ISO 4217');
|
|
166
|
+
if (!Array.isArray(payload.line_items) || payload.line_items.length === 0)
|
|
167
|
+
bad('line_items must be a non-empty array');
|
|
168
|
+
if (!Array.isArray(payload.totals))
|
|
169
|
+
bad('totals must be an array');
|
|
170
|
+
const line_items = payload.line_items.map((li, i) => {
|
|
171
|
+
if (!(0, sdjwt_1.isObject)(li) || typeof li.id !== 'string' || !(0, sdjwt_1.isObject)(li.item))
|
|
172
|
+
return bad(`line_items[${i}] is malformed`);
|
|
173
|
+
const item = li.item;
|
|
174
|
+
if (typeof item.id !== 'string' || typeof item.title !== 'string' || !Number.isSafeInteger(item.price) || item.price < 0)
|
|
175
|
+
bad(`line_items[${i}].item needs id, title and integer minor-unit price`);
|
|
176
|
+
if (!Number.isSafeInteger(li.quantity) || li.quantity < 1)
|
|
177
|
+
bad(`line_items[${i}].quantity must be a positive integer`);
|
|
178
|
+
return { id: li.id, item: { id: item.id, title: item.title, price: item.price }, quantity: li.quantity };
|
|
179
|
+
});
|
|
180
|
+
const totals = payload.totals.map((t, i) => {
|
|
181
|
+
if (!(0, sdjwt_1.isObject)(t) || typeof t.type !== 'string' || !Number.isSafeInteger(t.amount))
|
|
182
|
+
return bad(`totals[${i}] is malformed`);
|
|
183
|
+
return { type: t.type, amount: t.amount };
|
|
184
|
+
});
|
|
185
|
+
let merchant;
|
|
186
|
+
if (payload.merchant !== undefined) {
|
|
187
|
+
const m = payload.merchant;
|
|
188
|
+
if (!(0, sdjwt_1.isObject)(m) || typeof m.id !== 'string' || typeof m.name !== 'string')
|
|
189
|
+
bad('merchant needs id and name');
|
|
190
|
+
const mm = m;
|
|
191
|
+
merchant = { id: mm.id, name: mm.name, ...(typeof mm.website === 'string' ? { website: mm.website } : {}) };
|
|
192
|
+
}
|
|
193
|
+
return { id: payload.id, currency: payload.currency, line_items, totals, ...(merchant ? { merchant } : {}) };
|
|
194
|
+
}
|
|
195
|
+
/** The checkout's single `total` entry in minor units, or undefined if absent / ambiguous. */
|
|
196
|
+
function checkoutTotal(c) {
|
|
197
|
+
const t = c.totals.filter((x) => x.type === 'total');
|
|
198
|
+
return t.length === 1 ? t[0]?.amount : undefined;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Maximal-flow assignment of cart quantities to requirement slots (Edmonds-Karp on the bipartite
|
|
202
|
+
* graph of the documentation): satisfied iff the flow equals both the required and the carted total.
|
|
203
|
+
*/
|
|
204
|
+
function lineItemViolations(cart, reqs) {
|
|
205
|
+
const qty = new Map();
|
|
206
|
+
for (const li of cart)
|
|
207
|
+
qty.set(li.item.id, (qty.get(li.item.id) ?? 0) + li.quantity);
|
|
208
|
+
const skus = [...qty.keys()];
|
|
209
|
+
const S = 0;
|
|
210
|
+
const T = 1 + skus.length + reqs.length;
|
|
211
|
+
const cap = Array.from({ length: T + 1 }, () => new Map());
|
|
212
|
+
const add = (u, v, c) => {
|
|
213
|
+
cap[u]?.set(v, (cap[u]?.get(v) ?? 0) + c);
|
|
214
|
+
cap[v]?.set(u, cap[v]?.get(u) ?? 0);
|
|
215
|
+
};
|
|
216
|
+
const INF = Number.MAX_SAFE_INTEGER;
|
|
217
|
+
skus.forEach((s, i) => add(S, 1 + i, qty.get(s)));
|
|
218
|
+
reqs.forEach((r, j) => {
|
|
219
|
+
add(1 + skus.length + j, T, r.quantity);
|
|
220
|
+
const ok = new Set(r.acceptable_items.map((a) => a.id));
|
|
221
|
+
skus.forEach((s, i) => {
|
|
222
|
+
if (ok.has(s))
|
|
223
|
+
add(1 + i, 1 + skus.length + j, INF);
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
let flow = 0;
|
|
227
|
+
for (;;) {
|
|
228
|
+
const parent = new Map([[S, S]]);
|
|
229
|
+
const queue = [S];
|
|
230
|
+
for (let h = 0; h < queue.length && !parent.has(T); h++) {
|
|
231
|
+
const u = queue[h];
|
|
232
|
+
for (const [v, c] of cap[u] ?? [])
|
|
233
|
+
if (c > 0 && !parent.has(v)) {
|
|
234
|
+
parent.set(v, u);
|
|
235
|
+
queue.push(v);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
if (!parent.has(T))
|
|
239
|
+
break;
|
|
240
|
+
let push = INF;
|
|
241
|
+
for (let v = T; v !== S; v = parent.get(v))
|
|
242
|
+
push = Math.min(push, cap[parent.get(v)]?.get(v));
|
|
243
|
+
for (let v = T; v !== S; v = parent.get(v)) {
|
|
244
|
+
const u = parent.get(v);
|
|
245
|
+
cap[u]?.set(v, cap[u]?.get(v) - push);
|
|
246
|
+
cap[v]?.set(u, cap[v]?.get(u) + push);
|
|
247
|
+
}
|
|
248
|
+
flow += push;
|
|
249
|
+
}
|
|
250
|
+
const required = reqs.reduce((a, r) => a + r.quantity, 0);
|
|
251
|
+
const carted = [...qty.values()].reduce((a, b) => a + b, 0);
|
|
252
|
+
if (flow === required && flow === carted)
|
|
253
|
+
return [];
|
|
254
|
+
return [`line items do not satisfy the constraint: assigned ${flow} of ${required} required and ${carted} carted units`];
|
|
255
|
+
}
|
|
256
|
+
function evaluateCheckout(c, checkout) {
|
|
257
|
+
if (c.type === 'checkout.allowed_merchants') {
|
|
258
|
+
if (!checkout.merchant)
|
|
259
|
+
return ['missing merchant in the checkout'];
|
|
260
|
+
const m = checkout.merchant;
|
|
261
|
+
return c.allowed.some((a) => merchantMatches(a, m)) ? [] : [`merchant ${m.name} is not in the allowed list`];
|
|
262
|
+
}
|
|
263
|
+
if (c.type !== 'checkout.line_items')
|
|
264
|
+
return [`unknown constraint type ${String(c.type)}`];
|
|
265
|
+
return checkout.line_items.length === 0 ? ['empty cart does not satisfy a line_items constraint'] : lineItemViolations(checkout.line_items, c.items);
|
|
266
|
+
}
|
|
267
|
+
/** Violations of the open checkout mandate's constraints by `checkout` (empty = satisfied). */
|
|
268
|
+
function checkCheckoutConstraints(open, checkout) {
|
|
269
|
+
return open.constraints.flatMap((c) => evaluateCheckout(c, checkout));
|
|
270
|
+
}
|
|
271
|
+
//# sourceMappingURL=constraints.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constraints.js","sourceRoot":"","sources":["../src/constraints.ts"],"names":[],"mappings":";;AAqCA,0CAGC;AAmHD,0DAeC;AAgBD,0CA2BC;AAGD,sCAGC;AAgED,4DAEC;AArQD,yCAA8C;AAC9C,mCAAoD;AAYpD,SAAgB,eAAe,CAAC,SAAmB,EAAE,MAAgB;IACnE,IAAI,SAAS,CAAC,EAAE,IAAI,MAAM,CAAC,EAAE;QAAE,OAAO,SAAS,CAAC,EAAE,KAAK,MAAM,CAAC,EAAE,CAAC;IACjE,OAAO,CAAC,CAAC,SAAS,CAAC,IAAI,IAAI,CAAC,CAAC,SAAS,CAAC,OAAO,IAAI,SAAS,CAAC,IAAI,KAAK,MAAM,CAAC,IAAI,IAAI,SAAS,CAAC,OAAO,KAAK,MAAM,CAAC,OAAO,CAAC;AAC3H,CAAC;AAED,MAAM,QAAQ,GAAG,CAAC,CAAU,EAAE,CAAU,EAAW,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;AAClH,SAAS,QAAQ,CAAC,CAAU;IAC1B,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;QAAE,OAAO,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC7C,IAAI,IAAA,gBAAQ,EAAC,CAAC,CAAC;QAAE,OAAO,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,I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,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,IAAI,6BAA6B,CAAC,CAAC;IAC/G,CAAC;IACD,IAAI,CAAC,CAAC,IAAI,KAAK,qBAAqB;QAAE,OAAO,CAAC,2BAA2B,MAAM,CAAE,CAAwB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACnH,OAAO,QAAQ,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,qDAAqD,CAAC,CAAC,CAAC,CAAC,kBAAkB,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC;AACvJ,CAAC;AAED,+FAA+F;AAC/F,SAAgB,wBAAwB,CAAC,IAA+B,EAAE,QAAqB;IAC7F,OAAO,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,gBAAgB,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC;AACxE,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,325 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @atlasauth/pca-ap2
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
* That validation has now been run (see conformance.test.ts): the output does NOT conform to the current
|
|
36
|
-
* official SD-JWT mandate schemas, so treat this as a PCA rendition of the concepts, not the AP2 wire format.
|
|
37
|
-
* PCA-native terms that AP2 has no field for are carried in a namespaced `x_pca` extension so the chain
|
|
38
|
-
* can round-trip back to PCA terms; those fields are non-standard by construction.
|
|
39
|
-
*/
|
|
40
|
-
import type { MandateTerms, PaymentMandate as PcaPaymentMandate } from '@atlasauth/pca-payments';
|
|
41
|
-
/** The AP2 shape this module models. See the HONEST CAVEAT above. */
|
|
42
|
-
export declare const AP2_VERSION: "0.2";
|
|
43
|
-
/**
|
|
44
|
-
* Illustrative JSON-LD contexts for the VDC envelope. The second entry is a placeholder for the AP2
|
|
45
|
-
* context URL — replace with the canonical context from the AP2 repo before production.
|
|
46
|
-
*/
|
|
47
|
-
export declare const AP2_CONTEXT: readonly string[];
|
|
48
|
-
/** ISO-4217 currency + decimal value (use minor units in production to avoid float drift). */
|
|
49
|
-
export interface MonetaryAmount {
|
|
50
|
-
currency: string;
|
|
51
|
-
value: number;
|
|
52
|
-
}
|
|
53
|
-
export type AP2MandateType = 'IntentMandate' | 'CartMandate' | 'PaymentMandate';
|
|
54
|
-
/**
|
|
55
|
-
* A detached signature over the canonicalized credential body (everything except `proof`). Structural
|
|
56
|
-
* analogue of a JWS / Data-Integrity proof; signed with the issuer's Ed25519 key (PCA's own `sign`).
|
|
57
|
-
*/
|
|
58
|
-
export interface AP2Proof {
|
|
59
|
-
type: 'Ed25519Signature2020';
|
|
60
|
-
/** ISO timestamp the proof was created. */
|
|
61
|
-
created: string;
|
|
62
|
-
/** The issuer public key (b64u) the signature verifies under; equals the VDC `issuer`. */
|
|
63
|
-
verificationMethod: string;
|
|
64
|
-
proofPurpose: 'assertionMethod';
|
|
65
|
-
/** b64u Ed25519 signature over `canonicalBytes(<credential without proof>)`. */
|
|
66
|
-
signatureValue: string;
|
|
67
|
-
}
|
|
68
|
-
/** A signed (or signable) Verifiable Digital Credential carrying one AP2 mandate. */
|
|
69
|
-
export interface VerifiableDigitalCredential<T extends AP2MandateType, S> {
|
|
70
|
-
'@context': readonly string[];
|
|
71
|
-
type: readonly ['VerifiableCredential', T];
|
|
72
|
-
/** Issuer public key (b64u). Intent: the user/principal. Cart: the merchant. Payment: the payer. */
|
|
73
|
-
issuer: string;
|
|
74
|
-
/** ISO issuance time. */
|
|
75
|
-
issuanceDate: string;
|
|
76
|
-
/** ISO expiry, when the mandate names one. */
|
|
77
|
-
expirationDate?: string;
|
|
78
|
-
credentialSubject: S;
|
|
79
|
-
/** Present once signed (see {@link signMandate}). */
|
|
80
|
-
proof?: AP2Proof;
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* PCA-native extension carried inside an Intent Mandate so the VDC chain can round-trip back to the
|
|
84
|
-
* attenuating PCA terms AP2 has no standard field for. NON-STANDARD by construction (namespaced).
|
|
85
|
-
*/
|
|
86
|
-
export interface PcaIntentExtension {
|
|
87
|
-
/** Y — at/under ⇒ autonomous (human_present can be false); over ⇒ human co-sign (tier 3). */
|
|
88
|
-
auto_approve_threshold: number;
|
|
89
|
-
/** bMax — total autonomous spend between human co-signs. */
|
|
90
|
-
cumulative_cap: number;
|
|
91
|
-
/** X — hard per-transaction ceiling (mirrors `max_amount.value`). */
|
|
92
|
-
per_transaction_cap: number;
|
|
93
|
-
period_start?: number;
|
|
94
|
-
period_end?: number;
|
|
95
|
-
max_transactions_per_period?: number;
|
|
96
|
-
/** The PCA grant's salted goal commitment, if the source was a full PaymentMandate. */
|
|
97
|
-
goal_commit?: string;
|
|
98
|
-
}
|
|
99
|
-
/** IntentMandate: the user's natural-language/structured intent + the constraints the agent must obey. */
|
|
100
|
-
export interface IntentMandateContents {
|
|
101
|
-
natural_language_description: string;
|
|
102
|
-
/** Allowlisted merchant ids; `null` = any merchant (AP2 uses null for "unconstrained"). */
|
|
103
|
-
merchants: string[] | null;
|
|
104
|
-
/** Allowlisted SKUs; `null` = any. */
|
|
105
|
-
skus: string[] | null;
|
|
106
|
-
/** Allowlisted MCC categories; omitted = any. */
|
|
107
|
-
categories?: string[];
|
|
108
|
-
/** The ceiling a single purchase under this intent may reach (PCA's hard per-transaction cap X). */
|
|
109
|
-
max_amount: MonetaryAmount;
|
|
110
|
-
/** Whether purchases must be refundable/bonded (PCA mints charges in the `reversible` class ⇒ true). */
|
|
111
|
-
required_refundability: boolean;
|
|
112
|
-
/** Whether the user must confirm the concrete cart before payment (maps from PCA Y < X). */
|
|
113
|
-
user_cart_confirmation_required: boolean;
|
|
114
|
-
/** ISO expiry of the intent, if any. */
|
|
115
|
-
intent_expiry?: string;
|
|
116
|
-
/** PCA-native round-trip extension (non-standard). */
|
|
117
|
-
x_pca?: PcaIntentExtension;
|
|
118
|
-
}
|
|
119
|
-
/** A concrete line item the merchant commits to in a cart. */
|
|
120
|
-
export interface CartItem {
|
|
121
|
-
sku?: string;
|
|
122
|
-
name: string;
|
|
123
|
-
quantity: number;
|
|
124
|
-
unit_price: MonetaryAmount;
|
|
125
|
-
}
|
|
126
|
-
/** CartMandate: the concrete items/amounts the merchant commits, bound to the intent it fulfils. */
|
|
127
|
-
export interface CartMandateContents {
|
|
128
|
-
/** Stable cart id. */
|
|
129
|
-
id: string;
|
|
130
|
-
/** The merchant this cart is with (matched against the intent allowlist). */
|
|
131
|
-
merchant: string;
|
|
132
|
-
items: CartItem[];
|
|
133
|
-
/** The committed total (Σ quantity · unit_price). */
|
|
134
|
-
total: MonetaryAmount;
|
|
135
|
-
/** Hash of the IntentMandate VDC this cart fulfils — binds cart → intent. */
|
|
136
|
-
intent_reference?: string;
|
|
137
|
-
/** ISO expiry of the cart quote, if any. */
|
|
138
|
-
cart_expiry?: string;
|
|
139
|
-
}
|
|
140
|
-
/** The payment instrument a payment mandate authorizes. */
|
|
141
|
-
export interface PaymentMethod {
|
|
142
|
-
/** e.g. `card`, `crypto`, `shared_payment_token`, `x402`. */
|
|
143
|
-
type: string;
|
|
144
|
-
display?: string;
|
|
145
|
-
/** Opaque token (e.g. a Stripe Shared Payment Token id); never a raw PAN. */
|
|
146
|
-
token?: string;
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* PaymentMandate: the minimal payment authorization derived from the cart. Carries the human-present /
|
|
150
|
-
* human-not-present modality signal and binds to the cart (and intent) by hash — WITHOUT re-exposing
|
|
151
|
-
* the full cart contents.
|
|
152
|
-
*/
|
|
153
|
-
export interface PaymentMandateContents {
|
|
154
|
-
/** Hash of the CartMandate VDC — binds payment → cart. */
|
|
155
|
-
cart_hash: string;
|
|
156
|
-
/** Hash of the IntentMandate VDC — binds payment → intent (optional but recommended). */
|
|
157
|
-
intent_hash?: string;
|
|
158
|
-
amount: MonetaryAmount;
|
|
159
|
-
payment_method: PaymentMethod;
|
|
160
|
-
/**
|
|
161
|
-
* The AP2 modality signal. MAPPING: PCA tier-3 human step-up ⇒ `human_present = true`; a tier-1
|
|
162
|
-
* autonomous charge (amount ≤ Y, budget available) ⇒ `human_present = false` (human-not-present).
|
|
163
|
-
*/
|
|
164
|
-
human_present: boolean;
|
|
165
|
-
merchant?: string;
|
|
166
|
-
}
|
|
167
|
-
export type IntentMandate = VerifiableDigitalCredential<'IntentMandate', IntentMandateContents>;
|
|
168
|
-
export type CartMandate = VerifiableDigitalCredential<'CartMandate', CartMandateContents>;
|
|
169
|
-
/** AP2's Payment Mandate VDC (NOT the PCA `PaymentMandate` grant from `@atlasauth/pca-payments`). */
|
|
170
|
-
export type PaymentMandate = VerifiableDigitalCredential<'PaymentMandate', PaymentMandateContents>;
|
|
171
|
-
export type AnyAP2Mandate = IntentMandate | CartMandate | PaymentMandate;
|
|
172
|
-
/** Sign a VDC with the issuer's Ed25519 secret key, returning a copy carrying the `proof`. */
|
|
173
|
-
export declare function signMandate<T extends AP2MandateType, S>(vdc: VerifiableDigitalCredential<T, S>, secretKey: Uint8Array): VerifiableDigitalCredential<T, S>;
|
|
174
|
-
/** Verify a VDC's detached signature. Returns false when unsigned or the signature does not verify. */
|
|
175
|
-
export declare function verifyMandate(vdc: AnyAP2Mandate): boolean;
|
|
176
|
-
/** Stable content hash of a VDC (used to bind one mandate to the next). */
|
|
177
|
-
export declare function mandateHash(vdc: AnyAP2Mandate): string;
|
|
178
|
-
export interface IntentMapOptions {
|
|
179
|
-
/** Issuer (user/principal) public key, b64u. */
|
|
180
|
-
issuerPublic: string;
|
|
181
|
-
/** If present, the Intent VDC is signed with this Ed25519 secret key. */
|
|
182
|
-
issuerSecret?: Uint8Array;
|
|
183
|
-
/** Override the natural-language description (else derived from the terms). */
|
|
184
|
-
naturalLanguageDescription?: string;
|
|
185
|
-
/** Allowlisted SKUs, or null for any (default null). */
|
|
186
|
-
skus?: string[] | null;
|
|
187
|
-
/** Override `user_cart_confirmation_required` (default: Y < X ⇒ true). */
|
|
188
|
-
userCartConfirmationRequired?: boolean;
|
|
189
|
-
/** Issuance clock (ms). Default `Date.now()`. */
|
|
190
|
-
now?: number;
|
|
191
|
-
}
|
|
192
|
-
/** Map a PCA payment mandate (or raw terms) to an AP2 Intent Mandate VDC. */
|
|
193
|
-
export declare function toAP2IntentMandate(mandate: PcaPaymentMandate | MandateTerms, opts: IntentMapOptions): IntentMandate;
|
|
194
|
-
export interface CartInput {
|
|
195
|
-
merchant: string;
|
|
196
|
-
items: CartItem[];
|
|
197
|
-
/** Currency; defaults to the intent's `max_amount.currency`. */
|
|
198
|
-
currency?: string;
|
|
199
|
-
/** Stable cart id; derived from the item digest when omitted. */
|
|
200
|
-
id?: string;
|
|
201
|
-
/** Cart-quote expiry (ms). */
|
|
202
|
-
expiry?: number;
|
|
203
|
-
now?: number;
|
|
204
|
-
}
|
|
205
|
-
export interface CartMapOptions {
|
|
206
|
-
/** Issuer (merchant) public key, b64u. */
|
|
207
|
-
issuerPublic: string;
|
|
208
|
-
/** If present, the Cart VDC is signed with this Ed25519 secret key. */
|
|
209
|
-
issuerSecret?: Uint8Array;
|
|
210
|
-
}
|
|
211
|
-
/** Narrow an Intent Mandate into a concrete AP2 Cart Mandate VDC (items + committed total). */
|
|
212
|
-
export declare function toAP2CartMandate(intent: IntentMandate, cart: CartInput, opts: CartMapOptions): CartMandate;
|
|
213
|
-
export interface PaymentMapOptions {
|
|
214
|
-
/** Issuer (payer/user agent) public key, b64u. */
|
|
215
|
-
issuerPublic: string;
|
|
216
|
-
/** If present, the Payment VDC is signed with this Ed25519 secret key. */
|
|
217
|
-
issuerSecret?: Uint8Array;
|
|
218
|
-
paymentMethod: PaymentMethod;
|
|
219
|
-
/** Amount to authorize; defaults to the cart total (and must not exceed it to stay a narrowing). */
|
|
220
|
-
amount?: MonetaryAmount;
|
|
221
|
-
/**
|
|
222
|
-
* The human-present modality. If omitted, derived from `pcaTier` (tier 3 ⇒ true); if that is also
|
|
223
|
-
* omitted, defaults to `false` (human-not-present).
|
|
224
|
-
*/
|
|
225
|
-
humanPresent?: boolean;
|
|
226
|
-
/** PCA required-threshold tier for this charge (1 autonomous … 3 human co-sign). */
|
|
227
|
-
pcaTier?: number;
|
|
228
|
-
/** The Intent Mandate, if available — lets the payment also bind to the intent by hash. */
|
|
229
|
-
intent?: IntentMandate;
|
|
230
|
-
now?: number;
|
|
231
|
-
}
|
|
232
|
-
/** Narrow a Cart Mandate into an AP2 Payment Mandate VDC (the payment authorization + modality). */
|
|
233
|
-
export declare function toAP2PaymentMandate(cart: CartMandate, opts: PaymentMapOptions): PaymentMandate;
|
|
234
|
-
/** The PCA-facing view recovered from an AP2 mandate (fields depend on the mandate type). */
|
|
235
|
-
export interface ParsedAP2Mandate {
|
|
236
|
-
type: AP2MandateType;
|
|
237
|
-
/** Intent: the allowlist (absent/null ⇒ any). */
|
|
238
|
-
merchants?: string[];
|
|
239
|
-
categories?: string[];
|
|
240
|
-
currency?: string;
|
|
241
|
-
/** Intent: X (from `max_amount`); also recovered from `x_pca`. */
|
|
242
|
-
perTransactionCap?: number;
|
|
243
|
-
/** Intent: Y (from `x_pca`). */
|
|
244
|
-
autoApproveThreshold?: number;
|
|
245
|
-
/** Intent: bMax (from `x_pca`). */
|
|
246
|
-
cumulativeCap?: number;
|
|
247
|
-
periodStart?: number;
|
|
248
|
-
periodEnd?: number;
|
|
249
|
-
maxTransactionsPerPeriod?: number;
|
|
250
|
-
goalCommit?: string;
|
|
251
|
-
/** Cart/Payment: the concrete amount. */
|
|
252
|
-
amount?: number;
|
|
253
|
-
/** Cart/Payment: the concrete merchant. */
|
|
254
|
-
merchant?: string;
|
|
255
|
-
/** Payment: the modality signal. */
|
|
256
|
-
humanPresent?: boolean;
|
|
257
|
-
}
|
|
258
|
-
/** Parse an AP2 mandate VDC back toward PCA terms (lossless for an Intent minted with `x_pca`). */
|
|
259
|
-
export declare function fromAP2Mandate(vdc: AnyAP2Mandate): ParsedAP2Mandate;
|
|
260
|
-
export interface ChainVerification {
|
|
261
|
-
ok: boolean;
|
|
262
|
-
reasons: string[];
|
|
263
|
-
}
|
|
264
|
-
export interface AP2MandateChain {
|
|
265
|
-
intent: IntentMandate;
|
|
266
|
-
cart: CartMandate;
|
|
267
|
-
payment: PaymentMandate;
|
|
268
|
-
/** Verify the signatures, the hash bindings, and that each step is a non-amplifying narrowing. */
|
|
269
|
-
verify(): ChainVerification;
|
|
270
|
-
}
|
|
271
|
-
/**
|
|
272
|
-
* Verify an AP2 Intent→Cart→Payment chain: each VDC's signature, the hash bindings (cart→intent,
|
|
273
|
-
* payment→cart), and that every step only RESTRICTS the one above (never amplifies). This mirrors
|
|
274
|
-
* PCA's attenuation check: a child capability may narrow authority but never widen it.
|
|
275
|
-
*/
|
|
276
|
-
export declare function verifyAP2Chain(intent: IntentMandate, cart: CartMandate, payment: PaymentMandate): ChainVerification;
|
|
277
|
-
/** Assemble the signed Intent→Cart→Payment chain and attach its non-amplifying-narrowing verifier. */
|
|
278
|
-
export declare function chainMandates(intent: IntentMandate, cart: CartMandate, payment: PaymentMandate): AP2MandateChain;
|
|
279
|
-
/** Context the caller supplies for building a rail-specific settlement payload. */
|
|
280
|
-
export interface SettlementContext {
|
|
281
|
-
/** Protected resource URL (x402). */
|
|
282
|
-
resourceUrl?: string;
|
|
283
|
-
/** Payee address / account (x402 `payTo`, Stripe `on_behalf_of`). */
|
|
284
|
-
payTo?: string;
|
|
285
|
-
/** Rail network, e.g. an x402 chain id like `base-sepolia`. */
|
|
286
|
-
network?: string;
|
|
287
|
-
/** x402 `asset`: the token contract address. Defaults to the mandate's currency code (a placeholder; supply the address). */
|
|
288
|
-
asset?: string;
|
|
289
|
-
/** x402: decimals of the asset, used to convert the mandate amount to atomic units. Default 6 (USDC). */
|
|
290
|
-
decimals?: number;
|
|
291
|
-
/** x402 `maxTimeoutSeconds`: how long the payer has to complete payment. Default 60. */
|
|
292
|
-
maxTimeoutSeconds?: number;
|
|
293
|
-
}
|
|
294
|
-
/** A rail-specific settlement payload shape. No network is performed; this is the wire shape only. */
|
|
295
|
-
export interface SettlementInstruction {
|
|
296
|
-
rail: string;
|
|
297
|
-
amount: MonetaryAmount;
|
|
298
|
-
merchant?: string;
|
|
299
|
-
/** The rail-specific payload (structural). */
|
|
300
|
-
payload: Readonly<Record<string, unknown>>;
|
|
301
|
-
}
|
|
302
|
-
/**
|
|
303
|
-
* A settlement rail PCA's governance feeds. PCA + AP2 decide WHETHER a charge is authorized and carry
|
|
304
|
-
* the signed mandate; a `SettlementBackend` turns a verified Payment Mandate into the rail's wire shape.
|
|
305
|
-
* It never moves money here — it is the hook a real integration fills in.
|
|
306
|
-
*/
|
|
307
|
-
export interface SettlementBackend {
|
|
308
|
-
readonly rail: string;
|
|
309
|
-
/** Build the rail payload for a (presumed-verified) Payment Mandate. Pure; no network. */
|
|
310
|
-
settle(payment: PaymentMandate, ctx?: SettlementContext): SettlementInstruction;
|
|
311
|
-
}
|
|
312
|
-
/**
|
|
313
|
-
* Coinbase x402 adapter: models the HTTP 402 `Payment Required` challenge (the server's `accepts`
|
|
314
|
-
* payment requirements) plus the `X-PAYMENT` request header carrying the base64 payment payload the
|
|
315
|
-
* client re-sends. Structural only — the real rail settles on-chain. (Field names follow the public
|
|
316
|
-
* x402 shape and should be checked against the x402 spec before production.)
|
|
317
|
-
*/
|
|
318
|
-
export declare const x402Settlement: SettlementBackend;
|
|
319
|
-
/**
|
|
320
|
-
* Stripe Shared Payment Token adapter: models the SPT charge shape — a shared token the buyer's agent
|
|
321
|
-
* grants the merchant to pull a bounded amount. Structural only — a real integration calls Stripe with
|
|
322
|
-
* the token. Amount is converted to minor units (cents). (Check field names against Stripe's SPT docs
|
|
323
|
-
* before production.)
|
|
324
|
-
*/
|
|
325
|
-
export declare const stripeSptSettlement: SettlementBackend;
|
|
2
|
+
* @atlasauth/pca-ap2: AP2 (Agent Payments Protocol) mandates as real SD-JWT credentials, bound to a PCA grant.
|
|
3
|
+
*
|
|
4
|
+
* PCA governs: it decides who may spend, how much, until when, and when a human must co-sign. AP2 is
|
|
5
|
+
* the mandate wire other parties verify. Settlement rails (x402, Stripe Shared Payment Tokens) move
|
|
6
|
+
* the value, fed by PCA's decision.
|
|
7
|
+
*/
|
|
8
|
+
export * from './sdjwt';
|
|
9
|
+
export * from './mandates';
|
|
10
|
+
export * from './constraints';
|
|
11
|
+
export * from './chain';
|
|
12
|
+
export * from './pca';
|
|
13
|
+
export * from './settlement';
|
|
14
|
+
/** The AP2 repository commit whose schemas and documentation this package is checked against. */
|
|
15
|
+
export declare const AP2_COMMIT = "e1ea56db72a6385bce3e5c1112b3a56ce60acb43";
|