Skip to content

Commit

Permalink
refactor: remove connection protocol
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Bluhm <[email protected]>
  • Loading branch information
dbluhm committed Aug 19, 2024
1 parent 277e958 commit 69daceb
Show file tree
Hide file tree
Showing 54 changed files with 321 additions and 5,862 deletions.
23 changes: 0 additions & 23 deletions aries_cloudagent/config/argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,15 +279,6 @@ def add_arguments(self, parser: ArgumentParser):
"invitation URL. Default: false."
),
)
parser.add_argument(
"--connections-invite",
action="store_true",
env_var="ACAPY_CONNECTIONS_INVITE",
help=(
"After startup, generate and print a new connections protocol "
"style invitation URL. Default: false."
),
)
parser.add_argument(
"--invite-label",
dest="invite_label",
Expand Down Expand Up @@ -429,8 +420,6 @@ def get_settings(self, args: Namespace) -> dict:
settings["debug.seed"] = args.debug_seed
if args.invite:
settings["debug.print_invitation"] = True
if args.connections_invite:
settings["debug.print_connections_invitation"] = True
if args.invite_label:
settings["debug.invite_label"] = args.invite_label
if args.invite_multi_use:
Expand Down Expand Up @@ -1451,24 +1440,12 @@ def add_arguments(self, parser: ArgumentParser):
"and send mediation request and set as default mediator."
),
)
parser.add_argument(
"--mediator-connections-invite",
action="store_true",
env_var="ACAPY_MEDIATION_CONNECTIONS_INVITE",
help=(
"Connect to mediator through a connection invitation. "
"If not specified, connect using an OOB invitation. "
"Default: false."
),
)

def get_settings(self, args: Namespace):
"""Extract mediation invitation settings."""
settings = {}
if args.mediator_invitation:
settings["mediation.invite"] = args.mediator_invitation
if args.mediator_connections_invite:
settings["mediation.connections_invite"] = True

return settings

Expand Down
56 changes: 18 additions & 38 deletions aries_cloudagent/connections/base_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@
from ..core.profile import Profile
from ..did.did_key import DIDKey
from ..multitenant.base import BaseMultitenantManager
from ..protocols.connections.v1_0.message_types import ARIES_PROTOCOL as CONN_PROTO
from ..protocols.connections.v1_0.messages.connection_invitation import (
ConnectionInvitation,
)
from ..protocols.didexchange.v1_0.message_types import ARIES_PROTOCOL as CONN_PROTO
from ..protocols.coordinate_mediation.v1_0.models.mediation_record import (
MediationRecord,
)
Expand Down Expand Up @@ -615,7 +612,7 @@ def _extract_key_material_in_base58_format(method: VerificationMethod) -> str:
async def _fetch_connection_targets_for_invitation(
self,
connection: ConnRecord,
invitation: Union[ConnectionInvitation, InvitationMessage],
invitation: InvitationMessage,
sender_verkey: str,
) -> Sequence[ConnectionTarget]:
"""Get a list of connection targets for an invitation.
Expand All @@ -625,48 +622,31 @@ async def _fetch_connection_targets_for_invitation(
Args:
connection (ConnRecord): The connection record associated with the invitation.
invitation (Union[ConnectionInvitation, InvitationMessage]): The connection
invitation (InvitationMessage): The connection
or OOB invitation retrieved from the connection record.
sender_verkey (str): The sender's verification key.
Returns:
Sequence[ConnectionTarget]: A list of `ConnectionTarget` objects
representing the connection targets for the invitation.
"""
if isinstance(invitation, ConnectionInvitation):
# conn protocol invitation
if invitation.did:
did = invitation.did
(
endpoint,
recipient_keys,
routing_keys,
) = await self.resolve_invitation(did)
# out-of-band invitation
oob_service_item = invitation.services[0]
if isinstance(oob_service_item, str):
(
endpoint,
recipient_keys,
routing_keys,
) = await self.resolve_invitation(oob_service_item)

else:
endpoint = invitation.endpoint
recipient_keys = invitation.recipient_keys
routing_keys = invitation.routing_keys
else:
# out-of-band invitation
oob_service_item = invitation.services[0]
if isinstance(oob_service_item, str):
(
endpoint,
recipient_keys,
routing_keys,
) = await self.resolve_invitation(oob_service_item)

else:
endpoint = oob_service_item.service_endpoint
recipient_keys = [
DIDKey.from_did(k).public_key_b58
for k in oob_service_item.recipient_keys
]
routing_keys = [
DIDKey.from_did(k).public_key_b58
for k in oob_service_item.routing_keys
]
endpoint = oob_service_item.service_endpoint
recipient_keys = [
DIDKey.from_did(k).public_key_b58 for k in oob_service_item.recipient_keys
]
routing_keys = [
DIDKey.from_did(k).public_key_b58 for k in oob_service_item.routing_keys
]

return [
ConnectionTarget(
Expand Down
36 changes: 8 additions & 28 deletions aries_cloudagent/connections/models/conn_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,6 @@
INDY_RAW_PUBLIC_KEY_VALIDATE,
UUID4_EXAMPLE,
)
from ...protocols.connections.v1_0.message_types import ARIES_PROTOCOL as CONN_PROTO
from ...protocols.connections.v1_0.message_types import (
CONNECTION_INVITATION,
CONNECTION_REQUEST,
)
from ...protocols.connections.v1_0.messages.connection_invitation import (
ConnectionInvitation,
)
from ...protocols.connections.v1_0.messages.connection_request import ConnectionRequest
from ...protocols.didcomm_prefix import DIDCommPrefix
from ...protocols.didexchange.v1_0.message_types import ARIES_PROTOCOL as DIDEX_1_1
from ...protocols.didexchange.v1_0.message_types import DIDEX_1_0
from ...protocols.didexchange.v1_0.messages.request import DIDXRequest
Expand All @@ -44,7 +34,7 @@ class Meta:

schema_class = "MaybeStoredConnRecordSchema"

SUPPORTED_PROTOCOLS = (CONN_PROTO, DIDEX_1_0, DIDEX_1_1)
SUPPORTED_PROTOCOLS = ("connections/1.0", DIDEX_1_0, DIDEX_1_1)

class Role(Enum):
"""RFC 160 (inviter, invitee) = RFC 23 (responder, requester)."""
Expand Down Expand Up @@ -424,7 +414,7 @@ async def retrieve_by_alias(cls, session: ProfileSession, alias: str) -> "ConnRe
async def attach_invitation(
self,
session: ProfileSession,
invitation: Union[ConnectionInvitation, OOBInvitation],
invitation: OOBInvitation,
):
"""Persist the related connection invitation to storage.
Expand All @@ -441,9 +431,7 @@ async def attach_invitation(
storage = session.inject(BaseStorage)
await storage.add_record(record)

async def retrieve_invitation(
self, session: ProfileSession
) -> Union[ConnectionInvitation, OOBInvitation]:
async def retrieve_invitation(self, session: ProfileSession) -> OOBInvitation:
"""Retrieve the related connection invitation.
Args:
Expand All @@ -456,16 +444,12 @@ async def retrieve_invitation(
{"connection_id": self.connection_id},
)
ser = json.loads(result.value)
return (
ConnectionInvitation
if DIDCommPrefix.unqualify(ser["@type"]) == CONNECTION_INVITATION
else OOBInvitation
).deserialize(ser)
return OOBInvitation.deserialize(ser)

async def attach_request(
self,
session: ProfileSession,
request: Union[ConnectionRequest, DIDXRequest],
request: DIDXRequest,
):
"""Persist the related connection request to storage.
Expand All @@ -485,7 +469,7 @@ async def attach_request(
async def retrieve_request(
self,
session: ProfileSession,
) -> Union[ConnectionRequest, DIDXRequest]:
) -> DIDXRequest:
"""Retrieve the related connection invitation.
Args:
Expand All @@ -497,11 +481,7 @@ async def retrieve_request(
self.RECORD_TYPE_REQUEST, {"connection_id": self.connection_id}
)
ser = json.loads(result.value)
return (
ConnectionRequest
if DIDCommPrefix.unqualify(ser["@type"]) == CONNECTION_REQUEST
else DIDXRequest
).deserialize(ser)
return DIDXRequest.deserialize(ser)

@property
def is_ready(self) -> str:
Expand Down Expand Up @@ -703,7 +683,7 @@ class Meta:
validate=validate.OneOf(ConnRecord.SUPPORTED_PROTOCOLS),
metadata={
"description": "Connection protocol used",
"example": "connections/1.0",
"example": "didexchange/1.1",
},
)
rfc23_state = fields.Str(
Expand Down
37 changes: 20 additions & 17 deletions aries_cloudagent/connections/models/tests/test_conn_record.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from unittest import IsolatedAsyncioTestCase

from ....core.in_memory import InMemoryProfile
from ....protocols.connections.v1_0.messages.connection_invitation import (
ConnectionInvitation,
from aries_cloudagent.protocols.didexchange.v1_0.messages.request import DIDXRequest
from aries_cloudagent.protocols.out_of_band.v1_0.messages.invitation import (
InvitationMessage,
)
from ....protocols.connections.v1_0.messages.connection_request import ConnectionRequest
from ....protocols.connections.v1_0.models.connection_detail import ConnectionDetail
from aries_cloudagent.protocols.out_of_band.v1_0.messages.service import Service

from ....core.in_memory import InMemoryProfile
from ....storage.base import BaseStorage
from ....storage.error import StorageNotFoundError
from ..conn_record import ConnRecord
from ..diddoc.diddoc import DIDDoc


class TestConnRecord(IsolatedAsyncioTestCase):
Expand Down Expand Up @@ -354,14 +354,17 @@ async def test_attach_retrieve_invitation(self):
)
connection_id = await record.save(self.session)

invi = ConnectionInvitation(
label="abc123",
service = Service(
recipient_keys=[self.test_verkey],
endpoint="http://localhost:8999",
service_endpoint="http://localhost:8999",
)
invi = InvitationMessage(
services=[service],
label="abc123",
)
await record.attach_invitation(self.session, invi)
retrieved = await record.retrieve_invitation(self.session)
assert isinstance(retrieved, ConnectionInvitation)
assert isinstance(retrieved, InvitationMessage)

async def test_attach_retrieve_request(self):
record = ConnRecord(
Expand All @@ -370,13 +373,13 @@ async def test_attach_retrieve_request(self):
)
connection_id = await record.save(self.session)

req = ConnectionRequest(
connection=ConnectionDetail(did=self.test_did, did_doc=DIDDoc(self.test_did)),
req = DIDXRequest(
did=self.test_did,
label="abc123",
)
await record.attach_request(self.session, req)
retrieved = await record.retrieve_request(self.session)
assert isinstance(retrieved, ConnectionRequest)
assert isinstance(retrieved, DIDXRequest)

async def test_attach_request_abstain_on_alien_deco(self):
record = ConnRecord(
Expand All @@ -385,19 +388,19 @@ async def test_attach_request_abstain_on_alien_deco(self):
)
connection_id = await record.save(self.session)

req = ConnectionRequest(
connection=ConnectionDetail(did=self.test_did, did_doc=DIDDoc(self.test_did)),
req = DIDXRequest(
did=self.test_did,
label="abc123",
)
ser = req.serialize()
ser["~alien"] = [{"nickname": "profile-image", "data": {"links": ["face.png"]}}]
alien_req = ConnectionRequest.deserialize(ser)
alien_req = DIDXRequest.deserialize(ser)
await record.attach_request(self.session, alien_req)
alien_ser = alien_req.serialize()
assert "~alien" in alien_ser

ser["~alien"] = None
alien_req = ConnectionRequest.deserialize(ser)
alien_req = DIDXRequest.deserialize(ser)
await record.attach_request(self.session, alien_req)
alien_ser = alien_req.serialize()
assert "~alien" not in alien_ser
Expand Down
Loading

0 comments on commit 69daceb

Please sign in to comment.