diff --git a/acapy_agent/anoncreds/base.py b/acapy_agent/anoncreds/base.py index bdd7bf8c2d..36e6f816c1 100644 --- a/acapy_agent/anoncreds/base.py +++ b/acapy_agent/anoncreds/base.py @@ -135,10 +135,6 @@ async def get_revocation_list( async def get_schema_info_by_id(self, schema_id: str) -> AnoncredsSchemaInfo: """Get a schema info from the registry.""" - @abstractmethod - async def get_cred_def_info_by_id(self, schema_id: str) -> AnoncredsSchemaInfo: - """Get a cred def info from the registry.""" - class BaseAnonCredsRegistrar(BaseAnonCredsHandler): """Base Anoncreds Registrar.""" diff --git a/acapy_agent/anoncreds/default/did_indy/registry.py b/acapy_agent/anoncreds/default/did_indy/registry.py index 916cdcb571..51784d6f53 100644 --- a/acapy_agent/anoncreds/default/did_indy/registry.py +++ b/acapy_agent/anoncreds/default/did_indy/registry.py @@ -7,7 +7,6 @@ from ....config.injection_context import InjectionContext from ....core.profile import Profile from ...base import BaseAnonCredsRegistrar, BaseAnonCredsResolver -from ...models.cred_def_info import AnoncredsCredDefInfo from ...models.credential_definition import CredDef, CredDefResult, GetCredDefResult from ...models.revocation import ( GetRevListResult, @@ -124,7 +123,3 @@ async def update_revocation_list( async def get_schema_info_by_id(self, schema_id: str) -> AnoncredsSchemaInfo: """Get a schema info from the registry.""" return await super().get_schema_info_by_id(schema_id) - - async def get_cred_def_info_by_id(self, cred_def_id: str) -> AnoncredsCredDefInfo: - """Get cred def info by cred def id.""" - return await super().get_cred_def_info_by_id(cred_def_id) diff --git a/acapy_agent/anoncreds/default/did_web/registry.py b/acapy_agent/anoncreds/default/did_web/registry.py index 00d3b928db..88d2216358 100644 --- a/acapy_agent/anoncreds/default/did_web/registry.py +++ b/acapy_agent/anoncreds/default/did_web/registry.py @@ -6,7 +6,6 @@ from ....config.injection_context import InjectionContext from ....core.profile import Profile from ...base import BaseAnonCredsRegistrar, BaseAnonCredsResolver -from ...models.cred_def_info import AnoncredsCredDefInfo from ...models.credential_definition import CredDef, CredDefResult, GetCredDefResult from ...models.revocation import ( GetRevListResult, @@ -119,7 +118,3 @@ async def update_revocation_list( async def get_schema_info_by_id(self, schema_id: str) -> AnoncredsSchemaInfo: """Get a schema info from the registry.""" return await super().get_schema_info_by_id(schema_id) - - async def get_cred_def_info_by_id(self, cred_def_id: str) -> AnoncredsCredDefInfo: - """Get cred def info by cred def id.""" - return await super().get_cred_def_info_by_id(cred_def_id) diff --git a/acapy_agent/anoncreds/default/legacy_indy/registry.py b/acapy_agent/anoncreds/default/legacy_indy/registry.py index dc33339fa7..b4ed1a2f8f 100644 --- a/acapy_agent/anoncreds/default/legacy_indy/registry.py +++ b/acapy_agent/anoncreds/default/legacy_indy/registry.py @@ -56,7 +56,6 @@ ) from ...events import RevListFinishedEvent from ...issuer import CATEGORY_CRED_DEF, AnonCredsIssuer, AnonCredsIssuerError -from ...models.cred_def_info import AnoncredsCredDefInfo from ...models.credential_definition import ( CredDef, CredDefResult, @@ -1240,9 +1239,3 @@ async def get_schema_info_by_id(self, schema_id: str) -> AnoncredsSchemaInfo: name=schema_id_parts.group(2), version=schema_id_parts.group(3), ) - - async def get_cred_def_info_by_id(self, cred_def_id: str) -> AnoncredsCredDefInfo: - """Get cred def info by cred def id.""" - return AnoncredsCredDefInfo( - issuer_id=cred_def_id.split(":")[-5], - ) diff --git a/acapy_agent/anoncreds/models/cred_def_info.py b/acapy_agent/anoncreds/models/cred_def_info.py deleted file mode 100644 index f7a9b2360b..0000000000 --- a/acapy_agent/anoncreds/models/cred_def_info.py +++ /dev/null @@ -1,9 +0,0 @@ -"""This class represents cred def information for anoncreds.""" - - -class AnoncredsCredDefInfo: - """Represents the credential definition information for anonymous credentials.""" - - def __init__(self, issuer_id: str): - """Initialize the cred def information.""" - self.issuer_id = issuer_id diff --git a/acapy_agent/protocols/present_proof/v2_0/formats/anoncreds/handler.py b/acapy_agent/protocols/present_proof/v2_0/formats/anoncreds/handler.py index 59b1e38178..dbf854892e 100644 --- a/acapy_agent/protocols/present_proof/v2_0/formats/anoncreds/handler.py +++ b/acapy_agent/protocols/present_proof/v2_0/formats/anoncreds/handler.py @@ -199,13 +199,16 @@ async def _check_proof_vs_proposal(): sub_proof_index = attr_spec["sub_proof_index"] schema_id = proof["identifiers"][sub_proof_index]["schema_id"] cred_def_id = proof["identifiers"][sub_proof_index]["cred_def_id"] + registry = self.profile.inject(AnonCredsRegistry) + schema = await registry.get_schema(self.profile, schema_id) + cred_def = await registry.get_credential_definition(cred_def_id) criteria = { "schema_id": schema_id, - "schema_issuer_did": schema_id.split(":")[-4], - "schema_name": schema_id.split(":")[-2], - "schema_version": schema_id.split(":")[-1], + "schema_issuer_did": schema.schema_value.issuer_id, + "schema_name": schema.schema_value.name, + "schema_version": schema.schema_value.version, "cred_def_id": cred_def_id, - "issuer_did": cred_def_id.split(":")[-5], + "issuer_did": cred_def.credential_definition.issuer_id, f"attr::{name}::value": proof_value, } @@ -232,18 +235,18 @@ async def _check_proof_vs_proposal(): name: values["raw"] for name, values in attr_spec["values"].items() } sub_proof_index = attr_spec["sub_proof_index"] - registry = self.profile.inject(AnonCredsRegistry) schema_id = proof["identifiers"][sub_proof_index]["schema_id"] - schema_info = await registry.get_schema_info_by_id(schema_id) cred_def_id = proof["identifiers"][sub_proof_index]["cred_def_id"] - cred_def_info = await registry.get_cred_def_info_by_id(cred_def_id) + registry = self.profile.inject(AnonCredsRegistry) + schema = await registry.get_schema(self.profile, schema_id) + cred_def = await registry.get_credential_definition(cred_def_id) criteria = { "schema_id": schema_id, - "schema_issuer_did": schema_info.issuer_id, - "schema_name": schema_info.name, - "schema_version": schema_info.version, + "schema_issuer_did": schema.schema_value.issuer_id, + "schema_name": schema.schema_value.name, + "schema_version": schema.schema_value.version, "cred_def_id": cred_def_id, - "issuer_did": cred_def_info.issuer_id, + "issuer_did": cred_def.credential_definition.issuer_id, **{ f"attr::{name}::value": value for name, value in proof_values.items() @@ -296,18 +299,19 @@ async def _check_proof_vs_proposal(): f"Proposed request predicate on {req_name} not in presentation" ) - registry = self.profile.inject(AnonCredsRegistry) + sub_proof_index = attr_spec["sub_proof_index"] schema_id = proof["identifiers"][sub_proof_index]["schema_id"] - schema_info = await registry.get_schema_info_by_id(schema_id) cred_def_id = proof["identifiers"][sub_proof_index]["cred_def_id"] - cred_def_info = await registry.get_cred_def_info_by_id(cred_def_id) + registry = self.profile.inject(AnonCredsRegistry) + schema = await registry.get_schema(self.profile, schema_id) + cred_def = await registry.get_credential_definition(cred_def_id) criteria = { "schema_id": schema_id, - "schema_issuer_did": schema_info.issuer_id, - "schema_name": schema_info.name, - "schema_version": schema_info.version, + "schema_issuer_did": schema.schema_value.issuer_id, + "schema_name": schema.schema_value.name, + "schema_version": schema.schema_value.version, "cred_def_id": cred_def_id, - "issuer_did": cred_def_info.issuer_id, + "issuer_did": cred_def.credential_definition.issuer_id, } if ( diff --git a/acapy_agent/protocols/present_proof/v2_0/tests/test_manager_anoncreds.py b/acapy_agent/protocols/present_proof/v2_0/tests/test_manager_anoncreds.py index c0f135ef07..6692bde6de 100644 --- a/acapy_agent/protocols/present_proof/v2_0/tests/test_manager_anoncreds.py +++ b/acapy_agent/protocols/present_proof/v2_0/tests/test_manager_anoncreds.py @@ -6,7 +6,13 @@ import pytest from .....anoncreds.holder import AnonCredsHolder -from .....anoncreds.models.cred_def_info import AnoncredsCredDefInfo +from .....anoncreds.models.credential_definition import ( + CredDef, + CredDefValue, + CredDefValuePrimary, + GetCredDefResult, +) +from .....anoncreds.models.schema import AnonCredsSchema, GetSchemaResult from .....anoncreds.registry import AnonCredsRegistry from .....anoncreds.verifier import AnonCredsVerifier from .....indy.models.pres_preview import ( @@ -472,8 +478,34 @@ async def asyncSetUp(self): ) injector.bind_instance(AnonCredsHolder, self.holder) registry = mock.MagicMock(AnonCredsRegistry, autospec=True) - registry.get_cred_def_info_by_id = mock.CoroutineMock( - return_value=AnoncredsCredDefInfo(issuer_id=ISSUER_DID) + registry.get_schema = mock.CoroutineMock( + return_value=GetSchemaResult( + schema=AnonCredsSchema( + issuer_id=ISSUER_DID, + name="vidya", + version="1.0", + attr_names=["player", "screenCapture", "highScore"], + ), + schema_id=S_ID, + resolution_metadata={}, + schema_metadata={}, + ) + ) + registry.get_credential_definition = mock.CoroutineMock( + return_value=GetCredDefResult( + credential_definition_id="TUku9MDGa7QALbAJX4oAww:3:CL:531757:MYCO_Consent_Enablement", + credential_definition=CredDef( + issuer_id=ISSUER_DID, + schema_id=S_ID, + tag="tag", + type="CL", + value=CredDefValue( + primary=CredDefValuePrimary("n", "s", {}, "rctxt", "z") + ), + ), + credential_definition_metadata={}, + resolution_metadata={}, + ) ) injector.bind_instance(AnonCredsRegistry, registry)