@eduh_dev021/baileys 0.0.0-stage → 1.0.0
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 +23 -0
- package/README.md +495 -2
- package/WAProto/index.d.ts +22220 -0
- package/WAProto/index.js +5 -0
- package/cjs/WAProto/index.d.ts +22220 -0
- package/cjs/WAProto/index.js +60125 -0
- package/cjs/engine-requirements.js +12 -0
- package/cjs/lib/Addon/http-error.d.ts +18 -0
- package/cjs/lib/Addon/http-error.js +66 -0
- package/cjs/lib/Addon/index.d.ts +3 -0
- package/cjs/lib/Addon/index.js +50 -0
- package/cjs/lib/Addon/keyed-db.d.ts +14 -0
- package/cjs/lib/Addon/keyed-db.js +264 -0
- package/cjs/lib/Addon/link-preview.d.ts +15 -0
- package/cjs/lib/Addon/link-preview.js +104 -0
- package/cjs/lib/Defaults/index.d.ts +184 -0
- package/cjs/lib/Defaults/index.js +292 -0
- package/cjs/lib/Signal/Group/ciphertext-message.d.ts +9 -0
- package/cjs/lib/Signal/Group/ciphertext-message.js +37 -0
- package/cjs/lib/Signal/Group/group-cipher.d.ts +10 -0
- package/cjs/lib/Signal/Group/group-cipher.js +105 -0
- package/cjs/lib/Signal/Group/group-session-builder.d.ts +7 -0
- package/cjs/lib/Signal/Group/group-session-builder.js +65 -0
- package/cjs/lib/Signal/Group/index.d.ts +11 -0
- package/cjs/lib/Signal/Group/index.js +67 -0
- package/cjs/lib/Signal/Group/keyhelper.d.ts +6 -0
- package/cjs/lib/Signal/Group/keyhelper.js +47 -0
- package/cjs/lib/Signal/Group/sender-chain-key.d.ts +13 -0
- package/cjs/lib/Signal/Group/sender-chain-key.js +51 -0
- package/cjs/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
- package/cjs/lib/Signal/Group/sender-key-distribution-message.js +80 -0
- package/cjs/lib/Signal/Group/sender-key-message.d.ts +18 -0
- package/cjs/lib/Signal/Group/sender-key-message.js +87 -0
- package/cjs/lib/Signal/Group/sender-key-name.d.ts +11 -0
- package/cjs/lib/Signal/Group/sender-key-name.js +73 -0
- package/cjs/lib/Signal/Group/sender-key-record.d.ts +12 -0
- package/cjs/lib/Signal/Group/sender-key-record.js +66 -0
- package/cjs/lib/Signal/Group/sender-key-state.d.ts +16 -0
- package/cjs/lib/Signal/Group/sender-key-state.js +106 -0
- package/cjs/lib/Signal/Group/sender-message-key.d.ts +11 -0
- package/cjs/lib/Signal/Group/sender-message-key.js +51 -0
- package/cjs/lib/Signal/libsignal.d.ts +54 -0
- package/cjs/lib/Signal/libsignal.js +421 -0
- package/cjs/lib/Signal/lid-mapping.d.ts +20 -0
- package/cjs/lib/Signal/lid-mapping.js +292 -0
- package/cjs/lib/Socket/Client/index.d.ts +2 -0
- package/cjs/lib/Socket/Client/index.js +23 -0
- package/cjs/lib/Socket/Client/types.d.ts +5 -0
- package/cjs/lib/Socket/Client/types.js +36 -0
- package/cjs/lib/Socket/Client/websocket.d.ts +12 -0
- package/cjs/lib/Socket/Client/websocket.js +143 -0
- package/cjs/lib/Socket/business.d.ts +387 -0
- package/cjs/lib/Socket/business.js +402 -0
- package/cjs/lib/Socket/chats.d.ts +144 -0
- package/cjs/lib/Socket/chats.js +1118 -0
- package/cjs/lib/Socket/communities.d.ts +554 -0
- package/cjs/lib/Socket/communities.js +456 -0
- package/cjs/lib/Socket/groups.d.ts +286 -0
- package/cjs/lib/Socket/groups.js +366 -0
- package/cjs/lib/Socket/index.d.ts +522 -0
- package/cjs/lib/Socket/index.js +32 -0
- package/cjs/lib/Socket/messages-recv.d.ts +326 -0
- package/cjs/lib/Socket/messages-recv.js +1670 -0
- package/cjs/lib/Socket/messages-send.d.ts +321 -0
- package/cjs/lib/Socket/messages-send.js +1252 -0
- package/cjs/lib/Socket/mex.d.ts +1 -0
- package/cjs/lib/Socket/mex.js +65 -0
- package/cjs/lib/Socket/newsletter.d.ts +283 -0
- package/cjs/lib/Socket/newsletter.js +243 -0
- package/cjs/lib/Socket/socket.d.ts +61 -0
- package/cjs/lib/Socket/socket.js +908 -0
- package/cjs/lib/Store/index.d.ts +3 -0
- package/cjs/lib/Store/index.js +25 -0
- package/cjs/lib/Store/make-in-memory-store.d.ts +63 -0
- package/cjs/lib/Store/make-in-memory-store.js +431 -0
- package/cjs/lib/Store/make-ordered-dictionary.d.ts +12 -0
- package/cjs/lib/Store/make-ordered-dictionary.js +101 -0
- package/cjs/lib/Store/object-repository.d.ts +10 -0
- package/cjs/lib/Store/object-repository.js +49 -0
- package/cjs/lib/Transport/crypto.d.ts +6 -0
- package/cjs/lib/Transport/crypto.js +107 -0
- package/cjs/lib/Transport/curve.d.ts +8 -0
- package/cjs/lib/Transport/curve.js +94 -0
- package/cjs/lib/Transport/index.d.ts +16 -0
- package/cjs/lib/Transport/index.js +67 -0
- package/cjs/lib/Transport/internals.d.ts +57 -0
- package/cjs/lib/Transport/internals.js +203 -0
- package/cjs/lib/Transport/session-builder.d.ts +40 -0
- package/cjs/lib/Transport/session-builder.js +169 -0
- package/cjs/lib/Transport/session-cipher.d.ts +26 -0
- package/cjs/lib/Transport/session-cipher.js +328 -0
- package/cjs/lib/Transport/session-record.d.ts +55 -0
- package/cjs/lib/Transport/session-record.js +289 -0
- package/cjs/lib/Types/Auth.d.ts +1 -0
- package/cjs/lib/Types/Auth.js +15 -0
- package/cjs/lib/Types/Bussines.d.ts +1 -0
- package/cjs/lib/Types/Bussines.js +15 -0
- package/cjs/lib/Types/Call.d.ts +1 -0
- package/cjs/lib/Types/Call.js +15 -0
- package/cjs/lib/Types/Chat.d.ts +1 -0
- package/cjs/lib/Types/Chat.js +33 -0
- package/cjs/lib/Types/Contact.d.ts +1 -0
- package/cjs/lib/Types/Contact.js +15 -0
- package/cjs/lib/Types/Events.d.ts +1 -0
- package/cjs/lib/Types/Events.js +1 -0
- package/cjs/lib/Types/GroupMetadata.d.ts +1 -0
- package/cjs/lib/Types/GroupMetadata.js +15 -0
- package/cjs/lib/Types/Label.d.ts +2 -0
- package/cjs/lib/Types/Label.js +49 -0
- package/cjs/lib/Types/LabelAssociation.d.ts +2 -0
- package/cjs/lib/Types/LabelAssociation.js +31 -0
- package/cjs/lib/Types/Message.d.ts +11 -0
- package/cjs/lib/Types/Message.js +58 -0
- package/cjs/lib/Types/Mex.d.ts +2 -0
- package/cjs/lib/Types/Mex.js +66 -0
- package/cjs/lib/Types/Product.d.ts +1 -0
- package/cjs/lib/Types/Product.js +15 -0
- package/cjs/lib/Types/RichType.d.ts +2 -0
- package/cjs/lib/Types/RichType.js +50 -0
- package/cjs/lib/Types/Signal.d.ts +1 -0
- package/cjs/lib/Types/Signal.js +1 -0
- package/cjs/lib/Types/Socket.d.ts +1 -0
- package/cjs/lib/Types/Socket.js +1 -0
- package/cjs/lib/Types/State.d.ts +5 -0
- package/cjs/lib/Types/State.js +83 -0
- package/cjs/lib/Types/USync.d.ts +1 -0
- package/cjs/lib/Types/USync.js +1 -0
- package/cjs/lib/Types/index.d.ts +13 -0
- package/cjs/lib/Types/index.js +64 -0
- package/cjs/lib/Utils/auth-utils.d.ts +58 -0
- package/cjs/lib/Utils/auth-utils.js +275 -0
- package/cjs/lib/Utils/browser-utils.d.ts +9 -0
- package/cjs/lib/Utils/browser-utils.js +56 -0
- package/cjs/lib/Utils/business.d.ts +49 -0
- package/cjs/lib/Utils/business.js +259 -0
- package/cjs/lib/Utils/chat-utils.d.ts +408 -0
- package/cjs/lib/Utils/chat-utils.js +821 -0
- package/cjs/lib/Utils/companion-reg-client-utils.d.ts +4 -0
- package/cjs/lib/Utils/companion-reg-client-utils.js +71 -0
- package/cjs/lib/Utils/crypto.d.ts +39 -0
- package/cjs/lib/Utils/crypto.js +155 -0
- package/cjs/lib/Utils/decode-wa-message.d.ts +83 -0
- package/cjs/lib/Utils/decode-wa-message.js +316 -0
- package/cjs/lib/Utils/event-buffer.d.ts +12 -0
- package/cjs/lib/Utils/event-buffer.js +605 -0
- package/cjs/lib/Utils/generics.d.ts +63 -0
- package/cjs/lib/Utils/generics.js +440 -0
- package/cjs/lib/Utils/history.d.ts +75 -0
- package/cjs/lib/Utils/history.js +153 -0
- package/cjs/lib/Utils/identity-change-handler.d.ts +13 -0
- package/cjs/lib/Utils/identity-change-handler.js +73 -0
- package/cjs/lib/Utils/index.d.ts +24 -0
- package/cjs/lib/Utils/index.js +67 -0
- package/cjs/lib/Utils/link-preview.d.ts +13 -0
- package/cjs/lib/Utils/link-preview.js +87 -0
- package/cjs/lib/Utils/logger.d.ts +12 -0
- package/cjs/lib/Utils/logger.js +40 -0
- package/cjs/lib/Utils/lt-hash.d.ts +6 -0
- package/cjs/lib/Utils/lt-hash.js +28 -0
- package/cjs/lib/Utils/make-mutex.d.ts +6 -0
- package/cjs/lib/Utils/make-mutex.js +58 -0
- package/cjs/lib/Utils/message-retry-manager.d.ts +79 -0
- package/cjs/lib/Utils/message-retry-manager.js +274 -0
- package/cjs/lib/Utils/messages-media.d.ts +134 -0
- package/cjs/lib/Utils/messages-media.js +799 -0
- package/cjs/lib/Utils/messages.d.ts +47 -0
- package/cjs/lib/Utils/messages.js +1667 -0
- package/cjs/lib/Utils/noise-handler.d.ts +20 -0
- package/cjs/lib/Utils/noise-handler.js +223 -0
- package/cjs/lib/Utils/offline-node-processor.d.ts +10 -0
- package/cjs/lib/Utils/offline-node-processor.js +60 -0
- package/cjs/lib/Utils/pre-key-manager.d.ts +25 -0
- package/cjs/lib/Utils/pre-key-manager.js +116 -0
- package/cjs/lib/Utils/process-message.d.ts +83 -0
- package/cjs/lib/Utils/process-message.js +607 -0
- package/cjs/lib/Utils/reporting-utils.d.ts +12 -0
- package/cjs/lib/Utils/reporting-utils.js +282 -0
- package/cjs/lib/Utils/rich-message-utils.d.ts +48 -0
- package/cjs/lib/Utils/rich-message-utils.js +381 -0
- package/cjs/lib/Utils/signal.d.ts +82 -0
- package/cjs/lib/Utils/signal.js +232 -0
- package/cjs/lib/Utils/stanza-ack.d.ts +16 -0
- package/cjs/lib/Utils/stanza-ack.js +53 -0
- package/cjs/lib/Utils/sync-action-utils.d.ts +2 -0
- package/cjs/lib/Utils/sync-action-utils.js +68 -0
- package/cjs/lib/Utils/tc-token-utils.d.ts +29 -0
- package/cjs/lib/Utils/tc-token-utils.js +182 -0
- package/cjs/lib/Utils/use-multi-file-auth-state.d.ts +10 -0
- package/cjs/lib/Utils/use-multi-file-auth-state.js +135 -0
- package/cjs/lib/Utils/use-single-file-auth-state.d.ts +11 -0
- package/cjs/lib/Utils/use-single-file-auth-state.js +115 -0
- package/cjs/lib/Utils/use-sqlite-auth-state.d.ts +11 -0
- package/cjs/lib/Utils/use-sqlite-auth-state.js +140 -0
- package/cjs/lib/Utils/validate-connection.d.ts +44 -0
- package/cjs/lib/Utils/validate-connection.js +229 -0
- package/cjs/lib/WABinary/constants.d.ts +61 -0
- package/cjs/lib/WABinary/constants.js +1992 -0
- package/cjs/lib/WABinary/decode.d.ts +9 -0
- package/cjs/lib/WABinary/decode.js +292 -0
- package/cjs/lib/WABinary/encode.d.ts +2 -0
- package/cjs/lib/WABinary/encode.js +240 -0
- package/cjs/lib/WABinary/generic-utils.d.ts +79 -0
- package/cjs/lib/WABinary/generic-utils.js +252 -0
- package/cjs/lib/WABinary/index.d.ts +5 -0
- package/cjs/lib/WABinary/index.js +29 -0
- package/cjs/lib/WABinary/jid-utils.d.ts +28 -0
- package/cjs/lib/WABinary/jid-utils.js +151 -0
- package/cjs/lib/WABinary/types.d.ts +1 -0
- package/cjs/lib/WABinary/types.js +23 -0
- package/cjs/lib/WACrypto/appstate-keys.js +39 -0
- package/cjs/lib/WACrypto/curves/constants.js +37 -0
- package/cjs/lib/WACrypto/hkdf.js +38 -0
- package/cjs/lib/WACrypto/index.js +51 -0
- package/cjs/lib/WACrypto/lthash.js +59 -0
- package/cjs/lib/WACrypto/math/constants.js +53 -0
- package/cjs/lib/WACrypto/math/edwards.js +206 -0
- package/cjs/lib/WACrypto/math/fe.js +449 -0
- package/cjs/lib/WACrypto/math/le.js +44 -0
- package/cjs/lib/WACrypto/math/mod.js +36 -0
- package/cjs/lib/WACrypto/util/bytes.js +348 -0
- package/cjs/lib/WACrypto/x25519.js +157 -0
- package/cjs/lib/WACrypto/xeddsa.js +134 -0
- package/cjs/lib/WAM/BinaryInfo.d.ts +7 -0
- package/cjs/lib/WAM/BinaryInfo.js +35 -0
- package/cjs/lib/WAM/constants.d.ts +34926 -0
- package/cjs/lib/WAM/constants.js +22890 -0
- package/cjs/lib/WAM/encode.d.ts +1 -0
- package/cjs/lib/WAM/encode.js +162 -0
- package/cjs/lib/WAM/index.d.ts +3 -0
- package/cjs/lib/WAM/index.js +25 -0
- package/cjs/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +36 -0
- package/cjs/lib/WAUSync/Protocols/USyncContactProtocol.js +77 -0
- package/cjs/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
- package/cjs/lib/WAUSync/Protocols/USyncDeviceProtocol.js +76 -0
- package/cjs/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
- package/cjs/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +52 -0
- package/cjs/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
- package/cjs/lib/WAUSync/Protocols/USyncStatusProtocol.js +61 -0
- package/cjs/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +9 -0
- package/cjs/lib/WAUSync/Protocols/USyncUsernameProtocol.js +50 -0
- package/cjs/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +38 -0
- package/cjs/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +76 -0
- package/cjs/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +14 -0
- package/cjs/lib/WAUSync/Protocols/UsyncLIDProtocol.js +53 -0
- package/cjs/lib/WAUSync/Protocols/index.d.ts +5 -0
- package/cjs/lib/WAUSync/Protocols/index.js +29 -0
- package/cjs/lib/WAUSync/USyncQuery.d.ts +20 -0
- package/cjs/lib/WAUSync/USyncQuery.js +113 -0
- package/cjs/lib/WAUSync/USyncUser.d.ts +16 -0
- package/cjs/lib/WAUSync/USyncUser.js +56 -0
- package/cjs/lib/WAUSync/index.d.ts +3 -0
- package/cjs/lib/WAUSync/index.js +25 -0
- package/cjs/lib/index.d.ts +11 -0
- package/cjs/lib/index.js +56 -0
- package/cjs/package.json +3 -0
- package/engine-requirements.js +12 -0
- package/lib/Addon/http-error.d.ts +18 -0
- package/lib/Addon/http-error.js +40 -0
- package/lib/Addon/index.d.ts +3 -0
- package/lib/Addon/index.js +4 -0
- package/lib/Addon/keyed-db.d.ts +14 -0
- package/lib/Addon/keyed-db.js +241 -0
- package/lib/Addon/link-preview.d.ts +15 -0
- package/lib/Addon/link-preview.js +79 -0
- package/lib/Defaults/index.d.ts +184 -0
- package/lib/Defaults/index.js +181 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
- package/lib/Signal/Group/ciphertext-message.js +11 -0
- package/lib/Signal/Group/group-cipher.d.ts +10 -0
- package/lib/Signal/Group/group-cipher.js +81 -0
- package/lib/Signal/Group/group-session-builder.d.ts +7 -0
- package/lib/Signal/Group/group-session-builder.js +29 -0
- package/lib/Signal/Group/index.d.ts +11 -0
- package/lib/Signal/Group/index.js +11 -0
- package/lib/Signal/Group/keyhelper.d.ts +6 -0
- package/lib/Signal/Group/keyhelper.js +17 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
- package/lib/Signal/Group/sender-chain-key.js +25 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +62 -0
- package/lib/Signal/Group/sender-key-message.d.ts +18 -0
- package/lib/Signal/Group/sender-key-message.js +65 -0
- package/lib/Signal/Group/sender-key-name.d.ts +11 -0
- package/lib/Signal/Group/sender-key-name.js +47 -0
- package/lib/Signal/Group/sender-key-record.d.ts +12 -0
- package/lib/Signal/Group/sender-key-record.js +40 -0
- package/lib/Signal/Group/sender-key-state.d.ts +16 -0
- package/lib/Signal/Group/sender-key-state.js +83 -0
- package/lib/Signal/Group/sender-message-key.d.ts +11 -0
- package/lib/Signal/Group/sender-message-key.js +25 -0
- package/lib/Signal/libsignal.d.ts +54 -0
- package/lib/Signal/libsignal.js +426 -0
- package/lib/Signal/lid-mapping.d.ts +20 -0
- package/lib/Signal/lid-mapping.js +274 -0
- package/lib/Socket/Client/index.d.ts +2 -0
- package/lib/Socket/Client/index.js +2 -0
- package/lib/Socket/Client/types.d.ts +5 -0
- package/lib/Socket/Client/types.js +10 -0
- package/lib/Socket/Client/websocket.d.ts +12 -0
- package/lib/Socket/Client/websocket.js +119 -0
- package/lib/Socket/business.d.ts +387 -0
- package/lib/Socket/business.js +379 -0
- package/lib/Socket/chats.d.ts +144 -0
- package/lib/Socket/chats.js +1216 -0
- package/lib/Socket/communities.d.ts +554 -0
- package/lib/Socket/communities.js +431 -0
- package/lib/Socket/groups.d.ts +286 -0
- package/lib/Socket/groups.js +347 -0
- package/lib/Socket/index.d.ts +522 -0
- package/lib/Socket/index.js +11 -0
- package/lib/Socket/messages-recv.d.ts +326 -0
- package/lib/Socket/messages-recv.js +1822 -0
- package/lib/Socket/messages-send.d.ts +321 -0
- package/lib/Socket/messages-send.js +1378 -0
- package/lib/Socket/mex.d.ts +1 -0
- package/lib/Socket/mex.js +41 -0
- package/lib/Socket/newsletter.d.ts +283 -0
- package/lib/Socket/newsletter.js +225 -0
- package/lib/Socket/socket.d.ts +61 -0
- package/lib/Socket/socket.js +992 -0
- package/lib/Store/index.d.ts +3 -0
- package/lib/Store/index.js +3 -0
- package/lib/Store/make-in-memory-store.d.ts +63 -0
- package/lib/Store/make-in-memory-store.js +419 -0
- package/lib/Store/make-ordered-dictionary.d.ts +12 -0
- package/lib/Store/make-ordered-dictionary.js +78 -0
- package/lib/Store/object-repository.d.ts +10 -0
- package/lib/Store/object-repository.js +23 -0
- package/lib/Transport/crypto.d.ts +6 -0
- package/lib/Transport/crypto.js +61 -0
- package/lib/Transport/curve.d.ts +8 -0
- package/lib/Transport/curve.js +66 -0
- package/lib/Transport/index.d.ts +16 -0
- package/lib/Transport/index.js +9 -0
- package/lib/Transport/internals.d.ts +57 -0
- package/lib/Transport/internals.js +155 -0
- package/lib/Transport/session-builder.d.ts +40 -0
- package/lib/Transport/session-builder.js +143 -0
- package/lib/Transport/session-cipher.d.ts +26 -0
- package/lib/Transport/session-cipher.js +301 -0
- package/lib/Transport/session-record.d.ts +55 -0
- package/lib/Transport/session-record.js +272 -0
- package/lib/Types/Auth.d.ts +1 -0
- package/lib/Types/Auth.js +1 -0
- package/lib/Types/Bussines.d.ts +1 -0
- package/lib/Types/Bussines.js +1 -0
- package/lib/Types/Call.d.ts +1 -0
- package/lib/Types/Call.js +1 -0
- package/lib/Types/Chat.d.ts +1 -0
- package/lib/Types/Chat.js +7 -0
- package/lib/Types/Contact.d.ts +1 -0
- package/lib/Types/Contact.js +1 -0
- package/lib/Types/Events.d.ts +1 -0
- package/lib/Types/Events.js +1 -0
- package/lib/Types/GroupMetadata.d.ts +1 -0
- package/lib/Types/GroupMetadata.js +1 -0
- package/lib/Types/Label.d.ts +2 -0
- package/lib/Types/Label.js +24 -0
- package/lib/Types/LabelAssociation.d.ts +2 -0
- package/lib/Types/LabelAssociation.js +6 -0
- package/lib/Types/Message.d.ts +11 -0
- package/lib/Types/Message.js +17 -0
- package/lib/Types/Mex.d.ts +2 -0
- package/lib/Types/Mex.js +38 -0
- package/lib/Types/Product.d.ts +1 -0
- package/lib/Types/Product.js +1 -0
- package/lib/Types/RichType.d.ts +2 -0
- package/lib/Types/RichType.js +22 -0
- package/lib/Types/Signal.d.ts +1 -0
- package/lib/Types/Signal.js +1 -0
- package/lib/Types/Socket.d.ts +1 -0
- package/lib/Types/Socket.js +1 -0
- package/lib/Types/State.d.ts +5 -0
- package/lib/Types/State.js +54 -0
- package/lib/Types/USync.d.ts +1 -0
- package/lib/Types/USync.js +1 -0
- package/lib/Types/index.d.ts +13 -0
- package/lib/Types/index.js +25 -0
- package/lib/Utils/auth-utils.d.ts +58 -0
- package/lib/Utils/auth-utils.js +316 -0
- package/lib/Utils/browser-utils.d.ts +9 -0
- package/lib/Utils/browser-utils.js +28 -0
- package/lib/Utils/business.d.ts +49 -0
- package/lib/Utils/business.js +230 -0
- package/lib/Utils/chat-utils.d.ts +408 -0
- package/lib/Utils/chat-utils.js +871 -0
- package/lib/Utils/companion-reg-client-utils.d.ts +4 -0
- package/lib/Utils/companion-reg-client-utils.js +39 -0
- package/lib/Utils/crypto.d.ts +39 -0
- package/lib/Utils/crypto.js +117 -0
- package/lib/Utils/decode-wa-message.d.ts +83 -0
- package/lib/Utils/decode-wa-message.js +316 -0
- package/lib/Utils/event-buffer.d.ts +12 -0
- package/lib/Utils/event-buffer.js +621 -0
- package/lib/Utils/generics.d.ts +63 -0
- package/lib/Utils/generics.js +394 -0
- package/lib/Utils/history.d.ts +75 -0
- package/lib/Utils/history.js +133 -0
- package/lib/Utils/identity-change-handler.d.ts +13 -0
- package/lib/Utils/identity-change-handler.js +48 -0
- package/lib/Utils/index.d.ts +24 -0
- package/lib/Utils/index.js +24 -0
- package/lib/Utils/link-preview.d.ts +13 -0
- package/lib/Utils/link-preview.js +73 -0
- package/lib/Utils/logger.d.ts +12 -0
- package/lib/Utils/logger.js +12 -0
- package/lib/Utils/lt-hash.d.ts +6 -0
- package/lib/Utils/lt-hash.js +7 -0
- package/lib/Utils/make-mutex.d.ts +6 -0
- package/lib/Utils/make-mutex.js +32 -0
- package/lib/Utils/message-retry-manager.d.ts +79 -0
- package/lib/Utils/message-retry-manager.js +259 -0
- package/lib/Utils/messages-media.d.ts +134 -0
- package/lib/Utils/messages-media.js +802 -0
- package/lib/Utils/messages.d.ts +47 -0
- package/lib/Utils/messages.js +1911 -0
- package/lib/Utils/noise-handler.d.ts +20 -0
- package/lib/Utils/noise-handler.js +200 -0
- package/lib/Utils/offline-node-processor.d.ts +10 -0
- package/lib/Utils/offline-node-processor.js +40 -0
- package/lib/Utils/pre-key-manager.d.ts +25 -0
- package/lib/Utils/pre-key-manager.js +105 -0
- package/lib/Utils/process-message.d.ts +83 -0
- package/lib/Utils/process-message.js +748 -0
- package/lib/Utils/reporting-utils.d.ts +12 -0
- package/lib/Utils/reporting-utils.js +257 -0
- package/lib/Utils/rich-message-utils.d.ts +48 -0
- package/lib/Utils/rich-message-utils.js +369 -0
- package/lib/Utils/signal.d.ts +82 -0
- package/lib/Utils/signal.js +200 -0
- package/lib/Utils/stanza-ack.d.ts +16 -0
- package/lib/Utils/stanza-ack.js +37 -0
- package/lib/Utils/sync-action-utils.d.ts +2 -0
- package/lib/Utils/sync-action-utils.js +48 -0
- package/lib/Utils/tc-token-utils.d.ts +29 -0
- package/lib/Utils/tc-token-utils.js +163 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +10 -0
- package/lib/Utils/use-multi-file-auth-state.js +116 -0
- package/lib/Utils/use-single-file-auth-state.d.ts +11 -0
- package/lib/Utils/use-single-file-auth-state.js +94 -0
- package/lib/Utils/use-sqlite-auth-state.d.ts +11 -0
- package/lib/Utils/use-sqlite-auth-state.js +109 -0
- package/lib/Utils/validate-connection.d.ts +44 -0
- package/lib/Utils/validate-connection.js +210 -0
- package/lib/WABinary/constants.d.ts +61 -0
- package/lib/WABinary/constants.js +1466 -0
- package/lib/WABinary/decode.d.ts +9 -0
- package/lib/WABinary/decode.js +261 -0
- package/lib/WABinary/encode.d.ts +2 -0
- package/lib/WABinary/encode.js +219 -0
- package/lib/WABinary/generic-utils.d.ts +79 -0
- package/lib/WABinary/generic-utils.js +228 -0
- package/lib/WABinary/index.d.ts +5 -0
- package/lib/WABinary/index.js +5 -0
- package/lib/WABinary/jid-utils.d.ts +28 -0
- package/lib/WABinary/jid-utils.js +95 -0
- package/lib/WABinary/types.d.ts +1 -0
- package/lib/WABinary/types.js +1 -0
- package/lib/WACrypto/appstate-keys.js +26 -0
- package/lib/WACrypto/curves/constants.js +12 -0
- package/lib/WACrypto/hkdf.js +27 -0
- package/lib/WACrypto/index.js +20 -0
- package/lib/WACrypto/lthash.js +54 -0
- package/lib/WACrypto/math/constants.js +24 -0
- package/lib/WACrypto/math/edwards.js +194 -0
- package/lib/WACrypto/math/fe.js +698 -0
- package/lib/WACrypto/math/le.js +23 -0
- package/lib/WACrypto/math/mod.js +15 -0
- package/lib/WACrypto/util/bytes.js +339 -0
- package/lib/WACrypto/x25519.js +145 -0
- package/lib/WACrypto/xeddsa.js +92 -0
- package/lib/WAM/BinaryInfo.d.ts +7 -0
- package/lib/WAM/BinaryInfo.js +9 -0
- package/lib/WAM/constants.d.ts +34926 -0
- package/lib/WAM/constants.js +22852 -0
- package/lib/WAM/encode.d.ts +1 -0
- package/lib/WAM/encode.js +149 -0
- package/lib/WAM/index.d.ts +3 -0
- package/lib/WAM/index.js +3 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +36 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +51 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +53 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +26 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +37 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +9 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +24 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +38 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +14 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +28 -0
- package/lib/WAUSync/Protocols/index.d.ts +5 -0
- package/lib/WAUSync/Protocols/index.js +5 -0
- package/lib/WAUSync/USyncQuery.d.ts +20 -0
- package/lib/WAUSync/USyncQuery.js +97 -0
- package/lib/WAUSync/USyncUser.d.ts +16 -0
- package/lib/WAUSync/USyncUser.js +30 -0
- package/lib/WAUSync/index.d.ts +3 -0
- package/lib/WAUSync/index.js +3 -0
- package/lib/index.d.ts +11 -0
- package/lib/index.js +11 -0
- package/package.json +79 -5
|
@@ -0,0 +1,1118 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var chats_exports = {};
|
|
29
|
+
__export(chats_exports, {
|
|
30
|
+
buildProfilePictureQueryContent: () => buildProfilePictureQueryContent,
|
|
31
|
+
makeChatsSocket: () => makeChatsSocket
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(chats_exports);
|
|
34
|
+
var import_WAProto = require("../../WAProto/index.js");
|
|
35
|
+
var import_Addon = require("../Addon/index.js");
|
|
36
|
+
var import_Defaults = require("../Defaults/index.js");
|
|
37
|
+
var import_Types = require("../Types/index.js");
|
|
38
|
+
var import_State = require("../Types/State.js");
|
|
39
|
+
var import_Utils = require("../Utils/index.js");
|
|
40
|
+
var import_make_mutex = require("../Utils/make-mutex.js");
|
|
41
|
+
var import_process_message = __toESM(require("../Utils/process-message.js"));
|
|
42
|
+
var import_tc_token_utils = require("../Utils/tc-token-utils.js");
|
|
43
|
+
var import_WABinary = require("../WABinary/index.js");
|
|
44
|
+
var import_WAUSync = require("../WAUSync/index.js");
|
|
45
|
+
var import_socket = require("./socket.js");
|
|
46
|
+
const buildProfilePictureQueryContent = (type, tcTokenContent) => {
|
|
47
|
+
const picture = { tag: "picture", attrs: { type, query: "url" } };
|
|
48
|
+
if (tcTokenContent?.length) {
|
|
49
|
+
picture.content = tcTokenContent;
|
|
50
|
+
}
|
|
51
|
+
return [picture];
|
|
52
|
+
};
|
|
53
|
+
const makeChatsSocket = (config) => {
|
|
54
|
+
const { logger, markOnlineOnConnect, fireInitQueries, appStateMacVerification, shouldIgnoreJid, shouldSyncHistoryMessage, getMessage } = config;
|
|
55
|
+
const sock = (0, import_socket.makeSocket)(config);
|
|
56
|
+
const { ev, ws, authState, generateMessageTag, sendNode, query, signalRepository, onUnexpectedError, sendUnifiedSession, registerSocketEndHandler } = sock;
|
|
57
|
+
const getLIDForPN = signalRepository.lidMapping.getLIDForPN.bind(signalRepository.lidMapping);
|
|
58
|
+
let privacySettings;
|
|
59
|
+
const serverProps = {
|
|
60
|
+
/** AB prop 10518: gate tctoken on 1:1 messages. Default true (safe: avoids 463). */
|
|
61
|
+
privacyTokenOn1to1: true,
|
|
62
|
+
/** AB prop 9666: gate tctoken on profile picture IQs. WA Web default: true. */
|
|
63
|
+
profilePicPrivacyToken: true,
|
|
64
|
+
/** AB prop 14303: issue tctokens to LID instead of PN. WA Web default: false. */
|
|
65
|
+
lidTrustedTokenIssueToLid: false
|
|
66
|
+
};
|
|
67
|
+
let syncState = import_State.SyncState.Connecting;
|
|
68
|
+
const messageMutex = (0, import_make_mutex.makeMutex)();
|
|
69
|
+
const receiptMutex = (0, import_make_mutex.makeMutex)();
|
|
70
|
+
const appStatePatchMutex = (0, import_make_mutex.makeMutex)();
|
|
71
|
+
const notificationMutex = (0, import_make_mutex.makeMutex)();
|
|
72
|
+
let awaitingSyncTimeout;
|
|
73
|
+
const historySyncStatus = {
|
|
74
|
+
initialBootstrapComplete: false,
|
|
75
|
+
recentSyncComplete: false
|
|
76
|
+
};
|
|
77
|
+
let historySyncPausedTimeout;
|
|
78
|
+
const blockedCollections = /* @__PURE__ */ new Set();
|
|
79
|
+
const placeholderResendCache = config.placeholderResendCache || (0, import_Addon.createCache)({
|
|
80
|
+
ttl: import_Defaults.DEFAULT_CACHE_TTLS.MSG_RETRY
|
|
81
|
+
// 1 hour
|
|
82
|
+
});
|
|
83
|
+
const getAppStateSyncKey = async (keyId) => {
|
|
84
|
+
const { [keyId]: key } = await authState.keys.get("app-state-sync-key", [keyId]);
|
|
85
|
+
return key;
|
|
86
|
+
};
|
|
87
|
+
const fetchPrivacySettings = async (force = false) => {
|
|
88
|
+
if (!privacySettings || force) {
|
|
89
|
+
const { content } = await query({
|
|
90
|
+
tag: "iq",
|
|
91
|
+
attrs: {
|
|
92
|
+
xmlns: "privacy",
|
|
93
|
+
to: import_WABinary.S_WHATSAPP_NET,
|
|
94
|
+
type: "get"
|
|
95
|
+
},
|
|
96
|
+
content: [{ tag: "privacy", attrs: {} }]
|
|
97
|
+
});
|
|
98
|
+
privacySettings = (0, import_WABinary.reduceBinaryNodeToDictionary)(content?.[0], "category");
|
|
99
|
+
}
|
|
100
|
+
return privacySettings;
|
|
101
|
+
};
|
|
102
|
+
const privacyQuery = async (name, value) => {
|
|
103
|
+
await query({
|
|
104
|
+
tag: "iq",
|
|
105
|
+
attrs: {
|
|
106
|
+
xmlns: "privacy",
|
|
107
|
+
to: import_WABinary.S_WHATSAPP_NET,
|
|
108
|
+
type: "set"
|
|
109
|
+
},
|
|
110
|
+
content: [
|
|
111
|
+
{
|
|
112
|
+
tag: "privacy",
|
|
113
|
+
attrs: {},
|
|
114
|
+
content: [
|
|
115
|
+
{
|
|
116
|
+
tag: "category",
|
|
117
|
+
attrs: { name, value }
|
|
118
|
+
}
|
|
119
|
+
]
|
|
120
|
+
}
|
|
121
|
+
]
|
|
122
|
+
});
|
|
123
|
+
};
|
|
124
|
+
const updateMessagesPrivacy = async (value) => {
|
|
125
|
+
await privacyQuery("messages", value);
|
|
126
|
+
};
|
|
127
|
+
const updateCallPrivacy = async (value) => {
|
|
128
|
+
await privacyQuery("calladd", value);
|
|
129
|
+
};
|
|
130
|
+
const updateLastSeenPrivacy = async (value) => {
|
|
131
|
+
await privacyQuery("last", value);
|
|
132
|
+
};
|
|
133
|
+
const updateOnlinePrivacy = async (value) => {
|
|
134
|
+
await privacyQuery("online", value);
|
|
135
|
+
};
|
|
136
|
+
const updateProfilePicturePrivacy = async (value) => {
|
|
137
|
+
await privacyQuery("profile", value);
|
|
138
|
+
};
|
|
139
|
+
const updateStatusPrivacy = async (value) => {
|
|
140
|
+
await privacyQuery("status", value);
|
|
141
|
+
};
|
|
142
|
+
const updateReadReceiptsPrivacy = async (value) => {
|
|
143
|
+
await privacyQuery("readreceipts", value);
|
|
144
|
+
};
|
|
145
|
+
const updateGroupsAddPrivacy = async (value) => {
|
|
146
|
+
await privacyQuery("groupadd", value);
|
|
147
|
+
};
|
|
148
|
+
const updateDefaultDisappearingMode = async (duration) => {
|
|
149
|
+
await query({
|
|
150
|
+
tag: "iq",
|
|
151
|
+
attrs: {
|
|
152
|
+
xmlns: "disappearing_mode",
|
|
153
|
+
to: import_WABinary.S_WHATSAPP_NET,
|
|
154
|
+
type: "set"
|
|
155
|
+
},
|
|
156
|
+
content: [
|
|
157
|
+
{
|
|
158
|
+
tag: "disappearing_mode",
|
|
159
|
+
attrs: {
|
|
160
|
+
duration: duration.toString()
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
]
|
|
164
|
+
});
|
|
165
|
+
};
|
|
166
|
+
const getBotListV2 = async () => {
|
|
167
|
+
const resp = await query({
|
|
168
|
+
tag: "iq",
|
|
169
|
+
attrs: {
|
|
170
|
+
xmlns: "bot",
|
|
171
|
+
to: import_WABinary.S_WHATSAPP_NET,
|
|
172
|
+
type: "get"
|
|
173
|
+
},
|
|
174
|
+
content: [
|
|
175
|
+
{
|
|
176
|
+
tag: "bot",
|
|
177
|
+
attrs: {
|
|
178
|
+
v: "2"
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
]
|
|
182
|
+
});
|
|
183
|
+
const botNode = (0, import_WABinary.getBinaryNodeChild)(resp, "bot");
|
|
184
|
+
const botList = [];
|
|
185
|
+
for (const section of (0, import_WABinary.getBinaryNodeChildren)(botNode, "section")) {
|
|
186
|
+
if (section.attrs.type === "all") {
|
|
187
|
+
for (const bot of (0, import_WABinary.getBinaryNodeChildren)(section, "bot")) {
|
|
188
|
+
botList.push({
|
|
189
|
+
jid: bot.attrs.jid,
|
|
190
|
+
personaId: bot.attrs["persona_id"]
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return botList;
|
|
196
|
+
};
|
|
197
|
+
const fetchStatus = async (...jids) => {
|
|
198
|
+
const usyncQuery = new import_WAUSync.USyncQuery().withStatusProtocol();
|
|
199
|
+
for (const jid of jids) {
|
|
200
|
+
usyncQuery.withUser(new import_WAUSync.USyncUser().withId(jid));
|
|
201
|
+
}
|
|
202
|
+
const result = await sock.executeUSyncQuery(usyncQuery);
|
|
203
|
+
if (result) {
|
|
204
|
+
return result.list;
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
const fetchDisappearingDuration = async (...jids) => {
|
|
208
|
+
const usyncQuery = new import_WAUSync.USyncQuery().withDisappearingModeProtocol();
|
|
209
|
+
for (const jid of jids) {
|
|
210
|
+
usyncQuery.withUser(new import_WAUSync.USyncUser().withId(jid));
|
|
211
|
+
}
|
|
212
|
+
const result = await sock.executeUSyncQuery(usyncQuery);
|
|
213
|
+
if (result) {
|
|
214
|
+
return result.list;
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
const findUserId = async (pnLid) => {
|
|
218
|
+
const normalizedJid = (0, import_WABinary.jidNormalizedUser)(pnLid);
|
|
219
|
+
const userId = {
|
|
220
|
+
lid: void 0,
|
|
221
|
+
phoneNumber: void 0
|
|
222
|
+
};
|
|
223
|
+
if ((0, import_WABinary.isPnUser)(normalizedJid) || (0, import_WABinary.isHostedPnUser)(normalizedJid)) {
|
|
224
|
+
userId.phoneNumber = normalizedJid;
|
|
225
|
+
userId.lid = (0, import_WABinary.jidNormalizedUser)((await signalRepository.lidMapping.getLIDsForPNs([normalizedJid]))?.[0]?.lid);
|
|
226
|
+
} else if ((0, import_WABinary.isLidUser)(normalizedJid) || (0, import_WABinary.isHostedLidUser)(normalizedJid)) {
|
|
227
|
+
userId.lid = normalizedJid;
|
|
228
|
+
userId.phoneNumber = (0, import_WABinary.jidNormalizedUser)((await signalRepository.lidMapping.getPNsForLIDs([normalizedJid]))?.[0]?.pn);
|
|
229
|
+
} else {
|
|
230
|
+
throw new import_Addon.HttpError("Invalid id input to find user ids", { statusCode: 400 });
|
|
231
|
+
}
|
|
232
|
+
return userId;
|
|
233
|
+
};
|
|
234
|
+
const updateProfilePicture = async (jid, content, dimensions) => {
|
|
235
|
+
let targetJid;
|
|
236
|
+
if (!jid) {
|
|
237
|
+
throw new import_Addon.HttpError("Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update");
|
|
238
|
+
}
|
|
239
|
+
if ((0, import_WABinary.jidNormalizedUser)(jid) !== (0, import_WABinary.jidNormalizedUser)(authState.creds.me.id)) {
|
|
240
|
+
targetJid = (0, import_WABinary.jidNormalizedUser)(jid);
|
|
241
|
+
} else {
|
|
242
|
+
targetJid = void 0;
|
|
243
|
+
}
|
|
244
|
+
const { img } = await (0, import_Utils.generateProfilePicture)(content, dimensions);
|
|
245
|
+
await query({
|
|
246
|
+
tag: "iq",
|
|
247
|
+
attrs: {
|
|
248
|
+
to: import_WABinary.S_WHATSAPP_NET,
|
|
249
|
+
type: "set",
|
|
250
|
+
xmlns: "w:profile:picture",
|
|
251
|
+
...targetJid ? { target: targetJid } : {}
|
|
252
|
+
},
|
|
253
|
+
content: [
|
|
254
|
+
{
|
|
255
|
+
tag: "picture",
|
|
256
|
+
attrs: { type: "image" },
|
|
257
|
+
content: img
|
|
258
|
+
}
|
|
259
|
+
]
|
|
260
|
+
});
|
|
261
|
+
};
|
|
262
|
+
const removeProfilePicture = async (jid) => {
|
|
263
|
+
let targetJid;
|
|
264
|
+
if (!jid) {
|
|
265
|
+
throw new import_Addon.HttpError("Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update");
|
|
266
|
+
}
|
|
267
|
+
if ((0, import_WABinary.jidNormalizedUser)(jid) !== (0, import_WABinary.jidNormalizedUser)(authState.creds.me.id)) {
|
|
268
|
+
targetJid = (0, import_WABinary.jidNormalizedUser)(jid);
|
|
269
|
+
} else {
|
|
270
|
+
targetJid = void 0;
|
|
271
|
+
}
|
|
272
|
+
await query({
|
|
273
|
+
tag: "iq",
|
|
274
|
+
attrs: {
|
|
275
|
+
to: import_WABinary.S_WHATSAPP_NET,
|
|
276
|
+
type: "set",
|
|
277
|
+
xmlns: "w:profile:picture",
|
|
278
|
+
...targetJid ? { target: targetJid } : {}
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
};
|
|
282
|
+
const updateProfileStatus = async (status) => {
|
|
283
|
+
await query({
|
|
284
|
+
tag: "iq",
|
|
285
|
+
attrs: {
|
|
286
|
+
to: import_WABinary.S_WHATSAPP_NET,
|
|
287
|
+
type: "set",
|
|
288
|
+
xmlns: "status"
|
|
289
|
+
},
|
|
290
|
+
content: [
|
|
291
|
+
{
|
|
292
|
+
tag: "status",
|
|
293
|
+
attrs: {},
|
|
294
|
+
content: Buffer.from(status, "utf-8")
|
|
295
|
+
}
|
|
296
|
+
]
|
|
297
|
+
});
|
|
298
|
+
};
|
|
299
|
+
const updateProfileName = async (name) => {
|
|
300
|
+
await chatModify({ pushNameSetting: name }, "");
|
|
301
|
+
};
|
|
302
|
+
const fetchBlocklist = async () => {
|
|
303
|
+
const result = await query({
|
|
304
|
+
tag: "iq",
|
|
305
|
+
attrs: {
|
|
306
|
+
xmlns: "blocklist",
|
|
307
|
+
to: import_WABinary.S_WHATSAPP_NET,
|
|
308
|
+
type: "get"
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
const listNode = (0, import_WABinary.getBinaryNodeChild)(result, "list");
|
|
312
|
+
return (0, import_WABinary.getBinaryNodeChildren)(listNode, "item").map((n) => n.attrs.jid);
|
|
313
|
+
};
|
|
314
|
+
const updateBlockStatus = async (jid, action) => {
|
|
315
|
+
const normalizedJid = (0, import_WABinary.jidNormalizedUser)(jid);
|
|
316
|
+
let lid;
|
|
317
|
+
let pn_jid;
|
|
318
|
+
if ((0, import_WABinary.isLidUser)(normalizedJid) || (0, import_WABinary.isHostedLidUser)(normalizedJid)) {
|
|
319
|
+
lid = normalizedJid;
|
|
320
|
+
if (action === "block") {
|
|
321
|
+
const pn = (await findUserId(normalizedJid)).phoneNumber;
|
|
322
|
+
if (!pn) {
|
|
323
|
+
throw new import_Addon.HttpError(`Unable to resolve PN JID for LID: ${jid}`, { statusCode: 400 });
|
|
324
|
+
}
|
|
325
|
+
pn_jid = (0, import_WABinary.jidNormalizedUser)(pn);
|
|
326
|
+
}
|
|
327
|
+
} else if ((0, import_WABinary.isPnUser)(normalizedJid) || (0, import_WABinary.isHostedPnUser)(normalizedJid)) {
|
|
328
|
+
const mapped = (await findUserId(normalizedJid)).lid;
|
|
329
|
+
if (!mapped) {
|
|
330
|
+
throw new import_Addon.HttpError(`Unable to resolve LID for PN JID: ${jid}`, { statusCode: 400 });
|
|
331
|
+
}
|
|
332
|
+
lid = mapped;
|
|
333
|
+
if (action === "block") {
|
|
334
|
+
pn_jid = (0, import_WABinary.jidNormalizedUser)(normalizedJid);
|
|
335
|
+
}
|
|
336
|
+
} else {
|
|
337
|
+
throw new import_Addon.HttpError(`Invalid jid: ${jid}`, { statusCode: 400 });
|
|
338
|
+
}
|
|
339
|
+
const itemAttrs = {
|
|
340
|
+
action,
|
|
341
|
+
jid: lid
|
|
342
|
+
};
|
|
343
|
+
if (action === "block") {
|
|
344
|
+
if (!pn_jid) {
|
|
345
|
+
throw new import_Addon.HttpError(`pn_jid required for block: ${jid}`, { statusCode: 400 });
|
|
346
|
+
}
|
|
347
|
+
itemAttrs.pn_jid = pn_jid;
|
|
348
|
+
}
|
|
349
|
+
await query({
|
|
350
|
+
tag: "iq",
|
|
351
|
+
attrs: {
|
|
352
|
+
xmlns: "blocklist",
|
|
353
|
+
to: import_WABinary.S_WHATSAPP_NET,
|
|
354
|
+
type: "set"
|
|
355
|
+
},
|
|
356
|
+
content: [
|
|
357
|
+
{
|
|
358
|
+
tag: "item",
|
|
359
|
+
attrs: itemAttrs
|
|
360
|
+
}
|
|
361
|
+
]
|
|
362
|
+
});
|
|
363
|
+
};
|
|
364
|
+
const getBusinessProfile = async (jid) => {
|
|
365
|
+
const results = await query({
|
|
366
|
+
tag: "iq",
|
|
367
|
+
attrs: {
|
|
368
|
+
to: "s.whatsapp.net",
|
|
369
|
+
xmlns: "w:biz",
|
|
370
|
+
type: "get"
|
|
371
|
+
},
|
|
372
|
+
content: [
|
|
373
|
+
{
|
|
374
|
+
tag: "business_profile",
|
|
375
|
+
attrs: { v: "244" },
|
|
376
|
+
content: [
|
|
377
|
+
{
|
|
378
|
+
tag: "profile",
|
|
379
|
+
attrs: { jid }
|
|
380
|
+
}
|
|
381
|
+
]
|
|
382
|
+
}
|
|
383
|
+
]
|
|
384
|
+
});
|
|
385
|
+
const profileNode = (0, import_WABinary.getBinaryNodeChild)(results, "business_profile");
|
|
386
|
+
const profiles = (0, import_WABinary.getBinaryNodeChild)(profileNode, "profile");
|
|
387
|
+
if (profiles) {
|
|
388
|
+
const address = (0, import_WABinary.getBinaryNodeChild)(profiles, "address");
|
|
389
|
+
const description = (0, import_WABinary.getBinaryNodeChild)(profiles, "description");
|
|
390
|
+
const website = (0, import_WABinary.getBinaryNodeChild)(profiles, "website");
|
|
391
|
+
const email = (0, import_WABinary.getBinaryNodeChild)(profiles, "email");
|
|
392
|
+
const category = (0, import_WABinary.getBinaryNodeChild)((0, import_WABinary.getBinaryNodeChild)(profiles, "categories"), "category");
|
|
393
|
+
const businessHours = (0, import_WABinary.getBinaryNodeChild)(profiles, "business_hours");
|
|
394
|
+
const businessHoursConfig = businessHours ? (0, import_WABinary.getBinaryNodeChildren)(businessHours, "business_hours_config") : void 0;
|
|
395
|
+
const websiteStr = website?.content?.toString();
|
|
396
|
+
return {
|
|
397
|
+
wid: profiles.attrs?.jid,
|
|
398
|
+
address: address?.content?.toString(),
|
|
399
|
+
description: description?.content?.toString() || "",
|
|
400
|
+
website: websiteStr ? [websiteStr] : [],
|
|
401
|
+
email: email?.content?.toString(),
|
|
402
|
+
category: category?.content?.toString(),
|
|
403
|
+
business_hours: {
|
|
404
|
+
timezone: businessHours?.attrs?.timezone,
|
|
405
|
+
business_config: businessHoursConfig?.map(({ attrs }) => attrs)
|
|
406
|
+
}
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
};
|
|
410
|
+
const cleanDirtyBits = async (type, fromTimestamp) => {
|
|
411
|
+
logger.info({ fromTimestamp }, "clean dirty bits " + type);
|
|
412
|
+
await sendNode({
|
|
413
|
+
tag: "iq",
|
|
414
|
+
attrs: {
|
|
415
|
+
to: import_WABinary.S_WHATSAPP_NET,
|
|
416
|
+
type: "set",
|
|
417
|
+
xmlns: "urn:xmpp:whatsapp:dirty",
|
|
418
|
+
id: generateMessageTag()
|
|
419
|
+
},
|
|
420
|
+
content: [
|
|
421
|
+
{
|
|
422
|
+
tag: "clean",
|
|
423
|
+
attrs: {
|
|
424
|
+
type,
|
|
425
|
+
...fromTimestamp ? { timestamp: fromTimestamp.toString() } : null
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
]
|
|
429
|
+
});
|
|
430
|
+
};
|
|
431
|
+
const newAppStateChunkHandler = (isInitialSync) => {
|
|
432
|
+
return {
|
|
433
|
+
onMutation(mutation) {
|
|
434
|
+
(0, import_Utils.processSyncAction)(mutation, ev, authState.creds.me, isInitialSync ? { accountSettings: authState.creds.accountSettings } : void 0, logger);
|
|
435
|
+
}
|
|
436
|
+
};
|
|
437
|
+
};
|
|
438
|
+
const resyncAppState = ev.createBufferedFunction(async (collections, isInitialSync) => {
|
|
439
|
+
const appStateSyncKeyCache = /* @__PURE__ */ new Map();
|
|
440
|
+
const getCachedAppStateSyncKey = async (keyId) => {
|
|
441
|
+
if (appStateSyncKeyCache.has(keyId)) {
|
|
442
|
+
return appStateSyncKeyCache.get(keyId) ?? void 0;
|
|
443
|
+
}
|
|
444
|
+
const key = await getAppStateSyncKey(keyId);
|
|
445
|
+
appStateSyncKeyCache.set(keyId, key ?? null);
|
|
446
|
+
return key;
|
|
447
|
+
};
|
|
448
|
+
const initialVersionMap = {};
|
|
449
|
+
const globalMutationMap = {};
|
|
450
|
+
await authState.keys.transaction(async () => {
|
|
451
|
+
const collectionsToHandle = new Set(collections);
|
|
452
|
+
const attemptsMap = {};
|
|
453
|
+
const forceSnapshotCollections = /* @__PURE__ */ new Set();
|
|
454
|
+
while (collectionsToHandle.size) {
|
|
455
|
+
const states = {};
|
|
456
|
+
const nodes = [];
|
|
457
|
+
for (const name of collectionsToHandle) {
|
|
458
|
+
const result2 = await authState.keys.get("app-state-sync-version", [name]);
|
|
459
|
+
let state = result2[name];
|
|
460
|
+
if (state) {
|
|
461
|
+
state = (0, import_Utils.ensureLTHashStateVersion)(state);
|
|
462
|
+
if (typeof initialVersionMap[name] === "undefined") {
|
|
463
|
+
initialVersionMap[name] = state.version;
|
|
464
|
+
}
|
|
465
|
+
} else {
|
|
466
|
+
state = (0, import_Utils.newLTHashState)();
|
|
467
|
+
}
|
|
468
|
+
states[name] = state;
|
|
469
|
+
const shouldForceSnapshot = forceSnapshotCollections.has(name);
|
|
470
|
+
if (shouldForceSnapshot) {
|
|
471
|
+
forceSnapshotCollections.delete(name);
|
|
472
|
+
}
|
|
473
|
+
logger.info(`resyncing ${name} from v${state.version}${shouldForceSnapshot ? " (forcing snapshot)" : ""}`);
|
|
474
|
+
nodes.push({
|
|
475
|
+
tag: "collection",
|
|
476
|
+
attrs: {
|
|
477
|
+
name,
|
|
478
|
+
version: state.version.toString(),
|
|
479
|
+
// return snapshot if syncing from scratch or forcing after a failed attempt
|
|
480
|
+
return_snapshot: (shouldForceSnapshot || !state.version).toString()
|
|
481
|
+
}
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
const result = await query({
|
|
485
|
+
tag: "iq",
|
|
486
|
+
attrs: {
|
|
487
|
+
to: import_WABinary.S_WHATSAPP_NET,
|
|
488
|
+
xmlns: "w:sync:app:state",
|
|
489
|
+
type: "set"
|
|
490
|
+
},
|
|
491
|
+
content: [
|
|
492
|
+
{
|
|
493
|
+
tag: "sync",
|
|
494
|
+
attrs: {},
|
|
495
|
+
content: nodes
|
|
496
|
+
}
|
|
497
|
+
]
|
|
498
|
+
});
|
|
499
|
+
const decoded = await (0, import_Utils.extractSyncdPatches)(result, config?.options);
|
|
500
|
+
for (const key in decoded) {
|
|
501
|
+
const name = key;
|
|
502
|
+
const { patches, hasMorePatches, snapshot } = decoded[name];
|
|
503
|
+
try {
|
|
504
|
+
if (snapshot) {
|
|
505
|
+
const { state: newState, mutationMap } = await (0, import_Utils.decodeSyncdSnapshot)(name, snapshot, getCachedAppStateSyncKey, initialVersionMap[name], appStateMacVerification.snapshot, logger);
|
|
506
|
+
states[name] = newState;
|
|
507
|
+
Object.assign(globalMutationMap, mutationMap);
|
|
508
|
+
logger.info(`restored state of ${name} from snapshot to v${newState.version} with mutations`);
|
|
509
|
+
await authState.keys.set({ "app-state-sync-version": { [name]: newState } });
|
|
510
|
+
}
|
|
511
|
+
if (patches.length) {
|
|
512
|
+
const { state: newState, mutationMap } = await (0, import_Utils.decodePatches)(name, patches, states[name], getCachedAppStateSyncKey, config.options, initialVersionMap[name], logger, appStateMacVerification.patch);
|
|
513
|
+
await authState.keys.set({ "app-state-sync-version": { [name]: newState } });
|
|
514
|
+
logger.info(`synced ${name} to v${newState.version}`);
|
|
515
|
+
initialVersionMap[name] = newState.version;
|
|
516
|
+
Object.assign(globalMutationMap, mutationMap);
|
|
517
|
+
}
|
|
518
|
+
if (hasMorePatches) {
|
|
519
|
+
logger.info(`${name} has more patches...`);
|
|
520
|
+
} else {
|
|
521
|
+
collectionsToHandle.delete(name);
|
|
522
|
+
}
|
|
523
|
+
} catch (error) {
|
|
524
|
+
attemptsMap[name] = (attemptsMap[name] || 0) + 1;
|
|
525
|
+
const logData = {
|
|
526
|
+
name,
|
|
527
|
+
attempt: attemptsMap[name],
|
|
528
|
+
version: states[name].version,
|
|
529
|
+
statusCode: error.output?.statusCode,
|
|
530
|
+
errorType: error.name,
|
|
531
|
+
error: error.stack
|
|
532
|
+
};
|
|
533
|
+
if ((0, import_Utils.isMissingKeyError)(error) && attemptsMap[name] >= import_Utils.MAX_SYNC_ATTEMPTS) {
|
|
534
|
+
logger.warn(logData, `${name} blocked on missing key from v${states[name].version}, parking after ${attemptsMap[name]} attempts`);
|
|
535
|
+
blockedCollections.add(name);
|
|
536
|
+
collectionsToHandle.delete(name);
|
|
537
|
+
} else if ((0, import_Utils.isMissingKeyError)(error)) {
|
|
538
|
+
logger.info(logData, `${name} blocked on missing key from v${states[name].version}, retrying with snapshot`);
|
|
539
|
+
forceSnapshotCollections.add(name);
|
|
540
|
+
} else if ((0, import_Utils.isAppStateSyncIrrecoverable)(error, attemptsMap[name])) {
|
|
541
|
+
logger.warn(logData, `failed to sync ${name} from v${states[name].version}, giving up`);
|
|
542
|
+
collectionsToHandle.delete(name);
|
|
543
|
+
} else {
|
|
544
|
+
logger.info(logData, `failed to sync ${name} from v${states[name].version}, forcing snapshot retry`);
|
|
545
|
+
forceSnapshotCollections.add(name);
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
}, authState?.creds?.me?.id || "resync-app-state");
|
|
551
|
+
const { onMutation } = newAppStateChunkHandler(isInitialSync);
|
|
552
|
+
for (const key in globalMutationMap) {
|
|
553
|
+
onMutation(globalMutationMap[key]);
|
|
554
|
+
}
|
|
555
|
+
});
|
|
556
|
+
const profilePictureUrl = async (jid, type = "image", timeoutMs = 5e3, shouldIncludeTcToken = true) => {
|
|
557
|
+
const normalizedJid = (0, import_WABinary.jidNormalizedUser)(jid);
|
|
558
|
+
const isUserJid = (0, import_WABinary.isPnUser)(normalizedJid) || (0, import_WABinary.isLidUser)(normalizedJid);
|
|
559
|
+
const me = authState.creds.me;
|
|
560
|
+
const isSelf = me && (normalizedJid === (0, import_WABinary.jidNormalizedUser)(me.id) || me.lid && normalizedJid === (0, import_WABinary.jidNormalizedUser)(me.lid));
|
|
561
|
+
let tcTokenContent;
|
|
562
|
+
if (shouldIncludeTcToken && serverProps.profilePicPrivacyToken && isUserJid && !isSelf) {
|
|
563
|
+
tcTokenContent = await (0, import_tc_token_utils.buildTcTokenFromJid)({
|
|
564
|
+
authState,
|
|
565
|
+
jid: normalizedJid,
|
|
566
|
+
getLIDForPN
|
|
567
|
+
});
|
|
568
|
+
}
|
|
569
|
+
jid = (0, import_WABinary.jidNormalizedUser)(jid);
|
|
570
|
+
const result = await query({
|
|
571
|
+
tag: "iq",
|
|
572
|
+
attrs: {
|
|
573
|
+
target: jid,
|
|
574
|
+
to: import_WABinary.S_WHATSAPP_NET,
|
|
575
|
+
type: "get",
|
|
576
|
+
xmlns: "w:profile:picture"
|
|
577
|
+
},
|
|
578
|
+
content: buildProfilePictureQueryContent(type, tcTokenContent)
|
|
579
|
+
}, timeoutMs);
|
|
580
|
+
const child = (0, import_WABinary.getBinaryNodeChild)(result, "picture");
|
|
581
|
+
return child?.attrs?.url;
|
|
582
|
+
};
|
|
583
|
+
const createCallLink = async (type, event, timeoutMs) => {
|
|
584
|
+
const result = await query({
|
|
585
|
+
tag: "call",
|
|
586
|
+
attrs: {
|
|
587
|
+
id: generateMessageTag(),
|
|
588
|
+
to: "@call"
|
|
589
|
+
},
|
|
590
|
+
content: [
|
|
591
|
+
{
|
|
592
|
+
tag: "link_create",
|
|
593
|
+
attrs: { media: type },
|
|
594
|
+
content: event ? [{ tag: "event", attrs: { start_time: String(event.startTime) } }] : void 0
|
|
595
|
+
}
|
|
596
|
+
]
|
|
597
|
+
}, timeoutMs);
|
|
598
|
+
const child = (0, import_WABinary.getBinaryNodeChild)(result, "link_create");
|
|
599
|
+
return child?.attrs?.token;
|
|
600
|
+
};
|
|
601
|
+
const sendPresenceUpdate = async (type, toJid) => {
|
|
602
|
+
const me = authState.creds.me;
|
|
603
|
+
const isAvailableType = type === "available";
|
|
604
|
+
if (isAvailableType || type === "unavailable") {
|
|
605
|
+
if (!me.name) {
|
|
606
|
+
logger.warn("no name present, ignoring presence update request...");
|
|
607
|
+
return;
|
|
608
|
+
}
|
|
609
|
+
ev.emit("connection.update", { isOnline: isAvailableType });
|
|
610
|
+
if (isAvailableType) {
|
|
611
|
+
void sendUnifiedSession();
|
|
612
|
+
}
|
|
613
|
+
await sendNode({
|
|
614
|
+
tag: "presence",
|
|
615
|
+
attrs: {
|
|
616
|
+
name: me.name.replace(/@/g, ""),
|
|
617
|
+
type
|
|
618
|
+
}
|
|
619
|
+
});
|
|
620
|
+
} else {
|
|
621
|
+
const { server } = (0, import_WABinary.jidDecode)(toJid);
|
|
622
|
+
const isLid = server === "lid";
|
|
623
|
+
await sendNode({
|
|
624
|
+
tag: "chatstate",
|
|
625
|
+
attrs: {
|
|
626
|
+
from: isLid ? me.lid : me.id,
|
|
627
|
+
to: toJid
|
|
628
|
+
},
|
|
629
|
+
content: [
|
|
630
|
+
{
|
|
631
|
+
tag: type === "recording" ? "composing" : type,
|
|
632
|
+
attrs: type === "recording" ? { media: "audio" } : {}
|
|
633
|
+
}
|
|
634
|
+
]
|
|
635
|
+
});
|
|
636
|
+
}
|
|
637
|
+
};
|
|
638
|
+
const presenceSubscribe = async (toJid) => {
|
|
639
|
+
const normalizedToJid = (0, import_WABinary.jidNormalizedUser)(toJid);
|
|
640
|
+
const isUserJid = (0, import_WABinary.isPnUser)(normalizedToJid) || (0, import_WABinary.isLidUser)(normalizedToJid);
|
|
641
|
+
const tcTokenContent = isUserJid ? await (0, import_tc_token_utils.buildTcTokenFromJid)({ authState, jid: normalizedToJid, getLIDForPN }) : void 0;
|
|
642
|
+
return sendNode({
|
|
643
|
+
tag: "presence",
|
|
644
|
+
attrs: {
|
|
645
|
+
to: toJid,
|
|
646
|
+
id: generateMessageTag(),
|
|
647
|
+
type: "subscribe"
|
|
648
|
+
},
|
|
649
|
+
content: tcTokenContent
|
|
650
|
+
});
|
|
651
|
+
};
|
|
652
|
+
const handlePresenceUpdate = ({ tag, attrs, content }) => {
|
|
653
|
+
let presence;
|
|
654
|
+
const jid = attrs.from;
|
|
655
|
+
const participant = attrs.participant || attrs.from;
|
|
656
|
+
if (shouldIgnoreJid(jid) && jid !== import_WABinary.S_WHATSAPP_NET) {
|
|
657
|
+
return;
|
|
658
|
+
}
|
|
659
|
+
if (tag === "presence") {
|
|
660
|
+
presence = {
|
|
661
|
+
lastKnownPresence: attrs.type === "unavailable" ? "unavailable" : "available",
|
|
662
|
+
lastSeen: attrs.last && attrs.last !== "deny" ? +attrs.last : void 0,
|
|
663
|
+
groupOnlineCount: attrs.count ? +attrs.count : void 0
|
|
664
|
+
};
|
|
665
|
+
} else if (Array.isArray(content)) {
|
|
666
|
+
const [firstChild] = content;
|
|
667
|
+
let type = firstChild.tag;
|
|
668
|
+
if (type === "paused") {
|
|
669
|
+
type = "available";
|
|
670
|
+
}
|
|
671
|
+
if (firstChild.attrs?.media === "audio") {
|
|
672
|
+
type = "recording";
|
|
673
|
+
}
|
|
674
|
+
presence = { lastKnownPresence: type };
|
|
675
|
+
} else {
|
|
676
|
+
logger.error({ tag, attrs, content }, "recv invalid presence node");
|
|
677
|
+
}
|
|
678
|
+
if (presence) {
|
|
679
|
+
ev.emit("presence.update", { id: jid, presences: { [participant]: presence } });
|
|
680
|
+
}
|
|
681
|
+
};
|
|
682
|
+
const appPatch = async (patchCreate) => {
|
|
683
|
+
const name = patchCreate.type;
|
|
684
|
+
const myAppStateKeyId = authState.creds.myAppStateKeyId;
|
|
685
|
+
if (!myAppStateKeyId) {
|
|
686
|
+
throw new import_Addon.HttpError("App state key not present!", { statusCode: 400 });
|
|
687
|
+
}
|
|
688
|
+
let initial;
|
|
689
|
+
let encodeResult;
|
|
690
|
+
await appStatePatchMutex.mutex(async () => {
|
|
691
|
+
await authState.keys.transaction(async () => {
|
|
692
|
+
logger.debug({ patch: patchCreate }, "applying app patch");
|
|
693
|
+
await resyncAppState([name], false);
|
|
694
|
+
const { [name]: currentSyncVersion } = await authState.keys.get("app-state-sync-version", [name]);
|
|
695
|
+
initial = currentSyncVersion ? (0, import_Utils.ensureLTHashStateVersion)(currentSyncVersion) : (0, import_Utils.newLTHashState)();
|
|
696
|
+
encodeResult = await (0, import_Utils.encodeSyncdPatch)(patchCreate, myAppStateKeyId, initial, getAppStateSyncKey);
|
|
697
|
+
const { patch, state } = encodeResult;
|
|
698
|
+
const node = {
|
|
699
|
+
tag: "iq",
|
|
700
|
+
attrs: {
|
|
701
|
+
to: import_WABinary.S_WHATSAPP_NET,
|
|
702
|
+
type: "set",
|
|
703
|
+
xmlns: "w:sync:app:state"
|
|
704
|
+
},
|
|
705
|
+
content: [
|
|
706
|
+
{
|
|
707
|
+
tag: "sync",
|
|
708
|
+
attrs: {},
|
|
709
|
+
content: [
|
|
710
|
+
{
|
|
711
|
+
tag: "collection",
|
|
712
|
+
attrs: {
|
|
713
|
+
name,
|
|
714
|
+
version: (state.version - 1).toString(),
|
|
715
|
+
return_snapshot: "false"
|
|
716
|
+
},
|
|
717
|
+
content: [
|
|
718
|
+
{
|
|
719
|
+
tag: "patch",
|
|
720
|
+
attrs: {},
|
|
721
|
+
content: import_WAProto.proto.SyncdPatch.encode(patch).finish()
|
|
722
|
+
}
|
|
723
|
+
]
|
|
724
|
+
}
|
|
725
|
+
]
|
|
726
|
+
}
|
|
727
|
+
]
|
|
728
|
+
};
|
|
729
|
+
await query(node);
|
|
730
|
+
await authState.keys.set({ "app-state-sync-version": { [name]: state } });
|
|
731
|
+
}, authState?.creds?.me?.id || "app-patch");
|
|
732
|
+
});
|
|
733
|
+
if (config.emitOwnEvents) {
|
|
734
|
+
const { onMutation } = newAppStateChunkHandler(false);
|
|
735
|
+
const { mutationMap } = await (0, import_Utils.decodePatches)(name, [{ ...encodeResult.patch, version: { version: encodeResult.state.version } }], initial, getAppStateSyncKey, config.options, void 0, logger);
|
|
736
|
+
for (const key in mutationMap) {
|
|
737
|
+
onMutation(mutationMap[key]);
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
};
|
|
741
|
+
const fetchProps = async () => {
|
|
742
|
+
const resultNode = await query({
|
|
743
|
+
tag: "iq",
|
|
744
|
+
attrs: {
|
|
745
|
+
to: import_WABinary.S_WHATSAPP_NET,
|
|
746
|
+
xmlns: "abt",
|
|
747
|
+
type: "get"
|
|
748
|
+
},
|
|
749
|
+
content: [
|
|
750
|
+
{
|
|
751
|
+
tag: "props",
|
|
752
|
+
attrs: {
|
|
753
|
+
protocol: "1",
|
|
754
|
+
...authState?.creds?.lastPropHash ? { hash: authState.creds.lastPropHash } : {}
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
]
|
|
758
|
+
});
|
|
759
|
+
const propsNode = (0, import_WABinary.getBinaryNodeChild)(resultNode, "props");
|
|
760
|
+
let props = {};
|
|
761
|
+
if (propsNode) {
|
|
762
|
+
if (propsNode.attrs?.hash) {
|
|
763
|
+
authState.creds.lastPropHash = propsNode?.attrs?.hash;
|
|
764
|
+
ev.emit("creds.update", authState.creds);
|
|
765
|
+
}
|
|
766
|
+
props = (0, import_WABinary.reduceBinaryNodeToDictionary)(propsNode, "prop");
|
|
767
|
+
}
|
|
768
|
+
const privacyTokenProp = props["10518"] ?? props["privacy_token_sending_on_all_1_on_1_messages"];
|
|
769
|
+
if (privacyTokenProp !== void 0) {
|
|
770
|
+
serverProps.privacyTokenOn1to1 = privacyTokenProp === "true" || privacyTokenProp === "1";
|
|
771
|
+
}
|
|
772
|
+
const profilePicProp = props["9666"] ?? props["profile_scraping_privacy_token_in_photo_iq"];
|
|
773
|
+
if (profilePicProp !== void 0) {
|
|
774
|
+
serverProps.profilePicPrivacyToken = profilePicProp === "true" || profilePicProp === "1";
|
|
775
|
+
}
|
|
776
|
+
const lidIssueProp = props["14303"] ?? props["lid_trusted_token_issue_to_lid"];
|
|
777
|
+
if (lidIssueProp !== void 0) {
|
|
778
|
+
serverProps.lidTrustedTokenIssueToLid = lidIssueProp === "true" || lidIssueProp === "1";
|
|
779
|
+
}
|
|
780
|
+
logger.debug({ serverProps }, "fetched props");
|
|
781
|
+
return props;
|
|
782
|
+
};
|
|
783
|
+
const chatModify = (mod, jid) => {
|
|
784
|
+
const patch = (0, import_Utils.chatModificationToAppPatch)(mod, jid);
|
|
785
|
+
return appPatch(patch);
|
|
786
|
+
};
|
|
787
|
+
const updateDisableLinkPreviewsPrivacy = (isPreviewsDisabled) => {
|
|
788
|
+
return chatModify({
|
|
789
|
+
disableLinkPreviews: { isPreviewsDisabled }
|
|
790
|
+
}, "");
|
|
791
|
+
};
|
|
792
|
+
const star = (jid, messages, star2) => {
|
|
793
|
+
return chatModify({
|
|
794
|
+
star: {
|
|
795
|
+
messages,
|
|
796
|
+
star: star2
|
|
797
|
+
}
|
|
798
|
+
}, jid);
|
|
799
|
+
};
|
|
800
|
+
const addOrEditContact = (jid, contact) => {
|
|
801
|
+
return chatModify({
|
|
802
|
+
contact
|
|
803
|
+
}, jid);
|
|
804
|
+
};
|
|
805
|
+
const removeContact = (jid) => {
|
|
806
|
+
return chatModify({
|
|
807
|
+
contact: null
|
|
808
|
+
}, jid);
|
|
809
|
+
};
|
|
810
|
+
const addLabel = (jid, labels) => {
|
|
811
|
+
return chatModify({
|
|
812
|
+
addLabel: {
|
|
813
|
+
...labels
|
|
814
|
+
}
|
|
815
|
+
}, jid);
|
|
816
|
+
};
|
|
817
|
+
const addChatLabel = (jid, labelId) => {
|
|
818
|
+
return chatModify({
|
|
819
|
+
addChatLabel: {
|
|
820
|
+
labelId
|
|
821
|
+
}
|
|
822
|
+
}, jid);
|
|
823
|
+
};
|
|
824
|
+
const removeChatLabel = (jid, labelId) => {
|
|
825
|
+
return chatModify({
|
|
826
|
+
removeChatLabel: {
|
|
827
|
+
labelId
|
|
828
|
+
}
|
|
829
|
+
}, jid);
|
|
830
|
+
};
|
|
831
|
+
const addMessageLabel = (jid, messageId, labelId) => {
|
|
832
|
+
return chatModify({
|
|
833
|
+
addMessageLabel: {
|
|
834
|
+
messageId,
|
|
835
|
+
labelId
|
|
836
|
+
}
|
|
837
|
+
}, jid);
|
|
838
|
+
};
|
|
839
|
+
const removeMessageLabel = (jid, messageId, labelId) => {
|
|
840
|
+
return chatModify({
|
|
841
|
+
removeMessageLabel: {
|
|
842
|
+
messageId,
|
|
843
|
+
labelId
|
|
844
|
+
}
|
|
845
|
+
}, jid);
|
|
846
|
+
};
|
|
847
|
+
const addOrEditQuickReply = (quickReply) => {
|
|
848
|
+
return chatModify({
|
|
849
|
+
quickReply
|
|
850
|
+
}, "");
|
|
851
|
+
};
|
|
852
|
+
const removeQuickReply = (timestamp) => {
|
|
853
|
+
return chatModify({
|
|
854
|
+
quickReply: { timestamp, deleted: true }
|
|
855
|
+
}, "");
|
|
856
|
+
};
|
|
857
|
+
const executeInitQueries = async () => {
|
|
858
|
+
await Promise.all([fetchProps(), fetchBlocklist(), fetchPrivacySettings()]);
|
|
859
|
+
};
|
|
860
|
+
const upsertMessage = ev.createBufferedFunction(async (msg, type) => {
|
|
861
|
+
ev.emit("messages.upsert", { messages: [msg], type });
|
|
862
|
+
if (!!msg.pushName) {
|
|
863
|
+
let jid = msg.key.fromMe ? authState.creds.me.id : msg.key.participant || msg.key.remoteJid;
|
|
864
|
+
jid = (0, import_WABinary.jidNormalizedUser)(jid);
|
|
865
|
+
if (!msg.key.fromMe) {
|
|
866
|
+
ev.emit("contacts.update", [{ id: jid, notify: msg.pushName, verifiedName: msg.verifiedBizName }]);
|
|
867
|
+
}
|
|
868
|
+
if (msg.key.fromMe && msg.pushName && authState.creds.me?.name !== msg.pushName) {
|
|
869
|
+
ev.emit("creds.update", { me: { ...authState.creds.me, name: msg.pushName } });
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
const historyMsg = (0, import_Utils.getHistoryMsg)(msg.message);
|
|
873
|
+
const shouldProcessHistoryMsg = historyMsg ? shouldSyncHistoryMessage(historyMsg) && import_Defaults.PROCESSABLE_HISTORY_TYPES.includes(historyMsg.syncType) : false;
|
|
874
|
+
if (historyMsg && shouldProcessHistoryMsg) {
|
|
875
|
+
const syncType = historyMsg.syncType;
|
|
876
|
+
if (syncType === import_WAProto.proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP && !historySyncStatus.initialBootstrapComplete) {
|
|
877
|
+
historySyncStatus.initialBootstrapComplete = true;
|
|
878
|
+
ev.emit("messaging-history.status", {
|
|
879
|
+
syncType,
|
|
880
|
+
status: "complete",
|
|
881
|
+
explicit: true
|
|
882
|
+
});
|
|
883
|
+
}
|
|
884
|
+
if (syncType === import_WAProto.proto.HistorySync.HistorySyncType.RECENT && historyMsg.progress === 100 && !historySyncStatus.recentSyncComplete) {
|
|
885
|
+
historySyncStatus.recentSyncComplete = true;
|
|
886
|
+
clearTimeout(historySyncPausedTimeout);
|
|
887
|
+
historySyncPausedTimeout = void 0;
|
|
888
|
+
ev.emit("messaging-history.status", {
|
|
889
|
+
syncType,
|
|
890
|
+
status: "complete",
|
|
891
|
+
explicit: true
|
|
892
|
+
});
|
|
893
|
+
}
|
|
894
|
+
if (syncType === import_WAProto.proto.HistorySync.HistorySyncType.RECENT && !historySyncStatus.recentSyncComplete) {
|
|
895
|
+
clearTimeout(historySyncPausedTimeout);
|
|
896
|
+
historySyncPausedTimeout = setTimeout(() => {
|
|
897
|
+
if (!historySyncStatus.recentSyncComplete) {
|
|
898
|
+
historySyncStatus.recentSyncComplete = true;
|
|
899
|
+
ev.emit("messaging-history.status", {
|
|
900
|
+
syncType: import_WAProto.proto.HistorySync.HistorySyncType.RECENT,
|
|
901
|
+
status: "paused",
|
|
902
|
+
explicit: false
|
|
903
|
+
});
|
|
904
|
+
}
|
|
905
|
+
historySyncPausedTimeout = void 0;
|
|
906
|
+
}, import_Defaults.HISTORY_SYNC_PAUSED_TIMEOUT_MS);
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
if (historyMsg && syncState === import_State.SyncState.AwaitingInitialSync) {
|
|
910
|
+
if (awaitingSyncTimeout) {
|
|
911
|
+
clearTimeout(awaitingSyncTimeout);
|
|
912
|
+
awaitingSyncTimeout = void 0;
|
|
913
|
+
}
|
|
914
|
+
if (shouldProcessHistoryMsg) {
|
|
915
|
+
syncState = import_State.SyncState.Syncing;
|
|
916
|
+
logger.info("Transitioned to Syncing state");
|
|
917
|
+
} else {
|
|
918
|
+
syncState = import_State.SyncState.Online;
|
|
919
|
+
logger.info("History sync skipped, transitioning to Online state and flushing buffer");
|
|
920
|
+
ev.flush();
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
const doAppStateSync = async () => {
|
|
924
|
+
if (syncState === import_State.SyncState.Syncing) {
|
|
925
|
+
blockedCollections.clear();
|
|
926
|
+
logger.info("Doing app state sync");
|
|
927
|
+
await resyncAppState(import_Types.ALL_WA_PATCH_NAMES, true);
|
|
928
|
+
syncState = import_State.SyncState.Online;
|
|
929
|
+
logger.info("App state sync complete, transitioning to Online state and flushing buffer");
|
|
930
|
+
ev.flush();
|
|
931
|
+
const accountSyncCounter = (authState.creds.accountSyncCounter || 0) + 1;
|
|
932
|
+
ev.emit("creds.update", { accountSyncCounter });
|
|
933
|
+
}
|
|
934
|
+
};
|
|
935
|
+
await Promise.all([
|
|
936
|
+
(async () => {
|
|
937
|
+
if (shouldProcessHistoryMsg) {
|
|
938
|
+
await doAppStateSync();
|
|
939
|
+
}
|
|
940
|
+
})(),
|
|
941
|
+
(0, import_process_message.default)(msg, {
|
|
942
|
+
signalRepository,
|
|
943
|
+
shouldProcessHistoryMsg,
|
|
944
|
+
placeholderResendCache,
|
|
945
|
+
ev,
|
|
946
|
+
creds: authState.creds,
|
|
947
|
+
keyStore: authState.keys,
|
|
948
|
+
logger,
|
|
949
|
+
options: config.options,
|
|
950
|
+
getMessage
|
|
951
|
+
})
|
|
952
|
+
]);
|
|
953
|
+
if (msg.message?.protocolMessage?.appStateSyncKeyShare && syncState === import_State.SyncState.Syncing) {
|
|
954
|
+
logger.info("App state sync key arrived, triggering app state sync");
|
|
955
|
+
await doAppStateSync();
|
|
956
|
+
}
|
|
957
|
+
});
|
|
958
|
+
ws.on("CB:presence", handlePresenceUpdate);
|
|
959
|
+
ws.on("CB:chatstate", handlePresenceUpdate);
|
|
960
|
+
ws.on("CB:ib,,dirty", async (node) => {
|
|
961
|
+
const { attrs } = (0, import_WABinary.getBinaryNodeChild)(node, "dirty");
|
|
962
|
+
const type = attrs.type;
|
|
963
|
+
switch (type) {
|
|
964
|
+
case "account_sync":
|
|
965
|
+
if (attrs.timestamp) {
|
|
966
|
+
let { lastAccountSyncTimestamp } = authState.creds;
|
|
967
|
+
if (lastAccountSyncTimestamp) {
|
|
968
|
+
await cleanDirtyBits("account_sync", lastAccountSyncTimestamp);
|
|
969
|
+
}
|
|
970
|
+
lastAccountSyncTimestamp = +attrs.timestamp;
|
|
971
|
+
ev.emit("creds.update", { lastAccountSyncTimestamp });
|
|
972
|
+
}
|
|
973
|
+
break;
|
|
974
|
+
case "groups":
|
|
975
|
+
break;
|
|
976
|
+
default:
|
|
977
|
+
logger.info({ node }, "received unknown sync");
|
|
978
|
+
break;
|
|
979
|
+
}
|
|
980
|
+
});
|
|
981
|
+
ev.on("connection.update", ({ connection, receivedPendingNotifications }) => {
|
|
982
|
+
if (connection === "close") {
|
|
983
|
+
blockedCollections.clear();
|
|
984
|
+
clearTimeout(historySyncPausedTimeout);
|
|
985
|
+
historySyncPausedTimeout = void 0;
|
|
986
|
+
}
|
|
987
|
+
if (connection === "open") {
|
|
988
|
+
if (fireInitQueries) {
|
|
989
|
+
executeInitQueries().catch((error) => onUnexpectedError(error, "init queries"));
|
|
990
|
+
}
|
|
991
|
+
sendPresenceUpdate(markOnlineOnConnect ? "available" : "unavailable").catch((error) => onUnexpectedError(error, "presence update requests"));
|
|
992
|
+
}
|
|
993
|
+
if (!receivedPendingNotifications || syncState !== import_State.SyncState.Connecting) {
|
|
994
|
+
return;
|
|
995
|
+
}
|
|
996
|
+
historySyncStatus.initialBootstrapComplete = false;
|
|
997
|
+
historySyncStatus.recentSyncComplete = false;
|
|
998
|
+
clearTimeout(historySyncPausedTimeout);
|
|
999
|
+
historySyncPausedTimeout = void 0;
|
|
1000
|
+
syncState = import_State.SyncState.AwaitingInitialSync;
|
|
1001
|
+
logger.info("Connection is now AwaitingInitialSync, buffering events");
|
|
1002
|
+
ev.buffer();
|
|
1003
|
+
const willSyncHistory = shouldSyncHistoryMessage(import_WAProto.proto.Message.HistorySyncNotification.create({
|
|
1004
|
+
syncType: import_WAProto.proto.HistorySync.HistorySyncType.RECENT
|
|
1005
|
+
}));
|
|
1006
|
+
if (!willSyncHistory) {
|
|
1007
|
+
logger.info("History sync is disabled by config, not waiting for notification. Transitioning to Online.");
|
|
1008
|
+
syncState = import_State.SyncState.Online;
|
|
1009
|
+
setTimeout(() => ev.flush(), 0);
|
|
1010
|
+
return;
|
|
1011
|
+
}
|
|
1012
|
+
if (authState.creds.accountSyncCounter > 0) {
|
|
1013
|
+
logger.info("Reconnection with existing sync data, skipping history sync wait. Transitioning to Online.");
|
|
1014
|
+
syncState = import_State.SyncState.Online;
|
|
1015
|
+
setTimeout(() => ev.flush(), 0);
|
|
1016
|
+
return;
|
|
1017
|
+
}
|
|
1018
|
+
logger.info("First connection, awaiting history sync notification with a 20s timeout.");
|
|
1019
|
+
if (awaitingSyncTimeout) {
|
|
1020
|
+
clearTimeout(awaitingSyncTimeout);
|
|
1021
|
+
}
|
|
1022
|
+
awaitingSyncTimeout = setTimeout(() => {
|
|
1023
|
+
if (syncState === import_State.SyncState.AwaitingInitialSync) {
|
|
1024
|
+
logger.warn("Timeout in AwaitingInitialSync, forcing state to Online and flushing buffer");
|
|
1025
|
+
syncState = import_State.SyncState.Online;
|
|
1026
|
+
ev.flush();
|
|
1027
|
+
const accountSyncCounter = (authState.creds.accountSyncCounter || 0) + 1;
|
|
1028
|
+
ev.emit("creds.update", { accountSyncCounter });
|
|
1029
|
+
}
|
|
1030
|
+
}, 2e4);
|
|
1031
|
+
});
|
|
1032
|
+
ev.on("creds.update", ({ myAppStateKeyId }) => {
|
|
1033
|
+
if (!myAppStateKeyId || blockedCollections.size === 0) {
|
|
1034
|
+
return;
|
|
1035
|
+
}
|
|
1036
|
+
if (syncState === import_State.SyncState.Syncing) {
|
|
1037
|
+
blockedCollections.clear();
|
|
1038
|
+
return;
|
|
1039
|
+
}
|
|
1040
|
+
const collections = [...blockedCollections];
|
|
1041
|
+
blockedCollections.clear();
|
|
1042
|
+
logger.info({ collections }, "app state sync key arrived, re-syncing blocked collections");
|
|
1043
|
+
resyncAppState(collections, false).catch((error) => onUnexpectedError(error, "blocked collections resync"));
|
|
1044
|
+
});
|
|
1045
|
+
ev.on("lid-mapping.update", async ({ lid, pn }) => {
|
|
1046
|
+
try {
|
|
1047
|
+
await signalRepository.lidMapping.storeLIDPNMappings([{ lid, pn }]);
|
|
1048
|
+
} catch (error) {
|
|
1049
|
+
logger.warn({ lid, pn, error }, "Failed to store LID-PN mapping");
|
|
1050
|
+
}
|
|
1051
|
+
});
|
|
1052
|
+
registerSocketEndHandler(() => {
|
|
1053
|
+
if (awaitingSyncTimeout) {
|
|
1054
|
+
clearTimeout(awaitingSyncTimeout);
|
|
1055
|
+
awaitingSyncTimeout = void 0;
|
|
1056
|
+
}
|
|
1057
|
+
if (!config.placeholderResendCache && placeholderResendCache.close) {
|
|
1058
|
+
placeholderResendCache.close();
|
|
1059
|
+
}
|
|
1060
|
+
syncState = import_State.SyncState.Connecting;
|
|
1061
|
+
privacySettings = void 0;
|
|
1062
|
+
});
|
|
1063
|
+
return {
|
|
1064
|
+
...sock,
|
|
1065
|
+
findUserId,
|
|
1066
|
+
serverProps,
|
|
1067
|
+
createCallLink,
|
|
1068
|
+
getBotListV2,
|
|
1069
|
+
messageMutex,
|
|
1070
|
+
receiptMutex,
|
|
1071
|
+
appStatePatchMutex,
|
|
1072
|
+
notificationMutex,
|
|
1073
|
+
fetchPrivacySettings,
|
|
1074
|
+
upsertMessage,
|
|
1075
|
+
appPatch,
|
|
1076
|
+
sendPresenceUpdate,
|
|
1077
|
+
presenceSubscribe,
|
|
1078
|
+
profilePictureUrl,
|
|
1079
|
+
fetchBlocklist,
|
|
1080
|
+
fetchStatus,
|
|
1081
|
+
fetchDisappearingDuration,
|
|
1082
|
+
updateProfilePicture,
|
|
1083
|
+
removeProfilePicture,
|
|
1084
|
+
updateProfileStatus,
|
|
1085
|
+
updateProfileName,
|
|
1086
|
+
updateBlockStatus,
|
|
1087
|
+
updateDisableLinkPreviewsPrivacy,
|
|
1088
|
+
updateCallPrivacy,
|
|
1089
|
+
updateMessagesPrivacy,
|
|
1090
|
+
updateLastSeenPrivacy,
|
|
1091
|
+
updateOnlinePrivacy,
|
|
1092
|
+
updateProfilePicturePrivacy,
|
|
1093
|
+
updateStatusPrivacy,
|
|
1094
|
+
updateReadReceiptsPrivacy,
|
|
1095
|
+
updateGroupsAddPrivacy,
|
|
1096
|
+
updateDefaultDisappearingMode,
|
|
1097
|
+
getBusinessProfile,
|
|
1098
|
+
resyncAppState,
|
|
1099
|
+
chatModify,
|
|
1100
|
+
cleanDirtyBits,
|
|
1101
|
+
addOrEditContact,
|
|
1102
|
+
removeContact,
|
|
1103
|
+
placeholderResendCache,
|
|
1104
|
+
addLabel,
|
|
1105
|
+
addChatLabel,
|
|
1106
|
+
removeChatLabel,
|
|
1107
|
+
addMessageLabel,
|
|
1108
|
+
removeMessageLabel,
|
|
1109
|
+
star,
|
|
1110
|
+
addOrEditQuickReply,
|
|
1111
|
+
removeQuickReply
|
|
1112
|
+
};
|
|
1113
|
+
};
|
|
1114
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1115
|
+
0 && (module.exports = {
|
|
1116
|
+
buildProfilePictureQueryContent,
|
|
1117
|
+
makeChatsSocket
|
|
1118
|
+
});
|