-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreceiver.py
More file actions
86 lines (74 loc) · 2.68 KB
/
receiver.py
File metadata and controls
86 lines (74 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
"""
receiver.py — Docker receiver container entrypoint
Non-interactive pipeline: transmission → verify hash → rebuild payload
Reads from /output/ volume:
- folded_input.json (the fold from sender)
- transmission.json (hash + uid from sender)
Prints verified payload to stdout.
"""
import json
import hashlib
from pathlib import Path
SEED = "haskell_texas_bridge_2026"
def compute_hash(obj):
json_bytes = json.dumps(obj, sort_keys=True).encode('utf-8')
return hashlib.sha256(json_bytes).hexdigest()
def main():
print("=" * 60)
print("RECEIVER — hashkey-standalone Docker test")
print("=" * 60)
output_dir = Path("/output")
# Step 1 — Read transmission (what crossed the wire)
tx_path = output_dir / "transmission.json"
if not tx_path.exists():
print("[!] transmission.json not found — run sender first")
return
transmission = json.loads(tx_path.read_text())
uid = transmission["uid"]
hash_key = transmission["hash_key"]
timestamp = transmission["timestamp"]
print(f"[+] Transmission received")
print(f"[+] UID: {uid}")
print(f"[+] Hash key: {hash_key[:16]}...")
# Step 2 — Read fold from shared volume
fold_path = output_dir / "folded_input.json"
if not fold_path.exists():
print("[!] folded_input.json not found in shared volume")
return
folded = json.loads(fold_path.read_text())
print(f"[+] Fold loaded — strand length: {folded['strand_length']} bits")
# Step 3 — Recompute hash and verify
hash_obj = {
"uid": uid,
"seed": SEED,
"input": folded,
"timestamp": timestamp
}
recomputed = compute_hash(hash_obj)
if recomputed == hash_key:
print(f"[✔] Hash verified — MATCH")
else:
print(f"[✗] Hash MISMATCH")
print(f" Expected: {hash_key}")
print(f" Recomputed: {recomputed}")
return
# Step 4 — Rebuild payload
payload = folded.get("payload")
if not payload:
print("[!] No payload in fold")
return
print()
print("=" * 60)
print("PAYLOAD REBUILT AT RECEIVER")
print("=" * 60)
print(f" message: {payload.get('message')}")
print(f" sender: {payload.get('sender')}")
print(f" destination: {payload.get('destination')}")
print(f" content: {payload['payload'].get('content')}")
print(f" timestamp: {payload['payload'].get('timestamp')}")
print(f" strand: {folded['strand_length']} bits")
print(f" payload_hash:{folded['payload_hash'][:16]}...")
print()
print("RECEIVER COMPLETE — data rebuilt from hash address")
if __name__ == "__main__":
main()