@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/types.js
CHANGED
|
@@ -2,24 +2,14 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* x402 Offer/Receipt extension types
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* - acceptIndex: Unsigned envelope field (hint only, not binding)
|
|
10
|
-
*
|
|
11
|
-
* Key design choices:
|
|
12
|
-
* - validUntil: epoch seconds in signed payload
|
|
13
|
-
* - version: in signed payload
|
|
14
|
-
* - acceptIndex: unsigned envelope field (outside signature)
|
|
15
|
-
* - metadata: deferred to v2
|
|
16
|
-
*
|
|
17
|
-
* NOTE: This adapter targets the x402 Offer/Receipt EXTENSION,
|
|
18
|
-
* NOT the baseline x402 header flow. The profile identifier reflects this:
|
|
19
|
-
* `peac-x402-offer-receipt/0.1` (extension) vs `peac-x402/0.1` (baseline, reserved).
|
|
5
|
+
* Public API types for the x402 adapter. Uses raw wire types (Layer A)
|
|
6
|
+
* and normalized types (Layer B) from their respective modules.
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
20
9
|
*/
|
|
21
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
11
|
exports.MAX_AMOUNT_LENGTH = exports.MAX_TOTAL_ACCEPTS_BYTES = exports.MAX_ACCEPT_ENTRIES = exports.X402_OFFER_RECEIPT_PROFILE = void 0;
|
|
12
|
+
exports.defaultAddressComparator = defaultAddressComparator;
|
|
23
13
|
// ---------------------------------------------------------------------------
|
|
24
14
|
// Profile Identifier
|
|
25
15
|
// ---------------------------------------------------------------------------
|
|
@@ -31,7 +21,7 @@ exports.MAX_AMOUNT_LENGTH = exports.MAX_TOTAL_ACCEPTS_BYTES = exports.MAX_ACCEPT
|
|
|
31
21
|
*
|
|
32
22
|
* `peac-x402/0.1` is RESERVED for future baseline header flow support.
|
|
33
23
|
*/
|
|
34
|
-
exports.X402_OFFER_RECEIPT_PROFILE = 'peac-x402-offer-receipt/0.
|
|
24
|
+
exports.X402_OFFER_RECEIPT_PROFILE = 'peac-x402-offer-receipt/0.2';
|
|
35
25
|
// ---------------------------------------------------------------------------
|
|
36
26
|
// DoS Protection Limits
|
|
37
27
|
// ---------------------------------------------------------------------------
|
|
@@ -55,4 +45,16 @@ exports.MAX_TOTAL_ACCEPTS_BYTES = 256 * 1024; // 256 KiB
|
|
|
55
45
|
* 78 chars supports uint256 (Ethereum's max) without truncation.
|
|
56
46
|
*/
|
|
57
47
|
exports.MAX_AMOUNT_LENGTH = 78;
|
|
48
|
+
/**
|
|
49
|
+
* Default network-aware address comparator
|
|
50
|
+
*
|
|
51
|
+
* EVM networks (eip155:*): case-insensitive (EIP-55 checksums are cosmetic encoding).
|
|
52
|
+
* All other networks: exact string comparison (fail-closed for unknown formats).
|
|
53
|
+
*/
|
|
54
|
+
function defaultAddressComparator(a, b, network) {
|
|
55
|
+
if (network.startsWith('eip155:')) {
|
|
56
|
+
return a.toLowerCase() === b.toLowerCase();
|
|
57
|
+
}
|
|
58
|
+
return a === b;
|
|
59
|
+
}
|
|
58
60
|
//# sourceMappingURL=types.js.map
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AA4bH,4DAKC;AA3aD,8EAA8E;AAC9E,qBAAqB;AACrB,8EAA8E;AAE9E;;;;;;;GAOG;AACU,QAAA,0BAA0B,GAAG,6BAAsC,CAAC;AAEjF,8EAA8E;AAC9E,wBAAwB;AACxB,8EAA8E;AAE9E;;;;;GAKG;AACU,QAAA,kBAAkB,GAAG,GAAG,CAAC;AAEtC;;;;;GAKG;AACU,QAAA,uBAAuB,GAAG,GAAG,GAAG,IAAI,CAAC,CAAC,UAAU;AAE7D;;;;GAIG;AACU,QAAA,iBAAiB,GAAG,EAAE,CAAC;AAyXpC;;;;;GAKG;AACH,SAAgB,wBAAwB,CAAC,CAAS,EAAE,CAAS,EAAE,OAAe;IAC5E,IAAI,OAAO,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;QAClC,OAAO,CAAC,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC;IAC7C,CAAC;IACD,OAAO,CAAC,KAAK,CAAC,CAAC;AACjB,CAAC"}
|
package/dist/verify.d.ts
CHANGED
|
@@ -1,63 +1,77 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* x402 Offer/Receipt verification
|
|
3
3
|
*
|
|
4
|
-
* Verification
|
|
5
|
-
* 1.
|
|
6
|
-
* 2.
|
|
7
|
-
* 3.
|
|
8
|
-
* 4.
|
|
9
|
-
* 5.
|
|
10
|
-
* 6. Version check (supported versions)
|
|
11
|
-
* 7. Signature format validation (EIP-712 or JWS structure)
|
|
12
|
-
* 8. Term-matching (offer payload vs accept entry)
|
|
4
|
+
* Verification layers:
|
|
5
|
+
* 1. Wire validation (verifyWire): structural shape, format tags, required fields
|
|
6
|
+
* 2. Offer term verification (verifyOfferTerms): version, expiry, amount, network, term-matching
|
|
7
|
+
* 3. Receipt semantic verification (verifyReceiptSemantics): required fields, recency
|
|
8
|
+
* 4. Offer-receipt consistency (verifyOfferReceiptConsistency): resourceUrl, network, freshness
|
|
9
|
+
* 5. Opt-in crypto + authorization: CryptoVerifier and SignerAuthorizer interfaces (types only)
|
|
13
10
|
*
|
|
14
|
-
*
|
|
15
|
-
* is NOT performed here. That requires a crypto provider (viem, ethers, etc.)
|
|
16
|
-
* and should be done by the caller before passing artifacts to this adapter.
|
|
11
|
+
* Each layer is separately callable and separately reportable.
|
|
17
12
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
13
|
+
* IMPORTANT: Cryptographic signature verification is NOT performed here.
|
|
14
|
+
* That requires injecting a CryptoVerifier implementation.
|
|
15
|
+
*/
|
|
16
|
+
import type { RawSignedOffer, RawSignedReceipt } from './raw.js';
|
|
17
|
+
import type { NormalizedOfferPayload, NormalizedReceiptPayload } from './normalize.js';
|
|
18
|
+
import type { AcceptEntry, OfferVerification, ReceiptVerification, ConsistencyVerification, ConsistencyOptions, WireVerification, X402AdapterConfig, AddressComparator } from './types.js';
|
|
19
|
+
/**
|
|
20
|
+
* Validate raw wire structure of a signed offer
|
|
20
21
|
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* that makes unsigned acceptIndex irrelevant for security.
|
|
22
|
+
* Checks discriminated union shape, format tag, required fields.
|
|
23
|
+
* No semantic interpretation, no payload extraction.
|
|
24
24
|
*/
|
|
25
|
-
|
|
25
|
+
export declare function verifyOfferWire(offer: RawSignedOffer): WireVerification;
|
|
26
|
+
/**
|
|
27
|
+
* Validate raw wire structure of a signed receipt
|
|
28
|
+
*/
|
|
29
|
+
export declare function verifyReceiptWire(receipt: RawSignedReceipt): WireVerification;
|
|
26
30
|
/**
|
|
27
31
|
* Verify an x402 signed offer against accept terms
|
|
28
32
|
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
33
|
+
* Extracts and normalizes payload, then performs:
|
|
34
|
+
* - Version check
|
|
35
|
+
* - Expiry check (with offerExpiryPolicy)
|
|
36
|
+
* - Amount/network validation
|
|
37
|
+
* - Term-matching against accept entries
|
|
32
38
|
*
|
|
33
39
|
* @param offer - The signed offer to verify
|
|
34
40
|
* @param accepts - The list of acceptable payment terms
|
|
35
|
-
* @param acceptIndex - Optional hint index (unsigned, treat as advisory)
|
|
36
41
|
* @param config - Optional adapter configuration
|
|
37
42
|
* @returns Verification result with matched accept entry or errors
|
|
38
43
|
*/
|
|
39
|
-
export declare function verifyOffer(offer:
|
|
44
|
+
export declare function verifyOffer(offer: RawSignedOffer, accepts: AcceptEntry[], config?: X402AdapterConfig): OfferVerification;
|
|
40
45
|
/**
|
|
41
46
|
* Verify an x402 signed receipt
|
|
42
47
|
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
48
|
+
* Extracts and normalizes payload, then performs:
|
|
49
|
+
* - Required field validation (version, network, resourceUrl, payer, issuedAt)
|
|
50
|
+
* - Version check
|
|
51
|
+
* - Payer format check
|
|
52
|
+
* - issuedAt recency check
|
|
53
|
+
* - Network validation
|
|
49
54
|
*/
|
|
50
|
-
export declare function verifyReceipt(receipt:
|
|
55
|
+
export declare function verifyReceipt(receipt: RawSignedReceipt, config?: X402AdapterConfig): ReceiptVerification;
|
|
51
56
|
/**
|
|
52
|
-
*
|
|
57
|
+
* Verify consistency between an offer and a receipt
|
|
53
58
|
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
59
|
+
* Checks:
|
|
60
|
+
* - resourceUrl must match (exact string comparison)
|
|
61
|
+
* - network must match
|
|
62
|
+
* - issuedAt freshness relative to offer validity window
|
|
63
|
+
* - payer must match one of payerCandidates (if provided, network-aware)
|
|
64
|
+
*/
|
|
65
|
+
export declare function verifyOfferReceiptConsistency(offerPayload: NormalizedOfferPayload, receiptPayload: NormalizedReceiptPayload, config?: X402AdapterConfig, options?: ConsistencyOptions): ConsistencyVerification;
|
|
66
|
+
/**
|
|
67
|
+
* Match normalized offer payload fields against a single accept entry
|
|
57
68
|
*
|
|
69
|
+
* Compares: network, asset, payTo, amount, scheme
|
|
70
|
+
* All fields must match. Amount comparison is string-based.
|
|
71
|
+
* payTo comparison uses the address comparator (network-aware).
|
|
58
72
|
* @returns Array of mismatched field names (empty = match)
|
|
59
73
|
*/
|
|
60
|
-
export declare function matchAcceptTerms(payload:
|
|
74
|
+
export declare function matchAcceptTerms(payload: NormalizedOfferPayload, accept: AcceptEntry, addressComparator?: AddressComparator): string[];
|
|
61
75
|
/**
|
|
62
76
|
* Select the matching accept entry from the list
|
|
63
77
|
*
|
|
@@ -66,13 +80,8 @@ export declare function matchAcceptTerms(payload: OfferPayload, accept: AcceptEn
|
|
|
66
80
|
* - If absent: scan all entries for a unique match
|
|
67
81
|
* - If multiple matches: fail closed (ambiguous)
|
|
68
82
|
* - If no matches: fail closed
|
|
69
|
-
*
|
|
70
|
-
* @param payload - Offer payload to match
|
|
71
|
-
* @param accepts - List of accept entries
|
|
72
|
-
* @param acceptIndex - Optional hint (unsigned, untrusted)
|
|
73
|
-
* @returns The matched entry and its index, or throws X402Error
|
|
74
83
|
*/
|
|
75
|
-
export declare function selectAccept(payload:
|
|
84
|
+
export declare function selectAccept(payload: NormalizedOfferPayload, accepts: AcceptEntry[], acceptIndex?: number, addressComparator?: AddressComparator): {
|
|
76
85
|
entry: AcceptEntry;
|
|
77
86
|
index: number;
|
|
78
87
|
usedHint: boolean;
|
package/dist/verify.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verify.d.ts","sourceRoot":"","sources":["../src/verify.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"verify.d.ts","sourceRoot":"","sources":["../src/verify.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,KAAK,EACV,cAAc,EAEd,gBAAgB,EAIjB,MAAM,UAAU,CAAC;AAElB,OAAO,KAAK,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAEvF,OAAO,KAAK,EACV,WAAW,EACX,iBAAiB,EACjB,mBAAmB,EACnB,uBAAuB,EACvB,kBAAkB,EAClB,gBAAgB,EAEhB,iBAAiB,EAEjB,iBAAiB,EAClB,MAAM,YAAY,CAAC;AAsMpB;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,cAAc,GAAG,gBAAgB,CAgEvE;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,gBAAgB,GAAG,gBAAgB,CA8C7E;AAMD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,cAAc,EACrB,OAAO,EAAE,WAAW,EAAE,EACtB,MAAM,CAAC,EAAE,iBAAiB,GACzB,iBAAiB,CA8KnB;AAMD;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,gBAAgB,EACzB,MAAM,CAAC,EAAE,iBAAiB,GACzB,mBAAmB,CAsFrB;AAMD;;;;;;;;GAQG;AACH,wBAAgB,6BAA6B,CAC3C,YAAY,EAAE,sBAAsB,EACpC,cAAc,EAAE,wBAAwB,EACxC,MAAM,CAAC,EAAE,iBAAiB,EAC1B,OAAO,CAAC,EAAE,kBAAkB,GAC3B,uBAAuB,CAqDzB;AAMD;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,sBAAsB,EAC/B,MAAM,EAAE,WAAW,EACnB,iBAAiB,GAAE,iBAA4C,GAC9D,MAAM,EAAE,CAsBV;AAMD;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAC1B,OAAO,EAAE,sBAAsB,EAC/B,OAAO,EAAE,WAAW,EAAE,EACtB,WAAW,CAAC,EAAE,MAAM,EACpB,iBAAiB,GAAE,iBAA4C,GAC9D;IAAE,KAAK,EAAE,WAAW,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,CAyD1D"}
|