@d0v3riz/baileys 6.7.21 → 6.7.22
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/WAProto/GenerateStatics.sh +2 -3
- package/WAProto/index.js +4138 -4136
- package/lib/Defaults/index.d.ts +2 -3
- package/lib/Defaults/index.js +40 -36
- package/lib/Signal/Group/ciphertext-message.d.ts +0 -1
- package/lib/Signal/Group/ciphertext-message.js +5 -2
- package/lib/Signal/Group/group-session-builder.d.ts +3 -4
- package/lib/Signal/Group/group-session-builder.js +41 -7
- package/lib/Signal/Group/group_cipher.d.ts +2 -3
- package/lib/Signal/Group/group_cipher.js +16 -14
- package/lib/Signal/Group/index.d.ts +11 -12
- package/lib/Signal/Group/index.js +57 -12
- package/lib/Signal/Group/keyhelper.d.ts +1 -2
- package/lib/Signal/Group/keyhelper.js +44 -8
- package/lib/Signal/Group/queue-job.d.ts +0 -2
- package/lib/Signal/Group/queue-job.js +5 -5
- package/lib/Signal/Group/sender-chain-key.d.ts +1 -2
- package/lib/Signal/Group/sender-chain-key.js +9 -7
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +1 -2
- package/lib/Signal/Group/sender-key-distribution-message.js +9 -6
- package/lib/Signal/Group/sender-key-message.d.ts +1 -2
- package/lib/Signal/Group/sender-key-message.js +12 -10
- package/lib/Signal/Group/sender-key-name.d.ts +0 -1
- package/lib/Signal/Group/sender-key-name.js +5 -2
- package/lib/Signal/Group/sender-key-record.d.ts +1 -2
- package/lib/Signal/Group/sender-key-record.js +12 -9
- package/lib/Signal/Group/sender-key-state.d.ts +2 -3
- package/lib/Signal/Group/sender-key-state.js +9 -6
- package/lib/Signal/Group/sender-message-key.d.ts +0 -1
- package/lib/Signal/Group/sender-message-key.js +7 -5
- package/lib/Signal/libsignal.d.ts +2 -3
- package/lib/Signal/libsignal.js +55 -22
- package/lib/Socket/Client/index.d.ts +2 -3
- package/lib/Socket/Client/index.js +18 -3
- package/lib/Socket/Client/types.d.ts +1 -2
- package/lib/Socket/Client/types.js +6 -4
- package/lib/Socket/Client/websocket.d.ts +1 -2
- package/lib/Socket/Client/websocket.js +26 -14
- package/lib/Socket/business.d.ts +64 -66
- package/lib/Socket/business.js +37 -32
- package/lib/Socket/chats.d.ts +19 -21
- package/lib/Socket/chats.js +141 -176
- package/lib/Socket/groups.d.ts +35 -37
- package/lib/Socket/groups.js +63 -56
- package/lib/Socket/index.d.ts +70 -102
- package/lib/Socket/index.js +9 -16
- package/lib/Socket/messages-recv.d.ts +49 -51
- package/lib/Socket/messages-recv.js +173 -180
- package/lib/Socket/messages-send.d.ts +46 -48
- package/lib/Socket/messages-send.js +84 -75
- package/lib/Socket/mex.d.ts +1 -2
- package/lib/Socket/mex.js +16 -12
- package/lib/Socket/newsletter.d.ts +44 -46
- package/lib/Socket/newsletter.js +27 -23
- package/lib/Socket/socket.d.ts +12 -13
- package/lib/Socket/socket.js +115 -135
- package/lib/Socket/usync.d.ts +14 -15
- package/lib/Socket/usync.js +11 -9
- package/lib/Types/Auth.d.ts +3 -4
- package/lib/Types/Auth.js +2 -2
- package/lib/Types/Call.d.ts +0 -1
- package/lib/Types/Call.js +2 -2
- package/lib/Types/Chat.d.ts +7 -10
- package/lib/Types/Chat.js +4 -2
- package/lib/Types/Contact.d.ts +0 -1
- package/lib/Types/Contact.js +2 -2
- package/lib/Types/Events.d.ts +10 -11
- package/lib/Types/Events.js +2 -2
- package/lib/Types/GroupMetadata.d.ts +2 -3
- package/lib/Types/GroupMetadata.js +2 -2
- package/lib/Types/Label.d.ts +0 -1
- package/lib/Types/Label.js +5 -3
- package/lib/Types/LabelAssociation.d.ts +0 -1
- package/lib/Types/LabelAssociation.js +5 -3
- package/lib/Types/Message.d.ts +7 -9
- package/lib/Types/Message.js +7 -7
- package/lib/Types/Newsletter.d.ts +0 -1
- package/lib/Types/Newsletter.js +7 -5
- package/lib/Types/Product.d.ts +1 -2
- package/lib/Types/Product.js +2 -2
- package/lib/Types/Signal.d.ts +1 -2
- package/lib/Types/Signal.js +2 -2
- package/lib/Types/Socket.d.ts +7 -8
- package/lib/Types/Socket.js +2 -3
- package/lib/Types/State.d.ts +2 -14
- package/lib/Types/State.js +2 -13
- package/lib/Types/USync.d.ts +2 -3
- package/lib/Types/USync.js +2 -2
- package/lib/Types/index.d.ts +14 -15
- package/lib/Types/index.js +31 -15
- package/lib/Utils/auth-utils.d.ts +2 -3
- package/lib/Utils/auth-utils.js +34 -25
- package/lib/Utils/baileys-event-stream.d.ts +1 -2
- package/lib/Utils/baileys-event-stream.js +22 -15
- package/lib/Utils/business.d.ts +2 -3
- package/lib/Utils/business.js +70 -61
- package/lib/Utils/chat-utils.d.ts +7 -8
- package/lib/Utils/chat-utils.js +137 -130
- package/lib/Utils/crypto.d.ts +1 -2
- package/lib/Utils/crypto.js +86 -37
- package/lib/Utils/decode-wa-message.d.ts +4 -5
- package/lib/Utils/decode-wa-message.js +44 -38
- package/lib/Utils/event-buffer.d.ts +4 -4
- package/lib/Utils/event-buffer.js +50 -37
- package/lib/Utils/generics.d.ts +8 -9
- package/lib/Utils/generics.js +114 -87
- package/lib/Utils/history.d.ts +3 -4
- package/lib/Utils/history.js +40 -32
- package/lib/Utils/index.d.ts +17 -18
- package/lib/Utils/index.js +33 -18
- package/lib/Utils/link-preview.d.ts +3 -4
- package/lib/Utils/link-preview.js +47 -10
- package/lib/Utils/logger.d.ts +6 -8
- package/lib/Utils/logger.js +7 -3
- package/lib/Utils/lt-hash.d.ts +8 -9
- package/lib/Utils/lt-hash.js +26 -23
- package/lib/Utils/make-mutex.d.ts +0 -1
- package/lib/Utils/make-mutex.js +9 -5
- package/lib/Utils/messages-media.d.ts +10 -11
- package/lib/Utils/messages-media.js +203 -141
- package/lib/Utils/messages.d.ts +6 -7
- package/lib/Utils/messages.js +199 -190
- package/lib/Utils/noise-handler.d.ts +4 -5
- package/lib/Utils/noise-handler.js +26 -22
- package/lib/Utils/process-message.d.ts +4 -5
- package/lib/Utils/process-message.js +104 -95
- package/lib/Utils/signal.d.ts +4 -5
- package/lib/Utils/signal.js +52 -47
- package/lib/Utils/use-multi-file-auth-state.d.ts +1 -2
- package/lib/Utils/use-multi-file-auth-state.js +26 -23
- package/lib/Utils/validate-connection.d.ts +3 -4
- package/lib/Utils/validate-connection.js +58 -52
- package/lib/WABinary/constants.d.ts +0 -1
- package/lib/WABinary/constants.js +11 -9
- package/lib/WABinary/decode.d.ts +1 -2
- package/lib/WABinary/decode.js +51 -13
- package/lib/WABinary/encode.d.ts +1 -2
- package/lib/WABinary/encode.js +41 -5
- package/lib/WABinary/generic-utils.d.ts +3 -4
- package/lib/WABinary/generic-utils.js +38 -30
- package/lib/WABinary/index.d.ts +5 -6
- package/lib/WABinary/index.js +21 -6
- package/lib/WABinary/jid-utils.d.ts +0 -1
- package/lib/WABinary/jid-utils.js +35 -21
- package/lib/WABinary/types.d.ts +1 -2
- package/lib/WABinary/types.js +2 -2
- package/lib/WAM/BinaryInfo.d.ts +1 -2
- package/lib/WAM/BinaryInfo.js +5 -2
- package/lib/WAM/constants.d.ts +0 -1
- package/lib/WAM/constants.js +6 -4
- package/lib/WAM/encode.d.ts +1 -2
- package/lib/WAM/encode.js +14 -12
- package/lib/WAM/index.d.ts +3 -4
- package/lib/WAM/index.js +19 -4
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +3 -4
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +9 -6
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +2 -3
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +12 -9
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +2 -3
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +9 -6
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +2 -3
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +11 -7
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +3 -4
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +21 -19
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +2 -3
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +5 -2
- package/lib/WAUSync/Protocols/index.d.ts +4 -5
- package/lib/WAUSync/Protocols/index.js +20 -5
- package/lib/WAUSync/USyncQuery.d.ts +3 -4
- package/lib/WAUSync/USyncQuery.js +20 -18
- package/lib/WAUSync/USyncUser.d.ts +5 -6
- package/lib/WAUSync/USyncUser.js +5 -2
- package/lib/WAUSync/index.d.ts +3 -4
- package/lib/WAUSync/index.js +19 -4
- package/lib/index.d.ts +8 -9
- package/lib/index.js +30 -11
- package/package.json +26 -26
- package/WAProto/fix-imports.js +0 -29
- 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.map +0 -1
- package/lib/Signal/Group/ciphertext-message.js.map +0 -1
- 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.map +0 -1
- package/lib/Signal/Group/group_cipher.js.map +0 -1
- 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.map +0 -1
- package/lib/Signal/Group/keyhelper.js.map +0 -1
- package/lib/Signal/Group/queue-job.d.ts.map +0 -1
- package/lib/Signal/Group/queue-job.js.map +0 -1
- 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.map +0 -1
- package/lib/Signal/Group/sender-key-distribution-message.js.map +0 -1
- 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.map +0 -1
- package/lib/Signal/Group/sender-key-name.js.map +0 -1
- 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.map +0 -1
- package/lib/Signal/Group/sender-key-state.js.map +0 -1
- 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.map +0 -1
- package/lib/Signal/libsignal.js.map +0 -1
- 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.map +0 -1
- package/lib/Socket/Client/types.js.map +0 -1
- 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.map +0 -1
- package/lib/Socket/business.js.map +0 -1
- package/lib/Socket/chats.d.ts.map +0 -1
- package/lib/Socket/chats.js.map +0 -1
- package/lib/Socket/communities.d.ts +0 -219
- package/lib/Socket/communities.d.ts.map +0 -1
- package/lib/Socket/communities.js +0 -351
- package/lib/Socket/communities.js.map +0 -1
- package/lib/Socket/groups.d.ts.map +0 -1
- package/lib/Socket/groups.js.map +0 -1
- package/lib/Socket/index.d.ts.map +0 -1
- package/lib/Socket/index.js.map +0 -1
- 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.map +0 -1
- package/lib/Socket/messages-send.js.map +0 -1
- package/lib/Socket/mex.d.ts.map +0 -1
- package/lib/Socket/mex.js.map +0 -1
- package/lib/Socket/newsletter.d.ts.map +0 -1
- package/lib/Socket/newsletter.js.map +0 -1
- package/lib/Socket/socket.d.ts.map +0 -1
- package/lib/Socket/socket.js.map +0 -1
- package/lib/Socket/usync.d.ts.map +0 -1
- package/lib/Socket/usync.js.map +0 -1
- package/lib/Types/Auth.d.ts.map +0 -1
- package/lib/Types/Auth.js.map +0 -1
- package/lib/Types/Call.d.ts.map +0 -1
- package/lib/Types/Call.js.map +0 -1
- package/lib/Types/Chat.d.ts.map +0 -1
- package/lib/Types/Chat.js.map +0 -1
- package/lib/Types/Contact.d.ts.map +0 -1
- package/lib/Types/Contact.js.map +0 -1
- package/lib/Types/Events.d.ts.map +0 -1
- package/lib/Types/Events.js.map +0 -1
- package/lib/Types/GroupMetadata.d.ts.map +0 -1
- package/lib/Types/GroupMetadata.js.map +0 -1
- package/lib/Types/Label.d.ts.map +0 -1
- package/lib/Types/Label.js.map +0 -1
- package/lib/Types/LabelAssociation.d.ts.map +0 -1
- package/lib/Types/LabelAssociation.js.map +0 -1
- package/lib/Types/Message.d.ts.map +0 -1
- package/lib/Types/Message.js.map +0 -1
- package/lib/Types/Newsletter.d.ts.map +0 -1
- package/lib/Types/Newsletter.js.map +0 -1
- package/lib/Types/Product.d.ts.map +0 -1
- package/lib/Types/Product.js.map +0 -1
- package/lib/Types/Signal.d.ts.map +0 -1
- package/lib/Types/Signal.js.map +0 -1
- package/lib/Types/Socket.d.ts.map +0 -1
- package/lib/Types/Socket.js.map +0 -1
- package/lib/Types/State.d.ts.map +0 -1
- package/lib/Types/State.js.map +0 -1
- package/lib/Types/USync.d.ts.map +0 -1
- package/lib/Types/USync.js.map +0 -1
- package/lib/Types/index.d.ts.map +0 -1
- package/lib/Types/index.js.map +0 -1
- 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.map +0 -1
- package/lib/Utils/baileys-event-stream.js.map +0 -1
- package/lib/Utils/business.d.ts.map +0 -1
- package/lib/Utils/business.js.map +0 -1
- 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.map +0 -1
- package/lib/Utils/crypto.js.map +0 -1
- 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.map +0 -1
- package/lib/Utils/event-buffer.js.map +0 -1
- package/lib/Utils/generics.d.ts.map +0 -1
- package/lib/Utils/generics.js.map +0 -1
- package/lib/Utils/history.d.ts.map +0 -1
- package/lib/Utils/history.js.map +0 -1
- package/lib/Utils/index.d.ts.map +0 -1
- package/lib/Utils/index.js.map +0 -1
- 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.map +0 -1
- package/lib/Utils/logger.js.map +0 -1
- 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.map +0 -1
- package/lib/Utils/make-mutex.js.map +0 -1
- 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.map +0 -1
- package/lib/Utils/messages.js.map +0 -1
- 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.map +0 -1
- package/lib/Utils/process-message.js.map +0 -1
- 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.map +0 -1
- package/lib/Utils/use-multi-file-auth-state.js.map +0 -1
- 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.map +0 -1
- package/lib/WABinary/constants.js.map +0 -1
- package/lib/WABinary/decode.d.ts.map +0 -1
- package/lib/WABinary/decode.js.map +0 -1
- package/lib/WABinary/encode.d.ts.map +0 -1
- package/lib/WABinary/encode.js.map +0 -1
- 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.map +0 -1
- package/lib/WABinary/index.js.map +0 -1
- 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.map +0 -1
- package/lib/WABinary/types.js.map +0 -1
- package/lib/WAM/BinaryInfo.d.ts.map +0 -1
- package/lib/WAM/BinaryInfo.js.map +0 -1
- package/lib/WAM/constants.d.ts.map +0 -1
- package/lib/WAM/constants.js.map +0 -1
- package/lib/WAM/encode.d.ts.map +0 -1
- package/lib/WAM/encode.js.map +0 -1
- package/lib/WAM/index.d.ts.map +0 -1
- package/lib/WAM/index.js.map +0 -1
- 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.map +0 -1
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +0 -1
- 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.map +0 -1
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +0 -1
- 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.map +0 -1
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +0 -1
- 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.map +0 -1
- package/lib/WAUSync/USyncQuery.js.map +0 -1
- package/lib/WAUSync/USyncUser.d.ts.map +0 -1
- package/lib/WAUSync/USyncUser.js.map +0 -1
- package/lib/WAUSync/index.d.ts.map +0 -1
- package/lib/WAUSync/index.js.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
|
@@ -1,54 +1,97 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.getStatusCodeForMediaRetry = exports.decryptMediaRetryData = exports.decodeMediaRetryNode = exports.encryptMediaRetryRequest = exports.getWAUploadToServer = exports.downloadEncryptedContent = exports.downloadContentFromMessage = exports.getUrlFromDirectPath = exports.encryptedStream = exports.getHttpStream = exports.getStream = exports.toBuffer = exports.toReadable = exports.mediaMessageSHA256B64 = exports.generateProfilePicture = exports.encodeBase64EncodedStringForUpload = exports.extractImageThumb = exports.getRawMediaUploadData = exports.hkdfInfoKey = void 0;
|
|
40
|
+
exports.getMediaKeys = getMediaKeys;
|
|
41
|
+
exports.getAudioDuration = getAudioDuration;
|
|
42
|
+
exports.getAudioWaveform = getAudioWaveform;
|
|
43
|
+
exports.generateThumbnail = generateThumbnail;
|
|
44
|
+
exports.extensionForMediaMessage = extensionForMediaMessage;
|
|
45
|
+
const boom_1 = require("@hapi/boom");
|
|
46
|
+
const axios_1 = __importDefault(require("axios"));
|
|
47
|
+
const child_process_1 = require("child_process");
|
|
48
|
+
const Crypto = __importStar(require("crypto"));
|
|
49
|
+
const events_1 = require("events");
|
|
50
|
+
const fs_1 = require("fs");
|
|
51
|
+
const os_1 = require("os");
|
|
52
|
+
const path_1 = require("path");
|
|
53
|
+
const stream_1 = require("stream");
|
|
54
|
+
const WAProto_1 = require("../../WAProto");
|
|
55
|
+
const Defaults_1 = require("../Defaults");
|
|
56
|
+
const WABinary_1 = require("../WABinary");
|
|
57
|
+
const crypto_1 = require("./crypto");
|
|
58
|
+
const generics_1 = require("./generics");
|
|
59
|
+
const getTmpFilesDirectory = () => (0, os_1.tmpdir)();
|
|
17
60
|
const getImageProcessingLibrary = async () => {
|
|
18
|
-
|
|
19
|
-
const [jimp, sharp] = await Promise.all([import('jimp').catch(() => { }), import('sharp').catch(() => { })]);
|
|
61
|
+
const [jimp, sharp] = await Promise.all([Promise.resolve().then(() => __importStar(require('jimp'))).catch(() => { }), Promise.resolve().then(() => __importStar(require('sharp'))).catch(() => { })]);
|
|
20
62
|
if (sharp) {
|
|
21
63
|
return { sharp };
|
|
22
64
|
}
|
|
23
65
|
if (jimp) {
|
|
24
66
|
return { jimp };
|
|
25
67
|
}
|
|
26
|
-
throw new Boom('No image processing library available');
|
|
68
|
+
throw new boom_1.Boom('No image processing library available');
|
|
27
69
|
};
|
|
28
|
-
|
|
29
|
-
const hkdfInfo = MEDIA_HKDF_KEY_MAPPING[type];
|
|
70
|
+
const hkdfInfoKey = (type) => {
|
|
71
|
+
const hkdfInfo = Defaults_1.MEDIA_HKDF_KEY_MAPPING[type];
|
|
30
72
|
return `WhatsApp ${hkdfInfo} Keys`;
|
|
31
73
|
};
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
74
|
+
exports.hkdfInfoKey = hkdfInfoKey;
|
|
75
|
+
const getRawMediaUploadData = async (media, mediaType, logger) => {
|
|
76
|
+
const { stream } = await (0, exports.getStream)(media);
|
|
77
|
+
logger === null || logger === void 0 ? void 0 : logger.debug('got stream for raw upload');
|
|
35
78
|
const hasher = Crypto.createHash('sha256');
|
|
36
|
-
const filePath = join(tmpdir(), mediaType + generateMessageIDV2());
|
|
37
|
-
const fileWriteStream = createWriteStream(filePath);
|
|
79
|
+
const filePath = (0, path_1.join)((0, os_1.tmpdir)(), mediaType + (0, generics_1.generateMessageIDV2)());
|
|
80
|
+
const fileWriteStream = (0, fs_1.createWriteStream)(filePath);
|
|
38
81
|
let fileLength = 0;
|
|
39
82
|
try {
|
|
40
83
|
for await (const data of stream) {
|
|
41
84
|
fileLength += data.length;
|
|
42
85
|
hasher.update(data);
|
|
43
86
|
if (!fileWriteStream.write(data)) {
|
|
44
|
-
await once(fileWriteStream, 'drain');
|
|
87
|
+
await (0, events_1.once)(fileWriteStream, 'drain');
|
|
45
88
|
}
|
|
46
89
|
}
|
|
47
90
|
fileWriteStream.end();
|
|
48
|
-
await once(fileWriteStream, 'finish');
|
|
91
|
+
await (0, events_1.once)(fileWriteStream, 'finish');
|
|
49
92
|
stream.destroy();
|
|
50
93
|
const fileSha256 = hasher.digest();
|
|
51
|
-
logger
|
|
94
|
+
logger === null || logger === void 0 ? void 0 : logger.debug('hashed data for raw upload');
|
|
52
95
|
return {
|
|
53
96
|
filePath: filePath,
|
|
54
97
|
fileSha256,
|
|
@@ -59,24 +102,25 @@ export const getRawMediaUploadData = async (media, mediaType, logger) => {
|
|
|
59
102
|
fileWriteStream.destroy();
|
|
60
103
|
stream.destroy();
|
|
61
104
|
try {
|
|
62
|
-
await
|
|
105
|
+
await fs_1.promises.unlink(filePath);
|
|
63
106
|
}
|
|
64
|
-
catch {
|
|
107
|
+
catch (_a) {
|
|
65
108
|
//
|
|
66
109
|
}
|
|
67
110
|
throw error;
|
|
68
111
|
}
|
|
69
112
|
};
|
|
113
|
+
exports.getRawMediaUploadData = getRawMediaUploadData;
|
|
70
114
|
/** generates all the keys required to encrypt/decrypt & sign a media message */
|
|
71
|
-
|
|
115
|
+
async function getMediaKeys(buffer, mediaType) {
|
|
72
116
|
if (!buffer) {
|
|
73
|
-
throw new Boom('Cannot derive from empty media key');
|
|
117
|
+
throw new boom_1.Boom('Cannot derive from empty media key');
|
|
74
118
|
}
|
|
75
119
|
if (typeof buffer === 'string') {
|
|
76
120
|
buffer = Buffer.from(buffer.replace('data:;base64,', ''), 'base64');
|
|
77
121
|
}
|
|
78
122
|
// expand using HKDF to 112 bytes, also pass in the relevant app info
|
|
79
|
-
const expandedMediaKey = await hkdf(buffer, 112, { info: hkdfInfoKey(mediaType) });
|
|
123
|
+
const expandedMediaKey = await (0, crypto_1.hkdf)(buffer, 112, { info: (0, exports.hkdfInfoKey)(mediaType) });
|
|
80
124
|
return {
|
|
81
125
|
iv: expandedMediaKey.slice(0, 16),
|
|
82
126
|
cipherKey: expandedMediaKey.slice(16, 48),
|
|
@@ -86,7 +130,7 @@ export async function getMediaKeys(buffer, mediaType) {
|
|
|
86
130
|
/** Extracts video thumb using FFMPEG */
|
|
87
131
|
const extractVideoThumb = async (path, destPath, time, size) => new Promise((resolve, reject) => {
|
|
88
132
|
const cmd = `ffmpeg -ss ${time} -i ${path} -y -vf scale=${size.width}:-1 -vframes 1 -f image2 ${destPath}`;
|
|
89
|
-
exec(cmd, err => {
|
|
133
|
+
(0, child_process_1.exec)(cmd, err => {
|
|
90
134
|
if (err) {
|
|
91
135
|
reject(err);
|
|
92
136
|
}
|
|
@@ -95,14 +139,13 @@ const extractVideoThumb = async (path, destPath, time, size) => new Promise((res
|
|
|
95
139
|
}
|
|
96
140
|
});
|
|
97
141
|
});
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
bufferOrFilePath = await toBuffer(bufferOrFilePath);
|
|
142
|
+
const extractImageThumb = async (bufferOrFilePath, width = 32) => {
|
|
143
|
+
var _a, _b;
|
|
144
|
+
if (bufferOrFilePath instanceof stream_1.Readable) {
|
|
145
|
+
bufferOrFilePath = await (0, exports.toBuffer)(bufferOrFilePath);
|
|
103
146
|
}
|
|
104
147
|
const lib = await getImageProcessingLibrary();
|
|
105
|
-
if ('sharp' in lib && typeof lib.sharp
|
|
148
|
+
if ('sharp' in lib && typeof ((_a = lib.sharp) === null || _a === void 0 ? void 0 : _a.default) === 'function') {
|
|
106
149
|
const img = lib.sharp.default(bufferOrFilePath);
|
|
107
150
|
const dimensions = await img.metadata();
|
|
108
151
|
const buffer = await img.resize(width).jpeg({ quality: 50 }).toBuffer();
|
|
@@ -114,8 +157,8 @@ export const extractImageThumb = async (bufferOrFilePath, width = 32) => {
|
|
|
114
157
|
}
|
|
115
158
|
};
|
|
116
159
|
}
|
|
117
|
-
else if ('jimp' in lib && typeof lib.jimp
|
|
118
|
-
const jimp = await lib.jimp.Jimp.read(bufferOrFilePath);
|
|
160
|
+
else if ('jimp' in lib && typeof ((_b = lib.jimp) === null || _b === void 0 ? void 0 : _b.Jimp) === 'object') {
|
|
161
|
+
const jimp = await lib.jimp.default.Jimp.read(bufferOrFilePath);
|
|
119
162
|
const dimensions = {
|
|
120
163
|
width: jimp.width,
|
|
121
164
|
height: jimp.height
|
|
@@ -129,11 +172,14 @@ export const extractImageThumb = async (bufferOrFilePath, width = 32) => {
|
|
|
129
172
|
};
|
|
130
173
|
}
|
|
131
174
|
else {
|
|
132
|
-
throw new Boom('No image processing library available');
|
|
175
|
+
throw new boom_1.Boom('No image processing library available');
|
|
133
176
|
}
|
|
134
177
|
};
|
|
135
|
-
|
|
136
|
-
|
|
178
|
+
exports.extractImageThumb = extractImageThumb;
|
|
179
|
+
const encodeBase64EncodedStringForUpload = (b64) => encodeURIComponent(b64.replace(/\+/g, '-').replace(/\//g, '_').replace(/\=+$/, ''));
|
|
180
|
+
exports.encodeBase64EncodedStringForUpload = encodeBase64EncodedStringForUpload;
|
|
181
|
+
const generateProfilePicture = async (mediaUpload, dimensions) => {
|
|
182
|
+
var _a, _b;
|
|
137
183
|
let buffer;
|
|
138
184
|
const { width: w = 640, height: h = 640 } = dimensions || {};
|
|
139
185
|
if (Buffer.isBuffer(mediaUpload)) {
|
|
@@ -141,13 +187,13 @@ export const generateProfilePicture = async (mediaUpload, dimensions) => {
|
|
|
141
187
|
}
|
|
142
188
|
else {
|
|
143
189
|
// Use getStream to handle all WAMediaUpload types (Buffer, Stream, URL)
|
|
144
|
-
const { stream } = await getStream(mediaUpload);
|
|
190
|
+
const { stream } = await (0, exports.getStream)(mediaUpload);
|
|
145
191
|
// Convert the resulting stream to a buffer
|
|
146
|
-
buffer = await toBuffer(stream);
|
|
192
|
+
buffer = await (0, exports.toBuffer)(stream);
|
|
147
193
|
}
|
|
148
194
|
const lib = await getImageProcessingLibrary();
|
|
149
195
|
let img;
|
|
150
|
-
if ('sharp' in lib && typeof lib.sharp
|
|
196
|
+
if ('sharp' in lib && typeof ((_a = lib.sharp) === null || _a === void 0 ? void 0 : _a.default) === 'function') {
|
|
151
197
|
img = lib.sharp
|
|
152
198
|
.default(buffer)
|
|
153
199
|
.resize(w, h)
|
|
@@ -156,26 +202,28 @@ export const generateProfilePicture = async (mediaUpload, dimensions) => {
|
|
|
156
202
|
})
|
|
157
203
|
.toBuffer();
|
|
158
204
|
}
|
|
159
|
-
else if ('jimp' in lib && typeof lib.jimp
|
|
160
|
-
const jimp = await lib.jimp.Jimp.read(buffer);
|
|
205
|
+
else if ('jimp' in lib && typeof ((_b = lib.jimp) === null || _b === void 0 ? void 0 : _b.Jimp) === 'object') {
|
|
206
|
+
const jimp = await lib.jimp.default.Jimp.read(buffer);
|
|
161
207
|
const min = Math.min(jimp.width, jimp.height);
|
|
162
208
|
const cropped = jimp.crop({ x: 0, y: 0, w: min, h: min });
|
|
163
209
|
img = cropped.resize({ w, h, mode: lib.jimp.ResizeStrategy.BILINEAR }).getBuffer('image/jpeg', { quality: 50 });
|
|
164
210
|
}
|
|
165
211
|
else {
|
|
166
|
-
throw new Boom('No image processing library available');
|
|
212
|
+
throw new boom_1.Boom('No image processing library available');
|
|
167
213
|
}
|
|
168
214
|
return {
|
|
169
215
|
img: await img
|
|
170
216
|
};
|
|
171
217
|
};
|
|
218
|
+
exports.generateProfilePicture = generateProfilePicture;
|
|
172
219
|
/** gets the SHA256 of the given media message */
|
|
173
|
-
|
|
220
|
+
const mediaMessageSHA256B64 = (message) => {
|
|
174
221
|
const media = Object.values(message)[0];
|
|
175
|
-
return media
|
|
222
|
+
return (media === null || media === void 0 ? void 0 : media.fileSha256) && Buffer.from(media.fileSha256).toString('base64');
|
|
176
223
|
};
|
|
177
|
-
|
|
178
|
-
|
|
224
|
+
exports.mediaMessageSHA256B64 = mediaMessageSHA256B64;
|
|
225
|
+
async function getAudioDuration(buffer) {
|
|
226
|
+
const musicMetadata = await Promise.resolve().then(() => __importStar(require('music-metadata')));
|
|
179
227
|
let metadata;
|
|
180
228
|
const options = {
|
|
181
229
|
duration: true
|
|
@@ -194,20 +242,19 @@ export async function getAudioDuration(buffer) {
|
|
|
194
242
|
/**
|
|
195
243
|
referenced from and modifying https://github.com/wppconnect-team/wa-js/blob/main/src/chat/functions/prepareAudioWaveform.ts
|
|
196
244
|
*/
|
|
197
|
-
|
|
245
|
+
async function getAudioWaveform(buffer, logger) {
|
|
198
246
|
try {
|
|
199
|
-
|
|
200
|
-
const { default: decoder } = await import('audio-decode');
|
|
247
|
+
const { default: decoder } = await eval("import('audio-decode')");
|
|
201
248
|
let audioData;
|
|
202
249
|
if (Buffer.isBuffer(buffer)) {
|
|
203
250
|
audioData = buffer;
|
|
204
251
|
}
|
|
205
252
|
else if (typeof buffer === 'string') {
|
|
206
|
-
const rStream = createReadStream(buffer);
|
|
207
|
-
audioData = await toBuffer(rStream);
|
|
253
|
+
const rStream = (0, fs_1.createReadStream)(buffer);
|
|
254
|
+
audioData = await (0, exports.toBuffer)(rStream);
|
|
208
255
|
}
|
|
209
256
|
else {
|
|
210
|
-
audioData = await toBuffer(buffer);
|
|
257
|
+
audioData = await (0, exports.toBuffer)(buffer);
|
|
211
258
|
}
|
|
212
259
|
const audioBuffer = await decoder(audioData);
|
|
213
260
|
const rawData = audioBuffer.getChannelData(0); // We only need to work with one channel of data
|
|
@@ -230,16 +277,17 @@ export async function getAudioWaveform(buffer, logger) {
|
|
|
230
277
|
return waveform;
|
|
231
278
|
}
|
|
232
279
|
catch (e) {
|
|
233
|
-
logger
|
|
280
|
+
logger === null || logger === void 0 ? void 0 : logger.debug('Failed to generate waveform: ' + e);
|
|
234
281
|
}
|
|
235
282
|
}
|
|
236
|
-
|
|
237
|
-
const readable = new Readable({ read: () => { } });
|
|
283
|
+
const toReadable = (buffer) => {
|
|
284
|
+
const readable = new stream_1.Readable({ read: () => { } });
|
|
238
285
|
readable.push(buffer);
|
|
239
286
|
readable.push(null);
|
|
240
287
|
return readable;
|
|
241
288
|
};
|
|
242
|
-
|
|
289
|
+
exports.toReadable = toReadable;
|
|
290
|
+
const toBuffer = async (stream) => {
|
|
243
291
|
const chunks = [];
|
|
244
292
|
for await (const chunk of stream) {
|
|
245
293
|
chunks.push(chunk);
|
|
@@ -247,9 +295,10 @@ export const toBuffer = async (stream) => {
|
|
|
247
295
|
stream.destroy();
|
|
248
296
|
return Buffer.concat(chunks);
|
|
249
297
|
};
|
|
250
|
-
|
|
298
|
+
exports.toBuffer = toBuffer;
|
|
299
|
+
const getStream = async (item, opts) => {
|
|
251
300
|
if (Buffer.isBuffer(item)) {
|
|
252
|
-
return { stream: toReadable(item), type: 'buffer' };
|
|
301
|
+
return { stream: (0, exports.toReadable)(item), type: 'buffer' };
|
|
253
302
|
}
|
|
254
303
|
if ('stream' in item) {
|
|
255
304
|
return { stream: item.stream, type: 'readable' };
|
|
@@ -257,19 +306,21 @@ export const getStream = async (item, opts) => {
|
|
|
257
306
|
const urlStr = item.url.toString();
|
|
258
307
|
if (urlStr.startsWith('data:')) {
|
|
259
308
|
const buffer = Buffer.from(urlStr.split(',')[1], 'base64');
|
|
260
|
-
return { stream: toReadable(buffer), type: 'buffer' };
|
|
309
|
+
return { stream: (0, exports.toReadable)(buffer), type: 'buffer' };
|
|
261
310
|
}
|
|
262
311
|
if (urlStr.startsWith('http://') || urlStr.startsWith('https://')) {
|
|
263
|
-
return { stream: await getHttpStream(item.url, opts), type: 'remote' };
|
|
312
|
+
return { stream: await (0, exports.getHttpStream)(item.url, opts), type: 'remote' };
|
|
264
313
|
}
|
|
265
|
-
return { stream: createReadStream(item.url), type: 'file' };
|
|
314
|
+
return { stream: (0, fs_1.createReadStream)(item.url), type: 'file' };
|
|
266
315
|
};
|
|
316
|
+
exports.getStream = getStream;
|
|
267
317
|
/** generates a thumbnail for a given media, if required */
|
|
268
|
-
|
|
318
|
+
async function generateThumbnail(file, mediaType, options) {
|
|
319
|
+
var _a;
|
|
269
320
|
let thumbnail;
|
|
270
321
|
let originalImageDimensions;
|
|
271
322
|
if (mediaType === 'image') {
|
|
272
|
-
const { buffer, original } = await extractImageThumb(file);
|
|
323
|
+
const { buffer, original } = await (0, exports.extractImageThumb)(file);
|
|
273
324
|
thumbnail = buffer.toString('base64');
|
|
274
325
|
if (original.width && original.height) {
|
|
275
326
|
originalImageDimensions = {
|
|
@@ -279,15 +330,15 @@ export async function generateThumbnail(file, mediaType, options) {
|
|
|
279
330
|
}
|
|
280
331
|
}
|
|
281
332
|
else if (mediaType === 'video') {
|
|
282
|
-
const imgFilename = join(getTmpFilesDirectory(), generateMessageIDV2() + '.jpg');
|
|
333
|
+
const imgFilename = (0, path_1.join)(getTmpFilesDirectory(), (0, generics_1.generateMessageIDV2)() + '.jpg');
|
|
283
334
|
try {
|
|
284
335
|
await extractVideoThumb(file, imgFilename, '00:00:00', { width: 32, height: 32 });
|
|
285
|
-
const buff = await
|
|
336
|
+
const buff = await fs_1.promises.readFile(imgFilename);
|
|
286
337
|
thumbnail = buff.toString('base64');
|
|
287
|
-
await
|
|
338
|
+
await fs_1.promises.unlink(imgFilename);
|
|
288
339
|
}
|
|
289
340
|
catch (err) {
|
|
290
|
-
options.logger
|
|
341
|
+
(_a = options.logger) === null || _a === void 0 ? void 0 : _a.debug('could not generate video thumb: ' + err);
|
|
291
342
|
}
|
|
292
343
|
}
|
|
293
344
|
return {
|
|
@@ -295,22 +346,24 @@ export async function generateThumbnail(file, mediaType, options) {
|
|
|
295
346
|
originalImageDimensions
|
|
296
347
|
};
|
|
297
348
|
}
|
|
298
|
-
|
|
299
|
-
const fetched = await
|
|
349
|
+
const getHttpStream = async (url, options = {}) => {
|
|
350
|
+
const fetched = await axios_1.default.get(url.toString(), { ...options, responseType: 'stream' });
|
|
300
351
|
return fetched.data;
|
|
301
352
|
};
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
353
|
+
exports.getHttpStream = getHttpStream;
|
|
354
|
+
const encryptedStream = async (media, mediaType, { logger, saveOriginalFileIfRequired, opts } = {}) => {
|
|
355
|
+
var _a, _b;
|
|
356
|
+
const { stream, type } = await (0, exports.getStream)(media, opts);
|
|
357
|
+
logger === null || logger === void 0 ? void 0 : logger.debug('fetched media stream');
|
|
305
358
|
const mediaKey = Crypto.randomBytes(32);
|
|
306
359
|
const { cipherKey, iv, macKey } = await getMediaKeys(mediaKey, mediaType);
|
|
307
|
-
const encFilePath = join(getTmpFilesDirectory(), mediaType + generateMessageIDV2() + '-enc');
|
|
308
|
-
const encFileWriteStream = createWriteStream(encFilePath);
|
|
360
|
+
const encFilePath = (0, path_1.join)(getTmpFilesDirectory(), mediaType + (0, generics_1.generateMessageIDV2)() + '-enc');
|
|
361
|
+
const encFileWriteStream = (0, fs_1.createWriteStream)(encFilePath);
|
|
309
362
|
let originalFileStream;
|
|
310
363
|
let originalFilePath;
|
|
311
364
|
if (saveOriginalFileIfRequired) {
|
|
312
|
-
originalFilePath = join(getTmpFilesDirectory(), mediaType + generateMessageIDV2() + '-original');
|
|
313
|
-
originalFileStream = createWriteStream(originalFilePath);
|
|
365
|
+
originalFilePath = (0, path_1.join)(getTmpFilesDirectory(), mediaType + (0, generics_1.generateMessageIDV2)() + '-original');
|
|
366
|
+
originalFileStream = (0, fs_1.createWriteStream)(originalFilePath);
|
|
314
367
|
}
|
|
315
368
|
let fileLength = 0;
|
|
316
369
|
const aes = Crypto.createCipheriv('aes-256-cbc', cipherKey, iv);
|
|
@@ -325,14 +378,14 @@ export const encryptedStream = async (media, mediaType, { logger, saveOriginalFi
|
|
|
325
378
|
try {
|
|
326
379
|
for await (const data of stream) {
|
|
327
380
|
fileLength += data.length;
|
|
328
|
-
if (type === 'remote' && opts
|
|
329
|
-
throw new Boom(`content length exceeded when encrypting "${type}"`, {
|
|
381
|
+
if (type === 'remote' && (opts === null || opts === void 0 ? void 0 : opts.maxContentLength) && fileLength + data.length > opts.maxContentLength) {
|
|
382
|
+
throw new boom_1.Boom(`content length exceeded when encrypting "${type}"`, {
|
|
330
383
|
data: { media, type }
|
|
331
384
|
});
|
|
332
385
|
}
|
|
333
386
|
if (originalFileStream) {
|
|
334
387
|
if (!originalFileStream.write(data)) {
|
|
335
|
-
await once(originalFileStream, 'drain');
|
|
388
|
+
await (0, events_1.once)(originalFileStream, 'drain');
|
|
336
389
|
}
|
|
337
390
|
}
|
|
338
391
|
sha256Plain.update(data);
|
|
@@ -345,9 +398,9 @@ export const encryptedStream = async (media, mediaType, { logger, saveOriginalFi
|
|
|
345
398
|
const fileEncSha256 = sha256Enc.digest();
|
|
346
399
|
encFileWriteStream.write(mac);
|
|
347
400
|
encFileWriteStream.end();
|
|
348
|
-
originalFileStream
|
|
401
|
+
(_a = originalFileStream === null || originalFileStream === void 0 ? void 0 : originalFileStream.end) === null || _a === void 0 ? void 0 : _a.call(originalFileStream);
|
|
349
402
|
stream.destroy();
|
|
350
|
-
logger
|
|
403
|
+
logger === null || logger === void 0 ? void 0 : logger.debug('encrypted data successfully');
|
|
351
404
|
return {
|
|
352
405
|
mediaKey,
|
|
353
406
|
originalFilePath,
|
|
@@ -361,44 +414,47 @@ export const encryptedStream = async (media, mediaType, { logger, saveOriginalFi
|
|
|
361
414
|
catch (error) {
|
|
362
415
|
// destroy all streams with error
|
|
363
416
|
encFileWriteStream.destroy();
|
|
364
|
-
originalFileStream
|
|
417
|
+
(_b = originalFileStream === null || originalFileStream === void 0 ? void 0 : originalFileStream.destroy) === null || _b === void 0 ? void 0 : _b.call(originalFileStream);
|
|
365
418
|
aes.destroy();
|
|
366
419
|
hmac.destroy();
|
|
367
420
|
sha256Plain.destroy();
|
|
368
421
|
sha256Enc.destroy();
|
|
369
422
|
stream.destroy();
|
|
370
423
|
try {
|
|
371
|
-
await
|
|
424
|
+
await fs_1.promises.unlink(encFilePath);
|
|
372
425
|
if (originalFilePath) {
|
|
373
|
-
await
|
|
426
|
+
await fs_1.promises.unlink(originalFilePath);
|
|
374
427
|
}
|
|
375
428
|
}
|
|
376
429
|
catch (err) {
|
|
377
|
-
logger
|
|
430
|
+
logger === null || logger === void 0 ? void 0 : logger.error({ err }, 'failed deleting tmp files');
|
|
378
431
|
}
|
|
379
432
|
throw error;
|
|
380
433
|
}
|
|
381
434
|
};
|
|
435
|
+
exports.encryptedStream = encryptedStream;
|
|
382
436
|
const DEF_HOST = 'mmg.whatsapp.net';
|
|
383
437
|
const AES_CHUNK_SIZE = 16;
|
|
384
438
|
const toSmallestChunkSize = (num) => {
|
|
385
439
|
return Math.floor(num / AES_CHUNK_SIZE) * AES_CHUNK_SIZE;
|
|
386
440
|
};
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
const
|
|
441
|
+
const getUrlFromDirectPath = (directPath) => `https://${DEF_HOST}${directPath}`;
|
|
442
|
+
exports.getUrlFromDirectPath = getUrlFromDirectPath;
|
|
443
|
+
const downloadContentFromMessage = async ({ mediaKey, directPath, url }, type, opts = {}) => {
|
|
444
|
+
const isValidMediaUrl = url === null || url === void 0 ? void 0 : url.startsWith('https://mmg.whatsapp.net/');
|
|
445
|
+
const downloadUrl = isValidMediaUrl ? url : (0, exports.getUrlFromDirectPath)(directPath);
|
|
391
446
|
if (!downloadUrl) {
|
|
392
|
-
throw new Boom('No valid media URL or directPath present in message', { statusCode: 400 });
|
|
447
|
+
throw new boom_1.Boom('No valid media URL or directPath present in message', { statusCode: 400 });
|
|
393
448
|
}
|
|
394
449
|
const keys = await getMediaKeys(mediaKey, type);
|
|
395
|
-
return downloadEncryptedContent(downloadUrl, keys, opts);
|
|
450
|
+
return (0, exports.downloadEncryptedContent)(downloadUrl, keys, opts);
|
|
396
451
|
};
|
|
452
|
+
exports.downloadContentFromMessage = downloadContentFromMessage;
|
|
397
453
|
/**
|
|
398
454
|
* Decrypts and downloads an AES256-CBC encrypted file given the keys.
|
|
399
455
|
* Assumes the SHA256 of the plaintext is appended to the end of the ciphertext
|
|
400
456
|
* */
|
|
401
|
-
|
|
457
|
+
const downloadEncryptedContent = async (downloadUrl, { cipherKey, iv }, { startByte, endByte, options } = {}) => {
|
|
402
458
|
let bytesFetched = 0;
|
|
403
459
|
let startChunk = 0;
|
|
404
460
|
let firstBlockIsIV = false;
|
|
@@ -413,8 +469,8 @@ export const downloadEncryptedContent = async (downloadUrl, { cipherKey, iv }, {
|
|
|
413
469
|
}
|
|
414
470
|
const endChunk = endByte ? toSmallestChunkSize(endByte || 0) + AES_CHUNK_SIZE : undefined;
|
|
415
471
|
const headers = {
|
|
416
|
-
...(options
|
|
417
|
-
Origin: DEFAULT_ORIGIN
|
|
472
|
+
...((options === null || options === void 0 ? void 0 : options.headers) || {}),
|
|
473
|
+
Origin: Defaults_1.DEFAULT_ORIGIN
|
|
418
474
|
};
|
|
419
475
|
if (startChunk || endChunk) {
|
|
420
476
|
headers.Range = `bytes=${startChunk}-`;
|
|
@@ -423,7 +479,7 @@ export const downloadEncryptedContent = async (downloadUrl, { cipherKey, iv }, {
|
|
|
423
479
|
}
|
|
424
480
|
}
|
|
425
481
|
// download the message
|
|
426
|
-
const fetched = await getHttpStream(downloadUrl, {
|
|
482
|
+
const fetched = await (0, exports.getHttpStream)(downloadUrl, {
|
|
427
483
|
...(options || {}),
|
|
428
484
|
headers,
|
|
429
485
|
maxBodyLength: Infinity,
|
|
@@ -442,7 +498,7 @@ export const downloadEncryptedContent = async (downloadUrl, { cipherKey, iv }, {
|
|
|
442
498
|
push(bytes);
|
|
443
499
|
}
|
|
444
500
|
};
|
|
445
|
-
const output = new Transform({
|
|
501
|
+
const output = new stream_1.Transform({
|
|
446
502
|
transform(chunk, _, callback) {
|
|
447
503
|
let data = Buffer.concat([remainingBytes, chunk]);
|
|
448
504
|
const decryptLength = toSmallestChunkSize(data.length);
|
|
@@ -481,8 +537,9 @@ export const downloadEncryptedContent = async (downloadUrl, { cipherKey, iv }, {
|
|
|
481
537
|
});
|
|
482
538
|
return fetched.pipe(output, { end: true });
|
|
483
539
|
};
|
|
484
|
-
|
|
485
|
-
|
|
540
|
+
exports.downloadEncryptedContent = downloadEncryptedContent;
|
|
541
|
+
function extensionForMediaMessage(message) {
|
|
542
|
+
const getExtension = (mimetype) => mimetype.split(';')[0].split('/')[1];
|
|
486
543
|
const type = Object.keys(message)[0];
|
|
487
544
|
let extension;
|
|
488
545
|
if (type === 'locationMessage' || type === 'liveLocationMessage' || type === 'productMessage') {
|
|
@@ -494,27 +551,28 @@ export function extensionForMediaMessage(message) {
|
|
|
494
551
|
}
|
|
495
552
|
return extension;
|
|
496
553
|
}
|
|
497
|
-
|
|
554
|
+
const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, options }, refreshMediaConn) => {
|
|
498
555
|
return async (filePath, { mediaType, fileEncSha256B64, timeoutMs }) => {
|
|
556
|
+
var _a, _b;
|
|
499
557
|
// send a query JSON to obtain the url & auth token to upload our media
|
|
500
558
|
let uploadInfo = await refreshMediaConn(false);
|
|
501
559
|
let urls;
|
|
502
560
|
const hosts = [...customUploadHosts, ...uploadInfo.hosts];
|
|
503
|
-
fileEncSha256B64 = encodeBase64EncodedStringForUpload(fileEncSha256B64);
|
|
561
|
+
fileEncSha256B64 = (0, exports.encodeBase64EncodedStringForUpload)(fileEncSha256B64);
|
|
504
562
|
for (const { hostname } of hosts) {
|
|
505
563
|
logger.debug(`uploading to "${hostname}"`);
|
|
506
564
|
const auth = encodeURIComponent(uploadInfo.auth); // the auth token
|
|
507
|
-
const url = `https://${hostname}${MEDIA_PATH_MAP[mediaType]}/${fileEncSha256B64}?auth=${auth}&token=${fileEncSha256B64}`;
|
|
565
|
+
const url = `https://${hostname}${Defaults_1.MEDIA_PATH_MAP[mediaType]}/${fileEncSha256B64}?auth=${auth}&token=${fileEncSha256B64}`;
|
|
508
566
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
509
567
|
let result;
|
|
510
568
|
try {
|
|
511
|
-
const body = await
|
|
569
|
+
const body = await axios_1.default.post(url, (0, fs_1.createReadStream)(filePath), {
|
|
512
570
|
...options,
|
|
513
571
|
maxRedirects: 0,
|
|
514
572
|
headers: {
|
|
515
573
|
...(options.headers || {}),
|
|
516
574
|
'Content-Type': 'application/octet-stream',
|
|
517
|
-
Origin: DEFAULT_ORIGIN
|
|
575
|
+
Origin: Defaults_1.DEFAULT_ORIGIN
|
|
518
576
|
},
|
|
519
577
|
httpsAgent: fetchAgent,
|
|
520
578
|
timeout: timeoutMs,
|
|
@@ -523,7 +581,7 @@ export const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, opt
|
|
|
523
581
|
maxContentLength: Infinity
|
|
524
582
|
});
|
|
525
583
|
result = body.data;
|
|
526
|
-
if (result
|
|
584
|
+
if ((result === null || result === void 0 ? void 0 : result.url) || (result === null || result === void 0 ? void 0 : result.directPath)) {
|
|
527
585
|
urls = {
|
|
528
586
|
mediaUrl: result.url,
|
|
529
587
|
directPath: result.direct_path
|
|
@@ -536,36 +594,37 @@ export const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, opt
|
|
|
536
594
|
}
|
|
537
595
|
}
|
|
538
596
|
catch (error) {
|
|
539
|
-
if (
|
|
540
|
-
result = error.response
|
|
597
|
+
if (axios_1.default.isAxiosError(error)) {
|
|
598
|
+
result = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data;
|
|
541
599
|
}
|
|
542
|
-
const isLast = hostname === hosts[uploadInfo.hosts.length - 1]
|
|
600
|
+
const isLast = hostname === ((_b = hosts[uploadInfo.hosts.length - 1]) === null || _b === void 0 ? void 0 : _b.hostname);
|
|
543
601
|
logger.warn({ trace: error.stack, uploadResult: result }, `Error in uploading to ${hostname} ${isLast ? '' : ', retrying...'}`);
|
|
544
602
|
}
|
|
545
603
|
}
|
|
546
604
|
if (!urls) {
|
|
547
|
-
throw new Boom('Media upload failed on all hosts', { statusCode: 500 });
|
|
605
|
+
throw new boom_1.Boom('Media upload failed on all hosts', { statusCode: 500 });
|
|
548
606
|
}
|
|
549
607
|
return urls;
|
|
550
608
|
};
|
|
551
609
|
};
|
|
610
|
+
exports.getWAUploadToServer = getWAUploadToServer;
|
|
552
611
|
const getMediaRetryKey = (mediaKey) => {
|
|
553
|
-
return hkdf(mediaKey, 32, { info: 'WhatsApp Media Retry Notification' });
|
|
612
|
+
return (0, crypto_1.hkdf)(mediaKey, 32, { info: 'WhatsApp Media Retry Notification' });
|
|
554
613
|
};
|
|
555
614
|
/**
|
|
556
615
|
* Generate a binary node that will request the phone to re-upload the media & return the newly uploaded URL
|
|
557
616
|
*/
|
|
558
|
-
|
|
617
|
+
const encryptMediaRetryRequest = async (key, mediaKey, meId) => {
|
|
559
618
|
const recp = { stanzaId: key.id };
|
|
560
|
-
const recpBuffer = proto.ServerErrorReceipt.encode(recp).finish();
|
|
619
|
+
const recpBuffer = WAProto_1.proto.ServerErrorReceipt.encode(recp).finish();
|
|
561
620
|
const iv = Crypto.randomBytes(12);
|
|
562
621
|
const retryKey = await getMediaRetryKey(mediaKey);
|
|
563
|
-
const ciphertext = aesEncryptGCM(recpBuffer, retryKey, iv, Buffer.from(key.id));
|
|
622
|
+
const ciphertext = (0, crypto_1.aesEncryptGCM)(recpBuffer, retryKey, iv, Buffer.from(key.id));
|
|
564
623
|
const req = {
|
|
565
624
|
tag: 'receipt',
|
|
566
625
|
attrs: {
|
|
567
626
|
id: key.id,
|
|
568
|
-
to: jidNormalizedUser(meId),
|
|
627
|
+
to: (0, WABinary_1.jidNormalizedUser)(meId),
|
|
569
628
|
type: 'server-error'
|
|
570
629
|
},
|
|
571
630
|
content: [
|
|
@@ -593,8 +652,9 @@ export const encryptMediaRetryRequest = async (key, mediaKey, meId) => {
|
|
|
593
652
|
};
|
|
594
653
|
return req;
|
|
595
654
|
};
|
|
596
|
-
|
|
597
|
-
|
|
655
|
+
exports.encryptMediaRetryRequest = encryptMediaRetryRequest;
|
|
656
|
+
const decodeMediaRetryNode = (node) => {
|
|
657
|
+
const rmrNode = (0, WABinary_1.getBinaryNodeChild)(node, 'rmr');
|
|
598
658
|
const event = {
|
|
599
659
|
key: {
|
|
600
660
|
id: node.attrs.id,
|
|
@@ -603,37 +663,39 @@ export const decodeMediaRetryNode = (node) => {
|
|
|
603
663
|
participant: rmrNode.attrs.participant
|
|
604
664
|
}
|
|
605
665
|
};
|
|
606
|
-
const errorNode = getBinaryNodeChild(node, 'error');
|
|
666
|
+
const errorNode = (0, WABinary_1.getBinaryNodeChild)(node, 'error');
|
|
607
667
|
if (errorNode) {
|
|
608
668
|
const errorCode = +errorNode.attrs.code;
|
|
609
|
-
event.error = new Boom(`Failed to re-upload media (${errorCode})`, {
|
|
669
|
+
event.error = new boom_1.Boom(`Failed to re-upload media (${errorCode})`, {
|
|
610
670
|
data: errorNode.attrs,
|
|
611
|
-
statusCode: getStatusCodeForMediaRetry(errorCode)
|
|
671
|
+
statusCode: (0, exports.getStatusCodeForMediaRetry)(errorCode)
|
|
612
672
|
});
|
|
613
673
|
}
|
|
614
674
|
else {
|
|
615
|
-
const encryptedInfoNode = getBinaryNodeChild(node, 'encrypt');
|
|
616
|
-
const ciphertext = getBinaryNodeChildBuffer(encryptedInfoNode, 'enc_p');
|
|
617
|
-
const iv = getBinaryNodeChildBuffer(encryptedInfoNode, 'enc_iv');
|
|
675
|
+
const encryptedInfoNode = (0, WABinary_1.getBinaryNodeChild)(node, 'encrypt');
|
|
676
|
+
const ciphertext = (0, WABinary_1.getBinaryNodeChildBuffer)(encryptedInfoNode, 'enc_p');
|
|
677
|
+
const iv = (0, WABinary_1.getBinaryNodeChildBuffer)(encryptedInfoNode, 'enc_iv');
|
|
618
678
|
if (ciphertext && iv) {
|
|
619
679
|
event.media = { ciphertext, iv };
|
|
620
680
|
}
|
|
621
681
|
else {
|
|
622
|
-
event.error = new Boom('Failed to re-upload media (missing ciphertext)', { statusCode: 404 });
|
|
682
|
+
event.error = new boom_1.Boom('Failed to re-upload media (missing ciphertext)', { statusCode: 404 });
|
|
623
683
|
}
|
|
624
684
|
}
|
|
625
685
|
return event;
|
|
626
686
|
};
|
|
627
|
-
|
|
687
|
+
exports.decodeMediaRetryNode = decodeMediaRetryNode;
|
|
688
|
+
const decryptMediaRetryData = async ({ ciphertext, iv }, mediaKey, msgId) => {
|
|
628
689
|
const retryKey = await getMediaRetryKey(mediaKey);
|
|
629
|
-
const plaintext = aesDecryptGCM(ciphertext, retryKey, iv, Buffer.from(msgId));
|
|
630
|
-
return proto.MediaRetryNotification.decode(plaintext);
|
|
690
|
+
const plaintext = (0, crypto_1.aesDecryptGCM)(ciphertext, retryKey, iv, Buffer.from(msgId));
|
|
691
|
+
return WAProto_1.proto.MediaRetryNotification.decode(plaintext);
|
|
631
692
|
};
|
|
632
|
-
|
|
693
|
+
exports.decryptMediaRetryData = decryptMediaRetryData;
|
|
694
|
+
const getStatusCodeForMediaRetry = (code) => MEDIA_RETRY_STATUS_MAP[code];
|
|
695
|
+
exports.getStatusCodeForMediaRetry = getStatusCodeForMediaRetry;
|
|
633
696
|
const MEDIA_RETRY_STATUS_MAP = {
|
|
634
|
-
[proto.MediaRetryNotification.ResultType.SUCCESS]: 200,
|
|
635
|
-
[proto.MediaRetryNotification.ResultType.DECRYPTION_ERROR]: 412,
|
|
636
|
-
[proto.MediaRetryNotification.ResultType.NOT_FOUND]: 404,
|
|
637
|
-
[proto.MediaRetryNotification.ResultType.GENERAL_ERROR]: 418
|
|
697
|
+
[WAProto_1.proto.MediaRetryNotification.ResultType.SUCCESS]: 200,
|
|
698
|
+
[WAProto_1.proto.MediaRetryNotification.ResultType.DECRYPTION_ERROR]: 412,
|
|
699
|
+
[WAProto_1.proto.MediaRetryNotification.ResultType.NOT_FOUND]: 404,
|
|
700
|
+
[WAProto_1.proto.MediaRetryNotification.ResultType.GENERAL_ERROR]: 418
|
|
638
701
|
};
|
|
639
|
-
//# sourceMappingURL=messages-media.js.map
|