Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public static toDSON(data: any): Buffer {
const enc = new cbor.Encoder()
// Overide default object encoder to use stream encoding and lexicographical ordering of keys
enc.addSemanticType(Object, (encoder, obj) => {
const keys = Object.keys(obj)
keys.sort()
if (!encoder.push(Buffer.from([0b1011_1111]))) { return false }
for (const key of keys) {
if (isEmpty(obj[key])) {
continue
}
if (!encoder.pushAny(key)) { return false }
if (!encoder.pushAny(obj[key])) { return false }
var _toCBOR = function(signableObj) {
var encoder = new cbor.Encoder();
var output = new streamBuffers.WritableStreamBuffer({
initalSize: (16 * 1024),
});
encoder.pipe(output);
encoder.write(signableObj.sortBy(_byKey).toJSON());
encoder.end();
return output.getContents();
};