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