jagproject 26.3.23 → 26.3.26
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/GenerateStatics.sh +3 -4
- package/WAProto/WAProto.proto +1215 -511
- package/WAProto/fix-imports.js +73 -0
- package/WAProto/index.d.ts +14017 -0
- package/WAProto/index.js +64857 -145167
- package/engine-requirements.js +4 -7
- package/lib/Defaults/index.d.ts +74 -0
- package/lib/Defaults/index.js +49 -35
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Defaults/wileys-version.json +2 -2
- 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-session-builder.js +5 -3
- package/lib/Signal/Group/group_cipher.d.ts +17 -0
- package/lib/Signal/Group/group_cipher.js +35 -46
- package/lib/Signal/Group/index.d.ts +12 -0
- package/lib/Signal/Group/index.js +21 -21
- package/lib/Signal/Group/keyhelper.d.ts +11 -0
- package/lib/Signal/Group/keyhelper.js +2 -2
- package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
- package/lib/Signal/Group/sender-chain-key.js +5 -10
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +7 -7
- package/lib/Signal/Group/sender-key-message.d.ts +19 -0
- package/lib/Signal/Group/sender-key-message.js +8 -8
- 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-record.js +7 -16
- package/lib/Signal/Group/sender-key-state.d.ts +39 -0
- package/lib/Signal/Group/sender-key-state.js +25 -37
- package/lib/Signal/Group/sender-message-key.d.ts +12 -0
- package/lib/Signal/Group/sender-message-key.js +2 -2
- package/lib/Signal/libsignal.d.ts +5 -0
- package/lib/Signal/libsignal.js +358 -54
- package/lib/Signal/lid-mapping.d.ts +19 -0
- package/lib/Signal/lid-mapping.js +274 -0
- package/lib/Socket/Client/index.d.ts +3 -0
- package/lib/Socket/Client/index.js +2 -2
- package/lib/Socket/Client/types.d.ts +16 -0
- package/lib/Socket/Client/types.js +1 -0
- package/lib/Socket/Client/websocket.d.ts +13 -0
- package/lib/Socket/Client/websocket.js +18 -30
- package/lib/Socket/business.d.ts +202 -0
- package/lib/Socket/business.js +160 -38
- package/lib/Socket/chats.d.ts +111 -0
- package/lib/Socket/chats.js +497 -314
- package/lib/Socket/communities.d.ts +258 -0
- package/lib/Socket/communities.js +438 -0
- package/lib/Socket/community.js +333 -0
- package/lib/Socket/groups.d.ts +150 -0
- package/lib/Socket/groups.js +229 -91
- package/lib/Socket/index.d.ts +245 -0
- package/lib/Socket/index.js +9 -6
- package/lib/Socket/messages-recv.d.ts +187 -0
- package/lib/Socket/messages-recv.js +1105 -501
- package/lib/Socket/messages-send.d.ts +183 -0
- package/lib/Socket/messages-send.js +1181 -501
- package/lib/Socket/mex.d.ts +3 -0
- package/lib/Socket/mex.js +45 -0
- package/lib/Socket/newsletter.d.ts +160 -0
- package/lib/Socket/newsletter.js +227 -200
- package/lib/Socket/socket.d.ts +55 -0
- package/lib/Socket/socket.js +507 -206
- package/lib/Socket/usync.js +6 -6
- package/lib/Store/index.js +17 -5
- package/lib/Store/make-cache-manager-store.js +83 -0
- package/lib/Store/make-in-memory-store.js +48 -89
- package/lib/Store/make-ordered-dictionary.js +1 -1
- package/lib/Types/Auth.d.ts +116 -0
- package/lib/Types/Bussines.d.ts +25 -0
- package/lib/Types/Bussines.js +2 -0
- package/lib/Types/Call.d.ts +15 -0
- package/lib/Types/Chat.d.ts +123 -0
- package/lib/Types/Chat.js +7 -1
- package/lib/Types/Contact.d.ts +24 -0
- package/lib/Types/Events.d.ts +237 -0
- package/lib/Types/Events.js +1 -0
- package/lib/Types/GroupMetadata.d.ts +67 -0
- package/lib/Types/Label.d.ts +47 -0
- package/lib/Types/Label.js +1 -3
- package/lib/Types/LabelAssociation.d.ts +30 -0
- package/lib/Types/LabelAssociation.js +1 -3
- package/lib/Types/Message.d.ts +305 -0
- package/lib/Types/Message.js +9 -5
- package/lib/Types/MexUpdates.js +11 -0
- package/lib/Types/Newsletter.d.ts +135 -0
- package/lib/Types/Newsletter.js +36 -11
- package/lib/Types/Product.d.ts +79 -0
- package/lib/Types/Signal.d.ts +76 -0
- package/lib/Types/Signal.js +1 -0
- package/lib/Types/Socket.d.ts +133 -0
- package/lib/Types/Socket.js +1 -0
- package/lib/Types/State.d.ts +39 -0
- package/lib/Types/State.js +12 -0
- package/lib/Types/USync.d.ts +26 -0
- package/lib/Types/USync.js +1 -0
- package/lib/Types/index.d.ts +65 -0
- package/lib/Types/index.js +14 -14
- package/lib/Utils/audioToBuffer.js +31 -0
- package/lib/Utils/auth-utils.d.ts +19 -0
- package/lib/Utils/auth-utils.js +222 -123
- package/lib/Utils/baileys-event-stream.js +60 -0
- package/lib/Utils/bridge-runtime.d.ts +1 -0
- package/lib/Utils/bridge-runtime.js +14 -0
- package/lib/Utils/browser-utils.d.ts +4 -0
- package/lib/Utils/browser-utils.js +38 -29
- package/lib/Utils/business.d.ts +23 -0
- package/lib/Utils/business.js +54 -48
- package/lib/Utils/chat-utils.d.ts +70 -0
- package/lib/Utils/chat-utils.js +284 -189
- package/lib/Utils/crypto.d.ts +37 -0
- package/lib/Utils/crypto.js +16 -41
- package/lib/Utils/decode-wa-message.d.ts +48 -0
- package/lib/Utils/decode-wa-message.js +128 -48
- package/lib/Utils/event-buffer.d.ts +34 -0
- package/lib/Utils/event-buffer.js +124 -62
- package/lib/Utils/generics.d.ts +91 -0
- package/lib/Utils/generics.js +154 -138
- package/lib/Utils/history.d.ts +22 -0
- package/lib/Utils/history.js +77 -34
- package/lib/Utils/identity-change-handler.d.ts +37 -0
- package/lib/Utils/identity-change-handler.js +54 -0
- package/lib/Utils/index.d.ts +22 -0
- package/lib/Utils/index.js +32 -19
- package/lib/Utils/link-preview.d.ts +21 -0
- package/lib/Utils/link-preview.js +12 -17
- package/lib/Utils/logger.d.ts +13 -0
- package/lib/Utils/lt-hash.d.ts +8 -0
- package/lib/Utils/lt-hash.js +2 -43
- package/lib/Utils/make-mutex.d.ts +9 -0
- package/lib/Utils/make-mutex.js +21 -27
- package/lib/Utils/message-retry-manager.d.ts +110 -0
- package/lib/Utils/message-retry-manager.js +143 -45
- package/lib/Utils/messages-media.d.ts +130 -0
- package/lib/Utils/messages-media.js +429 -502
- package/lib/Utils/messages-newsletter.d.ts +84 -0
- package/lib/Utils/messages-newsletter.js +295 -0
- package/lib/Utils/messages.d.ts +92 -0
- package/lib/Utils/messages.js +1025 -674
- package/lib/Utils/noise-handler.d.ts +20 -0
- package/lib/Utils/noise-handler.js +145 -91
- package/lib/Utils/pre-key-manager.d.ts +28 -0
- package/lib/Utils/pre-key-manager.js +112 -0
- package/lib/Utils/process-message.d.ts +60 -0
- package/lib/Utils/process-message.js +316 -184
- package/lib/Utils/reporting-utils.d.ts +11 -0
- package/lib/Utils/reporting-utils.js +262 -0
- package/lib/Utils/resolve-jid.d.ts +43 -0
- package/lib/Utils/resolve-jid.js +95 -0
- package/lib/Utils/rust-bridge-shim.d.ts +22 -0
- package/lib/Utils/rust-bridge-shim.js +70 -0
- package/lib/Utils/serial-task-queue.js +29 -0
- package/lib/Utils/signal.d.ts +34 -0
- package/lib/Utils/signal.js +56 -39
- package/lib/Utils/streamToBuffer.js +17 -0
- package/lib/Utils/sync-action-utils.d.ts +19 -0
- package/lib/Utils/sync-action-utils.js +52 -0
- package/lib/Utils/tc-token-utils.d.ts +12 -0
- package/lib/Utils/tc-token-utils.js +20 -0
- package/lib/Utils/use-mongo-file-auth-state.js +71 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
- package/lib/Utils/use-multi-file-auth-state.js +11 -12
- package/lib/Utils/use-single-file-auth-state.js +73 -0
- package/lib/Utils/validate-connection.d.ts +11 -0
- package/lib/Utils/validate-connection.js +59 -82
- package/lib/Utils/wileys-event-stream.js +1 -61
- package/lib/WABinary/constants.d.ts +28 -0
- package/lib/WABinary/decode.d.ts +7 -0
- package/lib/WABinary/decode.js +39 -4
- package/lib/WABinary/encode.d.ts +3 -0
- package/lib/WABinary/encode.js +17 -11
- package/lib/WABinary/generic-utils.d.ts +15 -0
- package/lib/WABinary/generic-utils.js +46 -18
- package/lib/WABinary/index.d.ts +6 -0
- package/lib/WABinary/index.js +9 -5
- package/lib/WABinary/jid-utils.d.ts +48 -0
- package/lib/WABinary/jid-utils.js +67 -37
- package/lib/WABinary/types.d.ts +19 -0
- package/lib/WABinary/types.js +34 -0
- package/lib/WAM/BinaryInfo.d.ts +9 -0
- package/lib/WAM/constants.d.ts +40 -0
- package/lib/WAM/constants.js +19183 -11678
- package/lib/WAM/encode.d.ts +3 -0
- package/lib/WAM/encode.js +15 -17
- package/lib/WAM/index.d.ts +4 -0
- package/lib/WAM/index.js +3 -3
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +6 -6
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +9 -9
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +6 -6
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +7 -8
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +18 -17
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +11 -3
- package/lib/WAUSync/Protocols/index.d.ts +5 -0
- package/lib/WAUSync/Protocols/index.js +6 -4
- package/lib/WAUSync/USyncQuery.d.ts +29 -0
- package/lib/WAUSync/USyncQuery.js +38 -30
- package/lib/WAUSync/USyncUser.d.ts +13 -0
- package/lib/WAUSync/index.d.ts +4 -0
- package/lib/WAUSync/index.js +3 -3
- package/lib/index.d.ts +12 -0
- package/lib/index.js +3 -5
- package/package.json +7 -4
- package/LICENSE +0 -21
package/lib/Utils/history.js
CHANGED
|
@@ -3,15 +3,30 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getHistoryMsg = exports.downloadAndProcessHistorySyncNotification = exports.processHistoryMessage = exports.downloadHistory = void 0;
|
|
4
4
|
const util_1 = require("util");
|
|
5
5
|
const zlib_1 = require("zlib");
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
6
|
+
const index_js_1 = require("../../WAProto/index.js");
|
|
7
|
+
const index_js_2 = require("../Types/index.js");
|
|
8
|
+
const index_js_3 = require("../WABinary/index.js");
|
|
9
|
+
const generics_js_1 = require("./generics.js");
|
|
10
|
+
const messages_js_1 = require("./messages.js");
|
|
11
|
+
const messages_media_js_1 = require("./messages-media.js");
|
|
12
12
|
const inflatePromise = (0, util_1.promisify)(zlib_1.inflate);
|
|
13
|
+
const extractPnFromMessages = (messages) => {
|
|
14
|
+
for (const msgItem of messages) {
|
|
15
|
+
const message = msgItem.message;
|
|
16
|
+
// Only extract from outgoing messages (fromMe: true) in 1:1 chats
|
|
17
|
+
// because userReceipt.userJid is the recipient's JID
|
|
18
|
+
if (!message?.key?.fromMe || !message.userReceipt?.length) {
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
const userJid = message.userReceipt[0]?.userJid;
|
|
22
|
+
if (userJid && ((0, index_js_3.isPnUser)(userJid) || (0, index_js_3.isHostedPnUser)(userJid))) {
|
|
23
|
+
return userJid;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return undefined;
|
|
27
|
+
};
|
|
13
28
|
const downloadHistory = async (msg, options) => {
|
|
14
|
-
const stream = await (0,
|
|
29
|
+
const stream = await (0, messages_media_js_1.downloadContentFromMessage)(msg, 'md-msg-hist', { options });
|
|
15
30
|
const bufferArray = [];
|
|
16
31
|
for await (const chunk of stream) {
|
|
17
32
|
bufferArray.push(chunk);
|
|
@@ -19,53 +34,75 @@ const downloadHistory = async (msg, options) => {
|
|
|
19
34
|
let buffer = Buffer.concat(bufferArray);
|
|
20
35
|
// decompress buffer
|
|
21
36
|
buffer = await inflatePromise(buffer);
|
|
22
|
-
const syncData =
|
|
37
|
+
const syncData = index_js_1.proto.HistorySync.decode(buffer);
|
|
23
38
|
return syncData;
|
|
24
39
|
};
|
|
25
40
|
exports.downloadHistory = downloadHistory;
|
|
26
|
-
const processHistoryMessage = (item) => {
|
|
27
|
-
var _a, _b, _c;
|
|
41
|
+
const processHistoryMessage = (item, logger) => {
|
|
28
42
|
const messages = [];
|
|
29
43
|
const contacts = [];
|
|
30
44
|
const chats = [];
|
|
45
|
+
const lidPnMappings = [];
|
|
46
|
+
logger?.trace({ progress: item.progress }, 'processing history of type ' + item.syncType?.toString());
|
|
47
|
+
// Extract LID-PN mappings for all sync types
|
|
48
|
+
for (const m of item.phoneNumberToLidMappings || []) {
|
|
49
|
+
if (m.lidJid && m.pnJid) {
|
|
50
|
+
lidPnMappings.push({ lid: m.lidJid, pn: m.pnJid });
|
|
51
|
+
}
|
|
52
|
+
}
|
|
31
53
|
switch (item.syncType) {
|
|
32
|
-
case
|
|
33
|
-
case
|
|
34
|
-
case
|
|
35
|
-
case
|
|
54
|
+
case index_js_1.proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP:
|
|
55
|
+
case index_js_1.proto.HistorySync.HistorySyncType.RECENT:
|
|
56
|
+
case index_js_1.proto.HistorySync.HistorySyncType.FULL:
|
|
57
|
+
case index_js_1.proto.HistorySync.HistorySyncType.ON_DEMAND:
|
|
36
58
|
for (const chat of item.conversations) {
|
|
37
|
-
contacts.push({
|
|
59
|
+
contacts.push({
|
|
60
|
+
id: chat.id,
|
|
61
|
+
name: chat.displayName || chat.name || chat.username || undefined,
|
|
62
|
+
lid: chat.lidJid || chat.accountLid || undefined,
|
|
63
|
+
phoneNumber: chat.pnJid || undefined
|
|
64
|
+
});
|
|
65
|
+
const chatId = chat.id;
|
|
66
|
+
const isLid = (0, index_js_3.isLidUser)(chatId) || (0, index_js_3.isHostedLidUser)(chatId);
|
|
67
|
+
const isPn = (0, index_js_3.isPnUser)(chatId) || (0, index_js_3.isHostedPnUser)(chatId);
|
|
68
|
+
if (isLid && chat.pnJid) {
|
|
69
|
+
lidPnMappings.push({ lid: chatId, pn: chat.pnJid });
|
|
70
|
+
}
|
|
71
|
+
else if (isPn && chat.lidJid) {
|
|
72
|
+
lidPnMappings.push({ lid: chat.lidJid, pn: chatId });
|
|
73
|
+
}
|
|
74
|
+
else if (isLid && !chat.pnJid) {
|
|
75
|
+
// Fallback: extract PN from userReceipt in messages when pnJid is missing
|
|
76
|
+
const pnFromReceipt = extractPnFromMessages(chat.messages || []);
|
|
77
|
+
if (pnFromReceipt) {
|
|
78
|
+
lidPnMappings.push({ lid: chatId, pn: pnFromReceipt });
|
|
79
|
+
}
|
|
80
|
+
}
|
|
38
81
|
const msgs = chat.messages || [];
|
|
39
82
|
delete chat.messages;
|
|
40
|
-
delete chat.archived;
|
|
41
|
-
delete chat.muteEndTime;
|
|
42
|
-
delete chat.pinned;
|
|
43
83
|
for (const item of msgs) {
|
|
44
84
|
const message = item.message;
|
|
45
85
|
messages.push(message);
|
|
46
|
-
if (!
|
|
86
|
+
if (!chat.messages?.length) {
|
|
47
87
|
// keep only the most recent message in the chat array
|
|
48
88
|
chat.messages = [{ message }];
|
|
49
89
|
}
|
|
50
90
|
if (!message.key.fromMe && !chat.lastMessageRecvTimestamp) {
|
|
51
|
-
chat.lastMessageRecvTimestamp = (0,
|
|
91
|
+
chat.lastMessageRecvTimestamp = (0, generics_js_1.toNumber)(message.messageTimestamp);
|
|
52
92
|
}
|
|
53
|
-
if ((message.messageStubType ===
|
|
54
|
-
|
|
55
|
-
|
|
93
|
+
if ((message.messageStubType === index_js_2.WAMessageStubType.BIZ_PRIVACY_MODE_TO_BSP ||
|
|
94
|
+
message.messageStubType === index_js_2.WAMessageStubType.BIZ_PRIVACY_MODE_TO_FB) &&
|
|
95
|
+
message.messageStubParameters?.[0]) {
|
|
56
96
|
contacts.push({
|
|
57
97
|
id: message.key.participant || message.key.remoteJid,
|
|
58
|
-
verifiedName:
|
|
98
|
+
verifiedName: message.messageStubParameters?.[0]
|
|
59
99
|
});
|
|
60
100
|
}
|
|
61
101
|
}
|
|
62
|
-
if ((0, WABinary_1.isJidUser)(chat.id) && chat.readOnly && chat.archived) {
|
|
63
|
-
delete chat.readOnly;
|
|
64
|
-
}
|
|
65
102
|
chats.push({ ...chat });
|
|
66
103
|
}
|
|
67
104
|
break;
|
|
68
|
-
case
|
|
105
|
+
case index_js_1.proto.HistorySync.HistorySyncType.PUSH_NAME:
|
|
69
106
|
for (const c of item.pushnames) {
|
|
70
107
|
contacts.push({ id: c.id, notify: c.pushname });
|
|
71
108
|
}
|
|
@@ -75,20 +112,26 @@ const processHistoryMessage = (item) => {
|
|
|
75
112
|
chats,
|
|
76
113
|
contacts,
|
|
77
114
|
messages,
|
|
115
|
+
lidPnMappings,
|
|
78
116
|
syncType: item.syncType,
|
|
79
117
|
progress: item.progress
|
|
80
118
|
};
|
|
81
119
|
};
|
|
82
120
|
exports.processHistoryMessage = processHistoryMessage;
|
|
83
|
-
const downloadAndProcessHistorySyncNotification = async (msg, options) => {
|
|
84
|
-
|
|
85
|
-
|
|
121
|
+
const downloadAndProcessHistorySyncNotification = async (msg, options, logger) => {
|
|
122
|
+
let historyMsg;
|
|
123
|
+
if (msg.initialHistBootstrapInlinePayload) {
|
|
124
|
+
historyMsg = index_js_1.proto.HistorySync.decode(await inflatePromise(msg.initialHistBootstrapInlinePayload));
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
historyMsg = await (0, exports.downloadHistory)(msg, options);
|
|
128
|
+
}
|
|
129
|
+
return (0, exports.processHistoryMessage)(historyMsg, logger);
|
|
86
130
|
};
|
|
87
131
|
exports.downloadAndProcessHistorySyncNotification = downloadAndProcessHistorySyncNotification;
|
|
88
132
|
const getHistoryMsg = (message) => {
|
|
89
|
-
|
|
90
|
-
const
|
|
91
|
-
const anyHistoryMsg = (_a = normalizedContent === null || normalizedContent === void 0 ? void 0 : normalizedContent.protocolMessage) === null || _a === void 0 ? void 0 : _a.historySyncNotification;
|
|
133
|
+
const normalizedContent = !!message ? (0, messages_js_1.normalizeMessageContent)(message) : undefined;
|
|
134
|
+
const anyHistoryMsg = normalizedContent?.protocolMessage?.historySyncNotification;
|
|
92
135
|
return anyHistoryMsg;
|
|
93
136
|
};
|
|
94
137
|
exports.getHistoryMsg = getHistoryMsg;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import NodeCache from '@cacheable/node-cache';
|
|
2
|
+
import { type BinaryNode } from '../WABinary/index.js';
|
|
3
|
+
import type { ILogger } from './logger.js';
|
|
4
|
+
export type IdentityChangeResult = {
|
|
5
|
+
action: 'no_identity_node';
|
|
6
|
+
} | {
|
|
7
|
+
action: 'invalid_notification';
|
|
8
|
+
} | {
|
|
9
|
+
action: 'skipped_companion_device';
|
|
10
|
+
device: number;
|
|
11
|
+
} | {
|
|
12
|
+
action: 'skipped_self_primary';
|
|
13
|
+
} | {
|
|
14
|
+
action: 'debounced';
|
|
15
|
+
} | {
|
|
16
|
+
action: 'skipped_offline';
|
|
17
|
+
} | {
|
|
18
|
+
action: 'skipped_no_session';
|
|
19
|
+
} | {
|
|
20
|
+
action: 'session_refreshed';
|
|
21
|
+
} | {
|
|
22
|
+
action: 'session_refresh_failed';
|
|
23
|
+
error: unknown;
|
|
24
|
+
};
|
|
25
|
+
export type IdentityChangeContext = {
|
|
26
|
+
meId: string | undefined;
|
|
27
|
+
meLid: string | undefined;
|
|
28
|
+
validateSession: (jid: string) => Promise<{
|
|
29
|
+
exists: boolean;
|
|
30
|
+
reason?: string;
|
|
31
|
+
}>;
|
|
32
|
+
assertSessions: (jids: string[], force?: boolean) => Promise<boolean>;
|
|
33
|
+
debounceCache: NodeCache<boolean>;
|
|
34
|
+
logger: ILogger;
|
|
35
|
+
};
|
|
36
|
+
export declare function handleIdentityChange(node: BinaryNode, ctx: IdentityChangeContext): Promise<IdentityChangeResult>;
|
|
37
|
+
//# sourceMappingURL=identity-change-handler.d.ts.map
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.handleIdentityChange = handleIdentityChange;
|
|
7
|
+
const node_cache_1 = __importDefault(require("@cacheable/node-cache"));
|
|
8
|
+
const index_js_1 = require("../WABinary/index.js");
|
|
9
|
+
const generics_js_1 = require("./generics.js");
|
|
10
|
+
async function handleIdentityChange(node, ctx) {
|
|
11
|
+
const from = node.attrs.from;
|
|
12
|
+
if (!from) {
|
|
13
|
+
return { action: 'invalid_notification' };
|
|
14
|
+
}
|
|
15
|
+
const identityNode = (0, index_js_1.getBinaryNodeChild)(node, 'identity');
|
|
16
|
+
if (!identityNode) {
|
|
17
|
+
return { action: 'no_identity_node' };
|
|
18
|
+
}
|
|
19
|
+
ctx.logger.info({ jid: from }, 'identity changed');
|
|
20
|
+
const decoded = (0, index_js_1.jidDecode)(from);
|
|
21
|
+
if (decoded?.device && decoded.device !== 0) {
|
|
22
|
+
ctx.logger.debug({ jid: from, device: decoded.device }, 'ignoring identity change from companion device');
|
|
23
|
+
return { action: 'skipped_companion_device', device: decoded.device };
|
|
24
|
+
}
|
|
25
|
+
const isSelfPrimary = ctx.meId && ((0, index_js_1.areJidsSameUser)(from, ctx.meId) || (ctx.meLid && (0, index_js_1.areJidsSameUser)(from, ctx.meLid)));
|
|
26
|
+
if (isSelfPrimary) {
|
|
27
|
+
ctx.logger.info({ jid: from }, 'self primary identity changed');
|
|
28
|
+
return { action: 'skipped_self_primary' };
|
|
29
|
+
}
|
|
30
|
+
if (ctx.debounceCache.get(from)) {
|
|
31
|
+
ctx.logger.debug({ jid: from }, 'skipping identity assert (debounced)');
|
|
32
|
+
return { action: 'debounced' };
|
|
33
|
+
}
|
|
34
|
+
ctx.debounceCache.set(from, true);
|
|
35
|
+
const isOfflineNotification = !(0, generics_js_1.isStringNullOrEmpty)(node.attrs.offline);
|
|
36
|
+
const hasExistingSession = await ctx.validateSession(from);
|
|
37
|
+
if (!hasExistingSession.exists) {
|
|
38
|
+
ctx.logger.debug({ jid: from }, 'no old session, skipping session refresh');
|
|
39
|
+
return { action: 'skipped_no_session' };
|
|
40
|
+
}
|
|
41
|
+
ctx.logger.debug({ jid: from }, 'old session exists, will refresh session');
|
|
42
|
+
if (isOfflineNotification) {
|
|
43
|
+
ctx.logger.debug({ jid: from }, 'skipping session refresh during offline processing');
|
|
44
|
+
return { action: 'skipped_offline' };
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
await ctx.assertSessions([from], true);
|
|
48
|
+
return { action: 'session_refreshed' };
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
ctx.logger.warn({ error, jid: from }, 'failed to assert sessions after identity change');
|
|
52
|
+
return { action: 'session_refresh_failed', error };
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export * from './generics.js';
|
|
2
|
+
export * from './decode-wa-message.js';
|
|
3
|
+
export * from './messages.js';
|
|
4
|
+
export * from './messages-media.js';
|
|
5
|
+
export * from './validate-connection.js';
|
|
6
|
+
export * from './crypto.js';
|
|
7
|
+
export * from './signal.js';
|
|
8
|
+
export * from './noise-handler.js';
|
|
9
|
+
export * from './history.js';
|
|
10
|
+
export * from './chat-utils.js';
|
|
11
|
+
export * from './lt-hash.js';
|
|
12
|
+
export * from './auth-utils.js';
|
|
13
|
+
export * from './use-multi-file-auth-state.js';
|
|
14
|
+
export * from './link-preview.js';
|
|
15
|
+
export * from './event-buffer.js';
|
|
16
|
+
export * from './process-message.js';
|
|
17
|
+
export * from './message-retry-manager.js';
|
|
18
|
+
export * from './browser-utils.js';
|
|
19
|
+
export * from './identity-change-handler.js';
|
|
20
|
+
export * from './messages-newsletter.js';
|
|
21
|
+
export * from './resolve-jid.js';
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
package/lib/Utils/index.js
CHANGED
|
@@ -14,22 +14,35 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./generics"), exports);
|
|
18
|
-
__exportStar(require("./
|
|
19
|
-
__exportStar(require("./
|
|
20
|
-
__exportStar(require("./
|
|
21
|
-
__exportStar(require("./
|
|
22
|
-
__exportStar(require("./
|
|
23
|
-
__exportStar(require("./
|
|
24
|
-
__exportStar(require("./
|
|
25
|
-
__exportStar(require("./
|
|
26
|
-
__exportStar(require("./
|
|
27
|
-
__exportStar(require("./
|
|
28
|
-
__exportStar(require("./
|
|
29
|
-
__exportStar(require("./
|
|
30
|
-
__exportStar(require("./
|
|
31
|
-
__exportStar(require("./
|
|
32
|
-
__exportStar(require("./
|
|
33
|
-
__exportStar(require("./
|
|
34
|
-
__exportStar(require("./
|
|
35
|
-
__exportStar(require("./
|
|
17
|
+
__exportStar(require("./generics.js"), exports);
|
|
18
|
+
__exportStar(require("./audioToBuffer.js"), exports);
|
|
19
|
+
__exportStar(require("./streamToBuffer.js"), exports);
|
|
20
|
+
__exportStar(require("./decode-wa-message.js"), exports);
|
|
21
|
+
__exportStar(require("./messages.js"), exports);
|
|
22
|
+
__exportStar(require("./messages-media.js"), exports);
|
|
23
|
+
__exportStar(require("./messages-newsletter.js"), exports);
|
|
24
|
+
__exportStar(require("./validate-connection.js"), exports);
|
|
25
|
+
__exportStar(require("./crypto.js"), exports);
|
|
26
|
+
__exportStar(require("./signal.js"), exports);
|
|
27
|
+
__exportStar(require("./noise-handler.js"), exports);
|
|
28
|
+
__exportStar(require("./history.js"), exports);
|
|
29
|
+
__exportStar(require("./chat-utils.js"), exports);
|
|
30
|
+
__exportStar(require("./business.js"), exports);
|
|
31
|
+
__exportStar(require("./lt-hash.js"), exports);
|
|
32
|
+
__exportStar(require("./auth-utils.js"), exports);
|
|
33
|
+
__exportStar(require("./pre-key-manager.js"), exports);
|
|
34
|
+
__exportStar(require("./use-multi-file-auth-state.js"), exports);
|
|
35
|
+
__exportStar(require("./use-single-file-auth-state.js"), exports);
|
|
36
|
+
__exportStar(require("./use-mongo-file-auth-state.js"), exports);
|
|
37
|
+
__exportStar(require("./wileys-event-stream.js"), exports);
|
|
38
|
+
__exportStar(require("./baileys-event-stream.js"), exports);
|
|
39
|
+
__exportStar(require("./link-preview.js"), exports);
|
|
40
|
+
__exportStar(require("./event-buffer.js"), exports);
|
|
41
|
+
__exportStar(require("./process-message.js"), exports);
|
|
42
|
+
__exportStar(require("./message-retry-manager.js"), exports);
|
|
43
|
+
__exportStar(require("./browser-utils.js"), exports);
|
|
44
|
+
__exportStar(require("./identity-change-handler.js"), exports);
|
|
45
|
+
__exportStar(require("./resolve-jid.js"), exports);
|
|
46
|
+
__exportStar(require("./reporting-utils.js"), exports);
|
|
47
|
+
__exportStar(require("./sync-action-utils.js"), exports);
|
|
48
|
+
__exportStar(require("./tc-token-utils.js"), exports);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { WAMediaUploadFunction, WAUrlInfo } from '../Types/index.js';
|
|
2
|
+
import type { ILogger } from './logger.js';
|
|
3
|
+
export type URLGenerationOptions = {
|
|
4
|
+
thumbnailWidth: number;
|
|
5
|
+
fetchOpts: {
|
|
6
|
+
/** Timeout in ms */
|
|
7
|
+
timeout: number;
|
|
8
|
+
proxyUrl?: string;
|
|
9
|
+
headers?: HeadersInit;
|
|
10
|
+
};
|
|
11
|
+
uploadImage?: WAMediaUploadFunction;
|
|
12
|
+
logger?: ILogger;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Given a piece of text, checks for any URL present, generates link preview for the same and returns it
|
|
16
|
+
* Return undefined if the fetch failed or no URL was found
|
|
17
|
+
* @param text first matched URL in text
|
|
18
|
+
* @returns the URL info required to generate link preview
|
|
19
|
+
*/
|
|
20
|
+
export declare const getUrlInfo: (text: string, opts?: URLGenerationOptions) => Promise<WAUrlInfo | undefined>;
|
|
21
|
+
//# sourceMappingURL=link-preview.d.ts.map
|
|
@@ -34,13 +34,13 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.getUrlInfo = void 0;
|
|
37
|
-
const
|
|
38
|
-
const
|
|
37
|
+
const messages_js_1 = require("./messages.js");
|
|
38
|
+
const messages_media_js_1 = require("./messages-media.js");
|
|
39
39
|
const THUMBNAIL_WIDTH_PX = 192;
|
|
40
40
|
/** Fetches an image and generates a thumbnail for it */
|
|
41
41
|
const getCompressedJpegThumbnail = async (url, { thumbnailWidth, fetchOpts }) => {
|
|
42
|
-
const stream = await (0,
|
|
43
|
-
const result = await (0,
|
|
42
|
+
const stream = await (0, messages_media_js_1.getHttpStream)(url, fetchOpts);
|
|
43
|
+
const result = await (0, messages_media_js_1.extractImageThumb)(stream, thumbnailWidth);
|
|
44
44
|
return result;
|
|
45
45
|
};
|
|
46
46
|
/**
|
|
@@ -53,7 +53,6 @@ const getUrlInfo = async (text, opts = {
|
|
|
53
53
|
thumbnailWidth: THUMBNAIL_WIDTH_PX,
|
|
54
54
|
fetchOpts: { timeout: 3000 }
|
|
55
55
|
}) => {
|
|
56
|
-
var _a;
|
|
57
56
|
try {
|
|
58
57
|
// retries
|
|
59
58
|
const retries = 0;
|
|
@@ -72,9 +71,9 @@ const getUrlInfo = async (text, opts = {
|
|
|
72
71
|
if (retries >= maxRetry) {
|
|
73
72
|
return false;
|
|
74
73
|
}
|
|
75
|
-
if (forwardedURLObj.hostname === urlObj.hostname
|
|
76
|
-
|
|
77
|
-
|
|
74
|
+
if (forwardedURLObj.hostname === urlObj.hostname ||
|
|
75
|
+
forwardedURLObj.hostname === 'www.' + urlObj.hostname ||
|
|
76
|
+
'www.' + forwardedURLObj.hostname === urlObj.hostname) {
|
|
78
77
|
retries + 1;
|
|
79
78
|
return true;
|
|
80
79
|
}
|
|
@@ -82,7 +81,7 @@ const getUrlInfo = async (text, opts = {
|
|
|
82
81
|
return false;
|
|
83
82
|
}
|
|
84
83
|
},
|
|
85
|
-
headers: opts.fetchOpts
|
|
84
|
+
headers: opts.fetchOpts?.headers
|
|
86
85
|
});
|
|
87
86
|
if (info && 'title' in info && info.title) {
|
|
88
87
|
const [image] = info.images;
|
|
@@ -94,24 +93,20 @@ const getUrlInfo = async (text, opts = {
|
|
|
94
93
|
originalThumbnailUrl: image
|
|
95
94
|
};
|
|
96
95
|
if (opts.uploadImage) {
|
|
97
|
-
const { imageMessage } = await (0,
|
|
96
|
+
const { imageMessage } = await (0, messages_js_1.prepareWAMessageMedia)({ image: { url: image } }, {
|
|
98
97
|
upload: opts.uploadImage,
|
|
99
98
|
mediaTypeOverride: 'thumbnail-link',
|
|
100
99
|
options: opts.fetchOpts
|
|
101
100
|
});
|
|
102
|
-
urlInfo.jpegThumbnail =
|
|
103
|
-
? Buffer.from(imageMessage.jpegThumbnail)
|
|
104
|
-
: undefined;
|
|
101
|
+
urlInfo.jpegThumbnail = imageMessage?.jpegThumbnail ? Buffer.from(imageMessage.jpegThumbnail) : undefined;
|
|
105
102
|
urlInfo.highQualityThumbnail = imageMessage || undefined;
|
|
106
103
|
}
|
|
107
104
|
else {
|
|
108
105
|
try {
|
|
109
|
-
urlInfo.jpegThumbnail = image
|
|
110
|
-
? (await getCompressedJpegThumbnail(image, opts)).buffer
|
|
111
|
-
: undefined;
|
|
106
|
+
urlInfo.jpegThumbnail = image ? (await getCompressedJpegThumbnail(image, opts)).buffer : undefined;
|
|
112
107
|
}
|
|
113
108
|
catch (error) {
|
|
114
|
-
|
|
109
|
+
opts.logger?.debug({ err: error.stack, url: previewLink }, 'error in generating thumbnail');
|
|
115
110
|
}
|
|
116
111
|
}
|
|
117
112
|
return urlInfo;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import P from 'pino';
|
|
2
|
+
export interface ILogger {
|
|
3
|
+
level: string;
|
|
4
|
+
child(obj: Record<string, unknown>): ILogger;
|
|
5
|
+
trace(obj: unknown, msg?: string): void;
|
|
6
|
+
debug(obj: unknown, msg?: string): void;
|
|
7
|
+
info(obj: unknown, msg?: string): void;
|
|
8
|
+
warn(obj: unknown, msg?: string): void;
|
|
9
|
+
error(obj: unknown, msg?: string): void;
|
|
10
|
+
}
|
|
11
|
+
declare const _default: P.Logger<never, boolean>;
|
|
12
|
+
export default _default;
|
|
13
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { LTHashAntiTampering } from './bridge-runtime.js';
|
|
2
|
+
/**
|
|
3
|
+
* LT Hash is a summation based hash algorithm that maintains the integrity of a piece of data
|
|
4
|
+
* over a series of mutations. You can add/remove mutations and it'll return a hash equal to
|
|
5
|
+
* if the same series of mutations was made sequentially.
|
|
6
|
+
*/
|
|
7
|
+
export declare const LT_HASH_ANTI_TAMPERING: LTHashAntiTampering;
|
|
8
|
+
//# sourceMappingURL=lt-hash.d.ts.map
|
package/lib/Utils/lt-hash.js
CHANGED
|
@@ -1,51 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LT_HASH_ANTI_TAMPERING = void 0;
|
|
4
|
-
const
|
|
4
|
+
const bridge_runtime_js_1 = require("./bridge-runtime.js");
|
|
5
5
|
/**
|
|
6
6
|
* LT Hash is a summation based hash algorithm that maintains the integrity of a piece of data
|
|
7
7
|
* over a series of mutations. You can add/remove mutations and it'll return a hash equal to
|
|
8
8
|
* if the same series of mutations was made sequentially.
|
|
9
9
|
*/
|
|
10
|
-
|
|
11
|
-
class d {
|
|
12
|
-
constructor(e) {
|
|
13
|
-
this.salt = e;
|
|
14
|
-
}
|
|
15
|
-
add(e, t) {
|
|
16
|
-
var r = this;
|
|
17
|
-
for (const item of t) {
|
|
18
|
-
e = r._addSingle(e, item);
|
|
19
|
-
}
|
|
20
|
-
return e;
|
|
21
|
-
}
|
|
22
|
-
subtract(e, t) {
|
|
23
|
-
var r = this;
|
|
24
|
-
for (const item of t) {
|
|
25
|
-
e = r._subtractSingle(e, item);
|
|
26
|
-
}
|
|
27
|
-
return e;
|
|
28
|
-
}
|
|
29
|
-
subtractThenAdd(e, t, r) {
|
|
30
|
-
var n = this;
|
|
31
|
-
return n.add(n.subtract(e, r), t);
|
|
32
|
-
}
|
|
33
|
-
async _addSingle(e, t) {
|
|
34
|
-
var r = this;
|
|
35
|
-
const n = new Uint8Array(await (0, crypto_1.hkdf)(Buffer.from(t), o, { info: r.salt })).buffer;
|
|
36
|
-
return r.performPointwiseWithOverflow(await e, n, ((e, t) => e + t));
|
|
37
|
-
}
|
|
38
|
-
async _subtractSingle(e, t) {
|
|
39
|
-
var r = this;
|
|
40
|
-
const n = new Uint8Array(await (0, crypto_1.hkdf)(Buffer.from(t), o, { info: r.salt })).buffer;
|
|
41
|
-
return r.performPointwiseWithOverflow(await e, n, ((e, t) => e - t));
|
|
42
|
-
}
|
|
43
|
-
performPointwiseWithOverflow(e, t, r) {
|
|
44
|
-
const n = new DataView(e), i = new DataView(t), a = new ArrayBuffer(n.byteLength), s = new DataView(a);
|
|
45
|
-
for (let e = 0; e < n.byteLength; e += 2) {
|
|
46
|
-
s.setUint16(e, r(n.getUint16(e, !0), i.getUint16(e, !0)), !0);
|
|
47
|
-
}
|
|
48
|
-
return a;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
exports.LT_HASH_ANTI_TAMPERING = new d('WhatsApp Patch Integrity');
|
|
10
|
+
exports.LT_HASH_ANTI_TAMPERING = new bridge_runtime_js_1.LTHashAntiTampering();
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const makeMutex: () => {
|
|
2
|
+
mutex<T>(code: () => Promise<T> | T): Promise<T>;
|
|
3
|
+
};
|
|
4
|
+
export type Mutex = ReturnType<typeof makeMutex>;
|
|
5
|
+
export declare const makeKeyedMutex: () => {
|
|
6
|
+
mutex<T>(key: string, task: () => Promise<T> | T): Promise<T>;
|
|
7
|
+
};
|
|
8
|
+
export type KeyedMutex = ReturnType<typeof makeKeyedMutex>;
|
|
9
|
+
//# sourceMappingURL=make-mutex.d.ts.map
|
package/lib/Utils/make-mutex.js
CHANGED
|
@@ -1,42 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.makeKeyedMutex = exports.makeMutex = void 0;
|
|
4
|
+
const async_mutex_1 = require("async-mutex");
|
|
4
5
|
const makeMutex = () => {
|
|
5
|
-
|
|
6
|
-
let taskTimeout;
|
|
6
|
+
const mutex = new async_mutex_1.Mutex();
|
|
7
7
|
return {
|
|
8
8
|
mutex(code) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
// if there is an error, we swallow so as to not block the queue
|
|
12
|
-
try {
|
|
13
|
-
await task;
|
|
14
|
-
}
|
|
15
|
-
catch (_a) { }
|
|
16
|
-
try {
|
|
17
|
-
// execute the current task
|
|
18
|
-
const result = await code();
|
|
19
|
-
return result;
|
|
20
|
-
}
|
|
21
|
-
finally {
|
|
22
|
-
clearTimeout(taskTimeout);
|
|
23
|
-
}
|
|
24
|
-
})();
|
|
25
|
-
// we replace the existing task, appending the new piece of execution to it
|
|
26
|
-
// so the next task will have to wait for this one to finish
|
|
27
|
-
return task;
|
|
28
|
-
},
|
|
9
|
+
return mutex.runExclusive(code);
|
|
10
|
+
}
|
|
29
11
|
};
|
|
30
12
|
};
|
|
31
13
|
exports.makeMutex = makeMutex;
|
|
32
14
|
const makeKeyedMutex = () => {
|
|
33
|
-
const map =
|
|
15
|
+
const map = new Map();
|
|
34
16
|
return {
|
|
35
|
-
mutex(key, task) {
|
|
36
|
-
|
|
37
|
-
|
|
17
|
+
async mutex(key, task) {
|
|
18
|
+
let entry = map.get(key);
|
|
19
|
+
if (!entry) {
|
|
20
|
+
entry = { mutex: new async_mutex_1.Mutex(), refCount: 0 };
|
|
21
|
+
map.set(key, entry);
|
|
22
|
+
}
|
|
23
|
+
entry.refCount++;
|
|
24
|
+
try {
|
|
25
|
+
return await entry.mutex.runExclusive(task);
|
|
26
|
+
}
|
|
27
|
+
finally {
|
|
28
|
+
entry.refCount--;
|
|
29
|
+
// only delete it if this is still the current entry
|
|
30
|
+
if (entry.refCount === 0 && map.get(key) === entry) {
|
|
31
|
+
map.delete(key);
|
|
32
|
+
}
|
|
38
33
|
}
|
|
39
|
-
return map[key].mutex(task);
|
|
40
34
|
}
|
|
41
35
|
};
|
|
42
36
|
};
|