asepxyz12 1.0.0

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 (181) hide show
  1. package/LICENSE +25 -0
  2. package/README.md +2579 -0
  3. package/WAProto/AICommon/AICommon.js +19396 -0
  4. package/WAProto/AICommon/AICommon.proto +820 -0
  5. package/WAProto/Adv/Adv.js +1137 -0
  6. package/WAProto/Adv/Adv.proto +42 -0
  7. package/WAProto/BotMetadata/BotMetadata.js +8975 -0
  8. package/WAProto/BotMetadata/BotMetadata.proto +484 -0
  9. package/WAProto/Cert/Cert.js +893 -0
  10. package/WAProto/Cert/Cert.proto +30 -0
  11. package/WAProto/ChatLockSettings/ChatLockSettings.js +673 -0
  12. package/WAProto/ChatLockSettings/ChatLockSettings.proto +9 -0
  13. package/WAProto/CompanionReg/CompanionReg.js +2457 -0
  14. package/WAProto/CompanionReg/CompanionReg.proto +103 -0
  15. package/WAProto/DeviceCapabilities/DeviceCapabilities.js +846 -0
  16. package/WAProto/DeviceCapabilities/DeviceCapabilities.proto +38 -0
  17. package/WAProto/E2E/E2E.js +78728 -0
  18. package/WAProto/E2E/E2E.proto +1970 -0
  19. package/WAProto/Ephemeral/Ephemeral.js +143 -0
  20. package/WAProto/Ephemeral/Ephemeral.proto +7 -0
  21. package/WAProto/HistorySync/HistorySync.js +95931 -0
  22. package/WAProto/HistorySync/HistorySync.proto +229 -0
  23. package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.js +414 -0
  24. package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.proto +13 -0
  25. package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.js +980 -0
  26. package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.proto +38 -0
  27. package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.js +81185 -0
  28. package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.proto +88 -0
  29. package/WAProto/MmsRetry/MmsRetry.js +310 -0
  30. package/WAProto/MmsRetry/MmsRetry.proto +19 -0
  31. package/WAProto/Protocol/Protocol.js +399 -0
  32. package/WAProto/Protocol/Protocol.proto +22 -0
  33. package/WAProto/Reporting/Reporting.js +535 -0
  34. package/WAProto/Reporting/Reporting.proto +22 -0
  35. package/WAProto/ServerSync/ServerSync.js +1830 -0
  36. package/WAProto/ServerSync/ServerSync.proto +70 -0
  37. package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.js +3267 -0
  38. package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.proto +95 -0
  39. package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.js +1140 -0
  40. package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.proto +44 -0
  41. package/WAProto/StatusAttributions/StatusAttributions.js +1604 -0
  42. package/WAProto/StatusAttributions/StatusAttributions.proto +89 -0
  43. package/WAProto/SyncAction/SyncAction.js +17424 -0
  44. package/WAProto/SyncAction/SyncAction.proto +663 -0
  45. package/WAProto/UserPassword/UserPassword.js +544 -0
  46. package/WAProto/UserPassword/UserPassword.proto +28 -0
  47. package/WAProto/VnameCert/VnameCert.js +1466 -0
  48. package/WAProto/VnameCert/VnameCert.proto +65 -0
  49. package/WAProto/Wa6/Wa6.js +4601 -0
  50. package/WAProto/Wa6/Wa6.proto +241 -0
  51. package/WAProto/Web/Web.js +90819 -0
  52. package/WAProto/Web/Web.proto +605 -0
  53. package/WAProto/index.js +30 -0
  54. package/engine-requirements.js +9 -0
  55. package/lib/Defaults/baileys-version.json +3 -0
  56. package/lib/Defaults/connection.js +39 -0
  57. package/lib/Defaults/constants.js +50 -0
  58. package/lib/Defaults/history.js +13 -0
  59. package/lib/Defaults/index.js +36 -0
  60. package/lib/Defaults/media.js +43 -0
  61. package/lib/Defaults/phonenumber-mcc.json +223 -0
  62. package/lib/Defaults/prefix.js +12 -0
  63. package/lib/Function/Download/tiktok.js +19 -0
  64. package/lib/Function/Tools/bypass.js +19 -0
  65. package/lib/Function/index.js +13 -0
  66. package/lib/Signal/Group/ciphertext-message.js +14 -0
  67. package/lib/Signal/Group/group-session-builder.js +46 -0
  68. package/lib/Signal/Group/group_cipher.js +104 -0
  69. package/lib/Signal/Group/index.js +42 -0
  70. package/lib/Signal/Group/keyhelper.js +21 -0
  71. package/lib/Signal/Group/queue-job.js +57 -0
  72. package/lib/Signal/Group/sender-chain-key.js +34 -0
  73. package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
  74. package/lib/Signal/Group/sender-key-message.js +78 -0
  75. package/lib/Signal/Group/sender-key-name.js +49 -0
  76. package/lib/Signal/Group/sender-key-record.js +45 -0
  77. package/lib/Signal/Group/sender-key-state.js +100 -0
  78. package/lib/Signal/Group/sender-message-key.js +28 -0
  79. package/lib/Signal/libsignal.js +364 -0
  80. package/lib/Signal/lid-mapping.js +164 -0
  81. package/lib/Socket/Client/abstract-socket-client.js +13 -0
  82. package/lib/Socket/Client/index.js +31 -0
  83. package/lib/Socket/Client/mobile-socket-client.js +65 -0
  84. package/lib/Socket/Client/types.js +12 -0
  85. package/lib/Socket/Client/web-socket-client.js +62 -0
  86. package/lib/Socket/Client/websocket.js +67 -0
  87. package/lib/Socket/business.js +291 -0
  88. package/lib/Socket/chats.js +874 -0
  89. package/lib/Socket/community.js +454 -0
  90. package/lib/Socket/dugong.js +658 -0
  91. package/lib/Socket/groups.js +357 -0
  92. package/lib/Socket/index.js +13 -0
  93. package/lib/Socket/messages-recv.js +1509 -0
  94. package/lib/Socket/messages-send.js +1505 -0
  95. package/lib/Socket/mex.js +54 -0
  96. package/lib/Socket/newsletter.js +171 -0
  97. package/lib/Socket/registration.js +167 -0
  98. package/lib/Socket/rich-content.js +279 -0
  99. package/lib/Socket/socket.js +905 -0
  100. package/lib/Socket/username.js +157 -0
  101. package/lib/Store/index.js +37 -0
  102. package/lib/Store/keyed-db.js +114 -0
  103. package/lib/Store/make-cache-manager-store.js +77 -0
  104. package/lib/Store/make-in-memory-store.js +423 -0
  105. package/lib/Store/make-ordered-dictionary.js +78 -0
  106. package/lib/Store/object-repository.js +26 -0
  107. package/lib/Types/Auth.js +2 -0
  108. package/lib/Types/Bussines.js +2 -0
  109. package/lib/Types/Call.js +2 -0
  110. package/lib/Types/Chat.js +10 -0
  111. package/lib/Types/Contact.js +2 -0
  112. package/lib/Types/Events.js +2 -0
  113. package/lib/Types/GroupMetadata.js +2 -0
  114. package/lib/Types/Label.js +25 -0
  115. package/lib/Types/LabelAssociation.js +4 -0
  116. package/lib/Types/Message.js +11 -0
  117. package/lib/Types/Mex.js +40 -0
  118. package/lib/Types/MexUpdates.js +15 -0
  119. package/lib/Types/Newsletter.js +32 -0
  120. package/lib/Types/Product.js +2 -0
  121. package/lib/Types/Signal.js +2 -0
  122. package/lib/Types/Socket.js +2 -0
  123. package/lib/Types/State.js +9 -0
  124. package/lib/Types/USync.js +2 -0
  125. package/lib/Types/index.js +60 -0
  126. package/lib/Utils/auth-utils.js +256 -0
  127. package/lib/Utils/browser-utils.js +29 -0
  128. package/lib/Utils/business.js +233 -0
  129. package/lib/Utils/chat-utils.js +904 -0
  130. package/lib/Utils/companion-reg-client-utils.js +41 -0
  131. package/lib/Utils/crypto.js +144 -0
  132. package/lib/Utils/decode-wa-message.js +305 -0
  133. package/lib/Utils/event-buffer.js +555 -0
  134. package/lib/Utils/generics.js +411 -0
  135. package/lib/Utils/history.js +100 -0
  136. package/lib/Utils/identity-change-handler.js +53 -0
  137. package/lib/Utils/index.js +57 -0
  138. package/lib/Utils/link-preview.js +76 -0
  139. package/lib/Utils/logger.js +4 -0
  140. package/lib/Utils/lt-hash.js +45 -0
  141. package/lib/Utils/make-mutex.js +33 -0
  142. package/lib/Utils/message-composer.js +289 -0
  143. package/lib/Utils/message-retry-manager.js +134 -0
  144. package/lib/Utils/messages-media.js +806 -0
  145. package/lib/Utils/messages.js +1908 -0
  146. package/lib/Utils/noise-handler.js +157 -0
  147. package/lib/Utils/offline-node-processor.js +42 -0
  148. package/lib/Utils/pre-key-manager.js +86 -0
  149. package/lib/Utils/process-message.js +814 -0
  150. package/lib/Utils/reporting-utils.js +264 -0
  151. package/lib/Utils/signal.js +183 -0
  152. package/lib/Utils/stanza-ack.js +36 -0
  153. package/lib/Utils/sync-action-utils.js +52 -0
  154. package/lib/Utils/tc-token-utils.js +167 -0
  155. package/lib/Utils/use-multi-file-auth-state.js +104 -0
  156. package/lib/Utils/validate-connection.js +229 -0
  157. package/lib/Utils/vialeys-event-stream.js +41 -0
  158. package/lib/WABinary/constants.js +1308 -0
  159. package/lib/WABinary/decode.js +233 -0
  160. package/lib/WABinary/encode.js +212 -0
  161. package/lib/WABinary/generic-utils.js +124 -0
  162. package/lib/WABinary/index.js +36 -0
  163. package/lib/WABinary/jid-utils.js +101 -0
  164. package/lib/WABinary/types.js +2 -0
  165. package/lib/WAM/BinaryInfo.js +12 -0
  166. package/lib/WAM/constants.js +20491 -0
  167. package/lib/WAM/encode.js +148 -0
  168. package/lib/WAM/index.js +34 -0
  169. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +62 -0
  170. package/lib/WAUSync/Protocols/USyncContactProtocol.js +38 -0
  171. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +50 -0
  172. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +25 -0
  173. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +24 -0
  174. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +32 -0
  175. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +24 -0
  176. package/lib/WAUSync/Protocols/index.js +38 -0
  177. package/lib/WAUSync/USyncQuery.js +97 -0
  178. package/lib/WAUSync/USyncUser.js +33 -0
  179. package/lib/WAUSync/index.js +34 -0
  180. package/lib/index.js +113 -0
  181. package/package.json +100 -0
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const XWAPaths = {
4
+ CREATE: "xwa2_newsletter_create",
5
+ SUBSCRIBERS: "xwa2_newsletter_subscribers",
6
+ VIEW: "xwa2_newsletter_view",
7
+ METADATA: "xwa2_newsletter",
8
+ UPDATE: "xwa2_newsletter_update",
9
+ ADMIN_COUNT: "xwa2_newsletter_admin",
10
+ MUTE_V2: "xwa2_newsletter_mute_v2",
11
+ UNMUTE_V2: "xwa2_newsletter_unmute_v2",
12
+ FOLLOW: "xwa2_newsletter_follow",
13
+ UNFOLLOW: "xwa2_newsletter_unfollow",
14
+ CHANGE_OWNER: "xwa2_newsletter_change_owner",
15
+ DEMOTE: "xwa2_newsletter_demote",
16
+ DELETE_V2: "xwa2_newsletter_delete_v2",
17
+ };
18
+ const QueryIds = {
19
+ CREATE: "8823471724422422",
20
+ UPDATE_METADATA: "24250201037901610",
21
+ METADATA: "6563316087068696",
22
+ SUBSCRIBERS: "9783111038412085",
23
+ FOLLOW: "7871414976211147",
24
+ UNFOLLOW: "7238632346214362",
25
+ MUTE: "29766401636284406",
26
+ UNMUTE: "9864994326891137",
27
+ ADMIN_COUNT: "7130823597031706",
28
+ CHANGE_OWNER: "7341777602580933",
29
+ DEMOTE: "6551828931592903",
30
+ DELETE: "30062808666639665",
31
+ };
32
+ module.exports = { XWAPaths: XWAPaths, QueryIds: QueryIds };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const SyncState = {
4
+ Connecting: 0,
5
+ AwaitingInitialSync: 1,
6
+ Syncing: 2,
7
+ Online: 3,
8
+ };
9
+ module.exports = { SyncState: SyncState };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ const __createBinding =
3
+ (this && this.__createBinding) ||
4
+ (Object.create
5
+ ? function (o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ let desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = {
10
+ enumerable: true,
11
+ get: function () {
12
+ return m[k];
13
+ },
14
+ };
15
+ }
16
+ Object.defineProperty(o, k2, desc);
17
+ }
18
+ : function (o, m, k, k2) {
19
+ if (k2 === undefined) k2 = k;
20
+ o[k2] = m[k];
21
+ });
22
+ const __exportStar =
23
+ (this && this.__exportStar) ||
24
+ function (m, exports) {
25
+ for (var p in m) {
26
+ if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) {
27
+ __createBinding(exports, m, p);
28
+ }
29
+ }
30
+ };
31
+ Object.defineProperty(exports, "__esModule", { value: true });
32
+ exports.DisconnectReason = null;
33
+ __exportStar(require("./Auth"), exports);
34
+ __exportStar(require("./Bussines"), exports);
35
+ __exportStar(require("./Chat"), exports);
36
+ __exportStar(require("./Contact"), exports);
37
+ __exportStar(require("./GroupMetadata"), exports);
38
+ __exportStar(require("./State"), exports);
39
+ __exportStar(require("./MexUpdates"), exports);
40
+ __exportStar(require("./Message"), exports);
41
+ __exportStar(require("./Newsletter"), exports);
42
+ __exportStar(require("./Mex"), exports);
43
+ __exportStar(require("./Socket"), exports);
44
+ __exportStar(require("./Events"), exports);
45
+ __exportStar(require("./Product"), exports);
46
+ __exportStar(require("./Call"), exports);
47
+ __exportStar(require("./Signal"), exports);
48
+ const DisconnectReason = {
49
+ connectionClosed: 428,
50
+ connectionLost: 408,
51
+ connectionReplaced: 440,
52
+ timedOut: 408,
53
+ loggedOut: 401,
54
+ badSession: 500,
55
+ restartRequired: 515,
56
+ multideviceMismatch: 411,
57
+ forbidden: 403,
58
+ unavailableService: 503,
59
+ };
60
+ exports.DisconnectReason = DisconnectReason;
@@ -0,0 +1,256 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const { randomBytes: randomBytes } = require("crypto");
4
+ const { default: PQueue } = require("p-queue");
5
+ const { default: NodeCache } = require("@cacheable/node-cache");
6
+ const { DEFAULT_CACHE_TTLS: DEFAULT_CACHE_TTLS } = require("../Defaults/constants");
7
+ const { AsyncLocalStorage: AsyncLocalStorage } = require("async_hooks");
8
+ const { LRUCache: LRUCache } = require("lru-cache");
9
+ const { Mutex: Mutex } = require("async-mutex");
10
+ const { Curve: Curve, signedKeyPair: signedKeyPair } = require("./crypto");
11
+ const { delay: delay, generateRegistrationId: generateRegistrationId } = require("./generics");
12
+ const { PreKeyManager: PreKeyManager } = require("./pre-key-manager");
13
+ function makeCacheableSignalKeyStore(store, logger, _cache) {
14
+ const cache =
15
+ _cache ||
16
+ new NodeCache({
17
+ stdTTL: DEFAULT_CACHE_TTLS.SIGNAL_STORE,
18
+ useClones: false,
19
+ deleteOnExpire: true,
20
+ });
21
+ const cacheMutex = new Mutex();
22
+ function getUniqueId(type, id) {
23
+ return `${type}.${id}`;
24
+ }
25
+ return {
26
+ async get(type, ids) {
27
+ return cacheMutex.runExclusive(async () => {
28
+ const data = {};
29
+ const idsToFetch = [];
30
+ for (const id of ids) {
31
+ const item = cache.get(getUniqueId(type, id));
32
+ if (typeof item !== "undefined") {
33
+ data[id] = item;
34
+ } else {
35
+ idsToFetch.push(id);
36
+ }
37
+ }
38
+ if (idsToFetch.length) {
39
+ logger?.trace({ items: idsToFetch.length }, "loading from store");
40
+ const fetched = await store.get(type, idsToFetch);
41
+ for (const id of idsToFetch) {
42
+ const item = fetched[id];
43
+ if (item) {
44
+ data[id] = item;
45
+ cache.set(getUniqueId(type, id), item);
46
+ }
47
+ }
48
+ }
49
+ return data;
50
+ });
51
+ },
52
+ async set(data) {
53
+ return cacheMutex.runExclusive(async () => {
54
+ let keys = 0;
55
+ for (const type in data) {
56
+ for (const id in data[type]) {
57
+ await cache.set(getUniqueId(type, id), data[type][id]);
58
+ keys += 1;
59
+ }
60
+ }
61
+ logger?.trace({ keys: keys }, "updated cache");
62
+ await store.set(data);
63
+ });
64
+ },
65
+ async clear() {
66
+ await cache.flushAll();
67
+ await store.clear?.call(store);
68
+ },
69
+ };
70
+ }
71
+ const addTransactionCapability = (
72
+ state,
73
+ logger,
74
+ { maxCommitRetries: maxCommitRetries, delayBetweenTriesMs: delayBetweenTriesMs }
75
+ ) => {
76
+ const txStorage = new AsyncLocalStorage();
77
+ const keyQueues = new Map();
78
+ const txMutexes = new Map();
79
+ const txMutexRefCounts = new Map();
80
+ const preKeyManager = new PreKeyManager(state, logger);
81
+ function getQueue(key) {
82
+ if (!keyQueues.has(key)) {
83
+ keyQueues.set(key, new PQueue({ concurrency: 1 }));
84
+ }
85
+ return keyQueues.get(key);
86
+ }
87
+ function getTxMutex(key) {
88
+ if (!txMutexes.has(key)) {
89
+ txMutexes.set(key, new Mutex());
90
+ txMutexRefCounts.set(key, 0);
91
+ }
92
+ return txMutexes.get(key);
93
+ }
94
+ function acquireTxMutexRef(key) {
95
+ const count = txMutexRefCounts.get(key) ?? 0;
96
+ txMutexRefCounts.set(key, count + 1);
97
+ }
98
+ function releaseTxMutexRef(key) {
99
+ const count = (txMutexRefCounts.get(key) ?? 1) - 1;
100
+ txMutexRefCounts.set(key, count);
101
+ if (count <= 0) {
102
+ const mutex = txMutexes.get(key);
103
+ if (mutex && !mutex.isLocked()) {
104
+ txMutexes.delete(key);
105
+ txMutexRefCounts.delete(key);
106
+ }
107
+ }
108
+ }
109
+ function isInTransaction() {
110
+ return !!txStorage.getStore();
111
+ }
112
+ async function commitWithRetry(mutations) {
113
+ if (Object.keys(mutations).length === 0) {
114
+ logger.trace("no mutations in transaction");
115
+ return;
116
+ }
117
+ logger.trace("committing transaction");
118
+ for (let attempt = 0; attempt < maxCommitRetries; attempt++) {
119
+ try {
120
+ await state.set(mutations);
121
+ logger.trace(
122
+ { mutationCount: Object.keys(mutations).length },
123
+ "committed transaction"
124
+ );
125
+ return;
126
+ } catch (error) {
127
+ const retriesLeft = maxCommitRetries - attempt - 1;
128
+ logger.warn(`failed to commit mutations, retries left=${retriesLeft}`);
129
+ if (retriesLeft === 0) {
130
+ throw error;
131
+ }
132
+ await delay(delayBetweenTriesMs);
133
+ }
134
+ }
135
+ }
136
+ return {
137
+ get: async (type, ids) => {
138
+ const ctx = txStorage.getStore();
139
+ if (!ctx) {
140
+ return state.get(type, ids);
141
+ }
142
+ const cached = ctx.cache[type] || {};
143
+ const missing = ids.filter((id) => !(id in cached));
144
+ if (missing.length > 0) {
145
+ ctx.dbQueries++;
146
+ logger.trace(
147
+ { type: type, count: missing.length },
148
+ "fetching missing keys in transaction"
149
+ );
150
+ const fetched = await getTxMutex(type).runExclusive(() => state.get(type, missing));
151
+ ctx.cache[type] = ctx.cache[type] || {};
152
+ Object.assign(ctx.cache[type], fetched);
153
+ }
154
+ const result = {};
155
+ for (const id of ids) {
156
+ const value = ctx.cache[type]?.[id];
157
+ if (value !== undefined && value !== null) {
158
+ result[id] = value;
159
+ }
160
+ }
161
+ return result;
162
+ },
163
+ set: async (data) => {
164
+ const ctx = txStorage.getStore();
165
+ if (!ctx) {
166
+ const types = Object.keys(data);
167
+ for (const type_ of types) {
168
+ const type = type_;
169
+ if (type === "pre-key") {
170
+ await preKeyManager.validateDeletions(data, type);
171
+ }
172
+ }
173
+ await Promise.all(
174
+ types.map((type) =>
175
+ getQueue(type).add(async () => {
176
+ const typeData = { [type]: data[type] };
177
+ await state.set(typeData);
178
+ })
179
+ )
180
+ );
181
+ return;
182
+ }
183
+ logger.trace({ types: Object.keys(data) }, "caching in transaction");
184
+ for (const key_ in data) {
185
+ const key = key_;
186
+ ctx.cache[key] = ctx.cache[key] || {};
187
+ ctx.mutations[key] = ctx.mutations[key] || {};
188
+ if (key === "pre-key") {
189
+ await preKeyManager.processOperations(
190
+ data,
191
+ key,
192
+ ctx.cache,
193
+ ctx.mutations,
194
+ true
195
+ );
196
+ } else {
197
+ Object.assign(ctx.cache[key], data[key]);
198
+ Object.assign(ctx.mutations[key], data[key]);
199
+ }
200
+ }
201
+ },
202
+ isInTransaction: isInTransaction,
203
+ transaction: async (work, key) => {
204
+ const existing = txStorage.getStore();
205
+ if (existing) {
206
+ logger.trace("reusing existing transaction context");
207
+ return work();
208
+ }
209
+ const mutex = getTxMutex(key);
210
+ acquireTxMutexRef(key);
211
+ try {
212
+ return await mutex.runExclusive(async () => {
213
+ const ctx = { cache: {}, mutations: {}, dbQueries: 0 };
214
+ logger.trace("entering transaction");
215
+ try {
216
+ const result = await txStorage.run(ctx, work);
217
+ await commitWithRetry(ctx.mutations);
218
+ logger.trace({ dbQueries: ctx.dbQueries }, "transaction completed");
219
+ return result;
220
+ } catch (error) {
221
+ logger.error({ error: error }, "transaction failed, rolling back");
222
+ throw error;
223
+ }
224
+ });
225
+ } finally {
226
+ releaseTxMutexRef(key);
227
+ }
228
+ },
229
+ };
230
+ };
231
+ const initAuthCreds = () => {
232
+ const identityKey = Curve.generateKeyPair();
233
+ return {
234
+ noiseKey: Curve.generateKeyPair(),
235
+ pairingEphemeralKeyPair: Curve.generateKeyPair(),
236
+ signedIdentityKey: identityKey,
237
+ signedPreKey: signedKeyPair(identityKey, 1),
238
+ registrationId: generateRegistrationId(),
239
+ advSecretKey: randomBytes(32).toString("base64"),
240
+ processedHistoryMessages: [],
241
+ nextPreKeyId: 1,
242
+ firstUnuploadedPreKeyId: 1,
243
+ accountSyncCounter: 0,
244
+ accountSettings: { unarchiveChats: false },
245
+ registered: false,
246
+ pairingCode: undefined,
247
+ lastPropHash: undefined,
248
+ routingInfo: undefined,
249
+ additionalData: undefined,
250
+ };
251
+ };
252
+ module.exports = {
253
+ makeCacheableSignalKeyStore: makeCacheableSignalKeyStore,
254
+ addTransactionCapability: addTransactionCapability,
255
+ initAuthCreds: initAuthCreds,
256
+ };
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const { platform: platform, release: release } = require("os");
4
+ const { proto: proto } = require("../../WAProto");
5
+ const PLATFORM_MAP = {
6
+ aix: "AIX",
7
+ darwin: "Mac OS",
8
+ win32: "Windows",
9
+ android: "Android",
10
+ freebsd: "FreeBSD",
11
+ openbsd: "OpenBSD",
12
+ sunos: "Solaris",
13
+ linux: undefined,
14
+ haiku: undefined,
15
+ cygwin: undefined,
16
+ netbsd: undefined,
17
+ };
18
+ const Browsers = {
19
+ ubuntu: (browser) => ["Ubuntu", browser, "22.04.4"],
20
+ macOS: (browser) => ["Mac OS", browser, "14.4.1"],
21
+ baileys: (browser) => ["Baileys", browser, "6.5.0"],
22
+ windows: (browser) => ["Windows", browser, "10.0.22631"],
23
+ appropriate: (browser) => [PLATFORM_MAP[platform()] || "Ubuntu", browser, release()],
24
+ };
25
+ const getPlatformId = (browser) => {
26
+ const platformType = proto.DeviceProps.PlatformType[browser.toUpperCase()];
27
+ return platformType ? platformType.toString() : "1";
28
+ };
29
+ module.exports = { Browsers: Browsers, getPlatformId: getPlatformId };
@@ -0,0 +1,233 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const { Boom: Boom } = require("@hapi/boom");
4
+ const { createHash: createHash } = require("crypto");
5
+ const { join: join } = require("path");
6
+ const { tmpdir: tmpdir } = require("os");
7
+ const { promises: promises, createWriteStream: createWriteStream } = require("fs");
8
+ const {
9
+ getBinaryNodeChild: getBinaryNodeChild,
10
+ getBinaryNodeChildren: getBinaryNodeChildren,
11
+ getBinaryNodeChildString: getBinaryNodeChildString,
12
+ } = require("../WABinary");
13
+ const {
14
+ getStream: getStream,
15
+ getUrlFromDirectPath: getUrlFromDirectPath,
16
+ } = require("./messages-media");
17
+ const { generateMessageID: generateMessageID } = require("./generics");
18
+ const parseCatalogNode = (node) => {
19
+ const catalogNode = getBinaryNodeChild(node, "product_catalog");
20
+ const products = getBinaryNodeChildren(catalogNode, "product").map(parseProductNode);
21
+ const paging = getBinaryNodeChild(catalogNode, "paging");
22
+ return {
23
+ products: products,
24
+ nextPageCursor: paging ? getBinaryNodeChildString(paging, "after") : undefined,
25
+ };
26
+ };
27
+ const parseCollectionsNode = (node) => {
28
+ const collectionsNode = getBinaryNodeChild(node, "collections");
29
+ const collections = getBinaryNodeChildren(collectionsNode, "collection").map(
30
+ (collectionNode) => {
31
+ const id = getBinaryNodeChildString(collectionNode, "id");
32
+ const name = getBinaryNodeChildString(collectionNode, "name");
33
+ const products = getBinaryNodeChildren(collectionNode, "product").map(parseProductNode);
34
+ return {
35
+ id: id,
36
+ name: name,
37
+ products: products,
38
+ status: parseStatusInfo(collectionNode),
39
+ };
40
+ }
41
+ );
42
+ return { collections: collections };
43
+ };
44
+ const parseOrderDetailsNode = (node) => {
45
+ const orderNode = getBinaryNodeChild(node, "order");
46
+ const products = getBinaryNodeChildren(orderNode, "product").map((productNode) => {
47
+ const imageNode = getBinaryNodeChild(productNode, "image");
48
+ return {
49
+ id: getBinaryNodeChildString(productNode, "id"),
50
+ name: getBinaryNodeChildString(productNode, "name"),
51
+ imageUrl: getBinaryNodeChildString(imageNode, "url"),
52
+ price: +getBinaryNodeChildString(productNode, "price"),
53
+ currency: getBinaryNodeChildString(productNode, "currency"),
54
+ quantity: +getBinaryNodeChildString(productNode, "quantity"),
55
+ };
56
+ });
57
+ const priceNode = getBinaryNodeChild(orderNode, "price");
58
+ const orderDetails = {
59
+ price: {
60
+ total: +getBinaryNodeChildString(priceNode, "total"),
61
+ currency: getBinaryNodeChildString(priceNode, "currency"),
62
+ },
63
+ products: products,
64
+ };
65
+ return orderDetails;
66
+ };
67
+ const toProductNode = (productId, product) => {
68
+ const attrs = {};
69
+ const content = [];
70
+ if (typeof productId !== "undefined") {
71
+ content.push({ tag: "id", attrs: {}, content: Buffer.from(productId) });
72
+ }
73
+ if (typeof product.name !== "undefined") {
74
+ content.push({
75
+ tag: "name",
76
+ attrs: {},
77
+ content: Buffer.from(product.name),
78
+ });
79
+ }
80
+ if (typeof product.description !== "undefined") {
81
+ content.push({
82
+ tag: "description",
83
+ attrs: {},
84
+ content: Buffer.from(product.description),
85
+ });
86
+ }
87
+ if (typeof product.retailerId !== "undefined") {
88
+ content.push({
89
+ tag: "retailer_id",
90
+ attrs: {},
91
+ content: Buffer.from(product.retailerId),
92
+ });
93
+ }
94
+ if (product.images.length) {
95
+ content.push({
96
+ tag: "media",
97
+ attrs: {},
98
+ content: product.images.map((img) => {
99
+ if (!("url" in img)) {
100
+ throw new Boom("Expected img for product to already be uploaded", {
101
+ statusCode: 400,
102
+ });
103
+ }
104
+ return {
105
+ tag: "image",
106
+ attrs: {},
107
+ content: [{ tag: "url", attrs: {}, content: Buffer.from(img.url.toString()) }],
108
+ };
109
+ }),
110
+ });
111
+ }
112
+ if (typeof product.price !== "undefined") {
113
+ content.push({
114
+ tag: "price",
115
+ attrs: {},
116
+ content: Buffer.from(product.price.toString()),
117
+ });
118
+ }
119
+ if (typeof product.currency !== "undefined") {
120
+ content.push({
121
+ tag: "currency",
122
+ attrs: {},
123
+ content: Buffer.from(product.currency),
124
+ });
125
+ }
126
+ if ("originCountryCode" in product) {
127
+ if (typeof product.originCountryCode === "undefined") {
128
+ attrs["compliance_category"] = "COUNTRY_ORIGIN_EXEMPT";
129
+ } else {
130
+ content.push({
131
+ tag: "compliance_info",
132
+ attrs: {},
133
+ content: [
134
+ {
135
+ tag: "country_code_origin",
136
+ attrs: {},
137
+ content: Buffer.from(product.originCountryCode),
138
+ },
139
+ ],
140
+ });
141
+ }
142
+ }
143
+ if (typeof product.isHidden !== "undefined") {
144
+ attrs["is_hidden"] = product.isHidden.toString();
145
+ }
146
+ const node = { tag: "product", attrs: attrs, content: content };
147
+ return node;
148
+ };
149
+ const parseProductNode = (productNode) => {
150
+ const isHidden = productNode.attrs.is_hidden === "true";
151
+ const id = getBinaryNodeChildString(productNode, "id");
152
+ const mediaNode = getBinaryNodeChild(productNode, "media");
153
+ const statusInfoNode = getBinaryNodeChild(productNode, "status_info");
154
+ const product = {
155
+ id: id,
156
+ imageUrls: parseImageUrls(mediaNode),
157
+ reviewStatus: {
158
+ whatsapp: getBinaryNodeChildString(statusInfoNode, "status"),
159
+ },
160
+ availability: "in stock",
161
+ name: getBinaryNodeChildString(productNode, "name"),
162
+ retailerId: getBinaryNodeChildString(productNode, "retailer_id"),
163
+ url: getBinaryNodeChildString(productNode, "url"),
164
+ description: getBinaryNodeChildString(productNode, "description"),
165
+ price: +getBinaryNodeChildString(productNode, "price"),
166
+ currency: getBinaryNodeChildString(productNode, "currency"),
167
+ isHidden: isHidden,
168
+ };
169
+ return product;
170
+ };
171
+ async function uploadingNecessaryImagesOfProduct(product, waUploadToServer, timeoutMs = 3e4) {
172
+ product = {
173
+ ...product,
174
+ images: product.images
175
+ ? await uploadingNecessaryImages(product.images, waUploadToServer, timeoutMs)
176
+ : product.images,
177
+ };
178
+ return product;
179
+ }
180
+ const uploadingNecessaryImages = async (images, waUploadToServer, timeoutMs = 3e4) => {
181
+ const results = await Promise.all(
182
+ images.map(async (img) => {
183
+ if ("url" in img) {
184
+ const url = img.url.toString();
185
+ if (url.includes(".whatsapp.net")) {
186
+ return { url: url };
187
+ }
188
+ }
189
+ const { stream: stream } = await getStream(img);
190
+ const hasher = createHash("sha256");
191
+ const filePath = join(tmpdir(), "img" + generateMessageID());
192
+ const encFileWriteStream = createWriteStream(filePath);
193
+ for await (const block of stream) {
194
+ hasher.update(block);
195
+ encFileWriteStream.write(block);
196
+ }
197
+ const sha = hasher.digest("base64");
198
+ const { directPath: directPath } = await waUploadToServer(filePath, {
199
+ mediaType: "product-catalog-image",
200
+ fileEncSha256B64: sha,
201
+ timeoutMs: timeoutMs,
202
+ });
203
+ await promises
204
+ .unlink(filePath)
205
+ .catch((err) => console.log("Error deleting temp file ", err));
206
+ return { url: getUrlFromDirectPath(directPath) };
207
+ })
208
+ );
209
+ return results;
210
+ };
211
+ const parseImageUrls = (mediaNode) => {
212
+ const imgNode = getBinaryNodeChild(mediaNode, "image");
213
+ return {
214
+ requested: getBinaryNodeChildString(imgNode, "request_image_url"),
215
+ original: getBinaryNodeChildString(imgNode, "original_image_url"),
216
+ };
217
+ };
218
+ const parseStatusInfo = (mediaNode) => {
219
+ const node = getBinaryNodeChild(mediaNode, "status_info");
220
+ return {
221
+ status: getBinaryNodeChildString(node, "status"),
222
+ canAppeal: getBinaryNodeChildString(node, "can_appeal") === "true",
223
+ };
224
+ };
225
+ module.exports = {
226
+ parseCatalogNode: parseCatalogNode,
227
+ parseCollectionsNode: parseCollectionsNode,
228
+ parseOrderDetailsNode: parseOrderDetailsNode,
229
+ toProductNode: toProductNode,
230
+ parseProductNode: parseProductNode,
231
+ uploadingNecessaryImagesOfProduct: uploadingNecessaryImagesOfProduct,
232
+ uploadingNecessaryImages: uploadingNecessaryImages,
233
+ };