@neelegirl/baileys 1.5.3 → 1.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +195 -195
- package/WAProto/GenerateStatics.sh +3 -0
- package/WAProto/WAProto.proto +478 -1153
- package/WAProto/fix-imports.js +29 -0
- package/WAProto/index.d.ts +2645 -51971
- package/WAProto/index.js +48649 -154035
- package/engine-requirements.js +10 -0
- package/lib/Defaults/index.d.ts +62 -78
- package/lib/Defaults/index.d.ts.map +1 -0
- package/lib/Defaults/index.js +115 -149
- package/lib/Defaults/index.js.map +1 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
- package/lib/Signal/Group/ciphertext-message.d.ts.map +1 -0
- package/lib/Signal/Group/ciphertext-message.js +12 -0
- package/lib/Signal/Group/ciphertext-message.js.map +1 -0
- package/lib/Signal/{WASignalGroup → Group}/group-session-builder.d.ts +11 -13
- package/lib/Signal/Group/group-session-builder.d.ts.map +1 -0
- package/lib/Signal/Group/group-session-builder.js +30 -0
- package/lib/Signal/Group/group-session-builder.js.map +1 -0
- package/lib/Signal/Group/group_cipher.d.ts +17 -0
- package/lib/Signal/Group/group_cipher.d.ts.map +1 -0
- package/lib/Signal/{WASignalGroup → Group}/group_cipher.js +41 -70
- package/lib/Signal/Group/group_cipher.js.map +1 -0
- package/lib/Signal/Group/index.d.ts +12 -0
- package/lib/Signal/Group/index.d.ts.map +1 -0
- package/lib/Signal/Group/index.js +12 -0
- package/lib/Signal/Group/index.js.map +1 -0
- package/lib/Signal/Group/keyhelper.d.ts +11 -0
- package/lib/Signal/Group/keyhelper.d.ts.map +1 -0
- package/lib/Signal/Group/keyhelper.js +18 -0
- package/lib/Signal/Group/keyhelper.js.map +1 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
- package/lib/Signal/Group/sender-chain-key.d.ts.map +1 -0
- package/lib/Signal/Group/sender-chain-key.js +26 -0
- package/lib/Signal/Group/sender-chain-key.js.map +1 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +63 -0
- package/lib/Signal/Group/sender-key-distribution-message.js.map +1 -0
- package/lib/Signal/Group/sender-key-message.d.ts +19 -0
- package/lib/Signal/Group/sender-key-message.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-message.js +66 -0
- package/lib/Signal/Group/sender-key-message.js.map +1 -0
- package/lib/Signal/Group/sender-key-name.d.ts +18 -0
- package/lib/Signal/Group/sender-key-name.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-name.js +48 -0
- package/lib/Signal/Group/sender-key-name.js.map +1 -0
- package/lib/Signal/Group/sender-key-record.d.ts +31 -0
- package/lib/Signal/Group/sender-key-record.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-record.js +41 -0
- package/lib/Signal/Group/sender-key-record.js.map +1 -0
- package/lib/Signal/Group/sender-key-state.d.ts +39 -0
- package/lib/Signal/Group/sender-key-state.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-state.js +84 -0
- package/lib/Signal/Group/sender-key-state.js.map +1 -0
- package/lib/Signal/Group/sender-message-key.d.ts +12 -0
- package/lib/Signal/Group/sender-message-key.d.ts.map +1 -0
- package/lib/Signal/{WASignalGroup/sender_message_key.js → Group/sender-message-key.js} +26 -39
- package/lib/Signal/Group/sender-message-key.js.map +1 -0
- package/lib/Signal/libsignal.d.ts +5 -8
- package/lib/Signal/libsignal.d.ts.map +1 -0
- package/lib/Signal/libsignal.js +342 -391
- package/lib/Signal/libsignal.js.map +1 -0
- package/lib/Signal/lid-mapping.d.ts +23 -28
- package/lib/Signal/lid-mapping.d.ts.map +1 -0
- package/lib/Signal/lid-mapping.js +171 -184
- package/lib/Signal/lid-mapping.js.map +1 -0
- package/lib/Socket/Client/index.d.ts +3 -2
- package/lib/Socket/Client/index.d.ts.map +1 -0
- package/lib/Socket/Client/index.js +3 -22
- package/lib/Socket/Client/index.js.map +1 -0
- package/lib/Socket/Client/types.d.ts +15 -15
- package/lib/Socket/Client/types.d.ts.map +1 -0
- package/lib/Socket/Client/types.js +8 -15
- package/lib/Socket/Client/types.js.map +1 -0
- package/lib/Socket/Client/websocket.d.ts +12 -12
- package/lib/Socket/Client/websocket.d.ts.map +1 -0
- package/lib/Socket/Client/websocket.js +24 -36
- package/lib/Socket/Client/websocket.js.map +1 -0
- package/lib/Socket/business.d.ts +178 -177
- package/lib/Socket/business.d.ts.map +1 -0
- package/lib/Socket/business.js +81 -120
- package/lib/Socket/business.js.map +1 -0
- package/lib/Socket/chats.d.ts +93 -92
- package/lib/Socket/chats.d.ts.map +1 -0
- package/lib/Socket/chats.js +462 -618
- package/lib/Socket/chats.js.map +1 -0
- package/lib/Socket/communities.d.ts +244 -223
- package/lib/Socket/communities.d.ts.map +1 -0
- package/lib/Socket/communities.js +431 -433
- package/lib/Socket/communities.js.map +1 -0
- package/lib/Socket/groups.d.ts +118 -110
- package/lib/Socket/groups.d.ts.map +1 -0
- package/lib/Socket/groups.js +148 -181
- package/lib/Socket/groups.js.map +1 -0
- package/lib/Socket/index.d.ts +222 -182
- package/lib/Socket/index.d.ts.map +1 -0
- package/lib/Socket/index.js +12 -18
- package/lib/Socket/index.js.map +1 -0
- package/lib/Socket/messages-recv.d.ts +165 -166
- package/lib/Socket/messages-recv.d.ts.map +1 -0
- package/lib/Socket/messages-recv.js +753 -1031
- package/lib/Socket/messages-recv.js.map +1 -0
- package/lib/Socket/messages-send.d.ts +161 -157
- package/lib/Socket/messages-send.d.ts.map +1 -0
- package/lib/Socket/messages-send.js +564 -1396
- package/lib/Socket/messages-send.js.map +1 -0
- package/lib/Socket/mex.d.ts +3 -2
- package/lib/Socket/mex.d.ts.map +1 -0
- package/lib/Socket/mex.js +42 -47
- package/lib/Socket/mex.js.map +1 -0
- package/lib/Socket/newsletter.d.ts +139 -137
- package/lib/Socket/newsletter.d.ts.map +1 -0
- package/lib/Socket/newsletter.js +181 -295
- package/lib/Socket/newsletter.js.map +1 -0
- package/lib/Socket/socket.d.ts +42 -36
- package/lib/Socket/socket.d.ts.map +1 -0
- package/lib/Socket/socket.js +487 -557
- package/lib/Socket/socket.js.map +1 -0
- package/lib/Types/Auth.d.ts +87 -97
- package/lib/Types/Auth.d.ts.map +1 -0
- package/lib/Types/Auth.js +2 -3
- package/lib/Types/Auth.js.map +1 -0
- package/lib/Types/Bussines.d.ts +25 -0
- package/lib/Types/Bussines.d.ts.map +1 -0
- package/lib/Types/Bussines.js +2 -3
- package/lib/Types/Bussines.js.map +1 -0
- package/lib/Types/Call.d.ts +13 -13
- package/lib/Types/Call.d.ts.map +1 -0
- package/lib/Types/Call.js +2 -3
- package/lib/Types/Call.js.map +1 -0
- package/lib/Types/Chat.d.ts +77 -97
- package/lib/Types/Chat.d.ts.map +1 -0
- package/lib/Types/Chat.js +8 -9
- package/lib/Types/Chat.js.map +1 -0
- package/lib/Types/Contact.d.ts +10 -9
- package/lib/Types/Contact.d.ts.map +1 -0
- package/lib/Types/Contact.js +2 -3
- package/lib/Types/Contact.js.map +1 -0
- package/lib/Types/Events.d.ts +151 -175
- package/lib/Types/Events.d.ts.map +1 -0
- package/lib/Types/Events.js +2 -3
- package/lib/Types/Events.js.map +1 -0
- package/lib/Types/GroupMetadata.d.ts +49 -48
- package/lib/Types/GroupMetadata.d.ts.map +1 -0
- package/lib/Types/GroupMetadata.js +2 -3
- package/lib/Types/GroupMetadata.js.map +1 -0
- package/lib/Types/Label.d.ts +13 -14
- package/lib/Types/Label.d.ts.map +1 -0
- package/lib/Types/Label.js +24 -30
- package/lib/Types/Label.js.map +1 -0
- package/lib/Types/LabelAssociation.d.ts +15 -20
- package/lib/Types/LabelAssociation.d.ts.map +1 -0
- package/lib/Types/LabelAssociation.js +6 -12
- package/lib/Types/LabelAssociation.js.map +1 -0
- package/lib/Types/Message.d.ts +231 -412
- package/lib/Types/Message.d.ts.map +1 -0
- package/lib/Types/Message.js +11 -19
- package/lib/Types/Message.js.map +1 -0
- package/lib/Types/Newsletter.d.ts +130 -104
- package/lib/Types/Newsletter.d.ts.map +1 -0
- package/lib/Types/Newsletter.js +31 -40
- package/lib/Types/Newsletter.js.map +1 -0
- package/lib/Types/Product.d.ts +58 -71
- package/lib/Types/Product.d.ts.map +1 -0
- package/lib/Types/Product.js +2 -3
- package/lib/Types/Product.js.map +1 -0
- package/lib/Types/Signal.d.ts +60 -82
- package/lib/Types/Signal.d.ts.map +1 -0
- package/lib/Types/Signal.js +2 -3
- package/lib/Types/Signal.js.map +1 -0
- package/lib/Types/Socket.d.ts +73 -81
- package/lib/Types/Socket.d.ts.map +1 -0
- package/lib/Types/Socket.js +3 -3
- package/lib/Types/Socket.js.map +1 -0
- package/lib/Types/State.d.ts +17 -19
- package/lib/Types/State.d.ts.map +1 -0
- package/lib/Types/State.js +13 -14
- package/lib/Types/State.js.map +1 -0
- package/lib/Types/USync.d.ts +8 -8
- package/lib/Types/USync.d.ts.map +1 -0
- package/lib/Types/USync.js +2 -3
- package/lib/Types/USync.js.map +1 -0
- package/lib/Types/index.d.ts +47 -62
- package/lib/Types/index.d.ts.map +1 -0
- package/lib/Types/index.js +26 -50
- package/lib/Types/index.js.map +1 -0
- package/lib/Utils/auth-utils.d.ts +19 -21
- package/lib/Utils/auth-utils.d.ts.map +1 -0
- package/lib/Utils/auth-utils.js +257 -528
- package/lib/Utils/auth-utils.js.map +1 -0
- package/lib/Utils/baileys-event-stream.d.ts +17 -18
- package/lib/Utils/baileys-event-stream.d.ts.map +1 -0
- package/lib/Utils/baileys-event-stream.js +56 -70
- package/lib/Utils/baileys-event-stream.js.map +1 -0
- package/lib/Utils/browser-utils.d.ts +4 -0
- package/lib/Utils/browser-utils.d.ts.map +1 -0
- package/lib/Utils/browser-utils.js +28 -0
- package/lib/Utils/browser-utils.js.map +1 -0
- package/lib/Utils/business.d.ts +23 -29
- package/lib/Utils/business.d.ts.map +1 -0
- package/lib/Utils/business.js +231 -255
- package/lib/Utils/business.js.map +1 -0
- package/lib/Utils/chat-utils.d.ts +70 -82
- package/lib/Utils/chat-utils.d.ts.map +1 -0
- package/lib/Utils/chat-utils.js +763 -809
- package/lib/Utils/chat-utils.js.map +1 -0
- package/lib/Utils/crypto.d.ts +41 -56
- package/lib/Utils/crypto.d.ts.map +1 -0
- package/lib/Utils/crypto.js +142 -189
- package/lib/Utils/crypto.js.map +1 -0
- package/lib/Utils/decode-wa-message.d.ts +48 -53
- package/lib/Utils/decode-wa-message.d.ts.map +1 -0
- package/lib/Utils/decode-wa-message.js +279 -323
- package/lib/Utils/decode-wa-message.js.map +1 -0
- package/lib/Utils/event-buffer.d.ts +34 -39
- package/lib/Utils/event-buffer.d.ts.map +1 -0
- package/lib/Utils/event-buffer.js +548 -595
- package/lib/Utils/event-buffer.js.map +1 -0
- package/lib/Utils/generics.d.ts +90 -131
- package/lib/Utils/generics.d.ts.map +1 -0
- package/lib/Utils/generics.js +381 -630
- package/lib/Utils/generics.js.map +1 -0
- package/lib/Utils/history.d.ts +19 -23
- package/lib/Utils/history.d.ts.map +1 -0
- package/lib/Utils/history.js +84 -104
- package/lib/Utils/history.js.map +1 -0
- package/lib/Utils/index.d.ts +20 -20
- package/lib/Utils/index.d.ts.map +1 -0
- package/lib/Utils/index.js +19 -40
- package/lib/Utils/index.js.map +1 -0
- package/lib/Utils/link-preview.d.ts +21 -23
- package/lib/Utils/link-preview.d.ts.map +1 -0
- package/lib/Utils/link-preview.js +85 -120
- package/lib/Utils/link-preview.js.map +1 -0
- package/lib/Utils/logger.d.ts +12 -13
- package/lib/Utils/logger.d.ts.map +1 -0
- package/lib/Utils/logger.js +3 -7
- package/lib/Utils/logger.js.map +1 -0
- package/lib/Utils/lt-hash.d.ts +13 -14
- package/lib/Utils/lt-hash.d.ts.map +1 -0
- package/lib/Utils/lt-hash.js +48 -58
- package/lib/Utils/lt-hash.js.map +1 -0
- package/lib/Utils/make-mutex.d.ts +8 -9
- package/lib/Utils/make-mutex.d.ts.map +1 -0
- package/lib/Utils/make-mutex.js +40 -49
- package/lib/Utils/make-mutex.js.map +1 -0
- package/lib/Utils/message-retry-manager.d.ts +82 -88
- package/lib/Utils/message-retry-manager.d.ts.map +1 -0
- package/lib/Utils/message-retry-manager.js +149 -160
- package/lib/Utils/message-retry-manager.js.map +1 -0
- package/lib/Utils/messages-media.d.ts +114 -135
- package/lib/Utils/messages-media.d.ts.map +1 -0
- package/lib/Utils/messages-media.js +663 -869
- package/lib/Utils/messages-media.js.map +1 -0
- package/lib/Utils/messages.d.ts +76 -105
- package/lib/Utils/messages.d.ts.map +1 -0
- package/lib/Utils/messages.js +820 -1745
- package/lib/Utils/messages.js.map +1 -0
- package/lib/Utils/noise-handler.d.ts +20 -21
- package/lib/Utils/noise-handler.d.ts.map +1 -0
- package/lib/Utils/noise-handler.js +147 -165
- package/lib/Utils/noise-handler.js.map +1 -0
- package/lib/Utils/pre-key-manager.d.ts +28 -0
- package/lib/Utils/pre-key-manager.d.ts.map +1 -0
- package/lib/Utils/pre-key-manager.js +106 -0
- package/lib/Utils/pre-key-manager.js.map +1 -0
- package/lib/Utils/process-message.d.ts +42 -49
- package/lib/Utils/process-message.d.ts.map +1 -0
- package/lib/Utils/process-message.js +413 -427
- package/lib/Utils/process-message.js.map +1 -0
- package/lib/Utils/signal.d.ts +34 -42
- package/lib/Utils/signal.d.ts.map +1 -0
- package/lib/Utils/signal.js +159 -166
- package/lib/Utils/signal.js.map +1 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +13 -18
- package/lib/Utils/use-multi-file-auth-state.d.ts.map +1 -0
- package/lib/Utils/use-multi-file-auth-state.js +121 -238
- package/lib/Utils/use-multi-file-auth-state.js.map +1 -0
- package/lib/Utils/validate-connection.d.ts +11 -13
- package/lib/Utils/validate-connection.d.ts.map +1 -0
- package/lib/Utils/validate-connection.js +195 -220
- package/lib/Utils/validate-connection.js.map +1 -0
- package/lib/WABinary/constants.d.ts +28 -30
- package/lib/WABinary/constants.d.ts.map +1 -0
- package/lib/WABinary/constants.js +1301 -1316
- package/lib/WABinary/constants.js.map +1 -0
- package/lib/WABinary/decode.d.ts +7 -9
- package/lib/WABinary/decode.d.ts.map +1 -0
- package/lib/WABinary/decode.js +238 -288
- package/lib/WABinary/decode.js.map +1 -0
- package/lib/WABinary/encode.d.ts +3 -3
- package/lib/WABinary/encode.d.ts.map +1 -0
- package/lib/WABinary/encode.js +216 -265
- package/lib/WABinary/encode.js.map +1 -0
- package/lib/WABinary/generic-utils.d.ts +15 -28
- package/lib/WABinary/generic-utils.d.ts.map +1 -0
- package/lib/WABinary/generic-utils.js +102 -142
- package/lib/WABinary/generic-utils.js.map +1 -0
- package/lib/WABinary/index.d.ts +6 -5
- package/lib/WABinary/index.d.ts.map +1 -0
- package/lib/WABinary/index.js +6 -25
- package/lib/WABinary/index.js.map +1 -0
- package/lib/WABinary/jid-utils.d.ts +48 -58
- package/lib/WABinary/jid-utils.d.ts.map +1 -0
- package/lib/WABinary/jid-utils.js +96 -104
- package/lib/WABinary/jid-utils.js.map +1 -0
- package/lib/WABinary/types.d.ts +19 -22
- package/lib/WABinary/types.d.ts.map +1 -0
- package/lib/WABinary/types.js +2 -3
- package/lib/WABinary/types.js.map +1 -0
- package/lib/WAM/BinaryInfo.d.ts +9 -16
- package/lib/WAM/BinaryInfo.d.ts.map +1 -0
- package/lib/WAM/BinaryInfo.js +10 -17
- package/lib/WAM/BinaryInfo.js.map +1 -0
- package/lib/WAM/constants.d.ts +40 -47
- package/lib/WAM/constants.d.ts.map +1 -0
- package/lib/WAM/constants.js +22853 -15371
- package/lib/WAM/constants.js.map +1 -0
- package/lib/WAM/encode.d.ts +3 -3
- package/lib/WAM/encode.d.ts.map +1 -0
- package/lib/WAM/encode.js +150 -164
- package/lib/WAM/encode.js.map +1 -0
- package/lib/WAM/index.d.ts +4 -3
- package/lib/WAM/index.d.ts.map +1 -0
- package/lib/WAM/index.js +4 -23
- package/lib/WAM/index.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -9
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +12 -19
- package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +19 -22
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +18 -26
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +11 -12
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +12 -20
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +11 -12
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +16 -24
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +51 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +29 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/index.d.ts +5 -6
- package/lib/WAUSync/Protocols/index.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/index.js +5 -26
- package/lib/WAUSync/Protocols/index.js.map +1 -0
- package/lib/WAUSync/USyncQuery.d.ts +26 -28
- package/lib/WAUSync/USyncQuery.d.ts.map +1 -0
- package/lib/WAUSync/USyncQuery.js +64 -62
- package/lib/WAUSync/USyncQuery.js.map +1 -0
- package/lib/WAUSync/USyncUser.d.ts +11 -10
- package/lib/WAUSync/USyncUser.d.ts.map +1 -0
- package/lib/WAUSync/USyncUser.js +12 -19
- package/lib/WAUSync/USyncUser.js.map +1 -0
- package/lib/WAUSync/index.d.ts +4 -3
- package/lib/WAUSync/index.d.ts.map +1 -0
- package/lib/WAUSync/index.js +4 -23
- package/lib/WAUSync/index.js.map +1 -0
- package/lib/index.d.ts +12 -13
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +11 -33
- package/lib/index.js.map +1 -0
- package/package.json +99 -96
- package/lib/Defaults/baileys-version.json +0 -3
- package/lib/Defaults/phonenumber-mcc.json +0 -223
- package/lib/Signal/WASignalGroup/GroupProtocol.js +0 -1909
- package/lib/Signal/WASignalGroup/ciphertext-message.d.ts +0 -9
- package/lib/Signal/WASignalGroup/ciphertext-message.js +0 -19
- package/lib/Signal/WASignalGroup/ciphertext_message.js +0 -16
- package/lib/Signal/WASignalGroup/generate-proto.sh +0 -1
- package/lib/Signal/WASignalGroup/group-session-builder.js +0 -72
- package/lib/Signal/WASignalGroup/group.proto +0 -42
- package/lib/Signal/WASignalGroup/group_cipher.d.ts +0 -19
- package/lib/Signal/WASignalGroup/group_session_builder.js +0 -46
- package/lib/Signal/WASignalGroup/index.d.ts +0 -11
- package/lib/Signal/WASignalGroup/index.js +0 -61
- package/lib/Signal/WASignalGroup/keyhelper.d.ts +0 -16
- package/lib/Signal/WASignalGroup/keyhelper.js +0 -66
- package/lib/Signal/WASignalGroup/protobufs.js +0 -3
- package/lib/Signal/WASignalGroup/queue_job.js +0 -69
- package/lib/Signal/WASignalGroup/readme.md +0 -6
- package/lib/Signal/WASignalGroup/sender-chain-key.d.ts +0 -14
- package/lib/Signal/WASignalGroup/sender-chain-key.js +0 -47
- package/lib/Signal/WASignalGroup/sender-key-distribution-message.d.ts +0 -17
- package/lib/Signal/WASignalGroup/sender-key-distribution-message.js +0 -71
- package/lib/Signal/WASignalGroup/sender-key-message.d.ts +0 -19
- package/lib/Signal/WASignalGroup/sender-key-message.js +0 -73
- package/lib/Signal/WASignalGroup/sender-key-name.d.ts +0 -19
- package/lib/Signal/WASignalGroup/sender-key-name.js +0 -59
- package/lib/Signal/WASignalGroup/sender-key-record.d.ts +0 -32
- package/lib/Signal/WASignalGroup/sender-key-record.js +0 -58
- package/lib/Signal/WASignalGroup/sender-key-state.d.ts +0 -44
- package/lib/Signal/WASignalGroup/sender-key-state.js +0 -147
- package/lib/Signal/WASignalGroup/sender-message-key.d.ts +0 -11
- package/lib/Signal/WASignalGroup/sender-message-key.js +0 -33
- package/lib/Signal/WASignalGroup/sender_chain_key.js +0 -50
- package/lib/Signal/WASignalGroup/sender_key_distribution_message.js +0 -78
- package/lib/Signal/WASignalGroup/sender_key_message.js +0 -92
- package/lib/Signal/WASignalGroup/sender_key_name.js +0 -70
- package/lib/Signal/WASignalGroup/sender_key_record.js +0 -56
- package/lib/Signal/WASignalGroup/sender_key_state.js +0 -129
- package/lib/Socket/Client/abstract-socket-client.d.ts +0 -15
- package/lib/Socket/Client/abstract-socket-client.js +0 -13
- package/lib/Socket/Client/mobile-socket-client.d.ts +0 -12
- package/lib/Socket/Client/mobile-socket-client.js +0 -65
- package/lib/Socket/usync.d.ts +0 -37
- package/lib/Socket/usync.js +0 -83
- package/lib/Store/index.d.ts +0 -4
- package/lib/Store/index.js +0 -24
- package/lib/Store/make-cache-manager-store.d.ts +0 -14
- package/lib/Store/make-cache-manager-store.js +0 -90
- package/lib/Store/make-in-memory-store.d.ts +0 -123
- package/lib/Store/make-in-memory-store.js +0 -429
- package/lib/Store/make-ordered-dictionary.d.ts +0 -12
- package/lib/Store/make-ordered-dictionary.js +0 -86
- package/lib/Store/object-repository.d.ts +0 -10
- package/lib/Store/object-repository.js +0 -31
- package/lib/Types/Bussiness.d.ts +0 -28
- package/lib/Types/MexUpdates.d.ts +0 -9
- package/lib/Types/MexUpdates.js +0 -18
- package/lib/Utils/use-mongo-file-auth-state.d.ts +0 -6
- package/lib/Utils/use-mongo-file-auth-state.js +0 -84
- package/lib/Utils/use-single-file-auth-state.d.ts +0 -13
- package/lib/Utils/use-single-file-auth-state.js +0 -80
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.d.ts +0 -28
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +0 -69
- package/lib/WAUSync/Protocols/USyncLIDProtocol.d.ts +0 -10
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +0 -38
package/lib/Socket/socket.js
CHANGED
|
@@ -1,96 +1,163 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const Client_1 = require("./Client")
|
|
15
|
-
const WAUSync_1 = require("../WAUSync")
|
|
16
|
-
|
|
1
|
+
import { Boom } from '@hapi/boom';
|
|
2
|
+
import { randomBytes } from 'crypto';
|
|
3
|
+
import { URL } from 'url';
|
|
4
|
+
import { promisify } from 'util';
|
|
5
|
+
import { proto } from '../../WAProto/index.js';
|
|
6
|
+
import { DEF_CALLBACK_PREFIX, DEF_TAG_PREFIX, INITIAL_PREKEY_COUNT, MIN_PREKEY_COUNT, MIN_UPLOAD_INTERVAL, NOISE_WA_HEADER, UPLOAD_TIMEOUT } from '../Defaults/index.js';
|
|
7
|
+
import { DisconnectReason } from '../Types/index.js';
|
|
8
|
+
import { addTransactionCapability, aesEncryptCTR, bindWaitForConnectionUpdate, bytesToCrockford, configureSuccessfulPairing, Curve, derivePairingCodeKey, generateLoginNode, generateMdTagPrefix, generateRegistrationNode, getCodeFromWSError, getErrorCodeFromStreamError, getNextPreKeysNode, makeEventBuffer, makeNoiseHandler, promiseTimeout } from '../Utils/index.js';
|
|
9
|
+
import { getPlatformId } from '../Utils/browser-utils.js';
|
|
10
|
+
import { assertNodeErrorFree, binaryNodeToString, encodeBinaryNode, getBinaryNodeChild, getBinaryNodeChildren, isLidUser, jidDecode, jidEncode, S_WHATSAPP_NET } from '../WABinary/index.js';
|
|
11
|
+
import { BinaryInfo } from '../WAM/BinaryInfo.js';
|
|
12
|
+
import { USyncQuery, USyncUser } from '../WAUSync/index.js';
|
|
13
|
+
import { WebSocketClient } from './Client/index.js';
|
|
17
14
|
/**
|
|
18
15
|
* Connects to WA servers and performs:
|
|
19
16
|
* - simple queries (no retry mechanism, wait for connection establishment)
|
|
20
17
|
* - listen to messages and emit events
|
|
21
18
|
* - query phone connection
|
|
22
19
|
*/
|
|
23
|
-
const makeSocket = (config) => {
|
|
24
|
-
const { waWebSocketUrl, connectTimeoutMs, logger, keepAliveIntervalMs, browser, auth: authState, printQRInTerminal, defaultQueryTimeoutMs, transactionOpts, qrTimeout, makeSignalRepository } = config
|
|
25
|
-
|
|
26
|
-
const uqTagId =
|
|
27
|
-
const generateMessageTag = () => `${uqTagId}${epoch++}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
20
|
+
export const makeSocket = (config) => {
|
|
21
|
+
const { waWebSocketUrl, connectTimeoutMs, logger, keepAliveIntervalMs, browser, auth: authState, printQRInTerminal, defaultQueryTimeoutMs, transactionOpts, qrTimeout, makeSignalRepository } = config;
|
|
22
|
+
const publicWAMBuffer = new BinaryInfo();
|
|
23
|
+
const uqTagId = generateMdTagPrefix();
|
|
24
|
+
const generateMessageTag = () => `${uqTagId}${epoch++}`;
|
|
25
|
+
if (config.printQRInTerminal) {
|
|
26
|
+
try {
|
|
27
|
+
import('qrcode-terminal').then(qrcode => {
|
|
28
|
+
ev.on('connection.update', ({ qr, connection }) => {
|
|
29
|
+
if (qr) {
|
|
30
|
+
console.log('\n🌸Offizielle @Neelegirl/Baileys Version 1.5.4🌸');
|
|
31
|
+
console.log('。☆✼★━━━━━━━━━━━━★✼☆。');
|
|
32
|
+
console.log('📱 Neuer QR-Code erhalten Powered By @neelegirl/baileys');
|
|
33
|
+
qrcode.default.generate(qr, { small: true });
|
|
34
|
+
console.log('。☆✼★━━━━━━━━━━━━★✼☆。\n');
|
|
35
|
+
}
|
|
36
|
+
if (connection === 'open') {
|
|
37
|
+
//console.log('✅ Verbindung zu WhatsApp erfolgreich aufgebaut!');
|
|
38
|
+
}
|
|
39
|
+
if (connection === 'close') {
|
|
40
|
+
//console.log('❌ Verbindung geschlossen. Warte auf neuen QR...');
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}).catch(() => {
|
|
44
|
+
//console.warn('⚠️ QR-Terminal-Modul nicht gefunden. Installiere es mit: npm install qrcode-terminal');
|
|
45
|
+
});
|
|
46
|
+
} catch (err) {
|
|
47
|
+
//console.warn('⚠️ Fehler beim Laden von qrcode-terminal:', err.message);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const url = typeof waWebSocketUrl === 'string' ? new URL(waWebSocketUrl) : waWebSocketUrl;
|
|
31
52
|
if (config.mobile || url.protocol === 'tcp:') {
|
|
32
|
-
throw new
|
|
53
|
+
throw new Boom('Mobile API is not supported anymore', { statusCode: DisconnectReason.loggedOut });
|
|
33
54
|
}
|
|
34
|
-
|
|
35
55
|
if (url.protocol === 'wss' && authState?.creds?.routingInfo) {
|
|
36
|
-
url.searchParams.append('ED', authState.creds.routingInfo.toString('base64url'))
|
|
56
|
+
url.searchParams.append('ED', authState.creds.routingInfo.toString('base64url'));
|
|
37
57
|
}
|
|
38
|
-
|
|
58
|
+
/** ephemeral key pair used to encrypt/decrypt communication. Unique for each connection */
|
|
59
|
+
const ephemeralKeyPair = Curve.generateKeyPair();
|
|
60
|
+
/** WA noise protocol wrapper */
|
|
61
|
+
const noise = makeNoiseHandler({
|
|
62
|
+
keyPair: ephemeralKeyPair,
|
|
63
|
+
NOISE_HEADER: NOISE_WA_HEADER,
|
|
64
|
+
logger,
|
|
65
|
+
routingInfo: authState?.creds?.routingInfo
|
|
66
|
+
});
|
|
67
|
+
const ws = new WebSocketClient(url, config);
|
|
68
|
+
ws.connect();
|
|
69
|
+
const sendPromise = promisify(ws.send);
|
|
70
|
+
/** send a raw buffer */
|
|
71
|
+
const sendRawMessage = async (data) => {
|
|
72
|
+
if (!ws.isOpen) {
|
|
73
|
+
throw new Boom('Connection Closed', { statusCode: DisconnectReason.connectionClosed });
|
|
74
|
+
}
|
|
75
|
+
const bytes = noise.encodeFrame(data);
|
|
76
|
+
await promiseTimeout(connectTimeoutMs, async (resolve, reject) => {
|
|
77
|
+
try {
|
|
78
|
+
await sendPromise.call(ws, bytes);
|
|
79
|
+
resolve();
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
reject(error);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
/** send a binary node */
|
|
87
|
+
const sendNode = (frame) => {
|
|
88
|
+
if (logger.level === 'trace') {
|
|
89
|
+
logger.trace({ xml: binaryNodeToString(frame), msg: 'xml send' });
|
|
90
|
+
}
|
|
91
|
+
const buff = encodeBinaryNode(frame);
|
|
92
|
+
return sendRawMessage(buff);
|
|
93
|
+
};
|
|
39
94
|
/**
|
|
40
95
|
* Wait for a message with a certain tag to be received
|
|
41
96
|
* @param msgId the message tag to await
|
|
42
97
|
* @param timeoutMs timeout after which the promise will reject
|
|
43
98
|
*/
|
|
44
99
|
const waitForMessage = async (msgId, timeoutMs = defaultQueryTimeoutMs) => {
|
|
45
|
-
let onRecv
|
|
46
|
-
let onErr
|
|
100
|
+
let onRecv;
|
|
101
|
+
let onErr;
|
|
47
102
|
try {
|
|
48
|
-
|
|
49
|
-
onRecv =
|
|
103
|
+
const result = await promiseTimeout(timeoutMs, (resolve, reject) => {
|
|
104
|
+
onRecv = data => {
|
|
105
|
+
resolve(data);
|
|
106
|
+
};
|
|
50
107
|
onErr = err => {
|
|
51
|
-
reject(err ||
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
108
|
+
reject(err ||
|
|
109
|
+
new Boom('Connection Closed', {
|
|
110
|
+
statusCode: DisconnectReason.connectionClosed
|
|
111
|
+
}));
|
|
112
|
+
};
|
|
113
|
+
ws.on(`TAG:${msgId}`, onRecv);
|
|
114
|
+
ws.on('close', onErr);
|
|
115
|
+
ws.on('error', onErr);
|
|
116
|
+
return () => reject(new Boom('Query Cancelled'));
|
|
117
|
+
});
|
|
118
|
+
return result;
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
// Catch timeout and return undefined instead of throwing
|
|
122
|
+
if (error instanceof Boom && error.output?.statusCode === DisconnectReason.timedOut) {
|
|
123
|
+
logger?.warn?.({ msgId }, 'timed out waiting for message');
|
|
124
|
+
return undefined;
|
|
125
|
+
}
|
|
126
|
+
throw error;
|
|
57
127
|
}
|
|
58
|
-
|
|
59
128
|
finally {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
129
|
+
if (onRecv)
|
|
130
|
+
ws.off(`TAG:${msgId}`, onRecv);
|
|
131
|
+
if (onErr) {
|
|
132
|
+
ws.off('close', onErr);
|
|
133
|
+
ws.off('error', onErr);
|
|
134
|
+
}
|
|
63
135
|
}
|
|
64
|
-
}
|
|
65
|
-
|
|
136
|
+
};
|
|
66
137
|
/** send a query, and wait for its response. auto-generates message ID if not provided */
|
|
67
138
|
const query = async (node, timeoutMs) => {
|
|
68
139
|
if (!node.attrs.id) {
|
|
69
|
-
node.attrs.id = generateMessageTag()
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
return result
|
|
84
|
-
}
|
|
85
|
-
|
|
140
|
+
node.attrs.id = generateMessageTag();
|
|
141
|
+
}
|
|
142
|
+
const msgId = node.attrs.id;
|
|
143
|
+
const result = await promiseTimeout(timeoutMs, async (resolve, reject) => {
|
|
144
|
+
const result = waitForMessage(msgId, timeoutMs).catch(reject);
|
|
145
|
+
sendNode(node)
|
|
146
|
+
.then(async () => resolve(await result))
|
|
147
|
+
.catch(reject);
|
|
148
|
+
});
|
|
149
|
+
if (result && 'tag' in result) {
|
|
150
|
+
assertNodeErrorFree(result);
|
|
151
|
+
}
|
|
152
|
+
return result;
|
|
153
|
+
};
|
|
86
154
|
const executeUSyncQuery = async (usyncQuery) => {
|
|
87
155
|
if (usyncQuery.protocols.length === 0) {
|
|
88
|
-
throw new
|
|
156
|
+
throw new Boom('USyncQuery must have at least one protocol');
|
|
89
157
|
}
|
|
90
|
-
|
|
91
158
|
// todo: validate users, throw WARNING on no valid users
|
|
92
159
|
// variable below has only validated users
|
|
93
|
-
const validUsers = usyncQuery.users
|
|
160
|
+
const validUsers = usyncQuery.users;
|
|
94
161
|
const userNodes = validUsers.map(user => {
|
|
95
162
|
return {
|
|
96
163
|
tag: 'user',
|
|
@@ -98,25 +165,22 @@ const makeSocket = (config) => {
|
|
|
98
165
|
jid: !user.phone ? user.id : undefined
|
|
99
166
|
},
|
|
100
167
|
content: usyncQuery.protocols.map(a => a.getUserElement(user)).filter(a => a !== null)
|
|
101
|
-
}
|
|
102
|
-
})
|
|
103
|
-
|
|
168
|
+
};
|
|
169
|
+
});
|
|
104
170
|
const listNode = {
|
|
105
171
|
tag: 'list',
|
|
106
172
|
attrs: {},
|
|
107
173
|
content: userNodes
|
|
108
|
-
}
|
|
109
|
-
|
|
174
|
+
};
|
|
110
175
|
const queryNode = {
|
|
111
176
|
tag: 'query',
|
|
112
177
|
attrs: {},
|
|
113
178
|
content: usyncQuery.protocols.map(a => a.getQueryElement())
|
|
114
|
-
}
|
|
115
|
-
|
|
179
|
+
};
|
|
116
180
|
const iq = {
|
|
117
181
|
tag: 'iq',
|
|
118
182
|
attrs: {
|
|
119
|
-
to:
|
|
183
|
+
to: S_WHATSAPP_NET,
|
|
120
184
|
type: 'get',
|
|
121
185
|
xmlns: 'usync'
|
|
122
186
|
},
|
|
@@ -133,168 +197,125 @@ const makeSocket = (config) => {
|
|
|
133
197
|
content: [queryNode, listNode]
|
|
134
198
|
}
|
|
135
199
|
]
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
200
|
+
};
|
|
201
|
+
const result = await query(iq);
|
|
202
|
+
return usyncQuery.parseUSyncQueryResult(result);
|
|
203
|
+
};
|
|
204
|
+
const onWhatsApp = async (...phoneNumber) => {
|
|
205
|
+
let usyncQuery = new USyncQuery();
|
|
206
|
+
let contactEnabled = false;
|
|
207
|
+
for (const jid of phoneNumber) {
|
|
208
|
+
if (isLidUser(jid)) {
|
|
209
|
+
logger?.warn('LIDs are not supported with onWhatsApp');
|
|
210
|
+
continue;
|
|
147
211
|
}
|
|
148
212
|
else {
|
|
149
|
-
|
|
150
|
-
|
|
213
|
+
if (!contactEnabled) {
|
|
214
|
+
contactEnabled = true;
|
|
215
|
+
usyncQuery = usyncQuery.withContactProtocol();
|
|
216
|
+
}
|
|
217
|
+
const phone = `+${jid.replace('+', '').split('@')[0]?.split(':')[0]}`;
|
|
218
|
+
usyncQuery.withUser(new USyncUser().withPhone(phone));
|
|
151
219
|
}
|
|
152
220
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
if (results.list.filter(a => !!a.lid).length > 0) {
|
|
156
|
-
const lidOnly = results.list.filter(a => !!a.lid)
|
|
157
|
-
await signalRepository.lidMapping.storeLIDPNMappings(lidOnly.map(a => ({ pn: a.id, lid: a.lid })))
|
|
158
|
-
}
|
|
159
|
-
return results.list
|
|
160
|
-
.filter(a => !!a.contact)
|
|
161
|
-
.map(({ contact, id, lid }) => ({ jid: id, exists: contact, lid: lid }))
|
|
221
|
+
if (usyncQuery.users.length === 0) {
|
|
222
|
+
return []; // return early without forcing an empty query
|
|
162
223
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
ws.connect()
|
|
168
|
-
const ev = Utils_1.makeEventBuffer(logger)
|
|
169
|
-
|
|
170
|
-
/** ephemeral key pair used to encrypt/decrypt communication. Unique for each connection */
|
|
171
|
-
const ephemeralKeyPair = Utils_1.Curve.generateKeyPair()
|
|
172
|
-
|
|
173
|
-
/** WA noise protocol wrapper */
|
|
174
|
-
const noise = Utils_1.makeNoiseHandler({
|
|
175
|
-
keyPair: ephemeralKeyPair,
|
|
176
|
-
NOISE_HEADER: Defaults_1.NOISE_WA_HEADER,
|
|
177
|
-
logger,
|
|
178
|
-
routingInfo: authState?.creds?.routingInfo
|
|
179
|
-
})
|
|
180
|
-
|
|
181
|
-
const { creds } = authState
|
|
182
|
-
|
|
183
|
-
// add transaction capability
|
|
184
|
-
const keys = Utils_1.addTransactionCapability(authState.keys, logger, transactionOpts)
|
|
185
|
-
const signalRepository = makeSignalRepository({ creds, keys }, onWhatsApp, logger)
|
|
186
|
-
|
|
187
|
-
let lastDateRecv
|
|
188
|
-
let epoch = 1
|
|
189
|
-
let keepAliveReq
|
|
190
|
-
let qrTimer
|
|
191
|
-
let closed = false
|
|
192
|
-
|
|
193
|
-
const sendPromise = util_1.promisify(ws.send)
|
|
194
|
-
|
|
195
|
-
/** send a raw buffer */
|
|
196
|
-
const sendRawMessage = async (data) => {
|
|
197
|
-
if (!ws.isOpen) {
|
|
198
|
-
throw new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed })
|
|
224
|
+
const results = await executeUSyncQuery(usyncQuery);
|
|
225
|
+
if (results) {
|
|
226
|
+
return results.list.filter(a => !!a.contact).map(({ contact, id }) => ({ jid: id, exists: contact }));
|
|
199
227
|
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
228
|
+
};
|
|
229
|
+
const pnFromLIDUSync = async (jids) => {
|
|
230
|
+
const usyncQuery = new USyncQuery().withLIDProtocol().withContext('background');
|
|
231
|
+
for (const jid of jids) {
|
|
232
|
+
if (isLidUser(jid)) {
|
|
233
|
+
logger?.warn('LID user found in LID fetch call');
|
|
234
|
+
continue;
|
|
206
235
|
}
|
|
207
|
-
|
|
208
|
-
|
|
236
|
+
else {
|
|
237
|
+
usyncQuery.withUser(new USyncUser().withId(jid));
|
|
209
238
|
}
|
|
210
|
-
})
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
/** send a binary node */
|
|
214
|
-
const sendNode = (frame) => {
|
|
215
|
-
if (logger.level === 'trace') {
|
|
216
|
-
logger.trace({ xml: WABinary_1.binaryNodeToString(frame), msg: 'xml send' })
|
|
217
239
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
240
|
+
if (usyncQuery.users.length === 0) {
|
|
241
|
+
return []; // return early without forcing an empty query
|
|
242
|
+
}
|
|
243
|
+
const results = await executeUSyncQuery(usyncQuery);
|
|
244
|
+
if (results) {
|
|
245
|
+
return results.list.filter(a => !!a.lid).map(({ lid, id }) => ({ pn: id, lid: lid }));
|
|
246
|
+
}
|
|
247
|
+
return [];
|
|
248
|
+
};
|
|
249
|
+
const ev = makeEventBuffer(logger);
|
|
250
|
+
const { creds } = authState;
|
|
251
|
+
// add transaction capability
|
|
252
|
+
const keys = addTransactionCapability(authState.keys, logger, transactionOpts);
|
|
253
|
+
const signalRepository = makeSignalRepository({ creds, keys }, logger, pnFromLIDUSync);
|
|
254
|
+
let lastDateRecv;
|
|
255
|
+
let epoch = 1;
|
|
256
|
+
let keepAliveReq;
|
|
257
|
+
let qrTimer;
|
|
258
|
+
let closed = false;
|
|
224
259
|
/** log & process any unexpected errors */
|
|
225
260
|
const onUnexpectedError = (err, msg) => {
|
|
226
|
-
logger.error({ err }, `unexpected error in '${msg}'`)
|
|
227
|
-
}
|
|
228
|
-
|
|
261
|
+
logger.error({ err }, `unexpected error in '${msg}'`);
|
|
262
|
+
};
|
|
229
263
|
/** await the next incoming message */
|
|
230
264
|
const awaitNextMessage = async (sendMsg) => {
|
|
231
265
|
if (!ws.isOpen) {
|
|
232
|
-
throw new
|
|
233
|
-
statusCode:
|
|
234
|
-
})
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
let
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
onOpen
|
|
242
|
-
onClose
|
|
243
|
-
ws.on('
|
|
244
|
-
ws.on('close', onClose)
|
|
245
|
-
ws.on('error', onClose)
|
|
266
|
+
throw new Boom('Connection Closed', {
|
|
267
|
+
statusCode: DisconnectReason.connectionClosed
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
let onOpen;
|
|
271
|
+
let onClose;
|
|
272
|
+
const result = promiseTimeout(connectTimeoutMs, (resolve, reject) => {
|
|
273
|
+
onOpen = resolve;
|
|
274
|
+
onClose = mapWebSocketError(reject);
|
|
275
|
+
ws.on('frame', onOpen);
|
|
276
|
+
ws.on('close', onClose);
|
|
277
|
+
ws.on('error', onClose);
|
|
246
278
|
}).finally(() => {
|
|
247
|
-
ws.off('frame', onOpen)
|
|
248
|
-
ws.off('close', onClose)
|
|
249
|
-
ws.off('error', onClose)
|
|
250
|
-
})
|
|
251
|
-
|
|
279
|
+
ws.off('frame', onOpen);
|
|
280
|
+
ws.off('close', onClose);
|
|
281
|
+
ws.off('error', onClose);
|
|
282
|
+
});
|
|
252
283
|
if (sendMsg) {
|
|
253
|
-
sendRawMessage(sendMsg).catch(onClose)
|
|
284
|
+
sendRawMessage(sendMsg).catch(onClose);
|
|
254
285
|
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
}
|
|
258
|
-
|
|
286
|
+
return result;
|
|
287
|
+
};
|
|
259
288
|
/** connection handshake */
|
|
260
289
|
const validateConnection = async () => {
|
|
261
290
|
let helloMsg = {
|
|
262
291
|
clientHello: { ephemeral: ephemeralKeyPair.public }
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
helloMsg
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
const
|
|
269
|
-
|
|
270
|
-
const
|
|
271
|
-
|
|
272
|
-
logger.trace({ handshake }, 'handshake recv from WA')
|
|
273
|
-
|
|
274
|
-
const keyEnc = await noise.processHandshake(handshake, creds.noiseKey)
|
|
275
|
-
let node
|
|
276
|
-
|
|
292
|
+
};
|
|
293
|
+
helloMsg = proto.HandshakeMessage.fromObject(helloMsg);
|
|
294
|
+
logger.info({ browser, helloMsg }, 'connected to WA');
|
|
295
|
+
const init = proto.HandshakeMessage.encode(helloMsg).finish();
|
|
296
|
+
const result = await awaitNextMessage(init);
|
|
297
|
+
const handshake = proto.HandshakeMessage.decode(result);
|
|
298
|
+
logger.trace({ handshake }, 'handshake recv from WA');
|
|
299
|
+
const keyEnc = await noise.processHandshake(handshake, creds.noiseKey);
|
|
300
|
+
let node;
|
|
277
301
|
if (!creds.me) {
|
|
278
|
-
node =
|
|
279
|
-
logger.info({ node }, 'not logged in, attempting registration...')
|
|
302
|
+
node = generateRegistrationNode(creds, config);
|
|
303
|
+
logger.info({ node }, 'not logged in, attempting registration...');
|
|
280
304
|
}
|
|
281
|
-
|
|
282
305
|
else {
|
|
283
|
-
node =
|
|
284
|
-
logger.info({ node }, 'logging in...')
|
|
306
|
+
node = generateLoginNode(creds.me.id, config);
|
|
307
|
+
logger.info({ node }, 'logging in...');
|
|
285
308
|
}
|
|
286
|
-
const payloadEnc = noise.encrypt(
|
|
287
|
-
|
|
288
|
-
await sendRawMessage(WAProto_1.proto.HandshakeMessage.encode({
|
|
309
|
+
const payloadEnc = noise.encrypt(proto.ClientPayload.encode(node).finish());
|
|
310
|
+
await sendRawMessage(proto.HandshakeMessage.encode({
|
|
289
311
|
clientFinish: {
|
|
290
312
|
static: keyEnc,
|
|
291
|
-
payload: payloadEnc
|
|
292
|
-
}
|
|
293
|
-
}).finish())
|
|
294
|
-
noise.finishInit()
|
|
295
|
-
startKeepAliveRequest()
|
|
296
|
-
}
|
|
297
|
-
|
|
313
|
+
payload: payloadEnc
|
|
314
|
+
}
|
|
315
|
+
}).finish());
|
|
316
|
+
noise.finishInit();
|
|
317
|
+
startKeepAliveRequest();
|
|
318
|
+
};
|
|
298
319
|
const getAvailablePreKeysOnServer = async () => {
|
|
299
320
|
const result = await query({
|
|
300
321
|
tag: 'iq',
|
|
@@ -302,281 +323,240 @@ const makeSocket = (config) => {
|
|
|
302
323
|
id: generateMessageTag(),
|
|
303
324
|
xmlns: 'encrypt',
|
|
304
325
|
type: 'get',
|
|
305
|
-
to:
|
|
326
|
+
to: S_WHATSAPP_NET
|
|
306
327
|
},
|
|
307
|
-
content: [
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
const countChild = WABinary_1.getBinaryNodeChild(result, 'count')
|
|
313
|
-
|
|
314
|
-
return +countChild.attrs.value
|
|
315
|
-
}
|
|
316
|
-
|
|
328
|
+
content: [{ tag: 'count', attrs: {} }]
|
|
329
|
+
});
|
|
330
|
+
const countChild = getBinaryNodeChild(result, 'count');
|
|
331
|
+
return +countChild.attrs.value;
|
|
332
|
+
};
|
|
317
333
|
// Pre-key upload state management
|
|
318
|
-
let uploadPreKeysPromise = null
|
|
319
|
-
let lastUploadTime = 0
|
|
320
|
-
|
|
334
|
+
let uploadPreKeysPromise = null;
|
|
335
|
+
let lastUploadTime = 0;
|
|
321
336
|
/** generates and uploads a set of pre-keys to the server */
|
|
322
|
-
const uploadPreKeys = async (count =
|
|
337
|
+
const uploadPreKeys = async (count = MIN_PREKEY_COUNT, retryCount = 0) => {
|
|
323
338
|
// Check minimum interval (except for retries)
|
|
324
339
|
if (retryCount === 0) {
|
|
325
|
-
const timeSinceLastUpload = Date.now() - lastUploadTime
|
|
326
|
-
if (timeSinceLastUpload <
|
|
327
|
-
logger.debug(`Skipping upload, only ${timeSinceLastUpload}ms since last upload`)
|
|
328
|
-
return
|
|
340
|
+
const timeSinceLastUpload = Date.now() - lastUploadTime;
|
|
341
|
+
if (timeSinceLastUpload < MIN_UPLOAD_INTERVAL) {
|
|
342
|
+
logger.debug(`Skipping upload, only ${timeSinceLastUpload}ms since last upload`);
|
|
343
|
+
return;
|
|
329
344
|
}
|
|
330
345
|
}
|
|
331
|
-
|
|
332
346
|
// Prevent multiple concurrent uploads
|
|
333
347
|
if (uploadPreKeysPromise) {
|
|
334
|
-
logger.debug('Pre-key upload already in progress, waiting for completion')
|
|
335
|
-
|
|
348
|
+
logger.debug('Pre-key upload already in progress, waiting for completion');
|
|
349
|
+
await uploadPreKeysPromise;
|
|
336
350
|
}
|
|
337
|
-
|
|
338
351
|
const uploadLogic = async () => {
|
|
339
|
-
logger.info({ count, retryCount }, 'uploading pre-keys')
|
|
340
|
-
|
|
352
|
+
logger.info({ count, retryCount }, 'uploading pre-keys');
|
|
341
353
|
// Generate and save pre-keys atomically (prevents ID collisions on retry)
|
|
342
354
|
const node = await keys.transaction(async () => {
|
|
343
|
-
logger.debug({ requestedCount: count }, 'generating pre-keys with requested count')
|
|
344
|
-
const { update, node } = await
|
|
345
|
-
|
|
355
|
+
logger.debug({ requestedCount: count }, 'generating pre-keys with requested count');
|
|
356
|
+
const { update, node } = await getNextPreKeysNode({ creds, keys }, count);
|
|
346
357
|
// Update credentials immediately to prevent duplicate IDs on retry
|
|
347
|
-
ev.emit('creds.update', update)
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
}, creds?.me?.id || 'upload-pre-keys')
|
|
351
|
-
|
|
358
|
+
ev.emit('creds.update', update);
|
|
359
|
+
return node; // Only return node since update is already used
|
|
360
|
+
}, creds?.me?.id || 'upload-pre-keys');
|
|
352
361
|
// Upload to server (outside transaction, can fail without affecting local keys)
|
|
353
362
|
try {
|
|
354
|
-
await query(node)
|
|
355
|
-
logger.info({ count }, 'uploaded pre-keys successfully')
|
|
356
|
-
lastUploadTime = Date.now()
|
|
363
|
+
await query(node);
|
|
364
|
+
logger.info({ count }, 'uploaded pre-keys successfully');
|
|
365
|
+
lastUploadTime = Date.now();
|
|
357
366
|
}
|
|
358
367
|
catch (uploadError) {
|
|
359
|
-
logger.error({ uploadError, count }, 'Failed to upload pre-keys to server')
|
|
368
|
+
logger.error({ uploadError: uploadError.toString(), count }, 'Failed to upload pre-keys to server');
|
|
360
369
|
// Exponential backoff retry (max 3 retries)
|
|
361
370
|
if (retryCount < 3) {
|
|
362
|
-
const backoffDelay = Math.min(1000 * Math.pow(2, retryCount), 10000)
|
|
363
|
-
logger.info(`Retrying pre-key upload in ${backoffDelay}ms`)
|
|
364
|
-
await new Promise(resolve => setTimeout(resolve, backoffDelay))
|
|
365
|
-
return uploadPreKeys(count, retryCount + 1)
|
|
371
|
+
const backoffDelay = Math.min(1000 * Math.pow(2, retryCount), 10000);
|
|
372
|
+
logger.info(`Retrying pre-key upload in ${backoffDelay}ms`);
|
|
373
|
+
await new Promise(resolve => setTimeout(resolve, backoffDelay));
|
|
374
|
+
return uploadPreKeys(count, retryCount + 1);
|
|
366
375
|
}
|
|
367
|
-
throw uploadError
|
|
376
|
+
throw uploadError;
|
|
368
377
|
}
|
|
369
|
-
}
|
|
370
|
-
|
|
378
|
+
};
|
|
371
379
|
// Add timeout protection
|
|
372
380
|
uploadPreKeysPromise = Promise.race([
|
|
373
381
|
uploadLogic(),
|
|
374
|
-
new Promise((_, reject) => setTimeout(() => reject(new
|
|
375
|
-
])
|
|
382
|
+
new Promise((_, reject) => setTimeout(() => reject(new Boom('Pre-key upload timeout', { statusCode: 408 })), UPLOAD_TIMEOUT))
|
|
383
|
+
]);
|
|
376
384
|
try {
|
|
377
|
-
await uploadPreKeysPromise
|
|
385
|
+
await uploadPreKeysPromise;
|
|
378
386
|
}
|
|
379
387
|
finally {
|
|
380
|
-
uploadPreKeysPromise = null
|
|
388
|
+
uploadPreKeysPromise = null;
|
|
381
389
|
}
|
|
382
|
-
}
|
|
383
|
-
|
|
390
|
+
};
|
|
384
391
|
const verifyCurrentPreKeyExists = async () => {
|
|
385
|
-
const currentPreKeyId = creds.nextPreKeyId - 1
|
|
392
|
+
const currentPreKeyId = creds.nextPreKeyId - 1;
|
|
386
393
|
if (currentPreKeyId <= 0) {
|
|
387
|
-
return { exists: false, currentPreKeyId: 0 }
|
|
394
|
+
return { exists: false, currentPreKeyId: 0 };
|
|
388
395
|
}
|
|
389
|
-
const preKeys = await keys.get('pre-key', [currentPreKeyId.toString()])
|
|
390
|
-
const exists = !!preKeys[currentPreKeyId.toString()]
|
|
391
|
-
return { exists, currentPreKeyId }
|
|
392
|
-
}
|
|
393
|
-
|
|
396
|
+
const preKeys = await keys.get('pre-key', [currentPreKeyId.toString()]);
|
|
397
|
+
const exists = !!preKeys[currentPreKeyId.toString()];
|
|
398
|
+
return { exists, currentPreKeyId };
|
|
399
|
+
};
|
|
394
400
|
const uploadPreKeysToServerIfRequired = async () => {
|
|
395
401
|
try {
|
|
396
|
-
|
|
397
|
-
const
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
const
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
402
|
+
let count = 0;
|
|
403
|
+
const preKeyCount = await getAvailablePreKeysOnServer();
|
|
404
|
+
if (preKeyCount === 0)
|
|
405
|
+
count = INITIAL_PREKEY_COUNT;
|
|
406
|
+
else
|
|
407
|
+
count = MIN_PREKEY_COUNT;
|
|
408
|
+
const { exists: currentPreKeyExists, currentPreKeyId } = await verifyCurrentPreKeyExists();
|
|
409
|
+
logger.info(`${preKeyCount} pre-keys found on server`);
|
|
410
|
+
logger.info(`Current prekey ID: ${currentPreKeyId}, exists in storage: ${currentPreKeyExists}`);
|
|
411
|
+
const lowServerCount = preKeyCount <= count;
|
|
412
|
+
const missingCurrentPreKey = !currentPreKeyExists && currentPreKeyId > 0;
|
|
413
|
+
const shouldUpload = lowServerCount || missingCurrentPreKey;
|
|
406
414
|
if (shouldUpload) {
|
|
407
|
-
const reasons = []
|
|
415
|
+
const reasons = [];
|
|
408
416
|
if (lowServerCount)
|
|
409
|
-
reasons.push(`server count low (${preKeyCount})`)
|
|
417
|
+
reasons.push(`server count low (${preKeyCount})`);
|
|
410
418
|
if (missingCurrentPreKey)
|
|
411
|
-
reasons.push(`current prekey ${currentPreKeyId} missing from storage`)
|
|
412
|
-
logger.info(`Uploading PreKeys due to: ${reasons.join(', ')}`)
|
|
413
|
-
await uploadPreKeys()
|
|
419
|
+
reasons.push(`current prekey ${currentPreKeyId} missing from storage`);
|
|
420
|
+
logger.info(`Uploading PreKeys due to: ${reasons.join(', ')}`);
|
|
421
|
+
await uploadPreKeys(count);
|
|
414
422
|
}
|
|
415
423
|
else {
|
|
416
|
-
logger.info(`PreKey validation passed - Server: ${preKeyCount}, Current prekey ${currentPreKeyId} exists`)
|
|
424
|
+
logger.info(`PreKey validation passed - Server: ${preKeyCount}, Current prekey ${currentPreKeyId} exists`);
|
|
417
425
|
}
|
|
418
426
|
}
|
|
419
427
|
catch (error) {
|
|
420
|
-
logger.error({ error }, 'Failed to check/upload pre-keys during initialization')
|
|
428
|
+
logger.error({ error }, 'Failed to check/upload pre-keys during initialization');
|
|
421
429
|
// Don't throw - allow connection to continue even if pre-key check fails
|
|
422
430
|
}
|
|
423
|
-
}
|
|
424
|
-
|
|
431
|
+
};
|
|
425
432
|
const onMessageReceived = (data) => {
|
|
426
433
|
noise.decodeFrame(data, frame => {
|
|
427
434
|
// reset ping timeout
|
|
428
|
-
lastDateRecv = new Date()
|
|
429
|
-
let anyTriggered = false
|
|
430
|
-
anyTriggered = ws.emit('frame', frame)
|
|
431
|
-
|
|
435
|
+
lastDateRecv = new Date();
|
|
436
|
+
let anyTriggered = false;
|
|
437
|
+
anyTriggered = ws.emit('frame', frame);
|
|
432
438
|
// if it's a binary node
|
|
433
439
|
if (!(frame instanceof Uint8Array)) {
|
|
434
|
-
const msgId = frame.attrs.id
|
|
435
|
-
|
|
440
|
+
const msgId = frame.attrs.id;
|
|
436
441
|
if (logger.level === 'trace') {
|
|
437
|
-
logger.trace({ xml:
|
|
442
|
+
logger.trace({ xml: binaryNodeToString(frame), msg: 'recv xml' });
|
|
438
443
|
}
|
|
439
|
-
|
|
440
444
|
/* Check if this is a response to a message we sent */
|
|
441
|
-
anyTriggered = ws.emit(`${
|
|
442
|
-
|
|
445
|
+
anyTriggered = ws.emit(`${DEF_TAG_PREFIX}${msgId}`, frame) || anyTriggered;
|
|
443
446
|
/* Check if this is a response to a message we are expecting */
|
|
444
|
-
const l0 = frame.tag
|
|
445
|
-
const l1 = frame.attrs || {}
|
|
446
|
-
const l2 = Array.isArray(frame.content) ? frame.content[0]?.tag : ''
|
|
447
|
-
|
|
447
|
+
const l0 = frame.tag;
|
|
448
|
+
const l1 = frame.attrs || {};
|
|
449
|
+
const l2 = Array.isArray(frame.content) ? frame.content[0]?.tag : '';
|
|
448
450
|
for (const key of Object.keys(l1)) {
|
|
449
|
-
anyTriggered = ws.emit(`${
|
|
450
|
-
anyTriggered = ws.emit(`${
|
|
451
|
-
anyTriggered = ws.emit(`${
|
|
451
|
+
anyTriggered = ws.emit(`${DEF_CALLBACK_PREFIX}${l0},${key}:${l1[key]},${l2}`, frame) || anyTriggered;
|
|
452
|
+
anyTriggered = ws.emit(`${DEF_CALLBACK_PREFIX}${l0},${key}:${l1[key]}`, frame) || anyTriggered;
|
|
453
|
+
anyTriggered = ws.emit(`${DEF_CALLBACK_PREFIX}${l0},${key}`, frame) || anyTriggered;
|
|
452
454
|
}
|
|
453
|
-
|
|
454
|
-
anyTriggered = ws.emit(`${
|
|
455
|
-
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0}`, frame) || anyTriggered
|
|
456
|
-
|
|
455
|
+
anyTriggered = ws.emit(`${DEF_CALLBACK_PREFIX}${l0},,${l2}`, frame) || anyTriggered;
|
|
456
|
+
anyTriggered = ws.emit(`${DEF_CALLBACK_PREFIX}${l0}`, frame) || anyTriggered;
|
|
457
457
|
if (!anyTriggered && logger.level === 'debug') {
|
|
458
|
-
logger.debug({ unhandled: true, msgId, fromMe: false, frame }, 'communication recv')
|
|
458
|
+
logger.debug({ unhandled: true, msgId, fromMe: false, frame }, 'communication recv');
|
|
459
459
|
}
|
|
460
460
|
}
|
|
461
|
-
})
|
|
462
|
-
}
|
|
463
|
-
|
|
461
|
+
});
|
|
462
|
+
};
|
|
464
463
|
const end = (error) => {
|
|
465
464
|
if (closed) {
|
|
466
|
-
logger.trace({ trace: error?.stack }, 'connection already closed')
|
|
467
|
-
return
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
ws.removeAllListeners('
|
|
476
|
-
ws.removeAllListeners('open')
|
|
477
|
-
ws.removeAllListeners('message')
|
|
478
|
-
|
|
465
|
+
logger.trace({ trace: error?.stack }, 'connection already closed');
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
closed = true;
|
|
469
|
+
logger.info({ trace: error?.stack }, error ? 'connection errored' : 'connection closed');
|
|
470
|
+
clearInterval(keepAliveReq);
|
|
471
|
+
clearTimeout(qrTimer);
|
|
472
|
+
ws.removeAllListeners('close');
|
|
473
|
+
ws.removeAllListeners('open');
|
|
474
|
+
ws.removeAllListeners('message');
|
|
479
475
|
if (!ws.isClosed && !ws.isClosing) {
|
|
480
476
|
try {
|
|
481
|
-
ws.close()
|
|
477
|
+
ws.close();
|
|
482
478
|
}
|
|
483
|
-
catch
|
|
479
|
+
catch { }
|
|
484
480
|
}
|
|
485
|
-
|
|
486
481
|
ev.emit('connection.update', {
|
|
487
482
|
connection: 'close',
|
|
488
483
|
lastDisconnect: {
|
|
489
484
|
error,
|
|
490
485
|
date: new Date()
|
|
491
486
|
}
|
|
492
|
-
})
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
}
|
|
496
|
-
|
|
487
|
+
});
|
|
488
|
+
ev.removeAllListeners('connection.update');
|
|
489
|
+
};
|
|
497
490
|
const waitForSocketOpen = async () => {
|
|
498
491
|
if (ws.isOpen) {
|
|
499
|
-
return
|
|
492
|
+
return;
|
|
500
493
|
}
|
|
501
|
-
|
|
502
494
|
if (ws.isClosed || ws.isClosing) {
|
|
503
|
-
throw new
|
|
495
|
+
throw new Boom('Connection Closed', { statusCode: DisconnectReason.connectionClosed });
|
|
504
496
|
}
|
|
505
|
-
|
|
506
|
-
let
|
|
507
|
-
let onClose
|
|
508
|
-
|
|
497
|
+
let onOpen;
|
|
498
|
+
let onClose;
|
|
509
499
|
await new Promise((resolve, reject) => {
|
|
510
|
-
onOpen = () => resolve(undefined)
|
|
511
|
-
onClose = mapWebSocketError(reject)
|
|
512
|
-
ws.on('open', onOpen)
|
|
513
|
-
ws.on('close', onClose)
|
|
514
|
-
ws.on('error', onClose)
|
|
500
|
+
onOpen = () => resolve(undefined);
|
|
501
|
+
onClose = mapWebSocketError(reject);
|
|
502
|
+
ws.on('open', onOpen);
|
|
503
|
+
ws.on('close', onClose);
|
|
504
|
+
ws.on('error', onClose);
|
|
515
505
|
}).finally(() => {
|
|
516
|
-
ws.off('open', onOpen)
|
|
517
|
-
ws.off('close', onClose)
|
|
518
|
-
ws.off('error', onClose)
|
|
519
|
-
})
|
|
520
|
-
}
|
|
521
|
-
|
|
506
|
+
ws.off('open', onOpen);
|
|
507
|
+
ws.off('close', onClose);
|
|
508
|
+
ws.off('error', onClose);
|
|
509
|
+
});
|
|
510
|
+
};
|
|
522
511
|
const startKeepAliveRequest = () => (keepAliveReq = setInterval(() => {
|
|
523
512
|
if (!lastDateRecv) {
|
|
524
|
-
lastDateRecv = new Date()
|
|
513
|
+
lastDateRecv = new Date();
|
|
525
514
|
}
|
|
526
|
-
|
|
527
|
-
const diff = Date.now() - lastDateRecv.getTime()
|
|
528
|
-
|
|
515
|
+
const diff = Date.now() - lastDateRecv.getTime();
|
|
529
516
|
/*
|
|
530
517
|
check if it's been a suspicious amount of time since the server responded with our last seen
|
|
531
518
|
it could be that the network is down
|
|
532
519
|
*/
|
|
533
520
|
if (diff > keepAliveIntervalMs + 5000) {
|
|
534
|
-
end(new
|
|
521
|
+
end(new Boom('Connection was lost', { statusCode: DisconnectReason.connectionLost }));
|
|
535
522
|
}
|
|
536
|
-
|
|
537
523
|
else if (ws.isOpen) {
|
|
538
524
|
// if its all good, send a keep alive request
|
|
539
525
|
query({
|
|
540
526
|
tag: 'iq',
|
|
541
527
|
attrs: {
|
|
542
528
|
id: generateMessageTag(),
|
|
543
|
-
to:
|
|
529
|
+
to: S_WHATSAPP_NET,
|
|
544
530
|
type: 'get',
|
|
545
|
-
xmlns: 'w:p'
|
|
531
|
+
xmlns: 'w:p'
|
|
546
532
|
},
|
|
547
533
|
content: [{ tag: 'ping', attrs: {} }]
|
|
548
534
|
}).catch(err => {
|
|
549
|
-
logger.error({ trace: err.stack }, 'error in sending keep alive')
|
|
550
|
-
})
|
|
535
|
+
logger.error({ trace: err.stack }, 'error in sending keep alive');
|
|
536
|
+
});
|
|
551
537
|
}
|
|
552
|
-
|
|
553
538
|
else {
|
|
554
|
-
logger.warn('keep alive called when WS not open')
|
|
539
|
+
logger.warn('keep alive called when WS not open');
|
|
555
540
|
}
|
|
556
|
-
}, keepAliveIntervalMs))
|
|
557
|
-
|
|
541
|
+
}, keepAliveIntervalMs));
|
|
558
542
|
/** i have no idea why this exists. pls enlighten me */
|
|
559
|
-
const sendPassiveIq = (tag) =>
|
|
543
|
+
const sendPassiveIq = (tag) => query({
|
|
560
544
|
tag: 'iq',
|
|
561
545
|
attrs: {
|
|
562
|
-
to:
|
|
546
|
+
to: S_WHATSAPP_NET,
|
|
563
547
|
xmlns: 'passive',
|
|
564
|
-
type: 'set'
|
|
548
|
+
type: 'set'
|
|
565
549
|
},
|
|
566
|
-
content: [
|
|
567
|
-
|
|
568
|
-
]
|
|
569
|
-
}))
|
|
570
|
-
|
|
550
|
+
content: [{ tag, attrs: {} }]
|
|
551
|
+
});
|
|
571
552
|
/** logout & invalidate connection */
|
|
572
553
|
const logout = async (msg) => {
|
|
573
|
-
const jid = authState.creds.me?.id
|
|
574
|
-
|
|
554
|
+
const jid = authState.creds.me?.id;
|
|
575
555
|
if (jid) {
|
|
576
556
|
await sendNode({
|
|
577
557
|
tag: 'iq',
|
|
578
558
|
attrs: {
|
|
579
|
-
to:
|
|
559
|
+
to: S_WHATSAPP_NET,
|
|
580
560
|
type: 'set',
|
|
581
561
|
id: generateMessageTag(),
|
|
582
562
|
xmlns: 'md'
|
|
@@ -590,26 +570,25 @@ const makeSocket = (config) => {
|
|
|
590
570
|
}
|
|
591
571
|
}
|
|
592
572
|
]
|
|
593
|
-
})
|
|
573
|
+
});
|
|
594
574
|
}
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
575
|
+
end(new Boom(msg || 'Intentional Logout', { statusCode: DisconnectReason.loggedOut }));
|
|
576
|
+
};
|
|
577
|
+
const requestPairingCode = async (phoneNumber, customPairingCode) => {
|
|
578
|
+
const pairingCode = customPairingCode ?? bytesToCrockford(randomBytes(5));
|
|
579
|
+
if (customPairingCode && customPairingCode?.length !== 8) {
|
|
580
|
+
throw new Error('Custom pairing code must be exactly 8 chars');
|
|
581
|
+
}
|
|
582
|
+
authState.creds.pairingCode = pairingCode;
|
|
602
583
|
authState.creds.me = {
|
|
603
|
-
id:
|
|
584
|
+
id: jidEncode(phoneNumber, 's.whatsapp.net'),
|
|
604
585
|
name: '~'
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
ev.emit('creds.update', authState.creds)
|
|
608
|
-
|
|
586
|
+
};
|
|
587
|
+
ev.emit('creds.update', authState.creds);
|
|
609
588
|
await sendNode({
|
|
610
589
|
tag: 'iq',
|
|
611
590
|
attrs: {
|
|
612
|
-
to:
|
|
591
|
+
to: S_WHATSAPP_NET,
|
|
613
592
|
type: 'set',
|
|
614
593
|
id: generateMessageTag(),
|
|
615
594
|
xmlns: 'md'
|
|
@@ -620,7 +599,6 @@ const makeSocket = (config) => {
|
|
|
620
599
|
attrs: {
|
|
621
600
|
jid: authState.creds.me.id,
|
|
622
601
|
stage: 'companion_hello',
|
|
623
|
-
// eslint-disable-next-line camelcase
|
|
624
602
|
should_show_push_notification: 'true'
|
|
625
603
|
},
|
|
626
604
|
content: [
|
|
@@ -637,7 +615,7 @@ const makeSocket = (config) => {
|
|
|
637
615
|
{
|
|
638
616
|
tag: 'companion_platform_id',
|
|
639
617
|
attrs: {},
|
|
640
|
-
content:
|
|
618
|
+
content: getPlatformId(browser[1])
|
|
641
619
|
},
|
|
642
620
|
{
|
|
643
621
|
tag: 'companion_platform_display',
|
|
@@ -652,243 +630,199 @@ const makeSocket = (config) => {
|
|
|
652
630
|
]
|
|
653
631
|
}
|
|
654
632
|
]
|
|
655
|
-
})
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
}
|
|
659
|
-
|
|
633
|
+
});
|
|
634
|
+
return authState.creds.pairingCode;
|
|
635
|
+
};
|
|
660
636
|
async function generatePairingKey() {
|
|
661
|
-
const salt =
|
|
662
|
-
const randomIv =
|
|
663
|
-
const key = await
|
|
664
|
-
const ciphered =
|
|
665
|
-
|
|
666
|
-
return Buffer.concat([salt, randomIv, ciphered])
|
|
637
|
+
const salt = randomBytes(32);
|
|
638
|
+
const randomIv = randomBytes(16);
|
|
639
|
+
const key = await derivePairingCodeKey(authState.creds.pairingCode, salt);
|
|
640
|
+
const ciphered = aesEncryptCTR(authState.creds.pairingEphemeralKeyPair.public, key, randomIv);
|
|
641
|
+
return Buffer.concat([salt, randomIv, ciphered]);
|
|
667
642
|
}
|
|
668
|
-
|
|
669
643
|
const sendWAMBuffer = (wamBuffer) => {
|
|
670
644
|
return query({
|
|
671
645
|
tag: 'iq',
|
|
672
646
|
attrs: {
|
|
673
|
-
to:
|
|
647
|
+
to: S_WHATSAPP_NET,
|
|
674
648
|
id: generateMessageTag(),
|
|
675
649
|
xmlns: 'w:stats'
|
|
676
650
|
},
|
|
677
651
|
content: [
|
|
678
652
|
{
|
|
679
653
|
tag: 'add',
|
|
680
|
-
attrs: {},
|
|
654
|
+
attrs: { t: Math.round(Date.now() / 1000) + '' },
|
|
681
655
|
content: wamBuffer
|
|
682
656
|
}
|
|
683
657
|
]
|
|
684
|
-
})
|
|
685
|
-
}
|
|
686
|
-
|
|
687
|
-
ws.on('message', onMessageReceived)
|
|
688
|
-
|
|
658
|
+
});
|
|
659
|
+
};
|
|
660
|
+
ws.on('message', onMessageReceived);
|
|
689
661
|
ws.on('open', async () => {
|
|
690
662
|
try {
|
|
691
|
-
await validateConnection()
|
|
663
|
+
await validateConnection();
|
|
692
664
|
}
|
|
693
665
|
catch (err) {
|
|
694
|
-
logger.error({ err }, 'error in validating connection')
|
|
695
|
-
end(err)
|
|
696
|
-
}
|
|
697
|
-
})
|
|
698
|
-
|
|
699
|
-
ws.on('
|
|
700
|
-
|
|
701
|
-
ws.on('close', () => end(new boom_1.Boom('Connection Terminated', { statusCode: Types_1.DisconnectReason.connectionClosed })))
|
|
702
|
-
|
|
666
|
+
logger.error({ err }, 'error in validating connection');
|
|
667
|
+
end(err);
|
|
668
|
+
}
|
|
669
|
+
});
|
|
670
|
+
ws.on('error', mapWebSocketError(end));
|
|
671
|
+
ws.on('close', () => end(new Boom('Connection Terminated', { statusCode: DisconnectReason.connectionClosed })));
|
|
703
672
|
// the server terminated the connection
|
|
704
|
-
ws.on('CB:xmlstreamend', () => end(new
|
|
705
|
-
|
|
673
|
+
ws.on('CB:xmlstreamend', () => end(new Boom('Connection Terminated by Server', { statusCode: DisconnectReason.connectionClosed })));
|
|
706
674
|
// QR gen
|
|
707
675
|
ws.on('CB:iq,type:set,pair-device', async (stanza) => {
|
|
708
676
|
const iq = {
|
|
709
677
|
tag: 'iq',
|
|
710
678
|
attrs: {
|
|
711
|
-
to:
|
|
679
|
+
to: S_WHATSAPP_NET,
|
|
712
680
|
type: 'result',
|
|
713
|
-
id: stanza.attrs.id
|
|
681
|
+
id: stanza.attrs.id
|
|
714
682
|
}
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
const
|
|
720
|
-
const
|
|
721
|
-
const
|
|
722
|
-
|
|
723
|
-
const advB64 = creds.advSecretKey
|
|
724
|
-
|
|
725
|
-
let qrMs = qrTimeout || 60000 // time to let a QR live
|
|
726
|
-
|
|
683
|
+
};
|
|
684
|
+
await sendNode(iq);
|
|
685
|
+
const pairDeviceNode = getBinaryNodeChild(stanza, 'pair-device');
|
|
686
|
+
const refNodes = getBinaryNodeChildren(pairDeviceNode, 'ref');
|
|
687
|
+
const noiseKeyB64 = Buffer.from(creds.noiseKey.public).toString('base64');
|
|
688
|
+
const identityKeyB64 = Buffer.from(creds.signedIdentityKey.public).toString('base64');
|
|
689
|
+
const advB64 = creds.advSecretKey;
|
|
690
|
+
let qrMs = qrTimeout || 60000; // time to let a QR live
|
|
727
691
|
const genPairQR = () => {
|
|
728
692
|
if (!ws.isOpen) {
|
|
729
|
-
return
|
|
693
|
+
return;
|
|
730
694
|
}
|
|
731
|
-
|
|
732
|
-
const refNode = refNodes.shift()
|
|
733
|
-
|
|
695
|
+
const refNode = refNodes.shift();
|
|
734
696
|
if (!refNode) {
|
|
735
|
-
end(new
|
|
736
|
-
return
|
|
697
|
+
end(new Boom('QR refs attempts ended', { statusCode: DisconnectReason.timedOut }));
|
|
698
|
+
return;
|
|
737
699
|
}
|
|
738
|
-
|
|
739
|
-
const
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
genPairQR()
|
|
748
|
-
})
|
|
749
|
-
|
|
700
|
+
const ref = refNode.content.toString('utf-8');
|
|
701
|
+
const qr = [ref, noiseKeyB64, identityKeyB64, advB64].join(',');
|
|
702
|
+
ev.emit('connection.update', { qr });
|
|
703
|
+
qrTimer = setTimeout(genPairQR, qrMs);
|
|
704
|
+
qrMs = qrTimeout || 20000; // shorter subsequent qrs
|
|
705
|
+
};
|
|
706
|
+
genPairQR();
|
|
707
|
+
});
|
|
750
708
|
// device paired for the first time
|
|
751
709
|
// if device pairs successfully, the server asks to restart the connection
|
|
752
710
|
ws.on('CB:iq,,pair-success', async (stanza) => {
|
|
753
|
-
logger.debug('pair success recv')
|
|
711
|
+
logger.debug('pair success recv');
|
|
754
712
|
try {
|
|
755
|
-
const { reply, creds: updatedCreds } =
|
|
756
|
-
logger.info({ me: updatedCreds.me, platform: updatedCreds.platform }, 'pairing configured successfully, expect to restart the connection...')
|
|
757
|
-
|
|
758
|
-
ev.emit('
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
await sendNode(reply)
|
|
762
|
-
}
|
|
763
|
-
|
|
713
|
+
const { reply, creds: updatedCreds } = configureSuccessfulPairing(stanza, creds);
|
|
714
|
+
logger.info({ me: updatedCreds.me, platform: updatedCreds.platform }, 'pairing configured successfully, expect to restart the connection...');
|
|
715
|
+
ev.emit('creds.update', updatedCreds);
|
|
716
|
+
ev.emit('connection.update', { isNewLogin: true, qr: undefined });
|
|
717
|
+
await sendNode(reply);
|
|
718
|
+
}
|
|
764
719
|
catch (error) {
|
|
765
|
-
logger.info({ trace: error.stack }, 'error in pairing')
|
|
766
|
-
end(error)
|
|
720
|
+
logger.info({ trace: error.stack }, 'error in pairing');
|
|
721
|
+
end(error);
|
|
767
722
|
}
|
|
768
|
-
})
|
|
769
|
-
|
|
723
|
+
});
|
|
770
724
|
// login complete
|
|
771
725
|
ws.on('CB:success', async (node) => {
|
|
772
726
|
try {
|
|
773
|
-
await uploadPreKeysToServerIfRequired()
|
|
774
|
-
await sendPassiveIq('active')
|
|
727
|
+
await uploadPreKeysToServerIfRequired();
|
|
728
|
+
await sendPassiveIq('active');
|
|
775
729
|
}
|
|
776
730
|
catch (err) {
|
|
777
731
|
logger.warn({ err }, 'failed to send initial passive iq');
|
|
778
732
|
}
|
|
779
|
-
logger.info('opened connection to WA')
|
|
733
|
+
logger.info('opened connection to WA');
|
|
780
734
|
clearTimeout(qrTimer); // will never happen in all likelyhood -- but just in case WA sends success on first try
|
|
781
|
-
ev.emit('creds.update', { me: { ...authState.creds.me, lid: node.attrs.lid } })
|
|
782
|
-
ev.emit('connection.update', { connection: 'open' })
|
|
735
|
+
ev.emit('creds.update', { me: { ...authState.creds.me, lid: node.attrs.lid } });
|
|
736
|
+
ev.emit('connection.update', { connection: 'open' });
|
|
783
737
|
if (node.attrs.lid && authState.creds.me?.id) {
|
|
784
|
-
const myLID = node.attrs.lid
|
|
738
|
+
const myLID = node.attrs.lid;
|
|
785
739
|
process.nextTick(async () => {
|
|
786
740
|
try {
|
|
787
|
-
const myPN = authState.creds.me.id
|
|
788
|
-
|
|
741
|
+
const myPN = authState.creds.me.id;
|
|
789
742
|
// Store our own LID-PN mapping
|
|
790
|
-
await signalRepository.lidMapping.storeLIDPNMappings([{ lid: myLID, pn: myPN }])
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
await
|
|
794
|
-
|
|
743
|
+
await signalRepository.lidMapping.storeLIDPNMappings([{ lid: myLID, pn: myPN }]);
|
|
744
|
+
// Create device list for our own user (needed for bulk migration)
|
|
745
|
+
const { user, device } = jidDecode(myPN);
|
|
746
|
+
await authState.keys.set({
|
|
747
|
+
'device-list': {
|
|
748
|
+
[user]: [device?.toString() || '0']
|
|
749
|
+
}
|
|
750
|
+
});
|
|
751
|
+
// migrate our own session
|
|
752
|
+
await signalRepository.migrateSession(myPN, myLID);
|
|
753
|
+
logger.info({ myPN, myLID }, 'Own LID session created successfully');
|
|
795
754
|
}
|
|
796
755
|
catch (error) {
|
|
797
|
-
logger.error({ error, lid: myLID }, 'Failed to create own LID session')
|
|
756
|
+
logger.error({ error, lid: myLID }, 'Failed to create own LID session');
|
|
798
757
|
}
|
|
799
|
-
})
|
|
758
|
+
});
|
|
800
759
|
}
|
|
801
|
-
})
|
|
802
|
-
|
|
760
|
+
});
|
|
803
761
|
ws.on('CB:stream:error', (node) => {
|
|
804
|
-
logger.error({ node }, 'stream errored out')
|
|
805
|
-
const { reason, statusCode } =
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
})
|
|
809
|
-
|
|
762
|
+
logger.error({ node }, 'stream errored out');
|
|
763
|
+
const { reason, statusCode } = getErrorCodeFromStreamError(node);
|
|
764
|
+
end(new Boom(`Stream Errored (${reason})`, { statusCode, data: node }));
|
|
765
|
+
});
|
|
810
766
|
// stream fail, possible logout
|
|
811
767
|
ws.on('CB:failure', (node) => {
|
|
812
|
-
const reason = +(node.attrs.reason || 500)
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
})
|
|
816
|
-
|
|
768
|
+
const reason = +(node.attrs.reason || 500);
|
|
769
|
+
end(new Boom('Connection Failure', { statusCode: reason, data: node.attrs }));
|
|
770
|
+
});
|
|
817
771
|
ws.on('CB:ib,,downgrade_webclient', () => {
|
|
818
|
-
end(new
|
|
819
|
-
})
|
|
820
|
-
|
|
772
|
+
end(new Boom('Multi-device beta not joined', { statusCode: DisconnectReason.multideviceMismatch }));
|
|
773
|
+
});
|
|
821
774
|
ws.on('CB:ib,,offline_preview', (node) => {
|
|
822
|
-
logger.info('offline preview received', JSON.stringify(node))
|
|
823
|
-
|
|
775
|
+
logger.info('offline preview received', JSON.stringify(node));
|
|
824
776
|
sendNode({
|
|
825
777
|
tag: 'ib',
|
|
826
778
|
attrs: {},
|
|
827
779
|
content: [{ tag: 'offline_batch', attrs: { count: '100' } }]
|
|
828
|
-
})
|
|
829
|
-
})
|
|
830
|
-
|
|
780
|
+
});
|
|
781
|
+
});
|
|
831
782
|
ws.on('CB:ib,,edge_routing', (node) => {
|
|
832
|
-
const edgeRoutingNode =
|
|
833
|
-
const routingInfo =
|
|
834
|
-
|
|
783
|
+
const edgeRoutingNode = getBinaryNodeChild(node, 'edge_routing');
|
|
784
|
+
const routingInfo = getBinaryNodeChild(edgeRoutingNode, 'routing_info');
|
|
835
785
|
if (routingInfo?.content) {
|
|
836
|
-
authState.creds.routingInfo = Buffer.from(routingInfo?.content)
|
|
837
|
-
ev.emit('creds.update', authState.creds)
|
|
786
|
+
authState.creds.routingInfo = Buffer.from(routingInfo?.content);
|
|
787
|
+
ev.emit('creds.update', authState.creds);
|
|
838
788
|
}
|
|
839
|
-
})
|
|
840
|
-
|
|
841
|
-
let didStartBuffer = false
|
|
842
|
-
|
|
789
|
+
});
|
|
790
|
+
let didStartBuffer = false;
|
|
843
791
|
process.nextTick(() => {
|
|
844
792
|
if (creds.me?.id) {
|
|
845
793
|
// start buffering important events
|
|
846
794
|
// if we're logged in
|
|
847
|
-
ev.buffer()
|
|
848
|
-
didStartBuffer = true
|
|
795
|
+
ev.buffer();
|
|
796
|
+
didStartBuffer = true;
|
|
849
797
|
}
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
})
|
|
853
|
-
|
|
798
|
+
ev.emit('connection.update', { connection: 'connecting', receivedPendingNotifications: false, qr: undefined });
|
|
799
|
+
});
|
|
854
800
|
// called when all offline notifs are handled
|
|
855
801
|
ws.on('CB:ib,,offline', (node) => {
|
|
856
|
-
const child =
|
|
857
|
-
const offlineNotifs = +(child?.attrs.count || 0)
|
|
858
|
-
|
|
859
|
-
logger.info(`handled ${offlineNotifs} offline messages/notifications`)
|
|
860
|
-
|
|
802
|
+
const child = getBinaryNodeChild(node, 'offline');
|
|
803
|
+
const offlineNotifs = +(child?.attrs.count || 0);
|
|
804
|
+
logger.info(`handled ${offlineNotifs} offline messages/notifications`);
|
|
861
805
|
if (didStartBuffer) {
|
|
862
|
-
ev.flush()
|
|
863
|
-
logger.trace('flushed events for initial buffer')
|
|
806
|
+
ev.flush();
|
|
807
|
+
logger.trace('flushed events for initial buffer');
|
|
864
808
|
}
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
})
|
|
868
|
-
|
|
809
|
+
ev.emit('connection.update', { receivedPendingNotifications: true });
|
|
810
|
+
});
|
|
869
811
|
// update credentials when required
|
|
870
812
|
ev.on('creds.update', update => {
|
|
871
|
-
const name = update.me?.name
|
|
872
|
-
|
|
813
|
+
const name = update.me?.name;
|
|
873
814
|
// if name has just been received
|
|
874
815
|
if (creds.me?.name !== name) {
|
|
875
|
-
logger.debug({ name }, 'updated pushName')
|
|
876
|
-
|
|
816
|
+
logger.debug({ name }, 'updated pushName');
|
|
877
817
|
sendNode({
|
|
878
818
|
tag: 'presence',
|
|
879
|
-
attrs: { name }
|
|
819
|
+
attrs: { name: name }
|
|
880
820
|
}).catch(err => {
|
|
881
|
-
logger.warn({ trace: err.stack }, 'error in sending presence update on name change')
|
|
882
|
-
})
|
|
883
|
-
}
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
})
|
|
887
|
-
|
|
888
|
-
if (printQRInTerminal) {
|
|
889
|
-
Utils_1.printQRIfNecessaryListener(ev, logger)
|
|
890
|
-
}
|
|
891
|
-
|
|
821
|
+
logger.warn({ trace: err.stack }, 'error in sending presence update on name change');
|
|
822
|
+
});
|
|
823
|
+
}
|
|
824
|
+
Object.assign(creds, update);
|
|
825
|
+
});
|
|
892
826
|
return {
|
|
893
827
|
type: 'md',
|
|
894
828
|
ws,
|
|
@@ -896,7 +830,7 @@ const makeSocket = (config) => {
|
|
|
896
830
|
authState: { creds, keys },
|
|
897
831
|
signalRepository,
|
|
898
832
|
get user() {
|
|
899
|
-
return authState.creds.me
|
|
833
|
+
return authState.creds.me;
|
|
900
834
|
},
|
|
901
835
|
generateMessageTag,
|
|
902
836
|
query,
|
|
@@ -910,25 +844,21 @@ const makeSocket = (config) => {
|
|
|
910
844
|
uploadPreKeys,
|
|
911
845
|
uploadPreKeysToServerIfRequired,
|
|
912
846
|
requestPairingCode,
|
|
847
|
+
wamBuffer: publicWAMBuffer,
|
|
913
848
|
/** Waits for the connection to WA to reach a state */
|
|
914
|
-
waitForConnectionUpdate:
|
|
849
|
+
waitForConnectionUpdate: bindWaitForConnectionUpdate(ev),
|
|
915
850
|
sendWAMBuffer,
|
|
916
|
-
executeUSyncQuery,
|
|
917
|
-
onWhatsApp
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
}
|
|
921
|
-
|
|
851
|
+
executeUSyncQuery,
|
|
852
|
+
onWhatsApp
|
|
853
|
+
};
|
|
854
|
+
};
|
|
922
855
|
/**
|
|
923
856
|
* map the websocket error to the right type
|
|
924
857
|
* so it can be retried by the caller
|
|
925
858
|
* */
|
|
926
859
|
function mapWebSocketError(handler) {
|
|
927
860
|
return (error) => {
|
|
928
|
-
handler(new
|
|
929
|
-
}
|
|
861
|
+
handler(new Boom(`WebSocket Error (${error?.message})`, { statusCode: getCodeFromWSError(error), data: error }));
|
|
862
|
+
};
|
|
930
863
|
}
|
|
931
|
-
|
|
932
|
-
module.exports = {
|
|
933
|
-
makeSocket
|
|
934
|
-
}
|
|
864
|
+
//# sourceMappingURL=socket.js.map
|