dfinity / ICRC

Repository to ICRC proposals
Apache License 2.0
31 stars 5 forks source link

ICRC-30: JSON type syntax for Candid values #30

Open sea-snake opened 1 year ago

sea-snake commented 1 year ago

When communicating Candid data with JSON between web services, there are two options:

The latter is more accessible to services and dapps outside the IC ecosystem, they don't need to understand and decode CBOR to process incoming data.

A few examples:

This standard standardizes the JSON syntax of Candid type values for above use cases with a strong emphasis on making the data accessible for dapps outside the IC ecosystem without Candid knowledge.

The following technical details differ from other encoding formats of Candid types like CBOR:

The spec can be found at the following gist (until I've found a better place for it): https://gist.github.com/sea-snake/3043a9b83348111326a7699efb97e281

sea-snake commented 1 year ago

Some topics of discussion:

sea-snake commented 1 year ago

Example JS implementation compatible with autogenerated interfaceFactory that's used in @dfinity/candid: https://github.com/slide-computer/candid-json

frederikrothenberger commented 1 year ago

Thanks a lot for the contribution, @sea-snake! I would make it clear that it is a one-way transformation, as it is a lossy, if no candid types are given.

However, with the typings, one should be able to go back and forth, right? Would it make sense to write down the transformation algorithm?

@benjizhai: Is this the right repository to create a PR in? This standard is about general data transformation and does not fit nicely in one of the existing categories (I think). Maybe SDK/dev-tooling related?

sea-snake commented 1 year ago

@frederikrothenberger It's indeed one way but it retains all the structure information needed to go both ways when you have the Candid IDL, as seen in the JS implementation above.