44import json
55import logging
66from collections .abc import Awaitable , Coroutine
7- from typing import Any , Callable , Literal , Union
7+ from typing import Any , Callable , Dict , Literal , Union
88
99import cryptography .exceptions
1010import pydantic
1515from jwcrypto .jwa import JWA
1616from pydantic import BaseModel , ValidationError , root_validator , validator
1717
18-
1918logger = logging .getLogger (__name__ )
2019
2120DOMAIN_NAME = "localhost"
2221
22+
2323def is_token_still_valid (datestr : str ):
2424 """
2525 Checks if a token has expired based on its expiry timestamp
@@ -42,7 +42,7 @@ def verify_wallet_signature(signature, message, address):
4242class SignedPubKeyPayload (BaseModel ):
4343 """This payload is signed by the wallet of the user to authorize an ephemeral key to act on his behalf."""
4444
45- pubkey : dict [str , Any ]
45+ pubkey : Dict [str , Any ]
4646 # {'pubkey': {'alg': 'ES256', 'crv': 'P-256', 'ext': True, 'key_ops': ['verify'], 'kty': 'EC',
4747 # 'x': '4blJBYpltvQLFgRvLE-2H7dsMr5O0ImHkgOnjUbG2AU', 'y': '5VHnq_hUSogZBbVgsXMs0CjrVfMy4Pa3Uv2BEBqfrN4'}
4848 # alg: Literal["ECDSA"]
@@ -63,15 +63,15 @@ class SignedPubKeyHeader(BaseModel):
6363 @validator ("signature" )
6464 def signature_must_be_hex (cls , v : bytes ) -> bytes :
6565 """Convert the signature from hexadecimal to bytes"""
66- return bytes .fromhex (v .removeprefix ( b"0x" ). decode ())
66+ return bytes .fromhex (v .decode ())
6767
6868 @validator ("payload" )
6969 def payload_must_be_hex (cls , v : bytes ) -> bytes :
7070 """Convert the payload from hexadecimal to bytes"""
7171 return bytes .fromhex (v .decode ())
7272
7373 @root_validator (pre = False , skip_on_failure = True )
74- def check_expiry (cls , values ) -> dict [str , bytes ]:
74+ def check_expiry (cls , values ) -> Dict [str , bytes ]:
7575 """Check that the token has not expired"""
7676 payload : bytes = values ["payload" ]
7777 content = SignedPubKeyPayload .parse_raw (payload )
@@ -81,7 +81,7 @@ def check_expiry(cls, values) -> dict[str, bytes]:
8181 return values
8282
8383 @root_validator (pre = False , skip_on_failure = True )
84- def check_signature (cls , values ) -> dict [str , bytes ]:
84+ def check_signature (cls , values ) -> Dict [str , bytes ]:
8585 """Check that the signature is valid"""
8686 signature : bytes = values ["signature" ]
8787 payload : bytes = values ["payload" ]
0 commit comments