@skycodee/baileys 8.0.4 → 8.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/WAProto/WAProto.proto +352 -520
- package/WAProto/index.js +558 -4154
- package/lib/Defaults/index.js +123 -0
- package/lib/Defaults/index.js.bak +123 -0
- package/lib/KeyDB/BinarySearch.js +20 -0
- package/lib/KeyDB/KeyedDB.js +167 -0
- package/lib/KeyDB/index.js +4 -0
- package/lib/Signal/Group/ciphertext-message.js +13 -0
- package/lib/Signal/Group/group-session-builder.js +32 -0
- package/lib/Signal/Group/group_cipher.js +84 -0
- package/lib/Signal/Group/index.js +13 -0
- package/lib/Signal/Group/keyhelper.js +20 -0
- package/lib/Signal/Group/sender-chain-key.js +28 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +65 -0
- package/lib/Signal/Group/sender-key-message.js +68 -0
- package/lib/Signal/Group/sender-key-name.js +52 -0
- package/lib/Signal/Group/sender-key-record.js +43 -0
- package/lib/Signal/Group/sender-key-state.js +86 -0
- package/lib/Signal/Group/sender-message-key.js +28 -0
- package/lib/Signal/libsignal.js +324 -0
- package/lib/Signal/lid-mapping.js +155 -0
- package/lib/Socket/Client/index.js +4 -0
- package/lib/Socket/Client/types.js +13 -0
- package/lib/Socket/Client/websocket.js +52 -0
- package/lib/Socket/Client/websocket.js.bak +53 -0
- package/lib/Socket/business.js +377 -0
- package/lib/Socket/chats.js +885 -0
- package/lib/Socket/communities.js +413 -0
- package/lib/Socket/groups.js +312 -0
- package/lib/Socket/index.js +16 -0
- package/lib/Socket/messages-recv.js +1163 -0
- package/lib/Socket/messages-send.js +1100 -0
- package/lib/Socket/mex.js +45 -0
- package/lib/Socket/newsletter.js +247 -0
- package/lib/Socket/socket.js +820 -0
- package/lib/Store/index.js +6 -0
- package/lib/Store/make-cache-manager-store.js +75 -0
- package/lib/Store/make-in-memory-store.js +290 -0
- package/lib/Store/make-ordered-dictionary.js +79 -0
- package/lib/Store/object-repository.js +25 -0
- package/lib/Types/Auth.js +3 -0
- package/lib/Types/Bussines.js +3 -0
- package/lib/Types/Call.js +3 -0
- package/lib/Types/Chat.js +9 -0
- package/lib/Types/Contact.js +3 -0
- package/lib/Types/Events.js +3 -0
- package/lib/Types/GroupMetadata.js +3 -0
- package/lib/Types/Label.js +25 -0
- package/lib/Types/LabelAssociation.js +7 -0
- package/lib/Types/Message.js +12 -0
- package/lib/Types/Newsletter.js +33 -0
- package/lib/Types/Newsletter.js.bak +33 -0
- package/lib/Types/Product.js +3 -0
- package/lib/Types/Signal.js +3 -0
- package/lib/Types/Socket.js +4 -0
- package/lib/Types/State.js +11 -0
- package/lib/Types/USync.js +3 -0
- package/lib/Types/index.js +28 -0
- package/lib/Utils/auth-utils.js +219 -0
- package/lib/Utils/baileys-event-stream.js +44 -0
- package/lib/Utils/browser-utils.js +25 -0
- package/lib/Utils/business.js +233 -0
- package/lib/Utils/chat-utils.js +752 -0
- package/lib/Utils/crypto.js +130 -0
- package/lib/Utils/decode-wa-message.js +267 -0
- package/lib/Utils/event-buffer.js +528 -0
- package/lib/Utils/generics.js +355 -0
- package/lib/Utils/history.js +87 -0
- package/lib/Utils/index.js +21 -0
- package/lib/Utils/link-preview.js +81 -0
- package/lib/Utils/logger.js +5 -0
- package/lib/Utils/lt-hash.js +45 -0
- package/lib/Utils/make-mutex.js +36 -0
- package/lib/Utils/message-retry-manager.js +113 -0
- package/lib/Utils/messages-media.js +627 -0
- package/lib/Utils/messages.js +909 -0
- package/lib/Utils/noise-handler.js +144 -0
- package/lib/Utils/pre-key-manager.js +85 -0
- package/lib/Utils/process-message.js +341 -0
- package/lib/Utils/signal.js +161 -0
- package/lib/Utils/use-multi-file-auth-state.js +111 -0
- package/lib/Utils/validate-connection.js +200 -0
- package/lib/WABinary/constants.js +1303 -0
- package/lib/WABinary/decode.js +240 -0
- package/lib/WABinary/encode.js +218 -0
- package/lib/WABinary/generic-utils.js +189 -0
- package/lib/WABinary/index.js +7 -0
- package/lib/WABinary/jid-utils.js +93 -0
- package/lib/WABinary/types.js +3 -0
- package/lib/WAM/BinaryInfo.js +11 -0
- package/lib/WAM/constants.js +22853 -0
- package/lib/WAM/encode.js +154 -0
- package/lib/WAM/index.js +5 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +30 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +53 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +29 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +39 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +30 -0
- package/lib/WAUSync/Protocols/index.js +6 -0
- package/lib/WAUSync/USyncQuery.js +90 -0
- package/lib/WAUSync/USyncUser.js +24 -0
- package/lib/WAUSync/index.js +5 -0
- package/lib/index.js +21 -0
- package/package.json +84 -57
- package/README.md +0 -1312
- package/WAProto/GenerateStatics.sh +0 -3
- package/WAProto/fix-imports.js +0 -81
- package/WAProto/index.d.ts +0 -14017
- package/engine-requirements.js +0 -10
- package/src/Defaults/baileys-version.json +0 -1
- package/src/Defaults/index.ts +0 -149
- package/src/Signal/Group/ciphertext-message.ts +0 -9
- package/src/Signal/Group/group-session-builder.ts +0 -56
- package/src/Signal/Group/group_cipher.ts +0 -117
- package/src/Signal/Group/index.ts +0 -11
- package/src/Signal/Group/keyhelper.ts +0 -28
- package/src/Signal/Group/sender-chain-key.ts +0 -34
- package/src/Signal/Group/sender-key-distribution-message.ts +0 -95
- package/src/Signal/Group/sender-key-message.ts +0 -96
- package/src/Signal/Group/sender-key-name.ts +0 -66
- package/src/Signal/Group/sender-key-record.ts +0 -69
- package/src/Signal/Group/sender-key-state.ts +0 -134
- package/src/Signal/Group/sender-message-key.ts +0 -36
- package/src/Signal/libsignal.ts +0 -521
- package/src/Signal/lid-mapping.ts +0 -328
- package/src/Socket/Client/index.ts +0 -2
- package/src/Socket/Client/types.ts +0 -22
- package/src/Socket/Client/websocket.ts +0 -63
- package/src/Socket/business.ts +0 -424
- package/src/Socket/chats.ts +0 -1272
- package/src/Socket/communities.ts +0 -477
- package/src/Socket/groups.ts +0 -361
- package/src/Socket/index.ts +0 -15
- package/src/Socket/messages-recv.ts +0 -1668
- package/src/Socket/messages-send.ts +0 -1296
- package/src/Socket/mex.ts +0 -58
- package/src/Socket/newsletter.ts +0 -229
- package/src/Socket/socket.ts +0 -1184
- package/src/Types/Auth.ts +0 -116
- package/src/Types/Bussines.ts +0 -20
- package/src/Types/Call.ts +0 -15
- package/src/Types/Chat.ts +0 -138
- package/src/Types/Contact.ts +0 -24
- package/src/Types/Events.ts +0 -159
- package/src/Types/GroupMetadata.ts +0 -70
- package/src/Types/Label.ts +0 -48
- package/src/Types/LabelAssociation.ts +0 -35
- package/src/Types/Message.ts +0 -380
- package/src/Types/Newsletter.ts +0 -98
- package/src/Types/Product.ts +0 -85
- package/src/Types/Signal.ts +0 -76
- package/src/Types/Socket.ts +0 -150
- package/src/Types/State.ts +0 -43
- package/src/Types/USync.ts +0 -27
- package/src/Types/globals.d.ts +0 -8
- package/src/Types/index.ts +0 -67
- package/src/Utils/auth-utils.ts +0 -368
- package/src/Utils/browser-utils.ts +0 -31
- package/src/Utils/business.ts +0 -286
- package/src/Utils/chat-utils.ts +0 -974
- package/src/Utils/crypto.ts +0 -147
- package/src/Utils/decode-wa-message.ts +0 -355
- package/src/Utils/event-buffer.ts +0 -692
- package/src/Utils/generics.ts +0 -474
- package/src/Utils/history.ts +0 -161
- package/src/Utils/identity-change-handler.ts +0 -83
- package/src/Utils/index.ts +0 -19
- package/src/Utils/link-preview.ts +0 -111
- package/src/Utils/logger.ts +0 -13
- package/src/Utils/lt-hash.ts +0 -8
- package/src/Utils/make-mutex.ts +0 -42
- package/src/Utils/message-retry-manager.ts +0 -295
- package/src/Utils/messages-media.ts +0 -984
- package/src/Utils/messages.ts +0 -1097
- package/src/Utils/noise-handler.ts +0 -268
- package/src/Utils/pre-key-manager.ts +0 -126
- package/src/Utils/process-message.ts +0 -670
- package/src/Utils/reporting-utils.ts +0 -344
- package/src/Utils/signal.ts +0 -214
- package/src/Utils/sync-action-utils.ts +0 -74
- package/src/Utils/tc-token-utils.ts +0 -34
- package/src/Utils/use-multi-file-auth-state.ts +0 -136
- package/src/Utils/validate-connection.ts +0 -253
- package/src/WABinary/constants.ts +0 -1305
- package/src/WABinary/decode.ts +0 -308
- package/src/WABinary/encode.ts +0 -258
- package/src/WABinary/generic-utils.ts +0 -141
- package/src/WABinary/index.ts +0 -5
- package/src/WABinary/jid-utils.ts +0 -128
- package/src/WABinary/types.ts +0 -17
- package/src/WAM/BinaryInfo.ts +0 -12
- package/src/WAM/constants.ts +0 -22889
- package/src/WAM/encode.ts +0 -169
- package/src/WAM/index.ts +0 -3
- package/src/WAUSync/Protocols/USyncContactProtocol.ts +0 -32
- package/src/WAUSync/Protocols/USyncDeviceProtocol.ts +0 -78
- package/src/WAUSync/Protocols/USyncDisappearingModeProtocol.ts +0 -35
- package/src/WAUSync/Protocols/USyncStatusProtocol.ts +0 -44
- package/src/WAUSync/Protocols/UsyncBotProfileProtocol.ts +0 -76
- package/src/WAUSync/Protocols/UsyncLIDProtocol.ts +0 -33
- package/src/WAUSync/Protocols/index.ts +0 -4
- package/src/WAUSync/USyncQuery.ts +0 -133
- package/src/WAUSync/USyncUser.ts +0 -32
- package/src/WAUSync/index.ts +0 -3
- package/src/__tests__/Signal/Group/sender-key-state-regression.test.ts +0 -22
- package/src/__tests__/Signal/lid-mapping.test.ts +0 -47
- package/src/__tests__/Socket/identity-change-handling.test.ts +0 -207
- package/src/__tests__/TestUtils/session.ts +0 -47
- package/src/__tests__/Utils/generics.test.ts +0 -70
- package/src/__tests__/Utils/history.test.ts +0 -362
- package/src/__tests__/Utils/messages-media.test.ts +0 -405
- package/src/__tests__/Utils/noise-handler.test.ts +0 -339
- package/src/__tests__/Utils/process-message.test.ts +0 -138
- package/src/__tests__/Utils/process-sync-action.test.ts +0 -359
- package/src/__tests__/Utils/reporting-utils.test.ts +0 -160
- package/src/__tests__/Utils/signal.test.ts +0 -69
- package/src/__tests__/Utils/sync-action-utils.test.ts +0 -183
- package/src/__tests__/binary/connection-deadlock.test.ts +0 -54
- package/src/__tests__/e2e/fetch-wa-web-version.test-e2e.ts +0 -60
- package/src/__tests__/e2e/send-receive-message.test-e2e.ts +0 -644
- package/src/__tests__/proto-tojson-long.test.ts +0 -31
- package/src/index.ts +0 -13
|
@@ -1,359 +0,0 @@
|
|
|
1
|
-
import { jest } from '@jest/globals'
|
|
2
|
-
import { proto } from '../../../WAProto/index.js'
|
|
3
|
-
import type { BaileysEventEmitter, ChatMutation, Contact } from '../../Types'
|
|
4
|
-
import { LabelAssociationType } from '../../Types/LabelAssociation'
|
|
5
|
-
import { processSyncAction } from '../../Utils/chat-utils'
|
|
6
|
-
import type { ILogger } from '../../Utils/logger'
|
|
7
|
-
|
|
8
|
-
const createMockEventEmitter = () => {
|
|
9
|
-
const emittedEvents: Array<{ event: string; data: unknown }> = []
|
|
10
|
-
const emit = jest.fn((event: string, data: unknown) => {
|
|
11
|
-
emittedEvents.push({ event, data })
|
|
12
|
-
return true
|
|
13
|
-
})
|
|
14
|
-
return {
|
|
15
|
-
emit,
|
|
16
|
-
emittedEvents,
|
|
17
|
-
on: jest.fn(),
|
|
18
|
-
off: jest.fn(),
|
|
19
|
-
removeAllListeners: jest.fn()
|
|
20
|
-
} as unknown as BaileysEventEmitter & { emittedEvents: typeof emittedEvents }
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const createMockLogger = (): ILogger =>
|
|
24
|
-
({
|
|
25
|
-
warn: jest.fn(),
|
|
26
|
-
info: jest.fn(),
|
|
27
|
-
debug: jest.fn(),
|
|
28
|
-
error: jest.fn(),
|
|
29
|
-
trace: jest.fn(),
|
|
30
|
-
child: jest.fn(function (this: ILogger) {
|
|
31
|
-
return this
|
|
32
|
-
}),
|
|
33
|
-
level: 'silent'
|
|
34
|
-
}) as unknown as ILogger
|
|
35
|
-
|
|
36
|
-
const createSyncAction = (
|
|
37
|
-
action: proto.ISyncActionValue,
|
|
38
|
-
index: string[] = ['type', 'id', 'msgId', '0']
|
|
39
|
-
): ChatMutation => ({
|
|
40
|
-
syncAction: { value: action },
|
|
41
|
-
index
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
const mockMe: Contact = { id: 'me@s.whatsapp.net', name: 'Test User' }
|
|
45
|
-
|
|
46
|
-
describe('processSyncAction', () => {
|
|
47
|
-
let ev: ReturnType<typeof createMockEventEmitter>
|
|
48
|
-
let logger: ILogger
|
|
49
|
-
|
|
50
|
-
beforeEach(() => {
|
|
51
|
-
jest.clearAllMocks()
|
|
52
|
-
ev = createMockEventEmitter()
|
|
53
|
-
logger = createMockLogger()
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
describe('muteAction', () => {
|
|
57
|
-
it('emits chats.update with muteEndTime when muted', () => {
|
|
58
|
-
const syncAction = createSyncAction({ muteAction: { muted: true, muteEndTimestamp: 1700000000 } }, [
|
|
59
|
-
'mute',
|
|
60
|
-
'chat123@s.whatsapp.net'
|
|
61
|
-
])
|
|
62
|
-
processSyncAction(syncAction, ev, mockMe, undefined, logger)
|
|
63
|
-
expect(ev.emit).toHaveBeenCalledWith(
|
|
64
|
-
'chats.update',
|
|
65
|
-
expect.arrayContaining([expect.objectContaining({ id: 'chat123@s.whatsapp.net', muteEndTime: 1700000000 })])
|
|
66
|
-
)
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
it('emits null muteEndTime when unmuted', () => {
|
|
70
|
-
const syncAction = createSyncAction({ muteAction: { muted: false, muteEndTimestamp: 0 } }, [
|
|
71
|
-
'mute',
|
|
72
|
-
'chat123@s.whatsapp.net'
|
|
73
|
-
])
|
|
74
|
-
processSyncAction(syncAction, ev, mockMe, undefined, logger)
|
|
75
|
-
expect(ev.emit).toHaveBeenCalledWith(
|
|
76
|
-
'chats.update',
|
|
77
|
-
expect.arrayContaining([expect.objectContaining({ muteEndTime: null })])
|
|
78
|
-
)
|
|
79
|
-
})
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
describe('archiveChatAction', () => {
|
|
83
|
-
it('emits chats.update with archived true/false', () => {
|
|
84
|
-
const archived = createSyncAction({ archiveChatAction: { archived: true } }, ['archive', 'chat@s.whatsapp.net'])
|
|
85
|
-
processSyncAction(archived, ev, mockMe, undefined, logger)
|
|
86
|
-
expect(ev.emit).toHaveBeenCalledWith(
|
|
87
|
-
'chats.update',
|
|
88
|
-
expect.arrayContaining([expect.objectContaining({ archived: true })])
|
|
89
|
-
)
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
it('handles type fallback without archiveChatAction', () => {
|
|
93
|
-
const syncAction = createSyncAction({}, ['archive', 'chat@s.whatsapp.net'])
|
|
94
|
-
processSyncAction(syncAction, ev, mockMe, undefined, logger)
|
|
95
|
-
expect(ev.emit).toHaveBeenCalledWith(
|
|
96
|
-
'chats.update',
|
|
97
|
-
expect.arrayContaining([expect.objectContaining({ archived: true })])
|
|
98
|
-
)
|
|
99
|
-
})
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
describe('markChatAsReadAction', () => {
|
|
103
|
-
it('emits unreadCount 0 when read is true', () => {
|
|
104
|
-
const read = createSyncAction({ markChatAsReadAction: { read: true } }, ['markRead', 'chat@s.whatsapp.net'])
|
|
105
|
-
processSyncAction(read, ev, mockMe, undefined, logger)
|
|
106
|
-
expect(ev.emit).toHaveBeenCalledWith(
|
|
107
|
-
'chats.update',
|
|
108
|
-
expect.arrayContaining([expect.objectContaining({ unreadCount: 0 })])
|
|
109
|
-
)
|
|
110
|
-
})
|
|
111
|
-
|
|
112
|
-
it('emits unreadCount -1 when read is false', () => {
|
|
113
|
-
const unread = createSyncAction({ markChatAsReadAction: { read: false } }, ['markRead', 'chat@s.whatsapp.net'])
|
|
114
|
-
processSyncAction(unread, ev, mockMe, undefined, logger)
|
|
115
|
-
expect(ev.emit).toHaveBeenCalledWith(
|
|
116
|
-
'chats.update',
|
|
117
|
-
expect.arrayContaining([expect.objectContaining({ unreadCount: -1 })])
|
|
118
|
-
)
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
it('emits null unreadCount during initial sync when already read', () => {
|
|
122
|
-
const syncAction = createSyncAction({ markChatAsReadAction: { read: true } }, ['markRead', 'chat@s.whatsapp.net'])
|
|
123
|
-
processSyncAction(syncAction, ev, mockMe, { accountSettings: { unarchiveChats: false } }, logger)
|
|
124
|
-
expect(ev.emit).toHaveBeenCalledWith(
|
|
125
|
-
'chats.update',
|
|
126
|
-
expect.arrayContaining([expect.objectContaining({ unreadCount: null })])
|
|
127
|
-
)
|
|
128
|
-
})
|
|
129
|
-
})
|
|
130
|
-
|
|
131
|
-
describe('deleteMessageForMeAction', () => {
|
|
132
|
-
it('emits messages.delete with correct key', () => {
|
|
133
|
-
const syncAction = createSyncAction({ deleteMessageForMeAction: { deleteMedia: false } }, [
|
|
134
|
-
'deleteMessageForMe',
|
|
135
|
-
'chat@s.whatsapp.net',
|
|
136
|
-
'msg456',
|
|
137
|
-
'1'
|
|
138
|
-
])
|
|
139
|
-
processSyncAction(syncAction, ev, mockMe, undefined, logger)
|
|
140
|
-
expect(ev.emit).toHaveBeenCalledWith('messages.delete', {
|
|
141
|
-
keys: [{ remoteJid: 'chat@s.whatsapp.net', id: 'msg456', fromMe: true }]
|
|
142
|
-
})
|
|
143
|
-
})
|
|
144
|
-
})
|
|
145
|
-
|
|
146
|
-
describe('contactAction', () => {
|
|
147
|
-
it('emits contacts.upsert and lid-mapping.update for PN user with LID', () => {
|
|
148
|
-
const syncAction = createSyncAction({ contactAction: { fullName: 'John', lidJid: '123@lid', pnJid: null } }, [
|
|
149
|
-
'contact',
|
|
150
|
-
'5511999@s.whatsapp.net'
|
|
151
|
-
])
|
|
152
|
-
processSyncAction(syncAction, ev, mockMe, undefined, logger)
|
|
153
|
-
expect(ev.emit).toHaveBeenCalledWith('contacts.upsert', [
|
|
154
|
-
{
|
|
155
|
-
id: '5511999@s.whatsapp.net',
|
|
156
|
-
name: 'John',
|
|
157
|
-
lid: '123@lid',
|
|
158
|
-
phoneNumber: '5511999@s.whatsapp.net'
|
|
159
|
-
}
|
|
160
|
-
])
|
|
161
|
-
expect(ev.emit).toHaveBeenCalledWith('lid-mapping.update', {
|
|
162
|
-
lid: '123@lid',
|
|
163
|
-
pn: '5511999@s.whatsapp.net'
|
|
164
|
-
})
|
|
165
|
-
})
|
|
166
|
-
|
|
167
|
-
it('does not emit events when id is missing', () => {
|
|
168
|
-
const syncAction = createSyncAction({ contactAction: { fullName: 'John', lidJid: '123@lid', pnJid: null } }, [
|
|
169
|
-
'contact',
|
|
170
|
-
''
|
|
171
|
-
])
|
|
172
|
-
processSyncAction(syncAction, ev, mockMe, undefined, logger)
|
|
173
|
-
expect(ev.emittedEvents.filter(e => e.event === 'contacts.upsert')).toHaveLength(0)
|
|
174
|
-
})
|
|
175
|
-
})
|
|
176
|
-
|
|
177
|
-
describe('pushNameSetting', () => {
|
|
178
|
-
it('emits creds.update when name differs', () => {
|
|
179
|
-
const syncAction = createSyncAction({ pushNameSetting: { name: 'New' } }, ['pushName'])
|
|
180
|
-
processSyncAction(syncAction, ev, mockMe, undefined, logger)
|
|
181
|
-
expect(ev.emit).toHaveBeenCalledWith('creds.update', { me: { ...mockMe, name: 'New' } })
|
|
182
|
-
})
|
|
183
|
-
|
|
184
|
-
it('does not emit when name is same or empty', () => {
|
|
185
|
-
const same = createSyncAction({ pushNameSetting: { name: 'Test User' } }, ['pushName'])
|
|
186
|
-
processSyncAction(same, ev, mockMe, undefined, logger)
|
|
187
|
-
expect(ev.emit).not.toHaveBeenCalled()
|
|
188
|
-
})
|
|
189
|
-
})
|
|
190
|
-
|
|
191
|
-
describe('pinAction', () => {
|
|
192
|
-
it('emits chats.update with pinned timestamp or null', () => {
|
|
193
|
-
const syncAction: ChatMutation = {
|
|
194
|
-
syncAction: { value: { pinAction: { pinned: true }, timestamp: 1700000000 } },
|
|
195
|
-
index: ['pin', 'chat@s.whatsapp.net']
|
|
196
|
-
}
|
|
197
|
-
processSyncAction(syncAction, ev, mockMe, undefined, logger)
|
|
198
|
-
expect(ev.emit).toHaveBeenCalledWith(
|
|
199
|
-
'chats.update',
|
|
200
|
-
expect.arrayContaining([expect.objectContaining({ pinned: 1700000000 })])
|
|
201
|
-
)
|
|
202
|
-
})
|
|
203
|
-
})
|
|
204
|
-
|
|
205
|
-
describe('starAction', () => {
|
|
206
|
-
it('emits messages.update with starred value', () => {
|
|
207
|
-
const syncAction = createSyncAction({ starAction: { starred: true } }, [
|
|
208
|
-
'star',
|
|
209
|
-
'chat@s.whatsapp.net',
|
|
210
|
-
'msg',
|
|
211
|
-
'1'
|
|
212
|
-
])
|
|
213
|
-
processSyncAction(syncAction, ev, mockMe, undefined, logger)
|
|
214
|
-
expect(ev.emit).toHaveBeenCalledWith('messages.update', [
|
|
215
|
-
{
|
|
216
|
-
key: { remoteJid: 'chat@s.whatsapp.net', id: 'msg', fromMe: true },
|
|
217
|
-
update: { starred: true }
|
|
218
|
-
}
|
|
219
|
-
])
|
|
220
|
-
})
|
|
221
|
-
})
|
|
222
|
-
|
|
223
|
-
describe('deleteChatAction', () => {
|
|
224
|
-
it('emits chats.delete when not initial sync', () => {
|
|
225
|
-
const syncAction = createSyncAction({ deleteChatAction: { messageRange: null } }, [
|
|
226
|
-
'deleteChat',
|
|
227
|
-
'chat@s.whatsapp.net'
|
|
228
|
-
])
|
|
229
|
-
processSyncAction(syncAction, ev, mockMe, undefined, logger)
|
|
230
|
-
expect(ev.emit).toHaveBeenCalledWith('chats.delete', ['chat@s.whatsapp.net'])
|
|
231
|
-
})
|
|
232
|
-
|
|
233
|
-
it('does NOT emit during initial sync', () => {
|
|
234
|
-
const syncAction = createSyncAction({ deleteChatAction: { messageRange: null } }, [
|
|
235
|
-
'deleteChat',
|
|
236
|
-
'chat@s.whatsapp.net'
|
|
237
|
-
])
|
|
238
|
-
processSyncAction(syncAction, ev, mockMe, { accountSettings: { unarchiveChats: false } }, logger)
|
|
239
|
-
expect(ev.emit).not.toHaveBeenCalled()
|
|
240
|
-
})
|
|
241
|
-
})
|
|
242
|
-
|
|
243
|
-
describe('labelEditAction', () => {
|
|
244
|
-
it('emits labels.edit', () => {
|
|
245
|
-
const syncAction = createSyncAction(
|
|
246
|
-
{ labelEditAction: { name: 'Important', color: 1, deleted: false, predefinedId: 5 } },
|
|
247
|
-
['label', 'label123']
|
|
248
|
-
)
|
|
249
|
-
processSyncAction(syncAction, ev, mockMe, undefined, logger)
|
|
250
|
-
expect(ev.emit).toHaveBeenCalledWith('labels.edit', {
|
|
251
|
-
id: 'label123',
|
|
252
|
-
name: 'Important',
|
|
253
|
-
color: 1,
|
|
254
|
-
deleted: false,
|
|
255
|
-
predefinedId: '5'
|
|
256
|
-
})
|
|
257
|
-
})
|
|
258
|
-
})
|
|
259
|
-
|
|
260
|
-
describe('labelAssociationAction', () => {
|
|
261
|
-
it('emits labels.association for chat label', () => {
|
|
262
|
-
const syncAction = createSyncAction({ labelAssociationAction: { labeled: true } }, [
|
|
263
|
-
LabelAssociationType.Chat,
|
|
264
|
-
'label123',
|
|
265
|
-
'chat@s.whatsapp.net'
|
|
266
|
-
])
|
|
267
|
-
processSyncAction(syncAction, ev, mockMe, undefined, logger)
|
|
268
|
-
expect(ev.emit).toHaveBeenCalledWith('labels.association', {
|
|
269
|
-
type: 'add',
|
|
270
|
-
association: { type: LabelAssociationType.Chat, chatId: 'chat@s.whatsapp.net', labelId: 'label123' }
|
|
271
|
-
})
|
|
272
|
-
})
|
|
273
|
-
|
|
274
|
-
it('emits labels.association for message label', () => {
|
|
275
|
-
const syncAction = createSyncAction({ labelAssociationAction: { labeled: true } }, [
|
|
276
|
-
LabelAssociationType.Message,
|
|
277
|
-
'label123',
|
|
278
|
-
'chat@s.whatsapp.net',
|
|
279
|
-
'msg789'
|
|
280
|
-
])
|
|
281
|
-
processSyncAction(syncAction, ev, mockMe, undefined, logger)
|
|
282
|
-
expect(ev.emit).toHaveBeenCalledWith('labels.association', {
|
|
283
|
-
type: 'add',
|
|
284
|
-
association: {
|
|
285
|
-
type: LabelAssociationType.Message,
|
|
286
|
-
chatId: 'chat@s.whatsapp.net',
|
|
287
|
-
messageId: 'msg789',
|
|
288
|
-
labelId: 'label123'
|
|
289
|
-
}
|
|
290
|
-
})
|
|
291
|
-
})
|
|
292
|
-
})
|
|
293
|
-
|
|
294
|
-
describe('pnForLidChatAction', () => {
|
|
295
|
-
it('emits lid-mapping.update when pnJid is present', () => {
|
|
296
|
-
const syncAction = createSyncAction({ pnForLidChatAction: { pnJid: '5511999@s.whatsapp.net' } }, [
|
|
297
|
-
'pnForLid',
|
|
298
|
-
'123@lid'
|
|
299
|
-
])
|
|
300
|
-
processSyncAction(syncAction, ev, mockMe, undefined, logger)
|
|
301
|
-
expect(ev.emit).toHaveBeenCalledWith('lid-mapping.update', { lid: '123@lid', pn: '5511999@s.whatsapp.net' })
|
|
302
|
-
})
|
|
303
|
-
|
|
304
|
-
it('does not emit when pnJid is missing', () => {
|
|
305
|
-
const syncAction = createSyncAction({ pnForLidChatAction: { pnJid: '' } }, ['pnForLid', '123@lid'])
|
|
306
|
-
processSyncAction(syncAction, ev, mockMe, undefined, logger)
|
|
307
|
-
expect(ev.emit).not.toHaveBeenCalled()
|
|
308
|
-
})
|
|
309
|
-
})
|
|
310
|
-
|
|
311
|
-
describe('lockChatAction', () => {
|
|
312
|
-
it('emits chats.lock', () => {
|
|
313
|
-
const syncAction = createSyncAction({ lockChatAction: { locked: true } }, ['lockChat', 'chat@s.whatsapp.net'])
|
|
314
|
-
processSyncAction(syncAction, ev, mockMe, undefined, logger)
|
|
315
|
-
expect(ev.emit).toHaveBeenCalledWith('chats.lock', { id: 'chat@s.whatsapp.net', locked: true })
|
|
316
|
-
})
|
|
317
|
-
})
|
|
318
|
-
|
|
319
|
-
describe('lidContactAction', () => {
|
|
320
|
-
it('emits contacts.upsert with LID contact', () => {
|
|
321
|
-
const syncAction = createSyncAction({ lidContactAction: { fullName: 'LID Contact' } }, ['lidContact', '123@lid'])
|
|
322
|
-
processSyncAction(syncAction, ev, mockMe, undefined, logger)
|
|
323
|
-
expect(ev.emit).toHaveBeenCalledWith('contacts.upsert', [
|
|
324
|
-
{
|
|
325
|
-
id: '123@lid',
|
|
326
|
-
name: 'LID Contact',
|
|
327
|
-
lid: '123@lid',
|
|
328
|
-
phoneNumber: undefined
|
|
329
|
-
}
|
|
330
|
-
])
|
|
331
|
-
})
|
|
332
|
-
})
|
|
333
|
-
|
|
334
|
-
describe('settings actions', () => {
|
|
335
|
-
it('localeSetting emits settings.update', () => {
|
|
336
|
-
const syncAction = createSyncAction({ localeSetting: { locale: 'en-US' } }, ['locale'])
|
|
337
|
-
processSyncAction(syncAction, ev, mockMe, undefined, logger)
|
|
338
|
-
expect(ev.emit).toHaveBeenCalledWith('settings.update', { setting: 'locale', value: 'en-US' })
|
|
339
|
-
})
|
|
340
|
-
|
|
341
|
-
it('unarchiveChatsSetting emits creds.update', () => {
|
|
342
|
-
const syncAction = createSyncAction({ unarchiveChatsSetting: { unarchiveChats: true } }, ['unarchiveChats'])
|
|
343
|
-
processSyncAction(syncAction, ev, mockMe, undefined, logger)
|
|
344
|
-
expect(ev.emit).toHaveBeenCalledWith('creds.update', { accountSettings: { unarchiveChats: true } })
|
|
345
|
-
})
|
|
346
|
-
})
|
|
347
|
-
|
|
348
|
-
describe('unprocessable actions', () => {
|
|
349
|
-
it('logs debug for unknown action', () => {
|
|
350
|
-
const syncAction = createSyncAction({ unknownAction: {} } as unknown as proto.ISyncActionValue, [
|
|
351
|
-
'unknown',
|
|
352
|
-
'id123'
|
|
353
|
-
])
|
|
354
|
-
processSyncAction(syncAction, ev, mockMe, undefined, logger)
|
|
355
|
-
expect(logger.debug).toHaveBeenCalledWith({ syncAction, id: 'id123' }, 'unprocessable update')
|
|
356
|
-
expect(ev.emit).not.toHaveBeenCalled()
|
|
357
|
-
})
|
|
358
|
-
})
|
|
359
|
-
})
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
import { randomBytes } from 'crypto'
|
|
2
|
-
import { proto } from '../../../WAProto'
|
|
3
|
-
import type { WAMessageKey } from '../../Types'
|
|
4
|
-
import { getMessageReportingToken, shouldIncludeReportingToken } from '../../Utils/reporting-utils'
|
|
5
|
-
import type { BinaryNode } from '../../WABinary'
|
|
6
|
-
|
|
7
|
-
describe('Reporting Utils', () => {
|
|
8
|
-
describe('shouldIncludeReportingToken', () => {
|
|
9
|
-
const includedMessages: [string, proto.IMessage][] = [
|
|
10
|
-
['conversation', { conversation: 'Hello' }],
|
|
11
|
-
['extendedTextMessage', { extendedTextMessage: { text: 'Link' } }],
|
|
12
|
-
['imageMessage', { imageMessage: { url: 'url', mimetype: 'image/jpeg' } }],
|
|
13
|
-
['videoMessage', { videoMessage: { url: 'url', mimetype: 'video/mp4' } }],
|
|
14
|
-
['documentMessage', { documentMessage: { url: 'url', mimetype: 'application/pdf' } }],
|
|
15
|
-
['audioMessage', { audioMessage: { url: 'url', mimetype: 'audio/ogg' } }],
|
|
16
|
-
['stickerMessage', { stickerMessage: { url: 'url', mimetype: 'image/webp' } }]
|
|
17
|
-
]
|
|
18
|
-
|
|
19
|
-
const excludedMessages: [string, proto.IMessage][] = [
|
|
20
|
-
['reactionMessage', { reactionMessage: { key: { id: 'id' }, text: '👍' } }],
|
|
21
|
-
[
|
|
22
|
-
'encReactionMessage',
|
|
23
|
-
{
|
|
24
|
-
encReactionMessage: { targetMessageKey: { id: 'id' }, encPayload: Buffer.from('x'), encIv: Buffer.from('x') }
|
|
25
|
-
}
|
|
26
|
-
],
|
|
27
|
-
[
|
|
28
|
-
'pollUpdateMessage',
|
|
29
|
-
{
|
|
30
|
-
pollUpdateMessage: {
|
|
31
|
-
pollCreationMessageKey: { id: 'id' },
|
|
32
|
-
vote: { encPayload: Buffer.from('x'), encIv: Buffer.from('x') }
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
],
|
|
36
|
-
[
|
|
37
|
-
'encEventResponseMessage',
|
|
38
|
-
{
|
|
39
|
-
encEventResponseMessage: {
|
|
40
|
-
eventCreationMessageKey: { id: 'id' },
|
|
41
|
-
encPayload: Buffer.from('x'),
|
|
42
|
-
encIv: Buffer.from('x')
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
]
|
|
46
|
-
]
|
|
47
|
-
|
|
48
|
-
it.each(includedMessages)('should return true for %s', (_, message) => {
|
|
49
|
-
expect(shouldIncludeReportingToken(message)).toBe(true)
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
it.each(excludedMessages)('should return false for %s', (_, message) => {
|
|
53
|
-
expect(shouldIncludeReportingToken(message)).toBe(false)
|
|
54
|
-
})
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
describe('getMessageReportingToken', () => {
|
|
58
|
-
const createKey = (overrides?: Partial<WAMessageKey>): WAMessageKey => ({
|
|
59
|
-
id: 'test-id',
|
|
60
|
-
fromMe: true,
|
|
61
|
-
remoteJid: '123@s.whatsapp.net',
|
|
62
|
-
...overrides
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
const withSecret = (content: proto.IMessage, secret = randomBytes(32)): proto.IMessage => ({
|
|
66
|
-
...content,
|
|
67
|
-
messageContextInfo: { messageSecret: secret }
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
const encode = (msg: proto.IMessage) => Buffer.from(proto.Message.encode(msg).finish())
|
|
71
|
-
const getToken = (result: BinaryNode | null): Buffer | undefined => {
|
|
72
|
-
const content = result?.content
|
|
73
|
-
if (Array.isArray(content) && content[0]) {
|
|
74
|
-
return content[0].content as Buffer | undefined
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return undefined
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
it('should return null when message secret is missing', async () => {
|
|
81
|
-
const msg: proto.IMessage = { conversation: 'Hello' }
|
|
82
|
-
expect(await getMessageReportingToken(encode(msg), msg, createKey())).toBeNull()
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
it('should return null when message key id is missing', async () => {
|
|
86
|
-
const msg = withSecret({ conversation: 'Hello' })
|
|
87
|
-
expect(await getMessageReportingToken(encode(msg), msg, createKey({ id: '' }))).toBeNull()
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
it('should return valid reporting node structure', async () => {
|
|
91
|
-
const msg = withSecret({ conversation: 'Hello' })
|
|
92
|
-
const result = await getMessageReportingToken(encode(msg), msg, createKey())
|
|
93
|
-
|
|
94
|
-
expect(result).toMatchObject({ tag: 'reporting', attrs: {} })
|
|
95
|
-
const content = result?.content as any[]
|
|
96
|
-
expect(content).toHaveLength(1)
|
|
97
|
-
expect(content[0]).toMatchObject({ tag: 'reporting_token', attrs: { v: '2' } })
|
|
98
|
-
expect(content[0].content).toHaveLength(16)
|
|
99
|
-
})
|
|
100
|
-
|
|
101
|
-
it('should produce consistent tokens for the same input', async () => {
|
|
102
|
-
const secret = randomBytes(32)
|
|
103
|
-
const msg = withSecret({ conversation: 'Test' }, secret)
|
|
104
|
-
const encoded = encode(msg)
|
|
105
|
-
const key = createKey()
|
|
106
|
-
|
|
107
|
-
const token1 = getToken(await getMessageReportingToken(encoded, msg, key))
|
|
108
|
-
const token2 = getToken(await getMessageReportingToken(encoded, msg, key))
|
|
109
|
-
expect(token1).toEqual(token2)
|
|
110
|
-
})
|
|
111
|
-
|
|
112
|
-
const uniquenessTests: [string, () => [proto.IMessage, WAMessageKey, proto.IMessage, WAMessageKey]][] = [
|
|
113
|
-
[
|
|
114
|
-
'different secrets',
|
|
115
|
-
() => {
|
|
116
|
-
const msg1 = withSecret({ conversation: 'Same' }, randomBytes(32))
|
|
117
|
-
const msg2 = withSecret({ conversation: 'Same' }, randomBytes(32))
|
|
118
|
-
return [msg1, createKey(), msg2, createKey()]
|
|
119
|
-
}
|
|
120
|
-
],
|
|
121
|
-
[
|
|
122
|
-
'different message IDs',
|
|
123
|
-
() => {
|
|
124
|
-
const secret = randomBytes(32)
|
|
125
|
-
const msg = withSecret({ conversation: 'Same' }, secret)
|
|
126
|
-
return [msg, createKey({ id: 'id-1' }), msg, createKey({ id: 'id-2' })]
|
|
127
|
-
}
|
|
128
|
-
],
|
|
129
|
-
[
|
|
130
|
-
'different remoteJids',
|
|
131
|
-
() => {
|
|
132
|
-
const secret = randomBytes(32)
|
|
133
|
-
const msg = withSecret({ conversation: 'Same' }, secret)
|
|
134
|
-
return [
|
|
135
|
-
msg,
|
|
136
|
-
createKey({ remoteJid: '111@s.whatsapp.net' }),
|
|
137
|
-
msg,
|
|
138
|
-
createKey({ remoteJid: '222@s.whatsapp.net' })
|
|
139
|
-
]
|
|
140
|
-
}
|
|
141
|
-
]
|
|
142
|
-
]
|
|
143
|
-
|
|
144
|
-
it.each(uniquenessTests)('should produce different tokens for %s', async (_, setup) => {
|
|
145
|
-
const [msg1, key1, msg2, key2] = setup()
|
|
146
|
-
const token1 = getToken(await getMessageReportingToken(encode(msg1), msg1, key1))
|
|
147
|
-
const token2 = getToken(await getMessageReportingToken(encode(msg2), msg2, key2))
|
|
148
|
-
expect(token1).not.toEqual(token2)
|
|
149
|
-
})
|
|
150
|
-
|
|
151
|
-
it.each([
|
|
152
|
-
['group messages', { remoteJid: '123@g.us', participant: '456@s.whatsapp.net' }],
|
|
153
|
-
['incoming messages', { fromMe: false }]
|
|
154
|
-
])('should handle %s', async (_, keyOverrides) => {
|
|
155
|
-
const msg = withSecret({ conversation: 'Test' })
|
|
156
|
-
const result = await getMessageReportingToken(encode(msg), msg, createKey(keyOverrides))
|
|
157
|
-
expect(result?.tag).toBe('reporting')
|
|
158
|
-
})
|
|
159
|
-
})
|
|
160
|
-
})
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { jest } from '@jest/globals'
|
|
2
|
-
import type { SignalRepositoryWithLIDStore } from '../../Types'
|
|
3
|
-
import { parseAndInjectE2ESessions } from '../../Utils/signal'
|
|
4
|
-
import type { BinaryNode } from '../../WABinary/types'
|
|
5
|
-
|
|
6
|
-
describe('parseAndInjectE2ESessions', () => {
|
|
7
|
-
it('should process all user node', async () => {
|
|
8
|
-
const mockRepository = {
|
|
9
|
-
injectE2ESession: jest.fn<SignalRepositoryWithLIDStore['injectE2ESession']>()
|
|
10
|
-
} as jest.Mocked<Pick<SignalRepositoryWithLIDStore, 'injectE2ESession'>>
|
|
11
|
-
|
|
12
|
-
mockRepository.injectE2ESession.mockResolvedValue(undefined)
|
|
13
|
-
|
|
14
|
-
const createUserNode = (jid: string): BinaryNode => ({
|
|
15
|
-
tag: 'user',
|
|
16
|
-
attrs: { jid },
|
|
17
|
-
content: [
|
|
18
|
-
{
|
|
19
|
-
tag: 'skey',
|
|
20
|
-
attrs: {},
|
|
21
|
-
content: [
|
|
22
|
-
{ tag: 'id', attrs: {}, content: Buffer.from([0, 0, 1]) },
|
|
23
|
-
{ tag: 'value', attrs: {}, content: Buffer.alloc(33) },
|
|
24
|
-
{ tag: 'signature', attrs: {}, content: Buffer.alloc(64) }
|
|
25
|
-
]
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
tag: 'key',
|
|
29
|
-
attrs: {},
|
|
30
|
-
content: [
|
|
31
|
-
{ tag: 'id', attrs: {}, content: Buffer.from([0, 0, 2]) },
|
|
32
|
-
{ tag: 'value', attrs: {}, content: Buffer.alloc(33) }
|
|
33
|
-
]
|
|
34
|
-
},
|
|
35
|
-
{ tag: 'identity', attrs: {}, content: Buffer.alloc(32) },
|
|
36
|
-
{ tag: 'registration', attrs: {}, content: Buffer.alloc(4) }
|
|
37
|
-
]
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
const mockNode: BinaryNode = {
|
|
41
|
-
tag: 'iq',
|
|
42
|
-
attrs: {},
|
|
43
|
-
content: [
|
|
44
|
-
{
|
|
45
|
-
tag: 'list',
|
|
46
|
-
attrs: {},
|
|
47
|
-
content: [
|
|
48
|
-
createUserNode('user1@s.whatsapp.net'),
|
|
49
|
-
createUserNode('user2@s.whatsapp.net'),
|
|
50
|
-
createUserNode('user3@s.whatsapp.net')
|
|
51
|
-
]
|
|
52
|
-
}
|
|
53
|
-
]
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
await parseAndInjectE2ESessions(mockNode, mockRepository as any)
|
|
57
|
-
|
|
58
|
-
expect(mockRepository.injectE2ESession).toHaveBeenCalledTimes(3)
|
|
59
|
-
expect(mockRepository.injectE2ESession).toHaveBeenCalledWith(
|
|
60
|
-
expect.objectContaining({ jid: 'user1@s.whatsapp.net' })
|
|
61
|
-
)
|
|
62
|
-
expect(mockRepository.injectE2ESession).toHaveBeenCalledWith(
|
|
63
|
-
expect.objectContaining({ jid: 'user2@s.whatsapp.net' })
|
|
64
|
-
)
|
|
65
|
-
expect(mockRepository.injectE2ESession).toHaveBeenCalledWith(
|
|
66
|
-
expect.objectContaining({ jid: 'user3@s.whatsapp.net' })
|
|
67
|
-
)
|
|
68
|
-
})
|
|
69
|
-
})
|