enyal-sdk 2.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.
@@ -0,0 +1,208 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
203
+
204
+ ---
205
+
206
+ Copyright 2026 Greenland AI Limited
207
+
208
+ Licensed under the Apache License, Version 2.0.
@@ -0,0 +1,409 @@
1
+ Metadata-Version: 2.1
2
+ Name: enyal-sdk
3
+ Version: 2.1.0
4
+ Summary: ENYAL SDK — encrypted knowledge graph, local memory, permanent proof
5
+ Author-email: Greenland AI Limited <info@enyal.ai>
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://enyal.ai
8
+ Project-URL: Documentation, https://enyal.ai/docs
9
+ Project-URL: Repository, https://github.com/JoulePAI/enyal-sdk-python
10
+ Keywords: enyal,knowledge-graph,zero-knowledge,archival,sdk
11
+ Classifier: License :: OSI Approved :: Apache Software License
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.9
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Topic :: Security :: Cryptography
18
+ Requires-Python: >=3.9
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Provides-Extra: crypto
22
+ Requires-Dist: cryptography>=41.0; extra == "crypto"
23
+ Provides-Extra: llm
24
+ Requires-Dist: httpx>=0.24; extra == "llm"
25
+ Provides-Extra: all
26
+ Requires-Dist: cryptography>=41.0; extra == "all"
27
+ Requires-Dist: httpx>=0.24; extra == "all"
28
+
29
+ # ENYAL SDK
30
+
31
+ Your agent thinks locally. ENYAL proves permanently.
32
+
33
+ ## Quick Start — Local Knowledge + Permanent Proof
34
+
35
+ ```python
36
+ from enyal_sdk import EnyalAgent
37
+
38
+ agent = EnyalAgent(api_key="eyl_your_key")
39
+
40
+ # Remember locally (free, private, instant)
41
+ agent.remember("Tesla has 100GWh battery capacity",
42
+ node_type="entity",
43
+ properties={"frontier": "energy", "capacity": "100GWh"})
44
+
45
+ agent.remember("SpaceX launches 90 rockets per year",
46
+ node_type="entity",
47
+ properties={"frontier": "space", "launches": 90})
48
+
49
+ # Recall from local memory
50
+ results = agent.recall("battery capacity")
51
+
52
+ # Check what you know
53
+ health = agent.health()
54
+ print(health)
55
+ # {"status": "healthy", "total_nodes": 2, "contradictions": 0}
56
+
57
+ # Get compact context for your AI prompt (120 tokens)
58
+ context = agent.compact()
59
+ print(context)
60
+ # E:Tesla|100GWh battery capacity|0c
61
+ # E:SpaceX|90 launches per year|0c
62
+
63
+ # Archive permanently (costs joules, encrypted, provable)
64
+ agent.archive(
65
+ chunk_type="decision_record",
66
+ chunk_key="my-agent:decision:invest-energy",
67
+ data={"decision": "Invest in energy infrastructure",
68
+ "confidence": 0.85,
69
+ "entities": ["Tesla"]}
70
+ )
71
+
72
+ # Sync local brain to ENYAL for backup
73
+ agent.sync_to_enyal()
74
+
75
+ # Pull remote knowledge locally
76
+ agent.sync_from_enyal()
77
+ ```
78
+
79
+ ## Retry Safety
80
+
81
+ All state-changing API calls automatically retry on network errors, timeouts, 5xx, and 429 (rate limit) responses. Retries use exponential backoff with jitter and a deterministic idempotency key to prevent double-charges.
82
+
83
+ ```python
84
+ # Automatic retry with SDK-generated idempotency key (default)
85
+ agent.archive(chunk_type="decision_record",
86
+ chunk_key="my-agent:decision:001",
87
+ data={"decision": "Invest in space"})
88
+
89
+ # Explicit idempotency key (e.g., your own dedup token)
90
+ agent.archive(chunk_type="decision_record",
91
+ chunk_key="my-agent:decision:001",
92
+ data={"decision": "Invest in space"},
93
+ idempotency_key="my-dedup-key-12345678901234567890")
94
+
95
+ # Disable retry for a single call
96
+ agent.archive(..., retry=False)
97
+ ```
98
+
99
+ **Default retry policy:** 3 retries, 0.5s initial delay, 2x backoff, 8s max delay, 0.1-0.3s jitter. Respects `Retry-After` header on 429 responses. Never retries 4xx errors (except 429).
100
+
101
+ **Retry-safe endpoints:** archive, prove, disclose, client-side disclose, share-proof, timestamp, agreement/create, compliance/attest, message/send.
102
+
103
+ **Not available via SDK:** `knowledge/synthesise` requires session auth (web console only).
104
+
105
+ ## Two Layers
106
+
107
+ | Feature | Local (free) | ENYAL (paid) |
108
+ |---------|-------------|--------------|
109
+ | Storage | SQLite on your machine | Permanent cryptographic ledger |
110
+ | Speed | Instant | ~200ms |
111
+ | Privacy | Never leaves your device | Encrypted, you hold the key |
112
+ | Proof | None | ZK proofs, BSV settlement |
113
+ | Cost | Free | Joules per operation |
114
+ | Persistence | Until you delete it | Permanent, immutable |
115
+
116
+ ## Installation
117
+
118
+ ```bash
119
+ pip install enyal-sdk
120
+ ```
121
+
122
+ If using natural language `remember()` with a local LLM:
123
+
124
+ - Install Ollama: https://ollama.com
125
+ - Pull a model: `ollama pull mistral-nemo`
126
+ - Or set `ENYAL_LOCAL_MODEL=your-model-name`
127
+ - Without a pulled model, extraction falls back to using the full text as the entity name (10s timeout)
128
+
129
+ ### Node.js
130
+
131
+ ```bash
132
+ npm install enyal-sdk
133
+ ```
134
+
135
+ ```javascript
136
+ const { EnyalAgent } = require('enyal-sdk');
137
+
138
+ const agent = new EnyalAgent('eyl_your_key');
139
+
140
+ // Local (free, private, instant, synchronous)
141
+ agent.remember('SpaceX', 'entity', '90 launches/yr', { launches: 90 });
142
+ const results = agent.recall('SpaceX');
143
+
144
+ // Natural language (async, optional Ollama)
145
+ await agent.rememberText('Tesla has 100GWh battery capacity');
146
+
147
+ // Compact context for AI prompt
148
+ const ctx = agent.compact();
149
+
150
+ // Permanent proof (costs joules, async)
151
+ await agent.archive('decision_record',
152
+ 'my-agent:decision:001',
153
+ { decision: 'Invest in space', confidence: 0.85 });
154
+
155
+ // Always close when done (releases SQLite file lock)
156
+ agent.close();
157
+ ```
158
+
159
+ ## Backup & Restore
160
+
161
+ ```python
162
+ from enyal_sdk import EnyalAgent
163
+
164
+ agent = EnyalAgent(api_key="eyl_your_key")
165
+ agent.remember("Tesla", "entity", "100GWh capacity", {"sector": "energy"})
166
+
167
+ # Backup: encrypt locally, send to ENYAL
168
+ agent.sync_to_enyal(password="your-enyal-password")
169
+ # ENYAL stores an encrypted blob it cannot read
170
+
171
+ # Restore on new device:
172
+ new_agent = EnyalAgent(api_key="eyl_your_key")
173
+ new_agent.restore_from_enyal(password="your-enyal-password")
174
+ # Downloads encrypted snapshot, decrypts locally
175
+ print(new_agent.health())
176
+ ```
177
+
178
+ Your knowledge graph is portable and private:
179
+ - Encrypted before it leaves your device
180
+ - ENYAL stores the blob but can't read it
181
+ - Only your password can decrypt it
182
+ - Works across devices, platforms, and SDKs
183
+
184
+ **Important:** Snapshots are encrypted with your current password. If you change your password, old snapshots become undecryptable. Re-sync immediately after any password change.
185
+
186
+ ### Limitations
187
+
188
+ - Local knowledge uses SQLite WAL mode. Do not place the database file on a network filesystem (NFS/SMB).
189
+
190
+ ---
191
+
192
+ ## Client-Side Disclosure & Verification
193
+
194
+ Client-side disclosure, verification, and proof generation for ENYAL's intelligence archival system.
195
+
196
+ Three trust tiers — choose based on your security requirements:
197
+
198
+ | Tier | Trust in ENYAL | What runs where | Use case |
199
+ |------|----------------|-----------------|----------|
200
+ | **Tier 1** | None | Everything client-side | Maximum security, auditor self-verification |
201
+ | **Tier 2** | During proof generation | Proof on ENYAL's server | Third-party auditor proofs |
202
+ | **Tier 3** | None | Self-hosted Rust binary | Zero-trust zero-knowledge proof generation |
203
+
204
+ ## Installation
205
+
206
+ **JavaScript** — No npm packages required. Web Crypto API (browsers) or Node.js 19+.
207
+ For ECDH, provide a P-256 scalar multiply function (e.g. from `@noble/curves`).
208
+
209
+ **Python** — `pip install cryptography`
210
+
211
+ ## Usage
212
+
213
+ ### Tier 1 — Full client-side (zero trust)
214
+
215
+ ```js
216
+ import { requestClientDisclosure, decryptCustodialShare, combineSharesAndDecrypt, verifyShareCombination } from './enyal-client.js';
217
+ import { p256 } from '@noble/curves/p256';
218
+
219
+ // P-256 scalar multiply helper for @noble/curves
220
+ async function p256ScalarMul(privKeyBytes, compressedPubKey) {
221
+ const shared = p256.getSharedSecret(privKeyBytes, compressedPubKey, true);
222
+ return shared.slice(1, 33); // x-coordinate only
223
+ }
224
+
225
+ // 1. Request disclosure materials (no share sent to server)
226
+ const materials = await requestClientDisclosure(apiKey, 'https://api.enyal.ai', ['chunk-id'], 'audit');
227
+
228
+ // 2. Decrypt ENYAL's share using your private key
229
+ const custodialShare = await decryptCustodialShare(materials.custodial_share, myPrivateKey, p256ScalarMul);
230
+
231
+ // 3. Combine shares and decrypt the data
232
+ const plaintext = await combineSharesAndDecrypt(myShare, custodialShare, materials.chunks[0], p256ScalarMul);
233
+
234
+ // 4. Verify share combination locally (WASM, 78KB, zero server calls)
235
+ const verification = await verifyShareCombination(myShare, custodialShare, materials.poseidon_key_hash);
236
+ console.log(verification.valid); // true — verified locally, ENYAL never saw your share
237
+ ```
238
+
239
+ ```python
240
+ from enyal_sdk import request_client_disclosure, decrypt_custodial_share, combine_shares_and_decrypt, verify_share_combination
241
+
242
+ # 1. Request disclosure materials
243
+ materials = request_client_disclosure(api_key, 'https://api.enyal.ai', ['chunk-id'], 'audit')
244
+
245
+ # 2. Decrypt custodial share
246
+ custodial_share = decrypt_custodial_share(materials['custodial_share'], my_private_key_bytes)
247
+
248
+ # 3. Combine and decrypt
249
+ plaintext = combine_shares_and_decrypt(my_share, custodial_share, materials['chunks'][0])
250
+
251
+ # 4. Verify locally (requires shamir-circuit binary for content integrity hash)
252
+ result = verify_share_combination(my_share, custodial_share, materials['poseidon_key_hash'],
253
+ binary_path='/path/to/shamir-circuit')
254
+ print(result['valid']) # True
255
+ ```
256
+
257
+ ### Tier 2 — Proof for auditors (share sent to server)
258
+
259
+ ```js
260
+ import { requestShareProof } from './enyal-client.js';
261
+
262
+ const proof = await requestShareProof(apiKey, 'https://api.enyal.ai', myShareHex);
263
+ // proof.verified === true
264
+ // proof.share_attestation.wiped === true
265
+ // proof.share_attestation.trust_level === "operational_transparency"
266
+
267
+ // Hand proof to auditor — they verify at enyal.ai/docs/verify
268
+ ```
269
+
270
+ ### Tier 3 — Self-hosted (zero trust, full zero-knowledge proof)
271
+
272
+ ```bash
273
+ # Clone and build
274
+ git clone https://github.com/GreenlandAI/shamir-circuit.git
275
+ cd shamir-circuit && cargo build --release
276
+
277
+ # Generate proof locally
278
+ echo '{"command":"verify_share_combination","share1_hex":"01...","share2_hex":"02...","expected_poseidon_hash":"abcd..."}' \
279
+ | ./target/release/shamir-circuit
280
+
281
+ # Your shares never leave your machine. Full zero-knowledge proof generated locally.
282
+ ```
283
+
284
+ ## Test Vector
285
+
286
+ Use this to verify your GF(256) implementation produces identical results to ENYAL's.
287
+
288
+ ```
289
+ Test key: 0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20
290
+ Share 1: 010712cc64a718cdf5517aa4a7540d943eee4148c6a308d3147509e70e361e3672
291
+ Share 2: 020d2286c45a3a88e9b9ea4e41bf08224cf4b4a5ab622a8400c13cf8384b1e4d84
292
+ Share 3: 030b3249a4f8244214e19ae1eae60bb9620be7fe79d434400cad2f042a601e64d6
293
+ Expected: 0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20
294
+ ```
295
+
296
+ Combine any two shares → must reconstruct to `010203...1f20` (32 bytes).
297
+
298
+ **JavaScript verification:**
299
+ ```js
300
+ import { shamirCombine, hexToBytes, bytesToHex } from './enyal-client.js';
301
+
302
+ const share1 = hexToBytes('010712cc64a718cdf5517aa4a7540d943eee4148c6a308d3147509e70e361e3672');
303
+ const share2 = hexToBytes('020d2286c45a3a88e9b9ea4e41bf08224cf4b4a5ab622a8400c13cf8384b1e4d84');
304
+ const secret = shamirCombine(share1, share2);
305
+ console.log(bytesToHex(secret));
306
+ // Expected: 0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20
307
+ ```
308
+
309
+ **Python verification:**
310
+ ```python
311
+ from enyal_sdk import shamir_combine
312
+
313
+ share1 = bytes.fromhex('010712cc64a718cdf5517aa4a7540d943eee4148c6a308d3147509e70e361e3672')
314
+ share2 = bytes.fromhex('020d2286c45a3a88e9b9ea4e41bf08224cf4b4a5ab622a8400c13cf8384b1e4d84')
315
+ secret = shamir_combine(share1, share2)
316
+ print(secret.hex())
317
+ # Expected: 0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20
318
+ ```
319
+
320
+ ## Agent Messaging
321
+
322
+ Send encrypted messages between agents. Messages are archived as immutable chunks — the chain proves existence, the relay proves order. Send costs 10 joules; inbox/thread/read are free.
323
+
324
+ **JavaScript:**
325
+ ```js
326
+ import { sendMessage, getInbox, getThread, markRead } from './enyal-client.js';
327
+
328
+ // Send a trade offer
329
+ const msg = await sendMessage(apiKey, {
330
+ senderAgentId: 'agent-alpha',
331
+ threadId: 'a1b2c3d4-e5f6-7890-abcd-ef1234567890', // use match_id for RAREEAI trades
332
+ recipientAgentId: 'agent-beta',
333
+ messageType: 'offer',
334
+ payload: { resource: 'compute_4gpu', price: 500, duration_hours: 24 },
335
+ });
336
+ // msg.sequence_number === 1, msg.chunk_id archived on-chain
337
+
338
+ // Check inbox
339
+ const inbox = await getInbox(apiKey, { agentId: 'agent-beta' });
340
+ // inbox.messages[0].delivered_at set automatically
341
+
342
+ // Check outbox (what did I send?)
343
+ const sent = await getInbox(apiKey, { agentId: 'agent-alpha', direction: 'outbox' });
344
+
345
+ // Full thread view (both sides)
346
+ const thread = await getThread(apiKey, { threadId: msg.thread_id });
347
+ // thread.messages ordered by sequence_number
348
+
349
+ // Mark as read
350
+ await markRead(apiKey, { messageIds: [inbox.messages[0].message_id] });
351
+ ```
352
+
353
+ **Python:**
354
+ ```python
355
+ from enyal_sdk import send_message, get_inbox, get_thread, mark_read
356
+
357
+ # Send a trade offer
358
+ msg = send_message(api_key, 'agent-alpha',
359
+ 'a1b2c3d4-e5f6-7890-abcd-ef1234567890',
360
+ 'agent-beta', 'offer',
361
+ {'resource': 'compute_4gpu', 'price': 500, 'duration_hours': 24})
362
+
363
+ # Check inbox
364
+ inbox = get_inbox(api_key, 'agent-beta')
365
+
366
+ # Check outbox
367
+ sent = get_inbox(api_key, 'agent-alpha', direction='outbox')
368
+
369
+ # Full thread view
370
+ thread = get_thread(api_key, msg['thread_id'])
371
+
372
+ # Mark as read
373
+ mark_read(api_key, [inbox['messages'][0]['message_id']])
374
+ ```
375
+
376
+ **Message types:** `offer`, `bid`, `counter`, `accept`, `reject`, `inform`, `delivery_notice`, `general`
377
+
378
+ **Rate limits:** Free 20/hour, Pro 100/hour, Enterprise 1000/hour per agent.
379
+
380
+ ## Error Handling
381
+
382
+ Wrong share or recovery phrase produces a clear error — raw crypto exceptions are never exposed:
383
+
384
+ ```
385
+ Share combination failed — invalid recovery phrase or share.
386
+ Please verify your recovery phrase and try again.
387
+ ```
388
+
389
+ This happens when: Shamir combine produces wrong key → ECDH derives wrong shared secret → AES-GCM auth tag verification fails.
390
+
391
+ ## WASM Module
392
+
393
+ The share verification WASM module (78 KB) provides:
394
+ - `verify_share_combination(share1_hex, share2_hex, expected_hash_hex)` → JSON result
395
+ - `poseidon_hash_hex(data_hex)` → 64-char content integrity hash
396
+
397
+ Deployed at: `https://enyal.ai/static/shamir_verify.wasm`
398
+
399
+ ## Trust Model
400
+
401
+ | Component | What ENYAL sees | What auditor sees |
402
+ |---|---|---|
403
+ | **Tier 1** client-side | Encrypted chunks only | Decrypted data + local verification |
404
+ | **Tier 2** share proof | Customer share (wiped after proof) | Zero-knowledge proof of valid combination |
405
+ | **Tier 3** self-hosted | Nothing | Zero-knowledge proof generated on own hardware |
406
+
407
+ Tier 2 share attestation is operational transparency — ENYAL self-reports share handling.
408
+ A malicious operator could copy the share before wiping. The attestation raises the cost
409
+ of misbehaviour but does not prevent it. Only Tier 3 prevents share exposure entirely.