Skip to content

Commit

Permalink
Merge pull request #2537 from dbluhm/fix/routing-keys-backport
Browse files Browse the repository at this point in the history
fix (backport): routing behind mediator
  • Loading branch information
dbluhm committed Oct 8, 2023
2 parents 736cdfb + f498219 commit c5d16ed
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 3 deletions.
17 changes: 14 additions & 3 deletions aries_cloudagent/resolver/default/legacy_peer.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,18 @@ def recip_base58_to_ref(vms: List[dict], recip: str) -> str:
return recip

@classmethod
def didcomm_services_recip_keys_are_refs_routing_keys_are_did_key(
def did_key_to_did_key_ref(cls, key: str):
"""Convert did:key to did:key ref."""
# Check if key is already a ref
if key.rfind("#") != -1:
return key
# Get the value after removing did:key:
value = key.replace("did:key:", "")

return key + "#" + value

@classmethod
def didcomm_services_recip_keys_are_refs_routing_keys_are_did_key_ref(
cls,
value: dict,
) -> dict:
Expand All @@ -152,7 +163,7 @@ def didcomm_services_recip_keys_are_refs_routing_keys_are_did_key(
service["routingKeys"] = [
DIDKey.from_public_key_b58(key, ED25519).key_id
if "did:key:" not in key
else key
else cls.did_key_to_did_key_ref(key)
for key in service["routingKeys"]
]
return value
Expand Down Expand Up @@ -235,7 +246,7 @@ def apply(cls, value: dict) -> dict:
cls.fully_qualified_ids_and_controllers,
cls.didcomm_services_use_updated_conventions,
cls.remove_routing_keys_from_verification_method,
cls.didcomm_services_recip_keys_are_refs_routing_keys_are_did_key,
cls.didcomm_services_recip_keys_are_refs_routing_keys_are_did_key_ref,
):
value = correction(value)

Expand Down
71 changes: 71 additions & 0 deletions aries_cloudagent/resolver/default/tests/test_legacy_peer.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,3 +499,74 @@ def test_corrections(self, input_doc: dict, expected: dict):
doc = pydid.deserialize_document(actual)
assert doc.service
assert isinstance(doc.service[0], pydid.DIDCommService)

@pytest.mark.parametrize(
("input_doc", "expected"),
[
(
{
"@context": "https://w3id.org/did/v1",
"id": "StwSYX1WFcJ7MBfYWxmuQ9",
"publicKey": [
{
"type": "Ed25519VerificationKey2018",
"id": "StwSYX1WFcJ7MBfYWxmuQ9#1",
"controller": "StwSYX1WFcJ7MBfYWxmuQ9",
"publicKeyBase58": "F7cEyTgzUbFwHsTwC2cK2Zy8bdraeoMY8921gyDmefwK",
}
],
"authentication": [
{
"type": "Ed25519VerificationKey2018",
"publicKey": "StwSYX1WFcJ7MBfYWxmuQ9#1",
}
],
"service": [
{
"type": "IndyAgent",
"id": "StwSYX1WFcJ7MBfYWxmuQ9#IndyAgentService",
"serviceEndpoint": "https://example.com/endpoint",
"recipientKeys": [
"F7cEyTgzUbFwHsTwC2cK2Zy8bdraeoMY8921gyDmefwK"
],
"routingKeys": [
"did:key:z6Mko2LnynhGbkPQdZ3PQBUgCmrzdH9aJe7HTs4LKontx8Ge"
],
}
],
},
{
"@context": "https://w3id.org/did/v1",
"id": "did:sov:StwSYX1WFcJ7MBfYWxmuQ9",
"verificationMethod": [
{
"type": "Ed25519VerificationKey2018",
"id": "did:sov:StwSYX1WFcJ7MBfYWxmuQ9#1",
"controller": "did:sov:StwSYX1WFcJ7MBfYWxmuQ9",
"publicKeyBase58": "F7cEyTgzUbFwHsTwC2cK2Zy8bdraeoMY8921gyDmefwK",
}
],
"authentication": ["did:sov:StwSYX1WFcJ7MBfYWxmuQ9#1"],
"service": [
{
"id": "did:sov:StwSYX1WFcJ7MBfYWxmuQ9#didcomm-0",
"type": "did-communication",
"serviceEndpoint": "https://example.com/endpoint",
"recipientKeys": ["did:sov:StwSYX1WFcJ7MBfYWxmuQ9#1"],
"routingKeys": [
"did:key:z6Mko2LnynhGbkPQdZ3PQBUgCmrzdH9aJe7HTs4LKontx8Ge#z6Mko2LnynhGbkPQdZ3PQBUgCmrzdH9aJe7HTs4LKontx8Ge"
],
}
],
},
)
],
)
def test_corrections_on_doc_as_received(self, input_doc: dict, expected: dict):
parsed = DIDDoc.deserialize(input_doc)
actual = test_module.LegacyDocCorrections.apply(parsed.serialize())
assert actual == expected
assert expected == test_module.LegacyDocCorrections.apply(expected)
doc = pydid.deserialize_document(actual)
assert doc.service
assert isinstance(doc.service[0], pydid.DIDCommService)

0 comments on commit c5d16ed

Please sign in to comment.