@badzz88/baileys 8.5.6 → 8.5.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/WAProto/WAProto.proto +75 -1256
- package/WAProto/fix-imports.js +79 -69
- package/WAProto/index.d.ts +71491 -15254
- package/WAProto/index.js +126432 -19810
- package/engine-requirements.js +4 -3
- package/lib/Defaults/index.js +187 -0
- package/lib/Signal/Group/ciphertext-message.js +15 -0
- package/lib/Signal/Group/group-session-builder.js +92 -0
- package/lib/Signal/Group/group_cipher.js +89 -0
- package/lib/Signal/Group/index.js +136 -0
- package/lib/Signal/Group/keyhelper.js +73 -0
- package/lib/Signal/Group/sender-chain-key.js +32 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
- package/lib/Signal/Group/sender-key-message.js +69 -0
- package/lib/Signal/Group/sender-key-name.js +50 -0
- package/lib/Signal/Group/sender-key-record.js +44 -0
- package/lib/Signal/Group/sender-key-state.js +97 -0
- package/lib/Signal/Group/sender-message-key.js +30 -0
- package/lib/Signal/libsignal.js +459 -0
- package/lib/Signal/lid-mapping.js +260 -0
- package/lib/Socket/Client/index.js +30 -0
- package/lib/Socket/Client/types.js +13 -0
- package/lib/Socket/Client/websocket.js +62 -0
- package/lib/Socket/aigroups.js +240 -0
- package/lib/Socket/business.js +422 -0
- package/lib/Socket/chats.js +1816 -0
- package/lib/Socket/communities.js +549 -0
- package/lib/Socket/graphql.js +656 -0
- package/lib/Socket/groups.js +764 -0
- package/lib/Socket/index.js +39 -0
- package/lib/Socket/interactive-handler.js +522 -0
- package/lib/Socket/interop.js +549 -0
- package/{src → lib}/Socket/luxu.js +120 -82
- package/lib/Socket/managed-account.js +183 -0
- package/lib/Socket/messages-recv.js +2442 -0
- package/lib/Socket/messages-send.js +1853 -0
- package/lib/Socket/mex.js +60 -0
- package/lib/Socket/newsletter.js +818 -0
- package/lib/Socket/privacy.js +449 -0
- package/lib/Socket/registration.js +427 -0
- package/lib/Socket/socket.js +1092 -0
- package/lib/Socket/text-router.js +83 -0
- package/lib/Socket/username.js +243 -0
- package/lib/Store/index.js +36 -0
- package/{src → lib}/Store/keyed-db.js +11 -21
- package/lib/Store/make-cache-manager-store.js +90 -0
- package/lib/Store/make-in-memory-store.js +604 -0
- package/lib/Store/make-ordered-dictionary.js +81 -0
- package/lib/Store/object-repository.js +29 -0
- package/lib/Types/Auth.js +38 -0
- package/lib/Types/Bussines.js +2 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Chat.js +4 -0
- package/lib/Types/Contact.js +2 -0
- package/lib/Types/Events.js +2 -0
- package/lib/Types/GroupMetadata.js +2 -0
- package/lib/Types/Label.js +27 -0
- package/lib/Types/LabelAssociation.js +9 -0
- package/lib/Types/Message.js +95 -0
- package/lib/Types/Mex.js +112 -0
- package/lib/Types/Newsletter.js +121 -0
- package/lib/Types/Product.js +2 -0
- package/lib/Types/Signal.js +2 -0
- package/lib/Types/Socket.js +2 -0
- package/lib/Types/State.js +70 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/index.js +55 -0
- package/lib/Utils/auth-utils.js +306 -0
- package/lib/Utils/browser-utils.js +114 -0
- package/lib/Utils/business.js +247 -0
- package/lib/Utils/chat-utils.js +1208 -0
- package/lib/Utils/command-loader.d.ts +31 -0
- package/lib/Utils/command-loader.js +100 -0
- package/lib/Utils/companion-reg-client-utils.js +42 -0
- package/lib/Utils/consumer-application.js +107 -0
- package/lib/Utils/crypto.js +155 -0
- package/lib/Utils/curve25519-js.js +275 -0
- package/lib/Utils/decode-wa-message.js +560 -0
- package/lib/Utils/event-buffer.js +607 -0
- package/lib/Utils/generics.js +563 -0
- package/lib/Utils/group-history.js +60 -0
- package/lib/Utils/history.js +244 -0
- package/lib/Utils/identity-change-handler.js +52 -0
- package/lib/Utils/index.js +57 -0
- package/lib/Utils/jid-display-normalization.js +218 -0
- package/lib/Utils/link-preview.js +143 -0
- package/lib/Utils/logger.js +9 -0
- package/lib/Utils/lt-hash.js +39 -0
- package/lib/Utils/make-mutex.js +36 -0
- package/lib/Utils/message-composer.js +479 -0
- package/lib/Utils/message-retry-manager.js +270 -0
- package/lib/Utils/messages-media.js +896 -0
- package/lib/Utils/messages.js +2904 -0
- package/lib/Utils/meta-ai-msmsg.js +262 -0
- package/lib/Utils/native-bridge.js +82 -0
- package/lib/Utils/noise-handler.js +196 -0
- package/lib/Utils/offline-node-processor.js +42 -0
- package/lib/Utils/pre-key-manager.js +107 -0
- package/lib/Utils/process-message.js +1048 -0
- package/lib/Utils/reporting-utils.js +262 -0
- package/lib/Utils/session-pool.d.ts +16 -0
- package/lib/Utils/session-pool.js +94 -0
- package/lib/Utils/signal.js +224 -0
- package/lib/Utils/stanza-ack.js +40 -0
- package/lib/Utils/sticker.d.ts +17 -0
- package/lib/Utils/sticker.js +145 -0
- package/lib/Utils/sync-action-utils.js +54 -0
- package/lib/Utils/tc-token-utils.js +161 -0
- package/lib/Utils/use-multi-file-auth-state.js +121 -0
- package/lib/Utils/validate-connection.js +219 -0
- package/lib/Utils/view-once-cache.d.ts +9 -0
- package/lib/Utils/view-once-cache.js +79 -0
- package/lib/Utils/voip-rekey.js +22 -0
- package/lib/WABinary/constants.js +1304 -0
- package/lib/WABinary/decode.js +343 -0
- package/{src → lib}/WABinary/encode.js +12 -9
- package/lib/WABinary/generic-utils.js +240 -0
- package/lib/WABinary/index.js +33 -0
- package/lib/WABinary/jid-utils.js +361 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WAM/BinaryInfo.js +13 -0
- package/lib/WAM/constants.js +39486 -0
- package/lib/WAM/encode.js +142 -0
- package/lib/WAM/index.js +31 -0
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +55 -0
- package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +43 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +54 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
- package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +59 -0
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +31 -0
- package/lib/WAUSync/Protocols/USyncPictureProtocol.js +32 -0
- package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +29 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +39 -0
- package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +38 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +27 -0
- package/lib/WAUSync/Protocols/index.js +39 -0
- package/lib/WAUSync/USyncQuery.js +133 -0
- package/lib/WAUSync/USyncUser.js +50 -0
- package/lib/WAUSync/index.js +31 -0
- package/lib/antiban.js +4637 -0
- package/{src → lib}/index.js +49 -51
- package/package.json +4 -4
- package/src/Defaults/index.js +0 -186
- package/src/Signal/Group/ciphertext-message.js +0 -15
- package/src/Signal/Group/group-session-builder.js +0 -86
- package/src/Signal/Group/group_cipher.js +0 -82
- package/src/Signal/Group/index.js +0 -140
- package/src/Signal/Group/keyhelper.js +0 -77
- package/src/Signal/Group/sender-chain-key.js +0 -29
- package/src/Signal/Group/sender-key-distribution-message.js +0 -66
- package/src/Signal/Group/sender-key-message.js +0 -69
- package/src/Signal/Group/sender-key-name.js +0 -51
- package/src/Signal/Group/sender-key-record.js +0 -44
- package/src/Signal/Group/sender-key-state.js +0 -87
- package/src/Signal/Group/sender-message-key.js +0 -29
- package/src/Signal/libsignal.js +0 -455
- package/src/Signal/lid-mapping.js +0 -273
- package/src/Socket/Client/index.js +0 -31
- package/src/Socket/Client/types.js +0 -13
- package/src/Socket/Client/websocket.js +0 -61
- package/src/Socket/aigroups.js +0 -221
- package/src/Socket/business.js +0 -411
- package/src/Socket/chats.js +0 -1449
- package/src/Socket/communities.js +0 -463
- package/src/Socket/graphql.js +0 -523
- package/src/Socket/groups.js +0 -516
- package/src/Socket/index.js +0 -31
- package/src/Socket/interactive-handler.js +0 -527
- package/src/Socket/interop.js +0 -339
- package/src/Socket/managed-account.js +0 -98
- package/src/Socket/messages-recv.js +0 -2685
- package/src/Socket/messages-send.js +0 -2047
- package/src/Socket/mex.js +0 -57
- package/src/Socket/newsletter.js +0 -455
- package/src/Socket/privacy.js +0 -125
- package/src/Socket/registration.js +0 -236
- package/src/Socket/socket.js +0 -983
- package/src/Socket/text-router.js +0 -65
- package/src/Socket/username.js +0 -130
- package/src/Store/index.js +0 -33
- package/src/Store/make-cache-manager-store.js +0 -84
- package/src/Store/make-in-memory-store.js +0 -551
- package/src/Store/make-ordered-dictionary.js +0 -81
- package/src/Store/object-repository.js +0 -26
- package/src/Types/Auth.js +0 -31
- package/src/Types/Bussines.js +0 -2
- package/src/Types/Call.js +0 -2
- package/src/Types/Chat.js +0 -4
- package/src/Types/Contact.js +0 -2
- package/src/Types/Events.js +0 -2
- package/src/Types/GroupMetadata.js +0 -2
- package/src/Types/Label.js +0 -26
- package/src/Types/LabelAssociation.js +0 -8
- package/src/Types/Message.js +0 -93
- package/src/Types/Mex.js +0 -112
- package/src/Types/Newsletter.js +0 -109
- package/src/Types/Product.js +0 -2
- package/src/Types/Signal.js +0 -2
- package/src/Types/Socket.js +0 -2
- package/src/Types/State.js +0 -62
- package/src/Types/USync.js +0 -2
- package/src/Types/index.js +0 -56
- package/src/Utils/auth-utils.js +0 -254
- package/src/Utils/browser-utils.js +0 -112
- package/src/Utils/business.js +0 -240
- package/src/Utils/chat-utils.js +0 -1230
- package/src/Utils/command-loader.d.ts +0 -27
- package/src/Utils/command-loader.js +0 -89
- package/src/Utils/companion-reg-client-utils.js +0 -40
- package/src/Utils/consumer-application.js +0 -105
- package/src/Utils/crypto.js +0 -118
- package/src/Utils/curve25519-js.js +0 -242
- package/src/Utils/decode-wa-message.js +0 -529
- package/src/Utils/event-buffer.js +0 -580
- package/src/Utils/generics.js +0 -483
- package/src/Utils/group-history.js +0 -44
- package/src/Utils/history.js +0 -232
- package/src/Utils/identity-change-handler.js +0 -52
- package/src/Utils/index.js +0 -58
- package/src/Utils/jid-display-normalization.js +0 -195
- package/src/Utils/link-preview.js +0 -135
- package/src/Utils/logger.js +0 -8
- package/src/Utils/lt-hash.js +0 -25
- package/src/Utils/make-mutex.js +0 -36
- package/src/Utils/message-composer.js +0 -471
- package/src/Utils/message-retry-manager.js +0 -217
- package/src/Utils/messages-media.js +0 -843
- package/src/Utils/messages.js +0 -2817
- package/src/Utils/meta-ai-msmsg.js +0 -222
- package/src/Utils/native-bridge.js +0 -68
- package/src/Utils/noise-handler.js +0 -169
- package/src/Utils/offline-node-processor.js +0 -34
- package/src/Utils/pre-key-manager.js +0 -90
- package/src/Utils/process-message.js +0 -950
- package/src/Utils/reporting-utils.js +0 -261
- package/src/Utils/session-pool.d.ts +0 -14
- package/src/Utils/session-pool.js +0 -70
- package/src/Utils/signal.js +0 -217
- package/src/Utils/stanza-ack.js +0 -30
- package/src/Utils/sticker.d.ts +0 -13
- package/src/Utils/sticker.js +0 -123
- package/src/Utils/sync-action-utils.js +0 -45
- package/src/Utils/tc-token-utils.js +0 -158
- package/src/Utils/use-multi-file-auth-state.js +0 -111
- package/src/Utils/validate-connection.js +0 -209
- package/src/Utils/view-once-cache.d.ts +0 -12
- package/src/Utils/view-once-cache.js +0 -63
- package/src/Utils/voip-rekey.js +0 -22
- package/src/WABinary/constants.js +0 -1304
- package/src/WABinary/decode.js +0 -342
- package/src/WABinary/generic-utils.js +0 -238
- package/src/WABinary/index.js +0 -34
- package/src/WABinary/jid-utils.js +0 -351
- package/src/WABinary/types.js +0 -2
- package/src/WAM/BinaryInfo.js +0 -13
- package/src/WAM/constants.js +0 -39484
- package/src/WAM/encode.js +0 -149
- package/src/WAM/index.js +0 -32
- package/src/WAUSync/Protocols/USyncBotProfileProtocol.js +0 -53
- package/src/WAUSync/Protocols/USyncBusinessProtocol.js +0 -44
- package/src/WAUSync/Protocols/USyncContactProtocol.js +0 -55
- package/src/WAUSync/Protocols/USyncDeviceProtocol.js +0 -55
- package/src/WAUSync/Protocols/USyncDisappearingModeProtocol.js +0 -31
- package/src/WAUSync/Protocols/USyncFeatureProtocol.js +0 -54
- package/src/WAUSync/Protocols/USyncLIDProtocol.js +0 -32
- package/src/WAUSync/Protocols/USyncNewsletterProtocol.js +0 -473
- package/src/WAUSync/Protocols/USyncPictureProtocol.js +0 -34
- package/src/WAUSync/Protocols/USyncSidelistProtocol.js +0 -29
- package/src/WAUSync/Protocols/USyncStatusProtocol.js +0 -42
- package/src/WAUSync/Protocols/USyncTextStatusProtocol.js +0 -38
- package/src/WAUSync/Protocols/USyncUsernameProtocol.js +0 -28
- package/src/WAUSync/Protocols/index.js +0 -40
- package/src/WAUSync/USyncQuery.js +0 -126
- package/src/WAUSync/USyncUser.js +0 -50
- package/src/WAUSync/index.js +0 -32
- package/src/antiban.js +0 -4152
- /package/{src → lib}/Defaults/phonenumber-mcc.json +0 -0
package/src/Utils/generics.js
DELETED
|
@@ -1,483 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
|
-
exports.isWABusinessPlatform =
|
|
4
|
-
exports.getCodeFromWSError =
|
|
5
|
-
exports.getCallStatusFromNode =
|
|
6
|
-
exports.getErrorCodeFromStreamError =
|
|
7
|
-
exports.getStatusFromReceiptType =
|
|
8
|
-
exports.generateMdTagPrefix =
|
|
9
|
-
exports.fetchLatestWaWebVersion =
|
|
10
|
-
exports.fetchLatestBaileysVersion =
|
|
11
|
-
exports.bindWaitForConnectionUpdate =
|
|
12
|
-
exports.generateMessageID =
|
|
13
|
-
exports.generateMessageIDV2 =
|
|
14
|
-
exports.delayCancellable =
|
|
15
|
-
exports.delay =
|
|
16
|
-
exports.debouncedTimeout =
|
|
17
|
-
exports.unixTimestampSeconds =
|
|
18
|
-
exports.toNumber =
|
|
19
|
-
exports.encodeBigEndian =
|
|
20
|
-
exports.generateRegistrationId =
|
|
21
|
-
exports.encodeWAMessage =
|
|
22
|
-
exports.generateParticipantHashV2 =
|
|
23
|
-
exports.unpadRandomMax16 =
|
|
24
|
-
exports.writeRandomPadMax16 =
|
|
25
|
-
exports.isStringNullOrEmpty =
|
|
26
|
-
exports.getKeyAuthor =
|
|
27
|
-
exports.BufferJSON =
|
|
28
|
-
exports.jitterDelay =
|
|
29
|
-
exports.exponentialBackoff =
|
|
30
|
-
exports.bytesToHex =
|
|
31
|
-
exports.hexToBytes =
|
|
32
|
-
exports.bytesToBase64Url =
|
|
33
|
-
exports.sha256Hex =
|
|
34
|
-
exports.hmacSha256 =
|
|
35
|
-
exports.normalizeJidBatch =
|
|
36
|
-
exports.sleep =
|
|
37
|
-
exports.withRetry =
|
|
38
|
-
void 0;
|
|
39
|
-
exports.promiseTimeout = promiseTimeout;
|
|
40
|
-
exports.bindWaitForEvent = bindWaitForEvent;
|
|
41
|
-
exports.trimUndefined = trimUndefined;
|
|
42
|
-
exports.bytesToCrockford = bytesToCrockford;
|
|
43
|
-
exports.encodeNewsletterMessage = encodeNewsletterMessage;
|
|
44
|
-
exports.generateIOSMessageID = void 0;
|
|
45
|
-
exports.generateAndroMessageID = void 0;
|
|
46
|
-
const boom_1 = require('@hapi/boom');
|
|
47
|
-
const crypto_1 = require('crypto');
|
|
48
|
-
const Crypto_1 = require('./crypto');
|
|
49
|
-
const DEFAULTS_1 = require('../Defaults');
|
|
50
|
-
const index_js_1 = require('../../WAProto/index.js');
|
|
51
|
-
const baileysVersion = DEFAULTS_1.VERSION;
|
|
52
|
-
const Types_1 = require('../Types');
|
|
53
|
-
const WABinary_1 = require('../WABinary');
|
|
54
|
-
const crypto_2 = require('./crypto');
|
|
55
|
-
exports.BufferJSON = {
|
|
56
|
-
replacer: (k, value) => {
|
|
57
|
-
if (Buffer.isBuffer(value) || value instanceof Uint8Array || value?.type === 'Buffer') {
|
|
58
|
-
return { type: 'Buffer', data: Buffer.from(value?.data || value).toString('base64') };
|
|
59
|
-
}
|
|
60
|
-
return value;
|
|
61
|
-
},
|
|
62
|
-
reviver: (_, value) => {
|
|
63
|
-
if (typeof value === 'object' && value !== null && value.type === 'Buffer' && typeof value.data === 'string') {
|
|
64
|
-
return Buffer.from(value.data, 'base64');
|
|
65
|
-
}
|
|
66
|
-
if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
|
|
67
|
-
const keys = Object.keys(value);
|
|
68
|
-
if (keys.length > 0 && keys.every(k => !isNaN(parseInt(k, 10)))) {
|
|
69
|
-
const values = Object.values(value);
|
|
70
|
-
if (values.every(v => typeof v === 'number')) {
|
|
71
|
-
return Buffer.from(values);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return value;
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
const getKeyAuthor = (key, meId = 'me') => (key?.fromMe ? meId : key?.participantAlt || key?.remoteJidAlt || key?.participant || key?.remoteJid) || '';
|
|
79
|
-
exports.getKeyAuthor = getKeyAuthor;
|
|
80
|
-
const isStringNullOrEmpty = value => value == null || value === '';
|
|
81
|
-
exports.isStringNullOrEmpty = isStringNullOrEmpty;
|
|
82
|
-
const writeRandomPadMax16 = msg => {
|
|
83
|
-
const pad = (0, crypto_1.randomBytes)(1);
|
|
84
|
-
const padLength = (pad[0] & 0x0f) + 1;
|
|
85
|
-
return Buffer.concat([msg, Buffer.alloc(padLength, padLength)]);
|
|
86
|
-
};
|
|
87
|
-
exports.writeRandomPadMax16 = writeRandomPadMax16;
|
|
88
|
-
const unpadRandomMax16 = e => {
|
|
89
|
-
const t = new Uint8Array(e);
|
|
90
|
-
if (0 === t.length) {
|
|
91
|
-
throw new Error('unpadPkcs7 given empty bytes');
|
|
92
|
-
}
|
|
93
|
-
var r = t[t.length - 1];
|
|
94
|
-
if (r > t.length) {
|
|
95
|
-
throw new Error(`unpad given ${t.length} bytes, but pad is ${r}`);
|
|
96
|
-
}
|
|
97
|
-
return new Uint8Array(t.buffer, t.byteOffset, t.length - r);
|
|
98
|
-
};
|
|
99
|
-
exports.unpadRandomMax16 = unpadRandomMax16;
|
|
100
|
-
const generateParticipantHashV2 = participants => {
|
|
101
|
-
participants.sort();
|
|
102
|
-
const sha256Hash = (0, crypto_2.sha256)(Buffer.from(participants.join(''))).toString('base64');
|
|
103
|
-
return '2:' + sha256Hash.slice(0, 6);
|
|
104
|
-
};
|
|
105
|
-
exports.generateParticipantHashV2 = generateParticipantHashV2;
|
|
106
|
-
const encodeWAMessage = message => (0, exports.writeRandomPadMax16)(index_js_1.proto.Message.encode(message).finish());
|
|
107
|
-
exports.encodeWAMessage = encodeWAMessage;
|
|
108
|
-
const generateRegistrationId = () => {
|
|
109
|
-
return Uint16Array.from((0, crypto_1.randomBytes)(2))[0] & 16383;
|
|
110
|
-
};
|
|
111
|
-
exports.generateRegistrationId = generateRegistrationId;
|
|
112
|
-
const encodeBigEndian = (e, t = 4) => {
|
|
113
|
-
let r = e;
|
|
114
|
-
const a = new Uint8Array(t);
|
|
115
|
-
for (let i = t - 1; i >= 0; i--) {
|
|
116
|
-
a[i] = 255 & r;
|
|
117
|
-
r >>>= 8;
|
|
118
|
-
}
|
|
119
|
-
return a;
|
|
120
|
-
};
|
|
121
|
-
exports.encodeBigEndian = encodeBigEndian;
|
|
122
|
-
const toNumber = t => (typeof t === 'object' && t ? ('toNumber' in t ? t.toNumber() : t.low) : t || 0);
|
|
123
|
-
exports.toNumber = toNumber;
|
|
124
|
-
const unixTimestampSeconds = (date = new Date()) => Math.floor(date.getTime() / 1000);
|
|
125
|
-
exports.unixTimestampSeconds = unixTimestampSeconds;
|
|
126
|
-
const debouncedTimeout = (intervalMs = 1000, task) => {
|
|
127
|
-
let timeout;
|
|
128
|
-
return {
|
|
129
|
-
start: (newIntervalMs, newTask) => {
|
|
130
|
-
task = newTask || task;
|
|
131
|
-
intervalMs = newIntervalMs || intervalMs;
|
|
132
|
-
timeout && clearTimeout(timeout);
|
|
133
|
-
timeout = setTimeout(() => task?.(), intervalMs);
|
|
134
|
-
},
|
|
135
|
-
cancel: () => {
|
|
136
|
-
timeout && clearTimeout(timeout);
|
|
137
|
-
timeout = undefined;
|
|
138
|
-
},
|
|
139
|
-
setTask: newTask => (task = newTask),
|
|
140
|
-
setInterval: newInterval => (intervalMs = newInterval)
|
|
141
|
-
};
|
|
142
|
-
};
|
|
143
|
-
exports.debouncedTimeout = debouncedTimeout;
|
|
144
|
-
const delay = ms => (0, exports.delayCancellable)(ms).delay;
|
|
145
|
-
exports.delay = delay;
|
|
146
|
-
const delayCancellable = ms => {
|
|
147
|
-
const stack = new Error().stack;
|
|
148
|
-
let timeout;
|
|
149
|
-
let reject;
|
|
150
|
-
const delay = new Promise((resolve, _reject) => {
|
|
151
|
-
timeout = setTimeout(resolve, ms);
|
|
152
|
-
reject = _reject;
|
|
153
|
-
});
|
|
154
|
-
const cancel = () => {
|
|
155
|
-
clearTimeout(timeout);
|
|
156
|
-
reject(new boom_1.Boom('Cancelled', {
|
|
157
|
-
statusCode: 500,
|
|
158
|
-
data: {
|
|
159
|
-
stack
|
|
160
|
-
}
|
|
161
|
-
}));
|
|
162
|
-
};
|
|
163
|
-
return { delay, cancel };
|
|
164
|
-
};
|
|
165
|
-
exports.delayCancellable = delayCancellable;
|
|
166
|
-
async function promiseTimeout(ms, promise) {
|
|
167
|
-
if (!ms) {
|
|
168
|
-
return new Promise(promise);
|
|
169
|
-
}
|
|
170
|
-
const stack = new Error().stack;
|
|
171
|
-
const { delay, cancel } = (0, exports.delayCancellable)(ms);
|
|
172
|
-
const p = new Promise((resolve, reject) => {
|
|
173
|
-
delay
|
|
174
|
-
.then(() => reject(new boom_1.Boom('Timed Out', {
|
|
175
|
-
statusCode: Types_1.DisconnectReason.timedOut,
|
|
176
|
-
data: {
|
|
177
|
-
stack
|
|
178
|
-
}
|
|
179
|
-
})))
|
|
180
|
-
.catch(err => reject(err));
|
|
181
|
-
promise(resolve, reject);
|
|
182
|
-
}).finally(cancel);
|
|
183
|
-
return p;
|
|
184
|
-
}
|
|
185
|
-
const generateMessageIDV2 = (userId) => {
|
|
186
|
-
const data = Buffer.alloc(8 + 20 + 16);
|
|
187
|
-
data.writeBigUInt64BE(BigInt(Math.floor(Date.now() / 1000)));
|
|
188
|
-
if (userId) {
|
|
189
|
-
const id = (0, WABinary_1.jidDecode)(userId);
|
|
190
|
-
if (id?.user) {
|
|
191
|
-
data.write(id.user, 8);
|
|
192
|
-
data.write('@c.us', 8 + id.user.length);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
const random = (0, crypto_1.randomBytes)(16);
|
|
196
|
-
random.copy(data, 28);
|
|
197
|
-
const hash = (0, crypto_1.createHash)('sha256').update(data).digest();
|
|
198
|
-
return 'XZCYYX-' + hash.toString('hex').toUpperCase().substring(0, 18);
|
|
199
|
-
};
|
|
200
|
-
exports.generateMessageIDV2 = generateMessageIDV2;
|
|
201
|
-
const generateIOSMessageID = () => {
|
|
202
|
-
const prefix = '3A';
|
|
203
|
-
const random = (0, crypto_1.randomBytes)(9.5);
|
|
204
|
-
return (prefix + random.toString('hex')).toUpperCase().substring(0, 21);
|
|
205
|
-
};
|
|
206
|
-
exports.generateIOSMessageID = generateIOSMessageID;
|
|
207
|
-
const generateAndroMessageID = () => {
|
|
208
|
-
const prefix = '3A';
|
|
209
|
-
const random = (0, crypto_1.randomBytes)(16);
|
|
210
|
-
return (random.toString('hex')).toUpperCase().substring(0, 21);
|
|
211
|
-
};
|
|
212
|
-
exports.generateAndroMessageID = generateAndroMessageID;
|
|
213
|
-
const generateMessageID = () => 'XZCYYX-' + (0, crypto_1.randomBytes)(18).toString('hex').toUpperCase();
|
|
214
|
-
exports.generateMessageID = generateMessageID;
|
|
215
|
-
function bindWaitForEvent(ev, event) {
|
|
216
|
-
return async (check, timeoutMs) => {
|
|
217
|
-
let listener;
|
|
218
|
-
let closeListener;
|
|
219
|
-
await promiseTimeout(timeoutMs, (resolve, reject) => {
|
|
220
|
-
closeListener = ({ connection, lastDisconnect }) => {
|
|
221
|
-
if (connection === 'close') {
|
|
222
|
-
reject(lastDisconnect?.error ||
|
|
223
|
-
new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed }));
|
|
224
|
-
}
|
|
225
|
-
};
|
|
226
|
-
ev.on('connection.update', closeListener);
|
|
227
|
-
listener = async (update) => {
|
|
228
|
-
if (await check(update)) {
|
|
229
|
-
resolve();
|
|
230
|
-
}
|
|
231
|
-
};
|
|
232
|
-
ev.on(event, listener);
|
|
233
|
-
}).finally(() => {
|
|
234
|
-
ev.off(event, listener);
|
|
235
|
-
ev.off('connection.update', closeListener);
|
|
236
|
-
});
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
const bindWaitForConnectionUpdate = ev => bindWaitForEvent(ev, 'connection.update');
|
|
240
|
-
exports.bindWaitForConnectionUpdate = bindWaitForConnectionUpdate;
|
|
241
|
-
const fetchLatestBaileysVersion = async (options = {}) => {
|
|
242
|
-
const URL = 'https://raw.githubusercontent.com/WhiskeySockets/Baileys/master/src/Defaults/index.ts';
|
|
243
|
-
try {
|
|
244
|
-
const response = await fetch(URL, {
|
|
245
|
-
dispatcher: options.dispatcher,
|
|
246
|
-
method: 'GET',
|
|
247
|
-
headers: options.headers
|
|
248
|
-
});
|
|
249
|
-
if (!response.ok) {
|
|
250
|
-
throw new boom_1.Boom(`Failed to fetch latest Baileys version: ${response.statusText}`, {
|
|
251
|
-
statusCode: response.status
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
const text = await response.text();
|
|
255
|
-
const lines = text.split('\n');
|
|
256
|
-
const versionLine = lines[6];
|
|
257
|
-
const versionMatch = versionLine.match(/const version = \[(\d+),\s*(\d+),\s*(\d+)\]/);
|
|
258
|
-
if (versionMatch) {
|
|
259
|
-
const version = [parseInt(versionMatch[1]), parseInt(versionMatch[2]), parseInt(versionMatch[3])];
|
|
260
|
-
return {
|
|
261
|
-
version,
|
|
262
|
-
isLatest: true
|
|
263
|
-
};
|
|
264
|
-
}
|
|
265
|
-
else {
|
|
266
|
-
throw new Error('Could not parse version from Defaults/index.ts');
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
catch (error) {
|
|
270
|
-
return {
|
|
271
|
-
version: baileysVersion,
|
|
272
|
-
isLatest: false,
|
|
273
|
-
error
|
|
274
|
-
};
|
|
275
|
-
}
|
|
276
|
-
};
|
|
277
|
-
exports.fetchLatestBaileysVersion = fetchLatestBaileysVersion;
|
|
278
|
-
const fetchLatestWaWebVersion = async (options = {}) => {
|
|
279
|
-
try {
|
|
280
|
-
const defaultHeaders = {
|
|
281
|
-
'sec-fetch-site': 'none',
|
|
282
|
-
'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36'
|
|
283
|
-
};
|
|
284
|
-
const headers = { ...defaultHeaders, ...options.headers };
|
|
285
|
-
const response = await fetch('https://web.whatsapp.com/sw.js', {
|
|
286
|
-
...options,
|
|
287
|
-
method: 'GET',
|
|
288
|
-
headers
|
|
289
|
-
});
|
|
290
|
-
if (!response.ok) {
|
|
291
|
-
throw new boom_1.Boom(`Failed to fetch sw.js: ${response.statusText}`, { statusCode: response.status });
|
|
292
|
-
}
|
|
293
|
-
const data = await response.text();
|
|
294
|
-
const regex = /\\?"client_revision\\?":\s*(\d+)/;
|
|
295
|
-
const match = data.match(regex);
|
|
296
|
-
if (!match?.[1]) {
|
|
297
|
-
return {
|
|
298
|
-
version: baileysVersion,
|
|
299
|
-
isLatest: false,
|
|
300
|
-
error: {
|
|
301
|
-
message: 'Could not find client revision in the fetched content'
|
|
302
|
-
}
|
|
303
|
-
};
|
|
304
|
-
}
|
|
305
|
-
const clientRevision = match[1];
|
|
306
|
-
return {
|
|
307
|
-
version: [2, 3000, +clientRevision],
|
|
308
|
-
isLatest: true
|
|
309
|
-
};
|
|
310
|
-
}
|
|
311
|
-
catch (error) {
|
|
312
|
-
return {
|
|
313
|
-
version: baileysVersion,
|
|
314
|
-
isLatest: false,
|
|
315
|
-
error
|
|
316
|
-
};
|
|
317
|
-
}
|
|
318
|
-
};
|
|
319
|
-
exports.fetchLatestWaWebVersion = fetchLatestWaWebVersion;
|
|
320
|
-
const generateMdTagPrefix = () => {
|
|
321
|
-
const bytes = (0, crypto_1.randomBytes)(4);
|
|
322
|
-
return `${bytes.readUInt16BE()}.${bytes.readUInt16BE(2)}-`;
|
|
323
|
-
};
|
|
324
|
-
exports.generateMdTagPrefix = generateMdTagPrefix;
|
|
325
|
-
const STATUS_MAP = {
|
|
326
|
-
sender: index_js_1.proto.WebMessageInfo.Status.SERVER_ACK,
|
|
327
|
-
played: index_js_1.proto.WebMessageInfo.Status.PLAYED,
|
|
328
|
-
read: index_js_1.proto.WebMessageInfo.Status.READ,
|
|
329
|
-
'read-self': index_js_1.proto.WebMessageInfo.Status.READ
|
|
330
|
-
};
|
|
331
|
-
const getStatusFromReceiptType = type => {
|
|
332
|
-
const status = STATUS_MAP[type];
|
|
333
|
-
if (typeof type === 'undefined') {
|
|
334
|
-
return index_js_1.proto.WebMessageInfo.Status.DELIVERY_ACK;
|
|
335
|
-
}
|
|
336
|
-
return status;
|
|
337
|
-
};
|
|
338
|
-
exports.getStatusFromReceiptType = getStatusFromReceiptType;
|
|
339
|
-
const CODE_MAP = {
|
|
340
|
-
conflict: Types_1.DisconnectReason.connectionReplaced
|
|
341
|
-
};
|
|
342
|
-
const getErrorCodeFromStreamError = node => {
|
|
343
|
-
const [reasonNode] = (0, WABinary_1.getAllBinaryNodeChildren)(node);
|
|
344
|
-
let reason = reasonNode?.tag || 'unknown';
|
|
345
|
-
const statusCode = +(node.attrs.code || CODE_MAP[reason] || Types_1.DisconnectReason.badSession);
|
|
346
|
-
if (statusCode === Types_1.DisconnectReason.restartRequired) {
|
|
347
|
-
reason = 'restart required';
|
|
348
|
-
}
|
|
349
|
-
return {
|
|
350
|
-
reason,
|
|
351
|
-
statusCode
|
|
352
|
-
};
|
|
353
|
-
};
|
|
354
|
-
exports.getErrorCodeFromStreamError = getErrorCodeFromStreamError;
|
|
355
|
-
const getCallStatusFromNode = ({ tag, attrs }) => {
|
|
356
|
-
let status;
|
|
357
|
-
switch (tag) {
|
|
358
|
-
case 'offer':
|
|
359
|
-
case 'offer_notice':
|
|
360
|
-
status = 'offer';
|
|
361
|
-
break;
|
|
362
|
-
case 'terminate':
|
|
363
|
-
if (attrs.reason === 'timeout') {
|
|
364
|
-
status = 'timeout';
|
|
365
|
-
}
|
|
366
|
-
else {
|
|
367
|
-
status = 'terminate';
|
|
368
|
-
}
|
|
369
|
-
break;
|
|
370
|
-
case 'reject':
|
|
371
|
-
status = 'reject';
|
|
372
|
-
break;
|
|
373
|
-
case 'accept':
|
|
374
|
-
status = 'accept';
|
|
375
|
-
break;
|
|
376
|
-
default:
|
|
377
|
-
status = 'ringing';
|
|
378
|
-
break;
|
|
379
|
-
}
|
|
380
|
-
return status;
|
|
381
|
-
};
|
|
382
|
-
exports.getCallStatusFromNode = getCallStatusFromNode;
|
|
383
|
-
const UNEXPECTED_SERVER_CODE_TEXT = 'Unexpected server response: ';
|
|
384
|
-
const getCodeFromWSError = error => {
|
|
385
|
-
let statusCode = 500;
|
|
386
|
-
if (error?.message?.includes(UNEXPECTED_SERVER_CODE_TEXT)) {
|
|
387
|
-
const code = +error?.message.slice(UNEXPECTED_SERVER_CODE_TEXT.length);
|
|
388
|
-
if (!Number.isNaN(code) && code >= 400) {
|
|
389
|
-
statusCode = code;
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
else if (error?.code?.startsWith('E') ||
|
|
393
|
-
error?.message?.includes('timed out')) {
|
|
394
|
-
statusCode = 408;
|
|
395
|
-
}
|
|
396
|
-
return statusCode;
|
|
397
|
-
};
|
|
398
|
-
exports.getCodeFromWSError = getCodeFromWSError;
|
|
399
|
-
const isWABusinessPlatform = platform => {
|
|
400
|
-
return platform === 'smbi' || platform === 'smba';
|
|
401
|
-
};
|
|
402
|
-
exports.isWABusinessPlatform = isWABusinessPlatform;
|
|
403
|
-
function trimUndefined(obj) {
|
|
404
|
-
for (const key in obj) {
|
|
405
|
-
if (typeof obj[key] === 'undefined') {
|
|
406
|
-
delete obj[key];
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
return obj;
|
|
410
|
-
}
|
|
411
|
-
const CROCKFORD_CHARACTERS = '123456789ABCDEFGHJKLMNPQRSTVWXYZ';
|
|
412
|
-
function bytesToCrockford(buffer) {
|
|
413
|
-
let value = 0;
|
|
414
|
-
let bitCount = 0;
|
|
415
|
-
const crockford = [];
|
|
416
|
-
for (const element of buffer) {
|
|
417
|
-
value = (value << 8) | (element & 0xff);
|
|
418
|
-
bitCount += 8;
|
|
419
|
-
while (bitCount >= 5) {
|
|
420
|
-
crockford.push(CROCKFORD_CHARACTERS.charAt((value >>> (bitCount - 5)) & 31));
|
|
421
|
-
bitCount -= 5;
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
if (bitCount > 0) {
|
|
425
|
-
crockford.push(CROCKFORD_CHARACTERS.charAt((value << (5 - bitCount)) & 31));
|
|
426
|
-
}
|
|
427
|
-
return crockford.join('');
|
|
428
|
-
}
|
|
429
|
-
function encodeNewsletterMessage(message) {
|
|
430
|
-
return index_js_1.proto.Message.encode(message).finish();
|
|
431
|
-
}
|
|
432
|
-
const jitterDelay = (baseMs, varianceFraction = 0.3) => {
|
|
433
|
-
const variance = baseMs * varianceFraction;
|
|
434
|
-
return baseMs + (Math.random() * 2 - 1) * variance;
|
|
435
|
-
};
|
|
436
|
-
exports.jitterDelay = jitterDelay;
|
|
437
|
-
const exponentialBackoff = (attempt, baseMs = 500, maxMs = 30000) => {
|
|
438
|
-
return Math.min(baseMs * Math.pow(2, attempt), maxMs);
|
|
439
|
-
};
|
|
440
|
-
exports.exponentialBackoff = exponentialBackoff;
|
|
441
|
-
const bytesToHex = buf => Buffer.from(buf).toString('hex');
|
|
442
|
-
exports.bytesToHex = bytesToHex;
|
|
443
|
-
const hexToBytes = hex => Buffer.from(hex, 'hex');
|
|
444
|
-
exports.hexToBytes = hexToBytes;
|
|
445
|
-
const bytesToBase64Url = buf => Buffer.from(buf).toString('base64url');
|
|
446
|
-
exports.bytesToBase64Url = bytesToBase64Url;
|
|
447
|
-
const sha256Hex = data => (0, crypto_1.createHash)('sha256').update(data).digest('hex');
|
|
448
|
-
exports.sha256Hex = sha256Hex;
|
|
449
|
-
const hmacSha256 = (data, key) => (0, crypto_1.createHmac)('sha256', key).update(data).digest();
|
|
450
|
-
exports.hmacSha256 = hmacSha256;
|
|
451
|
-
const normalizeJidBatch = (jids, normalizer) => {
|
|
452
|
-
const seen = new Set();
|
|
453
|
-
const result = [];
|
|
454
|
-
for (const jid of jids) {
|
|
455
|
-
if (!jid)
|
|
456
|
-
continue;
|
|
457
|
-
const normalized = normalizer ? normalizer(jid) : jid;
|
|
458
|
-
if (!seen.has(normalized)) {
|
|
459
|
-
seen.add(normalized);
|
|
460
|
-
result.push(normalized);
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
return result;
|
|
464
|
-
};
|
|
465
|
-
exports.normalizeJidBatch = normalizeJidBatch;
|
|
466
|
-
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
|
|
467
|
-
exports.sleep = sleep;
|
|
468
|
-
const withRetry = async (fn, maxAttempts = 3, baseDelayMs = 500) => {
|
|
469
|
-
let lastErr;
|
|
470
|
-
for (let i = 0; i < maxAttempts; i++) {
|
|
471
|
-
try {
|
|
472
|
-
return await fn();
|
|
473
|
-
}
|
|
474
|
-
catch (err) {
|
|
475
|
-
lastErr = err;
|
|
476
|
-
if (i < maxAttempts - 1) {
|
|
477
|
-
await sleep(exponentialBackoff(i, baseDelayMs));
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
throw lastErr;
|
|
482
|
-
};
|
|
483
|
-
exports.withRetry = withRetry;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
|
-
exports.processGroupHistory = exports.decodeGroupHistory = void 0;
|
|
4
|
-
const zlib_1 = require('zlib');
|
|
5
|
-
const index_js_1 = require('../../WAProto/index.js');
|
|
6
|
-
const decodeGroupHistory = (buffer, options = {}) => {
|
|
7
|
-
const { inflate = true, withMessageBytes = false } = options;
|
|
8
|
-
if (!Buffer.isBuffer(buffer) && !(buffer instanceof Uint8Array)) {
|
|
9
|
-
throw new TypeError('decodeGroupHistory: buffer must be Buffer or Uint8Array');
|
|
10
|
-
}
|
|
11
|
-
let data = Buffer.isBuffer(buffer) ? buffer : Buffer.from(buffer);
|
|
12
|
-
if (inflate) {
|
|
13
|
-
try {
|
|
14
|
-
data = zlib_1.inflateSync(data);
|
|
15
|
-
}
|
|
16
|
-
catch {
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
if (withMessageBytes) {
|
|
20
|
-
const decoded = index_js_1.proto.GroupHistoryWithMessageBytes.decode(data);
|
|
21
|
-
const expand = list => (list || []).map(entry => entry?.messageBytes ? index_js_1.proto.WebMessageInfo.decode(entry.messageBytes) : { key: entry?.key });
|
|
22
|
-
return {
|
|
23
|
-
messages: expand(decoded.messages),
|
|
24
|
-
commentMessages: expand(decoded.commentMessages),
|
|
25
|
-
outOfWindowPinnedMessages: expand(decoded.outOfWindowPinnedMessages),
|
|
26
|
-
uncountedAssociatedMessageLists: (decoded.uncountedAssociatedMessageLists || []).map(l => ({
|
|
27
|
-
parentMessage: l.parentMessage,
|
|
28
|
-
messages: expand(l.messages)
|
|
29
|
-
}))
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
return index_js_1.proto.GroupHistory.decode(data);
|
|
33
|
-
};
|
|
34
|
-
exports.decodeGroupHistory = decodeGroupHistory;
|
|
35
|
-
const processGroupHistory = groupHistory => {
|
|
36
|
-
const gh = groupHistory || {};
|
|
37
|
-
return {
|
|
38
|
-
messages: gh.messages || [],
|
|
39
|
-
commentMessages: gh.commentMessages || [],
|
|
40
|
-
outOfWindowPinnedMessages: gh.outOfWindowPinnedMessages || [],
|
|
41
|
-
uncountedAssociatedMessageLists: gh.uncountedAssociatedMessageLists || []
|
|
42
|
-
};
|
|
43
|
-
};
|
|
44
|
-
exports.processGroupHistory = processGroupHistory;
|