@neelegirl/baileys 1.5.3 → 1.5.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.md +16 -195
- package/index.js +38 -0
- package/package.json +16 -96
- package/LICENSE +0 -21
- package/WAProto/WAProto.proto +0 -5308
- package/WAProto/index.d.ts +0 -61295
- package/WAProto/index.js +0 -189754
- package/lib/Defaults/baileys-version.json +0 -3
- package/lib/Defaults/index.d.ts +0 -78
- package/lib/Defaults/index.js +0 -149
- package/lib/Defaults/phonenumber-mcc.json +0 -223
- package/lib/Signal/WASignalGroup/GroupProtocol.js +0 -1909
- package/lib/Signal/WASignalGroup/ciphertext-message.d.ts +0 -9
- package/lib/Signal/WASignalGroup/ciphertext-message.js +0 -19
- package/lib/Signal/WASignalGroup/ciphertext_message.js +0 -16
- package/lib/Signal/WASignalGroup/generate-proto.sh +0 -1
- package/lib/Signal/WASignalGroup/group-session-builder.d.ts +0 -17
- package/lib/Signal/WASignalGroup/group-session-builder.js +0 -72
- package/lib/Signal/WASignalGroup/group.proto +0 -42
- package/lib/Signal/WASignalGroup/group_cipher.d.ts +0 -19
- package/lib/Signal/WASignalGroup/group_cipher.js +0 -111
- package/lib/Signal/WASignalGroup/group_session_builder.js +0 -46
- package/lib/Signal/WASignalGroup/index.d.ts +0 -11
- package/lib/Signal/WASignalGroup/index.js +0 -61
- package/lib/Signal/WASignalGroup/keyhelper.d.ts +0 -16
- package/lib/Signal/WASignalGroup/keyhelper.js +0 -66
- package/lib/Signal/WASignalGroup/protobufs.js +0 -3
- package/lib/Signal/WASignalGroup/queue_job.js +0 -69
- package/lib/Signal/WASignalGroup/readme.md +0 -6
- package/lib/Signal/WASignalGroup/sender-chain-key.d.ts +0 -14
- package/lib/Signal/WASignalGroup/sender-chain-key.js +0 -47
- package/lib/Signal/WASignalGroup/sender-key-distribution-message.d.ts +0 -17
- package/lib/Signal/WASignalGroup/sender-key-distribution-message.js +0 -71
- package/lib/Signal/WASignalGroup/sender-key-message.d.ts +0 -19
- package/lib/Signal/WASignalGroup/sender-key-message.js +0 -73
- package/lib/Signal/WASignalGroup/sender-key-name.d.ts +0 -19
- package/lib/Signal/WASignalGroup/sender-key-name.js +0 -59
- package/lib/Signal/WASignalGroup/sender-key-record.d.ts +0 -32
- package/lib/Signal/WASignalGroup/sender-key-record.js +0 -58
- package/lib/Signal/WASignalGroup/sender-key-state.d.ts +0 -44
- package/lib/Signal/WASignalGroup/sender-key-state.js +0 -147
- package/lib/Signal/WASignalGroup/sender-message-key.d.ts +0 -11
- package/lib/Signal/WASignalGroup/sender-message-key.js +0 -33
- package/lib/Signal/WASignalGroup/sender_chain_key.js +0 -50
- package/lib/Signal/WASignalGroup/sender_key_distribution_message.js +0 -78
- package/lib/Signal/WASignalGroup/sender_key_message.js +0 -92
- package/lib/Signal/WASignalGroup/sender_key_name.js +0 -70
- package/lib/Signal/WASignalGroup/sender_key_record.js +0 -56
- package/lib/Signal/WASignalGroup/sender_key_state.js +0 -129
- package/lib/Signal/WASignalGroup/sender_message_key.js +0 -39
- package/lib/Signal/libsignal.d.ts +0 -8
- package/lib/Signal/libsignal.js +0 -391
- package/lib/Signal/lid-mapping.d.ts +0 -28
- package/lib/Signal/lid-mapping.js +0 -184
- package/lib/Socket/Client/abstract-socket-client.d.ts +0 -15
- package/lib/Socket/Client/abstract-socket-client.js +0 -13
- package/lib/Socket/Client/index.d.ts +0 -2
- package/lib/Socket/Client/index.js +0 -22
- package/lib/Socket/Client/mobile-socket-client.d.ts +0 -12
- package/lib/Socket/Client/mobile-socket-client.js +0 -65
- package/lib/Socket/Client/types.d.ts +0 -16
- package/lib/Socket/Client/types.js +0 -18
- package/lib/Socket/Client/websocket.d.ts +0 -13
- package/lib/Socket/Client/websocket.js +0 -62
- package/lib/Socket/business.d.ts +0 -187
- package/lib/Socket/business.js +0 -415
- package/lib/Socket/chats.d.ts +0 -97
- package/lib/Socket/chats.js +0 -1118
- package/lib/Socket/communities.d.ts +0 -223
- package/lib/Socket/communities.js +0 -433
- package/lib/Socket/groups.d.ts +0 -129
- package/lib/Socket/groups.js +0 -360
- package/lib/Socket/index.d.ts +0 -191
- package/lib/Socket/index.js +0 -24
- package/lib/Socket/messages-recv.d.ts +0 -174
- package/lib/Socket/messages-recv.js +0 -1506
- package/lib/Socket/messages-send.d.ts +0 -165
- package/lib/Socket/messages-send.js +0 -1785
- package/lib/Socket/mex.d.ts +0 -2
- package/lib/Socket/mex.js +0 -47
- package/lib/Socket/newsletter.d.ts +0 -145
- package/lib/Socket/newsletter.js +0 -295
- package/lib/Socket/socket.d.ts +0 -45
- package/lib/Socket/socket.js +0 -934
- 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/index.js +0 -24
- package/lib/Store/make-cache-manager-store.d.ts +0 -14
- package/lib/Store/make-cache-manager-store.js +0 -90
- package/lib/Store/make-in-memory-store.d.ts +0 -123
- package/lib/Store/make-in-memory-store.js +0 -429
- package/lib/Store/make-ordered-dictionary.d.ts +0 -12
- package/lib/Store/make-ordered-dictionary.js +0 -86
- package/lib/Store/object-repository.d.ts +0 -10
- package/lib/Store/object-repository.js +0 -31
- package/lib/Types/Auth.d.ts +0 -121
- package/lib/Types/Auth.js +0 -3
- package/lib/Types/Bussines.js +0 -3
- package/lib/Types/Bussiness.d.ts +0 -28
- package/lib/Types/Call.d.ts +0 -14
- package/lib/Types/Call.js +0 -3
- package/lib/Types/Chat.d.ts +0 -143
- package/lib/Types/Chat.js +0 -9
- package/lib/Types/Contact.d.ts +0 -23
- package/lib/Types/Contact.js +0 -3
- package/lib/Types/Events.d.ts +0 -226
- package/lib/Types/Events.js +0 -3
- package/lib/Types/GroupMetadata.d.ts +0 -66
- package/lib/Types/GroupMetadata.js +0 -3
- package/lib/Types/Label.d.ts +0 -48
- package/lib/Types/Label.js +0 -31
- package/lib/Types/LabelAssociation.d.ts +0 -35
- package/lib/Types/LabelAssociation.js +0 -13
- package/lib/Types/Message.d.ts +0 -484
- package/lib/Types/Message.js +0 -19
- package/lib/Types/MexUpdates.d.ts +0 -9
- package/lib/Types/MexUpdates.js +0 -18
- package/lib/Types/Newsletter.d.ts +0 -109
- package/lib/Types/Newsletter.js +0 -40
- package/lib/Types/Product.d.ts +0 -92
- package/lib/Types/Product.js +0 -3
- package/lib/Types/Signal.d.ts +0 -98
- package/lib/Types/Signal.js +0 -3
- package/lib/Types/Socket.d.ts +0 -141
- package/lib/Types/Socket.js +0 -3
- package/lib/Types/State.d.ts +0 -41
- package/lib/Types/State.js +0 -14
- package/lib/Types/USync.d.ts +0 -26
- package/lib/Types/USync.js +0 -3
- package/lib/Types/index.d.ts +0 -80
- package/lib/Types/index.js +0 -50
- package/lib/Utils/auth-utils.d.ts +0 -21
- package/lib/Utils/auth-utils.js +0 -528
- package/lib/Utils/baileys-event-stream.d.ts +0 -18
- package/lib/Utils/baileys-event-stream.js +0 -70
- package/lib/Utils/business.d.ts +0 -29
- package/lib/Utils/business.js +0 -255
- package/lib/Utils/chat-utils.d.ts +0 -82
- package/lib/Utils/chat-utils.js +0 -809
- package/lib/Utils/crypto.d.ts +0 -56
- package/lib/Utils/crypto.js +0 -189
- package/lib/Utils/decode-wa-message.d.ts +0 -53
- package/lib/Utils/decode-wa-message.js +0 -323
- package/lib/Utils/event-buffer.d.ts +0 -39
- package/lib/Utils/event-buffer.js +0 -595
- package/lib/Utils/generics.d.ts +0 -131
- package/lib/Utils/generics.js +0 -630
- package/lib/Utils/history.d.ts +0 -23
- package/lib/Utils/history.js +0 -104
- package/lib/Utils/index.d.ts +0 -20
- package/lib/Utils/index.js +0 -40
- package/lib/Utils/link-preview.d.ts +0 -23
- package/lib/Utils/link-preview.js +0 -120
- package/lib/Utils/logger.d.ts +0 -13
- package/lib/Utils/logger.js +0 -7
- package/lib/Utils/lt-hash.d.ts +0 -14
- package/lib/Utils/lt-hash.js +0 -58
- package/lib/Utils/make-mutex.d.ts +0 -9
- package/lib/Utils/make-mutex.js +0 -49
- package/lib/Utils/message-retry-manager.d.ts +0 -88
- package/lib/Utils/message-retry-manager.js +0 -160
- package/lib/Utils/messages-media.d.ts +0 -135
- package/lib/Utils/messages-media.js +0 -869
- package/lib/Utils/messages.d.ts +0 -105
- package/lib/Utils/messages.js +0 -1745
- package/lib/Utils/noise-handler.d.ts +0 -21
- package/lib/Utils/noise-handler.js +0 -165
- package/lib/Utils/process-message.d.ts +0 -49
- package/lib/Utils/process-message.js +0 -427
- package/lib/Utils/signal.d.ts +0 -42
- package/lib/Utils/signal.js +0 -166
- 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 -18
- package/lib/Utils/use-multi-file-auth-state.js +0 -238
- 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/Utils/validate-connection.js +0 -220
- package/lib/WABinary/constants.d.ts +0 -30
- package/lib/WABinary/constants.js +0 -1316
- package/lib/WABinary/decode.d.ts +0 -9
- package/lib/WABinary/decode.js +0 -288
- package/lib/WABinary/encode.d.ts +0 -3
- package/lib/WABinary/encode.js +0 -265
- package/lib/WABinary/generic-utils.d.ts +0 -28
- package/lib/WABinary/generic-utils.js +0 -142
- package/lib/WABinary/index.d.ts +0 -5
- package/lib/WABinary/index.js +0 -25
- package/lib/WABinary/jid-utils.d.ts +0 -58
- package/lib/WABinary/jid-utils.js +0 -104
- package/lib/WABinary/types.d.ts +0 -22
- package/lib/WABinary/types.js +0 -3
- package/lib/WAM/BinaryInfo.d.ts +0 -16
- package/lib/WAM/BinaryInfo.js +0 -17
- package/lib/WAM/constants.d.ts +0 -47
- package/lib/WAM/constants.js +0 -15371
- package/lib/WAM/encode.d.ts +0 -3
- package/lib/WAM/encode.js +0 -164
- package/lib/WAM/index.d.ts +0 -3
- package/lib/WAM/index.js +0 -23
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.d.ts +0 -28
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +0 -69
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -10
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +0 -36
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -26
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +0 -62
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -14
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +0 -35
- package/lib/WAUSync/Protocols/USyncLIDProtocol.d.ts +0 -10
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +0 -38
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -14
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +0 -46
- package/lib/WAUSync/Protocols/index.d.ts +0 -6
- package/lib/WAUSync/Protocols/index.js +0 -26
- package/lib/WAUSync/USyncQuery.d.ts +0 -31
- package/lib/WAUSync/USyncQuery.js +0 -92
- package/lib/WAUSync/USyncUser.d.ts +0 -12
- package/lib/WAUSync/USyncUser.js +0 -30
- package/lib/WAUSync/index.d.ts +0 -3
- package/lib/WAUSync/index.js +0 -23
- package/lib/index.d.ts +0 -13
- package/lib/index.js +0 -33
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { CiphertextMessage } from './ciphertext-message'
|
|
2
|
-
|
|
3
|
-
export declare class SenderKeyDistributionMessage extends CiphertextMessage {
|
|
4
|
-
private readonly id
|
|
5
|
-
private readonly iteration
|
|
6
|
-
private readonly chainKey
|
|
7
|
-
private readonly signatureKey
|
|
8
|
-
private readonly serialized
|
|
9
|
-
constructor(id?: number | null, iteration?: number | null, chainKey?: Uint8Array | null, signatureKey?: Uint8Array | null, serialized?: Uint8Array | null)
|
|
10
|
-
private intsToByteHighAndLow
|
|
11
|
-
serialize(): Uint8Array
|
|
12
|
-
getType(): number
|
|
13
|
-
getIteration(): number
|
|
14
|
-
getChainKey(): Uint8Array
|
|
15
|
-
getSignatureKey(): Uint8Array
|
|
16
|
-
getId(): number
|
|
17
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict"
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true })
|
|
4
|
-
|
|
5
|
-
const WAProto_1 = require("../../../WAProto")
|
|
6
|
-
const ciphertext_message_1 = require("./ciphertext-message")
|
|
7
|
-
|
|
8
|
-
class SenderKeyDistributionMessage extends ciphertext_message_1.CiphertextMessage {
|
|
9
|
-
constructor(id, iteration, chainKey, signatureKey, serialized) {
|
|
10
|
-
super()
|
|
11
|
-
if (serialized) {
|
|
12
|
-
try {
|
|
13
|
-
const message = serialized.slice(1)
|
|
14
|
-
const distributionMessage = WAProto_1.proto.SenderKeyDistributionMessage.decode(message).toJSON()
|
|
15
|
-
this.serialized = serialized
|
|
16
|
-
this.id = distributionMessage.id
|
|
17
|
-
this.iteration = distributionMessage.iteration
|
|
18
|
-
this.chainKey =
|
|
19
|
-
typeof distributionMessage.chainKey === 'string'
|
|
20
|
-
? Buffer.from(distributionMessage.chainKey, 'base64')
|
|
21
|
-
: distributionMessage.chainKey
|
|
22
|
-
this.signatureKey =
|
|
23
|
-
typeof distributionMessage.signingKey === 'string'
|
|
24
|
-
? Buffer.from(distributionMessage.signingKey, 'base64')
|
|
25
|
-
: distributionMessage.signingKey
|
|
26
|
-
}
|
|
27
|
-
catch (e) {
|
|
28
|
-
throw new Error(String(e))
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
const version = this.intsToByteHighAndLow(this.CURRENT_VERSION, this.CURRENT_VERSION)
|
|
33
|
-
this.id = id
|
|
34
|
-
this.iteration = iteration
|
|
35
|
-
this.chainKey = chainKey
|
|
36
|
-
this.signatureKey = signatureKey
|
|
37
|
-
const message = WAProto_1.proto.SenderKeyDistributionMessage.encode(WAProto_1.proto.SenderKeyDistributionMessage.create({
|
|
38
|
-
id,
|
|
39
|
-
iteration,
|
|
40
|
-
chainKey,
|
|
41
|
-
signingKey: this.signatureKey
|
|
42
|
-
})).finish()
|
|
43
|
-
this.serialized = Buffer.concat([Buffer.from([version]), message])
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
intsToByteHighAndLow(highValue, lowValue) {
|
|
47
|
-
return (((highValue << 4) | lowValue) & 0xff) % 256
|
|
48
|
-
}
|
|
49
|
-
serialize() {
|
|
50
|
-
return this.serialized
|
|
51
|
-
}
|
|
52
|
-
getType() {
|
|
53
|
-
return this.SENDERKEY_DISTRIBUTION_TYPE
|
|
54
|
-
}
|
|
55
|
-
getIteration() {
|
|
56
|
-
return this.iteration
|
|
57
|
-
}
|
|
58
|
-
getChainKey() {
|
|
59
|
-
return typeof this.chainKey === 'string' ? Buffer.from(this.chainKey, 'base64') : this.chainKey
|
|
60
|
-
}
|
|
61
|
-
getSignatureKey() {
|
|
62
|
-
return typeof this.signatureKey === 'string' ? Buffer.from(this.signatureKey, 'base64') : this.signatureKey
|
|
63
|
-
}
|
|
64
|
-
getId() {
|
|
65
|
-
return this.id
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
module.exports = {
|
|
70
|
-
SenderKeyDistributionMessage
|
|
71
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { CiphertextMessage } from './ciphertext-message'
|
|
2
|
-
|
|
3
|
-
export declare class SenderKeyMessage extends CiphertextMessage {
|
|
4
|
-
private readonly SIGNATURE_LENGTH
|
|
5
|
-
private readonly messageVersion
|
|
6
|
-
private readonly keyId
|
|
7
|
-
private readonly iteration
|
|
8
|
-
private readonly ciphertext
|
|
9
|
-
private readonly signature
|
|
10
|
-
private readonly serialized
|
|
11
|
-
constructor(keyId?: number | null, iteration?: number | null, ciphertext?: Uint8Array | null, signatureKey?: Uint8Array | null, serialized?: Uint8Array | null)
|
|
12
|
-
getKeyId(): number
|
|
13
|
-
getIteration(): number
|
|
14
|
-
getCipherText(): Uint8Array
|
|
15
|
-
verifySignature(signatureKey: Uint8Array): void
|
|
16
|
-
private getSignature
|
|
17
|
-
serialize(): Uint8Array
|
|
18
|
-
getType(): number
|
|
19
|
-
}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
"use strict"
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true })
|
|
3
|
-
|
|
4
|
-
const curve_1 = require("@neelegirl/libsignal/src/curve")
|
|
5
|
-
const WAProto_1 = require("../../../WAProto")
|
|
6
|
-
const ciphertext_message_1 = require("./ciphertext-message")
|
|
7
|
-
|
|
8
|
-
class SenderKeyMessage extends ciphertext_message_1.CiphertextMessage {
|
|
9
|
-
constructor(keyId, iteration, ciphertext, signatureKey, serialized) {
|
|
10
|
-
super()
|
|
11
|
-
this.SIGNATURE_LENGTH = 64
|
|
12
|
-
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 = WAProto_1.proto.SenderKeyMessage.decode(message).toJSON()
|
|
17
|
-
this.serialized = serialized
|
|
18
|
-
this.messageVersion = (version & 0xff) >> 4
|
|
19
|
-
this.keyId = senderKeyMessage.id
|
|
20
|
-
this.iteration = senderKeyMessage.iteration
|
|
21
|
-
this.ciphertext =
|
|
22
|
-
typeof senderKeyMessage.ciphertext === 'string'
|
|
23
|
-
? Buffer.from(senderKeyMessage.ciphertext, 'base64')
|
|
24
|
-
: senderKeyMessage.ciphertext
|
|
25
|
-
this.signature = signature
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
const version = (((this.CURRENT_VERSION << 4) | this.CURRENT_VERSION) & 0xff) % 256
|
|
29
|
-
const ciphertextBuffer = Buffer.from(ciphertext)
|
|
30
|
-
const message = WAProto_1.proto.SenderKeyMessage.encode(WAProto_1.proto.SenderKeyMessage.create({
|
|
31
|
-
id: keyId,
|
|
32
|
-
iteration: iteration,
|
|
33
|
-
ciphertext: ciphertextBuffer
|
|
34
|
-
})).finish()
|
|
35
|
-
const signature = this.getSignature(signatureKey, Buffer.concat([Buffer.from([version]), message]))
|
|
36
|
-
this.serialized = Buffer.concat([Buffer.from([version]), message, Buffer.from(signature)])
|
|
37
|
-
this.messageVersion = this.CURRENT_VERSION
|
|
38
|
-
this.keyId = keyId
|
|
39
|
-
this.iteration = iteration
|
|
40
|
-
this.ciphertext = ciphertextBuffer
|
|
41
|
-
this.signature = signature
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
getKeyId() {
|
|
45
|
-
return this.keyId
|
|
46
|
-
}
|
|
47
|
-
getIteration() {
|
|
48
|
-
return this.iteration
|
|
49
|
-
}
|
|
50
|
-
getCipherText() {
|
|
51
|
-
return this.ciphertext
|
|
52
|
-
}
|
|
53
|
-
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 = curve_1.verifySignature(signatureKey, part1, part2)
|
|
57
|
-
if (!res)
|
|
58
|
-
throw new Error('Invalid signature!')
|
|
59
|
-
}
|
|
60
|
-
getSignature(signatureKey, serialized) {
|
|
61
|
-
return Buffer.from(curve_1.calculateSignature(signatureKey, serialized))
|
|
62
|
-
}
|
|
63
|
-
serialize() {
|
|
64
|
-
return this.serialized
|
|
65
|
-
}
|
|
66
|
-
getType() {
|
|
67
|
-
return 4
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
module.exports = {
|
|
72
|
-
SenderKeyMessage
|
|
73
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
interface Sender {
|
|
2
|
-
id: string
|
|
3
|
-
deviceId: number
|
|
4
|
-
toString(): string
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export declare class SenderKeyName {
|
|
8
|
-
private readonly groupId
|
|
9
|
-
private readonly sender
|
|
10
|
-
constructor(groupId: string, sender: Sender)
|
|
11
|
-
getGroupId(): string
|
|
12
|
-
getSender(): Sender
|
|
13
|
-
serialize(): string
|
|
14
|
-
toString(): string
|
|
15
|
-
equals(other: SenderKeyName | null): boolean
|
|
16
|
-
hashCode(): number
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export {}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict"
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true })
|
|
4
|
-
|
|
5
|
-
function isNull(str) {
|
|
6
|
-
return str === null || str === ''
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
function intValue(num) {
|
|
10
|
-
const MAX_VALUE = 0x7fffffff
|
|
11
|
-
const MIN_VALUE = -0x80000000
|
|
12
|
-
if (num > MAX_VALUE || num < MIN_VALUE) {
|
|
13
|
-
return num & 0xffffffff
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
return num
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function hashCode(strKey) {
|
|
20
|
-
let hash = 0
|
|
21
|
-
if (!isNull(strKey)) {
|
|
22
|
-
for (let i = 0; i < strKey.length; i++) {
|
|
23
|
-
hash = hash * 31 + strKey.charCodeAt(i)
|
|
24
|
-
hash = intValue(hash)
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return hash
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
class SenderKeyName {
|
|
31
|
-
constructor(groupId, sender) {
|
|
32
|
-
this.groupId = groupId
|
|
33
|
-
this.sender = sender
|
|
34
|
-
}
|
|
35
|
-
getGroupId() {
|
|
36
|
-
return this.groupId
|
|
37
|
-
}
|
|
38
|
-
getSender() {
|
|
39
|
-
return this.sender
|
|
40
|
-
}
|
|
41
|
-
serialize() {
|
|
42
|
-
return `${this.groupId}::${this.sender.id}::${this.sender.deviceId}`
|
|
43
|
-
}
|
|
44
|
-
toString() {
|
|
45
|
-
return this.serialize()
|
|
46
|
-
}
|
|
47
|
-
equals(other) {
|
|
48
|
-
if (other === null)
|
|
49
|
-
return false
|
|
50
|
-
return this.groupId === other.groupId && this.sender.toString() === other.sender.toString()
|
|
51
|
-
}
|
|
52
|
-
hashCode() {
|
|
53
|
-
return hashCode(this.groupId) ^ hashCode(this.sender.toString())
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
module.exports = {
|
|
58
|
-
SenderKeyName
|
|
59
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { SenderKeyState } from './sender-key-state'
|
|
2
|
-
|
|
3
|
-
export interface SenderKeyStateStructure {
|
|
4
|
-
senderKeyId: number
|
|
5
|
-
senderChainKey: {
|
|
6
|
-
iteration: number
|
|
7
|
-
seed: Uint8Array
|
|
8
|
-
}
|
|
9
|
-
senderSigningKey: {
|
|
10
|
-
public: Uint8Array
|
|
11
|
-
private?: Uint8Array
|
|
12
|
-
}
|
|
13
|
-
senderMessageKeys: Array<{
|
|
14
|
-
iteration: number
|
|
15
|
-
seed: Uint8Array
|
|
16
|
-
}>
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export declare class SenderKeyRecord {
|
|
20
|
-
private readonly MAX_STATES
|
|
21
|
-
private readonly senderKeyStates
|
|
22
|
-
constructor(serialized?: SenderKeyStateStructure[])
|
|
23
|
-
isEmpty(): boolean
|
|
24
|
-
getSenderKeyState(keyId?: number): SenderKeyState | undefined
|
|
25
|
-
addSenderKeyState(id: number, iteration: number, chainKey: Uint8Array, signatureKey: Uint8Array): void
|
|
26
|
-
setSenderKeyState(id: number, iteration: number, chainKey: Uint8Array, keyPair: {
|
|
27
|
-
public: Uint8Array
|
|
28
|
-
private: Uint8Array
|
|
29
|
-
}): void
|
|
30
|
-
serialize(): SenderKeyStateStructure[]
|
|
31
|
-
static deserialize(data: Uint8Array | string | SenderKeyStateStructure[]): SenderKeyRecord
|
|
32
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
"use strict"
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true })
|
|
4
|
-
|
|
5
|
-
const generics_1 = require("../../Utils/generics")
|
|
6
|
-
const sender_key_state_1 = require("./sender-key-state")
|
|
7
|
-
|
|
8
|
-
class SenderKeyRecord {
|
|
9
|
-
constructor(serialized) {
|
|
10
|
-
this.MAX_STATES = 5
|
|
11
|
-
this.senderKeyStates = []
|
|
12
|
-
if (serialized) {
|
|
13
|
-
for (const structure of serialized) {
|
|
14
|
-
this.senderKeyStates.push(new sender_key_state_1.SenderKeyState(null, null, null, null, null, null, structure))
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
isEmpty() {
|
|
19
|
-
return this.senderKeyStates.length === 0
|
|
20
|
-
}
|
|
21
|
-
getSenderKeyState(keyId) {
|
|
22
|
-
if (keyId === undefined && this.senderKeyStates.length) {
|
|
23
|
-
return this.senderKeyStates[this.senderKeyStates.length - 1]
|
|
24
|
-
}
|
|
25
|
-
return this.senderKeyStates.find(state => state.getKeyId() === keyId)
|
|
26
|
-
}
|
|
27
|
-
addSenderKeyState(id, iteration, chainKey, signatureKey) {
|
|
28
|
-
this.senderKeyStates.push(new sender_key_state_1.SenderKeyState(id, iteration, chainKey, null, signatureKey))
|
|
29
|
-
if (this.senderKeyStates.length > this.MAX_STATES) {
|
|
30
|
-
this.senderKeyStates.shift()
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
setSenderKeyState(id, iteration, chainKey, keyPair) {
|
|
34
|
-
this.senderKeyStates.length = 0
|
|
35
|
-
this.senderKeyStates.push(new sender_key_state_1.SenderKeyState(id, iteration, chainKey, keyPair))
|
|
36
|
-
}
|
|
37
|
-
serialize() {
|
|
38
|
-
return this.senderKeyStates.map(state => state.getStructure())
|
|
39
|
-
}
|
|
40
|
-
static deserialize(data) {
|
|
41
|
-
let parsed
|
|
42
|
-
if (typeof data === 'string') {
|
|
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
|
-
}
|
|
52
|
-
return new SenderKeyRecord(parsed)
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
module.exports = {
|
|
57
|
-
SenderKeyRecord
|
|
58
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { SenderChainKey } from './sender-chain-key'
|
|
2
|
-
import { SenderMessageKey } from './sender-message-key'
|
|
3
|
-
|
|
4
|
-
interface SenderChainKeyStructure {
|
|
5
|
-
iteration: number
|
|
6
|
-
seed: Uint8Array
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
interface SenderSigningKeyStructure {
|
|
10
|
-
public: Uint8Array
|
|
11
|
-
private?: Uint8Array
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
interface SenderMessageKeyStructure {
|
|
15
|
-
iteration: number
|
|
16
|
-
seed: Uint8Array
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
interface SenderKeyStateStructure {
|
|
20
|
-
senderKeyId: number
|
|
21
|
-
senderChainKey: SenderChainKeyStructure
|
|
22
|
-
senderSigningKey: SenderSigningKeyStructure
|
|
23
|
-
senderMessageKeys: SenderMessageKeyStructure[]
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export declare class SenderKeyState {
|
|
27
|
-
private readonly MAX_MESSAGE_KEYS
|
|
28
|
-
private readonly senderKeyStateStructure
|
|
29
|
-
constructor(id?: number | null, iteration?: number | null, chainKey?: Uint8Array | null, signatureKeyPair?: {
|
|
30
|
-
public: Uint8Array
|
|
31
|
-
private: Uint8Array
|
|
32
|
-
} | null, signatureKeyPublic?: Uint8Array | null, signatureKeyPrivate?: Uint8Array | null, senderKeyStateStructure?: SenderKeyStateStructure | null)
|
|
33
|
-
getKeyId(): number
|
|
34
|
-
getSenderChainKey(): SenderChainKey
|
|
35
|
-
setSenderChainKey(chainKey: SenderChainKey): void
|
|
36
|
-
getSigningKeyPublic(): Buffer
|
|
37
|
-
getSigningKeyPrivate(): Buffer | undefined
|
|
38
|
-
hasSenderMessageKey(iteration: number): boolean
|
|
39
|
-
addSenderMessageKey(senderMessageKey: SenderMessageKey): void
|
|
40
|
-
removeSenderMessageKey(iteration: number): SenderMessageKey | null
|
|
41
|
-
getStructure(): SenderKeyStateStructure
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export {}
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
"use strict"
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true })
|
|
4
|
-
|
|
5
|
-
const sender_chain_key_1 = require("./sender-chain-key")
|
|
6
|
-
const sender_message_key_1 = require("./sender-message-key")
|
|
7
|
-
|
|
8
|
-
class SenderKeyState {
|
|
9
|
-
constructor(id, iteration, chainKey, signatureKeyPair, signatureKeyPublic, signatureKeyPrivate, senderKeyStateStructure) {
|
|
10
|
-
this.MAX_MESSAGE_KEYS = 2000
|
|
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
|
-
if (senderKeyStateStructure) {
|
|
23
|
-
this.senderKeyStateStructure = {
|
|
24
|
-
...senderKeyStateStructure,
|
|
25
|
-
senderMessageKeys: Array.isArray(senderKeyStateStructure.senderMessageKeys)
|
|
26
|
-
? senderKeyStateStructure.senderMessageKeys
|
|
27
|
-
: []
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
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
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
this.senderKeyStateStructure = {
|
|
48
|
-
senderKeyId: id || 0,
|
|
49
|
-
senderChainKey: senderChainKeyStructure,
|
|
50
|
-
senderSigningKey: signingKeyStructure,
|
|
51
|
-
senderMessageKeys: []
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
getKeyId() {
|
|
56
|
-
return this.senderKeyStateStructure.senderKeyId
|
|
57
|
-
}
|
|
58
|
-
getSenderChainKey() {
|
|
59
|
-
return new sender_chain_key_1.SenderChainKey(this.senderKeyStateStructure.senderChainKey.iteration, this.senderKeyStateStructure.senderChainKey.seed)
|
|
60
|
-
}
|
|
61
|
-
setSenderChainKey(chainKey) {
|
|
62
|
-
this.senderKeyStateStructure.senderChainKey = {
|
|
63
|
-
iteration: chainKey.getIteration(),
|
|
64
|
-
seed: chainKey.getSeed()
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
getSigningKeyPublic() {
|
|
68
|
-
let key = this.senderKeyStateStructure.senderSigningKey.public
|
|
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
|
-
|
|
88
|
-
if (publicKey.length === 32) {
|
|
89
|
-
const fixed = Buffer.alloc(33)
|
|
90
|
-
|
|
91
|
-
fixed[0] = 0x05
|
|
92
|
-
publicKey.copy(fixed, 1)
|
|
93
|
-
|
|
94
|
-
return fixed
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return publicKey
|
|
98
|
-
}
|
|
99
|
-
getSigningKeyPrivate() {
|
|
100
|
-
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
|
-
return Buffer.from(privateKey || [])
|
|
117
|
-
}
|
|
118
|
-
hasSenderMessageKey(iteration) {
|
|
119
|
-
return this.senderKeyStateStructure.senderMessageKeys.some(key => key.iteration === iteration)
|
|
120
|
-
}
|
|
121
|
-
addSenderMessageKey(senderMessageKey) {
|
|
122
|
-
this.senderKeyStateStructure.senderMessageKeys.push({
|
|
123
|
-
iteration: senderMessageKey.getIteration(),
|
|
124
|
-
seed: senderMessageKey.getSeed()
|
|
125
|
-
})
|
|
126
|
-
|
|
127
|
-
if (this.senderKeyStateStructure.senderMessageKeys.length > this.MAX_MESSAGE_KEYS) {
|
|
128
|
-
this.senderKeyStateStructure.senderMessageKeys.shift()
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
removeSenderMessageKey(iteration) {
|
|
132
|
-
const index = this.senderKeyStateStructure.senderMessageKeys.findIndex(key => key.iteration === iteration)
|
|
133
|
-
if (index !== -1) {
|
|
134
|
-
const messageKey = this.senderKeyStateStructure.senderMessageKeys[index]
|
|
135
|
-
this.senderKeyStateStructure.senderMessageKeys.splice(index, 1)
|
|
136
|
-
return new sender_message_key_1.SenderMessageKey(messageKey.iteration, messageKey.seed)
|
|
137
|
-
}
|
|
138
|
-
return null
|
|
139
|
-
}
|
|
140
|
-
getStructure() {
|
|
141
|
-
return this.senderKeyStateStructure
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
module.exports = {
|
|
146
|
-
SenderKeyState
|
|
147
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export declare class SenderMessageKey {
|
|
2
|
-
private readonly iteration
|
|
3
|
-
private readonly iv
|
|
4
|
-
private readonly cipherKey
|
|
5
|
-
private readonly seed
|
|
6
|
-
constructor(iteration: number, seed: Uint8Array)
|
|
7
|
-
getIteration(): number
|
|
8
|
-
getIv(): Uint8Array
|
|
9
|
-
getCipherKey(): Uint8Array
|
|
10
|
-
getSeed(): Uint8Array
|
|
11
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict"
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true })
|
|
3
|
-
|
|
4
|
-
const crypto_1 = require("@neelegirl/libsignal/src/crypto")
|
|
5
|
-
|
|
6
|
-
class SenderMessageKey {
|
|
7
|
-
constructor(iteration, seed) {
|
|
8
|
-
const derivative = (0, crypto_1.deriveSecrets)(seed, Buffer.alloc(32), Buffer.from('WhisperGroup'))
|
|
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
|
|
16
|
-
}
|
|
17
|
-
getIteration() {
|
|
18
|
-
return this.iteration
|
|
19
|
-
}
|
|
20
|
-
getIv() {
|
|
21
|
-
return this.iv
|
|
22
|
-
}
|
|
23
|
-
getCipherKey() {
|
|
24
|
-
return this.cipherKey
|
|
25
|
-
}
|
|
26
|
-
getSeed() {
|
|
27
|
-
return this.seed
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
module.exports = {
|
|
32
|
-
SenderMessageKey
|
|
33
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
const SenderMessageKey = require('./sender_message_key');
|
|
2
|
-
//const HKDF = require('./hkdf');
|
|
3
|
-
const crypto = require('@neelegirl/libsignal/src/crypto');
|
|
4
|
-
|
|
5
|
-
class SenderChainKey {
|
|
6
|
-
MESSAGE_KEY_SEED = Buffer.from([0x01]);
|
|
7
|
-
|
|
8
|
-
CHAIN_KEY_SEED = Buffer.from([0x02]);
|
|
9
|
-
|
|
10
|
-
iteration = 0;
|
|
11
|
-
|
|
12
|
-
chainKey = Buffer.alloc(0);
|
|
13
|
-
|
|
14
|
-
constructor(iteration, chainKey) {
|
|
15
|
-
this.iteration = iteration;
|
|
16
|
-
this.chainKey = chainKey;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
getIteration() {
|
|
20
|
-
return this.iteration;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
getSenderMessageKey() {
|
|
24
|
-
return new SenderMessageKey(
|
|
25
|
-
this.iteration,
|
|
26
|
-
this.getDerivative(this.MESSAGE_KEY_SEED, this.chainKey)
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
getNext() {
|
|
31
|
-
return new SenderChainKey(
|
|
32
|
-
this.iteration + 1,
|
|
33
|
-
this.getDerivative(this.CHAIN_KEY_SEED, this.chainKey)
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
getSeed() {
|
|
38
|
-
return typeof this.chainKey === 'string' ? Buffer.from(this.chainKey, 'base64') : this.chainKey;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
getDerivative(seed, key) {
|
|
42
|
-
key = typeof key === 'string' ? Buffer.from(key, 'base64') : key;
|
|
43
|
-
const hash = crypto.calculateMAC(key, seed);
|
|
44
|
-
//const hash = new Hash().hmac_hash(key, seed, 'sha256', '');
|
|
45
|
-
|
|
46
|
-
return hash;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
module.exports = SenderChainKey;
|