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,43 @@
1
+ export const __esModule: boolean;
2
+ export namespace Curve {
3
+ function generateKeyPair(): {
4
+ private: Buffer<any>;
5
+ public: Buffer<any>;
6
+ };
7
+ function sharedKey(privateKey: any, publicKey: any): Buffer<any>;
8
+ function sign(privateKey: any, buf: any): any;
9
+ function verify(pubKey: any, message: any, signature: any): boolean;
10
+ }
11
+ /**
12
+ * encrypt AES 256 GCM;
13
+ * where the tag tag is suffixed to the ciphertext
14
+ * */
15
+ export function aesEncryptGCM(plaintext: any, key: any, iv: any, additionalData: any): Buffer<ArrayBuffer>;
16
+ /**
17
+ * decrypt AES 256 GCM;
18
+ * where the auth tag is suffixed to the ciphertext
19
+ * */
20
+ export function aesDecryptGCM(ciphertext: any, key: any, iv: any, additionalData: any): Buffer<ArrayBuffer>;
21
+ export function aesEncryptCTR(plaintext: any, key: any, iv: any): Buffer<ArrayBuffer>;
22
+ export function aesDecryptCTR(ciphertext: any, key: any, iv: any): Buffer<ArrayBuffer>;
23
+ /** decrypt AES 256 CBC; where the IV is prefixed to the buffer */
24
+ export function aesDecrypt(buffer: any, key: any): Buffer<ArrayBuffer>;
25
+ /** decrypt AES 256 CBC */
26
+ export function aesDecryptWithIV(buffer: any, key: any, IV: any): Buffer<ArrayBuffer>;
27
+ export function aesEncrypt(buffer: any, key: any): Buffer<ArrayBuffer>;
28
+ export function aesEncrypWithIV(buffer: any, key: any, IV: any): Buffer<ArrayBuffer>;
29
+ export function hmacSign(buffer: any, key: any, variant?: string): Buffer<ArrayBufferLike>;
30
+ export function sha256(buffer: any): Buffer<ArrayBufferLike>;
31
+ export function md5(buffer: any): Buffer<ArrayBufferLike>;
32
+ export function hkdf(buffer: any, expandedLength: any, info: any): Promise<Buffer<any>>;
33
+ export function derivePairingCodeKey(pairingCode: any, salt: any): Promise<Buffer<any>>;
34
+ /** prefix version byte to the pub keys, required for some curve crypto functions */
35
+ export function generateSignalPubKey(pubKey: any): any;
36
+ export function signedKeyPair(identityKeyPair: any, keyId: any): {
37
+ keyPair: {
38
+ private: Buffer<any>;
39
+ public: Buffer<any>;
40
+ };
41
+ signature: any;
42
+ keyId: any;
43
+ };
@@ -0,0 +1,219 @@
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.signedKeyPair = exports.Curve = exports.generateSignalPubKey = void 0;
63
+ exports.aesEncryptGCM = aesEncryptGCM;
64
+ exports.aesDecryptGCM = aesDecryptGCM;
65
+ exports.aesEncryptCTR = aesEncryptCTR;
66
+ exports.aesDecryptCTR = aesDecryptCTR;
67
+ exports.aesDecrypt = aesDecrypt;
68
+ exports.aesDecryptWithIV = aesDecryptWithIV;
69
+ exports.aesEncrypt = aesEncrypt;
70
+ exports.aesEncrypWithIV = aesEncrypWithIV;
71
+ exports.hmacSign = hmacSign;
72
+ exports.sha256 = sha256;
73
+ exports.md5 = md5;
74
+ exports.hkdf = hkdf;
75
+ exports.derivePairingCodeKey = derivePairingCodeKey;
76
+ const crypto_1 = require("crypto");
77
+ const libsignal = __importStar(require("libsignal"));
78
+ const Defaults_1 = require("../Defaults");
79
+
80
+ const { subtle } = globalThis.crypto;
81
+ /** prefix version byte to the pub keys, required for some curve crypto functions */
82
+ const generateSignalPubKey = (pubKey) => (pubKey.length === 33
83
+ ? pubKey
84
+ : Buffer.concat([Defaults_1.KEY_BUNDLE_TYPE, pubKey]));
85
+ exports.generateSignalPubKey = generateSignalPubKey;
86
+ exports.Curve = {
87
+ generateKeyPair: () => {
88
+ const { pubKey, privKey } = libsignal.curve.generateKeyPair();
89
+ return {
90
+ private: Buffer.from(privKey),
91
+
92
+ public: Buffer.from(pubKey.slice(1))
93
+ };
94
+ },
95
+ sharedKey: (privateKey, publicKey) => {
96
+ const shared = libsignal.curve.calculateAgreement((0, exports.generateSignalPubKey)(publicKey), privateKey);
97
+ return Buffer.from(shared);
98
+ },
99
+ sign: (privateKey, buf) => (libsignal.curve.calculateSignature(privateKey, buf)),
100
+ verify: (pubKey, message, signature) => {
101
+ try {
102
+ libsignal.curve.verifySignature((0, exports.generateSignalPubKey)(pubKey), message, signature);
103
+ return true;
104
+ }
105
+ catch (error) {
106
+ return false;
107
+ }
108
+ }
109
+ };
110
+ const signedKeyPair = (identityKeyPair, keyId) => {
111
+ const preKey = exports.Curve.generateKeyPair();
112
+ const pubKey = (0, exports.generateSignalPubKey)(preKey.public);
113
+ const signature = exports.Curve.sign(identityKeyPair.private, pubKey);
114
+ return { keyPair: preKey, signature, keyId };
115
+ };
116
+ exports.signedKeyPair = signedKeyPair;
117
+ const GCM_TAG_LENGTH = 128 >> 3;
118
+ /**
119
+ * encrypt AES 256 GCM;
120
+ * where the tag tag is suffixed to the ciphertext
121
+ * */
122
+ function aesEncryptGCM(plaintext, key, iv, additionalData) {
123
+ const cipher = (0, crypto_1.createCipheriv)('aes-256-gcm', key, iv);
124
+ cipher.setAAD(additionalData);
125
+ return Buffer.concat([cipher.update(plaintext), cipher.final(), cipher.getAuthTag()]);
126
+ }
127
+ /**
128
+ * decrypt AES 256 GCM;
129
+ * where the auth tag is suffixed to the ciphertext
130
+ * */
131
+ function aesDecryptGCM(ciphertext, key, iv, additionalData) {
132
+ const decipher = (0, crypto_1.createDecipheriv)('aes-256-gcm', key, iv);
133
+
134
+ const enc = ciphertext.slice(0, ciphertext.length - GCM_TAG_LENGTH);
135
+ const tag = ciphertext.slice(ciphertext.length - GCM_TAG_LENGTH);
136
+
137
+ decipher.setAAD(additionalData);
138
+ decipher.setAuthTag(tag);
139
+ return Buffer.concat([decipher.update(enc), decipher.final()]);
140
+ }
141
+ function aesEncryptCTR(plaintext, key, iv) {
142
+ const cipher = (0, crypto_1.createCipheriv)('aes-256-ctr', key, iv);
143
+ return Buffer.concat([cipher.update(plaintext), cipher.final()]);
144
+ }
145
+ function aesDecryptCTR(ciphertext, key, iv) {
146
+ const decipher = (0, crypto_1.createDecipheriv)('aes-256-ctr', key, iv);
147
+ return Buffer.concat([decipher.update(ciphertext), decipher.final()]);
148
+ }
149
+ /** decrypt AES 256 CBC; where the IV is prefixed to the buffer */
150
+ function aesDecrypt(buffer, key) {
151
+ return aesDecryptWithIV(buffer.slice(16, buffer.length), key, buffer.slice(0, 16));
152
+ }
153
+ /** decrypt AES 256 CBC */
154
+ function aesDecryptWithIV(buffer, key, IV) {
155
+ const aes = (0, crypto_1.createDecipheriv)('aes-256-cbc', key, IV);
156
+ return Buffer.concat([aes.update(buffer), aes.final()]);
157
+ }
158
+
159
+ function aesEncrypt(buffer, key) {
160
+ const IV = (0, crypto_1.randomBytes)(16);
161
+ const aes = (0, crypto_1.createCipheriv)('aes-256-cbc', key, IV);
162
+ return Buffer.concat([IV, aes.update(buffer), aes.final()]);
163
+ }
164
+
165
+ function aesEncrypWithIV(buffer, key, IV) {
166
+ const aes = (0, crypto_1.createCipheriv)('aes-256-cbc', key, IV);
167
+ return Buffer.concat([aes.update(buffer), aes.final()]);
168
+ }
169
+
170
+ function hmacSign(buffer, key, variant = 'sha256') {
171
+ return (0, crypto_1.createHmac)(variant, key).update(buffer).digest();
172
+ }
173
+ function sha256(buffer) {
174
+ return (0, crypto_1.createHash)('sha256').update(buffer).digest();
175
+ }
176
+ function md5(buffer) {
177
+ return (0, crypto_1.createHash)('md5').update(buffer).digest();
178
+ }
179
+
180
+ async function hkdf(buffer, expandedLength, info) {
181
+
182
+ const inputKeyMaterial = buffer instanceof Uint8Array
183
+ ? buffer
184
+ : new Uint8Array(buffer);
185
+
186
+ const salt = info.salt ? new Uint8Array(info.salt) : new Uint8Array(0);
187
+ const infoBytes = info.info
188
+ ? new TextEncoder().encode(info.info)
189
+ : new Uint8Array(0);
190
+
191
+ const importedKey = await subtle.importKey('raw', inputKeyMaterial, { name: 'HKDF' }, false, ['deriveBits']);
192
+
193
+ const derivedBits = await subtle.deriveBits({
194
+ name: 'HKDF',
195
+ hash: 'SHA-256',
196
+ salt: salt,
197
+ info: infoBytes
198
+ }, importedKey, expandedLength * 8
199
+ );
200
+ return Buffer.from(derivedBits);
201
+ }
202
+ async function derivePairingCodeKey(pairingCode, salt) {
203
+
204
+ const encoder = new TextEncoder();
205
+ const pairingCodeBuffer = encoder.encode(pairingCode);
206
+ const saltBuffer = salt instanceof Uint8Array ? salt : new Uint8Array(salt);
207
+
208
+ const keyMaterial = await subtle.importKey('raw', pairingCodeBuffer, { name: 'PBKDF2' }, false, ['deriveBits']);
209
+
210
+
211
+ const derivedBits = await subtle.deriveBits({
212
+ name: 'PBKDF2',
213
+ salt: saltBuffer,
214
+ iterations: 2 << 16,
215
+ hash: 'SHA-256'
216
+ }, keyMaterial, 32 * 8
217
+ );
218
+ return Buffer.from(derivedBits);
219
+ }
@@ -0,0 +1,61 @@
1
+ export const __esModule: boolean;
2
+ export const NO_MESSAGE_FOUND_ERROR_TEXT: "Message absent from node";
3
+ export const MISSING_KEYS_ERROR_TEXT: "Key used already or never filled";
4
+ export namespace NACK_REASONS {
5
+ let ParsingError: number;
6
+ let UnrecognizedStanza: number;
7
+ let UnrecognizedStanzaClass: number;
8
+ let UnrecognizedStanzaType: number;
9
+ let InvalidProtobuf: number;
10
+ let InvalidHostedCompanionStanza: number;
11
+ let MissingMessageSecret: number;
12
+ let SignalErrorOldCounter: number;
13
+ let MessageDeletedOnPeer: number;
14
+ let UnhandledError: number;
15
+ let UnsupportedAdminRevoke: number;
16
+ let UnsupportedLIDGroup: number;
17
+ let DBOperationFailed: number;
18
+ }
19
+ /**
20
+ * Decode the received node as a message.
21
+ * @note this will only parse the message, not decrypt it
22
+ */
23
+ export function decodeMessageNode(stanza: any, meId: any, meLid: any): {
24
+ fullMessage: {
25
+ key: {
26
+ remoteJid: any;
27
+ fromMe: any;
28
+ id: any;
29
+ senderPn: any;
30
+ senderLid: any;
31
+ participant: any;
32
+ participantLid: any;
33
+ server_id: any;
34
+ };
35
+ messageTimestamp: number;
36
+ pushName: any;
37
+ broadcast: any;
38
+ };
39
+ author: any;
40
+ sender: any;
41
+ };
42
+ export function decryptMessageNode(stanza: any, meId: any, meLid: any, repository: any, logger: any): {
43
+ fullMessage: {
44
+ key: {
45
+ remoteJid: any;
46
+ fromMe: any;
47
+ id: any;
48
+ senderPn: any;
49
+ senderLid: any;
50
+ participant: any;
51
+ participantLid: any;
52
+ server_id: any;
53
+ };
54
+ messageTimestamp: number;
55
+ pushName: any;
56
+ broadcast: any;
57
+ };
58
+ category: any;
59
+ author: any;
60
+ decrypt(): Promise<void>;
61
+ };
@@ -0,0 +1,233 @@
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.decryptMessageNode = exports.NACK_REASONS = exports.MISSING_KEYS_ERROR_TEXT = exports.NO_MESSAGE_FOUND_ERROR_TEXT = void 0;
30
+ exports.decodeMessageNode = decodeMessageNode;
31
+ const boom_1 = require("@hapi/boom");
32
+ const WAProto_1 = require("../../WAProto");
33
+ const WABinary_1 = require("../WABinary");
34
+ const generics_1 = require("./generics");
35
+ exports.NO_MESSAGE_FOUND_ERROR_TEXT = 'Message absent from node';
36
+ exports.MISSING_KEYS_ERROR_TEXT = 'Key used already or never filled';
37
+ exports.NACK_REASONS = {
38
+ ParsingError: 487,
39
+ UnrecognizedStanza: 488,
40
+ UnrecognizedStanzaClass: 489,
41
+ UnrecognizedStanzaType: 490,
42
+ InvalidProtobuf: 491,
43
+ InvalidHostedCompanionStanza: 493,
44
+ MissingMessageSecret: 495,
45
+ SignalErrorOldCounter: 496,
46
+ MessageDeletedOnPeer: 499,
47
+ UnhandledError: 500,
48
+ UnsupportedAdminRevoke: 550,
49
+ UnsupportedLIDGroup: 551,
50
+ DBOperationFailed: 552
51
+ };
52
+ /**
53
+ * Decode the received node as a message.
54
+ * @note this will only parse the message, not decrypt it
55
+ */
56
+ function decodeMessageNode(stanza, meId, meLid) {
57
+ var _a, _b, _c, _d, _e, _f, _g;
58
+ let msgType;
59
+ let chatId;
60
+ let author;
61
+ const msgId = stanza.attrs.id;
62
+ const from = stanza.attrs.from;
63
+ const senderPn = (_a = stanza === null || stanza === void 0 ? void 0 : stanza.attrs) === null || _a === void 0 ? void 0 : _a.sender_pn;
64
+ const senderLid = (_b = stanza === null || stanza === void 0 ? void 0 : stanza.attrs) === null || _b === void 0 ? void 0 : _b.sender_lid;
65
+ const participant = stanza.attrs.participant;
66
+ const participantLid = (_c = stanza === null || stanza === void 0 ? void 0 : stanza.attrs) === null || _c === void 0 ? void 0 : _c.participant_lid;
67
+ const recipient = stanza.attrs.recipient;
68
+ const isMe = (jid) => (0, WABinary_1.areJidsSameUser)(jid, meId);
69
+ const isMeLid = (jid) => (0, WABinary_1.areJidsSameUser)(jid, meLid);
70
+ if ((0, WABinary_1.isJidUser)(from) || (0, WABinary_1.isLidUser)(from)) {
71
+ if (recipient && !(0, WABinary_1.isJidMetaAi)(recipient)) {
72
+ if (!isMe(from) && !isMeLid(from)) {
73
+ throw new boom_1.Boom('receipient present, but msg not from me', { data: stanza });
74
+ }
75
+ chatId = recipient;
76
+ }
77
+ else {
78
+ chatId = from;
79
+ }
80
+ msgType = 'chat';
81
+ author = from;
82
+ }
83
+ else if ((0, WABinary_1.isJidGroup)(from)) {
84
+ if (!participant) {
85
+ throw new boom_1.Boom('No participant in group message');
86
+ }
87
+ msgType = 'group';
88
+ author = participant;
89
+ chatId = from;
90
+ }
91
+ else if ((0, WABinary_1.isJidNewsletter)(from)) {
92
+ msgType = 'newsletter';
93
+ author = from;
94
+ chatId = from;
95
+ }
96
+ else if ((0, WABinary_1.isJidBroadcast)(from)) {
97
+ if (!participant) {
98
+ throw new boom_1.Boom('No participant in group message');
99
+ }
100
+ const isParticipantMe = isMe(participant);
101
+ if ((0, WABinary_1.isJidStatusBroadcast)(from)) {
102
+ msgType = isParticipantMe ? 'direct_peer_status' : 'other_status';
103
+ }
104
+ else {
105
+ msgType = isParticipantMe ? 'peer_broadcast' : 'other_broadcast';
106
+ }
107
+ chatId = from;
108
+ author = participant;
109
+ }
110
+ else {
111
+ throw new boom_1.Boom('Unknown message type', { data: stanza });
112
+ }
113
+ const fromMe = (0, WABinary_1.isJidNewsletter)(from) ? !!((_d = stanza.attrs) === null || _d === void 0 ? void 0 : _d.is_sender) || false : ((0, WABinary_1.isLidUser)(from) ? isMeLid : isMe)(stanza.attrs.participant || stanza.attrs.from);
114
+ const pushname = (_e = stanza === null || stanza === void 0 ? void 0 : stanza.attrs) === null || _e === void 0 ? void 0 : _e.notify;
115
+ const key = {
116
+ remoteJid: chatId,
117
+ fromMe,
118
+ id: msgId,
119
+ senderPn,
120
+ senderLid,
121
+ participant,
122
+ participantLid,
123
+ 'server_id': (_f = stanza.attrs) === null || _f === void 0 ? void 0 : _f.server_id
124
+ };
125
+ const fullMessage = {
126
+ key,
127
+ messageTimestamp: +stanza.attrs.t,
128
+ pushName: pushname,
129
+ broadcast: (0, WABinary_1.isJidBroadcast)(from)
130
+ };
131
+ if (msgType === 'newsletter') {
132
+ fullMessage.newsletterServerId = +((_g = stanza.attrs) === null || _g === void 0 ? void 0 : _g.server_id);
133
+ }
134
+ if (key.fromMe) {
135
+ fullMessage.status = WAProto_1.proto.WebMessageInfo.Status.SERVER_ACK;
136
+ }
137
+ return {
138
+ fullMessage,
139
+ author,
140
+ sender: msgType === 'chat' ? author : chatId
141
+ };
142
+ }
143
+ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
144
+ const { fullMessage, author, sender } = decodeMessageNode(stanza, meId, meLid);
145
+ return {
146
+ fullMessage,
147
+ category: stanza.attrs.category,
148
+ author,
149
+ async decrypt() {
150
+ var _a;
151
+ let decryptables = 0;
152
+ if (Array.isArray(stanza.content)) {
153
+ for (const { tag, attrs, content } of stanza.content) {
154
+ if (tag === 'verified_name' && content instanceof Uint8Array) {
155
+ const cert = WAProto_1.proto.VerifiedNameCertificate.decode(content);
156
+ const details = WAProto_1.proto.VerifiedNameCertificate.Details.decode(cert.details);
157
+ fullMessage.verifiedBizName = details.verifiedName;
158
+ }
159
+ if (tag === 'unavailable' && attrs.type === 'view_once') {
160
+ fullMessage.key.isViewOnce = true;
161
+ }
162
+ if (tag !== 'enc' && tag !== 'plaintext') {
163
+ continue;
164
+ }
165
+ if (!(content instanceof Uint8Array)) {
166
+ continue;
167
+ }
168
+ decryptables += 1;
169
+ let msgBuffer;
170
+ try {
171
+ const e2eType = tag === 'plaintext' ? 'plaintext' : attrs.type;
172
+ switch (e2eType) {
173
+ case 'skmsg':
174
+ msgBuffer = await repository.decryptGroupMessage({
175
+ group: sender,
176
+ authorJid: author,
177
+ msg: content
178
+ });
179
+ break;
180
+ case 'pkmsg':
181
+ case 'msg':
182
+ const user = (0, WABinary_1.isJidUser)(sender) ? sender : author;
183
+ msgBuffer = await repository.decryptMessage({
184
+ jid: user,
185
+ type: e2eType,
186
+ ciphertext: content
187
+ });
188
+ break;
189
+ case 'plaintext':
190
+ msgBuffer = content;
191
+ break;
192
+ case undefined:
193
+ msgBuffer = content;
194
+ break;
195
+ default:
196
+ throw new Error(`Unknown e2e type: ${e2eType}`);
197
+ }
198
+ let msg = WAProto_1.proto.Message.decode(e2eType !== 'plaintext' ? (0, generics_1.unpadRandomMax16)(msgBuffer) : msgBuffer);
199
+ msg = ((_a = msg === null || msg === void 0 ? void 0 : msg.deviceSentMessage) === null || _a === void 0 ? void 0 : _a.message) || msg;
200
+ if (msg.senderKeyDistributionMessage) {
201
+ try {
202
+ await repository.processSenderKeyDistributionMessage({
203
+ authorJid: author,
204
+ item: msg.senderKeyDistributionMessage
205
+ });
206
+ }
207
+ catch (err) {
208
+ logger.error({ key: fullMessage.key, err }, 'failed to decrypt message');
209
+ }
210
+ }
211
+ if (fullMessage.message) {
212
+ Object.assign(fullMessage.message, msg);
213
+ }
214
+ else {
215
+ fullMessage.message = msg;
216
+ }
217
+ }
218
+ catch (err) {
219
+ logger.error({ key: fullMessage.key, err }, 'failed to decrypt message');
220
+ fullMessage.messageStubType = WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT;
221
+ fullMessage.messageStubParameters = [err.message];
222
+ }
223
+ }
224
+ }
225
+
226
+ if (!decryptables) {
227
+ fullMessage.messageStubType = WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT;
228
+ fullMessage.messageStubParameters = [exports.NO_MESSAGE_FOUND_ERROR_TEXT];
229
+ }
230
+ }
231
+ };
232
+ };
233
+ exports.decryptMessageNode = decryptMessageNode;
@@ -0,0 +1,17 @@
1
+ export const __esModule: boolean;
2
+ /**
3
+ * The event buffer logically consolidates different events into a single event
4
+ * making the data processing more efficient.
5
+ * @param ev the ye-bail event emitter
6
+ */
7
+ export function makeEventBuffer(logger: any): {
8
+ process(handler: any): () => void;
9
+ emit(event: any, evData: any): any;
10
+ isBuffering(): boolean;
11
+ buffer: () => void;
12
+ flush: (force?: boolean) => boolean;
13
+ createBufferedFunction(work: any): (...args: any[]) => Promise<any>;
14
+ on: (...args: any[]) => any;
15
+ off: (...args: any[]) => any;
16
+ removeAllListeners: (...args: any[]) => any;
17
+ };