@aleph-ai/tinyaleph 1.0.0

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 (58) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +278 -0
  3. package/backends/cryptographic/index.js +196 -0
  4. package/backends/index.js +15 -0
  5. package/backends/interface.js +89 -0
  6. package/backends/scientific/index.js +272 -0
  7. package/backends/semantic/index.js +527 -0
  8. package/backends/semantic/surface.js +393 -0
  9. package/backends/semantic/two-layer.js +375 -0
  10. package/core/fano.js +127 -0
  11. package/core/hilbert.js +564 -0
  12. package/core/hypercomplex.js +141 -0
  13. package/core/index.js +133 -0
  14. package/core/llm.js +132 -0
  15. package/core/prime.js +184 -0
  16. package/core/resonance.js +695 -0
  17. package/core/rformer-tf.js +1086 -0
  18. package/core/rformer.js +806 -0
  19. package/core/sieve.js +350 -0
  20. package/data.json +8163 -0
  21. package/docs/EXAMPLES_PLAN.md +293 -0
  22. package/docs/README.md +159 -0
  23. package/docs/design/ALEPH_CHAT_ARCHITECTURE.md +499 -0
  24. package/docs/guide/01-quickstart.md +298 -0
  25. package/docs/guide/02-semantic-computing.md +409 -0
  26. package/docs/guide/03-cryptographic.md +420 -0
  27. package/docs/guide/04-scientific.md +494 -0
  28. package/docs/guide/05-llm-integration.md +568 -0
  29. package/docs/guide/06-advanced.md +996 -0
  30. package/docs/guide/README.md +188 -0
  31. package/docs/reference/01-core.md +695 -0
  32. package/docs/reference/02-physics.md +601 -0
  33. package/docs/reference/03-backends.md +892 -0
  34. package/docs/reference/04-engine.md +632 -0
  35. package/docs/reference/README.md +252 -0
  36. package/docs/theory/01-prime-semantics.md +327 -0
  37. package/docs/theory/02-hypercomplex-algebra.md +421 -0
  38. package/docs/theory/03-phase-synchronization.md +364 -0
  39. package/docs/theory/04-entropy-reasoning.md +348 -0
  40. package/docs/theory/05-non-commutativity.md +402 -0
  41. package/docs/theory/06-two-layer-meaning.md +414 -0
  42. package/docs/theory/07-resonant-field-interface.md +419 -0
  43. package/docs/theory/08-semantic-sieve.md +520 -0
  44. package/docs/theory/09-temporal-emergence.md +298 -0
  45. package/docs/theory/10-quaternionic-memory.md +415 -0
  46. package/docs/theory/README.md +162 -0
  47. package/engine/aleph.js +418 -0
  48. package/engine/index.js +7 -0
  49. package/index.js +23 -0
  50. package/modular.js +254 -0
  51. package/package.json +99 -0
  52. package/physics/collapse.js +95 -0
  53. package/physics/entropy.js +88 -0
  54. package/physics/index.js +65 -0
  55. package/physics/kuramoto.js +91 -0
  56. package/physics/lyapunov.js +80 -0
  57. package/physics/oscillator.js +95 -0
  58. package/types/index.d.ts +575 -0
@@ -0,0 +1,420 @@
1
+ # Cryptographic Applications
2
+
3
+ This guide covers using Aleph for semantic hashing, key derivation, and verification.
4
+
5
+ ## Overview
6
+
7
+ Aleph's cryptographic backend leverages **hypercomplex arithmetic** to create semantically-aware cryptographic primitives. Unlike traditional hashing where similar inputs produce wildly different outputs, semantic hashing preserves relationships—similar meanings produce similar hashes.
8
+
9
+ ---
10
+
11
+ ## Creating a Cryptographic Engine
12
+
13
+ ```javascript
14
+ const { createEngine, CryptographicBackend } = require('./modular');
15
+
16
+ // Load configuration
17
+ const config = require('./data.json');
18
+
19
+ // Create engine
20
+ const engine = createEngine('cryptographic', config);
21
+
22
+ // Or create backend directly
23
+ const backend = new CryptographicBackend(config);
24
+ ```
25
+
26
+ ---
27
+
28
+ ## Semantic Hashing
29
+
30
+ ### Basic Hashing
31
+
32
+ ```javascript
33
+ const backend = new CryptographicBackend(config);
34
+
35
+ // Hash a phrase
36
+ const hash = backend.hash('truth and wisdom');
37
+ console.log('Hash:', hash);
38
+ // Returns a compact string representation of the hypercomplex state
39
+
40
+ // Hash is deterministic
41
+ console.log(backend.hash('truth and wisdom') === hash); // true
42
+ ```
43
+
44
+ ### Hash Properties
45
+
46
+ ```javascript
47
+ // Get full hash state (not just string)
48
+ const hashState = backend.hashToState('love and light');
49
+
50
+ console.log('Entropy:', hashState.entropy());
51
+ console.log('Norm:', hashState.norm());
52
+ console.log('Dimension:', hashState.dimension);
53
+
54
+ // Access components
55
+ console.log('Components:', hashState.components);
56
+ ```
57
+
58
+ ### Similarity-Preserving Hashes
59
+
60
+ ```javascript
61
+ const backend = new CryptographicBackend(config);
62
+
63
+ // Similar meanings → similar hashes
64
+ const hash1 = backend.hashToState('truth and wisdom');
65
+ const hash2 = backend.hashToState('truth and knowledge');
66
+ const hash3 = backend.hashToState('cats and dogs');
67
+
68
+ console.log('truth+wisdom vs truth+knowledge:', hash1.coherence(hash2));
69
+ // High coherence (~0.7-0.9)
70
+
71
+ console.log('truth+wisdom vs cats+dogs:', hash1.coherence(hash3));
72
+ // Low coherence (~0.1-0.3)
73
+ ```
74
+
75
+ ---
76
+
77
+ ## Key Derivation
78
+
79
+ ### Deriving Keys from Phrases
80
+
81
+ ```javascript
82
+ const backend = new CryptographicBackend(config);
83
+
84
+ // Derive a key from a passphrase
85
+ const key = backend.deriveKey('my secret passphrase');
86
+
87
+ console.log('Key type:', typeof key); // object (SedenionState)
88
+ console.log('Key dimension:', key.dimension);
89
+ console.log('Key entropy:', key.entropy());
90
+
91
+ // Keys are deterministic
92
+ const key2 = backend.deriveKey('my secret passphrase');
93
+ console.log('Same key:', key.coherence(key2) === 1.0); // true
94
+ ```
95
+
96
+ ### Key Strengthening
97
+
98
+ ```javascript
99
+ // Multiple rounds increase security
100
+ function strengthenKey(phrase, rounds, backend) {
101
+ let key = backend.deriveKey(phrase);
102
+
103
+ for (let i = 0; i < rounds; i++) {
104
+ // Use key to modify itself
105
+ key = key.multiply(backend.deriveKey(key.toString()));
106
+ }
107
+
108
+ return key;
109
+ }
110
+
111
+ const weakKey = backend.deriveKey('password');
112
+ const strongKey = strengthenKey('password', 1000, backend);
113
+
114
+ console.log('Weak entropy:', weakKey.entropy());
115
+ console.log('Strong entropy:', strongKey.entropy());
116
+ ```
117
+
118
+ ### Salted Keys
119
+
120
+ ```javascript
121
+ function deriveSaltedKey(phrase, salt, backend) {
122
+ const phraseKey = backend.deriveKey(phrase);
123
+ const saltKey = backend.deriveKey(salt);
124
+ return phraseKey.multiply(saltKey);
125
+ }
126
+
127
+ const key1 = deriveSaltedKey('password', 'user123', backend);
128
+ const key2 = deriveSaltedKey('password', 'user456', backend);
129
+
130
+ console.log('Same password, different salt:', key1.coherence(key2));
131
+ // Low coherence - effectively different keys
132
+ ```
133
+
134
+ ---
135
+
136
+ ## Verification
137
+
138
+ ### Content Verification
139
+
140
+ ```javascript
141
+ const backend = new CryptographicBackend(config);
142
+
143
+ // Create a verification hash for content
144
+ const content = 'This is the original message';
145
+ const verificationHash = backend.hash(content);
146
+
147
+ // Later, verify content hasn't changed
148
+ function verifyContent(content, expectedHash, backend) {
149
+ const actualHash = backend.hash(content);
150
+ return actualHash === expectedHash;
151
+ }
152
+
153
+ console.log('Verified:', verifyContent(content, verificationHash, backend));
154
+ // true
155
+
156
+ console.log('Modified:', verifyContent('This is a modified message', verificationHash, backend));
157
+ // false
158
+ ```
159
+
160
+ ### Signature Verification
161
+
162
+ ```javascript
163
+ // Sign with private key
164
+ function sign(message, privateKey, backend) {
165
+ const messageState = backend.hashToState(message);
166
+ return messageState.multiply(privateKey);
167
+ }
168
+
169
+ // Verify with public key
170
+ function verify(message, signature, publicKey, backend) {
171
+ const messageState = backend.hashToState(message);
172
+ const expectedSig = messageState.multiply(publicKey);
173
+ return signature.coherence(expectedSig) > 0.99;
174
+ }
175
+
176
+ const privateKey = backend.deriveKey('my private key seed');
177
+ const publicKey = privateKey.conjugate(); // Simplified example
178
+
179
+ const message = 'Transfer 100 coins to Alice';
180
+ const sig = sign(message, privateKey, backend);
181
+
182
+ console.log('Valid signature:', verify(message, sig, publicKey, backend));
183
+ console.log('Tampered:', verify('Transfer 1000 coins to Alice', sig, publicKey, backend));
184
+ ```
185
+
186
+ ---
187
+
188
+ ## Semantic Security Features
189
+
190
+ ### Meaning-Aware Access Control
191
+
192
+ ```javascript
193
+ const backend = new CryptographicBackend(config);
194
+
195
+ // Create capability based on meaning
196
+ function createCapability(intent, secretKey, backend) {
197
+ const intentState = backend.hashToState(intent);
198
+ return intentState.multiply(secretKey);
199
+ }
200
+
201
+ // Check if capability grants access
202
+ function checkCapability(capability, requiredIntent, secretKey, backend) {
203
+ const expected = createCapability(requiredIntent, secretKey, backend);
204
+ return capability.coherence(expected) > 0.8; // Allow semantic similarity
205
+ }
206
+
207
+ const secretKey = backend.deriveKey('master secret');
208
+ const readCap = createCapability('read documents', secretKey, backend);
209
+
210
+ console.log('Read access:', checkCapability(readCap, 'read documents', secretKey, backend));
211
+ // true
212
+
213
+ console.log('View access:', checkCapability(readCap, 'view documents', secretKey, backend));
214
+ // true (semantically similar)
215
+
216
+ console.log('Delete access:', checkCapability(readCap, 'delete documents', secretKey, backend));
217
+ // false (semantically different)
218
+ ```
219
+
220
+ ### Fuzzy Password Matching
221
+
222
+ ```javascript
223
+ function createFuzzyPassword(phrase, backend) {
224
+ return backend.hashToState(phrase);
225
+ }
226
+
227
+ function checkFuzzyPassword(attempt, stored, threshold = 0.9) {
228
+ return attempt.coherence(stored) >= threshold;
229
+ }
230
+
231
+ const backend = new CryptographicBackend(config);
232
+ const stored = createFuzzyPassword('my secret phrase', backend);
233
+
234
+ // Exact match
235
+ const attempt1 = createFuzzyPassword('my secret phrase', backend);
236
+ console.log('Exact:', checkFuzzyPassword(attempt1, stored)); // true
237
+
238
+ // Close match (typo-tolerant if using semantic encoding)
239
+ const attempt2 = createFuzzyPassword('my secret phrases', backend);
240
+ console.log('Close:', checkFuzzyPassword(attempt2, stored, 0.8)); // might be true
241
+
242
+ // Wrong password
243
+ const attempt3 = createFuzzyPassword('wrong password', backend);
244
+ console.log('Wrong:', checkFuzzyPassword(attempt3, stored)); // false
245
+ ```
246
+
247
+ ---
248
+
249
+ ## Practical Applications
250
+
251
+ ### Semantic Document Fingerprinting
252
+
253
+ ```javascript
254
+ function fingerprintDocument(text, backend) {
255
+ // Split into chunks
256
+ const sentences = text.split(/[.!?]+/).filter(s => s.trim());
257
+
258
+ // Hash each chunk
259
+ const chunkHashes = sentences.map(s => backend.hashToState(s.trim()));
260
+
261
+ // Combine all hashes
262
+ let fingerprint = chunkHashes[0];
263
+ for (let i = 1; i < chunkHashes.length; i++) {
264
+ fingerprint = fingerprint.multiply(chunkHashes[i]);
265
+ }
266
+
267
+ return fingerprint;
268
+ }
269
+
270
+ // Detect similar documents
271
+ function documentSimilarity(doc1, doc2, backend) {
272
+ const fp1 = fingerprintDocument(doc1, backend);
273
+ const fp2 = fingerprintDocument(doc2, backend);
274
+ return fp1.coherence(fp2);
275
+ }
276
+
277
+ const backend = new CryptographicBackend(config);
278
+ const doc1 = 'Truth leads to wisdom. Wisdom leads to peace.';
279
+ const doc2 = 'Truth guides us to knowledge. Knowledge brings tranquility.';
280
+ const doc3 = 'Cats are fluffy. Dogs are loyal.';
281
+
282
+ console.log('doc1 vs doc2:', documentSimilarity(doc1, doc2, backend)); // High
283
+ console.log('doc1 vs doc3:', documentSimilarity(doc1, doc3, backend)); // Low
284
+ ```
285
+
286
+ ### Commitment Schemes
287
+
288
+ ```javascript
289
+ // Commit to a value without revealing it
290
+ function commit(value, nonce, backend) {
291
+ const valueState = backend.hashToState(value);
292
+ const nonceState = backend.hashToState(nonce);
293
+ return valueState.multiply(nonceState);
294
+ }
295
+
296
+ // Reveal and verify commitment
297
+ function reveal(commitment, value, nonce, backend) {
298
+ const expected = commit(value, nonce, backend);
299
+ return commitment.coherence(expected) > 0.99;
300
+ }
301
+
302
+ const backend = new CryptographicBackend(config);
303
+ const secret = 'my secret vote';
304
+ const nonce = 'random_string_12345';
305
+
306
+ const commitment = commit(secret, nonce, backend);
307
+ console.log('Commitment created');
308
+
309
+ // Later...
310
+ console.log('Valid reveal:', reveal(commitment, secret, nonce, backend)); // true
311
+ console.log('Wrong value:', reveal(commitment, 'other vote', nonce, backend)); // false
312
+ ```
313
+
314
+ ### Secure Semantic Search
315
+
316
+ ```javascript
317
+ // Create searchable encryption index
318
+ function createSecureIndex(documents, key, backend) {
319
+ return documents.map((doc, i) => ({
320
+ id: i,
321
+ encryptedHash: backend.hashToState(doc).multiply(key)
322
+ }));
323
+ }
324
+
325
+ // Search without revealing query
326
+ function secureSearch(query, index, key, backend) {
327
+ const queryHash = backend.hashToState(query).multiply(key);
328
+
329
+ return index
330
+ .map(entry => ({
331
+ id: entry.id,
332
+ score: queryHash.coherence(entry.encryptedHash)
333
+ }))
334
+ .filter(r => r.score > 0.5)
335
+ .sort((a, b) => b.score - a.score);
336
+ }
337
+
338
+ const backend = new CryptographicBackend(config);
339
+ const key = backend.deriveKey('index encryption key');
340
+
341
+ const docs = [
342
+ 'Love and happiness',
343
+ 'Truth and wisdom',
344
+ 'Dogs and cats'
345
+ ];
346
+
347
+ const index = createSecureIndex(docs, key, backend);
348
+ const results = secureSearch('knowledge and understanding', index, key, backend);
349
+
350
+ console.log('Search results:', results);
351
+ // Documents semantically similar to query will rank higher
352
+ ```
353
+
354
+ ---
355
+
356
+ ## Security Considerations
357
+
358
+ ### Entropy Requirements
359
+
360
+ ```javascript
361
+ function checkKeyStrength(key, minEntropy = 4.0) {
362
+ const entropy = key.entropy();
363
+ return {
364
+ entropy,
365
+ sufficient: entropy >= minEntropy,
366
+ recommendation: entropy < minEntropy
367
+ ? 'Use longer passphrase or key strengthening'
368
+ : 'Key entropy is adequate'
369
+ };
370
+ }
371
+
372
+ const backend = new CryptographicBackend(config);
373
+
374
+ console.log(checkKeyStrength(backend.deriveKey('hi')));
375
+ // Low entropy warning
376
+
377
+ console.log(checkKeyStrength(backend.deriveKey('correct horse battery staple')));
378
+ // Adequate entropy
379
+ ```
380
+
381
+ ### Collision Resistance
382
+
383
+ ```javascript
384
+ // Hypercomplex hashes have 16 dimensions
385
+ // Collision probability depends on component precision
386
+
387
+ function estimateCollisionProbability(dimension, precision) {
388
+ const space = Math.pow(2, precision * dimension);
389
+ return 1 / space;
390
+ }
391
+
392
+ console.log('16D with 64-bit precision:');
393
+ console.log('Collision probability:', estimateCollisionProbability(16, 64));
394
+ // Astronomically small
395
+ ```
396
+
397
+ ### Side-Channel Considerations
398
+
399
+ ```javascript
400
+ // Use constant-time comparison for security-critical code
401
+ function constantTimeCompare(state1, state2) {
402
+ let diff = 0;
403
+ const c1 = state1.components;
404
+ const c2 = state2.components;
405
+
406
+ for (let i = 0; i < c1.length; i++) {
407
+ diff |= (c1[i] !== c2[i]) ? 1 : 0;
408
+ }
409
+
410
+ return diff === 0;
411
+ }
412
+ ```
413
+
414
+ ---
415
+
416
+ ## Next Steps
417
+
418
+ - [Scientific Applications →](./04-scientific.md)
419
+ - [Theory: Entropy and Information →](../theory/04-entropy-reasoning.md)
420
+ - [Reference: CryptographicBackend →](../reference/03-backends.md#cryptographic-backend)