@vinzsocket/baileys 2.8.20 → 2.8.35
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/lib/Defaults/index.js +38 -31
- package/lib/Signal/Group/ciphertext-message.js +9 -2
- package/lib/Signal/Group/group-session-builder.js +15 -7
- package/lib/Signal/Group/group_cipher.js +21 -13
- package/lib/Signal/Group/index.js +79 -12
- package/lib/Signal/Group/keyhelper.js +16 -6
- package/lib/Signal/Group/queue-job.js +9 -2
- package/lib/Signal/Group/sender-chain-key.js +14 -6
- package/lib/Signal/Group/sender-key-distribution-message.js +13 -6
- package/lib/Signal/Group/sender-key-message.js +17 -9
- package/lib/Signal/Group/sender-key-name.js +9 -2
- package/lib/Signal/Group/sender-key-record.js +16 -9
- package/lib/Signal/Group/sender-key-state.js +13 -6
- package/lib/Signal/Group/sender-message-key.js +12 -4
- package/lib/Signal/libsignal.js +35 -26
- package/lib/Signal/lid-mapping.js +27 -19
- package/lib/Socket/Client/index.js +27 -3
- package/lib/Socket/Client/types.js +11 -4
- package/lib/Socket/Client/websocket.js +19 -11
- package/lib/Socket/business.js +41 -34
- package/lib/Socket/chats.js +103 -95
- package/lib/Socket/communities.js +58 -49
- package/lib/Socket/groups.js +59 -51
- package/lib/Socket/index.js +11 -6
- package/lib/Socket/messages-recv.js +153 -145
- package/lib/Socket/messages-send.js +112 -104
- package/lib/Socket/mex.js +15 -8
- package/lib/Socket/newsletter.js +30 -23
- package/lib/Socket/socket.js +112 -105
- package/lib/Store/index.js +49 -4
- package/lib/Store/make-cache-manager-store.js +19 -11
- package/lib/Store/make-in-memory-store.js +38 -29
- package/lib/Store/make-ordered-dictionary.js +9 -2
- package/lib/Store/object-repository.js +9 -2
- package/lib/Types/Auth.js +5 -2
- package/lib/Types/Bussines.js +5 -2
- package/lib/Types/Call.js +5 -2
- package/lib/Types/Chat.js +7 -1
- package/lib/Types/Contact.js +5 -2
- package/lib/Types/Events.js +3 -2
- package/lib/Types/GroupMetadata.js +5 -2
- package/lib/Types/Label.js +8 -2
- package/lib/Types/LabelAssociation.js +8 -2
- package/lib/Types/Message.js +18 -6
- package/lib/Types/Newsletter.js +10 -4
- package/lib/Types/Product.js +5 -2
- package/lib/Types/Signal.js +3 -2
- package/lib/Types/Socket.js +4 -3
- package/lib/Types/State.js +9 -3
- package/lib/Types/USync.js +3 -2
- package/lib/Types/index.js +155 -14
- package/lib/Utils/auth-utils.js +35 -25
- package/lib/Utils/baileys-event-stream.js +24 -15
- package/lib/Utils/business.js +72 -59
- package/lib/Utils/chat-utils.js +94 -77
- package/lib/Utils/crypto.js +55 -30
- package/lib/Utils/decode-wa-message.js +47 -37
- package/lib/Utils/event-buffer.js +25 -17
- package/lib/Utils/extended-messages.js +16 -9
- package/lib/Utils/generics.js +101 -62
- package/lib/Utils/history.js +33 -23
- package/lib/Utils/index.js +236 -22
- package/lib/Utils/lid-resolver.js +14 -5
- package/lib/Utils/link-preview.js +14 -7
- package/lib/Utils/logger.js +10 -4
- package/lib/Utils/lt-hash.js +10 -4
- package/lib/Utils/make-mutex.js +11 -3
- package/lib/Utils/mention.js +14 -4
- package/lib/Utils/message-retry-manager.js +13 -6
- package/lib/Utils/messages-media.js +128 -93
- package/lib/Utils/messages.js +125 -98
- package/lib/Utils/noise-handler.js +28 -21
- package/lib/Utils/process-message.js +74 -63
- package/lib/Utils/signal.js +48 -33
- package/lib/Utils/use-multi-file-auth-state.js +27 -20
- package/lib/Utils/validate-connection.js +57 -47
- package/lib/WABinary/constants.js +10 -4
- package/lib/WABinary/decode.js +20 -10
- package/lib/WABinary/encode.js +12 -4
- package/lib/WABinary/generic-utils.js +32 -15
- package/lib/WABinary/index.js +60 -6
- package/lib/WABinary/jid-utils.js +39 -20
- package/lib/WABinary/types.js +4 -2
- package/lib/WAM/BinaryInfo.js +9 -2
- package/lib/WAM/constants.js +13001 -1
- package/lib/WAM/encode.js +17 -10
- package/lib/WAM/index.js +38 -4
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +12 -5
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +13 -6
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +11 -4
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +11 -4
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +11 -4
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +26 -19
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +9 -2
- package/lib/WAUSync/Protocols/index.js +60 -6
- package/lib/WAUSync/USyncQuery.js +24 -17
- package/lib/WAUSync/USyncUser.js +9 -2
- package/lib/WAUSync/index.js +38 -4
- package/lib/index.js +114 -12
- package/package.json +2 -1
- package/lib/Defaults/index.d.ts +0 -58
- package/lib/Defaults/index.d.ts.map +0 -1
- package/lib/Defaults/index.js.map +0 -1
- package/lib/Signal/Group/ciphertext-message.d.ts +0 -10
- package/lib/Signal/Group/ciphertext-message.d.ts.map +0 -1
- package/lib/Signal/Group/ciphertext-message.js.map +0 -1
- package/lib/Signal/Group/group-session-builder.d.ts +0 -15
- package/lib/Signal/Group/group-session-builder.d.ts.map +0 -1
- package/lib/Signal/Group/group-session-builder.js.map +0 -1
- package/lib/Signal/Group/group_cipher.d.ts +0 -18
- package/lib/Signal/Group/group_cipher.d.ts.map +0 -1
- package/lib/Signal/Group/group_cipher.js.map +0 -1
- package/lib/Signal/Group/index.d.ts +0 -12
- package/lib/Signal/Group/index.d.ts.map +0 -1
- package/lib/Signal/Group/index.js.map +0 -1
- package/lib/Signal/Group/keyhelper.d.ts +0 -11
- package/lib/Signal/Group/keyhelper.d.ts.map +0 -1
- package/lib/Signal/Group/keyhelper.js.map +0 -1
- package/lib/Signal/Group/queue-job.d.ts +0 -2
- package/lib/Signal/Group/sender-chain-key.d.ts +0 -14
- package/lib/Signal/Group/sender-chain-key.d.ts.map +0 -1
- package/lib/Signal/Group/sender-chain-key.js.map +0 -1
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -17
- package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +0 -1
- package/lib/Signal/Group/sender-key-distribution-message.js.map +0 -1
- package/lib/Signal/Group/sender-key-message.d.ts +0 -19
- package/lib/Signal/Group/sender-key-message.d.ts.map +0 -1
- package/lib/Signal/Group/sender-key-message.js.map +0 -1
- package/lib/Signal/Group/sender-key-name.d.ts +0 -18
- package/lib/Signal/Group/sender-key-name.d.ts.map +0 -1
- package/lib/Signal/Group/sender-key-name.js.map +0 -1
- package/lib/Signal/Group/sender-key-record.d.ts +0 -31
- package/lib/Signal/Group/sender-key-record.d.ts.map +0 -1
- package/lib/Signal/Group/sender-key-record.js.map +0 -1
- package/lib/Signal/Group/sender-key-state.d.ts +0 -39
- package/lib/Signal/Group/sender-key-state.d.ts.map +0 -1
- package/lib/Signal/Group/sender-key-state.js.map +0 -1
- package/lib/Signal/Group/sender-message-key.d.ts +0 -12
- package/lib/Signal/Group/sender-message-key.d.ts.map +0 -1
- package/lib/Signal/Group/sender-message-key.js.map +0 -1
- package/lib/Signal/libsignal.d.ts +0 -8
- package/lib/Signal/libsignal.d.ts.map +0 -1
- package/lib/Signal/libsignal.js.map +0 -1
- package/lib/Signal/lid-mapping.d.ts +0 -30
- package/lib/Signal/lid-mapping.d.ts.map +0 -1
- package/lib/Signal/lid-mapping.js.map +0 -1
- package/lib/Socket/Client/index.d.ts +0 -3
- package/lib/Socket/Client/index.d.ts.map +0 -1
- package/lib/Socket/Client/index.js.map +0 -1
- package/lib/Socket/Client/types.d.ts +0 -16
- package/lib/Socket/Client/types.d.ts.map +0 -1
- package/lib/Socket/Client/types.js.map +0 -1
- package/lib/Socket/Client/websocket.d.ts +0 -13
- package/lib/Socket/Client/websocket.d.ts.map +0 -1
- package/lib/Socket/Client/websocket.js.map +0 -1
- package/lib/Socket/business.d.ts +0 -188
- package/lib/Socket/business.d.ts.map +0 -1
- package/lib/Socket/business.js.map +0 -1
- package/lib/Socket/chats.d.ts +0 -98
- package/lib/Socket/chats.d.ts.map +0 -1
- package/lib/Socket/chats.js.map +0 -1
- package/lib/Socket/communities.d.ts +0 -233
- package/lib/Socket/communities.d.ts.map +0 -1
- package/lib/Socket/communities.js.map +0 -1
- package/lib/Socket/groups.d.ts +0 -137
- package/lib/Socket/groups.d.ts.map +0 -1
- package/lib/Socket/groups.js.map +0 -1
- package/lib/Socket/index.d.ts +0 -220
- package/lib/Socket/index.d.ts.map +0 -1
- package/lib/Socket/index.js.map +0 -1
- package/lib/Socket/messages-recv.d.ts +0 -173
- package/lib/Socket/messages-recv.d.ts.map +0 -1
- package/lib/Socket/messages-recv.js.map +0 -1
- package/lib/Socket/messages-send.d.ts +0 -169
- package/lib/Socket/messages-send.d.ts.map +0 -1
- package/lib/Socket/messages-send.js.map +0 -1
- package/lib/Socket/mex.d.ts +0 -3
- package/lib/Socket/mex.d.ts.map +0 -1
- package/lib/Socket/mex.js.map +0 -1
- package/lib/Socket/newsletter.d.ts +0 -147
- package/lib/Socket/newsletter.d.ts.map +0 -1
- package/lib/Socket/newsletter.js.map +0 -1
- package/lib/Socket/socket.d.ts +0 -50
- package/lib/Socket/socket.d.ts.map +0 -1
- package/lib/Socket/socket.js.map +0 -1
- package/lib/Store/index.d.ts +0 -4
- package/lib/Store/make-cache-manager-store.d.ts +0 -17
- package/lib/Store/make-in-memory-store.d.ts +0 -118
- package/lib/Store/make-ordered-dictionary.d.ts +0 -14
- package/lib/Store/object-repository.d.ts +0 -10
- package/lib/Types/Auth.d.ts +0 -105
- package/lib/Types/Auth.d.ts.map +0 -1
- package/lib/Types/Auth.js.map +0 -1
- package/lib/Types/Bussines.d.ts +0 -25
- package/lib/Types/Bussines.d.ts.map +0 -1
- package/lib/Types/Bussines.js.map +0 -1
- package/lib/Types/Call.d.ts +0 -14
- package/lib/Types/Call.d.ts.map +0 -1
- package/lib/Types/Call.js.map +0 -1
- package/lib/Types/Chat.d.ts +0 -123
- package/lib/Types/Chat.d.ts.map +0 -1
- package/lib/Types/Chat.js.map +0 -1
- package/lib/Types/Contact.d.ts +0 -24
- package/lib/Types/Contact.d.ts.map +0 -1
- package/lib/Types/Contact.js.map +0 -1
- package/lib/Types/Events.d.ts +0 -199
- package/lib/Types/Events.d.ts.map +0 -1
- package/lib/Types/Events.js.map +0 -1
- package/lib/Types/GroupMetadata.d.ts +0 -66
- package/lib/Types/GroupMetadata.d.ts.map +0 -1
- package/lib/Types/GroupMetadata.js.map +0 -1
- package/lib/Types/Label.d.ts +0 -47
- package/lib/Types/Label.d.ts.map +0 -1
- package/lib/Types/Label.js.map +0 -1
- package/lib/Types/LabelAssociation.d.ts +0 -30
- package/lib/Types/LabelAssociation.d.ts.map +0 -1
- package/lib/Types/LabelAssociation.js.map +0 -1
- package/lib/Types/Message.d.ts +0 -300
- package/lib/Types/Message.d.ts.map +0 -1
- package/lib/Types/Message.js.map +0 -1
- package/lib/Types/Newsletter.d.ts +0 -135
- package/lib/Types/Newsletter.d.ts.map +0 -1
- package/lib/Types/Newsletter.js.map +0 -1
- package/lib/Types/Product.d.ts +0 -79
- package/lib/Types/Product.d.ts.map +0 -1
- package/lib/Types/Product.js.map +0 -1
- package/lib/Types/Signal.d.ts +0 -82
- package/lib/Types/Signal.d.ts.map +0 -1
- package/lib/Types/Signal.js.map +0 -1
- package/lib/Types/Socket.d.ts +0 -130
- package/lib/Types/Socket.d.ts.map +0 -1
- package/lib/Types/Socket.js.map +0 -1
- package/lib/Types/State.d.ts +0 -39
- package/lib/Types/State.d.ts.map +0 -1
- package/lib/Types/State.js.map +0 -1
- package/lib/Types/USync.d.ts +0 -26
- package/lib/Types/USync.d.ts.map +0 -1
- package/lib/Types/USync.js.map +0 -1
- package/lib/Types/index.d.ts +0 -65
- package/lib/Types/index.d.ts.map +0 -1
- package/lib/Types/index.js.map +0 -1
- package/lib/Utils/auth-utils.d.ts +0 -19
- package/lib/Utils/auth-utils.d.ts.map +0 -1
- package/lib/Utils/auth-utils.js.map +0 -1
- package/lib/Utils/baileys-event-stream.d.ts +0 -17
- package/lib/Utils/baileys-event-stream.d.ts.map +0 -1
- package/lib/Utils/baileys-event-stream.js.map +0 -1
- package/lib/Utils/business.d.ts +0 -23
- package/lib/Utils/business.d.ts.map +0 -1
- package/lib/Utils/business.js.map +0 -1
- package/lib/Utils/chat-utils.d.ts +0 -71
- package/lib/Utils/chat-utils.d.ts.map +0 -1
- package/lib/Utils/chat-utils.js.map +0 -1
- package/lib/Utils/crypto.d.ts +0 -41
- package/lib/Utils/crypto.d.ts.map +0 -1
- package/lib/Utils/crypto.js.map +0 -1
- package/lib/Utils/decode-wa-message.d.ts +0 -46
- package/lib/Utils/decode-wa-message.d.ts.map +0 -1
- package/lib/Utils/decode-wa-message.js.map +0 -1
- package/lib/Utils/event-buffer.d.ts +0 -34
- package/lib/Utils/event-buffer.d.ts.map +0 -1
- package/lib/Utils/event-buffer.js.map +0 -1
- package/lib/Utils/extended-messages.d.ts +0 -73
- package/lib/Utils/generics.d.ts +0 -92
- package/lib/Utils/generics.d.ts.map +0 -1
- package/lib/Utils/generics.js.map +0 -1
- package/lib/Utils/history.d.ts +0 -20
- package/lib/Utils/history.d.ts.map +0 -1
- package/lib/Utils/history.js.map +0 -1
- package/lib/Utils/index.d.ts +0 -22
- package/lib/Utils/index.d.ts.map +0 -1
- package/lib/Utils/index.js.map +0 -1
- package/lib/Utils/lid-resolver.d.ts +0 -17
- package/lib/Utils/link-preview.d.ts +0 -22
- package/lib/Utils/link-preview.d.ts.map +0 -1
- package/lib/Utils/link-preview.js.map +0 -1
- package/lib/Utils/logger.d.ts +0 -12
- package/lib/Utils/logger.d.ts.map +0 -1
- package/lib/Utils/logger.js.map +0 -1
- package/lib/Utils/lt-hash.d.ts +0 -13
- package/lib/Utils/lt-hash.d.ts.map +0 -1
- package/lib/Utils/lt-hash.js.map +0 -1
- package/lib/Utils/make-mutex.d.ts +0 -8
- package/lib/Utils/make-mutex.d.ts.map +0 -1
- package/lib/Utils/make-mutex.js.map +0 -1
- package/lib/Utils/mention.d.ts +0 -27
- package/lib/Utils/message-retry-manager.d.ts +0 -82
- package/lib/Utils/message-retry-manager.d.ts.map +0 -1
- package/lib/Utils/message-retry-manager.js.map +0 -1
- package/lib/Utils/messages-media.d.ts +0 -113
- package/lib/Utils/messages-media.d.ts.map +0 -1
- package/lib/Utils/messages-media.js.map +0 -1
- package/lib/Utils/messages.d.ts +0 -76
- package/lib/Utils/messages.d.ts.map +0 -1
- package/lib/Utils/messages.js.map +0 -1
- package/lib/Utils/noise-handler.d.ts +0 -20
- package/lib/Utils/noise-handler.d.ts.map +0 -1
- package/lib/Utils/noise-handler.js.map +0 -1
- package/lib/Utils/process-message.d.ts +0 -43
- package/lib/Utils/process-message.d.ts.map +0 -1
- package/lib/Utils/process-message.js.map +0 -1
- package/lib/Utils/signal.d.ts +0 -34
- package/lib/Utils/signal.d.ts.map +0 -1
- package/lib/Utils/signal.js.map +0 -1
- package/lib/Utils/use-multi-file-auth-state.d.ts +0 -13
- package/lib/Utils/use-multi-file-auth-state.d.ts.map +0 -1
- package/lib/Utils/use-multi-file-auth-state.js.map +0 -1
- package/lib/Utils/validate-connection.d.ts +0 -11
- package/lib/Utils/validate-connection.d.ts.map +0 -1
- package/lib/Utils/validate-connection.js.map +0 -1
- package/lib/WABinary/constants.d.ts +0 -28
- package/lib/WABinary/constants.d.ts.map +0 -1
- package/lib/WABinary/constants.js.map +0 -1
- package/lib/WABinary/decode.d.ts +0 -7
- package/lib/WABinary/decode.d.ts.map +0 -1
- package/lib/WABinary/decode.js.map +0 -1
- package/lib/WABinary/encode.d.ts +0 -3
- package/lib/WABinary/encode.d.ts.map +0 -1
- package/lib/WABinary/encode.js.map +0 -1
- package/lib/WABinary/generic-utils.d.ts +0 -15
- package/lib/WABinary/generic-utils.d.ts.map +0 -1
- package/lib/WABinary/generic-utils.js.map +0 -1
- package/lib/WABinary/index.d.ts +0 -6
- package/lib/WABinary/index.d.ts.map +0 -1
- package/lib/WABinary/index.js.map +0 -1
- package/lib/WABinary/jid-utils.d.ts +0 -37
- package/lib/WABinary/jid-utils.d.ts.map +0 -1
- package/lib/WABinary/jid-utils.js.map +0 -1
- package/lib/WABinary/types.d.ts +0 -19
- package/lib/WABinary/types.d.ts.map +0 -1
- package/lib/WABinary/types.js.map +0 -1
- package/lib/WAM/BinaryInfo.d.ts +0 -9
- package/lib/WAM/BinaryInfo.d.ts.map +0 -1
- package/lib/WAM/BinaryInfo.js.map +0 -1
- package/lib/WAM/constants.d.ts +0 -40
- package/lib/WAM/constants.d.ts.map +0 -1
- package/lib/WAM/constants.js.map +0 -1
- package/lib/WAM/encode.d.ts +0 -3
- package/lib/WAM/encode.d.ts.map +0 -1
- package/lib/WAM/encode.js.map +0 -1
- package/lib/WAM/index.d.ts +0 -4
- package/lib/WAM/index.d.ts.map +0 -1
- package/lib/WAM/index.js.map +0 -1
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -10
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -23
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -13
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -13
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +0 -8
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +0 -26
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +0 -9
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/index.d.ts +0 -6
- package/lib/WAUSync/Protocols/index.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/index.js.map +0 -1
- package/lib/WAUSync/USyncQuery.d.ts +0 -30
- package/lib/WAUSync/USyncQuery.d.ts.map +0 -1
- package/lib/WAUSync/USyncQuery.js.map +0 -1
- package/lib/WAUSync/USyncUser.d.ts +0 -13
- package/lib/WAUSync/USyncUser.d.ts.map +0 -1
- package/lib/WAUSync/USyncUser.js.map +0 -1
- package/lib/WAUSync/index.d.ts +0 -4
- package/lib/WAUSync/index.d.ts.map +0 -1
- package/lib/WAUSync/index.js.map +0 -1
- package/lib/index.d.ts +0 -13
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
|
@@ -1,19 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.encryptedStream = exports.encryptMediaRetryRequest = exports.encodeBase64EncodedStringForUpload = exports.downloadEncryptedContent = exports.downloadContentFromMessage = exports.decryptMediaRetryData = exports.decodeMediaRetryNode = void 0;
|
|
7
|
+
exports.extensionForMediaMessage = extensionForMediaMessage;
|
|
8
|
+
exports.generateProfilePicture = exports.extractImageThumb = void 0;
|
|
9
|
+
exports.generateThumbnail = generateThumbnail;
|
|
10
|
+
exports.getAudioDuration = getAudioDuration;
|
|
11
|
+
exports.getAudioWaveform = getAudioWaveform;
|
|
12
|
+
exports.getHttpStream = void 0;
|
|
13
|
+
exports.getMediaKeys = getMediaKeys;
|
|
14
|
+
exports.toReadable = exports.toBuffer = exports.mediaMessageSHA256B64 = exports.hkdfInfoKey = exports.getWAUploadToServer = exports.getUrlFromDirectPath = exports.getStream = exports.getStatusCodeForMediaRetry = exports.getRawMediaUploadData = void 0;
|
|
15
|
+
var _boom = require("@hapi/boom");
|
|
16
|
+
var _axios = _interopRequireDefault(require("axios"));
|
|
17
|
+
var _child_process = require("child_process");
|
|
18
|
+
var Crypto = _interopRequireWildcard(require("crypto"));
|
|
19
|
+
var _events = require("events");
|
|
20
|
+
var _fs = require("fs");
|
|
21
|
+
var _os = require("os");
|
|
22
|
+
var _path = require("path");
|
|
23
|
+
var _stream = require("stream");
|
|
24
|
+
var _url = require("url");
|
|
25
|
+
var _index = require("../../WAProto/index.js");
|
|
26
|
+
var _index2 = require("../Defaults/index.js");
|
|
27
|
+
var _index3 = require("../WABinary/index.js");
|
|
28
|
+
var _crypto2 = require("./crypto.js");
|
|
29
|
+
var _generics = require("./generics.js");
|
|
30
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
31
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
32
|
+
const getTmpFilesDirectory = () => (0, _os.tmpdir)();
|
|
17
33
|
const getImageProcessingLibrary = async () => {
|
|
18
34
|
//@ts-ignore
|
|
19
35
|
const [jimp, sharp] = await Promise.all([import('jimp').catch(() => {}), import('sharp').catch(() => {})]);
|
|
@@ -27,31 +43,32 @@ const getImageProcessingLibrary = async () => {
|
|
|
27
43
|
jimp
|
|
28
44
|
};
|
|
29
45
|
}
|
|
30
|
-
throw new Boom('No image processing library available');
|
|
46
|
+
throw new _boom.Boom('No image processing library available');
|
|
31
47
|
};
|
|
32
|
-
|
|
33
|
-
const hkdfInfo = MEDIA_HKDF_KEY_MAPPING[type];
|
|
48
|
+
const hkdfInfoKey = type => {
|
|
49
|
+
const hkdfInfo = _index2.MEDIA_HKDF_KEY_MAPPING[type];
|
|
34
50
|
return `WhatsApp ${hkdfInfo} Keys`;
|
|
35
51
|
};
|
|
36
|
-
|
|
52
|
+
exports.hkdfInfoKey = hkdfInfoKey;
|
|
53
|
+
const getRawMediaUploadData = async (media, mediaType, logger) => {
|
|
37
54
|
const {
|
|
38
55
|
stream
|
|
39
56
|
} = await getStream(media);
|
|
40
57
|
logger?.debug('got stream for raw upload');
|
|
41
58
|
const hasher = Crypto.createHash('sha256');
|
|
42
|
-
const filePath = join(tmpdir(), mediaType + generateMessageIDV2());
|
|
43
|
-
const fileWriteStream = createWriteStream(filePath);
|
|
59
|
+
const filePath = (0, _path.join)((0, _os.tmpdir)(), mediaType + (0, _generics.generateMessageIDV2)());
|
|
60
|
+
const fileWriteStream = (0, _fs.createWriteStream)(filePath);
|
|
44
61
|
let fileLength = 0;
|
|
45
62
|
try {
|
|
46
63
|
for await (const data of stream) {
|
|
47
64
|
fileLength += data.length;
|
|
48
65
|
hasher.update(data);
|
|
49
66
|
if (!fileWriteStream.write(data)) {
|
|
50
|
-
await once(fileWriteStream, 'drain');
|
|
67
|
+
await (0, _events.once)(fileWriteStream, 'drain');
|
|
51
68
|
}
|
|
52
69
|
}
|
|
53
70
|
fileWriteStream.end();
|
|
54
|
-
await once(fileWriteStream, 'finish');
|
|
71
|
+
await (0, _events.once)(fileWriteStream, 'finish');
|
|
55
72
|
stream.destroy();
|
|
56
73
|
const fileSha256 = hasher.digest();
|
|
57
74
|
logger?.debug('hashed data for raw upload');
|
|
@@ -64,7 +81,7 @@ export const getRawMediaUploadData = async (media, mediaType, logger) => {
|
|
|
64
81
|
fileWriteStream.destroy();
|
|
65
82
|
stream.destroy();
|
|
66
83
|
try {
|
|
67
|
-
await
|
|
84
|
+
await _fs.promises.unlink(filePath);
|
|
68
85
|
} catch {
|
|
69
86
|
//
|
|
70
87
|
}
|
|
@@ -72,15 +89,16 @@ export const getRawMediaUploadData = async (media, mediaType, logger) => {
|
|
|
72
89
|
}
|
|
73
90
|
};
|
|
74
91
|
/** generates all the keys required to encrypt/decrypt & sign a media message */
|
|
75
|
-
|
|
92
|
+
exports.getRawMediaUploadData = getRawMediaUploadData;
|
|
93
|
+
async function getMediaKeys(buffer, mediaType) {
|
|
76
94
|
if (!buffer) {
|
|
77
|
-
throw new Boom('Cannot derive from empty media key');
|
|
95
|
+
throw new _boom.Boom('Cannot derive from empty media key');
|
|
78
96
|
}
|
|
79
97
|
if (typeof buffer === 'string') {
|
|
80
98
|
buffer = Buffer.from(buffer.replace('data:;base64,', ''), 'base64');
|
|
81
99
|
}
|
|
82
100
|
// expand using HKDF to 112 bytes, also pass in the relevant app info
|
|
83
|
-
const expandedMediaKey = await hkdf(buffer, 112, {
|
|
101
|
+
const expandedMediaKey = await (0, _crypto2.hkdf)(buffer, 112, {
|
|
84
102
|
info: hkdfInfoKey(mediaType)
|
|
85
103
|
});
|
|
86
104
|
return {
|
|
@@ -92,7 +110,7 @@ export async function getMediaKeys(buffer, mediaType) {
|
|
|
92
110
|
/** Extracts video thumb using FFMPEG */
|
|
93
111
|
const extractVideoThumb = async (path, destPath, time, size) => new Promise((resolve, reject) => {
|
|
94
112
|
const cmd = `ffmpeg -ss ${time} -i ${path} -y -vf scale=${size.width}:-1 -vframes 1 -f image2 ${destPath}`;
|
|
95
|
-
exec(cmd, err => {
|
|
113
|
+
(0, _child_process.exec)(cmd, err => {
|
|
96
114
|
if (err) {
|
|
97
115
|
reject(err);
|
|
98
116
|
} else {
|
|
@@ -100,10 +118,10 @@ const extractVideoThumb = async (path, destPath, time, size) => new Promise((res
|
|
|
100
118
|
}
|
|
101
119
|
});
|
|
102
120
|
});
|
|
103
|
-
|
|
121
|
+
const extractImageThumb = async (bufferOrFilePath, width = 32) => {
|
|
104
122
|
// TODO: Move entirely to sharp, removing jimp as it supports readable streams
|
|
105
123
|
// This will have positive speed and performance impacts as well as minimizing RAM usage.
|
|
106
|
-
if (bufferOrFilePath instanceof Readable) {
|
|
124
|
+
if (bufferOrFilePath instanceof _stream.Readable) {
|
|
107
125
|
bufferOrFilePath = await toBuffer(bufferOrFilePath);
|
|
108
126
|
}
|
|
109
127
|
const lib = await getImageProcessingLibrary();
|
|
@@ -137,11 +155,13 @@ export const extractImageThumb = async (bufferOrFilePath, width = 32) => {
|
|
|
137
155
|
original: dimensions
|
|
138
156
|
};
|
|
139
157
|
} else {
|
|
140
|
-
throw new Boom('No image processing library available');
|
|
158
|
+
throw new _boom.Boom('No image processing library available');
|
|
141
159
|
}
|
|
142
160
|
};
|
|
143
|
-
|
|
144
|
-
|
|
161
|
+
exports.extractImageThumb = extractImageThumb;
|
|
162
|
+
const encodeBase64EncodedStringForUpload = b64 => encodeURIComponent(b64.replace(/\+/g, '-').replace(/\//g, '_').replace(/\=+$/, ''));
|
|
163
|
+
exports.encodeBase64EncodedStringForUpload = encodeBase64EncodedStringForUpload;
|
|
164
|
+
const generateProfilePicture = async (mediaUpload, dimensions) => {
|
|
145
165
|
let buffer;
|
|
146
166
|
const {
|
|
147
167
|
width: w = 640,
|
|
@@ -180,18 +200,20 @@ export const generateProfilePicture = async (mediaUpload, dimensions) => {
|
|
|
180
200
|
quality: 50
|
|
181
201
|
});
|
|
182
202
|
} else {
|
|
183
|
-
throw new Boom('No image processing library available');
|
|
203
|
+
throw new _boom.Boom('No image processing library available');
|
|
184
204
|
}
|
|
185
205
|
return {
|
|
186
206
|
img: await img
|
|
187
207
|
};
|
|
188
208
|
};
|
|
189
209
|
/** gets the SHA256 of the given media message */
|
|
190
|
-
|
|
210
|
+
exports.generateProfilePicture = generateProfilePicture;
|
|
211
|
+
const mediaMessageSHA256B64 = message => {
|
|
191
212
|
const media = Object.values(message)[0];
|
|
192
213
|
return media?.fileSha256 && Buffer.from(media.fileSha256).toString('base64');
|
|
193
214
|
};
|
|
194
|
-
|
|
215
|
+
exports.mediaMessageSHA256B64 = mediaMessageSHA256B64;
|
|
216
|
+
async function getAudioDuration(buffer) {
|
|
195
217
|
const musicMetadata = await import('music-metadata');
|
|
196
218
|
let metadata;
|
|
197
219
|
const options = {
|
|
@@ -209,7 +231,7 @@ export async function getAudioDuration(buffer) {
|
|
|
209
231
|
/**
|
|
210
232
|
referenced from and modifying https://github.com/wppconnect-team/wa-js/blob/main/src/chat/functions/prepareAudioWaveform.ts
|
|
211
233
|
*/
|
|
212
|
-
|
|
234
|
+
async function getAudioWaveform(buffer, logger) {
|
|
213
235
|
try {
|
|
214
236
|
// @ts-ignore
|
|
215
237
|
const {
|
|
@@ -219,7 +241,7 @@ export async function getAudioWaveform(buffer, logger) {
|
|
|
219
241
|
if (Buffer.isBuffer(buffer)) {
|
|
220
242
|
audioData = buffer;
|
|
221
243
|
} else if (typeof buffer === 'string') {
|
|
222
|
-
const rStream = createReadStream(buffer);
|
|
244
|
+
const rStream = (0, _fs.createReadStream)(buffer);
|
|
223
245
|
audioData = await toBuffer(rStream);
|
|
224
246
|
} else {
|
|
225
247
|
audioData = await toBuffer(buffer);
|
|
@@ -247,15 +269,16 @@ export async function getAudioWaveform(buffer, logger) {
|
|
|
247
269
|
logger?.debug('Failed to generate waveform: ' + e);
|
|
248
270
|
}
|
|
249
271
|
}
|
|
250
|
-
|
|
251
|
-
const readable = new Readable({
|
|
272
|
+
const toReadable = buffer => {
|
|
273
|
+
const readable = new _stream.Readable({
|
|
252
274
|
read: () => {}
|
|
253
275
|
});
|
|
254
276
|
readable.push(buffer);
|
|
255
277
|
readable.push(null);
|
|
256
278
|
return readable;
|
|
257
279
|
};
|
|
258
|
-
|
|
280
|
+
exports.toReadable = toReadable;
|
|
281
|
+
const toBuffer = async stream => {
|
|
259
282
|
const chunks = [];
|
|
260
283
|
for await (const chunk of stream) {
|
|
261
284
|
chunks.push(chunk);
|
|
@@ -263,7 +286,8 @@ export const toBuffer = async stream => {
|
|
|
263
286
|
stream.destroy();
|
|
264
287
|
return Buffer.concat(chunks);
|
|
265
288
|
};
|
|
266
|
-
|
|
289
|
+
exports.toBuffer = toBuffer;
|
|
290
|
+
const getStream = async (item, opts) => {
|
|
267
291
|
if (Buffer.isBuffer(item)) {
|
|
268
292
|
return {
|
|
269
293
|
stream: toReadable(item),
|
|
@@ -291,12 +315,13 @@ export const getStream = async (item, opts) => {
|
|
|
291
315
|
};
|
|
292
316
|
}
|
|
293
317
|
return {
|
|
294
|
-
stream: createReadStream(item.url),
|
|
318
|
+
stream: (0, _fs.createReadStream)(item.url),
|
|
295
319
|
type: 'file'
|
|
296
320
|
};
|
|
297
321
|
};
|
|
298
322
|
/** generates a thumbnail for a given media, if required */
|
|
299
|
-
|
|
323
|
+
exports.getStream = getStream;
|
|
324
|
+
async function generateThumbnail(file, mediaType, options) {
|
|
300
325
|
let thumbnail;
|
|
301
326
|
let originalImageDimensions;
|
|
302
327
|
if (mediaType === 'image') {
|
|
@@ -312,15 +337,15 @@ export async function generateThumbnail(file, mediaType, options) {
|
|
|
312
337
|
};
|
|
313
338
|
}
|
|
314
339
|
} else if (mediaType === 'video') {
|
|
315
|
-
const imgFilename = join(getTmpFilesDirectory(), generateMessageIDV2() + '.jpg');
|
|
340
|
+
const imgFilename = (0, _path.join)(getTmpFilesDirectory(), (0, _generics.generateMessageIDV2)() + '.jpg');
|
|
316
341
|
try {
|
|
317
342
|
await extractVideoThumb(file, imgFilename, '00:00:00', {
|
|
318
343
|
width: 32,
|
|
319
344
|
height: 32
|
|
320
345
|
});
|
|
321
|
-
const buff = await
|
|
346
|
+
const buff = await _fs.promises.readFile(imgFilename);
|
|
322
347
|
thumbnail = buff.toString('base64');
|
|
323
|
-
await
|
|
348
|
+
await _fs.promises.unlink(imgFilename);
|
|
324
349
|
} catch (err) {
|
|
325
350
|
options.logger?.debug('could not generate video thumb: ' + err);
|
|
326
351
|
}
|
|
@@ -330,14 +355,15 @@ export async function generateThumbnail(file, mediaType, options) {
|
|
|
330
355
|
originalImageDimensions
|
|
331
356
|
};
|
|
332
357
|
}
|
|
333
|
-
|
|
334
|
-
const fetched = await
|
|
358
|
+
const getHttpStream = async (url, options = {}) => {
|
|
359
|
+
const fetched = await _axios.default.get(url.toString(), {
|
|
335
360
|
...options,
|
|
336
361
|
responseType: 'stream'
|
|
337
362
|
});
|
|
338
363
|
return fetched.data;
|
|
339
364
|
};
|
|
340
|
-
|
|
365
|
+
exports.getHttpStream = getHttpStream;
|
|
366
|
+
const encryptedStream = async (media, mediaType, {
|
|
341
367
|
logger,
|
|
342
368
|
saveOriginalFileIfRequired,
|
|
343
369
|
opts
|
|
@@ -353,13 +379,13 @@ export const encryptedStream = async (media, mediaType, {
|
|
|
353
379
|
iv,
|
|
354
380
|
macKey
|
|
355
381
|
} = await getMediaKeys(mediaKey, mediaType);
|
|
356
|
-
const encFilePath = join(getTmpFilesDirectory(), mediaType + generateMessageIDV2() + '-enc');
|
|
357
|
-
const encFileWriteStream = createWriteStream(encFilePath);
|
|
382
|
+
const encFilePath = (0, _path.join)(getTmpFilesDirectory(), mediaType + (0, _generics.generateMessageIDV2)() + '-enc');
|
|
383
|
+
const encFileWriteStream = (0, _fs.createWriteStream)(encFilePath);
|
|
358
384
|
let originalFileStream;
|
|
359
385
|
let originalFilePath;
|
|
360
386
|
if (saveOriginalFileIfRequired) {
|
|
361
|
-
originalFilePath = join(getTmpFilesDirectory(), mediaType + generateMessageIDV2() + '-original');
|
|
362
|
-
originalFileStream = createWriteStream(originalFilePath);
|
|
387
|
+
originalFilePath = (0, _path.join)(getTmpFilesDirectory(), mediaType + (0, _generics.generateMessageIDV2)() + '-original');
|
|
388
|
+
originalFileStream = (0, _fs.createWriteStream)(originalFilePath);
|
|
363
389
|
}
|
|
364
390
|
let fileLength = 0;
|
|
365
391
|
const aes = Crypto.createCipheriv('aes-256-cbc', cipherKey, iv);
|
|
@@ -375,7 +401,7 @@ export const encryptedStream = async (media, mediaType, {
|
|
|
375
401
|
for await (const data of stream) {
|
|
376
402
|
fileLength += data.length;
|
|
377
403
|
if (type === 'remote' && opts?.maxContentLength && fileLength + data.length > opts.maxContentLength) {
|
|
378
|
-
throw new Boom(`content length exceeded when encrypting "${type}"`, {
|
|
404
|
+
throw new _boom.Boom(`content length exceeded when encrypting "${type}"`, {
|
|
379
405
|
data: {
|
|
380
406
|
media,
|
|
381
407
|
type
|
|
@@ -384,7 +410,7 @@ export const encryptedStream = async (media, mediaType, {
|
|
|
384
410
|
}
|
|
385
411
|
if (originalFileStream) {
|
|
386
412
|
if (!originalFileStream.write(data)) {
|
|
387
|
-
await once(originalFileStream, 'drain');
|
|
413
|
+
await (0, _events.once)(originalFileStream, 'drain');
|
|
388
414
|
}
|
|
389
415
|
}
|
|
390
416
|
sha256Plain.update(data);
|
|
@@ -419,9 +445,9 @@ export const encryptedStream = async (media, mediaType, {
|
|
|
419
445
|
sha256Enc.destroy();
|
|
420
446
|
stream.destroy();
|
|
421
447
|
try {
|
|
422
|
-
await
|
|
448
|
+
await _fs.promises.unlink(encFilePath);
|
|
423
449
|
if (originalFilePath) {
|
|
424
|
-
await
|
|
450
|
+
await _fs.promises.unlink(originalFilePath);
|
|
425
451
|
}
|
|
426
452
|
} catch (err) {
|
|
427
453
|
logger?.error({
|
|
@@ -431,13 +457,15 @@ export const encryptedStream = async (media, mediaType, {
|
|
|
431
457
|
throw error;
|
|
432
458
|
}
|
|
433
459
|
};
|
|
460
|
+
exports.encryptedStream = encryptedStream;
|
|
434
461
|
const DEF_HOST = 'mmg.whatsapp.net';
|
|
435
462
|
const AES_CHUNK_SIZE = 16;
|
|
436
463
|
const toSmallestChunkSize = num => {
|
|
437
464
|
return Math.floor(num / AES_CHUNK_SIZE) * AES_CHUNK_SIZE;
|
|
438
465
|
};
|
|
439
|
-
|
|
440
|
-
|
|
466
|
+
const getUrlFromDirectPath = directPath => `https://${DEF_HOST}${directPath}`;
|
|
467
|
+
exports.getUrlFromDirectPath = getUrlFromDirectPath;
|
|
468
|
+
const downloadContentFromMessage = async ({
|
|
441
469
|
mediaKey,
|
|
442
470
|
directPath,
|
|
443
471
|
url
|
|
@@ -445,7 +473,7 @@ export const downloadContentFromMessage = async ({
|
|
|
445
473
|
const isValidMediaUrl = url?.startsWith('https://mmg.whatsapp.net/');
|
|
446
474
|
const downloadUrl = isValidMediaUrl ? url : getUrlFromDirectPath(directPath);
|
|
447
475
|
if (!downloadUrl) {
|
|
448
|
-
throw new Boom('No valid media URL or directPath present in message', {
|
|
476
|
+
throw new _boom.Boom('No valid media URL or directPath present in message', {
|
|
449
477
|
statusCode: 400
|
|
450
478
|
});
|
|
451
479
|
}
|
|
@@ -456,7 +484,8 @@ export const downloadContentFromMessage = async ({
|
|
|
456
484
|
* Decrypts and downloads an AES256-CBC encrypted file given the keys.
|
|
457
485
|
* Assumes the SHA256 of the plaintext is appended to the end of the ciphertext
|
|
458
486
|
* */
|
|
459
|
-
|
|
487
|
+
exports.downloadContentFromMessage = downloadContentFromMessage;
|
|
488
|
+
const downloadEncryptedContent = async (downloadUrl, {
|
|
460
489
|
cipherKey,
|
|
461
490
|
iv
|
|
462
491
|
}, {
|
|
@@ -479,7 +508,7 @@ export const downloadEncryptedContent = async (downloadUrl, {
|
|
|
479
508
|
const endChunk = endByte ? toSmallestChunkSize(endByte || 0) + AES_CHUNK_SIZE : undefined;
|
|
480
509
|
const headers = {
|
|
481
510
|
...(options?.headers || {}),
|
|
482
|
-
Origin: DEFAULT_ORIGIN
|
|
511
|
+
Origin: _index2.DEFAULT_ORIGIN
|
|
483
512
|
};
|
|
484
513
|
if (startChunk || endChunk) {
|
|
485
514
|
headers.Range = `bytes=${startChunk}-`;
|
|
@@ -506,7 +535,7 @@ export const downloadEncryptedContent = async (downloadUrl, {
|
|
|
506
535
|
push(bytes);
|
|
507
536
|
}
|
|
508
537
|
};
|
|
509
|
-
const output = new Transform({
|
|
538
|
+
const output = new _stream.Transform({
|
|
510
539
|
transform(chunk, _, callback) {
|
|
511
540
|
let data = Buffer.concat([remainingBytes, chunk]);
|
|
512
541
|
const decryptLength = toSmallestChunkSize(data.length);
|
|
@@ -545,7 +574,8 @@ export const downloadEncryptedContent = async (downloadUrl, {
|
|
|
545
574
|
end: true
|
|
546
575
|
});
|
|
547
576
|
};
|
|
548
|
-
|
|
577
|
+
exports.downloadEncryptedContent = downloadEncryptedContent;
|
|
578
|
+
function extensionForMediaMessage(message) {
|
|
549
579
|
const getExtension = mimetype => mimetype.split(';')[0]?.split('/')[1];
|
|
550
580
|
const type = Object.keys(message)[0];
|
|
551
581
|
let extension;
|
|
@@ -557,7 +587,7 @@ export function extensionForMediaMessage(message) {
|
|
|
557
587
|
}
|
|
558
588
|
return extension;
|
|
559
589
|
}
|
|
560
|
-
|
|
590
|
+
const getWAUploadToServer = ({
|
|
561
591
|
customUploadHosts,
|
|
562
592
|
fetchAgent,
|
|
563
593
|
logger,
|
|
@@ -578,17 +608,17 @@ export const getWAUploadToServer = ({
|
|
|
578
608
|
} of hosts) {
|
|
579
609
|
logger.debug(`uploading to "${hostname}"`);
|
|
580
610
|
const auth = encodeURIComponent(uploadInfo.auth); // the auth token
|
|
581
|
-
const url = `https://${hostname}${MEDIA_PATH_MAP[mediaType]}/${fileEncSha256B64}?auth=${auth}&token=${fileEncSha256B64}`;
|
|
611
|
+
const url = `https://${hostname}${_index2.MEDIA_PATH_MAP[mediaType]}/${fileEncSha256B64}?auth=${auth}&token=${fileEncSha256B64}`;
|
|
582
612
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
583
613
|
let result;
|
|
584
614
|
try {
|
|
585
|
-
const body = await
|
|
615
|
+
const body = await _axios.default.post(url, (0, _fs.createReadStream)(filePath), {
|
|
586
616
|
...options,
|
|
587
617
|
maxRedirects: 0,
|
|
588
618
|
headers: {
|
|
589
619
|
...(options.headers || {}),
|
|
590
620
|
'Content-Type': 'application/octet-stream',
|
|
591
|
-
Origin: DEFAULT_ORIGIN
|
|
621
|
+
Origin: _index2.DEFAULT_ORIGIN
|
|
592
622
|
},
|
|
593
623
|
httpsAgent: fetchAgent,
|
|
594
624
|
timeout: timeoutMs,
|
|
@@ -611,7 +641,7 @@ export const getWAUploadToServer = ({
|
|
|
611
641
|
throw new Error(`upload failed, reason: ${JSON.stringify(result)}`);
|
|
612
642
|
}
|
|
613
643
|
} catch (error) {
|
|
614
|
-
if (
|
|
644
|
+
if (_axios.default.isAxiosError(error)) {
|
|
615
645
|
result = error.response?.data;
|
|
616
646
|
}
|
|
617
647
|
const isLast = hostname === hosts[uploadInfo.hosts.length - 1]?.hostname;
|
|
@@ -622,34 +652,35 @@ export const getWAUploadToServer = ({
|
|
|
622
652
|
}
|
|
623
653
|
}
|
|
624
654
|
if (!urls) {
|
|
625
|
-
throw new Boom('Media upload failed on all hosts', {
|
|
655
|
+
throw new _boom.Boom('Media upload failed on all hosts', {
|
|
626
656
|
statusCode: 500
|
|
627
657
|
});
|
|
628
658
|
}
|
|
629
659
|
return urls;
|
|
630
660
|
};
|
|
631
661
|
};
|
|
662
|
+
exports.getWAUploadToServer = getWAUploadToServer;
|
|
632
663
|
const getMediaRetryKey = mediaKey => {
|
|
633
|
-
return hkdf(mediaKey, 32, {
|
|
664
|
+
return (0, _crypto2.hkdf)(mediaKey, 32, {
|
|
634
665
|
info: 'WhatsApp Media Retry Notification'
|
|
635
666
|
});
|
|
636
667
|
};
|
|
637
668
|
/**
|
|
638
669
|
* Generate a binary node that will request the phone to re-upload the media & return the newly uploaded URL
|
|
639
670
|
*/
|
|
640
|
-
|
|
671
|
+
const encryptMediaRetryRequest = async (key, mediaKey, meId) => {
|
|
641
672
|
const recp = {
|
|
642
673
|
stanzaId: key.id
|
|
643
674
|
};
|
|
644
|
-
const recpBuffer = proto.ServerErrorReceipt.encode(recp).finish();
|
|
675
|
+
const recpBuffer = _index.proto.ServerErrorReceipt.encode(recp).finish();
|
|
645
676
|
const iv = Crypto.randomBytes(12);
|
|
646
677
|
const retryKey = await getMediaRetryKey(mediaKey);
|
|
647
|
-
const ciphertext = aesEncryptGCM(recpBuffer, retryKey, iv, Buffer.from(key.id));
|
|
678
|
+
const ciphertext = (0, _crypto2.aesEncryptGCM)(recpBuffer, retryKey, iv, Buffer.from(key.id));
|
|
648
679
|
const req = {
|
|
649
680
|
tag: 'receipt',
|
|
650
681
|
attrs: {
|
|
651
682
|
id: key.id,
|
|
652
|
-
to: jidNormalizedUser(meId),
|
|
683
|
+
to: (0, _index3.jidNormalizedUser)(meId),
|
|
653
684
|
type: 'server-error'
|
|
654
685
|
},
|
|
655
686
|
content: [
|
|
@@ -680,8 +711,9 @@ export const encryptMediaRetryRequest = async (key, mediaKey, meId) => {
|
|
|
680
711
|
};
|
|
681
712
|
return req;
|
|
682
713
|
};
|
|
683
|
-
|
|
684
|
-
|
|
714
|
+
exports.encryptMediaRetryRequest = encryptMediaRetryRequest;
|
|
715
|
+
const decodeMediaRetryNode = node => {
|
|
716
|
+
const rmrNode = (0, _index3.getBinaryNodeChild)(node, 'rmr');
|
|
685
717
|
const event = {
|
|
686
718
|
key: {
|
|
687
719
|
id: node.attrs.id,
|
|
@@ -690,43 +722,46 @@ export const decodeMediaRetryNode = node => {
|
|
|
690
722
|
participant: rmrNode.attrs.participant
|
|
691
723
|
}
|
|
692
724
|
};
|
|
693
|
-
const errorNode = getBinaryNodeChild(node, 'error');
|
|
725
|
+
const errorNode = (0, _index3.getBinaryNodeChild)(node, 'error');
|
|
694
726
|
if (errorNode) {
|
|
695
727
|
const errorCode = +errorNode.attrs.code;
|
|
696
|
-
event.error = new Boom(`Failed to re-upload media (${errorCode})`, {
|
|
728
|
+
event.error = new _boom.Boom(`Failed to re-upload media (${errorCode})`, {
|
|
697
729
|
data: errorNode.attrs,
|
|
698
730
|
statusCode: getStatusCodeForMediaRetry(errorCode)
|
|
699
731
|
});
|
|
700
732
|
} else {
|
|
701
|
-
const encryptedInfoNode = getBinaryNodeChild(node, 'encrypt');
|
|
702
|
-
const ciphertext = getBinaryNodeChildBuffer(encryptedInfoNode, 'enc_p');
|
|
703
|
-
const iv = getBinaryNodeChildBuffer(encryptedInfoNode, 'enc_iv');
|
|
733
|
+
const encryptedInfoNode = (0, _index3.getBinaryNodeChild)(node, 'encrypt');
|
|
734
|
+
const ciphertext = (0, _index3.getBinaryNodeChildBuffer)(encryptedInfoNode, 'enc_p');
|
|
735
|
+
const iv = (0, _index3.getBinaryNodeChildBuffer)(encryptedInfoNode, 'enc_iv');
|
|
704
736
|
if (ciphertext && iv) {
|
|
705
737
|
event.media = {
|
|
706
738
|
ciphertext,
|
|
707
739
|
iv
|
|
708
740
|
};
|
|
709
741
|
} else {
|
|
710
|
-
event.error = new Boom('Failed to re-upload media (missing ciphertext)', {
|
|
742
|
+
event.error = new _boom.Boom('Failed to re-upload media (missing ciphertext)', {
|
|
711
743
|
statusCode: 404
|
|
712
744
|
});
|
|
713
745
|
}
|
|
714
746
|
}
|
|
715
747
|
return event;
|
|
716
748
|
};
|
|
717
|
-
|
|
749
|
+
exports.decodeMediaRetryNode = decodeMediaRetryNode;
|
|
750
|
+
const decryptMediaRetryData = async ({
|
|
718
751
|
ciphertext,
|
|
719
752
|
iv
|
|
720
753
|
}, mediaKey, msgId) => {
|
|
721
754
|
const retryKey = await getMediaRetryKey(mediaKey);
|
|
722
|
-
const plaintext = aesDecryptGCM(ciphertext, retryKey, iv, Buffer.from(msgId));
|
|
723
|
-
return proto.MediaRetryNotification.decode(plaintext);
|
|
755
|
+
const plaintext = (0, _crypto2.aesDecryptGCM)(ciphertext, retryKey, iv, Buffer.from(msgId));
|
|
756
|
+
return _index.proto.MediaRetryNotification.decode(plaintext);
|
|
724
757
|
};
|
|
725
|
-
|
|
758
|
+
exports.decryptMediaRetryData = decryptMediaRetryData;
|
|
759
|
+
const getStatusCodeForMediaRetry = code => MEDIA_RETRY_STATUS_MAP[code];
|
|
760
|
+
exports.getStatusCodeForMediaRetry = getStatusCodeForMediaRetry;
|
|
726
761
|
const MEDIA_RETRY_STATUS_MAP = {
|
|
727
|
-
[proto.MediaRetryNotification.ResultType.SUCCESS]: 200,
|
|
728
|
-
[proto.MediaRetryNotification.ResultType.DECRYPTION_ERROR]: 412,
|
|
729
|
-
[proto.MediaRetryNotification.ResultType.NOT_FOUND]: 404,
|
|
730
|
-
[proto.MediaRetryNotification.ResultType.GENERAL_ERROR]: 418
|
|
762
|
+
[_index.proto.MediaRetryNotification.ResultType.SUCCESS]: 200,
|
|
763
|
+
[_index.proto.MediaRetryNotification.ResultType.DECRYPTION_ERROR]: 412,
|
|
764
|
+
[_index.proto.MediaRetryNotification.ResultType.NOT_FOUND]: 404,
|
|
765
|
+
[_index.proto.MediaRetryNotification.ResultType.GENERAL_ERROR]: 418
|
|
731
766
|
};
|
|
732
767
|
//# sourceMappingURL=messages-media.js.map
|