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

Provide an optional Profile to the verification key strategy #2265

Merged
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@ async def _get_suite_for_detail(
verkey_id_strategy = self.profile.context.inject(BaseVerificationKeyStrategy)
verification_method = (
verification_method
or verkey_id_strategy.get_verification_method_id_for_did(
issuer_id, proof_purpose="assertionMethod"
or await verkey_id_strategy.get_verification_method_id_for_did(
issuer_id, self.profile, proof_purpose="assertionMethod"
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,10 @@ async def _get_issue_suite(
"""Get signature suite for signing presentation."""
did_info = await self._did_info_for_did(issuer_id)
verkey_id_strategy = self.profile.context.inject(BaseVerificationKeyStrategy)
verification_method = verkey_id_strategy.get_verification_method_id_for_did(
issuer_id, proof_purpose="assertionMethod"
verification_method = (
await verkey_id_strategy.get_verification_method_id_for_did(
issuer_id, self.profile, proof_purpose="assertionMethod"
)
)

if verification_method is None:
Expand Down
8 changes: 6 additions & 2 deletions aries_cloudagent/wallet/default_verification_key_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from abc import ABC, abstractmethod
from typing import Optional, List

from aries_cloudagent.core.profile import Profile

from aries_cloudagent.wallet.key_type import KeyType

from aries_cloudagent.did.did_key import DIDKey
Expand All @@ -11,9 +13,10 @@ class BaseVerificationKeyStrategy(ABC):
"""Base class for defining which verification method is in use."""

@abstractmethod
def get_verification_method_id_for_did(
async def get_verification_method_id_for_did(
self,
did: str,
profile: Optional[Profile] = None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to require the profile and just not use it if the strategy does not require it. This will make the calls to the strategy more consistent and prevent intermittent failures from one call not having it but others do.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @dbluhm.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

allowed_verification_method_types: Optional[List[KeyType]] = None,
proof_purpose: Optional[str] = None,
) -> Optional[str]:
Expand All @@ -35,9 +38,10 @@ class DefaultVerificationKeyStrategy(BaseVerificationKeyStrategy):
Supports did:key: and did:sov only.
"""

def get_verification_method_id_for_did(
async def get_verification_method_id_for_did(
self,
did: str,
profile: Optional[Profile] = None,
allowed_verification_method_types: Optional[List[KeyType]] = None,
proof_purpose: Optional[str] = None,
) -> Optional[str]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,22 @@


class TestDefaultVerificationKeyStrategy(TestCase):
def test_with_did_sov(self):
async def test_with_did_sov(self):
strategy = DefaultVerificationKeyStrategy()
assert (
strategy.get_verification_method_id_for_did(TEST_DID_SOV)
await strategy.get_verification_method_id_for_did(TEST_DID_SOV)
== TEST_DID_SOV + "#key-1"
)

def test_with_did_key(self):
async def test_with_did_key(self):
strategy = DefaultVerificationKeyStrategy()
assert (
strategy.get_verification_method_id_for_did(TEST_DID_KEY)
await strategy.get_verification_method_id_for_did(TEST_DID_KEY)
== DIDKey.from_did(TEST_DID_KEY).key_id
)

def test_unsupported_did_method(self):
async def test_unsupported_did_method(self):
strategy = DefaultVerificationKeyStrategy()
assert strategy.get_verification_method_id_for_did("did:test:test") is None
assert (
await strategy.get_verification_method_id_for_did("did:test:test") is None
)