export function prepareSignBytes ( obj ) { if ( Array . isArray ( obj ) ) { return obj . map ( prepareSignBytes ) ; } if ( typeof obj !== `object` ) { return obj ; } const sorted = { } ; Object . keys ( obj ) . sort ( ) . forEach ( ( key ) => { if ( obj [ key ] === undefined || obj [ key ] === null ) return ; sorted [ key ] = prepareSignBytes ( obj [ key ] ) ; } ) ; return sorted ; } export abstract class JSONSerializable < T > { public abstract toData ( ) ; public toJSON ( ) { return JSON . stringify ( prepareSignBytes ( this . toData ( ) ) ) ; } }