@zelynskybail/baileys 2.6.30 → 2.6.34
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/BUILD_STATUS.md +14 -18
- package/CHANGELOG.md +18 -0
- package/LICENSE-JAPOFC-VOIP +21 -0
- package/README.md +46 -8
- package/THIRD_PARTY_NOTICES.md +7 -0
- package/lib/Utils/ffmpeg-path.js +20 -0
- package/lib/VoIP/audio-feeder.d.ts +20 -0
- package/lib/VoIP/audio-feeder.js +208 -0
- package/lib/VoIP/call-recorder.d.ts +13 -0
- package/lib/VoIP/call-recorder.js +77 -0
- package/lib/VoIP/group-call.d.ts +105 -0
- package/lib/VoIP/group-call.js +718 -0
- package/lib/VoIP/index.d.ts +56 -4
- package/lib/VoIP/index.js +343 -28
- package/lib/VoIP/relay-transport.d.ts +43 -0
- package/lib/VoIP/relay-transport.js +563 -0
- package/lib/VoIP/signaling.d.ts +26 -0
- package/lib/VoIP/signaling.js +662 -0
- package/lib/VoIP/types.d.ts +69 -0
- package/lib/VoIP/types.js +19 -0
- package/lib/VoIP/wasm-engine.d.ts +120 -0
- package/lib/VoIP/wasm-engine.js +1386 -0
- package/lib/VoIP/worker-bootstrap.d.ts +4 -0
- package/lib/VoIP/worker-bootstrap.js +1046 -0
- package/package.json +16 -6
- package/scripts/check-publish-eligibility.mjs +13 -0
- package/scripts/fetch-wasm-resources.mjs +339 -0
- package/scripts/verify.mjs +31 -0
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zelynskybail/baileys",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.6.
|
|
5
|
-
"description": "Adaptive Baileys v7 fork with
|
|
4
|
+
"version": "2.6.34",
|
|
5
|
+
"description": "Adaptive Baileys v7 fork with interactive builders, media tools, and experimental shared-socket VoIP/group-call support.",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE",
|
|
7
7
|
"main": "lib/index.js",
|
|
8
8
|
"types": "lib/index.d.ts",
|
|
@@ -16,14 +16,20 @@
|
|
|
16
16
|
"NOTICE.md",
|
|
17
17
|
"THIRD_PARTY_NOTICES.md",
|
|
18
18
|
"CHANGELOG.md",
|
|
19
|
-
"THANKS.md"
|
|
19
|
+
"THANKS.md",
|
|
20
|
+
"scripts/fetch-wasm-resources.mjs",
|
|
21
|
+
"lib/assets/wasm/**/*",
|
|
22
|
+
"LICENSE-JAPOFC-VOIP",
|
|
23
|
+
"scripts/verify.mjs",
|
|
24
|
+
"scripts/check-publish-eligibility.mjs"
|
|
20
25
|
],
|
|
21
26
|
"scripts": {
|
|
22
27
|
"build": "node scripts/verify.mjs",
|
|
23
28
|
"verify": "node scripts/verify.mjs",
|
|
24
29
|
"test": "node --test",
|
|
25
30
|
"prepack": "npm run verify",
|
|
26
|
-
"prepublishOnly": "node scripts/check-publish-eligibility.mjs"
|
|
31
|
+
"prepublishOnly": "node scripts/check-publish-eligibility.mjs",
|
|
32
|
+
"voip:fetch-wasm": "node scripts/fetch-wasm-resources.mjs"
|
|
27
33
|
},
|
|
28
34
|
"keywords": [
|
|
29
35
|
"baileys",
|
|
@@ -34,7 +40,10 @@
|
|
|
34
40
|
"multi-device",
|
|
35
41
|
"bot",
|
|
36
42
|
"automation",
|
|
37
|
-
"interactive-messages"
|
|
43
|
+
"interactive-messages",
|
|
44
|
+
"group-call",
|
|
45
|
+
"voip",
|
|
46
|
+
"webrtc"
|
|
38
47
|
],
|
|
39
48
|
"dependencies": {
|
|
40
49
|
"@cacheable/node-cache": "^1.4.0",
|
|
@@ -126,6 +135,7 @@
|
|
|
126
135
|
"access": "public"
|
|
127
136
|
},
|
|
128
137
|
"optionalDependencies": {
|
|
129
|
-
"@paiavaliable/baileys-caller": "^1.0.0"
|
|
138
|
+
"@paiavaliable/baileys-caller": "^1.0.0",
|
|
139
|
+
"@roamhq/wrtc": "*"
|
|
130
140
|
}
|
|
131
141
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
|
|
5
|
+
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
6
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'));
|
|
7
|
+
if (!pkg.version || !/^2\.6\.34$/.test(pkg.version)) {
|
|
8
|
+
throw new Error(`Unexpected release version: ${pkg.version}`);
|
|
9
|
+
}
|
|
10
|
+
for (const file of ['README.md', 'CHANGELOG.md', 'NOTICE.md', 'THIRD_PARTY_NOTICES.md', 'LICENSE-JAPOFC-VOIP']) {
|
|
11
|
+
if (!fs.existsSync(path.join(root, file))) throw new Error(`Missing release file: ${file}`);
|
|
12
|
+
}
|
|
13
|
+
console.log(`Publish metadata OK for ${pkg.name}@${pkg.version}`);
|
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JAP@Tool --- refresh the bundled VoIP WASM resources from WhatsApp Web.
|
|
3
|
+
*
|
|
4
|
+
* Default mode uses WhatsApp Web's public bootloader endpoint, so no logged-in
|
|
5
|
+
* browser is required:
|
|
6
|
+
*
|
|
7
|
+
* npm run voip:fetch-wasm
|
|
8
|
+
*
|
|
9
|
+
* If the public endpoint changes, fallback to a running WhatsApp Web browser:
|
|
10
|
+
*
|
|
11
|
+
* CALL_WASM_FETCH_MODE=browser \
|
|
12
|
+
* CALL_CHROME_DEBUGGER_JSON_URL=http://127.0.0.1:9222/json/list \
|
|
13
|
+
* node --experimental-websocket scripts/fetch-wasm-resources.mjs
|
|
14
|
+
*/
|
|
15
|
+
import { writeFileSync, readFileSync, existsSync } from "fs";
|
|
16
|
+
import { createHash } from "crypto";
|
|
17
|
+
import { resolve, dirname } from "path";
|
|
18
|
+
import { fileURLToPath, pathToFileURL } from "url";
|
|
19
|
+
|
|
20
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
21
|
+
const RESOURCES_DIR = resolve(__dirname, "../lib/assets/wasm");
|
|
22
|
+
const DEBUGGER_URL = process.env.CALL_CHROME_DEBUGGER_JSON_URL || "http://127.0.0.1:9222/json/list";
|
|
23
|
+
const WASM_ID = process.env.CALL_BROWSER_WASM_ID || process.env.CALL_WASM_ID || "32180";
|
|
24
|
+
const FETCH_MODE = (process.env.CALL_WASM_FETCH_MODE || "auto").toLowerCase();
|
|
25
|
+
const BOOTLOADER_ENDPOINT = process.env.CALL_WA_BOOTLOADER_ENDPOINT || "https://web.whatsapp.com/ajax/bootloader-endpoint/";
|
|
26
|
+
const BOOTLOADER_MODULE = process.env.CALL_WA_WASM_MODULE || "WAWebVoipWebWasmLoader";
|
|
27
|
+
|
|
28
|
+
const DEFAULT_HEADERS = {
|
|
29
|
+
"accept": "*/*",
|
|
30
|
+
"cache-control": "no-cache",
|
|
31
|
+
"pragma": "no-cache",
|
|
32
|
+
"referer": "https://web.whatsapp.com/",
|
|
33
|
+
"sec-fetch-site": "same-origin",
|
|
34
|
+
"user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const sha = (buf) => createHash("sha256").update(buf).digest("hex");
|
|
38
|
+
|
|
39
|
+
async function fetchOk(url, options = {}) {
|
|
40
|
+
const response = await fetch(url, {
|
|
41
|
+
cache: "no-store",
|
|
42
|
+
...options,
|
|
43
|
+
headers: { ...DEFAULT_HEADERS, ...(options.headers || {}) }
|
|
44
|
+
});
|
|
45
|
+
if (!response.ok) {
|
|
46
|
+
throw new Error(`GET ${url} failed: ${response.status} ${response.statusText}`);
|
|
47
|
+
}
|
|
48
|
+
return response;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async function fetchText(url, options = {}) {
|
|
52
|
+
return await (await fetchOk(url, options)).text();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function parseBootloaderPayload(raw) {
|
|
56
|
+
const json = raw.replace(/^for \(;;\);/, "");
|
|
57
|
+
return JSON.parse(json);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function findDefine(payload, name) {
|
|
61
|
+
return payload?.hrp?.jsmods?.define?.find((row) => Array.isArray(row) && row[0] === name);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async function fetchLatestClientRevision() {
|
|
65
|
+
const raw = await fetchText("https://web.whatsapp.com/sw.js", {
|
|
66
|
+
headers: { "sec-fetch-site": "none", "referer": "https://web.whatsapp.com/" }
|
|
67
|
+
});
|
|
68
|
+
const match = raw.match(/\\?"client_revision\\?":\s*(\d+)/);
|
|
69
|
+
return match?.[1] || null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async function findLoaderResourceUrl(payload) {
|
|
73
|
+
const rsrcMap = payload?.hrp?.hsrp?.hblp?.rsrcMap || {};
|
|
74
|
+
const resources = payload?.hrp?.allResources || Object.keys(rsrcMap);
|
|
75
|
+
const moduleNeedle = `__d("${BOOTLOADER_MODULE}"`;
|
|
76
|
+
|
|
77
|
+
for (const id of resources) {
|
|
78
|
+
const entry = rsrcMap[id];
|
|
79
|
+
if (entry?.type !== "js" || !entry.src) continue;
|
|
80
|
+
const code = await fetchText(entry.src);
|
|
81
|
+
if (code.includes(moduleNeedle) || code.includes(`__d('${BOOTLOADER_MODULE}'`)) {
|
|
82
|
+
return { url: entry.src, code };
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return { url: null, code: null };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async function fetchFromBootloaderEndpoint() {
|
|
89
|
+
const latestClientRevision = await fetchLatestClientRevision().catch(() => null);
|
|
90
|
+
const url = new URL(BOOTLOADER_ENDPOINT);
|
|
91
|
+
url.searchParams.set("modules", BOOTLOADER_MODULE);
|
|
92
|
+
// Minimal params accepted for public logged-out WhatsApp Web bootloader data.
|
|
93
|
+
url.searchParams.set("__a", "1");
|
|
94
|
+
url.searchParams.set("__user", "0");
|
|
95
|
+
url.searchParams.set("__comet_req", "15");
|
|
96
|
+
// Ask the bootloader for the same live revision advertised by sw.js; without
|
|
97
|
+
// these hints, some CDN edges can serve an older logged-out cohort.
|
|
98
|
+
if (latestClientRevision) {
|
|
99
|
+
url.searchParams.set("__spin_r", latestClientRevision);
|
|
100
|
+
url.searchParams.set("__spin_b", "trunk");
|
|
101
|
+
url.searchParams.set("__spin_t", String(Math.floor(Date.now() / 1000)));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const payload = parseBootloaderPayload(await fetchText(url));
|
|
105
|
+
const bxData = payload?.hrp?.hsrp?.hsdp?.bxData || {};
|
|
106
|
+
const wasmUrl = bxData[WASM_ID]?.uri || Object.values(bxData).find((v) => /\.wasm(?:$|\?)/.test(v?.uri || ""))?.uri;
|
|
107
|
+
const workerDef = findDefine(payload, "WAWebVoipWebWasmWorkerResource");
|
|
108
|
+
const workerUrl = workerDef?.[2]?.url;
|
|
109
|
+
const clientRevision = workerDef?.[2]?.dynamicModules?.SiteData?.client_revision
|
|
110
|
+
|| workerDef?.[2]?.dynamicModules?.SiteData?.__spin_r
|
|
111
|
+
|| latestClientRevision
|
|
112
|
+
|| null;
|
|
113
|
+
const { url: loaderUrl, code: loaderCode } = await findLoaderResourceUrl(payload);
|
|
114
|
+
|
|
115
|
+
if (!workerUrl) throw new Error("WAWebVoipWebWasmWorkerResource.url not found in bootloader payload");
|
|
116
|
+
if (!wasmUrl) throw new Error(`WASM URL not found in bootloader bxData (wanted id ${WASM_ID}; ids: ${Object.keys(bxData).join(", ")})`);
|
|
117
|
+
if (!loaderUrl) throw new Error(`${BOOTLOADER_MODULE} resource not found in bootloader JS resources`);
|
|
118
|
+
|
|
119
|
+
return {
|
|
120
|
+
source: "bootloader-endpoint",
|
|
121
|
+
clientRevision,
|
|
122
|
+
workerUrl,
|
|
123
|
+
wasmUrl,
|
|
124
|
+
loaderUrl,
|
|
125
|
+
loaderCode,
|
|
126
|
+
availableWasmIds: Object.keys(bxData)
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Pure verifier: given a pinned integrity manifest and a map of freshly
|
|
132
|
+
* downloaded `{ name: Buffer }`, report which files match their pinned
|
|
133
|
+
* sha256 + size. No network, no fs — unit-testable in the offline suite.
|
|
134
|
+
* Returns `{ ok, files: [{ name, ok, reason?, expected, actual }] }`.
|
|
135
|
+
*/
|
|
136
|
+
export function verifyPinnedManifest(manifest, downloads) {
|
|
137
|
+
const pinned = manifest?.files || {};
|
|
138
|
+
const files = [];
|
|
139
|
+
for (const [name, meta] of Object.entries(pinned)) {
|
|
140
|
+
const buf = downloads?.[name];
|
|
141
|
+
if (!buf) {
|
|
142
|
+
files.push({ name, ok: false, reason: "missing", expected: meta, actual: null });
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
const actualSha = createHash("sha256").update(buf).digest("hex");
|
|
146
|
+
const actualSize = buf.length;
|
|
147
|
+
const shaOk = !meta?.sha256 || actualSha === meta.sha256;
|
|
148
|
+
const sizeOk = meta?.size == null || actualSize === meta.size;
|
|
149
|
+
files.push({
|
|
150
|
+
name,
|
|
151
|
+
ok: shaOk && sizeOk,
|
|
152
|
+
reason: shaOk ? (sizeOk ? undefined : "size-mismatch") : "sha256-mismatch",
|
|
153
|
+
expected: { sha256: meta?.sha256 ?? null, size: meta?.size ?? null },
|
|
154
|
+
actual: { sha256: actualSha, size: actualSize }
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
return { ok: files.length > 0 && files.every((f) => f.ok), files };
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Refresh straight from the URLs already recorded in `integrity.json`.
|
|
162
|
+
* Browser-free and independent of WhatsApp's (occasionally-moving) bootloader
|
|
163
|
+
* endpoint — the robust "re-verify / repair the pinned bundle" path.
|
|
164
|
+
*/
|
|
165
|
+
async function fetchFromPinnedManifest() {
|
|
166
|
+
const manifestFile = resolve(RESOURCES_DIR, "integrity.json");
|
|
167
|
+
if (!existsSync(manifestFile)) {
|
|
168
|
+
throw new Error(`pinned mode needs an existing integrity.json at ${manifestFile}`);
|
|
169
|
+
}
|
|
170
|
+
const manifest = JSON.parse(readFileSync(manifestFile, "utf8"));
|
|
171
|
+
const urls = manifest?.urls || {};
|
|
172
|
+
if (!urls.wasm || !urls.worker) {
|
|
173
|
+
throw new Error("integrity.json is missing pinned wasm/worker URLs");
|
|
174
|
+
}
|
|
175
|
+
return {
|
|
176
|
+
source: "pinned-manifest",
|
|
177
|
+
clientRevision: manifest?.clientRevision || null,
|
|
178
|
+
workerUrl: urls.worker,
|
|
179
|
+
wasmUrl: urls.wasm,
|
|
180
|
+
loaderUrl: urls.loader || null,
|
|
181
|
+
loaderCode: null,
|
|
182
|
+
pinnedManifest: manifest
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
async function fetchFromBrowserDebugger() {
|
|
187
|
+
const resp = await fetchOk(DEBUGGER_URL, { headers: {} });
|
|
188
|
+
const targets = await resp.json();
|
|
189
|
+
const page = targets.find(t => t.type === "page" && t.url?.includes("web.whatsapp.com"));
|
|
190
|
+
if (!page?.webSocketDebuggerUrl) throw new Error("No WhatsApp Web page found");
|
|
191
|
+
|
|
192
|
+
const ws = new WebSocket(page.webSocketDebuggerUrl);
|
|
193
|
+
let id = 1;
|
|
194
|
+
const send = (method, params = {}) => new Promise((resolve, reject) => {
|
|
195
|
+
const myId = id++;
|
|
196
|
+
const handler = (event) => {
|
|
197
|
+
const msg = JSON.parse(event.data);
|
|
198
|
+
if (msg.id === myId) {
|
|
199
|
+
ws.removeEventListener("message", handler);
|
|
200
|
+
if (msg.error) reject(new Error(msg.error.message));
|
|
201
|
+
else resolve(msg.result);
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
ws.addEventListener("message", handler);
|
|
205
|
+
ws.send(JSON.stringify({ id: myId, method, params }));
|
|
206
|
+
});
|
|
207
|
+
const evaluate = async (expression) => {
|
|
208
|
+
const result = await send("Runtime.evaluate", { expression, returnByValue: true, awaitPromise: true });
|
|
209
|
+
if (result.exceptionDetails) throw new Error(result.exceptionDetails.text || "eval error");
|
|
210
|
+
return result.result.value;
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
await new Promise(r => ws.addEventListener("open", r));
|
|
214
|
+
|
|
215
|
+
const resourceInfo = await evaluate(`(() => {
|
|
216
|
+
try {
|
|
217
|
+
const resource = require("WAWebVoipWebWasmWorkerResource");
|
|
218
|
+
return {
|
|
219
|
+
workerUrl: resource?.url || null,
|
|
220
|
+
wasmUrl: resource?.hsdp?.bxData?.["${WASM_ID}"]?.uri || null,
|
|
221
|
+
availableWasmIds: Object.keys(resource?.hsdp?.bxData || {}),
|
|
222
|
+
};
|
|
223
|
+
} catch(e) { return { error: e.message }; }
|
|
224
|
+
})()`);
|
|
225
|
+
ws.close();
|
|
226
|
+
|
|
227
|
+
if (resourceInfo.error) throw new Error(`Browser eval failed: ${resourceInfo.error}`);
|
|
228
|
+
if (!resourceInfo.workerUrl) throw new Error("Worker URL not found in browser");
|
|
229
|
+
if (!resourceInfo.wasmUrl) {
|
|
230
|
+
throw new Error(`WASM URL not found for ID ${WASM_ID}; available IDs: ${(resourceInfo.availableWasmIds || []).join(", ")}`);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
return { source: "browser-debugger", ...resourceInfo, loaderUrl: null, loaderCode: null };
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
async function resolveResourceInfo() {
|
|
237
|
+
if (FETCH_MODE === "browser") return await fetchFromBrowserDebugger();
|
|
238
|
+
if (FETCH_MODE === "pinned") return await fetchFromPinnedManifest();
|
|
239
|
+
if (FETCH_MODE === "direct" || FETCH_MODE === "bootloader") return await fetchFromBootloaderEndpoint();
|
|
240
|
+
try {
|
|
241
|
+
return await fetchFromBootloaderEndpoint();
|
|
242
|
+
} catch (directError) {
|
|
243
|
+
console.warn(`Direct bootloader fetch failed: ${directError.message}`);
|
|
244
|
+
// Prefer the browser-free pinned refresh before requiring a running Chrome —
|
|
245
|
+
// WA's bootloader endpoint moves, but the URLs pinned in integrity.json keep
|
|
246
|
+
// serving the exact bundle until the next deliberate revision bump.
|
|
247
|
+
try {
|
|
248
|
+
console.warn("Falling back to pinned-manifest refresh (from integrity.json URLs)...");
|
|
249
|
+
return await fetchFromPinnedManifest();
|
|
250
|
+
} catch (pinnedError) {
|
|
251
|
+
console.warn(`Pinned-manifest refresh failed: ${pinnedError.message}`);
|
|
252
|
+
console.warn("Falling back to Chrome remote-debugging mode...");
|
|
253
|
+
return await fetchFromBrowserDebugger();
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
async function main() {
|
|
259
|
+
const resourceInfo = await resolveResourceInfo();
|
|
260
|
+
console.log("Resource source:", resourceInfo.source);
|
|
261
|
+
if (resourceInfo.clientRevision) console.log("Client revision:", resourceInfo.clientRevision);
|
|
262
|
+
if (resourceInfo.availableWasmIds?.length) console.log("Available WASM IDs:", resourceInfo.availableWasmIds.join(", "));
|
|
263
|
+
|
|
264
|
+
console.log("Fetching worker-modules.js from:", resourceInfo.workerUrl);
|
|
265
|
+
const workerCode = await fetchText(resourceInfo.workerUrl);
|
|
266
|
+
if (!/WAWebVoipWebWasmWorker/.test(workerCode)) {
|
|
267
|
+
throw new Error("fetched worker bundle does not contain WAWebVoipWebWasmWorker — refusing to overwrite");
|
|
268
|
+
}
|
|
269
|
+
writeFileSync(resolve(RESOURCES_DIR, "worker-modules.js"), workerCode);
|
|
270
|
+
console.log(` Written: worker-modules.js (${workerCode.length} bytes)`);
|
|
271
|
+
|
|
272
|
+
let loaderCode = resourceInfo.loaderCode;
|
|
273
|
+
if (resourceInfo.loaderUrl && !loaderCode) {
|
|
274
|
+
console.log("Fetching loader.js from:", resourceInfo.loaderUrl);
|
|
275
|
+
loaderCode = await fetchText(resourceInfo.loaderUrl);
|
|
276
|
+
}
|
|
277
|
+
if (loaderCode) {
|
|
278
|
+
if (!loaderCode.includes(BOOTLOADER_MODULE)) {
|
|
279
|
+
throw new Error(`fetched loader bundle does not contain ${BOOTLOADER_MODULE} — refusing to overwrite`);
|
|
280
|
+
}
|
|
281
|
+
writeFileSync(resolve(RESOURCES_DIR, "loader.js"), loaderCode);
|
|
282
|
+
console.log(` Written: loader.js (${loaderCode.length} bytes)`);
|
|
283
|
+
} else {
|
|
284
|
+
console.log(" loader.js unchanged (browser-debugger mode did not expose a standalone loader URL)");
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
console.log("Fetching whatsapp.wasm from:", resourceInfo.wasmUrl);
|
|
288
|
+
const wasmBuffer = Buffer.from(await (await fetchOk(resourceInfo.wasmUrl)).arrayBuffer());
|
|
289
|
+
if (wasmBuffer.length < 8 || wasmBuffer.readUInt32LE(0) !== 0x6d736100) {
|
|
290
|
+
throw new Error(`fetched whatsapp.wasm is not a valid wasm binary (${wasmBuffer.length} bytes) — refusing to overwrite`);
|
|
291
|
+
}
|
|
292
|
+
writeFileSync(resolve(RESOURCES_DIR, "whatsapp.wasm"), wasmBuffer);
|
|
293
|
+
console.log(` Written: whatsapp.wasm (${wasmBuffer.length} bytes)`);
|
|
294
|
+
|
|
295
|
+
const files = {
|
|
296
|
+
"whatsapp.wasm": { sha256: sha(wasmBuffer), size: wasmBuffer.length },
|
|
297
|
+
"worker-modules.js": { sha256: sha(Buffer.from(workerCode)), size: Buffer.byteLength(workerCode) }
|
|
298
|
+
};
|
|
299
|
+
if (loaderCode) files["loader.js"] = { sha256: sha(Buffer.from(loaderCode)), size: Buffer.byteLength(loaderCode) };
|
|
300
|
+
const manifest = {
|
|
301
|
+
generatedAt: new Date().toISOString(),
|
|
302
|
+
source: resourceInfo.source,
|
|
303
|
+
clientRevision: resourceInfo.clientRevision || null,
|
|
304
|
+
urls: {
|
|
305
|
+
wasm: resourceInfo.wasmUrl,
|
|
306
|
+
worker: resourceInfo.workerUrl,
|
|
307
|
+
loader: resourceInfo.loaderUrl || null
|
|
308
|
+
},
|
|
309
|
+
files
|
|
310
|
+
};
|
|
311
|
+
// When refreshing from the pinned manifest, the whole point is that nothing
|
|
312
|
+
// changed — verify the freshly downloaded bytes still match the pins and shout
|
|
313
|
+
// if the CDN drifted (a deliberate WA revision bump), instead of silently
|
|
314
|
+
// rewriting the manifest to whatever was served.
|
|
315
|
+
if (resourceInfo.pinnedManifest) {
|
|
316
|
+
const downloads = { "whatsapp.wasm": wasmBuffer, "worker-modules.js": Buffer.from(workerCode) };
|
|
317
|
+
if (loaderCode) downloads["loader.js"] = Buffer.from(loaderCode);
|
|
318
|
+
const report = verifyPinnedManifest(resourceInfo.pinnedManifest, downloads);
|
|
319
|
+
for (const f of report.files) {
|
|
320
|
+
console.log(` verify ${f.name}: ${f.ok ? "OK (matches pin)" : `DRIFTED (${f.reason})`}`);
|
|
321
|
+
}
|
|
322
|
+
if (report.ok) {
|
|
323
|
+
console.log(" All pinned assets re-verified byte-for-byte — bundle is current.");
|
|
324
|
+
} else {
|
|
325
|
+
console.warn(" WARNING: live bytes differ from the pins; manifest updated to the newly-fetched values.");
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
writeFileSync(resolve(RESOURCES_DIR, "integrity.json"), JSON.stringify(manifest, null, 2));
|
|
330
|
+
console.log(" Written: integrity.json (pinned sha256 manifest)");
|
|
331
|
+
|
|
332
|
+
console.log("\nDone! Resources updated.");
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// Only run when executed directly (`node scripts/fetch-wasm-resources.mjs`), so
|
|
336
|
+
// the pure helpers above stay importable — e.g. from the offline test suite.
|
|
337
|
+
if (import.meta.url === pathToFileURL(process.argv[1] || "").href) {
|
|
338
|
+
main().catch(e => { console.error("Error:", e.message); process.exit(1); });
|
|
339
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
|
|
5
|
+
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
6
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'));
|
|
7
|
+
const errors = [];
|
|
8
|
+
|
|
9
|
+
if (pkg.version !== '2.6.34') errors.push(`Expected package version 2.6.34, got ${pkg.version}`);
|
|
10
|
+
for (const file of [
|
|
11
|
+
'lib/VoIP/group-call.js',
|
|
12
|
+
'lib/VoIP/signaling.js',
|
|
13
|
+
'lib/VoIP/wasm-engine.js',
|
|
14
|
+
'lib/VoIP/worker-bootstrap.js',
|
|
15
|
+
'lib/VoIP/audio-feeder.js',
|
|
16
|
+
'lib/VoIP/relay-transport.js',
|
|
17
|
+
'lib/VoIP/call-recorder.js',
|
|
18
|
+
'scripts/fetch-wasm-resources.mjs',
|
|
19
|
+
]) {
|
|
20
|
+
if (!fs.existsSync(path.join(root, file))) errors.push(`Missing required file: ${file}`);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (errors.length) {
|
|
24
|
+
for (const error of errors) console.error(`ERROR: ${error}`);
|
|
25
|
+
process.exitCode = 1;
|
|
26
|
+
} else {
|
|
27
|
+
console.log(`Verified ${pkg.name}@${pkg.version}: VoIP/Group Call modules are present.`);
|
|
28
|
+
if (!fs.existsSync(path.join(root, 'lib/assets/wasm/whatsapp.wasm'))) {
|
|
29
|
+
console.warn('WASM assets are not bundled. Run: npm run voip:fetch-wasm');
|
|
30
|
+
}
|
|
31
|
+
}
|