@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/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
package/dist/mandates.js
ADDED
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FREQUENCIES = exports.PCA_CLAIM = exports.VCT_PAYMENT_OPEN = exports.VCT_PAYMENT = exports.VCT_CHECKOUT_OPEN = exports.VCT_CHECKOUT = void 0;
|
|
4
|
+
exports.currencyExponent = currencyExponent;
|
|
5
|
+
exports.toMinorUnits = toMinorUnits;
|
|
6
|
+
exports.fromMinorUnits = fromMinorUnits;
|
|
7
|
+
exports.openPaymentMandateProblems = openPaymentMandateProblems;
|
|
8
|
+
exports.paymentMandateProblems = paymentMandateProblems;
|
|
9
|
+
exports.openCheckoutMandateProblems = openCheckoutMandateProblems;
|
|
10
|
+
exports.checkoutMandateProblems = checkoutMandateProblems;
|
|
11
|
+
exports.assertValid = assertValid;
|
|
12
|
+
/**
|
|
13
|
+
* AP2 mandate claim shapes (Intent/Cart/Payment, closed and open) and their validators.
|
|
14
|
+
*
|
|
15
|
+
* The shapes follow the official AP2 JSON Schemas (`checkout_mandate`, `open_checkout_mandate`,
|
|
16
|
+
* `payment_mandate`, `open_payment_mandate` and `types/*`). The validators are hand-written, check at
|
|
17
|
+
* least what those schemas check (the test-suite runs both against the same documents) and are
|
|
18
|
+
* stricter in places where a lax reading would be unsafe (non-negative safe-integer amounts,
|
|
19
|
+
* well-formed JWKs).
|
|
20
|
+
*/
|
|
21
|
+
const sdjwt_1 = require("./sdjwt");
|
|
22
|
+
// ---------------------------------------------------------------------------------------------
|
|
23
|
+
// vct values
|
|
24
|
+
// ---------------------------------------------------------------------------------------------
|
|
25
|
+
exports.VCT_CHECKOUT = 'mandate.checkout.1';
|
|
26
|
+
exports.VCT_CHECKOUT_OPEN = 'mandate.checkout.open.1';
|
|
27
|
+
exports.VCT_PAYMENT = 'mandate.payment.1';
|
|
28
|
+
exports.VCT_PAYMENT_OPEN = 'mandate.payment.open.1';
|
|
29
|
+
/** Namespaced claim carrying PCA's own proof inside a mandate object (see `pca.ts`). */
|
|
30
|
+
exports.PCA_CLAIM = 'x_pca';
|
|
31
|
+
// ---------------------------------------------------------------------------------------------
|
|
32
|
+
// currencies and minor units
|
|
33
|
+
// ---------------------------------------------------------------------------------------------
|
|
34
|
+
const ZERO_DECIMAL = new Set(['BIF', 'CLP', 'DJF', 'GNF', 'ISK', 'JPY', 'KMF', 'KRW', 'PYG', 'RWF', 'UGX', 'UYI', 'VND', 'VUV', 'XAF', 'XOF', 'XPF']);
|
|
35
|
+
const THREE_DECIMAL = new Set(['BHD', 'IQD', 'JOD', 'KWD', 'LYD', 'OMR', 'TND']);
|
|
36
|
+
const FOUR_DECIMAL = new Set(['CLF', 'UYW']);
|
|
37
|
+
/** ISO 4217 minor-unit exponent for `currency` (2 for any code not in the 0/3/4-digit tables). */
|
|
38
|
+
function currencyExponent(currency) {
|
|
39
|
+
if (!/^[A-Z]{3}$/.test(currency))
|
|
40
|
+
throw new sdjwt_1.Ap2Error(`currency must be an ISO 4217 alpha-3 code, got ${JSON.stringify(currency)}`);
|
|
41
|
+
if (ZERO_DECIMAL.has(currency))
|
|
42
|
+
return 0;
|
|
43
|
+
if (THREE_DECIMAL.has(currency))
|
|
44
|
+
return 3;
|
|
45
|
+
if (FOUR_DECIMAL.has(currency))
|
|
46
|
+
return 4;
|
|
47
|
+
return 2;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Convert a major-unit amount (e.g. `120.5` USD) to integer minor units (`12050`). Throws unless the
|
|
51
|
+
* amount is exactly representable with the currency's exponent: float drift (`0.1 + 0.2`) is refused
|
|
52
|
+
* rather than rounded away.
|
|
53
|
+
*/
|
|
54
|
+
function toMinorUnits(major, currency) {
|
|
55
|
+
const e = currencyExponent(currency);
|
|
56
|
+
if (typeof major !== 'number' || !Number.isFinite(major) || major < 0)
|
|
57
|
+
throw new sdjwt_1.Ap2Error(`amount must be a finite non-negative number, got ${String(major)}`);
|
|
58
|
+
const fixed = major.toFixed(e);
|
|
59
|
+
if (Number(fixed) !== major)
|
|
60
|
+
throw new sdjwt_1.Ap2Error(`amount ${String(major)} is not exactly representable in ${currency} minor units`);
|
|
61
|
+
const minor = Number(fixed.replace('.', ''));
|
|
62
|
+
if (!Number.isSafeInteger(minor))
|
|
63
|
+
throw new sdjwt_1.Ap2Error(`amount ${String(major)} is outside the safe integer range in minor units`);
|
|
64
|
+
return minor;
|
|
65
|
+
}
|
|
66
|
+
/** Integer minor units to the major-unit number PCA budgets use (exact for any safe integer). */
|
|
67
|
+
function fromMinorUnits(minor, currency) {
|
|
68
|
+
const e = currencyExponent(currency);
|
|
69
|
+
if (!Number.isSafeInteger(minor) || minor < 0)
|
|
70
|
+
throw new sdjwt_1.Ap2Error(`minor-unit amount must be a non-negative safe integer, got ${String(minor)}`);
|
|
71
|
+
return minor / 10 ** e;
|
|
72
|
+
}
|
|
73
|
+
exports.FREQUENCIES = ['ON_DEMAND', 'DAILY', 'WEEKLY', 'BIWEEKLY', 'MONTHLY', 'QUARTERLY', 'ANNUALLY'];
|
|
74
|
+
// ---------------------------------------------------------------------------------------------
|
|
75
|
+
// validators: each returns the list of problems (empty = valid)
|
|
76
|
+
// ---------------------------------------------------------------------------------------------
|
|
77
|
+
const isStr = (v) => typeof v === 'string';
|
|
78
|
+
const isNonEmptyStr = (v) => typeof v === 'string' && v.length > 0;
|
|
79
|
+
const isInt = (v) => typeof v === 'number' && Number.isSafeInteger(v);
|
|
80
|
+
const isNonNegInt = (v) => isInt(v) && v >= 0;
|
|
81
|
+
function merchantProblems(v, at) {
|
|
82
|
+
if (!(0, sdjwt_1.isObject)(v))
|
|
83
|
+
return [`${at}: not an object`];
|
|
84
|
+
const p = [];
|
|
85
|
+
if (!isNonEmptyStr(v.id))
|
|
86
|
+
p.push(`${at}.id: required string`);
|
|
87
|
+
if (!isNonEmptyStr(v.name))
|
|
88
|
+
p.push(`${at}.name: required string`);
|
|
89
|
+
if (v.website !== undefined && !isStr(v.website))
|
|
90
|
+
p.push(`${at}.website: must be a string`);
|
|
91
|
+
return p;
|
|
92
|
+
}
|
|
93
|
+
function amountProblems(v, at) {
|
|
94
|
+
if (!(0, sdjwt_1.isObject)(v))
|
|
95
|
+
return [`${at}: not an object`];
|
|
96
|
+
const p = [];
|
|
97
|
+
if (!isNonNegInt(v.amount))
|
|
98
|
+
p.push(`${at}.amount: must be a non-negative integer (minor units)`);
|
|
99
|
+
if (!isStr(v.currency) || !/^[A-Z]{3}$/.test(v.currency))
|
|
100
|
+
p.push(`${at}.currency: must be an ISO 4217 alpha-3 code`);
|
|
101
|
+
return p;
|
|
102
|
+
}
|
|
103
|
+
function instrumentProblems(v, at) {
|
|
104
|
+
if (!(0, sdjwt_1.isObject)(v))
|
|
105
|
+
return [`${at}: not an object`];
|
|
106
|
+
const p = [];
|
|
107
|
+
if (!isNonEmptyStr(v.id))
|
|
108
|
+
p.push(`${at}.id: required string`);
|
|
109
|
+
if (!isNonEmptyStr(v.type))
|
|
110
|
+
p.push(`${at}.type: required string`);
|
|
111
|
+
if (v.description !== undefined && !isStr(v.description))
|
|
112
|
+
p.push(`${at}.description: must be a string`);
|
|
113
|
+
return p;
|
|
114
|
+
}
|
|
115
|
+
function pispProblems(v, at) {
|
|
116
|
+
if (!(0, sdjwt_1.isObject)(v))
|
|
117
|
+
return [`${at}: not an object`];
|
|
118
|
+
return ['legal_name', 'brand_name', 'domain_name'].filter((k) => !isNonEmptyStr(v[k])).map((k) => `${at}.${k}: required string`);
|
|
119
|
+
}
|
|
120
|
+
function timeProblems(v) {
|
|
121
|
+
const p = [];
|
|
122
|
+
for (const k of ['iat', 'exp'])
|
|
123
|
+
if (v[k] !== undefined && !isNonNegInt(v[k]))
|
|
124
|
+
p.push(`${k}: must be an integer epoch-seconds`);
|
|
125
|
+
return p;
|
|
126
|
+
}
|
|
127
|
+
function cnfProblems(v) {
|
|
128
|
+
if (!(0, sdjwt_1.isObject)(v) || !(0, sdjwt_1.isObject)(v.jwk))
|
|
129
|
+
return ['cnf: must be { jwk }'];
|
|
130
|
+
try {
|
|
131
|
+
(0, sdjwt_1.assertP256Jwk)(v.jwk, 'cnf.jwk');
|
|
132
|
+
return [];
|
|
133
|
+
}
|
|
134
|
+
catch (e) {
|
|
135
|
+
return [e.message];
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
function pcaClaimProblems(v) {
|
|
139
|
+
return v[exports.PCA_CLAIM] !== undefined && !(0, sdjwt_1.isObject)(v[exports.PCA_CLAIM]) ? [`${exports.PCA_CLAIM}: must be an object`] : [];
|
|
140
|
+
}
|
|
141
|
+
function listProblems(v, at, each) {
|
|
142
|
+
if (!Array.isArray(v))
|
|
143
|
+
return [`${at}: must be an array`];
|
|
144
|
+
return v.flatMap((x, i) => each(x, `${at}[${i}]`));
|
|
145
|
+
}
|
|
146
|
+
function paymentConstraintProblems(c, at) {
|
|
147
|
+
if (!(0, sdjwt_1.isObject)(c) || !isStr(c.type))
|
|
148
|
+
return [`${at}: constraint must be an object with a string type`];
|
|
149
|
+
switch (c.type) {
|
|
150
|
+
case 'payment.agent_recurrence': {
|
|
151
|
+
const p = [];
|
|
152
|
+
if (!isStr(c.frequency) || !exports.FREQUENCIES.includes(c.frequency))
|
|
153
|
+
p.push(`${at}.frequency: not a known frequency`);
|
|
154
|
+
if (c.max_occurrences !== undefined && !(isInt(c.max_occurrences) && c.max_occurrences > 0))
|
|
155
|
+
p.push(`${at}.max_occurrences: must be a positive integer`);
|
|
156
|
+
return p;
|
|
157
|
+
}
|
|
158
|
+
case 'payment.allowed_payees':
|
|
159
|
+
return listProblems(c.allowed, `${at}.allowed`, merchantProblems);
|
|
160
|
+
case 'payment.allowed_payment_instruments':
|
|
161
|
+
return listProblems(c.allowed, `${at}.allowed`, instrumentProblems);
|
|
162
|
+
case 'payment.allowed_pisps':
|
|
163
|
+
return listProblems(c.allowed, `${at}.allowed`, pispProblems);
|
|
164
|
+
case 'payment.amount_range': {
|
|
165
|
+
const p = [];
|
|
166
|
+
if (!isStr(c.currency) || !/^[A-Z]{3}$/.test(c.currency))
|
|
167
|
+
p.push(`${at}.currency: must be an ISO 4217 alpha-3 code`);
|
|
168
|
+
if (!isNonNegInt(c.max))
|
|
169
|
+
p.push(`${at}.max: must be a non-negative integer (minor units)`);
|
|
170
|
+
if (c.min !== undefined && !isNonNegInt(c.min))
|
|
171
|
+
p.push(`${at}.min: must be a non-negative integer (minor units)`);
|
|
172
|
+
if (isInt(c.max) && isInt(c.min) && c.min > c.max)
|
|
173
|
+
p.push(`${at}: min exceeds max`);
|
|
174
|
+
return p;
|
|
175
|
+
}
|
|
176
|
+
case 'payment.budget': {
|
|
177
|
+
const p = [];
|
|
178
|
+
if (!isStr(c.currency) || !/^[A-Z]{3}$/.test(c.currency))
|
|
179
|
+
p.push(`${at}.currency: must be an ISO 4217 alpha-3 code`);
|
|
180
|
+
if (typeof c.max !== 'number' || !Number.isFinite(c.max) || c.max < 0)
|
|
181
|
+
p.push(`${at}.max: must be a non-negative number (major units)`);
|
|
182
|
+
return p;
|
|
183
|
+
}
|
|
184
|
+
case 'payment.execution_date':
|
|
185
|
+
return ['not_before', 'not_after'].filter((k) => c[k] !== undefined && !isStr(c[k])).map((k) => `${at}.${k}: must be a string`);
|
|
186
|
+
case 'payment.reference':
|
|
187
|
+
return isNonEmptyStr(c.conditional_transaction_id) ? [] : [`${at}.conditional_transaction_id: required string`];
|
|
188
|
+
default:
|
|
189
|
+
return [`${at}: unknown constraint type ${c.type}`];
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
function checkoutConstraintProblems(c, at) {
|
|
193
|
+
if (!(0, sdjwt_1.isObject)(c) || !isStr(c.type))
|
|
194
|
+
return [`${at}: constraint must be an object with a string type`];
|
|
195
|
+
if (c.type === 'checkout.allowed_merchants')
|
|
196
|
+
return listProblems(c.allowed, `${at}.allowed`, merchantProblems);
|
|
197
|
+
if (c.type === 'checkout.line_items') {
|
|
198
|
+
if (!Array.isArray(c.items) || c.items.length === 0)
|
|
199
|
+
return [`${at}.items: must be a non-empty array`];
|
|
200
|
+
return c.items.flatMap((it, i) => {
|
|
201
|
+
const a = `${at}.items[${i}]`;
|
|
202
|
+
if (!(0, sdjwt_1.isObject)(it))
|
|
203
|
+
return [`${a}: not an object`];
|
|
204
|
+
const p = [];
|
|
205
|
+
if (!isNonEmptyStr(it.id))
|
|
206
|
+
p.push(`${a}.id: required string`);
|
|
207
|
+
if (!isInt(it.quantity) || it.quantity <= 0)
|
|
208
|
+
p.push(`${a}.quantity: must be a positive integer`);
|
|
209
|
+
p.push(...listProblems(it.acceptable_items, `${a}.acceptable_items`, (x, ax) => !(0, sdjwt_1.isObject)(x) ? [`${ax}: not an object`] : ['id', 'title'].filter((k) => !isNonEmptyStr(x[k])).map((k) => `${ax}.${k}: required string`)));
|
|
210
|
+
return p;
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
return [`${at}: unknown constraint type ${c.type}`];
|
|
214
|
+
}
|
|
215
|
+
function vctProblem(v, want) {
|
|
216
|
+
return v.vct === want ? [] : [`vct: must be ${want}`];
|
|
217
|
+
}
|
|
218
|
+
function openPaymentMandateProblems(v) {
|
|
219
|
+
if (!(0, sdjwt_1.isObject)(v))
|
|
220
|
+
return ['mandate: not an object'];
|
|
221
|
+
const p = [...vctProblem(v, exports.VCT_PAYMENT_OPEN), ...timeProblems(v), ...cnfProblems(v.cnf), ...pcaClaimProblems(v)];
|
|
222
|
+
p.push(...listProblems(v.constraints, 'constraints', paymentConstraintProblems));
|
|
223
|
+
if (Array.isArray(v.constraints) && !v.constraints.some((c) => (0, sdjwt_1.isObject)(c) && c.type === 'payment.reference'))
|
|
224
|
+
p.push('constraints: must contain a payment.reference constraint');
|
|
225
|
+
if (v.payee !== undefined)
|
|
226
|
+
p.push(...merchantProblems(v.payee, 'payee'));
|
|
227
|
+
if (v.payment_amount !== undefined)
|
|
228
|
+
p.push(...amountProblems(v.payment_amount, 'payment_amount'));
|
|
229
|
+
if (v.payment_instrument !== undefined)
|
|
230
|
+
p.push(...instrumentProblems(v.payment_instrument, 'payment_instrument'));
|
|
231
|
+
if (v.pisp !== undefined)
|
|
232
|
+
p.push(...pispProblems(v.pisp, 'pisp'));
|
|
233
|
+
if (v.execution_date !== undefined && !isStr(v.execution_date))
|
|
234
|
+
p.push('execution_date: must be a string');
|
|
235
|
+
if (v.risk_data !== undefined && !(0, sdjwt_1.isObject)(v.risk_data))
|
|
236
|
+
p.push('risk_data: must be an object');
|
|
237
|
+
return p;
|
|
238
|
+
}
|
|
239
|
+
function paymentMandateProblems(v) {
|
|
240
|
+
if (!(0, sdjwt_1.isObject)(v))
|
|
241
|
+
return ['mandate: not an object'];
|
|
242
|
+
const p = [...vctProblem(v, exports.VCT_PAYMENT), ...timeProblems(v), ...pcaClaimProblems(v)];
|
|
243
|
+
if (!isNonEmptyStr(v.transaction_id))
|
|
244
|
+
p.push('transaction_id: required string');
|
|
245
|
+
p.push(...merchantProblems(v.payee, 'payee'), ...amountProblems(v.payment_amount, 'payment_amount'), ...instrumentProblems(v.payment_instrument, 'payment_instrument'));
|
|
246
|
+
if (v.pisp !== undefined)
|
|
247
|
+
p.push(...pispProblems(v.pisp, 'pisp'));
|
|
248
|
+
if (v.execution_date !== undefined && !isStr(v.execution_date))
|
|
249
|
+
p.push('execution_date: must be a string');
|
|
250
|
+
if (v.risk_data !== undefined && !(0, sdjwt_1.isObject)(v.risk_data))
|
|
251
|
+
p.push('risk_data: must be an object');
|
|
252
|
+
return p;
|
|
253
|
+
}
|
|
254
|
+
function openCheckoutMandateProblems(v) {
|
|
255
|
+
if (!(0, sdjwt_1.isObject)(v))
|
|
256
|
+
return ['mandate: not an object'];
|
|
257
|
+
const p = [...vctProblem(v, exports.VCT_CHECKOUT_OPEN), ...timeProblems(v), ...cnfProblems(v.cnf), ...pcaClaimProblems(v)];
|
|
258
|
+
p.push(...listProblems(v.constraints, 'constraints', checkoutConstraintProblems));
|
|
259
|
+
if (Array.isArray(v.constraints) && !v.constraints.some((c) => (0, sdjwt_1.isObject)(c) && c.type === 'checkout.line_items'))
|
|
260
|
+
p.push('constraints: must contain a checkout.line_items constraint');
|
|
261
|
+
return p;
|
|
262
|
+
}
|
|
263
|
+
function checkoutMandateProblems(v) {
|
|
264
|
+
if (!(0, sdjwt_1.isObject)(v))
|
|
265
|
+
return ['mandate: not an object'];
|
|
266
|
+
const p = [...vctProblem(v, exports.VCT_CHECKOUT), ...timeProblems(v), ...pcaClaimProblems(v)];
|
|
267
|
+
if (!isNonEmptyStr(v.checkout_jwt))
|
|
268
|
+
p.push('checkout_jwt: required string');
|
|
269
|
+
if (!isNonEmptyStr(v.checkout_hash))
|
|
270
|
+
p.push('checkout_hash: required string');
|
|
271
|
+
return p;
|
|
272
|
+
}
|
|
273
|
+
function assertValid(v, problems, what) {
|
|
274
|
+
const p = problems(v);
|
|
275
|
+
if (p.length > 0)
|
|
276
|
+
throw new sdjwt_1.Ap2Error(`${what}: ${p.join('; ')}`);
|
|
277
|
+
return v;
|
|
278
|
+
}
|
|
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AC,CAAC,IAAI,KAAK,qBAAqB,CAAC;QAAE,CAAC,CAAC,IAAI,CAAC,4DAA4D,CAAC,CAAC;IACtL,OAAO,CAAC,CAAC;AACX,CAAC;AAED,SAAgB,uBAAuB,CAAC,CAAU;IAChD,IAAI,CAAC,IAAA,gBAAQ,EAAC,CAAC,CAAC;QAAE,OAAO,CAAC,wBAAwB,CAAC,CAAC;IACpD,MAAM,CAAC,GAAG,CAAC,GAAG,UAAU,CAAC,CAAC,EAAE,oBAAY,CAAC,EAAE,GAAG,YAAY,CAAC,CAAC,CAAC,EAAE,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC;IACvF,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,YAAY,CAAC;QAAE,CAAC,CAAC,IAAI,CAAC,+BAA+B,CAAC,CAAC;IAC5E,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,aAAa,CAAC;QAAE,CAAC,CAAC,IAAI,CAAC,gCAAgC,CAAC,CAAC;IAC9E,OAAO,CAAC,CAAC;AACX,CAAC;AAED,SAAgB,WAAW,CAAI,CAAU,EAAE,QAAkC,EAAE,IAAY;IACzF,MAAM,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;IACtB,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC;QAAE,MAAM,IAAI,gBAAQ,CAAC,GAAG,IAAI,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACjE,OAAO,CAAM,CAAC;AAChB,CAAC"}
|
package/dist/pca.d.ts
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Binding AP2 mandates to a PCA grant and to the PCA proof of each action.
|
|
3
|
+
*
|
|
4
|
+
* AP2 decides what a mandate may say; PCA decides whether the agent may act. The two are tied
|
|
5
|
+
* together by a namespaced `x_pca` claim that lives INSIDE the mandate object (so it is covered by
|
|
6
|
+
* the issuer's / agent's signature and by the next hop's `sd_hash`). The official schemas do not set
|
|
7
|
+
* `additionalProperties: false` and the reference SDK ignores unknown mandate claims, so the claim
|
|
8
|
+
* does not affect schema validity or reference verification (both are tested).
|
|
9
|
+
*
|
|
10
|
+
* open mandate `x_pca = { v, grant, terms }` the PCA grant (principal-signed, Ed25519)
|
|
11
|
+
* and the terms it was minted from
|
|
12
|
+
* closed payment `x_pca = { v, charge, pcactn }` the PCActn (agent-signed, Ed25519) that
|
|
13
|
+
* authorises exactly this charge
|
|
14
|
+
*
|
|
15
|
+
* The PCActn's signed `nonce` commits to the AP2 side: the transaction id, payee, amount, instrument,
|
|
16
|
+
* the open mandate's `sd_hash` and the thumbprint of the agent's AP2 key. Swapping any of those, or
|
|
17
|
+
* replaying the PCActn under another mandate or another AP2 agent key, breaks the binding.
|
|
18
|
+
*/
|
|
19
|
+
import { verifyPCActnCore, type Capability, type PCActn, type ThresholdSignature } from '@atlasauth/pca';
|
|
20
|
+
import { type MandateTerms, type PaymentMandate as PcaPaymentMandate } from '@atlasauth/pca-payments';
|
|
21
|
+
import { type JsonObject, type P256Jwk } from './sdjwt';
|
|
22
|
+
import { type Merchant, type OpenCheckoutMandateClaims, type OpenPaymentMandateClaims, type PaymentConstraint, type PaymentMandateClaims } from './mandates';
|
|
23
|
+
import { type MandateIssuer } from './chain';
|
|
24
|
+
import type { CheckoutConstraint } from './mandates';
|
|
25
|
+
export declare const PCA_BINDING_VERSION = 1;
|
|
26
|
+
/** The `x_pca` claim of an open mandate: the principal-signed grant and the terms it was minted from. */
|
|
27
|
+
export declare function pcaOpenClaim(mandate: PcaPaymentMandate): JsonObject;
|
|
28
|
+
export interface FromTermsOptions {
|
|
29
|
+
issuer: MandateIssuer;
|
|
30
|
+
agentJwk: P256Jwk;
|
|
31
|
+
/** Descriptors for every merchant id in the PCA terms (AP2 needs a name; PCA only holds the id). */
|
|
32
|
+
merchants: Merchant[];
|
|
33
|
+
/** Issued-at, epoch seconds. */
|
|
34
|
+
iat: number;
|
|
35
|
+
/** Expiry, epoch seconds; must not exceed the PCA period end. Required when the terms have no period end. */
|
|
36
|
+
exp?: number;
|
|
37
|
+
salt?: () => string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The AP2 open payment constraints a set of PCA terms denotes. `budget.max` is in MAJOR units (the
|
|
41
|
+
* AP2 SDK multiplies it by 100); `amount_range` is in minor units. The budget is refused for any
|
|
42
|
+
* currency whose exponent is not 2 and for any cap whose x100 product is not exact in floating point,
|
|
43
|
+
* so the SDK and this package read the same number.
|
|
44
|
+
*/
|
|
45
|
+
export declare function paymentConstraintsFromTerms(terms: MandateTerms, merchants: Merchant[], checkoutReference: string): PaymentConstraint[];
|
|
46
|
+
/** Issue the open payment mandate for a PCA mandate (grant + terms), chained to `checkoutReference`. */
|
|
47
|
+
export declare function openPaymentMandateFromPca(mandate: PcaPaymentMandate, o: FromTermsOptions & {
|
|
48
|
+
checkoutReference: string;
|
|
49
|
+
}): string;
|
|
50
|
+
/** Issue the open checkout mandate for a PCA mandate: the merchant allowlist and the acceptable line items. */
|
|
51
|
+
export declare function openCheckoutMandateFromPca(mandate: PcaPaymentMandate, o: FromTermsOptions & {
|
|
52
|
+
lineItems: Extract<CheckoutConstraint, {
|
|
53
|
+
type: 'checkout.line_items';
|
|
54
|
+
}>['items'];
|
|
55
|
+
}): string;
|
|
56
|
+
export interface BindingFacts {
|
|
57
|
+
transactionId: string;
|
|
58
|
+
payeeId: string;
|
|
59
|
+
amount: number;
|
|
60
|
+
currency: string;
|
|
61
|
+
instrumentId: string;
|
|
62
|
+
/** `sd_hash` of the open payment mandate token the closed mandate is chained to. */
|
|
63
|
+
openHash: string;
|
|
64
|
+
/** RFC 7638 thumbprint of the agent's AP2 (P-256) key. */
|
|
65
|
+
agentJkt: string;
|
|
66
|
+
}
|
|
67
|
+
/** The value the PCActn's signed `nonce` must equal for these AP2 facts. */
|
|
68
|
+
export declare function pcaBindingNonce(f: BindingFacts): string;
|
|
69
|
+
export interface PcaPaymentBindingInput {
|
|
70
|
+
/** The PCA mandate (grant + terms + budget) the agent holds. */
|
|
71
|
+
mandate: PcaPaymentMandate;
|
|
72
|
+
/** The open payment mandate token the closed mandate will be chained to. */
|
|
73
|
+
open: string;
|
|
74
|
+
agentJwk: P256Jwk;
|
|
75
|
+
/** The agent's Ed25519 secret (the PCA grant's holder); signs the PCActn. */
|
|
76
|
+
agentSecret: Uint8Array;
|
|
77
|
+
/** PCA audience (the resource server / Atlas instance id this action is for). */
|
|
78
|
+
audience: string;
|
|
79
|
+
counter: number;
|
|
80
|
+
transactionId: string;
|
|
81
|
+
payee: Merchant;
|
|
82
|
+
amount: {
|
|
83
|
+
amount: number;
|
|
84
|
+
currency: string;
|
|
85
|
+
};
|
|
86
|
+
instrumentId: string;
|
|
87
|
+
category?: string;
|
|
88
|
+
/** PCActn `iat`, epoch ms. */
|
|
89
|
+
now?: number;
|
|
90
|
+
/** For a charge that needs a human co-sign (PCA step-up): returns the threshold shares over the built PCActn. */
|
|
91
|
+
cosign?: (pcactn: PCActn) => ThresholdSignature;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* amount / cap, clamped to [0, 1] and rounded UP to 12 decimals. PCA's canonical encoding refuses
|
|
95
|
+
* numbers with more than 15 significant digits (so 100/300 cannot be signed as-is); rounding up can
|
|
96
|
+
* only raise the risk the threshold policy sees, never lower it.
|
|
97
|
+
*/
|
|
98
|
+
export declare function riskRatio(amount: number, cap: number): number;
|
|
99
|
+
/** Build the `x_pca` claim of a closed payment mandate: a PCActn authorising exactly this charge. */
|
|
100
|
+
export declare function buildPcaPaymentBinding(i: PcaPaymentBindingInput): JsonObject;
|
|
101
|
+
type PcaVerifyExtras = Pick<NonNullable<Parameters<typeof verifyPCActnCore>[1]>, 'hooks' | 'enforce'>;
|
|
102
|
+
export interface VerifyPcaBindingInput extends PcaVerifyExtras {
|
|
103
|
+
open: OpenPaymentMandateClaims;
|
|
104
|
+
closed: PaymentMandateClaims;
|
|
105
|
+
/** `sd_hash` of the open payment mandate hop (from `verifyPaymentChain().openHash`). */
|
|
106
|
+
openHash: string;
|
|
107
|
+
/** The Ed25519 key (b64u) of the principal who must have signed the grant. Required. */
|
|
108
|
+
expectedPrincipal: string;
|
|
109
|
+
/** verifier-side PQ pins by Ed25519 identity (R3-01). A pure-PQ / hybrid ROOT is accepted only if the root issuer has a pin equal to its `pq_pk` (a signed binding from `pqPinFor`, or your own registry); without one it is refused. */
|
|
110
|
+
pqPins?: Readonly<Record<string, string>>;
|
|
111
|
+
/** This verifier's PCA audience; the PCActn's signed `aud` must equal it. */
|
|
112
|
+
audience: string;
|
|
113
|
+
/** Verification time, epoch ms. */
|
|
114
|
+
now?: number;
|
|
115
|
+
/**
|
|
116
|
+
* REQUIRED: the PCA mandate state THIS verifier holds (its live budget). The policy decision always runs on it, so the
|
|
117
|
+
* cumulative budget is enforced; without it the binding is refused ({@link PcaBindingError} `mandate_required`).
|
|
118
|
+
*/
|
|
119
|
+
mandate: PcaPaymentMandate;
|
|
120
|
+
/**
|
|
121
|
+
* Epoch-ms times of this holder's earlier admitted charges, from the verifier's own records (the velocity `rate`
|
|
122
|
+
* caveat reads them). REQUIRED when the mandate limits the charge count (`maxTransactionsPerPeriod`); otherwise empty.
|
|
123
|
+
*/
|
|
124
|
+
recentChargeTimes?: number[];
|
|
125
|
+
}
|
|
126
|
+
/** Thrown when `verifyPcaBinding` lacks the server-held state the policy decision needs. */
|
|
127
|
+
export declare class PcaBindingError extends Error {
|
|
128
|
+
readonly code: 'mandate_required' | 'charge_history_required';
|
|
129
|
+
constructor(code: 'mandate_required' | 'charge_history_required', message: string);
|
|
130
|
+
}
|
|
131
|
+
export type PcaBindingResult = {
|
|
132
|
+
ok: true;
|
|
133
|
+
pcactn: PCActn;
|
|
134
|
+
grant: Capability;
|
|
135
|
+
terms: MandateTerms;
|
|
136
|
+
} | {
|
|
137
|
+
ok: false;
|
|
138
|
+
reason: string;
|
|
139
|
+
};
|
|
140
|
+
/**
|
|
141
|
+
* Verify the PCA side of a verified AP2 payment chain: the grant in the open mandate (signed by the
|
|
142
|
+
* expected principal, consistent with the terms it claims and with the open constraints), and the
|
|
143
|
+
* closed mandate's PCActn (valid under that grant, for this audience, committing to exactly this
|
|
144
|
+
* AP2 charge). Run it after `verifyPaymentChain`, which establishes the AP2 signatures.
|
|
145
|
+
*/
|
|
146
|
+
export declare function verifyPcaBinding(i: VerifyPcaBindingInput): Promise<PcaBindingResult>;
|
|
147
|
+
export type { OpenCheckoutMandateClaims };
|