open-agentpay 0.0.0-stage → 0.2.5

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.
Files changed (131) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +133 -2
  3. package/dist/client/client.d.ts +37 -0
  4. package/dist/client/client.d.ts.map +1 -0
  5. package/dist/client/client.js +90 -0
  6. package/dist/client/client.js.map +1 -0
  7. package/dist/client/errors.d.ts +23 -0
  8. package/dist/client/errors.d.ts.map +1 -0
  9. package/dist/client/errors.js +38 -0
  10. package/dist/client/errors.js.map +1 -0
  11. package/dist/client/index.d.ts +6 -0
  12. package/dist/client/index.d.ts.map +1 -0
  13. package/dist/client/index.js +6 -0
  14. package/dist/client/index.js.map +1 -0
  15. package/dist/client/interfaces.d.ts +34 -0
  16. package/dist/client/interfaces.d.ts.map +1 -0
  17. package/dist/client/interfaces.js +5 -0
  18. package/dist/client/interfaces.js.map +1 -0
  19. package/dist/client/signer.d.ts +136 -0
  20. package/dist/client/signer.d.ts.map +1 -0
  21. package/dist/client/signer.js +300 -0
  22. package/dist/client/signer.js.map +1 -0
  23. package/dist/client/transport.d.ts +44 -0
  24. package/dist/client/transport.d.ts.map +1 -0
  25. package/dist/client/transport.js +389 -0
  26. package/dist/client/transport.js.map +1 -0
  27. package/dist/core/codecs.d.ts +35 -0
  28. package/dist/core/codecs.d.ts.map +1 -0
  29. package/dist/core/codecs.js +177 -0
  30. package/dist/core/codecs.js.map +1 -0
  31. package/dist/core/errors.d.ts +33 -0
  32. package/dist/core/errors.d.ts.map +1 -0
  33. package/dist/core/errors.js +48 -0
  34. package/dist/core/errors.js.map +1 -0
  35. package/dist/core/index.d.ts +6 -0
  36. package/dist/core/index.d.ts.map +1 -0
  37. package/dist/core/index.js +6 -0
  38. package/dist/core/index.js.map +1 -0
  39. package/dist/core/interop.d.ts +10 -0
  40. package/dist/core/interop.d.ts.map +1 -0
  41. package/dist/core/interop.js +28 -0
  42. package/dist/core/interop.js.map +1 -0
  43. package/dist/core/models.d.ts +155 -0
  44. package/dist/core/models.d.ts.map +1 -0
  45. package/dist/core/models.js +463 -0
  46. package/dist/core/models.js.map +1 -0
  47. package/dist/core/state.d.ts +82 -0
  48. package/dist/core/state.d.ts.map +1 -0
  49. package/dist/core/state.js +87 -0
  50. package/dist/core/state.js.map +1 -0
  51. package/dist/evm/constants.d.ts +52 -0
  52. package/dist/evm/constants.d.ts.map +1 -0
  53. package/dist/evm/constants.js +72 -0
  54. package/dist/evm/constants.js.map +1 -0
  55. package/dist/evm/eip3009.d.ts +43 -0
  56. package/dist/evm/eip3009.d.ts.map +1 -0
  57. package/dist/evm/eip3009.js +145 -0
  58. package/dist/evm/eip3009.js.map +1 -0
  59. package/dist/evm/index.d.ts +3 -0
  60. package/dist/evm/index.d.ts.map +1 -0
  61. package/dist/evm/index.js +3 -0
  62. package/dist/evm/index.js.map +1 -0
  63. package/dist/index.d.ts +12 -0
  64. package/dist/index.d.ts.map +1 -0
  65. package/dist/index.js +12 -0
  66. package/dist/index.js.map +1 -0
  67. package/dist/integrations/index.d.ts +4 -0
  68. package/dist/integrations/index.d.ts.map +1 -0
  69. package/dist/integrations/index.js +4 -0
  70. package/dist/integrations/index.js.map +1 -0
  71. package/dist/integrations/langchain.d.ts +40 -0
  72. package/dist/integrations/langchain.d.ts.map +1 -0
  73. package/dist/integrations/langchain.js +68 -0
  74. package/dist/integrations/langchain.js.map +1 -0
  75. package/dist/integrations/mcp.d.ts +29 -0
  76. package/dist/integrations/mcp.d.ts.map +1 -0
  77. package/dist/integrations/mcp.js +73 -0
  78. package/dist/integrations/mcp.js.map +1 -0
  79. package/dist/integrations/vercel-ai.d.ts +31 -0
  80. package/dist/integrations/vercel-ai.d.ts.map +1 -0
  81. package/dist/integrations/vercel-ai.js +50 -0
  82. package/dist/integrations/vercel-ai.js.map +1 -0
  83. package/dist/policy/db.d.ts +14 -0
  84. package/dist/policy/db.d.ts.map +1 -0
  85. package/dist/policy/db.js +86 -0
  86. package/dist/policy/db.js.map +1 -0
  87. package/dist/policy/errors.d.ts +31 -0
  88. package/dist/policy/errors.d.ts.map +1 -0
  89. package/dist/policy/errors.js +48 -0
  90. package/dist/policy/errors.js.map +1 -0
  91. package/dist/policy/evaluator.d.ts +22 -0
  92. package/dist/policy/evaluator.d.ts.map +1 -0
  93. package/dist/policy/evaluator.js +152 -0
  94. package/dist/policy/evaluator.js.map +1 -0
  95. package/dist/policy/index.d.ts +7 -0
  96. package/dist/policy/index.d.ts.map +1 -0
  97. package/dist/policy/index.js +7 -0
  98. package/dist/policy/index.js.map +1 -0
  99. package/dist/policy/interfaces.d.ts +59 -0
  100. package/dist/policy/interfaces.d.ts.map +1 -0
  101. package/dist/policy/interfaces.js +7 -0
  102. package/dist/policy/interfaces.js.map +1 -0
  103. package/dist/policy/models.d.ts +161 -0
  104. package/dist/policy/models.d.ts.map +1 -0
  105. package/dist/policy/models.js +449 -0
  106. package/dist/policy/models.js.map +1 -0
  107. package/dist/policy/sqlite-engine.d.ts +28 -0
  108. package/dist/policy/sqlite-engine.d.ts.map +1 -0
  109. package/dist/policy/sqlite-engine.js +501 -0
  110. package/dist/policy/sqlite-engine.js.map +1 -0
  111. package/dist/state/buyer-coordinator.d.ts +33 -0
  112. package/dist/state/buyer-coordinator.d.ts.map +1 -0
  113. package/dist/state/buyer-coordinator.js +363 -0
  114. package/dist/state/buyer-coordinator.js.map +1 -0
  115. package/dist/state/errors.d.ts +45 -0
  116. package/dist/state/errors.d.ts.map +1 -0
  117. package/dist/state/errors.js +88 -0
  118. package/dist/state/errors.js.map +1 -0
  119. package/dist/state/guards.d.ts +24 -0
  120. package/dist/state/guards.d.ts.map +1 -0
  121. package/dist/state/guards.js +211 -0
  122. package/dist/state/guards.js.map +1 -0
  123. package/dist/state/index.d.ts +5 -0
  124. package/dist/state/index.d.ts.map +1 -0
  125. package/dist/state/index.js +5 -0
  126. package/dist/state/index.js.map +1 -0
  127. package/dist/state/reconciliation.d.ts +105 -0
  128. package/dist/state/reconciliation.d.ts.map +1 -0
  129. package/dist/state/reconciliation.js +297 -0
  130. package/dist/state/reconciliation.js.map +1 -0
  131. package/package.json +112 -4
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or exemplary damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 AgentPay Contributors
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,134 @@
1
- # Temporary Holding Version
1
+ # open-agentpay
2
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.
3
+ > **The Open-Source Financial Firewall & Micro-Payment Infrastructure for Autonomous AI Agents (TypeScript / Node.js SDK)**
4
+
5
+ [![npm version](https://img.shields.io/npm/v/open-agentpay.svg)](https://www.npmjs.com/package/open-agentpay)
6
+ [![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
7
+ [![Documentation](https://img.shields.io/badge/Docs-Live-blue)](https://openagentpay.dev/)
8
+
9
+ `open-agentpay` provides autonomous AI agents with non-custodial financial guardrails, automated **HTTP 402 Payment Required** negotiation, and zero-gas offline cryptographic authorizations (EIP-712 / EIP-3009 transfer with authorization) in native TypeScript.
10
+
11
+ ---
12
+
13
+ ## ⚡ Features
14
+
15
+ - 🛡️ **Non-Custodial Financial Firewall**: Local SQLite-backed circuit breakers, 24h rolling budget enforcement, and strict whitelist matrix (EVM networks, token assets, payee addresses, domains).
16
+ - 🔄 **Transparent 402 Payment Interceptor**: `AgentPayClient` and `createAgentPayFetch` automatically intercept HTTP 402 challenges, evaluate local policies, sign authorizations, and replay requests.
17
+ - 🔐 **Pre-Signing Safety Guardrails**: Zero custom cryptography (backed strictly by `viem`), automated private key redaction, and strict reservation binding before signing.
18
+ - 🔒 **Post-Dispatch Wire Safety**: Once a payment signature is transmitted on the wire, upstream 5xx errors or network timeouts never release budget quotas prematurely; automated 3-state reconciler safely unlocks after on-chain expiration.
19
+ - 🤖 **AI Framework Ecosystem Native**: Drop-in tool wrappers for **LangChain.js** (`@langchain/core`), **Vercel AI SDK** (`ai`), and **Model Context Protocol** (`@modelcontextprotocol/sdk`).
20
+
21
+ ---
22
+
23
+ ## 📦 Installation
24
+
25
+ ```bash
26
+ npm install open-agentpay
27
+ # or
28
+ pnpm add open-agentpay
29
+ # or
30
+ yarn add open-agentpay
31
+ ```
32
+
33
+ ---
34
+
35
+ ## 🚀 5-Minute Quickstart
36
+
37
+ ```typescript
38
+ import { AgentPayClient, LocalSigner } from 'open-agentpay';
39
+ import { PolicyConfig, SQLitePolicyEngine, WhitelistMode } from 'open-agentpay/policy';
40
+
41
+ // 1. Initialize local non-custodial signer (no gas fees paid by buyer)
42
+ // Provide your 32-byte hex EVM private key via environment variable
43
+ const privateKey = process.env.AGENT_WALLET_KEY ?? '0xYOUR_EVM_PRIVATE_KEY';
44
+ const signer = new LocalSigner(privateKey);
45
+
46
+ // 2. Configure local SQLite budget policy & circuit breaker
47
+ const policy = SQLitePolicyEngine.createInMemory(
48
+ new PolicyConfig({
49
+ id: 'agent_firewall',
50
+ name: 'Agent Production Firewall',
51
+ walletAddress: signer.address,
52
+ whitelistMode: WhitelistMode.SIMPLE,
53
+ maxPerTxBaseUnits: 2_500_000n, // Max 2.50 USDC per transaction
54
+ rollingBudget24hBaseUnits: 5_000_000n, // Max 5.00 USDC per 24 hours
55
+ })
56
+ );
57
+
58
+ // 3. Create client with automatic 402 handshake & payment retry
59
+ const client = new AgentPayClient({ signer, policy });
60
+
61
+ // 4. Request paid API endpoint directly
62
+ const response = await client.get('https://gate.openagentpay.dev/v1/free/defi/dex-volume', {
63
+ params: {
64
+ chain: 'ethereum',
65
+ excludeTotalDataChart: true,
66
+ },
67
+ });
68
+
69
+ console.log('HTTP Status:', response.status); // 200 OK!
70
+ const data = await response.json();
71
+ console.log('Result:', data);
72
+ ```
73
+
74
+ ---
75
+
76
+ ## 🤖 AI Integrations
77
+
78
+ ### LangChain.js
79
+
80
+ ```typescript
81
+ import { createPaidTool } from 'open-agentpay/langchain';
82
+
83
+ const paidTool = createPaidTool({
84
+ name: 'market_data_oracle',
85
+ description: 'Query paid market volume data',
86
+ client,
87
+ func: async (args: { chain: string }, context) => {
88
+ const res = await context!.client!.get('https://gate.openagentpay.dev/v1/free/defi/dex-volume', {
89
+ params: { chain: args.chain },
90
+ });
91
+ return await res.json();
92
+ },
93
+ });
94
+ ```
95
+
96
+ ### Vercel AI SDK
97
+
98
+ ```typescript
99
+ import { paidVercelTool } from 'open-agentpay/vercel-ai';
100
+ import { z } from 'zod';
101
+
102
+ const marketTool = paidVercelTool({
103
+ description: 'Fetch DEX market data with financial firewall protection',
104
+ parameters: z.object({ chain: z.string() }),
105
+ client,
106
+ execute: async ({ chain }, context) => {
107
+ const res = await context!.client!.get('https://gate.openagentpay.dev/v1/free/defi/dex-volume', {
108
+ params: { chain },
109
+ });
110
+ return await res.json();
111
+ },
112
+ });
113
+ ```
114
+
115
+ ### Model Context Protocol (MCP)
116
+
117
+ ```typescript
118
+ import { createPaidMcpFetch, createPaidMcpToolHandler } from 'open-agentpay/mcp';
119
+
120
+ // Wrap MCP Server tool handlers
121
+ const mcpHandler = createPaidMcpToolHandler(client, async (args, context) => {
122
+ const res = await context!.client.get('https://api.example.com/paid-resource');
123
+ return await res.json();
124
+ });
125
+
126
+ // Or use drop-in fetch for MCP Client transports
127
+ const mcpFetch = createPaidMcpFetch(client);
128
+ ```
129
+
130
+ ---
131
+
132
+ ## 📄 License
133
+
134
+ Apache-2.0 License. See [LICENSE](https://github.com/july-whj/AgentPay/blob/main/LICENSE) for details.
@@ -0,0 +1,37 @@
1
+ /**
2
+ * AgentPayClient: HTTP Client with automatic 402 payment negotiation and financial firewall.
3
+ */
4
+ import type { IPolicyEngine } from '../policy/interfaces.js';
5
+ import type { ISigner } from './interfaces.js';
6
+ import { AgentPayTransport, type AgentPayClientOptions, type AgentPayRequestInit } from './transport.js';
7
+ export declare class AgentPayClient {
8
+ readonly signer: ISigner;
9
+ readonly policy: IPolicyEngine;
10
+ readonly transport: AgentPayTransport;
11
+ constructor(options: AgentPayClientOptions);
12
+ /**
13
+ * Return a fetch function bound to this client's payment interceptor.
14
+ */
15
+ asFetch(): typeof globalThis.fetch;
16
+ /**
17
+ * Dispatch an HTTP request through the AgentPay interceptor.
18
+ */
19
+ request(input: string | URL | Request, init?: AgentPayRequestInit): Promise<Response>;
20
+ /**
21
+ * Dispatch a GET request.
22
+ */
23
+ get(url: string | URL, init?: AgentPayRequestInit): Promise<Response>;
24
+ /**
25
+ * Dispatch a POST request with automatic JSON body encoding.
26
+ */
27
+ post(url: string | URL, body?: BodyInit | Record<string, unknown> | null, init?: AgentPayRequestInit): Promise<Response>;
28
+ /**
29
+ * Dispatch a PUT request with automatic JSON body encoding.
30
+ */
31
+ put(url: string | URL, body?: BodyInit | Record<string, unknown> | null, init?: AgentPayRequestInit): Promise<Response>;
32
+ /**
33
+ * Dispatch a DELETE request.
34
+ */
35
+ delete(url: string | URL, init?: AgentPayRequestInit): Promise<Response>;
36
+ }
37
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,KAAK,qBAAqB,EAAE,KAAK,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAEzG,qBAAa,cAAc;IACzB,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;IAC/B,QAAQ,CAAC,SAAS,EAAE,iBAAiB,CAAC;gBAE1B,OAAO,EAAE,qBAAqB;IAM1C;;OAEG;IACI,OAAO,IAAI,OAAO,UAAU,CAAC,KAAK;IAKzC;;OAEG;IACI,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG,GAAG,OAAO,EAAE,IAAI,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,QAAQ,CAAC;IAI5F;;OAEG;IACI,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,EAAE,IAAI,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,QAAQ,CAAC;IAI5E;;OAEG;IACI,IAAI,CACT,GAAG,EAAE,MAAM,GAAG,GAAG,EACjB,IAAI,CAAC,EAAE,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,EAChD,IAAI,CAAC,EAAE,mBAAmB,GACzB,OAAO,CAAC,QAAQ,CAAC;IA0BpB;;OAEG;IACI,GAAG,CACR,GAAG,EAAE,MAAM,GAAG,GAAG,EACjB,IAAI,CAAC,EAAE,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,EAChD,IAAI,CAAC,EAAE,mBAAmB,GACzB,OAAO,CAAC,QAAQ,CAAC;IA0BpB;;OAEG;IACI,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,EAAE,IAAI,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,QAAQ,CAAC;CAGhF"}
@@ -0,0 +1,90 @@
1
+ /**
2
+ * AgentPayClient: HTTP Client with automatic 402 payment negotiation and financial firewall.
3
+ */
4
+ import { AgentPayTransport } from './transport.js';
5
+ export class AgentPayClient {
6
+ signer;
7
+ policy;
8
+ transport;
9
+ constructor(options) {
10
+ this.signer = options.signer;
11
+ this.policy = options.policy;
12
+ this.transport = new AgentPayTransport(options);
13
+ }
14
+ /**
15
+ * Return a fetch function bound to this client's payment interceptor.
16
+ */
17
+ asFetch() {
18
+ const fetchFn = (input, init) => this.transport.fetch(input, init);
19
+ return fetchFn;
20
+ }
21
+ /**
22
+ * Dispatch an HTTP request through the AgentPay interceptor.
23
+ */
24
+ request(input, init) {
25
+ return this.transport.fetch(input, init);
26
+ }
27
+ /**
28
+ * Dispatch a GET request.
29
+ */
30
+ get(url, init) {
31
+ return this.request(url, { ...init, method: 'GET' });
32
+ }
33
+ /**
34
+ * Dispatch a POST request with automatic JSON body encoding.
35
+ */
36
+ post(url, body, init) {
37
+ const { headers: initialHeaders, ...restInit } = init ?? {};
38
+ const headers = new Headers(initialHeaders);
39
+ let finalBody;
40
+ if (body !== undefined && body !== null) {
41
+ if (typeof body === 'object' &&
42
+ !(body instanceof Uint8Array) &&
43
+ !(body instanceof ArrayBuffer) &&
44
+ !(body instanceof Blob) &&
45
+ !(body instanceof FormData) &&
46
+ !(body instanceof URLSearchParams)) {
47
+ finalBody = JSON.stringify(body);
48
+ if (!headers.has('content-type')) {
49
+ headers.set('content-type', 'application/json');
50
+ }
51
+ }
52
+ else {
53
+ finalBody = body;
54
+ }
55
+ }
56
+ return this.request(url, { ...restInit, method: 'POST', headers, body: finalBody });
57
+ }
58
+ /**
59
+ * Dispatch a PUT request with automatic JSON body encoding.
60
+ */
61
+ put(url, body, init) {
62
+ const { headers: initialHeaders, ...restInit } = init ?? {};
63
+ const headers = new Headers(initialHeaders);
64
+ let finalBody;
65
+ if (body !== undefined && body !== null) {
66
+ if (typeof body === 'object' &&
67
+ !(body instanceof Uint8Array) &&
68
+ !(body instanceof ArrayBuffer) &&
69
+ !(body instanceof Blob) &&
70
+ !(body instanceof FormData) &&
71
+ !(body instanceof URLSearchParams)) {
72
+ finalBody = JSON.stringify(body);
73
+ if (!headers.has('content-type')) {
74
+ headers.set('content-type', 'application/json');
75
+ }
76
+ }
77
+ else {
78
+ finalBody = body;
79
+ }
80
+ }
81
+ return this.request(url, { ...restInit, method: 'PUT', headers, body: finalBody });
82
+ }
83
+ /**
84
+ * Dispatch a DELETE request.
85
+ */
86
+ delete(url, init) {
87
+ return this.request(url, { ...init, method: 'DELETE' });
88
+ }
89
+ }
90
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client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Ae,CAAC,EAClC,CAAC;gBACD,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;gBACjC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE,CAAC;oBACjC,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,kBAAkB,CAAC,CAAC;gBAClD,CAAC;YACH,CAAC;iBAAM,CAAC;gBACN,SAAS,GAAG,IAAgB,CAAC;YAC/B,CAAC;QACH,CAAC;QAED,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,GAAG,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;IACrF,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,GAAiB,EAAE,IAA0B;QACzD,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,GAAG,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;IAC1D,CAAC;CACF"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Signer and Client Exceptions for AgentPay.
3
+ */
4
+ export declare class ClientError extends Error {
5
+ constructor(message: string);
6
+ }
7
+ export declare class SignerError extends ClientError {
8
+ constructor(message: string);
9
+ }
10
+ export declare class InvalidPrivateKeyError extends SignerError {
11
+ constructor(message: string);
12
+ }
13
+ export declare class UnsupportedNetworkError extends SignerError {
14
+ constructor(message: string);
15
+ }
16
+ export declare class ReservationMismatchError extends SignerError {
17
+ /**
18
+ * Raised when an approved ReservationToken does not match the PaymentChallenge.
19
+ * Critical financial firewall guardrail violation.
20
+ */
21
+ constructor(message: string);
22
+ }
23
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/client/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,qBAAa,WAAY,SAAQ,KAAK;gBACxB,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,WAAY,SAAQ,WAAW;gBAC9B,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,sBAAuB,SAAQ,WAAW;gBACzC,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,uBAAwB,SAAQ,WAAW;gBAC1C,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,wBAAyB,SAAQ,WAAW;IACvD;;;OAGG;gBACS,OAAO,EAAE,MAAM;CAI5B"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Signer and Client Exceptions for AgentPay.
3
+ */
4
+ export class ClientError extends Error {
5
+ constructor(message) {
6
+ super(message);
7
+ this.name = 'ClientError';
8
+ }
9
+ }
10
+ export class SignerError extends ClientError {
11
+ constructor(message) {
12
+ super(message);
13
+ this.name = 'SignerError';
14
+ }
15
+ }
16
+ export class InvalidPrivateKeyError extends SignerError {
17
+ constructor(message) {
18
+ super(message);
19
+ this.name = 'InvalidPrivateKeyError';
20
+ }
21
+ }
22
+ export class UnsupportedNetworkError extends SignerError {
23
+ constructor(message) {
24
+ super(message);
25
+ this.name = 'UnsupportedNetworkError';
26
+ }
27
+ }
28
+ export class ReservationMismatchError extends SignerError {
29
+ /**
30
+ * Raised when an approved ReservationToken does not match the PaymentChallenge.
31
+ * Critical financial firewall guardrail violation.
32
+ */
33
+ constructor(message) {
34
+ super(message);
35
+ this.name = 'ReservationMismatchError';
36
+ }
37
+ }
38
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/client/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,OAAO,WAAY,SAAQ,KAAK;IACpC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;IAC5B,CAAC;CACF;AAED,MAAM,OAAO,WAAY,SAAQ,WAAW;IAC1C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;IAC5B,CAAC;CACF;AAED,MAAM,OAAO,sBAAuB,SAAQ,WAAW;IACrD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;IACvC,CAAC;CACF;AAED,MAAM,OAAO,uBAAwB,SAAQ,WAAW;IACtD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;IACxC,CAAC;CACF;AAED,MAAM,OAAO,wBAAyB,SAAQ,WAAW;IACvD;;;OAGG;IACH,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;IACzC,CAAC;CACF"}
@@ -0,0 +1,6 @@
1
+ export * from './errors.js';
2
+ export * from './interfaces.js';
3
+ export * from './signer.js';
4
+ export * from './transport.js';
5
+ export * from './client.js';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC"}
@@ -0,0 +1,6 @@
1
+ export * from './errors.js';
2
+ export * from './interfaces.js';
3
+ export * from './signer.js';
4
+ export * from './transport.js';
5
+ export * from './client.js';
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Signer interface protocols for AgentPay.
3
+ */
4
+ import type { PaymentAuthorization, PaymentChallenge } from '../core/models.js';
5
+ import type { ReservationToken } from '../policy/models.js';
6
+ export interface SignAuthorizationOptions {
7
+ nonce?: `0x${string}` | string;
8
+ tokenName?: string;
9
+ tokenVersion?: string;
10
+ }
11
+ /**
12
+ * Protocol for signing agents and cryptographic keystores.
13
+ * Enforces firewall reservation binding before signing.
14
+ */
15
+ export interface ISigner {
16
+ /**
17
+ * The canonical lowercase EVM address of the signing wallet.
18
+ */
19
+ readonly address: `0x${string}`;
20
+ /**
21
+ * Sign an EIP-712/3009 transfer authorization for the given challenge.
22
+ *
23
+ * MUST verify that the reservation matches the challenge before signing.
24
+ *
25
+ * @param challenge The PaymentChallenge from the 402 PAYMENT-REQUIRED header.
26
+ * @param reservation The Approved ReservationToken from the policy engine.
27
+ * @param options Optional signing options (nonce, tokenName, tokenVersion).
28
+ * @returns PaymentAuthorization populated with cryptographic signature.
29
+ * @throws ReservationMismatchError If the reservation does not match the challenge.
30
+ * @throws SignerError If cryptographic signing fails.
31
+ */
32
+ signPaymentAuthorization(challenge: PaymentChallenge, reservation: ReservationToken, options?: SignAuthorizationOptions): Promise<PaymentAuthorization>;
33
+ }
34
+ //# sourceMappingURL=interfaces.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../src/client/interfaces.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAChF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE5D,MAAM,WAAW,wBAAwB;IACvC,KAAK,CAAC,EAAE,KAAK,MAAM,EAAE,GAAG,MAAM,CAAC;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;GAGG;AACH,MAAM,WAAW,OAAO;IACtB;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,KAAK,MAAM,EAAE,CAAC;IAEhC;;;;;;;;;;;OAWG;IACH,wBAAwB,CACtB,SAAS,EAAE,gBAAgB,EAC3B,WAAW,EAAE,gBAAgB,EAC7B,OAAO,CAAC,EAAE,wBAAwB,GACjC,OAAO,CAAC,oBAAoB,CAAC,CAAC;CAClC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Signer interface protocols for AgentPay.
3
+ */
4
+ export {};
5
+ //# sourceMappingURL=interfaces.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../src/client/interfaces.ts"],"names":[],"mappings":"AAAA;;GAEG"}