Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: additional tweaks for did:web and other methods as public DIDs #2392

Merged
merged 5 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
49 changes: 32 additions & 17 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 @@ -313,25 +317,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 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
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