libsignal: Process @hosted conversions to @hosted.lid
This commit is contained in:
@@ -36,9 +36,10 @@ export class SenderKeyMessage extends CiphertextMessage {
|
|||||||
this.messageVersion = (version & 0xff) >> 4
|
this.messageVersion = (version & 0xff) >> 4
|
||||||
this.keyId = senderKeyMessage.id
|
this.keyId = senderKeyMessage.id
|
||||||
this.iteration = senderKeyMessage.iteration
|
this.iteration = senderKeyMessage.iteration
|
||||||
this.ciphertext = typeof senderKeyMessage.ciphertext === 'string'
|
this.ciphertext =
|
||||||
? Buffer.from(senderKeyMessage.ciphertext, 'base64')
|
typeof senderKeyMessage.ciphertext === 'string'
|
||||||
: senderKeyMessage.ciphertext
|
? Buffer.from(senderKeyMessage.ciphertext, 'base64')
|
||||||
|
: senderKeyMessage.ciphertext
|
||||||
this.signature = signature
|
this.signature = signature
|
||||||
} else {
|
} else {
|
||||||
const version = (((this.CURRENT_VERSION << 4) | this.CURRENT_VERSION) & 0xff) % 256
|
const version = (((this.CURRENT_VERSION << 4) | this.CURRENT_VERSION) & 0xff) % 256
|
||||||
|
|||||||
+14
-9
@@ -329,7 +329,7 @@ const jidToSignalProtocolAddress = (jid: string): libsignal.ProtocolAddress => {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
let signalUser = domainType !== WAJIDDomains.WHATSAPP ? `${user}_${domainType}`: user;
|
const signalUser = domainType !== WAJIDDomains.WHATSAPP ? `${user}_${domainType}` : user
|
||||||
const finalDevice = device || 0
|
const finalDevice = device || 0
|
||||||
|
|
||||||
return new libsignal.ProtocolAddress(signalUser, finalDevice)
|
return new libsignal.ProtocolAddress(signalUser, finalDevice)
|
||||||
@@ -344,14 +344,19 @@ function signalStorage(
|
|||||||
lidMapping: LIDMappingStore
|
lidMapping: LIDMappingStore
|
||||||
): SenderKeyStore & libsignal.SignalStorage {
|
): SenderKeyStore & libsignal.SignalStorage {
|
||||||
// Shared function to resolve PN signal address to LID if mapping exists
|
// Shared function to resolve PN signal address to LID if mapping exists
|
||||||
const resolveSignalAddress = async (id: string): Promise<string> => {
|
const resolveLIDSignalAddress = async (id: string): Promise<string> => {
|
||||||
if (id.includes('.') && !id.includes('_1')) {
|
if (id.includes('.')) {
|
||||||
const parts = id.split('.')
|
const [deviceId, domainType_] = id.split('_')
|
||||||
const device = parts[1] || '0'
|
const domainType = parseInt(domainType_ || '0')
|
||||||
const pnJid = device === '0' ? `${parts[0]}@s.whatsapp.net` : `${parts[0]}:${device}@s.whatsapp.net`
|
const [user, device] = deviceId!.split('.')
|
||||||
|
|
||||||
const lidForPN = await lidMapping.getLIDForPN(pnJid)
|
if (domainType === WAJIDDomains.LID || domainType === WAJIDDomains.HOSTED_LID) return id
|
||||||
|
|
||||||
|
const pnJid = `${user!}${device !== '0' ? `:${device}` : ''}@s.whatsapp.net`
|
||||||
|
|
||||||
|
let lidForPN = await lidMapping.getLIDForPN(pnJid)
|
||||||
if (lidForPN?.includes('@lid')) {
|
if (lidForPN?.includes('@lid')) {
|
||||||
|
if (domainType === WAJIDDomains.HOSTED) lidForPN = `${lidForPN.split('@')[0]}@hosted.lid`
|
||||||
const lidAddr = jidToSignalProtocolAddress(lidForPN)
|
const lidAddr = jidToSignalProtocolAddress(lidForPN)
|
||||||
return lidAddr.toString()
|
return lidAddr.toString()
|
||||||
}
|
}
|
||||||
@@ -363,7 +368,7 @@ function signalStorage(
|
|||||||
return {
|
return {
|
||||||
loadSession: async (id: string) => {
|
loadSession: async (id: string) => {
|
||||||
try {
|
try {
|
||||||
const wireJid = await resolveSignalAddress(id)
|
const wireJid = await resolveLIDSignalAddress(id)
|
||||||
const { [wireJid]: sess } = await keys.get('session', [wireJid])
|
const { [wireJid]: sess } = await keys.get('session', [wireJid])
|
||||||
|
|
||||||
if (sess) {
|
if (sess) {
|
||||||
@@ -376,7 +381,7 @@ function signalStorage(
|
|||||||
return null
|
return null
|
||||||
},
|
},
|
||||||
storeSession: async (id: string, session: libsignal.SessionRecord) => {
|
storeSession: async (id: string, session: libsignal.SessionRecord) => {
|
||||||
const wireJid = await resolveSignalAddress(id)
|
const wireJid = await resolveLIDSignalAddress(id)
|
||||||
await keys.set({ session: { [wireJid]: session.serialize() } })
|
await keys.set({ session: { [wireJid]: session.serialize() } })
|
||||||
},
|
},
|
||||||
isTrustedIdentity: () => {
|
isTrustedIdentity: () => {
|
||||||
|
|||||||
@@ -448,7 +448,9 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
|||||||
messageRetryManager.schedulePhoneRequest(msgId, async () => {
|
messageRetryManager.schedulePhoneRequest(msgId, async () => {
|
||||||
try {
|
try {
|
||||||
const requestId = await requestPlaceholderResend(msgKey)
|
const requestId = await requestPlaceholderResend(msgKey)
|
||||||
logger.debug(`sendRetryRequest: requested placeholder resend (${requestId}) for message ${msgId} (scheduled)`)
|
logger.debug(
|
||||||
|
`sendRetryRequest: requested placeholder resend (${requestId}) for message ${msgId} (scheduled)`
|
||||||
|
)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.warn({ error, msgId }, 'failed to send scheduled phone request')
|
logger.warn({ error, msgId }, 'failed to send scheduled phone request')
|
||||||
}
|
}
|
||||||
@@ -478,7 +480,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
|||||||
t: node.attrs.t!,
|
t: node.attrs.t!,
|
||||||
v: '1',
|
v: '1',
|
||||||
// ADD ERROR FIELD
|
// ADD ERROR FIELD
|
||||||
error: '0'
|
error: '0'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user