violetics 7.0.1-alpha → 7.0.2-alpha

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 (114) hide show
  1. package/LICENSE +3 -2
  2. package/README.md +1001 -232
  3. package/WAProto/index.js +75379 -142631
  4. package/engine-requirements.js +11 -8
  5. package/lib/Defaults/index.js +132 -146
  6. package/lib/Signal/Group/ciphertext-message.js +2 -6
  7. package/lib/Signal/Group/group-session-builder.js +7 -42
  8. package/lib/Signal/Group/group_cipher.js +37 -52
  9. package/lib/Signal/Group/index.js +11 -57
  10. package/lib/Signal/Group/keyhelper.js +7 -45
  11. package/lib/Signal/Group/sender-chain-key.js +7 -16
  12. package/lib/Signal/Group/sender-key-distribution-message.js +8 -12
  13. package/lib/Signal/Group/sender-key-message.js +9 -13
  14. package/lib/Signal/Group/sender-key-name.js +2 -6
  15. package/lib/Signal/Group/sender-key-record.js +9 -22
  16. package/lib/Signal/Group/sender-key-state.js +27 -43
  17. package/lib/Signal/Group/sender-message-key.js +4 -8
  18. package/lib/Signal/libsignal.js +319 -94
  19. package/lib/Signal/lid-mapping.js +224 -139
  20. package/lib/Socket/Client/index.js +2 -19
  21. package/lib/Socket/Client/types.js +10 -0
  22. package/lib/Socket/Client/websocket.js +53 -0
  23. package/lib/Socket/business.js +162 -44
  24. package/lib/Socket/chats.js +477 -418
  25. package/lib/Socket/communities.js +430 -0
  26. package/lib/Socket/groups.js +110 -99
  27. package/lib/Socket/index.js +10 -10
  28. package/lib/Socket/messages-recv.js +884 -561
  29. package/lib/Socket/messages-send.js +859 -428
  30. package/lib/Socket/mex.js +41 -0
  31. package/lib/Socket/newsletter.js +195 -390
  32. package/lib/Socket/socket.js +465 -315
  33. package/lib/Store/index.js +3 -10
  34. package/lib/Store/make-in-memory-store.js +73 -79
  35. package/lib/Store/make-ordered-dictionary.js +4 -7
  36. package/lib/Store/object-repository.js +2 -6
  37. package/lib/Types/Auth.js +1 -2
  38. package/lib/Types/Bussines.js +1 -0
  39. package/lib/Types/Call.js +1 -2
  40. package/lib/Types/Chat.js +7 -4
  41. package/lib/Types/Contact.js +1 -2
  42. package/lib/Types/Events.js +1 -2
  43. package/lib/Types/GroupMetadata.js +1 -2
  44. package/lib/Types/Label.js +2 -5
  45. package/lib/Types/LabelAssociation.js +2 -5
  46. package/lib/Types/Message.js +17 -9
  47. package/lib/Types/Newsletter.js +33 -38
  48. package/lib/Types/Product.js +1 -2
  49. package/lib/Types/Signal.js +1 -2
  50. package/lib/Types/Socket.js +2 -2
  51. package/lib/Types/State.js +12 -2
  52. package/lib/Types/USync.js +1 -2
  53. package/lib/Types/index.js +14 -31
  54. package/lib/Utils/auth-utils.js +228 -152
  55. package/lib/Utils/browser-utils.js +28 -0
  56. package/lib/Utils/business.js +66 -70
  57. package/lib/Utils/chat-utils.js +331 -249
  58. package/lib/Utils/crypto.js +57 -91
  59. package/lib/Utils/decode-wa-message.js +168 -84
  60. package/lib/Utils/event-buffer.js +138 -80
  61. package/lib/Utils/generics.js +180 -297
  62. package/lib/Utils/history.js +83 -49
  63. package/lib/Utils/identity-change-handler.js +48 -0
  64. package/lib/Utils/index.js +19 -33
  65. package/lib/Utils/link-preview.js +14 -23
  66. package/lib/Utils/logger.js +2 -7
  67. package/lib/Utils/lt-hash.js +2 -46
  68. package/lib/Utils/make-mutex.js +24 -47
  69. package/lib/Utils/message-retry-manager.js +224 -0
  70. package/lib/Utils/messages-media.js +501 -496
  71. package/lib/Utils/messages.js +1428 -362
  72. package/lib/Utils/noise-handler.js +145 -100
  73. package/lib/Utils/pre-key-manager.js +105 -0
  74. package/lib/Utils/process-message.js +356 -150
  75. package/lib/Utils/reporting-utils.js +257 -0
  76. package/lib/Utils/signal.js +78 -73
  77. package/lib/Utils/sync-action-utils.js +47 -0
  78. package/lib/Utils/tc-token-utils.js +17 -0
  79. package/lib/Utils/use-multi-file-auth-state.js +35 -45
  80. package/lib/Utils/validate-connection.js +91 -107
  81. package/lib/WABinary/constants.js +1300 -1304
  82. package/lib/WABinary/decode.js +26 -48
  83. package/lib/WABinary/encode.js +109 -155
  84. package/lib/WABinary/generic-utils.js +161 -149
  85. package/lib/WABinary/index.js +5 -21
  86. package/lib/WABinary/jid-utils.js +73 -40
  87. package/lib/WABinary/types.js +1 -2
  88. package/lib/WAM/BinaryInfo.js +2 -6
  89. package/lib/WAM/constants.js +19070 -11568
  90. package/lib/WAM/encode.js +17 -23
  91. package/lib/WAM/index.js +3 -19
  92. package/lib/WAUSync/Protocols/USyncContactProtocol.js +8 -12
  93. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +11 -15
  94. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +9 -13
  95. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +9 -14
  96. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +20 -23
  97. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +13 -9
  98. package/lib/WAUSync/Protocols/index.js +4 -20
  99. package/lib/WAUSync/USyncQuery.js +40 -36
  100. package/lib/WAUSync/USyncUser.js +2 -6
  101. package/lib/WAUSync/index.js +3 -19
  102. package/lib/index.js +11 -44
  103. package/package.json +74 -107
  104. package/lib/Defaults/baileys-version.json +0 -3
  105. package/lib/Defaults/phonenumber-mcc.json +0 -223
  106. package/lib/Signal/Group/queue-job.js +0 -57
  107. package/lib/Socket/Client/abstract-socket-client.js +0 -13
  108. package/lib/Socket/Client/mobile-socket-client.js +0 -65
  109. package/lib/Socket/Client/web-socket-client.js +0 -118
  110. package/lib/Socket/groupStatus.js +0 -637
  111. package/lib/Socket/registration.js +0 -166
  112. package/lib/Socket/usync.js +0 -70
  113. package/lib/Store/make-cache-manager-store.js +0 -83
  114. package/lib/Utils/baileys-event-stream.js +0 -63
@@ -1,196 +1,278 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.initAuthCreds = exports.addTransactionCapability = exports.makeCacheableSignalKeyStore = void 0;
7
- const crypto_1 = require("crypto");
8
- const node_cache_1 = __importDefault(require("@cacheable/node-cache"));
9
- const uuid_1 = require("uuid");
10
- const Defaults_1 = require("../Defaults");
11
- const crypto_2 = require("./crypto");
12
- const generics_1 = require("./generics");
1
+ import NodeCache from '@cacheable/node-cache';
2
+ import { AsyncLocalStorage } from 'async_hooks';
3
+ import { Mutex } from 'async-mutex';
4
+ import { randomBytes } from 'crypto';
5
+ import PQueue from 'p-queue';
6
+ import { DEFAULT_CACHE_TTLS } from '../Defaults/index.js';
7
+ import { Curve, signedKeyPair } from './crypto.js';
8
+ import { delay, generateRegistrationId } from './generics.js';
9
+ import { PreKeyManager } from './pre-key-manager.js';
13
10
  /**
14
11
  * Adds caching capability to a SignalKeyStore
15
12
  * @param store the store to add caching to
16
13
  * @param logger to log trace events
17
14
  * @param _cache cache store to use
18
15
  */
19
- function makeCacheableSignalKeyStore(store, logger, _cache) {
20
- const cache = _cache || new node_cache_1.default({
21
- stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.SIGNAL_STORE,
22
- useClones: false,
23
- deleteOnExpire: true,
24
- });
16
+ export function makeCacheableSignalKeyStore(store, logger, _cache) {
17
+ const cache = _cache ||
18
+ new NodeCache({
19
+ stdTTL: DEFAULT_CACHE_TTLS.SIGNAL_STORE, // 5 minutes
20
+ useClones: false,
21
+ deleteOnExpire: true
22
+ });
23
+ // Mutex for protecting cache operations
24
+ const cacheMutex = new Mutex();
25
25
  function getUniqueId(type, id) {
26
26
  return `${type}.${id}`;
27
27
  }
28
28
  return {
29
29
  async get(type, ids) {
30
- const data = {};
31
- const idsToFetch = [];
32
- for (const id of ids) {
33
- const item = cache.get(getUniqueId(type, id));
34
- if (typeof item !== 'undefined') {
35
- data[id] = item;
36
- }
37
- else {
38
- idsToFetch.push(id);
39
- }
40
- }
41
- if (idsToFetch.length) {
42
- logger.trace({ items: idsToFetch.length }, 'loading from store');
43
- const fetched = await store.get(type, idsToFetch);
44
- for (const id of idsToFetch) {
45
- const item = fetched[id];
46
- if (item) {
30
+ return cacheMutex.runExclusive(async () => {
31
+ const data = {};
32
+ const idsToFetch = [];
33
+ for (const id of ids) {
34
+ const item = (await cache.get(getUniqueId(type, id)));
35
+ if (typeof item !== 'undefined') {
47
36
  data[id] = item;
48
- cache.set(getUniqueId(type, id), item);
37
+ }
38
+ else {
39
+ idsToFetch.push(id);
49
40
  }
50
41
  }
51
- }
52
- return data;
42
+ if (idsToFetch.length) {
43
+ logger?.trace({ items: idsToFetch.length }, 'loading from store');
44
+ const fetched = await store.get(type, idsToFetch);
45
+ for (const id of idsToFetch) {
46
+ const item = fetched[id];
47
+ if (item) {
48
+ data[id] = item;
49
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
50
+ await cache.set(getUniqueId(type, id), item);
51
+ }
52
+ }
53
+ }
54
+ return data;
55
+ });
53
56
  },
54
57
  async set(data) {
55
- let keys = 0;
56
- for (const type in data) {
57
- for (const id in data[type]) {
58
- cache.set(getUniqueId(type, id), data[type][id]);
59
- keys += 1;
58
+ return cacheMutex.runExclusive(async () => {
59
+ let keys = 0;
60
+ for (const type in data) {
61
+ for (const id in data[type]) {
62
+ await cache.set(getUniqueId(type, id), data[type][id]);
63
+ keys += 1;
64
+ }
60
65
  }
61
- }
62
- logger.trace({ keys }, 'updated cache');
63
- await store.set(data);
66
+ logger?.trace({ keys }, 'updated cache');
67
+ await store.set(data);
68
+ });
64
69
  },
65
70
  async clear() {
66
- var _a;
67
- cache.flushAll();
68
- await ((_a = store.clear) === null || _a === void 0 ? void 0 : _a.call(store));
71
+ await cache.flushAll();
72
+ await store.clear?.();
69
73
  }
70
74
  };
71
75
  }
72
- exports.makeCacheableSignalKeyStore = makeCacheableSignalKeyStore;
73
76
  /**
74
- * Adds DB like transaction capability (https://en.wikipedia.org/wiki/Database_transaction) to the SignalKeyStore,
75
- * this allows batch read & write operations & improves the performance of the lib
77
+ * Adds DB-like transaction capability to the SignalKeyStore
78
+ * Uses AsyncLocalStorage for automatic context management
76
79
  * @param state the key store to apply this capability to
77
80
  * @param logger logger to log events
78
81
  * @returns SignalKeyStore with transaction capability
79
82
  */
80
- const addTransactionCapability = (state, logger, { maxCommitRetries, delayBetweenTriesMs }) => {
81
- // number of queries made to the DB during the transaction
82
- // only there for logging purposes
83
- let dbQueriesInTransaction = 0;
84
- let transactionCache = {};
85
- let mutations = {};
86
- let transactionsInProgress = 0;
87
- return {
88
- get: async (type, ids) => {
89
- if (isInTransaction()) {
90
- const dict = transactionCache[type];
91
- const idsRequiringFetch = dict
92
- ? ids.filter(item => typeof dict[item] === 'undefined')
93
- : ids;
94
- // only fetch if there are any items to fetch
95
- if (idsRequiringFetch.length) {
96
- dbQueriesInTransaction += 1;
97
- const result = await state.get(type, idsRequiringFetch);
98
- transactionCache[type] || (transactionCache[type] = {});
99
- Object.assign(transactionCache[type], result);
83
+ export const addTransactionCapability = (state, logger, { maxCommitRetries, delayBetweenTriesMs }) => {
84
+ const txStorage = new AsyncLocalStorage();
85
+ // Queues for concurrency control (keyed by signal data type - bounded set)
86
+ const keyQueues = new Map();
87
+ // Transaction mutexes with reference counting for cleanup
88
+ const txMutexes = new Map();
89
+ const txMutexRefCounts = new Map();
90
+ // Pre-key manager for specialized operations
91
+ const preKeyManager = new PreKeyManager(state, logger);
92
+ /**
93
+ * Get or create a queue for a specific key type
94
+ */
95
+ function getQueue(key) {
96
+ if (!keyQueues.has(key)) {
97
+ keyQueues.set(key, new PQueue({ concurrency: 1 }));
98
+ }
99
+ return keyQueues.get(key);
100
+ }
101
+ /**
102
+ * Get or create a transaction mutex
103
+ */
104
+ function getTxMutex(key) {
105
+ if (!txMutexes.has(key)) {
106
+ txMutexes.set(key, new Mutex());
107
+ txMutexRefCounts.set(key, 0);
108
+ }
109
+ return txMutexes.get(key);
110
+ }
111
+ /**
112
+ * Acquire a reference to a transaction mutex
113
+ */
114
+ function acquireTxMutexRef(key) {
115
+ const count = txMutexRefCounts.get(key) ?? 0;
116
+ txMutexRefCounts.set(key, count + 1);
117
+ }
118
+ /**
119
+ * Release a reference to a transaction mutex and cleanup if no longer needed
120
+ */
121
+ function releaseTxMutexRef(key) {
122
+ const count = (txMutexRefCounts.get(key) ?? 1) - 1;
123
+ txMutexRefCounts.set(key, count);
124
+ // Cleanup if no more references and mutex is not locked
125
+ if (count <= 0) {
126
+ const mutex = txMutexes.get(key);
127
+ if (mutex && !mutex.isLocked()) {
128
+ txMutexes.delete(key);
129
+ txMutexRefCounts.delete(key);
130
+ }
131
+ }
132
+ }
133
+ /**
134
+ * Check if currently in a transaction
135
+ */
136
+ function isInTransaction() {
137
+ return !!txStorage.getStore();
138
+ }
139
+ /**
140
+ * Commit transaction with retries
141
+ */
142
+ async function commitWithRetry(mutations) {
143
+ if (Object.keys(mutations).length === 0) {
144
+ logger.trace('no mutations in transaction');
145
+ return;
146
+ }
147
+ logger.trace('committing transaction');
148
+ for (let attempt = 0; attempt < maxCommitRetries; attempt++) {
149
+ try {
150
+ await state.set(mutations);
151
+ logger.trace({ mutationCount: Object.keys(mutations).length }, 'committed transaction');
152
+ return;
153
+ }
154
+ catch (error) {
155
+ const retriesLeft = maxCommitRetries - attempt - 1;
156
+ logger.warn(`failed to commit mutations, retries left=${retriesLeft}`);
157
+ if (retriesLeft === 0) {
158
+ throw error;
100
159
  }
101
- return ids.reduce((dict, id) => {
102
- var _a;
103
- const value = (_a = transactionCache[type]) === null || _a === void 0 ? void 0 : _a[id];
104
- if (value) {
105
- dict[id] = value;
106
- }
107
- return dict;
108
- }, {});
160
+ await delay(delayBetweenTriesMs);
109
161
  }
110
- else {
162
+ }
163
+ }
164
+ return {
165
+ get: async (type, ids) => {
166
+ const ctx = txStorage.getStore();
167
+ if (!ctx) {
168
+ // No transaction - direct read without exclusive lock for concurrency
111
169
  return state.get(type, ids);
112
170
  }
171
+ // In transaction - check cache first
172
+ const cached = ctx.cache[type] || {};
173
+ const missing = ids.filter(id => !(id in cached));
174
+ if (missing.length > 0) {
175
+ ctx.dbQueries++;
176
+ logger.trace({ type, count: missing.length }, 'fetching missing keys in transaction');
177
+ const fetched = await getTxMutex(type).runExclusive(() => state.get(type, missing));
178
+ // Update cache
179
+ ctx.cache[type] = ctx.cache[type] || {};
180
+ Object.assign(ctx.cache[type], fetched);
181
+ }
182
+ // Return requested ids from cache
183
+ const result = {};
184
+ for (const id of ids) {
185
+ const value = ctx.cache[type]?.[id];
186
+ if (value !== undefined && value !== null) {
187
+ result[id] = value;
188
+ }
189
+ }
190
+ return result;
113
191
  },
114
- set: data => {
115
- if (isInTransaction()) {
116
- logger.trace({ types: Object.keys(data) }, 'caching in transaction');
117
- for (const key in data) {
118
- transactionCache[key] = transactionCache[key] || {};
119
- Object.assign(transactionCache[key], data[key]);
120
- mutations[key] = mutations[key] || {};
121
- Object.assign(mutations[key], data[key]);
192
+ set: async (data) => {
193
+ const ctx = txStorage.getStore();
194
+ if (!ctx) {
195
+ // No transaction - direct write with queue protection
196
+ const types = Object.keys(data);
197
+ // Process pre-keys with validation
198
+ for (const type_ of types) {
199
+ const type = type_;
200
+ if (type === 'pre-key') {
201
+ await preKeyManager.validateDeletions(data, type);
202
+ }
122
203
  }
204
+ // Write all data in parallel
205
+ await Promise.all(types.map(type => getQueue(type).add(async () => {
206
+ const typeData = { [type]: data[type] };
207
+ await state.set(typeData);
208
+ })));
209
+ return;
123
210
  }
124
- else {
125
- return state.set(data);
211
+ // In transaction - update cache and mutations
212
+ logger.trace({ types: Object.keys(data) }, 'caching in transaction');
213
+ for (const key_ in data) {
214
+ const key = key_;
215
+ // Ensure structures exist
216
+ ctx.cache[key] = ctx.cache[key] || {};
217
+ ctx.mutations[key] = ctx.mutations[key] || {};
218
+ // Special handling for pre-keys
219
+ if (key === 'pre-key') {
220
+ await preKeyManager.processOperations(data, key, ctx.cache, ctx.mutations, true);
221
+ }
222
+ else {
223
+ // Normal key types
224
+ Object.assign(ctx.cache[key], data[key]);
225
+ Object.assign(ctx.mutations[key], data[key]);
226
+ }
126
227
  }
127
228
  },
128
229
  isInTransaction,
129
- async transaction(work) {
130
- let result;
131
- transactionsInProgress += 1;
132
- if (transactionsInProgress === 1) {
133
- logger.trace('entering transaction');
230
+ transaction: async (work, key) => {
231
+ const existing = txStorage.getStore();
232
+ // Nested transaction - reuse existing context
233
+ if (existing) {
234
+ logger.trace('reusing existing transaction context');
235
+ return work();
134
236
  }
237
+ // New transaction - acquire mutex and create context
238
+ const mutex = getTxMutex(key);
239
+ acquireTxMutexRef(key);
135
240
  try {
136
- result = await work();
137
- // commit if this is the outermost transaction
138
- if (transactionsInProgress === 1) {
139
- if (Object.keys(mutations).length) {
140
- logger.trace('committing transaction');
141
- // retry mechanism to ensure we've some recovery
142
- // in case a transaction fails in the first attempt
143
- let tries = maxCommitRetries;
144
- let committed = false;
145
- while (tries) {
146
- tries -= 1;
147
- try {
148
- await state.set(mutations);
149
- logger.trace({ dbQueriesInTransaction }, 'committed transaction');
150
- committed = true;
151
- break;
152
- }
153
- catch (error) {
154
- logger.warn(`failed to commit ${Object.keys(mutations).length} mutations, tries left=${tries}`);
155
- await (0, generics_1.delay)(delayBetweenTriesMs);
156
- }
157
- }
158
- // All retries exhausted without success: throw so callers know.
159
- // Without this, mutations are silently discarded in the finally block.
160
- if (!committed) {
161
- throw new Error(`Transaction commit failed after ${maxCommitRetries} retries`);
162
- }
241
+ return await mutex.runExclusive(async () => {
242
+ const ctx = {
243
+ cache: {},
244
+ mutations: {},
245
+ dbQueries: 0
246
+ };
247
+ logger.trace('entering transaction');
248
+ try {
249
+ const result = await txStorage.run(ctx, work);
250
+ // Commit mutations
251
+ await commitWithRetry(ctx.mutations);
252
+ logger.trace({ dbQueries: ctx.dbQueries }, 'transaction completed');
253
+ return result;
163
254
  }
164
- else {
165
- logger.trace('no mutations in transaction');
255
+ catch (error) {
256
+ logger.error({ error }, 'transaction failed, rolling back');
257
+ throw error;
166
258
  }
167
- }
259
+ });
168
260
  }
169
261
  finally {
170
- transactionsInProgress -= 1;
171
- if (transactionsInProgress === 0) {
172
- transactionCache = {};
173
- mutations = {};
174
- dbQueriesInTransaction = 0;
175
- }
262
+ releaseTxMutexRef(key);
176
263
  }
177
- return result;
178
264
  }
179
265
  };
180
- function isInTransaction() {
181
- return transactionsInProgress > 0;
182
- }
183
266
  };
184
- exports.addTransactionCapability = addTransactionCapability;
185
- const initAuthCreds = () => {
186
- const identityKey = crypto_2.Curve.generateKeyPair();
267
+ export const initAuthCreds = () => {
268
+ const identityKey = Curve.generateKeyPair();
187
269
  return {
188
- noiseKey: crypto_2.Curve.generateKeyPair(),
189
- pairingEphemeralKeyPair: crypto_2.Curve.generateKeyPair(),
270
+ noiseKey: Curve.generateKeyPair(),
271
+ pairingEphemeralKeyPair: Curve.generateKeyPair(),
190
272
  signedIdentityKey: identityKey,
191
- signedPreKey: (0, crypto_2.signedKeyPair)(identityKey, 1),
192
- registrationId: (0, generics_1.generateRegistrationId)(),
193
- advSecretKey: (0, crypto_1.randomBytes)(32).toString('base64'),
273
+ signedPreKey: signedKeyPair(identityKey, 1),
274
+ registrationId: generateRegistrationId(),
275
+ advSecretKey: randomBytes(32).toString('base64'),
194
276
  processedHistoryMessages: [],
195
277
  nextPreKeyId: 1,
196
278
  firstUnuploadedPreKeyId: 1,
@@ -198,16 +280,10 @@ const initAuthCreds = () => {
198
280
  accountSettings: {
199
281
  unarchiveChats: false
200
282
  },
201
- // mobile creds
202
- deviceId: Buffer.from((0, uuid_1.v4)().replace(/-/g, ''), 'hex').toString('base64url'),
203
- phoneId: (0, uuid_1.v4)(),
204
- identityId: (0, crypto_1.randomBytes)(20),
205
283
  registered: false,
206
- backupToken: (0, crypto_1.randomBytes)(20),
207
- registration: {},
208
284
  pairingCode: undefined,
209
285
  lastPropHash: undefined,
210
286
  routingInfo: undefined,
287
+ additionalData: undefined
211
288
  };
212
- };
213
- exports.initAuthCreds = initAuthCreds;
289
+ };
@@ -0,0 +1,28 @@
1
+ import { platform, release } from 'node:os';
2
+ import { proto } from '../../WAProto/index.js';
3
+ const PLATFORM_MAP = {
4
+ aix: 'AIX',
5
+ darwin: 'Mac OS',
6
+ win32: 'Windows',
7
+ android: 'Android',
8
+ freebsd: 'FreeBSD',
9
+ openbsd: 'OpenBSD',
10
+ sunos: 'Solaris',
11
+ linux: undefined,
12
+ haiku: undefined,
13
+ cygwin: undefined,
14
+ netbsd: undefined
15
+ };
16
+ export const Browsers = {
17
+ ubuntu: browser => ['Ubuntu', browser, '22.04.4'],
18
+ macOS: browser => ['Mac OS', browser, '14.4.1'],
19
+ baileys: browser => ['Baileys', browser, '6.5.0'],
20
+ windows: browser => ['Windows', browser, '10.0.22631'],
21
+ android: browser => [browser, 'Android', ''],
22
+ /** The appropriate browser based on your OS & release */
23
+ appropriate: browser => [PLATFORM_MAP[platform()] || 'Ubuntu', browser, release()]
24
+ };
25
+ export const getPlatformId = (browser) => {
26
+ const platformType = proto.DeviceProps.PlatformType[browser.toUpperCase()];
27
+ return platformType ? platformType.toString() : '1'; //chrome
28
+ };