supunmd-bail 2.0.1

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 (196) hide show
  1. package/LICENSE +21 -0
  2. package/WAProto/GenerateStatics.sh +3 -0
  3. package/WAProto/WAProto.proto +5519 -0
  4. package/WAProto/fix-imports.js +29 -0
  5. package/WAProto/index.d.ts +11969 -0
  6. package/WAProto/index.js +84368 -0
  7. package/engine-requirements.js +10 -0
  8. package/lib/Defaults/baileys-version.json +3 -0
  9. package/lib/Defaults/index.d.ts +62 -0
  10. package/lib/Defaults/index.js +115 -0
  11. package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
  12. package/lib/Signal/Group/ciphertext-message.js +12 -0
  13. package/lib/Signal/Group/group-session-builder.d.ts +15 -0
  14. package/lib/Signal/Group/group-session-builder.js +30 -0
  15. package/lib/Signal/Group/group_cipher.d.ts +17 -0
  16. package/lib/Signal/Group/group_cipher.js +82 -0
  17. package/lib/Signal/Group/index.d.ts +12 -0
  18. package/lib/Signal/Group/index.js +12 -0
  19. package/lib/Signal/Group/keyhelper.d.ts +11 -0
  20. package/lib/Signal/Group/keyhelper.js +18 -0
  21. package/lib/Signal/Group/queue-job.d.ts +2 -0
  22. package/lib/Signal/Group/queue-job.js +54 -0
  23. package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
  24. package/lib/Signal/Group/sender-chain-key.js +26 -0
  25. package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
  26. package/lib/Signal/Group/sender-key-distribution-message.js +63 -0
  27. package/lib/Signal/Group/sender-key-message.d.ts +19 -0
  28. package/lib/Signal/Group/sender-key-message.js +66 -0
  29. package/lib/Signal/Group/sender-key-name.d.ts +18 -0
  30. package/lib/Signal/Group/sender-key-name.js +48 -0
  31. package/lib/Signal/Group/sender-key-record.d.ts +31 -0
  32. package/lib/Signal/Group/sender-key-record.js +41 -0
  33. package/lib/Signal/Group/sender-key-state.d.ts +39 -0
  34. package/lib/Signal/Group/sender-key-state.js +84 -0
  35. package/lib/Signal/Group/sender-message-key.d.ts +12 -0
  36. package/lib/Signal/Group/sender-message-key.js +26 -0
  37. package/lib/Signal/libsignal.d.ts +5 -0
  38. package/lib/Signal/libsignal.js +342 -0
  39. package/lib/Signal/lid-mapping.d.ts +23 -0
  40. package/lib/Signal/lid-mapping.js +171 -0
  41. package/lib/Socket/Client/index.d.ts +3 -0
  42. package/lib/Socket/Client/index.js +3 -0
  43. package/lib/Socket/Client/types.d.ts +16 -0
  44. package/lib/Socket/Client/types.js +11 -0
  45. package/lib/Socket/Client/websocket.d.ts +13 -0
  46. package/lib/Socket/Client/websocket.js +50 -0
  47. package/lib/Socket/business.d.ts +188 -0
  48. package/lib/Socket/business.js +376 -0
  49. package/lib/Socket/chats.d.ts +98 -0
  50. package/lib/Socket/chats.js +962 -0
  51. package/lib/Socket/communities.d.ts +244 -0
  52. package/lib/Socket/communities.js +431 -0
  53. package/lib/Socket/groups.d.ts +137 -0
  54. package/lib/Socket/groups.js +327 -0
  55. package/lib/Socket/index.d.ts +231 -0
  56. package/lib/Socket/index.js +18 -0
  57. package/lib/Socket/messages-recv.d.ts +173 -0
  58. package/lib/Socket/messages-recv.js +1228 -0
  59. package/lib/Socket/messages-send.d.ts +169 -0
  60. package/lib/Socket/messages-send.js +1070 -0
  61. package/lib/Socket/mex.d.ts +3 -0
  62. package/lib/Socket/mex.js +42 -0
  63. package/lib/Socket/newsletter.d.ts +147 -0
  64. package/lib/Socket/newsletter.js +181 -0
  65. package/lib/Socket/socket.d.ts +51 -0
  66. package/lib/Socket/socket.js +883 -0
  67. package/lib/Socket/usync.d.ts +37 -0
  68. package/lib/Socket/usync.js +63 -0
  69. package/lib/Types/Auth.d.ts +111 -0
  70. package/lib/Types/Auth.js +2 -0
  71. package/lib/Types/Bussines.d.ts +25 -0
  72. package/lib/Types/Bussines.js +2 -0
  73. package/lib/Types/Call.d.ts +14 -0
  74. package/lib/Types/Call.js +2 -0
  75. package/lib/Types/Chat.d.ts +123 -0
  76. package/lib/Types/Chat.js +8 -0
  77. package/lib/Types/Contact.d.ts +24 -0
  78. package/lib/Types/Contact.js +2 -0
  79. package/lib/Types/Events.d.ts +202 -0
  80. package/lib/Types/Events.js +2 -0
  81. package/lib/Types/GroupMetadata.d.ts +67 -0
  82. package/lib/Types/GroupMetadata.js +2 -0
  83. package/lib/Types/Label.d.ts +47 -0
  84. package/lib/Types/Label.js +25 -0
  85. package/lib/Types/LabelAssociation.d.ts +30 -0
  86. package/lib/Types/LabelAssociation.js +7 -0
  87. package/lib/Types/Message.d.ts +303 -0
  88. package/lib/Types/Message.js +11 -0
  89. package/lib/Types/Newsletter.d.ts +135 -0
  90. package/lib/Types/Newsletter.js +31 -0
  91. package/lib/Types/Product.d.ts +79 -0
  92. package/lib/Types/Product.js +2 -0
  93. package/lib/Types/Signal.d.ts +76 -0
  94. package/lib/Types/Signal.js +2 -0
  95. package/lib/Types/Socket.d.ts +133 -0
  96. package/lib/Types/Socket.js +3 -0
  97. package/lib/Types/State.d.ts +39 -0
  98. package/lib/Types/State.js +13 -0
  99. package/lib/Types/USync.d.ts +26 -0
  100. package/lib/Types/USync.js +2 -0
  101. package/lib/Types/index.d.ts +65 -0
  102. package/lib/Types/index.js +26 -0
  103. package/lib/Utils/auth-utils.d.ts +19 -0
  104. package/lib/Utils/auth-utils.js +257 -0
  105. package/lib/Utils/baileys-event-stream.d.ts +17 -0
  106. package/lib/Utils/baileys-event-stream.js +56 -0
  107. package/lib/Utils/browser-utils.d.ts +4 -0
  108. package/lib/Utils/browser-utils.js +28 -0
  109. package/lib/Utils/business.d.ts +23 -0
  110. package/lib/Utils/business.js +231 -0
  111. package/lib/Utils/chat-utils.d.ts +70 -0
  112. package/lib/Utils/chat-utils.js +763 -0
  113. package/lib/Utils/crypto.d.ts +41 -0
  114. package/lib/Utils/crypto.js +142 -0
  115. package/lib/Utils/decode-wa-message.d.ts +48 -0
  116. package/lib/Utils/decode-wa-message.js +279 -0
  117. package/lib/Utils/event-buffer.d.ts +34 -0
  118. package/lib/Utils/event-buffer.js +548 -0
  119. package/lib/Utils/generics.d.ts +90 -0
  120. package/lib/Utils/generics.js +381 -0
  121. package/lib/Utils/history.d.ts +19 -0
  122. package/lib/Utils/history.js +84 -0
  123. package/lib/Utils/index.d.ts +20 -0
  124. package/lib/Utils/index.js +20 -0
  125. package/lib/Utils/link-preview.d.ts +21 -0
  126. package/lib/Utils/link-preview.js +85 -0
  127. package/lib/Utils/logger.d.ts +12 -0
  128. package/lib/Utils/logger.js +3 -0
  129. package/lib/Utils/lt-hash.d.ts +13 -0
  130. package/lib/Utils/lt-hash.js +48 -0
  131. package/lib/Utils/make-mutex.d.ts +8 -0
  132. package/lib/Utils/make-mutex.js +40 -0
  133. package/lib/Utils/message-retry-manager.d.ts +82 -0
  134. package/lib/Utils/message-retry-manager.js +149 -0
  135. package/lib/Utils/messages-media.d.ts +114 -0
  136. package/lib/Utils/messages-media.js +663 -0
  137. package/lib/Utils/messages.d.ts +76 -0
  138. package/lib/Utils/messages.js +908 -0
  139. package/lib/Utils/noise-handler.d.ts +20 -0
  140. package/lib/Utils/noise-handler.js +147 -0
  141. package/lib/Utils/pre-key-manager.d.ts +28 -0
  142. package/lib/Utils/pre-key-manager.js +106 -0
  143. package/lib/Utils/process-message.d.ts +42 -0
  144. package/lib/Utils/process-message.js +413 -0
  145. package/lib/Utils/signal.d.ts +34 -0
  146. package/lib/Utils/signal.js +159 -0
  147. package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
  148. package/lib/Utils/use-multi-file-auth-state.js +121 -0
  149. package/lib/Utils/validate-connection.d.ts +11 -0
  150. package/lib/Utils/validate-connection.js +195 -0
  151. package/lib/WABinary/constants.d.ts +28 -0
  152. package/lib/WABinary/constants.js +1301 -0
  153. package/lib/WABinary/decode.d.ts +7 -0
  154. package/lib/WABinary/decode.js +238 -0
  155. package/lib/WABinary/encode.d.ts +3 -0
  156. package/lib/WABinary/encode.js +216 -0
  157. package/lib/WABinary/generic-utils.d.ts +15 -0
  158. package/lib/WABinary/generic-utils.js +191 -0
  159. package/lib/WABinary/index.d.ts +6 -0
  160. package/lib/WABinary/index.js +6 -0
  161. package/lib/WABinary/jid-utils.d.ts +48 -0
  162. package/lib/WABinary/jid-utils.js +96 -0
  163. package/lib/WABinary/types.d.ts +19 -0
  164. package/lib/WABinary/types.js +2 -0
  165. package/lib/WAM/BinaryInfo.d.ts +9 -0
  166. package/lib/WAM/BinaryInfo.js +10 -0
  167. package/lib/WAM/constants.d.ts +40 -0
  168. package/lib/WAM/constants.js +22853 -0
  169. package/lib/WAM/encode.d.ts +3 -0
  170. package/lib/WAM/encode.js +150 -0
  171. package/lib/WAM/index.d.ts +4 -0
  172. package/lib/WAM/index.js +4 -0
  173. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
  174. package/lib/WAUSync/Protocols/USyncContactProtocol.js +29 -0
  175. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
  176. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +54 -0
  177. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
  178. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +27 -0
  179. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
  180. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +38 -0
  181. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
  182. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +51 -0
  183. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
  184. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +29 -0
  185. package/lib/WAUSync/Protocols/index.d.ts +5 -0
  186. package/lib/WAUSync/Protocols/index.js +5 -0
  187. package/lib/WAUSync/USyncQuery.d.ts +29 -0
  188. package/lib/WAUSync/USyncQuery.js +94 -0
  189. package/lib/WAUSync/USyncUser.d.ts +13 -0
  190. package/lib/WAUSync/USyncUser.js +23 -0
  191. package/lib/WAUSync/index.d.ts +4 -0
  192. package/lib/WAUSync/index.js +4 -0
  193. package/lib/index.d.ts +22 -0
  194. package/lib/index.js +36 -0
  195. package/lib/supun +1 -0
  196. package/package.json +104 -0
@@ -0,0 +1,20 @@
1
+ import { proto } from '../../WAProto/index.js';
2
+ import type { KeyPair } from '../Types/index.js';
3
+ import type { BinaryNode } from '../WABinary/index.js';
4
+ import type { ILogger } from './logger.js';
5
+ export declare const makeNoiseHandler: ({ keyPair: { private: privateKey, public: publicKey }, NOISE_HEADER, logger, routingInfo }: {
6
+ keyPair: KeyPair;
7
+ NOISE_HEADER: Uint8Array;
8
+ logger: ILogger;
9
+ routingInfo?: Buffer | undefined;
10
+ }) => {
11
+ encrypt: (plaintext: Uint8Array) => Buffer<ArrayBuffer>;
12
+ decrypt: (ciphertext: Uint8Array) => Buffer<ArrayBuffer>;
13
+ authenticate: (data: Uint8Array) => void;
14
+ mixIntoKey: (data: Uint8Array) => Promise<void>;
15
+ finishInit: () => Promise<void>;
16
+ processHandshake: ({ serverHello }: proto.HandshakeMessage, noiseKey: KeyPair) => Promise<Buffer<ArrayBuffer>>;
17
+ encodeFrame: (data: Buffer | Uint8Array) => Buffer<ArrayBuffer>;
18
+ decodeFrame: (newData: Buffer | Uint8Array, onFrame: (buff: Uint8Array | BinaryNode) => void) => Promise<void>;
19
+ };
20
+ //# sourceMappingURL=noise-handler.d.ts.map
@@ -0,0 +1,147 @@
1
+ import { Boom } from '@hapi/boom';
2
+ import { proto } from '../../WAProto/index.js';
3
+ import { NOISE_MODE, WA_CERT_DETAILS } from '../Defaults/index.js';
4
+ import { decodeBinaryNode } from '../WABinary/index.js';
5
+ import { aesDecryptGCM, aesEncryptGCM, Curve, hkdf, sha256 } from './crypto.js';
6
+ const generateIV = (counter) => {
7
+ const iv = new ArrayBuffer(12);
8
+ new DataView(iv).setUint32(8, counter);
9
+ return new Uint8Array(iv);
10
+ };
11
+ export const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey }, NOISE_HEADER, logger, routingInfo }) => {
12
+ logger = logger.child({ class: 'ns' });
13
+ const authenticate = (data) => {
14
+ if (!isFinished) {
15
+ hash = sha256(Buffer.concat([hash, data]));
16
+ }
17
+ };
18
+ const encrypt = (plaintext) => {
19
+ const result = aesEncryptGCM(plaintext, encKey, generateIV(writeCounter), hash);
20
+ writeCounter += 1;
21
+ authenticate(result);
22
+ return result;
23
+ };
24
+ const decrypt = (ciphertext) => {
25
+ // before the handshake is finished, we use the same counter
26
+ // after handshake, the counters are different
27
+ const iv = generateIV(isFinished ? readCounter : writeCounter);
28
+ const result = aesDecryptGCM(ciphertext, decKey, iv, hash);
29
+ if (isFinished) {
30
+ readCounter += 1;
31
+ }
32
+ else {
33
+ writeCounter += 1;
34
+ }
35
+ authenticate(ciphertext);
36
+ return result;
37
+ };
38
+ const localHKDF = async (data) => {
39
+ const key = await hkdf(Buffer.from(data), 64, { salt, info: '' });
40
+ return [key.slice(0, 32), key.slice(32)];
41
+ };
42
+ const mixIntoKey = async (data) => {
43
+ const [write, read] = await localHKDF(data);
44
+ salt = write;
45
+ encKey = read;
46
+ decKey = read;
47
+ readCounter = 0;
48
+ writeCounter = 0;
49
+ };
50
+ const finishInit = async () => {
51
+ const [write, read] = await localHKDF(new Uint8Array(0));
52
+ encKey = write;
53
+ decKey = read;
54
+ hash = Buffer.from([]);
55
+ readCounter = 0;
56
+ writeCounter = 0;
57
+ isFinished = true;
58
+ };
59
+ const data = Buffer.from(NOISE_MODE);
60
+ let hash = data.byteLength === 32 ? data : sha256(data);
61
+ let salt = hash;
62
+ let encKey = hash;
63
+ let decKey = hash;
64
+ let readCounter = 0;
65
+ let writeCounter = 0;
66
+ let isFinished = false;
67
+ let sentIntro = false;
68
+ let inBytes = Buffer.alloc(0);
69
+ authenticate(NOISE_HEADER);
70
+ authenticate(publicKey);
71
+ return {
72
+ encrypt,
73
+ decrypt,
74
+ authenticate,
75
+ mixIntoKey,
76
+ finishInit,
77
+ processHandshake: async ({ serverHello }, noiseKey) => {
78
+ authenticate(serverHello.ephemeral);
79
+ await mixIntoKey(Curve.sharedKey(privateKey, serverHello.ephemeral));
80
+ const decStaticContent = decrypt(serverHello.static);
81
+ await mixIntoKey(Curve.sharedKey(privateKey, decStaticContent));
82
+ const certDecoded = decrypt(serverHello.payload);
83
+ const { intermediate: certIntermediate /*leaf*/ } = proto.CertChain.decode(certDecoded);
84
+ // TODO: handle this leaf stuff
85
+ const { issuerSerial } = proto.CertChain.NoiseCertificate.Details.decode(certIntermediate.details);
86
+ if (issuerSerial !== WA_CERT_DETAILS.SERIAL) {
87
+ throw new Boom('certification match failed', { statusCode: 400 });
88
+ }
89
+ const keyEnc = encrypt(noiseKey.public);
90
+ await mixIntoKey(Curve.sharedKey(noiseKey.private, serverHello.ephemeral));
91
+ return keyEnc;
92
+ },
93
+ encodeFrame: (data) => {
94
+ if (isFinished) {
95
+ data = encrypt(data);
96
+ }
97
+ let header;
98
+ if (routingInfo) {
99
+ header = Buffer.alloc(7);
100
+ header.write('ED', 0, 'utf8');
101
+ header.writeUint8(0, 2);
102
+ header.writeUint8(1, 3);
103
+ header.writeUint8(routingInfo.byteLength >> 16, 4);
104
+ header.writeUint16BE(routingInfo.byteLength & 65535, 5);
105
+ header = Buffer.concat([header, routingInfo, NOISE_HEADER]);
106
+ }
107
+ else {
108
+ header = Buffer.from(NOISE_HEADER);
109
+ }
110
+ const introSize = sentIntro ? 0 : header.length;
111
+ const frame = Buffer.alloc(introSize + 3 + data.byteLength);
112
+ if (!sentIntro) {
113
+ frame.set(header);
114
+ sentIntro = true;
115
+ }
116
+ frame.writeUInt8(data.byteLength >> 16, introSize);
117
+ frame.writeUInt16BE(65535 & data.byteLength, introSize + 1);
118
+ frame.set(data, introSize + 3);
119
+ return frame;
120
+ },
121
+ decodeFrame: async (newData, onFrame) => {
122
+ // the binary protocol uses its own framing mechanism
123
+ // on top of the WS frames
124
+ // so we get this data and separate out the frames
125
+ const getBytesSize = () => {
126
+ if (inBytes.length >= 3) {
127
+ return (inBytes.readUInt8() << 16) | inBytes.readUInt16BE(1);
128
+ }
129
+ };
130
+ inBytes = Buffer.concat([inBytes, newData]);
131
+ logger.trace(`recv ${newData.length} bytes, total recv ${inBytes.length} bytes`);
132
+ let size = getBytesSize();
133
+ while (size && inBytes.length >= size + 3) {
134
+ let frame = inBytes.slice(3, size + 3);
135
+ inBytes = inBytes.slice(size + 3);
136
+ if (isFinished) {
137
+ const result = decrypt(frame);
138
+ frame = await decodeBinaryNode(result);
139
+ }
140
+ logger.trace({ msg: frame?.attrs?.id }, 'recv frame');
141
+ onFrame(frame);
142
+ size = getBytesSize();
143
+ }
144
+ }
145
+ };
146
+ };
147
+ //# sourceMappingURL=noise-handler.js.map
@@ -0,0 +1,28 @@
1
+ import type { SignalDataSet, SignalDataTypeMap, SignalKeyStore } from '../Types/index.js';
2
+ import type { ILogger } from './logger.js';
3
+ /**
4
+ * Manages pre-key operations with proper concurrency control
5
+ */
6
+ export declare class PreKeyManager {
7
+ private readonly store;
8
+ private readonly logger;
9
+ private readonly queues;
10
+ constructor(store: SignalKeyStore, logger: ILogger);
11
+ /**
12
+ * Get or create a queue for a specific key type
13
+ */
14
+ private getQueue;
15
+ /**
16
+ * Process pre-key operations (updates and deletions)
17
+ */
18
+ processOperations(data: SignalDataSet, keyType: keyof SignalDataTypeMap, transactionCache: SignalDataSet, mutations: SignalDataSet, isInTransaction: boolean): Promise<void>;
19
+ /**
20
+ * Process deletions with validation
21
+ */
22
+ private processDeletions;
23
+ /**
24
+ * Validate and process pre-key deletions outside transactions
25
+ */
26
+ validateDeletions(data: SignalDataSet, keyType: keyof SignalDataTypeMap): Promise<void>;
27
+ }
28
+ //# sourceMappingURL=pre-key-manager.d.ts.map
@@ -0,0 +1,106 @@
1
+ import PQueue from 'p-queue';
2
+ /**
3
+ * Manages pre-key operations with proper concurrency control
4
+ */
5
+ export class PreKeyManager {
6
+ constructor(store, logger) {
7
+ this.store = store;
8
+ this.logger = logger;
9
+ this.queues = new Map();
10
+ }
11
+ /**
12
+ * Get or create a queue for a specific key type
13
+ */
14
+ getQueue(keyType) {
15
+ if (!this.queues.has(keyType)) {
16
+ this.queues.set(keyType, new PQueue({ concurrency: 1 }));
17
+ }
18
+ return this.queues.get(keyType);
19
+ }
20
+ /**
21
+ * Process pre-key operations (updates and deletions)
22
+ */
23
+ async processOperations(data, keyType, transactionCache, mutations, isInTransaction) {
24
+ const keyData = data[keyType];
25
+ if (!keyData)
26
+ return;
27
+ return this.getQueue(keyType).add(async () => {
28
+ // Ensure structures exist
29
+ transactionCache[keyType] = transactionCache[keyType] || {};
30
+ mutations[keyType] = mutations[keyType] || {};
31
+ // Separate deletions from updates
32
+ const deletions = [];
33
+ const updates = {};
34
+ for (const keyId in keyData) {
35
+ if (keyData[keyId] === null) {
36
+ deletions.push(keyId);
37
+ }
38
+ else {
39
+ updates[keyId] = keyData[keyId];
40
+ }
41
+ }
42
+ // Process updates (no validation needed)
43
+ if (Object.keys(updates).length > 0) {
44
+ Object.assign(transactionCache[keyType], updates);
45
+ Object.assign(mutations[keyType], updates);
46
+ }
47
+ // Process deletions with validation
48
+ if (deletions.length > 0) {
49
+ await this.processDeletions(keyType, deletions, transactionCache, mutations, isInTransaction);
50
+ }
51
+ });
52
+ }
53
+ /**
54
+ * Process deletions with validation
55
+ */
56
+ async processDeletions(keyType, ids, transactionCache, mutations, isInTransaction) {
57
+ if (isInTransaction) {
58
+ // In transaction, only allow deletion if key exists in cache
59
+ for (const keyId of ids) {
60
+ if (transactionCache[keyType]?.[keyId]) {
61
+ transactionCache[keyType][keyId] = null;
62
+ mutations[keyType][keyId] = null;
63
+ }
64
+ else {
65
+ this.logger.warn(`Skipping deletion of non-existent ${keyType} in transaction: ${keyId}`);
66
+ }
67
+ }
68
+ }
69
+ else {
70
+ // Outside transaction, validate against store
71
+ const existingKeys = await this.store.get(keyType, ids);
72
+ for (const keyId of ids) {
73
+ if (existingKeys[keyId]) {
74
+ transactionCache[keyType][keyId] = null;
75
+ mutations[keyType][keyId] = null;
76
+ }
77
+ else {
78
+ this.logger.warn(`Skipping deletion of non-existent ${keyType}: ${keyId}`);
79
+ }
80
+ }
81
+ }
82
+ }
83
+ /**
84
+ * Validate and process pre-key deletions outside transactions
85
+ */
86
+ async validateDeletions(data, keyType) {
87
+ const keyData = data[keyType];
88
+ if (!keyData)
89
+ return;
90
+ return this.getQueue(keyType).add(async () => {
91
+ // Find all deletion requests
92
+ const deletionIds = Object.keys(keyData).filter(id => keyData[id] === null);
93
+ if (deletionIds.length === 0)
94
+ return;
95
+ // Validate deletions
96
+ const existingKeys = await this.store.get(keyType, deletionIds);
97
+ for (const keyId of deletionIds) {
98
+ if (!existingKeys[keyId]) {
99
+ this.logger.warn(`Skipping deletion of non-existent ${keyType}: ${keyId}`);
100
+ delete data[keyType][keyId];
101
+ }
102
+ }
103
+ });
104
+ }
105
+ }
106
+ //# sourceMappingURL=pre-key-manager.js.map
@@ -0,0 +1,42 @@
1
+ import { proto } from '../../WAProto/index.js';
2
+ import type { AuthenticationCreds, BaileysEventEmitter, CacheStore, SignalKeyStoreWithTransaction, SignalRepositoryWithLIDStore, WAMessage, WAMessageKey } from '../Types/index.js';
3
+ import type { ILogger } from './logger.js';
4
+ type ProcessMessageContext = {
5
+ shouldProcessHistoryMsg: boolean;
6
+ placeholderResendCache?: CacheStore;
7
+ creds: AuthenticationCreds;
8
+ keyStore: SignalKeyStoreWithTransaction;
9
+ ev: BaileysEventEmitter;
10
+ logger?: ILogger;
11
+ options: RequestInit;
12
+ signalRepository: SignalRepositoryWithLIDStore;
13
+ };
14
+ /** Cleans a received message to further processing */
15
+ export declare const cleanMessage: (message: WAMessage, meId: string, meLid: string) => void;
16
+ export declare const isRealMessage: (message: WAMessage) => boolean;
17
+ export declare const shouldIncrementChatUnread: (message: WAMessage) => boolean;
18
+ /**
19
+ * Get the ID of the chat from the given key.
20
+ * Typically -- that'll be the remoteJid, but for broadcasts, it'll be the participant
21
+ */
22
+ export declare const getChatId: ({ remoteJid, participant, fromMe }: WAMessageKey) => string;
23
+ type PollContext = {
24
+ /** normalised jid of the person that created the poll */
25
+ pollCreatorJid: string;
26
+ /** ID of the poll creation message */
27
+ pollMsgId: string;
28
+ /** poll creation message enc key */
29
+ pollEncKey: Uint8Array;
30
+ /** jid of the person that voted */
31
+ voterJid: string;
32
+ };
33
+ /**
34
+ * Decrypt a poll vote
35
+ * @param vote encrypted vote
36
+ * @param ctx additional info about the poll required for decryption
37
+ * @returns list of SHA256 options
38
+ */
39
+ export declare function decryptPollVote({ encPayload, encIv }: proto.Message.IPollEncValue, { pollCreatorJid, pollMsgId, pollEncKey, voterJid }: PollContext): proto.Message.PollVoteMessage;
40
+ declare const processMessage: (message: WAMessage, { shouldProcessHistoryMsg, placeholderResendCache, ev, creds, signalRepository, keyStore, logger, options }: ProcessMessageContext) => Promise<void>;
41
+ export default processMessage;
42
+ //# sourceMappingURL=process-message.d.ts.map