@d0v3riz/baileys 6.7.21 → 6.7.22
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/GenerateStatics.sh +2 -3
- package/WAProto/index.js +4138 -4136
- package/lib/Defaults/index.d.ts +2 -3
- package/lib/Defaults/index.js +40 -36
- package/lib/Signal/Group/ciphertext-message.d.ts +0 -1
- package/lib/Signal/Group/ciphertext-message.js +5 -2
- package/lib/Signal/Group/group-session-builder.d.ts +3 -4
- package/lib/Signal/Group/group-session-builder.js +41 -7
- package/lib/Signal/Group/group_cipher.d.ts +2 -3
- package/lib/Signal/Group/group_cipher.js +16 -14
- package/lib/Signal/Group/index.d.ts +11 -12
- package/lib/Signal/Group/index.js +57 -12
- package/lib/Signal/Group/keyhelper.d.ts +1 -2
- package/lib/Signal/Group/keyhelper.js +44 -8
- package/lib/Signal/Group/queue-job.d.ts +0 -2
- package/lib/Signal/Group/queue-job.js +5 -5
- package/lib/Signal/Group/sender-chain-key.d.ts +1 -2
- package/lib/Signal/Group/sender-chain-key.js +9 -7
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +1 -2
- package/lib/Signal/Group/sender-key-distribution-message.js +9 -6
- package/lib/Signal/Group/sender-key-message.d.ts +1 -2
- package/lib/Signal/Group/sender-key-message.js +12 -10
- package/lib/Signal/Group/sender-key-name.d.ts +0 -1
- package/lib/Signal/Group/sender-key-name.js +5 -2
- package/lib/Signal/Group/sender-key-record.d.ts +1 -2
- package/lib/Signal/Group/sender-key-record.js +12 -9
- package/lib/Signal/Group/sender-key-state.d.ts +2 -3
- package/lib/Signal/Group/sender-key-state.js +9 -6
- package/lib/Signal/Group/sender-message-key.d.ts +0 -1
- package/lib/Signal/Group/sender-message-key.js +7 -5
- package/lib/Signal/libsignal.d.ts +2 -3
- package/lib/Signal/libsignal.js +55 -22
- package/lib/Socket/Client/index.d.ts +2 -3
- package/lib/Socket/Client/index.js +18 -3
- package/lib/Socket/Client/types.d.ts +1 -2
- package/lib/Socket/Client/types.js +6 -4
- package/lib/Socket/Client/websocket.d.ts +1 -2
- package/lib/Socket/Client/websocket.js +26 -14
- package/lib/Socket/business.d.ts +64 -66
- package/lib/Socket/business.js +37 -32
- package/lib/Socket/chats.d.ts +19 -21
- package/lib/Socket/chats.js +141 -176
- package/lib/Socket/groups.d.ts +35 -37
- package/lib/Socket/groups.js +63 -56
- package/lib/Socket/index.d.ts +70 -102
- package/lib/Socket/index.js +9 -16
- package/lib/Socket/messages-recv.d.ts +49 -51
- package/lib/Socket/messages-recv.js +173 -180
- package/lib/Socket/messages-send.d.ts +46 -48
- package/lib/Socket/messages-send.js +84 -75
- package/lib/Socket/mex.d.ts +1 -2
- package/lib/Socket/mex.js +16 -12
- package/lib/Socket/newsletter.d.ts +44 -46
- package/lib/Socket/newsletter.js +27 -23
- package/lib/Socket/socket.d.ts +12 -13
- package/lib/Socket/socket.js +115 -135
- package/lib/Socket/usync.d.ts +14 -15
- package/lib/Socket/usync.js +11 -9
- package/lib/Types/Auth.d.ts +3 -4
- package/lib/Types/Auth.js +2 -2
- package/lib/Types/Call.d.ts +0 -1
- package/lib/Types/Call.js +2 -2
- package/lib/Types/Chat.d.ts +7 -10
- package/lib/Types/Chat.js +4 -2
- package/lib/Types/Contact.d.ts +0 -1
- package/lib/Types/Contact.js +2 -2
- package/lib/Types/Events.d.ts +10 -11
- package/lib/Types/Events.js +2 -2
- package/lib/Types/GroupMetadata.d.ts +2 -3
- package/lib/Types/GroupMetadata.js +2 -2
- package/lib/Types/Label.d.ts +0 -1
- package/lib/Types/Label.js +5 -3
- package/lib/Types/LabelAssociation.d.ts +0 -1
- package/lib/Types/LabelAssociation.js +5 -3
- package/lib/Types/Message.d.ts +7 -9
- package/lib/Types/Message.js +7 -7
- package/lib/Types/Newsletter.d.ts +0 -1
- package/lib/Types/Newsletter.js +7 -5
- package/lib/Types/Product.d.ts +1 -2
- package/lib/Types/Product.js +2 -2
- package/lib/Types/Signal.d.ts +1 -2
- package/lib/Types/Signal.js +2 -2
- package/lib/Types/Socket.d.ts +7 -8
- package/lib/Types/Socket.js +2 -3
- package/lib/Types/State.d.ts +2 -14
- package/lib/Types/State.js +2 -13
- package/lib/Types/USync.d.ts +2 -3
- package/lib/Types/USync.js +2 -2
- package/lib/Types/index.d.ts +14 -15
- package/lib/Types/index.js +31 -15
- package/lib/Utils/auth-utils.d.ts +2 -3
- package/lib/Utils/auth-utils.js +34 -25
- package/lib/Utils/baileys-event-stream.d.ts +1 -2
- package/lib/Utils/baileys-event-stream.js +22 -15
- package/lib/Utils/business.d.ts +2 -3
- package/lib/Utils/business.js +70 -61
- package/lib/Utils/chat-utils.d.ts +7 -8
- package/lib/Utils/chat-utils.js +137 -130
- package/lib/Utils/crypto.d.ts +1 -2
- package/lib/Utils/crypto.js +86 -37
- package/lib/Utils/decode-wa-message.d.ts +4 -5
- package/lib/Utils/decode-wa-message.js +44 -38
- package/lib/Utils/event-buffer.d.ts +4 -4
- package/lib/Utils/event-buffer.js +50 -37
- package/lib/Utils/generics.d.ts +8 -9
- package/lib/Utils/generics.js +114 -87
- package/lib/Utils/history.d.ts +3 -4
- package/lib/Utils/history.js +40 -32
- package/lib/Utils/index.d.ts +17 -18
- package/lib/Utils/index.js +33 -18
- package/lib/Utils/link-preview.d.ts +3 -4
- package/lib/Utils/link-preview.js +47 -10
- package/lib/Utils/logger.d.ts +6 -8
- package/lib/Utils/logger.js +7 -3
- package/lib/Utils/lt-hash.d.ts +8 -9
- package/lib/Utils/lt-hash.js +26 -23
- package/lib/Utils/make-mutex.d.ts +0 -1
- package/lib/Utils/make-mutex.js +9 -5
- package/lib/Utils/messages-media.d.ts +10 -11
- package/lib/Utils/messages-media.js +203 -141
- package/lib/Utils/messages.d.ts +6 -7
- package/lib/Utils/messages.js +199 -190
- package/lib/Utils/noise-handler.d.ts +4 -5
- package/lib/Utils/noise-handler.js +26 -22
- package/lib/Utils/process-message.d.ts +4 -5
- package/lib/Utils/process-message.js +104 -95
- package/lib/Utils/signal.d.ts +4 -5
- package/lib/Utils/signal.js +52 -47
- package/lib/Utils/use-multi-file-auth-state.d.ts +1 -2
- package/lib/Utils/use-multi-file-auth-state.js +26 -23
- package/lib/Utils/validate-connection.d.ts +3 -4
- package/lib/Utils/validate-connection.js +58 -52
- package/lib/WABinary/constants.d.ts +0 -1
- package/lib/WABinary/constants.js +11 -9
- package/lib/WABinary/decode.d.ts +1 -2
- package/lib/WABinary/decode.js +51 -13
- package/lib/WABinary/encode.d.ts +1 -2
- package/lib/WABinary/encode.js +41 -5
- package/lib/WABinary/generic-utils.d.ts +3 -4
- package/lib/WABinary/generic-utils.js +38 -30
- package/lib/WABinary/index.d.ts +5 -6
- package/lib/WABinary/index.js +21 -6
- package/lib/WABinary/jid-utils.d.ts +0 -1
- package/lib/WABinary/jid-utils.js +35 -21
- package/lib/WABinary/types.d.ts +1 -2
- package/lib/WABinary/types.js +2 -2
- package/lib/WAM/BinaryInfo.d.ts +1 -2
- package/lib/WAM/BinaryInfo.js +5 -2
- package/lib/WAM/constants.d.ts +0 -1
- package/lib/WAM/constants.js +6 -4
- package/lib/WAM/encode.d.ts +1 -2
- package/lib/WAM/encode.js +14 -12
- package/lib/WAM/index.d.ts +3 -4
- package/lib/WAM/index.js +19 -4
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +3 -4
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +9 -6
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +2 -3
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +12 -9
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +2 -3
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +9 -6
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +2 -3
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +11 -7
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +3 -4
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +21 -19
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +2 -3
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +5 -2
- package/lib/WAUSync/Protocols/index.d.ts +4 -5
- package/lib/WAUSync/Protocols/index.js +20 -5
- package/lib/WAUSync/USyncQuery.d.ts +3 -4
- package/lib/WAUSync/USyncQuery.js +20 -18
- package/lib/WAUSync/USyncUser.d.ts +5 -6
- package/lib/WAUSync/USyncUser.js +5 -2
- package/lib/WAUSync/index.d.ts +3 -4
- package/lib/WAUSync/index.js +19 -4
- package/lib/index.d.ts +8 -9
- package/lib/index.js +30 -11
- package/package.json +26 -26
- package/WAProto/fix-imports.js +0 -29
- package/lib/Defaults/index.d.ts.map +0 -1
- package/lib/Defaults/index.js.map +0 -1
- package/lib/Signal/Group/ciphertext-message.d.ts.map +0 -1
- package/lib/Signal/Group/ciphertext-message.js.map +0 -1
- package/lib/Signal/Group/group-session-builder.d.ts.map +0 -1
- package/lib/Signal/Group/group-session-builder.js.map +0 -1
- package/lib/Signal/Group/group_cipher.d.ts.map +0 -1
- package/lib/Signal/Group/group_cipher.js.map +0 -1
- package/lib/Signal/Group/index.d.ts.map +0 -1
- package/lib/Signal/Group/index.js.map +0 -1
- package/lib/Signal/Group/keyhelper.d.ts.map +0 -1
- package/lib/Signal/Group/keyhelper.js.map +0 -1
- package/lib/Signal/Group/queue-job.d.ts.map +0 -1
- package/lib/Signal/Group/queue-job.js.map +0 -1
- package/lib/Signal/Group/sender-chain-key.d.ts.map +0 -1
- package/lib/Signal/Group/sender-chain-key.js.map +0 -1
- package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +0 -1
- package/lib/Signal/Group/sender-key-distribution-message.js.map +0 -1
- package/lib/Signal/Group/sender-key-message.d.ts.map +0 -1
- package/lib/Signal/Group/sender-key-message.js.map +0 -1
- package/lib/Signal/Group/sender-key-name.d.ts.map +0 -1
- package/lib/Signal/Group/sender-key-name.js.map +0 -1
- package/lib/Signal/Group/sender-key-record.d.ts.map +0 -1
- package/lib/Signal/Group/sender-key-record.js.map +0 -1
- package/lib/Signal/Group/sender-key-state.d.ts.map +0 -1
- package/lib/Signal/Group/sender-key-state.js.map +0 -1
- package/lib/Signal/Group/sender-message-key.d.ts.map +0 -1
- package/lib/Signal/Group/sender-message-key.js.map +0 -1
- package/lib/Signal/libsignal.d.ts.map +0 -1
- package/lib/Signal/libsignal.js.map +0 -1
- package/lib/Socket/Client/index.d.ts.map +0 -1
- package/lib/Socket/Client/index.js.map +0 -1
- package/lib/Socket/Client/types.d.ts.map +0 -1
- package/lib/Socket/Client/types.js.map +0 -1
- package/lib/Socket/Client/websocket.d.ts.map +0 -1
- package/lib/Socket/Client/websocket.js.map +0 -1
- package/lib/Socket/business.d.ts.map +0 -1
- package/lib/Socket/business.js.map +0 -1
- package/lib/Socket/chats.d.ts.map +0 -1
- package/lib/Socket/chats.js.map +0 -1
- package/lib/Socket/communities.d.ts +0 -219
- package/lib/Socket/communities.d.ts.map +0 -1
- package/lib/Socket/communities.js +0 -351
- package/lib/Socket/communities.js.map +0 -1
- package/lib/Socket/groups.d.ts.map +0 -1
- package/lib/Socket/groups.js.map +0 -1
- package/lib/Socket/index.d.ts.map +0 -1
- package/lib/Socket/index.js.map +0 -1
- package/lib/Socket/messages-recv.d.ts.map +0 -1
- package/lib/Socket/messages-recv.js.map +0 -1
- package/lib/Socket/messages-send.d.ts.map +0 -1
- package/lib/Socket/messages-send.js.map +0 -1
- package/lib/Socket/mex.d.ts.map +0 -1
- package/lib/Socket/mex.js.map +0 -1
- package/lib/Socket/newsletter.d.ts.map +0 -1
- package/lib/Socket/newsletter.js.map +0 -1
- package/lib/Socket/socket.d.ts.map +0 -1
- package/lib/Socket/socket.js.map +0 -1
- package/lib/Socket/usync.d.ts.map +0 -1
- package/lib/Socket/usync.js.map +0 -1
- package/lib/Types/Auth.d.ts.map +0 -1
- package/lib/Types/Auth.js.map +0 -1
- package/lib/Types/Call.d.ts.map +0 -1
- package/lib/Types/Call.js.map +0 -1
- package/lib/Types/Chat.d.ts.map +0 -1
- package/lib/Types/Chat.js.map +0 -1
- package/lib/Types/Contact.d.ts.map +0 -1
- package/lib/Types/Contact.js.map +0 -1
- package/lib/Types/Events.d.ts.map +0 -1
- package/lib/Types/Events.js.map +0 -1
- package/lib/Types/GroupMetadata.d.ts.map +0 -1
- package/lib/Types/GroupMetadata.js.map +0 -1
- package/lib/Types/Label.d.ts.map +0 -1
- package/lib/Types/Label.js.map +0 -1
- package/lib/Types/LabelAssociation.d.ts.map +0 -1
- package/lib/Types/LabelAssociation.js.map +0 -1
- package/lib/Types/Message.d.ts.map +0 -1
- package/lib/Types/Message.js.map +0 -1
- package/lib/Types/Newsletter.d.ts.map +0 -1
- package/lib/Types/Newsletter.js.map +0 -1
- package/lib/Types/Product.d.ts.map +0 -1
- package/lib/Types/Product.js.map +0 -1
- package/lib/Types/Signal.d.ts.map +0 -1
- package/lib/Types/Signal.js.map +0 -1
- package/lib/Types/Socket.d.ts.map +0 -1
- package/lib/Types/Socket.js.map +0 -1
- package/lib/Types/State.d.ts.map +0 -1
- package/lib/Types/State.js.map +0 -1
- package/lib/Types/USync.d.ts.map +0 -1
- package/lib/Types/USync.js.map +0 -1
- package/lib/Types/index.d.ts.map +0 -1
- package/lib/Types/index.js.map +0 -1
- package/lib/Utils/auth-utils.d.ts.map +0 -1
- package/lib/Utils/auth-utils.js.map +0 -1
- package/lib/Utils/baileys-event-stream.d.ts.map +0 -1
- package/lib/Utils/baileys-event-stream.js.map +0 -1
- package/lib/Utils/business.d.ts.map +0 -1
- package/lib/Utils/business.js.map +0 -1
- package/lib/Utils/chat-utils.d.ts.map +0 -1
- package/lib/Utils/chat-utils.js.map +0 -1
- package/lib/Utils/crypto.d.ts.map +0 -1
- package/lib/Utils/crypto.js.map +0 -1
- package/lib/Utils/decode-wa-message.d.ts.map +0 -1
- package/lib/Utils/decode-wa-message.js.map +0 -1
- package/lib/Utils/event-buffer.d.ts.map +0 -1
- package/lib/Utils/event-buffer.js.map +0 -1
- package/lib/Utils/generics.d.ts.map +0 -1
- package/lib/Utils/generics.js.map +0 -1
- package/lib/Utils/history.d.ts.map +0 -1
- package/lib/Utils/history.js.map +0 -1
- package/lib/Utils/index.d.ts.map +0 -1
- package/lib/Utils/index.js.map +0 -1
- package/lib/Utils/link-preview.d.ts.map +0 -1
- package/lib/Utils/link-preview.js.map +0 -1
- package/lib/Utils/logger.d.ts.map +0 -1
- package/lib/Utils/logger.js.map +0 -1
- package/lib/Utils/lt-hash.d.ts.map +0 -1
- package/lib/Utils/lt-hash.js.map +0 -1
- package/lib/Utils/make-mutex.d.ts.map +0 -1
- package/lib/Utils/make-mutex.js.map +0 -1
- package/lib/Utils/messages-media.d.ts.map +0 -1
- package/lib/Utils/messages-media.js.map +0 -1
- package/lib/Utils/messages.d.ts.map +0 -1
- package/lib/Utils/messages.js.map +0 -1
- package/lib/Utils/noise-handler.d.ts.map +0 -1
- package/lib/Utils/noise-handler.js.map +0 -1
- package/lib/Utils/process-message.d.ts.map +0 -1
- package/lib/Utils/process-message.js.map +0 -1
- package/lib/Utils/signal.d.ts.map +0 -1
- package/lib/Utils/signal.js.map +0 -1
- package/lib/Utils/use-multi-file-auth-state.d.ts.map +0 -1
- package/lib/Utils/use-multi-file-auth-state.js.map +0 -1
- package/lib/Utils/validate-connection.d.ts.map +0 -1
- package/lib/Utils/validate-connection.js.map +0 -1
- package/lib/WABinary/constants.d.ts.map +0 -1
- package/lib/WABinary/constants.js.map +0 -1
- package/lib/WABinary/decode.d.ts.map +0 -1
- package/lib/WABinary/decode.js.map +0 -1
- package/lib/WABinary/encode.d.ts.map +0 -1
- package/lib/WABinary/encode.js.map +0 -1
- package/lib/WABinary/generic-utils.d.ts.map +0 -1
- package/lib/WABinary/generic-utils.js.map +0 -1
- package/lib/WABinary/index.d.ts.map +0 -1
- package/lib/WABinary/index.js.map +0 -1
- package/lib/WABinary/jid-utils.d.ts.map +0 -1
- package/lib/WABinary/jid-utils.js.map +0 -1
- package/lib/WABinary/types.d.ts.map +0 -1
- package/lib/WABinary/types.js.map +0 -1
- package/lib/WAM/BinaryInfo.d.ts.map +0 -1
- package/lib/WAM/BinaryInfo.js.map +0 -1
- package/lib/WAM/constants.d.ts.map +0 -1
- package/lib/WAM/constants.js.map +0 -1
- package/lib/WAM/encode.d.ts.map +0 -1
- package/lib/WAM/encode.js.map +0 -1
- package/lib/WAM/index.d.ts.map +0 -1
- package/lib/WAM/index.js.map +0 -1
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/index.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/index.js.map +0 -1
- package/lib/WAUSync/USyncQuery.d.ts.map +0 -1
- package/lib/WAUSync/USyncQuery.js.map +0 -1
- package/lib/WAUSync/USyncUser.d.ts.map +0 -1
- package/lib/WAUSync/USyncUser.js.map +0 -1
- package/lib/WAUSync/index.d.ts.map +0 -1
- package/lib/WAUSync/index.js.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
package/lib/Socket/socket.js
CHANGED
|
@@ -1,63 +1,66 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeSocket = void 0;
|
|
4
|
+
const boom_1 = require("@hapi/boom");
|
|
5
|
+
const crypto_1 = require("crypto");
|
|
6
|
+
const url_1 = require("url");
|
|
7
|
+
const util_1 = require("util");
|
|
8
|
+
const WAProto_1 = require("../../WAProto");
|
|
9
|
+
const Defaults_1 = require("../Defaults");
|
|
10
|
+
const Types_1 = require("../Types");
|
|
11
|
+
const Utils_1 = require("../Utils");
|
|
12
|
+
const WABinary_1 = require("../WABinary");
|
|
13
|
+
const Client_1 = require("./Client");
|
|
12
14
|
/**
|
|
13
15
|
* Connects to WA servers and performs:
|
|
14
16
|
* - simple queries (no retry mechanism, wait for connection establishment)
|
|
15
17
|
* - listen to messages and emit events
|
|
16
18
|
* - query phone connection
|
|
17
19
|
*/
|
|
18
|
-
|
|
20
|
+
const makeSocket = (config) => {
|
|
21
|
+
var _a, _b;
|
|
19
22
|
const { waWebSocketUrl, connectTimeoutMs, logger, keepAliveIntervalMs, browser, auth: authState, printQRInTerminal, defaultQueryTimeoutMs, transactionOpts, qrTimeout, makeSignalRepository } = config;
|
|
20
23
|
if (printQRInTerminal) {
|
|
21
24
|
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.');
|
|
22
25
|
}
|
|
23
|
-
const url = typeof waWebSocketUrl === 'string' ? new URL(waWebSocketUrl) : waWebSocketUrl;
|
|
26
|
+
const url = typeof waWebSocketUrl === 'string' ? new url_1.URL(waWebSocketUrl) : waWebSocketUrl;
|
|
24
27
|
if (config.mobile || url.protocol === 'tcp:') {
|
|
25
|
-
throw new Boom('Mobile API is not supported anymore', { statusCode: DisconnectReason.loggedOut });
|
|
28
|
+
throw new boom_1.Boom('Mobile API is not supported anymore', { statusCode: Types_1.DisconnectReason.loggedOut });
|
|
26
29
|
}
|
|
27
|
-
if (url.protocol === 'wss' && authState
|
|
30
|
+
if (url.protocol === 'wss' && ((_a = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _a === void 0 ? void 0 : _a.routingInfo)) {
|
|
28
31
|
url.searchParams.append('ED', authState.creds.routingInfo.toString('base64url'));
|
|
29
32
|
}
|
|
30
|
-
const ws = new WebSocketClient(url, config);
|
|
33
|
+
const ws = new Client_1.WebSocketClient(url, config);
|
|
31
34
|
ws.connect();
|
|
32
|
-
const ev = makeEventBuffer(logger);
|
|
35
|
+
const ev = (0, Utils_1.makeEventBuffer)(logger);
|
|
33
36
|
/** ephemeral key pair used to encrypt/decrypt communication. Unique for each connection */
|
|
34
|
-
const ephemeralKeyPair = Curve.generateKeyPair();
|
|
37
|
+
const ephemeralKeyPair = Utils_1.Curve.generateKeyPair();
|
|
35
38
|
/** WA noise protocol wrapper */
|
|
36
|
-
const noise = makeNoiseHandler({
|
|
39
|
+
const noise = (0, Utils_1.makeNoiseHandler)({
|
|
37
40
|
keyPair: ephemeralKeyPair,
|
|
38
|
-
NOISE_HEADER: NOISE_WA_HEADER,
|
|
41
|
+
NOISE_HEADER: Defaults_1.NOISE_WA_HEADER,
|
|
39
42
|
logger,
|
|
40
|
-
routingInfo: authState
|
|
43
|
+
routingInfo: (_b = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _b === void 0 ? void 0 : _b.routingInfo
|
|
41
44
|
});
|
|
42
45
|
const { creds } = authState;
|
|
43
46
|
// add transaction capability
|
|
44
|
-
const keys = addTransactionCapability(authState.keys, logger, transactionOpts);
|
|
47
|
+
const keys = (0, Utils_1.addTransactionCapability)(authState.keys, logger, transactionOpts);
|
|
45
48
|
const signalRepository = makeSignalRepository({ creds, keys });
|
|
46
49
|
let lastDateRecv;
|
|
47
50
|
let epoch = 1;
|
|
48
51
|
let keepAliveReq;
|
|
49
52
|
let qrTimer;
|
|
50
53
|
let closed = false;
|
|
51
|
-
const uqTagId = generateMdTagPrefix();
|
|
54
|
+
const uqTagId = (0, Utils_1.generateMdTagPrefix)();
|
|
52
55
|
const generateMessageTag = () => `${uqTagId}${epoch++}`;
|
|
53
|
-
const sendPromise = promisify(ws.send);
|
|
56
|
+
const sendPromise = (0, util_1.promisify)(ws.send);
|
|
54
57
|
/** send a raw buffer */
|
|
55
58
|
const sendRawMessage = async (data) => {
|
|
56
59
|
if (!ws.isOpen) {
|
|
57
|
-
throw new Boom('Connection Closed', { statusCode: DisconnectReason.connectionClosed });
|
|
60
|
+
throw new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed });
|
|
58
61
|
}
|
|
59
62
|
const bytes = noise.encodeFrame(data);
|
|
60
|
-
await promiseTimeout(connectTimeoutMs, async (resolve, reject) => {
|
|
63
|
+
await (0, Utils_1.promiseTimeout)(connectTimeoutMs, async (resolve, reject) => {
|
|
61
64
|
try {
|
|
62
65
|
await sendPromise.call(ws, bytes);
|
|
63
66
|
resolve();
|
|
@@ -70,9 +73,9 @@ export const makeSocket = (config) => {
|
|
|
70
73
|
/** send a binary node */
|
|
71
74
|
const sendNode = (frame) => {
|
|
72
75
|
if (logger.level === 'trace') {
|
|
73
|
-
logger.trace({ xml: binaryNodeToString(frame), msg: 'xml send' });
|
|
76
|
+
logger.trace({ xml: (0, WABinary_1.binaryNodeToString)(frame), msg: 'xml send' });
|
|
74
77
|
}
|
|
75
|
-
const buff = encodeBinaryNode(frame);
|
|
78
|
+
const buff = (0, WABinary_1.encodeBinaryNode)(frame);
|
|
76
79
|
return sendRawMessage(buff);
|
|
77
80
|
};
|
|
78
81
|
/** log & process any unexpected errors */
|
|
@@ -82,13 +85,13 @@ export const makeSocket = (config) => {
|
|
|
82
85
|
/** await the next incoming message */
|
|
83
86
|
const awaitNextMessage = async (sendMsg) => {
|
|
84
87
|
if (!ws.isOpen) {
|
|
85
|
-
throw new Boom('Connection Closed', {
|
|
86
|
-
statusCode: DisconnectReason.connectionClosed
|
|
88
|
+
throw new boom_1.Boom('Connection Closed', {
|
|
89
|
+
statusCode: Types_1.DisconnectReason.connectionClosed
|
|
87
90
|
});
|
|
88
91
|
}
|
|
89
92
|
let onOpen;
|
|
90
93
|
let onClose;
|
|
91
|
-
const result = promiseTimeout(connectTimeoutMs, (resolve, reject) => {
|
|
94
|
+
const result = (0, Utils_1.promiseTimeout)(connectTimeoutMs, (resolve, reject) => {
|
|
92
95
|
onOpen = resolve;
|
|
93
96
|
onClose = mapWebSocketError(reject);
|
|
94
97
|
ws.on('frame', onOpen);
|
|
@@ -113,38 +116,21 @@ export const makeSocket = (config) => {
|
|
|
113
116
|
let onRecv;
|
|
114
117
|
let onErr;
|
|
115
118
|
try {
|
|
116
|
-
const result = await promiseTimeout(timeoutMs, (resolve, reject) => {
|
|
117
|
-
onRecv =
|
|
118
|
-
resolve(data);
|
|
119
|
-
};
|
|
119
|
+
const result = await (0, Utils_1.promiseTimeout)(timeoutMs, (resolve, reject) => {
|
|
120
|
+
onRecv = resolve;
|
|
120
121
|
onErr = err => {
|
|
121
|
-
reject(err ||
|
|
122
|
-
new Boom('Connection Closed', {
|
|
123
|
-
statusCode: DisconnectReason.connectionClosed
|
|
124
|
-
}));
|
|
122
|
+
reject(err || new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed }));
|
|
125
123
|
};
|
|
126
124
|
ws.on(`TAG:${msgId}`, onRecv);
|
|
127
|
-
ws.on('close', onErr);
|
|
128
|
-
ws.
|
|
129
|
-
return () => reject(new Boom('Query Cancelled'));
|
|
125
|
+
ws.on('close', onErr); // if the socket closes, you'll never receive the message
|
|
126
|
+
ws.off('error', onErr);
|
|
130
127
|
});
|
|
131
128
|
return result;
|
|
132
129
|
}
|
|
133
|
-
catch (error) {
|
|
134
|
-
// Catch timeout and return undefined instead of throwing
|
|
135
|
-
if (error instanceof Boom && error.output?.statusCode === DisconnectReason.timedOut) {
|
|
136
|
-
logger?.warn?.({ msgId }, 'timed out waiting for message');
|
|
137
|
-
return undefined;
|
|
138
|
-
}
|
|
139
|
-
throw error;
|
|
140
|
-
}
|
|
141
130
|
finally {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
ws.off('close', onErr);
|
|
146
|
-
ws.off('error', onErr);
|
|
147
|
-
}
|
|
131
|
+
ws.off(`TAG:${msgId}`, onRecv);
|
|
132
|
+
ws.off('close', onErr); // if the socket closes, you'll never receive the message
|
|
133
|
+
ws.off('error', onErr);
|
|
148
134
|
}
|
|
149
135
|
};
|
|
150
136
|
/** send a query, and wait for its response. auto-generates message ID if not provided */
|
|
@@ -153,14 +139,9 @@ export const makeSocket = (config) => {
|
|
|
153
139
|
node.attrs.id = generateMessageTag();
|
|
154
140
|
}
|
|
155
141
|
const msgId = node.attrs.id;
|
|
156
|
-
const result = await
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
.then(() => resolve(result))
|
|
160
|
-
.catch(reject);
|
|
161
|
-
});
|
|
162
|
-
if (result && 'tag' in result) {
|
|
163
|
-
assertNodeErrorFree(result);
|
|
142
|
+
const [result] = await Promise.all([waitForMessage(msgId, timeoutMs), sendNode(node)]);
|
|
143
|
+
if ('tag' in result) {
|
|
144
|
+
(0, WABinary_1.assertNodeErrorFree)(result);
|
|
164
145
|
}
|
|
165
146
|
return result;
|
|
166
147
|
};
|
|
@@ -169,24 +150,24 @@ export const makeSocket = (config) => {
|
|
|
169
150
|
let helloMsg = {
|
|
170
151
|
clientHello: { ephemeral: ephemeralKeyPair.public }
|
|
171
152
|
};
|
|
172
|
-
helloMsg = proto.HandshakeMessage.fromObject(helloMsg);
|
|
153
|
+
helloMsg = WAProto_1.proto.HandshakeMessage.fromObject(helloMsg);
|
|
173
154
|
logger.info({ browser, helloMsg }, 'connected to WA');
|
|
174
|
-
const init = proto.HandshakeMessage.encode(helloMsg).finish();
|
|
155
|
+
const init = WAProto_1.proto.HandshakeMessage.encode(helloMsg).finish();
|
|
175
156
|
const result = await awaitNextMessage(init);
|
|
176
|
-
const handshake = proto.HandshakeMessage.decode(result);
|
|
157
|
+
const handshake = WAProto_1.proto.HandshakeMessage.decode(result);
|
|
177
158
|
logger.trace({ handshake }, 'handshake recv from WA');
|
|
178
159
|
const keyEnc = await noise.processHandshake(handshake, creds.noiseKey);
|
|
179
160
|
let node;
|
|
180
161
|
if (!creds.me) {
|
|
181
|
-
node = generateRegistrationNode(creds, config);
|
|
162
|
+
node = (0, Utils_1.generateRegistrationNode)(creds, config);
|
|
182
163
|
logger.info({ node }, 'not logged in, attempting registration...');
|
|
183
164
|
}
|
|
184
165
|
else {
|
|
185
|
-
node = generateLoginNode(creds.me.id, config);
|
|
166
|
+
node = (0, Utils_1.generateLoginNode)(creds.me.id, config);
|
|
186
167
|
logger.info({ node }, 'logging in...');
|
|
187
168
|
}
|
|
188
|
-
const payloadEnc = noise.encrypt(proto.ClientPayload.encode(node).finish());
|
|
189
|
-
await sendRawMessage(proto.HandshakeMessage.encode({
|
|
169
|
+
const payloadEnc = noise.encrypt(WAProto_1.proto.ClientPayload.encode(node).finish());
|
|
170
|
+
await sendRawMessage(WAProto_1.proto.HandshakeMessage.encode({
|
|
190
171
|
clientFinish: {
|
|
191
172
|
static: keyEnc,
|
|
192
173
|
payload: payloadEnc
|
|
@@ -202,18 +183,18 @@ export const makeSocket = (config) => {
|
|
|
202
183
|
id: generateMessageTag(),
|
|
203
184
|
xmlns: 'encrypt',
|
|
204
185
|
type: 'get',
|
|
205
|
-
to: S_WHATSAPP_NET
|
|
186
|
+
to: WABinary_1.S_WHATSAPP_NET
|
|
206
187
|
},
|
|
207
188
|
content: [{ tag: 'count', attrs: {} }]
|
|
208
189
|
});
|
|
209
|
-
const countChild = getBinaryNodeChild(result, 'count');
|
|
190
|
+
const countChild = (0, WABinary_1.getBinaryNodeChild)(result, 'count');
|
|
210
191
|
return +countChild.attrs.value;
|
|
211
192
|
};
|
|
212
193
|
/** generates and uploads a set of pre-keys to the server */
|
|
213
|
-
const uploadPreKeys = async (count = INITIAL_PREKEY_COUNT) => {
|
|
194
|
+
const uploadPreKeys = async (count = Defaults_1.INITIAL_PREKEY_COUNT) => {
|
|
214
195
|
await keys.transaction(async () => {
|
|
215
196
|
logger.info({ count }, 'uploading pre-keys');
|
|
216
|
-
const { update, node } = await getNextPreKeysNode({ creds, keys }, count);
|
|
197
|
+
const { update, node } = await (0, Utils_1.getNextPreKeysNode)({ creds, keys }, count);
|
|
217
198
|
await query(node);
|
|
218
199
|
ev.emit('creds.update', update);
|
|
219
200
|
logger.info({ count }, 'uploaded pre-keys');
|
|
@@ -222,12 +203,13 @@ export const makeSocket = (config) => {
|
|
|
222
203
|
const uploadPreKeysToServerIfRequired = async () => {
|
|
223
204
|
const preKeyCount = await getAvailablePreKeysOnServer();
|
|
224
205
|
logger.info(`${preKeyCount} pre-keys found on server`);
|
|
225
|
-
if (preKeyCount <= MIN_PREKEY_COUNT) {
|
|
206
|
+
if (preKeyCount <= Defaults_1.MIN_PREKEY_COUNT) {
|
|
226
207
|
await uploadPreKeys();
|
|
227
208
|
}
|
|
228
209
|
};
|
|
229
210
|
const onMessageReceived = (data) => {
|
|
230
211
|
noise.decodeFrame(data, frame => {
|
|
212
|
+
var _a;
|
|
231
213
|
// reset ping timeout
|
|
232
214
|
lastDateRecv = new Date();
|
|
233
215
|
let anyTriggered = false;
|
|
@@ -236,21 +218,21 @@ export const makeSocket = (config) => {
|
|
|
236
218
|
if (!(frame instanceof Uint8Array)) {
|
|
237
219
|
const msgId = frame.attrs.id;
|
|
238
220
|
if (logger.level === 'trace') {
|
|
239
|
-
logger.trace({ xml: binaryNodeToString(frame), msg: 'recv xml' });
|
|
221
|
+
logger.trace({ xml: (0, WABinary_1.binaryNodeToString)(frame), msg: 'recv xml' });
|
|
240
222
|
}
|
|
241
223
|
/* Check if this is a response to a message we sent */
|
|
242
|
-
anyTriggered = ws.emit(`${DEF_TAG_PREFIX}${msgId}`, frame) || anyTriggered;
|
|
224
|
+
anyTriggered = ws.emit(`${Defaults_1.DEF_TAG_PREFIX}${msgId}`, frame) || anyTriggered;
|
|
243
225
|
/* Check if this is a response to a message we are expecting */
|
|
244
226
|
const l0 = frame.tag;
|
|
245
227
|
const l1 = frame.attrs || {};
|
|
246
|
-
const l2 = Array.isArray(frame.content) ? frame.content[0]
|
|
228
|
+
const l2 = Array.isArray(frame.content) ? (_a = frame.content[0]) === null || _a === void 0 ? void 0 : _a.tag : '';
|
|
247
229
|
for (const key of Object.keys(l1)) {
|
|
248
|
-
anyTriggered = ws.emit(`${DEF_CALLBACK_PREFIX}${l0},${key}:${l1[key]},${l2}`, frame) || anyTriggered;
|
|
249
|
-
anyTriggered = ws.emit(`${DEF_CALLBACK_PREFIX}${l0},${key}:${l1[key]}`, frame) || anyTriggered;
|
|
250
|
-
anyTriggered = ws.emit(`${DEF_CALLBACK_PREFIX}${l0},${key}`, frame) || anyTriggered;
|
|
230
|
+
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},${key}:${l1[key]},${l2}`, frame) || anyTriggered;
|
|
231
|
+
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},${key}:${l1[key]}`, frame) || anyTriggered;
|
|
232
|
+
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},${key}`, frame) || anyTriggered;
|
|
251
233
|
}
|
|
252
|
-
anyTriggered = ws.emit(`${DEF_CALLBACK_PREFIX}${l0},,${l2}`, frame) || anyTriggered;
|
|
253
|
-
anyTriggered = ws.emit(`${DEF_CALLBACK_PREFIX}${l0}`, frame) || anyTriggered;
|
|
234
|
+
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},,${l2}`, frame) || anyTriggered;
|
|
235
|
+
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0}`, frame) || anyTriggered;
|
|
254
236
|
if (!anyTriggered && logger.level === 'debug') {
|
|
255
237
|
logger.debug({ unhandled: true, msgId, fromMe: false, frame }, 'communication recv');
|
|
256
238
|
}
|
|
@@ -259,12 +241,11 @@ export const makeSocket = (config) => {
|
|
|
259
241
|
};
|
|
260
242
|
const end = (error) => {
|
|
261
243
|
if (closed) {
|
|
262
|
-
logger.trace({ trace: error
|
|
244
|
+
logger.trace({ trace: error === null || error === void 0 ? void 0 : error.stack }, 'connection already closed');
|
|
263
245
|
return;
|
|
264
246
|
}
|
|
265
|
-
cleanupQueues();
|
|
266
247
|
closed = true;
|
|
267
|
-
logger.info({ trace: error
|
|
248
|
+
logger.info({ trace: error === null || error === void 0 ? void 0 : error.stack }, error ? 'connection errored' : 'connection closed');
|
|
268
249
|
clearInterval(keepAliveReq);
|
|
269
250
|
clearTimeout(qrTimer);
|
|
270
251
|
ws.removeAllListeners('close');
|
|
@@ -274,7 +255,7 @@ export const makeSocket = (config) => {
|
|
|
274
255
|
try {
|
|
275
256
|
ws.close();
|
|
276
257
|
}
|
|
277
|
-
catch { }
|
|
258
|
+
catch (_a) { }
|
|
278
259
|
}
|
|
279
260
|
ev.emit('connection.update', {
|
|
280
261
|
connection: 'close',
|
|
@@ -290,7 +271,7 @@ export const makeSocket = (config) => {
|
|
|
290
271
|
return;
|
|
291
272
|
}
|
|
292
273
|
if (ws.isClosed || ws.isClosing) {
|
|
293
|
-
throw new Boom('Connection Closed', { statusCode: DisconnectReason.connectionClosed });
|
|
274
|
+
throw new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed });
|
|
294
275
|
}
|
|
295
276
|
let onOpen;
|
|
296
277
|
let onClose;
|
|
@@ -316,7 +297,7 @@ export const makeSocket = (config) => {
|
|
|
316
297
|
it could be that the network is down
|
|
317
298
|
*/
|
|
318
299
|
if (diff > keepAliveIntervalMs + 5000) {
|
|
319
|
-
end(new Boom('Connection was lost', { statusCode: DisconnectReason.connectionLost }));
|
|
300
|
+
end(new boom_1.Boom('Connection was lost', { statusCode: Types_1.DisconnectReason.connectionLost }));
|
|
320
301
|
}
|
|
321
302
|
else if (ws.isOpen) {
|
|
322
303
|
// if its all good, send a keep alive request
|
|
@@ -324,7 +305,7 @@ export const makeSocket = (config) => {
|
|
|
324
305
|
tag: 'iq',
|
|
325
306
|
attrs: {
|
|
326
307
|
id: generateMessageTag(),
|
|
327
|
-
to: S_WHATSAPP_NET,
|
|
308
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
328
309
|
type: 'get',
|
|
329
310
|
xmlns: 'w:p'
|
|
330
311
|
},
|
|
@@ -341,7 +322,7 @@ export const makeSocket = (config) => {
|
|
|
341
322
|
const sendPassiveIq = (tag) => query({
|
|
342
323
|
tag: 'iq',
|
|
343
324
|
attrs: {
|
|
344
|
-
to: S_WHATSAPP_NET,
|
|
325
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
345
326
|
xmlns: 'passive',
|
|
346
327
|
type: 'set'
|
|
347
328
|
},
|
|
@@ -349,12 +330,13 @@ export const makeSocket = (config) => {
|
|
|
349
330
|
});
|
|
350
331
|
/** logout & invalidate connection */
|
|
351
332
|
const logout = async (msg) => {
|
|
352
|
-
|
|
333
|
+
var _a;
|
|
334
|
+
const jid = (_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.id;
|
|
353
335
|
if (jid) {
|
|
354
336
|
await sendNode({
|
|
355
337
|
tag: 'iq',
|
|
356
338
|
attrs: {
|
|
357
|
-
to: S_WHATSAPP_NET,
|
|
339
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
358
340
|
type: 'set',
|
|
359
341
|
id: generateMessageTag(),
|
|
360
342
|
xmlns: 'md'
|
|
@@ -370,23 +352,23 @@ export const makeSocket = (config) => {
|
|
|
370
352
|
]
|
|
371
353
|
});
|
|
372
354
|
}
|
|
373
|
-
end(new Boom(msg || 'Intentional Logout', { statusCode: DisconnectReason.loggedOut }));
|
|
355
|
+
end(new boom_1.Boom(msg || 'Intentional Logout', { statusCode: Types_1.DisconnectReason.loggedOut }));
|
|
374
356
|
};
|
|
375
357
|
const requestPairingCode = async (phoneNumber, customPairingCode) => {
|
|
376
|
-
const pairingCode = customPairingCode
|
|
377
|
-
if (customPairingCode && customPairingCode
|
|
358
|
+
const pairingCode = customPairingCode !== null && customPairingCode !== void 0 ? customPairingCode : (0, Utils_1.bytesToCrockford)((0, crypto_1.randomBytes)(5));
|
|
359
|
+
if (customPairingCode && (customPairingCode === null || customPairingCode === void 0 ? void 0 : customPairingCode.length) !== 8) {
|
|
378
360
|
throw new Error('Custom pairing code must be exactly 8 chars');
|
|
379
361
|
}
|
|
380
362
|
authState.creds.pairingCode = pairingCode;
|
|
381
363
|
authState.creds.me = {
|
|
382
|
-
id: jidEncode(phoneNumber, 's.whatsapp.net'),
|
|
364
|
+
id: (0, WABinary_1.jidEncode)(phoneNumber, 's.whatsapp.net'),
|
|
383
365
|
name: '~'
|
|
384
366
|
};
|
|
385
367
|
ev.emit('creds.update', authState.creds);
|
|
386
368
|
await sendNode({
|
|
387
369
|
tag: 'iq',
|
|
388
370
|
attrs: {
|
|
389
|
-
to: S_WHATSAPP_NET,
|
|
371
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
390
372
|
type: 'set',
|
|
391
373
|
id: generateMessageTag(),
|
|
392
374
|
xmlns: 'md'
|
|
@@ -397,6 +379,7 @@ export const makeSocket = (config) => {
|
|
|
397
379
|
attrs: {
|
|
398
380
|
jid: authState.creds.me.id,
|
|
399
381
|
stage: 'companion_hello',
|
|
382
|
+
// eslint-disable-next-line camelcase
|
|
400
383
|
should_show_push_notification: 'true'
|
|
401
384
|
},
|
|
402
385
|
content: [
|
|
@@ -413,7 +396,7 @@ export const makeSocket = (config) => {
|
|
|
413
396
|
{
|
|
414
397
|
tag: 'companion_platform_id',
|
|
415
398
|
attrs: {},
|
|
416
|
-
content: getPlatformId(browser[1])
|
|
399
|
+
content: (0, Utils_1.getPlatformId)(browser[1])
|
|
417
400
|
},
|
|
418
401
|
{
|
|
419
402
|
tag: 'companion_platform_display',
|
|
@@ -432,17 +415,17 @@ export const makeSocket = (config) => {
|
|
|
432
415
|
return authState.creds.pairingCode;
|
|
433
416
|
};
|
|
434
417
|
async function generatePairingKey() {
|
|
435
|
-
const salt = randomBytes(32);
|
|
436
|
-
const randomIv = randomBytes(16);
|
|
437
|
-
const key = await derivePairingCodeKey(authState.creds.pairingCode, salt);
|
|
438
|
-
const ciphered = aesEncryptCTR(authState.creds.pairingEphemeralKeyPair.public, key, randomIv);
|
|
418
|
+
const salt = (0, crypto_1.randomBytes)(32);
|
|
419
|
+
const randomIv = (0, crypto_1.randomBytes)(16);
|
|
420
|
+
const key = await (0, Utils_1.derivePairingCodeKey)(authState.creds.pairingCode, salt);
|
|
421
|
+
const ciphered = (0, Utils_1.aesEncryptCTR)(authState.creds.pairingEphemeralKeyPair.public, key, randomIv);
|
|
439
422
|
return Buffer.concat([salt, randomIv, ciphered]);
|
|
440
423
|
}
|
|
441
424
|
const sendWAMBuffer = (wamBuffer) => {
|
|
442
425
|
return query({
|
|
443
426
|
tag: 'iq',
|
|
444
427
|
attrs: {
|
|
445
|
-
to: S_WHATSAPP_NET,
|
|
428
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
446
429
|
id: generateMessageTag(),
|
|
447
430
|
xmlns: 'w:stats'
|
|
448
431
|
},
|
|
@@ -466,22 +449,22 @@ export const makeSocket = (config) => {
|
|
|
466
449
|
}
|
|
467
450
|
});
|
|
468
451
|
ws.on('error', mapWebSocketError(end));
|
|
469
|
-
ws.on('close', () => end(new Boom('Connection Terminated', { statusCode: DisconnectReason.connectionClosed })));
|
|
452
|
+
ws.on('close', () => end(new boom_1.Boom('Connection Terminated', { statusCode: Types_1.DisconnectReason.connectionClosed })));
|
|
470
453
|
// the server terminated the connection
|
|
471
|
-
ws.on('CB:xmlstreamend', () => end(new Boom('Connection Terminated by Server', { statusCode: DisconnectReason.connectionClosed })));
|
|
454
|
+
ws.on('CB:xmlstreamend', () => end(new boom_1.Boom('Connection Terminated by Server', { statusCode: Types_1.DisconnectReason.connectionClosed })));
|
|
472
455
|
// QR gen
|
|
473
456
|
ws.on('CB:iq,type:set,pair-device', async (stanza) => {
|
|
474
457
|
const iq = {
|
|
475
458
|
tag: 'iq',
|
|
476
459
|
attrs: {
|
|
477
|
-
to: S_WHATSAPP_NET,
|
|
460
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
478
461
|
type: 'result',
|
|
479
462
|
id: stanza.attrs.id
|
|
480
463
|
}
|
|
481
464
|
};
|
|
482
465
|
await sendNode(iq);
|
|
483
|
-
const pairDeviceNode = getBinaryNodeChild(stanza, 'pair-device');
|
|
484
|
-
const refNodes = getBinaryNodeChildren(pairDeviceNode, 'ref');
|
|
466
|
+
const pairDeviceNode = (0, WABinary_1.getBinaryNodeChild)(stanza, 'pair-device');
|
|
467
|
+
const refNodes = (0, WABinary_1.getBinaryNodeChildren)(pairDeviceNode, 'ref');
|
|
485
468
|
const noiseKeyB64 = Buffer.from(creds.noiseKey.public).toString('base64');
|
|
486
469
|
const identityKeyB64 = Buffer.from(creds.signedIdentityKey.public).toString('base64');
|
|
487
470
|
const advB64 = creds.advSecretKey;
|
|
@@ -492,7 +475,7 @@ export const makeSocket = (config) => {
|
|
|
492
475
|
}
|
|
493
476
|
const refNode = refNodes.shift();
|
|
494
477
|
if (!refNode) {
|
|
495
|
-
end(new Boom('QR refs attempts ended', { statusCode: DisconnectReason.timedOut }));
|
|
478
|
+
end(new boom_1.Boom('QR refs attempts ended', { statusCode: Types_1.DisconnectReason.timedOut }));
|
|
496
479
|
return;
|
|
497
480
|
}
|
|
498
481
|
const ref = refNode.content.toString('utf-8');
|
|
@@ -508,7 +491,7 @@ export const makeSocket = (config) => {
|
|
|
508
491
|
ws.on('CB:iq,,pair-success', async (stanza) => {
|
|
509
492
|
logger.debug('pair success recv');
|
|
510
493
|
try {
|
|
511
|
-
const { reply, creds: updatedCreds } = configureSuccessfulPairing(stanza, creds);
|
|
494
|
+
const { reply, creds: updatedCreds } = (0, Utils_1.configureSuccessfulPairing)(stanza, creds);
|
|
512
495
|
logger.info({ me: updatedCreds.me, platform: updatedCreds.platform }, 'pairing configured successfully, expect to restart the connection...');
|
|
513
496
|
ev.emit('creds.update', updatedCreds);
|
|
514
497
|
ev.emit('connection.update', { isNewLogin: true, qr: undefined });
|
|
@@ -521,13 +504,8 @@ export const makeSocket = (config) => {
|
|
|
521
504
|
});
|
|
522
505
|
// login complete
|
|
523
506
|
ws.on('CB:success', async (node) => {
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
await sendPassiveIq('active');
|
|
527
|
-
}
|
|
528
|
-
catch (err) {
|
|
529
|
-
logger.warn({ err }, 'failed to send initial passive iq');
|
|
530
|
-
}
|
|
507
|
+
await uploadPreKeysToServerIfRequired();
|
|
508
|
+
await sendPassiveIq('active');
|
|
531
509
|
logger.info('opened connection to WA');
|
|
532
510
|
clearTimeout(qrTimer); // will never happen in all likelyhood -- but just in case WA sends success on first try
|
|
533
511
|
ev.emit('creds.update', { me: { ...authState.creds.me, lid: node.attrs.lid } });
|
|
@@ -535,16 +513,16 @@ export const makeSocket = (config) => {
|
|
|
535
513
|
});
|
|
536
514
|
ws.on('CB:stream:error', (node) => {
|
|
537
515
|
logger.error({ node }, 'stream errored out');
|
|
538
|
-
const { reason, statusCode } = getErrorCodeFromStreamError(node);
|
|
539
|
-
end(new Boom(`Stream Errored (${reason})`, { statusCode, data: node }));
|
|
516
|
+
const { reason, statusCode } = (0, Utils_1.getErrorCodeFromStreamError)(node);
|
|
517
|
+
end(new boom_1.Boom(`Stream Errored (${reason})`, { statusCode, data: node }));
|
|
540
518
|
});
|
|
541
519
|
// stream fail, possible logout
|
|
542
520
|
ws.on('CB:failure', (node) => {
|
|
543
521
|
const reason = +(node.attrs.reason || 500);
|
|
544
|
-
end(new Boom('Connection Failure', { statusCode: reason, data: node.attrs }));
|
|
522
|
+
end(new boom_1.Boom('Connection Failure', { statusCode: reason, data: node.attrs }));
|
|
545
523
|
});
|
|
546
524
|
ws.on('CB:ib,,downgrade_webclient', () => {
|
|
547
|
-
end(new Boom('Multi-device beta not joined', { statusCode: DisconnectReason.multideviceMismatch }));
|
|
525
|
+
end(new boom_1.Boom('Multi-device beta not joined', { statusCode: Types_1.DisconnectReason.multideviceMismatch }));
|
|
548
526
|
});
|
|
549
527
|
ws.on('CB:ib,,offline_preview', (node) => {
|
|
550
528
|
logger.info('offline preview received', JSON.stringify(node));
|
|
@@ -555,16 +533,17 @@ export const makeSocket = (config) => {
|
|
|
555
533
|
});
|
|
556
534
|
});
|
|
557
535
|
ws.on('CB:ib,,edge_routing', (node) => {
|
|
558
|
-
const edgeRoutingNode = getBinaryNodeChild(node, 'edge_routing');
|
|
559
|
-
const routingInfo = getBinaryNodeChild(edgeRoutingNode, 'routing_info');
|
|
560
|
-
if (routingInfo
|
|
561
|
-
authState.creds.routingInfo = Buffer.from(routingInfo
|
|
536
|
+
const edgeRoutingNode = (0, WABinary_1.getBinaryNodeChild)(node, 'edge_routing');
|
|
537
|
+
const routingInfo = (0, WABinary_1.getBinaryNodeChild)(edgeRoutingNode, 'routing_info');
|
|
538
|
+
if (routingInfo === null || routingInfo === void 0 ? void 0 : routingInfo.content) {
|
|
539
|
+
authState.creds.routingInfo = Buffer.from(routingInfo === null || routingInfo === void 0 ? void 0 : routingInfo.content);
|
|
562
540
|
ev.emit('creds.update', authState.creds);
|
|
563
541
|
}
|
|
564
542
|
});
|
|
565
543
|
let didStartBuffer = false;
|
|
566
544
|
process.nextTick(() => {
|
|
567
|
-
|
|
545
|
+
var _a;
|
|
546
|
+
if ((_a = creds.me) === null || _a === void 0 ? void 0 : _a.id) {
|
|
568
547
|
// start buffering important events
|
|
569
548
|
// if we're logged in
|
|
570
549
|
ev.buffer();
|
|
@@ -574,8 +553,8 @@ export const makeSocket = (config) => {
|
|
|
574
553
|
});
|
|
575
554
|
// called when all offline notifs are handled
|
|
576
555
|
ws.on('CB:ib,,offline', (node) => {
|
|
577
|
-
const child = getBinaryNodeChild(node, 'offline');
|
|
578
|
-
const offlineNotifs = +(child
|
|
556
|
+
const child = (0, WABinary_1.getBinaryNodeChild)(node, 'offline');
|
|
557
|
+
const offlineNotifs = +((child === null || child === void 0 ? void 0 : child.attrs.count) || 0);
|
|
579
558
|
logger.info(`handled ${offlineNotifs} offline messages/notifications`);
|
|
580
559
|
if (didStartBuffer) {
|
|
581
560
|
ev.flush();
|
|
@@ -585,9 +564,10 @@ export const makeSocket = (config) => {
|
|
|
585
564
|
});
|
|
586
565
|
// update credentials when required
|
|
587
566
|
ev.on('creds.update', update => {
|
|
588
|
-
|
|
567
|
+
var _a, _b;
|
|
568
|
+
const name = (_a = update.me) === null || _a === void 0 ? void 0 : _a.name;
|
|
589
569
|
// if name has just been received
|
|
590
|
-
if (creds.me
|
|
570
|
+
if (((_b = creds.me) === null || _b === void 0 ? void 0 : _b.name) !== name) {
|
|
591
571
|
logger.debug({ name }, 'updated pushName');
|
|
592
572
|
sendNode({
|
|
593
573
|
tag: 'presence',
|
|
@@ -620,17 +600,17 @@ export const makeSocket = (config) => {
|
|
|
620
600
|
uploadPreKeysToServerIfRequired,
|
|
621
601
|
requestPairingCode,
|
|
622
602
|
/** Waits for the connection to WA to reach a state */
|
|
623
|
-
waitForConnectionUpdate: bindWaitForConnectionUpdate(ev),
|
|
603
|
+
waitForConnectionUpdate: (0, Utils_1.bindWaitForConnectionUpdate)(ev),
|
|
624
604
|
sendWAMBuffer
|
|
625
605
|
};
|
|
626
606
|
};
|
|
607
|
+
exports.makeSocket = makeSocket;
|
|
627
608
|
/**
|
|
628
609
|
* map the websocket error to the right type
|
|
629
610
|
* so it can be retried by the caller
|
|
630
611
|
* */
|
|
631
612
|
function mapWebSocketError(handler) {
|
|
632
613
|
return (error) => {
|
|
633
|
-
handler(new Boom(`WebSocket Error (${error
|
|
614
|
+
handler(new boom_1.Boom(`WebSocket Error (${error === null || error === void 0 ? void 0 : error.message})`, { statusCode: (0, Utils_1.getCodeFromWSError)(error), data: error }));
|
|
634
615
|
};
|
|
635
616
|
}
|
|
636
|
-
//# sourceMappingURL=socket.js.map
|
package/lib/Socket/usync.d.ts
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
import { Boom } from '@hapi/boom';
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import { USyncQuery } from '../WAUSync
|
|
2
|
+
import { SocketConfig } from '../Types';
|
|
3
|
+
import { BinaryNode } from '../WABinary';
|
|
4
|
+
import { USyncQuery } from '../WAUSync';
|
|
5
5
|
export declare const makeUSyncSocket: (config: SocketConfig) => {
|
|
6
|
-
executeUSyncQuery: (usyncQuery: USyncQuery) => Promise<import("../
|
|
6
|
+
executeUSyncQuery: (usyncQuery: USyncQuery) => Promise<import("../WAUSync").USyncQueryResult | undefined>;
|
|
7
7
|
type: "md";
|
|
8
|
-
ws: import("./Client
|
|
9
|
-
ev: import("../
|
|
10
|
-
process(handler: (events: Partial<import("../
|
|
8
|
+
ws: import("./Client").WebSocketClient;
|
|
9
|
+
ev: import("../Types").BaileysEventEmitter & {
|
|
10
|
+
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
|
|
11
11
|
buffer(): void;
|
|
12
12
|
createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): (...args: A) => Promise<T>;
|
|
13
|
-
flush(): boolean;
|
|
13
|
+
flush(force?: boolean): boolean;
|
|
14
14
|
isBuffering(): boolean;
|
|
15
15
|
};
|
|
16
16
|
authState: {
|
|
17
|
-
creds: import("../
|
|
18
|
-
keys: import("../
|
|
17
|
+
creds: import("../Types").AuthenticationCreds;
|
|
18
|
+
keys: import("../Types").SignalKeyStoreWithTransaction;
|
|
19
19
|
};
|
|
20
|
-
signalRepository: import("../
|
|
21
|
-
user: import("../
|
|
20
|
+
signalRepository: import("../Types").SignalRepository;
|
|
21
|
+
user: import("../Types").Contact | undefined;
|
|
22
22
|
generateMessageTag: () => string;
|
|
23
23
|
query: (node: BinaryNode, timeoutMs?: number) => Promise<any>;
|
|
24
|
-
waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<
|
|
24
|
+
waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<any>;
|
|
25
25
|
waitForSocketOpen: () => Promise<void>;
|
|
26
26
|
sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
|
|
27
27
|
sendNode: (frame: BinaryNode) => Promise<void>;
|
|
@@ -31,7 +31,6 @@ export declare const makeUSyncSocket: (config: SocketConfig) => {
|
|
|
31
31
|
uploadPreKeys: (count?: number) => Promise<void>;
|
|
32
32
|
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
|
33
33
|
requestPairingCode: (phoneNumber: string, customPairingCode?: string) => Promise<string>;
|
|
34
|
-
waitForConnectionUpdate: (check: (u: Partial<import("../
|
|
34
|
+
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
|
|
35
35
|
sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
|
|
36
36
|
};
|
|
37
|
-
//# sourceMappingURL=usync.d.ts.map
|