@x4r1s3/baileys 0.0.0-stage → 1.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 (185) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1245 -2
  3. package/SECURITY.md +47 -0
  4. package/WAProto/V +1 -0
  5. package/WAProto/WAProto.proto +8892 -0
  6. package/WAProto/index.d.ts +104128 -0
  7. package/WAProto/index.js +334920 -0
  8. package/assets/rolling-circle.svg +133 -0
  9. package/assets/x4r1s3-banner.svg +32 -0
  10. package/engine-requirements.js +27 -0
  11. package/lib/Builders/A2UI.js +245 -0
  12. package/lib/Builders/AIRich.js +179 -0
  13. package/lib/Builders/Button.js +108 -0
  14. package/lib/Builders/CFC.js +284 -0
  15. package/lib/Builders/Carousel.js +81 -0
  16. package/lib/Call/THIRD_PARTY_LICENSE.txt +21 -0
  17. package/lib/Call/astralena-v3.mjs +96 -0
  18. package/lib/Call/audio-feeder.mjs +201 -0
  19. package/lib/Call/audio-recorder.mjs +250 -0
  20. package/lib/Call/fetch-wasm-resources.mjs +104 -0
  21. package/lib/Call/index.mjs +707 -0
  22. package/lib/Call/relay-transport.mjs +563 -0
  23. package/lib/Call/signaling.mjs +660 -0
  24. package/lib/Call/types.mjs +17 -0
  25. package/lib/Call/video-feeder.mjs +94 -0
  26. package/lib/Call/voip-resources.mjs +259 -0
  27. package/lib/Call/wasm-engine.mjs +1372 -0
  28. package/lib/Call/worker-bootstrap.mjs +1042 -0
  29. package/lib/Defaults/ban-checker.js +56 -0
  30. package/lib/Defaults/index.js +170 -0
  31. package/lib/Signal/Group/ciphertext-message.js +23 -0
  32. package/lib/Signal/Group/group-session-builder.js +41 -0
  33. package/lib/Signal/Group/group_cipher.js +93 -0
  34. package/lib/Signal/Group/index.js +23 -0
  35. package/lib/Signal/Group/keyhelper.js +29 -0
  36. package/lib/Signal/Group/sender-chain-key.js +37 -0
  37. package/lib/Signal/Group/sender-key-distribution-message.js +74 -0
  38. package/lib/Signal/Group/sender-key-message.js +77 -0
  39. package/lib/Signal/Group/sender-key-name.js +59 -0
  40. package/lib/Signal/Group/sender-key-record.js +52 -0
  41. package/lib/Signal/Group/sender-key-state.js +95 -0
  42. package/lib/Signal/Group/sender-message-key.js +37 -0
  43. package/lib/Signal/libsignal.js +440 -0
  44. package/lib/Signal/lid-mapping.js +292 -0
  45. package/lib/Socket/Client/index.js +14 -0
  46. package/lib/Socket/Client/types.js +22 -0
  47. package/lib/Socket/Client/websocket.js +65 -0
  48. package/lib/Socket/aigroups.js +327 -0
  49. package/lib/Socket/ban-checker.js +165 -0
  50. package/lib/Socket/business.js +419 -0
  51. package/lib/Socket/chats.js +1921 -0
  52. package/lib/Socket/communities.js +443 -0
  53. package/lib/Socket/graphql.js +911 -0
  54. package/lib/Socket/groups.js +561 -0
  55. package/lib/Socket/index.js +49 -0
  56. package/lib/Socket/interactive-handler.js +612 -0
  57. package/lib/Socket/interop.js +575 -0
  58. package/lib/Socket/managed-account.js +220 -0
  59. package/lib/Socket/messages-recv.js +2193 -0
  60. package/lib/Socket/messages-send.js +4141 -0
  61. package/lib/Socket/mex.js +53 -0
  62. package/lib/Socket/newsletter.js +291 -0
  63. package/lib/Socket/privacy.js +458 -0
  64. package/lib/Socket/registration.js +440 -0
  65. package/lib/Socket/socket.js +1042 -0
  66. package/lib/Socket/status-actions.js +287 -0
  67. package/lib/Socket/username.js +241 -0
  68. package/lib/Store/index.js +16 -0
  69. package/lib/Store/make-cache-manager-store.js +101 -0
  70. package/lib/Store/make-in-memory-store.js +432 -0
  71. package/lib/Store/make-ordered-dictionary.js +90 -0
  72. package/lib/Store/object-repository.js +35 -0
  73. package/lib/Types/Auth.js +13 -0
  74. package/lib/Types/Bussines.js +13 -0
  75. package/lib/Types/Call.js +13 -0
  76. package/lib/Types/Chat.js +19 -0
  77. package/lib/Types/Contact.js +13 -0
  78. package/lib/Types/Events.js +13 -0
  79. package/lib/Types/GroupMetadata.js +13 -0
  80. package/lib/Types/Label.js +36 -0
  81. package/lib/Types/LabelAssociation.js +18 -0
  82. package/lib/Types/Message.js +30 -0
  83. package/lib/Types/Mex.js +53 -0
  84. package/lib/Types/Product.js +13 -0
  85. package/lib/Types/RichType.js +34 -0
  86. package/lib/Types/Signal.js +13 -0
  87. package/lib/Types/Socket.js +14 -0
  88. package/lib/Types/State.js +60 -0
  89. package/lib/Types/USync.js +13 -0
  90. package/lib/Types/index.js +37 -0
  91. package/lib/Utils/auth-utils.js +313 -0
  92. package/lib/Utils/ban-checker.js +48 -0
  93. package/lib/Utils/bot-capabilities.js +96 -0
  94. package/lib/Utils/bot-planning-replay.js +177 -0
  95. package/lib/Utils/browser-utils.js +40 -0
  96. package/lib/Utils/business.js +242 -0
  97. package/lib/Utils/c2582.js +147 -0
  98. package/lib/Utils/chat-utils.js +905 -0
  99. package/lib/Utils/companion-reg-client-utils.js +104 -0
  100. package/lib/Utils/consumer-application.js +114 -0
  101. package/lib/Utils/crypto.js +129 -0
  102. package/lib/Utils/decode-wa-message.js +496 -0
  103. package/lib/Utils/direct-chat-theme.js +164 -0
  104. package/lib/Utils/event-buffer.js +601 -0
  105. package/lib/Utils/experimental-proto.js +206 -0
  106. package/lib/Utils/games/miniapp.js +17 -0
  107. package/lib/Utils/games/slot-machine.js +270 -0
  108. package/lib/Utils/games/website-preview.js +306 -0
  109. package/lib/Utils/generics.js +402 -0
  110. package/lib/Utils/group-history.js +68 -0
  111. package/lib/Utils/group-wallpaper.js +168 -0
  112. package/lib/Utils/history.js +162 -0
  113. package/lib/Utils/identity-change-handler.js +60 -0
  114. package/lib/Utils/index.js +61 -0
  115. package/lib/Utils/jid-display-normalization.js +221 -0
  116. package/lib/Utils/link-preview.js +96 -0
  117. package/lib/Utils/logger.js +14 -0
  118. package/lib/Utils/lt-hash.js +19 -0
  119. package/lib/Utils/make-mutex.js +44 -0
  120. package/lib/Utils/message-composer.js +709 -0
  121. package/lib/Utils/message-inspect.js +79 -0
  122. package/lib/Utils/message-retry-manager.js +253 -0
  123. package/lib/Utils/message-security.js +167 -0
  124. package/lib/Utils/messages-media.js +1027 -0
  125. package/lib/Utils/messages.js +2467 -0
  126. package/lib/Utils/meta-ai-msmsg.js +215 -0
  127. package/lib/Utils/meta-compositing.js +239 -0
  128. package/lib/Utils/native-flow.js +158 -0
  129. package/lib/Utils/newsletter-live-update-utils.js +74 -0
  130. package/lib/Utils/newsletter-status-utils.js +152 -0
  131. package/lib/Utils/noise-handler.js +212 -0
  132. package/lib/Utils/offline-node-processor.js +51 -0
  133. package/lib/Utils/poll-manager.js +206 -0
  134. package/lib/Utils/portable-compat.js +12 -0
  135. package/lib/Utils/pre-key-manager.js +117 -0
  136. package/lib/Utils/process-message.js +610 -0
  137. package/lib/Utils/reporting-utils.js +269 -0
  138. package/lib/Utils/rich-message-utils.js +2841 -0
  139. package/lib/Utils/scheduled-message.js +107 -0
  140. package/lib/Utils/signal.js +212 -0
  141. package/lib/Utils/source-grep.js +57 -0
  142. package/lib/Utils/stanza-ack.js +49 -0
  143. package/lib/Utils/sticker-annotation.js +87 -0
  144. package/lib/Utils/sync-action-utils.js +59 -0
  145. package/lib/Utils/tc-token-utils.js +174 -0
  146. package/lib/Utils/use-multi-file-auth-state.js +132 -0
  147. package/lib/Utils/use-single-file-auth-state.js +108 -0
  148. package/lib/Utils/use-sqlite-auth-state.js +120 -0
  149. package/lib/Utils/validate-connection.js +221 -0
  150. package/lib/Utils/view-once-utils.js +218 -0
  151. package/lib/Utils/voip-rekey.js +32 -0
  152. package/lib/Utils/website-preview.js +27 -0
  153. package/lib/Utils/welcome-flow.js +228 -0
  154. package/lib/Utils/x4r1s3.js +144 -0
  155. package/lib/WABinary/constants.js +1475 -0
  156. package/lib/WABinary/decode.js +273 -0
  157. package/lib/WABinary/encode.js +231 -0
  158. package/lib/WABinary/generic-utils.js +242 -0
  159. package/lib/WABinary/index.js +17 -0
  160. package/lib/WABinary/jid-utils.js +107 -0
  161. package/lib/WABinary/types.js +13 -0
  162. package/lib/WAM/BinaryInfo.js +21 -0
  163. package/lib/WAM/constants.js +22864 -0
  164. package/lib/WAM/encode.js +161 -0
  165. package/lib/WAM/index.js +15 -0
  166. package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +108 -0
  167. package/lib/WAUSync/Protocols/USyncContactProtocol.js +68 -0
  168. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +65 -0
  169. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +38 -0
  170. package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +82 -0
  171. package/lib/WAUSync/Protocols/USyncPictureProtocol.js +40 -0
  172. package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +37 -0
  173. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +49 -0
  174. package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +46 -0
  175. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +36 -0
  176. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +62 -0
  177. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +40 -0
  178. package/lib/WAUSync/Protocols/index.js +24 -0
  179. package/lib/WAUSync/USyncQuery.js +213 -0
  180. package/lib/WAUSync/USyncUser.js +66 -0
  181. package/lib/WAUSync/index.js +15 -0
  182. package/lib/antiban.cjs +4726 -0
  183. package/lib/index.d.ts +1895 -0
  184. package/lib/index.js +41 -0
  185. package/package.json +125 -4
@@ -0,0 +1,36 @@
1
+ /**
2
+ * @X4R1S3
3
+ *
4
+ * File: lib/Types/Label.js
5
+ * About: Label module for the X4R1S3 WhatsApp protocol client.
6
+ * Important exports: LabelColor
7
+ * Directions: Import the listed exports and preserve protocol, validation, and compatibility invariants when modifying.
8
+ *
9
+ * Copyright and attribution notice.
10
+ * Do not copy, reproduce, redistribute, modify, or create derivative works
11
+ * from this source without explicit written permission.
12
+ */
13
+ /** WhatsApp has 20 predefined colors */
14
+ export var LabelColor;
15
+ (function (LabelColor) {
16
+ LabelColor[LabelColor["Color1"] = 0] = "Color1";
17
+ LabelColor[LabelColor["Color2"] = 1] = "Color2";
18
+ LabelColor[LabelColor["Color3"] = 2] = "Color3";
19
+ LabelColor[LabelColor["Color4"] = 3] = "Color4";
20
+ LabelColor[LabelColor["Color5"] = 4] = "Color5";
21
+ LabelColor[LabelColor["Color6"] = 5] = "Color6";
22
+ LabelColor[LabelColor["Color7"] = 6] = "Color7";
23
+ LabelColor[LabelColor["Color8"] = 7] = "Color8";
24
+ LabelColor[LabelColor["Color9"] = 8] = "Color9";
25
+ LabelColor[LabelColor["Color10"] = 9] = "Color10";
26
+ LabelColor[LabelColor["Color11"] = 10] = "Color11";
27
+ LabelColor[LabelColor["Color12"] = 11] = "Color12";
28
+ LabelColor[LabelColor["Color13"] = 12] = "Color13";
29
+ LabelColor[LabelColor["Color14"] = 13] = "Color14";
30
+ LabelColor[LabelColor["Color15"] = 14] = "Color15";
31
+ LabelColor[LabelColor["Color16"] = 15] = "Color16";
32
+ LabelColor[LabelColor["Color17"] = 16] = "Color17";
33
+ LabelColor[LabelColor["Color18"] = 17] = "Color18";
34
+ LabelColor[LabelColor["Color19"] = 18] = "Color19";
35
+ LabelColor[LabelColor["Color20"] = 19] = "Color20";
36
+ })(LabelColor || (LabelColor = {}));
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @X4R1S3
3
+ *
4
+ * File: lib/Types/LabelAssociation.js
5
+ * About: LabelAssociation module for the X4R1S3 WhatsApp protocol client.
6
+ * Important exports: LabelAssociationType
7
+ * Directions: Import the listed exports and preserve protocol, validation, and compatibility invariants when modifying.
8
+ *
9
+ * Copyright and attribution notice.
10
+ * Do not copy, reproduce, redistribute, modify, or create derivative works
11
+ * from this source without explicit written permission.
12
+ */
13
+ /** Association type */
14
+ export var LabelAssociationType;
15
+ (function (LabelAssociationType) {
16
+ LabelAssociationType["Chat"] = "label_jid";
17
+ LabelAssociationType["Message"] = "label_message";
18
+ })(LabelAssociationType || (LabelAssociationType = {}));
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @X4R1S3
3
+ *
4
+ * File: lib/Types/Message.js
5
+ * About: Message module for the X4R1S3 WhatsApp protocol client.
6
+ * Important exports: AssociationType, ButtonHeaderType, ButtonType, CarouselCardType, ListType, ProtocolType, EventInviteStatus, WAMessageStubType; …
7
+ * Directions: Import the listed exports and preserve protocol, validation, and compatibility invariants when modifying.
8
+ *
9
+ * Copyright and attribution notice.
10
+ * Do not copy, reproduce, redistribute, modify, or create derivative works
11
+ * from this source without explicit written permission.
12
+ */
13
+ import { proto } from '../../WAProto/index.js';
14
+ // export the WAMessage Prototypes
15
+ export { proto as WAProto };
16
+ // Lia@Changes 03-02-26 --- Add exported message-related enum types from proto.Message
17
+ export const AssociationType = proto.MessageAssociation.AssociationType;
18
+ export const ButtonHeaderType = proto.Message.ButtonsMessage.HeaderType;
19
+ export const ButtonType = proto.Message.ButtonsMessage.Button.Type;
20
+ export const CarouselCardType = proto.Message.InteractiveMessage.CarouselMessage.CarouselCardType;
21
+ export const ListType = proto.Message.ListMessage.ListType;
22
+ export const ProtocolType = proto.Message.ProtocolMessage.Type;
23
+ export const EventInviteStatus = proto.Message.EventInviteMessage.EventStatus;
24
+ export const WAMessageStubType = proto.WebMessageInfo.StubType;
25
+ export const WAMessageStatus = proto.WebMessageInfo.Status;
26
+ export var WAMessageAddressingMode;
27
+ (function (WAMessageAddressingMode) {
28
+ WAMessageAddressingMode["PN"] = "pn";
29
+ WAMessageAddressingMode["LID"] = "lid";
30
+ })(WAMessageAddressingMode || (WAMessageAddressingMode = {}));
@@ -0,0 +1,53 @@
1
+ /**
2
+ * @X4R1S3
3
+ *
4
+ * File: lib/Types/Mex.js
5
+ * About: Mex module for the X4R1S3 WhatsApp protocol client.
6
+ * Important exports: XWAPaths, QueryIds
7
+ * Directions: Import the listed exports and preserve protocol, validation, and compatibility invariants when modifying.
8
+ *
9
+ * Copyright and attribution notice.
10
+ * Do not copy, reproduce, redistribute, modify, or create derivative works
11
+ * from this source without explicit written permission.
12
+ */
13
+ export var XWAPaths;
14
+ (function (XWAPaths) {
15
+ XWAPaths["xwa2_newsletter_create"] = "xwa2_newsletter_create";
16
+ XWAPaths["xwa2_newsletter_subscribers"] = "xwa2_newsletter_subscribers";
17
+ XWAPaths["xwa2_newsletter_subscribed"] = "xwa2_newsletter_subscribed";
18
+ XWAPaths["xwa2_newsletter_view"] = "xwa2_newsletter_view";
19
+ XWAPaths["xwa2_newsletter_metadata"] = "xwa2_newsletter";
20
+ XWAPaths["xwa2_newsletter_admin_count"] = "xwa2_newsletter_admin";
21
+ XWAPaths["xwa2_newsletter_admin_capabilities"] = "xwa2_newsletter_admin";
22
+ XWAPaths["xwa2_newsletter_mute_v2"] = "xwa2_newsletter_mute_v2";
23
+ XWAPaths["xwa2_newsletter_unmute_v2"] = "xwa2_newsletter_unmute_v2";
24
+ XWAPaths["xwa2_newsletter_follow"] = "xwa2_newsletter_follow";
25
+ XWAPaths["xwa2_newsletter_unfollow"] = "xwa2_newsletter_unfollow";
26
+ XWAPaths["xwa2_newsletter_join_v2"] = "xwa2_newsletter_join_v2";
27
+ XWAPaths["xwa2_newsletter_leave_v2"] = "xwa2_newsletter_leave_v2";
28
+ XWAPaths["xwa2_newsletter_change_owner"] = "xwa2_newsletter_change_owner";
29
+ XWAPaths["xwa2_newsletter_demote"] = "xwa2_newsletter_demote";
30
+ XWAPaths["xwa2_newsletter_delete_v2"] = "xwa2_newsletter_delete_v2";
31
+ XWAPaths["xwa2_fetch_account_reachout_timelock"] = "xwa2_fetch_account_reachout_timelock";
32
+ XWAPaths["xwa2_message_capping_info"] = "xwa2_message_capping_info";
33
+ })(XWAPaths || (XWAPaths = {}));
34
+ export var QueryIds;
35
+ (function (QueryIds) {
36
+ QueryIds["CREATE"] = "8823471724422422";
37
+ QueryIds["UPDATE_METADATA"] = "24250201037901610";
38
+ QueryIds["METADATA"] = "6563316087068696";
39
+ QueryIds["SUBSCRIBERS"] = "9783111038412085";
40
+ QueryIds["SUBSCRIBED"] = "6388546374527196";
41
+ QueryIds["FOLLOW"] = "24404358912487870";
42
+ QueryIds["UNFOLLOW"] = "9767147403369991";
43
+ QueryIds["MUTE"] = "29766401636284406";
44
+ QueryIds["UNMUTE"] = "9864994326891137";
45
+ QueryIds["ADMIN_COUNT"] = "7130823597031706";
46
+ QueryIds["ADMIN_CAPABILITIES"] = "9801384413216421";
47
+ QueryIds["CHANGE_OWNER"] = "7341777602580933";
48
+ QueryIds["DEMOTE"] = "6551828931592903";
49
+ QueryIds["JOB_MUTATION"] = "7150902998257522";
50
+ QueryIds["DELETE"] = "30062808666639665";
51
+ QueryIds["REACHOUT_TIMELOCK"] = "23983697327930364";
52
+ QueryIds["MESSAGE_CAPPING_INFO"] = "24503548349331633";
53
+ })(QueryIds || (QueryIds = {}));
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @X4R1S3
3
+ *
4
+ * File: lib/Types/Product.js
5
+ * About: Product module for the X4R1S3 WhatsApp protocol client.
6
+ * Important exports: No public exports detected; module side effects or declarations are local.
7
+ * Directions: Import the listed exports and preserve protocol, validation, and compatibility invariants when modifying.
8
+ *
9
+ * Copyright and attribution notice.
10
+ * Do not copy, reproduce, redistribute, modify, or create derivative works
11
+ * from this source without explicit written permission.
12
+ */
13
+ export {};
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @X4R1S3
3
+ *
4
+ * File: lib/Types/RichType.js
5
+ * About: RichType module for the X4R1S3 WhatsApp protocol client.
6
+ * Important exports: CodeHighlightType, RichSubMessageType
7
+ * Directions: Import the listed exports and preserve protocol, validation, and compatibility invariants when modifying.
8
+ *
9
+ * Copyright and attribution notice.
10
+ * Do not copy, reproduce, redistribute, modify, or create derivative works
11
+ * from this source without explicit written permission.
12
+ */
13
+ export var CodeHighlightType;
14
+ (function (CodeHighlightType) {
15
+ CodeHighlightType[CodeHighlightType["DEFAULT"] = 0] = "DEFAULT";
16
+ CodeHighlightType[CodeHighlightType["KEYWORD"] = 1] = "KEYWORD";
17
+ CodeHighlightType[CodeHighlightType["METHOD"] = 2] = "METHOD";
18
+ CodeHighlightType[CodeHighlightType["STRING"] = 3] = "STRING";
19
+ CodeHighlightType[CodeHighlightType["NUMBER"] = 4] = "NUMBER";
20
+ CodeHighlightType[CodeHighlightType["COMMENT"] = 5] = "COMMENT";
21
+ })(CodeHighlightType || (CodeHighlightType = {}));
22
+ export var RichSubMessageType;
23
+ (function (RichSubMessageType) {
24
+ RichSubMessageType[RichSubMessageType["UNKNOWN"] = 0] = "UNKNOWN";
25
+ RichSubMessageType[RichSubMessageType["GRID_IMAGE"] = 1] = "GRID_IMAGE";
26
+ RichSubMessageType[RichSubMessageType["TEXT"] = 2] = "TEXT";
27
+ RichSubMessageType[RichSubMessageType["INLINE_IMAGE"] = 3] = "INLINE_IMAGE";
28
+ RichSubMessageType[RichSubMessageType["TABLE"] = 4] = "TABLE";
29
+ RichSubMessageType[RichSubMessageType["CODE"] = 5] = "CODE";
30
+ RichSubMessageType[RichSubMessageType["DYNAMIC"] = 6] = "DYNAMIC";
31
+ RichSubMessageType[RichSubMessageType["MAP"] = 7] = "MAP";
32
+ RichSubMessageType[RichSubMessageType["LATEX"] = 8] = "LATEX";
33
+ RichSubMessageType[RichSubMessageType["CONTENT_ITEMS"] = 9] = "CONTENT_ITEMS";
34
+ })(RichSubMessageType || (RichSubMessageType = {}));
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @X4R1S3
3
+ *
4
+ * File: lib/Types/Signal.js
5
+ * About: Signal module for the X4R1S3 WhatsApp protocol client.
6
+ * Important exports: No public exports detected; module side effects or declarations are local.
7
+ * Directions: Import the listed exports and preserve protocol, validation, and compatibility invariants when modifying.
8
+ *
9
+ * Copyright and attribution notice.
10
+ * Do not copy, reproduce, redistribute, modify, or create derivative works
11
+ * from this source without explicit written permission.
12
+ */
13
+ import { proto } from '../../WAProto/index.js';
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @X4R1S3
3
+ *
4
+ * File: lib/Types/Socket.js
5
+ * About: Socket module for the X4R1S3 WhatsApp protocol client.
6
+ * Important exports: No public exports detected; module side effects or declarations are local.
7
+ * Directions: Import the listed exports and preserve protocol, validation, and compatibility invariants when modifying.
8
+ *
9
+ * Copyright and attribution notice.
10
+ * Do not copy, reproduce, redistribute, modify, or create derivative works
11
+ * from this source without explicit written permission.
12
+ */
13
+ import { proto } from '../../WAProto/index.js';
14
+ import {} from './Message.js';
@@ -0,0 +1,60 @@
1
+ /**
2
+ * @X4R1S3
3
+ *
4
+ * File: lib/Types/State.js
5
+ * About: State module for the X4R1S3 WhatsApp protocol client.
6
+ * Important exports: SyncState, ReachoutTimelockEnforcementType, NewChatMessageCappingStatusType, NewChatMessageCappingMVStatusType
7
+ * Directions: Import the listed exports and preserve protocol, validation, and compatibility invariants when modifying.
8
+ *
9
+ * Copyright and attribution notice.
10
+ * Do not copy, reproduce, redistribute, modify, or create derivative works
11
+ * from this source without explicit written permission.
12
+ */
13
+ import { Boom } from '@hapi/boom';
14
+ export var SyncState;
15
+ (function (SyncState) {
16
+ /** The socket is connecting, but we haven't received pending notifications yet. */
17
+ SyncState[SyncState["Connecting"] = 0] = "Connecting";
18
+ /** Pending notifications received. Buffering events until we decide whether to sync or not. */
19
+ SyncState[SyncState["AwaitingInitialSync"] = 1] = "AwaitingInitialSync";
20
+ /** The initial app state sync (history, etc.) is in progress. Buffering continues. */
21
+ SyncState[SyncState["Syncing"] = 2] = "Syncing";
22
+ /** Initial sync is complete, or was skipped. The socket is fully operational and events are processed in real-time. */
23
+ SyncState[SyncState["Online"] = 3] = "Online";
24
+ })(SyncState || (SyncState = {}));
25
+ export var ReachoutTimelockEnforcementType;
26
+ (function (ReachoutTimelockEnforcementType) {
27
+ ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_ALCOHOL"] = "BIZ_COMMERCE_VIOLATION_ALCOHOL";
28
+ ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_ADULT"] = "BIZ_COMMERCE_VIOLATION_ADULT";
29
+ ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_ANIMALS"] = "BIZ_COMMERCE_VIOLATION_ANIMALS";
30
+ ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_BODY_PARTS_FLUIDS"] = "BIZ_COMMERCE_VIOLATION_BODY_PARTS_FLUIDS";
31
+ ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_DATING"] = "BIZ_COMMERCE_VIOLATION_DATING";
32
+ ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_DIGITAL_SERVICES_PRODUCTS"] = "BIZ_COMMERCE_VIOLATION_DIGITAL_SERVICES_PRODUCTS";
33
+ ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_DRUGS"] = "BIZ_COMMERCE_VIOLATION_DRUGS";
34
+ ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_DRUGS_ONLY_OTC"] = "BIZ_COMMERCE_VIOLATION_DRUGS_ONLY_OTC";
35
+ ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_GAMBLING"] = "BIZ_COMMERCE_VIOLATION_GAMBLING";
36
+ ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_HEALTHCARE"] = "BIZ_COMMERCE_VIOLATION_HEALTHCARE";
37
+ ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_REAL_FAKE_CURRENCY"] = "BIZ_COMMERCE_VIOLATION_REAL_FAKE_CURRENCY";
38
+ ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_SUPPLEMENTS"] = "BIZ_COMMERCE_VIOLATION_SUPPLEMENTS";
39
+ ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_TOBACCO"] = "BIZ_COMMERCE_VIOLATION_TOBACCO";
40
+ ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_VIOLENT_CONTENT"] = "BIZ_COMMERCE_VIOLATION_VIOLENT_CONTENT";
41
+ ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_WEAPONS"] = "BIZ_COMMERCE_VIOLATION_WEAPONS";
42
+ ReachoutTimelockEnforcementType["BIZ_QUALITY"] = "BIZ_QUALITY";
43
+ /** This means there is no restriction */
44
+ ReachoutTimelockEnforcementType["DEFAULT"] = "DEFAULT";
45
+ ReachoutTimelockEnforcementType["WEB_COMPANION_ONLY"] = "WEB_COMPANION_ONLY";
46
+ })(ReachoutTimelockEnforcementType || (ReachoutTimelockEnforcementType = {}));
47
+ export var NewChatMessageCappingStatusType;
48
+ (function (NewChatMessageCappingStatusType) {
49
+ NewChatMessageCappingStatusType["NONE"] = "NONE";
50
+ NewChatMessageCappingStatusType["FIRST_WARNING"] = "FIRST_WARNING";
51
+ NewChatMessageCappingStatusType["SECOND_WARNING"] = "SECOND_WARNING";
52
+ NewChatMessageCappingStatusType["CAPPED"] = "CAPPED";
53
+ })(NewChatMessageCappingStatusType || (NewChatMessageCappingStatusType = {}));
54
+ export var NewChatMessageCappingMVStatusType;
55
+ (function (NewChatMessageCappingMVStatusType) {
56
+ NewChatMessageCappingMVStatusType["NOT_ELIGIBLE"] = "NOT_ELIGIBLE";
57
+ NewChatMessageCappingMVStatusType["NOT_ACTIVE"] = "NOT_ACTIVE";
58
+ NewChatMessageCappingMVStatusType["ACTIVE"] = "ACTIVE";
59
+ NewChatMessageCappingMVStatusType["ACTIVE_UPGRADE_AVAILABLE"] = "ACTIVE_UPGRADE_AVAILABLE";
60
+ })(NewChatMessageCappingMVStatusType || (NewChatMessageCappingMVStatusType = {}));
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @X4R1S3
3
+ *
4
+ * File: lib/Types/USync.js
5
+ * About: USync module for the X4R1S3 WhatsApp protocol client.
6
+ * Important exports: No public exports detected; module side effects or declarations are local.
7
+ * Directions: Import the listed exports and preserve protocol, validation, and compatibility invariants when modifying.
8
+ *
9
+ * Copyright and attribution notice.
10
+ * Do not copy, reproduce, redistribute, modify, or create derivative works
11
+ * from this source without explicit written permission.
12
+ */
13
+ import { USyncUser } from '../WAUSync/index.js';
@@ -0,0 +1,37 @@
1
+ /**
2
+ * @X4R1S3
3
+ *
4
+ * File: lib/Types/index.js
5
+ * About: Types module for the X4R1S3 WhatsApp protocol client.
6
+ * Important exports: DisconnectReason
7
+ * Directions: Import the listed exports and preserve protocol, validation, and compatibility invariants when modifying.
8
+ *
9
+ * Copyright and attribution notice.
10
+ * Do not copy, reproduce, redistribute, modify, or create derivative works
11
+ * from this source without explicit written permission.
12
+ */
13
+ export * from './Auth.js';
14
+ export * from './GroupMetadata.js';
15
+ export * from './Chat.js';
16
+ export * from './Contact.js';
17
+ export * from './State.js';
18
+ export * from './Mex.js';
19
+ export * from './Message.js';
20
+ export * from './Socket.js';
21
+ export * from './Events.js';
22
+ export * from './Product.js';
23
+ export * from './Call.js';
24
+ export * from './Signal.js';
25
+ export var DisconnectReason;
26
+ (function (DisconnectReason) {
27
+ DisconnectReason[DisconnectReason["connectionClosed"] = 428] = "connectionClosed";
28
+ DisconnectReason[DisconnectReason["connectionLost"] = 408] = "connectionLost";
29
+ DisconnectReason[DisconnectReason["connectionReplaced"] = 440] = "connectionReplaced";
30
+ DisconnectReason[DisconnectReason["timedOut"] = 408] = "timedOut";
31
+ DisconnectReason[DisconnectReason["loggedOut"] = 401] = "loggedOut";
32
+ DisconnectReason[DisconnectReason["badSession"] = 500] = "badSession";
33
+ DisconnectReason[DisconnectReason["restartRequired"] = 515] = "restartRequired";
34
+ DisconnectReason[DisconnectReason["multideviceMismatch"] = 411] = "multideviceMismatch";
35
+ DisconnectReason[DisconnectReason["forbidden"] = 403] = "forbidden";
36
+ DisconnectReason[DisconnectReason["unavailableService"] = 503] = "unavailableService";
37
+ })(DisconnectReason || (DisconnectReason = {}));
@@ -0,0 +1,313 @@
1
+ /**
2
+ * @X4R1S3
3
+ *
4
+ * File: lib/Utils/auth-utils.js
5
+ * About: Auth utils module for the X4R1S3 WhatsApp protocol client.
6
+ * Important exports: makeCacheableSignalKeyStore, addTransactionCapability, assertMeId, initAuthCreds
7
+ * Directions: Import the listed exports and preserve protocol, validation, and compatibility invariants when modifying.
8
+ *
9
+ * Copyright and attribution notice.
10
+ * Do not copy, reproduce, redistribute, modify, or create derivative works
11
+ * from this source without explicit written permission.
12
+ */
13
+ import NodeCache from '@cacheable/node-cache';
14
+ import { Boom } from '@hapi/boom';
15
+ import { AsyncLocalStorage } from 'async_hooks';
16
+ import { Mutex } from 'async-mutex';
17
+ import { randomBytes } from 'crypto';
18
+ import PQueue from 'p-queue';
19
+ import { DEFAULT_CACHE_TTLS } from '../Defaults/index.js';
20
+ import { Curve, signedKeyPair } from './crypto.js';
21
+ import { delay, generateRegistrationId } from './generics.js';
22
+ import { PreKeyManager } from './pre-key-manager.js';
23
+ /**
24
+ * Adds caching capability to a SignalKeyStore
25
+ * @param store the store to add caching to
26
+ * @param logger to log trace events
27
+ * @param _cache cache store to use
28
+ */
29
+ export function makeCacheableSignalKeyStore(store, logger, _cache) {
30
+ const cache = _cache ||
31
+ new NodeCache({
32
+ stdTTL: DEFAULT_CACHE_TTLS.SIGNAL_STORE, // 5 minutes
33
+ useClones: false,
34
+ deleteOnExpire: true
35
+ });
36
+ // Mutex for protecting cache operations
37
+ const cacheMutex = new Mutex();
38
+ function getUniqueId(type, id) {
39
+ return `${type}.${id}`;
40
+ }
41
+ return {
42
+ async get(type, ids) {
43
+ return cacheMutex.runExclusive(async () => {
44
+ const data = {};
45
+ const idsToFetch = [];
46
+ for (const id of ids) {
47
+ const item = (await cache.get(getUniqueId(type, id)));
48
+ if (typeof item !== 'undefined') {
49
+ data[id] = item;
50
+ }
51
+ else {
52
+ idsToFetch.push(id);
53
+ }
54
+ }
55
+ if (idsToFetch.length) {
56
+ logger?.trace({ items: idsToFetch.length }, 'loading from store');
57
+ const fetched = await store.get(type, idsToFetch);
58
+ for (const id of idsToFetch) {
59
+ const item = fetched[id];
60
+ if (item) {
61
+ data[id] = item;
62
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
63
+ await cache.set(getUniqueId(type, id), item);
64
+ }
65
+ }
66
+ }
67
+ return data;
68
+ });
69
+ },
70
+ async set(data) {
71
+ return cacheMutex.runExclusive(async () => {
72
+ let keys = 0;
73
+ for (const type in data) {
74
+ for (const id in data[type]) {
75
+ await cache.set(getUniqueId(type, id), data[type][id]);
76
+ keys += 1;
77
+ }
78
+ }
79
+ logger?.trace({ keys }, 'updated cache');
80
+ await store.set(data);
81
+ });
82
+ },
83
+ async clear() {
84
+ await cache.flushAll();
85
+ await store.clear?.();
86
+ }
87
+ };
88
+ }
89
+ /**
90
+ * Adds DB-like transaction capability to the SignalKeyStore
91
+ * Uses AsyncLocalStorage for automatic context management
92
+ * @param state the key store to apply this capability to
93
+ * @param logger logger to log events
94
+ * @returns SignalKeyStore with transaction capability
95
+ */
96
+ export const addTransactionCapability = (state, logger, { maxCommitRetries, delayBetweenTriesMs }) => {
97
+ const txStorage = new AsyncLocalStorage();
98
+ // Queues for concurrency control (keyed by signal data type - bounded set)
99
+ const keyQueues = new Map();
100
+ // Transaction mutexes with reference counting for cleanup
101
+ const txMutexes = new Map();
102
+ const txMutexRefCounts = new Map();
103
+ // Pre-key manager for specialized operations
104
+ const preKeyManager = new PreKeyManager(state, logger);
105
+ /**
106
+ * Get or create a queue for a specific key type
107
+ */
108
+ function getQueue(key) {
109
+ if (!keyQueues.has(key)) {
110
+ keyQueues.set(key, new PQueue({ concurrency: 1 }));
111
+ }
112
+ return keyQueues.get(key);
113
+ }
114
+ /**
115
+ * Get or create a transaction mutex
116
+ */
117
+ function getTxMutex(key) {
118
+ if (!txMutexes.has(key)) {
119
+ txMutexes.set(key, new Mutex());
120
+ txMutexRefCounts.set(key, 0);
121
+ }
122
+ return txMutexes.get(key);
123
+ }
124
+ /**
125
+ * Acquire a reference to a transaction mutex
126
+ */
127
+ function acquireTxMutexRef(key) {
128
+ const count = txMutexRefCounts.get(key) ?? 0;
129
+ txMutexRefCounts.set(key, count + 1);
130
+ }
131
+ /**
132
+ * Release a reference to a transaction mutex and cleanup if no longer needed
133
+ */
134
+ function releaseTxMutexRef(key) {
135
+ const count = (txMutexRefCounts.get(key) ?? 1) - 1;
136
+ txMutexRefCounts.set(key, count);
137
+ // Cleanup if no more references and mutex is not locked
138
+ if (count <= 0) {
139
+ const mutex = txMutexes.get(key);
140
+ if (mutex && !mutex.isLocked()) {
141
+ txMutexes.delete(key);
142
+ txMutexRefCounts.delete(key);
143
+ }
144
+ }
145
+ }
146
+ /**
147
+ * Check if currently in a transaction
148
+ */
149
+ function isInTransaction() {
150
+ return !!txStorage.getStore();
151
+ }
152
+ /**
153
+ * Commit transaction with retries
154
+ */
155
+ async function commitWithRetry(mutations) {
156
+ if (Object.keys(mutations).length === 0) {
157
+ logger.trace('no mutations in transaction');
158
+ return;
159
+ }
160
+ logger.trace('committing transaction');
161
+ for (let attempt = 0; attempt < maxCommitRetries; attempt++) {
162
+ try {
163
+ await state.set(mutations);
164
+ logger.trace({ mutationCount: Object.keys(mutations).length }, 'committed transaction');
165
+ return;
166
+ }
167
+ catch (error) {
168
+ const retriesLeft = maxCommitRetries - attempt - 1;
169
+ logger.warn(`failed to commit mutations, retries left=${retriesLeft}`);
170
+ if (retriesLeft === 0) {
171
+ throw error;
172
+ }
173
+ await delay(delayBetweenTriesMs);
174
+ }
175
+ }
176
+ }
177
+ return {
178
+ get: async (type, ids) => {
179
+ const ctx = txStorage.getStore();
180
+ if (!ctx) {
181
+ // No transaction - direct read without exclusive lock for concurrency
182
+ return state.get(type, ids);
183
+ }
184
+ // In transaction - check cache first
185
+ const cached = ctx.cache[type] || {};
186
+ const missing = ids.filter(id => !(id in cached));
187
+ if (missing.length > 0) {
188
+ ctx.dbQueries++;
189
+ logger.trace({ type, count: missing.length }, 'fetching missing keys in transaction');
190
+ const fetched = await getTxMutex(type).runExclusive(() => state.get(type, missing));
191
+ // Update cache
192
+ ctx.cache[type] = ctx.cache[type] || {};
193
+ Object.assign(ctx.cache[type], fetched);
194
+ }
195
+ // Return requested ids from cache
196
+ const result = {};
197
+ for (const id of ids) {
198
+ const value = ctx.cache[type]?.[id];
199
+ if (value !== undefined && value !== null) {
200
+ result[id] = value;
201
+ }
202
+ }
203
+ return result;
204
+ },
205
+ set: async (data) => {
206
+ const ctx = txStorage.getStore();
207
+ if (!ctx) {
208
+ // No transaction - direct write with queue protection
209
+ const types = Object.keys(data);
210
+ // Process pre-keys with validation
211
+ for (const type_ of types) {
212
+ const type = type_;
213
+ if (type === 'pre-key') {
214
+ await preKeyManager.validateDeletions(data, type);
215
+ }
216
+ }
217
+ // Write all data in parallel
218
+ await Promise.all(types.map(type => getQueue(type).add(async () => {
219
+ const typeData = { [type]: data[type] };
220
+ await state.set(typeData);
221
+ })));
222
+ return;
223
+ }
224
+ // In transaction - update cache and mutations
225
+ logger.trace({ types: Object.keys(data) }, 'caching in transaction');
226
+ for (const key_ in data) {
227
+ const key = key_;
228
+ // Ensure structures exist
229
+ ctx.cache[key] = ctx.cache[key] || {};
230
+ ctx.mutations[key] = ctx.mutations[key] || {};
231
+ // Special handling for pre-keys
232
+ if (key === 'pre-key') {
233
+ await preKeyManager.processOperations(data, key, ctx.cache, ctx.mutations, true);
234
+ }
235
+ else {
236
+ // Normal key types
237
+ Object.assign(ctx.cache[key], data[key]);
238
+ Object.assign(ctx.mutations[key], data[key]);
239
+ }
240
+ }
241
+ },
242
+ isInTransaction,
243
+ transaction: async (work, key) => {
244
+ const existing = txStorage.getStore();
245
+ // Nested transaction - reuse existing context
246
+ if (existing) {
247
+ logger.trace('reusing existing transaction context');
248
+ return work();
249
+ }
250
+ // New transaction - acquire mutex and create context
251
+ const mutex = getTxMutex(key);
252
+ acquireTxMutexRef(key);
253
+ try {
254
+ return await mutex.runExclusive(async () => {
255
+ const ctx = {
256
+ cache: {},
257
+ mutations: {},
258
+ dbQueries: 0
259
+ };
260
+ logger.trace('entering transaction');
261
+ try {
262
+ const result = await txStorage.run(ctx, work);
263
+ // Commit mutations
264
+ await commitWithRetry(ctx.mutations);
265
+ logger.trace({ dbQueries: ctx.dbQueries }, 'transaction completed');
266
+ return result;
267
+ }
268
+ catch (error) {
269
+ logger.error({ error }, 'transaction failed, rolling back');
270
+ throw error;
271
+ }
272
+ });
273
+ }
274
+ finally {
275
+ releaseTxMutexRef(key);
276
+ }
277
+ }
278
+ };
279
+ };
280
+ /**
281
+ * Returns the authenticated user's JID, or throws a Boom-401 if creds are not yet authenticated.
282
+ * Use this anywhere we'd otherwise reach for `creds.me!.id` to fail fast with a descriptive error.
283
+ */
284
+ export const assertMeId = (creds) => {
285
+ const id = creds.me?.id;
286
+ if (!id) {
287
+ throw new Boom('Cannot proceed: socket is not authenticated yet (creds.me.id is missing)', { statusCode: 401 });
288
+ }
289
+ return id;
290
+ };
291
+ export const initAuthCreds = () => {
292
+ const identityKey = Curve.generateKeyPair();
293
+ return {
294
+ noiseKey: Curve.generateKeyPair(),
295
+ pairingEphemeralKeyPair: Curve.generateKeyPair(),
296
+ signedIdentityKey: identityKey,
297
+ signedPreKey: signedKeyPair(identityKey, 1),
298
+ registrationId: generateRegistrationId(),
299
+ advSecretKey: randomBytes(32).toString('base64'),
300
+ processedHistoryMessages: [],
301
+ nextPreKeyId: 1,
302
+ firstUnuploadedPreKeyId: 1,
303
+ accountSyncCounter: 0,
304
+ accountSettings: {
305
+ unarchiveChats: false
306
+ },
307
+ registered: false,
308
+ pairingCode: undefined,
309
+ lastPropHash: undefined,
310
+ routingInfo: undefined,
311
+ additionalData: undefined
312
+ };
313
+ };