Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch verifier away from get_info methods in handler
Browse files Browse the repository at this point in the history
Signed-off-by: jamshale <[email protected]>
jamshale committed Dec 18, 2024
1 parent 5dfa089 commit 3581b01
Showing 7 changed files with 57 additions and 51 deletions.
4 changes: 0 additions & 4 deletions acapy_agent/anoncreds/base.py
Original file line number Diff line number Diff line change
@@ -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."""
5 changes: 0 additions & 5 deletions acapy_agent/anoncreds/default/did_indy/registry.py
Original file line number Diff line number Diff line change
@@ -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)
5 changes: 0 additions & 5 deletions acapy_agent/anoncreds/default/did_web/registry.py
Original file line number Diff line number Diff line change
@@ -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)
7 changes: 0 additions & 7 deletions acapy_agent/anoncreds/default/legacy_indy/registry.py
Original file line number Diff line number Diff line change
@@ -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],
)
9 changes: 0 additions & 9 deletions acapy_agent/anoncreds/models/cred_def_info.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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 (
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 3581b01

Please sign in to comment.