Skip to content

Commit

Permalink
Fix: black in aleph_vm_authentification.py
Browse files Browse the repository at this point in the history
fix: isort issue

Fix: mypy issue

Fix: black

Fix: isort
  • Loading branch information
1yam committed Jun 19, 2024
1 parent 328e087 commit 5c61b9b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/aleph/sdk/client/vmclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ async def _generate_header(
signed_operation = self.sign_payload(payload, self.ephemeral_key)

if not self.pubkey_signature_header:
self.pubkey_signature_header = await self.generate_pubkey_signature_header()
self.pubkey_signature_header = (
await self._generate_pubkey_signature_header()
)

headers = {
"X-SignedPubKey": self.pubkey_signature_header,
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/aleph_vm_authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import json
import logging
from collections.abc import Awaitable, Coroutine
from typing import Any, Callable, Literal, Union
from typing import Any, Callable, Dict, Literal, Union

import cryptography.exceptions
import pydantic
Expand All @@ -15,11 +15,11 @@
from jwcrypto.jwa import JWA
from pydantic import BaseModel, ValidationError, root_validator, validator


logger = logging.getLogger(__name__)

DOMAIN_NAME = "localhost"


def is_token_still_valid(datestr: str):
"""
Checks if a token has expired based on its expiry timestamp
Expand All @@ -42,7 +42,7 @@ def verify_wallet_signature(signature, message, address):
class SignedPubKeyPayload(BaseModel):
"""This payload is signed by the wallet of the user to authorize an ephemeral key to act on his behalf."""

pubkey: dict[str, Any]
pubkey: Dict[str, Any]
# {'pubkey': {'alg': 'ES256', 'crv': 'P-256', 'ext': True, 'key_ops': ['verify'], 'kty': 'EC',
# 'x': '4blJBYpltvQLFgRvLE-2H7dsMr5O0ImHkgOnjUbG2AU', 'y': '5VHnq_hUSogZBbVgsXMs0CjrVfMy4Pa3Uv2BEBqfrN4'}
# alg: Literal["ECDSA"]
Expand All @@ -63,15 +63,15 @@ class SignedPubKeyHeader(BaseModel):
@validator("signature")
def signature_must_be_hex(cls, v: bytes) -> bytes:
"""Convert the signature from hexadecimal to bytes"""
return bytes.fromhex(v.removeprefix(b"0x").decode())
return bytes.fromhex(v.decode())

@validator("payload")
def payload_must_be_hex(cls, v: bytes) -> bytes:
"""Convert the payload from hexadecimal to bytes"""
return bytes.fromhex(v.decode())

@root_validator(pre=False, skip_on_failure=True)
def check_expiry(cls, values) -> dict[str, bytes]:
def check_expiry(cls, values) -> Dict[str, bytes]:
"""Check that the token has not expired"""
payload: bytes = values["payload"]
content = SignedPubKeyPayload.parse_raw(payload)
Expand All @@ -81,7 +81,7 @@ def check_expiry(cls, values) -> dict[str, bytes]:
return values

@root_validator(pre=False, skip_on_failure=True)
def check_signature(cls, values) -> dict[str, bytes]:
def check_signature(cls, values) -> Dict[str, bytes]:
"""Check that the signature is valid"""
signature: bytes = values["signature"]
payload: bytes = values["payload"]
Expand Down

0 comments on commit 5c61b9b

Please sign in to comment.