@queenanya/baileys 8.2.7 → 8.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/WAProto/index.d.ts +1590 -6
- package/WAProto/index.js +4635 -3
- package/engine-requirements.js +1 -1
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.d.ts +1 -1
- package/lib/Defaults/index.js +4 -5
- 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 +33 -20
- package/lib/Socket/Client/types.d.ts +1 -0
- package/lib/Socket/Client/websocket.d.ts +1 -0
- package/lib/Socket/Client/websocket.js +11 -1
- package/lib/Socket/business.d.ts +5 -8
- package/lib/Socket/chats.d.ts +4 -8
- package/lib/Socket/chats.js +7 -87
- package/lib/Socket/groups.d.ts +4 -6
- package/lib/Socket/groups.js +13 -9
- package/lib/Socket/index.d.ts +5 -8
- package/lib/Socket/messages-recv.d.ts +5 -8
- package/lib/Socket/messages-recv.js +20 -25
- package/lib/Socket/messages-send.d.ts +5 -8
- package/lib/Socket/messages-send.js +116 -81
- package/lib/Socket/newsletter.d.ts +4 -6
- package/lib/Socket/newsletter.js +2 -4
- package/lib/Socket/socket.js +63 -1
- package/lib/Socket/usync.js +15 -10
- package/lib/Types/Chat.d.ts +2 -8
- package/lib/Types/Contact.d.ts +4 -5
- package/lib/Types/GroupMetadata.d.ts +4 -3
- package/lib/Types/Label.d.ts +0 -11
- package/lib/Types/Message.d.ts +15 -2
- package/lib/Types/Socket.d.ts +0 -2
- package/lib/Utils/chat-utils.d.ts +8 -8
- package/lib/Utils/chat-utils.js +4 -30
- package/lib/Utils/crypto.d.ts +1 -1
- package/lib/Utils/crypto.js +1 -3
- package/lib/Utils/decode-wa-message.d.ts +2 -4
- package/lib/Utils/decode-wa-message.js +18 -161
- package/lib/Utils/generics.d.ts +18 -8
- package/lib/Utils/generics.js +93 -7
- package/lib/Utils/history.js +1 -1
- package/lib/Utils/index.d.ts +1 -0
- package/lib/Utils/index.js +1 -0
- package/lib/Utils/messages-media.d.ts +9 -16
- package/lib/Utils/messages-media.js +186 -98
- package/lib/Utils/messages.d.ts +1 -1
- package/lib/Utils/messages.js +27 -17
- package/lib/Utils/use-single-file-auth-state.d.ts +5 -0
- package/lib/Utils/use-single-file-auth-state.js +66 -0
- package/lib/Utils/validate-connection.js +7 -7
- package/lib/WABinary/constants.d.ts +4 -4
- package/lib/WABinary/constants.js +1271 -8
- package/lib/WABinary/encode.js +5 -7
- package/lib/WABinary/jid-utils.d.ts +3 -3
- package/lib/WABinary/jid-utils.js +18 -18
- package/lib/WAM/constants.d.ts +2 -3
- package/lib/WAM/encode.js +2 -2
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +3 -3
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +2 -2
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +1 -1
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +1 -1
- package/lib/WAUSync/USyncQuery.js +13 -17
- package/package.json +10 -5
- 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
- package/lib/Store/make-cache-manager-store.d.ts +0 -14
- package/lib/Store/make-cache-manager-store.js +0 -83
|
@@ -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
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SenderMessageKey = void 0;
|
|
4
|
+
const crypto_1 = require("libsignal/src/crypto");
|
|
2
5
|
class SenderMessageKey {
|
|
3
|
-
iteration = 0;
|
|
4
|
-
|
|
5
|
-
iv = Buffer.alloc(0);
|
|
6
|
-
|
|
7
|
-
cipherKey = Buffer.alloc(0);
|
|
8
|
-
|
|
9
|
-
seed = Buffer.alloc(0);
|
|
10
|
-
|
|
11
6
|
constructor(iteration, seed) {
|
|
12
|
-
const derivative = deriveSecrets(seed, Buffer.alloc(32), Buffer.from('WhisperGroup'));
|
|
7
|
+
const derivative = (0, crypto_1.deriveSecrets)(seed, Buffer.alloc(32), Buffer.from('WhisperGroup'));
|
|
13
8
|
const keys = new Uint8Array(32);
|
|
14
9
|
keys.set(new Uint8Array(derivative[0].slice(16)));
|
|
15
10
|
keys.set(new Uint8Array(derivative[1].slice(0, 16)), 16);
|
|
16
11
|
this.iv = Buffer.from(derivative[0].slice(0, 16));
|
|
17
12
|
this.cipherKey = Buffer.from(keys.buffer);
|
|
18
|
-
|
|
19
13
|
this.iteration = iteration;
|
|
20
14
|
this.seed = seed;
|
|
21
15
|
}
|
|
22
|
-
|
|
23
16
|
getIteration() {
|
|
24
17
|
return this.iteration;
|
|
25
18
|
}
|
|
26
|
-
|
|
27
19
|
getIv() {
|
|
28
20
|
return this.iv;
|
|
29
21
|
}
|
|
30
|
-
|
|
31
22
|
getCipherKey() {
|
|
32
23
|
return this.cipherKey;
|
|
33
24
|
}
|
|
34
|
-
|
|
35
25
|
getSeed() {
|
|
36
26
|
return this.seed;
|
|
37
27
|
}
|
|
38
28
|
}
|
|
39
|
-
|
|
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
|
};
|
|
@@ -11,5 +11,6 @@ export declare abstract class AbstractSocketClient extends EventEmitter {
|
|
|
11
11
|
constructor(url: URL, config: SocketConfig);
|
|
12
12
|
abstract connect(): Promise<void>;
|
|
13
13
|
abstract close(): Promise<void>;
|
|
14
|
+
abstract restart(): Promise<void>;
|
|
14
15
|
abstract send(str: Uint8Array | string, cb?: (err?: Error) => void): boolean;
|
|
15
16
|
}
|
|
@@ -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'];
|
|
@@ -53,6 +53,16 @@ class WebSocketClient extends types_1.AbstractSocketClient {
|
|
|
53
53
|
this.socket.close();
|
|
54
54
|
this.socket = null;
|
|
55
55
|
}
|
|
56
|
+
async restart() {
|
|
57
|
+
if (this.socket) {
|
|
58
|
+
await new Promise(resolve => {
|
|
59
|
+
this.socket.once('close', resolve);
|
|
60
|
+
this.socket.terminate();
|
|
61
|
+
});
|
|
62
|
+
this.socket = null;
|
|
63
|
+
}
|
|
64
|
+
await this.connect();
|
|
65
|
+
}
|
|
56
66
|
send(str, cb) {
|
|
57
67
|
var _a;
|
|
58
68
|
(_a = this.socket) === null || _a === void 0 ? void 0 : _a.send(str, cb);
|
package/lib/Socket/business.d.ts
CHANGED
|
@@ -30,7 +30,6 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
|
|
|
30
30
|
relayMessage: (jid: string, message: import("../Types").WAProto.IMessage, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }: import("../Types").MessageRelayOptions) => Promise<string>;
|
|
31
31
|
sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type: import("../Types").MessageReceiptType) => Promise<void>;
|
|
32
32
|
sendReceipts: (keys: import("../Types").WAMessageKey[], type: import("../Types").MessageReceiptType) => Promise<void>;
|
|
33
|
-
getButtonArgs: (message: import("../Types").WAProto.IMessage) => BinaryNode["attrs"];
|
|
34
33
|
readMessages: (keys: import("../Types").WAMessageKey[]) => Promise<void>;
|
|
35
34
|
refreshMediaConn: (forceGet?: boolean) => Promise<import("../Types").MediaConnInfo>;
|
|
36
35
|
waUploadToServer: import("../Types").WAMediaUploadFunction;
|
|
@@ -44,7 +43,7 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
|
|
|
44
43
|
}>;
|
|
45
44
|
sendPeerDataOperationMessage: (pdoMessage: import("../Types").WAProto.Message.IPeerDataOperationRequestMessage) => Promise<string>;
|
|
46
45
|
updateMediaMessage: (message: import("../Types").WAProto.IWebMessageInfo) => Promise<import("../Types").WAProto.IWebMessageInfo>;
|
|
47
|
-
sendMessage: (jid: string, content: import("../Types").AnyMessageContent, options?: import("../Types").MiscMessageGenerationOptions) => Promise<import("../Types").WAProto.WebMessageInfo
|
|
46
|
+
sendMessage: (jid: string, content: import("../Types").AnyMessageContent, options?: import("../Types").MiscMessageGenerationOptions) => Promise<import("../Types").WAProto.WebMessageInfo>;
|
|
48
47
|
subscribeNewsletterUpdates: (jid: string) => Promise<{
|
|
49
48
|
duration: string;
|
|
50
49
|
}>;
|
|
@@ -66,6 +65,7 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
|
|
|
66
65
|
newsletterReactMessage: (jid: string, server_id: string, code?: string) => Promise<void>;
|
|
67
66
|
newsletterFetchMessages: (type: "invite" | "jid", key: string, count: number, after?: number) => Promise<import("../Types").NewsletterFetchedUpdate[]>;
|
|
68
67
|
newsletterFetchUpdates: (jid: string, count: number, after?: number, since?: number) => Promise<import("../Types").NewsletterFetchedUpdate[]>;
|
|
68
|
+
groupQuery: (jid: string, type: "get" | "set", content: BinaryNode[]) => Promise<any>;
|
|
69
69
|
groupMetadata: (jid: string) => Promise<import("../Types").GroupMetadata>;
|
|
70
70
|
groupCreate: (subject: string, participants: string[]) => Promise<import("../Types").GroupMetadata>;
|
|
71
71
|
groupLeave: (id: string) => Promise<void>;
|
|
@@ -114,8 +114,8 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
|
|
|
114
114
|
fetchDisappearingDuration: (...jids: string[]) => Promise<import("..").USyncQueryResultList[] | undefined>;
|
|
115
115
|
fetchStatus: (...jids: string[]) => Promise<import("..").USyncQueryResultList[] | undefined>;
|
|
116
116
|
updateProfilePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>;
|
|
117
|
-
updateProfilePictureFull:
|
|
118
|
-
updateProfilePictureFull2:
|
|
117
|
+
updateProfilePictureFull: any;
|
|
118
|
+
updateProfilePictureFull2: any;
|
|
119
119
|
removeProfilePicture: (jid: string) => Promise<void>;
|
|
120
120
|
updateProfileStatus: (status: string) => Promise<void>;
|
|
121
121
|
updateProfileName: (name: string) => Promise<void>;
|
|
@@ -130,12 +130,9 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
|
|
|
130
130
|
updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyGroupAddValue) => Promise<void>;
|
|
131
131
|
updateDefaultDisappearingMode: (duration: number) => Promise<void>;
|
|
132
132
|
getBusinessProfile: (jid: string) => Promise<import("../Types").WABusinessProfile | void>;
|
|
133
|
-
resyncAppState: (collections: readonly ("
|
|
133
|
+
resyncAppState: (collections: readonly ("critical_unblock_low" | "regular_high" | "regular_low" | "critical_block" | "regular")[], isInitialSync: boolean) => Promise<void>;
|
|
134
134
|
chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>;
|
|
135
135
|
cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: number | string) => Promise<void>;
|
|
136
|
-
addOrEditContact: (jid: string, contact: import("../Types").ContactAction) => Promise<void>;
|
|
137
|
-
removeContact: (jid: string) => Promise<void>;
|
|
138
|
-
addLabel: (jid: string, labels: import("../Types/Label").LabelActionBody) => Promise<void>;
|
|
139
136
|
addChatLabel: (jid: string, labelId: string) => Promise<void>;
|
|
140
137
|
removeChatLabel: (jid: string, labelId: string) => Promise<void>;
|
|
141
138
|
addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|