@vanzxy/baileys 1.4.8 → 1.5.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.

Potentially problematic release.


This version of @vanzxy/baileys might be problematic. Click here for more details.

Files changed (113) hide show
  1. package/README.md +10 -0
  2. package/lib/Utils/MessageBuilder.js +56 -28
  3. package/package.json +3 -5
  4. package/cjs/WAProto/index.js +0 -106053
  5. package/cjs/lib/Defaults/index.js +0 -168
  6. package/cjs/lib/Signal/Group/ciphertext-message.js +0 -16
  7. package/cjs/lib/Signal/Group/group-session-builder.js +0 -67
  8. package/cjs/lib/Signal/Group/group_cipher.js +0 -86
  9. package/cjs/lib/Signal/Group/index.js +0 -58
  10. package/cjs/lib/Signal/Group/keyhelper.js +0 -56
  11. package/cjs/lib/Signal/Group/sender-chain-key.js +0 -30
  12. package/cjs/lib/Signal/Group/sender-key-distribution-message.js +0 -67
  13. package/cjs/lib/Signal/Group/sender-key-message.js +0 -70
  14. package/cjs/lib/Signal/Group/sender-key-name.js +0 -52
  15. package/cjs/lib/Signal/Group/sender-key-record.js +0 -45
  16. package/cjs/lib/Signal/Group/sender-key-state.js +0 -88
  17. package/cjs/lib/Signal/Group/sender-message-key.js +0 -30
  18. package/cjs/lib/Signal/libsignal.js +0 -467
  19. package/cjs/lib/Signal/lid-mapping.js +0 -281
  20. package/cjs/lib/Socket/Client/index.js +0 -19
  21. package/cjs/lib/Socket/Client/types.js +0 -15
  22. package/cjs/lib/Socket/Client/websocket.js +0 -61
  23. package/cjs/lib/Socket/business.js +0 -384
  24. package/cjs/lib/Socket/chats.js +0 -1257
  25. package/cjs/lib/Socket/communities.js +0 -442
  26. package/cjs/lib/Socket/dugong.js +0 -753
  27. package/cjs/lib/Socket/groups.js +0 -360
  28. package/cjs/lib/Socket/index.js +0 -30
  29. package/cjs/lib/Socket/messages-recv.js +0 -1790
  30. package/cjs/lib/Socket/messages-send.js +0 -1390
  31. package/cjs/lib/Socket/mex.js +0 -46
  32. package/cjs/lib/Socket/newsletter.js +0 -340
  33. package/cjs/lib/Socket/socket.js +0 -1007
  34. package/cjs/lib/Store/index.js +0 -20
  35. package/cjs/lib/Store/make-in-memory-store.js +0 -438
  36. package/cjs/lib/Store/make-ordered-dictionary.js +0 -82
  37. package/cjs/lib/Store/object-repository.js +0 -28
  38. package/cjs/lib/Types/Auth.js +0 -3
  39. package/cjs/lib/Types/Bussines.js +0 -3
  40. package/cjs/lib/Types/Call.js +0 -3
  41. package/cjs/lib/Types/Chat.js +0 -11
  42. package/cjs/lib/Types/Contact.js +0 -3
  43. package/cjs/lib/Types/Events.js +0 -4
  44. package/cjs/lib/Types/GroupMetadata.js +0 -3
  45. package/cjs/lib/Types/Label.js +0 -26
  46. package/cjs/lib/Types/LabelAssociation.js +0 -8
  47. package/cjs/lib/Types/Message.js +0 -19
  48. package/cjs/lib/Types/Mex.js +0 -40
  49. package/cjs/lib/Types/Product.js +0 -3
  50. package/cjs/lib/Types/RichType.js +0 -24
  51. package/cjs/lib/Types/Signal.js +0 -4
  52. package/cjs/lib/Types/Socket.js +0 -4
  53. package/cjs/lib/Types/State.js +0 -54
  54. package/cjs/lib/Types/USync.js +0 -4
  55. package/cjs/lib/Types/index.js +0 -42
  56. package/cjs/lib/Utils/MessageBuilder.js +0 -2684
  57. package/cjs/lib/Utils/auth-utils.js +0 -312
  58. package/cjs/lib/Utils/browser-utils.js +0 -32
  59. package/cjs/lib/Utils/business.js +0 -245
  60. package/cjs/lib/Utils/chat-utils.js +0 -940
  61. package/cjs/lib/Utils/companion-reg-client-utils.js +0 -45
  62. package/cjs/lib/Utils/crypto.js +0 -202
  63. package/cjs/lib/Utils/decode-wa-message.js +0 -324
  64. package/cjs/lib/Utils/event-buffer.js +0 -643
  65. package/cjs/lib/Utils/generics.js +0 -429
  66. package/cjs/lib/Utils/history.js +0 -151
  67. package/cjs/lib/Utils/identity-change-handler.js +0 -56
  68. package/cjs/lib/Utils/index.js +0 -42
  69. package/cjs/lib/Utils/link-preview.js +0 -122
  70. package/cjs/lib/Utils/logger.js +0 -8
  71. package/cjs/lib/Utils/lt-hash.js +0 -64
  72. package/cjs/lib/Utils/make-mutex.js +0 -38
  73. package/cjs/lib/Utils/message-retry-manager.js +0 -267
  74. package/cjs/lib/Utils/messages-media.js +0 -933
  75. package/cjs/lib/Utils/messages.js +0 -2180
  76. package/cjs/lib/Utils/noise-handler.js +0 -205
  77. package/cjs/lib/Utils/offline-node-processor.js +0 -43
  78. package/cjs/lib/Utils/pre-key-manager.js +0 -113
  79. package/cjs/lib/Utils/process-message.js +0 -772
  80. package/cjs/lib/Utils/reporting-utils.js +0 -263
  81. package/cjs/lib/Utils/rich-message-utils.js +0 -439
  82. package/cjs/lib/Utils/signal.js +0 -214
  83. package/cjs/lib/Utils/stanza-ack.js +0 -41
  84. package/cjs/lib/Utils/sync-action-utils.js +0 -54
  85. package/cjs/lib/Utils/tc-token-utils.js +0 -174
  86. package/cjs/lib/Utils/use-multi-file-auth-state.js +0 -125
  87. package/cjs/lib/Utils/use-single-file-auth-state.js +0 -121
  88. package/cjs/lib/Utils/use-sqlite-auth-state.js +0 -182
  89. package/cjs/lib/Utils/validate-connection.js +0 -210
  90. package/cjs/lib/WABinary/constants.js +0 -1470
  91. package/cjs/lib/WABinary/decode.js +0 -301
  92. package/cjs/lib/WABinary/encode.js +0 -257
  93. package/cjs/lib/WABinary/generic-utils.js +0 -275
  94. package/cjs/lib/WABinary/index.js +0 -22
  95. package/cjs/lib/WABinary/jid-utils.js +0 -114
  96. package/cjs/lib/WABinary/types.js +0 -37
  97. package/cjs/lib/WAM/BinaryInfo.js +0 -14
  98. package/cjs/lib/WAM/constants.js +0 -22856
  99. package/cjs/lib/WAM/encode.js +0 -154
  100. package/cjs/lib/WAM/index.js +0 -20
  101. package/cjs/lib/WAUSync/Protocols/USyncContactProtocol.js +0 -56
  102. package/cjs/lib/WAUSync/Protocols/USyncDeviceProtocol.js +0 -67
  103. package/cjs/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +0 -31
  104. package/cjs/lib/WAUSync/Protocols/USyncStatusProtocol.js +0 -42
  105. package/cjs/lib/WAUSync/Protocols/USyncUsernameProtocol.js +0 -29
  106. package/cjs/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +0 -55
  107. package/cjs/lib/WAUSync/Protocols/UsyncLIDProtocol.js +0 -33
  108. package/cjs/lib/WAUSync/Protocols/index.js +0 -24
  109. package/cjs/lib/WAUSync/USyncQuery.js +0 -126
  110. package/cjs/lib/WAUSync/USyncUser.js +0 -35
  111. package/cjs/lib/WAUSync/index.js +0 -20
  112. package/cjs/lib/index.js +0 -34
  113. package/cjs/package.json +0 -1
@@ -1,205 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.makeNoiseHandler = void 0;
4
- const boom_1 = require("@hapi/boom");
5
- const index_js_1 = require("../../WAProto/index.js");
6
- const index_js_2 = require("../Defaults/index.js");
7
- const index_js_3 = require("../WABinary/index.js");
8
- const crypto_js_1 = require("./crypto.js");
9
- const IV_LENGTH = 12;
10
- const EMPTY_BUFFER = Buffer.alloc(0);
11
- const generateIV = (counter) => {
12
- const iv = new ArrayBuffer(IV_LENGTH);
13
- new DataView(iv).setUint32(8, counter);
14
- return new Uint8Array(iv);
15
- };
16
- class TransportState {
17
- constructor(encKey, decKey) {
18
- this.encKey = encKey;
19
- this.decKey = decKey;
20
- this.readCounter = 0;
21
- this.writeCounter = 0;
22
- this.iv = new Uint8Array(IV_LENGTH);
23
- }
24
- encrypt(plaintext) {
25
- const c = this.writeCounter++;
26
- this.iv[8] = (c >>> 24) & 0xff;
27
- this.iv[9] = (c >>> 16) & 0xff;
28
- this.iv[10] = (c >>> 8) & 0xff;
29
- this.iv[11] = c & 0xff;
30
- return (0, crypto_js_1.aesEncryptGCM)(plaintext, this.encKey, this.iv, EMPTY_BUFFER);
31
- }
32
- decrypt(ciphertext) {
33
- const c = this.readCounter++;
34
- this.iv[8] = (c >>> 24) & 0xff;
35
- this.iv[9] = (c >>> 16) & 0xff;
36
- this.iv[10] = (c >>> 8) & 0xff;
37
- this.iv[11] = c & 0xff;
38
- return (0, crypto_js_1.aesDecryptGCM)(ciphertext, this.decKey, this.iv, EMPTY_BUFFER);
39
- }
40
- }
41
- const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey }, NOISE_HEADER, logger, routingInfo }) => {
42
- logger = logger.child({ class: 'ns' });
43
- const data = Buffer.from(index_js_2.NOISE_MODE);
44
- let hash = data.byteLength === 32 ? data : (0, crypto_js_1.sha256)(data);
45
- let salt = hash;
46
- let encKey = hash;
47
- let decKey = hash;
48
- let counter = 0;
49
- let sentIntro = false;
50
- let inBytes = Buffer.alloc(0);
51
- let transport = null;
52
- let isWaitingForTransport = false;
53
- let pendingOnFrame = null;
54
- let introHeader;
55
- if (routingInfo) {
56
- introHeader = Buffer.alloc(7 + routingInfo.byteLength + NOISE_HEADER.length);
57
- introHeader.write('ED', 0, 'utf8');
58
- introHeader.writeUint8(0, 2);
59
- introHeader.writeUint8(1, 3);
60
- introHeader.writeUint8(routingInfo.byteLength >> 16, 4);
61
- introHeader.writeUint16BE(routingInfo.byteLength & 65535, 5);
62
- introHeader.set(routingInfo, 7);
63
- introHeader.set(NOISE_HEADER, 7 + routingInfo.byteLength);
64
- }
65
- else {
66
- introHeader = Buffer.from(NOISE_HEADER);
67
- }
68
- const authenticate = (data) => {
69
- if (!transport) {
70
- hash = (0, crypto_js_1.sha256)(Buffer.concat([hash, data]));
71
- }
72
- };
73
- const encrypt = (plaintext) => {
74
- if (transport) {
75
- return transport.encrypt(plaintext);
76
- }
77
- const result = (0, crypto_js_1.aesEncryptGCM)(plaintext, encKey, generateIV(counter++), hash);
78
- authenticate(result);
79
- return result;
80
- };
81
- const decrypt = (ciphertext) => {
82
- if (transport) {
83
- return transport.decrypt(ciphertext);
84
- }
85
- const result = (0, crypto_js_1.aesDecryptGCM)(ciphertext, decKey, generateIV(counter++), hash);
86
- authenticate(ciphertext);
87
- return result;
88
- };
89
- const localHKDF = (data) => {
90
- const key = (0, crypto_js_1.hkdf)(Buffer.from(data), 64, { salt, info: '' });
91
- return [key.subarray(0, 32), key.subarray(32)];
92
- };
93
- const mixIntoKey = (data) => {
94
- const [write, read] = localHKDF(data);
95
- salt = write;
96
- encKey = read;
97
- decKey = read;
98
- counter = 0;
99
- };
100
- const finishInit = async () => {
101
- isWaitingForTransport = true;
102
- const [write, read] = localHKDF(new Uint8Array(0));
103
- transport = new TransportState(write, read);
104
- isWaitingForTransport = false;
105
- logger.trace('Noise handler transitioned to Transport state');
106
- if (pendingOnFrame) {
107
- logger.trace({ length: inBytes.length }, 'Flushing buffered frames after transport ready');
108
- await processData(pendingOnFrame);
109
- pendingOnFrame = null;
110
- }
111
- };
112
- const processData = async (onFrame) => {
113
- let size;
114
- while (true) {
115
- if (inBytes.length < 3)
116
- return;
117
- size = (inBytes[0] << 16) | (inBytes[1] << 8) | inBytes[2];
118
- if (inBytes.length < size + 3)
119
- return;
120
- let frame = inBytes.subarray(3, size + 3);
121
- inBytes = inBytes.subarray(size + 3);
122
- if (transport) {
123
- const result = transport.decrypt(frame);
124
- frame = await (0, index_js_3.decodeBinaryNode)(result);
125
- }
126
- if (logger.level === 'trace') {
127
- logger.trace({ msg: frame?.attrs?.id }, 'recv frame');
128
- }
129
- onFrame(frame);
130
- }
131
- };
132
- authenticate(NOISE_HEADER);
133
- authenticate(publicKey);
134
- return {
135
- encrypt,
136
- decrypt,
137
- authenticate,
138
- mixIntoKey,
139
- finishInit,
140
- processHandshake: ({ serverHello }, noiseKey) => {
141
- authenticate(serverHello.ephemeral);
142
- mixIntoKey(crypto_js_1.Curve.sharedKey(privateKey, serverHello.ephemeral));
143
- const decStaticContent = decrypt(serverHello.static);
144
- mixIntoKey(crypto_js_1.Curve.sharedKey(privateKey, decStaticContent));
145
- const certDecoded = decrypt(serverHello.payload);
146
- const { intermediate: certIntermediate, leaf } = index_js_1.proto.CertChain.decode(certDecoded);
147
- // leaf
148
- if (!leaf?.details || !leaf?.signature) {
149
- throw new boom_1.Boom('invalid noise leaf certificate', { statusCode: 400 });
150
- }
151
- if (!certIntermediate?.details || !certIntermediate?.signature) {
152
- throw new boom_1.Boom('invalid noise intermediate certificate', { statusCode: 400 });
153
- }
154
- const details = index_js_1.proto.CertChain.NoiseCertificate.Details.decode(certIntermediate.details);
155
- const { issuerSerial } = details;
156
- const verify = crypto_js_1.Curve.verify(details.key, leaf.details, leaf.signature);
157
- const verifyIntermediate = crypto_js_1.Curve.verify(index_js_2.WA_CERT_DETAILS.PUBLIC_KEY, certIntermediate.details, certIntermediate.signature);
158
- if (!verify) {
159
- throw new boom_1.Boom('noise certificate signature invalid', { statusCode: 400 });
160
- }
161
- if (!verifyIntermediate) {
162
- throw new boom_1.Boom('noise intermediate certificate signature invalid', { statusCode: 400 });
163
- }
164
- if (issuerSerial !== index_js_2.WA_CERT_DETAILS.SERIAL) {
165
- throw new boom_1.Boom('certification match failed', { statusCode: 400 });
166
- }
167
- const keyEnc = encrypt(noiseKey.public);
168
- mixIntoKey(crypto_js_1.Curve.sharedKey(noiseKey.private, serverHello.ephemeral));
169
- return keyEnc;
170
- },
171
- encodeFrame: (data) => {
172
- if (transport) {
173
- data = transport.encrypt(data);
174
- }
175
- const dataLen = data.byteLength;
176
- const introSize = sentIntro ? 0 : introHeader.length;
177
- const frame = Buffer.allocUnsafe(introSize + 3 + dataLen);
178
- if (!sentIntro) {
179
- frame.set(introHeader);
180
- sentIntro = true;
181
- }
182
- frame[introSize] = (dataLen >>> 16) & 0xff;
183
- frame[introSize + 1] = (dataLen >>> 8) & 0xff;
184
- frame[introSize + 2] = dataLen & 0xff;
185
- frame.set(data, introSize + 3);
186
- return frame;
187
- },
188
- decodeFrame: async (newData, onFrame) => {
189
- if (isWaitingForTransport) {
190
- inBytes = Buffer.concat([inBytes, newData]);
191
- pendingOnFrame = onFrame;
192
- return;
193
- }
194
- if (inBytes.length === 0) {
195
- inBytes = Buffer.from(newData);
196
- }
197
- else {
198
- inBytes = Buffer.concat([inBytes, newData]);
199
- }
200
- await processData(onFrame);
201
- }
202
- };
203
- };
204
- exports.makeNoiseHandler = makeNoiseHandler;
205
- //# sourceMappingURL=noise-handler.js.map
@@ -1,43 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.makeOfflineNodeProcessor = makeOfflineNodeProcessor;
4
- /**
5
- * Creates a processor for offline stanza nodes that:
6
- * - Queues nodes for sequential processing
7
- * - Yields to the event loop periodically to avoid blocking
8
- * - Catches handler errors to prevent the processing loop from crashing
9
- */
10
- function makeOfflineNodeProcessor(nodeProcessorMap, deps, batchSize = 10) {
11
- const nodes = [];
12
- let isProcessing = false;
13
- const enqueue = (type, node) => {
14
- nodes.push({ type, node });
15
- if (isProcessing) {
16
- return;
17
- }
18
- isProcessing = true;
19
- const promise = async () => {
20
- let processedInBatch = 0;
21
- while (nodes.length && deps.isWsOpen()) {
22
- const { type, node } = nodes.shift();
23
- const nodeProcessor = nodeProcessorMap.get(type);
24
- if (!nodeProcessor) {
25
- deps.onUnexpectedError(new Error(`unknown offline node type: ${type}`), 'processing offline node');
26
- continue;
27
- }
28
- await nodeProcessor(node).catch(err => deps.onUnexpectedError(err, `processing offline ${type}`));
29
- processedInBatch++;
30
- // Yield to event loop after processing a batch
31
- // This prevents blocking the event loop for too long when there are many offline nodes
32
- if (processedInBatch >= batchSize) {
33
- processedInBatch = 0;
34
- await deps.yieldToEventLoop();
35
- }
36
- }
37
- isProcessing = false;
38
- };
39
- promise().catch(error => deps.onUnexpectedError(error, 'processing offline nodes'));
40
- };
41
- return { enqueue };
42
- }
43
- //# sourceMappingURL=offline-node-processor.js.map
@@ -1,113 +0,0 @@
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.PreKeyManager = void 0;
7
- const p_queue_1 = __importDefault(require("p-queue"));
8
- /**
9
- * Manages pre-key operations with proper concurrency control
10
- */
11
- class PreKeyManager {
12
- constructor(store, logger) {
13
- this.store = store;
14
- this.logger = logger;
15
- this.queues = new Map();
16
- }
17
- /**
18
- * Get or create a queue for a specific key type
19
- */
20
- getQueue(keyType) {
21
- if (!this.queues.has(keyType)) {
22
- this.queues.set(keyType, new p_queue_1.default({ concurrency: 1 }));
23
- }
24
- return this.queues.get(keyType);
25
- }
26
- /**
27
- * Process pre-key operations (updates and deletions)
28
- */
29
- async processOperations(data, keyType, transactionCache, mutations, isInTransaction) {
30
- const keyData = data[keyType];
31
- if (!keyData)
32
- return;
33
- return this.getQueue(keyType).add(async () => {
34
- // Ensure structures exist
35
- transactionCache[keyType] = transactionCache[keyType] || {};
36
- mutations[keyType] = mutations[keyType] || {};
37
- // Separate deletions from updates
38
- const deletions = [];
39
- const updates = {};
40
- for (const keyId in keyData) {
41
- if (keyData[keyId] === null) {
42
- deletions.push(keyId);
43
- }
44
- else {
45
- updates[keyId] = keyData[keyId];
46
- }
47
- }
48
- // Process updates (no validation needed)
49
- if (Object.keys(updates).length > 0) {
50
- Object.assign(transactionCache[keyType], updates);
51
- Object.assign(mutations[keyType], updates);
52
- }
53
- // Process deletions with validation
54
- if (deletions.length > 0) {
55
- await this.processDeletions(keyType, deletions, transactionCache, mutations, isInTransaction);
56
- }
57
- });
58
- }
59
- /**
60
- * Process deletions with validation
61
- */
62
- async processDeletions(keyType, ids, transactionCache, mutations, isInTransaction) {
63
- if (isInTransaction) {
64
- // In transaction, only allow deletion if key exists in cache
65
- for (const keyId of ids) {
66
- if (transactionCache[keyType]?.[keyId]) {
67
- transactionCache[keyType][keyId] = null;
68
- mutations[keyType][keyId] = null;
69
- }
70
- else {
71
- this.logger.warn(`Skipping deletion of non-existent ${keyType} in transaction: ${keyId}`);
72
- }
73
- }
74
- }
75
- else {
76
- // Outside transaction, validate against store
77
- const existingKeys = await this.store.get(keyType, ids);
78
- for (const keyId of ids) {
79
- if (existingKeys[keyId]) {
80
- transactionCache[keyType][keyId] = null;
81
- mutations[keyType][keyId] = null;
82
- }
83
- else {
84
- this.logger.warn(`Skipping deletion of non-existent ${keyType}: ${keyId}`);
85
- }
86
- }
87
- }
88
- }
89
- /**
90
- * Validate and process pre-key deletions outside transactions
91
- */
92
- async validateDeletions(data, keyType) {
93
- const keyData = data[keyType];
94
- if (!keyData)
95
- return;
96
- return this.getQueue(keyType).add(async () => {
97
- // Find all deletion requests
98
- const deletionIds = Object.keys(keyData).filter(id => keyData[id] === null);
99
- if (deletionIds.length === 0)
100
- return;
101
- // Validate deletions
102
- const existingKeys = await this.store.get(keyType, deletionIds);
103
- for (const keyId of deletionIds) {
104
- if (!existingKeys[keyId]) {
105
- this.logger.warn(`Skipping deletion of non-existent ${keyType}: ${keyId}`);
106
- delete data[keyType][keyId];
107
- }
108
- }
109
- });
110
- }
111
- }
112
- exports.PreKeyManager = PreKeyManager;
113
- //# sourceMappingURL=pre-key-manager.js.map