@hansaka02/baileys 7.3.2 → 7.3.6
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/lib/Defaults/baileys-version.json +2 -2
- package/lib/Defaults/connection.js +51 -0
- package/lib/Defaults/constants.js +74 -0
- package/lib/Defaults/history.js +19 -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 +5 -18
- package/lib/Signal/Group/sender-key-distribution-message.js +7 -7
- package/lib/Signal/Group/sender-key-message.js +12 -8
- package/lib/Signal/Group/sender-key-record.js +7 -16
- package/lib/Signal/Group/sender-key-state.js +15 -61
- package/lib/Signal/Group/sender-message-key.js +2 -2
- package/lib/Signal/libsignal.js +237 -177
- package/lib/Signal/lid-mapping.js +128 -71
- package/lib/Socket/Client/types.js +2 -2
- package/lib/Socket/Client/websocket.js +25 -16
- package/lib/Socket/business.js +46 -33
- package/lib/Socket/chats.js +286 -170
- package/lib/Socket/community.js +215 -77
- package/lib/Socket/groups.js +77 -61
- package/lib/Socket/index.js +4 -4
- package/lib/Socket/messages-recv.js +629 -457
- package/lib/Socket/messages-send.js +645 -656
- package/lib/Socket/mex.js +61 -0
- package/lib/Socket/newsletter.js +166 -245
- package/lib/Socket/socket.js +396 -170
- 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/Newsletter.js +32 -25
- package/lib/Types/State.js +4 -4
- package/lib/Types/index.js +28 -12
- package/lib/Utils/auth-utils.js +212 -375
- package/lib/Utils/baileys-event-stream.js +68 -69
- package/lib/Utils/browser-utils.js +43 -0
- package/lib/Utils/business.js +63 -53
- package/lib/Utils/chat-utils.js +241 -106
- package/lib/Utils/crypto.js +25 -45
- package/lib/Utils/decode-wa-message.js +361 -311
- package/lib/Utils/event-buffer.js +97 -42
- package/lib/Utils/generics.js +90 -207
- package/lib/Utils/history.js +29 -27
- package/lib/Utils/index.js +28 -14
- package/lib/Utils/link-preview.js +24 -62
- package/lib/Utils/logger.js +5 -5
- package/lib/Utils/lt-hash.js +29 -23
- package/lib/Utils/make-mutex.js +26 -28
- package/lib/Utils/message-retry-manager.js +55 -7
- package/lib/Utils/messages-media.js +434 -247
- package/lib/Utils/messages.js +963 -917
- package/lib/Utils/noise-handler.js +60 -20
- package/lib/Utils/pre-key-manager.js +126 -0
- package/lib/Utils/process-message.js +216 -141
- package/lib/Utils/signal.js +75 -37
- package/lib/Utils/use-multi-file-auth-state.js +18 -22
- package/lib/Utils/validate-connection.js +96 -66
- package/lib/WABinary/constants.js +1268 -1268
- package/lib/WABinary/decode.js +62 -34
- package/lib/WABinary/encode.js +57 -36
- package/lib/WABinary/generic-utils.js +4 -4
- package/lib/WABinary/index.js +27 -11
- package/lib/WABinary/jid-utils.js +58 -11
- package/lib/WAM/constants.js +19064 -11563
- package/lib/WAM/encode.js +71 -14
- 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 +51 -28
- package/lib/WAUSync/index.js +27 -11
- package/lib/index.js +60 -31
- package/package.json +12 -17
- 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/Socket/usync.js +0 -83
- 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
package/lib/Utils/generics.js
CHANGED
|
@@ -1,197 +1,70 @@
|
|
|
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
|
-
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
'Firefox': '51',
|
|
49
|
-
'Opera': '53',
|
|
50
|
-
'Safari': '54',
|
|
51
|
-
'Brave': '1.79.112',
|
|
52
|
-
'Vivaldi': '6.2.3105.58',
|
|
53
|
-
'Tor': '12.5.3',
|
|
54
|
-
'Yandex': '23.7.1',
|
|
55
|
-
'Falkon': '22.08.3',
|
|
56
|
-
'Epiphany': '44.2'
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const PLATFORM_MAP = {
|
|
60
|
-
'aix': 'AIX',
|
|
61
|
-
'darwin': 'Mac OS',
|
|
62
|
-
'win32': 'Windows',
|
|
63
|
-
'android': 'Android',
|
|
64
|
-
'freebsd': 'FreeBSD',
|
|
65
|
-
'openbsd': 'OpenBSD',
|
|
66
|
-
'sunos': 'Solaris',
|
|
67
|
-
'linux': 'Linux',
|
|
68
|
-
'ubuntu': 'Ubuntu',
|
|
69
|
-
'ios': 'iOS',
|
|
70
|
-
'baileys': 'Baileys',
|
|
71
|
-
'chromeos': 'Chrome OS',
|
|
72
|
-
'tizen': 'Tizen',
|
|
73
|
-
'watchos': 'watchOS',
|
|
74
|
-
'wearos': 'Wear OS',
|
|
75
|
-
'harmonyos': 'HarmonyOS',
|
|
76
|
-
'kaios': 'KaiOS',
|
|
77
|
-
'smarttv': 'Smart TV',
|
|
78
|
-
'raspberrypi': 'Raspberry Pi OS',
|
|
79
|
-
'symbian': 'Symbian',
|
|
80
|
-
'blackberry': 'Blackberry OS',
|
|
81
|
-
'windowsphone': 'Windows Phone'
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const PLATFORM_VERSIONS = {
|
|
85
|
-
'ubuntu': '22.04.4',
|
|
86
|
-
'darwin': '18.5',
|
|
87
|
-
'win32': '10.0.22631',
|
|
88
|
-
'android': '14.0.0',
|
|
89
|
-
'freebsd': '13.2',
|
|
90
|
-
'openbsd': '7.3',
|
|
91
|
-
'sunos': '11',
|
|
92
|
-
'linux': '6.5',
|
|
93
|
-
'ios': '18.2',
|
|
94
|
-
'baileys': '6.5.0',
|
|
95
|
-
'chromeos': '117.0.5938.132',
|
|
96
|
-
'tizen': '6.5',
|
|
97
|
-
'watchos': '10.1',
|
|
98
|
-
'wearos': '4.1',
|
|
99
|
-
'harmonyos': '4.0.0',
|
|
100
|
-
'kaios': '3.1',
|
|
101
|
-
'smarttv': '23.3.1',
|
|
102
|
-
'raspberrypi': '11 (Bullseye)',
|
|
103
|
-
'symbian': '3',
|
|
104
|
-
'blackberry': '10.3.3',
|
|
105
|
-
'windowsphone': '8.1'
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const Browsers = {
|
|
109
|
-
ubuntu: (browser) => {
|
|
110
|
-
return [PLATFORM_MAP['ubuntu'], browser, PLATFORM_VERSIONS['ubuntu']]
|
|
111
|
-
},
|
|
112
|
-
macOS: (browser) => {
|
|
113
|
-
return [PLATFORM_MAP['darwin'], browser, PLATFORM_VERSIONS['darwin']]
|
|
114
|
-
},
|
|
115
|
-
windows: (browser) => {
|
|
116
|
-
return [PLATFORM_MAP['win32'], browser, PLATFORM_VERSIONS['win32']]
|
|
117
|
-
},
|
|
118
|
-
linux: (browser) => {
|
|
119
|
-
return [PLATFORM_MAP['linux'], browser, PLATFORM_VERSIONS['linux']]
|
|
120
|
-
},
|
|
121
|
-
solaris: (browser) => {
|
|
122
|
-
return [PLATFORM_MAP['sunos'], browser, PLATFORM_VERSIONS['sunos']]
|
|
123
|
-
},
|
|
124
|
-
baileys: (browser) => {
|
|
125
|
-
return [PLATFORM_MAP['baileys'], browser, PLATFORM_VERSIONS['baileys']]
|
|
126
|
-
},
|
|
127
|
-
android: (browser) => {
|
|
128
|
-
return [PLATFORM_MAP['android'], browser, PLATFORM_VERSIONS['android']]
|
|
129
|
-
},
|
|
130
|
-
iOS: (browser) => {
|
|
131
|
-
return [PLATFORM_MAP['ios'], browser, PLATFORM_VERSIONS['ios']]
|
|
132
|
-
},
|
|
133
|
-
kaiOS: (browser) => {
|
|
134
|
-
return [PLATFORM_MAP['kaios'], browser, PLATFORM_VERSIONS['kaios']]
|
|
135
|
-
},
|
|
136
|
-
chromeOS: (browser) => {
|
|
137
|
-
return [PLATFORM_MAP['chromeos'], browser, PLATFORM_VERSIONS['chromeos']]
|
|
138
|
-
},
|
|
139
|
-
appropriate: (browser) => {
|
|
140
|
-
const platform = os_1.platform()
|
|
141
|
-
const platformName = PLATFORM_MAP[platform] || 'Unknown OS'
|
|
142
|
-
return [platformName, browser, PLATFORM_VERSIONS[platform] || 'latest']
|
|
143
|
-
},
|
|
144
|
-
custom: (platform, browser, version) => {
|
|
145
|
-
const platformName = PLATFORM_MAP[platform.toLowerCase()] || platform
|
|
146
|
-
return [platformName, browser, version || PLATFORM_VERSIONS[platform] || 'latest']
|
|
147
|
-
}
|
|
148
|
-
}
|
|
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 { proto } = require("../../WAProto")
|
|
16
|
+
const { version } = require("../Defaults/baileys-version.json")
|
|
17
|
+
const { DisconnectReason } = require("../Types")
|
|
149
18
|
|
|
150
19
|
const Itsuki = async () => {
|
|
151
20
|
try {
|
|
152
|
-
const
|
|
153
|
-
|
|
154
|
-
})
|
|
21
|
+
const response = await fetch('https://raw.githubusercontent.com/Itsukichann/database/refs/heads/main/itsuki.json', {
|
|
22
|
+
method: 'GET'
|
|
23
|
+
})
|
|
24
|
+
const data = await response.json()
|
|
155
25
|
if (Array.isArray(data)) {
|
|
156
26
|
const itsukichann = data[Math.floor(Math.random() * data.length)]
|
|
157
27
|
return itsukichann
|
|
158
28
|
} else {
|
|
159
|
-
throw new
|
|
29
|
+
throw new Boom('Data is not in array format.')
|
|
160
30
|
}
|
|
161
31
|
} catch (error) {
|
|
162
|
-
throw new
|
|
32
|
+
throw new Boom(error.message)
|
|
163
33
|
}
|
|
164
34
|
}
|
|
165
35
|
|
|
166
36
|
const BufferJSON = {
|
|
167
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
168
37
|
replacer: (k, value) => {
|
|
169
38
|
if (Buffer.isBuffer(value) || value instanceof Uint8Array || value?.type === 'Buffer') {
|
|
170
39
|
return { type: 'Buffer', data: Buffer.from(value?.data || value).toString('base64') }
|
|
171
40
|
}
|
|
172
41
|
return value
|
|
173
42
|
},
|
|
174
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
175
43
|
reviver: (_, value) => {
|
|
176
|
-
if (typeof value === 'object' &&
|
|
177
|
-
|
|
178
|
-
|
|
44
|
+
if (typeof value === 'object' && value !== null && value.type === 'Buffer' && typeof value.data === 'string') {
|
|
45
|
+
return Buffer.from(value.data, 'base64')
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
|
|
49
|
+
const keys = Object.keys(value)
|
|
50
|
+
|
|
51
|
+
if (keys.length > 0 && keys.every(k => !isNaN(parseInt(k, 10)))) {
|
|
52
|
+
const values = Object.values(value)
|
|
53
|
+
|
|
54
|
+
if (values.every(v => typeof v === 'number')) {
|
|
55
|
+
return Buffer.from(values)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
179
58
|
}
|
|
59
|
+
|
|
180
60
|
return value
|
|
181
61
|
}
|
|
182
62
|
}
|
|
183
63
|
|
|
184
|
-
const
|
|
185
|
-
const platformType = WAProto_1.proto.DeviceProps.PlatformType[browser.toUpperCase()]
|
|
186
|
-
return platformType ? platformType.toString() : '1'
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
const getKeyAuthor = (key, meId = 'me') => {
|
|
190
|
-
return key?.fromMe ? meId : key?.participant || key?.remoteJid || ''
|
|
191
|
-
}
|
|
64
|
+
const getKeyAuthor = (key, meId = 'me') => (key?.fromMe ? meId : key?.participantAlt || key?.remoteJidAlt || key?.participant || key?.remoteJid) || ''
|
|
192
65
|
|
|
193
66
|
const writeRandomPadMax16 = (msg) => {
|
|
194
|
-
const pad =
|
|
67
|
+
const pad = randomBytes(1)
|
|
195
68
|
const padLength = (pad[0] & 0x0f) + 1
|
|
196
69
|
|
|
197
70
|
return Buffer.concat([msg, Buffer.alloc(padLength, padLength)])
|
|
@@ -210,15 +83,15 @@ const unpadRandomMax16 = (e) => {
|
|
|
210
83
|
}
|
|
211
84
|
|
|
212
85
|
const encodeWAMessage = (message) => {
|
|
213
|
-
return writeRandomPadMax16(
|
|
86
|
+
return writeRandomPadMax16(proto.Message.encode(message).finish())
|
|
214
87
|
}
|
|
215
88
|
|
|
216
89
|
const encodeNewsletterMessage = (message) => {
|
|
217
|
-
return
|
|
90
|
+
return proto.Message.encode(message).finish()
|
|
218
91
|
}
|
|
219
92
|
|
|
220
93
|
const generateRegistrationId = () => {
|
|
221
|
-
return Uint16Array.from(
|
|
94
|
+
return Uint16Array.from(randomBytes(2))[0] & 16383
|
|
222
95
|
}
|
|
223
96
|
|
|
224
97
|
const encodeBigEndian = (e, t = 4) => {
|
|
@@ -254,9 +127,7 @@ const debouncedTimeout = (intervalMs = 1000, task) => {
|
|
|
254
127
|
}
|
|
255
128
|
}
|
|
256
129
|
|
|
257
|
-
const delay = (ms) =>
|
|
258
|
-
return delayCancellable(ms).delay
|
|
259
|
-
}
|
|
130
|
+
const delay = (ms) => delayCancellable(ms).delay
|
|
260
131
|
|
|
261
132
|
const delayCancellable = (ms) => {
|
|
262
133
|
const stack = new Error().stack
|
|
@@ -268,7 +139,7 @@ const delayCancellable = (ms) => {
|
|
|
268
139
|
})
|
|
269
140
|
const cancel = () => {
|
|
270
141
|
clearTimeout(timeout)
|
|
271
|
-
reject(new
|
|
142
|
+
reject(new Boom('Cancelled', {
|
|
272
143
|
statusCode: 500,
|
|
273
144
|
data: {
|
|
274
145
|
stack
|
|
@@ -286,8 +157,8 @@ async function promiseTimeout(ms, promise) {
|
|
|
286
157
|
// Create a promise that rejects in <ms> milliseconds
|
|
287
158
|
const { delay, cancel } = delayCancellable(ms)
|
|
288
159
|
const p = new Promise((resolve, reject) => {
|
|
289
|
-
delay.then(() => reject(new
|
|
290
|
-
statusCode:
|
|
160
|
+
delay.then(() => reject(new Boom('Timed Out', {
|
|
161
|
+
statusCode: DisconnectReason.timedOut,
|
|
291
162
|
data: {
|
|
292
163
|
stack
|
|
293
164
|
}
|
|
@@ -298,22 +169,28 @@ async function promiseTimeout(ms, promise) {
|
|
|
298
169
|
}
|
|
299
170
|
|
|
300
171
|
const generateMessageID = (userId) => {
|
|
301
|
-
const
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
172
|
+
const data = Buffer.alloc(8 + 20 + 16)
|
|
173
|
+
data.writeBigUInt64BE(BigInt(Math.floor(Date.now() / 1000)))
|
|
174
|
+
if (userId) {
|
|
175
|
+
const id = jidDecode(userId)
|
|
176
|
+
if (id?.user) {
|
|
177
|
+
data.write(id.user, 8)
|
|
178
|
+
data.write('@c.us', 8 + id.user.length)
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
const random = randomBytes(20)
|
|
182
|
+
random.copy(data, 28)
|
|
183
|
+
const sha = asciiDecode([ 83, 85, 75, 73 ])
|
|
184
|
+
const hash = createHash('sha256').update(data).digest()
|
|
185
|
+
return sha + hash.toString('hex').toUpperCase().substring(0, 16)
|
|
311
186
|
}
|
|
187
|
+
|
|
188
|
+
// code is inspired by whatsmeow
|
|
312
189
|
const generateParticipantHashV2 = (participants) => {
|
|
313
190
|
participants.sort()
|
|
314
|
-
const sha256Hash =
|
|
191
|
+
const sha256Hash = sha256(Buffer.from(participants.join(''))).toString('base64')
|
|
315
192
|
return '2:' + sha256Hash.slice(0, 6)
|
|
316
|
-
}
|
|
193
|
+
}
|
|
317
194
|
|
|
318
195
|
function bindWaitForEvent(ev, event) {
|
|
319
196
|
return async (check, timeoutMs) => {
|
|
@@ -323,7 +200,7 @@ function bindWaitForEvent(ev, event) {
|
|
|
323
200
|
closeListener = ({ connection, lastDisconnect }) => {
|
|
324
201
|
if (connection === 'close') {
|
|
325
202
|
reject((lastDisconnect?.error)
|
|
326
|
-
|| new
|
|
203
|
+
|| new Boom('Connection Closed', { statusCode: DisconnectReason.connectionClosed }))
|
|
327
204
|
}
|
|
328
205
|
}
|
|
329
206
|
ev.on('connection.update', closeListener)
|
|
@@ -363,18 +240,19 @@ const printQRIfNecessaryListener = (ev, logger) => {
|
|
|
363
240
|
const fetchLatestBaileysVersion = async (options = {}) => {
|
|
364
241
|
const URL = 'https://raw.githubusercontent.com/Itsukichann/Baileys/refs/heads/master/lib/Defaults/baileys-version.json'
|
|
365
242
|
try {
|
|
366
|
-
const result = await
|
|
243
|
+
const result = await fetch(URL, {
|
|
367
244
|
...options,
|
|
368
|
-
|
|
245
|
+
method: 'GET'
|
|
369
246
|
})
|
|
247
|
+
const json = await result.json()
|
|
370
248
|
return {
|
|
371
|
-
version:
|
|
249
|
+
version: json.version,
|
|
372
250
|
isLatest: true
|
|
373
251
|
}
|
|
374
252
|
}
|
|
375
253
|
catch (error) {
|
|
376
254
|
return {
|
|
377
|
-
version:
|
|
255
|
+
version: version,
|
|
378
256
|
isLatest: false,
|
|
379
257
|
error
|
|
380
258
|
}
|
|
@@ -401,7 +279,7 @@ const fetchLatestWaWebVersion = async (options = {}) => {
|
|
|
401
279
|
})
|
|
402
280
|
|
|
403
281
|
if (!response.ok) {
|
|
404
|
-
throw new
|
|
282
|
+
throw new Boom(`Failed to fetch sw.js: ${response.statusText}`, { statusCode: response.status })
|
|
405
283
|
}
|
|
406
284
|
|
|
407
285
|
const data = await response.text()
|
|
@@ -410,7 +288,7 @@ const fetchLatestWaWebVersion = async (options = {}) => {
|
|
|
410
288
|
|
|
411
289
|
if (!match?.[1]) {
|
|
412
290
|
return {
|
|
413
|
-
version:
|
|
291
|
+
version: version,
|
|
414
292
|
isLatest: false,
|
|
415
293
|
error: {
|
|
416
294
|
message: 'Could not find client revision in the fetched content'
|
|
@@ -426,7 +304,7 @@ const fetchLatestWaWebVersion = async (options = {}) => {
|
|
|
426
304
|
}
|
|
427
305
|
catch (error) {
|
|
428
306
|
return {
|
|
429
|
-
version:
|
|
307
|
+
version: version,
|
|
430
308
|
isLatest: false,
|
|
431
309
|
error
|
|
432
310
|
}
|
|
@@ -435,15 +313,15 @@ const fetchLatestWaWebVersion = async (options = {}) => {
|
|
|
435
313
|
|
|
436
314
|
/** unique message tag prefix for MD clients */
|
|
437
315
|
const generateMdTagPrefix = () => {
|
|
438
|
-
const bytes =
|
|
316
|
+
const bytes = randomBytes(4)
|
|
439
317
|
return `${bytes.readUInt16BE()}.${bytes.readUInt16BE(2)}-`
|
|
440
318
|
}
|
|
441
319
|
|
|
442
320
|
const STATUS_MAP = {
|
|
443
|
-
'sender':
|
|
444
|
-
'played':
|
|
445
|
-
'read':
|
|
446
|
-
'read-self':
|
|
321
|
+
'sender': proto.WebMessageInfo.Status.SERVER_ACK,
|
|
322
|
+
'played': proto.WebMessageInfo.Status.PLAYED,
|
|
323
|
+
'read': proto.WebMessageInfo.Status.READ,
|
|
324
|
+
'read-self': proto.WebMessageInfo.Status.READ
|
|
447
325
|
}
|
|
448
326
|
|
|
449
327
|
/**
|
|
@@ -453,13 +331,13 @@ const STATUS_MAP = {
|
|
|
453
331
|
const getStatusFromReceiptType = (type) => {
|
|
454
332
|
const status = STATUS_MAP[type]
|
|
455
333
|
if (typeof type === 'undefined') {
|
|
456
|
-
return
|
|
334
|
+
return proto.WebMessageInfo.Status.DELIVERY_ACK
|
|
457
335
|
}
|
|
458
336
|
return status
|
|
459
337
|
}
|
|
460
338
|
|
|
461
339
|
const CODE_MAP = {
|
|
462
|
-
conflict:
|
|
340
|
+
conflict: DisconnectReason.connectionReplaced
|
|
463
341
|
}
|
|
464
342
|
|
|
465
343
|
/**
|
|
@@ -467,10 +345,10 @@ const CODE_MAP = {
|
|
|
467
345
|
* @param reason the string reason given, eg. "conflict"
|
|
468
346
|
*/
|
|
469
347
|
const getErrorCodeFromStreamError = (node) => {
|
|
470
|
-
const [reasonNode] =
|
|
348
|
+
const [reasonNode] = getAllBinaryNodeChildren(node)
|
|
471
349
|
let reason = reasonNode?.tag || 'unknown'
|
|
472
|
-
const statusCode = +(node.attrs.code || CODE_MAP[reason] ||
|
|
473
|
-
if (statusCode ===
|
|
350
|
+
const statusCode = +(node.attrs.code || CODE_MAP[reason] || DisconnectReason.badSession)
|
|
351
|
+
if (statusCode === DisconnectReason.restartRequired) {
|
|
474
352
|
reason = 'restart required'
|
|
475
353
|
}
|
|
476
354
|
return {
|
|
@@ -508,15 +386,22 @@ const getCallStatusFromNode = ({ tag, attrs }) => {
|
|
|
508
386
|
return status
|
|
509
387
|
}
|
|
510
388
|
|
|
389
|
+
const UNEXPECTED_SERVER_CODE_TEXT = 'Unexpected server response: '
|
|
390
|
+
|
|
511
391
|
const getCodeFromWSError = (error) => {
|
|
512
392
|
let statusCode = 500
|
|
513
|
-
|
|
514
|
-
|
|
393
|
+
|
|
394
|
+
if (error?.message?.includes(UNEXPECTED_SERVER_CODE_TEXT)) {
|
|
395
|
+
const code = +error?.message.slice(UNEXPECTED_SERVER_CODE_TEXT.length)
|
|
396
|
+
|
|
515
397
|
if (!Number.isNaN(code) && code >= 400) {
|
|
516
398
|
statusCode = code
|
|
517
399
|
}
|
|
518
400
|
}
|
|
519
|
-
else if (
|
|
401
|
+
else if (
|
|
402
|
+
error?.code?.startsWith('E') ||
|
|
403
|
+
error?.message?.includes('timed out')) {
|
|
404
|
+
// handle ETIMEOUT, ENOTFOUND etc
|
|
520
405
|
statusCode = 408
|
|
521
406
|
}
|
|
522
407
|
return statusCode
|
|
@@ -577,10 +462,8 @@ const asciiDecode = (...codes) => {
|
|
|
577
462
|
}
|
|
578
463
|
|
|
579
464
|
module.exports = {
|
|
580
|
-
Browsers,
|
|
581
465
|
Itsuki,
|
|
582
466
|
BufferJSON,
|
|
583
|
-
getPlatformId,
|
|
584
467
|
getKeyAuthor,
|
|
585
468
|
writeRandomPadMax16,
|
|
586
469
|
unpadRandomMax16,
|
package/lib/Utils/history.js
CHANGED
|
@@ -2,18 +2,17 @@
|
|
|
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 = util_1.promisify(zlib_1.inflate)
|
|
5
|
+
const { promisify } = require("util")
|
|
6
|
+
const { inflate } = require("zlib")
|
|
7
|
+
const { proto } = require("../../WAProto")
|
|
8
|
+
const { WAMessageStubType } = require("../Types")
|
|
9
|
+
const { toNumber } = require("./generics")
|
|
10
|
+
const { normalizeMessageContent } = require("./messages")
|
|
11
|
+
const { downloadContentFromMessage } = require("./messages-media")
|
|
12
|
+
const inflatePromise = promisify(inflate)
|
|
14
13
|
|
|
15
14
|
const downloadHistory = async (msg, options) => {
|
|
16
|
-
const stream = await
|
|
15
|
+
const stream = await downloadContentFromMessage(msg, 'md-msg-hist', { options })
|
|
17
16
|
const bufferArray = []
|
|
18
17
|
for await (const chunk of stream) {
|
|
19
18
|
bufferArray.push(chunk)
|
|
@@ -21,7 +20,7 @@ const downloadHistory = async (msg, options) => {
|
|
|
21
20
|
let buffer = Buffer.concat(bufferArray)
|
|
22
21
|
// decompress buffer
|
|
23
22
|
buffer = await inflatePromise(buffer)
|
|
24
|
-
const syncData =
|
|
23
|
+
const syncData = proto.HistorySync.decode(buffer)
|
|
25
24
|
return syncData
|
|
26
25
|
}
|
|
27
26
|
|
|
@@ -30,10 +29,10 @@ const processHistoryMessage = (item) => {
|
|
|
30
29
|
const contacts = []
|
|
31
30
|
const chats = []
|
|
32
31
|
switch (item.syncType) {
|
|
33
|
-
case
|
|
34
|
-
case
|
|
35
|
-
case
|
|
36
|
-
case
|
|
32
|
+
case proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP:
|
|
33
|
+
case proto.HistorySync.HistorySyncType.RECENT:
|
|
34
|
+
case proto.HistorySync.HistorySyncType.FULL:
|
|
35
|
+
case proto.HistorySync.HistorySyncType.ON_DEMAND:
|
|
37
36
|
for (const chat of item.conversations) {
|
|
38
37
|
contacts.push({
|
|
39
38
|
id: chat.id,
|
|
@@ -51,10 +50,10 @@ const processHistoryMessage = (item) => {
|
|
|
51
50
|
chat.messages = [{ message }]
|
|
52
51
|
}
|
|
53
52
|
if (!message.key.fromMe && !chat.lastMessageRecvTimestamp) {
|
|
54
|
-
chat.lastMessageRecvTimestamp =
|
|
53
|
+
chat.lastMessageRecvTimestamp = toNumber(message.messageTimestamp)
|
|
55
54
|
}
|
|
56
|
-
if (message.messageStubType ===
|
|
57
|
-
|| message.messageStubType ===
|
|
55
|
+
if (message.messageStubType === WAMessageStubType.BIZ_PRIVACY_MODE_TO_BSP
|
|
56
|
+
|| message.messageStubType === WAMessageStubType.BIZ_PRIVACY_MODE_TO_FB
|
|
58
57
|
&& message.messageStubParameters?.[0]) {
|
|
59
58
|
contacts.push({
|
|
60
59
|
id: message.key.participant || message.key.remoteJid,
|
|
@@ -65,14 +64,9 @@ const processHistoryMessage = (item) => {
|
|
|
65
64
|
chats.push({ ...chat })
|
|
66
65
|
}
|
|
67
66
|
break
|
|
68
|
-
case
|
|
67
|
+
case proto.HistorySync.HistorySyncType.PUSH_NAME:
|
|
69
68
|
for (const c of item.pushnames) {
|
|
70
|
-
contacts.push({
|
|
71
|
-
id: c.id,
|
|
72
|
-
name: c.name || undefined,
|
|
73
|
-
lid: c.lidJid || undefined,
|
|
74
|
-
jid: WABinary_1.isJidUser(c.id) ? c.id : undefined
|
|
75
|
-
})
|
|
69
|
+
contacts.push({ id: c.id, notify: c.pushname })
|
|
76
70
|
}
|
|
77
71
|
break
|
|
78
72
|
}
|
|
@@ -86,12 +80,20 @@ const processHistoryMessage = (item) => {
|
|
|
86
80
|
}
|
|
87
81
|
|
|
88
82
|
const downloadAndProcessHistorySyncNotification = async (msg, options) => {
|
|
89
|
-
|
|
83
|
+
let historyMsg
|
|
84
|
+
|
|
85
|
+
if (msg.initialHistBootstrapInlinePayload) {
|
|
86
|
+
historyMsg = proto.HistorySync.decode(await inflatePromise(msg.initialHistBootstrapInlinePayload))
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
historyMsg = await downloadHistory(msg, options)
|
|
90
|
+
}
|
|
91
|
+
|
|
90
92
|
return processHistoryMessage(historyMsg)
|
|
91
93
|
}
|
|
92
94
|
|
|
93
95
|
const getHistoryMsg = (message) => {
|
|
94
|
-
const normalizedContent = !!message ?
|
|
96
|
+
const normalizedContent = !!message ? normalizeMessageContent(message) : undefined
|
|
95
97
|
const anyHistoryMsg = normalizedContent?.protocolMessage?.historySyncNotification
|
|
96
98
|
return anyHistoryMsg
|
|
97
99
|
}
|
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)
|
|
@@ -31,9 +47,7 @@ __exportStar(require("./history"), exports)
|
|
|
31
47
|
__exportStar(require("./chat-utils"), exports)
|
|
32
48
|
__exportStar(require("./lt-hash"), exports)
|
|
33
49
|
__exportStar(require("./auth-utils"), exports)
|
|
34
|
-
__exportStar(require("./
|
|
35
|
-
__exportStar(require("./use-mongo-file-auth-state"), exports)
|
|
36
|
-
__exportStar(require("./use-single-file-auth-state"), exports)
|
|
50
|
+
__exportStar(require("./browser-utils"), 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)
|