Skip to content

Commit

Permalink
feat(revocation): update revocation to track pending state
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Burdett <burdettadam@gmail.com>
  • Loading branch information
burdettadam committed May 31, 2023
1 parent ff62b91 commit 958cc7b
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
2 changes: 2 additions & 0 deletions aries_cloudagent/anoncreds/issuer.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
CATEGORY_CRED_DEF_PRIVATE = "credential_def_private"
CATEGORY_CRED_DEF_KEY_PROOF = "credential_def_key_proof"
STATE_FINISHED = "finished"
STATE_REVOCATION_POSTED = "posted"
STATE_REVOCATION_PENDING = "pending"

EVENT_PREFIX = "acapy::anoncreds::"
EVENT_SCHEMA = EVENT_PREFIX + CATEGORY_SCHEMA
Expand Down
57 changes: 57 additions & 0 deletions aries_cloudagent/anoncreds/revocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@
import base58
from requests import RequestException, Session


from ..askar.profile import AskarProfile, AskarProfileSession
from ..core.error import BaseError
from ..core.profile import Profile
from ..tails.base import BaseTailsServer
from .issuer import (
STATE_REVOCATION_PENDING,
STATE_REVOCATION_POSTED,
AnonCredsIssuer,
CATEGORY_CRED_DEF,
CATEGORY_CRED_DEF_PRIVATE,
Expand All @@ -47,6 +50,7 @@
CATEGORY_REV_REG_DEF = "revocation_reg_def"
CATEGORY_REV_REG_DEF_PRIVATE = "revocation_reg_def_private"
CATEGORY_REV_REG_ISSUER = "revocation_reg_def_issuer"
REV_REG_DEF_STATE_ACTIVE = "active"


class AnonCredsRevocationError(BaseError):
Expand Down Expand Up @@ -86,6 +90,29 @@ def profile(self) -> AskarProfile:

# Revocation artifact management

async def _update_rev_list_record(
self, txn: AskarProfileSession, state, rev_reg_def_id: str
):
entry = await txn.handle.fetch(
CATEGORY_REV_LIST,
rev_reg_def_id,
for_update=True,
)
if not entry:
raise AnonCredsRevocationError(
f"{CATEGORY_REV_LIST} with rev_reg_def_id "
f"{rev_reg_def_id} could not be found"
)

tags = entry.tags
tags["state"] = state
await txn.handle.insert(
CATEGORY_REV_LIST,
rev_reg_def_id,
value=entry.value,
tags=tags,
)

async def _finish_registration(
self, txn: AskarProfileSession, category: str, job_id: str, registered_id: str
):
Expand All @@ -109,6 +136,36 @@ async def _finish_registration(
)
await txn.handle.remove(category, job_id)

async def mark_pending_revocation(self, txn: AskarProfileSession, rev_reg_id):
await self._update_rev_list_record(txn, STATE_REVOCATION_PENDING, rev_reg_id)

async def clear_pending_revocation(self, txn: AskarProfileSession, rev_reg_id):
await self._update_rev_list_record(txn, STATE_REVOCATION_POSTED, rev_reg_id)

async def set_active_registry(
self, txn: AskarProfileSession, state, revoc_reg_id: str
):
entry = await txn.handle.fetch(
CATEGORY_REV_REG_DEF,
revoc_reg_id,
for_update=True,
)
if not entry:
raise AnonCredsRevocationError(
f"{CATEGORY_REV_REG_DEF} with revoc_reg_id "
f"{revoc_reg_id} could not be found"
)

tags = entry.tags
tags["state"] = REV_REG_DEF_STATE_ACTIVE
tags["active"] = True
await txn.handle.insert(
CATEGORY_REV_REG_DEF,
revoc_reg_id,
value=entry.value,
tags=tags,
)

async def create_and_register_revocation_registry_definition(
self,
issuer_id: str,
Expand Down
8 changes: 7 additions & 1 deletion aries_cloudagent/indy/credx/issuer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
Schema,
)

from aries_cloudagent.anoncreds.revocation import REV_REG_DEF_STATE_ACTIVE

from ...askar.profile import AskarProfile

from ..issuer import (
Expand Down Expand Up @@ -592,6 +594,7 @@ async def create_and_store_revocation_registry(

rev_reg_def_id = rev_reg_def.id
rev_reg_def_json = rev_reg_def.to_json()
rev_reg_def_json["state"] = REV_REG_DEF_STATE_ACTIVE
rev_reg_json = rev_reg.to_json()

try:
Expand All @@ -603,7 +606,10 @@ async def create_and_store_revocation_registry(
value_json={"curr_id": 0, "used_ids": []},
)
await txn.handle.insert(
CATEGORY_REV_REG_DEF, rev_reg_def_id, rev_reg_def_json
CATEGORY_REV_REG_DEF,
rev_reg_def_id,
rev_reg_def_json,
{"active": True},
)
await txn.handle.insert(
CATEGORY_REV_REG_DEF_PRIVATE,
Expand Down

0 comments on commit 958cc7b

Please sign in to comment.