@genuxofficial/baileys 2.0.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/WAProto/WAProto.proto +4633 -0
- package/engine-requirements.js +1 -1
- package/lib/Defaults/index.d.ts +5 -3
- package/lib/Defaults/index.js +7 -7
- package/lib/Signal/libsignal.js +9 -18
- package/lib/Socket/Client/types.d.ts +2 -0
- package/lib/Socket/Client/websocket.js +1 -1
- package/lib/Socket/business.d.ts +40 -38
- package/lib/Socket/chats.d.ts +17 -20
- package/lib/Socket/chats.js +1 -85
- package/lib/Socket/groups.d.ts +25 -28
- package/lib/Socket/groups.js +9 -10
- package/lib/Socket/index.d.ts +46 -44
- package/lib/Socket/messages-recv.d.ts +37 -36
- package/lib/Socket/messages-recv.js +14 -26
- package/lib/Socket/messages-send.d.ts +35 -33
- package/lib/Socket/messages-send.js +10 -8
- package/lib/Socket/newsletter.d.ts +28 -31
- package/lib/Socket/newsletter.js +21 -17
- package/lib/Socket/socket.d.ts +7 -5
- package/lib/Socket/socket.js +1 -1
- package/lib/Socket/usync.d.ts +11 -9
- package/lib/Socket/usync.js +15 -10
- package/lib/Store/make-in-memory-store.d.ts +1 -1
- package/lib/Store/make-ordered-dictionary.d.ts +1 -1
- package/lib/Types/Auth.d.ts +2 -0
- package/lib/Types/Chat.d.ts +2 -8
- package/lib/Types/Contact.d.ts +0 -5
- package/lib/Types/GroupMetadata.d.ts +4 -5
- package/lib/Types/Label.d.ts +0 -11
- package/lib/Types/Label.js +1 -1
- package/lib/Types/LabelAssociation.js +1 -1
- package/lib/Types/Message.d.ts +27 -2
- package/lib/Types/Newsletter.js +2 -2
- package/lib/Types/Socket.d.ts +2 -0
- package/lib/Types/index.js +1 -1
- package/lib/Utils/auth-utils.js +3 -3
- package/lib/Utils/business.js +17 -5
- package/lib/Utils/chat-utils.d.ts +10 -8
- package/lib/Utils/chat-utils.js +0 -27
- package/lib/Utils/crypto.d.ts +16 -14
- package/lib/Utils/crypto.js +22 -34
- package/lib/Utils/decode-wa-message.d.ts +1 -1
- package/lib/Utils/decode-wa-message.js +16 -31
- package/lib/Utils/generics.d.ts +8 -33
- package/lib/Utils/generics.js +12 -98
- package/lib/Utils/link-preview.js +1 -34
- package/lib/Utils/make-mutex.d.ts +2 -2
- package/lib/Utils/messages-media.d.ts +19 -29
- package/lib/Utils/messages-media.js +87 -151
- package/lib/Utils/messages.d.ts +8 -5
- package/lib/Utils/messages.js +20 -28
- package/lib/Utils/noise-handler.d.ts +6 -4
- package/lib/Utils/process-message.js +2 -2
- package/lib/Utils/validate-connection.d.ts +2 -2
- package/lib/WABinary/decode.d.ts +4 -2
- package/lib/WABinary/decode.js +7 -17
- package/lib/WABinary/encode.d.ts +3 -1
- package/lib/WABinary/encode.js +7 -17
- package/lib/WABinary/generic-utils.d.ts +6 -6
- package/lib/WABinary/generic-utils.js +36 -21
- package/lib/WABinary/jid-utils.d.ts +6 -2
- package/lib/WABinary/jid-utils.js +5 -1
- package/lib/WAM/BinaryInfo.d.ts +12 -2
- package/lib/WAM/encode.d.ts +3 -1
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +23 -14
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +2 -2
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +1 -1
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +1 -1
- package/lib/WAUSync/USyncQuery.js +13 -17
- package/package.json +59 -53
- package/lib/Store/make-cache-manager-store.d.ts +0 -14
- package/lib/Store/make-cache-manager-store.js +0 -83
package/lib/Socket/socket.d.ts
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
/// <reference types="node" />
|
2
|
+
/// <reference types="node" />
|
1
3
|
import { Boom } from '@hapi/boom';
|
2
4
|
import { SocketConfig } from '../Types';
|
3
5
|
import { BinaryNode } from '../WABinary';
|
@@ -12,10 +14,10 @@ export declare const makeSocket: (config: SocketConfig) => {
|
|
12
14
|
type: "md";
|
13
15
|
ws: WebSocketClient;
|
14
16
|
ev: import("../Types").BaileysEventEmitter & {
|
15
|
-
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): (
|
17
|
+
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
|
16
18
|
buffer(): void;
|
17
|
-
createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): (
|
18
|
-
flush(force?: boolean): boolean;
|
19
|
+
createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): (...args: A) => Promise<T>;
|
20
|
+
flush(force?: boolean | undefined): boolean;
|
19
21
|
isBuffering(): boolean;
|
20
22
|
};
|
21
23
|
authState: {
|
@@ -26,7 +28,7 @@ export declare const makeSocket: (config: SocketConfig) => {
|
|
26
28
|
readonly user: import("../Types").Contact | undefined;
|
27
29
|
generateMessageTag: () => string;
|
28
30
|
query: (node: BinaryNode, timeoutMs?: number) => Promise<any>;
|
29
|
-
waitForMessage: <
|
31
|
+
waitForMessage: <T_1>(msgId: string, timeoutMs?: number | undefined) => Promise<any>;
|
30
32
|
waitForSocketOpen: () => Promise<void>;
|
31
33
|
sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
|
32
34
|
sendNode: (frame: BinaryNode) => Promise<void>;
|
@@ -37,7 +39,7 @@ export declare const makeSocket: (config: SocketConfig) => {
|
|
37
39
|
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
38
40
|
requestPairingCode: (phoneNumber: string, pairCode: string) => Promise<string>;
|
39
41
|
/** Waits for the connection to WA to reach a state */
|
40
|
-
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
|
42
|
+
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number | undefined) => Promise<void>;
|
41
43
|
sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
|
42
44
|
};
|
43
45
|
export type Socket = ReturnType<typeof makeSocket>;
|
package/lib/Socket/socket.js
CHANGED
package/lib/Socket/usync.d.ts
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
/// <reference types="node" />
|
2
|
+
/// <reference types="node" />
|
1
3
|
import { Boom } from '@hapi/boom';
|
2
4
|
import { SocketConfig } from '../Types';
|
3
5
|
import { BinaryNode } from '../WABinary';
|
@@ -5,12 +7,12 @@ import { USyncQuery } from '../WAUSync';
|
|
5
7
|
export declare const makeUSyncSocket: (config: SocketConfig) => {
|
6
8
|
executeUSyncQuery: (usyncQuery: USyncQuery) => Promise<import("../WAUSync").USyncQueryResult | undefined>;
|
7
9
|
type: "md";
|
8
|
-
ws: import("./Client").WebSocketClient;
|
10
|
+
ws: import("./Client/websocket").WebSocketClient;
|
9
11
|
ev: import("../Types").BaileysEventEmitter & {
|
10
|
-
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): (
|
12
|
+
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
|
11
13
|
buffer(): void;
|
12
|
-
createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): (
|
13
|
-
flush(force?: boolean): boolean;
|
14
|
+
createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): (...args: A) => Promise<T>;
|
15
|
+
flush(force?: boolean | undefined): boolean;
|
14
16
|
isBuffering(): boolean;
|
15
17
|
};
|
16
18
|
authState: {
|
@@ -20,17 +22,17 @@ export declare const makeUSyncSocket: (config: SocketConfig) => {
|
|
20
22
|
signalRepository: import("../Types").SignalRepository;
|
21
23
|
user: import("../Types").Contact | undefined;
|
22
24
|
generateMessageTag: () => string;
|
23
|
-
query: (node: BinaryNode, timeoutMs?: number) => Promise<any>;
|
24
|
-
waitForMessage: <
|
25
|
+
query: (node: BinaryNode, timeoutMs?: number | undefined) => Promise<any>;
|
26
|
+
waitForMessage: <T_1>(msgId: string, timeoutMs?: number | undefined) => Promise<any>;
|
25
27
|
waitForSocketOpen: () => Promise<void>;
|
26
28
|
sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
|
27
29
|
sendNode: (frame: BinaryNode) => Promise<void>;
|
28
|
-
logout: (msg?: string) => Promise<void>;
|
30
|
+
logout: (msg?: string | undefined) => Promise<void>;
|
29
31
|
end: (error: Error | undefined) => void;
|
30
|
-
onUnexpectedError: (err: Error | Boom
|
32
|
+
onUnexpectedError: (err: Error | Boom<any>, msg: string) => void;
|
31
33
|
uploadPreKeys: (count?: number) => Promise<void>;
|
32
34
|
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
33
35
|
requestPairingCode: (phoneNumber: string, pairCode: string) => Promise<string>;
|
34
|
-
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
|
36
|
+
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number | undefined) => Promise<void>;
|
35
37
|
sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
|
36
38
|
};
|
package/lib/Socket/usync.js
CHANGED
@@ -6,7 +6,7 @@ const WABinary_1 = require("../WABinary");
|
|
6
6
|
const socket_1 = require("./socket");
|
7
7
|
const makeUSyncSocket = (config) => {
|
8
8
|
const sock = (0, socket_1.makeSocket)(config);
|
9
|
-
const { generateMessageTag, query } = sock;
|
9
|
+
const { generateMessageTag, query, } = sock;
|
10
10
|
const executeUSyncQuery = async (usyncQuery) => {
|
11
11
|
if (usyncQuery.protocols.length === 0) {
|
12
12
|
throw new boom_1.Boom('USyncQuery must have at least one protocol');
|
@@ -14,13 +14,15 @@ const makeUSyncSocket = (config) => {
|
|
14
14
|
// todo: validate users, throw WARNING on no valid users
|
15
15
|
// variable below has only validated users
|
16
16
|
const validUsers = usyncQuery.users;
|
17
|
-
const userNodes = validUsers.map(user => {
|
17
|
+
const userNodes = validUsers.map((user) => {
|
18
18
|
return {
|
19
19
|
tag: 'user',
|
20
20
|
attrs: {
|
21
|
-
jid: !user.phone ? user.id : undefined
|
21
|
+
jid: !user.phone ? user.id : undefined,
|
22
22
|
},
|
23
|
-
content: usyncQuery.protocols
|
23
|
+
content: usyncQuery.protocols
|
24
|
+
.map((a) => a.getUserElement(user))
|
25
|
+
.filter(a => a !== null)
|
24
26
|
};
|
25
27
|
});
|
26
28
|
const listNode = {
|
@@ -31,14 +33,14 @@ const makeUSyncSocket = (config) => {
|
|
31
33
|
const queryNode = {
|
32
34
|
tag: 'query',
|
33
35
|
attrs: {},
|
34
|
-
content: usyncQuery.protocols.map(a => a.getQueryElement())
|
36
|
+
content: usyncQuery.protocols.map((a) => a.getQueryElement())
|
35
37
|
};
|
36
38
|
const iq = {
|
37
39
|
tag: 'iq',
|
38
40
|
attrs: {
|
39
41
|
to: WABinary_1.S_WHATSAPP_NET,
|
40
42
|
type: 'get',
|
41
|
-
xmlns: 'usync'
|
43
|
+
xmlns: 'usync',
|
42
44
|
},
|
43
45
|
content: [
|
44
46
|
{
|
@@ -48,18 +50,21 @@ const makeUSyncSocket = (config) => {
|
|
48
50
|
mode: usyncQuery.mode,
|
49
51
|
sid: generateMessageTag(),
|
50
52
|
last: 'true',
|
51
|
-
index: '0'
|
53
|
+
index: '0',
|
52
54
|
},
|
53
|
-
content: [
|
55
|
+
content: [
|
56
|
+
queryNode,
|
57
|
+
listNode
|
58
|
+
]
|
54
59
|
}
|
55
|
-
]
|
60
|
+
],
|
56
61
|
};
|
57
62
|
const result = await query(iq);
|
58
63
|
return usyncQuery.parseUSyncQueryResult(result);
|
59
64
|
};
|
60
65
|
return {
|
61
66
|
...sock,
|
62
|
-
executeUSyncQuery
|
67
|
+
executeUSyncQuery,
|
63
68
|
};
|
64
69
|
};
|
65
70
|
exports.makeUSyncSocket = makeUSyncSocket;
|
@@ -1,7 +1,7 @@
|
|
1
1
|
declare function makeOrderedDictionary<T>(idGetter: (item: T) => string): {
|
2
2
|
array: T[];
|
3
3
|
get: (id: string) => T | undefined;
|
4
|
-
upsert: (item: T, mode:
|
4
|
+
upsert: (item: T, mode: 'append' | 'prepend') => void;
|
5
5
|
update: (item: T) => boolean;
|
6
6
|
remove: (item: T) => boolean;
|
7
7
|
updateAssign: (id: string, update: Partial<T>) => boolean;
|
package/lib/Types/Auth.d.ts
CHANGED
package/lib/Types/Chat.d.ts
CHANGED
@@ -1,18 +1,16 @@
|
|
1
1
|
import type { proto } from '../../WAProto';
|
2
2
|
import type { AccountSettings } from './Auth';
|
3
|
-
import type { ContactAction } from './Contact';
|
4
3
|
import type { BufferedEventData } from './Events';
|
5
|
-
import type { LabelActionBody } from './Label';
|
6
4
|
import type { ChatLabelAssociationActionBody } from './LabelAssociation';
|
7
5
|
import type { MessageLabelAssociationActionBody } from './LabelAssociation';
|
8
6
|
import type { MinimalMessage, WAMessageKey } from './Message';
|
9
7
|
/** privacy settings in WhatsApp Web */
|
10
8
|
export type WAPrivacyValue = 'all' | 'contacts' | 'contact_blacklist' | 'none';
|
9
|
+
export type WAPrivacyCallValue = 'all' | 'known';
|
10
|
+
export type WAPrivacyMessagesValue = 'all' | 'contacts';
|
11
11
|
export type WAPrivacyOnlineValue = 'all' | 'match_last_seen';
|
12
12
|
export type WAPrivacyGroupAddValue = 'all' | 'contacts' | 'contact_blacklist';
|
13
13
|
export type WAReadReceiptsValue = 'all' | 'none';
|
14
|
-
export type WAPrivacyCallValue = 'all' | 'known';
|
15
|
-
export type WAPrivacyMessagesValue = 'all' | 'contacts';
|
16
14
|
/** set of statuses visible to other people; see updatePresence() in WhatsAppWeb.Send */
|
17
15
|
export type WAPresence = 'unavailable' | 'available' | 'composing' | 'recording' | 'paused';
|
18
16
|
export declare const ALL_WA_PATCH_NAMES: readonly ["critical_block", "critical_unblock_low", "regular_high", "regular_low", "regular"];
|
@@ -89,10 +87,6 @@ export type ChatModification = {
|
|
89
87
|
} | {
|
90
88
|
delete: true;
|
91
89
|
lastMessages: LastMessageList;
|
92
|
-
} | {
|
93
|
-
contact: ContactAction | null;
|
94
|
-
} | {
|
95
|
-
addLabel: LabelActionBody;
|
96
90
|
} | {
|
97
91
|
addChatLabel: ChatLabelAssociationActionBody;
|
98
92
|
} | {
|
package/lib/Types/Contact.d.ts
CHANGED
@@ -3,7 +3,7 @@ export type GroupParticipant = (Contact & {
|
|
3
3
|
isAdmin?: boolean;
|
4
4
|
isSuperAdmin?: boolean;
|
5
5
|
admin?: 'admin' | 'superadmin' | null;
|
6
|
-
|
6
|
+
phoneNumber?: string | undefined;
|
7
7
|
});
|
8
8
|
export type ParticipantAction = 'add' | 'remove' | 'promote' | 'demote' | 'modify';
|
9
9
|
export type RequestJoinAction = 'created' | 'revoked' | 'rejected';
|
@@ -11,19 +11,18 @@ export type RequestJoinMethod = 'invite_link' | 'linked_group_join' | 'non_admin
|
|
11
11
|
export interface GroupMetadata {
|
12
12
|
id: string;
|
13
13
|
/** group uses 'lid' or 'pn' to send messages */
|
14
|
-
addressingMode:
|
14
|
+
addressingMode: "pn" | "lid";
|
15
15
|
owner: string | undefined;
|
16
|
-
onwerPn?: string | undefined;
|
17
16
|
subject: string;
|
18
17
|
/** group subject owner */
|
19
18
|
subjectOwner?: string;
|
20
|
-
|
19
|
+
subjectOwnerPhoneNumber?: string;
|
21
20
|
/** group subject modification date */
|
22
21
|
subjectTime?: number;
|
23
22
|
creation?: number;
|
24
23
|
desc?: string;
|
25
24
|
descOwner?: string;
|
26
|
-
|
25
|
+
descOwnerPhoneNumber?: string;
|
27
26
|
descId?: string;
|
28
27
|
descTime?: number;
|
29
28
|
/** if this group is part of a community, it returns the jid of the community to which it belongs */
|
package/lib/Types/Label.d.ts
CHANGED
@@ -10,17 +10,6 @@ export interface Label {
|
|
10
10
|
/** WhatsApp has 5 predefined labels (New customer, New order & etc) */
|
11
11
|
predefinedId?: string;
|
12
12
|
}
|
13
|
-
export interface LabelActionBody {
|
14
|
-
id: string;
|
15
|
-
/** Label name */
|
16
|
-
name?: string;
|
17
|
-
/** Label color ID */
|
18
|
-
color?: number;
|
19
|
-
/** Is label has been deleted */
|
20
|
-
deleted?: boolean;
|
21
|
-
/** WhatsApp has 5 predefined labels (New customer, New order & etc) */
|
22
|
-
predefinedId?: number;
|
23
|
-
}
|
24
13
|
/** WhatsApp has 20 predefined colors */
|
25
14
|
export declare enum LabelColor {
|
26
15
|
Color1 = 0,
|
package/lib/Types/Label.js
CHANGED
@@ -24,4 +24,4 @@ var LabelColor;
|
|
24
24
|
LabelColor[LabelColor["Color18"] = 17] = "Color18";
|
25
25
|
LabelColor[LabelColor["Color19"] = 18] = "Color19";
|
26
26
|
LabelColor[LabelColor["Color20"] = 19] = "Color20";
|
27
|
-
})(LabelColor
|
27
|
+
})(LabelColor = exports.LabelColor || (exports.LabelColor = {}));
|
@@ -6,4 +6,4 @@ var LabelAssociationType;
|
|
6
6
|
(function (LabelAssociationType) {
|
7
7
|
LabelAssociationType["Chat"] = "label_jid";
|
8
8
|
LabelAssociationType["Message"] = "label_message";
|
9
|
-
})(LabelAssociationType
|
9
|
+
})(LabelAssociationType = exports.LabelAssociationType || (exports.LabelAssociationType = {}));
|
package/lib/Types/Message.d.ts
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
/// <reference types="node" />
|
2
|
+
/// <reference types="node" />
|
3
|
+
/// <reference types="node" />
|
4
|
+
/// <reference types="node" />
|
1
5
|
import { AxiosRequestConfig } from 'axios';
|
2
6
|
import type { Readable } from 'stream';
|
3
7
|
import type { URL } from 'url';
|
@@ -13,7 +17,6 @@ export type WAMessageContent = proto.IMessage;
|
|
13
17
|
export type WAContactMessage = proto.Message.IContactMessage;
|
14
18
|
export type WAContactsArrayMessage = proto.Message.IContactsArrayMessage;
|
15
19
|
export type WAMessageKey = proto.IMessageKey & {
|
16
|
-
lid?: string;
|
17
20
|
server_id?: string;
|
18
21
|
};
|
19
22
|
export type WATextMessage = proto.Message.IExtendedTextMessage;
|
@@ -327,13 +330,35 @@ export type MiscMessageGenerationOptions = MinimalRelayOptions & {
|
|
327
330
|
export type MessageGenerationOptionsFromContent = MiscMessageGenerationOptions & {
|
328
331
|
userJid: string;
|
329
332
|
};
|
333
|
+
export type PrepareStreamResult = {
|
334
|
+
type: 'prepare';
|
335
|
+
mediaKey: undefined;
|
336
|
+
encWriteStream: Buffer;
|
337
|
+
fileLength: number;
|
338
|
+
fileSha256: Buffer;
|
339
|
+
fileEncSha256: undefined;
|
340
|
+
bodyPath: string | undefined;
|
341
|
+
didSaveToTmpPath: boolean;
|
342
|
+
};
|
343
|
+
export type EncryptedStreamResult = {
|
344
|
+
type: 'encrypted';
|
345
|
+
mediaKey: Buffer;
|
346
|
+
originalFilePath: string | undefined;
|
347
|
+
encFilePath: string;
|
348
|
+
mac: Buffer;
|
349
|
+
fileEncSha256: Buffer;
|
350
|
+
fileSha256: Buffer;
|
351
|
+
fileLength: number;
|
352
|
+
didSaveToTmpPath: boolean;
|
353
|
+
};
|
354
|
+
export type StreamResult = PrepareStreamResult | EncryptedStreamResult;
|
330
355
|
export type WAMediaUploadFunctionOpts = {
|
331
356
|
fileEncSha256B64: string;
|
332
357
|
mediaType: MediaType;
|
333
358
|
newsletter?: boolean;
|
334
359
|
timeoutMs?: number;
|
335
360
|
};
|
336
|
-
export type WAMediaUploadFunction = (
|
361
|
+
export type WAMediaUploadFunction = (encFilePath: string, opts: WAMediaUploadFunctionOpts) => Promise<{
|
337
362
|
mediaUrl: string;
|
338
363
|
directPath: string;
|
339
364
|
handle?: string;
|
package/lib/Types/Newsletter.js
CHANGED
@@ -6,7 +6,7 @@ var MexOperations;
|
|
6
6
|
MexOperations["PROMOTE"] = "NotificationNewsletterAdminPromote";
|
7
7
|
MexOperations["DEMOTE"] = "NotificationNewsletterAdminDemote";
|
8
8
|
MexOperations["UPDATE"] = "NotificationNewsletterUpdate";
|
9
|
-
})(MexOperations
|
9
|
+
})(MexOperations = exports.MexOperations || (exports.MexOperations = {}));
|
10
10
|
var XWAPaths;
|
11
11
|
(function (XWAPaths) {
|
12
12
|
XWAPaths["PROMOTE"] = "xwa2_notify_newsletter_admin_promote";
|
@@ -15,4 +15,4 @@ var XWAPaths;
|
|
15
15
|
XWAPaths["CREATE"] = "xwa2_newsletter_create";
|
16
16
|
XWAPaths["NEWSLETTER"] = "xwa2_newsletter";
|
17
17
|
XWAPaths["METADATA_UPDATE"] = "xwa2_notify_newsletter_on_metadata_update";
|
18
|
-
})(XWAPaths
|
18
|
+
})(XWAPaths = exports.XWAPaths || (exports.XWAPaths = {}));
|
package/lib/Types/Socket.d.ts
CHANGED
package/lib/Types/index.js
CHANGED
@@ -39,4 +39,4 @@ var DisconnectReason;
|
|
39
39
|
DisconnectReason[DisconnectReason["multideviceMismatch"] = 411] = "multideviceMismatch";
|
40
40
|
DisconnectReason[DisconnectReason["forbidden"] = 403] = "forbidden";
|
41
41
|
DisconnectReason[DisconnectReason["unavailableService"] = 503] = "unavailableService";
|
42
|
-
})(DisconnectReason
|
42
|
+
})(DisconnectReason = exports.DisconnectReason || (exports.DisconnectReason = {}));
|
package/lib/Utils/auth-utils.js
CHANGED
@@ -3,8 +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.initAuthCreds = exports.addTransactionCapability = void 0;
|
7
|
-
exports.makeCacheableSignalKeyStore = makeCacheableSignalKeyStore;
|
6
|
+
exports.initAuthCreds = exports.addTransactionCapability = exports.makeCacheableSignalKeyStore = void 0;
|
8
7
|
const crypto_1 = require("crypto");
|
9
8
|
const node_cache_1 = __importDefault(require("@cacheable/node-cache"));
|
10
9
|
const Defaults_1 = require("../Defaults");
|
@@ -18,7 +17,7 @@ const generics_1 = require("./generics");
|
|
18
17
|
*/
|
19
18
|
function makeCacheableSignalKeyStore(store, logger, _cache) {
|
20
19
|
const cache = _cache || new node_cache_1.default({
|
21
|
-
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.SIGNAL_STORE,
|
20
|
+
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.SIGNAL_STORE,
|
22
21
|
useClones: false,
|
23
22
|
deleteOnExpire: true,
|
24
23
|
});
|
@@ -69,6 +68,7 @@ function makeCacheableSignalKeyStore(store, logger, _cache) {
|
|
69
68
|
}
|
70
69
|
};
|
71
70
|
}
|
71
|
+
exports.makeCacheableSignalKeyStore = makeCacheableSignalKeyStore;
|
72
72
|
/**
|
73
73
|
* Adds DB like transaction capability (https://en.wikipedia.org/wiki/Database_transaction) to the SignalKeyStore,
|
74
74
|
* this allows batch read & write operations & improves the performance of the lib
|
package/lib/Utils/business.js
CHANGED
@@ -1,10 +1,15 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.uploadingNecessaryImages = exports.parseProductNode = exports.toProductNode = exports.parseOrderDetailsNode = exports.parseCollectionsNode = exports.parseCatalogNode = void 0;
|
4
|
-
exports.uploadingNecessaryImagesOfProduct = uploadingNecessaryImagesOfProduct;
|
3
|
+
exports.uploadingNecessaryImages = exports.uploadingNecessaryImagesOfProduct = exports.parseProductNode = exports.toProductNode = exports.parseOrderDetailsNode = exports.parseCollectionsNode = exports.parseCatalogNode = void 0;
|
5
4
|
const boom_1 = require("@hapi/boom");
|
6
5
|
const crypto_1 = require("crypto");
|
6
|
+
//new import
|
7
|
+
const fs_1 = require("fs");
|
8
|
+
const os_1 = require("os");
|
9
|
+
const path_1 = require("path");
|
7
10
|
const WABinary_1 = require("../WABinary");
|
11
|
+
//import { getStream, getUrlFromDirectPath, toReadable } from './messages-media'
|
12
|
+
const generics_1 = require("./generics");
|
8
13
|
const messages_media_1 = require("./messages-media");
|
9
14
|
const parseCatalogNode = (node) => {
|
10
15
|
const catalogNode = (0, WABinary_1.getBinaryNodeChild)(node, 'product_catalog');
|
@@ -189,6 +194,7 @@ async function uploadingNecessaryImagesOfProduct(product, waUploadToServer, time
|
|
189
194
|
};
|
190
195
|
return product;
|
191
196
|
}
|
197
|
+
exports.uploadingNecessaryImagesOfProduct = uploadingNecessaryImagesOfProduct;
|
192
198
|
/**
|
193
199
|
* Uploads images not already uploaded to WA's servers
|
194
200
|
*/
|
@@ -202,17 +208,23 @@ const uploadingNecessaryImages = async (images, waUploadToServer, timeoutMs = 30
|
|
202
208
|
}
|
203
209
|
const { stream } = await (0, messages_media_1.getStream)(img);
|
204
210
|
const hasher = (0, crypto_1.createHash)('sha256');
|
205
|
-
const contentBlocks = []
|
211
|
+
//const contentBlocks: Buffer[] = []
|
212
|
+
const filePath = (0, path_1.join)((0, os_1.tmpdir)(), 'img' + (0, generics_1.generateMessageIDV2)());
|
213
|
+
const encFileWriteStream = (0, fs_1.createWriteStream)(filePath);
|
206
214
|
for await (const block of stream) {
|
207
215
|
hasher.update(block);
|
208
|
-
contentBlocks.push(block)
|
216
|
+
//contentBlocks.push(block)
|
217
|
+
encFileWriteStream.write(block);
|
209
218
|
}
|
210
219
|
const sha = hasher.digest('base64');
|
211
|
-
const { directPath } = await waUploadToServer(
|
220
|
+
const { directPath } = await waUploadToServer(filePath, {
|
212
221
|
mediaType: 'product-catalog-image',
|
213
222
|
fileEncSha256B64: sha,
|
214
223
|
timeoutMs
|
215
224
|
});
|
225
|
+
await fs_1.promises
|
226
|
+
.unlink(filePath)
|
227
|
+
.catch(err => console.log('Error deleting temp file ', err));
|
216
228
|
return { url: (0, messages_media_1.getUrlFromDirectPath)(directPath) };
|
217
229
|
}));
|
218
230
|
return results;
|
@@ -1,3 +1,5 @@
|
|
1
|
+
/// <reference types="node" />
|
2
|
+
/// <reference types="node" />
|
1
3
|
import { AxiosRequestConfig } from 'axios';
|
2
4
|
import { proto } from '../../WAProto';
|
3
5
|
import { BaileysEventEmitter, ChatModification, ChatMutation, Contact, InitialAppStateSyncOptions, LTHashState, WAPatchCreate, WAPatchName } from '../Types';
|
@@ -13,7 +15,7 @@ export declare const encodeSyncdPatch: ({ type, index, syncAction, apiVersion, o
|
|
13
15
|
state: LTHashState;
|
14
16
|
}>;
|
15
17
|
export declare const decodeSyncdMutations: (msgMutations: (proto.ISyncdMutation | proto.ISyncdRecord)[], initialState: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey, onMutation: (mutation: ChatMutation) => void, validateMacs: boolean) => Promise<{
|
16
|
-
hash: Buffer
|
18
|
+
hash: Buffer;
|
17
19
|
indexValueMap: {
|
18
20
|
[indexMacBase64: string]: {
|
19
21
|
valueMac: Uint8Array | Buffer;
|
@@ -21,7 +23,7 @@ export declare const decodeSyncdMutations: (msgMutations: (proto.ISyncdMutation
|
|
21
23
|
};
|
22
24
|
}>;
|
23
25
|
export declare const decodeSyncdPatch: (msg: proto.ISyncdPatch, name: WAPatchName, initialState: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey, onMutation: (mutation: ChatMutation) => void, validateMacs: boolean) => Promise<{
|
24
|
-
hash: Buffer
|
26
|
+
hash: Buffer;
|
25
27
|
indexValueMap: {
|
26
28
|
[indexMacBase64: string]: {
|
27
29
|
valueMac: Uint8Array | Buffer;
|
@@ -32,30 +34,30 @@ export declare const extractSyncdPatches: (result: BinaryNode, options: AxiosReq
|
|
32
34
|
critical_block: {
|
33
35
|
patches: proto.ISyncdPatch[];
|
34
36
|
hasMorePatches: boolean;
|
35
|
-
snapshot?: proto.ISyncdSnapshot;
|
37
|
+
snapshot?: proto.ISyncdSnapshot | undefined;
|
36
38
|
};
|
37
39
|
critical_unblock_low: {
|
38
40
|
patches: proto.ISyncdPatch[];
|
39
41
|
hasMorePatches: boolean;
|
40
|
-
snapshot?: proto.ISyncdSnapshot;
|
42
|
+
snapshot?: proto.ISyncdSnapshot | undefined;
|
41
43
|
};
|
42
44
|
regular_high: {
|
43
45
|
patches: proto.ISyncdPatch[];
|
44
46
|
hasMorePatches: boolean;
|
45
|
-
snapshot?: proto.ISyncdSnapshot;
|
47
|
+
snapshot?: proto.ISyncdSnapshot | undefined;
|
46
48
|
};
|
47
49
|
regular_low: {
|
48
50
|
patches: proto.ISyncdPatch[];
|
49
51
|
hasMorePatches: boolean;
|
50
|
-
snapshot?: proto.ISyncdSnapshot;
|
52
|
+
snapshot?: proto.ISyncdSnapshot | undefined;
|
51
53
|
};
|
52
54
|
regular: {
|
53
55
|
patches: proto.ISyncdPatch[];
|
54
56
|
hasMorePatches: boolean;
|
55
|
-
snapshot?: proto.ISyncdSnapshot;
|
57
|
+
snapshot?: proto.ISyncdSnapshot | undefined;
|
56
58
|
};
|
57
59
|
}>;
|
58
|
-
export declare const downloadExternalBlob: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<{}>) => Promise<Buffer
|
60
|
+
export declare const downloadExternalBlob: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<{}>) => Promise<Buffer>;
|
59
61
|
export declare const downloadExternalPatch: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<{}>) => Promise<proto.SyncdMutations>;
|
60
62
|
export declare const decodeSyncdSnapshot: (name: WAPatchName, snapshot: proto.ISyncdSnapshot, getAppStateSyncKey: FetchAppStateSyncKey, minimumVersionNumber: number | undefined, validateMacs?: boolean) => Promise<{
|
61
63
|
state: LTHashState;
|
package/lib/Utils/chat-utils.js
CHANGED
@@ -456,17 +456,6 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
456
456
|
operation: OP.SET
|
457
457
|
};
|
458
458
|
}
|
459
|
-
else if ('contact' in mod) {
|
460
|
-
patch = {
|
461
|
-
syncAction: {
|
462
|
-
contactAction: mod.contact || {}
|
463
|
-
},
|
464
|
-
index: ['contact', jid],
|
465
|
-
type: 'critical_unblock_low',
|
466
|
-
apiVersion: 2,
|
467
|
-
operation: mod.contact ? OP.SET : OP.REMOVE
|
468
|
-
};
|
469
|
-
}
|
470
459
|
else if ('star' in mod) {
|
471
460
|
const key = mod.star.messages[0];
|
472
461
|
patch = {
|
@@ -507,22 +496,6 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
507
496
|
operation: OP.SET,
|
508
497
|
};
|
509
498
|
}
|
510
|
-
else if ('addLabel' in mod) {
|
511
|
-
patch = {
|
512
|
-
syncAction: {
|
513
|
-
labelEditAction: {
|
514
|
-
name: mod.addLabel.name,
|
515
|
-
color: mod.addLabel.color,
|
516
|
-
predefinedId: mod.addLabel.predefinedId,
|
517
|
-
deleted: mod.addLabel.deleted
|
518
|
-
}
|
519
|
-
},
|
520
|
-
index: ['label_edit', mod.addLabel.id],
|
521
|
-
type: 'regular',
|
522
|
-
apiVersion: 3,
|
523
|
-
operation: OP.SET,
|
524
|
-
};
|
525
|
-
}
|
526
499
|
else if ('addChatLabel' in mod) {
|
527
500
|
patch = {
|
528
501
|
syncAction: {
|
package/lib/Utils/crypto.d.ts
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
+
/// <reference types="node" />
|
2
|
+
/// <reference types="node" />
|
1
3
|
import { KeyPair } from '../Types';
|
2
4
|
/** prefix version byte to the pub keys, required for some curve crypto functions */
|
3
|
-
export declare const generateSignalPubKey: (pubKey: Uint8Array | Buffer) => Uint8Array
|
5
|
+
export declare const generateSignalPubKey: (pubKey: Uint8Array | Buffer) => Uint8Array | Buffer;
|
4
6
|
export declare const Curve: {
|
5
7
|
generateKeyPair: () => KeyPair;
|
6
|
-
sharedKey: (privateKey: Uint8Array, publicKey: Uint8Array) => Buffer
|
8
|
+
sharedKey: (privateKey: Uint8Array, publicKey: Uint8Array) => Buffer;
|
7
9
|
sign: (privateKey: Uint8Array, buf: Uint8Array) => any;
|
8
10
|
verify: (pubKey: Uint8Array, message: Uint8Array, signature: Uint8Array) => boolean;
|
9
11
|
};
|
@@ -16,25 +18,25 @@ export declare const signedKeyPair: (identityKeyPair: KeyPair, keyId: number) =>
|
|
16
18
|
* encrypt AES 256 GCM;
|
17
19
|
* where the tag tag is suffixed to the ciphertext
|
18
20
|
* */
|
19
|
-
export declare function aesEncryptGCM(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array): Buffer
|
21
|
+
export declare function aesEncryptGCM(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array): Buffer;
|
20
22
|
/**
|
21
23
|
* decrypt AES 256 GCM;
|
22
24
|
* where the auth tag is suffixed to the ciphertext
|
23
25
|
* */
|
24
|
-
export declare function aesDecryptGCM(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array): Buffer
|
25
|
-
export declare function aesEncryptCTR(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array): Buffer
|
26
|
-
export declare function aesDecryptCTR(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array): Buffer
|
26
|
+
export declare function aesDecryptGCM(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array): Buffer;
|
27
|
+
export declare function aesEncryptCTR(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array): Buffer;
|
28
|
+
export declare function aesDecryptCTR(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array): Buffer;
|
27
29
|
/** decrypt AES 256 CBC; where the IV is prefixed to the buffer */
|
28
|
-
export declare function aesDecrypt(buffer: Buffer, key: Buffer): Buffer
|
30
|
+
export declare function aesDecrypt(buffer: Buffer, key: Buffer): Buffer;
|
29
31
|
/** decrypt AES 256 CBC */
|
30
|
-
export declare function aesDecryptWithIV(buffer: Buffer, key: Buffer, IV: Buffer): Buffer
|
31
|
-
export declare function aesEncrypt(buffer: Buffer | Uint8Array, key: Buffer): Buffer
|
32
|
-
export declare function aesEncrypWithIV(buffer: Buffer, key: Buffer, IV: Buffer): Buffer
|
33
|
-
export declare function hmacSign(buffer: Buffer | Uint8Array, key: Buffer | Uint8Array, variant?: 'sha256' | 'sha512'): Buffer
|
34
|
-
export declare function sha256(buffer: Buffer): Buffer
|
35
|
-
export declare function md5(buffer: Buffer): Buffer
|
32
|
+
export declare function aesDecryptWithIV(buffer: Buffer, key: Buffer, IV: Buffer): Buffer;
|
33
|
+
export declare function aesEncrypt(buffer: Buffer | Uint8Array, key: Buffer): Buffer;
|
34
|
+
export declare function aesEncrypWithIV(buffer: Buffer, key: Buffer, IV: Buffer): Buffer;
|
35
|
+
export declare function hmacSign(buffer: Buffer | Uint8Array, key: Buffer | Uint8Array, variant?: 'sha256' | 'sha512'): Buffer;
|
36
|
+
export declare function sha256(buffer: Buffer): Buffer;
|
37
|
+
export declare function md5(buffer: Buffer): Buffer;
|
36
38
|
export declare function hkdf(buffer: Uint8Array | Buffer, expandedLength: number, info: {
|
37
39
|
salt?: Buffer;
|
38
|
-
info?: string
|
40
|
+
info?: string;
|
39
41
|
}): Promise<Buffer>;
|
40
42
|
export declare function derivePairingCodeKey(pairingCode: string, salt: Buffer): Promise<Buffer>;
|