nrx-bails 0.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 (199) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1541 -0
  3. package/WAProto/GenerateStatics.sh +4 -0
  4. package/WAProto/WAProto.proto +4775 -0
  5. package/WAProto/index.d.ts +2 -0
  6. package/WAProto/index.js +169661 -0
  7. package/lib/Defaults/index.d.ts +113 -0
  8. package/lib/Defaults/index.js +156 -0
  9. package/lib/Defaults/phonenumber-mcc.json +223 -0
  10. package/lib/Defaults/ye-bail-version.json +3 -0
  11. package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
  12. package/lib/Signal/Group/ciphertext-message.js +41 -0
  13. package/lib/Signal/Group/group-session-builder.d.ts +8 -0
  14. package/lib/Signal/Group/group-session-builder.js +90 -0
  15. package/lib/Signal/Group/group_cipher.d.ts +12 -0
  16. package/lib/Signal/Group/group_cipher.js +122 -0
  17. package/lib/Signal/Group/index.d.ts +22 -0
  18. package/lib/Signal/Group/index.js +83 -0
  19. package/lib/Signal/Group/keyhelper.d.ts +7 -0
  20. package/lib/Signal/Group/keyhelper.js +81 -0
  21. package/lib/Signal/Group/queue-job.d.ts +3 -0
  22. package/lib/Signal/Group/queue-job.js +83 -0
  23. package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
  24. package/lib/Signal/Group/sender-chain-key.js +60 -0
  25. package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
  26. package/lib/Signal/Group/sender-key-distribution-message.js +92 -0
  27. package/lib/Signal/Group/sender-key-message.d.ts +19 -0
  28. package/lib/Signal/Group/sender-key-message.js +95 -0
  29. package/lib/Signal/Group/sender-key-name.d.ts +12 -0
  30. package/lib/Signal/Group/sender-key-name.js +77 -0
  31. package/lib/Signal/Group/sender-key-record.d.ts +13 -0
  32. package/lib/Signal/Group/sender-key-record.js +79 -0
  33. package/lib/Signal/Group/sender-key-state.d.ts +17 -0
  34. package/lib/Signal/Group/sender-key-state.js +125 -0
  35. package/lib/Signal/Group/sender-message-key.d.ts +12 -0
  36. package/lib/Signal/Group/sender-message-key.js +55 -0
  37. package/lib/Signal/libsignal.d.ts +37 -0
  38. package/lib/Signal/libsignal.js +200 -0
  39. package/lib/Socket/Client/index.d.ts +1 -0
  40. package/lib/Socket/Client/index.js +44 -0
  41. package/lib/Socket/Client/types.d.ts +7 -0
  42. package/lib/Socket/Client/types.js +39 -0
  43. package/lib/Socket/Client/websocket.d.ts +19 -0
  44. package/lib/Socket/Client/websocket.js +137 -0
  45. package/lib/Socket/business.d.ts +329 -0
  46. package/lib/Socket/business.js +286 -0
  47. package/lib/Socket/chats.d.ts +84 -0
  48. package/lib/Socket/chats.js +1022 -0
  49. package/lib/Socket/groups.d.ts +216 -0
  50. package/lib/Socket/groups.js +358 -0
  51. package/lib/Socket/index.d.ts +330 -0
  52. package/lib/Socket/index.js +36 -0
  53. package/lib/Socket/messages-recv.d.ts +271 -0
  54. package/lib/Socket/messages-recv.js +1079 -0
  55. package/lib/Socket/messages-send.d.ts +258 -0
  56. package/lib/Socket/messages-send.js +1190 -0
  57. package/lib/Socket/newsletter.d.ts +253 -0
  58. package/lib/Socket/newsletter.js +362 -0
  59. package/lib/Socket/registration.d.ts +361 -0
  60. package/lib/Socket/registration.js +179 -0
  61. package/lib/Socket/socket.d.ts +33 -0
  62. package/lib/Socket/socket.js +699 -0
  63. package/lib/Socket/usync.d.ts +27 -0
  64. package/lib/Socket/usync.js +96 -0
  65. package/lib/Store/index.d.ts +3 -0
  66. package/lib/Store/index.js +36 -0
  67. package/lib/Store/make-cache-manager-auth-state.d.ts +16 -0
  68. package/lib/Store/make-cache-manager-auth-state.js +118 -0
  69. package/lib/Store/make-in-memory-store.d.ts +64 -0
  70. package/lib/Store/make-in-memory-store.js +465 -0
  71. package/lib/Store/make-ordered-dictionary.d.ts +14 -0
  72. package/lib/Store/make-ordered-dictionary.js +107 -0
  73. package/lib/Store/object-repository.d.ts +11 -0
  74. package/lib/Store/object-repository.js +53 -0
  75. package/lib/Types/Auth.d.ts +1 -0
  76. package/lib/Types/Auth.js +28 -0
  77. package/lib/Types/Call.d.ts +1 -0
  78. package/lib/Types/Call.js +28 -0
  79. package/lib/Types/Chat.d.ts +2 -0
  80. package/lib/Types/Chat.js +30 -0
  81. package/lib/Types/Contact.d.ts +1 -0
  82. package/lib/Types/Contact.js +28 -0
  83. package/lib/Types/Events.d.ts +1 -0
  84. package/lib/Types/Events.js +28 -0
  85. package/lib/Types/GroupMetadata.d.ts +1 -0
  86. package/lib/Types/GroupMetadata.js +28 -0
  87. package/lib/Types/Label.d.ts +2 -0
  88. package/lib/Types/Label.js +53 -0
  89. package/lib/Types/LabelAssociation.d.ts +2 -0
  90. package/lib/Types/LabelAssociation.js +35 -0
  91. package/lib/Types/Message.d.ts +2 -0
  92. package/lib/Types/Message.js +33 -0
  93. package/lib/Types/Newsletter.d.ts +4 -0
  94. package/lib/Types/Newsletter.js +62 -0
  95. package/lib/Types/Product.d.ts +1 -0
  96. package/lib/Types/Product.js +28 -0
  97. package/lib/Types/Signal.d.ts +1 -0
  98. package/lib/Types/Signal.js +28 -0
  99. package/lib/Types/Socket.d.ts +1 -0
  100. package/lib/Types/Socket.js +28 -0
  101. package/lib/Types/State.d.ts +1 -0
  102. package/lib/Types/State.js +28 -0
  103. package/lib/Types/USync.d.ts +1 -0
  104. package/lib/Types/USync.js +28 -0
  105. package/lib/Types/index.d.ts +2 -0
  106. package/lib/Types/index.js +68 -0
  107. package/lib/Utils/auth-utils.d.ts +63 -0
  108. package/lib/Utils/auth-utils.js +248 -0
  109. package/lib/Utils/browser-utils.d.ts +3 -0
  110. package/lib/Utils/browser-utils.js +61 -0
  111. package/lib/Utils/business.d.ts +53 -0
  112. package/lib/Utils/business.js +260 -0
  113. package/lib/Utils/chat-utils.d.ts +253 -0
  114. package/lib/Utils/chat-utils.js +756 -0
  115. package/lib/Utils/crypto.d.ts +43 -0
  116. package/lib/Utils/crypto.js +219 -0
  117. package/lib/Utils/decode-wa-message.d.ts +61 -0
  118. package/lib/Utils/decode-wa-message.js +233 -0
  119. package/lib/Utils/event-buffer.d.ts +17 -0
  120. package/lib/Utils/event-buffer.js +544 -0
  121. package/lib/Utils/generics.d.ts +89 -0
  122. package/lib/Utils/generics.js +471 -0
  123. package/lib/Utils/history.d.ts +59 -0
  124. package/lib/Utils/history.js +120 -0
  125. package/lib/Utils/index.d.ts +1 -0
  126. package/lib/Utils/index.js +61 -0
  127. package/lib/Utils/link-preview.d.ts +19 -0
  128. package/lib/Utils/link-preview.js +152 -0
  129. package/lib/Utils/logger.d.ts +3 -0
  130. package/lib/Utils/logger.js +33 -0
  131. package/lib/Utils/lt-hash.d.ts +13 -0
  132. package/lib/Utils/lt-hash.js +77 -0
  133. package/lib/Utils/make-mutex.d.ts +7 -0
  134. package/lib/Utils/make-mutex.js +69 -0
  135. package/lib/Utils/message-retry-manager.d.ts +34 -0
  136. package/lib/Utils/message-retry-manager.js +154 -0
  137. package/lib/Utils/messages-media.d.ts +137 -0
  138. package/lib/Utils/messages-media.js +1024 -0
  139. package/lib/Utils/messages.d.ts +66 -0
  140. package/lib/Utils/messages.js +1407 -0
  141. package/lib/Utils/noise-handler.d.ts +21 -0
  142. package/lib/Utils/noise-handler.js +176 -0
  143. package/lib/Utils/pre-key-manager.d.ts +13 -0
  144. package/lib/Utils/pre-key-manager.js +93 -0
  145. package/lib/Utils/process-message.d.ts +40 -0
  146. package/lib/Utils/process-message.js +430 -0
  147. package/lib/Utils/signal.d.ts +72 -0
  148. package/lib/Utils/signal.js +179 -0
  149. package/lib/Utils/use-multi-file-auth-state.d.ts +18 -0
  150. package/lib/Utils/use-multi-file-auth-state.js +151 -0
  151. package/lib/Utils/validate-connection.d.ts +43 -0
  152. package/lib/Utils/validate-connection.js +255 -0
  153. package/lib/Utils/ye-bail-event-stream.d.ts +16 -0
  154. package/lib/Utils/ye-bail-event-stream.js +89 -0
  155. package/lib/WABinary/constants.d.ts +23 -0
  156. package/lib/WABinary/constants.js +1328 -0
  157. package/lib/WABinary/decode.d.ts +10 -0
  158. package/lib/WABinary/decode.js +291 -0
  159. package/lib/WABinary/encode.d.ts +2 -0
  160. package/lib/WABinary/encode.js +276 -0
  161. package/lib/WABinary/generic-utils.d.ts +16 -0
  162. package/lib/WABinary/generic-utils.js +155 -0
  163. package/lib/WABinary/index.d.ts +1 -0
  164. package/lib/WABinary/index.js +47 -0
  165. package/lib/WABinary/jid-utils.d.ts +34 -0
  166. package/lib/WABinary/jid-utils.js +111 -0
  167. package/lib/WABinary/types.d.ts +1 -0
  168. package/lib/WABinary/types.js +28 -0
  169. package/lib/WAM/BinaryInfo.d.ts +8 -0
  170. package/lib/WAM/BinaryInfo.js +39 -0
  171. package/lib/WAM/constants.d.ts +35374 -0
  172. package/lib/WAM/constants.js +15376 -0
  173. package/lib/WAM/encode.d.ts +2 -0
  174. package/lib/WAM/encode.js +181 -0
  175. package/lib/WAM/index.d.ts +1 -0
  176. package/lib/WAM/index.js +45 -0
  177. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +14 -0
  178. package/lib/WAUSync/Protocols/USyncContactProtocol.js +58 -0
  179. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
  180. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +83 -0
  181. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
  182. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +56 -0
  183. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
  184. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +68 -0
  185. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +39 -0
  186. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +79 -0
  187. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
  188. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +50 -0
  189. package/lib/WAUSync/Protocols/index.d.ts +1 -0
  190. package/lib/WAUSync/Protocols/index.js +46 -0
  191. package/lib/WAUSync/USyncQuery.d.ts +20 -0
  192. package/lib/WAUSync/USyncQuery.js +115 -0
  193. package/lib/WAUSync/USyncUser.d.ts +13 -0
  194. package/lib/WAUSync/USyncUser.js +52 -0
  195. package/lib/WAUSync/index.d.ts +1 -0
  196. package/lib/WAUSync/index.js +45 -0
  197. package/lib/index.js +81 -0
  198. package/package.json +113 -0
  199. package/requirements.js +32 -0
@@ -0,0 +1,21 @@
1
+ export const __esModule: boolean;
2
+ export function makeNoiseHandler({ keyPair: { private: privateKey, public: publicKey }, NOISE_HEADER, logger, routingInfo }: {
3
+ keyPair: {
4
+ private: any;
5
+ public: any;
6
+ };
7
+ NOISE_HEADER: any;
8
+ logger: any;
9
+ routingInfo: any;
10
+ }): {
11
+ encrypt: (plaintext: any) => Buffer<ArrayBuffer>;
12
+ decrypt: (ciphertext: any) => Buffer<ArrayBuffer>;
13
+ authenticate: (data: any) => void;
14
+ mixIntoKey: (data: any) => Promise<void>;
15
+ finishInit: () => Promise<void>;
16
+ processHandshake: ({ serverHello }: {
17
+ serverHello: any;
18
+ }, noiseKey: any) => Promise<Buffer<ArrayBuffer>>;
19
+ encodeFrame: (data: any) => Buffer<ArrayBuffer>;
20
+ decodeFrame: (newData: any, onFrame: any) => Promise<void>;
21
+ };
@@ -0,0 +1,176 @@
1
+ /**
2
+ * ╔═══════════════════════════════════════════════════════════╗
3
+ * ║ NEROX - WhatsApp API Library ║
4
+ * ║ Premium Edition ║
5
+ * ╚═══════════════════════════════════════════════════════════╝
6
+ *
7
+ * @package nerox-bails
8
+ * @version 0.1.0
9
+ * @author NEROX Development Team
10
+ * @copyright Copyright (c) 2025 NEROX. All rights reserved.
11
+ * @license MIT License
12
+ *
13
+ * Permission is hereby granted, free of charge, to any person obtaining
14
+ * a copy of this software and associated documentation files (the "Software"),
15
+ * to deal in the Software without restriction, including without limitation
16
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
17
+ * and/or sell copies of the Software, and to permit persons to whom the
18
+ * Software is furnished to do so, subject to the following conditions:
19
+ *
20
+ * The above copyright notice and this permission notice shall be included
21
+ * in all copies or substantial portions of the Software.
22
+ *
23
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
26
+ */
27
+ "use strict";
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.makeNoiseHandler = void 0;
30
+ const boom_1 = require("@hapi/boom");
31
+ const WAProto_1 = require("../../WAProto");
32
+ const Defaults_1 = require("../Defaults");
33
+ const WABinary_1 = require("../WABinary");
34
+ const crypto_1 = require("./crypto");
35
+ const generateIV = (counter) => {
36
+ const iv = new ArrayBuffer(12);
37
+ new DataView(iv).setUint32(8, counter);
38
+ return new Uint8Array(iv);
39
+ };
40
+ const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey }, NOISE_HEADER, logger, routingInfo }) => {
41
+ logger = logger.child({ class: 'ns' });
42
+ const authenticate = (data) => {
43
+ if (!isFinished) {
44
+ hash = (0, crypto_1.sha256)(Buffer.concat([hash, data]));
45
+ }
46
+ };
47
+ const encrypt = (plaintext) => {
48
+ const result = (0, crypto_1.aesEncryptGCM)(plaintext, encKey, generateIV(writeCounter), hash);
49
+ writeCounter += 1;
50
+ authenticate(result);
51
+ return result;
52
+ };
53
+ const decrypt = (ciphertext) => {
54
+
55
+
56
+ const iv = generateIV(isFinished ? readCounter : writeCounter);
57
+ const result = (0, crypto_1.aesDecryptGCM)(ciphertext, decKey, iv, hash);
58
+ if (isFinished) {
59
+ readCounter += 1;
60
+ }
61
+ else {
62
+ writeCounter += 1;
63
+ }
64
+ authenticate(ciphertext);
65
+ return result;
66
+ };
67
+ const localHKDF = async (data) => {
68
+ const key = await (0, crypto_1.hkdf)(Buffer.from(data), 64, { salt, info: '' });
69
+ return [key.slice(0, 32), key.slice(32)];
70
+ };
71
+ const mixIntoKey = async (data) => {
72
+ const [write, read] = await localHKDF(data);
73
+ salt = write;
74
+ encKey = read;
75
+ decKey = read;
76
+ readCounter = 0;
77
+ writeCounter = 0;
78
+ };
79
+ const finishInit = async () => {
80
+ const [write, read] = await localHKDF(new Uint8Array(0));
81
+ encKey = write;
82
+ decKey = read;
83
+ hash = Buffer.from([]);
84
+ readCounter = 0;
85
+ writeCounter = 0;
86
+ isFinished = true;
87
+ };
88
+ const data = Buffer.from(Defaults_1.NOISE_MODE);
89
+ let hash = data.byteLength === 32 ? data : (0, crypto_1.sha256)(data);
90
+ let salt = hash;
91
+ let encKey = hash;
92
+ let decKey = hash;
93
+ let readCounter = 0;
94
+ let writeCounter = 0;
95
+ let isFinished = false;
96
+ let sentIntro = false;
97
+ let inBytes = Buffer.alloc(0);
98
+ authenticate(NOISE_HEADER);
99
+ authenticate(publicKey);
100
+ return {
101
+ encrypt,
102
+ decrypt,
103
+ authenticate,
104
+ mixIntoKey,
105
+ finishInit,
106
+ processHandshake: async ({ serverHello }, noiseKey) => {
107
+ authenticate(serverHello.ephemeral);
108
+ await mixIntoKey(crypto_1.Curve.sharedKey(privateKey, serverHello.ephemeral));
109
+ const decStaticContent = decrypt(serverHello.static);
110
+ await mixIntoKey(crypto_1.Curve.sharedKey(privateKey, decStaticContent));
111
+ const certDecoded = decrypt(serverHello.payload);
112
+ const { intermediate: certIntermediate } = WAProto_1.proto.CertChain.decode(certDecoded);
113
+ const { issuerSerial } = WAProto_1.proto.CertChain.NoiseCertificate.Details.decode(certIntermediate.details);
114
+ if (issuerSerial !== Defaults_1.WA_CERT_DETAILS.SERIAL) {
115
+ throw new boom_1.Boom('certification match failed', { statusCode: 400 });
116
+ }
117
+ const keyEnc = encrypt(noiseKey.public);
118
+ await mixIntoKey(crypto_1.Curve.sharedKey(noiseKey.private, serverHello.ephemeral));
119
+ return keyEnc;
120
+ },
121
+ encodeFrame: (data) => {
122
+ if (isFinished) {
123
+ data = encrypt(data);
124
+ }
125
+ let header;
126
+ if (routingInfo) {
127
+ header = Buffer.alloc(7);
128
+ header.write('ED', 0, 'utf8');
129
+ header.writeUint8(0, 2);
130
+ header.writeUint8(1, 3);
131
+ header.writeUint8(routingInfo.byteLength >> 16, 4);
132
+ header.writeUint16BE(routingInfo.byteLength & 65535, 5);
133
+ header = Buffer.concat([header, routingInfo, NOISE_HEADER]);
134
+ }
135
+ else {
136
+ header = Buffer.from(NOISE_HEADER);
137
+ }
138
+ const introSize = sentIntro ? 0 : header.length;
139
+ const frame = Buffer.alloc(introSize + 3 + data.byteLength);
140
+ if (!sentIntro) {
141
+ frame.set(header);
142
+ sentIntro = true;
143
+ }
144
+ frame.writeUInt8(data.byteLength >> 16, introSize);
145
+ frame.writeUInt16BE(65535 & data.byteLength, introSize + 1);
146
+ frame.set(data, introSize + 3);
147
+ return frame;
148
+ },
149
+ decodeFrame: async (newData, onFrame) => {
150
+ var _a;
151
+
152
+
153
+
154
+ const getBytesSize = () => {
155
+ if (inBytes.length >= 3) {
156
+ return (inBytes.readUInt8() << 16) | inBytes.readUInt16BE(1);
157
+ }
158
+ };
159
+ inBytes = Buffer.concat([inBytes, newData]);
160
+ logger.trace(`recv ${newData.length} bytes, total recv ${inBytes.length} bytes`);
161
+ let size = getBytesSize();
162
+ while (size && inBytes.length >= size + 3) {
163
+ let frame = inBytes.slice(3, size + 3);
164
+ inBytes = inBytes.slice(size + 3);
165
+ if (isFinished) {
166
+ const result = decrypt(frame);
167
+ frame = await (0, WABinary_1.decodeBinaryNode)(result);
168
+ }
169
+ logger.trace({ msg: (_a = frame === null || frame === void 0 ? void 0 : frame.attrs) === null || _a === void 0 ? void 0 : _a.id }, 'recv frame');
170
+ onFrame(frame);
171
+ size = getBytesSize();
172
+ }
173
+ }
174
+ };
175
+ };
176
+ exports.makeNoiseHandler = makeNoiseHandler;
@@ -0,0 +1,13 @@
1
+ import PQueue from 'p-queue';
2
+ import { SignalDataSet, SignalDataTypeMap, SignalKeyStore } from '../Types';
3
+ import { ILogger } from './logger';
4
+ export declare class PreKeyManager {
5
+ private readonly store;
6
+ private readonly logger;
7
+ private readonly queues;
8
+ constructor(store: SignalKeyStore, logger: ILogger);
9
+ private getQueue;
10
+ processOperations(data: SignalDataSet, keyType: keyof SignalDataTypeMap, transactionCache: SignalDataSet, mutations: SignalDataSet, isInTransaction: boolean): Promise<void>;
11
+ private processDeletions;
12
+ validateDeletions(data: SignalDataSet, keyType: keyof SignalDataTypeMap): Promise<void>;
13
+ }
@@ -0,0 +1,93 @@
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
+ class PreKeyManager {
9
+ queues = new Map();
10
+ constructor(store, logger) {
11
+ this.store = store;
12
+ this.logger = logger;
13
+ }
14
+ getQueue(keyType) {
15
+ if (!this.queues.has(keyType)) {
16
+ this.queues.set(keyType, new p_queue_1.default({ concurrency: 1 }));
17
+ }
18
+ return this.queues.get(keyType);
19
+ }
20
+ async processOperations(data, keyType, transactionCache, mutations, isInTransaction) {
21
+ const keyData = data[keyType];
22
+ if (!keyData) {
23
+ return;
24
+ }
25
+ return this.getQueue(keyType).add(async () => {
26
+ transactionCache[keyType] = transactionCache[keyType] || {};
27
+ mutations[keyType] = mutations[keyType] || {};
28
+ const deletions = [];
29
+ const updates = {};
30
+ for (const keyId in keyData) {
31
+ if (keyData[keyId] === null) {
32
+ deletions.push(keyId);
33
+ }
34
+ else {
35
+ updates[keyId] = keyData[keyId];
36
+ }
37
+ }
38
+ if (Object.keys(updates).length > 0) {
39
+ Object.assign(transactionCache[keyType], updates);
40
+ Object.assign(mutations[keyType], updates);
41
+ }
42
+ if (deletions.length > 0) {
43
+ await this.processDeletions(keyType, deletions, transactionCache, mutations, isInTransaction);
44
+ }
45
+ });
46
+ }
47
+ async processDeletions(keyType, ids, transactionCache, mutations, isInTransaction) {
48
+ if (isInTransaction) {
49
+ for (const keyId of ids) {
50
+ var _a;
51
+ if ((_a = transactionCache[keyType]) === null || _a === void 0 ? void 0 : _a[keyId]) {
52
+ transactionCache[keyType][keyId] = null;
53
+ mutations[keyType][keyId] = null;
54
+ }
55
+ else {
56
+ this.logger.warn(`Skipping deletion of non-existent ${keyType} in transaction: ${keyId}`);
57
+ }
58
+ }
59
+ }
60
+ else {
61
+ const existingKeys = await this.store.get(keyType, ids);
62
+ for (const keyId of ids) {
63
+ if (existingKeys[keyId]) {
64
+ transactionCache[keyType][keyId] = null;
65
+ mutations[keyType][keyId] = null;
66
+ }
67
+ else {
68
+ this.logger.warn(`Skipping deletion of non-existent ${keyType}: ${keyId}`);
69
+ }
70
+ }
71
+ }
72
+ }
73
+ async validateDeletions(data, keyType) {
74
+ const keyData = data[keyType];
75
+ if (!keyData) {
76
+ return;
77
+ }
78
+ return this.getQueue(keyType).add(async () => {
79
+ const deletionIds = Object.keys(keyData).filter(id => keyData[id] === null);
80
+ if (deletionIds.length === 0) {
81
+ return;
82
+ }
83
+ const existingKeys = await this.store.get(keyType, deletionIds);
84
+ for (const keyId of deletionIds) {
85
+ if (!existingKeys[keyId]) {
86
+ this.logger.warn(`Skipping deletion of non-existent ${keyType}: ${keyId}`);
87
+ delete data[keyType][keyId];
88
+ }
89
+ }
90
+ });
91
+ }
92
+ }
93
+ exports.PreKeyManager = PreKeyManager;
@@ -0,0 +1,40 @@
1
+ export const __esModule: boolean;
2
+ export default processMessage;
3
+ /**
4
+ * Decrypt a poll vote
5
+ * @param vote encrypted vote
6
+ * @param ctx additional info about the poll required for decryption
7
+ * @returns list of SHA256 options
8
+ */
9
+ export function decryptPollVote({ encPayload, encIv }: {
10
+ encPayload: any;
11
+ encIv: any;
12
+ }, { pollCreatorJid, pollMsgId, pollEncKey, voterJid, }: {
13
+ pollCreatorJid: any;
14
+ pollMsgId: any;
15
+ pollEncKey: any;
16
+ voterJid: any;
17
+ }): any;
18
+ /** Cleans a received message to further processing */
19
+ export function cleanMessage(message: any, meId: any): void;
20
+ export function isRealMessage(message: any, meId: any): boolean;
21
+ export function shouldIncrementChatUnread(message: any): boolean;
22
+ /**
23
+ * Get the ID of the chat from the given key.
24
+ * Typically -- that'll be the remoteJid, but for broadcasts, it'll be the participant
25
+ */
26
+ export function getChatId({ remoteJid, participant, fromMe }: {
27
+ remoteJid: any;
28
+ participant: any;
29
+ fromMe: any;
30
+ }): any;
31
+ declare function processMessage(message: any, { shouldProcessHistoryMsg, placeholderResendCache, ev, creds, keyStore, logger, options, getMessage }: {
32
+ shouldProcessHistoryMsg: any;
33
+ placeholderResendCache: any;
34
+ ev: any;
35
+ creds: any;
36
+ keyStore: any;
37
+ logger: any;
38
+ options: any;
39
+ getMessage: any;
40
+ }): Promise<void>;