@ubedsockets/baileys 1.6.6 → 1.6.8
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/GenerateStatics.sh +4 -3
- package/WAProto/WAProto.proto +511 -1215
- package/WAProto/index.js +131318 -59331
- package/lib/Defaults/index.js +92 -76
- package/lib/Signal/Group/ciphertext-message.js +5 -2
- package/lib/Signal/Group/group-session-builder.js +41 -7
- package/lib/Signal/Group/group_cipher.js +51 -37
- package/lib/Signal/Group/index.js +57 -12
- package/lib/Signal/Group/keyhelper.js +44 -7
- package/lib/Signal/Group/sender-chain-key.js +15 -7
- package/lib/Signal/Group/sender-key-distribution-message.js +11 -8
- package/lib/Signal/Group/sender-key-message.js +12 -9
- package/lib/Signal/Group/sender-key-name.js +5 -2
- package/lib/Signal/Group/sender-key-record.js +21 -9
- package/lib/Signal/Group/sender-key-state.js +42 -27
- package/lib/Signal/Group/sender-message-key.js +7 -4
- package/lib/Signal/libsignal.js +90 -347
- package/lib/Socket/Client/index.js +18 -3
- package/lib/Socket/Client/types.js +6 -4
- package/lib/Socket/Client/websocket.js +78 -21
- package/lib/Socket/business.js +43 -162
- package/lib/Socket/chats.js +249 -571
- package/lib/Socket/groups.js +99 -114
- package/lib/Socket/index.js +9 -11
- package/lib/Socket/messages-recv.js +559 -1277
- package/lib/Socket/messages-send.js +669 -674
- package/lib/Socket/newsletter.js +286 -149
- package/lib/Socket/socket.js +235 -548
- package/lib/Types/Auth.js +2 -2
- package/lib/Types/Call.js +2 -2
- package/lib/Types/Chat.js +4 -8
- package/lib/Types/Contact.js +2 -2
- package/lib/Types/Events.js +2 -2
- package/lib/Types/GroupMetadata.js +2 -2
- package/lib/Types/Label.js +5 -3
- package/lib/Types/LabelAssociation.js +5 -3
- package/lib/Types/Message.js +7 -11
- package/lib/Types/Product.js +2 -2
- package/lib/Types/Signal.js +2 -2
- package/lib/Types/Socket.js +2 -3
- package/lib/Types/State.js +2 -56
- package/lib/Types/USync.js +2 -2
- package/lib/Types/index.js +31 -15
- package/lib/Utils/auth-utils.js +136 -239
- package/lib/Utils/business.js +69 -66
- package/lib/Utils/chat-utils.js +238 -380
- package/lib/Utils/crypto.js +127 -56
- package/lib/Utils/decode-wa-message.js +63 -173
- package/lib/Utils/event-buffer.js +70 -174
- package/lib/Utils/generics.js +207 -159
- package/lib/Utils/history.js +53 -93
- package/lib/Utils/index.js +33 -22
- package/lib/Utils/link-preview.js +58 -17
- package/lib/Utils/logger.js +7 -3
- package/lib/Utils/lt-hash.js +46 -3
- package/lib/Utils/make-mutex.js +34 -24
- package/lib/Utils/messages-media.js +744 -483
- package/lib/Utils/messages.js +621 -411
- package/lib/Utils/noise-handler.js +99 -149
- package/lib/Utils/process-message.js +150 -459
- package/lib/Utils/signal.js +73 -112
- package/lib/Utils/use-multi-file-auth-state.js +27 -23
- package/lib/Utils/validate-connection.js +104 -74
- package/lib/WABinary/constants.js +11 -9
- package/lib/WABinary/decode.js +52 -49
- package/lib/WABinary/encode.js +49 -19
- package/lib/WABinary/generic-utils.js +43 -46
- package/lib/WABinary/index.js +21 -6
- package/lib/WABinary/jid-utils.js +45 -72
- package/lib/WABinary/types.js +2 -2
- package/lib/WAM/BinaryInfo.js +5 -2
- package/lib/WAM/constants.js +11958 -19461
- package/lib/WAM/encode.js +22 -17
- package/lib/WAM/index.js +19 -4
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +13 -33
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +14 -11
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +11 -8
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +13 -9
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +22 -20
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +8 -13
- package/lib/WAUSync/Protocols/index.js +20 -6
- package/lib/WAUSync/USyncQuery.js +35 -44
- package/lib/WAUSync/USyncUser.js +5 -10
- package/lib/WAUSync/index.js +19 -4
- package/lib/index.js +70 -11
- package/package.json +60 -100
- package/engine-requirements.js +0 -10
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SenderKeyMessage = void 0;
|
|
4
|
+
const curve_1 = require("libsignal/src/curve");
|
|
5
|
+
const WAProto_1 = require("../../../WAProto");
|
|
6
|
+
const ciphertext_message_1 = require("./ciphertext-message");
|
|
7
|
+
class SenderKeyMessage extends ciphertext_message_1.CiphertextMessage {
|
|
5
8
|
constructor(keyId, iteration, ciphertext, signatureKey, serialized) {
|
|
6
9
|
super();
|
|
7
10
|
this.SIGNATURE_LENGTH = 64;
|
|
@@ -9,7 +12,7 @@ export class SenderKeyMessage extends CiphertextMessage {
|
|
|
9
12
|
const version = serialized[0];
|
|
10
13
|
const message = serialized.slice(1, serialized.length - this.SIGNATURE_LENGTH);
|
|
11
14
|
const signature = serialized.slice(-1 * this.SIGNATURE_LENGTH);
|
|
12
|
-
const senderKeyMessage = proto.SenderKeyMessage.decode(message).toJSON();
|
|
15
|
+
const senderKeyMessage = WAProto_1.proto.SenderKeyMessage.decode(message).toJSON();
|
|
13
16
|
this.serialized = serialized;
|
|
14
17
|
this.messageVersion = (version & 0xff) >> 4;
|
|
15
18
|
this.keyId = senderKeyMessage.id;
|
|
@@ -23,7 +26,7 @@ export class SenderKeyMessage extends CiphertextMessage {
|
|
|
23
26
|
else {
|
|
24
27
|
const version = (((this.CURRENT_VERSION << 4) | this.CURRENT_VERSION) & 0xff) % 256;
|
|
25
28
|
const ciphertextBuffer = Buffer.from(ciphertext);
|
|
26
|
-
const message = proto.SenderKeyMessage.encode(proto.SenderKeyMessage.create({
|
|
29
|
+
const message = WAProto_1.proto.SenderKeyMessage.encode(WAProto_1.proto.SenderKeyMessage.create({
|
|
27
30
|
id: keyId,
|
|
28
31
|
iteration: iteration,
|
|
29
32
|
ciphertext: ciphertextBuffer
|
|
@@ -49,12 +52,12 @@ export class SenderKeyMessage extends CiphertextMessage {
|
|
|
49
52
|
verifySignature(signatureKey) {
|
|
50
53
|
const part1 = this.serialized.slice(0, this.serialized.length - this.SIGNATURE_LENGTH);
|
|
51
54
|
const part2 = this.serialized.slice(-1 * this.SIGNATURE_LENGTH);
|
|
52
|
-
const res = verifySignature(signatureKey, part1, part2);
|
|
55
|
+
const res = (0, curve_1.verifySignature)(signatureKey, part1, part2);
|
|
53
56
|
if (!res)
|
|
54
57
|
throw new Error('Invalid signature!');
|
|
55
58
|
}
|
|
56
59
|
getSignature(signatureKey, serialized) {
|
|
57
|
-
return Buffer.from(calculateSignature(signatureKey, serialized));
|
|
60
|
+
return Buffer.from((0, curve_1.calculateSignature)(signatureKey, serialized));
|
|
58
61
|
}
|
|
59
62
|
serialize() {
|
|
60
63
|
return this.serialized;
|
|
@@ -63,4 +66,4 @@ export class SenderKeyMessage extends CiphertextMessage {
|
|
|
63
66
|
return 4;
|
|
64
67
|
}
|
|
65
68
|
}
|
|
66
|
-
|
|
69
|
+
exports.SenderKeyMessage = SenderKeyMessage;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SenderKeyName = void 0;
|
|
1
4
|
function isNull(str) {
|
|
2
5
|
return str === null || str === '';
|
|
3
6
|
}
|
|
@@ -19,7 +22,7 @@ function hashCode(strKey) {
|
|
|
19
22
|
}
|
|
20
23
|
return hash;
|
|
21
24
|
}
|
|
22
|
-
|
|
25
|
+
class SenderKeyName {
|
|
23
26
|
constructor(groupId, sender) {
|
|
24
27
|
this.groupId = groupId;
|
|
25
28
|
this.sender = sender;
|
|
@@ -45,4 +48,4 @@ export class SenderKeyName {
|
|
|
45
48
|
return hashCode(this.groupId) ^ hashCode(this.sender.toString());
|
|
46
49
|
}
|
|
47
50
|
}
|
|
48
|
-
|
|
51
|
+
exports.SenderKeyName = SenderKeyName;
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SenderKeyRecord = void 0;
|
|
4
|
+
const generics_1 = require("../../Utils/generics");
|
|
5
|
+
const sender_key_state_1 = require("./sender-key-state");
|
|
6
|
+
class SenderKeyRecord {
|
|
4
7
|
constructor(serialized) {
|
|
5
8
|
this.MAX_STATES = 5;
|
|
6
9
|
this.senderKeyStates = [];
|
|
7
10
|
if (serialized) {
|
|
8
11
|
for (const structure of serialized) {
|
|
9
|
-
this.senderKeyStates.push(new SenderKeyState(null, null, null, null, null, null, structure));
|
|
12
|
+
this.senderKeyStates.push(new sender_key_state_1.SenderKeyState(null, null, null, null, null, null, structure));
|
|
10
13
|
}
|
|
11
14
|
}
|
|
12
15
|
}
|
|
@@ -20,22 +23,31 @@ export class SenderKeyRecord {
|
|
|
20
23
|
return this.senderKeyStates.find(state => state.getKeyId() === keyId);
|
|
21
24
|
}
|
|
22
25
|
addSenderKeyState(id, iteration, chainKey, signatureKey) {
|
|
23
|
-
this.senderKeyStates.push(new SenderKeyState(id, iteration, chainKey, null, signatureKey));
|
|
26
|
+
this.senderKeyStates.push(new sender_key_state_1.SenderKeyState(id, iteration, chainKey, null, signatureKey));
|
|
24
27
|
if (this.senderKeyStates.length > this.MAX_STATES) {
|
|
25
28
|
this.senderKeyStates.shift();
|
|
26
29
|
}
|
|
27
30
|
}
|
|
28
31
|
setSenderKeyState(id, iteration, chainKey, keyPair) {
|
|
29
32
|
this.senderKeyStates.length = 0;
|
|
30
|
-
this.senderKeyStates.push(new SenderKeyState(id, iteration, chainKey, keyPair));
|
|
33
|
+
this.senderKeyStates.push(new sender_key_state_1.SenderKeyState(id, iteration, chainKey, keyPair));
|
|
31
34
|
}
|
|
32
35
|
serialize() {
|
|
33
36
|
return this.senderKeyStates.map(state => state.getStructure());
|
|
34
37
|
}
|
|
35
38
|
static deserialize(data) {
|
|
36
|
-
|
|
37
|
-
|
|
39
|
+
let parsed;
|
|
40
|
+
if (typeof data === 'string') {
|
|
41
|
+
parsed = JSON.parse(data, generics_1.BufferJSON.reviver);
|
|
42
|
+
}
|
|
43
|
+
else if (data instanceof Uint8Array) {
|
|
44
|
+
const str = Buffer.from(data).toString('utf-8');
|
|
45
|
+
parsed = JSON.parse(str, generics_1.BufferJSON.reviver);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
parsed = data;
|
|
49
|
+
}
|
|
38
50
|
return new SenderKeyRecord(parsed);
|
|
39
51
|
}
|
|
40
52
|
}
|
|
41
|
-
|
|
53
|
+
exports.SenderKeyRecord = SenderKeyRecord;
|
|
@@ -1,31 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SenderKeyState = void 0;
|
|
4
|
+
const sender_chain_key_1 = require("./sender-chain-key");
|
|
5
|
+
const sender_message_key_1 = require("./sender-message-key");
|
|
6
|
+
class SenderKeyState {
|
|
4
7
|
constructor(id, iteration, chainKey, signatureKeyPair, signatureKeyPublic, signatureKeyPrivate, senderKeyStateStructure) {
|
|
5
8
|
this.MAX_MESSAGE_KEYS = 2000;
|
|
6
9
|
if (senderKeyStateStructure) {
|
|
7
|
-
this.senderKeyStateStructure =
|
|
8
|
-
...senderKeyStateStructure,
|
|
9
|
-
senderMessageKeys: Array.isArray(senderKeyStateStructure.senderMessageKeys)
|
|
10
|
-
? senderKeyStateStructure.senderMessageKeys
|
|
11
|
-
: []
|
|
12
|
-
};
|
|
10
|
+
this.senderKeyStateStructure = senderKeyStateStructure;
|
|
13
11
|
}
|
|
14
12
|
else {
|
|
15
13
|
if (signatureKeyPair) {
|
|
16
14
|
signatureKeyPublic = signatureKeyPair.public;
|
|
17
15
|
signatureKeyPrivate = signatureKeyPair.private;
|
|
18
16
|
}
|
|
17
|
+
chainKey = typeof chainKey === 'string' ? Buffer.from(chainKey, 'base64') : chainKey;
|
|
18
|
+
const senderChainKeyStructure = {
|
|
19
|
+
iteration: iteration || 0,
|
|
20
|
+
seed: chainKey || Buffer.alloc(0)
|
|
21
|
+
};
|
|
22
|
+
const signingKeyStructure = {
|
|
23
|
+
public: typeof signatureKeyPublic === 'string'
|
|
24
|
+
? Buffer.from(signatureKeyPublic, 'base64')
|
|
25
|
+
: signatureKeyPublic || Buffer.alloc(0)
|
|
26
|
+
};
|
|
27
|
+
if (signatureKeyPrivate) {
|
|
28
|
+
signingKeyStructure.private =
|
|
29
|
+
typeof signatureKeyPrivate === 'string' ? Buffer.from(signatureKeyPrivate, 'base64') : signatureKeyPrivate;
|
|
30
|
+
}
|
|
19
31
|
this.senderKeyStateStructure = {
|
|
20
32
|
senderKeyId: id || 0,
|
|
21
|
-
senderChainKey:
|
|
22
|
-
|
|
23
|
-
seed: Buffer.from(chainKey || [])
|
|
24
|
-
},
|
|
25
|
-
senderSigningKey: {
|
|
26
|
-
public: Buffer.from(signatureKeyPublic || []),
|
|
27
|
-
private: Buffer.from(signatureKeyPrivate || [])
|
|
28
|
-
},
|
|
33
|
+
senderChainKey: senderChainKeyStructure,
|
|
34
|
+
senderSigningKey: signingKeyStructure,
|
|
29
35
|
senderMessageKeys: []
|
|
30
36
|
};
|
|
31
37
|
}
|
|
@@ -34,7 +40,7 @@ export class SenderKeyState {
|
|
|
34
40
|
return this.senderKeyStateStructure.senderKeyId;
|
|
35
41
|
}
|
|
36
42
|
getSenderChainKey() {
|
|
37
|
-
return new SenderChainKey(this.senderKeyStateStructure.senderChainKey.iteration, this.senderKeyStateStructure.senderChainKey.seed);
|
|
43
|
+
return new sender_chain_key_1.SenderChainKey(this.senderKeyStateStructure.senderChainKey.iteration, this.senderKeyStateStructure.senderChainKey.seed);
|
|
38
44
|
}
|
|
39
45
|
setSenderChainKey(chainKey) {
|
|
40
46
|
this.senderKeyStateStructure.senderChainKey = {
|
|
@@ -43,17 +49,26 @@ export class SenderKeyState {
|
|
|
43
49
|
};
|
|
44
50
|
}
|
|
45
51
|
getSigningKeyPublic() {
|
|
46
|
-
const publicKey =
|
|
47
|
-
if (publicKey
|
|
48
|
-
|
|
49
|
-
fixed[0] = 0x05;
|
|
50
|
-
publicKey.copy(fixed, 1);
|
|
51
|
-
return fixed;
|
|
52
|
+
const publicKey = this.senderKeyStateStructure.senderSigningKey.public;
|
|
53
|
+
if (publicKey instanceof Buffer) {
|
|
54
|
+
return publicKey;
|
|
52
55
|
}
|
|
53
|
-
|
|
56
|
+
else if (typeof publicKey === 'string') {
|
|
57
|
+
return Buffer.from(publicKey, 'base64');
|
|
58
|
+
}
|
|
59
|
+
return Buffer.from(publicKey || []);
|
|
54
60
|
}
|
|
55
61
|
getSigningKeyPrivate() {
|
|
56
62
|
const privateKey = this.senderKeyStateStructure.senderSigningKey.private;
|
|
63
|
+
if (!privateKey) {
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
if (privateKey instanceof Buffer) {
|
|
67
|
+
return privateKey;
|
|
68
|
+
}
|
|
69
|
+
else if (typeof privateKey === 'string') {
|
|
70
|
+
return Buffer.from(privateKey, 'base64');
|
|
71
|
+
}
|
|
57
72
|
return Buffer.from(privateKey || []);
|
|
58
73
|
}
|
|
59
74
|
hasSenderMessageKey(iteration) {
|
|
@@ -73,7 +88,7 @@ export class SenderKeyState {
|
|
|
73
88
|
if (index !== -1) {
|
|
74
89
|
const messageKey = this.senderKeyStateStructure.senderMessageKeys[index];
|
|
75
90
|
this.senderKeyStateStructure.senderMessageKeys.splice(index, 1);
|
|
76
|
-
return new SenderMessageKey(messageKey.iteration, messageKey.seed);
|
|
91
|
+
return new sender_message_key_1.SenderMessageKey(messageKey.iteration, messageKey.seed);
|
|
77
92
|
}
|
|
78
93
|
return null;
|
|
79
94
|
}
|
|
@@ -81,4 +96,4 @@ export class SenderKeyState {
|
|
|
81
96
|
return this.senderKeyStateStructure;
|
|
82
97
|
}
|
|
83
98
|
}
|
|
84
|
-
|
|
99
|
+
exports.SenderKeyState = SenderKeyState;
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SenderMessageKey = void 0;
|
|
4
|
+
const crypto_1 = require("libsignal/src/crypto");
|
|
5
|
+
class SenderMessageKey {
|
|
3
6
|
constructor(iteration, seed) {
|
|
4
|
-
const derivative = deriveSecrets(seed, Buffer.alloc(32), Buffer.from('WhisperGroup'));
|
|
7
|
+
const derivative = (0, crypto_1.deriveSecrets)(seed, Buffer.alloc(32), Buffer.from('WhisperGroup'));
|
|
5
8
|
const keys = new Uint8Array(32);
|
|
6
9
|
keys.set(new Uint8Array(derivative[0].slice(16)));
|
|
7
10
|
keys.set(new Uint8Array(derivative[1].slice(0, 16)), 16);
|
|
@@ -23,4 +26,4 @@ export class SenderMessageKey {
|
|
|
23
26
|
return this.seed;
|
|
24
27
|
}
|
|
25
28
|
}
|
|
26
|
-
|
|
29
|
+
exports.SenderMessageKey = SenderMessageKey;
|