@dyyxyzz/baileys-mod 6.0.53 → 7.0.4

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 (213) hide show
  1. package/LICENSE +21 -0
  2. package/WAProto/WAProto.proto +5311 -0
  3. package/WAProto/index.js +65801 -141371
  4. package/lib/Defaults/index.js +117 -141
  5. package/lib/Defaults/index.js.bak +123 -0
  6. package/lib/KeyDB/BinarySearch.js +20 -0
  7. package/lib/KeyDB/KeyedDB.js +167 -0
  8. package/lib/KeyDB/index.js +4 -0
  9. package/lib/Signal/Group/ciphertext-message.js +12 -14
  10. package/lib/Signal/Group/group-session-builder.js +10 -42
  11. package/lib/Signal/Group/group_cipher.js +75 -87
  12. package/lib/Signal/Group/index.js +13 -57
  13. package/lib/Signal/Group/keyhelper.js +17 -52
  14. package/lib/Signal/Group/sender-chain-key.js +27 -33
  15. package/lib/Signal/Group/sender-key-distribution-message.js +62 -63
  16. package/lib/Signal/Group/sender-key-message.js +65 -66
  17. package/lib/Signal/Group/sender-key-name.js +45 -44
  18. package/lib/Signal/Group/sender-key-record.js +39 -49
  19. package/lib/Signal/Group/sender-key-state.js +80 -93
  20. package/lib/Signal/Group/sender-message-key.js +27 -28
  21. package/lib/Signal/libsignal.js +313 -163
  22. package/lib/Signal/lid-mapping.js +155 -0
  23. package/lib/Socket/Client/index.js +4 -19
  24. package/lib/Socket/Client/types.js +13 -0
  25. package/lib/Socket/Client/websocket.js +52 -0
  26. package/lib/Socket/Client/websocket.js.bak +53 -0
  27. package/lib/Socket/business.js +359 -242
  28. package/lib/Socket/chats.js +839 -943
  29. package/lib/Socket/communities.js +413 -0
  30. package/lib/Socket/groups.js +304 -309
  31. package/lib/Socket/index.js +15 -10
  32. package/lib/Socket/messages-recv.js +1107 -1054
  33. package/lib/Socket/messages-send.js +639 -449
  34. package/lib/Socket/mex.js +45 -0
  35. package/lib/Socket/newsletter.js +197 -311
  36. package/lib/Socket/socket.js +5 -3
  37. package/lib/Store/index.js +6 -10
  38. package/lib/Store/make-cache-manager-store.js +73 -81
  39. package/lib/Store/make-in-memory-store.js +286 -423
  40. package/lib/Store/make-ordered-dictionary.js +77 -79
  41. package/lib/Store/object-repository.js +24 -26
  42. package/lib/Types/Auth.js +3 -2
  43. package/lib/Types/Bussines.js +3 -0
  44. package/lib/Types/Call.js +3 -2
  45. package/lib/Types/Chat.js +9 -4
  46. package/lib/Types/Contact.js +3 -2
  47. package/lib/Types/Events.js +3 -2
  48. package/lib/Types/GroupMetadata.js +3 -2
  49. package/lib/Types/Label.js +24 -26
  50. package/lib/Types/LabelAssociation.js +6 -8
  51. package/lib/Types/Message.js +12 -9
  52. package/lib/Types/Newsletter.js +33 -38
  53. package/lib/Types/Newsletter.js.bak +33 -0
  54. package/lib/Types/Product.js +3 -2
  55. package/lib/Types/Signal.js +3 -2
  56. package/lib/Types/Socket.js +4 -2
  57. package/lib/Types/State.js +11 -2
  58. package/lib/Types/USync.js +3 -2
  59. package/lib/Types/index.js +27 -41
  60. package/lib/Utils/auth-utils.js +211 -198
  61. package/lib/Utils/baileys-event-stream.js +42 -61
  62. package/lib/Utils/browser-utils.js +5 -1
  63. package/lib/Utils/business.js +213 -214
  64. package/lib/Utils/chat-utils.js +703 -689
  65. package/lib/Utils/crypto.js +112 -133
  66. package/lib/Utils/decode-wa-message.js +252 -183
  67. package/lib/Utils/event-buffer.js +510 -496
  68. package/lib/Utils/generics.js +319 -392
  69. package/lib/Utils/history.js +83 -92
  70. package/lib/Utils/index.js +21 -33
  71. package/lib/Utils/link-preview.js +71 -83
  72. package/lib/Utils/logger.js +5 -7
  73. package/lib/Utils/lt-hash.js +40 -46
  74. package/lib/Utils/make-mutex.js +34 -41
  75. package/lib/Utils/message-retry-manager.js +113 -0
  76. package/lib/Utils/messages-media.js +550 -768
  77. package/lib/Utils/messages.js +371 -270
  78. package/lib/Utils/noise-handler.js +138 -149
  79. package/lib/Utils/pre-key-manager.js +85 -0
  80. package/lib/Utils/process-message.js +323 -303
  81. package/lib/Utils/signal.js +149 -141
  82. package/lib/Utils/use-multi-file-auth-state.js +95 -103
  83. package/lib/Utils/validate-connection.js +183 -214
  84. package/lib/WABinary/constants.js +1298 -35
  85. package/lib/WABinary/decode.js +237 -249
  86. package/lib/WABinary/encode.js +213 -260
  87. package/lib/WABinary/generic-utils.js +56 -65
  88. package/lib/WABinary/index.js +7 -21
  89. package/lib/WABinary/jid-utils.js +89 -58
  90. package/lib/WABinary/types.js +3 -2
  91. package/lib/WAM/BinaryInfo.js +10 -12
  92. package/lib/WAM/constants.js +22851 -15348
  93. package/lib/WAM/encode.js +135 -136
  94. package/lib/WAM/index.js +5 -19
  95. package/lib/WAUSync/Protocols/USyncContactProtocol.js +28 -30
  96. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +49 -53
  97. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +27 -28
  98. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +36 -39
  99. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -50
  100. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +26 -20
  101. package/lib/WAUSync/Protocols/index.js +6 -20
  102. package/lib/WAUSync/USyncQuery.js +86 -85
  103. package/lib/WAUSync/USyncUser.js +23 -25
  104. package/lib/WAUSync/index.js +5 -19
  105. package/lib/index.js +19 -34
  106. package/package.json +89 -106
  107. package/engine-requirements.js +0 -10
  108. package/lib/Defaults/baileys-version.json +0 -3
  109. package/lib/Defaults/index.d.ts +0 -53
  110. package/lib/Defaults/phonenumber-mcc.json +0 -223
  111. package/lib/Signal/Group/ciphertext-message.d.ts +0 -9
  112. package/lib/Signal/Group/group-session-builder.d.ts +0 -14
  113. package/lib/Signal/Group/group_cipher.d.ts +0 -17
  114. package/lib/Signal/Group/index.d.ts +0 -11
  115. package/lib/Signal/Group/keyhelper.d.ts +0 -10
  116. package/lib/Signal/Group/queue-job.d.ts +0 -1
  117. package/lib/Signal/Group/queue-job.js +0 -57
  118. package/lib/Signal/Group/sender-chain-key.d.ts +0 -13
  119. package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -16
  120. package/lib/Signal/Group/sender-key-message.d.ts +0 -18
  121. package/lib/Signal/Group/sender-key-name.d.ts +0 -17
  122. package/lib/Signal/Group/sender-key-record.d.ts +0 -30
  123. package/lib/Signal/Group/sender-key-state.d.ts +0 -38
  124. package/lib/Signal/Group/sender-message-key.d.ts +0 -11
  125. package/lib/Signal/libsignal.d.ts +0 -3
  126. package/lib/Socket/Client/abstract-socket-client.d.ts +0 -17
  127. package/lib/Socket/Client/abstract-socket-client.js +0 -13
  128. package/lib/Socket/Client/index.d.ts +0 -3
  129. package/lib/Socket/Client/mobile-socket-client.d.ts +0 -13
  130. package/lib/Socket/Client/mobile-socket-client.js +0 -65
  131. package/lib/Socket/Client/web-socket-client.d.ts +0 -12
  132. package/lib/Socket/Client/web-socket-client.js +0 -62
  133. package/lib/Socket/business.d.ts +0 -171
  134. package/lib/Socket/chats.d.ts +0 -267
  135. package/lib/Socket/chats.js.bak +0 -981
  136. package/lib/Socket/dugong.d.ts +0 -254
  137. package/lib/Socket/dugong.js +0 -484
  138. package/lib/Socket/groups.d.ts +0 -115
  139. package/lib/Socket/index.d.ts +0 -173
  140. package/lib/Socket/messages-recv.d.ts +0 -161
  141. package/lib/Socket/messages-send.d.ts +0 -149
  142. package/lib/Socket/newsletter.d.ts +0 -134
  143. package/lib/Socket/registration.d.ts +0 -267
  144. package/lib/Socket/registration.js +0 -166
  145. package/lib/Socket/socket.d.ts +0 -43
  146. package/lib/Socket/usync.d.ts +0 -36
  147. package/lib/Socket/usync.js +0 -70
  148. package/lib/Store/index.d.ts +0 -3
  149. package/lib/Store/make-cache-manager-store.d.ts +0 -13
  150. package/lib/Store/make-in-memory-store.d.ts +0 -118
  151. package/lib/Store/make-ordered-dictionary.d.ts +0 -13
  152. package/lib/Store/object-repository.d.ts +0 -10
  153. package/lib/Types/Auth.d.ts +0 -110
  154. package/lib/Types/Call.d.ts +0 -13
  155. package/lib/Types/Chat.d.ts +0 -102
  156. package/lib/Types/Contact.d.ts +0 -19
  157. package/lib/Types/Events.d.ts +0 -157
  158. package/lib/Types/GroupMetadata.d.ts +0 -55
  159. package/lib/Types/Label.d.ts +0 -35
  160. package/lib/Types/LabelAssociation.d.ts +0 -29
  161. package/lib/Types/Message.d.ts +0 -273
  162. package/lib/Types/Newsletter.d.ts +0 -103
  163. package/lib/Types/Product.d.ts +0 -78
  164. package/lib/Types/Signal.d.ts +0 -57
  165. package/lib/Types/Socket.d.ts +0 -111
  166. package/lib/Types/State.d.ts +0 -27
  167. package/lib/Types/USync.d.ts +0 -25
  168. package/lib/Types/index.d.ts +0 -57
  169. package/lib/Utils/auth-utils.d.ts +0 -18
  170. package/lib/Utils/baileys-event-stream.d.ts +0 -16
  171. package/lib/Utils/business.d.ts +0 -22
  172. package/lib/Utils/chat-utils.d.ts +0 -71
  173. package/lib/Utils/crypto.d.ts +0 -41
  174. package/lib/Utils/decode-wa-message.d.ts +0 -19
  175. package/lib/Utils/event-buffer.d.ts +0 -35
  176. package/lib/Utils/generics.d.ts +0 -92
  177. package/lib/Utils/generics.js.bak +0 -433
  178. package/lib/Utils/history.d.ts +0 -15
  179. package/lib/Utils/index.d.ts +0 -17
  180. package/lib/Utils/link-preview.d.ts +0 -21
  181. package/lib/Utils/logger.d.ts +0 -4
  182. package/lib/Utils/lt-hash.d.ts +0 -12
  183. package/lib/Utils/make-mutex.d.ts +0 -7
  184. package/lib/Utils/messages-media.d.ts +0 -116
  185. package/lib/Utils/messages.d.ts +0 -77
  186. package/lib/Utils/noise-handler.d.ts +0 -21
  187. package/lib/Utils/process-message.d.ts +0 -41
  188. package/lib/Utils/signal.d.ts +0 -32
  189. package/lib/Utils/use-multi-file-auth-state.d.ts +0 -13
  190. package/lib/Utils/validate-connection.d.ts +0 -11
  191. package/lib/Utils/validate-connection.js.bak +0 -237
  192. package/lib/WABinary/constants.d.ts +0 -30
  193. package/lib/WABinary/decode.d.ts +0 -7
  194. package/lib/WABinary/encode.d.ts +0 -3
  195. package/lib/WABinary/generic-utils.d.ts +0 -17
  196. package/lib/WABinary/index.d.ts +0 -5
  197. package/lib/WABinary/jid-utils.d.ts +0 -31
  198. package/lib/WABinary/types.d.ts +0 -18
  199. package/lib/WAM/BinaryInfo.d.ts +0 -17
  200. package/lib/WAM/constants.d.ts +0 -38
  201. package/lib/WAM/encode.d.ts +0 -3
  202. package/lib/WAM/index.d.ts +0 -3
  203. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -9
  204. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -22
  205. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -12
  206. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -12
  207. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +0 -25
  208. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +0 -8
  209. package/lib/WAUSync/Protocols/index.d.ts +0 -4
  210. package/lib/WAUSync/USyncQuery.d.ts +0 -28
  211. package/lib/WAUSync/USyncUser.d.ts +0 -12
  212. package/lib/WAUSync/index.d.ts +0 -3
  213. package/lib/index.d.ts +0 -12
@@ -1,147 +1,123 @@
1
- var __importDefault = this && this.__importDefault || function (a) {
2
- return a && a.__esModule ? a : { "default": a }
1
+ //=======================================================//
2
+ import { makeLibSignalRepository } from "../Signal/libsignal.js";
3
+ import { Browsers } from "../Utils/browser-utils.js";
4
+ import { proto } from "../../WAProto/index.js";
5
+ import logger from "../Utils/logger.js";
6
+ //=======================================================//
7
+ export const version = [2, 3000, 1029030078]
8
+ export const DICT_VERSION = 3;
9
+ //=======================================================//
10
+ export const NOISE_WA_HEADER = Buffer.from([87, 65, 6, DICT_VERSION]);
11
+ export const CALL_VIDEO_PREFIX = "https://call.whatsapp.com/video/";
12
+ export const CALL_AUDIO_PREFIX = "https://call.whatsapp.com/voice/";
13
+ export const WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX = Buffer.from([6, 5]);
14
+ export const WA_ADV_HOSTED_DEVICE_SIG_PREFIX = Buffer.from([6, 6]);
15
+ export const NOISE_MODE = "Noise_XX_25519_AESGCM_SHA256\0\0\0\0";
16
+ export const WA_ADV_ACCOUNT_SIG_PREFIX = Buffer.from([6, 0]);
17
+ export const WA_ADV_DEVICE_SIG_PREFIX = Buffer.from([6, 1]);
18
+ export const DEFAULT_ORIGIN = "https://web.whatsapp.com";
19
+ export const WA_DEFAULT_EPHEMERAL = 7 * 24 * 60 * 60;
20
+ export const UNAUTHORIZED_CODES = [401, 403, 419];
21
+ export const KEY_BUNDLE_TYPE = Buffer.from([5]);
22
+ export const PHONE_CONNECTION_CB = "CB:Pong";
23
+ export const DEF_CALLBACK_PREFIX = "CB:";
24
+ export const DEF_TAG_PREFIX = "TAG:";
25
+ //=======================================================//
26
+ export const URL_REGEX = /https:\/\/(?![^:@\/\s]+:[^:@\/\s]+@)[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}(:\d+)?(\/[^\s]*)?/g;
27
+ //=======================================================//
28
+ export const WA_CERT_DETAILS = {
29
+ SERIAL: 0
3
30
  };
4
-
5
- Object.defineProperty(exports, "__esModule", { value: !0 });
6
-
7
- exports.DEFAULT_CACHE_TTLS =
8
- exports.INITIAL_PREKEY_COUNT =
9
- exports.MIN_PREKEY_COUNT =
10
- exports.MEDIA_KEYS =
11
- exports.MEDIA_HKDF_KEY_MAPPING =
12
- exports.MEDIA_PATH_MAP =
13
- exports.DEFAULT_CONNECTION_CONFIG =
14
- exports.PROCESSABLE_HISTORY_TYPES =
15
- exports.WA_CERT_DETAILS =
16
- exports.URL_REGEX =
17
- exports.NOISE_WA_HEADER =
18
- exports.KEY_BUNDLE_TYPE =
19
- exports.DICT_VERSION =
20
- exports.NOISE_MODE =
21
- exports.WA_DEFAULT_EPHEMERAL =
22
- exports.PHONE_CONNECTION_CB =
23
- exports.DEF_TAG_PREFIX =
24
- exports.DEF_CALLBACK_PREFIX =
25
- exports.DEFAULT_ORIGIN =
26
- exports.UNAUTHORIZED_CODES =
27
- void 0;
28
-
29
- const crypto_1 = require("crypto");
30
- const WAProto_1 = require("../../WAProto"),
31
- libsignal_1 = require("../Signal/libsignal"),
32
- Utils_1 = require("../Utils"),
33
- logger_1 = __importDefault(require("../Utils/logger")),
34
- baileys_version_json_1 = require("./baileys-version.json"),
35
- phonenumber_mcc_json_1 = __importDefault(require("./phonenumber-mcc.json"));
36
-
37
- exports.UNAUTHORIZED_CODES = [401, 403, 419];
38
- exports.version = [2, 3000, 1027934701];
39
- exports.PHONENUMBER_MCC = phonenumber_mcc_json_1.default;
40
- exports.DEFAULT_ORIGIN = "https://web.whatsapp.com";
41
- exports.MOBILE_ENDPOINT = 'g.whatsapp.net';
42
- exports.MOBILE_PORT = 443;
43
- exports.DEF_CALLBACK_PREFIX = "CB:";
44
- exports.DEF_TAG_PREFIX = "TAG:";
45
- exports.PHONE_CONNECTION_CB = "CB:Pong";
46
- exports.WA_DEFAULT_EPHEMERAL = 604800;
47
- const WA_VERSION = '2.25.23.24';
48
- const WA_VERSION_HASH = (0, crypto_1.createHash)('md5').update(WA_VERSION).digest('hex');
49
- exports.MOBILE_TOKEN = Buffer.from('0a1mLfGUIBVrMKF1RdvLI5lkRBvof6vn0fD2QRSM' + WA_VERSION_HASH);
50
- exports.MOBILE_REGISTRATION_ENDPOINT = 'https://v.whatsapp.net/v2';
51
- exports.MOBILE_USERAGENT = `WhatsApp/${WA_VERSION} iOS/17.5.1 Device/Apple-iPhone_13`;
52
- exports.REGISTRATION_PUBLIC_KEY = Buffer.from([
53
- 5, 142, 140, 15, 116, 195, 235, 197, 215, 166, 134, 92, 108, 60, 132, 56, 86, 176, 97, 33, 204, 232, 234, 119, 77,
54
- 34, 251, 111, 18, 37, 18, 48, 45,
55
- ]);
56
- exports.NOISE_MODE = "Noise_XX_25519_AESGCM_SHA256\x00\x00\x00\x00";
57
- exports.DICT_VERSION = 2;
58
- exports.KEY_BUNDLE_TYPE = Buffer.from([5]);
59
- exports.NOISE_WA_HEADER = Buffer.from([87, 65, 6, exports.DICT_VERSION]);
60
- exports.PROTOCOL_VERSION = [5, 2];
61
- exports.MOBILE_NOISE_HEADER = Buffer.concat([Buffer.from('WA'), Buffer.from(exports.PROTOCOL_VERSION)]);
62
-
63
- exports.URL_REGEX = /https:\/\/(?![^:@\/\s]+:[^:@\/\s]+@)[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}(:\d+)?(\/[^\s]*)?/g;
64
- exports.WA_CERT_DETAILS = { SERIAL: 0 };
65
-
66
- exports.PROCESSABLE_HISTORY_TYPES = [
67
- WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.INITIAL_BOOTSTRAP,
68
- WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.PUSH_NAME,
69
- WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.RECENT,
70
- WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.FULL,
71
- WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.ON_DEMAND
31
+ //=======================================================//
32
+ export const PROCESSABLE_HISTORY_TYPES = [
33
+ proto.Message.HistorySyncNotification.HistorySyncType.INITIAL_BOOTSTRAP,
34
+ proto.Message.HistorySyncNotification.HistorySyncType.PUSH_NAME,
35
+ proto.Message.HistorySyncNotification.HistorySyncType.RECENT,
36
+ proto.Message.HistorySyncNotification.HistorySyncType.FULL,
37
+ proto.Message.HistorySyncNotification.HistorySyncType.ON_DEMAND,
38
+ proto.Message.HistorySyncNotification.HistorySyncType.NON_BLOCKING_DATA,
39
+ proto.Message.HistorySyncNotification.HistorySyncType.INITIAL_STATUS_V3
72
40
  ];
73
-
74
- exports.DEFAULT_CONNECTION_CONFIG = {
75
- version: baileys_version_json_1.version,
76
- browser: Utils_1.Browsers.ubuntu("Chrome"),
77
- waWebSocketUrl: "wss://web.whatsapp.com/ws/chat",
78
- connectTimeoutMs: 2E4,
79
- keepAliveIntervalMs: 3E4,
80
- logger: logger_1.default.child({ class: "baileys" }),
81
- printQRInTerminal: !1,
82
- emitOwnEvents: !0,
83
- defaultQueryTimeoutMs: 6E4,
84
- customUploadHosts: [],
85
- retryRequestDelayMs: 250,
86
- maxMsgRetryCount: 5,
87
- fireInitQueries: !0,
88
- auth: void 0,
89
- markOnlineOnConnect: !0,
90
- syncFullHistory: !1,
91
- patchMessageBeforeSending: a => a,
92
- shouldSyncHistoryMessage: () => !0,
93
- shouldIgnoreJid: () => !1,
94
- linkPreviewImageThumbnailWidth: 192,
95
- transactionOpts: { maxCommitRetries: 10, delayBetweenTriesMs: 3E3 },
96
- generateHighQualityLinkPreview: !1,
97
- options: {},
98
- appStateMacVerification: { patch: !1, snapshot: !1 },
99
- countryCode: "US",
100
- getMessage: async () => { },
101
- cachedGroupMetadata: async () => { },
102
- makeSignalRepository: libsignal_1.makeLibSignalRepository
41
+ //=======================================================//
42
+ export const DEFAULT_CONNECTION_CONFIG = {
43
+ "version": version,
44
+ "browser": Browsers.iOS("Safari"),
45
+ "waWebSocketUrl": "wss://web.whatsapp.com/ws/chat",
46
+ "connectTimeoutMs": 20000,
47
+ "keepAliveIntervalMs": 30000,
48
+ "logger": logger.child({ "class": "baileys" }),
49
+ "emitOwnEvents": true,
50
+ "defaultQueryTimeoutMs": 60000,
51
+ "customUploadHosts": [],
52
+ "retryRequestDelayMs": 250,
53
+ "maxMsgRetryCount": 5,
54
+ "fireInitQueries": true,
55
+ "auth": undefined,
56
+ "markOnlineOnConnect": true,
57
+ "syncFullHistory": true,
58
+ "patchMessageBeforeSending": msg => msg,
59
+ "shouldSyncHistoryMessage": () => true,
60
+ "shouldIgnoreJid": () => false,
61
+ "linkPreviewImageThumbnailWidth": 192,
62
+ "transactionOpts": { "maxCommitRetries": 10, "delayBetweenTriesMs": 3000 },
63
+ "generateHighQualityLinkPreview": false,
64
+ "enableAutoSessionRecreation": true,
65
+ "enableRecentMessageCache": true,
66
+ "options": {},
67
+ "appStateMacVerification": {
68
+ "patch": false,
69
+ "snapshot": false
70
+ },
71
+ "countryCode": "US",
72
+ "getMessage": async () => undefined,
73
+ "cachedGroupMetadata": async () => undefined,
74
+ "makeSignalRepository": makeLibSignalRepository
103
75
  };
104
-
105
- exports.MEDIA_PATH_MAP = {
106
- image: "/mms/image",
107
- video: "/mms/video",
108
- document: "/mms/document",
109
- audio: "/mms/audio",
110
- sticker: "/mms/image",
111
- "thumbnail-link": "/mms/image",
112
- "product-catalog-image": "/product/image",
113
- "md-app-state": "",
114
- "md-msg-hist": "/mms/md-app-state"
76
+ //=======================================================//
77
+ export const MEDIA_PATH_MAP = {
78
+ "image": "/mms/image",
79
+ "video": "/mms/video",
80
+ "document": "/mms/document",
81
+ "audio": "/mms/audio",
82
+ "sticker": "/mms/image",
83
+ "thumbnail-link": "/mms/image",
84
+ "product-catalog-image": "/product/image",
85
+ "md-app-state": "",
86
+ "md-msg-hist": "/mms/md-app-state",
87
+ "biz-cover-photo": "/pps/biz-cover-photo"
115
88
  };
116
-
117
- exports.MEDIA_HKDF_KEY_MAPPING = {
118
- audio: "Audio",
119
- document: "Document",
120
- gif: "Video",
121
- image: "Image",
122
- ppic: "",
123
- product: "Image",
124
- ptt: "Audio",
125
- sticker: "Image",
126
- video: "Video",
127
- "thumbnail-document": "Document Thumbnail",
128
- "thumbnail-image": "Image Thumbnail",
129
- "thumbnail-video": "Video Thumbnail",
130
- "thumbnail-link": "Link Thumbnail",
131
- "md-msg-hist": "History",
132
- "md-app-state": "App State",
133
- "product-catalog-image": "",
134
- "payment-bg-image": "Payment Background",
135
- ptv: "Video"
89
+ //=======================================================//
90
+ export const MEDIA_HKDF_KEY_MAPPING = {
91
+ "audio": "Audio",
92
+ "document": "Document",
93
+ "gif": "Video",
94
+ "image": "Image",
95
+ "ppic": "",
96
+ "product": "Image",
97
+ "ptt": "Audio",
98
+ "sticker": "Image",
99
+ "video": "Video",
100
+ "thumbnail-document": "Document Thumbnail",
101
+ "thumbnail-image": "Image Thumbnail",
102
+ "thumbnail-video": "Video Thumbnail",
103
+ "thumbnail-link": "Link Thumbnail",
104
+ "md-msg-hist": "History",
105
+ "md-app-state": "App State",
106
+ "product-catalog-image": "",
107
+ "payment-bg-image": "Payment Background",
108
+ "ptv": "Video",
109
+ "biz-cover-photo": "Image"
136
110
  };
137
-
138
- exports.MEDIA_KEYS = Object.keys(exports.MEDIA_PATH_MAP);
139
- exports.MIN_PREKEY_COUNT = 5;
140
- exports.INITIAL_PREKEY_COUNT = 30;
141
-
142
- exports.DEFAULT_CACHE_TTLS = {
143
- SIGNAL_STORE: 300,
144
- MSG_RETRY: 3600,
145
- CALL_OFFER: 300,
146
- USER_DEVICES: 300
111
+ //=======================================================//
112
+ export const MEDIA_KEYS = Object.keys(MEDIA_PATH_MAP);
113
+ export const MIN_PREKEY_COUNT = 5;
114
+ export const INITIAL_PREKEY_COUNT = 812;
115
+ export const UPLOAD_TIMEOUT = 30000;
116
+ export const MIN_UPLOAD_INTERVAL = 5000;
117
+ export const DEFAULT_CACHE_TTLS = {
118
+ SIGNAL_STORE: 5 * 60,
119
+ MSG_RETRY: 60 * 60,
120
+ CALL_OFFER: 5 * 60,
121
+ USER_DEVICES: 5 * 60
147
122
  };
123
+ //=======================================================//
@@ -0,0 +1,123 @@
1
+ //=======================================================//
2
+ import { makeLibSignalRepository } from "../Signal/libsignal.js";
3
+ import { Browsers } from "../Utils/browser-utils.js";
4
+ import { proto } from "../../WAProto/index.js";
5
+ import logger from "../Utils/logger.js";
6
+ //=======================================================//
7
+ export const version = [2, 3000, 1028716292];
8
+ export const DICT_VERSION = 3;
9
+ //=======================================================//
10
+ export const NOISE_WA_HEADER = Buffer.from([87, 65, 6, DICT_VERSION]);
11
+ export const CALL_VIDEO_PREFIX = "https://call.whatsapp.com/video/";
12
+ export const CALL_AUDIO_PREFIX = "https://call.whatsapp.com/voice/";
13
+ export const WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX = Buffer.from([6, 5]);
14
+ export const WA_ADV_HOSTED_DEVICE_SIG_PREFIX = Buffer.from([6, 6]);
15
+ export const NOISE_MODE = "Noise_XX_25519_AESGCM_SHA256\0\0\0\0";
16
+ export const WA_ADV_ACCOUNT_SIG_PREFIX = Buffer.from([6, 0]);
17
+ export const WA_ADV_DEVICE_SIG_PREFIX = Buffer.from([6, 1]);
18
+ export const DEFAULT_ORIGIN = "https://web.whatsapp.com";
19
+ export const WA_DEFAULT_EPHEMERAL = 7 * 24 * 60 * 60;
20
+ export const UNAUTHORIZED_CODES = [401, 403, 419];
21
+ export const KEY_BUNDLE_TYPE = Buffer.from([5]);
22
+ export const PHONE_CONNECTION_CB = "CB:Pong";
23
+ export const DEF_CALLBACK_PREFIX = "CB:";
24
+ export const DEF_TAG_PREFIX = "TAG:";
25
+ //=======================================================//
26
+ export const URL_REGEX = /https:\/\/(?![^:@\/\s]+:[^:@\/\s]+@)[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}(:\d+)?(\/[^\s]*)?/g;
27
+ //=======================================================//
28
+ export const WA_CERT_DETAILS = {
29
+ SERIAL: 0
30
+ };
31
+ //=======================================================//
32
+ export const PROCESSABLE_HISTORY_TYPES = [
33
+ proto.Message.HistorySyncNotification.HistorySyncType.INITIAL_BOOTSTRAP,
34
+ proto.Message.HistorySyncNotification.HistorySyncType.PUSH_NAME,
35
+ proto.Message.HistorySyncNotification.HistorySyncType.RECENT,
36
+ proto.Message.HistorySyncNotification.HistorySyncType.FULL,
37
+ proto.Message.HistorySyncNotification.HistorySyncType.ON_DEMAND,
38
+ proto.Message.HistorySyncNotification.HistorySyncType.NON_BLOCKING_DATA,
39
+ proto.Message.HistorySyncNotification.HistorySyncType.INITIAL_STATUS_V3
40
+ ];
41
+ //=======================================================//
42
+ export const DEFAULT_CONNECTION_CONFIG = {
43
+ "version": version,
44
+ "browser": Browsers.iOS("Safari"),
45
+ "waWebSocketUrl": "wss://web.whatsapp.com/ws/chat",
46
+ "connectTimeoutMs": 20000,
47
+ "keepAliveIntervalMs": 30000,
48
+ "logger": logger.child({ "class": "baileys" }),
49
+ "emitOwnEvents": true,
50
+ "defaultQueryTimeoutMs": 60000,
51
+ "customUploadHosts": [],
52
+ "retryRequestDelayMs": 250,
53
+ "maxMsgRetryCount": 5,
54
+ "fireInitQueries": true,
55
+ "auth": undefined,
56
+ "markOnlineOnConnect": true,
57
+ "syncFullHistory": true,
58
+ "patchMessageBeforeSending": msg => msg,
59
+ "shouldSyncHistoryMessage": () => true,
60
+ "shouldIgnoreJid": () => false,
61
+ "linkPreviewImageThumbnailWidth": 192,
62
+ "transactionOpts": { "maxCommitRetries": 10, "delayBetweenTriesMs": 3000 },
63
+ "generateHighQualityLinkPreview": false,
64
+ "enableAutoSessionRecreation": true,
65
+ "enableRecentMessageCache": true,
66
+ "options": {},
67
+ "appStateMacVerification": {
68
+ "patch": false,
69
+ "snapshot": false
70
+ },
71
+ "countryCode": "US",
72
+ "getMessage": async () => undefined,
73
+ "cachedGroupMetadata": async () => undefined,
74
+ "makeSignalRepository": makeLibSignalRepository
75
+ };
76
+ //=======================================================//
77
+ export const MEDIA_PATH_MAP = {
78
+ "image": "/mms/image",
79
+ "video": "/mms/video",
80
+ "document": "/mms/document",
81
+ "audio": "/mms/audio",
82
+ "sticker": "/mms/image",
83
+ "thumbnail-link": "/mms/image",
84
+ "product-catalog-image": "/product/image",
85
+ "md-app-state": "",
86
+ "md-msg-hist": "/mms/md-app-state",
87
+ "biz-cover-photo": "/pps/biz-cover-photo"
88
+ };
89
+ //=======================================================//
90
+ export const MEDIA_HKDF_KEY_MAPPING = {
91
+ "audio": "Audio",
92
+ "document": "Document",
93
+ "gif": "Video",
94
+ "image": "Image",
95
+ "ppic": "",
96
+ "product": "Image",
97
+ "ptt": "Audio",
98
+ "sticker": "Image",
99
+ "video": "Video",
100
+ "thumbnail-document": "Document Thumbnail",
101
+ "thumbnail-image": "Image Thumbnail",
102
+ "thumbnail-video": "Video Thumbnail",
103
+ "thumbnail-link": "Link Thumbnail",
104
+ "md-msg-hist": "History",
105
+ "md-app-state": "App State",
106
+ "product-catalog-image": "",
107
+ "payment-bg-image": "Payment Background",
108
+ "ptv": "Video",
109
+ "biz-cover-photo": "Image"
110
+ };
111
+ //=======================================================//
112
+ export const MEDIA_KEYS = Object.keys(MEDIA_PATH_MAP);
113
+ export const MIN_PREKEY_COUNT = 5;
114
+ export const INITIAL_PREKEY_COUNT = 812;
115
+ export const UPLOAD_TIMEOUT = 30000;
116
+ export const MIN_UPLOAD_INTERVAL = 5000;
117
+ export const DEFAULT_CACHE_TTLS = {
118
+ SIGNAL_STORE: 5 * 60,
119
+ MSG_RETRY: 60 * 60,
120
+ CALL_OFFER: 5 * 60,
121
+ USER_DEVICES: 5 * 60
122
+ };
123
+ //=======================================================//
@@ -0,0 +1,20 @@
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
+ //===================================//
@@ -0,0 +1,167 @@
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
+ //===================================//
@@ -0,0 +1,4 @@
1
+ //===================================//
2
+ export * from "./BinarySearch.js"
3
+ export * from "./KeyedDB.js"
4
+ //===================================//
@@ -1,15 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CiphertextMessage = void 0;
4
- class CiphertextMessage {
5
- constructor() {
6
- this.UNSUPPORTED_VERSION = 1;
7
- this.CURRENT_VERSION = 3;
8
- this.WHISPER_TYPE = 2;
9
- this.PREKEY_TYPE = 3;
10
- this.SENDERKEY_TYPE = 4;
11
- this.SENDERKEY_DISTRIBUTION_TYPE = 5;
12
- this.ENCRYPTED_MESSAGE_OVERHEAD = 53;
13
- }
1
+ //=======================================================//
2
+ export class CiphertextMessage {
3
+ constructor() {
4
+ this.UNSUPPORTED_VERSION = 1;
5
+ this.CURRENT_VERSION = 3;
6
+ this.WHISPER_TYPE = 2;
7
+ this.PREKEY_TYPE = 3;
8
+ this.SENDERKEY_TYPE = 4;
9
+ this.SENDERKEY_DISTRIBUTION_TYPE = 5;
10
+ this.ENCRYPTED_MESSAGE_OVERHEAD = 53;
11
+ }
14
12
  }
15
- exports.CiphertextMessage = CiphertextMessage;
13
+ //=======================================================//