@badzz88/baileys 8.4.7 → 8.5.0
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/LICENSE +21 -0
- package/README.md +1055 -337
- package/WAProto/index.js +5 -5
- package/lib/Defaults/index.js +187 -127
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Signal/Group/ciphertext-message.js +14 -11
- package/lib/Signal/Group/group-session-builder.js +91 -29
- package/lib/Signal/Group/group_cipher.js +88 -81
- package/lib/Signal/Group/index.js +136 -12
- package/lib/Signal/Group/keyhelper.js +70 -15
- package/lib/Signal/Group/sender-chain-key.js +31 -25
- package/lib/Signal/Group/sender-key-distribution-message.js +65 -62
- package/lib/Signal/Group/sender-key-message.js +68 -65
- package/lib/Signal/Group/sender-key-name.js +43 -41
- package/lib/Signal/Group/sender-key-record.js +43 -40
- package/lib/Signal/Group/sender-key-state.js +96 -83
- package/lib/Signal/Group/sender-message-key.js +29 -25
- package/lib/Signal/libsignal.js +483 -424
- package/lib/Signal/lid-mapping.js +261 -276
- package/lib/Socket/Client/index.js +30 -3
- package/lib/Socket/Client/types.js +12 -10
- package/lib/Socket/Client/websocket.js +61 -53
- package/lib/Socket/aigroups.js +240 -0
- package/lib/Socket/business.js +422 -379
- package/lib/Socket/chats.js +1816 -1193
- package/lib/Socket/communities.js +549 -431
- package/lib/Socket/graphql.js +656 -0
- package/lib/Socket/groups.js +764 -374
- package/lib/Socket/index.js +38 -11
- package/lib/Socket/interactive-handler.js +522 -0
- package/lib/Socket/interop.js +549 -0
- package/lib/Socket/luxu.js +6 -5
- package/lib/Socket/managed-account.js +183 -0
- package/lib/Socket/messages-recv.js +2439 -1915
- package/lib/Socket/messages-send.js +1642 -1242
- package/lib/Socket/mex.js +59 -40
- package/lib/Socket/newsletter.js +812 -249
- package/lib/Socket/privacy.js +449 -0
- package/lib/Socket/registration.js +427 -0
- package/lib/Socket/socket.js +1077 -965
- package/lib/Socket/text-router.js +83 -0
- package/lib/Socket/username.js +237 -140
- package/lib/Store/index.js +36 -10
- package/lib/Store/make-cache-manager-store.js +85 -80
- package/lib/Store/make-in-memory-store.js +591 -185
- package/lib/Store/make-ordered-dictionary.js +78 -72
- package/lib/Store/object-repository.js +25 -28
- package/lib/Types/Auth.js +38 -2
- package/lib/Types/Bussines.js +2 -2
- package/lib/Types/Call.js +2 -2
- package/lib/Types/Chat.js +4 -8
- 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 +26 -24
- package/lib/Types/LabelAssociation.js +8 -6
- package/lib/Types/Message.js +95 -11
- package/lib/Types/Mex.js +112 -37
- package/lib/Types/Newsletter.js +121 -0
- package/lib/Types/Product.js +2 -2
- package/lib/Types/Signal.js +2 -2
- package/lib/Types/Socket.js +2 -3
- package/lib/Types/State.js +70 -56
- package/lib/Types/USync.js +2 -2
- package/lib/Types/index.js +55 -26
- package/lib/Utils/auth-utils.js +292 -288
- package/lib/Utils/browser-utils.js +113 -48
- package/lib/Utils/business.js +240 -224
- package/lib/Utils/chat-utils.js +1205 -869
- package/lib/Utils/command-loader.d.ts +31 -0
- package/lib/Utils/command-loader.js +100 -0
- package/lib/Utils/companion-reg-client-utils.js +41 -34
- package/lib/Utils/consumer-application.js +107 -0
- package/lib/Utils/crypto.js +144 -107
- package/lib/Utils/curve25519-js.js +275 -0
- package/lib/Utils/decode-wa-message.js +518 -308
- package/lib/Utils/event-buffer.js +596 -611
- package/lib/Utils/generics.js +514 -354
- package/lib/Utils/group-history.js +60 -0
- package/lib/Utils/history.js +244 -134
- package/lib/Utils/identity-change-handler.js +51 -49
- package/lib/Utils/index.js +57 -23
- package/lib/Utils/jid-display-normalization.js +218 -0
- package/lib/Utils/link-preview.js +135 -77
- package/lib/Utils/logger.js +9 -3
- package/lib/Utils/lt-hash.js +37 -6
- package/lib/Utils/make-mutex.js +36 -33
- package/lib/Utils/message-composer.js +439 -233
- package/lib/Utils/message-retry-manager.js +265 -260
- package/lib/Utils/messages-media.js +855 -747
- package/lib/Utils/messages.js +2528 -884
- package/lib/Utils/meta-ai-msmsg.js +262 -0
- package/lib/Utils/native-bridge.js +82 -0
- package/lib/Utils/noise-handler.js +195 -200
- package/lib/Utils/offline-node-processor.js +35 -33
- package/lib/Utils/pre-key-manager.js +103 -102
- package/lib/Utils/process-message.js +978 -560
- package/lib/Utils/reporting-utils.js +257 -253
- package/lib/Utils/session-pool.d.ts +16 -0
- package/lib/Utils/session-pool.js +94 -0
- package/lib/Utils/signal.js +218 -195
- package/lib/Utils/stanza-ack.js +31 -29
- package/lib/Utils/sticker.d.ts +17 -0
- package/lib/Utils/sticker.js +145 -0
- package/lib/Utils/sync-action-utils.js +50 -45
- package/lib/Utils/tc-token-utils.js +137 -139
- package/lib/Utils/use-multi-file-auth-state.js +109 -109
- package/lib/Utils/validate-connection.js +218 -202
- package/lib/Utils/view-once-cache.d.ts +9 -0
- package/lib/Utils/view-once-cache.js +79 -0
- package/lib/Utils/voip-rekey.js +22 -0
- package/lib/WABinary/constants.js +1302 -1299
- package/lib/WABinary/decode.js +343 -262
- package/lib/WABinary/encode.js +12 -4
- package/lib/WABinary/generic-utils.js +223 -187
- package/lib/WABinary/index.js +33 -6
- package/lib/WABinary/jid-utils.js +351 -88
- package/lib/WABinary/types.js +2 -2
- package/lib/WAM/BinaryInfo.js +12 -9
- package/lib/WAM/constants.js +39486 -22853
- package/lib/WAM/encode.js +132 -140
- package/lib/WAM/index.js +31 -4
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +55 -0
- package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +43 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +53 -51
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +56 -53
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +29 -26
- package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +59 -0
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +31 -0
- package/lib/WAUSync/Protocols/USyncPictureProtocol.js +32 -0
- package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +29 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +38 -37
- package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +38 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +26 -24
- package/lib/WAUSync/Protocols/index.js +39 -6
- package/lib/WAUSync/USyncQuery.js +132 -97
- package/lib/WAUSync/USyncUser.js +49 -30
- package/lib/WAUSync/index.js +31 -4
- package/lib/antiban.js +4637 -0
- package/lib/index.js +48 -15
- package/package.json +55 -92
- package/lib/WAUSync/Protocols/USyncNewsletterProtocol.js +0 -263
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +0 -51
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +0 -29
|
@@ -0,0 +1,218 @@
|
|
|
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,85 +1,143 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
'use strict'
|
|
2
|
+
var __createBinding =
|
|
3
|
+
(this && this.__createBinding) ||
|
|
4
|
+
(Object.create
|
|
5
|
+
? function (o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k)
|
|
8
|
+
if (!desc || ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function () {
|
|
12
|
+
return m[k]
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
Object.defineProperty(o, k2, desc)
|
|
17
|
+
}
|
|
18
|
+
: function (o, m, k, k2) {
|
|
19
|
+
if (k2 === undefined) k2 = k
|
|
20
|
+
o[k2] = m[k]
|
|
21
|
+
})
|
|
22
|
+
var __setModuleDefault =
|
|
23
|
+
(this && this.__setModuleDefault) ||
|
|
24
|
+
(Object.create
|
|
25
|
+
? function (o, v) {
|
|
26
|
+
Object.defineProperty(o, 'default', { enumerable: true, value: v })
|
|
27
|
+
}
|
|
28
|
+
: function (o, v) {
|
|
29
|
+
o['default'] = v
|
|
30
|
+
})
|
|
31
|
+
var __importStar =
|
|
32
|
+
(this && this.__importStar) ||
|
|
33
|
+
(function () {
|
|
34
|
+
var ownKeys = function (o) {
|
|
35
|
+
ownKeys =
|
|
36
|
+
Object.getOwnPropertyNames ||
|
|
37
|
+
function (o) {
|
|
38
|
+
var ar = []
|
|
39
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k
|
|
40
|
+
return ar
|
|
41
|
+
}
|
|
42
|
+
return ownKeys(o)
|
|
43
|
+
}
|
|
44
|
+
return function (mod) {
|
|
45
|
+
if (mod && mod.__esModule) return mod
|
|
46
|
+
var result = {}
|
|
47
|
+
if (mod != null)
|
|
48
|
+
for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== 'default') __createBinding(result, mod, k[i])
|
|
49
|
+
__setModuleDefault(result, mod)
|
|
50
|
+
return result
|
|
51
|
+
}
|
|
52
|
+
})()
|
|
53
|
+
Object.defineProperty(exports, '__esModule', { value: true })
|
|
54
|
+
exports.getUrlInfo = void 0
|
|
55
|
+
const messages_1 = require('./messages')
|
|
56
|
+
const messages_media_1 = require('./messages-media')
|
|
57
|
+
const THUMBNAIL_WIDTH_PX = 192
|
|
4
58
|
/** Fetches an image and generates a thumbnail for it */
|
|
5
59
|
const getCompressedJpegThumbnail = async (url, { thumbnailWidth, fetchOpts }) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
60
|
+
const stream = await (0, messages_media_1.getHttpStream)(url, fetchOpts)
|
|
61
|
+
const result = await (0, messages_media_1.extractImageThumb)(stream, thumbnailWidth)
|
|
62
|
+
return result
|
|
63
|
+
}
|
|
10
64
|
/**
|
|
11
65
|
* Given a piece of text, checks for any URL present, generates link preview for the same and returns it
|
|
12
66
|
* Return undefined if the fetch failed or no URL was found
|
|
13
67
|
* @param text first matched URL in text
|
|
14
68
|
* @returns the URL info required to generate link preview
|
|
15
69
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
70
|
+
const getUrlInfo = async (
|
|
71
|
+
text,
|
|
72
|
+
opts = {
|
|
73
|
+
thumbnailWidth: THUMBNAIL_WIDTH_PX,
|
|
74
|
+
fetchOpts: { timeout: 3000 }
|
|
75
|
+
}
|
|
76
|
+
) => {
|
|
77
|
+
try {
|
|
78
|
+
// retries
|
|
79
|
+
const retries = 0
|
|
80
|
+
const maxRetry = 5
|
|
81
|
+
const { getLinkPreview } = await Promise.resolve().then(() => __importStar(require('link-preview-js')))
|
|
82
|
+
let previewLink = text
|
|
83
|
+
if (!text.startsWith('https://') && !text.startsWith('http://')) {
|
|
84
|
+
previewLink = 'https://' + previewLink
|
|
85
|
+
}
|
|
86
|
+
const info = await getLinkPreview(previewLink, {
|
|
87
|
+
...opts.fetchOpts,
|
|
88
|
+
followRedirects: 'follow',
|
|
89
|
+
handleRedirects: (baseURL, forwardedURL) => {
|
|
90
|
+
const urlObj = new URL(baseURL)
|
|
91
|
+
const forwardedURLObj = new URL(forwardedURL)
|
|
92
|
+
if (retries >= maxRetry) {
|
|
93
|
+
return false
|
|
94
|
+
}
|
|
95
|
+
if (
|
|
96
|
+
forwardedURLObj.hostname === urlObj.hostname ||
|
|
97
|
+
forwardedURLObj.hostname === 'www.' + urlObj.hostname ||
|
|
98
|
+
'www.' + forwardedURLObj.hostname === urlObj.hostname
|
|
99
|
+
) {
|
|
100
|
+
retries + 1
|
|
101
|
+
return true
|
|
102
|
+
} else {
|
|
103
|
+
return false
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
headers: opts.fetchOpts?.headers
|
|
107
|
+
})
|
|
108
|
+
if (info && 'title' in info && info.title) {
|
|
109
|
+
const [image] = info.images
|
|
110
|
+
const urlInfo = {
|
|
111
|
+
'canonical-url': info.url,
|
|
112
|
+
'matched-text': text,
|
|
113
|
+
title: info.title,
|
|
114
|
+
description: info.description,
|
|
115
|
+
originalThumbnailUrl: image
|
|
116
|
+
}
|
|
117
|
+
if (opts.uploadImage) {
|
|
118
|
+
const { imageMessage } = await (0, messages_1.prepareWAMessageMedia)(
|
|
119
|
+
{ image: { url: image } },
|
|
120
|
+
{
|
|
121
|
+
upload: opts.uploadImage,
|
|
122
|
+
mediaTypeOverride: 'thumbnail-link',
|
|
123
|
+
options: opts.fetchOpts
|
|
124
|
+
}
|
|
125
|
+
)
|
|
126
|
+
urlInfo.jpegThumbnail = imageMessage?.jpegThumbnail ? Buffer.from(imageMessage.jpegThumbnail) : undefined
|
|
127
|
+
urlInfo.highQualityThumbnail = imageMessage || undefined
|
|
128
|
+
} else {
|
|
129
|
+
try {
|
|
130
|
+
urlInfo.jpegThumbnail = image ? (await getCompressedJpegThumbnail(image, opts)).buffer : undefined
|
|
131
|
+
} catch (error) {
|
|
132
|
+
opts.logger?.debug({ err: error.stack, url: previewLink }, 'error in generating thumbnail')
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return urlInfo
|
|
136
|
+
}
|
|
137
|
+
} catch (error) {
|
|
138
|
+
if (!error.message.includes('receive a valid')) {
|
|
139
|
+
throw error
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
exports.getUrlInfo = getUrlInfo
|
package/lib/Utils/logger.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
'use strict'
|
|
2
|
+
var __importDefault =
|
|
3
|
+
(this && this.__importDefault) ||
|
|
4
|
+
function (mod) {
|
|
5
|
+
return mod && mod.__esModule ? mod : { default: mod }
|
|
6
|
+
}
|
|
7
|
+
Object.defineProperty(exports, '__esModule', { value: true })
|
|
8
|
+
const pino_1 = __importDefault(require('pino'))
|
|
9
|
+
exports.default = (0, pino_1.default)({ timestamp: () => `,"time":"${new Date().toJSON()}"` })
|
package/lib/Utils/lt-hash.js
CHANGED
|
@@ -1,8 +1,39 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict'
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true })
|
|
3
|
+
exports.LT_HASH_ANTI_TAMPERING = void 0
|
|
4
|
+
const crypto_1 = require('./crypto')
|
|
5
|
+
|
|
2
6
|
/**
|
|
3
|
-
* LT Hash is a summation
|
|
4
|
-
*
|
|
5
|
-
*
|
|
7
|
+
* LT Hash ("lthash16") is a summation-based homomorphic hash algorithm that
|
|
8
|
+
* maintains the integrity of a piece of data over a series of mutations. You
|
|
9
|
+
* can add/remove mutations and it'll return a hash equal to if the same
|
|
10
|
+
* series of mutations was made sequentially.
|
|
11
|
+
*
|
|
12
|
+
* WhatsApp expands each element to 128 bytes via HKDF (info = "WhatsApp Patch
|
|
13
|
+
* Integrity"), treats that as 64 little-endian uint16 lanes, and combines
|
|
14
|
+
* elements by adding/subtracting lane-wise mod 2^16 -- this is a pure HKDF +
|
|
15
|
+
* integer-arithmetic algorithm, no elliptic-curve math involved. Pure-JS,
|
|
16
|
+
* built on the already-validated `hkdf` implementation.
|
|
6
17
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
18
|
+
const LTHASH_INFO = 'WhatsApp Patch Integrity'
|
|
19
|
+
const LTHASH_SIZE = 128 // bytes = 64 uint16 lanes
|
|
20
|
+
|
|
21
|
+
const expand = element => (0, crypto_1.hkdf)(element, LTHASH_SIZE, { info: LTHASH_INFO })
|
|
22
|
+
|
|
23
|
+
const applyDelta = (result, element, sign) => {
|
|
24
|
+
const expanded = expand(element)
|
|
25
|
+
for (let i = 0; i < LTHASH_SIZE; i += 2) {
|
|
26
|
+
const lane = result.readUInt16LE(i)
|
|
27
|
+
const delta = expanded.readUInt16LE(i)
|
|
28
|
+
result.writeUInt16LE((lane + sign * delta) & 0xffff, i)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
exports.LT_HASH_ANTI_TAMPERING = {
|
|
33
|
+
subtractThenAdd: (base, subtract = [], add = []) => {
|
|
34
|
+
const result = Buffer.from(base)
|
|
35
|
+
for (const element of subtract) applyDelta(result, element, -1)
|
|
36
|
+
for (const element of add) applyDelta(result, element, 1)
|
|
37
|
+
return result
|
|
38
|
+
}
|
|
39
|
+
}
|
package/lib/Utils/make-mutex.js
CHANGED
|
@@ -1,33 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
1
|
+
'use strict'
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true })
|
|
3
|
+
exports.makeKeyedMutex = exports.makeMutex = void 0
|
|
4
|
+
const async_mutex_1 = require('async-mutex')
|
|
5
|
+
const makeMutex = () => {
|
|
6
|
+
const mutex = new async_mutex_1.Mutex()
|
|
7
|
+
return {
|
|
8
|
+
mutex(code) {
|
|
9
|
+
return mutex.runExclusive(code)
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.makeMutex = makeMutex
|
|
14
|
+
const makeKeyedMutex = () => {
|
|
15
|
+
const map = new Map()
|
|
16
|
+
return {
|
|
17
|
+
async mutex(key, task) {
|
|
18
|
+
let entry = map.get(key)
|
|
19
|
+
if (!entry) {
|
|
20
|
+
entry = { mutex: new async_mutex_1.Mutex(), refCount: 0 }
|
|
21
|
+
map.set(key, entry)
|
|
22
|
+
}
|
|
23
|
+
entry.refCount++
|
|
24
|
+
try {
|
|
25
|
+
return await entry.mutex.runExclusive(task)
|
|
26
|
+
} finally {
|
|
27
|
+
entry.refCount--
|
|
28
|
+
// only delete it if this is still the current entry
|
|
29
|
+
if (entry.refCount === 0 && map.get(key) === entry) {
|
|
30
|
+
map.delete(key)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.makeKeyedMutex = makeKeyedMutex
|