Spaces:
Sleeping
Sleeping
Create proof_engine.py
Browse files- proof_engine.py +23 -0
proof_engine.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# proof_engine.py
|
| 2 |
+
|
| 3 |
+
import hashlib
|
| 4 |
+
import json
|
| 5 |
+
import time
|
| 6 |
+
from typing import Dict
|
| 7 |
+
|
| 8 |
+
def make_proof(input_data: Dict, result: Dict) -> Dict:
|
| 9 |
+
"""
|
| 10 |
+
Generate deterministic proof hash of the economic result + timestamp.
|
| 11 |
+
"""
|
| 12 |
+
payload = {
|
| 13 |
+
"input": input_data,
|
| 14 |
+
"output": result,
|
| 15 |
+
"timestamp": time.time()
|
| 16 |
+
}
|
| 17 |
+
canonical = json.dumps(payload, sort_keys=True, separators=(",", ":"))
|
| 18 |
+
proof_hash = hashlib.sha256(canonical.encode()).hexdigest()
|
| 19 |
+
|
| 20 |
+
return {
|
| 21 |
+
"payload": payload,
|
| 22 |
+
"proof": proof_hash
|
| 23 |
+
}
|