diff --git a/src/datatypes/checksums.js b/src/datatypes/checksums.js index 1d516c70..2d5238f1 100644 --- a/src/datatypes/checksums.js +++ b/src/datatypes/checksums.js @@ -12,9 +12,11 @@ function computeChatChecksum (lastSeenMessages) { checksum = (31 * checksum + sigHash) & 0xffffffff } } - // Convert to byte - const result = checksum & 0xff - return result === 0 ? 1 : result + // Convert to signed byte (i8: -128..127) to match the chat_command_signed packet schema. + // The previous `& 0xff` produced 0..255 which causes RangeError when value > 127. + const unsigned = checksum & 0xff + const signed = unsigned > 127 ? unsigned - 256 : unsigned + return signed === 0 ? 1 : signed } module.exports = { computeChatChecksum }