@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/sdjwt.js
ADDED
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Ap2Error = void 0;
|
|
4
|
+
exports.b64uEncode = b64uEncode;
|
|
5
|
+
exports.b64uDecode = b64uDecode;
|
|
6
|
+
exports.isObject = isObject;
|
|
7
|
+
exports.parseJson = parseJson;
|
|
8
|
+
exports.isSdAlg = isSdAlg;
|
|
9
|
+
exports.sdDigest = sdDigest;
|
|
10
|
+
exports.assertP256Jwk = assertP256Jwk;
|
|
11
|
+
exports.generateAp2KeyPair = generateAp2KeyPair;
|
|
12
|
+
exports.ap2KeyPairFromPrivateJwk = ap2KeyPairFromPrivateJwk;
|
|
13
|
+
exports.jwkThumbprint = jwkThumbprint;
|
|
14
|
+
exports.hopSdJwt = hopSdJwt;
|
|
15
|
+
exports.parseSdJwtHop = parseSdJwtHop;
|
|
16
|
+
exports.sdHashOf = sdHashOf;
|
|
17
|
+
exports.issuerJwtHashOf = issuerJwtHashOf;
|
|
18
|
+
exports.verifyHopSignature = verifyHopSignature;
|
|
19
|
+
exports.processDisclosures = processDisclosures;
|
|
20
|
+
exports.newSalt = newSalt;
|
|
21
|
+
exports.disclosureBuilder = disclosureBuilder;
|
|
22
|
+
exports.signSdJwt = signSdJwt;
|
|
23
|
+
exports.signJwtEs256 = signJwtEs256;
|
|
24
|
+
exports.parseJwt = parseJwt;
|
|
25
|
+
exports.verifyJwtEs256 = verifyJwtEs256;
|
|
26
|
+
/**
|
|
27
|
+
* SD-JWT primitives for AP2 mandates (RFC 9901): strict compact parsing, disclosure processing, the
|
|
28
|
+
* `sd_hash` / `issuer_jwt_hash` binding digests, and ES256 (P-256) signing and verification.
|
|
29
|
+
*
|
|
30
|
+
* Nothing here implements a cryptographic primitive: SHA-2 and ECDSA come from `node:crypto`. The
|
|
31
|
+
* code is the SD-JWT *format* (what is hashed, in which order, which shapes are accepted) and it
|
|
32
|
+
* fails closed on every ambiguity (duplicate digests, unreferenced disclosures, malformed base64url,
|
|
33
|
+
* duplicate JSON keys, unknown `_sd_alg`, non-ES256 algorithms).
|
|
34
|
+
*/
|
|
35
|
+
const node_crypto_1 = require("node:crypto");
|
|
36
|
+
/** Every failure raised while parsing or verifying carries a human-readable reason. */
|
|
37
|
+
class Ap2Error extends Error {
|
|
38
|
+
constructor(message) {
|
|
39
|
+
super(message);
|
|
40
|
+
this.name = 'Ap2Error';
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.Ap2Error = Ap2Error;
|
|
44
|
+
// ---------------------------------------------------------------------------------------------
|
|
45
|
+
// base64url + JSON helpers
|
|
46
|
+
// ---------------------------------------------------------------------------------------------
|
|
47
|
+
function b64uEncode(data) {
|
|
48
|
+
return Buffer.from(typeof data === 'string' ? Buffer.from(data, 'utf8') : data).toString('base64url');
|
|
49
|
+
}
|
|
50
|
+
/** Strict base64url decode: canonical alphabet, no padding, and the encoding must round-trip. */
|
|
51
|
+
function b64uDecode(s, what) {
|
|
52
|
+
if (!/^[A-Za-z0-9_-]*$/.test(s))
|
|
53
|
+
throw new Ap2Error(`${what}: not base64url`);
|
|
54
|
+
const buf = Buffer.from(s, 'base64url');
|
|
55
|
+
if (buf.toString('base64url') !== s)
|
|
56
|
+
throw new Ap2Error(`${what}: non-canonical base64url`);
|
|
57
|
+
return buf;
|
|
58
|
+
}
|
|
59
|
+
function isObject(v) {
|
|
60
|
+
return typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Reject an object that repeats a key. `JSON.parse` silently keeps the last duplicate, which would let
|
|
64
|
+
* two parties read different claims out of the same signed bytes. Run on text that already parsed, so
|
|
65
|
+
* only string/brace structure needs tracking.
|
|
66
|
+
*/
|
|
67
|
+
function assertNoDuplicateKeys(text, what) {
|
|
68
|
+
const stack = [];
|
|
69
|
+
let expectKey = false;
|
|
70
|
+
for (let i = 0; i < text.length; i++) {
|
|
71
|
+
const c = text[i];
|
|
72
|
+
if (c === '"') {
|
|
73
|
+
let j = i + 1;
|
|
74
|
+
while (text[j] !== '"')
|
|
75
|
+
j += text[j] === '\\' ? 2 : 1;
|
|
76
|
+
const top = stack[stack.length - 1];
|
|
77
|
+
if (expectKey && top) {
|
|
78
|
+
const key = JSON.parse(text.slice(i, j + 1));
|
|
79
|
+
if (top.has(key))
|
|
80
|
+
throw new Ap2Error(`${what}: duplicate key ${JSON.stringify(key)}`);
|
|
81
|
+
top.add(key);
|
|
82
|
+
expectKey = false;
|
|
83
|
+
}
|
|
84
|
+
i = j;
|
|
85
|
+
}
|
|
86
|
+
else if (c === '{') {
|
|
87
|
+
stack.push(new Set());
|
|
88
|
+
expectKey = true;
|
|
89
|
+
}
|
|
90
|
+
else if (c === '[') {
|
|
91
|
+
stack.push(null);
|
|
92
|
+
expectKey = false;
|
|
93
|
+
}
|
|
94
|
+
else if (c === '}' || c === ']') {
|
|
95
|
+
stack.pop();
|
|
96
|
+
expectKey = false;
|
|
97
|
+
}
|
|
98
|
+
else if (c === ',') {
|
|
99
|
+
expectKey = stack[stack.length - 1] instanceof Set;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* JSON parse that rejects duplicate keys. Numbers are parsed as written (`1000.0` is accepted: the
|
|
105
|
+
* official Python SDK serialises float fields that way).
|
|
106
|
+
*/
|
|
107
|
+
function parseJson(text, what) {
|
|
108
|
+
let v;
|
|
109
|
+
try {
|
|
110
|
+
v = JSON.parse(text);
|
|
111
|
+
}
|
|
112
|
+
catch (e) {
|
|
113
|
+
throw new Ap2Error(`${what}: invalid JSON (${e.message})`);
|
|
114
|
+
}
|
|
115
|
+
assertNoDuplicateKeys(text, what);
|
|
116
|
+
return v;
|
|
117
|
+
}
|
|
118
|
+
function decodeJsonSegment(segment, what) {
|
|
119
|
+
const v = parseJson(b64uDecode(segment, what).toString('utf8'), what);
|
|
120
|
+
if (!isObject(v))
|
|
121
|
+
throw new Ap2Error(`${what}: must be a JSON object`);
|
|
122
|
+
return v;
|
|
123
|
+
}
|
|
124
|
+
const NODE_HASH = { 'sha-256': 'sha256', 'sha-384': 'sha384', 'sha-512': 'sha512' };
|
|
125
|
+
function isSdAlg(v) {
|
|
126
|
+
return v === 'sha-256' || v === 'sha-384' || v === 'sha-512';
|
|
127
|
+
}
|
|
128
|
+
/** base64url(hash(ascii(value))): the digest used for disclosures, `sd_hash` and `checkout_hash`. */
|
|
129
|
+
function sdDigest(value, alg = 'sha-256') {
|
|
130
|
+
if (!/^[\x20-\x7e]*$/.test(value))
|
|
131
|
+
throw new Ap2Error('digest input must be ASCII');
|
|
132
|
+
return (0, node_crypto_1.createHash)(NODE_HASH[alg]).update(value, 'ascii').digest('base64url');
|
|
133
|
+
}
|
|
134
|
+
const B64U_43 = /^[A-Za-z0-9_-]{43}$/;
|
|
135
|
+
/** Validate a public JWK against `types/jwk.json` and prove the point is on the curve. */
|
|
136
|
+
function assertP256Jwk(jwk, what) {
|
|
137
|
+
if (!isObject(jwk))
|
|
138
|
+
throw new Ap2Error(`${what}: JWK must be an object`);
|
|
139
|
+
if (jwk.kty !== 'EC' || jwk.crv !== 'P-256')
|
|
140
|
+
throw new Ap2Error(`${what}: JWK must be EC P-256`);
|
|
141
|
+
if (typeof jwk.x !== 'string' || !B64U_43.test(jwk.x))
|
|
142
|
+
throw new Ap2Error(`${what}: bad JWK x`);
|
|
143
|
+
if (typeof jwk.y !== 'string' || !B64U_43.test(jwk.y))
|
|
144
|
+
throw new Ap2Error(`${what}: bad JWK y`);
|
|
145
|
+
if ('d' in jwk)
|
|
146
|
+
throw new Ap2Error(`${what}: JWK carries private material`);
|
|
147
|
+
if (jwk.alg !== undefined && jwk.alg !== 'ES256')
|
|
148
|
+
throw new Ap2Error(`${what}: JWK alg must be ES256`);
|
|
149
|
+
try {
|
|
150
|
+
(0, node_crypto_1.createPublicKey)({ key: { kty: 'EC', crv: 'P-256', x: jwk.x, y: jwk.y }, format: 'jwk' });
|
|
151
|
+
}
|
|
152
|
+
catch {
|
|
153
|
+
throw new Ap2Error(`${what}: JWK is not a valid P-256 point`);
|
|
154
|
+
}
|
|
155
|
+
return jwk;
|
|
156
|
+
}
|
|
157
|
+
function publicKeyObject(jwk) {
|
|
158
|
+
return (0, node_crypto_1.createPublicKey)({ key: { kty: 'EC', crv: 'P-256', x: jwk.x, y: jwk.y }, format: 'jwk' });
|
|
159
|
+
}
|
|
160
|
+
function generateAp2KeyPair(kid) {
|
|
161
|
+
const { publicKey, privateKey } = (0, node_crypto_1.generateKeyPairSync)('ec', { namedCurve: 'P-256' });
|
|
162
|
+
const pub = publicKey.export({ format: 'jwk' });
|
|
163
|
+
const publicJwk = {
|
|
164
|
+
kty: 'EC',
|
|
165
|
+
crv: 'P-256',
|
|
166
|
+
x: String(pub.x),
|
|
167
|
+
y: String(pub.y),
|
|
168
|
+
...(kid !== undefined ? { kid } : {}),
|
|
169
|
+
};
|
|
170
|
+
return { publicJwk, privateKey };
|
|
171
|
+
}
|
|
172
|
+
/** Rebuild a key pair from a private JWK (`d` present), e.g. for fixtures. */
|
|
173
|
+
function ap2KeyPairFromPrivateJwk(jwk) {
|
|
174
|
+
const privateKey = (0, node_crypto_1.createPrivateKey)({ key: jwk, format: 'jwk' });
|
|
175
|
+
const pub = (0, node_crypto_1.createPublicKey)(privateKey).export({ format: 'jwk' });
|
|
176
|
+
const kid = typeof jwk.kid === 'string' ? jwk.kid : undefined;
|
|
177
|
+
return {
|
|
178
|
+
privateKey,
|
|
179
|
+
publicJwk: { kty: 'EC', crv: 'P-256', x: String(pub.x), y: String(pub.y), ...(kid !== undefined ? { kid } : {}) },
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
/** RFC 7638 JWK thumbprint (SHA-256) of an EC P-256 key. */
|
|
183
|
+
function jwkThumbprint(jwk) {
|
|
184
|
+
const canonical = `{"crv":"P-256","kty":"EC","x":"${jwk.x}","y":"${jwk.y}"}`;
|
|
185
|
+
return (0, node_crypto_1.createHash)('sha256').update(canonical, 'utf8').digest('base64url');
|
|
186
|
+
}
|
|
187
|
+
/** ES256 over `signingInput`; returns the 64-byte `r || s` JWS signature as base64url. */
|
|
188
|
+
function es256Sign(privateKey, signingInput) {
|
|
189
|
+
return (0, node_crypto_1.sign)('sha256', Buffer.from(signingInput, 'ascii'), { key: privateKey, dsaEncoding: 'ieee-p1363' }).toString('base64url');
|
|
190
|
+
}
|
|
191
|
+
function es256Verify(jwk, signingInput, signature) {
|
|
192
|
+
if (signature.length !== 64)
|
|
193
|
+
return false;
|
|
194
|
+
return (0, node_crypto_1.verify)('sha256', Buffer.from(signingInput, 'ascii'), { key: publicKeyObject(jwk), dsaEncoding: 'ieee-p1363' }, signature);
|
|
195
|
+
}
|
|
196
|
+
/** The hop's `~`-joined serialisation: what `sd_hash` is computed over. */
|
|
197
|
+
function hopSdJwt(hop) {
|
|
198
|
+
return `${hop.jwt}~${hop.disclosures.map((d) => `${d}~`).join('')}`;
|
|
199
|
+
}
|
|
200
|
+
/** Parse one SD-JWT (`jwt~d1~...~dn~`). The serialisation must end with `~`. */
|
|
201
|
+
function parseSdJwtHop(token) {
|
|
202
|
+
if (typeof token !== 'string' || token.length === 0)
|
|
203
|
+
throw new Ap2Error('SD-JWT: empty');
|
|
204
|
+
if (token.startsWith('~'))
|
|
205
|
+
throw new Ap2Error('SD-JWT: empty issuer JWT');
|
|
206
|
+
if (!token.endsWith('~'))
|
|
207
|
+
throw new Ap2Error('SD-JWT: must end with "~" (a trailing KB-JWT is not an AP2 form)');
|
|
208
|
+
const parts = token.slice(0, -1).split('~');
|
|
209
|
+
const jwt = parts[0] ?? '';
|
|
210
|
+
const disclosures = parts.slice(1);
|
|
211
|
+
if (disclosures.some((d) => d.length === 0))
|
|
212
|
+
throw new Ap2Error('SD-JWT: empty disclosure segment');
|
|
213
|
+
const seg = jwt.split('.');
|
|
214
|
+
if (seg.length !== 3 || seg.some((s) => s.length === 0))
|
|
215
|
+
throw new Ap2Error('SD-JWT: issuer JWT must be header.payload.signature');
|
|
216
|
+
const [h, p, s] = seg;
|
|
217
|
+
const header = decodeJsonSegment(h, 'JWT header');
|
|
218
|
+
const payload = decodeJsonSegment(p, 'JWT payload');
|
|
219
|
+
const signature = b64uDecode(s, 'JWT signature');
|
|
220
|
+
const rawAlg = payload._sd_alg;
|
|
221
|
+
if (rawAlg !== undefined && !isSdAlg(rawAlg))
|
|
222
|
+
throw new Ap2Error(`SD-JWT: unsupported _sd_alg ${JSON.stringify(rawAlg)}`);
|
|
223
|
+
return {
|
|
224
|
+
raw: token,
|
|
225
|
+
jwt,
|
|
226
|
+
header,
|
|
227
|
+
payload,
|
|
228
|
+
disclosures,
|
|
229
|
+
sdAlg: isSdAlg(rawAlg) ? rawAlg : 'sha-256',
|
|
230
|
+
signingInput: `${h}.${p}`,
|
|
231
|
+
signature,
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
/** `sd_hash` of a hop: the digest of `<jwt>~<d1>~...~` (the on-wire form of the preceding hop). */
|
|
235
|
+
function sdHashOf(hop, alg = hop.sdAlg) {
|
|
236
|
+
return sdDigest(hopSdJwt(hop), alg);
|
|
237
|
+
}
|
|
238
|
+
/** `issuer_jwt_hash` of a hop: the digest of the issuer-signed JWT alone. */
|
|
239
|
+
function issuerJwtHashOf(hop, alg = hop.sdAlg) {
|
|
240
|
+
return sdDigest(hop.jwt, alg);
|
|
241
|
+
}
|
|
242
|
+
/** Verify the issuer JWT's ES256 signature. Anything other than `alg: ES256` is rejected. */
|
|
243
|
+
function verifyHopSignature(hop, key) {
|
|
244
|
+
if (hop.header.alg !== 'ES256')
|
|
245
|
+
return false;
|
|
246
|
+
return es256Verify(assertP256Jwk(key, 'verification key'), hop.signingInput, hop.signature);
|
|
247
|
+
}
|
|
248
|
+
function decodeDisclosure(raw) {
|
|
249
|
+
const arr = parseJson(b64uDecode(raw, 'disclosure').toString('utf8'), 'disclosure');
|
|
250
|
+
if (!Array.isArray(arr))
|
|
251
|
+
throw new Ap2Error('disclosure: must be a JSON array');
|
|
252
|
+
if (typeof arr[0] !== 'string' || arr[0].length === 0)
|
|
253
|
+
throw new Ap2Error('disclosure: salt must be a non-empty string');
|
|
254
|
+
if (arr.length === 3) {
|
|
255
|
+
const name = arr[1];
|
|
256
|
+
if (typeof name !== 'string')
|
|
257
|
+
throw new Ap2Error('disclosure: claim name must be a string');
|
|
258
|
+
if (name === '_sd' || name === '...')
|
|
259
|
+
throw new Ap2Error(`disclosure: claim name ${name} is reserved`);
|
|
260
|
+
return { kind: 'property', name, value: arr[2], raw };
|
|
261
|
+
}
|
|
262
|
+
if (arr.length === 2)
|
|
263
|
+
return { kind: 'element', value: arr[1], raw };
|
|
264
|
+
throw new Ap2Error('disclosure: array must have 2 or 3 elements');
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Resolve every selectively-disclosable claim in `payload` using `disclosures`. Returns the processed
|
|
268
|
+
* claims (`_sd`, `...` markers and `_sd_alg` removed). Throws if a disclosure is duplicated, is not
|
|
269
|
+
* referenced from the payload, collides with an existing claim, or is used in the wrong position.
|
|
270
|
+
*/
|
|
271
|
+
function processDisclosures(payload, disclosures, alg) {
|
|
272
|
+
const byDigest = new Map();
|
|
273
|
+
for (const raw of disclosures) {
|
|
274
|
+
const d = decodeDisclosure(raw);
|
|
275
|
+
const digest = sdDigest(raw, alg);
|
|
276
|
+
if (byDigest.has(digest))
|
|
277
|
+
throw new Ap2Error('SD-JWT: duplicate disclosure');
|
|
278
|
+
byDigest.set(digest, d);
|
|
279
|
+
}
|
|
280
|
+
const used = new Set();
|
|
281
|
+
const take = (digest, want) => {
|
|
282
|
+
const d = byDigest.get(digest);
|
|
283
|
+
if (!d)
|
|
284
|
+
return undefined; // decoy digest, or a disclosure the holder chose not to reveal
|
|
285
|
+
if (used.has(digest))
|
|
286
|
+
throw new Ap2Error('SD-JWT: a digest is referenced more than once');
|
|
287
|
+
if (d.kind !== want)
|
|
288
|
+
throw new Ap2Error(`SD-JWT: a ${d.kind} disclosure is referenced from a ${want} position`);
|
|
289
|
+
used.add(digest);
|
|
290
|
+
return d;
|
|
291
|
+
};
|
|
292
|
+
const walk = (node, depth) => {
|
|
293
|
+
if (depth > 32)
|
|
294
|
+
throw new Ap2Error('SD-JWT: nesting too deep');
|
|
295
|
+
if (Array.isArray(node)) {
|
|
296
|
+
const out = [];
|
|
297
|
+
for (const el of node) {
|
|
298
|
+
if (isObject(el) && '...' in el) {
|
|
299
|
+
const keys = Object.keys(el);
|
|
300
|
+
if (keys.length !== 1 || typeof el['...'] !== 'string')
|
|
301
|
+
throw new Ap2Error('SD-JWT: malformed array digest placeholder');
|
|
302
|
+
const d = take(el['...'], 'element');
|
|
303
|
+
if (d)
|
|
304
|
+
out.push(walk(d.value, depth + 1));
|
|
305
|
+
}
|
|
306
|
+
else
|
|
307
|
+
out.push(walk(el, depth + 1));
|
|
308
|
+
}
|
|
309
|
+
return out;
|
|
310
|
+
}
|
|
311
|
+
if (isObject(node)) {
|
|
312
|
+
const out = {};
|
|
313
|
+
for (const [k, v] of Object.entries(node)) {
|
|
314
|
+
if (k === '_sd' || k === '_sd_alg')
|
|
315
|
+
continue;
|
|
316
|
+
if (k === '...')
|
|
317
|
+
throw new Ap2Error('SD-JWT: "..." is only valid as the sole key of an array element');
|
|
318
|
+
out[k] = walk(v, depth + 1);
|
|
319
|
+
}
|
|
320
|
+
const sd = node._sd;
|
|
321
|
+
if (sd !== undefined) {
|
|
322
|
+
if (!Array.isArray(sd) || sd.some((x) => typeof x !== 'string'))
|
|
323
|
+
throw new Ap2Error('SD-JWT: _sd must be an array of strings');
|
|
324
|
+
for (const digest of sd) {
|
|
325
|
+
const d = take(digest, 'property');
|
|
326
|
+
if (!d || d.kind !== 'property')
|
|
327
|
+
continue;
|
|
328
|
+
if (Object.prototype.hasOwnProperty.call(out, d.name))
|
|
329
|
+
throw new Ap2Error(`SD-JWT: disclosed claim ${d.name} collides with an existing claim`);
|
|
330
|
+
out[d.name] = walk(d.value, depth + 1);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
return out;
|
|
334
|
+
}
|
|
335
|
+
return node;
|
|
336
|
+
};
|
|
337
|
+
const result = walk(payload, 0);
|
|
338
|
+
if (used.size !== byDigest.size)
|
|
339
|
+
throw new Ap2Error('SD-JWT: a disclosure is not referenced by the signed payload');
|
|
340
|
+
return result;
|
|
341
|
+
}
|
|
342
|
+
// ---------------------------------------------------------------------------------------------
|
|
343
|
+
// issuing
|
|
344
|
+
// ---------------------------------------------------------------------------------------------
|
|
345
|
+
function newSalt() {
|
|
346
|
+
return (0, node_crypto_1.randomBytes)(16).toString('base64url');
|
|
347
|
+
}
|
|
348
|
+
function disclosureBuilder(alg = 'sha-256', salt = newSalt) {
|
|
349
|
+
const disclosures = [];
|
|
350
|
+
return {
|
|
351
|
+
disclosures,
|
|
352
|
+
element(value) {
|
|
353
|
+
const raw = b64uEncode(JSON.stringify([salt(), value]));
|
|
354
|
+
disclosures.push(raw);
|
|
355
|
+
return { '...': sdDigest(raw, alg) };
|
|
356
|
+
},
|
|
357
|
+
property(name, value) {
|
|
358
|
+
const raw = b64uEncode(JSON.stringify([salt(), name, value]));
|
|
359
|
+
disclosures.push(raw);
|
|
360
|
+
return sdDigest(raw, alg);
|
|
361
|
+
},
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
/** Sign `payload` as an ES256 JWT and append `disclosures`: `<jwt>~<d1>~...~<dn>~`. */
|
|
365
|
+
function signSdJwt(args) {
|
|
366
|
+
const header = b64uEncode(JSON.stringify({ alg: 'ES256', ...args.header }));
|
|
367
|
+
const payload = b64uEncode(JSON.stringify(args.payload));
|
|
368
|
+
const jwt = `${header}.${payload}.${es256Sign(args.privateKey, `${header}.${payload}`)}`;
|
|
369
|
+
return `${jwt}~${args.disclosures.map((d) => `${d}~`).join('')}`;
|
|
370
|
+
}
|
|
371
|
+
/** Sign an arbitrary compact JWT (used for merchant-signed `checkout_jwt`). */
|
|
372
|
+
function signJwtEs256(args) {
|
|
373
|
+
const header = b64uEncode(JSON.stringify({ alg: 'ES256', typ: 'JWT', ...args.header }));
|
|
374
|
+
const payload = b64uEncode(JSON.stringify(args.payload));
|
|
375
|
+
return `${header}.${payload}.${es256Sign(args.privateKey, `${header}.${payload}`)}`;
|
|
376
|
+
}
|
|
377
|
+
function parseJwt(jwt, what) {
|
|
378
|
+
const seg = jwt.split('.');
|
|
379
|
+
if (seg.length !== 3 || seg.some((s) => s.length === 0))
|
|
380
|
+
throw new Ap2Error(`${what}: must be header.payload.signature`);
|
|
381
|
+
const [h, p, s] = seg;
|
|
382
|
+
return {
|
|
383
|
+
header: decodeJsonSegment(h, `${what} header`),
|
|
384
|
+
payload: decodeJsonSegment(p, `${what} payload`),
|
|
385
|
+
signingInput: `${h}.${p}`,
|
|
386
|
+
signature: b64uDecode(s, `${what} signature`),
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
function verifyJwtEs256(parsed, key) {
|
|
390
|
+
if (parsed.header.alg !== 'ES256')
|
|
391
|
+
return false;
|
|
392
|
+
return es256Verify(assertP256Jwk(key, 'verification key'), parsed.signingInput, parsed.signature);
|
|
393
|
+
}
|
|
394
|
+
//# sourceMappingURL=sdjwt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdjwt.js","sourceRoot":"","sources":["../src/sdjwt.ts"],"names":[],"mappings":";;;AAmCA,gCAEC;AAGD,gCAKC;AAED,4BAEC;AA0CD,8BASC;AAgBD,0BAEC;AAGD,4BAGC;AA2BD,sCAaC;AAMD,gDAWC;AAGD,4DAQC;AAGD,sCAGC;AAuCD,4BAEC;AAGD,sCA0BC;AAGD,4BAEC;AAGD,0CAEC;AAGD,gDAGC;AA6BD,gDA0DC;AAMD,0BAEC;AAUD,8CAeC;AAGD,8BAUC;AAGD,oCAIC;AASD,4BAUC;AAED,wCAGC;AAhcD;;;;;;;;GAQG;AACH,6CASqB;AAKrB,uFAAuF;AACvF,MAAa,QAAS,SAAQ,KAAK;IACjC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;IACzB,CAAC;CACF;AALD,4BAKC;AAED,gGAAgG;AAChG,2BAA2B;AAC3B,gGAAgG;AAEhG,SAAgB,UAAU,CAAC,IAAyB;IAClD,OAAO,MAAM,CAAC,IAAI,CAAC,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;AACxG,CAAC;AAED,iGAAiG;AACjG,SAAgB,UAAU,CAAC,CAAS,EAAE,IAAY;IAChD,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC;QAAE,MAAM,IAAI,QAAQ,CAAC,GAAG,IAAI,iBAAiB,CAAC,CAAC;IAC9E,MAAM,GA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,IAAI,OAAO,IAAI,SAAS,CAAC,IAAI,CAAC,UAAU,EAAE,GAAG,MAAM,IAAI,OAAO,EAAE,CAAC,EAAE,CAAC;AACtF,CAAC;AASD,SAAgB,QAAQ,CAAC,GAAW,EAAE,IAAY;IAChD,MAAM,GAAG,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC3B,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC;QAAE,MAAM,IAAI,QAAQ,CAAC,GAAG,IAAI,oCAAoC,CAAC,CAAC;IACzH,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG,GAA+B,CAAC;IAClD,OAAO;QACL,MAAM,EAAE,iBAAiB,CAAC,CAAC,EAAE,GAAG,IAAI,SAAS,CAAc;QAC3D,OAAO,EAAE,iBAAiB,CAAC,CAAC,EAAE,GAAG,IAAI,UAAU,CAAC;QAChD,YAAY,EAAE,GAAG,CAAC,IAAI,CAAC,EAAE;QACzB,SAAS,EAAE,UAAU,CAAC,CAAC,EAAE,GAAG,IAAI,YAAY,CAAC;KAC9C,CAAC;AACJ,CAAC;AAED,SAAgB,cAAc,CAAC,MAAiB,EAAE,GAAY;IAC5D,IAAI,MAAM,CAAC,MAAM,CAAC,GAAG,KAAK,OAAO;QAAE,OAAO,KAAK,CAAC;IAChD,OAAO,WAAW,CAAC,aAAa,CAAC,GAAG,EAAE,kBAAkB,CAAC,EAAE,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC;AACpG,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { type Amount, type PaymentMandateClaims } from './mandates';
|
|
2
|
+
/** Context the caller supplies for building a rail-specific settlement payload. */
|
|
3
|
+
export interface SettlementContext {
|
|
4
|
+
/** Protected resource URL (x402). */
|
|
5
|
+
resourceUrl?: string;
|
|
6
|
+
/** Payee address / account (x402 `payTo`, Stripe `on_behalf_of`). */
|
|
7
|
+
payTo?: string;
|
|
8
|
+
/** Rail network, e.g. an x402 chain id like `base-sepolia`. */
|
|
9
|
+
network?: string;
|
|
10
|
+
/** x402 `asset`: the token contract address. Defaults to the mandate's currency code (a placeholder; supply the address). */
|
|
11
|
+
asset?: string;
|
|
12
|
+
/** x402: decimals of the asset, used to convert the mandate amount to atomic units. Default 6 (USDC). */
|
|
13
|
+
decimals?: number;
|
|
14
|
+
/** x402 `maxTimeoutSeconds`: how long the payer has to complete payment. Default 60. */
|
|
15
|
+
maxTimeoutSeconds?: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Convert integer minor units to an integer string of atomic units. Scales by `10 ** (decimals - exponent)`
|
|
19
|
+
* with BigInt, so no float is involved; when the asset has fewer decimals than the currency the
|
|
20
|
+
* division must be exact. Throws otherwise (fail closed).
|
|
21
|
+
*/
|
|
22
|
+
export declare function toAtomicUnits(amount: Amount, decimals: number): string;
|
|
23
|
+
/** A rail-specific settlement payload shape. No network is performed; this is the wire shape only. */
|
|
24
|
+
export interface SettlementInstruction {
|
|
25
|
+
rail: string;
|
|
26
|
+
amount: Amount;
|
|
27
|
+
merchant?: string;
|
|
28
|
+
/** The rail-specific payload (structural). */
|
|
29
|
+
payload: Readonly<Record<string, unknown>>;
|
|
30
|
+
}
|
|
31
|
+
export interface SettlementBackend {
|
|
32
|
+
readonly rail: string;
|
|
33
|
+
/** Build the rail payload for a (presumed-verified) closed Payment Mandate. Pure; no network. */
|
|
34
|
+
settle(payment: PaymentMandateClaims, ctx?: SettlementContext): SettlementInstruction;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Coinbase x402 adapter: the HTTP 402 `Payment Required` challenge (`accepts`) plus the `X-PAYMENT`
|
|
38
|
+
* request header (standard base64 of the JSON payment payload). The payload is a placeholder envelope,
|
|
39
|
+
* not a signed authorization: the real rail settles on-chain.
|
|
40
|
+
*/
|
|
41
|
+
export declare const x402Settlement: SettlementBackend;
|
|
42
|
+
/**
|
|
43
|
+
* Stripe Shared Payment Token adapter: a shared token the buyer's agent grants the merchant to pull a
|
|
44
|
+
* bounded amount. The mandate amount is already in minor units, which is what Stripe takes. The token
|
|
45
|
+
* is the mandate's payment instrument id, never a raw PAN.
|
|
46
|
+
*/
|
|
47
|
+
export declare const stripeSptSettlement: SettlementBackend;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stripeSptSettlement = exports.x402Settlement = void 0;
|
|
4
|
+
exports.toAtomicUnits = toAtomicUnits;
|
|
5
|
+
/**
|
|
6
|
+
* Settlement backends: the rails PCA's governance feeds. STRUCTURAL ONLY, no network.
|
|
7
|
+
*
|
|
8
|
+
* A backend turns a payment mandate that has ALREADY been verified (`verifyPaymentChain` /
|
|
9
|
+
* `verifyPurchase`, plus `verifyPcaBinding` for the PCA side) into the rail's wire shape. Amounts are
|
|
10
|
+
* the mandate's integer minor units; nothing here accepts a decimal.
|
|
11
|
+
*/
|
|
12
|
+
const sdjwt_1 = require("./sdjwt");
|
|
13
|
+
const mandates_1 = require("./mandates");
|
|
14
|
+
/**
|
|
15
|
+
* Convert integer minor units to an integer string of atomic units. Scales by `10 ** (decimals - exponent)`
|
|
16
|
+
* with BigInt, so no float is involved; when the asset has fewer decimals than the currency the
|
|
17
|
+
* division must be exact. Throws otherwise (fail closed).
|
|
18
|
+
*/
|
|
19
|
+
function toAtomicUnits(amount, decimals) {
|
|
20
|
+
if (!Number.isInteger(decimals) || decimals < 0 || decimals > 18)
|
|
21
|
+
throw new RangeError(`x402: decimals must be an integer in 0..18, got ${String(decimals)}`);
|
|
22
|
+
if (!Number.isSafeInteger(amount.amount) || amount.amount < 0)
|
|
23
|
+
throw new RangeError(`x402: amount ${String(amount.amount)} cannot be expressed in atomic units with ${decimals} decimals`);
|
|
24
|
+
const exp = (0, mandates_1.currencyExponent)(amount.currency);
|
|
25
|
+
const minor = BigInt(amount.amount);
|
|
26
|
+
if (decimals >= exp)
|
|
27
|
+
return String(minor * 10n ** BigInt(decimals - exp));
|
|
28
|
+
const div = 10n ** BigInt(exp - decimals);
|
|
29
|
+
if (minor % div !== 0n)
|
|
30
|
+
throw new RangeError(`x402: amount ${String(amount.amount)} cannot be expressed in atomic units with ${decimals} decimals`);
|
|
31
|
+
return String(minor / div);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Coinbase x402 adapter: the HTTP 402 `Payment Required` challenge (`accepts`) plus the `X-PAYMENT`
|
|
35
|
+
* request header (standard base64 of the JSON payment payload). The payload is a placeholder envelope,
|
|
36
|
+
* not a signed authorization: the real rail settles on-chain.
|
|
37
|
+
*/
|
|
38
|
+
exports.x402Settlement = {
|
|
39
|
+
rail: 'x402',
|
|
40
|
+
settle(payment, ctx) {
|
|
41
|
+
const network = ctx?.network ?? 'base-sepolia';
|
|
42
|
+
const requirement = {
|
|
43
|
+
scheme: 'exact',
|
|
44
|
+
network,
|
|
45
|
+
// x402 v1: `maxAmountRequired` is a string in ATOMIC token units, not a decimal amount.
|
|
46
|
+
maxAmountRequired: toAtomicUnits(payment.payment_amount, ctx?.decimals ?? 6),
|
|
47
|
+
resource: ctx?.resourceUrl ?? '',
|
|
48
|
+
description: `AP2 payment mandate ${payment.transaction_id}`,
|
|
49
|
+
payTo: ctx?.payTo ?? payment.payee.id,
|
|
50
|
+
asset: ctx?.asset ?? payment.payment_amount.currency,
|
|
51
|
+
mimeType: 'application/json',
|
|
52
|
+
maxTimeoutSeconds: ctx?.maxTimeoutSeconds ?? 60,
|
|
53
|
+
};
|
|
54
|
+
const xPayment = Buffer.from(JSON.stringify({
|
|
55
|
+
x402Version: 1,
|
|
56
|
+
scheme: 'exact',
|
|
57
|
+
network,
|
|
58
|
+
payload: { transactionId: payment.transaction_id, amount: payment.payment_amount.amount, currency: payment.payment_amount.currency },
|
|
59
|
+
}), 'utf8').toString('base64');
|
|
60
|
+
return {
|
|
61
|
+
rail: 'x402',
|
|
62
|
+
amount: payment.payment_amount,
|
|
63
|
+
merchant: payment.payee.id,
|
|
64
|
+
payload: { httpStatus: 402, x402Version: 1, error: 'X-PAYMENT header is required', accepts: [requirement], header: { 'X-PAYMENT': xPayment } },
|
|
65
|
+
};
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Stripe Shared Payment Token adapter: a shared token the buyer's agent grants the merchant to pull a
|
|
70
|
+
* bounded amount. The mandate amount is already in minor units, which is what Stripe takes. The token
|
|
71
|
+
* is the mandate's payment instrument id, never a raw PAN.
|
|
72
|
+
*/
|
|
73
|
+
exports.stripeSptSettlement = {
|
|
74
|
+
rail: 'stripe-spt',
|
|
75
|
+
settle(payment, ctx) {
|
|
76
|
+
if (payment.payment_instrument.type !== 'shared_payment_token')
|
|
77
|
+
throw new sdjwt_1.Ap2Error(`stripe-spt: the payment instrument must be of type shared_payment_token, got ${payment.payment_instrument.type}`);
|
|
78
|
+
return {
|
|
79
|
+
rail: 'stripe-spt',
|
|
80
|
+
amount: payment.payment_amount,
|
|
81
|
+
merchant: payment.payee.id,
|
|
82
|
+
payload: {
|
|
83
|
+
shared_payment_token: payment.payment_instrument.id,
|
|
84
|
+
amount: payment.payment_amount.amount,
|
|
85
|
+
currency: payment.payment_amount.currency.toLowerCase(),
|
|
86
|
+
...(ctx?.payTo ? { on_behalf_of: ctx.payTo } : {}),
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
//# sourceMappingURL=settlement.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"settlement.js","sourceRoot":"","sources":["../src/settlement.ts"],"names":[],"mappings":";;;AA+BA,sCASC;AAxCD;;;;;;GAMG;AACH,mCAAmC;AACnC,yCAAsF;AAkBtF;;;;GAIG;AACH,SAAgB,aAAa,CAAC,M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ACjB,IAAI,OAAO,CAAC,kBAAkB,CAAC,IAAI,KAAK,sBAAsB;YAAE,MAAM,IAAI,gBAAQ,CAAC,gFAAgF,OAAO,CAAC,kBAAkB,CAAC,IAAI,EAAE,CAAC,CAAC;QACtM,OAAO;YACL,IAAI,EAAE,YAAY;YAClB,MAAM,EAAE,OAAO,CAAC,cAAc;YAC9B,QAAQ,EAAE,OAAO,CAAC,KAAK,CAAC,EAAE;YAC1B,OAAO,EAAE;gBACP,oBAAoB,EAAE,OAAO,CAAC,kBAAkB,CAAC,EAAE;gBACnD,MAAM,EAAE,OAAO,CAAC,cAAc,CAAC,MAAM;gBACrC,QAAQ,EAAE,OAAO,CAAC,cAAc,CAAC,QAAQ,CAAC,WAAW,EAAE;gBACvD,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,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlasauth/pca-ap2",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "AP2
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "AP2 (Agent Payments Protocol) Intent/Cart/Payment mandates as real SD-JWT credentials (integer minor units, key binding), bound to a PCA grant and action proof; x402 / Stripe Shared-Payment-Token settlement shapes.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ap2",
|
|
7
7
|
"agent payments protocol",
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"./package.json": "./package.json"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@atlasauth/pca
|
|
36
|
-
"@atlasauth/pca": "0.
|
|
35
|
+
"@atlasauth/pca": "0.4.0",
|
|
36
|
+
"@atlasauth/pca-payments": "0.4.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"ajv": "8.20.0",
|