@rexxhayanasi/elaina-baileys 1.1.0-rc.2 → 1.1.0-rc.4

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.
Files changed (2) hide show
  1. package/lib/Socket/socket.js +105 -74
  2. package/package.json +1 -1
@@ -40,6 +40,19 @@ const makeSocket = (config) => {
40
40
  routingInfo: (_b = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _b === void 0 ? void 0 : _b.routingInfo
41
41
  });
42
42
  const { creds } = authState;
43
+ if (!creds.noiseKey?.public) {
44
+ creds.noiseKey = Utils_1.Curve.generateKeyPair()
45
+ }
46
+
47
+ if (!creds.signedIdentityKey?.public) {
48
+ creds.signedIdentityKey = Utils_1.Curve.generateKeyPair()
49
+ }
50
+
51
+ if (!creds.advSecretKey) {
52
+ creds.advSecretKey = (0, crypto_1.randomBytes)(32).toString('base64')
53
+ }
54
+
55
+ ev.emit('creds.update', creds)
43
56
  // add transaction capability
44
57
  const keys = (0, Utils_1.addTransactionCapability)(authState.keys, logger, transactionOpts);
45
58
  const signalRepository = makeSignalRepository({ creds, keys });
@@ -53,20 +66,26 @@ const makeSocket = (config) => {
53
66
  const sendPromise = (0, util_1.promisify)(ws.send);
54
67
  /** send a raw buffer */
55
68
  const sendRawMessage = async (data) => {
56
- if (!ws.isOpen) {
57
- throw new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed });
58
- }
59
- const bytes = noise.encodeFrame(data);
60
- await (0, Utils_1.promiseTimeout)(connectTimeoutMs, async (resolve, reject) => {
69
+ if (!ws || ws.isClosed || ws.isClosing || !ws.isOpen) {
70
+ throw new boom_1.Boom('Connection Closed', {
71
+ statusCode: Types_1.DisconnectReason.connectionClosed
72
+ })
73
+ }
74
+
75
+ const bytes = noise.encodeFrame(data)
76
+
77
+ await (0, Utils_1.promiseTimeout)(
78
+ connectTimeoutMs,
79
+ async (resolve, reject) => {
61
80
  try {
62
- await sendPromise.call(ws, bytes);
63
- resolve();
64
- }
65
- catch (error) {
66
- reject(error);
81
+ await sendPromise.call(ws, bytes)
82
+ resolve()
83
+ } catch (error) {
84
+ reject(error)
67
85
  }
68
- });
69
- };
86
+ }
87
+ )
88
+ };
70
89
  /** send a binary node */
71
90
  const sendNode = (frame) => {
72
91
  if (logger.level === 'trace') {
@@ -394,73 +413,85 @@ const end = (error) => {
394
413
  end(new boom_1.Boom(msg || 'Intentional Logout', { statusCode: Types_1.DisconnectReason.loggedOut }));
395
414
  };
396
415
  const requestPairingCode = async (phoneNumber, pairKey = "ELAINAMD") => {
397
- if (pairKey) {
398
- authState.creds.pairingCode = pairKey.toUpperCase();
399
- }
400
- else {
401
- authState.creds.pairingCode = (0, Utils_1.bytesToCrockford)((0, crypto_1.randomBytes)(5));
402
- }
403
- authState.creds.me = {
404
- id: (0, WABinary_1.jidEncode)(phoneNumber, 's.whatsapp.net'),
405
- name: '~'
406
- };
407
- ev.emit('creds.update', authState.creds);
408
- await sendNode({
409
- tag: 'iq',
410
- attrs: {
411
- to: WABinary_1.S_WHATSAPP_NET,
412
- type: 'set',
413
- id: generateMessageTag(),
414
- xmlns: 'md'
415
- },
416
- content: [
417
- {
418
- tag: 'link_code_companion_reg',
419
- attrs: {
420
- jid: authState.creds.me.id,
421
- stage: 'companion_hello',
422
- // eslint-disable-next-line camelcase
423
- should_show_push_notification: 'true'
416
+ if (!authState.creds.noiseKey?.public) {
417
+ authState.creds.noiseKey = Utils_1.Curve.generateKeyPair()
418
+ ev.emit('creds.update', authState.creds)
419
+ }
420
+
421
+ if (!authState.creds.pairingEphemeralKeyPair?.public) {
422
+ authState.creds.pairingEphemeralKeyPair = Utils_1.Curve.generateKeyPair()
423
+ ev.emit('creds.update', authState.creds)
424
+ }
425
+
426
+ if (pairKey) {
427
+ authState.creds.pairingCode = pairKey.toUpperCase()
428
+ } else {
429
+ authState.creds.pairingCode = (0, Utils_1.bytesToCrockford)((0, crypto_1.randomBytes)(5))
430
+ }
431
+
432
+ authState.creds.me = {
433
+ id: (0, WABinary_1.jidEncode)(phoneNumber, 's.whatsapp.net'),
434
+ name: '~'
435
+ }
436
+
437
+ ev.emit('creds.update', authState.creds)
438
+
439
+ await sendNode({
440
+ tag: 'iq',
441
+ attrs: {
442
+ to: WABinary_1.S_WHATSAPP_NET,
443
+ type: 'set',
444
+ id: generateMessageTag(),
445
+ xmlns: 'md'
446
+ },
447
+ content: [
448
+ {
449
+ tag: 'link_code_companion_reg',
450
+ attrs: {
451
+ jid: authState.creds.me.id,
452
+ stage: 'companion_hello',
453
+ should_show_push_notification: 'true'
454
+ },
455
+ content: [
456
+ {
457
+ tag: 'link_code_pairing_wrapped_companion_ephemeral_pub',
458
+ attrs: {},
459
+ content: await generatePairingKey()
424
460
  },
425
- content: [
426
- {
427
- tag: 'link_code_pairing_wrapped_companion_ephemeral_pub',
428
- attrs: {},
429
- content: await generatePairingKey()
430
- },
431
- {
432
- tag: 'companion_server_auth_key_pub',
433
- attrs: {},
434
- content: authState.creds.noiseKey.public
435
- },
436
- {
437
- tag: 'companion_platform_id',
438
- attrs: {},
439
- content: (0, Utils_1.getPlatformId)(browser[1])
440
- },
441
- {
442
- tag: 'companion_platform_display',
443
- attrs: {},
444
- content: `${browser[1]} (${browser[0]})`
445
- },
446
- {
447
- tag: 'link_code_pairing_nonce',
448
- attrs: {},
449
- content: '0'
450
- }
451
- ]
452
- }
453
- ]
454
- });
455
- return authState.creds.pairingCode;
456
- };
461
+ {
462
+ tag: 'companion_server_auth_key_pub',
463
+ attrs: {},
464
+ content: authState.creds.noiseKey.public
465
+ },
466
+ {
467
+ tag: 'companion_platform_id',
468
+ attrs: {},
469
+ content: (0, Utils_1.getPlatformId)(browser[1])
470
+ },
471
+ {
472
+ tag: 'companion_platform_display',
473
+ attrs: {},
474
+ content: `${browser[1]} (${browser[0]})`
475
+ },
476
+ {
477
+ tag: 'link_code_pairing_nonce',
478
+ attrs: {},
479
+ content: '0'
480
+ }
481
+ ]
482
+ }
483
+ ]
484
+ })
485
+
486
+ return authState.creds.pairingCode
487
+ }
457
488
  async function generatePairingKey() {
458
- if (!authState?.creds?.pairingEphemeralKeyPair) {
459
- authState.creds.pairingEphemeralKeyPair = require("../Utils").Curve.generateKeyPair()
489
+ if (!authState.creds.pairingEphemeralKeyPair?.public) {
490
+ authState.creds.pairingEphemeralKeyPair = Utils_1.Curve.generateKeyPair()
460
491
  ev.emit('creds.update', authState.creds)
461
492
  }
462
493
 
463
- if (!authState?.creds?.pairingCode) {
494
+ if (!authState.creds.pairingCode) {
464
495
  throw new Error("Pairing code belum tersedia")
465
496
  }
466
497
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rexxhayanasi/elaina-baileys",
3
- "version": "1.1.0-rc.2",
3
+ "version": "1.1.0-rc.4",
4
4
  "description": "Custom Baileys WhatsApp API",
5
5
  "keywords": [
6
6
  "baileys",