@vinzsocket/baileys 2.8.10 → 2.8.30
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/lib/Defaults/index.js +75 -73
- package/lib/Signal/Group/ciphertext-message.js +9 -9
- package/lib/Signal/Group/group-session-builder.js +21 -21
- package/lib/Signal/Group/group_cipher.js +79 -81
- package/lib/Signal/Group/index.js +2 -2
- package/lib/Signal/Group/keyhelper.js +9 -9
- package/lib/Signal/Group/queue-job.js +43 -46
- package/lib/Signal/Group/sender-chain-key.js +24 -25
- package/lib/Signal/Group/sender-key-distribution-message.js +50 -58
- package/lib/Signal/Group/sender-key-message.js +55 -60
- package/lib/Signal/Group/sender-key-name.js +38 -39
- package/lib/Signal/Group/sender-key-record.js +39 -41
- package/lib/Signal/Group/sender-key-state.js +85 -89
- package/lib/Signal/Group/sender-message-key.js +22 -22
- package/lib/Signal/libsignal.js +387 -292
- package/lib/Signal/lid-mapping.js +98 -93
- package/lib/Socket/Client/types.js +6 -6
- package/lib/Socket/Client/websocket.js +44 -44
- package/lib/Socket/business.js +350 -365
- package/lib/Socket/chats.js +1019 -914
- package/lib/Socket/communities.js +454 -376
- package/lib/Socket/groups.js +378 -310
- package/lib/Socket/index.js +11 -11
- package/lib/Socket/messages-recv.js +1355 -1182
- package/lib/Socket/messages-send.js +1224 -1081
- package/lib/Socket/mex.js +40 -34
- package/lib/Socket/newsletter.js +212 -169
- package/lib/Socket/socket.js +896 -757
- package/lib/Store/index.js +1 -1
- package/lib/Store/make-cache-manager-store.js +75 -79
- package/lib/Store/make-in-memory-store.js +450 -389
- package/lib/Store/make-ordered-dictionary.js +73 -76
- package/lib/Store/object-repository.js +24 -22
- package/lib/Types/Chat.js +1 -7
- package/lib/Types/Label.js +20 -20
- package/lib/Types/LabelAssociation.js +2 -2
- package/lib/Types/Message.js +2 -2
- package/lib/Types/Newsletter.js +24 -24
- package/lib/Types/Socket.js +1 -1
- package/lib/Types/State.js +8 -8
- package/lib/Types/index.js +10 -10
- package/lib/Utils/auth-utils.js +408 -401
- package/lib/Utils/baileys-event-stream.js +44 -35
- package/lib/Utils/business.js +200 -197
- package/lib/Utils/chat-utils.js +775 -708
- package/lib/Utils/crypto.js +97 -85
- package/lib/Utils/decode-wa-message.js +240 -227
- package/lib/Utils/event-buffer.js +547 -518
- package/lib/Utils/extended-messages.js +250 -203
- package/lib/Utils/generics.js +300 -289
- package/lib/Utils/history.js +76 -69
- package/lib/Utils/lid-resolver.js +47 -42
- package/lib/Utils/link-preview.js +75 -65
- package/lib/Utils/logger.js +3 -1
- package/lib/Utils/lt-hash.js +38 -34
- package/lib/Utils/make-mutex.js +32 -34
- package/lib/Utils/mention.js +79 -86
- package/lib/Utils/message-retry-manager.js +148 -136
- package/lib/Utils/messages-media.js +652 -562
- package/lib/Utils/messages.js +753 -707
- package/lib/Utils/noise-handler.js +156 -135
- package/lib/Utils/process-message.js +404 -341
- package/lib/Utils/signal.js +180 -118
- package/lib/Utils/use-multi-file-auth-state.js +87 -91
- package/lib/Utils/validate-connection.js +167 -142
- package/lib/WABinary/constants.js +28 -1293
- package/lib/WABinary/decode.js +220 -218
- package/lib/WABinary/encode.js +199 -201
- package/lib/WABinary/generic-utils.js +80 -77
- package/lib/WABinary/jid-utils.js +41 -35
- package/lib/WAM/BinaryInfo.js +7 -7
- package/lib/WAM/constants.js +1 -15241
- package/lib/WAM/encode.js +124 -131
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +23 -23
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +51 -47
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +22 -22
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +30 -32
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +19 -19
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -43
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +17 -17
- package/lib/WAUSync/USyncQuery.js +82 -84
- package/lib/WAUSync/USyncUser.js +20 -20
- package/package.json +4 -2
|
@@ -1,63 +1,55 @@
|
|
|
1
1
|
import { proto } from '../../../WAProto/index.js';
|
|
2
2
|
import { CiphertextMessage } from './ciphertext-message.js';
|
|
3
3
|
export class SenderKeyDistributionMessage extends CiphertextMessage {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
}
|
|
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);
|
|
10
|
+
this.serialized = serialized;
|
|
11
|
+
this.id = distributionMessage.id;
|
|
12
|
+
this.iteration = distributionMessage.iteration;
|
|
13
|
+
this.chainKey = typeof distributionMessage.chainKey === 'string' ? Buffer.from(distributionMessage.chainKey, 'base64') : distributionMessage.chainKey;
|
|
14
|
+
this.signatureKey = typeof distributionMessage.signingKey === 'string' ? Buffer.from(distributionMessage.signingKey, 'base64') : distributionMessage.signingKey;
|
|
15
|
+
} catch (e) {
|
|
16
|
+
throw new Error(String(e));
|
|
17
|
+
}
|
|
18
|
+
} else {
|
|
19
|
+
const version = this.intsToByteHighAndLow(this.CURRENT_VERSION, this.CURRENT_VERSION);
|
|
20
|
+
this.id = id;
|
|
21
|
+
this.iteration = iteration;
|
|
22
|
+
this.chainKey = chainKey;
|
|
23
|
+
this.signatureKey = signatureKey;
|
|
24
|
+
const message = proto.SenderKeyDistributionMessage.encode(proto.SenderKeyDistributionMessage.create({
|
|
25
|
+
id,
|
|
26
|
+
iteration,
|
|
27
|
+
chainKey,
|
|
28
|
+
signingKey: this.signatureKey
|
|
29
|
+
})).finish();
|
|
30
|
+
this.serialized = Buffer.concat([Buffer.from([version]), message]);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
intsToByteHighAndLow(highValue, lowValue) {
|
|
34
|
+
return ((highValue << 4 | lowValue) & 0xff) % 256;
|
|
35
|
+
}
|
|
36
|
+
serialize() {
|
|
37
|
+
return this.serialized;
|
|
38
|
+
}
|
|
39
|
+
getType() {
|
|
40
|
+
return this.SENDERKEY_DISTRIBUTION_TYPE;
|
|
41
|
+
}
|
|
42
|
+
getIteration() {
|
|
43
|
+
return this.iteration;
|
|
44
|
+
}
|
|
45
|
+
getChainKey() {
|
|
46
|
+
return typeof this.chainKey === 'string' ? Buffer.from(this.chainKey, 'base64') : this.chainKey;
|
|
47
|
+
}
|
|
48
|
+
getSignatureKey() {
|
|
49
|
+
return typeof this.signatureKey === 'string' ? Buffer.from(this.signatureKey, 'base64') : this.signatureKey;
|
|
50
|
+
}
|
|
51
|
+
getId() {
|
|
52
|
+
return this.id;
|
|
53
|
+
}
|
|
62
54
|
}
|
|
63
55
|
//# sourceMappingURL=sender-key-distribution-message.js.map
|
|
@@ -3,65 +3,60 @@ import { calculateSignature, verifySignature } from 'libsignal/src/curve.js';
|
|
|
3
3
|
import { proto } from '../../../WAProto/index.js';
|
|
4
4
|
import { CiphertextMessage } from './ciphertext-message.js';
|
|
5
5
|
export class SenderKeyMessage extends CiphertextMessage {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return this.serialized;
|
|
62
|
-
}
|
|
63
|
-
getType() {
|
|
64
|
-
return 4;
|
|
65
|
-
}
|
|
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);
|
|
14
|
+
this.serialized = serialized;
|
|
15
|
+
this.messageVersion = (version & 0xff) >> 4;
|
|
16
|
+
this.keyId = senderKeyMessage.id;
|
|
17
|
+
this.iteration = senderKeyMessage.iteration;
|
|
18
|
+
this.ciphertext = typeof senderKeyMessage.ciphertext === 'string' ? Buffer.from(senderKeyMessage.ciphertext, 'base64') : senderKeyMessage.ciphertext;
|
|
19
|
+
this.signature = signature;
|
|
20
|
+
} else {
|
|
21
|
+
const version = ((this.CURRENT_VERSION << 4 | this.CURRENT_VERSION) & 0xff) % 256;
|
|
22
|
+
const ciphertextBuffer = Buffer.from(ciphertext);
|
|
23
|
+
const message = proto.SenderKeyMessage.encode(proto.SenderKeyMessage.create({
|
|
24
|
+
id: keyId,
|
|
25
|
+
iteration: iteration,
|
|
26
|
+
ciphertext: ciphertextBuffer
|
|
27
|
+
})).finish();
|
|
28
|
+
const signature = this.getSignature(signatureKey, Buffer.concat([Buffer.from([version]), message]));
|
|
29
|
+
this.serialized = Buffer.concat([Buffer.from([version]), message, Buffer.from(signature)]);
|
|
30
|
+
this.messageVersion = this.CURRENT_VERSION;
|
|
31
|
+
this.keyId = keyId;
|
|
32
|
+
this.iteration = iteration;
|
|
33
|
+
this.ciphertext = ciphertextBuffer;
|
|
34
|
+
this.signature = signature;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
getKeyId() {
|
|
38
|
+
return this.keyId;
|
|
39
|
+
}
|
|
40
|
+
getIteration() {
|
|
41
|
+
return this.iteration;
|
|
42
|
+
}
|
|
43
|
+
getCipherText() {
|
|
44
|
+
return this.ciphertext;
|
|
45
|
+
}
|
|
46
|
+
verifySignature(signatureKey) {
|
|
47
|
+
const part1 = this.serialized.slice(0, this.serialized.length - this.SIGNATURE_LENGTH);
|
|
48
|
+
const part2 = this.serialized.slice(-1 * this.SIGNATURE_LENGTH);
|
|
49
|
+
const res = verifySignature(signatureKey, part1, part2);
|
|
50
|
+
if (!res) throw new Error('Invalid signature!');
|
|
51
|
+
}
|
|
52
|
+
getSignature(signatureKey, serialized) {
|
|
53
|
+
return Buffer.from(calculateSignature(signatureKey, serialized));
|
|
54
|
+
}
|
|
55
|
+
serialize() {
|
|
56
|
+
return this.serialized;
|
|
57
|
+
}
|
|
58
|
+
getType() {
|
|
59
|
+
return 4;
|
|
60
|
+
}
|
|
66
61
|
}
|
|
67
62
|
//# sourceMappingURL=sender-key-message.js.map
|
|
@@ -1,48 +1,47 @@
|
|
|
1
1
|
function isNull(str) {
|
|
2
|
-
|
|
2
|
+
return str === null || str === '';
|
|
3
3
|
}
|
|
4
4
|
function intValue(num) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
11
|
}
|
|
12
12
|
function hashCode(strKey) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
21
|
}
|
|
22
22
|
export class SenderKeyName {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
hashCode()
|
|
45
|
-
|
|
46
|
-
}
|
|
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) return false;
|
|
41
|
+
return this.groupId === other.groupId && this.sender.toString() === other.sender.toString();
|
|
42
|
+
}
|
|
43
|
+
hashCode() {
|
|
44
|
+
return hashCode(this.groupId) ^ hashCode(this.sender.toString());
|
|
45
|
+
}
|
|
47
46
|
}
|
|
48
47
|
//# sourceMappingURL=sender-key-name.js.map
|
|
@@ -1,50 +1,48 @@
|
|
|
1
1
|
import { BufferJSON } from '../../Utils/generics.js';
|
|
2
2
|
import { SenderKeyState } from './sender-key-state.js';
|
|
3
3
|
export class SenderKeyRecord {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
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
|
+
}
|
|
12
11
|
}
|
|
13
|
-
|
|
14
|
-
|
|
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];
|
|
15
19
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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();
|
|
21
26
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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);
|
|
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
|
+
} else if (data instanceof Uint8Array) {
|
|
40
|
+
const str = Buffer.from(data).toString('utf-8');
|
|
41
|
+
parsed = JSON.parse(str, BufferJSON.reviver);
|
|
42
|
+
} else {
|
|
43
|
+
parsed = data;
|
|
48
44
|
}
|
|
45
|
+
return new SenderKeyRecord(parsed);
|
|
46
|
+
}
|
|
49
47
|
}
|
|
50
48
|
//# sourceMappingURL=sender-key-record.js.map
|
|
@@ -1,101 +1,97 @@
|
|
|
1
1
|
import { SenderChainKey } from './sender-chain-key.js';
|
|
2
2
|
import { SenderMessageKey } from './sender-message-key.js';
|
|
3
3
|
export class SenderKeyState {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
this.senderKeyStateStructure = senderKeyStateStructure;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
else {
|
|
15
|
-
if (signatureKeyPair) {
|
|
16
|
-
signatureKeyPublic = signatureKeyPair.public;
|
|
17
|
-
signatureKeyPrivate = signatureKeyPair.private;
|
|
18
|
-
}
|
|
19
|
-
chainKey = typeof chainKey === 'string' ? Buffer.from(chainKey, 'base64') : chainKey;
|
|
20
|
-
const senderChainKeyStructure = {
|
|
21
|
-
iteration: iteration || 0,
|
|
22
|
-
seed: chainKey || Buffer.alloc(0)
|
|
23
|
-
};
|
|
24
|
-
const signingKeyStructure = {
|
|
25
|
-
public: typeof signatureKeyPublic === 'string'
|
|
26
|
-
? Buffer.from(signatureKeyPublic, 'base64')
|
|
27
|
-
: signatureKeyPublic || Buffer.alloc(0)
|
|
28
|
-
};
|
|
29
|
-
if (signatureKeyPrivate) {
|
|
30
|
-
signingKeyStructure.private =
|
|
31
|
-
typeof signatureKeyPrivate === 'string' ? Buffer.from(signatureKeyPrivate, 'base64') : signatureKeyPrivate;
|
|
32
|
-
}
|
|
33
|
-
this.senderKeyStateStructure = {
|
|
34
|
-
senderKeyId: id || 0,
|
|
35
|
-
senderChainKey: senderChainKeyStructure,
|
|
36
|
-
senderSigningKey: signingKeyStructure,
|
|
37
|
-
senderMessageKeys: []
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
getKeyId() {
|
|
42
|
-
return this.senderKeyStateStructure.senderKeyId;
|
|
43
|
-
}
|
|
44
|
-
getSenderChainKey() {
|
|
45
|
-
return new SenderChainKey(this.senderKeyStateStructure.senderChainKey.iteration, this.senderKeyStateStructure.senderChainKey.seed);
|
|
46
|
-
}
|
|
47
|
-
setSenderChainKey(chainKey) {
|
|
48
|
-
this.senderKeyStateStructure.senderChainKey = {
|
|
49
|
-
iteration: chainKey.getIteration(),
|
|
50
|
-
seed: chainKey.getSeed()
|
|
4
|
+
constructor(id, iteration, chainKey, signatureKeyPair, signatureKeyPublic, signatureKeyPrivate, senderKeyStateStructure) {
|
|
5
|
+
this.MAX_MESSAGE_KEYS = 2000;
|
|
6
|
+
if (senderKeyStateStructure) {
|
|
7
|
+
if (!Array.isArray(senderKeyStateStructure.senderMessageKeys)) {
|
|
8
|
+
this.senderKeyStateStructure = {
|
|
9
|
+
...senderKeyStateStructure,
|
|
10
|
+
senderMessageKeys: []
|
|
51
11
|
};
|
|
12
|
+
} else {
|
|
13
|
+
this.senderKeyStateStructure = senderKeyStateStructure;
|
|
14
|
+
}
|
|
15
|
+
} else {
|
|
16
|
+
if (signatureKeyPair) {
|
|
17
|
+
signatureKeyPublic = signatureKeyPair.public;
|
|
18
|
+
signatureKeyPrivate = signatureKeyPair.private;
|
|
19
|
+
}
|
|
20
|
+
chainKey = typeof chainKey === 'string' ? Buffer.from(chainKey, 'base64') : chainKey;
|
|
21
|
+
const senderChainKeyStructure = {
|
|
22
|
+
iteration: iteration || 0,
|
|
23
|
+
seed: chainKey || Buffer.alloc(0)
|
|
24
|
+
};
|
|
25
|
+
const signingKeyStructure = {
|
|
26
|
+
public: typeof signatureKeyPublic === 'string' ? Buffer.from(signatureKeyPublic, 'base64') : signatureKeyPublic || Buffer.alloc(0)
|
|
27
|
+
};
|
|
28
|
+
if (signatureKeyPrivate) {
|
|
29
|
+
signingKeyStructure.private = 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
|
+
};
|
|
52
37
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return Buffer.from(privateKey, 'base64');
|
|
73
|
-
}
|
|
74
|
-
return Buffer.from(privateKey || []);
|
|
38
|
+
}
|
|
39
|
+
getKeyId() {
|
|
40
|
+
return this.senderKeyStateStructure.senderKeyId;
|
|
41
|
+
}
|
|
42
|
+
getSenderChainKey() {
|
|
43
|
+
return new 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
|
+
} else if (typeof publicKey === 'string') {
|
|
56
|
+
return Buffer.from(publicKey, 'base64');
|
|
75
57
|
}
|
|
76
|
-
|
|
77
|
-
|
|
58
|
+
return Buffer.from(publicKey || []);
|
|
59
|
+
}
|
|
60
|
+
getSigningKeyPrivate() {
|
|
61
|
+
const privateKey = this.senderKeyStateStructure.senderSigningKey.private;
|
|
62
|
+
if (!privateKey) {
|
|
63
|
+
return undefined;
|
|
78
64
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
});
|
|
84
|
-
if (this.senderKeyStateStructure.senderMessageKeys.length > this.MAX_MESSAGE_KEYS) {
|
|
85
|
-
this.senderKeyStateStructure.senderMessageKeys.shift();
|
|
86
|
-
}
|
|
65
|
+
if (privateKey instanceof Buffer) {
|
|
66
|
+
return privateKey;
|
|
67
|
+
} else if (typeof privateKey === 'string') {
|
|
68
|
+
return Buffer.from(privateKey, 'base64');
|
|
87
69
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
70
|
+
return Buffer.from(privateKey || []);
|
|
71
|
+
}
|
|
72
|
+
hasSenderMessageKey(iteration) {
|
|
73
|
+
return this.senderKeyStateStructure.senderMessageKeys.some(key => key.iteration === iteration);
|
|
74
|
+
}
|
|
75
|
+
addSenderMessageKey(senderMessageKey) {
|
|
76
|
+
this.senderKeyStateStructure.senderMessageKeys.push({
|
|
77
|
+
iteration: senderMessageKey.getIteration(),
|
|
78
|
+
seed: senderMessageKey.getSeed()
|
|
79
|
+
});
|
|
80
|
+
if (this.senderKeyStateStructure.senderMessageKeys.length > this.MAX_MESSAGE_KEYS) {
|
|
81
|
+
this.senderKeyStateStructure.senderMessageKeys.shift();
|
|
96
82
|
}
|
|
97
|
-
|
|
98
|
-
|
|
83
|
+
}
|
|
84
|
+
removeSenderMessageKey(iteration) {
|
|
85
|
+
const index = this.senderKeyStateStructure.senderMessageKeys.findIndex(key => key.iteration === iteration);
|
|
86
|
+
if (index !== -1) {
|
|
87
|
+
const messageKey = this.senderKeyStateStructure.senderMessageKeys[index];
|
|
88
|
+
this.senderKeyStateStructure.senderMessageKeys.splice(index, 1);
|
|
89
|
+
return new SenderMessageKey(messageKey.iteration, messageKey.seed);
|
|
99
90
|
}
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
getStructure() {
|
|
94
|
+
return this.senderKeyStateStructure;
|
|
95
|
+
}
|
|
100
96
|
}
|
|
101
97
|
//# sourceMappingURL=sender-key-state.js.map
|
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
/* @ts-ignore */
|
|
2
2
|
import { deriveSecrets } from 'libsignal/src/crypto.js';
|
|
3
3
|
export class SenderMessageKey {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
4
|
+
constructor(iteration, seed) {
|
|
5
|
+
const derivative = deriveSecrets(seed, Buffer.alloc(32), Buffer.from('WhisperGroup'));
|
|
6
|
+
const keys = new Uint8Array(32);
|
|
7
|
+
keys.set(new Uint8Array(derivative[0].slice(16)));
|
|
8
|
+
keys.set(new Uint8Array(derivative[1].slice(0, 16)), 16);
|
|
9
|
+
this.iv = Buffer.from(derivative[0].slice(0, 16));
|
|
10
|
+
this.cipherKey = Buffer.from(keys.buffer);
|
|
11
|
+
this.iteration = iteration;
|
|
12
|
+
this.seed = seed;
|
|
13
|
+
}
|
|
14
|
+
getIteration() {
|
|
15
|
+
return this.iteration;
|
|
16
|
+
}
|
|
17
|
+
getIv() {
|
|
18
|
+
return this.iv;
|
|
19
|
+
}
|
|
20
|
+
getCipherKey() {
|
|
21
|
+
return this.cipherKey;
|
|
22
|
+
}
|
|
23
|
+
getSeed() {
|
|
24
|
+
return this.seed;
|
|
25
|
+
}
|
|
26
26
|
}
|
|
27
27
|
//# sourceMappingURL=sender-message-key.js.map
|