Skip to content

Commit 2f8db62

Browse files
committed
include _type and _version in AgentMessage
Signed-off-by: Shaanjot Gill <gill.shaanjots@gmail.com>
1 parent 006b8f6 commit 2f8db62

7 files changed

Lines changed: 28 additions & 34 deletions

File tree

aries_cloudagent/messaging/agent_message.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from collections import OrderedDict
66
from re import sub
7-
from typing import Mapping, Union
7+
from typing import Mapping, Optional, Union, Text
88

99
from marshmallow import (
1010
EXCLUDE,
@@ -55,7 +55,13 @@ class Meta:
5555
schema_class = None
5656
message_type = None
5757

58-
def __init__(self, _id: str = None, _decorators: BaseDecoratorSet = None):
58+
def __init__(
59+
self,
60+
_id: str = None,
61+
_type: Optional[Text] = None,
62+
_version: Optional[Text] = None,
63+
_decorators: BaseDecoratorSet = None,
64+
):
5965
"""
6066
Initialize base agent message object.
6167
@@ -83,7 +89,12 @@ def __init__(self, _id: str = None, _decorators: BaseDecoratorSet = None):
8389
self.__class__.__name__
8490
)
8591
)
86-
self._message_type = self.Meta.message_type
92+
if _type:
93+
self._message_type = _type
94+
elif _version:
95+
self._message_type = self.get_updated_msg_type(_version)
96+
else:
97+
self._message_type = self.Meta.message_type
8798
# Not required for now
8899
# if not self.Meta.handler_class:
89100
# raise TypeError(

aries_cloudagent/protocols/out_of_band/v1_0/manager.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ async def create_invitation(
108108
multi_use: set to True to create an invitation for multiple-use connection
109109
alias: optional alias to apply to connection for later use
110110
attachments: list of dicts in form of {"id": ..., "type": ...}
111-
service_accept: Optional list of mime types in the order of preference of the sender
112-
that the receiver can use in responding to the message
111+
service_accept: Optional list of mime types in the order of preference of
112+
the sender that the receiver can use in responding to the message
113113
protocol_version: OOB protocol version [1.0, 1.1]
114114
115115
Returns:
@@ -233,7 +233,7 @@ async def create_invitation(
233233
handshake_protocols=handshake_protocols,
234234
requests_attach=message_attachments,
235235
services=[f"did:sov:{public_did.did}"],
236-
service_accept=service_accept if protocol_version != "1.0" else None,
236+
accept=service_accept if protocol_version != "1.0" else None,
237237
version=protocol_version or DEFAULT_VERSION,
238238
)
239239

@@ -332,9 +332,7 @@ async def create_invitation(
332332
invi_msg.label = my_label or self.profile.settings.get("default_label")
333333
invi_msg.handshake_protocols = handshake_protocols
334334
invi_msg.requests_attach = message_attachments
335-
invi_msg.service_accept = (
336-
service_accept if protocol_version != "1.0" else None
337-
)
335+
invi_msg.accept = service_accept if protocol_version != "1.0" else None
338336
invi_msg.services = [
339337
ServiceMessage(
340338
_id="#inline",
@@ -429,7 +427,7 @@ async def receive_invitation(
429427
oob_service_item = invitation.services[0]
430428

431429
# service_accept
432-
service_accept = invitation.service_accept
430+
service_accept = invitation.accept
433431

434432
# Get the DID public did, if any
435433
public_did = None

aries_cloudagent/protocols/out_of_band/v1_0/messages/invitation.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def __init__(
123123
handshake_protocols: Sequence[Text] = None,
124124
requests_attach: Sequence[AttachDecorator] = None,
125125
services: Sequence[Union[Service, Text]] = None,
126-
service_accept: Optional[Sequence[Text]] = None,
126+
accept: Optional[Sequence[Text]] = None,
127127
version: str = DEFAULT_VERSION,
128128
msg_type: Optional[Text] = None,
129129
**kwargs,
@@ -136,18 +136,14 @@ def __init__(
136136
137137
"""
138138
# super().__init__(_id=_id, **kwargs)
139-
super().__init__(**kwargs)
139+
super().__init__(_type=msg_type, _version=version, **kwargs)
140140
self.label = label
141141
self.handshake_protocols = (
142142
list(handshake_protocols) if handshake_protocols else []
143143
)
144144
self.requests_attach = list(requests_attach) if requests_attach else []
145145
self.services = services
146-
if msg_type:
147-
self._type = msg_type
148-
else:
149-
self._type = self.get_updated_msg_type(version)
150-
self.service_accept = service_accept
146+
self.accept = accept
151147

152148
@classmethod
153149
def wrap_message(cls, message: dict) -> AttachDecorator:
@@ -222,7 +218,7 @@ class Meta:
222218
),
223219
required=False,
224220
)
225-
service_accept = fields.List(
221+
accept = fields.List(
226222
fields.Str(),
227223
example=["didcomm/aip1", "didcomm/aip2;env=rfc19"],
228224
description=("List of mime type in order of preference"),

aries_cloudagent/protocols/out_of_band/v1_0/messages/problem_report.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,7 @@ def __init__(
5050
**kwargs,
5151
):
5252
"""Initialize a ProblemReport message instance."""
53-
super().__init__(*args, **kwargs)
54-
if msg_type:
55-
self._type = msg_type
56-
else:
57-
self._type = self.get_updated_msg_type(version)
53+
super().__init__(_type=msg_type, _version=version, *args, **kwargs)
5854

5955

6056
class OOBProblemReportSchema(ProblemReportSchema):

aries_cloudagent/protocols/out_of_band/v1_0/messages/reuse.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,7 @@ def __init__(
2929
**kwargs,
3030
):
3131
"""Initialize Handshake Reuse message object."""
32-
super().__init__(**kwargs)
33-
if msg_type:
34-
self._type = msg_type
35-
else:
36-
self._type = self.get_updated_msg_type(version)
32+
super().__init__(_type=msg_type, _version=version, **kwargs)
3733

3834

3935
class HandshakeReuseSchema(AgentMessageSchema):

aries_cloudagent/protocols/out_of_band/v1_0/messages/reuse_accept.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,7 @@ def __init__(
3030
**kwargs,
3131
):
3232
"""Initialize Handshake Reuse Accept object."""
33-
super().__init__(**kwargs)
34-
if msg_type:
35-
self._type = msg_type
36-
else:
37-
self._type = self.get_updated_msg_type(version)
33+
super().__init__(_type=msg_type, _version=version, **kwargs)
3834

3935

4036
class HandshakeReuseAcceptSchema(AgentMessageSchema):

aries_cloudagent/resolver/default/indy.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ def add_services(
115115
service_endpoint=endpoint,
116116
recipient_keys=[recipient_key.id],
117117
routing_keys=routing_keys,
118-
# CHECKME accept=(service_accept if service_accept else ["didcomm/v2"]),
118+
# CHECKME
119+
# accept=(service_accept if service_accept else ["didcomm/v2"]),
119120
accept=["didcomm/v2"],
120121
)
121122
builder.context.append(self.CONTEXT_DIDCOMM_V2)

0 commit comments

Comments
 (0)