-
Notifications
You must be signed in to change notification settings - Fork 516
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 #2596 from ianco/anoncreds-rs-migrate-1
Initial code migration from anoncreds-rs branch
- Loading branch information
Showing
59 changed files
with
7,799 additions
and
175 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
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,4 +1,3 @@ | ||
--- | ||
repos: | ||
- repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook | ||
rev: v9.5.0 | ||
|
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,42 @@ | ||
import logging | ||
|
||
from ..config.injection_context import InjectionContext | ||
from ..config.provider import ClassProvider | ||
|
||
from .registry import AnonCredsRegistry | ||
|
||
LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
async def setup(context: InjectionContext): | ||
"""Set up default resolvers.""" | ||
registry = context.inject_or(AnonCredsRegistry) | ||
if not registry: | ||
LOGGER.error("No AnonCredsRegistry instance found in context!!!") | ||
return | ||
|
||
indy_registry = ClassProvider( | ||
"aries_cloudagent.anoncreds.default.did_indy.registry.DIDIndyRegistry", | ||
# supported_identifiers=[], | ||
# method_name="did:indy", | ||
).provide(context.settings, context.injector) | ||
await indy_registry.setup(context) | ||
registry.register(indy_registry) | ||
|
||
web_registry = ClassProvider( | ||
"aries_cloudagent.anoncreds.default.did_web.registry.DIDWebRegistry", | ||
# supported_identifiers=[], | ||
# method_name="did:web", | ||
).provide(context.settings, context.injector) | ||
await web_registry.setup(context) | ||
registry.register(web_registry) | ||
|
||
legacy_indy_registry = ClassProvider( | ||
"aries_cloudagent.anoncreds.default.legacy_indy.registry.LegacyIndyRegistry", | ||
# supported_identifiers=[], | ||
# method_name="", | ||
).provide(context.settings, context.injector) | ||
await legacy_indy_registry.setup(context) | ||
registry.register(legacy_indy_registry) | ||
|
||
# TODO: add context.settings |
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,190 @@ | ||
"""Base Registry.""" | ||
from abc import ABC, abstractmethod | ||
from typing import Generic, Optional, Pattern, Sequence, TypeVar | ||
|
||
from ..config.injection_context import InjectionContext | ||
from ..core.error import BaseError | ||
from ..core.profile import Profile | ||
from .models.anoncreds_cred_def import ( | ||
CredDef, | ||
CredDefResult, | ||
GetCredDefResult, | ||
) | ||
from .models.anoncreds_revocation import ( | ||
GetRevListResult, | ||
GetRevRegDefResult, | ||
RevRegDef, | ||
RevRegDefResult, | ||
RevList, | ||
RevListResult, | ||
) | ||
from .models.anoncreds_schema import AnonCredsSchema, GetSchemaResult, SchemaResult | ||
|
||
|
||
T = TypeVar("T") | ||
|
||
|
||
class BaseAnonCredsError(BaseError): | ||
"""Base error class for AnonCreds.""" | ||
|
||
|
||
class AnonCredsObjectNotFound(BaseAnonCredsError): | ||
"""Raised when object is not found in resolver.""" | ||
|
||
def __init__( | ||
self, message: Optional[str] = None, resolution_metadata: Optional[dict] = None | ||
): | ||
"""Constructor.""" | ||
super().__init__(message, resolution_metadata) | ||
self.resolution_metadata = resolution_metadata | ||
|
||
|
||
class AnonCredsRegistrationError(BaseAnonCredsError): | ||
"""Raised when registering an AnonCreds object fails.""" | ||
|
||
|
||
class AnonCredsObjectAlreadyExists(AnonCredsRegistrationError, Generic[T]): | ||
"""Raised when an AnonCreds object already exists.""" | ||
|
||
def __init__( | ||
self, | ||
message: str, | ||
obj_id: str, | ||
obj: T = None, | ||
*args, | ||
**kwargs, | ||
): | ||
"""Initialize an instance. | ||
Args: | ||
message: Message | ||
obj_id: Object ID | ||
obj: Object | ||
TODO: update this docstring - Anoncreds-break. | ||
""" | ||
super().__init__(message, obj_id, obj, *args, **kwargs) | ||
self._message = message | ||
self.obj_id = obj_id | ||
self.obj = obj | ||
|
||
@property | ||
def message(self): | ||
"""Message.""" | ||
return f"{self._message}: {self.obj_id}, {self.obj}" | ||
|
||
|
||
class AnonCredsSchemaAlreadyExists(AnonCredsObjectAlreadyExists[AnonCredsSchema]): | ||
"""Raised when a schema already exists.""" | ||
|
||
@property | ||
def schema_id(self): | ||
"""Get Schema Id.""" | ||
return self.obj_id | ||
|
||
@property | ||
def schema(self): | ||
"""Get Schema.""" | ||
return self.obj | ||
|
||
|
||
class AnonCredsResolutionError(BaseAnonCredsError): | ||
"""Raised when resolving an AnonCreds object fails.""" | ||
|
||
|
||
class BaseAnonCredsHandler(ABC): | ||
"""Base Anon Creds Handler.""" | ||
|
||
@property | ||
@abstractmethod | ||
def supported_identifiers_regex(self) -> Pattern: | ||
"""Regex to match supported identifiers.""" | ||
|
||
async def supports(self, identifier: str) -> bool: | ||
"""Determine whether this registry supports the given identifier.""" | ||
return bool(self.supported_identifiers_regex.match(identifier)) | ||
|
||
@abstractmethod | ||
async def setup(self, context: InjectionContext): | ||
"""Class Setup method.""" | ||
|
||
|
||
class BaseAnonCredsResolver(BaseAnonCredsHandler): | ||
"""Base Anon Creds Resolver.""" | ||
|
||
@abstractmethod | ||
async def get_schema(self, profile: Profile, schema_id: str) -> GetSchemaResult: | ||
"""Get a schema from the registry.""" | ||
|
||
@abstractmethod | ||
async def get_credential_definition( | ||
self, profile: Profile, credential_definition_id: str | ||
) -> GetCredDefResult: | ||
"""Get a credential definition from the registry.""" | ||
|
||
@abstractmethod | ||
async def get_revocation_registry_definition( | ||
self, profile: Profile, revocation_registry_id: str | ||
) -> GetRevRegDefResult: | ||
"""Get a revocation registry definition from the registry.""" | ||
|
||
@abstractmethod | ||
async def get_revocation_list( | ||
self, profile: Profile, revocation_registry_id: str, timestamp: int | ||
) -> GetRevListResult: | ||
"""Get a revocation list from the registry.""" | ||
|
||
|
||
class BaseAnonCredsRegistrar(BaseAnonCredsHandler): | ||
"""Base Anon Creds Registrar.""" | ||
|
||
@abstractmethod | ||
async def register_schema( | ||
self, | ||
profile: Profile, | ||
schema: AnonCredsSchema, | ||
options: Optional[dict] = None, | ||
) -> SchemaResult: | ||
"""Register a schema on the registry.""" | ||
|
||
@abstractmethod | ||
async def register_credential_definition( | ||
self, | ||
profile: Profile, | ||
schema: GetSchemaResult, | ||
credential_definition: CredDef, | ||
options: Optional[dict] = None, | ||
) -> CredDefResult: | ||
"""Register a credential definition on the registry.""" | ||
|
||
@abstractmethod | ||
async def register_revocation_registry_definition( | ||
self, | ||
profile: Profile, | ||
revocation_registry_definition: RevRegDef, | ||
options: Optional[dict] = None, | ||
) -> RevRegDefResult: | ||
"""Register a revocation registry definition on the registry.""" | ||
|
||
@abstractmethod | ||
async def register_revocation_list( | ||
self, | ||
profile: Profile, | ||
rev_reg_def: RevRegDef, | ||
rev_list: RevList, | ||
options: Optional[dict] = None, | ||
) -> RevListResult: | ||
"""Register a revocation list on the registry.""" | ||
|
||
@abstractmethod | ||
async def update_revocation_list( | ||
self, | ||
profile: Profile, | ||
rev_reg_def: RevRegDef, | ||
prev_list: RevList, | ||
curr_list: RevList, | ||
revoked: Sequence[int], | ||
options: Optional[dict] = None, | ||
) -> RevListResult: | ||
"""Update a revocation list on the registry.""" |
Empty file.
Empty file.
119 changes: 119 additions & 0 deletions
119
aries_cloudagent/anoncreds/default/did_indy/registry.py
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,119 @@ | ||
"""DID Indy Registry.""" | ||
import logging | ||
import re | ||
from typing import Optional, Pattern, Sequence | ||
|
||
from ....config.injection_context import InjectionContext | ||
from ....core.profile import Profile | ||
from ...models.anoncreds_cred_def import ( | ||
CredDef, | ||
CredDefResult, | ||
GetCredDefResult, | ||
) | ||
from ...models.anoncreds_revocation import ( | ||
GetRevListResult, | ||
GetRevRegDefResult, | ||
RevRegDef, | ||
RevRegDefResult, | ||
RevList, | ||
RevListResult, | ||
) | ||
from ...models.anoncreds_schema import AnonCredsSchema, GetSchemaResult, SchemaResult | ||
from ...base import BaseAnonCredsRegistrar, BaseAnonCredsResolver | ||
|
||
LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
class DIDIndyRegistry(BaseAnonCredsResolver, BaseAnonCredsRegistrar): | ||
"""DIDIndyRegistry.""" | ||
|
||
def __init__(self): | ||
"""Initialize an instance. | ||
Args: | ||
TODO: update this docstring - Anoncreds-break. | ||
""" | ||
self._supported_identifiers_regex = re.compile(r"^did:indy:.*$") | ||
|
||
@property | ||
def supported_identifiers_regex(self) -> Pattern: | ||
"""Supported Identifiers regex.""" | ||
return self._supported_identifiers_regex | ||
# TODO: fix regex (too general) | ||
|
||
async def setup(self, context: InjectionContext): | ||
"""Setup.""" | ||
print("Successfully registered DIDIndyRegistry") | ||
|
||
async def get_schema(self, profile: Profile, schema_id: str) -> GetSchemaResult: | ||
"""Get a schema from the registry.""" | ||
raise NotImplementedError() | ||
|
||
async def register_schema( | ||
self, | ||
profile: Profile, | ||
schema: AnonCredsSchema, | ||
options: Optional[dict], | ||
) -> SchemaResult: | ||
"""Register a schema on the registry.""" | ||
raise NotImplementedError() | ||
|
||
async def get_credential_definition( | ||
self, profile: Profile, credential_definition_id: str | ||
) -> GetCredDefResult: | ||
"""Get a credential definition from the registry.""" | ||
raise NotImplementedError() | ||
|
||
async def register_credential_definition( | ||
self, | ||
profile: Profile, | ||
schema: GetSchemaResult, | ||
credential_definition: CredDef, | ||
options: Optional[dict] = None, | ||
) -> CredDefResult: | ||
"""Register a credential definition on the registry.""" | ||
raise NotImplementedError() | ||
|
||
async def get_revocation_registry_definition( | ||
self, profile: Profile, revocation_registry_id: str | ||
) -> GetRevRegDefResult: | ||
"""Get a revocation registry definition from the registry.""" | ||
raise NotImplementedError() | ||
|
||
async def register_revocation_registry_definition( | ||
self, | ||
profile: Profile, | ||
revocation_registry_definition: RevRegDef, | ||
options: Optional[dict] = None, | ||
) -> RevRegDefResult: | ||
"""Register a revocation registry definition on the registry.""" | ||
raise NotImplementedError() | ||
|
||
async def get_revocation_list( | ||
self, profile: Profile, revocation_registry_id: str, timestamp: int | ||
) -> GetRevListResult: | ||
"""Get a revocation list from the registry.""" | ||
raise NotImplementedError() | ||
|
||
async def register_revocation_list( | ||
self, | ||
profile: Profile, | ||
rev_reg_def: RevRegDef, | ||
rev_list: RevList, | ||
options: Optional[dict] = None, | ||
) -> RevListResult: | ||
"""Register a revocation list on the registry.""" | ||
raise NotImplementedError() | ||
|
||
async def update_revocation_list( | ||
self, | ||
profile: Profile, | ||
rev_reg_def: RevRegDef, | ||
prev_list: RevList, | ||
curr_list: RevList, | ||
revoked: Sequence[int], | ||
options: Optional[dict] = None, | ||
) -> RevListResult: | ||
"""Update a revocation list on the registry.""" | ||
raise NotImplementedError() |
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 @@ | ||
"""Routes for DID Indy Registry.""" |
Empty file.
Oops, something went wrong.