Skip to content
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
7 changes: 4 additions & 3 deletions acapy_agent/wallet/default_verification_key_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import logging
from typing import Literal, Optional

from pydid import DIDDocument
from pydid import DIDDocument, VerificationMethod

from ..core.error import BaseError
from ..core.profile import Profile
Expand Down Expand Up @@ -68,6 +68,7 @@ def __init__(self):
self.key_types_mapping = {
"Ed25519Signature2018": ["Ed25519VerificationKey2018"],
"Ed25519Signature2020": ["Ed25519VerificationKey2020", "Multikey"],
"BbsBlsSignature2020": ["Bls12381G2Key2020"],
}

async def get_verification_method_id_for_did(
Expand Down Expand Up @@ -104,12 +105,12 @@ async def get_verification_method_id_for_did(
doc_raw = await resolver.resolve(profile=profile, did=did)
doc = DIDDocument.deserialize(doc_raw)

methods_or_refs = getattr(doc, proof_purpose, [])
methods_or_refs = doc_raw.get(proof_purpose, [])
# Dereference any refs in the verification relationship
methods = [
await resolver.dereference_verification_method(profile, method, document=doc)
if isinstance(method, str)
else method
else VerificationMethod.deserialize(method)
for method in methods_or_refs
]

Expand Down
74 changes: 74 additions & 0 deletions acapy_agent/wallet/tests/test_default_verification_key_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import pytest

from acapy_agent.resolver.did_resolver import DIDResolver
from ...resolver.tests.test_did_resolver import MockResolver

from ...did.did_key import DIDKey
from ...utils.testing import create_test_profile
Expand All @@ -17,6 +18,49 @@ class TestDefaultVerificationKeyStrategy(IsolatedAsyncioTestCase):
async def asyncSetUp(self) -> None:
self.profile = await create_test_profile()
resolver = DIDResolver()
resolver.register_resolver(
MockResolver(
["example"],
resolved={
"@context": [
"https://www.w3.org/ns/did/v1",
"https://w3id.org/security/multikey/v1",
],
"id": "did:example:123",
"verificationMethod": [
{
"id": "did:example:123#key-1",
"type": "Multikey",
"controller": "did:example:123",
"publicKeyMultibase": "z6MkjYXizfaAXTriV3h2Vc9uxJ9AMQpfG7mE1WKMnn1KJvFE",
},
{
"id": "did:example:123#key-2",
"type": "Multikey",
"controller": "did:example:123",
"publicKeyMultibase": "z6MkjYXizfaAXTriV3h2Vc9uxJ9AMQpfG7mE1WKMnn1KJvFE",
},
{
"id": "did:example:123#key-3",
"type": "Ed25519VerificationKey2018",
"controller": "did:example:123",
"publicKeyBase58": "66GgQRKjBvNFNYrKp3C57CbAXqYorEWsKVQRxW3JPhTr",
},
],
"authentication": ["did:example:123#key-1"],
"assertionMethod": [
"did:example:123#key-2",
"did:example:123#key-3",
{
"id": "did:example:123#key-4",
"type": "Bls12381G2Key2020",
"controller": "did:example:123",
"publicKeyBase58": "25EEkQtcLKsEzQ6JTo9cg4W7NHpaurn4Wg6LaNPFq6JQXnrP91SDviUz7KrJVMJd76CtAZFsRLYzvgX2JGxo2ccUHtuHk7ELCWwrkBDfrXCFVfqJKDootee9iVaF6NpdJtBE",
},
],
},
)
)
self.profile.context.injector.bind_instance(DIDResolver, resolver)

async def test_with_did_sov(self):
Expand All @@ -33,6 +77,36 @@ async def test_with_did_key(self):
== DIDKey.from_did(TEST_DID_KEY).key_id
)

async def test_with_did_for_assertion(self):
strategy = DefaultVerificationKeyStrategy()
assert (
await strategy.get_verification_method_id_for_did(
"did:example:123",
self.profile,
proof_type="Ed25519Signature2020",
proof_purpose="assertionMethod",
)
== "did:example:123#key-2"
)
assert (
await strategy.get_verification_method_id_for_did(
"did:example:123",
self.profile,
proof_type="Ed25519Signature2018",
proof_purpose="assertionMethod",
)
== "did:example:123#key-3"
)
assert (
await strategy.get_verification_method_id_for_did(
"did:example:123",
self.profile,
proof_type="BbsBlsSignature2020",
proof_purpose="assertionMethod",
)
== "did:example:123#key-4"
)

async def test_unsupported_did_method(self):
strategy = DefaultVerificationKeyStrategy()
with pytest.raises(Exception):
Expand Down