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