@pontalabs/baileys 1.0.11 → 1.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/README.md +96 -85
- package/lib/Defaults/connection.js +39 -0
- package/lib/Defaults/constants.js +50 -0
- package/lib/Defaults/history.js +13 -0
- package/lib/Defaults/index.js +36 -151
- package/lib/Defaults/media.js +43 -0
- package/lib/Defaults/phonenumber-mcc.json +221 -221
- package/lib/Defaults/prefix.js +12 -0
- package/lib/Defaults/vialeys-version.json +7 -0
- package/lib/Signal/Group/ciphertext-message.js +10 -15
- package/lib/Signal/Group/group-session-builder.js +34 -60
- package/lib/Signal/Group/group_cipher.js +69 -76
- package/lib/Signal/Group/index.js +41 -60
- package/lib/Signal/Group/keyhelper.js +12 -57
- package/lib/Signal/Group/sender-chain-key.js +20 -33
- package/lib/Signal/Group/sender-key-distribution-message.js +43 -48
- package/lib/Signal/Group/sender-key-message.js +58 -53
- package/lib/Signal/Group/sender-key-name.js +21 -31
- package/lib/Signal/Group/sender-key-record.js +21 -34
- package/lib/Signal/Group/sender-key-state.js +59 -106
- package/lib/Signal/Group/sender-message-key.js +16 -21
- package/lib/Signal/libsignal.js +282 -203
- package/lib/Signal/lid-mapping.js +164 -184
- package/lib/Socket/Client/index.js +31 -22
- package/lib/Socket/Client/types.js +9 -15
- package/lib/Socket/Client/websocket.js +42 -37
- package/lib/Socket/business.js +212 -336
- package/lib/Socket/chats.js +696 -940
- package/lib/Socket/community.js +454 -369
- package/lib/Socket/groups.js +278 -280
- package/lib/Socket/index.js +9 -21
- package/lib/Socket/messages-recv.js +1027 -1570
- package/lib/Socket/messages-send.js +1180 -1136
- package/lib/Socket/mex.js +59 -0
- package/lib/Socket/newsletter.js +193 -251
- package/lib/Socket/socket.js +758 -898
- package/lib/Store/index.js +35 -24
- package/lib/Store/make-cache-manager-store.js +53 -66
- package/lib/Store/make-in-memory-store.js +319 -325
- package/lib/Store/make-ordered-dictionary.js +49 -57
- package/lib/Store/object-repository.js +10 -15
- package/lib/Types/Auth.js +2 -3
- package/lib/Types/Bussines.js +2 -3
- package/lib/Types/Call.js +2 -3
- package/lib/Types/Chat.js +10 -9
- package/lib/Types/Contact.js +2 -3
- package/lib/Types/Events.js +2 -3
- package/lib/Types/GroupMetadata.js +2 -3
- package/lib/Types/Label.js +6 -12
- package/lib/Types/LabelAssociation.js +4 -13
- package/lib/Types/Message.js +10 -18
- package/lib/Types/MexUpdates.js +15 -18
- package/lib/Types/Newsletter.js +26 -34
- package/lib/Types/Product.js +2 -3
- package/lib/Types/Signal.js +2 -3
- package/lib/Types/Socket.js +2 -3
- package/lib/Types/State.js +8 -13
- package/lib/Types/USync.js +2 -3
- package/lib/Types/index.js +49 -40
- package/lib/Utils/auth-utils.js +190 -495
- package/lib/Utils/browser-utils.js +29 -0
- package/lib/Utils/business.js +177 -199
- package/lib/Utils/chat-utils.js +711 -624
- package/lib/Utils/crypto.js +116 -161
- package/lib/Utils/decode-wa-message.js +225 -321
- package/lib/Utils/event-buffer.js +363 -405
- package/lib/Utils/generics.js +318 -472
- package/lib/Utils/history.js +72 -76
- package/lib/Utils/index.js +49 -41
- package/lib/Utils/link-preview.js +59 -103
- package/lib/Utils/logger.js +4 -7
- package/lib/Utils/lt-hash.js +29 -42
- package/lib/Utils/make-mutex.js +26 -42
- package/lib/Utils/message-retry-manager.js +134 -160
- package/lib/Utils/messages-media.js +665 -731
- package/lib/Utils/messages.js +518 -1
- package/lib/Utils/noise-handler.js +127 -125
- package/lib/Utils/pre-key-manager.js +86 -0
- package/lib/Utils/process-message.js +739 -351
- package/lib/Utils/signal.js +146 -129
- package/lib/Utils/use-multi-file-auth-state.js +68 -135
- package/lib/Utils/validate-connection.js +183 -142
- package/lib/Utils/vialeys-event-stream.js +41 -0
- package/lib/WABinary/constants.js +1281 -1289
- package/lib/WABinary/decode.js +145 -200
- package/lib/WABinary/encode.js +149 -202
- package/lib/WABinary/generic-utils.js +79 -97
- package/lib/WABinary/index.js +36 -25
- package/lib/WABinary/jid-utils.js +91 -123
- package/lib/WABinary/types.js +2 -3
- package/lib/WAM/BinaryInfo.js +8 -13
- package/lib/WAM/constants.js +16584 -11464
- package/lib/WAM/encode.js +117 -133
- package/lib/WAM/index.js +34 -23
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +62 -69
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +11 -25
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +32 -44
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +13 -23
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +24 -38
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +17 -31
- package/lib/WAUSync/Protocols/index.js +37 -26
- package/lib/WAUSync/USyncQuery.js +66 -66
- package/lib/WAUSync/USyncUser.js +13 -18
- package/lib/WAUSync/index.js +34 -23
- package/lib/index.js +95 -28
- package/package.json +2 -1
- package/lib/Defaults/baileys-version.json +0 -3
- package/lib/Signal/Group/queue-job.d.ts +0 -1
- package/lib/Signal/Group/queue-job.js +0 -57
- package/lib/Socket/usync.d.ts +0 -37
- package/lib/Socket/usync.js +0 -83
- package/lib/Utils/baileys-event-stream.d.ts +0 -18
- package/lib/Utils/baileys-event-stream.js +0 -70
- package/lib/Utils/signal-housekeeping.d.ts +0 -19
- package/lib/Utils/signal-housekeeping.js +0 -73
- package/lib/Utils/use-mongo-file-auth-state.d.ts +0 -6
- package/lib/Utils/use-mongo-file-auth-state.js +0 -84
- package/lib/Utils/use-single-file-auth-state.d.ts +0 -13
- package/lib/Utils/use-single-file-auth-state.js +0 -80
|
@@ -1,73 +1,78 @@
|
|
|
1
|
-
"use strict"
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true })
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const {
|
|
4
|
+
verifySignature: verifySignature,
|
|
5
|
+
calculateSignature: calculateSignature,
|
|
6
|
+
} = require("libsignal/src/curve");
|
|
7
|
+
const { proto: proto } = require("../../../WAProto");
|
|
8
|
+
const { CiphertextMessage: CiphertextMessage } = require("./ciphertext-message");
|
|
9
|
+
class SenderKeyMessage extends CiphertextMessage {
|
|
9
10
|
constructor(keyId, iteration, ciphertext, signatureKey, serialized) {
|
|
10
|
-
super()
|
|
11
|
-
this.SIGNATURE_LENGTH = 64
|
|
11
|
+
super();
|
|
12
|
+
this.SIGNATURE_LENGTH = 64;
|
|
12
13
|
if (serialized) {
|
|
13
|
-
const version = serialized[0]
|
|
14
|
-
const message = serialized.slice(1, serialized.length - this.SIGNATURE_LENGTH)
|
|
15
|
-
const signature = serialized.slice(-1 * this.SIGNATURE_LENGTH)
|
|
16
|
-
const senderKeyMessage =
|
|
17
|
-
this.serialized = serialized
|
|
18
|
-
this.messageVersion = (version &
|
|
19
|
-
this.keyId = senderKeyMessage.id
|
|
20
|
-
this.iteration = senderKeyMessage.iteration
|
|
14
|
+
const version = serialized[0];
|
|
15
|
+
const message = serialized.slice(1, serialized.length - this.SIGNATURE_LENGTH);
|
|
16
|
+
const signature = serialized.slice(-1 * this.SIGNATURE_LENGTH);
|
|
17
|
+
const senderKeyMessage = proto.SenderKeyMessage.decode(message).toJSON();
|
|
18
|
+
this.serialized = serialized;
|
|
19
|
+
this.messageVersion = (version & 255) >> 4;
|
|
20
|
+
this.keyId = senderKeyMessage.id;
|
|
21
|
+
this.iteration = senderKeyMessage.iteration;
|
|
21
22
|
this.ciphertext =
|
|
22
|
-
typeof senderKeyMessage.ciphertext ===
|
|
23
|
-
? Buffer.from(senderKeyMessage.ciphertext,
|
|
24
|
-
: senderKeyMessage.ciphertext
|
|
25
|
-
this.signature = signature
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
this.
|
|
41
|
-
|
|
23
|
+
typeof senderKeyMessage.ciphertext === "string"
|
|
24
|
+
? Buffer.from(senderKeyMessage.ciphertext, "base64")
|
|
25
|
+
: senderKeyMessage.ciphertext;
|
|
26
|
+
this.signature = signature;
|
|
27
|
+
} else {
|
|
28
|
+
const version = (((this.CURRENT_VERSION << 4) | this.CURRENT_VERSION) & 255) % 256;
|
|
29
|
+
const ciphertextBuffer = Buffer.from(ciphertext);
|
|
30
|
+
const message = proto.SenderKeyMessage.encode(
|
|
31
|
+
proto.SenderKeyMessage.create({
|
|
32
|
+
id: keyId,
|
|
33
|
+
iteration: iteration,
|
|
34
|
+
ciphertext: ciphertextBuffer,
|
|
35
|
+
})
|
|
36
|
+
).finish();
|
|
37
|
+
const signature = this.getSignature(
|
|
38
|
+
signatureKey,
|
|
39
|
+
Buffer.concat([Buffer.from([version]), message])
|
|
40
|
+
);
|
|
41
|
+
this.serialized = Buffer.concat([
|
|
42
|
+
Buffer.from([version]),
|
|
43
|
+
message,
|
|
44
|
+
Buffer.from(signature),
|
|
45
|
+
]);
|
|
46
|
+
this.messageVersion = this.CURRENT_VERSION;
|
|
47
|
+
this.keyId = keyId;
|
|
48
|
+
this.iteration = iteration;
|
|
49
|
+
this.ciphertext = ciphertextBuffer;
|
|
50
|
+
this.signature = signature;
|
|
42
51
|
}
|
|
43
52
|
}
|
|
44
53
|
getKeyId() {
|
|
45
|
-
return this.keyId
|
|
54
|
+
return this.keyId;
|
|
46
55
|
}
|
|
47
56
|
getIteration() {
|
|
48
|
-
return this.iteration
|
|
57
|
+
return this.iteration;
|
|
49
58
|
}
|
|
50
59
|
getCipherText() {
|
|
51
|
-
return this.ciphertext
|
|
60
|
+
return this.ciphertext;
|
|
52
61
|
}
|
|
53
62
|
verifySignature(signatureKey) {
|
|
54
|
-
const part1 = this.serialized.slice(0, this.serialized.length - this.SIGNATURE_LENGTH)
|
|
55
|
-
const part2 = this.serialized.slice(-1 * this.SIGNATURE_LENGTH)
|
|
56
|
-
const res =
|
|
57
|
-
if (!res)
|
|
58
|
-
throw new Error('Invalid signature!')
|
|
63
|
+
const part1 = this.serialized.slice(0, this.serialized.length - this.SIGNATURE_LENGTH);
|
|
64
|
+
const part2 = this.serialized.slice(-1 * this.SIGNATURE_LENGTH);
|
|
65
|
+
const res = verifySignature(signatureKey, part1, part2);
|
|
66
|
+
if (!res) throw new Error("Invalid signature!");
|
|
59
67
|
}
|
|
60
68
|
getSignature(signatureKey, serialized) {
|
|
61
|
-
return Buffer.from(
|
|
69
|
+
return Buffer.from(calculateSignature(signatureKey, serialized));
|
|
62
70
|
}
|
|
63
71
|
serialize() {
|
|
64
|
-
return this.serialized
|
|
72
|
+
return this.serialized;
|
|
65
73
|
}
|
|
66
74
|
getType() {
|
|
67
|
-
return 4
|
|
75
|
+
return 4;
|
|
68
76
|
}
|
|
69
77
|
}
|
|
70
|
-
|
|
71
|
-
module.exports = {
|
|
72
|
-
SenderKeyMessage
|
|
73
|
-
}
|
|
78
|
+
module.exports = { SenderKeyMessage: SenderKeyMessage };
|
|
@@ -1,59 +1,49 @@
|
|
|
1
|
-
"use strict"
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true })
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
3
|
function isNull(str) {
|
|
6
|
-
return str === null || str ===
|
|
4
|
+
return str === null || str === "";
|
|
7
5
|
}
|
|
8
|
-
|
|
9
6
|
function intValue(num) {
|
|
10
|
-
const MAX_VALUE =
|
|
11
|
-
const MIN_VALUE = -
|
|
7
|
+
const MAX_VALUE = 2147483647;
|
|
8
|
+
const MIN_VALUE = -2147483648;
|
|
12
9
|
if (num > MAX_VALUE || num < MIN_VALUE) {
|
|
13
|
-
return num &
|
|
10
|
+
return num & 4294967295;
|
|
14
11
|
}
|
|
15
|
-
|
|
16
|
-
return num
|
|
12
|
+
return num;
|
|
17
13
|
}
|
|
18
|
-
|
|
19
14
|
function hashCode(strKey) {
|
|
20
|
-
let hash = 0
|
|
15
|
+
let hash = 0;
|
|
21
16
|
if (!isNull(strKey)) {
|
|
22
17
|
for (let i = 0; i < strKey.length; i++) {
|
|
23
|
-
hash = hash * 31 + strKey.charCodeAt(i)
|
|
24
|
-
hash = intValue(hash)
|
|
18
|
+
hash = hash * 31 + strKey.charCodeAt(i);
|
|
19
|
+
hash = intValue(hash);
|
|
25
20
|
}
|
|
26
21
|
}
|
|
27
|
-
return hash
|
|
22
|
+
return hash;
|
|
28
23
|
}
|
|
29
|
-
|
|
30
24
|
class SenderKeyName {
|
|
31
25
|
constructor(groupId, sender) {
|
|
32
|
-
this.groupId = groupId
|
|
33
|
-
this.sender = sender
|
|
26
|
+
this.groupId = groupId;
|
|
27
|
+
this.sender = sender;
|
|
34
28
|
}
|
|
35
29
|
getGroupId() {
|
|
36
|
-
return this.groupId
|
|
30
|
+
return this.groupId;
|
|
37
31
|
}
|
|
38
32
|
getSender() {
|
|
39
|
-
return this.sender
|
|
33
|
+
return this.sender;
|
|
40
34
|
}
|
|
41
35
|
serialize() {
|
|
42
|
-
return `${this.groupId}::${this.sender.id}::${this.sender.deviceId}
|
|
36
|
+
return `${this.groupId}::${this.sender.id}::${this.sender.deviceId}`;
|
|
43
37
|
}
|
|
44
38
|
toString() {
|
|
45
|
-
return this.serialize()
|
|
39
|
+
return this.serialize();
|
|
46
40
|
}
|
|
47
41
|
equals(other) {
|
|
48
|
-
if (other === null)
|
|
49
|
-
|
|
50
|
-
return this.groupId === other.groupId && this.sender.toString() === other.sender.toString()
|
|
42
|
+
if (other === null) return false;
|
|
43
|
+
return this.groupId === other.groupId && this.sender.toString() === other.sender.toString();
|
|
51
44
|
}
|
|
52
45
|
hashCode() {
|
|
53
|
-
return hashCode(this.groupId) ^ hashCode(this.sender.toString())
|
|
46
|
+
return hashCode(this.groupId) ^ hashCode(this.sender.toString());
|
|
54
47
|
}
|
|
55
48
|
}
|
|
56
|
-
|
|
57
|
-
module.exports = {
|
|
58
|
-
SenderKeyName
|
|
59
|
-
}
|
|
49
|
+
module.exports = { SenderKeyName: SenderKeyName };
|
|
@@ -1,58 +1,45 @@
|
|
|
1
|
-
"use strict"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const generics_1 = require("../../Utils/generics")
|
|
6
|
-
const sender_key_state_1 = require("./sender-key-state")
|
|
7
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const { BufferJSON: BufferJSON } = require("../../Utils/generics");
|
|
4
|
+
const { SenderKeyState: SenderKeyState } = require("./sender-key-state");
|
|
8
5
|
class SenderKeyRecord {
|
|
9
6
|
constructor(serialized) {
|
|
10
|
-
this.MAX_STATES = 5
|
|
11
|
-
this.senderKeyStates = []
|
|
7
|
+
this.MAX_STATES = 5;
|
|
8
|
+
this.senderKeyStates = [];
|
|
12
9
|
if (serialized) {
|
|
13
10
|
for (const structure of serialized) {
|
|
14
|
-
this.senderKeyStates.push(
|
|
11
|
+
this.senderKeyStates.push(
|
|
12
|
+
new SenderKeyState(null, null, null, null, null, null, structure)
|
|
13
|
+
);
|
|
15
14
|
}
|
|
16
15
|
}
|
|
17
16
|
}
|
|
18
17
|
isEmpty() {
|
|
19
|
-
return this.senderKeyStates.length === 0
|
|
18
|
+
return this.senderKeyStates.length === 0;
|
|
20
19
|
}
|
|
21
20
|
getSenderKeyState(keyId) {
|
|
22
21
|
if (keyId === undefined && this.senderKeyStates.length) {
|
|
23
|
-
return this.senderKeyStates[this.senderKeyStates.length - 1]
|
|
22
|
+
return this.senderKeyStates[this.senderKeyStates.length - 1];
|
|
24
23
|
}
|
|
25
|
-
return this.senderKeyStates.find(state => state.getKeyId() === keyId)
|
|
24
|
+
return this.senderKeyStates.find((state) => state.getKeyId() === keyId);
|
|
26
25
|
}
|
|
27
26
|
addSenderKeyState(id, iteration, chainKey, signatureKey) {
|
|
28
|
-
this.senderKeyStates.push(new
|
|
27
|
+
this.senderKeyStates.push(new SenderKeyState(id, iteration, chainKey, null, signatureKey));
|
|
29
28
|
if (this.senderKeyStates.length > this.MAX_STATES) {
|
|
30
|
-
this.senderKeyStates.shift()
|
|
29
|
+
this.senderKeyStates.shift();
|
|
31
30
|
}
|
|
32
31
|
}
|
|
33
32
|
setSenderKeyState(id, iteration, chainKey, keyPair) {
|
|
34
|
-
this.senderKeyStates.length = 0
|
|
35
|
-
this.senderKeyStates.push(new
|
|
33
|
+
this.senderKeyStates.length = 0;
|
|
34
|
+
this.senderKeyStates.push(new SenderKeyState(id, iteration, chainKey, keyPair));
|
|
36
35
|
}
|
|
37
36
|
serialize() {
|
|
38
|
-
return this.senderKeyStates.map(state => state.getStructure())
|
|
37
|
+
return this.senderKeyStates.map((state) => state.getStructure());
|
|
39
38
|
}
|
|
40
39
|
static deserialize(data) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
else if (data instanceof Uint8Array) {
|
|
46
|
-
const str = Buffer.from(data).toString('utf-8')
|
|
47
|
-
parsed = JSON.parse(str, generics_1.BufferJSON.reviver)
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
parsed = data
|
|
51
|
-
}
|
|
52
|
-
return new SenderKeyRecord(parsed)
|
|
40
|
+
const str = Buffer.from(data).toString("utf-8");
|
|
41
|
+
const parsed = JSON.parse(str, BufferJSON.reviver);
|
|
42
|
+
return new SenderKeyRecord(parsed);
|
|
53
43
|
}
|
|
54
44
|
}
|
|
55
|
-
|
|
56
|
-
module.exports = {
|
|
57
|
-
SenderKeyRecord
|
|
58
|
-
}
|
|
45
|
+
module.exports = { SenderKeyRecord: SenderKeyRecord };
|
|
@@ -1,147 +1,100 @@
|
|
|
1
|
-
"use strict"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const sender_chain_key_1 = require("./sender-chain-key")
|
|
6
|
-
const sender_message_key_1 = require("./sender-message-key")
|
|
7
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const { SenderChainKey: SenderChainKey } = require("./sender-chain-key");
|
|
4
|
+
const { SenderMessageKey: SenderMessageKey } = require("./sender-message-key");
|
|
8
5
|
class SenderKeyState {
|
|
9
|
-
constructor(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return Buffer.alloc(0)
|
|
20
|
-
}
|
|
21
|
-
|
|
6
|
+
constructor(
|
|
7
|
+
id,
|
|
8
|
+
iteration,
|
|
9
|
+
chainKey,
|
|
10
|
+
signatureKeyPair,
|
|
11
|
+
signatureKeyPublic,
|
|
12
|
+
signatureKeyPrivate,
|
|
13
|
+
senderKeyStateStructure
|
|
14
|
+
) {
|
|
15
|
+
this.MAX_MESSAGE_KEYS = 2e3;
|
|
22
16
|
if (senderKeyStateStructure) {
|
|
23
17
|
this.senderKeyStateStructure = {
|
|
24
18
|
...senderKeyStateStructure,
|
|
25
19
|
senderMessageKeys: Array.isArray(senderKeyStateStructure.senderMessageKeys)
|
|
26
20
|
? senderKeyStateStructure.senderMessageKeys
|
|
27
|
-
: []
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
21
|
+
: [],
|
|
22
|
+
};
|
|
23
|
+
} else {
|
|
31
24
|
if (signatureKeyPair) {
|
|
32
|
-
signatureKeyPublic = signatureKeyPair.public
|
|
33
|
-
signatureKeyPrivate = signatureKeyPair.private
|
|
34
|
-
}
|
|
35
|
-
chainKey = typeof chainKey === 'string' ? Buffer.from(chainKey, 'base64') : chainKey
|
|
36
|
-
|
|
37
|
-
const senderChainKeyStructure = {
|
|
38
|
-
iteration: iteration || 0,
|
|
39
|
-
seed: chainKey ? toBuffer(chainKey) : Buffer.alloc(0)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const signingKeyStructure = {
|
|
43
|
-
public: toBuffer(signatureKeyPublic),
|
|
44
|
-
private: signatureKeyPrivate ? toBuffer(signatureKeyPrivate) : undefined
|
|
25
|
+
signatureKeyPublic = signatureKeyPair.public;
|
|
26
|
+
signatureKeyPrivate = signatureKeyPair.private;
|
|
45
27
|
}
|
|
46
|
-
|
|
47
28
|
this.senderKeyStateStructure = {
|
|
48
29
|
senderKeyId: id || 0,
|
|
49
|
-
senderChainKey:
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
30
|
+
senderChainKey: {
|
|
31
|
+
iteration: iteration || 0,
|
|
32
|
+
seed: Buffer.from(chainKey || []),
|
|
33
|
+
},
|
|
34
|
+
senderSigningKey: {
|
|
35
|
+
public: Buffer.from(signatureKeyPublic || []),
|
|
36
|
+
private: Buffer.from(signatureKeyPrivate || []),
|
|
37
|
+
},
|
|
38
|
+
senderMessageKeys: [],
|
|
39
|
+
};
|
|
53
40
|
}
|
|
54
41
|
}
|
|
55
42
|
getKeyId() {
|
|
56
|
-
return this.senderKeyStateStructure.senderKeyId
|
|
43
|
+
return this.senderKeyStateStructure.senderKeyId;
|
|
57
44
|
}
|
|
58
45
|
getSenderChainKey() {
|
|
59
|
-
return new
|
|
46
|
+
return new SenderChainKey(
|
|
47
|
+
this.senderKeyStateStructure.senderChainKey.iteration,
|
|
48
|
+
this.senderKeyStateStructure.senderChainKey.seed
|
|
49
|
+
);
|
|
60
50
|
}
|
|
61
51
|
setSenderChainKey(chainKey) {
|
|
62
52
|
this.senderKeyStateStructure.senderChainKey = {
|
|
63
53
|
iteration: chainKey.getIteration(),
|
|
64
|
-
seed: chainKey.getSeed()
|
|
65
|
-
}
|
|
54
|
+
seed: chainKey.getSeed(),
|
|
55
|
+
};
|
|
66
56
|
}
|
|
67
57
|
getSigningKeyPublic() {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
// normalize into Buffer
|
|
71
|
-
if (!Buffer.isBuffer(key)) {
|
|
72
|
-
if (key instanceof Uint8Array) {
|
|
73
|
-
key = Buffer.from(key)
|
|
74
|
-
}
|
|
75
|
-
else if (typeof key === 'string') {
|
|
76
|
-
key = Buffer.from(key, 'base64')
|
|
77
|
-
}
|
|
78
|
-
else if (key && typeof key === 'object') {
|
|
79
|
-
return Buffer.from(Object.values(key)) // temp fix // inspired by @MartinSchere 's #1741
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
key = Buffer.from(key || [])
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const publicKey = key
|
|
87
|
-
|
|
58
|
+
const publicKey = Buffer.from(this.senderKeyStateStructure.senderSigningKey.public);
|
|
88
59
|
if (publicKey.length === 32) {
|
|
89
|
-
const fixed = Buffer.alloc(33)
|
|
90
|
-
|
|
91
|
-
fixed
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
return fixed
|
|
60
|
+
const fixed = Buffer.alloc(33);
|
|
61
|
+
fixed[0] = 5;
|
|
62
|
+
publicKey.copy(fixed, 1);
|
|
63
|
+
return fixed;
|
|
95
64
|
}
|
|
96
|
-
|
|
97
|
-
return publicKey
|
|
65
|
+
return publicKey;
|
|
98
66
|
}
|
|
99
67
|
getSigningKeyPrivate() {
|
|
100
|
-
const privateKey = this.senderKeyStateStructure.senderSigningKey.private
|
|
101
|
-
|
|
102
|
-
return undefined
|
|
103
|
-
}
|
|
104
|
-
if (Buffer.isBuffer(privateKey)) {
|
|
105
|
-
return privateKey
|
|
106
|
-
}
|
|
107
|
-
else if (privateKey instanceof Uint8Array) {
|
|
108
|
-
return Buffer.from(privateKey)
|
|
109
|
-
}
|
|
110
|
-
else if (privateKey && typeof privateKey === 'object') {
|
|
111
|
-
return Buffer.from(Object.values(privateKey)) // temp fix // inspired by @MartinSchere 's #1741
|
|
112
|
-
}
|
|
113
|
-
else if (typeof privateKey === 'string') {
|
|
114
|
-
return Buffer.from(privateKey, 'base64')
|
|
115
|
-
}
|
|
116
|
-
return Buffer.from(privateKey || [])
|
|
68
|
+
const privateKey = this.senderKeyStateStructure.senderSigningKey.private;
|
|
69
|
+
return Buffer.from(privateKey || []);
|
|
117
70
|
}
|
|
118
71
|
hasSenderMessageKey(iteration) {
|
|
119
|
-
return this.senderKeyStateStructure.senderMessageKeys.some(
|
|
72
|
+
return this.senderKeyStateStructure.senderMessageKeys.some(
|
|
73
|
+
(key) => key.iteration === iteration
|
|
74
|
+
);
|
|
120
75
|
}
|
|
121
76
|
addSenderMessageKey(senderMessageKey) {
|
|
122
77
|
this.senderKeyStateStructure.senderMessageKeys.push({
|
|
123
78
|
iteration: senderMessageKey.getIteration(),
|
|
124
|
-
seed: senderMessageKey.getSeed()
|
|
125
|
-
})
|
|
126
|
-
|
|
79
|
+
seed: senderMessageKey.getSeed(),
|
|
80
|
+
});
|
|
127
81
|
if (this.senderKeyStateStructure.senderMessageKeys.length > this.MAX_MESSAGE_KEYS) {
|
|
128
|
-
this.senderKeyStateStructure.senderMessageKeys.shift()
|
|
82
|
+
this.senderKeyStateStructure.senderMessageKeys.shift();
|
|
129
83
|
}
|
|
130
84
|
}
|
|
131
85
|
removeSenderMessageKey(iteration) {
|
|
132
|
-
const index = this.senderKeyStateStructure.senderMessageKeys.findIndex(
|
|
86
|
+
const index = this.senderKeyStateStructure.senderMessageKeys.findIndex(
|
|
87
|
+
(key) => key.iteration === iteration
|
|
88
|
+
);
|
|
133
89
|
if (index !== -1) {
|
|
134
|
-
const messageKey = this.senderKeyStateStructure.senderMessageKeys[index]
|
|
135
|
-
this.senderKeyStateStructure.senderMessageKeys.splice(index, 1)
|
|
136
|
-
return new
|
|
90
|
+
const messageKey = this.senderKeyStateStructure.senderMessageKeys[index];
|
|
91
|
+
this.senderKeyStateStructure.senderMessageKeys.splice(index, 1);
|
|
92
|
+
return new SenderMessageKey(messageKey.iteration, messageKey.seed);
|
|
137
93
|
}
|
|
138
|
-
return null
|
|
94
|
+
return null;
|
|
139
95
|
}
|
|
140
96
|
getStructure() {
|
|
141
|
-
return this.senderKeyStateStructure
|
|
97
|
+
return this.senderKeyStateStructure;
|
|
142
98
|
}
|
|
143
99
|
}
|
|
144
|
-
|
|
145
|
-
module.exports = {
|
|
146
|
-
SenderKeyState
|
|
147
|
-
}
|
|
100
|
+
module.exports = { SenderKeyState: SenderKeyState };
|
|
@@ -1,33 +1,28 @@
|
|
|
1
|
-
"use strict"
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true })
|
|
3
|
-
|
|
4
|
-
const crypto_1 = require("libsignal/src/crypto")
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const { deriveSecrets: deriveSecrets } = require("libsignal/src/crypto");
|
|
6
4
|
class SenderMessageKey {
|
|
7
5
|
constructor(iteration, seed) {
|
|
8
|
-
const derivative =
|
|
9
|
-
const keys = new Uint8Array(32)
|
|
10
|
-
keys.set(new Uint8Array(derivative[0].slice(16)))
|
|
11
|
-
keys.set(new Uint8Array(derivative[1].slice(0, 16)), 16)
|
|
12
|
-
this.iv = Buffer.from(derivative[0].slice(0, 16))
|
|
13
|
-
this.cipherKey = Buffer.from(keys.buffer)
|
|
14
|
-
this.iteration = iteration
|
|
15
|
-
this.seed = seed
|
|
6
|
+
const derivative = deriveSecrets(seed, Buffer.alloc(32), Buffer.from("WhisperGroup"));
|
|
7
|
+
const keys = new Uint8Array(32);
|
|
8
|
+
keys.set(new Uint8Array(derivative[0].slice(16)));
|
|
9
|
+
keys.set(new Uint8Array(derivative[1].slice(0, 16)), 16);
|
|
10
|
+
this.iv = Buffer.from(derivative[0].slice(0, 16));
|
|
11
|
+
this.cipherKey = Buffer.from(keys.buffer);
|
|
12
|
+
this.iteration = iteration;
|
|
13
|
+
this.seed = seed;
|
|
16
14
|
}
|
|
17
15
|
getIteration() {
|
|
18
|
-
return this.iteration
|
|
16
|
+
return this.iteration;
|
|
19
17
|
}
|
|
20
18
|
getIv() {
|
|
21
|
-
return this.iv
|
|
19
|
+
return this.iv;
|
|
22
20
|
}
|
|
23
21
|
getCipherKey() {
|
|
24
|
-
return this.cipherKey
|
|
22
|
+
return this.cipherKey;
|
|
25
23
|
}
|
|
26
24
|
getSeed() {
|
|
27
|
-
return this.seed
|
|
25
|
+
return this.seed;
|
|
28
26
|
}
|
|
29
27
|
}
|
|
30
|
-
|
|
31
|
-
module.exports = {
|
|
32
|
-
SenderMessageKey
|
|
33
|
-
}
|
|
28
|
+
module.exports = { SenderMessageKey: SenderMessageKey };
|