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 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
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
12 changes: 9 additions & 3 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],
allowed_verification_method_types: Optional[List[KeyType]] = None,
proof_purpose: Optional[str] = None,
) -> Optional[str]:
Expand All @@ -22,6 +25,7 @@ def get_verification_method_id_for_did(
Returns None if no strategy is specified for this DID.

:params did: the did
:params profile: context of the call
:params allowed_verification_method_types: list of accepted key types
:params proof_purpose: the verkey relationship (assertionMethod, keyAgreement, ..)
:returns Optional[str]: the current verkey ID
Expand All @@ -35,17 +39,19 @@ 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],
allowed_verification_method_types: Optional[List[KeyType]] = None,
proof_purpose: Optional[str] = None,
) -> Optional[str]:
"""Given a did:key or did:sov, returns the verification key ID in use.

Returns None if no strategy is specified for this DID.

:params str did: the did
:params did: the did
:params profile: context of the call
:params allowed_verification_method_types: list of accepted key types
:params proof_purpose: the verkey relationship (assertionMethod, keyAgreement, ..)
:returns Optional[str]: the current verkey ID
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from unittest import TestCase

from aries_cloudagent.core.profile import Profile

from aries_cloudagent.did.did_key import DIDKey

from aries_cloudagent.wallet.default_verification_key_strategy import (
Expand All @@ -11,20 +13,25 @@


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, Profile())
== 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, Profile())
== 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", Profile()
)
is None
)