astrabail 1.0.6

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 (224) hide show
  1. package/WAProto/GenerateStatics.sh +3 -0
  2. package/WAProto/WAProto.proto +5479 -0
  3. package/WAProto/fix-imports.js +73 -0
  4. package/WAProto/index.d.ts +14017 -0
  5. package/WAProto/index.js +89351 -0
  6. package/WAProto/p.html +1 -0
  7. package/engine-requirements.js +7 -0
  8. package/lib/Defaults/astrabail-version.json +8 -0
  9. package/lib/Defaults/index.d.ts +74 -0
  10. package/lib/Defaults/index.js +166 -0
  11. package/lib/Defaults/phonenumber-mcc.json +223 -0
  12. package/lib/Defaults/update-wa-version.js +75 -0
  13. package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
  14. package/lib/Signal/Group/ciphertext-message.js +15 -0
  15. package/lib/Signal/Group/group-session-builder.d.ts +15 -0
  16. package/lib/Signal/Group/group-session-builder.js +66 -0
  17. package/lib/Signal/Group/group_cipher.d.ts +17 -0
  18. package/lib/Signal/Group/group_cipher.js +85 -0
  19. package/lib/Signal/Group/index.d.ts +12 -0
  20. package/lib/Signal/Group/index.js +57 -0
  21. package/lib/Signal/Group/keyhelper.d.ts +11 -0
  22. package/lib/Signal/Group/keyhelper.js +55 -0
  23. package/lib/Signal/Group/queue-job.js +57 -0
  24. package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
  25. package/lib/Signal/Group/sender-chain-key.js +29 -0
  26. package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
  27. package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
  28. package/lib/Signal/Group/sender-key-message.d.ts +19 -0
  29. package/lib/Signal/Group/sender-key-message.js +69 -0
  30. package/lib/Signal/Group/sender-key-name.d.ts +18 -0
  31. package/lib/Signal/Group/sender-key-name.js +51 -0
  32. package/lib/Signal/Group/sender-key-record.d.ts +31 -0
  33. package/lib/Signal/Group/sender-key-record.js +44 -0
  34. package/lib/Signal/Group/sender-key-state.d.ts +39 -0
  35. package/lib/Signal/Group/sender-key-state.js +87 -0
  36. package/lib/Signal/Group/sender-message-key.d.ts +12 -0
  37. package/lib/Signal/Group/sender-message-key.js +29 -0
  38. package/lib/Signal/libsignal.d.ts +5 -0
  39. package/lib/Signal/libsignal.js +478 -0
  40. package/lib/Signal/lid-mapping.d.ts +19 -0
  41. package/lib/Signal/lid-mapping.js +274 -0
  42. package/lib/Socket/Client/index.d.ts +3 -0
  43. package/lib/Socket/Client/index.js +18 -0
  44. package/lib/Socket/Client/types.d.ts +16 -0
  45. package/lib/Socket/Client/types.js +14 -0
  46. package/lib/Socket/Client/websocket.d.ts +13 -0
  47. package/lib/Socket/Client/websocket.js +60 -0
  48. package/lib/Socket/business.d.ts +202 -0
  49. package/lib/Socket/business.js +382 -0
  50. package/lib/Socket/chats.d.ts +111 -0
  51. package/lib/Socket/chats.js +1155 -0
  52. package/lib/Socket/communities.d.ts +258 -0
  53. package/lib/Socket/communities.js +438 -0
  54. package/lib/Socket/community.js +333 -0
  55. package/lib/Socket/groups.d.ts +150 -0
  56. package/lib/Socket/groups.js +470 -0
  57. package/lib/Socket/index.d.ts +245 -0
  58. package/lib/Socket/index.js +13 -0
  59. package/lib/Socket/messages-recv.d.ts +187 -0
  60. package/lib/Socket/messages-recv.js +1708 -0
  61. package/lib/Socket/messages-send.d.ts +183 -0
  62. package/lib/Socket/messages-send.js +1692 -0
  63. package/lib/Socket/mex.d.ts +3 -0
  64. package/lib/Socket/mex.js +45 -0
  65. package/lib/Socket/newsletter.d.ts +160 -0
  66. package/lib/Socket/newsletter.js +293 -0
  67. package/lib/Socket/socket.d.ts +55 -0
  68. package/lib/Socket/socket.js +947 -0
  69. package/lib/Socket/usync.js +70 -0
  70. package/lib/Store/index.js +20 -0
  71. package/lib/Store/make-cache-manager-store.js +83 -0
  72. package/lib/Store/make-in-memory-store.js +398 -0
  73. package/lib/Store/make-ordered-dictionary.js +81 -0
  74. package/lib/Store/object-repository.js +27 -0
  75. package/lib/Types/Auth.d.ts +116 -0
  76. package/lib/Types/Auth.js +2 -0
  77. package/lib/Types/Bussines.d.ts +25 -0
  78. package/lib/Types/Bussines.js +2 -0
  79. package/lib/Types/Call.d.ts +15 -0
  80. package/lib/Types/Call.js +2 -0
  81. package/lib/Types/Chat.d.ts +123 -0
  82. package/lib/Types/Chat.js +10 -0
  83. package/lib/Types/Contact.d.ts +24 -0
  84. package/lib/Types/Contact.js +2 -0
  85. package/lib/Types/Events.d.ts +237 -0
  86. package/lib/Types/Events.js +3 -0
  87. package/lib/Types/GroupMetadata.d.ts +67 -0
  88. package/lib/Types/GroupMetadata.js +2 -0
  89. package/lib/Types/Label.d.ts +47 -0
  90. package/lib/Types/Label.js +25 -0
  91. package/lib/Types/LabelAssociation.d.ts +30 -0
  92. package/lib/Types/LabelAssociation.js +7 -0
  93. package/lib/Types/Message.d.ts +305 -0
  94. package/lib/Types/Message.js +11 -0
  95. package/lib/Types/MexUpdates.js +11 -0
  96. package/lib/Types/Newsletter.d.ts +135 -0
  97. package/lib/Types/Newsletter.js +43 -0
  98. package/lib/Types/Product.d.ts +79 -0
  99. package/lib/Types/Product.js +2 -0
  100. package/lib/Types/Signal.d.ts +76 -0
  101. package/lib/Types/Signal.js +3 -0
  102. package/lib/Types/Socket.d.ts +133 -0
  103. package/lib/Types/Socket.js +3 -0
  104. package/lib/Types/State.d.ts +39 -0
  105. package/lib/Types/State.js +14 -0
  106. package/lib/Types/USync.d.ts +26 -0
  107. package/lib/Types/USync.js +3 -0
  108. package/lib/Types/index.d.ts +65 -0
  109. package/lib/Types/index.js +42 -0
  110. package/lib/Utils/astrabail-event-stream.js +3 -0
  111. package/lib/Utils/audioToBuffer.js +31 -0
  112. package/lib/Utils/auth-utils.d.ts +19 -0
  113. package/lib/Utils/auth-utils.js +298 -0
  114. package/lib/Utils/baileys-event-stream.js +60 -0
  115. package/lib/Utils/bridge-runtime.d.ts +1 -0
  116. package/lib/Utils/bridge-runtime.js +14 -0
  117. package/lib/Utils/browser-utils.d.ts +4 -0
  118. package/lib/Utils/browser-utils.js +44 -0
  119. package/lib/Utils/business.d.ts +23 -0
  120. package/lib/Utils/business.js +240 -0
  121. package/lib/Utils/chat-utils.d.ts +70 -0
  122. package/lib/Utils/chat-utils.js +825 -0
  123. package/lib/Utils/crypto.d.ts +37 -0
  124. package/lib/Utils/crypto.js +168 -0
  125. package/lib/Utils/decode-wa-message.d.ts +48 -0
  126. package/lib/Utils/decode-wa-message.js +287 -0
  127. package/lib/Utils/event-buffer.d.ts +34 -0
  128. package/lib/Utils/event-buffer.js +580 -0
  129. package/lib/Utils/generics.d.ts +91 -0
  130. package/lib/Utils/generics.js +483 -0
  131. package/lib/Utils/history.d.ts +22 -0
  132. package/lib/Utils/history.js +137 -0
  133. package/lib/Utils/identity-change-handler.d.ts +37 -0
  134. package/lib/Utils/identity-change-handler.js +54 -0
  135. package/lib/Utils/index.d.ts +22 -0
  136. package/lib/Utils/index.js +48 -0
  137. package/lib/Utils/link-preview.d.ts +21 -0
  138. package/lib/Utils/link-preview.js +121 -0
  139. package/lib/Utils/logger.d.ts +13 -0
  140. package/lib/Utils/logger.js +7 -0
  141. package/lib/Utils/lt-hash.d.ts +8 -0
  142. package/lib/Utils/lt-hash.js +10 -0
  143. package/lib/Utils/make-mutex.d.ts +9 -0
  144. package/lib/Utils/make-mutex.js +37 -0
  145. package/lib/Utils/message-retry-manager.d.ts +110 -0
  146. package/lib/Utils/message-retry-manager.js +226 -0
  147. package/lib/Utils/messages-media.d.ts +130 -0
  148. package/lib/Utils/messages-media.js +887 -0
  149. package/lib/Utils/messages-newsletter.d.ts +84 -0
  150. package/lib/Utils/messages-newsletter.js +295 -0
  151. package/lib/Utils/messages.d.ts +92 -0
  152. package/lib/Utils/messages.js +1752 -0
  153. package/lib/Utils/noise-handler.d.ts +20 -0
  154. package/lib/Utils/noise-handler.js +204 -0
  155. package/lib/Utils/pre-key-manager.d.ts +28 -0
  156. package/lib/Utils/pre-key-manager.js +112 -0
  157. package/lib/Utils/process-message.d.ts +60 -0
  158. package/lib/Utils/process-message.js +536 -0
  159. package/lib/Utils/reporting-utils.d.ts +11 -0
  160. package/lib/Utils/reporting-utils.js +262 -0
  161. package/lib/Utils/resolve-jid.d.ts +43 -0
  162. package/lib/Utils/resolve-jid.js +95 -0
  163. package/lib/Utils/rust-bridge-shim.d.ts +22 -0
  164. package/lib/Utils/rust-bridge-shim.js +70 -0
  165. package/lib/Utils/serial-task-queue.js +29 -0
  166. package/lib/Utils/signal.d.ts +34 -0
  167. package/lib/Utils/signal.js +170 -0
  168. package/lib/Utils/streamToBuffer.js +17 -0
  169. package/lib/Utils/sync-action-utils.d.ts +19 -0
  170. package/lib/Utils/sync-action-utils.js +52 -0
  171. package/lib/Utils/tc-token-utils.d.ts +12 -0
  172. package/lib/Utils/tc-token-utils.js +20 -0
  173. package/lib/Utils/use-mongo-file-auth-state.js +71 -0
  174. package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
  175. package/lib/Utils/use-multi-file-auth-state.js +124 -0
  176. package/lib/Utils/use-single-file-auth-state.js +73 -0
  177. package/lib/Utils/validate-connection.d.ts +11 -0
  178. package/lib/Utils/validate-connection.js +206 -0
  179. package/lib/WABinary/constants.d.ts +28 -0
  180. package/lib/WABinary/constants.js +1303 -0
  181. package/lib/WABinary/decode.d.ts +7 -0
  182. package/lib/WABinary/decode.js +300 -0
  183. package/lib/WABinary/encode.d.ts +3 -0
  184. package/lib/WABinary/encode.js +256 -0
  185. package/lib/WABinary/generic-utils.d.ts +15 -0
  186. package/lib/WABinary/generic-utils.js +138 -0
  187. package/lib/WABinary/index.d.ts +6 -0
  188. package/lib/WABinary/index.js +25 -0
  189. package/lib/WABinary/jid-utils.d.ts +48 -0
  190. package/lib/WABinary/jid-utils.js +115 -0
  191. package/lib/WABinary/types.d.ts +19 -0
  192. package/lib/WABinary/types.js +36 -0
  193. package/lib/WAM/BinaryInfo.d.ts +9 -0
  194. package/lib/WAM/BinaryInfo.js +13 -0
  195. package/lib/WAM/constants.d.ts +40 -0
  196. package/lib/WAM/constants.js +22855 -0
  197. package/lib/WAM/encode.d.ts +3 -0
  198. package/lib/WAM/encode.js +153 -0
  199. package/lib/WAM/index.d.ts +4 -0
  200. package/lib/WAM/index.js +19 -0
  201. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
  202. package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
  203. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
  204. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
  205. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
  206. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
  207. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
  208. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +41 -0
  209. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
  210. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +54 -0
  211. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
  212. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +32 -0
  213. package/lib/WAUSync/Protocols/index.d.ts +5 -0
  214. package/lib/WAUSync/Protocols/index.js +22 -0
  215. package/lib/WAUSync/USyncQuery.d.ts +29 -0
  216. package/lib/WAUSync/USyncQuery.js +97 -0
  217. package/lib/WAUSync/USyncUser.d.ts +13 -0
  218. package/lib/WAUSync/USyncUser.js +26 -0
  219. package/lib/WAUSync/index.d.ts +4 -0
  220. package/lib/WAUSync/index.js +19 -0
  221. package/lib/index.d.ts +12 -0
  222. package/lib/index.js +124 -0
  223. package/package.json +120 -0
  224. package/readme.md +1956 -0
@@ -0,0 +1,298 @@
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.initAuthCreds = exports.addTransactionCapability = void 0;
7
+ exports.makeCacheableSignalKeyStore = makeCacheableSignalKeyStore;
8
+ const node_cache_1 = __importDefault(require("@cacheable/node-cache"));
9
+ const async_hooks_1 = require("async_hooks");
10
+ const async_mutex_1 = require("async-mutex");
11
+ const crypto_1 = require("crypto");
12
+ const serial_task_queue_js_1 = __importDefault(require("./serial-task-queue.js"));
13
+ const index_js_1 = require("../Defaults/index.js");
14
+ const crypto_js_1 = require("./crypto.js");
15
+ const generics_js_1 = require("./generics.js");
16
+ const pre_key_manager_js_1 = require("./pre-key-manager.js");
17
+ /**
18
+ * Adds caching capability to a SignalKeyStore
19
+ * @param store the store to add caching to
20
+ * @param logger to log trace events
21
+ * @param _cache cache store to use
22
+ */
23
+ function makeCacheableSignalKeyStore(store, logger, _cache) {
24
+ const cache = _cache ||
25
+ new node_cache_1.default({
26
+ stdTTL: index_js_1.DEFAULT_CACHE_TTLS.SIGNAL_STORE, // 5 minutes
27
+ useClones: false,
28
+ deleteOnExpire: true
29
+ });
30
+ // Mutex for protecting cache operations
31
+ const cacheMutex = new async_mutex_1.Mutex();
32
+ function getUniqueId(type, id) {
33
+ return `${type}.${id}`;
34
+ }
35
+ return {
36
+ async get(type, ids) {
37
+ return cacheMutex.runExclusive(async () => {
38
+ const data = {};
39
+ const idsToFetch = [];
40
+ for (const id of ids) {
41
+ const item = (await cache.get(getUniqueId(type, id)));
42
+ if (typeof item !== 'undefined') {
43
+ data[id] = item;
44
+ }
45
+ else {
46
+ idsToFetch.push(id);
47
+ }
48
+ }
49
+ if (idsToFetch.length) {
50
+ logger?.trace({ items: idsToFetch.length }, 'loading from store');
51
+ const fetched = await store.get(type, idsToFetch);
52
+ for (const id of idsToFetch) {
53
+ const item = fetched[id];
54
+ if (item) {
55
+ data[id] = item;
56
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
57
+ await cache.set(getUniqueId(type, id), item);
58
+ }
59
+ }
60
+ }
61
+ return data;
62
+ });
63
+ },
64
+ async set(data) {
65
+ return cacheMutex.runExclusive(async () => {
66
+ let keys = 0;
67
+ for (const type in data) {
68
+ for (const id in data[type]) {
69
+ await cache.set(getUniqueId(type, id), data[type][id]);
70
+ keys += 1;
71
+ }
72
+ }
73
+ logger?.trace({ keys }, 'updated cache');
74
+ await store.set(data);
75
+ });
76
+ },
77
+ async clear() {
78
+ await cache.flushAll();
79
+ await store.clear?.();
80
+ }
81
+ };
82
+ }
83
+ /**
84
+ * Adds DB-like transaction capability to the SignalKeyStore
85
+ * Uses AsyncLocalStorage for automatic context management
86
+ * @param state the key store to apply this capability to
87
+ * @param logger logger to log events
88
+ * @returns SignalKeyStore with transaction capability
89
+ */
90
+ const addTransactionCapability = (state, logger, { maxCommitRetries, delayBetweenTriesMs }) => {
91
+ const txStorage = new async_hooks_1.AsyncLocalStorage();
92
+ // Queues for concurrency control (keyed by signal data type - bounded set)
93
+ const keyQueues = new Map();
94
+ // Transaction mutexes with reference counting for cleanup
95
+ const txMutexes = new Map();
96
+ const txMutexRefCounts = new Map();
97
+ // Pre-key manager for specialized operations
98
+ const preKeyManager = new pre_key_manager_js_1.PreKeyManager(state, logger);
99
+ /**
100
+ * Get or create a queue for a specific key type
101
+ */
102
+ function getQueue(key) {
103
+ if (!keyQueues.has(key)) {
104
+ keyQueues.set(key, new serial_task_queue_js_1.default({ concurrency: 1 }));
105
+ }
106
+ return keyQueues.get(key);
107
+ }
108
+ /**
109
+ * Get or create a transaction mutex
110
+ */
111
+ function getTxMutex(key) {
112
+ if (!txMutexes.has(key)) {
113
+ txMutexes.set(key, new async_mutex_1.Mutex());
114
+ txMutexRefCounts.set(key, 0);
115
+ }
116
+ return txMutexes.get(key);
117
+ }
118
+ /**
119
+ * Acquire a reference to a transaction mutex
120
+ */
121
+ function acquireTxMutexRef(key) {
122
+ const count = txMutexRefCounts.get(key) ?? 0;
123
+ txMutexRefCounts.set(key, count + 1);
124
+ }
125
+ /**
126
+ * Release a reference to a transaction mutex and cleanup if no longer needed
127
+ */
128
+ function releaseTxMutexRef(key) {
129
+ const count = (txMutexRefCounts.get(key) ?? 1) - 1;
130
+ txMutexRefCounts.set(key, count);
131
+ // Cleanup if no more references and mutex is not locked
132
+ if (count <= 0) {
133
+ const mutex = txMutexes.get(key);
134
+ if (mutex && !mutex.isLocked()) {
135
+ txMutexes.delete(key);
136
+ txMutexRefCounts.delete(key);
137
+ }
138
+ }
139
+ }
140
+ /**
141
+ * Check if currently in a transaction
142
+ */
143
+ function isInTransaction() {
144
+ return !!txStorage.getStore();
145
+ }
146
+ /**
147
+ * Commit transaction with retries
148
+ */
149
+ async function commitWithRetry(mutations) {
150
+ if (Object.keys(mutations).length === 0) {
151
+ logger.trace('no mutations in transaction');
152
+ return;
153
+ }
154
+ logger.trace('committing transaction');
155
+ for (let attempt = 0; attempt < maxCommitRetries; attempt++) {
156
+ try {
157
+ await state.set(mutations);
158
+ logger.trace({ mutationCount: Object.keys(mutations).length }, 'committed transaction');
159
+ return;
160
+ }
161
+ catch (error) {
162
+ const retriesLeft = maxCommitRetries - attempt - 1;
163
+ logger.warn(`failed to commit mutations, retries left=${retriesLeft}`);
164
+ if (retriesLeft === 0) {
165
+ throw error;
166
+ }
167
+ await (0, generics_js_1.delay)(delayBetweenTriesMs);
168
+ }
169
+ }
170
+ }
171
+ return {
172
+ get: async (type, ids) => {
173
+ const ctx = txStorage.getStore();
174
+ if (!ctx) {
175
+ // No transaction - direct read without exclusive lock for concurrency
176
+ return state.get(type, ids);
177
+ }
178
+ // In transaction - check cache first
179
+ const cached = ctx.cache[type] || {};
180
+ const missing = ids.filter(id => !(id in cached));
181
+ if (missing.length > 0) {
182
+ ctx.dbQueries++;
183
+ logger.trace({ type, count: missing.length }, 'fetching missing keys in transaction');
184
+ const fetched = await getTxMutex(type).runExclusive(() => state.get(type, missing));
185
+ // Update cache
186
+ ctx.cache[type] = ctx.cache[type] || {};
187
+ Object.assign(ctx.cache[type], fetched);
188
+ }
189
+ // Return requested ids from cache
190
+ const result = {};
191
+ for (const id of ids) {
192
+ const value = ctx.cache[type]?.[id];
193
+ if (value !== undefined && value !== null) {
194
+ result[id] = value;
195
+ }
196
+ }
197
+ return result;
198
+ },
199
+ set: async (data) => {
200
+ const ctx = txStorage.getStore();
201
+ if (!ctx) {
202
+ // No transaction - direct write with queue protection
203
+ const types = Object.keys(data);
204
+ // Process pre-keys with validation
205
+ for (const type_ of types) {
206
+ const type = type_;
207
+ if (type === 'pre-key') {
208
+ await preKeyManager.validateDeletions(data, type);
209
+ }
210
+ }
211
+ // Write all data in parallel
212
+ await Promise.all(types.map(type => getQueue(type).add(async () => {
213
+ const typeData = { [type]: data[type] };
214
+ await state.set(typeData);
215
+ })));
216
+ return;
217
+ }
218
+ // In transaction - update cache and mutations
219
+ logger.trace({ types: Object.keys(data) }, 'caching in transaction');
220
+ for (const key_ in data) {
221
+ const key = key_;
222
+ // Ensure structures exist
223
+ ctx.cache[key] = ctx.cache[key] || {};
224
+ ctx.mutations[key] = ctx.mutations[key] || {};
225
+ // Special handling for pre-keys
226
+ if (key === 'pre-key') {
227
+ await preKeyManager.processOperations(data, key, ctx.cache, ctx.mutations, true);
228
+ }
229
+ else {
230
+ // Normal key types
231
+ Object.assign(ctx.cache[key], data[key]);
232
+ Object.assign(ctx.mutations[key], data[key]);
233
+ }
234
+ }
235
+ },
236
+ isInTransaction,
237
+ transaction: async (work, key) => {
238
+ const existing = txStorage.getStore();
239
+ // Nested transaction - reuse existing context
240
+ if (existing) {
241
+ logger.trace('reusing existing transaction context');
242
+ return work();
243
+ }
244
+ // New transaction - acquire mutex and create context
245
+ const mutex = getTxMutex(key);
246
+ acquireTxMutexRef(key);
247
+ try {
248
+ return await mutex.runExclusive(async () => {
249
+ const ctx = {
250
+ cache: {},
251
+ mutations: {},
252
+ dbQueries: 0
253
+ };
254
+ logger.trace('entering transaction');
255
+ try {
256
+ const result = await txStorage.run(ctx, work);
257
+ // Commit mutations
258
+ await commitWithRetry(ctx.mutations);
259
+ logger.trace({ dbQueries: ctx.dbQueries }, 'transaction completed');
260
+ return result;
261
+ }
262
+ catch (error) {
263
+ logger.error({ error }, 'transaction failed, rolling back');
264
+ throw error;
265
+ }
266
+ });
267
+ }
268
+ finally {
269
+ releaseTxMutexRef(key);
270
+ }
271
+ }
272
+ };
273
+ };
274
+ exports.addTransactionCapability = addTransactionCapability;
275
+ const initAuthCreds = () => {
276
+ const identityKey = crypto_js_1.Curve.generateKeyPair();
277
+ return {
278
+ noiseKey: crypto_js_1.Curve.generateKeyPair(),
279
+ pairingEphemeralKeyPair: crypto_js_1.Curve.generateKeyPair(),
280
+ signedIdentityKey: identityKey,
281
+ signedPreKey: (0, crypto_js_1.signedKeyPair)(identityKey, 1),
282
+ registrationId: (0, generics_js_1.generateRegistrationId)(),
283
+ advSecretKey: (0, crypto_1.randomBytes)(32).toString('base64'),
284
+ processedHistoryMessages: [],
285
+ nextPreKeyId: 1,
286
+ firstUnuploadedPreKeyId: 1,
287
+ accountSyncCounter: 0,
288
+ accountSettings: {
289
+ unarchiveChats: false
290
+ },
291
+ registered: false,
292
+ pairingCode: undefined,
293
+ lastPropHash: undefined,
294
+ routingInfo: undefined,
295
+ additionalData: undefined
296
+ };
297
+ };
298
+ exports.initAuthCreds = initAuthCreds;
@@ -0,0 +1,60 @@
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.readAndEmitEventStream = exports.captureEventStream = void 0;
7
+ const events_1 = __importDefault(require("events"));
8
+ const fs_1 = require("fs");
9
+ const promises_1 = require("fs/promises");
10
+ const readline_1 = require("readline");
11
+ const generics_js_1 = require("./generics.js");
12
+ const make_mutex_js_1 = require("./make-mutex.js");
13
+ /**
14
+ * Captures events from a baileys event emitter & stores them in a file
15
+ * @param ev The event emitter to read events from
16
+ * @param filename File to save to
17
+ */
18
+ const captureEventStream = (ev, filename) => {
19
+ const oldEmit = ev.emit;
20
+ // write mutex so data is appended in order
21
+ const writeMutex = (0, make_mutex_js_1.makeMutex)();
22
+ // monkey patch eventemitter to capture all events
23
+ ev.emit = function (...args) {
24
+ const content = JSON.stringify({ timestamp: Date.now(), event: args[0], data: args[1] }) + '\n';
25
+ const result = oldEmit.apply(ev, args);
26
+ writeMutex.mutex(async () => {
27
+ await (0, promises_1.writeFile)(filename, content, { flag: 'a' });
28
+ });
29
+ return result;
30
+ };
31
+ };
32
+ exports.captureEventStream = captureEventStream;
33
+ /**
34
+ * Read event file and emit events from there
35
+ * @param filename filename containing event data
36
+ * @param delayIntervalMs delay between each event emit
37
+ */
38
+ const readAndEmitEventStream = (filename, delayIntervalMs = 0) => {
39
+ const ev = new events_1.default();
40
+ const fireEvents = async () => {
41
+ const fileStream = (0, fs_1.createReadStream)(filename);
42
+ const rl = (0, readline_1.createInterface)({
43
+ input: fileStream,
44
+ crlfDelay: Infinity
45
+ });
46
+ for await (const line of rl) {
47
+ if (line) {
48
+ const { event, data } = JSON.parse(line);
49
+ ev.emit(event, data);
50
+ delayIntervalMs && await (0, generics_js_1.delay)(delayIntervalMs);
51
+ }
52
+ }
53
+ fileStream.close();
54
+ };
55
+ return {
56
+ ev,
57
+ task: fireEvents()
58
+ };
59
+ };
60
+ exports.readAndEmitEventStream = readAndEmitEventStream;
@@ -0,0 +1 @@
1
+ export { md5, hkdf, expandAppStateKeys, LTHashAntiTampering } from './rust-bridge-shim.js';
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LTHashAntiTampering = exports.expandAppStateKeys = exports.hkdf = exports.md5 = void 0;
4
+ let runtime;
5
+ try {
6
+ runtime = require("whatsapp-rust-bridge");
7
+ }
8
+ catch (error) {
9
+ runtime = require("./rust-bridge-shim.js");
10
+ }
11
+ exports.md5 = runtime.md5;
12
+ exports.hkdf = runtime.hkdf;
13
+ exports.expandAppStateKeys = runtime.expandAppStateKeys;
14
+ exports.LTHashAntiTampering = runtime.LTHashAntiTampering;
@@ -0,0 +1,4 @@
1
+ import type { BrowsersMap } from '../Types/index.js';
2
+ export declare const Browsers: BrowsersMap;
3
+ export declare const getPlatformId: (browser: string) => string;
4
+ //# sourceMappingURL=browser-utils.d.ts.map
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPlatformId = exports.Browsers = exports.PLATFORM_VERSIONS = exports.PLATFORM_MAP = void 0;
4
+ const os_1 = require("os");
5
+ const index_js_1 = require("../../WAProto/index.js");
6
+ exports.PLATFORM_MAP = {
7
+ 'aix': 'AIX', 'darwin': 'Mac OS', 'win32': 'Windows', 'android': 'Android',
8
+ 'freebsd': 'FreeBSD', 'openbsd': 'OpenBSD', 'sunos': 'Solaris', 'linux': 'Linux',
9
+ 'ubuntu': 'Ubuntu', 'ios': 'iOS', 'baileys': 'Baileys', 'chromeos': 'Chrome OS',
10
+ 'tizen': 'Tizen', 'watchos': 'watchOS', 'wearos': 'Wear OS', 'harmonyos': 'HarmonyOS',
11
+ 'kaios': 'KaiOS', 'smarttv': 'Smart TV', 'raspberrypi': 'Raspberry Pi OS',
12
+ 'symbian': 'Symbian', 'blackberry': 'Blackberry OS', 'windowsphone': 'Windows Phone'
13
+ };
14
+ exports.PLATFORM_VERSIONS = {
15
+ 'ubuntu': '22.04.4', 'darwin': '18.5', 'win32': '10.0.22631', 'android': '14.0.0',
16
+ 'freebsd': '13.2', 'openbsd': '7.3', 'sunos': '11', 'linux': '6.5', 'ios': '18.2',
17
+ 'baileys': '6.5.0', 'chromeos': '117.0.5938.132', 'tizen': '6.5', 'watchos': '10.1',
18
+ 'wearos': '4.1', 'harmonyos': '4.0.0', 'kaios': '3.1', 'smarttv': '23.3.1',
19
+ 'raspberrypi': '11 (Bullseye)', 'symbian': '3', 'blackberry': '10.3.3', 'windowsphone': '8.1'
20
+ };
21
+ exports.Browsers = {
22
+ ubuntu: (browser) => [exports.PLATFORM_MAP['ubuntu'], browser, exports.PLATFORM_VERSIONS['ubuntu']],
23
+ macOS: (browser) => [exports.PLATFORM_MAP['darwin'], browser, exports.PLATFORM_VERSIONS['darwin']],
24
+ windows: (browser) => [exports.PLATFORM_MAP['win32'], browser, exports.PLATFORM_VERSIONS['win32']],
25
+ linux: (browser) => [exports.PLATFORM_MAP['linux'], browser, exports.PLATFORM_VERSIONS['linux']],
26
+ solaris: (browser) => [exports.PLATFORM_MAP['sunos'], browser, exports.PLATFORM_VERSIONS['sunos']],
27
+ baileys: (browser) => [exports.PLATFORM_MAP['baileys'], browser, exports.PLATFORM_VERSIONS['baileys']],
28
+ android: (browser) => [exports.PLATFORM_MAP['android'], browser, exports.PLATFORM_VERSIONS['android']],
29
+ iOS: (browser) => [exports.PLATFORM_MAP['ios'], browser, exports.PLATFORM_VERSIONS['ios']],
30
+ kaiOS: (browser) => [exports.PLATFORM_MAP['kaios'], browser, exports.PLATFORM_VERSIONS['kaios']],
31
+ chromeOS: (browser) => [exports.PLATFORM_MAP['chromeos'], browser, exports.PLATFORM_VERSIONS['chromeos']],
32
+ appropriate: (browser) => {
33
+ const p = (0, os_1.platform)();
34
+ return [exports.PLATFORM_MAP[p] || 'Unknown OS', browser, exports.PLATFORM_VERSIONS[p] || 'latest'];
35
+ },
36
+ custom: (p, browser, version) => {
37
+ return [exports.PLATFORM_MAP[p.toLowerCase()] || p, browser, version || exports.PLATFORM_VERSIONS[p] || 'latest'];
38
+ }
39
+ };
40
+ const getPlatformId = (browser) => {
41
+ const platformType = index_js_1.proto.DeviceProps.PlatformType[browser.toUpperCase()];
42
+ return platformType ? platformType.toString() : '1';
43
+ };
44
+ exports.getPlatformId = getPlatformId;
@@ -0,0 +1,23 @@
1
+ import type { CatalogCollection, OrderDetails, Product, ProductCreate, ProductUpdate, WAMediaUpload, WAMediaUploadFunction } from '../Types/index.js';
2
+ import { type BinaryNode } from '../WABinary/index.js';
3
+ export declare const parseCatalogNode: (node: BinaryNode) => {
4
+ products: Product[];
5
+ nextPageCursor: string | undefined;
6
+ };
7
+ export declare const parseCollectionsNode: (node: BinaryNode) => {
8
+ collections: CatalogCollection[];
9
+ };
10
+ export declare const parseOrderDetailsNode: (node: BinaryNode) => OrderDetails;
11
+ export declare const toProductNode: (productId: string | undefined, product: ProductCreate | ProductUpdate) => BinaryNode;
12
+ export declare const parseProductNode: (productNode: BinaryNode) => Product;
13
+ /**
14
+ * Uploads images not already uploaded to WA's servers
15
+ */
16
+ export declare function uploadingNecessaryImagesOfProduct<T extends ProductUpdate | ProductCreate>(product: T, waUploadToServer: WAMediaUploadFunction, timeoutMs?: number): Promise<T>;
17
+ /**
18
+ * Uploads images not already uploaded to WA's servers
19
+ */
20
+ export declare const uploadingNecessaryImages: (images: WAMediaUpload[], waUploadToServer: WAMediaUploadFunction, timeoutMs?: number) => Promise<{
21
+ url: string;
22
+ }[]>;
23
+ //# sourceMappingURL=business.d.ts.map