|
16 | 16 | from jwcrypto import jwk |
17 | 17 | from jwcrypto.jwa import JWA |
18 | 18 | from pydantic import BaseModel, ValidationError, field_validator, model_validator |
| 19 | +from typing_extensions import Self |
19 | 20 |
|
20 | 21 | from aleph.sdk.utils import bytes_from_hex |
21 | 22 |
|
@@ -76,28 +77,28 @@ def payload_must_be_hex(cls, value: bytes) -> bytes: |
76 | 77 | return bytes_from_hex(value.decode()) |
77 | 78 |
|
78 | 79 | @model_validator(mode="after") # type: ignore |
79 | | - def check_expiry(cls, values: SignedPubKeyHeader) -> SignedPubKeyHeader: |
| 80 | + def check_expiry(self) -> Self: |
80 | 81 | """Check that the token has not expired""" |
81 | | - payload: bytes = values.payload |
| 82 | + payload: bytes = self.payload |
82 | 83 | content = SignedPubKeyPayload.model_validate_json(payload) |
83 | 84 |
|
84 | 85 | if not is_token_still_valid(content.expires): |
85 | 86 | msg = "Token expired" |
86 | 87 | raise ValueError(msg) |
87 | 88 |
|
88 | | - return values |
| 89 | + return self |
89 | 90 |
|
90 | 91 | @model_validator(mode="after") # type: ignore |
91 | | - def check_signature(cls, values: SignedPubKeyHeader) -> SignedPubKeyHeader: |
92 | | - signature: bytes = values.signature |
93 | | - payload: bytes = values.payload |
| 92 | + def check_signature(self) -> Self: |
| 93 | + signature: bytes = self.signature |
| 94 | + payload: bytes = self.payload |
94 | 95 | content = SignedPubKeyPayload.model_validate_json(payload) |
95 | 96 |
|
96 | 97 | if not verify_wallet_signature(signature, payload.hex(), content.address): |
97 | 98 | msg = "Invalid signature" |
98 | 99 | raise ValueError(msg) |
99 | 100 |
|
100 | | - return values |
| 101 | + return self |
101 | 102 |
|
102 | 103 | @property |
103 | 104 | def content(self) -> SignedPubKeyPayload: |
|
0 commit comments