Skip to content

Commit

Permalink
Merge pull request openwallet-foundation#108 from Indicio-tech/featur…
Browse files Browse the repository at this point in the history
…e/anoncreds-plugin-structure

feat: add plugin structure
  • Loading branch information
dbluhm authored Mar 10, 2023
2 parents 9612213 + dc01703 commit 96d3fd0
Show file tree
Hide file tree
Showing 14 changed files with 445 additions and 0 deletions.
45 changes: 45 additions & 0 deletions aries_cloudagent/anoncreds/anoncreds/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import logging

from ...config.injection_context import InjectionContext
from ...config.provider import ClassProvider

from ..anoncreds.anoncreds_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.warning("No AnonCredsRegistry instance found in context")
return

indy_registry = ClassProvider(
"aries_cloudagent.anoncreds.anoncreds.default.did_indy_registry.registry"
".DIDIndyRegistry",
supported_identifiers=[],
method_name="did:indy",
).provide(context.settings, context.injector)
await indy_registry.setup(context)
registry.register_registry(indy_registry)

web_registry = ClassProvider(
"aries_cloudagent.anoncreds.anoncreds.default.did_web_registry.registry"
".DIDWebRegistry",
supported_identifiers=[],
method_name="did:web",
).provide(context.settings, context.injector)
await web_registry.setup(context)
registry.register_registry(web_registry)

legacy_indy_registry = ClassProvider(
"aries_cloudagent.anoncreds.anoncreds.default.legacy_indy_registry.registry"
".LegacyIndyRegistry",
supported_identifiers=[],
method_name="",
).provide(context.settings, context.injector)
await legacy_indy_registry.setup(context)
registry.register_registry(legacy_indy_registry)

# TODO: add context.settings
69 changes: 69 additions & 0 deletions aries_cloudagent/anoncreds/anoncreds/anoncreds_registry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
"""AnonCreds Registry"""
import logging
from typing import List

from .base_registry import BaseRegistry
from .models import (
AnonCredsRegistryGetCredentialDefinition,
AnonCredsRegistryGetRevocationList,
AnonCredsRegistryGetRevocationRegistryDefinition,
AnonCredsRegistryGetSchema,
)
from ...config.injection_context import InjectionContext


LOGGER = logging.getLogger(__name__)


class AnonCredsRegistry(BaseRegistry):
"""AnonCredsRegistry"""

def __init__(self, registries: List[BaseRegistry] = None):
"""Create DID Resolver."""
super().__init__(supported_identifiers=[], method_name="")
# TODO: need both supported_identifiers and method_name?
self.registries = registries or []

# TODO: use supported_identifier and method_name to select which registry should
# resolve or register a given object + identifier

def register_registry(self, registry: BaseRegistry):
"""Register a new registry."""
self.registries.append(registry)

async def setup(self, context: InjectionContext):
"""Setup method."""

async def get_schema(self, schema_id: str) -> AnonCredsRegistryGetSchema:
"""Get a schema from the registry."""

# TODO: determine keyword arguments
async def register_schema(self):
"""Register a schema on the registry."""

async def get_credential_definition(
self, credential_definition_id: str
) -> AnonCredsRegistryGetCredentialDefinition:
"""Get a credential definition from the registry."""

# TODO: determine keyword arguments
async def register_credential_definition(self):
"""Register a credential definition on the registry."""

async def get_revocation_registry_definition(
self, revocation_registry_id: str
) -> AnonCredsRegistryGetRevocationRegistryDefinition:
"""Get a revocation registry definition from the registry."""

# TODO: determine keyword arguments
async def register_revocation_registry_definition(self):
"""Register a revocation registry definition on the registry."""

async def get_revocation_list(
self, revocation_registry_id: str, timestamp: str
) -> AnonCredsRegistryGetRevocationList:
"""Get a revocation list from the registry."""

# TODO: determine keyword arguments
async def register_revocation_list(self):
"""Register a revocation list on the registry."""
64 changes: 64 additions & 0 deletions aries_cloudagent/anoncreds/anoncreds/base_registry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
"""Base Registry"""
from abc import ABC, abstractmethod
from typing import List
from ...config.injection_context import InjectionContext

from .models import (
AnonCredsRegistryGetCredentialDefinition,
AnonCredsRegistryGetRevocationList,
AnonCredsRegistryGetRevocationRegistryDefinition,
AnonCredsRegistryGetSchema,
)


class BaseRegistry(ABC):
"""BaseRegistry"""

def __init__(self, supported_identifiers: List[str], method_name: str):
"""Initialize Base Registry."""

@abstractmethod
async def setup(self, context: InjectionContext):
"""Setup method."""

@abstractmethod
async def get_schema(self, schema_id: str) -> AnonCredsRegistryGetSchema:
"""Get a schema from the registry."""

# TODO: determine keyword arguments
@abstractmethod
async def register_schema(self):
"""Register a schema on the registry."""

@abstractmethod
async def get_credential_definition(
self, credential_definition_id: str
) -> AnonCredsRegistryGetCredentialDefinition:
"""Get a credential definition from the registry."""

# TODO: determine keyword arguments
@abstractmethod
async def register_credential_definition(self):
"""Register a credential definition on the registry."""

@abstractmethod
async def get_revocation_registry_definition(
self, revocation_registry_id: str
) -> AnonCredsRegistryGetRevocationRegistryDefinition:
"""Get a revocation registry definition from the registry."""

# TODO: determine keyword arguments
@abstractmethod
async def register_revocation_registry_definition(self):
"""Register a revocation registry definition on the registry."""

@abstractmethod
async def get_revocation_list(
self, revocation_registry_id: str, timestamp: str
) -> AnonCredsRegistryGetRevocationList:
"""Get a revocation list from the registry."""

# TODO: determine keyword arguments
@abstractmethod
async def register_revocation_list(self):
"""Register a revocation list on the registry."""
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"""DID Indy Registry"""
from ...models import (
AnonCredsRegistryGetCredentialDefinition,
AnonCredsRegistryGetRevocationList,
AnonCredsRegistryGetRevocationRegistryDefinition,
AnonCredsRegistryGetSchema,
)
from .....config.injection_context import InjectionContext
from ...anoncreds_registry import BaseRegistry


class DIDIndyRegistry(BaseRegistry):
"""DIDIndyRegistry"""

async def setup(self, context: InjectionContext):
"""Setup."""
print("Successfully registered DIDIndyRegistry")

async def get_schema(self, schema_id: str) -> AnonCredsRegistryGetSchema:
"""Get a schema from the registry."""

# TODO: determine keyword arguments
async def register_schema(self):
"""Register a schema on the registry."""

async def get_credential_definition(
self, credential_definition_id: str
) -> AnonCredsRegistryGetCredentialDefinition:
"""Get a credential definition from the registry."""

# TODO: determine keyword arguments
async def register_credential_definition(self):
"""Register a credential definition on the registry."""

async def get_revocation_registry_definition(
self, revocation_registry_id: str
) -> AnonCredsRegistryGetRevocationRegistryDefinition:
"""Get a revocation registry definition from the registry."""

# TODO: determine keyword arguments
async def register_revocation_registry_definition(self):
"""Register a revocation registry definition on the registry."""

async def get_revocation_list(
self, revocation_registry_id: str, timestamp: str
) -> AnonCredsRegistryGetRevocationList:
"""Get a revocation list from the registry."""

# TODO: determine keyword arguments
async def register_revocation_list(self):
"""Register a revocation list on the registry."""
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Routes for DID Indy Registry"""
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"""DID Web Registry"""
from ...models import (
AnonCredsRegistryGetCredentialDefinition,
AnonCredsRegistryGetRevocationList,
AnonCredsRegistryGetRevocationRegistryDefinition,
AnonCredsRegistryGetSchema,
)
from .....config.injection_context import InjectionContext
from ...anoncreds_registry import BaseRegistry


class DIDWebRegistry(BaseRegistry):
"""DIDWebRegistry"""

async def setup(self, context: InjectionContext):
"""Setup."""
print("Successfully registered DIDWebRegistry")

async def get_schema(self, schema_id: str) -> AnonCredsRegistryGetSchema:
"""Get a schema from the registry."""

# TODO: determine keyword arguments
async def register_schema(self):
"""Register a schema on the registry."""

async def get_credential_definition(
self, credential_definition_id: str
) -> AnonCredsRegistryGetCredentialDefinition:
"""Get a credential definition from the registry."""

# TODO: determine keyword arguments
async def register_credential_definition(self):
"""Register a credential definition on the registry."""

async def get_revocation_registry_definition(
self, revocation_registry_id: str
) -> AnonCredsRegistryGetRevocationRegistryDefinition:
"""Get a revocation registry definition from the registry."""

# TODO: determine keyword arguments
async def register_revocation_registry_definition(self):
"""Register a revocation registry definition on the registry."""

async def get_revocation_list(
self, revocation_registry_id: str, timestamp: str
) -> AnonCredsRegistryGetRevocationList:
"""Get a revocation list from the registry."""

# TODO: determine keyword arguments
async def register_revocation_list(self):
"""Register a revocation list on the registry."""
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Routes for DID Web Registry"""
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"""Legacy Indy Registry"""
from ...models import (
AnonCredsRegistryGetCredentialDefinition,
AnonCredsRegistryGetRevocationList,
AnonCredsRegistryGetRevocationRegistryDefinition,
AnonCredsRegistryGetSchema,
)
from .....config.injection_context import InjectionContext
from ...anoncreds_registry import BaseRegistry


class LegacyIndyRegistry(BaseRegistry):
"""LegacyIndyRegistry"""

async def setup(self, context: InjectionContext):
"""Setup."""
print("Successfully registered LegacyIndyRegistry")

async def get_schema(self, schema_id: str) -> AnonCredsRegistryGetSchema:
"""Get a schema from the registry."""

# TODO: determine keyword arguments
async def register_schema(self):
"""Register a schema on the registry."""

async def get_credential_definition(
self, credential_definition_id: str
) -> AnonCredsRegistryGetCredentialDefinition:
"""Get a credential definition from the registry."""

# TODO: determine keyword arguments
async def register_credential_definition(self):
"""Register a credential definition on the registry."""

async def get_revocation_registry_definition(
self, revocation_registry_id: str
) -> AnonCredsRegistryGetRevocationRegistryDefinition:
"""Get a revocation registry definition from the registry."""

# TODO: determine keyword arguments
async def register_revocation_registry_definition(self):
"""Register a revocation registry definition on the registry."""

async def get_revocation_list(
self, revocation_registry_id: str, timestamp: str
) -> AnonCredsRegistryGetRevocationList:
"""Get a revocation list from the registry."""

# TODO: determine keyword arguments
async def register_revocation_list(self):
"""Register a revocation list on the registry."""
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Routes for Legacy Indy Registry"""
Loading

0 comments on commit 96d3fd0

Please sign in to comment.