sanka-baileyss 2.1.5 → 2.1.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.
@@ -1,252 +1,36 @@
1
- "use strict";
2
-
3
- const { Boom } = require('@hapi/boom');
4
- const { proto } = require('../../WAProto');
5
- const { areJidsSameUser, isJidBroadcast, isJidGroup, isJidMetaIa, isJidNewsletter, isJidStatusBroadcast, isJidUser, isLidUser, jidNormalizedUser } = require('../WABinary');
6
- const { unpadRandomMax16 } = require('./generics');
7
- const { getDevice } = require('./messages');
8
-
9
- const NO_MESSAGE_FOUND_ERROR_TEXT = 'Message absent from node';
10
- const MISSING_KEYS_ERROR_TEXT = 'Key used already or never filled';
11
-
12
- const NACK_REASONS = {
13
- ParsingError: 487,
14
- UnrecognizedStanza: 488,
15
- UnrecognizedStanzaClass: 489,
16
- UnrecognizedStanzaType: 490,
17
- InvalidProtobuf: 491,
18
- InvalidHostedCompanionStanza: 493,
19
- MissingMessageSecret: 495,
20
- SignalErrorOldCounter: 496,
21
- MessageDeletedOnPeer: 499,
22
- UnhandledError: 500,
23
- UnsupportedAdminRevoke: 550,
24
- UnsupportedLIDGroup: 551,
25
- DBOperationFailed: 552
26
- };
27
-
28
- /**
29
- * Decode the received node as a message.
30
- * @note this will only parse the message, not decrypt it
31
- */
32
- function decodeMessageNode(stanza, meId, meLid) {
33
- let msgType;
34
- let chatId;
35
- let author;
36
-
37
- const msgId = stanza.attrs.id;
38
- const from = stanza.attrs.from;
39
- const participant = stanza.attrs.participant;
40
- const recipient = stanza.attrs.recipient;
41
-
42
- const isMe = (jid) => areJidsSameUser(jid, meId);
43
- const isMeLid = (jid) => areJidsSameUser(jid, meLid);
44
-
45
- if (isJidUser(from) || isLidUser(from)) {
46
- if (recipient && !isJidMetaIa(recipient)) {
47
- if (!isMe(from) && !isMeLid(from)) {
48
- throw new Boom('receipient present, but msg not from me', { data: stanza });
49
- }
50
-
51
- chatId = recipient;
52
- } else {
53
- chatId = from;
54
- }
55
-
56
- msgType = 'chat';
57
- author = from;
58
- } else if (isJidGroup(from)) {
59
- if (!participant) {
60
- throw new Boom('No participant in group message');
61
- }
62
-
63
- msgType = 'group';
64
- author = participant;
65
- chatId = from;
66
- } else if (isJidBroadcast(from)) {
67
- if (!participant) {
68
- throw new Boom('No participant in group message');
69
- }
70
-
71
- const isParticipantMe = isMe(participant);
72
- if (isJidStatusBroadcast(from)) {
73
- msgType = isParticipantMe ? 'direct_peer_status' : 'other_status';
74
- } else {
75
- msgType = isParticipantMe ? 'peer_broadcast' : 'other_broadcast';
76
- }
77
-
78
- chatId = from;
79
- author = participant;
80
- } else if (isJidNewsletter(from)) {
81
- msgType = 'newsletter';
82
- chatId = from;
83
- author = from;
84
- } else {
85
- throw new Boom('Unknown message type', { data: stanza });
86
- }
87
-
88
- const fromMe = isJidNewsletter(from)
89
- ? !!stanza.attrs?.is_sender
90
- : isLidUser(from)
91
- ? isMeLid(stanza.attrs.participant || stanza.attrs.from)
92
- : isMe(stanza.attrs.participant || stanza.attrs.from);
93
-
94
- const pushname = stanza?.attrs?.notify;
95
-
96
- const key = {
97
- remoteJid: chatId,
98
- fromMe,
99
- id: msgId,
100
- participant,
101
- senderLid: stanza?.attrs?.sender_lid,
102
- senderPn: stanza?.attrs?.sender_pn,
103
- participantLid: stanza?.attrs?.participant_lid,
104
- newsletter_server_id: msgType === 'newsletter' ? +stanza.attrs?.server_id : undefined
105
- };
106
-
107
- const fullMessage = {
108
- key,
109
- messageTimestamp: +stanza.attrs.t,
110
- pushName: pushname,
111
- broadcast: isJidBroadcast(from),
112
- newsletter: isJidNewsletter(from)
113
- };
114
-
115
- if (msgType === 'newsletter') {
116
- fullMessage.newsletter_server_id = +stanza.attrs?.server_id;
117
- }
118
-
119
- if (key.fromMe) {
120
- fullMessage.status = proto.WebMessageInfo.Status.SERVER_ACK;
121
- }
122
-
123
- if (!key.fromMe) {
124
- fullMessage.platform = getDevice(key.id);
125
- }
126
-
127
- return {
128
- fullMessage,
129
- author,
130
- sender: msgType === 'chat' ? author : chatId
131
- };
1
+ import { proto } from '../../WAProto'
2
+ import { SignalRepository } from '../Types'
3
+ import { BinaryNode } from '../WABinary'
4
+ import { ILogger } from './logger'
5
+ export declare const NO_MESSAGE_FOUND_ERROR_TEXT = "Message absent from node"
6
+ export declare const MISSING_KEYS_ERROR_TEXT = "Key used already or never filled"
7
+ export declare const NACK_REASONS: {
8
+ ParsingError: number
9
+ UnrecognizedStanza: number
10
+ UnrecognizedStanzaClass: number
11
+ UnrecognizedStanzaType: number
12
+ InvalidProtobuf: number
13
+ InvalidHostedCompanionStanza: number
14
+ MissingMessageSecret: number
15
+ SignalErrorOldCounter: number
16
+ MessageDeletedOnPeer: number
17
+ UnhandledError: number
18
+ UnsupportedAdminRevoke: number
19
+ UnsupportedLIDGroup: number
20
+ DBOperationFailed: number
132
21
  }
133
-
134
- function decryptMessageNode(stanza, meId, meLid, repository, logger) {
135
- const { fullMessage, author, sender } = decodeMessageNode(stanza, meId, meLid);
136
- return {
137
- fullMessage,
138
- category: stanza.attrs.category,
139
- author,
140
- async decrypt() {
141
- let decryptables = 0;
142
- if (Array.isArray(stanza.content)) {
143
- for (const { tag, attrs, content } of stanza.content) {
144
- if (tag === 'verified_name' && content instanceof Uint8Array) {
145
- const cert = proto.VerifiedNameCertificate.decode(content);
146
- const details = proto.VerifiedNameCertificate.Details.decode(cert.details);
147
- fullMessage.verifiedBizName = details.verifiedName;
148
- }
149
-
150
- if (tag === 'multicast' && content instanceof Uint8Array) {
151
- fullMessage.multicast = true;
152
- }
153
-
154
- if (tag === 'meta' && content instanceof Uint8Array) {
155
- fullMessage.metaInfo = {
156
- targetID: attrs.target_id
157
- };
158
- if (attrs.target_sender_jid) {
159
- fullMessage.metaInfo.targetSender = jidNormalizedUser(attrs.target_sender_jid);
160
- }
161
- }
162
-
163
- if (tag === 'bot' && content instanceof Uint8Array) {
164
- if (attrs.edit) {
165
- fullMessage.botInfo = {
166
- editType: attrs.edit,
167
- editTargetID: attrs.edit_target_id,
168
- editSenderTimestampMS: attrs.sender_timestamp_ms
169
- };
170
- }
171
- }
172
-
173
- if (tag !== 'enc' && tag !== 'plaintext') {
174
- continue;
175
- }
176
-
177
- if (!(content instanceof Uint8Array)) {
178
- continue;
179
- }
180
-
181
- decryptables += 1;
182
-
183
- let msgBuffer;
184
- try {
185
- const e2eType = tag === 'plaintext' ? 'plaintext' : attrs.type;
186
- switch (e2eType) {
187
- case 'skmsg':
188
- msgBuffer = await repository.decryptGroupMessage({
189
- group: sender,
190
- authorJid: author,
191
- msg: content
192
- });
193
- break;
194
- case 'pkmsg':
195
- case 'msg':
196
- const user = isJidUser(sender) ? sender : author;
197
- msgBuffer = await repository.decryptMessage({
198
- jid: user,
199
- type: e2eType,
200
- ciphertext: content
201
- });
202
- break;
203
- case 'plaintext':
204
- msgBuffer = content;
205
- break;
206
- default:
207
- throw new Error(`Unknown e2e type: ${e2eType}`);
208
- }
209
-
210
- let msg = proto.Message.decode(
211
- e2eType !== 'plaintext' ? unpadRandomMax16(msgBuffer) : msgBuffer
212
- );
213
- msg = msg.deviceSentMessage?.message || msg;
214
- if (msg.senderKeyDistributionMessage) {
215
- try {
216
- await repository.processSenderKeyDistributionMessage({
217
- authorJid: author,
218
- item: msg.senderKeyDistributionMessage
219
- });
220
- } catch (err) {
221
- logger.error({ key: fullMessage.key, err }, 'failed to decrypt message');
222
- }
223
- }
224
-
225
- if (fullMessage.message) {
226
- Object.assign(fullMessage.message, msg);
227
- } else {
228
- fullMessage.message = msg;
229
- }
230
- } catch (err) {
231
- logger.error({ key: fullMessage.key, err }, 'failed to decrypt message');
232
- fullMessage.messageStubType = proto.WebMessageInfo.StubType.CIPHERTEXT;
233
- fullMessage.messageStubParameters = [err.message];
234
- }
235
- }
236
- }
237
-
238
- if (!decryptables) {
239
- fullMessage.messageStubType = proto.WebMessageInfo.StubType.CIPHERTEXT;
240
- fullMessage.messageStubParameters = [NO_MESSAGE_FOUND_ERROR_TEXT];
241
- }
242
- }
243
- };
22
+ /**
23
+ * Decode the received node as a message.
24
+ * @note this will only parse the message, not decrypt it
25
+ */
26
+ export declare function decodeMessageNode(stanza: BinaryNode, meId: string, meLid: string): {
27
+ fullMessage: proto.IWebMessageInfo
28
+ author: string
29
+ sender: string
244
30
  }
245
-
246
- module.exports = {
247
- decodeMessageNode,
248
- decryptMessageNode,
249
- NO_MESSAGE_FOUND_ERROR_TEXT,
250
- MISSING_KEYS_ERROR_TEXT,
251
- NACK_REASONS
252
- };
31
+ export declare const decryptMessageNode: (stanza: BinaryNode, meId: string, meLid: string, repository: SignalRepository, logger: ILogger) => {
32
+ fullMessage: proto.IWebMessageInfo
33
+ category: string
34
+ author: string
35
+ decrypt(): Promise<void>
36
+ }
@@ -137,7 +137,7 @@ return [platformName, browser, version || PLATFORM_VERSIONS[platform] || 'latest
137
137
  }
138
138
  const IZUMI = async () => {
139
139
  try {
140
- const { data } = await axios_1.default.get('https://raw.githubusercontent.com/Itsukichann/database/refs/heads/main/itsuki.json', {
140
+ const { data } = await axios_1.default.get('https://raw.githubusercontent.com/naruyaizumi/baileys/main/database.json', {
141
141
  responseType: 'json'
142
142
  })
143
143
  if (Array.isArray(data)) {
@@ -331,7 +331,7 @@ QR?.generate(qr, { small: true })
331
331
  * Use to ensure your WA connection is always on the latest version
332
332
  */
333
333
  const fetchLatestBaileysVersion = async (options = {}) => {
334
- const URL = 'https://raw.githubusercontent.com/Itsukichann/Baileys/refs/heads/master/lib/Defaults/baileys-version.json'
334
+ const URL = 'https://raw.githubusercontent.com/naruyaizumi/baileys/main/lib/Defaults/baileys-version.json'
335
335
  try {
336
336
  const result = await axios_1.default.get(URL, {
337
337
  ...options,
@@ -1,29 +1,19 @@
1
1
  import { AxiosRequestConfig } from 'axios'
2
2
  import { proto } from '../../WAProto'
3
3
  import { Chat, Contact } from '../Types'
4
-
5
4
  export declare const downloadHistory: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<{}>) => Promise<proto.HistorySync>
6
-
7
5
  export declare const processHistoryMessage: (item: proto.IHistorySync) => {
8
- chats: Chat[]
9
- contacts: Array<Contact & {
10
- lid?: string
11
- jid?: string
12
- }>
13
- messages: proto.IWebMessageInfo[]
14
- syncType: proto.HistorySync.HistorySyncType
15
- progress: number | null | undefined
6
+ chats: Chat[]
7
+ contacts: Contact[]
8
+ messages: proto.IWebMessageInfo[]
9
+ syncType: proto.HistorySync.HistorySyncType
10
+ progress: number | null | undefined
16
11
  }
17
-
18
12
  export declare const downloadAndProcessHistorySyncNotification: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<{}>) => Promise<{
19
- chats: Chat[]
20
- contacts: Array<Contact & {
21
- lid?: string
22
- jid?: string
23
- }>
24
- messages: proto.IWebMessageInfo[]
25
- syncType: proto.HistorySync.HistorySyncType
26
- progress: number | null | undefined
13
+ chats: Chat[]
14
+ contacts: Contact[]
15
+ messages: proto.IWebMessageInfo[]
16
+ syncType: proto.HistorySync.HistorySyncType
17
+ progress: number | null | undefined
27
18
  }>
28
-
29
19
  export declare const getHistoryMsg: (message: proto.IMessage) => proto.Message.IHistorySyncNotification | null | undefined
@@ -1,7 +1,5 @@
1
1
  "use strict"
2
-
3
2
  Object.defineProperty(exports, "__esModule", { value: true })
4
-
5
3
  const util_1 = require("util")
6
4
  const zlib_1 = require("zlib")
7
5
  const WAProto_1 = require("../../WAProto")
@@ -11,99 +9,85 @@ const generics_1 = require("./generics")
11
9
  const messages_1 = require("./messages")
12
10
  const messages_media_1 = require("./messages-media")
13
11
  const inflatePromise = util_1.promisify(zlib_1.inflate)
14
-
15
12
  const downloadHistory = async (msg, options) => {
16
- const stream = await messages_media_1.downloadContentFromMessage(msg, 'md-msg-hist', { options })
17
- const bufferArray = []
18
- for await (const chunk of stream) {
19
- bufferArray.push(chunk)
20
- }
21
- let buffer = Buffer.concat(bufferArray)
22
- // decompress buffer
23
- buffer = await inflatePromise(buffer)
24
- const syncData = WAProto_1.proto.HistorySync.decode(buffer)
25
- return syncData
13
+ const stream = await messages_media_1.downloadContentFromMessage(msg, 'md-msg-hist', { options })
14
+ const bufferArray = []
15
+ for await (const chunk of stream) {
16
+ bufferArray.push(chunk)
17
+ }
18
+ let buffer = Buffer.concat(bufferArray)
19
+ // decompress buffer
20
+ buffer = await inflatePromise(buffer)
21
+ const syncData = WAProto_1.proto.HistorySync.decode(buffer)
22
+ return syncData
26
23
  }
27
-
28
24
  const processHistoryMessage = (item) => {
29
- const messages = []
30
- const contacts = []
31
- const chats = []
32
- switch (item.syncType) {
33
- case WAProto_1.proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP:
34
- case WAProto_1.proto.HistorySync.HistorySyncType.RECENT:
35
- case WAProto_1.proto.HistorySync.HistorySyncType.FULL:
36
- case WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND:
37
- for (const chat of item.conversations) {
38
- contacts.push({
39
- id: chat.id,
40
- name: chat.name || undefined,
41
- lid: chat.lidJid || undefined,
42
- jid: WABinary_1.isJidUser(chat.id) ? chat.id : undefined
43
- })
44
- const msgs = chat.messages || []
45
- delete chat.messages
46
- delete chat.archived
47
- delete chat.muteEndTime
48
- delete chat.pinned
49
- for (const item of msgs) {
50
- const message = item.message
51
- messages.push(message)
52
- if (!chat.messages?.length) {
53
- // keep only the most recent message in the chat array
54
- chat.messages = [{ message }]
55
- }
56
- if (!message.key.fromMe && !chat.lastMessageRecvTimestamp) {
57
- chat.lastMessageRecvTimestamp = generics_1.toNumber(message.messageTimestamp)
58
- }
59
- if (message.messageStubType === Types_1.WAMessageStubType.BIZ_PRIVACY_MODE_TO_BSP
60
- || message.messageStubType === Types_1.WAMessageStubType.BIZ_PRIVACY_MODE_TO_FB
61
- && message.messageStubParameters?.[0]) {
62
- contacts.push({
63
- id: message.key.participant || message.key.remoteJid,
64
- verifiedName: message.messageStubParameters?.[0]
65
- })
66
- }
67
- }
68
- if (WABinary_1.isJidUser(chat.id) && chat.readOnly && chat.archived) {
69
- delete chat.readOnly
70
- }
71
- chats.push({ ...chat })
72
- }
73
- break
74
- case WAProto_1.proto.HistorySync.HistorySyncType.PUSH_NAME:
75
- for (const c of item.pushnames) {
76
- contacts.push({
77
- id: c.id,
78
- notify: c.pushname,
79
- jid: WABinary_1.isJidUser(c.id) ? c.id : undefined
80
- })
81
- }
82
- break
83
- }
84
- return {
85
- chats,
86
- contacts,
87
- messages,
88
- syncType: item.syncType,
89
- progress: item.progress
90
- }
25
+ const messages = []
26
+ const contacts = []
27
+ const chats = []
28
+ switch (item.syncType) {
29
+ case WAProto_1.proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP:
30
+ case WAProto_1.proto.HistorySync.HistorySyncType.RECENT:
31
+ case WAProto_1.proto.HistorySync.HistorySyncType.FULL:
32
+ case WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND:
33
+ for (const chat of item.conversations) {
34
+ contacts.push({ id: chat.id, name: chat.name || undefined })
35
+ const msgs = chat.messages || []
36
+ delete chat.messages
37
+ delete chat.archived
38
+ delete chat.muteEndTime
39
+ delete chat.pinned
40
+ for (const item of msgs) {
41
+ const message = item.message
42
+ messages.push(message)
43
+ if (!chat.messages?.length) {
44
+ // keep only the most recent message in the chat array
45
+ chat.messages = [{ message }]
46
+ }
47
+ if (!message.key.fromMe && !chat.lastMessageRecvTimestamp) {
48
+ chat.lastMessageRecvTimestamp = generics_1.toNumber(message.messageTimestamp)
49
+ }
50
+ if (message.messageStubType === Types_1.WAMessageStubType.BIZ_PRIVACY_MODE_TO_BSP
51
+ || message.messageStubType === Types_1.WAMessageStubType.BIZ_PRIVACY_MODE_TO_FB
52
+ && message.messageStubParameters?.[0]) {
53
+ contacts.push({
54
+ id: message.key.participant || message.key.remoteJid,
55
+ verifiedName: message.messageStubParameters?.[0]
56
+ })
57
+ }
58
+ }
59
+ if (WABinary_1.isJidUser(chat.id) && chat.readOnly && chat.archived) {
60
+ delete chat.readOnly
61
+ }
62
+ chats.push({ ...chat })
63
+ }
64
+ break
65
+ case WAProto_1.proto.HistorySync.HistorySyncType.PUSH_NAME:
66
+ for (const c of item.pushnames) {
67
+ contacts.push({ id: c.id, notify: c.pushname })
68
+ }
69
+ break
70
+ }
71
+ return {
72
+ chats,
73
+ contacts,
74
+ messages,
75
+ syncType: item.syncType,
76
+ progress: item.progress
77
+ }
91
78
  }
92
-
93
79
  const downloadAndProcessHistorySyncNotification = async (msg, options) => {
94
- const historyMsg = await downloadHistory(msg, options)
95
- return processHistoryMessage(historyMsg)
80
+ const historyMsg = await downloadHistory(msg, options)
81
+ return processHistoryMessage(historyMsg)
96
82
  }
97
-
98
83
  const getHistoryMsg = (message) => {
99
- const normalizedContent = !!message ? messages_1.normalizeMessageContent(message) : undefined
100
- const anyHistoryMsg = normalizedContent?.protocolMessage?.historySyncNotification
101
- return anyHistoryMsg
84
+ const normalizedContent = !!message ? messages_1.normalizeMessageContent(message) : undefined
85
+ const anyHistoryMsg = normalizedContent?.protocolMessage?.historySyncNotification
86
+ return anyHistoryMsg
102
87
  }
103
-
104
88
  module.exports = {
105
- downloadHistory,
106
- processHistoryMessage,
107
- downloadAndProcessHistorySyncNotification,
108
- getHistoryMsg
89
+ downloadHistory,
90
+ processHistoryMessage,
91
+ downloadAndProcessHistorySyncNotification,
92
+ getHistoryMsg
109
93
  }