plogme 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 (154) hide show
  1. package/LICENSE +61 -0
  2. package/README.md +212 -0
  3. package/WAProto/V +1 -0
  4. package/WAProto/WAProto.proto +8051 -0
  5. package/WAProto/index.js +289292 -0
  6. package/engine-requirements.js +51 -0
  7. package/lib/Defaults/ban-checker.js +44 -0
  8. package/lib/Defaults/index.js +158 -0
  9. package/lib/Signal/Group/ciphertext-message.js +11 -0
  10. package/lib/Signal/Group/group-session-builder.js +29 -0
  11. package/lib/Signal/Group/group_cipher.js +81 -0
  12. package/lib/Signal/Group/index.js +11 -0
  13. package/lib/Signal/Group/keyhelper.js +17 -0
  14. package/lib/Signal/Group/sender-chain-key.js +25 -0
  15. package/lib/Signal/Group/sender-key-distribution-message.js +62 -0
  16. package/lib/Signal/Group/sender-key-message.js +65 -0
  17. package/lib/Signal/Group/sender-key-name.js +47 -0
  18. package/lib/Signal/Group/sender-key-record.js +40 -0
  19. package/lib/Signal/Group/sender-key-state.js +83 -0
  20. package/lib/Signal/Group/sender-message-key.js +25 -0
  21. package/lib/Signal/libsignal.js +428 -0
  22. package/lib/Signal/lid-mapping.js +280 -0
  23. package/lib/Socket/Client/index.js +2 -0
  24. package/lib/Socket/Client/types.js +10 -0
  25. package/lib/Socket/Client/websocket.js +53 -0
  26. package/lib/Socket/aigroups.js +315 -0
  27. package/lib/Socket/ban-checker.js +153 -0
  28. package/lib/Socket/business.js +407 -0
  29. package/lib/Socket/chats.js +1831 -0
  30. package/lib/Socket/chats.js[old] +1227 -0
  31. package/lib/Socket/communities.js +431 -0
  32. package/lib/Socket/graphql.js +899 -0
  33. package/lib/Socket/groups.js +549 -0
  34. package/lib/Socket/groups.js[old] +347 -0
  35. package/lib/Socket/index.js +71 -0
  36. package/lib/Socket/interactive-handler.js +600 -0
  37. package/lib/Socket/interop.js +563 -0
  38. package/lib/Socket/managed-account.js +208 -0
  39. package/lib/Socket/messages-recv.js +2144 -0
  40. package/lib/Socket/messages-send.js +2650 -0
  41. package/lib/Socket/messages-send.js[latest working] +1759 -0
  42. package/lib/Socket/mex.js +41 -0
  43. package/lib/Socket/newsletter.js +226 -0
  44. package/lib/Socket/privacy.js +446 -0
  45. package/lib/Socket/registration.js +428 -0
  46. package/lib/Socket/socket.js +1050 -0
  47. package/lib/Socket/username.js +229 -0
  48. package/lib/Store/index.js +4 -0
  49. package/lib/Store/make-cache-manager-store.js +89 -0
  50. package/lib/Store/make-in-memory-store.js +420 -0
  51. package/lib/Store/make-ordered-dictionary.js +78 -0
  52. package/lib/Store/object-repository.js +23 -0
  53. package/lib/Types/Auth.js +1 -0
  54. package/lib/Types/Bussines.js +1 -0
  55. package/lib/Types/Call.js +1 -0
  56. package/lib/Types/Chat.js +7 -0
  57. package/lib/Types/Contact.js +1 -0
  58. package/lib/Types/Events.js +1 -0
  59. package/lib/Types/GroupMetadata.js +1 -0
  60. package/lib/Types/Label.js +24 -0
  61. package/lib/Types/LabelAssociation.js +6 -0
  62. package/lib/Types/Message.js +17 -0
  63. package/lib/Types/Mex.js +39 -0
  64. package/lib/Types/Product.js +1 -0
  65. package/lib/Types/RichType.js +22 -0
  66. package/lib/Types/Signal.js +1 -0
  67. package/lib/Types/Socket.js +2 -0
  68. package/lib/Types/State.js +48 -0
  69. package/lib/Types/USync.js +1 -0
  70. package/lib/Types/index.js +25 -0
  71. package/lib/Utils/auth-utils.js +301 -0
  72. package/lib/Utils/bot-planning-replay.js +169 -0
  73. package/lib/Utils/browser-utils.js +28 -0
  74. package/lib/Utils/business.js +230 -0
  75. package/lib/Utils/channel-policy.js +1 -0
  76. package/lib/Utils/chat-utils.js +885 -0
  77. package/lib/Utils/chat-utils.js[old] +871 -0
  78. package/lib/Utils/companion-reg-client-utils.js +32 -0
  79. package/lib/Utils/consumer-application.js +102 -0
  80. package/lib/Utils/crypto.js +117 -0
  81. package/lib/Utils/decode-wa-message.js +484 -0
  82. package/lib/Utils/event-buffer.js +589 -0
  83. package/lib/Utils/games/slot-machine.js +258 -0
  84. package/lib/Utils/games/website-preview.js +293 -0
  85. package/lib/Utils/generics.js +390 -0
  86. package/lib/Utils/generics.js@old +385 -0
  87. package/lib/Utils/group-history.js +56 -0
  88. package/lib/Utils/history.js +130 -0
  89. package/lib/Utils/identity-change-handler.js +48 -0
  90. package/lib/Utils/index.js +35 -0
  91. package/lib/Utils/integrity.js +296 -0
  92. package/lib/Utils/jid-display-normalization.js +209 -0
  93. package/lib/Utils/link-preview.js +84 -0
  94. package/lib/Utils/logger.js +2 -0
  95. package/lib/Utils/lt-hash.js +7 -0
  96. package/lib/Utils/make-mutex.js +32 -0
  97. package/lib/Utils/message-composer.js +467 -0
  98. package/lib/Utils/message-inspect.js +67 -0
  99. package/lib/Utils/message-retry-manager.js +241 -0
  100. package/lib/Utils/messages-media.js +1006 -0
  101. package/lib/Utils/messages-media.js[old] +916 -0
  102. package/lib/Utils/messages.js +1982 -0
  103. package/lib/Utils/messages.js[old] +1902 -0
  104. package/lib/Utils/meta-ai-msmsg.js +130 -0
  105. package/lib/Utils/meta-compositing.js +202 -0
  106. package/lib/Utils/native-flow.js +100 -0
  107. package/lib/Utils/noise-handler.js +200 -0
  108. package/lib/Utils/offline-node-processor.js +39 -0
  109. package/lib/Utils/pre-key-manager.js +105 -0
  110. package/lib/Utils/process-message.js +582 -0
  111. package/lib/Utils/reporting-utils.js +257 -0
  112. package/lib/Utils/rich-message-utils.js +942 -0
  113. package/lib/Utils/rich-message-utils.js[Old] +387 -0
  114. package/lib/Utils/signal.js +200 -0
  115. package/lib/Utils/stanza-ack.js +37 -0
  116. package/lib/Utils/sync-action-utils.js +47 -0
  117. package/lib/Utils/tc-token-utils.js +162 -0
  118. package/lib/Utils/use-multi-file-auth-state.js +120 -0
  119. package/lib/Utils/use-single-file-auth-state.js +96 -0
  120. package/lib/Utils/use-sqlite-auth-state.js +108 -0
  121. package/lib/Utils/validate-connection.js +206 -0
  122. package/lib/Utils/view-once-utils.js +206 -0
  123. package/lib/Utils/voip-rekey.js +20 -0
  124. package/lib/Utils/welcome-flow.js +220 -0
  125. package/lib/WABinary/constants.js +1463 -0
  126. package/lib/WABinary/decode.js +261 -0
  127. package/lib/WABinary/encode.js +219 -0
  128. package/lib/WABinary/generic-utils.js +227 -0
  129. package/lib/WABinary/index.js +5 -0
  130. package/lib/WABinary/jid-utils.js +95 -0
  131. package/lib/WABinary/types.js +1 -0
  132. package/lib/WAM/BinaryInfo.js +9 -0
  133. package/lib/WAM/constants.js +22852 -0
  134. package/lib/WAM/encode.js +149 -0
  135. package/lib/WAM/index.js +3 -0
  136. package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +96 -0
  137. package/lib/WAUSync/Protocols/USyncContactProtocol.js +56 -0
  138. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +53 -0
  139. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +26 -0
  140. package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +70 -0
  141. package/lib/WAUSync/Protocols/USyncPictureProtocol.js +28 -0
  142. package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +25 -0
  143. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +37 -0
  144. package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +34 -0
  145. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +24 -0
  146. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -0
  147. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +28 -0
  148. package/lib/WAUSync/Protocols/index.js +12 -0
  149. package/lib/WAUSync/USyncQuery.js +201 -0
  150. package/lib/WAUSync/USyncUser.js +54 -0
  151. package/lib/WAUSync/index.js +3 -0
  152. package/lib/index.d.ts +406 -0
  153. package/lib/index.js +11 -0
  154. package/package.json +125 -0
@@ -0,0 +1,390 @@
1
+ import { Boom } from '@hapi/boom';
2
+ import { createHash, randomBytes, randomFillSync } from 'crypto';
3
+ import { proto } from '../../WAProto/index.js';
4
+ // Keep resolver fallbacks aligned with Defaults/index.js. If the hosted
5
+ // version endpoint is unavailable, never fall back to an obsolete revision.
6
+ const baileysVersion = [2, 3000, 1040735178];
7
+ import { DisconnectReason } from '../Types/index.js';
8
+ import { getAllBinaryNodeChildren, jidDecode } from '../WABinary/index.js';
9
+ import { sha256 } from './crypto.js';
10
+ export const BufferJSON = {
11
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
12
+ replacer: (k, value) => {
13
+ if (Buffer.isBuffer(value) || value instanceof Uint8Array || value?.type === 'Buffer') {
14
+ return { type: 'Buffer', data: Buffer.from(value?.data || value).toString('base64') };
15
+ }
16
+ return value;
17
+ },
18
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
19
+ reviver: (_, value) => {
20
+ if (typeof value === 'object' && value !== null && value.type === 'Buffer' && typeof value.data === 'string') {
21
+ return Buffer.from(value.data, 'base64');
22
+ }
23
+ if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
24
+ const keys = Object.keys(value);
25
+ if (keys.length > 0 && keys.every(k => !isNaN(parseInt(k, 10)))) {
26
+ const values = Object.values(value);
27
+ if (values.every(v => typeof v === 'number')) {
28
+ return Buffer.from(values);
29
+ }
30
+ }
31
+ }
32
+ return value;
33
+ }
34
+ };
35
+ export const getKeyAuthor = (key, meId = 'me') => (key?.fromMe ? meId : key?.participantAlt || key?.remoteJidAlt || key?.participant || key?.remoteJid) || '';
36
+ export const isStringNullOrEmpty = (value) =>
37
+ // eslint-disable-next-line eqeqeq
38
+ value == null || value === '';
39
+ export const writeRandomPadMax16 = (msg) => {
40
+ const pad = randomBytes(1);
41
+ const padLength = (pad[0] & 0x0f) + 1;
42
+ return Buffer.concat([msg, Buffer.alloc(padLength, padLength)]);
43
+ };
44
+ export const unpadRandomMax16 = (e) => {
45
+ const t = new Uint8Array(e);
46
+ if (0 === t.length) {
47
+ throw new Error('unpadPkcs7 given empty bytes');
48
+ }
49
+ var r = t[t.length - 1];
50
+ if (r > t.length) {
51
+ throw new Error(`unpad given ${t.length} bytes, but pad is ${r}`);
52
+ }
53
+ return new Uint8Array(t.buffer, t.byteOffset, t.length - r);
54
+ };
55
+ // code is inspired by whatsmeow
56
+ export const generateParticipantHashV2 = (participants) => {
57
+ participants.sort();
58
+ const sha256Hash = sha256(Buffer.from(participants.join(''))).toString('base64');
59
+ return '2:' + sha256Hash.slice(0, 6);
60
+ };
61
+ export const encodeWAMessage = (message) => writeRandomPadMax16(proto.Message.encode(message).finish());
62
+ export const generateRegistrationId = () => {
63
+ return Uint16Array.from(randomBytes(2))[0] & 16383;
64
+ };
65
+ export const encodeBigEndian = (e, t = 4) => {
66
+ let r = e;
67
+ const a = new Uint8Array(t);
68
+ for (let i = t - 1; i >= 0; i--) {
69
+ a[i] = 255 & r;
70
+ r >>>= 8;
71
+ }
72
+ return a;
73
+ };
74
+ export const toNumber = (t) => typeof t === 'object' && t ? ('toNumber' in t ? t.toNumber() : t.low) : t || 0;
75
+ /** unix timestamp of a date in seconds */
76
+ export const unixTimestampSeconds = (date = Date.now()) => date / 1000 | 0; // Changed from new Date → Date.now for faster operation
77
+ export const debouncedTimeout = (intervalMs = 1000, task) => {
78
+ let timeout;
79
+ return {
80
+ start: (newIntervalMs, newTask) => {
81
+ task = newTask || task;
82
+ intervalMs = newIntervalMs || intervalMs;
83
+ timeout && clearTimeout(timeout);
84
+ timeout = setTimeout(() => task?.(), intervalMs);
85
+ },
86
+ cancel: () => {
87
+ timeout && clearTimeout(timeout);
88
+ timeout = undefined;
89
+ },
90
+ setTask: (newTask) => (task = newTask),
91
+ setInterval: (newInterval) => (intervalMs = newInterval)
92
+ };
93
+ };
94
+ export const delay = (ms) => delayCancellable(ms).delay;
95
+ export const delayCancellable = (ms) => {
96
+ const stack = new Error().stack;
97
+ let timeout;
98
+ let reject;
99
+ const delay = new Promise((resolve, _reject) => {
100
+ timeout = setTimeout(resolve, ms);
101
+ reject = _reject;
102
+ });
103
+ const cancel = () => {
104
+ clearTimeout(timeout);
105
+ reject(new Boom('Cancelled', {
106
+ statusCode: 500,
107
+ data: {
108
+ stack
109
+ }
110
+ }));
111
+ };
112
+ return { delay, cancel };
113
+ };
114
+ export async function promiseTimeout(ms, promise) {
115
+ if (!ms) {
116
+ return new Promise(promise);
117
+ }
118
+ const stack = new Error().stack;
119
+ // Create a promise that rejects in <ms> milliseconds
120
+ const { delay, cancel } = delayCancellable(ms);
121
+ const p = new Promise((resolve, reject) => {
122
+ delay
123
+ .then(() => reject(new Boom('Timed Out', {
124
+ statusCode: DisconnectReason.timedOut,
125
+ data: {
126
+ stack
127
+ }
128
+ })))
129
+ .catch(err => reject(err));
130
+ promise(resolve, reject);
131
+ }).finally(cancel);
132
+ return p;
133
+ }
134
+ // inspired from whatsmeow code
135
+ // https://github.com/tulir/whatsmeow/blob/64bc969fbe78d31ae0dd443b8d4c80a5d026d07a/send.go#L42
136
+ export const generateMessageIDV2 = (userId) => {
137
+ const data = Buffer.allocUnsafe(44);
138
+ data.writeBigUInt64BE(BigInt(Date.now() / 1000 | 0), 0);
139
+ if (userId) {
140
+ const userStr = userId.split('@')[0].split(':')[0];
141
+ if (userStr) {
142
+ const len = data.write(userStr, 8);
143
+ data.write('@c.us', 8 + len);
144
+ }
145
+ }
146
+ randomFillSync(data, 28, 16);
147
+ const hash = createHash('sha256').update(data).digest();
148
+ const hex = hash.toString('hex', 0, 9).toUpperCase();
149
+ const baseId = '3EB0' + hex;
150
+ // Lia@Note 09-04-26 --- Fixed stamp position (not hash-derived) so the
151
+ // marker lands at the same index in every generated ID. @crysnovax/baileys
152
+ // v2.7.1+ own stamp, replacing the inherited "STARFALL" marker.
153
+ const pos = 4;
154
+ return baseId.slice(0, pos) + 'PLOGME' + baseId.slice(pos);
155
+ };
156
+ // generate a random ID to attach to a message
157
+ export const generateMessageID = () => '3EB0' + randomBytes(18).toString('hex').toUpperCase();
158
+ export function bindWaitForEvent(ev, event) {
159
+ return async (check, timeoutMs) => {
160
+ let listener;
161
+ let closeListener;
162
+ await promiseTimeout(timeoutMs, (resolve, reject) => {
163
+ closeListener = ({ connection, lastDisconnect }) => {
164
+ if (connection === 'close') {
165
+ reject(lastDisconnect?.error || new Boom('Connection Closed', { statusCode: DisconnectReason.connectionClosed }));
166
+ }
167
+ };
168
+ ev.on('connection.update', closeListener);
169
+ listener = async (update) => {
170
+ if (await check(update)) {
171
+ resolve();
172
+ }
173
+ };
174
+ ev.on(event, listener);
175
+ }).finally(() => {
176
+ ev.off(event, listener);
177
+ ev.off('connection.update', closeListener);
178
+ });
179
+ };
180
+ }
181
+ export const bindWaitForConnectionUpdate = (ev) => bindWaitForEvent(ev, 'connection.update');
182
+ /**
183
+ * utility that fetches latest baileys version from the master branch.
184
+ * Use to ensure your WA connection is always on the latest version
185
+ */
186
+ export const fetchLatestBaileysVersion = async (options = {}) => {
187
+ const URL = 'https://web.crysnovax.link';
188
+ try {
189
+ const response = await fetch(URL, {
190
+ dispatcher: options.dispatcher,
191
+ method: 'GET',
192
+ headers: options.headers
193
+ });
194
+ if (!response.ok) {
195
+ throw new Boom(`Failed to fetch latest crysnovax/bailey version: ${response.statusText}`, { statusCode: response.status });
196
+ }
197
+ const text = await response.text();
198
+ // Extract version from line 5 (const version = [...])
199
+ const lines = text.split('\n');
200
+ const versionLine = lines[4]; // Line 5 (0-indexed)
201
+ const versionMatch = versionLine.match(/const version = \[(\d+),\s*(\d+),\s*(\d+)\]/);
202
+ if (versionMatch) {
203
+ const version = [parseInt(versionMatch[1]), parseInt(versionMatch[2]), parseInt(versionMatch[3])];
204
+ return {
205
+ version,
206
+ isLatest: true
207
+ };
208
+ }
209
+ else {
210
+ throw new Error('Could not parse version from Defaults/index.ts');
211
+ }
212
+ }
213
+ catch (error) {
214
+ return {
215
+ version: baileysVersion,
216
+ isLatest: false,
217
+ error
218
+ };
219
+ }
220
+ };
221
+ /**
222
+ * A utility that fetches the latest web version of whatsapp.
223
+ * Use to ensure your WA connection is always on the latest version
224
+ */
225
+ export const fetchLatestWaWebVersion = async (options = {}) => {
226
+ try {
227
+ // Absolute minimal headers required to bypass anti-bot detection
228
+ const defaultHeaders = {
229
+ 'sec-fetch-site': 'none',
230
+ 'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36'
231
+ };
232
+ const headers = { ...defaultHeaders, ...options.headers };
233
+ const response = await fetch('https://web.whatsapp.com/sw.js', {
234
+ ...options,
235
+ method: 'GET',
236
+ headers
237
+ });
238
+ if (!response.ok) {
239
+ throw new Boom(`Failed to fetch sw.js: ${response.statusText}`, { statusCode: response.status });
240
+ }
241
+ const data = await response.text();
242
+ const regex = /\\?"client_revision\\?":\s*(\d+)/;
243
+ const match = data.match(regex);
244
+ if (!match?.[1]) {
245
+ return {
246
+ version: baileysVersion,
247
+ isLatest: false,
248
+ error: {
249
+ message: 'Could not find client revision in the fetched content'
250
+ }
251
+ };
252
+ }
253
+ const clientRevision = match[1];
254
+ return {
255
+ version: [2, 3000, +clientRevision],
256
+ isLatest: true
257
+ };
258
+ }
259
+ catch (error) {
260
+ return {
261
+ version: baileysVersion,
262
+ isLatest: false,
263
+ error
264
+ };
265
+ }
266
+ };
267
+ /** unique message tag prefix for MD clients */
268
+ export const generateMdTagPrefix = () => {
269
+ const bytes = randomBytes(4);
270
+ return `${bytes.readUInt16BE()}.${bytes.readUInt16BE(2)}-`;
271
+ };
272
+ const STATUS_MAP = {
273
+ sender: proto.WebMessageInfo.Status.SERVER_ACK,
274
+ played: proto.WebMessageInfo.Status.PLAYED,
275
+ read: proto.WebMessageInfo.Status.READ,
276
+ 'read-self': proto.WebMessageInfo.Status.READ
277
+ };
278
+ /**
279
+ * Given a type of receipt, returns what the new status of the message should be
280
+ * @param type type from receipt
281
+ */
282
+ export const getStatusFromReceiptType = (type) => {
283
+ const status = STATUS_MAP[type];
284
+ if (typeof type === 'undefined') {
285
+ return proto.WebMessageInfo.Status.DELIVERY_ACK;
286
+ }
287
+ return status;
288
+ };
289
+ const CODE_MAP = {
290
+ conflict: DisconnectReason.connectionReplaced
291
+ };
292
+ /**
293
+ * Stream errors generally provide a reason, map that to a baileys DisconnectReason
294
+ * @param reason the string reason given, eg. "conflict"
295
+ */
296
+ export const getErrorCodeFromStreamError = (node) => {
297
+ const [reasonNode] = getAllBinaryNodeChildren(node);
298
+ let reason = reasonNode?.tag || 'unknown';
299
+ const statusCode = +(node.attrs.code || CODE_MAP[reason] || DisconnectReason.badSession);
300
+ if (statusCode === DisconnectReason.restartRequired) {
301
+ reason = 'restart required';
302
+ }
303
+ return {
304
+ reason,
305
+ statusCode
306
+ };
307
+ };
308
+ export const getCallStatusFromNode = ({ tag, attrs }) => {
309
+ let status;
310
+ switch (tag) {
311
+ case 'offer':
312
+ case 'offer_notice':
313
+ status = 'offer';
314
+ break;
315
+ case 'terminate':
316
+ if (attrs.reason === 'timeout') {
317
+ status = 'timeout';
318
+ }
319
+ else {
320
+ //fired when accepted/rejected/timeout/caller hangs up
321
+ status = 'terminate';
322
+ }
323
+ break;
324
+ case 'reject':
325
+ status = 'reject';
326
+ break;
327
+ case 'accept':
328
+ status = 'accept';
329
+ break;
330
+ default:
331
+ status = 'ringing';
332
+ break;
333
+ }
334
+ return status;
335
+ };
336
+ const UNEXPECTED_SERVER_CODE_TEXT = 'Unexpected server response: ';
337
+ export const getCodeFromWSError = (error) => {
338
+ let statusCode = 500;
339
+ if (error?.message?.includes(UNEXPECTED_SERVER_CODE_TEXT)) {
340
+ const code = +error?.message.slice(UNEXPECTED_SERVER_CODE_TEXT.length);
341
+ if (!Number.isNaN(code) && code >= 400) {
342
+ statusCode = code;
343
+ }
344
+ }
345
+ else if (
346
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
347
+ error?.code?.startsWith('E') ||
348
+ error?.message?.includes('timed out')) {
349
+ // handle ETIMEOUT, ENOTFOUND etc
350
+ statusCode = 408;
351
+ }
352
+ return statusCode;
353
+ };
354
+ /**
355
+ * Is the given platform WA business
356
+ * @param platform AuthenticationCreds.platform
357
+ */
358
+ export const isWABusinessPlatform = (platform) => {
359
+ return platform === 'smbi' || platform === 'smba';
360
+ };
361
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
362
+ export function trimUndefined(obj) {
363
+ for (const key in obj) {
364
+ if (typeof obj[key] === 'undefined') {
365
+ delete obj[key];
366
+ }
367
+ }
368
+ return obj;
369
+ }
370
+ const CROCKFORD_CHARACTERS = '123456789ABCDEFGHJKLMNPQRSTVWXYZ';
371
+ export function bytesToCrockford(buffer) {
372
+ let value = 0;
373
+ let bitCount = 0;
374
+ const crockford = [];
375
+ for (const element of buffer) {
376
+ value = (value << 8) | (element & 0xff);
377
+ bitCount += 8;
378
+ while (bitCount >= 5) {
379
+ crockford.push(CROCKFORD_CHARACTERS.charAt((value >>> (bitCount - 5)) & 31));
380
+ bitCount -= 5;
381
+ }
382
+ }
383
+ if (bitCount > 0) {
384
+ crockford.push(CROCKFORD_CHARACTERS.charAt((value << (5 - bitCount)) & 31));
385
+ }
386
+ return crockford.join('');
387
+ }
388
+ export function encodeNewsletterMessage(message) {
389
+ return proto.Message.encode(message).finish();
390
+ }