@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.
- package/lib/Socket/socket.js +105 -74
- package/package.json +1 -1
package/lib/Socket/socket.js
CHANGED
|
@@ -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
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
|
|
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
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
authState.creds.
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
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
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
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
|
|
459
|
-
authState.creds.pairingEphemeralKeyPair =
|
|
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
|
|
494
|
+
if (!authState.creds.pairingCode) {
|
|
464
495
|
throw new Error("Pairing code belum tersedia")
|
|
465
496
|
}
|
|
466
497
|
|