@mrlegendbot/baileys 1.2.3 → 1.2.5
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.upstream.md +1312 -0
- package/WAProto/WAProto.json +1 -0
- package/WAProto/WAProto.proto +6275 -0
- package/WAProto/compiler.js +550 -0
- package/WAProto/index.js +2 -97691
- package/lib/Defaults/index.js +89 -92
- package/lib/Signal/Group/ciphertext-message.js +9 -10
- package/lib/Signal/Group/group-session-builder.js +21 -22
- package/lib/Signal/Group/group_cipher.js +75 -69
- package/lib/Signal/Group/index.js +0 -1
- package/lib/Signal/Group/keyhelper.js +9 -10
- package/lib/Signal/Group/sender-chain-key.js +21 -22
- package/lib/Signal/Group/sender-key-distribution-message.js +51 -60
- package/lib/Signal/Group/sender-key-message.js +56 -62
- package/lib/Signal/Group/sender-key-name.js +38 -40
- package/lib/Signal/Group/sender-key-record.js +33 -34
- package/lib/Signal/Group/sender-key-state.js +72 -76
- package/lib/Signal/Group/sender-message-key.js +22 -23
- package/lib/Signal/libsignal.js +506 -405
- package/lib/Signal/lid-mapping.js +276 -258
- package/lib/Socket/Client/index.js +0 -1
- package/lib/Socket/Client/types.js +6 -7
- package/lib/Socket/Client/websocket.js +48 -49
- package/lib/Socket/business.js +349 -369
- package/lib/Socket/chats.js +1172 -1148
- package/lib/Socket/communities.js +473 -413
- package/lib/Socket/groups.js +387 -331
- package/lib/Socket/index.js +6 -8
- package/lib/Socket/messages-recv.js +1782 -1719
- package/lib/Socket/messages-send.js +1554 -2450
- package/lib/Socket/mex.js +40 -35
- package/lib/Socket/newsletter.js +239 -191
- package/lib/Socket/socket.js +992 -923
- package/lib/Store/index.js +8 -0
- package/lib/Store/keyed-db.js +108 -0
- package/lib/Store/make-cache-manager-store.js +70 -0
- package/lib/Store/make-in-memory-store.js +417 -0
- package/lib/Store/make-ordered-dictionary.js +69 -0
- package/lib/Store/object-repository.js +27 -0
- package/lib/Types/Auth.js +0 -1
- package/lib/Types/Bussines.js +0 -1
- package/lib/Types/Call.js +0 -1
- package/lib/Types/Chat.js +1 -8
- package/lib/Types/Contact.js +0 -1
- package/lib/Types/Events.js +1 -2
- package/lib/Types/GroupMetadata.js +0 -1
- package/lib/Types/Label.js +20 -22
- package/lib/Types/LabelAssociation.js +2 -4
- package/lib/Types/Message.js +3 -5
- package/lib/Types/Mex.js +26 -31
- package/lib/Types/Product.js +0 -1
- package/lib/Types/Signal.js +1 -2
- package/lib/Types/Socket.js +2 -3
- package/lib/Types/State.js +4 -52
- package/lib/Types/USync.js +0 -1
- package/lib/Types/index.js +10 -11
- package/lib/Utils/auth-utils.js +240 -277
- package/lib/Utils/browser-utils.js +20 -23
- package/lib/Utils/business.js +200 -204
- package/lib/Utils/chat-utils.js +836 -810
- package/lib/Utils/companion-reg-client-utils.js +23 -25
- package/lib/Utils/crypto.js +70 -86
- package/lib/Utils/decode-wa-message.js +277 -284
- package/lib/Utils/event-buffer.js +592 -595
- package/lib/Utils/generics.js +312 -335
- package/lib/Utils/history.js +123 -115
- package/lib/Utils/index.js +1 -2
- package/lib/Utils/link-preview.js +74 -73
- package/lib/Utils/logger.js +3 -2
- package/lib/Utils/lt-hash.js +0 -6
- package/lib/Utils/make-mutex.js +27 -27
- package/lib/Utils/message-retry-manager.js +213 -254
- package/lib/Utils/messages-media.js +741 -715
- package/lib/Utils/messages.js +791 -827
- package/lib/Utils/noise-handler.js +215 -187
- package/lib/Utils/pre-key-manager.js +69 -98
- package/lib/Utils/process-message.js +617 -586
- package/lib/Utils/reporting-utils.js +553 -234
- package/lib/Utils/signal.js +217 -170
- package/lib/Utils/stanza-ack.js +27 -35
- package/lib/Utils/sync-action-utils.js +37 -41
- package/lib/Utils/tc-token-utils.js +120 -141
- package/lib/Utils/use-multi-file-auth-state.js +87 -105
- package/lib/Utils/use-sqlite-auth-state.js +162 -0
- package/lib/Utils/validate-connection.js +190 -188
- package/lib/WABinary/constants.js +28 -1294
- package/lib/WABinary/decode.js +245 -249
- package/lib/WABinary/encode.js +201 -206
- package/lib/WABinary/generic-utils.js +86 -89
- package/lib/WABinary/index.js +0 -1
- package/lib/WABinary/jid-utils.js +68 -77
- package/lib/WABinary/types.js +0 -1
- package/lib/WAM/BinaryInfo.js +7 -8
- package/lib/WAM/constants.js +19892 -22853
- package/lib/WAM/encode.js +121 -132
- package/lib/WAM/index.js +0 -1
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +46 -43
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +47 -48
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +22 -23
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +30 -33
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +19 -20
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -44
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -24
- package/lib/WAUSync/Protocols/index.js +0 -1
- package/lib/WAUSync/USyncQuery.js +79 -88
- package/lib/WAUSync/USyncUser.js +28 -29
- package/lib/WAUSync/index.js +0 -1
- package/lib/index.js +2 -2
- package/package.json +22 -86
- package/WAProto/GenerateStatics.sh +0 -3
- package/WAProto/fix-imports.js +0 -85
- package/WAProto/index.d.ts +0 -14017
- package/lib/Defaults/index.d.ts +0 -75
- package/lib/Signal/Group/ciphertext-message.d.ts +0 -10
- package/lib/Signal/Group/group-session-builder.d.ts +0 -15
- package/lib/Signal/Group/group_cipher.d.ts +0 -17
- package/lib/Signal/Group/index.d.ts +0 -12
- package/lib/Signal/Group/keyhelper.d.ts +0 -11
- package/lib/Signal/Group/sender-chain-key.d.ts +0 -14
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -17
- package/lib/Signal/Group/sender-key-message.d.ts +0 -19
- package/lib/Signal/Group/sender-key-name.d.ts +0 -18
- package/lib/Signal/Group/sender-key-record.d.ts +0 -31
- package/lib/Signal/Group/sender-key-state.d.ts +0 -39
- package/lib/Signal/Group/sender-message-key.d.ts +0 -12
- package/lib/Signal/libsignal.d.ts +0 -5
- package/lib/Signal/lid-mapping.d.ts +0 -23
- package/lib/Socket/Client/index.d.ts +0 -3
- package/lib/Socket/Client/types.d.ts +0 -16
- package/lib/Socket/Client/websocket.d.ts +0 -13
- package/lib/Socket/business.d.ts +0 -217
- package/lib/Socket/chats.d.ts +0 -125
- package/lib/Socket/communities.d.ts +0 -273
- package/lib/Socket/groups.d.ts +0 -161
- package/lib/Socket/index.d.ts +0 -260
- package/lib/Socket/messages-recv.d.ts +0 -203
- package/lib/Socket/messages-send.d.ts +0 -199
- package/lib/Socket/mex.d.ts +0 -3
- package/lib/Socket/newsletter.d.ts +0 -170
- package/lib/Socket/socket.d.ts +0 -59
- package/lib/Types/Auth.d.ts +0 -117
- package/lib/Types/Bussines.d.ts +0 -25
- package/lib/Types/Call.d.ts +0 -15
- package/lib/Types/Chat.d.ts +0 -124
- package/lib/Types/Contact.d.ts +0 -26
- package/lib/Types/Events.d.ts +0 -256
- package/lib/Types/GroupMetadata.d.ts +0 -71
- package/lib/Types/Label.d.ts +0 -47
- package/lib/Types/LabelAssociation.d.ts +0 -30
- package/lib/Types/Message.d.ts +0 -320
- package/lib/Types/Mex.d.ts +0 -141
- package/lib/Types/Product.d.ts +0 -79
- package/lib/Types/Signal.d.ts +0 -87
- package/lib/Types/Socket.d.ts +0 -136
- package/lib/Types/State.d.ts +0 -97
- package/lib/Types/USync.d.ts +0 -26
- package/lib/Types/index.d.ts +0 -66
- package/lib/Utils/auth-utils.d.ts +0 -24
- package/lib/Utils/browser-utils.d.ts +0 -4
- package/lib/Utils/business.d.ts +0 -23
- package/lib/Utils/chat-utils.d.ts +0 -100
- package/lib/Utils/companion-reg-client-utils.d.ts +0 -17
- package/lib/Utils/crypto.d.ts +0 -37
- package/lib/Utils/decode-wa-message.d.ts +0 -66
- package/lib/Utils/event-buffer.d.ts +0 -36
- package/lib/Utils/generics.d.ts +0 -92
- package/lib/Utils/history.d.ts +0 -24
- package/lib/Utils/identity-change-handler.d.ts +0 -44
- package/lib/Utils/identity-change-handler.js +0 -50
- package/lib/Utils/index.d.ts +0 -22
- package/lib/Utils/link-preview.d.ts +0 -21
- package/lib/Utils/logger.d.ts +0 -12
- package/lib/Utils/lt-hash.d.ts +0 -8
- package/lib/Utils/make-mutex.d.ts +0 -9
- package/lib/Utils/message-retry-manager.d.ts +0 -115
- package/lib/Utils/messages-media.d.ts +0 -133
- package/lib/Utils/messages.d.ts +0 -91
- package/lib/Utils/noise-handler.d.ts +0 -20
- package/lib/Utils/offline-node-processor.d.ts +0 -17
- package/lib/Utils/offline-node-processor.js +0 -40
- package/lib/Utils/pre-key-manager.d.ts +0 -28
- package/lib/Utils/process-message.d.ts +0 -60
- package/lib/Utils/reporting-utils.d.ts +0 -11
- package/lib/Utils/signal.d.ts +0 -47
- package/lib/Utils/stanza-ack.d.ts +0 -11
- package/lib/Utils/sync-action-utils.d.ts +0 -19
- package/lib/Utils/tc-token-utils.d.ts +0 -37
- package/lib/Utils/use-multi-file-auth-state.d.ts +0 -13
- package/lib/Utils/validate-connection.d.ts +0 -11
- package/lib/WABinary/constants.d.ts +0 -28
- package/lib/WABinary/decode.d.ts +0 -7
- package/lib/WABinary/encode.d.ts +0 -3
- package/lib/WABinary/generic-utils.d.ts +0 -15
- package/lib/WABinary/index.d.ts +0 -6
- package/lib/WABinary/jid-utils.d.ts +0 -48
- package/lib/WABinary/types.d.ts +0 -19
- package/lib/WAM/BinaryInfo.d.ts +0 -9
- package/lib/WAM/constants.d.ts +0 -40
- package/lib/WAM/encode.d.ts +0 -3
- package/lib/WAM/index.d.ts +0 -4
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -10
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -23
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -13
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -13
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +0 -10
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +0 -26
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +0 -10
- package/lib/WAUSync/Protocols/index.d.ts +0 -6
- package/lib/WAUSync/USyncQuery.d.ts +0 -30
- package/lib/WAUSync/USyncUser.d.ts +0 -17
- package/lib/WAUSync/index.d.ts +0 -4
- package/lib/index.d.ts +0 -12
|
@@ -1,66 +1,60 @@
|
|
|
1
1
|
import { calculateSignature, verifySignature } from 'libsignal/src/curve.js';
|
|
2
|
-
import { proto } from '../../../WAProto/
|
|
2
|
+
import { proto } from '../../../WAProto/compiler.js';
|
|
3
3
|
import { CiphertextMessage } from './ciphertext-message.js';
|
|
4
4
|
export class SenderKeyMessage extends CiphertextMessage {
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
return this.serialized;
|
|
61
|
-
}
|
|
62
|
-
getType() {
|
|
63
|
-
return 4;
|
|
64
|
-
}
|
|
5
|
+
constructor(keyId, iteration, ciphertext, signatureKey, serialized) {
|
|
6
|
+
super();
|
|
7
|
+
this.SIGNATURE_LENGTH = 64;
|
|
8
|
+
if (serialized) {
|
|
9
|
+
const version = serialized[0];
|
|
10
|
+
const message = serialized.slice(1, serialized.length - this.SIGNATURE_LENGTH);
|
|
11
|
+
const signature = serialized.slice(-1 * this.SIGNATURE_LENGTH);
|
|
12
|
+
const senderKeyMessage = proto.SenderKeyMessage.decode(message).toJSON();
|
|
13
|
+
this.serialized = serialized;
|
|
14
|
+
this.messageVersion = (version & 0xff) >> 4;
|
|
15
|
+
this.keyId = senderKeyMessage.id;
|
|
16
|
+
this.iteration = senderKeyMessage.iteration;
|
|
17
|
+
this.ciphertext = typeof senderKeyMessage.ciphertext === 'string' ? Buffer.from(senderKeyMessage.ciphertext, 'base64') : senderKeyMessage.ciphertext;
|
|
18
|
+
this.signature = signature;
|
|
19
|
+
} else {
|
|
20
|
+
const version = ((this.CURRENT_VERSION << 4 | this.CURRENT_VERSION) & 0xff) % 256;
|
|
21
|
+
const ciphertextBuffer = Buffer.from(ciphertext);
|
|
22
|
+
const message = proto.SenderKeyMessage.encode(proto.SenderKeyMessage.create({
|
|
23
|
+
id: keyId,
|
|
24
|
+
iteration: iteration,
|
|
25
|
+
ciphertext: ciphertextBuffer
|
|
26
|
+
})).finish();
|
|
27
|
+
const signature = this.getSignature(signatureKey, Buffer.concat([Buffer.from([version]), message]));
|
|
28
|
+
this.serialized = Buffer.concat([Buffer.from([version]), message, Buffer.from(signature)]);
|
|
29
|
+
this.messageVersion = this.CURRENT_VERSION;
|
|
30
|
+
this.keyId = keyId;
|
|
31
|
+
this.iteration = iteration;
|
|
32
|
+
this.ciphertext = ciphertextBuffer;
|
|
33
|
+
this.signature = signature;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
getKeyId() {
|
|
37
|
+
return this.keyId;
|
|
38
|
+
}
|
|
39
|
+
getIteration() {
|
|
40
|
+
return this.iteration;
|
|
41
|
+
}
|
|
42
|
+
getCipherText() {
|
|
43
|
+
return this.ciphertext;
|
|
44
|
+
}
|
|
45
|
+
verifySignature(signatureKey) {
|
|
46
|
+
const part1 = this.serialized.slice(0, this.serialized.length - this.SIGNATURE_LENGTH);
|
|
47
|
+
const part2 = this.serialized.slice(-1 * this.SIGNATURE_LENGTH);
|
|
48
|
+
const res = verifySignature(signatureKey, part1, part2);
|
|
49
|
+
if (!res) throw new Error('Invalid signature!');
|
|
50
|
+
}
|
|
51
|
+
getSignature(signatureKey, serialized) {
|
|
52
|
+
return Buffer.from(calculateSignature(signatureKey, serialized));
|
|
53
|
+
}
|
|
54
|
+
serialize() {
|
|
55
|
+
return this.serialized;
|
|
56
|
+
}
|
|
57
|
+
getType() {
|
|
58
|
+
return 4;
|
|
59
|
+
}
|
|
65
60
|
}
|
|
66
|
-
//# sourceMappingURL=sender-key-message.js.map
|
|
@@ -1,48 +1,46 @@
|
|
|
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
|
-
//# sourceMappingURL=sender-key-name.js.map
|
|
@@ -1,41 +1,40 @@
|
|
|
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
|
-
|
|
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
|
-
const str = Buffer.from(data).toString('utf-8');
|
|
37
|
-
const parsed = JSON.parse(str, BufferJSON.reviver);
|
|
38
|
-
return new SenderKeyRecord(parsed);
|
|
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();
|
|
39
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
|
+
const str = Buffer.from(data).toString('utf-8');
|
|
37
|
+
const parsed = JSON.parse(str, BufferJSON.reviver);
|
|
38
|
+
return new SenderKeyRecord(parsed);
|
|
39
|
+
}
|
|
40
40
|
}
|
|
41
|
-
//# sourceMappingURL=sender-key-record.js.map
|
|
@@ -1,84 +1,80 @@
|
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
},
|
|
29
|
-
senderMessageKeys: []
|
|
30
|
-
};
|
|
31
|
-
}
|
|
4
|
+
constructor(id, iteration, chainKey, signatureKeyPair, signatureKeyPublic, signatureKeyPrivate, senderKeyStateStructure) {
|
|
5
|
+
this.MAX_MESSAGE_KEYS = 2000;
|
|
6
|
+
if (senderKeyStateStructure) {
|
|
7
|
+
this.senderKeyStateStructure = {
|
|
8
|
+
...senderKeyStateStructure,
|
|
9
|
+
senderMessageKeys: Array.isArray(senderKeyStateStructure.senderMessageKeys) ? senderKeyStateStructure.senderMessageKeys : []
|
|
10
|
+
};
|
|
11
|
+
} else {
|
|
12
|
+
if (signatureKeyPair) {
|
|
13
|
+
signatureKeyPublic = signatureKeyPair.public;
|
|
14
|
+
signatureKeyPrivate = signatureKeyPair.private;
|
|
15
|
+
}
|
|
16
|
+
this.senderKeyStateStructure = {
|
|
17
|
+
senderKeyId: id || 0,
|
|
18
|
+
senderChainKey: {
|
|
19
|
+
iteration: iteration || 0,
|
|
20
|
+
seed: Buffer.from(chainKey || [])
|
|
21
|
+
},
|
|
22
|
+
senderSigningKey: {
|
|
23
|
+
public: Buffer.from(signatureKeyPublic || []),
|
|
24
|
+
private: Buffer.from(signatureKeyPrivate || [])
|
|
25
|
+
},
|
|
26
|
+
senderMessageKeys: []
|
|
27
|
+
};
|
|
32
28
|
}
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
}
|
|
30
|
+
getKeyId() {
|
|
31
|
+
return this.senderKeyStateStructure.senderKeyId;
|
|
32
|
+
}
|
|
33
|
+
getSenderChainKey() {
|
|
34
|
+
return new SenderChainKey(this.senderKeyStateStructure.senderChainKey.iteration, this.senderKeyStateStructure.senderChainKey.seed);
|
|
35
|
+
}
|
|
36
|
+
setSenderChainKey(chainKey) {
|
|
37
|
+
this.senderKeyStateStructure.senderChainKey = {
|
|
38
|
+
iteration: chainKey.getIteration(),
|
|
39
|
+
seed: chainKey.getSeed()
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
getSigningKeyPublic() {
|
|
43
|
+
const publicKey = Buffer.from(this.senderKeyStateStructure.senderSigningKey.public);
|
|
44
|
+
if (publicKey.length === 32) {
|
|
45
|
+
const fixed = Buffer.alloc(33);
|
|
46
|
+
fixed[0] = 0x05;
|
|
47
|
+
publicKey.copy(fixed, 1);
|
|
48
|
+
return fixed;
|
|
35
49
|
}
|
|
36
|
-
|
|
37
|
-
|
|
50
|
+
return publicKey;
|
|
51
|
+
}
|
|
52
|
+
getSigningKeyPrivate() {
|
|
53
|
+
const privateKey = this.senderKeyStateStructure.senderSigningKey.private;
|
|
54
|
+
return Buffer.from(privateKey || []);
|
|
55
|
+
}
|
|
56
|
+
hasSenderMessageKey(iteration) {
|
|
57
|
+
return this.senderKeyStateStructure.senderMessageKeys.some(key => key.iteration === iteration);
|
|
58
|
+
}
|
|
59
|
+
addSenderMessageKey(senderMessageKey) {
|
|
60
|
+
this.senderKeyStateStructure.senderMessageKeys.push({
|
|
61
|
+
iteration: senderMessageKey.getIteration(),
|
|
62
|
+
seed: senderMessageKey.getSeed()
|
|
63
|
+
});
|
|
64
|
+
if (this.senderKeyStateStructure.senderMessageKeys.length > this.MAX_MESSAGE_KEYS) {
|
|
65
|
+
this.senderKeyStateStructure.senderMessageKeys.shift();
|
|
38
66
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const publicKey = Buffer.from(this.senderKeyStateStructure.senderSigningKey.public);
|
|
47
|
-
if (publicKey.length === 32) {
|
|
48
|
-
const fixed = Buffer.alloc(33);
|
|
49
|
-
fixed[0] = 0x05;
|
|
50
|
-
publicKey.copy(fixed, 1);
|
|
51
|
-
return fixed;
|
|
52
|
-
}
|
|
53
|
-
return publicKey;
|
|
54
|
-
}
|
|
55
|
-
getSigningKeyPrivate() {
|
|
56
|
-
const privateKey = this.senderKeyStateStructure.senderSigningKey.private;
|
|
57
|
-
return Buffer.from(privateKey || []);
|
|
58
|
-
}
|
|
59
|
-
hasSenderMessageKey(iteration) {
|
|
60
|
-
return this.senderKeyStateStructure.senderMessageKeys.some(key => key.iteration === iteration);
|
|
61
|
-
}
|
|
62
|
-
addSenderMessageKey(senderMessageKey) {
|
|
63
|
-
this.senderKeyStateStructure.senderMessageKeys.push({
|
|
64
|
-
iteration: senderMessageKey.getIteration(),
|
|
65
|
-
seed: senderMessageKey.getSeed()
|
|
66
|
-
});
|
|
67
|
-
if (this.senderKeyStateStructure.senderMessageKeys.length > this.MAX_MESSAGE_KEYS) {
|
|
68
|
-
this.senderKeyStateStructure.senderMessageKeys.shift();
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
removeSenderMessageKey(iteration) {
|
|
72
|
-
const index = this.senderKeyStateStructure.senderMessageKeys.findIndex(key => key.iteration === iteration);
|
|
73
|
-
if (index !== -1) {
|
|
74
|
-
const messageKey = this.senderKeyStateStructure.senderMessageKeys[index];
|
|
75
|
-
this.senderKeyStateStructure.senderMessageKeys.splice(index, 1);
|
|
76
|
-
return new SenderMessageKey(messageKey.iteration, messageKey.seed);
|
|
77
|
-
}
|
|
78
|
-
return null;
|
|
79
|
-
}
|
|
80
|
-
getStructure() {
|
|
81
|
-
return this.senderKeyStateStructure;
|
|
67
|
+
}
|
|
68
|
+
removeSenderMessageKey(iteration) {
|
|
69
|
+
const index = this.senderKeyStateStructure.senderMessageKeys.findIndex(key => key.iteration === iteration);
|
|
70
|
+
if (index !== -1) {
|
|
71
|
+
const messageKey = this.senderKeyStateStructure.senderMessageKeys[index];
|
|
72
|
+
this.senderKeyStateStructure.senderMessageKeys.splice(index, 1);
|
|
73
|
+
return new SenderMessageKey(messageKey.iteration, messageKey.seed);
|
|
82
74
|
}
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
getStructure() {
|
|
78
|
+
return this.senderKeyStateStructure;
|
|
79
|
+
}
|
|
83
80
|
}
|
|
84
|
-
//# sourceMappingURL=sender-key-state.js.map
|
|
@@ -1,26 +1,25 @@
|
|
|
1
1
|
import { deriveSecrets } from 'libsignal/src/crypto.js';
|
|
2
2
|
export class SenderMessageKey {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
3
|
+
constructor(iteration, seed) {
|
|
4
|
+
const derivative = deriveSecrets(seed, Buffer.alloc(32), Buffer.from('WhisperGroup'));
|
|
5
|
+
const keys = new Uint8Array(32);
|
|
6
|
+
keys.set(new Uint8Array(derivative[0].slice(16)));
|
|
7
|
+
keys.set(new Uint8Array(derivative[1].slice(0, 16)), 16);
|
|
8
|
+
this.iv = Buffer.from(derivative[0].slice(0, 16));
|
|
9
|
+
this.cipherKey = Buffer.from(keys.buffer);
|
|
10
|
+
this.iteration = iteration;
|
|
11
|
+
this.seed = seed;
|
|
12
|
+
}
|
|
13
|
+
getIteration() {
|
|
14
|
+
return this.iteration;
|
|
15
|
+
}
|
|
16
|
+
getIv() {
|
|
17
|
+
return this.iv;
|
|
18
|
+
}
|
|
19
|
+
getCipherKey() {
|
|
20
|
+
return this.cipherKey;
|
|
21
|
+
}
|
|
22
|
+
getSeed() {
|
|
23
|
+
return this.seed;
|
|
24
|
+
}
|
|
25
25
|
}
|
|
26
|
-
//# sourceMappingURL=sender-message-key.js.map
|