Junaidb commited on
Commit
def47b4
·
verified ·
1 Parent(s): 2a2bb1a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -14
app.py CHANGED
@@ -57,27 +57,46 @@ async def relay_txn(payload: dict):
57
 
58
 
59
  @app.post("/sign-message")
60
- async def sign_message(payload: dict):
61
  #message = bytes(payload["message"])
62
 
63
  # 1️⃣ verify quantum proof (same as your txn logic)
64
- proof = base58.b58decode(payload["winternitz_proof"])
65
- anchor = base58.b58decode(payload["anchor"])
66
- lap = payload["lap"]
67
 
68
- check = proof
69
- for _ in range(lap):
70
- check = hashlib.sha256(check).digest()
71
 
72
- if check != anchor:
73
- return {"success": False, "error": "Quantum auth failed"}
74
 
75
- # 2️⃣ server signs message hash
76
-
77
 
78
- return {
79
- "success": True
80
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
 
82
 
83
 
 
57
 
58
 
59
  @app.post("/sign-message")
60
+ async def sign_message(req: dict):
61
  #message = bytes(payload["message"])
62
 
63
  # 1️⃣ verify quantum proof (same as your txn logic)
64
+ #proof = base58.b58decode(payload["winternitz_proof"])
65
+ #anchor = base58.b58decode(payload["anchor"])
66
+ #lap = payload["lap"]
67
 
68
+ #check = proof
69
+ #for _ in range(256-lap):
70
+ # check = hashlib.sha256(check).digest()
71
 
72
+ #if check != anchor:
73
+ # return {"success": False, "error": "Quantum auth failed"}
74
 
 
 
75
 
76
+ #return {
77
+ # "success": True
78
+ #}
79
+
80
+ payload = await req.json()
81
+
82
+ message = base58.b58decode(payload["message"])
83
+ signature = payload["signature"] # list[str]
84
+ public_key = payload["public_key"] # list[str]
85
+
86
+ msg_hash = hashlib.sha256(message).digest()
87
+
88
+ for i in range(len(signature)):
89
+ sig_i = base58.b58decode(signature[i])
90
+ pk_i = base58.b58decode(public_key[i])
91
+
92
+ check = sig_i
93
+ for _ in range(CHAIN_LENGTH - msg_hash[i]):
94
+ check = hashlib.sha256(check).digest()
95
+
96
+ if check != pk_i:
97
+ return {"status":False}
98
+
99
+ return {"status":True}
100
 
101
 
102