@hansaka02/baileys 7.3.2 → 7.3.4
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 +247 -203
- package/lib/Defaults/connection.js +51 -0
- package/lib/Defaults/constants.js +62 -0
- package/lib/Defaults/history.js +17 -0
- package/lib/Defaults/index.js +36 -142
- package/lib/Defaults/media.js +48 -0
- package/lib/Defaults/prefix.js +18 -0
- package/lib/Signal/Group/group-session-builder.js +10 -42
- package/lib/Signal/Group/group_cipher.js +9 -6
- package/lib/Signal/Group/index.js +39 -53
- package/lib/Signal/Group/keyhelper.js +8 -41
- package/lib/Signal/Group/sender-chain-key.js +4 -4
- package/lib/Signal/Group/sender-key-distribution-message.js +5 -5
- package/lib/Signal/Group/sender-key-message.js +12 -8
- package/lib/Signal/Group/sender-key-record.js +7 -7
- package/lib/Signal/Group/sender-key-state.js +4 -4
- package/lib/Signal/Group/sender-message-key.js +2 -2
- package/lib/Signal/libsignal.js +45 -69
- package/lib/Signal/lid-mapping.js +15 -11
- package/lib/Socket/Client/types.js +2 -2
- package/lib/Socket/Client/websocket.js +16 -14
- package/lib/Socket/business.js +41 -32
- package/lib/Socket/chats.js +123 -98
- package/lib/Socket/community.js +50 -40
- package/lib/Socket/groups.js +59 -47
- package/lib/Socket/index.js +4 -4
- package/lib/Socket/messages-recv.js +219 -172
- package/lib/Socket/messages-send.js +187 -143
- package/lib/Socket/newsletter.js +61 -47
- package/lib/Socket/socket.js +133 -90
- package/lib/Socket/usync.js +6 -6
- package/lib/Store/index.js +27 -11
- package/lib/Store/make-cache-manager-store.js +14 -15
- package/lib/Store/make-in-memory-store.js +28 -24
- package/lib/Types/LabelAssociation.js +2 -2
- package/lib/Types/Message.js +6 -6
- package/lib/Types/MexUpdates.js +5 -5
- package/lib/Types/State.js +4 -4
- package/lib/Types/index.js +28 -12
- package/lib/Utils/auth-utils.js +28 -26
- package/lib/Utils/baileys-event-stream.js +68 -69
- package/lib/Utils/business.js +63 -53
- package/lib/Utils/chat-utils.js +81 -71
- package/lib/Utils/crypto.js +25 -45
- package/lib/Utils/decode-wa-message.js +319 -311
- package/lib/Utils/event-buffer.js +21 -22
- package/lib/Utils/generics.js +65 -82
- package/lib/Utils/history.js +21 -21
- package/lib/Utils/index.js +27 -13
- package/lib/Utils/link-preview.js +7 -30
- package/lib/Utils/logger.js +5 -5
- package/lib/Utils/lt-hash.js +3 -3
- package/lib/Utils/message-retry-manager.js +4 -4
- package/lib/Utils/messages-media.js +104 -109
- package/lib/Utils/messages.js +203 -171
- package/lib/Utils/noise-handler.js +28 -19
- package/lib/Utils/process-message.js +111 -96
- package/lib/Utils/signal.js +36 -25
- package/lib/Utils/use-multi-file-auth-state.js +18 -22
- package/lib/Utils/validate-connection.js +52 -45
- package/lib/WABinary/decode.js +6 -32
- package/lib/WABinary/encode.js +3 -29
- package/lib/WABinary/generic-utils.js +4 -4
- package/lib/WABinary/index.js +27 -11
- package/lib/WAM/encode.js +16 -8
- package/lib/WAM/index.js +27 -11
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +20 -16
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +7 -4
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +0 -2
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +2 -2
- package/lib/WAUSync/Protocols/index.js +27 -11
- package/lib/WAUSync/USyncQuery.js +17 -10
- package/lib/WAUSync/index.js +27 -11
- package/lib/index.js +60 -31
- package/package.json +8 -14
- package/WAProto/AICommon/AICommon.d.ts +0 -11702
- package/WAProto/Adv/Adv.d.ts +0 -643
- package/WAProto/BotMetadata/BotMetadata.d.ts +0 -5654
- package/WAProto/Cert/Cert.d.ts +0 -613
- package/WAProto/ChatLockSettings/ChatLockSettings.d.ts +0 -476
- package/WAProto/CompanionReg/CompanionReg.d.ts +0 -1361
- package/WAProto/DeviceCapabilities/DeviceCapabilities.d.ts +0 -577
- package/WAProto/E2E/E2E.d.ts +0 -41724
- package/WAProto/Ephemeral/Ephemeral.d.ts +0 -114
- package/WAProto/HistorySync/HistorySync.d.ts +0 -51700
- package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.d.ts +0 -229
- package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.d.ts +0 -583
- package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.d.ts +0 -42897
- package/WAProto/MmsRetry/MmsRetry.d.ts +0 -243
- package/WAProto/Protocol/Protocol.d.ts +0 -270
- package/WAProto/Reporting/Reporting.d.ts +0 -371
- package/WAProto/ServerSync/ServerSync.d.ts +0 -1285
- package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.d.ts +0 -1868
- package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.d.ts +0 -767
- package/WAProto/StatusAttributions/StatusAttributions.d.ts +0 -1027
- package/WAProto/SyncAction/SyncAction.d.ts +0 -11193
- package/WAProto/UserPassword/UserPassword.d.ts +0 -363
- package/WAProto/VnameCert/VnameCert.d.ts +0 -821
- package/WAProto/Wa6/Wa6.d.ts +0 -2128
- package/WAProto/Web/Web.d.ts +0 -46383
- package/WAProto/index.d.ts +0 -55
- package/lib/Defaults/index.d.ts +0 -77
- package/lib/Signal/Group/ciphertext-message.d.ts +0 -9
- package/lib/Signal/Group/group-session-builder.d.ts +0 -17
- package/lib/Signal/Group/group_cipher.d.ts +0 -19
- package/lib/Signal/Group/index.d.ts +0 -11
- package/lib/Signal/Group/keyhelper.d.ts +0 -16
- 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 -19
- package/lib/Signal/Group/sender-key-record.d.ts +0 -32
- package/lib/Signal/Group/sender-key-state.d.ts +0 -44
- package/lib/Signal/Group/sender-message-key.d.ts +0 -11
- package/lib/Signal/libsignal.d.ts +0 -8
- package/lib/Signal/lid-mapping.d.ts +0 -28
- package/lib/Socket/Client/index.d.ts +0 -2
- 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 -187
- package/lib/Socket/chats.d.ts +0 -97
- package/lib/Socket/community.d.ts +0 -129
- package/lib/Socket/groups.d.ts +0 -129
- package/lib/Socket/index.d.ts +0 -191
- package/lib/Socket/messages-recv.d.ts +0 -174
- package/lib/Socket/messages-send.d.ts +0 -165
- package/lib/Socket/newsletter.d.ts +0 -145
- package/lib/Socket/socket.d.ts +0 -45
- package/lib/Socket/usync.d.ts +0 -37
- package/lib/Store/index.d.ts +0 -4
- package/lib/Store/make-cache-manager-store.d.ts +0 -14
- package/lib/Store/make-in-memory-store.d.ts +0 -123
- package/lib/Store/make-ordered-dictionary.d.ts +0 -12
- package/lib/Store/object-repository.d.ts +0 -10
- package/lib/Types/Auth.d.ts +0 -121
- package/lib/Types/Bussiness.d.ts +0 -28
- package/lib/Types/Call.d.ts +0 -14
- package/lib/Types/Chat.d.ts +0 -143
- package/lib/Types/Contact.d.ts +0 -23
- package/lib/Types/Events.d.ts +0 -226
- package/lib/Types/GroupMetadata.d.ts +0 -66
- package/lib/Types/Label.d.ts +0 -48
- package/lib/Types/LabelAssociation.d.ts +0 -35
- package/lib/Types/Message.d.ts +0 -484
- package/lib/Types/MexUpdates.d.ts +0 -9
- package/lib/Types/Newsletter.d.ts +0 -109
- package/lib/Types/Product.d.ts +0 -92
- package/lib/Types/Signal.d.ts +0 -98
- package/lib/Types/Socket.d.ts +0 -141
- package/lib/Types/State.d.ts +0 -41
- package/lib/Types/USync.d.ts +0 -26
- package/lib/Types/index.d.ts +0 -80
- package/lib/Utils/auth-utils.d.ts +0 -21
- package/lib/Utils/baileys-event-stream.d.ts +0 -18
- package/lib/Utils/business.d.ts +0 -29
- package/lib/Utils/chat-utils.d.ts +0 -82
- package/lib/Utils/crypto.d.ts +0 -56
- package/lib/Utils/decode-wa-message.d.ts +0 -53
- package/lib/Utils/event-buffer.d.ts +0 -39
- package/lib/Utils/generics.d.ts +0 -117
- package/lib/Utils/history.d.ts +0 -23
- package/lib/Utils/index.d.ts +0 -20
- package/lib/Utils/link-preview.d.ts +0 -23
- package/lib/Utils/logger.d.ts +0 -13
- package/lib/Utils/lt-hash.d.ts +0 -14
- package/lib/Utils/make-mutex.d.ts +0 -9
- package/lib/Utils/message-retry-manager.d.ts +0 -88
- package/lib/Utils/messages-media.d.ts +0 -135
- package/lib/Utils/messages.d.ts +0 -105
- package/lib/Utils/noise-handler.d.ts +0 -20
- package/lib/Utils/process-message.d.ts +0 -49
- package/lib/Utils/signal.d.ts +0 -42
- 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-multi-file-auth-state.d.ts +0 -13
- package/lib/Utils/use-single-file-auth-state.d.ts +0 -13
- package/lib/Utils/use-single-file-auth-state.js +0 -80
- package/lib/Utils/validate-connection.d.ts +0 -13
- package/lib/WABinary/constants.d.ts +0 -30
- package/lib/WABinary/decode.d.ts +0 -9
- package/lib/WABinary/encode.d.ts +0 -3
- package/lib/WABinary/generic-utils.d.ts +0 -28
- package/lib/WABinary/index.d.ts +0 -5
- package/lib/WABinary/jid-utils.d.ts +0 -58
- package/lib/WABinary/types.d.ts +0 -22
- package/lib/WAM/BinaryInfo.d.ts +0 -16
- package/lib/WAM/constants.d.ts +0 -47
- package/lib/WAM/encode.d.ts +0 -3
- package/lib/WAM/index.d.ts +0 -3
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.d.ts +0 -28
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -10
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -26
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -14
- package/lib/WAUSync/Protocols/USyncLIDProtocol.d.ts +0 -10
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -14
- package/lib/WAUSync/Protocols/index.d.ts +0 -6
- package/lib/WAUSync/USyncQuery.d.ts +0 -31
- package/lib/WAUSync/USyncUser.d.ts +0 -12
- package/lib/WAUSync/index.d.ts +0 -3
- package/lib/index.d.ts +0 -13
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true })
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
const
|
|
5
|
+
const { calculateMAC } = require("@itsukichan/libsignal-node/src/crypto")
|
|
6
|
+
const { SenderMessageKey } = require("./sender-message-key")
|
|
7
7
|
|
|
8
8
|
class SenderChainKey {
|
|
9
9
|
constructor(iteration, chainKey) {
|
|
@@ -29,7 +29,7 @@ class SenderChainKey {
|
|
|
29
29
|
return this.iteration
|
|
30
30
|
}
|
|
31
31
|
getSenderMessageKey() {
|
|
32
|
-
return new
|
|
32
|
+
return new SenderMessageKey(this.iteration, this.getDerivative(this.MESSAGE_KEY_SEED, this.chainKey))
|
|
33
33
|
}
|
|
34
34
|
getNext() {
|
|
35
35
|
return new SenderChainKey(this.iteration + 1, this.getDerivative(this.CHAIN_KEY_SEED, this.chainKey))
|
|
@@ -38,7 +38,7 @@ class SenderChainKey {
|
|
|
38
38
|
return this.chainKey
|
|
39
39
|
}
|
|
40
40
|
getDerivative(seed, key) {
|
|
41
|
-
return
|
|
41
|
+
return calculateMAC(key, seed)
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
|
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true })
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
const
|
|
5
|
+
const { proto } = require("../../../WAProto")
|
|
6
|
+
const { CiphertextMessage } = require("./ciphertext-message")
|
|
7
7
|
|
|
8
|
-
class SenderKeyDistributionMessage extends
|
|
8
|
+
class SenderKeyDistributionMessage extends CiphertextMessage {
|
|
9
9
|
constructor(id, iteration, chainKey, signatureKey, serialized) {
|
|
10
10
|
super()
|
|
11
11
|
if (serialized) {
|
|
12
12
|
try {
|
|
13
13
|
const message = serialized.slice(1)
|
|
14
|
-
const distributionMessage =
|
|
14
|
+
const distributionMessage = proto.SenderKeyDistributionMessage.decode(message).toJSON()
|
|
15
15
|
this.serialized = serialized
|
|
16
16
|
this.id = distributionMessage.id
|
|
17
17
|
this.iteration = distributionMessage.iteration
|
|
@@ -34,7 +34,7 @@ class SenderKeyDistributionMessage extends ciphertext_message_1.CiphertextMessag
|
|
|
34
34
|
this.iteration = iteration
|
|
35
35
|
this.chainKey = chainKey
|
|
36
36
|
this.signatureKey = signatureKey
|
|
37
|
-
const message =
|
|
37
|
+
const message = proto.SenderKeyDistributionMessage.encode(proto.SenderKeyDistributionMessage.create({
|
|
38
38
|
id,
|
|
39
39
|
iteration,
|
|
40
40
|
chainKey,
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
"use strict"
|
|
2
|
+
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true })
|
|
3
4
|
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
const {
|
|
6
|
+
verifySignature,
|
|
7
|
+
calculateSignature
|
|
8
|
+
} = require("@itsukichan/libsignal-node/src/curve")
|
|
9
|
+
const { proto } = require("../../../WAProto")
|
|
10
|
+
const { CiphertextMessage } = require("./ciphertext-message")
|
|
7
11
|
|
|
8
|
-
class SenderKeyMessage extends
|
|
12
|
+
class SenderKeyMessage extends CiphertextMessage {
|
|
9
13
|
constructor(keyId, iteration, ciphertext, signatureKey, serialized) {
|
|
10
14
|
super()
|
|
11
15
|
this.SIGNATURE_LENGTH = 64
|
|
@@ -13,7 +17,7 @@ class SenderKeyMessage extends ciphertext_message_1.CiphertextMessage {
|
|
|
13
17
|
const version = serialized[0]
|
|
14
18
|
const message = serialized.slice(1, serialized.length - this.SIGNATURE_LENGTH)
|
|
15
19
|
const signature = serialized.slice(-1 * this.SIGNATURE_LENGTH)
|
|
16
|
-
const senderKeyMessage =
|
|
20
|
+
const senderKeyMessage = proto.SenderKeyMessage.decode(message).toJSON()
|
|
17
21
|
this.serialized = serialized
|
|
18
22
|
this.messageVersion = (version & 0xff) >> 4
|
|
19
23
|
this.keyId = senderKeyMessage.id
|
|
@@ -27,7 +31,7 @@ class SenderKeyMessage extends ciphertext_message_1.CiphertextMessage {
|
|
|
27
31
|
else {
|
|
28
32
|
const version = (((this.CURRENT_VERSION << 4) | this.CURRENT_VERSION) & 0xff) % 256
|
|
29
33
|
const ciphertextBuffer = Buffer.from(ciphertext)
|
|
30
|
-
const message =
|
|
34
|
+
const message = proto.SenderKeyMessage.encode(proto.SenderKeyMessage.create({
|
|
31
35
|
id: keyId,
|
|
32
36
|
iteration: iteration,
|
|
33
37
|
ciphertext: ciphertextBuffer
|
|
@@ -53,12 +57,12 @@ class SenderKeyMessage extends ciphertext_message_1.CiphertextMessage {
|
|
|
53
57
|
verifySignature(signatureKey) {
|
|
54
58
|
const part1 = this.serialized.slice(0, this.serialized.length - this.SIGNATURE_LENGTH)
|
|
55
59
|
const part2 = this.serialized.slice(-1 * this.SIGNATURE_LENGTH)
|
|
56
|
-
const res =
|
|
60
|
+
const res = verifySignature(signatureKey, part1, part2)
|
|
57
61
|
if (!res)
|
|
58
62
|
throw new Error('Invalid signature!')
|
|
59
63
|
}
|
|
60
64
|
getSignature(signatureKey, serialized) {
|
|
61
|
-
return Buffer.from(
|
|
65
|
+
return Buffer.from(calculateSignature(signatureKey, serialized))
|
|
62
66
|
}
|
|
63
67
|
serialize() {
|
|
64
68
|
return this.serialized
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true })
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
const
|
|
5
|
+
const { BufferJSON } = require("../../Utils/generics")
|
|
6
|
+
const { SenderKeyState } = require("./sender-key-state")
|
|
7
7
|
|
|
8
8
|
class SenderKeyRecord {
|
|
9
9
|
constructor(serialized) {
|
|
@@ -11,7 +11,7 @@ class SenderKeyRecord {
|
|
|
11
11
|
this.senderKeyStates = []
|
|
12
12
|
if (serialized) {
|
|
13
13
|
for (const structure of serialized) {
|
|
14
|
-
this.senderKeyStates.push(new
|
|
14
|
+
this.senderKeyStates.push(new SenderKeyState(null, null, null, null, null, null, structure))
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
}
|
|
@@ -25,14 +25,14 @@ class SenderKeyRecord {
|
|
|
25
25
|
return this.senderKeyStates.find(state => state.getKeyId() === keyId)
|
|
26
26
|
}
|
|
27
27
|
addSenderKeyState(id, iteration, chainKey, signatureKey) {
|
|
28
|
-
this.senderKeyStates.push(new
|
|
28
|
+
this.senderKeyStates.push(new SenderKeyState(id, iteration, chainKey, null, signatureKey))
|
|
29
29
|
if (this.senderKeyStates.length > this.MAX_STATES) {
|
|
30
30
|
this.senderKeyStates.shift()
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
setSenderKeyState(id, iteration, chainKey, keyPair) {
|
|
34
34
|
this.senderKeyStates.length = 0
|
|
35
|
-
this.senderKeyStates.push(new
|
|
35
|
+
this.senderKeyStates.push(new SenderKeyState(id, iteration, chainKey, keyPair))
|
|
36
36
|
}
|
|
37
37
|
serialize() {
|
|
38
38
|
return this.senderKeyStates.map(state => state.getStructure())
|
|
@@ -40,11 +40,11 @@ class SenderKeyRecord {
|
|
|
40
40
|
static deserialize(data) {
|
|
41
41
|
let parsed
|
|
42
42
|
if (typeof data === 'string') {
|
|
43
|
-
parsed = JSON.parse(data,
|
|
43
|
+
parsed = JSON.parse(data, BufferJSON.reviver)
|
|
44
44
|
}
|
|
45
45
|
else if (data instanceof Uint8Array) {
|
|
46
46
|
const str = Buffer.from(data).toString('utf-8')
|
|
47
|
-
parsed = JSON.parse(str,
|
|
47
|
+
parsed = JSON.parse(str, BufferJSON.reviver)
|
|
48
48
|
}
|
|
49
49
|
else {
|
|
50
50
|
parsed = data
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true })
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
const
|
|
5
|
+
const { SenderChainKey } = require("./sender-chain-key")
|
|
6
|
+
const { SenderMessageKey } = require("./sender-message-key")
|
|
7
7
|
|
|
8
8
|
class SenderKeyState {
|
|
9
9
|
constructor(id, iteration, chainKey, signatureKeyPair, signatureKeyPublic, signatureKeyPrivate, senderKeyStateStructure) {
|
|
@@ -56,7 +56,7 @@ class SenderKeyState {
|
|
|
56
56
|
return this.senderKeyStateStructure.senderKeyId
|
|
57
57
|
}
|
|
58
58
|
getSenderChainKey() {
|
|
59
|
-
return new
|
|
59
|
+
return new SenderChainKey(this.senderKeyStateStructure.senderChainKey.iteration, this.senderKeyStateStructure.senderChainKey.seed)
|
|
60
60
|
}
|
|
61
61
|
setSenderChainKey(chainKey) {
|
|
62
62
|
this.senderKeyStateStructure.senderChainKey = {
|
|
@@ -133,7 +133,7 @@ class SenderKeyState {
|
|
|
133
133
|
if (index !== -1) {
|
|
134
134
|
const messageKey = this.senderKeyStateStructure.senderMessageKeys[index]
|
|
135
135
|
this.senderKeyStateStructure.senderMessageKeys.splice(index, 1)
|
|
136
|
-
return new
|
|
136
|
+
return new SenderMessageKey(messageKey.iteration, messageKey.seed)
|
|
137
137
|
}
|
|
138
138
|
return null
|
|
139
139
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict"
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true })
|
|
3
3
|
|
|
4
|
-
const
|
|
4
|
+
const { deriveSecrets } = require("@itsukichan/libsignal-node/src/crypto")
|
|
5
5
|
|
|
6
6
|
class SenderMessageKey {
|
|
7
7
|
constructor(iteration, seed) {
|
|
8
|
-
const derivative =
|
|
8
|
+
const derivative = deriveSecrets(seed, Buffer.alloc(32), Buffer.from('WhisperGroup'))
|
|
9
9
|
const keys = new Uint8Array(32)
|
|
10
10
|
keys.set(new Uint8Array(derivative[0].slice(16)))
|
|
11
11
|
keys.set(new Uint8Array(derivative[1].slice(0, 16)), 16)
|
package/lib/Signal/libsignal.js
CHANGED
|
@@ -1,53 +1,29 @@
|
|
|
1
1
|
"use strict"
|
|
2
2
|
|
|
3
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
-
if (k2 === undefined) k2 = k
|
|
5
|
-
var desc = Object.getOwnPropertyDescriptor(m, k)
|
|
6
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = { enumerable: true, get: function() { return m[k] } }
|
|
8
|
-
}
|
|
9
|
-
Object.defineProperty(o, k2, desc)
|
|
10
|
-
}) : (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k
|
|
12
|
-
o[k2] = m[k]
|
|
13
|
-
}))
|
|
14
|
-
|
|
15
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
16
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v })
|
|
17
|
-
}) : function(o, v) {
|
|
18
|
-
o["default"] = v
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
22
|
-
var ownKeys = function(o) {
|
|
23
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
24
|
-
var ar = []
|
|
25
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k
|
|
26
|
-
return ar
|
|
27
|
-
}
|
|
28
|
-
return ownKeys(o)
|
|
29
|
-
}
|
|
30
|
-
return function (mod) {
|
|
31
|
-
if (mod && mod.__esModule) return mod
|
|
32
|
-
var result = {}
|
|
33
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i])
|
|
34
|
-
__setModuleDefault(result, mod)
|
|
35
|
-
return result
|
|
36
|
-
}
|
|
37
|
-
})()
|
|
38
|
-
|
|
39
3
|
Object.defineProperty(exports, "__esModule", { value: true })
|
|
40
4
|
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const
|
|
5
|
+
const {
|
|
6
|
+
SessionCipher,
|
|
7
|
+
SessionBuilder,
|
|
8
|
+
SessionRecord,
|
|
9
|
+
ProtocolAddress
|
|
10
|
+
} = require("@itsukichan/libsignal-node")
|
|
11
|
+
const { generateSignalPubKey } = require("../Utils")
|
|
12
|
+
const {
|
|
13
|
+
jidDecode,
|
|
14
|
+
transferDevice
|
|
15
|
+
} = require("../WABinary")
|
|
16
|
+
const { SenderKeyName } = require("./Group/sender-key-name")
|
|
17
|
+
const { SenderKeyRecord } = require("./Group/sender-key-record")
|
|
18
|
+
const {
|
|
19
|
+
GroupCipher,
|
|
20
|
+
GroupSessionBuilder,
|
|
21
|
+
SenderKeyDistributionMessage
|
|
22
|
+
} = require("./Group")
|
|
23
|
+
const { LIDMappingStore } = require("./lid-mapping")
|
|
48
24
|
|
|
49
25
|
function makeLibSignalRepository(auth, onWhatsAppFunc, logger) {
|
|
50
|
-
const lidMapping = new
|
|
26
|
+
const lidMapping = new LIDMappingStore(auth.keys, onWhatsAppFunc, logger)
|
|
51
27
|
const storage = signalStorage(auth, lidMapping)
|
|
52
28
|
const parsedKeys = auth.keys
|
|
53
29
|
|
|
@@ -63,35 +39,35 @@ function makeLibSignalRepository(auth, onWhatsAppFunc, logger) {
|
|
|
63
39
|
const repository = {
|
|
64
40
|
decryptGroupMessage({ group, authorJid, msg }) {
|
|
65
41
|
const senderName = jidToSignalSenderKeyName(group, authorJid)
|
|
66
|
-
const cipher = new
|
|
42
|
+
const cipher = new GroupCipher(storage, senderName)
|
|
67
43
|
// Use transaction to ensure atomicity
|
|
68
44
|
return parsedKeys.transaction(async () => {
|
|
69
45
|
return cipher.decrypt(msg)
|
|
70
46
|
}, group)
|
|
71
47
|
},
|
|
72
48
|
async processSenderKeyDistributionMessage({ item, authorJid }) {
|
|
73
|
-
const builder = new
|
|
49
|
+
const builder = new GroupSessionBuilder(storage)
|
|
74
50
|
if (!item.groupId) {
|
|
75
51
|
throw new Error('Group ID is required for sender key distribution message')
|
|
76
52
|
}
|
|
77
53
|
const senderName = jidToSignalSenderKeyName(item.groupId, authorJid)
|
|
78
|
-
const senderMsg = new
|
|
54
|
+
const senderMsg = new SenderKeyDistributionMessage(null, null, null, null, item.axolotlSenderKeyDistributionMessage)
|
|
79
55
|
const senderNameStr = senderName.toString()
|
|
80
56
|
const { [senderNameStr]: senderKey } = await auth.keys.get('sender-key', [senderNameStr])
|
|
81
57
|
if (!senderKey) {
|
|
82
|
-
await storage.storeSenderKey(senderName, new
|
|
58
|
+
await storage.storeSenderKey(senderName, new SenderKeyRecord())
|
|
83
59
|
}
|
|
84
60
|
return parsedKeys.transaction(async () => {
|
|
85
61
|
const { [senderNameStr]: senderKey } = await auth.keys.get('sender-key', [senderNameStr])
|
|
86
62
|
if (!senderKey) {
|
|
87
|
-
await storage.storeSenderKey(senderName, new
|
|
63
|
+
await storage.storeSenderKey(senderName, new SenderKeyRecord())
|
|
88
64
|
}
|
|
89
65
|
await builder.process(senderName, senderMsg)
|
|
90
66
|
}, item.groupId)
|
|
91
67
|
},
|
|
92
68
|
async decryptMessage({ jid, type, ciphertext }) {
|
|
93
69
|
const addr = jidToSignalProtocolAddress(jid)
|
|
94
|
-
const session = new
|
|
70
|
+
const session = new SessionCipher(storage, addr)
|
|
95
71
|
async function doDecrypt() {
|
|
96
72
|
let result
|
|
97
73
|
switch (type) {
|
|
@@ -141,7 +117,7 @@ function makeLibSignalRepository(auth, onWhatsAppFunc, logger) {
|
|
|
141
117
|
}
|
|
142
118
|
}
|
|
143
119
|
const addr = jidToSignalProtocolAddress(encryptionJid)
|
|
144
|
-
const cipher = new
|
|
120
|
+
const cipher = new SessionCipher(storage, addr)
|
|
145
121
|
// Use transaction to ensure atomicity
|
|
146
122
|
return parsedKeys.transaction(async () => {
|
|
147
123
|
const { type: sigType, body } = await cipher.encrypt(data)
|
|
@@ -151,15 +127,15 @@ function makeLibSignalRepository(auth, onWhatsAppFunc, logger) {
|
|
|
151
127
|
},
|
|
152
128
|
async encryptGroupMessage({ group, meId, data }) {
|
|
153
129
|
const senderName = jidToSignalSenderKeyName(group, meId)
|
|
154
|
-
const builder = new
|
|
130
|
+
const builder = new GroupSessionBuilder(storage)
|
|
155
131
|
const senderNameStr = senderName.toString()
|
|
156
132
|
return parsedKeys.transaction(async () => {
|
|
157
133
|
const { [senderNameStr]: senderKey } = await auth.keys.get('sender-key', [senderNameStr])
|
|
158
134
|
if (!senderKey) {
|
|
159
|
-
await storage.storeSenderKey(senderName, new
|
|
135
|
+
await storage.storeSenderKey(senderName, new SenderKeyRecord())
|
|
160
136
|
}
|
|
161
137
|
const senderKeyDistributionMessage = await builder.create(senderName)
|
|
162
|
-
const session = new
|
|
138
|
+
const session = new GroupCipher(storage, senderName)
|
|
163
139
|
const ciphertext = await session.encrypt(data)
|
|
164
140
|
return {
|
|
165
141
|
ciphertext,
|
|
@@ -168,7 +144,7 @@ function makeLibSignalRepository(auth, onWhatsAppFunc, logger) {
|
|
|
168
144
|
}, group)
|
|
169
145
|
},
|
|
170
146
|
async injectE2ESession({ jid, session }) {
|
|
171
|
-
const cipher = new
|
|
147
|
+
const cipher = new SessionBuilder(storage, jidToSignalProtocolAddress(jid))
|
|
172
148
|
return parsedKeys.transaction(async () => {
|
|
173
149
|
await cipher.initOutgoing(session)
|
|
174
150
|
}, jid)
|
|
@@ -224,7 +200,7 @@ function makeLibSignalRepository(auth, onWhatsAppFunc, logger) {
|
|
|
224
200
|
return parsedKeys.transaction(async () => {
|
|
225
201
|
// 1. Batch store all LID mappings
|
|
226
202
|
const mappings = validJids.map(jid => ({
|
|
227
|
-
lid:
|
|
203
|
+
lid: transferDevice(jid, toJid),
|
|
228
204
|
pn: jid
|
|
229
205
|
}))
|
|
230
206
|
|
|
@@ -232,9 +208,9 @@ function makeLibSignalRepository(auth, onWhatsAppFunc, logger) {
|
|
|
232
208
|
|
|
233
209
|
// 2. Prepare migration operations
|
|
234
210
|
const migrationOps = validJids.map(jid => {
|
|
235
|
-
const lidWithDevice =
|
|
236
|
-
const fromDecoded =
|
|
237
|
-
const toDecoded =
|
|
211
|
+
const lidWithDevice = transferDevice(jid, toJid)
|
|
212
|
+
const fromDecoded = jidDecode(jid)
|
|
213
|
+
const toDecoded = jidDecode(lidWithDevice)
|
|
238
214
|
|
|
239
215
|
return {
|
|
240
216
|
fromJid: jid,
|
|
@@ -266,7 +242,7 @@ function makeLibSignalRepository(auth, onWhatsAppFunc, logger) {
|
|
|
266
242
|
if (fromSession?.haveOpenSession()) {
|
|
267
243
|
// Copy session to LID address
|
|
268
244
|
const sessionBytes = fromSession.serialize()
|
|
269
|
-
const copiedSession =
|
|
245
|
+
const copiedSession = SessionRecord.deserialize(sessionBytes)
|
|
270
246
|
await storage.storeSession(op.toAddr.toString(), copiedSession)
|
|
271
247
|
|
|
272
248
|
// Delete PN session
|
|
@@ -275,7 +251,7 @@ function makeLibSignalRepository(auth, onWhatsAppFunc, logger) {
|
|
|
275
251
|
}))
|
|
276
252
|
|
|
277
253
|
return { migrated: opsToMigrate.length, skipped: skippedCount, total: validJids.length }
|
|
278
|
-
}, `migrate-${validJids.length}-sessions-${
|
|
254
|
+
}, `migrate-${validJids.length}-sessions-${jidDecode(toJid)?.user}`)
|
|
279
255
|
},
|
|
280
256
|
async encryptMessageWithWire({ encryptionJid, wireJid, data }) {
|
|
281
257
|
const result = await repository.encryptMessage({ jid: encryptionJid, data })
|
|
@@ -286,7 +262,7 @@ function makeLibSignalRepository(auth, onWhatsAppFunc, logger) {
|
|
|
286
262
|
}
|
|
287
263
|
|
|
288
264
|
const jidToSignalProtocolAddress = (jid) => {
|
|
289
|
-
const decoded =
|
|
265
|
+
const decoded = jidDecode(jid)
|
|
290
266
|
const { user, device, server } = decoded
|
|
291
267
|
|
|
292
268
|
if (!user) {
|
|
@@ -297,11 +273,11 @@ const jidToSignalProtocolAddress = (jid) => {
|
|
|
297
273
|
const signalUser = server === 'lid' ? `${user}_1` : user
|
|
298
274
|
const finalDevice = device || 0
|
|
299
275
|
|
|
300
|
-
return new
|
|
276
|
+
return new ProtocolAddress(signalUser, finalDevice)
|
|
301
277
|
}
|
|
302
278
|
|
|
303
279
|
const jidToSignalSenderKeyName = (group, user) => {
|
|
304
|
-
return new
|
|
280
|
+
return new SenderKeyName(group, jidToSignalProtocolAddress(user))
|
|
305
281
|
}
|
|
306
282
|
|
|
307
283
|
function signalStorage({ creds, keys }, lidMapping) {
|
|
@@ -329,7 +305,7 @@ function signalStorage({ creds, keys }, lidMapping) {
|
|
|
329
305
|
}
|
|
330
306
|
const { [actualId]: sess } = await keys.get('session', [actualId])
|
|
331
307
|
if (sess) {
|
|
332
|
-
return
|
|
308
|
+
return SessionRecord.deserialize(sess)
|
|
333
309
|
}
|
|
334
310
|
}
|
|
335
311
|
catch (e) {
|
|
@@ -337,7 +313,7 @@ function signalStorage({ creds, keys }, lidMapping) {
|
|
|
337
313
|
}
|
|
338
314
|
return null
|
|
339
315
|
},
|
|
340
|
-
// TODO: Replace with
|
|
316
|
+
// TODO: Replace with SessionRecord when type exports are added to libsignal
|
|
341
317
|
storeSession: async (id, session) => {
|
|
342
318
|
await keys.set({ session: { [id]: session.serialize() } })
|
|
343
319
|
},
|
|
@@ -366,9 +342,9 @@ function signalStorage({ creds, keys }, lidMapping) {
|
|
|
366
342
|
const keyId = senderKeyName.toString()
|
|
367
343
|
const { [keyId]: key } = await keys.get('sender-key', [keyId])
|
|
368
344
|
if (key) {
|
|
369
|
-
return
|
|
345
|
+
return SenderKeyRecord.deserialize(key)
|
|
370
346
|
}
|
|
371
|
-
return new
|
|
347
|
+
return new SenderKeyRecord()
|
|
372
348
|
},
|
|
373
349
|
storeSenderKey: async (senderKeyName, key) => {
|
|
374
350
|
const keyId = senderKeyName.toString()
|
|
@@ -380,7 +356,7 @@ function signalStorage({ creds, keys }, lidMapping) {
|
|
|
380
356
|
const { signedIdentityKey } = creds
|
|
381
357
|
return {
|
|
382
358
|
privKey: Buffer.from(signedIdentityKey.private),
|
|
383
|
-
pubKey: Buffer.from(
|
|
359
|
+
pubKey: Buffer.from(generateSignalPubKey(signedIdentityKey.public))
|
|
384
360
|
}
|
|
385
361
|
}
|
|
386
362
|
}
|
|
@@ -2,12 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true })
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
const
|
|
5
|
+
const { LRUCache } = require("lru-cache")
|
|
6
|
+
const {
|
|
7
|
+
jidDecode,
|
|
8
|
+
isJidUser,
|
|
9
|
+
isLidUser
|
|
10
|
+
} = require("../WABinary")
|
|
7
11
|
|
|
8
12
|
class LIDMappingStore {
|
|
9
13
|
constructor(keys, onWhatsAppFunc, logger) {
|
|
10
|
-
this.mappingCache = new
|
|
14
|
+
this.mappingCache = new LRUCache({
|
|
11
15
|
ttl: 7 * 24 * 60 * 60 * 1000, // 7 days
|
|
12
16
|
ttlAutopurge: true,
|
|
13
17
|
updateAgeOnGet: true
|
|
@@ -25,13 +29,13 @@ class LIDMappingStore {
|
|
|
25
29
|
const logger = this.logger
|
|
26
30
|
|
|
27
31
|
for (const { lid, pn } of pairs) {
|
|
28
|
-
if (!((
|
|
32
|
+
if (!((isLidUser(lid) && isJidUser(pn)) || (isJidUser(lid) && isLidUser(pn)))) {
|
|
29
33
|
logger.warn(`Invalid LID-PN mapping: ${lid}, ${pn}`)
|
|
30
34
|
continue
|
|
31
35
|
}
|
|
32
36
|
|
|
33
|
-
const lidDecoded =
|
|
34
|
-
const pnDecoded =
|
|
37
|
+
const lidDecoded = jidDecode(lid)
|
|
38
|
+
const pnDecoded = jidDecode(pn)
|
|
35
39
|
|
|
36
40
|
if (!lidDecoded || !pnDecoded) return
|
|
37
41
|
|
|
@@ -83,10 +87,10 @@ class LIDMappingStore {
|
|
|
83
87
|
* Get LID for PN - Returns device-specific LID based on user mapping
|
|
84
88
|
*/
|
|
85
89
|
async getLIDForPN(pn) {
|
|
86
|
-
if (!
|
|
90
|
+
if (!isJidUser(pn)) return null
|
|
87
91
|
|
|
88
92
|
const logger = this.logger
|
|
89
|
-
const decoded =
|
|
93
|
+
const decoded = jidDecode(pn)
|
|
90
94
|
|
|
91
95
|
if (!decoded) return null
|
|
92
96
|
|
|
@@ -113,7 +117,7 @@ class LIDMappingStore {
|
|
|
113
117
|
const { exists, lid } = (await this.onWhatsAppFunc?.(pn))?.[0] // this function already adds LIDs to mapping
|
|
114
118
|
|
|
115
119
|
if (exists && lid) {
|
|
116
|
-
lidUser =
|
|
120
|
+
lidUser = jidDecode(lid)?.user
|
|
117
121
|
|
|
118
122
|
if (lidUser) {
|
|
119
123
|
// Cache the USync result
|
|
@@ -144,10 +148,10 @@ class LIDMappingStore {
|
|
|
144
148
|
* Get PN for LID - USER LEVEL with device construction
|
|
145
149
|
*/
|
|
146
150
|
async getPNForLID(lid) {
|
|
147
|
-
if (!
|
|
151
|
+
if (!isLidUser(lid)) return null
|
|
148
152
|
|
|
149
153
|
const logger = this.logger
|
|
150
|
-
const decoded =
|
|
154
|
+
const decoded = jidDecode(lid)
|
|
151
155
|
|
|
152
156
|
if (!decoded) return null
|
|
153
157
|
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true })
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const { EventEmitter } = require("events")
|
|
6
6
|
|
|
7
|
-
class AbstractSocketClient extends
|
|
7
|
+
class AbstractSocketClient extends EventEmitter {
|
|
8
8
|
constructor(url, config) {
|
|
9
9
|
super()
|
|
10
10
|
this.url = url
|
|
@@ -1,38 +1,40 @@
|
|
|
1
1
|
"use strict"
|
|
2
2
|
|
|
3
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
-
return (mod && mod.__esModule) ? mod : { "default": mod }
|
|
5
|
-
}
|
|
6
|
-
|
|
7
3
|
Object.defineProperty(exports, "__esModule", { value: true })
|
|
8
4
|
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
const {
|
|
6
|
+
OPEN,
|
|
7
|
+
CLOSED,
|
|
8
|
+
CLOSING,
|
|
9
|
+
CONNECTING,
|
|
10
|
+
WebSocket
|
|
11
|
+
} = require("ws")
|
|
12
|
+
const { DEFAULT_ORIGIN } = require("../../Defaults/constants")
|
|
13
|
+
const { AbstractSocketClient } = require("./types")
|
|
12
14
|
|
|
13
|
-
class WebSocketClient extends
|
|
15
|
+
class WebSocketClient extends AbstractSocketClient {
|
|
14
16
|
constructor() {
|
|
15
17
|
super(...arguments)
|
|
16
18
|
this.socket = null
|
|
17
19
|
}
|
|
18
20
|
get isOpen() {
|
|
19
|
-
return this.socket?.readyState ===
|
|
21
|
+
return this.socket?.readyState === OPEN
|
|
20
22
|
}
|
|
21
23
|
get isClosed() {
|
|
22
|
-
return this.socket?.readyState ===
|
|
24
|
+
return this.socket?.readyState === CLOSED
|
|
23
25
|
}
|
|
24
26
|
get isClosing() {
|
|
25
|
-
this.socket?.readyState ===
|
|
27
|
+
this.socket?.readyState === CLOSING
|
|
26
28
|
}
|
|
27
29
|
get isConnecting() {
|
|
28
|
-
this.socket?.readyState ===
|
|
30
|
+
this.socket?.readyState === CONNECTING
|
|
29
31
|
}
|
|
30
32
|
async connect() {
|
|
31
33
|
if (this.socket) {
|
|
32
34
|
return
|
|
33
35
|
}
|
|
34
|
-
this.socket = new
|
|
35
|
-
origin:
|
|
36
|
+
this.socket = new WebSocket(this.url, {
|
|
37
|
+
origin: DEFAULT_ORIGIN,
|
|
36
38
|
headers: this.config.options?.headers,
|
|
37
39
|
handshakeTimeout: this.config.connectTimeoutMs,
|
|
38
40
|
timeout: this.config.connectTimeoutMs,
|