@sixcore/baileys 1.0.0 → 1.0.2
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/WAProto/index.js +14270 -302
- package/jessica.js +91 -0
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.js +117 -79
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
- package/lib/Signal/Group/ciphertext-message.js +15 -0
- package/lib/Signal/Group/group-session-builder.d.ts +14 -0
- package/lib/Signal/Group/group-session-builder.js +64 -0
- package/lib/Signal/Group/group_cipher.d.ts +17 -0
- package/lib/Signal/Group/group_cipher.js +96 -0
- package/lib/Signal/Group/index.d.ts +11 -0
- package/lib/Signal/Group/index.js +57 -0
- package/lib/Signal/Group/keyhelper.d.ts +10 -0
- package/lib/Signal/Group/keyhelper.js +55 -0
- package/lib/Signal/Group/queue-job.d.ts +1 -0
- package/lib/Signal/Group/queue-job.js +57 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
- package/lib/Signal/Group/sender-chain-key.js +34 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
- package/lib/Signal/Group/sender-key-message.d.ts +18 -0
- package/lib/Signal/Group/sender-key-message.js +69 -0
- package/lib/Signal/Group/sender-key-name.d.ts +17 -0
- package/lib/Signal/Group/sender-key-name.js +51 -0
- package/lib/Signal/Group/sender-key-record.d.ts +30 -0
- package/lib/Signal/Group/sender-key-record.js +53 -0
- package/lib/Signal/Group/sender-key-state.d.ts +38 -0
- package/lib/Signal/Group/sender-key-state.js +99 -0
- package/lib/Signal/Group/sender-message-key.d.ts +11 -0
- package/{WASignalGroup/sender_message_key.js → lib/Signal/Group/sender-message-key.js} +6 -16
- package/lib/Signal/libsignal.js +51 -29
- package/lib/Socket/business.d.ts +43 -42
- package/lib/Socket/chats.d.ts +222 -36
- package/lib/Socket/chats.js +173 -153
- package/lib/Socket/dugong.d.ts +254 -0
- package/lib/Socket/dugong.js +484 -0
- package/lib/Socket/groups.d.ts +7 -7
- package/lib/Socket/groups.js +37 -35
- package/lib/Socket/index.d.ts +52 -51
- package/lib/Socket/index.js +1 -0
- package/lib/Socket/messages-recv.d.ts +37 -34
- package/lib/Socket/messages-recv.js +175 -37
- package/lib/Socket/messages-send.d.ts +12 -18
- package/lib/Socket/messages-send.js +396 -574
- package/lib/Socket/newsletter.d.ts +28 -26
- package/lib/Socket/newsletter.js +132 -121
- package/lib/Socket/registration.d.ts +52 -49
- package/lib/Socket/registration.js +7 -7
- package/lib/Socket/socket.d.ts +0 -1
- package/lib/Socket/socket.js +49 -27
- package/lib/Socket/usync.d.ts +10 -11
- package/lib/Store/make-cache-manager-store.d.ts +1 -2
- package/lib/Store/make-in-memory-store.d.ts +2 -2
- package/lib/Store/make-in-memory-store.js +1 -5
- package/lib/Store/make-ordered-dictionary.js +2 -2
- package/lib/Types/Auth.d.ts +1 -0
- package/lib/Types/Call.d.ts +1 -1
- package/lib/Types/Chat.d.ts +7 -12
- package/lib/Types/Events.d.ts +2 -17
- package/lib/Types/GroupMetadata.d.ts +2 -3
- package/lib/Types/Label.d.ts +0 -11
- package/lib/Types/Label.js +1 -1
- package/lib/Types/LabelAssociation.js +1 -1
- package/lib/Types/Message.d.ts +10 -170
- package/lib/Types/Newsletter.d.ts +97 -86
- package/lib/Types/Newsletter.js +38 -32
- package/lib/Types/Socket.d.ts +2 -7
- package/lib/Types/index.d.ts +0 -9
- package/lib/Types/index.js +1 -1
- package/lib/Utils/auth-utils.js +14 -35
- package/lib/Utils/business.d.ts +1 -1
- package/lib/Utils/business.js +2 -2
- package/lib/Utils/chat-utils.d.ts +12 -11
- package/lib/Utils/chat-utils.js +36 -52
- package/lib/Utils/crypto.d.ts +16 -15
- package/lib/Utils/crypto.js +26 -74
- package/lib/Utils/decode-wa-message.d.ts +0 -17
- package/lib/Utils/decode-wa-message.js +17 -53
- package/lib/Utils/event-buffer.js +7 -10
- package/lib/Utils/generics.d.ts +17 -13
- package/lib/Utils/generics.js +79 -58
- package/lib/Utils/history.d.ts +2 -6
- package/lib/Utils/history.js +6 -4
- package/lib/Utils/logger.d.ts +3 -1
- package/lib/Utils/lt-hash.js +12 -12
- package/lib/Utils/make-mutex.d.ts +2 -2
- package/lib/Utils/messages-media.d.ts +28 -25
- package/lib/Utils/messages-media.js +733 -557
- package/lib/Utils/messages.js +68 -473
- package/lib/Utils/noise-handler.d.ts +5 -4
- package/lib/Utils/noise-handler.js +14 -19
- package/lib/Utils/process-message.d.ts +5 -5
- package/lib/Utils/process-message.js +23 -75
- package/lib/Utils/signal.d.ts +1 -2
- package/lib/Utils/signal.js +26 -32
- package/lib/Utils/use-multi-file-auth-state.d.ts +1 -0
- package/lib/Utils/use-multi-file-auth-state.js +66 -242
- package/lib/Utils/validate-connection.d.ts +1 -1
- package/lib/Utils/validate-connection.js +88 -64
- package/lib/WABinary/constants.d.ts +27 -24
- package/lib/WABinary/decode.d.ts +2 -1
- package/lib/WABinary/decode.js +11 -23
- package/lib/WABinary/encode.d.ts +2 -1
- package/lib/WABinary/encode.js +147 -134
- package/lib/WABinary/generic-utils.d.ts +5 -2
- package/lib/WABinary/generic-utils.js +125 -37
- package/lib/WABinary/jid-utils.d.ts +1 -1
- package/lib/WAM/BinaryInfo.d.ts +11 -2
- package/lib/WAM/encode.d.ts +2 -1
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +3 -3
- package/lib/WAUSync/USyncUser.d.ts +2 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.js +64 -1
- package/package.json +113 -51
- package/WAProto/GenerateStatics.sh +0 -4
- package/WAProto/WAProto.proto +0 -4357
- package/WAProto/index.d.ts +0 -50383
- package/WASignalGroup/GroupProtocol.js +0 -1697
- package/WASignalGroup/ciphertext_message.js +0 -16
- package/WASignalGroup/generate-proto.sh +0 -1
- package/WASignalGroup/group.proto +0 -42
- package/WASignalGroup/group_cipher.js +0 -120
- package/WASignalGroup/group_session_builder.js +0 -46
- package/WASignalGroup/index.js +0 -5
- package/WASignalGroup/keyhelper.js +0 -21
- package/WASignalGroup/protobufs.js +0 -3
- package/WASignalGroup/queue_job.js +0 -69
- package/WASignalGroup/sender_chain_key.js +0 -50
- package/WASignalGroup/sender_key_distribution_message.js +0 -78
- package/WASignalGroup/sender_key_message.js +0 -92
- package/WASignalGroup/sender_key_name.js +0 -70
- package/WASignalGroup/sender_key_record.js +0 -56
- package/WASignalGroup/sender_key_state.js +0 -129
- package/lib/Utils/use-single-file-auth-state.d.ts +0 -12
- package/lib/Utils/use-single-file-auth-state.js +0 -75
- package/src/Defaults/baileys-version.json +0 -3
- package/src/Defaults/index.ts +0 -133
- package/src/Signal/Group/ciphertext-message.ts +0 -9
- package/src/Signal/Group/group-session-builder.ts +0 -56
- package/src/Signal/Group/group_cipher.ts +0 -117
- package/src/Signal/Group/index.ts +0 -11
- package/src/Signal/Group/keyhelper.ts +0 -28
- package/src/Signal/Group/sender-chain-key.ts +0 -34
- package/src/Signal/Group/sender-key-distribution-message.ts +0 -95
- package/src/Signal/Group/sender-key-message.ts +0 -96
- package/src/Signal/Group/sender-key-name.ts +0 -66
- package/src/Signal/Group/sender-key-record.ts +0 -69
- package/src/Signal/Group/sender-key-state.ts +0 -134
- package/src/Signal/Group/sender-message-key.ts +0 -36
- package/src/Signal/libsignal.ts +0 -447
- package/src/Signal/lid-mapping.ts +0 -209
- package/src/Socket/Client/index.ts +0 -2
- package/src/Socket/Client/types.ts +0 -22
- package/src/Socket/Client/websocket.ts +0 -56
- package/src/Socket/business.ts +0 -421
- package/src/Socket/chats.ts +0 -1223
- package/src/Socket/communities.ts +0 -477
- package/src/Socket/groups.ts +0 -361
- package/src/Socket/index.ts +0 -22
- package/src/Socket/messages-recv.ts +0 -1563
- package/src/Socket/messages-send.ts +0 -1210
- package/src/Socket/mex.ts +0 -58
- package/src/Socket/newsletter.ts +0 -229
- package/src/Socket/socket.ts +0 -1072
- package/src/Types/Auth.ts +0 -115
- package/src/Types/Bussines.ts +0 -20
- package/src/Types/Call.ts +0 -14
- package/src/Types/Chat.ts +0 -138
- package/src/Types/Contact.ts +0 -24
- package/src/Types/Events.ts +0 -132
- package/src/Types/GroupMetadata.ts +0 -70
- package/src/Types/Label.ts +0 -48
- package/src/Types/LabelAssociation.ts +0 -35
- package/src/Types/Message.ts +0 -424
- package/src/Types/Newsletter.ts +0 -98
- package/src/Types/Product.ts +0 -85
- package/src/Types/Signal.ts +0 -76
- package/src/Types/Socket.ts +0 -150
- package/src/Types/State.ts +0 -43
- package/src/Types/USync.ts +0 -27
- package/src/Types/globals.d.ts +0 -8
- package/src/Types/index.ts +0 -67
- package/src/Utils/auth-utils.ts +0 -331
- package/src/Utils/browser-utils.ts +0 -31
- package/src/Utils/business.ts +0 -286
- package/src/Utils/chat-utils.ts +0 -933
- package/src/Utils/crypto.ts +0 -184
- package/src/Utils/decode-wa-message.ts +0 -355
- package/src/Utils/event-buffer.ts +0 -662
- package/src/Utils/generics.ts +0 -470
- package/src/Utils/history.ts +0 -114
- package/src/Utils/index.ts +0 -18
- package/src/Utils/link-preview.ts +0 -111
- package/src/Utils/logger.ts +0 -13
- package/src/Utils/lt-hash.ts +0 -65
- package/src/Utils/make-mutex.ts +0 -45
- package/src/Utils/message-retry-manager.ts +0 -229
- package/src/Utils/messages-media.ts +0 -820
- package/src/Utils/messages.ts +0 -1137
- package/src/Utils/noise-handler.ts +0 -192
- package/src/Utils/pre-key-manager.ts +0 -126
- package/src/Utils/process-message.ts +0 -622
- package/src/Utils/signal.ts +0 -214
- package/src/Utils/use-multi-file-auth-state.ts +0 -136
- package/src/Utils/validate-connection.ts +0 -253
- package/src/WABinary/constants.ts +0 -1305
- package/src/WABinary/decode.ts +0 -281
- package/src/WABinary/encode.ts +0 -253
- package/src/WABinary/generic-utils.ts +0 -127
- package/src/WABinary/index.ts +0 -5
- package/src/WABinary/jid-utils.ts +0 -128
- package/src/WABinary/types.ts +0 -17
- package/src/WAM/BinaryInfo.ts +0 -12
- package/src/WAM/constants.ts +0 -22889
- package/src/WAM/encode.ts +0 -169
- package/src/WAM/index.ts +0 -3
- package/src/WAUSync/Protocols/USyncContactProtocol.ts +0 -32
- package/src/WAUSync/Protocols/USyncDeviceProtocol.ts +0 -78
- package/src/WAUSync/Protocols/USyncDisappearingModeProtocol.ts +0 -35
- package/src/WAUSync/Protocols/USyncStatusProtocol.ts +0 -44
- package/src/WAUSync/Protocols/UsyncBotProfileProtocol.ts +0 -76
- package/src/WAUSync/Protocols/UsyncLIDProtocol.ts +0 -33
- package/src/WAUSync/Protocols/index.ts +0 -4
- package/src/WAUSync/USyncQuery.ts +0 -133
- package/src/WAUSync/USyncUser.ts +0 -32
- package/src/WAUSync/index.ts +0 -3
- package/src/index.ts +0 -13
package/lib/Utils/generics.js
CHANGED
|
@@ -1,28 +1,19 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.isWABusinessPlatform = exports.getCodeFromWSError = exports.getCallStatusFromNode = exports.getErrorCodeFromStreamError = exports.getStatusFromReceiptType = exports.generateMdTagPrefix = exports.fetchLatestWaWebVersion = exports.fetchLatestBaileysVersion = exports.printQRIfNecessaryListener = exports.bindWaitForConnectionUpdate = exports.generateMessageID = exports.generateMessageIDV2 = exports.delayCancellable = exports.delay = exports.debouncedTimeout = exports.unixTimestampSeconds = exports.toNumber = exports.encodeBigEndian = exports.generateRegistrationId = exports.encodeWAMessage = exports.unpadRandomMax16 = exports.writeRandomPadMax16 = exports.getKeyAuthor = exports.BufferJSON = exports.
|
|
7
|
-
exports.promiseTimeout = promiseTimeout;
|
|
8
|
-
exports.bindWaitForEvent = bindWaitForEvent;
|
|
9
|
-
exports.trimUndefined = trimUndefined;
|
|
10
|
-
exports.bytesToCrockford = bytesToCrockford;
|
|
6
|
+
exports.bytesToCrockford = exports.trimUndefined = exports.isWABusinessPlatform = exports.getCodeFromWSError = exports.getCallStatusFromNode = exports.getErrorCodeFromStreamError = exports.getStatusFromReceiptType = exports.generateMdTagPrefix = exports.fetchLatestWaWebVersion = exports.fetchLatestBaileysVersion = exports.printQRIfNecessaryListener = exports.bindWaitForConnectionUpdate = exports.bindWaitForEvent = exports.generateMessageID = exports.generateMessageIDV2 = exports.promiseTimeout = exports.delayCancellable = exports.delay = exports.debouncedTimeout = exports.unixTimestampSeconds = exports.toNumber = exports.encodeBigEndian = exports.generateRegistrationId = exports.encodeWAMessage = exports.unpadRandomMax16 = exports.writeRandomPadMax16 = exports.getKeyAuthor = exports.BufferJSON = exports.Browsers = void 0;
|
|
11
7
|
const boom_1 = require("@hapi/boom");
|
|
12
8
|
const axios_1 = __importDefault(require("axios"));
|
|
13
9
|
const crypto_1 = require("crypto");
|
|
14
10
|
const os_1 = require("os");
|
|
11
|
+
const fetch_1 = require("node-fetch")
|
|
15
12
|
const WAProto_1 = require("../../WAProto");
|
|
16
13
|
const baileys_version_json_1 = require("../Defaults/baileys-version.json");
|
|
17
14
|
const Types_1 = require("../Types");
|
|
18
15
|
const WABinary_1 = require("../WABinary");
|
|
19
|
-
const
|
|
20
|
-
'Chrome': '49',
|
|
21
|
-
'Edge': '50',
|
|
22
|
-
'Firefox': '51',
|
|
23
|
-
'Opera': '53',
|
|
24
|
-
'Safari': '54'
|
|
25
|
-
};
|
|
16
|
+
const baileysVersion = [2, 3000, 1027934701]
|
|
26
17
|
const PLATFORM_MAP = {
|
|
27
18
|
'aix': 'AIX',
|
|
28
19
|
'darwin': 'Mac OS',
|
|
@@ -30,21 +21,21 @@ const PLATFORM_MAP = {
|
|
|
30
21
|
'android': 'Android',
|
|
31
22
|
'freebsd': 'FreeBSD',
|
|
32
23
|
'openbsd': 'OpenBSD',
|
|
33
|
-
'sunos': 'Solaris'
|
|
24
|
+
'sunos': 'Solaris',
|
|
25
|
+
'linux': undefined,
|
|
26
|
+
'haiku': undefined,
|
|
27
|
+
'cygwin': undefined,
|
|
28
|
+
'netbsd': undefined
|
|
34
29
|
};
|
|
35
|
-
exports.Browsers = {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
windows: (browser) => ['Windows', browser, '10.0.22631'],
|
|
40
|
-
iOS: (browser) => ['iOS', browser, '18.2'],
|
|
41
|
-
linux: (browser) => ['Linux', browser, '6.12.6'],
|
|
42
|
-
/** The appropriate browser based on your OS & release */
|
|
43
|
-
appropriate: (browser) => [PLATFORM_MAP[(0, os_1.platform)()] || 'Ubuntu', browser, (0, os_1.release)()]
|
|
30
|
+
exports.Browsers = (browser) => {
|
|
31
|
+
const osName = PLATFORM_MAP[os_1.platform()] || 'Ubuntu';
|
|
32
|
+
const osRelease = os_1.release();
|
|
33
|
+
return [osName, browser, osRelease];
|
|
44
34
|
};
|
|
35
|
+
|
|
45
36
|
const getPlatformId = (browser) => {
|
|
46
37
|
const platformType = WAProto_1.proto.DeviceProps.PlatformType[browser.toUpperCase()];
|
|
47
|
-
return platformType ? platformType.toString()
|
|
38
|
+
return platformType ? platformType.toString() : '1'; //chrome
|
|
48
39
|
};
|
|
49
40
|
exports.getPlatformId = getPlatformId;
|
|
50
41
|
exports.BufferJSON = {
|
|
@@ -101,7 +92,7 @@ const encodeBigEndian = (e, t = 4) => {
|
|
|
101
92
|
return a;
|
|
102
93
|
};
|
|
103
94
|
exports.encodeBigEndian = encodeBigEndian;
|
|
104
|
-
const toNumber = (t) => ((typeof t === 'object' && t) ? ('toNumber' in t ? t.toNumber() : t.low) : t
|
|
95
|
+
const toNumber = (t) => ((typeof t === 'object' && t) ? ('toNumber' in t ? t.toNumber() : t.low) : t);
|
|
105
96
|
exports.toNumber = toNumber;
|
|
106
97
|
/** unix timestamp of a date in seconds */
|
|
107
98
|
const unixTimestampSeconds = (date = new Date()) => Math.floor(date.getTime() / 1000);
|
|
@@ -167,6 +158,7 @@ async function promiseTimeout(ms, promise) {
|
|
|
167
158
|
.finally(cancel);
|
|
168
159
|
return p;
|
|
169
160
|
}
|
|
161
|
+
exports.promiseTimeout = promiseTimeout;
|
|
170
162
|
const generateMessageIDV2 = (userId) => {
|
|
171
163
|
const data = Buffer.alloc(8 + 20 + 16);
|
|
172
164
|
data.writeBigUInt64BE(BigInt(Math.floor(Date.now() / 1000)));
|
|
@@ -180,11 +172,11 @@ const generateMessageIDV2 = (userId) => {
|
|
|
180
172
|
const random = (0, crypto_1.randomBytes)(16);
|
|
181
173
|
random.copy(data, 28);
|
|
182
174
|
const hash = (0, crypto_1.createHash)('sha256').update(data).digest();
|
|
183
|
-
return hash.toString('hex').toUpperCase().substring(0,
|
|
175
|
+
return '3EB0' + hash.toString('hex').toUpperCase().substring(0, 18);
|
|
184
176
|
};
|
|
185
177
|
exports.generateMessageIDV2 = generateMessageIDV2;
|
|
186
178
|
// generate a random ID to attach to a message
|
|
187
|
-
const generateMessageID = () => (0, crypto_1.randomBytes)(
|
|
179
|
+
const generateMessageID = () => 'ILSYM-' + (0, crypto_1.randomBytes)(6).toString('hex').toUpperCase();
|
|
188
180
|
exports.generateMessageID = generateMessageID;
|
|
189
181
|
function bindWaitForEvent(ev, event) {
|
|
190
182
|
return async (check, timeoutMs) => {
|
|
@@ -211,6 +203,7 @@ function bindWaitForEvent(ev, event) {
|
|
|
211
203
|
}));
|
|
212
204
|
};
|
|
213
205
|
}
|
|
206
|
+
exports.bindWaitForEvent = bindWaitForEvent;
|
|
214
207
|
const bindWaitForConnectionUpdate = (ev) => bindWaitForEvent(ev, 'connection.update');
|
|
215
208
|
exports.bindWaitForConnectionUpdate = bindWaitForConnectionUpdate;
|
|
216
209
|
const printQRIfNecessaryListener = (ev, logger) => {
|
|
@@ -226,12 +219,61 @@ const printQRIfNecessaryListener = (ev, logger) => {
|
|
|
226
219
|
});
|
|
227
220
|
};
|
|
228
221
|
exports.printQRIfNecessaryListener = printQRIfNecessaryListener;
|
|
222
|
+
/**
|
|
223
|
+
* utility that fetches latest baileys version from the master branch.
|
|
224
|
+
* Use to ensure your WA connection is always on the latest version
|
|
225
|
+
*/
|
|
226
|
+
const fetchLatestWaWebVersion = async (options = {}) => {
|
|
227
|
+
try {
|
|
228
|
+
const defaultHeaders = {
|
|
229
|
+
'User-Agent':
|
|
230
|
+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
|
|
231
|
+
'Accept': '*/*'
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const headers = { ...defaultHeaders, ...options.headers }
|
|
235
|
+
|
|
236
|
+
const response = await fetch_1('https://web.whatsapp.com/sw.js', {
|
|
237
|
+
method: 'GET',
|
|
238
|
+
headers
|
|
239
|
+
})
|
|
240
|
+
|
|
241
|
+
if (!response.ok) {
|
|
242
|
+
throw new Error(`Failed to fetch sw.js: ${response.status} ${response.statusText}`)
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const data = await response.text()
|
|
246
|
+
const regex = /"client_revision":\s*(\d+)/ // regex cukup begini untuk Node
|
|
247
|
+
const match = data.match(regex)
|
|
248
|
+
|
|
249
|
+
if (!match || !match[1]) {
|
|
250
|
+
return {
|
|
251
|
+
version: baileysVersion,
|
|
252
|
+
isLatest: false,
|
|
253
|
+
error: { message: 'Client revision not found' }
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const clientRevision = match[1]
|
|
258
|
+
return {
|
|
259
|
+
version: [2, 3000, +clientRevision],
|
|
260
|
+
isLatest: true
|
|
261
|
+
}
|
|
262
|
+
} catch (error) {
|
|
263
|
+
return {
|
|
264
|
+
version: baileysVersion,
|
|
265
|
+
isLatest: false,
|
|
266
|
+
error
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
exports.fetchLatestWaWebVersion = fetchLatestWaWebVersion;
|
|
229
271
|
/**
|
|
230
272
|
* utility that fetches latest baileys version from the master branch.
|
|
231
273
|
* Use to ensure your WA connection is always on the latest version
|
|
232
274
|
*/
|
|
233
275
|
const fetchLatestBaileysVersion = async (options = {}) => {
|
|
234
|
-
const URL = 'https://raw.githubusercontent.com/
|
|
276
|
+
const URL = 'https://raw.githubusercontent.com/kiuur/bails/master/src/Defaults/baileys-version.json';
|
|
235
277
|
try {
|
|
236
278
|
const result = await axios_1.default.get(URL, {
|
|
237
279
|
...options,
|
|
@@ -251,31 +293,6 @@ const fetchLatestBaileysVersion = async (options = {}) => {
|
|
|
251
293
|
}
|
|
252
294
|
};
|
|
253
295
|
exports.fetchLatestBaileysVersion = fetchLatestBaileysVersion;
|
|
254
|
-
/**
|
|
255
|
-
* A utility that fetches the latest web version of whatsapp.
|
|
256
|
-
* Use to ensure your WA connection is always on the latest version
|
|
257
|
-
*/
|
|
258
|
-
const fetchLatestWaWebVersion = async (options) => {
|
|
259
|
-
try {
|
|
260
|
-
const result = await axios_1.default.get('https://web.whatsapp.com/check-update?version=1&platform=web', {
|
|
261
|
-
...options,
|
|
262
|
-
responseType: 'json'
|
|
263
|
-
});
|
|
264
|
-
const version = result.data.currentVersion.split('.');
|
|
265
|
-
return {
|
|
266
|
-
version: [+version[0], +version[1], +version[2]],
|
|
267
|
-
isLatest: true
|
|
268
|
-
};
|
|
269
|
-
}
|
|
270
|
-
catch (error) {
|
|
271
|
-
return {
|
|
272
|
-
version: baileys_version_json_1.version,
|
|
273
|
-
isLatest: false,
|
|
274
|
-
error
|
|
275
|
-
};
|
|
276
|
-
}
|
|
277
|
-
};
|
|
278
|
-
exports.fetchLatestWaWebVersion = fetchLatestWaWebVersion;
|
|
279
296
|
/** unique message tag prefix for MD clients */
|
|
280
297
|
const generateMdTagPrefix = () => {
|
|
281
298
|
const bytes = (0, crypto_1.randomBytes)(4);
|
|
@@ -283,7 +300,6 @@ const generateMdTagPrefix = () => {
|
|
|
283
300
|
};
|
|
284
301
|
exports.generateMdTagPrefix = generateMdTagPrefix;
|
|
285
302
|
const STATUS_MAP = {
|
|
286
|
-
'sender': WAProto_1.proto.WebMessageInfo.Status.SERVER_ACK,
|
|
287
303
|
'played': WAProto_1.proto.WebMessageInfo.Status.PLAYED,
|
|
288
304
|
'read': WAProto_1.proto.WebMessageInfo.Status.READ,
|
|
289
305
|
'read-self': WAProto_1.proto.WebMessageInfo.Status.READ
|
|
@@ -332,8 +348,7 @@ const getCallStatusFromNode = ({ tag, attrs }) => {
|
|
|
332
348
|
status = 'timeout';
|
|
333
349
|
}
|
|
334
350
|
else {
|
|
335
|
-
|
|
336
|
-
status = 'terminate';
|
|
351
|
+
status = 'reject';
|
|
337
352
|
}
|
|
338
353
|
break;
|
|
339
354
|
case 'reject':
|
|
@@ -382,13 +397,14 @@ function trimUndefined(obj) {
|
|
|
382
397
|
}
|
|
383
398
|
return obj;
|
|
384
399
|
}
|
|
400
|
+
exports.trimUndefined = trimUndefined;
|
|
385
401
|
const CROCKFORD_CHARACTERS = '123456789ABCDEFGHJKLMNPQRSTVWXYZ';
|
|
386
402
|
function bytesToCrockford(buffer) {
|
|
387
403
|
let value = 0;
|
|
388
404
|
let bitCount = 0;
|
|
389
405
|
const crockford = [];
|
|
390
|
-
for (
|
|
391
|
-
value = (value << 8) | (
|
|
406
|
+
for (let i = 0; i < buffer.length; i++) {
|
|
407
|
+
value = (value << 8) | (buffer[i] & 0xff);
|
|
392
408
|
bitCount += 8;
|
|
393
409
|
while (bitCount >= 5) {
|
|
394
410
|
crockford.push(CROCKFORD_CHARACTERS.charAt((value >>> (bitCount - 5)) & 31));
|
|
@@ -400,3 +416,8 @@ function bytesToCrockford(buffer) {
|
|
|
400
416
|
}
|
|
401
417
|
return crockford.join('');
|
|
402
418
|
}
|
|
419
|
+
exports.bytesToCrockford = bytesToCrockford;
|
|
420
|
+
const encodeNewsletterMessage = (message) => {
|
|
421
|
+
return WAProto_1.proto.Message.encode(message).finish()
|
|
422
|
+
}
|
|
423
|
+
exports.encodeNewsletterMessage = encodeNewsletterMessage;
|
package/lib/Utils/history.d.ts
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
1
|
import { AxiosRequestConfig } from 'axios';
|
|
2
2
|
import { proto } from '../../WAProto';
|
|
3
3
|
import { Chat, Contact } from '../Types';
|
|
4
|
-
export declare const downloadHistory: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<
|
|
4
|
+
export declare const downloadHistory: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<any>) => Promise<proto.HistorySync>;
|
|
5
5
|
export declare const processHistoryMessage: (item: proto.IHistorySync) => {
|
|
6
6
|
chats: Chat[];
|
|
7
7
|
contacts: Contact[];
|
|
8
8
|
messages: proto.IWebMessageInfo[];
|
|
9
|
-
syncType: proto.HistorySync.HistorySyncType;
|
|
10
|
-
progress: number | null | undefined;
|
|
11
9
|
};
|
|
12
|
-
export declare const downloadAndProcessHistorySyncNotification: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<
|
|
10
|
+
export declare const downloadAndProcessHistorySyncNotification: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<any>) => Promise<{
|
|
13
11
|
chats: Chat[];
|
|
14
12
|
contacts: Contact[];
|
|
15
13
|
messages: proto.IWebMessageInfo[];
|
|
16
|
-
syncType: proto.HistorySync.HistorySyncType;
|
|
17
|
-
progress: number | null | undefined;
|
|
18
14
|
}>;
|
|
19
15
|
export declare const getHistoryMsg: (message: proto.IMessage) => proto.Message.IHistorySyncNotification | null | undefined;
|
package/lib/Utils/history.js
CHANGED
|
@@ -32,9 +32,13 @@ const processHistoryMessage = (item) => {
|
|
|
32
32
|
case WAProto_1.proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP:
|
|
33
33
|
case WAProto_1.proto.HistorySync.HistorySyncType.RECENT:
|
|
34
34
|
case WAProto_1.proto.HistorySync.HistorySyncType.FULL:
|
|
35
|
-
case WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND:
|
|
36
35
|
for (const chat of item.conversations) {
|
|
37
|
-
contacts.push({
|
|
36
|
+
contacts.push({
|
|
37
|
+
id: chat.id,
|
|
38
|
+
name: chat.name || undefined,
|
|
39
|
+
lid: chat.lidJid || undefined,
|
|
40
|
+
jid: (0, WABinary_1.isJidUser)(chat.id) ? chat.id : undefined
|
|
41
|
+
});
|
|
38
42
|
const msgs = chat.messages || [];
|
|
39
43
|
delete chat.messages;
|
|
40
44
|
delete chat.archived;
|
|
@@ -75,8 +79,6 @@ const processHistoryMessage = (item) => {
|
|
|
75
79
|
chats,
|
|
76
80
|
contacts,
|
|
77
81
|
messages,
|
|
78
|
-
syncType: item.syncType,
|
|
79
|
-
progress: item.progress
|
|
80
82
|
};
|
|
81
83
|
};
|
|
82
84
|
exports.processHistoryMessage = processHistoryMessage;
|
package/lib/Utils/logger.d.ts
CHANGED
package/lib/Utils/lt-hash.js
CHANGED
|
@@ -12,33 +12,33 @@ class d {
|
|
|
12
12
|
constructor(e) {
|
|
13
13
|
this.salt = e;
|
|
14
14
|
}
|
|
15
|
-
|
|
15
|
+
add(e, t) {
|
|
16
16
|
var r = this;
|
|
17
17
|
for (const item of t) {
|
|
18
|
-
e =
|
|
18
|
+
e = r._addSingle(e, item);
|
|
19
19
|
}
|
|
20
20
|
return e;
|
|
21
21
|
}
|
|
22
|
-
|
|
22
|
+
subtract(e, t) {
|
|
23
23
|
var r = this;
|
|
24
24
|
for (const item of t) {
|
|
25
|
-
e =
|
|
25
|
+
e = r._subtractSingle(e, item);
|
|
26
26
|
}
|
|
27
27
|
return e;
|
|
28
28
|
}
|
|
29
|
-
|
|
29
|
+
subtractThenAdd(e, t, r) {
|
|
30
30
|
var n = this;
|
|
31
|
-
return n.add(
|
|
31
|
+
return n.add(n.subtract(e, r), t);
|
|
32
32
|
}
|
|
33
|
-
|
|
33
|
+
_addSingle(e, t) {
|
|
34
34
|
var r = this;
|
|
35
|
-
const n = new Uint8Array(
|
|
36
|
-
return r.performPointwiseWithOverflow(
|
|
35
|
+
const n = new Uint8Array((0, crypto_1.hkdf)(Buffer.from(t), o, { info: r.salt })).buffer;
|
|
36
|
+
return r.performPointwiseWithOverflow(e, n, ((e, t) => e + t));
|
|
37
37
|
}
|
|
38
|
-
|
|
38
|
+
_subtractSingle(e, t) {
|
|
39
39
|
var r = this;
|
|
40
|
-
const n = new Uint8Array(
|
|
41
|
-
return r.performPointwiseWithOverflow(
|
|
40
|
+
const n = new Uint8Array((0, crypto_1.hkdf)(Buffer.from(t), o, { info: r.salt })).buffer;
|
|
41
|
+
return r.performPointwiseWithOverflow(e, n, ((e, t) => e - t));
|
|
42
42
|
}
|
|
43
43
|
performPointwiseWithOverflow(e, t, r) {
|
|
44
44
|
const n = new DataView(e), i = new DataView(t), a = new ArrayBuffer(n.byteLength), s = new DataView(a);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare const makeMutex: () => {
|
|
2
|
-
mutex<T>(code: () =>
|
|
2
|
+
mutex<T>(code: () => T | Promise<T>): Promise<T>;
|
|
3
3
|
};
|
|
4
4
|
export type Mutex = ReturnType<typeof makeMutex>;
|
|
5
5
|
export declare const makeKeyedMutex: () => {
|
|
6
|
-
mutex<T>(key: string, task: () =>
|
|
6
|
+
mutex<T>(key: string, task: () => T | Promise<T>): Promise<T>;
|
|
7
7
|
};
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
/// <reference types="node" />
|
|
1
4
|
import { Boom } from '@hapi/boom';
|
|
2
5
|
import { AxiosRequestConfig } from 'axios';
|
|
3
6
|
import type { Logger } from 'pino';
|
|
4
|
-
import { Readable } from 'stream';
|
|
7
|
+
import { Readable, Transform } from 'stream';
|
|
5
8
|
import { URL } from 'url';
|
|
6
9
|
import { proto } from '../../WAProto';
|
|
7
10
|
import { DownloadableMessage, MediaConnInfo, MediaDecryptionKeyInfo, MediaType, SocketConfig, WAMediaUpload, WAMediaUploadFunction, WAMessageContent } from '../Types';
|
|
@@ -10,10 +13,10 @@ export declare const hkdfInfoKey: (type: MediaType) => string;
|
|
|
10
13
|
/** generates all the keys required to encrypt/decrypt & sign a media message */
|
|
11
14
|
export declare function getMediaKeys(buffer: Uint8Array | string | null | undefined, mediaType: MediaType): MediaDecryptionKeyInfo;
|
|
12
15
|
export declare const extractImageThumb: (bufferOrFilePath: Readable | Buffer | string, width?: number) => Promise<{
|
|
13
|
-
buffer:
|
|
16
|
+
buffer: Buffer;
|
|
14
17
|
original: {
|
|
15
|
-
width:
|
|
16
|
-
height:
|
|
18
|
+
width: number | undefined;
|
|
19
|
+
height: number | undefined;
|
|
17
20
|
};
|
|
18
21
|
}>;
|
|
19
22
|
export declare const encodeBase64EncodedStringForUpload: (b64: string) => string;
|
|
@@ -21,25 +24,25 @@ export declare const generateProfilePicture: (mediaUpload: WAMediaUpload) => Pro
|
|
|
21
24
|
img: Buffer;
|
|
22
25
|
}>;
|
|
23
26
|
/** gets the SHA256 of the given media message */
|
|
24
|
-
export declare const mediaMessageSHA256B64: (message: WAMessageContent) =>
|
|
25
|
-
export declare function getAudioDuration(buffer: Buffer | string | Readable): Promise<
|
|
27
|
+
export declare const mediaMessageSHA256B64: (message: WAMessageContent) => string | null | undefined;
|
|
28
|
+
export declare function getAudioDuration(buffer: Buffer | string | Readable): Promise<number | undefined>;
|
|
26
29
|
/**
|
|
27
30
|
referenced from and modifying https://github.com/wppconnect-team/wa-js/blob/main/src/chat/functions/prepareAudioWaveform.ts
|
|
28
31
|
*/
|
|
29
|
-
export declare function getAudioWaveform(buffer: Buffer | string | Readable, logger?: Logger): Promise<Uint8Array
|
|
30
|
-
export declare const toReadable: (buffer: Buffer) =>
|
|
31
|
-
export declare const toBuffer: (stream: Readable) => Promise<
|
|
32
|
+
export declare function getAudioWaveform(buffer: Buffer | string | Readable, logger?: Logger): Promise<Uint8Array | undefined>;
|
|
33
|
+
export declare const toReadable: (buffer: Buffer) => Readable;
|
|
34
|
+
export declare const toBuffer: (stream: Readable) => Promise<Buffer>;
|
|
32
35
|
export declare const getStream: (item: WAMediaUpload, opts?: AxiosRequestConfig) => Promise<{
|
|
33
|
-
readonly stream:
|
|
36
|
+
readonly stream: Readable;
|
|
34
37
|
readonly type: "buffer";
|
|
35
38
|
} | {
|
|
36
|
-
readonly stream:
|
|
39
|
+
readonly stream: Readable;
|
|
37
40
|
readonly type: "readable";
|
|
38
41
|
} | {
|
|
39
42
|
readonly stream: Readable;
|
|
40
43
|
readonly type: "remote";
|
|
41
44
|
} | {
|
|
42
|
-
readonly stream:
|
|
45
|
+
readonly stream: import("fs").ReadStream;
|
|
43
46
|
readonly type: "file";
|
|
44
47
|
}>;
|
|
45
48
|
/** generates a thumbnail for a given media, if required */
|
|
@@ -62,20 +65,20 @@ type EncryptedStreamOptions = {
|
|
|
62
65
|
};
|
|
63
66
|
export declare const prepareStream: (media: WAMediaUpload, mediaType: MediaType, { logger, saveOriginalFileIfRequired, opts }?: EncryptedStreamOptions) => Promise<{
|
|
64
67
|
mediaKey: undefined;
|
|
65
|
-
encWriteStream:
|
|
66
|
-
fileLength:
|
|
67
|
-
fileSha256:
|
|
68
|
+
encWriteStream: Buffer;
|
|
69
|
+
fileLength: number;
|
|
70
|
+
fileSha256: Buffer;
|
|
68
71
|
fileEncSha256: undefined;
|
|
69
72
|
bodyPath: string | undefined;
|
|
70
73
|
didSaveToTmpPath: boolean;
|
|
71
74
|
}>;
|
|
72
75
|
export declare const encryptedStream: (media: WAMediaUpload, mediaType: MediaType, { logger, saveOriginalFileIfRequired, opts }?: EncryptedStreamOptions) => Promise<{
|
|
73
|
-
mediaKey:
|
|
74
|
-
encWriteStream:
|
|
76
|
+
mediaKey: Buffer;
|
|
77
|
+
encWriteStream: Readable;
|
|
75
78
|
bodyPath: string | undefined;
|
|
76
|
-
mac:
|
|
77
|
-
fileEncSha256:
|
|
78
|
-
fileSha256:
|
|
79
|
+
mac: Buffer;
|
|
80
|
+
fileEncSha256: Buffer;
|
|
81
|
+
fileSha256: Buffer;
|
|
79
82
|
fileLength: number;
|
|
80
83
|
didSaveToTmpPath: boolean;
|
|
81
84
|
}>;
|
|
@@ -85,12 +88,12 @@ export type MediaDownloadOptions = {
|
|
|
85
88
|
options?: AxiosRequestConfig<any>;
|
|
86
89
|
};
|
|
87
90
|
export declare const getUrlFromDirectPath: (directPath: string) => string;
|
|
88
|
-
export declare const downloadContentFromMessage: ({ mediaKey, directPath, url }: DownloadableMessage, type: MediaType, opts?: MediaDownloadOptions) => Promise<
|
|
91
|
+
export declare const downloadContentFromMessage: ({ mediaKey, directPath, url }: DownloadableMessage, type: MediaType, opts?: MediaDownloadOptions) => Promise<Transform>;
|
|
89
92
|
/**
|
|
90
93
|
* Decrypts and downloads an AES256-CBC encrypted file given the keys.
|
|
91
94
|
* Assumes the SHA256 of the plaintext is appended to the end of the ciphertext
|
|
92
95
|
* */
|
|
93
|
-
export declare const downloadEncryptedContent: (downloadUrl: string, { cipherKey, iv }: MediaDecryptionKeyInfo, { startByte, endByte, options }?: MediaDownloadOptions) => Promise<
|
|
96
|
+
export declare const downloadEncryptedContent: (downloadUrl: string, { cipherKey, iv }: MediaDecryptionKeyInfo, { startByte, endByte, options }?: MediaDownloadOptions) => Promise<Transform>;
|
|
94
97
|
export declare function extensionForMediaMessage(message: WAMessageContent): string;
|
|
95
98
|
export declare const getWAUploadToServer: ({ customUploadHosts, fetchAgent, logger, options }: SocketConfig, refreshMediaConn: (force: boolean) => Promise<MediaConnInfo>) => WAMediaUploadFunction;
|
|
96
99
|
/**
|
|
@@ -98,12 +101,12 @@ export declare const getWAUploadToServer: ({ customUploadHosts, fetchAgent, logg
|
|
|
98
101
|
*/
|
|
99
102
|
export declare const encryptMediaRetryRequest: (key: proto.IMessageKey, mediaKey: Buffer | Uint8Array, meId: string) => BinaryNode;
|
|
100
103
|
export declare const decodeMediaRetryNode: (node: BinaryNode) => {
|
|
101
|
-
key:
|
|
104
|
+
key: proto.IMessageKey;
|
|
102
105
|
media?: {
|
|
103
106
|
ciphertext: Uint8Array;
|
|
104
107
|
iv: Uint8Array;
|
|
105
|
-
};
|
|
106
|
-
error?: Boom;
|
|
108
|
+
} | undefined;
|
|
109
|
+
error?: Boom<any> | undefined;
|
|
107
110
|
};
|
|
108
111
|
export declare const decryptMediaRetryData: ({ ciphertext, iv }: {
|
|
109
112
|
ciphertext: Uint8Array;
|