Signal, messages-recv, jid-utils: Handle ADJIDs properly in Signal
This commit is contained in:
@@ -5,7 +5,7 @@ import type { LIDMapping, SignalAuthState, SignalKeyStoreWithTransaction } from
|
|||||||
import type { SignalRepositoryWithLIDStore } from '../Types/Signal'
|
import type { SignalRepositoryWithLIDStore } from '../Types/Signal'
|
||||||
import { generateSignalPubKey } from '../Utils'
|
import { generateSignalPubKey } from '../Utils'
|
||||||
import type { ILogger } from '../Utils/logger'
|
import type { ILogger } from '../Utils/logger'
|
||||||
import { jidDecode, transferDevice } from '../WABinary'
|
import { jidDecode, transferDevice, WAJIDDomains } from '../WABinary'
|
||||||
import type { SenderKeyStore } from './Group/group_cipher'
|
import type { SenderKeyStore } from './Group/group_cipher'
|
||||||
import { SenderKeyName } from './Group/sender-key-name'
|
import { SenderKeyName } from './Group/sender-key-name'
|
||||||
import { SenderKeyRecord } from './Group/sender-key-record'
|
import { SenderKeyRecord } from './Group/sender-key-record'
|
||||||
@@ -321,7 +321,7 @@ export function makeLibSignalRepository(
|
|||||||
|
|
||||||
const jidToSignalProtocolAddress = (jid: string): libsignal.ProtocolAddress => {
|
const jidToSignalProtocolAddress = (jid: string): libsignal.ProtocolAddress => {
|
||||||
const decoded = jidDecode(jid)!
|
const decoded = jidDecode(jid)!
|
||||||
const { user, device, server } = decoded
|
const { user, device, server, domainType } = decoded
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
@@ -329,8 +329,7 @@ const jidToSignalProtocolAddress = (jid: string): libsignal.ProtocolAddress => {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// LID addresses get _1 suffix for Signal protocol
|
let signalUser = domainType !== WAJIDDomains.WHATSAPP ? `${user}_${domainType}`: user;
|
||||||
const signalUser = server === 'lid' ? `${user}_1` : user
|
|
||||||
const finalDevice = device || 0
|
const finalDevice = device || 0
|
||||||
|
|
||||||
return new libsignal.ProtocolAddress(signalUser, finalDevice)
|
return new libsignal.ProtocolAddress(signalUser, finalDevice)
|
||||||
|
|||||||
@@ -476,7 +476,9 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
|||||||
count: retryCount.toString(),
|
count: retryCount.toString(),
|
||||||
id: node.attrs.id!,
|
id: node.attrs.id!,
|
||||||
t: node.attrs.t!,
|
t: node.attrs.t!,
|
||||||
v: '1'
|
v: '1',
|
||||||
|
// ADD ERROR FIELD
|
||||||
|
error: '0'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ export const jidDecode = (jid: string | undefined): FullJid | undefined => {
|
|||||||
const userCombined = jid!.slice(0, sepIdx)
|
const userCombined = jid!.slice(0, sepIdx)
|
||||||
|
|
||||||
const [userAgent, device] = userCombined.split(':')
|
const [userAgent, device] = userCombined.split(':')
|
||||||
const user = userAgent!.split('_')[0]!
|
const [user, agent] = userAgent!.split('_')
|
||||||
|
|
||||||
let domainType = WAJIDDomains.WHATSAPP
|
let domainType = WAJIDDomains.WHATSAPP
|
||||||
if (server === 'lid') {
|
if (server === 'lid') {
|
||||||
@@ -58,11 +58,13 @@ export const jidDecode = (jid: string | undefined): FullJid | undefined => {
|
|||||||
domainType = WAJIDDomains.HOSTED
|
domainType = WAJIDDomains.HOSTED
|
||||||
} else if (server === 'hosted.lid') {
|
} else if (server === 'hosted.lid') {
|
||||||
domainType = WAJIDDomains.HOSTED_LID
|
domainType = WAJIDDomains.HOSTED_LID
|
||||||
|
} else if (agent) {
|
||||||
|
domainType = parseInt(agent)
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
server: server as JidServer,
|
server: server as JidServer,
|
||||||
user,
|
user: user!,
|
||||||
domainType,
|
domainType,
|
||||||
device: device ? +device : undefined
|
device: device ? +device : undefined
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user