Junaidb commited on
Commit
30deb22
·
verified ·
1 Parent(s): 863d0bc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -2
app.py CHANGED
@@ -13,12 +13,46 @@ from helpers.mongodbconnection import provideClient
13
 
14
 
15
 
16
-
17
-
18
  app = FastAPI()
19
  solana_client = Client("https://api.mainnet-beta.solana.com")
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
 
 
 
 
 
22
 
23
 
24
 
 
13
 
14
 
15
 
 
 
16
  app = FastAPI()
17
  solana_client = Client("https://api.mainnet-beta.solana.com")
18
 
19
+ SERVER_KEY = Keypair.from_base58_string("special_quantum_key")
20
+
21
+
22
+
23
+
24
+ @app.post("/relay-txn")
25
+ async def relay_txn(payload: dict):
26
+ # 1. Verification Math
27
+ proof = base58.b58decode(payload['winternitz_hash'])
28
+ anchor = base58.b58decode(payload['anchor']) # Stored in your DB
29
+ lap = payload['lap']
30
+
31
+ # Hash the proof 'lap' times to see if it hits the anchor
32
+ check = proof
33
+ for _ in range(lap):
34
+ check = hashlib.sha256(check).digest()
35
+
36
+ if check != anchor:
37
+ raise HTTPException(status_code=403, detail="Quantum Auth Failed")
38
+
39
+ # 2. Transaction Execution
40
+ # Deserialize the transaction sent from the UI
41
+ raw_tx = base58.b58decode(payload['txn'])
42
+ txn = Transaction.deserialize(raw_tx)
43
+
44
+ # ✅ THE MAGIC STEP: The server signs as the "Fee Payer"
45
+ # The 'From' address in the txn is still the user's wallet!
46
+ response = client.send_transaction(txn, SERVER_PAYER_KEY)
47
+
48
+ #🏁 THIS IS IT: The actual on-chain signature!
49
+ actual_signature = str(response.value)
50
 
51
+ return {
52
+ "success": True,
53
+ "signature": actual_signature,
54
+ "status": "Finalized on Solana"
55
+ }
56
 
57
 
58