@queenanya/baileys 7.5.11 → 8.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (157) hide show
  1. package/package.json +13 -97
  2. package/LICENSE +0 -21
  3. package/README.md +0 -931
  4. package/WAProto/GenerateStatics.sh +0 -4
  5. package/WAProto/WAProto.proto +0 -3344
  6. package/WAProto/index.d.ts +0 -37016
  7. package/WAProto/index.js +0 -101044
  8. package/WASignalGroup/GroupProtocol.js +0 -1697
  9. package/WASignalGroup/ciphertext_message.js +0 -16
  10. package/WASignalGroup/group_cipher.js +0 -120
  11. package/WASignalGroup/group_session_builder.js +0 -46
  12. package/WASignalGroup/index.js +0 -5
  13. package/WASignalGroup/keyhelper.js +0 -21
  14. package/WASignalGroup/protobufs.js +0 -3
  15. package/WASignalGroup/queue_job.js +0 -69
  16. package/WASignalGroup/sender_chain_key.js +0 -50
  17. package/WASignalGroup/sender_key_distribution_message.js +0 -78
  18. package/WASignalGroup/sender_key_message.js +0 -92
  19. package/WASignalGroup/sender_key_name.js +0 -70
  20. package/WASignalGroup/sender_key_record.js +0 -56
  21. package/WASignalGroup/sender_key_state.js +0 -129
  22. package/WASignalGroup/sender_message_key.js +0 -39
  23. package/lib/Defaults/baileys-version.json +0 -3
  24. package/lib/Defaults/index.d.ts +0 -53
  25. package/lib/Defaults/index.js +0 -107
  26. package/lib/Signal/libsignal.d.ts +0 -3
  27. package/lib/Signal/libsignal.js +0 -152
  28. package/lib/Socket/Client/index.d.ts +0 -2
  29. package/lib/Socket/Client/index.js +0 -18
  30. package/lib/Socket/Client/types.d.ts +0 -17
  31. package/lib/Socket/Client/types.js +0 -13
  32. package/lib/Socket/Client/websocket.d.ts +0 -12
  33. package/lib/Socket/Client/websocket.js +0 -62
  34. package/lib/Socket/business.d.ts +0 -177
  35. package/lib/Socket/business.js +0 -260
  36. package/lib/Socket/chats.d.ts +0 -91
  37. package/lib/Socket/chats.js +0 -949
  38. package/lib/Socket/groups.d.ts +0 -131
  39. package/lib/Socket/groups.js +0 -314
  40. package/lib/Socket/index.d.ts +0 -177
  41. package/lib/Socket/index.js +0 -10
  42. package/lib/Socket/messages-recv.d.ts +0 -164
  43. package/lib/Socket/messages-recv.js +0 -918
  44. package/lib/Socket/messages-send.d.ts +0 -157
  45. package/lib/Socket/messages-send.js +0 -794
  46. package/lib/Socket/newsletter.d.ts +0 -143
  47. package/lib/Socket/newsletter.js +0 -249
  48. package/lib/Socket/socket.d.ts +0 -45
  49. package/lib/Socket/socket.js +0 -616
  50. package/lib/Store/index.d.ts +0 -3
  51. package/lib/Store/index.js +0 -10
  52. package/lib/Store/make-cache-manager-store.d.ts +0 -14
  53. package/lib/Store/make-cache-manager-store.js +0 -83
  54. package/lib/Store/make-in-memory-store.d.ts +0 -118
  55. package/lib/Store/make-in-memory-store.js +0 -420
  56. package/lib/Store/make-ordered-dictionary.d.ts +0 -13
  57. package/lib/Store/make-ordered-dictionary.js +0 -81
  58. package/lib/Store/object-repository.d.ts +0 -10
  59. package/lib/Store/object-repository.js +0 -27
  60. package/lib/Types/Auth.d.ts +0 -105
  61. package/lib/Types/Auth.js +0 -2
  62. package/lib/Types/Call.d.ts +0 -13
  63. package/lib/Types/Call.js +0 -2
  64. package/lib/Types/Chat.d.ts +0 -107
  65. package/lib/Types/Chat.js +0 -4
  66. package/lib/Types/Contact.d.ts +0 -19
  67. package/lib/Types/Contact.js +0 -2
  68. package/lib/Types/Events.d.ts +0 -199
  69. package/lib/Types/Events.js +0 -2
  70. package/lib/Types/GroupMetadata.d.ts +0 -56
  71. package/lib/Types/GroupMetadata.js +0 -2
  72. package/lib/Types/Label.d.ts +0 -46
  73. package/lib/Types/Label.js +0 -27
  74. package/lib/Types/LabelAssociation.d.ts +0 -29
  75. package/lib/Types/LabelAssociation.js +0 -9
  76. package/lib/Types/Message.d.ts +0 -280
  77. package/lib/Types/Message.js +0 -9
  78. package/lib/Types/Newsletter.d.ts +0 -79
  79. package/lib/Types/Newsletter.js +0 -18
  80. package/lib/Types/Product.d.ts +0 -78
  81. package/lib/Types/Product.js +0 -2
  82. package/lib/Types/Signal.d.ts +0 -57
  83. package/lib/Types/Signal.js +0 -2
  84. package/lib/Types/Socket.d.ts +0 -118
  85. package/lib/Types/Socket.js +0 -2
  86. package/lib/Types/State.d.ts +0 -27
  87. package/lib/Types/State.js +0 -2
  88. package/lib/Types/index.d.ts +0 -65
  89. package/lib/Types/index.js +0 -42
  90. package/lib/Utils/auth-utils.d.ts +0 -18
  91. package/lib/Utils/auth-utils.js +0 -200
  92. package/lib/Utils/baileys-event-stream.d.ts +0 -16
  93. package/lib/Utils/baileys-event-stream.js +0 -63
  94. package/lib/Utils/business.d.ts +0 -22
  95. package/lib/Utils/business.js +0 -234
  96. package/lib/Utils/chat-utils.d.ts +0 -72
  97. package/lib/Utils/chat-utils.js +0 -745
  98. package/lib/Utils/crypto.d.ts +0 -42
  99. package/lib/Utils/crypto.js +0 -153
  100. package/lib/Utils/decode-wa-message.d.ts +0 -20
  101. package/lib/Utils/decode-wa-message.js +0 -218
  102. package/lib/Utils/event-buffer.d.ts +0 -35
  103. package/lib/Utils/event-buffer.js +0 -520
  104. package/lib/Utils/generics.d.ts +0 -119
  105. package/lib/Utils/generics.js +0 -467
  106. package/lib/Utils/history.d.ts +0 -19
  107. package/lib/Utils/history.js +0 -94
  108. package/lib/Utils/index.d.ts +0 -18
  109. package/lib/Utils/index.js +0 -34
  110. package/lib/Utils/link-preview.d.ts +0 -21
  111. package/lib/Utils/link-preview.js +0 -116
  112. package/lib/Utils/logger.d.ts +0 -2
  113. package/lib/Utils/logger.js +0 -7
  114. package/lib/Utils/lt-hash.d.ts +0 -12
  115. package/lib/Utils/lt-hash.js +0 -51
  116. package/lib/Utils/make-mutex.d.ts +0 -7
  117. package/lib/Utils/make-mutex.js +0 -44
  118. package/lib/Utils/messages-media.d.ts +0 -131
  119. package/lib/Utils/messages-media.js +0 -786
  120. package/lib/Utils/messages.d.ts +0 -78
  121. package/lib/Utils/messages.js +0 -767
  122. package/lib/Utils/noise-handler.d.ts +0 -21
  123. package/lib/Utils/noise-handler.js +0 -150
  124. package/lib/Utils/process-message.d.ts +0 -42
  125. package/lib/Utils/process-message.js +0 -355
  126. package/lib/Utils/signal.d.ts +0 -32
  127. package/lib/Utils/signal.js +0 -158
  128. package/lib/Utils/use-multi-file-auth-state.d.ts +0 -12
  129. package/lib/Utils/use-multi-file-auth-state.js +0 -94
  130. package/lib/Utils/use-single-file-auth-state.d.ts +0 -5
  131. package/lib/Utils/use-single-file-auth-state.js +0 -66
  132. package/lib/Utils/validate-connection.d.ts +0 -10
  133. package/lib/Utils/validate-connection.js +0 -171
  134. package/lib/WABinary/constants.d.ts +0 -27
  135. package/lib/WABinary/constants.js +0 -40
  136. package/lib/WABinary/decode.d.ts +0 -8
  137. package/lib/WABinary/decode.js +0 -254
  138. package/lib/WABinary/encode.d.ts +0 -2
  139. package/lib/WABinary/encode.js +0 -230
  140. package/lib/WABinary/generic-utils.d.ts +0 -16
  141. package/lib/WABinary/generic-utils.js +0 -110
  142. package/lib/WABinary/index.d.ts +0 -5
  143. package/lib/WABinary/index.js +0 -21
  144. package/lib/WABinary/jid-utils.d.ts +0 -31
  145. package/lib/WABinary/jid-utils.js +0 -62
  146. package/lib/WABinary/types.d.ts +0 -18
  147. package/lib/WABinary/types.js +0 -2
  148. package/lib/WAM/BinaryInfo.d.ts +0 -18
  149. package/lib/WAM/BinaryInfo.js +0 -13
  150. package/lib/WAM/constants.d.ts +0 -39
  151. package/lib/WAM/constants.js +0 -15350
  152. package/lib/WAM/encode.d.ts +0 -4
  153. package/lib/WAM/encode.js +0 -155
  154. package/lib/WAM/index.d.ts +0 -3
  155. package/lib/WAM/index.js +0 -19
  156. package/lib/index.d.ts +0 -11
  157. package/lib/index.js +0 -30
@@ -1,42 +0,0 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- import { KeyPair } from '../Types';
4
- /** prefix version byte to the pub keys, required for some curve crypto functions */
5
- export declare const generateSignalPubKey: (pubKey: Uint8Array | Buffer) => Uint8Array | Buffer;
6
- export declare const Curve: {
7
- generateKeyPair: () => KeyPair;
8
- sharedKey: (privateKey: Uint8Array, publicKey: Uint8Array) => Buffer;
9
- sign: (privateKey: Uint8Array, buf: Uint8Array) => any;
10
- verify: (pubKey: Uint8Array, message: Uint8Array, signature: Uint8Array) => boolean;
11
- };
12
- export declare const signedKeyPair: (identityKeyPair: KeyPair, keyId: number) => {
13
- keyPair: KeyPair;
14
- signature: any;
15
- keyId: number;
16
- };
17
- /**
18
- * encrypt AES 256 GCM;
19
- * where the tag tag is suffixed to the ciphertext
20
- * */
21
- export declare function aesEncryptGCM(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array): Buffer;
22
- /**
23
- * decrypt AES 256 GCM;
24
- * where the auth tag is suffixed to the ciphertext
25
- * */
26
- export declare function aesDecryptGCM(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array): Buffer;
27
- export declare function aesEncryptCTR(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array): Buffer;
28
- export declare function aesDecryptCTR(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array): Buffer;
29
- /** decrypt AES 256 CBC; where the IV is prefixed to the buffer */
30
- export declare function aesDecrypt(buffer: Buffer, key: Buffer): Buffer;
31
- /** decrypt AES 256 CBC */
32
- export declare function aesDecryptWithIV(buffer: Buffer, key: Buffer, IV: Buffer): Buffer;
33
- export declare function aesEncrypt(buffer: Buffer | Uint8Array, key: Buffer): Buffer;
34
- export declare function aesEncrypWithIV(buffer: Buffer, key: Buffer, IV: Buffer): Buffer;
35
- export declare function hmacSign(buffer: Buffer | Uint8Array, key: Buffer | Uint8Array, variant?: 'sha256' | 'sha512'): Buffer;
36
- export declare function sha256(buffer: Buffer): Buffer;
37
- export declare function md5(buffer: Buffer): Buffer;
38
- export declare function hkdf(buffer: Uint8Array | Buffer, expandedLength: number, info: {
39
- salt?: Buffer;
40
- info?: string;
41
- }): Buffer;
42
- export declare function derivePairingCodeKey(pairingCode: string, salt: Buffer): Promise<Buffer>;
@@ -1,153 +0,0 @@
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 (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.derivePairingCodeKey = exports.hkdf = exports.md5 = exports.sha256 = exports.hmacSign = exports.aesEncrypWithIV = exports.aesEncrypt = exports.aesDecryptWithIV = exports.aesDecrypt = exports.aesDecryptCTR = exports.aesEncryptCTR = exports.aesDecryptGCM = exports.aesEncryptGCM = exports.signedKeyPair = exports.Curve = exports.generateSignalPubKey = void 0;
30
- const crypto_1 = require("crypto");
31
- const futoin_hkdf_1 = __importDefault(require("futoin-hkdf"));
32
- const libsignal = __importStar(require("libsignal"));
33
- const util_1 = require("util");
34
- const Defaults_1 = require("../Defaults");
35
- const pbkdf2Promise = (0, util_1.promisify)(crypto_1.pbkdf2);
36
- /** prefix version byte to the pub keys, required for some curve crypto functions */
37
- const generateSignalPubKey = (pubKey) => (pubKey.length === 33
38
- ? pubKey
39
- : Buffer.concat([Defaults_1.KEY_BUNDLE_TYPE, pubKey]));
40
- exports.generateSignalPubKey = generateSignalPubKey;
41
- exports.Curve = {
42
- generateKeyPair: () => {
43
- const { pubKey, privKey } = libsignal.curve.generateKeyPair();
44
- return {
45
- private: Buffer.from(privKey),
46
- // remove version byte
47
- public: Buffer.from(pubKey.slice(1))
48
- };
49
- },
50
- sharedKey: (privateKey, publicKey) => {
51
- const shared = libsignal.curve.calculateAgreement((0, exports.generateSignalPubKey)(publicKey), privateKey);
52
- return Buffer.from(shared);
53
- },
54
- sign: (privateKey, buf) => (libsignal.curve.calculateSignature(privateKey, buf)),
55
- verify: (pubKey, message, signature) => {
56
- try {
57
- libsignal.curve.verifySignature((0, exports.generateSignalPubKey)(pubKey), message, signature);
58
- return true;
59
- }
60
- catch (error) {
61
- return false;
62
- }
63
- }
64
- };
65
- const signedKeyPair = (identityKeyPair, keyId) => {
66
- const preKey = exports.Curve.generateKeyPair();
67
- const pubKey = (0, exports.generateSignalPubKey)(preKey.public);
68
- const signature = exports.Curve.sign(identityKeyPair.private, pubKey);
69
- return { keyPair: preKey, signature, keyId };
70
- };
71
- exports.signedKeyPair = signedKeyPair;
72
- const GCM_TAG_LENGTH = 128 >> 3;
73
- /**
74
- * encrypt AES 256 GCM;
75
- * where the tag tag is suffixed to the ciphertext
76
- * */
77
- function aesEncryptGCM(plaintext, key, iv, additionalData) {
78
- const cipher = (0, crypto_1.createCipheriv)('aes-256-gcm', key, iv);
79
- cipher.setAAD(additionalData);
80
- return Buffer.concat([cipher.update(plaintext), cipher.final(), cipher.getAuthTag()]);
81
- }
82
- exports.aesEncryptGCM = aesEncryptGCM;
83
- /**
84
- * decrypt AES 256 GCM;
85
- * where the auth tag is suffixed to the ciphertext
86
- * */
87
- function aesDecryptGCM(ciphertext, key, iv, additionalData) {
88
- const decipher = (0, crypto_1.createDecipheriv)('aes-256-gcm', key, iv);
89
- // decrypt additional adata
90
- const enc = ciphertext.slice(0, ciphertext.length - GCM_TAG_LENGTH);
91
- const tag = ciphertext.slice(ciphertext.length - GCM_TAG_LENGTH);
92
- // set additional data
93
- decipher.setAAD(additionalData);
94
- decipher.setAuthTag(tag);
95
- return Buffer.concat([decipher.update(enc), decipher.final()]);
96
- }
97
- exports.aesDecryptGCM = aesDecryptGCM;
98
- function aesEncryptCTR(plaintext, key, iv) {
99
- const cipher = (0, crypto_1.createCipheriv)('aes-256-ctr', key, iv);
100
- return Buffer.concat([cipher.update(plaintext), cipher.final()]);
101
- }
102
- exports.aesEncryptCTR = aesEncryptCTR;
103
- function aesDecryptCTR(ciphertext, key, iv) {
104
- const decipher = (0, crypto_1.createDecipheriv)('aes-256-ctr', key, iv);
105
- return Buffer.concat([decipher.update(ciphertext), decipher.final()]);
106
- }
107
- exports.aesDecryptCTR = aesDecryptCTR;
108
- /** decrypt AES 256 CBC; where the IV is prefixed to the buffer */
109
- function aesDecrypt(buffer, key) {
110
- return aesDecryptWithIV(buffer.slice(16, buffer.length), key, buffer.slice(0, 16));
111
- }
112
- exports.aesDecrypt = aesDecrypt;
113
- /** decrypt AES 256 CBC */
114
- function aesDecryptWithIV(buffer, key, IV) {
115
- const aes = (0, crypto_1.createDecipheriv)('aes-256-cbc', key, IV);
116
- return Buffer.concat([aes.update(buffer), aes.final()]);
117
- }
118
- exports.aesDecryptWithIV = aesDecryptWithIV;
119
- // encrypt AES 256 CBC; where a random IV is prefixed to the buffer
120
- function aesEncrypt(buffer, key) {
121
- const IV = (0, crypto_1.randomBytes)(16);
122
- const aes = (0, crypto_1.createCipheriv)('aes-256-cbc', key, IV);
123
- return Buffer.concat([IV, aes.update(buffer), aes.final()]); // prefix IV to the buffer
124
- }
125
- exports.aesEncrypt = aesEncrypt;
126
- // encrypt AES 256 CBC with a given IV
127
- function aesEncrypWithIV(buffer, key, IV) {
128
- const aes = (0, crypto_1.createCipheriv)('aes-256-cbc', key, IV);
129
- return Buffer.concat([aes.update(buffer), aes.final()]); // prefix IV to the buffer
130
- }
131
- exports.aesEncrypWithIV = aesEncrypWithIV;
132
- // sign HMAC using SHA 256
133
- function hmacSign(buffer, key, variant = 'sha256') {
134
- return (0, crypto_1.createHmac)(variant, key).update(buffer).digest();
135
- }
136
- exports.hmacSign = hmacSign;
137
- function sha256(buffer) {
138
- return (0, crypto_1.createHash)('sha256').update(buffer).digest();
139
- }
140
- exports.sha256 = sha256;
141
- function md5(buffer) {
142
- return (0, crypto_1.createHash)('md5').update(buffer).digest();
143
- }
144
- exports.md5 = md5;
145
- // HKDF key expansion
146
- function hkdf(buffer, expandedLength, info) {
147
- return (0, futoin_hkdf_1.default)(!Buffer.isBuffer(buffer) ? Buffer.from(buffer) : buffer, expandedLength, info);
148
- }
149
- exports.hkdf = hkdf;
150
- async function derivePairingCodeKey(pairingCode, salt) {
151
- return await pbkdf2Promise(pairingCode, salt, 2 << 16, 32, 'sha256');
152
- }
153
- exports.derivePairingCodeKey = derivePairingCodeKey;
@@ -1,20 +0,0 @@
1
- import { Logger } from 'pino';
2
- import { proto } from '../../WAProto';
3
- import { SignalRepository } from '../Types';
4
- import { BinaryNode } from '../WABinary';
5
- export declare const NO_MESSAGE_FOUND_ERROR_TEXT = "Message absent from node";
6
- /**
7
- * Decode the received node as a message.
8
- * @note this will only parse the message, not decrypt it
9
- */
10
- export declare function decodeMessageNode(stanza: BinaryNode, meId: string, meLid: string): {
11
- fullMessage: proto.IWebMessageInfo;
12
- author: string;
13
- sender: string;
14
- };
15
- export declare const decryptMessageNode: (stanza: BinaryNode, meId: string, meLid: string, repository: SignalRepository, logger: Logger) => {
16
- fullMessage: proto.IWebMessageInfo;
17
- category: string;
18
- author: string;
19
- decrypt(): Promise<void>;
20
- };
@@ -1,218 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.decryptMessageNode = exports.decodeMessageNode = exports.NO_MESSAGE_FOUND_ERROR_TEXT = void 0;
4
- const boom_1 = require("@hapi/boom");
5
- const WAProto_1 = require("../../WAProto");
6
- const WABinary_1 = require("../WABinary");
7
- const generics_1 = require("./generics");
8
- exports.NO_MESSAGE_FOUND_ERROR_TEXT = 'Message absent from node';
9
- /**
10
- * Decode the received node as a message.
11
- * @note this will only parse the message, not decrypt it
12
- */
13
- function decodeMessageNode(stanza, meId, meLid) {
14
- var _a, _b, _c, _d;
15
- let msgType;
16
- let chatId;
17
- let author;
18
- const msgId = stanza.attrs.id;
19
- const from = stanza.attrs.from;
20
- const participant = stanza.attrs.participant;
21
- const recipient = stanza.attrs.recipient;
22
- const isMe = (jid) => (0, WABinary_1.areJidsSameUser)(jid, meId);
23
- const isMeLid = (jid) => (0, WABinary_1.areJidsSameUser)(jid, meLid);
24
- if ((0, WABinary_1.isJidUser)(from)) {
25
- if (recipient) {
26
- if (!isMe(from)) {
27
- throw new boom_1.Boom('receipient present, but msg not from me', { data: stanza });
28
- }
29
- chatId = recipient;
30
- }
31
- else {
32
- chatId = from;
33
- }
34
- msgType = 'chat';
35
- author = from;
36
- }
37
- else if ((0, WABinary_1.isLidUser)(from)) {
38
- if (recipient) {
39
- if (!isMeLid(from)) {
40
- throw new boom_1.Boom('receipient present, but msg not from me', { data: stanza });
41
- }
42
- chatId = recipient;
43
- }
44
- else {
45
- chatId = from;
46
- }
47
- msgType = 'chat';
48
- author = from;
49
- }
50
- else if ((0, WABinary_1.isJidGroup)(from)) {
51
- if (!participant) {
52
- throw new boom_1.Boom('No participant in group message');
53
- }
54
- msgType = 'group';
55
- author = participant;
56
- chatId = from;
57
- }
58
- else if ((0, WABinary_1.isJidNewsletter)(from)) {
59
- msgType = 'newsletter';
60
- author = from;
61
- chatId = from;
62
- }
63
- else if ((0, WABinary_1.isJidBroadcast)(from)) {
64
- if (!participant) {
65
- throw new boom_1.Boom('No participant in group message');
66
- }
67
- const isParticipantMe = isMe(participant);
68
- if ((0, WABinary_1.isJidStatusBroadcast)(from)) {
69
- msgType = isParticipantMe ? 'direct_peer_status' : 'other_status';
70
- }
71
- else {
72
- msgType = isParticipantMe ? 'peer_broadcast' : 'other_broadcast';
73
- }
74
- chatId = from;
75
- author = participant;
76
- }
77
- else if ((0, WABinary_1.isJidNewsletter)(from)) {
78
- msgType = 'newsletter';
79
- author = from;
80
- chatId = from;
81
- }
82
- else {
83
- throw new boom_1.Boom('Unknown message type', { data: stanza });
84
- }
85
- const fromMe = (0, WABinary_1.isJidNewsletter)(from) ? !!((_a = stanza.attrs) === null || _a === void 0 ? void 0 : _a.is_sender) || false : ((0, WABinary_1.isLidUser)(from) ? isMeLid : isMe)(stanza.attrs.participant || stanza.attrs.from);
86
- const pushname = (_b = stanza === null || stanza === void 0 ? void 0 : stanza.attrs) === null || _b === void 0 ? void 0 : _b.notify;
87
- const key = {
88
- remoteJid: chatId,
89
- fromMe,
90
- id: msgId,
91
- participant,
92
- server_id: (_c = stanza.attrs) === null || _c === void 0 ? void 0 : _c.server_id
93
- };
94
- const fullMessage = {
95
- key,
96
- messageTimestamp: +stanza.attrs.t,
97
- pushName: pushname,
98
- broadcast: (0, WABinary_1.isJidBroadcast)(from)
99
- };
100
- if (msgType === 'newsletter') {
101
- fullMessage.newsletterServerId = +((_d = stanza.attrs) === null || _d === void 0 ? void 0 : _d.server_id);
102
- }
103
- if (key.fromMe) {
104
- fullMessage.status = WAProto_1.proto.WebMessageInfo.Status.SERVER_ACK;
105
- }
106
- return {
107
- fullMessage,
108
- author,
109
- sender: msgType === 'chat' ? author : chatId
110
- };
111
- }
112
- exports.decodeMessageNode = decodeMessageNode;
113
- const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
114
- const { fullMessage, author, sender } = decodeMessageNode(stanza, meId, meLid);
115
- return {
116
- fullMessage,
117
- category: stanza.attrs.category,
118
- author,
119
- async decrypt() {
120
- var _a;
121
- let decryptables = 0;
122
- async function processSenderKeyDistribution(msg) {
123
- if (msg.senderKeyDistributionMessage) {
124
- try {
125
- await repository.processSenderKeyDistributionMessage({
126
- authorJid: author,
127
- item: msg.senderKeyDistributionMessage
128
- });
129
- }
130
- catch (err) {
131
- logger.error({ key: fullMessage.key, err }, 'failed to process senderKeyDistribution');
132
- }
133
- }
134
- }
135
- if ((0, WABinary_1.isJidNewsletter)(fullMessage.key.remoteJid)) {
136
- const node = (0, WABinary_1.getBinaryNodeChild)(stanza, 'plaintext');
137
- const msg = WAProto_1.proto.Message.decode(node === null || node === void 0 ? void 0 : node.content);
138
- await processSenderKeyDistribution(msg);
139
- fullMessage.message = msg;
140
- decryptables += 1;
141
- }
142
- else if (Array.isArray(stanza.content)) {
143
- for (const { tag, attrs, content } of stanza.content) {
144
- if (tag === 'verified_name' && content instanceof Uint8Array) {
145
- const cert = WAProto_1.proto.VerifiedNameCertificate.decode(content);
146
- const details = WAProto_1.proto.VerifiedNameCertificate.Details.decode(cert.details);
147
- fullMessage.verifiedBizName = details.verifiedName;
148
- }
149
- if (tag !== 'enc' && tag !== 'plaintext') {
150
- continue;
151
- }
152
- if (!(content instanceof Uint8Array)) {
153
- continue;
154
- }
155
- decryptables += 1;
156
- let msgBuffer;
157
- try {
158
- const e2eType = tag === 'plaintext' ? 'plaintext' : attrs.type;
159
- switch (e2eType) {
160
- case 'skmsg':
161
- msgBuffer = await repository.decryptGroupMessage({
162
- group: sender,
163
- authorJid: author,
164
- msg: content
165
- });
166
- break;
167
- case 'pkmsg':
168
- case 'msg':
169
- const user = (0, WABinary_1.isJidUser)(sender) ? sender : author;
170
- msgBuffer = await repository.decryptMessage({
171
- jid: user,
172
- type: e2eType,
173
- ciphertext: content
174
- });
175
- break;
176
- case 'plaintext':
177
- msgBuffer = content;
178
- break;
179
- default:
180
- throw new Error(`Unknown e2e type: ${e2eType}`);
181
- }
182
- let msg = WAProto_1.proto.Message.decode(e2eType !== 'plaintext' ? (0, generics_1.unpadRandomMax16)(msgBuffer) : msgBuffer);
183
- msg = ((_a = msg.deviceSentMessage) === null || _a === void 0 ? void 0 : _a.message) || msg;
184
- if (msg.senderKeyDistributionMessage) {
185
- //eslint-disable-next-line max-depth
186
- try {
187
- await repository.processSenderKeyDistributionMessage({
188
- authorJid: author,
189
- item: msg.senderKeyDistributionMessage
190
- });
191
- }
192
- catch (err) {
193
- logger.error({ key: fullMessage.key, err }, 'failed to decrypt message');
194
- }
195
- }
196
- if (fullMessage.message) {
197
- Object.assign(fullMessage.message, msg);
198
- }
199
- else {
200
- fullMessage.message = msg;
201
- }
202
- }
203
- catch (err) {
204
- logger.error({ key: fullMessage.key, err }, 'failed to decrypt message');
205
- fullMessage.messageStubType = WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT;
206
- fullMessage.messageStubParameters = [err.message];
207
- }
208
- }
209
- }
210
- // if nothing was found to decrypt
211
- if (!decryptables) {
212
- fullMessage.messageStubType = WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT;
213
- fullMessage.messageStubParameters = [exports.NO_MESSAGE_FOUND_ERROR_TEXT];
214
- }
215
- }
216
- };
217
- };
218
- exports.decryptMessageNode = decryptMessageNode;
@@ -1,35 +0,0 @@
1
- import { Logger } from 'pino';
2
- import { BaileysEventEmitter, BaileysEventMap } from '../Types';
3
- /**
4
- * A map that contains a list of all events that have been triggered
5
- *
6
- * Note, this can contain different type of events
7
- * this can make processing events extremely efficient -- since everything
8
- * can be done in a single transaction
9
- */
10
- type BaileysEventData = Partial<BaileysEventMap>;
11
- type BaileysBufferableEventEmitter = BaileysEventEmitter & {
12
- /** Use to process events in a batch */
13
- process(handler: (events: BaileysEventData) => void | Promise<void>): (() => void);
14
- /**
15
- * starts buffering events, call flush() to release them
16
- * */
17
- buffer(): void;
18
- /** buffers all events till the promise completes */
19
- createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): ((...args: A) => Promise<T>);
20
- /**
21
- * flushes all buffered events
22
- * @param force if true, will flush all data regardless of any pending buffers
23
- * @returns returns true if the flush actually happened, otherwise false
24
- */
25
- flush(force?: boolean): boolean;
26
- /** is there an ongoing buffer */
27
- isBuffering(): boolean;
28
- };
29
- /**
30
- * The event buffer logically consolidates different events into a single event
31
- * making the data processing more efficient.
32
- * @param ev the baileys event emitter
33
- */
34
- export declare const makeEventBuffer: (logger: Logger) => BaileysBufferableEventEmitter;
35
- export {};