cuki-bailx 1.1.2 → 1.2.2
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/WAProto/index.js +79296 -118676
- package/engine-requirements.js +1 -1
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.d.ts +6 -4
- package/lib/Defaults/index.js +102 -78
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Socket/Client/{types.d.ts → abstract-socket-client.d.ts} +2 -1
- package/lib/Socket/Client/index.d.ts +3 -2
- package/lib/Socket/Client/index.js +3 -2
- package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
- package/lib/Socket/Client/mobile-socket-client.js +65 -0
- package/lib/Socket/Client/{websocket.d.ts → web-socket-client.d.ts} +1 -2
- package/lib/Socket/Client/{websocket.js → web-socket-client.js} +2 -12
- package/lib/Socket/business.d.ts +58 -59
- package/lib/Socket/chats.d.ts +27 -29
- package/lib/Socket/chats.js +90 -97
- package/lib/Socket/dugong.d.ts +219 -0
- package/lib/Socket/dugong.js +441 -0
- package/lib/Socket/groups.d.ts +32 -41
- package/lib/Socket/groups.js +5 -20
- package/lib/Socket/index.d.ts +64 -63
- package/lib/Socket/index.js +2 -2
- package/lib/Socket/messages-recv.js +65 -9
- package/lib/Socket/messages-send.d.ts +47 -49
- package/lib/Socket/messages-send.js +312 -379
- package/lib/Socket/newsletter.d.ts +37 -39
- package/lib/Socket/newsletter.js +40 -54
- package/lib/Socket/registration.d.ts +267 -0
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.d.ts +10 -10
- package/lib/Socket/socket.js +32 -39
- package/lib/Socket/socket.js.bak +630 -0
- package/lib/Socket/usync.d.ts +3 -3
- package/lib/Store/index.d.ts +2 -1
- package/lib/Store/index.js +3 -1
- package/lib/Store/make-cache-manager-store.d.ts +13 -0
- package/lib/Store/make-cache-manager-store.js +83 -0
- package/lib/Store/make-in-memory-store.d.ts +24 -24
- package/lib/Store/make-in-memory-store.js +11 -13
- package/lib/Store/make-ordered-dictionary.d.ts +1 -1
- package/lib/Store/make-ordered-dictionary.js +2 -2
- package/lib/Types/Auth.d.ts +7 -0
- package/lib/Types/Call.d.ts +1 -1
- package/lib/Types/Chat.d.ts +7 -14
- package/lib/Types/Contact.d.ts +1 -5
- package/lib/Types/Events.d.ts +2 -44
- package/lib/Types/GroupMetadata.d.ts +2 -11
- package/lib/Types/Label.js +1 -1
- package/lib/Types/LabelAssociation.js +1 -1
- package/lib/Types/Message.d.ts +21 -148
- package/lib/Types/Message.js +2 -0
- package/lib/Types/Newsletter.d.ts +13 -0
- package/lib/Types/Newsletter.js +17 -3
- package/lib/Types/Socket.d.ts +9 -17
- package/lib/Types/index.d.ts +1 -8
- package/lib/Types/index.js +2 -2
- package/lib/Utils/auth-utils.d.ts +3 -3
- package/lib/Utils/auth-utils.js +13 -6
- package/lib/Utils/business.js +2 -2
- package/lib/Utils/chat-utils.d.ts +16 -15
- package/lib/Utils/chat-utils.js +35 -36
- package/lib/Utils/crypto.d.ts +16 -15
- package/lib/Utils/crypto.js +29 -71
- package/lib/Utils/decode-wa-message.d.ts +6 -22
- package/lib/Utils/decode-wa-message.js +56 -65
- package/lib/Utils/event-buffer.d.ts +2 -2
- package/lib/Utils/event-buffer.js +7 -11
- package/lib/Utils/generics.d.ts +20 -17
- package/lib/Utils/generics.js +23 -73
- package/lib/Utils/history.d.ts +0 -4
- package/lib/Utils/history.js +6 -4
- package/lib/Utils/link-preview.d.ts +2 -2
- package/lib/Utils/link-preview.js +1 -34
- package/lib/Utils/logger.d.ts +3 -10
- package/lib/Utils/lt-hash.d.ts +2 -2
- package/lib/Utils/lt-hash.js +6 -6
- package/lib/Utils/make-mutex.d.ts +2 -2
- package/lib/Utils/messages-media.d.ts +24 -28
- package/lib/Utils/messages-media.js +115 -263
- package/lib/Utils/messages.d.ts +10 -8
- package/lib/Utils/messages.js +72 -298
- package/lib/Utils/noise-handler.d.ts +12 -10
- package/lib/Utils/noise-handler.js +23 -18
- package/lib/Utils/process-message.d.ts +4 -5
- package/lib/Utils/process-message.js +23 -74
- package/lib/Utils/signal.d.ts +1 -2
- package/lib/Utils/signal.js +35 -37
- package/lib/Utils/use-multi-file-auth-state.d.ts +1 -0
- package/lib/Utils/use-multi-file-auth-state.js +6 -51
- package/lib/Utils/validate-connection.d.ts +4 -3
- package/lib/Utils/validate-connection.js +52 -20
- package/lib/WABinary/constants.d.ts +4 -4
- package/lib/WABinary/constants.js +13 -1276
- package/lib/WABinary/decode.d.ts +4 -3
- package/lib/WABinary/decode.js +13 -26
- package/lib/WABinary/encode.d.ts +2 -1
- package/lib/WABinary/encode.js +17 -39
- package/lib/WABinary/generic-utils.d.ts +3 -1
- package/lib/WABinary/generic-utils.js +85 -2
- package/lib/WABinary/jid-utils.d.ts +5 -10
- package/lib/WABinary/jid-utils.js +5 -26
- package/lib/WAM/BinaryInfo.d.ts +11 -2
- package/lib/WAM/encode.d.ts +2 -1
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +1 -1
- package/lib/index.d.ts +2 -6
- package/lib/index.js +7 -22
- package/lib/index.js.bak +37 -0
- package/package.json +103 -111
- package/LICENSE +0 -21
- package/WAProto/GenerateStatics.sh +0 -4
- package/WAProto/WAProto.proto +0 -4775
- package/WAProto/index.d.ts +0 -55057
- package/WAProto/index.ts.ts +0 -53473
- package/WAProto/p.html +0 -1
- package/lib/WABinary/jid-utils.js.bak +0 -83
- /package/lib/Socket/Client/{types.js → abstract-socket-client.js} +0 -0
|
@@ -176,9 +176,6 @@ function append(data, historyCache, event, eventData, logger) {
|
|
|
176
176
|
}
|
|
177
177
|
}
|
|
178
178
|
data.historySets.empty = false;
|
|
179
|
-
data.historySets.syncType = eventData.syncType;
|
|
180
|
-
data.historySets.progress = eventData.progress;
|
|
181
|
-
data.historySets.peerDataRequestSessionId = eventData.peerDataRequestSessionId;
|
|
182
179
|
data.historySets.isLatest = eventData.isLatest || data.historySets.isLatest;
|
|
183
180
|
break;
|
|
184
181
|
case 'chats.upsert':
|
|
@@ -445,10 +442,7 @@ function consolidateEvents(data) {
|
|
|
445
442
|
chats: Object.values(data.historySets.chats),
|
|
446
443
|
messages: Object.values(data.historySets.messages),
|
|
447
444
|
contacts: Object.values(data.historySets.contacts),
|
|
448
|
-
|
|
449
|
-
progress: data.historySets.progress,
|
|
450
|
-
isLatest: data.historySets.isLatest,
|
|
451
|
-
peerDataRequestSessionId: data.historySets.peerDataRequestSessionId
|
|
445
|
+
isLatest: data.historySets.isLatest
|
|
452
446
|
};
|
|
453
447
|
}
|
|
454
448
|
const chatUpsertList = Object.values(data.chatUpserts);
|
|
@@ -502,10 +496,12 @@ function consolidateEvents(data) {
|
|
|
502
496
|
return map;
|
|
503
497
|
}
|
|
504
498
|
function concatChats(a, b) {
|
|
505
|
-
if (b.unreadCount === null
|
|
506
|
-
|
|
507
|
-
a.unreadCount
|
|
508
|
-
|
|
499
|
+
if (b.unreadCount === null) {
|
|
500
|
+
// neutralize unread counter
|
|
501
|
+
if (a.unreadCount < 0) {
|
|
502
|
+
a.unreadCount = undefined;
|
|
503
|
+
b.unreadCount = undefined;
|
|
504
|
+
}
|
|
509
505
|
}
|
|
510
506
|
if (typeof a.unreadCount === 'number' && typeof b.unreadCount === 'number') {
|
|
511
507
|
b = { ...b };
|
package/lib/Utils/generics.d.ts
CHANGED
|
@@ -1,21 +1,24 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import { AxiosRequestConfig } from 'axios';
|
|
2
|
-
import {
|
|
3
|
+
import { Logger } from 'pino';
|
|
3
4
|
import { proto } from '../../WAProto';
|
|
4
|
-
import { BaileysEventEmitter, BaileysEventMap,
|
|
5
|
+
import { BaileysEventEmitter, BaileysEventMap, WACallUpdateType, WAVersion } from '../Types';
|
|
5
6
|
import { BinaryNode } from '../WABinary';
|
|
6
|
-
export declare const Browsers:
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
export declare const Browsers: {
|
|
8
|
+
ubuntu: (browser: any) => [string, string, string];
|
|
9
|
+
macOS: (browser: any) => [string, string, string];
|
|
10
|
+
baileys: (browser: any) => [string, string, string];
|
|
11
|
+
windows: (browser: any) => [string, string, string];
|
|
12
|
+
/** The appropriate browser based on your OS & release */
|
|
13
|
+
appropriate: (browser: any) => [string, string, string];
|
|
11
14
|
};
|
|
15
|
+
export declare const getPlatformId: (browser: string) => any;
|
|
12
16
|
export declare const getKeyAuthor: (key: proto.IMessageKey | undefined | null, meId?: string) => string;
|
|
13
|
-
export declare const writeRandomPadMax16: (msg: Uint8Array) => Buffer
|
|
14
|
-
export declare const unpadRandomMax16: (e: Uint8Array | Buffer) => Uint8Array
|
|
15
|
-
export declare const encodeWAMessage: (message: proto.IMessage) => Buffer
|
|
16
|
-
export declare const encodeNewsletterMessage: (message: proto.IMessage) => Uint8Array<ArrayBufferLike>;
|
|
17
|
+
export declare const writeRandomPadMax16: (msg: Uint8Array) => Buffer;
|
|
18
|
+
export declare const unpadRandomMax16: (e: Uint8Array | Buffer) => Uint8Array;
|
|
19
|
+
export declare const encodeWAMessage: (message: proto.IMessage) => Buffer;
|
|
17
20
|
export declare const generateRegistrationId: () => number;
|
|
18
|
-
export declare const encodeBigEndian: (e: number, t?: number) => Uint8Array
|
|
21
|
+
export declare const encodeBigEndian: (e: number, t?: number) => Uint8Array;
|
|
19
22
|
export declare const toNumber: (t: Long | number | null | undefined) => number;
|
|
20
23
|
/** unix timestamp of a date in seconds */
|
|
21
24
|
export declare const unixTimestampSeconds: (date?: Date) => number;
|
|
@@ -34,9 +37,9 @@ export declare const delayCancellable: (ms: number) => {
|
|
|
34
37
|
export declare function promiseTimeout<T>(ms: number | undefined, promise: (resolve: (v: T) => void, reject: (error: any) => void) => void): Promise<T>;
|
|
35
38
|
export declare const generateMessageIDV2: (userId?: string) => string;
|
|
36
39
|
export declare const generateMessageID: () => string;
|
|
37
|
-
export declare function bindWaitForEvent<T extends keyof BaileysEventMap>(ev: BaileysEventEmitter, event: T): (check: (u: BaileysEventMap[T]) =>
|
|
38
|
-
export declare const bindWaitForConnectionUpdate: (ev: BaileysEventEmitter) => (check: (u: Partial<import("../Types").ConnectionState>) =>
|
|
39
|
-
export declare const printQRIfNecessaryListener: (ev: BaileysEventEmitter, logger:
|
|
40
|
+
export declare function bindWaitForEvent<T extends keyof BaileysEventMap>(ev: BaileysEventEmitter, event: T): (check: (u: BaileysEventMap[T]) => boolean | undefined, timeoutMs?: number) => Promise<void>;
|
|
41
|
+
export declare const bindWaitForConnectionUpdate: (ev: BaileysEventEmitter) => (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number) => Promise<void>;
|
|
42
|
+
export declare const printQRIfNecessaryListener: (ev: BaileysEventEmitter, logger: Logger) => void;
|
|
40
43
|
/**
|
|
41
44
|
* utility that fetches latest baileys version from the master branch.
|
|
42
45
|
* Use to ensure your WA connection is always on the latest version
|
|
@@ -54,7 +57,7 @@ export declare const fetchLatestBaileysVersion: (options?: AxiosRequestConfig<an
|
|
|
54
57
|
* A utility that fetches the latest web version of whatsapp.
|
|
55
58
|
* Use to ensure your WA connection is always on the latest version
|
|
56
59
|
*/
|
|
57
|
-
export declare const fetchLatestWaWebVersion: (options: AxiosRequestConfig<
|
|
60
|
+
export declare const fetchLatestWaWebVersion: (options: AxiosRequestConfig<any>) => Promise<{
|
|
58
61
|
version: WAVersion;
|
|
59
62
|
isLatest: boolean;
|
|
60
63
|
error?: undefined;
|
|
@@ -84,6 +87,6 @@ export declare const getCodeFromWSError: (error: Error) => number;
|
|
|
84
87
|
* Is the given platform WA business
|
|
85
88
|
* @param platform AuthenticationCreds.platform
|
|
86
89
|
*/
|
|
87
|
-
export declare const isWABusinessPlatform: (platform: string) =>
|
|
90
|
+
export declare const isWABusinessPlatform: (platform: string) => boolean;
|
|
88
91
|
export declare function trimUndefined(obj: any): any;
|
|
89
92
|
export declare function bytesToCrockford(buffer: Buffer): string;
|
package/lib/Utils/generics.js
CHANGED
|
@@ -1,46 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
1
|
+
"use strict";
|
|
35
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
4
|
};
|
|
38
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
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.
|
|
40
|
-
exports.promiseTimeout = promiseTimeout;
|
|
41
|
-
exports.bindWaitForEvent = bindWaitForEvent;
|
|
42
|
-
exports.trimUndefined = trimUndefined;
|
|
43
|
-
exports.bytesToCrockford = bytesToCrockford;
|
|
6
|
+
exports.bytesToCrockford = exports.trimUndefined = exports.isWABusinessPlatform = exports.getCodeFromWSError = exports.getCallStatusFromNode = exports.getErrorCodeFromStreamError = exports.getStatusFromReceiptType = exports.generateMdTagPrefix = exports.fetchLatestWaWebVersion = exports.fetchLatestBaileysVersion = exports.printQRIfNecessaryListener = exports.bindWaitForConnectionUpdate = exports.bindWaitForEvent = exports.generateMessageID = exports.generateMessageIDV2 = exports.promiseTimeout = 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;
|
|
44
7
|
const boom_1 = require("@hapi/boom");
|
|
45
8
|
const axios_1 = __importDefault(require("axios"));
|
|
46
9
|
const crypto_1 = require("crypto");
|
|
@@ -49,13 +12,6 @@ const WAProto_1 = require("../../WAProto");
|
|
|
49
12
|
const baileys_version_json_1 = require("../Defaults/baileys-version.json");
|
|
50
13
|
const Types_1 = require("../Types");
|
|
51
14
|
const WABinary_1 = require("../WABinary");
|
|
52
|
-
const COMPANION_PLATFORM_MAP = {
|
|
53
|
-
'Chrome': '49',
|
|
54
|
-
'Edge': '50',
|
|
55
|
-
'Firefox': '51',
|
|
56
|
-
'Opera': '53',
|
|
57
|
-
'Safari': '54'
|
|
58
|
-
};
|
|
59
15
|
const PLATFORM_MAP = {
|
|
60
16
|
'aix': 'AIX',
|
|
61
17
|
'darwin': 'Mac OS',
|
|
@@ -70,12 +26,12 @@ exports.Browsers = {
|
|
|
70
26
|
macOS: (browser) => ['Mac OS', browser, '14.4.1'],
|
|
71
27
|
baileys: (browser) => ['Baileys', browser, '6.5.0'],
|
|
72
28
|
windows: (browser) => ['Windows', browser, '10.0.22631'],
|
|
73
|
-
/** The appropriate browser based on your OS & release */
|
|
74
29
|
appropriate: (browser) => [PLATFORM_MAP[(0, os_1.platform)()] || 'Ubuntu', browser, (0, os_1.release)()]
|
|
75
30
|
};
|
|
31
|
+
|
|
76
32
|
const getPlatformId = (browser) => {
|
|
77
33
|
const platformType = WAProto_1.proto.DeviceProps.PlatformType[browser.toUpperCase()];
|
|
78
|
-
return platformType ? platformType.toString() : '
|
|
34
|
+
return platformType ? platformType.toString() : '1'; //chrome
|
|
79
35
|
};
|
|
80
36
|
exports.getPlatformId = getPlatformId;
|
|
81
37
|
exports.BufferJSON = {
|
|
@@ -118,8 +74,6 @@ const unpadRandomMax16 = (e) => {
|
|
|
118
74
|
exports.unpadRandomMax16 = unpadRandomMax16;
|
|
119
75
|
const encodeWAMessage = (message) => ((0, exports.writeRandomPadMax16)(WAProto_1.proto.Message.encode(message).finish()));
|
|
120
76
|
exports.encodeWAMessage = encodeWAMessage;
|
|
121
|
-
const encodeNewsletterMessage = (message) => (WAProto_1.proto.Message.encode(message).finish());
|
|
122
|
-
exports.encodeNewsletterMessage = encodeNewsletterMessage;
|
|
123
77
|
const generateRegistrationId = () => {
|
|
124
78
|
return Uint16Array.from((0, crypto_1.randomBytes)(2))[0] & 16383;
|
|
125
79
|
};
|
|
@@ -134,7 +88,7 @@ const encodeBigEndian = (e, t = 4) => {
|
|
|
134
88
|
return a;
|
|
135
89
|
};
|
|
136
90
|
exports.encodeBigEndian = encodeBigEndian;
|
|
137
|
-
const toNumber = (t) => ((typeof t === 'object' && t) ? ('toNumber' in t ? t.toNumber() : t.low) : t
|
|
91
|
+
const toNumber = (t) => ((typeof t === 'object' && t) ? ('toNumber' in t ? t.toNumber() : t.low) : t);
|
|
138
92
|
exports.toNumber = toNumber;
|
|
139
93
|
/** unix timestamp of a date in seconds */
|
|
140
94
|
const unixTimestampSeconds = (date = new Date()) => Math.floor(date.getTime() / 1000);
|
|
@@ -200,6 +154,7 @@ async function promiseTimeout(ms, promise) {
|
|
|
200
154
|
.finally(cancel);
|
|
201
155
|
return p;
|
|
202
156
|
}
|
|
157
|
+
exports.promiseTimeout = promiseTimeout;
|
|
203
158
|
const generateMessageIDV2 = (userId) => {
|
|
204
159
|
const data = Buffer.alloc(8 + 20 + 16);
|
|
205
160
|
data.writeBigUInt64BE(BigInt(Math.floor(Date.now() / 1000)));
|
|
@@ -217,7 +172,7 @@ const generateMessageIDV2 = (userId) => {
|
|
|
217
172
|
};
|
|
218
173
|
exports.generateMessageIDV2 = generateMessageIDV2;
|
|
219
174
|
// generate a random ID to attach to a message
|
|
220
|
-
const generateMessageID = () => '
|
|
175
|
+
const generateMessageID = () => 'SH3NN-' + (0, crypto_1.randomBytes)(6).toString('hex').toUpperCase();
|
|
221
176
|
exports.generateMessageID = generateMessageID;
|
|
222
177
|
function bindWaitForEvent(ev, event) {
|
|
223
178
|
return async (check, timeoutMs) => {
|
|
@@ -231,8 +186,8 @@ function bindWaitForEvent(ev, event) {
|
|
|
231
186
|
}
|
|
232
187
|
};
|
|
233
188
|
ev.on('connection.update', closeListener);
|
|
234
|
-
listener =
|
|
235
|
-
if (
|
|
189
|
+
listener = (update) => {
|
|
190
|
+
if (check(update)) {
|
|
236
191
|
resolve();
|
|
237
192
|
}
|
|
238
193
|
};
|
|
@@ -244,12 +199,14 @@ function bindWaitForEvent(ev, event) {
|
|
|
244
199
|
}));
|
|
245
200
|
};
|
|
246
201
|
}
|
|
202
|
+
exports.bindWaitForEvent = bindWaitForEvent;
|
|
247
203
|
const bindWaitForConnectionUpdate = (ev) => bindWaitForEvent(ev, 'connection.update');
|
|
248
204
|
exports.bindWaitForConnectionUpdate = bindWaitForConnectionUpdate;
|
|
249
205
|
const printQRIfNecessaryListener = (ev, logger) => {
|
|
250
206
|
ev.on('connection.update', async ({ qr }) => {
|
|
251
207
|
if (qr) {
|
|
252
|
-
const QR = await
|
|
208
|
+
const QR = await import('qrcode-terminal')
|
|
209
|
+
.then(m => m.default || m)
|
|
253
210
|
.catch(() => {
|
|
254
211
|
logger.error('QR code terminal not added as dependency');
|
|
255
212
|
});
|
|
@@ -258,8 +215,12 @@ const printQRIfNecessaryListener = (ev, logger) => {
|
|
|
258
215
|
});
|
|
259
216
|
};
|
|
260
217
|
exports.printQRIfNecessaryListener = printQRIfNecessaryListener;
|
|
218
|
+
/**
|
|
219
|
+
* utility that fetches latest baileys version from the master branch.
|
|
220
|
+
* Use to ensure your WA connection is always on the latest version
|
|
221
|
+
*/
|
|
261
222
|
const fetchLatestBaileysVersion = async (options = {}) => {
|
|
262
|
-
const URL = 'https://
|
|
223
|
+
const URL = 'https://raw.githubusercontent.com/kiuur/bails/master/src/Defaults/baileys-version.json';
|
|
263
224
|
try {
|
|
264
225
|
const result = await axios_1.default.get(URL, {
|
|
265
226
|
...options,
|
|
@@ -285,24 +246,13 @@ exports.fetchLatestBaileysVersion = fetchLatestBaileysVersion;
|
|
|
285
246
|
*/
|
|
286
247
|
const fetchLatestWaWebVersion = async (options) => {
|
|
287
248
|
try {
|
|
288
|
-
const
|
|
249
|
+
const result = await axios_1.default.get('https://web.whatsapp.com/check-update?version=1&platform=web', {
|
|
289
250
|
...options,
|
|
290
251
|
responseType: 'json'
|
|
291
252
|
});
|
|
292
|
-
const
|
|
293
|
-
const match = data.match(regex);
|
|
294
|
-
if (!(match === null || match === void 0 ? void 0 : match[1])) {
|
|
295
|
-
return {
|
|
296
|
-
version: baileys_version_json_1.version,
|
|
297
|
-
isLatest: false,
|
|
298
|
-
error: {
|
|
299
|
-
message: 'Could not find client revision in the fetched content'
|
|
300
|
-
}
|
|
301
|
-
};
|
|
302
|
-
}
|
|
303
|
-
const clientRevision = match[1];
|
|
253
|
+
const version = result.data.currentVersion.split('.');
|
|
304
254
|
return {
|
|
305
|
-
version: [
|
|
255
|
+
version: [+version[0], +version[1], +version[2]],
|
|
306
256
|
isLatest: true
|
|
307
257
|
};
|
|
308
258
|
}
|
|
@@ -322,7 +272,6 @@ const generateMdTagPrefix = () => {
|
|
|
322
272
|
};
|
|
323
273
|
exports.generateMdTagPrefix = generateMdTagPrefix;
|
|
324
274
|
const STATUS_MAP = {
|
|
325
|
-
'sender': WAProto_1.proto.WebMessageInfo.Status.SERVER_ACK,
|
|
326
275
|
'played': WAProto_1.proto.WebMessageInfo.Status.PLAYED,
|
|
327
276
|
'read': WAProto_1.proto.WebMessageInfo.Status.READ,
|
|
328
277
|
'read-self': WAProto_1.proto.WebMessageInfo.Status.READ
|
|
@@ -371,8 +320,7 @@ const getCallStatusFromNode = ({ tag, attrs }) => {
|
|
|
371
320
|
status = 'timeout';
|
|
372
321
|
}
|
|
373
322
|
else {
|
|
374
|
-
|
|
375
|
-
status = 'terminate';
|
|
323
|
+
status = 'reject';
|
|
376
324
|
}
|
|
377
325
|
break;
|
|
378
326
|
case 'reject':
|
|
@@ -421,6 +369,7 @@ function trimUndefined(obj) {
|
|
|
421
369
|
}
|
|
422
370
|
return obj;
|
|
423
371
|
}
|
|
372
|
+
exports.trimUndefined = trimUndefined;
|
|
424
373
|
const CROCKFORD_CHARACTERS = '123456789ABCDEFGHJKLMNPQRSTVWXYZ';
|
|
425
374
|
function bytesToCrockford(buffer) {
|
|
426
375
|
let value = 0;
|
|
@@ -439,3 +388,4 @@ function bytesToCrockford(buffer) {
|
|
|
439
388
|
}
|
|
440
389
|
return crockford.join('');
|
|
441
390
|
}
|
|
391
|
+
exports.bytesToCrockford = bytesToCrockford;
|
package/lib/Utils/history.d.ts
CHANGED
|
@@ -6,14 +6,10 @@ 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;
|
|
11
9
|
};
|
|
12
10
|
export declare const downloadAndProcessHistorySyncNotification: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<any>) => Promise<{
|
|
13
11
|
chats: Chat[];
|
|
14
12
|
contacts: Contact[];
|
|
15
13
|
messages: proto.IWebMessageInfo[];
|
|
16
|
-
syncType: proto.HistorySync.HistorySyncType;
|
|
17
|
-
progress: number | null | undefined;
|
|
18
14
|
}>;
|
|
19
15
|
export declare const getHistoryMsg: (message: proto.IMessage) => proto.Message.IHistorySyncNotification | null | undefined;
|
package/lib/Utils/history.js
CHANGED
|
@@ -32,9 +32,13 @@ 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:
|
|
36
35
|
for (const chat of item.conversations) {
|
|
37
|
-
contacts.push({
|
|
36
|
+
contacts.push({
|
|
37
|
+
id: chat.id,
|
|
38
|
+
name: chat.name || undefined,
|
|
39
|
+
lid: chat.lidJid || undefined,
|
|
40
|
+
jid: (0, WABinary_1.isJidUser)(chat.id) ? chat.id : undefined
|
|
41
|
+
});
|
|
38
42
|
const msgs = chat.messages || [];
|
|
39
43
|
delete chat.messages;
|
|
40
44
|
delete chat.archived;
|
|
@@ -75,8 +79,6 @@ const processHistoryMessage = (item) => {
|
|
|
75
79
|
chats,
|
|
76
80
|
contacts,
|
|
77
81
|
messages,
|
|
78
|
-
syncType: item.syncType,
|
|
79
|
-
progress: item.progress
|
|
80
82
|
};
|
|
81
83
|
};
|
|
82
84
|
exports.processHistoryMessage = processHistoryMessage;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AxiosRequestConfig } from 'axios';
|
|
2
|
-
import {
|
|
2
|
+
import { Logger } from 'pino';
|
|
3
3
|
import { WAMediaUploadFunction, WAUrlInfo } from '../Types';
|
|
4
4
|
export type URLGenerationOptions = {
|
|
5
5
|
thumbnailWidth: number;
|
|
@@ -10,7 +10,7 @@ export type URLGenerationOptions = {
|
|
|
10
10
|
headers?: AxiosRequestConfig<{}>['headers'];
|
|
11
11
|
};
|
|
12
12
|
uploadImage?: WAMediaUploadFunction;
|
|
13
|
-
logger?:
|
|
13
|
+
logger?: Logger;
|
|
14
14
|
};
|
|
15
15
|
/**
|
|
16
16
|
* Given a piece of text, checks for any URL present, generates link preview for the same and returns it
|
|
@@ -1,37 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
3
|
exports.getUrlInfo = void 0;
|
|
37
4
|
const messages_1 = require("./messages");
|
|
@@ -58,7 +25,7 @@ const getUrlInfo = async (text, opts = {
|
|
|
58
25
|
// retries
|
|
59
26
|
const retries = 0;
|
|
60
27
|
const maxRetry = 5;
|
|
61
|
-
const { getLinkPreview } = await
|
|
28
|
+
const { getLinkPreview } = await import('link-preview-js');
|
|
62
29
|
let previewLink = text;
|
|
63
30
|
if (!text.startsWith('https://') && !text.startsWith('http://')) {
|
|
64
31
|
previewLink = 'https://' + previewLink;
|
package/lib/Utils/logger.d.ts
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
trace(obj: unknown, msg?: string): any;
|
|
5
|
-
debug(obj: unknown, msg?: string): any;
|
|
6
|
-
info(obj: unknown, msg?: string): any;
|
|
7
|
-
warn(obj: unknown, msg?: string): any;
|
|
8
|
-
error(obj: unknown, msg?: string): any;
|
|
9
|
-
}
|
|
10
|
-
declare const _default: import("pino").Logger<never, boolean>;
|
|
1
|
+
declare const _default: import("pino").Logger<{
|
|
2
|
+
timestamp: () => string;
|
|
3
|
+
}>;
|
|
11
4
|
export default _default;
|
package/lib/Utils/lt-hash.d.ts
CHANGED
|
@@ -4,8 +4,8 @@ declare class d {
|
|
|
4
4
|
add(e: any, t: any): any;
|
|
5
5
|
subtract(e: any, t: any): any;
|
|
6
6
|
subtractThenAdd(e: any, t: any, r: any): any;
|
|
7
|
-
_addSingle(e: any, t: any):
|
|
8
|
-
_subtractSingle(e: any, t: any):
|
|
7
|
+
_addSingle(e: any, t: any): ArrayBuffer;
|
|
8
|
+
_subtractSingle(e: any, t: any): ArrayBuffer;
|
|
9
9
|
performPointwiseWithOverflow(e: any, t: any, r: any): ArrayBuffer;
|
|
10
10
|
}
|
|
11
11
|
export declare const LT_HASH_ANTI_TAMPERING: d;
|
package/lib/Utils/lt-hash.js
CHANGED
|
@@ -30,15 +30,15 @@ class d {
|
|
|
30
30
|
var n = this;
|
|
31
31
|
return n.add(n.subtract(e, r), t);
|
|
32
32
|
}
|
|
33
|
-
|
|
33
|
+
_addSingle(e, t) {
|
|
34
34
|
var r = this;
|
|
35
|
-
const n = new Uint8Array(
|
|
36
|
-
return r.performPointwiseWithOverflow(
|
|
35
|
+
const n = new Uint8Array((0, crypto_1.hkdf)(Buffer.from(t), o, { info: r.salt })).buffer;
|
|
36
|
+
return r.performPointwiseWithOverflow(e, n, ((e, t) => e + t));
|
|
37
37
|
}
|
|
38
|
-
|
|
38
|
+
_subtractSingle(e, t) {
|
|
39
39
|
var r = this;
|
|
40
|
-
const n = new Uint8Array(
|
|
41
|
-
return r.performPointwiseWithOverflow(
|
|
40
|
+
const n = new Uint8Array((0, crypto_1.hkdf)(Buffer.from(t), o, { info: r.salt })).buffer;
|
|
41
|
+
return r.performPointwiseWithOverflow(e, n, ((e, t) => e - t));
|
|
42
42
|
}
|
|
43
43
|
performPointwiseWithOverflow(e, t, r) {
|
|
44
44
|
const n = new DataView(e), i = new DataView(t), a = new ArrayBuffer(n.byteLength), s = new DataView(a);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare const makeMutex: () => {
|
|
2
|
-
mutex<T>(code: () =>
|
|
2
|
+
mutex<T>(code: () => T | Promise<T>): Promise<T>;
|
|
3
3
|
};
|
|
4
4
|
export type Mutex = ReturnType<typeof makeMutex>;
|
|
5
5
|
export declare const makeKeyedMutex: () => {
|
|
6
|
-
mutex<T>(key: string, task: () =>
|
|
6
|
+
mutex<T>(key: string, task: () => T | Promise<T>): Promise<T>;
|
|
7
7
|
};
|
|
@@ -1,31 +1,27 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
/// <reference types="node" />
|
|
1
4
|
import { Boom } from '@hapi/boom';
|
|
2
5
|
import { AxiosRequestConfig } from 'axios';
|
|
6
|
+
import type { Logger } from 'pino';
|
|
3
7
|
import { Readable, Transform } from 'stream';
|
|
4
8
|
import { URL } from 'url';
|
|
5
9
|
import { proto } from '../../WAProto';
|
|
6
10
|
import { DownloadableMessage, MediaConnInfo, MediaDecryptionKeyInfo, MediaType, SocketConfig, WAMediaUpload, WAMediaUploadFunction, WAMessageContent } from '../Types';
|
|
7
11
|
import { BinaryNode } from '../WABinary';
|
|
8
|
-
import { ILogger } from './logger';
|
|
9
12
|
export declare const hkdfInfoKey: (type: MediaType) => string;
|
|
10
13
|
/** generates all the keys required to encrypt/decrypt & sign a media message */
|
|
11
|
-
export declare function getMediaKeys(buffer: Uint8Array | string | null | undefined, mediaType: MediaType):
|
|
12
|
-
export declare function uploadFile(buffer: Buffer, logger?: ILogger): Promise<string>;
|
|
13
|
-
export declare function vid2jpg(videoUrl: string): Promise<string>;
|
|
14
|
-
/**
|
|
15
|
-
* Originally written by Techwiz (https://github.com/techwiz37)
|
|
16
|
-
* Modified for customization and improvements
|
|
17
|
-
*/
|
|
18
|
-
export declare const extractVideoThumb: (videoPath: string) => Promise<Buffer<ArrayBufferLike>>;
|
|
14
|
+
export declare function getMediaKeys(buffer: Uint8Array | string | null | undefined, mediaType: MediaType): MediaDecryptionKeyInfo;
|
|
19
15
|
export declare const extractImageThumb: (bufferOrFilePath: Readable | Buffer | string, width?: number) => Promise<{
|
|
20
|
-
buffer: Buffer
|
|
16
|
+
buffer: Buffer;
|
|
21
17
|
original: {
|
|
22
|
-
width: number;
|
|
23
|
-
height: number;
|
|
18
|
+
width: number | undefined;
|
|
19
|
+
height: number | undefined;
|
|
24
20
|
};
|
|
25
21
|
}>;
|
|
26
22
|
export declare const encodeBase64EncodedStringForUpload: (b64: string) => string;
|
|
27
23
|
export declare const generateProfilePicture: (mediaUpload: WAMediaUpload) => Promise<{
|
|
28
|
-
img: Buffer
|
|
24
|
+
img: Buffer;
|
|
29
25
|
}>;
|
|
30
26
|
/** gets the SHA256 of the given media message */
|
|
31
27
|
export declare const mediaMessageSHA256B64: (message: WAMessageContent) => string | null | undefined;
|
|
@@ -33,9 +29,9 @@ export declare function getAudioDuration(buffer: Buffer | string | Readable): Pr
|
|
|
33
29
|
/**
|
|
34
30
|
referenced from and modifying https://github.com/wppconnect-team/wa-js/blob/main/src/chat/functions/prepareAudioWaveform.ts
|
|
35
31
|
*/
|
|
36
|
-
export declare function getAudioWaveform(buffer: Buffer | string | Readable, logger?:
|
|
32
|
+
export declare function getAudioWaveform(buffer: Buffer | string | Readable, logger?: Logger): Promise<Uint8Array | undefined>;
|
|
37
33
|
export declare const toReadable: (buffer: Buffer) => Readable;
|
|
38
|
-
export declare const toBuffer: (stream: Readable) => Promise<Buffer
|
|
34
|
+
export declare const toBuffer: (stream: Readable) => Promise<Buffer>;
|
|
39
35
|
export declare const getStream: (item: WAMediaUpload, opts?: AxiosRequestConfig) => Promise<{
|
|
40
36
|
readonly stream: Readable;
|
|
41
37
|
readonly type: "buffer";
|
|
@@ -51,7 +47,7 @@ export declare const getStream: (item: WAMediaUpload, opts?: AxiosRequestConfig)
|
|
|
51
47
|
}>;
|
|
52
48
|
/** generates a thumbnail for a given media, if required */
|
|
53
49
|
export declare function generateThumbnail(file: string, mediaType: 'video' | 'image', options: {
|
|
54
|
-
logger?:
|
|
50
|
+
logger?: Logger;
|
|
55
51
|
}): Promise<{
|
|
56
52
|
thumbnail: string | undefined;
|
|
57
53
|
originalImageDimensions: {
|
|
@@ -64,25 +60,25 @@ export declare const getHttpStream: (url: string | URL, options?: AxiosRequestCo
|
|
|
64
60
|
}) => Promise<Readable>;
|
|
65
61
|
type EncryptedStreamOptions = {
|
|
66
62
|
saveOriginalFileIfRequired?: boolean;
|
|
67
|
-
logger?:
|
|
63
|
+
logger?: Logger;
|
|
68
64
|
opts?: AxiosRequestConfig;
|
|
69
65
|
};
|
|
70
66
|
export declare const prepareStream: (media: WAMediaUpload, mediaType: MediaType, { logger, saveOriginalFileIfRequired, opts }?: EncryptedStreamOptions) => Promise<{
|
|
71
67
|
mediaKey: undefined;
|
|
72
|
-
encWriteStream: Buffer
|
|
68
|
+
encWriteStream: Buffer;
|
|
73
69
|
fileLength: number;
|
|
74
|
-
fileSha256: Buffer
|
|
70
|
+
fileSha256: Buffer;
|
|
75
71
|
fileEncSha256: undefined;
|
|
76
72
|
bodyPath: string | undefined;
|
|
77
73
|
didSaveToTmpPath: boolean;
|
|
78
74
|
}>;
|
|
79
75
|
export declare const encryptedStream: (media: WAMediaUpload, mediaType: MediaType, { logger, saveOriginalFileIfRequired, opts }?: EncryptedStreamOptions) => Promise<{
|
|
80
|
-
mediaKey: Buffer
|
|
76
|
+
mediaKey: Buffer;
|
|
81
77
|
encWriteStream: Readable;
|
|
82
78
|
bodyPath: string | undefined;
|
|
83
|
-
mac: Buffer
|
|
84
|
-
fileEncSha256: Buffer
|
|
85
|
-
fileSha256: Buffer
|
|
79
|
+
mac: Buffer;
|
|
80
|
+
fileEncSha256: Buffer;
|
|
81
|
+
fileSha256: Buffer;
|
|
86
82
|
fileLength: number;
|
|
87
83
|
didSaveToTmpPath: boolean;
|
|
88
84
|
}>;
|
|
@@ -103,18 +99,18 @@ export declare const getWAUploadToServer: ({ customUploadHosts, fetchAgent, logg
|
|
|
103
99
|
/**
|
|
104
100
|
* Generate a binary node that will request the phone to re-upload the media & return the newly uploaded URL
|
|
105
101
|
*/
|
|
106
|
-
export declare const encryptMediaRetryRequest: (key: proto.IMessageKey, mediaKey: Buffer | Uint8Array, meId: string) =>
|
|
102
|
+
export declare const encryptMediaRetryRequest: (key: proto.IMessageKey, mediaKey: Buffer | Uint8Array, meId: string) => BinaryNode;
|
|
107
103
|
export declare const decodeMediaRetryNode: (node: BinaryNode) => {
|
|
108
|
-
key:
|
|
104
|
+
key: proto.IMessageKey;
|
|
109
105
|
media?: {
|
|
110
106
|
ciphertext: Uint8Array;
|
|
111
107
|
iv: Uint8Array;
|
|
112
|
-
};
|
|
113
|
-
error?: Boom;
|
|
108
|
+
} | undefined;
|
|
109
|
+
error?: Boom<any> | undefined;
|
|
114
110
|
};
|
|
115
111
|
export declare const decryptMediaRetryData: ({ ciphertext, iv }: {
|
|
116
112
|
ciphertext: Uint8Array;
|
|
117
113
|
iv: Uint8Array;
|
|
118
|
-
}, mediaKey: Uint8Array, msgId: string) =>
|
|
114
|
+
}, mediaKey: Uint8Array, msgId: string) => proto.MediaRetryNotification;
|
|
119
115
|
export declare const getStatusCodeForMediaRetry: (code: number) => any;
|
|
120
116
|
export {};
|