@d0v3riz/baileys 6.7.19 → 6.7.20
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/README.md +1263 -4
- package/WAProto/GenerateStatics.sh +2 -0
- package/WAProto/WAProto.proto +4633 -0
- package/WAProto/index.d.ts +3212 -122
- package/WAProto/index.js +9635 -299
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.d.ts +1 -1
- package/lib/Defaults/index.js +16 -16
- 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} +29 -39
- package/lib/Signal/libsignal.js +33 -20
- package/lib/Socket/Client/websocket.js +1 -1
- package/lib/Socket/business.d.ts +5 -5
- package/lib/Socket/business.js +5 -5
- package/lib/Socket/chats.d.ts +4 -4
- package/lib/Socket/chats.js +70 -70
- package/lib/Socket/groups.d.ts +6 -6
- package/lib/Socket/groups.js +39 -24
- package/lib/Socket/index.d.ts +5 -5
- package/lib/Socket/index.js +2 -2
- package/lib/Socket/messages-recv.d.ts +5 -5
- package/lib/Socket/messages-recv.js +73 -56
- package/lib/Socket/messages-send.d.ts +5 -5
- package/lib/Socket/messages-send.js +53 -46
- package/lib/Socket/socket.d.ts +3 -3
- package/lib/Socket/socket.js +22 -29
- package/lib/Socket/usync.d.ts +3 -3
- package/lib/Socket/usync.js +10 -15
- package/lib/Types/Auth.d.ts +1 -1
- package/lib/Types/Chat.d.ts +1 -1
- package/lib/Types/Chat.js +7 -1
- package/lib/Types/Contact.d.ts +4 -0
- package/lib/Types/Events.d.ts +1 -1
- package/lib/Types/GroupMetadata.d.ts +7 -3
- package/lib/Types/Message.d.ts +6 -1
- package/lib/Types/Socket.d.ts +3 -3
- package/lib/Utils/auth-utils.js +8 -9
- package/lib/Utils/baileys-event-stream.js +1 -1
- package/lib/Utils/business.js +9 -11
- package/lib/Utils/chat-utils.d.ts +4 -4
- package/lib/Utils/chat-utils.js +64 -69
- package/lib/Utils/crypto.js +4 -10
- package/lib/Utils/decode-wa-message.js +6 -2
- package/lib/Utils/event-buffer.d.ts +2 -2
- package/lib/Utils/event-buffer.js +9 -13
- package/lib/Utils/generics.d.ts +1 -1
- package/lib/Utils/generics.js +28 -30
- package/lib/Utils/history.js +10 -5
- package/lib/Utils/link-preview.js +5 -9
- package/lib/Utils/lt-hash.js +2 -2
- package/lib/Utils/make-mutex.js +1 -1
- package/lib/Utils/messages-media.js +40 -55
- package/lib/Utils/messages.d.ts +1 -1
- package/lib/Utils/messages.js +71 -61
- package/lib/Utils/process-message.d.ts +1 -1
- package/lib/Utils/process-message.js +25 -30
- package/lib/Utils/signal.js +9 -7
- package/lib/Utils/use-multi-file-auth-state.js +2 -3
- package/lib/Utils/validate-connection.js +17 -22
- package/lib/WABinary/constants.d.ts +4 -4
- package/lib/WABinary/constants.js +1271 -8
- package/lib/WABinary/decode.js +2 -1
- package/lib/WABinary/encode.js +2 -2
- package/lib/WABinary/generic-utils.js +1 -1
- package/lib/WABinary/jid-utils.js +8 -11
- package/lib/WAM/constants.js +2252 -2359
- package/lib/WAM/encode.js +5 -7
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +5 -5
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +1 -1
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +1 -1
- package/lib/WAUSync/USyncQuery.js +17 -13
- package/package.json +11 -6
- package/WASignalGroup/GroupProtocol.js +0 -1697
- package/WASignalGroup/ciphertext_message.js +0 -16
- package/WASignalGroup/group_cipher.js +0 -120
- package/WASignalGroup/group_session_builder.js +0 -46
- package/WASignalGroup/index.js +0 -5
- package/WASignalGroup/keyhelper.js +0 -21
- package/WASignalGroup/protobufs.js +0 -3
- package/WASignalGroup/queue_job.js +0 -69
- package/WASignalGroup/sender_chain_key.js +0 -50
- package/WASignalGroup/sender_key_distribution_message.js +0 -78
- package/WASignalGroup/sender_key_message.js +0 -92
- package/WASignalGroup/sender_key_name.js +0 -70
- package/WASignalGroup/sender_key_record.js +0 -56
- package/WASignalGroup/sender_key_state.js +0 -129
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { CiphertextMessage } from './ciphertext-message';
|
|
2
|
+
export declare class SenderKeyMessage extends CiphertextMessage {
|
|
3
|
+
private readonly SIGNATURE_LENGTH;
|
|
4
|
+
private readonly messageVersion;
|
|
5
|
+
private readonly keyId;
|
|
6
|
+
private readonly iteration;
|
|
7
|
+
private readonly ciphertext;
|
|
8
|
+
private readonly signature;
|
|
9
|
+
private readonly serialized;
|
|
10
|
+
constructor(keyId?: number | null, iteration?: number | null, ciphertext?: Uint8Array | null, signatureKey?: Uint8Array | null, serialized?: Uint8Array | null);
|
|
11
|
+
getKeyId(): number;
|
|
12
|
+
getIteration(): number;
|
|
13
|
+
getCipherText(): Uint8Array;
|
|
14
|
+
verifySignature(signatureKey: Uint8Array): void;
|
|
15
|
+
private getSignature;
|
|
16
|
+
serialize(): Uint8Array;
|
|
17
|
+
getType(): number;
|
|
18
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
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 {
|
|
8
|
+
constructor(keyId, iteration, ciphertext, signatureKey, serialized) {
|
|
9
|
+
super();
|
|
10
|
+
this.SIGNATURE_LENGTH = 64;
|
|
11
|
+
if (serialized) {
|
|
12
|
+
const version = serialized[0];
|
|
13
|
+
const message = serialized.slice(1, serialized.length - this.SIGNATURE_LENGTH);
|
|
14
|
+
const signature = serialized.slice(-1 * this.SIGNATURE_LENGTH);
|
|
15
|
+
const senderKeyMessage = WAProto_1.proto.SenderKeyMessage.decode(message).toJSON();
|
|
16
|
+
this.serialized = serialized;
|
|
17
|
+
this.messageVersion = (version & 0xff) >> 4;
|
|
18
|
+
this.keyId = senderKeyMessage.id;
|
|
19
|
+
this.iteration = senderKeyMessage.iteration;
|
|
20
|
+
this.ciphertext =
|
|
21
|
+
typeof senderKeyMessage.ciphertext === 'string'
|
|
22
|
+
? Buffer.from(senderKeyMessage.ciphertext, 'base64')
|
|
23
|
+
: senderKeyMessage.ciphertext;
|
|
24
|
+
this.signature = signature;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
const version = (((this.CURRENT_VERSION << 4) | this.CURRENT_VERSION) & 0xff) % 256;
|
|
28
|
+
const ciphertextBuffer = Buffer.from(ciphertext);
|
|
29
|
+
const message = WAProto_1.proto.SenderKeyMessage.encode(WAProto_1.proto.SenderKeyMessage.create({
|
|
30
|
+
id: keyId,
|
|
31
|
+
iteration: iteration,
|
|
32
|
+
ciphertext: ciphertextBuffer
|
|
33
|
+
})).finish();
|
|
34
|
+
const signature = this.getSignature(signatureKey, Buffer.concat([Buffer.from([version]), message]));
|
|
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
|
+
}
|
|
42
|
+
}
|
|
43
|
+
getKeyId() {
|
|
44
|
+
return this.keyId;
|
|
45
|
+
}
|
|
46
|
+
getIteration() {
|
|
47
|
+
return this.iteration;
|
|
48
|
+
}
|
|
49
|
+
getCipherText() {
|
|
50
|
+
return this.ciphertext;
|
|
51
|
+
}
|
|
52
|
+
verifySignature(signatureKey) {
|
|
53
|
+
const part1 = this.serialized.slice(0, this.serialized.length - this.SIGNATURE_LENGTH);
|
|
54
|
+
const part2 = this.serialized.slice(-1 * this.SIGNATURE_LENGTH);
|
|
55
|
+
const res = (0, curve_1.verifySignature)(signatureKey, part1, part2);
|
|
56
|
+
if (!res)
|
|
57
|
+
throw new Error('Invalid signature!');
|
|
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;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.SenderKeyMessage = SenderKeyMessage;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
interface Sender {
|
|
2
|
+
id: string;
|
|
3
|
+
deviceId: number;
|
|
4
|
+
toString(): string;
|
|
5
|
+
}
|
|
6
|
+
export declare class SenderKeyName {
|
|
7
|
+
private readonly groupId;
|
|
8
|
+
private readonly sender;
|
|
9
|
+
constructor(groupId: string, sender: Sender);
|
|
10
|
+
getGroupId(): string;
|
|
11
|
+
getSender(): Sender;
|
|
12
|
+
serialize(): string;
|
|
13
|
+
toString(): string;
|
|
14
|
+
equals(other: SenderKeyName | null): boolean;
|
|
15
|
+
hashCode(): number;
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SenderKeyName = void 0;
|
|
4
|
+
function isNull(str) {
|
|
5
|
+
return str === null || str === '';
|
|
6
|
+
}
|
|
7
|
+
function intValue(num) {
|
|
8
|
+
const MAX_VALUE = 0x7fffffff;
|
|
9
|
+
const MIN_VALUE = -0x80000000;
|
|
10
|
+
if (num > MAX_VALUE || num < MIN_VALUE) {
|
|
11
|
+
return num & 0xffffffff;
|
|
12
|
+
}
|
|
13
|
+
return num;
|
|
14
|
+
}
|
|
15
|
+
function hashCode(strKey) {
|
|
16
|
+
let hash = 0;
|
|
17
|
+
if (!isNull(strKey)) {
|
|
18
|
+
for (let i = 0; i < strKey.length; i++) {
|
|
19
|
+
hash = hash * 31 + strKey.charCodeAt(i);
|
|
20
|
+
hash = intValue(hash);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return hash;
|
|
24
|
+
}
|
|
25
|
+
class SenderKeyName {
|
|
26
|
+
constructor(groupId, sender) {
|
|
27
|
+
this.groupId = groupId;
|
|
28
|
+
this.sender = sender;
|
|
29
|
+
}
|
|
30
|
+
getGroupId() {
|
|
31
|
+
return this.groupId;
|
|
32
|
+
}
|
|
33
|
+
getSender() {
|
|
34
|
+
return this.sender;
|
|
35
|
+
}
|
|
36
|
+
serialize() {
|
|
37
|
+
return `${this.groupId}::${this.sender.id}::${this.sender.deviceId}`;
|
|
38
|
+
}
|
|
39
|
+
toString() {
|
|
40
|
+
return this.serialize();
|
|
41
|
+
}
|
|
42
|
+
equals(other) {
|
|
43
|
+
if (other === null)
|
|
44
|
+
return false;
|
|
45
|
+
return this.groupId === other.groupId && this.sender.toString() === other.sender.toString();
|
|
46
|
+
}
|
|
47
|
+
hashCode() {
|
|
48
|
+
return hashCode(this.groupId) ^ hashCode(this.sender.toString());
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.SenderKeyName = SenderKeyName;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { SenderKeyState } from './sender-key-state';
|
|
2
|
+
export interface SenderKeyStateStructure {
|
|
3
|
+
senderKeyId: number;
|
|
4
|
+
senderChainKey: {
|
|
5
|
+
iteration: number;
|
|
6
|
+
seed: Uint8Array;
|
|
7
|
+
};
|
|
8
|
+
senderSigningKey: {
|
|
9
|
+
public: Uint8Array;
|
|
10
|
+
private?: Uint8Array;
|
|
11
|
+
};
|
|
12
|
+
senderMessageKeys: Array<{
|
|
13
|
+
iteration: number;
|
|
14
|
+
seed: Uint8Array;
|
|
15
|
+
}>;
|
|
16
|
+
}
|
|
17
|
+
export declare class SenderKeyRecord {
|
|
18
|
+
private readonly MAX_STATES;
|
|
19
|
+
private readonly senderKeyStates;
|
|
20
|
+
constructor(serialized?: SenderKeyStateStructure[]);
|
|
21
|
+
isEmpty(): boolean;
|
|
22
|
+
getSenderKeyState(keyId?: number): SenderKeyState | undefined;
|
|
23
|
+
addSenderKeyState(id: number, iteration: number, chainKey: Uint8Array, signatureKey: Uint8Array): void;
|
|
24
|
+
setSenderKeyState(id: number, iteration: number, chainKey: Uint8Array, keyPair: {
|
|
25
|
+
public: Uint8Array;
|
|
26
|
+
private: Uint8Array;
|
|
27
|
+
}): void;
|
|
28
|
+
serialize(): SenderKeyStateStructure[];
|
|
29
|
+
static deserialize(data: Uint8Array | string | SenderKeyStateStructure[]): SenderKeyRecord;
|
|
30
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
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 {
|
|
7
|
+
constructor(serialized) {
|
|
8
|
+
this.MAX_STATES = 5;
|
|
9
|
+
this.senderKeyStates = [];
|
|
10
|
+
if (serialized) {
|
|
11
|
+
for (const structure of serialized) {
|
|
12
|
+
this.senderKeyStates.push(new sender_key_state_1.SenderKeyState(null, null, null, null, null, null, structure));
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
isEmpty() {
|
|
17
|
+
return this.senderKeyStates.length === 0;
|
|
18
|
+
}
|
|
19
|
+
getSenderKeyState(keyId) {
|
|
20
|
+
if (keyId === undefined && this.senderKeyStates.length) {
|
|
21
|
+
return this.senderKeyStates[this.senderKeyStates.length - 1];
|
|
22
|
+
}
|
|
23
|
+
return this.senderKeyStates.find(state => state.getKeyId() === keyId);
|
|
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);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.SenderKeyRecord = SenderKeyRecord;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { SenderChainKey } from './sender-chain-key';
|
|
2
|
+
import { SenderMessageKey } from './sender-message-key';
|
|
3
|
+
interface SenderChainKeyStructure {
|
|
4
|
+
iteration: number;
|
|
5
|
+
seed: Uint8Array;
|
|
6
|
+
}
|
|
7
|
+
interface SenderSigningKeyStructure {
|
|
8
|
+
public: Uint8Array;
|
|
9
|
+
private?: Uint8Array;
|
|
10
|
+
}
|
|
11
|
+
interface SenderMessageKeyStructure {
|
|
12
|
+
iteration: number;
|
|
13
|
+
seed: Uint8Array;
|
|
14
|
+
}
|
|
15
|
+
interface SenderKeyStateStructure {
|
|
16
|
+
senderKeyId: number;
|
|
17
|
+
senderChainKey: SenderChainKeyStructure;
|
|
18
|
+
senderSigningKey: SenderSigningKeyStructure;
|
|
19
|
+
senderMessageKeys: SenderMessageKeyStructure[];
|
|
20
|
+
}
|
|
21
|
+
export declare class SenderKeyState {
|
|
22
|
+
private readonly MAX_MESSAGE_KEYS;
|
|
23
|
+
private readonly senderKeyStateStructure;
|
|
24
|
+
constructor(id?: number | null, iteration?: number | null, chainKey?: Uint8Array | null, signatureKeyPair?: {
|
|
25
|
+
public: Uint8Array;
|
|
26
|
+
private: Uint8Array;
|
|
27
|
+
} | null, signatureKeyPublic?: Uint8Array | null, signatureKeyPrivate?: Uint8Array | null, senderKeyStateStructure?: SenderKeyStateStructure | null);
|
|
28
|
+
getKeyId(): number;
|
|
29
|
+
getSenderChainKey(): SenderChainKey;
|
|
30
|
+
setSenderChainKey(chainKey: SenderChainKey): void;
|
|
31
|
+
getSigningKeyPublic(): Buffer;
|
|
32
|
+
getSigningKeyPrivate(): Buffer | undefined;
|
|
33
|
+
hasSenderMessageKey(iteration: number): boolean;
|
|
34
|
+
addSenderMessageKey(senderMessageKey: SenderMessageKey): void;
|
|
35
|
+
removeSenderMessageKey(iteration: number): SenderMessageKey | null;
|
|
36
|
+
getStructure(): SenderKeyStateStructure;
|
|
37
|
+
}
|
|
38
|
+
export {};
|
|
@@ -0,0 +1,99 @@
|
|
|
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 {
|
|
7
|
+
constructor(id, iteration, chainKey, signatureKeyPair, signatureKeyPublic, signatureKeyPrivate, senderKeyStateStructure) {
|
|
8
|
+
this.MAX_MESSAGE_KEYS = 2000;
|
|
9
|
+
if (senderKeyStateStructure) {
|
|
10
|
+
this.senderKeyStateStructure = senderKeyStateStructure;
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
if (signatureKeyPair) {
|
|
14
|
+
signatureKeyPublic = signatureKeyPair.public;
|
|
15
|
+
signatureKeyPrivate = signatureKeyPair.private;
|
|
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
|
+
}
|
|
31
|
+
this.senderKeyStateStructure = {
|
|
32
|
+
senderKeyId: id || 0,
|
|
33
|
+
senderChainKey: senderChainKeyStructure,
|
|
34
|
+
senderSigningKey: signingKeyStructure,
|
|
35
|
+
senderMessageKeys: []
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
getKeyId() {
|
|
40
|
+
return this.senderKeyStateStructure.senderKeyId;
|
|
41
|
+
}
|
|
42
|
+
getSenderChainKey() {
|
|
43
|
+
return new sender_chain_key_1.SenderChainKey(this.senderKeyStateStructure.senderChainKey.iteration, this.senderKeyStateStructure.senderChainKey.seed);
|
|
44
|
+
}
|
|
45
|
+
setSenderChainKey(chainKey) {
|
|
46
|
+
this.senderKeyStateStructure.senderChainKey = {
|
|
47
|
+
iteration: chainKey.getIteration(),
|
|
48
|
+
seed: chainKey.getSeed()
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
getSigningKeyPublic() {
|
|
52
|
+
const publicKey = this.senderKeyStateStructure.senderSigningKey.public;
|
|
53
|
+
if (publicKey instanceof Buffer) {
|
|
54
|
+
return publicKey;
|
|
55
|
+
}
|
|
56
|
+
else if (typeof publicKey === 'string') {
|
|
57
|
+
return Buffer.from(publicKey, 'base64');
|
|
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;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
exports.SenderKeyState = SenderKeyState;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare class SenderMessageKey {
|
|
2
|
+
private readonly iteration;
|
|
3
|
+
private readonly iv;
|
|
4
|
+
private readonly cipherKey;
|
|
5
|
+
private readonly seed;
|
|
6
|
+
constructor(iteration: number, seed: Uint8Array);
|
|
7
|
+
getIteration(): number;
|
|
8
|
+
getIv(): Uint8Array;
|
|
9
|
+
getCipherKey(): Uint8Array;
|
|
10
|
+
getSeed(): Uint8Array;
|
|
11
|
+
}
|
|
@@ -1,39 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
this.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
this.
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
getCipherKey() {
|
|
32
|
-
return this.cipherKey;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
getSeed() {
|
|
36
|
-
return this.seed;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
module.exports = SenderMessageKey;
|
|
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 {
|
|
6
|
+
constructor(iteration, seed) {
|
|
7
|
+
const derivative = (0, crypto_1.deriveSecrets)(seed, Buffer.alloc(32), Buffer.from('WhisperGroup'));
|
|
8
|
+
const keys = new Uint8Array(32);
|
|
9
|
+
keys.set(new Uint8Array(derivative[0].slice(16)));
|
|
10
|
+
keys.set(new Uint8Array(derivative[1].slice(0, 16)), 16);
|
|
11
|
+
this.iv = Buffer.from(derivative[0].slice(0, 16));
|
|
12
|
+
this.cipherKey = Buffer.from(keys.buffer);
|
|
13
|
+
this.iteration = iteration;
|
|
14
|
+
this.seed = seed;
|
|
15
|
+
}
|
|
16
|
+
getIteration() {
|
|
17
|
+
return this.iteration;
|
|
18
|
+
}
|
|
19
|
+
getIv() {
|
|
20
|
+
return this.iv;
|
|
21
|
+
}
|
|
22
|
+
getCipherKey() {
|
|
23
|
+
return this.cipherKey;
|
|
24
|
+
}
|
|
25
|
+
getSeed() {
|
|
26
|
+
return this.seed;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.SenderMessageKey = SenderMessageKey;
|
package/lib/Signal/libsignal.js
CHANGED
|
@@ -35,24 +35,30 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.makeLibSignalRepository = makeLibSignalRepository;
|
|
37
37
|
const libsignal = __importStar(require("libsignal"));
|
|
38
|
-
const WASignalGroup_1 = require("../../WASignalGroup");
|
|
39
38
|
const Utils_1 = require("../Utils");
|
|
40
39
|
const WABinary_1 = require("../WABinary");
|
|
40
|
+
const sender_key_name_1 = require("./Group/sender-key-name");
|
|
41
|
+
const sender_key_record_1 = require("./Group/sender-key-record");
|
|
42
|
+
const Group_1 = require("./Group");
|
|
41
43
|
function makeLibSignalRepository(auth) {
|
|
42
44
|
const storage = signalStorage(auth);
|
|
43
45
|
return {
|
|
44
46
|
decryptGroupMessage({ group, authorJid, msg }) {
|
|
45
47
|
const senderName = jidToSignalSenderKeyName(group, authorJid);
|
|
46
|
-
const cipher = new
|
|
48
|
+
const cipher = new Group_1.GroupCipher(storage, senderName);
|
|
47
49
|
return cipher.decrypt(msg);
|
|
48
50
|
},
|
|
49
51
|
async processSenderKeyDistributionMessage({ item, authorJid }) {
|
|
50
|
-
const builder = new
|
|
52
|
+
const builder = new Group_1.GroupSessionBuilder(storage);
|
|
53
|
+
if (!item.groupId) {
|
|
54
|
+
throw new Error('Group ID is required for sender key distribution message');
|
|
55
|
+
}
|
|
51
56
|
const senderName = jidToSignalSenderKeyName(item.groupId, authorJid);
|
|
52
|
-
const senderMsg = new
|
|
53
|
-
const
|
|
57
|
+
const senderMsg = new Group_1.SenderKeyDistributionMessage(null, null, null, null, item.axolotlSenderKeyDistributionMessage);
|
|
58
|
+
const senderNameStr = senderName.toString();
|
|
59
|
+
const { [senderNameStr]: senderKey } = await auth.keys.get('sender-key', [senderNameStr]);
|
|
54
60
|
if (!senderKey) {
|
|
55
|
-
await storage.storeSenderKey(senderName, new
|
|
61
|
+
await storage.storeSenderKey(senderName, new sender_key_record_1.SenderKeyRecord());
|
|
56
62
|
}
|
|
57
63
|
await builder.process(senderName, senderMsg);
|
|
58
64
|
},
|
|
@@ -67,6 +73,8 @@ function makeLibSignalRepository(auth) {
|
|
|
67
73
|
case 'msg':
|
|
68
74
|
result = await session.decryptWhisperMessage(ciphertext);
|
|
69
75
|
break;
|
|
76
|
+
default:
|
|
77
|
+
throw new Error(`Unknown message type: ${type}`);
|
|
70
78
|
}
|
|
71
79
|
return result;
|
|
72
80
|
},
|
|
@@ -79,17 +87,18 @@ function makeLibSignalRepository(auth) {
|
|
|
79
87
|
},
|
|
80
88
|
async encryptGroupMessage({ group, meId, data }) {
|
|
81
89
|
const senderName = jidToSignalSenderKeyName(group, meId);
|
|
82
|
-
const builder = new
|
|
83
|
-
const
|
|
90
|
+
const builder = new Group_1.GroupSessionBuilder(storage);
|
|
91
|
+
const senderNameStr = senderName.toString();
|
|
92
|
+
const { [senderNameStr]: senderKey } = await auth.keys.get('sender-key', [senderNameStr]);
|
|
84
93
|
if (!senderKey) {
|
|
85
|
-
await storage.storeSenderKey(senderName, new
|
|
94
|
+
await storage.storeSenderKey(senderName, new sender_key_record_1.SenderKeyRecord());
|
|
86
95
|
}
|
|
87
96
|
const senderKeyDistributionMessage = await builder.create(senderName);
|
|
88
|
-
const session = new
|
|
97
|
+
const session = new Group_1.GroupCipher(storage, senderName);
|
|
89
98
|
const ciphertext = await session.encrypt(data);
|
|
90
99
|
return {
|
|
91
100
|
ciphertext,
|
|
92
|
-
senderKeyDistributionMessage: senderKeyDistributionMessage.serialize()
|
|
101
|
+
senderKeyDistributionMessage: senderKeyDistributionMessage.serialize()
|
|
93
102
|
};
|
|
94
103
|
},
|
|
95
104
|
async injectE2ESession({ jid, session }) {
|
|
@@ -98,7 +107,7 @@ function makeLibSignalRepository(auth) {
|
|
|
98
107
|
},
|
|
99
108
|
jidToSignalProtocolAddress(jid) {
|
|
100
109
|
return jidToSignalProtocolAddress(jid).toString();
|
|
101
|
-
}
|
|
110
|
+
}
|
|
102
111
|
};
|
|
103
112
|
}
|
|
104
113
|
const jidToSignalProtocolAddress = (jid) => {
|
|
@@ -106,7 +115,7 @@ const jidToSignalProtocolAddress = (jid) => {
|
|
|
106
115
|
return new libsignal.ProtocolAddress(user, device || 0);
|
|
107
116
|
};
|
|
108
117
|
const jidToSignalSenderKeyName = (group, user) => {
|
|
109
|
-
return new
|
|
118
|
+
return new sender_key_name_1.SenderKeyName(group, jidToSignalProtocolAddress(user));
|
|
110
119
|
};
|
|
111
120
|
function signalStorage({ creds, keys }) {
|
|
112
121
|
return {
|
|
@@ -117,7 +126,7 @@ function signalStorage({ creds, keys }) {
|
|
|
117
126
|
}
|
|
118
127
|
},
|
|
119
128
|
storeSession: async (id, session) => {
|
|
120
|
-
await keys.set({
|
|
129
|
+
await keys.set({ session: { [id]: session.serialize() } });
|
|
121
130
|
},
|
|
122
131
|
isTrustedIdentity: () => {
|
|
123
132
|
return true;
|
|
@@ -140,21 +149,25 @@ function signalStorage({ creds, keys }) {
|
|
|
140
149
|
pubKey: Buffer.from(key.keyPair.public)
|
|
141
150
|
};
|
|
142
151
|
},
|
|
143
|
-
loadSenderKey: async (
|
|
152
|
+
loadSenderKey: async (senderKeyName) => {
|
|
153
|
+
const keyId = senderKeyName.toString();
|
|
144
154
|
const { [keyId]: key } = await keys.get('sender-key', [keyId]);
|
|
145
155
|
if (key) {
|
|
146
|
-
return
|
|
156
|
+
return sender_key_record_1.SenderKeyRecord.deserialize(key);
|
|
147
157
|
}
|
|
158
|
+
return new sender_key_record_1.SenderKeyRecord();
|
|
148
159
|
},
|
|
149
|
-
storeSenderKey: async (
|
|
150
|
-
|
|
160
|
+
storeSenderKey: async (senderKeyName, key) => {
|
|
161
|
+
const keyId = senderKeyName.toString();
|
|
162
|
+
const serialized = JSON.stringify(key.serialize());
|
|
163
|
+
await keys.set({ 'sender-key': { [keyId]: Buffer.from(serialized, 'utf-8') } });
|
|
151
164
|
},
|
|
152
|
-
getOurRegistrationId: () =>
|
|
165
|
+
getOurRegistrationId: () => creds.registrationId,
|
|
153
166
|
getOurIdentity: () => {
|
|
154
167
|
const { signedIdentityKey } = creds;
|
|
155
168
|
return {
|
|
156
169
|
privKey: Buffer.from(signedIdentityKey.private),
|
|
157
|
-
pubKey: (0, Utils_1.generateSignalPubKey)(signedIdentityKey.public)
|
|
170
|
+
pubKey: (0, Utils_1.generateSignalPubKey)(signedIdentityKey.public)
|
|
158
171
|
};
|
|
159
172
|
}
|
|
160
173
|
};
|
|
@@ -38,7 +38,7 @@ class WebSocketClient extends types_1.AbstractSocketClient {
|
|
|
38
38
|
headers: (_a = this.config.options) === null || _a === void 0 ? void 0 : _a.headers,
|
|
39
39
|
handshakeTimeout: this.config.connectTimeoutMs,
|
|
40
40
|
timeout: this.config.connectTimeoutMs,
|
|
41
|
-
agent: this.config.agent
|
|
41
|
+
agent: this.config.agent
|
|
42
42
|
});
|
|
43
43
|
this.socket.setMaxListeners(0);
|
|
44
44
|
const events = ['close', 'error', 'upgrade', 'message', 'open', 'ping', 'pong', 'unexpected-response'];
|
package/lib/Socket/business.d.ts
CHANGED
|
@@ -60,7 +60,7 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
|
|
|
60
60
|
groupRevokeInvite: (jid: string) => Promise<string | undefined>;
|
|
61
61
|
groupAcceptInvite: (code: string) => Promise<string | undefined>;
|
|
62
62
|
groupRevokeInviteV4: (groupJid: string, invitedJid: string) => Promise<boolean>;
|
|
63
|
-
groupAcceptInviteV4: (key: string | import("../Types").
|
|
63
|
+
groupAcceptInviteV4: (key: string | import("../Types").WAMessageKey, inviteMessage: import("../Types").WAProto.Message.IGroupInviteMessage) => Promise<any>;
|
|
64
64
|
groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
|
|
65
65
|
groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
|
|
66
66
|
groupSettingUpdate: (jid: string, setting: "announcement" | "not_announcement" | "locked" | "unlocked") => Promise<void>;
|
|
@@ -101,7 +101,7 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
|
|
|
101
101
|
updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyGroupAddValue) => Promise<void>;
|
|
102
102
|
updateDefaultDisappearingMode: (duration: number) => Promise<void>;
|
|
103
103
|
getBusinessProfile: (jid: string) => Promise<import("../Types").WABusinessProfile | void>;
|
|
104
|
-
resyncAppState: (collections: readonly ("
|
|
104
|
+
resyncAppState: (collections: readonly ("critical_unblock_low" | "regular_high" | "regular_low" | "critical_block" | "regular")[], isInitialSync: boolean) => Promise<void>;
|
|
105
105
|
chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>;
|
|
106
106
|
cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: number | string) => Promise<void>;
|
|
107
107
|
addLabel: (jid: string, labels: import("../Types/Label").LabelActionBody) => Promise<void>;
|
|
@@ -117,9 +117,9 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
|
|
|
117
117
|
type: "md";
|
|
118
118
|
ws: import("./Client").WebSocketClient;
|
|
119
119
|
ev: import("../Types").BaileysEventEmitter & {
|
|
120
|
-
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): (
|
|
120
|
+
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
|
|
121
121
|
buffer(): void;
|
|
122
|
-
createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): (
|
|
122
|
+
createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): (...args: A) => Promise<T>;
|
|
123
123
|
flush(force?: boolean): boolean;
|
|
124
124
|
isBuffering(): boolean;
|
|
125
125
|
};
|
|
@@ -140,7 +140,7 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
|
|
|
140
140
|
onUnexpectedError: (err: Error | import("@hapi/boom").Boom, msg: string) => void;
|
|
141
141
|
uploadPreKeys: (count?: number) => Promise<void>;
|
|
142
142
|
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
|
143
|
-
requestPairingCode: (phoneNumber: string) => Promise<string>;
|
|
143
|
+
requestPairingCode: (phoneNumber: string, customPairingCode?: string) => Promise<string>;
|
|
144
144
|
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
|
|
145
145
|
sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
|
|
146
146
|
};
|