@baileys-md/baileys 11.2.4 → 12.0.1
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/LICENSE +1 -1
- package/WAProto/WAProto.proto +5311 -0
- package/WAProto/index.js +70084 -131686
- package/lib/Defaults/index.js +118 -117
- package/lib/KeyDB/BinarySearch.js +20 -0
- package/lib/KeyDB/KeyedDB.js +167 -0
- package/lib/KeyDB/index.js +4 -0
- package/lib/Signal/Group/ciphertext-message.js +13 -0
- package/lib/Signal/Group/group-session-builder.js +32 -0
- package/lib/Signal/Group/group_cipher.js +84 -0
- package/lib/Signal/Group/index.js +13 -0
- package/lib/Signal/Group/keyhelper.js +20 -0
- package/lib/Signal/Group/sender-chain-key.js +28 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +65 -0
- package/lib/Signal/Group/sender-key-message.js +68 -0
- package/{WASignalGroup/sender_key_name.js → lib/Signal/Group/sender-key-name.js} +10 -28
- package/lib/Signal/Group/sender-key-record.js +43 -0
- package/lib/Signal/Group/sender-key-state.js +86 -0
- package/lib/Signal/Group/sender-message-key.js +28 -0
- package/lib/Signal/libsignal.js +314 -151
- package/lib/Signal/lid-mapping.js +155 -0
- package/lib/Socket/Client/index.js +4 -19
- package/lib/Socket/Client/types.js +13 -0
- package/lib/Socket/Client/websocket.js +52 -0
- package/lib/Socket/business.js +359 -242
- package/lib/Socket/chats.js +847 -844
- package/lib/Socket/communities.js +413 -0
- package/lib/Socket/groups.js +304 -319
- package/lib/Socket/index.js +15 -9
- package/lib/Socket/messages-recv.js +1109 -989
- package/lib/Socket/messages-send.js +611 -347
- package/lib/Socket/mex.js +45 -0
- package/lib/Socket/newsletter.js +230 -231
- package/lib/Socket/socket.js +795 -616
- package/lib/Store/index.js +6 -8
- package/lib/Store/make-cache-manager-store.js +73 -81
- package/lib/Store/make-in-memory-store.js +286 -427
- package/lib/Store/make-ordered-dictionary.js +77 -79
- package/lib/Store/object-repository.js +24 -26
- package/lib/Types/Auth.js +3 -2
- package/lib/Types/Bussines.js +3 -0
- package/lib/Types/Call.js +3 -2
- package/lib/Types/Chat.js +9 -4
- package/lib/Types/Contact.js +3 -2
- package/lib/Types/Events.js +3 -2
- package/lib/Types/GroupMetadata.js +3 -2
- package/lib/Types/Label.js +24 -26
- package/lib/Types/LabelAssociation.js +6 -8
- package/lib/Types/Message.js +12 -7
- package/lib/Types/Newsletter.js +32 -17
- package/lib/Types/Product.js +3 -2
- package/lib/Types/Signal.js +3 -2
- package/lib/Types/Socket.js +4 -2
- package/lib/Types/State.js +11 -2
- package/lib/Types/USync.js +3 -2
- package/lib/Types/index.js +27 -41
- package/lib/Utils/auth-utils.js +211 -198
- package/lib/Utils/baileys-event-stream.js +42 -61
- package/lib/Utils/browser-utils.js +25 -0
- package/lib/Utils/business.js +213 -214
- package/lib/Utils/chat-utils.js +711 -689
- package/lib/Utils/crypto.js +112 -133
- package/lib/Utils/decode-wa-message.js +254 -186
- package/lib/Utils/event-buffer.js +510 -502
- package/lib/Utils/generics.js +318 -408
- package/lib/Utils/history.js +83 -90
- package/lib/Utils/index.js +21 -33
- package/lib/Utils/link-preview.js +71 -116
- package/lib/Utils/logger.js +5 -7
- package/lib/Utils/lt-hash.js +40 -46
- package/lib/Utils/make-mutex.js +34 -41
- package/lib/Utils/message-retry-manager.js +113 -0
- package/lib/Utils/messages-media.js +575 -671
- package/lib/Utils/messages.js +354 -462
- package/lib/Utils/noise-handler.js +138 -149
- package/lib/Utils/pre-key-manager.js +85 -0
- package/lib/Utils/process-message.js +323 -354
- package/lib/Utils/signal.js +148 -130
- package/lib/Utils/use-multi-file-auth-state.js +109 -91
- package/lib/Utils/validate-connection.js +183 -190
- package/lib/WABinary/constants.js +1298 -35
- package/lib/WABinary/decode.js +231 -256
- package/lib/WABinary/encode.js +207 -239
- package/lib/WABinary/generic-utils.js +119 -40
- package/lib/WABinary/index.js +7 -21
- package/lib/WABinary/jid-utils.js +88 -64
- package/lib/WABinary/types.js +3 -2
- package/lib/WAM/BinaryInfo.js +10 -12
- package/lib/WAM/constants.js +22851 -15348
- package/lib/WAM/encode.js +135 -136
- package/lib/WAM/index.js +5 -19
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +28 -30
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +49 -53
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +27 -28
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +36 -39
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -50
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +26 -20
- package/lib/WAUSync/Protocols/index.js +6 -20
- package/lib/WAUSync/USyncQuery.js +86 -85
- package/lib/WAUSync/USyncUser.js +23 -25
- package/lib/WAUSync/index.js +5 -19
- package/lib/index.js +18 -33
- package/package.json +52 -57
- package/README.md +0 -2
- package/WASignalGroup/GroupProtocol.js +0 -1697
- package/WASignalGroup/ciphertext_message.js +0 -16
- package/WASignalGroup/group_cipher.js +0 -120
- package/WASignalGroup/group_session_builder.js +0 -46
- package/WASignalGroup/index.js +0 -5
- package/WASignalGroup/keyhelper.js +0 -21
- package/WASignalGroup/protobufs.js +0 -3
- package/WASignalGroup/queue_job.js +0 -69
- package/WASignalGroup/sender_chain_key.js +0 -50
- package/WASignalGroup/sender_key_distribution_message.js +0 -78
- package/WASignalGroup/sender_key_message.js +0 -92
- package/WASignalGroup/sender_key_record.js +0 -56
- package/WASignalGroup/sender_key_state.js +0 -129
- package/WASignalGroup/sender_message_key.js +0 -39
- package/lib/Defaults/baileys-version.json +0 -3
- package/lib/Defaults/phonenumber-mcc.json +0 -223
- package/lib/Socket/Client/abstract-socket-client.js +0 -13
- package/lib/Socket/Client/mobile-socket-client.js +0 -65
- package/lib/Socket/Client/web-socket-client.js +0 -62
- package/lib/Socket/registration.js +0 -166
- package/lib/Socket/usync.js +0 -70
- package/lib/Store/make-mongo-store.js +0 -567
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
const { deriveSecrets } = require('libsignal/src/crypto');
|
|
2
|
-
class SenderMessageKey {
|
|
3
|
-
iteration = 0;
|
|
4
|
-
|
|
5
|
-
iv = Buffer.alloc(0);
|
|
6
|
-
|
|
7
|
-
cipherKey = Buffer.alloc(0);
|
|
8
|
-
|
|
9
|
-
seed = Buffer.alloc(0);
|
|
10
|
-
|
|
11
|
-
constructor(iteration, seed) {
|
|
12
|
-
const derivative = deriveSecrets(seed, Buffer.alloc(32), Buffer.from('WhisperGroup'));
|
|
13
|
-
const keys = new Uint8Array(32);
|
|
14
|
-
keys.set(new Uint8Array(derivative[0].slice(16)));
|
|
15
|
-
keys.set(new Uint8Array(derivative[1].slice(0, 16)), 16);
|
|
16
|
-
this.iv = Buffer.from(derivative[0].slice(0, 16));
|
|
17
|
-
this.cipherKey = Buffer.from(keys.buffer);
|
|
18
|
-
|
|
19
|
-
this.iteration = iteration;
|
|
20
|
-
this.seed = seed;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
getIteration() {
|
|
24
|
-
return this.iteration;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
getIv() {
|
|
28
|
-
return this.iv;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
getCipherKey() {
|
|
32
|
-
return this.cipherKey;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
getSeed() {
|
|
36
|
-
return this.seed;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
module.exports = SenderMessageKey;
|
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"93": 412,
|
|
3
|
-
"355": 276,
|
|
4
|
-
"213": 603,
|
|
5
|
-
"1-684": 544,
|
|
6
|
-
"376": 213,
|
|
7
|
-
"244": 631,
|
|
8
|
-
"1-264": 365,
|
|
9
|
-
"1-268": 344,
|
|
10
|
-
"54": 722,
|
|
11
|
-
"374": 283,
|
|
12
|
-
"297": 363,
|
|
13
|
-
"61": 505,
|
|
14
|
-
"43": 232,
|
|
15
|
-
"994": 400,
|
|
16
|
-
"1-242": 364,
|
|
17
|
-
"973": 426,
|
|
18
|
-
"880": 470,
|
|
19
|
-
"1-246": 342,
|
|
20
|
-
"375": 257,
|
|
21
|
-
"32": 206,
|
|
22
|
-
"501": 702,
|
|
23
|
-
"229": 616,
|
|
24
|
-
"1-441": 350,
|
|
25
|
-
"975": 402,
|
|
26
|
-
"591": 736,
|
|
27
|
-
"387": 218,
|
|
28
|
-
"267": 652,
|
|
29
|
-
"55": 724,
|
|
30
|
-
"1-284": 348,
|
|
31
|
-
"673": 528,
|
|
32
|
-
"359": 284,
|
|
33
|
-
"226": 613,
|
|
34
|
-
"257": 642,
|
|
35
|
-
"855": 456,
|
|
36
|
-
"237": 624,
|
|
37
|
-
"238": 625,
|
|
38
|
-
"1-345": 346,
|
|
39
|
-
"236": 623,
|
|
40
|
-
"235": 622,
|
|
41
|
-
"56": 730,
|
|
42
|
-
"86": 454,
|
|
43
|
-
"57": 732,
|
|
44
|
-
"269": 654,
|
|
45
|
-
"682": 548,
|
|
46
|
-
"506": 712,
|
|
47
|
-
"385": 219,
|
|
48
|
-
"53": 368,
|
|
49
|
-
"357": 280,
|
|
50
|
-
"420": 230,
|
|
51
|
-
"243": 630,
|
|
52
|
-
"45": 238,
|
|
53
|
-
"253": 638,
|
|
54
|
-
"1-767": 366,
|
|
55
|
-
"1-809": 370,
|
|
56
|
-
"1-849": 370,
|
|
57
|
-
"1-829": 370,
|
|
58
|
-
"593": 740,
|
|
59
|
-
"20": 602,
|
|
60
|
-
"503": 706,
|
|
61
|
-
"240": 627,
|
|
62
|
-
"291": 657,
|
|
63
|
-
"372": 248,
|
|
64
|
-
"251": 636,
|
|
65
|
-
"500": 750,
|
|
66
|
-
"298": 288,
|
|
67
|
-
"679": 542,
|
|
68
|
-
"358": 244,
|
|
69
|
-
"33": 208,
|
|
70
|
-
"689": 547,
|
|
71
|
-
"241": 628,
|
|
72
|
-
"220": 607,
|
|
73
|
-
"995": 282,
|
|
74
|
-
"49": 262,
|
|
75
|
-
"233": 620,
|
|
76
|
-
"350": 266,
|
|
77
|
-
"30": 202,
|
|
78
|
-
"299": 290,
|
|
79
|
-
"1-473": 352,
|
|
80
|
-
"1-671": 535,
|
|
81
|
-
"502": 704,
|
|
82
|
-
"224": 537,
|
|
83
|
-
"592": 738,
|
|
84
|
-
"509": 372,
|
|
85
|
-
"504": 708,
|
|
86
|
-
"852": 454,
|
|
87
|
-
"36": 216,
|
|
88
|
-
"354": 274,
|
|
89
|
-
"91": 404,
|
|
90
|
-
"62": 510,
|
|
91
|
-
"98": 432,
|
|
92
|
-
"964": 418,
|
|
93
|
-
"353": 234,
|
|
94
|
-
"972": 425,
|
|
95
|
-
"39": 222,
|
|
96
|
-
"225": 612,
|
|
97
|
-
"1-876": 338,
|
|
98
|
-
"81": 440,
|
|
99
|
-
"962": 416,
|
|
100
|
-
"254": 639,
|
|
101
|
-
"686": 545,
|
|
102
|
-
"383": 221,
|
|
103
|
-
"965": 419,
|
|
104
|
-
"371": 247,
|
|
105
|
-
"961": 415,
|
|
106
|
-
"266": 651,
|
|
107
|
-
"231": 618,
|
|
108
|
-
"218": 606,
|
|
109
|
-
"423": 295,
|
|
110
|
-
"370": 246,
|
|
111
|
-
"352": 270,
|
|
112
|
-
"389": 294,
|
|
113
|
-
"261": 646,
|
|
114
|
-
"265": 650,
|
|
115
|
-
"60": 502,
|
|
116
|
-
"960": 472,
|
|
117
|
-
"223": 610,
|
|
118
|
-
"356": 278,
|
|
119
|
-
"692": 551,
|
|
120
|
-
"222": 609,
|
|
121
|
-
"230": 617,
|
|
122
|
-
"52": 334,
|
|
123
|
-
"691": 550,
|
|
124
|
-
"373": 259,
|
|
125
|
-
"377": 212,
|
|
126
|
-
"976": 428,
|
|
127
|
-
"382": 297,
|
|
128
|
-
"1-664": 354,
|
|
129
|
-
"212": 604,
|
|
130
|
-
"258": 643,
|
|
131
|
-
"95": 414,
|
|
132
|
-
"264": 649,
|
|
133
|
-
"674": 536,
|
|
134
|
-
"977": 429,
|
|
135
|
-
"31": 204,
|
|
136
|
-
"687": 546,
|
|
137
|
-
"64": 530,
|
|
138
|
-
"505": 710,
|
|
139
|
-
"227": 614,
|
|
140
|
-
"234": 621,
|
|
141
|
-
"683": 555,
|
|
142
|
-
"1-670": 534,
|
|
143
|
-
"47": 242,
|
|
144
|
-
"968": 226,
|
|
145
|
-
"92": 410,
|
|
146
|
-
"680": 552,
|
|
147
|
-
"970": 423,
|
|
148
|
-
"507": 714,
|
|
149
|
-
"675": 537,
|
|
150
|
-
"595": 744,
|
|
151
|
-
"51": 716,
|
|
152
|
-
"63": 515,
|
|
153
|
-
"48": 260,
|
|
154
|
-
"351": 268,
|
|
155
|
-
"1-787, 1-939": 330,
|
|
156
|
-
"974": 427,
|
|
157
|
-
"242": 630,
|
|
158
|
-
"40": 226,
|
|
159
|
-
"7": 250,
|
|
160
|
-
"250": 635,
|
|
161
|
-
"290": 658,
|
|
162
|
-
"1-869": 356,
|
|
163
|
-
"1-758": 358,
|
|
164
|
-
"508": 308,
|
|
165
|
-
"1-784": 360,
|
|
166
|
-
"685": 544,
|
|
167
|
-
"378": 292,
|
|
168
|
-
"239": 626,
|
|
169
|
-
"966": 420,
|
|
170
|
-
"221": 608,
|
|
171
|
-
"381": 220,
|
|
172
|
-
"248": 633,
|
|
173
|
-
"232": 619,
|
|
174
|
-
"65": 525,
|
|
175
|
-
"386": 293,
|
|
176
|
-
"677": 540,
|
|
177
|
-
"27": 655,
|
|
178
|
-
"211": 659,
|
|
179
|
-
"34": 214,
|
|
180
|
-
"94": 413,
|
|
181
|
-
"249": 634,
|
|
182
|
-
"597": 746,
|
|
183
|
-
"268": 653,
|
|
184
|
-
"46": 240,
|
|
185
|
-
"41": 228,
|
|
186
|
-
"963": 417,
|
|
187
|
-
"886": 466,
|
|
188
|
-
"992": 436,
|
|
189
|
-
"255": 640,
|
|
190
|
-
"66": 520,
|
|
191
|
-
"228": 615,
|
|
192
|
-
"690": 554,
|
|
193
|
-
"676": 539,
|
|
194
|
-
"1-868": 374,
|
|
195
|
-
"216": 605,
|
|
196
|
-
"90": 286,
|
|
197
|
-
"993": 438,
|
|
198
|
-
"1-649": 376,
|
|
199
|
-
"688": 553,
|
|
200
|
-
"1-340": 332,
|
|
201
|
-
"256": 641,
|
|
202
|
-
"380": 255,
|
|
203
|
-
"971": 424,
|
|
204
|
-
"44": 234,
|
|
205
|
-
"1": 310,
|
|
206
|
-
"598": 748,
|
|
207
|
-
"998": 434,
|
|
208
|
-
"678": 541,
|
|
209
|
-
"379": 225,
|
|
210
|
-
"58": 734,
|
|
211
|
-
"681": 543,
|
|
212
|
-
"967": 421,
|
|
213
|
-
"260": 645,
|
|
214
|
-
"263": 648,
|
|
215
|
-
"670": 514,
|
|
216
|
-
"245": 632,
|
|
217
|
-
"856": 457,
|
|
218
|
-
"599": 362,
|
|
219
|
-
"850": 467,
|
|
220
|
-
"262": 647,
|
|
221
|
-
"82": 450,
|
|
222
|
-
"84": 452
|
|
223
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AbstractSocketClient = void 0;
|
|
4
|
-
const events_1 = require("events");
|
|
5
|
-
class AbstractSocketClient extends events_1.EventEmitter {
|
|
6
|
-
constructor(url, config) {
|
|
7
|
-
super();
|
|
8
|
-
this.url = url;
|
|
9
|
-
this.config = config;
|
|
10
|
-
this.setMaxListeners(0);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
exports.AbstractSocketClient = AbstractSocketClient;
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MobileSocketClient = void 0;
|
|
4
|
-
const net_1 = require("net");
|
|
5
|
-
const abstract_socket_client_1 = require("./abstract-socket-client");
|
|
6
|
-
class MobileSocketClient extends abstract_socket_client_1.AbstractSocketClient {
|
|
7
|
-
constructor() {
|
|
8
|
-
super(...arguments);
|
|
9
|
-
this.socket = null;
|
|
10
|
-
}
|
|
11
|
-
get isOpen() {
|
|
12
|
-
var _a;
|
|
13
|
-
return ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === 'open';
|
|
14
|
-
}
|
|
15
|
-
get isClosed() {
|
|
16
|
-
var _a;
|
|
17
|
-
return this.socket === null || ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === 'closed';
|
|
18
|
-
}
|
|
19
|
-
get isClosing() {
|
|
20
|
-
var _a;
|
|
21
|
-
return this.socket === null || ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === 'closed';
|
|
22
|
-
}
|
|
23
|
-
get isConnecting() {
|
|
24
|
-
var _a;
|
|
25
|
-
return ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === 'opening';
|
|
26
|
-
}
|
|
27
|
-
async connect() {
|
|
28
|
-
var _a;
|
|
29
|
-
if (this.socket) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
if (this.config.agent) {
|
|
33
|
-
throw new Error('There are not support for proxy agent for mobile connection');
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
this.socket = (0, net_1.connect)({
|
|
37
|
-
host: this.url.hostname,
|
|
38
|
-
port: Number(this.url.port) || 443
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
this.socket.setMaxListeners(0);
|
|
42
|
-
const events = ['close', 'connect', 'data', 'drain', 'end', 'error', 'lookup', 'ready', 'timeout'];
|
|
43
|
-
for (const event of events) {
|
|
44
|
-
(_a = this.socket) === null || _a === void 0 ? void 0 : _a.on(event, (...args) => this.emit(event, ...args));
|
|
45
|
-
}
|
|
46
|
-
this.socket.on('data', (...args) => this.emit('message', ...args));
|
|
47
|
-
this.socket.on('ready', (...args) => this.emit('open', ...args));
|
|
48
|
-
}
|
|
49
|
-
async close() {
|
|
50
|
-
if (!this.socket) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
return new Promise(resolve => {
|
|
54
|
-
this.socket.end(resolve);
|
|
55
|
-
this.socket = null;
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
send(str, cb) {
|
|
59
|
-
if (this.socket === null) {
|
|
60
|
-
return false;
|
|
61
|
-
}
|
|
62
|
-
return this.socket.write(str, undefined, cb);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
exports.MobileSocketClient = MobileSocketClient;
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.WebSocketClient = void 0;
|
|
7
|
-
const ws_1 = __importDefault(require("ws"));
|
|
8
|
-
const Defaults_1 = require("../../Defaults");
|
|
9
|
-
const abstract_socket_client_1 = require("./abstract-socket-client");
|
|
10
|
-
class WebSocketClient extends abstract_socket_client_1.AbstractSocketClient {
|
|
11
|
-
constructor() {
|
|
12
|
-
super(...arguments);
|
|
13
|
-
this.socket = null;
|
|
14
|
-
}
|
|
15
|
-
get isOpen() {
|
|
16
|
-
var _a;
|
|
17
|
-
return ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.OPEN;
|
|
18
|
-
}
|
|
19
|
-
get isClosed() {
|
|
20
|
-
var _a;
|
|
21
|
-
return this.socket === null || ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.CLOSED;
|
|
22
|
-
}
|
|
23
|
-
get isClosing() {
|
|
24
|
-
var _a;
|
|
25
|
-
return this.socket === null || ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.CLOSING;
|
|
26
|
-
}
|
|
27
|
-
get isConnecting() {
|
|
28
|
-
var _a;
|
|
29
|
-
return ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.CONNECTING;
|
|
30
|
-
}
|
|
31
|
-
async connect() {
|
|
32
|
-
var _a, _b;
|
|
33
|
-
if (this.socket) {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
this.socket = new ws_1.default(this.url, {
|
|
37
|
-
origin: Defaults_1.DEFAULT_ORIGIN,
|
|
38
|
-
headers: (_a = this.config.options) === null || _a === void 0 ? void 0 : _a.headers,
|
|
39
|
-
handshakeTimeout: this.config.connectTimeoutMs,
|
|
40
|
-
timeout: this.config.connectTimeoutMs,
|
|
41
|
-
agent: this.config.agent,
|
|
42
|
-
});
|
|
43
|
-
this.socket.setMaxListeners(0);
|
|
44
|
-
const events = ['close', 'error', 'upgrade', 'message', 'open', 'ping', 'pong', 'unexpected-response'];
|
|
45
|
-
for (const event of events) {
|
|
46
|
-
(_b = this.socket) === null || _b === void 0 ? void 0 : _b.on(event, (...args) => this.emit(event, ...args));
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
async close() {
|
|
50
|
-
if (!this.socket) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
this.socket.close();
|
|
54
|
-
this.socket = null;
|
|
55
|
-
}
|
|
56
|
-
send(str, cb) {
|
|
57
|
-
var _a;
|
|
58
|
-
(_a = this.socket) === null || _a === void 0 ? void 0 : _a.send(str, cb);
|
|
59
|
-
return Boolean(this.socket);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
exports.WebSocketClient = WebSocketClient;
|
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.makeRegistrationSocket = void 0;
|
|
7
|
-
exports.registrationParams = registrationParams;
|
|
8
|
-
exports.mobileRegisterCode = mobileRegisterCode;
|
|
9
|
-
exports.mobileRegisterExists = mobileRegisterExists;
|
|
10
|
-
exports.mobileRegister = mobileRegister;
|
|
11
|
-
exports.mobileRegisterEncrypt = mobileRegisterEncrypt;
|
|
12
|
-
exports.mobileRegisterFetch = mobileRegisterFetch;
|
|
13
|
-
/* eslint-disable camelcase */
|
|
14
|
-
const axios_1 = __importDefault(require("axios"));
|
|
15
|
-
const Defaults_1 = require("../Defaults");
|
|
16
|
-
const crypto_1 = require("../Utils/crypto");
|
|
17
|
-
const WABinary_1 = require("../WABinary");
|
|
18
|
-
const business_1 = require("./business");
|
|
19
|
-
function urlencode(str) {
|
|
20
|
-
return str.replace(/-/g, '%2d').replace(/_/g, '%5f').replace(/~/g, '%7e');
|
|
21
|
-
}
|
|
22
|
-
const validRegistrationOptions = (config) => (config === null || config === void 0 ? void 0 : config.phoneNumberCountryCode) &&
|
|
23
|
-
config.phoneNumberNationalNumber &&
|
|
24
|
-
config.phoneNumberMobileCountryCode;
|
|
25
|
-
const makeRegistrationSocket = (config) => {
|
|
26
|
-
const sock = (0, business_1.makeBusinessSocket)(config);
|
|
27
|
-
const register = async (code) => {
|
|
28
|
-
if (!validRegistrationOptions(config.auth.creds.registration)) {
|
|
29
|
-
throw new Error('please specify the registration options');
|
|
30
|
-
}
|
|
31
|
-
const result = await mobileRegister({ ...sock.authState.creds, ...sock.authState.creds.registration, code }, config.options);
|
|
32
|
-
sock.authState.creds.me = {
|
|
33
|
-
id: (0, WABinary_1.jidEncode)(result.login, 's.whatsapp.net'),
|
|
34
|
-
name: '~'
|
|
35
|
-
};
|
|
36
|
-
sock.authState.creds.registered = true;
|
|
37
|
-
sock.ev.emit('creds.update', sock.authState.creds);
|
|
38
|
-
return result;
|
|
39
|
-
};
|
|
40
|
-
const requestRegistrationCode = async (registrationOptions) => {
|
|
41
|
-
registrationOptions = registrationOptions || config.auth.creds.registration;
|
|
42
|
-
if (!validRegistrationOptions(registrationOptions)) {
|
|
43
|
-
throw new Error('Invalid registration options');
|
|
44
|
-
}
|
|
45
|
-
sock.authState.creds.registration = registrationOptions;
|
|
46
|
-
sock.ev.emit('creds.update', sock.authState.creds);
|
|
47
|
-
return mobileRegisterCode({ ...config.auth.creds, ...registrationOptions }, config.options);
|
|
48
|
-
};
|
|
49
|
-
return {
|
|
50
|
-
...sock,
|
|
51
|
-
register,
|
|
52
|
-
requestRegistrationCode,
|
|
53
|
-
};
|
|
54
|
-
};
|
|
55
|
-
exports.makeRegistrationSocket = makeRegistrationSocket;
|
|
56
|
-
function convertBufferToUrlHex(buffer) {
|
|
57
|
-
var id = '';
|
|
58
|
-
buffer.forEach((x) => {
|
|
59
|
-
// encode random identity_id buffer as percentage url encoding
|
|
60
|
-
id += `%${x.toString(16).padStart(2, '0').toLowerCase()}`;
|
|
61
|
-
});
|
|
62
|
-
return id;
|
|
63
|
-
}
|
|
64
|
-
function registrationParams(params) {
|
|
65
|
-
const e_regid = Buffer.alloc(4);
|
|
66
|
-
e_regid.writeInt32BE(params.registrationId);
|
|
67
|
-
const e_skey_id = Buffer.alloc(3);
|
|
68
|
-
e_skey_id.writeInt16BE(params.signedPreKey.keyId);
|
|
69
|
-
params.phoneNumberCountryCode = params.phoneNumberCountryCode.replace('+', '').trim();
|
|
70
|
-
params.phoneNumberNationalNumber = params.phoneNumberNationalNumber.replace(/[/-\s)(]/g, '').trim();
|
|
71
|
-
return {
|
|
72
|
-
cc: params.phoneNumberCountryCode,
|
|
73
|
-
in: params.phoneNumberNationalNumber,
|
|
74
|
-
Rc: '0',
|
|
75
|
-
lg: 'en',
|
|
76
|
-
lc: 'GB',
|
|
77
|
-
mistyped: '6',
|
|
78
|
-
authkey: Buffer.from(params.noiseKey.public).toString('base64url'),
|
|
79
|
-
e_regid: e_regid.toString('base64url'),
|
|
80
|
-
e_keytype: 'BQ',
|
|
81
|
-
e_ident: Buffer.from(params.signedIdentityKey.public).toString('base64url'),
|
|
82
|
-
// e_skey_id: e_skey_id.toString('base64url'),
|
|
83
|
-
e_skey_id: 'AAAA',
|
|
84
|
-
e_skey_val: Buffer.from(params.signedPreKey.keyPair.public).toString('base64url'),
|
|
85
|
-
e_skey_sig: Buffer.from(params.signedPreKey.signature).toString('base64url'),
|
|
86
|
-
fdid: params.phoneId,
|
|
87
|
-
network_ratio_type: '1',
|
|
88
|
-
expid: params.deviceId,
|
|
89
|
-
simnum: '1',
|
|
90
|
-
hasinrc: '1',
|
|
91
|
-
pid: Math.floor(Math.random() * 1000).toString(),
|
|
92
|
-
id: convertBufferToUrlHex(params.identityId),
|
|
93
|
-
backup_token: convertBufferToUrlHex(params.backupToken),
|
|
94
|
-
token: (0, crypto_1.md5)(Buffer.concat([Defaults_1.MOBILE_TOKEN, Buffer.from(params.phoneNumberNationalNumber)])).toString('hex'),
|
|
95
|
-
fraud_checkpoint_code: params.captcha,
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Requests a registration code for the given phone number.
|
|
100
|
-
*/
|
|
101
|
-
function mobileRegisterCode(params, fetchOptions) {
|
|
102
|
-
return mobileRegisterFetch('/code', {
|
|
103
|
-
params: {
|
|
104
|
-
...registrationParams(params),
|
|
105
|
-
mcc: `${params.phoneNumberMobileCountryCode}`.padStart(3, '0'),
|
|
106
|
-
mnc: `${params.phoneNumberMobileNetworkCode || '001'}`.padStart(3, '0'),
|
|
107
|
-
sim_mcc: '000',
|
|
108
|
-
sim_mnc: '000',
|
|
109
|
-
method: (params === null || params === void 0 ? void 0 : params.method) || 'sms',
|
|
110
|
-
reason: '',
|
|
111
|
-
hasav: '1'
|
|
112
|
-
},
|
|
113
|
-
...fetchOptions,
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
function mobileRegisterExists(params, fetchOptions) {
|
|
117
|
-
return mobileRegisterFetch('/exist', {
|
|
118
|
-
params: registrationParams(params),
|
|
119
|
-
...fetchOptions
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Registers the phone number on whatsapp with the received OTP code.
|
|
124
|
-
*/
|
|
125
|
-
async function mobileRegister(params, fetchOptions) {
|
|
126
|
-
//const result = await mobileRegisterFetch(`/reg_onboard_abprop?cc=${params.phoneNumberCountryCode}&in=${params.phoneNumberNationalNumber}&rc=0`)
|
|
127
|
-
return mobileRegisterFetch('/register', {
|
|
128
|
-
params: { ...registrationParams(params), code: params.code.replace('-', '') },
|
|
129
|
-
...fetchOptions,
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Encrypts the given string as AEAD aes-256-gcm with the public whatsapp key and a random keypair.
|
|
134
|
-
*/
|
|
135
|
-
function mobileRegisterEncrypt(data) {
|
|
136
|
-
const keypair = crypto_1.Curve.generateKeyPair();
|
|
137
|
-
const key = crypto_1.Curve.sharedKey(keypair.private, Defaults_1.REGISTRATION_PUBLIC_KEY);
|
|
138
|
-
const buffer = (0, crypto_1.aesEncryptGCM)(Buffer.from(data), new Uint8Array(key), Buffer.alloc(12), Buffer.alloc(0));
|
|
139
|
-
return Buffer.concat([Buffer.from(keypair.public), buffer]).toString('base64url');
|
|
140
|
-
}
|
|
141
|
-
async function mobileRegisterFetch(path, opts = {}) {
|
|
142
|
-
let url = `${Defaults_1.MOBILE_REGISTRATION_ENDPOINT}${path}`;
|
|
143
|
-
if (opts.params) {
|
|
144
|
-
const parameter = [];
|
|
145
|
-
for (const param in opts.params) {
|
|
146
|
-
if (opts.params[param] !== null && opts.params[param] !== undefined) {
|
|
147
|
-
parameter.push(param + '=' + urlencode(opts.params[param]));
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
url += `?${parameter.join('&')}`;
|
|
151
|
-
delete opts.params;
|
|
152
|
-
}
|
|
153
|
-
if (!opts.headers) {
|
|
154
|
-
opts.headers = {};
|
|
155
|
-
}
|
|
156
|
-
opts.headers['User-Agent'] = Defaults_1.MOBILE_USERAGENT;
|
|
157
|
-
const response = await (0, axios_1.default)(url, opts);
|
|
158
|
-
var json = response.data;
|
|
159
|
-
if (response.status > 300 || json.reason) {
|
|
160
|
-
throw json;
|
|
161
|
-
}
|
|
162
|
-
if (json.status && !['ok', 'sent'].includes(json.status)) {
|
|
163
|
-
throw json;
|
|
164
|
-
}
|
|
165
|
-
return json;
|
|
166
|
-
}
|
package/lib/Socket/usync.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.makeUSyncSocket = void 0;
|
|
4
|
-
const boom_1 = require("@hapi/boom");
|
|
5
|
-
const WABinary_1 = require("../WABinary");
|
|
6
|
-
const socket_1 = require("./socket");
|
|
7
|
-
const makeUSyncSocket = (config) => {
|
|
8
|
-
const sock = (0, socket_1.makeSocket)(config);
|
|
9
|
-
const { generateMessageTag, query, } = sock;
|
|
10
|
-
const executeUSyncQuery = async (usyncQuery) => {
|
|
11
|
-
if (usyncQuery.protocols.length === 0) {
|
|
12
|
-
throw new boom_1.Boom('USyncQuery must have at least one protocol');
|
|
13
|
-
}
|
|
14
|
-
// todo: validate users, throw WARNING on no valid users
|
|
15
|
-
// variable below has only validated users
|
|
16
|
-
const validUsers = usyncQuery.users;
|
|
17
|
-
const userNodes = validUsers.map((user) => {
|
|
18
|
-
return {
|
|
19
|
-
tag: 'user',
|
|
20
|
-
attrs: {
|
|
21
|
-
jid: !user.phone ? user.id : undefined,
|
|
22
|
-
},
|
|
23
|
-
content: usyncQuery.protocols
|
|
24
|
-
.map((a) => a.getUserElement(user))
|
|
25
|
-
.filter(a => a !== null)
|
|
26
|
-
};
|
|
27
|
-
});
|
|
28
|
-
const listNode = {
|
|
29
|
-
tag: 'list',
|
|
30
|
-
attrs: {},
|
|
31
|
-
content: userNodes
|
|
32
|
-
};
|
|
33
|
-
const queryNode = {
|
|
34
|
-
tag: 'query',
|
|
35
|
-
attrs: {},
|
|
36
|
-
content: usyncQuery.protocols.map((a) => a.getQueryElement())
|
|
37
|
-
};
|
|
38
|
-
const iq = {
|
|
39
|
-
tag: 'iq',
|
|
40
|
-
attrs: {
|
|
41
|
-
to: WABinary_1.S_WHATSAPP_NET,
|
|
42
|
-
type: 'get',
|
|
43
|
-
xmlns: 'usync',
|
|
44
|
-
},
|
|
45
|
-
content: [
|
|
46
|
-
{
|
|
47
|
-
tag: 'usync',
|
|
48
|
-
attrs: {
|
|
49
|
-
context: usyncQuery.context,
|
|
50
|
-
mode: usyncQuery.mode,
|
|
51
|
-
sid: generateMessageTag(),
|
|
52
|
-
last: 'true',
|
|
53
|
-
index: '0',
|
|
54
|
-
},
|
|
55
|
-
content: [
|
|
56
|
-
queryNode,
|
|
57
|
-
listNode
|
|
58
|
-
]
|
|
59
|
-
}
|
|
60
|
-
],
|
|
61
|
-
};
|
|
62
|
-
const result = await query(iq);
|
|
63
|
-
return usyncQuery.parseUSyncQueryResult(result);
|
|
64
|
-
};
|
|
65
|
-
return {
|
|
66
|
-
...sock,
|
|
67
|
-
executeUSyncQuery,
|
|
68
|
-
};
|
|
69
|
-
};
|
|
70
|
-
exports.makeUSyncSocket = makeUSyncSocket;
|