naya-flore 4.7.1
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/LICENSE +21 -0
- package/README.md +104 -0
- package/WAProto/GenerateStatics.sh +4 -0
- package/WAProto/WAProto.proto +4450 -0
- package/WAProto/index.d.ts +48955 -0
- package/WAProto/index.js +151420 -0
- package/WASignalGroup/GroupProtocol.js +1697 -0
- package/WASignalGroup/ciphertext_message.js +16 -0
- package/WASignalGroup/group_cipher.js +120 -0
- package/WASignalGroup/group_session_builder.js +46 -0
- package/WASignalGroup/index.js +5 -0
- package/WASignalGroup/keyhelper.js +21 -0
- package/WASignalGroup/protobufs.js +3 -0
- package/WASignalGroup/queue_job.js +69 -0
- package/WASignalGroup/sender_chain_key.js +50 -0
- package/WASignalGroup/sender_key_distribution_message.js +78 -0
- package/WASignalGroup/sender_key_message.js +92 -0
- package/WASignalGroup/sender_key_name.js +70 -0
- package/WASignalGroup/sender_key_record.js +56 -0
- package/WASignalGroup/sender_key_state.js +129 -0
- package/WASignalGroup/sender_message_key.js +39 -0
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/index.d.ts +284 -0
- package/lib/Defaults/index.js +120 -0
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Signal/libsignal.d.ts +3 -0
- package/lib/Signal/libsignal.js +161 -0
- package/lib/Socket/Client/abstract-socket-client.d.ts +15 -0
- package/lib/Socket/Client/abstract-socket-client.js +13 -0
- package/lib/Socket/Client/index.d.ts +2 -0
- package/lib/Socket/Client/index.js +18 -0
- package/lib/Socket/Client/mobile-socket-client.d.ts +12 -0
- package/lib/Socket/Client/mobile-socket-client.js +65 -0
- package/lib/Socket/Client/types.d.ts +17 -0
- package/lib/Socket/Client/types.js +13 -0
- package/lib/Socket/Client/websocket.d.ts +12 -0
- package/lib/Socket/Client/websocket.js +62 -0
- package/lib/Socket/business.d.ts +170 -0
- package/lib/Socket/business.js +260 -0
- package/lib/Socket/chats.d.ts +81 -0
- package/lib/Socket/chats.js +871 -0
- package/lib/Socket/groups.d.ts +115 -0
- package/lib/Socket/groups.js +304 -0
- package/lib/Socket/index.d.ts +172 -0
- package/lib/Socket/index.js +10 -0
- package/lib/Socket/messages-recv.d.ts +158 -0
- package/lib/Socket/messages-recv.js +966 -0
- package/lib/Socket/messages-send.d.ts +155 -0
- package/lib/Socket/messages-send.js +1021 -0
- package/lib/Socket/newsletter.d.ts +132 -0
- package/lib/Socket/newsletter.js +236 -0
- package/lib/Socket/registration.d.ts +264 -0
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.d.ts +44 -0
- package/lib/Socket/socket.js +666 -0
- package/lib/Socket/usync.d.ts +37 -0
- package/lib/Socket/usync.js +70 -0
- package/lib/Store/index.d.ts +3 -0
- package/lib/Store/index.js +10 -0
- package/lib/Store/make-cache-manager-store.d.ts +14 -0
- package/lib/Store/make-cache-manager-store.js +83 -0
- package/lib/Store/make-in-memory-store.d.ts +118 -0
- package/lib/Store/make-in-memory-store.js +431 -0
- package/lib/Store/make-ordered-dictionary.d.ts +13 -0
- package/lib/Store/make-ordered-dictionary.js +81 -0
- package/lib/Store/object-repository.d.ts +10 -0
- package/lib/Store/object-repository.js +27 -0
- package/lib/Types/Auth.d.ts +109 -0
- package/lib/Types/Auth.js +2 -0
- package/lib/Types/Call.d.ts +13 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Chat.d.ts +107 -0
- package/lib/Types/Chat.js +4 -0
- package/lib/Types/Contact.d.ts +19 -0
- package/lib/Types/Contact.js +2 -0
- package/lib/Types/Events.d.ts +172 -0
- package/lib/Types/Events.js +2 -0
- package/lib/Types/GroupMetadata.d.ts +56 -0
- package/lib/Types/GroupMetadata.js +2 -0
- package/lib/Types/Label.d.ts +46 -0
- package/lib/Types/Label.js +27 -0
- package/lib/Types/LabelAssociation.d.ts +29 -0
- package/lib/Types/LabelAssociation.js +9 -0
- package/lib/Types/Message.d.ts +433 -0
- package/lib/Types/Message.js +9 -0
- package/lib/Types/Newsletter.d.ts +92 -0
- package/lib/Types/Newsletter.js +32 -0
- package/lib/Types/Product.d.ts +78 -0
- package/lib/Types/Product.js +2 -0
- package/lib/Types/Signal.d.ts +57 -0
- package/lib/Types/Signal.js +2 -0
- package/lib/Types/Socket.d.ts +114 -0
- package/lib/Types/Socket.js +2 -0
- package/lib/Types/State.d.ts +27 -0
- package/lib/Types/State.js +2 -0
- package/lib/Types/USync.d.ts +25 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/index.d.ts +66 -0
- package/lib/Types/index.js +42 -0
- package/lib/Utils/auth-utils.d.ts +18 -0
- package/lib/Utils/auth-utils.js +206 -0
- package/lib/Utils/baileys-event-stream.d.ts +16 -0
- package/lib/Utils/baileys-event-stream.js +63 -0
- package/lib/Utils/business.d.ts +22 -0
- package/lib/Utils/business.js +234 -0
- package/lib/Utils/chat-utils.d.ts +70 -0
- package/lib/Utils/chat-utils.js +745 -0
- package/lib/Utils/crypto.d.ts +40 -0
- package/lib/Utils/crypto.js +163 -0
- package/lib/Utils/decode-wa-message.d.ts +36 -0
- package/lib/Utils/decode-wa-message.js +226 -0
- package/lib/Utils/event-buffer.d.ts +35 -0
- package/lib/Utils/event-buffer.js +514 -0
- package/lib/Utils/generics.d.ts +88 -0
- package/lib/Utils/generics.js +401 -0
- package/lib/Utils/history.d.ts +19 -0
- package/lib/Utils/history.js +94 -0
- package/lib/Utils/index.d.ts +17 -0
- package/lib/Utils/index.js +33 -0
- package/lib/Utils/link-preview.d.ts +21 -0
- package/lib/Utils/link-preview.js +93 -0
- package/lib/Utils/logger.d.ts +2 -0
- package/lib/Utils/logger.js +7 -0
- package/lib/Utils/lt-hash.d.ts +12 -0
- package/lib/Utils/lt-hash.js +51 -0
- package/lib/Utils/make-mutex.d.ts +7 -0
- package/lib/Utils/make-mutex.js +43 -0
- package/lib/Utils/messages-media.d.ts +113 -0
- package/lib/Utils/messages-media.js +722 -0
- package/lib/Utils/messages.d.ts +77 -0
- package/lib/Utils/messages.js +1217 -0
- package/lib/Utils/noise-handler.d.ts +20 -0
- package/lib/Utils/noise-handler.js +155 -0
- package/lib/Utils/process-message.d.ts +41 -0
- package/lib/Utils/process-message.js +321 -0
- package/lib/Utils/signal.d.ts +33 -0
- package/lib/Utils/signal.js +143 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +12 -0
- package/lib/Utils/use-multi-file-auth-state.js +88 -0
- package/lib/Utils/validate-connection.d.ts +11 -0
- package/lib/Utils/validate-connection.js +205 -0
- package/lib/WABinary/constants.d.ts +27 -0
- package/lib/WABinary/constants.js +40 -0
- package/lib/WABinary/decode.d.ts +6 -0
- package/lib/WABinary/decode.js +262 -0
- package/lib/WABinary/encode.d.ts +2 -0
- package/lib/WABinary/encode.js +244 -0
- package/lib/WABinary/generic-utils.d.ts +14 -0
- package/lib/WABinary/generic-utils.js +110 -0
- package/lib/WABinary/index.d.ts +5 -0
- package/lib/WABinary/index.js +21 -0
- package/lib/WABinary/jid-utils.d.ts +31 -0
- package/lib/WABinary/jid-utils.js +62 -0
- package/lib/WABinary/types.d.ts +18 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WAM/BinaryInfo.d.ts +8 -0
- package/lib/WAM/BinaryInfo.js +13 -0
- package/lib/WAM/constants.d.ts +38 -0
- package/lib/WAM/constants.js +15350 -0
- package/lib/WAM/encode.d.ts +2 -0
- package/lib/WAM/encode.js +155 -0
- package/lib/WAM/index.d.ts +3 -0
- package/lib/WAM/index.js +19 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
- package/lib/WAUSync/Protocols/index.d.ts +4 -0
- package/lib/WAUSync/Protocols/index.js +20 -0
- package/lib/WAUSync/USyncQuery.d.ts +26 -0
- package/lib/WAUSync/USyncQuery.js +79 -0
- package/lib/WAUSync/USyncUser.d.ts +10 -0
- package/lib/WAUSync/USyncUser.js +22 -0
- package/lib/WAUSync/index.d.ts +3 -0
- package/lib/WAUSync/index.js +19 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.js +31 -0
- package/package.json +116 -0
@@ -0,0 +1,722 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
+
}) : function(o, v) {
|
16
|
+
o["default"] = v;
|
17
|
+
});
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
19
|
+
var ownKeys = function(o) {
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
21
|
+
var ar = [];
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
23
|
+
return ar;
|
24
|
+
};
|
25
|
+
return ownKeys(o);
|
26
|
+
};
|
27
|
+
return function (mod) {
|
28
|
+
if (mod && mod.__esModule) return mod;
|
29
|
+
var result = {};
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
31
|
+
__setModuleDefault(result, mod);
|
32
|
+
return result;
|
33
|
+
};
|
34
|
+
})();
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
36
|
+
exports.getStatusCodeForMediaRetry = exports.decryptMediaRetryData = exports.decodeMediaRetryNode = exports.encryptMediaRetryRequest = exports.getWAUploadToServer = exports.downloadEncryptedContent = exports.downloadContentFromMessage = exports.getUrlFromDirectPath = exports.encryptedStream = exports.prepareStream = exports.getHttpStream = exports.getStream = exports.toBuffer = exports.toReadable = exports.mediaMessageSHA256B64 = exports.generateProfilePicture = exports.encodeBase64EncodedStringForUpload = exports.extractImageThumb = exports.hkdfInfoKey = void 0;
|
37
|
+
exports.getMediaKeys = getMediaKeys;
|
38
|
+
exports.getAudioDuration = getAudioDuration;
|
39
|
+
exports.getAudioWaveform = getAudioWaveform;
|
40
|
+
exports.generateThumbnail = generateThumbnail;
|
41
|
+
exports.extensionForMediaMessage = extensionForMediaMessage;
|
42
|
+
const boom_1 = require("@hapi/boom");
|
43
|
+
const child_process_1 = require("child_process");
|
44
|
+
const Crypto = __importStar(require("crypto"));
|
45
|
+
const events_1 = require("events");
|
46
|
+
const fs_1 = require("fs");
|
47
|
+
const os_1 = require("os");
|
48
|
+
const path_1 = require("path");
|
49
|
+
const stream_1 = require("stream");
|
50
|
+
const WAProto_1 = require("../../WAProto");
|
51
|
+
const Defaults_1 = require("../Defaults");
|
52
|
+
const WABinary_1 = require("../WABinary");
|
53
|
+
const crypto_1 = require("./crypto");
|
54
|
+
const generics_1 = require("./generics");
|
55
|
+
const getTmpFilesDirectory = () => (0, os_1.tmpdir)();
|
56
|
+
const getImageProcessingLibrary = async () => {
|
57
|
+
const [_jimp, sharp] = await Promise.all([
|
58
|
+
(async () => {
|
59
|
+
const jimp = await (import('jimp')
|
60
|
+
.catch(() => { }));
|
61
|
+
return jimp;
|
62
|
+
})(),
|
63
|
+
(async () => {
|
64
|
+
const sharp = await (import('sharp')
|
65
|
+
.catch(() => { }));
|
66
|
+
return sharp;
|
67
|
+
})()
|
68
|
+
]);
|
69
|
+
if (sharp) {
|
70
|
+
return { sharp };
|
71
|
+
}
|
72
|
+
const jimp = (_jimp === null || _jimp === void 0 ? void 0 : _jimp.default) || _jimp;
|
73
|
+
if (jimp) {
|
74
|
+
return { jimp };
|
75
|
+
}
|
76
|
+
throw new boom_1.Boom('No image processing library available');
|
77
|
+
};
|
78
|
+
const hkdfInfoKey = (type) => {
|
79
|
+
const hkdfInfo = Defaults_1.MEDIA_HKDF_KEY_MAPPING[type];
|
80
|
+
return `WhatsApp ${hkdfInfo} Keys`;
|
81
|
+
};
|
82
|
+
exports.hkdfInfoKey = hkdfInfoKey;
|
83
|
+
/** generates all the keys required to encrypt/decrypt & sign a media message */
|
84
|
+
function getMediaKeys(buffer, mediaType) {
|
85
|
+
if (!buffer) {
|
86
|
+
throw new boom_1.Boom('Cannot derive from empty media key');
|
87
|
+
}
|
88
|
+
if (typeof buffer === 'string') {
|
89
|
+
buffer = Buffer.from(buffer.replace('data:;base64,', ''), 'base64');
|
90
|
+
}
|
91
|
+
// expand using HKDF to 112 bytes, also pass in the relevant app info
|
92
|
+
const expandedMediaKey = (0, crypto_1.hkdf)(buffer, 112, { info: (0, exports.hkdfInfoKey)(mediaType) });
|
93
|
+
return {
|
94
|
+
iv: expandedMediaKey.slice(0, 16),
|
95
|
+
cipherKey: expandedMediaKey.slice(16, 48),
|
96
|
+
macKey: expandedMediaKey.slice(48, 80),
|
97
|
+
};
|
98
|
+
}
|
99
|
+
/** Extracts video thumb using FFMPEG */
|
100
|
+
const extractVideoThumb = async (path, destPath, time, size) => new Promise((resolve, reject) => {
|
101
|
+
const cmd = `ffmpeg -ss ${time} -i ${path} -y -vf scale=${size.width}:-1 -vframes 1 -f image2 ${destPath}`;
|
102
|
+
(0, child_process_1.exec)(cmd, (err) => {
|
103
|
+
if (err) {
|
104
|
+
reject(err);
|
105
|
+
}
|
106
|
+
else {
|
107
|
+
resolve();
|
108
|
+
}
|
109
|
+
});
|
110
|
+
});
|
111
|
+
const extractImageThumb = async (bufferOrFilePath, width = 32) => {
|
112
|
+
var _a, _b;
|
113
|
+
if (bufferOrFilePath instanceof stream_1.Readable) {
|
114
|
+
bufferOrFilePath = await (0, exports.toBuffer)(bufferOrFilePath);
|
115
|
+
}
|
116
|
+
const lib = await getImageProcessingLibrary();
|
117
|
+
if ('sharp' in lib && typeof ((_a = lib.sharp) === null || _a === void 0 ? void 0 : _a.default) === 'function') {
|
118
|
+
const img = lib.sharp.default(bufferOrFilePath);
|
119
|
+
const dimensions = await img.metadata();
|
120
|
+
const buffer = await img
|
121
|
+
.resize(width)
|
122
|
+
.jpeg({ quality: 50 })
|
123
|
+
.toBuffer();
|
124
|
+
return {
|
125
|
+
buffer,
|
126
|
+
original: {
|
127
|
+
width: dimensions.width,
|
128
|
+
height: dimensions.height,
|
129
|
+
},
|
130
|
+
};
|
131
|
+
}
|
132
|
+
else if ('jimp' in lib && typeof ((_b = lib.jimp) === null || _b === void 0 ? void 0 : _b.read) === 'function') {
|
133
|
+
const { read, MIME_JPEG, RESIZE_BILINEAR, AUTO } = lib.jimp;
|
134
|
+
const jimp = await read(bufferOrFilePath);
|
135
|
+
const dimensions = {
|
136
|
+
width: jimp.getWidth(),
|
137
|
+
height: jimp.getHeight()
|
138
|
+
};
|
139
|
+
const buffer = await jimp
|
140
|
+
.quality(50)
|
141
|
+
.resize(width, AUTO, RESIZE_BILINEAR)
|
142
|
+
.getBufferAsync(MIME_JPEG);
|
143
|
+
return {
|
144
|
+
buffer,
|
145
|
+
original: dimensions
|
146
|
+
};
|
147
|
+
}
|
148
|
+
else {
|
149
|
+
throw new boom_1.Boom('No image processing library available');
|
150
|
+
}
|
151
|
+
};
|
152
|
+
exports.extractImageThumb = extractImageThumb;
|
153
|
+
const encodeBase64EncodedStringForUpload = (b64) => (encodeURIComponent(b64
|
154
|
+
.replace(/\+/g, '-')
|
155
|
+
.replace(/\//g, '_')
|
156
|
+
.replace(/\=+$/, '')));
|
157
|
+
exports.encodeBase64EncodedStringForUpload = encodeBase64EncodedStringForUpload;
|
158
|
+
const generateProfilePicture = async (mediaUpload) => {
|
159
|
+
const bufferOrFilePath = Buffer.isBuffer(mediaUpload)
|
160
|
+
? mediaUpload
|
161
|
+
: typeof mediaUpload === 'object' && 'url' in mediaUpload
|
162
|
+
? mediaUpload.url.toString()
|
163
|
+
: await (0, exports.toBuffer)(mediaUpload.stream);
|
164
|
+
let img;
|
165
|
+
const { read, MIME_JPEG, AUTO } = require('jimp');
|
166
|
+
const jimp = await read(bufferOrFilePath);
|
167
|
+
const min = jimp.getWidth();
|
168
|
+
const max = jimp.getHeight();
|
169
|
+
const cropped = jimp.crop(0, 0, min, max);
|
170
|
+
img = cropped
|
171
|
+
.quality(100)
|
172
|
+
.scaleToFit(720, 720, AUTO)
|
173
|
+
.getBufferAsync(MIME_JPEG);
|
174
|
+
return {
|
175
|
+
img: await img
|
176
|
+
};
|
177
|
+
};
|
178
|
+
exports.generateProfilePicture = generateProfilePicture;
|
179
|
+
/** gets the SHA256 of the given media message */
|
180
|
+
const mediaMessageSHA256B64 = (message) => {
|
181
|
+
const media = Object.values(message)[0];
|
182
|
+
return (media === null || media === void 0 ? void 0 : media.fileSha256) && Buffer.from(media.fileSha256).toString('base64');
|
183
|
+
};
|
184
|
+
exports.mediaMessageSHA256B64 = mediaMessageSHA256B64;
|
185
|
+
async function getAudioDuration(buffer) {
|
186
|
+
const musicMetadata = await import('music-metadata');
|
187
|
+
let metadata;
|
188
|
+
if (Buffer.isBuffer(buffer)) {
|
189
|
+
metadata = await musicMetadata.parseBuffer(buffer, undefined, { duration: true });
|
190
|
+
}
|
191
|
+
else if (typeof buffer === 'string') {
|
192
|
+
const rStream = (0, fs_1.createReadStream)(buffer);
|
193
|
+
try {
|
194
|
+
metadata = await musicMetadata.parseStream(rStream, undefined, { duration: true });
|
195
|
+
}
|
196
|
+
finally {
|
197
|
+
rStream.destroy();
|
198
|
+
}
|
199
|
+
}
|
200
|
+
else {
|
201
|
+
metadata = await musicMetadata.parseStream(buffer, undefined, { duration: true });
|
202
|
+
}
|
203
|
+
return metadata.format.duration;
|
204
|
+
}
|
205
|
+
/**
|
206
|
+
referenced from and modifying https://github.com/wppconnect-team/wa-js/blob/main/src/chat/functions/prepareAudioWaveform.ts
|
207
|
+
*/
|
208
|
+
async function getAudioWaveform(buffer, logger) {
|
209
|
+
try {
|
210
|
+
const audioDecode = (buffer) => import('audio-decode').then(({ default: audioDecode }) => audioDecode(buffer));
|
211
|
+
let audioData;
|
212
|
+
if (Buffer.isBuffer(buffer)) {
|
213
|
+
audioData = buffer;
|
214
|
+
}
|
215
|
+
else if (typeof buffer === 'string') {
|
216
|
+
const rStream = (0, fs_1.createReadStream)(buffer);
|
217
|
+
audioData = await (0, exports.toBuffer)(rStream);
|
218
|
+
}
|
219
|
+
else {
|
220
|
+
audioData = await (0, exports.toBuffer)(buffer);
|
221
|
+
}
|
222
|
+
const audioBuffer = await audioDecode(audioData);
|
223
|
+
const rawData = audioBuffer.getChannelData(0); // We only need to work with one channel of data
|
224
|
+
const samples = 64; // Number of samples we want to have in our final data set
|
225
|
+
const blockSize = Math.floor(rawData.length / samples); // the number of samples in each subdivision
|
226
|
+
const filteredData = [];
|
227
|
+
for (let i = 0; i < samples; i++) {
|
228
|
+
const blockStart = blockSize * i; // the location of the first sample in the block
|
229
|
+
let sum = 0;
|
230
|
+
for (let j = 0; j < blockSize; j++) {
|
231
|
+
sum = sum + Math.abs(rawData[blockStart + j]); // find the sum of all the samples in the block
|
232
|
+
}
|
233
|
+
filteredData.push(sum / blockSize); // divide the sum by the block size to get the average
|
234
|
+
}
|
235
|
+
// This guarantees that the largest data point will be set to 1, and the rest of the data will scale proportionally.
|
236
|
+
const multiplier = Math.pow(Math.max(...filteredData), -1);
|
237
|
+
const normalizedData = filteredData.map((n) => n * multiplier);
|
238
|
+
// Generate waveform like WhatsApp
|
239
|
+
const waveform = new Uint8Array(normalizedData.map((n) => Math.floor(100 * n)));
|
240
|
+
return waveform;
|
241
|
+
}
|
242
|
+
catch (e) {
|
243
|
+
logger === null || logger === void 0 ? void 0 : logger.debug('Failed to generate waveform: ' + e);
|
244
|
+
}
|
245
|
+
}
|
246
|
+
const toReadable = (buffer) => {
|
247
|
+
const readable = new stream_1.Readable({ read: () => { } });
|
248
|
+
readable.push(buffer);
|
249
|
+
readable.push(null);
|
250
|
+
return readable;
|
251
|
+
};
|
252
|
+
exports.toReadable = toReadable;
|
253
|
+
const toBuffer = async (stream) => {
|
254
|
+
const chunks = [];
|
255
|
+
for await (const chunk of stream) {
|
256
|
+
chunks.push(chunk);
|
257
|
+
}
|
258
|
+
stream.destroy();
|
259
|
+
return Buffer.concat(chunks);
|
260
|
+
};
|
261
|
+
exports.toBuffer = toBuffer;
|
262
|
+
const getStream = async (item, opts) => {
|
263
|
+
if (Buffer.isBuffer(item)) {
|
264
|
+
return { stream: (0, exports.toReadable)(item), type: 'buffer' };
|
265
|
+
}
|
266
|
+
if ('stream' in item) {
|
267
|
+
return { stream: item.stream, type: 'readable' };
|
268
|
+
}
|
269
|
+
if (item.url.toString().startsWith('http://') || item.url.toString().startsWith('https://')) {
|
270
|
+
return { stream: await (0, exports.getHttpStream)(item.url, opts), type: 'remote' };
|
271
|
+
}
|
272
|
+
return { stream: (0, fs_1.createReadStream)(item.url), type: 'file' };
|
273
|
+
};
|
274
|
+
exports.getStream = getStream;
|
275
|
+
/** generates a thumbnail for a given media, if required */
|
276
|
+
async function generateThumbnail(file, mediaType, options) {
|
277
|
+
var _a;
|
278
|
+
let thumbnail;
|
279
|
+
let originalImageDimensions;
|
280
|
+
if (mediaType === 'image') {
|
281
|
+
const { buffer, original } = await (0, exports.extractImageThumb)(file);
|
282
|
+
thumbnail = buffer.toString('base64');
|
283
|
+
if (original.width && original.height) {
|
284
|
+
originalImageDimensions = {
|
285
|
+
width: original.width,
|
286
|
+
height: original.height,
|
287
|
+
};
|
288
|
+
}
|
289
|
+
}
|
290
|
+
else if (mediaType === 'video') {
|
291
|
+
const imgFilename = (0, path_1.join)(getTmpFilesDirectory(), (0, generics_1.generateMessageID)() + '.jpg');
|
292
|
+
try {
|
293
|
+
await extractVideoThumb(file, imgFilename, '00:00:00', { width: 32, height: 32 });
|
294
|
+
const buff = await fs_1.promises.readFile(imgFilename);
|
295
|
+
thumbnail = buff.toString('base64');
|
296
|
+
await fs_1.promises.unlink(imgFilename);
|
297
|
+
}
|
298
|
+
catch (err) {
|
299
|
+
(_a = options.logger) === null || _a === void 0 ? void 0 : _a.debug('could not generate video thumb: ' + err);
|
300
|
+
}
|
301
|
+
}
|
302
|
+
return {
|
303
|
+
thumbnail,
|
304
|
+
originalImageDimensions
|
305
|
+
};
|
306
|
+
}
|
307
|
+
const getHttpStream = async (url, options = {}) => {
|
308
|
+
const { default: axios } = await import('axios');
|
309
|
+
const fetched = await axios.get(url.toString(), { ...options, responseType: 'stream' });
|
310
|
+
return fetched.data;
|
311
|
+
};
|
312
|
+
exports.getHttpStream = getHttpStream;
|
313
|
+
const prepareStream = async (media, mediaType, { logger, saveOriginalFileIfRequired, opts } = {}) => {
|
314
|
+
const { stream, type } = await (0, exports.getStream)(media, opts);
|
315
|
+
logger === null || logger === void 0 ? void 0 : logger.debug('fetched media stream');
|
316
|
+
let bodyPath;
|
317
|
+
let didSaveToTmpPath = false;
|
318
|
+
try {
|
319
|
+
const buffer = await (0, exports.toBuffer)(stream);
|
320
|
+
if (type === 'file') {
|
321
|
+
bodyPath = media.url;
|
322
|
+
}
|
323
|
+
else if (saveOriginalFileIfRequired) {
|
324
|
+
bodyPath = (0, path_1.join)(getTmpFilesDirectory(), mediaType + (0, generics_1.generateMessageID)());
|
325
|
+
(0, fs_1.writeFileSync)(bodyPath, buffer);
|
326
|
+
didSaveToTmpPath = true;
|
327
|
+
}
|
328
|
+
const fileLength = buffer.length;
|
329
|
+
const fileSha256 = Crypto.createHash('sha256').update(buffer).digest();
|
330
|
+
stream === null || stream === void 0 ? void 0 : stream.destroy();
|
331
|
+
logger === null || logger === void 0 ? void 0 : logger.debug('prepare stream data successfully');
|
332
|
+
return {
|
333
|
+
mediaKey: undefined,
|
334
|
+
encWriteStream: buffer,
|
335
|
+
fileLength,
|
336
|
+
fileSha256,
|
337
|
+
fileEncSha256: undefined,
|
338
|
+
bodyPath,
|
339
|
+
didSaveToTmpPath
|
340
|
+
};
|
341
|
+
}
|
342
|
+
catch (error) {
|
343
|
+
// destroy all streams with error
|
344
|
+
stream.destroy();
|
345
|
+
if (didSaveToTmpPath) {
|
346
|
+
try {
|
347
|
+
await fs_1.promises.unlink(bodyPath);
|
348
|
+
}
|
349
|
+
catch (err) {
|
350
|
+
logger === null || logger === void 0 ? void 0 : logger.error({ err }, 'failed to save to tmp path');
|
351
|
+
}
|
352
|
+
}
|
353
|
+
throw error;
|
354
|
+
}
|
355
|
+
};
|
356
|
+
exports.prepareStream = prepareStream;
|
357
|
+
const encryptedStream = async (media, mediaType, { logger, saveOriginalFileIfRequired, opts } = {}) => {
|
358
|
+
const { stream, type } = await (0, exports.getStream)(media, opts);
|
359
|
+
logger === null || logger === void 0 ? void 0 : logger.debug('fetched media stream');
|
360
|
+
const mediaKey = Crypto.randomBytes(32);
|
361
|
+
const { cipherKey, iv, macKey } = getMediaKeys(mediaKey, mediaType);
|
362
|
+
const encWriteStream = new stream_1.Readable({ read: () => { } });
|
363
|
+
let bodyPath;
|
364
|
+
let writeStream;
|
365
|
+
let didSaveToTmpPath = false;
|
366
|
+
if (type === 'file') {
|
367
|
+
bodyPath = media.url;
|
368
|
+
}
|
369
|
+
else if (saveOriginalFileIfRequired) {
|
370
|
+
bodyPath = (0, path_1.join)(getTmpFilesDirectory(), mediaType + (0, generics_1.generateMessageID)());
|
371
|
+
writeStream = (0, fs_1.createWriteStream)(bodyPath);
|
372
|
+
didSaveToTmpPath = true;
|
373
|
+
}
|
374
|
+
let fileLength = 0;
|
375
|
+
const aes = Crypto.createCipheriv('aes-256-cbc', cipherKey, iv);
|
376
|
+
let hmac = Crypto.createHmac('sha256', macKey).update(iv);
|
377
|
+
let sha256Plain = Crypto.createHash('sha256');
|
378
|
+
let sha256Enc = Crypto.createHash('sha256');
|
379
|
+
try {
|
380
|
+
for await (const data of stream) {
|
381
|
+
fileLength += data.length;
|
382
|
+
if (type === 'remote'
|
383
|
+
&& (opts === null || opts === void 0 ? void 0 : opts.maxContentLength)
|
384
|
+
&& fileLength + data.length > opts.maxContentLength) {
|
385
|
+
throw new boom_1.Boom(`content length exceeded when encrypting "${type}"`, {
|
386
|
+
data: { media, type }
|
387
|
+
});
|
388
|
+
}
|
389
|
+
sha256Plain = sha256Plain.update(data);
|
390
|
+
if (writeStream) {
|
391
|
+
if (!writeStream.write(data)) {
|
392
|
+
await (0, events_1.once)(writeStream, 'drain');
|
393
|
+
}
|
394
|
+
}
|
395
|
+
onChunk(aes.update(data));
|
396
|
+
}
|
397
|
+
onChunk(aes.final());
|
398
|
+
const mac = hmac.digest().slice(0, 10);
|
399
|
+
sha256Enc = sha256Enc.update(mac);
|
400
|
+
const fileSha256 = sha256Plain.digest();
|
401
|
+
const fileEncSha256 = sha256Enc.digest();
|
402
|
+
encWriteStream.push(mac);
|
403
|
+
encWriteStream.push(null);
|
404
|
+
writeStream === null || writeStream === void 0 ? void 0 : writeStream.end();
|
405
|
+
stream.destroy();
|
406
|
+
logger === null || logger === void 0 ? void 0 : logger.debug('encrypted data successfully');
|
407
|
+
return {
|
408
|
+
mediaKey,
|
409
|
+
encWriteStream,
|
410
|
+
bodyPath,
|
411
|
+
mac,
|
412
|
+
fileEncSha256,
|
413
|
+
fileSha256,
|
414
|
+
fileLength,
|
415
|
+
didSaveToTmpPath
|
416
|
+
};
|
417
|
+
}
|
418
|
+
catch (error) {
|
419
|
+
// destroy all streams with error
|
420
|
+
encWriteStream.destroy();
|
421
|
+
writeStream === null || writeStream === void 0 ? void 0 : writeStream.destroy();
|
422
|
+
aes.destroy();
|
423
|
+
hmac.destroy();
|
424
|
+
sha256Plain.destroy();
|
425
|
+
sha256Enc.destroy();
|
426
|
+
stream.destroy();
|
427
|
+
if (didSaveToTmpPath) {
|
428
|
+
try {
|
429
|
+
await fs_1.promises.unlink(bodyPath);
|
430
|
+
}
|
431
|
+
catch (err) {
|
432
|
+
logger === null || logger === void 0 ? void 0 : logger.error({ err }, 'failed to save to tmp path');
|
433
|
+
}
|
434
|
+
}
|
435
|
+
throw error;
|
436
|
+
}
|
437
|
+
function onChunk(buff) {
|
438
|
+
sha256Enc = sha256Enc.update(buff);
|
439
|
+
hmac = hmac.update(buff);
|
440
|
+
encWriteStream.push(buff);
|
441
|
+
}
|
442
|
+
};
|
443
|
+
exports.encryptedStream = encryptedStream;
|
444
|
+
const DEF_HOST = 'mmg.whatsapp.net';
|
445
|
+
const AES_CHUNK_SIZE = 16;
|
446
|
+
const toSmallestChunkSize = (num) => {
|
447
|
+
return Math.floor(num / AES_CHUNK_SIZE) * AES_CHUNK_SIZE;
|
448
|
+
};
|
449
|
+
const getUrlFromDirectPath = (directPath) => `https://${DEF_HOST}${directPath}`;
|
450
|
+
exports.getUrlFromDirectPath = getUrlFromDirectPath;
|
451
|
+
const downloadContentFromMessage = ({ mediaKey, directPath, url }, type, opts = {}) => {
|
452
|
+
const downloadUrl = url || (0, exports.getUrlFromDirectPath)(directPath);
|
453
|
+
const keys = getMediaKeys(mediaKey, type);
|
454
|
+
return (0, exports.downloadEncryptedContent)(downloadUrl, keys, opts);
|
455
|
+
};
|
456
|
+
exports.downloadContentFromMessage = downloadContentFromMessage;
|
457
|
+
/**
|
458
|
+
* Decrypts and downloads an AES256-CBC encrypted file given the keys.
|
459
|
+
* Assumes the SHA256 of the plaintext is appended to the end of the ciphertext
|
460
|
+
* */
|
461
|
+
const downloadEncryptedContent = async (downloadUrl, { cipherKey, iv }, { startByte, endByte, options } = {}) => {
|
462
|
+
let bytesFetched = 0;
|
463
|
+
let startChunk = 0;
|
464
|
+
let firstBlockIsIV = false;
|
465
|
+
// if a start byte is specified -- then we need to fetch the previous chunk as that will form the IV
|
466
|
+
if (startByte) {
|
467
|
+
const chunk = toSmallestChunkSize(startByte || 0);
|
468
|
+
if (chunk) {
|
469
|
+
startChunk = chunk - AES_CHUNK_SIZE;
|
470
|
+
bytesFetched = chunk;
|
471
|
+
firstBlockIsIV = true;
|
472
|
+
}
|
473
|
+
}
|
474
|
+
const endChunk = endByte ? toSmallestChunkSize(endByte || 0) + AES_CHUNK_SIZE : undefined;
|
475
|
+
const headers = {
|
476
|
+
...(options === null || options === void 0 ? void 0 : options.headers) || {},
|
477
|
+
Origin: Defaults_1.DEFAULT_ORIGIN,
|
478
|
+
};
|
479
|
+
if (startChunk || endChunk) {
|
480
|
+
headers.Range = `bytes=${startChunk}-`;
|
481
|
+
if (endChunk) {
|
482
|
+
headers.Range += endChunk;
|
483
|
+
}
|
484
|
+
}
|
485
|
+
// download the message
|
486
|
+
const fetched = await (0, exports.getHttpStream)(downloadUrl, {
|
487
|
+
...options || {},
|
488
|
+
headers,
|
489
|
+
maxBodyLength: Infinity,
|
490
|
+
maxContentLength: Infinity,
|
491
|
+
});
|
492
|
+
let remainingBytes = Buffer.from([]);
|
493
|
+
let aes;
|
494
|
+
const pushBytes = (bytes, push) => {
|
495
|
+
if (startByte || endByte) {
|
496
|
+
const start = bytesFetched >= startByte ? undefined : Math.max(startByte - bytesFetched, 0);
|
497
|
+
const end = bytesFetched + bytes.length < endByte ? undefined : Math.max(endByte - bytesFetched, 0);
|
498
|
+
push(bytes.slice(start, end));
|
499
|
+
bytesFetched += bytes.length;
|
500
|
+
}
|
501
|
+
else {
|
502
|
+
push(bytes);
|
503
|
+
}
|
504
|
+
};
|
505
|
+
const output = new stream_1.Transform({
|
506
|
+
transform(chunk, _, callback) {
|
507
|
+
let data = Buffer.concat([remainingBytes, chunk]);
|
508
|
+
const decryptLength = toSmallestChunkSize(data.length);
|
509
|
+
remainingBytes = data.slice(decryptLength);
|
510
|
+
data = data.slice(0, decryptLength);
|
511
|
+
if (!aes) {
|
512
|
+
let ivValue = iv;
|
513
|
+
if (firstBlockIsIV) {
|
514
|
+
ivValue = data.slice(0, AES_CHUNK_SIZE);
|
515
|
+
data = data.slice(AES_CHUNK_SIZE);
|
516
|
+
}
|
517
|
+
aes = Crypto.createDecipheriv('aes-256-cbc', cipherKey, ivValue);
|
518
|
+
// if an end byte that is not EOF is specified
|
519
|
+
// stop auto padding (PKCS7) -- otherwise throws an error for decryption
|
520
|
+
if (endByte) {
|
521
|
+
aes.setAutoPadding(false);
|
522
|
+
}
|
523
|
+
}
|
524
|
+
try {
|
525
|
+
pushBytes(aes.update(data), b => this.push(b));
|
526
|
+
callback();
|
527
|
+
}
|
528
|
+
catch (error) {
|
529
|
+
callback(error);
|
530
|
+
}
|
531
|
+
},
|
532
|
+
final(callback) {
|
533
|
+
try {
|
534
|
+
pushBytes(aes.final(), b => this.push(b));
|
535
|
+
callback();
|
536
|
+
}
|
537
|
+
catch (error) {
|
538
|
+
callback(error);
|
539
|
+
}
|
540
|
+
},
|
541
|
+
});
|
542
|
+
return fetched.pipe(output, { end: true });
|
543
|
+
};
|
544
|
+
exports.downloadEncryptedContent = downloadEncryptedContent;
|
545
|
+
function extensionForMediaMessage(message) {
|
546
|
+
const getExtension = (mimetype) => mimetype.split(';')[0].split('/')[1];
|
547
|
+
const type = Object.keys(message)[0];
|
548
|
+
let extension;
|
549
|
+
if (type === 'locationMessage' ||
|
550
|
+
type === 'liveLocationMessage' ||
|
551
|
+
type === 'productMessage') {
|
552
|
+
extension = '.jpeg';
|
553
|
+
}
|
554
|
+
else {
|
555
|
+
const messageContent = message[type];
|
556
|
+
extension = getExtension(messageContent.mimetype);
|
557
|
+
}
|
558
|
+
return extension;
|
559
|
+
}
|
560
|
+
const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, options }, refreshMediaConn) => {
|
561
|
+
return async (stream, { mediaType, fileEncSha256B64, newsletter, timeoutMs }) => {
|
562
|
+
var _a, _b;
|
563
|
+
const { default: axios } = await import('axios');
|
564
|
+
// send a query JSON to obtain the url & auth token to upload our media
|
565
|
+
let uploadInfo = await refreshMediaConn(false);
|
566
|
+
let urls;
|
567
|
+
const hosts = [...customUploadHosts, ...uploadInfo.hosts];
|
568
|
+
const chunks = [];
|
569
|
+
if (!Buffer.isBuffer(stream)) {
|
570
|
+
for await (const chunk of stream) {
|
571
|
+
chunks.push(chunk);
|
572
|
+
}
|
573
|
+
}
|
574
|
+
const reqBody = Buffer.isBuffer(stream) ? stream : Buffer.concat(chunks);
|
575
|
+
fileEncSha256B64 = (0, exports.encodeBase64EncodedStringForUpload)(fileEncSha256B64);
|
576
|
+
let media = Defaults_1.MEDIA_PATH_MAP[mediaType];
|
577
|
+
if (newsletter) {
|
578
|
+
media = media === null || media === void 0 ? void 0 : media.replace('/mms/', '/newsletter/newsletter-');
|
579
|
+
}
|
580
|
+
for (const { hostname, maxContentLengthBytes } of hosts) {
|
581
|
+
logger.debug(`uploading to "${hostname}"`);
|
582
|
+
const auth = encodeURIComponent(uploadInfo.auth); // the auth token
|
583
|
+
const url = `https://${hostname}${media}/${fileEncSha256B64}?auth=${auth}&token=${fileEncSha256B64}`;
|
584
|
+
let result;
|
585
|
+
try {
|
586
|
+
if (maxContentLengthBytes && reqBody.length > maxContentLengthBytes) {
|
587
|
+
throw new boom_1.Boom(`Body too large for "${hostname}"`, { statusCode: 413 });
|
588
|
+
}
|
589
|
+
const body = await axios.post(url, reqBody, {
|
590
|
+
...options,
|
591
|
+
headers: {
|
592
|
+
...options.headers || {},
|
593
|
+
'Content-Type': 'application/octet-stream',
|
594
|
+
'Origin': Defaults_1.DEFAULT_ORIGIN
|
595
|
+
},
|
596
|
+
httpsAgent: fetchAgent,
|
597
|
+
timeout: timeoutMs,
|
598
|
+
responseType: 'json',
|
599
|
+
maxBodyLength: Infinity,
|
600
|
+
maxContentLength: Infinity,
|
601
|
+
});
|
602
|
+
result = body.data;
|
603
|
+
if ((result === null || result === void 0 ? void 0 : result.url) || (result === null || result === void 0 ? void 0 : result.directPath)) {
|
604
|
+
urls = {
|
605
|
+
mediaUrl: result.url,
|
606
|
+
directPath: result.direct_path,
|
607
|
+
handle: result.handle
|
608
|
+
};
|
609
|
+
break;
|
610
|
+
}
|
611
|
+
else {
|
612
|
+
uploadInfo = await refreshMediaConn(true);
|
613
|
+
throw new Error(`upload failed, reason: ${JSON.stringify(result)}`);
|
614
|
+
}
|
615
|
+
}
|
616
|
+
catch (error) {
|
617
|
+
if (axios.isAxiosError(error)) {
|
618
|
+
result = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data;
|
619
|
+
}
|
620
|
+
const isLast = hostname === ((_b = hosts[uploadInfo.hosts.length - 1]) === null || _b === void 0 ? void 0 : _b.hostname);
|
621
|
+
logger.warn({ trace: error.stack, uploadResult: result }, `Error in uploading to ${hostname} ${isLast ? '' : ', retrying...'}`);
|
622
|
+
}
|
623
|
+
}
|
624
|
+
if (!urls) {
|
625
|
+
throw new boom_1.Boom('Media upload failed on all hosts', { statusCode: 500 });
|
626
|
+
}
|
627
|
+
return urls;
|
628
|
+
};
|
629
|
+
};
|
630
|
+
exports.getWAUploadToServer = getWAUploadToServer;
|
631
|
+
const getMediaRetryKey = (mediaKey) => {
|
632
|
+
return (0, crypto_1.hkdf)(mediaKey, 32, { info: 'WhatsApp Media Retry Notification' });
|
633
|
+
};
|
634
|
+
/**
|
635
|
+
* Generate a binary node that will request the phone to re-upload the media & return the newly uploaded URL
|
636
|
+
*/
|
637
|
+
const encryptMediaRetryRequest = (key, mediaKey, meId) => {
|
638
|
+
const recp = { stanzaId: key.id };
|
639
|
+
const recpBuffer = WAProto_1.proto.ServerErrorReceipt.encode(recp).finish();
|
640
|
+
const iv = Crypto.randomBytes(12);
|
641
|
+
const retryKey = getMediaRetryKey(mediaKey);
|
642
|
+
const ciphertext = (0, crypto_1.aesEncryptGCM)(recpBuffer, retryKey, iv, Buffer.from(key.id));
|
643
|
+
const req = {
|
644
|
+
tag: 'receipt',
|
645
|
+
attrs: {
|
646
|
+
id: key.id,
|
647
|
+
to: (0, WABinary_1.jidNormalizedUser)(meId),
|
648
|
+
type: 'server-error'
|
649
|
+
},
|
650
|
+
content: [
|
651
|
+
// this encrypt node is actually pretty useless
|
652
|
+
// the media is returned even without this node
|
653
|
+
// keeping it here to maintain parity with WA Web
|
654
|
+
{
|
655
|
+
tag: 'encrypt',
|
656
|
+
attrs: {},
|
657
|
+
content: [
|
658
|
+
{ tag: 'enc_p', attrs: {}, content: ciphertext },
|
659
|
+
{ tag: 'enc_iv', attrs: {}, content: iv }
|
660
|
+
]
|
661
|
+
},
|
662
|
+
{
|
663
|
+
tag: 'rmr',
|
664
|
+
attrs: {
|
665
|
+
jid: key.remoteJid,
|
666
|
+
'from_me': (!!key.fromMe).toString(),
|
667
|
+
// @ts-ignore
|
668
|
+
participant: key.participant || undefined
|
669
|
+
}
|
670
|
+
}
|
671
|
+
]
|
672
|
+
};
|
673
|
+
return req;
|
674
|
+
};
|
675
|
+
exports.encryptMediaRetryRequest = encryptMediaRetryRequest;
|
676
|
+
const decodeMediaRetryNode = (node) => {
|
677
|
+
const rmrNode = (0, WABinary_1.getBinaryNodeChild)(node, 'rmr');
|
678
|
+
const event = {
|
679
|
+
key: {
|
680
|
+
id: node.attrs.id,
|
681
|
+
remoteJid: rmrNode.attrs.jid,
|
682
|
+
fromMe: rmrNode.attrs.from_me === 'true',
|
683
|
+
participant: rmrNode.attrs.participant
|
684
|
+
}
|
685
|
+
};
|
686
|
+
const errorNode = (0, WABinary_1.getBinaryNodeChild)(node, 'error');
|
687
|
+
if (errorNode) {
|
688
|
+
const errorCode = +errorNode.attrs.code;
|
689
|
+
event.error = new boom_1.Boom(`Failed to re-upload media (${errorCode})`, { data: errorNode.attrs, statusCode: (0, exports.getStatusCodeForMediaRetry)(errorCode) });
|
690
|
+
}
|
691
|
+
else {
|
692
|
+
const encryptedInfoNode = (0, WABinary_1.getBinaryNodeChild)(node, 'encrypt');
|
693
|
+
const ciphertext = (0, WABinary_1.getBinaryNodeChildBuffer)(encryptedInfoNode, 'enc_p');
|
694
|
+
const iv = (0, WABinary_1.getBinaryNodeChildBuffer)(encryptedInfoNode, 'enc_iv');
|
695
|
+
if (ciphertext && iv) {
|
696
|
+
event.media = { ciphertext, iv };
|
697
|
+
}
|
698
|
+
else {
|
699
|
+
event.error = new boom_1.Boom('Failed to re-upload media (missing ciphertext)', { statusCode: 404 });
|
700
|
+
}
|
701
|
+
}
|
702
|
+
return event;
|
703
|
+
};
|
704
|
+
exports.decodeMediaRetryNode = decodeMediaRetryNode;
|
705
|
+
const decryptMediaRetryData = ({ ciphertext, iv }, mediaKey, msgId) => {
|
706
|
+
const retryKey = getMediaRetryKey(mediaKey);
|
707
|
+
const plaintext = (0, crypto_1.aesDecryptGCM)(ciphertext, retryKey, iv, Buffer.from(msgId));
|
708
|
+
return WAProto_1.proto.MediaRetryNotification.decode(plaintext);
|
709
|
+
};
|
710
|
+
exports.decryptMediaRetryData = decryptMediaRetryData;
|
711
|
+
const getStatusCodeForMediaRetry = (code) => MEDIA_RETRY_STATUS_MAP[code];
|
712
|
+
exports.getStatusCodeForMediaRetry = getStatusCodeForMediaRetry;
|
713
|
+
const MEDIA_RETRY_STATUS_MAP = {
|
714
|
+
[WAProto_1.proto.MediaRetryNotification.ResultType.SUCCESS]: 200,
|
715
|
+
[WAProto_1.proto.MediaRetryNotification.ResultType.DECRYPTION_ERROR]: 412,
|
716
|
+
[WAProto_1.proto.MediaRetryNotification.ResultType.NOT_FOUND]: 404,
|
717
|
+
[WAProto_1.proto.MediaRetryNotification.ResultType.GENERAL_ERROR]: 418,
|
718
|
+
};
|
719
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
720
|
+
function __importStar(arg0) {
|
721
|
+
throw new Error('Function not implemented.');
|
722
|
+
}
|