@sixcore/baileys 1.0.0 → 1.0.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.js +14270 -302
- package/jessica.js +91 -0
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.js +117 -79
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- 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/business.d.ts +43 -42
- package/lib/Socket/chats.d.ts +222 -36
- package/lib/Socket/chats.js +173 -153
- package/lib/Socket/dugong.d.ts +254 -0
- package/lib/Socket/dugong.js +484 -0
- package/lib/Socket/groups.d.ts +7 -7
- package/lib/Socket/groups.js +37 -35
- package/lib/Socket/index.d.ts +52 -51
- package/lib/Socket/index.js +1 -0
- package/lib/Socket/messages-recv.d.ts +37 -34
- package/lib/Socket/messages-recv.js +175 -37
- package/lib/Socket/messages-send.d.ts +12 -18
- package/lib/Socket/messages-send.js +396 -574
- package/lib/Socket/newsletter.d.ts +28 -26
- package/lib/Socket/newsletter.js +132 -121
- 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 +49 -27
- package/lib/Socket/usync.d.ts +10 -11
- package/lib/Store/make-cache-manager-store.d.ts +1 -2
- package/lib/Store/make-in-memory-store.d.ts +2 -2
- package/lib/Store/make-in-memory-store.js +1 -5
- package/lib/Store/make-ordered-dictionary.js +2 -2
- 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.d.ts +97 -86
- package/lib/Types/Newsletter.js +38 -32
- package/lib/Types/Socket.d.ts +2 -7
- package/lib/Types/index.d.ts +0 -9
- package/lib/Types/index.js +1 -1
- package/lib/Utils/auth-utils.js +14 -35
- 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 +36 -52
- package/lib/Utils/crypto.d.ts +16 -15
- package/lib/Utils/crypto.js +26 -74
- package/lib/Utils/decode-wa-message.d.ts +0 -17
- package/lib/Utils/decode-wa-message.js +17 -53
- package/lib/Utils/event-buffer.js +7 -10
- package/lib/Utils/generics.d.ts +17 -13
- package/lib/Utils/generics.js +79 -58
- 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/lt-hash.js +12 -12
- package/lib/Utils/make-mutex.d.ts +2 -2
- package/lib/Utils/messages-media.d.ts +28 -25
- package/lib/Utils/messages-media.js +733 -557
- package/lib/Utils/messages.js +68 -473
- package/lib/Utils/noise-handler.d.ts +5 -4
- package/lib/Utils/noise-handler.js +14 -19
- package/lib/Utils/process-message.d.ts +5 -5
- package/lib/Utils/process-message.js +23 -75
- package/lib/Utils/signal.d.ts +1 -2
- package/lib/Utils/signal.js +26 -32
- package/lib/Utils/use-multi-file-auth-state.d.ts +1 -0
- package/lib/Utils/use-multi-file-auth-state.js +66 -242
- package/lib/Utils/validate-connection.d.ts +1 -1
- package/lib/Utils/validate-connection.js +88 -64
- package/lib/WABinary/constants.d.ts +27 -24
- package/lib/WABinary/decode.d.ts +2 -1
- package/lib/WABinary/decode.js +11 -23
- package/lib/WABinary/encode.d.ts +2 -1
- package/lib/WABinary/encode.js +147 -134
- package/lib/WABinary/generic-utils.d.ts +5 -2
- package/lib/WABinary/generic-utils.js +125 -37
- 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/USyncUser.d.ts +2 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.js +64 -1
- package/package.json +113 -51
- package/WAProto/GenerateStatics.sh +0 -4
- package/WAProto/WAProto.proto +0 -4357
- package/WAProto/index.d.ts +0 -50383
- package/WASignalGroup/GroupProtocol.js +0 -1697
- package/WASignalGroup/ciphertext_message.js +0 -16
- package/WASignalGroup/generate-proto.sh +0 -1
- package/WASignalGroup/group.proto +0 -42
- 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/Utils/use-single-file-auth-state.d.ts +0 -12
- package/lib/Utils/use-single-file-auth-state.js +0 -75
- package/src/Defaults/baileys-version.json +0 -3
- package/src/Defaults/index.ts +0 -133
- package/src/Signal/Group/ciphertext-message.ts +0 -9
- package/src/Signal/Group/group-session-builder.ts +0 -56
- package/src/Signal/Group/group_cipher.ts +0 -117
- package/src/Signal/Group/index.ts +0 -11
- package/src/Signal/Group/keyhelper.ts +0 -28
- package/src/Signal/Group/sender-chain-key.ts +0 -34
- package/src/Signal/Group/sender-key-distribution-message.ts +0 -95
- package/src/Signal/Group/sender-key-message.ts +0 -96
- package/src/Signal/Group/sender-key-name.ts +0 -66
- package/src/Signal/Group/sender-key-record.ts +0 -69
- package/src/Signal/Group/sender-key-state.ts +0 -134
- package/src/Signal/Group/sender-message-key.ts +0 -36
- package/src/Signal/libsignal.ts +0 -447
- package/src/Signal/lid-mapping.ts +0 -209
- package/src/Socket/Client/index.ts +0 -2
- package/src/Socket/Client/types.ts +0 -22
- package/src/Socket/Client/websocket.ts +0 -56
- package/src/Socket/business.ts +0 -421
- package/src/Socket/chats.ts +0 -1223
- package/src/Socket/communities.ts +0 -477
- package/src/Socket/groups.ts +0 -361
- package/src/Socket/index.ts +0 -22
- package/src/Socket/messages-recv.ts +0 -1563
- package/src/Socket/messages-send.ts +0 -1210
- package/src/Socket/mex.ts +0 -58
- package/src/Socket/newsletter.ts +0 -229
- package/src/Socket/socket.ts +0 -1072
- package/src/Types/Auth.ts +0 -115
- package/src/Types/Bussines.ts +0 -20
- package/src/Types/Call.ts +0 -14
- package/src/Types/Chat.ts +0 -138
- package/src/Types/Contact.ts +0 -24
- package/src/Types/Events.ts +0 -132
- package/src/Types/GroupMetadata.ts +0 -70
- package/src/Types/Label.ts +0 -48
- package/src/Types/LabelAssociation.ts +0 -35
- package/src/Types/Message.ts +0 -424
- package/src/Types/Newsletter.ts +0 -98
- package/src/Types/Product.ts +0 -85
- package/src/Types/Signal.ts +0 -76
- package/src/Types/Socket.ts +0 -150
- package/src/Types/State.ts +0 -43
- package/src/Types/USync.ts +0 -27
- package/src/Types/globals.d.ts +0 -8
- package/src/Types/index.ts +0 -67
- package/src/Utils/auth-utils.ts +0 -331
- package/src/Utils/browser-utils.ts +0 -31
- package/src/Utils/business.ts +0 -286
- package/src/Utils/chat-utils.ts +0 -933
- package/src/Utils/crypto.ts +0 -184
- package/src/Utils/decode-wa-message.ts +0 -355
- package/src/Utils/event-buffer.ts +0 -662
- package/src/Utils/generics.ts +0 -470
- package/src/Utils/history.ts +0 -114
- package/src/Utils/index.ts +0 -18
- package/src/Utils/link-preview.ts +0 -111
- package/src/Utils/logger.ts +0 -13
- package/src/Utils/lt-hash.ts +0 -65
- package/src/Utils/make-mutex.ts +0 -45
- package/src/Utils/message-retry-manager.ts +0 -229
- package/src/Utils/messages-media.ts +0 -820
- package/src/Utils/messages.ts +0 -1137
- package/src/Utils/noise-handler.ts +0 -192
- package/src/Utils/pre-key-manager.ts +0 -126
- package/src/Utils/process-message.ts +0 -622
- package/src/Utils/signal.ts +0 -214
- package/src/Utils/use-multi-file-auth-state.ts +0 -136
- package/src/Utils/validate-connection.ts +0 -253
- package/src/WABinary/constants.ts +0 -1305
- package/src/WABinary/decode.ts +0 -281
- package/src/WABinary/encode.ts +0 -253
- package/src/WABinary/generic-utils.ts +0 -127
- package/src/WABinary/index.ts +0 -5
- package/src/WABinary/jid-utils.ts +0 -128
- package/src/WABinary/types.ts +0 -17
- package/src/WAM/BinaryInfo.ts +0 -12
- package/src/WAM/constants.ts +0 -22889
- package/src/WAM/encode.ts +0 -169
- package/src/WAM/index.ts +0 -3
- package/src/WAUSync/Protocols/USyncContactProtocol.ts +0 -32
- package/src/WAUSync/Protocols/USyncDeviceProtocol.ts +0 -78
- package/src/WAUSync/Protocols/USyncDisappearingModeProtocol.ts +0 -35
- package/src/WAUSync/Protocols/USyncStatusProtocol.ts +0 -44
- package/src/WAUSync/Protocols/UsyncBotProfileProtocol.ts +0 -76
- package/src/WAUSync/Protocols/UsyncLIDProtocol.ts +0 -33
- package/src/WAUSync/Protocols/index.ts +0 -4
- package/src/WAUSync/USyncQuery.ts +0 -133
- package/src/WAUSync/USyncUser.ts +0 -32
- package/src/WAUSync/index.ts +0 -3
- package/src/index.ts +0 -13
package/lib/Utils/crypto.js
CHANGED
|
@@ -15,48 +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
|
-
const
|
|
55
|
-
//const futoin_hkdf_1 = __importDefault(require("futoin-hkdf"));
|
|
31
|
+
const futoin_hkdf_1 = __importDefault(require("futoin-hkdf"));
|
|
56
32
|
const libsignal = __importStar(require("libsignal"));
|
|
57
|
-
const util_1 = require("util");
|
|
58
33
|
const Defaults_1 = require("../Defaults");
|
|
59
|
-
//const pbkdf2Promise = (0, util_1.promisify)(crypto_1.pbkdf2);
|
|
60
34
|
/** prefix version byte to the pub keys, required for some curve crypto functions */
|
|
61
35
|
const generateSignalPubKey = (pubKey) => (pubKey.length === 33
|
|
62
36
|
? pubKey
|
|
@@ -103,6 +77,7 @@ function aesEncryptGCM(plaintext, key, iv, additionalData) {
|
|
|
103
77
|
cipher.setAAD(additionalData);
|
|
104
78
|
return Buffer.concat([cipher.update(plaintext), cipher.final(), cipher.getAuthTag()]);
|
|
105
79
|
}
|
|
80
|
+
exports.aesEncryptGCM = aesEncryptGCM;
|
|
106
81
|
/**
|
|
107
82
|
* decrypt AES 256 GCM;
|
|
108
83
|
* where the auth tag is suffixed to the ciphertext
|
|
@@ -117,83 +92,60 @@ function aesDecryptGCM(ciphertext, key, iv, additionalData) {
|
|
|
117
92
|
decipher.setAuthTag(tag);
|
|
118
93
|
return Buffer.concat([decipher.update(enc), decipher.final()]);
|
|
119
94
|
}
|
|
95
|
+
exports.aesDecryptGCM = aesDecryptGCM;
|
|
120
96
|
function aesEncryptCTR(plaintext, key, iv) {
|
|
121
97
|
const cipher = (0, crypto_1.createCipheriv)('aes-256-ctr', key, iv);
|
|
122
98
|
return Buffer.concat([cipher.update(plaintext), cipher.final()]);
|
|
123
99
|
}
|
|
100
|
+
exports.aesEncryptCTR = aesEncryptCTR;
|
|
124
101
|
function aesDecryptCTR(ciphertext, key, iv) {
|
|
125
102
|
const decipher = (0, crypto_1.createDecipheriv)('aes-256-ctr', key, iv);
|
|
126
103
|
return Buffer.concat([decipher.update(ciphertext), decipher.final()]);
|
|
127
104
|
}
|
|
105
|
+
exports.aesDecryptCTR = aesDecryptCTR;
|
|
128
106
|
/** decrypt AES 256 CBC; where the IV is prefixed to the buffer */
|
|
129
107
|
function aesDecrypt(buffer, key) {
|
|
130
108
|
return aesDecryptWithIV(buffer.slice(16, buffer.length), key, buffer.slice(0, 16));
|
|
131
109
|
}
|
|
110
|
+
exports.aesDecrypt = aesDecrypt;
|
|
132
111
|
/** decrypt AES 256 CBC */
|
|
133
112
|
function aesDecryptWithIV(buffer, key, IV) {
|
|
134
113
|
const aes = (0, crypto_1.createDecipheriv)('aes-256-cbc', key, IV);
|
|
135
114
|
return Buffer.concat([aes.update(buffer), aes.final()]);
|
|
136
115
|
}
|
|
116
|
+
exports.aesDecryptWithIV = aesDecryptWithIV;
|
|
137
117
|
// encrypt AES 256 CBC; where a random IV is prefixed to the buffer
|
|
138
118
|
function aesEncrypt(buffer, key) {
|
|
139
119
|
const IV = (0, crypto_1.randomBytes)(16);
|
|
140
120
|
const aes = (0, crypto_1.createCipheriv)('aes-256-cbc', key, IV);
|
|
141
121
|
return Buffer.concat([IV, aes.update(buffer), aes.final()]); // prefix IV to the buffer
|
|
142
122
|
}
|
|
123
|
+
exports.aesEncrypt = aesEncrypt;
|
|
143
124
|
// encrypt AES 256 CBC with a given IV
|
|
144
125
|
function aesEncrypWithIV(buffer, key, IV) {
|
|
145
126
|
const aes = (0, crypto_1.createCipheriv)('aes-256-cbc', key, IV);
|
|
146
127
|
return Buffer.concat([aes.update(buffer), aes.final()]); // prefix IV to the buffer
|
|
147
128
|
}
|
|
129
|
+
exports.aesEncrypWithIV = aesEncrypWithIV;
|
|
148
130
|
// sign HMAC using SHA 256
|
|
149
131
|
function hmacSign(buffer, key, variant = 'sha256') {
|
|
150
132
|
return (0, crypto_1.createHmac)(variant, key).update(buffer).digest();
|
|
151
133
|
}
|
|
134
|
+
exports.hmacSign = hmacSign;
|
|
152
135
|
function sha256(buffer) {
|
|
153
136
|
return (0, crypto_1.createHash)('sha256').update(buffer).digest();
|
|
154
137
|
}
|
|
138
|
+
exports.sha256 = sha256;
|
|
155
139
|
function md5(buffer) {
|
|
156
140
|
return (0, crypto_1.createHash)('md5').update(buffer).digest();
|
|
157
141
|
}
|
|
142
|
+
exports.md5 = md5;
|
|
158
143
|
// HKDF key expansion
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
const inputKeyMaterial = buffer instanceof Uint8Array
|
|
162
|
-
? buffer
|
|
163
|
-
: new Uint8Array(buffer);
|
|
164
|
-
// Set default values if not provided
|
|
165
|
-
const salt = info.salt ? new Uint8Array(info.salt) : new Uint8Array(0);
|
|
166
|
-
const infoBytes = info.info
|
|
167
|
-
? new TextEncoder().encode(info.info)
|
|
168
|
-
: new Uint8Array(0);
|
|
169
|
-
// Import the input key material
|
|
170
|
-
const importedKey = await crypto_2.subtle.importKey('raw', inputKeyMaterial, { name: 'HKDF' }, false, ['deriveBits']);
|
|
171
|
-
// Derive bits using HKDF
|
|
172
|
-
const derivedBits = await crypto_2.subtle.deriveBits({
|
|
173
|
-
name: 'HKDF',
|
|
174
|
-
hash: 'SHA-256',
|
|
175
|
-
salt: salt,
|
|
176
|
-
info: infoBytes
|
|
177
|
-
}, importedKey, expandedLength * 8 // Convert bytes to bits
|
|
178
|
-
);
|
|
179
|
-
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);
|
|
180
146
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
const pairingCodeBuffer = encoder.encode(pairingCode);
|
|
185
|
-
const saltBuffer = salt instanceof Uint8Array ? salt : new Uint8Array(salt);
|
|
186
|
-
// Import the pairing code as key material
|
|
187
|
-
const keyMaterial = await crypto_2.subtle.importKey('raw', pairingCodeBuffer, { name: 'PBKDF2' }, false, ['deriveBits']);
|
|
188
|
-
// Derive bits using PBKDF2 with the same parameters
|
|
189
|
-
// 2 << 16 = 131,072 iterations
|
|
190
|
-
const derivedBits = await crypto_2.subtle.deriveBits({
|
|
191
|
-
name: 'PBKDF2',
|
|
192
|
-
salt: saltBuffer,
|
|
193
|
-
iterations: 2 << 16,
|
|
194
|
-
hash: 'SHA-256'
|
|
195
|
-
}, keyMaterial, 32 * 8 // 32 bytes * 8 = 256 bits
|
|
196
|
-
);
|
|
197
|
-
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');
|
|
198
150
|
}
|
|
199
|
-
|
|
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
|
|
@@ -94,21 +77,13 @@ function decodeMessageNode(stanza, meId, meLid) {
|
|
|
94
77
|
else {
|
|
95
78
|
throw new boom_1.Boom('Unknown message type', { data: stanza });
|
|
96
79
|
}
|
|
97
|
-
const fromMe = (0, WABinary_1.isJidNewsLetter)(from) ? !!((_a = stanza.attrs) === null || _a === void 0 ? void 0 : _a.is_sender) : ((0, WABinary_1.isLidUser)(
|
|
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);
|
|
98
81
|
const pushname = stanza.attrs.notify;
|
|
99
82
|
const key = {
|
|
100
83
|
remoteJid: chatId,
|
|
101
84
|
fromMe,
|
|
102
85
|
id: msgId,
|
|
103
|
-
|
|
104
|
-
participant: fromMe ? meId : stanza.attrs.participant_pn ?? participant
|
|
105
|
-
},
|
|
106
|
-
...(stanza.attrs.participant_pn ?? participant) !== undefined && {
|
|
107
|
-
participant_pn: fromMe ? meId : stanza.attrs.participant_pn ?? participant
|
|
108
|
-
},
|
|
109
|
-
...(stanza.attrs.participant_lid ?? participant) !== undefined && {
|
|
110
|
-
participant_lid: fromMe ? meLid : stanza.attrs.participant_lid ?? participant
|
|
111
|
-
}
|
|
86
|
+
participant
|
|
112
87
|
};
|
|
113
88
|
const fullMessage = {
|
|
114
89
|
key,
|
|
@@ -128,6 +103,7 @@ function decodeMessageNode(stanza, meId, meLid) {
|
|
|
128
103
|
sender: msgType === 'chat' ? author : chatId
|
|
129
104
|
};
|
|
130
105
|
}
|
|
106
|
+
exports.decodeMessageNode = decodeMessageNode;
|
|
131
107
|
const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
132
108
|
const { fullMessage, author, sender } = decodeMessageNode(stanza, meId, meLid);
|
|
133
109
|
return {
|
|
@@ -137,11 +113,8 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
|
137
113
|
async decrypt() {
|
|
138
114
|
var _a;
|
|
139
115
|
let decryptables = 0;
|
|
140
|
-
|
|
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);
|
|
116
|
+
async function processSenderKeyDistribution(msg) {
|
|
143
117
|
if (msg.senderKeyDistributionMessage) {
|
|
144
|
-
//eslint-disable-next-line max-depth
|
|
145
118
|
try {
|
|
146
119
|
await repository.processSenderKeyDistributionMessage({
|
|
147
120
|
authorJid: author,
|
|
@@ -149,9 +122,14 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
|
149
122
|
});
|
|
150
123
|
}
|
|
151
124
|
catch (err) {
|
|
152
|
-
logger.error({ key: fullMessage.key, err }, 'failed to
|
|
125
|
+
logger.error({ key: fullMessage.key, err }, 'failed to process senderKeyDistribution');
|
|
153
126
|
}
|
|
154
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);
|
|
155
133
|
fullMessage.message = msg;
|
|
156
134
|
decryptables += 1;
|
|
157
135
|
}
|
|
@@ -162,7 +140,7 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
|
162
140
|
const details = WAProto_1.proto.VerifiedNameCertificate.Details.decode(cert.details);
|
|
163
141
|
fullMessage.verifiedBizName = details.verifiedName;
|
|
164
142
|
}
|
|
165
|
-
if (tag !== 'enc'
|
|
143
|
+
if (tag !== 'enc') {
|
|
166
144
|
continue;
|
|
167
145
|
}
|
|
168
146
|
if (!(content instanceof Uint8Array)) {
|
|
@@ -171,7 +149,7 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
|
171
149
|
decryptables += 1;
|
|
172
150
|
let msgBuffer;
|
|
173
151
|
try {
|
|
174
|
-
const e2eType =
|
|
152
|
+
const e2eType = attrs.type;
|
|
175
153
|
switch (e2eType) {
|
|
176
154
|
case 'skmsg':
|
|
177
155
|
msgBuffer = await repository.decryptGroupMessage({
|
|
@@ -189,26 +167,12 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
|
189
167
|
ciphertext: content
|
|
190
168
|
});
|
|
191
169
|
break;
|
|
192
|
-
case 'plaintext':
|
|
193
|
-
msgBuffer = content;
|
|
194
|
-
break;
|
|
195
170
|
default:
|
|
196
171
|
throw new Error(`Unknown e2e type: ${e2eType}`);
|
|
197
172
|
}
|
|
198
|
-
let msg = WAProto_1.proto.Message.decode(
|
|
173
|
+
let msg = WAProto_1.proto.Message.decode((0, generics_1.unpadRandomMax16)(msgBuffer));
|
|
199
174
|
msg = ((_a = msg.deviceSentMessage) === null || _a === void 0 ? void 0 : _a.message) || msg;
|
|
200
|
-
|
|
201
|
-
//eslint-disable-next-line max-depth
|
|
202
|
-
try {
|
|
203
|
-
await repository.processSenderKeyDistributionMessage({
|
|
204
|
-
authorJid: author,
|
|
205
|
-
item: msg.senderKeyDistributionMessage
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
catch (err) {
|
|
209
|
-
logger.error({ key: fullMessage.key, err }, 'failed to decrypt message');
|
|
210
|
-
}
|
|
211
|
-
}
|
|
175
|
+
await processSenderKeyDistribution(msg);
|
|
212
176
|
if (fullMessage.message) {
|
|
213
177
|
Object.assign(fullMessage.message, msg);
|
|
214
178
|
}
|
|
@@ -226,7 +190,7 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
|
226
190
|
// if nothing was found to decrypt
|
|
227
191
|
if (!decryptables) {
|
|
228
192
|
fullMessage.messageStubType = WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT;
|
|
229
|
-
fullMessage.messageStubParameters = [
|
|
193
|
+
fullMessage.messageStubParameters = [NO_MESSAGE_FOUND_ERROR_TEXT, JSON.stringify(stanza, generics_1.BufferJSON.replacer)];
|
|
230
194
|
}
|
|
231
195
|
}
|
|
232
196
|
};
|
|
@@ -176,9 +176,6 @@ function append(data, historyCache, event, eventData, logger) {
|
|
|
176
176
|
}
|
|
177
177
|
}
|
|
178
178
|
data.historySets.empty = false;
|
|
179
|
-
data.historySets.syncType = eventData.syncType;
|
|
180
|
-
data.historySets.progress = eventData.progress;
|
|
181
|
-
data.historySets.peerDataRequestSessionId = eventData.peerDataRequestSessionId;
|
|
182
179
|
data.historySets.isLatest = eventData.isLatest || data.historySets.isLatest;
|
|
183
180
|
break;
|
|
184
181
|
case 'chats.upsert':
|
|
@@ -445,10 +442,7 @@ function consolidateEvents(data) {
|
|
|
445
442
|
chats: Object.values(data.historySets.chats),
|
|
446
443
|
messages: Object.values(data.historySets.messages),
|
|
447
444
|
contacts: Object.values(data.historySets.contacts),
|
|
448
|
-
|
|
449
|
-
progress: data.historySets.progress,
|
|
450
|
-
isLatest: data.historySets.isLatest,
|
|
451
|
-
peerDataRequestSessionId: data.historySets.peerDataRequestSessionId
|
|
445
|
+
isLatest: data.historySets.isLatest
|
|
452
446
|
};
|
|
453
447
|
}
|
|
454
448
|
const chatUpsertList = Object.values(data.chatUpserts);
|
|
@@ -502,9 +496,12 @@ function consolidateEvents(data) {
|
|
|
502
496
|
return map;
|
|
503
497
|
}
|
|
504
498
|
function concatChats(a, b) {
|
|
505
|
-
if (b.unreadCount === null
|
|
506
|
-
|
|
507
|
-
|
|
499
|
+
if (b.unreadCount === null) {
|
|
500
|
+
// neutralize unread counter
|
|
501
|
+
if (a.unreadCount < 0) {
|
|
502
|
+
a.unreadCount = undefined;
|
|
503
|
+
b.unreadCount = undefined;
|
|
504
|
+
}
|
|
508
505
|
}
|
|
509
506
|
if (typeof a.unreadCount === 'number' && typeof b.unreadCount === 'number') {
|
|
510
507
|
b = { ...b };
|
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;
|