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,95 @@
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.SenderKeyMessage = void 0;
30
+ const curve_1 = require("libsignal/src/curve");
31
+ const WAProto_1 = require("../../../WAProto");
32
+ const ciphertext_message_1 = require("./ciphertext-message");
33
+ class SenderKeyMessage extends ciphertext_message_1.CiphertextMessage {
34
+ constructor(keyId, iteration, ciphertext, signatureKey, serialized) {
35
+ super();
36
+ this.SIGNATURE_LENGTH = 64;
37
+ if (serialized) {
38
+ const version = serialized[0];
39
+ const message = serialized.slice(1, serialized.length - this.SIGNATURE_LENGTH);
40
+ const signature = serialized.slice(-1 * this.SIGNATURE_LENGTH);
41
+ const senderKeyMessage = WAProto_1.proto.SenderKeyMessage.decode(message).toJSON();
42
+ this.serialized = serialized;
43
+ this.messageVersion = (version & 0xff) >> 4;
44
+ this.keyId = senderKeyMessage.id;
45
+ this.iteration = senderKeyMessage.iteration;
46
+ this.ciphertext =
47
+ typeof senderKeyMessage.ciphertext === 'string'
48
+ ? Buffer.from(senderKeyMessage.ciphertext, 'base64')
49
+ : senderKeyMessage.ciphertext;
50
+ this.signature = signature;
51
+ }
52
+ else {
53
+ const version = (((this.CURRENT_VERSION << 4) | this.CURRENT_VERSION) & 0xff) % 256;
54
+ const ciphertextBuffer = Buffer.from(ciphertext);
55
+ const message = WAProto_1.proto.SenderKeyMessage.encode(WAProto_1.proto.SenderKeyMessage.create({
56
+ id: keyId,
57
+ iteration: iteration,
58
+ ciphertext: ciphertextBuffer
59
+ })).finish();
60
+ const signature = this.getSignature(signatureKey, Buffer.concat([Buffer.from([version]), message]));
61
+ this.serialized = Buffer.concat([Buffer.from([version]), message, Buffer.from(signature)]);
62
+ this.messageVersion = this.CURRENT_VERSION;
63
+ this.keyId = keyId;
64
+ this.iteration = iteration;
65
+ this.ciphertext = ciphertextBuffer;
66
+ this.signature = signature;
67
+ }
68
+ }
69
+ getKeyId() {
70
+ return this.keyId;
71
+ }
72
+ getIteration() {
73
+ return this.iteration;
74
+ }
75
+ getCipherText() {
76
+ return this.ciphertext;
77
+ }
78
+ verifySignature(signatureKey) {
79
+ const part1 = this.serialized.slice(0, this.serialized.length - this.SIGNATURE_LENGTH);
80
+ const part2 = this.serialized.slice(-1 * this.SIGNATURE_LENGTH);
81
+ const res = (0, curve_1.verifySignature)(signatureKey, part1, part2);
82
+ if (!res)
83
+ throw new Error('Invalid signature!');
84
+ }
85
+ getSignature(signatureKey, serialized) {
86
+ return Buffer.from((0, curve_1.calculateSignature)(signatureKey, serialized));
87
+ }
88
+ serialize() {
89
+ return this.serialized;
90
+ }
91
+ getType() {
92
+ return 4;
93
+ }
94
+ }
95
+ exports.SenderKeyMessage = SenderKeyMessage;
@@ -0,0 +1,12 @@
1
+ export const __esModule: boolean;
2
+ export class SenderKeyName {
3
+ constructor(groupId: any, sender: any);
4
+ groupId: any;
5
+ sender: any;
6
+ getGroupId(): any;
7
+ getSender(): any;
8
+ serialize(): string;
9
+ toString(): string;
10
+ equals(other: any): boolean;
11
+ hashCode(): number;
12
+ }
@@ -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.SenderKeyName = void 0;
30
+ function isNull(str) {
31
+ return str === null || str === '';
32
+ }
33
+ function intValue(num) {
34
+ const MAX_VALUE = 0x7fffffff;
35
+ const MIN_VALUE = -0x80000000;
36
+ if (num > MAX_VALUE || num < MIN_VALUE) {
37
+ return num & 0xffffffff;
38
+ }
39
+ return num;
40
+ }
41
+ function hashCode(strKey) {
42
+ let hash = 0;
43
+ if (!isNull(strKey)) {
44
+ for (let i = 0; i < strKey.length; i++) {
45
+ hash = hash * 31 + strKey.charCodeAt(i);
46
+ hash = intValue(hash);
47
+ }
48
+ }
49
+ return hash;
50
+ }
51
+ class SenderKeyName {
52
+ constructor(groupId, sender) {
53
+ this.groupId = groupId;
54
+ this.sender = sender;
55
+ }
56
+ getGroupId() {
57
+ return this.groupId;
58
+ }
59
+ getSender() {
60
+ return this.sender;
61
+ }
62
+ serialize() {
63
+ return `${this.groupId}::${this.sender.id}::${this.sender.deviceId}`;
64
+ }
65
+ toString() {
66
+ return this.serialize();
67
+ }
68
+ equals(other) {
69
+ if (other === null)
70
+ return false;
71
+ return this.groupId === other.groupId && this.sender.toString() === other.sender.toString();
72
+ }
73
+ hashCode() {
74
+ return hashCode(this.groupId) ^ hashCode(this.sender.toString());
75
+ }
76
+ }
77
+ exports.SenderKeyName = SenderKeyName;
@@ -0,0 +1,13 @@
1
+ export const __esModule: boolean;
2
+ export class SenderKeyRecord {
3
+ static deserialize(data: any): SenderKeyRecord;
4
+ constructor(serialized: any);
5
+ MAX_STATES: number;
6
+ senderKeyStates: sender_key_state_1.SenderKeyState[];
7
+ isEmpty(): boolean;
8
+ getSenderKeyState(keyId: any): sender_key_state_1.SenderKeyState;
9
+ addSenderKeyState(id: any, iteration: any, chainKey: any, signatureKey: any): void;
10
+ setSenderKeyState(id: any, iteration: any, chainKey: any, keyPair: any): void;
11
+ serialize(): any[];
12
+ }
13
+ import sender_key_state_1 = require("./sender-key-state");
@@ -0,0 +1,79 @@
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.SenderKeyRecord = void 0;
30
+ const generics_1 = require("../../Utils/generics");
31
+ const sender_key_state_1 = require("./sender-key-state");
32
+ class SenderKeyRecord {
33
+ constructor(serialized) {
34
+ this.MAX_STATES = 5;
35
+ this.senderKeyStates = [];
36
+ if (serialized) {
37
+ for (const structure of serialized) {
38
+ this.senderKeyStates.push(new sender_key_state_1.SenderKeyState(null, null, null, null, null, null, structure));
39
+ }
40
+ }
41
+ }
42
+ isEmpty() {
43
+ return this.senderKeyStates.length === 0;
44
+ }
45
+ getSenderKeyState(keyId) {
46
+ if (keyId === undefined && this.senderKeyStates.length) {
47
+ return this.senderKeyStates[this.senderKeyStates.length - 1];
48
+ }
49
+ return this.senderKeyStates.find(state => state.getKeyId() === keyId);
50
+ }
51
+ addSenderKeyState(id, iteration, chainKey, signatureKey) {
52
+ this.senderKeyStates.push(new sender_key_state_1.SenderKeyState(id, iteration, chainKey, null, signatureKey));
53
+ if (this.senderKeyStates.length > this.MAX_STATES) {
54
+ this.senderKeyStates.shift();
55
+ }
56
+ }
57
+ setSenderKeyState(id, iteration, chainKey, keyPair) {
58
+ this.senderKeyStates.length = 0;
59
+ this.senderKeyStates.push(new sender_key_state_1.SenderKeyState(id, iteration, chainKey, keyPair));
60
+ }
61
+ serialize() {
62
+ return this.senderKeyStates.map(state => state.getStructure());
63
+ }
64
+ static deserialize(data) {
65
+ let parsed;
66
+ if (typeof data === 'string') {
67
+ parsed = JSON.parse(data, generics_1.BufferJSON.reviver);
68
+ }
69
+ else if (data instanceof Uint8Array) {
70
+ const str = Buffer.from(data).toString('utf-8');
71
+ parsed = JSON.parse(str, generics_1.BufferJSON.reviver);
72
+ }
73
+ else {
74
+ parsed = data;
75
+ }
76
+ return new SenderKeyRecord(parsed);
77
+ }
78
+ }
79
+ exports.SenderKeyRecord = SenderKeyRecord;
@@ -0,0 +1,17 @@
1
+ export const __esModule: boolean;
2
+ export class SenderKeyState {
3
+ constructor(id: any, iteration: any, chainKey: any, signatureKeyPair: any, signatureKeyPublic: any, signatureKeyPrivate: any, senderKeyStateStructure: any);
4
+ MAX_MESSAGE_KEYS: number;
5
+ senderKeyStateStructure: any;
6
+ getKeyId(): any;
7
+ getSenderChainKey(): sender_chain_key_1.SenderChainKey;
8
+ setSenderChainKey(chainKey: any): void;
9
+ getSigningKeyPublic(): Buffer<any>;
10
+ getSigningKeyPrivate(): Buffer<any>;
11
+ hasSenderMessageKey(iteration: any): any;
12
+ addSenderMessageKey(senderMessageKey: any): void;
13
+ removeSenderMessageKey(iteration: any): sender_message_key_1.SenderMessageKey;
14
+ getStructure(): any;
15
+ }
16
+ import sender_chain_key_1 = require("./sender-chain-key");
17
+ import sender_message_key_1 = require("./sender-message-key");
@@ -0,0 +1,125 @@
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.SenderKeyState = void 0;
30
+ const sender_chain_key_1 = require("./sender-chain-key");
31
+ const sender_message_key_1 = require("./sender-message-key");
32
+ class SenderKeyState {
33
+ constructor(id, iteration, chainKey, signatureKeyPair, signatureKeyPublic, signatureKeyPrivate, senderKeyStateStructure) {
34
+ this.MAX_MESSAGE_KEYS = 2000;
35
+ if (senderKeyStateStructure) {
36
+ this.senderKeyStateStructure = senderKeyStateStructure;
37
+ }
38
+ else {
39
+ if (signatureKeyPair) {
40
+ signatureKeyPublic = signatureKeyPair.public;
41
+ signatureKeyPrivate = signatureKeyPair.private;
42
+ }
43
+ chainKey = typeof chainKey === 'string' ? Buffer.from(chainKey, 'base64') : chainKey;
44
+ const senderChainKeyStructure = {
45
+ iteration: iteration || 0,
46
+ seed: chainKey || Buffer.alloc(0)
47
+ };
48
+ const signingKeyStructure = {
49
+ public: typeof signatureKeyPublic === 'string'
50
+ ? Buffer.from(signatureKeyPublic, 'base64')
51
+ : signatureKeyPublic || Buffer.alloc(0)
52
+ };
53
+ if (signatureKeyPrivate) {
54
+ signingKeyStructure.private =
55
+ typeof signatureKeyPrivate === 'string' ? Buffer.from(signatureKeyPrivate, 'base64') : signatureKeyPrivate;
56
+ }
57
+ this.senderKeyStateStructure = {
58
+ senderKeyId: id || 0,
59
+ senderChainKey: senderChainKeyStructure,
60
+ senderSigningKey: signingKeyStructure,
61
+ senderMessageKeys: []
62
+ };
63
+ }
64
+ }
65
+ getKeyId() {
66
+ return this.senderKeyStateStructure.senderKeyId;
67
+ }
68
+ getSenderChainKey() {
69
+ return new sender_chain_key_1.SenderChainKey(this.senderKeyStateStructure.senderChainKey.iteration, this.senderKeyStateStructure.senderChainKey.seed);
70
+ }
71
+ setSenderChainKey(chainKey) {
72
+ this.senderKeyStateStructure.senderChainKey = {
73
+ iteration: chainKey.getIteration(),
74
+ seed: chainKey.getSeed()
75
+ };
76
+ }
77
+ getSigningKeyPublic() {
78
+ const publicKey = this.senderKeyStateStructure.senderSigningKey.public;
79
+ if (publicKey instanceof Buffer) {
80
+ return publicKey;
81
+ }
82
+ else if (typeof publicKey === 'string') {
83
+ return Buffer.from(publicKey, 'base64');
84
+ }
85
+ return Buffer.from(publicKey || []);
86
+ }
87
+ getSigningKeyPrivate() {
88
+ const privateKey = this.senderKeyStateStructure.senderSigningKey.private;
89
+ if (!privateKey) {
90
+ return undefined;
91
+ }
92
+ if (privateKey instanceof Buffer) {
93
+ return privateKey;
94
+ }
95
+ else if (typeof privateKey === 'string') {
96
+ return Buffer.from(privateKey, 'base64');
97
+ }
98
+ return Buffer.from(privateKey || []);
99
+ }
100
+ hasSenderMessageKey(iteration) {
101
+ return this.senderKeyStateStructure.senderMessageKeys.some(key => key.iteration === iteration);
102
+ }
103
+ addSenderMessageKey(senderMessageKey) {
104
+ this.senderKeyStateStructure.senderMessageKeys.push({
105
+ iteration: senderMessageKey.getIteration(),
106
+ seed: senderMessageKey.getSeed()
107
+ });
108
+ if (this.senderKeyStateStructure.senderMessageKeys.length > this.MAX_MESSAGE_KEYS) {
109
+ this.senderKeyStateStructure.senderMessageKeys.shift();
110
+ }
111
+ }
112
+ removeSenderMessageKey(iteration) {
113
+ const index = this.senderKeyStateStructure.senderMessageKeys.findIndex(key => key.iteration === iteration);
114
+ if (index !== -1) {
115
+ const messageKey = this.senderKeyStateStructure.senderMessageKeys[index];
116
+ this.senderKeyStateStructure.senderMessageKeys.splice(index, 1);
117
+ return new sender_message_key_1.SenderMessageKey(messageKey.iteration, messageKey.seed);
118
+ }
119
+ return null;
120
+ }
121
+ getStructure() {
122
+ return this.senderKeyStateStructure;
123
+ }
124
+ }
125
+ exports.SenderKeyState = SenderKeyState;
@@ -0,0 +1,12 @@
1
+ export const __esModule: boolean;
2
+ export class SenderMessageKey {
3
+ constructor(iteration: any, seed: any);
4
+ iv: Buffer<ArrayBuffer>;
5
+ cipherKey: Buffer<ArrayBufferLike>;
6
+ iteration: any;
7
+ seed: any;
8
+ getIteration(): any;
9
+ getIv(): Buffer<ArrayBuffer>;
10
+ getCipherKey(): Buffer<ArrayBufferLike>;
11
+ getSeed(): any;
12
+ }
@@ -0,0 +1,55 @@
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.SenderMessageKey = void 0;
30
+ const crypto_1 = require("libsignal/src/crypto");
31
+ class SenderMessageKey {
32
+ constructor(iteration, seed) {
33
+ const derivative = (0, crypto_1.deriveSecrets)(seed, Buffer.alloc(32), Buffer.from('WhisperGroup'));
34
+ const keys = new Uint8Array(32);
35
+ keys.set(new Uint8Array(derivative[0].slice(16)));
36
+ keys.set(new Uint8Array(derivative[1].slice(0, 16)), 16);
37
+ this.iv = Buffer.from(derivative[0].slice(0, 16));
38
+ this.cipherKey = Buffer.from(keys.buffer);
39
+ this.iteration = iteration;
40
+ this.seed = seed;
41
+ }
42
+ getIteration() {
43
+ return this.iteration;
44
+ }
45
+ getIv() {
46
+ return this.iv;
47
+ }
48
+ getCipherKey() {
49
+ return this.cipherKey;
50
+ }
51
+ getSeed() {
52
+ return this.seed;
53
+ }
54
+ }
55
+ exports.SenderMessageKey = SenderMessageKey;
@@ -0,0 +1,37 @@
1
+ export const __esModule: boolean;
2
+ export function makeLibSignalRepository(auth: any): {
3
+ decryptGroupMessage({ group, authorJid, msg }: {
4
+ group: any;
5
+ authorJid: any;
6
+ msg: any;
7
+ }): Promise<any>;
8
+ processSenderKeyDistributionMessage({ item, authorJid }: {
9
+ item: any;
10
+ authorJid: any;
11
+ }): Promise<void>;
12
+ decryptMessage({ jid, type, ciphertext }: {
13
+ jid: any;
14
+ type: any;
15
+ ciphertext: any;
16
+ }): Promise<any>;
17
+ encryptMessage({ jid, data }: {
18
+ jid: any;
19
+ data: any;
20
+ }): Promise<{
21
+ type: string;
22
+ ciphertext: Buffer<ArrayBuffer>;
23
+ }>;
24
+ encryptGroupMessage({ group, meId, data }: {
25
+ group: any;
26
+ meId: any;
27
+ data: any;
28
+ }): Promise<{
29
+ ciphertext: any;
30
+ senderKeyDistributionMessage: any;
31
+ }>;
32
+ injectE2ESession({ jid, session }: {
33
+ jid: any;
34
+ session: any;
35
+ }): Promise<void>;
36
+ jidToSignalProtocolAddress(jid: any): any;
37
+ };