fca-nx 6.6.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (196) hide show
  1. package/LICENCE +21 -0
  2. package/README.md +446 -0
  3. package/e2ee/config.json +0 -0
  4. package/e2ee/crypto.js +173 -0
  5. package/e2ee/index.js +1032 -0
  6. package/e2ee/proto/ArmadilloApplication.proto +281 -0
  7. package/e2ee/proto/ArmadilloICDC.proto +14 -0
  8. package/e2ee/proto/ConsumerApplication.proto +232 -0
  9. package/e2ee/proto/MessageApplication.proto +82 -0
  10. package/e2ee/proto/MessageTransport.proto +77 -0
  11. package/e2ee/proto/WACommon.proto +66 -0
  12. package/e2ee/proto/WAMediaTransport.proto +176 -0
  13. package/e2ee/protocol.js +196 -0
  14. package/e2ee/ratchet.js +219 -0
  15. package/e2ee/store.js +182 -0
  16. package/e2ee/vendor/fb-e2ee.cjs +9159 -0
  17. package/e2ee/vendor/proto/ArmadilloApplication.proto +281 -0
  18. package/e2ee/vendor/proto/ArmadilloICDC.proto +14 -0
  19. package/e2ee/vendor/proto/ConsumerApplication.proto +232 -0
  20. package/e2ee/vendor/proto/MessageApplication.proto +82 -0
  21. package/e2ee/vendor/proto/MessageTransport.proto +77 -0
  22. package/e2ee/vendor/proto/WACommon.proto +66 -0
  23. package/e2ee/vendor/proto/WAMediaTransport.proto +176 -0
  24. package/func/checkUpdate.js +7 -0
  25. package/func/logAdapter.js +33 -0
  26. package/func/logger.js +134 -0
  27. package/index.js +22 -0
  28. package/module/config.js +45 -0
  29. package/module/login.js +183 -0
  30. package/module/loginHelper.js +1382 -0
  31. package/module/options.js +52 -0
  32. package/package.json +101 -0
  33. package/src/api/action/addExternalModule.js +25 -0
  34. package/src/api/action/addFriend.js +145 -0
  35. package/src/api/action/changeAvatar.js +137 -0
  36. package/src/api/action/changeBio.js +75 -0
  37. package/src/api/action/changeCover.js +277 -0
  38. package/src/api/action/enableAutoSaveAppState.js +73 -0
  39. package/src/api/action/getCurrentUserID.js +7 -0
  40. package/src/api/action/handleFriendRequest.js +57 -0
  41. package/src/api/action/logout.js +76 -0
  42. package/src/api/action/refreshFb_dtsg.js +48 -0
  43. package/src/api/action/setPostReaction.js +106 -0
  44. package/src/api/action/unfriend.js +54 -0
  45. package/src/api/http/httpGet.js +46 -0
  46. package/src/api/http/httpPost.js +52 -0
  47. package/src/api/http/postFormData.js +47 -0
  48. package/src/api/messaging/addUserToGroup.js +68 -0
  49. package/src/api/messaging/changeAdminStatus.js +126 -0
  50. package/src/api/messaging/changeArchivedStatus.js +55 -0
  51. package/src/api/messaging/changeBlockedStatus.js +48 -0
  52. package/src/api/messaging/changeGroupImage.js +91 -0
  53. package/src/api/messaging/changeNickname.js +70 -0
  54. package/src/api/messaging/changeThreadColor.js +79 -0
  55. package/src/api/messaging/changeThreadEmoji.js +111 -0
  56. package/src/api/messaging/createNewGroup.js +88 -0
  57. package/src/api/messaging/createPoll.js +46 -0
  58. package/src/api/messaging/createThemeAI.js +98 -0
  59. package/src/api/messaging/deleteMessage.js +136 -0
  60. package/src/api/messaging/deleteThread.js +56 -0
  61. package/src/api/messaging/editMessage.js +90 -0
  62. package/src/api/messaging/forwardAttachment.js +57 -0
  63. package/src/api/messaging/forwardMessage.js +134 -0
  64. package/src/api/messaging/getEmojiUrl.js +29 -0
  65. package/src/api/messaging/getFriendsList.js +82 -0
  66. package/src/api/messaging/getMessage.js +829 -0
  67. package/src/api/messaging/getThemePictures.js +62 -0
  68. package/src/api/messaging/handleMessageRequest.js +65 -0
  69. package/src/api/messaging/markAsDelivered.js +57 -0
  70. package/src/api/messaging/markAsRead.js +88 -0
  71. package/src/api/messaging/markAsReadAll.js +49 -0
  72. package/src/api/messaging/markAsSeen.js +61 -0
  73. package/src/api/messaging/muteThread.js +50 -0
  74. package/src/api/messaging/pinMessage.js +115 -0
  75. package/src/api/messaging/removeUserFromGroup.js +62 -0
  76. package/src/api/messaging/resolvePhotoUrl.js +43 -0
  77. package/src/api/messaging/scheduler.js +264 -0
  78. package/src/api/messaging/searchForThread.js +53 -0
  79. package/src/api/messaging/sendBroadcast.js +93 -0
  80. package/src/api/messaging/sendMessage.js +269 -0
  81. package/src/api/messaging/sendTypingIndicator.js +74 -0
  82. package/src/api/messaging/sessionGuard.js +208 -0
  83. package/src/api/messaging/setMessageReaction.js +95 -0
  84. package/src/api/messaging/setTitle.js +124 -0
  85. package/src/api/messaging/shareContact.js +49 -0
  86. package/src/api/messaging/threadColors.js +128 -0
  87. package/src/api/messaging/unsendMessage.js +81 -0
  88. package/src/api/messaging/uploadAttachment.js +523 -0
  89. package/src/api/socket/OldMessage.js +186 -0
  90. package/src/api/socket/core/connectMqtt.js +320 -0
  91. package/src/api/socket/core/emitAuth.js +103 -0
  92. package/src/api/socket/core/getSeqID.js +338 -0
  93. package/src/api/socket/core/getTaskResponseData.js +25 -0
  94. package/src/api/socket/core/parseDelta.js +387 -0
  95. package/src/api/socket/detail/buildStream.js +215 -0
  96. package/src/api/socket/detail/constants.js +28 -0
  97. package/src/api/socket/e2ee/crypto.js +173 -0
  98. package/src/api/socket/e2ee/e2ee/crypto.js +173 -0
  99. package/src/api/socket/e2ee/e2ee/index.js +421 -0
  100. package/src/api/socket/e2ee/e2ee/proto/ArmadilloApplication.proto +281 -0
  101. package/src/api/socket/e2ee/e2ee/proto/ArmadilloICDC.proto +14 -0
  102. package/src/api/socket/e2ee/e2ee/proto/ConsumerApplication.proto +232 -0
  103. package/src/api/socket/e2ee/e2ee/proto/MessageApplication.proto +82 -0
  104. package/src/api/socket/e2ee/e2ee/proto/MessageTransport.proto +77 -0
  105. package/src/api/socket/e2ee/e2ee/proto/WACommon.proto +66 -0
  106. package/src/api/socket/e2ee/e2ee/proto/WAMediaTransport.proto +176 -0
  107. package/src/api/socket/e2ee/e2ee/protocol.js +196 -0
  108. package/src/api/socket/e2ee/e2ee/ratchet.js +219 -0
  109. package/src/api/socket/e2ee/e2ee/store.js +182 -0
  110. package/src/api/socket/e2ee/e2ee/vendor/fb-e2ee.cjs +9162 -0
  111. package/src/api/socket/e2ee/e2ee/vendor/proto/ArmadilloApplication.proto +281 -0
  112. package/src/api/socket/e2ee/e2ee/vendor/proto/ArmadilloICDC.proto +14 -0
  113. package/src/api/socket/e2ee/e2ee/vendor/proto/ConsumerApplication.proto +232 -0
  114. package/src/api/socket/e2ee/e2ee/vendor/proto/MessageApplication.proto +82 -0
  115. package/src/api/socket/e2ee/e2ee/vendor/proto/MessageTransport.proto +77 -0
  116. package/src/api/socket/e2ee/e2ee/vendor/proto/WACommon.proto +66 -0
  117. package/src/api/socket/e2ee/e2ee/vendor/proto/WAMediaTransport.proto +176 -0
  118. package/src/api/socket/e2ee/index.js +437 -0
  119. package/src/api/socket/e2ee/proto/ArmadilloApplication.proto +281 -0
  120. package/src/api/socket/e2ee/proto/ArmadilloICDC.proto +14 -0
  121. package/src/api/socket/e2ee/proto/ConsumerApplication.proto +232 -0
  122. package/src/api/socket/e2ee/proto/MessageApplication.proto +82 -0
  123. package/src/api/socket/e2ee/proto/MessageTransport.proto +77 -0
  124. package/src/api/socket/e2ee/proto/WACommon.proto +66 -0
  125. package/src/api/socket/e2ee/proto/WAMediaTransport.proto +176 -0
  126. package/src/api/socket/e2ee/protocol.js +196 -0
  127. package/src/api/socket/e2ee/ratchet.js +219 -0
  128. package/src/api/socket/e2ee/store.js +182 -0
  129. package/src/api/socket/e2ee/vendor/fb-e2ee.cjs +9162 -0
  130. package/src/api/socket/e2ee/vendor/proto/ArmadilloApplication.proto +281 -0
  131. package/src/api/socket/e2ee/vendor/proto/ArmadilloICDC.proto +14 -0
  132. package/src/api/socket/e2ee/vendor/proto/ConsumerApplication.proto +232 -0
  133. package/src/api/socket/e2ee/vendor/proto/MessageApplication.proto +82 -0
  134. package/src/api/socket/e2ee/vendor/proto/MessageTransport.proto +77 -0
  135. package/src/api/socket/e2ee/vendor/proto/WACommon.proto +66 -0
  136. package/src/api/socket/e2ee/vendor/proto/WAMediaTransport.proto +176 -0
  137. package/src/api/socket/listenE2EE.js +75 -0
  138. package/src/api/socket/listenMqtt.js +551 -0
  139. package/src/api/socket/middleware/index.js +216 -0
  140. package/src/api/socket/sendMessage.js +309 -0
  141. package/src/api/socket/sendMessageMqtt.js +69 -0
  142. package/src/api/threads/getThreadHistory.js +664 -0
  143. package/src/api/threads/getThreadInfo.js +296 -0
  144. package/src/api/threads/getThreadList.js +293 -0
  145. package/src/api/threads/getThreadPictures.js +78 -0
  146. package/src/api/users/getUserID.js +65 -0
  147. package/src/api/users/getUserInfo.js +402 -0
  148. package/src/api/users/getUserInfoV2.js +911 -0
  149. package/src/app/MessengerBot.js +209 -0
  150. package/src/app/MessengerContext.js +32 -0
  151. package/src/app/createFcaClient.js +139 -0
  152. package/src/app/threadInfoRealtimeSync.js +284 -0
  153. package/src/core/sendReqMqtt.js +96 -0
  154. package/src/database/helpers.js +53 -0
  155. package/src/database/models/index.js +88 -0
  156. package/src/database/models/thread.js +50 -0
  157. package/src/database/models/user.js +46 -0
  158. package/src/database/threadData.js +94 -0
  159. package/src/database/userData.js +98 -0
  160. package/src/remote/remoteClient.js +123 -0
  161. package/src/utils/broadcast.js +51 -0
  162. package/src/utils/client.js +10 -0
  163. package/src/utils/clientIdentity.js +118 -0
  164. package/src/utils/constants.js +23 -0
  165. package/src/utils/cookies.js +68 -0
  166. package/src/utils/format/attachment.js +357 -0
  167. package/src/utils/format/cookie.js +9 -0
  168. package/src/utils/format/date.js +50 -0
  169. package/src/utils/format/decode.js +44 -0
  170. package/src/utils/format/delta.js +194 -0
  171. package/src/utils/format/ids.js +64 -0
  172. package/src/utils/format/index.js +64 -0
  173. package/src/utils/format/message.js +88 -0
  174. package/src/utils/format/presence.js +132 -0
  175. package/src/utils/format/readTyp.js +44 -0
  176. package/src/utils/format/thread.js +42 -0
  177. package/src/utils/format/utils.js +141 -0
  178. package/src/utils/headers.js +124 -0
  179. package/src/utils/logger.js +144 -0
  180. package/src/utils/loginParser/autoLogin.js +125 -0
  181. package/src/utils/loginParser/helpers.js +43 -0
  182. package/src/utils/loginParser/index.js +10 -0
  183. package/src/utils/loginParser/parseAndCheckLogin.js +220 -0
  184. package/src/utils/loginParser/textUtils.js +28 -0
  185. package/src/utils/request/client.js +26 -0
  186. package/src/utils/request/config.js +29 -0
  187. package/src/utils/request/defaults.js +46 -0
  188. package/src/utils/request/helpers.js +46 -0
  189. package/src/utils/request/index.js +17 -0
  190. package/src/utils/request/methods.js +163 -0
  191. package/src/utils/request/proxy.js +46 -0
  192. package/src/utils/request/retry.js +77 -0
  193. package/src/utils/request/sanitize.js +49 -0
  194. package/src/utils/utils.js +686 -0
  195. package/src/utils/versionCheck.js +47 -0
  196. package/src/vendor/fca-unofficial/index.js +11 -0
package/LICENCE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 xalmandevv
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,446 @@
1
+ <div align="center">
2
+
3
+ <img src="https://capsule-render.vercel.app/api?type=waving&color=0:0f172a,50:2563eb,100:06b6d4&height=220&section=header&text=FCA-NX&fontSize=72&fontColor=ffffff&animation=fadeIn&fontAlignY=38&desc=The%20Facebook%20Messenger%20API%20for%20Node.js&descAlignY=60&descSize=18" width="100%"/>
4
+
5
+ <img src="https://readme-typing-svg.demolab.com?font=JetBrains+Mono&weight=600&size=20&duration=2800&pause=900&color=38BDF8&center=true&vCenter=true&width=700&lines=⚡+Lightning+Fast+Messenger+API;🔒+Secure+Session+Management;🛡️+Auto-Healing+Architecture;🌐+90%2B+Powerful+API+Methods;🚀+Built+for+Modern+Node.js+Projects" />
6
+
7
+ <br><br>
8
+
9
+ <a href="https://www.npmjs.com/package/fca-nx">
10
+ <img src="https://img.shields.io/npm/v/fca-nx?style=for-the-badge&logo=npm&logoColor=white">
11
+ </a>
12
+ <a href="https://www.npmjs.com/package/fca-nx">
13
+ <img src="https://img.shields.io/npm/dm/fca-nx?style=for-the-badge&logo=npm&logoColor=white">
14
+ </a>
15
+ <a href="https://github.com/xalmandevv/fca-nx">
16
+ <img src="https://img.shields.io/github/stars/xalmandevv/fca-nx?style=for-the-badge&logo=github">
17
+ </a>
18
+ <a href="https://github.com/xalmandevv/fca-nx/blob/main/LICENSE">
19
+ <img src="https://img.shields.io/github/license/xalmandevv/fca-nx?style=for-the-badge">
20
+ </a>
21
+ <a href="https://nodejs.org/">
22
+ <img src="https://img.shields.io/badge/Node.js-18%2B-339933?style=for-the-badge&logo=node.js&logoColor=white">
23
+ </a>
24
+
25
+ <br><br>
26
+
27
+ **⚡ Lightning Fast · 🔒 Secure · 🌐 90+ Methods · 🛡️ Auto-Healing**
28
+
29
+ <br>
30
+
31
+ FCA-NX is a modern Facebook Messenger API client for Node.js,
32
+ built for bots, automation systems, integrations, and advanced Messenger applications.
33
+
34
+ </div>
35
+
36
+ ---
37
+
38
+ <div align="center">✨ Why FCA-NX?</div>
39
+
40
+ <table>
41
+ <tr>
42
+ <td align="center" width="25%">⚡<br><br><b>FAST</b><br><br>Optimized communication and event handling</td>
43
+ <td align="center" width="25%">🛡️<br><br><b>STABLE</b><br><br>Session protection and automatic reconnection</td>
44
+ <td align="center" width="25%">🌐<br><br><b>POWERFUL</b><br><br>90+ API methods and utilities.</td>
45
+ <td align="center" width="25%">🔧<br><br><b>FLEXIBLE</b><br><br>Designed for bots and custom applications</td>
46
+ </tr>
47
+ </table>
48
+
49
+ ---
50
+
51
+ # ✨ Features
52
+
53
+ | Feature | Description |
54
+ |:---:|---|
55
+ | ⚡ **Lightning Fast** | Optimized MQTT communication engine |
56
+ | 🔒 **Security First** | Session protection with automatic backups |
57
+ | 🛡️ **Auto-Healing** | Automatic recovery from connection problems |
58
+ | 🔄 **Auto Reconnect** | Automatically reconnect after disconnects |
59
+ | 🌐 **90+ Methods** | Messages, users, threads, reactions and more |
60
+ | 📡 **Real-Time Events** | Powerful MQTT event listener |
61
+ | 💾 **Auto Save** | Automatic appState protection |
62
+ | 📢 **Broadcasting** | Controlled multi-thread broadcasting |
63
+ | 👥 **Thread Tools** | Complete group management utilities |
64
+ | 👤 **User Tools** | User information and relationship APIs |
65
+
66
+ # 📦 Installation
67
+
68
+ ```bash
69
+ npm install fca-nx
70
+
71
+ ```
72
+ ### Requirements
73
+ * Node.js >= 18.0.0
74
+ Check your Node.js version:
75
+ ```bash
76
+ node -v
77
+
78
+ ```
79
+ # 🚀 Quick Start
80
+ ```javascript
81
+ const { login } = require("fca-nx");
82
+ const appState = require("./account.json");
83
+
84
+ login(
85
+ { appState },
86
+ { listenEvents: true },
87
+ (err, api) => {
88
+ if (err) {
89
+ console.error(err);
90
+ return;
91
+ }
92
+
93
+ console.log("╭─────────────────────────────╮");
94
+ console.log("│ 🚀 FCA-NX CONNECTED │");
95
+ console.log("╰─────────────────────────────╯");
96
+
97
+ api.autoSaveSession("./account.json", {
98
+ interval: 3 * 60 * 1000,
99
+ backup: true
100
+ });
101
+
102
+ api.listenMqtt((err, event) => {
103
+ if (err) {
104
+ console.error("Listen error:", err);
105
+ return;
106
+ }
107
+
108
+ if (event.type === "message") {
109
+ api.sendMessage(
110
+ "🤖 I received: " + event.body,
111
+ event.threadID
112
+ );
113
+ }
114
+ });
115
+ }
116
+ );
117
+
118
+ ```
119
+ # 🔐 Session Protection
120
+ ```javascript
121
+ api.autoSaveSession("./account.json");
122
+
123
+ api.autoSaveSession("./account.json", {
124
+ interval: 5 * 60 * 1000,
125
+ debounce: 30 * 1000,
126
+ backup: true,
127
+ maxBackups: 5
128
+ });
129
+
130
+ api.saveSession();
131
+ api.restoreFromBackup();
132
+ api.stopAutoSave();
133
+
134
+ ```
135
+ # 💬 Messaging
136
+ ### Send Message
137
+ ```javascript
138
+ api.sendMessage("Hello world!", threadID);
139
+
140
+ ```
141
+ ### Send Attachment
142
+ ```javascript
143
+ const fs = require("fs");
144
+
145
+ api.sendMessage(
146
+ {
147
+ body: "Check this out!",
148
+ attachment: fs.createReadStream("./photo.jpg")
149
+ },
150
+ threadID
151
+ );
152
+
153
+ ```
154
+ ### Mentions
155
+ ```javascript
156
+ api.sendMessage(
157
+ {
158
+ body: "Hey @John, how are you?",
159
+ mentions: [
160
+ {
161
+ id: "123456789",
162
+ tag: "@John",
163
+ fromIndex: 4
164
+ }
165
+ ]
166
+ },
167
+ threadID
168
+ );
169
+
170
+ ```
171
+ ### Sticker
172
+ ```javascript
173
+ api.sendMessage(
174
+ {
175
+ sticker: "369239263222822"
176
+ },
177
+ threadID
178
+ );
179
+
180
+ ```
181
+ ### Location
182
+ ```javascript
183
+ api.sendMessage(
184
+ {
185
+ location: {
186
+ latitude: 23.8103,
187
+ longitude: 90.4125,
188
+ current: true
189
+ }
190
+ },
191
+ threadID
192
+ );
193
+
194
+ ```
195
+ # 📡 Mass Broadcasting
196
+ ```javascript
197
+ const result = await api.sendBroadcast(
198
+ "📢 Important announcement!",
199
+ [
200
+ "thread_id_1",
201
+ "thread_id_2",
202
+ "thread_id_3"
203
+ ],
204
+ {
205
+ parallel: 3,
206
+ delay: 2000,
207
+ onProgress: (sent, total) => {
208
+ console.log(`📊 Progress: ${sent}/${total}`);
209
+ }
210
+ }
211
+ );
212
+
213
+ console.log(`✅ Sent: ${result.success}`);
214
+ console.log(`❌ Failed: ${result.failed}`);
215
+
216
+ ```
217
+ # 👥 Thread Management
218
+ ```javascript
219
+ const info = await api.getThreadInfo(threadID);
220
+ const threads = await api.getThreadList(20);
221
+ const history = await api.getThreadHistory(threadID, 50);
222
+
223
+ const groupID = await api.createGroup("New Group", ["user1", "user2"]);
224
+
225
+ await api.addUserToGroup(userID, threadID);
226
+ await api.removeUserFromGroup(userID, threadID);
227
+
228
+ await api.setTitle("New Group Name", threadID);
229
+ await api.changeThreadColor("#0084FF", threadID);
230
+ await api.changeThreadEmoji("🔥", threadID);
231
+ await api.changeNickname("Captain", threadID, userID);
232
+ await api.changeGroupImage(fs.createReadStream("./group.png"), threadID);
233
+
234
+ await api.changeAdminStatus(threadID, userID, true);
235
+
236
+ await api.createPoll(
237
+ "What's your favorite color?",
238
+ threadID,
239
+ {
240
+ Red: false,
241
+ Blue: false,
242
+ Green: false
243
+ }
244
+ );
245
+
246
+ ```
247
+ # 👤 User Operations
248
+ ```javascript
249
+ const user = await api.getUserInfo(userID);
250
+ const userV2 = await api.getUserInfoV2(userID);
251
+ const users = await api.getUserID("John Doe");
252
+ const uid = await api.getUID("[https://facebook.com/username](https://facebook.com/username)");
253
+ const friends = await api.getFriendsList();
254
+ const avatar = await api.getAvatarUser(userID);
255
+
256
+ // Relationship Management
257
+ await api.sendFriendRequest(userID);
258
+ await api.handleFriendRequest(userID, true);
259
+ await api.changeBlockedStatus(userID, true);
260
+ await api.unfriend(userID);
261
+
262
+ ```
263
+ # 🖼️ Profile Management
264
+ ```javascript
265
+ await api.changeAvatar(fs.createReadStream("./avatar.jpg"));
266
+ await api.changeCover(fs.createReadStream("./cover.jpg"));
267
+ await api.changeBio("Powered by FCA-NX");
268
+
269
+ ```
270
+ # 😍 Reactions & Interactions
271
+ ```javascript
272
+ await api.setMessageReaction("❤️", messageID, threadID);
273
+ await api.setMessageReaction("", messageID); // Remove reaction
274
+ await api.reactToPost(postID, "😂");
275
+
276
+ await api.sendMessage("Nice message!", threadID, null, messageID); // Reply
277
+
278
+ ```
279
+ # 🔧 Message Actions
280
+ ```javascript
281
+ await api.editMessage("Updated text", messageID);
282
+ await api.unsendMessage(messageID);
283
+ await api.deleteMessage([messageID1, messageID2]);
284
+ await api.forwardAttachment(attachmentID, [userID]);
285
+
286
+ const attachments = await api.uploadAttachment([
287
+ fs.createReadStream("./file.pdf")
288
+ ]);
289
+
290
+ await api.markAsRead(threadID);
291
+ await api.markAsReadAll();
292
+ await api.sendTypingIndicator(threadID, true);
293
+
294
+ ```
295
+ # 🌐 HTTP Utilities
296
+ ```javascript
297
+ // GET
298
+ api.httpGet("[https://api.example.com](https://api.example.com)", { param: "value" }, (err, data) => {
299
+ console.log(data);
300
+ });
301
+
302
+ // POST
303
+ api.httpPost("[https://api.example.com](https://api.example.com)", { key: "value" }, (err, data) => {
304
+ console.log(data);
305
+ });
306
+
307
+ // Form Data
308
+ api.httpPostFormData("[https://api.example.com](https://api.example.com)", { file: fs.createReadStream("./file.jpg") }, (err, data) => {
309
+ console.log(data);
310
+ });
311
+
312
+ ```
313
+ # ⚙️ Configuration
314
+ | Option | Type | Default | Description |
315
+ |---|---|---|---|
316
+ | selfListen | boolean | false | Receive own messages |
317
+ | listenEvents | boolean | true | Receive thread events |
318
+ | listenTyping | boolean | false | Receive typing events |
319
+ | updatePresence | boolean | false | Receive online status |
320
+ | autoMarkDelivery | boolean | false | Auto mark delivered |
321
+ | autoMarkRead | boolean | false | Auto mark read |
322
+ | autoReconnect | boolean | true | Auto reconnect |
323
+ | online | boolean | false | Appear online |
324
+ | proxy | string | null | HTTP proxy |
325
+ | userAgent | string | null | Custom User-Agent |
326
+ | emitReady | boolean | false | Emit ready event |
327
+ # 🔑 Login Methods
328
+ ### AppState
329
+ ```javascript
330
+ const { login } = require("fca-nx");
331
+ const appState = require("./account.json");
332
+
333
+ login({ appState }, options, callback);
334
+
335
+ ```
336
+ ### Email & Password
337
+ ```javascript
338
+ login(
339
+ {
340
+ email: "your_email@example.com",
341
+ password: "your_password"
342
+ },
343
+ options,
344
+ callback
345
+ );
346
+
347
+ ```
348
+ > Email/password authentication may require additional verification.
349
+ >
350
+ # 🧩 API Architecture
351
+ ```text
352
+ api
353
+ │
354
+ ├── messages
355
+ │ ├── send
356
+ │ ├── edit
357
+ │ ├── delete
358
+ │ ├── unsend
359
+ │ ├── react
360
+ │ └── uploadAttachment
361
+ │
362
+ ├── threads
363
+ │ ├── createGroup
364
+ │ ├── getInfo
365
+ │ ├── getList
366
+ │ ├── addUsers
367
+ │ ├── removeUser
368
+ │ ├── setTitle
369
+ │ └── setNickname
370
+ │
371
+ ├── users
372
+ │ ├── getID
373
+ │ ├── getInfo
374
+ │ ├── getInfoV2
375
+ │ └── getFriends
376
+ │
377
+ ├── account
378
+ │ ├── changeAvatar
379
+ │ ├── changeCover
380
+ │ ├── changeBio
381
+ │ ├── handleFriendRequest
382
+ │ ├── changeBlockedStatus
383
+ │ └── logout
384
+ │
385
+ └── realtime
386
+ ├── listen
387
+ ├── stop
388
+ └── middleware
389
+
390
+ ```
391
+ # 🏗️ Architecture
392
+ ```text
393
+ ┌─────────────────────┐
394
+ │ Your Bot / App │
395
+ └──────────┬──────────┘
396
+ │
397
+ ▼
398
+ ┌─────────────────────┐
399
+ │ FCA-NX │
400
+ ├─────────────────────┤
401
+ │ API Layer │
402
+ │ MQTT Engine │
403
+ │ Session Manager │
404
+ │ Auto Healing │
405
+ └──────────┬──────────┘
406
+ │
407
+ ▼
408
+ ┌─────────────────────┐
409
+ │ Facebook Services │
410
+ │ │
411
+ └─────────────────────┘
412
+
413
+ ```
414
+ # 🛡️ Best Practices
415
+ 1. Always use AppState
416
+ 2. Enable automatic session backups
417
+ 3. Use listenMqtt for real-time events
418
+ 4. Handle connection errors properly
419
+ 5. Use controlled broadcasting
420
+ 6. Keep session files private
421
+ 7. Never publish account credentials
422
+ 8. Keep FCA-NX updated
423
+ # 🤝 Contributing
424
+ ```bash
425
+ git clone [https://github.com/xalmandevv/fca-nx.git](https://github.com/xalmandevv/fca-nx.git)
426
+ cd fca-nx
427
+ git checkout -b feature/amazing
428
+ git add .
429
+ git commit -m "Add amazing feature"
430
+ git push origin feature/amazing
431
+
432
+ ```
433
+ Then open a Pull Request.
434
+ # 📄 License
435
+ MIT License — Free to use, modify, and distribute.
436
+ <div align="center">
437
+ <img src="https://readme-typing-svg.demolab.com?font=JetBrains+Mono&weight=600&size=18&duration=3000&pause=1000&color=38BDF8&center=true&vCenter=true&width=600&lines=Built+with+⚡+for+Node.js+Developers;Powered+by+FCA-NX;Made+for+Bots+🤖+%26+Automation+🚀" />
438
+ <a href="https://github.com/xalmandevv/fca-nx">
439
+ <img src="https://img.shields.io/badge/GitHub-xalmandevv-181717?style=for-the-badge&logo=github">
440
+ </a>
441
+ <a href="https://www.npmjs.com/package/fca-nx">
442
+ <img src="https://img.shields.io/badge/NPM-fca--nx-CB3837?style=for-the-badge&logo=npm">
443
+ </a>
444
+ ⭐ Star the repository if FCA-NX helps your project! ⭐
445
+ <img src="https://capsule-render.vercel.app/api?type=waving&color=0:06b6d4,50:2563eb,100:0f172a&height=120&section=footer" width="100%"/>
446
+ </div>
File without changes
package/e2ee/crypto.js ADDED
@@ -0,0 +1,173 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * FCA-NX E2EE Crypto — All primitives using Node.js built-in crypto only.
5
+ * Implements: X25519 DH, HKDF-SHA256, AES-256-GCM, HMAC-SHA256
6
+ * Node.js >= 15 required (crypto.hkdfSync, crypto.generateKeyPairSync x25519).
7
+ */
8
+
9
+ const crypto = require("crypto");
10
+
11
+ // ─────────────────────────────────────────────────────────
12
+ // X25519 Key Management
13
+ // ─────────────────────────────────────────────────────────
14
+
15
+ function generateKeyPair() {
16
+ const { privateKey, publicKey } = crypto.generateKeyPairSync("x25519", {
17
+ privateKeyEncoding: { type: "pkcs8", format: "der" },
18
+ publicKeyEncoding: { type: "spki", format: "der" }
19
+ });
20
+ return {
21
+ privateKey,
22
+ publicKey,
23
+ publicKeyRaw: exportRawPublicKey(publicKey)
24
+ };
25
+ }
26
+
27
+ function exportRawPublicKey(spkiDer) {
28
+ // X25519 SPKI DER: 12 bytes header + 32 bytes key
29
+ return Buffer.from(spkiDer).slice(-32);
30
+ }
31
+
32
+ function importPublicKey(raw32bytes) {
33
+ if (raw32bytes.length !== 32) throw new Error("X25519 public key must be 32 bytes");
34
+ // Build minimal SPKI wrapper for X25519
35
+ const header = Buffer.from("302a300506032b656e032100", "hex");
36
+ return Buffer.concat([header, raw32bytes]);
37
+ }
38
+
39
+ function dh(privateKeyPkcs8Der, peerPublicRaw32) {
40
+ const privKey = crypto.createPrivateKey({ key: Buffer.from(privateKeyPkcs8Der), format: "der", type: "pkcs8" });
41
+ const pubKeyDer = importPublicKey(Buffer.from(peerPublicRaw32));
42
+ const pubKey = crypto.createPublicKey({ key: pubKeyDer, format: "der", type: "spki" });
43
+ return crypto.diffieHellman({ privateKey: privKey, publicKey: pubKey });
44
+ }
45
+
46
+ // ─────────────────────────────────────────────────────────
47
+ // HKDF-SHA256
48
+ // ─────────────────────────────────────────────────────────
49
+
50
+ function hkdf(ikm, length, salt, info) {
51
+ if (!salt) salt = Buffer.alloc(32, 0);
52
+ if (!info) info = Buffer.alloc(0);
53
+ if (typeof info === "string") info = Buffer.from(info, "utf8");
54
+ return Buffer.from(crypto.hkdfSync("sha256", ikm, salt, info, length));
55
+ }
56
+
57
+ function hkdfExtract(salt, ikm) {
58
+ return crypto.createHmac("sha256", salt).update(ikm).digest();
59
+ }
60
+
61
+ function hkdfExpand(prk, info, length) {
62
+ const results = [];
63
+ let t = Buffer.alloc(0);
64
+ let i = 0;
65
+ while (results.reduce((s, b) => s + b.length, 0) < length) {
66
+ i++;
67
+ const hmac = crypto.createHmac("sha256", prk);
68
+ hmac.update(t);
69
+ if (info) hmac.update(info);
70
+ hmac.update(Buffer.from([i]));
71
+ t = hmac.digest();
72
+ results.push(t);
73
+ }
74
+ return Buffer.concat(results).slice(0, length);
75
+ }
76
+
77
+ // ─────────────────────────────────────────────────────────
78
+ // AES-256-GCM
79
+ // ─────────────────────────────────────────────────────────
80
+
81
+ function encrypt(key32, plaintext, aad) {
82
+ if (key32.length !== 32) throw new Error("AES-GCM key must be 32 bytes");
83
+ const iv = crypto.randomBytes(12);
84
+ const cipher = crypto.createCipheriv("aes-256-gcm", key32, iv);
85
+ if (aad) cipher.setAAD(aad);
86
+ const encrypted = Buffer.concat([cipher.update(plaintext), cipher.final()]);
87
+ const authTag = cipher.getAuthTag();
88
+ return Buffer.concat([iv, authTag, encrypted]);
89
+ }
90
+
91
+ function decrypt(key32, ciphertext, aad) {
92
+ if (key32.length !== 32) throw new Error("AES-GCM key must be 32 bytes");
93
+ if (ciphertext.length < 28) throw new Error("Ciphertext too short");
94
+ const iv = ciphertext.slice(0, 12);
95
+ const authTag = ciphertext.slice(12, 28);
96
+ const data = ciphertext.slice(28);
97
+ const decipher = crypto.createDecipheriv("aes-256-gcm", key32, iv);
98
+ decipher.setAuthTag(authTag);
99
+ if (aad) decipher.setAAD(aad);
100
+ return Buffer.concat([decipher.update(data), decipher.final()]);
101
+ }
102
+
103
+ // ─────────────────────────────────────────────────────────
104
+ // HMAC-SHA256
105
+ // ─────────────────────────────────────────────────────────
106
+
107
+ function hmacSha256(key, data) {
108
+ return crypto.createHmac("sha256", key).update(data).digest();
109
+ }
110
+
111
+ function constantTimeEqual(a, b) {
112
+ if (a.length !== b.length) return false;
113
+ return crypto.timingSafeEqual(a, b);
114
+ }
115
+
116
+ // ─────────────────────────────────────────────────────────
117
+ // X3DH Key Agreement (Extended Triple Diffie-Hellman)
118
+ // ─────────────────────────────────────────────────────────
119
+
120
+ /**
121
+ * Sender side of X3DH.
122
+ * @param {object} senderIdKey - { privateKey, publicKey, publicKeyRaw } of sender identity key
123
+ * @param {object} ephemeralKey - { privateKey, publicKey, publicKeyRaw } of ephemeral key
124
+ * @param {Buffer} recipientIdPub - recipient's identity public key (raw 32 bytes)
125
+ * @param {Buffer} recipientSpkPub - recipient's signed pre-key (raw 32 bytes)
126
+ * @param {Buffer} [recipientOpkPub] - recipient's one-time pre-key (raw 32 bytes), optional
127
+ * @returns {Buffer} 32-byte shared master secret
128
+ */
129
+ function x3dhSend(senderIdKey, ephemeralKey, recipientIdPub, recipientSpkPub, recipientOpkPub) {
130
+ const dh1 = dh(senderIdKey.privateKey, recipientSpkPub);
131
+ const dh2 = dh(ephemeralKey.privateKey, recipientIdPub);
132
+ const dh3 = dh(ephemeralKey.privateKey, recipientSpkPub);
133
+ const parts = recipientOpkPub
134
+ ? [dh1, dh2, dh3, dh(ephemeralKey.privateKey, recipientOpkPub)]
135
+ : [dh1, dh2, dh3];
136
+ const ikm = Buffer.concat(parts);
137
+ const F = Buffer.alloc(32, 0xFF);
138
+ const salt = Buffer.alloc(32, 0);
139
+ return hkdf(Buffer.concat([F, ikm]), 32, salt, Buffer.from("WhisperText", "utf8"));
140
+ }
141
+
142
+ /**
143
+ * Receiver side of X3DH.
144
+ */
145
+ function x3dhReceive(recipientIdKey, recipientSpkKey, recipientOpkKey, senderIdPub, senderEphemeralPub) {
146
+ const dh1 = dh(recipientSpkKey.privateKey, senderIdPub);
147
+ const dh2 = dh(recipientIdKey.privateKey, senderEphemeralPub);
148
+ const dh3 = dh(recipientSpkKey.privateKey, senderEphemeralPub);
149
+ const parts = recipientOpkKey
150
+ ? [dh1, dh2, dh3, dh(recipientOpkKey.privateKey, senderEphemeralPub)]
151
+ : [dh1, dh2, dh3];
152
+ const ikm = Buffer.concat(parts);
153
+ const F = Buffer.alloc(32, 0xFF);
154
+ const salt = Buffer.alloc(32, 0);
155
+ return hkdf(Buffer.concat([F, ikm]), 32, salt, Buffer.from("WhisperText", "utf8"));
156
+ }
157
+
158
+ module.exports = {
159
+ generateKeyPair,
160
+ exportRawPublicKey,
161
+ importPublicKey,
162
+ dh,
163
+ hkdf,
164
+ hkdfExtract,
165
+ hkdfExpand,
166
+ encrypt,
167
+ decrypt,
168
+ hmacSha256,
169
+ constantTimeEqual,
170
+ x3dhSend,
171
+ x3dhReceive,
172
+ randomBytes: crypto.randomBytes.bind(crypto)
173
+ };