@d0v3riz/baileys 6.3.1 → 6.4.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/WAProto/WAProto.proto +58 -24
- package/WAProto/index.d.ts +649 -410
- package/WAProto/index.js +1632 -985
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.js +1 -1
- package/lib/Socket/Client/abstract-socket-client.d.ts +1 -0
- package/lib/Socket/Client/web-socket-client.d.ts +1 -1
- package/lib/Socket/Client/web-socket-client.js +1 -1
- package/lib/Socket/business.d.ts +4 -3
- package/lib/Socket/chats.d.ts +6 -5
- package/lib/Socket/groups.d.ts +3 -2
- package/lib/Socket/index.d.ts +9 -8
- package/lib/Socket/messages-recv.d.ts +5 -3
- package/lib/Socket/messages-recv.js +75 -2
- package/lib/Socket/messages-send.d.ts +3 -2
- package/lib/Socket/messages-send.js +13 -8
- package/lib/Socket/registration.d.ts +5 -4
- package/lib/Socket/socket.d.ts +4 -3
- package/lib/Socket/socket.js +69 -9
- package/lib/Store/make-in-memory-store.d.ts +2 -2
- package/lib/Types/Auth.d.ts +19 -17
- package/lib/Types/Call.d.ts +2 -2
- package/lib/Types/Chat.d.ts +13 -13
- package/lib/Types/Events.d.ts +3 -3
- package/lib/Types/GroupMetadata.d.ts +2 -2
- package/lib/Types/LabelAssociation.d.ts +2 -2
- package/lib/Types/Message.d.ts +57 -45
- package/lib/Types/Product.d.ts +14 -14
- package/lib/Types/Signal.d.ts +10 -10
- package/lib/Types/Socket.d.ts +5 -4
- package/lib/Types/State.d.ts +2 -2
- package/lib/Types/index.d.ts +5 -5
- package/lib/Utils/auth-utils.js +3 -1
- package/lib/Utils/chat-utils.d.ts +4 -4
- package/lib/Utils/crypto.d.ts +3 -0
- package/lib/Utils/crypto.js +15 -1
- package/lib/Utils/event-buffer.d.ts +2 -2
- package/lib/Utils/event-buffer.js +3 -3
- package/lib/Utils/generics.d.ts +7 -6
- package/lib/Utils/generics.js +25 -27
- package/lib/Utils/link-preview.d.ts +1 -1
- package/lib/Utils/link-preview.js +1 -24
- package/lib/Utils/make-mutex.d.ts +1 -1
- package/lib/Utils/messages-media.d.ts +9 -3
- package/lib/Utils/messages-media.js +54 -6
- package/lib/Utils/messages.d.ts +6 -5
- package/lib/Utils/messages.js +35 -1
- package/lib/Utils/process-message.d.ts +2 -2
- package/lib/Utils/validate-connection.js +1 -2
- package/lib/WABinary/jid-utils.d.ts +4 -4
- package/lib/WABinary/types.d.ts +4 -4
- package/lib/index.d.ts +1 -1
- package/package.json +8 -6
package/lib/Types/Product.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { WAMediaUpload } from './Message';
|
|
2
|
-
export
|
|
2
|
+
export type CatalogResult = {
|
|
3
3
|
data: {
|
|
4
4
|
paging: {
|
|
5
5
|
cursors: {
|
|
@@ -10,23 +10,23 @@ export declare type CatalogResult = {
|
|
|
10
10
|
data: any[];
|
|
11
11
|
};
|
|
12
12
|
};
|
|
13
|
-
export
|
|
13
|
+
export type ProductCreateResult = {
|
|
14
14
|
data: {
|
|
15
15
|
product: {};
|
|
16
16
|
};
|
|
17
17
|
};
|
|
18
|
-
export
|
|
18
|
+
export type CatalogStatus = {
|
|
19
19
|
status: string;
|
|
20
20
|
canAppeal: boolean;
|
|
21
21
|
};
|
|
22
|
-
export
|
|
22
|
+
export type CatalogCollection = {
|
|
23
23
|
id: string;
|
|
24
24
|
name: string;
|
|
25
25
|
products: Product[];
|
|
26
26
|
status: CatalogStatus;
|
|
27
27
|
};
|
|
28
|
-
export
|
|
29
|
-
export
|
|
28
|
+
export type ProductAvailability = 'in stock';
|
|
29
|
+
export type ProductBase = {
|
|
30
30
|
name: string;
|
|
31
31
|
retailerId?: string;
|
|
32
32
|
url?: string;
|
|
@@ -35,14 +35,14 @@ export declare type ProductBase = {
|
|
|
35
35
|
currency: string;
|
|
36
36
|
isHidden?: boolean;
|
|
37
37
|
};
|
|
38
|
-
export
|
|
38
|
+
export type ProductCreate = ProductBase & {
|
|
39
39
|
/** ISO country code for product origin. Set to undefined for no country */
|
|
40
40
|
originCountryCode: string | undefined;
|
|
41
41
|
/** images of the product */
|
|
42
42
|
images: WAMediaUpload[];
|
|
43
43
|
};
|
|
44
|
-
export
|
|
45
|
-
export
|
|
44
|
+
export type ProductUpdate = Omit<ProductCreate, 'originCountryCode'>;
|
|
45
|
+
export type Product = ProductBase & {
|
|
46
46
|
id: string;
|
|
47
47
|
imageUrls: {
|
|
48
48
|
[_: string]: string;
|
|
@@ -52,11 +52,11 @@ export declare type Product = ProductBase & {
|
|
|
52
52
|
};
|
|
53
53
|
availability: ProductAvailability;
|
|
54
54
|
};
|
|
55
|
-
export
|
|
55
|
+
export type OrderPrice = {
|
|
56
56
|
currency: string;
|
|
57
57
|
total: number;
|
|
58
58
|
};
|
|
59
|
-
export
|
|
59
|
+
export type OrderProduct = {
|
|
60
60
|
id: string;
|
|
61
61
|
imageUrl: string;
|
|
62
62
|
name: string;
|
|
@@ -64,12 +64,12 @@ export declare type OrderProduct = {
|
|
|
64
64
|
currency: string;
|
|
65
65
|
price: number;
|
|
66
66
|
};
|
|
67
|
-
export
|
|
67
|
+
export type OrderDetails = {
|
|
68
68
|
price: OrderPrice;
|
|
69
69
|
products: OrderProduct[];
|
|
70
70
|
};
|
|
71
|
-
export
|
|
72
|
-
export
|
|
71
|
+
export type CatalogCursor = string;
|
|
72
|
+
export type GetCatalogOptions = {
|
|
73
73
|
/** cursor to start from */
|
|
74
74
|
cursor?: CatalogCursor;
|
|
75
75
|
/** number of products to fetch */
|
package/lib/Types/Signal.d.ts
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
1
|
import { proto } from '../../WAProto';
|
|
2
|
-
|
|
2
|
+
type DecryptGroupSignalOpts = {
|
|
3
3
|
group: string;
|
|
4
4
|
authorJid: string;
|
|
5
5
|
msg: Uint8Array;
|
|
6
6
|
};
|
|
7
|
-
|
|
7
|
+
type ProcessSenderKeyDistributionMessageOpts = {
|
|
8
8
|
item: proto.Message.ISenderKeyDistributionMessage;
|
|
9
9
|
authorJid: string;
|
|
10
10
|
};
|
|
11
|
-
|
|
11
|
+
type DecryptSignalProtoOpts = {
|
|
12
12
|
jid: string;
|
|
13
13
|
type: 'pkmsg' | 'msg';
|
|
14
14
|
ciphertext: Uint8Array;
|
|
15
15
|
};
|
|
16
|
-
|
|
16
|
+
type EncryptMessageOpts = {
|
|
17
17
|
jid: string;
|
|
18
18
|
data: Uint8Array;
|
|
19
19
|
};
|
|
20
|
-
|
|
20
|
+
type EncryptGroupMessageOpts = {
|
|
21
21
|
group: string;
|
|
22
22
|
data: Uint8Array;
|
|
23
23
|
meId: string;
|
|
24
24
|
};
|
|
25
|
-
|
|
25
|
+
type PreKey = {
|
|
26
26
|
keyId: number;
|
|
27
27
|
publicKey: Uint8Array;
|
|
28
28
|
};
|
|
29
|
-
|
|
29
|
+
type SignedPreKey = PreKey & {
|
|
30
30
|
signature: Uint8Array;
|
|
31
31
|
};
|
|
32
|
-
|
|
32
|
+
type E2ESession = {
|
|
33
33
|
registrationId: number;
|
|
34
34
|
identityKey: Uint8Array;
|
|
35
35
|
signedPreKey: SignedPreKey;
|
|
36
36
|
preKey: PreKey;
|
|
37
37
|
};
|
|
38
|
-
|
|
38
|
+
type E2ESessionOpts = {
|
|
39
39
|
jid: string;
|
|
40
40
|
session: E2ESession;
|
|
41
41
|
};
|
|
42
|
-
export
|
|
42
|
+
export type SignalRepository = {
|
|
43
43
|
decryptGroupMessage(opts: DecryptGroupSignalOpts): Promise<Uint8Array>;
|
|
44
44
|
processSenderKeyDistributionMessage(opts: ProcessSenderKeyDistributionMessageOpts): Promise<void>;
|
|
45
45
|
decryptMessage(opts: DecryptSignalProtoOpts): Promise<Uint8Array>;
|
package/lib/Types/Socket.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
2
3
|
import { AxiosRequestConfig } from 'axios';
|
|
3
4
|
import type { Agent } from 'https';
|
|
4
5
|
import type { Logger } from 'pino';
|
|
@@ -7,9 +8,9 @@ import { proto } from '../../WAProto';
|
|
|
7
8
|
import { AuthenticationState, SignalAuthState, TransactionCapabilityOptions } from './Auth';
|
|
8
9
|
import { MediaConnInfo } from './Message';
|
|
9
10
|
import { SignalRepository } from './Signal';
|
|
10
|
-
export
|
|
11
|
-
export
|
|
12
|
-
export
|
|
11
|
+
export type WAVersion = [number, number, number];
|
|
12
|
+
export type WABrowserDescription = [string, string, string];
|
|
13
|
+
export type CacheStore = {
|
|
13
14
|
/** get a cached key and change the stats */
|
|
14
15
|
get<T>(key: string): T | undefined;
|
|
15
16
|
/** set a key in the cache */
|
|
@@ -19,7 +20,7 @@ export declare type CacheStore = {
|
|
|
19
20
|
/** flush all data */
|
|
20
21
|
flushAll(): void;
|
|
21
22
|
};
|
|
22
|
-
export
|
|
23
|
+
export type SocketConfig = {
|
|
23
24
|
/** the WS url to connect to WA */
|
|
24
25
|
waWebSocketUrl: string | URL;
|
|
25
26
|
/** Fails the connection if the socket times out in this interval */
|
package/lib/Types/State.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Contact } from './Contact';
|
|
2
|
-
export
|
|
3
|
-
export
|
|
2
|
+
export type WAConnectionState = 'open' | 'connecting' | 'close';
|
|
3
|
+
export type ConnectionState = {
|
|
4
4
|
/** connection is now open, connecting or closed */
|
|
5
5
|
connection: WAConnectionState;
|
|
6
6
|
/** the error that caused the connection to close */
|
package/lib/Types/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export * from './Call';
|
|
|
11
11
|
export * from './Signal';
|
|
12
12
|
import { AuthenticationState } from './Auth';
|
|
13
13
|
import { SocketConfig } from './Socket';
|
|
14
|
-
export
|
|
14
|
+
export type UserFacingSocketConfig = Partial<SocketConfig> & {
|
|
15
15
|
auth: AuthenticationState;
|
|
16
16
|
};
|
|
17
17
|
export declare enum DisconnectReason {
|
|
@@ -24,18 +24,18 @@ export declare enum DisconnectReason {
|
|
|
24
24
|
restartRequired = 515,
|
|
25
25
|
multideviceMismatch = 411
|
|
26
26
|
}
|
|
27
|
-
export
|
|
27
|
+
export type WAInitResponse = {
|
|
28
28
|
ref: string;
|
|
29
29
|
ttl: number;
|
|
30
30
|
status: 200;
|
|
31
31
|
};
|
|
32
|
-
export
|
|
32
|
+
export type WABusinessHoursConfig = {
|
|
33
33
|
day_of_week: string;
|
|
34
34
|
mode: string;
|
|
35
35
|
open_time?: number;
|
|
36
36
|
close_time?: number;
|
|
37
37
|
};
|
|
38
|
-
export
|
|
38
|
+
export type WABusinessProfile = {
|
|
39
39
|
description: string;
|
|
40
40
|
email: string | undefined;
|
|
41
41
|
business_hours: {
|
|
@@ -48,7 +48,7 @@ export declare type WABusinessProfile = {
|
|
|
48
48
|
wid?: string;
|
|
49
49
|
address?: string;
|
|
50
50
|
};
|
|
51
|
-
export
|
|
51
|
+
export type CurveKeyPair = {
|
|
52
52
|
private: Uint8Array;
|
|
53
53
|
public: Uint8Array;
|
|
54
54
|
};
|
package/lib/Utils/auth-utils.js
CHANGED
|
@@ -179,6 +179,7 @@ const initAuthCreds = () => {
|
|
|
179
179
|
const identityKey = crypto_2.Curve.generateKeyPair();
|
|
180
180
|
return {
|
|
181
181
|
noiseKey: crypto_2.Curve.generateKeyPair(),
|
|
182
|
+
pairingEphemeralKeyPair: crypto_2.Curve.generateKeyPair(),
|
|
182
183
|
signedIdentityKey: identityKey,
|
|
183
184
|
signedPreKey: (0, crypto_2.signedKeyPair)(identityKey, 1),
|
|
184
185
|
registrationId: (0, generics_1.generateRegistrationId)(),
|
|
@@ -196,7 +197,8 @@ const initAuthCreds = () => {
|
|
|
196
197
|
identityId: (0, crypto_1.randomBytes)(20),
|
|
197
198
|
registered: false,
|
|
198
199
|
backupToken: (0, crypto_1.randomBytes)(20),
|
|
199
|
-
registration: {}
|
|
200
|
+
registration: {},
|
|
201
|
+
pairingCode: undefined,
|
|
200
202
|
};
|
|
201
203
|
};
|
|
202
204
|
exports.initAuthCreds = initAuthCreds;
|
|
@@ -4,8 +4,8 @@ import type { Logger } from 'pino';
|
|
|
4
4
|
import { proto } from '../../WAProto';
|
|
5
5
|
import { BaileysEventEmitter, ChatModification, ChatMutation, Contact, InitialAppStateSyncOptions, LTHashState, WAPatchCreate, WAPatchName } from '../Types';
|
|
6
6
|
import { BinaryNode } from '../WABinary';
|
|
7
|
-
|
|
8
|
-
export
|
|
7
|
+
type FetchAppStateSyncKey = (keyId: string) => Promise<proto.Message.IAppStateSyncKeyData | null | undefined>;
|
|
8
|
+
export type ChatMutationMap = {
|
|
9
9
|
[index: string]: ChatMutation;
|
|
10
10
|
};
|
|
11
11
|
export declare const newLTHashState: () => LTHashState;
|
|
@@ -62,10 +62,10 @@ export declare const decodeSyncdSnapshot: (name: WAPatchName, snapshot: proto.IS
|
|
|
62
62
|
state: LTHashState;
|
|
63
63
|
mutationMap: ChatMutationMap;
|
|
64
64
|
}>;
|
|
65
|
-
export declare const decodePatches: (name: WAPatchName, syncds: proto.ISyncdPatch[], initial: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey, options: AxiosRequestConfig<any>, minimumVersionNumber?: number
|
|
65
|
+
export declare const decodePatches: (name: WAPatchName, syncds: proto.ISyncdPatch[], initial: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey, options: AxiosRequestConfig<any>, minimumVersionNumber?: number, logger?: Logger, validateMacs?: boolean) => Promise<{
|
|
66
66
|
state: LTHashState;
|
|
67
67
|
mutationMap: ChatMutationMap;
|
|
68
68
|
}>;
|
|
69
69
|
export declare const chatModificationToAppPatch: (mod: ChatModification, jid: string) => WAPatchCreate;
|
|
70
|
-
export declare const processSyncAction: (syncAction: ChatMutation, ev: BaileysEventEmitter, me: Contact, initialSyncOpts?: InitialAppStateSyncOptions
|
|
70
|
+
export declare const processSyncAction: (syncAction: ChatMutation, ev: BaileysEventEmitter, me: Contact, initialSyncOpts?: InitialAppStateSyncOptions, logger?: Logger) => void;
|
|
71
71
|
export {};
|
package/lib/Utils/crypto.d.ts
CHANGED
|
@@ -23,6 +23,8 @@ export declare function aesEncryptGCM(plaintext: Uint8Array, key: Uint8Array, iv
|
|
|
23
23
|
* where the auth tag is suffixed to the ciphertext
|
|
24
24
|
* */
|
|
25
25
|
export declare function aesDecryptGCM(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array): Buffer;
|
|
26
|
+
export declare function aesEncryptCTR(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array): Buffer;
|
|
27
|
+
export declare function aesDecryptCTR(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array): Buffer;
|
|
26
28
|
/** decrypt AES 256 CBC; where the IV is prefixed to the buffer */
|
|
27
29
|
export declare function aesDecrypt(buffer: Buffer, key: Buffer): Buffer;
|
|
28
30
|
/** decrypt AES 256 CBC */
|
|
@@ -36,3 +38,4 @@ export declare function hkdf(buffer: Uint8Array | Buffer, expandedLength: number
|
|
|
36
38
|
salt?: Buffer;
|
|
37
39
|
info?: string;
|
|
38
40
|
}): Buffer;
|
|
41
|
+
export declare function derivePairingCodeKey(pairingCode: string, salt: Buffer): Buffer;
|
package/lib/Utils/crypto.js
CHANGED
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.hkdf = exports.md5 = exports.sha256 = exports.hmacSign = exports.aesEncrypWithIV = exports.aesEncrypt = exports.aesDecryptWithIV = exports.aesDecrypt = exports.aesDecryptGCM = exports.aesEncryptGCM = exports.signedKeyPair = exports.Curve = exports.generateSignalPubKey = void 0;
|
|
29
|
+
exports.derivePairingCodeKey = exports.hkdf = exports.md5 = exports.sha256 = exports.hmacSign = exports.aesEncrypWithIV = exports.aesEncrypt = exports.aesDecryptWithIV = exports.aesDecrypt = exports.aesDecryptCTR = exports.aesEncryptCTR = exports.aesDecryptGCM = exports.aesEncryptGCM = exports.signedKeyPair = exports.Curve = exports.generateSignalPubKey = void 0;
|
|
30
30
|
const crypto_1 = require("crypto");
|
|
31
31
|
const futoin_hkdf_1 = __importDefault(require("futoin-hkdf"));
|
|
32
32
|
const libsignal = __importStar(require("libsignal"));
|
|
@@ -93,6 +93,16 @@ function aesDecryptGCM(ciphertext, key, iv, additionalData) {
|
|
|
93
93
|
return Buffer.concat([decipher.update(enc), decipher.final()]);
|
|
94
94
|
}
|
|
95
95
|
exports.aesDecryptGCM = aesDecryptGCM;
|
|
96
|
+
function aesEncryptCTR(plaintext, key, iv) {
|
|
97
|
+
const cipher = (0, crypto_1.createCipheriv)('aes-256-ctr', key, iv);
|
|
98
|
+
return Buffer.concat([cipher.update(plaintext), cipher.final()]);
|
|
99
|
+
}
|
|
100
|
+
exports.aesEncryptCTR = aesEncryptCTR;
|
|
101
|
+
function aesDecryptCTR(ciphertext, key, iv) {
|
|
102
|
+
const decipher = (0, crypto_1.createDecipheriv)('aes-256-ctr', key, iv);
|
|
103
|
+
return Buffer.concat([decipher.update(ciphertext), decipher.final()]);
|
|
104
|
+
}
|
|
105
|
+
exports.aesDecryptCTR = aesDecryptCTR;
|
|
96
106
|
/** decrypt AES 256 CBC; where the IV is prefixed to the buffer */
|
|
97
107
|
function aesDecrypt(buffer, key) {
|
|
98
108
|
return aesDecryptWithIV(buffer.slice(16, buffer.length), key, buffer.slice(0, 16));
|
|
@@ -135,3 +145,7 @@ function hkdf(buffer, expandedLength, info) {
|
|
|
135
145
|
return (0, futoin_hkdf_1.default)(!Buffer.isBuffer(buffer) ? Buffer.from(buffer) : buffer, expandedLength, info);
|
|
136
146
|
}
|
|
137
147
|
exports.hkdf = hkdf;
|
|
148
|
+
function derivePairingCodeKey(pairingCode, salt) {
|
|
149
|
+
return (0, crypto_1.pbkdf2Sync)(pairingCode, salt, 2 << 16, 32, 'sha256');
|
|
150
|
+
}
|
|
151
|
+
exports.derivePairingCodeKey = derivePairingCodeKey;
|
|
@@ -7,8 +7,8 @@ import { BaileysEventEmitter, BaileysEventMap } from '../Types';
|
|
|
7
7
|
* this can make processing events extremely efficient -- since everything
|
|
8
8
|
* can be done in a single transaction
|
|
9
9
|
*/
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
type BaileysEventData = Partial<BaileysEventMap>;
|
|
11
|
+
type BaileysBufferableEventEmitter = BaileysEventEmitter & {
|
|
12
12
|
/** Use to process events in a batch */
|
|
13
13
|
process(handler: (events: BaileysEventData) => void | Promise<void>): (() => void);
|
|
14
14
|
/**
|
|
@@ -156,7 +156,7 @@ function append(data, historyCache, event, eventData, logger) {
|
|
|
156
156
|
for (const contact of eventData.contacts) {
|
|
157
157
|
const existingContact = data.historySets.contacts[contact.id];
|
|
158
158
|
if (existingContact) {
|
|
159
|
-
Object.assign(existingContact, (0, generics_1.
|
|
159
|
+
Object.assign(existingContact, (0, generics_1.trimUndefined)(contact));
|
|
160
160
|
}
|
|
161
161
|
else {
|
|
162
162
|
const historyContactId = `c:${contact.id}`;
|
|
@@ -256,14 +256,14 @@ function append(data, historyCache, event, eventData, logger) {
|
|
|
256
256
|
}
|
|
257
257
|
}
|
|
258
258
|
if (upsert) {
|
|
259
|
-
upsert = Object.assign(upsert, (0, generics_1.
|
|
259
|
+
upsert = Object.assign(upsert, (0, generics_1.trimUndefined)(contact));
|
|
260
260
|
}
|
|
261
261
|
else {
|
|
262
262
|
upsert = contact;
|
|
263
263
|
data.contactUpserts[contact.id] = upsert;
|
|
264
264
|
}
|
|
265
265
|
if (data.contactUpdates[contact.id]) {
|
|
266
|
-
upsert = Object.assign(data.contactUpdates[contact.id], (0, generics_1.
|
|
266
|
+
upsert = Object.assign(data.contactUpdates[contact.id], (0, generics_1.trimUndefined)(contact));
|
|
267
267
|
delete data.contactUpdates[contact.id];
|
|
268
268
|
}
|
|
269
269
|
}
|
package/lib/Utils/generics.d.ts
CHANGED
|
@@ -24,9 +24,9 @@ export declare const encodeBigEndian: (e: number, t?: number) => Uint8Array;
|
|
|
24
24
|
export declare const toNumber: (t: Long | number | null | undefined) => number;
|
|
25
25
|
/** unix timestamp of a date in seconds */
|
|
26
26
|
export declare const unixTimestampSeconds: (date?: Date) => number;
|
|
27
|
-
export
|
|
28
|
-
export declare const debouncedTimeout: (intervalMs?: number, task?: (
|
|
29
|
-
start: (newIntervalMs?: number
|
|
27
|
+
export type DebouncedTimeout = ReturnType<typeof debouncedTimeout>;
|
|
28
|
+
export declare const debouncedTimeout: (intervalMs?: number, task?: () => void) => {
|
|
29
|
+
start: (newIntervalMs?: number, newTask?: () => void) => void;
|
|
30
30
|
cancel: () => void;
|
|
31
31
|
setTask: (newTask: () => void) => () => void;
|
|
32
32
|
setInterval: (newInterval: number) => number;
|
|
@@ -38,8 +38,8 @@ export declare const delayCancellable: (ms: number) => {
|
|
|
38
38
|
};
|
|
39
39
|
export declare function promiseTimeout<T>(ms: number | undefined, promise: (resolve: (v: T) => void, reject: (error: any) => void) => void): Promise<T>;
|
|
40
40
|
export declare const generateMessageID: () => string;
|
|
41
|
-
export declare function bindWaitForEvent<T extends keyof BaileysEventMap>(ev: BaileysEventEmitter, event: T): (check: (u: BaileysEventMap[T]) => boolean | undefined, timeoutMs?: number
|
|
42
|
-
export declare const bindWaitForConnectionUpdate: (ev: BaileysEventEmitter) => (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number
|
|
41
|
+
export declare function bindWaitForEvent<T extends keyof BaileysEventMap>(ev: BaileysEventEmitter, event: T): (check: (u: BaileysEventMap[T]) => boolean | undefined, timeoutMs?: number) => Promise<void>;
|
|
42
|
+
export declare const bindWaitForConnectionUpdate: (ev: BaileysEventEmitter) => (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number) => Promise<void>;
|
|
43
43
|
export declare const printQRIfNecessaryListener: (ev: BaileysEventEmitter, logger: Logger) => void;
|
|
44
44
|
/**
|
|
45
45
|
* utility that fetches latest baileys version from the master branch.
|
|
@@ -89,4 +89,5 @@ export declare const getCodeFromWSError: (error: Error) => number;
|
|
|
89
89
|
* @param platform AuthenticationCreds.platform
|
|
90
90
|
*/
|
|
91
91
|
export declare const isWABusinessPlatform: (platform: string) => boolean;
|
|
92
|
-
export declare function
|
|
92
|
+
export declare function trimUndefined(obj: any): any;
|
|
93
|
+
export declare function bytesToCrockford(buffer: Buffer): string;
|
package/lib/Utils/generics.js
CHANGED
|
@@ -1,32 +1,9 @@
|
|
|
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 (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
4
|
};
|
|
28
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.
|
|
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.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;
|
|
30
7
|
const boom_1 = require("@hapi/boom");
|
|
31
8
|
const axios_1 = __importDefault(require("axios"));
|
|
32
9
|
const crypto_1 = require("crypto");
|
|
@@ -203,7 +180,9 @@ exports.bindWaitForConnectionUpdate = bindWaitForConnectionUpdate;
|
|
|
203
180
|
const printQRIfNecessaryListener = (ev, logger) => {
|
|
204
181
|
ev.on('connection.update', async ({ qr }) => {
|
|
205
182
|
if (qr) {
|
|
206
|
-
const QR = await
|
|
183
|
+
const QR = await import('qrcode-terminal')
|
|
184
|
+
.then(m => m.default || m)
|
|
185
|
+
.catch(() => {
|
|
207
186
|
logger.error('QR code terminal not added as dependency');
|
|
208
187
|
});
|
|
209
188
|
QR === null || QR === void 0 ? void 0 : QR.generate(qr, { small: true });
|
|
@@ -357,7 +336,7 @@ const isWABusinessPlatform = (platform) => {
|
|
|
357
336
|
return platform === 'smbi' || platform === 'smba';
|
|
358
337
|
};
|
|
359
338
|
exports.isWABusinessPlatform = isWABusinessPlatform;
|
|
360
|
-
function
|
|
339
|
+
function trimUndefined(obj) {
|
|
361
340
|
for (const key in obj) {
|
|
362
341
|
if (typeof obj[key] === 'undefined') {
|
|
363
342
|
delete obj[key];
|
|
@@ -365,4 +344,23 @@ function trimUndefineds(obj) {
|
|
|
365
344
|
}
|
|
366
345
|
return obj;
|
|
367
346
|
}
|
|
368
|
-
exports.
|
|
347
|
+
exports.trimUndefined = trimUndefined;
|
|
348
|
+
const CROCKFORD_CHARACTERS = '123456789ABCDEFGHJKLMNPQRSTVWXYZ';
|
|
349
|
+
function bytesToCrockford(buffer) {
|
|
350
|
+
let value = 0;
|
|
351
|
+
let bitCount = 0;
|
|
352
|
+
const crockford = [];
|
|
353
|
+
for (let i = 0; i < buffer.length; i++) {
|
|
354
|
+
value = (value << 8) | (buffer[i] & 0xff);
|
|
355
|
+
bitCount += 8;
|
|
356
|
+
while (bitCount >= 5) {
|
|
357
|
+
crockford.push(CROCKFORD_CHARACTERS.charAt((value >>> (bitCount - 5)) & 31));
|
|
358
|
+
bitCount -= 5;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
if (bitCount > 0) {
|
|
362
|
+
crockford.push(CROCKFORD_CHARACTERS.charAt((value << (5 - bitCount)) & 31));
|
|
363
|
+
}
|
|
364
|
+
return crockford.join('');
|
|
365
|
+
}
|
|
366
|
+
exports.bytesToCrockford = bytesToCrockford;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AxiosRequestConfig } from 'axios';
|
|
2
2
|
import { Logger } from 'pino';
|
|
3
3
|
import { WAMediaUploadFunction, WAUrlInfo } from '../Types';
|
|
4
|
-
export
|
|
4
|
+
export type URLGenerationOptions = {
|
|
5
5
|
thumbnailWidth: number;
|
|
6
6
|
fetchOpts: {
|
|
7
7
|
/** Timeout in ms */
|
|
@@ -1,27 +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 (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
3
|
exports.getUrlInfo = void 0;
|
|
27
4
|
const messages_1 = require("./messages");
|
|
@@ -48,7 +25,7 @@ const getUrlInfo = async (text, opts = {
|
|
|
48
25
|
// retries
|
|
49
26
|
const retries = 0;
|
|
50
27
|
const maxRetry = 5;
|
|
51
|
-
const { getLinkPreview } = await
|
|
28
|
+
const { getLinkPreview } = await import('link-preview-js');
|
|
52
29
|
let previewLink = text;
|
|
53
30
|
if (!text.startsWith('https://') && !text.startsWith('http://')) {
|
|
54
31
|
previewLink = 'https://' + previewLink;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare const makeMutex: () => {
|
|
2
2
|
mutex<T>(code: () => T | Promise<T>): Promise<T>;
|
|
3
3
|
};
|
|
4
|
-
export
|
|
4
|
+
export type Mutex = ReturnType<typeof makeMutex>;
|
|
5
5
|
export declare const makeKeyedMutex: () => {
|
|
6
6
|
mutex<T>(key: string, task: () => T | Promise<T>): Promise<T>;
|
|
7
7
|
};
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
/// <reference types="node" />
|
|
2
4
|
import { Boom } from '@hapi/boom';
|
|
3
5
|
import { AxiosRequestConfig } from 'axios';
|
|
4
6
|
import type { Logger } from 'pino';
|
|
@@ -24,9 +26,13 @@ export declare const generateProfilePicture: (mediaUpload: WAMediaUpload) => Pro
|
|
|
24
26
|
/** gets the SHA256 of the given media message */
|
|
25
27
|
export declare const mediaMessageSHA256B64: (message: WAMessageContent) => string | null | undefined;
|
|
26
28
|
export declare function getAudioDuration(buffer: Buffer | string | Readable): Promise<number | undefined>;
|
|
29
|
+
/**
|
|
30
|
+
referenced from and modifying https://github.com/wppconnect-team/wa-js/blob/main/src/chat/functions/prepareAudioWaveform.ts
|
|
31
|
+
*/
|
|
32
|
+
export declare function getAudioWaveform(buffer: Buffer | string | Readable, logger?: Logger): Promise<Uint8Array | undefined>;
|
|
27
33
|
export declare const toReadable: (buffer: Buffer) => Readable;
|
|
28
34
|
export declare const toBuffer: (stream: Readable) => Promise<Buffer>;
|
|
29
|
-
export declare const getStream: (item: WAMediaUpload, opts?: AxiosRequestConfig
|
|
35
|
+
export declare const getStream: (item: WAMediaUpload, opts?: AxiosRequestConfig) => Promise<{
|
|
30
36
|
readonly stream: Readable;
|
|
31
37
|
readonly type: "buffer";
|
|
32
38
|
} | {
|
|
@@ -52,7 +58,7 @@ export declare function generateThumbnail(file: string, mediaType: 'video' | 'im
|
|
|
52
58
|
export declare const getHttpStream: (url: string | URL, options?: AxiosRequestConfig & {
|
|
53
59
|
isStream?: true;
|
|
54
60
|
}) => Promise<Readable>;
|
|
55
|
-
|
|
61
|
+
type EncryptedStreamOptions = {
|
|
56
62
|
saveOriginalFileIfRequired?: boolean;
|
|
57
63
|
logger?: Logger;
|
|
58
64
|
opts?: AxiosRequestConfig;
|
|
@@ -67,7 +73,7 @@ export declare const encryptedStream: (media: WAMediaUpload, mediaType: MediaTyp
|
|
|
67
73
|
fileLength: number;
|
|
68
74
|
didSaveToTmpPath: boolean;
|
|
69
75
|
}>;
|
|
70
|
-
export
|
|
76
|
+
export type MediaDownloadOptions = {
|
|
71
77
|
startByte?: number;
|
|
72
78
|
endByte?: number;
|
|
73
79
|
options?: AxiosRequestConfig<any>;
|