@badzz88/baileys 8.5.7 → 8.5.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +337 -1055
- package/WAProto/WAProto.proto +284 -264
- package/WAProto/index.js +5 -5
- package/engine-requirements.js +7 -15
- package/lib/Defaults/index.js +130 -187
- package/lib/Signal/Group/ciphertext-message.js +11 -14
- package/lib/Signal/Group/group-session-builder.js +29 -91
- package/lib/Signal/Group/group_cipher.js +81 -88
- package/lib/Signal/Group/index.js +12 -136
- package/lib/Signal/Group/keyhelper.js +15 -70
- package/lib/Signal/Group/sender-chain-key.js +25 -31
- package/lib/Signal/Group/sender-key-distribution-message.js +62 -65
- package/lib/Signal/Group/sender-key-message.js +65 -68
- package/lib/Signal/Group/sender-key-name.js +41 -43
- package/lib/Signal/Group/sender-key-record.js +40 -43
- package/lib/Signal/Group/sender-key-state.js +83 -96
- package/lib/Signal/Group/sender-message-key.js +25 -29
- package/lib/Signal/libsignal.js +425 -453
- package/lib/Signal/lid-mapping.js +276 -259
- package/lib/Socket/Client/index.js +3 -30
- package/lib/Socket/Client/types.js +10 -12
- package/lib/Socket/Client/websocket.js +53 -61
- package/lib/Socket/business.js +379 -422
- package/lib/Socket/chats.js +1193 -1816
- package/lib/Socket/communities.js +431 -549
- package/lib/Socket/graphql.js +672 -612
- package/lib/Socket/groups.js +374 -764
- package/lib/Socket/index.js +17 -38
- package/lib/Socket/interop.js +417 -503
- package/lib/Socket/messages-recv.js +1915 -2441
- package/lib/Socket/messages-send.js +1213 -1630
- package/lib/Socket/mex.js +9 -15
- package/lib/Socket/newsletter.js +746 -808
- package/lib/Socket/privacy.js +310 -441
- package/lib/Socket/socket.js +1025 -1022
- package/lib/Socket/username.js +8 -15
- package/lib/Store/index.js +10 -36
- package/lib/Store/make-cache-manager-store.js +80 -85
- package/lib/Store/make-in-memory-store.js +231 -591
- package/lib/Store/make-ordered-dictionary.js +72 -78
- package/lib/Store/object-repository.js +28 -25
- package/lib/Types/Auth.js +2 -38
- package/lib/Types/Bussines.js +2 -2
- package/lib/Types/Call.js +2 -2
- package/lib/Types/Chat.js +8 -4
- package/lib/Types/Contact.js +2 -2
- package/lib/Types/Events.js +2 -2
- package/lib/Types/GroupMetadata.js +2 -2
- package/lib/Types/Label.js +24 -26
- package/lib/Types/LabelAssociation.js +6 -8
- package/lib/Types/Message.js +11 -95
- package/lib/Types/Mex.js +111 -112
- package/lib/Types/Product.js +2 -2
- package/lib/Types/Signal.js +2 -2
- package/lib/Types/Socket.js +3 -2
- package/lib/Types/State.js +56 -70
- package/lib/Types/USync.js +2 -2
- package/lib/Types/index.js +26 -55
- package/lib/Utils/auth-utils.js +288 -292
- package/lib/Utils/browser-utils.js +47 -113
- package/lib/Utils/business.js +224 -240
- package/lib/Utils/chat-utils.js +869 -1205
- package/lib/Utils/companion-reg-client-utils.js +34 -41
- package/lib/Utils/crypto.js +107 -144
- package/lib/Utils/decode-wa-message.js +308 -518
- package/lib/Utils/event-buffer.js +611 -596
- package/lib/Utils/generics.js +355 -515
- package/lib/Utils/history.js +134 -244
- package/lib/Utils/identity-change-handler.js +49 -51
- package/lib/Utils/index.js +23 -57
- package/lib/Utils/link-preview.js +77 -135
- package/lib/Utils/logger.js +3 -9
- package/lib/Utils/lt-hash.js +6 -37
- package/lib/Utils/make-mutex.js +33 -36
- package/lib/Utils/message-composer.js +233 -439
- package/lib/Utils/message-retry-manager.js +260 -265
- package/lib/Utils/messages-media.js +829 -855
- package/lib/Utils/messages.js +961 -2528
- package/lib/Utils/noise-handler.js +200 -195
- package/lib/Utils/offline-node-processor.js +33 -35
- package/lib/Utils/pre-key-manager.js +102 -103
- package/lib/Utils/process-message.js +560 -978
- package/lib/Utils/reporting-utils.js +253 -257
- package/lib/Utils/signal.js +195 -218
- package/lib/Utils/stanza-ack.js +29 -31
- package/lib/Utils/sticker.js +109 -144
- package/lib/Utils/sync-action-utils.js +45 -50
- package/lib/Utils/tc-token-utils.js +139 -137
- package/lib/Utils/use-multi-file-auth-state.js +109 -109
- package/lib/Utils/validate-connection.js +202 -218
- package/lib/WABinary/constants.js +1299 -1302
- package/lib/WABinary/decode.js +262 -343
- package/lib/WABinary/encode.js +4 -12
- package/lib/WABinary/generic-utils.js +187 -223
- package/lib/WABinary/index.js +6 -33
- package/lib/WABinary/jid-utils.js +88 -351
- package/lib/WABinary/types.js +2 -2
- package/lib/WAM/BinaryInfo.js +9 -12
- package/lib/WAM/constants.js +22853 -39486
- package/lib/WAM/encode.js +140 -132
- package/lib/WAM/index.js +4 -31
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +21 -23
- package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +9 -9
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +7 -7
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +10 -10
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +7 -7
- package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +11 -12
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +4 -5
- package/lib/WAUSync/Protocols/USyncPictureProtocol.js +7 -7
- package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +7 -8
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +7 -7
- package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +8 -8
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +7 -7
- package/lib/WAUSync/Protocols/index.js +12 -39
- package/lib/WAUSync/USyncQuery.js +67 -49
- package/lib/WAUSync/USyncUser.js +11 -5
- package/lib/WAUSync/index.js +3 -31
- package/lib/index.js +15 -48
- package/package.json +129 -99
- package/LICENSE +0 -21
- package/lib/Defaults/phonenumber-mcc.json +0 -223
- package/lib/Socket/aigroups.js +0 -240
- package/lib/Socket/interactive-handler.js +0 -522
- package/lib/Socket/managed-account.js +0 -183
- package/lib/Socket/registration.js +0 -427
- package/lib/Socket/text-router.js +0 -83
- package/lib/Types/Newsletter.js +0 -121
- package/lib/Utils/command-loader.d.ts +0 -31
- package/lib/Utils/command-loader.js +0 -100
- package/lib/Utils/consumer-application.js +0 -107
- package/lib/Utils/curve25519-js.js +0 -275
- package/lib/Utils/group-history.js +0 -60
- package/lib/Utils/jid-display-normalization.js +0 -218
- package/lib/Utils/meta-ai-msmsg.js +0 -262
- package/lib/Utils/native-bridge.js +0 -82
- package/lib/Utils/session-pool.d.ts +0 -16
- package/lib/Utils/session-pool.js +0 -94
- package/lib/Utils/sticker.d.ts +0 -17
- package/lib/Utils/view-once-cache.d.ts +0 -9
- package/lib/Utils/view-once-cache.js +0 -79
- package/lib/Utils/voip-rekey.js +0 -22
- package/lib/antiban.js +0 -4637
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true })
|
|
4
|
-
exports.normalizeMessageForDisplayJids = void 0
|
|
5
|
-
exports.normalizeMentionedJidsForSend = void 0
|
|
6
|
-
|
|
7
|
-
const WABinary_1 = require('../WABinary')
|
|
8
|
-
|
|
9
|
-
const createLidPnDebug = logger => {
|
|
10
|
-
const enabled = process.env.LID_PN_DEBUG === '1' || process.env.LID_PN_DEBUG === 'true'
|
|
11
|
-
return (phase, payload) => {
|
|
12
|
-
if (!enabled) {
|
|
13
|
-
return
|
|
14
|
-
}
|
|
15
|
-
logger?.debug({ ...payload, phase }, 'lid->pn normalization trace')
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const fallbackPnFromLidJid = jid => {
|
|
20
|
-
const decoded = (0, WABinary_1.jidDecode)(jid)
|
|
21
|
-
const rawUser = decoded?.user || (typeof jid === 'string' ? jid.split('@')[0] : '')
|
|
22
|
-
const user = rawUser.split(':')[0]
|
|
23
|
-
if (!user) {
|
|
24
|
-
return jid
|
|
25
|
-
}
|
|
26
|
-
return `${user}@s.whatsapp.net`
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const toDisplayPnJid = jid => {
|
|
30
|
-
if (!jid || typeof jid !== 'string') {
|
|
31
|
-
return jid
|
|
32
|
-
}
|
|
33
|
-
const decoded = (0, WABinary_1.jidDecode)(jid)
|
|
34
|
-
if (!decoded?.user) {
|
|
35
|
-
return jid
|
|
36
|
-
}
|
|
37
|
-
if (!(0, WABinary_1.isPnUser)(jid) && !(0, WABinary_1.isHostedPnUser)(jid)) {
|
|
38
|
-
return jid
|
|
39
|
-
}
|
|
40
|
-
const user = decoded.user.split(':')[0]
|
|
41
|
-
if (!user) {
|
|
42
|
-
return jid
|
|
43
|
-
}
|
|
44
|
-
const server = decoded.server === 'hosted' ? 'hosted' : 's.whatsapp.net'
|
|
45
|
-
return `${user}@${server}`
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const buildLidPnHints = key => {
|
|
49
|
-
const hints = new Map()
|
|
50
|
-
if (!key) {
|
|
51
|
-
return hints
|
|
52
|
-
}
|
|
53
|
-
const addHint = (lid, pn) => {
|
|
54
|
-
if (!(0, WABinary_1.isLidUser)(lid) && !(0, WABinary_1.isHostedLidUser)(lid)) {
|
|
55
|
-
return
|
|
56
|
-
}
|
|
57
|
-
if (!(0, WABinary_1.isPnUser)(pn) && !(0, WABinary_1.isHostedPnUser)(pn)) {
|
|
58
|
-
return
|
|
59
|
-
}
|
|
60
|
-
hints.set(lid, pn)
|
|
61
|
-
const lidDecoded = (0, WABinary_1.jidDecode)(lid)
|
|
62
|
-
const pnDecoded = (0, WABinary_1.jidDecode)(pn)
|
|
63
|
-
if (lidDecoded?.user && pnDecoded?.user) {
|
|
64
|
-
hints.set(`${lidDecoded.user}@lid`, `${pnDecoded.user}@s.whatsapp.net`)
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
addHint(key.participant, key.participantAlt)
|
|
68
|
-
addHint(key.remoteJid, key.remoteJidAlt)
|
|
69
|
-
addHint(key.participantAlt, key.participant)
|
|
70
|
-
addHint(key.remoteJidAlt, key.remoteJid)
|
|
71
|
-
return hints
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const mergeGroupDataHints = (hints, groupData, debug) => {
|
|
75
|
-
if (!groupData?.participants?.length) {
|
|
76
|
-
return
|
|
77
|
-
}
|
|
78
|
-
debug?.('groupData-size', { participants: groupData.participants.length })
|
|
79
|
-
for (const participant of groupData.participants) {
|
|
80
|
-
const lidCandidate = participant?.lid
|
|
81
|
-
const idCandidate = participant?.id
|
|
82
|
-
const pnCandidate = participant?.phoneNumber
|
|
83
|
-
const lid =
|
|
84
|
-
((0, WABinary_1.isLidUser)(lidCandidate) || (0, WABinary_1.isHostedLidUser)(lidCandidate)
|
|
85
|
-
? lidCandidate
|
|
86
|
-
: undefined) ||
|
|
87
|
-
((0, WABinary_1.isLidUser)(idCandidate) || (0, WABinary_1.isHostedLidUser)(idCandidate) ? idCandidate : undefined)
|
|
88
|
-
const pn =
|
|
89
|
-
((0, WABinary_1.isPnUser)(pnCandidate) || (0, WABinary_1.isHostedPnUser)(pnCandidate)
|
|
90
|
-
? pnCandidate
|
|
91
|
-
: undefined) ||
|
|
92
|
-
((0, WABinary_1.isPnUser)(idCandidate) || (0, WABinary_1.isHostedPnUser)(idCandidate) ? idCandidate : undefined)
|
|
93
|
-
if (!lid || !pn) {
|
|
94
|
-
continue
|
|
95
|
-
}
|
|
96
|
-
if (
|
|
97
|
-
((0, WABinary_1.isLidUser)(lid) || (0, WABinary_1.isHostedLidUser)(lid)) &&
|
|
98
|
-
((0, WABinary_1.isPnUser)(pn) || (0, WABinary_1.isHostedPnUser)(pn))
|
|
99
|
-
) {
|
|
100
|
-
const displayPn = toDisplayPnJid(pn)
|
|
101
|
-
hints.set(lid, displayPn)
|
|
102
|
-
const lidDecoded = (0, WABinary_1.jidDecode)(lid)
|
|
103
|
-
if (lidDecoded?.user) {
|
|
104
|
-
hints.set(`${lidDecoded.user}@lid`, displayPn)
|
|
105
|
-
}
|
|
106
|
-
debug?.('group-hint', { lid, pn: displayPn })
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
const normalizeToPnJid = async (jid, hints, signalRepository, debug) => {
|
|
112
|
-
if (!jid || typeof jid !== 'string') {
|
|
113
|
-
return jid
|
|
114
|
-
}
|
|
115
|
-
if (!(0, WABinary_1.isLidUser)(jid) && !(0, WABinary_1.isHostedLidUser)(jid)) {
|
|
116
|
-
return jid
|
|
117
|
-
}
|
|
118
|
-
debug?.('input', { lid: jid })
|
|
119
|
-
const hinted = hints.get(jid)
|
|
120
|
-
if (hinted) {
|
|
121
|
-
const normalized = toDisplayPnJid(hinted)
|
|
122
|
-
debug?.('hint-exact', { lid: jid, hinted, normalized })
|
|
123
|
-
return normalized
|
|
124
|
-
}
|
|
125
|
-
const decoded = (0, WABinary_1.jidDecode)(jid)
|
|
126
|
-
if (decoded?.user) {
|
|
127
|
-
const userHint = hints.get(`${decoded.user}@lid`)
|
|
128
|
-
if (userHint) {
|
|
129
|
-
const normalized = toDisplayPnJid(userHint)
|
|
130
|
-
debug?.('hint-user', { lid: jid, userHint, normalized })
|
|
131
|
-
return normalized
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
const mapped = await signalRepository?.lidMapping?.getPNForLID?.(jid)
|
|
135
|
-
if (mapped) {
|
|
136
|
-
const normalized = toDisplayPnJid(mapped)
|
|
137
|
-
debug?.('mapping', { lid: jid, mapped, normalized })
|
|
138
|
-
return normalized
|
|
139
|
-
}
|
|
140
|
-
const fallback = fallbackPnFromLidJid(jid)
|
|
141
|
-
debug?.('fallback', { lid: jid, fallback })
|
|
142
|
-
return fallback
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
const normalizeMentionedJidsToPn = async (node, hints, signalRepository, debug) => {
|
|
146
|
-
if (!node || typeof node !== 'object') {
|
|
147
|
-
return
|
|
148
|
-
}
|
|
149
|
-
if (Array.isArray(node)) {
|
|
150
|
-
for (const item of node) {
|
|
151
|
-
await normalizeMentionedJidsToPn(item, hints, signalRepository, debug)
|
|
152
|
-
}
|
|
153
|
-
return
|
|
154
|
-
}
|
|
155
|
-
if (Array.isArray(node.mentionedJid)) {
|
|
156
|
-
const before = [...node.mentionedJid]
|
|
157
|
-
node.mentionedJid = await Promise.all(
|
|
158
|
-
node.mentionedJid.map(jid => normalizeToPnJid(jid, hints, signalRepository, debug))
|
|
159
|
-
)
|
|
160
|
-
debug?.('mentions', { before, after: node.mentionedJid })
|
|
161
|
-
}
|
|
162
|
-
if (typeof node.participant === 'string') {
|
|
163
|
-
const before = node.participant
|
|
164
|
-
node.participant = await normalizeToPnJid(node.participant, hints, signalRepository, debug)
|
|
165
|
-
if (before !== node.participant) {
|
|
166
|
-
debug?.('participant-field', { before, after: node.participant })
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
if (typeof node.remoteJid === 'string') {
|
|
170
|
-
const before = node.remoteJid
|
|
171
|
-
node.remoteJid = await normalizeToPnJid(node.remoteJid, hints, signalRepository, debug)
|
|
172
|
-
if (before !== node.remoteJid) {
|
|
173
|
-
debug?.('remoteJid-field', { before, after: node.remoteJid })
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
for (const value of Object.values(node)) {
|
|
177
|
-
if (value && typeof value === 'object') {
|
|
178
|
-
await normalizeMentionedJidsToPn(value, hints, signalRepository, debug)
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
const normalizeMentionedJidsForSend = async (mentions, groupData, signalRepository, logger) => {
|
|
184
|
-
if (!Array.isArray(mentions)) {
|
|
185
|
-
return mentions
|
|
186
|
-
}
|
|
187
|
-
const debug = createLidPnDebug(logger)
|
|
188
|
-
const hints = new Map()
|
|
189
|
-
mergeGroupDataHints(hints, groupData, debug)
|
|
190
|
-
const normalized = await Promise.all(mentions.map(jid => normalizeToPnJid(jid, hints, signalRepository, debug)))
|
|
191
|
-
debug('send-mentions-result', { before: mentions, after: normalized })
|
|
192
|
-
return normalized
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
const normalizeMessageForDisplayJids = async (messageInfo, signalRepository, logger, groupData) => {
|
|
196
|
-
if (!messageInfo?.key) {
|
|
197
|
-
return messageInfo
|
|
198
|
-
}
|
|
199
|
-
const debug = createLidPnDebug(logger)
|
|
200
|
-
const hints = buildLidPnHints(messageInfo.key)
|
|
201
|
-
mergeGroupDataHints(hints, groupData, debug)
|
|
202
|
-
const beforeKey = { ...messageInfo.key }
|
|
203
|
-
messageInfo.key.participant = await normalizeToPnJid(messageInfo.key.participant, hints, signalRepository, debug)
|
|
204
|
-
messageInfo.key.participantAlt = await normalizeToPnJid(
|
|
205
|
-
messageInfo.key.participantAlt,
|
|
206
|
-
hints,
|
|
207
|
-
signalRepository,
|
|
208
|
-
debug
|
|
209
|
-
)
|
|
210
|
-
messageInfo.key.remoteJid = await normalizeToPnJid(messageInfo.key.remoteJid, hints, signalRepository, debug)
|
|
211
|
-
messageInfo.key.remoteJidAlt = await normalizeToPnJid(messageInfo.key.remoteJidAlt, hints, signalRepository, debug)
|
|
212
|
-
await normalizeMentionedJidsToPn(messageInfo.message, hints, signalRepository, debug)
|
|
213
|
-
debug('display-key-result', { before: beforeKey, after: messageInfo.key })
|
|
214
|
-
return messageInfo
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
exports.normalizeMessageForDisplayJids = normalizeMessageForDisplayJids
|
|
218
|
-
exports.normalizeMentionedJidsForSend = normalizeMentionedJidsForSend
|
|
@@ -1,262 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const Crypto_1 = require('./crypto')
|
|
4
|
-
const { proto } = require('../../WAProto')
|
|
5
|
-
|
|
6
|
-
const BOT_MESSAGE_INFO = 'Bot Message'
|
|
7
|
-
const KEY_LENGTH = 32
|
|
8
|
-
const AUTH_TAG_LENGTH = 16
|
|
9
|
-
|
|
10
|
-
const MSG_ID_HEX_RE = /^[0-9A-Fa-f]{32}$/
|
|
11
|
-
|
|
12
|
-
const unpadRandomMax16 = value => {
|
|
13
|
-
const bytes = new Uint8Array(value)
|
|
14
|
-
if (!bytes.length) {
|
|
15
|
-
throw new Error('unpadPkcs7 given empty bytes')
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const padLength = bytes[bytes.length - 1]
|
|
19
|
-
if (padLength > bytes.length) {
|
|
20
|
-
throw new Error(`unpad given ${bytes.length} bytes, but pad is ${padLength}`)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return new Uint8Array(bytes.buffer, bytes.byteOffset, bytes.length - padLength)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const toBuffer = value => {
|
|
27
|
-
if (Buffer.isBuffer(value)) {
|
|
28
|
-
return value
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (value instanceof Uint8Array) {
|
|
32
|
-
return Buffer.from(value.buffer, value.byteOffset, value.byteLength)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return Buffer.from(value)
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const normalizeLidJid = jid => {
|
|
39
|
-
if (!jid || !jid.endsWith('@lid') || !jid.includes(':')) {
|
|
40
|
-
return jid
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return `${jid.split(':')[0]}@lid`
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const buildMessageIdRepresentations = messageId => {
|
|
47
|
-
const ascii = Buffer.from(messageId)
|
|
48
|
-
const binary = MSG_ID_HEX_RE.test(messageId) ? Buffer.from(messageId, 'hex') : ascii
|
|
49
|
-
return [
|
|
50
|
-
{ label: 'msgIdAscii', value: ascii },
|
|
51
|
-
...(binary.equals(ascii) ? [] : [{ label: 'msgIdBinary', value: binary }])
|
|
52
|
-
]
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const pushUnique = (items, seen, item) => {
|
|
56
|
-
const key = JSON.stringify([
|
|
57
|
-
item.messageId,
|
|
58
|
-
item.idSource,
|
|
59
|
-
item.idSources,
|
|
60
|
-
item.infoSource,
|
|
61
|
-
item.aadSource,
|
|
62
|
-
item.info.toString('hex'),
|
|
63
|
-
item.aad.toString('hex')
|
|
64
|
-
])
|
|
65
|
-
|
|
66
|
-
if (!seen.has(key)) {
|
|
67
|
-
seen.add(key)
|
|
68
|
-
items.push(item)
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const getCandidateIds = messageKey => {
|
|
73
|
-
const orderedCandidates = [
|
|
74
|
-
messageKey?.botType === 'full'
|
|
75
|
-
? { source: 'stanzaId', messageId: messageKey?.stanzaId }
|
|
76
|
-
: { source: 'botEditTargetId', messageId: messageKey?.botEditTargetId },
|
|
77
|
-
{ source: 'targetId', messageId: messageKey?.targetId },
|
|
78
|
-
{ source: 'metaTargetId', messageId: messageKey?.metaTargetId },
|
|
79
|
-
{ source: 'stanzaId', messageId: messageKey?.stanzaId }
|
|
80
|
-
]
|
|
81
|
-
|
|
82
|
-
const targetIdCandidates = Array.isArray(messageKey?.targetIdCandidates) ? messageKey.targetIdCandidates : []
|
|
83
|
-
for (let index = 0; index < targetIdCandidates.length; index += 1) {
|
|
84
|
-
orderedCandidates.push({
|
|
85
|
-
source: `targetIdCandidates[${index}]`,
|
|
86
|
-
messageId: targetIdCandidates[index]
|
|
87
|
-
})
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const grouped = new Map()
|
|
91
|
-
for (const candidate of orderedCandidates) {
|
|
92
|
-
if (!candidate.messageId) {
|
|
93
|
-
continue
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const messageId = String(candidate.messageId)
|
|
97
|
-
const existing = grouped.get(messageId)
|
|
98
|
-
if (existing) {
|
|
99
|
-
if (!existing.idSources.includes(candidate.source)) {
|
|
100
|
-
existing.idSources.push(candidate.source)
|
|
101
|
-
}
|
|
102
|
-
} else {
|
|
103
|
-
grouped.set(messageId, {
|
|
104
|
-
messageId,
|
|
105
|
-
idSource: candidate.source,
|
|
106
|
-
idSources: [candidate.source]
|
|
107
|
-
})
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return Array.from(grouped.values())
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const getJidCandidates = messageKey => {
|
|
115
|
-
const ordered = [
|
|
116
|
-
{ source: 'meId', jid: messageKey?.meId },
|
|
117
|
-
{ source: 'conversationJid', jid: messageKey?.conversationJid },
|
|
118
|
-
{ source: 'senderJid', jid: messageKey?.senderJid },
|
|
119
|
-
{ source: 'meLidNormalized', jid: normalizeLidJid(messageKey?.meLid) }
|
|
120
|
-
]
|
|
121
|
-
|
|
122
|
-
const seen = new Set()
|
|
123
|
-
const candidates = []
|
|
124
|
-
for (const candidate of ordered) {
|
|
125
|
-
if (!candidate.jid) {
|
|
126
|
-
continue
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const jid = String(candidate.jid)
|
|
130
|
-
if (!seen.has(jid)) {
|
|
131
|
-
seen.add(jid)
|
|
132
|
-
candidates.push({ source: candidate.source, jid, value: Buffer.from(jid) })
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
return candidates
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
const buildMsmsgDecryptionStrategies = messageKey => {
|
|
140
|
-
const botJid = String(messageKey?.participant || '')
|
|
141
|
-
const botJidBuffer = Buffer.from(botJid)
|
|
142
|
-
const targetIds = getCandidateIds(messageKey)
|
|
143
|
-
const jidCandidates = getJidCandidates(messageKey)
|
|
144
|
-
const primaryJid = jidCandidates[0]
|
|
145
|
-
const alternateJid = jidCandidates.find(
|
|
146
|
-
candidate => candidate.source !== primaryJid?.source && candidate.jid !== botJid
|
|
147
|
-
)
|
|
148
|
-
const strategies = []
|
|
149
|
-
const seen = new Set()
|
|
150
|
-
|
|
151
|
-
for (const idCandidate of targetIds) {
|
|
152
|
-
const idForms = buildMessageIdRepresentations(idCandidate.messageId)
|
|
153
|
-
for (const idForm of idForms) {
|
|
154
|
-
pushUnique(strategies, seen, {
|
|
155
|
-
mode: '2step',
|
|
156
|
-
idSource: idCandidate.idSource,
|
|
157
|
-
idSources: idCandidate.idSources,
|
|
158
|
-
infoSource: `${idForm.label}+meId+botJid`,
|
|
159
|
-
aadSource: `${idForm.label}+0+botJid`,
|
|
160
|
-
authTagLayout: 'trailing',
|
|
161
|
-
messageId: idCandidate.messageId,
|
|
162
|
-
info: Buffer.concat([idForm.value, primaryJid.value, botJidBuffer, Buffer.alloc(0)]),
|
|
163
|
-
aad: Buffer.concat([idForm.value, Buffer.from([0]), botJidBuffer]),
|
|
164
|
-
attemptLabel: `${idCandidate.idSource}:${idForm.label}:primary`
|
|
165
|
-
})
|
|
166
|
-
|
|
167
|
-
if (alternateJid) {
|
|
168
|
-
pushUnique(strategies, seen, {
|
|
169
|
-
mode: '2step',
|
|
170
|
-
idSource: idCandidate.idSource,
|
|
171
|
-
idSources: idCandidate.idSources,
|
|
172
|
-
infoSource: `${idForm.label}+${alternateJid.source}+botJid`,
|
|
173
|
-
aadSource: `${idForm.label}+0+${alternateJid.source}`,
|
|
174
|
-
authTagLayout: 'trailing',
|
|
175
|
-
messageId: idCandidate.messageId,
|
|
176
|
-
info: Buffer.concat([idForm.value, alternateJid.value, botJidBuffer, Buffer.alloc(0)]),
|
|
177
|
-
aad: Buffer.concat([idForm.value, Buffer.from([0]), alternateJid.value]),
|
|
178
|
-
attemptLabel: `${idCandidate.idSource}:${idForm.label}:${alternateJid.source}`
|
|
179
|
-
})
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
return strategies.slice(0, 12)
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
const assertRequired = (value, label) => {
|
|
188
|
-
if (
|
|
189
|
-
!value ||
|
|
190
|
-
(Buffer.isBuffer(value) && value.length === 0) ||
|
|
191
|
-
(value instanceof Uint8Array && value.byteLength === 0)
|
|
192
|
-
) {
|
|
193
|
-
throw new Error(`Missing required ${label} for msmsg decryption`)
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
const decryptWithStrategy = (messageSecret, msMsg, strategy) => {
|
|
198
|
-
const baseSecret = Buffer.from(Crypto_1.hkdf(toBuffer(messageSecret), KEY_LENGTH, { info: BOT_MESSAGE_INFO }))
|
|
199
|
-
const key = Buffer.from(Crypto_1.hkdf(baseSecret, KEY_LENGTH, { info: strategy.info }))
|
|
200
|
-
const payload = toBuffer(msMsg.encPayload)
|
|
201
|
-
// ciphertext = payload without last 16 bytes (auth tag) + auth tag appended → standard GCM layout
|
|
202
|
-
const ciphertextWithTag = Buffer.concat([payload.slice(0, -AUTH_TAG_LENGTH), payload.slice(-AUTH_TAG_LENGTH)])
|
|
203
|
-
return Buffer.from(Crypto_1.aesDecryptGCM(ciphertextWithTag, key, toBuffer(msMsg.encIv), strategy.aad))
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
const decodeDecryptedMsmsgMessage = decrypted => {
|
|
207
|
-
const messageBuffer = toBuffer(decrypted)
|
|
208
|
-
|
|
209
|
-
try {
|
|
210
|
-
const unpadded = Buffer.from(unpadRandomMax16(messageBuffer))
|
|
211
|
-
const decoded = proto.Message.decode(unpadded)
|
|
212
|
-
const hasContent = Object.keys(decoded).some(key => key !== 'messageContextInfo' && decoded[key] != null)
|
|
213
|
-
if (hasContent) {
|
|
214
|
-
return decoded
|
|
215
|
-
}
|
|
216
|
-
} catch {}
|
|
217
|
-
|
|
218
|
-
return proto.Message.decode(messageBuffer)
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
const decryptMsmsgBotMessage = async (messageSecret, messageKey, msMsg) => {
|
|
222
|
-
assertRequired(messageSecret, 'messageSecret')
|
|
223
|
-
assertRequired(messageKey?.participant, 'participant')
|
|
224
|
-
assertRequired(messageKey?.meId, 'meId')
|
|
225
|
-
assertRequired(msMsg?.encIv, 'encIv')
|
|
226
|
-
assertRequired(msMsg?.encPayload, 'encPayload')
|
|
227
|
-
if (getCandidateIds(messageKey).length === 0) {
|
|
228
|
-
throw new Error('Missing required target message id for msmsg decryption')
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
const strategies = buildMsmsgDecryptionStrategies(messageKey)
|
|
232
|
-
const attemptedStrategies = []
|
|
233
|
-
let lastError
|
|
234
|
-
|
|
235
|
-
for (const strategy of strategies) {
|
|
236
|
-
const attempt = {
|
|
237
|
-
idSource: strategy.idSource,
|
|
238
|
-
idSources: strategy.idSources,
|
|
239
|
-
infoSource: strategy.infoSource,
|
|
240
|
-
aadSource: strategy.aadSource,
|
|
241
|
-
messageId: strategy.messageId
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
try {
|
|
245
|
-
return await decryptWithStrategy(messageSecret, msMsg, strategy)
|
|
246
|
-
} catch (error) {
|
|
247
|
-
attemptedStrategies.push(attempt)
|
|
248
|
-
lastError = error
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
const error = new Error('Failed to decrypt msmsg with bounded deterministic strategies')
|
|
253
|
-
error.attemptedStrategies = attemptedStrategies
|
|
254
|
-
error.cause = lastError
|
|
255
|
-
throw error
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
module.exports = {
|
|
259
|
-
buildMsmsgDecryptionStrategies,
|
|
260
|
-
decodeDecryptedMsmsgMessage,
|
|
261
|
-
decryptMsmsgBotMessage
|
|
262
|
-
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
Object.defineProperty(exports, '__esModule', { value: true })
|
|
3
|
-
exports.loadRustBridge = void 0
|
|
4
|
-
const fs = require('fs')
|
|
5
|
-
const path = require('path')
|
|
6
|
-
|
|
7
|
-
const BRIDGE_NAME = 'whatsapp-rust-bridge'
|
|
8
|
-
let cached
|
|
9
|
-
let attempted = false
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Finds the installed package directory for `pkgName` by walking the same
|
|
13
|
-
* node_modules search path Node itself would use, without going through
|
|
14
|
-
* Node's package "exports" resolution gate.
|
|
15
|
-
*/
|
|
16
|
-
const findPackageDir = pkgName => {
|
|
17
|
-
let searchPaths
|
|
18
|
-
try {
|
|
19
|
-
searchPaths = require.resolve.paths(pkgName) || []
|
|
20
|
-
} catch {
|
|
21
|
-
searchPaths = []
|
|
22
|
-
}
|
|
23
|
-
for (const dir of searchPaths) {
|
|
24
|
-
const candidate = path.join(dir, pkgName)
|
|
25
|
-
if (fs.existsSync(path.join(candidate, 'package.json'))) {
|
|
26
|
-
return candidate
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
return null
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Loads whatsapp-rust-bridge, tolerating published versions/forks whose
|
|
34
|
-
* package.json ships an "exports" map with no "." entry (or an otherwise
|
|
35
|
-
* broken one) -- which makes a plain `require('whatsapp-rust-bridge')` throw
|
|
36
|
-
* ERR_PACKAGE_PATH_NOT_EXPORTED even though the module's files are present
|
|
37
|
-
* and perfectly usable. In that case, we locate the package directory
|
|
38
|
-
* ourselves and require its real entry file directly, bypassing the broken
|
|
39
|
-
* "exports" gate. Returns the loaded module, or null if it's unavailable.
|
|
40
|
-
*/
|
|
41
|
-
const loadRustBridge = () => {
|
|
42
|
-
if (attempted) return cached
|
|
43
|
-
attempted = true
|
|
44
|
-
try {
|
|
45
|
-
cached = require(BRIDGE_NAME)
|
|
46
|
-
return cached
|
|
47
|
-
} catch (error) {
|
|
48
|
-
const recoverableCodes = new Set(['ERR_PACKAGE_PATH_NOT_EXPORTED', 'ERR_PACKAGE_IMPORT_NOT_DEFINED'])
|
|
49
|
-
if (!recoverableCodes.has(error?.code)) {
|
|
50
|
-
cached = null
|
|
51
|
-
return null
|
|
52
|
-
}
|
|
53
|
-
try {
|
|
54
|
-
const dir = findPackageDir(BRIDGE_NAME)
|
|
55
|
-
if (!dir) {
|
|
56
|
-
cached = null
|
|
57
|
-
return null
|
|
58
|
-
}
|
|
59
|
-
const pkgJson = JSON.parse(fs.readFileSync(path.join(dir, 'package.json'), 'utf-8'))
|
|
60
|
-
const candidates = [
|
|
61
|
-
pkgJson.main,
|
|
62
|
-
'index.js',
|
|
63
|
-
'index.node',
|
|
64
|
-
'dist/index.js',
|
|
65
|
-
'lib/index.js',
|
|
66
|
-
'build/index.js'
|
|
67
|
-
].filter(Boolean)
|
|
68
|
-
for (const rel of candidates) {
|
|
69
|
-
const fullPath = path.join(dir, rel)
|
|
70
|
-
if (fs.existsSync(fullPath)) {
|
|
71
|
-
cached = require(fullPath)
|
|
72
|
-
return cached
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
} catch {
|
|
76
|
-
// fall through to returning null below
|
|
77
|
-
}
|
|
78
|
-
cached = null
|
|
79
|
-
return null
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
exports.loadRustBridge = loadRustBridge
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export interface SessionPoolOptions {
|
|
2
|
-
makeSocket: (sessionId: string) => Promise<any> | any
|
|
3
|
-
logger?: any
|
|
4
|
-
maxBackoffMs?: number
|
|
5
|
-
onSessionUpdate?: (sessionId: string, sock: any) => void
|
|
6
|
-
onLoggedOut?: (sessionId: string) => void
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export interface SessionPool {
|
|
10
|
-
add: (sessionId: string) => Promise<void>
|
|
11
|
-
remove: (sessionId: string) => void
|
|
12
|
-
get: (sessionId: string) => any
|
|
13
|
-
list: () => string[]
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function createSessionPool(options: SessionPoolOptions): SessionPool
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
Object.defineProperty(exports, '__esModule', { value: true })
|
|
3
|
-
exports.createSessionPool = void 0
|
|
4
|
-
|
|
5
|
-
const DISCONNECT_REASON_LOGGED_OUT = 401
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Manages multiple Baileys socket instances (one per account/session), automatically
|
|
9
|
-
* restarting any session that disconnects -- except when it was logged out -- using
|
|
10
|
-
* exponential backoff with jitter, instead of every project re-implementing its own
|
|
11
|
-
* reconnect loop.
|
|
12
|
-
*
|
|
13
|
-
* @param {{
|
|
14
|
-
* makeSocket: (sessionId: string) => Promise<any> | any,
|
|
15
|
-
* logger?: any,
|
|
16
|
-
* maxBackoffMs?: number,
|
|
17
|
-
* onSessionUpdate?: (sessionId: string, sock: any) => void,
|
|
18
|
-
* onLoggedOut?: (sessionId: string) => void
|
|
19
|
-
* }} options
|
|
20
|
-
* @returns {{
|
|
21
|
-
* add: (sessionId: string) => Promise<void>,
|
|
22
|
-
* remove: (sessionId: string) => void,
|
|
23
|
-
* get: (sessionId: string) => any,
|
|
24
|
-
* list: () => string[]
|
|
25
|
-
* }}
|
|
26
|
-
*/
|
|
27
|
-
const createSessionPool = options => {
|
|
28
|
-
const logger = options.logger
|
|
29
|
-
const maxBackoffMs = options.maxBackoffMs ?? 60000
|
|
30
|
-
const sessions = new Map() // sessionId -> { sock, attempts, stopped }
|
|
31
|
-
|
|
32
|
-
const computeBackoffMs = attempts => {
|
|
33
|
-
const base = Math.min(1000 * 2 ** attempts, maxBackoffMs)
|
|
34
|
-
return base + Math.floor(Math.random() * (base * 0.2))
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const start = async sessionId => {
|
|
38
|
-
const entry = sessions.get(sessionId) || { attempts: 0, stopped: false }
|
|
39
|
-
sessions.set(sessionId, entry)
|
|
40
|
-
if (entry.stopped) return
|
|
41
|
-
try {
|
|
42
|
-
const sock = await options.makeSocket(sessionId)
|
|
43
|
-
entry.sock = sock
|
|
44
|
-
options.onSessionUpdate?.(sessionId, sock)
|
|
45
|
-
sock.ev.on('connection.update', update => {
|
|
46
|
-
if (update.connection === 'open') {
|
|
47
|
-
entry.attempts = 0
|
|
48
|
-
}
|
|
49
|
-
if (update.connection === 'close') {
|
|
50
|
-
const statusCode = update.lastDisconnect?.error?.output?.statusCode
|
|
51
|
-
if (statusCode === DISCONNECT_REASON_LOGGED_OUT) {
|
|
52
|
-
logger?.info?.({ sessionId }, 'session logged out, removing from pool')
|
|
53
|
-
sessions.delete(sessionId)
|
|
54
|
-
options.onLoggedOut?.(sessionId)
|
|
55
|
-
return
|
|
56
|
-
}
|
|
57
|
-
if (entry.stopped) return
|
|
58
|
-
entry.attempts += 1
|
|
59
|
-
const backoffMs = computeBackoffMs(entry.attempts)
|
|
60
|
-
logger?.warn?.(
|
|
61
|
-
{ sessionId, attempt: entry.attempts, backoffMs },
|
|
62
|
-
'session disconnected, reconnecting with backoff'
|
|
63
|
-
)
|
|
64
|
-
setTimeout(() => start(sessionId), backoffMs)
|
|
65
|
-
}
|
|
66
|
-
})
|
|
67
|
-
} catch (error) {
|
|
68
|
-
entry.attempts += 1
|
|
69
|
-
const backoffMs = computeBackoffMs(entry.attempts)
|
|
70
|
-
logger?.error?.({ error, sessionId, backoffMs }, 'failed to start session, retrying with backoff')
|
|
71
|
-
if (!entry.stopped) {
|
|
72
|
-
setTimeout(() => start(sessionId), backoffMs)
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const add = sessionId => start(sessionId)
|
|
78
|
-
const remove = sessionId => {
|
|
79
|
-
const entry = sessions.get(sessionId)
|
|
80
|
-
if (!entry) return
|
|
81
|
-
entry.stopped = true
|
|
82
|
-
if (entry.sock?.end) {
|
|
83
|
-
try {
|
|
84
|
-
entry.sock.end(undefined)
|
|
85
|
-
} catch {}
|
|
86
|
-
}
|
|
87
|
-
sessions.delete(sessionId)
|
|
88
|
-
}
|
|
89
|
-
const get = sessionId => sessions.get(sessionId)?.sock
|
|
90
|
-
const list = () => [...sessions.keys()]
|
|
91
|
-
|
|
92
|
-
return { add, remove, get, list }
|
|
93
|
-
}
|
|
94
|
-
exports.createSessionPool = createSessionPool
|
package/lib/Utils/sticker.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export interface StickerMetaOptions {
|
|
2
|
-
packName?: string
|
|
3
|
-
packPublisher?: string
|
|
4
|
-
categories?: string[]
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export function addExifToWebp(webpBuffer: Buffer, options?: StickerMetaOptions): Promise<Buffer>
|
|
8
|
-
|
|
9
|
-
export function imageToWebpSticker(
|
|
10
|
-
imageBuffer: Buffer,
|
|
11
|
-
options?: StickerMetaOptions & { quality?: number }
|
|
12
|
-
): Promise<Buffer>
|
|
13
|
-
|
|
14
|
-
export function videoToWebpSticker(
|
|
15
|
-
videoBuffer: Buffer,
|
|
16
|
-
options?: StickerMetaOptions & { fps?: number; seconds?: number }
|
|
17
|
-
): Promise<Buffer>
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export interface AutoCacheViewOnceOptions {
|
|
2
|
-
cacheDir?: string
|
|
3
|
-
logger?: any
|
|
4
|
-
onCached?: (info: { id: string; jid: string; filePath: string; type: string }) => void
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export function getViewOnceContent(message: any): Record<string, any> | null
|
|
8
|
-
|
|
9
|
-
export function autoCacheViewOnceMedia(sock: any, options?: AutoCacheViewOnceOptions): () => void
|