From e7c31f9270e2dabe7d7178131db1945264e61ecb Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 9 Feb 2026 03:50:36 +0000 Subject: [PATCH] fix: revert defensive null checks in signal.ts that prevented Signal session creation The previous PRs (124-129) replaced non-null assertions (!) with defensive null checks + continue statements in parseAndInjectE2ESessions and extractDeviceJids. This caused ALL prekey bundles to be silently skipped because the continue statements would trigger whenever any sub-field appeared missing (even though WhatsApp always sends complete bundles). Result: no Signal sessions were created after QR scan, causing "SessionError: No sessions" when trying to send messages. Reverted to the original Baileys pattern using non-null assertions, which matches the upstream reference (infinitezap/Teste_InfiniteAPI). https://claude.ai/code/session_01XaA7GwNaB6azTHFYQ8WEpB --- src/Utils/signal.ts | 50 ++++++++++++++++----------------------------- 1 file changed, 18 insertions(+), 32 deletions(-) diff --git a/src/Utils/signal.ts b/src/Utils/signal.ts index 6900743b..fcc9d814 100644 --- a/src/Utils/signal.ts +++ b/src/Utils/signal.ts @@ -88,18 +88,14 @@ export const xmppPreKey = (pair: KeyPair, id: number): BinaryNode => ({ }) export const parseAndInjectE2ESessions = async (node: BinaryNode, repository: SignalRepositoryWithLIDStore) => { - const extractKey = (key: BinaryNode) => { - if (!key) return undefined - const keyId = getBinaryNodeChildUInt(key, 'id', 3) - const publicKeyBuf = getBinaryNodeChildBuffer(key, 'value') - const signature = getBinaryNodeChildBuffer(key, 'signature') - if (keyId === undefined || !publicKeyBuf || !signature) return undefined - return { - keyId, - publicKey: generateSignalPubKey(publicKeyBuf), - signature - } - } + const extractKey = (key: BinaryNode) => + key + ? { + keyId: getBinaryNodeChildUInt(key, 'id', 3)!, + publicKey: generateSignalPubKey(getBinaryNodeChildBuffer(key, 'value')!), + signature: getBinaryNodeChildBuffer(key, 'signature')! + } + : undefined const nodes = getBinaryNodeChildren(getBinaryNodeChild(node, 'list'), 'user') for (const node of nodes) { assertNodeErrorFree(node) @@ -115,26 +111,20 @@ export const parseAndInjectE2ESessions = async (node: BinaryNode, repository: Si for (const nodesChunk of chunks) { for (const node of nodesChunk) { - const signedKey = getBinaryNodeChild(node, 'skey') - const key = getBinaryNodeChild(node, 'key') - const identity = getBinaryNodeChildBuffer(node, 'identity') - const jid = node.attrs.jid - if (!signedKey || !key || !identity || !jid) continue + const signedKey = getBinaryNodeChild(node, 'skey')! + const key = getBinaryNodeChild(node, 'key')! + const identity = getBinaryNodeChildBuffer(node, 'identity')! + const jid = node.attrs.jid! const registrationId = getBinaryNodeChildUInt(node, 'registration', 4) - if (registrationId === undefined) continue - - const signedPreKey = extractKey(signedKey) - const preKey = extractKey(key) - if (!signedPreKey || !preKey) continue await repository.injectE2ESession({ jid, session: { - registrationId, + registrationId: registrationId!, identityKey: generateSignalPubKey(identity), - signedPreKey, - preKey + signedPreKey: extractKey(signedKey)!, + preKey: extractKey(key)! } }) } @@ -147,18 +137,14 @@ export const extractDeviceJids = ( myLid: string, excludeZeroDevices: boolean ) => { - const myJidDecoded = jidDecode(myJid) - if (!myJidDecoded) return [] - - const { user: myUser, device: myDevice } = myJidDecoded + const { user: myUser, device: myDevice } = jidDecode(myJid)! const extracted: FullJid[] = [] for (const userResult of result) { const { devices, id } = userResult as { devices: ParsedDeviceInfo; id: string } - const decoded = jidDecode(id) - if (!decoded) continue - const { user, server } = decoded + const decoded = jidDecode(id)!, + { user, server } = decoded let { domainType } = decoded const deviceList = devices?.deviceList as DeviceListData[] if (!Array.isArray(deviceList)) continue