@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,799 @@
|
|
|
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 messages_media_exports = {};
|
|
29
|
+
__export(messages_media_exports, {
|
|
30
|
+
DEF_MEDIA_HOST: () => DEF_MEDIA_HOST,
|
|
31
|
+
decodeMediaRetryNode: () => decodeMediaRetryNode,
|
|
32
|
+
decryptMediaRetryData: () => decryptMediaRetryData,
|
|
33
|
+
downloadContentFromMessage: () => downloadContentFromMessage,
|
|
34
|
+
downloadEncryptedContent: () => downloadEncryptedContent,
|
|
35
|
+
encodeBase64EncodedStringForUpload: () => encodeBase64EncodedStringForUpload,
|
|
36
|
+
encryptMediaRetryRequest: () => encryptMediaRetryRequest,
|
|
37
|
+
encryptedStream: () => encryptedStream,
|
|
38
|
+
extensionForMediaMessage: () => extensionForMediaMessage,
|
|
39
|
+
extractImageThumb: () => extractImageThumb,
|
|
40
|
+
extractVideoThumb: () => extractVideoThumb,
|
|
41
|
+
generateProfilePicture: () => generateProfilePicture,
|
|
42
|
+
generateThumbnail: () => generateThumbnail,
|
|
43
|
+
getAudioData: () => getAudioData,
|
|
44
|
+
getHttpStream: () => getHttpStream,
|
|
45
|
+
getImageProcessingLibrary: () => getImageProcessingLibrary,
|
|
46
|
+
getMediaKeys: () => getMediaKeys,
|
|
47
|
+
getRawMediaUploadData: () => getRawMediaUploadData,
|
|
48
|
+
getStatusCodeForMediaRetry: () => getStatusCodeForMediaRetry,
|
|
49
|
+
getStream: () => getStream,
|
|
50
|
+
getUrlFromDirectPath: () => getUrlFromDirectPath,
|
|
51
|
+
getWAUploadToServer: () => getWAUploadToServer,
|
|
52
|
+
hkdfInfoKey: () => hkdfInfoKey,
|
|
53
|
+
mediaMessageSHA256B64: () => mediaMessageSHA256B64,
|
|
54
|
+
toBuffer: () => toBuffer,
|
|
55
|
+
toReadable: () => toReadable,
|
|
56
|
+
uploadWithNodeHttp: () => uploadWithNodeHttp
|
|
57
|
+
});
|
|
58
|
+
module.exports = __toCommonJS(messages_media_exports);
|
|
59
|
+
var import_node_child_process = require("node:child_process");
|
|
60
|
+
var Crypto = __toESM(require("node:crypto"), 1);
|
|
61
|
+
var import_node_events = require("node:events");
|
|
62
|
+
var import_node_fs = require("node:fs");
|
|
63
|
+
var import_node_os = require("node:os");
|
|
64
|
+
var import_node_path = require("node:path");
|
|
65
|
+
var import_node_stream = require("node:stream");
|
|
66
|
+
var import_node_url = require("node:url");
|
|
67
|
+
var import_WAProto = require("../../WAProto/index.js");
|
|
68
|
+
var import_Addon = require("../Addon/index.js");
|
|
69
|
+
var import_Defaults = require("../Defaults/index.js");
|
|
70
|
+
var import_WABinary = require("../WABinary/index.js");
|
|
71
|
+
var import_crypto = require("./crypto.js");
|
|
72
|
+
var import_generics = require("./generics.js");
|
|
73
|
+
let imageProcessingLibrary;
|
|
74
|
+
const getImageProcessingLibrary = async () => {
|
|
75
|
+
if (imageProcessingLibrary) {
|
|
76
|
+
return imageProcessingLibrary;
|
|
77
|
+
}
|
|
78
|
+
const [sharp, image, jimp] = await Promise.all([
|
|
79
|
+
import("sharp").catch(() => {
|
|
80
|
+
}),
|
|
81
|
+
import("@napi-rs/image").catch(() => {
|
|
82
|
+
}),
|
|
83
|
+
import("jimp").catch(() => {
|
|
84
|
+
})
|
|
85
|
+
]);
|
|
86
|
+
if (sharp) {
|
|
87
|
+
imageProcessingLibrary = { sharp };
|
|
88
|
+
} else if (image) {
|
|
89
|
+
imageProcessingLibrary = { image };
|
|
90
|
+
} else if (jimp) {
|
|
91
|
+
imageProcessingLibrary = { jimp };
|
|
92
|
+
} else {
|
|
93
|
+
throw new import_Addon.HttpError("No image processing library available");
|
|
94
|
+
}
|
|
95
|
+
return imageProcessingLibrary;
|
|
96
|
+
};
|
|
97
|
+
const hkdfInfoKey = (type) => {
|
|
98
|
+
const hkdfInfo = import_Defaults.MEDIA_HKDF_KEY_MAPPING[type];
|
|
99
|
+
return `WhatsApp ${hkdfInfo} Keys`;
|
|
100
|
+
};
|
|
101
|
+
const getRawMediaUploadData = async (media, mediaType, logger) => {
|
|
102
|
+
const { stream } = await getStream(media);
|
|
103
|
+
logger?.debug("got stream for raw upload");
|
|
104
|
+
const hasher = Crypto.createHash("sha256");
|
|
105
|
+
const filePath = (0, import_node_path.join)((0, import_node_os.tmpdir)(), mediaType + (0, import_generics.generateMessageIDV2)());
|
|
106
|
+
const fileWriteStream = (0, import_node_fs.createWriteStream)(filePath);
|
|
107
|
+
let fileLength = 0;
|
|
108
|
+
try {
|
|
109
|
+
for await (const data of stream) {
|
|
110
|
+
fileLength += data.length;
|
|
111
|
+
hasher.update(data);
|
|
112
|
+
if (!fileWriteStream.write(data)) {
|
|
113
|
+
await (0, import_node_events.once)(fileWriteStream, "drain");
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
fileWriteStream.end();
|
|
117
|
+
await (0, import_node_events.once)(fileWriteStream, "finish");
|
|
118
|
+
stream.destroy();
|
|
119
|
+
const fileSha256 = hasher.digest();
|
|
120
|
+
logger?.debug("hashed data for raw upload");
|
|
121
|
+
return {
|
|
122
|
+
filePath,
|
|
123
|
+
fileSha256,
|
|
124
|
+
fileLength
|
|
125
|
+
};
|
|
126
|
+
} catch (error) {
|
|
127
|
+
fileWriteStream.destroy();
|
|
128
|
+
stream.destroy();
|
|
129
|
+
try {
|
|
130
|
+
await import_node_fs.promises.unlink(filePath);
|
|
131
|
+
} catch {
|
|
132
|
+
}
|
|
133
|
+
throw error;
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
async function getMediaKeys(buffer, mediaType) {
|
|
137
|
+
if (!buffer) {
|
|
138
|
+
throw new import_Addon.HttpError("Cannot derive from empty media key");
|
|
139
|
+
}
|
|
140
|
+
if (typeof buffer === "string") {
|
|
141
|
+
buffer = Buffer.from(buffer.replace("data:;base64,", ""), "base64");
|
|
142
|
+
}
|
|
143
|
+
const expandedMediaKey = (0, import_crypto.hkdf)(buffer, 112, { info: hkdfInfoKey(mediaType) });
|
|
144
|
+
return {
|
|
145
|
+
iv: expandedMediaKey.slice(0, 16),
|
|
146
|
+
cipherKey: expandedMediaKey.slice(16, 48),
|
|
147
|
+
macKey: expandedMediaKey.slice(48, 80)
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
const extractVideoThumb = async (path, time, size) => {
|
|
151
|
+
const ffmpeg = (0, import_node_child_process.spawn)("ffmpeg", [
|
|
152
|
+
"-loglevel",
|
|
153
|
+
"error",
|
|
154
|
+
"-ss",
|
|
155
|
+
String(time),
|
|
156
|
+
"-i",
|
|
157
|
+
path,
|
|
158
|
+
"-an",
|
|
159
|
+
"-sn",
|
|
160
|
+
"-dn",
|
|
161
|
+
"-map_metadata",
|
|
162
|
+
"-1",
|
|
163
|
+
"-vf",
|
|
164
|
+
`scale=${size.width}:-1`,
|
|
165
|
+
"-frames:v",
|
|
166
|
+
"1",
|
|
167
|
+
"-c:v",
|
|
168
|
+
"mjpeg",
|
|
169
|
+
"-f",
|
|
170
|
+
"image2pipe",
|
|
171
|
+
"pipe:1"
|
|
172
|
+
], {
|
|
173
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
174
|
+
});
|
|
175
|
+
let buffer = Buffer.alloc(0);
|
|
176
|
+
const stderrChunks = [];
|
|
177
|
+
ffmpeg.stdout.on("data", (chunk) => {
|
|
178
|
+
buffer = Buffer.concat([buffer, chunk]);
|
|
179
|
+
});
|
|
180
|
+
ffmpeg.stderr.on("data", (chunk) => stderrChunks.push(chunk));
|
|
181
|
+
const [code] = await (0, import_node_events.once)(ffmpeg, "close");
|
|
182
|
+
if (code !== 0) {
|
|
183
|
+
throw new import_Addon.HttpError(`FFmpeg failed (code ${code}):
|
|
184
|
+
` + Buffer.concat(stderrChunks).toString("utf8"));
|
|
185
|
+
}
|
|
186
|
+
return buffer;
|
|
187
|
+
};
|
|
188
|
+
const extractImageThumb = async (bufferOrFilePath, width = 32) => {
|
|
189
|
+
if (bufferOrFilePath instanceof import_node_stream.Readable) {
|
|
190
|
+
bufferOrFilePath = await toBuffer(bufferOrFilePath);
|
|
191
|
+
}
|
|
192
|
+
const lib = await getImageProcessingLibrary();
|
|
193
|
+
if ("sharp" in lib && lib.sharp?.default) {
|
|
194
|
+
const img = lib.sharp.default(bufferOrFilePath);
|
|
195
|
+
const dimensions = await img.metadata();
|
|
196
|
+
const buffer = await img.resize(width).jpeg({ quality: 50 }).toBuffer();
|
|
197
|
+
return {
|
|
198
|
+
buffer,
|
|
199
|
+
original: {
|
|
200
|
+
width: dimensions.width,
|
|
201
|
+
height: dimensions.height
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
} else if ("image" in lib && lib.image?.Transformer) {
|
|
205
|
+
if (!Buffer.isBuffer(bufferOrFilePath)) {
|
|
206
|
+
bufferOrFilePath = await import_node_fs.promises.readFile(bufferOrFilePath);
|
|
207
|
+
}
|
|
208
|
+
const img = new lib.image.Transformer(bufferOrFilePath);
|
|
209
|
+
const dimensions = await img.metadata();
|
|
210
|
+
const buffer = await img.resize(width, void 0, 0).jpeg(50);
|
|
211
|
+
return {
|
|
212
|
+
buffer,
|
|
213
|
+
original: {
|
|
214
|
+
width: dimensions.width,
|
|
215
|
+
height: dimensions.height
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
} else if ("jimp" in lib && lib.jimp?.Jimp) {
|
|
219
|
+
const jimp = await lib.jimp.Jimp.read(bufferOrFilePath);
|
|
220
|
+
const dimensions = {
|
|
221
|
+
width: jimp.width,
|
|
222
|
+
height: jimp.height
|
|
223
|
+
};
|
|
224
|
+
const buffer = await jimp.resize({ w: width, mode: lib.jimp.ResizeStrategy.BILINEAR }).getBuffer("image/jpeg", { quality: 50 });
|
|
225
|
+
return {
|
|
226
|
+
buffer,
|
|
227
|
+
original: dimensions
|
|
228
|
+
};
|
|
229
|
+
} else {
|
|
230
|
+
throw new import_Addon.HttpError("No image processing library available");
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
const encodeBase64EncodedStringForUpload = (b64) => encodeURIComponent(b64.replace(/\+/g, "-").replace(/\//g, "_").replace(/\=+$/, ""));
|
|
234
|
+
const generateProfilePicture = async (mediaUpload, dimensions) => {
|
|
235
|
+
let buffer;
|
|
236
|
+
const { width: w = 720, height: h = 720 } = dimensions || {};
|
|
237
|
+
if (Buffer.isBuffer(mediaUpload)) {
|
|
238
|
+
buffer = mediaUpload;
|
|
239
|
+
} else {
|
|
240
|
+
const { stream } = await getStream(mediaUpload);
|
|
241
|
+
buffer = await toBuffer(stream);
|
|
242
|
+
}
|
|
243
|
+
const lib = await getImageProcessingLibrary();
|
|
244
|
+
let img;
|
|
245
|
+
if ("sharp" in lib && lib.sharp?.default) {
|
|
246
|
+
img = lib.sharp.default(buffer).resize(w, h).jpeg({
|
|
247
|
+
quality: 80
|
|
248
|
+
}).toBuffer();
|
|
249
|
+
} else if ("image" in lib && lib.image?.Transformer) {
|
|
250
|
+
img = new lib.image.Transformer(buffer).resize(w, h, 0).jpeg(80);
|
|
251
|
+
} else if ("jimp" in lib && lib.jimp?.Jimp) {
|
|
252
|
+
const jimp = await lib.jimp.Jimp.read(buffer);
|
|
253
|
+
const min = Math.min(jimp.width, jimp.height);
|
|
254
|
+
const cropped = jimp.crop({ x: 0, y: 0, w: min, h: min });
|
|
255
|
+
img = cropped.resize({ w, h, mode: lib.jimp.ResizeStrategy.BILINEAR }).getBuffer("image/jpeg", { quality: 80 });
|
|
256
|
+
} else {
|
|
257
|
+
throw new import_Addon.HttpError("No image processing library available");
|
|
258
|
+
}
|
|
259
|
+
return {
|
|
260
|
+
img: await img
|
|
261
|
+
};
|
|
262
|
+
};
|
|
263
|
+
const mediaMessageSHA256B64 = (message) => {
|
|
264
|
+
const media = Object.values(message)[0];
|
|
265
|
+
return media?.fileSha256 && Buffer.from(media.fileSha256).toString("base64");
|
|
266
|
+
};
|
|
267
|
+
async function getAudioData(buffer, logger) {
|
|
268
|
+
try {
|
|
269
|
+
const filePath = await (0, import_Addon.getFile)(buffer);
|
|
270
|
+
const result = await (0, import_Addon.getAudioWaveform)(filePath);
|
|
271
|
+
await import_node_fs.promises.unlink(filePath);
|
|
272
|
+
return result;
|
|
273
|
+
} catch (e) {
|
|
274
|
+
logger?.debug("Failed to get audio data: " + e);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
const toReadable = (buffer) => {
|
|
278
|
+
const readable = new import_node_stream.Readable({ read: () => {
|
|
279
|
+
} });
|
|
280
|
+
readable.push(buffer);
|
|
281
|
+
readable.push(null);
|
|
282
|
+
return readable;
|
|
283
|
+
};
|
|
284
|
+
const toBuffer = async (stream) => {
|
|
285
|
+
const chunks = [];
|
|
286
|
+
for await (const chunk of stream) {
|
|
287
|
+
chunks.push(chunk);
|
|
288
|
+
}
|
|
289
|
+
stream.destroy();
|
|
290
|
+
return Buffer.concat(chunks);
|
|
291
|
+
};
|
|
292
|
+
const getStream = async (item, opts) => {
|
|
293
|
+
if (Buffer.isBuffer(item)) {
|
|
294
|
+
return { stream: toReadable(item), type: "buffer" };
|
|
295
|
+
}
|
|
296
|
+
if ("stream" in item) {
|
|
297
|
+
return { stream: item.stream, type: "readable" };
|
|
298
|
+
}
|
|
299
|
+
const urlStr = item.url.toString();
|
|
300
|
+
if (urlStr.startsWith("data:")) {
|
|
301
|
+
const buffer = Buffer.from(urlStr.split(",")[1], "base64");
|
|
302
|
+
return { stream: toReadable(buffer), type: "buffer" };
|
|
303
|
+
}
|
|
304
|
+
if (urlStr.startsWith("http://") || urlStr.startsWith("https://")) {
|
|
305
|
+
return { stream: await getHttpStream(item.url, opts), type: "remote" };
|
|
306
|
+
}
|
|
307
|
+
return { stream: (0, import_node_fs.createReadStream)(item.url), type: "file" };
|
|
308
|
+
};
|
|
309
|
+
async function generateThumbnail(file, mediaType, options) {
|
|
310
|
+
let thumbnail;
|
|
311
|
+
let originalImageDimensions;
|
|
312
|
+
if (mediaType === "image") {
|
|
313
|
+
const { buffer, original } = await extractImageThumb(file);
|
|
314
|
+
thumbnail = buffer.toString("base64");
|
|
315
|
+
if (original.width && original.height) {
|
|
316
|
+
originalImageDimensions = {
|
|
317
|
+
width: original.width,
|
|
318
|
+
height: original.height
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
} else if (mediaType === "video") {
|
|
322
|
+
try {
|
|
323
|
+
const buff = await extractVideoThumb(file, "00:00:00", { width: 32, height: 32 });
|
|
324
|
+
thumbnail = buff.toString("base64");
|
|
325
|
+
} catch (err) {
|
|
326
|
+
options.logger?.debug("could not generate video thumb: " + err);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
return {
|
|
330
|
+
thumbnail,
|
|
331
|
+
originalImageDimensions
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
const getHttpStream = async (url, options = {}) => {
|
|
335
|
+
const response = await fetch(url.toString(), {
|
|
336
|
+
dispatcher: options.dispatcher,
|
|
337
|
+
method: "GET",
|
|
338
|
+
headers: options.headers
|
|
339
|
+
});
|
|
340
|
+
if (!response.ok) {
|
|
341
|
+
throw new import_Addon.HttpError(`Failed to fetch stream from ${url}`, { statusCode: response.status, data: { url } });
|
|
342
|
+
}
|
|
343
|
+
return response.body instanceof import_node_stream.Readable ? response.body : import_node_stream.Readable.fromWeb(response.body);
|
|
344
|
+
};
|
|
345
|
+
const encryptedStream = async (media, mediaType, { logger, saveOriginalFileIfRequired, mediaKey = Crypto.randomBytes(32), opts } = {}) => {
|
|
346
|
+
const { stream, type } = await getStream(media, opts);
|
|
347
|
+
logger?.debug("fetched media stream");
|
|
348
|
+
const { cipherKey, iv, macKey } = await getMediaKeys(mediaKey, mediaType);
|
|
349
|
+
const encFilePath = (0, import_node_path.join)((0, import_node_os.tmpdir)(), mediaType + (0, import_generics.generateMessageIDV2)() + "-enc");
|
|
350
|
+
const encFileWriteStream = (0, import_node_fs.createWriteStream)(encFilePath);
|
|
351
|
+
let originalFileStream;
|
|
352
|
+
let originalFilePath;
|
|
353
|
+
if (saveOriginalFileIfRequired) {
|
|
354
|
+
originalFilePath = (0, import_node_path.join)((0, import_node_os.tmpdir)(), mediaType + (0, import_generics.generateMessageIDV2)() + "-original");
|
|
355
|
+
originalFileStream = (0, import_node_fs.createWriteStream)(originalFilePath);
|
|
356
|
+
}
|
|
357
|
+
let fileLength = 0;
|
|
358
|
+
const aes = Crypto.createCipheriv("aes-256-cbc", cipherKey, iv);
|
|
359
|
+
const hmac = Crypto.createHmac("sha256", macKey).update(iv);
|
|
360
|
+
const sha256Plain = Crypto.createHash("sha256");
|
|
361
|
+
const sha256Enc = Crypto.createHash("sha256");
|
|
362
|
+
const onChunk = async (buff) => {
|
|
363
|
+
sha256Enc.update(buff);
|
|
364
|
+
hmac.update(buff);
|
|
365
|
+
if (!encFileWriteStream.write(buff)) {
|
|
366
|
+
await (0, import_node_events.once)(encFileWriteStream, "drain");
|
|
367
|
+
}
|
|
368
|
+
};
|
|
369
|
+
try {
|
|
370
|
+
for await (const data of stream) {
|
|
371
|
+
fileLength += data.length;
|
|
372
|
+
if (type === "remote" && opts?.maxContentLength && fileLength + data.length > opts.maxContentLength) {
|
|
373
|
+
throw new import_Addon.HttpError(`content length exceeded when encrypting "${type}"`, {
|
|
374
|
+
data: { media, type }
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
if (originalFileStream) {
|
|
378
|
+
if (!originalFileStream.write(data)) {
|
|
379
|
+
await (0, import_node_events.once)(originalFileStream, "drain");
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
sha256Plain.update(data);
|
|
383
|
+
await onChunk(aes.update(data));
|
|
384
|
+
}
|
|
385
|
+
await onChunk(aes.final());
|
|
386
|
+
const mac = hmac.digest().slice(0, 10);
|
|
387
|
+
sha256Enc.update(mac);
|
|
388
|
+
const fileSha256 = sha256Plain.digest();
|
|
389
|
+
const fileEncSha256 = sha256Enc.digest();
|
|
390
|
+
encFileWriteStream.write(mac);
|
|
391
|
+
const encFinishPromise = (0, import_node_events.once)(encFileWriteStream, "finish");
|
|
392
|
+
const originalFinishPromise = originalFileStream ? (0, import_node_events.once)(originalFileStream, "finish") : Promise.resolve();
|
|
393
|
+
encFileWriteStream.end();
|
|
394
|
+
originalFileStream?.end?.();
|
|
395
|
+
stream.destroy();
|
|
396
|
+
await encFinishPromise;
|
|
397
|
+
await originalFinishPromise;
|
|
398
|
+
logger?.debug("encrypted data successfully");
|
|
399
|
+
return {
|
|
400
|
+
mediaKey,
|
|
401
|
+
originalFilePath,
|
|
402
|
+
encFilePath,
|
|
403
|
+
mac,
|
|
404
|
+
fileEncSha256,
|
|
405
|
+
fileSha256,
|
|
406
|
+
fileLength
|
|
407
|
+
};
|
|
408
|
+
} catch (error) {
|
|
409
|
+
encFileWriteStream.destroy();
|
|
410
|
+
originalFileStream?.destroy?.();
|
|
411
|
+
aes.destroy();
|
|
412
|
+
hmac.destroy();
|
|
413
|
+
sha256Plain.destroy();
|
|
414
|
+
sha256Enc.destroy();
|
|
415
|
+
stream.destroy();
|
|
416
|
+
try {
|
|
417
|
+
await import_node_fs.promises.unlink(encFilePath);
|
|
418
|
+
if (originalFilePath) {
|
|
419
|
+
await import_node_fs.promises.unlink(originalFilePath);
|
|
420
|
+
}
|
|
421
|
+
} catch (err) {
|
|
422
|
+
logger?.error({ err }, "failed deleting tmp files");
|
|
423
|
+
}
|
|
424
|
+
throw error;
|
|
425
|
+
}
|
|
426
|
+
};
|
|
427
|
+
const DEF_MEDIA_HOST = "mmg.whatsapp.net";
|
|
428
|
+
const AES_CHUNK_SIZE = 16;
|
|
429
|
+
const toSmallestChunkSize = (num) => {
|
|
430
|
+
return Math.floor(num / AES_CHUNK_SIZE) * AES_CHUNK_SIZE;
|
|
431
|
+
};
|
|
432
|
+
const getUrlFromDirectPath = (directPath, host = DEF_MEDIA_HOST) => `https://${host}${directPath}`;
|
|
433
|
+
const PLACEHOLDER_MEDIA_HOST = "a.whatsapp.net";
|
|
434
|
+
const extractHost = (url) => {
|
|
435
|
+
if (!url)
|
|
436
|
+
return void 0;
|
|
437
|
+
try {
|
|
438
|
+
const host = new import_node_url.URL(url).host;
|
|
439
|
+
return host === PLACEHOLDER_MEDIA_HOST ? void 0 : host;
|
|
440
|
+
} catch {
|
|
441
|
+
return void 0;
|
|
442
|
+
}
|
|
443
|
+
};
|
|
444
|
+
const downloadContentFromMessage = async ({ mediaKey, directPath, url }, type, opts = {}) => {
|
|
445
|
+
const fallbackHost = opts.host ?? extractHost(url);
|
|
446
|
+
const downloadUrl = directPath ? getUrlFromDirectPath(directPath, fallbackHost) : url;
|
|
447
|
+
if (!downloadUrl) {
|
|
448
|
+
throw new import_Addon.HttpError("No valid media URL or directPath present in message", { statusCode: 400 });
|
|
449
|
+
}
|
|
450
|
+
const keys = await getMediaKeys(mediaKey, type);
|
|
451
|
+
return downloadEncryptedContent(downloadUrl, keys, opts);
|
|
452
|
+
};
|
|
453
|
+
const downloadEncryptedContent = async (downloadUrl, { cipherKey, iv }, { startByte, endByte, options } = {}) => {
|
|
454
|
+
let bytesFetched = 0;
|
|
455
|
+
let startChunk = 0;
|
|
456
|
+
let firstBlockIsIV = false;
|
|
457
|
+
if (startByte) {
|
|
458
|
+
const chunk = toSmallestChunkSize(startByte || 0);
|
|
459
|
+
if (chunk) {
|
|
460
|
+
startChunk = chunk - AES_CHUNK_SIZE;
|
|
461
|
+
bytesFetched = chunk;
|
|
462
|
+
firstBlockIsIV = true;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
const endChunk = endByte ? toSmallestChunkSize(endByte || 0) + AES_CHUNK_SIZE : void 0;
|
|
466
|
+
const headersInit = options?.headers ? options.headers : void 0;
|
|
467
|
+
const headers = {
|
|
468
|
+
...headersInit ? Array.isArray(headersInit) ? Object.fromEntries(headersInit) : headersInit : {},
|
|
469
|
+
Origin: import_Defaults.DEFAULT_ORIGIN
|
|
470
|
+
};
|
|
471
|
+
if (startChunk || endChunk) {
|
|
472
|
+
headers.Range = `bytes=${startChunk}-`;
|
|
473
|
+
if (endChunk) {
|
|
474
|
+
headers.Range += endChunk;
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
const fetched = await getHttpStream(downloadUrl, {
|
|
478
|
+
...options || {},
|
|
479
|
+
headers
|
|
480
|
+
});
|
|
481
|
+
let remainingBytes = Buffer.from([]);
|
|
482
|
+
let aes;
|
|
483
|
+
const pushBytes = (bytes, push) => {
|
|
484
|
+
if (startByte || endByte) {
|
|
485
|
+
const start = bytesFetched >= startByte ? void 0 : Math.max(startByte - bytesFetched, 0);
|
|
486
|
+
const end = bytesFetched + bytes.length < endByte ? void 0 : Math.max(endByte - bytesFetched, 0);
|
|
487
|
+
push(bytes.slice(start, end));
|
|
488
|
+
bytesFetched += bytes.length;
|
|
489
|
+
} else {
|
|
490
|
+
push(bytes);
|
|
491
|
+
}
|
|
492
|
+
};
|
|
493
|
+
const output = new import_node_stream.Transform({
|
|
494
|
+
transform(chunk, _, callback) {
|
|
495
|
+
let data = remainingBytes.length ? Buffer.concat([remainingBytes, chunk]) : chunk;
|
|
496
|
+
const decryptLength = toSmallestChunkSize(data.length);
|
|
497
|
+
remainingBytes = data.slice(decryptLength);
|
|
498
|
+
data = data.slice(0, decryptLength);
|
|
499
|
+
if (!aes) {
|
|
500
|
+
let ivValue = iv;
|
|
501
|
+
if (firstBlockIsIV) {
|
|
502
|
+
ivValue = data.slice(0, AES_CHUNK_SIZE);
|
|
503
|
+
data = data.slice(AES_CHUNK_SIZE);
|
|
504
|
+
}
|
|
505
|
+
aes = Crypto.createDecipheriv("aes-256-cbc", cipherKey, ivValue);
|
|
506
|
+
if (endByte) {
|
|
507
|
+
aes.setAutoPadding(false);
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
try {
|
|
511
|
+
pushBytes(aes.update(data), (b) => this.push(b));
|
|
512
|
+
callback();
|
|
513
|
+
} catch (error) {
|
|
514
|
+
callback(error);
|
|
515
|
+
}
|
|
516
|
+
},
|
|
517
|
+
final(callback) {
|
|
518
|
+
try {
|
|
519
|
+
pushBytes(aes.final(), (b) => this.push(b));
|
|
520
|
+
callback();
|
|
521
|
+
} catch (error) {
|
|
522
|
+
callback(error);
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
});
|
|
526
|
+
return fetched.pipe(output, { end: true });
|
|
527
|
+
};
|
|
528
|
+
function extensionForMediaMessage(message) {
|
|
529
|
+
const getExtension = (mimetype) => mimetype.split(";")[0]?.split("/")[1];
|
|
530
|
+
const type = Object.keys(message)[0];
|
|
531
|
+
let extension;
|
|
532
|
+
if (type === "locationMessage" || type === "liveLocationMessage" || type === "productMessage") {
|
|
533
|
+
extension = ".jpeg";
|
|
534
|
+
} else {
|
|
535
|
+
const messageContent = message[type];
|
|
536
|
+
extension = getExtension(messageContent.mimetype);
|
|
537
|
+
}
|
|
538
|
+
return extension;
|
|
539
|
+
}
|
|
540
|
+
const isNodeRuntime = () => {
|
|
541
|
+
return typeof process !== "undefined" && process.versions?.node !== null && typeof process.versions.bun === "undefined" && typeof globalThis.Deno === "undefined";
|
|
542
|
+
};
|
|
543
|
+
const uploadWithNodeHttp = async ({ url, filePath, headers, timeoutMs, agent }, redirectCount = 0) => {
|
|
544
|
+
if (redirectCount > 5) {
|
|
545
|
+
throw new Error("Too many redirects");
|
|
546
|
+
}
|
|
547
|
+
const parsedUrl = new import_node_url.URL(url);
|
|
548
|
+
const httpModule = parsedUrl.protocol === "https:" ? await import("https") : await import("http");
|
|
549
|
+
const fileStats = await import_node_fs.promises.stat(filePath);
|
|
550
|
+
const fileSize = fileStats.size;
|
|
551
|
+
return new Promise((resolve, reject) => {
|
|
552
|
+
const req = httpModule.request({
|
|
553
|
+
hostname: parsedUrl.hostname,
|
|
554
|
+
port: parsedUrl.port || (parsedUrl.protocol === "https:" ? 443 : 80),
|
|
555
|
+
path: parsedUrl.pathname + parsedUrl.search,
|
|
556
|
+
method: "POST",
|
|
557
|
+
headers: {
|
|
558
|
+
...headers,
|
|
559
|
+
"Content-Length": fileSize
|
|
560
|
+
},
|
|
561
|
+
agent,
|
|
562
|
+
timeout: timeoutMs
|
|
563
|
+
}, (res) => {
|
|
564
|
+
if (res.statusCode && res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
565
|
+
res.resume();
|
|
566
|
+
const newUrl = new import_node_url.URL(res.headers.location, url).toString();
|
|
567
|
+
resolve(uploadWithNodeHttp({
|
|
568
|
+
url: newUrl,
|
|
569
|
+
filePath,
|
|
570
|
+
headers,
|
|
571
|
+
timeoutMs,
|
|
572
|
+
agent
|
|
573
|
+
}, redirectCount + 1));
|
|
574
|
+
return;
|
|
575
|
+
}
|
|
576
|
+
let body = "";
|
|
577
|
+
res.on("data", (chunk) => body += chunk);
|
|
578
|
+
res.on("end", () => {
|
|
579
|
+
try {
|
|
580
|
+
resolve(JSON.parse(body));
|
|
581
|
+
} catch {
|
|
582
|
+
resolve(void 0);
|
|
583
|
+
}
|
|
584
|
+
});
|
|
585
|
+
});
|
|
586
|
+
req.on("error", reject);
|
|
587
|
+
req.on("timeout", () => {
|
|
588
|
+
req.destroy();
|
|
589
|
+
reject(new Error("Upload timeout"));
|
|
590
|
+
});
|
|
591
|
+
const stream = (0, import_node_fs.createReadStream)(filePath);
|
|
592
|
+
stream.pipe(req);
|
|
593
|
+
stream.on("error", (err) => {
|
|
594
|
+
req.destroy();
|
|
595
|
+
reject(err);
|
|
596
|
+
});
|
|
597
|
+
});
|
|
598
|
+
};
|
|
599
|
+
const uploadWithFetch = async ({ url, filePath, headers, timeoutMs, agent }) => {
|
|
600
|
+
const nodeStream = (0, import_node_fs.createReadStream)(filePath);
|
|
601
|
+
const webStream = import_node_stream.Readable.toWeb(nodeStream);
|
|
602
|
+
const dispatcher = typeof agent?.dispatch === "function" ? agent : void 0;
|
|
603
|
+
const response = await fetch(url, {
|
|
604
|
+
...dispatcher ? { dispatcher } : {},
|
|
605
|
+
method: "POST",
|
|
606
|
+
body: webStream,
|
|
607
|
+
headers,
|
|
608
|
+
duplex: "half",
|
|
609
|
+
signal: timeoutMs ? AbortSignal.timeout(timeoutMs) : void 0
|
|
610
|
+
});
|
|
611
|
+
try {
|
|
612
|
+
return await response.json();
|
|
613
|
+
} catch {
|
|
614
|
+
return void 0;
|
|
615
|
+
}
|
|
616
|
+
};
|
|
617
|
+
const uploadMedia = async (params, logger) => {
|
|
618
|
+
if (isNodeRuntime()) {
|
|
619
|
+
logger?.debug("Using Node.js https module for upload (avoids undici buffering bug)");
|
|
620
|
+
return uploadWithNodeHttp(params);
|
|
621
|
+
} else {
|
|
622
|
+
logger?.debug("Using web-standard Fetch API for upload");
|
|
623
|
+
return uploadWithFetch(params);
|
|
624
|
+
}
|
|
625
|
+
};
|
|
626
|
+
const shouldIncludeServerTranscode = (mediaType) => !!(mediaType === "video" || mediaType === "gif" || mediaType === "ptv");
|
|
627
|
+
const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, options }, refreshMediaConn) => {
|
|
628
|
+
return async (filePath, { mediaType, fileEncSha256B64, timeoutMs, newsletter }) => {
|
|
629
|
+
let uploadInfo = await refreshMediaConn(false);
|
|
630
|
+
let urls;
|
|
631
|
+
const hosts = [...customUploadHosts, ...uploadInfo.hosts];
|
|
632
|
+
fileEncSha256B64 = encodeBase64EncodedStringForUpload(fileEncSha256B64);
|
|
633
|
+
let optsHeaders = options?.headers;
|
|
634
|
+
if (!optsHeaders)
|
|
635
|
+
optsHeaders = {};
|
|
636
|
+
optsHeaders = Array.isArray(optsHeaders) ? Object.fromEntries(optsHeaders) : optsHeaders;
|
|
637
|
+
const headers = {
|
|
638
|
+
...optsHeaders,
|
|
639
|
+
"Content-Type": "application/octet-stream",
|
|
640
|
+
Origin: import_Defaults.DEFAULT_ORIGIN
|
|
641
|
+
};
|
|
642
|
+
for (const { hostname } of hosts) {
|
|
643
|
+
logger.debug(`uploading to "${hostname}"`);
|
|
644
|
+
const auth = encodeURIComponent(uploadInfo.auth);
|
|
645
|
+
const mediaPathMap = newsletter ? import_Defaults.NEWSLETTER_MEDIA_PATH_MAP : import_Defaults.MEDIA_PATH_MAP;
|
|
646
|
+
let url = `https://${hostname}${mediaPathMap[mediaType]}/${fileEncSha256B64}?auth=${auth}&token=${fileEncSha256B64}`;
|
|
647
|
+
if (newsletter) {
|
|
648
|
+
url += "&server_thumb_gen=1";
|
|
649
|
+
if (shouldIncludeServerTranscode(mediaType)) {
|
|
650
|
+
url += "&server_transcode=1";
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
let result;
|
|
654
|
+
try {
|
|
655
|
+
result = await uploadMedia({
|
|
656
|
+
url,
|
|
657
|
+
filePath,
|
|
658
|
+
headers,
|
|
659
|
+
timeoutMs,
|
|
660
|
+
agent: fetchAgent
|
|
661
|
+
}, logger);
|
|
662
|
+
if (result?.url || result?.direct_path) {
|
|
663
|
+
urls = {
|
|
664
|
+
mediaUrl: result.url || result.direct_path,
|
|
665
|
+
directPath: result.direct_path,
|
|
666
|
+
meta_hmac: result.meta_hmac,
|
|
667
|
+
fbid: result.fbid,
|
|
668
|
+
ts: result.ts,
|
|
669
|
+
thumbnailDirectPath: result.thumbnail_info?.thumbnail_direct_path,
|
|
670
|
+
thumbnailSha256: result.thumbnail_info?.thumbnail_sha256
|
|
671
|
+
};
|
|
672
|
+
break;
|
|
673
|
+
} else {
|
|
674
|
+
uploadInfo = await refreshMediaConn(true);
|
|
675
|
+
throw new Error(`upload failed, reason: ${JSON.stringify(result)}`);
|
|
676
|
+
}
|
|
677
|
+
} catch (error) {
|
|
678
|
+
const isLast = hostname === hosts[uploadInfo.hosts.length - 1]?.hostname;
|
|
679
|
+
logger.warn({ trace: error?.stack, uploadResult: result }, `Error in uploading to ${hostname} ${isLast ? "" : ", retrying..."}`);
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
if (!urls) {
|
|
683
|
+
throw new import_Addon.HttpError("Media upload failed on all hosts", { statusCode: 500 });
|
|
684
|
+
}
|
|
685
|
+
return urls;
|
|
686
|
+
};
|
|
687
|
+
};
|
|
688
|
+
const getMediaRetryKey = (mediaKey) => {
|
|
689
|
+
return (0, import_crypto.hkdf)(mediaKey, 32, { info: "WhatsApp Media Retry Notification" });
|
|
690
|
+
};
|
|
691
|
+
const encryptMediaRetryRequest = (key, mediaKey, meId) => {
|
|
692
|
+
const recp = { stanzaId: key.id };
|
|
693
|
+
const recpBuffer = import_WAProto.proto.ServerErrorReceipt.encode(recp).finish();
|
|
694
|
+
const iv = Crypto.randomBytes(12);
|
|
695
|
+
const retryKey = getMediaRetryKey(mediaKey);
|
|
696
|
+
const ciphertext = (0, import_crypto.aesEncryptGCM)(recpBuffer, retryKey, iv, Buffer.from(key.id));
|
|
697
|
+
const req = {
|
|
698
|
+
tag: "receipt",
|
|
699
|
+
attrs: {
|
|
700
|
+
id: key.id,
|
|
701
|
+
to: (0, import_WABinary.jidNormalizedUser)(meId),
|
|
702
|
+
type: "server-error"
|
|
703
|
+
},
|
|
704
|
+
content: [
|
|
705
|
+
// this encrypt node is actually pretty useless
|
|
706
|
+
// the media is returned even without this node
|
|
707
|
+
// keeping it here to maintain parity with WA Web
|
|
708
|
+
{
|
|
709
|
+
tag: "encrypt",
|
|
710
|
+
attrs: {},
|
|
711
|
+
content: [
|
|
712
|
+
{ tag: "enc_p", attrs: {}, content: ciphertext },
|
|
713
|
+
{ tag: "enc_iv", attrs: {}, content: iv }
|
|
714
|
+
]
|
|
715
|
+
},
|
|
716
|
+
{
|
|
717
|
+
tag: "rmr",
|
|
718
|
+
attrs: {
|
|
719
|
+
jid: key.remoteJid,
|
|
720
|
+
from_me: (!!key.fromMe).toString(),
|
|
721
|
+
// @ts-ignore
|
|
722
|
+
participant: key.participant || void 0
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
]
|
|
726
|
+
};
|
|
727
|
+
return req;
|
|
728
|
+
};
|
|
729
|
+
const decodeMediaRetryNode = (node) => {
|
|
730
|
+
const rmrNode = (0, import_WABinary.getBinaryNodeChild)(node, "rmr");
|
|
731
|
+
const event = {
|
|
732
|
+
key: {
|
|
733
|
+
id: node.attrs.id,
|
|
734
|
+
remoteJid: rmrNode.attrs.jid,
|
|
735
|
+
fromMe: rmrNode.attrs.from_me === "true",
|
|
736
|
+
participant: rmrNode.attrs.participant
|
|
737
|
+
}
|
|
738
|
+
};
|
|
739
|
+
const errorNode = (0, import_WABinary.getBinaryNodeChild)(node, "error");
|
|
740
|
+
if (errorNode) {
|
|
741
|
+
const errorCode = +errorNode.attrs.code;
|
|
742
|
+
event.error = new import_Addon.HttpError(`Failed to re-upload media (${errorCode})`, {
|
|
743
|
+
data: errorNode.attrs,
|
|
744
|
+
statusCode: getStatusCodeForMediaRetry(errorCode)
|
|
745
|
+
});
|
|
746
|
+
} else {
|
|
747
|
+
const encryptedInfoNode = (0, import_WABinary.getBinaryNodeChild)(node, "encrypt");
|
|
748
|
+
const ciphertext = (0, import_WABinary.getBinaryNodeChildBuffer)(encryptedInfoNode, "enc_p");
|
|
749
|
+
const iv = (0, import_WABinary.getBinaryNodeChildBuffer)(encryptedInfoNode, "enc_iv");
|
|
750
|
+
if (ciphertext && iv) {
|
|
751
|
+
event.media = { ciphertext, iv };
|
|
752
|
+
} else {
|
|
753
|
+
event.error = new import_Addon.HttpError("Failed to re-upload media (missing ciphertext)", { statusCode: 404 });
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
return event;
|
|
757
|
+
};
|
|
758
|
+
const decryptMediaRetryData = ({ ciphertext, iv }, mediaKey, msgId) => {
|
|
759
|
+
const retryKey = getMediaRetryKey(mediaKey);
|
|
760
|
+
const plaintext = (0, import_crypto.aesDecryptGCM)(ciphertext, retryKey, iv, Buffer.from(msgId));
|
|
761
|
+
return import_WAProto.proto.MediaRetryNotification.decode(plaintext);
|
|
762
|
+
};
|
|
763
|
+
const getStatusCodeForMediaRetry = (code) => MEDIA_RETRY_STATUS_MAP[code];
|
|
764
|
+
const MEDIA_RETRY_STATUS_MAP = {
|
|
765
|
+
[import_WAProto.proto.MediaRetryNotification.ResultType.SUCCESS]: 200,
|
|
766
|
+
[import_WAProto.proto.MediaRetryNotification.ResultType.DECRYPTION_ERROR]: 412,
|
|
767
|
+
[import_WAProto.proto.MediaRetryNotification.ResultType.NOT_FOUND]: 404,
|
|
768
|
+
[import_WAProto.proto.MediaRetryNotification.ResultType.GENERAL_ERROR]: 418
|
|
769
|
+
};
|
|
770
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
771
|
+
0 && (module.exports = {
|
|
772
|
+
DEF_MEDIA_HOST,
|
|
773
|
+
decodeMediaRetryNode,
|
|
774
|
+
decryptMediaRetryData,
|
|
775
|
+
downloadContentFromMessage,
|
|
776
|
+
downloadEncryptedContent,
|
|
777
|
+
encodeBase64EncodedStringForUpload,
|
|
778
|
+
encryptMediaRetryRequest,
|
|
779
|
+
encryptedStream,
|
|
780
|
+
extensionForMediaMessage,
|
|
781
|
+
extractImageThumb,
|
|
782
|
+
extractVideoThumb,
|
|
783
|
+
generateProfilePicture,
|
|
784
|
+
generateThumbnail,
|
|
785
|
+
getAudioData,
|
|
786
|
+
getHttpStream,
|
|
787
|
+
getImageProcessingLibrary,
|
|
788
|
+
getMediaKeys,
|
|
789
|
+
getRawMediaUploadData,
|
|
790
|
+
getStatusCodeForMediaRetry,
|
|
791
|
+
getStream,
|
|
792
|
+
getUrlFromDirectPath,
|
|
793
|
+
getWAUploadToServer,
|
|
794
|
+
hkdfInfoKey,
|
|
795
|
+
mediaMessageSHA256B64,
|
|
796
|
+
toBuffer,
|
|
797
|
+
toReadable,
|
|
798
|
+
uploadWithNodeHttp
|
|
799
|
+
});
|