gifted-baileys 1.5.5 → 1.5.7
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/README.md +6 -1642
- package/WAProto/WAProto.proto +969 -88
- package/WAProto/index.d.ts +13199 -1260
- package/WAProto/index.js +124901 -74525
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/index.d.ts +284 -0
- package/{src → lib}/Defaults/index.js +7 -14
- 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/index.d.ts +2 -0
- package/{src → lib}/Socket/Client/index.js +2 -3
- 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/{src → lib}/Socket/business.js +28 -33
- package/lib/Socket/chats.d.ts +81 -0
- package/{src → lib}/Socket/chats.js +174 -176
- package/lib/Socket/groups.d.ts +115 -0
- package/{src → lib}/Socket/groups.js +80 -68
- package/lib/Socket/index.d.ts +172 -0
- package/{src → lib}/Socket/index.js +4 -1
- package/lib/Socket/messages-recv.d.ts +158 -0
- package/{src → lib}/Socket/messages-recv.js +378 -211
- package/lib/Socket/messages-send.d.ts +155 -0
- package/{src → lib}/Socket/messages-send.js +452 -177
- package/lib/Socket/newsletter.d.ts +132 -0
- package/{src → lib}/Socket/newsletter.js +107 -98
- package/lib/Socket/registration.d.ts +264 -0
- package/{src → lib}/Socket/registration.js +56 -48
- package/lib/Socket/socket.d.ts +44 -0
- package/{src → lib}/Socket/socket.js +77 -77
- 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/make-cache-manager-store.d.ts +14 -0
- package/{src → lib}/Store/make-cache-manager-store.js +25 -34
- package/lib/Store/make-in-memory-store.d.ts +118 -0
- package/{src → lib}/Store/make-in-memory-store.js +36 -32
- package/lib/Store/make-ordered-dictionary.d.ts +13 -0
- package/lib/Store/object-repository.d.ts +10 -0
- package/{src → lib}/Store/object-repository.js +1 -1
- package/lib/Types/Auth.d.ts +109 -0
- package/lib/Types/Call.d.ts +13 -0
- package/lib/Types/Chat.d.ts +107 -0
- package/{src/Types/Contact.ts → lib/Types/Contact.d.ts} +8 -9
- package/lib/Types/Events.d.ts +172 -0
- package/lib/Types/GroupMetadata.d.ts +56 -0
- package/lib/Types/Label.d.ts +46 -0
- package/{src/Types/LabelAssociation.ts → lib/Types/LabelAssociation.d.ts} +16 -22
- package/lib/Types/Message.d.ts +433 -0
- package/lib/Types/Newsletter.d.ts +92 -0
- package/lib/Types/Product.d.ts +78 -0
- package/lib/Types/Signal.d.ts +57 -0
- package/{src/Types/Socket.ts → lib/Types/Socket.d.ts} +61 -68
- package/lib/Types/State.d.ts +27 -0
- package/lib/Types/USync.d.ts +25 -0
- package/lib/Types/index.d.ts +66 -0
- package/lib/Utils/auth-utils.d.ts +18 -0
- package/{src → lib}/Utils/auth-utils.js +73 -90
- 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/{src → lib}/Utils/business.js +15 -43
- package/lib/Utils/chat-utils.d.ts +70 -0
- package/{src → lib}/Utils/chat-utils.js +87 -94
- package/lib/Utils/crypto.d.ts +40 -0
- package/{src → lib}/Utils/crypto.js +4 -2
- 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/{src → lib}/Utils/event-buffer.js +4 -13
- package/lib/Utils/generics.d.ts +88 -0
- package/{src → lib}/Utils/generics.js +67 -86
- package/lib/Utils/history.d.ts +19 -0
- package/{src → lib}/Utils/history.js +13 -39
- package/lib/Utils/index.d.ts +17 -0
- package/lib/Utils/link-preview.d.ts +21 -0
- package/{src → lib}/Utils/link-preview.js +17 -54
- package/lib/Utils/logger.d.ts +2 -0
- package/lib/Utils/lt-hash.d.ts +12 -0
- package/lib/Utils/make-mutex.d.ts +7 -0
- package/{src → lib}/Utils/make-mutex.js +4 -13
- package/lib/Utils/messages-media.d.ts +113 -0
- package/{src → lib}/Utils/messages-media.js +193 -255
- package/lib/Utils/messages.d.ts +77 -0
- package/{src → lib}/Utils/messages.js +588 -118
- package/lib/Utils/noise-handler.d.ts +20 -0
- package/lib/Utils/process-message.d.ts +41 -0
- package/{src → lib}/Utils/process-message.js +27 -30
- package/lib/Utils/signal.d.ts +33 -0
- package/{src → lib}/Utils/signal.js +25 -42
- package/lib/Utils/use-multi-file-auth-state.d.ts +12 -0
- package/{src → lib}/Utils/use-multi-file-auth-state.js +27 -28
- package/lib/Utils/validate-connection.d.ts +11 -0
- package/{src → lib}/Utils/validate-connection.js +40 -9
- package/lib/WABinary/constants.d.ts +27 -0
- package/lib/WABinary/decode.d.ts +6 -0
- package/lib/WABinary/encode.d.ts +2 -0
- package/{src → lib}/WABinary/encode.js +16 -10
- package/lib/WABinary/generic-utils.d.ts +14 -0
- package/lib/WABinary/index.d.ts +5 -0
- package/lib/WABinary/jid-utils.d.ts +31 -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/constants.d.ts +38 -0
- package/lib/WAM/encode.d.ts +2 -0
- package/lib/WAM/index.d.ts +3 -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/{src → lib}/index.js +1 -0
- package/package.json +26 -8
- package/LICENSE +0 -21
- package/src/Defaults/baileys-version.json +0 -3
- package/src/Defaults/index.ts +0 -131
- package/src/Signal/libsignal.js +0 -180
- package/src/Signal/libsignal.ts +0 -141
- package/src/Socket/Client/abstract-socket-client.ts +0 -19
- package/src/Socket/Client/index.ts +0 -3
- package/src/Socket/Client/mobile-socket-client.js +0 -78
- package/src/Socket/Client/mobile-socket-client.ts +0 -66
- package/src/Socket/Client/web-socket-client.js +0 -75
- package/src/Socket/Client/web-socket-client.ts +0 -57
- package/src/Socket/business.ts +0 -281
- package/src/Socket/chats.ts +0 -1030
- package/src/Socket/groups.ts +0 -356
- package/src/Socket/index.ts +0 -13
- package/src/Socket/messages-recv.ts +0 -985
- package/src/Socket/messages-send.ts +0 -871
- package/src/Socket/newsletter.ts +0 -282
- package/src/Socket/registration.ts +0 -250
- package/src/Socket/socket.ts +0 -777
- package/src/Store/index.ts +0 -3
- package/src/Store/make-cache-manager-store.ts +0 -100
- package/src/Store/make-in-memory-store.ts +0 -475
- package/src/Store/make-ordered-dictionary.ts +0 -86
- package/src/Store/object-repository.ts +0 -32
- package/src/Tests/test.app-state-sync.js +0 -204
- package/src/Tests/test.app-state-sync.ts +0 -207
- package/src/Tests/test.event-buffer.js +0 -270
- package/src/Tests/test.event-buffer.ts +0 -319
- package/src/Tests/test.key-store.js +0 -76
- package/src/Tests/test.key-store.ts +0 -92
- package/src/Tests/test.libsignal.js +0 -141
- package/src/Tests/test.libsignal.ts +0 -186
- package/src/Tests/test.media-download.js +0 -93
- package/src/Tests/test.media-download.ts +0 -76
- package/src/Tests/test.messages.js +0 -33
- package/src/Tests/test.messages.ts +0 -37
- package/src/Tests/utils.js +0 -34
- package/src/Tests/utils.ts +0 -36
- package/src/Types/Auth.ts +0 -113
- package/src/Types/Call.ts +0 -15
- package/src/Types/Chat.ts +0 -106
- package/src/Types/Events.ts +0 -93
- package/src/Types/GroupMetadata.ts +0 -53
- package/src/Types/Label.ts +0 -36
- package/src/Types/Message.ts +0 -288
- package/src/Types/Newsletter.ts +0 -98
- package/src/Types/Product.ts +0 -85
- package/src/Types/Signal.ts +0 -68
- package/src/Types/State.ts +0 -29
- package/src/Types/index.ts +0 -59
- package/src/Utils/auth-utils.ts +0 -222
- package/src/Utils/baileys-event-stream.js +0 -92
- package/src/Utils/baileys-event-stream.ts +0 -66
- package/src/Utils/business.ts +0 -275
- package/src/Utils/chat-utils.ts +0 -860
- package/src/Utils/crypto.ts +0 -131
- package/src/Utils/decode-wa-message.js +0 -211
- package/src/Utils/decode-wa-message.ts +0 -228
- package/src/Utils/event-buffer.ts +0 -613
- package/src/Utils/generics.ts +0 -434
- package/src/Utils/history.ts +0 -112
- package/src/Utils/index.ts +0 -17
- package/src/Utils/link-preview.ts +0 -122
- package/src/Utils/logger.ts +0 -3
- package/src/Utils/lt-hash.ts +0 -61
- package/src/Utils/make-mutex.ts +0 -44
- package/src/Utils/messages-media.ts +0 -847
- package/src/Utils/messages.ts +0 -956
- package/src/Utils/noise-handler.ts +0 -197
- package/src/Utils/process-message.ts +0 -414
- package/src/Utils/signal.ts +0 -177
- package/src/Utils/use-multi-file-auth-state.ts +0 -90
- package/src/Utils/validate-connection.ts +0 -238
- package/src/WABinary/constants.ts +0 -42
- package/src/WABinary/decode.ts +0 -265
- package/src/WABinary/encode.ts +0 -236
- package/src/WABinary/generic-utils.ts +0 -121
- package/src/WABinary/index.ts +0 -5
- package/src/WABinary/jid-utils.ts +0 -68
- package/src/WABinary/types.ts +0 -17
- package/src/WAM/BinaryInfo.ts +0 -12
- package/src/WAM/constants.ts +0 -15382
- package/src/WAM/encode.ts +0 -174
- package/src/WAM/index.ts +0 -3
- package/src/gifted +0 -1
- package/src/index.ts +0 -13
- /package/{src → lib}/Defaults/phonenumber-mcc.json +0 -0
- /package/{src → lib}/Socket/Client/abstract-socket-client.js +0 -0
- /package/{src → lib}/Store/index.js +0 -0
- /package/{src → lib}/Store/make-ordered-dictionary.js +0 -0
- /package/{src → lib}/Types/Auth.js +0 -0
- /package/{src → lib}/Types/Call.js +0 -0
- /package/{src → lib}/Types/Chat.js +0 -0
- /package/{src → lib}/Types/Contact.js +0 -0
- /package/{src → lib}/Types/Events.js +0 -0
- /package/{src → lib}/Types/GroupMetadata.js +0 -0
- /package/{src → lib}/Types/Label.js +0 -0
- /package/{src → lib}/Types/LabelAssociation.js +0 -0
- /package/{src → lib}/Types/Message.js +0 -0
- /package/{src → lib}/Types/Newsletter.js +0 -0
- /package/{src → lib}/Types/Product.js +0 -0
- /package/{src → lib}/Types/Signal.js +0 -0
- /package/{src → lib}/Types/Socket.js +0 -0
- /package/{src → lib}/Types/State.js +0 -0
- /package/{src/WABinary/types.js → lib/Types/USync.js} +0 -0
- /package/{src → lib}/Types/index.js +0 -0
- /package/{src → lib}/Utils/index.js +0 -0
- /package/{src → lib}/Utils/logger.js +0 -0
- /package/{src → lib}/Utils/lt-hash.js +0 -0
- /package/{src → lib}/Utils/noise-handler.js +0 -0
- /package/{src → lib}/WABinary/constants.js +0 -0
- /package/{src → lib}/WABinary/decode.js +0 -0
- /package/{src → lib}/WABinary/generic-utils.js +0 -0
- /package/{src → lib}/WABinary/index.js +0 -0
- /package/{src → lib}/WABinary/jid-utils.js +0 -0
- /package/{src → lib}/WAM/BinaryInfo.js +0 -0
- /package/{src → lib}/WAM/constants.js +0 -0
- /package/{src → lib}/WAM/encode.js +0 -0
- /package/{src → lib}/WAM/index.js +0 -0
|
@@ -1,20 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
12
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
13
|
-
var m = o[Symbol.asyncIterator], i;
|
|
14
|
-
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
15
|
-
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
16
|
-
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
17
|
-
};
|
|
18
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
3
|
exports.uploadingNecessaryImages = exports.parseProductNode = exports.toProductNode = exports.parseOrderDetailsNode = exports.parseCollectionsNode = exports.parseCatalogNode = void 0;
|
|
20
4
|
exports.uploadingNecessaryImagesOfProduct = uploadingNecessaryImagesOfProduct;
|
|
@@ -198,53 +182,41 @@ exports.parseProductNode = parseProductNode;
|
|
|
198
182
|
/**
|
|
199
183
|
* Uploads images not already uploaded to WA's servers
|
|
200
184
|
*/
|
|
201
|
-
function uploadingNecessaryImagesOfProduct(
|
|
202
|
-
|
|
203
|
-
product
|
|
204
|
-
|
|
205
|
-
}
|
|
185
|
+
async function uploadingNecessaryImagesOfProduct(product, waUploadToServer, timeoutMs = 30000) {
|
|
186
|
+
product = {
|
|
187
|
+
...product,
|
|
188
|
+
images: product.images ? await (0, exports.uploadingNecessaryImages)(product.images, waUploadToServer, timeoutMs) : product.images
|
|
189
|
+
};
|
|
190
|
+
return product;
|
|
206
191
|
}
|
|
207
192
|
/**
|
|
208
193
|
* Uploads images not already uploaded to WA's servers
|
|
209
194
|
*/
|
|
210
|
-
const uploadingNecessaryImages =
|
|
211
|
-
const results =
|
|
212
|
-
var _a, e_1, _b, _c;
|
|
195
|
+
const uploadingNecessaryImages = async (images, waUploadToServer, timeoutMs = 30000) => {
|
|
196
|
+
const results = await Promise.all(images.map(async (img) => {
|
|
213
197
|
if ('url' in img) {
|
|
214
198
|
const url = img.url.toString();
|
|
215
199
|
if (url.includes('.whatsapp.net')) {
|
|
216
200
|
return { url };
|
|
217
201
|
}
|
|
218
202
|
}
|
|
219
|
-
const { stream } =
|
|
203
|
+
const { stream } = await (0, messages_media_1.getStream)(img);
|
|
220
204
|
const hasher = (0, crypto_1.createHash)('sha256');
|
|
221
205
|
const contentBlocks = [];
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
_d = false;
|
|
226
|
-
const block = _c;
|
|
227
|
-
hasher.update(block);
|
|
228
|
-
contentBlocks.push(block);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
232
|
-
finally {
|
|
233
|
-
try {
|
|
234
|
-
if (!_d && !_a && (_b = stream_1.return)) yield _b.call(stream_1);
|
|
235
|
-
}
|
|
236
|
-
finally { if (e_1) throw e_1.error; }
|
|
206
|
+
for await (const block of stream) {
|
|
207
|
+
hasher.update(block);
|
|
208
|
+
contentBlocks.push(block);
|
|
237
209
|
}
|
|
238
210
|
const sha = hasher.digest('base64');
|
|
239
|
-
const { directPath } =
|
|
211
|
+
const { directPath } = await waUploadToServer((0, messages_media_1.toReadable)(Buffer.concat(contentBlocks)), {
|
|
240
212
|
mediaType: 'product-catalog-image',
|
|
241
213
|
fileEncSha256B64: sha,
|
|
242
214
|
timeoutMs
|
|
243
215
|
});
|
|
244
216
|
return { url: (0, messages_media_1.getUrlFromDirectPath)(directPath) };
|
|
245
|
-
}))
|
|
217
|
+
}));
|
|
246
218
|
return results;
|
|
247
|
-
}
|
|
219
|
+
};
|
|
248
220
|
exports.uploadingNecessaryImages = uploadingNecessaryImages;
|
|
249
221
|
const parseImageUrls = (mediaNode) => {
|
|
250
222
|
const imgNode = (0, WABinary_1.getBinaryNodeChild)(mediaNode, 'image');
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { AxiosRequestConfig } from 'axios';
|
|
2
|
+
import type { Logger } from 'pino';
|
|
3
|
+
import { proto } from '../../WAProto';
|
|
4
|
+
import { BaileysEventEmitter, ChatModification, ChatMutation, Contact, InitialAppStateSyncOptions, LTHashState, WAPatchCreate, WAPatchName } from '../Types';
|
|
5
|
+
import { BinaryNode } from '../WABinary';
|
|
6
|
+
type FetchAppStateSyncKey = (keyId: string) => Promise<proto.Message.IAppStateSyncKeyData | null | undefined>;
|
|
7
|
+
export type ChatMutationMap = {
|
|
8
|
+
[index: string]: ChatMutation;
|
|
9
|
+
};
|
|
10
|
+
export declare const newLTHashState: () => LTHashState;
|
|
11
|
+
export declare const encodeSyncdPatch: ({ type, index, syncAction, apiVersion, operation }: WAPatchCreate, myAppStateKeyId: string, state: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey) => Promise<{
|
|
12
|
+
patch: proto.ISyncdPatch;
|
|
13
|
+
state: LTHashState;
|
|
14
|
+
}>;
|
|
15
|
+
export declare const decodeSyncdMutations: (msgMutations: (proto.ISyncdMutation | proto.ISyncdRecord)[], initialState: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey, onMutation: (mutation: ChatMutation) => void, validateMacs: boolean) => Promise<{
|
|
16
|
+
hash: any;
|
|
17
|
+
indexValueMap: {
|
|
18
|
+
[indexMacBase64: string]: {
|
|
19
|
+
valueMac: Uint8Array | Buffer;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
}>;
|
|
23
|
+
export declare const decodeSyncdPatch: (msg: proto.ISyncdPatch, name: WAPatchName, initialState: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey, onMutation: (mutation: ChatMutation) => void, validateMacs: boolean) => Promise<{
|
|
24
|
+
hash: any;
|
|
25
|
+
indexValueMap: {
|
|
26
|
+
[indexMacBase64: string]: {
|
|
27
|
+
valueMac: Uint8Array | Buffer;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
}>;
|
|
31
|
+
export declare const extractSyncdPatches: (result: BinaryNode, options: AxiosRequestConfig<{}>) => Promise<{
|
|
32
|
+
critical_block: {
|
|
33
|
+
patches: proto.ISyncdPatch[];
|
|
34
|
+
hasMorePatches: boolean;
|
|
35
|
+
snapshot?: proto.ISyncdSnapshot;
|
|
36
|
+
};
|
|
37
|
+
critical_unblock_low: {
|
|
38
|
+
patches: proto.ISyncdPatch[];
|
|
39
|
+
hasMorePatches: boolean;
|
|
40
|
+
snapshot?: proto.ISyncdSnapshot;
|
|
41
|
+
};
|
|
42
|
+
regular_high: {
|
|
43
|
+
patches: proto.ISyncdPatch[];
|
|
44
|
+
hasMorePatches: boolean;
|
|
45
|
+
snapshot?: proto.ISyncdSnapshot;
|
|
46
|
+
};
|
|
47
|
+
regular_low: {
|
|
48
|
+
patches: proto.ISyncdPatch[];
|
|
49
|
+
hasMorePatches: boolean;
|
|
50
|
+
snapshot?: proto.ISyncdSnapshot;
|
|
51
|
+
};
|
|
52
|
+
regular: {
|
|
53
|
+
patches: proto.ISyncdPatch[];
|
|
54
|
+
hasMorePatches: boolean;
|
|
55
|
+
snapshot?: proto.ISyncdSnapshot;
|
|
56
|
+
};
|
|
57
|
+
}>;
|
|
58
|
+
export declare const downloadExternalBlob: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<{}>) => Promise<any>;
|
|
59
|
+
export declare const downloadExternalPatch: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<{}>) => Promise<proto.SyncdMutations>;
|
|
60
|
+
export declare const decodeSyncdSnapshot: (name: WAPatchName, snapshot: proto.ISyncdSnapshot, getAppStateSyncKey: FetchAppStateSyncKey, minimumVersionNumber: number | undefined, validateMacs?: boolean) => Promise<{
|
|
61
|
+
state: LTHashState;
|
|
62
|
+
mutationMap: ChatMutationMap;
|
|
63
|
+
}>;
|
|
64
|
+
export declare const decodePatches: (name: WAPatchName, syncds: proto.ISyncdPatch[], initial: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey, options: AxiosRequestConfig<{}>, minimumVersionNumber?: number, logger?: Logger, validateMacs?: boolean) => Promise<{
|
|
65
|
+
state: LTHashState;
|
|
66
|
+
mutationMap: ChatMutationMap;
|
|
67
|
+
}>;
|
|
68
|
+
export declare const chatModificationToAppPatch: (mod: ChatModification, jid: string) => WAPatchCreate;
|
|
69
|
+
export declare const processSyncAction: (syncAction: ChatMutation, ev: BaileysEventEmitter, me: Contact, initialSyncOpts?: InitialAppStateSyncOptions, logger?: Logger) => void;
|
|
70
|
+
export {};
|
|
@@ -1,20 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
12
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
13
|
-
var m = o[Symbol.asyncIterator], i;
|
|
14
|
-
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
15
|
-
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
16
|
-
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
17
|
-
};
|
|
18
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
3
|
exports.processSyncAction = exports.chatModificationToAppPatch = exports.decodePatches = exports.decodeSyncdSnapshot = exports.downloadExternalPatch = exports.downloadExternalBlob = exports.extractSyncdPatches = exports.decodeSyncdPatch = exports.decodeSyncdMutations = exports.encodeSyncdPatch = exports.newLTHashState = void 0;
|
|
20
4
|
const boom_1 = require("@hapi/boom");
|
|
@@ -62,7 +46,7 @@ const to64BitNetworkOrder = (e) => {
|
|
|
62
46
|
return buff;
|
|
63
47
|
};
|
|
64
48
|
const makeLtHashGenerator = ({ indexValueMap, hash }) => {
|
|
65
|
-
indexValueMap =
|
|
49
|
+
indexValueMap = { ...indexValueMap };
|
|
66
50
|
const addBuffs = [];
|
|
67
51
|
const subBuffs = [];
|
|
68
52
|
return {
|
|
@@ -115,13 +99,13 @@ const generatePatchMac = (snapshotMac, valueMacs, version, type, key) => {
|
|
|
115
99
|
};
|
|
116
100
|
const newLTHashState = () => ({ version: 0, hash: Buffer.alloc(128), indexValueMap: {} });
|
|
117
101
|
exports.newLTHashState = newLTHashState;
|
|
118
|
-
const encodeSyncdPatch =
|
|
119
|
-
const key = !!myAppStateKeyId ?
|
|
102
|
+
const encodeSyncdPatch = async ({ type, index, syncAction, apiVersion, operation }, myAppStateKeyId, state, getAppStateSyncKey) => {
|
|
103
|
+
const key = !!myAppStateKeyId ? await getAppStateSyncKey(myAppStateKeyId) : undefined;
|
|
120
104
|
if (!key) {
|
|
121
105
|
throw new boom_1.Boom(`myAppStateKey ("${myAppStateKeyId}") not present`, { statusCode: 404 });
|
|
122
106
|
}
|
|
123
107
|
const encKeyId = Buffer.from(myAppStateKeyId, 'base64');
|
|
124
|
-
state =
|
|
108
|
+
state = { ...state, indexValueMap: { ...state.indexValueMap } };
|
|
125
109
|
const indexBuffer = Buffer.from(JSON.stringify(index));
|
|
126
110
|
const dataProto = WAProto_1.proto.SyncActionData.fromObject({
|
|
127
111
|
index: indexBuffer,
|
|
@@ -162,9 +146,9 @@ const encodeSyncdPatch = (_a, myAppStateKeyId_1, state_1, getAppStateSyncKey_1)
|
|
|
162
146
|
const base64Index = indexMac.toString('base64');
|
|
163
147
|
state.indexValueMap[base64Index] = { valueMac };
|
|
164
148
|
return { patch, state };
|
|
165
|
-
}
|
|
149
|
+
};
|
|
166
150
|
exports.encodeSyncdPatch = encodeSyncdPatch;
|
|
167
|
-
const decodeSyncdMutations = (msgMutations, initialState, getAppStateSyncKey, onMutation, validateMacs) =>
|
|
151
|
+
const decodeSyncdMutations = async (msgMutations, initialState, getAppStateSyncKey, onMutation, validateMacs) => {
|
|
168
152
|
const ltGenerator = makeLtHashGenerator(initialState);
|
|
169
153
|
// indexKey used to HMAC sign record.index.blob
|
|
170
154
|
// valueEncryptionKey used to AES-256-CBC encrypt record.value.blob[0:-32]
|
|
@@ -174,7 +158,7 @@ const decodeSyncdMutations = (msgMutations, initialState, getAppStateSyncKey, on
|
|
|
174
158
|
// otherwise, if it's only a record -- it'll be a SET mutation
|
|
175
159
|
const operation = 'operation' in msgMutation ? msgMutation.operation : WAProto_1.proto.SyncdMutation.SyncdOperation.SET;
|
|
176
160
|
const record = ('record' in msgMutation && !!msgMutation.record) ? msgMutation.record : msgMutation;
|
|
177
|
-
const key =
|
|
161
|
+
const key = await getKey(record.keyId.id);
|
|
178
162
|
const content = Buffer.from(record.value.blob);
|
|
179
163
|
const encContent = content.slice(0, -32);
|
|
180
164
|
const ogValueMac = content.slice(-32);
|
|
@@ -201,22 +185,20 @@ const decodeSyncdMutations = (msgMutations, initialState, getAppStateSyncKey, on
|
|
|
201
185
|
});
|
|
202
186
|
}
|
|
203
187
|
return ltGenerator.finish();
|
|
204
|
-
function getKey(keyId) {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
return mutationKeys(keyEnc.keyData);
|
|
212
|
-
});
|
|
188
|
+
async function getKey(keyId) {
|
|
189
|
+
const base64Key = Buffer.from(keyId).toString('base64');
|
|
190
|
+
const keyEnc = await getAppStateSyncKey(base64Key);
|
|
191
|
+
if (!keyEnc) {
|
|
192
|
+
throw new boom_1.Boom(`failed to find key "${base64Key}" to decode mutation`, { statusCode: 404, data: { msgMutations } });
|
|
193
|
+
}
|
|
194
|
+
return mutationKeys(keyEnc.keyData);
|
|
213
195
|
}
|
|
214
|
-
}
|
|
196
|
+
};
|
|
215
197
|
exports.decodeSyncdMutations = decodeSyncdMutations;
|
|
216
|
-
const decodeSyncdPatch = (msg, name, initialState, getAppStateSyncKey, onMutation, validateMacs) =>
|
|
198
|
+
const decodeSyncdPatch = async (msg, name, initialState, getAppStateSyncKey, onMutation, validateMacs) => {
|
|
217
199
|
if (validateMacs) {
|
|
218
200
|
const base64Key = Buffer.from(msg.keyId.id).toString('base64');
|
|
219
|
-
const mainKeyObj =
|
|
201
|
+
const mainKeyObj = await getAppStateSyncKey(base64Key);
|
|
220
202
|
if (!mainKeyObj) {
|
|
221
203
|
throw new boom_1.Boom(`failed to find key "${base64Key}" to decode patch`, { statusCode: 404, data: { msg } });
|
|
222
204
|
}
|
|
@@ -227,15 +209,15 @@ const decodeSyncdPatch = (msg, name, initialState, getAppStateSyncKey, onMutatio
|
|
|
227
209
|
throw new boom_1.Boom('Invalid patch mac');
|
|
228
210
|
}
|
|
229
211
|
}
|
|
230
|
-
const result =
|
|
212
|
+
const result = await (0, exports.decodeSyncdMutations)(msg.mutations, initialState, getAppStateSyncKey, onMutation, validateMacs);
|
|
231
213
|
return result;
|
|
232
|
-
}
|
|
214
|
+
};
|
|
233
215
|
exports.decodeSyncdPatch = decodeSyncdPatch;
|
|
234
|
-
const extractSyncdPatches = (result, options) =>
|
|
216
|
+
const extractSyncdPatches = async (result, options) => {
|
|
235
217
|
const syncNode = (0, WABinary_1.getBinaryNodeChild)(result, 'sync');
|
|
236
218
|
const collectionNodes = (0, WABinary_1.getBinaryNodeChildren)(syncNode, 'collection');
|
|
237
219
|
const final = {};
|
|
238
|
-
|
|
220
|
+
await Promise.all(collectionNodes.map(async (collectionNode) => {
|
|
239
221
|
const patchesNode = (0, WABinary_1.getBinaryNodeChild)(collectionNode, 'patches');
|
|
240
222
|
const patches = (0, WABinary_1.getBinaryNodeChildren)(patchesNode || collectionNode, 'patch');
|
|
241
223
|
const snapshotNode = (0, WABinary_1.getBinaryNodeChild)(collectionNode, 'snapshot');
|
|
@@ -248,7 +230,7 @@ const extractSyncdPatches = (result, options) => __awaiter(void 0, void 0, void
|
|
|
248
230
|
snapshotNode.content = Buffer.from(Object.values(snapshotNode.content));
|
|
249
231
|
}
|
|
250
232
|
const blobRef = WAProto_1.proto.ExternalBlobReference.decode(snapshotNode.content);
|
|
251
|
-
const data =
|
|
233
|
+
const data = await (0, exports.downloadExternalBlob)(blobRef, options);
|
|
252
234
|
snapshot = WAProto_1.proto.SyncdSnapshot.decode(data);
|
|
253
235
|
}
|
|
254
236
|
for (let { content } of patches) {
|
|
@@ -264,45 +246,32 @@ const extractSyncdPatches = (result, options) => __awaiter(void 0, void 0, void
|
|
|
264
246
|
}
|
|
265
247
|
}
|
|
266
248
|
final[name] = { patches: syncds, hasMorePatches, snapshot };
|
|
267
|
-
}))
|
|
249
|
+
}));
|
|
268
250
|
return final;
|
|
269
|
-
}
|
|
251
|
+
};
|
|
270
252
|
exports.extractSyncdPatches = extractSyncdPatches;
|
|
271
|
-
const downloadExternalBlob = (blob, options) =>
|
|
272
|
-
|
|
273
|
-
const stream = yield (0, messages_media_1.downloadContentFromMessage)(blob, 'md-app-state', { options });
|
|
253
|
+
const downloadExternalBlob = async (blob, options) => {
|
|
254
|
+
const stream = await (0, messages_media_1.downloadContentFromMessage)(blob, 'md-app-state', { options });
|
|
274
255
|
const bufferArray = [];
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
_c = stream_1_1.value;
|
|
278
|
-
_d = false;
|
|
279
|
-
const chunk = _c;
|
|
280
|
-
bufferArray.push(chunk);
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
284
|
-
finally {
|
|
285
|
-
try {
|
|
286
|
-
if (!_d && !_a && (_b = stream_1.return)) yield _b.call(stream_1);
|
|
287
|
-
}
|
|
288
|
-
finally { if (e_1) throw e_1.error; }
|
|
256
|
+
for await (const chunk of stream) {
|
|
257
|
+
bufferArray.push(chunk);
|
|
289
258
|
}
|
|
290
259
|
return Buffer.concat(bufferArray);
|
|
291
|
-
}
|
|
260
|
+
};
|
|
292
261
|
exports.downloadExternalBlob = downloadExternalBlob;
|
|
293
|
-
const downloadExternalPatch = (blob, options) =>
|
|
294
|
-
const buffer =
|
|
262
|
+
const downloadExternalPatch = async (blob, options) => {
|
|
263
|
+
const buffer = await (0, exports.downloadExternalBlob)(blob, options);
|
|
295
264
|
const syncData = WAProto_1.proto.SyncdMutations.decode(buffer);
|
|
296
265
|
return syncData;
|
|
297
|
-
}
|
|
266
|
+
};
|
|
298
267
|
exports.downloadExternalPatch = downloadExternalPatch;
|
|
299
|
-
const decodeSyncdSnapshot =
|
|
268
|
+
const decodeSyncdSnapshot = async (name, snapshot, getAppStateSyncKey, minimumVersionNumber, validateMacs = true) => {
|
|
300
269
|
const newState = (0, exports.newLTHashState)();
|
|
301
270
|
newState.version = (0, generics_1.toNumber)(snapshot.version.version);
|
|
302
271
|
const mutationMap = {};
|
|
303
272
|
const areMutationsRequired = typeof minimumVersionNumber === 'undefined'
|
|
304
273
|
|| newState.version > minimumVersionNumber;
|
|
305
|
-
const { hash, indexValueMap } =
|
|
274
|
+
const { hash, indexValueMap } = await (0, exports.decodeSyncdMutations)(snapshot.records, newState, getAppStateSyncKey, areMutationsRequired
|
|
306
275
|
? (mutation) => {
|
|
307
276
|
var _a;
|
|
308
277
|
const index = (_a = mutation.syncAction.index) === null || _a === void 0 ? void 0 : _a.toString();
|
|
@@ -313,7 +282,7 @@ const decodeSyncdSnapshot = (name_1, snapshot_1, getAppStateSyncKey_1, minimumVe
|
|
|
313
282
|
newState.indexValueMap = indexValueMap;
|
|
314
283
|
if (validateMacs) {
|
|
315
284
|
const base64Key = Buffer.from(snapshot.keyId.id).toString('base64');
|
|
316
|
-
const keyEnc =
|
|
285
|
+
const keyEnc = await getAppStateSyncKey(base64Key);
|
|
317
286
|
if (!keyEnc) {
|
|
318
287
|
throw new boom_1.Boom(`failed to find key "${base64Key}" to decode mutation`);
|
|
319
288
|
}
|
|
@@ -327,25 +296,27 @@ const decodeSyncdSnapshot = (name_1, snapshot_1, getAppStateSyncKey_1, minimumVe
|
|
|
327
296
|
state: newState,
|
|
328
297
|
mutationMap
|
|
329
298
|
};
|
|
330
|
-
}
|
|
299
|
+
};
|
|
331
300
|
exports.decodeSyncdSnapshot = decodeSyncdSnapshot;
|
|
332
|
-
const decodePatches =
|
|
301
|
+
const decodePatches = async (name, syncds, initial, getAppStateSyncKey, options, minimumVersionNumber, logger, validateMacs = true) => {
|
|
333
302
|
var _a;
|
|
334
|
-
const newState =
|
|
303
|
+
const newState = {
|
|
304
|
+
...initial,
|
|
305
|
+
indexValueMap: { ...initial.indexValueMap }
|
|
306
|
+
};
|
|
335
307
|
const mutationMap = {};
|
|
336
|
-
for (
|
|
337
|
-
const syncd = syncds[i];
|
|
308
|
+
for (const syncd of syncds) {
|
|
338
309
|
const { version, keyId, snapshotMac } = syncd;
|
|
339
310
|
if (syncd.externalMutations) {
|
|
340
311
|
logger === null || logger === void 0 ? void 0 : logger.trace({ name, version }, 'downloading external patch');
|
|
341
|
-
const ref =
|
|
312
|
+
const ref = await (0, exports.downloadExternalPatch)(syncd.externalMutations, options);
|
|
342
313
|
logger === null || logger === void 0 ? void 0 : logger.debug({ name, version, mutations: ref.mutations.length }, 'downloaded external patch');
|
|
343
314
|
(_a = syncd.mutations) === null || _a === void 0 ? void 0 : _a.push(...ref.mutations);
|
|
344
315
|
}
|
|
345
316
|
const patchVersion = (0, generics_1.toNumber)(version.version);
|
|
346
317
|
newState.version = patchVersion;
|
|
347
318
|
const shouldMutate = typeof minimumVersionNumber === 'undefined' || patchVersion > minimumVersionNumber;
|
|
348
|
-
const decodeResult =
|
|
319
|
+
const decodeResult = await (0, exports.decodeSyncdPatch)(syncd, name, newState, getAppStateSyncKey, shouldMutate
|
|
349
320
|
? mutation => {
|
|
350
321
|
var _a;
|
|
351
322
|
const index = (_a = mutation.syncAction.index) === null || _a === void 0 ? void 0 : _a.toString();
|
|
@@ -356,7 +327,7 @@ const decodePatches = (name_1, syncds_1, initial_1, getAppStateSyncKey_1, option
|
|
|
356
327
|
newState.indexValueMap = decodeResult.indexValueMap;
|
|
357
328
|
if (validateMacs) {
|
|
358
329
|
const base64Key = Buffer.from(keyId.id).toString('base64');
|
|
359
|
-
const keyEnc =
|
|
330
|
+
const keyEnc = await getAppStateSyncKey(base64Key);
|
|
360
331
|
if (!keyEnc) {
|
|
361
332
|
throw new boom_1.Boom(`failed to find key "${base64Key}" to decode mutation`);
|
|
362
333
|
}
|
|
@@ -370,7 +341,7 @@ const decodePatches = (name_1, syncds_1, initial_1, getAppStateSyncKey_1, option
|
|
|
370
341
|
syncd.mutations = [];
|
|
371
342
|
}
|
|
372
343
|
return { state: newState, mutationMap };
|
|
373
|
-
}
|
|
344
|
+
};
|
|
374
345
|
exports.decodePatches = decodePatches;
|
|
375
346
|
const chatModificationToAppPatch = (mod, jid) => {
|
|
376
347
|
const OP = WAProto_1.proto.SyncdMutation.SyncdOperation;
|
|
@@ -446,25 +417,31 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
|
446
417
|
operation: OP.SET
|
|
447
418
|
};
|
|
448
419
|
}
|
|
420
|
+
else if ('deleteForMe' in mod) {
|
|
421
|
+
const { timestamp, key, deleteMedia } = mod.deleteForMe;
|
|
422
|
+
patch = {
|
|
423
|
+
syncAction: {
|
|
424
|
+
deleteMessageForMeAction: {
|
|
425
|
+
deleteMedia,
|
|
426
|
+
messageTimestamp: timestamp
|
|
427
|
+
}
|
|
428
|
+
},
|
|
429
|
+
index: ['deleteMessageForMe', jid, key.id, key.fromMe ? '1' : '0', '0'],
|
|
430
|
+
type: 'regular_high',
|
|
431
|
+
apiVersion: 3,
|
|
432
|
+
operation: OP.SET
|
|
433
|
+
};
|
|
434
|
+
}
|
|
449
435
|
else if ('clear' in mod) {
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
messageTimestamp: key.timestamp
|
|
460
|
-
}
|
|
461
|
-
},
|
|
462
|
-
index: ['deleteMessageForMe', jid, key.id, key.fromMe ? '1' : '0', '0'],
|
|
463
|
-
type: 'regular_high',
|
|
464
|
-
apiVersion: 3,
|
|
465
|
-
operation: OP.SET
|
|
466
|
-
};
|
|
467
|
-
}
|
|
436
|
+
patch = {
|
|
437
|
+
syncAction: {
|
|
438
|
+
clearChatAction: {} // add message range later
|
|
439
|
+
},
|
|
440
|
+
index: ['clearChat', jid, '1' /*the option here is 0 when keep starred messages is enabled*/, '0'],
|
|
441
|
+
type: 'regular_high',
|
|
442
|
+
apiVersion: 6,
|
|
443
|
+
operation: OP.SET
|
|
444
|
+
};
|
|
468
445
|
}
|
|
469
446
|
else if ('pin' in mod) {
|
|
470
447
|
patch = {
|
|
@@ -519,6 +496,22 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
|
519
496
|
operation: OP.SET,
|
|
520
497
|
};
|
|
521
498
|
}
|
|
499
|
+
else if ('addLabel' in mod) {
|
|
500
|
+
patch = {
|
|
501
|
+
syncAction: {
|
|
502
|
+
labelEditAction: {
|
|
503
|
+
name: mod.addLabel.name,
|
|
504
|
+
color: mod.addLabel.color,
|
|
505
|
+
predefinedId: mod.addLabel.predefinedId,
|
|
506
|
+
deleted: mod.addLabel.deleted
|
|
507
|
+
}
|
|
508
|
+
},
|
|
509
|
+
index: ['label_edit', mod.addLabel.id],
|
|
510
|
+
type: 'regular',
|
|
511
|
+
apiVersion: 3,
|
|
512
|
+
operation: OP.SET,
|
|
513
|
+
};
|
|
514
|
+
}
|
|
522
515
|
else if ('addChatLabel' in mod) {
|
|
523
516
|
patch = {
|
|
524
517
|
syncAction: {
|
|
@@ -666,7 +659,7 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
|
666
659
|
else if (action === null || action === void 0 ? void 0 : action.pushNameSetting) {
|
|
667
660
|
const name = (_b = action === null || action === void 0 ? void 0 : action.pushNameSetting) === null || _b === void 0 ? void 0 : _b.name;
|
|
668
661
|
if (name && (me === null || me === void 0 ? void 0 : me.name) !== name) {
|
|
669
|
-
ev.emit('creds.update', { me:
|
|
662
|
+
ev.emit('creds.update', { me: { ...me, name } });
|
|
670
663
|
}
|
|
671
664
|
}
|
|
672
665
|
else if (action === null || action === void 0 ? void 0 : action.pinAction) {
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { KeyPair } from '../Types';
|
|
2
|
+
/** prefix version byte to the pub keys, required for some curve crypto functions */
|
|
3
|
+
export declare const generateSignalPubKey: (pubKey: Uint8Array | Buffer) => any;
|
|
4
|
+
export declare const Curve: {
|
|
5
|
+
generateKeyPair: () => KeyPair;
|
|
6
|
+
sharedKey: (privateKey: Uint8Array, publicKey: Uint8Array) => any;
|
|
7
|
+
sign: (privateKey: Uint8Array, buf: Uint8Array) => any;
|
|
8
|
+
verify: (pubKey: Uint8Array, message: Uint8Array, signature: Uint8Array) => boolean;
|
|
9
|
+
};
|
|
10
|
+
export declare const signedKeyPair: (identityKeyPair: KeyPair, keyId: number) => {
|
|
11
|
+
keyPair: KeyPair;
|
|
12
|
+
signature: any;
|
|
13
|
+
keyId: number;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* encrypt AES 256 GCM;
|
|
17
|
+
* where the tag tag is suffixed to the ciphertext
|
|
18
|
+
* */
|
|
19
|
+
export declare function aesEncryptGCM(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array): any;
|
|
20
|
+
/**
|
|
21
|
+
* decrypt AES 256 GCM;
|
|
22
|
+
* where the auth tag is suffixed to the ciphertext
|
|
23
|
+
* */
|
|
24
|
+
export declare function aesDecryptGCM(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array): any;
|
|
25
|
+
export declare function aesEncryptCTR(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array): any;
|
|
26
|
+
export declare function aesDecryptCTR(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array): any;
|
|
27
|
+
/** decrypt AES 256 CBC; where the IV is prefixed to the buffer */
|
|
28
|
+
export declare function aesDecrypt(buffer: Buffer, key: Buffer): any;
|
|
29
|
+
/** decrypt AES 256 CBC */
|
|
30
|
+
export declare function aesDecryptWithIV(buffer: Buffer, key: Buffer, IV: Buffer): any;
|
|
31
|
+
export declare function aesEncrypt(buffer: Buffer | Uint8Array, key: Buffer): any;
|
|
32
|
+
export declare function aesEncrypWithIV(buffer: Buffer, key: Buffer, IV: Buffer): any;
|
|
33
|
+
export declare function hmacSign(buffer: Buffer | Uint8Array, key: Buffer | Uint8Array, variant?: 'sha256' | 'sha512'): any;
|
|
34
|
+
export declare function sha256(buffer: Buffer): any;
|
|
35
|
+
export declare function md5(buffer: Buffer): any;
|
|
36
|
+
export declare function hkdf(buffer: Uint8Array | Buffer, expandedLength: number, info: {
|
|
37
|
+
salt?: Buffer;
|
|
38
|
+
info?: string;
|
|
39
|
+
}): any;
|
|
40
|
+
export declare function derivePairingCodeKey(pairingCode: string, salt: Buffer): Promise<any>;
|
|
@@ -53,7 +53,9 @@ exports.derivePairingCodeKey = derivePairingCodeKey;
|
|
|
53
53
|
const crypto_1 = require("crypto");
|
|
54
54
|
const futoin_hkdf_1 = __importDefault(require("futoin-hkdf"));
|
|
55
55
|
const libsignal = __importStar(require("libsignal"));
|
|
56
|
+
const util_1 = require("util");
|
|
56
57
|
const Defaults_1 = require("../Defaults");
|
|
58
|
+
const pbkdf2Promise = (0, util_1.promisify)(crypto_1.pbkdf2);
|
|
57
59
|
/** prefix version byte to the pub keys, required for some curve crypto functions */
|
|
58
60
|
const generateSignalPubKey = (pubKey) => (pubKey.length === 33
|
|
59
61
|
? pubKey
|
|
@@ -156,6 +158,6 @@ function md5(buffer) {
|
|
|
156
158
|
function hkdf(buffer, expandedLength, info) {
|
|
157
159
|
return (0, futoin_hkdf_1.default)(!Buffer.isBuffer(buffer) ? Buffer.from(buffer) : buffer, expandedLength, info);
|
|
158
160
|
}
|
|
159
|
-
function derivePairingCodeKey(pairingCode, salt) {
|
|
160
|
-
return
|
|
161
|
+
async function derivePairingCodeKey(pairingCode, salt) {
|
|
162
|
+
return await pbkdf2Promise(pairingCode, salt, 2 << 16, 32, 'sha256');
|
|
161
163
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Logger } from 'pino';
|
|
2
|
+
import { proto } from '../../WAProto';
|
|
3
|
+
import { SignalRepository } from '../Types';
|
|
4
|
+
import { BinaryNode } from '../WABinary';
|
|
5
|
+
export declare const NO_MESSAGE_FOUND_ERROR_TEXT = "Message absent from node";
|
|
6
|
+
export declare const MISSING_KEYS_ERROR_TEXT = "Key used already or never filled";
|
|
7
|
+
export declare const NACK_REASONS: {
|
|
8
|
+
ParsingError: number;
|
|
9
|
+
UnrecognizedStanza: number;
|
|
10
|
+
UnrecognizedStanzaClass: number;
|
|
11
|
+
UnrecognizedStanzaType: number;
|
|
12
|
+
InvalidProtobuf: number;
|
|
13
|
+
InvalidHostedCompanionStanza: number;
|
|
14
|
+
MissingMessageSecret: number;
|
|
15
|
+
SignalErrorOldCounter: number;
|
|
16
|
+
MessageDeletedOnPeer: number;
|
|
17
|
+
UnhandledError: number;
|
|
18
|
+
UnsupportedAdminRevoke: number;
|
|
19
|
+
UnsupportedLIDGroup: number;
|
|
20
|
+
DBOperationFailed: number;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Decode the received node as a message.
|
|
24
|
+
* @note this will only parse the message, not decrypt it
|
|
25
|
+
*/
|
|
26
|
+
export declare function decodeMessageNode(stanza: BinaryNode, meId: string, meLid: string): {
|
|
27
|
+
fullMessage: proto.IWebMessageInfo;
|
|
28
|
+
author: string;
|
|
29
|
+
sender: string;
|
|
30
|
+
};
|
|
31
|
+
export declare const decryptMessageNode: (stanza: BinaryNode, meId: string, meLid: string, repository: SignalRepository, logger: Logger) => {
|
|
32
|
+
fullMessage: proto.IWebMessageInfo;
|
|
33
|
+
category: string;
|
|
34
|
+
author: string;
|
|
35
|
+
decrypt(): Promise<void>;
|
|
36
|
+
};
|