noxleys 0.0.1-security → 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.

Potentially problematic release.


This version of noxleys might be problematic. Click here for more details.

Files changed (159) hide show
  1. package/LICENSE +26 -0
  2. package/README.md +2577 -3
  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/connection.js +39 -0
  56. package/lib/Defaults/constants.js +50 -0
  57. package/lib/Defaults/history.js +13 -0
  58. package/lib/Defaults/index.js +36 -0
  59. package/lib/Defaults/media.js +43 -0
  60. package/lib/Defaults/phonenumber-mcc.json +223 -0
  61. package/lib/Defaults/prefix.js +12 -0
  62. package/lib/Defaults/vialeys-version.json +7 -0
  63. package/lib/Signal/Group/ciphertext-message.js +14 -0
  64. package/lib/Signal/Group/group-session-builder.js +46 -0
  65. package/lib/Signal/Group/group_cipher.js +104 -0
  66. package/lib/Signal/Group/index.js +42 -0
  67. package/lib/Signal/Group/keyhelper.js +21 -0
  68. package/lib/Signal/Group/sender-chain-key.js +34 -0
  69. package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
  70. package/lib/Signal/Group/sender-key-message.js +78 -0
  71. package/lib/Signal/Group/sender-key-name.js +49 -0
  72. package/lib/Signal/Group/sender-key-record.js +45 -0
  73. package/lib/Signal/Group/sender-key-state.js +100 -0
  74. package/lib/Signal/Group/sender-message-key.js +28 -0
  75. package/lib/Signal/libsignal.js +364 -0
  76. package/lib/Signal/lid-mapping.js +164 -0
  77. package/lib/Socket/Client/index.js +31 -0
  78. package/lib/Socket/Client/types.js +12 -0
  79. package/lib/Socket/Client/websocket.js +67 -0
  80. package/lib/Socket/business.js +291 -0
  81. package/lib/Socket/chats.js +874 -0
  82. package/lib/Socket/community.js +454 -0
  83. package/lib/Socket/groups.js +357 -0
  84. package/lib/Socket/index.js +12 -0
  85. package/lib/Socket/messages-recv.js +1349 -0
  86. package/lib/Socket/messages-send.js +1483 -0
  87. package/lib/Socket/mex.js +59 -0
  88. package/lib/Socket/newsletter.js +231 -0
  89. package/lib/Socket/socket.js +898 -0
  90. package/lib/Store/index.js +35 -0
  91. package/lib/Store/make-cache-manager-store.js +77 -0
  92. package/lib/Store/make-in-memory-store.js +423 -0
  93. package/lib/Store/make-ordered-dictionary.js +78 -0
  94. package/lib/Store/object-repository.js +26 -0
  95. package/lib/Types/Auth.js +2 -0
  96. package/lib/Types/Bussines.js +2 -0
  97. package/lib/Types/Call.js +2 -0
  98. package/lib/Types/Chat.js +10 -0
  99. package/lib/Types/Contact.js +2 -0
  100. package/lib/Types/Events.js +2 -0
  101. package/lib/Types/GroupMetadata.js +2 -0
  102. package/lib/Types/Label.js +25 -0
  103. package/lib/Types/LabelAssociation.js +4 -0
  104. package/lib/Types/Message.js +11 -0
  105. package/lib/Types/MexUpdates.js +15 -0
  106. package/lib/Types/Newsletter.js +32 -0
  107. package/lib/Types/Product.js +2 -0
  108. package/lib/Types/Signal.js +2 -0
  109. package/lib/Types/Socket.js +2 -0
  110. package/lib/Types/State.js +9 -0
  111. package/lib/Types/USync.js +2 -0
  112. package/lib/Types/index.js +59 -0
  113. package/lib/Utils/auth-utils.js +256 -0
  114. package/lib/Utils/browser-utils.js +29 -0
  115. package/lib/Utils/business.js +233 -0
  116. package/lib/Utils/chat-utils.js +896 -0
  117. package/lib/Utils/crypto.js +144 -0
  118. package/lib/Utils/decode-wa-message.js +305 -0
  119. package/lib/Utils/event-buffer.js +555 -0
  120. package/lib/Utils/generics.js +405 -0
  121. package/lib/Utils/history.js +100 -0
  122. package/lib/Utils/index.js +49 -0
  123. package/lib/Utils/link-preview.js +76 -0
  124. package/lib/Utils/logger.js +4 -0
  125. package/lib/Utils/lt-hash.js +45 -0
  126. package/lib/Utils/make-mutex.js +33 -0
  127. package/lib/Utils/message-retry-manager.js +134 -0
  128. package/lib/Utils/messages-media.js +806 -0
  129. package/lib/Utils/messages.js +1946 -0
  130. package/lib/Utils/noise-handler.js +157 -0
  131. package/lib/Utils/pre-key-manager.js +86 -0
  132. package/lib/Utils/process-message.js +814 -0
  133. package/lib/Utils/signal.js +183 -0
  134. package/lib/Utils/use-multi-file-auth-state.js +104 -0
  135. package/lib/Utils/validate-connection.js +229 -0
  136. package/lib/Utils/vialeys-event-stream.js +41 -0
  137. package/lib/WABinary/constants.js +1308 -0
  138. package/lib/WABinary/decode.js +233 -0
  139. package/lib/WABinary/encode.js +212 -0
  140. package/lib/WABinary/generic-utils.js +124 -0
  141. package/lib/WABinary/index.js +36 -0
  142. package/lib/WABinary/jid-utils.js +101 -0
  143. package/lib/WABinary/types.js +2 -0
  144. package/lib/WAM/BinaryInfo.js +12 -0
  145. package/lib/WAM/constants.js +20491 -0
  146. package/lib/WAM/encode.js +148 -0
  147. package/lib/WAM/index.js +34 -0
  148. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +62 -0
  149. package/lib/WAUSync/Protocols/USyncContactProtocol.js +22 -0
  150. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +50 -0
  151. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +25 -0
  152. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +24 -0
  153. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +32 -0
  154. package/lib/WAUSync/Protocols/index.js +37 -0
  155. package/lib/WAUSync/USyncQuery.js +92 -0
  156. package/lib/WAUSync/USyncUser.js +25 -0
  157. package/lib/WAUSync/index.js +34 -0
  158. package/lib/index.js +106 -0
  159. package/package.json +89 -4
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const LabelColor = {
4
+ Color1: 0,
5
+ Color2: 1,
6
+ Color3: 2,
7
+ Color4: 3,
8
+ Color5: 4,
9
+ Color6: 5,
10
+ Color7: 6,
11
+ Color8: 7,
12
+ Color9: 8,
13
+ Color10: 9,
14
+ Color11: 10,
15
+ Color12: 11,
16
+ Color13: 12,
17
+ Color14: 13,
18
+ Color15: 14,
19
+ Color16: 15,
20
+ Color17: 16,
21
+ Color18: 17,
22
+ Color19: 18,
23
+ Color20: 19,
24
+ };
25
+ module.exports = { LabelColor: LabelColor };
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const LabelAssociationType = { Chat: "label_jid", Message: "label_message" };
4
+ module.exports = { LabelAssociationType: LabelAssociationType };
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const { proto: proto } = require("../../WAProto");
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ const WAMessageAddressingMode = { PN: "pn", LID: "lid" };
6
+ module.exports = {
7
+ WAMessageAddressingMode: WAMessageAddressingMode,
8
+ WAMessageStubType: proto.WebMessageInfo.StubType,
9
+ WAMessageStatus: proto.WebMessageInfo.Status,
10
+ WAProto: proto,
11
+ };
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const MexUpdatesOperations = {
4
+ OWNER_COMMUNITY: "NotificationCommunityOwnerUpdate",
5
+ GROUP_MEMBER_LINK: "NotificationGroupMemberLinkPropertyUpdate",
6
+ GROUP_LIMIT_SHARING: "NotificationGroupLimitSharingPropertyUpdate",
7
+ };
8
+ const XWAPathsMexUpdates = {
9
+ GROUP_SHARING_CHANGE: "xwa2_notify_group_on_prop_change",
10
+ COMMUNITY_OWNER_CHANGE: "xwa2_notify_group_on_participants_roles_change",
11
+ };
12
+ module.exports = {
13
+ MexUpdatesOperations: MexUpdatesOperations,
14
+ XWAPathsMexUpdates: XWAPathsMexUpdates,
15
+ };
@@ -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,59 @@
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("./Socket"), exports);
43
+ __exportStar(require("./Events"), exports);
44
+ __exportStar(require("./Product"), exports);
45
+ __exportStar(require("./Call"), exports);
46
+ __exportStar(require("./Signal"), exports);
47
+ const DisconnectReason = {
48
+ connectionClosed: 428,
49
+ connectionLost: 408,
50
+ connectionReplaced: 440,
51
+ timedOut: 408,
52
+ loggedOut: 401,
53
+ badSession: 500,
54
+ restartRequired: 515,
55
+ multideviceMismatch: 411,
56
+ forbidden: 403,
57
+ unavailableService: 503,
58
+ };
59
+ 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 };