sicpa-dlab / peer-did-python

Peer DID method implementation in Python
Apache License 2.0
11 stars 10 forks source link

recipient_key cannot be referenced as id's are randomly generated #63

Open Jsyro opened 10 months ago

Jsyro commented 10 months ago

What

pydid's DIDCommV1Service.recipient_keys are required to be DIDUrl, referencing a verificationMethod (ideally in the same document) however those id's are randomly generated.

Why

To use the didurl, a consumer of this API must repair the reference by making assumptions about the structure of the document. See my workaround implemented in acapy https://github.com/hyperledger/aries-cloudagent-python/pull/2472#discussion_r1318565161

def _resolve_peer_did_with_service_key_reference(
    peer_did_2: Union[str, DID]
) -> DIDDocument:
    try:
        doc = resolve_peer_did(peer_did_2)
        ## WORKAROUND LIBRARY NOT REREFERENCING RECEIPIENT_KEY
        services = doc.service
        signing_keys = [
            vm
            for vm in doc.verification_method or []
            if vm.type == "Ed25519VerificationKey2020"
        ]
        if services and signing_keys:
            services[0].__dict__["recipient_keys"] = [signing_keys[0].id]
        else:
            raise Exception("no recipient_key signing_key pair")
    except Exception as e:
        raise ValueError("pydantic validation error:" + str(e))
    return doc

Success Criteria

After resolve_peer_did, calling dereference on the service.recipient_key should work with no modification. My example is one possible solution.