satsgate 0.1.1__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.
- satsgate-0.1.1/LICENSE +201 -0
- satsgate-0.1.1/PKG-INFO +83 -0
- satsgate-0.1.1/README.md +61 -0
- satsgate-0.1.1/pyproject.toml +43 -0
- satsgate-0.1.1/setup.cfg +4 -0
- satsgate-0.1.1/src/satsgate/__init__.py +3 -0
- satsgate-0.1.1/src/satsgate/__main__.py +92 -0
- satsgate-0.1.1/src/satsgate/files.py +160 -0
- satsgate-0.1.1/src/satsgate/init.py +1266 -0
- satsgate-0.1.1/src/satsgate/snippets/Caddyfile +17 -0
- satsgate-0.1.1/src/satsgate/snippets/express_verify.js +77 -0
- satsgate-0.1.1/src/satsgate/snippets/fastapi_verify.py +111 -0
- satsgate-0.1.1/src/satsgate/snippets/nginx.conf +21 -0
- satsgate-0.1.1/src/satsgate/snippets/nginx_verify.js +79 -0
- satsgate-0.1.1/src/satsgate.egg-info/PKG-INFO +83 -0
- satsgate-0.1.1/src/satsgate.egg-info/SOURCES.txt +18 -0
- satsgate-0.1.1/src/satsgate.egg-info/dependency_links.txt +1 -0
- satsgate-0.1.1/src/satsgate.egg-info/entry_points.txt +2 -0
- satsgate-0.1.1/src/satsgate.egg-info/requires.txt +5 -0
- satsgate-0.1.1/src/satsgate.egg-info/top_level.txt +1 -0
satsgate-0.1.1/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 consequential 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 [yyyy] [name of copyright owner]
|
|
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.
|
satsgate-0.1.1/PKG-INFO
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: satsgate
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Charge AI agents in Lightning and USDC on the same 402. 500 free unlocks per UTC month. Cobrale a agentes de IA en Lightning y USDC, en el mismo 402.
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
Project-URL: Homepage, https://github.com/Mike-io-hash/satsgate
|
|
7
|
+
Project-URL: Issues, https://github.com/Mike-io-hash/satsgate/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/Mike-io-hash/satsgate/blob/main/CHANGELOG.md
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Requires-Python: >=3.10
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Requires-Dist: satsgate-sdk<0.11,>=0.10.0
|
|
18
|
+
Requires-Dist: satsgate-proxy<0.15,>=0.14.1
|
|
19
|
+
Provides-Extra: mcp
|
|
20
|
+
Requires-Dist: satsgate-mcp<0.14,>=0.13.0; extra == "mcp"
|
|
21
|
+
Dynamic: license-file
|
|
22
|
+
|
|
23
|
+
# satsgate
|
|
24
|
+
|
|
25
|
+
Charge AI agents in Lightning and USDC on the same 402. 500 free unlocks per UTC month. Cobrale a agentes de IA en Lightning y USDC, en el mismo 402.
|
|
26
|
+
|
|
27
|
+
`satsgate init` takes a merchant from nothing to a self-hosted paywall config. It opens a free account, saves the account key in `.satsgate/account.env`, asks for a Lightning Address, mints a restricted proxy key, writes `.env` and `satsgate-proxy.yaml`, and checks the paywall with a real 402. That check does not pay, verify, or settle.
|
|
28
|
+
|
|
29
|
+
It does not ask for a seed, a private key, or a recovery phrase. It does not hold sats or USDC. The account key is not copied into the project `.env`. The project `.env` holds `SATSGATE_API_KEY` (`sgr_`) and `SATSGATE_ORIGIN_SECRET`.
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
uvx satsgate init
|
|
33
|
+
pip install satsgate
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
From a checkout: `pip install -e sdk/python -e proxy -e cli`.
|
|
37
|
+
|
|
38
|
+
## Human and agent
|
|
39
|
+
|
|
40
|
+
Human mode prompts when stdin is a terminal and `--json` is not set. Agent mode (`--json`, or stdin that is not a terminal) never prompts. It prints one JSON object on stdout and notes on stderr. A missing Lightning Address is exit 2 and names `--lightning-address`.
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
satsgate init --json --lightning-address merchant@pay.example
|
|
44
|
+
satsgate init --json --lightning-address merchant@pay.example --want-usdc
|
|
45
|
+
satsgate init --docker --framework fastapi
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
JSON (`schema_version` 1) includes `ok`, `status`, `exit_code`, `api_url`, `account` (`client_id`, `key_preview`, `fingerprint`, `reused`), `payee_lightning_address`, `usdc`, `files`, `route`, `test_402`, `start_command`, `next_steps`, `warnings`, and `error`. A key is shown as `sg_…` or `sgr_…` plus the last four characters, and as a fingerprint. The connect link is not a JSON field.
|
|
49
|
+
|
|
50
|
+
Exit codes: 0 done, 1 the API or the network failed, 2 usage, 3 a human has to decide, 4 rate-limited. A 429 includes `retry_after_seconds` and is not retried.
|
|
51
|
+
|
|
52
|
+
## Files
|
|
53
|
+
|
|
54
|
+
| Path | Mode | Contents |
|
|
55
|
+
| --- | --- | --- |
|
|
56
|
+
| `.satsgate/` | 0700 | directory |
|
|
57
|
+
| `.satsgate/account.env` | 0600 | `SATSGATE_ACCOUNT_KEY` |
|
|
58
|
+
| `.satsgate/.gitignore` | | `*` |
|
|
59
|
+
| `.env` | 0600 when created here | `SATSGATE_API_KEY`, `SATSGATE_ORIGIN_SECRET` |
|
|
60
|
+
| `satsgate-proxy.yaml` | | proxy config, no secrets |
|
|
61
|
+
| `.satsgate/connect-link.txt` | 0600 | wallet link in agent mode |
|
|
62
|
+
|
|
63
|
+
A second run reuses the account and the keys. An existing YAML or snippet is not overwritten (agent exit 3 `file_exists`). A different `SATSGATE_*` value is exit 3 `env_conflict`. A symlink is refused. On Windows the run finishes and warns `permissions_not_restricted`; WSL is the supported way to get owner-only files.
|
|
64
|
+
|
|
65
|
+
## USDC payments: Base network only
|
|
66
|
+
|
|
67
|
+
USDC payments use Base only. Ethereum mainnet, Polygon, Solana, Arbitrum, and any other chain are not accepted.
|
|
68
|
+
|
|
69
|
+
`--want-usdc` mints a one-time connect link when the EVM payee is not verified yet. A terminal prints the link once and can open it. Otherwise it is written to `.satsgate/connect-link.txt` and is not printed. After the payee is verified, a later run sets `x402: true` and `x402_mode: test`. The unpaid 402 then includes a Base Sepolia offer. Paying that offer is a later step for a buyer agent (`satsgate-mcp-pay`), with the key on the buyer's machine. Test mode is free.
|
|
70
|
+
|
|
71
|
+
To turn USDC test mode off, delete the YAML and run `init` again. It is regenerated and the keys are reused. Manual edits to the YAML are lost. To keep them, remove the route's `x402` and `x402_mode` lines and restart the proxy instead.
|
|
72
|
+
|
|
73
|
+
Lightning has no test network. A paid Lightning request moves real sats to the merchant's own address.
|
|
74
|
+
|
|
75
|
+
## Start
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
uvx --env-file .env satsgate-proxy --config satsgate-proxy.yaml
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
`satsgate` 0.1.1. `--docker` writes `docker-compose.satsgate.yml` and prints `docker compose -f docker-compose.satsgate.yml up`. The compose file uses the public image `ghcr.io/mike-io-hash/satsgate-proxy:0.14.1`. To build that image yourself, use `proxy/Dockerfile` from the repo. The generated service listens on `0.0.0.0`; the YAML written for `uvx` stays on `127.0.0.1`. From a checkout: `pip install -e sdk/python -e proxy -e cli`.
|
|
82
|
+
|
|
83
|
+
`--framework fastapi`, `express`, or `nginx` copies the existing origin check. A client that can reach the origin directly must fail closed. The Caddy file in the package is a note, not an HMAC check.
|
satsgate-0.1.1/README.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# satsgate
|
|
2
|
+
|
|
3
|
+
Charge AI agents in Lightning and USDC on the same 402. 500 free unlocks per UTC month. Cobrale a agentes de IA en Lightning y USDC, en el mismo 402.
|
|
4
|
+
|
|
5
|
+
`satsgate init` takes a merchant from nothing to a self-hosted paywall config. It opens a free account, saves the account key in `.satsgate/account.env`, asks for a Lightning Address, mints a restricted proxy key, writes `.env` and `satsgate-proxy.yaml`, and checks the paywall with a real 402. That check does not pay, verify, or settle.
|
|
6
|
+
|
|
7
|
+
It does not ask for a seed, a private key, or a recovery phrase. It does not hold sats or USDC. The account key is not copied into the project `.env`. The project `.env` holds `SATSGATE_API_KEY` (`sgr_`) and `SATSGATE_ORIGIN_SECRET`.
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
uvx satsgate init
|
|
11
|
+
pip install satsgate
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
From a checkout: `pip install -e sdk/python -e proxy -e cli`.
|
|
15
|
+
|
|
16
|
+
## Human and agent
|
|
17
|
+
|
|
18
|
+
Human mode prompts when stdin is a terminal and `--json` is not set. Agent mode (`--json`, or stdin that is not a terminal) never prompts. It prints one JSON object on stdout and notes on stderr. A missing Lightning Address is exit 2 and names `--lightning-address`.
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
satsgate init --json --lightning-address merchant@pay.example
|
|
22
|
+
satsgate init --json --lightning-address merchant@pay.example --want-usdc
|
|
23
|
+
satsgate init --docker --framework fastapi
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
JSON (`schema_version` 1) includes `ok`, `status`, `exit_code`, `api_url`, `account` (`client_id`, `key_preview`, `fingerprint`, `reused`), `payee_lightning_address`, `usdc`, `files`, `route`, `test_402`, `start_command`, `next_steps`, `warnings`, and `error`. A key is shown as `sg_…` or `sgr_…` plus the last four characters, and as a fingerprint. The connect link is not a JSON field.
|
|
27
|
+
|
|
28
|
+
Exit codes: 0 done, 1 the API or the network failed, 2 usage, 3 a human has to decide, 4 rate-limited. A 429 includes `retry_after_seconds` and is not retried.
|
|
29
|
+
|
|
30
|
+
## Files
|
|
31
|
+
|
|
32
|
+
| Path | Mode | Contents |
|
|
33
|
+
| --- | --- | --- |
|
|
34
|
+
| `.satsgate/` | 0700 | directory |
|
|
35
|
+
| `.satsgate/account.env` | 0600 | `SATSGATE_ACCOUNT_KEY` |
|
|
36
|
+
| `.satsgate/.gitignore` | | `*` |
|
|
37
|
+
| `.env` | 0600 when created here | `SATSGATE_API_KEY`, `SATSGATE_ORIGIN_SECRET` |
|
|
38
|
+
| `satsgate-proxy.yaml` | | proxy config, no secrets |
|
|
39
|
+
| `.satsgate/connect-link.txt` | 0600 | wallet link in agent mode |
|
|
40
|
+
|
|
41
|
+
A second run reuses the account and the keys. An existing YAML or snippet is not overwritten (agent exit 3 `file_exists`). A different `SATSGATE_*` value is exit 3 `env_conflict`. A symlink is refused. On Windows the run finishes and warns `permissions_not_restricted`; WSL is the supported way to get owner-only files.
|
|
42
|
+
|
|
43
|
+
## USDC payments: Base network only
|
|
44
|
+
|
|
45
|
+
USDC payments use Base only. Ethereum mainnet, Polygon, Solana, Arbitrum, and any other chain are not accepted.
|
|
46
|
+
|
|
47
|
+
`--want-usdc` mints a one-time connect link when the EVM payee is not verified yet. A terminal prints the link once and can open it. Otherwise it is written to `.satsgate/connect-link.txt` and is not printed. After the payee is verified, a later run sets `x402: true` and `x402_mode: test`. The unpaid 402 then includes a Base Sepolia offer. Paying that offer is a later step for a buyer agent (`satsgate-mcp-pay`), with the key on the buyer's machine. Test mode is free.
|
|
48
|
+
|
|
49
|
+
To turn USDC test mode off, delete the YAML and run `init` again. It is regenerated and the keys are reused. Manual edits to the YAML are lost. To keep them, remove the route's `x402` and `x402_mode` lines and restart the proxy instead.
|
|
50
|
+
|
|
51
|
+
Lightning has no test network. A paid Lightning request moves real sats to the merchant's own address.
|
|
52
|
+
|
|
53
|
+
## Start
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
uvx --env-file .env satsgate-proxy --config satsgate-proxy.yaml
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
`satsgate` 0.1.1. `--docker` writes `docker-compose.satsgate.yml` and prints `docker compose -f docker-compose.satsgate.yml up`. The compose file uses the public image `ghcr.io/mike-io-hash/satsgate-proxy:0.14.1`. To build that image yourself, use `proxy/Dockerfile` from the repo. The generated service listens on `0.0.0.0`; the YAML written for `uvx` stays on `127.0.0.1`. From a checkout: `pip install -e sdk/python -e proxy -e cli`.
|
|
60
|
+
|
|
61
|
+
`--framework fastapi`, `express`, or `nginx` copies the existing origin check. A client that can reach the origin directly must fail closed. The Caddy file in the package is a note, not an HMAC check.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "satsgate"
|
|
3
|
+
version = "0.1.1"
|
|
4
|
+
description = "Charge AI agents in Lightning and USDC on the same 402. 500 free unlocks per UTC month. Cobrale a agentes de IA en Lightning y USDC, en el mismo 402."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.10"
|
|
7
|
+
license = "Apache-2.0"
|
|
8
|
+
license-files = ["LICENSE"]
|
|
9
|
+
classifiers = [
|
|
10
|
+
"Development Status :: 4 - Beta",
|
|
11
|
+
"Programming Language :: Python :: 3",
|
|
12
|
+
"Programming Language :: Python :: 3.10",
|
|
13
|
+
"Programming Language :: Python :: 3.11",
|
|
14
|
+
"Programming Language :: Python :: 3.12",
|
|
15
|
+
]
|
|
16
|
+
dependencies = [
|
|
17
|
+
"satsgate-sdk>=0.10.0,<0.11",
|
|
18
|
+
"satsgate-proxy>=0.14.1,<0.15",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
[project.optional-dependencies]
|
|
22
|
+
mcp = ["satsgate-mcp>=0.13.0,<0.14"]
|
|
23
|
+
|
|
24
|
+
[project.scripts]
|
|
25
|
+
satsgate = "satsgate.__main__:main"
|
|
26
|
+
|
|
27
|
+
[project.urls]
|
|
28
|
+
Homepage = "https://github.com/Mike-io-hash/satsgate"
|
|
29
|
+
Issues = "https://github.com/Mike-io-hash/satsgate/issues"
|
|
30
|
+
Changelog = "https://github.com/Mike-io-hash/satsgate/blob/main/CHANGELOG.md"
|
|
31
|
+
|
|
32
|
+
[build-system]
|
|
33
|
+
requires = ["setuptools>=77", "wheel"]
|
|
34
|
+
build-backend = "setuptools.build_meta"
|
|
35
|
+
|
|
36
|
+
[tool.setuptools]
|
|
37
|
+
package-dir = {"" = "src"}
|
|
38
|
+
|
|
39
|
+
[tool.setuptools.packages.find]
|
|
40
|
+
where = ["src"]
|
|
41
|
+
|
|
42
|
+
[tool.setuptools.package-data]
|
|
43
|
+
satsgate = ["snippets/*"]
|
satsgate-0.1.1/setup.cfg
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"""Console entry: `satsgate` and `python -m satsgate`."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import sys
|
|
7
|
+
|
|
8
|
+
from satsgate import __version__
|
|
9
|
+
from satsgate.init import InitOptions, run_init
|
|
10
|
+
from satsgate_proxy import __version__ as proxy_version
|
|
11
|
+
from satsgate_sdk import __version__ as sdk_version
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def version_line() -> str:
|
|
15
|
+
return f"satsgate {__version__}\nsatsgate-sdk {sdk_version}\nsatsgate-proxy {proxy_version}\n"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
19
|
+
parser = argparse.ArgumentParser(prog="satsgate", description="Set up a self-hosted satsgate paywall.")
|
|
20
|
+
parser.add_argument("--version", action="store_true", help="Print the satsgate, SDK, and proxy versions.")
|
|
21
|
+
sub = parser.add_subparsers(dest="command")
|
|
22
|
+
init = sub.add_parser("init", help="Write a paywall config for a Lightning Address.")
|
|
23
|
+
init.add_argument("--json", action="store_true", help="Print one JSON object and do not prompt.")
|
|
24
|
+
init.add_argument("--api-url", default=None, help="Core API URL. Defaults to SATSGATE_API_URL or the public API.")
|
|
25
|
+
init.add_argument("--lightning-address", default=None, help="Lightning Address that receives payments.")
|
|
26
|
+
init.add_argument("--want-usdc", action="store_true", help="Offer USDC test mode when the EVM payee is verified.")
|
|
27
|
+
init.add_argument("--docker", action="store_true", help="Also write docker-compose.satsgate.yml.")
|
|
28
|
+
init.add_argument(
|
|
29
|
+
"--framework",
|
|
30
|
+
choices=("fastapi", "express", "nginx", "none"),
|
|
31
|
+
default=None,
|
|
32
|
+
help="Origin check to copy next to the config.",
|
|
33
|
+
)
|
|
34
|
+
init.add_argument("--path", default="/paid/**", help="Route path. Default: /paid/**.")
|
|
35
|
+
init.add_argument("--upstream", default="http://127.0.0.1:3000", help="Origin base URL.")
|
|
36
|
+
init.add_argument(
|
|
37
|
+
"--public-url",
|
|
38
|
+
default="http://127.0.0.1:8080",
|
|
39
|
+
help="Buyer-facing proxy URL used when USDC test mode is on. Buyers need a public URL.",
|
|
40
|
+
)
|
|
41
|
+
init.add_argument("--yaml-out", default=None, help="Config path. Default: satsgate-proxy.yaml.")
|
|
42
|
+
init.add_argument("--new-account", action="store_true", help="Open another account even if one is saved.")
|
|
43
|
+
init.add_argument(
|
|
44
|
+
"--replace-api-key",
|
|
45
|
+
action="store_true",
|
|
46
|
+
help="With --new-account, replace SATSGATE_API_KEY with a key for the new account.",
|
|
47
|
+
)
|
|
48
|
+
init.add_argument(
|
|
49
|
+
"--replace-lightning-address",
|
|
50
|
+
action="store_true",
|
|
51
|
+
help="Replace a different Lightning Address already saved on the account.",
|
|
52
|
+
)
|
|
53
|
+
return parser
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def options_from(args: argparse.Namespace) -> InitOptions:
|
|
57
|
+
want = True if args.want_usdc else None
|
|
58
|
+
return InitOptions(
|
|
59
|
+
api_url=args.api_url,
|
|
60
|
+
lightning_address=args.lightning_address,
|
|
61
|
+
want_usdc=want,
|
|
62
|
+
json_mode=bool(args.json),
|
|
63
|
+
docker=bool(args.docker),
|
|
64
|
+
framework=args.framework,
|
|
65
|
+
path=args.path,
|
|
66
|
+
upstream=args.upstream,
|
|
67
|
+
public_url=args.public_url,
|
|
68
|
+
yaml_out=args.yaml_out,
|
|
69
|
+
new_account=bool(args.new_account),
|
|
70
|
+
replace_lightning_address=bool(args.replace_lightning_address),
|
|
71
|
+
replace_api_key=bool(args.replace_api_key),
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def run(argv: list[str] | None = None) -> int:
|
|
76
|
+
parser = build_parser()
|
|
77
|
+
args = parser.parse_args(argv)
|
|
78
|
+
if args.version:
|
|
79
|
+
sys.stdout.write(version_line())
|
|
80
|
+
return 0
|
|
81
|
+
if args.command != "init":
|
|
82
|
+
parser.print_help(sys.stderr)
|
|
83
|
+
return 2
|
|
84
|
+
return run_init(options_from(args))
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def main(argv: list[str] | None = None) -> None:
|
|
88
|
+
raise SystemExit(run(argv))
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
if __name__ == "__main__":
|
|
92
|
+
main()
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"""Atomic local files for `satsgate init`. Never follow a symlink."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
import re
|
|
7
|
+
import stat
|
|
8
|
+
import subprocess
|
|
9
|
+
import tempfile
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
ACCOUNT_KEY = "SATSGATE_ACCOUNT_KEY"
|
|
13
|
+
API_KEY = "SATSGATE_API_KEY"
|
|
14
|
+
ORIGIN_SECRET = "SATSGATE_ORIGIN_SECRET"
|
|
15
|
+
ENV_KEYS = (API_KEY, ORIGIN_SECRET)
|
|
16
|
+
_ASSIGN = re.compile(r"^(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)=(.*)$")
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class FileRefusal(Exception):
|
|
20
|
+
def __init__(self, code: str, message: str) -> None:
|
|
21
|
+
super().__init__(message)
|
|
22
|
+
self.code = code
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def permissions_restricted() -> bool:
|
|
26
|
+
"""POSIX can lock a file to the owner. Windows cannot, and says so."""
|
|
27
|
+
return os.name != "nt"
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def mode_of(path: Path) -> int:
|
|
31
|
+
return stat.S_IMODE(path.lstat().st_mode)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def refuse_symlink(path: Path) -> None:
|
|
35
|
+
if path.is_symlink():
|
|
36
|
+
raise FileRefusal("symlink_refused", f"{path.name} is a symlink")
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def ensure_dir(path: Path, mode: int = 0o700) -> bool:
|
|
40
|
+
refuse_symlink(path)
|
|
41
|
+
path.mkdir(parents=True, exist_ok=True)
|
|
42
|
+
if not permissions_restricted():
|
|
43
|
+
return False
|
|
44
|
+
os.chmod(path, mode)
|
|
45
|
+
return mode_of(path) == mode
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def atomic_write(path: Path, text: str, *, mode: int = 0o600) -> bool:
|
|
49
|
+
"""Replace `path` by rename. A symlink is refused and its target is not opened."""
|
|
50
|
+
refuse_symlink(path)
|
|
51
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
52
|
+
fd, name = tempfile.mkstemp(prefix=f".{path.name}.", dir=str(path.parent))
|
|
53
|
+
tmp = Path(name)
|
|
54
|
+
closed = False
|
|
55
|
+
try:
|
|
56
|
+
os.write(fd, text.encode("utf-8"))
|
|
57
|
+
if permissions_restricted():
|
|
58
|
+
os.fchmod(fd, mode)
|
|
59
|
+
os.close(fd)
|
|
60
|
+
closed = True
|
|
61
|
+
os.replace(tmp, path)
|
|
62
|
+
tmp = None
|
|
63
|
+
finally:
|
|
64
|
+
if not closed:
|
|
65
|
+
os.close(fd)
|
|
66
|
+
if tmp is not None:
|
|
67
|
+
tmp.unlink(missing_ok=True)
|
|
68
|
+
if not permissions_restricted():
|
|
69
|
+
return False
|
|
70
|
+
os.chmod(path, mode)
|
|
71
|
+
return mode_of(path) == mode
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def read_text(path: Path) -> str:
|
|
75
|
+
refuse_symlink(path)
|
|
76
|
+
return path.read_text(encoding="utf-8")
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def unquote(value: str) -> str:
|
|
80
|
+
text = value.strip()
|
|
81
|
+
if len(text) >= 2 and text[0] == text[-1] and text[0] in {'"', "'"}:
|
|
82
|
+
return text[1:-1]
|
|
83
|
+
return text
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def parse_env(text: str) -> dict[str, str]:
|
|
87
|
+
found: dict[str, str] = {}
|
|
88
|
+
for line in text.splitlines():
|
|
89
|
+
stripped = line.strip()
|
|
90
|
+
if not stripped or stripped.startswith("#"):
|
|
91
|
+
continue
|
|
92
|
+
match = _ASSIGN.match(stripped)
|
|
93
|
+
if match is not None:
|
|
94
|
+
found[match.group(1)] = unquote(match.group(2))
|
|
95
|
+
return found
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def merge_env(text: str, updates: dict[str, str], *, replace: set[str]) -> tuple[str, dict[str, str]]:
|
|
99
|
+
"""Append missing keys. A different value is a conflict unless `replace` names it.
|
|
100
|
+
|
|
101
|
+
On conflict the original text is returned unchanged.
|
|
102
|
+
"""
|
|
103
|
+
lines = text.splitlines(keepends=True)
|
|
104
|
+
seen: set[str] = set()
|
|
105
|
+
conflicts: dict[str, str] = {}
|
|
106
|
+
rewritten: list[str] = []
|
|
107
|
+
for line in lines:
|
|
108
|
+
match = _ASSIGN.match(line.strip())
|
|
109
|
+
key = match.group(1) if match is not None else None
|
|
110
|
+
if key in updates and key not in seen:
|
|
111
|
+
seen.add(key)
|
|
112
|
+
current = unquote(match.group(2)) if match is not None else ""
|
|
113
|
+
if current == updates[key]:
|
|
114
|
+
rewritten.append(line if line.endswith("\n") else line + "\n")
|
|
115
|
+
elif key in replace:
|
|
116
|
+
prefix = "export " if line.strip().startswith("export ") else ""
|
|
117
|
+
rewritten.append(f"{prefix}{key}={updates[key]}\n")
|
|
118
|
+
else:
|
|
119
|
+
conflicts[key] = current
|
|
120
|
+
rewritten.append(line if line.endswith("\n") else line + "\n")
|
|
121
|
+
else:
|
|
122
|
+
rewritten.append(line if line.endswith("\n") else line + "\n")
|
|
123
|
+
if conflicts:
|
|
124
|
+
return text, conflicts
|
|
125
|
+
body = "".join(rewritten)
|
|
126
|
+
missing = [key for key in updates if key not in seen]
|
|
127
|
+
if missing:
|
|
128
|
+
if body and not body.endswith("\n"):
|
|
129
|
+
body += "\n"
|
|
130
|
+
for key in updates:
|
|
131
|
+
if key in missing:
|
|
132
|
+
body += f"{key}={updates[key]}\n"
|
|
133
|
+
return body, {}
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def inside_work_tree(cwd: Path) -> bool:
|
|
137
|
+
try:
|
|
138
|
+
proc = subprocess.run(
|
|
139
|
+
["git", "rev-parse", "--is-inside-work-tree"],
|
|
140
|
+
cwd=str(cwd),
|
|
141
|
+
check=False,
|
|
142
|
+
capture_output=True,
|
|
143
|
+
text=True,
|
|
144
|
+
)
|
|
145
|
+
except OSError:
|
|
146
|
+
return False
|
|
147
|
+
return proc.returncode == 0 and proc.stdout.strip() == "true"
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def env_is_ignored(cwd: Path) -> bool:
|
|
151
|
+
try:
|
|
152
|
+
proc = subprocess.run(
|
|
153
|
+
["git", "check-ignore", "-q", "--", ".env"],
|
|
154
|
+
cwd=str(cwd),
|
|
155
|
+
check=False,
|
|
156
|
+
capture_output=True,
|
|
157
|
+
)
|
|
158
|
+
except OSError:
|
|
159
|
+
return False
|
|
160
|
+
return proc.returncode == 0
|