lordceaser-baileys 2.0.37 → 2.0.39
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 +1 -1
- package/README.md +660 -1073
- package/WAProto/GenerateStatics.sh +4 -3
- package/WAProto/WAProto.proto +359 -2494
- package/WAProto/index.d.ts +31460 -8461
- package/WAProto/index.js +96236 -92883
- package/WASignalGroup/GroupProtocol.js +1697 -0
- package/WASignalGroup/ciphertext_message.js +16 -0
- package/WASignalGroup/group_cipher.js +120 -0
- package/WASignalGroup/group_session_builder.js +46 -0
- package/WASignalGroup/index.js +5 -0
- package/WASignalGroup/keyhelper.js +21 -0
- package/WASignalGroup/protobufs.js +3 -0
- package/WASignalGroup/queue_job.js +69 -0
- package/WASignalGroup/sender_chain_key.js +50 -0
- package/WASignalGroup/sender_key_distribution_message.js +78 -0
- package/WASignalGroup/sender_key_message.js +92 -0
- package/WASignalGroup/sender_key_name.js +70 -0
- package/WASignalGroup/sender_key_record.js +56 -0
- package/WASignalGroup/sender_key_state.js +129 -0
- package/{lib/Signal/Group/sender-message-key.js → WASignalGroup/sender_message_key.js} +16 -3
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/index.d.ts +245 -37
- package/lib/Defaults/index.js +74 -82
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Signal/libsignal.d.ts +3 -5
- package/lib/Signal/libsignal.js +80 -359
- package/lib/Socket/Client/{types.d.ts → abstract-socket-client.d.ts} +5 -4
- package/lib/Socket/Client/abstract-socket-client.js +13 -0
- package/lib/Socket/Client/index.d.ts +3 -3
- package/lib/Socket/Client/index.js +19 -3
- package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
- package/lib/Socket/Client/mobile-socket-client.js +65 -0
- package/lib/Socket/Client/{websocket.d.ts → web-socket-client.d.ts} +2 -3
- package/lib/Socket/Client/web-socket-client.js +62 -0
- package/lib/Socket/business.d.ts +87 -156
- package/lib/Socket/business.js +43 -162
- package/lib/Socket/chats.d.ts +40 -82
- package/lib/Socket/chats.js +284 -603
- package/lib/Socket/groups.d.ts +58 -96
- package/lib/Socket/groups.js +82 -115
- package/lib/Socket/index.d.ts +94 -204
- package/lib/Socket/index.js +9 -11
- package/lib/Socket/messages-recv.d.ts +77 -145
- package/lib/Socket/messages-recv.js +400 -1305
- package/lib/Socket/messages-send.d.ts +70 -141
- package/lib/Socket/messages-send.js +249 -717
- package/lib/Socket/registration.d.ts +242 -0
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.d.ts +18 -34
- package/lib/Socket/socket.js +206 -557
- package/lib/Store/index.d.ts +3 -0
- package/lib/Store/index.js +10 -0
- package/lib/Store/make-cache-manager-store.d.ts +14 -0
- package/lib/Store/make-cache-manager-store.js +83 -0
- package/lib/Store/make-in-memory-store.d.ts +118 -0
- package/lib/Store/make-in-memory-store.js +422 -0
- package/lib/Store/make-ordered-dictionary.d.ts +13 -0
- package/lib/Store/make-ordered-dictionary.js +81 -0
- package/lib/Store/object-repository.d.ts +10 -0
- package/lib/Store/object-repository.js +27 -0
- package/lib/Types/Auth.d.ts +12 -19
- package/lib/Types/Auth.js +2 -2
- package/lib/Types/Call.d.ts +1 -3
- package/lib/Types/Call.js +2 -2
- package/lib/Types/Chat.d.ts +14 -31
- package/lib/Types/Chat.js +4 -8
- package/lib/Types/Contact.d.ts +1 -8
- package/lib/Types/Contact.js +2 -2
- package/lib/Types/Events.d.ts +17 -101
- package/lib/Types/Events.js +2 -2
- package/lib/Types/GroupMetadata.d.ts +3 -18
- package/lib/Types/GroupMetadata.js +2 -2
- package/lib/Types/Label.d.ts +0 -1
- package/lib/Types/Label.js +5 -3
- package/lib/Types/LabelAssociation.d.ts +0 -1
- package/lib/Types/LabelAssociation.js +5 -3
- package/lib/Types/Message.d.ts +29 -81
- package/lib/Types/Message.js +9 -11
- package/lib/Types/Product.d.ts +1 -2
- package/lib/Types/Product.js +2 -2
- package/lib/Types/Signal.d.ts +2 -32
- package/lib/Types/Signal.js +2 -2
- package/lib/Types/Socket.d.ts +26 -46
- package/lib/Types/Socket.js +2 -3
- package/lib/Types/State.d.ts +2 -72
- package/lib/Types/State.js +2 -56
- package/lib/Types/index.d.ts +13 -16
- package/lib/Types/index.js +30 -15
- package/lib/Utils/auth-utils.d.ts +6 -12
- package/lib/Utils/auth-utils.js +143 -239
- package/lib/Utils/baileys-event-stream.d.ts +16 -0
- package/lib/Utils/baileys-event-stream.js +63 -0
- package/lib/Utils/business.d.ts +2 -3
- package/lib/Utils/business.js +69 -66
- package/lib/Utils/chat-utils.d.ts +23 -52
- package/lib/Utils/chat-utils.js +248 -380
- package/lib/Utils/crypto.d.ts +21 -17
- package/lib/Utils/crypto.js +92 -57
- package/lib/Utils/decode-wa-message.d.ts +8 -54
- package/lib/Utils/decode-wa-message.js +57 -186
- package/lib/Utils/event-buffer.d.ts +8 -9
- package/lib/Utils/event-buffer.js +76 -178
- package/lib/Utils/generics.d.ts +23 -26
- package/lib/Utils/generics.js +166 -165
- package/lib/Utils/history.d.ts +11 -16
- package/lib/Utils/history.js +53 -93
- package/lib/Utils/index.d.ts +17 -22
- package/lib/Utils/index.js +33 -22
- package/lib/Utils/link-preview.d.ts +5 -5
- package/lib/Utils/link-preview.js +24 -16
- package/lib/Utils/logger.d.ts +3 -11
- package/lib/Utils/logger.js +7 -3
- package/lib/Utils/lt-hash.d.ts +12 -8
- package/lib/Utils/lt-hash.js +46 -3
- package/lib/Utils/make-mutex.d.ts +2 -4
- package/lib/Utils/make-mutex.js +34 -24
- package/lib/Utils/messages-media.d.ts +35 -61
- package/lib/Utils/messages-media.js +301 -415
- package/lib/Utils/messages.d.ts +18 -32
- package/lib/Utils/messages.js +261 -396
- package/lib/Utils/noise-handler.d.ts +13 -12
- package/lib/Utils/noise-handler.js +98 -144
- package/lib/Utils/process-message.d.ts +12 -30
- package/lib/Utils/process-message.js +163 -439
- package/lib/Utils/signal.d.ts +5 -20
- package/lib/Utils/signal.js +74 -114
- package/lib/Utils/use-multi-file-auth-state.d.ts +1 -2
- package/lib/Utils/use-multi-file-auth-state.js +33 -61
- package/lib/Utils/validate-connection.d.ts +6 -6
- package/lib/Utils/validate-connection.js +114 -119
- package/lib/WABinary/constants.d.ts +4 -5
- package/lib/WABinary/constants.js +20 -1281
- package/lib/WABinary/decode.d.ts +4 -4
- package/lib/WABinary/decode.js +43 -51
- package/lib/WABinary/encode.d.ts +3 -3
- package/lib/WABinary/encode.js +44 -32
- package/lib/WABinary/generic-utils.d.ts +6 -6
- package/lib/WABinary/generic-utils.js +43 -46
- package/lib/WABinary/index.d.ts +5 -6
- package/lib/WABinary/index.js +21 -6
- package/lib/WABinary/jid-utils.d.ts +6 -23
- package/lib/WABinary/jid-utils.js +39 -73
- package/lib/WABinary/types.d.ts +1 -2
- package/lib/WABinary/types.js +2 -2
- package/lib/WAM/BinaryInfo.d.ts +11 -3
- package/lib/WAM/BinaryInfo.js +5 -2
- package/lib/WAM/constants.d.ts +3 -5
- package/lib/WAM/constants.js +11958 -19461
- package/lib/WAM/encode.d.ts +3 -3
- package/lib/WAM/encode.js +22 -17
- package/lib/WAM/index.d.ts +3 -4
- package/lib/WAM/index.js +19 -4
- package/lib/index.d.ts +8 -9
- package/lib/index.js +30 -11
- package/package.json +2 -2
- package/WAProto/WAProto/GenerateStatics.sh +0 -3
- package/WAProto/WAProto/WAProto.proto +0 -5479
- package/WAProto/WAProto/fix-imports.js +0 -85
- package/WAProto/WAProto/index.d.ts +0 -14017
- package/WAProto/WAProto/index.js +0 -97691
- package/WAProto/fix-imports.js +0 -85
- 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 -277
- 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 +0 -11
- 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 +0 -54
- package/lib/Socket/Client/websocket.js.map +0 -1
- package/lib/Socket/business.d.ts.map +0 -1
- package/lib/Socket/business.js.map +0 -1
- package/lib/Socket/chats.d.ts.map +0 -1
- package/lib/Socket/chats.js.map +0 -1
- package/lib/Socket/communities.d.ts +0 -273
- package/lib/Socket/communities.d.ts.map +0 -1
- package/lib/Socket/communities.js +0 -431
- 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 +0 -3
- package/lib/Socket/mex.d.ts.map +0 -1
- package/lib/Socket/mex.js +0 -42
- package/lib/Socket/mex.js.map +0 -1
- package/lib/Socket/newsletter.d.ts +0 -170
- package/lib/Socket/newsletter.d.ts.map +0 -1
- package/lib/Socket/newsletter.js +0 -181
- 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/Mex.d.ts +0 -141
- package/lib/Types/Mex.d.ts.map +0 -1
- package/lib/Types/Mex.js +0 -37
- package/lib/Types/Mex.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 +0 -26
- package/lib/Types/USync.d.ts.map +0 -1
- package/lib/Types/USync.js +0 -2
- 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/browser-utils.d.ts +0 -4
- package/lib/Utils/browser-utils.d.ts.map +0 -1
- package/lib/Utils/browser-utils.js +0 -29
- 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/companion-reg-client-utils.d.ts +0 -17
- package/lib/Utils/companion-reg-client-utils.d.ts.map +0 -1
- package/lib/Utils/companion-reg-client-utils.js +0 -35
- package/lib/Utils/companion-reg-client-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/identity-change-handler.d.ts +0 -44
- package/lib/Utils/identity-change-handler.d.ts.map +0 -1
- package/lib/Utils/identity-change-handler.js +0 -50
- package/lib/Utils/identity-change-handler.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 +0 -115
- package/lib/Utils/message-retry-manager.d.ts.map +0 -1
- package/lib/Utils/message-retry-manager.js +0 -265
- 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/offline-node-processor.d.ts +0 -17
- package/lib/Utils/offline-node-processor.d.ts.map +0 -1
- package/lib/Utils/offline-node-processor.js +0 -40
- package/lib/Utils/offline-node-processor.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/reporting-utils.d.ts +0 -11
- package/lib/Utils/reporting-utils.d.ts.map +0 -1
- package/lib/Utils/reporting-utils.js +0 -258
- package/lib/Utils/reporting-utils.js.map +0 -1
- package/lib/Utils/signal.d.ts.map +0 -1
- package/lib/Utils/signal.js.map +0 -1
- package/lib/Utils/stanza-ack.d.ts +0 -11
- package/lib/Utils/stanza-ack.d.ts.map +0 -1
- package/lib/Utils/stanza-ack.js +0 -38
- package/lib/Utils/stanza-ack.js.map +0 -1
- package/lib/Utils/sync-action-utils.d.ts +0 -19
- package/lib/Utils/sync-action-utils.d.ts.map +0 -1
- package/lib/Utils/sync-action-utils.js +0 -49
- package/lib/Utils/sync-action-utils.js.map +0 -1
- package/lib/Utils/tc-token-utils.d.ts +0 -37
- package/lib/Utils/tc-token-utils.d.ts.map +0 -1
- package/lib/Utils/tc-token-utils.js +0 -164
- package/lib/Utils/tc-token-utils.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 +0 -10
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +0 -52
- package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -23
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +0 -54
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -13
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +0 -27
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -13
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +0 -38
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +0 -10
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +0 -25
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.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 +0 -6
- package/lib/WAUSync/Protocols/index.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/index.js +0 -6
- package/lib/WAUSync/Protocols/index.js.map +0 -1
- package/lib/WAUSync/USyncQuery.d.ts +0 -30
- package/lib/WAUSync/USyncQuery.d.ts.map +0 -1
- package/lib/WAUSync/USyncQuery.js +0 -98
- package/lib/WAUSync/USyncQuery.js.map +0 -1
- package/lib/WAUSync/USyncUser.d.ts +0 -17
- package/lib/WAUSync/USyncUser.d.ts.map +0 -1
- package/lib/WAUSync/USyncUser.js +0 -31
- package/lib/WAUSync/USyncUser.js.map +0 -1
- package/lib/WAUSync/index.d.ts +0 -4
- package/lib/WAUSync/index.d.ts.map +0 -1
- package/lib/WAUSync/index.js +0 -4
- 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,66 +1,65 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
import { executeWMexQuery } from './mex.js';
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeSocket = void 0;
|
|
4
|
+
const boom_1 = require("@hapi/boom");
|
|
5
|
+
const crypto_1 = require("crypto");
|
|
6
|
+
const url_1 = require("url");
|
|
7
|
+
const util_1 = require("util");
|
|
8
|
+
const WAProto_1 = require("../../WAProto");
|
|
9
|
+
const Defaults_1 = require("../Defaults");
|
|
10
|
+
const Types_1 = require("../Types");
|
|
11
|
+
const Utils_1 = require("../Utils");
|
|
12
|
+
const WABinary_1 = require("../WABinary");
|
|
13
|
+
const Client_1 = require("./Client");
|
|
15
14
|
/**
|
|
16
15
|
* Connects to WA servers and performs:
|
|
17
16
|
* - simple queries (no retry mechanism, wait for connection establishment)
|
|
18
17
|
* - listen to messages and emit events
|
|
19
18
|
* - query phone connection
|
|
20
19
|
*/
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
let
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
logger.warn({}, '⚠️ The printQRInTerminal option has been deprecated. You will no longer receive QR codes in the terminal automatically. Please listen to the connection.update event yourself and handle the QR your way. You can remove this message by removing this opttion. This message will be removed in a future version.');
|
|
29
|
-
}
|
|
30
|
-
if (browser[1].toLocaleLowerCase().includes('android')) {
|
|
31
|
-
logger.warn('⚠️ Using the Android browser is experimental and may lead to unexpected behavior. Use at your own risk.');
|
|
32
|
-
}
|
|
33
|
-
const syncDisabled = PROCESSABLE_HISTORY_TYPES.map(syncType => config.shouldSyncHistoryMessage({ syncType })).filter(x => x === false)
|
|
34
|
-
.length === PROCESSABLE_HISTORY_TYPES.length;
|
|
35
|
-
if (syncDisabled) {
|
|
36
|
-
logger.warn('⚠️ DANGER: DISABLING ALL SYNC BY shouldSyncHistoryMsg PREVENTS BAILEYS FROM ACCESSING INITIAL LID MAPPINGS, LEADING TO INSTABILIY AND SESSION ERRORS');
|
|
20
|
+
const makeSocket = (config) => {
|
|
21
|
+
var _a, _b;
|
|
22
|
+
const { waWebSocketUrl, connectTimeoutMs, logger, keepAliveIntervalMs, browser, auth: authState, printQRInTerminal, defaultQueryTimeoutMs, transactionOpts, qrTimeout, makeSignalRepository, } = config;
|
|
23
|
+
let url = typeof waWebSocketUrl === 'string' ? new url_1.URL(waWebSocketUrl) : waWebSocketUrl;
|
|
24
|
+
config.mobile = config.mobile || url.protocol === 'tcp:';
|
|
25
|
+
if (config.mobile && url.protocol !== 'tcp:') {
|
|
26
|
+
url = new url_1.URL(`tcp://${Defaults_1.MOBILE_ENDPOINT}:${Defaults_1.MOBILE_PORT}`);
|
|
37
27
|
}
|
|
38
|
-
|
|
39
|
-
if (config.mobile || url.protocol === 'tcp:') {
|
|
40
|
-
throw new Boom('Mobile API is not supported anymore', { statusCode: DisconnectReason.loggedOut });
|
|
41
|
-
}
|
|
42
|
-
if (url.protocol === 'wss' && authState?.creds?.routingInfo) {
|
|
28
|
+
if (!config.mobile && url.protocol === 'wss' && ((_a = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _a === void 0 ? void 0 : _a.routingInfo)) {
|
|
43
29
|
url.searchParams.append('ED', authState.creds.routingInfo.toString('base64url'));
|
|
44
30
|
}
|
|
31
|
+
const ws = config.socket ? config.socket : config.mobile ? new Client_1.MobileSocketClient(url, config) : new Client_1.WebSocketClient(url, config);
|
|
32
|
+
ws.connect();
|
|
33
|
+
const ev = (0, Utils_1.makeEventBuffer)(logger);
|
|
45
34
|
/** ephemeral key pair used to encrypt/decrypt communication. Unique for each connection */
|
|
46
|
-
const ephemeralKeyPair = Curve.generateKeyPair();
|
|
35
|
+
const ephemeralKeyPair = Utils_1.Curve.generateKeyPair();
|
|
47
36
|
/** WA noise protocol wrapper */
|
|
48
|
-
const noise = makeNoiseHandler({
|
|
37
|
+
const noise = (0, Utils_1.makeNoiseHandler)({
|
|
49
38
|
keyPair: ephemeralKeyPair,
|
|
50
|
-
NOISE_HEADER: NOISE_WA_HEADER,
|
|
39
|
+
NOISE_HEADER: config.mobile ? Defaults_1.MOBILE_NOISE_HEADER : Defaults_1.NOISE_WA_HEADER,
|
|
40
|
+
mobile: config.mobile,
|
|
51
41
|
logger,
|
|
52
|
-
routingInfo: authState
|
|
42
|
+
routingInfo: (_b = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _b === void 0 ? void 0 : _b.routingInfo
|
|
53
43
|
});
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
const
|
|
44
|
+
const { creds } = authState;
|
|
45
|
+
// add transaction capability
|
|
46
|
+
const keys = (0, Utils_1.addTransactionCapability)(authState.keys, logger, transactionOpts);
|
|
47
|
+
const signalRepository = makeSignalRepository({ creds, keys });
|
|
48
|
+
let lastDateRecv;
|
|
49
|
+
let epoch = 1;
|
|
50
|
+
let keepAliveReq;
|
|
51
|
+
let qrTimer;
|
|
52
|
+
let closed = false;
|
|
53
|
+
const uqTagId = (0, Utils_1.generateMdTagPrefix)();
|
|
54
|
+
const generateMessageTag = () => `${uqTagId}${epoch++}`;
|
|
55
|
+
const sendPromise = (0, util_1.promisify)(ws.send);
|
|
57
56
|
/** send a raw buffer */
|
|
58
57
|
const sendRawMessage = async (data) => {
|
|
59
58
|
if (!ws.isOpen) {
|
|
60
|
-
throw new Boom('Connection Closed', { statusCode: DisconnectReason.connectionClosed });
|
|
59
|
+
throw new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed });
|
|
61
60
|
}
|
|
62
61
|
const bytes = noise.encodeFrame(data);
|
|
63
|
-
await promiseTimeout(connectTimeoutMs, async (resolve, reject) => {
|
|
62
|
+
await (0, Utils_1.promiseTimeout)(connectTimeoutMs, async (resolve, reject) => {
|
|
64
63
|
try {
|
|
65
64
|
await sendPromise.call(ws, bytes);
|
|
66
65
|
resolve();
|
|
@@ -73,11 +72,41 @@ export const makeSocket = (config) => {
|
|
|
73
72
|
/** send a binary node */
|
|
74
73
|
const sendNode = (frame) => {
|
|
75
74
|
if (logger.level === 'trace') {
|
|
76
|
-
logger.trace({ xml: binaryNodeToString(frame), msg: 'xml send' });
|
|
75
|
+
logger.trace({ xml: (0, WABinary_1.binaryNodeToString)(frame), msg: 'xml send' });
|
|
77
76
|
}
|
|
78
|
-
const buff = encodeBinaryNode(frame);
|
|
77
|
+
const buff = (0, WABinary_1.encodeBinaryNode)(frame);
|
|
79
78
|
return sendRawMessage(buff);
|
|
80
79
|
};
|
|
80
|
+
/** log & process any unexpected errors */
|
|
81
|
+
const onUnexpectedError = (err, msg) => {
|
|
82
|
+
logger.error({ err }, `unexpected error in '${msg}'`);
|
|
83
|
+
};
|
|
84
|
+
/** await the next incoming message */
|
|
85
|
+
const awaitNextMessage = async (sendMsg) => {
|
|
86
|
+
if (!ws.isOpen) {
|
|
87
|
+
throw new boom_1.Boom('Connection Closed', {
|
|
88
|
+
statusCode: Types_1.DisconnectReason.connectionClosed
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
let onOpen;
|
|
92
|
+
let onClose;
|
|
93
|
+
const result = (0, Utils_1.promiseTimeout)(connectTimeoutMs, (resolve, reject) => {
|
|
94
|
+
onOpen = resolve;
|
|
95
|
+
onClose = mapWebSocketError(reject);
|
|
96
|
+
ws.on('frame', onOpen);
|
|
97
|
+
ws.on('close', onClose);
|
|
98
|
+
ws.on('error', onClose);
|
|
99
|
+
})
|
|
100
|
+
.finally(() => {
|
|
101
|
+
ws.off('frame', onOpen);
|
|
102
|
+
ws.off('close', onClose);
|
|
103
|
+
ws.off('error', onClose);
|
|
104
|
+
});
|
|
105
|
+
if (sendMsg) {
|
|
106
|
+
sendRawMessage(sendMsg).catch(onClose);
|
|
107
|
+
}
|
|
108
|
+
return result;
|
|
109
|
+
};
|
|
81
110
|
/**
|
|
82
111
|
* Wait for a message with a certain tag to be received
|
|
83
112
|
* @param msgId the message tag to await
|
|
@@ -87,38 +116,20 @@ export const makeSocket = (config) => {
|
|
|
87
116
|
let onRecv;
|
|
88
117
|
let onErr;
|
|
89
118
|
try {
|
|
90
|
-
|
|
91
|
-
onRecv =
|
|
92
|
-
resolve(data);
|
|
93
|
-
};
|
|
119
|
+
return await (0, Utils_1.promiseTimeout)(timeoutMs, (resolve, reject) => {
|
|
120
|
+
onRecv = resolve;
|
|
94
121
|
onErr = err => {
|
|
95
|
-
reject(err ||
|
|
96
|
-
new Boom('Connection Closed', {
|
|
97
|
-
statusCode: DisconnectReason.connectionClosed
|
|
98
|
-
}));
|
|
122
|
+
reject(err || new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed }));
|
|
99
123
|
};
|
|
100
124
|
ws.on(`TAG:${msgId}`, onRecv);
|
|
101
|
-
ws.on('close', onErr);
|
|
102
|
-
ws.
|
|
103
|
-
return () => reject(new Boom('Query Cancelled'));
|
|
125
|
+
ws.on('close', onErr); // if the socket closes, you'll never receive the message
|
|
126
|
+
ws.off('error', onErr);
|
|
104
127
|
});
|
|
105
|
-
return result;
|
|
106
|
-
}
|
|
107
|
-
catch (error) {
|
|
108
|
-
// Catch timeout and return undefined instead of throwing
|
|
109
|
-
if (error instanceof Boom && error.output?.statusCode === DisconnectReason.timedOut) {
|
|
110
|
-
logger?.warn?.({ msgId }, 'timed out waiting for message');
|
|
111
|
-
return undefined;
|
|
112
|
-
}
|
|
113
|
-
throw error;
|
|
114
128
|
}
|
|
115
129
|
finally {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
ws.off('close', onErr);
|
|
120
|
-
ws.off('error', onErr);
|
|
121
|
-
}
|
|
130
|
+
ws.off(`TAG:${msgId}`, onRecv);
|
|
131
|
+
ws.off('close', onErr); // if the socket closes, you'll never receive the message
|
|
132
|
+
ws.off('error', onErr);
|
|
122
133
|
}
|
|
123
134
|
};
|
|
124
135
|
/** send a query, and wait for its response. auto-generates message ID if not provided */
|
|
@@ -127,180 +138,11 @@ export const makeSocket = (config) => {
|
|
|
127
138
|
node.attrs.id = generateMessageTag();
|
|
128
139
|
}
|
|
129
140
|
const msgId = node.attrs.id;
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
});
|
|
136
|
-
if (result && 'tag' in result) {
|
|
137
|
-
assertNodeErrorFree(result);
|
|
138
|
-
}
|
|
139
|
-
return result;
|
|
140
|
-
};
|
|
141
|
-
// Validate current key-bundle on server; on failure, trigger pre-key upload and rethrow
|
|
142
|
-
const digestKeyBundle = async () => {
|
|
143
|
-
const res = await query({
|
|
144
|
-
tag: 'iq',
|
|
145
|
-
attrs: { to: S_WHATSAPP_NET, type: 'get', xmlns: 'encrypt' },
|
|
146
|
-
content: [{ tag: 'digest', attrs: {} }]
|
|
147
|
-
});
|
|
148
|
-
const digestNode = getBinaryNodeChild(res, 'digest');
|
|
149
|
-
if (!digestNode) {
|
|
150
|
-
await uploadPreKeys();
|
|
151
|
-
throw new Error('encrypt/get digest returned no digest node');
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
// Rotate our signed pre-key on server; on failure, run digest as fallback and rethrow
|
|
155
|
-
const rotateSignedPreKey = async () => {
|
|
156
|
-
const newId = (creds.signedPreKey.keyId || 0) + 1;
|
|
157
|
-
const skey = await signedKeyPair(creds.signedIdentityKey, newId);
|
|
158
|
-
await query({
|
|
159
|
-
tag: 'iq',
|
|
160
|
-
attrs: { to: S_WHATSAPP_NET, type: 'set', xmlns: 'encrypt' },
|
|
161
|
-
content: [
|
|
162
|
-
{
|
|
163
|
-
tag: 'rotate',
|
|
164
|
-
attrs: {},
|
|
165
|
-
content: [xmppSignedPreKey(skey)]
|
|
166
|
-
}
|
|
167
|
-
]
|
|
168
|
-
});
|
|
169
|
-
// Persist new signed pre-key in creds
|
|
170
|
-
ev.emit('creds.update', { signedPreKey: skey });
|
|
171
|
-
};
|
|
172
|
-
const executeUSyncQuery = async (usyncQuery) => {
|
|
173
|
-
if (usyncQuery.protocols.length === 0) {
|
|
174
|
-
throw new Boom('USyncQuery must have at least one protocol');
|
|
175
|
-
}
|
|
176
|
-
// todo: validate users, throw WARNING on no valid users
|
|
177
|
-
// variable below has only validated users
|
|
178
|
-
const validUsers = usyncQuery.users;
|
|
179
|
-
const userNodes = validUsers.map(user => {
|
|
180
|
-
return {
|
|
181
|
-
tag: 'user',
|
|
182
|
-
attrs: {
|
|
183
|
-
jid: !user.phone ? user.id : undefined
|
|
184
|
-
},
|
|
185
|
-
content: usyncQuery.protocols.map(a => a.getUserElement(user)).filter(a => a !== null)
|
|
186
|
-
};
|
|
187
|
-
});
|
|
188
|
-
const listNode = {
|
|
189
|
-
tag: 'list',
|
|
190
|
-
attrs: {},
|
|
191
|
-
content: userNodes
|
|
192
|
-
};
|
|
193
|
-
const queryNode = {
|
|
194
|
-
tag: 'query',
|
|
195
|
-
attrs: {},
|
|
196
|
-
content: usyncQuery.protocols.map(a => a.getQueryElement())
|
|
197
|
-
};
|
|
198
|
-
const iq = {
|
|
199
|
-
tag: 'iq',
|
|
200
|
-
attrs: {
|
|
201
|
-
to: S_WHATSAPP_NET,
|
|
202
|
-
type: 'get',
|
|
203
|
-
xmlns: 'usync'
|
|
204
|
-
},
|
|
205
|
-
content: [
|
|
206
|
-
{
|
|
207
|
-
tag: 'usync',
|
|
208
|
-
attrs: {
|
|
209
|
-
context: usyncQuery.context,
|
|
210
|
-
mode: usyncQuery.mode,
|
|
211
|
-
sid: generateMessageTag(),
|
|
212
|
-
last: 'true',
|
|
213
|
-
index: '0'
|
|
214
|
-
},
|
|
215
|
-
content: [queryNode, listNode]
|
|
216
|
-
}
|
|
217
|
-
]
|
|
218
|
-
};
|
|
219
|
-
const result = await query(iq);
|
|
220
|
-
return usyncQuery.parseUSyncQueryResult(result);
|
|
221
|
-
};
|
|
222
|
-
const onWhatsApp = async (...phoneNumber) => {
|
|
223
|
-
let usyncQuery = new USyncQuery();
|
|
224
|
-
let contactEnabled = false;
|
|
225
|
-
for (const jid of phoneNumber) {
|
|
226
|
-
if (isLidUser(jid)) {
|
|
227
|
-
logger?.warn('LIDs are not supported with onWhatsApp');
|
|
228
|
-
continue;
|
|
229
|
-
}
|
|
230
|
-
else {
|
|
231
|
-
if (!contactEnabled) {
|
|
232
|
-
contactEnabled = true;
|
|
233
|
-
usyncQuery = usyncQuery.withContactProtocol();
|
|
234
|
-
}
|
|
235
|
-
const phone = `+${jid.replace('+', '').split('@')[0]?.split(':')[0]}`;
|
|
236
|
-
usyncQuery.withUser(new USyncUser().withPhone(phone));
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
if (usyncQuery.users.length === 0) {
|
|
240
|
-
return []; // return early without forcing an empty query
|
|
241
|
-
}
|
|
242
|
-
const results = await executeUSyncQuery(usyncQuery);
|
|
243
|
-
if (results) {
|
|
244
|
-
return results.list.filter(a => !!a.contact).map(({ contact, id }) => ({ jid: id, exists: contact }));
|
|
245
|
-
}
|
|
246
|
-
};
|
|
247
|
-
const pnFromLIDUSync = async (jids) => {
|
|
248
|
-
const usyncQuery = new USyncQuery().withLIDProtocol().withContext('background');
|
|
249
|
-
for (const jid of jids) {
|
|
250
|
-
if (isLidUser(jid)) {
|
|
251
|
-
logger?.warn('LID user found in LID fetch call');
|
|
252
|
-
continue;
|
|
253
|
-
}
|
|
254
|
-
else {
|
|
255
|
-
usyncQuery.withUser(new USyncUser().withId(jid));
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
if (usyncQuery.users.length === 0) {
|
|
259
|
-
return []; // return early without forcing an empty query
|
|
260
|
-
}
|
|
261
|
-
const results = await executeUSyncQuery(usyncQuery);
|
|
262
|
-
if (results) {
|
|
263
|
-
return results.list.filter(a => !!a.lid).map(({ lid, id }) => ({ pn: id, lid: lid }));
|
|
264
|
-
}
|
|
265
|
-
return [];
|
|
266
|
-
};
|
|
267
|
-
const ev = makeEventBuffer(logger);
|
|
268
|
-
const { creds } = authState;
|
|
269
|
-
// add transaction capability
|
|
270
|
-
const keys = addTransactionCapability(authState.keys, logger, transactionOpts);
|
|
271
|
-
const signalRepository = makeSignalRepository({ creds, keys }, logger, pnFromLIDUSync);
|
|
272
|
-
let lastDateRecv;
|
|
273
|
-
let epoch = 1;
|
|
274
|
-
let keepAliveReq;
|
|
275
|
-
let qrTimer;
|
|
276
|
-
let closed = false;
|
|
277
|
-
const socketEndHandlers = [];
|
|
278
|
-
/** log & process any unexpected errors */
|
|
279
|
-
const onUnexpectedError = (err, msg) => {
|
|
280
|
-
logger.error({ err }, `unexpected error in '${msg}'`);
|
|
281
|
-
};
|
|
282
|
-
/** await the next incoming message */
|
|
283
|
-
const awaitNextMessage = async (sendMsg) => {
|
|
284
|
-
if (!ws.isOpen) {
|
|
285
|
-
throw new Boom('Connection Closed', {
|
|
286
|
-
statusCode: DisconnectReason.connectionClosed
|
|
287
|
-
});
|
|
288
|
-
}
|
|
289
|
-
let onOpen;
|
|
290
|
-
let onClose;
|
|
291
|
-
const result = promiseTimeout(connectTimeoutMs, (resolve, reject) => {
|
|
292
|
-
onOpen = resolve;
|
|
293
|
-
onClose = mapWebSocketError(reject);
|
|
294
|
-
ws.on('frame', onOpen);
|
|
295
|
-
ws.on('close', onClose);
|
|
296
|
-
ws.on('error', onClose);
|
|
297
|
-
}).finally(() => {
|
|
298
|
-
ws.off('frame', onOpen);
|
|
299
|
-
ws.off('close', onClose);
|
|
300
|
-
ws.off('error', onClose);
|
|
301
|
-
});
|
|
302
|
-
if (sendMsg) {
|
|
303
|
-
sendRawMessage(sendMsg).catch(onClose);
|
|
141
|
+
const wait = waitForMessage(msgId, timeoutMs);
|
|
142
|
+
await sendNode(node);
|
|
143
|
+
const result = await wait;
|
|
144
|
+
if ('tag' in result) {
|
|
145
|
+
(0, WABinary_1.assertNodeErrorFree)(result);
|
|
304
146
|
}
|
|
305
147
|
return result;
|
|
306
148
|
};
|
|
@@ -309,30 +151,33 @@ export const makeSocket = (config) => {
|
|
|
309
151
|
let helloMsg = {
|
|
310
152
|
clientHello: { ephemeral: ephemeralKeyPair.public }
|
|
311
153
|
};
|
|
312
|
-
helloMsg = proto.HandshakeMessage.fromObject(helloMsg);
|
|
154
|
+
helloMsg = WAProto_1.proto.HandshakeMessage.fromObject(helloMsg);
|
|
313
155
|
logger.info({ browser, helloMsg }, 'connected to WA');
|
|
314
|
-
const init = proto.HandshakeMessage.encode(helloMsg).finish();
|
|
156
|
+
const init = WAProto_1.proto.HandshakeMessage.encode(helloMsg).finish();
|
|
315
157
|
const result = await awaitNextMessage(init);
|
|
316
|
-
const handshake = proto.HandshakeMessage.decode(result);
|
|
158
|
+
const handshake = WAProto_1.proto.HandshakeMessage.decode(result);
|
|
317
159
|
logger.trace({ handshake }, 'handshake recv from WA');
|
|
318
160
|
const keyEnc = noise.processHandshake(handshake, creds.noiseKey);
|
|
319
161
|
let node;
|
|
320
|
-
if (
|
|
321
|
-
node =
|
|
162
|
+
if (config.mobile) {
|
|
163
|
+
node = (0, Utils_1.generateMobileNode)(config);
|
|
164
|
+
}
|
|
165
|
+
else if (!creds.me) {
|
|
166
|
+
node = (0, Utils_1.generateRegistrationNode)(creds, config);
|
|
322
167
|
logger.info({ node }, 'not logged in, attempting registration...');
|
|
323
168
|
}
|
|
324
169
|
else {
|
|
325
|
-
node = generateLoginNode(creds.me.id, config);
|
|
170
|
+
node = (0, Utils_1.generateLoginNode)(creds.me.id, config);
|
|
326
171
|
logger.info({ node }, 'logging in...');
|
|
327
172
|
}
|
|
328
|
-
const payloadEnc = noise.encrypt(proto.ClientPayload.encode(node).finish());
|
|
329
|
-
await sendRawMessage(proto.HandshakeMessage.encode({
|
|
173
|
+
const payloadEnc = noise.encrypt(WAProto_1.proto.ClientPayload.encode(node).finish());
|
|
174
|
+
await sendRawMessage(WAProto_1.proto.HandshakeMessage.encode({
|
|
330
175
|
clientFinish: {
|
|
331
176
|
static: keyEnc,
|
|
332
|
-
payload: payloadEnc
|
|
333
|
-
}
|
|
177
|
+
payload: payloadEnc,
|
|
178
|
+
},
|
|
334
179
|
}).finish());
|
|
335
|
-
|
|
180
|
+
noise.finishInit();
|
|
336
181
|
startKeepAliveRequest();
|
|
337
182
|
};
|
|
338
183
|
const getAvailablePreKeysOnServer = async () => {
|
|
@@ -342,104 +187,35 @@ export const makeSocket = (config) => {
|
|
|
342
187
|
id: generateMessageTag(),
|
|
343
188
|
xmlns: 'encrypt',
|
|
344
189
|
type: 'get',
|
|
345
|
-
to: S_WHATSAPP_NET
|
|
190
|
+
to: WABinary_1.S_WHATSAPP_NET
|
|
346
191
|
},
|
|
347
|
-
content: [
|
|
192
|
+
content: [
|
|
193
|
+
{ tag: 'count', attrs: {} }
|
|
194
|
+
]
|
|
348
195
|
});
|
|
349
|
-
const countChild = getBinaryNodeChild(result, 'count');
|
|
196
|
+
const countChild = (0, WABinary_1.getBinaryNodeChild)(result, 'count');
|
|
350
197
|
return +countChild.attrs.value;
|
|
351
198
|
};
|
|
352
|
-
// WAWeb has no time throttle here; the server drives uploads via PreKeyLow notifications.
|
|
353
|
-
let uploadPreKeysPromise = null;
|
|
354
199
|
/** generates and uploads a set of pre-keys to the server */
|
|
355
|
-
const uploadPreKeys = async (count =
|
|
356
|
-
|
|
357
|
-
logger.
|
|
358
|
-
await
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
// Generate and save pre-keys atomically (prevents ID collisions on retry)
|
|
364
|
-
const node = await keys.transaction(async () => {
|
|
365
|
-
logger.debug({ requestedCount: count }, 'generating pre-keys with requested count');
|
|
366
|
-
const { update, node } = await getNextPreKeysNode({ creds, keys }, count);
|
|
367
|
-
// Update credentials immediately to prevent duplicate IDs on retry
|
|
368
|
-
ev.emit('creds.update', update);
|
|
369
|
-
return node;
|
|
370
|
-
}, creds?.me?.id || 'upload-pre-keys');
|
|
371
|
-
// Upload to server (outside transaction, can fail without affecting local keys)
|
|
372
|
-
try {
|
|
373
|
-
await query(node);
|
|
374
|
-
logger.info({ count }, 'uploaded pre-keys successfully');
|
|
375
|
-
}
|
|
376
|
-
catch (uploadError) {
|
|
377
|
-
logger.error({ uploadError: uploadError.toString(), count }, 'Failed to upload pre-keys to server');
|
|
378
|
-
// Recurse into uploadLogic; calling uploadPreKeys would await its own in-flight promise.
|
|
379
|
-
if (retryCount < 3) {
|
|
380
|
-
const backoffDelay = Math.min(1000 * Math.pow(2, retryCount), 10000);
|
|
381
|
-
logger.info(`Retrying pre-key upload in ${backoffDelay}ms`);
|
|
382
|
-
await new Promise(resolve => setTimeout(resolve, backoffDelay));
|
|
383
|
-
return uploadLogic(retryCount + 1);
|
|
384
|
-
}
|
|
385
|
-
throw uploadError;
|
|
386
|
-
}
|
|
387
|
-
};
|
|
388
|
-
// Add timeout protection
|
|
389
|
-
uploadPreKeysPromise = Promise.race([
|
|
390
|
-
uploadLogic(0),
|
|
391
|
-
new Promise((_, reject) => setTimeout(() => reject(new Boom('Pre-key upload timeout', { statusCode: 408 })), UPLOAD_TIMEOUT))
|
|
392
|
-
]);
|
|
393
|
-
try {
|
|
394
|
-
await uploadPreKeysPromise;
|
|
395
|
-
}
|
|
396
|
-
finally {
|
|
397
|
-
uploadPreKeysPromise = null;
|
|
398
|
-
}
|
|
399
|
-
};
|
|
400
|
-
const verifyCurrentPreKeyExists = async () => {
|
|
401
|
-
const currentPreKeyId = creds.nextPreKeyId - 1;
|
|
402
|
-
if (currentPreKeyId <= 0) {
|
|
403
|
-
return { exists: false, currentPreKeyId: 0 };
|
|
404
|
-
}
|
|
405
|
-
const preKeys = await keys.get('pre-key', [currentPreKeyId.toString()]);
|
|
406
|
-
const exists = !!preKeys[currentPreKeyId.toString()];
|
|
407
|
-
return { exists, currentPreKeyId };
|
|
200
|
+
const uploadPreKeys = async (count = Defaults_1.INITIAL_PREKEY_COUNT) => {
|
|
201
|
+
await keys.transaction(async () => {
|
|
202
|
+
logger.info({ count }, 'uploading pre-keys');
|
|
203
|
+
const { update, node } = await (0, Utils_1.getNextPreKeysNode)({ creds, keys }, count);
|
|
204
|
+
await query(node);
|
|
205
|
+
ev.emit('creds.update', update);
|
|
206
|
+
logger.info({ count }, 'uploaded pre-keys');
|
|
207
|
+
});
|
|
408
208
|
};
|
|
409
209
|
const uploadPreKeysToServerIfRequired = async () => {
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
count = INITIAL_PREKEY_COUNT;
|
|
415
|
-
else
|
|
416
|
-
count = MIN_PREKEY_COUNT;
|
|
417
|
-
const { exists: currentPreKeyExists, currentPreKeyId } = await verifyCurrentPreKeyExists();
|
|
418
|
-
logger.info(`${preKeyCount} pre-keys found on server`);
|
|
419
|
-
logger.info(`Current prekey ID: ${currentPreKeyId}, exists in storage: ${currentPreKeyExists}`);
|
|
420
|
-
const lowServerCount = preKeyCount <= count;
|
|
421
|
-
const missingCurrentPreKey = !currentPreKeyExists && currentPreKeyId > 0;
|
|
422
|
-
const shouldUpload = lowServerCount || missingCurrentPreKey;
|
|
423
|
-
if (shouldUpload) {
|
|
424
|
-
const reasons = [];
|
|
425
|
-
if (lowServerCount)
|
|
426
|
-
reasons.push(`server count low (${preKeyCount})`);
|
|
427
|
-
if (missingCurrentPreKey)
|
|
428
|
-
reasons.push(`current prekey ${currentPreKeyId} missing from storage`);
|
|
429
|
-
logger.info(`Uploading PreKeys due to: ${reasons.join(', ')}`);
|
|
430
|
-
await uploadPreKeys(count);
|
|
431
|
-
}
|
|
432
|
-
else {
|
|
433
|
-
logger.info(`PreKey validation passed - Server: ${preKeyCount}, Current prekey ${currentPreKeyId} exists`);
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
catch (error) {
|
|
437
|
-
logger.error({ error }, 'Failed to check/upload pre-keys during initialization');
|
|
438
|
-
// Don't throw - allow connection to continue even if pre-key check fails
|
|
210
|
+
const preKeyCount = await getAvailablePreKeysOnServer();
|
|
211
|
+
logger.info(`${preKeyCount} pre-keys found on server`);
|
|
212
|
+
if (preKeyCount <= Defaults_1.MIN_PREKEY_COUNT) {
|
|
213
|
+
await uploadPreKeys();
|
|
439
214
|
}
|
|
440
215
|
};
|
|
441
|
-
const onMessageReceived =
|
|
442
|
-
|
|
216
|
+
const onMessageReceived = (data) => {
|
|
217
|
+
noise.decodeFrame(data, frame => {
|
|
218
|
+
var _a;
|
|
443
219
|
// reset ping timeout
|
|
444
220
|
lastDateRecv = new Date();
|
|
445
221
|
let anyTriggered = false;
|
|
@@ -448,53 +224,45 @@ export const makeSocket = (config) => {
|
|
|
448
224
|
if (!(frame instanceof Uint8Array)) {
|
|
449
225
|
const msgId = frame.attrs.id;
|
|
450
226
|
if (logger.level === 'trace') {
|
|
451
|
-
logger.trace({ xml: binaryNodeToString(frame), msg: 'recv xml' });
|
|
227
|
+
logger.trace({ xml: (0, WABinary_1.binaryNodeToString)(frame), msg: 'recv xml' });
|
|
452
228
|
}
|
|
453
229
|
/* Check if this is a response to a message we sent */
|
|
454
|
-
anyTriggered = ws.emit(`${DEF_TAG_PREFIX}${msgId}`, frame) || anyTriggered;
|
|
230
|
+
anyTriggered = ws.emit(`${Defaults_1.DEF_TAG_PREFIX}${msgId}`, frame) || anyTriggered;
|
|
455
231
|
/* Check if this is a response to a message we are expecting */
|
|
456
232
|
const l0 = frame.tag;
|
|
457
233
|
const l1 = frame.attrs || {};
|
|
458
|
-
const l2 = Array.isArray(frame.content) ? frame.content[0]
|
|
459
|
-
|
|
460
|
-
anyTriggered = ws.emit(`${DEF_CALLBACK_PREFIX}${l0},${key}:${l1[key]},${l2}`, frame) || anyTriggered;
|
|
461
|
-
anyTriggered = ws.emit(`${DEF_CALLBACK_PREFIX}${l0},${key}:${l1[key]}`, frame) || anyTriggered;
|
|
462
|
-
anyTriggered = ws.emit(`${DEF_CALLBACK_PREFIX}${l0},${key}`, frame) || anyTriggered;
|
|
463
|
-
}
|
|
464
|
-
anyTriggered = ws.emit(`${DEF_CALLBACK_PREFIX}${l0},,${l2}`, frame) || anyTriggered;
|
|
465
|
-
anyTriggered = ws.emit(`${DEF_CALLBACK_PREFIX}${l0}`, frame) || anyTriggered;
|
|
234
|
+
const l2 = Array.isArray(frame.content) ? (_a = frame.content[0]) === null || _a === void 0 ? void 0 : _a.tag : '';
|
|
235
|
+
Object.keys(l1).forEach(key => {
|
|
236
|
+
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},${key}:${l1[key]},${l2}`, frame) || anyTriggered;
|
|
237
|
+
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},${key}:${l1[key]}`, frame) || anyTriggered;
|
|
238
|
+
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},${key}`, frame) || anyTriggered;
|
|
239
|
+
});
|
|
240
|
+
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},,${l2}`, frame) || anyTriggered;
|
|
241
|
+
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0}`, frame) || anyTriggered;
|
|
466
242
|
if (!anyTriggered && logger.level === 'debug') {
|
|
467
243
|
logger.debug({ unhandled: true, msgId, fromMe: false, frame }, 'communication recv');
|
|
468
244
|
}
|
|
469
245
|
}
|
|
470
246
|
});
|
|
471
247
|
};
|
|
472
|
-
const end =
|
|
248
|
+
const end = (error) => {
|
|
473
249
|
if (closed) {
|
|
474
|
-
logger.trace({ trace: error
|
|
250
|
+
logger.trace({ trace: error === null || error === void 0 ? void 0 : error.stack }, 'connection already closed');
|
|
475
251
|
return;
|
|
476
252
|
}
|
|
477
253
|
closed = true;
|
|
478
|
-
logger.info({ trace: error
|
|
254
|
+
logger.info({ trace: error === null || error === void 0 ? void 0 : error.stack }, error ? 'connection errored' : 'connection closed');
|
|
479
255
|
clearInterval(keepAliveReq);
|
|
480
256
|
clearTimeout(qrTimer);
|
|
481
257
|
ws.removeAllListeners('close');
|
|
258
|
+
ws.removeAllListeners('error');
|
|
482
259
|
ws.removeAllListeners('open');
|
|
483
260
|
ws.removeAllListeners('message');
|
|
484
|
-
signalRepository.close?.();
|
|
485
261
|
if (!ws.isClosed && !ws.isClosing) {
|
|
486
262
|
try {
|
|
487
|
-
|
|
488
|
-
}
|
|
489
|
-
catch { }
|
|
490
|
-
}
|
|
491
|
-
for (const handler of socketEndHandlers) {
|
|
492
|
-
try {
|
|
493
|
-
await handler(error);
|
|
494
|
-
}
|
|
495
|
-
catch (err) {
|
|
496
|
-
logger.error({ err }, 'error in socket end handler');
|
|
263
|
+
ws.close();
|
|
497
264
|
}
|
|
265
|
+
catch (_a) { }
|
|
498
266
|
}
|
|
499
267
|
ev.emit('connection.update', {
|
|
500
268
|
connection: 'close',
|
|
@@ -504,14 +272,13 @@ export const makeSocket = (config) => {
|
|
|
504
272
|
}
|
|
505
273
|
});
|
|
506
274
|
ev.removeAllListeners('connection.update');
|
|
507
|
-
ev.destroy();
|
|
508
275
|
};
|
|
509
276
|
const waitForSocketOpen = async () => {
|
|
510
277
|
if (ws.isOpen) {
|
|
511
278
|
return;
|
|
512
279
|
}
|
|
513
280
|
if (ws.isClosed || ws.isClosing) {
|
|
514
|
-
throw new Boom('Connection Closed', { statusCode: DisconnectReason.connectionClosed });
|
|
281
|
+
throw new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed });
|
|
515
282
|
}
|
|
516
283
|
let onOpen;
|
|
517
284
|
let onClose;
|
|
@@ -521,7 +288,8 @@ export const makeSocket = (config) => {
|
|
|
521
288
|
ws.on('open', onOpen);
|
|
522
289
|
ws.on('close', onClose);
|
|
523
290
|
ws.on('error', onClose);
|
|
524
|
-
})
|
|
291
|
+
})
|
|
292
|
+
.finally(() => {
|
|
525
293
|
ws.off('open', onOpen);
|
|
526
294
|
ws.off('close', onClose);
|
|
527
295
|
ws.off('error', onClose);
|
|
@@ -537,7 +305,7 @@ export const makeSocket = (config) => {
|
|
|
537
305
|
it could be that the network is down
|
|
538
306
|
*/
|
|
539
307
|
if (diff > keepAliveIntervalMs + 5000) {
|
|
540
|
-
|
|
308
|
+
end(new boom_1.Boom('Connection was lost', { statusCode: Types_1.DisconnectReason.connectionLost }));
|
|
541
309
|
}
|
|
542
310
|
else if (ws.isOpen) {
|
|
543
311
|
// if its all good, send a keep alive request
|
|
@@ -545,12 +313,13 @@ export const makeSocket = (config) => {
|
|
|
545
313
|
tag: 'iq',
|
|
546
314
|
attrs: {
|
|
547
315
|
id: generateMessageTag(),
|
|
548
|
-
to: S_WHATSAPP_NET,
|
|
316
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
549
317
|
type: 'get',
|
|
550
|
-
xmlns: 'w:p'
|
|
318
|
+
xmlns: 'w:p',
|
|
551
319
|
},
|
|
552
320
|
content: [{ tag: 'ping', attrs: {} }]
|
|
553
|
-
})
|
|
321
|
+
})
|
|
322
|
+
.catch(err => {
|
|
554
323
|
logger.error({ trace: err.stack }, 'error in sending keep alive');
|
|
555
324
|
});
|
|
556
325
|
}
|
|
@@ -559,23 +328,26 @@ export const makeSocket = (config) => {
|
|
|
559
328
|
}
|
|
560
329
|
}, keepAliveIntervalMs));
|
|
561
330
|
/** i have no idea why this exists. pls enlighten me */
|
|
562
|
-
const sendPassiveIq = (tag) => query({
|
|
331
|
+
const sendPassiveIq = (tag) => (query({
|
|
563
332
|
tag: 'iq',
|
|
564
333
|
attrs: {
|
|
565
|
-
to: S_WHATSAPP_NET,
|
|
334
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
566
335
|
xmlns: 'passive',
|
|
567
|
-
type: 'set'
|
|
336
|
+
type: 'set',
|
|
568
337
|
},
|
|
569
|
-
content: [
|
|
570
|
-
|
|
338
|
+
content: [
|
|
339
|
+
{ tag, attrs: {} }
|
|
340
|
+
]
|
|
341
|
+
}));
|
|
571
342
|
/** logout & invalidate connection */
|
|
572
343
|
const logout = async (msg) => {
|
|
573
|
-
|
|
344
|
+
var _a;
|
|
345
|
+
const jid = (_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.id;
|
|
574
346
|
if (jid) {
|
|
575
347
|
await sendNode({
|
|
576
348
|
tag: 'iq',
|
|
577
349
|
attrs: {
|
|
578
|
-
to: S_WHATSAPP_NET,
|
|
350
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
579
351
|
type: 'set',
|
|
580
352
|
id: generateMessageTag(),
|
|
581
353
|
xmlns: 'md'
|
|
@@ -591,23 +363,19 @@ export const makeSocket = (config) => {
|
|
|
591
363
|
]
|
|
592
364
|
});
|
|
593
365
|
}
|
|
594
|
-
|
|
366
|
+
end(new boom_1.Boom(msg || 'Intentional Logout', { statusCode: Types_1.DisconnectReason.loggedOut }));
|
|
595
367
|
};
|
|
596
|
-
const requestPairingCode = async (phoneNumber
|
|
597
|
-
|
|
598
|
-
if (customPairingCode && customPairingCode?.length !== 8) {
|
|
599
|
-
throw new Error('Custom pairing code must be exactly 8 chars');
|
|
600
|
-
}
|
|
601
|
-
authState.creds.pairingCode = pairingCode;
|
|
368
|
+
const requestPairingCode = async (phoneNumber) => {
|
|
369
|
+
authState.creds.pairingCode = (0, Utils_1.bytesToCrockford)((0, crypto_1.randomBytes)(5));
|
|
602
370
|
authState.creds.me = {
|
|
603
|
-
id: jidEncode(phoneNumber, 's.whatsapp.net'),
|
|
371
|
+
id: (0, WABinary_1.jidEncode)(phoneNumber, 's.whatsapp.net'),
|
|
604
372
|
name: '~'
|
|
605
373
|
};
|
|
606
374
|
ev.emit('creds.update', authState.creds);
|
|
607
375
|
await sendNode({
|
|
608
376
|
tag: 'iq',
|
|
609
377
|
attrs: {
|
|
610
|
-
to: S_WHATSAPP_NET,
|
|
378
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
611
379
|
type: 'set',
|
|
612
380
|
id: generateMessageTag(),
|
|
613
381
|
xmlns: 'md'
|
|
@@ -618,6 +386,7 @@ export const makeSocket = (config) => {
|
|
|
618
386
|
attrs: {
|
|
619
387
|
jid: authState.creds.me.id,
|
|
620
388
|
stage: 'companion_hello',
|
|
389
|
+
// eslint-disable-next-line camelcase
|
|
621
390
|
should_show_push_notification: 'true'
|
|
622
391
|
},
|
|
623
392
|
content: [
|
|
@@ -634,7 +403,7 @@ export const makeSocket = (config) => {
|
|
|
634
403
|
{
|
|
635
404
|
tag: 'companion_platform_id',
|
|
636
405
|
attrs: {},
|
|
637
|
-
content:
|
|
406
|
+
content: (0, Utils_1.getPlatformId)(browser[1])
|
|
638
407
|
},
|
|
639
408
|
{
|
|
640
409
|
tag: 'companion_platform_display',
|
|
@@ -653,24 +422,24 @@ export const makeSocket = (config) => {
|
|
|
653
422
|
return authState.creds.pairingCode;
|
|
654
423
|
};
|
|
655
424
|
async function generatePairingKey() {
|
|
656
|
-
const salt = randomBytes(32);
|
|
657
|
-
const randomIv = randomBytes(16);
|
|
658
|
-
const key = await derivePairingCodeKey(authState.creds.pairingCode, salt);
|
|
659
|
-
const ciphered = aesEncryptCTR(authState.creds.pairingEphemeralKeyPair.public, key, randomIv);
|
|
425
|
+
const salt = (0, crypto_1.randomBytes)(32);
|
|
426
|
+
const randomIv = (0, crypto_1.randomBytes)(16);
|
|
427
|
+
const key = await (0, Utils_1.derivePairingCodeKey)(authState.creds.pairingCode, salt);
|
|
428
|
+
const ciphered = (0, Utils_1.aesEncryptCTR)(authState.creds.pairingEphemeralKeyPair.public, key, randomIv);
|
|
660
429
|
return Buffer.concat([salt, randomIv, ciphered]);
|
|
661
430
|
}
|
|
662
431
|
const sendWAMBuffer = (wamBuffer) => {
|
|
663
432
|
return query({
|
|
664
433
|
tag: 'iq',
|
|
665
434
|
attrs: {
|
|
666
|
-
to: S_WHATSAPP_NET,
|
|
435
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
667
436
|
id: generateMessageTag(),
|
|
668
437
|
xmlns: 'w:stats'
|
|
669
438
|
},
|
|
670
439
|
content: [
|
|
671
440
|
{
|
|
672
441
|
tag: 'add',
|
|
673
|
-
attrs: {
|
|
442
|
+
attrs: {},
|
|
674
443
|
content: wamBuffer
|
|
675
444
|
}
|
|
676
445
|
]
|
|
@@ -683,26 +452,26 @@ export const makeSocket = (config) => {
|
|
|
683
452
|
}
|
|
684
453
|
catch (err) {
|
|
685
454
|
logger.error({ err }, 'error in validating connection');
|
|
686
|
-
|
|
455
|
+
end(err);
|
|
687
456
|
}
|
|
688
457
|
});
|
|
689
458
|
ws.on('error', mapWebSocketError(end));
|
|
690
|
-
ws.on('close', () =>
|
|
459
|
+
ws.on('close', () => end(new boom_1.Boom('Connection Terminated', { statusCode: Types_1.DisconnectReason.connectionClosed })));
|
|
691
460
|
// the server terminated the connection
|
|
692
|
-
ws.on('CB:xmlstreamend', () =>
|
|
461
|
+
ws.on('CB:xmlstreamend', () => end(new boom_1.Boom('Connection Terminated by Server', { statusCode: Types_1.DisconnectReason.connectionClosed })));
|
|
693
462
|
// QR gen
|
|
694
463
|
ws.on('CB:iq,type:set,pair-device', async (stanza) => {
|
|
695
464
|
const iq = {
|
|
696
465
|
tag: 'iq',
|
|
697
466
|
attrs: {
|
|
698
|
-
to: S_WHATSAPP_NET,
|
|
467
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
699
468
|
type: 'result',
|
|
700
|
-
id: stanza.attrs.id
|
|
469
|
+
id: stanza.attrs.id,
|
|
701
470
|
}
|
|
702
471
|
};
|
|
703
472
|
await sendNode(iq);
|
|
704
|
-
const pairDeviceNode = getBinaryNodeChild(stanza, 'pair-device');
|
|
705
|
-
const refNodes = getBinaryNodeChildren(pairDeviceNode, 'ref');
|
|
473
|
+
const pairDeviceNode = (0, WABinary_1.getBinaryNodeChild)(stanza, 'pair-device');
|
|
474
|
+
const refNodes = (0, WABinary_1.getBinaryNodeChildren)(pairDeviceNode, 'ref');
|
|
706
475
|
const noiseKeyB64 = Buffer.from(creds.noiseKey.public).toString('base64');
|
|
707
476
|
const identityKeyB64 = Buffer.from(creds.signedIdentityKey.public).toString('base64');
|
|
708
477
|
const advB64 = creds.advSecretKey;
|
|
@@ -713,11 +482,11 @@ export const makeSocket = (config) => {
|
|
|
713
482
|
}
|
|
714
483
|
const refNode = refNodes.shift();
|
|
715
484
|
if (!refNode) {
|
|
716
|
-
|
|
485
|
+
end(new boom_1.Boom('QR refs attempts ended', { statusCode: Types_1.DisconnectReason.timedOut }));
|
|
717
486
|
return;
|
|
718
487
|
}
|
|
719
488
|
const ref = refNode.content.toString('utf-8');
|
|
720
|
-
const qr =
|
|
489
|
+
const qr = [ref, noiseKeyB64, identityKeyB64, advB64].join(',');
|
|
721
490
|
ev.emit('connection.update', { qr });
|
|
722
491
|
qrTimer = setTimeout(genPairQR, qrMs);
|
|
723
492
|
qrMs = qrTimeout || 20000; // shorter subsequent qrs
|
|
@@ -729,98 +498,51 @@ export const makeSocket = (config) => {
|
|
|
729
498
|
ws.on('CB:iq,,pair-success', async (stanza) => {
|
|
730
499
|
logger.debug('pair success recv');
|
|
731
500
|
try {
|
|
732
|
-
|
|
733
|
-
const { reply, creds: updatedCreds } = configureSuccessfulPairing(stanza, creds);
|
|
501
|
+
const { reply, creds: updatedCreds } = (0, Utils_1.configureSuccessfulPairing)(stanza, creds);
|
|
734
502
|
logger.info({ me: updatedCreds.me, platform: updatedCreds.platform }, 'pairing configured successfully, expect to restart the connection...');
|
|
735
503
|
ev.emit('creds.update', updatedCreds);
|
|
736
504
|
ev.emit('connection.update', { isNewLogin: true, qr: undefined });
|
|
737
505
|
await sendNode(reply);
|
|
738
|
-
void sendUnifiedSession();
|
|
739
506
|
}
|
|
740
507
|
catch (error) {
|
|
741
508
|
logger.info({ trace: error.stack }, 'error in pairing');
|
|
742
|
-
|
|
509
|
+
end(error);
|
|
743
510
|
}
|
|
744
511
|
});
|
|
745
512
|
// login complete
|
|
746
513
|
ws.on('CB:success', async (node) => {
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
await uploadPreKeysToServerIfRequired();
|
|
750
|
-
await sendPassiveIq('active');
|
|
751
|
-
// After successful login, validate our key-bundle against server
|
|
752
|
-
try {
|
|
753
|
-
await digestKeyBundle();
|
|
754
|
-
}
|
|
755
|
-
catch (e) {
|
|
756
|
-
logger.warn({ e }, 'failed to run digest after login');
|
|
757
|
-
}
|
|
758
|
-
}
|
|
759
|
-
catch (err) {
|
|
760
|
-
logger.warn({ err }, 'failed to send initial passive iq');
|
|
761
|
-
}
|
|
514
|
+
await uploadPreKeysToServerIfRequired();
|
|
515
|
+
await sendPassiveIq('active');
|
|
762
516
|
logger.info('opened connection to WA');
|
|
763
517
|
clearTimeout(qrTimer); // will never happen in all likelyhood -- but just in case WA sends success on first try
|
|
764
518
|
ev.emit('creds.update', { me: { ...authState.creds.me, lid: node.attrs.lid } });
|
|
765
519
|
ev.emit('connection.update', { connection: 'open' });
|
|
766
|
-
void sendUnifiedSession();
|
|
767
|
-
if (node.attrs.lid && authState.creds.me?.id) {
|
|
768
|
-
const myLID = node.attrs.lid;
|
|
769
|
-
process.nextTick(async () => {
|
|
770
|
-
try {
|
|
771
|
-
const myPN = authState.creds.me.id;
|
|
772
|
-
// Store our own LID-PN mapping
|
|
773
|
-
await signalRepository.lidMapping.storeLIDPNMappings([{ lid: myLID, pn: myPN }]);
|
|
774
|
-
// Create device list for our own user (needed for bulk migration)
|
|
775
|
-
const { user, device } = jidDecode(myPN);
|
|
776
|
-
await authState.keys.set({
|
|
777
|
-
'device-list': {
|
|
778
|
-
[user]: [device?.toString() || '0']
|
|
779
|
-
}
|
|
780
|
-
});
|
|
781
|
-
// migrate our own session
|
|
782
|
-
await signalRepository.migrateSession(myPN, myLID);
|
|
783
|
-
logger.info({ myPN, myLID }, 'Own LID session created successfully');
|
|
784
|
-
}
|
|
785
|
-
catch (error) {
|
|
786
|
-
logger.error({ error, lid: myLID }, 'Failed to create own LID session');
|
|
787
|
-
}
|
|
788
|
-
});
|
|
789
|
-
}
|
|
790
520
|
});
|
|
791
521
|
ws.on('CB:stream:error', (node) => {
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
void end(new Boom(`Stream Errored (${reason})`, { statusCode, data: reasonNode || node }));
|
|
522
|
+
logger.error({ node }, 'stream errored out');
|
|
523
|
+
const { reason, statusCode } = (0, Utils_1.getErrorCodeFromStreamError)(node);
|
|
524
|
+
end(new boom_1.Boom(`Stream Errored (${reason})`, { statusCode, data: node }));
|
|
796
525
|
});
|
|
797
526
|
// stream fail, possible logout
|
|
798
527
|
ws.on('CB:failure', (node) => {
|
|
799
528
|
const reason = +(node.attrs.reason || 500);
|
|
800
|
-
|
|
529
|
+
end(new boom_1.Boom('Connection Failure', { statusCode: reason, data: node.attrs }));
|
|
801
530
|
});
|
|
802
531
|
ws.on('CB:ib,,downgrade_webclient', () => {
|
|
803
|
-
|
|
804
|
-
});
|
|
805
|
-
ws.on('CB:ib,,offline_preview', async (node) => {
|
|
806
|
-
logger.info('offline preview received', JSON.stringify(node));
|
|
807
|
-
await sendNode({
|
|
808
|
-
tag: 'ib',
|
|
809
|
-
attrs: {},
|
|
810
|
-
content: [{ tag: 'offline_batch', attrs: { count: '100' } }]
|
|
811
|
-
});
|
|
532
|
+
end(new boom_1.Boom('Multi-device beta not joined', { statusCode: Types_1.DisconnectReason.multideviceMismatch }));
|
|
812
533
|
});
|
|
813
534
|
ws.on('CB:ib,,edge_routing', (node) => {
|
|
814
|
-
const edgeRoutingNode = getBinaryNodeChild(node, 'edge_routing');
|
|
815
|
-
const routingInfo = getBinaryNodeChild(edgeRoutingNode, 'routing_info');
|
|
816
|
-
if (routingInfo
|
|
817
|
-
authState.creds.routingInfo = Buffer.from(routingInfo
|
|
535
|
+
const edgeRoutingNode = (0, WABinary_1.getBinaryNodeChild)(node, 'edge_routing');
|
|
536
|
+
const routingInfo = (0, WABinary_1.getBinaryNodeChild)(edgeRoutingNode, 'routing_info');
|
|
537
|
+
if (routingInfo === null || routingInfo === void 0 ? void 0 : routingInfo.content) {
|
|
538
|
+
authState.creds.routingInfo = Buffer.from(routingInfo === null || routingInfo === void 0 ? void 0 : routingInfo.content);
|
|
818
539
|
ev.emit('creds.update', authState.creds);
|
|
819
540
|
}
|
|
820
541
|
});
|
|
821
542
|
let didStartBuffer = false;
|
|
822
543
|
process.nextTick(() => {
|
|
823
|
-
|
|
544
|
+
var _a;
|
|
545
|
+
if ((_a = creds.me) === null || _a === void 0 ? void 0 : _a.id) {
|
|
824
546
|
// start buffering important events
|
|
825
547
|
// if we're logged in
|
|
826
548
|
ev.buffer();
|
|
@@ -830,8 +552,8 @@ export const makeSocket = (config) => {
|
|
|
830
552
|
});
|
|
831
553
|
// called when all offline notifs are handled
|
|
832
554
|
ws.on('CB:ib,,offline', (node) => {
|
|
833
|
-
const child = getBinaryNodeChild(node, 'offline');
|
|
834
|
-
const offlineNotifs = +(child
|
|
555
|
+
const child = (0, WABinary_1.getBinaryNodeChild)(node, 'offline');
|
|
556
|
+
const offlineNotifs = +((child === null || child === void 0 ? void 0 : child.attrs.count) || 0);
|
|
835
557
|
logger.info(`handled ${offlineNotifs} offline messages/notifications`);
|
|
836
558
|
if (didStartBuffer) {
|
|
837
559
|
ev.flush();
|
|
@@ -841,87 +563,24 @@ export const makeSocket = (config) => {
|
|
|
841
563
|
});
|
|
842
564
|
// update credentials when required
|
|
843
565
|
ev.on('creds.update', update => {
|
|
844
|
-
|
|
566
|
+
var _a, _b;
|
|
567
|
+
const name = (_a = update.me) === null || _a === void 0 ? void 0 : _a.name;
|
|
845
568
|
// if name has just been received
|
|
846
|
-
if (creds.me
|
|
569
|
+
if (((_b = creds.me) === null || _b === void 0 ? void 0 : _b.name) !== name) {
|
|
847
570
|
logger.debug({ name }, 'updated pushName');
|
|
848
571
|
sendNode({
|
|
849
572
|
tag: 'presence',
|
|
850
573
|
attrs: { name: name }
|
|
851
|
-
})
|
|
574
|
+
})
|
|
575
|
+
.catch(err => {
|
|
852
576
|
logger.warn({ trace: err.stack }, 'error in sending presence update on name change');
|
|
853
577
|
});
|
|
854
578
|
}
|
|
855
579
|
Object.assign(creds, update);
|
|
856
580
|
});
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
return;
|
|
861
|
-
}
|
|
862
|
-
const parsed = Number(tValue);
|
|
863
|
-
if (Number.isNaN(parsed) || parsed <= 0) {
|
|
864
|
-
return;
|
|
865
|
-
}
|
|
866
|
-
const localMs = Date.now();
|
|
867
|
-
serverTimeOffsetMs = parsed * 1000 - localMs;
|
|
868
|
-
logger.debug({ offset: serverTimeOffsetMs }, 'calculated server time offset');
|
|
869
|
-
};
|
|
870
|
-
const getUnifiedSessionId = () => {
|
|
871
|
-
const offsetMs = 3 * TimeMs.Day;
|
|
872
|
-
const now = Date.now() + serverTimeOffsetMs;
|
|
873
|
-
const id = (now + offsetMs) % TimeMs.Week;
|
|
874
|
-
return id.toString();
|
|
875
|
-
};
|
|
876
|
-
const sendUnifiedSession = async () => {
|
|
877
|
-
if (!ws.isOpen) {
|
|
878
|
-
return;
|
|
879
|
-
}
|
|
880
|
-
const node = {
|
|
881
|
-
tag: 'ib',
|
|
882
|
-
attrs: {},
|
|
883
|
-
content: [
|
|
884
|
-
{
|
|
885
|
-
tag: 'unified_session',
|
|
886
|
-
attrs: {
|
|
887
|
-
id: getUnifiedSessionId()
|
|
888
|
-
}
|
|
889
|
-
}
|
|
890
|
-
]
|
|
891
|
-
};
|
|
892
|
-
try {
|
|
893
|
-
await sendNode(node);
|
|
894
|
-
}
|
|
895
|
-
catch (error) {
|
|
896
|
-
logger.debug({ error }, 'failed to send unified_session telemetry');
|
|
897
|
-
}
|
|
898
|
-
};
|
|
899
|
-
const registerSocketEndHandler = (handler) => {
|
|
900
|
-
socketEndHandlers.push(handler);
|
|
901
|
-
};
|
|
902
|
-
/**
|
|
903
|
-
* Fetches your account's standing when it comes to restrictions.
|
|
904
|
-
* @returns Returns the state of the restrictions.
|
|
905
|
-
*/
|
|
906
|
-
const fetchAccountReachoutTimelock = async () => {
|
|
907
|
-
const queryResult = await executeWMexQuery({}, QueryIds.REACHOUT_TIMELOCK, XWAPaths.xwa2_fetch_account_reachout_timelock, query, generateMessageTag);
|
|
908
|
-
const result = {
|
|
909
|
-
isActive: !!queryResult?.is_active,
|
|
910
|
-
timeEnforcementEnds: queryResult?.time_enforcement_ends && queryResult?.time_enforcement_ends !== '0'
|
|
911
|
-
? new Date(parseInt(queryResult.time_enforcement_ends, 10) * 1000)
|
|
912
|
-
: undefined,
|
|
913
|
-
enforcementType: queryResult?.enforcement_type ?? ReachoutTimelockEnforcementType.DEFAULT
|
|
914
|
-
};
|
|
915
|
-
ev.emit('connection.update', { reachoutTimeLock: result });
|
|
916
|
-
return result;
|
|
917
|
-
};
|
|
918
|
-
/**
|
|
919
|
-
* Fetches your account's new chat limits.
|
|
920
|
-
* @returns Returns the quota and the usage.
|
|
921
|
-
*/
|
|
922
|
-
const fetchNewChatMessageCap = async () => {
|
|
923
|
-
return executeWMexQuery({ input: { type: 'INDIVIDUAL_NEW_CHAT_MSG' } }, QueryIds.MESSAGE_CAPPING_INFO, XWAPaths.xwa2_message_capping_info, query, generateMessageTag);
|
|
924
|
-
};
|
|
581
|
+
if (printQRInTerminal) {
|
|
582
|
+
(0, Utils_1.printQRIfNecessaryListener)(ev, logger);
|
|
583
|
+
}
|
|
925
584
|
return {
|
|
926
585
|
type: 'md',
|
|
927
586
|
ws,
|
|
@@ -939,32 +598,22 @@ export const makeSocket = (config) => {
|
|
|
939
598
|
sendNode,
|
|
940
599
|
logout,
|
|
941
600
|
end,
|
|
942
|
-
registerSocketEndHandler,
|
|
943
601
|
onUnexpectedError,
|
|
944
602
|
uploadPreKeys,
|
|
945
603
|
uploadPreKeysToServerIfRequired,
|
|
946
|
-
digestKeyBundle,
|
|
947
|
-
rotateSignedPreKey,
|
|
948
604
|
requestPairingCode,
|
|
949
|
-
updateServerTimeOffset,
|
|
950
|
-
sendUnifiedSession,
|
|
951
|
-
wamBuffer: publicWAMBuffer,
|
|
952
605
|
/** Waits for the connection to WA to reach a state */
|
|
953
|
-
waitForConnectionUpdate: bindWaitForConnectionUpdate(ev),
|
|
606
|
+
waitForConnectionUpdate: (0, Utils_1.bindWaitForConnectionUpdate)(ev),
|
|
954
607
|
sendWAMBuffer,
|
|
955
|
-
executeUSyncQuery,
|
|
956
|
-
onWhatsApp,
|
|
957
|
-
fetchAccountReachoutTimelock,
|
|
958
|
-
fetchNewChatMessageCap
|
|
959
608
|
};
|
|
960
609
|
};
|
|
610
|
+
exports.makeSocket = makeSocket;
|
|
961
611
|
/**
|
|
962
612
|
* map the websocket error to the right type
|
|
963
613
|
* so it can be retried by the caller
|
|
964
614
|
* */
|
|
965
615
|
function mapWebSocketError(handler) {
|
|
966
616
|
return (error) => {
|
|
967
|
-
handler(new Boom(`WebSocket Error (${error
|
|
617
|
+
handler(new boom_1.Boom(`WebSocket Error (${error === null || error === void 0 ? void 0 : error.message})`, { statusCode: (0, Utils_1.getCodeFromWSError)(error), data: error }));
|
|
968
618
|
};
|
|
969
619
|
}
|
|
970
|
-
//# sourceMappingURL=socket.js.map
|