Remove buffer dependency

This commit is contained in:
Jack Hadrill
2022-02-22 22:35:55 +00:00
parent 4d7cf1347f
commit 5c17b880cf
19 changed files with 106 additions and 96 deletions

View File

@@ -2,7 +2,7 @@ import Color from 'color'
import { MessageTypes } from '../../src/common'
import { packers, unpackers } from '../../src/mapping'
const KEY = Buffer.from([0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F])
const KEY = new Uint8Array([0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F])
test('Create a user data response (0x0003) packet.', () => {
// Given
@@ -20,12 +20,10 @@ test('Create a user data response (0x0003) packet.', () => {
KEY
)
console.log(packedPacket.slice(4).toString('hex'))
// Then
// We can't check the contents of the data as it's encrypted with a random nonce.
// Check the message type and length.
expect(packedPacket.slice(0, 4)).toMatchObject(Buffer.from([0x00, 0x03, 0x00, 0x3A]))
expect(packedPacket.slice(0, 4)).toMatchObject(new Uint8Array([0x00, 0x03, 0x00, 0x3A]))
// Check the total length is as expected.
expect(packedPacket.length).toBe(62)
@@ -33,7 +31,7 @@ test('Create a user data response (0x0003) packet.', () => {
test('Parse a user data response (0x0003).', () => {
// Given
const ciphertext = Buffer.from([
const ciphertext = new Uint8Array([
0x56, 0x71, 0x08, 0xf9, 0x2c, 0x4e, 0x41, 0x13, 0xbe, 0x44, 0xba, 0xd9, 0xe4, 0x25,
0x14, 0x60, 0x3b, 0x96, 0x7e, 0x0b, 0xbd, 0xac, 0xf0, 0xaf, 0xac, 0xd7, 0x80, 0xe5,
0x62, 0xd4, 0x33, 0x10, 0x23, 0x6d, 0x00, 0x3c, 0xae, 0x40, 0x6c, 0xe9, 0x40, 0xfc,