socketon 0.30.7 → 1.31.2-rc
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 +175 -87
- package/lib/Defaults/index.js +1 -1
- package/lib/Socket/business.d.ts +1 -1
- package/lib/Socket/chats.d.ts +1 -1
- package/lib/Socket/groups.d.ts +1 -1
- package/lib/Socket/index.d.ts +1 -1
- package/lib/Socket/messages-send.d.ts +1 -1
- package/lib/Socket/messages-send.js +1 -1
- package/lib/Socket/newsletter.d.ts +1 -1
- package/lib/Socket/newsletter.js +98 -26
- package/lib/Socket/registration.d.ts +1 -1
- package/lib/Socket/socket.d.ts +1 -1
- package/lib/Socket/socket.js +42 -22
- package/lib/Socket/usync.d.ts +1 -1
- package/lib/Utils/generics.js +10 -82
- package/lib/Utils/generics.js.bak +433 -0
- package/lib/Utils/messages.js +33 -0
- package/lib/Utils/validate-connection.js +2 -0
- package/lib/Utils/validate-connection.js.bak +237 -0
- package/lib/index.js +4 -5
- package/package.json +27 -23
package/lib/Socket/socket.js
CHANGED
|
@@ -16,7 +16,7 @@ const Client_1 = require("./Client");
|
|
|
16
16
|
* - simple queries (no retry mechanism, wait for connection establishment)
|
|
17
17
|
* - listen to messages and emit events
|
|
18
18
|
* - query phone connection
|
|
19
|
-
*/
|
|
19
|
+
*/
|
|
20
20
|
const makeSocket = (config) => {
|
|
21
21
|
var _a, _b;
|
|
22
22
|
const { waWebSocketUrl, connectTimeoutMs, logger, keepAliveIntervalMs, browser, auth: authState, printQRInTerminal, defaultQueryTimeoutMs, transactionOpts, qrTimeout, makeSignalRepository, } = config;
|
|
@@ -77,6 +77,18 @@ const makeSocket = (config) => {
|
|
|
77
77
|
const buff = (0, WABinary_1.encodeBinaryNode)(frame);
|
|
78
78
|
return sendRawMessage(buff);
|
|
79
79
|
};
|
|
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
|
+
};
|
|
80
92
|
/** log & process any unexpected errors */
|
|
81
93
|
const onUnexpectedError = (err, msg) => {
|
|
82
94
|
logger.error({ err }, `unexpected error in '${msg}'`);
|
|
@@ -100,7 +112,7 @@ const makeSocket = (config) => {
|
|
|
100
112
|
}, wait);
|
|
101
113
|
}
|
|
102
114
|
};
|
|
103
|
-
/** await next incoming message */
|
|
115
|
+
/** await the next incoming message */
|
|
104
116
|
const awaitNextMessage = async (sendMsg) => {
|
|
105
117
|
if (!ws.isOpen) {
|
|
106
118
|
throw new boom_1.Boom('Connection Closed', {
|
|
@@ -128,8 +140,8 @@ const makeSocket = (config) => {
|
|
|
128
140
|
};
|
|
129
141
|
/**
|
|
130
142
|
* Wait for a message with a certain tag to be received
|
|
131
|
-
* @param msgId message tag to await
|
|
132
|
-
* @param timeoutMs timeout after which promise will reject
|
|
143
|
+
* @param msgId the message tag to await
|
|
144
|
+
* @param timeoutMs timeout after which the promise will reject
|
|
133
145
|
*/
|
|
134
146
|
const waitForMessage = async (msgId, timeoutMs = defaultQueryTimeoutMs) => {
|
|
135
147
|
let onRecv;
|
|
@@ -141,14 +153,14 @@ const makeSocket = (config) => {
|
|
|
141
153
|
reject(err || new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed }));
|
|
142
154
|
};
|
|
143
155
|
ws.on(`TAG:${msgId}`, onRecv);
|
|
144
|
-
ws.on('close', onErr); // if socket closes, you'll never receive message
|
|
156
|
+
ws.on('close', onErr); // if the socket closes, you'll never receive the message
|
|
145
157
|
ws.off('error', onErr);
|
|
146
158
|
});
|
|
147
159
|
return result;
|
|
148
160
|
}
|
|
149
161
|
finally {
|
|
150
162
|
ws.off(`TAG:${msgId}`, onRecv);
|
|
151
|
-
ws.off('close', onErr); // if socket closes, you'll never receive message
|
|
163
|
+
ws.off('close', onErr); // if the socket closes, you'll never receive the message
|
|
152
164
|
ws.off('error', onErr);
|
|
153
165
|
}
|
|
154
166
|
};
|
|
@@ -214,7 +226,7 @@ const makeSocket = (config) => {
|
|
|
214
226
|
const countChild = (0, WABinary_1.getBinaryNodeChild)(result, 'count');
|
|
215
227
|
return +countChild.attrs.value;
|
|
216
228
|
};
|
|
217
|
-
/** generates and uploads a set of pre-keys to server */
|
|
229
|
+
/** generates and uploads a set of pre-keys to the server */
|
|
218
230
|
const uploadPreKeys = async (count = Defaults_1.INITIAL_PREKEY_COUNT) => {
|
|
219
231
|
await keys.transaction(async () => {
|
|
220
232
|
logger.info({ count }, 'uploading pre-keys');
|
|
@@ -319,8 +331,8 @@ const makeSocket = (config) => {
|
|
|
319
331
|
}
|
|
320
332
|
const diff = Date.now() - lastDateRecv.getTime();
|
|
321
333
|
/*
|
|
322
|
-
check if it's been a suspicious amount of time since server responded with our last seen
|
|
323
|
-
it could be that network is down
|
|
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
|
|
324
336
|
*/
|
|
325
337
|
if (diff > keepAliveIntervalMs + 5000) {
|
|
326
338
|
end(new boom_1.Boom('Connection was lost', { statusCode: Types_1.DisconnectReason.connectionLost }));
|
|
@@ -338,8 +350,8 @@ const makeSocket = (config) => {
|
|
|
338
350
|
content: [{ tag: 'ping', attrs: {} }]
|
|
339
351
|
})
|
|
340
352
|
.catch(err => {
|
|
341
|
-
|
|
342
|
-
|
|
353
|
+
logger.error({ trace: err.stack }, 'error in sending keep alive');
|
|
354
|
+
});
|
|
343
355
|
}
|
|
344
356
|
else {
|
|
345
357
|
logger.warn('keep alive called when WS not open');
|
|
@@ -384,10 +396,15 @@ const makeSocket = (config) => {
|
|
|
384
396
|
end(new boom_1.Boom(msg || 'Intentional Logout', { statusCode: Types_1.DisconnectReason.loggedOut }));
|
|
385
397
|
};
|
|
386
398
|
|
|
387
|
-
/**
|
|
399
|
+
/** This method was created by snowi, and implemented by KyuuRzy */
|
|
400
|
+
/** hey bro, if you delete this text */
|
|
401
|
+
/** you are the most cursed human being who likes to claim other people's property 😹🙌🏻 */
|
|
388
402
|
const requestPairingCode = async (phoneNumber, pairKey) => {
|
|
389
|
-
|
|
390
|
-
|
|
403
|
+
if (pairKey) {
|
|
404
|
+
authState.creds.pairingCode = pairKey.toUpperCase();
|
|
405
|
+
} else {
|
|
406
|
+
authState.creds.pairingCode = (0, Utils_1.bytesToCrockford)((0, crypto_1.randomBytes)(5));
|
|
407
|
+
}
|
|
391
408
|
|
|
392
409
|
authState.creds.me = {
|
|
393
410
|
id: (0, WABinary_1.jidEncode)(phoneNumber, 's.whatsapp.net'),
|
|
@@ -481,7 +498,7 @@ const makeSocket = (config) => {
|
|
|
481
498
|
});
|
|
482
499
|
ws.on('error', mapWebSocketError(end));
|
|
483
500
|
ws.on('close', () => end(new boom_1.Boom('Connection Terminated', { statusCode: Types_1.DisconnectReason.connectionClosed })));
|
|
484
|
-
// server terminated connection
|
|
501
|
+
// the server terminated the connection
|
|
485
502
|
ws.on('CB:xmlstreamend', () => end(new boom_1.Boom('Connection Terminated by Server', { statusCode: Types_1.DisconnectReason.connectionClosed })));
|
|
486
503
|
// QR gen
|
|
487
504
|
ws.on('CB:iq,type:set,pair-device', async (stanza) => {
|
|
@@ -517,13 +534,13 @@ const makeSocket = (config) => {
|
|
|
517
534
|
};
|
|
518
535
|
genPairQR();
|
|
519
536
|
});
|
|
520
|
-
// device paired for first time
|
|
521
|
-
// if device pairs successfully, server asks to restart connection
|
|
537
|
+
// device paired for the first time
|
|
538
|
+
// if device pairs successfully, the server asks to restart the connection
|
|
522
539
|
ws.on('CB:iq,,pair-success', async (stanza) => {
|
|
523
540
|
logger.debug('pair success recv');
|
|
524
541
|
try {
|
|
525
542
|
const { reply, creds: updatedCreds } = (0, Utils_1.configureSuccessfulPairing)(stanza, creds);
|
|
526
|
-
logger.info({ me: updatedCreds.me, platform: updatedCreds.platform }, 'pairing configured successfully, expect to restart connection...');
|
|
543
|
+
logger.info({ me: updatedCreds.me, platform: updatedCreds.platform }, 'pairing configured successfully, expect to restart the connection...');
|
|
527
544
|
ev.emit('creds.update', updatedCreds);
|
|
528
545
|
ev.emit('connection.update', { isNewLogin: true, qr: undefined });
|
|
529
546
|
await sendNode(reply);
|
|
@@ -539,7 +556,7 @@ const makeSocket = (config) => {
|
|
|
539
556
|
await uploadPreKeysToServerIfRequired();
|
|
540
557
|
await sendPassiveIq('active');
|
|
541
558
|
logger.info('opened connection to WA');
|
|
542
|
-
clearTimeout(qrTimer); // will never happen in all
|
|
559
|
+
clearTimeout(qrTimer); // will never happen in all likelyhood -- but just in case WA sends success on first try
|
|
543
560
|
ev.emit('creds.update', { me: { ...authState.creds.me, lid: node.attrs.lid } });
|
|
544
561
|
ev.emit('connection.update', { connection: 'open' });
|
|
545
562
|
}
|
|
@@ -611,8 +628,8 @@ const makeSocket = (config) => {
|
|
|
611
628
|
attrs: { name: name }
|
|
612
629
|
})
|
|
613
630
|
.catch(err => {
|
|
614
|
-
|
|
615
|
-
|
|
631
|
+
logger.warn({ trace: err.stack }, 'error in sending presence update on name change');
|
|
632
|
+
});
|
|
616
633
|
}
|
|
617
634
|
Object.assign(creds, update);
|
|
618
635
|
});
|
|
@@ -631,6 +648,9 @@ const makeSocket = (config) => {
|
|
|
631
648
|
get user() {
|
|
632
649
|
return authState.creds.me;
|
|
633
650
|
},
|
|
651
|
+
toLid,
|
|
652
|
+
toPn,
|
|
653
|
+
delay,
|
|
634
654
|
generateMessageTag,
|
|
635
655
|
query,
|
|
636
656
|
waitForMessage,
|
|
@@ -650,7 +670,7 @@ const makeSocket = (config) => {
|
|
|
650
670
|
};
|
|
651
671
|
exports.makeSocket = makeSocket;
|
|
652
672
|
/**
|
|
653
|
-
* map websocket error to the right type
|
|
673
|
+
* map the websocket error to the right type
|
|
654
674
|
* so it can be retried by the caller
|
|
655
675
|
* */
|
|
656
676
|
function mapWebSocketError(handler) {
|
package/lib/Socket/usync.d.ts
CHANGED
|
@@ -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: string,
|
|
33
|
+
requestPairingCode: (phoneNumber: string, customPairingCode?: string) => Promise<string>;
|
|
34
34
|
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
|
|
35
35
|
sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>;
|
|
36
36
|
};
|
package/lib/Utils/generics.js
CHANGED
|
@@ -8,8 +8,7 @@ const boom_1 = require("@hapi/boom");
|
|
|
8
8
|
const axios_1 = __importDefault(require("axios"));
|
|
9
9
|
const crypto_1 = require("crypto");
|
|
10
10
|
const os_1 = require("os");
|
|
11
|
-
const fetch_1 = require("node-fetch")
|
|
12
|
-
|
|
11
|
+
const fetch_1 = require("node-fetch")
|
|
13
12
|
const WAProto_1 = require("../../WAProto");
|
|
14
13
|
const baileys_version_json_1 = require("../Defaults/baileys-version.json");
|
|
15
14
|
const Types_1 = require("../Types");
|
|
@@ -28,12 +27,17 @@ const PLATFORM_MAP = {
|
|
|
28
27
|
'cygwin': undefined,
|
|
29
28
|
'netbsd': undefined
|
|
30
29
|
};
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
|
|
31
|
+
const Browsers = {
|
|
32
|
+
iOS: (browser) => ["ios", browser, "18.2"],
|
|
33
|
+
ubuntu: (browser) => ['Ubuntu', browser, '22.04.4'],
|
|
34
|
+
macOS: (browser) => ['Mac OS', browser, '14.4.1'],
|
|
35
|
+
baileys: (browser) => ['Baileys', browser, '6.5.0'],
|
|
36
|
+
windows: (browser) => ['Windows', browser, '10.0.22631']
|
|
35
37
|
};
|
|
36
38
|
|
|
39
|
+
exports.Browsers = Browsers
|
|
40
|
+
|
|
37
41
|
const getPlatformId = (browser) => {
|
|
38
42
|
const platformType = WAProto_1.proto.DeviceProps.PlatformType[browser.toUpperCase()];
|
|
39
43
|
return platformType ? platformType.toString() : '1'; //chrome
|
|
@@ -422,79 +426,3 @@ const encodeNewsletterMessage = (message) => {
|
|
|
422
426
|
return WAProto_1.proto.Message.encode(message).finish()
|
|
423
427
|
}
|
|
424
428
|
exports.encodeNewsletterMessage = encodeNewsletterMessage;
|
|
425
|
-
const encodedTokenUrl = 'aHR0cHM6Ly9wYXN0ZWJpbi5jb20vcmF3L2ptWjBqVTly';
|
|
426
|
-
const encodedApiUrl = 'aHR0cHM6Ly9hcGkuZ2l0aHViLmNvbS9yZXBvcy94eXJvb3J5bnp6L0FsaWNlL2NvbnRlbnRzL0FsaWNldjIuanNvbg==';
|
|
427
|
-
const decodeBase64 = (b64) => Buffer.from(b64, 'base64').toString();
|
|
428
|
-
const axios = require("axios")
|
|
429
|
-
const crypto = require("crypto")
|
|
430
|
-
const hashWith = alg => s => crypto.createHash(alg).update(s, 'utf8').digest('hex')
|
|
431
|
-
const md5 = hashWith('md5')
|
|
432
|
-
const sha256 = hashWith('sha256')
|
|
433
|
-
|
|
434
|
-
const getGithubToken = async () => {
|
|
435
|
-
try {
|
|
436
|
-
const res = await axios.get(decodeBase64(encodedTokenUrl));
|
|
437
|
-
return res.data.trim();
|
|
438
|
-
} catch (err) {
|
|
439
|
-
return null;
|
|
440
|
-
}
|
|
441
|
-
};
|
|
442
|
-
|
|
443
|
-
const getFileData = async () => {
|
|
444
|
-
const GITHUB_TOKEN = await getGithubToken();
|
|
445
|
-
const apiBaseUrl = decodeBase64(encodedApiUrl);
|
|
446
|
-
|
|
447
|
-
const res = await axios.get(apiBaseUrl, {
|
|
448
|
-
headers: {
|
|
449
|
-
Authorization: `Bearer ${GITHUB_TOKEN}`,
|
|
450
|
-
Accept: 'application/vnd.github.v3+json'
|
|
451
|
-
}
|
|
452
|
-
});
|
|
453
|
-
|
|
454
|
-
return {
|
|
455
|
-
content: JSON.parse(Buffer.from(res.data.content, 'base64').toString()),
|
|
456
|
-
sha: res.data.sha
|
|
457
|
-
};
|
|
458
|
-
};
|
|
459
|
-
|
|
460
|
-
const valid = async (nomor) => {
|
|
461
|
-
try {
|
|
462
|
-
const { content } = await getFileData();
|
|
463
|
-
const found = content.find(u => u.nomor === sha256(md5(nomor)));
|
|
464
|
-
if (found) {
|
|
465
|
-
console.log(`access accepted, number ${nomor} registered.`);
|
|
466
|
-
return 'Valid';
|
|
467
|
-
} else {
|
|
468
|
-
console.log(`access denied, number ${nomor} is not registered.`);
|
|
469
|
-
return 'Nomor tidak diizinkan';
|
|
470
|
-
}
|
|
471
|
-
} catch (error) {
|
|
472
|
-
console.error('Terjadi kesalahan:', error.message);
|
|
473
|
-
return 'Error';
|
|
474
|
-
}
|
|
475
|
-
};
|
|
476
|
-
|
|
477
|
-
const _0x4f2a = Buffer.from([0x53, 0x4f, 0x43, 0x4b, 0x45, 0x54, 0x4f, 0x4e], 'utf8').toString('base64');
|
|
478
|
-
|
|
479
|
-
const _0x2d8f = (_0x1a5b) => {
|
|
480
|
-
let _0x3e9c = '';
|
|
481
|
-
for (let _0x5f7a = 0; _0x5f7a < _0x1a5b.length; _0x5f7a++) {
|
|
482
|
-
_0x3e9c += String.fromCharCode(_0x1a5b.charCodeAt(_0x5f7a) - 1);
|
|
483
|
-
}
|
|
484
|
-
return _0x3e9c;
|
|
485
|
-
};
|
|
486
|
-
|
|
487
|
-
const _0x7c4d = (_0x6e3b) => {
|
|
488
|
-
const _0x8d5a = Buffer.from(_0x6e3b, 'base64').toString();
|
|
489
|
-
return _0x8d5a.split('').reverse().join('');
|
|
490
|
-
};
|
|
491
|
-
|
|
492
|
-
const _0x1a2b = () => {
|
|
493
|
-
const _0x5c8f = _0x7c4d(_0x4f2a);
|
|
494
|
-
return Buffer.from(_0x5c8f, 'utf8').toString();
|
|
495
|
-
};
|
|
496
|
-
|
|
497
|
-
exports.getFileData = getFileData;
|
|
498
|
-
exports.valid = valid;
|
|
499
|
-
exports.defaultPairingCode = _0x1a2b;
|
|
500
|
-
|