@langitdeveloper/baileys 2.0.7 → 2.0.9

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 (126) hide show
  1. package/WAProto/index.js +131281 -59270
  2. package/lib/Defaults/baileys-version.json +3 -1
  3. package/lib/Defaults/index.js +6 -6
  4. package/lib/Function/Download/tiktok.js +19 -0
  5. package/lib/Function/Tools/bypass.js +19 -0
  6. package/lib/Function/index.js +13 -0
  7. package/lib/Signal/libsignal.js +0 -15
  8. package/lib/Socket/chats.js +48 -16
  9. package/lib/Socket/dugong.js +165 -12
  10. package/lib/Socket/messages-send.js +576 -1213
  11. package/lib/Socket/newsletter.js +212 -99
  12. package/lib/Socket/socket.js +1 -1
  13. package/lib/Types/index.js +0 -2
  14. package/lib/Utils/generics.js +79 -4
  15. package/lib/Utils/index.js +0 -4
  16. package/lib/Utils/messages.js +4 -33
  17. package/lib/WAUSync/Protocols/index.js +0 -2
  18. package/lib/index.js +10 -12
  19. package/package.json +7 -6
  20. package/lib/Defaults/index.d.ts +0 -53
  21. package/lib/Signal/Group/ciphertext-message.d.ts +0 -9
  22. package/lib/Signal/Group/group-session-builder.d.ts +0 -14
  23. package/lib/Signal/Group/group_cipher.d.ts +0 -17
  24. package/lib/Signal/Group/index.d.ts +0 -11
  25. package/lib/Signal/Group/keyhelper.d.ts +0 -10
  26. package/lib/Signal/Group/queue-job.d.ts +0 -1
  27. package/lib/Signal/Group/sender-chain-key.d.ts +0 -13
  28. package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -16
  29. package/lib/Signal/Group/sender-key-message.d.ts +0 -18
  30. package/lib/Signal/Group/sender-key-name.d.ts +0 -17
  31. package/lib/Signal/Group/sender-key-record.d.ts +0 -30
  32. package/lib/Signal/Group/sender-key-state.d.ts +0 -38
  33. package/lib/Signal/Group/sender-message-key.d.ts +0 -11
  34. package/lib/Signal/libsignal.d.ts +0 -3
  35. package/lib/Signal/lid-mapping.js +0 -164
  36. package/lib/Socket/Client/abstract-socket-client.d.ts +0 -17
  37. package/lib/Socket/Client/index.d.ts +0 -3
  38. package/lib/Socket/Client/mobile-socket-client.d.ts +0 -13
  39. package/lib/Socket/Client/types.js +0 -12
  40. package/lib/Socket/Client/web-socket-client.d.ts +0 -12
  41. package/lib/Socket/Client/websocket.js +0 -67
  42. package/lib/Socket/business.d.ts +0 -171
  43. package/lib/Socket/chats.d.ts +0 -267
  44. package/lib/Socket/community.js +0 -454
  45. package/lib/Socket/dugong.d.ts +0 -254
  46. package/lib/Socket/groups.d.ts +0 -115
  47. package/lib/Socket/index.d.ts +0 -173
  48. package/lib/Socket/messages-recv.d.ts +0 -161
  49. package/lib/Socket/messages-send.d.ts +0 -149
  50. package/lib/Socket/mex.js +0 -54
  51. package/lib/Socket/newsletter.d.ts +0 -134
  52. package/lib/Socket/registration.d.ts +0 -267
  53. package/lib/Socket/socket.d.ts +0 -43
  54. package/lib/Socket/usync.d.ts +0 -36
  55. package/lib/Store/index.d.ts +0 -3
  56. package/lib/Store/make-cache-manager-store.d.ts +0 -13
  57. package/lib/Store/make-in-memory-store.d.ts +0 -118
  58. package/lib/Store/make-ordered-dictionary.d.ts +0 -13
  59. package/lib/Store/object-repository.d.ts +0 -10
  60. package/lib/Types/Auth.d.ts +0 -110
  61. package/lib/Types/Bussines.js +0 -2
  62. package/lib/Types/Call.d.ts +0 -13
  63. package/lib/Types/Chat.d.ts +0 -102
  64. package/lib/Types/Contact.d.ts +0 -19
  65. package/lib/Types/Events.d.ts +0 -157
  66. package/lib/Types/GroupMetadata.d.ts +0 -55
  67. package/lib/Types/Label.d.ts +0 -35
  68. package/lib/Types/LabelAssociation.d.ts +0 -29
  69. package/lib/Types/Message.d.ts +0 -273
  70. package/lib/Types/MexUpdates.js +0 -15
  71. package/lib/Types/Newsletter.d.ts +0 -103
  72. package/lib/Types/Product.d.ts +0 -78
  73. package/lib/Types/Signal.d.ts +0 -57
  74. package/lib/Types/Socket.d.ts +0 -111
  75. package/lib/Types/State.d.ts +0 -27
  76. package/lib/Types/USync.d.ts +0 -25
  77. package/lib/Types/index.d.ts +0 -57
  78. package/lib/Utils/auth-utils.d.ts +0 -18
  79. package/lib/Utils/baileys-event-stream.d.ts +0 -16
  80. package/lib/Utils/browser-utils.js +0 -29
  81. package/lib/Utils/business.d.ts +0 -22
  82. package/lib/Utils/chat-utils.d.ts +0 -71
  83. package/lib/Utils/crypto.d.ts +0 -41
  84. package/lib/Utils/decode-wa-message.d.ts +0 -19
  85. package/lib/Utils/event-buffer.d.ts +0 -35
  86. package/lib/Utils/generics.d.ts +0 -92
  87. package/lib/Utils/history.d.ts +0 -15
  88. package/lib/Utils/index.d.ts +0 -17
  89. package/lib/Utils/link-preview.d.ts +0 -21
  90. package/lib/Utils/logger.d.ts +0 -4
  91. package/lib/Utils/lt-hash.d.ts +0 -12
  92. package/lib/Utils/make-mutex.d.ts +0 -7
  93. package/lib/Utils/message-retry-manager.js +0 -134
  94. package/lib/Utils/messages-media.d.ts +0 -116
  95. package/lib/Utils/messages.d.ts +0 -77
  96. package/lib/Utils/noise-handler.d.ts +0 -21
  97. package/lib/Utils/pre-key-manager.js +0 -86
  98. package/lib/Utils/process-message.d.ts +0 -41
  99. package/lib/Utils/signal.d.ts +0 -32
  100. package/lib/Utils/use-multi-file-auth-state.d.ts +0 -13
  101. package/lib/Utils/validate-connection.d.ts +0 -11
  102. package/lib/Utils/vialeys-event-stream.js +0 -41
  103. package/lib/WABinary/constants.d.ts +0 -30
  104. package/lib/WABinary/decode.d.ts +0 -7
  105. package/lib/WABinary/encode.d.ts +0 -3
  106. package/lib/WABinary/generic-utils.d.ts +0 -17
  107. package/lib/WABinary/index.d.ts +0 -5
  108. package/lib/WABinary/jid-utils.d.ts +0 -31
  109. package/lib/WABinary/types.d.ts +0 -18
  110. package/lib/WAM/BinaryInfo.d.ts +0 -17
  111. package/lib/WAM/constants.d.ts +0 -38
  112. package/lib/WAM/encode.d.ts +0 -3
  113. package/lib/WAM/index.d.ts +0 -3
  114. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +0 -62
  115. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -9
  116. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -22
  117. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -12
  118. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +0 -24
  119. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -12
  120. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +0 -25
  121. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +0 -8
  122. package/lib/WAUSync/Protocols/index.d.ts +0 -4
  123. package/lib/WAUSync/USyncQuery.d.ts +0 -28
  124. package/lib/WAUSync/USyncUser.d.ts +0 -12
  125. package/lib/WAUSync/index.d.ts +0 -3
  126. package/lib/index.d.ts +0 -12
@@ -1,19 +0,0 @@
1
- import { Logger } from 'pino';
2
- import { proto } from '../../WAProto';
3
- import { SignalRepository } from '../Types';
4
- import { BinaryNode } from '../WABinary';
5
- /**
6
- * Decode the received node as a message.
7
- * @note this will only parse the message, not decrypt it
8
- */
9
- export declare function decodeMessageNode(stanza: BinaryNode, meId: string, meLid: string): {
10
- fullMessage: proto.IWebMessageInfo;
11
- author: string;
12
- sender: string;
13
- };
14
- export declare const decryptMessageNode: (stanza: BinaryNode, meId: string, meLid: string, repository: SignalRepository, logger: Logger) => {
15
- fullMessage: proto.IWebMessageInfo;
16
- category: string;
17
- author: string;
18
- decrypt(): Promise<void>;
19
- };
@@ -1,35 +0,0 @@
1
- import { Logger } from 'pino';
2
- import { BaileysEventEmitter, BaileysEventMap } from '../Types';
3
- /**
4
- * A map that contains a list of all events that have been triggered
5
- *
6
- * Note, this can contain different type of events
7
- * this can make processing events extremely efficient -- since everything
8
- * can be done in a single transaction
9
- */
10
- type BaileysEventData = Partial<BaileysEventMap>;
11
- type BaileysBufferableEventEmitter = BaileysEventEmitter & {
12
- /** Use to process events in a batch */
13
- process(handler: (events: BaileysEventData) => void | Promise<void>): (() => void);
14
- /**
15
- * starts buffering events, call flush() to release them
16
- * */
17
- buffer(): void;
18
- /** buffers all events till the promise completes */
19
- createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): ((...args: A) => Promise<T>);
20
- /**
21
- * flushes all buffered events
22
- * @param force if true, will flush all data regardless of any pending buffers
23
- * @returns returns true if the flush actually happened, otherwise false
24
- */
25
- flush(force?: boolean): boolean;
26
- /** is there an ongoing buffer */
27
- isBuffering(): boolean;
28
- };
29
- /**
30
- * The event buffer logically consolidates different events into a single event
31
- * making the data processing more efficient.
32
- * @param ev the baileys event emitter
33
- */
34
- export declare const makeEventBuffer: (logger: Logger) => BaileysBufferableEventEmitter;
35
- export {};
@@ -1,92 +0,0 @@
1
- /// <reference types="node" />
2
- import { AxiosRequestConfig } from 'axios';
3
- import { Logger } from 'pino';
4
- import { proto } from '../../WAProto';
5
- import { BaileysEventEmitter, BaileysEventMap, WACallUpdateType, WAVersion } from '../Types';
6
- import { BinaryNode } from '../WABinary';
7
- export declare const Browsers: {
8
- ubuntu: (browser: any) => [string, string, string];
9
- macOS: (browser: any) => [string, string, string];
10
- baileys: (browser: any) => [string, string, string];
11
- windows: (browser: any) => [string, string, string];
12
- /** The appropriate browser based on your OS & release */
13
- appropriate: (browser: any) => [string, string, string];
14
- };
15
- export declare const getPlatformId: (browser: string) => any;
16
- export declare const getKeyAuthor: (key: proto.IMessageKey | undefined | null, meId?: string) => string;
17
- export declare const writeRandomPadMax16: (msg: Uint8Array) => Buffer;
18
- export declare const unpadRandomMax16: (e: Uint8Array | Buffer) => Uint8Array;
19
- export declare const encodeWAMessage: (message: proto.IMessage) => Buffer;
20
- export declare const generateRegistrationId: () => number;
21
- export declare const encodeBigEndian: (e: number, t?: number) => Uint8Array;
22
- export declare const toNumber: (t: Long | number | null | undefined) => number;
23
- /** unix timestamp of a date in seconds */
24
- export declare const unixTimestampSeconds: (date?: Date) => number;
25
- export type DebouncedTimeout = ReturnType<typeof debouncedTimeout>;
26
- export declare const debouncedTimeout: (intervalMs?: number, task?: () => void) => {
27
- start: (newIntervalMs?: number, newTask?: () => void) => void;
28
- cancel: () => void;
29
- setTask: (newTask: () => void) => () => void;
30
- setInterval: (newInterval: number) => number;
31
- };
32
- export declare const delay: (ms: number) => Promise<void>;
33
- export declare const delayCancellable: (ms: number) => {
34
- delay: Promise<void>;
35
- cancel: () => void;
36
- };
37
- export declare function promiseTimeout<T>(ms: number | undefined, promise: (resolve: (v: T) => void, reject: (error: any) => void) => void): Promise<T>;
38
- export declare const generateMessageIDV2: (userId?: string) => string;
39
- export declare const generateMessageID: () => string;
40
- export declare function bindWaitForEvent<T extends keyof BaileysEventMap>(ev: BaileysEventEmitter, event: T): (check: (u: BaileysEventMap[T]) => boolean | undefined, timeoutMs?: number) => Promise<void>;
41
- export declare const bindWaitForConnectionUpdate: (ev: BaileysEventEmitter) => (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number) => Promise<void>;
42
- export declare const printQRIfNecessaryListener: (ev: BaileysEventEmitter, logger: Logger) => void;
43
- /**
44
- * utility that fetches latest baileys version from the master branch.
45
- * Use to ensure your WA connection is always on the latest version
46
- */
47
- export declare const fetchLatestBaileysVersion: (options?: AxiosRequestConfig<any>) => Promise<{
48
- version: WAVersion;
49
- isLatest: boolean;
50
- error?: undefined;
51
- } | {
52
- version: WAVersion;
53
- isLatest: boolean;
54
- error: any;
55
- }>;
56
- /**
57
- * A utility that fetches the latest web version of whatsapp.
58
- * Use to ensure your WA connection is always on the latest version
59
- */
60
- export declare const fetchLatestWaWebVersion: (options: AxiosRequestConfig<any>) => Promise<{
61
- version: WAVersion;
62
- isLatest: boolean;
63
- error?: undefined;
64
- } | {
65
- version: WAVersion;
66
- isLatest: boolean;
67
- error: any;
68
- }>;
69
- /** unique message tag prefix for MD clients */
70
- export declare const generateMdTagPrefix: () => string;
71
- /**
72
- * Given a type of receipt, returns what the new status of the message should be
73
- * @param type type from receipt
74
- */
75
- export declare const getStatusFromReceiptType: (type: string | undefined) => proto.WebMessageInfo.Status;
76
- /**
77
- * Stream errors generally provide a reason, map that to a baileys DisconnectReason
78
- * @param reason the string reason given, eg. "conflict"
79
- */
80
- export declare const getErrorCodeFromStreamError: (node: BinaryNode) => {
81
- reason: string;
82
- statusCode: number;
83
- };
84
- export declare const getCallStatusFromNode: ({ tag, attrs }: BinaryNode) => WACallUpdateType;
85
- export declare const getCodeFromWSError: (error: Error) => number;
86
- /**
87
- * Is the given platform WA business
88
- * @param platform AuthenticationCreds.platform
89
- */
90
- export declare const isWABusinessPlatform: (platform: string) => boolean;
91
- export declare function trimUndefined(obj: any): any;
92
- export declare function bytesToCrockford(buffer: Buffer): string;
@@ -1,15 +0,0 @@
1
- import { AxiosRequestConfig } from 'axios';
2
- import { proto } from '../../WAProto';
3
- import { Chat, Contact } from '../Types';
4
- export declare const downloadHistory: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<any>) => Promise<proto.HistorySync>;
5
- export declare const processHistoryMessage: (item: proto.IHistorySync) => {
6
- chats: Chat[];
7
- contacts: Contact[];
8
- messages: proto.IWebMessageInfo[];
9
- };
10
- export declare const downloadAndProcessHistorySyncNotification: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<any>) => Promise<{
11
- chats: Chat[];
12
- contacts: Contact[];
13
- messages: proto.IWebMessageInfo[];
14
- }>;
15
- export declare const getHistoryMsg: (message: proto.IMessage) => proto.Message.IHistorySyncNotification | null | undefined;
@@ -1,17 +0,0 @@
1
- export * from './generics';
2
- export * from './decode-wa-message';
3
- export * from './messages';
4
- export * from './messages-media';
5
- export * from './validate-connection';
6
- export * from './crypto';
7
- export * from './signal';
8
- export * from './noise-handler';
9
- export * from './history';
10
- export * from './chat-utils';
11
- export * from './lt-hash';
12
- export * from './auth-utils';
13
- export * from './baileys-event-stream';
14
- export * from './use-multi-file-auth-state';
15
- export * from './link-preview';
16
- export * from './event-buffer';
17
- export * from './process-message';
@@ -1,21 +0,0 @@
1
- import { AxiosRequestConfig } from 'axios';
2
- import { Logger } from 'pino';
3
- import { WAMediaUploadFunction, WAUrlInfo } from '../Types';
4
- export type URLGenerationOptions = {
5
- thumbnailWidth: number;
6
- fetchOpts: {
7
- /** Timeout in ms */
8
- timeout: number;
9
- proxyUrl?: string;
10
- headers?: AxiosRequestConfig<{}>['headers'];
11
- };
12
- uploadImage?: WAMediaUploadFunction;
13
- logger?: Logger;
14
- };
15
- /**
16
- * Given a piece of text, checks for any URL present, generates link preview for the same and returns it
17
- * Return undefined if the fetch failed or no URL was found
18
- * @param text first matched URL in text
19
- * @returns the URL info required to generate link preview
20
- */
21
- export declare const getUrlInfo: (text: string, opts?: URLGenerationOptions) => Promise<WAUrlInfo | undefined>;
@@ -1,4 +0,0 @@
1
- declare const _default: import("pino").Logger<{
2
- timestamp: () => string;
3
- }>;
4
- export default _default;
@@ -1,12 +0,0 @@
1
- declare class d {
2
- salt: string;
3
- constructor(e: string);
4
- add(e: any, t: any): any;
5
- subtract(e: any, t: any): any;
6
- subtractThenAdd(e: any, t: any, r: any): any;
7
- _addSingle(e: any, t: any): ArrayBuffer;
8
- _subtractSingle(e: any, t: any): ArrayBuffer;
9
- performPointwiseWithOverflow(e: any, t: any, r: any): ArrayBuffer;
10
- }
11
- export declare const LT_HASH_ANTI_TAMPERING: d;
12
- export {};
@@ -1,7 +0,0 @@
1
- export declare const makeMutex: () => {
2
- mutex<T>(code: () => T | Promise<T>): Promise<T>;
3
- };
4
- export type Mutex = ReturnType<typeof makeMutex>;
5
- export declare const makeKeyedMutex: () => {
6
- mutex<T>(key: string, task: () => T | Promise<T>): Promise<T>;
7
- };
@@ -1,134 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const { LRUCache: LRUCache } = require("lru-cache");
4
- const RECENT_MESSAGES_SIZE = 512;
5
- const MESSAGE_KEY_SEPARATOR = "\0";
6
- const RECREATE_SESSION_TIMEOUT = 60 * 60 * 1e3;
7
- const PHONE_REQUEST_DELAY = 3e3;
8
- class MessageRetryManager {
9
- constructor(logger, maxMsgRetryCount) {
10
- this.logger = logger;
11
- this.recentMessagesMap = new LRUCache({
12
- max: RECENT_MESSAGES_SIZE,
13
- ttl: 5 * 60 * 1e3,
14
- ttlAutopurge: true,
15
- dispose: (_value, key) => {
16
- const separatorIndex = key.lastIndexOf(MESSAGE_KEY_SEPARATOR);
17
- if (separatorIndex > -1) {
18
- const messageId = key.slice(separatorIndex + MESSAGE_KEY_SEPARATOR.length);
19
- this.messageKeyIndex.delete(messageId);
20
- }
21
- },
22
- });
23
- this.messageKeyIndex = new Map();
24
- this.sessionRecreateHistory = new LRUCache({
25
- ttl: RECREATE_SESSION_TIMEOUT * 2,
26
- ttlAutopurge: true,
27
- });
28
- this.retryCounters = new LRUCache({
29
- ttl: 15 * 60 * 1e3,
30
- ttlAutopurge: true,
31
- updateAgeOnGet: true,
32
- });
33
- this.pendingPhoneRequests = {};
34
- this.maxMsgRetryCount = 5;
35
- this.statistics = {
36
- totalRetries: 0,
37
- successfulRetries: 0,
38
- failedRetries: 0,
39
- mediaRetries: 0,
40
- sessionRecreations: 0,
41
- phoneRequests: 0,
42
- };
43
- this.maxMsgRetryCount = maxMsgRetryCount;
44
- }
45
- addRecentMessage(to, id, message) {
46
- const key = { to: to, id: id };
47
- const keyStr = this.keyToString(key);
48
- this.recentMessagesMap.set(keyStr, {
49
- message: message,
50
- timestamp: Date.now(),
51
- });
52
- this.messageKeyIndex.set(id, keyStr);
53
- this.logger.debug(`Added message to retry cache: ${to}/${id}`);
54
- }
55
- getRecentMessage(to, id) {
56
- const key = { to: to, id: id };
57
- const keyStr = this.keyToString(key);
58
- return this.recentMessagesMap.get(keyStr);
59
- }
60
- shouldRecreateSession(jid, retryCount, hasSession) {
61
- if (!hasSession) {
62
- this.sessionRecreateHistory.set(jid, Date.now());
63
- this.statistics.sessionRecreations++;
64
- return {
65
- reason: "we don't have a Signal session with them",
66
- recreate: true,
67
- };
68
- }
69
- if (retryCount < 2) {
70
- return { reason: "", recreate: false };
71
- }
72
- const now = Date.now();
73
- const prevTime = this.sessionRecreateHistory.get(jid);
74
- if (!prevTime || now - prevTime > RECREATE_SESSION_TIMEOUT) {
75
- this.sessionRecreateHistory.set(jid, now);
76
- this.statistics.sessionRecreations++;
77
- return {
78
- reason: "retry count > 1 and over an hour since last recreation",
79
- recreate: true,
80
- };
81
- }
82
- return { reason: "", recreate: false };
83
- }
84
- incrementRetryCount(messageId) {
85
- this.retryCounters.set(messageId, (this.retryCounters.get(messageId) || 0) + 1);
86
- this.statistics.totalRetries++;
87
- return this.retryCounters.get(messageId);
88
- }
89
- getRetryCount(messageId) {
90
- return this.retryCounters.get(messageId) || 0;
91
- }
92
- hasExceededMaxRetries(messageId) {
93
- return this.getRetryCount(messageId) >= this.maxMsgRetryCount;
94
- }
95
- markRetrySuccess(messageId) {
96
- this.statistics.successfulRetries++;
97
- this.retryCounters.delete(messageId);
98
- this.cancelPendingPhoneRequest(messageId);
99
- this.removeRecentMessage(messageId);
100
- }
101
- markRetryFailed(messageId) {
102
- this.statistics.failedRetries++;
103
- this.retryCounters.delete(messageId);
104
- this.cancelPendingPhoneRequest(messageId);
105
- this.removeRecentMessage(messageId);
106
- }
107
- schedulePhoneRequest(messageId, callback, delay = PHONE_REQUEST_DELAY) {
108
- this.cancelPendingPhoneRequest(messageId);
109
- this.pendingPhoneRequests[messageId] = setTimeout(() => {
110
- delete this.pendingPhoneRequests[messageId];
111
- this.statistics.phoneRequests++;
112
- callback();
113
- }, delay);
114
- this.logger.debug(`Scheduled phone request for message ${messageId} with ${delay}ms delay`);
115
- }
116
- cancelPendingPhoneRequest(messageId) {
117
- const timeout = this.pendingPhoneRequests[messageId];
118
- if (timeout) {
119
- clearTimeout(timeout);
120
- delete this.pendingPhoneRequests[messageId];
121
- this.logger.debug(`Cancelled pending phone request for message ${messageId}`);
122
- }
123
- }
124
- keyToString(key) {
125
- return `${key.to}${MESSAGE_KEY_SEPARATOR}${key.id}`;
126
- }
127
- removeRecentMessage(messageId) {
128
- const keyStr = this.messageKeyIndex.get(messageId);
129
- if (!keyStr) return;
130
- this.recentMessagesMap.delete(keyStr);
131
- this.messageKeyIndex.delete(messageId);
132
- }
133
- }
134
- module.exports = { MessageRetryManager: MessageRetryManager };
@@ -1,116 +0,0 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- /// <reference types="node" />
4
- import { Boom } from '@hapi/boom';
5
- import { AxiosRequestConfig } from 'axios';
6
- import type { Logger } from 'pino';
7
- import { Readable, Transform } from 'stream';
8
- import { URL } from 'url';
9
- import { proto } from '../../WAProto';
10
- import { DownloadableMessage, MediaConnInfo, MediaDecryptionKeyInfo, MediaType, SocketConfig, WAMediaUpload, WAMediaUploadFunction, WAMessageContent } from '../Types';
11
- import { BinaryNode } from '../WABinary';
12
- export declare const hkdfInfoKey: (type: MediaType) => string;
13
- /** generates all the keys required to encrypt/decrypt & sign a media message */
14
- export declare function getMediaKeys(buffer: Uint8Array | string | null | undefined, mediaType: MediaType): MediaDecryptionKeyInfo;
15
- export declare const extractImageThumb: (bufferOrFilePath: Readable | Buffer | string, width?: number) => Promise<{
16
- buffer: Buffer;
17
- original: {
18
- width: number | undefined;
19
- height: number | undefined;
20
- };
21
- }>;
22
- export declare const encodeBase64EncodedStringForUpload: (b64: string) => string;
23
- export declare const generateProfilePicture: (mediaUpload: WAMediaUpload) => Promise<{
24
- img: Buffer;
25
- }>;
26
- /** gets the SHA256 of the given media message */
27
- export declare const mediaMessageSHA256B64: (message: WAMessageContent) => string | null | undefined;
28
- export declare function getAudioDuration(buffer: Buffer | string | Readable): Promise<number | undefined>;
29
- /**
30
- referenced from and modifying https://github.com/wppconnect-team/wa-js/blob/main/src/chat/functions/prepareAudioWaveform.ts
31
- */
32
- export declare function getAudioWaveform(buffer: Buffer | string | Readable, logger?: Logger): Promise<Uint8Array | undefined>;
33
- export declare const toReadable: (buffer: Buffer) => Readable;
34
- export declare const toBuffer: (stream: Readable) => Promise<Buffer>;
35
- export declare const getStream: (item: WAMediaUpload, opts?: AxiosRequestConfig) => Promise<{
36
- readonly stream: Readable;
37
- readonly type: "buffer";
38
- } | {
39
- readonly stream: Readable;
40
- readonly type: "readable";
41
- } | {
42
- readonly stream: Readable;
43
- readonly type: "remote";
44
- } | {
45
- readonly stream: import("fs").ReadStream;
46
- readonly type: "file";
47
- }>;
48
- /** generates a thumbnail for a given media, if required */
49
- export declare function generateThumbnail(file: string, mediaType: 'video' | 'image', options: {
50
- logger?: Logger;
51
- }): Promise<{
52
- thumbnail: string | undefined;
53
- originalImageDimensions: {
54
- width: number;
55
- height: number;
56
- } | undefined;
57
- }>;
58
- export declare const getHttpStream: (url: string | URL, options?: AxiosRequestConfig & {
59
- isStream?: true;
60
- }) => Promise<Readable>;
61
- type EncryptedStreamOptions = {
62
- saveOriginalFileIfRequired?: boolean;
63
- logger?: Logger;
64
- opts?: AxiosRequestConfig;
65
- };
66
- export declare const prepareStream: (media: WAMediaUpload, mediaType: MediaType, { logger, saveOriginalFileIfRequired, opts }?: EncryptedStreamOptions) => Promise<{
67
- mediaKey: undefined;
68
- encWriteStream: Buffer;
69
- fileLength: number;
70
- fileSha256: Buffer;
71
- fileEncSha256: undefined;
72
- bodyPath: string | undefined;
73
- didSaveToTmpPath: boolean;
74
- }>;
75
- export declare const encryptedStream: (media: WAMediaUpload, mediaType: MediaType, { logger, saveOriginalFileIfRequired, opts }?: EncryptedStreamOptions) => Promise<{
76
- mediaKey: Buffer;
77
- encWriteStream: Readable;
78
- bodyPath: string | undefined;
79
- mac: Buffer;
80
- fileEncSha256: Buffer;
81
- fileSha256: Buffer;
82
- fileLength: number;
83
- didSaveToTmpPath: boolean;
84
- }>;
85
- export type MediaDownloadOptions = {
86
- startByte?: number;
87
- endByte?: number;
88
- options?: AxiosRequestConfig<any>;
89
- };
90
- export declare const getUrlFromDirectPath: (directPath: string) => string;
91
- export declare const downloadContentFromMessage: ({ mediaKey, directPath, url }: DownloadableMessage, type: MediaType, opts?: MediaDownloadOptions) => Promise<Transform>;
92
- /**
93
- * Decrypts and downloads an AES256-CBC encrypted file given the keys.
94
- * Assumes the SHA256 of the plaintext is appended to the end of the ciphertext
95
- * */
96
- export declare const downloadEncryptedContent: (downloadUrl: string, { cipherKey, iv }: MediaDecryptionKeyInfo, { startByte, endByte, options }?: MediaDownloadOptions) => Promise<Transform>;
97
- export declare function extensionForMediaMessage(message: WAMessageContent): string;
98
- export declare const getWAUploadToServer: ({ customUploadHosts, fetchAgent, logger, options }: SocketConfig, refreshMediaConn: (force: boolean) => Promise<MediaConnInfo>) => WAMediaUploadFunction;
99
- /**
100
- * Generate a binary node that will request the phone to re-upload the media & return the newly uploaded URL
101
- */
102
- export declare const encryptMediaRetryRequest: (key: proto.IMessageKey, mediaKey: Buffer | Uint8Array, meId: string) => BinaryNode;
103
- export declare const decodeMediaRetryNode: (node: BinaryNode) => {
104
- key: proto.IMessageKey;
105
- media?: {
106
- ciphertext: Uint8Array;
107
- iv: Uint8Array;
108
- } | undefined;
109
- error?: Boom<any> | undefined;
110
- };
111
- export declare const decryptMediaRetryData: ({ ciphertext, iv }: {
112
- ciphertext: Uint8Array;
113
- iv: Uint8Array;
114
- }, mediaKey: Uint8Array, msgId: string) => proto.MediaRetryNotification;
115
- export declare const getStatusCodeForMediaRetry: (code: number) => any;
116
- export {};
@@ -1,77 +0,0 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- import { Logger } from 'pino';
4
- import { type Transform } from 'stream';
5
- import { proto } from '../../WAProto';
6
- import { AnyMediaMessageContent, AnyMessageContent, MediaGenerationOptions, MessageContentGenerationOptions, MessageGenerationOptions, MessageGenerationOptionsFromContent, MessageUserReceipt, WAMessage, WAMessageContent, WAProto } from '../Types';
7
- import { MediaDownloadOptions } from './messages-media';
8
- /**
9
- * Uses a regex to test whether the string contains a URL, and returns the URL if it does.
10
- * @param text eg. hello https://google.com
11
- * @returns the URL, eg. https://google.com
12
- */
13
- export declare const extractUrlFromText: (text: string) => string | undefined;
14
- export declare const generateLinkPreviewIfRequired: (text: string, getUrlInfo: MessageGenerationOptions['getUrlInfo'], logger: MessageGenerationOptions['logger']) => Promise<import("../Types").WAUrlInfo | undefined>;
15
- export declare const prepareWAMessageMedia: (message: AnyMediaMessageContent, options: MediaGenerationOptions) => Promise<proto.Message>;
16
- export declare const prepareDisappearingMessageSettingContent: (ephemeralExpiration?: number) => proto.Message;
17
- /**
18
- * Generate forwarded message content like WA does
19
- * @param message the message to forward
20
- * @param options.forceForward will show the message as forwarded even if it is from you
21
- */
22
- export declare const generateForwardMessageContent: (message: WAMessage, forceForward?: boolean) => proto.IMessage;
23
- export declare const generateWAMessageContent: (message: AnyMessageContent, options: MessageContentGenerationOptions) => Promise<proto.Message>;
24
- export declare const generateWAMessageFromContent: (jid: string, message: WAMessageContent, options: MessageGenerationOptionsFromContent) => proto.WebMessageInfo;
25
- export declare const generateWAMessage: (jid: string, content: AnyMessageContent, options: MessageGenerationOptions) => Promise<proto.WebMessageInfo>;
26
- /** Get the key to access the true type of content */
27
- export declare const getContentType: (content: WAProto.IMessage | undefined) => keyof proto.IMessage | undefined;
28
- /**
29
- * Normalizes ephemeral, view once messages to regular message content
30
- * Eg. image messages in ephemeral messages, in view once messages etc.
31
- * @param content
32
- * @returns
33
- */
34
- export declare const normalizeMessageContent: (content: WAMessageContent | null | undefined) => WAMessageContent | undefined;
35
- /**
36
- * Extract the true message content from a message
37
- * Eg. extracts the inner message from a disappearing message/view once message
38
- */
39
- export declare const extractMessageContent: (content: WAMessageContent | undefined | null) => WAMessageContent | undefined;
40
- /**
41
- * Returns the device predicted by message ID
42
- */
43
- export declare const getDevice: (id: string) => "android" | "unknown" | "web" | "ios" | "desktop";
44
- /** Upserts a receipt in the message */
45
- export declare const updateMessageWithReceipt: (msg: Pick<WAMessage, 'userReceipt'>, receipt: MessageUserReceipt) => void;
46
- /** Update the message with a new reaction */
47
- export declare const updateMessageWithReaction: (msg: Pick<WAMessage, 'reactions'>, reaction: proto.IReaction) => void;
48
- /** Update the message with a new poll update */
49
- export declare const updateMessageWithPollUpdate: (msg: Pick<WAMessage, 'pollUpdates'>, update: proto.IPollUpdate) => void;
50
- type VoteAggregation = {
51
- name: string;
52
- voters: string[];
53
- };
54
- /**
55
- * Aggregates all poll updates in a poll.
56
- * @param msg the poll creation message
57
- * @param meId your jid
58
- * @returns A list of options & their voters
59
- */
60
- export declare function getAggregateVotesInPollMessage({ message, pollUpdates }: Pick<WAMessage, 'pollUpdates' | 'message'>, meId?: string): VoteAggregation[];
61
- /** Given a list of message keys, aggregates them by chat & sender. Useful for sending read receipts in bulk */
62
- export declare const aggregateMessageKeysNotFromMe: (keys: proto.IMessageKey[]) => {
63
- jid: string;
64
- participant: string | undefined;
65
- messageIds: string[];
66
- }[];
67
- type DownloadMediaMessageContext = {
68
- reuploadRequest: (msg: WAMessage) => Promise<WAMessage>;
69
- logger: Logger;
70
- };
71
- /**
72
- * Downloads the given message. Throws an error if it's not a media message
73
- */
74
- export declare const downloadMediaMessage: <Type extends "stream" | "buffer">(message: WAMessage, type: Type, options: MediaDownloadOptions, ctx?: DownloadMediaMessageContext) => Promise<Type extends "buffer" ? Buffer : Transform>;
75
- /** Checks whether the given message is a media message; if it is returns the inner content */
76
- export declare const assertMediaContent: (content: proto.IMessage | null | undefined) => proto.Message.IVideoMessage | proto.Message.IImageMessage | proto.Message.IAudioMessage | proto.Message.IDocumentMessage | proto.Message.IStickerMessage;
77
- export {};
@@ -1,21 +0,0 @@
1
- /// <reference types="node" />
2
- import { Logger } from 'pino';
3
- import { proto } from '../../WAProto';
4
- import { KeyPair } from '../Types';
5
- import { BinaryNode } from '../WABinary';
6
- export declare const makeNoiseHandler: ({ keyPair: { private: privateKey, public: publicKey }, NOISE_HEADER, mobile, logger, routingInfo }: {
7
- keyPair: KeyPair;
8
- NOISE_HEADER: Uint8Array;
9
- mobile: boolean;
10
- logger: Logger;
11
- routingInfo?: Buffer | undefined;
12
- }) => {
13
- encrypt: (plaintext: Uint8Array) => Buffer;
14
- decrypt: (ciphertext: Uint8Array) => Buffer;
15
- authenticate: (data: Uint8Array) => void;
16
- mixIntoKey: (data: Uint8Array) => void;
17
- finishInit: () => void;
18
- processHandshake: ({ serverHello }: proto.HandshakeMessage, noiseKey: KeyPair) => Buffer;
19
- encodeFrame: (data: Buffer | Uint8Array) => Buffer;
20
- decodeFrame: (newData: Buffer | Uint8Array, onFrame: (buff: Uint8Array | BinaryNode) => void) => void;
21
- };
@@ -1,86 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const { default: PQueue } = require("p-queue");
4
- class PreKeyManager {
5
- constructor(store, logger) {
6
- this.store = store;
7
- this.logger = logger;
8
- this.queues = new Map();
9
- }
10
- getQueue(keyType) {
11
- if (!this.queues.has(keyType)) {
12
- this.queues.set(keyType, new PQueue({ concurrency: 1 }));
13
- }
14
- return this.queues.get(keyType);
15
- }
16
- async processOperations(data, keyType, transactionCache, mutations, isInTransaction) {
17
- const keyData = data[keyType];
18
- if (!keyData) return;
19
- return this.getQueue(keyType).add(async () => {
20
- transactionCache[keyType] = transactionCache[keyType] || {};
21
- mutations[keyType] = mutations[keyType] || {};
22
- const deletions = [];
23
- const updates = {};
24
- for (const keyId in keyData) {
25
- if (keyData[keyId] === null) {
26
- deletions.push(keyId);
27
- } else {
28
- updates[keyId] = keyData[keyId];
29
- }
30
- }
31
- if (Object.keys(updates).length > 0) {
32
- Object.assign(transactionCache[keyType], updates);
33
- Object.assign(mutations[keyType], updates);
34
- }
35
- if (deletions.length > 0) {
36
- await this.processDeletions(
37
- keyType,
38
- deletions,
39
- transactionCache,
40
- mutations,
41
- isInTransaction
42
- );
43
- }
44
- });
45
- }
46
- async processDeletions(keyType, ids, transactionCache, mutations, isInTransaction) {
47
- if (isInTransaction) {
48
- for (const keyId of ids) {
49
- if (transactionCache[keyType]?.[keyId]) {
50
- transactionCache[keyType][keyId] = null;
51
- mutations[keyType][keyId] = null;
52
- } else {
53
- this.logger.warn(
54
- `Skipping deletion of non-existent ${keyType} in transaction: ${keyId}`
55
- );
56
- }
57
- }
58
- } else {
59
- const existingKeys = await this.store.get(keyType, ids);
60
- for (const keyId of ids) {
61
- if (existingKeys[keyId]) {
62
- transactionCache[keyType][keyId] = null;
63
- mutations[keyType][keyId] = null;
64
- } else {
65
- this.logger.warn(`Skipping deletion of non-existent ${keyType}: ${keyId}`);
66
- }
67
- }
68
- }
69
- }
70
- async validateDeletions(data, keyType) {
71
- const keyData = data[keyType];
72
- if (!keyData) return;
73
- return this.getQueue(keyType).add(async () => {
74
- const deletionIds = Object.keys(keyData).filter((id) => keyData[id] === null);
75
- if (deletionIds.length === 0) return;
76
- const existingKeys = await this.store.get(keyType, deletionIds);
77
- for (const keyId of deletionIds) {
78
- if (!existingKeys[keyId]) {
79
- this.logger.warn(`Skipping deletion of non-existent ${keyType}: ${keyId}`);
80
- delete data[keyType][keyId];
81
- }
82
- }
83
- });
84
- }
85
- }
86
- module.exports = { PreKeyManager: PreKeyManager };