@hiroosy/baileys-lite 0.3.3 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -717,7 +717,8 @@ export const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publi
717
717
  let decKey = hash
718
718
  let counter = 0
719
719
  let sentIntro = false
720
- let inBytes = Buffer.alloc(0)
720
+ const EMPTY_BYTES = Buffer.alloc(0)
721
+ let inBytes = EMPTY_BYTES
721
722
  let transport = null
722
723
  let isWaitingForTransport = false
723
724
  let pendingOnFrame = null
@@ -785,7 +786,7 @@ export const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publi
785
786
  size = (inBytes[0] << 16) | (inBytes[1] << 8) | inBytes[2]
786
787
  if (inBytes.length < size + 3) return
787
788
  let frame = inBytes.subarray(3, size + 3)
788
- inBytes = inBytes.subarray(size + 3)
789
+ inBytes = inBytes.length === size + 3 ? EMPTY_BYTES : inBytes.subarray(size + 3)
789
790
  if (transport) {
790
791
  const result = transport.decrypt(frame) // gagal decrypt = counter tidak sinkron lagi -> biarkan melempar (fatal)
791
792
  try {
@@ -863,11 +864,11 @@ export const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publi
863
864
  inBytes = Buffer.concat([inBytes, newData])
864
865
  pendingOnFrame = onFrame
865
866
  } else {
866
- inBytes = inBytes.length === 0 ? Buffer.from(newData) : Buffer.concat([inBytes, newData])
867
+ inBytes = inBytes.length === 0 ? newData : Buffer.concat([inBytes, newData])
867
868
  }
868
869
  if (inBytes.length > MAX_IN_BYTES) {
869
870
  logger.error({ bufferedBytes: inBytes.length, max: MAX_IN_BYTES }, 'noise handler inBytes buffer exceeded cap, clearing')
870
- inBytes = Buffer.alloc(0)
871
+ inBytes = EMPTY_BYTES
871
872
  pendingOnFrame = null
872
873
  return
873
874
  }
@@ -882,7 +883,7 @@ export const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publi
882
883
 
883
884
  destroy: () => {
884
885
  destroyed = true
885
- inBytes = Buffer.alloc(0)
886
+ inBytes = EMPTY_BYTES
886
887
  pendingOnFrame = null
887
888
  transport = null
888
889
  }