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

Service from create_peer_did_numalgo_2 serde to UnknownService #60

Open
Jsyro opened this issue Jul 13, 2023 · 3 comments
Open

Service from create_peer_did_numalgo_2 serde to UnknownService #60

Jsyro opened this issue Jul 13, 2023 · 3 comments
Labels
related to: code Something related to the code base status: accepted ✅ Issue or PR is accepted type: improvement 👍 Improving existing functionality or features

Comments

@Jsyro
Copy link
Contributor

Jsyro commented Jul 13, 2023

What

After providing this dictionary as the service parameter to create_peer_did_numalgo_2(), the DIDDocument that is returned has an object of type Service.

                service = {
                    "type": "DIDCommMessaging",
                    "serviceEndpoint": self.profile.settings.get("default_endpoint"),
                    "accept": ["didcomm/v2", "didcomm/aip2;env=rfc587"],
                }

After that returned DIDDocument is serialized and deserialized, the Service object becomes a UnknownService object, when it should become a DIDCommService object.

Why

This is needed to create a did:peer:2 did and the corresponding did_doc in way that can be encoded into secure messages (like acapy).

Success Criteria

the type string should result in the appropriate pydid.service Class to be instantiated.

@chumbert chumbert added related to: code Something related to the code base status: accepted ✅ Issue or PR is accepted type: improvement 👍 Improving existing functionality or features labels Jul 17, 2023
@Jsyro
Copy link
Contributor Author

Jsyro commented Jul 18, 2023

Here is a sample script demonstrating my issue. I'm looking into making an appropriate change that will resolve it.

from peerdid.dids import resolve_peer_did, DIDDocument, create_peer_did_numalgo_2
from peerdid.keys import Ed25519VerificationKey2018, X25519KeyAgreementKey, Ed25519VerificationKey
from pydid import DIDCommService

from pprint import pprint
from json import loads

#starting params
verkey = "jBQAjABKakepe5Ay8qTYp1RWN5eaWnKjfepi3fXiXUL"
service = {
    "type": "did-communication",
    "serviceEndpoint": "http://host.docker.internal:9060",
    "accept": ["didcomm/v2", "didcomm/aip2;env=rfc587"],
}

#use lib to create peer_did
enc_keys = [X25519KeyAgreementKey.from_base58(verkey)]
sign_keys = [Ed25519VerificationKey.from_base58(verkey)]
peer_did = create_peer_did_numalgo_2(enc_keys, sign_keys, service)

#resolve did and serde
did_doc = resolve_peer_did(peer_did)
dd_str = did_doc.to_json()
deser_did_doc = DIDDocument.from_json(dd_str)


#use pydid to explicitly create DIDCommService
vm = Ed25519VerificationKey2018.make(
    id="#resv",
    controller=peer_did,
    public_key_base58=verkey,
)

dc_service = DIDCommService.make(
    id="#ress",
    service_endpoint="http://host.docker.internal:9060",
    recipient_keys=["#resv"]
)

#resolve document and serde
dd = DIDDocument.make(id=peer_did,verification_method=[vm],service=[dc_service])
dd2_str = dd.to_json()
deser_dd2 =DIDDocument.from_json(dd2_str)

#print library+serde
print("")
print("create_peer_did_numalgo_2")
pprint(type(did_doc.service[0]))
pprint(type(deser_did_doc.service[0]))

#print DIDDocument+serde
print("")
print("DIDDocument.make")
pprint(type(dd.service[0]))
pprint(type(deser_dd2.service[0]))

#isolate json differences after serialization
print("")
print("json service string")
print(loads(dd_str)["service"])
print("json DIDCommService string")
print(loads(dd2_str)["service"])

OUTPUT


create_peer_did_numalgo_2
<class 'pydid.service.Service'>
<class 'pydid.service.UnknownService'>

DIDDocument.make
<class 'pydid.service.DIDCommService'>
<class 'pydid.service.DIDCommService'>

json service string
[{'id': '#did-communication-0', 'type': 'did-communication', 'serviceEndpoint': 'http://host.docker.internal:9060', 'accept': ['didcomm/v2', 'didcomm/aip2;env=rfc587']}]
json DIDCommService string
[{'id': '#ress', 'type': 'did-communication', 'serviceEndpoint': 'http://host.docker.internal:9060', 'recipientKeys': ['#resv'], 'routingKeys': [], 'priority': 0}]

@Jsyro
Copy link
Contributor Author

Jsyro commented Jul 18, 2023

Updating pydid to the current HEAD installed as pydid-0.3.9a0 only changes the output slightly.

create_peer_did_numalgo_2
<class 'pydid.service.Service'>
<class 'pydid.service.UnknownService'>

DIDDocument.make
<class 'pydid.service.DIDCommV1Service'>
<class 'pydid.service.DIDCommV1Service'>

json service string
[{'id': '#did-communication-0', 'type': 'did-communication', 'serviceEndpoint': 'http://host.docker.internal:9060', 'accept': ['didcomm/v2', 'didcomm/aip2;env=rfc587']}]
json DIDCommService string
[{'id': '#ress', 'type': 'did-communication', 'serviceEndpoint': 'http://host.docker.internal:9060', 'recipientKeys': ['#resv'], 'routingKeys': [], 'priority': 0}]

@Jsyro
Copy link
Contributor Author

Jsyro commented Jul 18, 2023

service = {
    "type": "did-communication",
    "serviceEndpoint": "http://host.docker.internal:9060",
    "recipient_keys":[]
}

By providing an empty recipient_keys list, the object is created as a Service but after serde, becomes as DIDCommV1Service object. that is apparently the critical value that was causing it to not being loaded to the right service subclass!

Success!

create_peer_did_numalgo_2
<class 'pydid.service.Service'>
<class 'pydid.service.DIDCommV1Service'>

DIDDocument.make
<class 'pydid.service.DIDCommV1Service'>
<class 'pydid.service.DIDCommV1Service'>

json service string
[{'id': '#did-communication-0', 'type': 'did-communication', 'serviceEndpoint': 'http://host.docker.internal:9060', 'recipient_keys': []}]
json DIDCommService string
[{'id': '#ress', 'type': 'did-communication', 'serviceEndpoint': 'http://host.docker.internal:9060', 'recipientKeys': ['#resv'], 'routingKeys': [], 'priority': 0}]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
related to: code Something related to the code base status: accepted ✅ Issue or PR is accepted type: improvement 👍 Improving existing functionality or features
Projects
None yet
Development

No branches or pull requests

2 participants