@baileys-md/baileys 12.0.0 → 12.2.0
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 -13
- package/WAProto/WAProto.proto +769 -233
- package/WAProto/index.js +65813 -141372
- package/lib/Defaults/index.js +128 -113
- package/lib/KeyDB/BinarySearch.js +30 -0
- package/lib/KeyDB/KeyedDB.js +178 -0
- package/lib/KeyDB/index.js +14 -0
- package/lib/Signal/Group/ciphertext-message.js +22 -14
- package/lib/Signal/Group/group-session-builder.js +21 -42
- package/lib/Signal/Group/group_cipher.js +85 -87
- package/lib/Signal/Group/index.js +23 -57
- package/lib/Signal/Group/keyhelper.js +28 -52
- package/lib/Signal/Group/sender-chain-key.js +37 -33
- package/lib/Signal/Group/sender-key-distribution-message.js +73 -63
- package/lib/Signal/Group/sender-key-message.js +75 -66
- package/lib/Signal/Group/sender-key-name.js +55 -44
- package/lib/Signal/Group/sender-key-record.js +49 -49
- package/lib/Signal/Group/sender-key-state.js +90 -93
- package/lib/Signal/Group/sender-message-key.js +37 -28
- package/lib/Signal/libsignal.js +324 -163
- package/lib/Signal/lid-mapping.js +166 -0
- package/lib/Socket/Client/index.js +14 -18
- package/lib/Socket/Client/types.js +12 -12
- package/lib/Socket/Client/websocket.js +60 -109
- package/lib/Socket/business.js +359 -242
- package/lib/Socket/chats.js +857 -898
- package/lib/Socket/communities.js +413 -0
- package/lib/Socket/groups.js +304 -324
- package/lib/Socket/index.js +25 -9
- package/lib/Socket/messages-recv.js +1109 -1000
- package/lib/Socket/messages-send.js +615 -387
- package/lib/Socket/mex.js +45 -0
- package/lib/Socket/newsletter.js +231 -227
- package/lib/Socket/socket.js +803 -628
- package/lib/Store/index.js +18 -8
- package/lib/Store/make-cache-manager-store.js +75 -0
- package/lib/Store/make-in-memory-store.js +286 -435
- package/lib/Store/make-ordered-dictionary.js +77 -79
- package/lib/Store/object-repository.js +24 -26
- package/lib/Types/Auth.js +13 -2
- package/lib/Types/Bussines.js +13 -0
- package/lib/Types/Call.js +13 -2
- package/lib/Types/Chat.js +19 -4
- package/lib/Types/Contact.js +13 -2
- package/lib/Types/Events.js +13 -2
- package/lib/Types/GroupMetadata.js +13 -2
- package/lib/Types/Label.js +43 -26
- package/lib/Types/LabelAssociation.js +16 -8
- package/lib/Types/Message.js +22 -7
- package/lib/Types/Newsletter.js +42 -17
- package/lib/Types/Product.js +13 -2
- package/lib/Types/Signal.js +13 -2
- package/lib/Types/Socket.js +14 -2
- package/lib/Types/State.js +21 -2
- package/lib/Types/USync.js +13 -2
- package/lib/Types/index.js +37 -41
- package/lib/Utils/auth-utils.js +219 -189
- package/lib/Utils/baileys-event-stream.js +54 -0
- package/lib/Utils/browser-utils.js +21 -31
- package/lib/Utils/business.js +213 -214
- package/lib/Utils/chat-utils.js +711 -689
- package/lib/Utils/crypto.js +112 -175
- package/lib/Utils/decode-wa-message.js +254 -194
- package/lib/Utils/event-buffer.js +510 -500
- package/lib/Utils/generics.js +318 -430
- package/lib/Utils/history.js +83 -90
- package/lib/Utils/index.js +31 -35
- package/lib/Utils/link-preview.js +71 -116
- package/lib/Utils/logger.js +5 -7
- package/lib/Utils/lt-hash.js +40 -46
- package/lib/Utils/make-mutex.js +34 -41
- package/lib/Utils/message-retry-manager.js +33 -48
- package/lib/Utils/messages-media.js +516 -784
- package/lib/Utils/messages.js +347 -489
- package/lib/Utils/noise-handler.js +138 -144
- package/lib/Utils/pre-key-manager.js +95 -0
- package/lib/Utils/process-message.js +331 -384
- package/lib/Utils/signal.js +157 -139
- package/lib/Utils/use-multi-file-auth-state.js +119 -91
- package/lib/Utils/validate-connection.js +184 -203
- package/lib/WABinary/constants.js +1308 -1298
- package/lib/WABinary/decode.js +241 -256
- package/lib/WABinary/encode.js +217 -239
- package/lib/WABinary/generic-utils.js +131 -40
- package/lib/WABinary/index.js +17 -21
- package/lib/WABinary/jid-utils.js +97 -79
- package/lib/WABinary/types.js +13 -2
- package/lib/WAM/BinaryInfo.js +20 -12
- package/lib/WAM/constants.js +22863 -15348
- package/lib/WAM/encode.js +145 -136
- package/lib/WAM/index.js +15 -19
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +39 -31
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +61 -54
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +39 -29
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +48 -40
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +62 -51
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +38 -21
- package/lib/WAUSync/Protocols/index.js +17 -20
- package/lib/WAUSync/USyncQuery.js +98 -86
- package/lib/WAUSync/USyncUser.js +35 -26
- package/lib/WAUSync/index.js +16 -19
- package/lib/index.js +23 -41
- package/package.json +46 -56
- package/README.md +0 -113
- package/WAProto/GenerateStatics.sh +0 -4
- package/lib/Defaults/wileys-version.json +0 -3
- package/lib/Signal/Group/queue-job.js +0 -57
- package/lib/Socket/usync.js +0 -70
- package/lib/Utils/wileys-event-stream.js +0 -63
|
@@ -1,69 +1,78 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
this.serialized = Buffer.concat([Buffer.from([version]), message, Buffer.from(signature)]);
|
|
36
|
-
this.messageVersion = this.CURRENT_VERSION;
|
|
37
|
-
this.keyId = keyId;
|
|
38
|
-
this.iteration = iteration;
|
|
39
|
-
this.ciphertext = ciphertextBuffer;
|
|
40
|
-
this.signature = signature;
|
|
41
|
-
}
|
|
1
|
+
//========================================//
|
|
2
|
+
/**
|
|
3
|
+
* @project @sixcore/baileys
|
|
4
|
+
* @author Sixx.js </>🌿
|
|
5
|
+
* @version 1.0.3
|
|
6
|
+
* @license MIT
|
|
7
|
+
* @country Mozambique 🇲🇿♥️
|
|
8
|
+
* @chamadas || sms +258860817689
|
|
9
|
+
* @whatsApp +55889616-2417 || +258851907875
|
|
10
|
+
* @description Biblioteca Node.js para integração e automação no WhatsApp usando Baileys
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { calculateSignature, verifySignature } from "libsignal-xeuka/src/curve.js";
|
|
14
|
+
import { CiphertextMessage } from "./ciphertext-message.js";
|
|
15
|
+
import { proto } from "../../../WAProto/index.js";
|
|
16
|
+
|
|
17
|
+
export class SenderKeyMessage extends CiphertextMessage {
|
|
18
|
+
constructor(keyId, iteration, ciphertext, signatureKey, serialized) {
|
|
19
|
+
super();
|
|
20
|
+
this.SIGNATURE_LENGTH = 64;
|
|
21
|
+
if (serialized) {
|
|
22
|
+
const version = serialized[0];
|
|
23
|
+
const message = serialized.slice(1, serialized.length - this.SIGNATURE_LENGTH);
|
|
24
|
+
const signature = serialized.slice(-1 * this.SIGNATURE_LENGTH);
|
|
25
|
+
const senderKeyMessage = proto.SenderKeyMessage.decode(message).toJSON();
|
|
26
|
+
this.serialized = serialized;
|
|
27
|
+
this.messageVersion = (version & 0xff) >> 4;
|
|
28
|
+
this.keyId = senderKeyMessage.id;
|
|
29
|
+
this.iteration = senderKeyMessage.iteration;
|
|
30
|
+
this.ciphertext =
|
|
31
|
+
typeof senderKeyMessage.ciphertext === "string"
|
|
32
|
+
? Buffer.from(senderKeyMessage.ciphertext, "base64")
|
|
33
|
+
: senderKeyMessage.ciphertext;
|
|
34
|
+
this.signature = signature;
|
|
42
35
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
getSignature(signatureKey, serialized) {
|
|
60
|
-
return Buffer.from((0, curve_1.calculateSignature)(signatureKey, serialized));
|
|
61
|
-
}
|
|
62
|
-
serialize() {
|
|
63
|
-
return this.serialized;
|
|
64
|
-
}
|
|
65
|
-
getType() {
|
|
66
|
-
return 4;
|
|
36
|
+
else {
|
|
37
|
+
const version = (((this.CURRENT_VERSION << 4) | this.CURRENT_VERSION) & 0xff) % 256;
|
|
38
|
+
const ciphertextBuffer = Buffer.from(ciphertext);
|
|
39
|
+
const message = proto.SenderKeyMessage.encode(proto.SenderKeyMessage.create({
|
|
40
|
+
id: keyId,
|
|
41
|
+
iteration: iteration,
|
|
42
|
+
ciphertext: ciphertextBuffer
|
|
43
|
+
})).finish();
|
|
44
|
+
const signature = this.getSignature(signatureKey, Buffer.concat([Buffer.from([version]), message]));
|
|
45
|
+
this.serialized = Buffer.concat([Buffer.from([version]), message, Buffer.from(signature)]);
|
|
46
|
+
this.messageVersion = this.CURRENT_VERSION;
|
|
47
|
+
this.keyId = keyId;
|
|
48
|
+
this.iteration = iteration;
|
|
49
|
+
this.ciphertext = ciphertextBuffer;
|
|
50
|
+
this.signature = signature;
|
|
67
51
|
}
|
|
52
|
+
}
|
|
53
|
+
getKeyId() {
|
|
54
|
+
return this.keyId;
|
|
55
|
+
}
|
|
56
|
+
getIteration() {
|
|
57
|
+
return this.iteration;
|
|
58
|
+
}
|
|
59
|
+
getCipherText() {
|
|
60
|
+
return this.ciphertext;
|
|
61
|
+
}
|
|
62
|
+
verifySignature(signatureKey) {
|
|
63
|
+
const part1 = this.serialized.slice(0, this.serialized.length - this.SIGNATURE_LENGTH);
|
|
64
|
+
const part2 = this.serialized.slice(-1 * this.SIGNATURE_LENGTH);
|
|
65
|
+
const res = verifySignature(signatureKey, part1, part2);
|
|
66
|
+
if (!res)
|
|
67
|
+
throw new Error("Invalid signature!");
|
|
68
|
+
}
|
|
69
|
+
getSignature(signatureKey, serialized) {
|
|
70
|
+
return Buffer.from(calculateSignature(signatureKey, serialized));
|
|
71
|
+
}
|
|
72
|
+
serialize() {
|
|
73
|
+
return this.serialized;
|
|
74
|
+
}
|
|
75
|
+
getType() {
|
|
76
|
+
return 4;
|
|
77
|
+
}
|
|
68
78
|
}
|
|
69
|
-
exports.SenderKeyMessage = SenderKeyMessage;
|
|
@@ -1,51 +1,62 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
//========================================//
|
|
2
|
+
/**
|
|
3
|
+
* @project @sixcore/baileys
|
|
4
|
+
* @author Sixx.js </>🌿
|
|
5
|
+
* @version 1.0.3
|
|
6
|
+
* @license MIT
|
|
7
|
+
* @country Mozambique 🇲🇿♥️
|
|
8
|
+
* @chamadas || sms +258860817689
|
|
9
|
+
* @whatsApp +55889616-2417 || +258851907875
|
|
10
|
+
* @description Biblioteca Node.js para integração e automação no WhatsApp usando Baileys
|
|
11
|
+
*/
|
|
12
|
+
|
|
4
13
|
function isNull(str) {
|
|
5
|
-
|
|
14
|
+
return str === null || str === "";
|
|
6
15
|
}
|
|
16
|
+
|
|
7
17
|
function intValue(num) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
18
|
+
const MAX_VALUE = 0x7fffffff;
|
|
19
|
+
const MIN_VALUE = -0x80000000;
|
|
20
|
+
if (num > MAX_VALUE || num < MIN_VALUE) {
|
|
21
|
+
return num & 0xffffffff;
|
|
22
|
+
}
|
|
23
|
+
return num;
|
|
14
24
|
}
|
|
25
|
+
|
|
15
26
|
function hashCode(strKey) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
27
|
+
let hash = 0;
|
|
28
|
+
if (!isNull(strKey)) {
|
|
29
|
+
for (let i = 0; i < strKey.length; i++) {
|
|
30
|
+
hash = hash * 31 + strKey.charCodeAt(i);
|
|
31
|
+
hash = intValue(hash);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return hash;
|
|
24
35
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
36
|
+
|
|
37
|
+
export class SenderKeyName {
|
|
38
|
+
constructor(groupId, sender) {
|
|
39
|
+
this.groupId = groupId;
|
|
40
|
+
this.sender = sender;
|
|
41
|
+
}
|
|
42
|
+
getGroupId() {
|
|
43
|
+
return this.groupId;
|
|
44
|
+
}
|
|
45
|
+
getSender() {
|
|
46
|
+
return this.sender;
|
|
47
|
+
}
|
|
48
|
+
serialize() {
|
|
49
|
+
return `${this.groupId}::${this.sender.id}::${this.sender.deviceId}`;
|
|
50
|
+
}
|
|
51
|
+
toString() {
|
|
52
|
+
return this.serialize();
|
|
53
|
+
}
|
|
54
|
+
equals(other) {
|
|
55
|
+
if (other === null)
|
|
56
|
+
return false;
|
|
57
|
+
return this.groupId === other.groupId && this.sender.toString() === other.sender.toString();
|
|
58
|
+
}
|
|
59
|
+
hashCode() {
|
|
60
|
+
return hashCode(this.groupId) ^ hashCode(this.sender.toString());
|
|
61
|
+
}
|
|
50
62
|
}
|
|
51
|
-
exports.SenderKeyName = SenderKeyName;
|
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
//========================================//
|
|
2
|
+
/**
|
|
3
|
+
* @project @sixcore/baileys
|
|
4
|
+
* @author Sixx.js </>🌿
|
|
5
|
+
* @version 1.0.3
|
|
6
|
+
* @license MIT
|
|
7
|
+
* @country Mozambique 🇲🇿♥️
|
|
8
|
+
* @chamadas || sms +258860817689
|
|
9
|
+
* @whatsApp +55889616-2417 || +258851907875
|
|
10
|
+
* @description Biblioteca Node.js para integração e automação no WhatsApp usando Baileys
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { SenderKeyState } from "./sender-key-state.js";
|
|
14
|
+
import { BufferJSON } from "../../Utils/generics.js";
|
|
15
|
+
|
|
16
|
+
export class SenderKeyRecord {
|
|
17
|
+
constructor(serialized) {
|
|
18
|
+
this.MAX_STATES = 5;
|
|
19
|
+
this.senderKeyStates = [];
|
|
20
|
+
if (serialized) {
|
|
21
|
+
for (const structure of serialized) {
|
|
22
|
+
this.senderKeyStates.push(new SenderKeyState(null, null, null, null, null, null, structure));
|
|
23
|
+
}
|
|
15
24
|
}
|
|
16
|
-
|
|
17
|
-
|
|
25
|
+
}
|
|
26
|
+
isEmpty() {
|
|
27
|
+
return this.senderKeyStates.length === 0;
|
|
28
|
+
}
|
|
29
|
+
getSenderKeyState(keyId) {
|
|
30
|
+
if (keyId === undefined && this.senderKeyStates.length) {
|
|
31
|
+
return this.senderKeyStates[this.senderKeyStates.length - 1];
|
|
18
32
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
addSenderKeyState(id, iteration, chainKey, signatureKey) {
|
|
26
|
-
this.senderKeyStates.push(new sender_key_state_1.SenderKeyState(id, iteration, chainKey, null, signatureKey));
|
|
27
|
-
if (this.senderKeyStates.length > this.MAX_STATES) {
|
|
28
|
-
this.senderKeyStates.shift();
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
setSenderKeyState(id, iteration, chainKey, keyPair) {
|
|
32
|
-
this.senderKeyStates.length = 0;
|
|
33
|
-
this.senderKeyStates.push(new sender_key_state_1.SenderKeyState(id, iteration, chainKey, keyPair));
|
|
34
|
-
}
|
|
35
|
-
serialize() {
|
|
36
|
-
return this.senderKeyStates.map(state => state.getStructure());
|
|
37
|
-
}
|
|
38
|
-
static deserialize(data) {
|
|
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
|
-
}
|
|
50
|
-
return new SenderKeyRecord(parsed);
|
|
33
|
+
return this.senderKeyStates.find(state => state.getKeyId() === keyId);
|
|
34
|
+
}
|
|
35
|
+
addSenderKeyState(id, iteration, chainKey, signatureKey) {
|
|
36
|
+
this.senderKeyStates.push(new SenderKeyState(id, iteration, chainKey, null, signatureKey));
|
|
37
|
+
if (this.senderKeyStates.length > this.MAX_STATES) {
|
|
38
|
+
this.senderKeyStates.shift();
|
|
51
39
|
}
|
|
40
|
+
}
|
|
41
|
+
setSenderKeyState(id, iteration, chainKey, keyPair) {
|
|
42
|
+
this.senderKeyStates.length = 0;
|
|
43
|
+
this.senderKeyStates.push(new SenderKeyState(id, iteration, chainKey, keyPair));
|
|
44
|
+
}
|
|
45
|
+
serialize() {
|
|
46
|
+
return this.senderKeyStates.map(state => state.getStructure());
|
|
47
|
+
}
|
|
48
|
+
static deserialize(data) {
|
|
49
|
+
const str = Buffer.from(data).toString("utf-8");
|
|
50
|
+
const parsed = JSON.parse(str, BufferJSON.reviver);
|
|
51
|
+
return new SenderKeyRecord(parsed);
|
|
52
|
+
}
|
|
52
53
|
}
|
|
53
|
-
exports.SenderKeyRecord = SenderKeyRecord;
|
|
@@ -1,99 +1,96 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
};
|
|
27
|
-
if (signatureKeyPrivate) {
|
|
28
|
-
signingKeyStructure.private =
|
|
29
|
-
typeof signatureKeyPrivate === 'string' ? Buffer.from(signatureKeyPrivate, 'base64') : signatureKeyPrivate;
|
|
30
|
-
}
|
|
31
|
-
this.senderKeyStateStructure = {
|
|
32
|
-
senderKeyId: id || 0,
|
|
33
|
-
senderChainKey: senderChainKeyStructure,
|
|
34
|
-
senderSigningKey: signingKeyStructure,
|
|
35
|
-
senderMessageKeys: []
|
|
36
|
-
};
|
|
37
|
-
}
|
|
1
|
+
//========================================//
|
|
2
|
+
/**
|
|
3
|
+
* @project @sixcore/baileys
|
|
4
|
+
* @author Sixx.js </>🌿
|
|
5
|
+
* @version 1.0.3
|
|
6
|
+
* @license MIT
|
|
7
|
+
* @country Mozambique 🇲🇿♥️
|
|
8
|
+
* @chamadas || sms +258860817689
|
|
9
|
+
* @whatsApp +55889616-2417 || +258851907875
|
|
10
|
+
* @description Biblioteca Node.js para integração e automação no WhatsApp usando Baileys
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { SenderMessageKey } from "./sender-message-key.js";
|
|
14
|
+
import { SenderChainKey } from "./sender-chain-key.js";
|
|
15
|
+
|
|
16
|
+
export class SenderKeyState {
|
|
17
|
+
constructor(id, iteration, chainKey, signatureKeyPair, signatureKeyPublic, signatureKeyPrivate, senderKeyStateStructure) {
|
|
18
|
+
this.MAX_MESSAGE_KEYS = 2000;
|
|
19
|
+
if (senderKeyStateStructure) {
|
|
20
|
+
this.senderKeyStateStructure = {
|
|
21
|
+
...senderKeyStateStructure,
|
|
22
|
+
senderMessageKeys: Array.isArray(senderKeyStateStructure.senderMessageKeys)
|
|
23
|
+
? senderKeyStateStructure.senderMessageKeys
|
|
24
|
+
: []
|
|
25
|
+
};
|
|
38
26
|
}
|
|
39
|
-
|
|
40
|
-
|
|
27
|
+
else {
|
|
28
|
+
if (signatureKeyPair) {
|
|
29
|
+
signatureKeyPublic = signatureKeyPair.public;
|
|
30
|
+
signatureKeyPrivate = signatureKeyPair.private;
|
|
31
|
+
}
|
|
32
|
+
this.senderKeyStateStructure = {
|
|
33
|
+
senderKeyId: id || 0,
|
|
34
|
+
senderChainKey: {
|
|
35
|
+
iteration: iteration || 0,
|
|
36
|
+
seed: Buffer.from(chainKey || [])
|
|
37
|
+
},
|
|
38
|
+
senderSigningKey: {
|
|
39
|
+
public: Buffer.from(signatureKeyPublic || []),
|
|
40
|
+
private: Buffer.from(signatureKeyPrivate || [])
|
|
41
|
+
},
|
|
42
|
+
senderMessageKeys: []
|
|
43
|
+
};
|
|
41
44
|
}
|
|
42
|
-
|
|
43
|
-
|
|
45
|
+
}
|
|
46
|
+
getKeyId() {
|
|
47
|
+
return this.senderKeyStateStructure.senderKeyId;
|
|
48
|
+
}
|
|
49
|
+
getSenderChainKey() {
|
|
50
|
+
return new SenderChainKey(this.senderKeyStateStructure.senderChainKey.iteration, this.senderKeyStateStructure.senderChainKey.seed);
|
|
51
|
+
}
|
|
52
|
+
setSenderChainKey(chainKey) {
|
|
53
|
+
this.senderKeyStateStructure.senderChainKey = {
|
|
54
|
+
iteration: chainKey.getIteration(),
|
|
55
|
+
seed: chainKey.getSeed()
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
getSigningKeyPublic() {
|
|
59
|
+
const publicKey = Buffer.from(this.senderKeyStateStructure.senderSigningKey.public);
|
|
60
|
+
if (publicKey.length === 32) {
|
|
61
|
+
const fixed = Buffer.alloc(33);
|
|
62
|
+
fixed[0] = 0x05;
|
|
63
|
+
publicKey.copy(fixed, 1);
|
|
64
|
+
return fixed;
|
|
44
65
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
66
|
+
return publicKey;
|
|
67
|
+
}
|
|
68
|
+
getSigningKeyPrivate() {
|
|
69
|
+
const privateKey = this.senderKeyStateStructure.senderSigningKey.private;
|
|
70
|
+
return Buffer.from(privateKey || []);
|
|
71
|
+
}
|
|
72
|
+
hasSenderMessageKey(iteration) {
|
|
73
|
+
return this.senderKeyStateStructure.senderMessageKeys.some(key => key.iteration === iteration);
|
|
74
|
+
}
|
|
75
|
+
addSenderMessageKey(senderMessageKey) {
|
|
76
|
+
this.senderKeyStateStructure.senderMessageKeys.push({
|
|
77
|
+
iteration: senderMessageKey.getIteration(),
|
|
78
|
+
seed: senderMessageKey.getSeed()
|
|
79
|
+
});
|
|
80
|
+
if (this.senderKeyStateStructure.senderMessageKeys.length > this.MAX_MESSAGE_KEYS) {
|
|
81
|
+
this.senderKeyStateStructure.senderMessageKeys.shift();
|
|
50
82
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
return Buffer.from(publicKey || []);
|
|
60
|
-
}
|
|
61
|
-
getSigningKeyPrivate() {
|
|
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
|
-
}
|
|
72
|
-
return Buffer.from(privateKey || []);
|
|
73
|
-
}
|
|
74
|
-
hasSenderMessageKey(iteration) {
|
|
75
|
-
return this.senderKeyStateStructure.senderMessageKeys.some(key => key.iteration === iteration);
|
|
76
|
-
}
|
|
77
|
-
addSenderMessageKey(senderMessageKey) {
|
|
78
|
-
this.senderKeyStateStructure.senderMessageKeys.push({
|
|
79
|
-
iteration: senderMessageKey.getIteration(),
|
|
80
|
-
seed: senderMessageKey.getSeed()
|
|
81
|
-
});
|
|
82
|
-
if (this.senderKeyStateStructure.senderMessageKeys.length > this.MAX_MESSAGE_KEYS) {
|
|
83
|
-
this.senderKeyStateStructure.senderMessageKeys.shift();
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
removeSenderMessageKey(iteration) {
|
|
87
|
-
const index = this.senderKeyStateStructure.senderMessageKeys.findIndex(key => key.iteration === iteration);
|
|
88
|
-
if (index !== -1) {
|
|
89
|
-
const messageKey = this.senderKeyStateStructure.senderMessageKeys[index];
|
|
90
|
-
this.senderKeyStateStructure.senderMessageKeys.splice(index, 1);
|
|
91
|
-
return new sender_message_key_1.SenderMessageKey(messageKey.iteration, messageKey.seed);
|
|
92
|
-
}
|
|
93
|
-
return null;
|
|
94
|
-
}
|
|
95
|
-
getStructure() {
|
|
96
|
-
return this.senderKeyStateStructure;
|
|
83
|
+
}
|
|
84
|
+
removeSenderMessageKey(iteration) {
|
|
85
|
+
const index = this.senderKeyStateStructure.senderMessageKeys.findIndex(key => key.iteration === iteration);
|
|
86
|
+
if (index !== -1) {
|
|
87
|
+
const messageKey = this.senderKeyStateStructure.senderMessageKeys[index];
|
|
88
|
+
this.senderKeyStateStructure.senderMessageKeys.splice(index, 1);
|
|
89
|
+
return new SenderMessageKey(messageKey.iteration, messageKey.seed);
|
|
97
90
|
}
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
getStructure() {
|
|
94
|
+
return this.senderKeyStateStructure;
|
|
95
|
+
}
|
|
98
96
|
}
|
|
99
|
-
exports.SenderKeyState = SenderKeyState;
|
|
@@ -1,29 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
1
|
+
//========================================//
|
|
2
|
+
/**
|
|
3
|
+
* @project @sixcore/baileys
|
|
4
|
+
* @author Sixx.js </>🌿
|
|
5
|
+
* @version 1.0.3
|
|
6
|
+
* @license MIT
|
|
7
|
+
* @country Mozambique 🇲🇿♥️
|
|
8
|
+
* @chamadas || sms +258860817689
|
|
9
|
+
* @whatsApp +55889616-2417 || +258851907875
|
|
10
|
+
* @description Biblioteca Node.js para integração e automação no WhatsApp usando Baileys
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { deriveSecrets } from "libsignal-xeuka/src/crypto.js";
|
|
14
|
+
|
|
15
|
+
export class SenderMessageKey {
|
|
16
|
+
constructor(iteration, seed) {
|
|
17
|
+
const derivative = deriveSecrets(seed, Buffer.alloc(32), Buffer.from("WhisperGroup"));
|
|
18
|
+
const keys = new Uint8Array(32);
|
|
19
|
+
keys.set(new Uint8Array(derivative[0].slice(16)));
|
|
20
|
+
keys.set(new Uint8Array(derivative[1].slice(0, 16)), 16);
|
|
21
|
+
this.iv = Buffer.from(derivative[0].slice(0, 16));
|
|
22
|
+
this.cipherKey = Buffer.from(keys.buffer);
|
|
23
|
+
this.iteration = iteration;
|
|
24
|
+
this.seed = seed;
|
|
25
|
+
}
|
|
26
|
+
getIteration() {
|
|
27
|
+
return this.iteration;
|
|
28
|
+
}
|
|
29
|
+
getIv() {
|
|
30
|
+
return this.iv;
|
|
31
|
+
}
|
|
32
|
+
getCipherKey() {
|
|
33
|
+
return this.cipherKey;
|
|
34
|
+
}
|
|
35
|
+
getSeed() {
|
|
36
|
+
return this.seed;
|
|
37
|
+
}
|
|
28
38
|
}
|
|
29
|
-
exports.SenderMessageKey = SenderMessageKey;
|