@agentpos/rail-arc 0.0.0-stage → 0.1.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/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/README.md CHANGED
@@ -1,3 +1,76 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
1
+ # @agentpos/rail-arc
2
+
3
+ AgentPOS payment rail for **Arc**, Circle's L1: x402 checkout in USDC, settled by the **Circle
4
+ Facilitator Service** straight to the merchant's own Arc wallet. AgentPOS never holds funds or
5
+ keys and takes no commission; the merchant stays the merchant of record.
6
+
7
+ It plugs into the open-source AgentPOS core
8
+ ([`@agentpos/core`](https://www.npmjs.com/package/@agentpos/core),
9
+ [NovaCorpAI/agentpos](https://github.com/NovaCorpAI/agentpos)), which turns an existing store
10
+ (WooCommerce today) into one AI agents can buy from.
11
+
12
+ > **Testnet only for now.** Arc mainnet (`eip155:5042`) is defined here but stays locked in the
13
+ > core until the Arc production gate passes. Use Arc testnet (`eip155:5042002`).
14
+
15
+ ## Install
16
+
17
+ ```bash
18
+ npm install @agentpos/core @agentpos/rail-arc
19
+ ```
20
+
21
+ Importing the package registers both Arc networks with the core (pricing, address validation,
22
+ wallet linking). Node >= 22.5.
23
+
24
+ ## Store side: offer Arc in the 402
25
+
26
+ ```ts
27
+ import { createAgentPOSApp } from "@agentpos/site";
28
+ import { ARC_TESTNET, arcStoreNetwork } from "@agentpos/rail-arc";
29
+
30
+ const app = createAgentPOSApp({
31
+ // ...site, core, connector, storage
32
+ x402Networks: [
33
+ arcStoreNetwork(ARC_TESTNET, "0xMerchantArcWallet", {
34
+ url: process.env.AGENTPOS_ARC_FACILITATOR_URL!, // https://api.circle.com/v1/facilitator/x402
35
+ apiKey: process.env.AGENTPOS_ARC_FACILITATOR_API_KEY_TESTNET!, // console.circle.com
36
+ }),
37
+ ],
38
+ });
39
+ ```
40
+
41
+ The store keeps its own network and adds Arc next to it. The order is created only after the
42
+ facilitator settles, idempotent by transaction hash. `arcStoreNetwork` also brings a read-only
43
+ payment watcher that alerts on any USDC that reached the merchant's wallet without an order.
44
+
45
+ ## Buyer side: pay on Arc under the human's mandate
46
+
47
+ ```ts
48
+ import { BuyerService } from "@agentpos/mcp-buyer";
49
+ import { ARC_TESTNET, arcBuyerNetwork } from "@agentpos/rail-arc";
50
+
51
+ // mandate: { "maxPerTx": "15", "maxTotal": "20", "allowedNetworks": ["eip155:5042002"] }
52
+ const buyer = new BuyerService({ profile, networks: [arcBuyerNetwork(ARC_TESTNET, account)] });
53
+ ```
54
+
55
+ The agent pays on Arc only when the mandate lists it, each payment is capped at the cart total
56
+ converted exactly to Arc's 6-decimal USDC (a price Arc cannot represent is refused, never
57
+ rounded), and the period limit adds up spending across every network.
58
+
59
+ ## What else is exported
60
+
61
+ - `ARC_MAINNET`, `ARC_TESTNET`, `registerArcNetworks()`: the networks and their USDC.
62
+ - `registerArcWalletProof()`: lets a merchant link an Arc wallet by signing a challenge
63
+ (EIP-191, ERC-1271 for smart accounts). No key ever reaches AgentPOS.
64
+ - `arcResourceExtension`, `arcAccept`: lower-level x402 wiring for a custom server.
65
+ - `createArcPaymentWatcher`: the reconciliation reader on its own.
66
+
67
+ ## Evidence
68
+
69
+ Real purchases on Arc testnet through the Circle Facilitator Service, with the order created in
70
+ WooCommerce only after settlement, are listed with their transaction hashes in the
71
+ [repository README](https://github.com/NovaCorpAI/agentpos-arc#readme). A purchase also runs
72
+ once a day in CI.
73
+
74
+ ## License
75
+
76
+ Apache-2.0. Built by NovaCorpAI SpA, Santiago, Chile.
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Arc for the AgentPOS buyer (`@agentpos/mcp-buyer`): the buyer's own Arc wallet as one more
3
+ * network its `BuyerService` can pay on. The mandate still decides: the network is used only
4
+ * when the human lists it in `allowedNetworks`, and every payment is capped at the cart total,
5
+ * converted exactly to Arc's 6 decimals, before anything is signed.
6
+ */
7
+ import { ExactEvmScheme } from "@x402/evm/exact/client";
8
+ import type { BuyerNetworkExtension, UsdcMinor } from "@agentpos/core";
9
+ /** The buyer's own signer on Arc: a viem account, or a Circle agent wallet behind one. */
10
+ export type ArcBuyerSigner = ConstructorParameters<typeof ExactEvmScheme>[0];
11
+ /**
12
+ * Pass to `new BuyerService({ networks: [arcBuyerNetwork(ARC_TESTNET, account)] })`, or to the
13
+ * MCP server through `buildBuyerServer({ depsOverrides: { networks } })`. The key stays with
14
+ * the signer; this package never sees it.
15
+ */
16
+ export declare function arcBuyerNetwork(network: string, signer: ArcBuyerSigner): (maxPerPayment: UsdcMinor) => BuyerNetworkExtension;
17
+ //# sourceMappingURL=buyer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buyer.d.ts","sourceRoot":"","sources":["../src/buyer.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,KAAK,EAAE,qBAAqB,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAGvE,0FAA0F;AAC1F,MAAM,MAAM,cAAc,GAAG,qBAAqB,CAAC,OAAO,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;AAE7E;;;;GAIG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,cAAc,GACrB,CAAC,aAAa,EAAE,SAAS,KAAK,qBAAqB,CAGrD"}
package/dist/buyer.js ADDED
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Arc for the AgentPOS buyer (`@agentpos/mcp-buyer`): the buyer's own Arc wallet as one more
3
+ * network its `BuyerService` can pay on. The mandate still decides: the network is used only
4
+ * when the human lists it in `allowedNetworks`, and every payment is capped at the cart total,
5
+ * converted exactly to Arc's 6 decimals, before anything is signed.
6
+ */
7
+ import { ExactEvmScheme } from "@x402/evm/exact/client";
8
+ import { arcBuyerExtension } from "./x402.js";
9
+ /**
10
+ * Pass to `new BuyerService({ networks: [arcBuyerNetwork(ARC_TESTNET, account)] })`, or to the
11
+ * MCP server through `buildBuyerServer({ depsOverrides: { networks } })`. The key stays with
12
+ * the signer; this package never sees it.
13
+ */
14
+ export function arcBuyerNetwork(network, signer) {
15
+ const client = new ExactEvmScheme(signer);
16
+ return (maxPerPayment) => arcBuyerExtension(network, client, maxPerPayment);
17
+ }
18
+ //# sourceMappingURL=buyer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buyer.js","sourceRoot":"","sources":["../src/buyer.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAExD,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAK9C;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAC7B,OAAe,EACf,MAAsB;IAEtB,MAAM,MAAM,GAAG,IAAI,cAAc,CAAC,MAAM,CAAC,CAAC;IAC1C,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,aAAa,CAAC,CAAC;AAC9E,CAAC"}
@@ -0,0 +1,6 @@
1
+ export * from "./networks.js";
2
+ export * from "./wallet-proof.js";
3
+ export * from "./x402.js";
4
+ export * from "./reconcile.js";
5
+ export * from "./buyer.js";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAWA,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @agentpos/rail-arc: AgentPOS checkout in USDC on Arc.
3
+ *
4
+ * Importing this package registers both Arc networks with @agentpos/core, so the core can
5
+ * price, validate addresses and link wallets on Arc. Call `registerArcWalletProof()` once at
6
+ * startup to verify merchant wallet links on Arc.
7
+ */
8
+ import { registerArcNetworks } from "./networks.js";
9
+ registerArcNetworks();
10
+ export * from "./networks.js";
11
+ export * from "./wallet-proof.js";
12
+ export * from "./x402.js";
13
+ export * from "./reconcile.js";
14
+ export * from "./buyer.js";
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAEpD,mBAAmB,EAAE,CAAC;AAEtB,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC"}
@@ -0,0 +1,27 @@
1
+ import type { ChainProfile } from "@agentpos/core";
2
+ export declare const ARC_MAINNET: "eip155:5042";
3
+ export declare const ARC_TESTNET: "eip155:5042002";
4
+ export type ArcNetwork = typeof ARC_MAINNET | typeof ARC_TESTNET;
5
+ /** USDC on Arc, same address on mainnet and testnet. ERC-20 interface, 6 decimals. */
6
+ export declare const ARC_USDC: "0x3600000000000000000000000000000000000000";
7
+ export declare const ARC_USDC_DECIMALS = 6;
8
+ /**
9
+ * EIP-712 domain of USDC on Arc, which the exact scheme needs in every 402 so the buyer can sign
10
+ * the EIP-3009 authorization. Confirmed by the Circle facilitator's /supported on 2026-10-23.
11
+ */
12
+ export declare const ARC_USDC_EIP712: {
13
+ readonly name: "USDC";
14
+ readonly version: "2";
15
+ };
16
+ export declare const ARC_RPC_URLS: Record<ArcNetwork, string>;
17
+ /**
18
+ * Strict EVM receiving address: well formed, not the zero address, and when it is written in
19
+ * mixed case its EIP-55 checksum must be right (a wrong checksum is a typo, and a typo in a
20
+ * payTo sends a merchant's money nowhere).
21
+ */
22
+ export declare function isValidArcAddress(address: string): boolean;
23
+ export declare const ARC_CHAIN_PROFILES: readonly ChainProfile[];
24
+ /** Registers both Arc networks with the core. Safe to call more than once. */
25
+ export declare function registerArcNetworks(): void;
26
+ export declare function isArcNetwork(value: string): value is ArcNetwork;
27
+ //# sourceMappingURL=networks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"networks.d.ts","sourceRoot":"","sources":["../src/networks.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAGnD,eAAO,MAAM,WAAW,EAAG,aAAsB,CAAC;AAClD,eAAO,MAAM,WAAW,EAAG,gBAAyB,CAAC;AACrD,MAAM,MAAM,UAAU,GAAG,OAAO,WAAW,GAAG,OAAO,WAAW,CAAC;AAEjE,sFAAsF;AACtF,eAAO,MAAM,QAAQ,EAAG,4CAAqD,CAAC;AAC9E,eAAO,MAAM,iBAAiB,IAAI,CAAC;AACnC;;;GAGG;AACH,eAAO,MAAM,eAAe;;;CAA0C,CAAC;AAEvE,eAAO,MAAM,YAAY,EAAE,MAAM,CAAC,UAAU,EAAE,MAAM,CAGnD,CAAC;AAOF;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAM1D;AAYD,eAAO,MAAM,kBAAkB,EAAE,SAAS,YAAY,EAGrD,CAAC;AAEF,8EAA8E;AAC9E,wBAAgB,mBAAmB,IAAI,IAAI,CAE1C;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,UAAU,CAE/D"}
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Arc, Circle's L1, as AgentPOS sees it: two networks, USDC with 6 decimals in its ERC-20
3
+ * interface, EVM addresses with EIP-55 checksums.
4
+ *
5
+ * Sources (checked 2026-10-23): docs.arc.io/arc/references/connect-to-arc and
6
+ * contract-addresses; @x402/evm 2.28.0 default asset table (USDC "USDC" version "2", EIP-3009).
7
+ * Arc pays gas in USDC; the native balance has 18 decimals, but payments always use the
8
+ * ERC-20 interface at the address below, which has 6. AgentPOS never touches the native unit.
9
+ */
10
+ import { getAddress, isAddress } from "viem";
11
+ import { registerChainProfile } from "@agentpos/core";
12
+ export const ARC_MAINNET = "eip155:5042";
13
+ export const ARC_TESTNET = "eip155:5042002";
14
+ /** USDC on Arc, same address on mainnet and testnet. ERC-20 interface, 6 decimals. */
15
+ export const ARC_USDC = "0x3600000000000000000000000000000000000000";
16
+ export const ARC_USDC_DECIMALS = 6;
17
+ /**
18
+ * EIP-712 domain of USDC on Arc, which the exact scheme needs in every 402 so the buyer can sign
19
+ * the EIP-3009 authorization. Confirmed by the Circle facilitator's /supported on 2026-10-23.
20
+ */
21
+ export const ARC_USDC_EIP712 = { name: "USDC", version: "2" };
22
+ export const ARC_RPC_URLS = {
23
+ [ARC_MAINNET]: "https://rpc.mainnet.arc.io",
24
+ [ARC_TESTNET]: "https://rpc.testnet.arc.io",
25
+ };
26
+ const EXPLORERS = {
27
+ [ARC_MAINNET]: "https://explorer.arc.io",
28
+ [ARC_TESTNET]: "https://explorer.testnet.arc.io",
29
+ };
30
+ /**
31
+ * Strict EVM receiving address: well formed, not the zero address, and when it is written in
32
+ * mixed case its EIP-55 checksum must be right (a wrong checksum is a typo, and a typo in a
33
+ * payTo sends a merchant's money nowhere).
34
+ */
35
+ export function isValidArcAddress(address) {
36
+ if (!isAddress(address, { strict: false }))
37
+ return false;
38
+ if (/^0x0{40}$/i.test(address))
39
+ return false;
40
+ const hex = address.slice(2);
41
+ const mixedCase = hex !== hex.toLowerCase() && hex !== hex.toUpperCase();
42
+ return mixedCase ? getAddress(address) === address : true;
43
+ }
44
+ const profile = (caip2, testnet) => ({
45
+ caip2,
46
+ family: "eip155",
47
+ label: testnet ? "Arc testnet" : "Arc",
48
+ testnet,
49
+ usdcDecimals: ARC_USDC_DECIMALS,
50
+ isValidAddress: isValidArcAddress,
51
+ explorerTxUrl: (tx) => `${EXPLORERS[caip2]}/tx/${encodeURIComponent(tx)}`,
52
+ });
53
+ export const ARC_CHAIN_PROFILES = [
54
+ profile(ARC_MAINNET, false),
55
+ profile(ARC_TESTNET, true),
56
+ ];
57
+ /** Registers both Arc networks with the core. Safe to call more than once. */
58
+ export function registerArcNetworks() {
59
+ for (const p of ARC_CHAIN_PROFILES)
60
+ registerChainProfile(p);
61
+ }
62
+ export function isArcNetwork(value) {
63
+ return value === ARC_MAINNET || value === ARC_TESTNET;
64
+ }
65
+ //# sourceMappingURL=networks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"networks.js","sourceRoot":"","sources":["../src/networks.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAE7C,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAEtD,MAAM,CAAC,MAAM,WAAW,GAAG,aAAsB,CAAC;AAClD,MAAM,CAAC,MAAM,WAAW,GAAG,gBAAyB,CAAC;AAGrD,sFAAsF;AACtF,MAAM,CAAC,MAAM,QAAQ,GAAG,4CAAqD,CAAC;AAC9E,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC;AACnC;;;GAGG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,EAAW,CAAC;AAEvE,MAAM,CAAC,MAAM,YAAY,GAA+B;IACtD,CAAC,WAAW,CAAC,EAAE,4BAA4B;IAC3C,CAAC,WAAW,CAAC,EAAE,4BAA4B;CAC5C,CAAC;AAEF,MAAM,SAAS,GAA+B;IAC5C,CAAC,WAAW,CAAC,EAAE,yBAAyB;IACxC,CAAC,WAAW,CAAC,EAAE,iCAAiC;CACjD,CAAC;AAEF;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAe;IAC/C,IAAI,CAAC,SAAS,CAAC,O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mount, UsdcMinor } from "@agentpos/core";
2
+ export interface ArcTransfer {
3
+ txHash: string;
4
+ logIndex: number;
5
+ blockNumber: bigint;
6
+ from: string;
7
+ to: string;
8
+ /** USDC in Arc's unit (6 decimals). */
9
+ amount: MinorAmount;
10
+ }
11
+ export interface FetchTransfersInput {
12
+ network: string;
13
+ merchant: string;
14
+ fromBlock: bigint;
15
+ toBlock?: bigint;
16
+ rpcUrl?: string;
17
+ }
18
+ /** Every USDC transfer into the merchant's wallet in the block range, in 9,000-block windows. */
19
+ export declare function fetchArcUsdcTransfers(input: FetchTransfersInput): Promise<ArcTransfer[]>;
20
+ /** An order as the store recorded it: amount in the catalog's unit (7 decimals). */
21
+ export interface RecordedArcPayment {
22
+ orderId: string;
23
+ txHash: string;
24
+ network: string;
25
+ amountMinor: bigint;
26
+ }
27
+ export interface ArcReconciliation {
28
+ matched: Array<{
29
+ orderId: string;
30
+ txHash: string;
31
+ }>;
32
+ /** Money in the wallet with no order: create or refund, never ignore. */
33
+ paymentsWithoutOrder: ArcTransfer[];
34
+ /** Orders marked paid that the chain does not confirm as recorded. */
35
+ ordersWithoutPayment: Array<{
36
+ orderId: string;
37
+ txHash: string;
38
+ reason: string;
39
+ }>;
40
+ }
41
+ /**
42
+ * Pure comparison, so it is testable without a network. Amounts are compared in the catalog's
43
+ * unit after an exact conversion from Arc's 6 decimals.
44
+ */
45
+ export declare function reconcileArcPayments(transfers: ReadonlyArray<ArcTransfer>, orders: ReadonlyArray<RecordedArcPayment>): ArcReconciliation;
46
+ /** A payment the merchant's wallet received, as the AgentPOS sidecar reconciles it. */
47
+ export interface ArcReceivedPayment {
48
+ txHash: string;
49
+ /** In the catalog's unit (7 decimals), converted exactly from Arc's 6. */
50
+ amountMinor: UsdcMinor;
51
+ from: string;
52
+ }
53
+ export interface ArcPaymentWatcherOptions {
54
+ network: string;
55
+ /** The merchant's own Arc wallet (public address only). */
56
+ merchant: string;
57
+ rpcUrl?: string;
58
+ /**
59
+ * How far back the first pass reads, in blocks (default 20,000: about 5 hours on Arc testnet,
60
+ * which made ~97,000 blocks a day in Oct 2026, read in 3 RPC calls). The sidecar keeps the
61
+ * payments it has seen in memory, so after a restart this window is what gets checked again.
62
+ */
63
+ lookbackBlocks?: bigint;
64
+ /** Tests only: chain head and transfer reader. */
65
+ head?: () => Promise<bigint>;
66
+ fetchTransfers?: typeof fetchArcUsdcTransfers;
67
+ }
68
+ /**
69
+ * The `PaymentWatcher` the AgentPOS sidecar takes in `x402Networks[].watcher` (D3): each call
70
+ * returns the USDC received by the merchant since the previous call, one entry per transaction.
71
+ * Read-only, no key. Pass it next to `arcResourceExtension` when the store offers Arc.
72
+ */
73
+ export declare function createArcPaymentWatcher(options: ArcPaymentWatcherOptions): {
74
+ recentPayments(): Promise<ArcReceivedPayment[]>;
75
+ };
76
+ //# sourceMappingURL=reconcile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reconcile.d.ts","sourceRoot":"","sources":["../src/reconcile.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAW7D,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,uCAAuC;IACvC,MAAM,EAAE,WAAW,CAAC;CACrB;AAED,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,iGAAiG;AACjG,wBAAsB,qBAAqB,CAAC,KAAK,EAAE,mBAAmB,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,CA4C9F;AAED,oFAAoF;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AC;CACjD,CA0CA"}
@@ -0,0 +1,160 @@
1
+ /**
2
+ * Reconciliation on Arc: what the chain says the merchant received, against what the store
3
+ * recorded. It catches the two failures that matter for money (guardrail 6):
4
+ * - a payment that reached the merchant's wallet but has no order (settled, then the store
5
+ * crashed before recording it), and
6
+ * - an order marked paid whose transaction the chain does not show, or shows with a different
7
+ * amount or recipient.
8
+ *
9
+ * Read-only: it never moves funds and needs no key. On Arc, a USDC payment emits two Transfer
10
+ * logs: the ERC-20 one from the USDC contract (6 decimals), and a mirror of the native balance
11
+ * from a system address (18 decimals). Only the ERC-20 log counts.
12
+ */
13
+ import { createPublicClient, http, parseAbiItem } from "viem";
14
+ import { AgentPOSError, rescaleMinor, USDC_DECIMALS, usdcFromMinor } from "@agentpos/core";
15
+ import { ARC_RPC_URLS, ARC_USDC, ARC_USDC_DECIMALS, isArcNetwork } from "./networks.js";
16
+ const TRANSFER = parseAbiItem("event Transfer(address indexed from, address indexed to, uint256 value)");
17
+ /** The public Arc RPC answers eth_getLogs for at most 10,000 blocks per call. */
18
+ const MAX_WINDOW = 9000n;
19
+ /** Every USDC transfer into the merchant's wallet in the block range, in 9,000-block windows. */
20
+ export async function fetchArcUsdcTransfers(input) {
21
+ if (!isArcNetwork(input.network)) {
22
+ throw new AgentPOSError("CHAIN_UNKNOWN", `'${input.network}' is not an Arc network`, {
23
+ hint: "Use eip155:5042 or eip155:5042002.",
24
+ });
25
+ }
26
+ const client = createPublicClient({
27
+ transport: http(input.rpcUrl ?? ARC_RPC_URLS[input.network]),
28
+ });
29
+ try {
30
+ // Never ask past the chain's head: the RPC refuses ranges it has not produced yet.
31
+ const head = await client.getBlockNumber();
32
+ const to = input.toBlock !== undefined && input.toBlock < head ? input.toBlock : head;
33
+ const out = [];
34
+ for (let start = input.fromBlock; start <= to; start += MAX_WINDOW + 1n) {
35
+ const end = start + MAX_WINDOW > to ? to : start + MAX_WINDOW;
36
+ const logs = await client.getLogs({
37
+ address: ARC_USDC,
38
+ event: TRANSFER,
39
+ args: { to: input.merchant },
40
+ fromBlock: start,
41
+ toBlock: end,
42
+ });
43
+ for (const log of logs) {
44
+ if (!log.transactionHash || log.args.value === undefined)
45
+ continue;
46
+ out.push({
47
+ txHash: log.transactionHash,
48
+ logIndex: log.logIndex ?? 0,
49
+ blockNumber: log.blockNumber ?? 0n,
50
+ from: log.args.from ?? "",
51
+ to: log.args.to ?? "",
52
+ amount: { minor: log.args.value, currency: "USDC", decimals: ARC_USDC_DECIMALS },
53
+ });
54
+ }
55
+ }
56
+ return out;
57
+ }
58
+ catch (cause) {
59
+ throw new AgentPOSError("RAIL_UNAVAILABLE", "Could not read Arc transfers from the RPC", {
60
+ hint: "The RPC did not answer this range; retry later or use another Arc RPC (rpcUrl).",
61
+ retryable: true,
62
+ details: { network: input.network, fromBlock: input.fromBlock.toString() },
63
+ cause,
64
+ });
65
+ }
66
+ }
67
+ /**
68
+ * Pure comparison, so it is testable without a network. Amounts are compared in the catalog's
69
+ * unit after an exact conversion from Arc's 6 decimals.
70
+ */
71
+ export function reconcileArcPayments(transfers, orders) {
72
+ const byTx = new Map();
73
+ for (const t of transfers) {
74
+ const key = t.txHash.toLowerCase();
75
+ byTx.set(key, [...(byTx.get(key) ?? []), t]);
76
+ }
77
+ const seen = new Set();
78
+ const result = {
79
+ matched: [],
80
+ paymentsWithoutOrder: [],
81
+ ordersWithoutPayment: [],
82
+ };
83
+ for (const order of orders) {
84
+ if (!isArcNetwork(order.network))
85
+ continue;
86
+ const key = order.txHash.toLowerCase();
87
+ const found = byTx.get(key);
88
+ if (!found || found.length === 0) {
89
+ result.ordersWithoutPayment.push({
90
+ orderId: order.orderId,
91
+ txHash: order.txHash,
92
+ reason: "transaction not found as a USDC transfer to the merchant",
93
+ });
94
+ continue;
95
+ }
96
+ const received = found.reduce((sum, t) => sum + t.amount.minor, 0n);
97
+ const receivedCatalog = rescaleMinor(received, ARC_USDC_DECIMALS, USDC_DECIMALS);
98
+ seen.add(key);
99
+ if (receivedCatalog !== order.amountMinor) {
100
+ result.ordersWithoutPayment.push({
101
+ orderId: order.orderId,
102
+ txHash: order.txHash,
103
+ reason: `amount differs: chain ${receivedCatalog}, order ${order.amountMinor} (catalog unit)`,
104
+ });
105
+ continue;
106
+ }
107
+ result.matched.push({ orderId: order.orderId, txHash: order.txHash });
108
+ }
109
+ for (const [key, list] of byTx)
110
+ if (!seen.has(key))
111
+ result.paymentsWithoutOrder.push(...list);
112
+ return result;
113
+ }
114
+ /**
115
+ * The `PaymentWatcher` the AgentPOS sidecar takes in `x402Networks[].watcher` (D3): each call
116
+ * returns the USDC received by the merchant since the previous call, one entry per transaction.
117
+ * Read-only, no key. Pass it next to `arcResourceExtension` when the store offers Arc.
118
+ */
119
+ export function createArcPaymentWatcher(options) {
120
+ if (!isArcNetwork(options.network)) {
121
+ throw new AgentPOSError("CHAIN_UNKNOWN", `'${options.network}' is not an Arc network`, {
122
+ hint: "Use eip155:5042 or eip155:5042002.",
123
+ });
124
+ }
125
+ const rpcUrl = options.rpcUrl ?? ARC_RPC_URLS[options.network];
126
+ const head = options.head ?? (() => createPublicClient({ transport: http(rpcUrl) }).getBlockNumber());
127
+ const fetchTransfers = options.fetchTransfers ?? fetchArcUsdcTransfers;
128
+ const lookback = options.lookbackBlocks ?? 20000n;
129
+ let next;
130
+ return {
131
+ async recentPayments() {
132
+ const to = await head();
133
+ const from = next ?? (to > lookback ? to - lookback : 0n);
134
+ if (from > to)
135
+ return [];
136
+ const transfers = await fetchTransfers({
137
+ network: options.network,
138
+ merchant: options.merchant,
139
+ fromBlock: from,
140
+ toBlock: to,
141
+ rpcUrl,
142
+ });
143
+ // Advance only after a successful read, so a failed window is read again next time.
144
+ next = to + 1n;
145
+ const byTx = new Map();
146
+ for (const t of transfers) {
147
+ const key = t.txHash.toLowerCase();
148
+ const amount = usdcFromMinor(rescaleMinor(t.amount.minor, ARC_USDC_DECIMALS, USDC_DECIMALS));
149
+ const prev = byTx.get(key);
150
+ byTx.set(key, {
151
+ txHash: key,
152
+ amountMinor: prev ? usdcFromMinor(prev.amountMinor + amount) : amount,
153
+ from: t.from,
154
+ });
155
+ }
156
+ return [...byTx.values()];
157
+ },
158
+ };
159
+ }
160
+ //# sourceMappingURL=reconcile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reconcile.js","sourceRoot":"","sources":["../src/reconcile.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,kBAAkB,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAG9D,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC3F,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAExF,MAAM,QAAQ,GAAG,YAAY,CAC3B,yEAAyE,CAC1E,CAAC;AAEF,iFAAiF;AACjF,MAAM,UAAU,GAAG,KAAM,CAAC;AAoB1B,iGAAiG;AACjG,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAC,KAA0B;IACpE,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;QACjC,MAAM,IAAI,aAAa,CAAC,eAAe,EAAE,IAAI,KAAK,CAAC,OAAO,yBAAyB,EAAE;YACnF,IAAI,EAAE,oCAAoC;SAC3C,CAAC,CAAC;IACL,CAAC;IACD,MAAM,MAAM,GAAG,kBAAkB,CAAC;QAChC,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,IAAI,YAAY,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;KAC7D,CAAC,CAAC;IACH,IAAI,CAAC;QACH,mFAAmF;QACnF,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,cAAc,EAAE,CAAC;QAC3C,MAAM,EAAE,GAAG,KAAK,CAAC,OAAO,KAAK,SAAS,IAAI,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC,CA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C,CAAC,MAAM,CAAC,KAAK,EAAE,iBAAiB,EAAE,aAAa,CAAC,CAC/D,CAAC;gBACF,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;gBAC3B,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE;oBACZ,MAAM,EAAE,GAAG;oBACX,WAAW,EAAE,IAAI,CAAC,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM;oBACrE,IAAI,EAAE,CAAC,CAAC,IAAI;iBACb,CAAC,CAAC;YACL,CAAC;YACD,OAAO,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;QAC5B,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { WalletProofVerifier } from "@agentpos/core";
2
+ export interface ArcWalletProofOptions {
3
+ /**
4
+ * RPC per network for smart-account wallets. Pass `true` to use Arc's public RPCs; omit to
5
+ * verify ordinary wallets offline only.
6
+ */
7
+ rpc?: true | Partial<Record<string, string>>;
8
+ }
9
+ export declare function createArcWalletProofVerifier(options?: ArcWalletProofOptions): WalletProofVerifier;
10
+ /** Registers the EVM verifier with the core for every eip155 network. */
11
+ export declare function registerArcWalletProof(options?: ArcWalletProofOptions): void;
12
+ //# sourceMappingURL=wallet-proof.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wallet-proof.d.ts","sourceRoot":"","sources":["../src/wallet-proof.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAM1D,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,GAAG,CAAC,EAAE,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CAC9C;AAED,wBAAgB,4BAA4B,CAC1C,OAAO,GAAE,qBAA0B,GAClC,mBAAmB,CAwBrB;AAED,yEAAyE;AACzE,wBAAgB,sBAAsB,CAAC,OAAO,GAAE,qBAA0B,GAAG,IAAI,CAEhF"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Proof that a merchant controls an Arc wallet: EIP-191 `personal_sign` over the challenge text
3
+ * issued by `createWalletChallenge` in @agentpos/core. The merchant signs in their own wallet
4
+ * (MetaMask, Rabby...); no key ever reaches AgentPOS (guardrail 1).
5
+ *
6
+ * Without an RPC the check is offline and covers ordinary wallets (EOAs). With an RPC it also
7
+ * covers smart-contract wallets, which prove control through ERC-1271 / ERC-6492, by asking
8
+ * the chain.
9
+ */
10
+ import { createPublicClient, http, verifyMessage } from "viem";
11
+ import { registerWalletProofVerifier } from "@agentpos/core";
12
+ import { ARC_RPC_URLS, isArcNetwork } from "./networks.js";
13
+ const HEX_SIG = /^0x[0-9a-fA-F]+$/;
14
+ export function createArcWalletProofVerifier(options = {}) {
15
+ return async ({ caip2, address, message, signature }) => {
16
+ if (!HEX_SIG.test(signature) || !/^0x[0-9a-fA-F]{40}$/.test(address))
17
+ return false;
18
+ const rpcUrl = options.rpc === true
19
+ ? isArcNetwork(caip2)
20
+ ? ARC_RPC_URLS[caip2]
21
+ : undefined
22
+ : options.rpc?.[caip2];
23
+ try {
24
+ if (rpcUrl) {
25
+ const client = createPublicClient({ transport: http(rpcUrl) });
26
+ return await client.verifyMessage({
27
+ address: address,
28
+ message,
29
+ signature: signature,
30
+ });
31
+ }
32
+ return await verifyMessage({ address: address, message, signature: signature });
33
+ }
34
+ catch {
35
+ // Malformed signature bytes: a wrong proof, not an outage.
36
+ return false;
37
+ }
38
+ };
39
+ }
40
+ /** Registers the EVM verifier with the core for every eip155 network. */
41
+ export function registerArcWalletProof(options = {}) {
42
+ registerWalletProofVerifier("eip155", createArcWalletProofVerifier(options));
43
+ }
44
+ //# sourceMappingURL=wallet-proof.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wallet-proof.js","sourceRoot":"","sources":["../src/wallet-proof.ts"],"names":[],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CAAC,CAAC;AACJ,CAAC;AAED,yEAAyE;AACzE,MAAM,UAAU,sBAAsB,CAAC,UAAiC,EAAE;IACxE,2BAA2B,CAAC,QAAQ,EAAE,4BAA4B,CAAC,OAAO,CAAC,CAAC,CAAC;AAC/E,CAAC"}
package/dist/x402.d.ts ADDED
@@ -0,0 +1,44 @@
1
+ import type { BuyerNetworkExtension, ExtraAccept, FacilitatorConfig, SchemeNetworkClient, UsdcMinor, X402NetworkExtension } from "@agentpos/core";
2
+ import { createArcPaymentWatcher } from "./reconcile.js";
3
+ import type { ArcPaymentWatcherOptions } from "./reconcile.js";
4
+ /** Reverse-DNS id of this rail, like `org.x402.stellar` for the core's Stellar rail. */
5
+ export declare const X402_ARC_RAIL_ID: "org.x402.arc";
6
+ export interface CircleFacilitatorOptions {
7
+ /** Facilitator base URL from Circle's docs. No default: Circle publishes it per account. */
8
+ url: string;
9
+ /** API key from console.circle.com for THIS network (testnet and mainnet keys differ). */
10
+ apiKey: string;
11
+ }
12
+ /** A facilitator config that authenticates every call with the Circle API key. */
13
+ export declare function circleFacilitator(options: CircleFacilitatorOptions): FacilitatorConfig;
14
+ /**
15
+ * The seller side: what a store passes to `createResourceServer` so its 402 also offers Arc.
16
+ * Registers the Arc networks with the core as a side effect.
17
+ */
18
+ export declare function arcResourceExtension(network: string, facilitator: CircleFacilitatorOptions): X402NetworkExtension;
19
+ /**
20
+ * The same route, payable on Arc: the catalog price converted EXACTLY to Arc's 6-decimal USDC
21
+ * (a price with a 7th decimal is refused, never rounded) and the merchant's own Arc address.
22
+ */
23
+ export declare function arcAccept(network: string, payTo: string, price: UsdcMinor): ExtraAccept;
24
+ /**
25
+ * What a store passes to the AgentPOS sidecar (`x402Networks`) to take payments on Arc: the
26
+ * resource extension, the merchant's own Arc address, the USDC asset with its EIP-712 domain,
27
+ * and a payment watcher so the sidecar reconciles the merchant's wallet against its orders (D3).
28
+ * Pass `reconcile: false` to leave the watcher out, or watcher options to tune it.
29
+ */
30
+ export declare function arcStoreNetwork(network: string, merchantAddress: string, facilitator: CircleFacilitatorOptions, reconcile?: Omit<ArcPaymentWatcherOptions, "network" | "merchant"> | false): {
31
+ extension: X402NetworkExtension;
32
+ payTo: string;
33
+ asset: string;
34
+ extra: Record<string, unknown>;
35
+ watcher?: ReturnType<typeof createArcPaymentWatcher>;
36
+ };
37
+ /**
38
+ * The buyer side: lets an agent pay on Arc within a per-payment ceiling. `client` is the
39
+ * official `ExactEvmScheme` client from `@x402/evm/exact/client`, built by the caller around
40
+ * the buyer's own signer (a viem account or a Circle agent wallet); this package never sees
41
+ * the key.
42
+ */
43
+ export declare function arcBuyerExtension(network: string, client: SchemeNetworkClient, maxPerPayment: UsdcMinor): BuyerNetworkExtension;
44
+ //# sourceMappingURL=x402.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"x402.d.ts","sourceRoot":"","sources":["../src/x402.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EACV,qBAAqB,EACrB,WAAW,EACX,iBAAiB,EAEjB,mBAAmB,EACnB,SAAS,EACT,oBAAoB,EACrB,MAAM,gBAAgB,CAAC;AAIxB,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAE/D,wFAAwF;AACxF,eAAO,MAAM,gBAAgB,EAAG,cAAuB,CAAC;AAExD,MAAM,WAAW,wBAAwB;IACvC,4FAA4F;IAC5F,GAAG,EAAE,MAAM,CAAC;IACZ,0FAA0F;IAC1F,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,kFAAkF;AAClF,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,GAAG,iBAAiB,CAiBtF;AAYD;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,wBAAwB,GACpC,oBAAoB,CAOtB;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,GAAG,WAAW,CAUvF;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,MAAM,EACf,eAAe,EAAE,MAAM,EACvB,WAAW,EAAE,wBAAwB,EACrC,SAAS,GAAE,IAAI,CAAC,wBAAwB,EAAE,SAAS,GAAG,UAAU,CAAC,GAAG,KAAU,GAC7E;IACD,SAAS,EAAE,oBAAoB,CAAC;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,OAAO,CAAC,EAAE,UAAU,CAAC,OAAO,uBAAuB,CAAC,CAAC;CACtD,CAkBA;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,mBAAmB,EAC3B,aAAa,EAAE,SAAS,GACvB,qBAAqB,CAKvB"}
package/dist/x402.js ADDED
@@ -0,0 +1,108 @@
1
+ /**
2
+ * x402 on Arc. This is the rail's protocol contact (guardrail 3, as amended 2026-10-23): it
3
+ * uses the official `@x402/evm` "exact" scheme (EIP-3009 transferWithAuthorization on USDC)
4
+ * and hands it to the core, which adds Arc to the store's 402 next to Stellar.
5
+ *
6
+ * Settlement goes through the Circle Facilitator Service, which pays the gas and moves the USDC
7
+ * from the buyer's wallet straight to the merchant's. AgentPOS never holds the funds and charges
8
+ * no commission (guardrails 1 and 7).
9
+ */
10
+ import { ExactEvmScheme as ExactEvmServerScheme } from "@x402/evm/exact/server";
11
+ import { AgentPOSError, assertAddressFor, usdcOnChain } from "@agentpos/core";
12
+ import { ARC_USDC, ARC_USDC_EIP712, isArcNetwork, registerArcNetworks } from "./networks.js";
13
+ import { createArcPaymentWatcher } from "./reconcile.js";
14
+ /** Reverse-DNS id of this rail, like `org.x402.stellar` for the core's Stellar rail. */
15
+ export const X402_ARC_RAIL_ID = "org.x402.arc";
16
+ /** A facilitator config that authenticates every call with the Circle API key. */
17
+ export function circleFacilitator(options) {
18
+ if (!/^https:\/\//.test(options.url)) {
19
+ throw new AgentPOSError("CONFIG_INVALID", "The Circle facilitator URL must be https", {
20
+ hint: "Copy the facilitator base URL from developers.circle.com/facilitator-service.",
21
+ details: { url: options.url },
22
+ });
23
+ }
24
+ if (!options.apiKey) {
25
+ throw new AgentPOSError("CONFIG_INVALID", "The Circle facilitator needs an API key", {
26
+ hint: "Create one at console.circle.com; use the testnet key for Arc testnet.",
27
+ });
28
+ }
29
+ const headers = { Authorization: `Bearer ${options.apiKey}` };
30
+ return {
31
+ url: options.url.replace(/\/+$/, ""),
32
+ createAuthHeaders: async () => ({ verify: headers, settle: headers, supported: headers }),
33
+ };
34
+ }
35
+ function requireArc(network) {
36
+ if (!isArcNetwork(network)) {
37
+ throw new AgentPOSError("CHAIN_UNKNOWN", `'${network}' is not an Arc network`, {
38
+ hint: "Use eip155:5042 (Arc mainnet) or eip155:5042002 (Arc testnet).",
39
+ details: { network },
40
+ });
41
+ }
42
+ return network;
43
+ }
44
+ /**
45
+ * The seller side: what a store passes to `createResourceServer` so its 402 also offers Arc.
46
+ * Registers the Arc networks with the core as a side effect.
47
+ */
48
+ export function arcResourceExtension(network, facilitator) {
49
+ registerArcNetworks();
50
+ return {
51
+ network: requireArc(network),
52
+ server: new ExactEvmServerScheme(),
53
+ facilitator: circleFacilitator(facilitator),
54
+ };
55
+ }
56
+ /**
57
+ * The same route, payable on Arc: the catalog price converted EXACTLY to Arc's 6-decimal USDC
58
+ * (a price with a 7th decimal is refused, never rounded) and the merchant's own Arc address.
59
+ */
60
+ export function arcAccept(network, payTo, price) {
61
+ registerArcNetworks();
62
+ const arc = requireArc(network);
63
+ return {
64
+ network: arc,
65
+ payTo: assertAddressFor(arc, payTo),
66
+ asset: ARC_USDC,
67
+ amount: usdcOnChain(price, arc),
68
+ extra: { ...ARC_USDC_EIP712 },
69
+ };
70
+ }
71
+ /**
72
+ * What a store passes to the AgentPOS sidecar (`x402Networks`) to take payments on Arc: the
73
+ * resource extension, the merchant's own Arc address, the USDC asset with its EIP-712 domain,
74
+ * and a payment watcher so the sidecar reconciles the merchant's wallet against its orders (D3).
75
+ * Pass `reconcile: false` to leave the watcher out, or watcher options to tune it.
76
+ */
77
+ export function arcStoreNetwork(network, merchantAddress, facilitator, reconcile = {}) {
78
+ const extension = arcResourceExtension(network, facilitator);
79
+ const payTo = assertAddressFor(extension.network, merchantAddress);
80
+ return {
81
+ extension,
82
+ payTo,
83
+ asset: ARC_USDC,
84
+ extra: { ...ARC_USDC_EIP712 },
85
+ ...(reconcile === false
86
+ ? {}
87
+ : {
88
+ watcher: createArcPaymentWatcher({
89
+ ...reconcile,
90
+ network: extension.network,
91
+ merchant: payTo,
92
+ }),
93
+ }),
94
+ };
95
+ }
96
+ /**
97
+ * The buyer side: lets an agent pay on Arc within a per-payment ceiling. `client` is the
98
+ * official `ExactEvmScheme` client from `@x402/evm/exact/client`, built by the caller around
99
+ * the buyer's own signer (a viem account or a Circle agent wallet); this package never sees
100
+ * the key.
101
+ */
102
+ export function arcBuyerExtension(network, client, maxPerPayment) {
103
+ registerArcNetworks();
104
+ const arc = requireArc(network);
105
+ const ceiling = usdcOnChain(maxPerPayment, arc);
106
+ return { network: arc, client, asset: ARC_USDC, maxPerPayment: ceiling };
107
+ }
108
+ //# sourceMappingURL=x402.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"x402.js","sourceRoot":"","sources":["../src/x402.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,cAAc,IAAI,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAUhF,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC9E,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAE7F,OAAO,EA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B,CAC/B,OAAe,EACf,MAA2B,EAC3B,aAAwB;IAExB,mBAAmB,EAAE,CAAC;IACtB,MAAM,GAAG,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;IAChC,MAAM,OAAO,GAAgB,WAAW,CAAC,aAAa,EAAE,GAAG,CAAC,CAAC;IAC7D,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,OAAO,EAAE,CAAC;AAC3E,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,73 @@
1
1
  {
2
2
  "name": "@agentpos/rail-arc",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "AgentPOS payment rail for Arc: x402 checkout in USDC on Circle's Arc network, settled by the Circle Facilitator Service straight to the merchant's wallet.",
5
+ "license": "Apache-2.0",
6
+ "homepage": "https://agentposhq.com",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/NovaCorpAI/agentpos-arc.git",
10
+ "directory": "packages/rail-arc"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/NovaCorpAI/agentpos-arc/issues"
14
+ },
15
+ "keywords": [
16
+ "agentpos",
17
+ "x402",
18
+ "arc",
19
+ "circle",
20
+ "usdc",
21
+ "agentic-commerce",
22
+ "payments"
23
+ ],
24
+ "type": "module",
25
+ "main": "./dist/index.js",
26
+ "types": "./dist/index.d.ts",
27
+ "exports": {
28
+ ".": {
29
+ "types": "./dist/index.d.ts",
30
+ "import": "./dist/index.js"
31
+ }
32
+ },
33
+ "files": [
34
+ "dist",
35
+ "README.md"
36
+ ],
37
+ "engines": {
38
+ "node": ">=22.5"
39
+ },
40
+ "scripts": {
41
+ "build": "tsc -p tsconfig.json",
42
+ "typecheck": "tsc -p tsconfig.typecheck.json",
43
+ "test": "vitest run",
44
+ "lint": "eslint src",
45
+ "e2e:arc-testnet": "tsx scripts/e2e-arc-testnet.ts",
46
+ "e2e:arc-woo": "tsx scripts/e2e-arc-woo.ts",
47
+ "e2e:arc-buyer": "tsx scripts/e2e-arc-buyer.ts",
48
+ "ci:wallet": "tsx scripts/ci-wallet.ts",
49
+ "buy:arc": "tsx scripts/buy-on-arc.ts"
50
+ },
51
+ "dependencies": {
52
+ "@agentpos/core": "^0.1.5",
53
+ "@x402/core": "2.28.0",
54
+ "@x402/evm": "2.28.0",
55
+ "viem": "2.57.10"
56
+ },
57
+ "devDependencies": {
58
+ "@types/node": "^24.19.2",
59
+ "typescript": "^5.9.3",
60
+ "vitest": "^4.1.11",
61
+ "@stellar/stellar-sdk": "^16.3.1",
62
+ "@agentpos/site": "^0.1.5",
63
+ "@x402/fetch": "2.28.0",
64
+ "tsx": "^4.20.6",
65
+ "@agentpos/connectors": "^0.1.5",
66
+ "@agentpos/mcp-buyer": "^0.1.5",
67
+ "@agentpos/scanner": "^0.1.5"
68
+ },
69
+ "publishConfig": {
70
+ "access": "public",
71
+ "provenance": true
72
+ }
73
+ }