@vinzsocket/baileys 2.8.30 → 3.0.0
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/WAProto/fix-imports.js +7 -16
- package/WAProto/index.js +1 -37306
- package/lib/Defaults/index.js +37 -33
- package/lib/Signal/Group/ciphertext-message.js +6 -2
- package/lib/Signal/Group/group-session-builder.js +12 -7
- package/lib/Signal/Group/group_cipher.js +18 -13
- package/lib/Signal/Group/index.js +77 -12
- package/lib/Signal/Group/keyhelper.js +15 -8
- package/lib/Signal/Group/queue-job.js +7 -2
- package/lib/Signal/Group/sender-chain-key.js +11 -6
- package/lib/Signal/Group/sender-key-distribution-message.js +10 -6
- package/lib/Signal/Group/sender-key-message.js +14 -9
- package/lib/Signal/Group/sender-key-name.js +6 -2
- package/lib/Signal/Group/sender-key-record.js +13 -9
- package/lib/Signal/Group/sender-key-state.js +10 -6
- package/lib/Signal/Group/sender-message-key.js +9 -4
- package/lib/Signal/libsignal.js +34 -28
- package/lib/Signal/lid-mapping.js +24 -19
- package/lib/Socket/Client/index.js +25 -3
- package/lib/Socket/Client/types.js +8 -4
- package/lib/Socket/Client/websocket.js +16 -11
- package/lib/Socket/business.js +38 -34
- package/lib/Socket/chats.js +100 -95
- package/lib/Socket/communities.js +55 -49
- package/lib/Socket/groups.js +56 -51
- package/lib/Socket/index.js +9 -6
- package/lib/Socket/messages-recv.js +150 -145
- package/lib/Socket/messages-send.js +109 -104
- package/lib/Socket/mex.js +12 -8
- package/lib/Socket/newsletter.js +27 -23
- package/lib/Socket/socket.js +111 -107
- package/lib/Store/index.js +47 -4
- package/lib/Store/make-cache-manager-store.js +17 -11
- package/lib/Store/make-in-memory-store.js +31 -29
- package/lib/Store/make-ordered-dictionary.js +7 -2
- package/lib/Store/object-repository.js +7 -2
- package/lib/Types/Auth.js +3 -2
- package/lib/Types/Bussines.js +3 -2
- package/lib/Types/Call.js +3 -2
- package/lib/Types/Chat.js +5 -2
- package/lib/Types/Contact.js +3 -2
- package/lib/Types/Events.js +1 -2
- package/lib/Types/GroupMetadata.js +3 -2
- package/lib/Types/Label.js +6 -3
- package/lib/Types/LabelAssociation.js +6 -3
- package/lib/Types/Message.js +16 -7
- package/lib/Types/Newsletter.js +8 -5
- package/lib/Types/Product.js +3 -2
- package/lib/Types/Signal.js +1 -2
- package/lib/Types/Socket.js +2 -3
- package/lib/Types/State.js +7 -4
- package/lib/Types/USync.js +1 -2
- package/lib/Types/index.js +153 -15
- package/lib/Utils/auth-utils.js +32 -25
- package/lib/Utils/baileys-event-stream.js +21 -15
- package/lib/Utils/business.js +71 -61
- package/lib/Utils/chat-utils.js +91 -77
- package/lib/Utils/crypto.js +54 -32
- package/lib/Utils/decode-wa-message.js +46 -39
- package/lib/Utils/event-buffer.js +24 -19
- package/lib/Utils/extended-messages.js +14 -9
- package/lib/Utils/generics.js +100 -64
- package/lib/Utils/history.js +30 -23
- package/lib/Utils/index.js +234 -22
- package/lib/Utils/lid-resolver.js +12 -5
- package/lib/Utils/link-preview.js +11 -7
- package/lib/Utils/logger.js +8 -4
- package/lib/Utils/lt-hash.js +8 -5
- package/lib/Utils/make-mutex.js +8 -3
- package/lib/Utils/mention.js +12 -4
- package/lib/Utils/message-retry-manager.js +10 -6
- package/lib/Utils/messages-media.js +127 -95
- package/lib/Utils/messages.js +122 -98
- package/lib/Utils/noise-handler.js +25 -21
- package/lib/Utils/process-message.js +72 -63
- package/lib/Utils/signal.js +45 -33
- package/lib/Utils/use-multi-file-auth-state.js +24 -20
- package/lib/Utils/validate-connection.js +54 -47
- package/lib/WABinary/constants.js +9 -6
- package/lib/WABinary/decode.js +17 -10
- package/lib/WABinary/encode.js +11 -6
- package/lib/WABinary/generic-utils.js +31 -17
- package/lib/WABinary/index.js +58 -6
- package/lib/WABinary/jid-utils.js +36 -20
- package/lib/WABinary/types.js +2 -2
- package/lib/WAM/BinaryInfo.js +6 -2
- package/lib/WAM/constants.js +1 -1
- package/lib/WAM/encode.js +16 -12
- package/lib/WAM/index.js +36 -4
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +9 -5
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +10 -6
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +8 -4
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +8 -4
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +9 -4
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +23 -19
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +6 -2
- package/lib/WAUSync/Protocols/index.js +58 -6
- package/lib/WAUSync/USyncQuery.js +21 -17
- package/lib/WAUSync/USyncUser.js +6 -2
- package/lib/WAUSync/index.js +36 -4
- package/lib/index.js +112 -12
- package/package.json +8 -6
package/lib/Socket/socket.js
CHANGED
|
@@ -1,21 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
Object.defineProperty(exports, "__esModule", {
|
|
2
|
+
value: true
|
|
3
|
+
});
|
|
4
|
+
exports.makeSocket = void 0;
|
|
5
|
+
var _boom = require("@hapi/boom");
|
|
6
|
+
var _crypto = require("crypto");
|
|
7
|
+
var _url = require("url");
|
|
8
|
+
var _util = require("util");
|
|
9
|
+
var _index = require("../../WAProto/index.js");
|
|
10
|
+
var _index2 = require("../Defaults/index.js");
|
|
11
|
+
var _index3 = require("../Types/index.js");
|
|
12
|
+
var _index4 = require("../Utils/index.js");
|
|
13
|
+
var _index5 = require("../WABinary/index.js");
|
|
14
|
+
var _index6 = require("../WAUSync/index.js");
|
|
15
|
+
var _index7 = require("./Client/index.js");
|
|
12
16
|
/**
|
|
13
17
|
* Connects to WA servers and performs:
|
|
14
18
|
* - simple queries (no retry mechanism, wait for connection establishment)
|
|
15
19
|
* - listen to messages and emit events
|
|
16
20
|
* - query phone connection
|
|
17
21
|
*/
|
|
18
|
-
|
|
22
|
+
const makeSocket = config => {
|
|
19
23
|
const {
|
|
20
24
|
waWebSocketUrl,
|
|
21
25
|
connectTimeoutMs,
|
|
@@ -29,41 +33,41 @@ export const makeSocket = config => {
|
|
|
29
33
|
qrTimeout,
|
|
30
34
|
makeSignalRepository
|
|
31
35
|
} = config;
|
|
32
|
-
const uqTagId = generateMdTagPrefix();
|
|
36
|
+
const uqTagId = (0, _index4.generateMdTagPrefix)();
|
|
33
37
|
const generateMessageTag = () => `${uqTagId}${epoch++}`;
|
|
34
38
|
if (printQRInTerminal) {
|
|
35
39
|
console.warn('⚠️ The printQRInTerminal option has been deprecated. You will no longer receive QR codes in the terminal automatically. Please listen to the connection.update event yourself and handle the QR your way. You can remove this message by removing this opttion. This message will be removed in a future version.');
|
|
36
40
|
}
|
|
37
|
-
const url = typeof waWebSocketUrl === 'string' ? new URL(waWebSocketUrl) : waWebSocketUrl;
|
|
41
|
+
const url = typeof waWebSocketUrl === 'string' ? new _url.URL(waWebSocketUrl) : waWebSocketUrl;
|
|
38
42
|
if (config.mobile || url.protocol === 'tcp:') {
|
|
39
|
-
throw new Boom('Mobile API is not supported anymore', {
|
|
40
|
-
statusCode: DisconnectReason.loggedOut
|
|
43
|
+
throw new _boom.Boom('Mobile API is not supported anymore', {
|
|
44
|
+
statusCode: _index3.DisconnectReason.loggedOut
|
|
41
45
|
});
|
|
42
46
|
}
|
|
43
47
|
if (url.protocol === 'wss' && authState?.creds?.routingInfo) {
|
|
44
48
|
url.searchParams.append('ED', authState.creds.routingInfo.toString('base64url'));
|
|
45
49
|
}
|
|
46
50
|
/** ephemeral key pair used to encrypt/decrypt communication. Unique for each connection */
|
|
47
|
-
const ephemeralKeyPair = Curve.generateKeyPair();
|
|
51
|
+
const ephemeralKeyPair = _index4.Curve.generateKeyPair();
|
|
48
52
|
/** WA noise protocol wrapper */
|
|
49
|
-
const noise = makeNoiseHandler({
|
|
53
|
+
const noise = (0, _index4.makeNoiseHandler)({
|
|
50
54
|
keyPair: ephemeralKeyPair,
|
|
51
|
-
NOISE_HEADER: NOISE_WA_HEADER,
|
|
55
|
+
NOISE_HEADER: _index2.NOISE_WA_HEADER,
|
|
52
56
|
logger,
|
|
53
57
|
routingInfo: authState?.creds?.routingInfo
|
|
54
58
|
});
|
|
55
|
-
const ws = new WebSocketClient(url, config);
|
|
59
|
+
const ws = new _index7.WebSocketClient(url, config);
|
|
56
60
|
ws.connect();
|
|
57
|
-
const sendPromise = promisify(ws.send);
|
|
61
|
+
const sendPromise = (0, _util.promisify)(ws.send);
|
|
58
62
|
/** send a raw buffer */
|
|
59
63
|
const sendRawMessage = async data => {
|
|
60
64
|
if (!ws.isOpen) {
|
|
61
|
-
throw new Boom('Connection Closed', {
|
|
62
|
-
statusCode: DisconnectReason.connectionClosed
|
|
65
|
+
throw new _boom.Boom('Connection Closed', {
|
|
66
|
+
statusCode: _index3.DisconnectReason.connectionClosed
|
|
63
67
|
});
|
|
64
68
|
}
|
|
65
69
|
const bytes = noise.encodeFrame(data);
|
|
66
|
-
await promiseTimeout(connectTimeoutMs, async (resolve, reject) => {
|
|
70
|
+
await (0, _index4.promiseTimeout)(connectTimeoutMs, async (resolve, reject) => {
|
|
67
71
|
try {
|
|
68
72
|
await sendPromise.call(ws, bytes);
|
|
69
73
|
resolve();
|
|
@@ -76,11 +80,11 @@ export const makeSocket = config => {
|
|
|
76
80
|
const sendNode = frame => {
|
|
77
81
|
if (logger.level === 'trace') {
|
|
78
82
|
logger.trace({
|
|
79
|
-
xml: binaryNodeToString(frame),
|
|
83
|
+
xml: (0, _index5.binaryNodeToString)(frame),
|
|
80
84
|
msg: 'xml send'
|
|
81
85
|
});
|
|
82
86
|
}
|
|
83
|
-
const buff = encodeBinaryNode(frame);
|
|
87
|
+
const buff = (0, _index5.encodeBinaryNode)(frame);
|
|
84
88
|
return sendRawMessage(buff);
|
|
85
89
|
};
|
|
86
90
|
/**
|
|
@@ -92,24 +96,24 @@ export const makeSocket = config => {
|
|
|
92
96
|
let onRecv;
|
|
93
97
|
let onErr;
|
|
94
98
|
try {
|
|
95
|
-
const result = await promiseTimeout(timeoutMs, (resolve, reject) => {
|
|
99
|
+
const result = await (0, _index4.promiseTimeout)(timeoutMs, (resolve, reject) => {
|
|
96
100
|
onRecv = data => {
|
|
97
101
|
resolve(data);
|
|
98
102
|
};
|
|
99
103
|
onErr = err => {
|
|
100
|
-
reject(err || new Boom('Connection Closed', {
|
|
101
|
-
statusCode: DisconnectReason.connectionClosed
|
|
104
|
+
reject(err || new _boom.Boom('Connection Closed', {
|
|
105
|
+
statusCode: _index3.DisconnectReason.connectionClosed
|
|
102
106
|
}));
|
|
103
107
|
};
|
|
104
108
|
ws.on(`TAG:${msgId}`, onRecv);
|
|
105
109
|
ws.on('close', onErr);
|
|
106
110
|
ws.on('error', onErr);
|
|
107
|
-
return () => reject(new Boom('Query Cancelled'));
|
|
111
|
+
return () => reject(new _boom.Boom('Query Cancelled'));
|
|
108
112
|
});
|
|
109
113
|
return result;
|
|
110
114
|
} catch (error) {
|
|
111
115
|
// Catch timeout and return undefined instead of throwing
|
|
112
|
-
if (error instanceof Boom && error.output?.statusCode === DisconnectReason.timedOut) {
|
|
116
|
+
if (error instanceof _boom.Boom && error.output?.statusCode === _index3.DisconnectReason.timedOut) {
|
|
113
117
|
logger?.warn?.({
|
|
114
118
|
msgId
|
|
115
119
|
}, 'timed out waiting for message');
|
|
@@ -130,18 +134,18 @@ export const makeSocket = config => {
|
|
|
130
134
|
node.attrs.id = generateMessageTag();
|
|
131
135
|
}
|
|
132
136
|
const msgId = node.attrs.id;
|
|
133
|
-
const result = await promiseTimeout(timeoutMs, async (resolve, reject) => {
|
|
137
|
+
const result = await (0, _index4.promiseTimeout)(timeoutMs, async (resolve, reject) => {
|
|
134
138
|
const result = waitForMessage(msgId, timeoutMs).catch(reject);
|
|
135
139
|
sendNode(node).then(async () => resolve(await result)).catch(reject);
|
|
136
140
|
});
|
|
137
141
|
if (result && 'tag' in result) {
|
|
138
|
-
assertNodeErrorFree(result);
|
|
142
|
+
(0, _index5.assertNodeErrorFree)(result);
|
|
139
143
|
}
|
|
140
144
|
return result;
|
|
141
145
|
};
|
|
142
146
|
const executeUSyncQuery = async usyncQuery => {
|
|
143
147
|
if (usyncQuery.protocols.length === 0) {
|
|
144
|
-
throw new Boom('USyncQuery must have at least one protocol');
|
|
148
|
+
throw new _boom.Boom('USyncQuery must have at least one protocol');
|
|
145
149
|
}
|
|
146
150
|
// todo: validate users, throw WARNING on no valid users
|
|
147
151
|
// variable below has only validated users
|
|
@@ -168,7 +172,7 @@ export const makeSocket = config => {
|
|
|
168
172
|
const iq = {
|
|
169
173
|
tag: 'iq',
|
|
170
174
|
attrs: {
|
|
171
|
-
to: S_WHATSAPP_NET,
|
|
175
|
+
to: _index5.S_WHATSAPP_NET,
|
|
172
176
|
type: 'get',
|
|
173
177
|
xmlns: 'usync'
|
|
174
178
|
},
|
|
@@ -188,15 +192,15 @@ export const makeSocket = config => {
|
|
|
188
192
|
return usyncQuery.parseUSyncQueryResult(result);
|
|
189
193
|
};
|
|
190
194
|
const onWhatsApp = async (...jids) => {
|
|
191
|
-
const usyncQuery = new USyncQuery().withLIDProtocol();
|
|
195
|
+
const usyncQuery = new _index6.USyncQuery().withLIDProtocol();
|
|
192
196
|
// .withContactProtocol() when dealing with phone
|
|
193
197
|
// .withId simply with LIDs and WIDs
|
|
194
198
|
for (const jid of jids) {
|
|
195
|
-
if (isLidUser(jid)) {
|
|
196
|
-
usyncQuery.withUser(new USyncUser().withId(jid)); // intentional
|
|
199
|
+
if ((0, _index5.isLidUser)(jid)) {
|
|
200
|
+
usyncQuery.withUser(new _index6.USyncUser().withId(jid)); // intentional
|
|
197
201
|
} else {
|
|
198
202
|
const phone = `+${jid.replace('+', '').split('@')[0]?.split(':')[0]}`;
|
|
199
|
-
usyncQuery.withUser(new USyncUser().withPhone(phone));
|
|
203
|
+
usyncQuery.withUser(new _index6.USyncUser().withPhone(phone));
|
|
200
204
|
}
|
|
201
205
|
}
|
|
202
206
|
const results = await executeUSyncQuery(usyncQuery);
|
|
@@ -220,12 +224,12 @@ export const makeSocket = config => {
|
|
|
220
224
|
}));
|
|
221
225
|
}
|
|
222
226
|
};
|
|
223
|
-
const ev = makeEventBuffer(logger);
|
|
227
|
+
const ev = (0, _index4.makeEventBuffer)(logger);
|
|
224
228
|
const {
|
|
225
229
|
creds
|
|
226
230
|
} = authState;
|
|
227
231
|
// add transaction capability
|
|
228
|
-
const keys = addTransactionCapability(authState.keys, logger, transactionOpts);
|
|
232
|
+
const keys = (0, _index4.addTransactionCapability)(authState.keys, logger, transactionOpts);
|
|
229
233
|
const signalRepository = makeSignalRepository({
|
|
230
234
|
creds,
|
|
231
235
|
keys
|
|
@@ -244,13 +248,13 @@ export const makeSocket = config => {
|
|
|
244
248
|
/** await the next incoming message */
|
|
245
249
|
const awaitNextMessage = async sendMsg => {
|
|
246
250
|
if (!ws.isOpen) {
|
|
247
|
-
throw new Boom('Connection Closed', {
|
|
248
|
-
statusCode: DisconnectReason.connectionClosed
|
|
251
|
+
throw new _boom.Boom('Connection Closed', {
|
|
252
|
+
statusCode: _index3.DisconnectReason.connectionClosed
|
|
249
253
|
});
|
|
250
254
|
}
|
|
251
255
|
let onOpen;
|
|
252
256
|
let onClose;
|
|
253
|
-
const result = promiseTimeout(connectTimeoutMs, (resolve, reject) => {
|
|
257
|
+
const result = (0, _index4.promiseTimeout)(connectTimeoutMs, (resolve, reject) => {
|
|
254
258
|
onOpen = resolve;
|
|
255
259
|
onClose = mapWebSocketError(reject);
|
|
256
260
|
ws.on('frame', onOpen);
|
|
@@ -273,32 +277,32 @@ export const makeSocket = config => {
|
|
|
273
277
|
ephemeral: ephemeralKeyPair.public
|
|
274
278
|
}
|
|
275
279
|
};
|
|
276
|
-
helloMsg = proto.HandshakeMessage.create(helloMsg);
|
|
280
|
+
helloMsg = _index.proto.HandshakeMessage.create(helloMsg);
|
|
277
281
|
logger.info({
|
|
278
282
|
browser,
|
|
279
283
|
helloMsg
|
|
280
284
|
}, 'connected to WA');
|
|
281
|
-
const init = proto.HandshakeMessage.encode(helloMsg).finish();
|
|
285
|
+
const init = _index.proto.HandshakeMessage.encode(helloMsg).finish();
|
|
282
286
|
const result = await awaitNextMessage(init);
|
|
283
|
-
const handshake = proto.HandshakeMessage.decode(result);
|
|
287
|
+
const handshake = _index.proto.HandshakeMessage.decode(result);
|
|
284
288
|
logger.trace({
|
|
285
289
|
handshake
|
|
286
290
|
}, 'handshake recv from WA');
|
|
287
291
|
const keyEnc = await noise.processHandshake(handshake, creds.noiseKey);
|
|
288
292
|
let node;
|
|
289
293
|
if (!creds.me) {
|
|
290
|
-
node = generateRegistrationNode(creds, config);
|
|
294
|
+
node = (0, _index4.generateRegistrationNode)(creds, config);
|
|
291
295
|
logger.info({
|
|
292
296
|
node
|
|
293
297
|
}, 'not logged in, attempting registration...');
|
|
294
298
|
} else {
|
|
295
|
-
node = generateLoginNode(creds.me.id, config);
|
|
299
|
+
node = (0, _index4.generateLoginNode)(creds.me.id, config);
|
|
296
300
|
logger.info({
|
|
297
301
|
node
|
|
298
302
|
}, 'logging in...');
|
|
299
303
|
}
|
|
300
|
-
const payloadEnc = noise.encrypt(proto.ClientPayload.encode(node).finish());
|
|
301
|
-
await sendRawMessage(proto.HandshakeMessage.encode({
|
|
304
|
+
const payloadEnc = noise.encrypt(_index.proto.ClientPayload.encode(node).finish());
|
|
305
|
+
await sendRawMessage(_index.proto.HandshakeMessage.encode({
|
|
302
306
|
clientFinish: {
|
|
303
307
|
static: keyEnc,
|
|
304
308
|
payload: payloadEnc
|
|
@@ -314,25 +318,25 @@ export const makeSocket = config => {
|
|
|
314
318
|
id: generateMessageTag(),
|
|
315
319
|
xmlns: 'encrypt',
|
|
316
320
|
type: 'get',
|
|
317
|
-
to: S_WHATSAPP_NET
|
|
321
|
+
to: _index5.S_WHATSAPP_NET
|
|
318
322
|
},
|
|
319
323
|
content: [{
|
|
320
324
|
tag: 'count',
|
|
321
325
|
attrs: {}
|
|
322
326
|
}]
|
|
323
327
|
});
|
|
324
|
-
const countChild = getBinaryNodeChild(result, 'count');
|
|
328
|
+
const countChild = (0, _index5.getBinaryNodeChild)(result, 'count');
|
|
325
329
|
return +countChild.attrs.value;
|
|
326
330
|
};
|
|
327
331
|
// Pre-key upload state management
|
|
328
332
|
let uploadPreKeysPromise = null;
|
|
329
333
|
let lastUploadTime = 0;
|
|
330
334
|
/** generates and uploads a set of pre-keys to the server */
|
|
331
|
-
const uploadPreKeys = async (count = INITIAL_PREKEY_COUNT, retryCount = 0) => {
|
|
335
|
+
const uploadPreKeys = async (count = _index2.INITIAL_PREKEY_COUNT, retryCount = 0) => {
|
|
332
336
|
// Check minimum interval (except for retries)
|
|
333
337
|
if (retryCount === 0) {
|
|
334
338
|
const timeSinceLastUpload = Date.now() - lastUploadTime;
|
|
335
|
-
if (timeSinceLastUpload < MIN_UPLOAD_INTERVAL) {
|
|
339
|
+
if (timeSinceLastUpload < _index2.MIN_UPLOAD_INTERVAL) {
|
|
336
340
|
logger.debug(`Skipping upload, only ${timeSinceLastUpload}ms since last upload`);
|
|
337
341
|
return;
|
|
338
342
|
}
|
|
@@ -355,7 +359,7 @@ export const makeSocket = config => {
|
|
|
355
359
|
const {
|
|
356
360
|
update,
|
|
357
361
|
node
|
|
358
|
-
} = await getNextPreKeysNode({
|
|
362
|
+
} = await (0, _index4.getNextPreKeysNode)({
|
|
359
363
|
creds,
|
|
360
364
|
keys
|
|
361
365
|
}, count);
|
|
@@ -386,9 +390,9 @@ export const makeSocket = config => {
|
|
|
386
390
|
}
|
|
387
391
|
};
|
|
388
392
|
// Add timeout protection
|
|
389
|
-
uploadPreKeysPromise = Promise.race([uploadLogic(), new Promise((_, reject) => setTimeout(() => reject(new Boom('Pre-key upload timeout', {
|
|
393
|
+
uploadPreKeysPromise = Promise.race([uploadLogic(), new Promise((_, reject) => setTimeout(() => reject(new _boom.Boom('Pre-key upload timeout', {
|
|
390
394
|
statusCode: 408
|
|
391
|
-
})), UPLOAD_TIMEOUT))]);
|
|
395
|
+
})), _index2.UPLOAD_TIMEOUT))]);
|
|
392
396
|
try {
|
|
393
397
|
await uploadPreKeysPromise;
|
|
394
398
|
} finally {
|
|
@@ -419,7 +423,7 @@ export const makeSocket = config => {
|
|
|
419
423
|
} = await verifyCurrentPreKeyExists();
|
|
420
424
|
logger.info(`${preKeyCount} pre-keys found on server`);
|
|
421
425
|
logger.info(`Current prekey ID: ${currentPreKeyId}, exists in storage: ${currentPreKeyExists}`);
|
|
422
|
-
const lowServerCount = preKeyCount <= MIN_PREKEY_COUNT;
|
|
426
|
+
const lowServerCount = preKeyCount <= _index2.MIN_PREKEY_COUNT;
|
|
423
427
|
const missingCurrentPreKey = !currentPreKeyExists && currentPreKeyId > 0;
|
|
424
428
|
const shouldUpload = lowServerCount || missingCurrentPreKey;
|
|
425
429
|
if (shouldUpload) {
|
|
@@ -449,23 +453,23 @@ export const makeSocket = config => {
|
|
|
449
453
|
const msgId = frame.attrs.id;
|
|
450
454
|
if (logger.level === 'trace') {
|
|
451
455
|
logger.trace({
|
|
452
|
-
xml: binaryNodeToString(frame),
|
|
456
|
+
xml: (0, _index5.binaryNodeToString)(frame),
|
|
453
457
|
msg: 'recv xml'
|
|
454
458
|
});
|
|
455
459
|
}
|
|
456
460
|
/* Check if this is a response to a message we sent */
|
|
457
|
-
anyTriggered = ws.emit(`${DEF_TAG_PREFIX}${msgId}`, frame) || anyTriggered;
|
|
461
|
+
anyTriggered = ws.emit(`${_index2.DEF_TAG_PREFIX}${msgId}`, frame) || anyTriggered;
|
|
458
462
|
/* Check if this is a response to a message we are expecting */
|
|
459
463
|
const l0 = frame.tag;
|
|
460
464
|
const l1 = frame.attrs || {};
|
|
461
465
|
const l2 = Array.isArray(frame.content) ? frame.content[0]?.tag : '';
|
|
462
466
|
for (const key of Object.keys(l1)) {
|
|
463
|
-
anyTriggered = ws.emit(`${DEF_CALLBACK_PREFIX}${l0},${key}:${l1[key]},${l2}`, frame) || anyTriggered;
|
|
464
|
-
anyTriggered = ws.emit(`${DEF_CALLBACK_PREFIX}${l0},${key}:${l1[key]}`, frame) || anyTriggered;
|
|
465
|
-
anyTriggered = ws.emit(`${DEF_CALLBACK_PREFIX}${l0},${key}`, frame) || anyTriggered;
|
|
467
|
+
anyTriggered = ws.emit(`${_index2.DEF_CALLBACK_PREFIX}${l0},${key}:${l1[key]},${l2}`, frame) || anyTriggered;
|
|
468
|
+
anyTriggered = ws.emit(`${_index2.DEF_CALLBACK_PREFIX}${l0},${key}:${l1[key]}`, frame) || anyTriggered;
|
|
469
|
+
anyTriggered = ws.emit(`${_index2.DEF_CALLBACK_PREFIX}${l0},${key}`, frame) || anyTriggered;
|
|
466
470
|
}
|
|
467
|
-
anyTriggered = ws.emit(`${DEF_CALLBACK_PREFIX}${l0},,${l2}`, frame) || anyTriggered;
|
|
468
|
-
anyTriggered = ws.emit(`${DEF_CALLBACK_PREFIX}${l0}`, frame) || anyTriggered;
|
|
471
|
+
anyTriggered = ws.emit(`${_index2.DEF_CALLBACK_PREFIX}${l0},,${l2}`, frame) || anyTriggered;
|
|
472
|
+
anyTriggered = ws.emit(`${_index2.DEF_CALLBACK_PREFIX}${l0}`, frame) || anyTriggered;
|
|
469
473
|
if (!anyTriggered && logger.level === 'debug') {
|
|
470
474
|
logger.debug({
|
|
471
475
|
unhandled: true,
|
|
@@ -512,8 +516,8 @@ export const makeSocket = config => {
|
|
|
512
516
|
return;
|
|
513
517
|
}
|
|
514
518
|
if (ws.isClosed || ws.isClosing) {
|
|
515
|
-
throw new Boom('Connection Closed', {
|
|
516
|
-
statusCode: DisconnectReason.connectionClosed
|
|
519
|
+
throw new _boom.Boom('Connection Closed', {
|
|
520
|
+
statusCode: _index3.DisconnectReason.connectionClosed
|
|
517
521
|
});
|
|
518
522
|
}
|
|
519
523
|
let onOpen;
|
|
@@ -540,8 +544,8 @@ export const makeSocket = config => {
|
|
|
540
544
|
it could be that the network is down
|
|
541
545
|
*/
|
|
542
546
|
if (diff > keepAliveIntervalMs + 5000) {
|
|
543
|
-
end(new Boom('Connection was lost', {
|
|
544
|
-
statusCode: DisconnectReason.connectionLost
|
|
547
|
+
end(new _boom.Boom('Connection was lost', {
|
|
548
|
+
statusCode: _index3.DisconnectReason.connectionLost
|
|
545
549
|
}));
|
|
546
550
|
} else if (ws.isOpen) {
|
|
547
551
|
// if its all good, send a keep alive request
|
|
@@ -549,7 +553,7 @@ export const makeSocket = config => {
|
|
|
549
553
|
tag: 'iq',
|
|
550
554
|
attrs: {
|
|
551
555
|
id: generateMessageTag(),
|
|
552
|
-
to: S_WHATSAPP_NET,
|
|
556
|
+
to: _index5.S_WHATSAPP_NET,
|
|
553
557
|
type: 'get',
|
|
554
558
|
xmlns: 'w:p'
|
|
555
559
|
},
|
|
@@ -570,7 +574,7 @@ export const makeSocket = config => {
|
|
|
570
574
|
const sendPassiveIq = tag => query({
|
|
571
575
|
tag: 'iq',
|
|
572
576
|
attrs: {
|
|
573
|
-
to: S_WHATSAPP_NET,
|
|
577
|
+
to: _index5.S_WHATSAPP_NET,
|
|
574
578
|
xmlns: 'passive',
|
|
575
579
|
type: 'set'
|
|
576
580
|
},
|
|
@@ -586,7 +590,7 @@ export const makeSocket = config => {
|
|
|
586
590
|
await sendNode({
|
|
587
591
|
tag: 'iq',
|
|
588
592
|
attrs: {
|
|
589
|
-
to: S_WHATSAPP_NET,
|
|
593
|
+
to: _index5.S_WHATSAPP_NET,
|
|
590
594
|
type: 'set',
|
|
591
595
|
id: generateMessageTag(),
|
|
592
596
|
xmlns: 'md'
|
|
@@ -600,25 +604,25 @@ export const makeSocket = config => {
|
|
|
600
604
|
}]
|
|
601
605
|
});
|
|
602
606
|
}
|
|
603
|
-
end(new Boom(msg || 'Intentional Logout', {
|
|
604
|
-
statusCode: DisconnectReason.loggedOut
|
|
607
|
+
end(new _boom.Boom(msg || 'Intentional Logout', {
|
|
608
|
+
statusCode: _index3.DisconnectReason.loggedOut
|
|
605
609
|
}));
|
|
606
610
|
};
|
|
607
611
|
const requestPairingCode = async (phoneNumber, customPairingCode) => {
|
|
608
|
-
const pairingCode = customPairingCode ?? bytesToCrockford(randomBytes(5));
|
|
612
|
+
const pairingCode = customPairingCode ?? (0, _index4.bytesToCrockford)((0, _crypto.randomBytes)(5));
|
|
609
613
|
if (customPairingCode && customPairingCode?.length !== 8) {
|
|
610
614
|
throw new Error('Custom pairing code must be exactly 8 chars');
|
|
611
615
|
}
|
|
612
616
|
authState.creds.pairingCode = pairingCode;
|
|
613
617
|
authState.creds.me = {
|
|
614
|
-
id: jidEncode(phoneNumber, 's.whatsapp.net'),
|
|
618
|
+
id: (0, _index5.jidEncode)(phoneNumber, 's.whatsapp.net'),
|
|
615
619
|
name: '~'
|
|
616
620
|
};
|
|
617
621
|
ev.emit('creds.update', authState.creds);
|
|
618
622
|
await sendNode({
|
|
619
623
|
tag: 'iq',
|
|
620
624
|
attrs: {
|
|
621
|
-
to: S_WHATSAPP_NET,
|
|
625
|
+
to: _index5.S_WHATSAPP_NET,
|
|
622
626
|
type: 'set',
|
|
623
627
|
id: generateMessageTag(),
|
|
624
628
|
xmlns: 'md'
|
|
@@ -641,7 +645,7 @@ export const makeSocket = config => {
|
|
|
641
645
|
}, {
|
|
642
646
|
tag: 'companion_platform_id',
|
|
643
647
|
attrs: {},
|
|
644
|
-
content: getPlatformId(browser[1])
|
|
648
|
+
content: (0, _index4.getPlatformId)(browser[1])
|
|
645
649
|
}, {
|
|
646
650
|
tag: 'companion_platform_display',
|
|
647
651
|
attrs: {},
|
|
@@ -656,17 +660,17 @@ export const makeSocket = config => {
|
|
|
656
660
|
return authState.creds.pairingCode;
|
|
657
661
|
};
|
|
658
662
|
async function generatePairingKey() {
|
|
659
|
-
const salt = randomBytes(32);
|
|
660
|
-
const randomIv = randomBytes(16);
|
|
661
|
-
const key = await derivePairingCodeKey(authState.creds.pairingCode, salt);
|
|
662
|
-
const ciphered = aesEncryptCTR(authState.creds.pairingEphemeralKeyPair.public, key, randomIv);
|
|
663
|
+
const salt = (0, _crypto.randomBytes)(32);
|
|
664
|
+
const randomIv = (0, _crypto.randomBytes)(16);
|
|
665
|
+
const key = await (0, _index4.derivePairingCodeKey)(authState.creds.pairingCode, salt);
|
|
666
|
+
const ciphered = (0, _index4.aesEncryptCTR)(authState.creds.pairingEphemeralKeyPair.public, key, randomIv);
|
|
663
667
|
return Buffer.concat([salt, randomIv, ciphered]);
|
|
664
668
|
}
|
|
665
669
|
const sendWAMBuffer = wamBuffer => {
|
|
666
670
|
return query({
|
|
667
671
|
tag: 'iq',
|
|
668
672
|
attrs: {
|
|
669
|
-
to: S_WHATSAPP_NET,
|
|
673
|
+
to: _index5.S_WHATSAPP_NET,
|
|
670
674
|
id: generateMessageTag(),
|
|
671
675
|
xmlns: 'w:stats'
|
|
672
676
|
},
|
|
@@ -689,26 +693,26 @@ export const makeSocket = config => {
|
|
|
689
693
|
}
|
|
690
694
|
});
|
|
691
695
|
ws.on('error', mapWebSocketError(end));
|
|
692
|
-
ws.on('close', () => end(new Boom('Connection Terminated', {
|
|
693
|
-
statusCode: DisconnectReason.connectionClosed
|
|
696
|
+
ws.on('close', () => end(new _boom.Boom('Connection Terminated', {
|
|
697
|
+
statusCode: _index3.DisconnectReason.connectionClosed
|
|
694
698
|
})));
|
|
695
699
|
// the server terminated the connection
|
|
696
|
-
ws.on('CB:xmlstreamend', () => end(new Boom('Connection Terminated by Server', {
|
|
697
|
-
statusCode: DisconnectReason.connectionClosed
|
|
700
|
+
ws.on('CB:xmlstreamend', () => end(new _boom.Boom('Connection Terminated by Server', {
|
|
701
|
+
statusCode: _index3.DisconnectReason.connectionClosed
|
|
698
702
|
})));
|
|
699
703
|
// QR gen
|
|
700
704
|
ws.on('CB:iq,type:set,pair-device', async stanza => {
|
|
701
705
|
const iq = {
|
|
702
706
|
tag: 'iq',
|
|
703
707
|
attrs: {
|
|
704
|
-
to: S_WHATSAPP_NET,
|
|
708
|
+
to: _index5.S_WHATSAPP_NET,
|
|
705
709
|
type: 'result',
|
|
706
710
|
id: stanza.attrs.id
|
|
707
711
|
}
|
|
708
712
|
};
|
|
709
713
|
await sendNode(iq);
|
|
710
|
-
const pairDeviceNode = getBinaryNodeChild(stanza, 'pair-device');
|
|
711
|
-
const refNodes = getBinaryNodeChildren(pairDeviceNode, 'ref');
|
|
714
|
+
const pairDeviceNode = (0, _index5.getBinaryNodeChild)(stanza, 'pair-device');
|
|
715
|
+
const refNodes = (0, _index5.getBinaryNodeChildren)(pairDeviceNode, 'ref');
|
|
712
716
|
const noiseKeyB64 = Buffer.from(creds.noiseKey.public).toString('base64');
|
|
713
717
|
const identityKeyB64 = Buffer.from(creds.signedIdentityKey.public).toString('base64');
|
|
714
718
|
const advB64 = creds.advSecretKey;
|
|
@@ -719,8 +723,8 @@ export const makeSocket = config => {
|
|
|
719
723
|
}
|
|
720
724
|
const refNode = refNodes.shift();
|
|
721
725
|
if (!refNode) {
|
|
722
|
-
end(new Boom('QR refs attempts ended', {
|
|
723
|
-
statusCode: DisconnectReason.timedOut
|
|
726
|
+
end(new _boom.Boom('QR refs attempts ended', {
|
|
727
|
+
statusCode: _index3.DisconnectReason.timedOut
|
|
724
728
|
}));
|
|
725
729
|
return;
|
|
726
730
|
}
|
|
@@ -742,7 +746,7 @@ export const makeSocket = config => {
|
|
|
742
746
|
const {
|
|
743
747
|
reply,
|
|
744
748
|
creds: updatedCreds
|
|
745
|
-
} = configureSuccessfulPairing(stanza, creds);
|
|
749
|
+
} = (0, _index4.configureSuccessfulPairing)(stanza, creds);
|
|
746
750
|
logger.info({
|
|
747
751
|
me: updatedCreds.me,
|
|
748
752
|
platform: updatedCreds.platform
|
|
@@ -810,8 +814,8 @@ export const makeSocket = config => {
|
|
|
810
814
|
const {
|
|
811
815
|
reason,
|
|
812
816
|
statusCode
|
|
813
|
-
} = getErrorCodeFromStreamError(node);
|
|
814
|
-
end(new Boom(`Stream Errored (${reason})`, {
|
|
817
|
+
} = (0, _index4.getErrorCodeFromStreamError)(node);
|
|
818
|
+
end(new _boom.Boom(`Stream Errored (${reason})`, {
|
|
815
819
|
statusCode,
|
|
816
820
|
data: node
|
|
817
821
|
}));
|
|
@@ -819,14 +823,14 @@ export const makeSocket = config => {
|
|
|
819
823
|
// stream fail, possible logout
|
|
820
824
|
ws.on('CB:failure', node => {
|
|
821
825
|
const reason = +(node.attrs.reason || 500);
|
|
822
|
-
end(new Boom('Connection Failure', {
|
|
826
|
+
end(new _boom.Boom('Connection Failure', {
|
|
823
827
|
statusCode: reason,
|
|
824
828
|
data: node.attrs
|
|
825
829
|
}));
|
|
826
830
|
});
|
|
827
831
|
ws.on('CB:ib,,downgrade_webclient', () => {
|
|
828
|
-
end(new Boom('Multi-device beta not joined', {
|
|
829
|
-
statusCode: DisconnectReason.multideviceMismatch
|
|
832
|
+
end(new _boom.Boom('Multi-device beta not joined', {
|
|
833
|
+
statusCode: _index3.DisconnectReason.multideviceMismatch
|
|
830
834
|
}));
|
|
831
835
|
});
|
|
832
836
|
ws.on('CB:ib,,offline_preview', node => {
|
|
@@ -843,8 +847,8 @@ export const makeSocket = config => {
|
|
|
843
847
|
});
|
|
844
848
|
});
|
|
845
849
|
ws.on('CB:ib,,edge_routing', node => {
|
|
846
|
-
const edgeRoutingNode = getBinaryNodeChild(node, 'edge_routing');
|
|
847
|
-
const routingInfo = getBinaryNodeChild(edgeRoutingNode, 'routing_info');
|
|
850
|
+
const edgeRoutingNode = (0, _index5.getBinaryNodeChild)(node, 'edge_routing');
|
|
851
|
+
const routingInfo = (0, _index5.getBinaryNodeChild)(edgeRoutingNode, 'routing_info');
|
|
848
852
|
if (routingInfo?.content) {
|
|
849
853
|
authState.creds.routingInfo = Buffer.from(routingInfo?.content);
|
|
850
854
|
ev.emit('creds.update', authState.creds);
|
|
@@ -866,7 +870,7 @@ export const makeSocket = config => {
|
|
|
866
870
|
});
|
|
867
871
|
// called when all offline notifs are handled
|
|
868
872
|
ws.on('CB:ib,,offline', node => {
|
|
869
|
-
const child = getBinaryNodeChild(node, 'offline');
|
|
873
|
+
const child = (0, _index5.getBinaryNodeChild)(node, 'offline');
|
|
870
874
|
const offlineNotifs = +(child?.attrs.count || 0);
|
|
871
875
|
logger.info(`handled ${offlineNotifs} offline messages/notifications`);
|
|
872
876
|
if (didStartBuffer) {
|
|
@@ -923,7 +927,7 @@ export const makeSocket = config => {
|
|
|
923
927
|
uploadPreKeysToServerIfRequired,
|
|
924
928
|
requestPairingCode,
|
|
925
929
|
/** Waits for the connection to WA to reach a state */
|
|
926
|
-
waitForConnectionUpdate: bindWaitForConnectionUpdate(ev),
|
|
930
|
+
waitForConnectionUpdate: (0, _index4.bindWaitForConnectionUpdate)(ev),
|
|
927
931
|
sendWAMBuffer,
|
|
928
932
|
executeUSyncQuery,
|
|
929
933
|
onWhatsApp
|
|
@@ -933,12 +937,12 @@ export const makeSocket = config => {
|
|
|
933
937
|
* map the websocket error to the right type
|
|
934
938
|
* so it can be retried by the caller
|
|
935
939
|
* */
|
|
940
|
+
exports.makeSocket = makeSocket;
|
|
936
941
|
function mapWebSocketError(handler) {
|
|
937
942
|
return error => {
|
|
938
|
-
handler(new Boom(`WebSocket Error (${error?.message})`, {
|
|
939
|
-
statusCode: getCodeFromWSError(error),
|
|
943
|
+
handler(new _boom.Boom(`WebSocket Error (${error?.message})`, {
|
|
944
|
+
statusCode: (0, _index4.getCodeFromWSError)(error),
|
|
940
945
|
data: error
|
|
941
946
|
}));
|
|
942
947
|
};
|
|
943
|
-
}
|
|
944
|
-
//# sourceMappingURL=socket.js.map
|
|
948
|
+
}
|
package/lib/Store/index.js
CHANGED
|
@@ -1,4 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
Object.defineProperty(exports, "__esModule", {
|
|
2
|
+
value: true
|
|
3
|
+
});
|
|
4
|
+
var _makeInMemoryStore = require("./make-in-memory-store.js");
|
|
5
|
+
Object.keys(_makeInMemoryStore).forEach(function (key) {
|
|
6
|
+
if (key === "default" || key === "__esModule") return;
|
|
7
|
+
if (key in exports && exports[key] === _makeInMemoryStore[key]) return;
|
|
8
|
+
Object.defineProperty(exports, key, {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function () {
|
|
11
|
+
return _makeInMemoryStore[key];
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
var _makeCacheManagerStore = require("./make-cache-manager-store.js");
|
|
16
|
+
Object.keys(_makeCacheManagerStore).forEach(function (key) {
|
|
17
|
+
if (key === "default" || key === "__esModule") return;
|
|
18
|
+
if (key in exports && exports[key] === _makeCacheManagerStore[key]) return;
|
|
19
|
+
Object.defineProperty(exports, key, {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function () {
|
|
22
|
+
return _makeCacheManagerStore[key];
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
var _makeOrderedDictionary = require("./make-ordered-dictionary.js");
|
|
27
|
+
Object.keys(_makeOrderedDictionary).forEach(function (key) {
|
|
28
|
+
if (key === "default" || key === "__esModule") return;
|
|
29
|
+
if (key in exports && exports[key] === _makeOrderedDictionary[key]) return;
|
|
30
|
+
Object.defineProperty(exports, key, {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _makeOrderedDictionary[key];
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
var _objectRepository = require("./object-repository.js");
|
|
38
|
+
Object.keys(_objectRepository).forEach(function (key) {
|
|
39
|
+
if (key === "default" || key === "__esModule") return;
|
|
40
|
+
if (key in exports && exports[key] === _objectRepository[key]) return;
|
|
41
|
+
Object.defineProperty(exports, key, {
|
|
42
|
+
enumerable: true,
|
|
43
|
+
get: function () {
|
|
44
|
+
return _objectRepository[key];
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
});
|