fix: harden Protobuf Deserialization and Refactor Utilities (#1820)
* refactor: reorganize browser utility functions and improve buffer handling * fix: harden protobuf deserialization and clean up code * refactor: simplify data handling in GroupCipher and SenderKey classes * fix: Ensure consistent Buffer hydration and remove redundant code * refactor: update decodeAndHydrate calls to use proto types for improved type safety
This commit is contained in:
committed by
GitHub
parent
202c39f3fe
commit
3b46d43beb
@@ -39,6 +39,7 @@ import {
|
||||
xmppSignedPreKey
|
||||
} from '../Utils'
|
||||
import { makeMutex } from '../Utils/make-mutex'
|
||||
import { decodeAndHydrate } from '../Utils/proto-utils'
|
||||
import {
|
||||
areJidsSameUser,
|
||||
type BinaryNode,
|
||||
@@ -293,7 +294,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
||||
typeof plaintextNode.content === 'string'
|
||||
? Buffer.from(plaintextNode.content, 'binary')
|
||||
: Buffer.from(plaintextNode.content as Uint8Array)
|
||||
const messageProto = proto.Message.decode(contentBuf)
|
||||
const messageProto = decodeAndHydrate(proto.Message, contentBuf)
|
||||
const fullMessage = proto.WebMessageInfo.create({
|
||||
key: {
|
||||
remoteJid: from,
|
||||
|
||||
@@ -28,11 +28,12 @@ import {
|
||||
getCodeFromWSError,
|
||||
getErrorCodeFromStreamError,
|
||||
getNextPreKeysNode,
|
||||
getPlatformId,
|
||||
makeEventBuffer,
|
||||
makeNoiseHandler,
|
||||
promiseTimeout
|
||||
} from '../Utils'
|
||||
import { getPlatformId } from '../Utils/browser-utils'
|
||||
import { decodeAndHydrate } from '../Utils/proto-utils'
|
||||
import {
|
||||
assertNodeErrorFree,
|
||||
type BinaryNode,
|
||||
@@ -342,7 +343,7 @@ export const makeSocket = (config: SocketConfig) => {
|
||||
const init = proto.HandshakeMessage.encode(helloMsg).finish()
|
||||
|
||||
const result = await awaitNextMessage<Uint8Array>(init)
|
||||
const handshake = proto.HandshakeMessage.decode(result)
|
||||
const handshake = decodeAndHydrate(proto.HandshakeMessage, result)
|
||||
|
||||
logger.trace({ handshake }, 'handshake recv from WA')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user