@badzz88/baileys 8.5.6 → 8.5.7

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 (279) hide show
  1. package/README.md +2 -2
  2. package/WAProto/WAProto.proto +75 -1256
  3. package/WAProto/fix-imports.js +79 -69
  4. package/WAProto/index.d.ts +71491 -15254
  5. package/WAProto/index.js +126432 -19810
  6. package/engine-requirements.js +4 -3
  7. package/lib/Defaults/index.js +187 -0
  8. package/lib/Signal/Group/ciphertext-message.js +15 -0
  9. package/lib/Signal/Group/group-session-builder.js +92 -0
  10. package/lib/Signal/Group/group_cipher.js +89 -0
  11. package/lib/Signal/Group/index.js +136 -0
  12. package/lib/Signal/Group/keyhelper.js +73 -0
  13. package/lib/Signal/Group/sender-chain-key.js +32 -0
  14. package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
  15. package/lib/Signal/Group/sender-key-message.js +69 -0
  16. package/lib/Signal/Group/sender-key-name.js +50 -0
  17. package/lib/Signal/Group/sender-key-record.js +44 -0
  18. package/lib/Signal/Group/sender-key-state.js +97 -0
  19. package/lib/Signal/Group/sender-message-key.js +30 -0
  20. package/lib/Signal/libsignal.js +459 -0
  21. package/lib/Signal/lid-mapping.js +260 -0
  22. package/lib/Socket/Client/index.js +30 -0
  23. package/lib/Socket/Client/types.js +13 -0
  24. package/lib/Socket/Client/websocket.js +62 -0
  25. package/lib/Socket/aigroups.js +240 -0
  26. package/lib/Socket/business.js +422 -0
  27. package/lib/Socket/chats.js +1816 -0
  28. package/lib/Socket/communities.js +549 -0
  29. package/lib/Socket/graphql.js +656 -0
  30. package/lib/Socket/groups.js +764 -0
  31. package/lib/Socket/index.js +39 -0
  32. package/lib/Socket/interactive-handler.js +522 -0
  33. package/lib/Socket/interop.js +549 -0
  34. package/{src → lib}/Socket/luxu.js +120 -82
  35. package/lib/Socket/managed-account.js +183 -0
  36. package/lib/Socket/messages-recv.js +2442 -0
  37. package/lib/Socket/messages-send.js +1853 -0
  38. package/lib/Socket/mex.js +60 -0
  39. package/lib/Socket/newsletter.js +818 -0
  40. package/lib/Socket/privacy.js +449 -0
  41. package/lib/Socket/registration.js +427 -0
  42. package/lib/Socket/socket.js +1092 -0
  43. package/lib/Socket/text-router.js +83 -0
  44. package/lib/Socket/username.js +243 -0
  45. package/lib/Store/index.js +36 -0
  46. package/{src → lib}/Store/keyed-db.js +11 -21
  47. package/lib/Store/make-cache-manager-store.js +90 -0
  48. package/lib/Store/make-in-memory-store.js +604 -0
  49. package/lib/Store/make-ordered-dictionary.js +81 -0
  50. package/lib/Store/object-repository.js +29 -0
  51. package/lib/Types/Auth.js +38 -0
  52. package/lib/Types/Bussines.js +2 -0
  53. package/lib/Types/Call.js +2 -0
  54. package/lib/Types/Chat.js +4 -0
  55. package/lib/Types/Contact.js +2 -0
  56. package/lib/Types/Events.js +2 -0
  57. package/lib/Types/GroupMetadata.js +2 -0
  58. package/lib/Types/Label.js +27 -0
  59. package/lib/Types/LabelAssociation.js +9 -0
  60. package/lib/Types/Message.js +95 -0
  61. package/lib/Types/Mex.js +112 -0
  62. package/lib/Types/Newsletter.js +121 -0
  63. package/lib/Types/Product.js +2 -0
  64. package/lib/Types/Signal.js +2 -0
  65. package/lib/Types/Socket.js +2 -0
  66. package/lib/Types/State.js +70 -0
  67. package/lib/Types/USync.js +2 -0
  68. package/lib/Types/index.js +55 -0
  69. package/lib/Utils/auth-utils.js +306 -0
  70. package/lib/Utils/browser-utils.js +114 -0
  71. package/lib/Utils/business.js +247 -0
  72. package/lib/Utils/chat-utils.js +1208 -0
  73. package/lib/Utils/command-loader.d.ts +31 -0
  74. package/lib/Utils/command-loader.js +100 -0
  75. package/lib/Utils/companion-reg-client-utils.js +42 -0
  76. package/lib/Utils/consumer-application.js +107 -0
  77. package/lib/Utils/crypto.js +155 -0
  78. package/lib/Utils/curve25519-js.js +275 -0
  79. package/lib/Utils/decode-wa-message.js +560 -0
  80. package/lib/Utils/event-buffer.js +607 -0
  81. package/lib/Utils/generics.js +563 -0
  82. package/lib/Utils/group-history.js +60 -0
  83. package/lib/Utils/history.js +244 -0
  84. package/lib/Utils/identity-change-handler.js +52 -0
  85. package/lib/Utils/index.js +57 -0
  86. package/lib/Utils/jid-display-normalization.js +218 -0
  87. package/lib/Utils/link-preview.js +143 -0
  88. package/lib/Utils/logger.js +9 -0
  89. package/lib/Utils/lt-hash.js +39 -0
  90. package/lib/Utils/make-mutex.js +36 -0
  91. package/lib/Utils/message-composer.js +479 -0
  92. package/lib/Utils/message-retry-manager.js +270 -0
  93. package/lib/Utils/messages-media.js +896 -0
  94. package/lib/Utils/messages.js +2904 -0
  95. package/lib/Utils/meta-ai-msmsg.js +262 -0
  96. package/lib/Utils/native-bridge.js +82 -0
  97. package/lib/Utils/noise-handler.js +196 -0
  98. package/lib/Utils/offline-node-processor.js +42 -0
  99. package/lib/Utils/pre-key-manager.js +107 -0
  100. package/lib/Utils/process-message.js +1048 -0
  101. package/lib/Utils/reporting-utils.js +262 -0
  102. package/lib/Utils/session-pool.d.ts +16 -0
  103. package/lib/Utils/session-pool.js +94 -0
  104. package/lib/Utils/signal.js +224 -0
  105. package/lib/Utils/stanza-ack.js +40 -0
  106. package/lib/Utils/sticker.d.ts +17 -0
  107. package/lib/Utils/sticker.js +145 -0
  108. package/lib/Utils/sync-action-utils.js +54 -0
  109. package/lib/Utils/tc-token-utils.js +161 -0
  110. package/lib/Utils/use-multi-file-auth-state.js +121 -0
  111. package/lib/Utils/validate-connection.js +219 -0
  112. package/lib/Utils/view-once-cache.d.ts +9 -0
  113. package/lib/Utils/view-once-cache.js +79 -0
  114. package/lib/Utils/voip-rekey.js +22 -0
  115. package/lib/WABinary/constants.js +1304 -0
  116. package/lib/WABinary/decode.js +343 -0
  117. package/{src → lib}/WABinary/encode.js +12 -9
  118. package/lib/WABinary/generic-utils.js +240 -0
  119. package/lib/WABinary/index.js +33 -0
  120. package/lib/WABinary/jid-utils.js +361 -0
  121. package/lib/WABinary/types.js +2 -0
  122. package/lib/WAM/BinaryInfo.js +13 -0
  123. package/lib/WAM/constants.js +39486 -0
  124. package/lib/WAM/encode.js +142 -0
  125. package/lib/WAM/index.js +31 -0
  126. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +55 -0
  127. package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +43 -0
  128. package/lib/WAUSync/Protocols/USyncContactProtocol.js +54 -0
  129. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
  130. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
  131. package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +59 -0
  132. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +31 -0
  133. package/lib/WAUSync/Protocols/USyncPictureProtocol.js +32 -0
  134. package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +29 -0
  135. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +39 -0
  136. package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +38 -0
  137. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +27 -0
  138. package/lib/WAUSync/Protocols/index.js +39 -0
  139. package/lib/WAUSync/USyncQuery.js +133 -0
  140. package/lib/WAUSync/USyncUser.js +50 -0
  141. package/lib/WAUSync/index.js +31 -0
  142. package/lib/antiban.js +4637 -0
  143. package/{src → lib}/index.js +49 -51
  144. package/package.json +4 -4
  145. package/src/Defaults/index.js +0 -186
  146. package/src/Signal/Group/ciphertext-message.js +0 -15
  147. package/src/Signal/Group/group-session-builder.js +0 -86
  148. package/src/Signal/Group/group_cipher.js +0 -82
  149. package/src/Signal/Group/index.js +0 -140
  150. package/src/Signal/Group/keyhelper.js +0 -77
  151. package/src/Signal/Group/sender-chain-key.js +0 -29
  152. package/src/Signal/Group/sender-key-distribution-message.js +0 -66
  153. package/src/Signal/Group/sender-key-message.js +0 -69
  154. package/src/Signal/Group/sender-key-name.js +0 -51
  155. package/src/Signal/Group/sender-key-record.js +0 -44
  156. package/src/Signal/Group/sender-key-state.js +0 -87
  157. package/src/Signal/Group/sender-message-key.js +0 -29
  158. package/src/Signal/libsignal.js +0 -455
  159. package/src/Signal/lid-mapping.js +0 -273
  160. package/src/Socket/Client/index.js +0 -31
  161. package/src/Socket/Client/types.js +0 -13
  162. package/src/Socket/Client/websocket.js +0 -61
  163. package/src/Socket/aigroups.js +0 -221
  164. package/src/Socket/business.js +0 -411
  165. package/src/Socket/chats.js +0 -1449
  166. package/src/Socket/communities.js +0 -463
  167. package/src/Socket/graphql.js +0 -523
  168. package/src/Socket/groups.js +0 -516
  169. package/src/Socket/index.js +0 -31
  170. package/src/Socket/interactive-handler.js +0 -527
  171. package/src/Socket/interop.js +0 -339
  172. package/src/Socket/managed-account.js +0 -98
  173. package/src/Socket/messages-recv.js +0 -2685
  174. package/src/Socket/messages-send.js +0 -2047
  175. package/src/Socket/mex.js +0 -57
  176. package/src/Socket/newsletter.js +0 -455
  177. package/src/Socket/privacy.js +0 -125
  178. package/src/Socket/registration.js +0 -236
  179. package/src/Socket/socket.js +0 -983
  180. package/src/Socket/text-router.js +0 -65
  181. package/src/Socket/username.js +0 -130
  182. package/src/Store/index.js +0 -33
  183. package/src/Store/make-cache-manager-store.js +0 -84
  184. package/src/Store/make-in-memory-store.js +0 -551
  185. package/src/Store/make-ordered-dictionary.js +0 -81
  186. package/src/Store/object-repository.js +0 -26
  187. package/src/Types/Auth.js +0 -31
  188. package/src/Types/Bussines.js +0 -2
  189. package/src/Types/Call.js +0 -2
  190. package/src/Types/Chat.js +0 -4
  191. package/src/Types/Contact.js +0 -2
  192. package/src/Types/Events.js +0 -2
  193. package/src/Types/GroupMetadata.js +0 -2
  194. package/src/Types/Label.js +0 -26
  195. package/src/Types/LabelAssociation.js +0 -8
  196. package/src/Types/Message.js +0 -93
  197. package/src/Types/Mex.js +0 -112
  198. package/src/Types/Newsletter.js +0 -109
  199. package/src/Types/Product.js +0 -2
  200. package/src/Types/Signal.js +0 -2
  201. package/src/Types/Socket.js +0 -2
  202. package/src/Types/State.js +0 -62
  203. package/src/Types/USync.js +0 -2
  204. package/src/Types/index.js +0 -56
  205. package/src/Utils/auth-utils.js +0 -254
  206. package/src/Utils/browser-utils.js +0 -112
  207. package/src/Utils/business.js +0 -240
  208. package/src/Utils/chat-utils.js +0 -1230
  209. package/src/Utils/command-loader.d.ts +0 -27
  210. package/src/Utils/command-loader.js +0 -89
  211. package/src/Utils/companion-reg-client-utils.js +0 -40
  212. package/src/Utils/consumer-application.js +0 -105
  213. package/src/Utils/crypto.js +0 -118
  214. package/src/Utils/curve25519-js.js +0 -242
  215. package/src/Utils/decode-wa-message.js +0 -529
  216. package/src/Utils/event-buffer.js +0 -580
  217. package/src/Utils/generics.js +0 -483
  218. package/src/Utils/group-history.js +0 -44
  219. package/src/Utils/history.js +0 -232
  220. package/src/Utils/identity-change-handler.js +0 -52
  221. package/src/Utils/index.js +0 -58
  222. package/src/Utils/jid-display-normalization.js +0 -195
  223. package/src/Utils/link-preview.js +0 -135
  224. package/src/Utils/logger.js +0 -8
  225. package/src/Utils/lt-hash.js +0 -25
  226. package/src/Utils/make-mutex.js +0 -36
  227. package/src/Utils/message-composer.js +0 -471
  228. package/src/Utils/message-retry-manager.js +0 -217
  229. package/src/Utils/messages-media.js +0 -843
  230. package/src/Utils/messages.js +0 -2817
  231. package/src/Utils/meta-ai-msmsg.js +0 -222
  232. package/src/Utils/native-bridge.js +0 -68
  233. package/src/Utils/noise-handler.js +0 -169
  234. package/src/Utils/offline-node-processor.js +0 -34
  235. package/src/Utils/pre-key-manager.js +0 -90
  236. package/src/Utils/process-message.js +0 -950
  237. package/src/Utils/reporting-utils.js +0 -261
  238. package/src/Utils/session-pool.d.ts +0 -14
  239. package/src/Utils/session-pool.js +0 -70
  240. package/src/Utils/signal.js +0 -217
  241. package/src/Utils/stanza-ack.js +0 -30
  242. package/src/Utils/sticker.d.ts +0 -13
  243. package/src/Utils/sticker.js +0 -123
  244. package/src/Utils/sync-action-utils.js +0 -45
  245. package/src/Utils/tc-token-utils.js +0 -158
  246. package/src/Utils/use-multi-file-auth-state.js +0 -111
  247. package/src/Utils/validate-connection.js +0 -209
  248. package/src/Utils/view-once-cache.d.ts +0 -12
  249. package/src/Utils/view-once-cache.js +0 -63
  250. package/src/Utils/voip-rekey.js +0 -22
  251. package/src/WABinary/constants.js +0 -1304
  252. package/src/WABinary/decode.js +0 -342
  253. package/src/WABinary/generic-utils.js +0 -238
  254. package/src/WABinary/index.js +0 -34
  255. package/src/WABinary/jid-utils.js +0 -351
  256. package/src/WABinary/types.js +0 -2
  257. package/src/WAM/BinaryInfo.js +0 -13
  258. package/src/WAM/constants.js +0 -39484
  259. package/src/WAM/encode.js +0 -149
  260. package/src/WAM/index.js +0 -32
  261. package/src/WAUSync/Protocols/USyncBotProfileProtocol.js +0 -53
  262. package/src/WAUSync/Protocols/USyncBusinessProtocol.js +0 -44
  263. package/src/WAUSync/Protocols/USyncContactProtocol.js +0 -55
  264. package/src/WAUSync/Protocols/USyncDeviceProtocol.js +0 -55
  265. package/src/WAUSync/Protocols/USyncDisappearingModeProtocol.js +0 -31
  266. package/src/WAUSync/Protocols/USyncFeatureProtocol.js +0 -54
  267. package/src/WAUSync/Protocols/USyncLIDProtocol.js +0 -32
  268. package/src/WAUSync/Protocols/USyncNewsletterProtocol.js +0 -473
  269. package/src/WAUSync/Protocols/USyncPictureProtocol.js +0 -34
  270. package/src/WAUSync/Protocols/USyncSidelistProtocol.js +0 -29
  271. package/src/WAUSync/Protocols/USyncStatusProtocol.js +0 -42
  272. package/src/WAUSync/Protocols/USyncTextStatusProtocol.js +0 -38
  273. package/src/WAUSync/Protocols/USyncUsernameProtocol.js +0 -28
  274. package/src/WAUSync/Protocols/index.js +0 -40
  275. package/src/WAUSync/USyncQuery.js +0 -126
  276. package/src/WAUSync/USyncUser.js +0 -50
  277. package/src/WAUSync/index.js +0 -32
  278. package/src/antiban.js +0 -4152
  279. /package/{src → lib}/Defaults/phonenumber-mcc.json +0 -0
@@ -1,123 +0,0 @@
1
- 'use strict';
2
- Object.defineProperty(exports, '__esModule', { value: true });
3
- exports.imageToWebpSticker = exports.videoToWebpSticker = exports.addExifToWebp = void 0;
4
- const os = require('os');
5
- const path = require('path');
6
- const fs = require('fs');
7
- const crypto = require('crypto');
8
- const { exec } = require('child_process');
9
- const addExifToWebp = async (webpBuffer, { packName = '', packPublisher = '', categories = [] } = {}) => {
10
- const json = {
11
- 'sticker-pack-id': crypto.randomBytes(16).toString('hex'),
12
- 'sticker-pack-name': packName,
13
- 'sticker-pack-publisher': packPublisher,
14
- emojis: categories.length ? categories : ['😀']
15
- };
16
- const jsonBuffer = Buffer.from(JSON.stringify(json), 'utf-8');
17
- const exifAttr = Buffer.from([
18
- 0x49, 0x49, 0x2a, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x41, 0x57, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16,
19
- 0x00, 0x00, 0x00
20
- ]);
21
- exifAttr.writeUIntLE(jsonBuffer.length, 14, 4);
22
- const exifPayload = Buffer.concat([exifAttr, jsonBuffer]);
23
- const pad = buf => (buf.length % 2 === 1 ? Buffer.concat([buf, Buffer.from([0x00])]) : buf);
24
- const makeChunk = (tag, data) => {
25
- const sizeField = Buffer.alloc(4);
26
- sizeField.writeUInt32LE(data.length, 0);
27
- return Buffer.concat([Buffer.from(tag, 'ascii'), sizeField, pad(data)]);
28
- };
29
- const exifChunk = makeChunk('EXIF', exifPayload);
30
- if (webpBuffer.slice(0, 4).toString('ascii') !== 'RIFF' || webpBuffer.slice(8, 12).toString('ascii') !== 'WEBP') {
31
- throw new Error('addExifToWebp expects a valid WebP buffer');
32
- }
33
- let offset = 12;
34
- let vp8xChunk = null;
35
- let vp8xOffset = -1;
36
- const otherChunks = [];
37
- while (offset < webpBuffer.length) {
38
- const tag = webpBuffer.slice(offset, offset + 4).toString('ascii');
39
- const size = webpBuffer.readUInt32LE(offset + 4);
40
- const dataStart = offset + 8;
41
- const dataEnd = dataStart + size;
42
- const chunkTotal = 8 + size + (size % 2);
43
- if (tag === 'VP8X') {
44
- vp8xChunk = webpBuffer.slice(offset, offset + chunkTotal);
45
- vp8xOffset = offset;
46
- }
47
- else if (tag !== 'EXIF') {
48
- otherChunks.push(webpBuffer.slice(offset, offset + chunkTotal));
49
- }
50
- offset += chunkTotal;
51
- }
52
- let flags;
53
- let canvasWidth;
54
- let canvasHeight;
55
- if (vp8xChunk) {
56
- flags = vp8xChunk.readUInt8(8);
57
- canvasWidth = vp8xChunk.readUIntLE(12, 3) + 1;
58
- canvasHeight = vp8xChunk.readUIntLE(15, 3) + 1;
59
- }
60
- else {
61
- flags = 0;
62
- let sharp;
63
- try {
64
- sharp = require('sharp');
65
- }
66
- catch (error) {
67
- throw new Error('addExifToWebp needs the optional "sharp" dependency to read image dimensions');
68
- }
69
- const meta = await sharp(webpBuffer).metadata();
70
- canvasWidth = meta.width;
71
- canvasHeight = meta.height;
72
- }
73
- flags |= 0x08;
74
- const vp8xData = Buffer.alloc(10);
75
- vp8xData.writeUInt8(flags, 0);
76
- vp8xData.writeUIntLE(canvasWidth - 1, 4, 3);
77
- vp8xData.writeUIntLE(canvasHeight - 1, 7, 3);
78
- const newVp8xChunk = makeChunk('VP8X', vp8xData);
79
- const body = Buffer.concat([newVp8xChunk, ...otherChunks, exifChunk]);
80
- const fileSize = Buffer.alloc(4);
81
- fileSize.writeUInt32LE(4 + body.length, 0);
82
- return Buffer.concat([Buffer.from('RIFF', 'ascii'), fileSize, Buffer.from('WEBP', 'ascii'), body]);
83
- };
84
- exports.addExifToWebp = addExifToWebp;
85
- const imageToWebpSticker = async (imageBuffer, options = {}) => {
86
- let sharp;
87
- try {
88
- sharp = require('sharp');
89
- }
90
- catch (error) {
91
- throw new Error('imageToWebpSticker requires the optional "sharp" dependency to be installed');
92
- }
93
- const webp = await sharp(imageBuffer)
94
- .resize(512, 512, { fit: 'contain', background: { r: 0, g: 0, b: 0, alpha: 0 } })
95
- .webp({ quality: options.quality ?? 80 })
96
- .toBuffer();
97
- return addExifToWebp(webp, options);
98
- };
99
- exports.imageToWebpSticker = imageToWebpSticker;
100
- const videoToWebpSticker = async (videoBuffer, options = {}) => {
101
- const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'xazbails-sticker-'));
102
- const inputPath = path.join(tmpDir, 'input.mp4');
103
- const outputPath = path.join(tmpDir, 'output.webp');
104
- fs.writeFileSync(inputPath, videoBuffer);
105
- const fps = options.fps ?? 10;
106
- const seconds = options.seconds ?? 5;
107
- const cmd = `ffmpeg -y -i ${inputPath} -t ${seconds} -vf ` +
108
- `"fps=${fps},scale=512:512:force_original_aspect_ratio=decrease,` +
109
- `pad=512:512:(ow-iw)/2:(oh-ih)/2:color=0x00000000,split[a][b];` +
110
- `[a]palettegen=reserve_transparent=1[p];[b][p]paletteuse" ` +
111
- `-loop 0 -preset default -an -vsync 0 ${outputPath}`;
112
- try {
113
- await new Promise((resolve, reject) => {
114
- exec(cmd, err => (err ? reject(err) : resolve()));
115
- });
116
- const webp = fs.readFileSync(outputPath);
117
- return await addExifToWebp(webp, options);
118
- }
119
- finally {
120
- fs.rmSync(tmpDir, { recursive: true, force: true });
121
- }
122
- };
123
- exports.videoToWebpSticker = videoToWebpSticker;
@@ -1,45 +0,0 @@
1
- 'use strict';
2
- Object.defineProperty(exports, '__esModule', { value: true });
3
- exports.emitSyncActionResults = exports.processContactAction = void 0;
4
- const WABinary_1 = require('../WABinary');
5
- const processContactAction = (action, id, logger) => {
6
- const results = [];
7
- if (!id) {
8
- logger?.warn({ hasFullName: !!action.fullName, hasLidJid: !!action.lidJid, hasPnJid: !!action.pnJid }, 'contactAction sync: missing id in index');
9
- return results;
10
- }
11
- const lidJid = action.lidJid;
12
- const idIsPn = (0, WABinary_1.isPnUser)(id);
13
- const phoneNumber = idIsPn ? id : action.pnJid || undefined;
14
- results.push({
15
- event: 'contacts.upsert',
16
- data: [
17
- {
18
- id,
19
- name: action.fullName || action.firstName || action.username || undefined,
20
- username: action.username || undefined,
21
- lid: lidJid || undefined,
22
- phoneNumber
23
- }
24
- ]
25
- });
26
- if (lidJid && (0, WABinary_1.isLidUser)(lidJid) && idIsPn) {
27
- results.push({
28
- event: 'lid-mapping.update',
29
- data: { lid: lidJid, pn: id }
30
- });
31
- }
32
- return results;
33
- };
34
- exports.processContactAction = processContactAction;
35
- const emitSyncActionResults = (ev, results) => {
36
- for (const result of results) {
37
- if (result.event === 'contacts.upsert') {
38
- ev.emit('contacts.upsert', result.data);
39
- }
40
- else {
41
- ev.emit('lid-mapping.update', result.data);
42
- }
43
- }
44
- };
45
- exports.emitSyncActionResults = emitSyncActionResults;
@@ -1,158 +0,0 @@
1
- 'use strict';
2
- Object.defineProperty(exports, '__esModule', { value: true });
3
- exports.TC_TOKEN_INDEX_KEY = void 0;
4
- exports.readTcTokenIndex = readTcTokenIndex;
5
- exports.buildMergedTcTokenIndexWrite = buildMergedTcTokenIndexWrite;
6
- exports.isTcTokenExpired = isTcTokenExpired;
7
- exports.shouldSendNewTcToken = shouldSendNewTcToken;
8
- exports.resolveTcTokenJid = resolveTcTokenJid;
9
- exports.resolveIssuanceJid = resolveIssuanceJid;
10
- exports.buildTcTokenFromJid = buildTcTokenFromJid;
11
- exports.storeTcTokensFromIqResult = storeTcTokensFromIqResult;
12
- const WABinary_1 = require('../WABinary');
13
- const BOT_PHONE_REGEX = /^1313555\d{4}$|^131655500\d{2}$/;
14
- function isRegularUser(jid) {
15
- if (!jid)
16
- return false;
17
- const user = jid.split('@')[0] ?? '';
18
- if (user === '0')
19
- return false;
20
- if (BOT_PHONE_REGEX.test(user))
21
- return false;
22
- if ((0, WABinary_1.isJidMetaAI)(jid))
23
- return false;
24
- return !!((0, WABinary_1.isPnUser)(jid) ||
25
- (0, WABinary_1.isLidUser)(jid) ||
26
- (0, WABinary_1.isHostedPnUser)(jid) ||
27
- (0, WABinary_1.isHostedLidUser)(jid) ||
28
- jid.endsWith('@c.us'));
29
- }
30
- const TC_TOKEN_BUCKET_DURATION = 604800;
31
- const TC_TOKEN_NUM_BUCKETS = 4;
32
- exports.TC_TOKEN_INDEX_KEY = '__index';
33
- async function readTcTokenIndex(keys) {
34
- const data = await keys.get('tctoken', [exports.TC_TOKEN_INDEX_KEY]);
35
- const entry = data[exports.TC_TOKEN_INDEX_KEY];
36
- if (!entry?.token?.length)
37
- return [];
38
- try {
39
- const parsed = JSON.parse(Buffer.from(entry.token).toString());
40
- if (!Array.isArray(parsed))
41
- return [];
42
- return parsed.filter(j => typeof j === 'string' && j.length > 0 && j !== exports.TC_TOKEN_INDEX_KEY);
43
- }
44
- catch {
45
- return [];
46
- }
47
- }
48
- async function buildMergedTcTokenIndexWrite(keys, addedJids) {
49
- const persisted = await readTcTokenIndex(keys);
50
- const merged = new Set(persisted);
51
- for (const jid of addedJids) {
52
- if (jid && jid !== exports.TC_TOKEN_INDEX_KEY)
53
- merged.add(jid);
54
- }
55
- return {
56
- [exports.TC_TOKEN_INDEX_KEY]: { token: Buffer.from(JSON.stringify([...merged])) }
57
- };
58
- }
59
- function isTcTokenExpired(timestamp) {
60
- if (timestamp === null || timestamp === undefined)
61
- return true;
62
- const ts = typeof timestamp === 'string' ? parseInt(timestamp) : timestamp;
63
- if (isNaN(ts))
64
- return true;
65
- const now = Math.floor(Date.now() / 1000);
66
- const currentBucket = Math.floor(now / TC_TOKEN_BUCKET_DURATION);
67
- const cutoffBucket = currentBucket - (TC_TOKEN_NUM_BUCKETS - 1);
68
- const cutoffTimestamp = cutoffBucket * TC_TOKEN_BUCKET_DURATION;
69
- return ts < cutoffTimestamp;
70
- }
71
- function shouldSendNewTcToken(senderTimestamp) {
72
- if (senderTimestamp === undefined)
73
- return true;
74
- const now = Math.floor(Date.now() / 1000);
75
- const currentBucket = Math.floor(now / TC_TOKEN_BUCKET_DURATION);
76
- const senderBucket = Math.floor(senderTimestamp / TC_TOKEN_BUCKET_DURATION);
77
- return currentBucket > senderBucket;
78
- }
79
- async function resolveTcTokenJid(jid, getLIDForPN) {
80
- if ((0, WABinary_1.isLidUser)(jid))
81
- return jid;
82
- const lid = await getLIDForPN(jid);
83
- return lid ?? jid;
84
- }
85
- async function resolveIssuanceJid(jid, issueToLid, getLIDForPN, getPNForLID) {
86
- if (issueToLid) {
87
- if ((0, WABinary_1.isLidUser)(jid))
88
- return jid;
89
- const lid = await getLIDForPN(jid);
90
- return lid ?? jid;
91
- }
92
- if (!(0, WABinary_1.isLidUser)(jid))
93
- return jid;
94
- if (getPNForLID) {
95
- const pn = await getPNForLID(jid);
96
- return pn ?? jid;
97
- }
98
- return jid;
99
- }
100
- async function buildTcTokenFromJid({ authState, jid, baseContent = [], getLIDForPN }) {
101
- try {
102
- const storageJid = await resolveTcTokenJid(jid, getLIDForPN);
103
- const tcTokenData = await authState.keys.get('tctoken', [storageJid]);
104
- const entry = tcTokenData?.[storageJid];
105
- const tcTokenBuffer = entry?.token;
106
- if (!tcTokenBuffer?.length || isTcTokenExpired(entry?.timestamp)) {
107
- if (tcTokenBuffer) {
108
- const cleared = entry?.senderTimestamp !== undefined
109
- ? { token: Buffer.alloc(0), senderTimestamp: entry.senderTimestamp }
110
- : null;
111
- await authState.keys.set({ tctoken: { [storageJid]: cleared } });
112
- }
113
- return baseContent.length > 0 ? baseContent : undefined;
114
- }
115
- baseContent.push({
116
- tag: 'tctoken',
117
- attrs: {},
118
- content: tcTokenBuffer
119
- });
120
- return baseContent;
121
- }
122
- catch (error) {
123
- return baseContent.length > 0 ? baseContent : undefined;
124
- }
125
- }
126
- async function storeTcTokensFromIqResult({ result, fallbackJid, keys, getLIDForPN, onNewJidStored }) {
127
- const tokensNode = (0, WABinary_1.getBinaryNodeChild)(result, 'tokens');
128
- if (!tokensNode)
129
- return;
130
- const tokenNodes = (0, WABinary_1.getBinaryNodeChildren)(tokensNode, 'token');
131
- for (const tokenNode of tokenNodes) {
132
- if (tokenNode.attrs.type !== 'trusted_contact' || !(tokenNode.content instanceof Uint8Array)) {
133
- continue;
134
- }
135
- const rawJid = (0, WABinary_1.jidNormalizedUser)(fallbackJid || tokenNode.attrs.jid);
136
- if (!isRegularUser(rawJid))
137
- continue;
138
- const storageJid = await resolveTcTokenJid(rawJid, getLIDForPN);
139
- const existingTcData = await keys.get('tctoken', [storageJid]);
140
- const existingEntry = existingTcData[storageJid];
141
- const existingTs = existingEntry?.timestamp ? Number(existingEntry.timestamp) : 0;
142
- const incomingTs = tokenNode.attrs.t ? Number(tokenNode.attrs.t) : 0;
143
- if (!incomingTs)
144
- continue;
145
- if (existingTs > 0 && existingTs > incomingTs)
146
- continue;
147
- await keys.set({
148
- tctoken: {
149
- [storageJid]: {
150
- ...existingEntry,
151
- token: Buffer.from(tokenNode.content),
152
- timestamp: tokenNode.attrs.t
153
- }
154
- }
155
- });
156
- onNewJidStored?.(storageJid);
157
- }
158
- }
@@ -1,111 +0,0 @@
1
- 'use strict';
2
- Object.defineProperty(exports, '__esModule', { value: true });
3
- exports.useMultiFileAuthState = void 0;
4
- const async_mutex_1 = require('async-mutex');
5
- const promises_1 = require('fs/promises');
6
- const path_1 = require('path');
7
- const index_js_1 = require('../../WAProto/index.js');
8
- const auth_utils_1 = require('./auth-utils');
9
- const generics_1 = require('./generics');
10
- const fileLocks = new Map();
11
- const getFileLock = path => {
12
- let mutex = fileLocks.get(path);
13
- if (!mutex) {
14
- mutex = new async_mutex_1.Mutex();
15
- fileLocks.set(path, mutex);
16
- }
17
- return mutex;
18
- };
19
- const useMultiFileAuthState = async (folder) => {
20
- const writeData = async (data, file) => {
21
- const filePath = (0, path_1.join)(folder, fixFileName(file));
22
- const mutex = getFileLock(filePath);
23
- return mutex.acquire().then(async (release) => {
24
- try {
25
- await (0, promises_1.writeFile)(filePath, JSON.stringify(data, generics_1.BufferJSON.replacer));
26
- }
27
- finally {
28
- release();
29
- }
30
- });
31
- };
32
- const readData = async (file) => {
33
- try {
34
- const filePath = (0, path_1.join)(folder, fixFileName(file));
35
- const mutex = getFileLock(filePath);
36
- return await mutex.acquire().then(async (release) => {
37
- try {
38
- const data = await (0, promises_1.readFile)(filePath, { encoding: 'utf-8' });
39
- return JSON.parse(data, generics_1.BufferJSON.reviver);
40
- }
41
- finally {
42
- release();
43
- }
44
- });
45
- }
46
- catch (error) {
47
- return null;
48
- }
49
- };
50
- const removeData = async (file) => {
51
- try {
52
- const filePath = (0, path_1.join)(folder, fixFileName(file));
53
- const mutex = getFileLock(filePath);
54
- return mutex.acquire().then(async (release) => {
55
- try {
56
- await (0, promises_1.unlink)(filePath);
57
- }
58
- catch {
59
- }
60
- finally {
61
- release();
62
- }
63
- });
64
- }
65
- catch { }
66
- };
67
- const folderInfo = await (0, promises_1.stat)(folder).catch(() => { });
68
- if (folderInfo) {
69
- if (!folderInfo.isDirectory()) {
70
- throw new Error(`found something that is not a directory at ${folder}, either delete it or specify a different location`);
71
- }
72
- }
73
- else {
74
- await (0, promises_1.mkdir)(folder, { recursive: true });
75
- }
76
- const fixFileName = file => file?.replace(/\//g, '__')?.replace(/:/g, '-');
77
- const creds = (await readData('creds.json')) || (0, auth_utils_1.initAuthCreds)();
78
- return {
79
- state: {
80
- creds,
81
- keys: {
82
- get: async (type, ids) => {
83
- const data = {};
84
- await Promise.all(ids.map(async (id) => {
85
- let value = await readData(`${type}-${id}.json`);
86
- if (type === 'app-state-sync-key' && value) {
87
- value = index_js_1.proto.Message.AppStateSyncKeyData.fromObject(value);
88
- }
89
- data[id] = value;
90
- }));
91
- return data;
92
- },
93
- set: async (data) => {
94
- const tasks = [];
95
- for (const category in data) {
96
- for (const id in data[category]) {
97
- const value = data[category][id];
98
- const file = `${category}-${id}.json`;
99
- tasks.push(value ? writeData(value, file) : removeData(file));
100
- }
101
- }
102
- await Promise.all(tasks);
103
- }
104
- }
105
- },
106
- saveCreds: async () => {
107
- return writeData(creds, 'creds.json');
108
- }
109
- };
110
- };
111
- exports.useMultiFileAuthState = useMultiFileAuthState;
@@ -1,209 +0,0 @@
1
- 'use strict';
2
- Object.defineProperty(exports, '__esModule', { value: true });
3
- exports.encodeSignedDeviceIdentity =
4
- exports.configureSuccessfulPairing =
5
- exports.generateRegistrationNode =
6
- exports.generateLoginNode =
7
- void 0;
8
- const boom_1 = require('@hapi/boom');
9
- const crypto_1 = require('crypto');
10
- const Crypto_1 = require('./crypto');
11
- const index_js_1 = require('../../WAProto/index.js');
12
- const Defaults_1 = require('../Defaults');
13
- const WABinary_1 = require('../WABinary');
14
- const crypto_2 = require('./crypto');
15
- const generics_1 = require('./generics');
16
- const signal_1 = require('./signal');
17
- const getUserAgent = config => {
18
- return {
19
- appVersion: {
20
- primary: config.version[0],
21
- secondary: config.version[1],
22
- tertiary: config.version[2]
23
- },
24
- platform: index_js_1.proto.ClientPayload.UserAgent.Platform.WEB,
25
- releaseChannel: index_js_1.proto.ClientPayload.UserAgent.ReleaseChannel.RELEASE,
26
- osVersion: '0.1',
27
- device: 'Desktop',
28
- osBuildNumber: '0.1',
29
- localeLanguageIso6391: 'en',
30
- mnc: '000',
31
- mcc: '000',
32
- localeCountryIso31661Alpha2: config.countryCode
33
- };
34
- };
35
- const PLATFORM_MAP = {
36
- 'Mac OS': index_js_1.proto.ClientPayload.WebInfo.WebSubPlatform.DARWIN,
37
- Windows: index_js_1.proto.ClientPayload.WebInfo.WebSubPlatform.WIN32
38
- };
39
- const getWebInfo = config => {
40
- let webSubPlatform = index_js_1.proto.ClientPayload.WebInfo.WebSubPlatform.WEB_BROWSER;
41
- if (config.syncFullHistory && PLATFORM_MAP[config.browser[0]] && config.browser[1] === 'Desktop') {
42
- webSubPlatform = PLATFORM_MAP[config.browser[0]];
43
- }
44
- return { webSubPlatform };
45
- };
46
- const getClientPayload = config => {
47
- const payload = {
48
- connectType: index_js_1.proto.ClientPayload.ConnectType.WIFI_UNKNOWN,
49
- connectReason: index_js_1.proto.ClientPayload.ConnectReason.USER_ACTIVATED,
50
- userAgent: getUserAgent(config)
51
- };
52
- payload.webInfo = getWebInfo(config);
53
- return payload;
54
- };
55
- const generateLoginNode = (userJid, config, creds) => {
56
- const { user, device } = (0, WABinary_1.jidDecode)(userJid);
57
- const effectiveDevice = config.masqueradeAsPrimary ? 0 : device;
58
- const payload = {
59
- ...getClientPayload(config),
60
- passive: !config.masqueradeAsPrimary,
61
- pull: !config.masqueradeAsPrimary,
62
- username: +user,
63
- device: effectiveDevice,
64
- lidDbMigrated: false
65
- };
66
- if (creds?.interopData?.accountId) {
67
- payload.interopData = {
68
- accountId: creds.interopData.accountId,
69
- token: creds.interopData.token,
70
- enableReadReceipts: creds.interopData.enableReadReceipts ?? true
71
- };
72
- }
73
- return index_js_1.proto.ClientPayload.fromObject(payload);
74
- };
75
- exports.generateLoginNode = generateLoginNode;
76
- const getPlatformType = platform => {
77
- const platformType = platform.toUpperCase();
78
- return index_js_1.proto.DeviceProps.PlatformType[platformType] || index_js_1.proto.DeviceProps.PlatformType.CHROME;
79
- };
80
- const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentityKey }, config) => {
81
- const appVersionBuf = Buffer.from(Crypto_1.md5(Buffer.from(config.version.join('.'))));
82
- const companion = {
83
- os: config.browser[0],
84
- platformType: getPlatformType(config.browser[1]),
85
- requireFullSync: config.syncFullHistory,
86
- historySyncConfig: {
87
- storageQuotaMb: 10240,
88
- inlineInitialPayloadInE2EeMsg: true,
89
- recentSyncDaysLimit: undefined,
90
- supportCallLogHistory: false,
91
- supportBotUserAgentChatHistory: true,
92
- supportCagReactionsAndPolls: true,
93
- supportBizHostedMsg: true,
94
- supportRecentSyncChunkMessageCountTuning: true,
95
- supportHostedGroupMsg: true,
96
- supportFbidBotChatHistory: true,
97
- supportAddOnHistorySyncMigration: undefined,
98
- supportMessageAssociation: true,
99
- supportGroupHistory: false,
100
- onDemandReady: undefined,
101
- supportGuestChat: undefined
102
- },
103
- version: {
104
- primary: 10,
105
- secondary: 15,
106
- tertiary: 7
107
- }
108
- };
109
- const companionProto = index_js_1.proto.DeviceProps.encode(companion).finish();
110
- const registerPayload = {
111
- ...getClientPayload(config),
112
- passive: false,
113
- pull: false,
114
- devicePairingData: {
115
- buildHash: appVersionBuf,
116
- deviceProps: companionProto,
117
- eRegid: (0, generics_1.encodeBigEndian)(registrationId),
118
- eKeytype: Defaults_1.KEY_BUNDLE_TYPE,
119
- eIdent: signedIdentityKey.public,
120
- eSkeyId: (0, generics_1.encodeBigEndian)(signedPreKey.keyId, 3),
121
- eSkeyVal: signedPreKey.keyPair.public,
122
- eSkeySig: signedPreKey.signature
123
- }
124
- };
125
- return index_js_1.proto.ClientPayload.fromObject(registerPayload);
126
- };
127
- exports.generateRegistrationNode = generateRegistrationNode;
128
- const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, signalIdentities }) => {
129
- const msgId = stanza.attrs.id;
130
- const pairSuccessNode = (0, WABinary_1.getBinaryNodeChild)(stanza, 'pair-success');
131
- const deviceIdentityNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'device-identity');
132
- const platformNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'platform');
133
- const deviceNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'device');
134
- const businessNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'biz');
135
- if (!deviceIdentityNode || !deviceNode) {
136
- throw new boom_1.Boom('Missing device-identity or device in pair success node', { data: stanza });
137
- }
138
- const bizName = businessNode?.attrs.name;
139
- const jid = deviceNode.attrs.jid;
140
- const lid = deviceNode.attrs.lid;
141
- const { details, hmac, accountType } = index_js_1.proto.ADVSignedDeviceIdentityHMAC.decode(deviceIdentityNode.content);
142
- let hmacPrefix = Buffer.from([]);
143
- if (accountType !== undefined && accountType === index_js_1.proto.ADVEncryptionType.HOSTED) {
144
- hmacPrefix = Defaults_1.WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX;
145
- }
146
- const advSign = (0, crypto_2.hmacSign)(Buffer.concat([hmacPrefix, details]), Buffer.from(advSecretKey, 'base64'));
147
- if (Buffer.compare(hmac, advSign) !== 0) {
148
- throw new boom_1.Boom('Invalid account signature');
149
- }
150
- const account = index_js_1.proto.ADVSignedDeviceIdentity.decode(details);
151
- const { accountSignatureKey, accountSignature, details: deviceDetails } = account;
152
- const deviceIdentity = index_js_1.proto.ADVDeviceIdentity.decode(deviceDetails);
153
- const accountSignaturePrefix = deviceIdentity.deviceType === index_js_1.proto.ADVEncryptionType.HOSTED
154
- ? Defaults_1.WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX
155
- : Defaults_1.WA_ADV_ACCOUNT_SIG_PREFIX;
156
- const accountMsg = Buffer.concat([accountSignaturePrefix, deviceDetails, signedIdentityKey.public]);
157
- if (!crypto_2.Curve.verify(accountSignatureKey, accountMsg, accountSignature)) {
158
- throw new boom_1.Boom('Failed to verify account signature');
159
- }
160
- const deviceMsg = Buffer.concat([
161
- Defaults_1.WA_ADV_DEVICE_SIG_PREFIX,
162
- deviceDetails,
163
- signedIdentityKey.public,
164
- accountSignatureKey
165
- ]);
166
- account.deviceSignature = crypto_2.Curve.sign(signedIdentityKey.private, deviceMsg);
167
- const identity = (0, signal_1.createSignalIdentity)(lid, accountSignatureKey);
168
- const accountEnc = (0, exports.encodeSignedDeviceIdentity)(account, false);
169
- const reply = {
170
- tag: 'iq',
171
- attrs: {
172
- to: WABinary_1.S_WHATSAPP_NET,
173
- type: 'result',
174
- id: msgId
175
- },
176
- content: [
177
- {
178
- tag: 'pair-device-sign',
179
- attrs: {},
180
- content: [
181
- {
182
- tag: 'device-identity',
183
- attrs: { 'key-index': deviceIdentity.keyIndex.toString() },
184
- content: accountEnc
185
- }
186
- ]
187
- }
188
- ]
189
- };
190
- const authUpdate = {
191
- account,
192
- me: { id: jid, name: bizName, lid },
193
- signalIdentities: [...(signalIdentities || []), identity],
194
- platform: platformNode?.attrs.name
195
- };
196
- return {
197
- creds: authUpdate,
198
- reply
199
- };
200
- };
201
- exports.configureSuccessfulPairing = configureSuccessfulPairing;
202
- const encodeSignedDeviceIdentity = (account, includeSignatureKey) => {
203
- account = { ...account };
204
- if (!includeSignatureKey || !account.accountSignatureKey?.length) {
205
- account.accountSignatureKey = null;
206
- }
207
- return index_js_1.proto.ADVSignedDeviceIdentity.encode(account).finish();
208
- };
209
- exports.encodeSignedDeviceIdentity = encodeSignedDeviceIdentity;
@@ -1,12 +0,0 @@
1
- export interface AutoCacheViewOnceOptions {
2
- cacheDir?: string;
3
- logger?: any;
4
- onCached?: (info: {
5
- id: string;
6
- jid: string;
7
- filePath: string;
8
- type: string;
9
- }) => void;
10
- }
11
- export function getViewOnceContent(message: any): Record<string, any> | null;
12
- export function autoCacheViewOnceMedia(sock: any, options?: AutoCacheViewOnceOptions): () => void;