Research-Stack/5-Applications/tools-scripts/utils/bind_secrets_to_substrate.py

119 lines
5 KiB
Python

#!/usr/bin/env python3
# ==============================================================================
# COPYRIGHT NO ONE EVERYWHERE LLC (WYOMING HOLDING COMPANY)
# PROJECT: SOVEREIGN STACK
# This artifact is entirely proprietary and cryptographically proven.
# Open-Source usage requires explicit permission from Brandon Scott Schneider.
# ==============================================================================
# PTOS: LAYER=SECURITY / DOMAIN=ISOLATION / CONDITION=STABLE / STAGE=ACTIVE / SOURCE=CODE
"""
Secret Sub-Register Binder v4.0 — High-speed GPU/Neuromorph binding.
==================================================================
Binds .secrets/* files to the 11D Neuromorphic GPU Surface using TSM-AAC opcodes.
"""
import os
import json
import hashlib
import sys
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
from math_harness_compat import xp, AnyArray
from pathlib import Path
REPO_ROOT = Path(os.getenv("RESEARCH_STACK_ROOT") or Path(__file__).resolve().parents[1])
DOWNLOADS_ROOT = Path(os.getenv("DOWNLOADS_ROOT") or Path.home() / "Downloads")
# Add paths for dependencies
sys.path.append(str(DOWNLOADS_ROOT))
from tsm_aac_mcp_harness import TSMAACKernel, TermType
from neuromorphic_soliton_miner import NeuromorphicGPUSurface, SolitonCollisionEngine
ROOT = REPO_ROOT
SECRETS_DIR = ROOT / ".secrets"
DATA_DIR = ROOT / "data"
# ── NE geometry scaffold (geometry-rip branch) ────────────────────────────────
# Fixes EUCLIDEAN_ASSUMPTION_AUDIT finding #10 (MEDIUM): arithmetic mean of
# bimodal (potentiated/depressed) Hebbian weights. Mean is wrong for bimodal.
# Fix: use xp.median or fraction-above-0.5 as more geometrically meaningful proxy.
_USE_NE_GEOMETRY = False
class SecretBinder:
def __init__(self):
self.kernel = TSMAACKernel()
self.surface = NeuromorphicGPUSurface(num_neurons=2048, dimensions=11)
self.soliton_engine = SolitonCollisionEngine(dimensions=11)
self.bindings = {}
def bind_secret(self, secret_path: Path):
"""Bind a secret using TSM-AAC opcodes 0x5F and 0x0E."""
content = secret_path.read_bytes()
secret_hash = hashlib.sha256(content).hexdigest()
print(f"[bind] Binding {secret_path.name} (hash: {secret_hash[:16]}...)")
# 1. PHI-locked seed from hash
seed = int(secret_hash[:16], 16)
xp.random.seed(seed % (2**32))
# 2. Execute 0x01: ABSORB_BH
# This "melts" the data into the manifold state-space
state_id = self.kernel.absorb_bh(content.decode('utf-8', errors='ignore'), {"pkg": secret_path.name, "tier": "DIAMONDOID_HYDRIDE"})
# 3. Execute 0x5F: LANE_REGISTER_BIND
reg_id = f"R{seed % 16:02d}"
bind_result = self.kernel.execute([("0x5F", [state_id, reg_id])])
# 3. Generate and Collide Solitons
s1 = self.soliton_engine.generate_soliton_packet(seed)
s2 = self.soliton_engine.generate_soliton_packet(seed ^ 0xFFFFFFFF)
collapsed = self.soliton_engine.collide_solitons(s1, s2)
# 4. Execute 0x0E: NEUROMORPH_COLLISION
# Reinforces the binding through the neural surface
sub_register_id = f"subreg_{hashlib.sha256(collapsed.packet_id.encode()).hexdigest()[:12]}"
self.kernel.execute([("0x0E", [sub_register_id, {"phi_resonance": 0.618034}])])
# 5. Bind to Neural Surface (Weights)
input_vector = collapsed.position / xp.linalg.norm(collapsed.position)
self.surface.process_input(input_vector)
self.surface.update_weights(1.0)
self.bindings[secret_path.name] = {
"sub_register_id": sub_register_id,
"target_register": reg_id,
"foam_score": round(float(
# NE path: median is correct for bimodal Hebbian distributions.
# AUDIT FINDING #10: arithmetic mean is wrong for bimodal (potentiated/depressed).
xp.median(self.surface.synaptic_weights) if _USE_NE_GEOMETRY
else xp.mean(self.surface.synaptic_weights)
), 6),
"nd_point": collapsed.position.tolist(),
"attestation": bind_result[0]
}
print(f" -> Assigned to {reg_id} | {sub_register_id}")
def save_registry(self):
"""Update the substrate index with new bindings."""
registry_path = DATA_DIR / "secret_sub_registers.json"
DATA_DIR.mkdir(exist_ok=True)
with open(registry_path, 'w') as f:
json.dump(self.bindings, f, indent=2)
print(f"\n[save] Secret Sub-Register Registry updated -> {registry_path}")
def main():
binder = SecretBinder()
if not SECRETS_DIR.exists():
print(f"Error: Secrets directory {SECRETS_DIR} not found.")
return
for secret_file in SECRETS_DIR.iterdir():
if secret_file.is_file() and not secret_file.name.startswith("."):
binder.bind_secret(secret_file)
binder.save_registry()
if __name__ == "__main__":
main()