@integraledger/lcp-binding-canton-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,12 @@
1
+ # @integraledger/lcp-binding-canton-x402
2
+
3
+ ## 0.9.0
4
+
5
+ First release. Welds an ATR hash into a Canton Coin settlement over x402's `exact` scheme for Canton:
6
+ the seller advertises `PaymentRequirements.extra.memo`, the payer echoes it into the transfer metadata
7
+ under `x402.memo`, and the facilitator rejects `invalid_exact_canton_memo_mismatch` on a mismatch
8
+ (scheme safety check 12). A §8.3.1 Native Field binding, conforms to LCP v1.38.
9
+
10
+ Split out of `@integraledger/lcp-binding-canton` rather than replacing it: x402's exact-Canton scheme
11
+ settles Canton Coin only, so the `LcpAnchor` overlay remains the carrier for every other Canton
12
+ deployment. One chain, two carriers, two rails — `canton` and `canton:x402`.
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,119 @@
1
+ # @integraledger/lcp-binding-canton-x402
2
+
3
+ Welds an ATR hash into a Canton Coin settlement over x402's `exact` scheme.
4
+
5
+ ```bash
6
+ npm install @integraledger/lcp-binding-canton-x402
7
+ ```
8
+
9
+ | | |
10
+ |---|---|
11
+ | **Chain** | Canton — **Canton Coin only**, see below |
12
+ | **Pattern** | `native-field` (LCP §8.3.1) |
13
+ | **Protocol** | `x402` — the carrier is x402's, not Canton's own |
14
+ | **Carrier** | `PaymentRequirements.extra.memo`, echoed into the transfer metadata under `x402.memo` |
15
+ | **Surface** | `createCantonX402Adapter` returning a rail-native adapter over a `CantonX402Reader` port — **not** `binding-core`'s `WeldAdapter`, whose shape is EVM's |
16
+
17
+ ## The carrier
18
+
19
+ x402's `exact` scheme for Canton defines a seller-set memo:
20
+
21
+ > `extra.memo` (optional): Seller-defined UTF-8 string, max 256 bytes. When present, the client MUST
22
+ > include it in the transfer's metadata.
23
+
24
+ and its facilitator safety checks make it binding:
25
+
26
+ > **Memo.** If `paymentRequirements.extra.memo` is set, the transfer metadata MUST carry the identical
27
+ > value under `x402.memo`. Reject with `invalid_exact_canton_memo_mismatch`.
28
+
29
+ So the seller names the value, the payer must echo it into the transfer that moves the money, and a third
30
+ party refuses to relay the payment if the two disagree. One transaction settles each payment, so the
31
+ weld, the value and the settlement are the same on-ledger event.
32
+
33
+ ```ts
34
+ import {
35
+ CANTON_X402_MANIFEST,
36
+ createCantonX402Adapter,
37
+ makeCantonX402Reader,
38
+ } from "@integraledger/lcp-binding-canton-x402";
39
+
40
+ declare const atrHash: string;
41
+ declare const updateId: string;
42
+
43
+ const adapter = createCantonX402Adapter(CANTON_X402_MANIFEST);
44
+
45
+ // SELLER, at proposal time — merge into the x402 PaymentRequirements you already emit.
46
+ const extra = adapter.propose(atrHash); // { memo: "0x…" }
47
+
48
+ // VERIFIER, after settlement — one update carries the weld and the asset it is attached to.
49
+ const reader = makeCantonX402Reader({
50
+ jsonLedgerUrl: "https://participant.example",
51
+ bearerJwt: process.env["CANTON_READER_JWT"] ?? "",
52
+ });
53
+ const settled = await adapter.observe({ updateId }, reader);
54
+ // { ok: true, value: { state: "settled", atrHash, receiver, amount, instrumentId } }
55
+ ```
56
+
57
+ ## Which Canton binding do I want?
58
+
59
+ There are two, because Canton has two carriers and a manifest can honestly describe one.
60
+
61
+ **This one, when you settle through x402.** The scheme covers **Canton Coin only** — `asset: "CC"`,
62
+ instrument fixed to `Amulet`, via `transfer-factory`, relayed by a facilitator. Within that, it wins on
63
+ every axis:
64
+
65
+ | | `LcpAnchor` overlay | `extra.memo` (this package) |
66
+ |---|---|---|
67
+ | Same transaction as the payment | no — a separate contract create | **yes** |
68
+ | Weld enforced by | nobody | **the facilitator, before relaying** |
69
+ | `assetBinding` | `none` — recovery never saw what settled | **`carried`** — receiver, amount, instrument |
70
+ | Needs a Daml package deployed | yes | **no** |
71
+
72
+ **[`@integraledger/lcp-binding-canton`](../binding-canton#readme) for everything else** — any instrument,
73
+ any synchronizer, DvP and fund and bond workflows, deployments with no facilitator and no x402 at all.
74
+ There is no native field to ride there, so an overlay contract genuinely is the only carrier, and that
75
+ package now ships the `lcp-anchor` Daml template so it can be deployed.
76
+
77
+ An earlier release said Canton *"cannot"* be bound with a native field, because "Daml has no native
78
+ arbitrary-bytes carrier on a transaction". That was false, and this package is the correction — but the
79
+ overlay is an overlay by **choice**, not obsolete.
80
+
81
+ ## What it still costs, stated plainly
82
+
83
+ **Not zero-party recoverable, and the carrier move did not change that.** Canton is a privacy ledger: a
84
+ transfer and its metadata are visible only to the transaction's stakeholders, so a reader needs a JWT
85
+ authenticating one of them. §8.3 asks whether an auditor can reconstruct the atrHash from the settlement
86
+ reference **alone, without trusting either party to produce records** — on Canton they cannot, whichever
87
+ carrier is used. No private key is needed; a party's cooperation is.
88
+
89
+ **Not forward-indexable.** A participant's update stream is one participant's view, not a chain-global
90
+ index, and the memo is a metadata value rather than an indexed key. `enumerate` scans one party's visible
91
+ transfers and says so.
92
+
93
+ **Scoped to x402.** The manifest declares `protocol: "x402"` because the field, its 256-byte ceiling and
94
+ its enforcement are all x402's. A Canton Coin payment settled outside x402 does not get this carrier — and
95
+ an absent `protocol` would have been a positive claim of protocol-neutrality this binding cannot make.
96
+
97
+ ## Requirement ids
98
+
99
+ This package's source and its messages cite short ids — `ATA-3`, `RCS-5`, `CMP-6` and their kin.
100
+ **They are not LCP clause numbers.** LCP is cited by section (`§8.3.1`, `§C.2`); anything shaped `XXX-n`
101
+ comes from Integra's functional specification of what a complete agent transaction requires, the fourteen
102
+ families below. Nothing in this package's behaviour depends on them, and where an id and an LCP section
103
+ disagree the section governs.
104
+
105
+ | | | | |
106
+ |---|---|---|---|
107
+ | `IDN` identity | `ASP` authority to spend | `ATA` authority to accept terms | `TRM` the terms record |
108
+ | `RCS` recourse | `PAY` payment and settlement | `WLD` the transactional weld | `OFR` offer integrity |
109
+ | `FRC` fraud, risk, and compliance | `OPS` commercial operations | `DSC` discovery and reputation | `ORC` orchestration |
110
+ | `CMP` composition | `PRS` persistence and verification infrastructure | | |
111
+
112
+ ---
113
+
114
+ **Requires Node >= 24.** Part of the
115
+ [Legal Context Protocol open layer](https://github.com/IntegraLedger/integra-protocol) — see the
116
+ [documentation](https://github.com/IntegraLedger/integra-protocol/blob/main/docs/developer/index.md)
117
+ and the
118
+ [package index](https://github.com/IntegraLedger/integra-protocol/blob/main/docs/developer/reference.md).
119
+ Apache-2.0.
@@ -0,0 +1,113 @@
1
+ /**
2
+ * The Canton adapter — thin I/O over an injected participant-reader port. It is a **Canton-native
3
+ * surface**, NOT binding-core's `WeldAdapter`: that port is EVM-shaped (`SettlementRef` is a `0x`-hex tx
4
+ * hash, `ChainReader` speaks `eth_getLogs`), whereas a Canton settlement is a ledger update read via the
5
+ * Daml JSON Ledger API over HTTP.
6
+ *
7
+ * **THE CARRIER.** x402's `exact` scheme for Canton: the seller advertises `PaymentRequirements.extra.memo`,
8
+ * the payer MUST echo it into the transfer's metadata under `x402.memo`, and the facilitator MUST reject
9
+ * `invalid_exact_canton_memo_mismatch` if the two disagree. One transaction settles each payment (scheme
10
+ * §Protocol Flow): the payer signs a `TransferFactory_Transfer` naming the merchant as receiver and does
11
+ * NOT submit it; the facilitator relays the signed submission and pays the traffic fee; the merchant's
12
+ * standing `TransferPreapproval` resolves it `direct`.
13
+ *
14
+ * So the weld, the value and the settlement are one on-ledger event, and `recover` reads all three off a
15
+ * single update. The `LcpAnchor` overlay this replaced pointed at a SEPARATE contract — which is exactly
16
+ * why it could bind no asset: the thing it referenced was not the thing that moved the money.
17
+ *
18
+ * `recover` refuses rather than throwing: an update under audit may be any transaction on the party's
19
+ * stream, and "this is not an LCP settlement" is an answer, not an error. `propose` throws, because a
20
+ * seller advertising a malformed memo is a wiring defect and the facilitator would reject the payment.
21
+ */
22
+ import type { BindingManifest, Outcome } from "@integraledger/lcp-binding-core";
23
+ /**
24
+ * A Canton settlement reference — the ledger update id of the transfer the facilitator relayed.
25
+ *
26
+ * One id, because one transaction settles each payment.
27
+ */
28
+ export interface CantonX402SettlementRef {
29
+ updateId: string;
30
+ }
31
+ /**
32
+ * A settled `TransferFactory_Transfer` as one participant sees it.
33
+ *
34
+ * The asset fields are carried rather than decoded and discarded, and that is what lets the manifest
35
+ * declare `assetBinding: "carried"` honestly: the axis asks whether a CONSUMER can reach the asset the
36
+ * weld is attached to, not merely whether the chain recorded it.
37
+ */
38
+ export interface CantonX402TransferView {
39
+ /** The transfer's on-ledger metadata map. The memo rides `x402.memo` (scheme safety check 12). */
40
+ meta: Readonly<Record<string, string>>;
41
+ /** Receiving party id — the merchant's `payTo` in the scheme's `PaymentRequirements`. */
42
+ receiver: string;
43
+ /** Atomic units as an integer string (1 CC = 1e10 units), exactly as the ledger records it. */
44
+ amount: string;
45
+ /** The Canton Coin instrument identifier `{ admin, id }`. */
46
+ instrumentId: {
47
+ admin: string;
48
+ id: string;
49
+ };
50
+ }
51
+ /** What a settled LCP transfer yields: the weld, and the asset it is welded to. */
52
+ export interface CantonX402Settlement {
53
+ state: "settled";
54
+ atrHash: `0x${string}`;
55
+ receiver: string;
56
+ amount: string;
57
+ instrumentId: {
58
+ admin: string;
59
+ id: string;
60
+ };
61
+ }
62
+ /**
63
+ * Reads the participant's update stream over the Daml JSON Ledger API. Injected so the adapter is pure
64
+ * and testable; a live implementation wraps a participant URL and a party bearer JWT.
65
+ */
66
+ export interface CantonX402Reader {
67
+ /** One settled transfer by ledger update id, or `null` if the participant has no such update. */
68
+ transferView(updateId: string): Promise<CantonX402TransferView | null>;
69
+ /** Update ids of transfers visible to `party`, most recent first. A participant view, not an index. */
70
+ transfersFor(party: string, limit?: number): Promise<string[]>;
71
+ }
72
+ /** The Canton x402 rail's surface. `propose` returns an `extra` fragment for the SELLER to merge into its
73
+ * `PaymentRequirements` — this rail's weld is committed by the seller and echoed by the payer, unlike the
74
+ * memo rails where the payer chooses the value. Its reach is exactly x402's `exact` Canton scheme, which
75
+ * settles Canton Coin only; anything else on Canton needs `@integraledger/lcp-binding-canton`'s overlay. */
76
+ export interface CantonX402Adapter {
77
+ manifest: BindingManifest;
78
+ /**
79
+ * The `extra` fragment the seller merges into its x402 `PaymentRequirements`, committing it to the memo
80
+ * the payer must echo. Throws on a malformed atrHash.
81
+ */
82
+ propose(atrHash: string): {
83
+ readonly memo: string;
84
+ };
85
+ /** Recover the atrHash from a settled transfer, or a `verification-failure` Refusal if none binds. */
86
+ recover(ref: CantonX402SettlementRef, reader: CantonX402Reader): Promise<Outcome<`0x${string}`>>;
87
+ /** Report the `settled` transition, with the asset the weld is attached to. */
88
+ observe(ref: CantonX402SettlementRef, reader: CantonX402Reader): Promise<Outcome<CantonX402Settlement>>;
89
+ /** Scan one party's visible transfers for `atrHash` — a participant view, never a global index. */
90
+ enumerate(atrHash: string, party: string, reader: CantonX402Reader, limit?: number): Promise<CantonX402SettlementRef[]>;
91
+ }
92
+ /** Config for a live Daml JSON Ledger API participant reader. */
93
+ export interface CantonX402ReaderConfig {
94
+ /** JSON Ledger API base URL — e.g. `https://164.92.95.184.nip.io`. */
95
+ jsonLedgerUrl: string;
96
+ /** Bearer JWT authenticating the reading party on the participant. */
97
+ bearerJwt: string;
98
+ }
99
+ /**
100
+ * A live `CantonX402Reader` over the Daml JSON Ledger API, PURE `fetch` — no Daml SDK.
101
+ *
102
+ * Fails LOUD on a non-2xx response or a Daml `errors[]` envelope; an absent update surfaces as `null`,
103
+ * because a reference the participant cannot see is a value the caller must classify, not a transport
104
+ * failure. No package id is required — the memo rides the CIP-56 token-standard transfer, so unlike the
105
+ * overlay this replaced there is no deployment-specific DAR to deploy or configure.
106
+ */
107
+ export declare function makeCantonX402Reader(cfg: CantonX402ReaderConfig): CantonX402Reader;
108
+ /** Construct the Canton x402 adapter. **The manifest is injected, not baked in** — pass this package's own
109
+ * `CANTON_X402_MANIFEST`; a manifest whose `rail` is not `"canton:x402"` throws, because an adapter over
110
+ * another rail's manifest would publish that rail's claims as its own. Nothing has to be deployed first:
111
+ * the memo rides the token-standard transfer, so there is no DAR here. This is the package's entry point. */
112
+ export declare function createCantonX402Adapter(manifest: BindingManifest): CantonX402Adapter;
113
+ //# sourceMappingURL=adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,KAAK,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAIhF;;;;GAIG;AACH,MAAM,WAAW,uBAAuB;IACtC,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,sBAAsB;IACrC,kGAAkG;IAClG,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACvC,yFAAyF;IACzF,QAAQ,EAAE,MAAM,CAAC;IACjB,+FAA+F;IAC/F,MAAM,EAAE,MAAM,CAAC;IACf,6DAA6D;IAC7D,YAAY,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC;CAC7C;AAED,mFAAm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ACtE,aAAa,EAAE,MAAM,CAAC;IACtB,sEAAsE;IACtE,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,sBAAsB,GAC1B,gBAAgB,CA4ClB;AAED;;;8GAG8G;AAC9G,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,eAAe,GACxB,iBAAiB,CA4FnB"}
@@ -0,0 +1,122 @@
1
+ import { atrHashEquals, isAtrHash } from "@integraledger/lcp-kernel";
2
+ import { readTransferMemoAtrHash, x402MemoRequirement } from "./memo.js";
3
+ /**
4
+ * A live `CantonX402Reader` over the Daml JSON Ledger API, PURE `fetch` — no Daml SDK.
5
+ *
6
+ * Fails LOUD on a non-2xx response or a Daml `errors[]` envelope; an absent update surfaces as `null`,
7
+ * because a reference the participant cannot see is a value the caller must classify, not a transport
8
+ * failure. No package id is required — the memo rides the CIP-56 token-standard transfer, so unlike the
9
+ * overlay this replaced there is no deployment-specific DAR to deploy or configure.
10
+ */
11
+ export function makeCantonX402Reader(cfg) {
12
+ if (cfg.jsonLedgerUrl.length === 0)
13
+ throw new Error("makeCantonX402Reader: jsonLedgerUrl is empty");
14
+ if (cfg.bearerJwt.length === 0)
15
+ throw new Error("makeCantonX402Reader: bearerJwt is empty");
16
+ async function ledgerCall(path, body) {
17
+ const res = await fetch(`${cfg.jsonLedgerUrl}${path}`, {
18
+ method: "POST",
19
+ headers: {
20
+ "content-type": "application/json",
21
+ authorization: `Bearer ${cfg.bearerJwt}`,
22
+ },
23
+ body: JSON.stringify(body),
24
+ });
25
+ if (!res.ok) {
26
+ const text = await res.text().catch(() => "");
27
+ throw new Error(`Daml ${path} HTTP ${res.status}: ${text}`);
28
+ }
29
+ const envelope = (await res.json());
30
+ if (envelope.errors !== undefined && envelope.errors.length > 0)
31
+ throw new Error(`Daml ${path} errors: ${envelope.errors.join("; ")}`);
32
+ if (envelope.result === undefined)
33
+ throw new Error(`Daml ${path} returned no result`);
34
+ return envelope.result;
35
+ }
36
+ return {
37
+ async transferView(updateId) {
38
+ const result = await ledgerCall("/v1/updates/transfer", { updateId });
39
+ return result ?? null;
40
+ },
41
+ async transfersFor(party, limit) {
42
+ return ledgerCall("/v1/updates/transfers", {
43
+ party,
44
+ ...(limit !== undefined ? { limit } : {}),
45
+ });
46
+ },
47
+ };
48
+ }
49
+ /** Construct the Canton x402 adapter. **The manifest is injected, not baked in** — pass this package's own
50
+ * `CANTON_X402_MANIFEST`; a manifest whose `rail` is not `"canton:x402"` throws, because an adapter over
51
+ * another rail's manifest would publish that rail's claims as its own. Nothing has to be deployed first:
52
+ * the memo rides the token-standard transfer, so there is no DAR here. This is the package's entry point. */
53
+ export function createCantonX402Adapter(manifest) {
54
+ // Fail-fast: an adapter constructed over another rail's manifest would report that rail's claims as
55
+ // this one's. The EVM adapters bake their module const in; the injectable factories refuse instead.
56
+ // Stryker disable next-line all: the guard runs during test-module load (the repository's
57
+ // test suite constructs the adapter at describe scope), so its mutants are 'static' — outside the vitest
58
+ // runner's per-test attribution and unkillable by any test that in fact kills them behaviorally
59
+ // (each rail pins both arms: valid manifest constructs, wrong rail throws by message).
60
+ if (manifest.rail !== "canton:x402")
61
+ throw new Error(`createCantonX402Adapter: manifest.rail "${manifest.rail}" is not "canton:x402"`);
62
+ // Closure helper (not `this`) so the returned methods stay destructure-safe.
63
+ async function readSettlement(ref, reader) {
64
+ const view = await reader.transferView(ref.updateId);
65
+ if (view === null)
66
+ return {
67
+ refused: true,
68
+ haltClass: "verification-failure",
69
+ code: "canton/no-such-update",
70
+ detail: `the participant has no transfer at updateId ${ref.updateId}`,
71
+ };
72
+ const atrHash = readTransferMemoAtrHash(view.meta);
73
+ if (atrHash === null)
74
+ return {
75
+ refused: true,
76
+ haltClass: "verification-failure",
77
+ code: "canton/no-lcp-memo",
78
+ detail: `the transfer at updateId ${ref.updateId} carries no well-formed atrHash under x402.memo`,
79
+ };
80
+ return {
81
+ ok: true,
82
+ value: {
83
+ state: "settled",
84
+ atrHash,
85
+ receiver: view.receiver,
86
+ amount: view.amount,
87
+ instrumentId: view.instrumentId,
88
+ },
89
+ };
90
+ }
91
+ return {
92
+ manifest,
93
+ propose(atrHash) {
94
+ return x402MemoRequirement(atrHash);
95
+ },
96
+ async recover(ref, reader) {
97
+ const settlement = await readSettlement(ref, reader);
98
+ return "refused" in settlement
99
+ ? settlement
100
+ : { ok: true, value: settlement.value.atrHash };
101
+ },
102
+ observe(ref, reader) {
103
+ return readSettlement(ref, reader);
104
+ },
105
+ async enumerate(atrHash, party, reader, limit) {
106
+ // Fail-fast, like propose: a malformed atrHash can never match a decoded memo, and the silent []
107
+ // it would produce is indistinguishable from "this party has no settlements".
108
+ if (!isAtrHash(atrHash))
109
+ throw new Error(`enumerate: atrHash must be a 0x-prefixed 32-byte value, got "${atrHash}"`);
110
+ const updateIds = await reader.transfersFor(party, limit);
111
+ const out = [];
112
+ for (const updateId of updateIds) {
113
+ const view = await reader.transferView(updateId);
114
+ const found = view === null ? null : readTransferMemoAtrHash(view.meta);
115
+ if (found !== null && atrHashEquals(found, atrHash))
116
+ out.push({ updateId });
117
+ }
118
+ return out;
119
+ },
120
+ };
121
+ }
122
+ //# sourceMappingURL=adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACrE,OAAO,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAuFzE;;;;;;;GAOG;AACH,MAAM,UAAU,oBAAoB,CAClC,GAA2B;IAE3B,IAAI,GAAG,CAAC,aAAa,CAAC,MAAM,KAAK,CAAC;QAChC,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;IAClE,IAAI,GAAG,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,0CAA0C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IAAI,IAAI,aAAa,CAAC,KAAK,EAAE,OAAO,CAAC;oBACjD,GAAG,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC;YAC3B,CAAC;YACD,OAAO,GAAG,CAAC;QACb,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Canton / Daml constants for the LCP transfer-memo binding.
3
+ *
4
+ * **Canton has a native arbitrary-bytes carrier, and this binding uses it.** x402's `exact` scheme for
5
+ * Canton defines `PaymentRequirements.extra.memo` — "Seller-defined UTF-8 string, max 256 bytes. When
6
+ * present, the client MUST include it in the transfer's metadata" — and its facilitator rule 12 rejects
7
+ * `invalid_exact_canton_memo_mismatch` when the transfer metadata does not carry the identical value under
8
+ * `x402.memo`. Seller-committed, payer-echoed, facilitator-verified, and riding the same transaction as
9
+ * the value.
10
+ *
11
+ * Daml is often said to have no native arbitrary-bytes carrier — no memo, no metadata label, no nonce. That
12
+ * is true of the LEDGER's own primitives and false of a payment settled through x402, which is why this
13
+ * rail exists beside `@integraledger/lcp-binding-canton`'s overlay contract rather than instead of it.
14
+ */
15
+ /**
16
+ * The transfer-metadata key the facilitator compares against `extra.memo`. The host's, read exactly: a
17
+ * metadata map carrying our value under a different key is a transfer no facilitator checked.
18
+ */
19
+ export declare const CANTON_X402_MEMO_KEY = "x402.memo";
20
+ /** The scheme's stated ceiling for `extra.memo`. A canonical atrHash is 66 UTF-8 bytes. */
21
+ export declare const CANTON_X402_MEMO_MAX_BYTES = 256;
22
+ /** The three Canton environments this binding ships constants for. */
23
+ export type CantonX402Network = "sandbox" | "devnet" | "mainnet";
24
+ /** Per-network constants. Same shape as the overlay rail's and for the same reason: a Canton participant
25
+ * node is a deployment's own, so there is no endpoint to pin here. */
26
+ export interface CantonX402NetworkConfig {
27
+ network: CantonX402Network;
28
+ /** Explorer base for a contract link (Daml Sandbox has no public explorer — Navigator stand-in). */
29
+ explorerBase: string;
30
+ /** CAIP-2-style identifier — Canton has no canonical namespace yet (informal, like Cardano's). */
31
+ caip2: string;
32
+ }
33
+ /** The constants for one environment. Which Canton rail you want is the real choice: this one only reaches
34
+ * payments settled through x402's Canton-Coin scheme, and `@integraledger/lcp-binding-canton`'s overlay
35
+ * covers everything else. */
36
+ export declare function getCantonX402Config(network: CantonX402Network): CantonX402NetworkConfig;
37
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH;;;GAGG;AACH,eAAO,MAAM,oBAAoB,cAAc,CAAC;AAEhD,2FAA2F;AAC3F,eAAO,MAAM,0BAA0B,MAAM,CAAC;AAE9C,sEAAsE;AACtE,MAAM,MAAM,iBAAiB,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS,CAAC;AAEjE;uEACuE;AACvE,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,iBAAiB,CAAC;IAC3B,oGAAoG;IACpG,YAAY,EAAE,MAAM,CAAC;IACrB,kGAAkG;IAClG,KAAK,EAAE,MAAM,CAAC;CACf;AAoBD;;8BAE8B;AAC9B,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,iBAAiB,GACzB,uBAAuB,CAIzB"}