supunmd-bail 2.0.1
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 +21 -0
- package/WAProto/GenerateStatics.sh +3 -0
- package/WAProto/WAProto.proto +5519 -0
- package/WAProto/fix-imports.js +29 -0
- package/WAProto/index.d.ts +11969 -0
- package/WAProto/index.js +84368 -0
- package/engine-requirements.js +10 -0
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/index.d.ts +62 -0
- package/lib/Defaults/index.js +115 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
- package/lib/Signal/Group/ciphertext-message.js +12 -0
- package/lib/Signal/Group/group-session-builder.d.ts +15 -0
- package/lib/Signal/Group/group-session-builder.js +30 -0
- package/lib/Signal/Group/group_cipher.d.ts +17 -0
- package/lib/Signal/Group/group_cipher.js +82 -0
- package/lib/Signal/Group/index.d.ts +12 -0
- package/lib/Signal/Group/index.js +12 -0
- package/lib/Signal/Group/keyhelper.d.ts +11 -0
- package/lib/Signal/Group/keyhelper.js +18 -0
- package/lib/Signal/Group/queue-job.d.ts +2 -0
- package/lib/Signal/Group/queue-job.js +54 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
- package/lib/Signal/Group/sender-chain-key.js +26 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +63 -0
- package/lib/Signal/Group/sender-key-message.d.ts +19 -0
- package/lib/Signal/Group/sender-key-message.js +66 -0
- package/lib/Signal/Group/sender-key-name.d.ts +18 -0
- package/lib/Signal/Group/sender-key-name.js +48 -0
- package/lib/Signal/Group/sender-key-record.d.ts +31 -0
- package/lib/Signal/Group/sender-key-record.js +41 -0
- package/lib/Signal/Group/sender-key-state.d.ts +39 -0
- package/lib/Signal/Group/sender-key-state.js +84 -0
- package/lib/Signal/Group/sender-message-key.d.ts +12 -0
- package/lib/Signal/Group/sender-message-key.js +26 -0
- package/lib/Signal/libsignal.d.ts +5 -0
- package/lib/Signal/libsignal.js +342 -0
- package/lib/Signal/lid-mapping.d.ts +23 -0
- package/lib/Signal/lid-mapping.js +171 -0
- package/lib/Socket/Client/index.d.ts +3 -0
- package/lib/Socket/Client/index.js +3 -0
- package/lib/Socket/Client/types.d.ts +16 -0
- package/lib/Socket/Client/types.js +11 -0
- package/lib/Socket/Client/websocket.d.ts +13 -0
- package/lib/Socket/Client/websocket.js +50 -0
- package/lib/Socket/business.d.ts +188 -0
- package/lib/Socket/business.js +376 -0
- package/lib/Socket/chats.d.ts +98 -0
- package/lib/Socket/chats.js +962 -0
- package/lib/Socket/communities.d.ts +244 -0
- package/lib/Socket/communities.js +431 -0
- package/lib/Socket/groups.d.ts +137 -0
- package/lib/Socket/groups.js +327 -0
- package/lib/Socket/index.d.ts +231 -0
- package/lib/Socket/index.js +18 -0
- package/lib/Socket/messages-recv.d.ts +173 -0
- package/lib/Socket/messages-recv.js +1228 -0
- package/lib/Socket/messages-send.d.ts +169 -0
- package/lib/Socket/messages-send.js +1070 -0
- package/lib/Socket/mex.d.ts +3 -0
- package/lib/Socket/mex.js +42 -0
- package/lib/Socket/newsletter.d.ts +147 -0
- package/lib/Socket/newsletter.js +181 -0
- package/lib/Socket/socket.d.ts +51 -0
- package/lib/Socket/socket.js +883 -0
- package/lib/Socket/usync.d.ts +37 -0
- package/lib/Socket/usync.js +63 -0
- package/lib/Types/Auth.d.ts +111 -0
- package/lib/Types/Auth.js +2 -0
- package/lib/Types/Bussines.d.ts +25 -0
- package/lib/Types/Bussines.js +2 -0
- package/lib/Types/Call.d.ts +14 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Chat.d.ts +123 -0
- package/lib/Types/Chat.js +8 -0
- package/lib/Types/Contact.d.ts +24 -0
- package/lib/Types/Contact.js +2 -0
- package/lib/Types/Events.d.ts +202 -0
- package/lib/Types/Events.js +2 -0
- package/lib/Types/GroupMetadata.d.ts +67 -0
- package/lib/Types/GroupMetadata.js +2 -0
- package/lib/Types/Label.d.ts +47 -0
- package/lib/Types/Label.js +25 -0
- package/lib/Types/LabelAssociation.d.ts +30 -0
- package/lib/Types/LabelAssociation.js +7 -0
- package/lib/Types/Message.d.ts +303 -0
- package/lib/Types/Message.js +11 -0
- package/lib/Types/Newsletter.d.ts +135 -0
- package/lib/Types/Newsletter.js +31 -0
- package/lib/Types/Product.d.ts +79 -0
- package/lib/Types/Product.js +2 -0
- package/lib/Types/Signal.d.ts +76 -0
- package/lib/Types/Signal.js +2 -0
- package/lib/Types/Socket.d.ts +133 -0
- package/lib/Types/Socket.js +3 -0
- package/lib/Types/State.d.ts +39 -0
- package/lib/Types/State.js +13 -0
- package/lib/Types/USync.d.ts +26 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/index.d.ts +65 -0
- package/lib/Types/index.js +26 -0
- package/lib/Utils/auth-utils.d.ts +19 -0
- package/lib/Utils/auth-utils.js +257 -0
- package/lib/Utils/baileys-event-stream.d.ts +17 -0
- package/lib/Utils/baileys-event-stream.js +56 -0
- package/lib/Utils/browser-utils.d.ts +4 -0
- package/lib/Utils/browser-utils.js +28 -0
- package/lib/Utils/business.d.ts +23 -0
- package/lib/Utils/business.js +231 -0
- package/lib/Utils/chat-utils.d.ts +70 -0
- package/lib/Utils/chat-utils.js +763 -0
- package/lib/Utils/crypto.d.ts +41 -0
- package/lib/Utils/crypto.js +142 -0
- package/lib/Utils/decode-wa-message.d.ts +48 -0
- package/lib/Utils/decode-wa-message.js +279 -0
- package/lib/Utils/event-buffer.d.ts +34 -0
- package/lib/Utils/event-buffer.js +548 -0
- package/lib/Utils/generics.d.ts +90 -0
- package/lib/Utils/generics.js +381 -0
- package/lib/Utils/history.d.ts +19 -0
- package/lib/Utils/history.js +84 -0
- package/lib/Utils/index.d.ts +20 -0
- package/lib/Utils/index.js +20 -0
- package/lib/Utils/link-preview.d.ts +21 -0
- package/lib/Utils/link-preview.js +85 -0
- package/lib/Utils/logger.d.ts +12 -0
- package/lib/Utils/logger.js +3 -0
- package/lib/Utils/lt-hash.d.ts +13 -0
- package/lib/Utils/lt-hash.js +48 -0
- package/lib/Utils/make-mutex.d.ts +8 -0
- package/lib/Utils/make-mutex.js +40 -0
- package/lib/Utils/message-retry-manager.d.ts +82 -0
- package/lib/Utils/message-retry-manager.js +149 -0
- package/lib/Utils/messages-media.d.ts +114 -0
- package/lib/Utils/messages-media.js +663 -0
- package/lib/Utils/messages.d.ts +76 -0
- package/lib/Utils/messages.js +908 -0
- package/lib/Utils/noise-handler.d.ts +20 -0
- package/lib/Utils/noise-handler.js +147 -0
- package/lib/Utils/pre-key-manager.d.ts +28 -0
- package/lib/Utils/pre-key-manager.js +106 -0
- package/lib/Utils/process-message.d.ts +42 -0
- package/lib/Utils/process-message.js +413 -0
- package/lib/Utils/signal.d.ts +34 -0
- package/lib/Utils/signal.js +159 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
- package/lib/Utils/use-multi-file-auth-state.js +121 -0
- package/lib/Utils/validate-connection.d.ts +11 -0
- package/lib/Utils/validate-connection.js +195 -0
- package/lib/WABinary/constants.d.ts +28 -0
- package/lib/WABinary/constants.js +1301 -0
- package/lib/WABinary/decode.d.ts +7 -0
- package/lib/WABinary/decode.js +238 -0
- package/lib/WABinary/encode.d.ts +3 -0
- package/lib/WABinary/encode.js +216 -0
- package/lib/WABinary/generic-utils.d.ts +15 -0
- package/lib/WABinary/generic-utils.js +191 -0
- package/lib/WABinary/index.d.ts +6 -0
- package/lib/WABinary/index.js +6 -0
- package/lib/WABinary/jid-utils.d.ts +48 -0
- package/lib/WABinary/jid-utils.js +96 -0
- package/lib/WABinary/types.d.ts +19 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WAM/BinaryInfo.d.ts +9 -0
- package/lib/WAM/BinaryInfo.js +10 -0
- package/lib/WAM/constants.d.ts +40 -0
- package/lib/WAM/constants.js +22853 -0
- package/lib/WAM/encode.d.ts +3 -0
- package/lib/WAM/encode.js +150 -0
- package/lib/WAM/index.d.ts +4 -0
- package/lib/WAM/index.js +4 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +29 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +54 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +27 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +38 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +51 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +29 -0
- package/lib/WAUSync/Protocols/index.d.ts +5 -0
- package/lib/WAUSync/Protocols/index.js +5 -0
- package/lib/WAUSync/USyncQuery.d.ts +29 -0
- package/lib/WAUSync/USyncQuery.js +94 -0
- package/lib/WAUSync/USyncUser.d.ts +13 -0
- package/lib/WAUSync/USyncUser.js +23 -0
- package/lib/WAUSync/index.d.ts +4 -0
- package/lib/WAUSync/index.js +4 -0
- package/lib/index.d.ts +22 -0
- package/lib/index.js +36 -0
- package/lib/supun +1 -0
- package/package.json +104 -0
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
import { proto } from '../../WAProto/index.js';
|
|
2
|
+
import { WAMessageStubType } from '../Types/index.js';
|
|
3
|
+
import { getContentType, normalizeMessageContent } from '../Utils/messages.js';
|
|
4
|
+
import { areJidsSameUser, isHostedLidUser, isHostedPnUser, isJidBroadcast, isJidStatusBroadcast, jidDecode, jidEncode, jidNormalizedUser } from '../WABinary/index.js';
|
|
5
|
+
import { aesDecryptGCM, hmacSign } from './crypto.js';
|
|
6
|
+
import { toNumber } from './generics.js';
|
|
7
|
+
import { downloadAndProcessHistorySyncNotification } from './history.js';
|
|
8
|
+
const REAL_MSG_STUB_TYPES = new Set([
|
|
9
|
+
WAMessageStubType.CALL_MISSED_GROUP_VIDEO,
|
|
10
|
+
WAMessageStubType.CALL_MISSED_GROUP_VOICE,
|
|
11
|
+
WAMessageStubType.CALL_MISSED_VIDEO,
|
|
12
|
+
WAMessageStubType.CALL_MISSED_VOICE
|
|
13
|
+
]);
|
|
14
|
+
const REAL_MSG_REQ_ME_STUB_TYPES = new Set([WAMessageStubType.GROUP_PARTICIPANT_ADD]);
|
|
15
|
+
/** Cleans a received message to further processing */
|
|
16
|
+
export const cleanMessage = (message, meId, meLid) => {
|
|
17
|
+
// ensure remoteJid and participant doesn't have device or agent in it
|
|
18
|
+
if (isHostedPnUser(message.key.remoteJid) || isHostedLidUser(message.key.remoteJid)) {
|
|
19
|
+
message.key.remoteJid = jidEncode(jidDecode(message.key?.remoteJid)?.user, isHostedPnUser(message.key.remoteJid) ? 's.whatsapp.net' : 'lid');
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
message.key.remoteJid = jidNormalizedUser(message.key.remoteJid);
|
|
23
|
+
}
|
|
24
|
+
if (isHostedPnUser(message.key.participant) || isHostedLidUser(message.key.participant)) {
|
|
25
|
+
message.key.participant = jidEncode(jidDecode(message.key.participant)?.user, isHostedPnUser(message.key.participant) ? 's.whatsapp.net' : 'lid');
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
message.key.participant = jidNormalizedUser(message.key.participant);
|
|
29
|
+
}
|
|
30
|
+
const content = normalizeMessageContent(message.message);
|
|
31
|
+
// if the message has a reaction, ensure fromMe & remoteJid are from our perspective
|
|
32
|
+
if (content?.reactionMessage) {
|
|
33
|
+
normaliseKey(content.reactionMessage.key);
|
|
34
|
+
}
|
|
35
|
+
if (content?.pollUpdateMessage) {
|
|
36
|
+
normaliseKey(content.pollUpdateMessage.pollCreationMessageKey);
|
|
37
|
+
}
|
|
38
|
+
function normaliseKey(msgKey) {
|
|
39
|
+
// if the reaction is from another user
|
|
40
|
+
// we've to correctly map the key to this user's perspective
|
|
41
|
+
if (!message.key.fromMe) {
|
|
42
|
+
// if the sender believed the message being reacted to is not from them
|
|
43
|
+
// we've to correct the key to be from them, or some other participant
|
|
44
|
+
msgKey.fromMe = !msgKey.fromMe
|
|
45
|
+
? areJidsSameUser(msgKey.participant || msgKey.remoteJid, meId) ||
|
|
46
|
+
areJidsSameUser(msgKey.participant || msgKey.remoteJid, meLid)
|
|
47
|
+
: // if the message being reacted to, was from them
|
|
48
|
+
// fromMe automatically becomes false
|
|
49
|
+
false;
|
|
50
|
+
// set the remoteJid to being the same as the chat the message came from
|
|
51
|
+
// TODO: investigate inconsistencies
|
|
52
|
+
msgKey.remoteJid = message.key.remoteJid;
|
|
53
|
+
// set participant of the message
|
|
54
|
+
msgKey.participant = msgKey.participant || message.key.participant;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
// TODO: target:audit AUDIT THIS FUNCTION AGAIN
|
|
59
|
+
export const isRealMessage = (message) => {
|
|
60
|
+
const normalizedContent = normalizeMessageContent(message.message);
|
|
61
|
+
const hasSomeContent = !!getContentType(normalizedContent);
|
|
62
|
+
return ((!!normalizedContent ||
|
|
63
|
+
REAL_MSG_STUB_TYPES.has(message.messageStubType) ||
|
|
64
|
+
REAL_MSG_REQ_ME_STUB_TYPES.has(message.messageStubType)) &&
|
|
65
|
+
hasSomeContent &&
|
|
66
|
+
!normalizedContent?.protocolMessage &&
|
|
67
|
+
!normalizedContent?.reactionMessage &&
|
|
68
|
+
!normalizedContent?.pollUpdateMessage);
|
|
69
|
+
};
|
|
70
|
+
export const shouldIncrementChatUnread = (message) => !message.key.fromMe && !message.messageStubType;
|
|
71
|
+
/**
|
|
72
|
+
* Get the ID of the chat from the given key.
|
|
73
|
+
* Typically -- that'll be the remoteJid, but for broadcasts, it'll be the participant
|
|
74
|
+
*/
|
|
75
|
+
export const getChatId = ({ remoteJid, participant, fromMe }) => {
|
|
76
|
+
if (isJidBroadcast(remoteJid) && !isJidStatusBroadcast(remoteJid) && !fromMe) {
|
|
77
|
+
return participant;
|
|
78
|
+
}
|
|
79
|
+
return remoteJid;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Decrypt a poll vote
|
|
83
|
+
* @param vote encrypted vote
|
|
84
|
+
* @param ctx additional info about the poll required for decryption
|
|
85
|
+
* @returns list of SHA256 options
|
|
86
|
+
*/
|
|
87
|
+
export function decryptPollVote({ encPayload, encIv }, { pollCreatorJid, pollMsgId, pollEncKey, voterJid }) {
|
|
88
|
+
const sign = Buffer.concat([
|
|
89
|
+
toBinary(pollMsgId),
|
|
90
|
+
toBinary(pollCreatorJid),
|
|
91
|
+
toBinary(voterJid),
|
|
92
|
+
toBinary('Poll Vote'),
|
|
93
|
+
new Uint8Array([1])
|
|
94
|
+
]);
|
|
95
|
+
const key0 = hmacSign(pollEncKey, new Uint8Array(32), 'sha256');
|
|
96
|
+
const decKey = hmacSign(sign, key0, 'sha256');
|
|
97
|
+
const aad = toBinary(`${pollMsgId}\u0000${voterJid}`);
|
|
98
|
+
const decrypted = aesDecryptGCM(encPayload, decKey, encIv, aad);
|
|
99
|
+
return proto.Message.PollVoteMessage.decode(decrypted);
|
|
100
|
+
function toBinary(txt) {
|
|
101
|
+
return Buffer.from(txt);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const processMessage = async (message, { shouldProcessHistoryMsg, placeholderResendCache, ev, creds, signalRepository, keyStore, logger, options }) => {
|
|
105
|
+
const meId = creds.me.id;
|
|
106
|
+
const { accountSettings } = creds;
|
|
107
|
+
const chat = { id: jidNormalizedUser(getChatId(message.key)) };
|
|
108
|
+
const isRealMsg = isRealMessage(message);
|
|
109
|
+
if (isRealMsg) {
|
|
110
|
+
chat.messages = [{ message }];
|
|
111
|
+
chat.conversationTimestamp = toNumber(message.messageTimestamp);
|
|
112
|
+
// only increment unread count if not CIPHERTEXT and from another person
|
|
113
|
+
if (shouldIncrementChatUnread(message)) {
|
|
114
|
+
chat.unreadCount = (chat.unreadCount || 0) + 1;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
const content = normalizeMessageContent(message.message);
|
|
118
|
+
// unarchive chat if it's a real message, or someone reacted to our message
|
|
119
|
+
// and we've the unarchive chats setting on
|
|
120
|
+
if ((isRealMsg || content?.reactionMessage?.key?.fromMe) && accountSettings?.unarchiveChats) {
|
|
121
|
+
chat.archived = false;
|
|
122
|
+
chat.readOnly = false;
|
|
123
|
+
}
|
|
124
|
+
const protocolMsg = content?.protocolMessage;
|
|
125
|
+
if (protocolMsg) {
|
|
126
|
+
switch (protocolMsg.type) {
|
|
127
|
+
case proto.Message.ProtocolMessage.Type.HISTORY_SYNC_NOTIFICATION:
|
|
128
|
+
const histNotification = protocolMsg.historySyncNotification;
|
|
129
|
+
const process = shouldProcessHistoryMsg;
|
|
130
|
+
const isLatest = !creds.processedHistoryMessages?.length;
|
|
131
|
+
logger?.info({
|
|
132
|
+
histNotification,
|
|
133
|
+
process,
|
|
134
|
+
id: message.key.id,
|
|
135
|
+
isLatest
|
|
136
|
+
}, 'got history notification');
|
|
137
|
+
if (process) {
|
|
138
|
+
// TODO: investigate
|
|
139
|
+
if (histNotification.syncType !== proto.HistorySync.HistorySyncType.ON_DEMAND) {
|
|
140
|
+
ev.emit('creds.update', {
|
|
141
|
+
processedHistoryMessages: [
|
|
142
|
+
...(creds.processedHistoryMessages || []),
|
|
143
|
+
{ key: message.key, messageTimestamp: message.messageTimestamp }
|
|
144
|
+
]
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
const data = await downloadAndProcessHistorySyncNotification(histNotification, options);
|
|
148
|
+
ev.emit('messaging-history.set', {
|
|
149
|
+
...data,
|
|
150
|
+
isLatest: histNotification.syncType !== proto.HistorySync.HistorySyncType.ON_DEMAND ? isLatest : undefined,
|
|
151
|
+
peerDataRequestSessionId: histNotification.peerDataRequestSessionId
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
break;
|
|
155
|
+
case proto.Message.ProtocolMessage.Type.APP_STATE_SYNC_KEY_SHARE:
|
|
156
|
+
const keys = protocolMsg.appStateSyncKeyShare.keys;
|
|
157
|
+
if (keys?.length) {
|
|
158
|
+
let newAppStateSyncKeyId = '';
|
|
159
|
+
await keyStore.transaction(async () => {
|
|
160
|
+
const newKeys = [];
|
|
161
|
+
for (const { keyData, keyId } of keys) {
|
|
162
|
+
const strKeyId = Buffer.from(keyId.keyId).toString('base64');
|
|
163
|
+
newKeys.push(strKeyId);
|
|
164
|
+
await keyStore.set({ 'app-state-sync-key': { [strKeyId]: keyData } });
|
|
165
|
+
newAppStateSyncKeyId = strKeyId;
|
|
166
|
+
}
|
|
167
|
+
logger?.info({ newAppStateSyncKeyId, newKeys }, 'injecting new app state sync keys');
|
|
168
|
+
}, meId);
|
|
169
|
+
ev.emit('creds.update', { myAppStateKeyId: newAppStateSyncKeyId });
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
logger?.info({ protocolMsg }, 'recv app state sync with 0 keys');
|
|
173
|
+
}
|
|
174
|
+
break;
|
|
175
|
+
case proto.Message.ProtocolMessage.Type.REVOKE:
|
|
176
|
+
ev.emit('messages.update', [
|
|
177
|
+
{
|
|
178
|
+
key: {
|
|
179
|
+
...message.key,
|
|
180
|
+
id: protocolMsg.key.id
|
|
181
|
+
},
|
|
182
|
+
update: { message: null, messageStubType: WAMessageStubType.REVOKE, key: message.key }
|
|
183
|
+
}
|
|
184
|
+
]);
|
|
185
|
+
break;
|
|
186
|
+
case proto.Message.ProtocolMessage.Type.EPHEMERAL_SETTING:
|
|
187
|
+
Object.assign(chat, {
|
|
188
|
+
ephemeralSettingTimestamp: toNumber(message.messageTimestamp),
|
|
189
|
+
ephemeralExpiration: protocolMsg.ephemeralExpiration || null
|
|
190
|
+
});
|
|
191
|
+
break;
|
|
192
|
+
case proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_RESPONSE_MESSAGE:
|
|
193
|
+
const response = protocolMsg.peerDataOperationRequestResponseMessage;
|
|
194
|
+
if (response) {
|
|
195
|
+
await placeholderResendCache?.del(response.stanzaId);
|
|
196
|
+
// TODO: IMPLEMENT HISTORY SYNC ETC (sticker uploads etc.).
|
|
197
|
+
const { peerDataOperationResult } = response;
|
|
198
|
+
for (const result of peerDataOperationResult) {
|
|
199
|
+
const { placeholderMessageResendResponse: retryResponse } = result;
|
|
200
|
+
//eslint-disable-next-line max-depth
|
|
201
|
+
if (retryResponse) {
|
|
202
|
+
const webMessageInfo = proto.WebMessageInfo.decode(retryResponse.webMessageInfoBytes);
|
|
203
|
+
// wait till another upsert event is available, don't want it to be part of the PDO response message
|
|
204
|
+
// TODO: parse through proper message handling utilities (to add relevant key fields)
|
|
205
|
+
setTimeout(() => {
|
|
206
|
+
ev.emit('messages.upsert', {
|
|
207
|
+
messages: [webMessageInfo],
|
|
208
|
+
type: 'notify',
|
|
209
|
+
requestId: response.stanzaId
|
|
210
|
+
});
|
|
211
|
+
}, 500);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
break;
|
|
216
|
+
case proto.Message.ProtocolMessage.Type.MESSAGE_EDIT:
|
|
217
|
+
ev.emit('messages.update', [
|
|
218
|
+
{
|
|
219
|
+
// flip the sender / fromMe properties because they're in the perspective of the sender
|
|
220
|
+
key: { ...message.key, id: protocolMsg.key?.id },
|
|
221
|
+
update: {
|
|
222
|
+
message: {
|
|
223
|
+
editedMessage: {
|
|
224
|
+
message: protocolMsg.editedMessage
|
|
225
|
+
}
|
|
226
|
+
},
|
|
227
|
+
messageTimestamp: protocolMsg.timestampMs
|
|
228
|
+
? Math.floor(toNumber(protocolMsg.timestampMs) / 1000)
|
|
229
|
+
: message.messageTimestamp
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
]);
|
|
233
|
+
break;
|
|
234
|
+
case proto.Message.ProtocolMessage.Type.LID_MIGRATION_MAPPING_SYNC:
|
|
235
|
+
const encodedPayload = protocolMsg.lidMigrationMappingSyncMessage?.encodedMappingPayload;
|
|
236
|
+
const { pnToLidMappings, chatDbMigrationTimestamp } = proto.LIDMigrationMappingSyncPayload.decode(encodedPayload);
|
|
237
|
+
logger?.debug({ pnToLidMappings, chatDbMigrationTimestamp }, 'got lid mappings and chat db migration timestamp');
|
|
238
|
+
const pairs = [];
|
|
239
|
+
for (const { pn, latestLid, assignedLid } of pnToLidMappings) {
|
|
240
|
+
const lid = latestLid || assignedLid;
|
|
241
|
+
pairs.push({ lid: `${lid}@lid`, pn: `${pn}@s.whatsapp.net` });
|
|
242
|
+
}
|
|
243
|
+
await signalRepository.lidMapping.storeLIDPNMappings(pairs);
|
|
244
|
+
if (pairs.length) {
|
|
245
|
+
for (const { pn, lid } of pairs) {
|
|
246
|
+
await signalRepository.migrateSession(pn, lid);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
else if (content?.reactionMessage) {
|
|
252
|
+
const reaction = {
|
|
253
|
+
...content.reactionMessage,
|
|
254
|
+
key: message.key
|
|
255
|
+
};
|
|
256
|
+
ev.emit('messages.reaction', [
|
|
257
|
+
{
|
|
258
|
+
reaction,
|
|
259
|
+
key: content.reactionMessage?.key
|
|
260
|
+
}
|
|
261
|
+
]);
|
|
262
|
+
}
|
|
263
|
+
else if (message.messageStubType) {
|
|
264
|
+
const jid = message.key?.remoteJid;
|
|
265
|
+
//let actor = whatsappID (message.participant)
|
|
266
|
+
let participants;
|
|
267
|
+
const emitParticipantsUpdate = (action) => ev.emit('group-participants.update', {
|
|
268
|
+
id: jid,
|
|
269
|
+
author: message.key.participant,
|
|
270
|
+
authorPn: message.key.participantAlt,
|
|
271
|
+
participants,
|
|
272
|
+
action
|
|
273
|
+
});
|
|
274
|
+
const emitGroupUpdate = (update) => {
|
|
275
|
+
ev.emit('groups.update', [
|
|
276
|
+
{ id: jid, ...update, author: message.key.participant ?? undefined, authorPn: message.key.participantAlt }
|
|
277
|
+
]);
|
|
278
|
+
};
|
|
279
|
+
const emitGroupRequestJoin = (participant, action, method) => {
|
|
280
|
+
ev.emit('group.join-request', {
|
|
281
|
+
id: jid,
|
|
282
|
+
author: message.key.participant,
|
|
283
|
+
authorPn: message.key.participantAlt,
|
|
284
|
+
participant: participant.lid,
|
|
285
|
+
participantPn: participant.pn,
|
|
286
|
+
action,
|
|
287
|
+
method: method
|
|
288
|
+
});
|
|
289
|
+
};
|
|
290
|
+
const participantsIncludesMe = () => participants.find(jid => areJidsSameUser(meId, jid.phoneNumber)); // ADD SUPPORT FOR LID
|
|
291
|
+
switch (message.messageStubType) {
|
|
292
|
+
case WAMessageStubType.GROUP_PARTICIPANT_CHANGE_NUMBER:
|
|
293
|
+
participants = message.messageStubParameters.map((a) => JSON.parse(a)) || [];
|
|
294
|
+
emitParticipantsUpdate('modify');
|
|
295
|
+
break;
|
|
296
|
+
case WAMessageStubType.GROUP_PARTICIPANT_LEAVE:
|
|
297
|
+
case WAMessageStubType.GROUP_PARTICIPANT_REMOVE:
|
|
298
|
+
participants = message.messageStubParameters.map((a) => JSON.parse(a)) || [];
|
|
299
|
+
emitParticipantsUpdate('remove');
|
|
300
|
+
// mark the chat read only if you left the group
|
|
301
|
+
if (participantsIncludesMe()) {
|
|
302
|
+
chat.readOnly = true;
|
|
303
|
+
}
|
|
304
|
+
break;
|
|
305
|
+
case WAMessageStubType.GROUP_PARTICIPANT_ADD:
|
|
306
|
+
case WAMessageStubType.GROUP_PARTICIPANT_INVITE:
|
|
307
|
+
case WAMessageStubType.GROUP_PARTICIPANT_ADD_REQUEST_JOIN:
|
|
308
|
+
participants = message.messageStubParameters.map((a) => JSON.parse(a)) || [];
|
|
309
|
+
if (participantsIncludesMe()) {
|
|
310
|
+
chat.readOnly = false;
|
|
311
|
+
}
|
|
312
|
+
emitParticipantsUpdate('add');
|
|
313
|
+
break;
|
|
314
|
+
case WAMessageStubType.GROUP_PARTICIPANT_DEMOTE:
|
|
315
|
+
participants = message.messageStubParameters.map((a) => JSON.parse(a)) || [];
|
|
316
|
+
emitParticipantsUpdate('demote');
|
|
317
|
+
break;
|
|
318
|
+
case WAMessageStubType.GROUP_PARTICIPANT_PROMOTE:
|
|
319
|
+
participants = message.messageStubParameters.map((a) => JSON.parse(a)) || [];
|
|
320
|
+
emitParticipantsUpdate('promote');
|
|
321
|
+
break;
|
|
322
|
+
case WAMessageStubType.GROUP_CHANGE_ANNOUNCE:
|
|
323
|
+
const announceValue = message.messageStubParameters?.[0];
|
|
324
|
+
emitGroupUpdate({ announce: announceValue === 'true' || announceValue === 'on' });
|
|
325
|
+
break;
|
|
326
|
+
case WAMessageStubType.GROUP_CHANGE_RESTRICT:
|
|
327
|
+
const restrictValue = message.messageStubParameters?.[0];
|
|
328
|
+
emitGroupUpdate({ restrict: restrictValue === 'true' || restrictValue === 'on' });
|
|
329
|
+
break;
|
|
330
|
+
case WAMessageStubType.GROUP_CHANGE_SUBJECT:
|
|
331
|
+
const name = message.messageStubParameters?.[0];
|
|
332
|
+
chat.name = name;
|
|
333
|
+
emitGroupUpdate({ subject: name });
|
|
334
|
+
break;
|
|
335
|
+
case WAMessageStubType.GROUP_CHANGE_DESCRIPTION:
|
|
336
|
+
const description = message.messageStubParameters?.[0];
|
|
337
|
+
chat.description = description;
|
|
338
|
+
emitGroupUpdate({ desc: description });
|
|
339
|
+
break;
|
|
340
|
+
case WAMessageStubType.GROUP_CHANGE_INVITE_LINK:
|
|
341
|
+
const code = message.messageStubParameters?.[0];
|
|
342
|
+
emitGroupUpdate({ inviteCode: code });
|
|
343
|
+
break;
|
|
344
|
+
case WAMessageStubType.GROUP_MEMBER_ADD_MODE:
|
|
345
|
+
const memberAddValue = message.messageStubParameters?.[0];
|
|
346
|
+
emitGroupUpdate({ memberAddMode: memberAddValue === 'all_member_add' });
|
|
347
|
+
break;
|
|
348
|
+
case WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_MODE:
|
|
349
|
+
const approvalMode = message.messageStubParameters?.[0];
|
|
350
|
+
emitGroupUpdate({ joinApprovalMode: approvalMode === 'on' });
|
|
351
|
+
break;
|
|
352
|
+
case WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD: // TODO: Add other events
|
|
353
|
+
const participant = JSON.parse(message.messageStubParameters?.[0]);
|
|
354
|
+
const action = message.messageStubParameters?.[1];
|
|
355
|
+
const method = message.messageStubParameters?.[2];
|
|
356
|
+
emitGroupRequestJoin(participant, action, method);
|
|
357
|
+
break;
|
|
358
|
+
}
|
|
359
|
+
} /* else if(content?.pollUpdateMessage) {
|
|
360
|
+
const creationMsgKey = content.pollUpdateMessage.pollCreationMessageKey!
|
|
361
|
+
// we need to fetch the poll creation message to get the poll enc key
|
|
362
|
+
// TODO: make standalone, remove getMessage reference
|
|
363
|
+
// TODO: Remove entirely
|
|
364
|
+
const pollMsg = await getMessage(creationMsgKey)
|
|
365
|
+
if(pollMsg) {
|
|
366
|
+
const meIdNormalised = jidNormalizedUser(meId)
|
|
367
|
+
const pollCreatorJid = getKeyAuthor(creationMsgKey, meIdNormalised)
|
|
368
|
+
const voterJid = getKeyAuthor(message.key, meIdNormalised)
|
|
369
|
+
const pollEncKey = pollMsg.messageContextInfo?.messageSecret!
|
|
370
|
+
|
|
371
|
+
try {
|
|
372
|
+
const voteMsg = decryptPollVote(
|
|
373
|
+
content.pollUpdateMessage.vote!,
|
|
374
|
+
{
|
|
375
|
+
pollEncKey,
|
|
376
|
+
pollCreatorJid,
|
|
377
|
+
pollMsgId: creationMsgKey.id!,
|
|
378
|
+
voterJid,
|
|
379
|
+
}
|
|
380
|
+
)
|
|
381
|
+
ev.emit('messages.update', [
|
|
382
|
+
{
|
|
383
|
+
key: creationMsgKey,
|
|
384
|
+
update: {
|
|
385
|
+
pollUpdates: [
|
|
386
|
+
{
|
|
387
|
+
pollUpdateMessageKey: message.key,
|
|
388
|
+
vote: voteMsg,
|
|
389
|
+
senderTimestampMs: (content.pollUpdateMessage.senderTimestampMs! as Long).toNumber(),
|
|
390
|
+
}
|
|
391
|
+
]
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
])
|
|
395
|
+
} catch(err) {
|
|
396
|
+
logger?.warn(
|
|
397
|
+
{ err, creationMsgKey },
|
|
398
|
+
'failed to decrypt poll vote'
|
|
399
|
+
)
|
|
400
|
+
}
|
|
401
|
+
} else {
|
|
402
|
+
logger?.warn(
|
|
403
|
+
{ creationMsgKey },
|
|
404
|
+
'poll creation message not found, cannot decrypt update'
|
|
405
|
+
)
|
|
406
|
+
}
|
|
407
|
+
} */
|
|
408
|
+
if (Object.keys(chat).length > 1) {
|
|
409
|
+
ev.emit('chats.update', [chat]);
|
|
410
|
+
}
|
|
411
|
+
};
|
|
412
|
+
export default processMessage;
|
|
413
|
+
//# sourceMappingURL=process-message.js.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { SignalRepositoryWithLIDStore } from '../Types/index.js';
|
|
2
|
+
import type { AuthenticationCreds, AuthenticationState, KeyPair, SignalIdentity, SignalKeyStore, SignedKeyPair } from '../Types/Auth.js';
|
|
3
|
+
import { type BinaryNode, type FullJid } from '../WABinary/index.js';
|
|
4
|
+
import type { USyncQueryResultList } from '../WAUSync/index.js';
|
|
5
|
+
export declare const createSignalIdentity: (wid: string, accountSignatureKey: Uint8Array) => SignalIdentity;
|
|
6
|
+
export declare const getPreKeys: ({ get }: SignalKeyStore, min: number, limit: number) => Promise<{
|
|
7
|
+
[id: string]: KeyPair;
|
|
8
|
+
}>;
|
|
9
|
+
export declare const generateOrGetPreKeys: (creds: AuthenticationCreds, range: number) => {
|
|
10
|
+
newPreKeys: {
|
|
11
|
+
[id: number]: KeyPair;
|
|
12
|
+
};
|
|
13
|
+
lastPreKeyId: number;
|
|
14
|
+
preKeysRange: readonly [number, number];
|
|
15
|
+
};
|
|
16
|
+
export declare const xmppSignedPreKey: (key: SignedKeyPair) => BinaryNode;
|
|
17
|
+
export declare const xmppPreKey: (pair: KeyPair, id: number) => BinaryNode;
|
|
18
|
+
export declare const parseAndInjectE2ESessions: (node: BinaryNode, repository: SignalRepositoryWithLIDStore) => Promise<void>;
|
|
19
|
+
export declare const extractDeviceJids: (result: USyncQueryResultList[], myJid: string, myLid: string, excludeZeroDevices: boolean) => FullJid[];
|
|
20
|
+
/**
|
|
21
|
+
* get the next N keys for upload or processing
|
|
22
|
+
* @param count number of pre-keys to get or generate
|
|
23
|
+
*/
|
|
24
|
+
export declare const getNextPreKeys: ({ creds, keys }: AuthenticationState, count: number) => Promise<{
|
|
25
|
+
update: Partial<AuthenticationCreds>;
|
|
26
|
+
preKeys: {
|
|
27
|
+
[id: string]: KeyPair;
|
|
28
|
+
};
|
|
29
|
+
}>;
|
|
30
|
+
export declare const getNextPreKeysNode: (state: AuthenticationState, count: number) => Promise<{
|
|
31
|
+
update: Partial<AuthenticationCreds>;
|
|
32
|
+
node: BinaryNode;
|
|
33
|
+
}>;
|
|
34
|
+
//# sourceMappingURL=signal.d.ts.map
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { KEY_BUNDLE_TYPE } from '../Defaults/index.js';
|
|
2
|
+
import { assertNodeErrorFree, getBinaryNodeChild, getBinaryNodeChildBuffer, getBinaryNodeChildren, getBinaryNodeChildUInt, getServerFromDomainType, jidDecode, S_WHATSAPP_NET, WAJIDDomains } from '../WABinary/index.js';
|
|
3
|
+
import { Curve, generateSignalPubKey } from './crypto.js';
|
|
4
|
+
import { encodeBigEndian } from './generics.js';
|
|
5
|
+
function chunk(array, size) {
|
|
6
|
+
const chunks = [];
|
|
7
|
+
for (let i = 0; i < array.length; i += size) {
|
|
8
|
+
chunks.push(array.slice(i, i + size));
|
|
9
|
+
}
|
|
10
|
+
return chunks;
|
|
11
|
+
}
|
|
12
|
+
export const createSignalIdentity = (wid, accountSignatureKey) => {
|
|
13
|
+
return {
|
|
14
|
+
identifier: { name: wid, deviceId: 0 },
|
|
15
|
+
identifierKey: generateSignalPubKey(accountSignatureKey)
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export const getPreKeys = async ({ get }, min, limit) => {
|
|
19
|
+
const idList = [];
|
|
20
|
+
for (let id = min; id < limit; id++) {
|
|
21
|
+
idList.push(id.toString());
|
|
22
|
+
}
|
|
23
|
+
return get('pre-key', idList);
|
|
24
|
+
};
|
|
25
|
+
export const generateOrGetPreKeys = (creds, range) => {
|
|
26
|
+
const avaliable = creds.nextPreKeyId - creds.firstUnuploadedPreKeyId;
|
|
27
|
+
const remaining = range - avaliable;
|
|
28
|
+
const lastPreKeyId = creds.nextPreKeyId + remaining - 1;
|
|
29
|
+
const newPreKeys = {};
|
|
30
|
+
if (remaining > 0) {
|
|
31
|
+
for (let i = creds.nextPreKeyId; i <= lastPreKeyId; i++) {
|
|
32
|
+
newPreKeys[i] = Curve.generateKeyPair();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
newPreKeys,
|
|
37
|
+
lastPreKeyId,
|
|
38
|
+
preKeysRange: [creds.firstUnuploadedPreKeyId, range]
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
export const xmppSignedPreKey = (key) => ({
|
|
42
|
+
tag: 'skey',
|
|
43
|
+
attrs: {},
|
|
44
|
+
content: [
|
|
45
|
+
{ tag: 'id', attrs: {}, content: encodeBigEndian(key.keyId, 3) },
|
|
46
|
+
{ tag: 'value', attrs: {}, content: key.keyPair.public },
|
|
47
|
+
{ tag: 'signature', attrs: {}, content: key.signature }
|
|
48
|
+
]
|
|
49
|
+
});
|
|
50
|
+
export const xmppPreKey = (pair, id) => ({
|
|
51
|
+
tag: 'key',
|
|
52
|
+
attrs: {},
|
|
53
|
+
content: [
|
|
54
|
+
{ tag: 'id', attrs: {}, content: encodeBigEndian(id, 3) },
|
|
55
|
+
{ tag: 'value', attrs: {}, content: pair.public }
|
|
56
|
+
]
|
|
57
|
+
});
|
|
58
|
+
export const parseAndInjectE2ESessions = async (node, repository) => {
|
|
59
|
+
const extractKey = (key) => key
|
|
60
|
+
? {
|
|
61
|
+
keyId: getBinaryNodeChildUInt(key, 'id', 3),
|
|
62
|
+
publicKey: generateSignalPubKey(getBinaryNodeChildBuffer(key, 'value')),
|
|
63
|
+
signature: getBinaryNodeChildBuffer(key, 'signature')
|
|
64
|
+
}
|
|
65
|
+
: undefined;
|
|
66
|
+
const nodes = getBinaryNodeChildren(getBinaryNodeChild(node, 'list'), 'user');
|
|
67
|
+
for (const node of nodes) {
|
|
68
|
+
assertNodeErrorFree(node);
|
|
69
|
+
}
|
|
70
|
+
// Most of the work in repository.injectE2ESession is CPU intensive, not IO
|
|
71
|
+
// So Promise.all doesn't really help here,
|
|
72
|
+
// but blocks even loop if we're using it inside keys.transaction, and it makes it "sync" actually
|
|
73
|
+
// This way we chunk it in smaller parts and between those parts we can yield to the event loop
|
|
74
|
+
// It's rare case when you need to E2E sessions for so many users, but it's possible
|
|
75
|
+
const chunkSize = 100;
|
|
76
|
+
const chunks = chunk(nodes, chunkSize);
|
|
77
|
+
for (const nodesChunk of chunks) {
|
|
78
|
+
for (const node of nodesChunk) {
|
|
79
|
+
const signedKey = getBinaryNodeChild(node, 'skey');
|
|
80
|
+
const key = getBinaryNodeChild(node, 'key');
|
|
81
|
+
const identity = getBinaryNodeChildBuffer(node, 'identity');
|
|
82
|
+
const jid = node.attrs.jid;
|
|
83
|
+
const registrationId = getBinaryNodeChildUInt(node, 'registration', 4);
|
|
84
|
+
await repository.injectE2ESession({
|
|
85
|
+
jid,
|
|
86
|
+
session: {
|
|
87
|
+
registrationId: registrationId,
|
|
88
|
+
identityKey: generateSignalPubKey(identity),
|
|
89
|
+
signedPreKey: extractKey(signedKey),
|
|
90
|
+
preKey: extractKey(key)
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
export const extractDeviceJids = (result, myJid, myLid, excludeZeroDevices) => {
|
|
97
|
+
const { user: myUser, device: myDevice } = jidDecode(myJid);
|
|
98
|
+
const extracted = [];
|
|
99
|
+
for (const userResult of result) {
|
|
100
|
+
const { devices, id } = userResult;
|
|
101
|
+
const decoded = jidDecode(id), { user, server } = decoded;
|
|
102
|
+
let { domainType } = decoded;
|
|
103
|
+
const deviceList = devices?.deviceList;
|
|
104
|
+
if (!Array.isArray(deviceList))
|
|
105
|
+
continue;
|
|
106
|
+
for (const { id: device, keyIndex, isHosted } of deviceList) {
|
|
107
|
+
if ((!excludeZeroDevices || device !== 0) && // if zero devices are not-excluded, or device is non zero
|
|
108
|
+
((myUser !== user && myLid !== user) || myDevice !== device) && // either different user or if me user, not this device
|
|
109
|
+
(device === 0 || !!keyIndex) // ensure that "key-index" is specified for "non-zero" devices, produces a bad req otherwise
|
|
110
|
+
) {
|
|
111
|
+
if (isHosted) {
|
|
112
|
+
domainType = domainType === WAJIDDomains.LID ? WAJIDDomains.HOSTED_LID : WAJIDDomains.HOSTED;
|
|
113
|
+
}
|
|
114
|
+
extracted.push({
|
|
115
|
+
user,
|
|
116
|
+
device,
|
|
117
|
+
domainType,
|
|
118
|
+
server: getServerFromDomainType(server, domainType)
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return extracted;
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* get the next N keys for upload or processing
|
|
127
|
+
* @param count number of pre-keys to get or generate
|
|
128
|
+
*/
|
|
129
|
+
export const getNextPreKeys = async ({ creds, keys }, count) => {
|
|
130
|
+
const { newPreKeys, lastPreKeyId, preKeysRange } = generateOrGetPreKeys(creds, count);
|
|
131
|
+
const update = {
|
|
132
|
+
nextPreKeyId: Math.max(lastPreKeyId + 1, creds.nextPreKeyId),
|
|
133
|
+
firstUnuploadedPreKeyId: Math.max(creds.firstUnuploadedPreKeyId, lastPreKeyId + 1)
|
|
134
|
+
};
|
|
135
|
+
await keys.set({ 'pre-key': newPreKeys });
|
|
136
|
+
const preKeys = await getPreKeys(keys, preKeysRange[0], preKeysRange[0] + preKeysRange[1]);
|
|
137
|
+
return { update, preKeys };
|
|
138
|
+
};
|
|
139
|
+
export const getNextPreKeysNode = async (state, count) => {
|
|
140
|
+
const { creds } = state;
|
|
141
|
+
const { update, preKeys } = await getNextPreKeys(state, count);
|
|
142
|
+
const node = {
|
|
143
|
+
tag: 'iq',
|
|
144
|
+
attrs: {
|
|
145
|
+
xmlns: 'encrypt',
|
|
146
|
+
type: 'set',
|
|
147
|
+
to: S_WHATSAPP_NET
|
|
148
|
+
},
|
|
149
|
+
content: [
|
|
150
|
+
{ tag: 'registration', attrs: {}, content: encodeBigEndian(creds.registrationId) },
|
|
151
|
+
{ tag: 'type', attrs: {}, content: KEY_BUNDLE_TYPE },
|
|
152
|
+
{ tag: 'identity', attrs: {}, content: creds.signedIdentityKey.public },
|
|
153
|
+
{ tag: 'list', attrs: {}, content: Object.keys(preKeys).map(k => xmppPreKey(preKeys[+k], +k)) },
|
|
154
|
+
xmppSignedPreKey(creds.signedPreKey)
|
|
155
|
+
]
|
|
156
|
+
};
|
|
157
|
+
return { update, node };
|
|
158
|
+
};
|
|
159
|
+
//# sourceMappingURL=signal.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { AuthenticationState } from '../Types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* stores the full authentication state in a single folder.
|
|
4
|
+
* Far more efficient than singlefileauthstate
|
|
5
|
+
*
|
|
6
|
+
* Again, I wouldn't endorse this for any production level use other than perhaps a bot.
|
|
7
|
+
* Would recommend writing an auth state for use with a proper SQL or No-SQL DB
|
|
8
|
+
* */
|
|
9
|
+
export declare const useMultiFileAuthState: (folder: string) => Promise<{
|
|
10
|
+
state: AuthenticationState;
|
|
11
|
+
saveCreds: () => Promise<void>;
|
|
12
|
+
}>;
|
|
13
|
+
//# sourceMappingURL=use-multi-file-auth-state.d.ts.map
|