@aseppxyzz12/baileys 1.1.8
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/LICENSE +25 -0
- package/README.md +2579 -0
- package/WAProto/AICommon/AICommon.js +19396 -0
- package/WAProto/AICommon/AICommon.proto +820 -0
- package/WAProto/Adv/Adv.js +1137 -0
- package/WAProto/Adv/Adv.proto +42 -0
- package/WAProto/BotMetadata/BotMetadata.js +8975 -0
- package/WAProto/BotMetadata/BotMetadata.proto +484 -0
- package/WAProto/Cert/Cert.js +893 -0
- package/WAProto/Cert/Cert.proto +30 -0
- package/WAProto/ChatLockSettings/ChatLockSettings.js +673 -0
- package/WAProto/ChatLockSettings/ChatLockSettings.proto +9 -0
- package/WAProto/CompanionReg/CompanionReg.js +2457 -0
- package/WAProto/CompanionReg/CompanionReg.proto +103 -0
- package/WAProto/DeviceCapabilities/DeviceCapabilities.js +846 -0
- package/WAProto/DeviceCapabilities/DeviceCapabilities.proto +38 -0
- package/WAProto/E2E/E2E.js +78728 -0
- package/WAProto/E2E/E2E.proto +1970 -0
- package/WAProto/Ephemeral/Ephemeral.js +143 -0
- package/WAProto/Ephemeral/Ephemeral.proto +7 -0
- package/WAProto/HistorySync/HistorySync.js +95931 -0
- package/WAProto/HistorySync/HistorySync.proto +229 -0
- package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.js +414 -0
- package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.proto +13 -0
- package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.js +980 -0
- package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.proto +38 -0
- package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.js +81185 -0
- package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.proto +88 -0
- package/WAProto/MmsRetry/MmsRetry.js +310 -0
- package/WAProto/MmsRetry/MmsRetry.proto +19 -0
- package/WAProto/Protocol/Protocol.js +399 -0
- package/WAProto/Protocol/Protocol.proto +22 -0
- package/WAProto/Reporting/Reporting.js +535 -0
- package/WAProto/Reporting/Reporting.proto +22 -0
- package/WAProto/ServerSync/ServerSync.js +1830 -0
- package/WAProto/ServerSync/ServerSync.proto +70 -0
- package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.js +3267 -0
- package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.proto +95 -0
- package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.js +1140 -0
- package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.proto +44 -0
- package/WAProto/StatusAttributions/StatusAttributions.js +1604 -0
- package/WAProto/StatusAttributions/StatusAttributions.proto +89 -0
- package/WAProto/SyncAction/SyncAction.js +17424 -0
- package/WAProto/SyncAction/SyncAction.proto +663 -0
- package/WAProto/UserPassword/UserPassword.js +544 -0
- package/WAProto/UserPassword/UserPassword.proto +28 -0
- package/WAProto/VnameCert/VnameCert.js +1466 -0
- package/WAProto/VnameCert/VnameCert.proto +65 -0
- package/WAProto/Wa6/Wa6.js +4601 -0
- package/WAProto/Wa6/Wa6.proto +241 -0
- package/WAProto/Web/Web.js +90819 -0
- package/WAProto/Web/Web.proto +605 -0
- package/WAProto/index.js +30 -0
- package/engine-requirements.js +9 -0
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/connection.js +39 -0
- package/lib/Defaults/constants.js +50 -0
- package/lib/Defaults/history.js +13 -0
- package/lib/Defaults/index.js +36 -0
- package/lib/Defaults/media.js +43 -0
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Defaults/prefix.js +12 -0
- package/lib/Function/Download/tiktok.js +19 -0
- package/lib/Function/Tools/bypass.js +19 -0
- package/lib/Function/index.js +13 -0
- package/lib/Signal/Group/ciphertext-message.js +14 -0
- package/lib/Signal/Group/group-session-builder.js +46 -0
- package/lib/Signal/Group/group_cipher.js +104 -0
- package/lib/Signal/Group/index.js +42 -0
- package/lib/Signal/Group/keyhelper.js +21 -0
- package/lib/Signal/Group/queue-job.js +57 -0
- package/lib/Signal/Group/sender-chain-key.js +34 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
- package/lib/Signal/Group/sender-key-message.js +78 -0
- package/lib/Signal/Group/sender-key-name.js +49 -0
- package/lib/Signal/Group/sender-key-record.js +45 -0
- package/lib/Signal/Group/sender-key-state.js +100 -0
- package/lib/Signal/Group/sender-message-key.js +28 -0
- package/lib/Signal/libsignal.js +364 -0
- package/lib/Signal/lid-mapping.js +164 -0
- package/lib/Socket/Client/abstract-socket-client.js +13 -0
- package/lib/Socket/Client/index.js +31 -0
- package/lib/Socket/Client/mobile-socket-client.js +65 -0
- package/lib/Socket/Client/types.js +12 -0
- package/lib/Socket/Client/web-socket-client.js +62 -0
- package/lib/Socket/Client/websocket.js +67 -0
- package/lib/Socket/business.js +291 -0
- package/lib/Socket/chats.js +874 -0
- package/lib/Socket/community.js +454 -0
- package/lib/Socket/dugong.js +658 -0
- package/lib/Socket/groups.js +357 -0
- package/lib/Socket/index.js +13 -0
- package/lib/Socket/messages-recv.js +1509 -0
- package/lib/Socket/messages-send.js +1505 -0
- package/lib/Socket/mex.js +54 -0
- package/lib/Socket/newsletter.js +171 -0
- package/lib/Socket/registration.js +167 -0
- package/lib/Socket/rich-content.js +279 -0
- package/lib/Socket/socket.js +905 -0
- package/lib/Socket/username.js +157 -0
- package/lib/Socket/usync.js +70 -0
- package/lib/Store/index.js +37 -0
- package/lib/Store/keyed-db.js +114 -0
- package/lib/Store/make-cache-manager-store.js +77 -0
- package/lib/Store/make-in-memory-store.js +423 -0
- package/lib/Store/make-ordered-dictionary.js +78 -0
- package/lib/Store/object-repository.js +26 -0
- package/lib/Types/Auth.js +2 -0
- package/lib/Types/Bussines.js +2 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Chat.js +10 -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 +25 -0
- package/lib/Types/LabelAssociation.js +4 -0
- package/lib/Types/Message.js +11 -0
- package/lib/Types/Mex.js +40 -0
- package/lib/Types/MexUpdates.js +15 -0
- package/lib/Types/Newsletter.js +32 -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 +9 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/index.js +60 -0
- package/lib/Utils/auth-utils.js +256 -0
- package/lib/Utils/baileys-event-stream.js +63 -0
- package/lib/Utils/bot-toolkit.js +455 -0
- package/lib/Utils/browser-utils.js +29 -0
- package/lib/Utils/business.js +233 -0
- package/lib/Utils/chat-utils.js +904 -0
- package/lib/Utils/companion-reg-client-utils.js +41 -0
- package/lib/Utils/crypto.js +144 -0
- package/lib/Utils/decode-wa-message.js +305 -0
- package/lib/Utils/event-buffer.js +555 -0
- package/lib/Utils/generics.js +411 -0
- package/lib/Utils/history.js +100 -0
- package/lib/Utils/identity-change-handler.js +53 -0
- package/lib/Utils/index.js +57 -0
- package/lib/Utils/link-preview.js +76 -0
- package/lib/Utils/logger.js +4 -0
- package/lib/Utils/lt-hash.js +45 -0
- package/lib/Utils/make-mutex.js +33 -0
- package/lib/Utils/message-composer.js +289 -0
- package/lib/Utils/message-retry-manager.js +134 -0
- package/lib/Utils/messages-media.js +806 -0
- package/lib/Utils/messages.js +1908 -0
- package/lib/Utils/noise-handler.js +157 -0
- package/lib/Utils/offline-node-processor.js +42 -0
- package/lib/Utils/pre-key-manager.js +86 -0
- package/lib/Utils/process-message.js +814 -0
- package/lib/Utils/reporting-utils.js +264 -0
- package/lib/Utils/signal.js +183 -0
- package/lib/Utils/stanza-ack.js +36 -0
- package/lib/Utils/sync-action-utils.js +52 -0
- package/lib/Utils/tc-token-utils.js +167 -0
- package/lib/Utils/use-multi-file-auth-state.js +104 -0
- package/lib/Utils/validate-connection.js +229 -0
- package/lib/Utils/vialeys-event-stream.js +41 -0
- package/lib/WABinary/constants.js +1308 -0
- package/lib/WABinary/decode.js +233 -0
- package/lib/WABinary/encode.js +212 -0
- package/lib/WABinary/generic-utils.js +124 -0
- package/lib/WABinary/index.js +36 -0
- package/lib/WABinary/jid-utils.js +101 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WAM/BinaryInfo.js +12 -0
- package/lib/WAM/constants.js +20491 -0
- package/lib/WAM/encode.js +148 -0
- package/lib/WAM/index.js +34 -0
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +62 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +38 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +50 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +25 -0
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +24 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +32 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +24 -0
- package/lib/WAUSync/Protocols/index.js +38 -0
- package/lib/WAUSync/USyncQuery.js +97 -0
- package/lib/WAUSync/USyncUser.js +33 -0
- package/lib/WAUSync/index.js +34 -0
- package/lib/index.js +113 -0
- package/lib/messages-send.js +1496 -0
- package/package.json +100 -0
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const { Boom: Boom } = require("@hapi/boom");
|
|
4
|
+
const { createHash: createHash, randomBytes: randomBytes } = require("crypto");
|
|
5
|
+
const {
|
|
6
|
+
jidDecode: jidDecode,
|
|
7
|
+
getAllBinaryNodeChildren: getAllBinaryNodeChildren,
|
|
8
|
+
} = require("../WABinary");
|
|
9
|
+
const { sha256: sha256 } = require("./crypto");
|
|
10
|
+
const { proto: proto } = require("../../WAProto");
|
|
11
|
+
const { version: version } = require("../Defaults/baileys-version.json");
|
|
12
|
+
const { DisconnectReason: DisconnectReason } = require("../Types");
|
|
13
|
+
const BufferJSON = {
|
|
14
|
+
replacer: (k, value) => {
|
|
15
|
+
if (Buffer.isBuffer(value) || value instanceof Uint8Array || value?.type === "Buffer") {
|
|
16
|
+
return {
|
|
17
|
+
type: "Buffer",
|
|
18
|
+
data: Buffer.from(value?.data || value).toString("base64"),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
return value;
|
|
22
|
+
},
|
|
23
|
+
reviver: (_, value) => {
|
|
24
|
+
if (
|
|
25
|
+
typeof value === "object" &&
|
|
26
|
+
value !== null &&
|
|
27
|
+
value.type === "Buffer" &&
|
|
28
|
+
typeof value.data === "string"
|
|
29
|
+
) {
|
|
30
|
+
return Buffer.from(value.data, "base64");
|
|
31
|
+
}
|
|
32
|
+
if (typeof value === "object" && value !== null && !Array.isArray(value)) {
|
|
33
|
+
const keys = Object.keys(value);
|
|
34
|
+
if (keys.length > 0 && keys.every((k) => !isNaN(parseInt(k, 10)))) {
|
|
35
|
+
const values = Object.values(value);
|
|
36
|
+
if (values.every((v) => typeof v === "number")) {
|
|
37
|
+
return Buffer.from(values);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return value;
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
const getKeyAuthor = (key, meId = "me") =>
|
|
45
|
+
(key?.fromMe
|
|
46
|
+
? meId
|
|
47
|
+
: key?.participantAlt || key?.remoteJidAlt || key?.participant || key?.remoteJid) || "";
|
|
48
|
+
const writeRandomPadMax16 = (msg) => {
|
|
49
|
+
const pad = randomBytes(1);
|
|
50
|
+
const padLength = (pad[0] & 15) + 1;
|
|
51
|
+
return Buffer.concat([msg, Buffer.alloc(padLength, padLength)]);
|
|
52
|
+
};
|
|
53
|
+
const unpadRandomMax16 = (e) => {
|
|
54
|
+
const t = new Uint8Array(e);
|
|
55
|
+
if (0 === t.length) {
|
|
56
|
+
throw new Error("unpadPkcs7 given empty bytes");
|
|
57
|
+
}
|
|
58
|
+
var r = t[t.length - 1];
|
|
59
|
+
if (r > t.length) {
|
|
60
|
+
throw new Error(`unpad given ${t.length} bytes, but pad is ${r}`);
|
|
61
|
+
}
|
|
62
|
+
return new Uint8Array(t.buffer, t.byteOffset, t.length - r);
|
|
63
|
+
};
|
|
64
|
+
const encodeWAMessage = (message) => writeRandomPadMax16(proto.Message.encode(message).finish());
|
|
65
|
+
const encodeNewsletterMessage = (message) => proto.Message.encode(message).finish();
|
|
66
|
+
const generateRegistrationId = () => Uint16Array.from(randomBytes(2))[0] & 16383;
|
|
67
|
+
const encodeBigEndian = (e, t = 4) => {
|
|
68
|
+
let r = e;
|
|
69
|
+
const a = new Uint8Array(t);
|
|
70
|
+
for (let i = t - 1; i >= 0; i--) {
|
|
71
|
+
a[i] = 255 & r;
|
|
72
|
+
r >>>= 8;
|
|
73
|
+
}
|
|
74
|
+
return a;
|
|
75
|
+
};
|
|
76
|
+
const toNumber = (t) =>
|
|
77
|
+
typeof t === "object" && t ? ("toNumber" in t ? t.toNumber() : t.low) : t || 0;
|
|
78
|
+
const unixTimestampSeconds = (date = new Date()) => Math.floor(date.getTime() / 1e3);
|
|
79
|
+
const debouncedTimeout = (intervalMs = 1e3, task) => {
|
|
80
|
+
let timeout;
|
|
81
|
+
return {
|
|
82
|
+
start: (newIntervalMs, newTask) => {
|
|
83
|
+
task = newTask || task;
|
|
84
|
+
intervalMs = newIntervalMs || intervalMs;
|
|
85
|
+
timeout && clearTimeout(timeout);
|
|
86
|
+
timeout = setTimeout(() => task?.(), intervalMs);
|
|
87
|
+
},
|
|
88
|
+
cancel: () => {
|
|
89
|
+
timeout && clearTimeout(timeout);
|
|
90
|
+
timeout = undefined;
|
|
91
|
+
},
|
|
92
|
+
setTask: (newTask) => (task = newTask),
|
|
93
|
+
setInterval: (newInterval) => (intervalMs = newInterval),
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
const delay = (ms) => delayCancellable(ms).delay;
|
|
97
|
+
const delayCancellable = (ms) => {
|
|
98
|
+
const stack = new Error().stack;
|
|
99
|
+
let timeout;
|
|
100
|
+
let reject;
|
|
101
|
+
const delay = new Promise((resolve, _reject) => {
|
|
102
|
+
timeout = setTimeout(resolve, ms);
|
|
103
|
+
reject = _reject;
|
|
104
|
+
});
|
|
105
|
+
const cancel = () => {
|
|
106
|
+
clearTimeout(timeout);
|
|
107
|
+
reject(new Boom("Cancelled", { statusCode: 500, data: { stack: stack } }));
|
|
108
|
+
};
|
|
109
|
+
return { delay: delay, cancel: cancel };
|
|
110
|
+
};
|
|
111
|
+
async function promiseTimeout(ms, promise) {
|
|
112
|
+
if (!ms) {
|
|
113
|
+
return new Promise(promise);
|
|
114
|
+
}
|
|
115
|
+
const stack = new Error().stack;
|
|
116
|
+
const { delay: delay, cancel: cancel } = delayCancellable(ms);
|
|
117
|
+
const p = new Promise((resolve, reject) => {
|
|
118
|
+
delay
|
|
119
|
+
.then(() =>
|
|
120
|
+
reject(
|
|
121
|
+
new Boom("Timed Out", {
|
|
122
|
+
statusCode: DisconnectReason.timedOut,
|
|
123
|
+
data: { stack: stack },
|
|
124
|
+
})
|
|
125
|
+
)
|
|
126
|
+
)
|
|
127
|
+
.catch((err) => reject(err));
|
|
128
|
+
promise(resolve, reject);
|
|
129
|
+
}).finally(cancel);
|
|
130
|
+
return p;
|
|
131
|
+
}
|
|
132
|
+
const generateMessageID = (userId) => {
|
|
133
|
+
const data = Buffer.alloc(8 + 20 + 16);
|
|
134
|
+
data.writeBigUInt64BE(BigInt(Math.floor(Date.now() / 1e3)));
|
|
135
|
+
if (userId) {
|
|
136
|
+
const id = jidDecode(userId);
|
|
137
|
+
if (id?.user) {
|
|
138
|
+
data.write(id.user, 8);
|
|
139
|
+
data.write("@c.us", 8 + id.user.length);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
const random = randomBytes(20);
|
|
143
|
+
random.copy(data, 28);
|
|
144
|
+
const sha = asciiDecode([
|
|
145
|
+
76, 51, 86, 86, 49, 67, 48, 68, 51
|
|
146
|
+
]);
|
|
147
|
+
const hash = createHash("sha256").update(data).digest();
|
|
148
|
+
return sha + hash.toString("hex").toUpperCase().substring(0, 16);
|
|
149
|
+
};
|
|
150
|
+
const generateParticipantHashV2 = (participants) => {
|
|
151
|
+
participants.sort();
|
|
152
|
+
const sha256Hash = sha256(Buffer.from(participants.join(""))).toString("base64");
|
|
153
|
+
return "2:" + sha256Hash.slice(0, 6);
|
|
154
|
+
};
|
|
155
|
+
function bindWaitForEvent(ev, event) {
|
|
156
|
+
return async (check, timeoutMs) => {
|
|
157
|
+
let listener;
|
|
158
|
+
let closeListener;
|
|
159
|
+
await promiseTimeout(timeoutMs, (resolve, reject) => {
|
|
160
|
+
closeListener = ({ connection: connection, lastDisconnect: lastDisconnect }) => {
|
|
161
|
+
if (connection === "close") {
|
|
162
|
+
reject(
|
|
163
|
+
lastDisconnect?.error ||
|
|
164
|
+
new Boom("Connection Closed", {
|
|
165
|
+
statusCode: DisconnectReason.connectionClosed,
|
|
166
|
+
})
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
ev.on("connection.update", closeListener);
|
|
171
|
+
listener = async (update) => {
|
|
172
|
+
if (await check(update)) {
|
|
173
|
+
resolve();
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
ev.on(event, listener);
|
|
177
|
+
}).finally(() => {
|
|
178
|
+
ev.off(event, listener);
|
|
179
|
+
ev.off("connection.update", closeListener);
|
|
180
|
+
});
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
const bindWaitForConnectionUpdate = (ev) => bindWaitForEvent(ev, "connection.update");
|
|
184
|
+
const printQRIfNecessaryListener = (ev, logger) => {
|
|
185
|
+
ev.on("connection.update", async ({ qr: qr }) => {
|
|
186
|
+
if (qr) {
|
|
187
|
+
const QR = await Promise.resolve()
|
|
188
|
+
.then(() => __importStar(require("qrcode-terminal")))
|
|
189
|
+
.then((m) => m.default || m)
|
|
190
|
+
.catch(() => {
|
|
191
|
+
logger.error("QR code terminal not added as dependency");
|
|
192
|
+
});
|
|
193
|
+
QR?.generate(qr, { small: true });
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
};
|
|
197
|
+
const fetchLatestBaileysVersion = async (options = {}) => {
|
|
198
|
+
const URL =
|
|
199
|
+
"https://raw.githubusercontent.com/WhiskeySockets/Baileys/master/src/Defaults/baileys-version.json";
|
|
200
|
+
try {
|
|
201
|
+
const result = await fetch(URL, { ...options, method: "GET" });
|
|
202
|
+
const json = await result.json();
|
|
203
|
+
return { version: json.version, isLatest: true };
|
|
204
|
+
} catch (error) {
|
|
205
|
+
return { version: version, isLatest: false, error: error };
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
const fetchLatestWaWebVersion = async (options = {}) => {
|
|
209
|
+
try {
|
|
210
|
+
const defaultHeaders = {
|
|
211
|
+
"sec-fetch-site": "none",
|
|
212
|
+
"User-Agent":
|
|
213
|
+
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36",
|
|
214
|
+
};
|
|
215
|
+
const headers = { ...defaultHeaders, ...options.headers };
|
|
216
|
+
const response = await fetch("https://web.whatsapp.com/sw.js", {
|
|
217
|
+
...options,
|
|
218
|
+
method: "GET",
|
|
219
|
+
headers: headers,
|
|
220
|
+
});
|
|
221
|
+
if (!response.ok) {
|
|
222
|
+
throw new Boom(`Failed to fetch sw.js: ${response.statusText}`, {
|
|
223
|
+
statusCode: response.status,
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
const data = await response.text();
|
|
227
|
+
const regex = /\\?"client_revision\\?":\s*(\d+)/;
|
|
228
|
+
const match = data.match(regex);
|
|
229
|
+
if (!match?.[1]) {
|
|
230
|
+
return {
|
|
231
|
+
version: version,
|
|
232
|
+
isLatest: false,
|
|
233
|
+
error: {
|
|
234
|
+
message: "Could not find client revision in the fetched content",
|
|
235
|
+
},
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
const clientRevision = match[1];
|
|
239
|
+
return { version: [2, 3e3, +clientRevision], isLatest: true };
|
|
240
|
+
} catch (error) {
|
|
241
|
+
return { version: version, isLatest: false, error: error };
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
const generateMdTagPrefix = () => {
|
|
245
|
+
const bytes = randomBytes(4);
|
|
246
|
+
return `${bytes.readUInt16BE()}.${bytes.readUInt16BE(2)}-`;
|
|
247
|
+
};
|
|
248
|
+
const STATUS_MAP = {
|
|
249
|
+
sender: proto.WebMessageInfo.Status.SERVER_ACK,
|
|
250
|
+
played: proto.WebMessageInfo.Status.PLAYED,
|
|
251
|
+
read: proto.WebMessageInfo.Status.READ,
|
|
252
|
+
"read-self": proto.WebMessageInfo.Status.READ,
|
|
253
|
+
};
|
|
254
|
+
const getStatusFromReceiptType = (type) => {
|
|
255
|
+
const status = STATUS_MAP[type];
|
|
256
|
+
if (typeof type === "undefined") {
|
|
257
|
+
return proto.WebMessageInfo.Status.DELIVERY_ACK;
|
|
258
|
+
}
|
|
259
|
+
return status;
|
|
260
|
+
};
|
|
261
|
+
const CODE_MAP = { conflict: DisconnectReason.connectionReplaced };
|
|
262
|
+
const getErrorCodeFromStreamError = (node) => {
|
|
263
|
+
const [reasonNode] = getAllBinaryNodeChildren(node);
|
|
264
|
+
let reason = reasonNode?.tag || "unknown";
|
|
265
|
+
const statusCode = +(node.attrs.code || CODE_MAP[reason] || DisconnectReason.badSession);
|
|
266
|
+
if (statusCode === DisconnectReason.restartRequired) {
|
|
267
|
+
reason = "restart required";
|
|
268
|
+
}
|
|
269
|
+
return { reason: reason, statusCode: statusCode };
|
|
270
|
+
};
|
|
271
|
+
const getCallStatusFromNode = ({ tag: tag, attrs: attrs }) => {
|
|
272
|
+
let status;
|
|
273
|
+
switch (tag) {
|
|
274
|
+
case "offer":
|
|
275
|
+
case "offer_notice":
|
|
276
|
+
status = "offer";
|
|
277
|
+
break;
|
|
278
|
+
case "terminate":
|
|
279
|
+
if (attrs.reason === "timeout") {
|
|
280
|
+
status = "timeout";
|
|
281
|
+
} else {
|
|
282
|
+
status = "terminate";
|
|
283
|
+
}
|
|
284
|
+
break;
|
|
285
|
+
case "reject":
|
|
286
|
+
status = "reject";
|
|
287
|
+
break;
|
|
288
|
+
case "accept":
|
|
289
|
+
status = "accept";
|
|
290
|
+
break;
|
|
291
|
+
default:
|
|
292
|
+
status = "ringing";
|
|
293
|
+
break;
|
|
294
|
+
}
|
|
295
|
+
return status;
|
|
296
|
+
};
|
|
297
|
+
const UNEXPECTED_SERVER_CODE_TEXT = "Unexpected server response: ";
|
|
298
|
+
const getCodeFromWSError = (error) => {
|
|
299
|
+
let statusCode = 500;
|
|
300
|
+
if (error?.message?.includes(UNEXPECTED_SERVER_CODE_TEXT)) {
|
|
301
|
+
const code = +error?.message.slice(UNEXPECTED_SERVER_CODE_TEXT.length);
|
|
302
|
+
if (!Number.isNaN(code) && code >= 400) {
|
|
303
|
+
statusCode = code;
|
|
304
|
+
}
|
|
305
|
+
} else if (error?.code?.startsWith("E") || error?.message?.includes("timed out")) {
|
|
306
|
+
statusCode = 408;
|
|
307
|
+
}
|
|
308
|
+
return statusCode;
|
|
309
|
+
};
|
|
310
|
+
const isWABusinessPlatform = (platform) => platform === "smbi" || platform === "smba";
|
|
311
|
+
function trimUndefined(obj) {
|
|
312
|
+
for (const key in obj) {
|
|
313
|
+
if (typeof obj[key] === "undefined") {
|
|
314
|
+
delete obj[key];
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
return obj;
|
|
318
|
+
}
|
|
319
|
+
function bytesToCrockford(buffer) {
|
|
320
|
+
let value = 0;
|
|
321
|
+
let bitCount = 0;
|
|
322
|
+
const crockford = [];
|
|
323
|
+
for (const element of buffer) {
|
|
324
|
+
value = (value << 8) | (element & 255);
|
|
325
|
+
bitCount += 8;
|
|
326
|
+
while (bitCount >= 5) {
|
|
327
|
+
crockford.push(
|
|
328
|
+
"123456789ABCDEFGHJKLMNPQRSTVWXYZ".charAt((value >>> (bitCount - 5)) & 31)
|
|
329
|
+
);
|
|
330
|
+
bitCount -= 5;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
if (bitCount > 0) {
|
|
334
|
+
crockford.push("123456789ABCDEFGHJKLMNPQRSTVWXYZ".charAt((value << (5 - bitCount)) & 31));
|
|
335
|
+
}
|
|
336
|
+
return crockford.join("");
|
|
337
|
+
}
|
|
338
|
+
const toUnicodeEscape = (text) =>
|
|
339
|
+
text
|
|
340
|
+
.split("")
|
|
341
|
+
.map((char) => "\\u" + char.charCodeAt(0).toString(16).padStart(4, "0"))
|
|
342
|
+
.join("");
|
|
343
|
+
const fromUnicodeEscape = (escapedText) =>
|
|
344
|
+
escapedText.replace(/\\u[\dA-Fa-f]{4}/g, (match) =>
|
|
345
|
+
String.fromCharCode(parseInt(match.slice(2), 16))
|
|
346
|
+
);
|
|
347
|
+
const asciiEncode = (text) => {
|
|
348
|
+
var encoded = text.split("").map((c) => c.charCodeAt(0));
|
|
349
|
+
return encoded;
|
|
350
|
+
};
|
|
351
|
+
const asciiDecode = (...codes) => {
|
|
352
|
+
var codeArray = Array.isArray(codes[0]) ? codes[0] : codes;
|
|
353
|
+
return codeArray.map((c) => String.fromCharCode(c)).join("");
|
|
354
|
+
};
|
|
355
|
+
// Added for AsepXyz Baileys: alternate message-id generator (used by rich-message helpers)
|
|
356
|
+
const generateMessageIDV2 = (userId) => {
|
|
357
|
+
const data = Buffer.alloc(8 + 20 + 16);
|
|
358
|
+
data.writeBigUInt64BE(BigInt(Math.floor(Date.now() / 1000)));
|
|
359
|
+
if (userId) {
|
|
360
|
+
const id = jidDecode(userId);
|
|
361
|
+
if (id?.user) {
|
|
362
|
+
data.write(id.user, 8);
|
|
363
|
+
data.write("@c.us", 8 + id.user.length);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
const random = randomBytes(16);
|
|
367
|
+
random.copy(data, 28);
|
|
368
|
+
const hash = createHash("sha256").update(data).digest();
|
|
369
|
+
return "ASEPXYZ-" + hash.toString("hex").toUpperCase().substring(0, 18);
|
|
370
|
+
};
|
|
371
|
+
// Added for AsepXyz Baileys
|
|
372
|
+
const isStringNullOrEmpty = (value) =>
|
|
373
|
+
// eslint-disable-next-line eqeqeq
|
|
374
|
+
value == null || value === "";
|
|
375
|
+
module.exports = {
|
|
376
|
+
BufferJSON: BufferJSON,
|
|
377
|
+
getKeyAuthor: getKeyAuthor,
|
|
378
|
+
writeRandomPadMax16: writeRandomPadMax16,
|
|
379
|
+
unpadRandomMax16: unpadRandomMax16,
|
|
380
|
+
encodeWAMessage: encodeWAMessage,
|
|
381
|
+
encodeNewsletterMessage: encodeNewsletterMessage,
|
|
382
|
+
generateRegistrationId: generateRegistrationId,
|
|
383
|
+
encodeBigEndian: encodeBigEndian,
|
|
384
|
+
toNumber: toNumber,
|
|
385
|
+
unixTimestampSeconds: unixTimestampSeconds,
|
|
386
|
+
debouncedTimeout: debouncedTimeout,
|
|
387
|
+
delay: delay,
|
|
388
|
+
delayCancellable: delayCancellable,
|
|
389
|
+
promiseTimeout: promiseTimeout,
|
|
390
|
+
generateMessageID: generateMessageID,
|
|
391
|
+
generateParticipantHashV2: generateParticipantHashV2,
|
|
392
|
+
bindWaitForEvent: bindWaitForEvent,
|
|
393
|
+
bindWaitForConnectionUpdate: bindWaitForConnectionUpdate,
|
|
394
|
+
printQRIfNecessaryListener: printQRIfNecessaryListener,
|
|
395
|
+
fetchLatestBaileysVersion: fetchLatestBaileysVersion,
|
|
396
|
+
fetchLatestWaWebVersion: fetchLatestWaWebVersion,
|
|
397
|
+
generateMdTagPrefix: generateMdTagPrefix,
|
|
398
|
+
getStatusFromReceiptType: getStatusFromReceiptType,
|
|
399
|
+
getErrorCodeFromStreamError: getErrorCodeFromStreamError,
|
|
400
|
+
getCallStatusFromNode: getCallStatusFromNode,
|
|
401
|
+
getCodeFromWSError: getCodeFromWSError,
|
|
402
|
+
isWABusinessPlatform: isWABusinessPlatform,
|
|
403
|
+
trimUndefined: trimUndefined,
|
|
404
|
+
bytesToCrockford: bytesToCrockford,
|
|
405
|
+
toUnicodeEscape: toUnicodeEscape,
|
|
406
|
+
fromUnicodeEscape: fromUnicodeEscape,
|
|
407
|
+
asciiEncode: asciiEncode,
|
|
408
|
+
asciiDecode: asciiDecode,
|
|
409
|
+
generateMessageIDV2: generateMessageIDV2,
|
|
410
|
+
isStringNullOrEmpty: isStringNullOrEmpty,
|
|
411
|
+
};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const { promisify: promisify } = require("util");
|
|
4
|
+
const { inflate: inflate } = require("zlib");
|
|
5
|
+
const { proto: proto } = require("../../WAProto");
|
|
6
|
+
const { WAMessageStubType: WAMessageStubType } = require("../Types");
|
|
7
|
+
const { toNumber: toNumber } = require("./generics");
|
|
8
|
+
const { normalizeMessageContent: normalizeMessageContent } = require("./messages");
|
|
9
|
+
const { downloadContentFromMessage: downloadContentFromMessage } = require("./messages-media");
|
|
10
|
+
const inflatePromise = promisify(inflate);
|
|
11
|
+
const downloadHistory = async (msg, options) => {
|
|
12
|
+
const stream = await downloadContentFromMessage(msg, "md-msg-hist", {
|
|
13
|
+
options: options,
|
|
14
|
+
});
|
|
15
|
+
const bufferArray = [];
|
|
16
|
+
for await (const chunk of stream) {
|
|
17
|
+
bufferArray.push(chunk);
|
|
18
|
+
}
|
|
19
|
+
let buffer = Buffer.concat(bufferArray);
|
|
20
|
+
buffer = await inflatePromise(buffer);
|
|
21
|
+
const syncData = proto.HistorySync.decode(buffer);
|
|
22
|
+
return syncData;
|
|
23
|
+
};
|
|
24
|
+
const processHistoryMessage = (item) => {
|
|
25
|
+
const messages = [];
|
|
26
|
+
const contacts = [];
|
|
27
|
+
const chats = [];
|
|
28
|
+
switch (item.syncType) {
|
|
29
|
+
case proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP:
|
|
30
|
+
case proto.HistorySync.HistorySyncType.RECENT:
|
|
31
|
+
case proto.HistorySync.HistorySyncType.FULL:
|
|
32
|
+
case proto.HistorySync.HistorySyncType.ON_DEMAND:
|
|
33
|
+
for (const chat of item.conversations) {
|
|
34
|
+
contacts.push({
|
|
35
|
+
id: chat.id,
|
|
36
|
+
name: chat.name || undefined,
|
|
37
|
+
lid: chat.lidJid || undefined,
|
|
38
|
+
phoneNumber: chat.pnJid || undefined,
|
|
39
|
+
});
|
|
40
|
+
const msgs = chat.messages || [];
|
|
41
|
+
delete chat.messages;
|
|
42
|
+
for (const item of msgs) {
|
|
43
|
+
const message = item.message;
|
|
44
|
+
messages.push(message);
|
|
45
|
+
if (!chat.messages?.length) {
|
|
46
|
+
chat.messages = [{ message: message }];
|
|
47
|
+
}
|
|
48
|
+
if (!message.key.fromMe && !chat.lastMessageRecvTimestamp) {
|
|
49
|
+
chat.lastMessageRecvTimestamp = toNumber(message.messageTimestamp);
|
|
50
|
+
}
|
|
51
|
+
if (
|
|
52
|
+
message.messageStubType === WAMessageStubType.BIZ_PRIVACY_MODE_TO_BSP ||
|
|
53
|
+
(message.messageStubType === WAMessageStubType.BIZ_PRIVACY_MODE_TO_FB &&
|
|
54
|
+
message.messageStubParameters?.[0])
|
|
55
|
+
) {
|
|
56
|
+
contacts.push({
|
|
57
|
+
id: message.key.participant || message.key.remoteJid,
|
|
58
|
+
verifiedName: message.messageStubParameters?.[0],
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
chats.push({ ...chat });
|
|
63
|
+
}
|
|
64
|
+
break;
|
|
65
|
+
case proto.HistorySync.HistorySyncType.PUSH_NAME:
|
|
66
|
+
for (const c of item.pushnames) {
|
|
67
|
+
contacts.push({ id: c.id, notify: c.pushname });
|
|
68
|
+
}
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
chats: chats,
|
|
73
|
+
contacts: contacts,
|
|
74
|
+
messages: messages,
|
|
75
|
+
syncType: item.syncType,
|
|
76
|
+
progress: item.progress,
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
const downloadAndProcessHistorySyncNotification = async (msg, options) => {
|
|
80
|
+
let historyMsg;
|
|
81
|
+
if (msg.initialHistBootstrapInlinePayload) {
|
|
82
|
+
historyMsg = proto.HistorySync.decode(
|
|
83
|
+
await inflatePromise(msg.initialHistBootstrapInlinePayload)
|
|
84
|
+
);
|
|
85
|
+
} else {
|
|
86
|
+
historyMsg = await downloadHistory(msg, options);
|
|
87
|
+
}
|
|
88
|
+
return processHistoryMessage(historyMsg);
|
|
89
|
+
};
|
|
90
|
+
const getHistoryMsg = (message) => {
|
|
91
|
+
const normalizedContent = !!message ? normalizeMessageContent(message) : undefined;
|
|
92
|
+
const anyHistoryMsg = normalizedContent?.protocolMessage?.historySyncNotification;
|
|
93
|
+
return anyHistoryMsg;
|
|
94
|
+
};
|
|
95
|
+
module.exports = {
|
|
96
|
+
downloadHistory: downloadHistory,
|
|
97
|
+
processHistoryMessage: processHistoryMessage,
|
|
98
|
+
downloadAndProcessHistorySyncNotification: downloadAndProcessHistorySyncNotification,
|
|
99
|
+
getHistoryMsg: getHistoryMsg,
|
|
100
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Ported & adapted from PouCode fork for AsepXyz Baileys
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.handleIdentityChange = void 0;
|
|
5
|
+
const { areJidsSameUser, getBinaryNodeChild, jidDecode } = require("../WABinary");
|
|
6
|
+
const { isStringNullOrEmpty } = require("./generics");
|
|
7
|
+
async function handleIdentityChange(node, ctx) {
|
|
8
|
+
const from = node.attrs.from;
|
|
9
|
+
if (!from) {
|
|
10
|
+
return { action: 'invalid_notification' };
|
|
11
|
+
}
|
|
12
|
+
const identityNode = getBinaryNodeChild(node, 'identity');
|
|
13
|
+
if (!identityNode) {
|
|
14
|
+
return { action: 'no_identity_node' };
|
|
15
|
+
}
|
|
16
|
+
ctx.logger.info({ jid: from }, 'identity changed');
|
|
17
|
+
const decoded = jidDecode(from);
|
|
18
|
+
if (decoded?.device && decoded.device !== 0) {
|
|
19
|
+
ctx.logger.debug({ jid: from, device: decoded.device }, 'ignoring identity change from companion device');
|
|
20
|
+
return { action: 'skipped_companion_device', device: decoded.device };
|
|
21
|
+
}
|
|
22
|
+
const isSelfPrimary = ctx.meId && (areJidsSameUser(from, ctx.meId) || (ctx.meLid && areJidsSameUser(from, ctx.meLid)));
|
|
23
|
+
if (isSelfPrimary) {
|
|
24
|
+
ctx.logger.info({ jid: from }, 'self primary identity changed');
|
|
25
|
+
return { action: 'skipped_self_primary' };
|
|
26
|
+
}
|
|
27
|
+
if (ctx.debounceCache.get(from)) {
|
|
28
|
+
ctx.logger.debug({ jid: from }, 'skipping identity assert (debounced)');
|
|
29
|
+
return { action: 'debounced' };
|
|
30
|
+
}
|
|
31
|
+
ctx.debounceCache.set(from, true);
|
|
32
|
+
const isOfflineNotification = !isStringNullOrEmpty(node.attrs.offline);
|
|
33
|
+
const hasExistingSession = await ctx.validateSession(from);
|
|
34
|
+
if (!hasExistingSession.exists) {
|
|
35
|
+
ctx.logger.debug({ jid: from }, 'no old session, skipping session refresh');
|
|
36
|
+
return { action: 'skipped_no_session' };
|
|
37
|
+
}
|
|
38
|
+
ctx.logger.debug({ jid: from }, 'old session exists, will refresh session');
|
|
39
|
+
if (isOfflineNotification) {
|
|
40
|
+
ctx.logger.debug({ jid: from }, 'skipping session refresh during offline processing');
|
|
41
|
+
return { action: 'skipped_offline' };
|
|
42
|
+
}
|
|
43
|
+
ctx.onBeforeSessionRefresh?.(from);
|
|
44
|
+
try {
|
|
45
|
+
await ctx.assertSessions([from], true);
|
|
46
|
+
return { action: 'session_refreshed' };
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
ctx.logger.warn({ error, jid: from }, 'failed to assert sessions after identity change');
|
|
50
|
+
return { action: 'session_refresh_failed', error };
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.handleIdentityChange = handleIdentityChange;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const __createBinding =
|
|
3
|
+
(this && this.__createBinding) ||
|
|
4
|
+
(Object.create
|
|
5
|
+
? function (o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
let desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function () {
|
|
12
|
+
return m[k];
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
Object.defineProperty(o, k2, desc);
|
|
17
|
+
}
|
|
18
|
+
: function (o, m, k, k2) {
|
|
19
|
+
if (k2 === undefined) k2 = k;
|
|
20
|
+
o[k2] = m[k];
|
|
21
|
+
});
|
|
22
|
+
const __exportStar =
|
|
23
|
+
(this && this.__exportStar) ||
|
|
24
|
+
function (m, exports) {
|
|
25
|
+
for (var p in m) {
|
|
26
|
+
if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) {
|
|
27
|
+
__createBinding(exports, m, p);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
+
__exportStar(require("./generics"), exports);
|
|
33
|
+
__exportStar(require("./decode-wa-message"), exports);
|
|
34
|
+
__exportStar(require("./messages"), exports);
|
|
35
|
+
__exportStar(require("./messages-media"), exports);
|
|
36
|
+
__exportStar(require("./message-retry-manager"), exports);
|
|
37
|
+
__exportStar(require("./validate-connection"), exports);
|
|
38
|
+
__exportStar(require("./crypto"), exports);
|
|
39
|
+
__exportStar(require("./signal"), exports);
|
|
40
|
+
__exportStar(require("./noise-handler"), exports);
|
|
41
|
+
__exportStar(require("./history"), exports);
|
|
42
|
+
__exportStar(require("./chat-utils"), exports);
|
|
43
|
+
__exportStar(require("./lt-hash"), exports);
|
|
44
|
+
__exportStar(require("./auth-utils"), exports);
|
|
45
|
+
__exportStar(require("./browser-utils"), exports);
|
|
46
|
+
__exportStar(require("./use-multi-file-auth-state"), exports);
|
|
47
|
+
__exportStar(require("./link-preview"), exports);
|
|
48
|
+
__exportStar(require("./event-buffer"), exports);
|
|
49
|
+
__exportStar(require("./process-message"), exports);
|
|
50
|
+
__exportStar(require("./companion-reg-client-utils"), exports);
|
|
51
|
+
__exportStar(require("./identity-change-handler"), exports);
|
|
52
|
+
__exportStar(require("./stanza-ack"), exports);
|
|
53
|
+
__exportStar(require("./message-composer"), exports);
|
|
54
|
+
__exportStar(require("./tc-token-utils"), exports);
|
|
55
|
+
__exportStar(require("./reporting-utils"), exports);
|
|
56
|
+
__exportStar(require("./offline-node-processor"), exports);
|
|
57
|
+
__exportStar(require("./sync-action-utils"), exports);
|