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