@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
package/lib/Utils/crypto.js
CHANGED
|
@@ -1,12 +1,61 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.signedKeyPair = exports.Curve = exports.generateSignalPubKey = void 0;
|
|
37
|
+
exports.aesEncryptGCM = aesEncryptGCM;
|
|
38
|
+
exports.aesDecryptGCM = aesDecryptGCM;
|
|
39
|
+
exports.aesEncryptCTR = aesEncryptCTR;
|
|
40
|
+
exports.aesDecryptCTR = aesDecryptCTR;
|
|
41
|
+
exports.aesDecrypt = aesDecrypt;
|
|
42
|
+
exports.aesDecryptWithIV = aesDecryptWithIV;
|
|
43
|
+
exports.aesEncrypt = aesEncrypt;
|
|
44
|
+
exports.aesEncrypWithIV = aesEncrypWithIV;
|
|
45
|
+
exports.hmacSign = hmacSign;
|
|
46
|
+
exports.sha256 = sha256;
|
|
47
|
+
exports.md5 = md5;
|
|
48
|
+
exports.hkdf = hkdf;
|
|
49
|
+
exports.derivePairingCodeKey = derivePairingCodeKey;
|
|
50
|
+
const crypto_1 = require("crypto");
|
|
51
|
+
const libsignal = __importStar(require("libsignal"));
|
|
52
|
+
const Defaults_1 = require("../Defaults");
|
|
5
53
|
// insure browser & node compatibility
|
|
6
54
|
const { subtle } = globalThis.crypto;
|
|
7
55
|
/** prefix version byte to the pub keys, required for some curve crypto functions */
|
|
8
|
-
|
|
9
|
-
|
|
56
|
+
const generateSignalPubKey = (pubKey) => pubKey.length === 33 ? pubKey : Buffer.concat([Defaults_1.KEY_BUNDLE_TYPE, pubKey]);
|
|
57
|
+
exports.generateSignalPubKey = generateSignalPubKey;
|
|
58
|
+
exports.Curve = {
|
|
10
59
|
generateKeyPair: () => {
|
|
11
60
|
const { pubKey, privKey } = libsignal.curve.generateKeyPair();
|
|
12
61
|
return {
|
|
@@ -16,13 +65,13 @@ export const Curve = {
|
|
|
16
65
|
};
|
|
17
66
|
},
|
|
18
67
|
sharedKey: (privateKey, publicKey) => {
|
|
19
|
-
const shared = libsignal.curve.calculateAgreement(generateSignalPubKey(publicKey), privateKey);
|
|
68
|
+
const shared = libsignal.curve.calculateAgreement((0, exports.generateSignalPubKey)(publicKey), privateKey);
|
|
20
69
|
return Buffer.from(shared);
|
|
21
70
|
},
|
|
22
71
|
sign: (privateKey, buf) => libsignal.curve.calculateSignature(privateKey, buf),
|
|
23
72
|
verify: (pubKey, message, signature) => {
|
|
24
73
|
try {
|
|
25
|
-
libsignal.curve.verifySignature(generateSignalPubKey(pubKey), message, signature);
|
|
74
|
+
libsignal.curve.verifySignature((0, exports.generateSignalPubKey)(pubKey), message, signature);
|
|
26
75
|
return true;
|
|
27
76
|
}
|
|
28
77
|
catch (error) {
|
|
@@ -30,19 +79,20 @@ export const Curve = {
|
|
|
30
79
|
}
|
|
31
80
|
}
|
|
32
81
|
};
|
|
33
|
-
|
|
34
|
-
const preKey = Curve.generateKeyPair();
|
|
35
|
-
const pubKey = generateSignalPubKey(preKey.public);
|
|
36
|
-
const signature = Curve.sign(identityKeyPair.private, pubKey);
|
|
82
|
+
const signedKeyPair = (identityKeyPair, keyId) => {
|
|
83
|
+
const preKey = exports.Curve.generateKeyPair();
|
|
84
|
+
const pubKey = (0, exports.generateSignalPubKey)(preKey.public);
|
|
85
|
+
const signature = exports.Curve.sign(identityKeyPair.private, pubKey);
|
|
37
86
|
return { keyPair: preKey, signature, keyId };
|
|
38
87
|
};
|
|
88
|
+
exports.signedKeyPair = signedKeyPair;
|
|
39
89
|
const GCM_TAG_LENGTH = 128 >> 3;
|
|
40
90
|
/**
|
|
41
91
|
* encrypt AES 256 GCM;
|
|
42
92
|
* where the tag tag is suffixed to the ciphertext
|
|
43
93
|
* */
|
|
44
|
-
|
|
45
|
-
const cipher = createCipheriv('aes-256-gcm', key, iv);
|
|
94
|
+
function aesEncryptGCM(plaintext, key, iv, additionalData) {
|
|
95
|
+
const cipher = (0, crypto_1.createCipheriv)('aes-256-gcm', key, iv);
|
|
46
96
|
cipher.setAAD(additionalData);
|
|
47
97
|
return Buffer.concat([cipher.update(plaintext), cipher.final(), cipher.getAuthTag()]);
|
|
48
98
|
}
|
|
@@ -50,8 +100,8 @@ export function aesEncryptGCM(plaintext, key, iv, additionalData) {
|
|
|
50
100
|
* decrypt AES 256 GCM;
|
|
51
101
|
* where the auth tag is suffixed to the ciphertext
|
|
52
102
|
* */
|
|
53
|
-
|
|
54
|
-
const decipher = createDecipheriv('aes-256-gcm', key, iv);
|
|
103
|
+
function aesDecryptGCM(ciphertext, key, iv, additionalData) {
|
|
104
|
+
const decipher = (0, crypto_1.createDecipheriv)('aes-256-gcm', key, iv);
|
|
55
105
|
// decrypt additional adata
|
|
56
106
|
const enc = ciphertext.slice(0, ciphertext.length - GCM_TAG_LENGTH);
|
|
57
107
|
const tag = ciphertext.slice(ciphertext.length - GCM_TAG_LENGTH);
|
|
@@ -60,46 +110,46 @@ export function aesDecryptGCM(ciphertext, key, iv, additionalData) {
|
|
|
60
110
|
decipher.setAuthTag(tag);
|
|
61
111
|
return Buffer.concat([decipher.update(enc), decipher.final()]);
|
|
62
112
|
}
|
|
63
|
-
|
|
64
|
-
const cipher = createCipheriv('aes-256-ctr', key, iv);
|
|
113
|
+
function aesEncryptCTR(plaintext, key, iv) {
|
|
114
|
+
const cipher = (0, crypto_1.createCipheriv)('aes-256-ctr', key, iv);
|
|
65
115
|
return Buffer.concat([cipher.update(plaintext), cipher.final()]);
|
|
66
116
|
}
|
|
67
|
-
|
|
68
|
-
const decipher = createDecipheriv('aes-256-ctr', key, iv);
|
|
117
|
+
function aesDecryptCTR(ciphertext, key, iv) {
|
|
118
|
+
const decipher = (0, crypto_1.createDecipheriv)('aes-256-ctr', key, iv);
|
|
69
119
|
return Buffer.concat([decipher.update(ciphertext), decipher.final()]);
|
|
70
120
|
}
|
|
71
121
|
/** decrypt AES 256 CBC; where the IV is prefixed to the buffer */
|
|
72
|
-
|
|
122
|
+
function aesDecrypt(buffer, key) {
|
|
73
123
|
return aesDecryptWithIV(buffer.slice(16, buffer.length), key, buffer.slice(0, 16));
|
|
74
124
|
}
|
|
75
125
|
/** decrypt AES 256 CBC */
|
|
76
|
-
|
|
77
|
-
const aes = createDecipheriv('aes-256-cbc', key, IV);
|
|
126
|
+
function aesDecryptWithIV(buffer, key, IV) {
|
|
127
|
+
const aes = (0, crypto_1.createDecipheriv)('aes-256-cbc', key, IV);
|
|
78
128
|
return Buffer.concat([aes.update(buffer), aes.final()]);
|
|
79
129
|
}
|
|
80
130
|
// encrypt AES 256 CBC; where a random IV is prefixed to the buffer
|
|
81
|
-
|
|
82
|
-
const IV = randomBytes(16);
|
|
83
|
-
const aes = createCipheriv('aes-256-cbc', key, IV);
|
|
131
|
+
function aesEncrypt(buffer, key) {
|
|
132
|
+
const IV = (0, crypto_1.randomBytes)(16);
|
|
133
|
+
const aes = (0, crypto_1.createCipheriv)('aes-256-cbc', key, IV);
|
|
84
134
|
return Buffer.concat([IV, aes.update(buffer), aes.final()]); // prefix IV to the buffer
|
|
85
135
|
}
|
|
86
136
|
// encrypt AES 256 CBC with a given IV
|
|
87
|
-
|
|
88
|
-
const aes = createCipheriv('aes-256-cbc', key, IV);
|
|
137
|
+
function aesEncrypWithIV(buffer, key, IV) {
|
|
138
|
+
const aes = (0, crypto_1.createCipheriv)('aes-256-cbc', key, IV);
|
|
89
139
|
return Buffer.concat([aes.update(buffer), aes.final()]); // prefix IV to the buffer
|
|
90
140
|
}
|
|
91
141
|
// sign HMAC using SHA 256
|
|
92
|
-
|
|
93
|
-
return createHmac(variant, key).update(buffer).digest();
|
|
142
|
+
function hmacSign(buffer, key, variant = 'sha256') {
|
|
143
|
+
return (0, crypto_1.createHmac)(variant, key).update(buffer).digest();
|
|
94
144
|
}
|
|
95
|
-
|
|
96
|
-
return createHash('sha256').update(buffer).digest();
|
|
145
|
+
function sha256(buffer) {
|
|
146
|
+
return (0, crypto_1.createHash)('sha256').update(buffer).digest();
|
|
97
147
|
}
|
|
98
|
-
|
|
99
|
-
return createHash('md5').update(buffer).digest();
|
|
148
|
+
function md5(buffer) {
|
|
149
|
+
return (0, crypto_1.createHash)('md5').update(buffer).digest();
|
|
100
150
|
}
|
|
101
151
|
// HKDF key expansion
|
|
102
|
-
|
|
152
|
+
async function hkdf(buffer, expandedLength, info) {
|
|
103
153
|
// Ensure we have a Uint8Array for the key material
|
|
104
154
|
const inputKeyMaterial = buffer instanceof Uint8Array ? buffer : new Uint8Array(buffer);
|
|
105
155
|
// Set default values if not provided
|
|
@@ -117,7 +167,7 @@ export async function hkdf(buffer, expandedLength, info) {
|
|
|
117
167
|
);
|
|
118
168
|
return Buffer.from(derivedBits);
|
|
119
169
|
}
|
|
120
|
-
|
|
170
|
+
async function derivePairingCodeKey(pairingCode, salt) {
|
|
121
171
|
// Convert inputs to formats Web Crypto API can work with
|
|
122
172
|
const encoder = new TextEncoder();
|
|
123
173
|
const pairingCodeBuffer = encoder.encode(pairingCode);
|
|
@@ -135,4 +185,3 @@ export async function derivePairingCodeKey(pairingCode, salt) {
|
|
|
135
185
|
);
|
|
136
186
|
return Buffer.from(derivedBits);
|
|
137
187
|
}
|
|
138
|
-
//# sourceMappingURL=crypto.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
1
|
+
import { SignalRepository, WAMessage } from '../Types';
|
|
2
|
+
import { BinaryNode } from '../WABinary';
|
|
3
|
+
import { ILogger } from './logger';
|
|
4
4
|
export declare const NO_MESSAGE_FOUND_ERROR_TEXT = "Message absent from node";
|
|
5
5
|
export declare const MISSING_KEYS_ERROR_TEXT = "Key used already or never filled";
|
|
6
6
|
export declare const NACK_REASONS: {
|
|
@@ -29,8 +29,7 @@ export declare function decodeMessageNode(stanza: BinaryNode, meId: string, meLi
|
|
|
29
29
|
};
|
|
30
30
|
export declare const decryptMessageNode: (stanza: BinaryNode, meId: string, meLid: string, repository: SignalRepository, logger: ILogger) => {
|
|
31
31
|
fullMessage: WAMessage;
|
|
32
|
-
category: string
|
|
32
|
+
category: string;
|
|
33
33
|
author: string;
|
|
34
34
|
decrypt(): Promise<void>;
|
|
35
35
|
};
|
|
36
|
-
//# sourceMappingURL=decode-wa-message.d.ts.map
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.decryptMessageNode = exports.NACK_REASONS = exports.MISSING_KEYS_ERROR_TEXT = exports.NO_MESSAGE_FOUND_ERROR_TEXT = void 0;
|
|
4
|
+
exports.decodeMessageNode = decodeMessageNode;
|
|
5
|
+
const boom_1 = require("@hapi/boom");
|
|
6
|
+
const WAProto_1 = require("../../WAProto");
|
|
7
|
+
const WABinary_1 = require("../WABinary");
|
|
8
|
+
const generics_1 = require("./generics");
|
|
9
|
+
exports.NO_MESSAGE_FOUND_ERROR_TEXT = 'Message absent from node';
|
|
10
|
+
exports.MISSING_KEYS_ERROR_TEXT = 'Key used already or never filled';
|
|
11
|
+
exports.NACK_REASONS = {
|
|
8
12
|
ParsingError: 487,
|
|
9
13
|
UnrecognizedStanza: 488,
|
|
10
14
|
UnrecognizedStanzaClass: 489,
|
|
@@ -23,7 +27,8 @@ export const NACK_REASONS = {
|
|
|
23
27
|
* Decode the received node as a message.
|
|
24
28
|
* @note this will only parse the message, not decrypt it
|
|
25
29
|
*/
|
|
26
|
-
|
|
30
|
+
function decodeMessageNode(stanza, meId, meLid) {
|
|
31
|
+
var _a, _b, _c, _d, _e;
|
|
27
32
|
let msgType;
|
|
28
33
|
let chatId;
|
|
29
34
|
let author;
|
|
@@ -31,12 +36,12 @@ export function decodeMessageNode(stanza, meId, meLid) {
|
|
|
31
36
|
const from = stanza.attrs.from;
|
|
32
37
|
const participant = stanza.attrs.participant;
|
|
33
38
|
const recipient = stanza.attrs.recipient;
|
|
34
|
-
const isMe = (jid) => areJidsSameUser(jid, meId);
|
|
35
|
-
const isMeLid = (jid) => areJidsSameUser(jid, meLid);
|
|
36
|
-
if (isJidUser(from) || isLidUser(from)) {
|
|
37
|
-
if (recipient && !isJidMetaIa(recipient)) {
|
|
39
|
+
const isMe = (jid) => (0, WABinary_1.areJidsSameUser)(jid, meId);
|
|
40
|
+
const isMeLid = (jid) => (0, WABinary_1.areJidsSameUser)(jid, meLid);
|
|
41
|
+
if ((0, WABinary_1.isJidUser)(from) || (0, WABinary_1.isLidUser)(from)) {
|
|
42
|
+
if (recipient && !(0, WABinary_1.isJidMetaIa)(recipient)) {
|
|
38
43
|
if (!isMe(from) && !isMeLid(from)) {
|
|
39
|
-
throw new Boom('receipient present, but msg not from me', { data: stanza });
|
|
44
|
+
throw new boom_1.Boom('receipient present, but msg not from me', { data: stanza });
|
|
40
45
|
}
|
|
41
46
|
chatId = recipient;
|
|
42
47
|
}
|
|
@@ -46,20 +51,20 @@ export function decodeMessageNode(stanza, meId, meLid) {
|
|
|
46
51
|
msgType = 'chat';
|
|
47
52
|
author = from;
|
|
48
53
|
}
|
|
49
|
-
else if (isJidGroup(from)) {
|
|
54
|
+
else if ((0, WABinary_1.isJidGroup)(from)) {
|
|
50
55
|
if (!participant) {
|
|
51
|
-
throw new Boom('No participant in group message');
|
|
56
|
+
throw new boom_1.Boom('No participant in group message');
|
|
52
57
|
}
|
|
53
58
|
msgType = 'group';
|
|
54
59
|
author = participant;
|
|
55
60
|
chatId = from;
|
|
56
61
|
}
|
|
57
|
-
else if (isJidBroadcast(from)) {
|
|
62
|
+
else if ((0, WABinary_1.isJidBroadcast)(from)) {
|
|
58
63
|
if (!participant) {
|
|
59
|
-
throw new Boom('No participant in group message');
|
|
64
|
+
throw new boom_1.Boom('No participant in group message');
|
|
60
65
|
}
|
|
61
66
|
const isParticipantMe = isMe(participant);
|
|
62
|
-
if (isJidStatusBroadcast(from)) {
|
|
67
|
+
if ((0, WABinary_1.isJidStatusBroadcast)(from)) {
|
|
63
68
|
msgType = isParticipantMe ? 'direct_peer_status' : 'other_status';
|
|
64
69
|
}
|
|
65
70
|
else {
|
|
@@ -68,35 +73,35 @@ export function decodeMessageNode(stanza, meId, meLid) {
|
|
|
68
73
|
chatId = from;
|
|
69
74
|
author = participant;
|
|
70
75
|
}
|
|
71
|
-
else if (isJidNewsletter(from)) {
|
|
76
|
+
else if ((0, WABinary_1.isJidNewsletter)(from)) {
|
|
72
77
|
msgType = 'newsletter';
|
|
73
78
|
chatId = from;
|
|
74
79
|
author = from;
|
|
75
80
|
}
|
|
76
81
|
else {
|
|
77
|
-
throw new Boom('Unknown message type', { data: stanza });
|
|
82
|
+
throw new boom_1.Boom('Unknown message type', { data: stanza });
|
|
78
83
|
}
|
|
79
|
-
const fromMe = (isLidUser(from) ? isMeLid : isMe)(
|
|
80
|
-
const pushname = stanza
|
|
84
|
+
const fromMe = ((0, WABinary_1.isLidUser)(from) ? isMeLid : isMe)(stanza.attrs.participant || stanza.attrs.from);
|
|
85
|
+
const pushname = (_a = stanza === null || stanza === void 0 ? void 0 : stanza.attrs) === null || _a === void 0 ? void 0 : _a.notify;
|
|
81
86
|
const key = {
|
|
82
87
|
remoteJid: chatId,
|
|
83
88
|
fromMe,
|
|
84
89
|
id: msgId,
|
|
85
|
-
senderLid: stanza
|
|
86
|
-
senderPn: stanza
|
|
90
|
+
senderLid: (_b = stanza === null || stanza === void 0 ? void 0 : stanza.attrs) === null || _b === void 0 ? void 0 : _b.sender_lid,
|
|
91
|
+
senderPn: (_c = stanza === null || stanza === void 0 ? void 0 : stanza.attrs) === null || _c === void 0 ? void 0 : _c.sender_pn,
|
|
87
92
|
participant,
|
|
88
|
-
participantPn: stanza
|
|
89
|
-
participantLid: stanza
|
|
93
|
+
participantPn: (_d = stanza === null || stanza === void 0 ? void 0 : stanza.attrs) === null || _d === void 0 ? void 0 : _d.participant_pn,
|
|
94
|
+
participantLid: (_e = stanza === null || stanza === void 0 ? void 0 : stanza.attrs) === null || _e === void 0 ? void 0 : _e.participant_lid,
|
|
90
95
|
...(msgType === 'newsletter' && stanza.attrs.server_id ? { server_id: stanza.attrs.server_id } : {})
|
|
91
96
|
};
|
|
92
97
|
const fullMessage = {
|
|
93
98
|
key,
|
|
94
99
|
messageTimestamp: +stanza.attrs.t,
|
|
95
100
|
pushName: pushname,
|
|
96
|
-
broadcast: isJidBroadcast(from)
|
|
101
|
+
broadcast: (0, WABinary_1.isJidBroadcast)(from)
|
|
97
102
|
};
|
|
98
103
|
if (key.fromMe) {
|
|
99
|
-
fullMessage.status = proto.WebMessageInfo.Status.SERVER_ACK;
|
|
104
|
+
fullMessage.status = WAProto_1.proto.WebMessageInfo.Status.SERVER_ACK;
|
|
100
105
|
}
|
|
101
106
|
return {
|
|
102
107
|
fullMessage,
|
|
@@ -104,19 +109,20 @@ export function decodeMessageNode(stanza, meId, meLid) {
|
|
|
104
109
|
sender: msgType === 'chat' ? author : chatId
|
|
105
110
|
};
|
|
106
111
|
}
|
|
107
|
-
|
|
112
|
+
const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
108
113
|
const { fullMessage, author, sender } = decodeMessageNode(stanza, meId, meLid);
|
|
109
114
|
return {
|
|
110
115
|
fullMessage,
|
|
111
116
|
category: stanza.attrs.category,
|
|
112
117
|
author,
|
|
113
118
|
async decrypt() {
|
|
119
|
+
var _a;
|
|
114
120
|
let decryptables = 0;
|
|
115
121
|
if (Array.isArray(stanza.content)) {
|
|
116
122
|
for (const { tag, attrs, content } of stanza.content) {
|
|
117
123
|
if (tag === 'verified_name' && content instanceof Uint8Array) {
|
|
118
|
-
const cert = proto.VerifiedNameCertificate.decode(content);
|
|
119
|
-
const details = proto.VerifiedNameCertificate.Details.decode(cert.details);
|
|
124
|
+
const cert = WAProto_1.proto.VerifiedNameCertificate.decode(content);
|
|
125
|
+
const details = WAProto_1.proto.VerifiedNameCertificate.Details.decode(cert.details);
|
|
120
126
|
fullMessage.verifiedBizName = details.verifiedName;
|
|
121
127
|
}
|
|
122
128
|
if (tag === 'unavailable' && attrs.type === 'view_once') {
|
|
@@ -142,7 +148,7 @@ export const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
|
142
148
|
break;
|
|
143
149
|
case 'pkmsg':
|
|
144
150
|
case 'msg':
|
|
145
|
-
const user = isJidUser(sender) ? sender : author;
|
|
151
|
+
const user = (0, WABinary_1.isJidUser)(sender) ? sender : author;
|
|
146
152
|
msgBuffer = await repository.decryptMessage({
|
|
147
153
|
jid: user,
|
|
148
154
|
type: e2eType,
|
|
@@ -155,8 +161,8 @@ export const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
|
155
161
|
default:
|
|
156
162
|
throw new Error(`Unknown e2e type: ${e2eType}`);
|
|
157
163
|
}
|
|
158
|
-
let msg = proto.Message.decode(e2eType !== 'plaintext' ? unpadRandomMax16(msgBuffer) : msgBuffer);
|
|
159
|
-
msg = msg.deviceSentMessage
|
|
164
|
+
let msg = WAProto_1.proto.Message.decode(e2eType !== 'plaintext' ? (0, generics_1.unpadRandomMax16)(msgBuffer) : msgBuffer);
|
|
165
|
+
msg = ((_a = msg.deviceSentMessage) === null || _a === void 0 ? void 0 : _a.message) || msg;
|
|
160
166
|
if (msg.senderKeyDistributionMessage) {
|
|
161
167
|
//eslint-disable-next-line max-depth
|
|
162
168
|
try {
|
|
@@ -178,17 +184,17 @@ export const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
|
178
184
|
}
|
|
179
185
|
catch (err) {
|
|
180
186
|
logger.error({ key: fullMessage.key, err }, 'failed to decrypt message');
|
|
181
|
-
fullMessage.messageStubType = proto.WebMessageInfo.StubType.CIPHERTEXT;
|
|
187
|
+
fullMessage.messageStubType = WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT;
|
|
182
188
|
fullMessage.messageStubParameters = [err.message];
|
|
183
189
|
}
|
|
184
190
|
}
|
|
185
191
|
}
|
|
186
192
|
// if nothing was found to decrypt
|
|
187
193
|
if (!decryptables) {
|
|
188
|
-
fullMessage.messageStubType = proto.WebMessageInfo.StubType.CIPHERTEXT;
|
|
189
|
-
fullMessage.messageStubParameters = [NO_MESSAGE_FOUND_ERROR_TEXT];
|
|
194
|
+
fullMessage.messageStubType = WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT;
|
|
195
|
+
fullMessage.messageStubParameters = [exports.NO_MESSAGE_FOUND_ERROR_TEXT];
|
|
190
196
|
}
|
|
191
197
|
}
|
|
192
198
|
};
|
|
193
199
|
};
|
|
194
|
-
|
|
200
|
+
exports.decryptMessageNode = decryptMessageNode;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { BaileysEventEmitter, BaileysEventMap } from '../Types';
|
|
2
|
+
import { ILogger } from './logger';
|
|
3
3
|
/**
|
|
4
4
|
* A map that contains a list of all events that have been triggered
|
|
5
5
|
*
|
|
@@ -19,9 +19,10 @@ type BaileysBufferableEventEmitter = BaileysEventEmitter & {
|
|
|
19
19
|
createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): (...args: A) => Promise<T>;
|
|
20
20
|
/**
|
|
21
21
|
* flushes all buffered events
|
|
22
|
+
* @param force if true, will flush all data regardless of any pending buffers
|
|
22
23
|
* @returns returns true if the flush actually happened, otherwise false
|
|
23
24
|
*/
|
|
24
|
-
flush(): boolean;
|
|
25
|
+
flush(force?: boolean): boolean;
|
|
25
26
|
/** is there an ongoing buffer */
|
|
26
27
|
isBuffering(): boolean;
|
|
27
28
|
};
|
|
@@ -32,4 +33,3 @@ type BaileysBufferableEventEmitter = BaileysEventEmitter & {
|
|
|
32
33
|
*/
|
|
33
34
|
export declare const makeEventBuffer: (logger: ILogger) => BaileysBufferableEventEmitter;
|
|
34
35
|
export {};
|
|
35
|
-
//# sourceMappingURL=event-buffer.d.ts.map
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.makeEventBuffer = void 0;
|
|
7
|
+
const events_1 = __importDefault(require("events"));
|
|
8
|
+
const Types_1 = require("../Types");
|
|
9
|
+
const generics_1 = require("./generics");
|
|
10
|
+
const messages_1 = require("./messages");
|
|
11
|
+
const process_message_1 = require("./process-message");
|
|
7
12
|
const BUFFERABLE_EVENT = [
|
|
8
13
|
'messaging-history.set',
|
|
9
14
|
'chats.upsert',
|
|
@@ -24,11 +29,11 @@ const BUFFERABLE_EVENT_SET = new Set(BUFFERABLE_EVENT);
|
|
|
24
29
|
* making the data processing more efficient.
|
|
25
30
|
* @param ev the baileys event emitter
|
|
26
31
|
*/
|
|
27
|
-
|
|
28
|
-
const ev = new
|
|
32
|
+
const makeEventBuffer = (logger) => {
|
|
33
|
+
const ev = new events_1.default();
|
|
29
34
|
const historyCache = new Set();
|
|
30
35
|
let data = makeBufferData();
|
|
31
|
-
let
|
|
36
|
+
let buffersInProgress = 0;
|
|
32
37
|
// take the generic event and fire it as a baileys event
|
|
33
38
|
ev.on('event', (map) => {
|
|
34
39
|
for (const event in map) {
|
|
@@ -36,19 +41,25 @@ export const makeEventBuffer = (logger) => {
|
|
|
36
41
|
}
|
|
37
42
|
});
|
|
38
43
|
function buffer() {
|
|
39
|
-
|
|
40
|
-
logger.info('Event buffer activated');
|
|
41
|
-
isBuffering = true;
|
|
42
|
-
}
|
|
44
|
+
buffersInProgress += 1;
|
|
43
45
|
}
|
|
44
|
-
function flush() {
|
|
45
|
-
|
|
46
|
+
function flush(force = false) {
|
|
47
|
+
// no buffer going on
|
|
48
|
+
if (!buffersInProgress) {
|
|
46
49
|
return false;
|
|
47
50
|
}
|
|
48
|
-
|
|
49
|
-
|
|
51
|
+
if (!force) {
|
|
52
|
+
// reduce the number of buffers in progress
|
|
53
|
+
buffersInProgress -= 1;
|
|
54
|
+
// if there are still some buffers going on
|
|
55
|
+
// then we don't flush now
|
|
56
|
+
if (buffersInProgress) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
50
60
|
const newData = makeBufferData();
|
|
51
61
|
const chatUpdates = Object.values(data.chatUpdates);
|
|
62
|
+
// gather the remaining conditional events so we re-queue them
|
|
52
63
|
let conditionalChatUpdatesLeft = 0;
|
|
53
64
|
for (const update of chatUpdates) {
|
|
54
65
|
if (update.conditional) {
|
|
@@ -76,14 +87,14 @@ export const makeEventBuffer = (logger) => {
|
|
|
76
87
|
};
|
|
77
88
|
},
|
|
78
89
|
emit(event, evData) {
|
|
79
|
-
if (
|
|
90
|
+
if (buffersInProgress && BUFFERABLE_EVENT_SET.has(event)) {
|
|
80
91
|
append(data, historyCache, event, evData, logger);
|
|
81
92
|
return true;
|
|
82
93
|
}
|
|
83
94
|
return ev.emit('event', { [event]: evData });
|
|
84
95
|
},
|
|
85
96
|
isBuffering() {
|
|
86
|
-
return
|
|
97
|
+
return buffersInProgress > 0;
|
|
87
98
|
},
|
|
88
99
|
buffer,
|
|
89
100
|
flush,
|
|
@@ -91,10 +102,11 @@ export const makeEventBuffer = (logger) => {
|
|
|
91
102
|
return async (...args) => {
|
|
92
103
|
buffer();
|
|
93
104
|
try {
|
|
94
|
-
|
|
105
|
+
const result = await work(...args);
|
|
106
|
+
return result;
|
|
95
107
|
}
|
|
96
108
|
finally {
|
|
97
|
-
|
|
109
|
+
flush();
|
|
98
110
|
}
|
|
99
111
|
};
|
|
100
112
|
},
|
|
@@ -103,6 +115,7 @@ export const makeEventBuffer = (logger) => {
|
|
|
103
115
|
removeAllListeners: (...args) => ev.removeAllListeners(...args)
|
|
104
116
|
};
|
|
105
117
|
};
|
|
118
|
+
exports.makeEventBuffer = makeEventBuffer;
|
|
106
119
|
const makeBufferData = () => {
|
|
107
120
|
return {
|
|
108
121
|
historySets: {
|
|
@@ -128,6 +141,7 @@ const makeBufferData = () => {
|
|
|
128
141
|
function append(data, historyCache, event,
|
|
129
142
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
130
143
|
eventData, logger) {
|
|
144
|
+
var _a, _b, _c;
|
|
131
145
|
switch (event) {
|
|
132
146
|
case 'messaging-history.set':
|
|
133
147
|
for (const chat of eventData.chats) {
|
|
@@ -144,7 +158,7 @@ eventData, logger) {
|
|
|
144
158
|
for (const contact of eventData.contacts) {
|
|
145
159
|
const existingContact = data.historySets.contacts[contact.id];
|
|
146
160
|
if (existingContact) {
|
|
147
|
-
Object.assign(existingContact, trimUndefined(contact));
|
|
161
|
+
Object.assign(existingContact, (0, generics_1.trimUndefined)(contact));
|
|
148
162
|
}
|
|
149
163
|
else {
|
|
150
164
|
const historyContactId = `c:${contact.id}`;
|
|
@@ -173,7 +187,7 @@ eventData, logger) {
|
|
|
173
187
|
for (const chat of eventData) {
|
|
174
188
|
let upsert = data.chatUpserts[chat.id];
|
|
175
189
|
if (!upsert) {
|
|
176
|
-
upsert = data.historySets
|
|
190
|
+
upsert = data.historySets[chat.id];
|
|
177
191
|
if (upsert) {
|
|
178
192
|
logger.debug({ chatId: chat.id }, 'absorbed chat upsert in chat set');
|
|
179
193
|
}
|
|
@@ -247,14 +261,14 @@ eventData, logger) {
|
|
|
247
261
|
}
|
|
248
262
|
}
|
|
249
263
|
if (upsert) {
|
|
250
|
-
upsert = Object.assign(upsert, trimUndefined(contact));
|
|
264
|
+
upsert = Object.assign(upsert, (0, generics_1.trimUndefined)(contact));
|
|
251
265
|
}
|
|
252
266
|
else {
|
|
253
267
|
upsert = contact;
|
|
254
268
|
data.contactUpserts[contact.id] = upsert;
|
|
255
269
|
}
|
|
256
270
|
if (data.contactUpdates[contact.id]) {
|
|
257
|
-
upsert = Object.assign(data.contactUpdates[contact.id], trimUndefined(contact));
|
|
271
|
+
upsert = Object.assign(data.contactUpdates[contact.id], (0, generics_1.trimUndefined)(contact));
|
|
258
272
|
delete data.contactUpdates[contact.id];
|
|
259
273
|
}
|
|
260
274
|
}
|
|
@@ -279,7 +293,7 @@ eventData, logger) {
|
|
|
279
293
|
const { messages, type } = eventData;
|
|
280
294
|
for (const message of messages) {
|
|
281
295
|
const key = stringifyMessageKey(message.key);
|
|
282
|
-
let existing = data.messageUpserts[key]
|
|
296
|
+
let existing = (_a = data.messageUpserts[key]) === null || _a === void 0 ? void 0 : _a.message;
|
|
283
297
|
if (!existing) {
|
|
284
298
|
existing = data.historySets.messages[key];
|
|
285
299
|
if (existing) {
|
|
@@ -300,7 +314,7 @@ eventData, logger) {
|
|
|
300
314
|
else {
|
|
301
315
|
data.messageUpserts[key] = {
|
|
302
316
|
message,
|
|
303
|
-
type: type === 'notify' || data.messageUpserts[key]
|
|
317
|
+
type: type === 'notify' || ((_b = data.messageUpserts[key]) === null || _b === void 0 ? void 0 : _b.type) === 'notify' ? 'notify' : type
|
|
304
318
|
};
|
|
305
319
|
}
|
|
306
320
|
}
|
|
@@ -309,13 +323,13 @@ eventData, logger) {
|
|
|
309
323
|
const msgUpdates = eventData;
|
|
310
324
|
for (const { key, update } of msgUpdates) {
|
|
311
325
|
const keyStr = stringifyMessageKey(key);
|
|
312
|
-
const existing = data.historySets.messages[keyStr] || data.messageUpserts[keyStr]
|
|
326
|
+
const existing = data.historySets.messages[keyStr] || ((_c = data.messageUpserts[keyStr]) === null || _c === void 0 ? void 0 : _c.message);
|
|
313
327
|
if (existing) {
|
|
314
328
|
Object.assign(existing, update);
|
|
315
329
|
// if the message was received & read by us
|
|
316
330
|
// the chat counter must have been incremented
|
|
317
331
|
// so we need to decrement it
|
|
318
|
-
if (update.status === WAMessageStatus.READ && !key.fromMe) {
|
|
332
|
+
if (update.status === Types_1.WAMessageStatus.READ && !key.fromMe) {
|
|
319
333
|
decrementChatReadCounterIfMsgDidUnread(existing);
|
|
320
334
|
}
|
|
321
335
|
}
|
|
@@ -353,11 +367,11 @@ eventData, logger) {
|
|
|
353
367
|
const keyStr = stringifyMessageKey(key);
|
|
354
368
|
const existing = data.messageUpserts[keyStr];
|
|
355
369
|
if (existing) {
|
|
356
|
-
updateMessageWithReaction(existing.message, reaction);
|
|
370
|
+
(0, messages_1.updateMessageWithReaction)(existing.message, reaction);
|
|
357
371
|
}
|
|
358
372
|
else {
|
|
359
373
|
data.messageReactions[keyStr] = data.messageReactions[keyStr] || { key, reactions: [] };
|
|
360
|
-
updateMessageWithReaction(data.messageReactions[keyStr], reaction);
|
|
374
|
+
(0, messages_1.updateMessageWithReaction)(data.messageReactions[keyStr], reaction);
|
|
361
375
|
}
|
|
362
376
|
}
|
|
363
377
|
break;
|
|
@@ -367,11 +381,11 @@ eventData, logger) {
|
|
|
367
381
|
const keyStr = stringifyMessageKey(key);
|
|
368
382
|
const existing = data.messageUpserts[keyStr];
|
|
369
383
|
if (existing) {
|
|
370
|
-
updateMessageWithReceipt(existing.message, receipt);
|
|
384
|
+
(0, messages_1.updateMessageWithReceipt)(existing.message, receipt);
|
|
371
385
|
}
|
|
372
386
|
else {
|
|
373
387
|
data.messageReceipts[keyStr] = data.messageReceipts[keyStr] || { key, userReceipt: [] };
|
|
374
|
-
updateMessageWithReceipt(data.messageReceipts[keyStr], receipt);
|
|
388
|
+
(0, messages_1.updateMessageWithReceipt)(data.messageReceipts[keyStr], receipt);
|
|
375
389
|
}
|
|
376
390
|
}
|
|
377
391
|
break;
|
|
@@ -410,9 +424,9 @@ eventData, logger) {
|
|
|
410
424
|
// if the message has already been marked read by us
|
|
411
425
|
const chatId = message.key.remoteJid;
|
|
412
426
|
const chat = data.chatUpdates[chatId] || data.chatUpserts[chatId];
|
|
413
|
-
if (isRealMessage(message, '') &&
|
|
414
|
-
shouldIncrementChatUnread(message) &&
|
|
415
|
-
typeof chat
|
|
427
|
+
if ((0, process_message_1.isRealMessage)(message, '') &&
|
|
428
|
+
(0, process_message_1.shouldIncrementChatUnread)(message) &&
|
|
429
|
+
typeof (chat === null || chat === void 0 ? void 0 : chat.unreadCount) === 'number' &&
|
|
416
430
|
chat.unreadCount > 0) {
|
|
417
431
|
logger.debug({ chatId: chat.id }, 'decrementing chat counter');
|
|
418
432
|
chat.unreadCount -= 1;
|
|
@@ -500,4 +514,3 @@ function concatChats(a, b) {
|
|
|
500
514
|
return Object.assign(a, b);
|
|
501
515
|
}
|
|
502
516
|
const stringifyMessageKey = (key) => `${key.remoteJid},${key.id},${key.fromMe ? '1' : '0'}`;
|
|
503
|
-
//# sourceMappingURL=event-buffer.js.map
|