cognitect / transit-format

A data interchange format.
1.88k stars 36 forks source link

Canonical Encoding #36

Open ghadishayban opened 7 years ago

ghadishayban commented 7 years ago

Use cases like blockchain transaction payloads and content-addressable storage have a general requirement that securely hashing equivalent information generates the same hash. Has a canonical sort order for map keys been considered?

(There may be other considerations besides key sort order that prevent generating the same hash.)

ghadishayban commented 7 years ago

Something like IPLD is another interesting use case https://github.com/ipld/specs/tree/master/ipld

ghadishayban commented 7 years ago

CBOR defines a "canonical encoding" [1] that, among other things, requires:

The keys in every map must be sorted lowest value to highest. Sorting is performed on the bytes of the representation of the key data items without paying attention to the 3/5 bit splitting for major types.

[1] https://tools.ietf.org/html/rfc7049#section-3.9