@dyyxyzz/baileys-mod 6.0.48 → 6.0.49

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.
@@ -78,40 +78,36 @@ const makeSocket = (config) => {
78
78
  return sendRawMessage(buff);
79
79
  };
80
80
 
81
- const toLid = async (pn) => {
82
- return pn;
83
- };
81
+ const toLid = async (pn) => {
82
+ return pn;
83
+ };
84
+
85
+ const delay = async (ms) => {
86
+ return new Promise(resolve => setTimeout(resolve, ms));
87
+ };
84
88
 
85
- const delay = async (ms) => {
86
- return new Promise(resolve => setTimeout(resolve, ms));
87
- }
89
+ const toPn = async (pn) => {
90
+ return pn;
91
+ };
88
92
 
89
- const toPn = async (pn) => {
90
- return pn;
91
- };
92
93
  /** log & process any unexpected errors */
93
94
  const onUnexpectedError = (err, msg) => {
94
95
  logger.error({ err }, `unexpected error in '${msg}'`);
95
96
  const message = (err && ((err.stack || err.message) || String(err))).toLowerCase();
96
- // auto recover from cryptographic desyncs by re-uploading prekeys
97
97
  if (message.includes('bad mac') || (message.includes('mac') && message.includes('invalid'))) {
98
98
  try {
99
99
  uploadPreKeysToServerIfRequired(true)
100
100
  .catch(e => logger.warn({ e }, 'failed to re-upload prekeys after bad mac'));
101
101
  }
102
- catch (_e) {
103
- // ignore
104
- }
102
+ catch (_e) {}
105
103
  }
106
- // gently back off when encountering rate limits (429)
107
104
  if (message.includes('429') || message.includes('rate limit')) {
108
105
  const wait = Math.min(30000, (config.backoffDelayMs || 5000));
109
106
  logger.info({ wait }, 'backing off due to rate limit');
110
- setTimeout(() => {
111
- // intentionally empty; wait to delay further sends
112
- }, wait);
107
+ setTimeout(() => {}, wait);
113
108
  }
114
109
  };
110
+
115
111
  /** await the next incoming message */
116
112
  const awaitNextMessage = async (sendMsg) => {
117
113
  if (!ws.isOpen) {
@@ -138,11 +134,7 @@ const toPn = async (pn) => {
138
134
  }
139
135
  return result;
140
136
  };
141
- /**
142
- * Wait for a message with a certain tag to be received
143
- * @param msgId the message tag to await
144
- * @param timeoutMs timeout after which the promise will reject
145
- */
137
+
146
138
  const waitForMessage = async (msgId, timeoutMs = defaultQueryTimeoutMs) => {
147
139
  let onRecv;
148
140
  let onErr;
@@ -153,18 +145,18 @@ const toPn = async (pn) => {
153
145
  reject(err || new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed }));
154
146
  };
155
147
  ws.on(`TAG:${msgId}`, onRecv);
156
- ws.on('close', onErr); // if the socket closes, you'll never receive the message
148
+ ws.on('close', onErr);
157
149
  ws.off('error', onErr);
158
150
  });
159
151
  return result;
160
152
  }
161
153
  finally {
162
154
  ws.off(`TAG:${msgId}`, onRecv);
163
- ws.off('close', onErr); // if the socket closes, you'll never receive the message
155
+ ws.off('close', onErr);
164
156
  ws.off('error', onErr);
165
157
  }
166
158
  };
167
- /** send a query, and wait for its response. auto-generates message ID if not provided */
159
+
168
160
  const query = async (node, timeoutMs) => {
169
161
  if (!node.attrs.id) {
170
162
  node.attrs.id = generateMessageTag();
@@ -179,6 +171,7 @@ const toPn = async (pn) => {
179
171
  }
180
172
  return result;
181
173
  };
174
+
182
175
  /** connection handshake */
183
176
  const validateConnection = async () => {
184
177
  let helloMsg = {
@@ -210,6 +203,7 @@ const toPn = async (pn) => {
210
203
  noise.finishInit();
211
204
  startKeepAliveRequest();
212
205
  };
206
+
213
207
  const getAvailablePreKeysOnServer = async () => {
214
208
  const result = await query({
215
209
  tag: 'iq',
@@ -226,7 +220,7 @@ const toPn = async (pn) => {
226
220
  const countChild = (0, WABinary_1.getBinaryNodeChild)(result, 'count');
227
221
  return +countChild.attrs.value;
228
222
  };
229
- /** generates and uploads a set of pre-keys to the server */
223
+
230
224
  const uploadPreKeys = async (count = Defaults_1.INITIAL_PREKEY_COUNT) => {
231
225
  await keys.transaction(async () => {
232
226
  logger.info({ count }, 'uploading pre-keys');
@@ -236,6 +230,7 @@ const toPn = async (pn) => {
236
230
  logger.info({ count }, 'uploaded pre-keys');
237
231
  });
238
232
  };
233
+
239
234
  const uploadPreKeysToServerIfRequired = async () => {
240
235
  const preKeyCount = await getAvailablePreKeysOnServer();
241
236
  logger.info(`${preKeyCount} pre-keys found on server`);
@@ -243,22 +238,19 @@ const toPn = async (pn) => {
243
238
  await uploadPreKeys();
244
239
  }
245
240
  };
241
+
246
242
  const onMessageReceived = (data) => {
247
243
  noise.decodeFrame(data, frame => {
248
244
  var _a;
249
- // reset ping timeout
250
245
  lastDateRecv = new Date();
251
246
  let anyTriggered = false;
252
247
  anyTriggered = ws.emit('frame', frame);
253
- // if it's a binary node
254
248
  if (!(frame instanceof Uint8Array)) {
255
249
  const msgId = frame.attrs.id;
256
250
  if (logger.level === 'trace') {
257
251
  logger.trace({ xml: (0, WABinary_1.binaryNodeToString)(frame), msg: 'recv xml' });
258
252
  }
259
- /* Check if this is a response to a message we sent */
260
253
  anyTriggered = ws.emit(`${Defaults_1.DEF_TAG_PREFIX}${msgId}`, frame) || anyTriggered;
261
- /* Check if this is a response to a message we are expecting */
262
254
  const l0 = frame.tag;
263
255
  const l1 = frame.attrs || {};
264
256
  const l2 = Array.isArray(frame.content) ? (_a = frame.content[0]) === null || _a === void 0 ? void 0 : _a.tag : '';
@@ -275,6 +267,7 @@ const toPn = async (pn) => {
275
267
  }
276
268
  });
277
269
  };
270
+
278
271
  const end = (error) => {
279
272
  if (closed) {
280
273
  logger.trace({ trace: error === null || error === void 0 ? void 0 : error.stack }, 'connection already closed');
@@ -303,6 +296,7 @@ const toPn = async (pn) => {
303
296
  });
304
297
  ev.removeAllListeners('connection.update');
305
298
  };
299
+
306
300
  const waitForSocketOpen = async () => {
307
301
  if (ws.isOpen) {
308
302
  return;
@@ -325,20 +319,16 @@ const toPn = async (pn) => {
325
319
  ws.off('error', onClose);
326
320
  });
327
321
  };
322
+
328
323
  const startKeepAliveRequest = () => (keepAliveReq = setInterval(() => {
329
324
  if (!lastDateRecv) {
330
325
  lastDateRecv = new Date();
331
326
  }
332
327
  const diff = Date.now() - lastDateRecv.getTime();
333
- /*
334
- check if it's been a suspicious amount of time since the server responded with our last seen
335
- it could be that the network is down
336
- */
337
328
  if (diff > keepAliveIntervalMs + 5000) {
338
329
  end(new boom_1.Boom('Connection was lost', { statusCode: Types_1.DisconnectReason.connectionLost }));
339
330
  }
340
331
  else if (ws.isOpen) {
341
- // if its all good, send a keep alive request
342
332
  query({
343
333
  tag: 'iq',
344
334
  attrs: {
@@ -357,7 +347,7 @@ const toPn = async (pn) => {
357
347
  logger.warn('keep alive called when WS not open');
358
348
  }
359
349
  }, keepAliveIntervalMs));
360
- /** i have no idea why this exists. pls enlighten me */
350
+
361
351
  const sendPassiveIq = (tag) => (query({
362
352
  tag: 'iq',
363
353
  attrs: {
@@ -369,7 +359,7 @@ const toPn = async (pn) => {
369
359
  { tag, attrs: {} }
370
360
  ]
371
361
  }));
372
- /** logout & invalidate connection */
362
+
373
363
  const logout = async (msg) => {
374
364
  var _a;
375
365
  const jid = (_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.id;
@@ -395,7 +385,7 @@ const toPn = async (pn) => {
395
385
  }
396
386
  end(new boom_1.Boom(msg || 'Intentional Logout', { statusCode: Types_1.DisconnectReason.loggedOut }));
397
387
  };
398
-
388
+
399
389
  /** This method was created by snowi, and implemented by KyuuRzy */
400
390
  /** hey bro, if you delete this text */
401
391
  /** you are the most cursed human being who likes to claim other people's property 😹🙌🏻 */
@@ -412,7 +402,13 @@ const toPn = async (pn) => {
412
402
  };
413
403
 
414
404
  ev.emit('creds.update', authState.creds);
415
-
405
+
406
+ // ── FIX: Platform ID 1 = Chrome, dikenali WA sebagai companion browser valid ──
407
+ // Sebelumnya pakai getPlatformId(browser[1]) yang return nilai tidak dikenal
408
+ // untuk string 'Android' sehingga WA tidak mengirimkan push notif pairing ke HP
409
+ const PLATFORM_ID = Buffer.from([1]); // 1 = Chrome/Browser companion
410
+ const PLATFORM_DISPLAY = Buffer.from('Chrome (Linux)', 'utf-8');
411
+
416
412
  await sendNode({
417
413
  tag: 'iq',
418
414
  attrs: {
@@ -443,25 +439,26 @@ const toPn = async (pn) => {
443
439
  {
444
440
  tag: 'companion_platform_id',
445
441
  attrs: {},
446
- content: (0, Utils_1.getPlatformId)(browser[1])
442
+ content: PLATFORM_ID
447
443
  },
448
444
  {
449
445
  tag: 'companion_platform_display',
450
446
  attrs: {},
451
- content: `${browser[1]} (${browser[0]})`
447
+ content: PLATFORM_DISPLAY
452
448
  },
453
449
  {
454
450
  tag: 'link_code_pairing_nonce',
455
451
  attrs: {},
456
- content: "0"
452
+ content: Buffer.from('0', 'utf-8')
457
453
  }
458
454
  ]
459
455
  }
460
456
  ]
461
457
  });
462
-
458
+
463
459
  return authState.creds.pairingCode;
464
- }
460
+ };
461
+
465
462
  async function generatePairingKey() {
466
463
  const salt = (0, crypto_1.randomBytes)(32);
467
464
  const randomIv = (0, crypto_1.randomBytes)(16);
@@ -469,6 +466,7 @@ const toPn = async (pn) => {
469
466
  const ciphered = (0, Utils_1.aesEncryptCTR)(authState.creds.pairingEphemeralKeyPair.public, key, randomIv);
470
467
  return Buffer.concat([salt, randomIv, ciphered]);
471
468
  }
469
+
472
470
  const sendWAMBuffer = (wamBuffer) => {
473
471
  return query({
474
472
  tag: 'iq',
@@ -486,6 +484,7 @@ const toPn = async (pn) => {
486
484
  ]
487
485
  });
488
486
  };
487
+
489
488
  ws.on('message', onMessageReceived);
490
489
  ws.on('open', async () => {
491
490
  try {
@@ -498,9 +497,8 @@ const toPn = async (pn) => {
498
497
  });
499
498
  ws.on('error', mapWebSocketError(end));
500
499
  ws.on('close', () => end(new boom_1.Boom('Connection Terminated', { statusCode: Types_1.DisconnectReason.connectionClosed })));
501
- // the server terminated the connection
502
500
  ws.on('CB:xmlstreamend', () => end(new boom_1.Boom('Connection Terminated by Server', { statusCode: Types_1.DisconnectReason.connectionClosed })));
503
- // QR gen
501
+
504
502
  ws.on('CB:iq,type:set,pair-device', async (stanza) => {
505
503
  const iq = {
506
504
  tag: 'iq',
@@ -516,7 +514,7 @@ const toPn = async (pn) => {
516
514
  const noiseKeyB64 = Buffer.from(creds.noiseKey.public).toString('base64');
517
515
  const identityKeyB64 = Buffer.from(creds.signedIdentityKey.public).toString('base64');
518
516
  const advB64 = creds.advSecretKey;
519
- let qrMs = qrTimeout || 60000; // time to let a QR live
517
+ let qrMs = qrTimeout || 60000;
520
518
  const genPairQR = () => {
521
519
  if (!ws.isOpen) {
522
520
  return;
@@ -530,12 +528,11 @@ const toPn = async (pn) => {
530
528
  const qr = [ref, noiseKeyB64, identityKeyB64, advB64].join(',');
531
529
  ev.emit('connection.update', { qr });
532
530
  qrTimer = setTimeout(genPairQR, qrMs);
533
- qrMs = qrTimeout || 20000; // shorter subsequent qrs
531
+ qrMs = qrTimeout || 20000;
534
532
  };
535
533
  genPairQR();
536
534
  });
537
- // device paired for the first time
538
- // if device pairs successfully, the server asks to restart the connection
535
+
539
536
  ws.on('CB:iq,,pair-success', async (stanza) => {
540
537
  logger.debug('pair success recv');
541
538
  try {
@@ -550,13 +547,13 @@ const toPn = async (pn) => {
550
547
  end(error);
551
548
  }
552
549
  });
553
- // login complete
550
+
554
551
  ws.on('CB:success', async (node) => {
555
552
  try {
556
553
  await uploadPreKeysToServerIfRequired();
557
554
  await sendPassiveIq('active');
558
555
  logger.info('opened connection to WA');
559
- clearTimeout(qrTimer); // will never happen in all likelyhood -- but just in case WA sends success on first try
556
+ clearTimeout(qrTimer);
560
557
  ev.emit('creds.update', { me: { ...authState.creds.me, lid: node.attrs.lid } });
561
558
  ev.emit('connection.update', { connection: 'open' });
562
559
  }
@@ -565,19 +562,22 @@ const toPn = async (pn) => {
565
562
  end(err);
566
563
  }
567
564
  });
565
+
568
566
  ws.on('CB:stream:error', (node) => {
569
567
  logger.error({ node }, 'stream errored out');
570
568
  const { reason, statusCode } = (0, Utils_1.getErrorCodeFromStreamError)(node);
571
569
  end(new boom_1.Boom(`Stream Errored (${reason})`, { statusCode, data: node }));
572
570
  });
573
- // stream fail, possible logout
571
+
574
572
  ws.on('CB:failure', (node) => {
575
573
  const reason = +(node.attrs.reason || 500);
576
574
  end(new boom_1.Boom('Connection Failure', { statusCode: reason, data: node.attrs }));
577
575
  });
576
+
578
577
  ws.on('CB:ib,,downgrade_webclient', () => {
579
578
  end(new boom_1.Boom('Multi-device beta not joined', { statusCode: Types_1.DisconnectReason.multideviceMismatch }));
580
579
  });
580
+
581
581
  ws.on('CB:ib,,offline_preview', (node) => {
582
582
  logger.info('offline preview received', JSON.stringify(node));
583
583
  sendNode({
@@ -586,6 +586,7 @@ const toPn = async (pn) => {
586
586
  content: [{ tag: 'offline_batch', attrs: { count: '100' } }]
587
587
  });
588
588
  });
589
+
589
590
  ws.on('CB:ib,,edge_routing', (node) => {
590
591
  const edgeRoutingNode = (0, WABinary_1.getBinaryNodeChild)(node, 'edge_routing');
591
592
  const routingInfo = (0, WABinary_1.getBinaryNodeChild)(edgeRoutingNode, 'routing_info');
@@ -594,18 +595,17 @@ const toPn = async (pn) => {
594
595
  ev.emit('creds.update', authState.creds);
595
596
  }
596
597
  });
598
+
597
599
  let didStartBuffer = false;
598
600
  process.nextTick(() => {
599
601
  var _a;
600
602
  if ((_a = creds.me) === null || _a === void 0 ? void 0 : _a.id) {
601
- // start buffering important events
602
- // if we're logged in
603
603
  ev.buffer();
604
604
  didStartBuffer = true;
605
605
  }
606
606
  ev.emit('connection.update', { connection: 'connecting', receivedPendingNotifications: false, qr: undefined });
607
607
  });
608
- // called when all offline notifs are handled
608
+
609
609
  ws.on('CB:ib,,offline', (node) => {
610
610
  const child = (0, WABinary_1.getBinaryNodeChild)(node, 'offline');
611
611
  const offlineNotifs = +((child === null || child === void 0 ? void 0 : child.attrs.count) || 0);
@@ -616,11 +616,10 @@ const toPn = async (pn) => {
616
616
  }
617
617
  ev.emit('connection.update', { receivedPendingNotifications: true });
618
618
  });
619
- // update credentials when required
619
+
620
620
  ev.on('creds.update', update => {
621
621
  var _a, _b;
622
622
  const name = (_a = update.me) === null || _a === void 0 ? void 0 : _a.name;
623
- // if name has just been received
624
623
  if (((_b = creds.me) === null || _b === void 0 ? void 0 : _b.name) !== name) {
625
624
  logger.debug({ name }, 'updated pushName');
626
625
  sendNode({
@@ -633,9 +632,11 @@ const toPn = async (pn) => {
633
632
  }
634
633
  Object.assign(creds, update);
635
634
  });
635
+
636
636
  if (printQRInTerminal) {
637
637
  (0, Utils_1.printQRIfNecessaryListener)(ev, logger);
638
638
  }
639
+
639
640
  return {
640
641
  type: 'md',
641
642
  ws,
@@ -663,16 +664,12 @@ const toPn = async (pn) => {
663
664
  uploadPreKeys,
664
665
  uploadPreKeysToServerIfRequired,
665
666
  requestPairingCode,
666
- /** Waits for the connection to WA to reach a state */
667
667
  waitForConnectionUpdate: (0, Utils_1.bindWaitForConnectionUpdate)(ev),
668
668
  sendWAMBuffer,
669
669
  };
670
670
  };
671
671
  exports.makeSocket = makeSocket;
672
- /**
673
- * map the websocket error to the right type
674
- * so it can be retried by the caller
675
- * */
672
+
676
673
  function mapWebSocketError(handler) {
677
674
  return (error) => {
678
675
  handler(new boom_1.Boom(`WebSocket Error (${error === null || error === void 0 ? void 0 : error.message})`, { statusCode: (0, Utils_1.getCodeFromWSError)(error), data: error }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dyyxyzz/baileys-mod",
3
- "version": "6.0.48",
3
+ "version": "6.0.49",
4
4
  "description": "WhatsApp API Modification",
5
5
  "keywords": [
6
6
  "whatsapp",