Junaidb commited on
Commit
9c72176
·
verified ·
1 Parent(s): 848cb59

Update components/middleware.py

Browse files
Files changed (1) hide show
  1. components/middleware.py +63 -2
components/middleware.py CHANGED
@@ -25,6 +25,8 @@ import time
25
  #from geopy.exc import GeocoderServiceError
26
  #geolocator = Nominatim(user_agent="velocity")
27
 
 
 
28
  from privy import PrivyAPI
29
 
30
  client = PrivyAPI(
@@ -259,12 +261,71 @@ class x401Kit(BaseHTTPMiddleware):
259
 
260
 
261
 
 
 
262
  NONCE=SecretNonceGenerator()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
263
 
264
  X_401_Nonce=request.headers.get("X-401-Nonce")
265
  X_401_Sign=request.headers.get("X-401-Signature")
266
  X_401_Addr=request.headers.get("X-401-Addr")
267
- aud=request.headers.get("origin")
268
  client_jwt=request.headers.get("x-jwt")
269
 
270
 
@@ -274,7 +335,7 @@ class x401Kit(BaseHTTPMiddleware):
274
  if client_jwt:
275
  decoded=verifyJWT(client_jwt,aud)
276
  return JSONResponse(
277
- content={"status":"identified","token":X_401_Addr,"message":"identified already"},
278
  status_code=200,
279
  headers={
280
 
 
25
  #from geopy.exc import GeocoderServiceError
26
  #geolocator = Nominatim(user_agent="velocity")
27
 
28
+ from mongodbconnection import provideClient
29
+
30
  from privy import PrivyAPI
31
 
32
  client = PrivyAPI(
 
261
 
262
 
263
 
264
+
265
+
266
  NONCE=SecretNonceGenerator()
267
+
268
+ aud=request.headers.get("origin")
269
+ MPC_=request.headers.get("mpc")
270
+ MPC_ID=request.headers.get("mpc_id")
271
+ MPC_STATUS=request.headers.get("mpc_status")
272
+
273
+
274
+ if MPC=="true" and MPC_STATUS=="active":
275
+
276
+ document=coll.find_one({"onwer":"system"})
277
+ for doc in document:
278
+ if doc["id"]==MPC_ID:
279
+ decoded=verifyJWT(doc["x-jwt"],aud)
280
+ return JSONResponse(
281
+ content={"status":"active","token":decoded,"message":"identified already"},
282
+ status_code=200,
283
+ headers={
284
+
285
+ "Access-Control-Allow-Origin": "*",
286
+ "Access-Control-Allow-Credentials": "true"
287
+
288
+ })
289
+
290
+ elif MPC=="true" and MPC_STATUS=="create":
291
+ wallet = client.wallets.create( chain_type="solana")
292
+ payload={
293
+ "id":wallet.id,
294
+ "x-jwt":""
295
+ }
296
+
297
+ coll.update_one(
298
+ {"owner": "system"},
299
+ {"$push": {"mpc": payload}}
300
+ )
301
+
302
+ return JSONResponse(
303
+ content={"status":"ready","id":wallet.id},
304
+ status_code+200,
305
+ headers={
306
+
307
+ "Access-Control-Allow-Origin":"*",
308
+ "Access-Control-Allow-Credentials": "true"
309
+
310
+ }
311
+ )
312
+
313
+
314
+ elif MPC=="true" and MPC_STATUS=="ready":
315
+
316
+
317
+
318
+
319
+
320
+
321
+
322
+
323
+
324
 
325
  X_401_Nonce=request.headers.get("X-401-Nonce")
326
  X_401_Sign=request.headers.get("X-401-Signature")
327
  X_401_Addr=request.headers.get("X-401-Addr")
328
+
329
  client_jwt=request.headers.get("x-jwt")
330
 
331
 
 
335
  if client_jwt:
336
  decoded=verifyJWT(client_jwt,aud)
337
  return JSONResponse(
338
+ content={"status":"identified","token":decoded,"message":"identified already"},
339
  status_code=200,
340
  headers={
341