@skycodee/baileys 8.0.2 → 8.0.3

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.
Files changed (114) hide show
  1. package/package.json +14 -44
  2. package/src/Defaults/baileys-version.json +0 -1
  3. package/src/Defaults/index.ts +0 -149
  4. package/src/Signal/Group/ciphertext-message.ts +0 -9
  5. package/src/Signal/Group/group-session-builder.ts +0 -56
  6. package/src/Signal/Group/group_cipher.ts +0 -117
  7. package/src/Signal/Group/index.ts +0 -11
  8. package/src/Signal/Group/keyhelper.ts +0 -28
  9. package/src/Signal/Group/sender-chain-key.ts +0 -34
  10. package/src/Signal/Group/sender-key-distribution-message.ts +0 -95
  11. package/src/Signal/Group/sender-key-message.ts +0 -96
  12. package/src/Signal/Group/sender-key-name.ts +0 -66
  13. package/src/Signal/Group/sender-key-record.ts +0 -69
  14. package/src/Signal/Group/sender-key-state.ts +0 -134
  15. package/src/Signal/Group/sender-message-key.ts +0 -36
  16. package/src/Signal/libsignal.ts +0 -521
  17. package/src/Signal/lid-mapping.ts +0 -328
  18. package/src/Socket/Client/index.ts +0 -2
  19. package/src/Socket/Client/types.ts +0 -22
  20. package/src/Socket/Client/websocket.ts +0 -63
  21. package/src/Socket/business.ts +0 -424
  22. package/src/Socket/chats.ts +0 -1272
  23. package/src/Socket/communities.ts +0 -477
  24. package/src/Socket/groups.ts +0 -361
  25. package/src/Socket/index.ts +0 -15
  26. package/src/Socket/messages-recv.ts +0 -1668
  27. package/src/Socket/messages-send.ts +0 -1296
  28. package/src/Socket/mex.ts +0 -58
  29. package/src/Socket/newsletter.ts +0 -229
  30. package/src/Socket/socket.ts +0 -1184
  31. package/src/Types/Auth.ts +0 -116
  32. package/src/Types/Bussines.ts +0 -20
  33. package/src/Types/Call.ts +0 -15
  34. package/src/Types/Chat.ts +0 -138
  35. package/src/Types/Contact.ts +0 -24
  36. package/src/Types/Events.ts +0 -159
  37. package/src/Types/GroupMetadata.ts +0 -70
  38. package/src/Types/Label.ts +0 -48
  39. package/src/Types/LabelAssociation.ts +0 -35
  40. package/src/Types/Message.ts +0 -380
  41. package/src/Types/Newsletter.ts +0 -98
  42. package/src/Types/Product.ts +0 -85
  43. package/src/Types/Signal.ts +0 -76
  44. package/src/Types/Socket.ts +0 -150
  45. package/src/Types/State.ts +0 -43
  46. package/src/Types/USync.ts +0 -27
  47. package/src/Types/globals.d.ts +0 -8
  48. package/src/Types/index.ts +0 -67
  49. package/src/Utils/auth-utils.ts +0 -368
  50. package/src/Utils/browser-utils.ts +0 -31
  51. package/src/Utils/business.ts +0 -286
  52. package/src/Utils/chat-utils.ts +0 -974
  53. package/src/Utils/crypto.ts +0 -147
  54. package/src/Utils/decode-wa-message.ts +0 -355
  55. package/src/Utils/event-buffer.ts +0 -692
  56. package/src/Utils/generics.ts +0 -474
  57. package/src/Utils/history.ts +0 -161
  58. package/src/Utils/identity-change-handler.ts +0 -83
  59. package/src/Utils/index.ts +0 -19
  60. package/src/Utils/link-preview.ts +0 -111
  61. package/src/Utils/logger.ts +0 -13
  62. package/src/Utils/lt-hash.ts +0 -8
  63. package/src/Utils/make-mutex.ts +0 -42
  64. package/src/Utils/message-retry-manager.ts +0 -295
  65. package/src/Utils/messages-media.ts +0 -984
  66. package/src/Utils/messages.ts +0 -1097
  67. package/src/Utils/noise-handler.ts +0 -268
  68. package/src/Utils/pre-key-manager.ts +0 -126
  69. package/src/Utils/process-message.ts +0 -670
  70. package/src/Utils/reporting-utils.ts +0 -344
  71. package/src/Utils/signal.ts +0 -214
  72. package/src/Utils/sync-action-utils.ts +0 -74
  73. package/src/Utils/tc-token-utils.ts +0 -34
  74. package/src/Utils/use-multi-file-auth-state.ts +0 -136
  75. package/src/Utils/validate-connection.ts +0 -253
  76. package/src/WABinary/constants.ts +0 -1305
  77. package/src/WABinary/decode.ts +0 -308
  78. package/src/WABinary/encode.ts +0 -258
  79. package/src/WABinary/generic-utils.ts +0 -141
  80. package/src/WABinary/index.ts +0 -5
  81. package/src/WABinary/jid-utils.ts +0 -128
  82. package/src/WABinary/types.ts +0 -17
  83. package/src/WAM/BinaryInfo.ts +0 -12
  84. package/src/WAM/constants.ts +0 -22889
  85. package/src/WAM/encode.ts +0 -169
  86. package/src/WAM/index.ts +0 -3
  87. package/src/WAUSync/Protocols/USyncContactProtocol.ts +0 -32
  88. package/src/WAUSync/Protocols/USyncDeviceProtocol.ts +0 -78
  89. package/src/WAUSync/Protocols/USyncDisappearingModeProtocol.ts +0 -35
  90. package/src/WAUSync/Protocols/USyncStatusProtocol.ts +0 -44
  91. package/src/WAUSync/Protocols/UsyncBotProfileProtocol.ts +0 -76
  92. package/src/WAUSync/Protocols/UsyncLIDProtocol.ts +0 -33
  93. package/src/WAUSync/Protocols/index.ts +0 -4
  94. package/src/WAUSync/USyncQuery.ts +0 -133
  95. package/src/WAUSync/USyncUser.ts +0 -32
  96. package/src/WAUSync/index.ts +0 -3
  97. package/src/__tests__/Signal/Group/sender-key-state-regression.test.ts +0 -22
  98. package/src/__tests__/Signal/lid-mapping.test.ts +0 -47
  99. package/src/__tests__/Socket/identity-change-handling.test.ts +0 -207
  100. package/src/__tests__/TestUtils/session.ts +0 -47
  101. package/src/__tests__/Utils/generics.test.ts +0 -70
  102. package/src/__tests__/Utils/history.test.ts +0 -362
  103. package/src/__tests__/Utils/messages-media.test.ts +0 -405
  104. package/src/__tests__/Utils/noise-handler.test.ts +0 -339
  105. package/src/__tests__/Utils/process-message.test.ts +0 -138
  106. package/src/__tests__/Utils/process-sync-action.test.ts +0 -359
  107. package/src/__tests__/Utils/reporting-utils.test.ts +0 -160
  108. package/src/__tests__/Utils/signal.test.ts +0 -69
  109. package/src/__tests__/Utils/sync-action-utils.test.ts +0 -183
  110. package/src/__tests__/binary/connection-deadlock.test.ts +0 -54
  111. package/src/__tests__/e2e/fetch-wa-web-version.test-e2e.ts +0 -60
  112. package/src/__tests__/e2e/send-receive-message.test-e2e.ts +0 -644
  113. package/src/__tests__/proto-tojson-long.test.ts +0 -31
  114. package/src/index.ts +0 -13
@@ -1,96 +0,0 @@
1
- import { calculateSignature, verifySignature } from 'libsignal/src/curve'
2
- import { proto } from '../../../WAProto/index.js'
3
- import { CiphertextMessage } from './ciphertext-message'
4
-
5
- interface SenderKeyMessageStructure {
6
- id: number
7
- iteration: number
8
- ciphertext: string | Buffer
9
- }
10
-
11
- export class SenderKeyMessage extends CiphertextMessage {
12
- private readonly SIGNATURE_LENGTH = 64
13
- private readonly messageVersion: number
14
- private readonly keyId: number
15
- private readonly iteration: number
16
- private readonly ciphertext: Uint8Array
17
- private readonly signature: Uint8Array
18
- private readonly serialized: Uint8Array
19
-
20
- constructor(
21
- keyId?: number | null,
22
- iteration?: number | null,
23
- ciphertext?: Uint8Array | null,
24
- signatureKey?: Uint8Array | null,
25
- serialized?: Uint8Array | null
26
- ) {
27
- super()
28
-
29
- if (serialized) {
30
- const version = serialized[0]!
31
- const message = serialized.slice(1, serialized.length - this.SIGNATURE_LENGTH)
32
- const signature = serialized.slice(-1 * this.SIGNATURE_LENGTH)
33
- const senderKeyMessage = proto.SenderKeyMessage.decode(message).toJSON() as SenderKeyMessageStructure
34
-
35
- this.serialized = serialized
36
- this.messageVersion = (version & 0xff) >> 4
37
- this.keyId = senderKeyMessage.id
38
- this.iteration = senderKeyMessage.iteration
39
- this.ciphertext =
40
- typeof senderKeyMessage.ciphertext === 'string'
41
- ? Buffer.from(senderKeyMessage.ciphertext, 'base64')
42
- : senderKeyMessage.ciphertext
43
- this.signature = signature
44
- } else {
45
- const version = (((this.CURRENT_VERSION << 4) | this.CURRENT_VERSION) & 0xff) % 256
46
- const ciphertextBuffer = Buffer.from(ciphertext!)
47
- const message = proto.SenderKeyMessage.encode(
48
- proto.SenderKeyMessage.create({
49
- id: keyId!,
50
- iteration: iteration!,
51
- ciphertext: ciphertextBuffer
52
- })
53
- ).finish()
54
-
55
- const signature = this.getSignature(signatureKey!, Buffer.concat([Buffer.from([version]), message]))
56
-
57
- this.serialized = Buffer.concat([Buffer.from([version]), message, Buffer.from(signature)])
58
- this.messageVersion = this.CURRENT_VERSION
59
- this.keyId = keyId!
60
- this.iteration = iteration!
61
- this.ciphertext = ciphertextBuffer
62
- this.signature = signature
63
- }
64
- }
65
-
66
- public getKeyId(): number {
67
- return this.keyId
68
- }
69
-
70
- public getIteration(): number {
71
- return this.iteration
72
- }
73
-
74
- public getCipherText(): Uint8Array {
75
- return this.ciphertext
76
- }
77
-
78
- public verifySignature(signatureKey: Uint8Array): void {
79
- const part1 = this.serialized.slice(0, this.serialized.length - this.SIGNATURE_LENGTH)
80
- const part2 = this.serialized.slice(-1 * this.SIGNATURE_LENGTH)
81
- const res = verifySignature(signatureKey, part1, part2)
82
- if (!res) throw new Error('Invalid signature!')
83
- }
84
-
85
- private getSignature(signatureKey: Uint8Array, serialized: Uint8Array): Uint8Array {
86
- return Buffer.from(calculateSignature(signatureKey, serialized))
87
- }
88
-
89
- public serialize(): Uint8Array {
90
- return this.serialized
91
- }
92
-
93
- public getType(): number {
94
- return 4
95
- }
96
- }
@@ -1,66 +0,0 @@
1
- interface Sender {
2
- id: string
3
- deviceId: number
4
- toString(): string
5
- }
6
-
7
- function isNull(str: string | null): boolean {
8
- return str === null || str === ''
9
- }
10
-
11
- function intValue(num: number): number {
12
- const MAX_VALUE = 0x7fffffff
13
- const MIN_VALUE = -0x80000000
14
- if (num > MAX_VALUE || num < MIN_VALUE) {
15
- return num & 0xffffffff
16
- }
17
-
18
- return num
19
- }
20
-
21
- function hashCode(strKey: string): number {
22
- let hash = 0
23
- if (!isNull(strKey)) {
24
- for (let i = 0; i < strKey.length; i++) {
25
- hash = hash * 31 + strKey.charCodeAt(i)
26
- hash = intValue(hash)
27
- }
28
- }
29
-
30
- return hash
31
- }
32
-
33
- export class SenderKeyName {
34
- private readonly groupId: string
35
- private readonly sender: Sender
36
-
37
- constructor(groupId: string, sender: Sender) {
38
- this.groupId = groupId
39
- this.sender = sender
40
- }
41
-
42
- public getGroupId(): string {
43
- return this.groupId
44
- }
45
-
46
- public getSender(): Sender {
47
- return this.sender
48
- }
49
-
50
- public serialize(): string {
51
- return `${this.groupId}::${this.sender.id}::${this.sender.deviceId}`
52
- }
53
-
54
- public toString(): string {
55
- return this.serialize()
56
- }
57
-
58
- public equals(other: SenderKeyName | null): boolean {
59
- if (other === null) return false
60
- return this.groupId === other.groupId && this.sender.toString() === other.sender.toString()
61
- }
62
-
63
- public hashCode(): number {
64
- return hashCode(this.groupId) ^ hashCode(this.sender.toString())
65
- }
66
- }
@@ -1,69 +0,0 @@
1
- import { BufferJSON } from '../../Utils/generics'
2
- import { SenderKeyState } from './sender-key-state'
3
-
4
- export interface SenderKeyStateStructure {
5
- senderKeyId: number
6
- senderChainKey: {
7
- iteration: number
8
- seed: Uint8Array
9
- }
10
- senderSigningKey: {
11
- public: Uint8Array
12
- private?: Uint8Array
13
- }
14
- senderMessageKeys: Array<{
15
- iteration: number
16
- seed: Uint8Array
17
- }>
18
- }
19
-
20
- export class SenderKeyRecord {
21
- private readonly MAX_STATES = 5
22
- private readonly senderKeyStates: SenderKeyState[] = []
23
-
24
- constructor(serialized?: SenderKeyStateStructure[]) {
25
- if (serialized) {
26
- for (const structure of serialized) {
27
- this.senderKeyStates.push(new SenderKeyState(null, null, null, null, null, null, structure))
28
- }
29
- }
30
- }
31
-
32
- public isEmpty(): boolean {
33
- return this.senderKeyStates.length === 0
34
- }
35
-
36
- public getSenderKeyState(keyId?: number): SenderKeyState | undefined {
37
- if (keyId === undefined && this.senderKeyStates.length) {
38
- return this.senderKeyStates[this.senderKeyStates.length - 1]
39
- }
40
-
41
- return this.senderKeyStates.find(state => state.getKeyId() === keyId)
42
- }
43
-
44
- public addSenderKeyState(id: number, iteration: number, chainKey: Uint8Array, signatureKey: Uint8Array): void {
45
- this.senderKeyStates.push(new SenderKeyState(id, iteration, chainKey, null, signatureKey))
46
- if (this.senderKeyStates.length > this.MAX_STATES) {
47
- this.senderKeyStates.shift()
48
- }
49
- }
50
-
51
- public setSenderKeyState(
52
- id: number,
53
- iteration: number,
54
- chainKey: Uint8Array,
55
- keyPair: { public: Uint8Array; private: Uint8Array }
56
- ): void {
57
- this.senderKeyStates.length = 0
58
- this.senderKeyStates.push(new SenderKeyState(id, iteration, chainKey, keyPair))
59
- }
60
-
61
- public serialize(): SenderKeyStateStructure[] {
62
- return this.senderKeyStates.map(state => state.getStructure())
63
- }
64
- static deserialize(data: Uint8Array): SenderKeyRecord {
65
- const str = Buffer.from(data).toString('utf-8')
66
- const parsed = JSON.parse(str, BufferJSON.reviver)
67
- return new SenderKeyRecord(parsed)
68
- }
69
- }
@@ -1,134 +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 class SenderKeyState {
27
- private readonly MAX_MESSAGE_KEYS = 2000
28
- private readonly senderKeyStateStructure: SenderKeyStateStructure
29
-
30
- constructor(
31
- id?: number | null,
32
- iteration?: number | null,
33
- chainKey?: Uint8Array | null | string,
34
- signatureKeyPair?: { public: Uint8Array | string; private: Uint8Array | string } | null,
35
- signatureKeyPublic?: Uint8Array | string | null,
36
- signatureKeyPrivate?: Uint8Array | string | null,
37
- senderKeyStateStructure?: SenderKeyStateStructure | null
38
- ) {
39
- if (senderKeyStateStructure) {
40
- this.senderKeyStateStructure = {
41
- ...senderKeyStateStructure,
42
- senderMessageKeys: Array.isArray(senderKeyStateStructure.senderMessageKeys)
43
- ? senderKeyStateStructure.senderMessageKeys
44
- : []
45
- }
46
- } else {
47
- if (signatureKeyPair) {
48
- signatureKeyPublic = signatureKeyPair.public
49
- signatureKeyPrivate = signatureKeyPair.private
50
- }
51
-
52
- this.senderKeyStateStructure = {
53
- senderKeyId: id || 0,
54
- senderChainKey: {
55
- iteration: iteration || 0,
56
- seed: Buffer.from(chainKey || [])
57
- },
58
- senderSigningKey: {
59
- public: Buffer.from(signatureKeyPublic || []),
60
- private: Buffer.from(signatureKeyPrivate || [])
61
- },
62
- senderMessageKeys: []
63
- }
64
- }
65
- }
66
-
67
- public getKeyId(): number {
68
- return this.senderKeyStateStructure.senderKeyId
69
- }
70
-
71
- public getSenderChainKey(): SenderChainKey {
72
- return new SenderChainKey(
73
- this.senderKeyStateStructure.senderChainKey.iteration,
74
- this.senderKeyStateStructure.senderChainKey.seed
75
- )
76
- }
77
-
78
- public setSenderChainKey(chainKey: SenderChainKey): void {
79
- this.senderKeyStateStructure.senderChainKey = {
80
- iteration: chainKey.getIteration(),
81
- seed: chainKey.getSeed()
82
- }
83
- }
84
-
85
- public getSigningKeyPublic(): Buffer {
86
- const publicKey = Buffer.from(this.senderKeyStateStructure.senderSigningKey.public)
87
-
88
- if (publicKey.length === 32) {
89
- const fixed = Buffer.alloc(33)
90
- fixed[0] = 0x05
91
- publicKey.copy(fixed, 1)
92
- return fixed
93
- }
94
-
95
- return publicKey
96
- }
97
-
98
- public getSigningKeyPrivate(): Buffer | undefined {
99
- const privateKey = this.senderKeyStateStructure.senderSigningKey.private
100
-
101
- return Buffer.from(privateKey || [])
102
- }
103
-
104
- public hasSenderMessageKey(iteration: number): boolean {
105
- return this.senderKeyStateStructure.senderMessageKeys.some(key => key.iteration === iteration)
106
- }
107
-
108
- public addSenderMessageKey(senderMessageKey: SenderMessageKey): void {
109
- this.senderKeyStateStructure.senderMessageKeys.push({
110
- iteration: senderMessageKey.getIteration(),
111
- seed: senderMessageKey.getSeed()
112
- })
113
-
114
- if (this.senderKeyStateStructure.senderMessageKeys.length > this.MAX_MESSAGE_KEYS) {
115
- this.senderKeyStateStructure.senderMessageKeys.shift()
116
- }
117
- }
118
-
119
- public removeSenderMessageKey(iteration: number): SenderMessageKey | null {
120
- const index = this.senderKeyStateStructure.senderMessageKeys.findIndex(key => key.iteration === iteration)
121
-
122
- if (index !== -1) {
123
- const messageKey = this.senderKeyStateStructure.senderMessageKeys[index]!
124
- this.senderKeyStateStructure.senderMessageKeys.splice(index, 1)
125
- return new SenderMessageKey(messageKey.iteration, messageKey.seed)
126
- }
127
-
128
- return null
129
- }
130
-
131
- public getStructure(): SenderKeyStateStructure {
132
- return this.senderKeyStateStructure
133
- }
134
- }
@@ -1,36 +0,0 @@
1
- import { deriveSecrets } from 'libsignal/src/crypto'
2
-
3
- export class SenderMessageKey {
4
- private readonly iteration: number
5
- private readonly iv: Uint8Array
6
- private readonly cipherKey: Uint8Array
7
- private readonly seed: Uint8Array
8
-
9
- constructor(iteration: number, seed: Uint8Array) {
10
- const derivative = deriveSecrets(seed, Buffer.alloc(32), Buffer.from('WhisperGroup'))
11
- const keys = new Uint8Array(32)
12
- keys.set(new Uint8Array(derivative[0].slice(16)))
13
- keys.set(new Uint8Array(derivative[1].slice(0, 16)), 16)
14
-
15
- this.iv = Buffer.from(derivative[0].slice(0, 16))
16
- this.cipherKey = Buffer.from(keys.buffer)
17
- this.iteration = iteration
18
- this.seed = seed
19
- }
20
-
21
- public getIteration(): number {
22
- return this.iteration
23
- }
24
-
25
- public getIv(): Uint8Array {
26
- return this.iv
27
- }
28
-
29
- public getCipherKey(): Uint8Array {
30
- return this.cipherKey
31
- }
32
-
33
- public getSeed(): Uint8Array {
34
- return this.seed
35
- }
36
- }