@peac/mappings-paymentauth 0.12.4
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/LICENSE +190 -0
- package/README.md +31 -0
- package/dist/carrier.d.ts +80 -0
- package/dist/carrier.d.ts.map +1 -0
- package/dist/carrier.js +169 -0
- package/dist/carrier.js.map +1 -0
- package/dist/constants.d.ts +34 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +46 -0
- package/dist/constants.js.map +1 -0
- package/dist/discovery.d.ts +23 -0
- package/dist/discovery.d.ts.map +1 -0
- package/dist/discovery.js +74 -0
- package/dist/discovery.js.map +1 -0
- package/dist/errors.d.ts +13 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +20 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +63 -0
- package/dist/index.js.map +1 -0
- package/dist/jsonrpc.d.ts +37 -0
- package/dist/jsonrpc.d.ts.map +1 -0
- package/dist/jsonrpc.js +83 -0
- package/dist/jsonrpc.js.map +1 -0
- package/dist/map.d.ts +38 -0
- package/dist/map.d.ts.map +1 -0
- package/dist/map.js +96 -0
- package/dist/map.js.map +1 -0
- package/dist/mcp.d.ts +44 -0
- package/dist/mcp.d.ts.map +1 -0
- package/dist/mcp.js +62 -0
- package/dist/mcp.js.map +1 -0
- package/dist/parse.d.ts +70 -0
- package/dist/parse.d.ts.map +1 -0
- package/dist/parse.js +399 -0
- package/dist/parse.js.map +1 -0
- package/dist/types.d.ts +139 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +16 -0
- package/dist/types.js.map +1 -0
- package/package.json +40 -0
package/dist/parse.d.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Paymentauth header parsing: envelope-first, raw + normalized.
|
|
3
|
+
*
|
|
4
|
+
* Parses WWW-Authenticate: Payment challenges, Authorization: Payment
|
|
5
|
+
* credentials, and Payment-Receipt headers per draft-ryan-httpauth-payment-01.
|
|
6
|
+
*
|
|
7
|
+
* SECURITY:
|
|
8
|
+
* - Raw header values MUST NOT appear in thrown errors or debug output
|
|
9
|
+
* - Parser limits enforced: header size, param count, payload size, JSON depth
|
|
10
|
+
* - Decoded bytes preserved alongside strings for non-UTF-8 safety
|
|
11
|
+
* - Method-specific payloads typed as `unknown`; no eager interpretation
|
|
12
|
+
*/
|
|
13
|
+
import type { RawPaymentauthChallenge, RawPaymentauthCredential, RawPaymentauthReceipt, NormalizedPaymentauthChallenge, NormalizedPaymentauthCredential, NormalizedPaymentauthReceipt } from './types.js';
|
|
14
|
+
/**
|
|
15
|
+
* Redact a paymentauth header value for safe logging.
|
|
16
|
+
*
|
|
17
|
+
* Preserves the scheme name and challenge id (if present) but replaces
|
|
18
|
+
* credential/receipt payload with "[REDACTED]".
|
|
19
|
+
*/
|
|
20
|
+
export declare function redactPaymentauthHeader(header: string): string;
|
|
21
|
+
/**
|
|
22
|
+
* Parse paymentauth challenges from WWW-Authenticate header value.
|
|
23
|
+
*
|
|
24
|
+
* Parses the FIRST Payment challenge from a WWW-Authenticate header value.
|
|
25
|
+
*
|
|
26
|
+
* NOTE: RFC 9110 allows multiple challenges per header line (Section 7.3),
|
|
27
|
+
* but robust multi-challenge splitting requires a full quote-aware tokenizer.
|
|
28
|
+
* This parser extracts the first Payment challenge reliably. For headers
|
|
29
|
+
* with multiple Payment challenges, use separate WWW-Authenticate header
|
|
30
|
+
* lines (one challenge per line) which is the recommended interoperability
|
|
31
|
+
* approach per RFC 9110.
|
|
32
|
+
*
|
|
33
|
+
* Returns an array for forward compatibility; currently contains at most
|
|
34
|
+
* one challenge.
|
|
35
|
+
*/
|
|
36
|
+
export declare function parsePaymentauthChallenges(wwwAuthenticate: string): RawPaymentauthChallenge[];
|
|
37
|
+
/**
|
|
38
|
+
* Parse paymentauth credential from Authorization header value.
|
|
39
|
+
*
|
|
40
|
+
* Format: "Payment <base64url-nopad>" (Section 5.2)
|
|
41
|
+
*/
|
|
42
|
+
export declare function parsePaymentauthCredential(authorization: string): RawPaymentauthCredential;
|
|
43
|
+
/**
|
|
44
|
+
* Parse paymentauth receipt from Payment-Receipt header value.
|
|
45
|
+
*
|
|
46
|
+
* Format: base64url-nopad (Section 5.3)
|
|
47
|
+
*/
|
|
48
|
+
export declare function parsePaymentauthReceipt(headerValue: string): RawPaymentauthReceipt;
|
|
49
|
+
/**
|
|
50
|
+
* Normalize a raw challenge into a stable PEAC-facing projection.
|
|
51
|
+
*
|
|
52
|
+
* Requires id, realm, method, intent, request (common envelope).
|
|
53
|
+
* All other params are optional.
|
|
54
|
+
*/
|
|
55
|
+
export declare function normalizeChallenge(raw: RawPaymentauthChallenge): NormalizedPaymentauthChallenge;
|
|
56
|
+
/**
|
|
57
|
+
* Normalize a raw credential into a stable PEAC-facing projection.
|
|
58
|
+
*
|
|
59
|
+
* Extracts challenge.id, method, intent, and source from the decoded JSON
|
|
60
|
+
* if it is object-shaped. Method-specific payload remains `unknown`.
|
|
61
|
+
*/
|
|
62
|
+
export declare function normalizeCredential(raw: RawPaymentauthCredential): NormalizedPaymentauthCredential;
|
|
63
|
+
/**
|
|
64
|
+
* Normalize a raw receipt into a stable PEAC-facing projection.
|
|
65
|
+
*
|
|
66
|
+
* Extracts status, method, timestamp, reference from decoded JSON.
|
|
67
|
+
* All other fields go into extras.
|
|
68
|
+
*/
|
|
69
|
+
export declare function normalizeReceipt(raw: RawPaymentauthReceipt): NormalizedPaymentauthReceipt;
|
|
70
|
+
//# sourceMappingURL=parse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../src/parse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAUH,OAAO,KAAK,EACV,uBAAuB,EACvB,wBAAwB,EACxB,qBAAqB,EACrB,8BAA8B,EAC9B,+BAA+B,EAC/B,4BAA4B,EAC7B,MAAM,YAAY,CAAC;AAMpB;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAa9D;AAgKD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,0BAA0B,CAAC,eAAe,EAAE,MAAM,GAAG,uBAAuB,EAAE,CA0B7F;AAED;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,aAAa,EAAE,MAAM,GAAG,wBAAwB,CAsC1F;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,WAAW,EAAE,MAAM,GAAG,qBAAqB,CA4BlF;AAMD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,uBAAuB,GAAG,8BAA8B,CAsC/F;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,wBAAwB,GAC5B,+BAA+B,CAmCjC;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,qBAAqB,GAAG,4BAA4B,CAgCzF"}
|
package/dist/parse.js
ADDED
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Paymentauth header parsing: envelope-first, raw + normalized.
|
|
4
|
+
*
|
|
5
|
+
* Parses WWW-Authenticate: Payment challenges, Authorization: Payment
|
|
6
|
+
* credentials, and Payment-Receipt headers per draft-ryan-httpauth-payment-01.
|
|
7
|
+
*
|
|
8
|
+
* SECURITY:
|
|
9
|
+
* - Raw header values MUST NOT appear in thrown errors or debug output
|
|
10
|
+
* - Parser limits enforced: header size, param count, payload size, JSON depth
|
|
11
|
+
* - Decoded bytes preserved alongside strings for non-UTF-8 safety
|
|
12
|
+
* - Method-specific payloads typed as `unknown`; no eager interpretation
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.redactPaymentauthHeader = redactPaymentauthHeader;
|
|
16
|
+
exports.parsePaymentauthChallenges = parsePaymentauthChallenges;
|
|
17
|
+
exports.parsePaymentauthCredential = parsePaymentauthCredential;
|
|
18
|
+
exports.parsePaymentauthReceipt = parsePaymentauthReceipt;
|
|
19
|
+
exports.normalizeChallenge = normalizeChallenge;
|
|
20
|
+
exports.normalizeCredential = normalizeCredential;
|
|
21
|
+
exports.normalizeReceipt = normalizeReceipt;
|
|
22
|
+
const constants_js_1 = require("./constants.js");
|
|
23
|
+
const errors_js_1 = require("./errors.js");
|
|
24
|
+
// ---------------------------------------------------------------------------
|
|
25
|
+
// Redaction
|
|
26
|
+
// ---------------------------------------------------------------------------
|
|
27
|
+
/**
|
|
28
|
+
* Redact a paymentauth header value for safe logging.
|
|
29
|
+
*
|
|
30
|
+
* Preserves the scheme name and challenge id (if present) but replaces
|
|
31
|
+
* credential/receipt payload with "[REDACTED]".
|
|
32
|
+
*/
|
|
33
|
+
function redactPaymentauthHeader(header) {
|
|
34
|
+
if (!header)
|
|
35
|
+
return '[empty]';
|
|
36
|
+
const schemeEnd = header.indexOf(' ');
|
|
37
|
+
if (schemeEnd === -1)
|
|
38
|
+
return header;
|
|
39
|
+
const scheme = header.substring(0, schemeEnd);
|
|
40
|
+
// For challenges (WWW-Authenticate), try to preserve id param
|
|
41
|
+
const idMatch = header.match(/\bid="([^"]{1,64})"/);
|
|
42
|
+
if (idMatch) {
|
|
43
|
+
return `${scheme} id="${idMatch[1]}" [REDACTED]`;
|
|
44
|
+
}
|
|
45
|
+
return `${scheme} [REDACTED]`;
|
|
46
|
+
}
|
|
47
|
+
// ---------------------------------------------------------------------------
|
|
48
|
+
// Base64url Helpers
|
|
49
|
+
// ---------------------------------------------------------------------------
|
|
50
|
+
/**
|
|
51
|
+
* Decode base64url without padding (RFC 4648 Section 5).
|
|
52
|
+
* Returns raw bytes as Uint8Array.
|
|
53
|
+
*/
|
|
54
|
+
function decodeBase64url(input) {
|
|
55
|
+
// Validate characters
|
|
56
|
+
if (!/^[A-Za-z0-9_-]*$/.test(input)) {
|
|
57
|
+
throw new errors_js_1.PaymentauthError('PARSE_INVALID_BASE64URL', 'Invalid base64url characters');
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
// Add padding
|
|
61
|
+
const padded = input + '==='.slice(0, (4 - (input.length % 4)) % 4);
|
|
62
|
+
const standard = padded.replace(/-/g, '+').replace(/_/g, '/');
|
|
63
|
+
// Use Buffer in Node.js for predictable server-side behavior
|
|
64
|
+
if (typeof Buffer !== 'undefined') {
|
|
65
|
+
return new Uint8Array(Buffer.from(standard, 'base64'));
|
|
66
|
+
}
|
|
67
|
+
// Fallback to atob for non-Node environments
|
|
68
|
+
const binaryStr = atob(standard);
|
|
69
|
+
const bytes = new Uint8Array(binaryStr.length);
|
|
70
|
+
for (let i = 0; i < binaryStr.length; i++) {
|
|
71
|
+
bytes[i] = binaryStr.charCodeAt(i);
|
|
72
|
+
}
|
|
73
|
+
return bytes;
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
throw new errors_js_1.PaymentauthError('PARSE_INVALID_BASE64URL', 'Failed to decode base64url value');
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Try to decode bytes as UTF-8 string.
|
|
81
|
+
* Returns null if bytes are not valid UTF-8.
|
|
82
|
+
*/
|
|
83
|
+
function tryDecodeUtf8(bytes) {
|
|
84
|
+
try {
|
|
85
|
+
const decoder = new TextDecoder('utf-8', { fatal: true });
|
|
86
|
+
return decoder.decode(bytes);
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Try to parse a string as JSON with depth checking.
|
|
94
|
+
* Returns undefined on any failure.
|
|
95
|
+
*/
|
|
96
|
+
function tryParseJsonBounded(str, maxDepth) {
|
|
97
|
+
if (str.length > constants_js_1.MAX_DECODED_PAYLOAD_BYTES) {
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
try {
|
|
101
|
+
const parsed = JSON.parse(str);
|
|
102
|
+
if (!checkJsonDepth(parsed, maxDepth, 0)) {
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
return parsed;
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
return undefined;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
function checkJsonDepth(value, maxDepth, current) {
|
|
112
|
+
if (current > maxDepth)
|
|
113
|
+
return false;
|
|
114
|
+
if (value === null || typeof value !== 'object')
|
|
115
|
+
return true;
|
|
116
|
+
if (Array.isArray(value)) {
|
|
117
|
+
return value.every((v) => checkJsonDepth(v, maxDepth, current + 1));
|
|
118
|
+
}
|
|
119
|
+
return Object.values(value).every((v) => checkJsonDepth(v, maxDepth, current + 1));
|
|
120
|
+
}
|
|
121
|
+
// ---------------------------------------------------------------------------
|
|
122
|
+
// Auth-param Parsing (RFC 9110 Section 11)
|
|
123
|
+
// ---------------------------------------------------------------------------
|
|
124
|
+
/**
|
|
125
|
+
* Parse auth-params from a challenge string.
|
|
126
|
+
*
|
|
127
|
+
* Handles both token and quoted-string values per RFC 9110.
|
|
128
|
+
* Rejects duplicate params. Bounds-checks param count.
|
|
129
|
+
*/
|
|
130
|
+
function parseAuthParams(paramStr) {
|
|
131
|
+
const params = {};
|
|
132
|
+
let pos = 0;
|
|
133
|
+
let count = 0;
|
|
134
|
+
while (pos < paramStr.length) {
|
|
135
|
+
// Skip whitespace and commas
|
|
136
|
+
while (pos < paramStr.length && /[\s,]/.test(paramStr[pos]))
|
|
137
|
+
pos++;
|
|
138
|
+
if (pos >= paramStr.length)
|
|
139
|
+
break;
|
|
140
|
+
// Parse token (key)
|
|
141
|
+
const keyStart = pos;
|
|
142
|
+
while (pos < paramStr.length && /[A-Za-z0-9!#$%&'*+\-.^_`|~]/.test(paramStr[pos]))
|
|
143
|
+
pos++;
|
|
144
|
+
const key = paramStr.substring(keyStart, pos).toLowerCase();
|
|
145
|
+
if (!key)
|
|
146
|
+
break;
|
|
147
|
+
// Skip BWS = BWS
|
|
148
|
+
while (pos < paramStr.length && /\s/.test(paramStr[pos]))
|
|
149
|
+
pos++;
|
|
150
|
+
if (paramStr[pos] !== '=')
|
|
151
|
+
break;
|
|
152
|
+
pos++; // skip =
|
|
153
|
+
while (pos < paramStr.length && /\s/.test(paramStr[pos]))
|
|
154
|
+
pos++;
|
|
155
|
+
// Parse value: quoted-string or token
|
|
156
|
+
let value;
|
|
157
|
+
if (paramStr[pos] === '"') {
|
|
158
|
+
// Quoted string
|
|
159
|
+
pos++; // skip opening quote
|
|
160
|
+
let escaped = '';
|
|
161
|
+
while (pos < paramStr.length && paramStr[pos] !== '"') {
|
|
162
|
+
if (paramStr[pos] === '\\' && pos + 1 < paramStr.length) {
|
|
163
|
+
pos++;
|
|
164
|
+
escaped += paramStr[pos];
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
escaped += paramStr[pos];
|
|
168
|
+
}
|
|
169
|
+
pos++;
|
|
170
|
+
}
|
|
171
|
+
if (paramStr[pos] === '"')
|
|
172
|
+
pos++; // skip closing quote
|
|
173
|
+
value = escaped;
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
// Token value
|
|
177
|
+
const valStart = pos;
|
|
178
|
+
while (pos < paramStr.length && !/[\s,]/.test(paramStr[pos]))
|
|
179
|
+
pos++;
|
|
180
|
+
value = paramStr.substring(valStart, pos);
|
|
181
|
+
}
|
|
182
|
+
count++;
|
|
183
|
+
if (count > constants_js_1.MAX_AUTH_PARAMS) {
|
|
184
|
+
throw new errors_js_1.PaymentauthError('PARSE_TOO_MANY_PARAMS', `Challenge exceeds maximum param count (${constants_js_1.MAX_AUTH_PARAMS})`);
|
|
185
|
+
}
|
|
186
|
+
if (key in params) {
|
|
187
|
+
throw new errors_js_1.PaymentauthError('PARSE_TOO_MANY_PARAMS', `Duplicate auth-param: ${key}`);
|
|
188
|
+
}
|
|
189
|
+
params[key] = value;
|
|
190
|
+
}
|
|
191
|
+
return params;
|
|
192
|
+
}
|
|
193
|
+
// ---------------------------------------------------------------------------
|
|
194
|
+
// Challenge Parsing
|
|
195
|
+
// ---------------------------------------------------------------------------
|
|
196
|
+
/**
|
|
197
|
+
* Parse paymentauth challenges from WWW-Authenticate header value.
|
|
198
|
+
*
|
|
199
|
+
* Parses the FIRST Payment challenge from a WWW-Authenticate header value.
|
|
200
|
+
*
|
|
201
|
+
* NOTE: RFC 9110 allows multiple challenges per header line (Section 7.3),
|
|
202
|
+
* but robust multi-challenge splitting requires a full quote-aware tokenizer.
|
|
203
|
+
* This parser extracts the first Payment challenge reliably. For headers
|
|
204
|
+
* with multiple Payment challenges, use separate WWW-Authenticate header
|
|
205
|
+
* lines (one challenge per line) which is the recommended interoperability
|
|
206
|
+
* approach per RFC 9110.
|
|
207
|
+
*
|
|
208
|
+
* Returns an array for forward compatibility; currently contains at most
|
|
209
|
+
* one challenge.
|
|
210
|
+
*/
|
|
211
|
+
function parsePaymentauthChallenges(wwwAuthenticate) {
|
|
212
|
+
const headerBytes = new TextEncoder().encode(wwwAuthenticate);
|
|
213
|
+
if (headerBytes.length > constants_js_1.MAX_HEADER_BYTES) {
|
|
214
|
+
throw new errors_js_1.PaymentauthError('PARSE_HEADER_TOO_LARGE', `Header exceeds ${constants_js_1.MAX_HEADER_BYTES} bytes`);
|
|
215
|
+
}
|
|
216
|
+
// Find the first "Payment " occurrence (case-insensitive per RFC 9110)
|
|
217
|
+
const schemePattern = new RegExp(`\\b${constants_js_1.PAYMENTAUTH_SCHEME}\\s+`, 'i');
|
|
218
|
+
const match = schemePattern.exec(wwwAuthenticate);
|
|
219
|
+
if (!match)
|
|
220
|
+
return [];
|
|
221
|
+
const paramStart = match.index + match[0].length;
|
|
222
|
+
const paramStr = wwwAuthenticate.substring(paramStart).trim();
|
|
223
|
+
const params = parseAuthParams(paramStr);
|
|
224
|
+
return [
|
|
225
|
+
{
|
|
226
|
+
rawHeader: wwwAuthenticate,
|
|
227
|
+
rawSegment: wwwAuthenticate.substring(match.index),
|
|
228
|
+
params,
|
|
229
|
+
},
|
|
230
|
+
];
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Parse paymentauth credential from Authorization header value.
|
|
234
|
+
*
|
|
235
|
+
* Format: "Payment <base64url-nopad>" (Section 5.2)
|
|
236
|
+
*/
|
|
237
|
+
function parsePaymentauthCredential(authorization) {
|
|
238
|
+
const headerBytes = new TextEncoder().encode(authorization);
|
|
239
|
+
if (headerBytes.length > constants_js_1.MAX_HEADER_BYTES) {
|
|
240
|
+
throw new errors_js_1.PaymentauthError('PARSE_HEADER_TOO_LARGE', `Header exceeds ${constants_js_1.MAX_HEADER_BYTES} bytes`);
|
|
241
|
+
}
|
|
242
|
+
// RFC 9110: authentication scheme tokens are case-insensitive
|
|
243
|
+
const schemePrefixLen = constants_js_1.PAYMENTAUTH_SCHEME.length + 1; // "Payment "
|
|
244
|
+
const headerPrefix = authorization.substring(0, schemePrefixLen);
|
|
245
|
+
if (headerPrefix.toLowerCase() !== `${constants_js_1.PAYMENTAUTH_SCHEME.toLowerCase()} `) {
|
|
246
|
+
throw new errors_js_1.PaymentauthError('PARSE_MISSING_SCHEME', `Expected "${constants_js_1.PAYMENTAUTH_SCHEME}" scheme prefix (case-insensitive)`);
|
|
247
|
+
}
|
|
248
|
+
const rawValue = authorization.substring(schemePrefixLen).trim();
|
|
249
|
+
if (!rawValue) {
|
|
250
|
+
throw new errors_js_1.PaymentauthError('PARSE_INVALID_BASE64URL', 'Empty credential value');
|
|
251
|
+
}
|
|
252
|
+
const decodedBytes = decodeBase64url(rawValue);
|
|
253
|
+
if (decodedBytes.length > constants_js_1.MAX_DECODED_PAYLOAD_BYTES) {
|
|
254
|
+
throw new errors_js_1.PaymentauthError('PARSE_PAYLOAD_TOO_LARGE', `Decoded payload exceeds ${constants_js_1.MAX_DECODED_PAYLOAD_BYTES} bytes`);
|
|
255
|
+
}
|
|
256
|
+
const decodedString = tryDecodeUtf8(decodedBytes);
|
|
257
|
+
const parsedJson = decodedString
|
|
258
|
+
? tryParseJsonBounded(decodedString, constants_js_1.MAX_JSON_NESTING_DEPTH)
|
|
259
|
+
: undefined;
|
|
260
|
+
return { rawValue, decodedBytes, decodedString, parsedJson };
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Parse paymentauth receipt from Payment-Receipt header value.
|
|
264
|
+
*
|
|
265
|
+
* Format: base64url-nopad (Section 5.3)
|
|
266
|
+
*/
|
|
267
|
+
function parsePaymentauthReceipt(headerValue) {
|
|
268
|
+
const headerBytes = new TextEncoder().encode(headerValue);
|
|
269
|
+
if (headerBytes.length > constants_js_1.MAX_HEADER_BYTES) {
|
|
270
|
+
throw new errors_js_1.PaymentauthError('PARSE_HEADER_TOO_LARGE', `Header exceeds ${constants_js_1.MAX_HEADER_BYTES} bytes`);
|
|
271
|
+
}
|
|
272
|
+
const rawValue = headerValue.trim();
|
|
273
|
+
if (!rawValue) {
|
|
274
|
+
throw new errors_js_1.PaymentauthError('PARSE_INVALID_BASE64URL', 'Empty receipt value');
|
|
275
|
+
}
|
|
276
|
+
const decodedBytes = decodeBase64url(rawValue);
|
|
277
|
+
if (decodedBytes.length > constants_js_1.MAX_DECODED_PAYLOAD_BYTES) {
|
|
278
|
+
throw new errors_js_1.PaymentauthError('PARSE_PAYLOAD_TOO_LARGE', `Decoded payload exceeds ${constants_js_1.MAX_DECODED_PAYLOAD_BYTES} bytes`);
|
|
279
|
+
}
|
|
280
|
+
const decodedString = tryDecodeUtf8(decodedBytes);
|
|
281
|
+
const parsedJson = decodedString
|
|
282
|
+
? tryParseJsonBounded(decodedString, constants_js_1.MAX_JSON_NESTING_DEPTH)
|
|
283
|
+
: undefined;
|
|
284
|
+
return { rawValue, decodedBytes, decodedString, parsedJson };
|
|
285
|
+
}
|
|
286
|
+
// ---------------------------------------------------------------------------
|
|
287
|
+
// Normalization
|
|
288
|
+
// ---------------------------------------------------------------------------
|
|
289
|
+
/**
|
|
290
|
+
* Normalize a raw challenge into a stable PEAC-facing projection.
|
|
291
|
+
*
|
|
292
|
+
* Requires id, realm, method, intent, request (common envelope).
|
|
293
|
+
* All other params are optional.
|
|
294
|
+
*/
|
|
295
|
+
function normalizeChallenge(raw) {
|
|
296
|
+
const { params } = raw;
|
|
297
|
+
const required = ['id', 'realm', 'method', 'intent', 'request'];
|
|
298
|
+
for (const key of required) {
|
|
299
|
+
if (!params[key]) {
|
|
300
|
+
throw new errors_js_1.PaymentauthError('NORMALIZE_MISSING_FIELD', `Missing required challenge param: ${key}`);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
// Decode the request param (base64url JSON)
|
|
304
|
+
let decodedRequest;
|
|
305
|
+
try {
|
|
306
|
+
const requestBytes = decodeBase64url(params.request);
|
|
307
|
+
const requestStr = tryDecodeUtf8(requestBytes);
|
|
308
|
+
decodedRequest = requestStr
|
|
309
|
+
? tryParseJsonBounded(requestStr, constants_js_1.MAX_JSON_NESTING_DEPTH)
|
|
310
|
+
: undefined;
|
|
311
|
+
}
|
|
312
|
+
catch {
|
|
313
|
+
decodedRequest = undefined;
|
|
314
|
+
}
|
|
315
|
+
return {
|
|
316
|
+
id: params.id,
|
|
317
|
+
realm: params.realm,
|
|
318
|
+
method: params.method,
|
|
319
|
+
intent: params.intent,
|
|
320
|
+
requestRaw: params.request,
|
|
321
|
+
decodedRequest,
|
|
322
|
+
expires: params.expires,
|
|
323
|
+
digest: params.digest,
|
|
324
|
+
description: params.description,
|
|
325
|
+
opaque: params.opaque,
|
|
326
|
+
_raw: raw,
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Normalize a raw credential into a stable PEAC-facing projection.
|
|
331
|
+
*
|
|
332
|
+
* Extracts challenge.id, method, intent, and source from the decoded JSON
|
|
333
|
+
* if it is object-shaped. Method-specific payload remains `unknown`.
|
|
334
|
+
*/
|
|
335
|
+
function normalizeCredential(raw) {
|
|
336
|
+
const obj = raw.parsedJson;
|
|
337
|
+
if (!obj || typeof obj !== 'object' || Array.isArray(obj)) {
|
|
338
|
+
throw new errors_js_1.PaymentauthError('NORMALIZE_MISSING_FIELD', 'Credential decoded JSON is not an object');
|
|
339
|
+
}
|
|
340
|
+
const cred = obj;
|
|
341
|
+
const challenge = cred.challenge;
|
|
342
|
+
if (!challenge || typeof challenge !== 'object') {
|
|
343
|
+
throw new errors_js_1.PaymentauthError('NORMALIZE_MISSING_FIELD', 'Credential missing challenge object');
|
|
344
|
+
}
|
|
345
|
+
// Require essential envelope fields; do not coerce missing to empty string
|
|
346
|
+
if (typeof challenge.id !== 'string' || !challenge.id) {
|
|
347
|
+
throw new errors_js_1.PaymentauthError('NORMALIZE_MISSING_FIELD', 'Credential challenge.id is missing');
|
|
348
|
+
}
|
|
349
|
+
if (typeof challenge.method !== 'string' || !challenge.method) {
|
|
350
|
+
throw new errors_js_1.PaymentauthError('NORMALIZE_MISSING_FIELD', 'Credential challenge.method is missing');
|
|
351
|
+
}
|
|
352
|
+
if (typeof challenge.intent !== 'string' || !challenge.intent) {
|
|
353
|
+
throw new errors_js_1.PaymentauthError('NORMALIZE_MISSING_FIELD', 'Credential challenge.intent is missing');
|
|
354
|
+
}
|
|
355
|
+
return {
|
|
356
|
+
challengeId: challenge.id,
|
|
357
|
+
method: challenge.method,
|
|
358
|
+
intent: challenge.intent,
|
|
359
|
+
source: typeof cred.source === 'string' ? cred.source : undefined,
|
|
360
|
+
payload: cred.payload,
|
|
361
|
+
_raw: raw,
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Normalize a raw receipt into a stable PEAC-facing projection.
|
|
366
|
+
*
|
|
367
|
+
* Extracts status, method, timestamp, reference from decoded JSON.
|
|
368
|
+
* All other fields go into extras.
|
|
369
|
+
*/
|
|
370
|
+
function normalizeReceipt(raw) {
|
|
371
|
+
const obj = raw.parsedJson;
|
|
372
|
+
if (!obj || typeof obj !== 'object' || Array.isArray(obj)) {
|
|
373
|
+
throw new errors_js_1.PaymentauthError('NORMALIZE_MISSING_FIELD', 'Receipt decoded JSON is not an object');
|
|
374
|
+
}
|
|
375
|
+
const receipt = obj;
|
|
376
|
+
const knownKeys = new Set(['status', 'method', 'timestamp', 'reference']);
|
|
377
|
+
const extras = {};
|
|
378
|
+
for (const [key, value] of Object.entries(receipt)) {
|
|
379
|
+
if (!knownKeys.has(key)) {
|
|
380
|
+
extras[key] = value;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
// Require essential receipt envelope fields
|
|
384
|
+
if (typeof receipt.status !== 'string' || !receipt.status) {
|
|
385
|
+
throw new errors_js_1.PaymentauthError('NORMALIZE_MISSING_FIELD', 'Receipt status is missing');
|
|
386
|
+
}
|
|
387
|
+
if (typeof receipt.method !== 'string' || !receipt.method) {
|
|
388
|
+
throw new errors_js_1.PaymentauthError('NORMALIZE_MISSING_FIELD', 'Receipt method is missing');
|
|
389
|
+
}
|
|
390
|
+
return {
|
|
391
|
+
status: receipt.status,
|
|
392
|
+
method: receipt.method,
|
|
393
|
+
timestamp: typeof receipt.timestamp === 'string' ? receipt.timestamp : undefined,
|
|
394
|
+
reference: typeof receipt.reference === 'string' ? receipt.reference : undefined,
|
|
395
|
+
extras,
|
|
396
|
+
_raw: raw,
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
//# sourceMappingURL=parse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse.js","sourceRoot":"","sources":["../src/parse.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;AA6BH,0DAaC;AA+KD,gEA0BC;AAOD,gEAsCC;AAOD,0DA4BC;AAYD,gDAsCC;AAQD,kDAqCC;AAQD,4CAgCC;AAxcD,iDAMwB;AACxB,2CAA+C;AAU/C,8EAA8E;AAC9E,YAAY;AACZ,8EAA8E;AAE9E;;;;;GAKG;AACH,SAAgB,uBAAuB,CAAC,MAAc;IACpD,IAAI,CAAC,MAAM;QAAE,OAAO,SAAS,CAAC;IAC9B,MAAM,SAAS,GAAG,MA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AAC;IAED,OAAO;QACL,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,SAAS,EAAE,OAAO,OAAO,CAAC,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS;QAChF,SAAS,EAAE,OAAO,OAAO,CAAC,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS;QAChF,MAAM;QACN,IAAI,EAAE,GAAG;KACV,CAAC;AACJ,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Paymentauth wire types: raw + normalized.
|
|
3
|
+
*
|
|
4
|
+
* Envelope-first design: the stable surface is the common envelope
|
|
5
|
+
* (id, realm, method, intent, request, expires, digest, opaque).
|
|
6
|
+
* Method-specific payloads (request content, credential payload,
|
|
7
|
+
* receipt details) are typed as `unknown` because each payment method
|
|
8
|
+
* (card, lightning, stripe, tempo) has its own draft spec.
|
|
9
|
+
*
|
|
10
|
+
* Raw types preserve the original wire form exactly.
|
|
11
|
+
* Normalized types project a stable PEAC-facing structure.
|
|
12
|
+
* Every normalized type retains a `_raw` field for traceability.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Raw paymentauth challenge from WWW-Authenticate header.
|
|
16
|
+
*
|
|
17
|
+
* Preserves the original header string and parsed auth-params.
|
|
18
|
+
* The `request` field is kept as raw base64url (not decoded).
|
|
19
|
+
*/
|
|
20
|
+
export interface RawPaymentauthChallenge {
|
|
21
|
+
/** Original full header string (for redaction and traceability) */
|
|
22
|
+
rawHeader: string;
|
|
23
|
+
/** Raw segment of the header corresponding to this challenge (for precise tracing) */
|
|
24
|
+
rawSegment: string;
|
|
25
|
+
/** Parsed auth-param key-value pairs */
|
|
26
|
+
params: Record<string, string>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Raw paymentauth credential from Authorization header.
|
|
30
|
+
*
|
|
31
|
+
* The decoded JSON payload is typed as `unknown` because the
|
|
32
|
+
* credential structure contains method-specific `payload` fields.
|
|
33
|
+
*/
|
|
34
|
+
export interface RawPaymentauthCredential {
|
|
35
|
+
/** Original base64url-encoded header value (after scheme prefix) */
|
|
36
|
+
rawValue: string;
|
|
37
|
+
/** Decoded bytes as Uint8Array (preserved for non-UTF-8 safety) */
|
|
38
|
+
decodedBytes: Uint8Array;
|
|
39
|
+
/** Decoded UTF-8 string, or null if bytes are not valid UTF-8 */
|
|
40
|
+
decodedString: string | null;
|
|
41
|
+
/** Parsed JSON object if decoding and parsing succeeded, otherwise undefined */
|
|
42
|
+
parsedJson: unknown;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Raw paymentauth receipt from Payment-Receipt header.
|
|
46
|
+
*
|
|
47
|
+
* Same raw preservation pattern as credential.
|
|
48
|
+
*/
|
|
49
|
+
export interface RawPaymentauthReceipt {
|
|
50
|
+
/** Original base64url-encoded header value */
|
|
51
|
+
rawValue: string;
|
|
52
|
+
/** Decoded bytes as Uint8Array */
|
|
53
|
+
decodedBytes: Uint8Array;
|
|
54
|
+
/** Decoded UTF-8 string, or null if bytes are not valid UTF-8 */
|
|
55
|
+
decodedString: string | null;
|
|
56
|
+
/** Parsed JSON object if decoding and parsing succeeded */
|
|
57
|
+
parsedJson: unknown;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Normalized paymentauth challenge.
|
|
61
|
+
*
|
|
62
|
+
* Only common envelope fields are typed. Method-specific data within
|
|
63
|
+
* the decoded request is typed as `unknown`.
|
|
64
|
+
*/
|
|
65
|
+
export interface NormalizedPaymentauthChallenge {
|
|
66
|
+
id: string;
|
|
67
|
+
realm: string;
|
|
68
|
+
method: string;
|
|
69
|
+
intent: string;
|
|
70
|
+
/** Raw base64url string of the request parameter */
|
|
71
|
+
requestRaw: string;
|
|
72
|
+
/**
|
|
73
|
+
* Decoded request payload. Typed as `unknown` first; best-effort
|
|
74
|
+
* `Record<string, unknown>` when JSON parsing succeeds and result is object-shaped.
|
|
75
|
+
* Preserves raw base64url + decoded string alongside.
|
|
76
|
+
*/
|
|
77
|
+
decodedRequest: unknown;
|
|
78
|
+
expires?: string;
|
|
79
|
+
digest?: string;
|
|
80
|
+
description?: string;
|
|
81
|
+
opaque?: string;
|
|
82
|
+
/** Back-reference to the raw form */
|
|
83
|
+
_raw: RawPaymentauthChallenge;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Normalized paymentauth credential.
|
|
87
|
+
*
|
|
88
|
+
* Stable projection of the credential envelope.
|
|
89
|
+
* Method-specific payload typed as `unknown`.
|
|
90
|
+
*/
|
|
91
|
+
export interface NormalizedPaymentauthCredential {
|
|
92
|
+
challengeId: string;
|
|
93
|
+
method: string;
|
|
94
|
+
intent: string;
|
|
95
|
+
/** Payer identifier (DID format recommended per spec) */
|
|
96
|
+
source?: string;
|
|
97
|
+
/** Method-specific payment proof (typed as `unknown`) */
|
|
98
|
+
payload: unknown;
|
|
99
|
+
/** Back-reference to the raw form */
|
|
100
|
+
_raw: RawPaymentauthCredential;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Normalized paymentauth receipt.
|
|
104
|
+
*
|
|
105
|
+
* Stable projection of the receipt envelope.
|
|
106
|
+
* Method-specific fields typed as `unknown` via extras.
|
|
107
|
+
*/
|
|
108
|
+
export interface NormalizedPaymentauthReceipt {
|
|
109
|
+
status: string;
|
|
110
|
+
method: string;
|
|
111
|
+
timestamp?: string;
|
|
112
|
+
reference?: string;
|
|
113
|
+
/** Any additional fields from the receipt (method-specific) */
|
|
114
|
+
extras: Record<string, unknown>;
|
|
115
|
+
/** Back-reference to the raw form */
|
|
116
|
+
_raw: RawPaymentauthReceipt;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Parsed x-service-info from OpenAPI document.
|
|
120
|
+
*/
|
|
121
|
+
export interface PaymentauthServiceInfo {
|
|
122
|
+
categories?: string[];
|
|
123
|
+
docs?: {
|
|
124
|
+
apiReference?: string;
|
|
125
|
+
homepage?: string;
|
|
126
|
+
llms?: string;
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Parsed x-payment-info from OpenAPI operation.
|
|
131
|
+
*/
|
|
132
|
+
export interface PaymentauthPaymentInfo {
|
|
133
|
+
intent?: string;
|
|
134
|
+
method?: string;
|
|
135
|
+
amount?: string | null;
|
|
136
|
+
currency?: string;
|
|
137
|
+
description?: string;
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAMH;;;;;GAKG;AACH,MAAM,WAAW,uBAAuB;IACtC,mEAAmE;IACnE,SAAS,EAAE,MAAM,CAAC;IAClB,sFAAsF;IACtF,UAAU,EAAE,MAAM,CAAC;IACnB,wCAAwC;IACxC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAChC;AAED;;;;;GAKG;AACH,MAAM,WAAW,wBAAwB;IACvC,oEAAoE;IACpE,QAAQ,EAAE,MAAM,CAAC;IACjB,mEAAmE;IACnE,YAAY,EAAE,UAAU,CAAC;IACzB,iEAAiE;IACjE,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,gFAAgF;IAChF,UAAU,EAAE,OAAO,CAAC;CACrB;AAED;;;;GAIG;AACH,MAAM,WAAW,qBAAqB;IACpC,8CAA8C;IAC9C,QAAQ,EAAE,MAAM,CAAC;IACjB,kCAAkC;IAClC,YAAY,EAAE,UAAU,CAAC;IACzB,iEAAiE;IACjE,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,2DAA2D;IAC3D,UAAU,EAAE,OAAO,CAAC;CACrB;AA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AAC;KACf,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Paymentauth wire types: raw + normalized.
|
|
4
|
+
*
|
|
5
|
+
* Envelope-first design: the stable surface is the common envelope
|
|
6
|
+
* (id, realm, method, intent, request, expires, digest, opaque).
|
|
7
|
+
* Method-specific payloads (request content, credential payload,
|
|
8
|
+
* receipt details) are typed as `unknown` because each payment method
|
|
9
|
+
* (card, lightning, stripe, tempo) has its own draft spec.
|
|
10
|
+
*
|
|
11
|
+
* Raw types preserve the original wire form exactly.
|
|
12
|
+
* Normalized types project a stable PEAC-facing structure.
|
|
13
|
+
* Every normalized type retains a `_raw` field for traceability.
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG"}
|