@integraledger/lcp-binding-evm-x402 0.9.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/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ # @integraledger/lcp-binding-evm-x402
2
+
3
+ ## 0.9.0
4
+
5
+ First public release.
6
+
7
+ `0.9.0` is deliberate: this is a release candidate for 1.0, not a preview. The implementation is complete
8
+ against LCP v1.38 and certified by the conformance corpus, and the remaining distance to 1.0 is the
9
+ specification's own — the standard is still moving through its steering committee, and this package will not
10
+ claim a stability its protocol has not yet promised.
11
+
12
+ Development before this release happened in a private repository and is not reproduced here; no earlier
13
+ version was ever available to install.
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,14 @@
1
+ Integra Protocol
2
+ Copyright 2026 Integra Ledger
3
+
4
+ This product includes software developed by Integra Ledger (https://integraledger.com).
5
+
6
+ "Integra", "Integra Ledger", and the Integra logo are trademarks of Integra Ledger.
7
+ Trademark use is not granted by the Apache License 2.0 (see Section 6).
8
+
9
+ The Legal Context Protocol is co-stewarded by Integra Ledger and AAA-ICDR. This repository is a
10
+ reference implementation of the standard's open layer; the specification itself is published at
11
+ https://legalcontextprotocol.org/standard and is not part of this distribution.
12
+
13
+ The vendored submodule under lib/commerce-payments is Coinbase's AuthCaptureEscrow and carries its own
14
+ MIT licence at lib/commerce-payments/LICENSE.md. It is not covered by the Apache License above.
package/README.md ADDED
@@ -0,0 +1,115 @@
1
+ # @integraledger/lcp-binding-evm-x402
2
+
3
+ Welds an ATR hash into an [x402](https://x402.org) instant settlement on any EVM chain.
4
+
5
+ ```bash
6
+ npm install @integraledger/lcp-binding-evm-x402
7
+ ```
8
+
9
+ | | |
10
+ |---|---|
11
+ | **Chain** | EVM |
12
+ | **Pattern** | `native-field` |
13
+ | **Carrier** | the EIP-3009 `nonce` |
14
+ | **Surface** | `createX402Adapter` returning [`@integraledger/lcp-binding-core`](../binding-core#readme)'s `WeldAdapter` over a `ChainReader` |
15
+
16
+
17
+ Built on [`@integraledger/lcp-binding-core`](../binding-core#readme)'s `WeldAdapter` and
18
+ [`@integraledger/lcp-binding-evm-common`](../binding-evm-common#readme)'s typed-data and event machinery.
19
+ Installing this package installs **viem**.
20
+
21
+ ```ts
22
+ import { createX402Adapter, getX402Deployment } from "@integraledger/lcp-binding-evm-x402";
23
+ import type { VerifierPorts } from "@integraledger/lcp-binding-core";
24
+
25
+ declare const atrHash: `0x${string}`;
26
+ declare const from: string;
27
+ declare const payTo: string;
28
+ declare const ports: VerifierPorts; // your viem-backed ChainReader + ArtifactResolver
29
+ declare const txHash: `0x${string}`;
30
+
31
+ const d = getX402Deployment("base-sepolia-usdc");
32
+ const adapter = createX402Adapter({
33
+ chainId: d.chainId,
34
+ asset: d.asset,
35
+ tokenName: d.tokenName,
36
+ tokenVersion: d.tokenVersion,
37
+ });
38
+
39
+ // PAYER — the EIP-3009 authorization plus the EIP-712 payload to sign. `nonce` IS the atrHash.
40
+ const proposed = await adapter.propose(atrHash, {
41
+ from,
42
+ payTo,
43
+ amount: "1000000",
44
+ validAfter: "0",
45
+ validBefore: "99999999999",
46
+ });
47
+
48
+ // VERIFIER — the atrHash back out of the settlement's `AuthorizationUsed` log.
49
+ const recovered = await adapter.recover({ chainId: d.chainId, txHash }, ports);
50
+ if (!("refused" in recovered)) console.log(recovered.value); // "0x…"
51
+ // Narrow with `"refused" in x` — `Refusal` has no `ok`, so the union cannot discriminate on one.
52
+ ```
53
+
54
+ ## The carrier
55
+
56
+ The ATR hash rides the EIP-3009 `nonce` — a field that already exists in the authorization the payer
57
+ signs. There is no derivation and no overlay contract: the payer's signature covers the nonce, so it
58
+ covers the ATR hash, and the binding inherits the settlement's own authenticity.
59
+
60
+ ```ts
61
+ import { verifyInboundNonce } from "@integraledger/lcp-binding-evm-x402";
62
+
63
+ declare const presentedNonce: string;
64
+ declare const advertisedAtrHash: string;
65
+
66
+ const checked = verifyInboundNonce(presentedNonce, advertisedAtrHash);
67
+ if ("refused" in checked) console.log(checked.code); // "x402/nonce-mismatch" -> re-challenge
68
+ ```
69
+
70
+ Recovery is a scan of `AuthorizationUsed` events on the nonce topic, so a settlement is
71
+ forward-indexable: given the ATR hash, the settlement that carried it can be found without knowing the
72
+ transaction in advance.
73
+
74
+ ## What it refuses rather than guesses
75
+
76
+ Two settlements this binding will not answer for, because the honest answer is a refusal and the
77
+ convenient one is wrong:
78
+
79
+ | Refusal | When |
80
+ |---|---|
81
+ | `x402/not-eip3009-settlement` | The token moved and no `AuthorizationUsed` accompanied it. The payment settled — through the Permit2 fallback or another path that carries no payer-controlled nonce — so there is no weld to report. An empty transition list would say the opposite: that nothing settled. |
82
+ | `x402/ambiguous-settlement` | One transaction carries several `AuthorizationUsed` events with *different* nonces and the `SettlementRef` pins no `logIndex`. Answering either one would be a coin flip presented as a recovery. Pin one with `ref.logIndex`. Repeats of the *same* nonce are one weld seen twice, and resolve normally. |
83
+
84
+ `x402/permit2-fallback` is the propose-side counterpart: an offer requesting a non-EIP-3009 transfer
85
+ method is refused before it is signed, rather than settled unwelded.
86
+
87
+ ## The inbound re-challenge
88
+
89
+ `verifyInboundNonce` is what makes the weld non-optional in practice. A client that settles with a nonce
90
+ that is not the advertised ATR hash is re-challenged rather than silently served — so an unwelded payment
91
+ does not quietly become a served request.
92
+
93
+ ## Requirement ids
94
+
95
+ This package's source and its messages cite short ids — `ATA-3`, `RCS-5`, `CMP-6` and their kin.
96
+ **They are not LCP clause numbers.** LCP is cited by section (`§8.3.1`, `§C.2`); anything shaped `XXX-n`
97
+ comes from Integra's functional specification of what a complete agent transaction requires, the fourteen
98
+ families below. Nothing in this package's behaviour depends on them, and where an id and an LCP section
99
+ disagree the section governs.
100
+
101
+ | | | | |
102
+ |---|---|---|---|
103
+ | `IDN` identity | `ASP` authority to spend | `ATA` authority to accept terms | `TRM` the terms record |
104
+ | `RCS` recourse | `PAY` payment and settlement | `WLD` the transactional weld | `OFR` offer integrity |
105
+ | `FRC` fraud, risk, and compliance | `OPS` commercial operations | `DSC` discovery and reputation | `ORC` orchestration |
106
+ | `CMP` composition | `PRS` persistence and verification infrastructure | | |
107
+
108
+ ---
109
+
110
+ **Requires Node >= 24.** Part of the
111
+ [Legal Context Protocol open layer](https://github.com/IntegraLedger/integra-protocol) — see the
112
+ [documentation](https://github.com/IntegraLedger/integra-protocol/blob/main/docs/developer/index.md)
113
+ and the
114
+ [package index](https://github.com/IntegraLedger/integra-protocol/blob/main/docs/developer/reference.md).
115
+ Apache-2.0.
@@ -0,0 +1,42 @@
1
+ /**
2
+ * The x402 `exact` / EIP-3009 WeldAdapter (LCP `LCP-X402-EVM-NONCE-1`). Built on the live
3
+ * (`lcp-x402-reference`, 114 tests) onto binding-core's `WeldAdapter` contract, with the typed-data
4
+ * machinery reused from `binding-evm-common` (viem lives only here and in binding-evm-common).
5
+ *
6
+ * - `propose` — build the EIP-3009 authorization + typed-data with `nonce = atrHash` (after the Permit2
7
+ * filter); the payer signs the returned `typedData`.
8
+ * - `recover` — read the committed nonce back out of ONE settlement's `AuthorizationUsed` log (= atrHash).
9
+ * - `observe` — map a settlement's `AuthorizationUsed` events to `welded-settled` lifecycle transitions.
10
+ * - `enumerate`— forward-index by the indexed nonce topic (`AuthorizationUsed(_, indexed nonce)`).
11
+ */
12
+ import type { WeldAdapter } from "@integraledger/lcp-binding-core";
13
+ import { type Eip3009Authorization, type Eip3009TypedData } from "@integraledger/lcp-binding-evm-common";
14
+ /** One chain + token this adapter binds. `tokenName`/`tokenVersion` pin the EIP-712 domain of `asset`. */
15
+ export interface X402AdapterConfig {
16
+ chainId: number;
17
+ /** The payment token — the EIP-712 `verifyingContract` and the `AuthorizationUsed` emitter. */
18
+ asset: `0x${string}`;
19
+ tokenName: string;
20
+ tokenVersion: string;
21
+ /** Enumeration lower bound; defaults to the full history (`earliest`). */
22
+ fromBlock?: bigint;
23
+ }
24
+ /** The per-payment proposal inputs (the token/chain identity lives in the adapter config). */
25
+ export interface X402ProposalContext {
26
+ from: string;
27
+ payTo: string;
28
+ /** Amount in token base units (decimal string). */
29
+ amount: string;
30
+ validAfter: string;
31
+ validBefore: string;
32
+ /** The x402 offer's asset-transfer method; anything but `eip3009` is refused (Permit2 filter). */
33
+ assetTransferMethod?: string;
34
+ }
35
+ /** What `propose` yields: the wire authorization + the typed-data the payer signs. */
36
+ export interface X402Proposal {
37
+ authorization: Eip3009Authorization;
38
+ typedData: Eip3009TypedData;
39
+ }
40
+ /** Construct the x402 WeldAdapter for one chain + token. */
41
+ export declare function createX402Adapter(config: X402AdapterConfig): WeldAdapter;
42
+ //# sourceMappingURL=adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAKV,WAAW,EACZ,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAIL,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EAGtB,MAAM,uCAAuC,CAAC;AAM/C,0GAA0G;AAC1G,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,+FAA+F;IAC/F,KAAK,EAAE,KAAK,MAAM,EAAE,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,0EAA0E;IAC1E,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,8FAA8F;AAC9F,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,mDAAmD;IACnD,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,kGAAkG;IAClG,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED,sFAAsF;AACtF,MAAM,WAAW,YAAY;IAC3B,aAAa,EAAE,oBAAoB,CAAC;IACpC,SAAS,EAAE,gBAAgB,CAAC;CAC7B;AAED,4DAA4D;AAC5D,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,iBAAiB,GAAG,WAAW,CA2HxE"}
@@ -0,0 +1,124 @@
1
+ /**
2
+ * The x402 `exact` / EIP-3009 WeldAdapter (LCP `LCP-X402-EVM-NONCE-1`). Built on the live
3
+ * (`lcp-x402-reference`, 114 tests) onto binding-core's `WeldAdapter` contract, with the typed-data
4
+ * machinery reused from `binding-evm-common` (viem lives only here and in binding-evm-common).
5
+ *
6
+ * - `propose` — build the EIP-3009 authorization + typed-data with `nonce = atrHash` (after the Permit2
7
+ * filter); the payer signs the returned `typedData`.
8
+ * - `recover` — read the committed nonce back out of ONE settlement's `AuthorizationUsed` log (= atrHash).
9
+ * - `observe` — map a settlement's `AuthorizationUsed` events to `welded-settled` lifecycle transitions.
10
+ * - `enumerate`— forward-index by the indexed nonce topic (`AuthorizationUsed(_, indexed nonce)`).
11
+ */
12
+ import { AUTHORIZATION_USED_ABI, assetWasTransferred, buildEip3009TypedData, readAuthorizationUsed, refOf, } from "@integraledger/lcp-binding-evm-common";
13
+ import { canonicalAtrHash } from "@integraledger/lcp-kernel";
14
+ import { filterAssetTransferMethod } from "./asset-transfer-method-filter.js";
15
+ import { X402_MANIFEST } from "./manifest.js";
16
+ /** Construct the x402 WeldAdapter for one chain + token. */
17
+ export function createX402Adapter(config) {
18
+ return {
19
+ manifest: X402_MANIFEST,
20
+ async propose(atrHash, ctx) {
21
+ const c = ctx;
22
+ const refusal = filterAssetTransferMethod(c.assetTransferMethod);
23
+ if (refusal !== null)
24
+ return refusal;
25
+ // buildEip3009TypedData throws (fail-fast) on a malformed atrHash — a programming error, not a
26
+ // policy outcome; the Permit2 refusal above is the only value-level Refusal on this path.
27
+ const { authorization, typedData } = buildEip3009TypedData({
28
+ atrHash,
29
+ from: c.from,
30
+ to: c.payTo,
31
+ value: c.amount,
32
+ validAfter: c.validAfter,
33
+ validBefore: c.validBefore,
34
+ chainId: config.chainId,
35
+ tokenName: config.tokenName,
36
+ tokenVersion: config.tokenVersion,
37
+ verifyingContract: config.asset,
38
+ });
39
+ return { ok: true, value: { authorization, typedData } };
40
+ },
41
+ async recover(ref, ports) {
42
+ const logs = (await ports.chain.getTransactionLogs(ref));
43
+ const events = readAuthorizationUsed(logs, config.asset);
44
+ if (events.length === 0)
45
+ return {
46
+ refused: true,
47
+ haltClass: "verification-failure",
48
+ code: "x402/no-settlement-event",
49
+ detail: `no AuthorizationUsed for asset ${config.asset} in this settlement`,
50
+ };
51
+ // Disambiguate by logIndex when the ref pins one — but a pinned index that matches NO event is a
52
+ // failure, never a silent fallback to events[0] (that could recover a DIFFERENT settlement's
53
+ // atrHash — a fail-fast violation). events.length > 0 guarantees events[0] is defined.
54
+ if (ref.logIndex !== undefined) {
55
+ const match = events.find((e) => e.logIndex === ref.logIndex);
56
+ if (match === undefined)
57
+ return {
58
+ refused: true,
59
+ haltClass: "verification-failure",
60
+ code: "x402/log-index-not-found",
61
+ detail: `no AuthorizationUsed at logIndex ${ref.logIndex} for asset ${config.asset}`,
62
+ };
63
+ return { ok: true, value: match.nonce };
64
+ }
65
+ // UNPINNED, and more than one DISTINCT nonce in the transaction: the caller has not said which
66
+ // settlement it is asking about, and this function must not choose for it. It used to answer
67
+ // `events[0]` — the silent fallback the comment three lines above already calls a fail-fast
68
+ // violation, committed in the branch that comment did not cover. Distinctness is what makes it an
69
+ // ambiguity: several `AuthorizationUsed` logs carrying the SAME nonce are one weld observed more
70
+ // than once, and refusing those would break a legitimate batch. Same shape as tempo-mpp's
71
+ // `ambiguous-memos`, for the same reason.
72
+ const distinct = new Set(events.map((e) => e.nonce.toLowerCase()));
73
+ if (distinct.size > 1)
74
+ return {
75
+ refused: true,
76
+ haltClass: "verification-failure",
77
+ code: "x402/ambiguous-settlement",
78
+ detail: `settlement ${ref.txHash} carries ${distinct.size} AuthorizationUsed events with different nonces for asset ${config.asset} — pin one with ref.logIndex rather than choosing for the caller`,
79
+ };
80
+ return { ok: true, value: events[0].nonce };
81
+ },
82
+ async observe(ref, ports) {
83
+ const logs = (await ports.chain.getTransactionLogs(ref));
84
+ const events = readAuthorizationUsed(logs, config.asset);
85
+ if (events.length === 0) {
86
+ // An empty transition list is a POSITIVE claim: this transaction settled nothing of this asset.
87
+ // That is true only when the token did not move. If it did, the payment settled through a path
88
+ // this binding cannot read the weld from — in practice x402's Permit2 fallback
89
+ // (`x402ExactPermit2Proxy`), which exposes no payer-controlled nonce, which is exactly why
90
+ // `filterAssetTransferMethod` refuses it on the propose side. Answering `[]` here would let the
91
+ // observe side quietly assert the opposite of what the propose side refuses to allow.
92
+ if (assetWasTransferred(logs, config.asset))
93
+ return {
94
+ refused: true,
95
+ haltClass: "verification-failure",
96
+ code: "x402/not-eip3009-settlement",
97
+ detail: `token ${config.asset} was transferred by settlement ${ref.txHash} but it emitted no EIP-3009 AuthorizationUsed — the atrHash weld rides only on the payer-controlled nonce of transferWithAuthorization, so a settlement reached by any other path (the Permit2 fallback among them) carries no on-chain weld this binding can report`,
98
+ };
99
+ return { ok: true, value: [] };
100
+ }
101
+ // The only on-chain state x402 exposes is settlement itself (proposed is off-chain, pre-settlement).
102
+ const at = await ports.chain.blockTime(ref);
103
+ return {
104
+ ok: true,
105
+ value: events.map((e) => ({
106
+ state: "welded-settled",
107
+ at,
108
+ ref: refOf(ref.chainId, ref.txHash, e.logIndex),
109
+ })),
110
+ };
111
+ },
112
+ async enumerate(atrHash, ports) {
113
+ const logs = (await ports.chain.getLogs({
114
+ address: config.asset,
115
+ event: AUTHORIZATION_USED_ABI[0],
116
+ args: { nonce: canonicalAtrHash(atrHash, "enumerate") },
117
+ fromBlock: config.fromBlock ?? "earliest",
118
+ toBlock: "latest",
119
+ }));
120
+ return logs.map((l) => refOf(config.chainId, l.transactionHash ?? undefined, l.logIndex));
121
+ },
122
+ };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AAC;YAC5C,OAAO;gBACL,EAAE,EAAE,IAAI;gBACR,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;oBACxB,KAAK,EAAE,gBAAgB;oBACvB,EAAE;oBACF,GAAG,EAAE,KAAK,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,CAAC;iBAChD,CAAC,CAAC;aACJ,CAAC;QACJ,CAAC;QAED,KAAK,CAAC,SAAS,CACb,OAAsB,EACtB,KAAoB;YAEpB,MAAM,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC;gBACtC,OAAO,EAAE,MAAM,CAAC,KAAK;gBACrB,KAAK,EAAE,sBAAsB,CAAC,CAAC,CAAC;gBAChC,IAAI,EAAE,EAAE,KAAK,EAAE,gBAAgB,CAAC,OAAO,EAAE,WAAW,CAAC,EAAE;gBACvD,SAAS,EAAE,MAAM,CAAC,SAAS,IAAI,UAAU;gBACzC,OAAO,EAAE,QAAQ;aAClB,CAAC,CAAU,CAAC;YACb,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CACpB,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,eAAe,IAAI,SAAS,EAAE,CAAC,CAAC,QAAQ,CAAC,CAClE,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,82 @@
1
+ /**
2
+ * The two mandatory x402 checks.
3
+ *
4
+ * 1. **Asset-transfer-method filter.** The atrHash-as-nonce weld rides ONLY on EIP-3009
5
+ * `transferWithAuthorization`, whose `nonce` is a payer-controlled 32-byte field committed on-chain in
6
+ * `AuthorizationUsed`. x402's `exact` scheme on EVM defines **three** methods, verified at
7
+ * `x402-foundation/x402@1fec3aa04e41`:
8
+ *
9
+ * 1. `eip3009` — tokens with native `transferWithAuthorization` (the default when `extra` omits it)
10
+ * 2. `permit2` — tokens without it, via a proxy and the canonical Permit2 contract
11
+ * 3. `erc7710` — smart accounts with delegation support
12
+ *
13
+ * Only the first exposes a payer-controlled nonce. Under `permit2` the value rides an off-chain EIP-712
14
+ * witness, and under `erc7710` the payment is authorized by a delegation the payer's smart account
15
+ * granted — in neither case is there a 32-byte field on the settlement for the weld to occupy. An offer
16
+ * requesting either would settle a payment that silently DROPS the binding, so this refuses instead.
17
+ *
18
+ * The rule is not Permit2-specific and the naming here is deliberate: it is "the method must be the one
19
+ * that carries a payer nonce". A refusal naming only one of the two rejected methods would report a
20
+ * correct decision for the wrong reason, which is what an operator then debugs.
21
+ *
22
+ * The settlement-side spender/witness proxy detection is the on-chain extension that lands once a
23
+ * harness run closes it; it is NOT fabricated here.
24
+ *
25
+ * 2. **Payment-flow filter.** x402 §6.1 defines three flows and reserves `extra.paymentFlow` as a
26
+ * protocol key: `authorization` (verify → resource → settle), `upfront` (settle → resource) and
27
+ * `escrow` (settle → resource → settle). "When the resolved payment flow is not `authorization`,
28
+ * `PaymentRequired` `accepts[].extra.paymentFlow` MUST be present", and "Clients MUST NOT construct a
29
+ * payment for a `paymentFlow` they do not recognize."
30
+ *
31
+ * This weld survives `upfront` untouched — one settlement, one EIP-3009 authorization, one nonce.
32
+ *
33
+ * `escrow` settles TWICE, and the scheme's own table marks `eip3009` "One-time use", so a single nonce
34
+ * cannot carry both the deposit and the final charge. **That is a statement about THIS carrier, not a
35
+ * judgement about the flow.** A two-phase settlement is exactly the case the record is supposed to
36
+ * survive, and there is a binding for it: `@integraledger/lcp-binding-evm-escrow` welds
37
+ * `PaymentInfo.salt`, which is recoverable from BOTH the authorization and the capture artifact and
38
+ * joins them on `paymentInfoHash`. So this answers "not this binding, that one" and names it — it does
39
+ * not tell a deployment how to transact, which is not this project's business.
40
+ *
41
+ * 3. **Inbound `nonce == atrHash` re-challenge.** The seller-side verification that a presented
42
+ * authorization's nonce equals the atrHash it advertised. The primitive lives here; the re-challenge
43
+ * orchestration (re-issue the 402 on mismatch) belongs to the seller surface.
44
+ */
45
+ import type { Outcome, Refusal } from "@integraledger/lcp-binding-core";
46
+ /** The x402 asset-transfer method an offer may request. Only `eip3009` carries the payer nonce. */
47
+ export declare const EIP3009_TRANSFER_METHOD = "eip3009";
48
+ /**
49
+ * The methods x402's exact-EVM scheme defines, in the scheme's own order. Listed so the refusal can say
50
+ * whether it met a method the host defines or one nobody does — a typo and an unsupported-but-real method
51
+ * are different problems for the operator reading the message.
52
+ */
53
+ export declare const X402_TRANSFER_METHODS: readonly string[];
54
+ /**
55
+ * Refuse an asset-transfer method that carries no payer nonce. Returns a typed `policy-rejection`
56
+ * `Refusal` when the method is present and not `eip3009`; `null` when it is absent or `eip3009` (proceed).
57
+ *
58
+ * Absent is `null` because x402's scheme says so: "If no `assetTransferMethod` is specified in
59
+ * `PaymentRequired.extra`, clients should default to `eip3009`."
60
+ */
61
+ export declare function filterAssetTransferMethod(assetTransferMethod: string | undefined): Refusal | null;
62
+ /** The x402 payment flows, §6.1. `authorization` is the default when `extra.paymentFlow` is omitted. */
63
+ export declare const X402_PAYMENT_FLOWS: readonly string[];
64
+ /**
65
+ * Report a payment flow this weld cannot ride. `null` means proceed.
66
+ *
67
+ * Absent is `null` because §6.1 makes `authorization` the resolved default, and it is also the flow whose
68
+ * ordering the rest of this package assumes: verify → resource → settle.
69
+ *
70
+ * The `escrow` answer is a ROUTING answer, not a policy one. Which settlement shape a party chooses is
71
+ * theirs; what this project owes them is a record that survives it, and for two-phase settlement that
72
+ * record is `binding-evm-escrow`'s, not this one's.
73
+ */
74
+ export declare function filterPaymentFlow(paymentFlow: string | undefined): Refusal | null;
75
+ /**
76
+ * The inbound re-challenge: does a presented authorization nonce equal the advertised atrHash?
77
+ * Compared as DECODED BYTES per LCP §2.5, so the two any-case spellings of one hash agree; returns the
78
+ * lowercased nonce on match, else a `verification-failure`
79
+ * `Refusal` (the caller re-issues the 402 — never settles an unwelded payment).
80
+ */
81
+ export declare function verifyInboundNonce(presentedNonce: string, expectedAtrHash: string): Outcome<`0x${string}`>;
82
+ //# sourceMappingURL=asset-transfer-method-filter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asset-transfer-method-filter.d.ts","sourceRoot":"","sources":["../src/asset-transfer-method-filter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAGxE,mGAAmG;AACnG,eAAO,MAAM,uBAAuB,YAAY,CAAC;AAEjD;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,EAAE,SAAS,MAAM,EAIlD,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CACvC,mBAAmB,EAAE,MAAM,GAAG,SAAS,GACtC,OAAO,GAAG,IAAI,CAiBhB;AAED,wGAAwG;AACxG,eAAO,MAAM,kBAAkB,EAAE,SAAS,MAAM,EAI/C,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAC/B,WAAW,EAAE,MAAM,GAAG,SAAS,GAC9B,OAAO,GAAG,IAAI,CAchB;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,cAAc,EAAE,MAAM,EACtB,eAAe,EAAE,MAAM,GACtB,OAAO,CAAC,KAAK,MAAM,EAAE,CAAC,CAWxB"}