enigma-memory 0.1.18 → 0.1.22
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.
- package/README.md +76 -24
- package/apps/cli/bin/enigma-desktop.mjs +140 -0
- package/apps/cli/bin/enigma-terminal.mjs +78 -0
- package/apps/cli/bin/enigma.mjs +1923 -285
- package/apps/desktop/electron-main.cjs +217 -0
- package/apps/desktop/package.json +12 -0
- package/apps/desktop/src/app.js +264 -7
- package/apps/desktop/src/index.html +3514 -1373
- package/apps/desktop/src/launch-electron.mjs +51 -0
- package/apps/desktop/src/server.mjs +2914 -0
- package/apps/desktop/src/styles.css +2972 -260
- package/apps/desktop/src/zk-browser-prove.mjs +53 -0
- package/apps/desktop/src/zk-state.mjs +1789 -0
- package/apps/gateway/bin/enigma-gateway.mjs +102 -5
- package/apps/gateway/src/server.mjs +271 -8
- package/apps/ios/EnigmaCore/Package.swift +12 -0
- package/apps/ios/EnigmaCore/Sources/EnigmaCore/EnigmaAPIClient.swift +227 -0
- package/apps/ios/EnigmaCore/Sources/EnigmaCore/Models.swift +278 -0
- package/apps/ios/EnigmaCore/Sources/EnigmaCore/PKCE.swift +96 -0
- package/apps/ios/EnigmaCore/Sources/EnigmaCore/PrivacyMinimizer.swift +187 -0
- package/apps/ios/EnigmaCore/Sources/EnigmaCore/ToolModels.swift +129 -0
- package/apps/ios/EnigmaCore/Tests/EnigmaCoreTests/EnigmaCoreTests.swift +42 -0
- package/apps/ios/EnigmaIOS/Enigma/AppModel.swift +346 -0
- package/apps/ios/EnigmaIOS/Enigma/Assets.xcassets/AccentColor.colorset/Contents.json +12 -0
- package/apps/ios/EnigmaIOS/Enigma/Assets.xcassets/AppIcon.appiconset/Contents.json +11 -0
- package/apps/ios/EnigmaIOS/Enigma/Assets.xcassets/AppIcon.appiconset/EnigmaAppIcon.png +0 -0
- package/apps/ios/EnigmaIOS/Enigma/Assets.xcassets/Contents.json +3 -0
- package/apps/ios/EnigmaIOS/Enigma/Assets.xcassets/LaunchBackground.colorset/Contents.json +12 -0
- package/apps/ios/EnigmaIOS/Enigma/ChatView.swift +181 -0
- package/apps/ios/EnigmaIOS/Enigma/CouncilView.swift +78 -0
- package/apps/ios/EnigmaIOS/Enigma/CreateView.swift +152 -0
- package/apps/ios/EnigmaIOS/Enigma/EnigmaApp.swift +52 -0
- package/apps/ios/EnigmaIOS/Enigma/Info.plist +52 -0
- package/apps/ios/EnigmaIOS/Enigma/NaturalLanguagePrivacyTagger.swift +26 -0
- package/apps/ios/EnigmaIOS/Enigma/OAuthClient.swift +321 -0
- package/apps/ios/EnigmaIOS/Enigma/OnboardingView.swift +105 -0
- package/apps/ios/EnigmaIOS/Enigma/PrivateVaultView.swift +275 -0
- package/apps/ios/EnigmaIOS/Enigma/SecureStore.swift +76 -0
- package/apps/ios/EnigmaIOS/Enigma/SettingsView.swift +60 -0
- package/apps/ios/EnigmaIOS/Enigma/Theme.swift +80 -0
- package/apps/ios/EnigmaIOS/EnigmaIOS.xcodeproj/project.pbxproj +211 -0
- package/apps/ios/EnigmaIOS/EnigmaIOS.xcodeproj/xcshareddata/xcschemes/Enigma.xcscheme +23 -0
- package/apps/native-host/README.md +19 -8
- package/apps/native-host/bin/enigma-native-host.mjs +229 -13
- package/apps/relay/bin/enigma-relay.mjs +103 -5
- package/apps/relay/src/federation-runtime.mjs +618 -0
- package/apps/relay/src/server.mjs +310 -9
- package/apps/verifier/bin/enigma-verify.mjs +327 -11
- package/cortex-v3/circuits/build/intent_vk_bytes.json +35 -0
- package/cortex-v3/circuits/build/sale_vk_bytes.json +35 -0
- package/cortex-v3/circuits/build/vk_bytes.json +32 -0
- package/cortex-v3/proving-assets.json +64 -0
- package/cortex-v3/zk/BUILD-CONTRACT.md +87 -0
- package/cortex-v3/zk/action-transition-vk.json +119 -0
- package/cortex-v3/zk/alias-adversarial.test.mjs +220 -0
- package/cortex-v3/zk/groth16-verify-child.mjs +17 -0
- package/cortex-v3/zk/intent-witness.mjs +365 -0
- package/cortex-v3/zk/intent-witness.test.mjs +485 -0
- package/cortex-v3/zk/proving-assets.mjs +203 -0
- package/cortex-v3/zk/sale-witness.mjs +783 -0
- package/cortex-v3/zk/sale-witness.test.mjs +784 -0
- package/cortex-v3/zk/sealed-sale-release-vk.json +119 -0
- package/cortex-v3/zk/settlement-evidence.mjs +722 -0
- package/cortex-v3/zk/setup-intent.mjs +688 -0
- package/cortex-v3/zk/setup-sale.mjs +666 -0
- package/cortex-v3/zk/setup.mjs +594 -0
- package/cortex-v3/zk/witness.mjs +184 -0
- package/cortex-v3/zk/zk-codec.mjs +232 -0
- package/cortex-v3/zk/zk-codec.test.mjs +293 -0
- package/cortex-v3/zk/zk-settle.mjs +370 -0
- package/cortex-v3/zk/zk-tree.mjs +256 -0
- package/cortex-v3/zk/zk-tree.test.mjs +419 -0
- package/deploy/docker-compose.local-production-simulation.yml +36 -0
- package/docs/browser-extension-install.md +8 -6
- package/docs/client-connectors.md +15 -11
- package/docs/developer-ecosystem.md +15 -13
- package/docs/enigma-memory-ready-conformance.md +11 -9
- package/docs/install-anywhere.md +61 -28
- package/docs/installers-and-desktop.md +8 -7
- package/docs/novelty-invention-candidates.md +161 -161
- package/docs/proof-network-claim-boundaries.md +320 -318
- package/examples/01-quickstart-agent/index.mjs +49 -0
- package/examples/01_agent_memory_quickstart.mjs +57 -0
- package/examples/02-multi-agent-swarm/index.mjs +57 -0
- package/examples/02_cross_model_passport.mjs +64 -0
- package/examples/03-langchain-memory/index.mjs +41 -0
- package/examples/03_poseidon_commitment_verification.mjs +71 -0
- package/examples/04-python-trading-agent/trader.py +49 -0
- package/examples/README.md +27 -0
- package/examples/ci/github-actions.yml +7 -2
- package/package.json +142 -11
- package/packages/adapters/PACKAGE_CONTRACT.md +1 -1
- package/packages/connectors/src/index.js +196 -4
- package/packages/connectors/swarm-router.mjs +168 -0
- package/packages/core/src/index.js +248 -1
- package/packages/core/src/version.mjs +7 -0
- package/packages/dev-tools/package.json +19 -0
- package/packages/dev-tools/src/index.js +4 -0
- package/packages/dev-tools/src/memory-benchmark-suite.js +112 -0
- package/packages/dev-tools/src/swarm-simulator.js +101 -0
- package/packages/dev-tools/src/vault-inspector.js +114 -0
- package/packages/dev-tools/src/vector-benchmark.js +100 -0
- package/packages/developer-platform/src/access-credentials.js +341 -0
- package/packages/developer-platform/src/http.js +132 -0
- package/packages/developer-platform/src/index.js +4 -0
- package/packages/developer-platform/src/usage-http.js +60 -0
- package/packages/developer-platform/src/usage.js +295 -0
- package/packages/enclave-runtime/attestation.mjs +159 -0
- package/packages/enclave-runtime/index.mjs +47 -0
- package/packages/enclave-runtime/session-manager.mjs +253 -0
- package/packages/enclave-runtime/zeroization-proof.mjs +227 -0
- package/packages/enigma-reflex/package.json +14 -0
- package/packages/enigma-reflex/src/index.js +204 -0
- package/packages/enigma-reflex/training/generate-dataset.mjs +40 -0
- package/packages/enigma-reflex/training/requirements.txt +8 -0
- package/packages/enigma-reflex/training/train.py +314 -0
- package/packages/enigma-weave/LICENSE +22 -0
- package/packages/enigma-weave/UPSTREAM.json +21 -0
- package/packages/enigma-weave/package.json +14 -0
- package/packages/enigma-weave/src/index.js +286 -0
- package/packages/hosted-cloud/src/index.js +80 -5
- package/packages/importers/src/index.js +432 -0
- package/packages/inference-runtime/src/browser.js +401 -0
- package/packages/inference-runtime/src/chat.js +265 -0
- package/packages/inference-runtime/src/code.js +407 -0
- package/packages/inference-runtime/src/contracts.js +162 -0
- package/packages/inference-runtime/src/http.js +232 -0
- package/packages/inference-runtime/src/image.js +186 -0
- package/packages/inference-runtime/src/index.js +10 -0
- package/packages/inference-runtime/src/model-router.js +320 -0
- package/packages/inference-runtime/src/platform.js +125 -0
- package/packages/inference-runtime/src/privacy.js +400 -0
- package/packages/inference-runtime/src/video.js +253 -0
- package/packages/mcp-server/README.md +22 -6
- package/packages/mcp-server/bin/enigma-mcp.mjs +2 -1
- package/packages/mcp-server/src/index.js +1418 -105
- package/packages/mcp-server/src/oauth.js +561 -0
- package/packages/mcp-server/src/private-handoff.js +84 -0
- package/packages/mcp-server/src/remote-http.js +273 -0
- package/packages/mcp-server/src/remote-policy.js +72 -0
- package/packages/mcp-server/swarm-bridge.mjs +361 -0
- package/packages/mesh/index.d.ts +283 -0
- package/packages/mesh/package.json +23 -0
- package/packages/mesh/src/crypto.js +189 -0
- package/packages/mesh/src/federation-packets.js +353 -0
- package/packages/mesh/src/gossip.js +311 -0
- package/packages/mesh/src/index.js +6 -0
- package/packages/mesh/src/protocol.js +255 -0
- package/packages/mesh/src/router.js +279 -0
- package/packages/mesh/src/transport.js +306 -0
- package/packages/passport/src/index.js +426 -1
- package/packages/private-economy/src/credits-http.js +100 -0
- package/packages/private-economy/src/credits.js +447 -0
- package/packages/private-economy/src/index.js +5 -0
- package/packages/private-economy/src/payments-http.js +120 -0
- package/packages/private-economy/src/payments.js +509 -0
- package/packages/private-economy/src/x402.js +346 -0
- package/packages/proof-network/PACKAGE_CONTRACT.md +21 -0
- package/packages/rag/index.d.ts +182 -0
- package/packages/rag/models/Xenova/all-MiniLM-L6-v2/THIRD_PARTY_LICENSES.txt +207 -0
- package/packages/rag/models/Xenova/all-MiniLM-L6-v2/config.json +25 -0
- package/packages/rag/models/Xenova/all-MiniLM-L6-v2/onnx/model_quantized.onnx +0 -0
- package/packages/rag/models/Xenova/all-MiniLM-L6-v2/sha256-manifest.json +28 -0
- package/packages/rag/models/Xenova/all-MiniLM-L6-v2/tokenizer.json +30686 -0
- package/packages/rag/models/Xenova/all-MiniLM-L6-v2/tokenizer_config.json +15 -0
- package/packages/rag/package.json +27 -0
- package/packages/rag/src/blinded-search.js +109 -0
- package/packages/rag/src/bm25.js +169 -0
- package/packages/rag/src/embeddings.js +459 -0
- package/packages/rag/src/hybrid.js +76 -0
- package/packages/rag/src/index.js +38 -0
- package/packages/rag/src/reranker.js +61 -0
- package/packages/rag/src/research.js +107 -0
- package/packages/rag/src/vector-store.js +430 -0
- package/packages/rag/src/verify-model-artifacts.mjs +4 -0
- package/packages/sdk/index.d.ts +760 -0
- package/packages/sdk/package.json +33 -0
- package/packages/sdk/python/README.md +24 -0
- package/packages/sdk/python/enigma_sdk.py +250 -0
- package/packages/sdk/python/pyproject.toml +34 -0
- package/packages/sdk/python/requirements.txt +1 -0
- package/packages/sdk/python/setup.py +20 -0
- package/packages/sdk/src/federation/capability-grant.js +389 -0
- package/packages/sdk/src/federation/federation-router.js +360 -0
- package/packages/sdk/src/federation/ghostmesh-bridge.js +497 -0
- package/packages/sdk/src/federation/index.js +3 -0
- package/packages/sdk/src/index.js +1796 -0
- package/packages/sdk/src/intelligence/contradiction.js +337 -0
- package/packages/sdk/src/intelligence/decision-engine.js +155 -0
- package/packages/sdk/src/intelligence/index.js +4 -0
- package/packages/sdk/src/intelligence/ontology.js +122 -0
- package/packages/sdk/src/intelligence/temporal.js +123 -0
- package/packages/sdk/src/market-client.js +142 -0
- package/packages/sdk/src/mesh-client.js +110 -0
- package/packages/sdk/src/middleware/index.js +3 -0
- package/packages/sdk/src/middleware/langchain.js +159 -0
- package/packages/sdk/src/middleware/llamaindex.js +101 -0
- package/packages/sdk/src/middleware/vercel-ai.js +112 -0
- package/packages/sdk/src/rag-client.js +85 -0
- package/packages/sdk/src/swarm-orchestrator.js +260 -0
- package/packages/settlement/PACKAGE_CONTRACT.md +1 -1
- package/packages/snapcompact/THIRD_PARTY_LICENSES.txt +40 -0
- package/packages/snapcompact/assets/8x13-latin1.bdf +3837 -0
- package/packages/snapcompact/index.d.ts +284 -0
- package/packages/snapcompact/package.json +25 -0
- package/packages/snapcompact/src/index.js +716 -0
- package/packages/storage/PACKAGE_CONTRACT.md +1 -1
- package/packages/terminal-console/animations.mjs +240 -0
- package/packages/terminal-console/auto-anchor.mjs +220 -0
- package/packages/terminal-console/banner.mjs +91 -0
- package/packages/terminal-console/commands.mjs +459 -0
- package/packages/terminal-console/delegation.mjs +152 -0
- package/packages/terminal-console/index.mjs +5 -0
- package/packages/terminal-console/outbox.mjs +143 -0
- package/packages/terminal-console/phantom-bridge.mjs +637 -0
- package/packages/terminal-console/repl.mjs +136 -0
- package/packages/terminal-console/signer-store.mjs +130 -0
- package/packages/terminal-console/solana-rpc.mjs +214 -0
- package/packages/terminal-console/solana-transport.mjs +189 -0
- package/packages/terminal-tui/dashboard.mjs +214 -0
- package/packages/terminal-tui/index.mjs +28 -0
- package/packages/terminal-tui/merkle-tree-renderer.mjs +268 -0
- package/packages/terminal-tui/telemetry-hud.mjs +137 -0
- package/packages/vault/index.d.ts +449 -0
- package/packages/vault/package.json +27 -0
- package/packages/vault/src/e2ee.mjs +393 -0
- package/packages/vault/src/enclave.js +481 -0
- package/packages/vault/src/erasure.js +207 -0
- package/packages/vault/src/index.js +1018 -155
- package/packages/vault/src/persistence.js +307 -0
- package/packages/vault/src/poseidon.js +354 -0
- package/packages/vault/src/receipt.js +459 -0
- package/scripts/benchmark-optical-context.mjs +166 -0
- package/scripts/bootstrap-enigma.mjs +502 -0
- package/scripts/build-edge-backend-workers.mjs +20 -5
- package/scripts/build-goal-completion-audit.mjs +72 -25
- package/scripts/build-hosted-api-key-lifecycle.mjs +26 -8
- package/scripts/build-hosted-customer-lifecycle.mjs +20 -3
- package/scripts/build-hosted-probe-worker.mjs +19 -4
- package/scripts/build-installer-assets.mjs +41 -21
- package/scripts/build-operator-evidence-starter.mjs +59 -1
- package/scripts/build-production-backend-env-kit.mjs +2 -0
- package/scripts/build-production-unblocker.mjs +3 -0
- package/scripts/check.mjs +17 -3
- package/scripts/collect-hosted-backend-live-evidence.mjs +49 -12
- package/scripts/install-enigma-local.mjs +18 -5
- package/scripts/release-audit.mjs +65 -109
- package/scripts/release-provenance.mjs +6 -0
- package/scripts/run-backend-readiness-smoke.mjs +112 -10
- package/scripts/scan-secrets.mjs +1 -0
- package/scripts/simulate-production-env.mjs +7 -2
- package/scripts/validate-hosted-backend-live.mjs +112 -1
- package/specs/antibody-pack-v1.schema.json +95 -0
- package/specs/antigen-envelope-v1.schema.json +81 -0
- package/specs/boundary-manifest-v1.schema.json +35 -35
- package/specs/capsule-v1.schema.json +55 -55
- package/specs/claim-boundary-manifest-v1.schema.json +22 -22
- package/specs/claim-ledger-v1.schema.json +291 -0
- package/specs/context-passport-v1.schema.json +59 -0
- package/specs/deletion-tombstone-v1.schema.json +26 -26
- package/specs/evidence-packet-v1.schema.json +177 -0
- package/specs/hosted-backend-live-evidence-v1.schema.json +72 -3
- package/specs/immune-scan-report-v1.schema.json +112 -0
- package/specs/lifecycle-receipt-log-v1.schema.json +67 -0
- package/specs/memory-atom-v1.schema.json +59 -0
- package/specs/memory-event-v1.schema.json +42 -42
- package/specs/passport-v1.schema.json +50 -50
- package/specs/proof-of-non-use-v1.schema.json +65 -0
- package/specs/quarantine-record-v1.schema.json +126 -0
- package/specs/receipt-v1.schema.json +61 -61
- package/specs/state-checkpoint-v1.schema.json +37 -37
- package/specs/trust-bundle-v1.schema.json +56 -56
- package/specs/trust-card-v1.schema.json +119 -0
- package/docs/proof-network-launch-plan.md +0 -421
- package/packages/metering/PACKAGE_CONTRACT.md +0 -20
- package/scripts/build-ai-orchestration-plan.mjs +0 -248
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@enigma/sdk",
|
|
3
|
+
"version": "0.1.22",
|
|
4
|
+
"description": "Unified Sovereign AI Agent SDK for Persistent Memory, GhostMesh P2P, and Solana ZKCP",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "src/index.js",
|
|
7
|
+
"types": "./index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"src/",
|
|
10
|
+
"index.d.ts",
|
|
11
|
+
"python/"
|
|
12
|
+
],
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./index.d.ts",
|
|
16
|
+
"import": "./src/index.js",
|
|
17
|
+
"default": "./src/index.js"
|
|
18
|
+
},
|
|
19
|
+
"./mesh": "./src/mesh-client.js",
|
|
20
|
+
"./market": {
|
|
21
|
+
"types": "./index.d.ts",
|
|
22
|
+
"import": "./src/market-client.js",
|
|
23
|
+
"default": "./src/market-client.js"
|
|
24
|
+
},
|
|
25
|
+
"./rag": "./src/rag-client.js"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@enigma/core": "workspace:*",
|
|
29
|
+
"@enigma/mesh": "workspace:*",
|
|
30
|
+
"@enigma/rag": "workspace:*",
|
|
31
|
+
"@enigma/vault": "workspace:*"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Enigma Sovereign AI Agent SDK (Python)
|
|
2
|
+
|
|
3
|
+
Native Python SDK for sovereign AI memory custody, AES-256-GCM vault encryption, and local vector retrieval.
|
|
4
|
+
|
|
5
|
+
## Quickstart
|
|
6
|
+
|
|
7
|
+
```python
|
|
8
|
+
from enigma_sdk import EnigmaPythonSDK
|
|
9
|
+
|
|
10
|
+
# 1. Connect
|
|
11
|
+
enigma = EnigmaPythonSDK.connect(scope="agent.solana", storage_path="./agent_vault.enc.json", passphrase="my-secret-passphrase")
|
|
12
|
+
|
|
13
|
+
# 2. Remember
|
|
14
|
+
enigma.remember("Always enforce 0.5% max slippage on Jupiter DEX swaps")
|
|
15
|
+
|
|
16
|
+
# 3. Recall
|
|
17
|
+
memories = enigma.recall("Jupiter swap slippage rules", top_k=1)
|
|
18
|
+
print(memories[0]["text"])
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Security
|
|
22
|
+
|
|
23
|
+
- **Encryption at Rest**: AES-256-GCM authenticated encryption with 600,000-round PBKDF2-HMAC-SHA256 key derivation.
|
|
24
|
+
- **Fail-Closed**: Requires explicit passphrase or 32-byte vault key when persistent storage is configured.
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Enigma Sovereign AI Agent SDK for Python.
|
|
3
|
+
Provides persistent memory custody, local vector search, and sovereign agent context.
|
|
4
|
+
Uses AES-256-GCM encryption at rest with 600,000-round PBKDF2-HMAC-SHA256 key derivation
|
|
5
|
+
or direct 32-byte master vault keys. Zero plaintext is stored on disk.
|
|
6
|
+
"""
|
|
7
|
+
import time
|
|
8
|
+
import math
|
|
9
|
+
import json
|
|
10
|
+
import os
|
|
11
|
+
import secrets
|
|
12
|
+
import base64
|
|
13
|
+
import hashlib
|
|
14
|
+
from typing import List, Dict, Any, Optional
|
|
15
|
+
from cryptography.hazmat.primitives.ciphers.aead import AESGCM
|
|
16
|
+
|
|
17
|
+
VAULT_AAD = b"enigma.python_vault.v1"
|
|
18
|
+
PBKDF2_ROUNDS = 600000
|
|
19
|
+
|
|
20
|
+
class EnigmaPythonSDK:
|
|
21
|
+
def __init__(
|
|
22
|
+
self,
|
|
23
|
+
scope: str = "enigma.global",
|
|
24
|
+
agent_id: Optional[str] = None,
|
|
25
|
+
storage_path: Optional[str] = None,
|
|
26
|
+
passphrase: Optional[str] = None,
|
|
27
|
+
vault_key: Optional[bytes] = None,
|
|
28
|
+
in_memory: bool = False,
|
|
29
|
+
api_base: str = "http://127.0.0.1:8787",
|
|
30
|
+
auth_token: Optional[str] = None
|
|
31
|
+
):
|
|
32
|
+
self.scope = scope
|
|
33
|
+
self.agent_id = agent_id or f"py_agent_{int(time.time())}"
|
|
34
|
+
self.storage_path = os.path.abspath(storage_path) if storage_path and not in_memory else None
|
|
35
|
+
self.passphrase = passphrase
|
|
36
|
+
self.api_base = api_base.rstrip('/')
|
|
37
|
+
self.auth_token = auth_token
|
|
38
|
+
self._local_memories: Dict[str, Dict[str, Any]] = {}
|
|
39
|
+
|
|
40
|
+
if self.storage_path and not self.passphrase and not vault_key:
|
|
41
|
+
raise ValueError(
|
|
42
|
+
"Explicit passphrase or vault_key is required when persistent storage_path is configured."
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
if vault_key:
|
|
46
|
+
if not isinstance(vault_key, (bytes, bytearray)) or len(vault_key) != 32:
|
|
47
|
+
raise ValueError("vault_key must be exactly 32 bytes")
|
|
48
|
+
self.vault_key = bytes(vault_key)
|
|
49
|
+
elif self.passphrase:
|
|
50
|
+
self.vault_key = self._derive_key(self.passphrase, secrets.token_bytes(16))
|
|
51
|
+
else:
|
|
52
|
+
self.vault_key = secrets.token_bytes(32)
|
|
53
|
+
|
|
54
|
+
if self.storage_path and os.path.exists(self.storage_path):
|
|
55
|
+
self.load()
|
|
56
|
+
|
|
57
|
+
@staticmethod
|
|
58
|
+
def _derive_key(passphrase: str, salt: bytes) -> bytes:
|
|
59
|
+
return hashlib.pbkdf2_hmac("sha256", passphrase.encode("utf-8"), salt, PBKDF2_ROUNDS, dklen=32)
|
|
60
|
+
|
|
61
|
+
@classmethod
|
|
62
|
+
def connect(
|
|
63
|
+
cls,
|
|
64
|
+
scope: str = "enigma.global",
|
|
65
|
+
agent_id: Optional[str] = None,
|
|
66
|
+
storage_path: Optional[str] = None,
|
|
67
|
+
passphrase: Optional[str] = None,
|
|
68
|
+
vault_key: Optional[bytes] = None,
|
|
69
|
+
api_base: str = "http://127.0.0.1:8787",
|
|
70
|
+
auth_token: Optional[str] = None
|
|
71
|
+
) -> 'EnigmaPythonSDK':
|
|
72
|
+
"""3-Line Quickstart Factory for Python Agents."""
|
|
73
|
+
return cls(
|
|
74
|
+
scope=scope,
|
|
75
|
+
agent_id=agent_id,
|
|
76
|
+
storage_path=storage_path,
|
|
77
|
+
passphrase=passphrase,
|
|
78
|
+
vault_key=vault_key,
|
|
79
|
+
api_base=api_base,
|
|
80
|
+
auth_token=auth_token
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
def remember(
|
|
84
|
+
self,
|
|
85
|
+
text: str,
|
|
86
|
+
scope: Optional[str] = None,
|
|
87
|
+
importance: float = 1.0,
|
|
88
|
+
metadata: Optional[Dict[str, Any]] = None
|
|
89
|
+
) -> Dict[str, Any]:
|
|
90
|
+
"""Stores a persistent memory atom in the sovereign vault."""
|
|
91
|
+
if not text or not isinstance(text, str):
|
|
92
|
+
raise ValueError("Memory text must be a non-empty string")
|
|
93
|
+
|
|
94
|
+
target_scope = scope or self.scope
|
|
95
|
+
atom_id = f"atom_{int(time.time() * 1000)}"
|
|
96
|
+
record = {
|
|
97
|
+
"id": atom_id,
|
|
98
|
+
"text": text,
|
|
99
|
+
"scope": target_scope,
|
|
100
|
+
"importance": importance,
|
|
101
|
+
"created_at": int(time.time() * 1000),
|
|
102
|
+
"metadata": metadata or {}
|
|
103
|
+
}
|
|
104
|
+
self._local_memories[atom_id] = record
|
|
105
|
+
|
|
106
|
+
if self.storage_path:
|
|
107
|
+
self.save()
|
|
108
|
+
|
|
109
|
+
return record
|
|
110
|
+
|
|
111
|
+
def recall(
|
|
112
|
+
self,
|
|
113
|
+
query: str,
|
|
114
|
+
top_k: int = 5,
|
|
115
|
+
scope: Optional[str] = None
|
|
116
|
+
) -> List[Dict[str, Any]]:
|
|
117
|
+
"""Retrieves top-k relevant memory atoms using lexical similarity."""
|
|
118
|
+
if not query or not isinstance(query, str):
|
|
119
|
+
return []
|
|
120
|
+
|
|
121
|
+
target_scope = scope or self.scope
|
|
122
|
+
query_words = set(query.lower().split())
|
|
123
|
+
scored = []
|
|
124
|
+
|
|
125
|
+
for atom_id, doc in self._local_memories.items():
|
|
126
|
+
if target_scope and doc["scope"] != target_scope and doc["scope"] != "enigma.global":
|
|
127
|
+
continue
|
|
128
|
+
doc_words = set(doc["text"].lower().split())
|
|
129
|
+
intersection = query_words.intersection(doc_words)
|
|
130
|
+
sim = len(intersection) / max(1, math.sqrt(len(query_words) * len(doc_words)))
|
|
131
|
+
score = sim * doc.get("importance", 1.0)
|
|
132
|
+
if score > 0:
|
|
133
|
+
scored.append({
|
|
134
|
+
"id": atom_id,
|
|
135
|
+
"text": doc["text"],
|
|
136
|
+
"score": round(score, 4),
|
|
137
|
+
"scope": doc["scope"],
|
|
138
|
+
"created_at": doc["created_at"]
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
scored.sort(key=lambda x: x["score"], reverse=True)
|
|
142
|
+
return scored[:top_k]
|
|
143
|
+
|
|
144
|
+
def save(self, target_path: Optional[str] = None) -> None:
|
|
145
|
+
"""Persists memory store to disk encrypted with AES-256-GCM."""
|
|
146
|
+
dest = os.path.abspath(target_path) if target_path else self.storage_path
|
|
147
|
+
if not dest:
|
|
148
|
+
raise ValueError("No storage_path configured for persistence")
|
|
149
|
+
|
|
150
|
+
kdf_meta = None
|
|
151
|
+
if self.passphrase:
|
|
152
|
+
salt = secrets.token_bytes(16)
|
|
153
|
+
active_key = self._derive_key(self.passphrase, salt)
|
|
154
|
+
self.vault_key = active_key
|
|
155
|
+
kdf_meta = {
|
|
156
|
+
"algorithm": "pbkdf2",
|
|
157
|
+
"iterations": PBKDF2_ROUNDS,
|
|
158
|
+
"hash": "sha256",
|
|
159
|
+
"salt": base64.b64encode(salt).decode("ascii")
|
|
160
|
+
}
|
|
161
|
+
else:
|
|
162
|
+
active_key = self.vault_key
|
|
163
|
+
kdf_meta = {
|
|
164
|
+
"algorithm": "direct_vault_key",
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
payload_raw = json.dumps({
|
|
168
|
+
"version": 1,
|
|
169
|
+
"format": "enigma.python_vault.v1",
|
|
170
|
+
"scope": self.scope,
|
|
171
|
+
"agent_id": self.agent_id,
|
|
172
|
+
"updated_at": int(time.time() * 1000),
|
|
173
|
+
"memories": list(self._local_memories.values())
|
|
174
|
+
}).encode("utf-8")
|
|
175
|
+
|
|
176
|
+
iv = secrets.token_bytes(12)
|
|
177
|
+
aesgcm = AESGCM(active_key)
|
|
178
|
+
ciphertext_with_tag = aesgcm.encrypt(iv, payload_raw, VAULT_AAD)
|
|
179
|
+
ciphertext = ciphertext_with_tag[:-16]
|
|
180
|
+
auth_tag = ciphertext_with_tag[-16:]
|
|
181
|
+
|
|
182
|
+
bundle = {
|
|
183
|
+
"version": 1,
|
|
184
|
+
"format": "enigma.python_vault.v1",
|
|
185
|
+
"kdf": kdf_meta,
|
|
186
|
+
"ciphertext": base64.b64encode(ciphertext).decode("ascii"),
|
|
187
|
+
"iv": iv.hex(),
|
|
188
|
+
"auth_tag": auth_tag.hex(),
|
|
189
|
+
"count": len(self._local_memories)
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
os.makedirs(os.path.dirname(dest), exist_ok=True)
|
|
193
|
+
tmp_file = f"{dest}.tmp.{int(time.time() * 1000)}"
|
|
194
|
+
with open(tmp_file, "w", encoding="utf-8") as f:
|
|
195
|
+
json.dump(bundle, f, indent=2)
|
|
196
|
+
os.replace(tmp_file, dest)
|
|
197
|
+
|
|
198
|
+
def load(self, source_path: Optional[str] = None) -> None:
|
|
199
|
+
"""Loads and decrypts memory store from disk. Fails closed on corruption/tampering."""
|
|
200
|
+
src = os.path.abspath(source_path) if source_path else self.storage_path
|
|
201
|
+
if not src or not os.path.exists(src):
|
|
202
|
+
raise FileNotFoundError(f"Storage path not found: {src}")
|
|
203
|
+
|
|
204
|
+
with open(src, "r", encoding="utf-8") as f:
|
|
205
|
+
bundle = json.load(f)
|
|
206
|
+
|
|
207
|
+
if bundle.get("format") != "enigma.python_vault.v1":
|
|
208
|
+
raise ValueError("Invalid Python vault bundle format")
|
|
209
|
+
|
|
210
|
+
kdf_meta = bundle.get("kdf", {})
|
|
211
|
+
if kdf_meta.get("algorithm") == "pbkdf2":
|
|
212
|
+
if not self.passphrase:
|
|
213
|
+
raise ValueError("Vault bundle requires passphrase to decrypt")
|
|
214
|
+
salt = base64.b64decode(kdf_meta.get("salt", ""))
|
|
215
|
+
if len(salt) < 16:
|
|
216
|
+
raise ValueError("Invalid or missing KDF salt in vault bundle")
|
|
217
|
+
active_key = self._derive_key(self.passphrase, salt)
|
|
218
|
+
self.vault_key = active_key
|
|
219
|
+
else:
|
|
220
|
+
active_key = self.vault_key
|
|
221
|
+
|
|
222
|
+
iv = bytes.fromhex(bundle["iv"])
|
|
223
|
+
auth_tag = bytes.fromhex(bundle["auth_tag"])
|
|
224
|
+
ciphertext = base64.b64decode(bundle["ciphertext"])
|
|
225
|
+
ciphertext_with_tag = ciphertext + auth_tag
|
|
226
|
+
|
|
227
|
+
aesgcm = AESGCM(active_key)
|
|
228
|
+
try:
|
|
229
|
+
decrypted_bytes = aesgcm.decrypt(iv, ciphertext_with_tag, VAULT_AAD)
|
|
230
|
+
except Exception as e:
|
|
231
|
+
raise ValueError(f"Decryption failed: invalid passphrase/key or corrupted vault bundle ({e})")
|
|
232
|
+
|
|
233
|
+
data = json.loads(decrypted_bytes.decode("utf-8"))
|
|
234
|
+
self._local_memories.clear()
|
|
235
|
+
for mem in data.get("memories", []):
|
|
236
|
+
self._local_memories[mem["id"]] = mem
|
|
237
|
+
|
|
238
|
+
def status(self) -> Dict[str, Any]:
|
|
239
|
+
"""Returns local agent status."""
|
|
240
|
+
return {
|
|
241
|
+
"ok": True,
|
|
242
|
+
"agent_id": self.agent_id,
|
|
243
|
+
"scope": self.scope,
|
|
244
|
+
"memory_count": len(self._local_memories),
|
|
245
|
+
"storage_path": self.storage_path,
|
|
246
|
+
"api_base": self.api_base
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
# Top-level canonical class alias
|
|
250
|
+
Enigma = EnigmaPythonSDK
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "enigma-memory"
|
|
7
|
+
version = "0.1.22"
|
|
8
|
+
description = "Enigma Sovereign AI Agent SDK for persistent memory custody, local vector search, and sovereign agent context"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = { text = "Apache-2.0" }
|
|
12
|
+
authors = [
|
|
13
|
+
{ name = "Enigma Memory", email = "team@enigmamemory.com" }
|
|
14
|
+
]
|
|
15
|
+
keywords = ["ai-memory", "sovereign-ai", "rag", "vector-search", "solana", "zk"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 4 - Beta",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"License :: OSI Approved :: Apache Software License",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3.9",
|
|
22
|
+
"Programming Language :: Python :: 3.10",
|
|
23
|
+
"Programming Language :: Python :: 3.11",
|
|
24
|
+
"Programming Language :: Python :: 3.12",
|
|
25
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
26
|
+
"Topic :: Security :: Cryptography"
|
|
27
|
+
]
|
|
28
|
+
dependencies = [
|
|
29
|
+
"cryptography>=41.0.0"
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
[project.urls]
|
|
33
|
+
Homepage = "https://enigmamemory.com"
|
|
34
|
+
Repository = "https://github.com/Enigma-Memory/enigma-cortex-enterprise"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
cryptography>=41.0.0
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
setup(
|
|
4
|
+
name="enigma-memory",
|
|
5
|
+
version="0.1.22",
|
|
6
|
+
py_modules=["enigma_sdk"],
|
|
7
|
+
install_requires=[
|
|
8
|
+
"cryptography>=41.0.0",
|
|
9
|
+
],
|
|
10
|
+
author="Enigma Memory",
|
|
11
|
+
author_email="team@enigmamemory.com",
|
|
12
|
+
description="Enigma Sovereign AI Agent SDK for persistent memory custody, local vector search, and sovereign agent context",
|
|
13
|
+
license="Apache-2.0",
|
|
14
|
+
keywords="ai-memory sovereign-ai rag vector-search solana zk",
|
|
15
|
+
url="https://enigmamemory.com",
|
|
16
|
+
classifiers=[
|
|
17
|
+
"License :: OSI Approved :: Apache Software License",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
],
|
|
20
|
+
)
|