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
This commit is contained in:
Claude
2026-02-09 03:50:36 +00:00
parent 38575fb2d8
commit e7c31f9270
+18 -32
View File
@@ -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