@zervonex/baileys 0.0.0-stage → 3.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 (125) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +3203 -2
  3. package/WAProto/WAProtoCompile.js +291 -0
  4. package/WAProto/fetcher.js +69 -0
  5. package/WAProto/index.js +88 -0
  6. package/WAProto/parser.js +313 -0
  7. package/engine-requirements.js +10 -0
  8. package/lib/Builders/AIRich.js +590 -0
  9. package/lib/Builders/base.js +130 -0
  10. package/lib/Builders/builders.js +448 -0
  11. package/lib/Builders/index.js +3 -0
  12. package/lib/Defaults/index.js +225 -0
  13. package/lib/Defaults/phonenumber-mcc.json +223 -0
  14. package/lib/Signal/index.js +2 -0
  15. package/lib/Signal/libsignal.js +523 -0
  16. package/lib/Signal/lid-mapping.js +283 -0
  17. package/lib/Socket/Client/index.js +2 -0
  18. package/lib/Socket/Client/types.js +10 -0
  19. package/lib/Socket/Client/websocket.js +84 -0
  20. package/lib/Socket/business.js +152 -0
  21. package/lib/Socket/chats.js +855 -0
  22. package/lib/Socket/communities.js +147 -0
  23. package/lib/Socket/groups.js +294 -0
  24. package/lib/Socket/index.js +15 -0
  25. package/lib/Socket/messages-recv.js +904 -0
  26. package/lib/Socket/messages-send.js +693 -0
  27. package/lib/Socket/mex.js +34 -0
  28. package/lib/Socket/newsletter.js +752 -0
  29. package/lib/Socket/nexus-handler.js +55 -0
  30. package/lib/Socket/registration.js +155 -0
  31. package/lib/Socket/socket.js +798 -0
  32. package/lib/Socket/spam-report.js +65 -0
  33. package/lib/Socket/username.js +82 -0
  34. package/lib/Store/index.js +6 -0
  35. package/lib/Store/make-cache-manager-store.js +81 -0
  36. package/lib/Store/make-in-memory-store.js +425 -0
  37. package/lib/Store/make-ordered-dictionary.js +82 -0
  38. package/lib/Store/object-repository.js +31 -0
  39. package/lib/Store/reporting-info-store.js +38 -0
  40. package/lib/Types/Auth.js +2 -0
  41. package/lib/Types/Bussines.js +2 -0
  42. package/lib/Types/Call.js +2 -0
  43. package/lib/Types/Chat.js +8 -0
  44. package/lib/Types/Contact.js +2 -0
  45. package/lib/Types/Events.js +2 -0
  46. package/lib/Types/GroupMetadata.js +2 -0
  47. package/lib/Types/Label.js +25 -0
  48. package/lib/Types/LabelAssociation.js +7 -0
  49. package/lib/Types/Message.js +15 -0
  50. package/lib/Types/Newsletter.js +100 -0
  51. package/lib/Types/Product.js +2 -0
  52. package/lib/Types/Signal.js +2 -0
  53. package/lib/Types/Socket.js +14 -0
  54. package/lib/Types/State.js +26 -0
  55. package/lib/Types/USync.js +2 -0
  56. package/lib/Types/index.js +30 -0
  57. package/lib/Utils/auth-utils.js +142 -0
  58. package/lib/Utils/baileys-event-stream.js +33 -0
  59. package/lib/Utils/bot-capabilities.js +40 -0
  60. package/lib/Utils/bot-planning-replay.js +44 -0
  61. package/lib/Utils/browser-utils.js +26 -0
  62. package/lib/Utils/business.js +75 -0
  63. package/lib/Utils/chat-utils.js +316 -0
  64. package/lib/Utils/companion-reg-client-utils.js +20 -0
  65. package/lib/Utils/consumer-application.js +38 -0
  66. package/lib/Utils/crypto.js +52 -0
  67. package/lib/Utils/decode-wa-message.js +197 -0
  68. package/lib/Utils/event-buffer.js +273 -0
  69. package/lib/Utils/extras.js +186 -0
  70. package/lib/Utils/generics.js +195 -0
  71. package/lib/Utils/history.js +51 -0
  72. package/lib/Utils/identity-change-handler.js +19 -0
  73. package/lib/Utils/index.js +39 -0
  74. package/lib/Utils/key-store.js +3 -0
  75. package/lib/Utils/link-preview.js +51 -0
  76. package/lib/Utils/logger.js +2 -0
  77. package/lib/Utils/lt-hash.js +3 -0
  78. package/lib/Utils/make-mutex.js +16 -0
  79. package/lib/Utils/message-composer.js +59 -0
  80. package/lib/Utils/message-retry-manager.js +48 -0
  81. package/lib/Utils/messages-media.js +520 -0
  82. package/lib/Utils/messages.js +742 -0
  83. package/lib/Utils/meta-ai-msmsg.js +122 -0
  84. package/lib/Utils/meta-compositing.js +75 -0
  85. package/lib/Utils/modern-messages.js +235 -0
  86. package/lib/Utils/native-flow.js +55 -0
  87. package/lib/Utils/noise-handler.js +161 -0
  88. package/lib/Utils/pre-key-manager.js +76 -0
  89. package/lib/Utils/process-message.js +399 -0
  90. package/lib/Utils/reporting-utils.js +171 -0
  91. package/lib/Utils/signal.js +167 -0
  92. package/lib/Utils/spam-report-utils.js +142 -0
  93. package/lib/Utils/sync-action-utils.js +33 -0
  94. package/lib/Utils/tc-token-utils.js +102 -0
  95. package/lib/Utils/use-multi-file-auth-state.js +307 -0
  96. package/lib/Utils/validate-connection.js +181 -0
  97. package/lib/WABinary/constants.js +1321 -0
  98. package/lib/WABinary/decode.js +152 -0
  99. package/lib/WABinary/encode.js +140 -0
  100. package/lib/WABinary/generic-utils.js +179 -0
  101. package/lib/WABinary/index.js +6 -0
  102. package/lib/WABinary/jid-utils.js +235 -0
  103. package/lib/WABinary/types.js +4 -0
  104. package/lib/WAM/BinaryInfo.js +10 -0
  105. package/lib/WAM/constants.js +22853 -0
  106. package/lib/WAM/encode.js +150 -0
  107. package/lib/WAM/index.js +3 -0
  108. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +30 -0
  109. package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +48 -0
  110. package/lib/WAUSync/Protocols/USyncContactProtocol.js +23 -0
  111. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +28 -0
  112. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +15 -0
  113. package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +24 -0
  114. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +9 -0
  115. package/lib/WAUSync/Protocols/USyncPictureProtocol.js +21 -0
  116. package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +19 -0
  117. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +19 -0
  118. package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +22 -0
  119. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +16 -0
  120. package/lib/WAUSync/Protocols/index.js +12 -0
  121. package/lib/WAUSync/USyncQuery.js +100 -0
  122. package/lib/WAUSync/USyncUser.js +20 -0
  123. package/lib/WAUSync/index.js +3 -0
  124. package/lib/index.js +68 -0
  125. package/package.json +216 -5
@@ -0,0 +1,82 @@
1
+ function makeOrderedDictionary(idGetter) {
2
+ const array = [];
3
+ const dict = {};
4
+
5
+ const get = (id) => dict[id];
6
+
7
+ const update = (item) => {
8
+ const id = idGetter(item);
9
+ const idx = array.findIndex((i) => idGetter(i) === id);
10
+ if (idx >= 0) {
11
+ array[idx] = item;
12
+ dict[id] = item;
13
+ }
14
+ return false;
15
+ };
16
+
17
+ const upsert = (item, mode) => {
18
+ const id = idGetter(item);
19
+ if (get(id)) {
20
+ update(item);
21
+ } else {
22
+ if (mode === 'append') {
23
+ array.push(item);
24
+ } else {
25
+ array.splice(0, 0, item);
26
+ }
27
+ dict[id] = item;
28
+ }
29
+ };
30
+
31
+ const remove = (item) => {
32
+ const id = idGetter(item);
33
+ const idx = array.findIndex((i) => idGetter(i) === id);
34
+ if (idx >= 0) {
35
+ array.splice(idx, 1);
36
+ delete dict[id];
37
+ return true;
38
+ }
39
+ return false;
40
+ };
41
+
42
+ return {
43
+ array,
44
+ get,
45
+ upsert,
46
+ update,
47
+ remove,
48
+ updateAssign: (id, update) => {
49
+ const item = get(id);
50
+ if (item) {
51
+ Object.assign(item, update);
52
+ delete dict[id];
53
+ dict[idGetter(item)] = item;
54
+ return true;
55
+ }
56
+ return false;
57
+ },
58
+ clear: () => {
59
+ array.splice(0, array.length);
60
+ for (const key of Object.keys(dict)) {
61
+ delete dict[key];
62
+ }
63
+ },
64
+ filter: (contain) => {
65
+ let i = 0;
66
+ while (i < array.length) {
67
+ if (!contain(array[i])) {
68
+ delete dict[idGetter(array[i])];
69
+ array.splice(i, 1);
70
+ } else {
71
+ i += 1;
72
+ }
73
+ }
74
+ },
75
+ toJSON: () => array,
76
+ fromJSON: (newItems) => {
77
+ array.splice(0, array.length, ...newItems);
78
+ },
79
+ };
80
+ }
81
+
82
+ export { makeOrderedDictionary };
@@ -0,0 +1,31 @@
1
+ class ObjectRepository {
2
+ constructor(entities = {}) {
3
+ this.entityMap = new Map(Object.entries(entities));
4
+ }
5
+
6
+ findById(id) {
7
+ return this.entityMap.get(id);
8
+ }
9
+
10
+ findAll() {
11
+ return Array.from(this.entityMap.values());
12
+ }
13
+
14
+ upsertById(id, entity) {
15
+ return this.entityMap.set(id, { ...entity });
16
+ }
17
+
18
+ deleteById(id) {
19
+ return this.entityMap.delete(id);
20
+ }
21
+
22
+ count() {
23
+ return this.entityMap.size;
24
+ }
25
+
26
+ toJSON() {
27
+ return this.findAll();
28
+ }
29
+ }
30
+
31
+ export { ObjectRepository };
@@ -0,0 +1,38 @@
1
+ const createReportingInfoStore = () => {
2
+ const byJid = new Map()
3
+
4
+ const normalizeKey = jid => (jid || '').toLowerCase()
5
+
6
+ return {
7
+ add(jid, entry) {
8
+ const key = normalizeKey(jid)
9
+ if (!key || !entry?.stanzaId || !entry?.reportingTag?.length) return
10
+ const list = byJid.get(key) || []
11
+ const idx = list.findIndex(e => e.stanzaId === entry.stanzaId)
12
+ if (idx >= 0) list[idx] = entry
13
+ else list.push(entry)
14
+ list.sort((a, b) => b.timestamp - a.timestamp)
15
+ byJid.set(key, list)
16
+ },
17
+
18
+ getForJid(jid, max = 5) {
19
+ return (byJid.get(normalizeKey(jid)) || []).slice(0, max)
20
+ },
21
+
22
+ clear(jid) {
23
+ byJid.delete(normalizeKey(jid))
24
+ },
25
+
26
+ listJids() {
27
+ return [...byJid.keys()]
28
+ },
29
+
30
+ size() {
31
+ let n = 0
32
+ for (const list of byJid.values()) n += list.length
33
+ return n
34
+ }
35
+ }
36
+ }
37
+
38
+ export { createReportingInfoStore }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=Auth.js.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=Bussines.js.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=Call.js.map
@@ -0,0 +1,8 @@
1
+ import { proto } from '../../WAProto/index.js'
2
+
3
+ // Derived from proto.CollectionName — sorted by enum value, lowercased, UNKNOWN (0) excluded.
4
+ // Automatically picks up new collection names when the proto updates.
5
+ export const ALL_WA_PATCH_NAMES = Object.entries(proto.CollectionName ?? {})
6
+ .filter(([k, v]) => typeof v === 'number' && v !== 0)
7
+ .sort((a, b) => a[1] - b[1])
8
+ .map(([k]) => k.toLowerCase())
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=Contact.js.map
@@ -0,0 +1,2 @@
1
+ import { proto } from '../../WAProto/index.js';
2
+ //# sourceMappingURL=Events.js.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=GroupMetadata.js.map
@@ -0,0 +1,25 @@
1
+ /** WhatsApp has 20 predefined colors */
2
+ export var LabelColor;
3
+ (function (LabelColor) {
4
+ LabelColor[LabelColor["Color1"] = 0] = "Color1";
5
+ LabelColor[LabelColor["Color2"] = 1] = "Color2";
6
+ LabelColor[LabelColor["Color3"] = 2] = "Color3";
7
+ LabelColor[LabelColor["Color4"] = 3] = "Color4";
8
+ LabelColor[LabelColor["Color5"] = 4] = "Color5";
9
+ LabelColor[LabelColor["Color6"] = 5] = "Color6";
10
+ LabelColor[LabelColor["Color7"] = 6] = "Color7";
11
+ LabelColor[LabelColor["Color8"] = 7] = "Color8";
12
+ LabelColor[LabelColor["Color9"] = 8] = "Color9";
13
+ LabelColor[LabelColor["Color10"] = 9] = "Color10";
14
+ LabelColor[LabelColor["Color11"] = 10] = "Color11";
15
+ LabelColor[LabelColor["Color12"] = 11] = "Color12";
16
+ LabelColor[LabelColor["Color13"] = 12] = "Color13";
17
+ LabelColor[LabelColor["Color14"] = 13] = "Color14";
18
+ LabelColor[LabelColor["Color15"] = 14] = "Color15";
19
+ LabelColor[LabelColor["Color16"] = 15] = "Color16";
20
+ LabelColor[LabelColor["Color17"] = 16] = "Color17";
21
+ LabelColor[LabelColor["Color18"] = 17] = "Color18";
22
+ LabelColor[LabelColor["Color19"] = 18] = "Color19";
23
+ LabelColor[LabelColor["Color20"] = 19] = "Color20";
24
+ })(LabelColor || (LabelColor = {}));
25
+ //# sourceMappingURL=Label.js.map
@@ -0,0 +1,7 @@
1
+ /** Association type */
2
+ export var LabelAssociationType;
3
+ (function (LabelAssociationType) {
4
+ LabelAssociationType["Chat"] = "label_jid";
5
+ LabelAssociationType["Message"] = "label_message";
6
+ })(LabelAssociationType || (LabelAssociationType = {}));
7
+ //# sourceMappingURL=LabelAssociation.js.map
@@ -0,0 +1,15 @@
1
+ import { proto } from '../../WAProto/index.js'
2
+
3
+ export { proto as WAProto }
4
+
5
+ // Proto is the authoritative source. These Proxies let callers use
6
+ // WAMessageStubType.GROUP_CREATE or WAMessageStatus.READ exactly as before.
7
+ export const WAMessageStubType = new Proxy({}, { get: (_, k) => proto.WebMessageInfo?.StubType?.[k] })
8
+ export const WAMessageStatus = new Proxy({}, { get: (_, k) => proto.WebMessageInfo?.Status?.[k] })
9
+
10
+ export const WAMessageAddressingMode = Object.freeze({ PN: 'pn', LID: 'lid' })
11
+
12
+ // Resolve a numeric stub type to its string name.
13
+ // Proto is the true source — only falls back to UNKNOWN_STUB_N for values not yet in the compiled proto.
14
+ export const resolveStubType = (stubType) =>
15
+ proto.WebMessageInfo?.StubType?.[stubType] ?? `UNKNOWN_STUB_${stubType}`
@@ -0,0 +1,100 @@
1
+ export var XWAPaths;
2
+ (function (XWAPaths) {
3
+ XWAPaths["xwa2_newsletter_create"] = "xwa2_newsletter_create";
4
+ XWAPaths["xwa2_newsletter_subscribed"] = "xwa2_newsletter_subscribed";
5
+ XWAPaths["xwa2_newsletter_metadata"] = "xwa2_newsletter";
6
+ XWAPaths["xwa2_newsletter_admin_count"] = "xwa2_newsletter_admin";
7
+ XWAPaths["xwa2_newsletter_admin_info"] = "xwa2_newsletter_admin";
8
+ XWAPaths["xwa2_newsletter_admin_capabilities"] = "xwa2_newsletter_admin";
9
+ XWAPaths["admin_profile"] = "xwa2_newsletter_admin";
10
+ XWAPaths["pending_admin_invites"] = "xwa2_newsletter_admin";
11
+ XWAPaths["xwa2_channel_enforcements"] = "xwa2_channel_enforcements";
12
+ XWAPaths["xwa2_channels_reports"] = "xwa2_channels_reports";
13
+ XWAPaths["xwa2_create_channel_report_appeal_v2"] = "xwa2_create_channel_report_appeal_v2";
14
+ XWAPaths["xwa2_newsletter_update_user_setting"] = "xwa2_newsletter_update_user_setting";
15
+ XWAPaths["xwa2_newsletter_join_v2"] = "xwa2_newsletter_join_v2";
16
+ XWAPaths["xwa2_newsletter_leave_v2"] = "xwa2_newsletter_leave_v2";
17
+ XWAPaths["xwa2_newsletter_change_owner"] = "xwa2_newsletter_change_owner";
18
+ XWAPaths["xwa2_newsletter_demote"] = "xwa2_newsletter_admin_demote";
19
+ XWAPaths["xwa2_newsletter_delete_v2"] = "xwa2_newsletter_delete_v2";
20
+ XWAPaths["xwa2_newsletter_followers"] = "xwa2_newsletter_followers";
21
+ XWAPaths["xwa2_newsletter_mute_v2"] = "xwa2_newsletter_mute_v2";
22
+ XWAPaths["xwa2_newsletter_unmute_v2"] = "xwa2_newsletter_unmute_v2";
23
+ XWAPaths["xwa2_newsletter_admin_insights"] = "xwa2_newsletter_admin_insights";
24
+ XWAPaths["xwa2_newsletter_pin_messages"] = "xwa2_newsletter_pin_messages";
25
+ XWAPaths["xwa2_newsletter_unpin_messages"] = "xwa2_newsletter_unpin_messages";
26
+ XWAPaths["xwa2_newsletter_label_ai_content"] = "xwa2_newsletter_label_ai_content";
27
+ XWAPaths["xwa2_newsletter_label_paid_partnership"] = "xwa2_newsletter_label_paid_partnership";
28
+ XWAPaths["xwa2_newsletter_admin_invite_create"] = "xwa2_newsletter_admin_invite_create";
29
+ XWAPaths["xwa2_newsletter_admin_invite_revoke"] = "xwa2_newsletter_admin_invite_revoke";
30
+ XWAPaths["xwa2_newsletter_admin_invite_accept"] = "xwa2_newsletter_admin_invite_accept";
31
+ XWAPaths["xwa2_newsletter_link_preview"] = "xwa2_newsletter_link_preview";
32
+ XWAPaths["xwa2_newsletter_question_response_state_update"] = "xwa2_newsletter_question_response_state_update";
33
+ XWAPaths["voter_list"] = "voter_list";
34
+ XWAPaths["xwa2_newsletters_reaction_sender_list"] = "xwa2_newsletters_reaction_sender_list";
35
+ XWAPaths["xwa2_newsletters_recommended"] = "xwa2_newsletters_recommended";
36
+ XWAPaths["xwa2_newsletters_similar"] = "xwa2_newsletters_similar";
37
+ XWAPaths["xwa2_newsletters_directory_list"] = "xwa2_newsletters_directory_list";
38
+ XWAPaths["xwa2_newsletters_directory_search"] = "xwa2_newsletters_directory_search";
39
+ XWAPaths["xwa2_newsletters_directory_category_preview"] = "xwa2_newsletters_directory_category_preview";
40
+ XWAPaths["xwa2_fetch_account_reachout_timelock"] = "xwa2_fetch_account_reachout_timelock";
41
+ XWAPaths["xwa2_message_capping_info"] = "xwa2_message_capping_info";
42
+ XWAPaths["xwa2_username_get"] = "xwa2_username_get";
43
+ XWAPaths["xwa2_username_set"] = "xwa2_username_set";
44
+ XWAPaths["xwa2_username_pin_set"] = "xwa2_username_pin_set";
45
+ XWAPaths["xwa2_username_check"] = "xwa2_username_check";
46
+ XWAPaths["xwa2_update_text_status"] = "xwa2_update_text_status";
47
+ XWAPaths["xwa2_text_status_list"] = "xwa2_text_status_list";
48
+ XWAPaths["xwa2_users_updates_since"] = "xwa2_users_updates_since";
49
+ })(XWAPaths || (XWAPaths = {}));
50
+
51
+ export var QueryIds;
52
+ (function (QueryIds) {
53
+ QueryIds["CREATE"] = "25149874324715067";
54
+ QueryIds["UPDATE_METADATA"] = "24250201037901610";
55
+ QueryIds["METADATA"] = "27456920720571478";
56
+ QueryIds["SUBSCRIBERS"] = "9783111038412085";
57
+ QueryIds["SUBSCRIBED"] = "25399611239711790";
58
+ QueryIds["FOLLOW"] = "24404358912487870";
59
+ QueryIds["UNFOLLOW"] = "9767147403369991";
60
+ QueryIds["ENFORCEMENTS"] = "27835373536068060";
61
+ QueryIds["CHANNEL_REPORTS"] = "35936238352686172";
62
+ QueryIds["CREATE_REPORT_APPEAL"] = "27103316329328467";
63
+ QueryIds["UPDATE_USER_SETTING"] = "31938993655691868";
64
+ QueryIds["ADMIN_COUNT"] = "26278439461859188";
65
+ QueryIds["ADMIN_INFO"] = "26278439461859188";
66
+ QueryIds["ADMIN_CAPABILITIES"] = "9801384413216421";
67
+ QueryIds["CHANGE_OWNER"] = "9546742745432473";
68
+ QueryIds["DEMOTE"] = "9880997548630971";
69
+ QueryIds["DELETE"] = "30062808666639665";
70
+ QueryIds["FOLLOWERS"] = "27472091235714801";
71
+ QueryIds["MUTE"] = "29766401636284406";
72
+ QueryIds["UNMUTE"] = "9864994326891137";
73
+ QueryIds["INSIGHTS"] = "9853618868050977";
74
+ QueryIds["PIN_MESSAGES"] = "27165709459706559";
75
+ QueryIds["UNPIN_MESSAGES"] = "28007176042216937";
76
+ QueryIds["LABEL_AI_CONTENT"] = "27909718265289596";
77
+ QueryIds["PAID_PARTNERSHIP_LABEL"] = "26102375079404865";
78
+ QueryIds["CREATE_ADMIN_INVITE"] = "9387141988078609";
79
+ QueryIds["REVOKE_ADMIN_INVITE"] = "9656078347839416";
80
+ QueryIds["ACCEPT_ADMIN_INVITE"] = "9580828702035549";
81
+ QueryIds["POLL_VOTERS"] = "9407762219322536";
82
+ QueryIds["REACTION_SENDER_LIST"] = "29575462448733991";
83
+ QueryIds["RECOMMENDED"] = "25806748772361516";
84
+ QueryIds["SIMILAR"] = "26217043484590756";
85
+ QueryIds["DIRECTORY_LIST"] = "26125047313831973";
86
+ QueryIds["DIRECTORY_SEARCH"] = "26301059626252132";
87
+ QueryIds["DIRECTORY_CATEGORIES"] = "35266481849605779";
88
+ QueryIds["PENDING_ADMIN_INVITES"] = "9783111038412085";
89
+ QueryIds["QUESTION_RESPONSE_STATE"] = "24636260219323456";
90
+ QueryIds["REACHOUT_TIMELOCK"] = "23983697327930364";
91
+ QueryIds["MESSAGE_CAPPING_INFO"] = "27910975521856601";
92
+ QueryIds["PLAINTEXT_LINK_PREVIEW"] = "9101130456653613";
93
+ QueryIds["USERNAME_GET"] = "25347099718279209";
94
+ QueryIds["USERNAME_SET"] = "25757341163897635";
95
+ QueryIds["USERNAME_PIN_SET"] = "9749436995157074";
96
+ QueryIds["USERNAME_CHECK"] = "26122779627399568";
97
+ QueryIds["UPDATE_TEXT_STATUS"] = "9152604461510864";
98
+ QueryIds["TEXT_STATUS_LIST"] = "24072923595647473";
99
+ QueryIds["ABOUT_STATUS"] = "24535500086059408";
100
+ })(QueryIds || (QueryIds = {}));
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=Product.js.map
@@ -0,0 +1,2 @@
1
+ import { proto } from '../../WAProto/index.js';
2
+ //# sourceMappingURL=Signal.js.map
@@ -0,0 +1,14 @@
1
+ import { proto } from '../../WAProto/index.js';
2
+ import {} from './Message.js';
3
+ //# sourceMappingURL=Socket.js.map
4
+ export const AIProvenanceType = Object.freeze({
5
+ NONE: 0,
6
+ CREATED_WITH_GEN_AI: 1,
7
+ EDITED_WITH_GEN_AI: 2,
8
+ })
9
+
10
+ export const DeviceCapabilityLevel = Object.freeze({
11
+ NONE: 0,
12
+ INFRA: 1,
13
+ FULL: 2,
14
+ })
@@ -0,0 +1,26 @@
1
+ export const SyncState = Object.freeze({ Connecting: 0, AwaitingInitialSync: 1, Syncing: 2, Online: 3 })
2
+
3
+ export const ReachoutTimelockEnforcementType = Object.freeze({
4
+ BIZ_COMMERCE_VIOLATION_ALCOHOL: 'BIZ_COMMERCE_VIOLATION_ALCOHOL',
5
+ BIZ_COMMERCE_VIOLATION_ADULT: 'BIZ_COMMERCE_VIOLATION_ADULT',
6
+ BIZ_COMMERCE_VIOLATION_ANIMALS: 'BIZ_COMMERCE_VIOLATION_ANIMALS',
7
+ BIZ_COMMERCE_VIOLATION_BODY_PARTS_FLUIDS: 'BIZ_COMMERCE_VIOLATION_BODY_PARTS_FLUIDS',
8
+ BIZ_COMMERCE_VIOLATION_DATING: 'BIZ_COMMERCE_VIOLATION_DATING',
9
+ BIZ_COMMERCE_VIOLATION_DIGITAL_SERVICES_PRODUCTS: 'BIZ_COMMERCE_VIOLATION_DIGITAL_SERVICES_PRODUCTS',
10
+ BIZ_COMMERCE_VIOLATION_DRUGS: 'BIZ_COMMERCE_VIOLATION_DRUGS',
11
+ BIZ_COMMERCE_VIOLATION_DRUGS_ONLY_OTC: 'BIZ_COMMERCE_VIOLATION_DRUGS_ONLY_OTC',
12
+ BIZ_COMMERCE_VIOLATION_GAMBLING: 'BIZ_COMMERCE_VIOLATION_GAMBLING',
13
+ BIZ_COMMERCE_VIOLATION_HEALTHCARE: 'BIZ_COMMERCE_VIOLATION_HEALTHCARE',
14
+ BIZ_COMMERCE_VIOLATION_REAL_FAKE_CURRENCY: 'BIZ_COMMERCE_VIOLATION_REAL_FAKE_CURRENCY',
15
+ BIZ_COMMERCE_VIOLATION_SUPPLEMENTS: 'BIZ_COMMERCE_VIOLATION_SUPPLEMENTS',
16
+ BIZ_COMMERCE_VIOLATION_TOBACCO: 'BIZ_COMMERCE_VIOLATION_TOBACCO',
17
+ BIZ_COMMERCE_VIOLATION_VIOLENT_CONTENT: 'BIZ_COMMERCE_VIOLATION_VIOLENT_CONTENT',
18
+ BIZ_COMMERCE_VIOLATION_WEAPONS: 'BIZ_COMMERCE_VIOLATION_WEAPONS',
19
+ BIZ_QUALITY: 'BIZ_QUALITY',
20
+ DEFAULT: 'DEFAULT',
21
+ WEB_COMPANION_ONLY: 'WEB_COMPANION_ONLY',
22
+ })
23
+
24
+ export const NewChatMessageCappingStatusType = Object.freeze({ NONE:'NONE', FIRST_WARNING:'FIRST_WARNING', SECOND_WARNING:'SECOND_WARNING', CAPPED:'CAPPED' })
25
+ export const NewChatMessageCappingMVStatusType = Object.freeze({ NOT_ELIGIBLE:'NOT_ELIGIBLE', NOT_ACTIVE:'NOT_ACTIVE', ACTIVE:'ACTIVE', ACTIVE_UPGRADE_AVAILABLE:'ACTIVE_UPGRADE_AVAILABLE' })
26
+ export const NewChatMessageCappingOTEStatusType = Object.freeze({ NOT_ELIGIBLE:'NOT_ELIGIBLE', ELIGIBLE:'ELIGIBLE', ACTIVE_IN_CURRENT_CYCLE:'ACTIVE_IN_CURRENT_CYCLE', EXHAUSTED:'EXHAUSTED' })
@@ -0,0 +1,2 @@
1
+ import { USyncUser } from '../WAUSync/index.js';
2
+ //# sourceMappingURL=USync.js.map
@@ -0,0 +1,30 @@
1
+ export * from './Auth.js'
2
+ export * from './GroupMetadata.js'
3
+ export * from './Chat.js'
4
+ export * from './Contact.js'
5
+ export * from './State.js'
6
+ export * from './Message.js'
7
+ export * from './Socket.js'
8
+ export * from './Events.js'
9
+ export * from './Product.js'
10
+ export * from './Call.js'
11
+ export * from './Signal.js'
12
+ export * from './Newsletter.js'
13
+ export * from './Label.js'
14
+ export * from './LabelAssociation.js'
15
+ export * from './USync.js'
16
+
17
+ export const DisconnectReason = Object.freeze({
18
+ connectionClosed: 428,
19
+ connectionLost: 408,
20
+ connectionReplaced: 440,
21
+ timedOut: 408,
22
+ loggedOut: 401,
23
+ badSession: 500,
24
+ restartRequired: 515,
25
+ multideviceMismatch: 411,
26
+ forbidden: 403,
27
+ unavailableService: 503,
28
+ })
29
+
30
+
@@ -0,0 +1,142 @@
1
+ import NodeCache from '@cacheable/node-cache'
2
+ import { AsyncLocalStorage } from 'async_hooks'
3
+ import { Mutex } from 'async-mutex'
4
+ import { randomBytes } from 'crypto'
5
+ import PQueue from 'p-queue'
6
+ import { v4 } from 'uuid'
7
+ import { DEFAULT_CACHE_TTLS } from '../Defaults/index.js'
8
+ import { Curve, signedKeyPair } from './crypto.js'
9
+ import { delay, generateRegistrationId } from './generics.js'
10
+ import { PreKeyManager } from './pre-key-manager.js'
11
+
12
+ export function makeCacheableSignalKeyStore(store, logger, _cache) {
13
+ const cache = _cache || new NodeCache({ stdTTL: DEFAULT_CACHE_TTLS.SIGNAL_STORE, useClones: false, deleteOnExpire: true })
14
+ const cacheMutex = new Mutex()
15
+ const uid = (type, id) => `${type}.${id}`
16
+ return {
17
+ async get(type, ids) {
18
+ return cacheMutex.runExclusive(async () => {
19
+ const data = {}, missing = []
20
+ for (const id of ids) { const item = await cache.get(uid(type, id)); if (typeof item !== 'undefined') data[id] = item; else missing.push(id) }
21
+ if (missing.length) { logger?.trace({ items: missing.length }, 'loading from store'); const fetched = await store.get(type, missing); for (const id of missing) { if (fetched[id]) { data[id] = fetched[id]; cache.set(uid(type, id), fetched[id]) } } }
22
+ return data
23
+ })
24
+ },
25
+ async set(data) {
26
+ return cacheMutex.runExclusive(async () => {
27
+ let keys = 0
28
+ for (const type in data) { for (const id in data[type]) { await cache.set(uid(type, id), data[type][id]); keys++ } }
29
+ logger?.trace({ keys }, 'updated cache')
30
+ await store.set(data)
31
+ })
32
+ },
33
+ async clear() { await cache.flushAll(); await store.clear?.() }
34
+ }
35
+ }
36
+
37
+ export const addTransactionCapability = (state, logger, { maxCommitRetries, delayBetweenTriesMs }) => {
38
+ const txStorage = new AsyncLocalStorage()
39
+ const keyQueues = new Map()
40
+ const txMutexes = new Map()
41
+ const preKeyManager = new PreKeyManager(state, logger)
42
+
43
+ const getQueue = key => { if (!keyQueues.has(key)) keyQueues.set(key, new PQueue({ concurrency: 1 })); return keyQueues.get(key) }
44
+ const getTxMutex = key => { if (!txMutexes.has(key)) txMutexes.set(key, new Mutex()); return txMutexes.get(key) }
45
+ const isInTransaction = () => !!txStorage.getStore()
46
+
47
+ const EXPECTED_ERRORS = ['InvalidPreKeyId', 'SessionNotFound', 'InvalidMessage', 'no sender key state', 'memory access out of bounds', 'old counter', 'DuplicatedMessage', 'BadMac', 'Connection Closed']
48
+ const isExpectedError = msg => EXPECTED_ERRORS.some(e => msg.includes(e))
49
+
50
+ async function commitWithRetry(mutations) {
51
+ if (Object.keys(mutations).length === 0) { logger.trace('no mutations in transaction'); return }
52
+ logger.trace('committing transaction')
53
+ for (let attempt = 0; attempt < maxCommitRetries; attempt++) {
54
+ try {
55
+ await state.set(mutations)
56
+ logger.trace({ mutationCount: Object.keys(mutations).length }, 'committed transaction')
57
+ return
58
+ } catch (error) {
59
+ const msg = error?.message || (typeof error === 'string' ? error : '') || ''
60
+ if (isExpectedError(msg)) { logger?.debug?.({ error: msg }, 'transaction skipped — expected decrypt error'); return }
61
+ if (attempt < maxCommitRetries - 1) { await delay(delayBetweenTriesMs); continue }
62
+ logger?.error?.({ error: msg || error }, 'transaction failed after retries')
63
+ throw error
64
+ }
65
+ }
66
+ }
67
+
68
+ return {
69
+ get: async (type, ids) => {
70
+ const ctx = txStorage.getStore()
71
+ if (!ctx) return state.get(type, ids)
72
+ const cached = ctx.cache[type] || {}
73
+ const missing = ids.filter(id => !(id in cached))
74
+ if (missing.length) { ctx.dbQueries++; logger.trace({ type, count: missing.length }, 'fetching missing keys in transaction'); const fetched = await getTxMutex(type).runExclusive(() => state.get(type, missing)); ctx.cache[type] = ctx.cache[type] || {}; Object.assign(ctx.cache[type], fetched) }
75
+ const result = {}
76
+ for (const id of ids) { const value = ctx.cache[type]?.[id]; if (value !== undefined && value !== null) result[id] = value }
77
+ return result
78
+ },
79
+ set: async (data) => {
80
+ const ctx = txStorage.getStore()
81
+ if (!ctx) {
82
+ const types = Object.keys(data)
83
+ for (const type of types) { if (type === 'pre-key') await preKeyManager.validateDeletions(data, type) }
84
+ await Promise.all(types.map(type => getQueue(type).add(async () => state.set({ [type]: data[type] }))))
85
+ return
86
+ }
87
+ logger.trace({ types: Object.keys(data) }, 'caching in transaction')
88
+ for (const key in data) {
89
+ ctx.cache[key] = ctx.cache[key] || {}
90
+ ctx.mutations[key] = ctx.mutations[key] || {}
91
+ if (key === 'pre-key') await preKeyManager.processOperations(data, key, ctx.cache, ctx.mutations, true)
92
+ else { Object.assign(ctx.cache[key], data[key]); Object.assign(ctx.mutations[key], data[key]) }
93
+ }
94
+ },
95
+ isInTransaction,
96
+ transaction: async (work, key) => {
97
+ const existing = txStorage.getStore()
98
+ if (existing) { logger.trace('reusing existing transaction context'); return work() }
99
+ return getTxMutex(key).runExclusive(async () => {
100
+ const ctx = { cache: {}, mutations: {}, dbQueries: 0 }
101
+ logger.trace('entering transaction')
102
+ try {
103
+ const result = await txStorage.run(ctx, work)
104
+ await commitWithRetry(ctx.mutations)
105
+ logger.trace({ dbQueries: ctx.dbQueries }, 'transaction completed')
106
+ return result
107
+ } catch (error) {
108
+ const msg = error?.message || (typeof error === 'string' ? error : '') || ''
109
+ ; (isExpectedError(msg) ? logger?.debug?.bind(logger) : logger?.error?.bind(logger))?.({ error: msg || error }, 'transaction failed, rolling back')
110
+ throw error
111
+ }
112
+ })
113
+ }
114
+ }
115
+ }
116
+
117
+ export const initAuthCreds = () => {
118
+ const identityKey = Curve.generateKeyPair()
119
+ return {
120
+ noiseKey: Curve.generateKeyPair(),
121
+ pairingEphemeralKeyPair: Curve.generateKeyPair(),
122
+ signedIdentityKey: identityKey,
123
+ signedPreKey: signedKeyPair(identityKey, 1),
124
+ registrationId: generateRegistrationId(),
125
+ advSecretKey: randomBytes(32).toString('base64'),
126
+ processedHistoryMessages: [],
127
+ nextPreKeyId: 1,
128
+ firstUnuploadedPreKeyId: 1,
129
+ accountSyncCounter: 0,
130
+ accountSettings: { unarchiveChats: false },
131
+ deviceId: Buffer.from(v4().replace(/-/g, ''), 'hex').toString('base64url'),
132
+ phoneId: v4(),
133
+ identityId: randomBytes(20),
134
+ registered: false,
135
+ backupToken: randomBytes(20),
136
+ registration: {},
137
+ pairingCode: undefined,
138
+ lastPropHash: undefined,
139
+ routingInfo: undefined,
140
+ additionalData: undefined
141
+ }
142
+ }
@@ -0,0 +1,33 @@
1
+ import EventEmitter from 'events'
2
+ import { createReadStream } from 'fs'
3
+ import { writeFile } from 'fs/promises'
4
+ import { createInterface } from 'readline'
5
+ import { delay } from './generics.js'
6
+ import { makeMutex } from './make-mutex.js'
7
+
8
+ export const captureEventStream = (ev, filename) => {
9
+ const oldEmit = ev.emit.bind(ev)
10
+ const writeMutex = makeMutex()
11
+ ev.emit = (...args) => {
12
+ const content = JSON.stringify({ timestamp: Date.now(), event: args[0], data: args[1] }) + '\n'
13
+ const result = oldEmit(...args)
14
+ writeMutex.mutex(() => writeFile(filename, content, { flag: 'a' }))
15
+ return result
16
+ }
17
+ }
18
+
19
+ export const readAndEmitEventStream = (filename, delayIntervalMs = 0) => {
20
+ const ev = new EventEmitter()
21
+ const fireEvents = async () => {
22
+ const fileStream = createReadStream(filename)
23
+ const rl = createInterface({ input: fileStream, crlfDelay: Infinity })
24
+ for await (const line of rl) {
25
+ if (!line) continue
26
+ const { event, data } = JSON.parse(line)
27
+ ev.emit(event, data)
28
+ if (delayIntervalMs) await delay(delayIntervalMs)
29
+ }
30
+ fileStream.destroy()
31
+ }
32
+ return { ev, task: fireEvents() }
33
+ }
@@ -0,0 +1,40 @@
1
+ import { proto } from '../../WAProto/index.js'
2
+ import { BOT_RENDERING_CONFIG_METADATA } from '../Defaults/index.js'
3
+
4
+ export const BotCapabilityType = proto.BotCapabilityMetadata.BotCapabilityType
5
+
6
+ const capabilityNames = new Set(Object.keys(BotCapabilityType).filter(n => Number.isNaN(Number(n))))
7
+
8
+ export const normalizeBotCapabilities = (capabilities = []) => {
9
+ if (!Array.isArray(capabilities)) throw new TypeError('capabilities must be an array')
10
+ const values = capabilities.map(c => {
11
+ if (typeof c === 'string') { if (!capabilityNames.has(c)) throw new TypeError(`Unknown bot capability: ${c}`); return BotCapabilityType[c] }
12
+ if (Number.isInteger(c) && BotCapabilityType[c] !== undefined) return c
13
+ throw new TypeError(`Invalid bot capability: ${String(c)}`)
14
+ })
15
+ return [...new Set(values)]
16
+ }
17
+
18
+ export const buildBotCapabilityMetadata = (capabilities = []) => ({ capabilities: normalizeBotCapabilities(capabilities) })
19
+
20
+ // Use AIRich builder for complex multi-section responses
21
+ export const buildBotRichResponse = ({ text, submessages, capabilities = [], botMetadata = {}, botJid = '867051314767696@bot', richResponse = {} } = {}) => {
22
+ const resolved = submessages || (text == null ? [] : [{ messageType: proto.AIRichResponseSubMessageType.AI_RICH_RESPONSE_TEXT, messageText: String(text) }])
23
+ return {
24
+ messageContextInfo: {
25
+ botMetadata: { ...botMetadata, capabilityMetadata: buildBotCapabilityMetadata(capabilities), botRenderingConfigMetadata: BOT_RENDERING_CONFIG_METADATA }
26
+ },
27
+ botForwardedMessage: {
28
+ message: {
29
+ richResponseMessage: {
30
+ messageType: proto.AIRichResponseMessageType.AI_RICH_RESPONSE_TYPE_STANDARD,
31
+ submessages: resolved,
32
+ ...richResponse,
33
+ contextInfo: { isForwarded: true, forwardingScore: 1, forwardedAiBotMessageInfo: { botJid }, forwardOrigin: 4, ...(richResponse.contextInfo || {}) }
34
+ }
35
+ }
36
+ }
37
+ }
38
+ }
39
+
40
+ export const capability = name => { if (!capabilityNames.has(name)) throw new TypeError(`Unknown bot capability: ${name}`); return BotCapabilityType[name] }