Skip to content

Commit

Permalink
Merge branch 'main' into multi_ledger_write
Browse files Browse the repository at this point in the history
  • Loading branch information
dbluhm authored Aug 2, 2023
2 parents 4805259 + ad702a1 commit 071a969
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 35 deletions.
6 changes: 4 additions & 2 deletions aries_cloudagent/messaging/responder.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import json

from abc import ABC, abstractmethod
from typing import Sequence, Union, Optional, Tuple
from typing import List, Sequence, Union, Optional, Tuple

from ..cache.base import BaseCache
from ..connections.models.connection_target import ConnectionTarget
Expand Down Expand Up @@ -208,7 +208,9 @@ class MockResponder(BaseResponder):

def __init__(self):
"""Initialize the mock responder."""
self.messages = []
self.messages: List[
Tuple[Union[BaseMessage, str, bytes, OutboundMessage], Optional[dict]]
] = []

async def send(
self, message: Union[BaseMessage, str, bytes], **kwargs
Expand Down
61 changes: 38 additions & 23 deletions aries_cloudagent/protocols/didexchange/v1_0/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ async def create_request_implicit(
mediation_id=mediation_id,
goal_code=goal_code,
goal=goal,
use_public_did=bool(my_public_info),
)
conn_rec.request_id = request._id
conn_rec.state = ConnRecord.State.REQUEST.rfc23
Expand All @@ -245,11 +246,12 @@ async def create_request_implicit(
async def create_request(
self,
conn_rec: ConnRecord,
my_label: str = None,
my_endpoint: str = None,
mediation_id: str = None,
goal_code: str = None,
goal: str = None,
my_label: Optional[str] = None,
my_endpoint: Optional[str] = None,
mediation_id: Optional[str] = None,
goal_code: Optional[str] = None,
goal: Optional[str] = None,
use_public_did: bool = False,
) -> DIDXRequest:
"""
Create a new connection request for a previously-received invitation.
Expand All @@ -262,6 +264,8 @@ async def create_request(
service endpoint
goal_code: Optional self-attested code for sharing intent of connection
goal: Optional self-attested string for sharing intent of connection
use_public_did: Flag whether to use public DID and omit DID Doc
attachment on request
Returns:
A new `DIDXRequest` message to send to the other agent
Expand Down Expand Up @@ -296,12 +300,7 @@ async def create_request(
method=SOV,
key_type=ED25519,
)
conn_rec.my_did = my_info.did

# Idempotent; if routing has already been set up, no action taken
await self._route_manager.route_connection_as_invitee(
self.profile, conn_rec, mediation_record
)
conn_rec.my_did = my_info.did

# Create connection request message
if my_endpoint:
Expand All @@ -313,25 +312,36 @@ async def create_request(
my_endpoints.append(default_endpoint)
my_endpoints.extend(self.profile.settings.get("additional_endpoints", []))

did_doc = await self.create_did_document(
my_info,
conn_rec.inbound_connection_id,
my_endpoints,
mediation_records=list(
filter(None, [base_mediation_record, mediation_record])
),
)
if use_public_did:
# Omit DID Doc attachment if we're using a public DID
did_doc = None
attach = None
else:
did_doc = await self.create_did_document(
my_info,
conn_rec.inbound_connection_id,
my_endpoints,
mediation_records=list(
filter(None, [base_mediation_record, mediation_record])
),
)
attach = AttachDecorator.data_base64(did_doc.serialize())
async with self.profile.session() as session:
wallet = session.inject(BaseWallet)
await attach.data.sign(my_info.verkey, wallet)

if conn_rec.their_public_did is not None:
qualified_did = conn_rec.their_public_did
did_document = await self.get_resolved_did_document(qualified_did)
did_url = await self.get_first_applicable_didcomm_service(did_document)
else:
did_url = None

pthid = conn_rec.invitation_msg_id or did_url
attach = AttachDecorator.data_base64(did_doc.serialize())
async with self.profile.session() as session:
wallet = session.inject(BaseWallet)
await attach.data.sign(my_info.verkey, wallet)

if not my_label:
my_label = self.profile.settings.get("default_label")

request = DIDXRequest(
label=my_label,
did=conn_rec.my_did,
Expand All @@ -347,6 +357,11 @@ async def create_request(
async with self.profile.session() as session:
await conn_rec.save(session, reason="Created connection request")

# Idempotent; if routing has already been set up, no action taken
await self._route_manager.route_connection_as_invitee(
self.profile, conn_rec, mediation_record
)

return request

async def receive_request(
Expand Down
11 changes: 6 additions & 5 deletions aries_cloudagent/protocols/didexchange/v1_0/messages/request.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Represents a DID exchange request message under RFC 23."""

from typing import Optional
from marshmallow import EXCLUDE, fields

from .....messaging.agent_message import AgentMessage, AgentMessageSchema
Expand Down Expand Up @@ -27,11 +28,11 @@ class Meta:
def __init__(
self,
*,
label: str = None,
did: str = None,
did_doc_attach: AttachDecorator = None,
goal_code: str = None,
goal: str = None,
label: Optional[str] = None,
did: Optional[str] = None,
did_doc_attach: Optional[AttachDecorator] = None,
goal_code: Optional[str] = None,
goal: Optional[str] = None,
**kwargs,
):
"""
Expand Down
22 changes: 22 additions & 0 deletions aries_cloudagent/protocols/didexchange/v1_0/tests/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,10 @@ async def test_create_request_implicit_use_public_did(self):
)

assert info_public.did == conn_rec.my_did
assert self.responder.messages
request, kwargs = self.responder.messages[0]
assert isinstance(request, test_module.DIDXRequest)
assert request.did_doc_attach is None

async def test_create_request_implicit_no_public_did(self):
with self.assertRaises(WalletError) as context:
Expand Down Expand Up @@ -471,6 +475,24 @@ async def test_create_request_my_endpoint(self):
)
assert didx_req

async def test_create_request_public_did(self):
mock_conn_rec = async_mock.MagicMock(
connection_id="dummy",
my_did=self.did_info.did,
their_did=TestConfig.test_target_did,
their_role=ConnRecord.Role.RESPONDER.rfc23,
state=ConnRecord.State.REQUEST.rfc23,
retrieve_invitation=async_mock.CoroutineMock(
return_value=async_mock.MagicMock(
services=[TestConfig.test_target_did],
)
),
save=async_mock.CoroutineMock(),
)

request = await self.manager.create_request(mock_conn_rec, use_public_did=True)
assert request.did_doc_attach is None

async def test_receive_request_explicit_public_did(self):
async with self.profile.session() as session:
mock_request = async_mock.MagicMock(
Expand Down
2 changes: 1 addition & 1 deletion aries_cloudagent/revocation/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,7 @@ async def send_rev_reg_def(request: web.BaseRequest):
raise web.HTTPBadRequest(reason=err.roll_up) from err

if not create_transaction_for_endorser:
return web.json_response({"result": rev_reg.serialize()})
return web.json_response({"sent": rev_reg.serialize()})

else:
transaction_mgr = TransactionManager(profile)
Expand Down
2 changes: 1 addition & 1 deletion aries_cloudagent/revocation/tests/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ async def test_send_rev_reg_def(self):
)

result = await test_module.send_rev_reg_def(self.request)
mock_json_response.assert_called_once_with({"result": "dummy"})
mock_json_response.assert_called_once_with({"sent": "dummy"})
assert result is mock_json_response.return_value

async def test_send_rev_reg_def_not_found(self):
Expand Down
6 changes: 3 additions & 3 deletions aries_cloudagent/wallet/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import json
import logging
from typing import List
from typing import List, Optional, Tuple

from aiohttp import web
from aiohttp_apispec import docs, querystring_schema, request_schema, response_schema
Expand Down Expand Up @@ -187,7 +187,7 @@ class DIDListQueryStringSchema(OpenAPISchema):
class DIDQueryStringSchema(OpenAPISchema):
"""Parameters and validators for set public DID request query string."""

did = fields.Str(description="DID of interest", required=True, **INDY_DID)
did = fields.Str(description="DID of interest", required=True, **GENERIC_DID)


class DIDCreateOptionsSchema(OpenAPISchema):
Expand Down Expand Up @@ -601,7 +601,7 @@ async def promote_wallet_public_did(
connection_id: str = None,
routing_keys: List[str] = None,
mediator_endpoint: str = None,
) -> DIDInfo:
) -> Tuple[DIDInfo, Optional[dict]]:
"""Promote supplied DID to the wallet public DID."""
info: DIDInfo = None
endorser_did = None
Expand Down

0 comments on commit 071a969

Please sign in to comment.