@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,47 +0,0 @@
1
- import { jest } from '@jest/globals'
2
- import P from 'pino'
3
- import { LIDMappingStore } from '../../Signal/lid-mapping'
4
- import type { LIDMapping, SignalDataTypeMap, SignalKeyStoreWithTransaction } from '../../Types'
5
-
6
- const HOSTED_DEVICE_ID = 99
7
-
8
- const mockKeys: jest.Mocked<SignalKeyStoreWithTransaction> = {
9
- get: jest.fn<SignalKeyStoreWithTransaction['get']>() as any,
10
- set: jest.fn<SignalKeyStoreWithTransaction['set']>(),
11
- transaction: jest.fn<SignalKeyStoreWithTransaction['transaction']>(async (work: () => any) => await work()) as any,
12
- isInTransaction: jest.fn<SignalKeyStoreWithTransaction['isInTransaction']>()
13
- }
14
- const logger = P({ level: 'silent' })
15
-
16
- describe('LIDMappingStore', () => {
17
- const mockPnToLIDFunc = jest.fn<(jids: string[]) => Promise<LIDMapping[] | undefined>>()
18
- let lidMappingStore: LIDMappingStore
19
-
20
- beforeEach(() => {
21
- jest.clearAllMocks()
22
- lidMappingStore = new LIDMappingStore(mockKeys, logger, mockPnToLIDFunc)
23
- })
24
-
25
- describe('getPNForLID', () => {
26
- it('should correctly map a standard LID with a hosted device ID back to a standard PN with a hosted device', async () => {
27
- const lidWithHostedDevice = `12345:${HOSTED_DEVICE_ID}@lid`
28
- const pnUser = '54321'
29
-
30
- // @ts-ignore
31
- mockKeys.get.mockResolvedValue({ [`12345_reverse`]: pnUser } as SignalDataTypeMap['lid-mapping'])
32
-
33
- const result = await lidMappingStore.getPNForLID(lidWithHostedDevice)
34
- expect(result).toBe(`${pnUser}:${HOSTED_DEVICE_ID}@s.whatsapp.net`)
35
- })
36
-
37
- it('should return null if no reverse mapping is found', async () => {
38
- const lid = 'nonexistent@lid'
39
-
40
- // @ts-ignore
41
- mockKeys.get.mockResolvedValue({} as SignalDataTypeMap['lid-mapping']) // Simulate not found in DB
42
-
43
- const result = await lidMappingStore.getPNForLID(lid)
44
- expect(result).toBeNull()
45
- })
46
- })
47
- })
@@ -1,207 +0,0 @@
1
- import NodeCache from '@cacheable/node-cache'
2
- import { jest } from '@jest/globals'
3
- import P from 'pino'
4
- import { handleIdentityChange, type IdentityChangeContext } from '../../Utils/identity-change-handler'
5
- import { type BinaryNode } from '../../WABinary'
6
-
7
- const logger = P({ level: 'silent' })
8
-
9
- type ValidateSessionFn = (jid: string) => Promise<{ exists: boolean; reason?: string }>
10
- type AssertSessionsFn = (jids: string[], force?: boolean) => Promise<boolean>
11
-
12
- describe('Identity Change Handling', () => {
13
- let mockValidateSession: jest.Mock<ValidateSessionFn>
14
- let mockAssertSessions: jest.Mock<AssertSessionsFn>
15
- let identityAssertDebounce: NodeCache<boolean>
16
- let mockMeId: string
17
- let mockMeLid: string | undefined
18
-
19
- function createIdentityChangeNode(from: string, offline?: string): BinaryNode {
20
- return {
21
- tag: 'notification',
22
- attrs: {
23
- from,
24
- type: 'encrypt',
25
- ...(offline !== undefined ? { offline } : {})
26
- },
27
- content: [
28
- {
29
- tag: 'identity',
30
- attrs: {},
31
- content: Buffer.from('test-identity-key')
32
- }
33
- ]
34
- }
35
- }
36
-
37
- function createContext(): IdentityChangeContext {
38
- return {
39
- meId: mockMeId,
40
- meLid: mockMeLid,
41
- validateSession: mockValidateSession,
42
- assertSessions: mockAssertSessions,
43
- debounceCache: identityAssertDebounce,
44
- logger
45
- }
46
- }
47
-
48
- beforeEach(() => {
49
- jest.clearAllMocks()
50
- mockValidateSession = jest.fn()
51
- mockAssertSessions = jest.fn()
52
- identityAssertDebounce = new NodeCache<boolean>({ stdTTL: 5, useClones: false })
53
- mockMeId = 'myuser@s.whatsapp.net'
54
- mockMeLid = 'mylid@lid'
55
- })
56
-
57
- describe('Core Checks', () => {
58
- it('should skip companion devices (device > 0)', async () => {
59
- const node = createIdentityChangeNode('user:5@s.whatsapp.net')
60
- const result = await handleIdentityChange(node, createContext())
61
-
62
- expect(mockValidateSession).not.toHaveBeenCalled()
63
- expect(result.action).toBe('skipped_companion_device')
64
- })
65
-
66
- it('should process primary device (device 0 or undefined)', async () => {
67
- mockValidateSession.mockResolvedValue({ exists: true })
68
- mockAssertSessions.mockResolvedValue(true)
69
-
70
- const node = createIdentityChangeNode('user@s.whatsapp.net')
71
- const result = await handleIdentityChange(node, createContext())
72
-
73
- expect(result.action).toBe('session_refreshed')
74
- })
75
-
76
- it('should skip self-primary identity (PN match)', async () => {
77
- const node = createIdentityChangeNode('myuser@s.whatsapp.net')
78
- const result = await handleIdentityChange(node, createContext())
79
-
80
- expect(mockValidateSession).not.toHaveBeenCalled()
81
- expect(result.action).toBe('skipped_self_primary')
82
- })
83
-
84
- it('should skip self-primary identity (LID match)', async () => {
85
- const node = createIdentityChangeNode('mylid@lid')
86
- const result = await handleIdentityChange(node, createContext())
87
-
88
- expect(mockValidateSession).not.toHaveBeenCalled()
89
- expect(result.action).toBe('skipped_self_primary')
90
- })
91
-
92
- it('should skip when no existing session', async () => {
93
- mockValidateSession.mockResolvedValue({ exists: false })
94
-
95
- const node = createIdentityChangeNode('user@s.whatsapp.net')
96
- const result = await handleIdentityChange(node, createContext())
97
-
98
- expect(mockAssertSessions).not.toHaveBeenCalled()
99
- expect(result.action).toBe('skipped_no_session')
100
- })
101
-
102
- it('should skip session refresh during offline processing', async () => {
103
- mockValidateSession.mockResolvedValue({ exists: true })
104
-
105
- const node = createIdentityChangeNode('user@s.whatsapp.net', '0')
106
- const result = await handleIdentityChange(node, createContext())
107
-
108
- expect(mockAssertSessions).not.toHaveBeenCalled()
109
- expect(result.action).toBe('skipped_offline')
110
- })
111
-
112
- it('should refresh session when online with existing session', async () => {
113
- mockValidateSession.mockResolvedValue({ exists: true })
114
- mockAssertSessions.mockResolvedValue(true)
115
-
116
- const node = createIdentityChangeNode('user@s.whatsapp.net')
117
- const result = await handleIdentityChange(node, createContext())
118
-
119
- expect(mockAssertSessions).toHaveBeenCalledWith(['user@s.whatsapp.net'], true)
120
- expect(result.action).toBe('session_refreshed')
121
- })
122
- })
123
-
124
- describe('Debounce', () => {
125
- it('should debounce multiple identity changes for the same JID', async () => {
126
- mockValidateSession.mockResolvedValue({ exists: true })
127
- mockAssertSessions.mockResolvedValue(true)
128
-
129
- const node = createIdentityChangeNode('user@s.whatsapp.net')
130
-
131
- const result1 = await handleIdentityChange(node, createContext())
132
- expect(result1.action).toBe('session_refreshed')
133
-
134
- const result2 = await handleIdentityChange(node, createContext())
135
- expect(result2.action).toBe('debounced')
136
- expect(mockAssertSessions).toHaveBeenCalledTimes(1)
137
- })
138
-
139
- it('should allow different JIDs to process independently', async () => {
140
- mockValidateSession.mockResolvedValue({ exists: true })
141
- mockAssertSessions.mockResolvedValue(true)
142
-
143
- const result1 = await handleIdentityChange(createIdentityChangeNode('user1@s.whatsapp.net'), createContext())
144
- const result2 = await handleIdentityChange(createIdentityChangeNode('user2@s.whatsapp.net'), createContext())
145
-
146
- expect(result1.action).toBe('session_refreshed')
147
- expect(result2.action).toBe('session_refreshed')
148
- expect(mockAssertSessions).toHaveBeenCalledTimes(2)
149
- })
150
- })
151
-
152
- describe('Error Handling', () => {
153
- it('should handle assertSessions failure gracefully', async () => {
154
- mockValidateSession.mockResolvedValue({ exists: true })
155
- const testError = new Error('Session assertion failed')
156
- mockAssertSessions.mockRejectedValue(testError)
157
-
158
- const node = createIdentityChangeNode('user@s.whatsapp.net')
159
- const result = await handleIdentityChange(node, createContext())
160
-
161
- expect(result.action).toBe('session_refresh_failed')
162
- expect((result as { error: unknown }).error).toBe(testError)
163
- })
164
-
165
- it('should propagate validateSession errors', async () => {
166
- mockValidateSession.mockRejectedValue(new Error('Database error'))
167
-
168
- const node = createIdentityChangeNode('user@s.whatsapp.net')
169
- await expect(handleIdentityChange(node, createContext())).rejects.toThrow('Database error')
170
- })
171
- })
172
-
173
- describe('Edge Cases', () => {
174
- it('should return invalid_notification when from is missing', async () => {
175
- const node: BinaryNode = {
176
- tag: 'notification',
177
- attrs: { type: 'encrypt' },
178
- content: [{ tag: 'identity', attrs: {}, content: Buffer.from('key') }]
179
- }
180
-
181
- const result = await handleIdentityChange(node, createContext())
182
- expect(result.action).toBe('invalid_notification')
183
- })
184
-
185
- it('should return no_identity_node when identity child is missing', async () => {
186
- const node: BinaryNode = {
187
- tag: 'notification',
188
- attrs: { from: 'user@s.whatsapp.net', type: 'encrypt' },
189
- content: []
190
- }
191
-
192
- const result = await handleIdentityChange(node, createContext())
193
- expect(result.action).toBe('no_identity_node')
194
- })
195
-
196
- it('should handle LID JIDs correctly', async () => {
197
- mockValidateSession.mockResolvedValue({ exists: true })
198
- mockAssertSessions.mockResolvedValue(true)
199
-
200
- const node = createIdentityChangeNode('12345@lid')
201
- const result = await handleIdentityChange(node, createContext())
202
-
203
- expect(mockValidateSession).toHaveBeenCalledWith('12345@lid')
204
- expect(result.action).toBe('session_refreshed')
205
- })
206
- })
207
- })
@@ -1,47 +0,0 @@
1
- import { jest } from '@jest/globals'
2
- import { promises as fs } from 'fs'
3
- import { tmpdir } from 'os'
4
- import { join } from 'path'
5
- import { useMultiFileAuthState } from '../..'
6
-
7
- /**
8
- * Creates a temporary, isolated authentication state for tests.
9
- * This prevents tests from interfering with each other or with a real session.
10
- * @returns An object with the authentication state and a cleanup function.
11
- */
12
- export const makeSession = async () => {
13
- // Create a temporary directory for the session files
14
- const dir = join(tmpdir(), `baileys-test-session-${Date.now()}`)
15
- await fs.mkdir(dir, { recursive: true })
16
-
17
- // Use the multi-file auth state with the temporary directory
18
- const { state, saveCreds } = await useMultiFileAuthState(dir)
19
-
20
- return {
21
- state,
22
- saveCreds,
23
- /**
24
- * Cleans up the temporary session files.
25
- * Call this at the end of your test.
26
- */
27
- clear: async () => {
28
- await fs.rm(dir, { recursive: true, force: true })
29
- }
30
- }
31
- }
32
-
33
- export const mockWebSocket = () => {
34
- jest.mock('../../Socket/Client/websocket', () => {
35
- return {
36
- WebSocketClient: jest.fn().mockImplementation(() => ({
37
- connect: jest.fn(() => Promise.resolve()),
38
- close: jest.fn(),
39
- on: jest.fn(),
40
- off: jest.fn(),
41
- emit: jest.fn(),
42
- send: jest.fn(),
43
- isOpen: true
44
- }))
45
- }
46
- })
47
- }
@@ -1,70 +0,0 @@
1
- import { BufferJSON } from '../../Utils/generics'
2
-
3
- describe('BufferJSON', () => {
4
- const originalObject = {
5
- id: 1,
6
- key: Buffer.from([1, 2, 3, 4, 5]),
7
- nested: {
8
- data: Buffer.from([6, 7, 8])
9
- }
10
- }
11
-
12
- const legacyJsonString = '{"id":1,"key":{"0":1,"1":2,"2":3,"3":4,"4":5},"nested":{"data":{"0":6,"1":7,"2":8}}}'
13
-
14
- it('should correctly perform a round trip (stringify with replacer, parse with reviver)', () => {
15
- const serialized = JSON.stringify(originalObject, BufferJSON.replacer)
16
-
17
- expect(serialized).toContain('"type":"Buffer"')
18
- expect(serialized).not.toContain('"data":[1,2,3,4,5]')
19
-
20
- const revived = JSON.parse(serialized, BufferJSON.reviver)
21
-
22
- expect(Buffer.isBuffer(revived.key)).toBe(true)
23
- expect(Buffer.isBuffer(revived.nested.data)).toBe(true)
24
- expect(revived.key).toEqual(originalObject.key)
25
- expect(revived).toEqual(originalObject)
26
- })
27
-
28
- it('should correctly revive a legacy JSON string with object-like buffers', () => {
29
- const revived = JSON.parse(legacyJsonString, BufferJSON.reviver)
30
-
31
- expect(Buffer.isBuffer(revived.key)).toBe(true)
32
- expect(Buffer.isBuffer(revived.nested.data)).toBe(true)
33
- expect(revived.key).toEqual(originalObject.key)
34
- expect(revived.nested.data).toEqual(originalObject.nested.data)
35
- expect(revived.id).toEqual(originalObject.id)
36
- })
37
-
38
- it('should not corrupt legitimate objects that are not buffers', () => {
39
- const legitimateProtoObject = {
40
- '0': 'some-value',
41
- '1': 'another-value'
42
- }
43
- const jsonString = JSON.stringify(legitimateProtoObject)
44
- const revived = JSON.parse(jsonString, BufferJSON.reviver)
45
-
46
- expect(Buffer.isBuffer(revived)).toBe(false)
47
- expect(revived).toEqual(legitimateProtoObject)
48
- })
49
-
50
- it('should not convert other objects or null values', () => {
51
- const otherObject = {
52
- a: 1,
53
- b: 2,
54
- c: null,
55
- d: { '0': 1, foo: 'bar' }
56
- }
57
- const jsonString = JSON.stringify(otherObject)
58
- const revived = JSON.parse(jsonString, BufferJSON.reviver)
59
-
60
- expect(Buffer.isBuffer(revived.a)).toBe(false)
61
- expect(revived.c).toBeNull()
62
- expect(Buffer.isBuffer(revived.d)).toBe(false)
63
- expect(revived).toEqual(otherObject)
64
- })
65
-
66
- it('should correctly handle an empty object', () => {
67
- const revived = JSON.parse('{}', BufferJSON.reviver)
68
- expect(revived).toEqual({})
69
- })
70
- })