ÿØÿà JFIF    ÿÛ „ ( %!1!%*+...983,7(-.- PK"^]çМ@@canonical-json/LICENSEnu„[µü¤MIT License Copyright (c) 2022 GitHub and the TUF Contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. PK"^]âÈ?Eääcanonical-json/lib/index.jsnu„[µü¤const COMMA = ','; const COLON = ':'; const LEFT_SQUARE_BRACKET = '['; const RIGHT_SQUARE_BRACKET = ']'; const LEFT_CURLY_BRACKET = '{'; const RIGHT_CURLY_BRACKET = '}'; // Recursively encodes the supplied object according to the canonical JSON form // as specified at http://wiki.laptop.org/go/Canonical_JSON. It's a restricted // dialect of JSON in which keys are lexically sorted, floats are not allowed, // and only double quotes and backslashes are escaped. function canonicalize(object) { const buffer = []; if (typeof object === 'string') { buffer.push(canonicalizeString(object)); } else if (typeof object === 'boolean') { buffer.push(JSON.stringify(object)); } else if (Number.isInteger(object)) { buffer.push(JSON.stringify(object)); } else if (object === null) { buffer.push(JSON.stringify(object)); } else if (Array.isArray(object)) { buffer.push(LEFT_SQUARE_BRACKET); let first = true; object.forEach((element) => { if (!first) { buffer.push(COMMA); } first = false; buffer.push(canonicalize(element)); }); buffer.push(RIGHT_SQUARE_BRACKET); } else if (typeof object === 'object') { buffer.push(LEFT_CURLY_BRACKET); let first = true; Object.keys(object) .sort() .forEach((property) => { if (!first) { buffer.push(COMMA); } first = false; buffer.push(canonicalizeString(property)); buffer.push(COLON); buffer.push(canonicalize(object[property])); }); buffer.push(RIGHT_CURLY_BRACKET); } else { throw new TypeError('cannot encode ' + object.toString()); } return buffer.join(''); } // String canonicalization consists of escaping backslash (\) and double // quote (") characters and wrapping the resulting string in double quotes. function canonicalizeString(string) { const escapedString = string.replace(/\\/g, '\\\\').replace(/"/g, '\\"'); return '"' + escapedString + '"'; } module.exports = { canonicalize, }; PK"^]¦£à;canonical-json/package.jsonnu„[µü¤{ "name": "@tufjs/canonical-json", "version": "2.0.0", "description": "OLPC JSON canonicalization", "main": "lib/index.js", "typings": "lib/index.d.ts", "license": "MIT", "keywords": [ "json", "canonical", "canonicalize", "canonicalization", "crypto", "signature", "olpc" ], "author": "bdehamer@github.com", "repository": { "type": "git", "url": "git+https://github.com/theupdateframework/tuf-js.git" }, "homepage": "https://github.com/theupdateframework/tuf-js/tree/main/packages/canonical-json#readme", "bugs": { "url": "https://github.com/theupdateframework/tuf-js/issues" }, "files": [ "lib/" ], "scripts": { "test": "jest" }, "engines": { "node": "^16.14.0 || >=18.0.0" } } PK"^]çМ@@canonical-json/LICENSEnu„[µü¤PK"^]âÈ?Eää†canonical-json/lib/index.jsnu„[µü¤PK"^]¦£à;µ canonical-json/package.jsonnu„[µü¤PK