naya-flore 4.7.2 → 4.7.3
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 +0 -104
- package/WAProto/WAProto.proto +89 -1195
- package/WAProto/index.d.ts +1256 -13195
- package/WAProto/index.js +11405 -32544
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.d.ts +0 -231
- package/lib/Defaults/index.js +102 -92
- package/lib/Defaults/phonenumber-mcc.json +221 -221
- package/lib/Signal/libsignal.js +9 -18
- package/lib/Socket/Client/abstract-socket-client.d.ts +2 -0
- package/lib/Socket/Client/index.d.ts +3 -2
- package/lib/Socket/Client/index.js +3 -2
- package/lib/Socket/Client/mobile-socket-client.d.ts +1 -0
- package/lib/Socket/Client/{websocket.d.ts → web-socket-client.d.ts} +1 -1
- package/lib/Socket/Client/{websocket.js → web-socket-client.js} +2 -2
- package/lib/Socket/business.d.ts +43 -42
- package/lib/Socket/chats.d.ts +8 -9
- package/lib/Socket/chats.js +34 -41
- package/lib/Socket/groups.d.ts +7 -7
- package/lib/Socket/groups.js +4 -2
- package/lib/Socket/index.d.ts +52 -51
- package/lib/Socket/messages-recv.d.ts +42 -41
- package/lib/Socket/messages-recv.js +127 -190
- package/lib/Socket/messages-send.d.ts +9 -16
- package/lib/Socket/messages-send.js +316 -467
- package/lib/Socket/newsletter.d.ts +28 -26
- package/lib/Socket/newsletter.js +3 -3
- package/lib/Socket/registration.d.ts +52 -49
- package/lib/Socket/registration.js +7 -7
- package/lib/Socket/socket.d.ts +0 -1
- package/lib/Socket/socket.js +23 -49
- package/lib/Socket/usync.d.ts +10 -11
- package/lib/Store/index.d.ts +2 -2
- package/lib/Store/index.js +2 -2
- package/lib/Store/make-cache-manager-store.d.ts +0 -1
- package/lib/Store/make-in-memory-store.js +1 -5
- package/lib/Store/make-ordered-dictionary.d.ts +1 -1
- package/lib/Types/Auth.d.ts +1 -0
- package/lib/Types/Call.d.ts +1 -1
- package/lib/Types/Chat.d.ts +7 -12
- package/lib/Types/Events.d.ts +2 -17
- package/lib/Types/GroupMetadata.d.ts +2 -3
- package/lib/Types/Label.d.ts +0 -11
- package/lib/Types/Label.js +1 -1
- package/lib/Types/LabelAssociation.js +1 -1
- package/lib/Types/Message.d.ts +10 -170
- package/lib/Types/Newsletter.js +3 -3
- package/lib/Types/Socket.d.ts +4 -7
- package/lib/Types/index.d.ts +0 -9
- package/lib/Types/index.js +1 -1
- package/lib/Utils/auth-utils.js +3 -3
- package/lib/Utils/business.d.ts +1 -1
- package/lib/Utils/business.js +2 -2
- package/lib/Utils/chat-utils.d.ts +12 -11
- package/lib/Utils/chat-utils.js +26 -42
- package/lib/Utils/crypto.d.ts +16 -15
- package/lib/Utils/crypto.js +23 -35
- package/lib/Utils/decode-wa-message.d.ts +0 -17
- package/lib/Utils/decode-wa-message.js +15 -43
- package/lib/Utils/generics.d.ts +17 -13
- package/lib/Utils/generics.js +15 -25
- package/lib/Utils/history.d.ts +2 -6
- package/lib/Utils/history.js +6 -4
- package/lib/Utils/logger.d.ts +3 -1
- package/lib/Utils/make-mutex.d.ts +2 -2
- package/lib/Utils/messages-media.d.ts +28 -25
- package/lib/Utils/messages-media.js +47 -38
- package/lib/Utils/messages.js +41 -454
- package/lib/Utils/noise-handler.d.ts +5 -4
- package/lib/Utils/process-message.js +2 -2
- package/lib/Utils/signal.d.ts +1 -2
- package/lib/Utils/signal.js +19 -11
- package/lib/Utils/use-multi-file-auth-state.d.ts +1 -0
- package/lib/Utils/use-multi-file-auth-state.js +3 -11
- package/lib/Utils/validate-connection.d.ts +1 -1
- package/lib/Utils/validate-connection.js +1 -1
- package/lib/WABinary/decode.d.ts +2 -1
- package/lib/WABinary/decode.js +7 -17
- package/lib/WABinary/encode.d.ts +2 -1
- package/lib/WABinary/encode.js +17 -33
- package/lib/WABinary/generic-utils.d.ts +3 -2
- package/lib/WABinary/generic-utils.js +2 -2
- package/lib/WABinary/jid-utils.d.ts +1 -1
- package/lib/WAM/BinaryInfo.d.ts +11 -2
- package/lib/WAM/encode.d.ts +2 -1
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +3 -3
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +25 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +8 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -0
- package/lib/WAUSync/USyncQuery.d.ts +2 -0
- package/lib/WAUSync/USyncQuery.js +10 -0
- package/lib/WAUSync/USyncUser.d.ts +2 -0
- package/lib/WAUSync/USyncUser.js +4 -0
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -1
- package/package.json +19 -32
- package/lib/Socket/Client/types.d.ts +0 -17
- package/lib/Socket/Client/types.js +0 -13
package/lib/Utils/auth-utils.js
CHANGED
@@ -3,8 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.initAuthCreds = exports.addTransactionCapability = void 0;
|
7
|
-
exports.makeCacheableSignalKeyStore = makeCacheableSignalKeyStore;
|
6
|
+
exports.initAuthCreds = exports.addTransactionCapability = exports.makeCacheableSignalKeyStore = void 0;
|
8
7
|
const crypto_1 = require("crypto");
|
9
8
|
const node_cache_1 = __importDefault(require("node-cache"));
|
10
9
|
const uuid_1 = require("uuid");
|
@@ -19,7 +18,7 @@ const generics_1 = require("./generics");
|
|
19
18
|
*/
|
20
19
|
function makeCacheableSignalKeyStore(store, logger, _cache) {
|
21
20
|
const cache = _cache || new node_cache_1.default({
|
22
|
-
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.SIGNAL_STORE,
|
21
|
+
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.SIGNAL_STORE,
|
23
22
|
useClones: false,
|
24
23
|
deleteOnExpire: true,
|
25
24
|
});
|
@@ -70,6 +69,7 @@ function makeCacheableSignalKeyStore(store, logger, _cache) {
|
|
70
69
|
}
|
71
70
|
};
|
72
71
|
}
|
72
|
+
exports.makeCacheableSignalKeyStore = makeCacheableSignalKeyStore;
|
73
73
|
/**
|
74
74
|
* Adds DB like transaction capability (https://en.wikipedia.org/wiki/Database_transaction) to the SignalKeyStore,
|
75
75
|
* this allows batch read & write operations & improves the performance of the lib
|
package/lib/Utils/business.d.ts
CHANGED
@@ -2,7 +2,7 @@ import { CatalogCollection, OrderDetails, Product, ProductCreate, ProductUpdate,
|
|
2
2
|
import { BinaryNode } from '../WABinary';
|
3
3
|
export declare const parseCatalogNode: (node: BinaryNode) => {
|
4
4
|
products: Product[];
|
5
|
-
nextPageCursor:
|
5
|
+
nextPageCursor: string | undefined;
|
6
6
|
};
|
7
7
|
export declare const parseCollectionsNode: (node: BinaryNode) => {
|
8
8
|
collections: CatalogCollection[];
|
package/lib/Utils/business.js
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.uploadingNecessaryImages = exports.parseProductNode = exports.toProductNode = exports.parseOrderDetailsNode = exports.parseCollectionsNode = exports.parseCatalogNode = void 0;
|
4
|
-
exports.uploadingNecessaryImagesOfProduct = uploadingNecessaryImagesOfProduct;
|
3
|
+
exports.uploadingNecessaryImages = exports.uploadingNecessaryImagesOfProduct = exports.parseProductNode = exports.toProductNode = exports.parseOrderDetailsNode = exports.parseCollectionsNode = exports.parseCatalogNode = void 0;
|
5
4
|
const boom_1 = require("@hapi/boom");
|
6
5
|
const crypto_1 = require("crypto");
|
7
6
|
const WABinary_1 = require("../WABinary");
|
@@ -189,6 +188,7 @@ async function uploadingNecessaryImagesOfProduct(product, waUploadToServer, time
|
|
189
188
|
};
|
190
189
|
return product;
|
191
190
|
}
|
191
|
+
exports.uploadingNecessaryImagesOfProduct = uploadingNecessaryImagesOfProduct;
|
192
192
|
/**
|
193
193
|
* Uploads images not already uploaded to WA's servers
|
194
194
|
*/
|
@@ -1,3 +1,4 @@
|
|
1
|
+
/// <reference types="node" />
|
1
2
|
import { AxiosRequestConfig } from 'axios';
|
2
3
|
import type { Logger } from 'pino';
|
3
4
|
import { proto } from '../../WAProto';
|
@@ -13,7 +14,7 @@ export declare const encodeSyncdPatch: ({ type, index, syncAction, apiVersion, o
|
|
13
14
|
state: LTHashState;
|
14
15
|
}>;
|
15
16
|
export declare const decodeSyncdMutations: (msgMutations: (proto.ISyncdMutation | proto.ISyncdRecord)[], initialState: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey, onMutation: (mutation: ChatMutation) => void, validateMacs: boolean) => Promise<{
|
16
|
-
hash:
|
17
|
+
hash: Buffer;
|
17
18
|
indexValueMap: {
|
18
19
|
[indexMacBase64: string]: {
|
19
20
|
valueMac: Uint8Array | Buffer;
|
@@ -21,47 +22,47 @@ export declare const decodeSyncdMutations: (msgMutations: (proto.ISyncdMutation
|
|
21
22
|
};
|
22
23
|
}>;
|
23
24
|
export declare const decodeSyncdPatch: (msg: proto.ISyncdPatch, name: WAPatchName, initialState: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey, onMutation: (mutation: ChatMutation) => void, validateMacs: boolean) => Promise<{
|
24
|
-
hash:
|
25
|
+
hash: Buffer;
|
25
26
|
indexValueMap: {
|
26
27
|
[indexMacBase64: string]: {
|
27
28
|
valueMac: Uint8Array | Buffer;
|
28
29
|
};
|
29
30
|
};
|
30
31
|
}>;
|
31
|
-
export declare const extractSyncdPatches: (result: BinaryNode, options: AxiosRequestConfig<
|
32
|
+
export declare const extractSyncdPatches: (result: BinaryNode, options: AxiosRequestConfig<any>) => Promise<{
|
32
33
|
critical_block: {
|
33
34
|
patches: proto.ISyncdPatch[];
|
34
35
|
hasMorePatches: boolean;
|
35
|
-
snapshot?: proto.ISyncdSnapshot;
|
36
|
+
snapshot?: proto.ISyncdSnapshot | undefined;
|
36
37
|
};
|
37
38
|
critical_unblock_low: {
|
38
39
|
patches: proto.ISyncdPatch[];
|
39
40
|
hasMorePatches: boolean;
|
40
|
-
snapshot?: proto.ISyncdSnapshot;
|
41
|
+
snapshot?: proto.ISyncdSnapshot | undefined;
|
41
42
|
};
|
42
43
|
regular_high: {
|
43
44
|
patches: proto.ISyncdPatch[];
|
44
45
|
hasMorePatches: boolean;
|
45
|
-
snapshot?: proto.ISyncdSnapshot;
|
46
|
+
snapshot?: proto.ISyncdSnapshot | undefined;
|
46
47
|
};
|
47
48
|
regular_low: {
|
48
49
|
patches: proto.ISyncdPatch[];
|
49
50
|
hasMorePatches: boolean;
|
50
|
-
snapshot?: proto.ISyncdSnapshot;
|
51
|
+
snapshot?: proto.ISyncdSnapshot | undefined;
|
51
52
|
};
|
52
53
|
regular: {
|
53
54
|
patches: proto.ISyncdPatch[];
|
54
55
|
hasMorePatches: boolean;
|
55
|
-
snapshot?: proto.ISyncdSnapshot;
|
56
|
+
snapshot?: proto.ISyncdSnapshot | undefined;
|
56
57
|
};
|
57
58
|
}>;
|
58
|
-
export declare const downloadExternalBlob: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<
|
59
|
-
export declare const downloadExternalPatch: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<
|
59
|
+
export declare const downloadExternalBlob: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<any>) => Promise<Buffer>;
|
60
|
+
export declare const downloadExternalPatch: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<any>) => Promise<proto.SyncdMutations>;
|
60
61
|
export declare const decodeSyncdSnapshot: (name: WAPatchName, snapshot: proto.ISyncdSnapshot, getAppStateSyncKey: FetchAppStateSyncKey, minimumVersionNumber: number | undefined, validateMacs?: boolean) => Promise<{
|
61
62
|
state: LTHashState;
|
62
63
|
mutationMap: ChatMutationMap;
|
63
64
|
}>;
|
64
|
-
export declare const decodePatches: (name: WAPatchName, syncds: proto.ISyncdPatch[], initial: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey, options: AxiosRequestConfig<
|
65
|
+
export declare const decodePatches: (name: WAPatchName, syncds: proto.ISyncdPatch[], initial: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey, options: AxiosRequestConfig<any>, minimumVersionNumber?: number, logger?: Logger, validateMacs?: boolean) => Promise<{
|
65
66
|
state: LTHashState;
|
66
67
|
mutationMap: ChatMutationMap;
|
67
68
|
}>;
|
package/lib/Utils/chat-utils.js
CHANGED
@@ -305,7 +305,8 @@ const decodePatches = async (name, syncds, initial, getAppStateSyncKey, options,
|
|
305
305
|
indexValueMap: { ...initial.indexValueMap }
|
306
306
|
};
|
307
307
|
const mutationMap = {};
|
308
|
-
for (
|
308
|
+
for (let i = 0; i < syncds.length; i++) {
|
309
|
+
const syncd = syncds[i];
|
309
310
|
const { version, keyId, snapshotMac } = syncd;
|
310
311
|
if (syncd.externalMutations) {
|
311
312
|
logger === null || logger === void 0 ? void 0 : logger.trace({ name, version }, 'downloading external patch');
|
@@ -417,31 +418,25 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
417
418
|
operation: OP.SET
|
418
419
|
};
|
419
420
|
}
|
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
|
-
}
|
435
421
|
else if ('clear' in mod) {
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
422
|
+
if (mod.clear === 'all') {
|
423
|
+
throw new boom_1.Boom('not supported');
|
424
|
+
}
|
425
|
+
else {
|
426
|
+
const key = mod.clear.messages[0];
|
427
|
+
patch = {
|
428
|
+
syncAction: {
|
429
|
+
deleteMessageForMeAction: {
|
430
|
+
deleteMedia: false,
|
431
|
+
messageTimestamp: key.timestamp
|
432
|
+
}
|
433
|
+
},
|
434
|
+
index: ['deleteMessageForMe', jid, key.id, key.fromMe ? '1' : '0', '0'],
|
435
|
+
type: 'regular_high',
|
436
|
+
apiVersion: 3,
|
437
|
+
operation: OP.SET
|
438
|
+
};
|
439
|
+
}
|
445
440
|
}
|
446
441
|
else if ('pin' in mod) {
|
447
442
|
patch = {
|
@@ -496,22 +491,6 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
496
491
|
operation: OP.SET,
|
497
492
|
};
|
498
493
|
}
|
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
|
-
}
|
515
494
|
else if ('addChatLabel' in mod) {
|
516
495
|
patch = {
|
517
496
|
syncAction: {
|
@@ -654,7 +633,12 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
654
633
|
});
|
655
634
|
}
|
656
635
|
else if (action === null || action === void 0 ? void 0 : action.contactAction) {
|
657
|
-
ev.emit('contacts.upsert', [{
|
636
|
+
ev.emit('contacts.upsert', [{
|
637
|
+
id: id,
|
638
|
+
name: action.contactAction.fullName,
|
639
|
+
lid: action.contactAction.lidJid || undefined,
|
640
|
+
jid: (0, WABinary_1.isJidUser)(id) ? id : undefined
|
641
|
+
}]);
|
658
642
|
}
|
659
643
|
else if (action === null || action === void 0 ? void 0 : action.pushNameSetting) {
|
660
644
|
const name = (_b = action === null || action === void 0 ? void 0 : action.pushNameSetting) === null || _b === void 0 ? void 0 : _b.name;
|
package/lib/Utils/crypto.d.ts
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
+
/// <reference types="node" />
|
1
2
|
import { KeyPair } from '../Types';
|
2
3
|
/** prefix version byte to the pub keys, required for some curve crypto functions */
|
3
|
-
export declare const generateSignalPubKey: (pubKey: Uint8Array | Buffer) =>
|
4
|
+
export declare const generateSignalPubKey: (pubKey: Uint8Array | Buffer) => Uint8Array | Buffer;
|
4
5
|
export declare const Curve: {
|
5
6
|
generateKeyPair: () => KeyPair;
|
6
|
-
sharedKey: (privateKey: Uint8Array, publicKey: Uint8Array) =>
|
7
|
+
sharedKey: (privateKey: Uint8Array, publicKey: Uint8Array) => Buffer;
|
7
8
|
sign: (privateKey: Uint8Array, buf: Uint8Array) => any;
|
8
9
|
verify: (pubKey: Uint8Array, message: Uint8Array, signature: Uint8Array) => boolean;
|
9
10
|
};
|
@@ -16,25 +17,25 @@ export declare const signedKeyPair: (identityKeyPair: KeyPair, keyId: number) =>
|
|
16
17
|
* encrypt AES 256 GCM;
|
17
18
|
* where the tag tag is suffixed to the ciphertext
|
18
19
|
* */
|
19
|
-
export declare function aesEncryptGCM(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array):
|
20
|
+
export declare function aesEncryptGCM(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array): Buffer;
|
20
21
|
/**
|
21
22
|
* decrypt AES 256 GCM;
|
22
23
|
* where the auth tag is suffixed to the ciphertext
|
23
24
|
* */
|
24
|
-
export declare function aesDecryptGCM(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array):
|
25
|
-
export declare function aesEncryptCTR(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array):
|
26
|
-
export declare function aesDecryptCTR(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array):
|
25
|
+
export declare function aesDecryptGCM(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array): Buffer;
|
26
|
+
export declare function aesEncryptCTR(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array): Buffer;
|
27
|
+
export declare function aesDecryptCTR(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array): Buffer;
|
27
28
|
/** decrypt AES 256 CBC; where the IV is prefixed to the buffer */
|
28
|
-
export declare function aesDecrypt(buffer: Buffer, key: Buffer):
|
29
|
+
export declare function aesDecrypt(buffer: Buffer, key: Buffer): Buffer;
|
29
30
|
/** decrypt AES 256 CBC */
|
30
|
-
export declare function aesDecryptWithIV(buffer: Buffer, key: Buffer, IV: Buffer):
|
31
|
-
export declare function aesEncrypt(buffer: Buffer | Uint8Array, key: Buffer):
|
32
|
-
export declare function aesEncrypWithIV(buffer: Buffer, key: Buffer, IV: Buffer):
|
33
|
-
export declare function hmacSign(buffer: Buffer | Uint8Array, key: Buffer | Uint8Array, variant?: 'sha256' | 'sha512'):
|
34
|
-
export declare function sha256(buffer: Buffer):
|
35
|
-
export declare function md5(buffer: Buffer):
|
31
|
+
export declare function aesDecryptWithIV(buffer: Buffer, key: Buffer, IV: Buffer): Buffer;
|
32
|
+
export declare function aesEncrypt(buffer: Buffer | Uint8Array, key: Buffer): Buffer;
|
33
|
+
export declare function aesEncrypWithIV(buffer: Buffer, key: Buffer, IV: Buffer): Buffer;
|
34
|
+
export declare function hmacSign(buffer: Buffer | Uint8Array, key: Buffer | Uint8Array, variant?: 'sha256' | 'sha512'): Buffer;
|
35
|
+
export declare function sha256(buffer: Buffer): Buffer;
|
36
|
+
export declare function md5(buffer: Buffer): Buffer;
|
36
37
|
export declare function hkdf(buffer: Uint8Array | Buffer, expandedLength: number, info: {
|
37
38
|
salt?: Buffer;
|
38
39
|
info?: string;
|
39
|
-
}):
|
40
|
-
export declare function derivePairingCodeKey(pairingCode: string, salt: Buffer):
|
40
|
+
}): Buffer;
|
41
|
+
export declare function derivePairingCodeKey(pairingCode: string, salt: Buffer): Buffer;
|
package/lib/Utils/crypto.js
CHANGED
@@ -15,47 +15,22 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
15
15
|
}) : function(o, v) {
|
16
16
|
o["default"] = v;
|
17
17
|
});
|
18
|
-
var __importStar = (this && this.__importStar) ||
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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
|
-
})();
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
+
if (mod && mod.__esModule) return mod;
|
20
|
+
var result = {};
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
+
__setModuleDefault(result, mod);
|
23
|
+
return result;
|
24
|
+
};
|
35
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
36
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
37
27
|
};
|
38
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
39
|
-
exports.signedKeyPair = exports.Curve = exports.generateSignalPubKey = void 0;
|
40
|
-
exports.aesEncryptGCM = aesEncryptGCM;
|
41
|
-
exports.aesDecryptGCM = aesDecryptGCM;
|
42
|
-
exports.aesEncryptCTR = aesEncryptCTR;
|
43
|
-
exports.aesDecryptCTR = aesDecryptCTR;
|
44
|
-
exports.aesDecrypt = aesDecrypt;
|
45
|
-
exports.aesDecryptWithIV = aesDecryptWithIV;
|
46
|
-
exports.aesEncrypt = aesEncrypt;
|
47
|
-
exports.aesEncrypWithIV = aesEncrypWithIV;
|
48
|
-
exports.hmacSign = hmacSign;
|
49
|
-
exports.sha256 = sha256;
|
50
|
-
exports.md5 = md5;
|
51
|
-
exports.hkdf = hkdf;
|
52
|
-
exports.derivePairingCodeKey = derivePairingCodeKey;
|
29
|
+
exports.derivePairingCodeKey = exports.hkdf = exports.md5 = exports.sha256 = exports.hmacSign = exports.aesEncrypWithIV = exports.aesEncrypt = exports.aesDecryptWithIV = exports.aesDecrypt = exports.aesDecryptCTR = exports.aesEncryptCTR = exports.aesDecryptGCM = exports.aesEncryptGCM = exports.signedKeyPair = exports.Curve = exports.generateSignalPubKey = void 0;
|
53
30
|
const crypto_1 = require("crypto");
|
54
31
|
const futoin_hkdf_1 = __importDefault(require("futoin-hkdf"));
|
55
32
|
const libsignal = __importStar(require("libsignal"));
|
56
|
-
const util_1 = require("util");
|
57
33
|
const Defaults_1 = require("../Defaults");
|
58
|
-
const pbkdf2Promise = (0, util_1.promisify)(crypto_1.pbkdf2);
|
59
34
|
/** prefix version byte to the pub keys, required for some curve crypto functions */
|
60
35
|
const generateSignalPubKey = (pubKey) => (pubKey.length === 33
|
61
36
|
? pubKey
|
@@ -102,6 +77,7 @@ function aesEncryptGCM(plaintext, key, iv, additionalData) {
|
|
102
77
|
cipher.setAAD(additionalData);
|
103
78
|
return Buffer.concat([cipher.update(plaintext), cipher.final(), cipher.getAuthTag()]);
|
104
79
|
}
|
80
|
+
exports.aesEncryptGCM = aesEncryptGCM;
|
105
81
|
/**
|
106
82
|
* decrypt AES 256 GCM;
|
107
83
|
* where the auth tag is suffixed to the ciphertext
|
@@ -116,48 +92,60 @@ function aesDecryptGCM(ciphertext, key, iv, additionalData) {
|
|
116
92
|
decipher.setAuthTag(tag);
|
117
93
|
return Buffer.concat([decipher.update(enc), decipher.final()]);
|
118
94
|
}
|
95
|
+
exports.aesDecryptGCM = aesDecryptGCM;
|
119
96
|
function aesEncryptCTR(plaintext, key, iv) {
|
120
97
|
const cipher = (0, crypto_1.createCipheriv)('aes-256-ctr', key, iv);
|
121
98
|
return Buffer.concat([cipher.update(plaintext), cipher.final()]);
|
122
99
|
}
|
100
|
+
exports.aesEncryptCTR = aesEncryptCTR;
|
123
101
|
function aesDecryptCTR(ciphertext, key, iv) {
|
124
102
|
const decipher = (0, crypto_1.createDecipheriv)('aes-256-ctr', key, iv);
|
125
103
|
return Buffer.concat([decipher.update(ciphertext), decipher.final()]);
|
126
104
|
}
|
105
|
+
exports.aesDecryptCTR = aesDecryptCTR;
|
127
106
|
/** decrypt AES 256 CBC; where the IV is prefixed to the buffer */
|
128
107
|
function aesDecrypt(buffer, key) {
|
129
108
|
return aesDecryptWithIV(buffer.slice(16, buffer.length), key, buffer.slice(0, 16));
|
130
109
|
}
|
110
|
+
exports.aesDecrypt = aesDecrypt;
|
131
111
|
/** decrypt AES 256 CBC */
|
132
112
|
function aesDecryptWithIV(buffer, key, IV) {
|
133
113
|
const aes = (0, crypto_1.createDecipheriv)('aes-256-cbc', key, IV);
|
134
114
|
return Buffer.concat([aes.update(buffer), aes.final()]);
|
135
115
|
}
|
116
|
+
exports.aesDecryptWithIV = aesDecryptWithIV;
|
136
117
|
// encrypt AES 256 CBC; where a random IV is prefixed to the buffer
|
137
118
|
function aesEncrypt(buffer, key) {
|
138
119
|
const IV = (0, crypto_1.randomBytes)(16);
|
139
120
|
const aes = (0, crypto_1.createCipheriv)('aes-256-cbc', key, IV);
|
140
121
|
return Buffer.concat([IV, aes.update(buffer), aes.final()]); // prefix IV to the buffer
|
141
122
|
}
|
123
|
+
exports.aesEncrypt = aesEncrypt;
|
142
124
|
// encrypt AES 256 CBC with a given IV
|
143
125
|
function aesEncrypWithIV(buffer, key, IV) {
|
144
126
|
const aes = (0, crypto_1.createCipheriv)('aes-256-cbc', key, IV);
|
145
127
|
return Buffer.concat([aes.update(buffer), aes.final()]); // prefix IV to the buffer
|
146
128
|
}
|
129
|
+
exports.aesEncrypWithIV = aesEncrypWithIV;
|
147
130
|
// sign HMAC using SHA 256
|
148
131
|
function hmacSign(buffer, key, variant = 'sha256') {
|
149
132
|
return (0, crypto_1.createHmac)(variant, key).update(buffer).digest();
|
150
133
|
}
|
134
|
+
exports.hmacSign = hmacSign;
|
151
135
|
function sha256(buffer) {
|
152
136
|
return (0, crypto_1.createHash)('sha256').update(buffer).digest();
|
153
137
|
}
|
138
|
+
exports.sha256 = sha256;
|
154
139
|
function md5(buffer) {
|
155
140
|
return (0, crypto_1.createHash)('md5').update(buffer).digest();
|
156
141
|
}
|
142
|
+
exports.md5 = md5;
|
157
143
|
// HKDF key expansion
|
158
144
|
function hkdf(buffer, expandedLength, info) {
|
159
145
|
return (0, futoin_hkdf_1.default)(!Buffer.isBuffer(buffer) ? Buffer.from(buffer) : buffer, expandedLength, info);
|
160
146
|
}
|
161
|
-
|
162
|
-
|
147
|
+
exports.hkdf = hkdf;
|
148
|
+
function derivePairingCodeKey(pairingCode, salt) {
|
149
|
+
return (0, crypto_1.pbkdf2Sync)(pairingCode, salt, 2 << 16, 32, 'sha256');
|
163
150
|
}
|
151
|
+
exports.derivePairingCodeKey = derivePairingCodeKey;
|
@@ -2,23 +2,6 @@ import { Logger } from 'pino';
|
|
2
2
|
import { proto } from '../../WAProto';
|
3
3
|
import { SignalRepository } from '../Types';
|
4
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
5
|
/**
|
23
6
|
* Decode the received node as a message.
|
24
7
|
* @note this will only parse the message, not decrypt it
|
@@ -1,28 +1,11 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.decryptMessageNode = exports.
|
4
|
-
exports.decodeMessageNode = decodeMessageNode;
|
3
|
+
exports.decryptMessageNode = exports.decodeMessageNode = void 0;
|
5
4
|
const boom_1 = require("@hapi/boom");
|
6
5
|
const WAProto_1 = require("../../WAProto");
|
7
6
|
const WABinary_1 = require("../WABinary");
|
8
7
|
const generics_1 = require("./generics");
|
9
|
-
|
10
|
-
exports.MISSING_KEYS_ERROR_TEXT = 'Key used already or never filled';
|
11
|
-
exports.NACK_REASONS = {
|
12
|
-
ParsingError: 487,
|
13
|
-
UnrecognizedStanza: 488,
|
14
|
-
UnrecognizedStanzaClass: 489,
|
15
|
-
UnrecognizedStanzaType: 490,
|
16
|
-
InvalidProtobuf: 491,
|
17
|
-
InvalidHostedCompanionStanza: 493,
|
18
|
-
MissingMessageSecret: 495,
|
19
|
-
SignalErrorOldCounter: 496,
|
20
|
-
MessageDeletedOnPeer: 499,
|
21
|
-
UnhandledError: 500,
|
22
|
-
UnsupportedAdminRevoke: 550,
|
23
|
-
UnsupportedLIDGroup: 551,
|
24
|
-
DBOperationFailed: 552
|
25
|
-
};
|
8
|
+
const NO_MESSAGE_FOUND_ERROR_TEXT = 'Message absent from node';
|
26
9
|
/**
|
27
10
|
* Decode the received node as a message.
|
28
11
|
* @note this will only parse the message, not decrypt it
|
@@ -120,6 +103,7 @@ function decodeMessageNode(stanza, meId, meLid) {
|
|
120
103
|
sender: msgType === 'chat' ? author : chatId
|
121
104
|
};
|
122
105
|
}
|
106
|
+
exports.decodeMessageNode = decodeMessageNode;
|
123
107
|
const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
124
108
|
const { fullMessage, author, sender } = decodeMessageNode(stanza, meId, meLid);
|
125
109
|
return {
|
@@ -129,11 +113,8 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
129
113
|
async decrypt() {
|
130
114
|
var _a;
|
131
115
|
let decryptables = 0;
|
132
|
-
|
133
|
-
const node = (0, WABinary_1.getBinaryNodeChild)(stanza, 'plaintext');
|
134
|
-
const msg = WAProto_1.proto.Message.decode(node === null || node === void 0 ? void 0 : node.content);
|
116
|
+
async function processSenderKeyDistribution(msg) {
|
135
117
|
if (msg.senderKeyDistributionMessage) {
|
136
|
-
//eslint-disable-next-line max-depth
|
137
118
|
try {
|
138
119
|
await repository.processSenderKeyDistributionMessage({
|
139
120
|
authorJid: author,
|
@@ -141,9 +122,14 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
141
122
|
});
|
142
123
|
}
|
143
124
|
catch (err) {
|
144
|
-
logger.error({ key: fullMessage.key, err }, 'failed to
|
125
|
+
logger.error({ key: fullMessage.key, err }, 'failed to process senderKeyDistribution');
|
145
126
|
}
|
146
127
|
}
|
128
|
+
}
|
129
|
+
if ((0, WABinary_1.isJidNewsLetter)(fullMessage.key.remoteJid)) {
|
130
|
+
const node = (0, WABinary_1.getBinaryNodeChild)(stanza, 'plaintext');
|
131
|
+
const msg = WAProto_1.proto.Message.decode(node === null || node === void 0 ? void 0 : node.content);
|
132
|
+
await processSenderKeyDistribution(msg);
|
147
133
|
fullMessage.message = msg;
|
148
134
|
decryptables += 1;
|
149
135
|
}
|
@@ -154,7 +140,7 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
154
140
|
const details = WAProto_1.proto.VerifiedNameCertificate.Details.decode(cert.details);
|
155
141
|
fullMessage.verifiedBizName = details.verifiedName;
|
156
142
|
}
|
157
|
-
if (tag !== 'enc'
|
143
|
+
if (tag !== 'enc') {
|
158
144
|
continue;
|
159
145
|
}
|
160
146
|
if (!(content instanceof Uint8Array)) {
|
@@ -163,7 +149,7 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
163
149
|
decryptables += 1;
|
164
150
|
let msgBuffer;
|
165
151
|
try {
|
166
|
-
const e2eType =
|
152
|
+
const e2eType = attrs.type;
|
167
153
|
switch (e2eType) {
|
168
154
|
case 'skmsg':
|
169
155
|
msgBuffer = await repository.decryptGroupMessage({
|
@@ -181,26 +167,12 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
181
167
|
ciphertext: content
|
182
168
|
});
|
183
169
|
break;
|
184
|
-
case 'plaintext':
|
185
|
-
msgBuffer = content;
|
186
|
-
break;
|
187
170
|
default:
|
188
171
|
throw new Error(`Unknown e2e type: ${e2eType}`);
|
189
172
|
}
|
190
|
-
let msg = WAProto_1.proto.Message.decode(
|
173
|
+
let msg = WAProto_1.proto.Message.decode((0, generics_1.unpadRandomMax16)(msgBuffer));
|
191
174
|
msg = ((_a = msg.deviceSentMessage) === null || _a === void 0 ? void 0 : _a.message) || msg;
|
192
|
-
|
193
|
-
//eslint-disable-next-line max-depth
|
194
|
-
try {
|
195
|
-
await repository.processSenderKeyDistributionMessage({
|
196
|
-
authorJid: author,
|
197
|
-
item: msg.senderKeyDistributionMessage
|
198
|
-
});
|
199
|
-
}
|
200
|
-
catch (err) {
|
201
|
-
logger.error({ key: fullMessage.key, err }, 'failed to decrypt message');
|
202
|
-
}
|
203
|
-
}
|
175
|
+
await processSenderKeyDistribution(msg);
|
204
176
|
if (fullMessage.message) {
|
205
177
|
Object.assign(fullMessage.message, msg);
|
206
178
|
}
|
@@ -218,7 +190,7 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
218
190
|
// if nothing was found to decrypt
|
219
191
|
if (!decryptables) {
|
220
192
|
fullMessage.messageStubType = WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT;
|
221
|
-
fullMessage.messageStubParameters = [
|
193
|
+
fullMessage.messageStubParameters = [NO_MESSAGE_FOUND_ERROR_TEXT, JSON.stringify(stanza, generics_1.BufferJSON.replacer)];
|
222
194
|
}
|
223
195
|
}
|
224
196
|
};
|
package/lib/Utils/generics.d.ts
CHANGED
@@ -1,20 +1,24 @@
|
|
1
|
+
/// <reference types="node" />
|
1
2
|
import { AxiosRequestConfig } from 'axios';
|
2
3
|
import { Logger } from 'pino';
|
3
4
|
import { proto } from '../../WAProto';
|
4
|
-
import { BaileysEventEmitter, BaileysEventMap,
|
5
|
+
import { BaileysEventEmitter, BaileysEventMap, WACallUpdateType, WAVersion } from '../Types';
|
5
6
|
import { BinaryNode } from '../WABinary';
|
6
|
-
export declare const Browsers:
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
export declare const Browsers: {
|
8
|
+
ubuntu: (browser: any) => [string, string, string];
|
9
|
+
macOS: (browser: any) => [string, string, string];
|
10
|
+
baileys: (browser: any) => [string, string, string];
|
11
|
+
windows: (browser: any) => [string, string, string];
|
12
|
+
/** The appropriate browser based on your OS & release */
|
13
|
+
appropriate: (browser: any) => [string, string, string];
|
11
14
|
};
|
15
|
+
export declare const getPlatformId: (browser: string) => any;
|
12
16
|
export declare const getKeyAuthor: (key: proto.IMessageKey | undefined | null, meId?: string) => string;
|
13
|
-
export declare const writeRandomPadMax16: (msg: Uint8Array) =>
|
14
|
-
export declare const unpadRandomMax16: (e: Uint8Array | Buffer) => Uint8Array
|
15
|
-
export declare const encodeWAMessage: (message: proto.IMessage) =>
|
17
|
+
export declare const writeRandomPadMax16: (msg: Uint8Array) => Buffer;
|
18
|
+
export declare const unpadRandomMax16: (e: Uint8Array | Buffer) => Uint8Array;
|
19
|
+
export declare const encodeWAMessage: (message: proto.IMessage) => Buffer;
|
16
20
|
export declare const generateRegistrationId: () => number;
|
17
|
-
export declare const encodeBigEndian: (e: number, t?: number) => Uint8Array
|
21
|
+
export declare const encodeBigEndian: (e: number, t?: number) => Uint8Array;
|
18
22
|
export declare const toNumber: (t: Long | number | null | undefined) => number;
|
19
23
|
/** unix timestamp of a date in seconds */
|
20
24
|
export declare const unixTimestampSeconds: (date?: Date) => number;
|
@@ -34,14 +38,14 @@ export declare function promiseTimeout<T>(ms: number | undefined, promise: (reso
|
|
34
38
|
export declare const generateMessageIDV2: (userId?: string) => string;
|
35
39
|
export declare const generateMessageID: () => string;
|
36
40
|
export declare function bindWaitForEvent<T extends keyof BaileysEventMap>(ev: BaileysEventEmitter, event: T): (check: (u: BaileysEventMap[T]) => boolean | undefined, timeoutMs?: number) => Promise<void>;
|
37
|
-
export declare const bindWaitForConnectionUpdate: (ev: BaileysEventEmitter) => (check: (u: Partial<ConnectionState>) => boolean | undefined, timeoutMs?: number) => Promise<void>;
|
41
|
+
export declare const bindWaitForConnectionUpdate: (ev: BaileysEventEmitter) => (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number) => Promise<void>;
|
38
42
|
export declare const printQRIfNecessaryListener: (ev: BaileysEventEmitter, logger: Logger) => void;
|
39
43
|
/**
|
40
44
|
* utility that fetches latest baileys version from the master branch.
|
41
45
|
* Use to ensure your WA connection is always on the latest version
|
42
46
|
*/
|
43
47
|
export declare const fetchLatestBaileysVersion: (options?: AxiosRequestConfig<any>) => Promise<{
|
44
|
-
version:
|
48
|
+
version: WAVersion;
|
45
49
|
isLatest: boolean;
|
46
50
|
error?: undefined;
|
47
51
|
} | {
|
@@ -83,6 +87,6 @@ export declare const getCodeFromWSError: (error: Error) => number;
|
|
83
87
|
* Is the given platform WA business
|
84
88
|
* @param platform AuthenticationCreds.platform
|
85
89
|
*/
|
86
|
-
export declare const isWABusinessPlatform: (platform: string) =>
|
90
|
+
export declare const isWABusinessPlatform: (platform: string) => boolean;
|
87
91
|
export declare function trimUndefined(obj: any): any;
|
88
92
|
export declare function bytesToCrockford(buffer: Buffer): string;
|