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:
+18
-32
@@ -88,18 +88,14 @@ export const xmppPreKey = (pair: KeyPair, id: number): BinaryNode => ({
|
|||||||
})
|
})
|
||||||
|
|
||||||
export const parseAndInjectE2ESessions = async (node: BinaryNode, repository: SignalRepositoryWithLIDStore) => {
|
export const parseAndInjectE2ESessions = async (node: BinaryNode, repository: SignalRepositoryWithLIDStore) => {
|
||||||
const extractKey = (key: BinaryNode) => {
|
const extractKey = (key: BinaryNode) =>
|
||||||
if (!key) return undefined
|
key
|
||||||
const keyId = getBinaryNodeChildUInt(key, 'id', 3)
|
? {
|
||||||
const publicKeyBuf = getBinaryNodeChildBuffer(key, 'value')
|
keyId: getBinaryNodeChildUInt(key, 'id', 3)!,
|
||||||
const signature = getBinaryNodeChildBuffer(key, 'signature')
|
publicKey: generateSignalPubKey(getBinaryNodeChildBuffer(key, 'value')!),
|
||||||
if (keyId === undefined || !publicKeyBuf || !signature) return undefined
|
signature: getBinaryNodeChildBuffer(key, 'signature')!
|
||||||
return {
|
}
|
||||||
keyId,
|
: undefined
|
||||||
publicKey: generateSignalPubKey(publicKeyBuf),
|
|
||||||
signature
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const nodes = getBinaryNodeChildren(getBinaryNodeChild(node, 'list'), 'user')
|
const nodes = getBinaryNodeChildren(getBinaryNodeChild(node, 'list'), 'user')
|
||||||
for (const node of nodes) {
|
for (const node of nodes) {
|
||||||
assertNodeErrorFree(node)
|
assertNodeErrorFree(node)
|
||||||
@@ -115,26 +111,20 @@ export const parseAndInjectE2ESessions = async (node: BinaryNode, repository: Si
|
|||||||
|
|
||||||
for (const nodesChunk of chunks) {
|
for (const nodesChunk of chunks) {
|
||||||
for (const node of nodesChunk) {
|
for (const node of nodesChunk) {
|
||||||
const signedKey = getBinaryNodeChild(node, 'skey')
|
const signedKey = getBinaryNodeChild(node, 'skey')!
|
||||||
const key = getBinaryNodeChild(node, 'key')
|
const key = getBinaryNodeChild(node, 'key')!
|
||||||
const identity = getBinaryNodeChildBuffer(node, 'identity')
|
const identity = getBinaryNodeChildBuffer(node, 'identity')!
|
||||||
const jid = node.attrs.jid
|
const jid = node.attrs.jid!
|
||||||
if (!signedKey || !key || !identity || !jid) continue
|
|
||||||
|
|
||||||
const registrationId = getBinaryNodeChildUInt(node, 'registration', 4)
|
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({
|
await repository.injectE2ESession({
|
||||||
jid,
|
jid,
|
||||||
session: {
|
session: {
|
||||||
registrationId,
|
registrationId: registrationId!,
|
||||||
identityKey: generateSignalPubKey(identity),
|
identityKey: generateSignalPubKey(identity),
|
||||||
signedPreKey,
|
signedPreKey: extractKey(signedKey)!,
|
||||||
preKey
|
preKey: extractKey(key)!
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -147,18 +137,14 @@ export const extractDeviceJids = (
|
|||||||
myLid: string,
|
myLid: string,
|
||||||
excludeZeroDevices: boolean
|
excludeZeroDevices: boolean
|
||||||
) => {
|
) => {
|
||||||
const myJidDecoded = jidDecode(myJid)
|
const { user: myUser, device: myDevice } = jidDecode(myJid)!
|
||||||
if (!myJidDecoded) return []
|
|
||||||
|
|
||||||
const { user: myUser, device: myDevice } = myJidDecoded
|
|
||||||
|
|
||||||
const extracted: FullJid[] = []
|
const extracted: FullJid[] = []
|
||||||
|
|
||||||
for (const userResult of result) {
|
for (const userResult of result) {
|
||||||
const { devices, id } = userResult as { devices: ParsedDeviceInfo; id: string }
|
const { devices, id } = userResult as { devices: ParsedDeviceInfo; id: string }
|
||||||
const decoded = jidDecode(id)
|
const decoded = jidDecode(id)!,
|
||||||
if (!decoded) continue
|
{ user, server } = decoded
|
||||||
const { user, server } = decoded
|
|
||||||
let { domainType } = decoded
|
let { domainType } = decoded
|
||||||
const deviceList = devices?.deviceList as DeviceListData[]
|
const deviceList = devices?.deviceList as DeviceListData[]
|
||||||
if (!Array.isArray(deviceList)) continue
|
if (!Array.isArray(deviceList)) continue
|
||||||
|
|||||||
Reference in New Issue
Block a user