@sixcore/baileys 1.0.0 → 1.0.2

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 (228) hide show
  1. package/WAProto/index.js +14270 -302
  2. package/jessica.js +91 -0
  3. package/lib/Defaults/baileys-version.json +1 -1
  4. package/lib/Defaults/index.js +117 -79
  5. package/lib/Defaults/phonenumber-mcc.json +223 -0
  6. package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
  7. package/lib/Signal/Group/ciphertext-message.js +15 -0
  8. package/lib/Signal/Group/group-session-builder.d.ts +14 -0
  9. package/lib/Signal/Group/group-session-builder.js +64 -0
  10. package/lib/Signal/Group/group_cipher.d.ts +17 -0
  11. package/lib/Signal/Group/group_cipher.js +96 -0
  12. package/lib/Signal/Group/index.d.ts +11 -0
  13. package/lib/Signal/Group/index.js +57 -0
  14. package/lib/Signal/Group/keyhelper.d.ts +10 -0
  15. package/lib/Signal/Group/keyhelper.js +55 -0
  16. package/lib/Signal/Group/queue-job.d.ts +1 -0
  17. package/lib/Signal/Group/queue-job.js +57 -0
  18. package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
  19. package/lib/Signal/Group/sender-chain-key.js +34 -0
  20. package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
  21. package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
  22. package/lib/Signal/Group/sender-key-message.d.ts +18 -0
  23. package/lib/Signal/Group/sender-key-message.js +69 -0
  24. package/lib/Signal/Group/sender-key-name.d.ts +17 -0
  25. package/lib/Signal/Group/sender-key-name.js +51 -0
  26. package/lib/Signal/Group/sender-key-record.d.ts +30 -0
  27. package/lib/Signal/Group/sender-key-record.js +53 -0
  28. package/lib/Signal/Group/sender-key-state.d.ts +38 -0
  29. package/lib/Signal/Group/sender-key-state.js +99 -0
  30. package/lib/Signal/Group/sender-message-key.d.ts +11 -0
  31. package/{WASignalGroup/sender_message_key.js → lib/Signal/Group/sender-message-key.js} +6 -16
  32. package/lib/Signal/libsignal.js +51 -29
  33. package/lib/Socket/business.d.ts +43 -42
  34. package/lib/Socket/chats.d.ts +222 -36
  35. package/lib/Socket/chats.js +173 -153
  36. package/lib/Socket/dugong.d.ts +254 -0
  37. package/lib/Socket/dugong.js +484 -0
  38. package/lib/Socket/groups.d.ts +7 -7
  39. package/lib/Socket/groups.js +37 -35
  40. package/lib/Socket/index.d.ts +52 -51
  41. package/lib/Socket/index.js +1 -0
  42. package/lib/Socket/messages-recv.d.ts +37 -34
  43. package/lib/Socket/messages-recv.js +175 -37
  44. package/lib/Socket/messages-send.d.ts +12 -18
  45. package/lib/Socket/messages-send.js +396 -574
  46. package/lib/Socket/newsletter.d.ts +28 -26
  47. package/lib/Socket/newsletter.js +132 -121
  48. package/lib/Socket/registration.d.ts +52 -49
  49. package/lib/Socket/registration.js +7 -7
  50. package/lib/Socket/socket.d.ts +0 -1
  51. package/lib/Socket/socket.js +49 -27
  52. package/lib/Socket/usync.d.ts +10 -11
  53. package/lib/Store/make-cache-manager-store.d.ts +1 -2
  54. package/lib/Store/make-in-memory-store.d.ts +2 -2
  55. package/lib/Store/make-in-memory-store.js +1 -5
  56. package/lib/Store/make-ordered-dictionary.js +2 -2
  57. package/lib/Types/Auth.d.ts +1 -0
  58. package/lib/Types/Call.d.ts +1 -1
  59. package/lib/Types/Chat.d.ts +7 -12
  60. package/lib/Types/Events.d.ts +2 -17
  61. package/lib/Types/GroupMetadata.d.ts +2 -3
  62. package/lib/Types/Label.d.ts +0 -11
  63. package/lib/Types/Label.js +1 -1
  64. package/lib/Types/LabelAssociation.js +1 -1
  65. package/lib/Types/Message.d.ts +10 -170
  66. package/lib/Types/Newsletter.d.ts +97 -86
  67. package/lib/Types/Newsletter.js +38 -32
  68. package/lib/Types/Socket.d.ts +2 -7
  69. package/lib/Types/index.d.ts +0 -9
  70. package/lib/Types/index.js +1 -1
  71. package/lib/Utils/auth-utils.js +14 -35
  72. package/lib/Utils/business.d.ts +1 -1
  73. package/lib/Utils/business.js +2 -2
  74. package/lib/Utils/chat-utils.d.ts +12 -11
  75. package/lib/Utils/chat-utils.js +36 -52
  76. package/lib/Utils/crypto.d.ts +16 -15
  77. package/lib/Utils/crypto.js +26 -74
  78. package/lib/Utils/decode-wa-message.d.ts +0 -17
  79. package/lib/Utils/decode-wa-message.js +17 -53
  80. package/lib/Utils/event-buffer.js +7 -10
  81. package/lib/Utils/generics.d.ts +17 -13
  82. package/lib/Utils/generics.js +79 -58
  83. package/lib/Utils/history.d.ts +2 -6
  84. package/lib/Utils/history.js +6 -4
  85. package/lib/Utils/logger.d.ts +3 -1
  86. package/lib/Utils/lt-hash.js +12 -12
  87. package/lib/Utils/make-mutex.d.ts +2 -2
  88. package/lib/Utils/messages-media.d.ts +28 -25
  89. package/lib/Utils/messages-media.js +733 -557
  90. package/lib/Utils/messages.js +68 -473
  91. package/lib/Utils/noise-handler.d.ts +5 -4
  92. package/lib/Utils/noise-handler.js +14 -19
  93. package/lib/Utils/process-message.d.ts +5 -5
  94. package/lib/Utils/process-message.js +23 -75
  95. package/lib/Utils/signal.d.ts +1 -2
  96. package/lib/Utils/signal.js +26 -32
  97. package/lib/Utils/use-multi-file-auth-state.d.ts +1 -0
  98. package/lib/Utils/use-multi-file-auth-state.js +66 -242
  99. package/lib/Utils/validate-connection.d.ts +1 -1
  100. package/lib/Utils/validate-connection.js +88 -64
  101. package/lib/WABinary/constants.d.ts +27 -24
  102. package/lib/WABinary/decode.d.ts +2 -1
  103. package/lib/WABinary/decode.js +11 -23
  104. package/lib/WABinary/encode.d.ts +2 -1
  105. package/lib/WABinary/encode.js +147 -134
  106. package/lib/WABinary/generic-utils.d.ts +5 -2
  107. package/lib/WABinary/generic-utils.js +125 -37
  108. package/lib/WABinary/jid-utils.d.ts +1 -1
  109. package/lib/WAM/BinaryInfo.d.ts +11 -2
  110. package/lib/WAM/encode.d.ts +2 -1
  111. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +3 -3
  112. package/lib/WAUSync/USyncUser.d.ts +2 -0
  113. package/lib/index.d.ts +12 -0
  114. package/lib/index.js +64 -1
  115. package/package.json +113 -51
  116. package/WAProto/GenerateStatics.sh +0 -4
  117. package/WAProto/WAProto.proto +0 -4357
  118. package/WAProto/index.d.ts +0 -50383
  119. package/WASignalGroup/GroupProtocol.js +0 -1697
  120. package/WASignalGroup/ciphertext_message.js +0 -16
  121. package/WASignalGroup/generate-proto.sh +0 -1
  122. package/WASignalGroup/group.proto +0 -42
  123. package/WASignalGroup/group_cipher.js +0 -120
  124. package/WASignalGroup/group_session_builder.js +0 -46
  125. package/WASignalGroup/index.js +0 -5
  126. package/WASignalGroup/keyhelper.js +0 -21
  127. package/WASignalGroup/protobufs.js +0 -3
  128. package/WASignalGroup/queue_job.js +0 -69
  129. package/WASignalGroup/sender_chain_key.js +0 -50
  130. package/WASignalGroup/sender_key_distribution_message.js +0 -78
  131. package/WASignalGroup/sender_key_message.js +0 -92
  132. package/WASignalGroup/sender_key_name.js +0 -70
  133. package/WASignalGroup/sender_key_record.js +0 -56
  134. package/WASignalGroup/sender_key_state.js +0 -129
  135. package/lib/Utils/use-single-file-auth-state.d.ts +0 -12
  136. package/lib/Utils/use-single-file-auth-state.js +0 -75
  137. package/src/Defaults/baileys-version.json +0 -3
  138. package/src/Defaults/index.ts +0 -133
  139. package/src/Signal/Group/ciphertext-message.ts +0 -9
  140. package/src/Signal/Group/group-session-builder.ts +0 -56
  141. package/src/Signal/Group/group_cipher.ts +0 -117
  142. package/src/Signal/Group/index.ts +0 -11
  143. package/src/Signal/Group/keyhelper.ts +0 -28
  144. package/src/Signal/Group/sender-chain-key.ts +0 -34
  145. package/src/Signal/Group/sender-key-distribution-message.ts +0 -95
  146. package/src/Signal/Group/sender-key-message.ts +0 -96
  147. package/src/Signal/Group/sender-key-name.ts +0 -66
  148. package/src/Signal/Group/sender-key-record.ts +0 -69
  149. package/src/Signal/Group/sender-key-state.ts +0 -134
  150. package/src/Signal/Group/sender-message-key.ts +0 -36
  151. package/src/Signal/libsignal.ts +0 -447
  152. package/src/Signal/lid-mapping.ts +0 -209
  153. package/src/Socket/Client/index.ts +0 -2
  154. package/src/Socket/Client/types.ts +0 -22
  155. package/src/Socket/Client/websocket.ts +0 -56
  156. package/src/Socket/business.ts +0 -421
  157. package/src/Socket/chats.ts +0 -1223
  158. package/src/Socket/communities.ts +0 -477
  159. package/src/Socket/groups.ts +0 -361
  160. package/src/Socket/index.ts +0 -22
  161. package/src/Socket/messages-recv.ts +0 -1563
  162. package/src/Socket/messages-send.ts +0 -1210
  163. package/src/Socket/mex.ts +0 -58
  164. package/src/Socket/newsletter.ts +0 -229
  165. package/src/Socket/socket.ts +0 -1072
  166. package/src/Types/Auth.ts +0 -115
  167. package/src/Types/Bussines.ts +0 -20
  168. package/src/Types/Call.ts +0 -14
  169. package/src/Types/Chat.ts +0 -138
  170. package/src/Types/Contact.ts +0 -24
  171. package/src/Types/Events.ts +0 -132
  172. package/src/Types/GroupMetadata.ts +0 -70
  173. package/src/Types/Label.ts +0 -48
  174. package/src/Types/LabelAssociation.ts +0 -35
  175. package/src/Types/Message.ts +0 -424
  176. package/src/Types/Newsletter.ts +0 -98
  177. package/src/Types/Product.ts +0 -85
  178. package/src/Types/Signal.ts +0 -76
  179. package/src/Types/Socket.ts +0 -150
  180. package/src/Types/State.ts +0 -43
  181. package/src/Types/USync.ts +0 -27
  182. package/src/Types/globals.d.ts +0 -8
  183. package/src/Types/index.ts +0 -67
  184. package/src/Utils/auth-utils.ts +0 -331
  185. package/src/Utils/browser-utils.ts +0 -31
  186. package/src/Utils/business.ts +0 -286
  187. package/src/Utils/chat-utils.ts +0 -933
  188. package/src/Utils/crypto.ts +0 -184
  189. package/src/Utils/decode-wa-message.ts +0 -355
  190. package/src/Utils/event-buffer.ts +0 -662
  191. package/src/Utils/generics.ts +0 -470
  192. package/src/Utils/history.ts +0 -114
  193. package/src/Utils/index.ts +0 -18
  194. package/src/Utils/link-preview.ts +0 -111
  195. package/src/Utils/logger.ts +0 -13
  196. package/src/Utils/lt-hash.ts +0 -65
  197. package/src/Utils/make-mutex.ts +0 -45
  198. package/src/Utils/message-retry-manager.ts +0 -229
  199. package/src/Utils/messages-media.ts +0 -820
  200. package/src/Utils/messages.ts +0 -1137
  201. package/src/Utils/noise-handler.ts +0 -192
  202. package/src/Utils/pre-key-manager.ts +0 -126
  203. package/src/Utils/process-message.ts +0 -622
  204. package/src/Utils/signal.ts +0 -214
  205. package/src/Utils/use-multi-file-auth-state.ts +0 -136
  206. package/src/Utils/validate-connection.ts +0 -253
  207. package/src/WABinary/constants.ts +0 -1305
  208. package/src/WABinary/decode.ts +0 -281
  209. package/src/WABinary/encode.ts +0 -253
  210. package/src/WABinary/generic-utils.ts +0 -127
  211. package/src/WABinary/index.ts +0 -5
  212. package/src/WABinary/jid-utils.ts +0 -128
  213. package/src/WABinary/types.ts +0 -17
  214. package/src/WAM/BinaryInfo.ts +0 -12
  215. package/src/WAM/constants.ts +0 -22889
  216. package/src/WAM/encode.ts +0 -169
  217. package/src/WAM/index.ts +0 -3
  218. package/src/WAUSync/Protocols/USyncContactProtocol.ts +0 -32
  219. package/src/WAUSync/Protocols/USyncDeviceProtocol.ts +0 -78
  220. package/src/WAUSync/Protocols/USyncDisappearingModeProtocol.ts +0 -35
  221. package/src/WAUSync/Protocols/USyncStatusProtocol.ts +0 -44
  222. package/src/WAUSync/Protocols/UsyncBotProfileProtocol.ts +0 -76
  223. package/src/WAUSync/Protocols/UsyncLIDProtocol.ts +0 -33
  224. package/src/WAUSync/Protocols/index.ts +0 -4
  225. package/src/WAUSync/USyncQuery.ts +0 -133
  226. package/src/WAUSync/USyncUser.ts +0 -32
  227. package/src/WAUSync/index.ts +0 -3
  228. package/src/index.ts +0 -13
@@ -1,32 +1,38 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.QueryIds = exports.XWAPaths = exports.MexOperations = void 0;
4
- var MexOperations;
5
- (function (MexOperations) {
6
- MexOperations["PROMOTE"] = "NotificationNewsletterAdminPromote";
7
- MexOperations["DEMOTE"] = "NotificationNewsletterAdminDemote";
8
- MexOperations["UPDATE"] = "NotificationNewsletterUpdate";
9
- })(MexOperations || (exports.MexOperations = MexOperations = {}));
10
- var XWAPaths;
11
- (function (XWAPaths) {
12
- XWAPaths["PROMOTE"] = "xwa2_notify_newsletter_admin_promote";
13
- XWAPaths["DEMOTE"] = "xwa2_notify_newsletter_admin_demote";
14
- XWAPaths["ADMIN_COUNT"] = "xwa2_newsletter_admin";
15
- XWAPaths["CREATE"] = "xwa2_newsletter_create";
16
- XWAPaths["NEWSLETTER"] = "xwa2_newsletter";
17
- XWAPaths["METADATA_UPDATE"] = "xwa2_notify_newsletter_on_metadata_update";
18
- })(XWAPaths || (exports.XWAPaths = XWAPaths = {}));
19
- var QueryIds;
20
- (function (QueryIds) {
21
- QueryIds["JOB_MUTATION"] = "7150902998257522";
22
- QueryIds["METADATA"] = "6620195908089573";
23
- QueryIds["UNFOLLOW"] = "7238632346214362";
24
- QueryIds["FOLLOW"] = "7871414976211147";
25
- QueryIds["UNMUTE"] = "7337137176362961";
26
- QueryIds["MUTE"] = "25151904754424642";
27
- QueryIds["CREATE"] = "6996806640408138";
28
- QueryIds["ADMIN_COUNT"] = "7130823597031706";
29
- QueryIds["CHANGE_OWNER"] = "7341777602580933";
30
- QueryIds["DELETE"] = "8316537688363079";
31
- QueryIds["DEMOTE"] = "6551828931592903";
32
- })(QueryIds || (exports.QueryIds = QueryIds = {}));
1
+ "use strict"
2
+
3
+ Object.defineProperty(exports, "__esModule", { value: true })
4
+
5
+ const MexOperations = {
6
+ PROMOTE: "NotificationNewsletterAdminPromote",
7
+ DEMOTE: "NotificationNewsletterAdminDemote",
8
+ UPDATE: "NotificationNewsletterUpdate"
9
+ }
10
+
11
+ const XWAPaths = {
12
+ PROMOTE: "xwa2_notify_newsletter_admin_promote",
13
+ DEMOTE: "xwa2_notify_newsletter_admin_demote",
14
+ ADMIN_COUNT: "xwa2_newsletter_admin",
15
+ CREATE: "xwa2_newsletter_create",
16
+ NEWSLETTER: "xwa2_newsletter",
17
+ SUBSCRIBED: "xwa2_newsletter_subscribed",
18
+ METADATA_UPDATE: "xwa2_notify_newsletter_on_metadata_update"
19
+ }
20
+
21
+ const QueryIds = {
22
+ JOB_MUTATION: "7150902998257522",
23
+ METADATA: "6620195908089573",
24
+ UNFOLLOW: "7238632346214362",
25
+ FOLLOW: "7871414976211147",
26
+ UNMUTE: "7337137176362961",
27
+ MUTE: "25151904754424642",
28
+ CREATE: "6996806640408138",
29
+ ADMIN_COUNT: "7130823597031706",
30
+ CHANGE_OWNER: "7341777602580933",
31
+ DELETE: "8316537688363079",
32
+ DEMOTE: "6551828931592903",
33
+ SUBSCRIBED: "6388546374527196"
34
+ }
35
+
36
+ exports.MexOperations = MexOperations
37
+ exports.XWAPaths = XWAPaths
38
+ exports.QueryIds = QueryIds
@@ -1,10 +1,11 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
1
3
  import { AxiosRequestConfig } from 'axios';
2
4
  import type { Agent } from 'https';
3
5
  import type { Logger } from 'pino';
4
6
  import type { URL } from 'url';
5
7
  import { proto } from '../../WAProto';
6
8
  import { AuthenticationState, SignalAuthState, TransactionCapabilityOptions } from './Auth';
7
- import { GroupMetadata } from './GroupMetadata';
8
9
  import { MediaConnInfo } from './Message';
9
10
  import { SignalRepository } from './Signal';
10
11
  export type WAVersion = [number, number, number];
@@ -60,8 +61,6 @@ export type SocketConfig = {
60
61
  transactionOpts: TransactionCapabilityOptions;
61
62
  /** marks the client as online whenever the socket successfully connects */
62
63
  markOnlineOnConnect: boolean;
63
- /** alphanumeric country code (USA -> US) for the number used */
64
- countryCode: string;
65
64
  /** provide a cache to store media, so does not have to be re-uploaded */
66
65
  mediaCache?: CacheStore;
67
66
  /**
@@ -72,8 +71,6 @@ export type SocketConfig = {
72
71
  userDevicesCache?: CacheStore;
73
72
  /** cache to store call offers */
74
73
  callOfferCache?: CacheStore;
75
- /** cache to track placeholder resends */
76
- placeholderResendCache?: CacheStore;
77
74
  /** width for link preview images */
78
75
  linkPreviewImageThumbnailWidth: number;
79
76
  /** Should Baileys ask the phone for full history, will be received async */
@@ -108,8 +105,6 @@ export type SocketConfig = {
108
105
  * (solves the "this message can take a while" issue) can be retried
109
106
  * */
110
107
  getMessage: (key: proto.IMessageKey) => Promise<proto.IMessage | undefined>;
111
- /** cached group metadata, use to prevent redundant requests to WA & speed up msg sending */
112
- cachedGroupMetadata: (jid: string) => Promise<GroupMetadata | undefined>;
113
108
  makeSignalRepository: (auth: SignalAuthState) => SignalRepository;
114
109
  /** Socket passthrough */
115
110
  socket?: any;
@@ -15,15 +15,6 @@ import { SocketConfig } from './Socket';
15
15
  export type UserFacingSocketConfig = Partial<SocketConfig> & {
16
16
  auth: AuthenticationState;
17
17
  };
18
- export type BrowsersMap = {
19
- ubuntu(browser: string): [string, string, string];
20
- macOS(browser: string): [string, string, string];
21
- baileys(browser: string): [string, string, string];
22
- windows(browser: string): [string, string, string];
23
- iOS(browser: string): [string, string, string];
24
- linux(browser: string): [string, string, string];
25
- appropriate(browser: string): [string, string, string];
26
- };
27
18
  export declare enum DisconnectReason {
28
19
  connectionClosed = 428,
29
20
  connectionLost = 408,
@@ -39,4 +39,4 @@ var DisconnectReason;
39
39
  DisconnectReason[DisconnectReason["multideviceMismatch"] = 411] = "multideviceMismatch";
40
40
  DisconnectReason[DisconnectReason["forbidden"] = 403] = "forbidden";
41
41
  DisconnectReason[DisconnectReason["unavailableService"] = 503] = "unavailableService";
42
- })(DisconnectReason || (exports.DisconnectReason = DisconnectReason = {}));
42
+ })(DisconnectReason = exports.DisconnectReason || (exports.DisconnectReason = {}));
@@ -3,8 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.initAuthCreds = exports.addTransactionCapability = void 0;
7
- exports.makeCacheableSignalKeyStore = makeCacheableSignalKeyStore;
6
+ exports.initAuthCreds = exports.addTransactionCapability = exports.makeCacheableSignalKeyStore = void 0;
8
7
  const crypto_1 = require("crypto");
9
8
  const node_cache_1 = __importDefault(require("node-cache"));
10
9
  const uuid_1 = require("uuid");
@@ -19,30 +18,9 @@ const generics_1 = require("./generics");
19
18
  */
20
19
  function makeCacheableSignalKeyStore(store, logger, _cache) {
21
20
  const cache = _cache || new node_cache_1.default({
22
- stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.SIGNAL_STORE,
23
- useClones: false,
24
- deleteOnExpire: true,
25
- checkperiod: 120
26
- });
27
-
28
- cache.on('expired', async (key) => {
29
- const [type, id] = key.split('.');
30
- const item = cache.get(key, { noUpdate: true });
31
- if (item) {
32
- try {
33
- await store.set({
34
- [type]: {
35
- [id]: item
36
- }
37
- });
38
- cache.del(key);
39
- } catch (error) {
40
- logger?.error({
41
- key
42
- }, 'Failed to persist expired cache item');
43
- cache.ttl(key, 60);
44
- }
45
- }
21
+ stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.SIGNAL_STORE,
22
+ useClones: false,
23
+ deleteOnExpire: true,
46
24
  });
47
25
  function getUniqueId(type, id) {
48
26
  return `${type}.${id}`;
@@ -52,7 +30,7 @@ function makeCacheableSignalKeyStore(store, logger, _cache) {
52
30
  const data = {};
53
31
  const idsToFetch = [];
54
32
  for (const id of ids) {
55
- const item = cache.get(getUniqueId(type, id), { noUpdate: true });
33
+ const item = cache.get(getUniqueId(type, id));
56
34
  if (typeof item !== 'undefined') {
57
35
  data[id] = item;
58
36
  }
@@ -61,7 +39,7 @@ function makeCacheableSignalKeyStore(store, logger, _cache) {
61
39
  }
62
40
  }
63
41
  if (idsToFetch.length) {
64
- logger?.trace({ items: idsToFetch.length }, 'loading from store');
42
+ logger.trace({ items: idsToFetch.length }, 'loading from store');
65
43
  const fetched = await store.get(type, idsToFetch);
66
44
  for (const id of idsToFetch) {
67
45
  const item = fetched[id];
@@ -81,7 +59,7 @@ function makeCacheableSignalKeyStore(store, logger, _cache) {
81
59
  keys += 1;
82
60
  }
83
61
  }
84
- logger?.trace({ keys }, 'updated cache');
62
+ logger.trace({ keys }, 'updated cache');
85
63
  await store.set(data);
86
64
  },
87
65
  async clear() {
@@ -91,6 +69,7 @@ function makeCacheableSignalKeyStore(store, logger, _cache) {
91
69
  }
92
70
  };
93
71
  }
72
+ exports.makeCacheableSignalKeyStore = makeCacheableSignalKeyStore;
94
73
  /**
95
74
  * Adds DB like transaction capability (https://en.wikipedia.org/wiki/Database_transaction) to the SignalKeyStore,
96
75
  * this allows batch read & write operations & improves the performance of the lib
@@ -134,7 +113,7 @@ const addTransactionCapability = (state, logger, { maxCommitRetries, delayBetwee
134
113
  },
135
114
  set: data => {
136
115
  if (isInTransaction()) {
137
- logger?.trace({ types: Object.keys(data) }, 'caching in transaction');
116
+ logger.trace({ types: Object.keys(data) }, 'caching in transaction');
138
117
  for (const key in data) {
139
118
  transactionCache[key] = transactionCache[key] || {};
140
119
  Object.assign(transactionCache[key], data[key]);
@@ -151,14 +130,14 @@ const addTransactionCapability = (state, logger, { maxCommitRetries, delayBetwee
151
130
  let result;
152
131
  transactionsInProgress += 1;
153
132
  if (transactionsInProgress === 1) {
154
- logger?.trace('entering transaction');
133
+ logger.trace('entering transaction');
155
134
  }
156
135
  try {
157
136
  result = await work();
158
137
  // commit if this is the outermost transaction
159
138
  if (transactionsInProgress === 1) {
160
139
  if (Object.keys(mutations).length) {
161
- logger?.trace('committing transaction');
140
+ logger.trace('committing transaction');
162
141
  // retry mechanism to ensure we've some recovery
163
142
  // in case a transaction fails in the first attempt
164
143
  let tries = maxCommitRetries;
@@ -166,17 +145,17 @@ const addTransactionCapability = (state, logger, { maxCommitRetries, delayBetwee
166
145
  tries -= 1;
167
146
  try {
168
147
  await state.set(mutations);
169
- logger?.trace({ dbQueriesInTransaction }, 'committed transaction');
148
+ logger.trace({ dbQueriesInTransaction }, 'committed transaction');
170
149
  break;
171
150
  }
172
151
  catch (error) {
173
- logger?.warn(`failed to commit ${Object.keys(mutations).length} mutations, tries left=${tries}`);
152
+ logger.warn(`failed to commit ${Object.keys(mutations).length} mutations, tries left=${tries}`);
174
153
  await (0, generics_1.delay)(delayBetweenTriesMs);
175
154
  }
176
155
  }
177
156
  }
178
157
  else {
179
- logger?.trace('no mutations in transaction');
158
+ logger.trace('no mutations in transaction');
180
159
  }
181
160
  }
182
161
  }
@@ -2,7 +2,7 @@ import { CatalogCollection, OrderDetails, Product, ProductCreate, ProductUpdate,
2
2
  import { BinaryNode } from '../WABinary';
3
3
  export declare const parseCatalogNode: (node: BinaryNode) => {
4
4
  products: Product[];
5
- nextPageCursor: any;
5
+ nextPageCursor: string | undefined;
6
6
  };
7
7
  export declare const parseCollectionsNode: (node: BinaryNode) => {
8
8
  collections: CatalogCollection[];
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.uploadingNecessaryImages = exports.parseProductNode = exports.toProductNode = exports.parseOrderDetailsNode = exports.parseCollectionsNode = exports.parseCatalogNode = void 0;
4
- exports.uploadingNecessaryImagesOfProduct = uploadingNecessaryImagesOfProduct;
3
+ exports.uploadingNecessaryImages = exports.uploadingNecessaryImagesOfProduct = exports.parseProductNode = exports.toProductNode = exports.parseOrderDetailsNode = exports.parseCollectionsNode = exports.parseCatalogNode = void 0;
5
4
  const boom_1 = require("@hapi/boom");
6
5
  const crypto_1 = require("crypto");
7
6
  const WABinary_1 = require("../WABinary");
@@ -189,6 +188,7 @@ async function uploadingNecessaryImagesOfProduct(product, waUploadToServer, time
189
188
  };
190
189
  return product;
191
190
  }
191
+ exports.uploadingNecessaryImagesOfProduct = uploadingNecessaryImagesOfProduct;
192
192
  /**
193
193
  * Uploads images not already uploaded to WA's servers
194
194
  */
@@ -1,3 +1,4 @@
1
+ /// <reference types="node" />
1
2
  import { AxiosRequestConfig } from 'axios';
2
3
  import type { Logger } from 'pino';
3
4
  import { proto } from '../../WAProto';
@@ -13,7 +14,7 @@ export declare const encodeSyncdPatch: ({ type, index, syncAction, apiVersion, o
13
14
  state: LTHashState;
14
15
  }>;
15
16
  export declare const decodeSyncdMutations: (msgMutations: (proto.ISyncdMutation | proto.ISyncdRecord)[], initialState: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey, onMutation: (mutation: ChatMutation) => void, validateMacs: boolean) => Promise<{
16
- hash: any;
17
+ hash: Buffer;
17
18
  indexValueMap: {
18
19
  [indexMacBase64: string]: {
19
20
  valueMac: Uint8Array | Buffer;
@@ -21,47 +22,47 @@ export declare const decodeSyncdMutations: (msgMutations: (proto.ISyncdMutation
21
22
  };
22
23
  }>;
23
24
  export declare const decodeSyncdPatch: (msg: proto.ISyncdPatch, name: WAPatchName, initialState: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey, onMutation: (mutation: ChatMutation) => void, validateMacs: boolean) => Promise<{
24
- hash: any;
25
+ hash: Buffer;
25
26
  indexValueMap: {
26
27
  [indexMacBase64: string]: {
27
28
  valueMac: Uint8Array | Buffer;
28
29
  };
29
30
  };
30
31
  }>;
31
- export declare const extractSyncdPatches: (result: BinaryNode, options: AxiosRequestConfig<{}>) => Promise<{
32
+ export declare const extractSyncdPatches: (result: BinaryNode, options: AxiosRequestConfig<any>) => Promise<{
32
33
  critical_block: {
33
34
  patches: proto.ISyncdPatch[];
34
35
  hasMorePatches: boolean;
35
- snapshot?: proto.ISyncdSnapshot;
36
+ snapshot?: proto.ISyncdSnapshot | undefined;
36
37
  };
37
38
  critical_unblock_low: {
38
39
  patches: proto.ISyncdPatch[];
39
40
  hasMorePatches: boolean;
40
- snapshot?: proto.ISyncdSnapshot;
41
+ snapshot?: proto.ISyncdSnapshot | undefined;
41
42
  };
42
43
  regular_high: {
43
44
  patches: proto.ISyncdPatch[];
44
45
  hasMorePatches: boolean;
45
- snapshot?: proto.ISyncdSnapshot;
46
+ snapshot?: proto.ISyncdSnapshot | undefined;
46
47
  };
47
48
  regular_low: {
48
49
  patches: proto.ISyncdPatch[];
49
50
  hasMorePatches: boolean;
50
- snapshot?: proto.ISyncdSnapshot;
51
+ snapshot?: proto.ISyncdSnapshot | undefined;
51
52
  };
52
53
  regular: {
53
54
  patches: proto.ISyncdPatch[];
54
55
  hasMorePatches: boolean;
55
- snapshot?: proto.ISyncdSnapshot;
56
+ snapshot?: proto.ISyncdSnapshot | undefined;
56
57
  };
57
58
  }>;
58
- export declare const downloadExternalBlob: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<{}>) => Promise<any>;
59
- export declare const downloadExternalPatch: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<{}>) => Promise<proto.SyncdMutations>;
59
+ export declare const downloadExternalBlob: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<any>) => Promise<Buffer>;
60
+ export declare const downloadExternalPatch: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<any>) => Promise<proto.SyncdMutations>;
60
61
  export declare const decodeSyncdSnapshot: (name: WAPatchName, snapshot: proto.ISyncdSnapshot, getAppStateSyncKey: FetchAppStateSyncKey, minimumVersionNumber: number | undefined, validateMacs?: boolean) => Promise<{
61
62
  state: LTHashState;
62
63
  mutationMap: ChatMutationMap;
63
64
  }>;
64
- export declare const decodePatches: (name: WAPatchName, syncds: proto.ISyncdPatch[], initial: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey, options: AxiosRequestConfig<{}>, minimumVersionNumber?: number, logger?: Logger, validateMacs?: boolean) => Promise<{
65
+ export declare const decodePatches: (name: WAPatchName, syncds: proto.ISyncdPatch[], initial: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey, options: AxiosRequestConfig<any>, minimumVersionNumber?: number, logger?: Logger, validateMacs?: boolean) => Promise<{
65
66
  state: LTHashState;
66
67
  mutationMap: ChatMutationMap;
67
68
  }>;
@@ -9,8 +9,8 @@ const crypto_1 = require("./crypto");
9
9
  const generics_1 = require("./generics");
10
10
  const lt_hash_1 = require("./lt-hash");
11
11
  const messages_media_1 = require("./messages-media");
12
- const mutationKeys = async (keydata) => {
13
- const expanded = await (0, crypto_1.hkdf)(keydata, 160, { info: 'WhatsApp Mutation Keys' });
12
+ const mutationKeys = (keydata) => {
13
+ const expanded = (0, crypto_1.hkdf)(keydata, 160, { info: 'WhatsApp Mutation Keys' });
14
14
  return {
15
15
  indexKey: expanded.slice(0, 32),
16
16
  valueEncryptionKey: expanded.slice(32, 64),
@@ -69,9 +69,9 @@ const makeLtHashGenerator = ({ indexValueMap, hash }) => {
69
69
  subBuffs.push(new Uint8Array(prevOp.valueMac).buffer);
70
70
  }
71
71
  },
72
- finish: async () => {
72
+ finish: () => {
73
73
  const hashArrayBuffer = new Uint8Array(hash).buffer;
74
- const result = await lt_hash_1.LT_HASH_ANTI_TAMPERING.subtractThenAdd(hashArrayBuffer, addBuffs, subBuffs);
74
+ const result = lt_hash_1.LT_HASH_ANTI_TAMPERING.subtractThenAdd(hashArrayBuffer, addBuffs, subBuffs);
75
75
  const buffer = Buffer.from(result);
76
76
  return {
77
77
  hash: buffer,
@@ -114,14 +114,14 @@ const encodeSyncdPatch = async ({ type, index, syncAction, apiVersion, operation
114
114
  version: apiVersion
115
115
  });
116
116
  const encoded = WAProto_1.proto.SyncActionData.encode(dataProto).finish();
117
- const keyValue = await mutationKeys(key.keyData);
117
+ const keyValue = mutationKeys(key.keyData);
118
118
  const encValue = (0, crypto_1.aesEncrypt)(encoded, keyValue.valueEncryptionKey);
119
119
  const valueMac = generateMac(operation, encValue, encKeyId, keyValue.valueMacKey);
120
120
  const indexMac = (0, crypto_1.hmacSign)(indexBuffer, keyValue.indexKey);
121
121
  // update LT hash
122
122
  const generator = makeLtHashGenerator(state);
123
123
  generator.mix({ indexMac, valueMac, operation });
124
- Object.assign(state, await generator.finish());
124
+ Object.assign(state, generator.finish());
125
125
  state.version += 1;
126
126
  const snapshotMac = generateSnapshotMac(state.hash, state.version, type, keyValue.snapshotMacKey);
127
127
  const patch = {
@@ -184,7 +184,7 @@ const decodeSyncdMutations = async (msgMutations, initialState, getAppStateSyncK
184
184
  operation: operation
185
185
  });
186
186
  }
187
- return await ltGenerator.finish();
187
+ return ltGenerator.finish();
188
188
  async function getKey(keyId) {
189
189
  const base64Key = Buffer.from(keyId).toString('base64');
190
190
  const keyEnc = await getAppStateSyncKey(base64Key);
@@ -202,7 +202,7 @@ const decodeSyncdPatch = async (msg, name, initialState, getAppStateSyncKey, onM
202
202
  if (!mainKeyObj) {
203
203
  throw new boom_1.Boom(`failed to find key "${base64Key}" to decode patch`, { statusCode: 404, data: { msg } });
204
204
  }
205
- const mainKey = await mutationKeys(mainKeyObj.keyData);
205
+ const mainKey = mutationKeys(mainKeyObj.keyData);
206
206
  const mutationmacs = msg.mutations.map(mutation => mutation.record.value.blob.slice(-32));
207
207
  const patchMac = generatePatchMac(msg.snapshotMac, mutationmacs, (0, generics_1.toNumber)(msg.version.version), name, mainKey.patchMacKey);
208
208
  if (Buffer.compare(patchMac, msg.patchMac) !== 0) {
@@ -286,7 +286,7 @@ const decodeSyncdSnapshot = async (name, snapshot, getAppStateSyncKey, minimumVe
286
286
  if (!keyEnc) {
287
287
  throw new boom_1.Boom(`failed to find key "${base64Key}" to decode mutation`);
288
288
  }
289
- const result = await mutationKeys(keyEnc.keyData);
289
+ const result = mutationKeys(keyEnc.keyData);
290
290
  const computedSnapshotMac = generateSnapshotMac(newState.hash, newState.version, name, result.snapshotMacKey);
291
291
  if (Buffer.compare(snapshot.mac, computedSnapshotMac) !== 0) {
292
292
  throw new boom_1.Boom(`failed to verify LTHash at ${newState.version} of ${name} from snapshot`);
@@ -305,7 +305,8 @@ const decodePatches = async (name, syncds, initial, getAppStateSyncKey, options,
305
305
  indexValueMap: { ...initial.indexValueMap }
306
306
  };
307
307
  const mutationMap = {};
308
- for (const syncd of syncds) {
308
+ for (let i = 0; i < syncds.length; i++) {
309
+ const syncd = syncds[i];
309
310
  const { version, keyId, snapshotMac } = syncd;
310
311
  if (syncd.externalMutations) {
311
312
  logger === null || logger === void 0 ? void 0 : logger.trace({ name, version }, 'downloading external patch');
@@ -331,7 +332,7 @@ const decodePatches = async (name, syncds, initial, getAppStateSyncKey, options,
331
332
  if (!keyEnc) {
332
333
  throw new boom_1.Boom(`failed to find key "${base64Key}" to decode mutation`);
333
334
  }
334
- const result = await mutationKeys(keyEnc.keyData);
335
+ const result = mutationKeys(keyEnc.keyData);
335
336
  const computedSnapshotMac = generateSnapshotMac(newState.hash, newState.version, name, result.snapshotMacKey);
336
337
  if (Buffer.compare(snapshotMac, computedSnapshotMac) !== 0) {
337
338
  throw new boom_1.Boom(`failed to verify LTHash at ${newState.version} of ${name}`);
@@ -417,31 +418,25 @@ const chatModificationToAppPatch = (mod, jid) => {
417
418
  operation: OP.SET
418
419
  };
419
420
  }
420
- else if ('deleteForMe' in mod) {
421
- const { timestamp, key, deleteMedia } = mod.deleteForMe;
422
- patch = {
423
- syncAction: {
424
- deleteMessageForMeAction: {
425
- deleteMedia,
426
- messageTimestamp: timestamp
427
- }
428
- },
429
- index: ['deleteMessageForMe', jid, key.id, key.fromMe ? '1' : '0', '0'],
430
- type: 'regular_high',
431
- apiVersion: 3,
432
- operation: OP.SET
433
- };
434
- }
435
421
  else if ('clear' in mod) {
436
- patch = {
437
- syncAction: {
438
- clearChatAction: {} // add message range later
439
- },
440
- index: ['clearChat', jid, '1' /*the option here is 0 when keep starred messages is enabled*/, '0'],
441
- type: 'regular_high',
442
- apiVersion: 6,
443
- operation: OP.SET
444
- };
422
+ if (mod.clear === 'all') {
423
+ throw new boom_1.Boom('not supported');
424
+ }
425
+ else {
426
+ const key = mod.clear.messages[0];
427
+ patch = {
428
+ syncAction: {
429
+ deleteMessageForMeAction: {
430
+ deleteMedia: false,
431
+ messageTimestamp: key.timestamp
432
+ }
433
+ },
434
+ index: ['deleteMessageForMe', jid, key.id, key.fromMe ? '1' : '0', '0'],
435
+ type: 'regular_high',
436
+ apiVersion: 3,
437
+ operation: OP.SET
438
+ };
439
+ }
445
440
  }
446
441
  else if ('pin' in mod) {
447
442
  patch = {
@@ -496,22 +491,6 @@ const chatModificationToAppPatch = (mod, jid) => {
496
491
  operation: OP.SET,
497
492
  };
498
493
  }
499
- else if ('addLabel' in mod) {
500
- patch = {
501
- syncAction: {
502
- labelEditAction: {
503
- name: mod.addLabel.name,
504
- color: mod.addLabel.color,
505
- predefinedId: mod.addLabel.predefinedId,
506
- deleted: mod.addLabel.deleted
507
- }
508
- },
509
- index: ['label_edit', mod.addLabel.id],
510
- type: 'regular',
511
- apiVersion: 3,
512
- operation: OP.SET,
513
- };
514
- }
515
494
  else if ('addChatLabel' in mod) {
516
495
  patch = {
517
496
  syncAction: {
@@ -654,7 +633,12 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
654
633
  });
655
634
  }
656
635
  else if (action === null || action === void 0 ? void 0 : action.contactAction) {
657
- ev.emit('contacts.upsert', [{ id, name: action.contactAction.fullName }]);
636
+ ev.emit('contacts.upsert', [{
637
+ id: id,
638
+ name: action.contactAction.fullName,
639
+ lid: action.contactAction.lidJid || undefined,
640
+ jid: (0, WABinary_1.isJidUser)(id) ? id : undefined
641
+ }]);
658
642
  }
659
643
  else if (action === null || action === void 0 ? void 0 : action.pushNameSetting) {
660
644
  const name = (_b = action === null || action === void 0 ? void 0 : action.pushNameSetting) === null || _b === void 0 ? void 0 : _b.name;
@@ -1,9 +1,10 @@
1
+ /// <reference types="node" />
1
2
  import { KeyPair } from '../Types';
2
3
  /** prefix version byte to the pub keys, required for some curve crypto functions */
3
- export declare const generateSignalPubKey: (pubKey: Uint8Array | Buffer) => any;
4
+ export declare const generateSignalPubKey: (pubKey: Uint8Array | Buffer) => Uint8Array | Buffer;
4
5
  export declare const Curve: {
5
6
  generateKeyPair: () => KeyPair;
6
- sharedKey: (privateKey: Uint8Array, publicKey: Uint8Array) => any;
7
+ sharedKey: (privateKey: Uint8Array, publicKey: Uint8Array) => Buffer;
7
8
  sign: (privateKey: Uint8Array, buf: Uint8Array) => any;
8
9
  verify: (pubKey: Uint8Array, message: Uint8Array, signature: Uint8Array) => boolean;
9
10
  };
@@ -16,25 +17,25 @@ export declare const signedKeyPair: (identityKeyPair: KeyPair, keyId: number) =>
16
17
  * encrypt AES 256 GCM;
17
18
  * where the tag tag is suffixed to the ciphertext
18
19
  * */
19
- export declare function aesEncryptGCM(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array): any;
20
+ export declare function aesEncryptGCM(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array): Buffer;
20
21
  /**
21
22
  * decrypt AES 256 GCM;
22
23
  * where the auth tag is suffixed to the ciphertext
23
24
  * */
24
- export declare function aesDecryptGCM(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array): any;
25
- export declare function aesEncryptCTR(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array): any;
26
- export declare function aesDecryptCTR(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array): any;
25
+ export declare function aesDecryptGCM(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array): Buffer;
26
+ export declare function aesEncryptCTR(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array): Buffer;
27
+ export declare function aesDecryptCTR(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array): Buffer;
27
28
  /** decrypt AES 256 CBC; where the IV is prefixed to the buffer */
28
- export declare function aesDecrypt(buffer: Buffer, key: Buffer): any;
29
+ export declare function aesDecrypt(buffer: Buffer, key: Buffer): Buffer;
29
30
  /** decrypt AES 256 CBC */
30
- export declare function aesDecryptWithIV(buffer: Buffer, key: Buffer, IV: Buffer): any;
31
- export declare function aesEncrypt(buffer: Buffer | Uint8Array, key: Buffer): any;
32
- export declare function aesEncrypWithIV(buffer: Buffer, key: Buffer, IV: Buffer): any;
33
- export declare function hmacSign(buffer: Buffer | Uint8Array, key: Buffer | Uint8Array, variant?: 'sha256' | 'sha512'): any;
34
- export declare function sha256(buffer: Buffer): any;
35
- export declare function md5(buffer: Buffer): any;
31
+ export declare function aesDecryptWithIV(buffer: Buffer, key: Buffer, IV: Buffer): Buffer;
32
+ export declare function aesEncrypt(buffer: Buffer | Uint8Array, key: Buffer): Buffer;
33
+ export declare function aesEncrypWithIV(buffer: Buffer, key: Buffer, IV: Buffer): Buffer;
34
+ export declare function hmacSign(buffer: Buffer | Uint8Array, key: Buffer | Uint8Array, variant?: 'sha256' | 'sha512'): Buffer;
35
+ export declare function sha256(buffer: Buffer): Buffer;
36
+ export declare function md5(buffer: Buffer): Buffer;
36
37
  export declare function hkdf(buffer: Uint8Array | Buffer, expandedLength: number, info: {
37
38
  salt?: Buffer;
38
39
  info?: string;
39
- }): any;
40
- export declare function derivePairingCodeKey(pairingCode: string, salt: Buffer): Promise<any>;
40
+ }): Buffer;
41
+ export declare function derivePairingCodeKey(pairingCode: string, salt: Buffer): Buffer;