ample-receipts-client 0.2.0rc3__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.
- ample_receipts_client-0.2.0rc3/LICENSE +202 -0
- ample_receipts_client-0.2.0rc3/PKG-INFO +357 -0
- ample_receipts_client-0.2.0rc3/README.md +332 -0
- ample_receipts_client-0.2.0rc3/pyproject.toml +80 -0
- ample_receipts_client-0.2.0rc3/src/ample_receipts_client/__init__.py +521 -0
- ample_receipts_client-0.2.0rc3/src/ample_receipts_client/__main__.py +6 -0
- ample_receipts_client-0.2.0rc3/src/ample_receipts_client/_cli_parser.py +28 -0
- ample_receipts_client-0.2.0rc3/src/ample_receipts_client/_httplib.py +131 -0
- ample_receipts_client-0.2.0rc3/src/ample_receipts_client/_vendored_ed25519.py +256 -0
- ample_receipts_client-0.2.0rc3/src/ample_receipts_client/_vendored_jcs.py +109 -0
- ample_receipts_client-0.2.0rc3/src/ample_receipts_client/_vendored_merkle.py +130 -0
- ample_receipts_client-0.2.0rc3/src/ample_receipts_client/_version.py +3 -0
- ample_receipts_client-0.2.0rc3/src/ample_receipts_client/ack.py +452 -0
- ample_receipts_client-0.2.0rc3/src/ample_receipts_client/app.py +641 -0
- ample_receipts_client-0.2.0rc3/src/ample_receipts_client/builder.py +513 -0
- ample_receipts_client-0.2.0rc3/src/ample_receipts_client/capture.py +234 -0
- ample_receipts_client-0.2.0rc3/src/ample_receipts_client/cli.py +410 -0
- ample_receipts_client-0.2.0rc3/src/ample_receipts_client/commit.py +260 -0
- ample_receipts_client-0.2.0rc3/src/ample_receipts_client/config.py +165 -0
- ample_receipts_client-0.2.0rc3/src/ample_receipts_client/connect.py +116 -0
- ample_receipts_client-0.2.0rc3/src/ample_receipts_client/decode.py +203 -0
- ample_receipts_client-0.2.0rc3/src/ample_receipts_client/demo/__init__.py +40 -0
- ample_receipts_client-0.2.0rc3/src/ample_receipts_client/demo/__main__.py +6 -0
- ample_receipts_client-0.2.0rc3/src/ample_receipts_client/demo/cli.py +335 -0
- ample_receipts_client-0.2.0rc3/src/ample_receipts_client/demo/files.py +187 -0
- ample_receipts_client-0.2.0rc3/src/ample_receipts_client/demo/run.py +349 -0
- ample_receipts_client-0.2.0rc3/src/ample_receipts_client/demo/upstream.py +133 -0
- ample_receipts_client-0.2.0rc3/src/ample_receipts_client/f1.py +189 -0
- ample_receipts_client-0.2.0rc3/src/ample_receipts_client/folder.py +537 -0
- ample_receipts_client-0.2.0rc3/src/ample_receipts_client/handover.py +171 -0
- ample_receipts_client-0.2.0rc3/src/ample_receipts_client/held_acks.py +140 -0
- ample_receipts_client-0.2.0rc3/src/ample_receipts_client/hold.py +301 -0
- ample_receipts_client-0.2.0rc3/src/ample_receipts_client/notices.py +209 -0
- ample_receipts_client-0.2.0rc3/src/ample_receipts_client/parse.py +537 -0
- ample_receipts_client-0.2.0rc3/src/ample_receipts_client/py.typed +0 -0
- ample_receipts_client-0.2.0rc3/src/ample_receipts_client/record.py +814 -0
- ample_receipts_client-0.2.0rc3/src/ample_receipts_client/redact.py +129 -0
- ample_receipts_client-0.2.0rc3/src/ample_receipts_client/reveal.py +744 -0
- ample_receipts_client-0.2.0rc3/src/ample_receipts_client/salts.py +218 -0
- ample_receipts_client-0.2.0rc3/src/ample_receipts_client/service.py +60 -0
- ample_receipts_client-0.2.0rc3/src/ample_receipts_client/sign.py +320 -0
- ample_receipts_client-0.2.0rc3/src/ample_receipts_client/spool.py +1320 -0
- ample_receipts_client-0.2.0rc3/src/ample_receipts_client/statement.py +343 -0
- ample_receipts_client-0.2.0rc3/src/ample_receipts_client/submit.py +566 -0
- ample_receipts_client-0.2.0rc3/src/ample_receipts_client/submitter.py +2089 -0
- ample_receipts_client-0.2.0rc3/src/ample_receipts_client/tee.py +931 -0
- ample_receipts_client-0.2.0rc3/src/ample_receipts_client/tee_httpx2.py +184 -0
- ample_receipts_client-0.2.0rc3/src/ample_receipts_client/vault.py +1719 -0
- ample_receipts_client-0.2.0rc3/src/ample_receipts_client/wire.py +235 -0
|
@@ -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 2026 ISRM Labs AB
|
|
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.
|
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: ample-receipts-client
|
|
3
|
+
Version: 0.2.0rc3
|
|
4
|
+
Summary: Ample receipts client library: an httpx transport tee that records each call for a receipt.
|
|
5
|
+
Project-URL: Homepage, https://ample.isrm.ai/receipts
|
|
6
|
+
Author: ISRM Labs AB
|
|
7
|
+
Maintainer: ISRM Labs AB
|
|
8
|
+
License-Expression: Apache-2.0
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: ample,audit,ed25519,httpx,llm,receipts,transparency-log
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Topic :: Security :: Cryptography
|
|
18
|
+
Classifier: Typing :: Typed
|
|
19
|
+
Requires-Python: >=3.12
|
|
20
|
+
Requires-Dist: cryptography<51,>=50.0.0
|
|
21
|
+
Requires-Dist: httpx<0.29,>=0.27
|
|
22
|
+
Provides-Extra: httpx2
|
|
23
|
+
Requires-Dist: httpx2<2.17,>=2.16.0; extra == 'httpx2'
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
|
|
26
|
+
# ample-receipts-client
|
|
27
|
+
|
|
28
|
+
The client library of Ample receipts. This release holds the **transport tee** (an
|
|
29
|
+
httpx and an `httpx2` transport that sits under a provider client, records each HTTP
|
|
30
|
+
attempt and changes nothing about the call), **`record()`** for every other client, the
|
|
31
|
+
**spool**, the statement **builder** with your salt key and client key, the client key's
|
|
32
|
+
**introduction** request, the **submitter** with its ack check and kept acks, the
|
|
33
|
+
**reveal**, and the opt-in **vault**. It is Apache-2.0, by ISRM Labs AB. It talks only to the
|
|
34
|
+
receipts service you name: it has no default service address (see "Changes before the first
|
|
35
|
+
release" below).
|
|
36
|
+
|
|
37
|
+
```sh
|
|
38
|
+
pip install ample-receipts-client # Python 3.12
|
|
39
|
+
pip install "ample-receipts-client[httpx2]" # with the httpx2 tee
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
This version is a release candidate, not a stable release; a stable release follows. Pin the
|
|
43
|
+
exact version you install (`ample-receipts-client==` and the version this page names).
|
|
44
|
+
|
|
45
|
+
It depends on `httpx` and `cryptography`, each held to the versions it was tested against
|
|
46
|
+
(`httpx>=0.27,<0.29`, `cryptography>=50.0.0,<51`): the tee uses httpx's own content decoders, which
|
|
47
|
+
are private to httpx, so a newer httpx is allowed only after a test run on it. Pin them in your own
|
|
48
|
+
lock file as you do for the rest of your application.
|
|
49
|
+
|
|
50
|
+
## Quick start
|
|
51
|
+
|
|
52
|
+
The operator of the receipts service you use gives you your tenant id, your tenant's URL at the
|
|
53
|
+
service, your API key (in a file only you can read) and the service's ledger public keys. Make the
|
|
54
|
+
folder your app uses, once:
|
|
55
|
+
|
|
56
|
+
```sh
|
|
57
|
+
ample-receipts init --dir /var/lib/myapp/receipts --tenant acme \
|
|
58
|
+
--service-url https://receipts.example.com/t/acme \
|
|
59
|
+
--api-key-file /run/secrets/receipts-api-key --ledger-keys ledger-public.json
|
|
60
|
+
ample-receipts status --dir /var/lib/myapp/receipts
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
`init` sends nothing. It makes your client key and salt key (new files, mode 0600) and
|
|
64
|
+
`receipts.json`, which names every file the library reads. It never prints a key and never
|
|
65
|
+
overwrites one. Back up `client.key` and `salt.key`: nobody can make them again. If the service's
|
|
66
|
+
certificate comes from a private CA, add `--ca-file <private-ca.pem>`. `status` checks the service
|
|
67
|
+
and counts the calls recorded and acknowledged; it sends nothing.
|
|
68
|
+
|
|
69
|
+
In your app:
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
import ample_receipts_client as ar
|
|
73
|
+
import openai
|
|
74
|
+
|
|
75
|
+
receipts = ar.setup(dir="/var/lib/myapp/receipts") # or set AMPLE_RECEIPTS_DIR and call ar.setup()
|
|
76
|
+
client = openai.OpenAI(http_client=receipts.httpx2_client()) # needs the httpx2 extra
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
`setup()` reads the folder, reaches the service once over verified TLS, introduces your client key
|
|
80
|
+
and starts sending in the background; if any step fails, it raises and starts nothing.
|
|
81
|
+
`receipts.httpx_client()` and `receipts.async_httpx_client()` give httpx clients, and
|
|
82
|
+
`receipts.httpx2_client()` and `receipts.async_httpx2_client()` give `httpx2` clients (the current
|
|
83
|
+
`openai` and `anthropic` SDKs take one as `http_client=`). Each gives a new client with its own tee.
|
|
84
|
+
The SDK form is the documented wiring, checked earlier at `openai` 3.39.0 and `anthropic` 2.3.0;
|
|
85
|
+
this release did not test it again. `AMPLE_RECEIPTS_DIR` is the only environment variable the
|
|
86
|
+
library reads, and only inside `setup()`.
|
|
87
|
+
|
|
88
|
+
At a normal exit the library seals what it recorded, sends what is waiting, checks each ack and
|
|
89
|
+
writes the acks to `held-acks.jsonl` in the folder; `receipts.close()` does the same at once. Calls
|
|
90
|
+
not yet acknowledged stay in the folder and are sent at the next start. A plain SIGTERM runs no exit
|
|
91
|
+
code: let your server turn it into a normal exit, or call `receipts.close()` in your shutdown hook.
|
|
92
|
+
With several worker processes, call `setup()` in each worker after the fork.
|
|
93
|
+
|
|
94
|
+
For your auditor:
|
|
95
|
+
|
|
96
|
+
```sh
|
|
97
|
+
ample-receipts handover --dir /var/lib/myapp/receipts --out for-auditor
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
It writes your held acks, your client public keys and the ledger public keys into the new folder,
|
|
101
|
+
never a secret, and prints the verifier's command for your auditor.
|
|
102
|
+
|
|
103
|
+
## Wiring it by hand
|
|
104
|
+
|
|
105
|
+
The partner guide (`integration.md`, which Ample gives you with each release) gives every step in
|
|
106
|
+
order, each with the requirement it rests on: make the keys, introduce the client key, record,
|
|
107
|
+
submit, keep the acks, and hand the auditor your client public keys. In short:
|
|
108
|
+
|
|
109
|
+
```python
|
|
110
|
+
import httpx
|
|
111
|
+
from ample_receipts_client import (
|
|
112
|
+
CoreStatementBuilder, HttpxPoster, Spool, Submitter,
|
|
113
|
+
load_client_signing_key_file, load_ledger_public_keys, load_salt_key_file, service_url,
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
builder = CoreStatementBuilder(
|
|
117
|
+
salt_key=load_salt_key_file("salt-key.json"),
|
|
118
|
+
signer=load_client_signing_key_file("client-key.json"),
|
|
119
|
+
)
|
|
120
|
+
spool = Spool("receipts.spool", builder)
|
|
121
|
+
client = httpx.Client(transport=spool.transport()) # each attempt becomes a statement
|
|
122
|
+
|
|
123
|
+
# the root of the receipts service you use, https only; required (there is no default)
|
|
124
|
+
base_url = service_url(tenant, "https://receipts.example.com/receipts")
|
|
125
|
+
submitter = Submitter(spool, poster=HttpxPoster(base_url, api_key),
|
|
126
|
+
ledger_keys=load_ledger_public_keys(ledger_keys_bytes))
|
|
127
|
+
submitter.start()
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
`service_url(tenant, root)` gives `<root>/t/<tenant>` and refuses a root that is not `https`. If
|
|
131
|
+
your service's certificate comes from a private CA (an internal mesh, say), keep `https` and give
|
|
132
|
+
the poster an httpx client that trusts that CA; never turn verification off:
|
|
133
|
+
|
|
134
|
+
```python
|
|
135
|
+
import ssl
|
|
136
|
+
private = httpx.Client(timeout=30, verify=ssl.create_default_context(cafile="private-ca.pem"))
|
|
137
|
+
poster = HttpxPoster(base_url, api_key, client=private)
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Without `client=` the poster uses httpx's own CA bundle (certifi's, or the one `SSL_CERT_FILE` or
|
|
141
|
+
`SSL_CERT_DIR` names, not the operating system's store), which holds no private CA.
|
|
142
|
+
|
|
143
|
+
Take the tee from the spool (`spool.transport()`, `Httpx2TeeTransport.for_spool(spool)`):
|
|
144
|
+
a bare `TeeTransport(inner, on_capture=...)` only hands each capture to your callback and
|
|
145
|
+
makes no statement and no G3 hold (MUST-142).
|
|
146
|
+
|
|
147
|
+
For a client built on `httpx2` (the current `openai` and `anthropic` SDKs), install the `httpx2`
|
|
148
|
+
extra (`ample-receipts-client[httpx2]`) and use the `httpx2` tee, the same tee on the same code path
|
|
149
|
+
(unit R05b):
|
|
150
|
+
|
|
151
|
+
```python
|
|
152
|
+
import httpx2, openai
|
|
153
|
+
from ample_receipts_client import Httpx2TeeTransport
|
|
154
|
+
|
|
155
|
+
client = openai.OpenAI(http_client=httpx2.Client(transport=Httpx2TeeTransport.for_spool(spool)))
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Without the extra, the package never imports `httpx2`. One tee per client: closing a client closes
|
|
159
|
+
its tee and the transport the tee wraps. An app that calls `httpx2.alias_httpx()` before importing
|
|
160
|
+
the library gets `httpx2` from `import httpx`; the library notices, and `TeeTransport` then runs the
|
|
161
|
+
`httpx2` code path with `httpx2`'s decoders, giving the same records as `Httpx2TeeTransport`.
|
|
162
|
+
|
|
163
|
+
Each capture follows the call-receipt spec (the specification Ample gives you with each release)
|
|
164
|
+
wherever it touches it:
|
|
165
|
+
|
|
166
|
+
- One record per HTTP attempt: retries and redirects each make their own.
|
|
167
|
+
- The wire kind (`CHAT_COMPLETIONS`, `RESPONSES`, `MESSAGES`, `OPAQUE`) comes
|
|
168
|
+
from the method and the raw path alone; the terminal follows the spec's
|
|
169
|
+
order (`TRANSPORT_FAILURE`, `OUTCOME_UNKNOWN`, `HTTP_ERROR`, `COMPLETED`).
|
|
170
|
+
- Bodies are recorded after content-decoding, with httpx's own decoders, as
|
|
171
|
+
`DECODED` or (an unsupported or failed coding) `WIRE`; a body over the
|
|
172
|
+
capture limit (16 MiB by default, never less) is `NOT_CAPTURED`.
|
|
173
|
+
- Header values are their wire bytes read as ISO-8859-1 (one code point per
|
|
174
|
+
byte, as httpx and httpx2 read them): `caf\xe9` is committed as `café`,
|
|
175
|
+
the UTF-8 bytes `caf\xc3\xa9` as `café`, so the same bytes always give
|
|
176
|
+
the same commitment.
|
|
177
|
+
- Headers are read by two closed allow-lists only, so credential headers are
|
|
178
|
+
never read. Credential query values (the spec's 20 names, plus any the
|
|
179
|
+
customer adds) and URL user-info are replaced by `MASKED` before the head
|
|
180
|
+
and upstream parts are recorded.
|
|
181
|
+
- G3: with a `hold_hook` set and the hold on, everything from the hold point
|
|
182
|
+
waits for the hook, at most `hold_deadline_ms` (250 by default, 1 to 10,000)
|
|
183
|
+
from that point, and is then released either way; anything but a hook that
|
|
184
|
+
returned in time is recorded `MISSED`. With no hook it never holds.
|
|
185
|
+
The terminator scan holds a line, and an event's data, only up to the
|
|
186
|
+
capture limit; past it the scan stops for that reply
|
|
187
|
+
(`terminator:EventTooLarge` in `capture_errors`): nothing is held before
|
|
188
|
+
the body's end, where the hold still applies as for any reply with no
|
|
189
|
+
terminator, and the terminal is `OUTCOME_UNKNOWN` unless an earlier
|
|
190
|
+
rule applies. The
|
|
191
|
+
async hold waits on asyncio; under another event loop it fails open and
|
|
192
|
+
records the miss.
|
|
193
|
+
- Only httpx- and `httpx2`-based clients are recorded live; every other client is recorded
|
|
194
|
+
after the fact (below). WebSocket/realtime and batch APIs are out of scope.
|
|
195
|
+
|
|
196
|
+
**After the fact** (`ample_receipts_client.record`, unit R18): for any other client (another
|
|
197
|
+
HTTP library, gRPC, another language), hand `Recorder.record` the request and the response your
|
|
198
|
+
client already made. It runs the tee's own rules on them (wire kind, reply form, masking, the
|
|
199
|
+
allow-lists) and builds the same signed statement with capture basis `REPORTED_AFTER_THE_FACT`
|
|
200
|
+
and `hold` `OFF`; each part you do not supply is `NOT_CAPTURED`, and the terminal and times are
|
|
201
|
+
your report (with no terminal given it follows the spec's order from what you supplied). A value
|
|
202
|
+
it cannot take (a wrong type, text that cannot be encoded, a terminal that contradicts the
|
|
203
|
+
response) raises `RecordInputError` or `TypeError` and records nothing; any other failure is
|
|
204
|
+
recorded, never raised. A header field whose name is empty or not ASCII is skipped, its value
|
|
205
|
+
unread: no allow-list name is such a name. The method is committed as sent, so `post` is not
|
|
206
|
+
`POST`, and such a call is `OPAQUE` (MUST-9). Give it a spool file of its own, with G3 off
|
|
207
|
+
(`Recorder.open` does both). Each `headers` is a list of `(name, value)` pairs in the order
|
|
208
|
+
sent or received, or a mapping, whose order is taken as that order (MUST-44); `recorder.spool`
|
|
209
|
+
is the spool a submitter sends:
|
|
210
|
+
|
|
211
|
+
```python
|
|
212
|
+
from ample_receipts_client import Recorder, ReceivedResponse, SentRequest
|
|
213
|
+
|
|
214
|
+
recorder = Recorder.open("after.spool", salt_key=salt_key, signer=client_key)
|
|
215
|
+
recorder.record(
|
|
216
|
+
SentRequest("POST", url, headers=sent_headers, body=sent_body),
|
|
217
|
+
ReceivedResponse(200, headers=received_headers, body=received_body),
|
|
218
|
+
)
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
`python -m ample_receipts_client.submit pairs.jsonl --spool after.spool --salt-key FILE
|
|
222
|
+
--client-key FILE` does the same for a file of pairs (one JSON object per line, bodies in base64;
|
|
223
|
+
the partner guide's `record()` section gives every member) and, with `--service URL --api-key-file FILE
|
|
224
|
+
--ledger-keys FILE`, sends the spool's statements through the submitter. A malformed line is
|
|
225
|
+
refused with its line number and the rest are still recorded. It prints counts only and reads the
|
|
226
|
+
API key from a file, never from the command line.
|
|
227
|
+
|
|
228
|
+
**Reveal** (`ample_receipts_client.reveal`, unit R17; spec 5.8 and 6): to show an auditor one
|
|
229
|
+
part of one call, `python -m ample_receipts_client.reveal` derives that part's salt again from the
|
|
230
|
+
salt key file (MUST-65), takes the part's bytes from the opt-in vault (`--vault-dir` and
|
|
231
|
+
`--vault-key-file`) or from the app's own copy (`--data-file`), and checks the reveal against the
|
|
232
|
+
call receipt as the auditor's `reveal-call` will (MUST-62, and the receipt's own members and
|
|
233
|
+
formats, MUST-126 step 3) before it writes anything. The receipt comes from `--receipt` (its
|
|
234
|
+
canonical payload as stored) or from `--held-acks FILE --statement-id ID`. Every key comes from a
|
|
235
|
+
file; no option takes a key's or a salt's value. On R07's vector S1, with its TEST ONLY salt key:
|
|
236
|
+
|
|
237
|
+
```
|
|
238
|
+
$ python -m ample_receipts_client.reveal --salt-key-file keys/salt.key --receipt s1.receipt \
|
|
239
|
+
--part response_body --data-file response.bin --out reveal-s1
|
|
240
|
+
MATCH: part response_body of statement d962c036-24d1-4c5e-b6ee-fddd31e3bd82 is revealed in reveal-s1
|
|
241
|
+
receipt reveal-s1/receipt.txt
|
|
242
|
+
data reveal-s1/response_body.bin
|
|
243
|
+
salt reveal-s1/response_body.salt
|
|
244
|
+
The auditor checks it offline, with no salt key, with:
|
|
245
|
+
python -m ample_replay.verify reveal-call --receipt reveal-s1/receipt.txt --part response_body --data-file reveal-s1/response_body.bin --salt-file reveal-s1/response_body.salt
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
The directory is new (mode 0700) and each file is 0600; only the one part's salt leaves, never
|
|
249
|
+
the salt key (MUST-67). A reveal that would not match writes nothing, prints 5.8's reason (for
|
|
250
|
+
other data, `MISMATCH: COMMITMENT_DIFFERS`) and exits 1; an input it refuses (a receipt it cannot
|
|
251
|
+
read, a salt key that is not the statement's) exits 2.
|
|
252
|
+
|
|
253
|
+
The **spool** (`ample_receipts_client.spool.Spool`, unit R11) is the local
|
|
254
|
+
store the tee's hook writes to: one SQLite file in WAL mode, fsynced before the
|
|
255
|
+
reply's end is released (G3). Each process gets its own instance id and
|
|
256
|
+
sequence (1, 2, 3, with a hash chain), a forked child a new one, and several
|
|
257
|
+
processes can share one spool file. A record left by a killed process is
|
|
258
|
+
numbered by the next instance as `MISSED`; damage found inside the file is
|
|
259
|
+
named by a `SPOOL_DAMAGED` declared loss. A deleted spool (a lost tail) is not
|
|
260
|
+
detected, nor is a process that dies while its spool keeps failing (the numbers
|
|
261
|
+
it would have declared lost were held in memory). The statements themselves (commitments, salts, signatures) come from
|
|
262
|
+
the spool's builder (`ample_receipts_client.builder.CoreStatementBuilder`, unit R12):
|
|
263
|
+
|
|
264
|
+
```python
|
|
265
|
+
spool = Spool("receipts.spool", builder)
|
|
266
|
+
client = httpx.Client(transport=spool.transport(httpx.HTTPTransport()))
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
**Keys** (spec 6 and 7): `SaltKey.generate(tenant).write_file(path)` and
|
|
270
|
+
`ClientKey.generate().write_file(path)` make the two key files once, each new and mode 0600
|
|
271
|
+
(MUST-64, MUST-68, MUST-69, MUST-71); `load_salt_key_file` and `load_client_signing_key_file`
|
|
272
|
+
read them back and refuse a file group or other can read. `introduction_request(client_key,
|
|
273
|
+
tenant)` builds the introduction and `rotation_request(previous_key, new_key, tenant)` a rotation;
|
|
274
|
+
`submitter.send_key_request(request)` journals it, posts it through the submitter's poster to the
|
|
275
|
+
service's `/v1/client-keys/introductions` or `/v1/client-keys/rotations` with the tenant API key,
|
|
276
|
+
sends the same bytes again after a crash or a lost answer, checks the ack with
|
|
277
|
+
`check_ack(ack, pinned_keys=ledger_keys, key_request=request)` and keeps it beside the
|
|
278
|
+
statements' acks, a failed one marked and alarmed (MUST-77, MUST-93, MUST-107, MUST-108). Its
|
|
279
|
+
result is `ACKNOWLEDGED`, `ACK_FAILED`, `REFUSED` with the service's reason, `NOT_WRITTEN` or
|
|
280
|
+
`OUTCOME_UNKNOWN`. `client_keys_file_text([client_key])` is the `ample.call-client-keys.v1` file you
|
|
281
|
+
hand your auditor (MUST-80).
|
|
282
|
+
|
|
283
|
+
**Submission** (spec 9 and 11): `Submitter(spool, poster=HttpxPoster(service_url, api_key),
|
|
284
|
+
ledger_keys=...)` sends one spool's statements to `<service_url>/v1/statements` and checks
|
|
285
|
+
every ack under the pinned ledger keys; `start()` runs it in the background, `drain(timeout)`
|
|
286
|
+
until nothing waits (call `spool.flush()` first at shutdown, since the submitter sends only
|
|
287
|
+
sealed statements); `acks()` and `key_acks()` list the kept acks and `write_held_acks(path)`
|
|
288
|
+
writes the passing ones of both, one per line in `link.seq` order, mode 0600 even over an
|
|
289
|
+
existing file, and refuses a symbolic link (MUST-93, MUST-107, MUST-108). `drain()` makes passes
|
|
290
|
+
of its own, so it still sends after `stop()`. Give each submitter its own `HttpxPoster`: a poster
|
|
291
|
+
takes no lock, and one without `client=` makes its httpx client on its first post. `python -m
|
|
292
|
+
ample_receipts_client.held_acks --spool FILE --out FILE` writes the same held-acks file from a spool
|
|
293
|
+
without a submitter (a new file, 0600), and with `--spool` once per spool it writes one file of
|
|
294
|
+
several spools' acks (an app's live and after-the-fact spools), each ack once; the auditor gives
|
|
295
|
+
it to the verifier with `--held-acks`, or to `python -m ample_replay.verify.audit` (MUST-108,
|
|
296
|
+
MUST-125). `read_statements(path)` lists a spool's statements read-only, with no `Spool` and no
|
|
297
|
+
key; it never changes the database file, but for a closed or copied spool SQLite makes the
|
|
298
|
+
`-wal` and `-shm` files beside it, so the directory must be writable. The partner guide (`integration.md`) names each field of
|
|
299
|
+
`KeptAck`, `KeptKeyAck`, `SpooledStatement`, `Backlog`, `RecordResult` and `Alarm`, and shows
|
|
300
|
+
`check_ack(ack, pinned_keys=..., statement=..., signature=...)` for a statement's ack and
|
|
301
|
+
`check_ack(ack, pinned_keys=..., key_request=kept.key_request)` for a kept key ack.
|
|
302
|
+
|
|
303
|
+
**Demo** (`ample_receipts_client.demo`, the pilot's R23): `python -m ample_receipts_client.demo`
|
|
304
|
+
makes receipts with this library alone (it imports the library, the standard library and httpx),
|
|
305
|
+
against a mock model inside the process, so a clean venv holding only this wheel and the
|
|
306
|
+
verifier's can show the whole path from a call to the auditor's check:
|
|
307
|
+
|
|
308
|
+
```
|
|
309
|
+
$ ROOT=https://receipts.example.com/receipts
|
|
310
|
+
$ python -m ample_receipts_client.demo init --dir demo --tenant acme-pilot \
|
|
311
|
+
--service-url "$ROOT/t/acme-pilot" \
|
|
312
|
+
--api-key-file api-key --ledger-keys ledger-public-keys.json --vault
|
|
313
|
+
$ python -m ample_receipts_client.demo run --dir demo --calls 6
|
|
314
|
+
$ python -m ample_receipts_client.demo handover --dir demo --out for-auditor
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
`init` talks to the `--service-url` it is given, which is required: your tenant's URL at the
|
|
318
|
+
receipts service you use, `<root>/t/<tenant>` as `service_url(tenant, root)` makes it, `https`
|
|
319
|
+
(plain `http` only to this machine). It makes
|
|
320
|
+
the client key and the salt key (and with `--vault` the vault key) in `--dir`, each new and mode
|
|
321
|
+
0600, and `demo.json`, which names every file the demo reads; it prints no key and
|
|
322
|
+
never overwrites one. A service with a certificate from a public CA needs no CA file:
|
|
323
|
+
httpx's default bundle verifies it (certifi's, or the one `SSL_CERT_FILE` or `SSL_CERT_DIR`
|
|
324
|
+
names, not the operating system's store). `--ca-file` names another PEM bundle, such as your
|
|
325
|
+
private CA's; it is the httpx client's `verify` for every request, and nothing turns verification off.
|
|
326
|
+
`run` first reaches the service (`GET /v1/keys` under the tenant API key, read from its file) and
|
|
327
|
+
stops with the TLS error, before any call, when the certificate does not verify. It introduces
|
|
328
|
+
the client key on the first run (`send_key_request`; a later run finds the kept ack), makes
|
|
329
|
+
`--calls` calls through the tee to the mock upstream (`https://api.example.test/v1/chat/completions`,
|
|
330
|
+
answered inside the process with fixed JSON and event-stream replies; every `--stream-every`-th
|
|
331
|
+
call streams, 2 by default) with G3 on at 250 ms, drains the submitter, checks every ack, and
|
|
332
|
+
writes `held-acks.jsonl` and `client-keys.json`. It prints counts, the receipts' ledger range and
|
|
333
|
+
the G3 misses, never a text, a body or a key, and exits 1 if any call is left unacknowledged.
|
|
334
|
+
`handover` copies the held acks, the client public keys and the ledger public keys into a new
|
|
335
|
+
directory with one reveal (`--reveal-call N`, `--reveal-part`, from the vault or the demo's own
|
|
336
|
+
copy of the fixture bytes; `--no-reveal` for none), never a private key, the salt key, the vault
|
|
337
|
+
key or the API key, and prints the auditor's `python -m ample_replay.verify.audit` command for the
|
|
338
|
+
tenant bundle the service's operator exports.
|
|
339
|
+
|
|
340
|
+
The library commits, signs and spools statements on the machine that makes the calls. It sends
|
|
341
|
+
to the receipts service the customer names only the statements with their client signatures,
|
|
342
|
+
through the submitter (`ample_receipts_client.submitter`, or `python -m
|
|
343
|
+
ample_receipts_client.submit --service URL`), and the client-key requests
|
|
344
|
+
(`Submitter.send_key_request`), both under the tenant API key. A statement carries commitments, never a part's data (spec 5); no
|
|
345
|
+
salt, salt key or private key is sent.
|
|
346
|
+
|
|
347
|
+
## Changes before the first release
|
|
348
|
+
|
|
349
|
+
These changes came before the first release on PyPI, so no published version behaves
|
|
350
|
+
otherwise.
|
|
351
|
+
|
|
352
|
+
- **The service root is required (breaks).** Each customer runs the receipts service on its own
|
|
353
|
+
infrastructure, so the library no longer sends anywhere by default. `DEFAULT_SERVICE_ROOT` is
|
|
354
|
+
gone from the package, `service_url(tenant, root)` takes the root as a required argument
|
|
355
|
+
(`service_url(tenant)` is a `TypeError`), and the demo's `init` requires `--service-url`. Pass
|
|
356
|
+
the root of the service you use; it stays `https` only, and a private CA is trusted through the
|
|
357
|
+
httpx client you give `HttpxPoster` (above).
|