readium / r2-streamer-js

NodeJS Readium2 "streamer"
BSD 3-Clause "New" or "Revised" License
21 stars 10 forks source link

Lexicographically canonical JSON form of "Readium webpub manifest" #28

Open danielweck opened 6 years ago

danielweck commented 6 years ago

See: https://tools.ietf.org/html/draft-rundgren-json-canonicalization-scheme-01 https://github.com/cyberphone/json-canonicalization https://github.com/erdtman/canonicalize

danielweck commented 6 years ago

Note that there are several "competing" proposals for various definitions of "canonical" JSON, e.g.

https://github.com/gibson042/canonicaljson-spec https://github.com/gibson042/canonicaljson-go

http://wiki.laptop.org/go/Canonical_JSON https://github.com/well-typed/canonical-json

https://github.com/mirkokiefer/canonical-json https://github.com/davidchambers/CANON

https://keybase.io/docs/api/1.0/canonical_packings#json

https://bigeasy.github.io/keyify/docco/keyify.js.html https://github.com/bigeasy/keyify

...as exemplified by this expansive discussion thread: https://esdiscuss.org/topic/json-canonicalize https://mail.mozilla.org/pipermail/es-discuss/2018-March/thread.html#50334

However, in our limited use-case we would in fact not have to deal with sophisticated normalization of unicode strings (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize ) and/or number types, mostly just removal of insignificant whitespace in the serialized representation ("stringify-ed" JSON), and sorting of object properties / keys as per their lexicographic (alphabetical) order.

danielweck commented 6 years ago

Also see improved JSON "stringify" solutions: https://github.com/epoberezkin/fast-json-stable-stringify