@baileys-md/baileys 11.0.3 → 11.1.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 +1 -1
- package/README.md +1 -1
- package/WAProto/index.js +4182 -13516
- package/WASignalGroup/GroupProtocol.js +1697 -0
- package/WASignalGroup/ciphertext_message.js +16 -0
- package/WASignalGroup/group_cipher.js +120 -0
- package/WASignalGroup/group_session_builder.js +46 -0
- package/WASignalGroup/index.js +5 -0
- package/WASignalGroup/keyhelper.js +21 -0
- package/WASignalGroup/protobufs.js +3 -0
- package/WASignalGroup/queue_job.js +69 -0
- package/WASignalGroup/sender_chain_key.js +50 -0
- package/WASignalGroup/sender_key_distribution_message.js +78 -0
- package/WASignalGroup/sender_key_message.js +92 -0
- package/WASignalGroup/sender_key_name.js +70 -0
- package/WASignalGroup/sender_key_record.js +56 -0
- package/WASignalGroup/sender_key_state.js +129 -0
- package/{lib/Signal/Group/sender-message-key.js → WASignalGroup/sender_message_key.js} +16 -4
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/index.js +71 -52
- package/lib/Defaults/{phonenumber-mcc.js → phonenumber-mcc.json} +1 -1
- package/lib/Signal/libsignal.js +61 -41
- package/lib/Socket/Client/abstract-socket-client.js +13 -0
- package/lib/Socket/Client/index.js +19 -3
- package/lib/Socket/Client/mobile-socket-client.js +65 -0
- package/lib/Socket/Client/web-socket-client.js +62 -0
- package/lib/Socket/business.js +42 -37
- package/lib/Socket/chats.js +187 -194
- package/lib/Socket/groups.js +90 -87
- package/lib/Socket/index.js +8 -7
- package/lib/Socket/messages-recv.js +335 -360
- package/lib/Socket/messages-send.js +279 -156
- package/lib/Socket/newsletter.js +213 -144
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.js +161 -128
- package/lib/Socket/usync.js +26 -19
- package/lib/Store/index.js +8 -0
- package/lib/Store/make-cache-manager-store.js +83 -0
- package/lib/{Utils → Store}/make-in-memory-store.js +27 -19
- package/lib/Store/make-mongo-store.js +567 -0
- package/lib/{Utils → Store}/make-ordered-dictionary.js +5 -2
- package/lib/{Utils → Store}/object-repository.js +4 -1
- package/lib/Types/Auth.js +2 -2
- package/lib/Types/Call.js +2 -2
- package/lib/Types/Chat.js +4 -8
- package/lib/Types/Contact.js +2 -2
- package/lib/Types/Events.js +2 -2
- package/lib/Types/GroupMetadata.js +2 -2
- package/lib/Types/Label.js +5 -3
- package/lib/Types/LabelAssociation.js +5 -3
- package/lib/Types/Message.js +7 -7
- package/lib/Types/Newsletter.js +17 -30
- package/lib/Types/Product.js +2 -2
- package/lib/Types/Signal.js +2 -2
- package/lib/Types/Socket.js +2 -3
- package/lib/Types/State.js +2 -2
- package/lib/Types/USync.js +2 -2
- package/lib/Types/index.js +31 -15
- package/lib/Utils/auth-utils.js +47 -31
- package/lib/Utils/baileys-event-stream.js +22 -15
- package/lib/Utils/business.js +69 -66
- package/lib/Utils/chat-utils.js +195 -200
- package/lib/Utils/crypto.js +85 -70
- package/lib/Utils/decode-wa-message.js +51 -46
- package/lib/Utils/event-buffer.js +46 -36
- package/lib/Utils/generics.js +188 -116
- package/lib/Utils/history.js +46 -37
- package/lib/Utils/index.js +33 -19
- package/lib/Utils/link-preview.js +55 -14
- package/lib/Utils/logger.js +7 -3
- package/lib/Utils/lt-hash.js +26 -23
- package/lib/Utils/make-mutex.js +10 -7
- package/lib/Utils/messages-media.js +368 -239
- package/lib/Utils/messages.js +510 -278
- package/lib/Utils/noise-handler.js +31 -22
- package/lib/Utils/process-message.js +148 -144
- package/lib/Utils/signal.js +64 -71
- package/lib/Utils/use-multi-file-auth-state.js +32 -14
- package/lib/Utils/validate-connection.js +115 -72
- package/lib/WABinary/constants.js +20 -1281
- package/lib/WABinary/decode.js +52 -15
- package/lib/WABinary/encode.js +48 -14
- package/lib/WABinary/generic-utils.js +39 -31
- package/lib/WABinary/index.js +21 -6
- package/lib/WABinary/jid-utils.js +40 -23
- package/lib/WABinary/types.js +2 -2
- package/lib/WAM/BinaryInfo.js +5 -2
- package/lib/WAM/constants.js +2366 -2257
- package/lib/WAM/encode.js +21 -17
- package/lib/WAM/index.js +19 -4
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +11 -8
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +14 -11
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +12 -9
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +13 -9
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +22 -20
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +6 -3
- package/lib/WAUSync/Protocols/index.js +20 -5
- package/lib/WAUSync/USyncQuery.js +32 -34
- package/lib/WAUSync/USyncUser.js +5 -2
- package/lib/WAUSync/index.js +19 -4
- package/lib/index.js +33 -11
- package/package.json +61 -21
- package/WAProto/GenerateStatics.sh +0 -3
- package/WAProto/WAProto.proto +0 -4633
- package/WAProto/fix-imports.js +0 -29
- package/lib/Defaults/baileys-version.js +0 -1
- package/lib/Signal/Group/ciphertext-message.js +0 -12
- package/lib/Signal/Group/group-session-builder.js +0 -30
- package/lib/Signal/Group/group_cipher.js +0 -94
- package/lib/Signal/Group/index.js +0 -12
- package/lib/Signal/Group/keyhelper.js +0 -19
- package/lib/Signal/Group/queue-job.js +0 -54
- package/lib/Signal/Group/sender-chain-key.js +0 -32
- package/lib/Signal/Group/sender-key-distribution-message.js +0 -63
- package/lib/Signal/Group/sender-key-message.js +0 -67
- package/lib/Signal/Group/sender-key-name.js +0 -48
- package/lib/Signal/Group/sender-key-record.js +0 -50
- package/lib/Signal/Group/sender-key-state.js +0 -96
- package/lib/Socket/Client/types.js +0 -11
- package/lib/Socket/Client/websocket.js +0 -50
- package/lib/Socket/communities.js +0 -351
- package/lib/Socket/mex.js +0 -42
package/WAProto/fix-imports.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { readFileSync, writeFileSync } from 'fs';
|
|
2
|
-
import { argv, exit } from 'process';
|
|
3
|
-
|
|
4
|
-
const filePath = './index.js';
|
|
5
|
-
|
|
6
|
-
try {
|
|
7
|
-
// Read the file
|
|
8
|
-
let content = readFileSync(filePath, 'utf8');
|
|
9
|
-
|
|
10
|
-
// Fix the import statement
|
|
11
|
-
content = content.replace(
|
|
12
|
-
/import \* as (\$protobuf) from/g,
|
|
13
|
-
'import $1 from'
|
|
14
|
-
);
|
|
15
|
-
|
|
16
|
-
// add missing extension to the import
|
|
17
|
-
content = content.replace(
|
|
18
|
-
/(['"])protobufjs\/minimal(['"])/g,
|
|
19
|
-
'$1protobufjs/minimal.js$2'
|
|
20
|
-
);
|
|
21
|
-
|
|
22
|
-
// Write back
|
|
23
|
-
writeFileSync(filePath, content, 'utf8');
|
|
24
|
-
|
|
25
|
-
console.log(`✅ Fixed imports in ${filePath}`);
|
|
26
|
-
} catch (error) {
|
|
27
|
-
console.error(`❌ Error fixing imports: ${error.message}`);
|
|
28
|
-
exit(1);
|
|
29
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const version = [2, 3000, 1023223821]
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export class CiphertextMessage {
|
|
2
|
-
constructor() {
|
|
3
|
-
this.UNSUPPORTED_VERSION = 1;
|
|
4
|
-
this.CURRENT_VERSION = 3;
|
|
5
|
-
this.WHISPER_TYPE = 2;
|
|
6
|
-
this.PREKEY_TYPE = 3;
|
|
7
|
-
this.SENDERKEY_TYPE = 4;
|
|
8
|
-
this.SENDERKEY_DISTRIBUTION_TYPE = 5;
|
|
9
|
-
this.ENCRYPTED_MESSAGE_OVERHEAD = 53;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=ciphertext-message.js.map
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import * as keyhelper from './keyhelper.js';
|
|
2
|
-
import { SenderKeyDistributionMessage } from './sender-key-distribution-message.js';
|
|
3
|
-
import { SenderKeyName } from './sender-key-name.js';
|
|
4
|
-
import { SenderKeyRecord } from './sender-key-record.js';
|
|
5
|
-
export class GroupSessionBuilder {
|
|
6
|
-
constructor(senderKeyStore) {
|
|
7
|
-
this.senderKeyStore = senderKeyStore;
|
|
8
|
-
}
|
|
9
|
-
async process(senderKeyName, senderKeyDistributionMessage) {
|
|
10
|
-
const senderKeyRecord = await this.senderKeyStore.loadSenderKey(senderKeyName);
|
|
11
|
-
senderKeyRecord.addSenderKeyState(senderKeyDistributionMessage.getId(), senderKeyDistributionMessage.getIteration(), senderKeyDistributionMessage.getChainKey(), senderKeyDistributionMessage.getSignatureKey());
|
|
12
|
-
await this.senderKeyStore.storeSenderKey(senderKeyName, senderKeyRecord);
|
|
13
|
-
}
|
|
14
|
-
async create(senderKeyName) {
|
|
15
|
-
const senderKeyRecord = await this.senderKeyStore.loadSenderKey(senderKeyName);
|
|
16
|
-
if (senderKeyRecord.isEmpty()) {
|
|
17
|
-
const keyId = keyhelper.generateSenderKeyId();
|
|
18
|
-
const senderKey = keyhelper.generateSenderKey();
|
|
19
|
-
const signingKey = keyhelper.generateSenderSigningKey();
|
|
20
|
-
senderKeyRecord.setSenderKeyState(keyId, 0, senderKey, signingKey);
|
|
21
|
-
await this.senderKeyStore.storeSenderKey(senderKeyName, senderKeyRecord);
|
|
22
|
-
}
|
|
23
|
-
const state = senderKeyRecord.getSenderKeyState();
|
|
24
|
-
if (!state) {
|
|
25
|
-
throw new Error('No session state available');
|
|
26
|
-
}
|
|
27
|
-
return new SenderKeyDistributionMessage(state.getKeyId(), state.getSenderChainKey().getIteration(), state.getSenderChainKey().getSeed(), state.getSigningKeyPublic());
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
//# sourceMappingURL=group-session-builder.js.map
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
/* @ts-ignore */
|
|
2
|
-
import { decrypt, encrypt } from 'libsignal/src/crypto.js';
|
|
3
|
-
import queueJob from './queue-job.js';
|
|
4
|
-
import { SenderKeyMessage } from './sender-key-message.js';
|
|
5
|
-
import { SenderKeyName } from './sender-key-name.js';
|
|
6
|
-
import { SenderKeyRecord } from './sender-key-record.js';
|
|
7
|
-
import { SenderKeyState } from './sender-key-state.js';
|
|
8
|
-
export class GroupCipher {
|
|
9
|
-
constructor(senderKeyStore, senderKeyName) {
|
|
10
|
-
this.senderKeyStore = senderKeyStore;
|
|
11
|
-
this.senderKeyName = senderKeyName;
|
|
12
|
-
}
|
|
13
|
-
queueJob(awaitable) {
|
|
14
|
-
return queueJob(this.senderKeyName.toString(), awaitable);
|
|
15
|
-
}
|
|
16
|
-
async encrypt(paddedPlaintext) {
|
|
17
|
-
return await this.queueJob(async () => {
|
|
18
|
-
const record = await this.senderKeyStore.loadSenderKey(this.senderKeyName);
|
|
19
|
-
if (!record) {
|
|
20
|
-
throw new Error('No SenderKeyRecord found for encryption');
|
|
21
|
-
}
|
|
22
|
-
const senderKeyState = record.getSenderKeyState();
|
|
23
|
-
if (!senderKeyState) {
|
|
24
|
-
throw new Error('No session to encrypt message');
|
|
25
|
-
}
|
|
26
|
-
const iteration = senderKeyState.getSenderChainKey().getIteration();
|
|
27
|
-
const senderKey = this.getSenderKey(senderKeyState, iteration === 0 ? 0 : iteration + 1);
|
|
28
|
-
const ciphertext = await this.getCipherText(senderKey.getIv(), senderKey.getCipherKey(), paddedPlaintext);
|
|
29
|
-
const senderKeyMessage = new SenderKeyMessage(senderKeyState.getKeyId(), senderKey.getIteration(), ciphertext, senderKeyState.getSigningKeyPrivate());
|
|
30
|
-
await this.senderKeyStore.storeSenderKey(this.senderKeyName, record);
|
|
31
|
-
return senderKeyMessage.serialize();
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
async decrypt(senderKeyMessageBytes) {
|
|
35
|
-
return await this.queueJob(async () => {
|
|
36
|
-
const record = await this.senderKeyStore.loadSenderKey(this.senderKeyName);
|
|
37
|
-
if (!record) {
|
|
38
|
-
throw new Error('No SenderKeyRecord found for decryption');
|
|
39
|
-
}
|
|
40
|
-
const senderKeyMessage = new SenderKeyMessage(null, null, null, null, senderKeyMessageBytes);
|
|
41
|
-
const senderKeyState = record.getSenderKeyState(senderKeyMessage.getKeyId());
|
|
42
|
-
if (!senderKeyState) {
|
|
43
|
-
throw new Error('No session found to decrypt message');
|
|
44
|
-
}
|
|
45
|
-
senderKeyMessage.verifySignature(senderKeyState.getSigningKeyPublic());
|
|
46
|
-
const senderKey = this.getSenderKey(senderKeyState, senderKeyMessage.getIteration());
|
|
47
|
-
const plaintext = await this.getPlainText(senderKey.getIv(), senderKey.getCipherKey(), senderKeyMessage.getCipherText());
|
|
48
|
-
await this.senderKeyStore.storeSenderKey(this.senderKeyName, record);
|
|
49
|
-
return plaintext;
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
getSenderKey(senderKeyState, iteration) {
|
|
53
|
-
let senderChainKey = senderKeyState.getSenderChainKey();
|
|
54
|
-
if (senderChainKey.getIteration() > iteration) {
|
|
55
|
-
if (senderKeyState.hasSenderMessageKey(iteration)) {
|
|
56
|
-
const messageKey = senderKeyState.removeSenderMessageKey(iteration);
|
|
57
|
-
if (!messageKey) {
|
|
58
|
-
throw new Error('No sender message key found for iteration');
|
|
59
|
-
}
|
|
60
|
-
return messageKey;
|
|
61
|
-
}
|
|
62
|
-
throw new Error(`Received message with old counter: ${senderChainKey.getIteration()}, ${iteration}`);
|
|
63
|
-
}
|
|
64
|
-
if (iteration - senderChainKey.getIteration() > 2000) {
|
|
65
|
-
throw new Error('Over 2000 messages into the future!');
|
|
66
|
-
}
|
|
67
|
-
while (senderChainKey.getIteration() < iteration) {
|
|
68
|
-
senderKeyState.addSenderMessageKey(senderChainKey.getSenderMessageKey());
|
|
69
|
-
senderChainKey = senderChainKey.getNext();
|
|
70
|
-
}
|
|
71
|
-
senderKeyState.setSenderChainKey(senderChainKey.getNext());
|
|
72
|
-
return senderChainKey.getSenderMessageKey();
|
|
73
|
-
}
|
|
74
|
-
async getPlainText(iv, key, ciphertext) {
|
|
75
|
-
try {
|
|
76
|
-
return decrypt(key, ciphertext, iv);
|
|
77
|
-
}
|
|
78
|
-
catch (e) {
|
|
79
|
-
throw new Error('InvalidMessageException');
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
async getCipherText(iv, key, plaintext) {
|
|
83
|
-
try {
|
|
84
|
-
const ivBuffer = typeof iv === 'string' ? Buffer.from(iv, 'base64') : iv;
|
|
85
|
-
const keyBuffer = typeof key === 'string' ? Buffer.from(key, 'base64') : key;
|
|
86
|
-
const plaintextBuffer = typeof plaintext === 'string' ? Buffer.from(plaintext) : plaintext;
|
|
87
|
-
return encrypt(keyBuffer, plaintextBuffer, ivBuffer);
|
|
88
|
-
}
|
|
89
|
-
catch (e) {
|
|
90
|
-
throw new Error('InvalidMessageException');
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
//# sourceMappingURL=group_cipher.js.map
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export { GroupSessionBuilder } from './group-session-builder.js';
|
|
2
|
-
export { SenderKeyDistributionMessage } from './sender-key-distribution-message.js';
|
|
3
|
-
export { SenderKeyRecord } from './sender-key-record.js';
|
|
4
|
-
export { SenderKeyName } from './sender-key-name.js';
|
|
5
|
-
export { GroupCipher } from './group_cipher.js';
|
|
6
|
-
export { SenderKeyState } from './sender-key-state.js';
|
|
7
|
-
export { SenderKeyMessage } from './sender-key-message.js';
|
|
8
|
-
export { SenderMessageKey } from './sender-message-key.js';
|
|
9
|
-
export { SenderChainKey } from './sender-chain-key.js';
|
|
10
|
-
export { CiphertextMessage } from './ciphertext-message.js';
|
|
11
|
-
export * as keyhelper from './keyhelper.js';
|
|
12
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import * as nodeCrypto from 'crypto';
|
|
2
|
-
/* @ts-ignore */
|
|
3
|
-
import { generateKeyPair } from 'libsignal/src/curve.js';
|
|
4
|
-
export function generateSenderKey() {
|
|
5
|
-
return nodeCrypto.randomBytes(32);
|
|
6
|
-
}
|
|
7
|
-
export function generateSenderKeyId() {
|
|
8
|
-
return nodeCrypto.randomInt(2147483647);
|
|
9
|
-
}
|
|
10
|
-
export function generateSenderSigningKey(key) {
|
|
11
|
-
if (!key) {
|
|
12
|
-
key = generateKeyPair();
|
|
13
|
-
}
|
|
14
|
-
return {
|
|
15
|
-
public: Buffer.from(key.pubKey),
|
|
16
|
-
private: Buffer.from(key.privKey)
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
//# sourceMappingURL=keyhelper.js.map
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
const _queueAsyncBuckets = new Map();
|
|
2
|
-
const _gcLimit = 10000;
|
|
3
|
-
async function _asyncQueueExecutor(queue, cleanup) {
|
|
4
|
-
let offt = 0;
|
|
5
|
-
while (true) {
|
|
6
|
-
const limit = Math.min(queue.length, _gcLimit);
|
|
7
|
-
for (let i = offt; i < limit; i++) {
|
|
8
|
-
const job = queue[i];
|
|
9
|
-
try {
|
|
10
|
-
job.resolve(await job.awaitable());
|
|
11
|
-
}
|
|
12
|
-
catch (e) {
|
|
13
|
-
job.reject(e);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
if (limit < queue.length) {
|
|
17
|
-
if (limit >= _gcLimit) {
|
|
18
|
-
queue.splice(0, limit);
|
|
19
|
-
offt = 0;
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
offt = limit;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
break;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
cleanup();
|
|
30
|
-
}
|
|
31
|
-
export default function queueJob(bucket, awaitable) {
|
|
32
|
-
// Skip name assignment since it's readonly in strict mode
|
|
33
|
-
if (typeof bucket !== 'string') {
|
|
34
|
-
console.warn('Unhandled bucket type (for naming):', typeof bucket, bucket);
|
|
35
|
-
}
|
|
36
|
-
let inactive = false;
|
|
37
|
-
if (!_queueAsyncBuckets.has(bucket)) {
|
|
38
|
-
_queueAsyncBuckets.set(bucket, []);
|
|
39
|
-
inactive = true;
|
|
40
|
-
}
|
|
41
|
-
const queue = _queueAsyncBuckets.get(bucket);
|
|
42
|
-
const job = new Promise((resolve, reject) => {
|
|
43
|
-
queue.push({
|
|
44
|
-
awaitable,
|
|
45
|
-
resolve: resolve,
|
|
46
|
-
reject
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
if (inactive) {
|
|
50
|
-
_asyncQueueExecutor(queue, () => _queueAsyncBuckets.delete(bucket));
|
|
51
|
-
}
|
|
52
|
-
return job;
|
|
53
|
-
}
|
|
54
|
-
//# sourceMappingURL=queue-job.js.map
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/* @ts-ignore */
|
|
2
|
-
import { calculateMAC } from 'libsignal/src/crypto.js';
|
|
3
|
-
import { SenderMessageKey } from './sender-message-key.js';
|
|
4
|
-
export class SenderChainKey {
|
|
5
|
-
constructor(iteration, chainKey) {
|
|
6
|
-
this.MESSAGE_KEY_SEED = Buffer.from([0x01]);
|
|
7
|
-
this.CHAIN_KEY_SEED = Buffer.from([0x02]);
|
|
8
|
-
this.iteration = iteration;
|
|
9
|
-
if (chainKey instanceof Buffer) {
|
|
10
|
-
this.chainKey = chainKey;
|
|
11
|
-
}
|
|
12
|
-
else {
|
|
13
|
-
this.chainKey = Buffer.from(chainKey || []);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
getIteration() {
|
|
17
|
-
return this.iteration;
|
|
18
|
-
}
|
|
19
|
-
getSenderMessageKey() {
|
|
20
|
-
return new SenderMessageKey(this.iteration, this.getDerivative(this.MESSAGE_KEY_SEED, this.chainKey));
|
|
21
|
-
}
|
|
22
|
-
getNext() {
|
|
23
|
-
return new SenderChainKey(this.iteration + 1, this.getDerivative(this.CHAIN_KEY_SEED, this.chainKey));
|
|
24
|
-
}
|
|
25
|
-
getSeed() {
|
|
26
|
-
return this.chainKey;
|
|
27
|
-
}
|
|
28
|
-
getDerivative(seed, key) {
|
|
29
|
-
return calculateMAC(key, seed);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
//# sourceMappingURL=sender-chain-key.js.map
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { proto } from '../../../WAProto/index.js';
|
|
2
|
-
import { CiphertextMessage } from './ciphertext-message.js';
|
|
3
|
-
export class SenderKeyDistributionMessage extends CiphertextMessage {
|
|
4
|
-
constructor(id, iteration, chainKey, signatureKey, serialized) {
|
|
5
|
-
super();
|
|
6
|
-
if (serialized) {
|
|
7
|
-
try {
|
|
8
|
-
const message = serialized.slice(1);
|
|
9
|
-
const distributionMessage = proto.SenderKeyDistributionMessage.decode(message).toJSON();
|
|
10
|
-
this.serialized = serialized;
|
|
11
|
-
this.id = distributionMessage.id;
|
|
12
|
-
this.iteration = distributionMessage.iteration;
|
|
13
|
-
this.chainKey =
|
|
14
|
-
typeof distributionMessage.chainKey === 'string'
|
|
15
|
-
? Buffer.from(distributionMessage.chainKey, 'base64')
|
|
16
|
-
: distributionMessage.chainKey;
|
|
17
|
-
this.signatureKey =
|
|
18
|
-
typeof distributionMessage.signingKey === 'string'
|
|
19
|
-
? Buffer.from(distributionMessage.signingKey, 'base64')
|
|
20
|
-
: distributionMessage.signingKey;
|
|
21
|
-
}
|
|
22
|
-
catch (e) {
|
|
23
|
-
throw new Error(String(e));
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
const version = this.intsToByteHighAndLow(this.CURRENT_VERSION, this.CURRENT_VERSION);
|
|
28
|
-
this.id = id;
|
|
29
|
-
this.iteration = iteration;
|
|
30
|
-
this.chainKey = chainKey;
|
|
31
|
-
this.signatureKey = signatureKey;
|
|
32
|
-
const message = proto.SenderKeyDistributionMessage.encode(proto.SenderKeyDistributionMessage.create({
|
|
33
|
-
id,
|
|
34
|
-
iteration,
|
|
35
|
-
chainKey,
|
|
36
|
-
signingKey: this.signatureKey
|
|
37
|
-
})).finish();
|
|
38
|
-
this.serialized = Buffer.concat([Buffer.from([version]), message]);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
intsToByteHighAndLow(highValue, lowValue) {
|
|
42
|
-
return (((highValue << 4) | lowValue) & 0xff) % 256;
|
|
43
|
-
}
|
|
44
|
-
serialize() {
|
|
45
|
-
return this.serialized;
|
|
46
|
-
}
|
|
47
|
-
getType() {
|
|
48
|
-
return this.SENDERKEY_DISTRIBUTION_TYPE;
|
|
49
|
-
}
|
|
50
|
-
getIteration() {
|
|
51
|
-
return this.iteration;
|
|
52
|
-
}
|
|
53
|
-
getChainKey() {
|
|
54
|
-
return typeof this.chainKey === 'string' ? Buffer.from(this.chainKey, 'base64') : this.chainKey;
|
|
55
|
-
}
|
|
56
|
-
getSignatureKey() {
|
|
57
|
-
return typeof this.signatureKey === 'string' ? Buffer.from(this.signatureKey, 'base64') : this.signatureKey;
|
|
58
|
-
}
|
|
59
|
-
getId() {
|
|
60
|
-
return this.id;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
//# sourceMappingURL=sender-key-distribution-message.js.map
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
/* @ts-ignore */
|
|
2
|
-
import { calculateSignature, verifySignature } from 'libsignal/src/curve.js';
|
|
3
|
-
import { proto } from '../../../WAProto/index.js';
|
|
4
|
-
import { CiphertextMessage } from './ciphertext-message.js';
|
|
5
|
-
export class SenderKeyMessage extends CiphertextMessage {
|
|
6
|
-
constructor(keyId, iteration, ciphertext, signatureKey, serialized) {
|
|
7
|
-
super();
|
|
8
|
-
this.SIGNATURE_LENGTH = 64;
|
|
9
|
-
if (serialized) {
|
|
10
|
-
const version = serialized[0];
|
|
11
|
-
const message = serialized.slice(1, serialized.length - this.SIGNATURE_LENGTH);
|
|
12
|
-
const signature = serialized.slice(-1 * this.SIGNATURE_LENGTH);
|
|
13
|
-
const senderKeyMessage = proto.SenderKeyMessage.decode(message).toJSON();
|
|
14
|
-
this.serialized = serialized;
|
|
15
|
-
this.messageVersion = (version & 0xff) >> 4;
|
|
16
|
-
this.keyId = senderKeyMessage.id;
|
|
17
|
-
this.iteration = senderKeyMessage.iteration;
|
|
18
|
-
this.ciphertext =
|
|
19
|
-
typeof senderKeyMessage.ciphertext === 'string'
|
|
20
|
-
? Buffer.from(senderKeyMessage.ciphertext, 'base64')
|
|
21
|
-
: senderKeyMessage.ciphertext;
|
|
22
|
-
this.signature = signature;
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
const version = (((this.CURRENT_VERSION << 4) | this.CURRENT_VERSION) & 0xff) % 256;
|
|
26
|
-
const ciphertextBuffer = Buffer.from(ciphertext);
|
|
27
|
-
const message = proto.SenderKeyMessage.encode(proto.SenderKeyMessage.create({
|
|
28
|
-
id: keyId,
|
|
29
|
-
iteration: iteration,
|
|
30
|
-
ciphertext: ciphertextBuffer
|
|
31
|
-
})).finish();
|
|
32
|
-
const signature = this.getSignature(signatureKey, Buffer.concat([Buffer.from([version]), message]));
|
|
33
|
-
this.serialized = Buffer.concat([Buffer.from([version]), message, Buffer.from(signature)]);
|
|
34
|
-
this.messageVersion = this.CURRENT_VERSION;
|
|
35
|
-
this.keyId = keyId;
|
|
36
|
-
this.iteration = iteration;
|
|
37
|
-
this.ciphertext = ciphertextBuffer;
|
|
38
|
-
this.signature = signature;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
getKeyId() {
|
|
42
|
-
return this.keyId;
|
|
43
|
-
}
|
|
44
|
-
getIteration() {
|
|
45
|
-
return this.iteration;
|
|
46
|
-
}
|
|
47
|
-
getCipherText() {
|
|
48
|
-
return this.ciphertext;
|
|
49
|
-
}
|
|
50
|
-
verifySignature(signatureKey) {
|
|
51
|
-
const part1 = this.serialized.slice(0, this.serialized.length - this.SIGNATURE_LENGTH);
|
|
52
|
-
const part2 = this.serialized.slice(-1 * this.SIGNATURE_LENGTH);
|
|
53
|
-
const res = verifySignature(signatureKey, part1, part2);
|
|
54
|
-
if (!res)
|
|
55
|
-
throw new Error('Invalid signature!');
|
|
56
|
-
}
|
|
57
|
-
getSignature(signatureKey, serialized) {
|
|
58
|
-
return Buffer.from(calculateSignature(signatureKey, serialized));
|
|
59
|
-
}
|
|
60
|
-
serialize() {
|
|
61
|
-
return this.serialized;
|
|
62
|
-
}
|
|
63
|
-
getType() {
|
|
64
|
-
return 4;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
//# sourceMappingURL=sender-key-message.js.map
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
function isNull(str) {
|
|
2
|
-
return str === null || str === '';
|
|
3
|
-
}
|
|
4
|
-
function intValue(num) {
|
|
5
|
-
const MAX_VALUE = 0x7fffffff;
|
|
6
|
-
const MIN_VALUE = -0x80000000;
|
|
7
|
-
if (num > MAX_VALUE || num < MIN_VALUE) {
|
|
8
|
-
return num & 0xffffffff;
|
|
9
|
-
}
|
|
10
|
-
return num;
|
|
11
|
-
}
|
|
12
|
-
function hashCode(strKey) {
|
|
13
|
-
let hash = 0;
|
|
14
|
-
if (!isNull(strKey)) {
|
|
15
|
-
for (let i = 0; i < strKey.length; i++) {
|
|
16
|
-
hash = hash * 31 + strKey.charCodeAt(i);
|
|
17
|
-
hash = intValue(hash);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return hash;
|
|
21
|
-
}
|
|
22
|
-
export class SenderKeyName {
|
|
23
|
-
constructor(groupId, sender) {
|
|
24
|
-
this.groupId = groupId;
|
|
25
|
-
this.sender = sender;
|
|
26
|
-
}
|
|
27
|
-
getGroupId() {
|
|
28
|
-
return this.groupId;
|
|
29
|
-
}
|
|
30
|
-
getSender() {
|
|
31
|
-
return this.sender;
|
|
32
|
-
}
|
|
33
|
-
serialize() {
|
|
34
|
-
return `${this.groupId}::${this.sender.id}::${this.sender.deviceId}`;
|
|
35
|
-
}
|
|
36
|
-
toString() {
|
|
37
|
-
return this.serialize();
|
|
38
|
-
}
|
|
39
|
-
equals(other) {
|
|
40
|
-
if (other === null)
|
|
41
|
-
return false;
|
|
42
|
-
return this.groupId === other.groupId && this.sender.toString() === other.sender.toString();
|
|
43
|
-
}
|
|
44
|
-
hashCode() {
|
|
45
|
-
return hashCode(this.groupId) ^ hashCode(this.sender.toString());
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
//# sourceMappingURL=sender-key-name.js.map
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { BufferJSON } from '../../Utils/generics.js';
|
|
2
|
-
import { SenderKeyState } from './sender-key-state.js';
|
|
3
|
-
export class SenderKeyRecord {
|
|
4
|
-
constructor(serialized) {
|
|
5
|
-
this.MAX_STATES = 5;
|
|
6
|
-
this.senderKeyStates = [];
|
|
7
|
-
if (serialized) {
|
|
8
|
-
for (const structure of serialized) {
|
|
9
|
-
this.senderKeyStates.push(new SenderKeyState(null, null, null, null, null, null, structure));
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
isEmpty() {
|
|
14
|
-
return this.senderKeyStates.length === 0;
|
|
15
|
-
}
|
|
16
|
-
getSenderKeyState(keyId) {
|
|
17
|
-
if (keyId === undefined && this.senderKeyStates.length) {
|
|
18
|
-
return this.senderKeyStates[this.senderKeyStates.length - 1];
|
|
19
|
-
}
|
|
20
|
-
return this.senderKeyStates.find(state => state.getKeyId() === keyId);
|
|
21
|
-
}
|
|
22
|
-
addSenderKeyState(id, iteration, chainKey, signatureKey) {
|
|
23
|
-
this.senderKeyStates.push(new SenderKeyState(id, iteration, chainKey, null, signatureKey));
|
|
24
|
-
if (this.senderKeyStates.length > this.MAX_STATES) {
|
|
25
|
-
this.senderKeyStates.shift();
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
setSenderKeyState(id, iteration, chainKey, keyPair) {
|
|
29
|
-
this.senderKeyStates.length = 0;
|
|
30
|
-
this.senderKeyStates.push(new SenderKeyState(id, iteration, chainKey, keyPair));
|
|
31
|
-
}
|
|
32
|
-
serialize() {
|
|
33
|
-
return this.senderKeyStates.map(state => state.getStructure());
|
|
34
|
-
}
|
|
35
|
-
static deserialize(data) {
|
|
36
|
-
let parsed;
|
|
37
|
-
if (typeof data === 'string') {
|
|
38
|
-
parsed = JSON.parse(data, BufferJSON.reviver);
|
|
39
|
-
}
|
|
40
|
-
else if (data instanceof Uint8Array) {
|
|
41
|
-
const str = Buffer.from(data).toString('utf-8');
|
|
42
|
-
parsed = JSON.parse(str, BufferJSON.reviver);
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
parsed = data;
|
|
46
|
-
}
|
|
47
|
-
return new SenderKeyRecord(parsed);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
//# sourceMappingURL=sender-key-record.js.map
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { SenderChainKey } from './sender-chain-key.js';
|
|
2
|
-
import { SenderMessageKey } from './sender-message-key.js';
|
|
3
|
-
export class SenderKeyState {
|
|
4
|
-
constructor(id, iteration, chainKey, signatureKeyPair, signatureKeyPublic, signatureKeyPrivate, senderKeyStateStructure) {
|
|
5
|
-
this.MAX_MESSAGE_KEYS = 2000;
|
|
6
|
-
if (senderKeyStateStructure) {
|
|
7
|
-
this.senderKeyStateStructure = senderKeyStateStructure;
|
|
8
|
-
}
|
|
9
|
-
else {
|
|
10
|
-
if (signatureKeyPair) {
|
|
11
|
-
signatureKeyPublic = signatureKeyPair.public;
|
|
12
|
-
signatureKeyPrivate = signatureKeyPair.private;
|
|
13
|
-
}
|
|
14
|
-
chainKey = typeof chainKey === 'string' ? Buffer.from(chainKey, 'base64') : chainKey;
|
|
15
|
-
const senderChainKeyStructure = {
|
|
16
|
-
iteration: iteration || 0,
|
|
17
|
-
seed: chainKey || Buffer.alloc(0)
|
|
18
|
-
};
|
|
19
|
-
const signingKeyStructure = {
|
|
20
|
-
public: typeof signatureKeyPublic === 'string'
|
|
21
|
-
? Buffer.from(signatureKeyPublic, 'base64')
|
|
22
|
-
: signatureKeyPublic || Buffer.alloc(0)
|
|
23
|
-
};
|
|
24
|
-
if (signatureKeyPrivate) {
|
|
25
|
-
signingKeyStructure.private =
|
|
26
|
-
typeof signatureKeyPrivate === 'string' ? Buffer.from(signatureKeyPrivate, 'base64') : signatureKeyPrivate;
|
|
27
|
-
}
|
|
28
|
-
this.senderKeyStateStructure = {
|
|
29
|
-
senderKeyId: id || 0,
|
|
30
|
-
senderChainKey: senderChainKeyStructure,
|
|
31
|
-
senderSigningKey: signingKeyStructure,
|
|
32
|
-
senderMessageKeys: []
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
getKeyId() {
|
|
37
|
-
return this.senderKeyStateStructure.senderKeyId;
|
|
38
|
-
}
|
|
39
|
-
getSenderChainKey() {
|
|
40
|
-
return new SenderChainKey(this.senderKeyStateStructure.senderChainKey.iteration, this.senderKeyStateStructure.senderChainKey.seed);
|
|
41
|
-
}
|
|
42
|
-
setSenderChainKey(chainKey) {
|
|
43
|
-
this.senderKeyStateStructure.senderChainKey = {
|
|
44
|
-
iteration: chainKey.getIteration(),
|
|
45
|
-
seed: chainKey.getSeed()
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
getSigningKeyPublic() {
|
|
49
|
-
const publicKey = this.senderKeyStateStructure.senderSigningKey.public;
|
|
50
|
-
if (publicKey instanceof Buffer) {
|
|
51
|
-
return publicKey;
|
|
52
|
-
}
|
|
53
|
-
else if (typeof publicKey === 'string') {
|
|
54
|
-
return Buffer.from(publicKey, 'base64');
|
|
55
|
-
}
|
|
56
|
-
return Buffer.from(publicKey || []);
|
|
57
|
-
}
|
|
58
|
-
getSigningKeyPrivate() {
|
|
59
|
-
const privateKey = this.senderKeyStateStructure.senderSigningKey.private;
|
|
60
|
-
if (!privateKey) {
|
|
61
|
-
return undefined;
|
|
62
|
-
}
|
|
63
|
-
if (privateKey instanceof Buffer) {
|
|
64
|
-
return privateKey;
|
|
65
|
-
}
|
|
66
|
-
else if (typeof privateKey === 'string') {
|
|
67
|
-
return Buffer.from(privateKey, 'base64');
|
|
68
|
-
}
|
|
69
|
-
return Buffer.from(privateKey || []);
|
|
70
|
-
}
|
|
71
|
-
hasSenderMessageKey(iteration) {
|
|
72
|
-
return this.senderKeyStateStructure.senderMessageKeys.some(key => key.iteration === iteration);
|
|
73
|
-
}
|
|
74
|
-
addSenderMessageKey(senderMessageKey) {
|
|
75
|
-
this.senderKeyStateStructure.senderMessageKeys.push({
|
|
76
|
-
iteration: senderMessageKey.getIteration(),
|
|
77
|
-
seed: senderMessageKey.getSeed()
|
|
78
|
-
});
|
|
79
|
-
if (this.senderKeyStateStructure.senderMessageKeys.length > this.MAX_MESSAGE_KEYS) {
|
|
80
|
-
this.senderKeyStateStructure.senderMessageKeys.shift();
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
removeSenderMessageKey(iteration) {
|
|
84
|
-
const index = this.senderKeyStateStructure.senderMessageKeys.findIndex(key => key.iteration === iteration);
|
|
85
|
-
if (index !== -1) {
|
|
86
|
-
const messageKey = this.senderKeyStateStructure.senderMessageKeys[index];
|
|
87
|
-
this.senderKeyStateStructure.senderMessageKeys.splice(index, 1);
|
|
88
|
-
return new SenderMessageKey(messageKey.iteration, messageKey.seed);
|
|
89
|
-
}
|
|
90
|
-
return null;
|
|
91
|
-
}
|
|
92
|
-
getStructure() {
|
|
93
|
-
return this.senderKeyStateStructure;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
//# sourceMappingURL=sender-key-state.js.map
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { EventEmitter } from 'events';
|
|
2
|
-
import { URL } from 'url';
|
|
3
|
-
export class AbstractSocketClient extends EventEmitter {
|
|
4
|
-
constructor(url, config) {
|
|
5
|
-
super();
|
|
6
|
-
this.url = url;
|
|
7
|
-
this.config = config;
|
|
8
|
-
this.setMaxListeners(0);
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
//# sourceMappingURL=types.js.map
|