@codexverified/baileys 2.7.5

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 (139) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +233 -0
  3. package/WAProto/V +1 -0
  4. package/WAProto/WAProto.proto +8051 -0
  5. package/WAProto/index.js +289292 -0
  6. package/engine-requirements.js +13 -0
  7. package/lib/Defaults/index.js +158 -0
  8. package/lib/Signal/Group/ciphertext-message.js +11 -0
  9. package/lib/Signal/Group/group-session-builder.js +29 -0
  10. package/lib/Signal/Group/group_cipher.js +81 -0
  11. package/lib/Signal/Group/index.js +11 -0
  12. package/lib/Signal/Group/keyhelper.js +17 -0
  13. package/lib/Signal/Group/sender-chain-key.js +25 -0
  14. package/lib/Signal/Group/sender-key-distribution-message.js +62 -0
  15. package/lib/Signal/Group/sender-key-message.js +65 -0
  16. package/lib/Signal/Group/sender-key-name.js +47 -0
  17. package/lib/Signal/Group/sender-key-record.js +40 -0
  18. package/lib/Signal/Group/sender-key-state.js +83 -0
  19. package/lib/Signal/Group/sender-message-key.js +25 -0
  20. package/lib/Signal/libsignal.js +428 -0
  21. package/lib/Signal/lid-mapping.js +280 -0
  22. package/lib/Socket/Client/index.js +2 -0
  23. package/lib/Socket/Client/types.js +10 -0
  24. package/lib/Socket/Client/websocket.js +53 -0
  25. package/lib/Socket/aigroups.js +315 -0
  26. package/lib/Socket/business.js +407 -0
  27. package/lib/Socket/chats.js +1831 -0
  28. package/lib/Socket/communities.js +431 -0
  29. package/lib/Socket/graphql.js +899 -0
  30. package/lib/Socket/groups.js +549 -0
  31. package/lib/Socket/index.js +79 -0
  32. package/lib/Socket/interactive-handler.js +600 -0
  33. package/lib/Socket/interop.js +563 -0
  34. package/lib/Socket/managed-account.js +208 -0
  35. package/lib/Socket/messages-recv.js +2144 -0
  36. package/lib/Socket/messages-send.js +2030 -0
  37. package/lib/Socket/mex.js +41 -0
  38. package/lib/Socket/newsletter.js +226 -0
  39. package/lib/Socket/privacy.js +446 -0
  40. package/lib/Socket/registration.js +428 -0
  41. package/lib/Socket/socket.js +1017 -0
  42. package/lib/Socket/username.js +229 -0
  43. package/lib/Store/index.js +4 -0
  44. package/lib/Store/make-cache-manager-store.js +89 -0
  45. package/lib/Store/make-in-memory-store.js +420 -0
  46. package/lib/Store/make-ordered-dictionary.js +78 -0
  47. package/lib/Store/object-repository.js +23 -0
  48. package/lib/Types/Auth.js +1 -0
  49. package/lib/Types/Bussines.js +1 -0
  50. package/lib/Types/Call.js +1 -0
  51. package/lib/Types/Chat.js +7 -0
  52. package/lib/Types/Contact.js +1 -0
  53. package/lib/Types/Events.js +1 -0
  54. package/lib/Types/GroupMetadata.js +1 -0
  55. package/lib/Types/Label.js +24 -0
  56. package/lib/Types/LabelAssociation.js +6 -0
  57. package/lib/Types/Message.js +17 -0
  58. package/lib/Types/Mex.js +39 -0
  59. package/lib/Types/Product.js +1 -0
  60. package/lib/Types/RichType.js +22 -0
  61. package/lib/Types/Signal.js +1 -0
  62. package/lib/Types/Socket.js +2 -0
  63. package/lib/Types/State.js +48 -0
  64. package/lib/Types/USync.js +1 -0
  65. package/lib/Types/index.js +25 -0
  66. package/lib/Utils/auth-utils.js +301 -0
  67. package/lib/Utils/bot-planning-replay.js +169 -0
  68. package/lib/Utils/browser-utils.js +28 -0
  69. package/lib/Utils/business.js +230 -0
  70. package/lib/Utils/chat-utils.js +885 -0
  71. package/lib/Utils/companion-reg-client-utils.js +32 -0
  72. package/lib/Utils/consumer-application.js +102 -0
  73. package/lib/Utils/crypto.js +117 -0
  74. package/lib/Utils/decode-wa-message.js +484 -0
  75. package/lib/Utils/event-buffer.js +589 -0
  76. package/lib/Utils/generics.js +388 -0
  77. package/lib/Utils/group-history.js +56 -0
  78. package/lib/Utils/history.js +130 -0
  79. package/lib/Utils/identity-change-handler.js +48 -0
  80. package/lib/Utils/index.js +34 -0
  81. package/lib/Utils/jid-display-normalization.js +209 -0
  82. package/lib/Utils/link-preview.js +84 -0
  83. package/lib/Utils/logger.js +2 -0
  84. package/lib/Utils/lt-hash.js +7 -0
  85. package/lib/Utils/make-mutex.js +32 -0
  86. package/lib/Utils/message-composer.js +467 -0
  87. package/lib/Utils/message-inspect.js +67 -0
  88. package/lib/Utils/message-retry-manager.js +241 -0
  89. package/lib/Utils/messages-media.js +1006 -0
  90. package/lib/Utils/messages.js +1851 -0
  91. package/lib/Utils/meta-ai-msmsg.js +130 -0
  92. package/lib/Utils/meta-compositing.js +194 -0
  93. package/lib/Utils/noise-handler.js +200 -0
  94. package/lib/Utils/offline-node-processor.js +39 -0
  95. package/lib/Utils/pre-key-manager.js +105 -0
  96. package/lib/Utils/process-message.js +527 -0
  97. package/lib/Utils/reporting-utils.js +257 -0
  98. package/lib/Utils/rich-message-utils.js +439 -0
  99. package/lib/Utils/signal.js +200 -0
  100. package/lib/Utils/stanza-ack.js +37 -0
  101. package/lib/Utils/sync-action-utils.js +47 -0
  102. package/lib/Utils/tc-token-utils.js +162 -0
  103. package/lib/Utils/use-multi-file-auth-state.js +120 -0
  104. package/lib/Utils/use-single-file-auth-state.js +96 -0
  105. package/lib/Utils/use-sqlite-auth-state.js +108 -0
  106. package/lib/Utils/validate-connection.js +206 -0
  107. package/lib/Utils/voip-rekey.js +20 -0
  108. package/lib/Utils/welcome-flow.js +217 -0
  109. package/lib/WABinary/constants.js +1463 -0
  110. package/lib/WABinary/decode.js +261 -0
  111. package/lib/WABinary/encode.js +219 -0
  112. package/lib/WABinary/generic-utils.js +227 -0
  113. package/lib/WABinary/index.js +5 -0
  114. package/lib/WABinary/jid-utils.js +95 -0
  115. package/lib/WABinary/types.js +1 -0
  116. package/lib/WAM/BinaryInfo.js +9 -0
  117. package/lib/WAM/constants.js +22852 -0
  118. package/lib/WAM/encode.js +149 -0
  119. package/lib/WAM/index.js +3 -0
  120. package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +96 -0
  121. package/lib/WAUSync/Protocols/USyncContactProtocol.js +56 -0
  122. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +53 -0
  123. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +26 -0
  124. package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +70 -0
  125. package/lib/WAUSync/Protocols/USyncPictureProtocol.js +28 -0
  126. package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +25 -0
  127. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +37 -0
  128. package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +34 -0
  129. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +24 -0
  130. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -0
  131. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +28 -0
  132. package/lib/WAUSync/Protocols/index.js +12 -0
  133. package/lib/WAUSync/USyncQuery.js +201 -0
  134. package/lib/WAUSync/USyncUser.js +54 -0
  135. package/lib/WAUSync/index.js +3 -0
  136. package/lib/antiban.cjs +4726 -0
  137. package/lib/index.d.ts +286 -0
  138. package/lib/index.js +18 -0
  139. package/package.json +121 -0
@@ -0,0 +1,28 @@
1
+ export class USyncLIDProtocol {
2
+ constructor() {
3
+ this.name = 'lid';
4
+ }
5
+ getQueryElement() {
6
+ return {
7
+ tag: 'lid',
8
+ attrs: {}
9
+ };
10
+ }
11
+ getUserElement(user) {
12
+ if (user.lid) {
13
+ return {
14
+ tag: 'lid',
15
+ attrs: { jid: user.lid }
16
+ };
17
+ }
18
+ else {
19
+ return null;
20
+ }
21
+ }
22
+ parser(node) {
23
+ if (node.tag === 'lid') {
24
+ return node.attrs.val;
25
+ }
26
+ return null;
27
+ }
28
+ }
@@ -0,0 +1,12 @@
1
+ export * from './USyncDeviceProtocol.js';
2
+ export * from './USyncContactProtocol.js';
3
+ export * from './USyncStatusProtocol.js';
4
+ export * from './USyncDisappearingModeProtocol.js';
5
+ export * from './USyncUsernameProtocol.js';
6
+ export * from './UsyncBotProfileProtocol.js';
7
+ export * from './USyncBusinessProtocol.js';
8
+ export * from './USyncPictureProtocol.js';
9
+ export * from './USyncTextStatusProtocol.js';
10
+ export * from './UsyncLIDProtocol.js';
11
+ export * from './USyncSidelistProtocol.js';
12
+ export * from './USyncFeatureProtocol.js';
@@ -0,0 +1,201 @@
1
+ import { getBinaryNodeChild } from '../WABinary/index.js';
2
+ import { USyncBotProfileProtocol } from './Protocols/UsyncBotProfileProtocol.js';
3
+ import { USyncLIDProtocol } from './Protocols/UsyncLIDProtocol.js';
4
+ import { USyncBusinessProtocol } from './Protocols/USyncBusinessProtocol.js';
5
+ import { USyncFeatureProtocol } from './Protocols/USyncFeatureProtocol.js';
6
+ import { USyncPictureProtocol } from './Protocols/USyncPictureProtocol.js';
7
+ import { USyncTextStatusProtocol } from './Protocols/USyncTextStatusProtocol.js';
8
+ import { USyncSidelistProtocol } from './Protocols/USyncSidelistProtocol.js';
9
+ import { USyncContactProtocol, USyncDeviceProtocol, USyncDisappearingModeProtocol, USyncStatusProtocol, USyncUsernameProtocol } from './Protocols/index.js';
10
+ import { USyncUser } from './USyncUser.js';
11
+ export class USyncQuery {
12
+ constructor() {
13
+ this.protocols = [];
14
+ this.users = [];
15
+ this.context = 'interactive';
16
+ this.mode = 'query';
17
+ }
18
+ withMode(mode) {
19
+ this.mode = mode;
20
+ return this;
21
+ }
22
+ withContext(context) {
23
+ this.context = context;
24
+ return this;
25
+ }
26
+ withUser(user) {
27
+ this.users.push(user);
28
+ return this;
29
+ }
30
+ parseUSyncQueryResult(result) {
31
+ if (!result || result.attrs.type !== 'result') {
32
+ return;
33
+ }
34
+ const protocolMap = Object.fromEntries(this.protocols.map(protocol => {
35
+ return [protocol.name, protocol.parser];
36
+ }));
37
+ const queryResult = {
38
+ errors: {},
39
+ refresh: {},
40
+ list: [],
41
+ sideList: []
42
+ };
43
+ const usyncNode = getBinaryNodeChild(result, 'usync');
44
+ // Each protocol's result child can carry either an <error code text backoff/>
45
+ // (caller should back off future queries for that protocol) or a refresh="n"
46
+ // attr (caller may cache the response for n seconds). Ported from WAWebUsync's
47
+ // usyncParser.
48
+ const resultNode = usyncNode ? getBinaryNodeChild(usyncNode, 'result') : undefined;
49
+ if (resultNode) {
50
+ for (const protocol of this.protocols) {
51
+ const protocolNode = getBinaryNodeChild(resultNode, protocol.name);
52
+ if (!protocolNode) continue;
53
+ const errorNode = getBinaryNodeChild(protocolNode, 'error');
54
+ if (errorNode) {
55
+ queryResult.errors[protocol.name] = {
56
+ errorCode: errorNode.attrs.code ? +errorNode.attrs.code : undefined,
57
+ errorText: errorNode.attrs.text,
58
+ errorBackoff: errorNode.attrs.backoff ? +errorNode.attrs.backoff : undefined
59
+ };
60
+ }
61
+ else if (protocolNode.attrs.refresh !== undefined) {
62
+ queryResult.refresh[protocol.name] = +protocolNode.attrs.refresh;
63
+ }
64
+ }
65
+ }
66
+ const parseUserNodes = nodes => {
67
+ return nodes.reduce((acc, node) => {
68
+ const id = node?.attrs.jid;
69
+ if (id) {
70
+ // G. Blocked-by tracking: a user-level error attribute signals the contact
71
+ // has blocked us (WA uses 401/403/405 on the <user> node in this case).
72
+ const userErrorCode = node?.attrs?.error ? parseInt(node.attrs.error, 10) : 0;
73
+ const isBlockedByAttr = userErrorCode === 401 || userErrorCode === 403 || userErrorCode === 405;
74
+
75
+ const data = Array.isArray(node?.content)
76
+ ? Object.fromEntries(
77
+ node.content
78
+ .map(content => {
79
+ const protocol = content.tag;
80
+
81
+ // B. Privacy Token: extract per-contact privacy_token and
82
+ // privacy_mode_ts from <privacy> child elements in usync responses.
83
+ if (protocol === 'privacy') {
84
+ const tokenNode = getBinaryNodeChild(content, 'token');
85
+ const modeTsNode = getBinaryNodeChild(content, 'mode_ts');
86
+ // Also accept inline attrs format
87
+ const tokenVal = tokenNode?.content || content.attrs?.token;
88
+ const modeTsVal =
89
+ modeTsNode?.content?.toString?.() || modeTsNode?.attrs?.value || content.attrs?.mode_ts || null;
90
+ if (tokenVal) {
91
+ return [
92
+ 'privacy',
93
+ {
94
+ token: Buffer.isBuffer(tokenVal) || tokenVal instanceof Uint8Array
95
+ ? Buffer.from(tokenVal)
96
+ : tokenVal,
97
+ modeTs: modeTsVal
98
+ }
99
+ ];
100
+ }
101
+ return ['privacy', null];
102
+ }
103
+
104
+ const parser = protocolMap[protocol];
105
+ if (parser) {
106
+ try {
107
+ return [protocol, parser(content)];
108
+ }
109
+ catch (err) {
110
+ // G. Blocked-by: sub-node parser errors with blocked codes
111
+ // should surface as isBlockedByContact rather than crashing.
112
+ const errCode = err?.data ?? err?.output?.payload?.data;
113
+ if (errCode === 401 || errCode === 403 || errCode === 405) {
114
+ return ['isBlockedByContact', true];
115
+ }
116
+ throw err;
117
+ }
118
+ }
119
+ else {
120
+ return [protocol, null];
121
+ }
122
+ })
123
+ .filter(([, b]) => b !== null)
124
+ )
125
+ : {};
126
+
127
+ // Merge user-attr blocked flag with any parser-detected blocked flag.
128
+ if (isBlockedByAttr) {
129
+ data.isBlockedByContact = true;
130
+ }
131
+
132
+ // Remap snake_case protocol keys to camelCase contact fields.
133
+ if ('disappearing_mode' in data) {
134
+ data.disappearingMode = data.disappearing_mode;
135
+ delete data.disappearing_mode;
136
+ }
137
+
138
+ acc.push({ ...data, id });
139
+ }
140
+ return acc;
141
+ }, []);
142
+ };
143
+ const listNode = usyncNode ? getBinaryNodeChild(usyncNode, 'list') : undefined;
144
+ if (listNode?.content && Array.isArray(listNode.content)) {
145
+ queryResult.list = parseUserNodes(listNode.content);
146
+ }
147
+ const sideListNode = usyncNode ? getBinaryNodeChild(usyncNode, 'side_list') : undefined;
148
+ if (sideListNode?.content && Array.isArray(sideListNode.content)) {
149
+ queryResult.sideList = parseUserNodes(sideListNode.content);
150
+ }
151
+ return queryResult;
152
+ }
153
+ withDeviceProtocol() {
154
+ this.protocols.push(new USyncDeviceProtocol());
155
+ return this;
156
+ }
157
+ withContactProtocol() {
158
+ this.protocols.push(new USyncContactProtocol());
159
+ return this;
160
+ }
161
+ withStatusProtocol() {
162
+ this.protocols.push(new USyncStatusProtocol());
163
+ return this;
164
+ }
165
+ withDisappearingModeProtocol() {
166
+ this.protocols.push(new USyncDisappearingModeProtocol());
167
+ return this;
168
+ }
169
+ withBotProfileProtocol() {
170
+ this.protocols.push(new USyncBotProfileProtocol());
171
+ return this;
172
+ }
173
+ withLIDProtocol() {
174
+ this.protocols.push(new USyncLIDProtocol());
175
+ return this;
176
+ }
177
+ withUsernameProtocol() {
178
+ this.protocols.push(new USyncUsernameProtocol());
179
+ return this;
180
+ }
181
+ withBusinessProtocol(profileVersion) {
182
+ this.protocols.push(new USyncBusinessProtocol(profileVersion));
183
+ return this;
184
+ }
185
+ withPictureProtocol(type) {
186
+ this.protocols.push(new USyncPictureProtocol(type));
187
+ return this;
188
+ }
189
+ withTextStatusProtocol() {
190
+ this.protocols.push(new USyncTextStatusProtocol());
191
+ return this;
192
+ }
193
+ withSidelistProtocol(useLidAddressing) {
194
+ this.protocols.push(new USyncSidelistProtocol(useLidAddressing));
195
+ return this;
196
+ }
197
+ withFeatureProtocol(features) {
198
+ this.protocols.push(new USyncFeatureProtocol(features));
199
+ return this;
200
+ }
201
+ }
@@ -0,0 +1,54 @@
1
+ export class USyncUser {
2
+ withId(id) {
3
+ this.id = id;
4
+ return this;
5
+ }
6
+ withLid(lid) {
7
+ this.lid = lid;
8
+ return this;
9
+ }
10
+ withPhone(phone) {
11
+ this.phone = phone;
12
+ return this;
13
+ }
14
+ withUsername(username) {
15
+ this.username = username;
16
+ return this;
17
+ }
18
+ withUsernameKey(usernameKey) {
19
+ this.usernameKey = usernameKey;
20
+ return this;
21
+ }
22
+ withType(type) {
23
+ this.type = type;
24
+ return this;
25
+ }
26
+ withPersonaId(personaId) {
27
+ this.personaId = personaId;
28
+ return this;
29
+ }
30
+ withTcToken(tcToken) {
31
+ this.tcToken = tcToken;
32
+ return this;
33
+ }
34
+ withPnJid(pnJid) {
35
+ this.pnJid = pnJid;
36
+ return this;
37
+ }
38
+ withDeviceHash(deviceHash) {
39
+ this.deviceHash = deviceHash;
40
+ return this;
41
+ }
42
+ withTs(ts) {
43
+ this.ts = ts;
44
+ return this;
45
+ }
46
+ withExpectedTs(expectedTs) {
47
+ this.expectedTs = expectedTs;
48
+ return this;
49
+ }
50
+ /** Ported from WAWebUsyncUser's validate() a usync user needs at least one addressable field. */
51
+ validate() {
52
+ return !!(this.id || this.phone || this.username || this.pnJid);
53
+ }
54
+ }
@@ -0,0 +1,3 @@
1
+ export * from './Protocols/index.js';
2
+ export * from './USyncQuery.js';
3
+ export * from './USyncUser.js';