trustchain 0.1.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.
Files changed (85) hide show
  1. trustchain-0.1.0/LICENSE +21 -0
  2. trustchain-0.1.0/MANIFEST.in +12 -0
  3. trustchain-0.1.0/PKG-INFO +345 -0
  4. trustchain-0.1.0/README.md +264 -0
  5. trustchain-0.1.0/docs/ARCHITECTURE.md +610 -0
  6. trustchain-0.1.0/docs/MCP_SECURITY_SPEC.md +290 -0
  7. trustchain-0.1.0/docs/wiki/API-Reference.md +224 -0
  8. trustchain-0.1.0/docs/wiki/Architecture.md +283 -0
  9. trustchain-0.1.0/docs/wiki/Examples.md +372 -0
  10. trustchain-0.1.0/docs/wiki/FAQ.md +284 -0
  11. trustchain-0.1.0/docs/wiki/Getting-Started.md +104 -0
  12. trustchain-0.1.0/docs/wiki/Home.md +76 -0
  13. trustchain-0.1.0/examples/__init__.py +1 -0
  14. trustchain-0.1.0/examples/api_agent.py +214 -0
  15. trustchain-0.1.0/examples/basic_usage.py +236 -0
  16. trustchain-0.1.0/examples/database_agent.py +289 -0
  17. trustchain-0.1.0/examples/full_enforcement_demo.py +297 -0
  18. trustchain-0.1.0/examples/javascript_integration.py +275 -0
  19. trustchain-0.1.0/examples/langchain_agent.py +125 -0
  20. trustchain-0.1.0/examples/legal_rag_demo.py +365 -0
  21. trustchain-0.1.0/examples/llm_real_api_examples.py +429 -0
  22. trustchain-0.1.0/examples/mcp_claude_desktop.py +126 -0
  23. trustchain-0.1.0/examples/secure_rag.py +196 -0
  24. trustchain-0.1.0/examples/security_vulnerability_demo.py +213 -0
  25. trustchain-0.1.0/pyproject.toml +206 -0
  26. trustchain-0.1.0/setup.cfg +4 -0
  27. trustchain-0.1.0/setup.py +99 -0
  28. trustchain-0.1.0/tests/__init__.py +1 -0
  29. trustchain-0.1.0/tests/conftest.py +74 -0
  30. trustchain-0.1.0/tests/test_async.py +124 -0
  31. trustchain-0.1.0/tests/test_basic.py +694 -0
  32. trustchain-0.1.0/tests/test_chain_of_trust.py +232 -0
  33. trustchain-0.1.0/tests/test_comprehensive_features.py +590 -0
  34. trustchain-0.1.0/tests/test_e2e.py +281 -0
  35. trustchain-0.1.0/tests/test_events.py +164 -0
  36. trustchain-0.1.0/tests/test_examples.py +144 -0
  37. trustchain-0.1.0/tests/test_graph.py +150 -0
  38. trustchain-0.1.0/tests/test_key_rotation.py +92 -0
  39. trustchain-0.1.0/tests/test_langchain.py +171 -0
  40. trustchain-0.1.0/tests/test_legal_rag.py +83 -0
  41. trustchain-0.1.0/tests/test_llm_tool_calling.py +249 -0
  42. trustchain-0.1.0/tests/test_mcp.py +164 -0
  43. trustchain-0.1.0/tests/test_merkle.py +265 -0
  44. trustchain-0.1.0/tests/test_nonce_storage.py +113 -0
  45. trustchain-0.1.0/tests/test_policy.py +153 -0
  46. trustchain-0.1.0/tests/test_real_llm_clean.py +234 -0
  47. trustchain-0.1.0/tests/test_realistic_integration.py +283 -0
  48. trustchain-0.1.0/tests/test_schemas.py +205 -0
  49. trustchain-0.1.0/tests/test_server.py +200 -0
  50. trustchain-0.1.0/tests/test_tenants.py +159 -0
  51. trustchain-0.1.0/tests/test_ui.py +266 -0
  52. trustchain-0.1.0/tests/test_v2_basic.py +208 -0
  53. trustchain-0.1.0/tests/test_verifier.py +128 -0
  54. trustchain-0.1.0/trustchain/__init__.py +60 -0
  55. trustchain-0.1.0/trustchain/integrations/__init__.py +35 -0
  56. trustchain-0.1.0/trustchain/integrations/langchain.py +158 -0
  57. trustchain-0.1.0/trustchain/integrations/mcp.py +211 -0
  58. trustchain-0.1.0/trustchain/ui/__init__.py +5 -0
  59. trustchain-0.1.0/trustchain/ui/explorer.py +333 -0
  60. trustchain-0.1.0/trustchain/utils/__init__.py +15 -0
  61. trustchain-0.1.0/trustchain/utils/config.py +352 -0
  62. trustchain-0.1.0/trustchain/utils/exceptions.py +221 -0
  63. trustchain-0.1.0/trustchain/v2/__init__.py +38 -0
  64. trustchain-0.1.0/trustchain/v2/config.py +63 -0
  65. trustchain-0.1.0/trustchain/v2/core.py +395 -0
  66. trustchain-0.1.0/trustchain/v2/events.py +164 -0
  67. trustchain-0.1.0/trustchain/v2/example.py +106 -0
  68. trustchain-0.1.0/trustchain/v2/graph.py +266 -0
  69. trustchain-0.1.0/trustchain/v2/logging.py +97 -0
  70. trustchain-0.1.0/trustchain/v2/merkle.py +205 -0
  71. trustchain-0.1.0/trustchain/v2/metrics.py +91 -0
  72. trustchain-0.1.0/trustchain/v2/nonce_storage.py +219 -0
  73. trustchain-0.1.0/trustchain/v2/policy.py +286 -0
  74. trustchain-0.1.0/trustchain/v2/schemas.py +211 -0
  75. trustchain-0.1.0/trustchain/v2/server.py +219 -0
  76. trustchain-0.1.0/trustchain/v2/signer.py +219 -0
  77. trustchain-0.1.0/trustchain/v2/storage.py +111 -0
  78. trustchain-0.1.0/trustchain/v2/tenants.py +91 -0
  79. trustchain-0.1.0/trustchain/v2/verifier.py +159 -0
  80. trustchain-0.1.0/trustchain.egg-info/PKG-INFO +345 -0
  81. trustchain-0.1.0/trustchain.egg-info/SOURCES.txt +83 -0
  82. trustchain-0.1.0/trustchain.egg-info/dependency_links.txt +1 -0
  83. trustchain-0.1.0/trustchain.egg-info/entry_points.txt +2 -0
  84. trustchain-0.1.0/trustchain.egg-info/requires.txt +58 -0
  85. trustchain-0.1.0/trustchain.egg-info/top_level.txt +3 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Ed Cherednik
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,12 @@
1
+ include README.md
2
+ include QUICKSTART.md
3
+ include LICENSE
4
+ include requirements.txt
5
+ include pyproject.toml
6
+ recursive-include trustchain *.py
7
+ recursive-include examples *.py
8
+ recursive-include tests *.py
9
+ recursive-include docs *.md
10
+ exclude .gitignore
11
+ exclude .pre-commit-config.yaml
12
+ prune .git
@@ -0,0 +1,345 @@
1
+ Metadata-Version: 2.4
2
+ Name: trustchain
3
+ Version: 0.1.0
4
+ Summary: Cryptographically signed AI tool responses for preventing hallucinations
5
+ Home-page: https://github.com/trustchain/trustchain
6
+ Author: TrustChain Contributors
7
+ Author-email: Ed Cherednik <edcherednik@gmail.com>
8
+ License: MIT
9
+ Project-URL: Homepage, https://github.com/petro1eum/Tool_blockchain
10
+ Project-URL: Documentation, https://trustchain.readthedocs.io/
11
+ Project-URL: Repository, https://github.com/petro1eum/Tool_blockchain.git
12
+ Project-URL: Bug Tracker, https://github.com/petro1eum/Tool_blockchain/issues
13
+ Keywords: ai,security,cryptography,signatures,blockchain,trust
14
+ Classifier: Development Status :: 3 - Alpha
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Topic :: Security :: Cryptography
17
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
18
+ Classifier: License :: OSI Approved :: MIT License
19
+ Classifier: Programming Language :: Python :: 3
20
+ Classifier: Programming Language :: Python :: 3.8
21
+ Classifier: Programming Language :: Python :: 3.9
22
+ Classifier: Programming Language :: Python :: 3.10
23
+ Classifier: Programming Language :: Python :: 3.11
24
+ Classifier: Programming Language :: Python :: 3.12
25
+ Requires-Python: >=3.8
26
+ Description-Content-Type: text/markdown
27
+ License-File: LICENSE
28
+ Requires-Dist: PyNaCl>=1.5.0
29
+ Requires-Dist: cryptography>=41.0.0
30
+ Requires-Dist: pydantic>=2.0.0
31
+ Requires-Dist: msgpack>=1.0.0
32
+ Requires-Dist: click>=8.0.0
33
+ Requires-Dist: rich>=13.0.0
34
+ Requires-Dist: typer>=0.9.0
35
+ Requires-Dist: pyyaml>=6.0
36
+ Requires-Dist: python-dotenv>=1.0.0
37
+ Provides-Extra: kafka
38
+ Requires-Dist: kafka-python>=2.0.0; extra == "kafka"
39
+ Requires-Dist: aiokafka>=0.10.0; extra == "kafka"
40
+ Requires-Dist: confluent-kafka>=2.3.0; extra == "kafka"
41
+ Provides-Extra: redis
42
+ Requires-Dist: redis>=5.0.0; extra == "redis"
43
+ Requires-Dist: aioredis>=2.0.0; extra == "redis"
44
+ Provides-Extra: blockchain
45
+ Requires-Dist: web3>=6.0.0; extra == "blockchain"
46
+ Requires-Dist: ipfshttpclient>=0.8.0; extra == "blockchain"
47
+ Provides-Extra: web
48
+ Requires-Dist: fastapi>=0.104.0; extra == "web"
49
+ Requires-Dist: uvicorn>=0.24.0; extra == "web"
50
+ Requires-Dist: pydantic>=2.0.0; extra == "web"
51
+ Requires-Dist: websockets>=11.0.0; extra == "web"
52
+ Provides-Extra: monitoring
53
+ Requires-Dist: prometheus-client>=0.19.0; extra == "monitoring"
54
+ Requires-Dist: grafana-api>=1.0.0; extra == "monitoring"
55
+ Requires-Dist: fastapi>=0.104.0; extra == "monitoring"
56
+ Requires-Dist: uvicorn>=0.24.0; extra == "monitoring"
57
+ Provides-Extra: ai
58
+ Requires-Dist: langchain>=0.1.0; extra == "ai"
59
+ Requires-Dist: langchain-core>=0.1.0; extra == "ai"
60
+ Requires-Dist: openai>=1.0.0; extra == "ai"
61
+ Requires-Dist: anthropic>=0.8.0; extra == "ai"
62
+ Provides-Extra: mcp
63
+ Requires-Dist: mcp>=1.0.0; extra == "mcp"
64
+ Provides-Extra: integrations
65
+ Requires-Dist: langchain-core>=0.1.0; extra == "integrations"
66
+ Requires-Dist: mcp>=1.0.0; extra == "integrations"
67
+ Provides-Extra: dev
68
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
69
+ Requires-Dist: pytest-asyncio>=0.23.0; extra == "dev"
70
+ Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
71
+ Requires-Dist: black==24.8.0; extra == "dev"
72
+ Requires-Dist: isort==5.13.2; extra == "dev"
73
+ Requires-Dist: mypy>=1.0.0; extra == "dev"
74
+ Requires-Dist: pre-commit>=3.0.0; extra == "dev"
75
+ Requires-Dist: coverage>=7.0.0; extra == "dev"
76
+ Requires-Dist: ruff>=0.1.0; extra == "dev"
77
+ Dynamic: author
78
+ Dynamic: home-page
79
+ Dynamic: license-file
80
+ Dynamic: requires-python
81
+
82
+ # TrustChain v2.1
83
+
84
+ **Cryptographic verification layer for AI agents - "SSL for AI"**
85
+
86
+ [![CI](https://github.com/petro1eum/trust_chain/actions/workflows/ci.yml/badge.svg)](https://github.com/petro1eum/trust_chain/actions/workflows/ci.yml)
87
+ [![Python 3.8+](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)
88
+ [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
89
+
90
+ TrustChain adds **Ed25519 cryptographic signatures** to AI tool responses, enabling:
91
+
92
+ - **Proof of execution** - data came from a real tool, not hallucinated
93
+ - **Chain of Trust** - cryptographically linked operation sequences
94
+ - **Replay attack protection** - nonce-based anti-replay
95
+ - **Key rotation** - seamless key management with persistence
96
+ - **Audit trails** - beautiful HTML reports for compliance
97
+ - **Integrations** - OpenAI, Anthropic, LangChain, MCP (Claude Desktop)
98
+
99
+ ---
100
+
101
+ ## Installation
102
+
103
+ ```bash
104
+ pip install trustchain
105
+ ```
106
+
107
+ **Optional extras:**
108
+
109
+ ```bash
110
+ pip install trustchain[integrations] # LangChain + MCP support
111
+ pip install trustchain[ai] # OpenAI + Anthropic + LangChain
112
+ pip install trustchain[mcp] # MCP Server only
113
+ pip install trustchain[redis] # Distributed nonce storage
114
+ pip install trustchain[all] # Everything
115
+ ```
116
+
117
+ ---
118
+
119
+ ## Quick Start
120
+
121
+ ```python
122
+ from trustchain import TrustChain
123
+
124
+ tc = TrustChain()
125
+
126
+ @tc.tool("weather")
127
+ def get_weather(city: str) -> dict:
128
+ return {"city": city, "temp": 22}
129
+
130
+ # Calling the function returns a SignedResponse
131
+ result = get_weather("Moscow")
132
+ print(result.data) # {'city': 'Moscow', 'temp': 22}
133
+ print(result.signature) # Ed25519 signature (Base64)
134
+
135
+ # Verify authenticity
136
+ assert tc.verify(result) == True
137
+ ```
138
+
139
+ ---
140
+
141
+ ## Features
142
+
143
+ ### Chain of Trust
144
+
145
+ Link operations cryptographically to prove execution order:
146
+
147
+ ```python
148
+ step1 = tc._signer.sign("search", {"query": "balance"})
149
+ step2 = tc._signer.sign("analyze", {"result": 100}, parent_signature=step1.signature)
150
+ step3 = tc._signer.sign("report", {"text": "Done"}, parent_signature=step2.signature)
151
+
152
+ # Verify the entire chain
153
+ assert tc.verify_chain([step1, step2, step3]) == True
154
+ ```
155
+
156
+ ### Key Management
157
+
158
+ ```python
159
+ from trustchain import TrustChain, TrustChainConfig
160
+
161
+ # Persistent keys with auto-save
162
+ tc = TrustChain(TrustChainConfig(
163
+ key_file="keys.json",
164
+ enable_nonce=True
165
+ ))
166
+ tc.save_keys()
167
+
168
+ # Key rotation (generates new keys)
169
+ old_key = tc.get_key_id()
170
+ new_key = tc.rotate_keys() # Also saves if key_file is configured
171
+ print(f"Rotated from {old_key[:16]} to {new_key[:16]}")
172
+
173
+ # Export for external verification
174
+ public_key = tc.export_public_key()
175
+ ```
176
+
177
+ ### Multi-Tenant (Agent Isolation)
178
+
179
+ ```python
180
+ from trustchain.v2.tenants import TenantManager
181
+
182
+ manager = TenantManager()
183
+
184
+ research_agent = manager.get_or_create("research_agent")
185
+ code_agent = manager.get_or_create("code_agent")
186
+
187
+ # Each agent has isolated keys - cannot verify each other's signatures
188
+ result = research_agent._signer.sign("data", {"value": 42})
189
+ assert research_agent.verify(result) == True
190
+ assert code_agent.verify(result) == False # Different keys!
191
+ ```
192
+
193
+ ### OpenAI / Anthropic Schema Export
194
+
195
+ ```python
196
+ # Get OpenAI-compatible function schema
197
+ schema = tc.get_tools_schema()
198
+
199
+ # Anthropic format
200
+ schema = tc.get_tools_schema(format="anthropic")
201
+ ```
202
+
203
+ ### MCP Server (Claude Desktop)
204
+
205
+ ```python
206
+ from trustchain.integrations.mcp import serve_mcp
207
+
208
+ @tc.tool("calculator")
209
+ def add(a: int, b: int) -> int:
210
+ return a + b
211
+
212
+ serve_mcp(tc) # Starts MCP server for Claude Desktop
213
+ ```
214
+
215
+ ### LangChain Integration
216
+
217
+ ```python
218
+ from trustchain.integrations.langchain import to_langchain_tools
219
+
220
+ lc_tools = to_langchain_tools(tc)
221
+ # Use with LangChain AgentExecutor
222
+ ```
223
+
224
+ ### Merkle Trees for Large Documents
225
+
226
+ ```python
227
+ from trustchain.v2.merkle import MerkleTree, verify_proof
228
+
229
+ pages = ["Page 1...", "Page 2...", ...]
230
+ tree = MerkleTree.from_chunks(pages)
231
+
232
+ # Verify single page without loading entire document
233
+ proof = tree.get_proof(42)
234
+ assert verify_proof(pages[42], proof, tree.root)
235
+ ```
236
+
237
+ ### CloudEvents Format
238
+
239
+ ```python
240
+ from trustchain.v2.events import TrustEvent
241
+
242
+ event = TrustEvent.from_signed_response(result, source="/agent/bot")
243
+ kafka_headers = event.to_kafka_headers()
244
+ ```
245
+
246
+ ### Audit Trail UI
247
+
248
+ ```python
249
+ from trustchain.ui.explorer import ChainExplorer
250
+
251
+ explorer = ChainExplorer(chain, tc)
252
+ explorer.export_html("audit_report.html")
253
+
254
+ # Export formats
255
+ json_data = explorer.to_json() # Returns list of responses
256
+ stats = explorer.get_stats() # Summary statistics
257
+ ```
258
+
259
+ ---
260
+
261
+ ## Performance
262
+
263
+ | Operation | Latency | Throughput |
264
+ |-----------|---------|------------|
265
+ | Sign | 0.11 ms | 9,100 ops/sec |
266
+ | Verify | 0.22 ms | 4,500 ops/sec |
267
+ | Merkle (100 pages) | 0.18 ms | 5,400 ops/sec |
268
+
269
+ Storage overhead: ~124 bytes per operation.
270
+
271
+ ---
272
+
273
+ ## Interactive Examples
274
+
275
+ See the `examples/` directory:
276
+
277
+ | Notebook | Description |
278
+ |----------|-------------|
279
+ | [trustchain_tutorial.ipynb](examples/trustchain_tutorial.ipynb) | Basic tutorial - 7 core use cases |
280
+ | [trustchain_advanced.ipynb](examples/trustchain_advanced.ipynb) | Advanced - key persistence, multi-agent, Redis |
281
+ | [trustchain_pro.ipynb](examples/trustchain_pro.ipynb) | Full API reference with all v2.1 capabilities |
282
+
283
+ **Python examples:**
284
+ - `mcp_claude_desktop.py` - MCP Server for Claude
285
+ - `langchain_agent.py` - LangChain integration
286
+ - `secure_rag.py` - RAG with Merkle verification
287
+ - `database_agent.py` - SQL with Chain of Trust
288
+ - `api_agent.py` - HTTP client with CloudEvents
289
+
290
+ ---
291
+
292
+ ## Architecture
293
+
294
+ ```
295
+ trustchain/
296
+ v2/
297
+ core.py # Main TrustChain class
298
+ signer.py # Ed25519 signatures
299
+ schemas.py # OpenAI/Anthropic schema generation
300
+ merkle.py # Merkle tree implementation
301
+ events.py # CloudEvents format
302
+ tenants.py # Multi-tenant isolation
303
+ nonce_storage.py # Memory/Redis nonce storage
304
+ server.py # REST API
305
+ integrations/
306
+ langchain.py # LangChain adapter
307
+ mcp.py # MCP Server
308
+ ui/
309
+ explorer.py # HTML audit reports
310
+ ```
311
+
312
+ ---
313
+
314
+ ## Use Cases
315
+
316
+ | Industry | Application |
317
+ |----------|-------------|
318
+ | **AI Agents** | Prove tool outputs are real, not hallucinations |
319
+ | **FinTech** | Audit trail for financial operations |
320
+ | **LegalTech** | Document verification with Merkle proofs |
321
+ | **Healthcare (HIPAA)** | Compliant AI data handling |
322
+ | **Enterprise** | SOC2-ready AI deployments |
323
+
324
+ ---
325
+
326
+ ## Documentation
327
+
328
+ - [Russian Guide](GUIDE_RU.md) - Comprehensive documentation in Russian
329
+ - [Roadmap](ROADMAP.md) - Development roadmap and status
330
+ - [Architecture](docs/ARCHITECTURE.md) - Technical details
331
+ - [GitHub Wiki](https://github.com/petro1eum/trust_chain/wiki) - Full API reference
332
+
333
+ ---
334
+
335
+ ## License
336
+
337
+ MIT
338
+
339
+ ## Author
340
+
341
+ Ed Cherednik
342
+
343
+ ## Version
344
+
345
+ 2.1.0
@@ -0,0 +1,264 @@
1
+ # TrustChain v2.1
2
+
3
+ **Cryptographic verification layer for AI agents - "SSL for AI"**
4
+
5
+ [![CI](https://github.com/petro1eum/trust_chain/actions/workflows/ci.yml/badge.svg)](https://github.com/petro1eum/trust_chain/actions/workflows/ci.yml)
6
+ [![Python 3.8+](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)
7
+ [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
8
+
9
+ TrustChain adds **Ed25519 cryptographic signatures** to AI tool responses, enabling:
10
+
11
+ - **Proof of execution** - data came from a real tool, not hallucinated
12
+ - **Chain of Trust** - cryptographically linked operation sequences
13
+ - **Replay attack protection** - nonce-based anti-replay
14
+ - **Key rotation** - seamless key management with persistence
15
+ - **Audit trails** - beautiful HTML reports for compliance
16
+ - **Integrations** - OpenAI, Anthropic, LangChain, MCP (Claude Desktop)
17
+
18
+ ---
19
+
20
+ ## Installation
21
+
22
+ ```bash
23
+ pip install trustchain
24
+ ```
25
+
26
+ **Optional extras:**
27
+
28
+ ```bash
29
+ pip install trustchain[integrations] # LangChain + MCP support
30
+ pip install trustchain[ai] # OpenAI + Anthropic + LangChain
31
+ pip install trustchain[mcp] # MCP Server only
32
+ pip install trustchain[redis] # Distributed nonce storage
33
+ pip install trustchain[all] # Everything
34
+ ```
35
+
36
+ ---
37
+
38
+ ## Quick Start
39
+
40
+ ```python
41
+ from trustchain import TrustChain
42
+
43
+ tc = TrustChain()
44
+
45
+ @tc.tool("weather")
46
+ def get_weather(city: str) -> dict:
47
+ return {"city": city, "temp": 22}
48
+
49
+ # Calling the function returns a SignedResponse
50
+ result = get_weather("Moscow")
51
+ print(result.data) # {'city': 'Moscow', 'temp': 22}
52
+ print(result.signature) # Ed25519 signature (Base64)
53
+
54
+ # Verify authenticity
55
+ assert tc.verify(result) == True
56
+ ```
57
+
58
+ ---
59
+
60
+ ## Features
61
+
62
+ ### Chain of Trust
63
+
64
+ Link operations cryptographically to prove execution order:
65
+
66
+ ```python
67
+ step1 = tc._signer.sign("search", {"query": "balance"})
68
+ step2 = tc._signer.sign("analyze", {"result": 100}, parent_signature=step1.signature)
69
+ step3 = tc._signer.sign("report", {"text": "Done"}, parent_signature=step2.signature)
70
+
71
+ # Verify the entire chain
72
+ assert tc.verify_chain([step1, step2, step3]) == True
73
+ ```
74
+
75
+ ### Key Management
76
+
77
+ ```python
78
+ from trustchain import TrustChain, TrustChainConfig
79
+
80
+ # Persistent keys with auto-save
81
+ tc = TrustChain(TrustChainConfig(
82
+ key_file="keys.json",
83
+ enable_nonce=True
84
+ ))
85
+ tc.save_keys()
86
+
87
+ # Key rotation (generates new keys)
88
+ old_key = tc.get_key_id()
89
+ new_key = tc.rotate_keys() # Also saves if key_file is configured
90
+ print(f"Rotated from {old_key[:16]} to {new_key[:16]}")
91
+
92
+ # Export for external verification
93
+ public_key = tc.export_public_key()
94
+ ```
95
+
96
+ ### Multi-Tenant (Agent Isolation)
97
+
98
+ ```python
99
+ from trustchain.v2.tenants import TenantManager
100
+
101
+ manager = TenantManager()
102
+
103
+ research_agent = manager.get_or_create("research_agent")
104
+ code_agent = manager.get_or_create("code_agent")
105
+
106
+ # Each agent has isolated keys - cannot verify each other's signatures
107
+ result = research_agent._signer.sign("data", {"value": 42})
108
+ assert research_agent.verify(result) == True
109
+ assert code_agent.verify(result) == False # Different keys!
110
+ ```
111
+
112
+ ### OpenAI / Anthropic Schema Export
113
+
114
+ ```python
115
+ # Get OpenAI-compatible function schema
116
+ schema = tc.get_tools_schema()
117
+
118
+ # Anthropic format
119
+ schema = tc.get_tools_schema(format="anthropic")
120
+ ```
121
+
122
+ ### MCP Server (Claude Desktop)
123
+
124
+ ```python
125
+ from trustchain.integrations.mcp import serve_mcp
126
+
127
+ @tc.tool("calculator")
128
+ def add(a: int, b: int) -> int:
129
+ return a + b
130
+
131
+ serve_mcp(tc) # Starts MCP server for Claude Desktop
132
+ ```
133
+
134
+ ### LangChain Integration
135
+
136
+ ```python
137
+ from trustchain.integrations.langchain import to_langchain_tools
138
+
139
+ lc_tools = to_langchain_tools(tc)
140
+ # Use with LangChain AgentExecutor
141
+ ```
142
+
143
+ ### Merkle Trees for Large Documents
144
+
145
+ ```python
146
+ from trustchain.v2.merkle import MerkleTree, verify_proof
147
+
148
+ pages = ["Page 1...", "Page 2...", ...]
149
+ tree = MerkleTree.from_chunks(pages)
150
+
151
+ # Verify single page without loading entire document
152
+ proof = tree.get_proof(42)
153
+ assert verify_proof(pages[42], proof, tree.root)
154
+ ```
155
+
156
+ ### CloudEvents Format
157
+
158
+ ```python
159
+ from trustchain.v2.events import TrustEvent
160
+
161
+ event = TrustEvent.from_signed_response(result, source="/agent/bot")
162
+ kafka_headers = event.to_kafka_headers()
163
+ ```
164
+
165
+ ### Audit Trail UI
166
+
167
+ ```python
168
+ from trustchain.ui.explorer import ChainExplorer
169
+
170
+ explorer = ChainExplorer(chain, tc)
171
+ explorer.export_html("audit_report.html")
172
+
173
+ # Export formats
174
+ json_data = explorer.to_json() # Returns list of responses
175
+ stats = explorer.get_stats() # Summary statistics
176
+ ```
177
+
178
+ ---
179
+
180
+ ## Performance
181
+
182
+ | Operation | Latency | Throughput |
183
+ |-----------|---------|------------|
184
+ | Sign | 0.11 ms | 9,100 ops/sec |
185
+ | Verify | 0.22 ms | 4,500 ops/sec |
186
+ | Merkle (100 pages) | 0.18 ms | 5,400 ops/sec |
187
+
188
+ Storage overhead: ~124 bytes per operation.
189
+
190
+ ---
191
+
192
+ ## Interactive Examples
193
+
194
+ See the `examples/` directory:
195
+
196
+ | Notebook | Description |
197
+ |----------|-------------|
198
+ | [trustchain_tutorial.ipynb](examples/trustchain_tutorial.ipynb) | Basic tutorial - 7 core use cases |
199
+ | [trustchain_advanced.ipynb](examples/trustchain_advanced.ipynb) | Advanced - key persistence, multi-agent, Redis |
200
+ | [trustchain_pro.ipynb](examples/trustchain_pro.ipynb) | Full API reference with all v2.1 capabilities |
201
+
202
+ **Python examples:**
203
+ - `mcp_claude_desktop.py` - MCP Server for Claude
204
+ - `langchain_agent.py` - LangChain integration
205
+ - `secure_rag.py` - RAG with Merkle verification
206
+ - `database_agent.py` - SQL with Chain of Trust
207
+ - `api_agent.py` - HTTP client with CloudEvents
208
+
209
+ ---
210
+
211
+ ## Architecture
212
+
213
+ ```
214
+ trustchain/
215
+ v2/
216
+ core.py # Main TrustChain class
217
+ signer.py # Ed25519 signatures
218
+ schemas.py # OpenAI/Anthropic schema generation
219
+ merkle.py # Merkle tree implementation
220
+ events.py # CloudEvents format
221
+ tenants.py # Multi-tenant isolation
222
+ nonce_storage.py # Memory/Redis nonce storage
223
+ server.py # REST API
224
+ integrations/
225
+ langchain.py # LangChain adapter
226
+ mcp.py # MCP Server
227
+ ui/
228
+ explorer.py # HTML audit reports
229
+ ```
230
+
231
+ ---
232
+
233
+ ## Use Cases
234
+
235
+ | Industry | Application |
236
+ |----------|-------------|
237
+ | **AI Agents** | Prove tool outputs are real, not hallucinations |
238
+ | **FinTech** | Audit trail for financial operations |
239
+ | **LegalTech** | Document verification with Merkle proofs |
240
+ | **Healthcare (HIPAA)** | Compliant AI data handling |
241
+ | **Enterprise** | SOC2-ready AI deployments |
242
+
243
+ ---
244
+
245
+ ## Documentation
246
+
247
+ - [Russian Guide](GUIDE_RU.md) - Comprehensive documentation in Russian
248
+ - [Roadmap](ROADMAP.md) - Development roadmap and status
249
+ - [Architecture](docs/ARCHITECTURE.md) - Technical details
250
+ - [GitHub Wiki](https://github.com/petro1eum/trust_chain/wiki) - Full API reference
251
+
252
+ ---
253
+
254
+ ## License
255
+
256
+ MIT
257
+
258
+ ## Author
259
+
260
+ Ed Cherednik
261
+
262
+ ## Version
263
+
264
+ 2.1.0