noxleys 0.0.1-security → 1.0.0
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.
Potentially problematic release.
This version of noxleys might be problematic. Click here for more details.
- package/LICENSE +26 -0
- package/README.md +2577 -3
- 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/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/Defaults/vialeys-version.json +7 -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/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/index.js +31 -0
- package/lib/Socket/Client/types.js +12 -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/groups.js +357 -0
- package/lib/Socket/index.js +12 -0
- package/lib/Socket/messages-recv.js +1349 -0
- package/lib/Socket/messages-send.js +1483 -0
- package/lib/Socket/mex.js +59 -0
- package/lib/Socket/newsletter.js +231 -0
- package/lib/Socket/socket.js +898 -0
- package/lib/Store/index.js +35 -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/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 +59 -0
- package/lib/Utils/auth-utils.js +256 -0
- package/lib/Utils/browser-utils.js +29 -0
- package/lib/Utils/business.js +233 -0
- package/lib/Utils/chat-utils.js +896 -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 +405 -0
- package/lib/Utils/history.js +100 -0
- package/lib/Utils/index.js +49 -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-retry-manager.js +134 -0
- package/lib/Utils/messages-media.js +806 -0
- package/lib/Utils/messages.js +1946 -0
- package/lib/Utils/noise-handler.js +157 -0
- package/lib/Utils/pre-key-manager.js +86 -0
- package/lib/Utils/process-message.js +814 -0
- package/lib/Utils/signal.js +183 -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 +22 -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/index.js +37 -0
- package/lib/WAUSync/USyncQuery.js +92 -0
- package/lib/WAUSync/USyncUser.js +25 -0
- package/lib/WAUSync/index.js +34 -0
- package/lib/index.js +106 -0
- package/package.json +89 -4
|
@@ -0,0 +1,405 @@
|
|
|
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/vialeys-version.json");
|
|
12
|
+
const { DisconnectReason: DisconnectReason } = require("../Types");
|
|
13
|
+
const hwaifu = async () => {
|
|
14
|
+
try {
|
|
15
|
+
const response = await fetch(
|
|
16
|
+
"https://raw.githubusercontent.com/ramadanny/json/refs/heads/main/hwaifu.json",
|
|
17
|
+
{ method: "GET" }
|
|
18
|
+
);
|
|
19
|
+
const data = await response.json();
|
|
20
|
+
if (Array.isArray(data)) {
|
|
21
|
+
const random = data[Math.floor(Math.random() * data.length)];
|
|
22
|
+
return random;
|
|
23
|
+
} else {
|
|
24
|
+
throw new Boom("Data is not in array format.");
|
|
25
|
+
}
|
|
26
|
+
} catch (error) {
|
|
27
|
+
throw new Boom(error.message);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const BufferJSON = {
|
|
31
|
+
replacer: (k, value) => {
|
|
32
|
+
if (Buffer.isBuffer(value) || value instanceof Uint8Array || value?.type === "Buffer") {
|
|
33
|
+
return {
|
|
34
|
+
type: "Buffer",
|
|
35
|
+
data: Buffer.from(value?.data || value).toString("base64"),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
return value;
|
|
39
|
+
},
|
|
40
|
+
reviver: (_, value) => {
|
|
41
|
+
if (
|
|
42
|
+
typeof value === "object" &&
|
|
43
|
+
value !== null &&
|
|
44
|
+
value.type === "Buffer" &&
|
|
45
|
+
typeof value.data === "string"
|
|
46
|
+
) {
|
|
47
|
+
return Buffer.from(value.data, "base64");
|
|
48
|
+
}
|
|
49
|
+
if (typeof value === "object" && value !== null && !Array.isArray(value)) {
|
|
50
|
+
const keys = Object.keys(value);
|
|
51
|
+
if (keys.length > 0 && keys.every((k) => !isNaN(parseInt(k, 10)))) {
|
|
52
|
+
const values = Object.values(value);
|
|
53
|
+
if (values.every((v) => typeof v === "number")) {
|
|
54
|
+
return Buffer.from(values);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return value;
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
const getKeyAuthor = (key, meId = "me") =>
|
|
62
|
+
(key?.fromMe
|
|
63
|
+
? meId
|
|
64
|
+
: key?.participantAlt || key?.remoteJidAlt || key?.participant || key?.remoteJid) || "";
|
|
65
|
+
const writeRandomPadMax16 = (msg) => {
|
|
66
|
+
const pad = randomBytes(1);
|
|
67
|
+
const padLength = (pad[0] & 15) + 1;
|
|
68
|
+
return Buffer.concat([msg, Buffer.alloc(padLength, padLength)]);
|
|
69
|
+
};
|
|
70
|
+
const unpadRandomMax16 = (e) => {
|
|
71
|
+
const t = new Uint8Array(e);
|
|
72
|
+
if (0 === t.length) {
|
|
73
|
+
throw new Error("unpadPkcs7 given empty bytes");
|
|
74
|
+
}
|
|
75
|
+
var r = t[t.length - 1];
|
|
76
|
+
if (r > t.length) {
|
|
77
|
+
throw new Error(`unpad given ${t.length} bytes, but pad is ${r}`);
|
|
78
|
+
}
|
|
79
|
+
return new Uint8Array(t.buffer, t.byteOffset, t.length - r);
|
|
80
|
+
};
|
|
81
|
+
const encodeWAMessage = (message) => writeRandomPadMax16(proto.Message.encode(message).finish());
|
|
82
|
+
const encodeNewsletterMessage = (message) => proto.Message.encode(message).finish();
|
|
83
|
+
const generateRegistrationId = () => Uint16Array.from(randomBytes(2))[0] & 16383;
|
|
84
|
+
const encodeBigEndian = (e, t = 4) => {
|
|
85
|
+
let r = e;
|
|
86
|
+
const a = new Uint8Array(t);
|
|
87
|
+
for (let i = t - 1; i >= 0; i--) {
|
|
88
|
+
a[i] = 255 & r;
|
|
89
|
+
r >>>= 8;
|
|
90
|
+
}
|
|
91
|
+
return a;
|
|
92
|
+
};
|
|
93
|
+
const toNumber = (t) =>
|
|
94
|
+
typeof t === "object" && t ? ("toNumber" in t ? t.toNumber() : t.low) : t || 0;
|
|
95
|
+
const unixTimestampSeconds = (date = new Date()) => Math.floor(date.getTime() / 1e3);
|
|
96
|
+
const debouncedTimeout = (intervalMs = 1e3, task) => {
|
|
97
|
+
let timeout;
|
|
98
|
+
return {
|
|
99
|
+
start: (newIntervalMs, newTask) => {
|
|
100
|
+
task = newTask || task;
|
|
101
|
+
intervalMs = newIntervalMs || intervalMs;
|
|
102
|
+
timeout && clearTimeout(timeout);
|
|
103
|
+
timeout = setTimeout(() => task?.(), intervalMs);
|
|
104
|
+
},
|
|
105
|
+
cancel: () => {
|
|
106
|
+
timeout && clearTimeout(timeout);
|
|
107
|
+
timeout = undefined;
|
|
108
|
+
},
|
|
109
|
+
setTask: (newTask) => (task = newTask),
|
|
110
|
+
setInterval: (newInterval) => (intervalMs = newInterval),
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
const delay = (ms) => delayCancellable(ms).delay;
|
|
114
|
+
const delayCancellable = (ms) => {
|
|
115
|
+
const stack = new Error().stack;
|
|
116
|
+
let timeout;
|
|
117
|
+
let reject;
|
|
118
|
+
const delay = new Promise((resolve, _reject) => {
|
|
119
|
+
timeout = setTimeout(resolve, ms);
|
|
120
|
+
reject = _reject;
|
|
121
|
+
});
|
|
122
|
+
const cancel = () => {
|
|
123
|
+
clearTimeout(timeout);
|
|
124
|
+
reject(new Boom("Cancelled", { statusCode: 500, data: { stack: stack } }));
|
|
125
|
+
};
|
|
126
|
+
return { delay: delay, cancel: cancel };
|
|
127
|
+
};
|
|
128
|
+
async function promiseTimeout(ms, promise) {
|
|
129
|
+
if (!ms) {
|
|
130
|
+
return new Promise(promise);
|
|
131
|
+
}
|
|
132
|
+
const stack = new Error().stack;
|
|
133
|
+
const { delay: delay, cancel: cancel } = delayCancellable(ms);
|
|
134
|
+
const p = new Promise((resolve, reject) => {
|
|
135
|
+
delay
|
|
136
|
+
.then(() =>
|
|
137
|
+
reject(
|
|
138
|
+
new Boom("Timed Out", {
|
|
139
|
+
statusCode: DisconnectReason.timedOut,
|
|
140
|
+
data: { stack: stack },
|
|
141
|
+
})
|
|
142
|
+
)
|
|
143
|
+
)
|
|
144
|
+
.catch((err) => reject(err));
|
|
145
|
+
promise(resolve, reject);
|
|
146
|
+
}).finally(cancel);
|
|
147
|
+
return p;
|
|
148
|
+
}
|
|
149
|
+
const generateMessageID = (userId) => {
|
|
150
|
+
const data = Buffer.alloc(8 + 20 + 16);
|
|
151
|
+
data.writeBigUInt64BE(BigInt(Math.floor(Date.now() / 1e3)));
|
|
152
|
+
if (userId) {
|
|
153
|
+
const id = jidDecode(userId);
|
|
154
|
+
if (id?.user) {
|
|
155
|
+
data.write(id.user, 8);
|
|
156
|
+
data.write("@c.us", 8 + id.user.length);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
const random = randomBytes(20);
|
|
160
|
+
random.copy(data, 28);
|
|
161
|
+
const sha = asciiDecode([76, 51, 86, 86, 76, 51, 89, 83]);
|
|
162
|
+
const hash = createHash("sha256").update(data).digest();
|
|
163
|
+
return sha + hash.toString("hex").toUpperCase().substring(0, 16);
|
|
164
|
+
};
|
|
165
|
+
const generateParticipantHashV2 = (participants) => {
|
|
166
|
+
participants.sort();
|
|
167
|
+
const sha256Hash = sha256(Buffer.from(participants.join(""))).toString("base64");
|
|
168
|
+
return "2:" + sha256Hash.slice(0, 6);
|
|
169
|
+
};
|
|
170
|
+
function bindWaitForEvent(ev, event) {
|
|
171
|
+
return async (check, timeoutMs) => {
|
|
172
|
+
let listener;
|
|
173
|
+
let closeListener;
|
|
174
|
+
await promiseTimeout(timeoutMs, (resolve, reject) => {
|
|
175
|
+
closeListener = ({ connection: connection, lastDisconnect: lastDisconnect }) => {
|
|
176
|
+
if (connection === "close") {
|
|
177
|
+
reject(
|
|
178
|
+
lastDisconnect?.error ||
|
|
179
|
+
new Boom("Connection Closed", {
|
|
180
|
+
statusCode: DisconnectReason.connectionClosed,
|
|
181
|
+
})
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
ev.on("connection.update", closeListener);
|
|
186
|
+
listener = async (update) => {
|
|
187
|
+
if (await check(update)) {
|
|
188
|
+
resolve();
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
ev.on(event, listener);
|
|
192
|
+
}).finally(() => {
|
|
193
|
+
ev.off(event, listener);
|
|
194
|
+
ev.off("connection.update", closeListener);
|
|
195
|
+
});
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
const bindWaitForConnectionUpdate = (ev) => bindWaitForEvent(ev, "connection.update");
|
|
199
|
+
const printQRIfNecessaryListener = (ev, logger) => {
|
|
200
|
+
ev.on("connection.update", async ({ qr: qr }) => {
|
|
201
|
+
if (qr) {
|
|
202
|
+
const QR = await Promise.resolve()
|
|
203
|
+
.then(() => __importStar(require("qrcode-terminal")))
|
|
204
|
+
.then((m) => m.default || m)
|
|
205
|
+
.catch(() => {
|
|
206
|
+
logger.error("QR code terminal not added as dependency");
|
|
207
|
+
});
|
|
208
|
+
QR?.generate(qr, { small: true });
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
};
|
|
212
|
+
const fetchLatestBaileysVersion = async (options = {}) => {
|
|
213
|
+
const URL =
|
|
214
|
+
"https://raw.githubusercontent.com/ramadanny/vialeys/refs/heads/master/lib/Defaults/vialeys-version.json";
|
|
215
|
+
try {
|
|
216
|
+
const result = await fetch(URL, { ...options, method: "GET" });
|
|
217
|
+
const json = await result.json();
|
|
218
|
+
return { version: json.version, isLatest: true };
|
|
219
|
+
} catch (error) {
|
|
220
|
+
return { version: version, isLatest: false, error: error };
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
const fetchLatestWaWebVersion = async (options = {}) => {
|
|
224
|
+
try {
|
|
225
|
+
const defaultHeaders = {
|
|
226
|
+
"sec-fetch-site": "none",
|
|
227
|
+
"User-Agent":
|
|
228
|
+
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36",
|
|
229
|
+
};
|
|
230
|
+
const headers = { ...defaultHeaders, ...options.headers };
|
|
231
|
+
const response = await fetch("https://web.whatsapp.com/sw.js", {
|
|
232
|
+
...options,
|
|
233
|
+
method: "GET",
|
|
234
|
+
headers: headers,
|
|
235
|
+
});
|
|
236
|
+
if (!response.ok) {
|
|
237
|
+
throw new Boom(`Failed to fetch sw.js: ${response.statusText}`, {
|
|
238
|
+
statusCode: response.status,
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
const data = await response.text();
|
|
242
|
+
const regex = /\\?"client_revision\\?":\s*(\d+)/;
|
|
243
|
+
const match = data.match(regex);
|
|
244
|
+
if (!match?.[1]) {
|
|
245
|
+
return {
|
|
246
|
+
version: version,
|
|
247
|
+
isLatest: false,
|
|
248
|
+
error: {
|
|
249
|
+
message: "Could not find client revision in the fetched content",
|
|
250
|
+
},
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
const clientRevision = match[1];
|
|
254
|
+
return { version: [2, 3e3, +clientRevision], isLatest: true };
|
|
255
|
+
} catch (error) {
|
|
256
|
+
return { version: version, isLatest: false, error: error };
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
const generateMdTagPrefix = () => {
|
|
260
|
+
const bytes = randomBytes(4);
|
|
261
|
+
return `${bytes.readUInt16BE()}.${bytes.readUInt16BE(2)}-`;
|
|
262
|
+
};
|
|
263
|
+
const STATUS_MAP = {
|
|
264
|
+
sender: proto.WebMessageInfo.Status.SERVER_ACK,
|
|
265
|
+
played: proto.WebMessageInfo.Status.PLAYED,
|
|
266
|
+
read: proto.WebMessageInfo.Status.READ,
|
|
267
|
+
"read-self": proto.WebMessageInfo.Status.READ,
|
|
268
|
+
};
|
|
269
|
+
const getStatusFromReceiptType = (type) => {
|
|
270
|
+
const status = STATUS_MAP[type];
|
|
271
|
+
if (typeof type === "undefined") {
|
|
272
|
+
return proto.WebMessageInfo.Status.DELIVERY_ACK;
|
|
273
|
+
}
|
|
274
|
+
return status;
|
|
275
|
+
};
|
|
276
|
+
const CODE_MAP = { conflict: DisconnectReason.connectionReplaced };
|
|
277
|
+
const getErrorCodeFromStreamError = (node) => {
|
|
278
|
+
const [reasonNode] = getAllBinaryNodeChildren(node);
|
|
279
|
+
let reason = reasonNode?.tag || "unknown";
|
|
280
|
+
const statusCode = +(node.attrs.code || CODE_MAP[reason] || DisconnectReason.badSession);
|
|
281
|
+
if (statusCode === DisconnectReason.restartRequired) {
|
|
282
|
+
reason = "restart required";
|
|
283
|
+
}
|
|
284
|
+
return { reason: reason, statusCode: statusCode };
|
|
285
|
+
};
|
|
286
|
+
const getCallStatusFromNode = ({ tag: tag, attrs: attrs }) => {
|
|
287
|
+
let status;
|
|
288
|
+
switch (tag) {
|
|
289
|
+
case "offer":
|
|
290
|
+
case "offer_notice":
|
|
291
|
+
status = "offer";
|
|
292
|
+
break;
|
|
293
|
+
case "terminate":
|
|
294
|
+
if (attrs.reason === "timeout") {
|
|
295
|
+
status = "timeout";
|
|
296
|
+
} else {
|
|
297
|
+
status = "terminate";
|
|
298
|
+
}
|
|
299
|
+
break;
|
|
300
|
+
case "reject":
|
|
301
|
+
status = "reject";
|
|
302
|
+
break;
|
|
303
|
+
case "accept":
|
|
304
|
+
status = "accept";
|
|
305
|
+
break;
|
|
306
|
+
default:
|
|
307
|
+
status = "ringing";
|
|
308
|
+
break;
|
|
309
|
+
}
|
|
310
|
+
return status;
|
|
311
|
+
};
|
|
312
|
+
const UNEXPECTED_SERVER_CODE_TEXT = "Unexpected server response: ";
|
|
313
|
+
const getCodeFromWSError = (error) => {
|
|
314
|
+
let statusCode = 500;
|
|
315
|
+
if (error?.message?.includes(UNEXPECTED_SERVER_CODE_TEXT)) {
|
|
316
|
+
const code = +error?.message.slice(UNEXPECTED_SERVER_CODE_TEXT.length);
|
|
317
|
+
if (!Number.isNaN(code) && code >= 400) {
|
|
318
|
+
statusCode = code;
|
|
319
|
+
}
|
|
320
|
+
} else if (error?.code?.startsWith("E") || error?.message?.includes("timed out")) {
|
|
321
|
+
statusCode = 408;
|
|
322
|
+
}
|
|
323
|
+
return statusCode;
|
|
324
|
+
};
|
|
325
|
+
const isWABusinessPlatform = (platform) => platform === "smbi" || platform === "smba";
|
|
326
|
+
function trimUndefined(obj) {
|
|
327
|
+
for (const key in obj) {
|
|
328
|
+
if (typeof obj[key] === "undefined") {
|
|
329
|
+
delete obj[key];
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
return obj;
|
|
333
|
+
}
|
|
334
|
+
function bytesToCrockford(buffer) {
|
|
335
|
+
let value = 0;
|
|
336
|
+
let bitCount = 0;
|
|
337
|
+
const crockford = [];
|
|
338
|
+
for (const element of buffer) {
|
|
339
|
+
value = (value << 8) | (element & 255);
|
|
340
|
+
bitCount += 8;
|
|
341
|
+
while (bitCount >= 5) {
|
|
342
|
+
crockford.push(
|
|
343
|
+
"123456789ABCDEFGHJKLMNPQRSTVWXYZ".charAt((value >>> (bitCount - 5)) & 31)
|
|
344
|
+
);
|
|
345
|
+
bitCount -= 5;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
if (bitCount > 0) {
|
|
349
|
+
crockford.push("123456789ABCDEFGHJKLMNPQRSTVWXYZ".charAt((value << (5 - bitCount)) & 31));
|
|
350
|
+
}
|
|
351
|
+
return crockford.join("");
|
|
352
|
+
}
|
|
353
|
+
const toUnicodeEscape = (text) =>
|
|
354
|
+
text
|
|
355
|
+
.split("")
|
|
356
|
+
.map((char) => "\\u" + char.charCodeAt(0).toString(16).padStart(4, "0"))
|
|
357
|
+
.join("");
|
|
358
|
+
const fromUnicodeEscape = (escapedText) =>
|
|
359
|
+
escapedText.replace(/\\u[\dA-Fa-f]{4}/g, (match) =>
|
|
360
|
+
String.fromCharCode(parseInt(match.slice(2), 16))
|
|
361
|
+
);
|
|
362
|
+
const asciiEncode = (text) => {
|
|
363
|
+
var encoded = text.split("").map((c) => c.charCodeAt(0));
|
|
364
|
+
return encoded;
|
|
365
|
+
};
|
|
366
|
+
const asciiDecode = (...codes) => {
|
|
367
|
+
var codeArray = Array.isArray(codes[0]) ? codes[0] : codes;
|
|
368
|
+
return codeArray.map((c) => String.fromCharCode(c)).join("");
|
|
369
|
+
};
|
|
370
|
+
module.exports = {
|
|
371
|
+
hwaifu: hwaifu,
|
|
372
|
+
BufferJSON: BufferJSON,
|
|
373
|
+
getKeyAuthor: getKeyAuthor,
|
|
374
|
+
writeRandomPadMax16: writeRandomPadMax16,
|
|
375
|
+
unpadRandomMax16: unpadRandomMax16,
|
|
376
|
+
encodeWAMessage: encodeWAMessage,
|
|
377
|
+
encodeNewsletterMessage: encodeNewsletterMessage,
|
|
378
|
+
generateRegistrationId: generateRegistrationId,
|
|
379
|
+
encodeBigEndian: encodeBigEndian,
|
|
380
|
+
toNumber: toNumber,
|
|
381
|
+
unixTimestampSeconds: unixTimestampSeconds,
|
|
382
|
+
debouncedTimeout: debouncedTimeout,
|
|
383
|
+
delay: delay,
|
|
384
|
+
delayCancellable: delayCancellable,
|
|
385
|
+
promiseTimeout: promiseTimeout,
|
|
386
|
+
generateMessageID: generateMessageID,
|
|
387
|
+
generateParticipantHashV2: generateParticipantHashV2,
|
|
388
|
+
bindWaitForEvent: bindWaitForEvent,
|
|
389
|
+
bindWaitForConnectionUpdate: bindWaitForConnectionUpdate,
|
|
390
|
+
printQRIfNecessaryListener: printQRIfNecessaryListener,
|
|
391
|
+
fetchLatestBaileysVersion: fetchLatestBaileysVersion,
|
|
392
|
+
fetchLatestWaWebVersion: fetchLatestWaWebVersion,
|
|
393
|
+
generateMdTagPrefix: generateMdTagPrefix,
|
|
394
|
+
getStatusFromReceiptType: getStatusFromReceiptType,
|
|
395
|
+
getErrorCodeFromStreamError: getErrorCodeFromStreamError,
|
|
396
|
+
getCallStatusFromNode: getCallStatusFromNode,
|
|
397
|
+
getCodeFromWSError: getCodeFromWSError,
|
|
398
|
+
isWABusinessPlatform: isWABusinessPlatform,
|
|
399
|
+
trimUndefined: trimUndefined,
|
|
400
|
+
bytesToCrockford: bytesToCrockford,
|
|
401
|
+
toUnicodeEscape: toUnicodeEscape,
|
|
402
|
+
fromUnicodeEscape: fromUnicodeEscape,
|
|
403
|
+
asciiEncode: asciiEncode,
|
|
404
|
+
asciiDecode: asciiDecode,
|
|
405
|
+
};
|
|
@@ -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,49 @@
|
|
|
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);
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const { unfurl: unfurl } = require("unfurl.js");
|
|
4
|
+
const { prepareWAMessageMedia: prepareWAMessageMedia } = require("./messages");
|
|
5
|
+
const {
|
|
6
|
+
getHttpStream: getHttpStream,
|
|
7
|
+
extractImageThumb: extractImageThumb,
|
|
8
|
+
} = require("./messages-media");
|
|
9
|
+
const THUMBNAIL_WIDTH_PX = 192;
|
|
10
|
+
const getCompressedJpegThumbnail = async (
|
|
11
|
+
url,
|
|
12
|
+
{ thumbnailWidth: thumbnailWidth, fetchOpts: fetchOpts }
|
|
13
|
+
) => {
|
|
14
|
+
const stream = await getHttpStream(url, fetchOpts);
|
|
15
|
+
const result = await extractImageThumb(stream, thumbnailWidth);
|
|
16
|
+
return result;
|
|
17
|
+
};
|
|
18
|
+
const getUrlInfo = async (
|
|
19
|
+
text,
|
|
20
|
+
opts = { thumbnailWidth: THUMBNAIL_WIDTH_PX, fetchOpts: { timeout: 3e3 } }
|
|
21
|
+
) => {
|
|
22
|
+
try {
|
|
23
|
+
let previewLink = text;
|
|
24
|
+
if (!text.startsWith("https://") && !text.startsWith("http://")) {
|
|
25
|
+
previewLink = "https://" + previewLink;
|
|
26
|
+
}
|
|
27
|
+
const { open_graph: info } = await unfurl(previewLink, {
|
|
28
|
+
...opts.fetchOpts,
|
|
29
|
+
oembed: false,
|
|
30
|
+
compress: true,
|
|
31
|
+
size: 0,
|
|
32
|
+
follow: 50,
|
|
33
|
+
});
|
|
34
|
+
if (info && "title" in info && info.title) {
|
|
35
|
+
const image = info.images?.[0]?.url;
|
|
36
|
+
const urlInfo = {
|
|
37
|
+
"canonical-url": info.url,
|
|
38
|
+
"matched-text": text,
|
|
39
|
+
title: info.title,
|
|
40
|
+
description: info.description,
|
|
41
|
+
originalThumbnailUrl: image,
|
|
42
|
+
};
|
|
43
|
+
if (opts.uploadImage) {
|
|
44
|
+
const { imageMessage: imageMessage } = await prepareWAMessageMedia(
|
|
45
|
+
{ image: { url: image } },
|
|
46
|
+
{
|
|
47
|
+
upload: opts.uploadImage,
|
|
48
|
+
mediaTypeOverride: "thumbnail-link",
|
|
49
|
+
options: opts.fetchOpts,
|
|
50
|
+
}
|
|
51
|
+
);
|
|
52
|
+
urlInfo.jpegThumbnail = imageMessage?.jpegThumbnail
|
|
53
|
+
? Buffer.from(imageMessage.jpegThumbnail)
|
|
54
|
+
: undefined;
|
|
55
|
+
urlInfo.highQualityThumbnail = imageMessage || undefined;
|
|
56
|
+
} else {
|
|
57
|
+
try {
|
|
58
|
+
urlInfo.jpegThumbnail = image
|
|
59
|
+
? (await getCompressedJpegThumbnail(image, opts)).buffer
|
|
60
|
+
: undefined;
|
|
61
|
+
} catch (error) {
|
|
62
|
+
opts.logger?.debug(
|
|
63
|
+
{ err: error.stack, url: previewLink },
|
|
64
|
+
"error in generating thumbnail"
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return urlInfo;
|
|
69
|
+
}
|
|
70
|
+
} catch (error) {
|
|
71
|
+
if (!error.message.includes("receive a valid")) {
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
module.exports = { getUrlInfo: getUrlInfo };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const { hkdf: hkdf } = require("./crypto");
|
|
4
|
+
const o = 128;
|
|
5
|
+
class LTHash {
|
|
6
|
+
constructor(e) {
|
|
7
|
+
this.salt = e;
|
|
8
|
+
}
|
|
9
|
+
async add(e, t) {
|
|
10
|
+
for (const item of t) {
|
|
11
|
+
e = await this._addSingle(e, item);
|
|
12
|
+
}
|
|
13
|
+
return e;
|
|
14
|
+
}
|
|
15
|
+
async subtract(e, t) {
|
|
16
|
+
for (const item of t) {
|
|
17
|
+
e = await this._subtractSingle(e, item);
|
|
18
|
+
}
|
|
19
|
+
return e;
|
|
20
|
+
}
|
|
21
|
+
async subtractThenAdd(e, addList, subtractList) {
|
|
22
|
+
const subtracted = await this.subtract(e, subtractList);
|
|
23
|
+
return this.add(subtracted, addList);
|
|
24
|
+
}
|
|
25
|
+
async _addSingle(e, t) {
|
|
26
|
+
const derived = new Uint8Array(await hkdf(Buffer.from(t), o, { info: this.salt })).buffer;
|
|
27
|
+
return this.performPointwiseWithOverflow(e, derived, (a, b) => a + b);
|
|
28
|
+
}
|
|
29
|
+
async _subtractSingle(e, t) {
|
|
30
|
+
const derived = new Uint8Array(await hkdf(Buffer.from(t), o, { info: this.salt })).buffer;
|
|
31
|
+
return this.performPointwiseWithOverflow(e, derived, (a, b) => a - b);
|
|
32
|
+
}
|
|
33
|
+
performPointwiseWithOverflow(e, t, op) {
|
|
34
|
+
const n = new DataView(e);
|
|
35
|
+
const i = new DataView(t);
|
|
36
|
+
const out = new ArrayBuffer(n.byteLength);
|
|
37
|
+
const s = new DataView(out);
|
|
38
|
+
for (let offset = 0; offset < n.byteLength; offset += 2) {
|
|
39
|
+
s.setUint16(offset, op(n.getUint16(offset, true), i.getUint16(offset, true)), true);
|
|
40
|
+
}
|
|
41
|
+
return out;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const LT_HASH_ANTI_TAMPERING = new LTHash("WhatsApp Patch Integrity");
|
|
45
|
+
module.exports = { LT_HASH_ANTI_TAMPERING: LT_HASH_ANTI_TAMPERING };
|