diff --git a/src/Signal/libsignal.ts b/src/Signal/libsignal.ts index 69d3e539..2e2654df 100644 --- a/src/Signal/libsignal.ts +++ b/src/Signal/libsignal.ts @@ -5,7 +5,15 @@ import type { LIDMapping, SignalAuthState, SignalKeyStoreWithTransaction } from import type { SignalRepositoryWithLIDStore } from '../Types/Signal' import { generateSignalPubKey } from '../Utils' import type { ILogger } from '../Utils/logger' -import { isHostedLidUser, isHostedPnUser, isLidUser, isPnUser, jidDecode, transferDevice, WAJIDDomains } from '../WABinary' +import { + isHostedLidUser, + isHostedPnUser, + isLidUser, + isPnUser, + jidDecode, + transferDevice, + WAJIDDomains +} from '../WABinary' import type { SenderKeyStore } from './Group/group_cipher' import { SenderKeyName } from './Group/sender-key-name' import { SenderKeyRecord } from './Group/sender-key-record' @@ -223,9 +231,10 @@ export function makeLibSignalRepository( if (!deviceStr) continue const deviceNum = parseInt(deviceStr) let jid = deviceNum === 0 ? `${user}@s.whatsapp.net` : `${user}:${deviceNum}@s.whatsapp.net` - if (deviceNum == 99) { + if (deviceNum === 99) { jid = `${user}:99@hosted` } + deviceJids.push(jid) } } diff --git a/src/Signal/lid-mapping.ts b/src/Signal/lid-mapping.ts index ac02273c..bacd6697 100644 --- a/src/Signal/lid-mapping.ts +++ b/src/Signal/lid-mapping.ts @@ -1,15 +1,7 @@ import { LRUCache } from 'lru-cache' import type { LIDMapping, SignalKeyStoreWithTransaction } from '../Types' import type { ILogger } from '../Utils/logger' -import { - isHostedLidUser, - isHostedPnUser, - isLidUser, - isPnUser, - jidDecode, - jidNormalizedUser, - WAJIDDomains -} from '../WABinary' +import { isHostedPnUser, isLidUser, isPnUser, jidDecode, jidNormalizedUser, WAJIDDomains } from '../WABinary' export class LIDMappingStore { private readonly mappingCache = new LRUCache({ diff --git a/src/Socket/messages-recv.ts b/src/Socket/messages-recv.ts index 68a09a02..274b2732 100644 --- a/src/Socket/messages-recv.ts +++ b/src/Socket/messages-recv.ts @@ -11,7 +11,6 @@ import type { MessageUserReceipt, SocketConfig, WACallEvent, - WACallUpdateType, WAMessage, WAMessageKey, WAPatchName @@ -1278,9 +1277,9 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => { } const handleCall = async (node: BinaryNode) => { - let status: WACallUpdateType const { attrs } = node const [infoChild] = getAllBinaryNodeChildren(node) + const status = getCallStatusFromNode(infoChild!) if (!infoChild) { throw new Boom('Missing call info in call node') @@ -1288,7 +1287,6 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => { const callId = infoChild.attrs['call-id']! const from = infoChild.attrs.from! || infoChild.attrs['call-creator']! - status = getCallStatusFromNode(infoChild) const call: WACallEvent = { chatId: attrs.from!, diff --git a/src/Socket/messages-send.ts b/src/Socket/messages-send.ts index cef7fc99..a2c989df 100644 --- a/src/Socket/messages-send.ts +++ b/src/Socket/messages-send.ts @@ -42,7 +42,6 @@ import { type FullJid, getBinaryNodeChild, getBinaryNodeChildren, - getServerFromDomainType, isHostedLidUser, isHostedPnUser, isJidGroup, @@ -51,7 +50,6 @@ import { jidDecode, jidEncode, jidNormalizedUser, - type JidServer, type JidWithDevice, S_WHATSAPP_NET } from '../WABinary' @@ -408,7 +406,7 @@ export const makeMessagesSocket = (config: SocketConfig) => { ...jidsRequiringFetch.filter(jid => !!isLidUser(jid) || !!isHostedLidUser(jid)), ...( (await signalRepository.lidMapping.getLIDsForPNs( - jidsRequiringFetch.filter(jid => !!isPnUser(jid) || !!isHostedPnUser(jid) + jidsRequiringFetch.filter(jid => !!isPnUser(jid) || !!isHostedPnUser(jid)) )) || [] ).map(a => a.lid) ] diff --git a/src/Utils/noise-handler.ts b/src/Utils/noise-handler.ts index 6e2d632e..3ff5f4e5 100644 --- a/src/Utils/noise-handler.ts +++ b/src/Utils/noise-handler.ts @@ -112,7 +112,7 @@ export const makeNoiseHandler = ({ const certDecoded = decrypt(serverHello!.payload!) - const { intermediate: certIntermediate, leaf } = proto.CertChain.decode(certDecoded) + const { intermediate: certIntermediate /*leaf*/ } = proto.CertChain.decode(certDecoded) // TODO: handle this leaf stuff const { issuerSerial } = proto.CertChain.NoiseCertificate.Details.decode(certIntermediate!.details!) diff --git a/src/Utils/signal.ts b/src/Utils/signal.ts index d9febd42..fcc9d814 100644 --- a/src/Utils/signal.ts +++ b/src/Utils/signal.ts @@ -143,30 +143,27 @@ export const extractDeviceJids = ( for (const userResult of result) { const { devices, id } = userResult as { devices: ParsedDeviceInfo; id: string } - let { user, domainType, server } = jidDecode(id)! + const decoded = jidDecode(id)!, + { user, server } = decoded + let { domainType } = decoded const deviceList = devices?.deviceList as DeviceListData[] - if (Array.isArray(deviceList)) { - for (const { id: device, keyIndex, isHosted } of deviceList) { - if ( - (!excludeZeroDevices || device !== 0) && // if zero devices are not-excluded, or device is non zero - ((myUser !== user && myLid !== user) || myDevice !== device) && // either different user or if me user, not this device - (device === 0 || !!keyIndex) // ensure that "key-index" is specified for "non-zero" devices, produces a bad req otherwise - ) { - if (isHosted) { - if (domainType === WAJIDDomains.LID) { - domainType = WAJIDDomains.HOSTED_LID - } else { - domainType = WAJIDDomains.HOSTED - } - } - - extracted.push({ - user, - device, - domainType, - server: getServerFromDomainType(server, domainType) - }) + if (!Array.isArray(deviceList)) continue + for (const { id: device, keyIndex, isHosted } of deviceList) { + if ( + (!excludeZeroDevices || device !== 0) && // if zero devices are not-excluded, or device is non zero + ((myUser !== user && myLid !== user) || myDevice !== device) && // either different user or if me user, not this device + (device === 0 || !!keyIndex) // ensure that "key-index" is specified for "non-zero" devices, produces a bad req otherwise + ) { + if (isHosted) { + domainType = domainType === WAJIDDomains.LID ? WAJIDDomains.HOSTED_LID : WAJIDDomains.HOSTED } + + extracted.push({ + user, + device, + domainType, + server: getServerFromDomainType(server, domainType) + }) } } }