44import json
55import logging
66from collections .abc import Awaitable , Coroutine
7- from typing import Any , Callable , Dict , Literal , Union
7+ from typing import Any , Callable , Dict , Literal , Union , Optional
88
99import cryptography .exceptions
1010import pydantic
@@ -45,7 +45,7 @@ def verify_wallet_signature(signature: bytes, message: str, address: str) -> boo
4545class SignedPubKeyPayload (BaseModel ):
4646 """This payload is signed by the wallet of the user to authorize an ephemeral key to act on his behalf."""
4747
48- pubkey : dict [str , Any ]
48+ pubkey : Dict [str , Any ]
4949 # {'pubkey': {'alg': 'ES256', 'crv': 'P-256', 'ext': True, 'key_ops': ['verify'], 'kty': 'EC',
5050 # 'x': '4blJBYpltvQLFgRvLE-2H7dsMr5O0ImHkgOnjUbG2AU', 'y': '5VHnq_hUSogZBbVgsXMs0CjrVfMy4Pa3Uv2BEBqfrN4'}
5151 # alg: Literal["ECDSA"]
@@ -76,7 +76,7 @@ def payload_must_be_hex(cls, value: bytes) -> bytes:
7676 return bytes_from_hex (value .decode ())
7777
7878 @root_validator (pre = False , skip_on_failure = True )
79- def check_expiry (cls , values ) -> dict [str , bytes ]:
79+ def check_expiry (cls , values ) -> Dict [str , bytes ]:
8080 """Check that the token has not expired"""
8181 payload : bytes = values ["payload" ]
8282 content = SignedPubKeyPayload .parse_raw (payload )
@@ -229,7 +229,9 @@ def verify_signed_operation(
229229 raise web .HTTPUnauthorized (reason = "Signature could not verified" )
230230
231231
232- async def authenticate_jwk (request : web .Request , domain_name : str = DOMAIN_NAME ) -> str :
232+ async def authenticate_jwk (
233+ request : web .Request , domain_name : Optional [str ] = DOMAIN_NAME
234+ ) -> str :
233235 """Authenticate a request using the X-SignedPubKey and X-SignedOperation headers."""
234236 signed_pubkey = get_signed_pubkey (request )
235237 signed_operation = get_signed_operation (request )
@@ -254,7 +256,7 @@ async def authenticate_jwk(request: web.Request, domain_name: str = DOMAIN_NAME)
254256
255257
256258async def authenticate_websocket_message (
257- message , domain_name : str = DOMAIN_NAME
259+ message , domain_name : Optional [ str ] = DOMAIN_NAME
258260) -> str :
259261 """Authenticate a websocket message since JS cannot configure headers on WebSockets."""
260262 signed_pubkey = SignedPubKeyHeader .parse_obj (message ["X-SignedPubKey" ])
0 commit comments