-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
120 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
import typing as t | ||
|
||
from .p256 import P256 | ||
from .secp256k1 import Secp256k1 | ||
|
||
__all__ = ['P256', 'Secp256k1'] | ||
_ANY_ALG_TYPE = t.Union[t.Type[P256], t.Type[Secp256k1]] | ||
|
||
AVAILABLE_ALGORITHMS: t.List[_ANY_ALG_TYPE] = [P256, Secp256k1] | ||
ALGORITHM_TO_CLASS: t.Dict[str, _ANY_ALG_TYPE] = {alg.NAME: alg for alg in AVAILABLE_ALGORITHMS} | ||
|
||
AVAILABLE_ALGORITHMS = [P256, Secp256k1] | ||
__all__ = ['P256', 'Secp256k1', 'ALGORITHM_TO_CLASS'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
from cryptography.hazmat.primitives.asymmetric.ec import SECP256R1 | ||
|
||
from atproto_crypto.algs.base_alg import AlgBase | ||
from atproto_crypto.consts import P256_JWT_ALG | ||
|
||
|
||
class P256(AlgBase): | ||
NAME = P256_JWT_ALG | ||
|
||
def __init__(self) -> None: | ||
super().__init__(SECP256R1()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
from cryptography.hazmat.primitives.asymmetric.ec import SECP256K1 | ||
|
||
from atproto_crypto.algs.base_alg import AlgBase | ||
from atproto_crypto.consts import SECP256K1_JWT_ALG | ||
|
||
|
||
class Secp256k1(AlgBase): | ||
NAME = SECP256K1_JWT_ALG | ||
|
||
def __init__(self) -> None: | ||
super().__init__(SECP256K1()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,24 @@ | ||
import typing as t | ||
import warnings | ||
|
||
from atproto_crypto.algs import ALGORITHM_TO_CLASS | ||
from atproto_crypto.did import parse_did_key | ||
from atproto_crypto.exceptions import UnsupportedSignatureAlgorithmError | ||
|
||
|
||
def verify_signature(did_key: str, signing_input: t.Union[str, bytes], signature: t.Union[str, bytes]) -> bool: | ||
# TODO(MarshalX): implement | ||
warnings.warn( | ||
'verify_signature is not implemented yet. Do not trust to this signing_input', | ||
RuntimeWarning, | ||
stacklevel=0, | ||
) | ||
|
||
return True | ||
"""Verify signature. | ||
Args: | ||
did_key: DID key. | ||
signing_input: Signing input (data). | ||
signature: Signature. | ||
Returns: | ||
bool: True if signature is valid, False otherwise. | ||
""" | ||
parsed_did_key = parse_did_key(did_key) | ||
if parsed_did_key.jwt_alg not in ALGORITHM_TO_CLASS: | ||
raise UnsupportedSignatureAlgorithmError('Unsupported signature alg') | ||
|
||
algorithm_class = ALGORITHM_TO_CLASS[parsed_did_key.jwt_alg] | ||
return algorithm_class().verify_signature(parsed_did_key.key_bytes, signing_input, signature) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters