diff --git a/didcomm_messaging/didcomm.py b/didcomm_messaging/didcomm.py index 3f65dc9..194af3d 100644 --- a/didcomm_messaging/didcomm.py +++ b/didcomm_messaging/didcomm.py @@ -7,7 +7,7 @@ from pydid import DIDUrl, VerificationMethod from didcomm_messaging.crypto import P, S, CryptoService, SecretsManager from didcomm_messaging.jwe import JweEnvelope, from_b64url -from didcomm_messaging.resolver import Resolver +from didcomm_messaging.resolver import DIDResolver @dataclass @@ -24,12 +24,12 @@ class DIDCommMessagingError(Exception): """Represents an error from the DIDComm Messaging interface.""" -class DIDCommMessaging(Generic[P, S]): +class PackagingService(Generic[P, S]): """DIDComm Messaging interface.""" def __init__( self, - resolver: Resolver, + resolver: DIDResolver, crypto: CryptoService[P, S], secrets: SecretsManager[S], ): diff --git a/didcomm_messaging/resolver/__init__.py b/didcomm_messaging/resolver/__init__.py index 4963d81..19871fd 100644 --- a/didcomm_messaging/resolver/__init__.py +++ b/didcomm_messaging/resolver/__init__.py @@ -5,19 +5,19 @@ from pydid import DIDDocument, DIDUrl, Resource, VerificationMethod -class ResolutionError(Exception): +class DIDResolutionError(Exception): """Represents an error from a DID Resolver.""" -class DIDNotFound(ResolutionError): +class DIDNotFound(DIDResolutionError): """Represents a DID not found error.""" -class DIDMethodNotSupported(ResolutionError): +class DIDMethodNotSupported(DIDResolutionError): """Represents a DID method not supported error.""" -class Resolver(ABC): +class DIDResolver(ABC): """DID Resolver interface.""" @abstractmethod @@ -33,7 +33,7 @@ async def resolve_and_dereference(self, did_url: str) -> Resource: """Resolve a DID URL and dereference the identifier.""" url = DIDUrl.parse(did_url) if not url.did: - raise ResolutionError("Invalid DID URL; must be absolute") + raise DIDResolutionError("Invalid DID URL; must be absolute") doc = await self.resolve_and_parse(url.did) return doc.dereference(url) @@ -44,15 +44,15 @@ async def resolve_and_dereference_verification_method( """Resolve a DID URL and dereference the identifier.""" resource = await self.resolve_and_dereference(did_url) if not isinstance(resource, VerificationMethod): - raise ResolutionError("Resource is not a verification method") + raise DIDResolutionError("Resource is not a verification method") return resource -class PrefixResolver(Resolver): +class PrefixResolver(DIDResolver): """DID Resolver delegates to sub-resolvers by DID prefix.""" - def __init__(self, resolvers: Dict[str, Resolver]): + def __init__(self, resolvers: Dict[str, DIDResolver]): """Initialize the resolver.""" self.resolvers = resolvers diff --git a/didcomm_messaging/resolver/peer.py b/didcomm_messaging/resolver/peer.py index 3fb3bfa..cedc7ba 100644 --- a/didcomm_messaging/resolver/peer.py +++ b/didcomm_messaging/resolver/peer.py @@ -1,6 +1,6 @@ """did:peer resolver.""" -from didcomm_messaging.resolver import Resolver +from didcomm_messaging.resolver import DIDResolver try: from did_peer_2 import resolve as resolve_peer_2 @@ -12,7 +12,7 @@ ) -class Peer2(Resolver): +class Peer2(DIDResolver): """did:peer:2 resolver.""" async def resolve(self, did: str) -> dict: @@ -20,7 +20,7 @@ async def resolve(self, did: str) -> dict: return resolve_peer_2(did) -class Peer4(Resolver): +class Peer4(DIDResolver): """did:peer:4 resolver.""" async def resolve(self, did: str) -> dict: diff --git a/example.py b/example.py index 95bdebb..c358beb 100644 --- a/example.py +++ b/example.py @@ -3,7 +3,7 @@ from aries_askar import Key, KeyAlg from didcomm_messaging.crypto.askar import AskarCryptoService, AskarSecretKey from didcomm_messaging.crypto.basic import InMemorySecretsManager -from didcomm_messaging.didcomm import DIDCommMessaging +from didcomm_messaging.didcomm import PackagingService from didcomm_messaging.multiformats import multibase from didcomm_messaging.multiformats import multicodec from didcomm_messaging.resolver.peer import Peer2, Peer4 @@ -15,7 +15,7 @@ async def main(): """An example of using DIDComm Messaging.""" secrets = InMemorySecretsManager() crypto = AskarCryptoService() - didcomm = DIDCommMessaging( + packer = PackagingService( PrefixResolver({"did:peer:2": Peer2(), "did:peer:4": Peer4()}), crypto, secrets ) verkey = Key.generate(KeyAlg.ED25519) @@ -39,9 +39,9 @@ async def main(): await secrets.add_secret(AskarSecretKey(verkey, f"{did}#key-1")) await secrets.add_secret(AskarSecretKey(xkey, f"{did}#key-2")) print(did) - packed = await didcomm.pack(b"hello world", [did], did) + packed = await packer.pack(b"hello world", [did], did) print(json.dumps(json.loads(packed), indent=2)) - unpacked = await didcomm.unpack(packed) + unpacked = await packer.unpack(packed) print(unpacked)