@eduh_dev021/baileys 0.0.0-stage → 1.1.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 +1843 -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/cache.js +179 -0
- package/cjs/lib/Addon/crc32.js +41 -0
- package/cjs/lib/Addon/file-type.js +217 -0
- package/cjs/lib/Addon/get-file.js +99 -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 +96 -0
- package/cjs/lib/Addon/index.js +58 -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/Addon/media-info.js +98 -0
- package/cjs/lib/Addon/mutex.js +78 -0
- package/cjs/lib/Addon/qr.js +464 -0
- package/cjs/lib/Addon/queue.js +54 -0
- package/cjs/lib/Addon/waveform.js +130 -0
- package/cjs/lib/Addon/zip.js +136 -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/cache.js +201 -0
- package/lib/Addon/crc32.js +21 -0
- package/lib/Addon/file-type.js +198 -0
- package/lib/Addon/get-file.js +98 -0
- package/lib/Addon/http-error.d.ts +18 -0
- package/lib/Addon/http-error.js +40 -0
- package/lib/Addon/index.d.ts +96 -0
- package/lib/Addon/index.js +26 -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/Addon/media-info.js +96 -0
- package/lib/Addon/mutex.js +76 -0
- package/lib/Addon/qr.js +531 -0
- package/lib/Addon/queue.js +44 -0
- package/lib/Addon/waveform.js +135 -0
- package/lib/Addon/zip.js +144 -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 +1907 -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 +366 -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 +226 -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 +74 -5
- package/tests/addon-test.mjs +162 -0
- package/tests/differential-test.mjs +90 -0
|
@@ -0,0 +1,821 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var chat_utils_exports = {};
|
|
19
|
+
__export(chat_utils_exports, {
|
|
20
|
+
MAX_SYNC_ATTEMPTS: () => MAX_SYNC_ATTEMPTS,
|
|
21
|
+
chatModificationToAppPatch: () => chatModificationToAppPatch,
|
|
22
|
+
decodePatches: () => decodePatches,
|
|
23
|
+
decodeSyncdMutations: () => decodeSyncdMutations,
|
|
24
|
+
decodeSyncdPatch: () => decodeSyncdPatch,
|
|
25
|
+
decodeSyncdSnapshot: () => decodeSyncdSnapshot,
|
|
26
|
+
downloadExternalBlob: () => downloadExternalBlob,
|
|
27
|
+
downloadExternalPatch: () => downloadExternalPatch,
|
|
28
|
+
encodeSyncdPatch: () => encodeSyncdPatch,
|
|
29
|
+
ensureLTHashStateVersion: () => ensureLTHashStateVersion,
|
|
30
|
+
extractSyncdPatches: () => extractSyncdPatches,
|
|
31
|
+
isAppStateSyncIrrecoverable: () => isAppStateSyncIrrecoverable,
|
|
32
|
+
isMissingKeyError: () => isMissingKeyError,
|
|
33
|
+
makeLtHashGenerator: () => makeLtHashGenerator,
|
|
34
|
+
newLTHashState: () => newLTHashState,
|
|
35
|
+
processSyncAction: () => processSyncAction
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(chat_utils_exports);
|
|
38
|
+
var import_WACrypto = require("../WACrypto/index.js");
|
|
39
|
+
var import_WAProto = require("../../WAProto/index.js");
|
|
40
|
+
var import_Addon = require("../Addon/index.js");
|
|
41
|
+
var import_LabelAssociation = require("../Types/LabelAssociation.js");
|
|
42
|
+
var import_WABinary = require("../WABinary/index.js");
|
|
43
|
+
var import_crypto = require("./crypto.js");
|
|
44
|
+
var import_generics = require("./generics.js");
|
|
45
|
+
var import_lt_hash = require("./lt-hash.js");
|
|
46
|
+
var import_messages_media = require("./messages-media.js");
|
|
47
|
+
var import_sync_action_utils = require("./sync-action-utils.js");
|
|
48
|
+
const mutationKeys = (keydata) => {
|
|
49
|
+
const keys = (0, import_WACrypto.expandAppStateKeys)(keydata);
|
|
50
|
+
return {
|
|
51
|
+
indexKey: keys.indexKey,
|
|
52
|
+
valueEncryptionKey: keys.valueEncryptionKey,
|
|
53
|
+
valueMacKey: keys.valueMacKey,
|
|
54
|
+
snapshotMacKey: keys.snapshotMacKey,
|
|
55
|
+
patchMacKey: keys.patchMacKey
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
const generateMac = (operation, data, keyId, key) => {
|
|
59
|
+
const opByte = operation === import_WAProto.proto.SyncdMutation.SyncdOperation.SET ? 1 : 2;
|
|
60
|
+
const keyIdBuffer = typeof keyId === "string" ? Buffer.from(keyId, "base64") : keyId;
|
|
61
|
+
const keyData = new Uint8Array(1 + keyIdBuffer.length);
|
|
62
|
+
keyData[0] = opByte;
|
|
63
|
+
keyData.set(keyIdBuffer, 1);
|
|
64
|
+
const last = new Uint8Array(8);
|
|
65
|
+
last[7] = keyData.length;
|
|
66
|
+
const total = new Uint8Array(keyData.length + data.length + last.length);
|
|
67
|
+
total.set(keyData, 0);
|
|
68
|
+
total.set(data, keyData.length);
|
|
69
|
+
total.set(last, keyData.length + data.length);
|
|
70
|
+
const hmac = (0, import_crypto.hmacSign)(total, key, "sha512");
|
|
71
|
+
return hmac.subarray(0, 32);
|
|
72
|
+
};
|
|
73
|
+
const to64BitNetworkOrder = (e) => {
|
|
74
|
+
const buff = Buffer.alloc(8);
|
|
75
|
+
buff.writeUint32BE(e, 4);
|
|
76
|
+
return buff;
|
|
77
|
+
};
|
|
78
|
+
const makeLtHashGenerator = ({ indexValueMap, hash }) => {
|
|
79
|
+
indexValueMap = { ...indexValueMap };
|
|
80
|
+
const addBuffs = [];
|
|
81
|
+
const subBuffs = [];
|
|
82
|
+
return {
|
|
83
|
+
mix: ({ indexMac, valueMac, operation }) => {
|
|
84
|
+
const indexMacBase64 = Buffer.from(indexMac).toString("base64");
|
|
85
|
+
const prevOp = indexValueMap[indexMacBase64];
|
|
86
|
+
if (operation === import_WAProto.proto.SyncdMutation.SyncdOperation.REMOVE) {
|
|
87
|
+
if (!prevOp) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
delete indexValueMap[indexMacBase64];
|
|
91
|
+
} else {
|
|
92
|
+
addBuffs.push(valueMac);
|
|
93
|
+
indexValueMap[indexMacBase64] = { valueMac };
|
|
94
|
+
}
|
|
95
|
+
if (prevOp) {
|
|
96
|
+
subBuffs.push(prevOp.valueMac);
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
finish: () => {
|
|
100
|
+
const result = import_lt_hash.LT_HASH_ANTI_TAMPERING.subtractThenAdd(hash, subBuffs, addBuffs);
|
|
101
|
+
return {
|
|
102
|
+
hash: Buffer.from(result),
|
|
103
|
+
indexValueMap
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
const generateSnapshotMac = (lthash, version, name, key) => {
|
|
109
|
+
const total = Buffer.concat([lthash, to64BitNetworkOrder(version), Buffer.from(name, "utf-8")]);
|
|
110
|
+
return (0, import_crypto.hmacSign)(total, key, "sha256");
|
|
111
|
+
};
|
|
112
|
+
const generatePatchMac = (snapshotMac, valueMacs, version, type, key) => {
|
|
113
|
+
const total = Buffer.concat([snapshotMac, ...valueMacs, to64BitNetworkOrder(version), Buffer.from(type, "utf-8")]);
|
|
114
|
+
return (0, import_crypto.hmacSign)(total, key);
|
|
115
|
+
};
|
|
116
|
+
const newLTHashState = () => ({ version: 0, hash: Buffer.alloc(128), indexValueMap: {} });
|
|
117
|
+
const ensureLTHashStateVersion = (state) => {
|
|
118
|
+
if (typeof state.version !== "number" || isNaN(state.version)) {
|
|
119
|
+
state.version = 0;
|
|
120
|
+
}
|
|
121
|
+
return state;
|
|
122
|
+
};
|
|
123
|
+
const MAX_SYNC_ATTEMPTS = 2;
|
|
124
|
+
const isMissingKeyError = (error) => {
|
|
125
|
+
return error?.data?.isMissingKey === true;
|
|
126
|
+
};
|
|
127
|
+
const isAppStateSyncIrrecoverable = (error, attempts) => {
|
|
128
|
+
return attempts >= MAX_SYNC_ATTEMPTS || error?.name === "TypeError";
|
|
129
|
+
};
|
|
130
|
+
const encodeSyncdPatch = async ({ type, index, syncAction, apiVersion, operation }, myAppStateKeyId, state, getAppStateSyncKey) => {
|
|
131
|
+
const key = !!myAppStateKeyId ? await getAppStateSyncKey(myAppStateKeyId) : void 0;
|
|
132
|
+
if (!key) {
|
|
133
|
+
throw new import_Addon.HttpError(`myAppStateKey ("${myAppStateKeyId}") not present`, { data: { isMissingKey: true } });
|
|
134
|
+
}
|
|
135
|
+
const encKeyId = Buffer.from(myAppStateKeyId, "base64");
|
|
136
|
+
state = { ...state, indexValueMap: { ...state.indexValueMap } };
|
|
137
|
+
const indexBuffer = Buffer.from(JSON.stringify(index));
|
|
138
|
+
const dataProto = import_WAProto.proto.SyncActionData.fromObject({
|
|
139
|
+
index: indexBuffer,
|
|
140
|
+
value: syncAction,
|
|
141
|
+
padding: new Uint8Array(0),
|
|
142
|
+
version: apiVersion
|
|
143
|
+
});
|
|
144
|
+
const encoded = import_WAProto.proto.SyncActionData.encode(dataProto).finish();
|
|
145
|
+
const keyValue = mutationKeys(key.keyData);
|
|
146
|
+
const encValue = (0, import_crypto.aesEncrypt)(encoded, keyValue.valueEncryptionKey);
|
|
147
|
+
const valueMac = generateMac(operation, encValue, encKeyId, keyValue.valueMacKey);
|
|
148
|
+
const indexMac = (0, import_crypto.hmacSign)(indexBuffer, keyValue.indexKey);
|
|
149
|
+
const generator = makeLtHashGenerator(state);
|
|
150
|
+
generator.mix({ indexMac, valueMac, operation });
|
|
151
|
+
Object.assign(state, generator.finish());
|
|
152
|
+
state.version += 1;
|
|
153
|
+
const snapshotMac = generateSnapshotMac(state.hash, state.version, type, keyValue.snapshotMacKey);
|
|
154
|
+
const patch = {
|
|
155
|
+
patchMac: generatePatchMac(snapshotMac, [valueMac], state.version, type, keyValue.patchMacKey),
|
|
156
|
+
snapshotMac,
|
|
157
|
+
keyId: { id: encKeyId },
|
|
158
|
+
mutations: [
|
|
159
|
+
{
|
|
160
|
+
operation,
|
|
161
|
+
record: {
|
|
162
|
+
index: {
|
|
163
|
+
blob: indexMac
|
|
164
|
+
},
|
|
165
|
+
value: {
|
|
166
|
+
blob: Buffer.concat([encValue, valueMac])
|
|
167
|
+
},
|
|
168
|
+
keyId: { id: encKeyId }
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
]
|
|
172
|
+
};
|
|
173
|
+
const base64Index = indexMac.toString("base64");
|
|
174
|
+
state.indexValueMap[base64Index] = { valueMac };
|
|
175
|
+
return { patch, state };
|
|
176
|
+
};
|
|
177
|
+
const decodeSyncdMutations = async (msgMutations, initialState, getAppStateSyncKey, onMutation, validateMacs) => {
|
|
178
|
+
const ltGenerator = makeLtHashGenerator(initialState);
|
|
179
|
+
const derivedKeyCache = /* @__PURE__ */ new Map();
|
|
180
|
+
for (const msgMutation of msgMutations) {
|
|
181
|
+
const operation = "operation" in msgMutation ? msgMutation.operation : import_WAProto.proto.SyncdMutation.SyncdOperation.SET;
|
|
182
|
+
const record = "record" in msgMutation && !!msgMutation.record ? msgMutation.record : msgMutation;
|
|
183
|
+
let key;
|
|
184
|
+
try {
|
|
185
|
+
key = await getKey(record.keyId.id);
|
|
186
|
+
} catch (err) {
|
|
187
|
+
if (isMissingKeyError(err))
|
|
188
|
+
throw err;
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
const content = record.value.blob;
|
|
192
|
+
const encContent = content.subarray(0, -32);
|
|
193
|
+
const ogValueMac = content.subarray(-32);
|
|
194
|
+
if (validateMacs) {
|
|
195
|
+
const contentHmac = generateMac(operation, encContent, record.keyId.id, key.valueMacKey);
|
|
196
|
+
if (Buffer.compare(contentHmac, ogValueMac) !== 0) {
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
let result;
|
|
201
|
+
try {
|
|
202
|
+
result = (0, import_crypto.aesDecrypt)(encContent, key.valueEncryptionKey);
|
|
203
|
+
} catch {
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
const syncAction = import_WAProto.proto.SyncActionData.decode(result);
|
|
207
|
+
if (validateMacs) {
|
|
208
|
+
const hmac = (0, import_crypto.hmacSign)(syncAction.index, key.indexKey);
|
|
209
|
+
if (Buffer.compare(hmac, record.index.blob) !== 0) {
|
|
210
|
+
throw new import_Addon.HttpError("HMAC index verification failed");
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
const indexStr = Buffer.from(syncAction.index).toString();
|
|
214
|
+
onMutation({ syncAction, index: JSON.parse(indexStr) });
|
|
215
|
+
ltGenerator.mix({
|
|
216
|
+
indexMac: record.index.blob,
|
|
217
|
+
valueMac: ogValueMac,
|
|
218
|
+
operation
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
return ltGenerator.finish();
|
|
222
|
+
async function getKey(keyId) {
|
|
223
|
+
const base64Key = Buffer.from(keyId).toString("base64");
|
|
224
|
+
const cached = derivedKeyCache.get(base64Key);
|
|
225
|
+
if (cached) {
|
|
226
|
+
return cached;
|
|
227
|
+
}
|
|
228
|
+
const keyEnc = await getAppStateSyncKey(base64Key);
|
|
229
|
+
if (!keyEnc) {
|
|
230
|
+
throw new import_Addon.HttpError(`failed to find key "${base64Key}" to decode mutation`, {
|
|
231
|
+
data: { isMissingKey: true, msgMutations }
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
const keys = mutationKeys(keyEnc.keyData);
|
|
235
|
+
derivedKeyCache.set(base64Key, keys);
|
|
236
|
+
return keys;
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
const decodeSyncdPatch = async (msg, name, initialState, getAppStateSyncKey, onMutation, validateMacs) => {
|
|
240
|
+
if (validateMacs) {
|
|
241
|
+
const base64Key = Buffer.from(msg.keyId.id).toString("base64");
|
|
242
|
+
const mainKeyObj = await getAppStateSyncKey(base64Key);
|
|
243
|
+
if (!mainKeyObj) {
|
|
244
|
+
throw new import_Addon.HttpError(`failed to find key "${base64Key}" to decode patch`, { data: { isMissingKey: true, msg } });
|
|
245
|
+
}
|
|
246
|
+
const mainKey = mutationKeys(mainKeyObj.keyData);
|
|
247
|
+
const mutationmacs = msg.mutations.map((mutation) => mutation.record.value.blob.slice(-32));
|
|
248
|
+
const patchMac = generatePatchMac(msg.snapshotMac, mutationmacs, (0, import_generics.toNumber)(msg.version.version), name, mainKey.patchMacKey);
|
|
249
|
+
if (Buffer.compare(patchMac, msg.patchMac) !== 0) {
|
|
250
|
+
throw new import_Addon.HttpError("Invalid patch mac");
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
const result = await decodeSyncdMutations(msg.mutations, initialState, getAppStateSyncKey, onMutation, validateMacs);
|
|
254
|
+
return result;
|
|
255
|
+
};
|
|
256
|
+
const extractSyncdPatches = async (result, options) => {
|
|
257
|
+
const syncNode = (0, import_WABinary.getBinaryNodeChild)(result, "sync");
|
|
258
|
+
const collectionNodes = (0, import_WABinary.getBinaryNodeChildren)(syncNode, "collection");
|
|
259
|
+
const final = {};
|
|
260
|
+
await Promise.all(collectionNodes.map(async (collectionNode) => {
|
|
261
|
+
const patchesNode = (0, import_WABinary.getBinaryNodeChild)(collectionNode, "patches");
|
|
262
|
+
const patches = (0, import_WABinary.getBinaryNodeChildren)(patchesNode || collectionNode, "patch");
|
|
263
|
+
const snapshotNode = (0, import_WABinary.getBinaryNodeChild)(collectionNode, "snapshot");
|
|
264
|
+
const syncds = [];
|
|
265
|
+
const name = collectionNode.attrs.name;
|
|
266
|
+
const hasMorePatches = collectionNode.attrs.has_more_patches === "true";
|
|
267
|
+
let snapshot = void 0;
|
|
268
|
+
if (snapshotNode && !!snapshotNode.content) {
|
|
269
|
+
if (!Buffer.isBuffer(snapshotNode)) {
|
|
270
|
+
snapshotNode.content = Buffer.from(Object.values(snapshotNode.content));
|
|
271
|
+
}
|
|
272
|
+
const blobRef = import_WAProto.proto.ExternalBlobReference.decode(snapshotNode.content);
|
|
273
|
+
const data = await downloadExternalBlob(blobRef, options);
|
|
274
|
+
snapshot = import_WAProto.proto.SyncdSnapshot.decode(data);
|
|
275
|
+
}
|
|
276
|
+
for (let { content } of patches) {
|
|
277
|
+
if (content) {
|
|
278
|
+
if (!Buffer.isBuffer(content)) {
|
|
279
|
+
content = Buffer.from(Object.values(content));
|
|
280
|
+
}
|
|
281
|
+
const syncd = import_WAProto.proto.SyncdPatch.decode(content);
|
|
282
|
+
if (!syncd.version) {
|
|
283
|
+
syncd.version = { version: +collectionNode.attrs.version + 1 };
|
|
284
|
+
}
|
|
285
|
+
syncds.push(syncd);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
final[name] = { patches: syncds, hasMorePatches, snapshot };
|
|
289
|
+
}));
|
|
290
|
+
return final;
|
|
291
|
+
};
|
|
292
|
+
const downloadExternalBlob = async (blob, options) => {
|
|
293
|
+
const stream = await (0, import_messages_media.downloadContentFromMessage)(blob, "md-app-state", { options });
|
|
294
|
+
const bufferArray = [];
|
|
295
|
+
for await (const chunk of stream) {
|
|
296
|
+
bufferArray.push(chunk);
|
|
297
|
+
}
|
|
298
|
+
return Buffer.concat(bufferArray);
|
|
299
|
+
};
|
|
300
|
+
const downloadExternalPatch = async (blob, options) => {
|
|
301
|
+
const buffer = await downloadExternalBlob(blob, options);
|
|
302
|
+
const syncData = import_WAProto.proto.SyncdMutations.decode(buffer);
|
|
303
|
+
return syncData;
|
|
304
|
+
};
|
|
305
|
+
const decodeSyncdSnapshot = async (name, snapshot, getAppStateSyncKey, minimumVersionNumber, validateMacs = true, logger) => {
|
|
306
|
+
const newState = newLTHashState();
|
|
307
|
+
newState.version = (0, import_generics.toNumber)(snapshot.version.version);
|
|
308
|
+
const mutationMap = {};
|
|
309
|
+
const areMutationsRequired = typeof minimumVersionNumber === "undefined" || newState.version > minimumVersionNumber;
|
|
310
|
+
const { hash, indexValueMap } = await decodeSyncdMutations(snapshot.records, newState, getAppStateSyncKey, areMutationsRequired ? (mutation) => {
|
|
311
|
+
const index = mutation.syncAction.index?.toString();
|
|
312
|
+
mutationMap[index] = mutation;
|
|
313
|
+
} : () => {
|
|
314
|
+
}, validateMacs);
|
|
315
|
+
newState.hash = hash;
|
|
316
|
+
newState.indexValueMap = indexValueMap;
|
|
317
|
+
if (validateMacs) {
|
|
318
|
+
const base64Key = Buffer.from(snapshot.keyId.id).toString("base64");
|
|
319
|
+
const keyEnc = await getAppStateSyncKey(base64Key);
|
|
320
|
+
if (!keyEnc) {
|
|
321
|
+
throw new import_Addon.HttpError(`failed to find key "${base64Key}" to decode mutation`, { data: { isMissingKey: true } });
|
|
322
|
+
}
|
|
323
|
+
const result = mutationKeys(keyEnc.keyData);
|
|
324
|
+
const computedSnapshotMac = generateSnapshotMac(newState.hash, newState.version, name, result.snapshotMacKey);
|
|
325
|
+
if (Buffer.compare(snapshot.mac, computedSnapshotMac) !== 0) {
|
|
326
|
+
logger?.warn({ name, version: newState.version }, "LTHash verification failed on snapshot, continuing with partial state");
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
return {
|
|
330
|
+
state: newState,
|
|
331
|
+
mutationMap
|
|
332
|
+
};
|
|
333
|
+
};
|
|
334
|
+
const decodePatches = async (name, syncds, initial, getAppStateSyncKey, options, minimumVersionNumber, logger, validateMacs = true) => {
|
|
335
|
+
const newState = {
|
|
336
|
+
...initial,
|
|
337
|
+
indexValueMap: { ...initial.indexValueMap }
|
|
338
|
+
};
|
|
339
|
+
const mutationMap = {};
|
|
340
|
+
for (const syncd of syncds) {
|
|
341
|
+
const { version, keyId, snapshotMac } = syncd;
|
|
342
|
+
if (syncd.externalMutations) {
|
|
343
|
+
logger?.trace({ name, version }, "downloading external patch");
|
|
344
|
+
const ref = await downloadExternalPatch(syncd.externalMutations, options);
|
|
345
|
+
logger?.debug({ name, version, mutations: ref.mutations.length }, "downloaded external patch");
|
|
346
|
+
syncd.mutations?.push(...ref.mutations);
|
|
347
|
+
}
|
|
348
|
+
const patchVersion = (0, import_generics.toNumber)(version.version);
|
|
349
|
+
newState.version = patchVersion;
|
|
350
|
+
const shouldMutate = typeof minimumVersionNumber === "undefined" || patchVersion > minimumVersionNumber;
|
|
351
|
+
let decodeResult;
|
|
352
|
+
try {
|
|
353
|
+
decodeResult = await decodeSyncdPatch(syncd, name, newState, getAppStateSyncKey, shouldMutate ? (mutation) => {
|
|
354
|
+
const index = mutation.syncAction.index?.toString();
|
|
355
|
+
mutationMap[index] = mutation;
|
|
356
|
+
} : () => {
|
|
357
|
+
}, validateMacs);
|
|
358
|
+
} catch (err) {
|
|
359
|
+
if (isMissingKeyError(err))
|
|
360
|
+
throw err;
|
|
361
|
+
logger?.warn({ name, version: patchVersion, error: err.message }, "failed to decode patch, skipping");
|
|
362
|
+
continue;
|
|
363
|
+
}
|
|
364
|
+
newState.hash = decodeResult.hash;
|
|
365
|
+
newState.indexValueMap = decodeResult.indexValueMap;
|
|
366
|
+
if (validateMacs) {
|
|
367
|
+
const base64Key = Buffer.from(keyId.id).toString("base64");
|
|
368
|
+
const keyEnc = await getAppStateSyncKey(base64Key);
|
|
369
|
+
if (!keyEnc) {
|
|
370
|
+
throw new import_Addon.HttpError(`failed to find key "${base64Key}" to decode mutation`, { data: { isMissingKey: true } });
|
|
371
|
+
}
|
|
372
|
+
const result = mutationKeys(keyEnc.keyData);
|
|
373
|
+
const computedSnapshotMac = generateSnapshotMac(newState.hash, newState.version, name, result.snapshotMacKey);
|
|
374
|
+
if (Buffer.compare(snapshotMac, computedSnapshotMac) !== 0) {
|
|
375
|
+
logger?.warn({ name, version: newState.version }, "LTHash verification failed, skipping remaining patches");
|
|
376
|
+
break;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
syncd.mutations = [];
|
|
380
|
+
}
|
|
381
|
+
return { state: newState, mutationMap };
|
|
382
|
+
};
|
|
383
|
+
const chatModificationToAppPatch = (mod, jid) => {
|
|
384
|
+
const OP = import_WAProto.proto.SyncdMutation.SyncdOperation;
|
|
385
|
+
const getMessageRange = (lastMessages) => {
|
|
386
|
+
let messageRange;
|
|
387
|
+
if (Array.isArray(lastMessages)) {
|
|
388
|
+
const lastMsg = lastMessages[lastMessages.length - 1];
|
|
389
|
+
messageRange = {
|
|
390
|
+
lastMessageTimestamp: lastMsg?.messageTimestamp,
|
|
391
|
+
messages: lastMessages?.length ? lastMessages.map((m) => {
|
|
392
|
+
if (!m.key?.id || !m.key?.remoteJid) {
|
|
393
|
+
throw new import_Addon.HttpError("Incomplete key", { statusCode: 400, data: m });
|
|
394
|
+
}
|
|
395
|
+
if ((0, import_WABinary.isJidGroup)(m.key.remoteJid) && !m.key.fromMe && !m.key.participant) {
|
|
396
|
+
throw new import_Addon.HttpError("Expected not from me message to have participant", { statusCode: 400, data: m });
|
|
397
|
+
}
|
|
398
|
+
if (!m.messageTimestamp || !(0, import_generics.toNumber)(m.messageTimestamp)) {
|
|
399
|
+
throw new import_Addon.HttpError("Missing timestamp in last message list", { statusCode: 400, data: m });
|
|
400
|
+
}
|
|
401
|
+
if (m.key.participant) {
|
|
402
|
+
m.key.participant = (0, import_WABinary.jidNormalizedUser)(m.key.participant);
|
|
403
|
+
}
|
|
404
|
+
return m;
|
|
405
|
+
}) : void 0
|
|
406
|
+
};
|
|
407
|
+
} else {
|
|
408
|
+
messageRange = lastMessages;
|
|
409
|
+
}
|
|
410
|
+
return messageRange;
|
|
411
|
+
};
|
|
412
|
+
let patch;
|
|
413
|
+
if ("mute" in mod) {
|
|
414
|
+
patch = {
|
|
415
|
+
syncAction: {
|
|
416
|
+
muteAction: {
|
|
417
|
+
muted: !!mod.mute,
|
|
418
|
+
muteEndTimestamp: mod.mute || void 0
|
|
419
|
+
}
|
|
420
|
+
},
|
|
421
|
+
index: ["mute", jid],
|
|
422
|
+
type: "regular_high",
|
|
423
|
+
apiVersion: 2,
|
|
424
|
+
operation: OP.SET
|
|
425
|
+
};
|
|
426
|
+
} else if ("archive" in mod) {
|
|
427
|
+
patch = {
|
|
428
|
+
syncAction: {
|
|
429
|
+
archiveChatAction: {
|
|
430
|
+
archived: !!mod.archive,
|
|
431
|
+
messageRange: getMessageRange(mod.lastMessages)
|
|
432
|
+
}
|
|
433
|
+
},
|
|
434
|
+
index: ["archive", jid],
|
|
435
|
+
type: "regular_low",
|
|
436
|
+
apiVersion: 3,
|
|
437
|
+
operation: OP.SET
|
|
438
|
+
};
|
|
439
|
+
} else if ("markRead" in mod) {
|
|
440
|
+
patch = {
|
|
441
|
+
syncAction: {
|
|
442
|
+
markChatAsReadAction: {
|
|
443
|
+
read: mod.markRead,
|
|
444
|
+
messageRange: getMessageRange(mod.lastMessages)
|
|
445
|
+
}
|
|
446
|
+
},
|
|
447
|
+
index: ["markChatAsRead", jid],
|
|
448
|
+
type: "regular_low",
|
|
449
|
+
apiVersion: 3,
|
|
450
|
+
operation: OP.SET
|
|
451
|
+
};
|
|
452
|
+
} else if ("deleteForMe" in mod) {
|
|
453
|
+
const { timestamp, key, deleteMedia } = mod.deleteForMe;
|
|
454
|
+
patch = {
|
|
455
|
+
syncAction: {
|
|
456
|
+
deleteMessageForMeAction: {
|
|
457
|
+
deleteMedia,
|
|
458
|
+
messageTimestamp: timestamp
|
|
459
|
+
}
|
|
460
|
+
},
|
|
461
|
+
index: ["deleteMessageForMe", jid, key.id, key.fromMe ? "1" : "0", "0"],
|
|
462
|
+
type: "regular_high",
|
|
463
|
+
apiVersion: 3,
|
|
464
|
+
operation: OP.SET
|
|
465
|
+
};
|
|
466
|
+
} else if ("clear" in mod) {
|
|
467
|
+
patch = {
|
|
468
|
+
syncAction: {
|
|
469
|
+
clearChatAction: {
|
|
470
|
+
messageRange: getMessageRange(mod.lastMessages)
|
|
471
|
+
}
|
|
472
|
+
},
|
|
473
|
+
index: ["clearChat", jid, "1", "0"],
|
|
474
|
+
type: "regular_high",
|
|
475
|
+
apiVersion: 6,
|
|
476
|
+
operation: OP.SET
|
|
477
|
+
};
|
|
478
|
+
} else if ("pin" in mod) {
|
|
479
|
+
patch = {
|
|
480
|
+
syncAction: {
|
|
481
|
+
pinAction: {
|
|
482
|
+
pinned: !!mod.pin
|
|
483
|
+
}
|
|
484
|
+
},
|
|
485
|
+
index: ["pin_v1", jid],
|
|
486
|
+
type: "regular_low",
|
|
487
|
+
apiVersion: 5,
|
|
488
|
+
operation: OP.SET
|
|
489
|
+
};
|
|
490
|
+
} else if ("contact" in mod) {
|
|
491
|
+
patch = {
|
|
492
|
+
syncAction: {
|
|
493
|
+
contactAction: mod.contact || {}
|
|
494
|
+
},
|
|
495
|
+
index: ["contact", jid],
|
|
496
|
+
type: "critical_unblock_low",
|
|
497
|
+
apiVersion: 2,
|
|
498
|
+
operation: mod.contact ? OP.SET : OP.REMOVE
|
|
499
|
+
};
|
|
500
|
+
} else if ("disableLinkPreviews" in mod) {
|
|
501
|
+
patch = {
|
|
502
|
+
syncAction: {
|
|
503
|
+
privacySettingDisableLinkPreviewsAction: mod.disableLinkPreviews || {}
|
|
504
|
+
},
|
|
505
|
+
index: ["setting_disableLinkPreviews"],
|
|
506
|
+
type: "regular",
|
|
507
|
+
apiVersion: 8,
|
|
508
|
+
operation: OP.SET
|
|
509
|
+
};
|
|
510
|
+
} else if ("star" in mod) {
|
|
511
|
+
const key = mod.star.messages[0];
|
|
512
|
+
patch = {
|
|
513
|
+
syncAction: {
|
|
514
|
+
starAction: {
|
|
515
|
+
starred: !!mod.star.star
|
|
516
|
+
}
|
|
517
|
+
},
|
|
518
|
+
index: ["star", jid, key.id, key.fromMe ? "1" : "0", "0"],
|
|
519
|
+
type: "regular_low",
|
|
520
|
+
apiVersion: 2,
|
|
521
|
+
operation: OP.SET
|
|
522
|
+
};
|
|
523
|
+
} else if ("delete" in mod) {
|
|
524
|
+
patch = {
|
|
525
|
+
syncAction: {
|
|
526
|
+
deleteChatAction: {
|
|
527
|
+
messageRange: getMessageRange(mod.lastMessages)
|
|
528
|
+
}
|
|
529
|
+
},
|
|
530
|
+
index: ["deleteChat", jid, "1"],
|
|
531
|
+
type: "regular_high",
|
|
532
|
+
apiVersion: 6,
|
|
533
|
+
operation: OP.SET
|
|
534
|
+
};
|
|
535
|
+
} else if ("pushNameSetting" in mod) {
|
|
536
|
+
patch = {
|
|
537
|
+
syncAction: {
|
|
538
|
+
pushNameSetting: {
|
|
539
|
+
name: mod.pushNameSetting
|
|
540
|
+
}
|
|
541
|
+
},
|
|
542
|
+
index: ["setting_pushName"],
|
|
543
|
+
type: "critical_block",
|
|
544
|
+
apiVersion: 1,
|
|
545
|
+
operation: OP.SET
|
|
546
|
+
};
|
|
547
|
+
} else if ("quickReply" in mod) {
|
|
548
|
+
patch = {
|
|
549
|
+
syncAction: {
|
|
550
|
+
quickReplyAction: {
|
|
551
|
+
count: 0,
|
|
552
|
+
deleted: mod.quickReply.deleted || false,
|
|
553
|
+
keywords: [],
|
|
554
|
+
message: mod.quickReply.message || "",
|
|
555
|
+
shortcut: mod.quickReply.shortcut || ""
|
|
556
|
+
}
|
|
557
|
+
},
|
|
558
|
+
index: ["quick_reply", mod.quickReply.timestamp || String(Math.floor(Date.now() / 1e3))],
|
|
559
|
+
type: "regular",
|
|
560
|
+
apiVersion: 2,
|
|
561
|
+
operation: OP.SET
|
|
562
|
+
};
|
|
563
|
+
} else if ("addLabel" in mod) {
|
|
564
|
+
patch = {
|
|
565
|
+
syncAction: {
|
|
566
|
+
labelEditAction: {
|
|
567
|
+
name: mod.addLabel.name,
|
|
568
|
+
color: mod.addLabel.color,
|
|
569
|
+
predefinedId: mod.addLabel.predefinedId,
|
|
570
|
+
deleted: mod.addLabel.deleted
|
|
571
|
+
}
|
|
572
|
+
},
|
|
573
|
+
index: ["label_edit", mod.addLabel.id],
|
|
574
|
+
type: "regular",
|
|
575
|
+
apiVersion: 3,
|
|
576
|
+
operation: OP.SET
|
|
577
|
+
};
|
|
578
|
+
} else if ("addChatLabel" in mod) {
|
|
579
|
+
patch = {
|
|
580
|
+
syncAction: {
|
|
581
|
+
labelAssociationAction: {
|
|
582
|
+
labeled: true
|
|
583
|
+
}
|
|
584
|
+
},
|
|
585
|
+
index: [import_LabelAssociation.LabelAssociationType.Chat, mod.addChatLabel.labelId, jid],
|
|
586
|
+
type: "regular",
|
|
587
|
+
apiVersion: 3,
|
|
588
|
+
operation: OP.SET
|
|
589
|
+
};
|
|
590
|
+
} else if ("removeChatLabel" in mod) {
|
|
591
|
+
patch = {
|
|
592
|
+
syncAction: {
|
|
593
|
+
labelAssociationAction: {
|
|
594
|
+
labeled: false
|
|
595
|
+
}
|
|
596
|
+
},
|
|
597
|
+
index: [import_LabelAssociation.LabelAssociationType.Chat, mod.removeChatLabel.labelId, jid],
|
|
598
|
+
type: "regular",
|
|
599
|
+
apiVersion: 3,
|
|
600
|
+
operation: OP.SET
|
|
601
|
+
};
|
|
602
|
+
} else if ("addMessageLabel" in mod) {
|
|
603
|
+
patch = {
|
|
604
|
+
syncAction: {
|
|
605
|
+
labelAssociationAction: {
|
|
606
|
+
labeled: true
|
|
607
|
+
}
|
|
608
|
+
},
|
|
609
|
+
index: [import_LabelAssociation.LabelAssociationType.Message, mod.addMessageLabel.labelId, jid, mod.addMessageLabel.messageId, "0", "0"],
|
|
610
|
+
type: "regular",
|
|
611
|
+
apiVersion: 3,
|
|
612
|
+
operation: OP.SET
|
|
613
|
+
};
|
|
614
|
+
} else if ("removeMessageLabel" in mod) {
|
|
615
|
+
patch = {
|
|
616
|
+
syncAction: {
|
|
617
|
+
labelAssociationAction: {
|
|
618
|
+
labeled: false
|
|
619
|
+
}
|
|
620
|
+
},
|
|
621
|
+
index: [
|
|
622
|
+
import_LabelAssociation.LabelAssociationType.Message,
|
|
623
|
+
mod.removeMessageLabel.labelId,
|
|
624
|
+
jid,
|
|
625
|
+
mod.removeMessageLabel.messageId,
|
|
626
|
+
"0",
|
|
627
|
+
"0"
|
|
628
|
+
],
|
|
629
|
+
type: "regular",
|
|
630
|
+
apiVersion: 3,
|
|
631
|
+
operation: OP.SET
|
|
632
|
+
};
|
|
633
|
+
} else {
|
|
634
|
+
throw new import_Addon.HttpError("not supported");
|
|
635
|
+
}
|
|
636
|
+
patch.syncAction.timestamp = Date.now();
|
|
637
|
+
return patch;
|
|
638
|
+
};
|
|
639
|
+
const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
640
|
+
const isInitialSync = !!initialSyncOpts;
|
|
641
|
+
const accountSettings = initialSyncOpts?.accountSettings;
|
|
642
|
+
logger?.trace({ syncAction, initialSync: !!initialSyncOpts }, "processing sync action");
|
|
643
|
+
const { syncAction: { value: action }, index: [type, id, msgId, fromMe] } = syncAction;
|
|
644
|
+
if (action?.muteAction) {
|
|
645
|
+
ev.emit("chats.update", [
|
|
646
|
+
{
|
|
647
|
+
id,
|
|
648
|
+
muteEndTime: action.muteAction?.muted ? (0, import_generics.toNumber)(action.muteAction.muteEndTimestamp) : null,
|
|
649
|
+
conditional: getChatUpdateConditional(id, void 0)
|
|
650
|
+
}
|
|
651
|
+
]);
|
|
652
|
+
} else if (action?.archiveChatAction || type === "archive" || type === "unarchive") {
|
|
653
|
+
const archiveAction = action?.archiveChatAction;
|
|
654
|
+
const isArchived = archiveAction ? archiveAction.archived : type === "archive";
|
|
655
|
+
const msgRange = !accountSettings?.unarchiveChats ? void 0 : archiveAction?.messageRange;
|
|
656
|
+
ev.emit("chats.update", [
|
|
657
|
+
{
|
|
658
|
+
id,
|
|
659
|
+
archived: isArchived,
|
|
660
|
+
conditional: getChatUpdateConditional(id, msgRange)
|
|
661
|
+
}
|
|
662
|
+
]);
|
|
663
|
+
} else if (action?.markChatAsReadAction) {
|
|
664
|
+
const markReadAction = action.markChatAsReadAction;
|
|
665
|
+
const isNullUpdate = isInitialSync && markReadAction.read;
|
|
666
|
+
ev.emit("chats.update", [
|
|
667
|
+
{
|
|
668
|
+
id,
|
|
669
|
+
unreadCount: isNullUpdate ? null : !!markReadAction?.read ? 0 : -1,
|
|
670
|
+
conditional: getChatUpdateConditional(id, markReadAction?.messageRange)
|
|
671
|
+
}
|
|
672
|
+
]);
|
|
673
|
+
} else if (action?.deleteMessageForMeAction || type === "deleteMessageForMe") {
|
|
674
|
+
ev.emit("messages.delete", {
|
|
675
|
+
keys: [
|
|
676
|
+
{
|
|
677
|
+
remoteJid: id,
|
|
678
|
+
id: msgId,
|
|
679
|
+
fromMe: fromMe === "1"
|
|
680
|
+
}
|
|
681
|
+
]
|
|
682
|
+
});
|
|
683
|
+
} else if (action?.contactAction) {
|
|
684
|
+
const results = (0, import_sync_action_utils.processContactAction)(action.contactAction, id, logger);
|
|
685
|
+
(0, import_sync_action_utils.emitSyncActionResults)(ev, results);
|
|
686
|
+
} else if (action?.pushNameSetting) {
|
|
687
|
+
const name = action?.pushNameSetting?.name;
|
|
688
|
+
if (name && me?.name !== name) {
|
|
689
|
+
ev.emit("creds.update", { me: { ...me, name } });
|
|
690
|
+
}
|
|
691
|
+
} else if (action?.pinAction) {
|
|
692
|
+
ev.emit("chats.update", [
|
|
693
|
+
{
|
|
694
|
+
id,
|
|
695
|
+
pinned: action.pinAction?.pinned ? (0, import_generics.toNumber)(action.timestamp) : null,
|
|
696
|
+
conditional: getChatUpdateConditional(id, void 0)
|
|
697
|
+
}
|
|
698
|
+
]);
|
|
699
|
+
} else if (action?.unarchiveChatsSetting) {
|
|
700
|
+
const unarchiveChats = !!action.unarchiveChatsSetting.unarchiveChats;
|
|
701
|
+
ev.emit("creds.update", { accountSettings: { unarchiveChats } });
|
|
702
|
+
logger?.info(`archive setting updated => '${action.unarchiveChatsSetting.unarchiveChats}'`);
|
|
703
|
+
if (accountSettings) {
|
|
704
|
+
accountSettings.unarchiveChats = unarchiveChats;
|
|
705
|
+
}
|
|
706
|
+
} else if (action?.starAction || type === "star") {
|
|
707
|
+
let starred = action?.starAction?.starred;
|
|
708
|
+
if (typeof starred !== "boolean") {
|
|
709
|
+
starred = syncAction.index[syncAction.index.length - 1] === "1";
|
|
710
|
+
}
|
|
711
|
+
ev.emit("messages.update", [
|
|
712
|
+
{
|
|
713
|
+
key: { remoteJid: id, id: msgId, fromMe: fromMe === "1" },
|
|
714
|
+
update: { starred }
|
|
715
|
+
}
|
|
716
|
+
]);
|
|
717
|
+
} else if (action?.deleteChatAction || type === "deleteChat") {
|
|
718
|
+
if (!isInitialSync) {
|
|
719
|
+
ev.emit("chats.delete", [id]);
|
|
720
|
+
}
|
|
721
|
+
} else if (action?.labelEditAction) {
|
|
722
|
+
const { name, color, deleted, predefinedId } = action.labelEditAction;
|
|
723
|
+
ev.emit("labels.edit", {
|
|
724
|
+
id,
|
|
725
|
+
name,
|
|
726
|
+
color,
|
|
727
|
+
deleted,
|
|
728
|
+
predefinedId: predefinedId ? String(predefinedId) : void 0
|
|
729
|
+
});
|
|
730
|
+
} else if (action?.labelAssociationAction) {
|
|
731
|
+
ev.emit("labels.association", {
|
|
732
|
+
type: action.labelAssociationAction.labeled ? "add" : "remove",
|
|
733
|
+
association: type === import_LabelAssociation.LabelAssociationType.Chat ? {
|
|
734
|
+
type: import_LabelAssociation.LabelAssociationType.Chat,
|
|
735
|
+
chatId: syncAction.index[2],
|
|
736
|
+
labelId: syncAction.index[1]
|
|
737
|
+
} : {
|
|
738
|
+
type: import_LabelAssociation.LabelAssociationType.Message,
|
|
739
|
+
chatId: syncAction.index[2],
|
|
740
|
+
messageId: syncAction.index[3],
|
|
741
|
+
labelId: syncAction.index[1]
|
|
742
|
+
}
|
|
743
|
+
});
|
|
744
|
+
} else if (action?.localeSetting?.locale) {
|
|
745
|
+
ev.emit("settings.update", { setting: "locale", value: action.localeSetting.locale });
|
|
746
|
+
} else if (action?.timeFormatAction) {
|
|
747
|
+
ev.emit("settings.update", { setting: "timeFormat", value: action.timeFormatAction });
|
|
748
|
+
} else if (action?.pnForLidChatAction) {
|
|
749
|
+
if (action.pnForLidChatAction.pnJid) {
|
|
750
|
+
ev.emit("lid-mapping.update", { lid: id, pn: action.pnForLidChatAction.pnJid });
|
|
751
|
+
}
|
|
752
|
+
} else if (action?.privacySettingRelayAllCalls) {
|
|
753
|
+
ev.emit("settings.update", {
|
|
754
|
+
setting: "privacySettingRelayAllCalls",
|
|
755
|
+
value: action.privacySettingRelayAllCalls
|
|
756
|
+
});
|
|
757
|
+
} else if (action?.statusPrivacy) {
|
|
758
|
+
ev.emit("settings.update", { setting: "statusPrivacy", value: action.statusPrivacy });
|
|
759
|
+
} else if (action?.lockChatAction) {
|
|
760
|
+
ev.emit("chats.lock", { id, locked: !!action.lockChatAction.locked });
|
|
761
|
+
} else if (action?.privacySettingDisableLinkPreviewsAction) {
|
|
762
|
+
ev.emit("settings.update", {
|
|
763
|
+
setting: "disableLinkPreviews",
|
|
764
|
+
value: action.privacySettingDisableLinkPreviewsAction
|
|
765
|
+
});
|
|
766
|
+
} else if (action?.notificationActivitySettingAction?.notificationActivitySetting) {
|
|
767
|
+
ev.emit("settings.update", {
|
|
768
|
+
setting: "notificationActivitySetting",
|
|
769
|
+
value: action.notificationActivitySettingAction.notificationActivitySetting
|
|
770
|
+
});
|
|
771
|
+
} else if (action?.lidContactAction) {
|
|
772
|
+
ev.emit("contacts.upsert", [
|
|
773
|
+
{
|
|
774
|
+
id,
|
|
775
|
+
name: action.lidContactAction.fullName || action.lidContactAction.firstName || action.lidContactAction.username || void 0,
|
|
776
|
+
username: action.lidContactAction.username || void 0,
|
|
777
|
+
lid: id,
|
|
778
|
+
phoneNumber: void 0
|
|
779
|
+
}
|
|
780
|
+
]);
|
|
781
|
+
} else if (action?.privacySettingChannelsPersonalisedRecommendationAction) {
|
|
782
|
+
ev.emit("settings.update", {
|
|
783
|
+
setting: "channelsPersonalisedRecommendation",
|
|
784
|
+
value: action.privacySettingChannelsPersonalisedRecommendationAction
|
|
785
|
+
});
|
|
786
|
+
} else {
|
|
787
|
+
logger?.debug({ syncAction, id }, "unprocessable update");
|
|
788
|
+
}
|
|
789
|
+
function getChatUpdateConditional(id2, msgRange) {
|
|
790
|
+
return isInitialSync ? (data) => {
|
|
791
|
+
const chat = data.historySets.chats[id2] || data.chatUpserts[id2];
|
|
792
|
+
if (chat) {
|
|
793
|
+
return msgRange ? isValidPatchBasedOnMessageRange(chat, msgRange) : true;
|
|
794
|
+
}
|
|
795
|
+
} : void 0;
|
|
796
|
+
}
|
|
797
|
+
function isValidPatchBasedOnMessageRange(chat, msgRange) {
|
|
798
|
+
const lastMsgTimestamp = Number(msgRange?.lastMessageTimestamp || msgRange?.lastSystemMessageTimestamp || 0);
|
|
799
|
+
const chatLastMsgTimestamp = Number(chat?.lastMessageRecvTimestamp || 0);
|
|
800
|
+
return lastMsgTimestamp >= chatLastMsgTimestamp;
|
|
801
|
+
}
|
|
802
|
+
};
|
|
803
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
804
|
+
0 && (module.exports = {
|
|
805
|
+
MAX_SYNC_ATTEMPTS,
|
|
806
|
+
chatModificationToAppPatch,
|
|
807
|
+
decodePatches,
|
|
808
|
+
decodeSyncdMutations,
|
|
809
|
+
decodeSyncdPatch,
|
|
810
|
+
decodeSyncdSnapshot,
|
|
811
|
+
downloadExternalBlob,
|
|
812
|
+
downloadExternalPatch,
|
|
813
|
+
encodeSyncdPatch,
|
|
814
|
+
ensureLTHashStateVersion,
|
|
815
|
+
extractSyncdPatches,
|
|
816
|
+
isAppStateSyncIrrecoverable,
|
|
817
|
+
isMissingKeyError,
|
|
818
|
+
makeLtHashGenerator,
|
|
819
|
+
newLTHashState,
|
|
820
|
+
processSyncAction
|
|
821
|
+
});
|