aetherproof 0.2.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.
@@ -0,0 +1,88 @@
1
+ Metadata-Version: 2.4
2
+ Name: aetherproof
3
+ Version: 0.2.0
4
+ Summary: Cryptographic, tamper-evident execution receipts for any AI model
5
+ Author: Pulkit
6
+ License: AGPL-3.0-or-later
7
+ Project-URL: Homepage, https://github.com/pulkit6732/aetherproof
8
+ Project-URL: Repository, https://github.com/pulkit6732/aetherproof
9
+ Project-URL: Issues, https://github.com/pulkit6732/aetherproof/issues
10
+ Keywords: ai,audit,receipt,ed25519,tamper-evident,compliance,eu-ai-act,llm,ollama
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)
14
+ Classifier: Programming Language :: Python :: 3
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 :: Security :: Cryptography
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Requires-Python: >=3.9
23
+ Description-Content-Type: text/markdown
24
+ Requires-Dist: cryptography>=41.0
25
+ Provides-Extra: dev
26
+ Requires-Dist: pytest>=7; extra == "dev"
27
+ Requires-Dist: pytest-benchmark; extra == "dev"
28
+ Provides-Extra: test
29
+ Requires-Dist: pytest>=7; extra == "test"
30
+
31
+ # AetherProof
32
+
33
+ **Cryptographic, tamper-evident execution receipts for any AI model.**
34
+
35
+ One call generates a 128-byte Ed25519-signed receipt that proves what model ran
36
+ and what it produced — verifiable offline by anyone, with no server and no account.
37
+ Works with Claude, GPT, Gemini, or a local model via Ollama.
38
+
39
+ ## Install
40
+
41
+ ```bash
42
+ pip install aetherproof
43
+ ```
44
+
45
+ ## Drop-in: one line to a verified receipt
46
+
47
+ Run a local model and get its answer **plus** a signed, tamper-evident receipt —
48
+ no extra dependencies, no server:
49
+
50
+ ```python
51
+ import aetherproof
52
+
53
+ r = aetherproof.ollama("llama3", "Explain quantum tunneling")
54
+ print(r.text) # the model's answer
55
+ print(r.verify()) # True — cryptographically receipted
56
+ r.save("call.receipt")
57
+ ```
58
+
59
+ Cloud providers work the same way (`pip install openai` / `anthropic`):
60
+
61
+ ```python
62
+ r = aetherproof.openai("gpt-4o", "Summarise this contract.")
63
+ r = aetherproof.anthropic("claude-3-opus-20240229", "Explain GDPR Article 13")
64
+ ```
65
+
66
+ Already have a response? Receipt it directly:
67
+
68
+ ```python
69
+ receipt = aetherproof.for_anthropic(prompt, response_text, model="claude-3-opus-20240229")
70
+ print(receipt.verify()) # True
71
+ receipt.save("run.receipt")
72
+ ```
73
+
74
+ ## What a receipt proves
75
+
76
+ - **What ran** — a hash identifying the model.
77
+ - **What it produced** — a hash of the output; any change is detectable.
78
+ - **Tamper-evidence** — flip a single byte and verification fails.
79
+ - **Offline-verifiable** — anyone can check it with the public key; no server.
80
+ - **Portable** — the same 128-byte wire format verifies in Python, the Rust CLI,
81
+ and the AetherOS kernel.
82
+
83
+ The receipt can also ride **invisibly inside the model's own output text**
84
+ (`aetherproof.embed`), so the proof travels with the content.
85
+
86
+ ## License
87
+
88
+ AGPL-3.0-or-later. See [LICENSE](https://github.com/pulkit6732/aetherproof/blob/main/LICENSE).
@@ -0,0 +1,58 @@
1
+ # AetherProof
2
+
3
+ **Cryptographic, tamper-evident execution receipts for any AI model.**
4
+
5
+ One call generates a 128-byte Ed25519-signed receipt that proves what model ran
6
+ and what it produced — verifiable offline by anyone, with no server and no account.
7
+ Works with Claude, GPT, Gemini, or a local model via Ollama.
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ pip install aetherproof
13
+ ```
14
+
15
+ ## Drop-in: one line to a verified receipt
16
+
17
+ Run a local model and get its answer **plus** a signed, tamper-evident receipt —
18
+ no extra dependencies, no server:
19
+
20
+ ```python
21
+ import aetherproof
22
+
23
+ r = aetherproof.ollama("llama3", "Explain quantum tunneling")
24
+ print(r.text) # the model's answer
25
+ print(r.verify()) # True — cryptographically receipted
26
+ r.save("call.receipt")
27
+ ```
28
+
29
+ Cloud providers work the same way (`pip install openai` / `anthropic`):
30
+
31
+ ```python
32
+ r = aetherproof.openai("gpt-4o", "Summarise this contract.")
33
+ r = aetherproof.anthropic("claude-3-opus-20240229", "Explain GDPR Article 13")
34
+ ```
35
+
36
+ Already have a response? Receipt it directly:
37
+
38
+ ```python
39
+ receipt = aetherproof.for_anthropic(prompt, response_text, model="claude-3-opus-20240229")
40
+ print(receipt.verify()) # True
41
+ receipt.save("run.receipt")
42
+ ```
43
+
44
+ ## What a receipt proves
45
+
46
+ - **What ran** — a hash identifying the model.
47
+ - **What it produced** — a hash of the output; any change is detectable.
48
+ - **Tamper-evidence** — flip a single byte and verification fails.
49
+ - **Offline-verifiable** — anyone can check it with the public key; no server.
50
+ - **Portable** — the same 128-byte wire format verifies in Python, the Rust CLI,
51
+ and the AetherOS kernel.
52
+
53
+ The receipt can also ride **invisibly inside the model's own output text**
54
+ (`aetherproof.embed`), so the proof travels with the content.
55
+
56
+ ## License
57
+
58
+ AGPL-3.0-or-later. See [LICENSE](https://github.com/pulkit6732/aetherproof/blob/main/LICENSE).
@@ -0,0 +1,95 @@
1
+ """AetherProof — cryptographic AI execution audit.
2
+
3
+ Generates 128-byte Ed25519-signed receipts that satisfy EU AI Act §13(3)(c)
4
+ technical documentation requirements for automated decision-making systems.
5
+
6
+ Quick start::
7
+
8
+ import aetherproof
9
+
10
+ # One-liner: generate a receipt for any binary
11
+ receipt = aetherproof.generate(open("model.onnx", "rb").read())
12
+ print(receipt.verify()) # True
13
+ receipt.save("run.receipt")
14
+
15
+ # Context manager: wrap a full inference session
16
+ with aetherproof.Session(pid=1) as s:
17
+ output = my_model.predict(data)
18
+ s.record_output(output_bytes)
19
+ receipt = s.seal(model_path="model.onnx")
20
+
21
+ # Decorator: auto-generate receipt on every call
22
+ @aetherproof.audit(model_path="model.onnx")
23
+ def run_inference(data):
24
+ return model.predict(data)
25
+
26
+ Wire format (128 bytes) is identical to the AetherOS kernel — receipts generated
27
+ here can be verified by `aetherproof verify` CLI and the kernel's QEMU verifier.
28
+ """
29
+
30
+ from ._receipt import (
31
+ Receipt,
32
+ generate,
33
+ verify_bytes,
34
+ tamper_probe,
35
+ fnv1a,
36
+ RECEIPT_SIZE,
37
+ RECEIPT_MAGIC,
38
+ RECEIPT_VERSION,
39
+ )
40
+ from ._keys import (
41
+ SigningKey,
42
+ VerifyingKey,
43
+ dev_signing_key,
44
+ dev_verifying_key,
45
+ DEV_SIGNING_SEED,
46
+ )
47
+ from ._session import Session, audit
48
+ from ._watermark import embed, extract, has_watermark, verify_embedded, strip
49
+ from ._api import (
50
+ for_api_call,
51
+ for_anthropic,
52
+ for_openai,
53
+ for_gemini,
54
+ for_local_model,
55
+ for_rag_pipeline,
56
+ for_embedding,
57
+ for_image_gen,
58
+ StreamRecorder,
59
+ )
60
+ from ._integrations import (
61
+ TracedResponse,
62
+ ollama,
63
+ ollama_chat,
64
+ openai,
65
+ anthropic,
66
+ )
67
+
68
+ __version__ = "0.2.0"
69
+ __all__ = [
70
+ "Receipt",
71
+ "generate",
72
+ "verify_bytes",
73
+ "tamper_probe",
74
+ "fnv1a",
75
+ "SigningKey",
76
+ "VerifyingKey",
77
+ "dev_signing_key",
78
+ "dev_verifying_key",
79
+ "DEV_SIGNING_SEED",
80
+ "Session",
81
+ "audit",
82
+ "embed",
83
+ "extract",
84
+ "has_watermark",
85
+ "verify_embedded",
86
+ "strip",
87
+ "RECEIPT_SIZE",
88
+ "RECEIPT_MAGIC",
89
+ "RECEIPT_VERSION",
90
+ "TracedResponse",
91
+ "ollama",
92
+ "ollama_chat",
93
+ "openai",
94
+ "anthropic",
95
+ ]
@@ -0,0 +1,353 @@
1
+ """AetherProof API wrappers — generate receipts for any AI deployment type.
2
+
3
+ Fixes Tiger #1: the original generate() required a model binary file.
4
+ Most AI in production runs via API (Claude, GPT-4, Gemini, Llama, etc.)
5
+ where no binary is available. These wrappers create receipts for all cases.
6
+
7
+ Receipt field mapping for API calls:
8
+ binary_hash = FNV-1a of "provider/model_id" (identifies what model ran)
9
+ memory_hash = FNV-1a of response bytes (what the model produced)
10
+ syscall_count = number of API calls in this session
11
+ binary_len = len(request_bytes) (input size)
12
+ pid = user-supplied run/session ID
13
+
14
+ All wrappers produce a 128-byte receipt that is:
15
+ - Verifiable offline with the CLI
16
+ - Embeddable in output text via aetherproof.embed()
17
+ - Cross-language compatible with the Rust library
18
+ """
19
+ from __future__ import annotations
20
+ import json
21
+ import os
22
+ from typing import Optional, Union
23
+ from ._receipt import Receipt, generate, fnv1a
24
+ from ._keys import SigningKey
25
+
26
+
27
+ # ── Generic API call receipt ──────────────────────────────────────────────────
28
+
29
+ def for_api_call(
30
+ provider: str,
31
+ model_id: str,
32
+ request: Union[str, bytes, dict],
33
+ response: Union[str, bytes, dict],
34
+ *,
35
+ pid: int = 1,
36
+ call_count: int = 1,
37
+ signing_key: Optional[SigningKey] = None,
38
+ ) -> Receipt:
39
+ """Generate a receipt for any API-based AI inference call.
40
+
41
+ Works with any provider: Anthropic, OpenAI, Google, Cohere, Mistral, etc.
42
+
43
+ Args:
44
+ provider: Provider name, e.g. "anthropic", "openai", "google"
45
+ model_id: Model identifier, e.g. "claude-3-opus-20240229"
46
+ request: The request (str, bytes, or dict serialised to JSON)
47
+ response: The response (str, bytes, or dict serialised to JSON)
48
+ pid: Session/run ID (use a UUID or sequential counter)
49
+ call_count: Number of API calls in this session
50
+ signing_key: Ed25519 signing key (uses DEV key if None)
51
+
52
+ Returns:
53
+ Signed Receipt — verify with aetherproof verify <file> or receipt.verify()
54
+
55
+ Example::
56
+
57
+ client = anthropic.Anthropic()
58
+ message = client.messages.create(model="claude-3-opus-20240229", ...)
59
+ receipt = aetherproof.for_api_call(
60
+ "anthropic", "claude-3-opus-20240229",
61
+ request={"messages": [...]},
62
+ response=message.content[0].text,
63
+ )
64
+ receipt.save("call.receipt")
65
+ """
66
+ model_key = f"{provider.lower()}/{model_id}".encode()
67
+ request_b = _to_bytes(request)
68
+ response_b = _to_bytes(response)
69
+
70
+ return generate(
71
+ binary = model_key, # binary_hash = FNV-1a of "provider/model"
72
+ pid = pid,
73
+ memory_hash = fnv1a(response_b), # what the model produced
74
+ syscall_count = call_count,
75
+ signing_key = signing_key,
76
+ )
77
+
78
+
79
+ # ── Provider-specific helpers ─────────────────────────────────────────────────
80
+
81
+ def for_anthropic(
82
+ messages_or_prompt: Union[str, list, dict],
83
+ response_text: str,
84
+ *,
85
+ model: str = "claude-3-opus-20240229",
86
+ pid: int = 1,
87
+ call_count: int = 1,
88
+ signing_key: Optional[SigningKey] = None,
89
+ ) -> Receipt:
90
+ """Receipt for a Claude / Anthropic Messages API call.
91
+
92
+ Example::
93
+
94
+ import anthropic, aetherproof
95
+
96
+ client = anthropic.Anthropic()
97
+ message = client.messages.create(
98
+ model = "claude-3-opus-20240229",
99
+ max_tokens = 1024,
100
+ messages = [{"role": "user", "content": "Explain GDPR Article 13"}],
101
+ )
102
+ receipt = aetherproof.for_anthropic(
103
+ messages_or_prompt = [{"role": "user", "content": "Explain GDPR Article 13"}],
104
+ response_text = message.content[0].text,
105
+ model = "claude-3-opus-20240229",
106
+ )
107
+ receipt.save("claude_call.receipt")
108
+ print(receipt.verify()) # True
109
+ """
110
+ return for_api_call(
111
+ "anthropic", model,
112
+ request = messages_or_prompt,
113
+ response = response_text,
114
+ pid = pid,
115
+ call_count = call_count,
116
+ signing_key = signing_key,
117
+ )
118
+
119
+
120
+ def for_openai(
121
+ messages: Union[list, str],
122
+ response_text: str,
123
+ *,
124
+ model: str = "gpt-4o",
125
+ pid: int = 1,
126
+ call_count: int = 1,
127
+ signing_key: Optional[SigningKey] = None,
128
+ ) -> Receipt:
129
+ """Receipt for an OpenAI ChatCompletion API call.
130
+
131
+ Example::
132
+
133
+ from openai import OpenAI
134
+ import aetherproof
135
+
136
+ client = OpenAI()
137
+ result = client.chat.completions.create(
138
+ model = "gpt-4o",
139
+ messages = [{"role": "user", "content": "Summarise this contract."}],
140
+ )
141
+ receipt = aetherproof.for_openai(
142
+ messages = [{"role": "user", "content": "Summarise this contract."}],
143
+ response_text = result.choices[0].message.content,
144
+ model = "gpt-4o",
145
+ )
146
+ """
147
+ return for_api_call(
148
+ "openai", model,
149
+ request = messages,
150
+ response = response_text,
151
+ pid = pid,
152
+ call_count = call_count,
153
+ signing_key = signing_key,
154
+ )
155
+
156
+
157
+ def for_gemini(
158
+ prompt: Union[str, list],
159
+ response_text: str,
160
+ *,
161
+ model: str = "gemini-1.5-pro",
162
+ pid: int = 1,
163
+ call_count: int = 1,
164
+ signing_key: Optional[SigningKey] = None,
165
+ ) -> Receipt:
166
+ """Receipt for a Google Gemini API call."""
167
+ return for_api_call(
168
+ "google", model,
169
+ request = prompt,
170
+ response = response_text,
171
+ pid = pid,
172
+ call_count = call_count,
173
+ signing_key = signing_key,
174
+ )
175
+
176
+
177
+ def for_local_model(
178
+ model_path_or_name: str,
179
+ input_text: Union[str, bytes],
180
+ output_text: Union[str, bytes],
181
+ *,
182
+ pid: int = 1,
183
+ call_count: int = 1,
184
+ signing_key: Optional[SigningKey] = None,
185
+ ) -> Receipt:
186
+ """Receipt for local model inference: HuggingFace, llama.cpp, Ollama, etc.
187
+
188
+ Example::
189
+
190
+ from transformers import pipeline
191
+ import aetherproof
192
+
193
+ pipe = pipeline("text-generation", model="mistralai/Mistral-7B-v0.1")
194
+ result = pipe("Write a GDPR compliance summary")
195
+ receipt = aetherproof.for_local_model(
196
+ "mistralai/Mistral-7B-v0.1",
197
+ input_text = "Write a GDPR compliance summary",
198
+ output_text = result[0]["generated_text"],
199
+ )
200
+ """
201
+ model_key = f"local/{model_path_or_name}".encode()
202
+ input_b = _to_bytes(input_text)
203
+ output_b = _to_bytes(output_text)
204
+
205
+ return generate(
206
+ binary = model_key,
207
+ pid = pid,
208
+ memory_hash = fnv1a(output_b),
209
+ syscall_count = call_count,
210
+ signing_key = signing_key,
211
+ )
212
+
213
+
214
+ def for_rag_pipeline(
215
+ query: Union[str, bytes],
216
+ retrieved_docs: list,
217
+ final_answer: Union[str, bytes],
218
+ *,
219
+ model_id: str,
220
+ pid: int = 1,
221
+ signing_key: Optional[SigningKey] = None,
222
+ ) -> Receipt:
223
+ """Receipt for a RAG pipeline (LangChain, LlamaIndex, etc.).
224
+
225
+ The receipt covers the full pipeline: query + retrieved context + final answer.
226
+ binary_hash = FNV-1a of (query + all retrieved doc hashes combined)
227
+ memory_hash = FNV-1a of final_answer
228
+
229
+ Example::
230
+
231
+ answer = rag_chain.invoke({"query": "What is the EU AI Act?"})
232
+ receipt = aetherproof.for_rag_pipeline(
233
+ query = "What is the EU AI Act?",
234
+ retrieved_docs = docs, # list of strings or Document objects
235
+ final_answer = answer,
236
+ model_id = "gpt-4o",
237
+ )
238
+ """
239
+ query_b = _to_bytes(query)
240
+ docs_b = b"".join(_to_bytes(d) for d in retrieved_docs)
241
+ pipeline_b = f"rag/{model_id}".encode() + query_b + docs_b
242
+ answer_b = _to_bytes(final_answer)
243
+
244
+ return generate(
245
+ binary = pipeline_b,
246
+ pid = pid,
247
+ memory_hash = fnv1a(answer_b),
248
+ syscall_count = len(retrieved_docs), # number of docs retrieved
249
+ signing_key = signing_key,
250
+ )
251
+
252
+
253
+ def for_embedding(
254
+ model_id: str,
255
+ input_text: Union[str, bytes],
256
+ embedding: Union[list, bytes],
257
+ *,
258
+ pid: int = 1,
259
+ signing_key: Optional[SigningKey] = None,
260
+ ) -> Receipt:
261
+ """Receipt for an embedding API call (OpenAI, Cohere, etc.)."""
262
+ model_key = f"embedding/{model_id}".encode()
263
+ input_b = _to_bytes(input_text)
264
+ embedding_b = _to_bytes(embedding)
265
+
266
+ return generate(
267
+ binary = model_key,
268
+ pid = pid,
269
+ memory_hash = fnv1a(input_b),
270
+ syscall_count = 1,
271
+ signing_key = signing_key,
272
+ )
273
+
274
+
275
+ def for_image_gen(
276
+ model_id: str,
277
+ prompt: Union[str, bytes],
278
+ image_bytes: bytes,
279
+ *,
280
+ pid: int = 1,
281
+ signing_key: Optional[SigningKey] = None,
282
+ ) -> Receipt:
283
+ """Receipt for image generation (DALL-E, Stable Diffusion, Midjourney, etc.)."""
284
+ model_key = f"image/{model_id}".encode()
285
+ return generate(
286
+ binary = model_key,
287
+ pid = pid,
288
+ memory_hash = fnv1a(image_bytes),
289
+ syscall_count = 1,
290
+ signing_key = signing_key,
291
+ )
292
+
293
+
294
+ # ── Streaming helper ──────────────────────────────────────────────────────────
295
+
296
+ class StreamRecorder:
297
+ """Collect streamed response chunks and generate a receipt at the end.
298
+
299
+ Works with Anthropic streaming, OpenAI streaming, and any
300
+ chunk-based streaming API.
301
+
302
+ Example::
303
+
304
+ recorder = aetherproof.StreamRecorder("anthropic", "claude-3-opus-20240229")
305
+
306
+ with client.messages.stream(...) as stream:
307
+ for text_chunk in stream.text_stream:
308
+ recorder.add_chunk(text_chunk)
309
+ print(text_chunk, end="", flush=True)
310
+
311
+ receipt = recorder.seal(pid=1)
312
+ receipt.save("stream.receipt")
313
+ """
314
+
315
+ def __init__(
316
+ self,
317
+ provider: str,
318
+ model_id: str,
319
+ signing_key: Optional[SigningKey] = None,
320
+ ) -> None:
321
+ self._model_key = f"{provider.lower()}/{model_id}".encode()
322
+ self._sk = signing_key
323
+ self._chunks: list[bytes] = []
324
+ self._call_count = 0
325
+
326
+ def add_chunk(self, chunk: Union[str, bytes]) -> None:
327
+ self._chunks.append(_to_bytes(chunk))
328
+ self._call_count += 1
329
+
330
+ def full_response(self) -> bytes:
331
+ return b"".join(self._chunks)
332
+
333
+ def seal(self, pid: int = 1) -> Receipt:
334
+ full = self.full_response()
335
+ return generate(
336
+ binary = self._model_key,
337
+ pid = pid,
338
+ memory_hash = fnv1a(full),
339
+ syscall_count = self._call_count,
340
+ signing_key = self._sk,
341
+ )
342
+
343
+
344
+ # ── Internal ──────────────────────────────────────────────────────────────────
345
+
346
+ def _to_bytes(v: Union[str, bytes, dict, list]) -> bytes:
347
+ if isinstance(v, bytes):
348
+ return v
349
+ if isinstance(v, str):
350
+ return v.encode("utf-8")
351
+ if isinstance(v, (dict, list)):
352
+ return json.dumps(v, sort_keys=True, ensure_ascii=False).encode("utf-8")
353
+ return str(v).encode("utf-8")