@hansaka02/baileys 7.3.2 → 7.3.6
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/baileys-version.json +2 -2
- package/lib/Defaults/connection.js +51 -0
- package/lib/Defaults/constants.js +74 -0
- package/lib/Defaults/history.js +19 -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 +5 -18
- package/lib/Signal/Group/sender-key-distribution-message.js +7 -7
- package/lib/Signal/Group/sender-key-message.js +12 -8
- package/lib/Signal/Group/sender-key-record.js +7 -16
- package/lib/Signal/Group/sender-key-state.js +15 -61
- package/lib/Signal/Group/sender-message-key.js +2 -2
- package/lib/Signal/libsignal.js +237 -177
- package/lib/Signal/lid-mapping.js +128 -71
- package/lib/Socket/Client/types.js +2 -2
- package/lib/Socket/Client/websocket.js +25 -16
- package/lib/Socket/business.js +46 -33
- package/lib/Socket/chats.js +286 -170
- package/lib/Socket/community.js +215 -77
- package/lib/Socket/groups.js +77 -61
- package/lib/Socket/index.js +4 -4
- package/lib/Socket/messages-recv.js +629 -457
- package/lib/Socket/messages-send.js +645 -656
- package/lib/Socket/mex.js +61 -0
- package/lib/Socket/newsletter.js +166 -245
- package/lib/Socket/socket.js +396 -170
- 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/Newsletter.js +32 -25
- package/lib/Types/State.js +4 -4
- package/lib/Types/index.js +28 -12
- package/lib/Utils/auth-utils.js +212 -375
- package/lib/Utils/baileys-event-stream.js +68 -69
- package/lib/Utils/browser-utils.js +43 -0
- package/lib/Utils/business.js +63 -53
- package/lib/Utils/chat-utils.js +241 -106
- package/lib/Utils/crypto.js +25 -45
- package/lib/Utils/decode-wa-message.js +361 -311
- package/lib/Utils/event-buffer.js +97 -42
- package/lib/Utils/generics.js +90 -207
- package/lib/Utils/history.js +29 -27
- package/lib/Utils/index.js +28 -14
- package/lib/Utils/link-preview.js +24 -62
- package/lib/Utils/logger.js +5 -5
- package/lib/Utils/lt-hash.js +29 -23
- package/lib/Utils/make-mutex.js +26 -28
- package/lib/Utils/message-retry-manager.js +55 -7
- package/lib/Utils/messages-media.js +434 -247
- package/lib/Utils/messages.js +963 -917
- package/lib/Utils/noise-handler.js +60 -20
- package/lib/Utils/pre-key-manager.js +126 -0
- package/lib/Utils/process-message.js +216 -141
- package/lib/Utils/signal.js +75 -37
- package/lib/Utils/use-multi-file-auth-state.js +18 -22
- package/lib/Utils/validate-connection.js +96 -66
- package/lib/WABinary/constants.js +1268 -1268
- package/lib/WABinary/decode.js +62 -34
- package/lib/WABinary/encode.js +57 -36
- package/lib/WABinary/generic-utils.js +4 -4
- package/lib/WABinary/index.js +27 -11
- package/lib/WABinary/jid-utils.js +58 -11
- package/lib/WAM/constants.js +19064 -11563
- package/lib/WAM/encode.js +71 -14
- 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 +51 -28
- package/lib/WAUSync/index.js +27 -11
- package/lib/index.js +60 -31
- package/package.json +12 -17
- 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/Socket/usync.js +0 -83
- 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
|
@@ -1,57 +1,24 @@
|
|
|
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
|
-
|
|
5
|
+
const {
|
|
6
|
+
randomInt,
|
|
7
|
+
randomBytes
|
|
8
|
+
} = require("crypto")
|
|
9
|
+
const { generateKeyPair } = require("@itsukichan/libsignal-node/src/curve")
|
|
43
10
|
|
|
44
11
|
function generateSenderKey() {
|
|
45
|
-
return
|
|
12
|
+
return randomBytes(32)
|
|
46
13
|
}
|
|
47
14
|
|
|
48
15
|
function generateSenderKeyId() {
|
|
49
|
-
return
|
|
16
|
+
return randomInt(2147483647)
|
|
50
17
|
}
|
|
51
18
|
|
|
52
19
|
function generateSenderSigningKey(key) {
|
|
53
20
|
if (!key) {
|
|
54
|
-
key =
|
|
21
|
+
key = generateKeyPair()
|
|
55
22
|
}
|
|
56
23
|
return {
|
|
57
24
|
public: Buffer.from(key.pubKey),
|
|
@@ -2,34 +2,21 @@
|
|
|
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) {
|
|
10
10
|
this.MESSAGE_KEY_SEED = Buffer.from([0x01])
|
|
11
11
|
this.CHAIN_KEY_SEED = Buffer.from([0x02])
|
|
12
12
|
this.iteration = iteration
|
|
13
|
-
|
|
14
|
-
// backported from @MartinSchere's PR
|
|
15
|
-
this.chainKey = chainKey
|
|
16
|
-
}
|
|
17
|
-
else if (chainKey instanceof Uint8Array) {
|
|
18
|
-
this.chainKey = Buffer.from(chainKey)
|
|
19
|
-
}
|
|
20
|
-
else if (chainKey && typeof chainKey === 'object') {
|
|
21
|
-
// backported from @MartinSchere (#1741)
|
|
22
|
-
this.chainKey = Buffer.from(Object.values(chainKey)) // temp fix // backported from @MartinSchere (#1741)
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
this.chainKey = Buffer.alloc(0)
|
|
26
|
-
}
|
|
13
|
+
this.chainKey = Buffer.from(chainKey)
|
|
27
14
|
}
|
|
28
15
|
getIteration() {
|
|
29
16
|
return this.iteration
|
|
30
17
|
}
|
|
31
18
|
getSenderMessageKey() {
|
|
32
|
-
return new
|
|
19
|
+
return new SenderMessageKey(this.iteration, this.getDerivative(this.MESSAGE_KEY_SEED, this.chainKey))
|
|
33
20
|
}
|
|
34
21
|
getNext() {
|
|
35
22
|
return new SenderChainKey(this.iteration + 1, this.getDerivative(this.CHAIN_KEY_SEED, this.chainKey))
|
|
@@ -38,7 +25,7 @@ class SenderChainKey {
|
|
|
38
25
|
return this.chainKey
|
|
39
26
|
}
|
|
40
27
|
getDerivative(seed, key) {
|
|
41
|
-
return
|
|
28
|
+
return calculateMAC(key, seed)
|
|
42
29
|
}
|
|
43
30
|
}
|
|
44
31
|
|
|
@@ -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,
|
|
@@ -56,10 +56,10 @@ class SenderKeyDistributionMessage extends ciphertext_message_1.CiphertextMessag
|
|
|
56
56
|
return this.iteration
|
|
57
57
|
}
|
|
58
58
|
getChainKey() {
|
|
59
|
-
return
|
|
59
|
+
return this.chainKey
|
|
60
60
|
}
|
|
61
61
|
getSignatureKey() {
|
|
62
|
-
return
|
|
62
|
+
return this.signatureKey
|
|
63
63
|
}
|
|
64
64
|
getId() {
|
|
65
65
|
return this.id
|
|
@@ -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,30 +25,21 @@ 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())
|
|
39
39
|
}
|
|
40
40
|
static deserialize(data) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
parsed = JSON.parse(data, generics_1.BufferJSON.reviver)
|
|
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
|
-
}
|
|
41
|
+
const str = Buffer.from(data).toString('utf-8')
|
|
42
|
+
const parsed = JSON.parse(str, BufferJSON.reviver)
|
|
52
43
|
return new SenderKeyRecord(parsed)
|
|
53
44
|
}
|
|
54
45
|
}
|
|
@@ -2,23 +2,13 @@
|
|
|
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) {
|
|
10
10
|
this.MAX_MESSAGE_KEYS = 2000
|
|
11
11
|
|
|
12
|
-
const toBuffer = (val) => {
|
|
13
|
-
if (!val)
|
|
14
|
-
return Buffer.alloc(0)
|
|
15
|
-
if (typeof val === 'string')
|
|
16
|
-
return Buffer.from(val, 'base64')
|
|
17
|
-
if (val instanceof Uint8Array || Array.isArray(val))
|
|
18
|
-
return Buffer.from(val)
|
|
19
|
-
return Buffer.alloc(0)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
12
|
if (senderKeyStateStructure) {
|
|
23
13
|
this.senderKeyStateStructure = {
|
|
24
14
|
...senderKeyStateStructure,
|
|
@@ -32,22 +22,17 @@ class SenderKeyState {
|
|
|
32
22
|
signatureKeyPublic = signatureKeyPair.public
|
|
33
23
|
signatureKeyPrivate = signatureKeyPair.private
|
|
34
24
|
}
|
|
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
|
|
45
|
-
}
|
|
46
25
|
|
|
47
26
|
this.senderKeyStateStructure = {
|
|
48
27
|
senderKeyId: id || 0,
|
|
49
|
-
senderChainKey:
|
|
50
|
-
|
|
28
|
+
senderChainKey: {
|
|
29
|
+
iteration: iteration || 0,
|
|
30
|
+
seed: Buffer.from(chainKey || [])
|
|
31
|
+
},
|
|
32
|
+
senderSigningKey: {
|
|
33
|
+
public: Buffer.from(signatureKeyPublic || []),
|
|
34
|
+
private: Buffer.from(signatureKeyPrivate || [])
|
|
35
|
+
},
|
|
51
36
|
senderMessageKeys: []
|
|
52
37
|
}
|
|
53
38
|
}
|
|
@@ -56,7 +41,7 @@ class SenderKeyState {
|
|
|
56
41
|
return this.senderKeyStateStructure.senderKeyId
|
|
57
42
|
}
|
|
58
43
|
getSenderChainKey() {
|
|
59
|
-
return new
|
|
44
|
+
return new SenderChainKey(this.senderKeyStateStructure.senderChainKey.iteration, this.senderKeyStateStructure.senderChainKey.seed)
|
|
60
45
|
}
|
|
61
46
|
setSenderChainKey(chainKey) {
|
|
62
47
|
this.senderKeyStateStructure.senderChainKey = {
|
|
@@ -65,25 +50,7 @@ class SenderKeyState {
|
|
|
65
50
|
}
|
|
66
51
|
}
|
|
67
52
|
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
|
|
53
|
+
const publicKey = Buffer.from(this.senderKeyStateStructure.senderSigningKey.public)
|
|
87
54
|
|
|
88
55
|
if (publicKey.length === 32) {
|
|
89
56
|
const fixed = Buffer.alloc(33)
|
|
@@ -98,21 +65,6 @@ class SenderKeyState {
|
|
|
98
65
|
}
|
|
99
66
|
getSigningKeyPrivate() {
|
|
100
67
|
const privateKey = this.senderKeyStateStructure.senderSigningKey.private
|
|
101
|
-
if (!privateKey) {
|
|
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
68
|
return Buffer.from(privateKey || [])
|
|
117
69
|
}
|
|
118
70
|
hasSenderMessageKey(iteration) {
|
|
@@ -130,11 +82,13 @@ class SenderKeyState {
|
|
|
130
82
|
}
|
|
131
83
|
removeSenderMessageKey(iteration) {
|
|
132
84
|
const index = this.senderKeyStateStructure.senderMessageKeys.findIndex(key => key.iteration === iteration)
|
|
85
|
+
|
|
133
86
|
if (index !== -1) {
|
|
134
87
|
const messageKey = this.senderKeyStateStructure.senderMessageKeys[index]
|
|
135
88
|
this.senderKeyStateStructure.senderMessageKeys.splice(index, 1)
|
|
136
|
-
return new
|
|
89
|
+
return new SenderMessageKey(messageKey.iteration, messageKey.seed)
|
|
137
90
|
}
|
|
91
|
+
|
|
138
92
|
return null
|
|
139
93
|
}
|
|
140
94
|
getStructure() {
|
|
@@ -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)
|