Skip to content

Commit

Permalink
refactor: move rev list register logic from IssuerRevRegRecord to Ano…
Browse files Browse the repository at this point in the history
…nCredsIssuer

Signed-off-by: Char Howland <char@indicio.tech>
  • Loading branch information
cjhowland committed May 18, 2023
1 parent 0eb5ac4 commit b1ef34d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
36 changes: 31 additions & 5 deletions aries_cloudagent/anoncreds/issuer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
Schema,
)
from aries_askar import AskarError
from aries_cloudagent.revocation.error import RevocationError
from aries_cloudagent.revocation.models.issuer_rev_reg_record import IssuerRevRegRecord

from ..askar.profile import AskarProfile, AskarProfileSession
from ..core.error import BaseError
Expand Down Expand Up @@ -682,13 +684,28 @@ async def get_created_revocation_registry_definitions(
return [entry.name for entry in rev_reg_defs]

async def create_and_register_revocation_list(
self, rev_reg_def_id: str, options: Optional[dict] = None
self, rev_reg_record: IssuerRevRegRecord, options: Optional[dict] = None
):
"""Create and register a revocation list."""

if not (
rev_reg_record.revoc_reg_id
and rev_reg_record.revoc_def_type
and rev_reg_record.issuer_id
):
raise RevocationError("Revocation registry undefined")

if rev_reg_record.state not in (IssuerRevRegRecord.STATE_POSTED,):
raise RevocationError(
"Revocation registry {} in state {}: cannot publish entry".format(
rev_reg_record.revoc_reg_id, rev_reg_record.state
)
)

try:
async with self._profile.session() as session:
rev_reg_def_entry = await session.handle.fetch(
CATEGORY_REV_REG_DEF, rev_reg_def_id
CATEGORY_REV_REG_DEF, rev_reg_record.revoc_reg_id
)
except AskarError as err:
raise AnonCredsIssuerError(
Expand All @@ -697,13 +714,13 @@ async def create_and_register_revocation_list(

if not rev_reg_def_entry:
raise AnonCredsIssuerError(
f"Revocation registry definition not found for id {rev_reg_def_id}"
f"Revocation registry definition not found for id {rev_reg_record.revoc_reg_id}"
)

rev_reg_def = RevRegDef.deserialize(rev_reg_def_entry.value_json)

rev_list = RevocationStatusList.create(
rev_reg_def_id,
rev_reg_record.revoc_reg_id,
rev_reg_def_entry.raw_value,
rev_reg_def.issuer_id,
)
Expand All @@ -717,12 +734,21 @@ async def create_and_register_revocation_list(
async with self._profile.session() as session:
await session.handle.insert(
CATEGORY_REV_LIST,
rev_reg_def_id,
rev_reg_record.revoc_reg_id,
result.revocation_list_state.revocation_list.to_json(),
)
except AskarError as err:
raise AnonCredsIssuerError("Error saving new revocation registry") from err

if rev_reg_record.state == IssuerRevRegRecord.STATE_POSTED:
rev_reg_record.state = (
IssuerRevRegRecord.STATE_ACTIVE
) # registering rev status list activates
async with self._profile.session() as session:
await rev_reg_record.save(
session, reason="Published initial revocation registry entry"
)

return result

async def create_credential_offer(self, credential_definition_id: str) -> str:
Expand Down
7 changes: 4 additions & 3 deletions aries_cloudagent/anoncreds/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,9 +424,10 @@ async def rev_list_post(request: web.BaseRequest):

try:
revoc = AnonCredsRevocation(context.profile)
rev_reg = await revoc.get_issuer_rev_reg_record(rev_reg_def_id)
result = await rev_reg.create_and_register_list(
context.profile,
rev_reg_record = await revoc.get_issuer_rev_reg_record(rev_reg_def_id)
issuer = AnonCredsIssuer(context.profile)
result = await issuer.create_and_register_revocation_list(
rev_reg_record,
options,
)
LOGGER.debug("published revocation list for: %s", rev_reg_def_id)
Expand Down

0 comments on commit b1ef34d

Please sign in to comment.