@heavstaltech/baileys 2.3.4 → 3.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +226 -53
- package/WAProto/index.js +14270 -302
- package/engine-requirements.js +10 -0
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.js +118 -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 +186 -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 +140 -25
- 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 +47 -198
- 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 +201 -103
- package/lib/Utils/messages.js +36 -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 +12 -0
- package/package.json +102 -98
- package/WAProto/index.d.ts +0 -50383
- package/WASignalGroup/GroupProtocol.js +0 -1697
- package/WASignalGroup/ciphertext_message.js +0 -16
- 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
|
@@ -1,28 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.decryptMessageNode = exports.
|
|
4
|
-
exports.decodeMessageNode = decodeMessageNode;
|
|
3
|
+
exports.decryptMessageNode = exports.decodeMessageNode = void 0;
|
|
5
4
|
const boom_1 = require("@hapi/boom");
|
|
6
5
|
const WAProto_1 = require("../../WAProto");
|
|
7
6
|
const WABinary_1 = require("../WABinary");
|
|
8
7
|
const generics_1 = require("./generics");
|
|
9
|
-
|
|
10
|
-
exports.MISSING_KEYS_ERROR_TEXT = 'Key used already or never filled';
|
|
11
|
-
exports.NACK_REASONS = {
|
|
12
|
-
ParsingError: 487,
|
|
13
|
-
UnrecognizedStanza: 488,
|
|
14
|
-
UnrecognizedStanzaClass: 489,
|
|
15
|
-
UnrecognizedStanzaType: 490,
|
|
16
|
-
InvalidProtobuf: 491,
|
|
17
|
-
InvalidHostedCompanionStanza: 493,
|
|
18
|
-
MissingMessageSecret: 495,
|
|
19
|
-
SignalErrorOldCounter: 496,
|
|
20
|
-
MessageDeletedOnPeer: 499,
|
|
21
|
-
UnhandledError: 500,
|
|
22
|
-
UnsupportedAdminRevoke: 550,
|
|
23
|
-
UnsupportedLIDGroup: 551,
|
|
24
|
-
DBOperationFailed: 552
|
|
25
|
-
};
|
|
8
|
+
const NO_MESSAGE_FOUND_ERROR_TEXT = 'Message absent from node';
|
|
26
9
|
/**
|
|
27
10
|
* Decode the received node as a message.
|
|
28
11
|
* @note this will only parse the message, not decrypt it
|
|
@@ -94,21 +77,13 @@ function decodeMessageNode(stanza, meId, meLid) {
|
|
|
94
77
|
else {
|
|
95
78
|
throw new boom_1.Boom('Unknown message type', { data: stanza });
|
|
96
79
|
}
|
|
97
|
-
const fromMe = (0, WABinary_1.isJidNewsLetter)(from) ? !!((_a = stanza.attrs) === null || _a === void 0 ? void 0 : _a.is_sender) : ((0, WABinary_1.isLidUser)(
|
|
80
|
+
const fromMe = (0, WABinary_1.isJidNewsLetter)(from) ? !!((_a = stanza.attrs) === null || _a === void 0 ? void 0 : _a.is_sender) : ((0, WABinary_1.isLidUser)(from) ? isMeLid : isMe)(stanza.attrs.participant || stanza.attrs.from);
|
|
98
81
|
const pushname = stanza.attrs.notify;
|
|
99
82
|
const key = {
|
|
100
83
|
remoteJid: chatId,
|
|
101
84
|
fromMe,
|
|
102
85
|
id: msgId,
|
|
103
|
-
|
|
104
|
-
participant: fromMe ? meId : stanza.attrs.participant_pn ?? participant
|
|
105
|
-
},
|
|
106
|
-
...(stanza.attrs.participant_pn ?? participant) !== undefined && {
|
|
107
|
-
participant_pn: fromMe ? meId : stanza.attrs.participant_pn ?? participant
|
|
108
|
-
},
|
|
109
|
-
...(stanza.attrs.participant_lid ?? participant) !== undefined && {
|
|
110
|
-
participant_lid: fromMe ? meLid : stanza.attrs.participant_lid ?? participant
|
|
111
|
-
}
|
|
86
|
+
participant
|
|
112
87
|
};
|
|
113
88
|
const fullMessage = {
|
|
114
89
|
key,
|
|
@@ -128,6 +103,7 @@ function decodeMessageNode(stanza, meId, meLid) {
|
|
|
128
103
|
sender: msgType === 'chat' ? author : chatId
|
|
129
104
|
};
|
|
130
105
|
}
|
|
106
|
+
exports.decodeMessageNode = decodeMessageNode;
|
|
131
107
|
const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
132
108
|
const { fullMessage, author, sender } = decodeMessageNode(stanza, meId, meLid);
|
|
133
109
|
return {
|
|
@@ -137,11 +113,8 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
|
137
113
|
async decrypt() {
|
|
138
114
|
var _a;
|
|
139
115
|
let decryptables = 0;
|
|
140
|
-
|
|
141
|
-
const node = (0, WABinary_1.getBinaryNodeChild)(stanza, 'plaintext');
|
|
142
|
-
const msg = WAProto_1.proto.Message.decode(node === null || node === void 0 ? void 0 : node.content);
|
|
116
|
+
async function processSenderKeyDistribution(msg) {
|
|
143
117
|
if (msg.senderKeyDistributionMessage) {
|
|
144
|
-
//eslint-disable-next-line max-depth
|
|
145
118
|
try {
|
|
146
119
|
await repository.processSenderKeyDistributionMessage({
|
|
147
120
|
authorJid: author,
|
|
@@ -149,9 +122,14 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
|
149
122
|
});
|
|
150
123
|
}
|
|
151
124
|
catch (err) {
|
|
152
|
-
logger.error({ key: fullMessage.key, err }, 'failed to
|
|
125
|
+
logger.error({ key: fullMessage.key, err }, 'failed to process senderKeyDistribution');
|
|
153
126
|
}
|
|
154
127
|
}
|
|
128
|
+
}
|
|
129
|
+
if ((0, WABinary_1.isJidNewsLetter)(fullMessage.key.remoteJid)) {
|
|
130
|
+
const node = (0, WABinary_1.getBinaryNodeChild)(stanza, 'plaintext');
|
|
131
|
+
const msg = WAProto_1.proto.Message.decode(node === null || node === void 0 ? void 0 : node.content);
|
|
132
|
+
await processSenderKeyDistribution(msg);
|
|
155
133
|
fullMessage.message = msg;
|
|
156
134
|
decryptables += 1;
|
|
157
135
|
}
|
|
@@ -162,7 +140,7 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
|
162
140
|
const details = WAProto_1.proto.VerifiedNameCertificate.Details.decode(cert.details);
|
|
163
141
|
fullMessage.verifiedBizName = details.verifiedName;
|
|
164
142
|
}
|
|
165
|
-
if (tag !== 'enc'
|
|
143
|
+
if (tag !== 'enc') {
|
|
166
144
|
continue;
|
|
167
145
|
}
|
|
168
146
|
if (!(content instanceof Uint8Array)) {
|
|
@@ -171,7 +149,7 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
|
171
149
|
decryptables += 1;
|
|
172
150
|
let msgBuffer;
|
|
173
151
|
try {
|
|
174
|
-
const e2eType =
|
|
152
|
+
const e2eType = attrs.type;
|
|
175
153
|
switch (e2eType) {
|
|
176
154
|
case 'skmsg':
|
|
177
155
|
msgBuffer = await repository.decryptGroupMessage({
|
|
@@ -189,26 +167,12 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
|
189
167
|
ciphertext: content
|
|
190
168
|
});
|
|
191
169
|
break;
|
|
192
|
-
case 'plaintext':
|
|
193
|
-
msgBuffer = content;
|
|
194
|
-
break;
|
|
195
170
|
default:
|
|
196
171
|
throw new Error(`Unknown e2e type: ${e2eType}`);
|
|
197
172
|
}
|
|
198
|
-
let msg = WAProto_1.proto.Message.decode(
|
|
173
|
+
let msg = WAProto_1.proto.Message.decode((0, generics_1.unpadRandomMax16)(msgBuffer));
|
|
199
174
|
msg = ((_a = msg.deviceSentMessage) === null || _a === void 0 ? void 0 : _a.message) || msg;
|
|
200
|
-
|
|
201
|
-
//eslint-disable-next-line max-depth
|
|
202
|
-
try {
|
|
203
|
-
await repository.processSenderKeyDistributionMessage({
|
|
204
|
-
authorJid: author,
|
|
205
|
-
item: msg.senderKeyDistributionMessage
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
catch (err) {
|
|
209
|
-
logger.error({ key: fullMessage.key, err }, 'failed to decrypt message');
|
|
210
|
-
}
|
|
211
|
-
}
|
|
175
|
+
await processSenderKeyDistribution(msg);
|
|
212
176
|
if (fullMessage.message) {
|
|
213
177
|
Object.assign(fullMessage.message, msg);
|
|
214
178
|
}
|
|
@@ -226,7 +190,7 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
|
226
190
|
// if nothing was found to decrypt
|
|
227
191
|
if (!decryptables) {
|
|
228
192
|
fullMessage.messageStubType = WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT;
|
|
229
|
-
fullMessage.messageStubParameters = [
|
|
193
|
+
fullMessage.messageStubParameters = [NO_MESSAGE_FOUND_ERROR_TEXT, JSON.stringify(stanza, generics_1.BufferJSON.replacer)];
|
|
230
194
|
}
|
|
231
195
|
}
|
|
232
196
|
};
|
|
@@ -176,9 +176,6 @@ function append(data, historyCache, event, eventData, logger) {
|
|
|
176
176
|
}
|
|
177
177
|
}
|
|
178
178
|
data.historySets.empty = false;
|
|
179
|
-
data.historySets.syncType = eventData.syncType;
|
|
180
|
-
data.historySets.progress = eventData.progress;
|
|
181
|
-
data.historySets.peerDataRequestSessionId = eventData.peerDataRequestSessionId;
|
|
182
179
|
data.historySets.isLatest = eventData.isLatest || data.historySets.isLatest;
|
|
183
180
|
break;
|
|
184
181
|
case 'chats.upsert':
|
|
@@ -445,10 +442,7 @@ function consolidateEvents(data) {
|
|
|
445
442
|
chats: Object.values(data.historySets.chats),
|
|
446
443
|
messages: Object.values(data.historySets.messages),
|
|
447
444
|
contacts: Object.values(data.historySets.contacts),
|
|
448
|
-
|
|
449
|
-
progress: data.historySets.progress,
|
|
450
|
-
isLatest: data.historySets.isLatest,
|
|
451
|
-
peerDataRequestSessionId: data.historySets.peerDataRequestSessionId
|
|
445
|
+
isLatest: data.historySets.isLatest
|
|
452
446
|
};
|
|
453
447
|
}
|
|
454
448
|
const chatUpsertList = Object.values(data.chatUpserts);
|
|
@@ -502,9 +496,12 @@ function consolidateEvents(data) {
|
|
|
502
496
|
return map;
|
|
503
497
|
}
|
|
504
498
|
function concatChats(a, b) {
|
|
505
|
-
if (b.unreadCount === null
|
|
506
|
-
|
|
507
|
-
|
|
499
|
+
if (b.unreadCount === null) {
|
|
500
|
+
// neutralize unread counter
|
|
501
|
+
if (a.unreadCount < 0) {
|
|
502
|
+
a.unreadCount = undefined;
|
|
503
|
+
b.unreadCount = undefined;
|
|
504
|
+
}
|
|
508
505
|
}
|
|
509
506
|
if (typeof a.unreadCount === 'number' && typeof b.unreadCount === 'number') {
|
|
510
507
|
b = { ...b };
|
package/lib/Utils/generics.d.ts
CHANGED
|
@@ -1,20 +1,24 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import { AxiosRequestConfig } from 'axios';
|
|
2
3
|
import { Logger } from 'pino';
|
|
3
4
|
import { proto } from '../../WAProto';
|
|
4
|
-
import { BaileysEventEmitter, BaileysEventMap,
|
|
5
|
+
import { BaileysEventEmitter, BaileysEventMap, WACallUpdateType, WAVersion } from '../Types';
|
|
5
6
|
import { BinaryNode } from '../WABinary';
|
|
6
|
-
export declare const Browsers:
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
export declare const Browsers: {
|
|
8
|
+
ubuntu: (browser: any) => [string, string, string];
|
|
9
|
+
macOS: (browser: any) => [string, string, string];
|
|
10
|
+
baileys: (browser: any) => [string, string, string];
|
|
11
|
+
windows: (browser: any) => [string, string, string];
|
|
12
|
+
/** The appropriate browser based on your OS & release */
|
|
13
|
+
appropriate: (browser: any) => [string, string, string];
|
|
11
14
|
};
|
|
15
|
+
export declare const getPlatformId: (browser: string) => any;
|
|
12
16
|
export declare const getKeyAuthor: (key: proto.IMessageKey | undefined | null, meId?: string) => string;
|
|
13
|
-
export declare const writeRandomPadMax16: (msg: Uint8Array) =>
|
|
14
|
-
export declare const unpadRandomMax16: (e: Uint8Array | Buffer) => Uint8Array
|
|
15
|
-
export declare const encodeWAMessage: (message: proto.IMessage) =>
|
|
17
|
+
export declare const writeRandomPadMax16: (msg: Uint8Array) => Buffer;
|
|
18
|
+
export declare const unpadRandomMax16: (e: Uint8Array | Buffer) => Uint8Array;
|
|
19
|
+
export declare const encodeWAMessage: (message: proto.IMessage) => Buffer;
|
|
16
20
|
export declare const generateRegistrationId: () => number;
|
|
17
|
-
export declare const encodeBigEndian: (e: number, t?: number) => Uint8Array
|
|
21
|
+
export declare const encodeBigEndian: (e: number, t?: number) => Uint8Array;
|
|
18
22
|
export declare const toNumber: (t: Long | number | null | undefined) => number;
|
|
19
23
|
/** unix timestamp of a date in seconds */
|
|
20
24
|
export declare const unixTimestampSeconds: (date?: Date) => number;
|
|
@@ -34,14 +38,14 @@ export declare function promiseTimeout<T>(ms: number | undefined, promise: (reso
|
|
|
34
38
|
export declare const generateMessageIDV2: (userId?: string) => string;
|
|
35
39
|
export declare const generateMessageID: () => string;
|
|
36
40
|
export declare function bindWaitForEvent<T extends keyof BaileysEventMap>(ev: BaileysEventEmitter, event: T): (check: (u: BaileysEventMap[T]) => boolean | undefined, timeoutMs?: number) => Promise<void>;
|
|
37
|
-
export declare const bindWaitForConnectionUpdate: (ev: BaileysEventEmitter) => (check: (u: Partial<ConnectionState>) => boolean | undefined, timeoutMs?: number) => Promise<void>;
|
|
41
|
+
export declare const bindWaitForConnectionUpdate: (ev: BaileysEventEmitter) => (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number) => Promise<void>;
|
|
38
42
|
export declare const printQRIfNecessaryListener: (ev: BaileysEventEmitter, logger: Logger) => void;
|
|
39
43
|
/**
|
|
40
44
|
* utility that fetches latest baileys version from the master branch.
|
|
41
45
|
* Use to ensure your WA connection is always on the latest version
|
|
42
46
|
*/
|
|
43
47
|
export declare const fetchLatestBaileysVersion: (options?: AxiosRequestConfig<any>) => Promise<{
|
|
44
|
-
version:
|
|
48
|
+
version: WAVersion;
|
|
45
49
|
isLatest: boolean;
|
|
46
50
|
error?: undefined;
|
|
47
51
|
} | {
|
|
@@ -83,6 +87,6 @@ export declare const getCodeFromWSError: (error: Error) => number;
|
|
|
83
87
|
* Is the given platform WA business
|
|
84
88
|
* @param platform AuthenticationCreds.platform
|
|
85
89
|
*/
|
|
86
|
-
export declare const isWABusinessPlatform: (platform: string) =>
|
|
90
|
+
export declare const isWABusinessPlatform: (platform: string) => boolean;
|
|
87
91
|
export declare function trimUndefined(obj: any): any;
|
|
88
92
|
export declare function bytesToCrockford(buffer: Buffer): string;
|
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
|
};
|