@xbibzlibrary/whatsbibz 1.3.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.
- package/CHANGELOG.md +93 -0
- package/LICENSE +22 -0
- package/LICENSE.upstream +21 -0
- package/README.md +280 -0
- package/VERIFIKASI-IDENTITAS-2026-09-03.md +138 -0
- package/WAProto/GenerateStatics.sh +3 -0
- package/WAProto/WAProto.proto +6035 -0
- package/WAProto/fix-imports.js +81 -0
- package/WAProto/index.d.ts +15314 -0
- package/WAProto/index.js +132326 -0
- package/assets/logo/README.md +21 -0
- package/assets/logo/png/banner-1200x360.png +0 -0
- package/assets/logo/png/icon-1024.png +0 -0
- package/assets/logo/png/icon-128.png +0 -0
- package/assets/logo/png/icon-16.png +0 -0
- package/assets/logo/png/icon-24.png +0 -0
- package/assets/logo/png/icon-256.png +0 -0
- package/assets/logo/png/icon-32.png +0 -0
- package/assets/logo/png/icon-48.png +0 -0
- package/assets/logo/png/icon-512.png +0 -0
- package/assets/logo/png/icon-64.png +0 -0
- package/assets/logo/png/mark-512.png +0 -0
- package/assets/logo/preview.png +0 -0
- package/assets/logo/whatsbibz.ico +0 -0
- package/lib/BibzWhats/client.d.ts +95 -0
- package/lib/BibzWhats/client.js +501 -0
- package/lib/BibzWhats/device-identity.d.ts +60 -0
- package/lib/BibzWhats/device-identity.js +234 -0
- package/lib/BibzWhats/extract.d.ts +29 -0
- package/lib/BibzWhats/extract.js +115 -0
- package/lib/BibzWhats/index.d.ts +7 -0
- package/lib/BibzWhats/index.js +8 -0
- package/lib/BibzWhats/jid.d.ts +22 -0
- package/lib/BibzWhats/jid.js +98 -0
- package/lib/BibzWhats/pairing.d.ts +35 -0
- package/lib/BibzWhats/pairing.js +186 -0
- package/lib/BibzWhats/send.d.ts +9 -0
- package/lib/BibzWhats/send.js +107 -0
- package/lib/BibzWhats/version.d.ts +6 -0
- package/lib/BibzWhats/version.js +7 -0
- package/lib/Defaults/index.d.ts +73 -0
- package/lib/Defaults/index.js +141 -0
- package/lib/Modded/message_builder.d.ts +15 -0
- package/lib/Modded/message_builder.js +2330 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
- package/lib/Signal/Group/ciphertext-message.js +11 -0
- package/lib/Signal/Group/group-session-builder.d.ts +14 -0
- package/lib/Signal/Group/group-session-builder.js +29 -0
- package/lib/Signal/Group/group_cipher.d.ts +16 -0
- package/lib/Signal/Group/group_cipher.js +81 -0
- package/lib/Signal/Group/index.d.ts +11 -0
- package/lib/Signal/Group/index.js +11 -0
- package/lib/Signal/Group/keyhelper.d.ts +10 -0
- package/lib/Signal/Group/keyhelper.js +17 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
- package/lib/Signal/Group/sender-chain-key.js +25 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +62 -0
- package/lib/Signal/Group/sender-key-message.d.ts +18 -0
- package/lib/Signal/Group/sender-key-message.js +65 -0
- package/lib/Signal/Group/sender-key-name.d.ts +17 -0
- package/lib/Signal/Group/sender-key-name.js +47 -0
- package/lib/Signal/Group/sender-key-record.d.ts +30 -0
- package/lib/Signal/Group/sender-key-record.js +40 -0
- package/lib/Signal/Group/sender-key-state.d.ts +38 -0
- package/lib/Signal/Group/sender-key-state.js +83 -0
- package/lib/Signal/Group/sender-message-key.d.ts +11 -0
- package/lib/Signal/Group/sender-message-key.js +25 -0
- package/lib/Signal/libsignal.d.ts +4 -0
- package/lib/Signal/libsignal.js +406 -0
- package/lib/Signal/lid-mapping.d.ts +18 -0
- package/lib/Signal/lid-mapping.js +276 -0
- package/lib/Socket/Client/index.d.ts +2 -0
- package/lib/Socket/Client/index.js +2 -0
- package/lib/Socket/Client/types.d.ts +15 -0
- package/lib/Socket/Client/types.js +10 -0
- package/lib/Socket/Client/websocket.d.ts +12 -0
- package/lib/Socket/Client/websocket.js +53 -0
- package/lib/Socket/business.d.ts +537 -0
- package/lib/Socket/business.js +421 -0
- package/lib/Socket/chats.d.ts +110 -0
- package/lib/Socket/chats.js +1006 -0
- package/lib/Socket/communities.d.ts +646 -0
- package/lib/Socket/communities.js +430 -0
- package/lib/Socket/engine.d.ts +129 -0
- package/lib/Socket/engine.js +767 -0
- package/lib/Socket/groups.d.ts +149 -0
- package/lib/Socket/groups.js +326 -0
- package/lib/Socket/index.d.ts +637 -0
- package/lib/Socket/index.js +14 -0
- package/lib/Socket/messages-recv.d.ts +239 -0
- package/lib/Socket/messages-recv.js +1307 -0
- package/lib/Socket/messages-send.d.ts +580 -0
- package/lib/Socket/messages-send.js +1639 -0
- package/lib/Socket/mex.d.ts +2 -0
- package/lib/Socket/mex.js +47 -0
- package/lib/Socket/newsletter.d.ts +176 -0
- package/lib/Socket/newsletter.js +456 -0
- package/lib/Socket/socket.d.ts +56 -0
- package/lib/Socket/socket.js +998 -0
- package/lib/Types/Auth.d.ts +115 -0
- package/lib/Types/Auth.js +1 -0
- package/lib/Types/Bussines.d.ts +36 -0
- package/lib/Types/Bussines.js +1 -0
- package/lib/Types/Call.d.ts +14 -0
- package/lib/Types/Call.js +1 -0
- package/lib/Types/Chat.d.ts +124 -0
- package/lib/Types/Chat.js +7 -0
- package/lib/Types/Contact.d.ts +23 -0
- package/lib/Types/Contact.js +1 -0
- package/lib/Types/Events.d.ts +241 -0
- package/lib/Types/Events.js +1 -0
- package/lib/Types/GroupMetadata.d.ts +67 -0
- package/lib/Types/GroupMetadata.js +1 -0
- package/lib/Types/Label.d.ts +46 -0
- package/lib/Types/Label.js +24 -0
- package/lib/Types/LabelAssociation.d.ts +29 -0
- package/lib/Types/LabelAssociation.js +6 -0
- package/lib/Types/Message.d.ts +427 -0
- package/lib/Types/Message.js +10 -0
- package/lib/Types/Newsletter.d.ts +134 -0
- package/lib/Types/Newsletter.js +30 -0
- package/lib/Types/Product.d.ts +78 -0
- package/lib/Types/Product.js +1 -0
- package/lib/Types/Signal.d.ts +77 -0
- package/lib/Types/Signal.js +1 -0
- package/lib/Types/Socket.d.ts +173 -0
- package/lib/Types/Socket.js +2 -0
- package/lib/Types/State.d.ts +38 -0
- package/lib/Types/State.js +12 -0
- package/lib/Types/USync.d.ts +25 -0
- package/lib/Types/USync.js +1 -0
- package/lib/Types/index.d.ts +75 -0
- package/lib/Types/index.js +32 -0
- package/lib/Utils/auth-utils.d.ts +18 -0
- package/lib/Utils/auth-utils.js +289 -0
- package/lib/Utils/browser-utils.d.ts +3 -0
- package/lib/Utils/browser-utils.js +47 -0
- package/lib/Utils/business.d.ts +22 -0
- package/lib/Utils/business.js +230 -0
- package/lib/Utils/chat-utils.d.ts +69 -0
- package/lib/Utils/chat-utils.js +811 -0
- package/lib/Utils/companion-reg-client-utils.d.ts +20 -0
- package/lib/Utils/companion-reg-client-utils.js +66 -0
- package/lib/Utils/crypto.d.ts +41 -0
- package/lib/Utils/crypto.js +117 -0
- package/lib/Utils/decode-wa-message.d.ts +47 -0
- package/lib/Utils/decode-wa-message.js +282 -0
- package/lib/Utils/event-buffer.d.ts +35 -0
- package/lib/Utils/event-buffer.js +590 -0
- package/lib/Utils/generics.d.ts +90 -0
- package/lib/Utils/generics.js +384 -0
- package/lib/Utils/history.d.ts +21 -0
- package/lib/Utils/history.js +130 -0
- package/lib/Utils/identity-change-handler.d.ts +36 -0
- package/lib/Utils/identity-change-handler.js +48 -0
- package/lib/Utils/index.d.ts +25 -0
- package/lib/Utils/index.js +24 -0
- package/lib/Utils/link-preview.d.ts +20 -0
- package/lib/Utils/link-preview.js +84 -0
- package/lib/Utils/logger.d.ts +12 -0
- package/lib/Utils/logger.js +2 -0
- package/lib/Utils/lt-hash.d.ts +10 -0
- package/lib/Utils/lt-hash.js +7 -0
- package/lib/Utils/make-mutex.d.ts +8 -0
- package/lib/Utils/make-mutex.js +32 -0
- package/lib/Utils/message-retry-manager.d.ts +109 -0
- package/lib/Utils/message-retry-manager.js +224 -0
- package/lib/Utils/messages-media.d.ts +129 -0
- package/lib/Utils/messages-media.js +784 -0
- package/lib/Utils/messages.d.ts +90 -0
- package/lib/Utils/messages.js +1240 -0
- package/lib/Utils/noise-handler.d.ts +19 -0
- package/lib/Utils/noise-handler.js +200 -0
- package/lib/Utils/offline-node-processor.d.ts +16 -0
- package/lib/Utils/offline-node-processor.js +39 -0
- package/lib/Utils/platform-identity.d.ts +14 -0
- package/lib/Utils/platform-identity.js +148 -0
- package/lib/Utils/pre-key-manager.d.ts +27 -0
- package/lib/Utils/pre-key-manager.js +105 -0
- package/lib/Utils/process-message.d.ts +59 -0
- package/lib/Utils/process-message.js +544 -0
- package/lib/Utils/reporting-utils.d.ts +10 -0
- package/lib/Utils/reporting-utils.js +257 -0
- package/lib/Utils/rich-messages.d.ts +276 -0
- package/lib/Utils/rich-messages.js +1143 -0
- package/lib/Utils/signal.d.ts +33 -0
- package/lib/Utils/signal.js +158 -0
- package/lib/Utils/stanza-ack.d.ts +10 -0
- package/lib/Utils/stanza-ack.js +37 -0
- package/lib/Utils/sticker-pack.d.ts +10 -0
- package/lib/Utils/sticker-pack.js +111 -0
- package/lib/Utils/sync-action-utils.d.ts +18 -0
- package/lib/Utils/sync-action-utils.js +47 -0
- package/lib/Utils/tc-token-utils.d.ts +8 -0
- package/lib/Utils/tc-token-utils.js +45 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +12 -0
- package/lib/Utils/use-multi-file-auth-state.js +120 -0
- package/lib/Utils/validate-connection.d.ts +10 -0
- package/lib/Utils/validate-connection.js +222 -0
- package/lib/VoIP/audio-feeder.d.ts +15 -0
- package/lib/VoIP/audio-feeder.js +136 -0
- package/lib/VoIP/index.d.ts +12 -0
- package/lib/VoIP/index.js +282 -0
- package/lib/VoIP/relay-transport.d.ts +43 -0
- package/lib/VoIP/relay-transport.js +559 -0
- package/lib/VoIP/signaling.js +603 -0
- package/lib/VoIP/types.d.ts +69 -0
- package/lib/VoIP/types.js +17 -0
- package/lib/VoIP/wasm-engine.d.ts +103 -0
- package/lib/VoIP/wasm-engine.js +1214 -0
- package/lib/VoIP/worker-bootstrap.js +1042 -0
- package/lib/WABinary/constants.d.ts +27 -0
- package/lib/WABinary/constants.js +1300 -0
- package/lib/WABinary/decode.d.ts +6 -0
- package/lib/WABinary/decode.js +261 -0
- package/lib/WABinary/encode.d.ts +2 -0
- package/lib/WABinary/encode.js +219 -0
- package/lib/WABinary/generic-utils.d.ts +16 -0
- package/lib/WABinary/generic-utils.js +190 -0
- package/lib/WABinary/index.d.ts +5 -0
- package/lib/WABinary/index.js +5 -0
- package/lib/WABinary/jid-utils.d.ts +47 -0
- package/lib/WABinary/jid-utils.js +95 -0
- package/lib/WABinary/types.d.ts +18 -0
- package/lib/WABinary/types.js +1 -0
- package/lib/WAM/BinaryInfo.d.ts +8 -0
- package/lib/WAM/BinaryInfo.js +9 -0
- package/lib/WAM/constants.d.ts +39 -0
- package/lib/WAM/constants.js +22852 -0
- package/lib/WAM/encode.d.ts +2 -0
- package/lib/WAM/encode.js +149 -0
- package/lib/WAM/index.d.ts +3 -0
- package/lib/WAM/index.js +3 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +28 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +53 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +26 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +37 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +25 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +9 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +28 -0
- package/lib/WAUSync/Protocols/index.d.ts +4 -0
- package/lib/WAUSync/Protocols/index.js +4 -0
- package/lib/WAUSync/USyncQuery.d.ts +28 -0
- package/lib/WAUSync/USyncQuery.js +93 -0
- package/lib/WAUSync/USyncUser.d.ts +12 -0
- package/lib/WAUSync/USyncUser.js +22 -0
- package/lib/WAUSync/index.d.ts +3 -0
- package/lib/WAUSync/index.js +3 -0
- package/lib/assets/wasm/loader.js +5 -0
- package/lib/assets/wasm/whatsapp.wasm +0 -0
- package/lib/assets/wasm/worker-modules.js +273 -0
- package/lib/index.d.ts +21 -0
- package/lib/index.js +22 -0
- package/package.json +111 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { WAMediaUploadFunction, WAUrlInfo } from '../Types/index.js';
|
|
2
|
+
import type { ILogger } from './logger.js';
|
|
3
|
+
export type URLGenerationOptions = {
|
|
4
|
+
thumbnailWidth: number;
|
|
5
|
+
fetchOpts: {
|
|
6
|
+
/** Timeout in ms */
|
|
7
|
+
timeout: number;
|
|
8
|
+
proxyUrl?: string;
|
|
9
|
+
headers?: HeadersInit;
|
|
10
|
+
};
|
|
11
|
+
uploadImage?: WAMediaUploadFunction;
|
|
12
|
+
logger?: ILogger;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Given a piece of text, checks for any URL present, generates link preview for the same and returns it
|
|
16
|
+
* Return undefined if the fetch failed or no URL was found
|
|
17
|
+
* @param text first matched URL in text
|
|
18
|
+
* @returns the URL info required to generate link preview
|
|
19
|
+
*/
|
|
20
|
+
export declare const getUrlInfo: (text: string, opts?: URLGenerationOptions) => Promise<WAUrlInfo | undefined>;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { prepareWAMessageMedia } from './messages.js';
|
|
2
|
+
import { extractImageThumb, getHttpStream } from './messages-media.js';
|
|
3
|
+
const THUMBNAIL_WIDTH_PX = 192;
|
|
4
|
+
/** Fetches an image and generates a thumbnail for it */
|
|
5
|
+
const getCompressedJpegThumbnail = async (url, { thumbnailWidth, fetchOpts }) => {
|
|
6
|
+
const stream = await getHttpStream(url, fetchOpts);
|
|
7
|
+
const result = await extractImageThumb(stream, thumbnailWidth);
|
|
8
|
+
return result;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Given a piece of text, checks for any URL present, generates link preview for the same and returns it
|
|
12
|
+
* Return undefined if the fetch failed or no URL was found
|
|
13
|
+
* @param text first matched URL in text
|
|
14
|
+
* @returns the URL info required to generate link preview
|
|
15
|
+
*/
|
|
16
|
+
export const getUrlInfo = async (text, opts = {
|
|
17
|
+
thumbnailWidth: THUMBNAIL_WIDTH_PX,
|
|
18
|
+
fetchOpts: { timeout: 3000 }
|
|
19
|
+
}) => {
|
|
20
|
+
try {
|
|
21
|
+
// retries
|
|
22
|
+
const retries = 0;
|
|
23
|
+
const maxRetry = 5;
|
|
24
|
+
const { getLinkPreview } = await import('link-preview-js');
|
|
25
|
+
let previewLink = text;
|
|
26
|
+
if (!text.startsWith('https://') && !text.startsWith('http://')) {
|
|
27
|
+
previewLink = 'https://' + previewLink;
|
|
28
|
+
}
|
|
29
|
+
const info = await getLinkPreview(previewLink, {
|
|
30
|
+
...opts.fetchOpts,
|
|
31
|
+
followRedirects: 'follow',
|
|
32
|
+
handleRedirects: (baseURL, forwardedURL) => {
|
|
33
|
+
const urlObj = new URL(baseURL);
|
|
34
|
+
const forwardedURLObj = new URL(forwardedURL);
|
|
35
|
+
if (retries >= maxRetry) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
if (forwardedURLObj.hostname === urlObj.hostname ||
|
|
39
|
+
forwardedURLObj.hostname === 'www.' + urlObj.hostname ||
|
|
40
|
+
'www.' + forwardedURLObj.hostname === urlObj.hostname) {
|
|
41
|
+
retries + 1;
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
headers: opts.fetchOpts?.headers
|
|
49
|
+
});
|
|
50
|
+
if (info && 'title' in info && info.title) {
|
|
51
|
+
const [image] = info.images;
|
|
52
|
+
const urlInfo = {
|
|
53
|
+
'canonical-url': info.url,
|
|
54
|
+
'matched-text': text,
|
|
55
|
+
title: info.title,
|
|
56
|
+
description: info.description,
|
|
57
|
+
originalThumbnailUrl: image
|
|
58
|
+
};
|
|
59
|
+
if (opts.uploadImage) {
|
|
60
|
+
const { imageMessage } = await prepareWAMessageMedia({ image: { url: image } }, {
|
|
61
|
+
upload: opts.uploadImage,
|
|
62
|
+
mediaTypeOverride: 'thumbnail-link',
|
|
63
|
+
options: opts.fetchOpts
|
|
64
|
+
});
|
|
65
|
+
urlInfo.jpegThumbnail = imageMessage?.jpegThumbnail ? Buffer.from(imageMessage.jpegThumbnail) : undefined;
|
|
66
|
+
urlInfo.highQualityThumbnail = imageMessage || undefined;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
try {
|
|
70
|
+
urlInfo.jpegThumbnail = image ? (await getCompressedJpegThumbnail(image, opts)).buffer : undefined;
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
opts.logger?.debug({ err: error.stack, url: previewLink }, 'error in generating thumbnail');
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return urlInfo;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
if (!error.message.includes('receive a valid')) {
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import P from 'pino';
|
|
2
|
+
export interface ILogger {
|
|
3
|
+
level: string;
|
|
4
|
+
child(obj: Record<string, unknown>): ILogger;
|
|
5
|
+
trace(obj: unknown, msg?: string): void;
|
|
6
|
+
debug(obj: unknown, msg?: string): void;
|
|
7
|
+
info(obj: unknown, msg?: string): void;
|
|
8
|
+
warn(obj: unknown, msg?: string): void;
|
|
9
|
+
error(obj: unknown, msg?: string): void;
|
|
10
|
+
}
|
|
11
|
+
declare const _default: P.Logger<never, boolean>;
|
|
12
|
+
export default _default;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LT Hash is a summation based hash algorithm that maintains the integrity of a piece of data
|
|
3
|
+
* over a series of mutations. You can add/remove mutations and it'll return a hash equal to
|
|
4
|
+
* if the same series of mutations was made sequentially.
|
|
5
|
+
*/
|
|
6
|
+
export interface LTHashAntiTampering {
|
|
7
|
+
subtractThenAdd(base: Uint8Array, subtract: Uint8Array[], add: Uint8Array[]): Uint8Array;
|
|
8
|
+
free(): void;
|
|
9
|
+
}
|
|
10
|
+
export declare const LT_HASH_ANTI_TAMPERING: LTHashAntiTampering;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { LTHashAntiTampering } from 'whatsapp-rust-bridge';
|
|
2
|
+
/**
|
|
3
|
+
* LT Hash is a summation based hash algorithm that maintains the integrity of a piece of data
|
|
4
|
+
* over a series of mutations. You can add/remove mutations and it'll return a hash equal to
|
|
5
|
+
* if the same series of mutations was made sequentially.
|
|
6
|
+
*/
|
|
7
|
+
export const LT_HASH_ANTI_TAMPERING = new LTHashAntiTampering();
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const makeMutex: () => {
|
|
2
|
+
mutex<T>(code: () => Promise<T> | T): Promise<T>;
|
|
3
|
+
};
|
|
4
|
+
export type Mutex = ReturnType<typeof makeMutex>;
|
|
5
|
+
export declare const makeKeyedMutex: () => {
|
|
6
|
+
mutex<T>(key: string, task: () => Promise<T> | T): Promise<T>;
|
|
7
|
+
};
|
|
8
|
+
export type KeyedMutex = ReturnType<typeof makeKeyedMutex>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Mutex as AsyncMutex } from 'async-mutex';
|
|
2
|
+
export const makeMutex = () => {
|
|
3
|
+
const mutex = new AsyncMutex();
|
|
4
|
+
return {
|
|
5
|
+
mutex(code) {
|
|
6
|
+
return mutex.runExclusive(code);
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
export const makeKeyedMutex = () => {
|
|
11
|
+
const map = new Map();
|
|
12
|
+
return {
|
|
13
|
+
async mutex(key, task) {
|
|
14
|
+
let entry = map.get(key);
|
|
15
|
+
if (!entry) {
|
|
16
|
+
entry = { mutex: new AsyncMutex(), refCount: 0 };
|
|
17
|
+
map.set(key, entry);
|
|
18
|
+
}
|
|
19
|
+
entry.refCount++;
|
|
20
|
+
try {
|
|
21
|
+
return await entry.mutex.runExclusive(task);
|
|
22
|
+
}
|
|
23
|
+
finally {
|
|
24
|
+
entry.refCount--;
|
|
25
|
+
// only delete it if this is still the current entry
|
|
26
|
+
if (entry.refCount === 0 && map.get(key) === entry) {
|
|
27
|
+
map.delete(key);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import type { proto } from '../../WAProto/index.js';
|
|
2
|
+
import type { ILogger } from './logger.js';
|
|
3
|
+
export interface RecentMessageKey {
|
|
4
|
+
to: string;
|
|
5
|
+
id: string;
|
|
6
|
+
}
|
|
7
|
+
export interface RecentMessage {
|
|
8
|
+
message: proto.IMessage;
|
|
9
|
+
timestamp: number;
|
|
10
|
+
}
|
|
11
|
+
export interface SessionRecreateHistory {
|
|
12
|
+
[jid: string]: number;
|
|
13
|
+
}
|
|
14
|
+
export interface RetryCounter {
|
|
15
|
+
[messageId: string]: number;
|
|
16
|
+
}
|
|
17
|
+
export type PendingPhoneRequest = Record<string, ReturnType<typeof setTimeout>>;
|
|
18
|
+
export interface RetryStatistics {
|
|
19
|
+
totalRetries: number;
|
|
20
|
+
successfulRetries: number;
|
|
21
|
+
failedRetries: number;
|
|
22
|
+
mediaRetries: number;
|
|
23
|
+
sessionRecreations: number;
|
|
24
|
+
phoneRequests: number;
|
|
25
|
+
}
|
|
26
|
+
export declare enum RetryReason {
|
|
27
|
+
UnknownError = 0,
|
|
28
|
+
SignalErrorNoSession = 1,
|
|
29
|
+
SignalErrorInvalidKey = 2,
|
|
30
|
+
SignalErrorInvalidKeyId = 3,
|
|
31
|
+
/** MAC verification failed - most common cause of decryption failures */
|
|
32
|
+
SignalErrorInvalidMessage = 4,
|
|
33
|
+
SignalErrorInvalidSignature = 5,
|
|
34
|
+
SignalErrorFutureMessage = 6,
|
|
35
|
+
/** Explicit MAC failure - session is definitely out of sync */
|
|
36
|
+
SignalErrorBadMac = 7,
|
|
37
|
+
SignalErrorInvalidSession = 8,
|
|
38
|
+
SignalErrorInvalidMsgKey = 9,
|
|
39
|
+
BadBroadcastEphemeralSetting = 10,
|
|
40
|
+
UnknownCompanionNoPrekey = 11,
|
|
41
|
+
AdvFailure = 12,
|
|
42
|
+
StatusRevokeDelay = 13
|
|
43
|
+
}
|
|
44
|
+
export declare class MessageRetryManager {
|
|
45
|
+
private logger;
|
|
46
|
+
private recentMessagesMap;
|
|
47
|
+
private messageKeyIndex;
|
|
48
|
+
private sessionRecreateHistory;
|
|
49
|
+
private retryCounters;
|
|
50
|
+
private pendingPhoneRequests;
|
|
51
|
+
private readonly maxMsgRetryCount;
|
|
52
|
+
private statistics;
|
|
53
|
+
constructor(logger: ILogger, maxMsgRetryCount: number);
|
|
54
|
+
/**
|
|
55
|
+
* Add a recent message to the cache for retry handling
|
|
56
|
+
*/
|
|
57
|
+
addRecentMessage(to: string, id: string, message: proto.IMessage): void;
|
|
58
|
+
/**
|
|
59
|
+
* Get a recent message from the cache
|
|
60
|
+
*/
|
|
61
|
+
getRecentMessage(to: string, id: string): RecentMessage | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* Check if a session should be recreated based on retry count, history, and error code.
|
|
64
|
+
* MAC errors (codes 4 and 7) trigger immediate session recreation regardless of timeout.
|
|
65
|
+
*/
|
|
66
|
+
shouldRecreateSession(jid: string, hasSession: boolean, errorCode?: RetryReason): {
|
|
67
|
+
reason: string;
|
|
68
|
+
recreate: boolean;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Parse error code from retry receipt's retry node.
|
|
72
|
+
* Returns undefined if no error code is present.
|
|
73
|
+
*/
|
|
74
|
+
parseRetryErrorCode(errorAttr: string | undefined): RetryReason | undefined;
|
|
75
|
+
/**
|
|
76
|
+
* Check if an error code indicates a MAC failure
|
|
77
|
+
*/
|
|
78
|
+
isMacError(errorCode: RetryReason | undefined): boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Increment retry counter for a message
|
|
81
|
+
*/
|
|
82
|
+
incrementRetryCount(messageId: string): number;
|
|
83
|
+
/**
|
|
84
|
+
* Get retry count for a message
|
|
85
|
+
*/
|
|
86
|
+
getRetryCount(messageId: string): number;
|
|
87
|
+
/**
|
|
88
|
+
* Check if message has exceeded maximum retry attempts
|
|
89
|
+
*/
|
|
90
|
+
hasExceededMaxRetries(messageId: string): boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Mark retry as successful
|
|
93
|
+
*/
|
|
94
|
+
markRetrySuccess(messageId: string): void;
|
|
95
|
+
/**
|
|
96
|
+
* Mark retry as failed
|
|
97
|
+
*/
|
|
98
|
+
markRetryFailed(messageId: string): void;
|
|
99
|
+
/**
|
|
100
|
+
* Schedule a phone request with delay
|
|
101
|
+
*/
|
|
102
|
+
schedulePhoneRequest(messageId: string, callback: () => void, delay?: number): void;
|
|
103
|
+
/**
|
|
104
|
+
* Cancel pending phone request
|
|
105
|
+
*/
|
|
106
|
+
cancelPendingPhoneRequest(messageId: string): void;
|
|
107
|
+
private keyToString;
|
|
108
|
+
private removeRecentMessage;
|
|
109
|
+
}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { LRUCache } from 'lru-cache';
|
|
2
|
+
/** Number of sent messages to cache in memory for handling retry receipts */
|
|
3
|
+
const RECENT_MESSAGES_SIZE = 512;
|
|
4
|
+
const MESSAGE_KEY_SEPARATOR = '\u0000';
|
|
5
|
+
/** Timeout for session recreation - 1 hour */
|
|
6
|
+
const RECREATE_SESSION_TIMEOUT = 60 * 60 * 1000; // 1 hour in milliseconds
|
|
7
|
+
const PHONE_REQUEST_DELAY = 3000;
|
|
8
|
+
// Retry reason codes matching WhatsApp Web's Signal error codes.
|
|
9
|
+
export var RetryReason;
|
|
10
|
+
(function (RetryReason) {
|
|
11
|
+
RetryReason[RetryReason["UnknownError"] = 0] = "UnknownError";
|
|
12
|
+
RetryReason[RetryReason["SignalErrorNoSession"] = 1] = "SignalErrorNoSession";
|
|
13
|
+
RetryReason[RetryReason["SignalErrorInvalidKey"] = 2] = "SignalErrorInvalidKey";
|
|
14
|
+
RetryReason[RetryReason["SignalErrorInvalidKeyId"] = 3] = "SignalErrorInvalidKeyId";
|
|
15
|
+
/** MAC verification failed - most common cause of decryption failures */
|
|
16
|
+
RetryReason[RetryReason["SignalErrorInvalidMessage"] = 4] = "SignalErrorInvalidMessage";
|
|
17
|
+
RetryReason[RetryReason["SignalErrorInvalidSignature"] = 5] = "SignalErrorInvalidSignature";
|
|
18
|
+
RetryReason[RetryReason["SignalErrorFutureMessage"] = 6] = "SignalErrorFutureMessage";
|
|
19
|
+
/** Explicit MAC failure - session is definitely out of sync */
|
|
20
|
+
RetryReason[RetryReason["SignalErrorBadMac"] = 7] = "SignalErrorBadMac";
|
|
21
|
+
RetryReason[RetryReason["SignalErrorInvalidSession"] = 8] = "SignalErrorInvalidSession";
|
|
22
|
+
RetryReason[RetryReason["SignalErrorInvalidMsgKey"] = 9] = "SignalErrorInvalidMsgKey";
|
|
23
|
+
RetryReason[RetryReason["BadBroadcastEphemeralSetting"] = 10] = "BadBroadcastEphemeralSetting";
|
|
24
|
+
RetryReason[RetryReason["UnknownCompanionNoPrekey"] = 11] = "UnknownCompanionNoPrekey";
|
|
25
|
+
RetryReason[RetryReason["AdvFailure"] = 12] = "AdvFailure";
|
|
26
|
+
RetryReason[RetryReason["StatusRevokeDelay"] = 13] = "StatusRevokeDelay";
|
|
27
|
+
})(RetryReason || (RetryReason = {}));
|
|
28
|
+
/** Error codes that indicate a MAC failure and require immediate session recreation */
|
|
29
|
+
const MAC_ERROR_CODES = new Set([RetryReason.SignalErrorInvalidMessage, RetryReason.SignalErrorBadMac]);
|
|
30
|
+
export class MessageRetryManager {
|
|
31
|
+
constructor(logger, maxMsgRetryCount) {
|
|
32
|
+
this.logger = logger;
|
|
33
|
+
this.recentMessagesMap = new LRUCache({
|
|
34
|
+
max: RECENT_MESSAGES_SIZE,
|
|
35
|
+
ttl: 5 * 60 * 1000,
|
|
36
|
+
ttlAutopurge: true,
|
|
37
|
+
dispose: (_value, key) => {
|
|
38
|
+
const separatorIndex = key.lastIndexOf(MESSAGE_KEY_SEPARATOR);
|
|
39
|
+
if (separatorIndex > -1) {
|
|
40
|
+
const messageId = key.slice(separatorIndex + MESSAGE_KEY_SEPARATOR.length);
|
|
41
|
+
this.messageKeyIndex.delete(messageId);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
this.messageKeyIndex = new Map();
|
|
46
|
+
this.sessionRecreateHistory = new LRUCache({
|
|
47
|
+
ttl: RECREATE_SESSION_TIMEOUT * 2,
|
|
48
|
+
ttlAutopurge: true
|
|
49
|
+
});
|
|
50
|
+
this.retryCounters = new LRUCache({
|
|
51
|
+
ttl: 15 * 60 * 1000,
|
|
52
|
+
ttlAutopurge: true,
|
|
53
|
+
updateAgeOnGet: true
|
|
54
|
+
}); // 15 minutes TTL
|
|
55
|
+
this.pendingPhoneRequests = {};
|
|
56
|
+
this.maxMsgRetryCount = 5;
|
|
57
|
+
this.statistics = {
|
|
58
|
+
totalRetries: 0,
|
|
59
|
+
successfulRetries: 0,
|
|
60
|
+
failedRetries: 0,
|
|
61
|
+
mediaRetries: 0,
|
|
62
|
+
sessionRecreations: 0,
|
|
63
|
+
phoneRequests: 0
|
|
64
|
+
};
|
|
65
|
+
this.maxMsgRetryCount = maxMsgRetryCount;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Add a recent message to the cache for retry handling
|
|
69
|
+
*/
|
|
70
|
+
addRecentMessage(to, id, message) {
|
|
71
|
+
const key = { to, id };
|
|
72
|
+
const keyStr = this.keyToString(key);
|
|
73
|
+
// Add new message
|
|
74
|
+
this.recentMessagesMap.set(keyStr, {
|
|
75
|
+
message,
|
|
76
|
+
timestamp: Date.now()
|
|
77
|
+
});
|
|
78
|
+
this.messageKeyIndex.set(id, keyStr);
|
|
79
|
+
this.logger.debug(`Added message to retry cache: ${to}/${id}`);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Get a recent message from the cache
|
|
83
|
+
*/
|
|
84
|
+
getRecentMessage(to, id) {
|
|
85
|
+
const key = { to, id };
|
|
86
|
+
const keyStr = this.keyToString(key);
|
|
87
|
+
return this.recentMessagesMap.get(keyStr);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Check if a session should be recreated based on retry count, history, and error code.
|
|
91
|
+
* MAC errors (codes 4 and 7) trigger immediate session recreation regardless of timeout.
|
|
92
|
+
*/
|
|
93
|
+
shouldRecreateSession(jid, hasSession, errorCode) {
|
|
94
|
+
// If we don't have a session, always recreate
|
|
95
|
+
if (!hasSession) {
|
|
96
|
+
this.sessionRecreateHistory.set(jid, Date.now());
|
|
97
|
+
this.statistics.sessionRecreations++;
|
|
98
|
+
return {
|
|
99
|
+
reason: "we don't have a Signal session with them",
|
|
100
|
+
recreate: true
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
// IMMEDIATE recreation for MAC errors - session is definitely out of sync
|
|
104
|
+
if (errorCode !== undefined && MAC_ERROR_CODES.has(errorCode)) {
|
|
105
|
+
this.sessionRecreateHistory.set(jid, Date.now());
|
|
106
|
+
this.statistics.sessionRecreations++;
|
|
107
|
+
this.logger.warn({ jid, errorCode: RetryReason[errorCode] }, 'MAC error detected, forcing immediate session recreation');
|
|
108
|
+
return {
|
|
109
|
+
reason: `MAC error (code ${errorCode}: ${RetryReason[errorCode]}), immediate session recreation`,
|
|
110
|
+
recreate: true
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
const now = Date.now();
|
|
114
|
+
const prevTime = this.sessionRecreateHistory.get(jid);
|
|
115
|
+
// If no previous recreation or it's been more than an hour
|
|
116
|
+
if (!prevTime || now - prevTime > RECREATE_SESSION_TIMEOUT) {
|
|
117
|
+
this.sessionRecreateHistory.set(jid, now);
|
|
118
|
+
this.statistics.sessionRecreations++;
|
|
119
|
+
return {
|
|
120
|
+
reason: 'retry count > 1 and over an hour since last recreation',
|
|
121
|
+
recreate: true
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
return { reason: '', recreate: false };
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Parse error code from retry receipt's retry node.
|
|
128
|
+
* Returns undefined if no error code is present.
|
|
129
|
+
*/
|
|
130
|
+
parseRetryErrorCode(errorAttr) {
|
|
131
|
+
if (errorAttr === undefined || errorAttr === '') {
|
|
132
|
+
return undefined;
|
|
133
|
+
}
|
|
134
|
+
const code = parseInt(errorAttr, 10);
|
|
135
|
+
if (Number.isNaN(code)) {
|
|
136
|
+
return undefined;
|
|
137
|
+
}
|
|
138
|
+
// Validate it's a known RetryReason
|
|
139
|
+
if (code >= RetryReason.UnknownError && code <= RetryReason.StatusRevokeDelay) {
|
|
140
|
+
return code;
|
|
141
|
+
}
|
|
142
|
+
return RetryReason.UnknownError;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Check if an error code indicates a MAC failure
|
|
146
|
+
*/
|
|
147
|
+
isMacError(errorCode) {
|
|
148
|
+
return errorCode !== undefined && MAC_ERROR_CODES.has(errorCode);
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Increment retry counter for a message
|
|
152
|
+
*/
|
|
153
|
+
incrementRetryCount(messageId) {
|
|
154
|
+
this.retryCounters.set(messageId, (this.retryCounters.get(messageId) || 0) + 1);
|
|
155
|
+
this.statistics.totalRetries++;
|
|
156
|
+
return this.retryCounters.get(messageId);
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Get retry count for a message
|
|
160
|
+
*/
|
|
161
|
+
getRetryCount(messageId) {
|
|
162
|
+
return this.retryCounters.get(messageId) || 0;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Check if message has exceeded maximum retry attempts
|
|
166
|
+
*/
|
|
167
|
+
hasExceededMaxRetries(messageId) {
|
|
168
|
+
return this.getRetryCount(messageId) >= this.maxMsgRetryCount;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Mark retry as successful
|
|
172
|
+
*/
|
|
173
|
+
markRetrySuccess(messageId) {
|
|
174
|
+
this.statistics.successfulRetries++;
|
|
175
|
+
// Clean up retry counter for successful message
|
|
176
|
+
this.retryCounters.delete(messageId);
|
|
177
|
+
this.cancelPendingPhoneRequest(messageId);
|
|
178
|
+
this.removeRecentMessage(messageId);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Mark retry as failed
|
|
182
|
+
*/
|
|
183
|
+
markRetryFailed(messageId) {
|
|
184
|
+
this.statistics.failedRetries++;
|
|
185
|
+
this.retryCounters.delete(messageId);
|
|
186
|
+
this.cancelPendingPhoneRequest(messageId);
|
|
187
|
+
this.removeRecentMessage(messageId);
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Schedule a phone request with delay
|
|
191
|
+
*/
|
|
192
|
+
schedulePhoneRequest(messageId, callback, delay = PHONE_REQUEST_DELAY) {
|
|
193
|
+
// Cancel any existing request for this message
|
|
194
|
+
this.cancelPendingPhoneRequest(messageId);
|
|
195
|
+
this.pendingPhoneRequests[messageId] = setTimeout(() => {
|
|
196
|
+
delete this.pendingPhoneRequests[messageId];
|
|
197
|
+
this.statistics.phoneRequests++;
|
|
198
|
+
callback();
|
|
199
|
+
}, delay);
|
|
200
|
+
this.logger.debug(`Scheduled phone request for message ${messageId} with ${delay}ms delay`);
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Cancel pending phone request
|
|
204
|
+
*/
|
|
205
|
+
cancelPendingPhoneRequest(messageId) {
|
|
206
|
+
const timeout = this.pendingPhoneRequests[messageId];
|
|
207
|
+
if (timeout) {
|
|
208
|
+
clearTimeout(timeout);
|
|
209
|
+
delete this.pendingPhoneRequests[messageId];
|
|
210
|
+
this.logger.debug(`Cancelled pending phone request for message ${messageId}`);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
keyToString(key) {
|
|
214
|
+
return `${key.to}${MESSAGE_KEY_SEPARATOR}${key.id}`;
|
|
215
|
+
}
|
|
216
|
+
removeRecentMessage(messageId) {
|
|
217
|
+
const keyStr = this.messageKeyIndex.get(messageId);
|
|
218
|
+
if (!keyStr) {
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
this.recentMessagesMap.delete(keyStr);
|
|
222
|
+
this.messageKeyIndex.delete(messageId);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { Boom } from '@hapi/boom';
|
|
2
|
+
import type { Agent } from 'https';
|
|
3
|
+
import { Readable } from 'stream';
|
|
4
|
+
import { URL } from 'url';
|
|
5
|
+
import { proto } from '../../WAProto/index.js';
|
|
6
|
+
import { type MediaType } from '../Defaults/index.js';
|
|
7
|
+
import type { DownloadableMessage, MediaConnInfo, MediaDecryptionKeyInfo, SocketConfig, WAMediaUpload, WAMediaUploadFunction, WAMessageContent, WAMessageKey } from '../Types/index.js';
|
|
8
|
+
import { type BinaryNode } from '../WABinary/index.js';
|
|
9
|
+
import type { ILogger } from './logger.js';
|
|
10
|
+
export declare const hkdfInfoKey: (type: MediaType) => string;
|
|
11
|
+
export declare const getRawMediaUploadData: (media: WAMediaUpload, mediaType: MediaType, logger?: ILogger) => Promise<{
|
|
12
|
+
filePath: string;
|
|
13
|
+
fileSha256: Buffer;
|
|
14
|
+
fileLength: number;
|
|
15
|
+
}>;
|
|
16
|
+
/** generates all the keys required to encrypt/decrypt & sign a media message */
|
|
17
|
+
export declare function getMediaKeys(buffer: Uint8Array | string | null | undefined, mediaType: MediaType): Promise<MediaDecryptionKeyInfo>;
|
|
18
|
+
export declare const extractImageThumb: (bufferOrFilePath: Readable | Buffer | string, width?: number) => Promise<{
|
|
19
|
+
buffer: any;
|
|
20
|
+
original: {
|
|
21
|
+
width: any;
|
|
22
|
+
height: any;
|
|
23
|
+
};
|
|
24
|
+
}>;
|
|
25
|
+
export declare const encodeBase64EncodedStringForUpload: (b64: string) => string;
|
|
26
|
+
export declare const generateProfilePicture: (mediaUpload: WAMediaUpload, dimensions?: {
|
|
27
|
+
width: number;
|
|
28
|
+
height: number;
|
|
29
|
+
}) => Promise<{
|
|
30
|
+
img: Buffer;
|
|
31
|
+
}>;
|
|
32
|
+
/** gets the SHA256 of the given media message */
|
|
33
|
+
export declare const mediaMessageSHA256B64: (message: WAMessageContent) => string | null | undefined;
|
|
34
|
+
export declare function getAudioDuration(buffer: Buffer | string | Readable): Promise<number | undefined>;
|
|
35
|
+
/**
|
|
36
|
+
referenced from and modifying https://github.com/wppconnect-team/wa-js/blob/main/src/chat/functions/prepareAudioWaveform.ts
|
|
37
|
+
*/
|
|
38
|
+
export declare function getAudioWaveform(buffer: Buffer | string | Readable, logger?: ILogger): Promise<Uint8Array<ArrayBuffer> | undefined>;
|
|
39
|
+
export declare const toReadable: (buffer: Buffer) => Readable;
|
|
40
|
+
export declare const toBuffer: (stream: Readable) => Promise<Buffer>;
|
|
41
|
+
export declare const getStream: (item: WAMediaUpload, opts?: RequestInit & {
|
|
42
|
+
maxContentLength?: number;
|
|
43
|
+
}) => Promise<{
|
|
44
|
+
readonly stream: Readable;
|
|
45
|
+
readonly type: "buffer";
|
|
46
|
+
} | {
|
|
47
|
+
readonly stream: Readable;
|
|
48
|
+
readonly type: "readable";
|
|
49
|
+
} | {
|
|
50
|
+
readonly stream: any;
|
|
51
|
+
readonly type: "remote";
|
|
52
|
+
} | {
|
|
53
|
+
readonly stream: import("fs").ReadStream;
|
|
54
|
+
readonly type: "file";
|
|
55
|
+
}>;
|
|
56
|
+
/** generates a thumbnail for a given media, if required */
|
|
57
|
+
export declare function generateThumbnail(file: string, mediaType: 'video' | 'image', options: {
|
|
58
|
+
logger?: ILogger;
|
|
59
|
+
}): Promise<{
|
|
60
|
+
thumbnail: string | undefined;
|
|
61
|
+
originalImageDimensions: {
|
|
62
|
+
width: number;
|
|
63
|
+
height: number;
|
|
64
|
+
} | undefined;
|
|
65
|
+
}>;
|
|
66
|
+
export declare const getHttpStream: (url: string | URL, options?: RequestInit & {
|
|
67
|
+
isStream?: true;
|
|
68
|
+
}) => Promise<any>;
|
|
69
|
+
type EncryptedStreamOptions = {
|
|
70
|
+
saveOriginalFileIfRequired?: boolean;
|
|
71
|
+
logger?: ILogger;
|
|
72
|
+
opts?: RequestInit;
|
|
73
|
+
};
|
|
74
|
+
export declare const encryptedStream: (media: WAMediaUpload, mediaType: MediaType, { logger, saveOriginalFileIfRequired, opts }?: EncryptedStreamOptions) => Promise<{
|
|
75
|
+
mediaKey: Buffer;
|
|
76
|
+
originalFilePath: string | undefined;
|
|
77
|
+
encFilePath: string;
|
|
78
|
+
mac: Buffer;
|
|
79
|
+
fileEncSha256: Buffer;
|
|
80
|
+
fileSha256: Buffer;
|
|
81
|
+
fileLength: number;
|
|
82
|
+
}>;
|
|
83
|
+
export type MediaDownloadOptions = {
|
|
84
|
+
startByte?: number;
|
|
85
|
+
endByte?: number;
|
|
86
|
+
options?: RequestInit;
|
|
87
|
+
};
|
|
88
|
+
export declare const getUrlFromDirectPath: (directPath: string) => string;
|
|
89
|
+
export declare const downloadContentFromMessage: ({ mediaKey, directPath, url }: DownloadableMessage, type: MediaType, opts?: MediaDownloadOptions) => Promise<any>;
|
|
90
|
+
/**
|
|
91
|
+
* Decrypts and downloads an AES256-CBC encrypted file given the keys.
|
|
92
|
+
* Assumes the SHA256 of the plaintext is appended to the end of the ciphertext
|
|
93
|
+
* */
|
|
94
|
+
export declare const downloadEncryptedContent: (downloadUrl: string, { cipherKey, iv }: MediaDecryptionKeyInfo, { startByte, endByte, options }?: MediaDownloadOptions) => Promise<any>;
|
|
95
|
+
export declare function extensionForMediaMessage(message: WAMessageContent): string;
|
|
96
|
+
type MediaUploadResult = {
|
|
97
|
+
url?: string;
|
|
98
|
+
direct_path?: string;
|
|
99
|
+
meta_hmac?: string;
|
|
100
|
+
ts?: number;
|
|
101
|
+
fbid?: number;
|
|
102
|
+
};
|
|
103
|
+
export type UploadParams = {
|
|
104
|
+
url: string;
|
|
105
|
+
filePath: string;
|
|
106
|
+
headers: Record<string, string>;
|
|
107
|
+
timeoutMs?: number;
|
|
108
|
+
agent?: Agent;
|
|
109
|
+
};
|
|
110
|
+
export declare const uploadWithNodeHttp: ({ url, filePath, headers, timeoutMs, agent }: UploadParams, redirectCount?: number) => Promise<MediaUploadResult | undefined>;
|
|
111
|
+
export declare const getWAUploadToServer: ({ customUploadHosts, fetchAgent, logger, options }: SocketConfig, refreshMediaConn: (force: boolean) => Promise<MediaConnInfo>) => WAMediaUploadFunction;
|
|
112
|
+
/**
|
|
113
|
+
* Generate a binary node that will request the phone to re-upload the media & return the newly uploaded URL
|
|
114
|
+
*/
|
|
115
|
+
export declare const encryptMediaRetryRequest: (key: WAMessageKey, mediaKey: Buffer | Uint8Array, meId: string) => BinaryNode;
|
|
116
|
+
export declare const decodeMediaRetryNode: (node: BinaryNode) => {
|
|
117
|
+
key: WAMessageKey;
|
|
118
|
+
media?: {
|
|
119
|
+
ciphertext: Uint8Array;
|
|
120
|
+
iv: Uint8Array;
|
|
121
|
+
};
|
|
122
|
+
error?: Boom;
|
|
123
|
+
};
|
|
124
|
+
export declare const decryptMediaRetryData: ({ ciphertext, iv }: {
|
|
125
|
+
ciphertext: Uint8Array;
|
|
126
|
+
iv: Uint8Array;
|
|
127
|
+
}, mediaKey: Uint8Array, msgId: string) => proto.MediaRetryNotification;
|
|
128
|
+
export declare const getStatusCodeForMediaRetry: (code: number) => 200 | 412 | 404 | 418;
|
|
129
|
+
export {};
|