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

fix (backport): routing behind mediator #2537

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
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
Copy link
Contributor

Choose a reason for hiding this comment

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

Without applying the transform in the first case, wouldn't it still be a key and not ref? As DIDKey.from_public_key_b58(key, ED25519).key_id would provide a did:key:.... not a ref. In which case, it would still fail to give DIDCommService at the pydid.deserialize_document() stage? @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.

DIDKey.key_id is a reference (perhaps not the best name for the property)

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)