angularsockets 1.0.3 → 1.4.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 +170 -0
- package/README.md +163 -1813
- package/WAProto/GenerateStatics.sh +4 -0
- package/WAProto/WAProto.proto +4775 -0
- package/WAProto/index.d.ts +4798 -124
- package/WAProto/index.js +14270 -302
- package/WAProto/index.ts.ts +53473 -0
- package/engine-requirements.js +10 -0
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.d.ts +4 -6
- package/lib/Defaults/index.js +4 -6
- package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
- package/lib/Signal/Group/ciphertext-message.js +15 -0
- package/lib/Signal/Group/group-session-builder.d.ts +14 -0
- package/lib/Signal/Group/group-session-builder.js +64 -0
- package/lib/Signal/Group/group_cipher.d.ts +17 -0
- package/lib/Signal/Group/group_cipher.js +96 -0
- package/lib/Signal/Group/index.d.ts +11 -0
- package/lib/Signal/Group/index.js +57 -0
- package/lib/Signal/Group/keyhelper.d.ts +10 -0
- package/lib/Signal/Group/keyhelper.js +55 -0
- package/lib/Signal/Group/queue-job.d.ts +1 -0
- package/lib/Signal/Group/queue-job.js +57 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
- package/lib/Signal/Group/sender-chain-key.js +34 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
- package/lib/Signal/Group/sender-key-message.d.ts +18 -0
- package/lib/Signal/Group/sender-key-message.js +69 -0
- package/lib/Signal/Group/sender-key-name.d.ts +17 -0
- package/lib/Signal/Group/sender-key-name.js +51 -0
- package/lib/Signal/Group/sender-key-record.d.ts +30 -0
- package/lib/Signal/Group/sender-key-record.js +53 -0
- package/lib/Signal/Group/sender-key-state.d.ts +38 -0
- package/lib/Signal/Group/sender-key-state.js +99 -0
- package/lib/Signal/Group/sender-message-key.d.ts +11 -0
- package/{WASignalGroup/sender_message_key.js → lib/Signal/Group/sender-message-key.js} +6 -16
- package/lib/Signal/libsignal.js +51 -29
- package/lib/Socket/Client/index.d.ts +2 -3
- package/lib/Socket/Client/index.js +2 -3
- package/lib/Socket/Client/{abstract-socket-client.d.ts → types.d.ts} +1 -2
- package/lib/Socket/Client/{web-socket-client.d.ts → websocket.d.ts} +2 -1
- package/lib/Socket/Client/{web-socket-client.js → websocket.js} +54 -5
- package/lib/Socket/RHandler.d.ts +416 -0
- package/lib/Socket/RHandler.js +530 -0
- package/lib/Socket/business.d.ts +39 -37
- package/lib/Socket/chats.d.ts +36 -23
- package/lib/Socket/chats.js +74 -116
- package/lib/Socket/groups.d.ts +42 -33
- package/lib/Socket/groups.js +26 -9
- package/lib/Socket/index.d.ts +39 -39
- package/lib/Socket/index.js +2 -2
- package/lib/Socket/messages-recv.d.ts +37 -34
- package/lib/Socket/messages-recv.js +111 -29
- package/lib/Socket/messages-send.d.ts +50 -53
- package/lib/Socket/messages-send.js +213 -397
- package/lib/Socket/newsletter.d.ts +25 -21
- package/lib/Socket/newsletter.js +92 -25
- package/lib/Socket/socket.d.ts +10 -11
- package/lib/Socket/socket.js +34 -23
- package/lib/Socket/usync.d.ts +11 -12
- package/lib/Store/index.d.ts +1 -2
- package/lib/Store/index.js +1 -3
- package/lib/Store/make-in-memory-store.d.ts +22 -22
- package/lib/Store/make-in-memory-store.js +21 -13
- package/lib/Store/make-ordered-dictionary.d.ts +1 -1
- package/lib/Types/Auth.d.ts +0 -6
- package/lib/Types/Chat.d.ts +6 -4
- package/lib/Types/Contact.d.ts +5 -1
- package/lib/Types/Events.d.ts +27 -0
- package/lib/Types/GroupMetadata.d.ts +8 -0
- package/lib/Types/Label.d.ts +0 -11
- package/lib/Types/Message.d.ts +59 -90
- package/lib/Types/Message.js +0 -2
- package/lib/Types/Newsletter.d.ts +97 -86
- package/lib/Types/Newsletter.js +38 -32
- package/lib/Types/Socket.d.ts +10 -7
- package/lib/Types/index.d.ts +1 -3
- package/lib/Types/index.js +1 -1
- package/lib/Utils/audioToBuffer.js +29 -0
- package/lib/Utils/auth-utils.d.ts +3 -3
- package/lib/Utils/auth-utils.js +13 -41
- package/lib/Utils/business.d.ts +1 -1
- package/lib/Utils/chat-utils.d.ts +12 -12
- package/lib/Utils/chat-utils.js +4 -19
- package/lib/Utils/crypto.d.ts +15 -15
- package/lib/Utils/crypto.js +6 -12
- package/lib/Utils/decode-wa-message.d.ts +5 -6
- package/lib/Utils/decode-wa-message.js +28 -55
- package/lib/Utils/event-buffer.d.ts +2 -2
- package/lib/Utils/event-buffer.js +2 -1
- package/lib/Utils/generics.d.ts +12 -11
- package/lib/Utils/generics.js +64 -38
- package/lib/Utils/history.d.ts +2 -2
- package/lib/Utils/history.js +1 -1
- package/lib/Utils/index.d.ts +2 -0
- package/lib/Utils/index.js +3 -0
- package/lib/Utils/link-preview.d.ts +2 -2
- package/lib/Utils/link-preview.js +34 -1
- package/lib/Utils/logger.d.ts +10 -1
- package/lib/Utils/lt-hash.d.ts +2 -2
- package/lib/Utils/lt-hash.js +6 -6
- package/lib/Utils/messages-media.d.ts +40 -29
- package/lib/Utils/messages-media.js +276 -110
- package/lib/Utils/messages.d.ts +8 -10
- package/lib/Utils/messages.js +126 -317
- package/lib/Utils/noise-handler.d.ts +10 -11
- package/lib/Utils/noise-handler.js +3 -13
- package/lib/Utils/process-message.d.ts +3 -2
- package/lib/Utils/process-message.js +17 -5
- package/lib/Utils/signal.js +2 -8
- package/lib/Utils/streamToBuffer.js +15 -0
- package/lib/Utils/use-multi-file-auth-state.js +72 -242
- package/lib/Utils/validate-connection.d.ts +2 -3
- package/lib/Utils/validate-connection.js +19 -51
- package/lib/WABinary/constants.d.ts +4 -4
- package/lib/WABinary/constants.js +1276 -13
- package/lib/WABinary/decode.d.ts +2 -2
- package/lib/WABinary/decode.js +3 -2
- package/lib/WABinary/encode.js +5 -7
- package/lib/WABinary/generic-utils.d.ts +2 -2
- package/lib/WABinary/jid-utils.d.ts +9 -4
- package/lib/WABinary/jid-utils.js +26 -5
- package/lib/WABinary/jid-utils.js.bak +83 -0
- package/lib/WAM/encode.d.ts +1 -1
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +1 -1
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +3 -3
- package/lib/WAUSync/USyncUser.d.ts +2 -0
- package/lib/index.d.ts +16 -0
- package/lib/index.js +48 -4
- package/lib/index.js.bak +56 -0
- package/package.json +43 -35
- package/WASignalGroup/GroupProtocol.js +0 -1697
- package/WASignalGroup/ciphertext_message.js +0 -16
- package/WASignalGroup/group_cipher.js +0 -120
- package/WASignalGroup/group_session_builder.js +0 -46
- package/WASignalGroup/index.js +0 -5
- package/WASignalGroup/keyhelper.js +0 -21
- package/WASignalGroup/protobufs.js +0 -3
- package/WASignalGroup/queue_job.js +0 -69
- package/WASignalGroup/sender_chain_key.js +0 -50
- package/WASignalGroup/sender_key_distribution_message.js +0 -78
- package/WASignalGroup/sender_key_message.js +0 -92
- package/WASignalGroup/sender_key_name.js +0 -70
- package/WASignalGroup/sender_key_record.js +0 -56
- package/WASignalGroup/sender_key_state.js +0 -129
- package/lib/Socket/Client/mobile-socket-client.d.ts +0 -13
- package/lib/Socket/Client/mobile-socket-client.js +0 -65
- package/lib/Socket/registration.d.ts +0 -264
- package/lib/Socket/registration.js +0 -166
- package/lib/Store/make-cache-manager-store.d.ts +0 -14
- package/lib/Store/make-cache-manager-store.js +0 -83
- package/lib/Utils/use-single-file-auth-state.d.ts +0 -12
- package/lib/Utils/use-single-file-auth-state.js +0 -75
- /package/lib/Socket/Client/{abstract-socket-client.js → types.js} +0 -0
package/lib/Utils/chat-utils.js
CHANGED
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
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;
|
|
4
4
|
const boom_1 = require("@hapi/boom");
|
|
5
5
|
const WAProto_1 = require("../../WAProto");
|
|
6
|
-
const LabelAssociation_1 = require("../Types/LabelAssociation");
|
|
7
6
|
const WABinary_1 = require("../WABinary");
|
|
7
|
+
const LabelAssociation_1 = require("../Types/LabelAssociation");
|
|
8
8
|
const crypto_1 = require("./crypto");
|
|
9
9
|
const generics_1 = require("./generics");
|
|
10
10
|
const lt_hash_1 = require("./lt-hash");
|
|
@@ -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');
|
|
@@ -496,22 +497,6 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
|
496
497
|
operation: OP.SET,
|
|
497
498
|
};
|
|
498
499
|
}
|
|
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
500
|
else if ('addChatLabel' in mod) {
|
|
516
501
|
patch = {
|
|
517
502
|
syncAction: {
|
|
@@ -654,7 +639,7 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
|
654
639
|
});
|
|
655
640
|
}
|
|
656
641
|
else if (action === null || action === void 0 ? void 0 : action.contactAction) {
|
|
657
|
-
ev.emit('contacts.upsert', [{ id, name: action.contactAction.fullName }]);
|
|
642
|
+
ev.emit('contacts.upsert', [{ id, name: action.contactAction.fullName, lid: action.contactAction.lidJid || undefined, jid: (0, WABinary_1.isJidUser)(id) ? id : action.contactAction.pnJid }]);
|
|
658
643
|
}
|
|
659
644
|
else if (action === null || action === void 0 ? void 0 : action.pushNameSetting) {
|
|
660
645
|
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,9 @@
|
|
|
1
1
|
import { KeyPair } from '../Types';
|
|
2
2
|
/** prefix version byte to the pub keys, required for some curve crypto functions */
|
|
3
|
-
export declare const generateSignalPubKey: (pubKey: Uint8Array | Buffer) =>
|
|
3
|
+
export declare const generateSignalPubKey: (pubKey: Uint8Array | Buffer) => Uint8Array<ArrayBufferLike> | Buffer<ArrayBufferLike>;
|
|
4
4
|
export declare const Curve: {
|
|
5
5
|
generateKeyPair: () => KeyPair;
|
|
6
|
-
sharedKey: (privateKey: Uint8Array, publicKey: Uint8Array) => any
|
|
6
|
+
sharedKey: (privateKey: Uint8Array, publicKey: Uint8Array) => Buffer<any>;
|
|
7
7
|
sign: (privateKey: Uint8Array, buf: Uint8Array) => any;
|
|
8
8
|
verify: (pubKey: Uint8Array, message: Uint8Array, signature: Uint8Array) => boolean;
|
|
9
9
|
};
|
|
@@ -16,25 +16,25 @@ export declare const signedKeyPair: (identityKeyPair: KeyPair, keyId: number) =>
|
|
|
16
16
|
* encrypt AES 256 GCM;
|
|
17
17
|
* where the tag tag is suffixed to the ciphertext
|
|
18
18
|
* */
|
|
19
|
-
export declare function aesEncryptGCM(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array):
|
|
19
|
+
export declare function aesEncryptGCM(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array): Buffer<ArrayBuffer>;
|
|
20
20
|
/**
|
|
21
21
|
* decrypt AES 256 GCM;
|
|
22
22
|
* where the auth tag is suffixed to the ciphertext
|
|
23
23
|
* */
|
|
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):
|
|
24
|
+
export declare function aesDecryptGCM(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array): Buffer<ArrayBuffer>;
|
|
25
|
+
export declare function aesEncryptCTR(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array): Buffer<ArrayBuffer>;
|
|
26
|
+
export declare function aesDecryptCTR(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array): Buffer<ArrayBuffer>;
|
|
27
27
|
/** decrypt AES 256 CBC; where the IV is prefixed to the buffer */
|
|
28
|
-
export declare function aesDecrypt(buffer: Buffer, key: Buffer):
|
|
28
|
+
export declare function aesDecrypt(buffer: Buffer, key: Buffer): Buffer<ArrayBuffer>;
|
|
29
29
|
/** 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):
|
|
30
|
+
export declare function aesDecryptWithIV(buffer: Buffer, key: Buffer, IV: Buffer): Buffer<ArrayBuffer>;
|
|
31
|
+
export declare function aesEncrypt(buffer: Buffer | Uint8Array, key: Buffer): Buffer<ArrayBuffer>;
|
|
32
|
+
export declare function aesEncrypWithIV(buffer: Buffer, key: Buffer, IV: Buffer): Buffer<ArrayBuffer>;
|
|
33
|
+
export declare function hmacSign(buffer: Buffer | Uint8Array, key: Buffer | Uint8Array, variant?: 'sha256' | 'sha512'): Buffer<ArrayBufferLike>;
|
|
34
|
+
export declare function sha256(buffer: Buffer): Buffer<ArrayBufferLike>;
|
|
35
|
+
export declare function md5(buffer: Buffer): Buffer<ArrayBufferLike>;
|
|
36
36
|
export declare function hkdf(buffer: Uint8Array | Buffer, expandedLength: number, info: {
|
|
37
37
|
salt?: Buffer;
|
|
38
38
|
info?: string;
|
|
39
|
-
}):
|
|
40
|
-
export declare function derivePairingCodeKey(pairingCode: string, salt: Buffer): Promise<
|
|
39
|
+
}): Promise<Buffer>;
|
|
40
|
+
export declare function derivePairingCodeKey(pairingCode: string, salt: Buffer): Promise<Buffer>;
|
package/lib/Utils/crypto.js
CHANGED
|
@@ -32,9 +32,6 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
32
32
|
return result;
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
36
|
exports.signedKeyPair = exports.Curve = exports.generateSignalPubKey = void 0;
|
|
40
37
|
exports.aesEncryptGCM = aesEncryptGCM;
|
|
@@ -51,12 +48,10 @@ exports.md5 = md5;
|
|
|
51
48
|
exports.hkdf = hkdf;
|
|
52
49
|
exports.derivePairingCodeKey = derivePairingCodeKey;
|
|
53
50
|
const crypto_1 = require("crypto");
|
|
54
|
-
const crypto_2 = globalThis.crypto ?? crypto_1.webcrypto ?? crypto_1;
|
|
55
|
-
//const futoin_hkdf_1 = __importDefault(require("futoin-hkdf"));
|
|
56
51
|
const libsignal = __importStar(require("libsignal"));
|
|
57
|
-
const util_1 = require("util");
|
|
58
52
|
const Defaults_1 = require("../Defaults");
|
|
59
|
-
//
|
|
53
|
+
// insure browser & node compatibility
|
|
54
|
+
const { subtle } = globalThis.crypto;
|
|
60
55
|
/** prefix version byte to the pub keys, required for some curve crypto functions */
|
|
61
56
|
const generateSignalPubKey = (pubKey) => (pubKey.length === 33
|
|
62
57
|
? pubKey
|
|
@@ -167,9 +162,9 @@ async function hkdf(buffer, expandedLength, info) {
|
|
|
167
162
|
? new TextEncoder().encode(info.info)
|
|
168
163
|
: new Uint8Array(0);
|
|
169
164
|
// Import the input key material
|
|
170
|
-
const importedKey = await
|
|
165
|
+
const importedKey = await subtle.importKey('raw', inputKeyMaterial, { name: 'HKDF' }, false, ['deriveBits']);
|
|
171
166
|
// Derive bits using HKDF
|
|
172
|
-
const derivedBits = await
|
|
167
|
+
const derivedBits = await subtle.deriveBits({
|
|
173
168
|
name: 'HKDF',
|
|
174
169
|
hash: 'SHA-256',
|
|
175
170
|
salt: salt,
|
|
@@ -184,10 +179,10 @@ async function derivePairingCodeKey(pairingCode, salt) {
|
|
|
184
179
|
const pairingCodeBuffer = encoder.encode(pairingCode);
|
|
185
180
|
const saltBuffer = salt instanceof Uint8Array ? salt : new Uint8Array(salt);
|
|
186
181
|
// Import the pairing code as key material
|
|
187
|
-
const keyMaterial = await
|
|
182
|
+
const keyMaterial = await subtle.importKey('raw', pairingCodeBuffer, { name: 'PBKDF2' }, false, ['deriveBits']);
|
|
188
183
|
// Derive bits using PBKDF2 with the same parameters
|
|
189
184
|
// 2 << 16 = 131,072 iterations
|
|
190
|
-
const derivedBits = await
|
|
185
|
+
const derivedBits = await subtle.deriveBits({
|
|
191
186
|
name: 'PBKDF2',
|
|
192
187
|
salt: saltBuffer,
|
|
193
188
|
iterations: 2 << 16,
|
|
@@ -196,4 +191,3 @@ async function derivePairingCodeKey(pairingCode, salt) {
|
|
|
196
191
|
);
|
|
197
192
|
return Buffer.from(derivedBits);
|
|
198
193
|
}
|
|
199
|
-
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { SignalRepository } from '../Types';
|
|
1
|
+
import { ILogger } from './logger';
|
|
2
|
+
import { SignalRepository, WAMessage } from '../Types';
|
|
4
3
|
import { BinaryNode } from '../WABinary';
|
|
5
4
|
export declare const NO_MESSAGE_FOUND_ERROR_TEXT = "Message absent from node";
|
|
6
5
|
export declare const MISSING_KEYS_ERROR_TEXT = "Key used already or never filled";
|
|
@@ -24,12 +23,12 @@ export declare const NACK_REASONS: {
|
|
|
24
23
|
* @note this will only parse the message, not decrypt it
|
|
25
24
|
*/
|
|
26
25
|
export declare function decodeMessageNode(stanza: BinaryNode, meId: string, meLid: string): {
|
|
27
|
-
fullMessage:
|
|
26
|
+
fullMessage: WAMessage;
|
|
28
27
|
author: string;
|
|
29
28
|
sender: string;
|
|
30
29
|
};
|
|
31
|
-
export declare const decryptMessageNode: (stanza: BinaryNode, meId: string, meLid: string, repository: SignalRepository, logger:
|
|
32
|
-
fullMessage:
|
|
30
|
+
export declare const decryptMessageNode: (stanza: BinaryNode, meId: string, meLid: string, repository: SignalRepository, logger: ILogger) => {
|
|
31
|
+
fullMessage: WAMessage;
|
|
33
32
|
category: string;
|
|
34
33
|
author: string;
|
|
35
34
|
decrypt(): Promise<void>;
|
|
@@ -28,32 +28,22 @@ exports.NACK_REASONS = {
|
|
|
28
28
|
* @note this will only parse the message, not decrypt it
|
|
29
29
|
*/
|
|
30
30
|
function decodeMessageNode(stanza, meId, meLid) {
|
|
31
|
-
var _a, _b;
|
|
31
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
32
32
|
let msgType;
|
|
33
33
|
let chatId;
|
|
34
34
|
let author;
|
|
35
35
|
const msgId = stanza.attrs.id;
|
|
36
36
|
const from = stanza.attrs.from;
|
|
37
|
+
const senderPn = (_a = stanza === null || stanza === void 0 ? void 0 : stanza.attrs) === null || _a === void 0 ? void 0 : _a.sender_pn;
|
|
38
|
+
const senderLid = (_b = stanza === null || stanza === void 0 ? void 0 : stanza.attrs) === null || _b === void 0 ? void 0 : _b.sender_lid;
|
|
37
39
|
const participant = stanza.attrs.participant;
|
|
40
|
+
const participantLid = (_c = stanza === null || stanza === void 0 ? void 0 : stanza.attrs) === null || _c === void 0 ? void 0 : _c.participant_lid;
|
|
38
41
|
const recipient = stanza.attrs.recipient;
|
|
39
42
|
const isMe = (jid) => (0, WABinary_1.areJidsSameUser)(jid, meId);
|
|
40
43
|
const isMeLid = (jid) => (0, WABinary_1.areJidsSameUser)(jid, meLid);
|
|
41
|
-
if ((0, WABinary_1.isJidUser)(from)) {
|
|
42
|
-
if (recipient) {
|
|
43
|
-
if (!isMe(from)) {
|
|
44
|
-
throw new boom_1.Boom('receipient present, but msg not from me', { data: stanza });
|
|
45
|
-
}
|
|
46
|
-
chatId = recipient;
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
chatId = from;
|
|
50
|
-
}
|
|
51
|
-
msgType = 'chat';
|
|
52
|
-
author = from;
|
|
53
|
-
}
|
|
54
|
-
else if ((0, WABinary_1.isLidUser)(from)) {
|
|
55
|
-
if (recipient) {
|
|
56
|
-
if (!isMeLid(from)) {
|
|
44
|
+
if ((0, WABinary_1.isJidUser)(from) || (0, WABinary_1.isLidUser)(from)) {
|
|
45
|
+
if (recipient && !(0, WABinary_1.isJidMetaAi)(recipient)) {
|
|
46
|
+
if (!isMe(from) && !isMeLid(from)) {
|
|
57
47
|
throw new boom_1.Boom('receipient present, but msg not from me', { data: stanza });
|
|
58
48
|
}
|
|
59
49
|
chatId = recipient;
|
|
@@ -72,6 +62,11 @@ function decodeMessageNode(stanza, meId, meLid) {
|
|
|
72
62
|
author = participant;
|
|
73
63
|
chatId = from;
|
|
74
64
|
}
|
|
65
|
+
else if ((0, WABinary_1.isJidNewsletter)(from)) {
|
|
66
|
+
msgType = 'newsletter';
|
|
67
|
+
author = from;
|
|
68
|
+
chatId = from;
|
|
69
|
+
}
|
|
75
70
|
else if ((0, WABinary_1.isJidBroadcast)(from)) {
|
|
76
71
|
if (!participant) {
|
|
77
72
|
throw new boom_1.Boom('No participant in group message');
|
|
@@ -86,29 +81,20 @@ function decodeMessageNode(stanza, meId, meLid) {
|
|
|
86
81
|
chatId = from;
|
|
87
82
|
author = participant;
|
|
88
83
|
}
|
|
89
|
-
else if ((0, WABinary_1.isJidNewsLetter)(from)) {
|
|
90
|
-
msgType = 'newsletter';
|
|
91
|
-
author = from;
|
|
92
|
-
chatId = from;
|
|
93
|
-
}
|
|
94
84
|
else {
|
|
95
85
|
throw new boom_1.Boom('Unknown message type', { data: stanza });
|
|
96
86
|
}
|
|
97
|
-
const fromMe = (0, WABinary_1.
|
|
98
|
-
const pushname = stanza.attrs.notify;
|
|
87
|
+
const fromMe = (0, WABinary_1.isJidNewsletter)(from) ? !!((_d = stanza.attrs) === null || _d === void 0 ? void 0 : _d.is_sender) || false : ((0, WABinary_1.isLidUser)(from) ? isMeLid : isMe)(stanza.attrs.participant || stanza.attrs.from);
|
|
88
|
+
const pushname = (_e = stanza === null || stanza === void 0 ? void 0 : stanza.attrs) === null || _e === void 0 ? void 0 : _e.notify;
|
|
99
89
|
const key = {
|
|
100
90
|
remoteJid: chatId,
|
|
101
91
|
fromMe,
|
|
102
92
|
id: msgId,
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
},
|
|
109
|
-
...(stanza.attrs.participant_lid ?? participant) !== undefined && {
|
|
110
|
-
participant_lid: fromMe ? meLid : stanza.attrs.participant_lid ?? participant
|
|
111
|
-
}
|
|
93
|
+
senderPn,
|
|
94
|
+
senderLid,
|
|
95
|
+
participant,
|
|
96
|
+
participantLid,
|
|
97
|
+
'server_id': (_f = stanza.attrs) === null || _f === void 0 ? void 0 : _f.server_id
|
|
112
98
|
};
|
|
113
99
|
const fullMessage = {
|
|
114
100
|
key,
|
|
@@ -117,7 +103,7 @@ function decodeMessageNode(stanza, meId, meLid) {
|
|
|
117
103
|
broadcast: (0, WABinary_1.isJidBroadcast)(from)
|
|
118
104
|
};
|
|
119
105
|
if (msgType === 'newsletter') {
|
|
120
|
-
fullMessage.newsletterServerId = +((
|
|
106
|
+
fullMessage.newsletterServerId = +((_g = stanza.attrs) === null || _g === void 0 ? void 0 : _g.server_id);
|
|
121
107
|
}
|
|
122
108
|
if (key.fromMe) {
|
|
123
109
|
fullMessage.status = WAProto_1.proto.WebMessageInfo.Status.SERVER_ACK;
|
|
@@ -137,31 +123,16 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
|
137
123
|
async decrypt() {
|
|
138
124
|
var _a;
|
|
139
125
|
let decryptables = 0;
|
|
140
|
-
if (
|
|
141
|
-
const node = (0, WABinary_1.getBinaryNodeChild)(stanza, 'plaintext');
|
|
142
|
-
const msg = WAProto_1.proto.Message.decode(node === null || node === void 0 ? void 0 : node.content);
|
|
143
|
-
if (msg.senderKeyDistributionMessage) {
|
|
144
|
-
//eslint-disable-next-line max-depth
|
|
145
|
-
try {
|
|
146
|
-
await repository.processSenderKeyDistributionMessage({
|
|
147
|
-
authorJid: author,
|
|
148
|
-
item: msg.senderKeyDistributionMessage
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
catch (err) {
|
|
152
|
-
logger.error({ key: fullMessage.key, err }, 'failed to decrypt message');
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
fullMessage.message = msg;
|
|
156
|
-
decryptables += 1;
|
|
157
|
-
}
|
|
158
|
-
else if (Array.isArray(stanza.content)) {
|
|
126
|
+
if (Array.isArray(stanza.content)) {
|
|
159
127
|
for (const { tag, attrs, content } of stanza.content) {
|
|
160
128
|
if (tag === 'verified_name' && content instanceof Uint8Array) {
|
|
161
129
|
const cert = WAProto_1.proto.VerifiedNameCertificate.decode(content);
|
|
162
130
|
const details = WAProto_1.proto.VerifiedNameCertificate.Details.decode(cert.details);
|
|
163
131
|
fullMessage.verifiedBizName = details.verifiedName;
|
|
164
132
|
}
|
|
133
|
+
if (tag === 'unavailable' && attrs.type === 'view_once') {
|
|
134
|
+
fullMessage.key.isViewOnce = true;
|
|
135
|
+
}
|
|
165
136
|
if (tag !== 'enc' && tag !== 'plaintext') {
|
|
166
137
|
continue;
|
|
167
138
|
}
|
|
@@ -192,13 +163,15 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
|
192
163
|
case 'plaintext':
|
|
193
164
|
msgBuffer = content;
|
|
194
165
|
break;
|
|
166
|
+
case undefined:
|
|
167
|
+
msgBuffer = content;
|
|
168
|
+
break;
|
|
195
169
|
default:
|
|
196
170
|
throw new Error(`Unknown e2e type: ${e2eType}`);
|
|
197
171
|
}
|
|
198
172
|
let msg = WAProto_1.proto.Message.decode(e2eType !== 'plaintext' ? (0, generics_1.unpadRandomMax16)(msgBuffer) : msgBuffer);
|
|
199
|
-
msg = ((_a = msg.deviceSentMessage) === null || _a === void 0 ? void 0 : _a.message) || msg;
|
|
173
|
+
msg = ((_a = msg === null || msg === void 0 ? void 0 : msg.deviceSentMessage) === null || _a === void 0 ? void 0 : _a.message) || msg;
|
|
200
174
|
if (msg.senderKeyDistributionMessage) {
|
|
201
|
-
//eslint-disable-next-line max-depth
|
|
202
175
|
try {
|
|
203
176
|
await repository.processSenderKeyDistributionMessage({
|
|
204
177
|
authorJid: author,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Logger } from 'pino';
|
|
2
1
|
import { BaileysEventEmitter, BaileysEventMap } from '../Types';
|
|
2
|
+
import { ILogger } from './logger';
|
|
3
3
|
/**
|
|
4
4
|
* A map that contains a list of all events that have been triggered
|
|
5
5
|
*
|
|
@@ -31,5 +31,5 @@ type BaileysBufferableEventEmitter = BaileysEventEmitter & {
|
|
|
31
31
|
* making the data processing more efficient.
|
|
32
32
|
* @param ev the baileys event emitter
|
|
33
33
|
*/
|
|
34
|
-
export declare const makeEventBuffer: (logger:
|
|
34
|
+
export declare const makeEventBuffer: (logger: ILogger) => BaileysBufferableEventEmitter;
|
|
35
35
|
export {};
|
|
@@ -502,7 +502,8 @@ function consolidateEvents(data) {
|
|
|
502
502
|
return map;
|
|
503
503
|
}
|
|
504
504
|
function concatChats(a, b) {
|
|
505
|
-
if (b.unreadCount === null &&
|
|
505
|
+
if (b.unreadCount === null && // neutralize unread counter
|
|
506
|
+
a.unreadCount < 0) {
|
|
506
507
|
a.unreadCount = undefined;
|
|
507
508
|
b.unreadCount = undefined;
|
|
508
509
|
}
|
package/lib/Utils/generics.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AxiosRequestConfig } from 'axios';
|
|
2
|
-
import {
|
|
2
|
+
import { ILogger } from './logger';
|
|
3
3
|
import { proto } from '../../WAProto';
|
|
4
|
-
import { BaileysEventEmitter, BaileysEventMap, BrowsersMap,
|
|
4
|
+
import { BaileysEventEmitter, BaileysEventMap, BrowsersMap, WACallUpdateType, WAVersion } from '../Types';
|
|
5
5
|
import { BinaryNode } from '../WABinary';
|
|
6
6
|
export declare const Browsers: BrowsersMap;
|
|
7
7
|
export declare const getPlatformId: (browser: string) => any;
|
|
@@ -10,9 +10,10 @@ export declare const BufferJSON: {
|
|
|
10
10
|
reviver: (_: any, value: any) => any;
|
|
11
11
|
};
|
|
12
12
|
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) =>
|
|
13
|
+
export declare const writeRandomPadMax16: (msg: Uint8Array) => Buffer<ArrayBuffer>;
|
|
14
|
+
export declare const unpadRandomMax16: (e: Uint8Array | Buffer) => Uint8Array<ArrayBuffer>;
|
|
15
|
+
export declare const encodeWAMessage: (message: proto.IMessage) => Buffer<ArrayBuffer>;
|
|
16
|
+
export declare const encodeNewsletterMessage: (message: proto.IMessage) => Uint8Array<ArrayBufferLike>;
|
|
16
17
|
export declare const generateRegistrationId: () => number;
|
|
17
18
|
export declare const encodeBigEndian: (e: number, t?: number) => Uint8Array<ArrayBuffer>;
|
|
18
19
|
export declare const toNumber: (t: Long | number | null | undefined) => number;
|
|
@@ -33,15 +34,15 @@ export declare const delayCancellable: (ms: number) => {
|
|
|
33
34
|
export declare function promiseTimeout<T>(ms: number | undefined, promise: (resolve: (v: T) => void, reject: (error: any) => void) => void): Promise<T>;
|
|
34
35
|
export declare const generateMessageIDV2: (userId?: string) => string;
|
|
35
36
|
export declare const generateMessageID: () => string;
|
|
36
|
-
export declare function bindWaitForEvent<T extends keyof BaileysEventMap>(ev: BaileysEventEmitter, event: T): (check: (u: BaileysEventMap[T]) => boolean | undefined
|
|
37
|
-
export declare const bindWaitForConnectionUpdate: (ev: BaileysEventEmitter) => (check: (u: Partial<ConnectionState>) => boolean | undefined
|
|
38
|
-
export declare const printQRIfNecessaryListener: (ev: BaileysEventEmitter, logger:
|
|
37
|
+
export declare function bindWaitForEvent<T extends keyof BaileysEventMap>(ev: BaileysEventEmitter, event: T): (check: (u: BaileysEventMap[T]) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
|
|
38
|
+
export declare const bindWaitForConnectionUpdate: (ev: BaileysEventEmitter) => (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
|
|
39
|
+
export declare const printQRIfNecessaryListener: (ev: BaileysEventEmitter, logger: ILogger) => void;
|
|
39
40
|
/**
|
|
40
41
|
* utility that fetches latest baileys version from the master branch.
|
|
41
42
|
* Use to ensure your WA connection is always on the latest version
|
|
42
43
|
*/
|
|
43
44
|
export declare const fetchLatestBaileysVersion: (options?: AxiosRequestConfig<any>) => Promise<{
|
|
44
|
-
version:
|
|
45
|
+
version: WAVersion;
|
|
45
46
|
isLatest: boolean;
|
|
46
47
|
error?: undefined;
|
|
47
48
|
} | {
|
|
@@ -53,7 +54,7 @@ export declare const fetchLatestBaileysVersion: (options?: AxiosRequestConfig<an
|
|
|
53
54
|
* A utility that fetches the latest web version of whatsapp.
|
|
54
55
|
* Use to ensure your WA connection is always on the latest version
|
|
55
56
|
*/
|
|
56
|
-
export declare const fetchLatestWaWebVersion: (options: AxiosRequestConfig<
|
|
57
|
+
export declare const fetchLatestWaWebVersion: (options: AxiosRequestConfig<{}>) => Promise<{
|
|
57
58
|
version: WAVersion;
|
|
58
59
|
isLatest: boolean;
|
|
59
60
|
error?: undefined;
|
|
@@ -83,6 +84,6 @@ export declare const getCodeFromWSError: (error: Error) => number;
|
|
|
83
84
|
* Is the given platform WA business
|
|
84
85
|
* @param platform AuthenticationCreds.platform
|
|
85
86
|
*/
|
|
86
|
-
export declare const isWABusinessPlatform: (platform: string) => platform is "
|
|
87
|
+
export declare const isWABusinessPlatform: (platform: string) => platform is "smba" | "smbi";
|
|
87
88
|
export declare function trimUndefined(obj: any): any;
|
|
88
89
|
export declare function bytesToCrockford(buffer: Buffer): string;
|
package/lib/Utils/generics.js
CHANGED
|
@@ -1,9 +1,42 @@
|
|
|
1
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
|
+
})();
|
|
2
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
37
|
};
|
|
5
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.isWABusinessPlatform = exports.getCodeFromWSError = exports.getCallStatusFromNode = exports.getErrorCodeFromStreamError = exports.getStatusFromReceiptType = exports.generateMdTagPrefix = exports.fetchLatestWaWebVersion = exports.fetchLatestBaileysVersion = exports.printQRIfNecessaryListener = exports.bindWaitForConnectionUpdate = exports.generateMessageID = exports.generateMessageIDV2 = exports.delayCancellable = exports.delay = exports.debouncedTimeout = exports.unixTimestampSeconds = exports.toNumber = exports.encodeBigEndian = exports.generateRegistrationId = exports.encodeWAMessage = exports.unpadRandomMax16 = exports.writeRandomPadMax16 = exports.getKeyAuthor = exports.BufferJSON = exports.getPlatformId = exports.Browsers = void 0;
|
|
39
|
+
exports.isWABusinessPlatform = exports.getCodeFromWSError = exports.getCallStatusFromNode = exports.getErrorCodeFromStreamError = exports.getStatusFromReceiptType = exports.generateMdTagPrefix = exports.fetchLatestWaWebVersion = exports.fetchLatestBaileysVersion = exports.printQRIfNecessaryListener = exports.bindWaitForConnectionUpdate = exports.generateMessageID = exports.generateMessageIDV2 = exports.delayCancellable = exports.delay = exports.debouncedTimeout = exports.unixTimestampSeconds = exports.toNumber = exports.encodeBigEndian = exports.generateRegistrationId = exports.encodeNewsletterMessage = exports.encodeWAMessage = exports.unpadRandomMax16 = exports.writeRandomPadMax16 = exports.getKeyAuthor = exports.BufferJSON = exports.getPlatformId = exports.Browsers = void 0;
|
|
7
40
|
exports.promiseTimeout = promiseTimeout;
|
|
8
41
|
exports.bindWaitForEvent = bindWaitForEvent;
|
|
9
42
|
exports.trimUndefined = trimUndefined;
|
|
@@ -37,14 +70,12 @@ exports.Browsers = {
|
|
|
37
70
|
macOS: (browser) => ['Mac OS', browser, '14.4.1'],
|
|
38
71
|
baileys: (browser) => ['Baileys', browser, '6.5.0'],
|
|
39
72
|
windows: (browser) => ['Windows', browser, '10.0.22631'],
|
|
40
|
-
iOS: (browser) => ['iOS', browser, '18.2'],
|
|
41
|
-
linux: (browser) => ['Linux', browser, '6.12.6'],
|
|
42
73
|
/** The appropriate browser based on your OS & release */
|
|
43
74
|
appropriate: (browser) => [PLATFORM_MAP[(0, os_1.platform)()] || 'Ubuntu', browser, (0, os_1.release)()]
|
|
44
75
|
};
|
|
45
76
|
const getPlatformId = (browser) => {
|
|
46
77
|
const platformType = WAProto_1.proto.DeviceProps.PlatformType[browser.toUpperCase()];
|
|
47
|
-
return platformType ? platformType.toString()
|
|
78
|
+
return platformType ? platformType.toString() : '49'; //chrome
|
|
48
79
|
};
|
|
49
80
|
exports.getPlatformId = getPlatformId;
|
|
50
81
|
exports.BufferJSON = {
|
|
@@ -87,6 +118,8 @@ const unpadRandomMax16 = (e) => {
|
|
|
87
118
|
exports.unpadRandomMax16 = unpadRandomMax16;
|
|
88
119
|
const encodeWAMessage = (message) => ((0, exports.writeRandomPadMax16)(WAProto_1.proto.Message.encode(message).finish()));
|
|
89
120
|
exports.encodeWAMessage = encodeWAMessage;
|
|
121
|
+
const encodeNewsletterMessage = (message) => (WAProto_1.proto.Message.encode(message).finish());
|
|
122
|
+
exports.encodeNewsletterMessage = encodeNewsletterMessage;
|
|
90
123
|
const generateRegistrationId = () => {
|
|
91
124
|
return Uint16Array.from((0, crypto_1.randomBytes)(2))[0] & 16383;
|
|
92
125
|
};
|
|
@@ -180,11 +213,11 @@ const generateMessageIDV2 = (userId) => {
|
|
|
180
213
|
const random = (0, crypto_1.randomBytes)(16);
|
|
181
214
|
random.copy(data, 28);
|
|
182
215
|
const hash = (0, crypto_1.createHash)('sha256').update(data).digest();
|
|
183
|
-
return hash.toString('hex').toUpperCase().substring(0,
|
|
216
|
+
return '3EB0' + hash.toString('hex').toUpperCase().substring(0, 18);
|
|
184
217
|
};
|
|
185
218
|
exports.generateMessageIDV2 = generateMessageIDV2;
|
|
186
219
|
// generate a random ID to attach to a message
|
|
187
|
-
const generateMessageID = () => (0, crypto_1.randomBytes)(
|
|
220
|
+
const generateMessageID = () => '3EB0' + (0, crypto_1.randomBytes)(18).toString('hex').toUpperCase();
|
|
188
221
|
exports.generateMessageID = generateMessageID;
|
|
189
222
|
function bindWaitForEvent(ev, event) {
|
|
190
223
|
return async (check, timeoutMs) => {
|
|
@@ -198,8 +231,8 @@ function bindWaitForEvent(ev, event) {
|
|
|
198
231
|
}
|
|
199
232
|
};
|
|
200
233
|
ev.on('connection.update', closeListener);
|
|
201
|
-
listener = (update) => {
|
|
202
|
-
if (check(update)) {
|
|
234
|
+
listener = async (update) => {
|
|
235
|
+
if (await check(update)) {
|
|
203
236
|
resolve();
|
|
204
237
|
}
|
|
205
238
|
};
|
|
@@ -216,8 +249,7 @@ exports.bindWaitForConnectionUpdate = bindWaitForConnectionUpdate;
|
|
|
216
249
|
const printQRIfNecessaryListener = (ev, logger) => {
|
|
217
250
|
ev.on('connection.update', async ({ qr }) => {
|
|
218
251
|
if (qr) {
|
|
219
|
-
const QR = await
|
|
220
|
-
.then(m => m.default || m)
|
|
252
|
+
const QR = await Promise.resolve().then(() => __importStar(require('qrcode-terminal'))).then(m => m.default || m)
|
|
221
253
|
.catch(() => {
|
|
222
254
|
logger.error('QR code terminal not added as dependency');
|
|
223
255
|
});
|
|
@@ -226,44 +258,38 @@ const printQRIfNecessaryListener = (ev, logger) => {
|
|
|
226
258
|
});
|
|
227
259
|
};
|
|
228
260
|
exports.printQRIfNecessaryListener = printQRIfNecessaryListener;
|
|
229
|
-
/**
|
|
230
|
-
* utility that fetches latest baileys version from the master branch.
|
|
231
|
-
* Use to ensure your WA connection is always on the latest version
|
|
232
|
-
*/
|
|
233
261
|
const fetchLatestBaileysVersion = async (options = {}) => {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
responseType: 'json'
|
|
239
|
-
});
|
|
240
|
-
return {
|
|
241
|
-
version: result.data.version,
|
|
242
|
-
isLatest: true
|
|
243
|
-
};
|
|
244
|
-
}
|
|
245
|
-
catch (error) {
|
|
246
|
-
return {
|
|
247
|
-
version: baileys_version_json_1.version,
|
|
248
|
-
isLatest: false,
|
|
249
|
-
error
|
|
250
|
-
};
|
|
251
|
-
}
|
|
262
|
+
return {
|
|
263
|
+
version: baileys_version_json_1.version,
|
|
264
|
+
isLatest: true
|
|
265
|
+
};
|
|
252
266
|
};
|
|
253
267
|
exports.fetchLatestBaileysVersion = fetchLatestBaileysVersion;
|
|
268
|
+
|
|
254
269
|
/**
|
|
255
270
|
* A utility that fetches the latest web version of whatsapp.
|
|
256
271
|
* Use to ensure your WA connection is always on the latest version
|
|
257
272
|
*/
|
|
258
273
|
const fetchLatestWaWebVersion = async (options) => {
|
|
259
274
|
try {
|
|
260
|
-
const
|
|
275
|
+
const { data } = await axios_1.default.get('https://web.whatsapp.com/sw.js', {
|
|
261
276
|
...options,
|
|
262
277
|
responseType: 'json'
|
|
263
278
|
});
|
|
264
|
-
const
|
|
279
|
+
const regex = /\\?"client_revision\\?":\s*(\d+)/;
|
|
280
|
+
const match = data.match(regex);
|
|
281
|
+
if (!(match === null || match === void 0 ? void 0 : match[1])) {
|
|
282
|
+
return {
|
|
283
|
+
version: baileys_version_json_1.version,
|
|
284
|
+
isLatest: false,
|
|
285
|
+
error: {
|
|
286
|
+
message: 'Could not find client revision in the fetched content'
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
const clientRevision = match[1];
|
|
265
291
|
return {
|
|
266
|
-
version: [
|
|
292
|
+
version: [2, 3000, +clientRevision],
|
|
267
293
|
isLatest: true
|
|
268
294
|
};
|
|
269
295
|
}
|
|
@@ -332,7 +358,7 @@ const getCallStatusFromNode = ({ tag, attrs }) => {
|
|
|
332
358
|
status = 'timeout';
|
|
333
359
|
}
|
|
334
360
|
else {
|
|
335
|
-
//fired when accepted/rejected/timeout/caller hangs up
|
|
361
|
+
// fired when accepted/rejected/timeout/caller hangs up
|
|
336
362
|
status = 'terminate';
|
|
337
363
|
}
|
|
338
364
|
break;
|
|
@@ -387,8 +413,8 @@ function bytesToCrockford(buffer) {
|
|
|
387
413
|
let value = 0;
|
|
388
414
|
let bitCount = 0;
|
|
389
415
|
const crockford = [];
|
|
390
|
-
for (
|
|
391
|
-
value = (value << 8) | (
|
|
416
|
+
for (let i = 0; i < buffer.length; i++) {
|
|
417
|
+
value = (value << 8) | (buffer[i] & 0xff);
|
|
392
418
|
bitCount += 8;
|
|
393
419
|
while (bitCount >= 5) {
|
|
394
420
|
crockford.push(CROCKFORD_CHARACTERS.charAt((value >>> (bitCount - 5)) & 31));
|
package/lib/Utils/history.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AxiosRequestConfig } from 'axios';
|
|
2
2
|
import { proto } from '../../WAProto';
|
|
3
3
|
import { Chat, Contact } from '../Types';
|
|
4
|
-
export declare const downloadHistory: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<
|
|
4
|
+
export declare const downloadHistory: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<any>) => Promise<proto.HistorySync>;
|
|
5
5
|
export declare const processHistoryMessage: (item: proto.IHistorySync) => {
|
|
6
6
|
chats: Chat[];
|
|
7
7
|
contacts: Contact[];
|
|
@@ -9,7 +9,7 @@ export declare const processHistoryMessage: (item: proto.IHistorySync) => {
|
|
|
9
9
|
syncType: proto.HistorySync.HistorySyncType;
|
|
10
10
|
progress: number | null | undefined;
|
|
11
11
|
};
|
|
12
|
-
export declare const downloadAndProcessHistorySyncNotification: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<
|
|
12
|
+
export declare const downloadAndProcessHistorySyncNotification: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<any>) => Promise<{
|
|
13
13
|
chats: Chat[];
|
|
14
14
|
contacts: Contact[];
|
|
15
15
|
messages: proto.IWebMessageInfo[];
|
package/lib/Utils/history.js
CHANGED
|
@@ -34,7 +34,7 @@ const processHistoryMessage = (item) => {
|
|
|
34
34
|
case WAProto_1.proto.HistorySync.HistorySyncType.FULL:
|
|
35
35
|
case WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND:
|
|
36
36
|
for (const chat of item.conversations) {
|
|
37
|
-
contacts.push({ id: chat.id, name: chat.name || undefined });
|
|
37
|
+
contacts.push({ id: chat.id, name: chat.name || undefined, lid: chat.lidJid || undefined, jid: (0, WABinary_1.isJidUser)(chat.id) ? chat.id : chat.pnJid });
|
|
38
38
|
const msgs = chat.messages || [];
|
|
39
39
|
delete chat.messages;
|
|
40
40
|
delete chat.archived;
|