Skip to content

Commit

Permalink
Merge pull request #2862 from dbluhm/refactor/use-did
Browse files Browse the repository at this point in the history
refactor: introduce use_did and use_did_method
  • Loading branch information
swcurran authored Apr 8, 2024
2 parents 7d75760 + 27ed8f3 commit a9e0cf7
Show file tree
Hide file tree
Showing 31 changed files with 906 additions and 557 deletions.
18 changes: 0 additions & 18 deletions aries_cloudagent/config/argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -1166,19 +1166,6 @@ def add_arguments(self, parser: ArgumentParser):
"using unencrypted rather than encrypted tags"
),
)
parser.add_argument(
"--emit-did-peer-2",
action="store_true",
env_var="ACAPY_EMIT_DID_PEER_2",
help=("Emit did:peer:2 DIDs in DID Exchange Protocol"),
)

parser.add_argument(
"--emit-did-peer-4",
action="store_true",
env_var="ACAPY_EMIT_DID_PEER_4",
help=("Emit did:peer:4 DIDs in DID Exchange Protocol"),
)

def get_settings(self, args: Namespace) -> dict:
"""Get protocol settings."""
Expand Down Expand Up @@ -1246,11 +1233,6 @@ def get_settings(self, args: Namespace) -> dict:
settings["exch_use_unencrypted_tags"] = True
environ["EXCH_UNENCRYPTED_TAGS"] = "True"

if args.emit_did_peer_2:
settings["emit_did_peer_2"] = True
if args.emit_did_peer_4:
settings["emit_did_peer_4"] = True

return settings


Expand Down
9 changes: 5 additions & 4 deletions aries_cloudagent/connections/base_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
from ..wallet.base import BaseWallet
from ..wallet.crypto import create_keypair, seed_to_did
from ..wallet.did_info import INVITATION_REUSE_KEY, DIDInfo, KeyInfo
from ..wallet.did_method import PEER2, PEER4, SOV
from ..wallet.did_method import PEER2, PEER4, SOV, DIDMethod
from ..wallet.error import WalletNotFoundError
from ..wallet.key_type import ED25519
from ..wallet.util import b64_to_bytes, bytes_to_b58
Expand Down Expand Up @@ -245,19 +245,20 @@ async def create_did_peer_2(

async def fetch_invitation_reuse_did(
self,
did_method: str,
) -> DIDDoc:
did_method: DIDMethod,
) -> Optional[DIDInfo]:
"""Fetch a DID from the wallet to use across multiple invitations.
Args:
did_method: The DID method used (e.g. PEER2 or PEER4)
Returns:
The `DIDDoc` instance, or "None" if no DID is found
The `DIDInfo` instance, or "None" if no DID is found
"""
did_info = None
async with self._profile.session() as session:
wallet = session.inject(BaseWallet)
# TODO Iterating through all DIDs is problematic
did_list = await wallet.get_local_dids()
for did in did_list:
if did.method == did_method and INVITATION_REUSE_KEY in did.metadata:
Expand Down
2 changes: 2 additions & 0 deletions aries_cloudagent/core/tests/test_conductor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,8 @@ async def test_print_invite_connection(self):
"debug.print_connections_invitation": True,
"invite_base_url": "http://localhost",
"wallet.type": "askar",
"default_endpoint": "http://localhost",
"default_label": "test",
}
)
conductor = test_module.Conductor(builder)
Expand Down
3 changes: 1 addition & 2 deletions aries_cloudagent/messaging/agent_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ def assign_thread_from(self, msg: "AgentMessage"):
pthid = thread and thread.pthid
self.assign_thread_id(thid, pthid)

def assign_thread_id(self, thid: str, pthid: Optional[str] = None):
def assign_thread_id(self, thid: Optional[str] = None, pthid: Optional[str] = None):
"""Assign a specific thread ID.
Args:
Expand Down Expand Up @@ -450,7 +450,6 @@ class Meta:
# Avoid clobbering keywords
_type = fields.Str(
data_key="@type",
dump_only=True,
required=False,
metadata={
"description": "Message type",
Expand Down
8 changes: 4 additions & 4 deletions aries_cloudagent/messaging/tests/test_agent_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,12 @@ class BadImplementationClass(AgentMessageSchema):
def test_extract_decorators_x(self):
for serial in [
{
"@type": "signed-agent-message",
"@type": "doc/proto/1.0/signed-agent-message",
"@id": "030ac9e6-0d60-49d3-a8c6-e7ce0be8df5a",
"value": "Test value",
},
{
"@type": "signed-agent-message",
"@type": "doc/proto/1.0/signed-agent-message",
"@id": "030ac9e6-0d60-49d3-a8c6-e7ce0be8df5a",
"value": "Test value",
"value~sig": {
Expand All @@ -231,7 +231,7 @@ def test_extract_decorators_x(self):
},
},
{
"@type": "signed-agent-message",
"@type": "doc/proto/1.0/signed-agent-message",
"@id": "030ac9e6-0d60-49d3-a8c6-e7ce0be8df5a",
"superfluous~sig": {
"@type": DIDCommPrefix.qualify_current(
Expand All @@ -251,7 +251,7 @@ def test_extract_decorators_x(self):

def test_serde(self):
serial = {
"@type": "signed-agent-message",
"@type": "doc/proto/1.0/signed-agent-message",
"@id": "030ac9e6-0d60-49d3-a8c6-e7ce0be8df5a",
"value~sig": {
"@type": DIDCommPrefix.qualify_current(
Expand Down
6 changes: 3 additions & 3 deletions aries_cloudagent/messaging/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from datetime import datetime, timedelta, timezone
from hashlib import sha256
from math import floor
from typing import Any, Dict, List, Optional, Union
from typing import Any, Dict, List, Union


LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -151,7 +151,7 @@ def canon(raw_attr_name: str) -> str:

def get_proto_default_version(
versions: List[Dict[str, Any]], major_version: int = 1
) -> Optional[str]:
) -> str:
"""Return default protocol version from version definition list."""

for version in versions:
Expand All @@ -160,4 +160,4 @@ def get_proto_default_version(
default_minor_version = version["current_minor_version"]
return f"{default_major_version}.{default_minor_version}"

return None
return "1.0"
4 changes: 0 additions & 4 deletions aries_cloudagent/multitenant/admin/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
"ACAPY_AUTO_VERIFY_PRESENTATION": "debug.auto_verify_presentation",
"ACAPY_AUTO_WRITE_TRANSACTIONS": "endorser.auto_write",
"ACAPY_CREATE_REVOCATION_TRANSACTIONS": "endorser.auto_create_rev_reg",
"ACAPY_EMIT_DID_PEER_2": "emit_did_peer_2",
"ACAPY_EMIT_DID_PEER_4": "emit_did_peer_4",
"ACAPY_ENDORSER_ALIAS": "endorser.endorser_alias",
"ACAPY_ENDORSER_INVITATION": "endorser.endorser_invitation",
"ACAPY_ENDORSER_PUBLIC_DID": "endorser.endorser_public_did",
Expand All @@ -63,8 +61,6 @@
"auto-respond-messages": "debug.auto_respond_messages",
"auto-verify-presentation": "debug.auto_verify_presentation",
"auto-write-transactions": "endorser.auto_write",
"emit-did-peer-2": "emit_did_peer_2",
"emit-did-peer-4": "emit_did_peer_4",
"endorser-alias": "endorser.endorser_alias",
"endorser-invitation": "endorser.endorser_invitation",
"endorser-protocol-role": "endorser.protocol_role",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,16 @@ async def route_invitation(

raise ValueError("Expected connection to have invitation_key")

async def route_verkey(self, profile: Profile, verkey: str):
async def route_verkey(
self,
profile: Profile,
verkey: str,
mediation_record: Optional[MediationRecord] = None,
):
"""Establish routing for a public DID."""
return await self._route_for_key(profile, verkey, skip_if_exists=True)
return await self._route_for_key(
profile, verkey, mediation_record, skip_if_exists=True
)

async def route_public_did(self, profile: Profile, verkey: str):
"""Establish routing for a public DID.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ async def test_route_public_did(profile: Profile, route_manager: RouteManager):
async def test_route_verkey(profile: Profile, route_manager: RouteManager):
await route_manager.route_verkey(profile, "test-verkey")
route_manager._route_for_key.assert_called_once_with(
profile, "test-verkey", skip_if_exists=True
profile, "test-verkey", None, skip_if_exists=True
)


Expand Down
Loading

0 comments on commit a9e0cf7

Please sign in to comment.