@pontalabs/baileys 1.0.6 → 1.0.8
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/LICENSE +1 -1
- package/README.md +839 -267
- package/WAProto/GenerateStatics.sh +4 -3
- package/WAProto/WAProto.proto +511 -1215
- package/WAProto/index.d.ts +55 -14017
- package/WAProto/index.js +29 -97689
- package/lib/Defaults/index.d.ts +74 -72
- package/lib/Defaults/index.js +108 -94
- package/lib/Signal/Group/ciphertext-message.d.ts +7 -8
- package/lib/Signal/Group/ciphertext-message.js +16 -9
- package/lib/Signal/Group/group-session-builder.d.ts +13 -11
- package/lib/Signal/Group/group-session-builder.js +61 -19
- package/lib/Signal/Group/group_cipher.d.ts +16 -14
- package/lib/Signal/Group/group_cipher.js +70 -41
- package/lib/Signal/Group/index.d.ts +11 -12
- package/lib/Signal/Group/index.js +61 -12
- package/lib/Signal/Group/keyhelper.d.ts +14 -9
- package/lib/Signal/Group/keyhelper.js +58 -10
- package/lib/Signal/Group/sender-chain-key.d.ts +13 -13
- package/lib/Signal/Group/sender-chain-key.js +34 -13
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -16
- package/lib/Signal/Group/sender-key-distribution-message.js +36 -28
- package/lib/Signal/Group/sender-key-message.d.ts +18 -18
- package/lib/Signal/Group/sender-key-message.js +45 -38
- package/lib/Signal/Group/sender-key-name.d.ts +15 -14
- package/lib/Signal/Group/sender-key-name.js +31 -20
- package/lib/Signal/Group/sender-key-record.d.ts +25 -24
- package/lib/Signal/Group/sender-key-record.js +35 -18
- package/lib/Signal/Group/sender-key-state.d.ts +34 -29
- package/lib/Signal/Group/sender-key-state.js +100 -37
- package/lib/Signal/Group/sender-message-key.d.ts +10 -11
- package/lib/Signal/Group/sender-message-key.js +22 -15
- package/lib/Signal/libsignal.d.ts +8 -5
- package/lib/Signal/libsignal.js +142 -288
- package/lib/Signal/lid-mapping.d.ts +28 -23
- package/lib/Signal/lid-mapping.js +184 -277
- package/lib/Socket/Client/index.d.ts +2 -3
- package/lib/Socket/Client/index.js +22 -3
- package/lib/Socket/Client/types.d.ts +15 -15
- package/lib/Socket/Client/types.js +15 -8
- package/lib/Socket/Client/websocket.d.ts +12 -12
- package/lib/Socket/Client/websocket.js +37 -29
- package/lib/Socket/business.d.ts +178 -208
- package/lib/Socket/business.js +127 -91
- package/lib/Socket/chats.d.ts +93 -120
- package/lib/Socket/chats.js +652 -727
- package/lib/Socket/community.js +10 -2
- package/lib/Socket/groups.d.ts +111 -143
- package/lib/Socket/groups.js +186 -165
- package/lib/Socket/index.d.ts +183 -252
- package/lib/Socket/index.js +18 -38
- package/lib/Socket/messages-recv.d.ts +167 -196
- package/lib/Socket/messages-recv.js +1567 -1443
- package/lib/Socket/messages-send.d.ts +158 -192
- package/lib/Socket/messages-send.js +1208 -1102
- package/lib/Socket/newsletter.d.ts +138 -163
- package/lib/Socket/newsletter.js +249 -153
- package/lib/Socket/socket.d.ts +36 -50
- package/lib/Socket/socket.js +820 -749
- package/lib/Store/index.d.ts +4 -4
- package/lib/Store/index.js +24 -4
- package/lib/Store/make-in-memory-store.d.ts +104 -44
- package/lib/Store/make-in-memory-store.js +213 -199
- package/lib/Store/make-ordered-dictionary.d.ts +12 -13
- package/lib/Store/make-ordered-dictionary.js +45 -38
- package/lib/Store/object-repository.d.ts +10 -11
- package/lib/Store/object-repository.js +16 -9
- package/lib/Types/Auth.d.ts +97 -93
- package/lib/Types/Auth.js +3 -2
- package/lib/Types/Bussines.js +3 -2
- package/lib/Types/Call.d.ts +13 -14
- package/lib/Types/Call.js +3 -2
- package/lib/Types/Chat.d.ts +97 -78
- package/lib/Types/Chat.js +9 -8
- package/lib/Types/Contact.d.ts +9 -12
- package/lib/Types/Contact.js +3 -2
- package/lib/Types/Events.d.ts +176 -206
- package/lib/Types/Events.js +3 -2
- package/lib/Types/GroupMetadata.d.ts +48 -53
- package/lib/Types/GroupMetadata.js +3 -2
- package/lib/Types/Label.d.ts +14 -13
- package/lib/Types/Label.js +30 -24
- package/lib/Types/LabelAssociation.d.ts +20 -15
- package/lib/Types/LabelAssociation.js +12 -6
- package/lib/Types/Message.d.ts +412 -248
- package/lib/Types/Message.js +19 -17
- package/lib/Types/Product.d.ts +71 -58
- package/lib/Types/Product.js +3 -2
- package/lib/Types/Signal.d.ts +82 -71
- package/lib/Types/Signal.js +3 -2
- package/lib/Types/Socket.d.ts +81 -76
- package/lib/Types/Socket.js +3 -3
- package/lib/Types/State.d.ts +19 -75
- package/lib/Types/State.js +14 -56
- package/lib/Types/USync.d.ts +8 -8
- package/lib/Types/USync.js +3 -2
- package/lib/Types/index.d.ts +62 -47
- package/lib/Types/index.js +50 -26
- package/lib/Utils/auth-utils.d.ts +10 -13
- package/lib/Utils/auth-utils.js +472 -213
- package/lib/Utils/business.d.ts +20 -14
- package/lib/Utils/business.js +134 -110
- package/lib/Utils/chat-utils.d.ts +70 -88
- package/lib/Utils/chat-utils.js +403 -466
- package/lib/Utils/crypto.d.ts +46 -27
- package/lib/Utils/crypto.js +188 -117
- package/lib/Utils/decode-wa-message.d.ts +45 -58
- package/lib/Utils/decode-wa-message.js +311 -212
- package/lib/Utils/event-buffer.d.ts +17 -14
- package/lib/Utils/event-buffer.js +296 -321
- package/lib/Utils/generics.d.ts +92 -66
- package/lib/Utils/generics.js +436 -270
- package/lib/Utils/history.d.ts +23 -24
- package/lib/Utils/history.js +76 -106
- package/lib/Utils/index.d.ts +21 -24
- package/lib/Utils/index.js +41 -24
- package/lib/Utils/link-preview.d.ts +14 -12
- package/lib/Utils/link-preview.js +75 -40
- package/lib/Utils/logger.d.ts +11 -10
- package/lib/Utils/logger.js +7 -3
- package/lib/Utils/lt-hash.d.ts +14 -8
- package/lib/Utils/lt-hash.js +53 -3
- package/lib/Utils/make-mutex.d.ts +7 -7
- package/lib/Utils/make-mutex.js +44 -28
- package/lib/Utils/message-retry-manager.d.ts +88 -115
- package/lib/Utils/message-retry-manager.js +160 -265
- package/lib/Utils/messages-media.d.ts +107 -105
- package/lib/Utils/messages-media.js +619 -548
- package/lib/Utils/messages.d.ts +66 -52
- package/lib/Utils/messages.js +1558 -1730
- package/lib/Utils/noise-handler.d.ts +18 -18
- package/lib/Utils/noise-handler.js +130 -176
- package/lib/Utils/process-message.d.ts +32 -43
- package/lib/Utils/process-message.js +282 -484
- package/lib/Utils/rich-message-utils.js +724 -1220
- package/lib/Utils/signal.d.ts +32 -37
- package/lib/Utils/signal.js +105 -140
- package/lib/Utils/use-multi-file-auth-state.d.ts +5 -5
- package/lib/Utils/use-multi-file-auth-state.js +120 -70
- package/lib/Utils/use-single-file-auth-state.d.ts +13 -11
- package/lib/Utils/use-single-file-auth-state.js +66 -92
- package/lib/Utils/validate-connection.d.ts +13 -11
- package/lib/Utils/validate-connection.js +113 -128
- package/lib/WABinary/constants.d.ts +27 -25
- package/lib/WABinary/constants.js +1292 -1451
- package/lib/WABinary/decode.d.ts +9 -7
- package/lib/WABinary/decode.js +189 -163
- package/lib/WABinary/encode.d.ts +3 -3
- package/lib/WABinary/encode.js +155 -110
- package/lib/WABinary/generic-utils.d.ts +27 -14
- package/lib/WABinary/generic-utils.js +105 -177
- package/lib/WABinary/index.d.ts +5 -6
- package/lib/WABinary/index.js +25 -6
- package/lib/WABinary/jid-utils.d.ts +54 -41
- package/lib/WABinary/jid-utils.js +152 -83
- package/lib/WABinary/types.d.ts +13 -10
- package/lib/WABinary/types.js +3 -2
- package/lib/WAM/BinaryInfo.d.ts +15 -8
- package/lib/WAM/BinaryInfo.js +14 -7
- package/lib/WAM/constants.d.ts +37 -30
- package/lib/WAM/constants.js +11983 -19465
- package/lib/WAM/encode.d.ts +3 -3
- package/lib/WAM/encode.js +109 -95
- package/lib/WAM/index.d.ts +3 -4
- package/lib/WAM/index.js +23 -4
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -9
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +21 -37
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -19
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +26 -18
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -11
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +20 -12
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -11
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +24 -16
- package/lib/WAUSync/Protocols/index.d.ts +6 -6
- package/lib/WAUSync/Protocols/index.js +26 -6
- package/lib/WAUSync/USyncQuery.d.ts +28 -27
- package/lib/WAUSync/USyncQuery.js +62 -68
- package/lib/WAUSync/USyncUser.d.ts +10 -15
- package/lib/WAUSync/USyncUser.js +19 -20
- package/lib/WAUSync/index.d.ts +3 -4
- package/lib/WAUSync/index.js +23 -4
- package/lib/index.d.ts +12 -11
- package/lib/index.js +39 -12
- package/package.json +43 -87
- package/engine-requirements.js +0 -10
|
@@ -1,66 +1,73 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict"
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true })
|
|
3
|
+
|
|
4
|
+
const curve_1 = require("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 {
|
|
5
9
|
constructor(keyId, iteration, ciphertext, signatureKey, serialized) {
|
|
6
|
-
super()
|
|
7
|
-
this.SIGNATURE_LENGTH = 64
|
|
10
|
+
super()
|
|
11
|
+
this.SIGNATURE_LENGTH = 64
|
|
8
12
|
if (serialized) {
|
|
9
|
-
const version = serialized[0]
|
|
10
|
-
const message = serialized.slice(1, serialized.length - this.SIGNATURE_LENGTH)
|
|
11
|
-
const signature = serialized.slice(-1 * this.SIGNATURE_LENGTH)
|
|
12
|
-
const senderKeyMessage = proto.SenderKeyMessage.decode(message).toJSON()
|
|
13
|
-
this.serialized = serialized
|
|
14
|
-
this.messageVersion = (version & 0xff) >> 4
|
|
15
|
-
this.keyId = senderKeyMessage.id
|
|
16
|
-
this.iteration = senderKeyMessage.iteration
|
|
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
|
|
17
21
|
this.ciphertext =
|
|
18
22
|
typeof senderKeyMessage.ciphertext === 'string'
|
|
19
23
|
? Buffer.from(senderKeyMessage.ciphertext, 'base64')
|
|
20
|
-
: senderKeyMessage.ciphertext
|
|
21
|
-
this.signature = signature
|
|
24
|
+
: senderKeyMessage.ciphertext
|
|
25
|
+
this.signature = signature
|
|
22
26
|
}
|
|
23
27
|
else {
|
|
24
|
-
const version = (((this.CURRENT_VERSION << 4) | this.CURRENT_VERSION) & 0xff) % 256
|
|
25
|
-
const ciphertextBuffer = Buffer.from(ciphertext)
|
|
26
|
-
const message = proto.SenderKeyMessage.encode(proto.SenderKeyMessage.create({
|
|
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({
|
|
27
31
|
id: keyId,
|
|
28
32
|
iteration: iteration,
|
|
29
33
|
ciphertext: ciphertextBuffer
|
|
30
|
-
})).finish()
|
|
31
|
-
const signature = this.getSignature(signatureKey, Buffer.concat([Buffer.from([version]), message]))
|
|
32
|
-
this.serialized = Buffer.concat([Buffer.from([version]), message, Buffer.from(signature)])
|
|
33
|
-
this.messageVersion = this.CURRENT_VERSION
|
|
34
|
-
this.keyId = keyId
|
|
35
|
-
this.iteration = iteration
|
|
36
|
-
this.ciphertext = ciphertextBuffer
|
|
37
|
-
this.signature = signature
|
|
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
|
|
38
42
|
}
|
|
39
43
|
}
|
|
40
44
|
getKeyId() {
|
|
41
|
-
return this.keyId
|
|
45
|
+
return this.keyId
|
|
42
46
|
}
|
|
43
47
|
getIteration() {
|
|
44
|
-
return this.iteration
|
|
48
|
+
return this.iteration
|
|
45
49
|
}
|
|
46
50
|
getCipherText() {
|
|
47
|
-
return this.ciphertext
|
|
51
|
+
return this.ciphertext
|
|
48
52
|
}
|
|
49
53
|
verifySignature(signatureKey) {
|
|
50
|
-
const part1 = this.serialized.slice(0, this.serialized.length - this.SIGNATURE_LENGTH)
|
|
51
|
-
const part2 = this.serialized.slice(-1 * this.SIGNATURE_LENGTH)
|
|
52
|
-
const res = verifySignature(signatureKey, part1, part2)
|
|
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)
|
|
53
57
|
if (!res)
|
|
54
|
-
throw new Error('Invalid signature!')
|
|
58
|
+
throw new Error('Invalid signature!')
|
|
55
59
|
}
|
|
56
60
|
getSignature(signatureKey, serialized) {
|
|
57
|
-
return Buffer.from(calculateSignature(signatureKey, serialized))
|
|
61
|
+
return Buffer.from(curve_1.calculateSignature(signatureKey, serialized))
|
|
58
62
|
}
|
|
59
63
|
serialize() {
|
|
60
|
-
return this.serialized
|
|
64
|
+
return this.serialized
|
|
61
65
|
}
|
|
62
66
|
getType() {
|
|
63
|
-
return 4
|
|
67
|
+
return 4
|
|
64
68
|
}
|
|
65
69
|
}
|
|
66
|
-
|
|
70
|
+
|
|
71
|
+
module.exports = {
|
|
72
|
+
SenderKeyMessage
|
|
73
|
+
}
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
interface Sender {
|
|
2
|
-
id: string
|
|
3
|
-
deviceId: number
|
|
4
|
-
toString(): string
|
|
2
|
+
id: string
|
|
3
|
+
deviceId: number
|
|
4
|
+
toString(): string
|
|
5
5
|
}
|
|
6
|
+
|
|
6
7
|
export declare class SenderKeyName {
|
|
7
|
-
private readonly groupId
|
|
8
|
-
private readonly sender
|
|
9
|
-
constructor(groupId: string, sender: Sender)
|
|
10
|
-
getGroupId(): string
|
|
11
|
-
getSender(): Sender
|
|
12
|
-
serialize(): string
|
|
13
|
-
toString(): string
|
|
14
|
-
equals(other: SenderKeyName | null): boolean
|
|
15
|
-
hashCode(): number
|
|
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
|
|
16
17
|
}
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
|
|
19
|
+
export {}
|
|
@@ -1,48 +1,59 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true })
|
|
4
|
+
|
|
1
5
|
function isNull(str) {
|
|
2
|
-
return str === null || str === ''
|
|
6
|
+
return str === null || str === ''
|
|
3
7
|
}
|
|
8
|
+
|
|
4
9
|
function intValue(num) {
|
|
5
|
-
const MAX_VALUE = 0x7fffffff
|
|
6
|
-
const MIN_VALUE = -0x80000000
|
|
10
|
+
const MAX_VALUE = 0x7fffffff
|
|
11
|
+
const MIN_VALUE = -0x80000000
|
|
7
12
|
if (num > MAX_VALUE || num < MIN_VALUE) {
|
|
8
|
-
return num & 0xffffffff
|
|
13
|
+
return num & 0xffffffff
|
|
9
14
|
}
|
|
10
|
-
|
|
15
|
+
|
|
16
|
+
return num
|
|
11
17
|
}
|
|
18
|
+
|
|
12
19
|
function hashCode(strKey) {
|
|
13
|
-
let hash = 0
|
|
20
|
+
let hash = 0
|
|
14
21
|
if (!isNull(strKey)) {
|
|
15
22
|
for (let i = 0; i < strKey.length; i++) {
|
|
16
|
-
hash = hash * 31 + strKey.charCodeAt(i)
|
|
17
|
-
hash = intValue(hash)
|
|
23
|
+
hash = hash * 31 + strKey.charCodeAt(i)
|
|
24
|
+
hash = intValue(hash)
|
|
18
25
|
}
|
|
19
26
|
}
|
|
20
|
-
return hash
|
|
27
|
+
return hash
|
|
21
28
|
}
|
|
22
|
-
|
|
29
|
+
|
|
30
|
+
class SenderKeyName {
|
|
23
31
|
constructor(groupId, sender) {
|
|
24
|
-
this.groupId = groupId
|
|
25
|
-
this.sender = sender
|
|
32
|
+
this.groupId = groupId
|
|
33
|
+
this.sender = sender
|
|
26
34
|
}
|
|
27
35
|
getGroupId() {
|
|
28
|
-
return this.groupId
|
|
36
|
+
return this.groupId
|
|
29
37
|
}
|
|
30
38
|
getSender() {
|
|
31
|
-
return this.sender
|
|
39
|
+
return this.sender
|
|
32
40
|
}
|
|
33
41
|
serialize() {
|
|
34
|
-
return `${this.groupId}::${this.sender.id}::${this.sender.deviceId}
|
|
42
|
+
return `${this.groupId}::${this.sender.id}::${this.sender.deviceId}`
|
|
35
43
|
}
|
|
36
44
|
toString() {
|
|
37
|
-
return this.serialize()
|
|
45
|
+
return this.serialize()
|
|
38
46
|
}
|
|
39
47
|
equals(other) {
|
|
40
48
|
if (other === null)
|
|
41
|
-
return false
|
|
42
|
-
return this.groupId === other.groupId && this.sender.toString() === other.sender.toString()
|
|
49
|
+
return false
|
|
50
|
+
return this.groupId === other.groupId && this.sender.toString() === other.sender.toString()
|
|
43
51
|
}
|
|
44
52
|
hashCode() {
|
|
45
|
-
return hashCode(this.groupId) ^ hashCode(this.sender.toString())
|
|
53
|
+
return hashCode(this.groupId) ^ hashCode(this.sender.toString())
|
|
46
54
|
}
|
|
47
55
|
}
|
|
48
|
-
|
|
56
|
+
|
|
57
|
+
module.exports = {
|
|
58
|
+
SenderKeyName
|
|
59
|
+
}
|
|
@@ -1,31 +1,32 @@
|
|
|
1
|
-
import { SenderKeyState } from './sender-key-state
|
|
1
|
+
import { SenderKeyState } from './sender-key-state'
|
|
2
|
+
|
|
2
3
|
export interface SenderKeyStateStructure {
|
|
3
|
-
senderKeyId: number
|
|
4
|
+
senderKeyId: number
|
|
4
5
|
senderChainKey: {
|
|
5
|
-
iteration: number
|
|
6
|
-
seed: Uint8Array
|
|
7
|
-
}
|
|
6
|
+
iteration: number
|
|
7
|
+
seed: Uint8Array
|
|
8
|
+
}
|
|
8
9
|
senderSigningKey: {
|
|
9
|
-
public: Uint8Array
|
|
10
|
-
private?: Uint8Array
|
|
11
|
-
}
|
|
10
|
+
public: Uint8Array
|
|
11
|
+
private?: Uint8Array
|
|
12
|
+
}
|
|
12
13
|
senderMessageKeys: Array<{
|
|
13
|
-
iteration: number
|
|
14
|
-
seed: Uint8Array
|
|
15
|
-
}
|
|
14
|
+
iteration: number
|
|
15
|
+
seed: Uint8Array
|
|
16
|
+
}>
|
|
16
17
|
}
|
|
18
|
+
|
|
17
19
|
export declare class SenderKeyRecord {
|
|
18
|
-
private readonly MAX_STATES
|
|
19
|
-
private readonly senderKeyStates
|
|
20
|
-
constructor(serialized?: SenderKeyStateStructure[])
|
|
21
|
-
isEmpty(): boolean
|
|
22
|
-
getSenderKeyState(keyId?: number): SenderKeyState | undefined
|
|
23
|
-
addSenderKeyState(id: number, iteration: number, chainKey: Uint8Array, signatureKey: Uint8Array): void
|
|
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
|
|
24
26
|
setSenderKeyState(id: number, iteration: number, chainKey: Uint8Array, keyPair: {
|
|
25
|
-
public: Uint8Array
|
|
26
|
-
private: Uint8Array
|
|
27
|
-
}): void
|
|
28
|
-
serialize(): SenderKeyStateStructure[]
|
|
29
|
-
static deserialize(data: Uint8Array): SenderKeyRecord
|
|
30
|
-
}
|
|
31
|
-
//# sourceMappingURL=sender-key-record.d.ts.map
|
|
27
|
+
public: Uint8Array
|
|
28
|
+
private: Uint8Array
|
|
29
|
+
}): void
|
|
30
|
+
serialize(): SenderKeyStateStructure[]
|
|
31
|
+
static deserialize(data: Uint8Array | string | SenderKeyStateStructure[]): SenderKeyRecord
|
|
32
|
+
}
|
|
@@ -1,41 +1,58 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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 {
|
|
4
9
|
constructor(serialized) {
|
|
5
|
-
this.MAX_STATES = 5
|
|
6
|
-
this.senderKeyStates = []
|
|
10
|
+
this.MAX_STATES = 5
|
|
11
|
+
this.senderKeyStates = []
|
|
7
12
|
if (serialized) {
|
|
8
13
|
for (const structure of serialized) {
|
|
9
|
-
this.senderKeyStates.push(new SenderKeyState(null, null, null, null, null, null, structure))
|
|
14
|
+
this.senderKeyStates.push(new sender_key_state_1.SenderKeyState(null, null, null, null, null, null, structure))
|
|
10
15
|
}
|
|
11
16
|
}
|
|
12
17
|
}
|
|
13
18
|
isEmpty() {
|
|
14
|
-
return this.senderKeyStates.length === 0
|
|
19
|
+
return this.senderKeyStates.length === 0
|
|
15
20
|
}
|
|
16
21
|
getSenderKeyState(keyId) {
|
|
17
22
|
if (keyId === undefined && this.senderKeyStates.length) {
|
|
18
|
-
return this.senderKeyStates[this.senderKeyStates.length - 1]
|
|
23
|
+
return this.senderKeyStates[this.senderKeyStates.length - 1]
|
|
19
24
|
}
|
|
20
|
-
return this.senderKeyStates.find(state => state.getKeyId() === keyId)
|
|
25
|
+
return this.senderKeyStates.find(state => state.getKeyId() === keyId)
|
|
21
26
|
}
|
|
22
27
|
addSenderKeyState(id, iteration, chainKey, signatureKey) {
|
|
23
|
-
this.senderKeyStates.push(new SenderKeyState(id, iteration, chainKey, null, signatureKey))
|
|
28
|
+
this.senderKeyStates.push(new sender_key_state_1.SenderKeyState(id, iteration, chainKey, null, signatureKey))
|
|
24
29
|
if (this.senderKeyStates.length > this.MAX_STATES) {
|
|
25
|
-
this.senderKeyStates.shift()
|
|
30
|
+
this.senderKeyStates.shift()
|
|
26
31
|
}
|
|
27
32
|
}
|
|
28
33
|
setSenderKeyState(id, iteration, chainKey, keyPair) {
|
|
29
|
-
this.senderKeyStates.length = 0
|
|
30
|
-
this.senderKeyStates.push(new SenderKeyState(id, iteration, chainKey, keyPair))
|
|
34
|
+
this.senderKeyStates.length = 0
|
|
35
|
+
this.senderKeyStates.push(new sender_key_state_1.SenderKeyState(id, iteration, chainKey, keyPair))
|
|
31
36
|
}
|
|
32
37
|
serialize() {
|
|
33
|
-
return this.senderKeyStates.map(state => state.getStructure())
|
|
38
|
+
return this.senderKeyStates.map(state => state.getStructure())
|
|
34
39
|
}
|
|
35
40
|
static deserialize(data) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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)
|
|
39
53
|
}
|
|
40
54
|
}
|
|
41
|
-
|
|
55
|
+
|
|
56
|
+
module.exports = {
|
|
57
|
+
SenderKeyRecord
|
|
58
|
+
}
|
|
@@ -1,39 +1,44 @@
|
|
|
1
|
-
import { SenderChainKey } from './sender-chain-key
|
|
2
|
-
import { SenderMessageKey } from './sender-message-key
|
|
1
|
+
import { SenderChainKey } from './sender-chain-key'
|
|
2
|
+
import { SenderMessageKey } from './sender-message-key'
|
|
3
|
+
|
|
3
4
|
interface SenderChainKeyStructure {
|
|
4
|
-
iteration: number
|
|
5
|
-
seed: Uint8Array
|
|
5
|
+
iteration: number
|
|
6
|
+
seed: Uint8Array
|
|
6
7
|
}
|
|
8
|
+
|
|
7
9
|
interface SenderSigningKeyStructure {
|
|
8
|
-
public: Uint8Array
|
|
9
|
-
private?: Uint8Array
|
|
10
|
+
public: Uint8Array
|
|
11
|
+
private?: Uint8Array
|
|
10
12
|
}
|
|
13
|
+
|
|
11
14
|
interface SenderMessageKeyStructure {
|
|
12
|
-
iteration: number
|
|
13
|
-
seed: Uint8Array
|
|
15
|
+
iteration: number
|
|
16
|
+
seed: Uint8Array
|
|
14
17
|
}
|
|
18
|
+
|
|
15
19
|
interface SenderKeyStateStructure {
|
|
16
|
-
senderKeyId: number
|
|
17
|
-
senderChainKey: SenderChainKeyStructure
|
|
18
|
-
senderSigningKey: SenderSigningKeyStructure
|
|
19
|
-
senderMessageKeys: SenderMessageKeyStructure[]
|
|
20
|
+
senderKeyId: number
|
|
21
|
+
senderChainKey: SenderChainKeyStructure
|
|
22
|
+
senderSigningKey: SenderSigningKeyStructure
|
|
23
|
+
senderMessageKeys: SenderMessageKeyStructure[]
|
|
20
24
|
}
|
|
25
|
+
|
|
21
26
|
export declare class SenderKeyState {
|
|
22
|
-
private readonly MAX_MESSAGE_KEYS
|
|
23
|
-
private readonly senderKeyStateStructure
|
|
24
|
-
constructor(id?: number | null, iteration?: number | null, chainKey?: Uint8Array | null
|
|
25
|
-
public: Uint8Array
|
|
26
|
-
private: Uint8Array
|
|
27
|
-
} | null, signatureKeyPublic?: Uint8Array |
|
|
28
|
-
getKeyId(): number
|
|
29
|
-
getSenderChainKey(): SenderChainKey
|
|
30
|
-
setSenderChainKey(chainKey: SenderChainKey): void
|
|
31
|
-
getSigningKeyPublic(): Buffer
|
|
32
|
-
getSigningKeyPrivate(): Buffer | undefined
|
|
33
|
-
hasSenderMessageKey(iteration: number): boolean
|
|
34
|
-
addSenderMessageKey(senderMessageKey: SenderMessageKey): void
|
|
35
|
-
removeSenderMessageKey(iteration: number): SenderMessageKey | null
|
|
36
|
-
getStructure(): SenderKeyStateStructure
|
|
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
|
|
37
42
|
}
|
|
38
|
-
|
|
39
|
-
|
|
43
|
+
|
|
44
|
+
export {}
|
|
@@ -1,84 +1,147 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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 {
|
|
4
9
|
constructor(id, iteration, chainKey, signatureKeyPair, signatureKeyPublic, signatureKeyPrivate, senderKeyStateStructure) {
|
|
5
|
-
this.MAX_MESSAGE_KEYS = 2000
|
|
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
|
+
|
|
6
22
|
if (senderKeyStateStructure) {
|
|
7
23
|
this.senderKeyStateStructure = {
|
|
8
24
|
...senderKeyStateStructure,
|
|
9
25
|
senderMessageKeys: Array.isArray(senderKeyStateStructure.senderMessageKeys)
|
|
10
26
|
? senderKeyStateStructure.senderMessageKeys
|
|
11
27
|
: []
|
|
12
|
-
}
|
|
28
|
+
}
|
|
13
29
|
}
|
|
14
30
|
else {
|
|
15
31
|
if (signatureKeyPair) {
|
|
16
|
-
signatureKeyPublic = signatureKeyPair.public
|
|
17
|
-
signatureKeyPrivate = signatureKeyPair.private
|
|
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
|
|
18
45
|
}
|
|
46
|
+
|
|
19
47
|
this.senderKeyStateStructure = {
|
|
20
48
|
senderKeyId: id || 0,
|
|
21
|
-
senderChainKey:
|
|
22
|
-
|
|
23
|
-
seed: Buffer.from(chainKey || [])
|
|
24
|
-
},
|
|
25
|
-
senderSigningKey: {
|
|
26
|
-
public: Buffer.from(signatureKeyPublic || []),
|
|
27
|
-
private: Buffer.from(signatureKeyPrivate || [])
|
|
28
|
-
},
|
|
49
|
+
senderChainKey: senderChainKeyStructure,
|
|
50
|
+
senderSigningKey: signingKeyStructure,
|
|
29
51
|
senderMessageKeys: []
|
|
30
|
-
}
|
|
52
|
+
}
|
|
31
53
|
}
|
|
32
54
|
}
|
|
33
55
|
getKeyId() {
|
|
34
|
-
return this.senderKeyStateStructure.senderKeyId
|
|
56
|
+
return this.senderKeyStateStructure.senderKeyId
|
|
35
57
|
}
|
|
36
58
|
getSenderChainKey() {
|
|
37
|
-
return new SenderChainKey(this.senderKeyStateStructure.senderChainKey.iteration, this.senderKeyStateStructure.senderChainKey.seed)
|
|
59
|
+
return new sender_chain_key_1.SenderChainKey(this.senderKeyStateStructure.senderChainKey.iteration, this.senderKeyStateStructure.senderChainKey.seed)
|
|
38
60
|
}
|
|
39
61
|
setSenderChainKey(chainKey) {
|
|
40
62
|
this.senderKeyStateStructure.senderChainKey = {
|
|
41
63
|
iteration: chainKey.getIteration(),
|
|
42
64
|
seed: chainKey.getSeed()
|
|
43
|
-
}
|
|
65
|
+
}
|
|
44
66
|
}
|
|
45
67
|
getSigningKeyPublic() {
|
|
46
|
-
|
|
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
|
+
|
|
47
88
|
if (publicKey.length === 32) {
|
|
48
|
-
const fixed = Buffer.alloc(33)
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
89
|
+
const fixed = Buffer.alloc(33)
|
|
90
|
+
|
|
91
|
+
fixed[0] = 0x05
|
|
92
|
+
publicKey.copy(fixed, 1)
|
|
93
|
+
|
|
94
|
+
return fixed
|
|
52
95
|
}
|
|
53
|
-
|
|
96
|
+
|
|
97
|
+
return publicKey
|
|
54
98
|
}
|
|
55
99
|
getSigningKeyPrivate() {
|
|
56
|
-
const privateKey = this.senderKeyStateStructure.senderSigningKey.private
|
|
57
|
-
|
|
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 || [])
|
|
58
117
|
}
|
|
59
118
|
hasSenderMessageKey(iteration) {
|
|
60
|
-
return this.senderKeyStateStructure.senderMessageKeys.some(key => key.iteration === iteration)
|
|
119
|
+
return this.senderKeyStateStructure.senderMessageKeys.some(key => key.iteration === iteration)
|
|
61
120
|
}
|
|
62
121
|
addSenderMessageKey(senderMessageKey) {
|
|
63
122
|
this.senderKeyStateStructure.senderMessageKeys.push({
|
|
64
123
|
iteration: senderMessageKey.getIteration(),
|
|
65
124
|
seed: senderMessageKey.getSeed()
|
|
66
|
-
})
|
|
125
|
+
})
|
|
126
|
+
|
|
67
127
|
if (this.senderKeyStateStructure.senderMessageKeys.length > this.MAX_MESSAGE_KEYS) {
|
|
68
|
-
this.senderKeyStateStructure.senderMessageKeys.shift()
|
|
128
|
+
this.senderKeyStateStructure.senderMessageKeys.shift()
|
|
69
129
|
}
|
|
70
130
|
}
|
|
71
131
|
removeSenderMessageKey(iteration) {
|
|
72
|
-
const index = this.senderKeyStateStructure.senderMessageKeys.findIndex(key => key.iteration === iteration)
|
|
132
|
+
const index = this.senderKeyStateStructure.senderMessageKeys.findIndex(key => key.iteration === iteration)
|
|
73
133
|
if (index !== -1) {
|
|
74
|
-
const messageKey = this.senderKeyStateStructure.senderMessageKeys[index]
|
|
75
|
-
this.senderKeyStateStructure.senderMessageKeys.splice(index, 1)
|
|
76
|
-
return new SenderMessageKey(messageKey.iteration, messageKey.seed)
|
|
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)
|
|
77
137
|
}
|
|
78
|
-
return null
|
|
138
|
+
return null
|
|
79
139
|
}
|
|
80
140
|
getStructure() {
|
|
81
|
-
return this.senderKeyStateStructure
|
|
141
|
+
return this.senderKeyStateStructure
|
|
82
142
|
}
|
|
83
143
|
}
|
|
84
|
-
|
|
144
|
+
|
|
145
|
+
module.exports = {
|
|
146
|
+
SenderKeyState
|
|
147
|
+
}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
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
|
-
}
|
|
12
|
-
//# sourceMappingURL=sender-message-key.d.ts.map
|
|
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
|
+
}
|