sicpa-dlab / didcomm-python

basic DIDComm v2 support in python
Apache License 2.0
17 stars 15 forks source link

Parsing messages with custom headers fails #79

Closed rodolfomiranda closed 1 year ago

rodolfomiranda commented 1 year ago

GenericMessage class expects custom headers in a custom-headers field as a List[Header] from the plain json/dict, instead of a header in the root msg. Example of a custom header Is return_route.

dkulic commented 1 year ago

@rodolfomiranda can you provide an example what should be expected behaviour? I am not sure I get that.

rodolfomiranda commented 1 year ago

@dkulic custom-headers is not a defined field in DIDComm message. I understand that this library, as well as the JVM one, uses that property to embed extra fields that are not listed in the GenericMessage class. When reading from a json, or generating a json from that class, the customer-headers must be converted from/to properties in the plain json message. For example a plain json of the form:

{
   "id": "abcd",
   "type": "https://didcomm.org/basicmessage/2.0/message",
   "from": "did:example:1234",
   "to": "did.example:4321",
   "body": {'content': 'Hello Bob!'},
   "return_route": "yes",
}

should be converted in a GenericMessage object like:

(
   "id" = "abcd",
   "type" = "https://didcomm.org/basicmessage/2.0/message",
   "from" = "did:example:1234",
   "to" = "did.example:4321",
   "body": {'content': 'Hello Bob!'},
   "custom-headers": [{"return_route": "yes"}]
)

and viceversa when going back from a GenericMessage to the plain json object.

In the python library that treatment of custom-headers seems that was not implemented. However, the JVM library is handling that case correctly. You can see the differences in the following clases: didcomm-python didcomm-jvm

dkulic commented 1 year ago

Thanks. I will take a look.

dkulic commented 1 year ago

@rodolfomiranda I have created a PR for this issue. Can you take a look does it solve your problem?