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,226 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MessageRetryManager = exports.RetryReason = void 0;
4
+ const lru_cache_1 = require("lru-cache");
5
+ /** Number of sent messages to cache in memory for handling retry receipts */
6
+ const RECENT_MESSAGES_SIZE = 512;
7
+ const MESSAGE_KEY_SEPARATOR = '\u0000';
8
+ /** Timeout for session recreation - 1 hour */
9
+ const RECREATE_SESSION_TIMEOUT = 60 * 60 * 1000; // 1 hour in milliseconds
10
+ const PHONE_REQUEST_DELAY = 3000;
11
+ (function (RetryReason) {
12
+ RetryReason[RetryReason["UnknownError"] = 0] = "UnknownError";
13
+ RetryReason[RetryReason["SignalErrorNoSession"] = 1] = "SignalErrorNoSession";
14
+ RetryReason[RetryReason["SignalErrorInvalidKey"] = 2] = "SignalErrorInvalidKey";
15
+ RetryReason[RetryReason["SignalErrorInvalidKeyId"] = 3] = "SignalErrorInvalidKeyId";
16
+ /** MAC verification failed - most common cause of decryption failures */
17
+ RetryReason[RetryReason["SignalErrorInvalidMessage"] = 4] = "SignalErrorInvalidMessage";
18
+ RetryReason[RetryReason["SignalErrorInvalidSignature"] = 5] = "SignalErrorInvalidSignature";
19
+ RetryReason[RetryReason["SignalErrorFutureMessage"] = 6] = "SignalErrorFutureMessage";
20
+ /** Explicit MAC failure - session is definitely out of sync */
21
+ RetryReason[RetryReason["SignalErrorBadMac"] = 7] = "SignalErrorBadMac";
22
+ RetryReason[RetryReason["SignalErrorInvalidSession"] = 8] = "SignalErrorInvalidSession";
23
+ RetryReason[RetryReason["SignalErrorInvalidMsgKey"] = 9] = "SignalErrorInvalidMsgKey";
24
+ RetryReason[RetryReason["BadBroadcastEphemeralSetting"] = 10] = "BadBroadcastEphemeralSetting";
25
+ RetryReason[RetryReason["UnknownCompanionNoPrekey"] = 11] = "UnknownCompanionNoPrekey";
26
+ RetryReason[RetryReason["AdvFailure"] = 12] = "AdvFailure";
27
+ RetryReason[RetryReason["StatusRevokeDelay"] = 13] = "StatusRevokeDelay";
28
+ })(exports.RetryReason || (exports.RetryReason = {}));
29
+ /** Error codes that indicate a MAC failure and require immediate session recreation */
30
+ const MAC_ERROR_CODES = new Set([exports.RetryReason.SignalErrorInvalidMessage, exports.RetryReason.SignalErrorBadMac]);
31
+ class MessageRetryManager {
32
+ constructor(logger, maxMsgRetryCount) {
33
+ this.logger = logger;
34
+ this.recentMessagesMap = new lru_cache_1.LRUCache({
35
+ max: RECENT_MESSAGES_SIZE,
36
+ ttl: 5 * 60 * 1000,
37
+ ttlAutopurge: true,
38
+ dispose: (_value, key) => {
39
+ const separatorIndex = key.lastIndexOf(MESSAGE_KEY_SEPARATOR);
40
+ if (separatorIndex > -1) {
41
+ const messageId = key.slice(separatorIndex + MESSAGE_KEY_SEPARATOR.length);
42
+ this.messageKeyIndex.delete(messageId);
43
+ }
44
+ }
45
+ });
46
+ this.messageKeyIndex = new Map();
47
+ this.sessionRecreateHistory = new lru_cache_1.LRUCache({
48
+ ttl: RECREATE_SESSION_TIMEOUT * 2,
49
+ ttlAutopurge: true
50
+ });
51
+ this.retryCounters = new lru_cache_1.LRUCache({
52
+ ttl: 15 * 60 * 1000,
53
+ ttlAutopurge: true,
54
+ updateAgeOnGet: true
55
+ }); // 15 minutes TTL
56
+ this.pendingPhoneRequests = {};
57
+ this.maxMsgRetryCount = 5;
58
+ this.statistics = {
59
+ totalRetries: 0,
60
+ successfulRetries: 0,
61
+ failedRetries: 0,
62
+ mediaRetries: 0,
63
+ sessionRecreations: 0,
64
+ phoneRequests: 0
65
+ };
66
+ this.maxMsgRetryCount = maxMsgRetryCount;
67
+ }
68
+ /**
69
+ * Add a recent message to the cache for retry handling
70
+ */
71
+ addRecentMessage(to, id, message) {
72
+ const key = { to, id };
73
+ const keyStr = this.keyToString(key);
74
+ // Add new message
75
+ this.recentMessagesMap.set(keyStr, {
76
+ message,
77
+ timestamp: Date.now()
78
+ });
79
+ this.messageKeyIndex.set(id, keyStr);
80
+ this.logger.debug(`Added message to retry cache: ${to}/${id}`);
81
+ }
82
+ /**
83
+ * Get a recent message from the cache
84
+ */
85
+ getRecentMessage(to, id) {
86
+ const key = { to, id };
87
+ const keyStr = this.keyToString(key);
88
+ return this.recentMessagesMap.get(keyStr);
89
+ }
90
+ /**
91
+ * Check if a session should be recreated based on retry count, history, and error code.
92
+ * MAC errors (codes 4 and 7) trigger immediate session recreation regardless of timeout.
93
+ */
94
+ shouldRecreateSession(jid, hasSession, errorCode) {
95
+ // If we don't have a session, always recreate
96
+ if (!hasSession) {
97
+ this.sessionRecreateHistory.set(jid, Date.now());
98
+ this.statistics.sessionRecreations++;
99
+ return {
100
+ reason: "we don't have a Signal session with them",
101
+ recreate: true
102
+ };
103
+ }
104
+ // IMMEDIATE recreation for MAC errors - session is definitely out of sync
105
+ if (errorCode !== undefined && MAC_ERROR_CODES.has(errorCode)) {
106
+ this.sessionRecreateHistory.set(jid, Date.now());
107
+ this.statistics.sessionRecreations++;
108
+ this.logger.warn({ jid, errorCode: exports.RetryReason[errorCode] }, 'MAC error detected, forcing immediate session recreation');
109
+ return {
110
+ reason: `MAC error (code ${errorCode}: ${exports.RetryReason[errorCode]}), immediate session recreation`,
111
+ recreate: true
112
+ };
113
+ }
114
+ const now = Date.now();
115
+ const prevTime = this.sessionRecreateHistory.get(jid);
116
+ // If no previous recreation or it's been more than an hour
117
+ if (!prevTime || now - prevTime > RECREATE_SESSION_TIMEOUT) {
118
+ this.sessionRecreateHistory.set(jid, now);
119
+ this.statistics.sessionRecreations++;
120
+ return {
121
+ reason: 'retry count > 1 and over an hour since last recreation',
122
+ recreate: true
123
+ };
124
+ }
125
+ return { reason: '', recreate: false };
126
+ }
127
+ /**
128
+ * Parse error code from retry receipt's retry node.
129
+ * Returns undefined if no error code is present.
130
+ */
131
+ parseRetryErrorCode(errorAttr) {
132
+ if (errorAttr === undefined || errorAttr === '') {
133
+ return undefined;
134
+ }
135
+ const code = parseInt(errorAttr, 10);
136
+ if (Number.isNaN(code)) {
137
+ return undefined;
138
+ }
139
+ // Validate it's a known RetryReason
140
+ if (code >= exports.RetryReason.UnknownError && code <= exports.RetryReason.StatusRevokeDelay) {
141
+ return code;
142
+ }
143
+ return exports.RetryReason.UnknownError;
144
+ }
145
+ /**
146
+ * Check if an error code indicates a MAC failure
147
+ */
148
+ isMacError(errorCode) {
149
+ return errorCode !== undefined && MAC_ERROR_CODES.has(errorCode);
150
+ }
151
+ /**
152
+ * Increment retry counter for a message
153
+ */
154
+ incrementRetryCount(messageId) {
155
+ this.retryCounters.set(messageId, (this.retryCounters.get(messageId) || 0) + 1);
156
+ this.statistics.totalRetries++;
157
+ return this.retryCounters.get(messageId);
158
+ }
159
+ /**
160
+ * Get retry count for a message
161
+ */
162
+ getRetryCount(messageId) {
163
+ return this.retryCounters.get(messageId) || 0;
164
+ }
165
+ /**
166
+ * Check if message has exceeded maximum retry attempts
167
+ */
168
+ hasExceededMaxRetries(messageId) {
169
+ return this.getRetryCount(messageId) >= this.maxMsgRetryCount;
170
+ }
171
+ /**
172
+ * Mark retry as successful
173
+ */
174
+ markRetrySuccess(messageId) {
175
+ this.statistics.successfulRetries++;
176
+ // Clean up retry counter for successful message
177
+ this.retryCounters.delete(messageId);
178
+ this.cancelPendingPhoneRequest(messageId);
179
+ this.removeRecentMessage(messageId);
180
+ }
181
+ /**
182
+ * Mark retry as failed
183
+ */
184
+ markRetryFailed(messageId) {
185
+ this.statistics.failedRetries++;
186
+ this.retryCounters.delete(messageId);
187
+ this.cancelPendingPhoneRequest(messageId);
188
+ this.removeRecentMessage(messageId);
189
+ }
190
+ /**
191
+ * Schedule a phone request with delay
192
+ */
193
+ schedulePhoneRequest(messageId, callback, delay = PHONE_REQUEST_DELAY) {
194
+ // Cancel any existing request for this message
195
+ this.cancelPendingPhoneRequest(messageId);
196
+ this.pendingPhoneRequests[messageId] = setTimeout(() => {
197
+ delete this.pendingPhoneRequests[messageId];
198
+ this.statistics.phoneRequests++;
199
+ callback();
200
+ }, delay);
201
+ this.logger.debug(`Scheduled phone request for message ${messageId} with ${delay}ms delay`);
202
+ }
203
+ /**
204
+ * Cancel pending phone request
205
+ */
206
+ cancelPendingPhoneRequest(messageId) {
207
+ const timeout = this.pendingPhoneRequests[messageId];
208
+ if (timeout) {
209
+ clearTimeout(timeout);
210
+ delete this.pendingPhoneRequests[messageId];
211
+ this.logger.debug(`Cancelled pending phone request for message ${messageId}`);
212
+ }
213
+ }
214
+ keyToString(key) {
215
+ return `${key.to}${MESSAGE_KEY_SEPARATOR}${key.id}`;
216
+ }
217
+ removeRecentMessage(messageId) {
218
+ const keyStr = this.messageKeyIndex.get(messageId);
219
+ if (!keyStr) {
220
+ return;
221
+ }
222
+ this.recentMessagesMap.delete(keyStr);
223
+ this.messageKeyIndex.delete(messageId);
224
+ }
225
+ }
226
+ exports.MessageRetryManager = MessageRetryManager;
@@ -0,0 +1,130 @@
1
+ import { Boom } from '@hapi/boom';
2
+ import type { Agent } from 'https';
3
+ import { Readable, Transform } from 'stream';
4
+ import { URL } from 'url';
5
+ import { proto } from '../../WAProto/index.js';
6
+ import { type MediaType } from '../Defaults/index.js';
7
+ import type { DownloadableMessage, MediaConnInfo, MediaDecryptionKeyInfo, SocketConfig, WAMediaUpload, WAMediaUploadFunction, WAMessageContent, WAMessageKey } from '../Types/index.js';
8
+ import { type BinaryNode } from '../WABinary/index.js';
9
+ import type { ILogger } from './logger.js';
10
+ export declare const hkdfInfoKey: (type: MediaType) => string;
11
+ export declare const getRawMediaUploadData: (media: WAMediaUpload, mediaType: MediaType, logger?: ILogger) => Promise<{
12
+ filePath: string;
13
+ fileSha256: NonSharedBuffer;
14
+ fileLength: number;
15
+ }>;
16
+ /** generates all the keys required to encrypt/decrypt & sign a media message */
17
+ export declare function getMediaKeys(buffer: Uint8Array | string | null | undefined, mediaType: MediaType): Promise<MediaDecryptionKeyInfo>;
18
+ export declare const extractImageThumb: (bufferOrFilePath: Readable | Buffer | string, width?: number) => Promise<{
19
+ buffer: any;
20
+ original: {
21
+ width: any;
22
+ height: any;
23
+ };
24
+ }>;
25
+ export declare const encodeBase64EncodedStringForUpload: (b64: string) => string;
26
+ export declare const generateProfilePicture: (mediaUpload: WAMediaUpload, dimensions?: {
27
+ width: number;
28
+ height: number;
29
+ }) => Promise<{
30
+ img: Buffer<ArrayBufferLike>;
31
+ }>;
32
+ /** gets the SHA256 of the given media message */
33
+ export declare const mediaMessageSHA256B64: (message: WAMessageContent) => string | null | undefined;
34
+ export declare function getAudioDuration(buffer: Buffer | string | Readable): Promise<number | undefined>;
35
+ /**
36
+ referenced from and modifying https://github.com/wppconnect-team/wa-js/blob/main/src/chat/functions/prepareAudioWaveform.ts
37
+ */
38
+ export declare function getAudioWaveform(buffer: Buffer | string | Readable, logger?: ILogger): Promise<Uint8Array<ArrayBuffer> | undefined>;
39
+ export declare const toReadable: (buffer: Buffer) => Readable;
40
+ export declare const toBuffer: (stream: Readable) => Promise<Buffer<ArrayBuffer>>;
41
+ export declare const getStream: (item: WAMediaUpload, opts?: RequestInit & {
42
+ maxContentLength?: number;
43
+ }) => Promise<{
44
+ readonly stream: Readable;
45
+ readonly type: "buffer";
46
+ } | {
47
+ readonly stream: Readable;
48
+ readonly type: "readable";
49
+ } | {
50
+ readonly stream: Readable;
51
+ readonly type: "remote";
52
+ } | {
53
+ readonly stream: import("fs").ReadStream;
54
+ readonly type: "file";
55
+ }>;
56
+ /** generates a thumbnail for a given media, if required */
57
+ export declare function generateThumbnail(file: string, mediaType: 'video' | 'image', options: {
58
+ logger?: ILogger;
59
+ }): Promise<{
60
+ thumbnail: string | undefined;
61
+ originalImageDimensions: {
62
+ width: number;
63
+ height: number;
64
+ } | undefined;
65
+ }>;
66
+ export declare const getHttpStream: (url: string | URL, options?: RequestInit & {
67
+ isStream?: true;
68
+ }) => Promise<Readable>;
69
+ type EncryptedStreamOptions = {
70
+ saveOriginalFileIfRequired?: boolean;
71
+ logger?: ILogger;
72
+ opts?: RequestInit;
73
+ };
74
+ export declare const encryptedStream: (media: WAMediaUpload, mediaType: MediaType, { logger, saveOriginalFileIfRequired, opts }?: EncryptedStreamOptions) => Promise<{
75
+ mediaKey: NonSharedBuffer;
76
+ originalFilePath: string | undefined;
77
+ encFilePath: string;
78
+ mac: Buffer<ArrayBuffer>;
79
+ fileEncSha256: NonSharedBuffer;
80
+ fileSha256: NonSharedBuffer;
81
+ fileLength: number;
82
+ }>;
83
+ export type MediaDownloadOptions = {
84
+ startByte?: number;
85
+ endByte?: number;
86
+ options?: RequestInit;
87
+ };
88
+ export declare const getUrlFromDirectPath: (directPath: string) => string;
89
+ export declare const downloadContentFromMessage: ({ mediaKey, directPath, url }: DownloadableMessage, type: MediaType, opts?: MediaDownloadOptions) => Promise<Transform>;
90
+ /**
91
+ * Decrypts and downloads an AES256-CBC encrypted file given the keys.
92
+ * Assumes the SHA256 of the plaintext is appended to the end of the ciphertext
93
+ * */
94
+ export declare const downloadEncryptedContent: (downloadUrl: string, { cipherKey, iv }: MediaDecryptionKeyInfo, { startByte, endByte, options }?: MediaDownloadOptions) => Promise<Transform>;
95
+ export declare function extensionForMediaMessage(message: WAMessageContent): string;
96
+ type MediaUploadResult = {
97
+ url?: string;
98
+ direct_path?: string;
99
+ meta_hmac?: string;
100
+ ts?: number;
101
+ fbid?: number;
102
+ };
103
+ export type UploadParams = {
104
+ url: string;
105
+ filePath: string;
106
+ headers: Record<string, string>;
107
+ timeoutMs?: number;
108
+ agent?: Agent;
109
+ };
110
+ export declare const uploadWithNodeHttp: ({ url, filePath, headers, timeoutMs, agent }: UploadParams, redirectCount?: number) => Promise<MediaUploadResult | undefined>;
111
+ export declare const getWAUploadToServer: ({ customUploadHosts, fetchAgent, logger, options }: SocketConfig, refreshMediaConn: (force: boolean) => Promise<MediaConnInfo>) => WAMediaUploadFunction;
112
+ /**
113
+ * Generate a binary node that will request the phone to re-upload the media & return the newly uploaded URL
114
+ */
115
+ export declare const encryptMediaRetryRequest: (key: WAMessageKey, mediaKey: Buffer | Uint8Array, meId: string) => BinaryNode;
116
+ export declare const decodeMediaRetryNode: (node: BinaryNode) => {
117
+ key: WAMessageKey;
118
+ media?: {
119
+ ciphertext: Uint8Array;
120
+ iv: Uint8Array;
121
+ };
122
+ error?: Boom;
123
+ };
124
+ export declare const decryptMediaRetryData: ({ ciphertext, iv }: {
125
+ ciphertext: Uint8Array;
126
+ iv: Uint8Array;
127
+ }, mediaKey: Uint8Array, msgId: string) => proto.MediaRetryNotification;
128
+ export declare const getStatusCodeForMediaRetry: (code: number) => 200 | 412 | 404 | 418;
129
+ export {};
130
+ //# sourceMappingURL=messages-media.d.ts.map