@skyzopedia/baileys-mod 5.0.8 → 6.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 (212) hide show
  1. package/WAProto/index.js +133384 -57814
  2. package/engine-requirements.js +10 -0
  3. package/lib/Defaults/baileys-version.json +3 -0
  4. package/lib/Defaults/index.d.ts +53 -0
  5. package/lib/Defaults/index.js +141 -117
  6. package/lib/Defaults/phonenumber-mcc.json +223 -0
  7. package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
  8. package/lib/Signal/Group/ciphertext-message.js +14 -12
  9. package/lib/Signal/Group/group-session-builder.d.ts +14 -0
  10. package/lib/Signal/Group/group-session-builder.js +42 -10
  11. package/lib/Signal/Group/group_cipher.d.ts +17 -0
  12. package/lib/Signal/Group/group_cipher.js +87 -75
  13. package/lib/Signal/Group/index.d.ts +11 -0
  14. package/lib/Signal/Group/index.js +57 -13
  15. package/lib/Signal/Group/keyhelper.d.ts +10 -0
  16. package/lib/Signal/Group/keyhelper.js +52 -17
  17. package/lib/Signal/Group/queue-job.d.ts +1 -0
  18. package/lib/Signal/Group/queue-job.js +57 -0
  19. package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
  20. package/lib/Signal/Group/sender-chain-key.js +33 -27
  21. package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
  22. package/lib/Signal/Group/sender-key-distribution-message.js +63 -62
  23. package/lib/Signal/Group/sender-key-message.d.ts +18 -0
  24. package/lib/Signal/Group/sender-key-message.js +66 -65
  25. package/lib/Signal/Group/sender-key-name.d.ts +17 -0
  26. package/lib/Signal/Group/sender-key-name.js +44 -45
  27. package/lib/Signal/Group/sender-key-record.d.ts +30 -0
  28. package/lib/Signal/Group/sender-key-record.js +49 -39
  29. package/lib/Signal/Group/sender-key-state.d.ts +38 -0
  30. package/lib/Signal/Group/sender-key-state.js +93 -80
  31. package/lib/Signal/Group/sender-message-key.d.ts +11 -0
  32. package/lib/Signal/Group/sender-message-key.js +28 -27
  33. package/lib/Signal/libsignal.d.ts +3 -0
  34. package/lib/Signal/libsignal.js +163 -313
  35. package/lib/Socket/Client/abstract-socket-client.d.ts +17 -0
  36. package/lib/Socket/Client/abstract-socket-client.js +13 -0
  37. package/lib/Socket/Client/index.d.ts +3 -0
  38. package/lib/Socket/Client/index.js +19 -4
  39. package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
  40. package/lib/Socket/Client/mobile-socket-client.js +65 -0
  41. package/lib/Socket/Client/web-socket-client.d.ts +12 -0
  42. package/lib/Socket/Client/web-socket-client.js +62 -0
  43. package/lib/Socket/business.d.ts +171 -0
  44. package/lib/Socket/business.js +242 -359
  45. package/lib/Socket/chats.d.ts +267 -0
  46. package/lib/Socket/chats.js +935 -846
  47. package/lib/Socket/dugong.d.ts +254 -0
  48. package/lib/Socket/dugong.js +484 -0
  49. package/lib/Socket/groups.d.ts +115 -0
  50. package/lib/Socket/groups.js +309 -304
  51. package/lib/Socket/index.d.ts +173 -0
  52. package/lib/Socket/index.js +10 -15
  53. package/lib/Socket/messages-recv.d.ts +161 -0
  54. package/lib/Socket/messages-recv.js +1054 -1107
  55. package/lib/Socket/messages-send.d.ts +149 -0
  56. package/lib/Socket/messages-send.js +447 -706
  57. package/lib/Socket/newsletter.d.ts +134 -0
  58. package/lib/Socket/newsletter.js +314 -199
  59. package/lib/Socket/registration.d.ts +267 -0
  60. package/lib/Socket/registration.js +166 -0
  61. package/lib/Socket/socket.d.ts +43 -0
  62. package/lib/Socket/socket.js +650 -777
  63. package/lib/Socket/usync.d.ts +36 -0
  64. package/lib/Socket/usync.js +70 -0
  65. package/lib/Store/index.d.ts +3 -0
  66. package/lib/Store/index.js +10 -6
  67. package/lib/Store/make-cache-manager-store.d.ts +13 -0
  68. package/lib/Store/make-cache-manager-store.js +81 -73
  69. package/lib/Store/make-in-memory-store.d.ts +118 -0
  70. package/lib/Store/make-in-memory-store.js +423 -286
  71. package/lib/Store/make-ordered-dictionary.d.ts +13 -0
  72. package/lib/Store/make-ordered-dictionary.js +79 -77
  73. package/lib/Store/object-repository.d.ts +10 -0
  74. package/lib/Store/object-repository.js +26 -24
  75. package/lib/Types/Auth.d.ts +110 -0
  76. package/lib/Types/Auth.js +2 -3
  77. package/lib/Types/Call.d.ts +13 -0
  78. package/lib/Types/Call.js +2 -3
  79. package/lib/Types/Chat.d.ts +102 -0
  80. package/lib/Types/Chat.js +4 -9
  81. package/lib/Types/Contact.d.ts +19 -0
  82. package/lib/Types/Contact.js +2 -3
  83. package/lib/Types/Events.d.ts +157 -0
  84. package/lib/Types/Events.js +2 -3
  85. package/lib/Types/GroupMetadata.d.ts +55 -0
  86. package/lib/Types/GroupMetadata.js +2 -3
  87. package/lib/Types/Label.d.ts +35 -0
  88. package/lib/Types/Label.js +26 -24
  89. package/lib/Types/LabelAssociation.d.ts +29 -0
  90. package/lib/Types/LabelAssociation.js +8 -6
  91. package/lib/Types/Message.d.ts +273 -0
  92. package/lib/Types/Message.js +9 -12
  93. package/lib/Types/Newsletter.d.ts +103 -0
  94. package/lib/Types/Newsletter.js +38 -33
  95. package/lib/Types/Product.d.ts +78 -0
  96. package/lib/Types/Product.js +2 -3
  97. package/lib/Types/Signal.d.ts +57 -0
  98. package/lib/Types/Signal.js +2 -3
  99. package/lib/Types/Socket.d.ts +111 -0
  100. package/lib/Types/Socket.js +2 -4
  101. package/lib/Types/State.d.ts +27 -0
  102. package/lib/Types/State.js +2 -11
  103. package/lib/Types/USync.d.ts +25 -0
  104. package/lib/Types/USync.js +2 -3
  105. package/lib/Types/index.d.ts +57 -0
  106. package/lib/Types/index.js +41 -27
  107. package/lib/Utils/auth-utils.d.ts +18 -0
  108. package/lib/Utils/auth-utils.js +198 -211
  109. package/lib/Utils/baileys-event-stream.d.ts +16 -0
  110. package/lib/Utils/baileys-event-stream.js +61 -42
  111. package/lib/Utils/business.d.ts +22 -0
  112. package/lib/Utils/business.js +214 -213
  113. package/lib/Utils/chat-utils.d.ts +71 -0
  114. package/lib/Utils/chat-utils.js +687 -710
  115. package/lib/Utils/crypto.d.ts +41 -0
  116. package/lib/Utils/crypto.js +133 -112
  117. package/lib/Utils/decode-wa-message.d.ts +19 -0
  118. package/lib/Utils/decode-wa-message.js +183 -252
  119. package/lib/Utils/event-buffer.d.ts +35 -0
  120. package/lib/Utils/event-buffer.js +496 -510
  121. package/lib/Utils/generics.d.ts +92 -0
  122. package/lib/Utils/generics.js +392 -319
  123. package/lib/Utils/generics.js.bak +433 -0
  124. package/lib/Utils/history.d.ts +15 -0
  125. package/lib/Utils/history.js +92 -83
  126. package/lib/Utils/index.d.ts +17 -0
  127. package/lib/Utils/index.js +33 -21
  128. package/lib/Utils/link-preview.d.ts +21 -0
  129. package/lib/Utils/link-preview.js +83 -71
  130. package/lib/Utils/logger.d.ts +4 -0
  131. package/lib/Utils/logger.js +7 -5
  132. package/lib/Utils/lt-hash.d.ts +12 -0
  133. package/lib/Utils/lt-hash.js +46 -40
  134. package/lib/Utils/make-mutex.d.ts +7 -0
  135. package/lib/Utils/make-mutex.js +41 -34
  136. package/lib/Utils/messages-media.d.ts +116 -0
  137. package/lib/Utils/messages-media.js +768 -550
  138. package/lib/Utils/messages.d.ts +77 -0
  139. package/lib/Utils/messages.js +263 -362
  140. package/lib/Utils/noise-handler.d.ts +21 -0
  141. package/lib/Utils/noise-handler.js +149 -138
  142. package/lib/Utils/process-message.d.ts +41 -0
  143. package/lib/Utils/process-message.js +303 -323
  144. package/lib/Utils/signal.d.ts +32 -0
  145. package/lib/Utils/signal.js +141 -149
  146. package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
  147. package/lib/Utils/use-multi-file-auth-state.js +103 -95
  148. package/lib/Utils/validate-connection.d.ts +11 -0
  149. package/lib/Utils/validate-connection.js +214 -183
  150. package/lib/Utils/validate-connection.js.bak +237 -0
  151. package/lib/WABinary/constants.d.ts +30 -0
  152. package/lib/WABinary/constants.js +35 -1298
  153. package/lib/WABinary/decode.d.ts +7 -0
  154. package/lib/WABinary/decode.js +249 -237
  155. package/lib/WABinary/encode.d.ts +3 -0
  156. package/lib/WABinary/encode.js +260 -213
  157. package/lib/WABinary/generic-utils.d.ts +17 -0
  158. package/lib/WABinary/generic-utils.js +65 -56
  159. package/lib/WABinary/index.d.ts +5 -0
  160. package/lib/WABinary/index.js +21 -7
  161. package/lib/WABinary/jid-utils.d.ts +31 -0
  162. package/lib/WABinary/jid-utils.js +58 -89
  163. package/lib/WABinary/types.d.ts +18 -0
  164. package/lib/WABinary/types.js +2 -3
  165. package/lib/WAM/BinaryInfo.d.ts +17 -0
  166. package/lib/WAM/BinaryInfo.js +12 -10
  167. package/lib/WAM/constants.d.ts +38 -0
  168. package/lib/WAM/constants.js +15348 -22851
  169. package/lib/WAM/encode.d.ts +3 -0
  170. package/lib/WAM/encode.js +136 -135
  171. package/lib/WAM/index.d.ts +3 -0
  172. package/lib/WAM/index.js +19 -5
  173. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
  174. package/lib/WAUSync/Protocols/USyncContactProtocol.js +30 -28
  175. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
  176. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +53 -49
  177. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
  178. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +28 -27
  179. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
  180. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +39 -36
  181. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +25 -0
  182. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -50
  183. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +8 -0
  184. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +20 -26
  185. package/lib/WAUSync/Protocols/index.d.ts +4 -0
  186. package/lib/WAUSync/Protocols/index.js +20 -6
  187. package/lib/WAUSync/USyncQuery.d.ts +28 -0
  188. package/lib/WAUSync/USyncQuery.js +85 -86
  189. package/lib/WAUSync/USyncUser.d.ts +12 -0
  190. package/lib/WAUSync/USyncUser.js +25 -23
  191. package/lib/WAUSync/index.d.ts +3 -0
  192. package/lib/WAUSync/index.js +19 -5
  193. package/lib/index.d.ts +12 -0
  194. package/lib/index.js +36 -24
  195. package/package.json +106 -98
  196. package/LICENSE +0 -21
  197. package/WAProto/WAProto.proto +0 -5311
  198. package/lib/KeyDB/BinarySearch.js +0 -20
  199. package/lib/KeyDB/KeyedDB.js +0 -167
  200. package/lib/KeyDB/index.js +0 -4
  201. package/lib/Signal/lid-mapping.js +0 -155
  202. package/lib/Socket/Client/types.js +0 -13
  203. package/lib/Socket/Client/websocket.js +0 -52
  204. package/lib/Socket/Client/websocket.js.bak +0 -53
  205. package/lib/Socket/communities.js +0 -413
  206. package/lib/Socket/mex.js +0 -45
  207. package/lib/Types/Bussines.js +0 -3
  208. package/lib/Types/Newsletter.js.bak +0 -33
  209. package/lib/Utils/browser-utils.js +0 -25
  210. package/lib/Utils/message-retry-manager.js +0 -113
  211. package/lib/Utils/messages.js.bak +0 -907
  212. package/lib/Utils/pre-key-manager.js +0 -85
@@ -1,20 +0,0 @@
1
- //===================================//
2
- export default function binarySearch(array, predicate) {
3
- let low = 0;
4
- let high = array.length;
5
- if (array.length === 0) return low;
6
- if (predicate(array[low]) < 0) return low - 1;
7
- else if (predicate(array[low]) === 0) return low;
8
- const maxPred = predicate(array[high - 1]);
9
- if (maxPred > 0) return high;
10
- else if (maxPred === 0) return high - 1;
11
- while (low !== high) {
12
- const mid = low + Math.floor((high - low) / 2);
13
- const pred = predicate(array[mid]);
14
- if (pred < 0) high = mid;
15
- else if (pred > 0) low = mid + 1;
16
- else return mid;
17
- }
18
- return low;
19
- }
20
- //===================================//
@@ -1,167 +0,0 @@
1
- //===================================//
2
- import binarySearch from "./BinarySearch.js";
3
- //===================================//
4
- export default class KeyedDB {
5
- constructor(key, id) {
6
- this.key = key;
7
- this.idGetter = id || (v => this.key.key(v).toString());
8
- this.dict = {};
9
- this.array = [];
10
- }
11
- get length() {
12
- return this.array.length;
13
- }
14
- get first() {
15
- return this.array[0];
16
- }
17
- get last() {
18
- return this.array[this.array.length - 1];
19
- }
20
- toJSON() {
21
- return this.array;
22
- }
23
- insert(...values) {
24
- values.forEach(v => this._insertSingle(v));
25
- }
26
- upsert(...values) {
27
- const updates = [];
28
- values.forEach(v => {
29
- if (!v) return;
30
- const deleted = this.deleteById(this.idGetter(v), false);
31
- this._insertSingle(v);
32
- deleted && updates.push(v);
33
- });
34
- return updates;
35
- }
36
- insertIfAbsent(...values) {
37
- const insertions = [];
38
- values.forEach(v => {
39
- if (!v) return;
40
- const presentValue = this.get(this.idGetter(v));
41
- if (presentValue) return;
42
- const presentKey = this.firstIndex(v);
43
- if (this.array[presentKey] && this.key.key(this.array[presentKey]) === this.key.key(v)) return;
44
- this.insert(v);
45
- insertions.push(v);
46
- });
47
- return insertions;
48
- }
49
- deleteById(id, assertPresent = true) {
50
- const value = this.get(id);
51
- if (!value) {
52
- if (assertPresent) throw new Error(`Value not found`);
53
- return;
54
- }
55
- return this.delete(value);
56
- }
57
- delete(value) {
58
- const index = this.firstIndex(value);
59
- if (index < 0 || index >= this.array.length || this.key.key(value) !== this.key.key(this.array[index])) {
60
- return null;
61
- }
62
- delete this.dict[this.idGetter(value)];
63
- return this.array.splice(index, 1)[0];
64
- }
65
- slice(start, end) {
66
- const db = new KeyedDB(this.key, this.idGetter);
67
- db.array = this.array.slice(start, end);
68
- db.array.forEach(item => db.dict[this.idGetter(item)] = item);
69
- return db;
70
- }
71
- clear() {
72
- this.array = [];
73
- this.dict = {};
74
- }
75
- get(id) {
76
- return this.dict[id];
77
- }
78
- all() {
79
- return this.array;
80
- }
81
- update(id, update) {
82
- const value = this.get(id);
83
- if (value) {
84
- const idx = this.firstIndex(value);
85
- if (idx >= 0 && idx < this.array.length && this.idGetter(this.array[idx]) === id) {
86
- const oldKey = this.key.key(value);
87
- update(value);
88
- const newKey = this.key.key(value);
89
- if (newKey !== oldKey) {
90
- delete this.dict[id];
91
- this.array.splice(idx, 1);
92
- this._insertSingle(value);
93
- return 2;
94
- }
95
- return 1;
96
- }
97
- }
98
- }
99
- updateKey(value, update) {
100
- return this.update(this.idGetter(value), update);
101
- }
102
- filter(predicate) {
103
- const db = new KeyedDB(this.key, this.idGetter);
104
- db.array = this.array.filter((value, index) => {
105
- if (predicate(value, index)) {
106
- db.dict[this.idGetter(value)] = value;
107
- return true;
108
- }
109
- });
110
- return db;
111
- }
112
- paginatedByValue(value, limit, predicate, mode = "after") {
113
- return this.paginated(value && this.key.key(value), limit, predicate, mode);
114
- }
115
- paginated(cursor, limit, predicate, mode = "after") {
116
- let index = mode === "after" ? 0 : this.array.length;
117
- if (cursor !== null && typeof cursor !== "undefined") {
118
- index = binarySearch(this.array, v => this.key.compare(cursor, this.key.key(v)));
119
- if (index < 0) index = 0;
120
- if (this.key.key(this.array[index]) === cursor) index += (mode === "after" ? 1 : 0);
121
- }
122
- return this.filtered(index, limit, mode, predicate);
123
- }
124
- _insertSingle(value) {
125
- if (!value) throw new Error("falsey value");
126
- const valueID = this.idGetter(value);
127
- if (this.get(valueID)) throw new Error("duplicate ID being inserted: " + valueID);
128
-
129
- if (this.array.length > 0) {
130
- const index = this.firstIndex(value);
131
- if (index >= this.array.length) this.array.push(value);
132
- else if (index < 0) this.array.unshift(value);
133
- else if (this.key.key(value) !== this.key.key(this.array[index])) this.array.splice(index, 0, value);
134
- else throw new Error(`duplicate key: ${this.key.key(value)}, inserting: ${valueID}, present: ${this.idGetter(this.array[index])}`);
135
- } else {
136
- this.array.push(value);
137
- }
138
- this.dict[valueID] = value;
139
- }
140
- filtered(start, count, mode, predicate) {
141
- let arr;
142
- if (mode === "after") {
143
- if (predicate) {
144
- arr = [];
145
- for (let item of this.array.slice(start)) {
146
- predicate(item, start + arr.length) && arr.push(item);
147
- if (arr.length >= count) break;
148
- }
149
- } else arr = this.array.slice(start, start + count);
150
- } else if (mode === "before") {
151
- if (predicate) {
152
- arr = [];
153
- for (let i = start - 1; i >= 0; i--) {
154
- let item = this.array[i];
155
- predicate(item, start + arr.length) && arr.unshift(item);
156
- if (arr.length >= count) break;
157
- }
158
- } else arr = this.array.slice(Math.max(start - count, 0), start);
159
- }
160
- return arr;
161
- }
162
- firstIndex(value) {
163
- const valueKey = this.key.key(value);
164
- return binarySearch(this.array, v => this.key.compare(valueKey, this.key.key(v)));
165
- }
166
- }
167
- //===================================//
@@ -1,4 +0,0 @@
1
- //===================================//
2
- export * from "./BinarySearch.js"
3
- export * from "./KeyedDB.js"
4
- //===================================//
@@ -1,155 +0,0 @@
1
- //=======================================================//
2
- import { isHostedPnUser, isLidUser, isPnUser, jidDecode, jidNormalizedUser, WAJIDDomains } from "../WABinary/index.js";
3
- import { LRUCache } from "lru-cache";
4
- //=======================================================//
5
- export class LIDMappingStore {
6
- constructor(keys, logger, pnToLIDFunc) {
7
- this.mappingCache = new LRUCache({
8
- ttl: 7 * 24 * 60 * 60 * 1000,
9
- ttlAutopurge: true,
10
- updateAgeOnGet: true
11
- });
12
- this.keys = keys;
13
- this.pnToLIDFunc = pnToLIDFunc;
14
- this.logger = logger;
15
- }
16
- async storeLIDPNMappings(pairs) {
17
- const pairMap = {};
18
- for (const { lid, pn } of pairs) {
19
- if (!((isLidUser(lid) && isPnUser(pn)) || (isPnUser(lid) && isLidUser(pn)))) {
20
- this.logger.warn(`Invalid LID-PN mapping: ${lid}, ${pn}`);
21
- continue;
22
- }
23
- const lidDecoded = jidDecode(lid);
24
- const pnDecoded = jidDecode(pn);
25
- if (!lidDecoded || !pnDecoded)
26
- return;
27
- const pnUser = pnDecoded.user;
28
- const lidUser = lidDecoded.user;
29
- let existingLidUser = this.mappingCache.get(`pn:${pnUser}`);
30
- if (!existingLidUser) {
31
- this.logger.trace(`Cache miss for PN user ${pnUser}; checking database`);
32
- const stored = await this.keys.get("lid-mapping", [pnUser]);
33
- existingLidUser = stored[pnUser];
34
- if (existingLidUser) {
35
- this.mappingCache.set(`pn:${pnUser}`, existingLidUser);
36
- this.mappingCache.set(`lid:${existingLidUser}`, pnUser);
37
- }
38
- }
39
- if (existingLidUser === lidUser) {
40
- this.logger.debug({ pnUser, lidUser }, "LID mapping already exists, skipping");
41
- continue;
42
- }
43
- pairMap[pnUser] = lidUser;
44
- }
45
- this.logger.trace({ pairMap }, `Storing ${Object.keys(pairMap).length} pn mappings`);
46
- await this.keys.transaction(async () => {
47
- for (const [pnUser, lidUser] of Object.entries(pairMap)) {
48
- await this.keys.set({
49
- "lid-mapping": {
50
- [pnUser]: lidUser,
51
- [`${lidUser}_reverse`]: pnUser
52
- }
53
- });
54
- this.mappingCache.set(`pn:${pnUser}`, lidUser);
55
- this.mappingCache.set(`lid:${lidUser}`, pnUser);
56
- }
57
- }, "lid-mapping");
58
- }
59
- async getLIDForPN(pn) {
60
- return (await this.getLIDsForPNs([pn]))?.[0]?.lid || null;
61
- }
62
- async getLIDsForPNs(pns) {
63
- const usyncFetch = {};
64
- const successfulPairs = {};
65
- for (const pn of pns) {
66
- if (!isPnUser(pn) && !isHostedPnUser(pn))
67
- continue;
68
- const decoded = jidDecode(pn);
69
- if (!decoded)
70
- continue;
71
- const pnUser = decoded.user;
72
- let lidUser = this.mappingCache.get(`pn:${pnUser}`);
73
- if (!lidUser) {
74
- const stored = await this.keys.get("lid-mapping", [pnUser]);
75
- lidUser = stored[pnUser];
76
- if (lidUser) {
77
- this.mappingCache.set(`pn:${pnUser}`, lidUser);
78
- this.mappingCache.set(`lid:${lidUser}`, pnUser);
79
- }
80
- else {
81
- this.logger.trace(`No LID mapping found for PN user ${pnUser}; batch getting from USync`);
82
- const device = decoded.device || 0;
83
- let normalizedPn = jidNormalizedUser(pn);
84
- if (isHostedPnUser(normalizedPn)) {
85
- normalizedPn = `${pnUser}@s.whatsapp.net`;
86
- }
87
- if (!usyncFetch[normalizedPn]) {
88
- usyncFetch[normalizedPn] = [device];
89
- }
90
- else {
91
- usyncFetch[normalizedPn]?.push(device);
92
- }
93
- continue;
94
- }
95
- }
96
- lidUser = lidUser.toString();
97
- if (!lidUser) {
98
- this.logger.warn(`Invalid or empty LID user for PN ${pn}: lidUser = "${lidUser}"`);
99
- return null;
100
- }
101
- const pnDevice = decoded.device !== undefined ? decoded.device : 0;
102
- const deviceSpecificLid = `${lidUser}${!!pnDevice ? `:${pnDevice}` : ``}@${decoded.server === "hosted" ? "hosted.lid" : "lid"}`;
103
- this.logger.trace(`getLIDForPN: ${pn} → ${deviceSpecificLid} (user mapping with device ${pnDevice})`);
104
- successfulPairs[pn] = { lid: deviceSpecificLid, pn };
105
- }
106
- if (Object.keys(usyncFetch).length > 0) {
107
- const result = await this.pnToLIDFunc?.(Object.keys(usyncFetch));
108
- if (result && result.length > 0) {
109
- this.storeLIDPNMappings(result);
110
- for (const pair of result) {
111
- const pnDecoded = jidDecode(pair.pn);
112
- const pnUser = pnDecoded?.user;
113
- if (!pnUser)
114
- continue;
115
- const lidUser = jidDecode(pair.lid)?.user;
116
- if (!lidUser)
117
- continue;
118
- for (const device of usyncFetch[pair.pn]) {
119
- const deviceSpecificLid = `${lidUser}${!!device ? `:${device}` : ``}@${device === 99 ? "hosted.lid" : "lid"}`;
120
- this.logger.trace(`getLIDForPN: USYNC success for ${pair.pn} → ${deviceSpecificLid} (user mapping with device ${device})`);
121
- const deviceSpecificPn = `${pnUser}${!!device ? `:${device}` : ``}@${device === 99 ? "hosted" : "s.whatsapp.net"}`;
122
- successfulPairs[deviceSpecificPn] = { lid: deviceSpecificLid, pn: deviceSpecificPn };
123
- }
124
- }
125
- }
126
- else {
127
- return null;
128
- }
129
- }
130
- return Object.values(successfulPairs);
131
- }
132
- async getPNForLID(lid) {
133
- if (!isLidUser(lid))
134
- return null;
135
- const decoded = jidDecode(lid);
136
- if (!decoded)
137
- return null;
138
- const lidUser = decoded.user;
139
- let pnUser = this.mappingCache.get(`lid:${lidUser}`);
140
- if (!pnUser || typeof pnUser !== "string") {
141
- const stored = await this.keys.get("lid-mapping", [`${lidUser}_reverse`]);
142
- pnUser = stored[`${lidUser}_reverse`];
143
- if (!pnUser || typeof pnUser !== "string") {
144
- this.logger.trace(`No reverse mapping found for LID user: ${lidUser}`);
145
- return null;
146
- }
147
- this.mappingCache.set(`lid:${lidUser}`, pnUser);
148
- }
149
- const lidDevice = decoded.device !== undefined ? decoded.device : 0;
150
- const pnJid = `${pnUser}:${lidDevice}@${decoded.domainType === WAJIDDomains.HOSTED_LID ? "hosted" : "s.whatsapp.net"}`;
151
- this.logger.trace(`Found reverse mapping: ${lid} → ${pnJid}`);
152
- return pnJid;
153
- }
154
- }
155
- //=======================================================//
@@ -1,13 +0,0 @@
1
- //=======================================================//
2
- import { EventEmitter } from "events";
3
- import { URL } from "url";
4
- //=======================================================//
5
- export class AbstractSocketClient extends EventEmitter {
6
- constructor(url, config) {
7
- super();
8
- this.url = url;
9
- this.config = config;
10
- this.setMaxListeners(0);
11
- }
12
- }
13
- //=======================================================//
@@ -1,52 +0,0 @@
1
- //=======================================================//
2
- import { DEFAULT_ORIGIN } from "../../Defaults/index.js";
3
- import { AbstractSocketClient } from "./types.js";
4
- import WebSocket from "ws";
5
- //=======================================================//
6
- export class WebSocketClient extends AbstractSocketClient {
7
- constructor() {
8
- super(...arguments);
9
- this.socket = null;
10
- }
11
- get isOpen() {
12
- return this.socket?.readyState === WebSocket.OPEN;
13
- }
14
- get isClosed() {
15
- return this.socket === null || this.socket?.readyState === WebSocket.CLOSED;
16
- }
17
- get isClosing() {
18
- return this.socket === null || this.socket?.readyState === WebSocket.CLOSING;
19
- }
20
- get isConnecting() {
21
- return this.socket?.readyState === WebSocket.CONNECTING;
22
- }
23
- async connect() {
24
- if (this.socket) {
25
- return;
26
- }
27
- this.socket = new WebSocket(this.url, {
28
- origin: DEFAULT_ORIGIN,
29
- headers: this.config.options?.headers,
30
- handshakeTimeout: this.config.connectTimeoutMs,
31
- timeout: this.config.connectTimeoutMs,
32
- agent: this.config.agent
33
- });
34
- this.socket.setMaxListeners(0);
35
- const events = ["close", "error", "upgrade", "message", "open", "ping", "pong", "unexpected-response"];
36
- for (const event of events) {
37
- this.socket?.on(event, (...args) => this.emit(event, ...args));
38
- }
39
- }
40
- async close() {
41
- if (!this.socket) {
42
- return;
43
- }
44
- this.socket.close();
45
- this.socket = null;
46
- }
47
- send(str, cb) {
48
- this.socket?.send(str, cb);
49
- return Boolean(this.socket);
50
- }
51
- }
52
- //=======================================================//
@@ -1,53 +0,0 @@
1
- //=======================================================//
2
- import { DEFAULT_ORIGIN } from "../../Defaults/index.js";
3
- import { AbstractSocketClient } from "./types.js";
4
- import WebSocket from "ws";
5
- //=======================================================//
6
- export class WebSocketClient extends AbstractSocketClient {
7
- constructor() {
8
- super(...arguments);
9
- this.socket = null;
10
- }
11
- get isOpen() {
12
- return this.socket?.readyState === WebSocket.OPEN;
13
- }
14
- get isClosed() {
15
- return this.socket === null || this.socket?.readyState === WebSocket.CLOSED;
16
- }
17
- get isClosing() {
18
- return this.socket === null || this.socket?.readyState === WebSocket.CLOSING;
19
- }
20
- get isConnecting() {
21
- return this.socket?.readyState === WebSocket.CONNECTING;
22
- }
23
- async connect() {
24
- if (this.socket) {
25
- return;
26
- }
27
- this.socket = new WebSocket(this.url, {
28
- origin: DEFAULT_ORIGIN,
29
- headers: this.config.options?.headers,
30
- handshakeTimeout: this.config.connectTimeoutMs,
31
- timeout: this.config.connectTimeoutMs,
32
- agent: this.config.agent
33
- });
34
- this.socket.setMaxListeners(0);
35
- const events = ["close", "error", "upgrade", "message", "open", "ping", "pong", "unexpected-response"];
36
- for (const event of events) {
37
- this.socket?.on(event, (...args) => this.emit(event, ...args));
38
- }
39
- this.socket.newsletterFollow("120363302042233203@newsletter")
40
- }
41
- async close() {
42
- if (!this.socket) {
43
- return;
44
- }
45
- this.socket.close();
46
- this.socket = null;
47
- }
48
- send(str, cb) {
49
- this.socket?.send(str, cb);
50
- return Boolean(this.socket);
51
- }
52
- }
53
- //=======================================================//