libsignal,lid-mapping, etc.: Partially fix "No sessions" on hosted JIDs

This commit is contained in:
Rajeh Taher
2025-10-16 18:31:01 +03:00
parent d0feb240fa
commit e41a66b3c4
8 changed files with 37 additions and 30 deletions
+5 -4
View File
@@ -128,6 +128,7 @@ export function makeLibSignalRepository(
},
async injectE2ESession({ jid, session }) {
logger.trace({ jid }, 'injecting E2EE session')
const cipher = new libsignal.SessionBuilder(storage, jidToSignalProtocolAddress(jid))
return parsedKeys.transaction(async () => {
await cipher.initOutgoing(session)
@@ -350,13 +351,13 @@ function signalStorage(
// Shared function to resolve PN signal address to LID if mapping exists
const resolveLIDSignalAddress = async (id: string): Promise<string> => {
if (id.includes('.')) {
const [deviceId, domainType_] = id.split('_')
const [deviceId, device] = id.split('.')
const [user, domainType_] = deviceId!.split('_')
const domainType = parseInt(domainType_ || '0')
const [user, device] = deviceId!.split('.')
if (domainType === WAJIDDomains.LID || domainType === WAJIDDomains.HOSTED_LID) return id
const pnJid = `${user!}${device !== '0' ? `:${device}` : ''}@s.whatsapp.net`
const pnJid = `${user!}${device !== '0' ? `:${device}` : ''}@${domainType == WAJIDDomains.HOSTED ? 'hosted' : 's.whatsapp.net'}`
let lidForPN = await lidMapping.getLIDForPN(pnJid)
if (lidForPN?.includes('@lid')) {
@@ -389,7 +390,7 @@ function signalStorage(
await keys.set({ session: { [wireJid]: session.serialize() } })
},
isTrustedIdentity: () => {
return true
return true // todo: implement
},
loadPreKey: async (id: number | string) => {
const keyId = id.toString()
+3 -3
View File
@@ -1,7 +1,7 @@
import { LRUCache } from 'lru-cache'
import type { LIDMapping, SignalKeyStoreWithTransaction } from '../Types'
import type { ILogger } from '../Utils/logger'
import { isJidHostedLidUser, isJidHostedPnUser, isLidUser, isPnUser, jidDecode, jidNormalizedUser } from '../WABinary'
import { isHostedLidUser, isHostedPnUser, isLidUser, isPnUser, jidDecode, jidNormalizedUser } from '../WABinary'
export class LIDMappingStore {
private readonly mappingCache = new LRUCache<string, string>({
@@ -93,7 +93,7 @@ export class LIDMappingStore {
// mapped from pn to lid mapping to prevent duplication in results later
const successfulPairs: { [_: string]: LIDMapping } = {}
for (const pn of pns) {
if (!isPnUser(pn)) continue
if (!isPnUser(pn) && !isHostedPnUser(pn)) continue
const decoded = jidDecode(pn)
if (!decoded) continue
@@ -114,7 +114,7 @@ export class LIDMappingStore {
this.logger.trace(`No LID mapping found for PN user ${pnUser}; batch getting from USync`)
const device = decoded.device || 0
let normalizedPn = jidNormalizedUser(pn)
if (isJidHostedLidUser(normalizedPn) || isJidHostedPnUser(normalizedPn)) {
if (isHostedLidUser(normalizedPn) || isHostedPnUser(normalizedPn)) {
normalizedPn = `${pnUser}@s.whatsapp.net`
}