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,61 @@
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
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
29
+ if (k2 === undefined) k2 = k;
30
+ var desc = Object.getOwnPropertyDescriptor(m, k);
31
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
32
+ desc = { enumerable: true, get: function() { return m[k]; } };
33
+ }
34
+ Object.defineProperty(o, k2, desc);
35
+ }) : (function(o, m, k, k2) {
36
+ if (k2 === undefined) k2 = k;
37
+ o[k2] = m[k];
38
+ }));
39
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
40
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
41
+ };
42
+ Object.defineProperty(exports, "__esModule", { value: true });
43
+ __exportStar(require("./generics"), exports);
44
+ __exportStar(require("./decode-wa-message"), exports);
45
+ __exportStar(require("./messages"), exports);
46
+ __exportStar(require("./messages-media"), exports);
47
+ __exportStar(require("./validate-connection"), exports);
48
+ __exportStar(require("./crypto"), exports);
49
+ __exportStar(require("./signal"), exports);
50
+ __exportStar(require("./noise-handler"), exports);
51
+ __exportStar(require("./history"), exports);
52
+ __exportStar(require("./chat-utils"), exports);
53
+ __exportStar(require("./lt-hash"), exports);
54
+ __exportStar(require("./auth-utils"), exports);
55
+ __exportStar(require("./ye-bail-event-stream"), exports);
56
+ __exportStar(require("./use-multi-file-auth-state"), exports);
57
+ __exportStar(require("./link-preview"), exports);
58
+ __exportStar(require("./event-buffer"), exports);
59
+ __exportStar(require("./process-message"), exports);
60
+ __exportStar(require("./message-retry-manager"), exports);
61
+ __exportStar(require("./browser-utils"), exports);
@@ -0,0 +1,19 @@
1
+ export const __esModule: boolean;
2
+ /**
3
+ * Given a piece of text, checks for any URL present, generates link preview for the same and returns it
4
+ * Return undefined if the fetch failed or no URL was found
5
+ * @param text first matched URL in text
6
+ * @returns the URL info required to generate link preview
7
+ */
8
+ export function getUrlInfo(text: any, opts?: {
9
+ thumbnailWidth: number;
10
+ fetchOpts: {
11
+ timeout: number;
12
+ };
13
+ }): Promise<{
14
+ 'canonical-url': any;
15
+ 'matched-text': any;
16
+ title: any;
17
+ description: any;
18
+ originalThumbnailUrl: any;
19
+ }>;
@@ -0,0 +1,152 @@
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
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
29
+ if (k2 === undefined) k2 = k;
30
+ var desc = Object.getOwnPropertyDescriptor(m, k);
31
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
32
+ desc = { enumerable: true, get: function() { return m[k]; } };
33
+ }
34
+ Object.defineProperty(o, k2, desc);
35
+ }) : (function(o, m, k, k2) {
36
+ if (k2 === undefined) k2 = k;
37
+ o[k2] = m[k];
38
+ }));
39
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
40
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
41
+ }) : function(o, v) {
42
+ o["default"] = v;
43
+ });
44
+ var __importStar = (this && this.__importStar) || (function () {
45
+ var ownKeys = function(o) {
46
+ ownKeys = Object.getOwnPropertyNames || function (o) {
47
+ var ar = [];
48
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
49
+ return ar;
50
+ };
51
+ return ownKeys(o);
52
+ };
53
+ return function (mod) {
54
+ if (mod && mod.__esModule) return mod;
55
+ var result = {};
56
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
57
+ __setModuleDefault(result, mod);
58
+ return result;
59
+ };
60
+ })();
61
+ Object.defineProperty(exports, "__esModule", { value: true });
62
+ exports.getUrlInfo = void 0;
63
+ const messages_1 = require("./messages");
64
+ const messages_media_1 = require("./messages-media");
65
+ const THUMBNAIL_WIDTH_PX = 192;
66
+ /** Fetches an image and generates a thumbnail for it */
67
+ const getCompressedJpegThumbnail = async (url, { thumbnailWidth, fetchOpts }) => {
68
+ const stream = await (0, messages_media_1.getHttpStream)(url, fetchOpts);
69
+ const result = await (0, messages_media_1.extractImageThumb)(stream, thumbnailWidth);
70
+ return result;
71
+ };
72
+ /**
73
+ * Given a piece of text, checks for any URL present, generates link preview for the same and returns it
74
+ * Return undefined if the fetch failed or no URL was found
75
+ * @param text first matched URL in text
76
+ * @returns the URL info required to generate link preview
77
+ */
78
+ const getUrlInfo = async (text, opts = {
79
+ thumbnailWidth: THUMBNAIL_WIDTH_PX,
80
+ fetchOpts: { timeout: 3000 }
81
+ }) => {
82
+ var _a;
83
+ try {
84
+
85
+ const retries = 0;
86
+ const maxRetry = 5;
87
+ const { getLinkPreview } = await Promise.resolve().then(() => __importStar(require('link-preview-js')));
88
+ let previewLink = text;
89
+ if (!text.startsWith('https://') && !text.startsWith('http://')) {
90
+ previewLink = 'https://' + previewLink;
91
+ }
92
+ const info = await getLinkPreview(previewLink, {
93
+ ...opts.fetchOpts,
94
+ followRedirects: 'follow',
95
+ handleRedirects: (baseURL, forwardedURL) => {
96
+ const urlObj = new URL(baseURL);
97
+ const forwardedURLObj = new URL(forwardedURL);
98
+ if (retries >= maxRetry) {
99
+ return false;
100
+ }
101
+ if (forwardedURLObj.hostname === urlObj.hostname
102
+ || forwardedURLObj.hostname === 'www.' + urlObj.hostname
103
+ || 'www.' + forwardedURLObj.hostname === urlObj.hostname) {
104
+ retries + 1;
105
+ return true;
106
+ }
107
+ else {
108
+ return false;
109
+ }
110
+ },
111
+ headers: opts.fetchOpts
112
+ });
113
+ if (info && 'title' in info && info.title) {
114
+ const [image] = info.images;
115
+ const urlInfo = {
116
+ 'canonical-url': info.url,
117
+ 'matched-text': text,
118
+ title: info.title,
119
+ description: info.description,
120
+ originalThumbnailUrl: image
121
+ };
122
+ if (opts.uploadImage) {
123
+ const { imageMessage } = await (0, messages_1.prepareWAMessageMedia)({ image: { url: image } }, {
124
+ upload: opts.uploadImage,
125
+ mediaTypeOverride: 'thumbnail-link',
126
+ options: opts.fetchOpts
127
+ });
128
+ urlInfo.jpegThumbnail = (imageMessage === null || imageMessage === void 0 ? void 0 : imageMessage.jpegThumbnail)
129
+ ? Buffer.from(imageMessage.jpegThumbnail)
130
+ : undefined;
131
+ urlInfo.highQualityThumbnail = imageMessage || undefined;
132
+ }
133
+ else {
134
+ try {
135
+ urlInfo.jpegThumbnail = image
136
+ ? (await getCompressedJpegThumbnail(image, opts)).buffer
137
+ : undefined;
138
+ }
139
+ catch (error) {
140
+ (_a = opts.logger) === null || _a === void 0 ? void 0 : _a.debug({ err: error.stack, url: previewLink }, 'error in generating thumbnail');
141
+ }
142
+ }
143
+ return urlInfo;
144
+ }
145
+ }
146
+ catch (error) {
147
+ if (!error.message.includes('receive a valid')) {
148
+ throw error;
149
+ }
150
+ }
151
+ };
152
+ exports.getUrlInfo = getUrlInfo;
@@ -0,0 +1,3 @@
1
+ export const __esModule: boolean;
2
+ declare const _default: any;
3
+ export default _default;
@@ -0,0 +1,33 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
29
+ return (mod && mod.__esModule) ? mod : { "default": mod };
30
+ };
31
+ Object.defineProperty(exports, "__esModule", { value: true });
32
+ const pino_1 = __importDefault(require("pino"));
33
+ exports.default = (0, pino_1.default)({ timestamp: () => `,"time":"${new Date().toJSON()}"` });
@@ -0,0 +1,13 @@
1
+ export const __esModule: boolean;
2
+ export const LT_HASH_ANTI_TAMPERING: d;
3
+ declare class d {
4
+ constructor(e: any);
5
+ salt: any;
6
+ add(e: any, t: any): any;
7
+ subtract(e: any, t: any): any;
8
+ subtractThenAdd(e: any, t: any, r: any): any;
9
+ _addSingle(e: any, t: any): Promise<ArrayBuffer>;
10
+ _subtractSingle(e: any, t: any): Promise<ArrayBuffer>;
11
+ performPointwiseWithOverflow(e: any, t: any, r: any): ArrayBuffer;
12
+ }
13
+ export {};
@@ -0,0 +1,77 @@
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.LT_HASH_ANTI_TAMPERING = void 0;
30
+ const crypto_1 = require("./crypto");
31
+ /**
32
+ * LT Hash is a summation based hash algorithm that maintains the integrity of a piece of data
33
+ * over a series of mutations. You can add/remove mutations and it'll return a hash equal to
34
+ * if the same series of mutations was made sequentially.
35
+ */
36
+ const o = 128;
37
+ class d {
38
+ constructor(e) {
39
+ this.salt = e;
40
+ }
41
+ add(e, t) {
42
+ var r = this;
43
+ for (const item of t) {
44
+ e = r._addSingle(e, item);
45
+ }
46
+ return e;
47
+ }
48
+ subtract(e, t) {
49
+ var r = this;
50
+ for (const item of t) {
51
+ e = r._subtractSingle(e, item);
52
+ }
53
+ return e;
54
+ }
55
+ subtractThenAdd(e, t, r) {
56
+ var n = this;
57
+ return n.add(n.subtract(e, r), t);
58
+ }
59
+ async _addSingle(e, t) {
60
+ var r = this;
61
+ const n = new Uint8Array(await (0, crypto_1.hkdf)(Buffer.from(t), o, { info: r.salt })).buffer;
62
+ return r.performPointwiseWithOverflow(await e, n, ((e, t) => e + t));
63
+ }
64
+ async _subtractSingle(e, t) {
65
+ var r = this;
66
+ const n = new Uint8Array(await (0, crypto_1.hkdf)(Buffer.from(t), o, { info: r.salt })).buffer;
67
+ return r.performPointwiseWithOverflow(await e, n, ((e, t) => e - t));
68
+ }
69
+ performPointwiseWithOverflow(e, t, r) {
70
+ const n = new DataView(e), i = new DataView(t), a = new ArrayBuffer(n.byteLength), s = new DataView(a);
71
+ for (let e = 0; e < n.byteLength; e += 2) {
72
+ s.setUint16(e, r(n.getUint16(e, !0), i.getUint16(e, !0)), !0);
73
+ }
74
+ return a;
75
+ }
76
+ }
77
+ exports.LT_HASH_ANTI_TAMPERING = new d('WhatsApp Patch Integrity');
@@ -0,0 +1,7 @@
1
+ export const __esModule: boolean;
2
+ export function makeMutex(): {
3
+ mutex(code: any): Promise<void>;
4
+ };
5
+ export function makeKeyedMutex(): {
6
+ mutex(key: any, task: any): any;
7
+ };
@@ -0,0 +1,69 @@
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.makeKeyedMutex = exports.makeMutex = void 0;
30
+ const makeMutex = () => {
31
+ let task = Promise.resolve();
32
+ let taskTimeout;
33
+ return {
34
+ mutex(code) {
35
+ task = (async () => {
36
+
37
+
38
+ try {
39
+ await task;
40
+ }
41
+ catch (_a) { }
42
+ try {
43
+
44
+ const result = await code();
45
+ return result;
46
+ }
47
+ finally {
48
+ clearTimeout(taskTimeout);
49
+ }
50
+ })();
51
+
52
+
53
+ return task;
54
+ },
55
+ };
56
+ };
57
+ exports.makeMutex = makeMutex;
58
+ const makeKeyedMutex = () => {
59
+ const map = {};
60
+ return {
61
+ mutex(key, task) {
62
+ if (!map[key]) {
63
+ map[key] = (0, exports.makeMutex)();
64
+ }
65
+ return map[key].mutex(task);
66
+ }
67
+ };
68
+ };
69
+ exports.makeKeyedMutex = makeKeyedMutex;
@@ -0,0 +1,34 @@
1
+ export const __esModule: boolean;
2
+ export class MessageRetryManager {
3
+ constructor(logger: any, maxMsgRetryCount: any);
4
+ logger: any;
5
+ maxMsgRetryCount: any;
6
+ _recentMessagesMap: lru_cache_1.LRUCache<{}, {}, unknown>;
7
+ _sessionRecreateHistory: lru_cache_1.LRUCache<{}, {}, unknown>;
8
+ _retryCounters: lru_cache_1.LRUCache<{}, {}, unknown>;
9
+ _pendingPhoneRequests: {};
10
+ statistics: {
11
+ totalRetries: number;
12
+ successfulRetries: number;
13
+ failedRetries: number;
14
+ mediaRetries: number;
15
+ sessionRecreations: number;
16
+ phoneRequests: number;
17
+ };
18
+ addRecentMessage(to: any, id: any, message: any): void;
19
+ getRecentMessage(to: any, id: any): {};
20
+ shouldRecreateSession(jid: any, retryCount: any, hasSession: any): {
21
+ reason: string;
22
+ recreate: boolean;
23
+ };
24
+ incrementRetryCount(messageId: any): {};
25
+ getRetryCount(messageId: any): {};
26
+ hasExceededMaxRetries(messageId: any): boolean;
27
+ markRetrySuccess(messageId: any): void;
28
+ markRetryFailed(messageId: any): void;
29
+ schedulePhoneRequest(messageId: any, callback: any, delay?: number): void;
30
+ cancelPendingPhoneRequest(messageId: any): void;
31
+ _keyToString(key: any): string;
32
+ _cancelPendingPhoneRequest(messageId: any): void;
33
+ }
34
+ import lru_cache_1 = require("lru-cache");
@@ -0,0 +1,154 @@
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.MessageRetryManager = void 0;
30
+
31
+ const lru_cache_1 = require("lru-cache");
32
+
33
+ const RECENT_MESSAGES_SIZE = 512;
34
+
35
+ const RECREATE_SESSION_TIMEOUT = 60 * 60 * 1000;
36
+
37
+ const PHONE_REQUEST_DELAY = 3000;
38
+
39
+ class MessageRetryManager {
40
+ constructor(logger, maxMsgRetryCount) {
41
+ this.logger = logger;
42
+ this.maxMsgRetryCount = maxMsgRetryCount;
43
+ this._recentMessagesMap = new lru_cache_1.LRUCache({
44
+ max: RECENT_MESSAGES_SIZE
45
+ });
46
+ this._sessionRecreateHistory = new lru_cache_1.LRUCache({
47
+ ttl: RECREATE_SESSION_TIMEOUT * 2,
48
+ ttlAutopurge: true
49
+ });
50
+ this._retryCounters = new lru_cache_1.LRUCache({
51
+ ttl: 15 * 60 * 1000,
52
+ ttlAutopurge: true,
53
+ updateAgeOnGet: true
54
+ });
55
+ this._pendingPhoneRequests = {};
56
+ this.statistics = {
57
+ totalRetries: 0,
58
+ successfulRetries: 0,
59
+ failedRetries: 0,
60
+ mediaRetries: 0,
61
+ sessionRecreations: 0,
62
+ phoneRequests: 0
63
+ };
64
+ this.maxMsgRetryCount = maxMsgRetryCount;
65
+ }
66
+ addRecentMessage(to, id, message) {
67
+ const key = { to, id };
68
+ const keyStr = this._keyToString(key);
69
+ this._recentMessagesMap.set(keyStr, {
70
+ message,
71
+ timestamp: Date.now()
72
+ });
73
+ this.logger.debug(`Added message to retry cache: ${to}/${id}`);
74
+ }
75
+ getRecentMessage(to, id) {
76
+ const key = { to, id };
77
+ const keyStr = this._keyToString(key);
78
+ return this._recentMessagesMap.get(keyStr);
79
+ }
80
+ shouldRecreateSession(jid, retryCount, hasSession) {
81
+ if (!hasSession) {
82
+ this._sessionRecreateHistory.set(jid, Date.now());
83
+ this.statistics.sessionRecreations++;
84
+ return {
85
+ reason: "we don't have a Signal session with them",
86
+ recreate: true
87
+ };
88
+ }
89
+ if (retryCount < 2) {
90
+ return { reason: '', recreate: false };
91
+ }
92
+ const now = Date.now();
93
+ const prevTime = this._sessionRecreateHistory.get(jid);
94
+ if (!prevTime || now - prevTime > RECREATE_SESSION_TIMEOUT) {
95
+ this._sessionRecreateHistory.set(jid, now);
96
+ this.statistics.sessionRecreations++;
97
+ return {
98
+ reason: 'retry count > 1 and over an hour since last recreation',
99
+ recreate: true
100
+ };
101
+ }
102
+ return { reason: '', recreate: false };
103
+ }
104
+ incrementRetryCount(messageId) {
105
+ this._retryCounters.set(messageId, (this._retryCounters.get(messageId) || 0) + 1);
106
+ this.statistics.totalRetries++;
107
+ return this._retryCounters.get(messageId);
108
+ }
109
+ getRetryCount(messageId) {
110
+ return this._retryCounters.get(messageId) || 0;
111
+ }
112
+ hasExceededMaxRetries(messageId) {
113
+ return this.getRetryCount(messageId) >= this.maxMsgRetryCount;
114
+ }
115
+ markRetrySuccess(messageId) {
116
+ this.statistics.successfulRetries++;
117
+ this._retryCounters.delete(messageId);
118
+ this._cancelPendingPhoneRequest(messageId);
119
+ }
120
+ markRetryFailed(messageId) {
121
+ this.statistics.failedRetries++;
122
+ this._retryCounters.delete(messageId);
123
+ }
124
+ schedulePhoneRequest(messageId, callback, delay = PHONE_REQUEST_DELAY) {
125
+ this._cancelPendingPhoneRequest(messageId);
126
+ this._pendingPhoneRequests[messageId] = setTimeout(() => {
127
+ delete this._pendingPhoneRequests[messageId];
128
+ this.statistics.phoneRequests++;
129
+ callback();
130
+ }, delay);
131
+ this.logger.debug(`Scheduled phone request for message ${messageId} with ${delay}ms delay`);
132
+ }
133
+ cancelPendingPhoneRequest(messageId) {
134
+ const timeout = this._pendingPhoneRequests[messageId];
135
+ if (timeout) {
136
+ clearTimeout(timeout);
137
+ delete this._pendingPhoneRequests[messageId];
138
+ this.logger.debug(`Cancelled pending phone request for message ${messageId}`);
139
+ }
140
+ }
141
+ _keyToString(key) {
142
+ return `${key.to}:${key.id}`;
143
+ }
144
+ _cancelPendingPhoneRequest(messageId) {
145
+ const timeout = this._pendingPhoneRequests[messageId];
146
+ if (timeout) {
147
+ clearTimeout(timeout);
148
+ delete this._pendingPhoneRequests[messageId];
149
+ this.logger.debug(`Cancelled pending phone request for message ${messageId}`);
150
+ }
151
+ }
152
+ }
153
+
154
+ exports.MessageRetryManager = MessageRetryManager;