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,122 @@
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
+ exports.GroupCipher = void 0;
33
+ const crypto_1 = require("libsignal/src/crypto");
34
+ const queue_job_1 = __importDefault(require("./queue-job"));
35
+ const sender_key_message_1 = require("./sender-key-message");
36
+ class GroupCipher {
37
+ constructor(senderKeyStore, senderKeyName) {
38
+ this.senderKeyStore = senderKeyStore;
39
+ this.senderKeyName = senderKeyName;
40
+ }
41
+ queueJob(awaitable) {
42
+ return (0, queue_job_1.default)(this.senderKeyName.toString(), awaitable);
43
+ }
44
+ async encrypt(paddedPlaintext) {
45
+ return await this.queueJob(async () => {
46
+ const record = await this.senderKeyStore.loadSenderKey(this.senderKeyName);
47
+ if (!record) {
48
+ throw new Error('No SenderKeyRecord found for encryption');
49
+ }
50
+ const senderKeyState = record.getSenderKeyState();
51
+ if (!senderKeyState) {
52
+ throw new Error('No session to encrypt message');
53
+ }
54
+ const iteration = senderKeyState.getSenderChainKey().getIteration();
55
+ const senderKey = this.getSenderKey(senderKeyState, iteration === 0 ? 0 : iteration + 1);
56
+ const ciphertext = await this.getCipherText(senderKey.getIv(), senderKey.getCipherKey(), paddedPlaintext);
57
+ const senderKeyMessage = new sender_key_message_1.SenderKeyMessage(senderKeyState.getKeyId(), senderKey.getIteration(), ciphertext, senderKeyState.getSigningKeyPrivate());
58
+ await this.senderKeyStore.storeSenderKey(this.senderKeyName, record);
59
+ return senderKeyMessage.serialize();
60
+ });
61
+ }
62
+ async decrypt(senderKeyMessageBytes) {
63
+ return await this.queueJob(async () => {
64
+ const record = await this.senderKeyStore.loadSenderKey(this.senderKeyName);
65
+ if (!record) {
66
+ throw new Error('No SenderKeyRecord found for decryption');
67
+ }
68
+ const senderKeyMessage = new sender_key_message_1.SenderKeyMessage(null, null, null, null, senderKeyMessageBytes);
69
+ const senderKeyState = record.getSenderKeyState(senderKeyMessage.getKeyId());
70
+ if (!senderKeyState) {
71
+ throw new Error('No session found to decrypt message');
72
+ }
73
+ senderKeyMessage.verifySignature(senderKeyState.getSigningKeyPublic());
74
+ const senderKey = this.getSenderKey(senderKeyState, senderKeyMessage.getIteration());
75
+ const plaintext = await this.getPlainText(senderKey.getIv(), senderKey.getCipherKey(), senderKeyMessage.getCipherText());
76
+ await this.senderKeyStore.storeSenderKey(this.senderKeyName, record);
77
+ return plaintext;
78
+ });
79
+ }
80
+ getSenderKey(senderKeyState, iteration) {
81
+ let senderChainKey = senderKeyState.getSenderChainKey();
82
+ if (senderChainKey.getIteration() > iteration) {
83
+ if (senderKeyState.hasSenderMessageKey(iteration)) {
84
+ const messageKey = senderKeyState.removeSenderMessageKey(iteration);
85
+ if (!messageKey) {
86
+ throw new Error('No sender message key found for iteration');
87
+ }
88
+ return messageKey;
89
+ }
90
+ throw new Error(`Received message with old counter: ${senderChainKey.getIteration()}, ${iteration}`);
91
+ }
92
+ if (iteration - senderChainKey.getIteration() > 2000) {
93
+ throw new Error('Over 2000 messages into the future!');
94
+ }
95
+ while (senderChainKey.getIteration() < iteration) {
96
+ senderKeyState.addSenderMessageKey(senderChainKey.getSenderMessageKey());
97
+ senderChainKey = senderChainKey.getNext();
98
+ }
99
+ senderKeyState.setSenderChainKey(senderChainKey.getNext());
100
+ return senderChainKey.getSenderMessageKey();
101
+ }
102
+ async getPlainText(iv, key, ciphertext) {
103
+ try {
104
+ return (0, crypto_1.decrypt)(key, ciphertext, iv);
105
+ }
106
+ catch (e) {
107
+ throw new Error('InvalidMessageException');
108
+ }
109
+ }
110
+ async getCipherText(iv, key, plaintext) {
111
+ try {
112
+ const ivBuffer = typeof iv === 'string' ? Buffer.from(iv, 'base64') : iv;
113
+ const keyBuffer = typeof key === 'string' ? Buffer.from(key, 'base64') : key;
114
+ const plaintextBuffer = typeof plaintext === 'string' ? Buffer.from(plaintext) : plaintext;
115
+ return (0, crypto_1.encrypt)(keyBuffer, plaintextBuffer, ivBuffer);
116
+ }
117
+ catch (e) {
118
+ throw new Error('InvalidMessageException');
119
+ }
120
+ }
121
+ }
122
+ exports.GroupCipher = GroupCipher;
@@ -0,0 +1,22 @@
1
+ export const __esModule: boolean;
2
+ export const GroupSessionBuilder: typeof group_session_builder_1.GroupSessionBuilder;
3
+ export const SenderKeyDistributionMessage: typeof sender_key_distribution_message_1.SenderKeyDistributionMessage;
4
+ export const SenderKeyRecord: typeof sender_key_record_1.SenderKeyRecord;
5
+ export const SenderKeyName: typeof sender_key_name_1.SenderKeyName;
6
+ export const GroupCipher: typeof group_cipher_1.GroupCipher;
7
+ export const SenderKeyState: typeof sender_key_state_1.SenderKeyState;
8
+ export const SenderKeyMessage: typeof sender_key_message_1.SenderKeyMessage;
9
+ export const SenderMessageKey: typeof sender_message_key_1.SenderMessageKey;
10
+ export const SenderChainKey: typeof sender_chain_key_1.SenderChainKey;
11
+ export const CiphertextMessage: typeof ciphertext_message_1.CiphertextMessage;
12
+ export const keyhelper: any;
13
+ import group_session_builder_1 = require("./group-session-builder");
14
+ import sender_key_distribution_message_1 = require("./sender-key-distribution-message");
15
+ import sender_key_record_1 = require("./sender-key-record");
16
+ import sender_key_name_1 = require("./sender-key-name");
17
+ import group_cipher_1 = require("./group_cipher");
18
+ import sender_key_state_1 = require("./sender-key-state");
19
+ import sender_key_message_1 = require("./sender-key-message");
20
+ import sender_message_key_1 = require("./sender-message-key");
21
+ import sender_chain_key_1 = require("./sender-chain-key");
22
+ import ciphertext_message_1 = require("./ciphertext-message");
@@ -0,0 +1,83 @@
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.keyhelper = exports.CiphertextMessage = exports.SenderChainKey = exports.SenderMessageKey = exports.SenderKeyMessage = exports.SenderKeyState = exports.GroupCipher = exports.SenderKeyName = exports.SenderKeyRecord = exports.SenderKeyDistributionMessage = exports.GroupSessionBuilder = void 0;
63
+ var group_session_builder_1 = require("./group-session-builder");
64
+ Object.defineProperty(exports, "GroupSessionBuilder", { enumerable: true, get: function () { return group_session_builder_1.GroupSessionBuilder; } });
65
+ var sender_key_distribution_message_1 = require("./sender-key-distribution-message");
66
+ Object.defineProperty(exports, "SenderKeyDistributionMessage", { enumerable: true, get: function () { return sender_key_distribution_message_1.SenderKeyDistributionMessage; } });
67
+ var sender_key_record_1 = require("./sender-key-record");
68
+ Object.defineProperty(exports, "SenderKeyRecord", { enumerable: true, get: function () { return sender_key_record_1.SenderKeyRecord; } });
69
+ var sender_key_name_1 = require("./sender-key-name");
70
+ Object.defineProperty(exports, "SenderKeyName", { enumerable: true, get: function () { return sender_key_name_1.SenderKeyName; } });
71
+ var group_cipher_1 = require("./group_cipher");
72
+ Object.defineProperty(exports, "GroupCipher", { enumerable: true, get: function () { return group_cipher_1.GroupCipher; } });
73
+ var sender_key_state_1 = require("./sender-key-state");
74
+ Object.defineProperty(exports, "SenderKeyState", { enumerable: true, get: function () { return sender_key_state_1.SenderKeyState; } });
75
+ var sender_key_message_1 = require("./sender-key-message");
76
+ Object.defineProperty(exports, "SenderKeyMessage", { enumerable: true, get: function () { return sender_key_message_1.SenderKeyMessage; } });
77
+ var sender_message_key_1 = require("./sender-message-key");
78
+ Object.defineProperty(exports, "SenderMessageKey", { enumerable: true, get: function () { return sender_message_key_1.SenderMessageKey; } });
79
+ var sender_chain_key_1 = require("./sender-chain-key");
80
+ Object.defineProperty(exports, "SenderChainKey", { enumerable: true, get: function () { return sender_chain_key_1.SenderChainKey; } });
81
+ var ciphertext_message_1 = require("./ciphertext-message");
82
+ Object.defineProperty(exports, "CiphertextMessage", { enumerable: true, get: function () { return ciphertext_message_1.CiphertextMessage; } });
83
+ exports.keyhelper = __importStar(require("./keyhelper"));
@@ -0,0 +1,7 @@
1
+ export const __esModule: boolean;
2
+ export function generateSenderKey(): any;
3
+ export function generateSenderKeyId(): any;
4
+ export function generateSenderSigningKey(key: any): {
5
+ public: Buffer<any>;
6
+ private: Buffer<any>;
7
+ };
@@ -0,0 +1,81 @@
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.generateSenderKey = generateSenderKey;
63
+ exports.generateSenderKeyId = generateSenderKeyId;
64
+ exports.generateSenderSigningKey = generateSenderSigningKey;
65
+ const nodeCrypto = __importStar(require("crypto"));
66
+ const curve_1 = require("libsignal/src/curve");
67
+ function generateSenderKey() {
68
+ return nodeCrypto.randomBytes(32);
69
+ }
70
+ function generateSenderKeyId() {
71
+ return nodeCrypto.randomInt(2147483647);
72
+ }
73
+ function generateSenderSigningKey(key) {
74
+ if (!key) {
75
+ key = (0, curve_1.generateKeyPair)();
76
+ }
77
+ return {
78
+ public: Buffer.from(key.pubKey),
79
+ private: Buffer.from(key.privKey)
80
+ };
81
+ }
@@ -0,0 +1,3 @@
1
+ export const __esModule: boolean;
2
+ export default queueJob;
3
+ declare function queueJob(bucket: any, awaitable: any): Promise<any>;
@@ -0,0 +1,83 @@
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.default = queueJob;
30
+ const _queueAsyncBuckets = new Map();
31
+ const _gcLimit = 10000;
32
+ async function _asyncQueueExecutor(queue, cleanup) {
33
+ let offt = 0;
34
+
35
+ while (true) {
36
+ const limit = Math.min(queue.length, _gcLimit);
37
+ for (let i = offt; i < limit; i++) {
38
+ const job = queue[i];
39
+ try {
40
+ job.resolve(await job.awaitable());
41
+ }
42
+ catch (e) {
43
+ job.reject(e);
44
+ }
45
+ }
46
+ if (limit < queue.length) {
47
+ if (limit >= _gcLimit) {
48
+ queue.splice(0, limit);
49
+ offt = 0;
50
+ }
51
+ else {
52
+ offt = limit;
53
+ }
54
+ }
55
+ else {
56
+ break;
57
+ }
58
+ }
59
+ cleanup();
60
+ }
61
+ function queueJob(bucket, awaitable) {
62
+
63
+ if (typeof bucket !== 'string') {
64
+ console.warn('Unhandled bucket type (for naming):', typeof bucket, bucket);
65
+ }
66
+ let inactive = false;
67
+ if (!_queueAsyncBuckets.has(bucket)) {
68
+ _queueAsyncBuckets.set(bucket, []);
69
+ inactive = true;
70
+ }
71
+ const queue = _queueAsyncBuckets.get(bucket);
72
+ const job = new Promise((resolve, reject) => {
73
+ queue.push({
74
+ awaitable,
75
+ resolve: resolve,
76
+ reject
77
+ });
78
+ });
79
+ if (inactive) {
80
+ _asyncQueueExecutor(queue, () => _queueAsyncBuckets.delete(bucket));
81
+ }
82
+ return job;
83
+ }
@@ -0,0 +1,14 @@
1
+ export const __esModule: boolean;
2
+ export class SenderChainKey {
3
+ constructor(iteration: any, chainKey: any);
4
+ MESSAGE_KEY_SEED: Buffer<ArrayBuffer>;
5
+ CHAIN_KEY_SEED: Buffer<ArrayBuffer>;
6
+ iteration: any;
7
+ chainKey: Buffer<any>;
8
+ getIteration(): any;
9
+ getSenderMessageKey(): sender_message_key_1.SenderMessageKey;
10
+ getNext(): SenderChainKey;
11
+ getSeed(): Buffer<any>;
12
+ getDerivative(seed: any, key: any): Uint8Array<ArrayBufferLike>;
13
+ }
14
+ import sender_message_key_1 = require("./sender-message-key");
@@ -0,0 +1,60 @@
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.SenderChainKey = void 0;
30
+ const crypto_1 = require("libsignal/src/crypto");
31
+ const sender_message_key_1 = require("./sender-message-key");
32
+ class SenderChainKey {
33
+ constructor(iteration, chainKey) {
34
+ this.MESSAGE_KEY_SEED = Buffer.from([0x01]);
35
+ this.CHAIN_KEY_SEED = Buffer.from([0x02]);
36
+ this.iteration = iteration;
37
+ if (chainKey instanceof Buffer) {
38
+ this.chainKey = chainKey;
39
+ }
40
+ else {
41
+ this.chainKey = Buffer.from(chainKey || []);
42
+ }
43
+ }
44
+ getIteration() {
45
+ return this.iteration;
46
+ }
47
+ getSenderMessageKey() {
48
+ return new sender_message_key_1.SenderMessageKey(this.iteration, this.getDerivative(this.MESSAGE_KEY_SEED, this.chainKey));
49
+ }
50
+ getNext() {
51
+ return new SenderChainKey(this.iteration + 1, this.getDerivative(this.CHAIN_KEY_SEED, this.chainKey));
52
+ }
53
+ getSeed() {
54
+ return this.chainKey;
55
+ }
56
+ getDerivative(seed, key) {
57
+ return (0, crypto_1.calculateMAC)(key, seed);
58
+ }
59
+ }
60
+ exports.SenderChainKey = SenderChainKey;
@@ -0,0 +1,17 @@
1
+ export const __esModule: boolean;
2
+ export class SenderKeyDistributionMessage extends ciphertext_message_1.CiphertextMessage {
3
+ constructor(id: any, iteration: any, chainKey: any, signatureKey: any, serialized: any);
4
+ serialized: any;
5
+ id: any;
6
+ iteration: any;
7
+ chainKey: any;
8
+ signatureKey: any;
9
+ intsToByteHighAndLow(highValue: any, lowValue: any): number;
10
+ serialize(): any;
11
+ getType(): number;
12
+ getIteration(): any;
13
+ getChainKey(): any;
14
+ getSignatureKey(): any;
15
+ getId(): any;
16
+ }
17
+ import ciphertext_message_1 = require("./ciphertext-message");
@@ -0,0 +1,92 @@
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.SenderKeyDistributionMessage = void 0;
30
+ const WAProto_1 = require("../../../WAProto");
31
+ const ciphertext_message_1 = require("./ciphertext-message");
32
+ class SenderKeyDistributionMessage extends ciphertext_message_1.CiphertextMessage {
33
+ constructor(id, iteration, chainKey, signatureKey, serialized) {
34
+ super();
35
+ if (serialized) {
36
+ try {
37
+ const message = serialized.slice(1);
38
+ const distributionMessage = WAProto_1.proto.SenderKeyDistributionMessage.decode(message).toJSON();
39
+ this.serialized = serialized;
40
+ this.id = distributionMessage.id;
41
+ this.iteration = distributionMessage.iteration;
42
+ this.chainKey =
43
+ typeof distributionMessage.chainKey === 'string'
44
+ ? Buffer.from(distributionMessage.chainKey, 'base64')
45
+ : distributionMessage.chainKey;
46
+ this.signatureKey =
47
+ typeof distributionMessage.signingKey === 'string'
48
+ ? Buffer.from(distributionMessage.signingKey, 'base64')
49
+ : distributionMessage.signingKey;
50
+ }
51
+ catch (e) {
52
+ throw new Error(String(e));
53
+ }
54
+ }
55
+ else {
56
+ const version = this.intsToByteHighAndLow(this.CURRENT_VERSION, this.CURRENT_VERSION);
57
+ this.id = id;
58
+ this.iteration = iteration;
59
+ this.chainKey = chainKey;
60
+ this.signatureKey = signatureKey;
61
+ const message = WAProto_1.proto.SenderKeyDistributionMessage.encode(WAProto_1.proto.SenderKeyDistributionMessage.create({
62
+ id,
63
+ iteration,
64
+ chainKey,
65
+ signingKey: this.signatureKey
66
+ })).finish();
67
+ this.serialized = Buffer.concat([Buffer.from([version]), message]);
68
+ }
69
+ }
70
+ intsToByteHighAndLow(highValue, lowValue) {
71
+ return (((highValue << 4) | lowValue) & 0xff) % 256;
72
+ }
73
+ serialize() {
74
+ return this.serialized;
75
+ }
76
+ getType() {
77
+ return this.SENDERKEY_DISTRIBUTION_TYPE;
78
+ }
79
+ getIteration() {
80
+ return this.iteration;
81
+ }
82
+ getChainKey() {
83
+ return typeof this.chainKey === 'string' ? Buffer.from(this.chainKey, 'base64') : this.chainKey;
84
+ }
85
+ getSignatureKey() {
86
+ return typeof this.signatureKey === 'string' ? Buffer.from(this.signatureKey, 'base64') : this.signatureKey;
87
+ }
88
+ getId() {
89
+ return this.id;
90
+ }
91
+ }
92
+ exports.SenderKeyDistributionMessage = SenderKeyDistributionMessage;
@@ -0,0 +1,19 @@
1
+ export const __esModule: boolean;
2
+ export class SenderKeyMessage extends ciphertext_message_1.CiphertextMessage {
3
+ constructor(keyId: any, iteration: any, ciphertext: any, signatureKey: any, serialized: any);
4
+ SIGNATURE_LENGTH: number;
5
+ serialized: any;
6
+ messageVersion: number;
7
+ keyId: any;
8
+ iteration: any;
9
+ ciphertext: any;
10
+ signature: any;
11
+ getKeyId(): any;
12
+ getIteration(): any;
13
+ getCipherText(): any;
14
+ verifySignature(signatureKey: any): void;
15
+ getSignature(signatureKey: any, serialized: any): Buffer<ArrayBuffer>;
16
+ serialize(): any;
17
+ getType(): number;
18
+ }
19
+ import ciphertext_message_1 = require("./ciphertext-message");