-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathverify_tlsn_proof.py
70 lines (60 loc) · 2.33 KB
/
verify_tlsn_proof.py
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
import json
import requests
from typing import Dict, Any, Annotated
def verify_tlsn_proof(proof_json: Annotated[str, "JSON content of the TLSN proof"]) -> Dict[str, Any]:
"""
Verify a TLSN proof by uploading it to explorer.tlsn.org
Args:
proof_json (str): The JSON content of the TLSN proof
Returns:
Dict[str, Any]: A dictionary containing the verification result
"""
try:
# Parse the JSON to ensure it's valid
proof_data = json.loads(proof_json)
# Upload to explorer.tlsn.org
# This is a simplified implementation - you may need to adjust based on actual API
response = requests.post(
"https://explorer.tlsn.org/api/verify",
json=proof_data,
headers={"Content-Type": "application/json"}
)
if response.status_code == 200:
result = response.json()
# Extract relevant information like name and country
return {
"success": True,
"verification_result": result,
"name": result.get("name", "Not found"),
"country": result.get("country", "Not found"),
"account_number": result.get("account_number", "Not found")
}
else:
return {
"success": False,
"error": f"Verification failed: {response.status_code}",
"message": response.text
}
except json.JSONDecodeError:
return {"success": False, "error": "Invalid JSON format"}
except Exception as e:
return {"success": False, "error": str(e)}
def save_tlsn_proof(proof_json: str) -> Dict[str, Any]:
"""
Save TLSN proof to a file
Args:
proof_json (str): The JSON content of the TLSN proof
Returns:
Dict[str, Any]: Result of the save operation
"""
try:
# Parse JSON to validate format
json.loads(proof_json)
# Save to file
with open("tlsn_proof.json", "w") as f:
f.write(proof_json)
return {"success": True, "message": "TLSN proof saved successfully"}
except json.JSONDecodeError:
return {"success": False, "error": "Invalid JSON format"}
except Exception as e:
return {"success": False, "error": str(e)}