@peac/adapter-x402 0.12.0 → 0.12.2
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 +46 -19
- package/dist/carrier.d.ts +4 -4
- package/dist/carrier.d.ts.map +1 -1
- package/dist/carrier.js +7 -7
- package/dist/carrier.js.map +1 -1
- package/dist/errors.d.ts +1 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +10 -0
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +14 -23
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +25 -22
- package/dist/index.js.map +1 -1
- package/dist/map.d.ts +29 -23
- package/dist/map.d.ts.map +1 -1
- package/dist/map.js +58 -37
- package/dist/map.js.map +1 -1
- package/dist/normalize.d.ts +97 -0
- package/dist/normalize.d.ts.map +1 -0
- package/dist/normalize.js +75 -0
- package/dist/normalize.js.map +1 -0
- package/dist/raw.d.ts +246 -0
- package/dist/raw.d.ts.map +1 -0
- package/dist/raw.js +246 -0
- package/dist/raw.js.map +1 -0
- package/dist/types.d.ts +292 -144
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +18 -16
- package/dist/types.js.map +1 -1
- package/dist/verify.d.ts +50 -41
- package/dist/verify.d.ts.map +1 -1
- package/dist/verify.js +380 -344
- package/dist/verify.js.map +1 -1
- package/package.json +5 -4
package/dist/map.js
CHANGED
|
@@ -1,24 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* x402 to PEAC record mapping
|
|
3
|
+
* x402 to PEAC record mapping (Layer C)
|
|
4
4
|
*
|
|
5
|
-
* Maps x402
|
|
5
|
+
* Maps x402 offer/receipt extension data into a canonical
|
|
6
6
|
* PEAC interaction record (X402PeacRecord).
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* The record preserves:
|
|
12
|
-
* - Raw proofs (offer + receipt) for audit/dispute
|
|
13
|
-
* - Normalized evidence fields from signed payloads
|
|
14
|
-
* - Unsigned hints (acceptIndex) explicitly marked as untrusted
|
|
15
|
-
* - Verification status metadata (structural, cryptographic, termMatching)
|
|
8
|
+
* Uses normalized payloads (Layer B output) for evidence fields.
|
|
9
|
+
* Raw upstream artifacts are preserved as-is in proofs.
|
|
16
10
|
*/
|
|
17
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
12
|
exports.toPeacRecord = toPeacRecord;
|
|
19
13
|
exports.toPeacCarrier = toPeacCarrier;
|
|
20
14
|
const schema_1 = require("@peac/schema");
|
|
21
15
|
const errors_js_1 = require("./errors.js");
|
|
16
|
+
const raw_js_1 = require("./raw.js");
|
|
17
|
+
const normalize_js_1 = require("./normalize.js");
|
|
22
18
|
const types_js_1 = require("./types.js");
|
|
23
19
|
/**
|
|
24
20
|
* Map x402 payment flow to a PEAC interaction record
|
|
@@ -26,35 +22,46 @@ const types_js_1 = require("./types.js");
|
|
|
26
22
|
* Takes a PaymentRequired (offer side) and SettlementResponse (receipt side)
|
|
27
23
|
* and produces a canonical PEAC record with normalized evidence.
|
|
28
24
|
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* See `hints.verification.cryptographic` in the output.
|
|
25
|
+
* Uses Layer B (normalized) payloads for evidence; stores exact raw
|
|
26
|
+
* artifacts in proofs (proof preservation discipline).
|
|
32
27
|
*
|
|
33
|
-
* @param paymentRequired - The 402 response with
|
|
28
|
+
* @param paymentRequired - The 402 response with offers and accepts
|
|
34
29
|
* @param settlementResponse - The settlement response with receipt
|
|
35
30
|
* @param options - Optional mapping options
|
|
36
31
|
* @returns Canonical PEAC interaction record
|
|
37
32
|
* @throws X402Error if inputs are structurally invalid
|
|
38
33
|
*/
|
|
39
34
|
function toPeacRecord(paymentRequired, settlementResponse, options) {
|
|
40
|
-
const
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
35
|
+
const offerIndex = options?.offerIndex ?? 0;
|
|
36
|
+
const maxJwsBytes = options?.maxCompactJwsBytes;
|
|
37
|
+
// Validate offers array
|
|
38
|
+
if (!paymentRequired.offers ||
|
|
39
|
+
!Array.isArray(paymentRequired.offers) ||
|
|
40
|
+
paymentRequired.offers.length === 0) {
|
|
41
|
+
throw new errors_js_1.X402Error('offer_invalid_format', 'PaymentRequired must contain a non-empty offers array');
|
|
42
|
+
}
|
|
43
|
+
if (offerIndex < 0 || offerIndex >= paymentRequired.offers.length) {
|
|
44
|
+
throw new errors_js_1.X402Error('offer_invalid_format', `offerIndex ${offerIndex} is out of range [0, ${paymentRequired.offers.length - 1}]`);
|
|
44
45
|
}
|
|
45
|
-
|
|
46
|
-
|
|
46
|
+
const offer = paymentRequired.offers[offerIndex];
|
|
47
|
+
const receipt = settlementResponse.receipt;
|
|
48
|
+
if (!receipt) {
|
|
49
|
+
throw new errors_js_1.X402Error('receipt_invalid_format', 'SettlementResponse must contain a valid receipt');
|
|
47
50
|
}
|
|
48
|
-
|
|
49
|
-
const
|
|
51
|
+
// Extract and normalize payloads (Layer A -> Layer B)
|
|
52
|
+
const rawOfferPayload = (0, raw_js_1.extractOfferPayload)(offer, maxJwsBytes);
|
|
53
|
+
const rawReceiptPayload = (0, raw_js_1.extractReceiptPayload)(receipt, maxJwsBytes);
|
|
54
|
+
const offerPayload = (0, normalize_js_1.normalizeOfferPayload)(rawOfferPayload);
|
|
55
|
+
const receiptPayload = (0, normalize_js_1.normalizeReceiptPayload)(rawReceiptPayload);
|
|
50
56
|
// Build hints (unsigned metadata, explicitly untrusted)
|
|
51
57
|
const hints = {};
|
|
52
|
-
// Derive mismatchDetected from termMatching
|
|
58
|
+
// Derive mismatchDetected from termMatching
|
|
53
59
|
const termMatching = options?.offerVerification?.termMatching;
|
|
54
60
|
const mismatchDetected = termMatching?.hintMismatchDetected ?? false;
|
|
55
|
-
|
|
61
|
+
// acceptIndex is now per-offer
|
|
62
|
+
if (offer.acceptIndex !== undefined) {
|
|
56
63
|
hints.acceptIndex = {
|
|
57
|
-
value:
|
|
64
|
+
value: offer.acceptIndex,
|
|
58
65
|
untrusted: true,
|
|
59
66
|
...(mismatchDetected && { mismatchDetected: true }),
|
|
60
67
|
};
|
|
@@ -64,59 +71,73 @@ function toPeacRecord(paymentRequired, settlementResponse, options) {
|
|
|
64
71
|
hints.resourceUrl = resourceUrl;
|
|
65
72
|
}
|
|
66
73
|
// Build verification status
|
|
67
|
-
// IMPORTANT: If offerVerification is not provided, we cannot assume terms matched.
|
|
68
|
-
// Callers SHOULD provide offerVerification for a complete record.
|
|
69
74
|
const offerVerification = options?.offerVerification;
|
|
70
75
|
const termMatchingVerified = offerVerification !== undefined;
|
|
76
|
+
const cryptoResult = options?.cryptoResult;
|
|
77
|
+
const authResult = options?.authorizationResult;
|
|
71
78
|
const verification = {
|
|
72
79
|
structural: true,
|
|
73
80
|
cryptographic: {
|
|
74
81
|
verified: options?.cryptoVerified ?? false,
|
|
75
82
|
...(!(options?.cryptoVerified ?? false) && { reason: 'not_checked' }),
|
|
76
83
|
format: offer.format,
|
|
77
|
-
...(
|
|
84
|
+
...(cryptoResult?.signer && { signer: cryptoResult.signer }),
|
|
78
85
|
},
|
|
79
86
|
termMatching: {
|
|
80
|
-
// Safe-by-default: if verification wasn't performed, indicate that clearly
|
|
81
87
|
matched: termMatchingVerified ? offerVerification.valid : false,
|
|
82
88
|
method: offerVerification?.usedHint ? 'hint' : 'scan',
|
|
83
89
|
...(offerVerification?.matchedIndex !== undefined && {
|
|
84
90
|
matchedIndex: offerVerification.matchedIndex,
|
|
85
91
|
}),
|
|
86
|
-
// Add flag to indicate if term-matching was actually performed
|
|
87
92
|
...(!termMatchingVerified && { reason: 'not_verified' }),
|
|
88
93
|
},
|
|
94
|
+
...(options?.consistencyVerification && {
|
|
95
|
+
consistency: {
|
|
96
|
+
checked: true,
|
|
97
|
+
valid: options.consistencyVerification.valid,
|
|
98
|
+
},
|
|
99
|
+
}),
|
|
100
|
+
...(authResult && {
|
|
101
|
+
signerAuthorization: {
|
|
102
|
+
checked: true,
|
|
103
|
+
authorized: authResult.authorized,
|
|
104
|
+
...(authResult.method && { method: authResult.method }),
|
|
105
|
+
},
|
|
106
|
+
}),
|
|
89
107
|
};
|
|
90
108
|
hints.verification = verification;
|
|
91
109
|
return {
|
|
92
110
|
version: types_js_1.X402_OFFER_RECEIPT_PROFILE,
|
|
93
111
|
proofs: {
|
|
94
112
|
x402: {
|
|
95
|
-
offer,
|
|
96
|
-
receipt,
|
|
113
|
+
offer, // exact raw artifact, never mutated
|
|
114
|
+
receipt, // exact raw artifact, never mutated
|
|
97
115
|
},
|
|
98
116
|
},
|
|
99
117
|
evidence: {
|
|
100
|
-
|
|
118
|
+
resourceUrl: offerPayload.resourceUrl,
|
|
119
|
+
...(offerPayload.validUntil !== undefined && { validUntil: offerPayload.validUntil }),
|
|
101
120
|
network: offerPayload.network,
|
|
102
121
|
payee: offerPayload.payTo,
|
|
103
122
|
asset: offerPayload.asset,
|
|
104
123
|
amount: offerPayload.amount,
|
|
105
|
-
txHash: receiptPayload.txHash,
|
|
106
124
|
offerVersion: offerPayload.version,
|
|
107
|
-
...(receiptPayload.
|
|
125
|
+
...(receiptPayload.payer && { payer: receiptPayload.payer }),
|
|
126
|
+
...(receiptPayload.issuedAt && { issuedAt: receiptPayload.issuedAt }),
|
|
127
|
+
...(receiptPayload.transaction && { transaction: receiptPayload.transaction }),
|
|
128
|
+
...(receiptPayload.version !== undefined && { receiptVersion: receiptPayload.version }),
|
|
108
129
|
},
|
|
109
130
|
hints,
|
|
110
131
|
createdAt: new Date().toISOString(),
|
|
111
132
|
};
|
|
112
133
|
}
|
|
113
134
|
// ---------------------------------------------------------------------------
|
|
114
|
-
// Evidence Carrier mapping
|
|
135
|
+
// Evidence Carrier mapping
|
|
115
136
|
// ---------------------------------------------------------------------------
|
|
116
137
|
/**
|
|
117
138
|
* Convert an x402 PEAC record to a PeacEvidenceCarrier.
|
|
118
139
|
*
|
|
119
|
-
* Uses the shared `computeReceiptRef()` from `@peac/schema`
|
|
140
|
+
* Uses the shared `computeReceiptRef()` from `@peac/schema`
|
|
120
141
|
* to produce a canonical, content-addressed receipt_ref from the JWS.
|
|
121
142
|
*
|
|
122
143
|
* @param receiptJws - Compact JWS of the PEAC receipt
|
package/dist/map.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map.js","sourceRoot":"","sources":["../src/map.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"map.js","sourceRoot":"","sources":["../src/map.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;AAwEH,oCA+HC;AAeD,sCAMC;AAzND,yCAAiD;AAEjD,2CAAwC;AAExC,qCAAsE;AACtE,iDAAgF;AAWhF,yCAAwD;AAsCxD;;;;;;;;;;;;;;GAcG;AACH,SAAgB,YAAY,CAC1B,eAA0C,EAC1C,kBAA0C,EAC1C,OAA6B;IAE7B,MAAM,UAAU,GAAG,OAAO,EAAE,UAAU,IAAI,CAAC,CAAC;IAC5C,MAAM,WAAW,GAAG,OAAO,EAAE,kBAAkB,CAAC;IAEhD,wBAAwB;IACxB,IACE,CAAC,eAAe,CAAC,MAAM;QACvB,CAAC,KAAK,CAAC,OAAO,CAAC,eAAe,CAAC,MAAM,CAAC;QACtC,eAAe,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,EACnC,CAAC;QACD,MAAM,IAAI,qBAAS,CACjB,sBAAsB,EACtB,uDAAuD,CACxD,CAAC;IACJ,CAAC;IAED,IAAI,UAAU,GAAG,CAAC,IAAI,UAAU,IAAI,eAAe,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;QAClE,MAAM,IAAI,qBAAS,CACjB,sBAAsB,EACtB,cAAc,UAAU,wBAAwB,eAAe,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,GAAG,CACrF,CAAC;IACJ,CAAC;IAED,MAAM,KAAK,GAAmB,eAAe,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IACjE,MAAM,OAAO,GAAqB,kBA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 semantic normalization (Layer B)
|
|
3
|
+
*
|
|
4
|
+
* Converts EIP-712 placeholder values into semantic absence.
|
|
5
|
+
* This layer exists because EIP-712 requires fixed schemas, so unused
|
|
6
|
+
* values are represented as `0` (for numbers) and `""` (for strings).
|
|
7
|
+
*
|
|
8
|
+
* Normalization rules:
|
|
9
|
+
* - `validUntil === 0` -> `undefined` (EIP-712 "no expiry" placeholder)
|
|
10
|
+
* - `transaction === ""` -> `undefined` (EIP-712 "no transaction" placeholder)
|
|
11
|
+
* - All other fields pass through unchanged
|
|
12
|
+
*
|
|
13
|
+
* IMPORTANT: Raw artifacts are NEVER mutated. Normalization produces
|
|
14
|
+
* new objects; the originals are preserved in proofs.
|
|
15
|
+
*/
|
|
16
|
+
import type { RawOfferPayload, RawReceiptPayload } from './raw.js';
|
|
17
|
+
/**
|
|
18
|
+
* Normalized offer payload (semantically clean)
|
|
19
|
+
*
|
|
20
|
+
* Same fields as RawOfferPayload, but with EIP-712 placeholders
|
|
21
|
+
* converted to semantic absence (`undefined`).
|
|
22
|
+
*/
|
|
23
|
+
export interface NormalizedOfferPayload {
|
|
24
|
+
/** Schema version */
|
|
25
|
+
version: number;
|
|
26
|
+
/** Resource URL the offer is for */
|
|
27
|
+
resourceUrl: string;
|
|
28
|
+
/** Settlement scheme */
|
|
29
|
+
scheme: string;
|
|
30
|
+
/** CAIP-2 network identifier */
|
|
31
|
+
network: string;
|
|
32
|
+
/** Payment asset identifier */
|
|
33
|
+
asset: string;
|
|
34
|
+
/** Payment recipient address */
|
|
35
|
+
payTo: string;
|
|
36
|
+
/** Payment amount in minor units */
|
|
37
|
+
amount: string;
|
|
38
|
+
/**
|
|
39
|
+
* Offer expiry as epoch seconds
|
|
40
|
+
*
|
|
41
|
+
* `undefined` means "no expiry" (was `0` in EIP-712 encoding, or absent).
|
|
42
|
+
* Verification layer enforces expiry policy separately.
|
|
43
|
+
*/
|
|
44
|
+
validUntil?: number;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Normalized receipt payload (semantically clean)
|
|
48
|
+
*
|
|
49
|
+
* Same fields as RawReceiptPayload, but with EIP-712 placeholders
|
|
50
|
+
* converted to semantic absence (`undefined`).
|
|
51
|
+
*/
|
|
52
|
+
export interface NormalizedReceiptPayload {
|
|
53
|
+
/** Schema version */
|
|
54
|
+
version: number;
|
|
55
|
+
/** CAIP-2 network identifier */
|
|
56
|
+
network: string;
|
|
57
|
+
/** Resource URL the receipt is for */
|
|
58
|
+
resourceUrl: string;
|
|
59
|
+
/** Payer address */
|
|
60
|
+
payer: string;
|
|
61
|
+
/** Receipt issuance timestamp (epoch seconds) */
|
|
62
|
+
issuedAt: number;
|
|
63
|
+
/**
|
|
64
|
+
* On-chain transaction reference
|
|
65
|
+
*
|
|
66
|
+
* `undefined` means "no transaction reference" (was `""` in EIP-712, or absent).
|
|
67
|
+
* Privacy-minimal: transaction is optional enrichable evidence, not receipt identity.
|
|
68
|
+
*/
|
|
69
|
+
transaction?: string;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Normalize an offer payload from raw wire to semantic representation
|
|
73
|
+
*
|
|
74
|
+
* Applies EIP-712 placeholder rules:
|
|
75
|
+
* - `validUntil === 0` -> `undefined` (no expiry)
|
|
76
|
+
*
|
|
77
|
+
* `validUntil` is always present in the raw payload (required per upstream TS).
|
|
78
|
+
* All other fields pass through unchanged.
|
|
79
|
+
*
|
|
80
|
+
* @param raw - The raw offer payload (Layer A2)
|
|
81
|
+
* @returns Normalized offer payload (Layer B)
|
|
82
|
+
*/
|
|
83
|
+
export declare function normalizeOfferPayload(raw: RawOfferPayload): NormalizedOfferPayload;
|
|
84
|
+
/**
|
|
85
|
+
* Normalize a receipt payload from raw wire to semantic representation
|
|
86
|
+
*
|
|
87
|
+
* Applies EIP-712 placeholder rules:
|
|
88
|
+
* - `transaction === ""` -> `undefined` (no transaction)
|
|
89
|
+
*
|
|
90
|
+
* `transaction` is always present in the raw payload (required per upstream TS).
|
|
91
|
+
* All other fields pass through unchanged.
|
|
92
|
+
*
|
|
93
|
+
* @param raw - The raw receipt payload (Layer A2)
|
|
94
|
+
* @returns Normalized receipt payload (Layer B)
|
|
95
|
+
*/
|
|
96
|
+
export declare function normalizeReceiptPayload(raw: RawReceiptPayload): NormalizedReceiptPayload;
|
|
97
|
+
//# sourceMappingURL=normalize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../src/normalize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAMnE;;;;;GAKG;AACH,MAAM,WAAW,sBAAsB;IACrC,qBAAqB;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,oCAAoC;IACpC,WAAW,EAAE,MAAM,CAAC;IACpB,wBAAwB;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,gCAAgC;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,+BAA+B;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,gCAAgC;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,oCAAoC;IACpC,MAAM,EAAE,MAAM,CAAC;IACf;;;;;OAKG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;GAKG;AACH,MAAM,WAAW,wBAAwB;IACvC,qBAAqB;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,gCAAgC;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,sCAAsC;IACtC,WAAW,EAAE,MAAM,CAAC;IACpB,oBAAoB;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,iDAAiD;IACjD,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;;OAKG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAMD;;;;;;;;;;;GAWG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,eAAe,GAAG,sBAAsB,CAclF;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,iBAAiB,GAAG,wBAAwB,CAYxF"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* x402 semantic normalization (Layer B)
|
|
4
|
+
*
|
|
5
|
+
* Converts EIP-712 placeholder values into semantic absence.
|
|
6
|
+
* This layer exists because EIP-712 requires fixed schemas, so unused
|
|
7
|
+
* values are represented as `0` (for numbers) and `""` (for strings).
|
|
8
|
+
*
|
|
9
|
+
* Normalization rules:
|
|
10
|
+
* - `validUntil === 0` -> `undefined` (EIP-712 "no expiry" placeholder)
|
|
11
|
+
* - `transaction === ""` -> `undefined` (EIP-712 "no transaction" placeholder)
|
|
12
|
+
* - All other fields pass through unchanged
|
|
13
|
+
*
|
|
14
|
+
* IMPORTANT: Raw artifacts are NEVER mutated. Normalization produces
|
|
15
|
+
* new objects; the originals are preserved in proofs.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.normalizeOfferPayload = normalizeOfferPayload;
|
|
19
|
+
exports.normalizeReceiptPayload = normalizeReceiptPayload;
|
|
20
|
+
// ---------------------------------------------------------------------------
|
|
21
|
+
// Normalization Functions
|
|
22
|
+
// ---------------------------------------------------------------------------
|
|
23
|
+
/**
|
|
24
|
+
* Normalize an offer payload from raw wire to semantic representation
|
|
25
|
+
*
|
|
26
|
+
* Applies EIP-712 placeholder rules:
|
|
27
|
+
* - `validUntil === 0` -> `undefined` (no expiry)
|
|
28
|
+
*
|
|
29
|
+
* `validUntil` is always present in the raw payload (required per upstream TS).
|
|
30
|
+
* All other fields pass through unchanged.
|
|
31
|
+
*
|
|
32
|
+
* @param raw - The raw offer payload (Layer A2)
|
|
33
|
+
* @returns Normalized offer payload (Layer B)
|
|
34
|
+
*/
|
|
35
|
+
function normalizeOfferPayload(raw) {
|
|
36
|
+
return {
|
|
37
|
+
version: raw.version,
|
|
38
|
+
resourceUrl: raw.resourceUrl,
|
|
39
|
+
scheme: raw.scheme,
|
|
40
|
+
network: raw.network,
|
|
41
|
+
asset: raw.asset,
|
|
42
|
+
payTo: raw.payTo,
|
|
43
|
+
amount: raw.amount,
|
|
44
|
+
// EIP-712 placeholder: 0 means "no expiry"
|
|
45
|
+
...(raw.validUntil !== 0 && {
|
|
46
|
+
validUntil: raw.validUntil,
|
|
47
|
+
}),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Normalize a receipt payload from raw wire to semantic representation
|
|
52
|
+
*
|
|
53
|
+
* Applies EIP-712 placeholder rules:
|
|
54
|
+
* - `transaction === ""` -> `undefined` (no transaction)
|
|
55
|
+
*
|
|
56
|
+
* `transaction` is always present in the raw payload (required per upstream TS).
|
|
57
|
+
* All other fields pass through unchanged.
|
|
58
|
+
*
|
|
59
|
+
* @param raw - The raw receipt payload (Layer A2)
|
|
60
|
+
* @returns Normalized receipt payload (Layer B)
|
|
61
|
+
*/
|
|
62
|
+
function normalizeReceiptPayload(raw) {
|
|
63
|
+
return {
|
|
64
|
+
version: raw.version,
|
|
65
|
+
network: raw.network,
|
|
66
|
+
resourceUrl: raw.resourceUrl,
|
|
67
|
+
payer: raw.payer,
|
|
68
|
+
issuedAt: raw.issuedAt,
|
|
69
|
+
// EIP-712 placeholder: "" means "no transaction"
|
|
70
|
+
...(raw.transaction !== '' && {
|
|
71
|
+
transaction: raw.transaction,
|
|
72
|
+
}),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=normalize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize.js","sourceRoot":"","sources":["../src/normalize.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;AAgFH,sDAcC;AAcD,0DAYC;AAxDD,8EAA8E;AAC9E,0BAA0B;AAC1B,8EAA8E;AAE9E;;;;;;;;;;;GAWG;AACH,SAAgB,qBAAqB,CAAC,GAAoB;IACxD,OAAO;QACL,OAAO,EAAE,GAAG,CAAC,OAAO;QACpB,WAAW,EAAE,GAAG,CAAC,WAAW;QAC5B,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,OAAO,EAAE,GAAG,CAAC,OAAO;QACpB,KAAK,EAAE,GAAG,CAAC,KAAK;QAChB,KAAK,EAAE,GAAG,CAAC,KAAK;QAChB,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,2CAA2C;QAC3C,GAAG,CAAC,GAAG,CAAC,UAAU,KAAK,CAAC,IAAI;YAC1B,UAAU,EAAE,GAAG,CAAC,UAAU;SAC3B,CAAC;KACH,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;GAWG;AACH,SAAgB,uBAAuB,CAAC,GAAsB;IAC5D,OAAO;QACL,OAAO,EAAE,GAAG,CAAC,OAAO;QACpB,OAAO,EAAE,GAAG,CAAC,OAAO;QACpB,WAAW,EAAE,GAAG,CAAC,WAAW;QAC5B,KAAK,EAAE,GAAG,CAAC,KAAK;QAChB,QAAQ,EAAE,GAAG,CAAC,QAAQ;QACtB,iDAAiD;QACjD,GAAG,CAAC,GAAG,CAAC,WAAW,KAAK,EAAE,IAAI;YAC5B,WAAW,EAAE,GAAG,CAAC,WAAW;SAC7B,CAAC;KACH,CAAC;AACJ,CAAC"}
|
package/dist/raw.d.ts
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* x402 raw wire types and extraction (Layer A)
|
|
3
|
+
*
|
|
4
|
+
* Exact mirror of upstream coinbase/x402 TypeScript types and field shapes
|
|
5
|
+
* after PR #935 (Offer/Receipt Extension) merged at commit f2bbb5c.
|
|
6
|
+
*
|
|
7
|
+
* This layer exists to:
|
|
8
|
+
* 1. Match upstream encoded wire shapes exactly (no renames, no approximations)
|
|
9
|
+
* 2. Provide extraction helpers for both JWS and EIP-712 formats
|
|
10
|
+
* 3. Serve as the single source of truth for wire-level types
|
|
11
|
+
*
|
|
12
|
+
* Upstream TypeScript keeps `validUntil` and `transaction` as always-present
|
|
13
|
+
* fields because EIP-712 requires fixed schemas. Unused values are encoded as
|
|
14
|
+
* `0` (validUntil) and `""` (transaction). This layer preserves that encoding;
|
|
15
|
+
* semantic normalization to `undefined` happens in Layer B (normalize.ts).
|
|
16
|
+
*
|
|
17
|
+
* IMPORTANT: Types in this file MUST match upstream exactly.
|
|
18
|
+
* Do NOT rename fields, add PEAC-specific fields, or change types.
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* Upstream extension key for offer/receipt extension
|
|
22
|
+
*
|
|
23
|
+
* Matches upstream `OFFER_RECEIPT = "offer-receipt"`.
|
|
24
|
+
* Used in `extensions["offer-receipt"].info`.
|
|
25
|
+
*/
|
|
26
|
+
export declare const OFFER_RECEIPT: "offer-receipt";
|
|
27
|
+
/**
|
|
28
|
+
* Exact upstream x402 offer payload (encoded, Layer A2)
|
|
29
|
+
*
|
|
30
|
+
* Field names and types match coinbase/x402 PR #935 TS interface exactly.
|
|
31
|
+
* All fields are always present in the encoded payload.
|
|
32
|
+
* EIP-712 uses `0` for unused `validUntil` (encoding placeholder, not semantic absence).
|
|
33
|
+
* Conversion to semantic optionality happens exclusively in Layer B (normalize.ts).
|
|
34
|
+
*/
|
|
35
|
+
export interface RawOfferPayload {
|
|
36
|
+
/** Schema version (upstream: number, not string) */
|
|
37
|
+
version: number;
|
|
38
|
+
/** Resource URL the offer is for (required per upstream) */
|
|
39
|
+
resourceUrl: string;
|
|
40
|
+
/** Settlement scheme (required per upstream) */
|
|
41
|
+
scheme: string;
|
|
42
|
+
/** CAIP-2 network identifier (e.g., "eip155:8453") */
|
|
43
|
+
network: string;
|
|
44
|
+
/** Payment asset identifier (e.g., "USDC") */
|
|
45
|
+
asset: string;
|
|
46
|
+
/** Payment recipient address */
|
|
47
|
+
payTo: string;
|
|
48
|
+
/** Payment amount in minor units */
|
|
49
|
+
amount: string;
|
|
50
|
+
/**
|
|
51
|
+
* Offer expiry as epoch seconds
|
|
52
|
+
*
|
|
53
|
+
* Always present in the encoded payload per upstream TS interface.
|
|
54
|
+
* EIP-712 encodes unused values as `0` (fixed schema requirement).
|
|
55
|
+
* Layer B (normalize.ts) converts `0` to `undefined` (semantic absence).
|
|
56
|
+
*/
|
|
57
|
+
validUntil: number;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Exact upstream x402 receipt payload (encoded, Layer A2)
|
|
61
|
+
*
|
|
62
|
+
* Field names and types match coinbase/x402 PR #935 TS interface exactly.
|
|
63
|
+
* All fields are always present in the encoded payload.
|
|
64
|
+
* EIP-712 uses `""` for unused `transaction` (encoding placeholder, not semantic absence).
|
|
65
|
+
* Conversion to semantic optionality happens exclusively in Layer B (normalize.ts).
|
|
66
|
+
*
|
|
67
|
+
* Privacy-minimal by design: receipts carry service-delivery proof, not payment details.
|
|
68
|
+
*/
|
|
69
|
+
export interface RawReceiptPayload {
|
|
70
|
+
/** Schema version (upstream: number) */
|
|
71
|
+
version: number;
|
|
72
|
+
/** CAIP-2 network identifier */
|
|
73
|
+
network: string;
|
|
74
|
+
/** Resource URL the receipt is for */
|
|
75
|
+
resourceUrl: string;
|
|
76
|
+
/** Payer address */
|
|
77
|
+
payer: string;
|
|
78
|
+
/** Receipt issuance timestamp (epoch seconds) */
|
|
79
|
+
issuedAt: number;
|
|
80
|
+
/**
|
|
81
|
+
* On-chain transaction reference
|
|
82
|
+
*
|
|
83
|
+
* Always present in the encoded payload per upstream TS interface.
|
|
84
|
+
* EIP-712 encodes unused values as `""` (fixed schema requirement).
|
|
85
|
+
* Layer B (normalize.ts) converts `""` to `undefined` (semantic absence).
|
|
86
|
+
*/
|
|
87
|
+
transaction: string;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* JWS-signed offer (compact serialization)
|
|
91
|
+
*
|
|
92
|
+
* For JWS format, the payload is encoded inside the compact JWS string.
|
|
93
|
+
* There is no separate `payload` field. The `signature` field contains
|
|
94
|
+
* the full compact JWS (header.payload.signature).
|
|
95
|
+
*/
|
|
96
|
+
export interface RawJWSSignedOffer {
|
|
97
|
+
format: 'jws';
|
|
98
|
+
/** Compact JWS containing the offer payload (header.payload.signature) */
|
|
99
|
+
signature: string;
|
|
100
|
+
/** Index into accepts[] that this offer targets (per-offer, not top-level) */
|
|
101
|
+
acceptIndex?: number;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* EIP-712 signed offer
|
|
105
|
+
*
|
|
106
|
+
* For EIP-712 format, the payload is a separate field alongside
|
|
107
|
+
* the hex-encoded ECDSA signature.
|
|
108
|
+
*/
|
|
109
|
+
export interface RawEIP712SignedOffer {
|
|
110
|
+
format: 'eip712';
|
|
111
|
+
/** The signed offer payload */
|
|
112
|
+
payload: RawOfferPayload;
|
|
113
|
+
/** Hex-encoded ECDSA signature */
|
|
114
|
+
signature: string;
|
|
115
|
+
/** Index into accepts[] that this offer targets (per-offer, not top-level) */
|
|
116
|
+
acceptIndex?: number;
|
|
117
|
+
}
|
|
118
|
+
/** Discriminated union of signed offer formats */
|
|
119
|
+
export type RawSignedOffer = RawJWSSignedOffer | RawEIP712SignedOffer;
|
|
120
|
+
/**
|
|
121
|
+
* JWS-signed receipt (compact serialization)
|
|
122
|
+
*
|
|
123
|
+
* Same pattern as JWS offers: payload is inside the compact JWS string.
|
|
124
|
+
*/
|
|
125
|
+
export interface RawJWSSignedReceipt {
|
|
126
|
+
format: 'jws';
|
|
127
|
+
/** Compact JWS containing the receipt payload */
|
|
128
|
+
signature: string;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* EIP-712 signed receipt
|
|
132
|
+
*/
|
|
133
|
+
export interface RawEIP712SignedReceipt {
|
|
134
|
+
format: 'eip712';
|
|
135
|
+
/** The signed receipt payload */
|
|
136
|
+
payload: RawReceiptPayload;
|
|
137
|
+
/** Hex-encoded ECDSA signature */
|
|
138
|
+
signature: string;
|
|
139
|
+
}
|
|
140
|
+
/** Discriminated union of signed receipt formats */
|
|
141
|
+
export type RawSignedReceipt = RawJWSSignedReceipt | RawEIP712SignedReceipt;
|
|
142
|
+
/**
|
|
143
|
+
* Upstream x402 extension info structure
|
|
144
|
+
*
|
|
145
|
+
* In upstream, the offer/receipt data lives under:
|
|
146
|
+
* `extensions["offer-receipt"].info`
|
|
147
|
+
*/
|
|
148
|
+
export interface RawX402ExtensionInfo {
|
|
149
|
+
/** Array of signed offers */
|
|
150
|
+
offers: RawSignedOffer[];
|
|
151
|
+
/** Optional signed receipt */
|
|
152
|
+
receipt?: RawSignedReceipt;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Default maximum compact JWS byte length (64 KB)
|
|
156
|
+
*
|
|
157
|
+
* Enforced BEFORE base64url decoding to prevent memory amplification.
|
|
158
|
+
*/
|
|
159
|
+
export declare const MAX_COMPACT_JWS_BYTES: number;
|
|
160
|
+
/**
|
|
161
|
+
* Parsed compact JWS components
|
|
162
|
+
*
|
|
163
|
+
* The raw `compact` string is the signed artifact and MUST be preserved as-is.
|
|
164
|
+
* These parsed components are for extraction only; never reconstruct from parts.
|
|
165
|
+
*/
|
|
166
|
+
export interface ParsedCompactJWS {
|
|
167
|
+
/** Decoded JOSE header */
|
|
168
|
+
header: Record<string, unknown>;
|
|
169
|
+
/** Decoded payload (guaranteed to be a plain object) */
|
|
170
|
+
payload: Record<string, unknown>;
|
|
171
|
+
/** Raw signature segment (base64url-encoded) */
|
|
172
|
+
signatureSegment: string;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Parse a compact JWS string with hardened validation
|
|
176
|
+
*
|
|
177
|
+
* Contract:
|
|
178
|
+
* 1. Exactly 3 segments (split on `.`)
|
|
179
|
+
* 2. No padding characters (`=`) in any segment
|
|
180
|
+
* 3. Size limit enforced BEFORE decoding
|
|
181
|
+
* 4. Payload MUST be a plain JSON object (not array, primitive, or null)
|
|
182
|
+
* 5. Never reconstruct: the compact JWS is the signed artifact
|
|
183
|
+
* 6. Fail-closed on any anomaly
|
|
184
|
+
*
|
|
185
|
+
* @param compact - The compact JWS string
|
|
186
|
+
* @param maxBytes - Maximum byte length (default: MAX_COMPACT_JWS_BYTES)
|
|
187
|
+
* @returns Parsed components
|
|
188
|
+
* @throws X402Error with specific error code on any parsing failure
|
|
189
|
+
*/
|
|
190
|
+
export declare function parseCompactJWS(compact: string, maxBytes?: number): ParsedCompactJWS;
|
|
191
|
+
/**
|
|
192
|
+
* Extract offer payload from a signed offer
|
|
193
|
+
*
|
|
194
|
+
* For EIP-712: returns the `payload` field directly.
|
|
195
|
+
* For JWS: decodes the compact JWS and returns the decoded payload.
|
|
196
|
+
*
|
|
197
|
+
* @param offer - The signed offer (discriminated union)
|
|
198
|
+
* @param maxJwsBytes - Maximum JWS byte length for JWS format
|
|
199
|
+
* @returns The raw offer payload
|
|
200
|
+
* @throws X402Error if extraction fails
|
|
201
|
+
*/
|
|
202
|
+
export declare function extractOfferPayload(offer: RawSignedOffer, maxJwsBytes?: number): RawOfferPayload;
|
|
203
|
+
/**
|
|
204
|
+
* Extract receipt payload from a signed receipt
|
|
205
|
+
*
|
|
206
|
+
* For EIP-712: returns the `payload` field directly.
|
|
207
|
+
* For JWS: decodes the compact JWS and returns the decoded payload.
|
|
208
|
+
*
|
|
209
|
+
* @param receipt - The signed receipt (discriminated union)
|
|
210
|
+
* @param maxJwsBytes - Maximum JWS byte length for JWS format
|
|
211
|
+
* @returns The raw receipt payload
|
|
212
|
+
* @throws X402Error if extraction fails
|
|
213
|
+
*/
|
|
214
|
+
export declare function extractReceiptPayload(receipt: RawSignedReceipt, maxJwsBytes?: number): RawReceiptPayload;
|
|
215
|
+
/**
|
|
216
|
+
* Extract x402 extension info from an upstream response body
|
|
217
|
+
*
|
|
218
|
+
* Equivalent to upstream's `extractOffersFromPaymentRequired()` but operates
|
|
219
|
+
* on the raw response body rather than the upstream `PaymentRequired` type.
|
|
220
|
+
* Looks for `extensions["offer-receipt"].info` in the body.
|
|
221
|
+
*
|
|
222
|
+
* This is the entry point for converting raw upstream wire data into
|
|
223
|
+
* PEAC's `X402OfferReceiptChallenge` convenience type.
|
|
224
|
+
*
|
|
225
|
+
* @param body - The upstream response body (unknown shape)
|
|
226
|
+
* @returns The extension info, or null if absent/malformed
|
|
227
|
+
*/
|
|
228
|
+
export declare function extractExtensionInfo(body: unknown): RawX402ExtensionInfo | null;
|
|
229
|
+
/**
|
|
230
|
+
* Standard x402 response header names for payment receipts
|
|
231
|
+
*
|
|
232
|
+
* Upstream uses `X-PAYMENT-RESPONSE` (primary) and `PAYMENT-RESPONSE` (alias).
|
|
233
|
+
*/
|
|
234
|
+
export declare const X402_RECEIPT_HEADERS: readonly ["x-payment-response", "payment-response"];
|
|
235
|
+
/**
|
|
236
|
+
* Extract signed receipt from x402 settlement response headers
|
|
237
|
+
*
|
|
238
|
+
* Equivalent to upstream's `extractReceiptFromResponse()` but operates
|
|
239
|
+
* on raw headers rather than a `Response` object. Upstream sends the
|
|
240
|
+
* signed receipt as JSON in `X-PAYMENT-RESPONSE` or `PAYMENT-RESPONSE`.
|
|
241
|
+
*
|
|
242
|
+
* @param headers - Response headers (case-insensitive lookup)
|
|
243
|
+
* @returns The signed receipt, or null if absent/malformed
|
|
244
|
+
*/
|
|
245
|
+
export declare function extractReceiptFromHeaders(headers: Record<string, string | string[] | undefined>): RawSignedReceipt | null;
|
|
246
|
+
//# sourceMappingURL=raw.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"raw.d.ts","sourceRoot":"","sources":["../src/raw.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAUH;;;;;GAKG;AACH,eAAO,MAAM,aAAa,EAAG,eAAwB,CAAC;AAMtD;;;;;;;GAOG;AACH,MAAM,WAAW,eAAe;IAC9B,oDAAoD;IACpD,OAAO,EAAE,MAAM,CAAC;IAChB,4DAA4D;IAC5D,WAAW,EAAE,MAAM,CAAC;IACpB,gDAAgD;IAChD,MAAM,EA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