mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
feat(add-routing-info): initial commit (#773)
This commit is contained in:
@@ -217,5 +217,6 @@ export const initAuthCreds = (): AuthenticationCreds => {
|
||||
registration: {} as never,
|
||||
pairingCode: undefined,
|
||||
lastPropHash: undefined,
|
||||
routingInfo: undefined,
|
||||
}
|
||||
}
|
||||
@@ -18,11 +18,13 @@ export const makeNoiseHandler = ({
|
||||
NOISE_HEADER,
|
||||
mobile,
|
||||
logger,
|
||||
routingInfo
|
||||
}: {
|
||||
keyPair: KeyPair
|
||||
NOISE_HEADER: Uint8Array
|
||||
mobile: boolean
|
||||
logger: Logger
|
||||
routingInfo?: Buffer | undefined
|
||||
}) => {
|
||||
logger = logger.child({ class: 'ns' })
|
||||
|
||||
@@ -133,11 +135,25 @@ export const makeNoiseHandler = ({
|
||||
data = encrypt(data)
|
||||
}
|
||||
|
||||
const introSize = sentIntro ? 0 : NOISE_HEADER.length
|
||||
let header: Buffer
|
||||
|
||||
if(routingInfo) {
|
||||
header = Buffer.alloc(7)
|
||||
header.write('ED', 0, 'utf8')
|
||||
header.writeUint8(0, 2)
|
||||
header.writeUint8(1, 3)
|
||||
header.writeUint8(routingInfo.byteLength >> 16, 4)
|
||||
header.writeUint16BE(routingInfo.byteLength & 65535, 5)
|
||||
header = Buffer.concat([header, routingInfo, NOISE_HEADER])
|
||||
} else {
|
||||
header = Buffer.from(NOISE_HEADER)
|
||||
}
|
||||
|
||||
const introSize = sentIntro ? 0 : header.length
|
||||
const frame = Buffer.alloc(introSize + 3 + data.byteLength)
|
||||
|
||||
if(!sentIntro) {
|
||||
frame.set(NOISE_HEADER)
|
||||
frame.set(header)
|
||||
sentIntro = true
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user