@denzy-official/baileys 1.1.1 → 1.1.2
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/WAProto/index.d.ts +55058 -0
- package/WAProto/index.js +169662 -0
- package/WAProto/index.ts.ts +53474 -0
- package/lib/Defaults/index.d.ts +52 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
- package/lib/Signal/Group/group-session-builder.d.ts +15 -0
- package/lib/Signal/Group/group_cipher.d.ts +18 -0
- package/lib/Signal/Group/index.d.ts +12 -0
- package/lib/Signal/Group/keyhelper.d.ts +11 -0
- package/lib/Signal/Group/queue-job.d.ts +2 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
- package/lib/Signal/Group/sender-key-message.d.ts +19 -0
- package/lib/Signal/Group/sender-key-name.d.ts +18 -0
- package/lib/Signal/Group/sender-key-record.d.ts +31 -0
- package/lib/Signal/Group/sender-key-state.d.ts +39 -0
- package/lib/Signal/Group/sender-message-key.d.ts +12 -0
- package/lib/Signal/libsignal.d.ts +4 -0
- package/lib/Socket/Client/abstract-socket-client.d.ts +17 -0
- package/lib/Socket/Client/abstract-socket-client.js +13 -0
- package/lib/Socket/Client/index.d.ts +3 -0
- package/lib/Socket/Client/index.js +3 -3
- package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
- package/lib/Socket/Client/mobile-socket-client.js +65 -0
- package/lib/Socket/Client/types.d.ts +17 -0
- package/lib/Socket/Client/web-socket-client.d.ts +12 -0
- package/lib/Socket/Client/web-socket-client.js +62 -0
- package/lib/Socket/Client/websocket.d.ts +14 -0
- package/lib/Socket/business.d.ts +171 -0
- package/lib/Socket/business.js +0 -1
- package/lib/Socket/chats.d.ts +267 -0
- package/lib/Socket/chats.js +238 -140
- package/lib/Socket/dugong.d.ts +254 -0
- package/lib/Socket/dugong.js +343 -335
- package/lib/Socket/groups.d.ts +115 -0
- package/lib/Socket/groups.js +23 -39
- package/lib/Socket/index.d.ts +173 -0
- package/lib/Socket/index.js +3 -3
- package/lib/Socket/messages-recv.d.ts +161 -0
- package/lib/Socket/messages-recv.js +65 -10
- package/lib/Socket/messages-send.d.ts +149 -0
- package/lib/Socket/messages-send.js +392 -412
- package/lib/Socket/newsletter.d.ts +134 -0
- package/lib/Socket/newsletter.js +124 -72
- package/lib/Socket/registration.d.ts +267 -0
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.d.ts +43 -0
- package/lib/Socket/socket.js +38 -63
- package/lib/Socket/usync.d.ts +36 -0
- package/lib/Socket/usync.js +0 -1
- package/lib/Store/index.d.ts +3 -0
- package/lib/Store/make-in-memory-store.d.ts +119 -0
- package/lib/Store/make-ordered-dictionary.d.ts +14 -0
- package/lib/Store/object-repository.d.ts +11 -0
- package/lib/Types/Auth.d.ts +104 -0
- package/lib/Types/Call.d.ts +14 -0
- package/lib/Types/Chat.d.ts +110 -0
- package/lib/Types/Contact.d.ts +24 -0
- package/lib/Types/Events.d.ts +200 -0
- package/lib/Types/GroupMetadata.d.ts +65 -0
- package/lib/Types/Label.d.ts +36 -0
- package/lib/Types/LabelAssociation.d.ts +30 -0
- package/lib/Types/Message.d.ts +401 -0
- package/lib/Types/Newsletter.d.ts +80 -0
- package/lib/Types/Product.d.ts +78 -0
- package/lib/Types/Signal.d.ts +57 -0
- package/lib/Types/Socket.d.ts +119 -0
- package/lib/Types/State.d.ts +27 -0
- package/lib/Types/USync.d.ts +25 -0
- package/lib/Types/index.d.ts +65 -0
- package/lib/Utils/auth-utils.d.ts +18 -0
- package/lib/Utils/auth-utils.js +13 -8
- package/lib/Utils/baileys-event-stream.d.ts +16 -0
- package/lib/Utils/baileys-event-stream.js +0 -1
- package/lib/Utils/business.d.ts +22 -0
- package/lib/Utils/business.js +2 -3
- package/lib/Utils/chat-utils.d.ts +71 -0
- package/lib/Utils/chat-utils.js +35 -37
- package/lib/Utils/crypto.d.ts +41 -0
- package/lib/Utils/crypto.js +29 -72
- package/lib/Utils/decode-wa-message.d.ts +19 -0
- package/lib/Utils/decode-wa-message.js +56 -66
- package/lib/Utils/event-buffer.d.ts +35 -0
- package/lib/Utils/event-buffer.js +7 -12
- package/lib/Utils/generics.d.ts +92 -0
- package/lib/Utils/generics.js +75 -96
- package/lib/Utils/history.d.ts +15 -0
- package/lib/Utils/history.js +6 -5
- package/lib/Utils/index.d.ts +17 -0
- package/lib/Utils/index.js +0 -1
- package/lib/Utils/link-preview.d.ts +21 -0
- package/lib/Utils/link-preview.js +1 -34
- package/lib/Utils/logger.d.ts +4 -0
- package/lib/Utils/lt-hash.d.ts +12 -0
- package/lib/Utils/lt-hash.js +6 -6
- package/lib/Utils/make-mutex.d.ts +7 -0
- package/lib/Utils/messages-media.d.ts +116 -0
- package/lib/Utils/messages-media.js +235 -296
- package/lib/Utils/messages.d.ts +77 -0
- package/lib/Utils/messages.js +60 -304
- package/lib/Utils/noise-handler.d.ts +21 -0
- package/lib/Utils/noise-handler.js +23 -18
- package/lib/Utils/process-message.d.ts +41 -0
- package/lib/Utils/process-message.js +25 -89
- package/lib/Utils/signal.d.ts +32 -0
- package/lib/Utils/signal.js +26 -26
- package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
- package/lib/Utils/use-multi-file-auth-state.js +6 -51
- package/lib/Utils/validate-connection.d.ts +11 -0
- package/lib/Utils/validate-connection.js +52 -20
- package/lib/WABinary/constants.d.ts +28 -0
- package/lib/WABinary/decode.d.ts +7 -0
- package/lib/WABinary/encode.d.ts +3 -0
- package/lib/WABinary/generic-utils.d.ts +15 -0
- package/lib/WABinary/index.d.ts +6 -0
- package/lib/WABinary/jid-utils.d.ts +37 -0
- package/lib/WABinary/types.d.ts +19 -0
- package/lib/WAM/BinaryInfo.d.ts +9 -0
- package/lib/WAM/constants.d.ts +39 -0
- package/lib/WAM/encode.d.ts +3 -0
- package/lib/WAM/index.d.ts +4 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +25 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +8 -0
- package/lib/WAUSync/Protocols/index.d.ts +4 -0
- package/lib/WAUSync/USyncQuery.d.ts +28 -0
- package/lib/WAUSync/USyncUser.d.ts +12 -0
- package/lib/WAUSync/index.d.ts +3 -0
- package/package.json +1 -1
package/lib/Utils/crypto.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// baileys by denzy
|
|
2
1
|
"use strict";
|
|
3
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
3
|
if (k2 === undefined) k2 = k;
|
|
@@ -16,43 +15,22 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
16
15
|
}) : function(o, v) {
|
|
17
16
|
o["default"] = v;
|
|
18
17
|
});
|
|
19
|
-
var __importStar = (this && this.__importStar) ||
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
if (mod && mod.__esModule) return mod;
|
|
30
|
-
var result = {};
|
|
31
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
-
__setModuleDefault(result, mod);
|
|
33
|
-
return result;
|
|
34
|
-
};
|
|
35
|
-
})();
|
|
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
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
36
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
-
exports.signedKeyPair = exports.Curve = exports.generateSignalPubKey = void 0;
|
|
38
|
-
exports.aesEncryptGCM = aesEncryptGCM;
|
|
39
|
-
exports.aesDecryptGCM = aesDecryptGCM;
|
|
40
|
-
exports.aesEncryptCTR = aesEncryptCTR;
|
|
41
|
-
exports.aesDecryptCTR = aesDecryptCTR;
|
|
42
|
-
exports.aesDecrypt = aesDecrypt;
|
|
43
|
-
exports.aesDecryptWithIV = aesDecryptWithIV;
|
|
44
|
-
exports.aesEncrypt = aesEncrypt;
|
|
45
|
-
exports.aesEncrypWithIV = aesEncrypWithIV;
|
|
46
|
-
exports.hmacSign = hmacSign;
|
|
47
|
-
exports.sha256 = sha256;
|
|
48
|
-
exports.md5 = md5;
|
|
49
|
-
exports.hkdf = hkdf;
|
|
50
|
-
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;
|
|
51
30
|
const crypto_1 = require("crypto");
|
|
31
|
+
const futoin_hkdf_1 = __importDefault(require("futoin-hkdf"));
|
|
52
32
|
const libsignal = __importStar(require("libsignal"));
|
|
53
33
|
const Defaults_1 = require("../Defaults");
|
|
54
|
-
// insure browser & node compatibility
|
|
55
|
-
const { subtle } = globalThis.crypto;
|
|
56
34
|
/** prefix version byte to the pub keys, required for some curve crypto functions */
|
|
57
35
|
const generateSignalPubKey = (pubKey) => (pubKey.length === 33
|
|
58
36
|
? pubKey
|
|
@@ -99,6 +77,7 @@ function aesEncryptGCM(plaintext, key, iv, additionalData) {
|
|
|
99
77
|
cipher.setAAD(additionalData);
|
|
100
78
|
return Buffer.concat([cipher.update(plaintext), cipher.final(), cipher.getAuthTag()]);
|
|
101
79
|
}
|
|
80
|
+
exports.aesEncryptGCM = aesEncryptGCM;
|
|
102
81
|
/**
|
|
103
82
|
* decrypt AES 256 GCM;
|
|
104
83
|
* where the auth tag is suffixed to the ciphertext
|
|
@@ -113,82 +92,60 @@ function aesDecryptGCM(ciphertext, key, iv, additionalData) {
|
|
|
113
92
|
decipher.setAuthTag(tag);
|
|
114
93
|
return Buffer.concat([decipher.update(enc), decipher.final()]);
|
|
115
94
|
}
|
|
95
|
+
exports.aesDecryptGCM = aesDecryptGCM;
|
|
116
96
|
function aesEncryptCTR(plaintext, key, iv) {
|
|
117
97
|
const cipher = (0, crypto_1.createCipheriv)('aes-256-ctr', key, iv);
|
|
118
98
|
return Buffer.concat([cipher.update(plaintext), cipher.final()]);
|
|
119
99
|
}
|
|
100
|
+
exports.aesEncryptCTR = aesEncryptCTR;
|
|
120
101
|
function aesDecryptCTR(ciphertext, key, iv) {
|
|
121
102
|
const decipher = (0, crypto_1.createDecipheriv)('aes-256-ctr', key, iv);
|
|
122
103
|
return Buffer.concat([decipher.update(ciphertext), decipher.final()]);
|
|
123
104
|
}
|
|
105
|
+
exports.aesDecryptCTR = aesDecryptCTR;
|
|
124
106
|
/** decrypt AES 256 CBC; where the IV is prefixed to the buffer */
|
|
125
107
|
function aesDecrypt(buffer, key) {
|
|
126
108
|
return aesDecryptWithIV(buffer.slice(16, buffer.length), key, buffer.slice(0, 16));
|
|
127
109
|
}
|
|
110
|
+
exports.aesDecrypt = aesDecrypt;
|
|
128
111
|
/** decrypt AES 256 CBC */
|
|
129
112
|
function aesDecryptWithIV(buffer, key, IV) {
|
|
130
113
|
const aes = (0, crypto_1.createDecipheriv)('aes-256-cbc', key, IV);
|
|
131
114
|
return Buffer.concat([aes.update(buffer), aes.final()]);
|
|
132
115
|
}
|
|
116
|
+
exports.aesDecryptWithIV = aesDecryptWithIV;
|
|
133
117
|
// encrypt AES 256 CBC; where a random IV is prefixed to the buffer
|
|
134
118
|
function aesEncrypt(buffer, key) {
|
|
135
119
|
const IV = (0, crypto_1.randomBytes)(16);
|
|
136
120
|
const aes = (0, crypto_1.createCipheriv)('aes-256-cbc', key, IV);
|
|
137
121
|
return Buffer.concat([IV, aes.update(buffer), aes.final()]); // prefix IV to the buffer
|
|
138
122
|
}
|
|
123
|
+
exports.aesEncrypt = aesEncrypt;
|
|
139
124
|
// encrypt AES 256 CBC with a given IV
|
|
140
125
|
function aesEncrypWithIV(buffer, key, IV) {
|
|
141
126
|
const aes = (0, crypto_1.createCipheriv)('aes-256-cbc', key, IV);
|
|
142
127
|
return Buffer.concat([aes.update(buffer), aes.final()]); // prefix IV to the buffer
|
|
143
128
|
}
|
|
129
|
+
exports.aesEncrypWithIV = aesEncrypWithIV;
|
|
144
130
|
// sign HMAC using SHA 256
|
|
145
131
|
function hmacSign(buffer, key, variant = 'sha256') {
|
|
146
132
|
return (0, crypto_1.createHmac)(variant, key).update(buffer).digest();
|
|
147
133
|
}
|
|
134
|
+
exports.hmacSign = hmacSign;
|
|
148
135
|
function sha256(buffer) {
|
|
149
136
|
return (0, crypto_1.createHash)('sha256').update(buffer).digest();
|
|
150
137
|
}
|
|
138
|
+
exports.sha256 = sha256;
|
|
151
139
|
function md5(buffer) {
|
|
152
140
|
return (0, crypto_1.createHash)('md5').update(buffer).digest();
|
|
153
141
|
}
|
|
142
|
+
exports.md5 = md5;
|
|
154
143
|
// HKDF key expansion
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
const inputKeyMaterial = buffer instanceof Uint8Array
|
|
158
|
-
? buffer
|
|
159
|
-
: new Uint8Array(buffer);
|
|
160
|
-
// Set default values if not provided
|
|
161
|
-
const salt = info.salt ? new Uint8Array(info.salt) : new Uint8Array(0);
|
|
162
|
-
const infoBytes = info.info
|
|
163
|
-
? new TextEncoder().encode(info.info)
|
|
164
|
-
: new Uint8Array(0);
|
|
165
|
-
// Import the input key material
|
|
166
|
-
const importedKey = await subtle.importKey('raw', inputKeyMaterial, { name: 'HKDF' }, false, ['deriveBits']);
|
|
167
|
-
// Derive bits using HKDF
|
|
168
|
-
const derivedBits = await subtle.deriveBits({
|
|
169
|
-
name: 'HKDF',
|
|
170
|
-
hash: 'SHA-256',
|
|
171
|
-
salt: salt,
|
|
172
|
-
info: infoBytes
|
|
173
|
-
}, importedKey, expandedLength * 8 // Convert bytes to bits
|
|
174
|
-
);
|
|
175
|
-
return Buffer.from(derivedBits);
|
|
144
|
+
function hkdf(buffer, expandedLength, info) {
|
|
145
|
+
return (0, futoin_hkdf_1.default)(!Buffer.isBuffer(buffer) ? Buffer.from(buffer) : buffer, expandedLength, info);
|
|
176
146
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
const pairingCodeBuffer = encoder.encode(pairingCode);
|
|
181
|
-
const saltBuffer = salt instanceof Uint8Array ? salt : new Uint8Array(salt);
|
|
182
|
-
// Import the pairing code as key material
|
|
183
|
-
const keyMaterial = await subtle.importKey('raw', pairingCodeBuffer, { name: 'PBKDF2' }, false, ['deriveBits']);
|
|
184
|
-
// Derive bits using PBKDF2 with the same parameters
|
|
185
|
-
// 2 << 16 = 131,072 iterations
|
|
186
|
-
const derivedBits = await subtle.deriveBits({
|
|
187
|
-
name: 'PBKDF2',
|
|
188
|
-
salt: saltBuffer,
|
|
189
|
-
iterations: 2 << 16,
|
|
190
|
-
hash: 'SHA-256'
|
|
191
|
-
}, keyMaterial, 32 * 8 // 32 bytes * 8 = 256 bits
|
|
192
|
-
);
|
|
193
|
-
return Buffer.from(derivedBits);
|
|
147
|
+
exports.hkdf = hkdf;
|
|
148
|
+
function derivePairingCodeKey(pairingCode, salt) {
|
|
149
|
+
return (0, crypto_1.pbkdf2Sync)(pairingCode, salt, 2 << 16, 32, 'sha256');
|
|
194
150
|
}
|
|
151
|
+
exports.derivePairingCodeKey = derivePairingCodeKey;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Logger } from 'pino';
|
|
2
|
+
import { proto } from '../../WAProto';
|
|
3
|
+
import { SignalRepository } from '../Types';
|
|
4
|
+
import { BinaryNode } from '../WABinary';
|
|
5
|
+
/**
|
|
6
|
+
* Decode the received node as a message.
|
|
7
|
+
* @note this will only parse the message, not decrypt it
|
|
8
|
+
*/
|
|
9
|
+
export declare function decodeMessageNode(stanza: BinaryNode, meId: string, meLid: string): {
|
|
10
|
+
fullMessage: proto.IWebMessageInfo;
|
|
11
|
+
author: string;
|
|
12
|
+
sender: string;
|
|
13
|
+
};
|
|
14
|
+
export declare const decryptMessageNode: (stanza: BinaryNode, meId: string, meLid: string, repository: SignalRepository, logger: Logger) => {
|
|
15
|
+
fullMessage: proto.IWebMessageInfo;
|
|
16
|
+
category: string;
|
|
17
|
+
author: string;
|
|
18
|
+
decrypt(): Promise<void>;
|
|
19
|
+
};
|
|
@@ -1,50 +1,42 @@
|
|
|
1
|
-
// baileys by denzy
|
|
2
1
|
"use strict";
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.decryptMessageNode = exports.
|
|
5
|
-
exports.decodeMessageNode = decodeMessageNode;
|
|
3
|
+
exports.decryptMessageNode = exports.decodeMessageNode = void 0;
|
|
6
4
|
const boom_1 = require("@hapi/boom");
|
|
7
5
|
const WAProto_1 = require("../../WAProto");
|
|
8
6
|
const WABinary_1 = require("../WABinary");
|
|
9
7
|
const generics_1 = require("./generics");
|
|
10
|
-
|
|
11
|
-
exports.MISSING_KEYS_ERROR_TEXT = 'Key used already or never filled';
|
|
12
|
-
exports.NACK_REASONS = {
|
|
13
|
-
ParsingError: 487,
|
|
14
|
-
UnrecognizedStanza: 488,
|
|
15
|
-
UnrecognizedStanzaClass: 489,
|
|
16
|
-
UnrecognizedStanzaType: 490,
|
|
17
|
-
InvalidProtobuf: 491,
|
|
18
|
-
InvalidHostedCompanionStanza: 493,
|
|
19
|
-
MissingMessageSecret: 495,
|
|
20
|
-
SignalErrorOldCounter: 496,
|
|
21
|
-
MessageDeletedOnPeer: 499,
|
|
22
|
-
UnhandledError: 500,
|
|
23
|
-
UnsupportedAdminRevoke: 550,
|
|
24
|
-
UnsupportedLIDGroup: 551,
|
|
25
|
-
DBOperationFailed: 552
|
|
26
|
-
};
|
|
8
|
+
const NO_MESSAGE_FOUND_ERROR_TEXT = 'Message absent from node';
|
|
27
9
|
/**
|
|
28
10
|
* Decode the received node as a message.
|
|
29
11
|
* @note this will only parse the message, not decrypt it
|
|
30
12
|
*/
|
|
31
13
|
function decodeMessageNode(stanza, meId, meLid) {
|
|
32
|
-
var _a, _b
|
|
14
|
+
var _a, _b;
|
|
33
15
|
let msgType;
|
|
34
16
|
let chatId;
|
|
35
17
|
let author;
|
|
36
18
|
const msgId = stanza.attrs.id;
|
|
37
19
|
const from = stanza.attrs.from;
|
|
38
|
-
const senderPn = (_a = stanza === null || stanza === void 0 ? void 0 : stanza.attrs) === null || _a === void 0 ? void 0 : _a.sender_pn;
|
|
39
|
-
const senderLid = (_b = stanza === null || stanza === void 0 ? void 0 : stanza.attrs) === null || _b === void 0 ? void 0 : _b.sender_lid;
|
|
40
20
|
const participant = stanza.attrs.participant;
|
|
41
|
-
const participantLid = (_c = stanza === null || stanza === void 0 ? void 0 : stanza.attrs) === null || _c === void 0 ? void 0 : _c.participant_lid;
|
|
42
21
|
const recipient = stanza.attrs.recipient;
|
|
43
22
|
const isMe = (jid) => (0, WABinary_1.areJidsSameUser)(jid, meId);
|
|
44
23
|
const isMeLid = (jid) => (0, WABinary_1.areJidsSameUser)(jid, meLid);
|
|
45
|
-
if ((0, WABinary_1.isJidUser)(from)
|
|
46
|
-
if (recipient
|
|
47
|
-
if (!isMe(from)
|
|
24
|
+
if ((0, WABinary_1.isJidUser)(from)) {
|
|
25
|
+
if (recipient) {
|
|
26
|
+
if (!isMe(from)) {
|
|
27
|
+
throw new boom_1.Boom('receipient present, but msg not from me', { data: stanza });
|
|
28
|
+
}
|
|
29
|
+
chatId = recipient;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
chatId = from;
|
|
33
|
+
}
|
|
34
|
+
msgType = 'chat';
|
|
35
|
+
author = from;
|
|
36
|
+
}
|
|
37
|
+
else if ((0, WABinary_1.isLidUser)(from)) {
|
|
38
|
+
if (recipient) {
|
|
39
|
+
if (!isMeLid(from)) {
|
|
48
40
|
throw new boom_1.Boom('receipient present, but msg not from me', { data: stanza });
|
|
49
41
|
}
|
|
50
42
|
chatId = recipient;
|
|
@@ -63,11 +55,6 @@ function decodeMessageNode(stanza, meId, meLid) {
|
|
|
63
55
|
author = participant;
|
|
64
56
|
chatId = from;
|
|
65
57
|
}
|
|
66
|
-
else if ((0, WABinary_1.isJidNewsletter)(from)) {
|
|
67
|
-
msgType = 'newsletter';
|
|
68
|
-
author = from;
|
|
69
|
-
chatId = from;
|
|
70
|
-
}
|
|
71
58
|
else if ((0, WABinary_1.isJidBroadcast)(from)) {
|
|
72
59
|
if (!participant) {
|
|
73
60
|
throw new boom_1.Boom('No participant in group message');
|
|
@@ -82,20 +69,21 @@ function decodeMessageNode(stanza, meId, meLid) {
|
|
|
82
69
|
chatId = from;
|
|
83
70
|
author = participant;
|
|
84
71
|
}
|
|
72
|
+
else if ((0, WABinary_1.isJidNewsLetter)(from)) {
|
|
73
|
+
msgType = 'newsletter';
|
|
74
|
+
author = from;
|
|
75
|
+
chatId = from;
|
|
76
|
+
}
|
|
85
77
|
else {
|
|
86
78
|
throw new boom_1.Boom('Unknown message type', { data: stanza });
|
|
87
79
|
}
|
|
88
|
-
const fromMe = (0, WABinary_1.
|
|
89
|
-
const pushname =
|
|
80
|
+
const fromMe = (0, WABinary_1.isJidNewsLetter)(from) ? !!((_a = stanza.attrs) === null || _a === void 0 ? void 0 : _a.is_sender) : ((0, WABinary_1.isLidUser)(from) ? isMeLid : isMe)(stanza.attrs.participant || stanza.attrs.from);
|
|
81
|
+
const pushname = stanza.attrs.notify;
|
|
90
82
|
const key = {
|
|
91
83
|
remoteJid: chatId,
|
|
92
84
|
fromMe,
|
|
93
85
|
id: msgId,
|
|
94
|
-
|
|
95
|
-
senderLid,
|
|
96
|
-
participant,
|
|
97
|
-
participantLid,
|
|
98
|
-
'server_id': (_f = stanza.attrs) === null || _f === void 0 ? void 0 : _f.server_id
|
|
86
|
+
participant
|
|
99
87
|
};
|
|
100
88
|
const fullMessage = {
|
|
101
89
|
key,
|
|
@@ -104,7 +92,7 @@ function decodeMessageNode(stanza, meId, meLid) {
|
|
|
104
92
|
broadcast: (0, WABinary_1.isJidBroadcast)(from)
|
|
105
93
|
};
|
|
106
94
|
if (msgType === 'newsletter') {
|
|
107
|
-
fullMessage.newsletterServerId = +((
|
|
95
|
+
fullMessage.newsletterServerId = +((_b = stanza.attrs) === null || _b === void 0 ? void 0 : _b.server_id);
|
|
108
96
|
}
|
|
109
97
|
if (key.fromMe) {
|
|
110
98
|
fullMessage.status = WAProto_1.proto.WebMessageInfo.Status.SERVER_ACK;
|
|
@@ -115,6 +103,7 @@ function decodeMessageNode(stanza, meId, meLid) {
|
|
|
115
103
|
sender: msgType === 'chat' ? author : chatId
|
|
116
104
|
};
|
|
117
105
|
}
|
|
106
|
+
exports.decodeMessageNode = decodeMessageNode;
|
|
118
107
|
const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
119
108
|
const { fullMessage, author, sender } = decodeMessageNode(stanza, meId, meLid);
|
|
120
109
|
return {
|
|
@@ -124,17 +113,34 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
|
124
113
|
async decrypt() {
|
|
125
114
|
var _a;
|
|
126
115
|
let decryptables = 0;
|
|
127
|
-
|
|
116
|
+
async function processSenderKeyDistribution(msg) {
|
|
117
|
+
if (msg.senderKeyDistributionMessage) {
|
|
118
|
+
try {
|
|
119
|
+
await repository.processSenderKeyDistributionMessage({
|
|
120
|
+
authorJid: author,
|
|
121
|
+
item: msg.senderKeyDistributionMessage
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
catch (err) {
|
|
125
|
+
logger.error({ key: fullMessage.key, err }, 'failed to process senderKeyDistribution');
|
|
126
|
+
}
|
|
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);
|
|
133
|
+
fullMessage.message = msg;
|
|
134
|
+
decryptables += 1;
|
|
135
|
+
}
|
|
136
|
+
else if (Array.isArray(stanza.content)) {
|
|
128
137
|
for (const { tag, attrs, content } of stanza.content) {
|
|
129
138
|
if (tag === 'verified_name' && content instanceof Uint8Array) {
|
|
130
139
|
const cert = WAProto_1.proto.VerifiedNameCertificate.decode(content);
|
|
131
140
|
const details = WAProto_1.proto.VerifiedNameCertificate.Details.decode(cert.details);
|
|
132
141
|
fullMessage.verifiedBizName = details.verifiedName;
|
|
133
142
|
}
|
|
134
|
-
if (tag
|
|
135
|
-
fullMessage.key.isViewOnce = true;
|
|
136
|
-
}
|
|
137
|
-
if (tag !== 'enc' && tag !== 'plaintext') {
|
|
143
|
+
if (tag !== 'enc') {
|
|
138
144
|
continue;
|
|
139
145
|
}
|
|
140
146
|
if (!(content instanceof Uint8Array)) {
|
|
@@ -143,7 +149,7 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
|
143
149
|
decryptables += 1;
|
|
144
150
|
let msgBuffer;
|
|
145
151
|
try {
|
|
146
|
-
const e2eType =
|
|
152
|
+
const e2eType = attrs.type;
|
|
147
153
|
switch (e2eType) {
|
|
148
154
|
case 'skmsg':
|
|
149
155
|
msgBuffer = await repository.decryptGroupMessage({
|
|
@@ -161,28 +167,12 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
|
161
167
|
ciphertext: content
|
|
162
168
|
});
|
|
163
169
|
break;
|
|
164
|
-
case 'plaintext':
|
|
165
|
-
msgBuffer = content;
|
|
166
|
-
break;
|
|
167
|
-
case undefined:
|
|
168
|
-
msgBuffer = content;
|
|
169
|
-
break;
|
|
170
170
|
default:
|
|
171
171
|
throw new Error(`Unknown e2e type: ${e2eType}`);
|
|
172
172
|
}
|
|
173
|
-
let msg = WAProto_1.proto.Message.decode(
|
|
174
|
-
msg = ((_a = msg
|
|
175
|
-
|
|
176
|
-
try {
|
|
177
|
-
await repository.processSenderKeyDistributionMessage({
|
|
178
|
-
authorJid: author,
|
|
179
|
-
item: msg.senderKeyDistributionMessage
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
catch (err) {
|
|
183
|
-
logger.error({ key: fullMessage.key, err }, 'failed to decrypt message');
|
|
184
|
-
}
|
|
185
|
-
}
|
|
173
|
+
let msg = WAProto_1.proto.Message.decode((0, generics_1.unpadRandomMax16)(msgBuffer));
|
|
174
|
+
msg = ((_a = msg.deviceSentMessage) === null || _a === void 0 ? void 0 : _a.message) || msg;
|
|
175
|
+
await processSenderKeyDistribution(msg);
|
|
186
176
|
if (fullMessage.message) {
|
|
187
177
|
Object.assign(fullMessage.message, msg);
|
|
188
178
|
}
|
|
@@ -200,7 +190,7 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
|
200
190
|
// if nothing was found to decrypt
|
|
201
191
|
if (!decryptables) {
|
|
202
192
|
fullMessage.messageStubType = WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT;
|
|
203
|
-
fullMessage.messageStubParameters = [
|
|
193
|
+
fullMessage.messageStubParameters = [NO_MESSAGE_FOUND_ERROR_TEXT, JSON.stringify(stanza, generics_1.BufferJSON.replacer)];
|
|
204
194
|
}
|
|
205
195
|
}
|
|
206
196
|
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Logger } from 'pino';
|
|
2
|
+
import { BaileysEventEmitter, BaileysEventMap } from '../Types';
|
|
3
|
+
/**
|
|
4
|
+
* A map that contains a list of all events that have been triggered
|
|
5
|
+
*
|
|
6
|
+
* Note, this can contain different type of events
|
|
7
|
+
* this can make processing events extremely efficient -- since everything
|
|
8
|
+
* can be done in a single transaction
|
|
9
|
+
*/
|
|
10
|
+
type BaileysEventData = Partial<BaileysEventMap>;
|
|
11
|
+
type BaileysBufferableEventEmitter = BaileysEventEmitter & {
|
|
12
|
+
/** Use to process events in a batch */
|
|
13
|
+
process(handler: (events: BaileysEventData) => void | Promise<void>): (() => void);
|
|
14
|
+
/**
|
|
15
|
+
* starts buffering events, call flush() to release them
|
|
16
|
+
* */
|
|
17
|
+
buffer(): void;
|
|
18
|
+
/** buffers all events till the promise completes */
|
|
19
|
+
createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): ((...args: A) => Promise<T>);
|
|
20
|
+
/**
|
|
21
|
+
* flushes all buffered events
|
|
22
|
+
* @param force if true, will flush all data regardless of any pending buffers
|
|
23
|
+
* @returns returns true if the flush actually happened, otherwise false
|
|
24
|
+
*/
|
|
25
|
+
flush(force?: boolean): boolean;
|
|
26
|
+
/** is there an ongoing buffer */
|
|
27
|
+
isBuffering(): boolean;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* The event buffer logically consolidates different events into a single event
|
|
31
|
+
* making the data processing more efficient.
|
|
32
|
+
* @param ev the baileys event emitter
|
|
33
|
+
*/
|
|
34
|
+
export declare const makeEventBuffer: (logger: Logger) => BaileysBufferableEventEmitter;
|
|
35
|
+
export {};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// baileys by denzy
|
|
2
1
|
"use strict";
|
|
3
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
@@ -177,9 +176,6 @@ function append(data, historyCache, event, eventData, logger) {
|
|
|
177
176
|
}
|
|
178
177
|
}
|
|
179
178
|
data.historySets.empty = false;
|
|
180
|
-
data.historySets.syncType = eventData.syncType;
|
|
181
|
-
data.historySets.progress = eventData.progress;
|
|
182
|
-
data.historySets.peerDataRequestSessionId = eventData.peerDataRequestSessionId;
|
|
183
179
|
data.historySets.isLatest = eventData.isLatest || data.historySets.isLatest;
|
|
184
180
|
break;
|
|
185
181
|
case 'chats.upsert':
|
|
@@ -446,10 +442,7 @@ function consolidateEvents(data) {
|
|
|
446
442
|
chats: Object.values(data.historySets.chats),
|
|
447
443
|
messages: Object.values(data.historySets.messages),
|
|
448
444
|
contacts: Object.values(data.historySets.contacts),
|
|
449
|
-
|
|
450
|
-
progress: data.historySets.progress,
|
|
451
|
-
isLatest: data.historySets.isLatest,
|
|
452
|
-
peerDataRequestSessionId: data.historySets.peerDataRequestSessionId
|
|
445
|
+
isLatest: data.historySets.isLatest
|
|
453
446
|
};
|
|
454
447
|
}
|
|
455
448
|
const chatUpsertList = Object.values(data.chatUpserts);
|
|
@@ -503,10 +496,12 @@ function consolidateEvents(data) {
|
|
|
503
496
|
return map;
|
|
504
497
|
}
|
|
505
498
|
function concatChats(a, b) {
|
|
506
|
-
if (b.unreadCount === null
|
|
507
|
-
|
|
508
|
-
a.unreadCount
|
|
509
|
-
|
|
499
|
+
if (b.unreadCount === null) {
|
|
500
|
+
// neutralize unread counter
|
|
501
|
+
if (a.unreadCount < 0) {
|
|
502
|
+
a.unreadCount = undefined;
|
|
503
|
+
b.unreadCount = undefined;
|
|
504
|
+
}
|
|
510
505
|
}
|
|
511
506
|
if (typeof a.unreadCount === 'number' && typeof b.unreadCount === 'number') {
|
|
512
507
|
b = { ...b };
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { AxiosRequestConfig } from 'axios';
|
|
3
|
+
import { Logger } from 'pino';
|
|
4
|
+
import { proto } from '../../WAProto';
|
|
5
|
+
import { BaileysEventEmitter, BaileysEventMap, WACallUpdateType, WAVersion } from '../Types';
|
|
6
|
+
import { BinaryNode } from '../WABinary';
|
|
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];
|
|
14
|
+
};
|
|
15
|
+
export declare const getPlatformId: (browser: string) => any;
|
|
16
|
+
export declare const getKeyAuthor: (key: proto.IMessageKey | undefined | null, meId?: string) => string;
|
|
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;
|
|
20
|
+
export declare const generateRegistrationId: () => number;
|
|
21
|
+
export declare const encodeBigEndian: (e: number, t?: number) => Uint8Array;
|
|
22
|
+
export declare const toNumber: (t: Long | number | null | undefined) => number;
|
|
23
|
+
/** unix timestamp of a date in seconds */
|
|
24
|
+
export declare const unixTimestampSeconds: (date?: Date) => number;
|
|
25
|
+
export type DebouncedTimeout = ReturnType<typeof debouncedTimeout>;
|
|
26
|
+
export declare const debouncedTimeout: (intervalMs?: number, task?: () => void) => {
|
|
27
|
+
start: (newIntervalMs?: number, newTask?: () => void) => void;
|
|
28
|
+
cancel: () => void;
|
|
29
|
+
setTask: (newTask: () => void) => () => void;
|
|
30
|
+
setInterval: (newInterval: number) => number;
|
|
31
|
+
};
|
|
32
|
+
export declare const delay: (ms: number) => Promise<void>;
|
|
33
|
+
export declare const delayCancellable: (ms: number) => {
|
|
34
|
+
delay: Promise<void>;
|
|
35
|
+
cancel: () => void;
|
|
36
|
+
};
|
|
37
|
+
export declare function promiseTimeout<T>(ms: number | undefined, promise: (resolve: (v: T) => void, reject: (error: any) => void) => void): Promise<T>;
|
|
38
|
+
export declare const generateMessageIDV2: (userId?: string) => string;
|
|
39
|
+
export declare const generateMessageID: () => string;
|
|
40
|
+
export declare function bindWaitForEvent<T extends keyof BaileysEventMap>(ev: BaileysEventEmitter, event: T): (check: (u: BaileysEventMap[T]) => 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>;
|
|
42
|
+
export declare const printQRIfNecessaryListener: (ev: BaileysEventEmitter, logger: Logger) => void;
|
|
43
|
+
/**
|
|
44
|
+
* utility that fetches latest baileys version from the master branch.
|
|
45
|
+
* Use to ensure your WA connection is always on the latest version
|
|
46
|
+
*/
|
|
47
|
+
export declare const fetchLatestBaileysVersion: (options?: AxiosRequestConfig<any>) => Promise<{
|
|
48
|
+
version: WAVersion;
|
|
49
|
+
isLatest: boolean;
|
|
50
|
+
error?: undefined;
|
|
51
|
+
} | {
|
|
52
|
+
version: WAVersion;
|
|
53
|
+
isLatest: boolean;
|
|
54
|
+
error: any;
|
|
55
|
+
}>;
|
|
56
|
+
/**
|
|
57
|
+
* A utility that fetches the latest web version of whatsapp.
|
|
58
|
+
* Use to ensure your WA connection is always on the latest version
|
|
59
|
+
*/
|
|
60
|
+
export declare const fetchLatestWaWebVersion: (options: AxiosRequestConfig<any>) => Promise<{
|
|
61
|
+
version: WAVersion;
|
|
62
|
+
isLatest: boolean;
|
|
63
|
+
error?: undefined;
|
|
64
|
+
} | {
|
|
65
|
+
version: WAVersion;
|
|
66
|
+
isLatest: boolean;
|
|
67
|
+
error: any;
|
|
68
|
+
}>;
|
|
69
|
+
/** unique message tag prefix for MD clients */
|
|
70
|
+
export declare const generateMdTagPrefix: () => string;
|
|
71
|
+
/**
|
|
72
|
+
* Given a type of receipt, returns what the new status of the message should be
|
|
73
|
+
* @param type type from receipt
|
|
74
|
+
*/
|
|
75
|
+
export declare const getStatusFromReceiptType: (type: string | undefined) => proto.WebMessageInfo.Status;
|
|
76
|
+
/**
|
|
77
|
+
* Stream errors generally provide a reason, map that to a baileys DisconnectReason
|
|
78
|
+
* @param reason the string reason given, eg. "conflict"
|
|
79
|
+
*/
|
|
80
|
+
export declare const getErrorCodeFromStreamError: (node: BinaryNode) => {
|
|
81
|
+
reason: string;
|
|
82
|
+
statusCode: number;
|
|
83
|
+
};
|
|
84
|
+
export declare const getCallStatusFromNode: ({ tag, attrs }: BinaryNode) => WACallUpdateType;
|
|
85
|
+
export declare const getCodeFromWSError: (error: Error) => number;
|
|
86
|
+
/**
|
|
87
|
+
* Is the given platform WA business
|
|
88
|
+
* @param platform AuthenticationCreds.platform
|
|
89
|
+
*/
|
|
90
|
+
export declare const isWABusinessPlatform: (platform: string) => boolean;
|
|
91
|
+
export declare function trimUndefined(obj: any): any;
|
|
92
|
+
export declare function bytesToCrockford(buffer: Buffer): string;
|