Skip to content

Commit 00e53d9

Browse files
committed
tmp
1 parent aa3e7cd commit 00e53d9

24 files changed

Lines changed: 862 additions & 40 deletions

aries_cloudagent/protocols/revocation_notification/v1_0/models/rev_notification_record.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def __init__(
4747
comment: str = None,
4848
version: str = None,
4949
unrevoke: Optional[bool] = None,
50+
revocation_format: str = None,
5051
**kwargs,
5152
):
5253
"""Construct record."""
@@ -58,6 +59,7 @@ def __init__(
5859
self.comment = comment
5960
self.version = version
6061
self.unrevoke = unrevoke
62+
self.revocation_format = revocation_format
6163

6264
@property
6365
def revocation_notification_id(self) -> Optional[str]:

aries_cloudagent/protocols/revocation_notification/v2_0/handlers/revoke_handler.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
"""Handler for revoke message."""
22

3-
from aries_cloudagent.protocols.didcomm_prefix import DIDCommPrefix
4-
53
from .....messaging.base_handler import BaseHandler
64
from .....messaging.request_context import RequestContext
75
from .....messaging.responder import BaseResponder
6+
87
from ..messages.revoke import Revoke
9-
from ..messages.unrevoke import Unrevoke
108

119

1210
class RevokeHandler(BaseHandler):
@@ -17,22 +15,18 @@ class RevokeHandler(BaseHandler):
1715

1816
async def handle(self, context: RequestContext, responder: BaseResponder):
1917
"""Handle revoke message."""
20-
assert isinstance(context.message, (Revoke, Unrevoke))
18+
assert isinstance(context.message, Revoke)
2119
self._logger.debug(
2220
"Received notification of revocation for %s cred %s with comment: %s",
2321
context.message.revocation_format,
2422
context.message.credential_id,
2523
context.message.comment,
2624
)
27-
28-
message_type = f"{DIDCommPrefix.NEW}/{context.message.Meta.message_type}"
29-
3025
# Emit a webhook
3126
if context.settings.get("revocation.monitor_notification"):
3227
await context.profile.notify(
3328
self.WEBHOOK_TOPIC,
3429
{
35-
"@type": message_type,
3630
"revocation_format": context.message.revocation_format,
3731
"credential_id": context.message.credential_id,
3832
"comment": context.message.comment,
@@ -43,7 +37,6 @@ async def handle(self, context: RequestContext, responder: BaseResponder):
4337
await context.profile.notify(
4438
self.RECEIVED_TOPIC,
4539
{
46-
"@type": message_type,
4740
"revocation_format": context.message.revocation_format,
4841
"credential_id": context.message.credential_id,
4942
"comment": context.message.comment,

aries_cloudagent/protocols/revocation_notification/v2_0/message_types.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from ...didcomm_prefix import DIDCommPrefix
44

5+
56
SPEC_URI = (
67
"https://github.com/hyperledger/aries-rfcs/blob/main/features/"
78
"0721-revocation-notification-v2/README.md"
@@ -12,12 +13,8 @@
1213

1314
# Message types
1415
REVOKE = f"{BASE}/revoke"
15-
UNREVOKE = f"{BASE}/unrevoke"
1616

1717
PROTOCOL_PACKAGE = "aries_cloudagent.protocols.revocation_notification.v2_0"
1818
MESSAGE_TYPES = DIDCommPrefix.qualify_all(
19-
{
20-
REVOKE: f"{PROTOCOL_PACKAGE}.messages.revoke.Revoke",
21-
UNREVOKE: f"{PROTOCOL_PACKAGE}.messages.unrevoke.Unrevoke",
22-
}
19+
{REVOKE: f"{PROTOCOL_PACKAGE}.messages.revoke.Revoke"}
2320
)

aries_cloudagent/protocols/revocation_notification/v2_0/models/rev_notification_record.py

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55
from marshmallow import fields
66
from marshmallow.utils import EXCLUDE
77

8-
from aries_cloudagent.protocols.revocation_notification.v2_0.messages.unrevoke import (
9-
Unrevoke,
10-
)
11-
128
from .....core.profile import ProfileSession
139
from .....messaging.models.base_record import BaseRecord, BaseRecordSchema
1410
from .....messaging.valid import (
@@ -50,7 +46,7 @@ def __init__(
5046
thread_id: str = None,
5147
comment: str = None,
5248
version: str = None,
53-
unrevoke: bool = None,
49+
revocation_format: str = "indy-anoncreds",
5450
**kwargs,
5551
):
5652
"""Construct record."""
@@ -61,7 +57,7 @@ def __init__(
6157
self.thread_id = thread_id
6258
self.comment = comment
6359
self.version = version
64-
self.unrevoke = unrevoke
60+
self.revocation_format = revocation_format
6561

6662
@property
6763
def revocation_notification_id(self) -> Optional[str]:
@@ -71,9 +67,7 @@ def revocation_notification_id(self) -> Optional[str]:
7167
@property
7268
def record_value(self) -> dict:
7369
"""Return record value."""
74-
return {
75-
prop: getattr(self, prop) for prop in ("thread_id", "comment", "unrevoke")
76-
}
70+
return {prop: getattr(self, prop) for prop in ("thread_id", "comment")}
7771

7872
@classmethod
7973
async def query_by_ids(
@@ -132,18 +126,11 @@ def to_message(self):
132126
"No thread ID set on revocation notification record, "
133127
"cannot create message"
134128
)
135-
if self.unrevoke:
136-
return Unrevoke(
137-
revocation_format="indy-anoncreds",
138-
credential_id=f"{self.rev_reg_id}::{self.cred_rev_id}",
139-
comment=self.comment,
140-
)
141-
else:
142-
return Revoke(
143-
revocation_format="indy-anoncreds",
144-
credential_id=f"{self.rev_reg_id}::{self.cred_rev_id}",
145-
comment=self.comment,
146-
)
129+
return Revoke(
130+
revocation_format=self.revocation_format,
131+
credential_id=f"{self.rev_reg_id}::{self.cred_rev_id}",
132+
comment=self.comment,
133+
)
147134

148135

149136
class RevNotificationRecordSchema(BaseRecordSchema):
@@ -201,7 +188,3 @@ class Meta:
201188
required=False,
202189
metadata={"description": "Version of Revocation Notification to send out"},
203190
)
204-
unrevoke = fields.Bool(
205-
required=False,
206-
metadata={"description": "If it is Unrevoked"},
207-
)

aries_cloudagent/protocols/revocation_notification/v2_1/__init__.py

Whitespace-only changes.

aries_cloudagent/protocols/revocation_notification/v2_1/handlers/__init__.py

Whitespace-only changes.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
"""Handler for revoke message."""
2+
3+
from aries_cloudagent.protocols.didcomm_prefix import DIDCommPrefix
4+
5+
from .....messaging.base_handler import BaseHandler
6+
from .....messaging.request_context import RequestContext
7+
from .....messaging.responder import BaseResponder
8+
from ..messages.revoke import Revoke
9+
from ..messages.unrevoke import Unrevoke
10+
11+
12+
class RevokeHandler(BaseHandler):
13+
"""Handler for revoke message."""
14+
15+
RECEIVED_TOPIC = "acapy::revocation-notification-v2::received"
16+
WEBHOOK_TOPIC = "acapy::webhook::revocation-notification-v2"
17+
18+
async def handle(self, context: RequestContext, responder: BaseResponder):
19+
"""Handle revoke message."""
20+
assert isinstance(context.message, (Revoke, Unrevoke))
21+
self._logger.debug(
22+
"Received notification of revocation for %s cred %s with comment: %s",
23+
context.message.revocation_format,
24+
context.message.credential_id,
25+
context.message.comment,
26+
)
27+
28+
message_type = f"{DIDCommPrefix.NEW}/{context.message.Meta.message_type}"
29+
30+
# Emit a webhook
31+
if context.settings.get("revocation.monitor_notification"):
32+
await context.profile.notify(
33+
self.WEBHOOK_TOPIC,
34+
{
35+
"@type": message_type,
36+
"revocation_format": context.message.revocation_format,
37+
"credential_id": context.message.credential_id,
38+
"comment": context.message.comment,
39+
},
40+
)
41+
42+
# Emit an event
43+
await context.profile.notify(
44+
self.RECEIVED_TOPIC,
45+
{
46+
"@type": message_type,
47+
"revocation_format": context.message.revocation_format,
48+
"credential_id": context.message.credential_id,
49+
"comment": context.message.comment,
50+
},
51+
)

aries_cloudagent/protocols/revocation_notification/v2_1/handlers/tests/__init__.py

Whitespace-only changes.
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
"""Test RevokeHandler."""
2+
3+
import pytest
4+
5+
from ......core.event_bus import EventBus, MockEventBus
6+
from ......core.in_memory import InMemoryProfile
7+
from ......core.profile import Profile
8+
from ......messaging.request_context import RequestContext
9+
from ......messaging.responder import MockResponder, BaseResponder
10+
from ...messages.revoke import Revoke
11+
from ..revoke_handler import RevokeHandler
12+
13+
14+
@pytest.fixture
15+
def event_bus():
16+
yield MockEventBus()
17+
18+
19+
@pytest.fixture
20+
def responder():
21+
yield MockResponder()
22+
23+
24+
@pytest.fixture
25+
def profile(event_bus):
26+
yield InMemoryProfile.test_profile(bind={EventBus: event_bus})
27+
28+
29+
@pytest.fixture
30+
def message():
31+
yield Revoke(
32+
revocation_format="indy-anoncreds",
33+
credential_id="mock_cred_revocation_id",
34+
comment="mock_comment",
35+
)
36+
37+
38+
@pytest.fixture
39+
def context(profile: Profile, message: Revoke):
40+
request_context = RequestContext(profile)
41+
request_context.message = message
42+
yield request_context
43+
44+
45+
@pytest.mark.asyncio
46+
async def test_handle(
47+
context: RequestContext, responder: BaseResponder, event_bus: MockEventBus
48+
):
49+
await RevokeHandler().handle(context, responder)
50+
assert event_bus.events
51+
[(_, received)] = event_bus.events
52+
assert received.topic == RevokeHandler.RECEIVED_TOPIC
53+
assert "revocation_format" in received.payload
54+
assert "credential_id" in received.payload
55+
assert "comment" in received.payload
56+
57+
58+
@pytest.mark.asyncio
59+
async def test_handle_monitor(
60+
context: RequestContext, responder: BaseResponder, event_bus: MockEventBus
61+
):
62+
context.settings["revocation.monitor_notification"] = True
63+
await RevokeHandler().handle(context, responder)
64+
[(_, webhook), (_, received)] = event_bus.events
65+
66+
assert webhook.topic == RevokeHandler.WEBHOOK_TOPIC
67+
assert "revocation_format" in received.payload
68+
assert "credential_id" in received.payload
69+
assert "comment" in webhook.payload
70+
71+
assert received.topic == RevokeHandler.RECEIVED_TOPIC
72+
assert "revocation_format" in received.payload
73+
assert "credential_id" in received.payload
74+
assert "comment" in received.payload
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""Message type identifiers for Revocation Notification protocol."""
2+
3+
from ...didcomm_prefix import DIDCommPrefix
4+
5+
SPEC_URI = (
6+
"https://github.com/hyperledger/aries-rfcs/blob/main/features/"
7+
"0721-revocation-notification-v2/README.md"
8+
)
9+
PROTOCOL = "revocation_notification"
10+
VERSION = "2.0"
11+
BASE = f"{PROTOCOL}/{VERSION}"
12+
13+
# Message types
14+
REVOKE = f"{BASE}/revoke"
15+
UNREVOKE = f"{BASE}/unrevoke"
16+
17+
PROTOCOL_PACKAGE = "aries_cloudagent.protocols.revocation_notification.v2_0"
18+
MESSAGE_TYPES = DIDCommPrefix.qualify_all(
19+
{
20+
REVOKE: f"{PROTOCOL_PACKAGE}.messages.revoke.Revoke",
21+
UNREVOKE: f"{PROTOCOL_PACKAGE}.messages.unrevoke.Unrevoke",
22+
}
23+
)

0 commit comments

Comments
 (0)