Skip to content

Commit

Permalink
refactor: split rev methods from issuer
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Bluhm <dbluhm@pm.me>
  • Loading branch information
dbluhm committed May 29, 2023
1 parent 8a699bc commit aa87a45
Show file tree
Hide file tree
Showing 9 changed files with 975 additions and 835 deletions.
26 changes: 15 additions & 11 deletions aries_cloudagent/anoncreds/holder.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from ..anoncreds.models.anoncreds_schema import AnonCredsSchema
from ..askar.profile import AskarProfile
from ..core.error import BaseError
from ..core.profile import Profile
from ..ledger.base import BaseLedger
from ..wallet.error import WalletNotFoundError
from .models.anoncreds_cred_def import CredDef
Expand Down Expand Up @@ -57,7 +58,7 @@ class AnonCredsHolder:

MASTER_SECRET_ID = "default"

def __init__(self, profile: AskarProfile):
def __init__(self, profile: Profile):
"""
Initialize an AnonCredsHolder instance.
Expand All @@ -68,15 +69,18 @@ def __init__(self, profile: AskarProfile):
self._profile = profile

@property
def profile(self):
def profile(self) -> AskarProfile:
"""Accessor for the profile instance."""
if not isinstance(self._profile, AskarProfile):
raise ValueError("AnonCreds interface requires Askar")

return self._profile

async def get_master_secret(self) -> str:
"""Get or create the default master secret."""

while True:
async with self._profile.session() as session:
async with self.profile.session() as session:
try:
record = await session.handle.fetch(
CATEGORY_MASTER_SECRET, AnonCredsHolder.MASTER_SECRET_ID
Expand Down Expand Up @@ -237,7 +241,7 @@ async def store_credential(
mime_types[k] = credential_attr_mime_types[k]

try:
async with self._profile.transaction() as txn:
async with self.profile.transaction() as txn:
await txn.handle.insert(
CATEGORY_CREDENTIAL,
credential_id,
Expand Down Expand Up @@ -270,12 +274,12 @@ async def get_credentials(self, start: int, count: int, wql: dict):
result = []

try:
rows = self._profile.store.scan(
rows = self.profile.store.scan(
CATEGORY_CREDENTIAL,
wql,
start,
count,
self._profile.settings.get("wallet.askar_profile"),
self.profile.settings.get("wallet.askar_profile"),
)
async for row in rows:
cred = Credential.load(row.raw_value)
Expand Down Expand Up @@ -344,12 +348,12 @@ async def get_credentials_for_presentation_request_by_referent(
if extra_query:
tag_filter = {"$and": [tag_filter, extra_query]}

rows = self._profile.store.scan(
rows = self.profile.store.scan(
CATEGORY_CREDENTIAL,
tag_filter,
start,
count,
self._profile.settings.get("wallet.askar_profile"),
self.profile.settings.get("wallet.askar_profile"),
)
async for row in rows:
if row.name in creds:
Expand Down Expand Up @@ -383,7 +387,7 @@ async def get_credential(self, credential_id: str) -> str:
async def _get_credential(self, credential_id: str) -> Credential:
"""Get an unencoded Credential instance from the store."""
try:
async with self._profile.session() as session:
async with self.profile.session() as session:
cred = await session.handle.fetch(CATEGORY_CREDENTIAL, credential_id)
except AskarError as err:
raise AnonCredsHolderError("Error retrieving credential") from err
Expand Down Expand Up @@ -431,7 +435,7 @@ async def delete_credential(self, credential_id: str):
"""
try:
async with self._profile.session() as session:
async with self.profile.session() as session:
await session.handle.remove(CATEGORY_CREDENTIAL, credential_id)
await session.handle.remove(
AnonCredsHolder.RECORD_TYPE_MIME_TYPES, credential_id
Expand All @@ -457,7 +461,7 @@ async def get_mime_type(
"""
try:
async with self._profile.session() as session:
async with self.profile.session() as session:
mime_types_record = await session.handle.fetch(
AnonCredsHolder.RECORD_TYPE_MIME_TYPES,
credential_id,
Expand Down
Loading

0 comments on commit aa87a45

Please sign in to comment.