Dorian 0d073fa89e Add comprehensive installation and setup documentation
- Add GETTING_STARTED.md with quick start guide and development modes
- Add INSTALL.sh automated installation script
- Add INSTALLATION_CHECKLIST.md, INSTALLATION_SUCCESS.md, and INSTALLATION_SUMMARY.md
- Add QUICK_REFERENCE.md for common commands
- Add SETUP_GUIDE.md with detailed setup instructions
- Update README.md with improved project overview
- Add did-wallet app dependencies and node_modules
2026-01-27 17:18:21 +00:00

33 lines
1.3 KiB
JavaScript

import * as canonicalize from 'canonicalize';
import Encoder from './Encoder.js';
/**
* Class containing reusable JSON canonicalization operations using JSON Canonicalization Scheme (JCS).
*/
export default class JsonCanonicalizer {
/**
* Canonicalizes the given content as bytes.
*/
static canonicalizeAsBytes(content) {
// We need to remove all properties with `undefined` as value so that JCS canonicalization will not produce invalid JSON.
const contentWithoutUndefinedProperties = JsonCanonicalizer.removeAllUndefinedProperties(content);
// @ts-expect-error because its a cjs package
const canonicalizedString = canonicalize.default(contentWithoutUndefinedProperties);
const contentBytes = Encoder.stringToBytes(canonicalizedString);
return contentBytes;
}
/**
* Removes all properties within the given object with `undefined` as value.
*/
static removeAllUndefinedProperties(content) {
for (const key in content) {
if (typeof content[key] === 'object') {
JsonCanonicalizer.removeAllUndefinedProperties(content[key]);
}
else if (content[key] === undefined) {
delete content[key];
}
}
return content;
}
}
//# sourceMappingURL=JsonCanonicalizer.js.map