zeambridge 2.0.0__tar.gz
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.
- zeambridge-2.0.0/LICENSE +202 -0
- zeambridge-2.0.0/MANIFEST.in +2 -0
- zeambridge-2.0.0/NOTICE +4 -0
- zeambridge-2.0.0/PKG-INFO +344 -0
- zeambridge-2.0.0/README.md +316 -0
- zeambridge-2.0.0/examples/server.py +43 -0
- zeambridge-2.0.0/pyproject.toml +41 -0
- zeambridge-2.0.0/setup.cfg +4 -0
- zeambridge-2.0.0/zeam_bridge/__init__.py +1233 -0
- zeambridge-2.0.0/zeam_bridge/engine/__init__.py +5 -0
- zeambridge-2.0.0/zeam_bridge/engine/abi.py +266 -0
- zeambridge-2.0.0/zeam_bridge/engine/batch_settlement.py +334 -0
- zeambridge-2.0.0/zeam_bridge/engine/bazaar.py +115 -0
- zeambridge-2.0.0/zeam_bridge/engine/core.py +285 -0
- zeambridge-2.0.0/zeam_bridge/engine/discovery.py +76 -0
- zeambridge-2.0.0/zeam_bridge/engine/env.py +27 -0
- zeambridge-2.0.0/zeam_bridge/engine/files.py +82 -0
- zeambridge-2.0.0/zeam_bridge/engine/gate/__init__.py +9 -0
- zeambridge-2.0.0/zeam_bridge/engine/gate/admission.py +152 -0
- zeambridge-2.0.0/zeam_bridge/engine/gate/credits.py +159 -0
- zeambridge-2.0.0/zeam_bridge/engine/gate/exact.py +189 -0
- zeambridge-2.0.0/zeam_bridge/engine/gate/http.py +17 -0
- zeambridge-2.0.0/zeam_bridge/engine/gate/jsonx.py +121 -0
- zeambridge-2.0.0/zeam_bridge/engine/gate/meter.py +92 -0
- zeambridge-2.0.0/zeam_bridge/engine/gate/store.py +48 -0
- zeambridge-2.0.0/zeam_bridge/engine/keys.py +131 -0
- zeambridge-2.0.0/zeam_bridge/engine/messages.py +111 -0
- zeambridge-2.0.0/zeam_bridge/engine/meter.py +563 -0
- zeambridge-2.0.0/zeam_bridge/engine/php.py +157 -0
- zeambridge-2.0.0/zeam_bridge/engine/pricing.py +282 -0
- zeambridge-2.0.0/zeam_bridge/engine/rpc.py +74 -0
- zeambridge-2.0.0/zeam_bridge/engine/runtime.py +684 -0
- zeambridge-2.0.0/zeam_bridge/engine/settlement/__init__.py +18 -0
- zeambridge-2.0.0/zeam_bridge/engine/settlement/cache.py +82 -0
- zeambridge-2.0.0/zeam_bridge/engine/settlement/chain.py +97 -0
- zeambridge-2.0.0/zeam_bridge/engine/settlement/channels.py +342 -0
- zeambridge-2.0.0/zeam_bridge/engine/settlement/claims.py +159 -0
- zeambridge-2.0.0/zeam_bridge/engine/settlement/config.py +193 -0
- zeambridge-2.0.0/zeam_bridge/engine/settlement/gas_quote.py +147 -0
- zeambridge-2.0.0/zeam_bridge/engine/settlement/jsonx.py +70 -0
- zeambridge-2.0.0/zeam_bridge/engine/settlement/mpp.py +505 -0
- zeambridge-2.0.0/zeam_bridge/engine/settlement/payout.py +52 -0
- zeambridge-2.0.0/zeam_bridge/engine/settlement/reason.py +33 -0
- zeambridge-2.0.0/zeam_bridge/engine/settlement/refunds.py +780 -0
- zeambridge-2.0.0/zeam_bridge/engine/settlement/relay.py +172 -0
- zeambridge-2.0.0/zeam_bridge/engine/settlement/server.py +924 -0
- zeambridge-2.0.0/zeam_bridge/engine/settlement/store.py +184 -0
- zeambridge-2.0.0/zeam_bridge/engine/settlement/verify.py +450 -0
- zeambridge-2.0.0/zeam_bridge/engine/settlement/withdrawals.py +44 -0
- zeambridge-2.0.0/zeam_bridge/engine/splits.py +116 -0
- zeambridge-2.0.0/zeam_bridge/engine/typed_data.py +88 -0
- zeambridge-2.0.0/zeam_bridge/engine/wire.py +9 -0
- zeambridge-2.0.0/zeam_bridge/grants.py +68 -0
- zeambridge-2.0.0/zeam_bridge/old_name.py +14 -0
- zeambridge-2.0.0/zeam_pass/__init__.py +5 -0
- zeambridge-2.0.0/zeam_pass.py +5 -0
- zeambridge-2.0.0/zeambridge.egg-info/PKG-INFO +344 -0
- zeambridge-2.0.0/zeambridge.egg-info/SOURCES.txt +59 -0
- zeambridge-2.0.0/zeambridge.egg-info/dependency_links.txt +1 -0
- zeambridge-2.0.0/zeambridge.egg-info/requires.txt +2 -0
- zeambridge-2.0.0/zeambridge.egg-info/top_level.txt +2 -0
zeambridge-2.0.0/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.
|
zeambridge-2.0.0/NOTICE
ADDED
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: zeambridge
|
|
3
|
+
Version: 2.0.0
|
|
4
|
+
Summary: ZEAM :: Bridge for your own server: a paywall (x402 and MPP; you keep 90.01%), a key gate, or both, for your MCP and HTTP tools. Runs in your process with your keys.
|
|
5
|
+
Author-email: "ZEAM Labs, LLC" <info@zeamlabs.com>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://zeambridge.com
|
|
8
|
+
Project-URL: Source, https://github.com/zeam-labs/pass
|
|
9
|
+
Keywords: x402,mpp,mcp,agents,paywall,gate,batch-settlement,usdc,base
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
|
|
21
|
+
Requires-Python: >=3.9
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
License-File: NOTICE
|
|
25
|
+
Requires-Dist: coincurve<22,>=20
|
|
26
|
+
Requires-Dist: pycryptodome<4,>=3.19
|
|
27
|
+
Dynamic: license-file
|
|
28
|
+
|
|
29
|
+
# zeambridge (Python)
|
|
30
|
+
|
|
31
|
+
ZEAM :: Bridge for your own server. Define your tools once; agents pay per call over MCP and HTTP on your domain, by x402 or MPP.
|
|
32
|
+
The Bridge engine runs in your process: keys, channel records, gate usage and settlement stay on your server. ZEAM runs
|
|
33
|
+
the relay (gas for transactions that cover their own gas) and the credit service (gate checks). You keep 90.01% of
|
|
34
|
+
every sale, paid to your own split.
|
|
35
|
+
|
|
36
|
+
Source: https://github.com/zeam-labs/pass
|
|
37
|
+
|
|
38
|
+
License: Apache-2.0. Patent pending.
|
|
39
|
+
|
|
40
|
+
## Install
|
|
41
|
+
|
|
42
|
+
Published: `pip install zeambridge` (Python ≥3.9).
|
|
43
|
+
Until 1.0.9 this package was `zeam-pass`: change the requirement to `zeambridge`; `import zeam_pass` and `Pass` keep working.
|
|
44
|
+
Dependencies: `coincurve` (libsecp256k1, signing) and `pycryptodome` (Keccak, key sealing).
|
|
45
|
+
|
|
46
|
+
## Start
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
from zeam_bridge import Bridge
|
|
50
|
+
|
|
51
|
+
agents = Bridge(name="acme", payout="0xYourWalletAddress", price="0.01")
|
|
52
|
+
|
|
53
|
+
@agents.tool(
|
|
54
|
+
description="A price for a symbol.",
|
|
55
|
+
input_schema={
|
|
56
|
+
"type": "object",
|
|
57
|
+
"properties": {"symbol": {"type": "string"}},
|
|
58
|
+
"required": ["symbol"],
|
|
59
|
+
},
|
|
60
|
+
)
|
|
61
|
+
def quote(symbol):
|
|
62
|
+
return {"symbol": symbol, "price": lookup(symbol)}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
FastAPI / Starlette:
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
app.mount("/agents", agents.asgi())
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Flask (`pip install flask`; werkzeug comes with it):
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
from werkzeug.middleware.dispatcher import DispatcherMiddleware
|
|
75
|
+
|
|
76
|
+
app.wsgi_app = DispatcherMiddleware(app.wsgi_app, {"/agents": agents.wsgi()})
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Replace `0xYourWalletAddress`: `payout` is a wallet address on Base that you control, and your earnings are paid to
|
|
80
|
+
it. `Bridge()` raises `ValueError` on a placeholder. Replace `acme` with your own `name` as well: it fixes your split's address.
|
|
81
|
+
|
|
82
|
+
Routes: `/agents/mcp` (MCP; payment in the tool call's `_meta`), `POST /agents/v1/<tool>` (x402 or MPP headers),
|
|
83
|
+
`/agents/openapi.json` and `/agents/refund`, with CORS. Django mounts `agents.wsgi()` or `agents.asgi()` the same
|
|
84
|
+
way. `examples/server.py` is a whole server on the standard library. `pip install` does not put it on disk: it is in
|
|
85
|
+
the source distribution and at https://github.com/zeam-labs/pass/blob/main/python/examples/server.py
|
|
86
|
+
|
|
87
|
+
In `openapi.json` each paid operation carries a `402` response and `x-payment-info`: its `price` in dollars,
|
|
88
|
+
`protocols`, and under `offers` the MPP `evm` charge its 402 carries now, where it carries one. Every operation says
|
|
89
|
+
`security: []`: no API key; a paid tool is opened by the payment.
|
|
90
|
+
|
|
91
|
+
MPP directories and validators look for `GET /openapi.json` at the root of your origin. Bridge mounted at `/agents`
|
|
92
|
+
does not see that path, so add the route in your own app; `agents.discovery(origin, "/agents")` is the same document
|
|
93
|
+
with each path written in full. Flask:
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
@app.get("/openapi.json")
|
|
97
|
+
def discovery():
|
|
98
|
+
return agents.discovery(request.host_url, "/agents")
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
FastAPI serves its own schema at `/openapi.json`: create the app with `FastAPI(openapi_url=None)` (or another path)
|
|
102
|
+
and add the route the same way, with `str(request.base_url)` as the origin. Without that route there is no root
|
|
103
|
+
document and a directory will not find your tools. Set `site` to your public origin when you run behind a proxy: the
|
|
104
|
+
document, the 402 and the MPP `realm` then name that origin. A directory fetches the document over HTTPS.
|
|
105
|
+
|
|
106
|
+
The agent side: https://zeampass.com/docs/agents
|
|
107
|
+
|
|
108
|
+
## Modes
|
|
109
|
+
|
|
110
|
+
What an agent does in each `mode`:
|
|
111
|
+
|
|
112
|
+
- `paywall` (default): pays `price` USD per call with x402 `batch-settlement`,
|
|
113
|
+
or with an MPP charge where the 402 offers one (USDC on Base).
|
|
114
|
+
- `gate`: signs each call with its key as a zero-value x402 `exact` payment:
|
|
115
|
+
nothing is paid, the key needs no funds; `admit=[...]` lists the admitted
|
|
116
|
+
key addresses; a grant (`x-grant`) from one of them admits one other key.
|
|
117
|
+
- `both`: its key must be admitted; it pays per call.
|
|
118
|
+
|
|
119
|
+
`name` (2 to 32 of a-z, 0-9 and -, starting with a letter) and `payout` (the wallet address earnings go to) fix your
|
|
120
|
+
split's address and hold your gate credit: a change moves new earnings to a new split and leaves gate credit bought
|
|
121
|
+
before it behind, so pay out first.
|
|
122
|
+
|
|
123
|
+
Other keyword arguments to `Bridge(...)`:
|
|
124
|
+
|
|
125
|
+
- `price`: USD per call, up to 6 decimals (`"0.02"`); the default for tools
|
|
126
|
+
with no price of their own.
|
|
127
|
+
- `prices`: per tool: `{"tool": "0.05"}` or
|
|
128
|
+
`{"tool": {"price": "0.05", "unit": "0.0001"}}`, or a callable
|
|
129
|
+
`(tool, args) -> spec`; a paywall needs `price` or `prices`.
|
|
130
|
+
- `free` (default `[]`): tool names served with no payment and no admission.
|
|
131
|
+
- `time` (default none): line time:
|
|
132
|
+
`{"usd": "0.00025", "ms": 250, "idleMs": 0}`: that many dollars buys that many milliseconds. A buyer buys any
|
|
133
|
+
number of milliseconds and buying again adds time (`"maxMs": N` limits one purchase, if you want that);
|
|
134
|
+
`paywall` and `both` only; adds `buy_time`, `line` and `POST <base>/line`. Up to 1000 calls run at once on one
|
|
135
|
+
line (`"maxCalls": N`, 1..1000, default 1000); lower it to limit a buyer's parallel calls — the next is refused `429 too_many_calls`.
|
|
136
|
+
- `free_limit` (default none): `N` or `{"perHour": N}`: N free calls per tool
|
|
137
|
+
per client address per clock hour, kept in `state_dir/free.json` (a restart
|
|
138
|
+
keeps the hour); no client address: one shared count; over it: 429
|
|
139
|
+
`free_limit`, `retry-after`.
|
|
140
|
+
- `site` (default the request's origin): your public origin, used in the
|
|
141
|
+
402's resource and refund URL.
|
|
142
|
+
- `admit` (default `[]`): admitted key addresses.
|
|
143
|
+
- `on_empty` (default `"refuse"`): gate credit at 0: `"refuse"`, or `"allow"`
|
|
144
|
+
and warn.
|
|
145
|
+
- `contact` (default none): an `http(s)://` URL or a `mailto:` address; goes in
|
|
146
|
+
every 402, in the 403 `refused` answer (`how` and `contact`) and in
|
|
147
|
+
`openapi.json` `info.contact`.
|
|
148
|
+
- `state_dir` (default `$BRIDGE_STATE_DIR` or `~/.zeam-pass/<name>`): keys,
|
|
149
|
+
channel records, gate usage, line time and free-call counts.
|
|
150
|
+
- `rpc` (default `https://mainnet.base.org`): a Base RPC URL.
|
|
151
|
+
- `relay` (default `https://api.zeampass.com/relay`): ZEAM's relay.
|
|
152
|
+
- `credits` (default `https://api.zeampass.com/credits`): ZEAM's gate credit
|
|
153
|
+
service.
|
|
154
|
+
- `refund_url`: the refund URL the 402 names.
|
|
155
|
+
- `tick_seconds` (default `60`): seconds between background runs; `0` turns
|
|
156
|
+
the thread off.
|
|
157
|
+
- `server_name`, `version`: the MCP handshake's server info.
|
|
158
|
+
- `fee_recipient`, `credit_issuer` (default `$BRIDGE_FEE_RECIPIENT`,
|
|
159
|
+
`$BRIDGE_CREDIT_ISSUER`): development only.
|
|
160
|
+
- `payout_is_fee_recipient` (default `False`): `True` only when `payout` is
|
|
161
|
+
the fee address: the split pays it 100%.
|
|
162
|
+
- `settings`: engine tuning; `gateFreePerMonth` and `gateCreditBlock` set the
|
|
163
|
+
gate's free checks and credit block, for tests.
|
|
164
|
+
|
|
165
|
+
Settings from the environment are `BRIDGE_…`; the `PASS_…` name of each still works and is read second.
|
|
166
|
+
|
|
167
|
+
The Python plugin does not read `pass.json`.
|
|
168
|
+
|
|
169
|
+
`@agents.tool(...)` keyword arguments:
|
|
170
|
+
|
|
171
|
+
- `name`, `description`, `input_schema` (default the function's name and
|
|
172
|
+
docstring, `{"type": "object"}`).
|
|
173
|
+
- `output_schema` (default none): the JSON Schema of the result, for the x402
|
|
174
|
+
`bazaar` discovery extension the 402 carries (`extensions.bazaar`: how to
|
|
175
|
+
call the tool, `input_schema`, `output_schema` or "any JSON"). In the
|
|
176
|
+
`PAYMENT-REQUIRED` header while the extension is at most 4,096 bytes and the
|
|
177
|
+
header at most 12,288; past that, in the body only.
|
|
178
|
+
- `price` (default `prices[name]`, then `price`): USD per call; an invalid
|
|
179
|
+
price raises at registration.
|
|
180
|
+
- `unit` (default none): USD per unit: the call reserves `price`; the tool
|
|
181
|
+
calls `zeam_bridge.units(n)`; charge = min(`price`, n × `unit`).
|
|
182
|
+
- `free` (default `False`): `True`: no payment, no admission; arguments still
|
|
183
|
+
validated.
|
|
184
|
+
- `meter` (default none): `"time"`: on a line (`x-line`) the call burns the
|
|
185
|
+
line's time; without one it is a paid call bounded to
|
|
186
|
+
the milliseconds its price buys at the `time` rate (past it: 402 `out_of_time`, not
|
|
187
|
+
charged); needs `time`, never free.
|
|
188
|
+
|
|
189
|
+
Order: the tool's `price`/`unit`, then `prices`, then `price`. The 402 carries this call's amount in `accepts`,
|
|
190
|
+
`pricing` for this call and `prices` for every tool; `tools/list` entries carry `_meta["zeam-pass/price"]`; `openapi.json`
|
|
191
|
+
operations carry `x-price`. A price the callable cannot give: 500 `price_invalid`. `gate` mode never prices.
|
|
192
|
+
|
|
193
|
+
## The gate
|
|
194
|
+
|
|
195
|
+
```python
|
|
196
|
+
import os
|
|
197
|
+
|
|
198
|
+
from zeam_bridge import Bridge, sign_grant
|
|
199
|
+
|
|
200
|
+
agents = Bridge(
|
|
201
|
+
name="acme",
|
|
202
|
+
payout="0xYourWalletAddress",
|
|
203
|
+
mode="gate",
|
|
204
|
+
admit=["0xAgentKeyAddress"],
|
|
205
|
+
)
|
|
206
|
+
|
|
207
|
+
grant = sign_grant(
|
|
208
|
+
os.environ["ADMITTED_KEY"],
|
|
209
|
+
"0xTheirKeyAddress",
|
|
210
|
+
"2026-12-31T00:00:00Z",
|
|
211
|
+
scope="quote",
|
|
212
|
+
)
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
An agent signs each call with its own key; nothing is paid, nothing goes on chain. `sign_grant(key, delegate, until,
|
|
216
|
+
scope="*")`: `key` is the private key of an address in `admit`, `delegate` the address of the key you admit, `until`
|
|
217
|
+
an ISO time or a timezone-aware `datetime`, `scope` one tool name or `"*"`. It returns the `x-grant` header value for
|
|
218
|
+
the agent that holds `delegate`. A call signed by any other key is refused `bad_grant`; so is one past `until`.
|
|
219
|
+
Removing the signing key from `admit` ends every grant it signed.
|
|
220
|
+
|
|
221
|
+
Agent side, in Python: `new_key()` makes a key; `key_address(key)` is the address the seller lists;
|
|
222
|
+
`gate_proof(key, payment_required)` signs the zero-value row of a gate's 402 (the body, or its `PAYMENT-REQUIRED`
|
|
223
|
+
header) and returns the `PAYMENT-SIGNATURE` value. Pass a gate: https://zeampass.com/docs/agents#pass-a-gate
|
|
224
|
+
|
|
225
|
+
## Keys
|
|
226
|
+
|
|
227
|
+
On first start the plugin writes its keys to `state_dir`: the settle key (signs your claims and refunds) and, for
|
|
228
|
+
`gate` and `both`, a credit wallet, which holds the gate's USDC; `agents.status()` shows its address. Gate mode: send
|
|
229
|
+
it USDC on Base; it needs no ETH. Credit is 2,000 checks at a time for $1 USDC ($0.50 per 1,000), bought after the
|
|
230
|
+
month's 10,000 free checks are used and again below 200 remaining. Keep $1 USDC on Base in the credit wallet. `both`
|
|
231
|
+
mode needs no USDC in the credit wallet: paid calls are not gate checks.
|
|
232
|
+
|
|
233
|
+
`keys.json` has mode 0600 in a 0700 directory. `BRIDGE_KEY_SECRET` seals the keys with AES-256-GCM (key from scrypt);
|
|
234
|
+
unsealed keys are sealed on the next start. Secret missing or wrong: paid calls answer 503 and nothing is served.
|
|
235
|
+
|
|
236
|
+
Put `state_dir` on storage that survives a redeploy, and back it up: it holds the keys and the channel records your
|
|
237
|
+
earnings are claimed from. `agents.status()` shows the settle key and credit wallet addresses, unclaimed and unpaid
|
|
238
|
+
earnings, and gate usage. Fields: https://zeambridge.com/docs/sell#status
|
|
239
|
+
|
|
240
|
+
## A call
|
|
241
|
+
|
|
242
|
+
1. Arguments are checked against your `input_schema` (types, `required`, `enum`, `minimum`, `maximum`, `minLength`,
|
|
243
|
+
`maxLength`, and the same for an object argument's properties, 1 level deep). Bad arguments, and bodies with
|
|
244
|
+
`NaN`, `Infinity` or numbers too large for a float: 400 (MCP: an error result); nothing held. An unpaid call to
|
|
245
|
+
a paid tool with no arguments (no body, `{}`) gets the 402 with the price. Properties the
|
|
246
|
+
schema does not name are allowed, as in Node: your function gets the ones its signature takes (all of them with
|
|
247
|
+
`**kwargs`).
|
|
248
|
+
2. The payment is verified and held.
|
|
249
|
+
3. Your tool runs. With a `unit`, it reports whole units with `zeam_bridge.units(n)` (outside a tool run: `RuntimeError`).
|
|
250
|
+
4. The payment settles only on success. With a `unit`: no report, or a bad one (negative, not whole, bool, str),
|
|
251
|
+
is a failure: released, nothing charged per call (on a line the call has used the time it ran). The settle response's `extra` carries `chargedAmount` and
|
|
252
|
+
`reservedAmount`. The tool raised, returned a dict with `"isError": True`, or returned a value
|
|
253
|
+
that is not valid JSON (a set, a non-finite float, a non-string dict key): the hold is released, nothing is
|
|
254
|
+
charged per call (on a line the call has used the time it ran); the last answers 500 `tool_failed` with the message every engine gives: "the result is not valid JSON (a
|
|
255
|
+
non-finite number or a non-JSON value); nothing was charged". An `"isError": True` dict is answered over HTTP with
|
|
256
|
+
the fields of its `structuredContent`, as MCP carries them; a `status` of 400 to 599 among them, other than 402,
|
|
257
|
+
marks a refusal that is the caller's and is the answer's status, with `Retry-After` from `retry_after_seconds`;
|
|
258
|
+
otherwise 500 `tool_failed`.
|
|
259
|
+
|
|
260
|
+
The payment does not settle: the result is not delivered. Chain unreadable: nothing is served. Request bodies are
|
|
261
|
+
capped at 1 MB.
|
|
262
|
+
|
|
263
|
+
A voucher settles in your process with no transaction. A deposit (the first call on a channel, and every top-up) goes
|
|
264
|
+
through the relay and waits for its receipt: that call takes a few seconds.
|
|
265
|
+
|
|
266
|
+
Behind a proxy or on localhost, pass `site="https://your.domain"`: the 402's resource and refund URL use that origin.
|
|
267
|
+
|
|
268
|
+
Flask routes you already have: `@agents.paid` holds, runs and settles the same way; an exception or a status of 400
|
|
269
|
+
or more releases the hold. Add the refund route:
|
|
270
|
+
|
|
271
|
+
```python
|
|
272
|
+
from flask import Flask
|
|
273
|
+
|
|
274
|
+
app = Flask(__name__)
|
|
275
|
+
|
|
276
|
+
@app.post("/quote")
|
|
277
|
+
@agents.paid
|
|
278
|
+
def quote():
|
|
279
|
+
...
|
|
280
|
+
|
|
281
|
+
app.add_url_rule("/refund", view_func=agents.refund_view(), methods=["POST"])
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
## Line time
|
|
285
|
+
|
|
286
|
+
With `time` set, an agent buys time and spends it on a line with no payment per call:
|
|
287
|
+
|
|
288
|
+
1. `buy_time {"ms": n}` (any number of milliseconds; buying again adds time): a paid call for n ms at the `time` rate; the n ms are credited to the
|
|
289
|
+
paying channel once the payment settles, once per payment.
|
|
290
|
+
2. `POST <base>/line {"op": "open", "channelId"}` (or the free `line` tool): a message to sign with the payer key.
|
|
291
|
+
3. `{"op": "prove", "channelId", "nonce", "signature"}`: the credential; the meter is on. A nonce is one attempt, 300 s.
|
|
292
|
+
4. Calls to a `meter="time"` tool with the credential in `x-line` (MCP: `_meta["zeam-pass/line"]` or the request's
|
|
293
|
+
`x-line`) run until the time runs out; answers carry `x-pass-ms-remaining` and `x-pass-ms-elapsed` (MCP:
|
|
294
|
+
`_meta["zeam-pass/meter"]`). Time burns while a call runs, once for calls at the same time, plus `idleMs` after each.
|
|
295
|
+
Refusals: 403 `line_unknown`, 402 `meter_off`, `out_of_time`, `channel_leaving`, `refund_settling`, 429 `too_many_calls`.
|
|
296
|
+
5. `{"op": "off"}`, `"on"`, `"status"`, `"close"` with `credential` or `x-line`.
|
|
297
|
+
|
|
298
|
+
`zeam_bridge.deadline_ms()` inside a time tool: the epoch ms its call must end by (`None` elsewhere). The call runs in a
|
|
299
|
+
worker thread; past the deadline the caller gets `out_of_time` and a late result is discarded, so stop by then.
|
|
300
|
+
`zeam_bridge.stopped(wait=0)` inside a tool: true once the caller hung up, canceled the call over MCP
|
|
301
|
+
(`notifications/cancelled` with the call's line or its `Mcp-Session-Id`) or the time ran out; it waits up to `wait`
|
|
302
|
+
seconds for that. The meter stops at that moment and a call priced per call is not charged; a tool that does not check
|
|
303
|
+
runs on, unbilled. Over ASGI a disconnect is the hang-up. WSGI and `@agents.paid` cannot see one: there a call is billed
|
|
304
|
+
until it returns or is canceled. With a server of your own, pass `hangup=zeam_bridge.Hangup()` to `agents.handle()` and
|
|
305
|
+
call its `hang_up()` when the caller leaves.
|
|
306
|
+
Claims and payouts take what burned; a refund switches the meter off, returns the unburned time with the balance
|
|
307
|
+
(`timeReturnedMs`) and closes the channel's lines. State: `<state_dir>/meter`.
|
|
308
|
+
|
|
309
|
+
## Refunds
|
|
310
|
+
|
|
311
|
+
The buyer posts `{"channelId", "issued", "signature"}`, signed by the channel's payer over
|
|
312
|
+
`ZEAM Pass refund\nchannel: <id>\nissued: <ISO time>` within 5 minutes, plus `channelConfig` for a channel with no
|
|
313
|
+
calls. The balance goes back through the relay:
|
|
314
|
+
|
|
315
|
+
- The channel's spend times the fee address's share of your split (9.99%; 100% with `payout_is_fee_recipient`), in
|
|
316
|
+
whole micro-dollars, ≥ the gas of its deposit, its refund and any calls not yet settled, and of every further deposit and every earlier refund ZEAM paid for on that channel, plus 15%: ZEAM pays the gas. `"op": "refunded"`, `gasMicroUSD: 0`.
|
|
317
|
+
- Otherwise: 409 `"op": "refund_quote"` (`gas_payment_needed`), an EIP-3009 `TransferWithAuthorization` of the quoted
|
|
318
|
+
gas (15% margin) for the buyer to sign. The relay prices it; no quote from the relay: the engine prices from `GAS`
|
|
319
|
+
(`quotedBy: "engine"`), with the ETH price and gas wallet it read from the relay's `/health` in the last 60
|
|
320
|
+
seconds; without those, 503 `gas_unpriced`. Public check: `https://api.zeampass.com/relay/quote`. The buyer posts again with
|
|
321
|
+
`"gasPayment"`; the relay sends the refund, then the payment, in one transaction.
|
|
322
|
+
- `"selfSend": true`: the buyer gets a signed refund of the full balance and sends it from any wallet with ETH on Base for gas.
|
|
323
|
+
|
|
324
|
+
Every field and error: https://zeampass.com/docs/agents#errors and
|
|
325
|
+
https://zeampass.com/docs/agents#refunds
|
|
326
|
+
|
|
327
|
+
## Background work
|
|
328
|
+
|
|
329
|
+
Where no process stays alive between requests the thread below does not run: set `tick_seconds=0` and call
|
|
330
|
+
`agents.tick()` from your scheduler. A daemon thread runs `agents.tick()` every `tick_seconds` (60): it stamps channels whose payer started a withdrawal,
|
|
331
|
+
claims earnings once the fee covers the gas and pays them out in the same relay request, and, in `gate` mode, buys
|
|
332
|
+
credit. Several workers can share one `state_dir`; overlapping ticks skip. `tick_seconds=0` and `agents.tick()` from
|
|
333
|
+
your cron schedules it yourself. `agents.payout_now()` pays out now, or returns the transaction to send from your
|
|
334
|
+
wallet with ETH on Base for gas.
|
|
335
|
+
|
|
336
|
+
A paid call waits on the chain and, for a deposit, on the relay: serve with threads or workers (gunicorn, uvicorn, or
|
|
337
|
+
`wsgiref` with `socketserver.ThreadingMixIn` and `request_queue_size = socket.SOMAXCONN` as in `examples/server.py`:
|
|
338
|
+
the standard library's default queue of 5 connections drops a burst).
|
|
339
|
+
|
|
340
|
+
## Tests
|
|
341
|
+
|
|
342
|
+
`python -m unittest` from this directory runs the plugin tests and the 5 fixture sets every engine shares
|
|
343
|
+
(`wordpress/tests/vectors.json`, `settlement/fixtures.json`, `gate/fixtures.json`, `pricing/fixtures.json`,
|
|
344
|
+
`meter/fixtures.json`).
|