export function byteArrayToLong(byteArray: Uint8Array): number { let value = 0; for (let i = byteArray.length - 1; i >= 0; i--) { value = value * 256 + byteArray[i]; } return value; } export function shortTo2ByteArray(long: number): Uint8Array { if (long > (2 ^ (32 - 1))) throw new Error('Short too long'); // we want to represent the input as a 8-bytes array const byteArray = [0, 0]; for (let index = 0; index < byteArray.length; index++) { const byte = long & 0xff; byteArray[index] = byte; long = (long - byte) / 256; } return Uint8Array.from(byteArray); } export function longTo8ByteArray(long: number): Uint8Array { // we want to represent the input as a 8-bytes array const byteArray = [0, 0, 0, 0, 0, 0, 0, 0]; for (let index = 0; index < byteArray.length; index++) { const byte = long & 0xff; byteArray[index] = byte; long = (long - byte) / 256; } return Uint8Array.from(byteArray); }