-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from Indicio-tech/feature/authlib
feat: Add Authlib backend and test compatibility with Askar
- Loading branch information
Showing
16 changed files
with
926 additions
and
227 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,94 +1,5 @@ | ||
"""Key Management Service (CryptoService) interface for DIDComm Messaging.""" | ||
"""DIDComm Messaging Cryptography and Secrets Interfaces.""" | ||
|
||
from .base import CryptoService, SecretsManager, PublicKey, SecretKey, P, S | ||
|
||
from abc import ABC, abstractmethod | ||
from typing import Generic, Optional, Sequence, TypeVar, Union | ||
|
||
from pydid import VerificationMethod | ||
|
||
from .jwe import JweEnvelope | ||
|
||
|
||
class CryptoServiceError(Exception): | ||
"""Represents an error from a CryptoService.""" | ||
|
||
|
||
class PublicKey(ABC): | ||
"""Key representation for CryptoService.""" | ||
|
||
@classmethod | ||
@abstractmethod | ||
def from_verification_method(cls, vm: VerificationMethod) -> "PublicKey": | ||
"""Create a Key instance from a DID Document Verification Method.""" | ||
|
||
@property | ||
@abstractmethod | ||
def kid(self) -> str: | ||
"""Get the key ID.""" | ||
|
||
@property | ||
@abstractmethod | ||
def multikey(self) -> str: | ||
"""Get the key in multikey format.""" | ||
|
||
|
||
class SecretKey(ABC): | ||
"""Secret Key Type.""" | ||
|
||
@property | ||
@abstractmethod | ||
def kid(self) -> str: | ||
"""Get the key ID.""" | ||
|
||
|
||
P = TypeVar("P", bound=PublicKey) | ||
S = TypeVar("S", bound=SecretKey) | ||
|
||
|
||
class CryptoService(ABC, Generic[P, S]): | ||
"""Key Management Service (CryptoService) interface for DIDComm Messaging.""" | ||
|
||
@abstractmethod | ||
async def ecdh_es_encrypt(self, to_keys: Sequence[P], message: bytes) -> bytes: | ||
"""Encode a message into DIDComm v2 anonymous encryption.""" | ||
|
||
@abstractmethod | ||
async def ecdh_es_decrypt( | ||
self, wrapper: Union[JweEnvelope, str, bytes], recip_key: S | ||
) -> bytes: | ||
"""Decode a message from DIDComm v2 anonymous encryption.""" | ||
|
||
@abstractmethod | ||
async def ecdh_1pu_encrypt( | ||
self, | ||
to_keys: Sequence[P], | ||
sender_key: S, | ||
message: bytes, | ||
) -> bytes: | ||
"""Encode a message into DIDComm v2 authenticated encryption.""" | ||
|
||
@abstractmethod | ||
async def ecdh_1pu_decrypt( | ||
self, | ||
wrapper: Union[JweEnvelope, str, bytes], | ||
recip_key: S, | ||
sender_key: P, | ||
) -> bytes: | ||
"""Decode a message from DIDComm v2 authenticated encryption.""" | ||
|
||
@classmethod | ||
@abstractmethod | ||
def verification_method_to_public_key(cls, vm: VerificationMethod) -> P: | ||
"""Convert a verification method to a public key.""" | ||
|
||
|
||
class SecretsManager(ABC, Generic[S]): | ||
"""Secrets Resolver interface. | ||
Thie secrets resolver may be used to supplement the CryptoService backend to provide | ||
greater flexibility. | ||
""" | ||
|
||
@abstractmethod | ||
async def get_secret_by_kid(self, kid: str) -> Optional[S]: | ||
"""Get a secret key by its ID.""" | ||
__all__ = ["CryptoService", "SecretsManager", "PublicKey", "SecretKey", "P", "S"] |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Cryptography and Secrets Management backends.""" |
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
Oops, something went wrong.