@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/dist/types.js CHANGED
@@ -2,24 +2,14 @@
2
2
  /**
3
3
  * x402 Offer/Receipt extension types
4
4
  *
5
- * Models the x402 offer/receipt flow:
6
- * - SignedOffer: EIP-712 or JWS signed payment terms
7
- * - SignedReceipt: Settlement proof binding offer to on-chain transaction
8
- * - AcceptEntry: Terms an offer can match against
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.1';
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;;;;;;;;;;;;;;;;;;GAkBG;;;AAOH,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"}
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 rules (PEAC-first):
5
- * 1. Structural validation (format, required fields)
6
- * 2. DoS guards (accepts array limits)
7
- * 3. Amount validation (non-negative integer string)
8
- * 4. Network validation (CAIP-2 format)
9
- * 5. Expiry check (validUntil vs current time)
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
- * IMPORTANT: Cryptographic signature verification (EIP-712 recovery, JWS validation)
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
- * `valid: true` does NOT imply cryptographic signature validity unless a
19
- * CryptoVerifier is supplied and `verification.cryptographic.verified` is true.
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
- * The focus of this module is TERM-MATCHING: ensuring the signed payload
22
- * fields match the declared accept terms. This is the binding mechanism
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
- import type { OfferPayload, SignedOffer, SignedReceipt, AcceptEntry, OfferVerification, ReceiptVerification, X402AdapterConfig } from './types.js';
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
- * This performs structural validation, expiry/version checks, and
30
- * term-matching against the provided accept entries. It does NOT verify
31
- * the cryptographic signature (that is the caller's responsibility).
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: SignedOffer, accepts: AcceptEntry[], acceptIndex?: number, config?: X402AdapterConfig): OfferVerification;
44
+ export declare function verifyOffer(offer: RawSignedOffer, accepts: AcceptEntry[], config?: X402AdapterConfig): OfferVerification;
40
45
  /**
41
46
  * Verify an x402 signed receipt
42
47
  *
43
- * Performs structural validation on the receipt. Does NOT verify
44
- * the cryptographic signature.
45
- *
46
- * @param receipt - The signed receipt to verify
47
- * @param config - Optional adapter configuration
48
- * @returns Verification result with errors if invalid
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: SignedReceipt, config?: X402AdapterConfig): ReceiptVerification;
55
+ export declare function verifyReceipt(receipt: RawSignedReceipt, config?: X402AdapterConfig): ReceiptVerification;
51
56
  /**
52
- * Match offer payload fields against a single accept entry
57
+ * Verify consistency between an offer and a receipt
53
58
  *
54
- * Compares: network, asset, payTo, amount, scheme, settlement
55
- * All present fields must match exactly. Amount comparison is string-based
56
- * (minor units) to avoid floating-point issues.
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: OfferPayload, accept: AcceptEntry): string[];
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: OfferPayload, accepts: AcceptEntry[], acceptIndex?: number): {
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;
@@ -1 +1 @@
1
- {"version":3,"file":"verify.d.ts","sourceRoot":"","sources":["../src/verify.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAGH,OAAO,KAAK,EACV,YAAY,EACZ,WAAW,EACX,aAAa,EACb,WAAW,EACX,iBAAiB,EACjB,mBAAmB,EAEnB,iBAAiB,EAElB,MAAM,YAAY,CAAC;AA+PpB;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,WAAW,EAClB,OAAO,EAAE,WAAW,EAAE,EACtB,WAAW,CAAC,EAAE,MAAM,EACpB,MAAM,CAAC,EAAE,iBAAiB,GACzB,iBAAiB,CAuInB;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,aAAa,EACtB,MAAM,CAAC,EAAE,iBAAiB,GACzB,mBAAmB,CAgDrB;AAMD;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,WAAW,GAAG,MAAM,EAAE,CAwBrF;AAMD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,YAAY,CAC1B,OAAO,EAAE,YAAY,EACrB,OAAO,EAAE,WAAW,EAAE,EACtB,WAAW,CAAC,EAAE,MAAM,GACnB;IAAE,KAAK,EAAE,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