cleanup: remove string lid / jid refs and improve hosted support

This commit is contained in:
Rajeh Taher
2025-10-20 00:05:54 +03:00
parent 2e47d4b66b
commit cc3cd17392
6 changed files with 16 additions and 32 deletions
+1 -1
View File
@@ -122,7 +122,7 @@ export class LIDMappingStore {
this.logger.trace(`No LID mapping found for PN user ${pnUser}; batch getting from USync`) this.logger.trace(`No LID mapping found for PN user ${pnUser}; batch getting from USync`)
const device = decoded.device || 0 const device = decoded.device || 0
let normalizedPn = jidNormalizedUser(pn) let normalizedPn = jidNormalizedUser(pn)
if (isHostedLidUser(normalizedPn) || isHostedPnUser(normalizedPn)) { if (isHostedPnUser(normalizedPn)) {
normalizedPn = `${pnUser}@s.whatsapp.net` normalizedPn = `${pnUser}@s.whatsapp.net`
} }
+1 -1
View File
@@ -707,7 +707,7 @@ export const makeChatsSocket = (config: SocketConfig) => {
const jid = attrs.from const jid = attrs.from
const participant = attrs.participant || attrs.from const participant = attrs.participant || attrs.from
if (shouldIgnoreJid(jid!) && jid !== '@s.whatsapp.net') { if (shouldIgnoreJid(jid!) && jid !== S_WHATSAPP_NET) {
return return
} }
+3 -19
View File
@@ -1021,7 +1021,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
participant: attrs.participant participant: attrs.participant
} }
if (shouldIgnoreJid(remoteJid!) && remoteJid !== '@s.whatsapp.net') { if (shouldIgnoreJid(remoteJid!) && remoteJid !== S_WHATSAPP_NET) {
logger.debug({ remoteJid }, 'ignoring receipt from jid') logger.debug({ remoteJid }, 'ignoring receipt from jid')
await sendMessageAck(node) await sendMessageAck(node)
return return
@@ -1101,7 +1101,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
const handleNotification = async (node: BinaryNode) => { const handleNotification = async (node: BinaryNode) => {
const remoteJid = node.attrs.from const remoteJid = node.attrs.from
if (shouldIgnoreJid(remoteJid!) && remoteJid !== '@s.whatsapp.net') { if (shouldIgnoreJid(remoteJid!) && remoteJid !== S_WHATSAPP_NET) {
logger.debug({ remoteJid, id: node.attrs.id }, 'ignored notification') logger.debug({ remoteJid, id: node.attrs.id }, 'ignored notification')
await sendMessageAck(node) await sendMessageAck(node)
return return
@@ -1137,7 +1137,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
} }
const handleMessage = async (node: BinaryNode) => { const handleMessage = async (node: BinaryNode) => {
if (shouldIgnoreJid(node.attrs.from!) && node.attrs.from !== '@s.whatsapp.net') { if (shouldIgnoreJid(node.attrs.from!) && node.attrs.from !== S_WHATSAPP_NET) {
logger.debug({ key: node.attrs.key }, 'ignored message') logger.debug({ key: node.attrs.key }, 'ignored message')
await sendMessageAck(node, NACK_REASONS.UnhandledError) await sendMessageAck(node, NACK_REASONS.UnhandledError)
return return
@@ -1290,22 +1290,6 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
const from = infoChild.attrs.from! || infoChild.attrs['call-creator']! const from = infoChild.attrs.from! || infoChild.attrs['call-creator']!
status = getCallStatusFromNode(infoChild) status = getCallStatusFromNode(infoChild)
if (isLidUser(from) && infoChild.tag === 'relaylatency') {
const verify = await callOfferCache.get(callId)
if (!verify) {
status = 'offer'
const callLid: WACallEvent = {
chatId: attrs.from!,
from,
id: callId,
date: new Date(+attrs.t! * 1000),
offline: !!attrs.offline,
status
}
await callOfferCache.set(callId, callLid)
}
}
const call: WACallEvent = { const call: WACallEvent = {
chatId: attrs.from!, chatId: attrs.from!,
from, from,
+3 -3
View File
@@ -281,7 +281,7 @@ export const makeMessagesSocket = (config: SocketConfig) => {
const requestedLidUsers = new Set<string>() const requestedLidUsers = new Set<string>()
for (const jid of toFetch) { for (const jid of toFetch) {
if (jid.includes('@lid') || jid.includes('@hosted.lid')) { if (isLidUser(jid) || isHostedLidUser(jid)) {
const user = jidDecode(jid)?.user const user = jidDecode(jid)?.user
if (user) requestedLidUsers.add(user) if (user) requestedLidUsers.add(user)
} }
@@ -405,10 +405,10 @@ export const makeMessagesSocket = (config: SocketConfig) => {
if (jidsRequiringFetch.length) { if (jidsRequiringFetch.length) {
// LID if mapped, otherwise original // LID if mapped, otherwise original
const wireJids = [ const wireJids = [
...jidsRequiringFetch.filter(jid => !!jid.includes('@lid') || !!jid.includes('@hosted.lid')), ...jidsRequiringFetch.filter(jid => !!isLidUser(jid) || !!isHostedLidUser(jid)),
...( ...(
(await signalRepository.lidMapping.getLIDsForPNs( (await signalRepository.lidMapping.getLIDsForPNs(
jidsRequiringFetch.filter(jid => !!jid.includes('@s.whatsapp.net') || !!jid.includes('@hosted')) jidsRequiringFetch.filter(jid => !!isPnUser(jid) || !!isHostedPnUser(jid)
)) || [] )) || []
).map(a => a.lid) ).map(a => a.lid)
] ]
+6 -6
View File
@@ -19,8 +19,8 @@ import {
import { unpadRandomMax16 } from './generics' import { unpadRandomMax16 } from './generics'
import type { ILogger } from './logger' import type { ILogger } from './logger'
const getDecryptionJid = async (sender: string, repository: SignalRepositoryWithLIDStore): Promise<string> => { export const getDecryptionJid = async (sender: string, repository: SignalRepositoryWithLIDStore): Promise<string> => {
if (sender.includes('@lid')) { if (isLidUser(sender) || isHostedLidUser(sender)) {
return sender return sender
} }
@@ -35,6 +35,7 @@ const storeMappingFromEnvelope = async (
decryptionJid: string, decryptionJid: string,
logger: ILogger logger: ILogger
): Promise<void> => { ): Promise<void> => {
// TODO: Handle hosted IDs
const { senderAlt } = extractAddressingContext(stanza) const { senderAlt } = extractAddressingContext(stanza)
if (senderAlt && isLidUser(senderAlt) && isPnUser(sender) && decryptionJid === sender) { if (senderAlt && isLidUser(senderAlt) && isPnUser(sender) && decryptionJid === sender) {
@@ -259,12 +260,11 @@ export const decryptMessageNode = (
let msgBuffer: Uint8Array let msgBuffer: Uint8Array
const user = isPnUser(sender) ? sender : author // TODO: flaky logic const decryptionJid = await getDecryptionJid(author, repository)
const decryptionJid = await getDecryptionJid(user, repository)
if (tag !== 'plaintext') { if (tag !== 'plaintext') {
await storeMappingFromEnvelope(stanza, user, repository, decryptionJid, logger) // TODO: Handle hosted devices
await storeMappingFromEnvelope(stanza, author, repository, decryptionJid, logger)
} }
try { try {
+2 -2
View File
@@ -112,8 +112,8 @@ export const makeNoiseHandler = ({
const certDecoded = decrypt(serverHello!.payload!) const certDecoded = decrypt(serverHello!.payload!)
const { intermediate: certIntermediate } = 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!) const { issuerSerial } = proto.CertChain.NoiseCertificate.Details.decode(certIntermediate!.details!)
if (issuerSerial !== WA_CERT_DETAILS.SERIAL) { if (issuerSerial !== WA_CERT_DETAILS.SERIAL) {