Skip to content

Commit

Permalink
Notify revocation when written to ledger
Browse files Browse the repository at this point in the history
Signed-off-by: jamshale <[email protected]>
  • Loading branch information
jamshale committed Feb 23, 2024
1 parent e809cd8 commit 3739c3a
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 31 deletions.
7 changes: 7 additions & 0 deletions aries_cloudagent/anoncreds/default/legacy_indy/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
BaseAnonCredsRegistrar,
BaseAnonCredsResolver,
)
from ...events import RevListFinishedEvent
from ...issuer import AnonCredsIssuer, AnonCredsIssuerError
from ...models.anoncreds_cred_def import (
CredDef,
Expand Down Expand Up @@ -966,6 +967,11 @@ async def update_revocation_list(
)

if write_ledger:
await self.notify(
RevListFinishedEvent.with_payload(
curr_list.rev_reg_def_id, newly_revoked_indices
)
)
return RevListResult(
job_id=None,
revocation_list_state=RevListState(
Expand All @@ -983,6 +989,7 @@ async def update_revocation_list(
"context": {
"job_id": job_id,
"rev_reg_def_id": rev_reg_def_id,
"rev_list": curr_list.serialize(),
"options": {
"endorser_connection_id": endorser_connection_id,
"create_transaction_for_endorser": create_transaction,
Expand Down
8 changes: 5 additions & 3 deletions aries_cloudagent/anoncreds/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ def payload(self) -> RevRegDefFinishedPayload:
class RevListFinishedPayload(NamedTuple):
"""Payload of rev list finished event."""

rev_reg_def_id: str
rev_reg_id: str
revoked: list
options: dict


Expand All @@ -131,11 +132,12 @@ def __init__(self, payload: RevListFinishedPayload):
@classmethod
def with_payload(
cls,
rev_reg_def_id: str,
rev_reg_id: str,
revoked: list,
options: Optional[dict] = None,
):
"""With payload."""
payload = RevListFinishedPayload(rev_reg_def_id, options)
payload = RevListFinishedPayload(rev_reg_id, revoked, options)
return cls(payload)

@property
Expand Down
11 changes: 8 additions & 3 deletions aries_cloudagent/anoncreds/revocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,15 +494,17 @@ async def store_revocation_registry_list(self, result: RevListResult):

if result.revocation_list_state.state == STATE_FINISHED:
await self.notify(
RevListFinishedEvent.with_payload(rev_list.rev_reg_def_id)
RevListFinishedEvent.with_payload(rev_list.rev_reg_def_id, rev_list)
)

except AskarError as err:
raise AnonCredsRevocationError(
"Error saving new revocation registry"
) from err

async def finish_revocation_list(self, job_id: str, rev_reg_def_id: str):
async def finish_revocation_list(
self, job_id: str, rev_reg_def_id: str, revoked: list
):
"""Mark a revocation list as finished."""
async with self.profile.transaction() as txn:
# Finish the registration if the list is new, otherwise already updated
Expand All @@ -519,7 +521,10 @@ async def finish_revocation_list(self, job_id: str, rev_reg_def_id: str):
state=STATE_FINISHED,
)
await txn.commit()
await self.notify(RevListFinishedEvent.with_payload(rev_reg_def_id))
# Notify about revoked creds on any list update
await self.notify(
RevListFinishedEvent.with_payload(rev_reg_def_id, revoked)
)

async def update_revocation_list(
self,
Expand Down
5 changes: 4 additions & 1 deletion aries_cloudagent/anoncreds/revocation_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from ..anoncreds.revocation import AnonCredsRevocation
from ..core.event_bus import EventBus
from ..core.profile import Profile
from ..revocation.util import notify_revocation_published_event
from .events import (
CRED_DEF_FINISHED_PATTERN,
REV_LIST_FINISHED_PATTERN,
Expand Down Expand Up @@ -105,4 +106,6 @@ async def on_rev_reg_def(self, profile: Profile, event: RevRegDefFinishedEvent):

async def on_rev_list(self, profile: Profile, event: RevListFinishedEvent):
"""Handle rev list finished."""
LOGGER.debug("Revocation list finished: %s", event.payload.rev_reg_def_id)
await notify_revocation_published_event(
profile, event.payload.rev_reg_id, event.payload.revoked
)
Original file line number Diff line number Diff line change
Expand Up @@ -863,14 +863,17 @@ async def endorsed_txn_post_processing(
elif ledger_response["result"]["txn"]["type"] == "114":
# revocation entry transaction
rev_reg_id = ledger_response["result"]["txn"]["data"]["revocRegDefId"]
revoked = ledger_response["result"]["txn"]["data"]["value"].get(
"revoked", []
)
meta_data["context"]["rev_reg_id"] = rev_reg_id
if is_anoncreds:
await AnonCredsRevocation(self._profile).finish_revocation_list(
meta_data["context"]["job_id"], rev_reg_id
meta_data["context"]["job_id"], rev_reg_id, revoked
)
else:
await notify_revocation_entry_endorsed_event(
self._profile, rev_reg_id, meta_data
self._profile, rev_reg_id, meta_data, revoked
)

elif ledger_response["result"]["txn"]["type"] == "1":
Expand Down
6 changes: 0 additions & 6 deletions aries_cloudagent/revocation/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,6 @@ async def revoke_credential(
write_ledger=write_ledger,
endorser_did=endorser_did,
)
await notify_revocation_published_event(
self._profile, rev_reg_id, [cred_rev_id]
)
return rev_entry_resp
else:
async with self._profile.transaction() as txn:
Expand Down Expand Up @@ -299,9 +296,6 @@ async def publish_pending_revocations(
rev_entry_resp = await issuer_rr_upd.send_entry(self._profile)
published = sorted(crid for crid in crids if crid not in failed_crids)
result[issuer_rr_rec.revoc_reg_id] = published
await notify_revocation_published_event(
self._profile, issuer_rr_rec.revoc_reg_id, published
)

return rev_entry_resp, result

Expand Down
7 changes: 0 additions & 7 deletions aries_cloudagent/revocation/tests/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ async def test_revoke_credential_publish(self):
revoc.return_value.get_ledger_registry = mock.CoroutineMock(
return_value=mock_rev_reg
)
test_module.notify_revocation_published_event = mock.CoroutineMock()

await self.manager.revoke_credential_by_cred_ex_id(CRED_EX_ID, publish=True)

Expand All @@ -93,7 +92,6 @@ async def test_revoke_credential_publish(self):
mock_issuer_rev_reg_record.tails_local_path,
["2", "1"],
)
assert test_module.notify_revocation_published_event.called

async def test_revoke_credential_publish_endorser(self):
conn_record = ConnRecord(
Expand Down Expand Up @@ -168,7 +166,6 @@ async def test_revoke_credential_publish_endorser(self):
revoc.return_value.get_ledger_registry = mock.CoroutineMock(
return_value=mock_rev_reg
)
test_module.notify_revocation_published_event = mock.CoroutineMock()

await self.manager.revoke_credential_by_cred_ex_id(
cred_ex_id=CRED_EX_ID,
Expand All @@ -177,8 +174,6 @@ async def test_revoke_credential_publish_endorser(self):
write_ledger=False,
)

assert test_module.notify_revocation_published_event.called

issuer.revoke_credentials.assert_awaited_once_with(
mock_issuer_rev_reg_record.cred_def_id,
mock_issuer_rev_reg_record.revoc_reg_id,
Expand Down Expand Up @@ -385,15 +380,13 @@ async def test_publish_pending_revocations_endorser(self):
side_effect=[(json.dumps(delta), []) for delta in deltas]
)
self.profile.context.injector.bind_instance(IndyIssuer, issuer)
test_module.notify_revocation_published_event = mock.CoroutineMock()
manager = RevocationManager(self.profile)
_, result = await manager.publish_pending_revocations(
rrid2crid={REV_REG_ID: "2"}, connection_id=conn_id
)
assert result == {REV_REG_ID: ["2"]}
mock_issuer_rev_reg_records[0].clear_pending.assert_called_once()
mock_issuer_rev_reg_records[1].clear_pending.assert_not_called()
assert test_module.notify_revocation_published_event.called

async def test_publish_pending_revocations_endorser_x(self):
deltas = [
Expand Down
4 changes: 2 additions & 2 deletions aries_cloudagent/revocation/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from ..core.profile import Profile


REVOCATION_EVENT_PREFIX = "acapy::REVOCATION::"
EVENT_LISTENER_PATTERN = re.compile(f"^{REVOCATION_EVENT_PREFIX}(.*)?$")
REVOCATION_REG_INIT_EVENT = "REGISTRY_INIT"
Expand Down Expand Up @@ -52,11 +51,12 @@ async def notify_revocation_reg_endorsed_event(


async def notify_revocation_entry_endorsed_event(
profile: Profile, rev_reg_id: str, meta_data: dict
profile: Profile, rev_reg_id: str, meta_data: dict, revoked: list
):
"""Send notification for a revocation registry entry endorsement event."""
topic = f"{REVOCATION_EVENT_PREFIX}{REVOCATION_ENTRY_ENDORSED_EVENT}::{rev_reg_id}"
await profile.notify(topic, meta_data)
await notify_revocation_published_event(profile, rev_reg_id, revoked)


async def notify_revocation_published_event(
Expand Down
7 changes: 0 additions & 7 deletions aries_cloudagent/revocation_anoncreds/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
)
from ..revocation.util import (
notify_pending_cleared_event,
notify_revocation_published_event,
)
from ..storage.error import StorageNotFoundError
from .models.issuer_cred_rev_record import IssuerCredRevRecord
Expand Down Expand Up @@ -129,9 +128,6 @@ async def revoke_credential(
result.revoked,
options=options,
)
await notify_revocation_published_event(
self._profile, rev_reg_id, [cred_rev_id]
)

else:
await revoc.mark_pending_revocations(rev_reg_id, int(cred_rev_id))
Expand Down Expand Up @@ -237,9 +233,6 @@ async def publish_pending_revocations(
rrid, result.prev, result.curr, result.revoked, options
)
published_crids[rrid] = sorted(result.revoked)
await notify_revocation_published_event(
self._profile, rrid, [str(crid) for crid in result.revoked]
)

return published_crids

Expand Down

0 comments on commit 3739c3a

Please sign in to comment.