@hansaka02/baileys 7.3.2 → 7.3.4
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 +247 -203
- package/lib/Defaults/connection.js +51 -0
- package/lib/Defaults/constants.js +62 -0
- package/lib/Defaults/history.js +17 -0
- package/lib/Defaults/index.js +36 -142
- package/lib/Defaults/media.js +48 -0
- package/lib/Defaults/prefix.js +18 -0
- package/lib/Signal/Group/group-session-builder.js +10 -42
- package/lib/Signal/Group/group_cipher.js +9 -6
- package/lib/Signal/Group/index.js +39 -53
- package/lib/Signal/Group/keyhelper.js +8 -41
- package/lib/Signal/Group/sender-chain-key.js +4 -4
- package/lib/Signal/Group/sender-key-distribution-message.js +5 -5
- package/lib/Signal/Group/sender-key-message.js +12 -8
- package/lib/Signal/Group/sender-key-record.js +7 -7
- package/lib/Signal/Group/sender-key-state.js +4 -4
- package/lib/Signal/Group/sender-message-key.js +2 -2
- package/lib/Signal/libsignal.js +45 -69
- package/lib/Signal/lid-mapping.js +15 -11
- package/lib/Socket/Client/types.js +2 -2
- package/lib/Socket/Client/websocket.js +16 -14
- package/lib/Socket/business.js +41 -32
- package/lib/Socket/chats.js +123 -98
- package/lib/Socket/community.js +50 -40
- package/lib/Socket/groups.js +59 -47
- package/lib/Socket/index.js +4 -4
- package/lib/Socket/messages-recv.js +219 -172
- package/lib/Socket/messages-send.js +187 -143
- package/lib/Socket/newsletter.js +61 -47
- package/lib/Socket/socket.js +133 -90
- package/lib/Socket/usync.js +6 -6
- package/lib/Store/index.js +27 -11
- package/lib/Store/make-cache-manager-store.js +14 -15
- package/lib/Store/make-in-memory-store.js +28 -24
- package/lib/Types/LabelAssociation.js +2 -2
- package/lib/Types/Message.js +6 -6
- package/lib/Types/MexUpdates.js +5 -5
- package/lib/Types/State.js +4 -4
- package/lib/Types/index.js +28 -12
- package/lib/Utils/auth-utils.js +28 -26
- package/lib/Utils/baileys-event-stream.js +68 -69
- package/lib/Utils/business.js +63 -53
- package/lib/Utils/chat-utils.js +81 -71
- package/lib/Utils/crypto.js +25 -45
- package/lib/Utils/decode-wa-message.js +319 -311
- package/lib/Utils/event-buffer.js +21 -22
- package/lib/Utils/generics.js +65 -82
- package/lib/Utils/history.js +21 -21
- package/lib/Utils/index.js +27 -13
- package/lib/Utils/link-preview.js +7 -30
- package/lib/Utils/logger.js +5 -5
- package/lib/Utils/lt-hash.js +3 -3
- package/lib/Utils/message-retry-manager.js +4 -4
- package/lib/Utils/messages-media.js +104 -109
- package/lib/Utils/messages.js +203 -171
- package/lib/Utils/noise-handler.js +28 -19
- package/lib/Utils/process-message.js +111 -96
- package/lib/Utils/signal.js +36 -25
- package/lib/Utils/use-multi-file-auth-state.js +18 -22
- package/lib/Utils/validate-connection.js +52 -45
- package/lib/WABinary/decode.js +6 -32
- package/lib/WABinary/encode.js +3 -29
- package/lib/WABinary/generic-utils.js +4 -4
- package/lib/WABinary/index.js +27 -11
- package/lib/WAM/encode.js +16 -8
- package/lib/WAM/index.js +27 -11
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +20 -16
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +7 -4
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +0 -2
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +2 -2
- package/lib/WAUSync/Protocols/index.js +27 -11
- package/lib/WAUSync/USyncQuery.js +17 -10
- package/lib/WAUSync/index.js +27 -11
- package/lib/index.js +60 -31
- package/package.json +8 -14
- package/WAProto/AICommon/AICommon.d.ts +0 -11702
- package/WAProto/Adv/Adv.d.ts +0 -643
- package/WAProto/BotMetadata/BotMetadata.d.ts +0 -5654
- package/WAProto/Cert/Cert.d.ts +0 -613
- package/WAProto/ChatLockSettings/ChatLockSettings.d.ts +0 -476
- package/WAProto/CompanionReg/CompanionReg.d.ts +0 -1361
- package/WAProto/DeviceCapabilities/DeviceCapabilities.d.ts +0 -577
- package/WAProto/E2E/E2E.d.ts +0 -41724
- package/WAProto/Ephemeral/Ephemeral.d.ts +0 -114
- package/WAProto/HistorySync/HistorySync.d.ts +0 -51700
- package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.d.ts +0 -229
- package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.d.ts +0 -583
- package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.d.ts +0 -42897
- package/WAProto/MmsRetry/MmsRetry.d.ts +0 -243
- package/WAProto/Protocol/Protocol.d.ts +0 -270
- package/WAProto/Reporting/Reporting.d.ts +0 -371
- package/WAProto/ServerSync/ServerSync.d.ts +0 -1285
- package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.d.ts +0 -1868
- package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.d.ts +0 -767
- package/WAProto/StatusAttributions/StatusAttributions.d.ts +0 -1027
- package/WAProto/SyncAction/SyncAction.d.ts +0 -11193
- package/WAProto/UserPassword/UserPassword.d.ts +0 -363
- package/WAProto/VnameCert/VnameCert.d.ts +0 -821
- package/WAProto/Wa6/Wa6.d.ts +0 -2128
- package/WAProto/Web/Web.d.ts +0 -46383
- package/WAProto/index.d.ts +0 -55
- package/lib/Defaults/index.d.ts +0 -77
- package/lib/Signal/Group/ciphertext-message.d.ts +0 -9
- package/lib/Signal/Group/group-session-builder.d.ts +0 -17
- package/lib/Signal/Group/group_cipher.d.ts +0 -19
- package/lib/Signal/Group/index.d.ts +0 -11
- package/lib/Signal/Group/keyhelper.d.ts +0 -16
- package/lib/Signal/Group/sender-chain-key.d.ts +0 -14
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -17
- package/lib/Signal/Group/sender-key-message.d.ts +0 -19
- package/lib/Signal/Group/sender-key-name.d.ts +0 -19
- package/lib/Signal/Group/sender-key-record.d.ts +0 -32
- package/lib/Signal/Group/sender-key-state.d.ts +0 -44
- package/lib/Signal/Group/sender-message-key.d.ts +0 -11
- package/lib/Signal/libsignal.d.ts +0 -8
- package/lib/Signal/lid-mapping.d.ts +0 -28
- package/lib/Socket/Client/index.d.ts +0 -2
- package/lib/Socket/Client/types.d.ts +0 -16
- package/lib/Socket/Client/websocket.d.ts +0 -13
- package/lib/Socket/business.d.ts +0 -187
- package/lib/Socket/chats.d.ts +0 -97
- package/lib/Socket/community.d.ts +0 -129
- package/lib/Socket/groups.d.ts +0 -129
- package/lib/Socket/index.d.ts +0 -191
- package/lib/Socket/messages-recv.d.ts +0 -174
- package/lib/Socket/messages-send.d.ts +0 -165
- package/lib/Socket/newsletter.d.ts +0 -145
- package/lib/Socket/socket.d.ts +0 -45
- package/lib/Socket/usync.d.ts +0 -37
- package/lib/Store/index.d.ts +0 -4
- package/lib/Store/make-cache-manager-store.d.ts +0 -14
- package/lib/Store/make-in-memory-store.d.ts +0 -123
- package/lib/Store/make-ordered-dictionary.d.ts +0 -12
- package/lib/Store/object-repository.d.ts +0 -10
- package/lib/Types/Auth.d.ts +0 -121
- package/lib/Types/Bussiness.d.ts +0 -28
- package/lib/Types/Call.d.ts +0 -14
- package/lib/Types/Chat.d.ts +0 -143
- package/lib/Types/Contact.d.ts +0 -23
- package/lib/Types/Events.d.ts +0 -226
- package/lib/Types/GroupMetadata.d.ts +0 -66
- package/lib/Types/Label.d.ts +0 -48
- package/lib/Types/LabelAssociation.d.ts +0 -35
- package/lib/Types/Message.d.ts +0 -484
- package/lib/Types/MexUpdates.d.ts +0 -9
- package/lib/Types/Newsletter.d.ts +0 -109
- package/lib/Types/Product.d.ts +0 -92
- package/lib/Types/Signal.d.ts +0 -98
- package/lib/Types/Socket.d.ts +0 -141
- package/lib/Types/State.d.ts +0 -41
- package/lib/Types/USync.d.ts +0 -26
- package/lib/Types/index.d.ts +0 -80
- package/lib/Utils/auth-utils.d.ts +0 -21
- package/lib/Utils/baileys-event-stream.d.ts +0 -18
- package/lib/Utils/business.d.ts +0 -29
- package/lib/Utils/chat-utils.d.ts +0 -82
- package/lib/Utils/crypto.d.ts +0 -56
- package/lib/Utils/decode-wa-message.d.ts +0 -53
- package/lib/Utils/event-buffer.d.ts +0 -39
- package/lib/Utils/generics.d.ts +0 -117
- package/lib/Utils/history.d.ts +0 -23
- package/lib/Utils/index.d.ts +0 -20
- package/lib/Utils/link-preview.d.ts +0 -23
- package/lib/Utils/logger.d.ts +0 -13
- package/lib/Utils/lt-hash.d.ts +0 -14
- package/lib/Utils/make-mutex.d.ts +0 -9
- package/lib/Utils/message-retry-manager.d.ts +0 -88
- package/lib/Utils/messages-media.d.ts +0 -135
- package/lib/Utils/messages.d.ts +0 -105
- package/lib/Utils/noise-handler.d.ts +0 -20
- package/lib/Utils/process-message.d.ts +0 -49
- package/lib/Utils/signal.d.ts +0 -42
- package/lib/Utils/use-mongo-file-auth-state.d.ts +0 -6
- package/lib/Utils/use-mongo-file-auth-state.js +0 -84
- package/lib/Utils/use-multi-file-auth-state.d.ts +0 -13
- package/lib/Utils/use-single-file-auth-state.d.ts +0 -13
- package/lib/Utils/use-single-file-auth-state.js +0 -80
- package/lib/Utils/validate-connection.d.ts +0 -13
- package/lib/WABinary/constants.d.ts +0 -30
- package/lib/WABinary/decode.d.ts +0 -9
- package/lib/WABinary/encode.d.ts +0 -3
- package/lib/WABinary/generic-utils.d.ts +0 -28
- package/lib/WABinary/index.d.ts +0 -5
- package/lib/WABinary/jid-utils.d.ts +0 -58
- package/lib/WABinary/types.d.ts +0 -22
- package/lib/WAM/BinaryInfo.d.ts +0 -16
- package/lib/WAM/constants.d.ts +0 -47
- package/lib/WAM/encode.d.ts +0 -3
- package/lib/WAM/index.d.ts +0 -3
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.d.ts +0 -28
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -10
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -26
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -14
- package/lib/WAUSync/Protocols/USyncLIDProtocol.d.ts +0 -10
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -14
- package/lib/WAUSync/Protocols/index.d.ts +0 -6
- package/lib/WAUSync/USyncQuery.d.ts +0 -31
- package/lib/WAUSync/USyncUser.d.ts +0 -12
- package/lib/WAUSync/index.d.ts +0 -3
- package/lib/index.d.ts +0 -13
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
"use strict"
|
|
2
2
|
|
|
3
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
-
return (mod && mod.__esModule) ? mod : { "default": mod }
|
|
5
|
-
}
|
|
6
|
-
|
|
7
3
|
Object.defineProperty(exports, "__esModule", { value: true })
|
|
8
4
|
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
|
|
5
|
+
const Events = require("events")
|
|
6
|
+
const { WAMessageStatus } = require("../Types")
|
|
7
|
+
const { trimUndefined } = require("./generics")
|
|
8
|
+
const {
|
|
9
|
+
updateMessageWithReceipt,
|
|
10
|
+
updateMessageWithReaction
|
|
11
|
+
} = require("./messages")
|
|
12
|
+
const { isRealMessage } = require("./process-message")
|
|
14
13
|
|
|
15
14
|
const BUFFERABLE_EVENT = [
|
|
16
15
|
'messaging-history.set',
|
|
@@ -35,7 +34,7 @@ const BUFFERABLE_EVENT_SET = new Set(BUFFERABLE_EVENT)
|
|
|
35
34
|
* making the data processing more efficient.
|
|
36
35
|
*/
|
|
37
36
|
const makeEventBuffer = (logger) => {
|
|
38
|
-
const ev = new
|
|
37
|
+
const ev = new Events()
|
|
39
38
|
const historyCache = new Set()
|
|
40
39
|
let data = makeBufferData()
|
|
41
40
|
let isBuffering = false
|
|
@@ -210,7 +209,7 @@ function append(data, historyCache, event, eventData, logger) {
|
|
|
210
209
|
for (const contact of eventData.contacts) {
|
|
211
210
|
const existingContact = data.historySets.contacts[contact.id]
|
|
212
211
|
if (existingContact) {
|
|
213
|
-
Object.assign(existingContact,
|
|
212
|
+
Object.assign(existingContact, trimUndefined(contact))
|
|
214
213
|
}
|
|
215
214
|
else {
|
|
216
215
|
const historyContactId = `c:${contact.id}`
|
|
@@ -313,14 +312,14 @@ function append(data, historyCache, event, eventData, logger) {
|
|
|
313
312
|
}
|
|
314
313
|
}
|
|
315
314
|
if (upsert) {
|
|
316
|
-
upsert = Object.assign(upsert,
|
|
315
|
+
upsert = Object.assign(upsert, trimUndefined(contact))
|
|
317
316
|
}
|
|
318
317
|
else {
|
|
319
318
|
upsert = contact
|
|
320
319
|
data.contactUpserts[contact.id] = upsert
|
|
321
320
|
}
|
|
322
321
|
if (data.contactUpdates[contact.id]) {
|
|
323
|
-
upsert = Object.assign(data.contactUpdates[contact.id],
|
|
322
|
+
upsert = Object.assign(data.contactUpdates[contact.id], trimUndefined(contact))
|
|
324
323
|
delete data.contactUpdates[contact.id]
|
|
325
324
|
}
|
|
326
325
|
}
|
|
@@ -383,7 +382,7 @@ function append(data, historyCache, event, eventData, logger) {
|
|
|
383
382
|
// if the message was received & read by us
|
|
384
383
|
// the chat counter must have been incremented
|
|
385
384
|
// so we need to decrement it
|
|
386
|
-
if (update.status ===
|
|
385
|
+
if (update.status === WAMessageStatus.READ && !key.fromMe) {
|
|
387
386
|
decrementChatReadCounterIfMsgDidUnread(existing)
|
|
388
387
|
}
|
|
389
388
|
}
|
|
@@ -421,11 +420,11 @@ function append(data, historyCache, event, eventData, logger) {
|
|
|
421
420
|
// const keyStr = stringifyMessageKey(pollUpdateMessageKey)
|
|
422
421
|
// const existing = data.messagePollings[keyStr]
|
|
423
422
|
// if(existing) {
|
|
424
|
-
//
|
|
423
|
+
// updateMessageWithPollUpdate(existing.message, pollUpdates)
|
|
425
424
|
// } else {
|
|
426
425
|
// data.messagePollings[keyStr] = data.messagePollings[keyStr]
|
|
427
426
|
// || { pollUpdateMessageKey, pollUpdates: [] }
|
|
428
|
-
//
|
|
427
|
+
// updateMessageWithPollUpdate(data.messagePollings[keyStr], vote)
|
|
429
428
|
// }
|
|
430
429
|
// }
|
|
431
430
|
// break
|
|
@@ -435,12 +434,12 @@ function append(data, historyCache, event, eventData, logger) {
|
|
|
435
434
|
const keyStr = stringifyMessageKey(key)
|
|
436
435
|
const existing = data.messageUpserts[keyStr]
|
|
437
436
|
if (existing) {
|
|
438
|
-
|
|
437
|
+
updateMessageWithReaction(existing.message, reaction)
|
|
439
438
|
}
|
|
440
439
|
else {
|
|
441
440
|
data.messageReactions[keyStr] = data.messageReactions[keyStr]
|
|
442
441
|
|| { key, reactions: [] }
|
|
443
|
-
|
|
442
|
+
updateMessageWithReaction(data.messageReactions[keyStr], reaction)
|
|
444
443
|
}
|
|
445
444
|
}
|
|
446
445
|
break
|
|
@@ -450,12 +449,12 @@ function append(data, historyCache, event, eventData, logger) {
|
|
|
450
449
|
const keyStr = stringifyMessageKey(key)
|
|
451
450
|
const existing = data.messageUpserts[keyStr]
|
|
452
451
|
if (existing) {
|
|
453
|
-
|
|
452
|
+
updateMessageWithReceipt(existing.message, receipt)
|
|
454
453
|
}
|
|
455
454
|
else {
|
|
456
455
|
data.messageReceipts[keyStr] = data.messageReceipts[keyStr]
|
|
457
456
|
|| { key, userReceipt: [] }
|
|
458
|
-
|
|
457
|
+
updateMessageWithReceipt(data.messageReceipts[keyStr], receipt)
|
|
459
458
|
}
|
|
460
459
|
}
|
|
461
460
|
break
|
|
@@ -494,8 +493,8 @@ function append(data, historyCache, event, eventData, logger) {
|
|
|
494
493
|
// if the message has already been marked read by us
|
|
495
494
|
const chatId = message.key.remoteJid
|
|
496
495
|
const chat = data.chatUpdates[chatId] || data.chatUpserts[chatId]
|
|
497
|
-
if (
|
|
498
|
-
&&
|
|
496
|
+
if (isRealMessage(message, '')
|
|
497
|
+
&& shouldIncrementChatUnread(message)
|
|
499
498
|
&& typeof (chat?.unreadCount) === 'number'
|
|
500
499
|
&& chat.unreadCount > 0) {
|
|
501
500
|
logger.debug({ chatId: chat.id }, 'decrementing chat counter')
|
package/lib/Utils/generics.js
CHANGED
|
@@ -1,46 +1,21 @@
|
|
|
1
1
|
"use strict"
|
|
2
2
|
|
|
3
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
-
if (k2 === undefined) k2 = k
|
|
5
|
-
var desc = Object.getOwnPropertyDescriptor(m, k)
|
|
6
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = { enumerable: true, get: function() { return m[k] } }
|
|
8
|
-
}
|
|
9
|
-
Object.defineProperty(o, k2, desc)
|
|
10
|
-
}) : (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k
|
|
12
|
-
o[k2] = m[k]
|
|
13
|
-
}))
|
|
14
|
-
|
|
15
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
16
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v })
|
|
17
|
-
}) : function(o, v) {
|
|
18
|
-
o["default"] = v
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
|
-
if (mod && mod.__esModule) return mod
|
|
23
|
-
var result = {}
|
|
24
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k)
|
|
25
|
-
__setModuleDefault(result, mod)
|
|
26
|
-
return result
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
30
|
-
return (mod && mod.__esModule) ? mod : { "default": mod }
|
|
31
|
-
}
|
|
32
|
-
|
|
33
3
|
Object.defineProperty(exports, "__esModule", { value: true })
|
|
34
4
|
|
|
35
|
-
const
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
5
|
+
const { Boom } = require("@hapi/boom")
|
|
6
|
+
const {
|
|
7
|
+
createHash,
|
|
8
|
+
randomBytes
|
|
9
|
+
} = require("crypto")
|
|
10
|
+
const {
|
|
11
|
+
jidDecode,
|
|
12
|
+
getAllBinaryNodeChildren
|
|
13
|
+
} = require("../WABinary")
|
|
14
|
+
const { sha256 } = require("./crypto")
|
|
15
|
+
const { platform } = require("os")
|
|
16
|
+
const { proto } = require("../../WAProto")
|
|
17
|
+
const { version } = require("../Defaults/baileys-version.json")
|
|
18
|
+
const { DisconnectReason } = require("../Types")
|
|
44
19
|
|
|
45
20
|
const COMPANION_PLATFORM_MAP = {
|
|
46
21
|
'Chrome': '49',
|
|
@@ -137,7 +112,7 @@ const Browsers = {
|
|
|
137
112
|
return [PLATFORM_MAP['chromeos'], browser, PLATFORM_VERSIONS['chromeos']]
|
|
138
113
|
},
|
|
139
114
|
appropriate: (browser) => {
|
|
140
|
-
const platform =
|
|
115
|
+
const platform = platform()
|
|
141
116
|
const platformName = PLATFORM_MAP[platform] || 'Unknown OS'
|
|
142
117
|
return [platformName, browser, PLATFORM_VERSIONS[platform] || 'latest']
|
|
143
118
|
},
|
|
@@ -149,17 +124,18 @@ const Browsers = {
|
|
|
149
124
|
|
|
150
125
|
const Itsuki = async () => {
|
|
151
126
|
try {
|
|
152
|
-
const
|
|
153
|
-
|
|
154
|
-
})
|
|
127
|
+
const response = await fetch('https://raw.githubusercontent.com/Itsukichann/database/refs/heads/main/itsuki.json', {
|
|
128
|
+
method: 'GET'
|
|
129
|
+
})
|
|
130
|
+
const data = await response.json()
|
|
155
131
|
if (Array.isArray(data)) {
|
|
156
132
|
const itsukichann = data[Math.floor(Math.random() * data.length)]
|
|
157
133
|
return itsukichann
|
|
158
134
|
} else {
|
|
159
|
-
throw new
|
|
135
|
+
throw new Boom('Data is not in array format.')
|
|
160
136
|
}
|
|
161
137
|
} catch (error) {
|
|
162
|
-
throw new
|
|
138
|
+
throw new Boom(error.message)
|
|
163
139
|
}
|
|
164
140
|
}
|
|
165
141
|
|
|
@@ -182,7 +158,7 @@ const BufferJSON = {
|
|
|
182
158
|
}
|
|
183
159
|
|
|
184
160
|
const getPlatformId = (browser) => {
|
|
185
|
-
const platformType =
|
|
161
|
+
const platformType = proto.DeviceProps.PlatformType[browser.toUpperCase()]
|
|
186
162
|
return platformType ? platformType.toString() : '1'
|
|
187
163
|
}
|
|
188
164
|
|
|
@@ -191,7 +167,7 @@ const getKeyAuthor = (key, meId = 'me') => {
|
|
|
191
167
|
}
|
|
192
168
|
|
|
193
169
|
const writeRandomPadMax16 = (msg) => {
|
|
194
|
-
const pad =
|
|
170
|
+
const pad = randomBytes(1)
|
|
195
171
|
const padLength = (pad[0] & 0x0f) + 1
|
|
196
172
|
|
|
197
173
|
return Buffer.concat([msg, Buffer.alloc(padLength, padLength)])
|
|
@@ -210,15 +186,15 @@ const unpadRandomMax16 = (e) => {
|
|
|
210
186
|
}
|
|
211
187
|
|
|
212
188
|
const encodeWAMessage = (message) => {
|
|
213
|
-
return writeRandomPadMax16(
|
|
189
|
+
return writeRandomPadMax16(proto.Message.encode(message).finish())
|
|
214
190
|
}
|
|
215
191
|
|
|
216
192
|
const encodeNewsletterMessage = (message) => {
|
|
217
|
-
return
|
|
193
|
+
return proto.Message.encode(message).finish()
|
|
218
194
|
}
|
|
219
195
|
|
|
220
196
|
const generateRegistrationId = () => {
|
|
221
|
-
return Uint16Array.from(
|
|
197
|
+
return Uint16Array.from(randomBytes(2))[0] & 16383
|
|
222
198
|
}
|
|
223
199
|
|
|
224
200
|
const encodeBigEndian = (e, t = 4) => {
|
|
@@ -268,7 +244,7 @@ const delayCancellable = (ms) => {
|
|
|
268
244
|
})
|
|
269
245
|
const cancel = () => {
|
|
270
246
|
clearTimeout(timeout)
|
|
271
|
-
reject(new
|
|
247
|
+
reject(new Boom('Cancelled', {
|
|
272
248
|
statusCode: 500,
|
|
273
249
|
data: {
|
|
274
250
|
stack
|
|
@@ -286,8 +262,8 @@ async function promiseTimeout(ms, promise) {
|
|
|
286
262
|
// Create a promise that rejects in <ms> milliseconds
|
|
287
263
|
const { delay, cancel } = delayCancellable(ms)
|
|
288
264
|
const p = new Promise((resolve, reject) => {
|
|
289
|
-
delay.then(() => reject(new
|
|
290
|
-
statusCode:
|
|
265
|
+
delay.then(() => reject(new Boom('Timed Out', {
|
|
266
|
+
statusCode: DisconnectReason.timedOut,
|
|
291
267
|
data: {
|
|
292
268
|
stack
|
|
293
269
|
}
|
|
@@ -298,20 +274,26 @@ async function promiseTimeout(ms, promise) {
|
|
|
298
274
|
}
|
|
299
275
|
|
|
300
276
|
const generateMessageID = (userId) => {
|
|
301
|
-
const
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
277
|
+
const data = Buffer.alloc(8 + 20 + 16)
|
|
278
|
+
data.writeBigUInt64BE(BigInt(Math.floor(Date.now() / 1000)))
|
|
279
|
+
if (userId) {
|
|
280
|
+
const id = jidDecode(userId)
|
|
281
|
+
if (id?.user) {
|
|
282
|
+
data.write(id.user, 8)
|
|
283
|
+
data.write('@c.us', 8 + id.user.length)
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
const random = randomBytes(20)
|
|
287
|
+
random.copy(data, 28)
|
|
288
|
+
const sha = asciiDecode([ 83, 85, 75, 73 ])
|
|
289
|
+
const hash = createHash('sha256').update(data).digest()
|
|
290
|
+
return sha + hash.toString('hex').toUpperCase().substring(0, 16)
|
|
311
291
|
}
|
|
292
|
+
|
|
293
|
+
// code is inspired by whatsmeow
|
|
312
294
|
const generateParticipantHashV2 = (participants) => {
|
|
313
295
|
participants.sort()
|
|
314
|
-
const sha256Hash =
|
|
296
|
+
const sha256Hash = sha256(Buffer.from(participants.join(''))).toString('base64')
|
|
315
297
|
return '2:' + sha256Hash.slice(0, 6)
|
|
316
298
|
};
|
|
317
299
|
|
|
@@ -323,7 +305,7 @@ function bindWaitForEvent(ev, event) {
|
|
|
323
305
|
closeListener = ({ connection, lastDisconnect }) => {
|
|
324
306
|
if (connection === 'close') {
|
|
325
307
|
reject((lastDisconnect?.error)
|
|
326
|
-
|| new
|
|
308
|
+
|| new Boom('Connection Closed', { statusCode: DisconnectReason.connectionClosed }))
|
|
327
309
|
}
|
|
328
310
|
}
|
|
329
311
|
ev.on('connection.update', closeListener)
|
|
@@ -363,18 +345,19 @@ const printQRIfNecessaryListener = (ev, logger) => {
|
|
|
363
345
|
const fetchLatestBaileysVersion = async (options = {}) => {
|
|
364
346
|
const URL = 'https://raw.githubusercontent.com/Itsukichann/Baileys/refs/heads/master/lib/Defaults/baileys-version.json'
|
|
365
347
|
try {
|
|
366
|
-
const result = await
|
|
348
|
+
const result = await fetch(URL, {
|
|
367
349
|
...options,
|
|
368
|
-
|
|
350
|
+
method: 'GET'
|
|
369
351
|
})
|
|
352
|
+
const json = await result.json()
|
|
370
353
|
return {
|
|
371
|
-
version:
|
|
354
|
+
version: json.version,
|
|
372
355
|
isLatest: true
|
|
373
356
|
}
|
|
374
357
|
}
|
|
375
358
|
catch (error) {
|
|
376
359
|
return {
|
|
377
|
-
version:
|
|
360
|
+
version: version,
|
|
378
361
|
isLatest: false,
|
|
379
362
|
error
|
|
380
363
|
}
|
|
@@ -401,7 +384,7 @@ const fetchLatestWaWebVersion = async (options = {}) => {
|
|
|
401
384
|
})
|
|
402
385
|
|
|
403
386
|
if (!response.ok) {
|
|
404
|
-
throw new
|
|
387
|
+
throw new Boom(`Failed to fetch sw.js: ${response.statusText}`, { statusCode: response.status })
|
|
405
388
|
}
|
|
406
389
|
|
|
407
390
|
const data = await response.text()
|
|
@@ -410,7 +393,7 @@ const fetchLatestWaWebVersion = async (options = {}) => {
|
|
|
410
393
|
|
|
411
394
|
if (!match?.[1]) {
|
|
412
395
|
return {
|
|
413
|
-
version:
|
|
396
|
+
version: version,
|
|
414
397
|
isLatest: false,
|
|
415
398
|
error: {
|
|
416
399
|
message: 'Could not find client revision in the fetched content'
|
|
@@ -426,7 +409,7 @@ const fetchLatestWaWebVersion = async (options = {}) => {
|
|
|
426
409
|
}
|
|
427
410
|
catch (error) {
|
|
428
411
|
return {
|
|
429
|
-
version:
|
|
412
|
+
version: version,
|
|
430
413
|
isLatest: false,
|
|
431
414
|
error
|
|
432
415
|
}
|
|
@@ -435,15 +418,15 @@ const fetchLatestWaWebVersion = async (options = {}) => {
|
|
|
435
418
|
|
|
436
419
|
/** unique message tag prefix for MD clients */
|
|
437
420
|
const generateMdTagPrefix = () => {
|
|
438
|
-
const bytes =
|
|
421
|
+
const bytes = randomBytes(4)
|
|
439
422
|
return `${bytes.readUInt16BE()}.${bytes.readUInt16BE(2)}-`
|
|
440
423
|
}
|
|
441
424
|
|
|
442
425
|
const STATUS_MAP = {
|
|
443
|
-
'sender':
|
|
444
|
-
'played':
|
|
445
|
-
'read':
|
|
446
|
-
'read-self':
|
|
426
|
+
'sender': proto.WebMessageInfo.Status.SERVER_ACK,
|
|
427
|
+
'played': proto.WebMessageInfo.Status.PLAYED,
|
|
428
|
+
'read': proto.WebMessageInfo.Status.READ,
|
|
429
|
+
'read-self': proto.WebMessageInfo.Status.READ
|
|
447
430
|
}
|
|
448
431
|
|
|
449
432
|
/**
|
|
@@ -453,13 +436,13 @@ const STATUS_MAP = {
|
|
|
453
436
|
const getStatusFromReceiptType = (type) => {
|
|
454
437
|
const status = STATUS_MAP[type]
|
|
455
438
|
if (typeof type === 'undefined') {
|
|
456
|
-
return
|
|
439
|
+
return proto.WebMessageInfo.Status.DELIVERY_ACK
|
|
457
440
|
}
|
|
458
441
|
return status
|
|
459
442
|
}
|
|
460
443
|
|
|
461
444
|
const CODE_MAP = {
|
|
462
|
-
conflict:
|
|
445
|
+
conflict: DisconnectReason.connectionReplaced
|
|
463
446
|
}
|
|
464
447
|
|
|
465
448
|
/**
|
|
@@ -467,10 +450,10 @@ const CODE_MAP = {
|
|
|
467
450
|
* @param reason the string reason given, eg. "conflict"
|
|
468
451
|
*/
|
|
469
452
|
const getErrorCodeFromStreamError = (node) => {
|
|
470
|
-
const [reasonNode] =
|
|
453
|
+
const [reasonNode] = getAllBinaryNodeChildren(node)
|
|
471
454
|
let reason = reasonNode?.tag || 'unknown'
|
|
472
|
-
const statusCode = +(node.attrs.code || CODE_MAP[reason] ||
|
|
473
|
-
if (statusCode ===
|
|
455
|
+
const statusCode = +(node.attrs.code || CODE_MAP[reason] || DisconnectReason.badSession)
|
|
456
|
+
if (statusCode === DisconnectReason.restartRequired) {
|
|
474
457
|
reason = 'restart required'
|
|
475
458
|
}
|
|
476
459
|
return {
|
package/lib/Utils/history.js
CHANGED
|
@@ -2,18 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true })
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const inflatePromise =
|
|
5
|
+
const { promisify } = require("util")
|
|
6
|
+
const { inflate } = require("zlib")
|
|
7
|
+
const { proto } = require("../../WAProto")
|
|
8
|
+
const { WAMessageStubType } = require("../Types")
|
|
9
|
+
const { isJidUser } = require("../WABinary")
|
|
10
|
+
const { toNumber } = require("./generics")
|
|
11
|
+
const { normalizeMessageContent } = require("./messages")
|
|
12
|
+
const { downloadContentFromMessage } = require("./messages-media")
|
|
13
|
+
const inflatePromise = promisify(inflate)
|
|
14
14
|
|
|
15
15
|
const downloadHistory = async (msg, options) => {
|
|
16
|
-
const stream = await
|
|
16
|
+
const stream = await downloadContentFromMessage(msg, 'md-msg-hist', { options })
|
|
17
17
|
const bufferArray = []
|
|
18
18
|
for await (const chunk of stream) {
|
|
19
19
|
bufferArray.push(chunk)
|
|
@@ -21,7 +21,7 @@ const downloadHistory = async (msg, options) => {
|
|
|
21
21
|
let buffer = Buffer.concat(bufferArray)
|
|
22
22
|
// decompress buffer
|
|
23
23
|
buffer = await inflatePromise(buffer)
|
|
24
|
-
const syncData =
|
|
24
|
+
const syncData = proto.HistorySync.decode(buffer)
|
|
25
25
|
return syncData
|
|
26
26
|
}
|
|
27
27
|
|
|
@@ -30,10 +30,10 @@ const processHistoryMessage = (item) => {
|
|
|
30
30
|
const contacts = []
|
|
31
31
|
const chats = []
|
|
32
32
|
switch (item.syncType) {
|
|
33
|
-
case
|
|
34
|
-
case
|
|
35
|
-
case
|
|
36
|
-
case
|
|
33
|
+
case proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP:
|
|
34
|
+
case proto.HistorySync.HistorySyncType.RECENT:
|
|
35
|
+
case proto.HistorySync.HistorySyncType.FULL:
|
|
36
|
+
case proto.HistorySync.HistorySyncType.ON_DEMAND:
|
|
37
37
|
for (const chat of item.conversations) {
|
|
38
38
|
contacts.push({
|
|
39
39
|
id: chat.id,
|
|
@@ -51,10 +51,10 @@ const processHistoryMessage = (item) => {
|
|
|
51
51
|
chat.messages = [{ message }]
|
|
52
52
|
}
|
|
53
53
|
if (!message.key.fromMe && !chat.lastMessageRecvTimestamp) {
|
|
54
|
-
chat.lastMessageRecvTimestamp =
|
|
54
|
+
chat.lastMessageRecvTimestamp = toNumber(message.messageTimestamp)
|
|
55
55
|
}
|
|
56
|
-
if (message.messageStubType ===
|
|
57
|
-
|| message.messageStubType ===
|
|
56
|
+
if (message.messageStubType === WAMessageStubType.BIZ_PRIVACY_MODE_TO_BSP
|
|
57
|
+
|| message.messageStubType === WAMessageStubType.BIZ_PRIVACY_MODE_TO_FB
|
|
58
58
|
&& message.messageStubParameters?.[0]) {
|
|
59
59
|
contacts.push({
|
|
60
60
|
id: message.key.participant || message.key.remoteJid,
|
|
@@ -65,13 +65,13 @@ const processHistoryMessage = (item) => {
|
|
|
65
65
|
chats.push({ ...chat })
|
|
66
66
|
}
|
|
67
67
|
break
|
|
68
|
-
case
|
|
68
|
+
case proto.HistorySync.HistorySyncType.PUSH_NAME:
|
|
69
69
|
for (const c of item.pushnames) {
|
|
70
70
|
contacts.push({
|
|
71
71
|
id: c.id,
|
|
72
72
|
name: c.name || undefined,
|
|
73
73
|
lid: c.lidJid || undefined,
|
|
74
|
-
jid:
|
|
74
|
+
jid: isJidUser(c.id) ? c.id : undefined
|
|
75
75
|
})
|
|
76
76
|
}
|
|
77
77
|
break
|
|
@@ -91,7 +91,7 @@ const downloadAndProcessHistorySyncNotification = async (msg, options) => {
|
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
const getHistoryMsg = (message) => {
|
|
94
|
-
const normalizedContent = !!message ?
|
|
94
|
+
const normalizedContent = !!message ? normalizeMessageContent(message) : undefined
|
|
95
95
|
const anyHistoryMsg = normalizedContent?.protocolMessage?.historySyncNotification
|
|
96
96
|
return anyHistoryMsg
|
|
97
97
|
}
|
package/lib/Utils/index.js
CHANGED
|
@@ -1,22 +1,38 @@
|
|
|
1
1
|
"use strict"
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
4
|
if (k2 === undefined) k2 = k
|
|
5
|
-
|
|
5
|
+
|
|
6
|
+
let desc = Object.getOwnPropertyDescriptor(m, k)
|
|
7
|
+
|
|
6
8
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = {
|
|
9
|
+
desc = {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function() {
|
|
12
|
+
return m[k]
|
|
13
|
+
}
|
|
14
|
+
}
|
|
8
15
|
}
|
|
9
|
-
Object.defineProperty(o, k2, desc)
|
|
10
|
-
}) : (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k
|
|
12
|
-
o[k2] = m[k]
|
|
13
|
-
}))
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
Object.defineProperty(o, k2, desc)
|
|
18
|
+
|
|
19
|
+
}) : (function(o, m, k, k2) {
|
|
20
|
+
if (k2 === undefined) k2 = k
|
|
21
|
+
o[k2] = m[k]
|
|
22
|
+
}
|
|
23
|
+
))
|
|
24
|
+
|
|
25
|
+
const __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
26
|
+
for (var p in m) {
|
|
27
|
+
if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) {
|
|
28
|
+
__createBinding(exports, m, p)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
17
31
|
}
|
|
18
32
|
|
|
19
|
-
Object.defineProperty(exports, "__esModule", {
|
|
33
|
+
Object.defineProperty(exports, "__esModule", {
|
|
34
|
+
value: true
|
|
35
|
+
})
|
|
20
36
|
|
|
21
37
|
__exportStar(require("./generics"), exports)
|
|
22
38
|
__exportStar(require("./decode-wa-message"), exports)
|
|
@@ -32,8 +48,6 @@ __exportStar(require("./chat-utils"), exports)
|
|
|
32
48
|
__exportStar(require("./lt-hash"), exports)
|
|
33
49
|
__exportStar(require("./auth-utils"), exports)
|
|
34
50
|
__exportStar(require("./baileys-event-stream"), exports)
|
|
35
|
-
__exportStar(require("./use-mongo-file-auth-state"), exports)
|
|
36
|
-
__exportStar(require("./use-single-file-auth-state"), exports)
|
|
37
51
|
__exportStar(require("./use-multi-file-auth-state"), exports)
|
|
38
52
|
__exportStar(require("./link-preview"), exports)
|
|
39
53
|
__exportStar(require("./event-buffer"), exports)
|
|
@@ -1,41 +1,18 @@
|
|
|
1
1
|
"use strict"
|
|
2
2
|
|
|
3
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
-
if (k2 === undefined) k2 = k
|
|
5
|
-
var desc = Object.getOwnPropertyDescriptor(m, k)
|
|
6
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = { enumerable: true, get: function() { return m[k] } }
|
|
8
|
-
}
|
|
9
|
-
Object.defineProperty(o, k2, desc)
|
|
10
|
-
}) : (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k
|
|
12
|
-
o[k2] = m[k]
|
|
13
|
-
}))
|
|
14
|
-
|
|
15
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
16
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v })
|
|
17
|
-
}) : function(o, v) {
|
|
18
|
-
o["default"] = v
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
|
-
if (mod && mod.__esModule) return mod
|
|
23
|
-
var result = {}
|
|
24
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k)
|
|
25
|
-
__setModuleDefault(result, mod)
|
|
26
|
-
return result
|
|
27
|
-
}
|
|
28
|
-
|
|
29
3
|
Object.defineProperty(exports, "__esModule", { value: true })
|
|
30
4
|
|
|
31
|
-
const
|
|
32
|
-
const
|
|
5
|
+
const { prepareWAMessageMedia } = require("./messages")
|
|
6
|
+
const {
|
|
7
|
+
getHttpStream,
|
|
8
|
+
extractImageThumb
|
|
9
|
+
} = require("./messages-media")
|
|
33
10
|
const THUMBNAIL_WIDTH_PX = 192
|
|
34
11
|
|
|
35
12
|
/** Fetches an image and generates a thumbnail for it */
|
|
36
13
|
const getCompressedJpegThumbnail = async (url, { thumbnailWidth, fetchOpts }) => {
|
|
37
|
-
const stream = await
|
|
38
|
-
const result = await
|
|
14
|
+
const stream = await getHttpStream(url, fetchOpts)
|
|
15
|
+
const result = await extractImageThumb(stream, thumbnailWidth)
|
|
39
16
|
return result
|
|
40
17
|
}
|
|
41
18
|
|
package/lib/Utils/logger.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict"
|
|
2
|
-
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod }
|
|
4
|
-
}
|
|
2
|
+
|
|
5
3
|
Object.defineProperty(exports, "__esModule", { value: true })
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
|
|
5
|
+
const pino = require("pino")
|
|
6
|
+
|
|
7
|
+
exports.default = pino({ timestamp: () => `,"time":"${new Date().toJSON()}"` })
|
package/lib/Utils/lt-hash.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true })
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const { hkdf } = require("./crypto")
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* LT Hash is a summation based hash algorithm that maintains the integrity of a piece of data
|
|
@@ -34,12 +34,12 @@ class d {
|
|
|
34
34
|
}
|
|
35
35
|
async _addSingle(e, t) {
|
|
36
36
|
var r = this
|
|
37
|
-
const n = new Uint8Array(await
|
|
37
|
+
const n = new Uint8Array(await hkdf(Buffer.from(t), o, { info: r.salt })).buffer
|
|
38
38
|
return r.performPointwiseWithOverflow(await e, n, ((e, t) => e + t))
|
|
39
39
|
}
|
|
40
40
|
async _subtractSingle(e, t) {
|
|
41
41
|
var r = this
|
|
42
|
-
const n = new Uint8Array(await
|
|
42
|
+
const n = new Uint8Array(await hkdf(Buffer.from(t), o, { info: r.salt })).buffer
|
|
43
43
|
return r.performPointwiseWithOverflow(await e, n, ((e, t) => e - t))
|
|
44
44
|
}
|
|
45
45
|
performPointwiseWithOverflow(e, t, r) {
|