Skip to content

DAG-CBOR/CBOR vs DAG-JSON/JSON format inconsistencies #522

@achingbrain

Description

@achingbrain

If I have a DAG-CBOR block with a CID in it, it has a tag 42. This tag is not present in "vanilla" CBOR.

Currently if I request a DAG-CBOR block that contains tag 42 in the cbor format from Kubo, it happily serves me binary with tag 42 present which I then cannot deserialize it using only a vanilla CBOR parser, so the returned value is invalid, or at least close to invalid.

Compare this to DAG-JSON which may contain serialized CIDs as { "/": "QmFoo" }, which can be lossily deserialized using a vanilla JSON parser.

If the user has explicitly requested a DAG-CBOR CID in the cbor format, perhaps any CIDs present should be converted to A1 61 2F 65 Qmfoo (e.g. { "/": "QmFoo"}) so it is parsable by a CBOR parser?

Then the user could arrive back at the original bytes if they wanted to via:

  1. Convert DAG-CBOR bytes to CBOR bytes
  2. Deserialize CBOR bytes as object
  3. Serialize object to JSON
  4. Deserialize JSON to object using DAG-JSON parser
  5. Serialize object to DAG-CBOR

Alternatively the gateway should return a 406 if tag 42 is present in a block requested in the cbor format, since it cannot be represented as vanilla CBOR, and the user can request dag-cbor, which means they are ready and prepared to handle tag 42.

Metadata

Metadata

Assignees

No one assigned

    Labels

    need/triageNeeds initial labeling and prioritization

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions