@denzy-official/baileys 1.1.1 → 1.1.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.d.ts +55058 -0
- package/WAProto/index.js +169662 -0
- package/WAProto/index.ts.ts +53474 -0
- package/lib/Defaults/index.d.ts +52 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
- package/lib/Signal/Group/group-session-builder.d.ts +15 -0
- package/lib/Signal/Group/group_cipher.d.ts +18 -0
- package/lib/Signal/Group/index.d.ts +12 -0
- package/lib/Signal/Group/keyhelper.d.ts +11 -0
- package/lib/Signal/Group/queue-job.d.ts +2 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
- package/lib/Signal/Group/sender-key-message.d.ts +19 -0
- package/lib/Signal/Group/sender-key-name.d.ts +18 -0
- package/lib/Signal/Group/sender-key-record.d.ts +31 -0
- package/lib/Signal/Group/sender-key-state.d.ts +39 -0
- package/lib/Signal/Group/sender-message-key.d.ts +12 -0
- package/lib/Signal/libsignal.d.ts +4 -0
- package/lib/Socket/Client/abstract-socket-client.d.ts +17 -0
- package/lib/Socket/Client/abstract-socket-client.js +13 -0
- package/lib/Socket/Client/index.d.ts +3 -0
- package/lib/Socket/Client/index.js +3 -3
- package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
- package/lib/Socket/Client/mobile-socket-client.js +65 -0
- package/lib/Socket/Client/types.d.ts +17 -0
- package/lib/Socket/Client/web-socket-client.d.ts +12 -0
- package/lib/Socket/Client/web-socket-client.js +62 -0
- package/lib/Socket/Client/websocket.d.ts +14 -0
- package/lib/Socket/business.d.ts +171 -0
- package/lib/Socket/business.js +0 -1
- package/lib/Socket/chats.d.ts +267 -0
- package/lib/Socket/chats.js +238 -140
- package/lib/Socket/dugong.d.ts +254 -0
- package/lib/Socket/dugong.js +343 -335
- package/lib/Socket/groups.d.ts +115 -0
- package/lib/Socket/groups.js +23 -39
- package/lib/Socket/index.d.ts +173 -0
- package/lib/Socket/index.js +3 -3
- package/lib/Socket/messages-recv.d.ts +161 -0
- package/lib/Socket/messages-recv.js +65 -10
- package/lib/Socket/messages-send.d.ts +149 -0
- package/lib/Socket/messages-send.js +392 -412
- package/lib/Socket/newsletter.d.ts +134 -0
- package/lib/Socket/newsletter.js +124 -72
- package/lib/Socket/registration.d.ts +267 -0
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.d.ts +43 -0
- package/lib/Socket/socket.js +38 -63
- package/lib/Socket/usync.d.ts +36 -0
- package/lib/Socket/usync.js +0 -1
- package/lib/Store/index.d.ts +3 -0
- package/lib/Store/make-in-memory-store.d.ts +119 -0
- package/lib/Store/make-ordered-dictionary.d.ts +14 -0
- package/lib/Store/object-repository.d.ts +11 -0
- package/lib/Types/Auth.d.ts +104 -0
- package/lib/Types/Call.d.ts +14 -0
- package/lib/Types/Chat.d.ts +110 -0
- package/lib/Types/Contact.d.ts +24 -0
- package/lib/Types/Events.d.ts +200 -0
- package/lib/Types/GroupMetadata.d.ts +65 -0
- package/lib/Types/Label.d.ts +36 -0
- package/lib/Types/LabelAssociation.d.ts +30 -0
- package/lib/Types/Message.d.ts +401 -0
- package/lib/Types/Newsletter.d.ts +80 -0
- package/lib/Types/Product.d.ts +78 -0
- package/lib/Types/Signal.d.ts +57 -0
- package/lib/Types/Socket.d.ts +119 -0
- package/lib/Types/State.d.ts +27 -0
- package/lib/Types/USync.d.ts +25 -0
- package/lib/Types/index.d.ts +65 -0
- package/lib/Utils/auth-utils.d.ts +18 -0
- package/lib/Utils/auth-utils.js +13 -8
- package/lib/Utils/baileys-event-stream.d.ts +16 -0
- package/lib/Utils/baileys-event-stream.js +0 -1
- package/lib/Utils/business.d.ts +22 -0
- package/lib/Utils/business.js +2 -3
- package/lib/Utils/chat-utils.d.ts +71 -0
- package/lib/Utils/chat-utils.js +35 -37
- package/lib/Utils/crypto.d.ts +41 -0
- package/lib/Utils/crypto.js +29 -72
- package/lib/Utils/decode-wa-message.d.ts +19 -0
- package/lib/Utils/decode-wa-message.js +56 -66
- package/lib/Utils/event-buffer.d.ts +35 -0
- package/lib/Utils/event-buffer.js +7 -12
- package/lib/Utils/generics.d.ts +92 -0
- package/lib/Utils/generics.js +75 -96
- package/lib/Utils/history.d.ts +15 -0
- package/lib/Utils/history.js +6 -5
- package/lib/Utils/index.d.ts +17 -0
- package/lib/Utils/index.js +0 -1
- package/lib/Utils/link-preview.d.ts +21 -0
- package/lib/Utils/link-preview.js +1 -34
- package/lib/Utils/logger.d.ts +4 -0
- package/lib/Utils/lt-hash.d.ts +12 -0
- package/lib/Utils/lt-hash.js +6 -6
- package/lib/Utils/make-mutex.d.ts +7 -0
- package/lib/Utils/messages-media.d.ts +116 -0
- package/lib/Utils/messages-media.js +235 -296
- package/lib/Utils/messages.d.ts +77 -0
- package/lib/Utils/messages.js +60 -304
- package/lib/Utils/noise-handler.d.ts +21 -0
- package/lib/Utils/noise-handler.js +23 -18
- package/lib/Utils/process-message.d.ts +41 -0
- package/lib/Utils/process-message.js +25 -89
- package/lib/Utils/signal.d.ts +32 -0
- package/lib/Utils/signal.js +26 -26
- package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
- package/lib/Utils/use-multi-file-auth-state.js +6 -51
- package/lib/Utils/validate-connection.d.ts +11 -0
- package/lib/Utils/validate-connection.js +52 -20
- package/lib/WABinary/constants.d.ts +28 -0
- package/lib/WABinary/decode.d.ts +7 -0
- package/lib/WABinary/encode.d.ts +3 -0
- package/lib/WABinary/generic-utils.d.ts +15 -0
- package/lib/WABinary/index.d.ts +6 -0
- package/lib/WABinary/jid-utils.d.ts +37 -0
- package/lib/WABinary/types.d.ts +19 -0
- package/lib/WAM/BinaryInfo.d.ts +9 -0
- package/lib/WAM/constants.d.ts +39 -0
- package/lib/WAM/encode.d.ts +3 -0
- package/lib/WAM/index.d.ts +4 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +25 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +8 -0
- package/lib/WAUSync/Protocols/index.d.ts +4 -0
- package/lib/WAUSync/USyncQuery.d.ts +28 -0
- package/lib/WAUSync/USyncUser.d.ts +12 -0
- package/lib/WAUSync/index.d.ts +3 -0
- package/package.json +1 -1
package/lib/Utils/generics.js
CHANGED
|
@@ -1,62 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
"use strict";
|
|
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
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
-
}) : function(o, v) {
|
|
17
|
-
o["default"] = v;
|
|
18
|
-
});
|
|
19
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
-
var ownKeys = function(o) {
|
|
21
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
-
var ar = [];
|
|
23
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
-
return ar;
|
|
25
|
-
};
|
|
26
|
-
return ownKeys(o);
|
|
27
|
-
};
|
|
28
|
-
return function (mod) {
|
|
29
|
-
if (mod && mod.__esModule) return mod;
|
|
30
|
-
var result = {};
|
|
31
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
-
__setModuleDefault(result, mod);
|
|
33
|
-
return result;
|
|
34
|
-
};
|
|
35
|
-
})();
|
|
1
|
+
"use strict";
|
|
36
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
4
|
};
|
|
39
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
-
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.
|
|
41
|
-
exports.promiseTimeout = promiseTimeout;
|
|
42
|
-
exports.bindWaitForEvent = bindWaitForEvent;
|
|
43
|
-
exports.trimUndefined = trimUndefined;
|
|
44
|
-
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;
|
|
45
7
|
const boom_1 = require("@hapi/boom");
|
|
46
8
|
const axios_1 = __importDefault(require("axios"));
|
|
47
9
|
const crypto_1 = require("crypto");
|
|
48
10
|
const os_1 = require("os");
|
|
11
|
+
const fetch_1 = require("node-fetch")
|
|
49
12
|
const WAProto_1 = require("../../WAProto");
|
|
50
13
|
const baileys_version_json_1 = require("../Defaults/baileys-version.json");
|
|
51
14
|
const Types_1 = require("../Types");
|
|
52
15
|
const WABinary_1 = require("../WABinary");
|
|
53
|
-
const
|
|
54
|
-
'Chrome': '49',
|
|
55
|
-
'Edge': '50',
|
|
56
|
-
'Firefox': '51',
|
|
57
|
-
'Opera': '53',
|
|
58
|
-
'Safari': '54'
|
|
59
|
-
};
|
|
16
|
+
const baileysVersion = [2, 3000, 1027934701]
|
|
60
17
|
const PLATFORM_MAP = {
|
|
61
18
|
'aix': 'AIX',
|
|
62
19
|
'darwin': 'Mac OS',
|
|
@@ -71,12 +28,12 @@ exports.Browsers = {
|
|
|
71
28
|
macOS: (browser) => ['Mac OS', browser, '14.4.1'],
|
|
72
29
|
baileys: (browser) => ['Baileys', browser, '6.5.0'],
|
|
73
30
|
windows: (browser) => ['Windows', browser, '10.0.22631'],
|
|
74
|
-
/** The appropriate browser based on your OS & release */
|
|
75
31
|
appropriate: (browser) => [PLATFORM_MAP[(0, os_1.platform)()] || 'Ubuntu', browser, (0, os_1.release)()]
|
|
76
32
|
};
|
|
33
|
+
|
|
77
34
|
const getPlatformId = (browser) => {
|
|
78
35
|
const platformType = WAProto_1.proto.DeviceProps.PlatformType[browser.toUpperCase()];
|
|
79
|
-
return platformType ? platformType.toString() : '
|
|
36
|
+
return platformType ? platformType.toString() : '1'; //chrome
|
|
80
37
|
};
|
|
81
38
|
exports.getPlatformId = getPlatformId;
|
|
82
39
|
exports.BufferJSON = {
|
|
@@ -119,8 +76,6 @@ const unpadRandomMax16 = (e) => {
|
|
|
119
76
|
exports.unpadRandomMax16 = unpadRandomMax16;
|
|
120
77
|
const encodeWAMessage = (message) => ((0, exports.writeRandomPadMax16)(WAProto_1.proto.Message.encode(message).finish()));
|
|
121
78
|
exports.encodeWAMessage = encodeWAMessage;
|
|
122
|
-
const encodeNewsletterMessage = (message) => (WAProto_1.proto.Message.encode(message).finish());
|
|
123
|
-
exports.encodeNewsletterMessage = encodeNewsletterMessage;
|
|
124
79
|
const generateRegistrationId = () => {
|
|
125
80
|
return Uint16Array.from((0, crypto_1.randomBytes)(2))[0] & 16383;
|
|
126
81
|
};
|
|
@@ -135,7 +90,7 @@ const encodeBigEndian = (e, t = 4) => {
|
|
|
135
90
|
return a;
|
|
136
91
|
};
|
|
137
92
|
exports.encodeBigEndian = encodeBigEndian;
|
|
138
|
-
const toNumber = (t) => ((typeof t === 'object' && t) ? ('toNumber' in t ? t.toNumber() : t.low) : t
|
|
93
|
+
const toNumber = (t) => ((typeof t === 'object' && t) ? ('toNumber' in t ? t.toNumber() : t.low) : t);
|
|
139
94
|
exports.toNumber = toNumber;
|
|
140
95
|
/** unix timestamp of a date in seconds */
|
|
141
96
|
const unixTimestampSeconds = (date = new Date()) => Math.floor(date.getTime() / 1000);
|
|
@@ -201,6 +156,7 @@ async function promiseTimeout(ms, promise) {
|
|
|
201
156
|
.finally(cancel);
|
|
202
157
|
return p;
|
|
203
158
|
}
|
|
159
|
+
exports.promiseTimeout = promiseTimeout;
|
|
204
160
|
const generateMessageIDV2 = (userId) => {
|
|
205
161
|
const data = Buffer.alloc(8 + 20 + 16);
|
|
206
162
|
data.writeBigUInt64BE(BigInt(Math.floor(Date.now() / 1000)));
|
|
@@ -218,7 +174,7 @@ const generateMessageIDV2 = (userId) => {
|
|
|
218
174
|
};
|
|
219
175
|
exports.generateMessageIDV2 = generateMessageIDV2;
|
|
220
176
|
// generate a random ID to attach to a message
|
|
221
|
-
const generateMessageID = () => '
|
|
177
|
+
const generateMessageID = () => 'ILSYM-' + (0, crypto_1.randomBytes)(6).toString('hex').toUpperCase();
|
|
222
178
|
exports.generateMessageID = generateMessageID;
|
|
223
179
|
function bindWaitForEvent(ev, event) {
|
|
224
180
|
return async (check, timeoutMs) => {
|
|
@@ -232,8 +188,8 @@ function bindWaitForEvent(ev, event) {
|
|
|
232
188
|
}
|
|
233
189
|
};
|
|
234
190
|
ev.on('connection.update', closeListener);
|
|
235
|
-
listener =
|
|
236
|
-
if (
|
|
191
|
+
listener = (update) => {
|
|
192
|
+
if (check(update)) {
|
|
237
193
|
resolve();
|
|
238
194
|
}
|
|
239
195
|
};
|
|
@@ -245,12 +201,14 @@ function bindWaitForEvent(ev, event) {
|
|
|
245
201
|
}));
|
|
246
202
|
};
|
|
247
203
|
}
|
|
204
|
+
exports.bindWaitForEvent = bindWaitForEvent;
|
|
248
205
|
const bindWaitForConnectionUpdate = (ev) => bindWaitForEvent(ev, 'connection.update');
|
|
249
206
|
exports.bindWaitForConnectionUpdate = bindWaitForConnectionUpdate;
|
|
250
207
|
const printQRIfNecessaryListener = (ev, logger) => {
|
|
251
208
|
ev.on('connection.update', async ({ qr }) => {
|
|
252
209
|
if (qr) {
|
|
253
|
-
const QR = await
|
|
210
|
+
const QR = await import('qrcode-terminal')
|
|
211
|
+
.then(m => m.default || m)
|
|
254
212
|
.catch(() => {
|
|
255
213
|
logger.error('QR code terminal not added as dependency');
|
|
256
214
|
});
|
|
@@ -259,8 +217,61 @@ const printQRIfNecessaryListener = (ev, logger) => {
|
|
|
259
217
|
});
|
|
260
218
|
};
|
|
261
219
|
exports.printQRIfNecessaryListener = printQRIfNecessaryListener;
|
|
220
|
+
/**
|
|
221
|
+
* utility that fetches latest baileys version from the master branch.
|
|
222
|
+
* Use to ensure your WA connection is always on the latest version
|
|
223
|
+
*/
|
|
224
|
+
const fetchLatestWaWebVersion = async (options = {}) => {
|
|
225
|
+
try {
|
|
226
|
+
const defaultHeaders = {
|
|
227
|
+
'User-Agent':
|
|
228
|
+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
|
|
229
|
+
'Accept': '*/*'
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const headers = { ...defaultHeaders, ...options.headers }
|
|
233
|
+
|
|
234
|
+
const response = await fetch_1('https://web.whatsapp.com/sw.js', {
|
|
235
|
+
method: 'GET',
|
|
236
|
+
headers
|
|
237
|
+
})
|
|
238
|
+
|
|
239
|
+
if (!response.ok) {
|
|
240
|
+
throw new Error(`Failed to fetch sw.js: ${response.status} ${response.statusText}`)
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const data = await response.text()
|
|
244
|
+
const regex = /"client_revision":\s*(\d+)/ // regex cukup begini untuk Node
|
|
245
|
+
const match = data.match(regex)
|
|
246
|
+
|
|
247
|
+
if (!match || !match[1]) {
|
|
248
|
+
return {
|
|
249
|
+
version: baileysVersion,
|
|
250
|
+
isLatest: false,
|
|
251
|
+
error: { message: 'Client revision not found' }
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
const clientRevision = match[1]
|
|
256
|
+
return {
|
|
257
|
+
version: [2, 3000, +clientRevision],
|
|
258
|
+
isLatest: true
|
|
259
|
+
}
|
|
260
|
+
} catch (error) {
|
|
261
|
+
return {
|
|
262
|
+
version: baileysVersion,
|
|
263
|
+
isLatest: false,
|
|
264
|
+
error
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
exports.fetchLatestWaWebVersion = fetchLatestWaWebVersion;
|
|
269
|
+
/**
|
|
270
|
+
* utility that fetches latest baileys version from the master branch.
|
|
271
|
+
* Use to ensure your WA connection is always on the latest version
|
|
272
|
+
*/
|
|
262
273
|
const fetchLatestBaileysVersion = async (options = {}) => {
|
|
263
|
-
const URL = 'https://
|
|
274
|
+
const URL = 'https://raw.githubusercontent.com/kiuur/bails/master/src/Defaults/baileys-version.json';
|
|
264
275
|
try {
|
|
265
276
|
const result = await axios_1.default.get(URL, {
|
|
266
277
|
...options,
|
|
@@ -280,42 +291,6 @@ const fetchLatestBaileysVersion = async (options = {}) => {
|
|
|
280
291
|
}
|
|
281
292
|
};
|
|
282
293
|
exports.fetchLatestBaileysVersion = fetchLatestBaileysVersion;
|
|
283
|
-
/**
|
|
284
|
-
* A utility that fetches the latest web version of whatsapp.
|
|
285
|
-
* Use to ensure your WA connection is always on the latest version
|
|
286
|
-
*/
|
|
287
|
-
const fetchLatestWaWebVersion = async (options) => {
|
|
288
|
-
try {
|
|
289
|
-
const { data } = await axios_1.default.get('https://web.whatsapp.com/sw.js', {
|
|
290
|
-
...options,
|
|
291
|
-
responseType: 'json'
|
|
292
|
-
});
|
|
293
|
-
const regex = /\\?"client_revision\\?":\s*(\d+)/;
|
|
294
|
-
const match = data.match(regex);
|
|
295
|
-
if (!(match === null || match === void 0 ? void 0 : match[1])) {
|
|
296
|
-
return {
|
|
297
|
-
version: baileys_version_json_1.version,
|
|
298
|
-
isLatest: false,
|
|
299
|
-
error: {
|
|
300
|
-
message: 'Could not find client revision in the fetched content'
|
|
301
|
-
}
|
|
302
|
-
};
|
|
303
|
-
}
|
|
304
|
-
const clientRevision = match[1];
|
|
305
|
-
return {
|
|
306
|
-
version: [2, 3000, +clientRevision],
|
|
307
|
-
isLatest: true
|
|
308
|
-
};
|
|
309
|
-
}
|
|
310
|
-
catch (error) {
|
|
311
|
-
return {
|
|
312
|
-
version: baileys_version_json_1.version,
|
|
313
|
-
isLatest: false,
|
|
314
|
-
error
|
|
315
|
-
};
|
|
316
|
-
}
|
|
317
|
-
};
|
|
318
|
-
exports.fetchLatestWaWebVersion = fetchLatestWaWebVersion;
|
|
319
294
|
/** unique message tag prefix for MD clients */
|
|
320
295
|
const generateMdTagPrefix = () => {
|
|
321
296
|
const bytes = (0, crypto_1.randomBytes)(4);
|
|
@@ -323,7 +298,6 @@ const generateMdTagPrefix = () => {
|
|
|
323
298
|
};
|
|
324
299
|
exports.generateMdTagPrefix = generateMdTagPrefix;
|
|
325
300
|
const STATUS_MAP = {
|
|
326
|
-
'sender': WAProto_1.proto.WebMessageInfo.Status.SERVER_ACK,
|
|
327
301
|
'played': WAProto_1.proto.WebMessageInfo.Status.PLAYED,
|
|
328
302
|
'read': WAProto_1.proto.WebMessageInfo.Status.READ,
|
|
329
303
|
'read-self': WAProto_1.proto.WebMessageInfo.Status.READ
|
|
@@ -372,8 +346,7 @@ const getCallStatusFromNode = ({ tag, attrs }) => {
|
|
|
372
346
|
status = 'timeout';
|
|
373
347
|
}
|
|
374
348
|
else {
|
|
375
|
-
|
|
376
|
-
status = 'terminate';
|
|
349
|
+
status = 'reject';
|
|
377
350
|
}
|
|
378
351
|
break;
|
|
379
352
|
case 'reject':
|
|
@@ -422,6 +395,7 @@ function trimUndefined(obj) {
|
|
|
422
395
|
}
|
|
423
396
|
return obj;
|
|
424
397
|
}
|
|
398
|
+
exports.trimUndefined = trimUndefined;
|
|
425
399
|
const CROCKFORD_CHARACTERS = '123456789ABCDEFGHJKLMNPQRSTVWXYZ';
|
|
426
400
|
function bytesToCrockford(buffer) {
|
|
427
401
|
let value = 0;
|
|
@@ -440,3 +414,8 @@ function bytesToCrockford(buffer) {
|
|
|
440
414
|
}
|
|
441
415
|
return crockford.join('');
|
|
442
416
|
}
|
|
417
|
+
exports.bytesToCrockford = bytesToCrockford;
|
|
418
|
+
const encodeNewsletterMessage = (message) => {
|
|
419
|
+
return WAProto_1.proto.Message.encode(message).finish()
|
|
420
|
+
}
|
|
421
|
+
exports.encodeNewsletterMessage = encodeNewsletterMessage;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AxiosRequestConfig } from 'axios';
|
|
2
|
+
import { proto } from '../../WAProto';
|
|
3
|
+
import { Chat, Contact } from '../Types';
|
|
4
|
+
export declare const downloadHistory: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<any>) => Promise<proto.HistorySync>;
|
|
5
|
+
export declare const processHistoryMessage: (item: proto.IHistorySync) => {
|
|
6
|
+
chats: Chat[];
|
|
7
|
+
contacts: Contact[];
|
|
8
|
+
messages: proto.IWebMessageInfo[];
|
|
9
|
+
};
|
|
10
|
+
export declare const downloadAndProcessHistorySyncNotification: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<any>) => Promise<{
|
|
11
|
+
chats: Chat[];
|
|
12
|
+
contacts: Contact[];
|
|
13
|
+
messages: proto.IWebMessageInfo[];
|
|
14
|
+
}>;
|
|
15
|
+
export declare const getHistoryMsg: (message: proto.IMessage) => proto.Message.IHistorySyncNotification | null | undefined;
|
package/lib/Utils/history.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// baileys by denzy
|
|
2
1
|
"use strict";
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
3
|
exports.getHistoryMsg = exports.downloadAndProcessHistorySyncNotification = exports.processHistoryMessage = exports.downloadHistory = void 0;
|
|
@@ -33,9 +32,13 @@ const processHistoryMessage = (item) => {
|
|
|
33
32
|
case WAProto_1.proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP:
|
|
34
33
|
case WAProto_1.proto.HistorySync.HistorySyncType.RECENT:
|
|
35
34
|
case WAProto_1.proto.HistorySync.HistorySyncType.FULL:
|
|
36
|
-
case WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND:
|
|
37
35
|
for (const chat of item.conversations) {
|
|
38
|
-
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
|
+
});
|
|
39
42
|
const msgs = chat.messages || [];
|
|
40
43
|
delete chat.messages;
|
|
41
44
|
delete chat.archived;
|
|
@@ -76,8 +79,6 @@ const processHistoryMessage = (item) => {
|
|
|
76
79
|
chats,
|
|
77
80
|
contacts,
|
|
78
81
|
messages,
|
|
79
|
-
syncType: item.syncType,
|
|
80
|
-
progress: item.progress
|
|
81
82
|
};
|
|
82
83
|
};
|
|
83
84
|
exports.processHistoryMessage = processHistoryMessage;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export * from './generics';
|
|
2
|
+
export * from './decode-wa-message';
|
|
3
|
+
export * from './messages';
|
|
4
|
+
export * from './messages-media';
|
|
5
|
+
export * from './validate-connection';
|
|
6
|
+
export * from './crypto';
|
|
7
|
+
export * from './signal';
|
|
8
|
+
export * from './noise-handler';
|
|
9
|
+
export * from './history';
|
|
10
|
+
export * from './chat-utils';
|
|
11
|
+
export * from './lt-hash';
|
|
12
|
+
export * from './auth-utils';
|
|
13
|
+
export * from './baileys-event-stream';
|
|
14
|
+
export * from './use-multi-file-auth-state';
|
|
15
|
+
export * from './link-preview';
|
|
16
|
+
export * from './event-buffer';
|
|
17
|
+
export * from './process-message';
|
package/lib/Utils/index.js
CHANGED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { AxiosRequestConfig } from 'axios';
|
|
2
|
+
import { Logger } from 'pino';
|
|
3
|
+
import { WAMediaUploadFunction, WAUrlInfo } from '../Types';
|
|
4
|
+
export type URLGenerationOptions = {
|
|
5
|
+
thumbnailWidth: number;
|
|
6
|
+
fetchOpts: {
|
|
7
|
+
/** Timeout in ms */
|
|
8
|
+
timeout: number;
|
|
9
|
+
proxyUrl?: string;
|
|
10
|
+
headers?: AxiosRequestConfig<{}>['headers'];
|
|
11
|
+
};
|
|
12
|
+
uploadImage?: WAMediaUploadFunction;
|
|
13
|
+
logger?: Logger;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Given a piece of text, checks for any URL present, generates link preview for the same and returns it
|
|
17
|
+
* Return undefined if the fetch failed or no URL was found
|
|
18
|
+
* @param text first matched URL in text
|
|
19
|
+
* @returns the URL info required to generate link preview
|
|
20
|
+
*/
|
|
21
|
+
export declare const getUrlInfo: (text: string, opts?: URLGenerationOptions) => Promise<WAUrlInfo | undefined>;
|
|
@@ -1,37 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
3
|
exports.getUrlInfo = void 0;
|
|
37
4
|
const messages_1 = require("./messages");
|
|
@@ -58,7 +25,7 @@ const getUrlInfo = async (text, opts = {
|
|
|
58
25
|
// retries
|
|
59
26
|
const retries = 0;
|
|
60
27
|
const maxRetry = 5;
|
|
61
|
-
const { getLinkPreview } = await
|
|
28
|
+
const { getLinkPreview } = await import('link-preview-js');
|
|
62
29
|
let previewLink = text;
|
|
63
30
|
if (!text.startsWith('https://') && !text.startsWith('http://')) {
|
|
64
31
|
previewLink = 'https://' + previewLink;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
declare class d {
|
|
2
|
+
salt: string;
|
|
3
|
+
constructor(e: string);
|
|
4
|
+
add(e: any, t: any): any;
|
|
5
|
+
subtract(e: any, t: any): any;
|
|
6
|
+
subtractThenAdd(e: any, t: any, r: any): any;
|
|
7
|
+
_addSingle(e: any, t: any): ArrayBuffer;
|
|
8
|
+
_subtractSingle(e: any, t: any): ArrayBuffer;
|
|
9
|
+
performPointwiseWithOverflow(e: any, t: any, r: any): ArrayBuffer;
|
|
10
|
+
}
|
|
11
|
+
export declare const LT_HASH_ANTI_TAMPERING: d;
|
|
12
|
+
export {};
|
package/lib/Utils/lt-hash.js
CHANGED
|
@@ -30,15 +30,15 @@ class d {
|
|
|
30
30
|
var n = this;
|
|
31
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);
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
/// <reference types="node" />
|
|
4
|
+
import { Boom } from '@hapi/boom';
|
|
5
|
+
import { AxiosRequestConfig } from 'axios';
|
|
6
|
+
import type { Logger } from 'pino';
|
|
7
|
+
import { Readable, Transform } from 'stream';
|
|
8
|
+
import { URL } from 'url';
|
|
9
|
+
import { proto } from '../../WAProto';
|
|
10
|
+
import { DownloadableMessage, MediaConnInfo, MediaDecryptionKeyInfo, MediaType, SocketConfig, WAMediaUpload, WAMediaUploadFunction, WAMessageContent } from '../Types';
|
|
11
|
+
import { BinaryNode } from '../WABinary';
|
|
12
|
+
export declare const hkdfInfoKey: (type: MediaType) => string;
|
|
13
|
+
/** generates all the keys required to encrypt/decrypt & sign a media message */
|
|
14
|
+
export declare function getMediaKeys(buffer: Uint8Array | string | null | undefined, mediaType: MediaType): MediaDecryptionKeyInfo;
|
|
15
|
+
export declare const extractImageThumb: (bufferOrFilePath: Readable | Buffer | string, width?: number) => Promise<{
|
|
16
|
+
buffer: Buffer;
|
|
17
|
+
original: {
|
|
18
|
+
width: number | undefined;
|
|
19
|
+
height: number | undefined;
|
|
20
|
+
};
|
|
21
|
+
}>;
|
|
22
|
+
export declare const encodeBase64EncodedStringForUpload: (b64: string) => string;
|
|
23
|
+
export declare const generateProfilePicture: (mediaUpload: WAMediaUpload) => Promise<{
|
|
24
|
+
img: Buffer;
|
|
25
|
+
}>;
|
|
26
|
+
/** gets the SHA256 of the given media message */
|
|
27
|
+
export declare const mediaMessageSHA256B64: (message: WAMessageContent) => string | null | undefined;
|
|
28
|
+
export declare function getAudioDuration(buffer: Buffer | string | Readable): Promise<number | undefined>;
|
|
29
|
+
/**
|
|
30
|
+
referenced from and modifying https://github.com/wppconnect-team/wa-js/blob/main/src/chat/functions/prepareAudioWaveform.ts
|
|
31
|
+
*/
|
|
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>;
|
|
35
|
+
export declare const getStream: (item: WAMediaUpload, opts?: AxiosRequestConfig) => Promise<{
|
|
36
|
+
readonly stream: Readable;
|
|
37
|
+
readonly type: "buffer";
|
|
38
|
+
} | {
|
|
39
|
+
readonly stream: Readable;
|
|
40
|
+
readonly type: "readable";
|
|
41
|
+
} | {
|
|
42
|
+
readonly stream: Readable;
|
|
43
|
+
readonly type: "remote";
|
|
44
|
+
} | {
|
|
45
|
+
readonly stream: import("fs").ReadStream;
|
|
46
|
+
readonly type: "file";
|
|
47
|
+
}>;
|
|
48
|
+
/** generates a thumbnail for a given media, if required */
|
|
49
|
+
export declare function generateThumbnail(file: string, mediaType: 'video' | 'image', options: {
|
|
50
|
+
logger?: Logger;
|
|
51
|
+
}): Promise<{
|
|
52
|
+
thumbnail: string | undefined;
|
|
53
|
+
originalImageDimensions: {
|
|
54
|
+
width: number;
|
|
55
|
+
height: number;
|
|
56
|
+
} | undefined;
|
|
57
|
+
}>;
|
|
58
|
+
export declare const getHttpStream: (url: string | URL, options?: AxiosRequestConfig & {
|
|
59
|
+
isStream?: true;
|
|
60
|
+
}) => Promise<Readable>;
|
|
61
|
+
type EncryptedStreamOptions = {
|
|
62
|
+
saveOriginalFileIfRequired?: boolean;
|
|
63
|
+
logger?: Logger;
|
|
64
|
+
opts?: AxiosRequestConfig;
|
|
65
|
+
};
|
|
66
|
+
export declare const prepareStream: (media: WAMediaUpload, mediaType: MediaType, { logger, saveOriginalFileIfRequired, opts }?: EncryptedStreamOptions) => Promise<{
|
|
67
|
+
mediaKey: undefined;
|
|
68
|
+
encWriteStream: Buffer;
|
|
69
|
+
fileLength: number;
|
|
70
|
+
fileSha256: Buffer;
|
|
71
|
+
fileEncSha256: undefined;
|
|
72
|
+
bodyPath: string | undefined;
|
|
73
|
+
didSaveToTmpPath: boolean;
|
|
74
|
+
}>;
|
|
75
|
+
export declare const encryptedStream: (media: WAMediaUpload, mediaType: MediaType, { logger, saveOriginalFileIfRequired, opts }?: EncryptedStreamOptions) => Promise<{
|
|
76
|
+
mediaKey: Buffer;
|
|
77
|
+
encWriteStream: Readable;
|
|
78
|
+
bodyPath: string | undefined;
|
|
79
|
+
mac: Buffer;
|
|
80
|
+
fileEncSha256: Buffer;
|
|
81
|
+
fileSha256: Buffer;
|
|
82
|
+
fileLength: number;
|
|
83
|
+
didSaveToTmpPath: boolean;
|
|
84
|
+
}>;
|
|
85
|
+
export type MediaDownloadOptions = {
|
|
86
|
+
startByte?: number;
|
|
87
|
+
endByte?: number;
|
|
88
|
+
options?: AxiosRequestConfig<any>;
|
|
89
|
+
};
|
|
90
|
+
export declare const getUrlFromDirectPath: (directPath: string) => string;
|
|
91
|
+
export declare const downloadContentFromMessage: ({ mediaKey, directPath, url }: DownloadableMessage, type: MediaType, opts?: MediaDownloadOptions) => Promise<Transform>;
|
|
92
|
+
/**
|
|
93
|
+
* Decrypts and downloads an AES256-CBC encrypted file given the keys.
|
|
94
|
+
* Assumes the SHA256 of the plaintext is appended to the end of the ciphertext
|
|
95
|
+
* */
|
|
96
|
+
export declare const downloadEncryptedContent: (downloadUrl: string, { cipherKey, iv }: MediaDecryptionKeyInfo, { startByte, endByte, options }?: MediaDownloadOptions) => Promise<Transform>;
|
|
97
|
+
export declare function extensionForMediaMessage(message: WAMessageContent): string;
|
|
98
|
+
export declare const getWAUploadToServer: ({ customUploadHosts, fetchAgent, logger, options }: SocketConfig, refreshMediaConn: (force: boolean) => Promise<MediaConnInfo>) => WAMediaUploadFunction;
|
|
99
|
+
/**
|
|
100
|
+
* Generate a binary node that will request the phone to re-upload the media & return the newly uploaded URL
|
|
101
|
+
*/
|
|
102
|
+
export declare const encryptMediaRetryRequest: (key: proto.IMessageKey, mediaKey: Buffer | Uint8Array, meId: string) => BinaryNode;
|
|
103
|
+
export declare const decodeMediaRetryNode: (node: BinaryNode) => {
|
|
104
|
+
key: proto.IMessageKey;
|
|
105
|
+
media?: {
|
|
106
|
+
ciphertext: Uint8Array;
|
|
107
|
+
iv: Uint8Array;
|
|
108
|
+
} | undefined;
|
|
109
|
+
error?: Boom<any> | undefined;
|
|
110
|
+
};
|
|
111
|
+
export declare const decryptMediaRetryData: ({ ciphertext, iv }: {
|
|
112
|
+
ciphertext: Uint8Array;
|
|
113
|
+
iv: Uint8Array;
|
|
114
|
+
}, mediaKey: Uint8Array, msgId: string) => proto.MediaRetryNotification;
|
|
115
|
+
export declare const getStatusCodeForMediaRetry: (code: number) => any;
|
|
116
|
+
export {};
|