@jkt48connect-corp/baileys 7.3.2 → 7.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +459 -143
- package/WAProto/WAProto.proto +227 -2
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.d.ts +9 -7
- package/lib/Defaults/index.js +6 -4
- package/lib/Socket/Client/index.d.ts +2 -3
- package/lib/Socket/Client/index.js +2 -3
- package/lib/Socket/Client/types.d.ts +17 -0
- package/lib/Socket/Client/types.js +13 -0
- package/lib/Socket/Client/{web-socket-client.d.ts → websocket.d.ts} +1 -1
- package/lib/Socket/Client/{web-socket-client.js → websocket.js} +2 -2
- package/lib/Socket/business.d.ts +8 -3
- package/lib/Socket/chats.d.ts +21 -19
- package/lib/Socket/chats.js +51 -48
- package/lib/Socket/groups.d.ts +28 -26
- package/lib/Socket/groups.js +2 -1
- package/lib/Socket/index.d.ts +6 -3
- package/lib/Socket/messages-recv.d.ts +8 -3
- package/lib/Socket/messages-recv.js +308 -149
- package/lib/Socket/messages-send.d.ts +23 -26
- package/lib/Socket/messages-send.js +193 -166
- package/lib/Socket/newsletter.d.ts +2 -2
- package/lib/Socket/newsletter.js +3 -3
- package/lib/Socket/registration.d.ts +8 -3
- package/lib/Socket/socket.d.ts +8 -6
- package/lib/Socket/socket.js +19 -14
- package/lib/Socket/usync.d.ts +37 -0
- package/lib/Socket/usync.js +70 -0
- package/lib/Store/make-cache-manager-store.d.ts +2 -2
- package/lib/Store/make-ordered-dictionary.d.ts +1 -1
- package/lib/Types/Call.d.ts +1 -1
- package/lib/Types/Chat.d.ts +12 -7
- package/lib/Types/Events.d.ts +17 -2
- package/lib/Types/GroupMetadata.d.ts +3 -1
- package/lib/Types/Label.d.ts +11 -0
- package/lib/Types/Message.d.ts +324 -328
- package/lib/Types/Socket.d.ts +7 -0
- package/lib/Types/USync.d.ts +25 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/index.d.ts +9 -0
- package/lib/Utils/chat-utils.d.ts +4 -4
- package/lib/Utils/chat-utils.js +41 -20
- package/lib/Utils/crypto.d.ts +1 -1
- package/lib/Utils/crypto.js +4 -2
- package/lib/Utils/decode-wa-message.d.ts +17 -0
- package/lib/Utils/decode-wa-message.js +42 -14
- package/lib/Utils/generics.d.ts +4 -10
- package/lib/Utils/generics.js +30 -14
- package/lib/Utils/history.d.ts +6 -2
- package/lib/Utils/history.js +3 -0
- package/lib/Utils/messages.d.ts +0 -1
- package/lib/Utils/messages.js +247 -39
- package/lib/Utils/signal.d.ts +2 -1
- package/lib/Utils/signal.js +11 -19
- package/lib/Utils/use-multi-file-auth-state.js +11 -3
- package/lib/Utils/validate-connection.d.ts +2 -2
- package/lib/Utils/validate-connection.js +1 -1
- package/lib/WABinary/encode.d.ts +1 -1
- package/lib/WABinary/encode.js +16 -10
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
- package/lib/WAUSync/Protocols/index.d.ts +4 -0
- package/lib/WAUSync/Protocols/index.js +20 -0
- package/lib/WAUSync/USyncQuery.d.ts +26 -0
- package/lib/WAUSync/USyncQuery.js +79 -0
- package/lib/WAUSync/USyncUser.d.ts +10 -0
- package/lib/WAUSync/USyncUser.js +22 -0
- package/lib/WAUSync/index.d.ts +3 -0
- package/lib/WAUSync/index.js +19 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/package.json +24 -19
- package/LICENSE +0 -21
- package/lib/index.ts +0 -13
package/lib/Types/Socket.d.ts
CHANGED
@@ -4,6 +4,7 @@ import type { Logger } from 'pino';
|
|
4
4
|
import type { URL } from 'url';
|
5
5
|
import { proto } from '../../WAProto';
|
6
6
|
import { AuthenticationState, SignalAuthState, TransactionCapabilityOptions } from './Auth';
|
7
|
+
import { GroupMetadata } from './GroupMetadata';
|
7
8
|
import { MediaConnInfo } from './Message';
|
8
9
|
import { SignalRepository } from './Signal';
|
9
10
|
export type WAVersion = [number, number, number];
|
@@ -59,6 +60,8 @@ export type SocketConfig = {
|
|
59
60
|
transactionOpts: TransactionCapabilityOptions;
|
60
61
|
/** marks the client as online whenever the socket successfully connects */
|
61
62
|
markOnlineOnConnect: boolean;
|
63
|
+
/** alphanumeric country code (USA -> US) for the number used */
|
64
|
+
countryCode: string;
|
62
65
|
/** provide a cache to store media, so does not have to be re-uploaded */
|
63
66
|
mediaCache?: CacheStore;
|
64
67
|
/**
|
@@ -69,6 +72,8 @@ export type SocketConfig = {
|
|
69
72
|
userDevicesCache?: CacheStore;
|
70
73
|
/** cache to store call offers */
|
71
74
|
callOfferCache?: CacheStore;
|
75
|
+
/** cache to track placeholder resends */
|
76
|
+
placeholderResendCache?: CacheStore;
|
72
77
|
/** width for link preview images */
|
73
78
|
linkPreviewImageThumbnailWidth: number;
|
74
79
|
/** Should Baileys ask the phone for full history, will be received async */
|
@@ -103,6 +108,8 @@ export type SocketConfig = {
|
|
103
108
|
* (solves the "this message can take a while" issue) can be retried
|
104
109
|
* */
|
105
110
|
getMessage: (key: proto.IMessageKey) => Promise<proto.IMessage | undefined>;
|
111
|
+
/** cached group metadata, use to prevent redundant requests to WA & speed up msg sending */
|
112
|
+
cachedGroupMetadata: (jid: string) => Promise<GroupMetadata | undefined>;
|
106
113
|
makeSignalRepository: (auth: SignalAuthState) => SignalRepository;
|
107
114
|
/** Socket passthrough */
|
108
115
|
socket?: any;
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import { BinaryNode } from '../WABinary';
|
2
|
+
import { USyncUser } from '../WAUSync';
|
3
|
+
/**
|
4
|
+
* Defines the interface for a USyncQuery protocol
|
5
|
+
*/
|
6
|
+
export interface USyncQueryProtocol {
|
7
|
+
/**
|
8
|
+
* The name of the protocol
|
9
|
+
*/
|
10
|
+
name: string;
|
11
|
+
/**
|
12
|
+
* Defines what goes inside the query part of a USyncQuery
|
13
|
+
*/
|
14
|
+
getQueryElement: () => BinaryNode;
|
15
|
+
/**
|
16
|
+
* Defines what goes inside the user part of a USyncQuery
|
17
|
+
*/
|
18
|
+
getUserElement: (user: USyncUser) => BinaryNode | null;
|
19
|
+
/**
|
20
|
+
* Parse the result of the query
|
21
|
+
* @param data Data from the result
|
22
|
+
* @returns Whatever the protocol is supposed to return
|
23
|
+
*/
|
24
|
+
parser: (data: BinaryNode) => unknown;
|
25
|
+
}
|
package/lib/Types/index.d.ts
CHANGED
@@ -15,6 +15,15 @@ import { SocketConfig } from './Socket';
|
|
15
15
|
export type UserFacingSocketConfig = Partial<SocketConfig> & {
|
16
16
|
auth: AuthenticationState;
|
17
17
|
};
|
18
|
+
export type BrowsersMap = {
|
19
|
+
ubuntu(browser: string): [string, string, string];
|
20
|
+
macOS(browser: string): [string, string, string];
|
21
|
+
baileys(browser: string): [string, string, string];
|
22
|
+
windows(browser: string): [string, string, string];
|
23
|
+
iOS(browser: string): [string, string, string];
|
24
|
+
linux(browser: string): [string, string, string];
|
25
|
+
appropriate(browser: string): [string, string, string];
|
26
|
+
};
|
18
27
|
export declare enum DisconnectReason {
|
19
28
|
connectionClosed = 428,
|
20
29
|
connectionLost = 408,
|
@@ -28,7 +28,7 @@ export declare const decodeSyncdPatch: (msg: proto.ISyncdPatch, name: WAPatchNam
|
|
28
28
|
};
|
29
29
|
};
|
30
30
|
}>;
|
31
|
-
export declare const extractSyncdPatches: (result: BinaryNode, options: AxiosRequestConfig<
|
31
|
+
export declare const extractSyncdPatches: (result: BinaryNode, options: AxiosRequestConfig<{}>) => Promise<{
|
32
32
|
critical_block: {
|
33
33
|
patches: proto.ISyncdPatch[];
|
34
34
|
hasMorePatches: boolean;
|
@@ -55,13 +55,13 @@ export declare const extractSyncdPatches: (result: BinaryNode, options: AxiosReq
|
|
55
55
|
snapshot?: proto.ISyncdSnapshot;
|
56
56
|
};
|
57
57
|
}>;
|
58
|
-
export declare const downloadExternalBlob: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<
|
59
|
-
export declare const downloadExternalPatch: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<
|
58
|
+
export declare const downloadExternalBlob: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<{}>) => Promise<any>;
|
59
|
+
export declare const downloadExternalPatch: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<{}>) => Promise<proto.SyncdMutations>;
|
60
60
|
export declare const decodeSyncdSnapshot: (name: WAPatchName, snapshot: proto.ISyncdSnapshot, getAppStateSyncKey: FetchAppStateSyncKey, minimumVersionNumber: number | undefined, validateMacs?: boolean) => Promise<{
|
61
61
|
state: LTHashState;
|
62
62
|
mutationMap: ChatMutationMap;
|
63
63
|
}>;
|
64
|
-
export declare const decodePatches: (name: WAPatchName, syncds: proto.ISyncdPatch[], initial: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey, options: AxiosRequestConfig<
|
64
|
+
export declare const decodePatches: (name: WAPatchName, syncds: proto.ISyncdPatch[], initial: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey, options: AxiosRequestConfig<{}>, minimumVersionNumber?: number, logger?: Logger, validateMacs?: boolean) => Promise<{
|
65
65
|
state: LTHashState;
|
66
66
|
mutationMap: ChatMutationMap;
|
67
67
|
}>;
|
package/lib/Utils/chat-utils.js
CHANGED
@@ -305,8 +305,7 @@ const decodePatches = async (name, syncds, initial, getAppStateSyncKey, options,
|
|
305
305
|
indexValueMap: { ...initial.indexValueMap }
|
306
306
|
};
|
307
307
|
const mutationMap = {};
|
308
|
-
for (
|
309
|
-
const syncd = syncds[i];
|
308
|
+
for (const syncd of syncds) {
|
310
309
|
const { version, keyId, snapshotMac } = syncd;
|
311
310
|
if (syncd.externalMutations) {
|
312
311
|
logger === null || logger === void 0 ? void 0 : logger.trace({ name, version }, 'downloading external patch');
|
@@ -418,25 +417,31 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
418
417
|
operation: OP.SET
|
419
418
|
};
|
420
419
|
}
|
420
|
+
else if ('deleteForMe' in mod) {
|
421
|
+
const { timestamp, key, deleteMedia } = mod.deleteForMe;
|
422
|
+
patch = {
|
423
|
+
syncAction: {
|
424
|
+
deleteMessageForMeAction: {
|
425
|
+
deleteMedia,
|
426
|
+
messageTimestamp: timestamp
|
427
|
+
}
|
428
|
+
},
|
429
|
+
index: ['deleteMessageForMe', jid, key.id, key.fromMe ? '1' : '0', '0'],
|
430
|
+
type: 'regular_high',
|
431
|
+
apiVersion: 3,
|
432
|
+
operation: OP.SET
|
433
|
+
};
|
434
|
+
}
|
421
435
|
else if ('clear' in mod) {
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
messageTimestamp: key.timestamp
|
432
|
-
}
|
433
|
-
},
|
434
|
-
index: ['deleteMessageForMe', jid, key.id, key.fromMe ? '1' : '0', '0'],
|
435
|
-
type: 'regular_high',
|
436
|
-
apiVersion: 3,
|
437
|
-
operation: OP.SET
|
438
|
-
};
|
439
|
-
}
|
436
|
+
patch = {
|
437
|
+
syncAction: {
|
438
|
+
clearChatAction: {} // add message range later
|
439
|
+
},
|
440
|
+
index: ['clearChat', jid, '1' /*the option here is 0 when keep starred messages is enabled*/, '0'],
|
441
|
+
type: 'regular_high',
|
442
|
+
apiVersion: 6,
|
443
|
+
operation: OP.SET
|
444
|
+
};
|
440
445
|
}
|
441
446
|
else if ('pin' in mod) {
|
442
447
|
patch = {
|
@@ -491,6 +496,22 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
491
496
|
operation: OP.SET,
|
492
497
|
};
|
493
498
|
}
|
499
|
+
else if ('addLabel' in mod) {
|
500
|
+
patch = {
|
501
|
+
syncAction: {
|
502
|
+
labelEditAction: {
|
503
|
+
name: mod.addLabel.name,
|
504
|
+
color: mod.addLabel.color,
|
505
|
+
predefinedId: mod.addLabel.predefinedId,
|
506
|
+
deleted: mod.addLabel.deleted
|
507
|
+
}
|
508
|
+
},
|
509
|
+
index: ['label_edit', mod.addLabel.id],
|
510
|
+
type: 'regular',
|
511
|
+
apiVersion: 3,
|
512
|
+
operation: OP.SET,
|
513
|
+
};
|
514
|
+
}
|
494
515
|
else if ('addChatLabel' in mod) {
|
495
516
|
patch = {
|
496
517
|
syncAction: {
|
package/lib/Utils/crypto.d.ts
CHANGED
@@ -37,4 +37,4 @@ export declare function hkdf(buffer: Uint8Array | Buffer, expandedLength: number
|
|
37
37
|
salt?: Buffer;
|
38
38
|
info?: string;
|
39
39
|
}): any;
|
40
|
-
export declare function derivePairingCodeKey(pairingCode: string, salt: Buffer): any
|
40
|
+
export declare function derivePairingCodeKey(pairingCode: string, salt: Buffer): Promise<any>;
|
package/lib/Utils/crypto.js
CHANGED
@@ -53,7 +53,9 @@ exports.derivePairingCodeKey = derivePairingCodeKey;
|
|
53
53
|
const crypto_1 = require("crypto");
|
54
54
|
const futoin_hkdf_1 = __importDefault(require("futoin-hkdf"));
|
55
55
|
const libsignal = __importStar(require("libsignal"));
|
56
|
+
const util_1 = require("util");
|
56
57
|
const Defaults_1 = require("../Defaults");
|
58
|
+
const pbkdf2Promise = (0, util_1.promisify)(crypto_1.pbkdf2);
|
57
59
|
/** prefix version byte to the pub keys, required for some curve crypto functions */
|
58
60
|
const generateSignalPubKey = (pubKey) => (pubKey.length === 33
|
59
61
|
? pubKey
|
@@ -156,6 +158,6 @@ function md5(buffer) {
|
|
156
158
|
function hkdf(buffer, expandedLength, info) {
|
157
159
|
return (0, futoin_hkdf_1.default)(!Buffer.isBuffer(buffer) ? Buffer.from(buffer) : buffer, expandedLength, info);
|
158
160
|
}
|
159
|
-
function derivePairingCodeKey(pairingCode, salt) {
|
160
|
-
return
|
161
|
+
async function derivePairingCodeKey(pairingCode, salt) {
|
162
|
+
return await pbkdf2Promise(pairingCode, salt, 2 << 16, 32, 'sha256');
|
161
163
|
}
|
@@ -2,6 +2,23 @@ import { Logger } from 'pino';
|
|
2
2
|
import { proto } from '../../WAProto';
|
3
3
|
import { SignalRepository } from '../Types';
|
4
4
|
import { BinaryNode } from '../WABinary';
|
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;
|
21
|
+
};
|
5
22
|
/**
|
6
23
|
* Decode the received node as a message.
|
7
24
|
* @note this will only parse the message, not decrypt it
|
@@ -1,12 +1,28 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.decryptMessageNode = void 0;
|
3
|
+
exports.decryptMessageNode = exports.NACK_REASONS = exports.MISSING_KEYS_ERROR_TEXT = exports.NO_MESSAGE_FOUND_ERROR_TEXT = void 0;
|
4
4
|
exports.decodeMessageNode = decodeMessageNode;
|
5
5
|
const boom_1 = require("@hapi/boom");
|
6
6
|
const WAProto_1 = require("../../WAProto");
|
7
7
|
const WABinary_1 = require("../WABinary");
|
8
8
|
const generics_1 = require("./generics");
|
9
|
-
|
9
|
+
exports.NO_MESSAGE_FOUND_ERROR_TEXT = 'Message absent from node';
|
10
|
+
exports.MISSING_KEYS_ERROR_TEXT = 'Key used already or never filled';
|
11
|
+
exports.NACK_REASONS = {
|
12
|
+
ParsingError: 487,
|
13
|
+
UnrecognizedStanza: 488,
|
14
|
+
UnrecognizedStanzaClass: 489,
|
15
|
+
UnrecognizedStanzaType: 490,
|
16
|
+
InvalidProtobuf: 491,
|
17
|
+
InvalidHostedCompanionStanza: 493,
|
18
|
+
MissingMessageSecret: 495,
|
19
|
+
SignalErrorOldCounter: 496,
|
20
|
+
MessageDeletedOnPeer: 499,
|
21
|
+
UnhandledError: 500,
|
22
|
+
UnsupportedAdminRevoke: 550,
|
23
|
+
UnsupportedLIDGroup: 551,
|
24
|
+
DBOperationFailed: 552
|
25
|
+
};
|
10
26
|
/**
|
11
27
|
* Decode the received node as a message.
|
12
28
|
* @note this will only parse the message, not decrypt it
|
@@ -113,8 +129,11 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
113
129
|
async decrypt() {
|
114
130
|
var _a;
|
115
131
|
let decryptables = 0;
|
116
|
-
|
132
|
+
if ((0, WABinary_1.isJidNewsLetter)(fullMessage.key.remoteJid)) {
|
133
|
+
const node = (0, WABinary_1.getBinaryNodeChild)(stanza, 'plaintext');
|
134
|
+
const msg = WAProto_1.proto.Message.decode(node === null || node === void 0 ? void 0 : node.content);
|
117
135
|
if (msg.senderKeyDistributionMessage) {
|
136
|
+
//eslint-disable-next-line max-depth
|
118
137
|
try {
|
119
138
|
await repository.processSenderKeyDistributionMessage({
|
120
139
|
authorJid: author,
|
@@ -122,14 +141,9 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
122
141
|
});
|
123
142
|
}
|
124
143
|
catch (err) {
|
125
|
-
logger.error({ key: fullMessage.key, err }, 'failed to
|
144
|
+
logger.error({ key: fullMessage.key, err }, 'failed to decrypt message');
|
126
145
|
}
|
127
146
|
}
|
128
|
-
}
|
129
|
-
if ((0, WABinary_1.isJidNewsLetter)(fullMessage.key.remoteJid)) {
|
130
|
-
const node = (0, WABinary_1.getBinaryNodeChild)(stanza, 'plaintext');
|
131
|
-
const msg = WAProto_1.proto.Message.decode(node === null || node === void 0 ? void 0 : node.content);
|
132
|
-
await processSenderKeyDistribution(msg);
|
133
147
|
fullMessage.message = msg;
|
134
148
|
decryptables += 1;
|
135
149
|
}
|
@@ -140,7 +154,7 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
140
154
|
const details = WAProto_1.proto.VerifiedNameCertificate.Details.decode(cert.details);
|
141
155
|
fullMessage.verifiedBizName = details.verifiedName;
|
142
156
|
}
|
143
|
-
if (tag !== 'enc') {
|
157
|
+
if (tag !== 'enc' && tag !== 'plaintext') {
|
144
158
|
continue;
|
145
159
|
}
|
146
160
|
if (!(content instanceof Uint8Array)) {
|
@@ -149,7 +163,7 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
149
163
|
decryptables += 1;
|
150
164
|
let msgBuffer;
|
151
165
|
try {
|
152
|
-
const e2eType = attrs.type;
|
166
|
+
const e2eType = tag === 'plaintext' ? 'plaintext' : attrs.type;
|
153
167
|
switch (e2eType) {
|
154
168
|
case 'skmsg':
|
155
169
|
msgBuffer = await repository.decryptGroupMessage({
|
@@ -167,12 +181,26 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
167
181
|
ciphertext: content
|
168
182
|
});
|
169
183
|
break;
|
184
|
+
case 'plaintext':
|
185
|
+
msgBuffer = content;
|
186
|
+
break;
|
170
187
|
default:
|
171
188
|
throw new Error(`Unknown e2e type: ${e2eType}`);
|
172
189
|
}
|
173
|
-
let msg = WAProto_1.proto.Message.decode((0, generics_1.unpadRandomMax16)(msgBuffer));
|
190
|
+
let msg = WAProto_1.proto.Message.decode(e2eType !== 'plaintext' ? (0, generics_1.unpadRandomMax16)(msgBuffer) : msgBuffer);
|
174
191
|
msg = ((_a = msg.deviceSentMessage) === null || _a === void 0 ? void 0 : _a.message) || msg;
|
175
|
-
|
192
|
+
if (msg.senderKeyDistributionMessage) {
|
193
|
+
//eslint-disable-next-line max-depth
|
194
|
+
try {
|
195
|
+
await repository.processSenderKeyDistributionMessage({
|
196
|
+
authorJid: author,
|
197
|
+
item: msg.senderKeyDistributionMessage
|
198
|
+
});
|
199
|
+
}
|
200
|
+
catch (err) {
|
201
|
+
logger.error({ key: fullMessage.key, err }, 'failed to decrypt message');
|
202
|
+
}
|
203
|
+
}
|
176
204
|
if (fullMessage.message) {
|
177
205
|
Object.assign(fullMessage.message, msg);
|
178
206
|
}
|
@@ -190,7 +218,7 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
190
218
|
// if nothing was found to decrypt
|
191
219
|
if (!decryptables) {
|
192
220
|
fullMessage.messageStubType = WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT;
|
193
|
-
fullMessage.messageStubParameters = [NO_MESSAGE_FOUND_ERROR_TEXT
|
221
|
+
fullMessage.messageStubParameters = [exports.NO_MESSAGE_FOUND_ERROR_TEXT];
|
194
222
|
}
|
195
223
|
}
|
196
224
|
};
|
package/lib/Utils/generics.d.ts
CHANGED
@@ -1,16 +1,10 @@
|
|
1
1
|
import { AxiosRequestConfig } from 'axios';
|
2
2
|
import { Logger } from 'pino';
|
3
3
|
import { proto } from '../../WAProto';
|
4
|
-
import { BaileysEventEmitter, BaileysEventMap, WACallUpdateType, WAVersion } from '../Types';
|
4
|
+
import { BaileysEventEmitter, BaileysEventMap, BrowsersMap, ConnectionState, WACallUpdateType, WAVersion } from '../Types';
|
5
5
|
import { BinaryNode } from '../WABinary';
|
6
|
-
export declare const Browsers:
|
7
|
-
|
8
|
-
macOS: (browser: any) => [string, string, string];
|
9
|
-
baileys: (browser: any) => [string, string, string];
|
10
|
-
windows: (browser: any) => [string, string, string];
|
11
|
-
/** The appropriate browser based on your OS & release */
|
12
|
-
appropriate: (browser: any) => [string, string, string];
|
13
|
-
};
|
6
|
+
export declare const Browsers: BrowsersMap;
|
7
|
+
export declare const getPlatformId: (browser: string) => any;
|
14
8
|
export declare const BufferJSON: {
|
15
9
|
replacer: (k: any, value: any) => any;
|
16
10
|
reviver: (_: any, value: any) => any;
|
@@ -40,7 +34,7 @@ export declare function promiseTimeout<T>(ms: number | undefined, promise: (reso
|
|
40
34
|
export declare const generateMessageIDV2: (userId?: string) => string;
|
41
35
|
export declare const generateMessageID: () => string;
|
42
36
|
export declare function bindWaitForEvent<T extends keyof BaileysEventMap>(ev: BaileysEventEmitter, event: T): (check: (u: BaileysEventMap[T]) => boolean | undefined, timeoutMs?: number) => Promise<void>;
|
43
|
-
export declare const bindWaitForConnectionUpdate: (ev: BaileysEventEmitter) => (check: (u: Partial<
|
37
|
+
export declare const bindWaitForConnectionUpdate: (ev: BaileysEventEmitter) => (check: (u: Partial<ConnectionState>) => boolean | undefined, timeoutMs?: number) => Promise<void>;
|
44
38
|
export declare const printQRIfNecessaryListener: (ev: BaileysEventEmitter, logger: Logger) => void;
|
45
39
|
/**
|
46
40
|
* utility that fetches latest baileys version from the master branch.
|
package/lib/Utils/generics.js
CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.isWABusinessPlatform = exports.getCodeFromWSError = exports.getCallStatusFromNode = exports.getErrorCodeFromStreamError = exports.getStatusFromReceiptType = exports.generateMdTagPrefix = exports.fetchLatestWaWebVersion = exports.fetchLatestBaileysVersion = exports.printQRIfNecessaryListener = exports.bindWaitForConnectionUpdate = exports.generateMessageID = exports.generateMessageIDV2 = exports.delayCancellable = exports.delay = exports.debouncedTimeout = exports.unixTimestampSeconds = exports.toNumber = exports.encodeBigEndian = exports.generateRegistrationId = exports.encodeWAMessage = exports.unpadRandomMax16 = exports.writeRandomPadMax16 = exports.getKeyAuthor = exports.BufferJSON = exports.Browsers = void 0;
|
6
|
+
exports.isWABusinessPlatform = exports.getCodeFromWSError = exports.getCallStatusFromNode = exports.getErrorCodeFromStreamError = exports.getStatusFromReceiptType = exports.generateMdTagPrefix = exports.fetchLatestWaWebVersion = exports.fetchLatestBaileysVersion = exports.printQRIfNecessaryListener = exports.bindWaitForConnectionUpdate = exports.generateMessageID = exports.generateMessageIDV2 = exports.delayCancellable = exports.delay = exports.debouncedTimeout = exports.unixTimestampSeconds = exports.toNumber = exports.encodeBigEndian = exports.generateRegistrationId = exports.encodeWAMessage = exports.unpadRandomMax16 = exports.writeRandomPadMax16 = exports.getKeyAuthor = exports.BufferJSON = exports.getPlatformId = exports.Browsers = void 0;
|
7
7
|
exports.promiseTimeout = promiseTimeout;
|
8
8
|
exports.bindWaitForEvent = bindWaitForEvent;
|
9
9
|
exports.trimUndefined = trimUndefined;
|
@@ -16,20 +16,37 @@ const WAProto_1 = require("../../WAProto");
|
|
16
16
|
const baileys_version_json_1 = require("../Defaults/baileys-version.json");
|
17
17
|
const Types_1 = require("../Types");
|
18
18
|
const WABinary_1 = require("../WABinary");
|
19
|
+
const COMPANION_PLATFORM_MAP = {
|
20
|
+
'Chrome': '49',
|
21
|
+
'Edge': '50',
|
22
|
+
'Firefox': '51',
|
23
|
+
'Opera': '53',
|
24
|
+
'Safari': '54'
|
25
|
+
};
|
19
26
|
const PLATFORM_MAP = {
|
20
27
|
'aix': 'AIX',
|
21
28
|
'darwin': 'Mac OS',
|
22
29
|
'win32': 'Windows',
|
23
|
-
'android': 'Android'
|
30
|
+
'android': 'Android',
|
31
|
+
'freebsd': 'FreeBSD',
|
32
|
+
'openbsd': 'OpenBSD',
|
33
|
+
'sunos': 'Solaris'
|
24
34
|
};
|
25
35
|
exports.Browsers = {
|
26
|
-
ubuntu: browser => ['Ubuntu', browser, '
|
27
|
-
macOS: browser => ['Mac OS', browser, '
|
28
|
-
baileys: browser => ['Baileys', browser, '
|
29
|
-
windows: browser => ['Windows', browser, '10.0.
|
36
|
+
ubuntu: (browser) => ['Ubuntu', browser, '22.04.4'],
|
37
|
+
macOS: (browser) => ['Mac OS', browser, '14.4.1'],
|
38
|
+
baileys: (browser) => ['Baileys', browser, '6.5.0'],
|
39
|
+
windows: (browser) => ['Windows', browser, '10.0.22631'],
|
40
|
+
iOS: (browser) => ['iOS', browser, '18.2'],
|
41
|
+
linux: (browser) => ['Linux', browser, '6.12.6'],
|
30
42
|
/** The appropriate browser based on your OS & release */
|
31
|
-
appropriate: browser => [PLATFORM_MAP[(0, os_1.platform)()] || 'Ubuntu', browser, (0, os_1.release)()]
|
43
|
+
appropriate: (browser) => [PLATFORM_MAP[(0, os_1.platform)()] || 'Ubuntu', browser, (0, os_1.release)()]
|
44
|
+
};
|
45
|
+
const getPlatformId = (browser) => {
|
46
|
+
const platformType = WAProto_1.proto.DeviceProps.PlatformType[browser.toUpperCase()];
|
47
|
+
return platformType ? platformType.toString() : '1' //chrome
|
32
48
|
};
|
49
|
+
exports.getPlatformId = getPlatformId;
|
33
50
|
exports.BufferJSON = {
|
34
51
|
replacer: (k, value) => {
|
35
52
|
if (Buffer.isBuffer(value) || value instanceof Uint8Array || (value === null || value === void 0 ? void 0 : value.type) === 'Buffer') {
|
@@ -150,7 +167,6 @@ async function promiseTimeout(ms, promise) {
|
|
150
167
|
.finally(cancel);
|
151
168
|
return p;
|
152
169
|
}
|
153
|
-
// ngapain? nyolong kah? wkwkwk minimal punya skill sendiri, gak modal nyolong!!
|
154
170
|
const generateMessageIDV2 = (userId) => {
|
155
171
|
const data = Buffer.alloc(8 + 20 + 16);
|
156
172
|
data.writeBigUInt64BE(BigInt(Math.floor(Date.now() / 1000)));
|
@@ -161,15 +177,14 @@ const generateMessageIDV2 = (userId) => {
|
|
161
177
|
data.write('@c.us', 8 + id.user.length);
|
162
178
|
}
|
163
179
|
}
|
164
|
-
const random = (0, crypto_1.randomBytes)(
|
180
|
+
const random = (0, crypto_1.randomBytes)(16);
|
165
181
|
random.copy(data, 28);
|
166
182
|
const hash = (0, crypto_1.createHash)('sha256').update(data).digest();
|
167
|
-
return hash.toString('hex').toUpperCase().substring(0, 18);
|
183
|
+
return 'BAE5-' + hash.toString('hex').toUpperCase().substring(0, 18);
|
168
184
|
};
|
169
185
|
exports.generateMessageIDV2 = generateMessageIDV2;
|
170
|
-
|
171
|
-
|
172
|
-
};
|
186
|
+
// generate a random ID to attach to a message
|
187
|
+
const generateMessageID = () => 'FTG-' + (0, crypto_1.randomBytes)(6).toString('hex').toUpperCase();
|
173
188
|
exports.generateMessageID = generateMessageID;
|
174
189
|
function bindWaitForEvent(ev, event) {
|
175
190
|
return async (check, timeoutMs) => {
|
@@ -316,7 +331,8 @@ const getCallStatusFromNode = ({ tag, attrs }) => {
|
|
316
331
|
status = 'timeout';
|
317
332
|
}
|
318
333
|
else {
|
319
|
-
|
334
|
+
//fired when accepted/rejected/timeout/caller hangs up
|
335
|
+
status = 'terminate';
|
320
336
|
}
|
321
337
|
break;
|
322
338
|
case 'reject':
|
package/lib/Utils/history.d.ts
CHANGED
@@ -1,15 +1,19 @@
|
|
1
1
|
import { AxiosRequestConfig } from 'axios';
|
2
2
|
import { proto } from '../../WAProto';
|
3
3
|
import { Chat, Contact } from '../Types';
|
4
|
-
export declare const downloadHistory: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<
|
4
|
+
export declare const downloadHistory: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<{}>) => Promise<proto.HistorySync>;
|
5
5
|
export declare const processHistoryMessage: (item: proto.IHistorySync) => {
|
6
6
|
chats: Chat[];
|
7
7
|
contacts: Contact[];
|
8
8
|
messages: proto.IWebMessageInfo[];
|
9
|
+
syncType: proto.HistorySync.HistorySyncType;
|
10
|
+
progress: number | null | undefined;
|
9
11
|
};
|
10
|
-
export declare const downloadAndProcessHistorySyncNotification: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<
|
12
|
+
export declare const downloadAndProcessHistorySyncNotification: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<{}>) => Promise<{
|
11
13
|
chats: Chat[];
|
12
14
|
contacts: Contact[];
|
13
15
|
messages: proto.IWebMessageInfo[];
|
16
|
+
syncType: proto.HistorySync.HistorySyncType;
|
17
|
+
progress: number | null | undefined;
|
14
18
|
}>;
|
15
19
|
export declare const getHistoryMsg: (message: proto.IMessage) => proto.Message.IHistorySyncNotification | null | undefined;
|
package/lib/Utils/history.js
CHANGED
@@ -32,6 +32,7 @@ const processHistoryMessage = (item) => {
|
|
32
32
|
case WAProto_1.proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP:
|
33
33
|
case WAProto_1.proto.HistorySync.HistorySyncType.RECENT:
|
34
34
|
case WAProto_1.proto.HistorySync.HistorySyncType.FULL:
|
35
|
+
case WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND:
|
35
36
|
for (const chat of item.conversations) {
|
36
37
|
contacts.push({ id: chat.id, name: chat.name || undefined });
|
37
38
|
const msgs = chat.messages || [];
|
@@ -74,6 +75,8 @@ const processHistoryMessage = (item) => {
|
|
74
75
|
chats,
|
75
76
|
contacts,
|
76
77
|
messages,
|
78
|
+
syncType: item.syncType,
|
79
|
+
progress: item.progress
|
77
80
|
};
|
78
81
|
};
|
79
82
|
exports.processHistoryMessage = processHistoryMessage;
|