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