@d0v3riz/baileys 6.3.1 → 6.4.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/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/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 +6 -5
package/lib/Defaults/index.js
CHANGED
|
@@ -49,7 +49,7 @@ exports.DEFAULT_CONNECTION_CONFIG = {
|
|
|
49
49
|
browser: Utils_1.Browsers.baileys('Chrome'),
|
|
50
50
|
waWebSocketUrl: 'wss://web.whatsapp.com/ws/chat',
|
|
51
51
|
connectTimeoutMs: 20000,
|
|
52
|
-
keepAliveIntervalMs:
|
|
52
|
+
keepAliveIntervalMs: 30000,
|
|
53
53
|
logger: logger_1.default.child({ class: 'baileys' }),
|
|
54
54
|
printQRInTerminal: false,
|
|
55
55
|
emitOwnEvents: true,
|
package/lib/Socket/business.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
|
|
|
7
7
|
products: import("../Types").Product[];
|
|
8
8
|
nextPageCursor: string | undefined;
|
|
9
9
|
}>;
|
|
10
|
-
getCollections: (jid?: string
|
|
10
|
+
getCollections: (jid?: string, limit?: number) => Promise<{
|
|
11
11
|
collections: import("../Types").CatalogCollection[];
|
|
12
12
|
}>;
|
|
13
13
|
productCreate: (create: ProductCreate) => Promise<import("../Types").Product>;
|
|
@@ -20,7 +20,7 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
|
|
|
20
20
|
rejectCall: (callId: string, callFrom: string) => Promise<void>;
|
|
21
21
|
getPrivacyTokens: (jids: string[]) => Promise<BinaryNode>;
|
|
22
22
|
assertSessions: (jids: string[], force: boolean) => Promise<boolean>;
|
|
23
|
-
relayMessage: (jid: string, message: import("../Types").WAProto.IMessage, { messageId: msgId, participant, additionalAttributes, useUserDevicesCache, cachedGroupMetadata }: import("../Types").MessageRelayOptions) => Promise<string>;
|
|
23
|
+
relayMessage: (jid: string, message: import("../Types").WAProto.IMessage, { messageId: msgId, participant, additionalAttributes, useUserDevicesCache, cachedGroupMetadata, statusJidList }: import("../Types").MessageRelayOptions) => Promise<string>;
|
|
24
24
|
sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type: import("../Types").MessageReceiptType) => Promise<void>;
|
|
25
25
|
sendReceipts: (keys: import("../Types").WAProto.IMessageKey[], type: import("../Types").MessageReceiptType) => Promise<void>;
|
|
26
26
|
readMessages: (keys: import("../Types").WAProto.IMessageKey[]) => Promise<void>;
|
|
@@ -96,7 +96,7 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
|
|
|
96
96
|
addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
97
97
|
removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
98
98
|
type: "md";
|
|
99
|
-
ws: import("./Client").MobileSocketClient | import("./Client").WebSocketClient;
|
|
99
|
+
ws: import("./Client/mobile-socket-client").MobileSocketClient | import("./Client/web-socket-client").WebSocketClient;
|
|
100
100
|
ev: import("../Types").BaileysEventEmitter & {
|
|
101
101
|
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
|
|
102
102
|
buffer(): void;
|
|
@@ -121,5 +121,6 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
|
|
|
121
121
|
onUnexpectedError: (err: Error | import("@hapi/boom").Boom<any>, msg: string) => void;
|
|
122
122
|
uploadPreKeys: (count?: number) => Promise<void>;
|
|
123
123
|
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
|
124
|
+
requestPairingCode: (phoneNumber: string) => Promise<string>;
|
|
124
125
|
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number | undefined) => Promise<void>;
|
|
125
126
|
};
|
package/lib/Socket/chats.d.ts
CHANGED
|
@@ -12,9 +12,9 @@ export declare const makeChatsSocket: (config: SocketConfig) => {
|
|
|
12
12
|
}>;
|
|
13
13
|
upsertMessage: (msg: proto.IWebMessageInfo, type: MessageUpsertType) => Promise<void>;
|
|
14
14
|
appPatch: (patchCreate: WAPatchCreate) => Promise<void>;
|
|
15
|
-
sendPresenceUpdate: (type: WAPresence, toJid?: string
|
|
16
|
-
presenceSubscribe: (toJid: string, tcToken?: Buffer
|
|
17
|
-
profilePictureUrl: (jid: string, type?: 'preview' | 'image', timeoutMs?: number
|
|
15
|
+
sendPresenceUpdate: (type: WAPresence, toJid?: string) => Promise<void>;
|
|
16
|
+
presenceSubscribe: (toJid: string, tcToken?: Buffer) => Promise<void>;
|
|
17
|
+
profilePictureUrl: (jid: string, type?: 'preview' | 'image', timeoutMs?: number) => Promise<string | undefined>;
|
|
18
18
|
onWhatsApp: (...jids: string[]) => Promise<{
|
|
19
19
|
exists: boolean;
|
|
20
20
|
jid: string;
|
|
@@ -39,13 +39,13 @@ export declare const makeChatsSocket: (config: SocketConfig) => {
|
|
|
39
39
|
getBusinessProfile: (jid: string) => Promise<WABusinessProfile | void>;
|
|
40
40
|
resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>;
|
|
41
41
|
chatModify: (mod: ChatModification, jid: string) => Promise<void>;
|
|
42
|
-
cleanDirtyBits: (type: 'account_sync' | 'groups', fromTimestamp?:
|
|
42
|
+
cleanDirtyBits: (type: 'account_sync' | 'groups', fromTimestamp?: number | string) => Promise<void>;
|
|
43
43
|
addChatLabel: (jid: string, labelId: string) => Promise<void>;
|
|
44
44
|
removeChatLabel: (jid: string, labelId: string) => Promise<void>;
|
|
45
45
|
addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
46
46
|
removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
47
47
|
type: "md";
|
|
48
|
-
ws: import("./Client").MobileSocketClient | import("./Client").WebSocketClient;
|
|
48
|
+
ws: import("./Client/mobile-socket-client").MobileSocketClient | import("./Client/web-socket-client").WebSocketClient;
|
|
49
49
|
ev: import("../Types").BaileysEventEmitter & {
|
|
50
50
|
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
|
|
51
51
|
buffer(): void;
|
|
@@ -70,5 +70,6 @@ export declare const makeChatsSocket: (config: SocketConfig) => {
|
|
|
70
70
|
onUnexpectedError: (err: Error | Boom<any>, msg: string) => void;
|
|
71
71
|
uploadPreKeys: (count?: number) => Promise<void>;
|
|
72
72
|
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
|
73
|
+
requestPairingCode: (phoneNumber: string) => Promise<string>;
|
|
73
74
|
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number | undefined) => Promise<void>;
|
|
74
75
|
};
|
package/lib/Socket/groups.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export declare const makeGroupsSocket: (config: SocketConfig) => {
|
|
|
19
19
|
jid: string;
|
|
20
20
|
content: BinaryNode;
|
|
21
21
|
}[]>;
|
|
22
|
-
groupUpdateDescription: (jid: string, description?: string
|
|
22
|
+
groupUpdateDescription: (jid: string, description?: string) => Promise<void>;
|
|
23
23
|
groupInviteCode: (jid: string) => Promise<string | undefined>;
|
|
24
24
|
groupRevokeInvite: (jid: string) => Promise<string | undefined>;
|
|
25
25
|
groupAcceptInvite: (code: string) => Promise<string | undefined>;
|
|
@@ -76,7 +76,7 @@ export declare const makeGroupsSocket: (config: SocketConfig) => {
|
|
|
76
76
|
addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
77
77
|
removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
78
78
|
type: "md";
|
|
79
|
-
ws: import("./Client").MobileSocketClient | import("./Client").WebSocketClient;
|
|
79
|
+
ws: import("./Client/mobile-socket-client").MobileSocketClient | import("./Client/web-socket-client").WebSocketClient;
|
|
80
80
|
ev: import("../Types").BaileysEventEmitter & {
|
|
81
81
|
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
|
|
82
82
|
buffer(): void;
|
|
@@ -101,6 +101,7 @@ export declare const makeGroupsSocket: (config: SocketConfig) => {
|
|
|
101
101
|
onUnexpectedError: (err: Error | import("@hapi/boom").Boom<any>, msg: string) => void;
|
|
102
102
|
uploadPreKeys: (count?: number) => Promise<void>;
|
|
103
103
|
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
|
104
|
+
requestPairingCode: (phoneNumber: string) => Promise<string>;
|
|
104
105
|
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number | undefined) => Promise<void>;
|
|
105
106
|
};
|
|
106
107
|
export declare const extractGroupMetadata: (result: BinaryNode) => GroupMetadata;
|
package/lib/Socket/index.d.ts
CHANGED
|
@@ -16,12 +16,12 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
|
|
|
16
16
|
deleted: number;
|
|
17
17
|
}>;
|
|
18
18
|
productUpdate: (productId: string, update: import("../Types").ProductUpdate) => Promise<import("../Types").Product>;
|
|
19
|
-
sendMessageAck: ({ tag, attrs }: import("
|
|
20
|
-
sendRetryRequest: (node: import("
|
|
19
|
+
sendMessageAck: ({ tag, attrs }: import("../index").BinaryNode) => Promise<void>;
|
|
20
|
+
sendRetryRequest: (node: import("../index").BinaryNode, forceIncludeKeys?: boolean) => Promise<void>;
|
|
21
21
|
rejectCall: (callId: string, callFrom: string) => Promise<void>;
|
|
22
|
-
getPrivacyTokens: (jids: string[]) => Promise<import("
|
|
22
|
+
getPrivacyTokens: (jids: string[]) => Promise<import("../index").BinaryNode>;
|
|
23
23
|
assertSessions: (jids: string[], force: boolean) => Promise<boolean>;
|
|
24
|
-
relayMessage: (jid: string, message: import("../Types").WAProto.IMessage, { messageId: msgId, participant, additionalAttributes, useUserDevicesCache, cachedGroupMetadata }: import("../Types").MessageRelayOptions) => Promise<string>;
|
|
24
|
+
relayMessage: (jid: string, message: import("../Types").WAProto.IMessage, { messageId: msgId, participant, additionalAttributes, useUserDevicesCache, cachedGroupMetadata, statusJidList }: import("../Types").MessageRelayOptions) => Promise<string>;
|
|
25
25
|
sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type: import("../Types").MessageReceiptType) => Promise<void>;
|
|
26
26
|
sendReceipts: (keys: import("../Types").WAProto.IMessageKey[], type: import("../Types").MessageReceiptType) => Promise<void>;
|
|
27
27
|
readMessages: (keys: import("../Types").WAProto.IMessageKey[]) => Promise<void>;
|
|
@@ -46,7 +46,7 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
|
|
|
46
46
|
groupParticipantsUpdate: (jid: string, participants: string[], action: import("../Types").ParticipantAction) => Promise<{
|
|
47
47
|
status: string;
|
|
48
48
|
jid: string;
|
|
49
|
-
content: import("
|
|
49
|
+
content: import("../index").BinaryNode;
|
|
50
50
|
}[]>;
|
|
51
51
|
groupUpdateDescription: (jid: string, description?: string | undefined) => Promise<void>;
|
|
52
52
|
groupInviteCode: (jid: string) => Promise<string | undefined>;
|
|
@@ -97,7 +97,7 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
|
|
|
97
97
|
addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
98
98
|
removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
99
99
|
type: "md";
|
|
100
|
-
ws: import("./Client").MobileSocketClient | import("./Client").WebSocketClient;
|
|
100
|
+
ws: import("./Client/mobile-socket-client").MobileSocketClient | import("./Client/web-socket-client").WebSocketClient;
|
|
101
101
|
ev: import("../Types").BaileysEventEmitter & {
|
|
102
102
|
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
|
|
103
103
|
buffer(): void;
|
|
@@ -112,16 +112,17 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
|
|
|
112
112
|
signalRepository: import("../Types").SignalRepository;
|
|
113
113
|
user: import("../Types").Contact | undefined;
|
|
114
114
|
generateMessageTag: () => string;
|
|
115
|
-
query: (node: import("
|
|
115
|
+
query: (node: import("../index").BinaryNode, timeoutMs?: number | undefined) => Promise<import("../index").BinaryNode>;
|
|
116
116
|
waitForMessage: <T_2>(msgId: string, timeoutMs?: number | undefined) => Promise<T_2>;
|
|
117
117
|
waitForSocketOpen: () => Promise<void>;
|
|
118
118
|
sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
|
|
119
|
-
sendNode: (frame: import("
|
|
119
|
+
sendNode: (frame: import("../index").BinaryNode) => Promise<void>;
|
|
120
120
|
logout: (msg?: string | undefined) => Promise<void>;
|
|
121
121
|
end: (error: Error | undefined) => void;
|
|
122
122
|
onUnexpectedError: (err: Error | import("@hapi/boom").Boom<any>, msg: string) => void;
|
|
123
123
|
uploadPreKeys: (count?: number) => Promise<void>;
|
|
124
124
|
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
|
125
|
+
requestPairingCode: (phoneNumber: string) => Promise<string>;
|
|
125
126
|
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number | undefined) => Promise<void>;
|
|
126
127
|
};
|
|
127
128
|
export default makeWASocket;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
import { Boom } from '@hapi/boom';
|
|
2
3
|
import { proto } from '../../WAProto';
|
|
3
4
|
import { MessageReceiptType, MessageRelayOptions, SocketConfig } from '../Types';
|
|
4
5
|
import { BinaryNode } from '../WABinary';
|
|
@@ -8,7 +9,7 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
|
|
|
8
9
|
rejectCall: (callId: string, callFrom: string) => Promise<void>;
|
|
9
10
|
getPrivacyTokens: (jids: string[]) => Promise<BinaryNode>;
|
|
10
11
|
assertSessions: (jids: string[], force: boolean) => Promise<boolean>;
|
|
11
|
-
relayMessage: (jid: string, message: proto.IMessage, { messageId: msgId, participant, additionalAttributes, useUserDevicesCache, cachedGroupMetadata }: MessageRelayOptions) => Promise<string>;
|
|
12
|
+
relayMessage: (jid: string, message: proto.IMessage, { messageId: msgId, participant, additionalAttributes, useUserDevicesCache, cachedGroupMetadata, statusJidList }: MessageRelayOptions) => Promise<string>;
|
|
12
13
|
sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type: MessageReceiptType) => Promise<void>;
|
|
13
14
|
sendReceipts: (keys: proto.IMessageKey[], type: MessageReceiptType) => Promise<void>;
|
|
14
15
|
readMessages: (keys: proto.IMessageKey[]) => Promise<void>;
|
|
@@ -84,7 +85,7 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
|
|
|
84
85
|
addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
85
86
|
removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
86
87
|
type: "md";
|
|
87
|
-
ws: import("./Client").MobileSocketClient | import("./Client").WebSocketClient;
|
|
88
|
+
ws: import("./Client/mobile-socket-client").MobileSocketClient | import("./Client/web-socket-client").WebSocketClient;
|
|
88
89
|
ev: import("../Types").BaileysEventEmitter & {
|
|
89
90
|
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
|
|
90
91
|
buffer(): void;
|
|
@@ -106,8 +107,9 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
|
|
|
106
107
|
sendNode: (frame: BinaryNode) => Promise<void>;
|
|
107
108
|
logout: (msg?: string | undefined) => Promise<void>;
|
|
108
109
|
end: (error: Error | undefined) => void;
|
|
109
|
-
onUnexpectedError: (err: Error |
|
|
110
|
+
onUnexpectedError: (err: Error | Boom<any>, msg: string) => void;
|
|
110
111
|
uploadPreKeys: (count?: number) => Promise<void>;
|
|
111
112
|
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
|
113
|
+
requestPairingCode: (phoneNumber: string) => Promise<string>;
|
|
112
114
|
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number | undefined) => Promise<void>;
|
|
113
115
|
};
|
|
@@ -4,13 +4,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.makeMessagesRecvSocket = void 0;
|
|
7
|
+
const boom_1 = require("@hapi/boom");
|
|
8
|
+
const crypto_1 = require("crypto");
|
|
7
9
|
const node_cache_1 = __importDefault(require("node-cache"));
|
|
8
10
|
const WAProto_1 = require("../../WAProto");
|
|
9
11
|
const Defaults_1 = require("../Defaults");
|
|
10
12
|
const Types_1 = require("../Types");
|
|
11
13
|
const Utils_1 = require("../Utils");
|
|
14
|
+
const Utils_2 = require("../Utils");
|
|
12
15
|
const make_mutex_1 = require("../Utils/make-mutex");
|
|
13
|
-
const process_message_1 = require("../Utils/process-message");
|
|
14
16
|
const WABinary_1 = require("../WABinary");
|
|
15
17
|
const groups_1 = require("./groups");
|
|
16
18
|
const messages_send_1 = require("./messages-send");
|
|
@@ -299,11 +301,82 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
299
301
|
});
|
|
300
302
|
}
|
|
301
303
|
break;
|
|
304
|
+
case 'link_code_companion_reg':
|
|
305
|
+
const linkCodeCompanionReg = (0, WABinary_1.getBinaryNodeChild)(node, 'link_code_companion_reg');
|
|
306
|
+
const ref = toRequiredBuffer((0, WABinary_1.getBinaryNodeChildBuffer)(linkCodeCompanionReg, 'link_code_pairing_ref'));
|
|
307
|
+
const primaryIdentityPublicKey = toRequiredBuffer((0, WABinary_1.getBinaryNodeChildBuffer)(linkCodeCompanionReg, 'primary_identity_pub'));
|
|
308
|
+
const primaryEphemeralPublicKeyWrapped = toRequiredBuffer((0, WABinary_1.getBinaryNodeChildBuffer)(linkCodeCompanionReg, 'link_code_pairing_wrapped_primary_ephemeral_pub'));
|
|
309
|
+
const codePairingPublicKey = decipherLinkPublicKey(primaryEphemeralPublicKeyWrapped);
|
|
310
|
+
const companionSharedKey = Utils_1.Curve.sharedKey(authState.creds.pairingEphemeralKeyPair.private, codePairingPublicKey);
|
|
311
|
+
const random = (0, crypto_1.randomBytes)(32);
|
|
312
|
+
const linkCodeSalt = (0, crypto_1.randomBytes)(32);
|
|
313
|
+
const linkCodePairingExpanded = (0, Utils_1.hkdf)(companionSharedKey, 32, {
|
|
314
|
+
salt: linkCodeSalt,
|
|
315
|
+
info: 'link_code_pairing_key_bundle_encryption_key'
|
|
316
|
+
});
|
|
317
|
+
const encryptPayload = Buffer.concat([Buffer.from(authState.creds.signedIdentityKey.public), primaryIdentityPublicKey, random]);
|
|
318
|
+
const encryptIv = (0, crypto_1.randomBytes)(12);
|
|
319
|
+
const encrypted = (0, Utils_1.aesEncryptGCM)(encryptPayload, linkCodePairingExpanded, encryptIv, Buffer.alloc(0));
|
|
320
|
+
const encryptedPayload = Buffer.concat([linkCodeSalt, encryptIv, encrypted]);
|
|
321
|
+
const identitySharedKey = Utils_1.Curve.sharedKey(authState.creds.signedIdentityKey.private, primaryIdentityPublicKey);
|
|
322
|
+
const identityPayload = Buffer.concat([companionSharedKey, identitySharedKey, random]);
|
|
323
|
+
authState.creds.advSecretKey = (0, Utils_1.hkdf)(identityPayload, 32, { info: 'adv_secret' }).toString('base64');
|
|
324
|
+
await query({
|
|
325
|
+
tag: 'iq',
|
|
326
|
+
attrs: {
|
|
327
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
328
|
+
type: 'set',
|
|
329
|
+
id: sock.generateMessageTag(),
|
|
330
|
+
xmlns: 'md'
|
|
331
|
+
},
|
|
332
|
+
content: [
|
|
333
|
+
{
|
|
334
|
+
tag: 'link_code_companion_reg',
|
|
335
|
+
attrs: {
|
|
336
|
+
jid: authState.creds.me.id,
|
|
337
|
+
stage: 'companion_finish',
|
|
338
|
+
},
|
|
339
|
+
content: [
|
|
340
|
+
{
|
|
341
|
+
tag: 'link_code_pairing_wrapped_key_bundle',
|
|
342
|
+
attrs: {},
|
|
343
|
+
content: encryptedPayload
|
|
344
|
+
},
|
|
345
|
+
{
|
|
346
|
+
tag: 'companion_identity_public',
|
|
347
|
+
attrs: {},
|
|
348
|
+
content: authState.creds.signedIdentityKey.public
|
|
349
|
+
},
|
|
350
|
+
{
|
|
351
|
+
tag: 'link_code_pairing_ref',
|
|
352
|
+
attrs: {},
|
|
353
|
+
content: ref
|
|
354
|
+
}
|
|
355
|
+
]
|
|
356
|
+
}
|
|
357
|
+
]
|
|
358
|
+
});
|
|
359
|
+
authState.creds.registered = true;
|
|
360
|
+
ev.emit('creds.update', authState.creds);
|
|
302
361
|
}
|
|
303
362
|
if (Object.keys(result).length) {
|
|
304
363
|
return result;
|
|
305
364
|
}
|
|
306
365
|
};
|
|
366
|
+
function decipherLinkPublicKey(data) {
|
|
367
|
+
const buffer = toRequiredBuffer(data);
|
|
368
|
+
const salt = buffer.slice(0, 32);
|
|
369
|
+
const secretKey = (0, Utils_1.derivePairingCodeKey)(authState.creds.pairingCode, salt);
|
|
370
|
+
const iv = buffer.slice(32, 48);
|
|
371
|
+
const payload = buffer.slice(48, 80);
|
|
372
|
+
return (0, Utils_1.aesDecryptCTR)(payload, secretKey, iv);
|
|
373
|
+
}
|
|
374
|
+
function toRequiredBuffer(data) {
|
|
375
|
+
if (data === undefined) {
|
|
376
|
+
throw new boom_1.Boom('Invalid buffer', { statusCode: 400 });
|
|
377
|
+
}
|
|
378
|
+
return data instanceof Buffer ? data : Buffer.from(data);
|
|
379
|
+
}
|
|
307
380
|
const willSendMessageAgain = (id, participant) => {
|
|
308
381
|
const key = `${id}:${participant}`;
|
|
309
382
|
const retryCount = msgRetryCache.get(key) || 0;
|
|
@@ -504,7 +577,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
504
577
|
await sendReceipt(jid, undefined, [msg.key.id], 'hist_sync');
|
|
505
578
|
}
|
|
506
579
|
}
|
|
507
|
-
(0,
|
|
580
|
+
(0, Utils_2.cleanMessage)(msg, authState.creds.me.id);
|
|
508
581
|
await upsertMessage(msg, node.attrs.offline ? 'append' : 'notify');
|
|
509
582
|
}),
|
|
510
583
|
sendMessageAck(node)
|
|
@@ -6,7 +6,7 @@ import { BinaryNode } from '../WABinary';
|
|
|
6
6
|
export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
7
7
|
getPrivacyTokens: (jids: string[]) => Promise<BinaryNode>;
|
|
8
8
|
assertSessions: (jids: string[], force: boolean) => Promise<boolean>;
|
|
9
|
-
relayMessage: (jid: string, message: proto.IMessage, { messageId: msgId, participant, additionalAttributes, useUserDevicesCache, cachedGroupMetadata }: MessageRelayOptions) => Promise<string>;
|
|
9
|
+
relayMessage: (jid: string, message: proto.IMessage, { messageId: msgId, participant, additionalAttributes, useUserDevicesCache, cachedGroupMetadata, statusJidList }: MessageRelayOptions) => Promise<string>;
|
|
10
10
|
sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type: MessageReceiptType) => Promise<void>;
|
|
11
11
|
sendReceipts: (keys: WAMessageKey[], type: MessageReceiptType) => Promise<void>;
|
|
12
12
|
readMessages: (keys: WAMessageKey[]) => Promise<void>;
|
|
@@ -82,7 +82,7 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
|
82
82
|
addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
83
83
|
removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
84
84
|
type: "md";
|
|
85
|
-
ws: import("./Client").MobileSocketClient | import("./Client").WebSocketClient;
|
|
85
|
+
ws: import("./Client/mobile-socket-client").MobileSocketClient | import("./Client/web-socket-client").WebSocketClient;
|
|
86
86
|
ev: import("../Types").BaileysEventEmitter & {
|
|
87
87
|
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
|
|
88
88
|
buffer(): void;
|
|
@@ -107,5 +107,6 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
|
107
107
|
onUnexpectedError: (err: Error | Boom<any>, msg: string) => void;
|
|
108
108
|
uploadPreKeys: (count?: number) => Promise<void>;
|
|
109
109
|
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
|
110
|
+
requestPairingCode: (phoneNumber: string) => Promise<string>;
|
|
110
111
|
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number | undefined) => Promise<void>;
|
|
111
112
|
};
|
|
@@ -246,15 +246,17 @@ const makeMessagesSocket = (config) => {
|
|
|
246
246
|
}));
|
|
247
247
|
return { nodes, shouldIncludeDeviceIdentity };
|
|
248
248
|
};
|
|
249
|
-
const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, useUserDevicesCache, cachedGroupMetadata }) => {
|
|
249
|
+
const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, useUserDevicesCache, cachedGroupMetadata, statusJidList }) => {
|
|
250
250
|
const meId = authState.creds.me.id;
|
|
251
251
|
let shouldIncludeDeviceIdentity = false;
|
|
252
252
|
const { user, server } = (0, WABinary_1.jidDecode)(jid);
|
|
253
|
+
const statusJid = 'status@broadcast';
|
|
253
254
|
const isGroup = server === 'g.us';
|
|
255
|
+
const isStatus = jid === statusJid;
|
|
254
256
|
msgId = msgId || (0, Utils_1.generateMessageID)();
|
|
255
257
|
useUserDevicesCache = useUserDevicesCache !== false;
|
|
256
258
|
const participants = [];
|
|
257
|
-
const destinationJid = (0, WABinary_1.jidEncode)(user, isGroup ? 'g.us' : 's.whatsapp.net');
|
|
259
|
+
const destinationJid = (!isStatus) ? (0, WABinary_1.jidEncode)(user, isGroup ? 'g.us' : 's.whatsapp.net') : statusJid;
|
|
258
260
|
const binaryNodeContent = [];
|
|
259
261
|
const devices = [];
|
|
260
262
|
const meMsg = {
|
|
@@ -267,7 +269,7 @@ const makeMessagesSocket = (config) => {
|
|
|
267
269
|
// when the retry request is not for a group
|
|
268
270
|
// only send to the specific device that asked for a retry
|
|
269
271
|
// otherwise the message is sent out to every device that should be a recipient
|
|
270
|
-
if (!isGroup) {
|
|
272
|
+
if (!isGroup && !isStatus) {
|
|
271
273
|
additionalAttributes = { ...additionalAttributes, 'device_fanout': 'false' };
|
|
272
274
|
}
|
|
273
275
|
const { user, device } = (0, WABinary_1.jidDecode)(participant.jid);
|
|
@@ -275,20 +277,20 @@ const makeMessagesSocket = (config) => {
|
|
|
275
277
|
}
|
|
276
278
|
await authState.keys.transaction(async () => {
|
|
277
279
|
const mediaType = getMediaType(message);
|
|
278
|
-
if (isGroup) {
|
|
280
|
+
if (isGroup || isStatus) {
|
|
279
281
|
const [groupData, senderKeyMap] = await Promise.all([
|
|
280
282
|
(async () => {
|
|
281
283
|
let groupData = cachedGroupMetadata ? await cachedGroupMetadata(jid) : undefined;
|
|
282
284
|
if (groupData) {
|
|
283
285
|
logger.trace({ jid, participants: groupData.participants.length }, 'using cached group metadata');
|
|
284
286
|
}
|
|
285
|
-
if (!groupData) {
|
|
287
|
+
if (!groupData && !isStatus) {
|
|
286
288
|
groupData = await groupMetadata(jid);
|
|
287
289
|
}
|
|
288
290
|
return groupData;
|
|
289
291
|
})(),
|
|
290
292
|
(async () => {
|
|
291
|
-
if (!participant) {
|
|
293
|
+
if (!participant && !isStatus) {
|
|
292
294
|
const result = await authState.keys.get('sender-key-memory', [jid]);
|
|
293
295
|
return result[jid] || {};
|
|
294
296
|
}
|
|
@@ -296,7 +298,10 @@ const makeMessagesSocket = (config) => {
|
|
|
296
298
|
})()
|
|
297
299
|
]);
|
|
298
300
|
if (!participant) {
|
|
299
|
-
const participantsList = groupData.participants.map(p => p.id);
|
|
301
|
+
const participantsList = (groupData && !isStatus) ? groupData.participants.map(p => p.id) : [];
|
|
302
|
+
if (isStatus && statusJidList) {
|
|
303
|
+
participantsList.push(...statusJidList);
|
|
304
|
+
}
|
|
300
305
|
const additionalDevices = await getUSyncDevices(participantsList, !!useUserDevicesCache, false);
|
|
301
306
|
devices.push(...additionalDevices);
|
|
302
307
|
}
|
|
@@ -638,7 +643,7 @@ const makeMessagesSocket = (config) => {
|
|
|
638
643
|
else if (isEditMsg) {
|
|
639
644
|
additionalAttributes.edit = '1';
|
|
640
645
|
}
|
|
641
|
-
await relayMessage(jid, fullMsg.message, { messageId: fullMsg.key.id, cachedGroupMetadata: options.cachedGroupMetadata, additionalAttributes });
|
|
646
|
+
await relayMessage(jid, fullMsg.message, { messageId: fullMsg.key.id, cachedGroupMetadata: options.cachedGroupMetadata, additionalAttributes, statusJidList: options.statusJidList });
|
|
642
647
|
if (config.emitOwnEvents) {
|
|
643
648
|
process.nextTick(() => {
|
|
644
649
|
processingMutex.mutex(() => (upsertMessage(fullMsg, 'append')));
|
|
@@ -3,7 +3,7 @@ import { AxiosRequestConfig } from 'axios';
|
|
|
3
3
|
import { KeyPair, SignedKeyPair, SocketConfig } from '../Types';
|
|
4
4
|
export declare const makeRegistrationSocket: (config: SocketConfig) => {
|
|
5
5
|
register: (code: string) => Promise<ExistsResponse>;
|
|
6
|
-
requestRegistrationCode: (registrationOptions?: RegistrationOptions
|
|
6
|
+
requestRegistrationCode: (registrationOptions?: RegistrationOptions) => Promise<ExistsResponse>;
|
|
7
7
|
getOrderDetails: (orderId: string, tokenBase64: string) => Promise<import("../Types").OrderDetails>;
|
|
8
8
|
getCatalog: ({ jid, limit, cursor }: import("../Types").GetCatalogOptions) => Promise<{
|
|
9
9
|
products: import("../Types").Product[];
|
|
@@ -22,7 +22,7 @@ export declare const makeRegistrationSocket: (config: SocketConfig) => {
|
|
|
22
22
|
rejectCall: (callId: string, callFrom: string) => Promise<void>;
|
|
23
23
|
getPrivacyTokens: (jids: string[]) => Promise<import("../WABinary").BinaryNode>;
|
|
24
24
|
assertSessions: (jids: string[], force: boolean) => Promise<boolean>;
|
|
25
|
-
relayMessage: (jid: string, message: import("../Types").WAProto.IMessage, { messageId: msgId, participant, additionalAttributes, useUserDevicesCache, cachedGroupMetadata }: import("../Types").MessageRelayOptions) => Promise<string>;
|
|
25
|
+
relayMessage: (jid: string, message: import("../Types").WAProto.IMessage, { messageId: msgId, participant, additionalAttributes, useUserDevicesCache, cachedGroupMetadata, statusJidList }: import("../Types").MessageRelayOptions) => Promise<string>;
|
|
26
26
|
sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type: import("../Types").MessageReceiptType) => Promise<void>;
|
|
27
27
|
sendReceipts: (keys: import("../Types").WAProto.IMessageKey[], type: import("../Types").MessageReceiptType) => Promise<void>;
|
|
28
28
|
readMessages: (keys: import("../Types").WAProto.IMessageKey[]) => Promise<void>;
|
|
@@ -98,7 +98,7 @@ export declare const makeRegistrationSocket: (config: SocketConfig) => {
|
|
|
98
98
|
addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
99
99
|
removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
100
100
|
type: "md";
|
|
101
|
-
ws: import("./Client").MobileSocketClient | import("./Client").WebSocketClient;
|
|
101
|
+
ws: import("./Client/mobile-socket-client").MobileSocketClient | import("./Client/web-socket-client").WebSocketClient;
|
|
102
102
|
ev: import("../Types").BaileysEventEmitter & {
|
|
103
103
|
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
|
|
104
104
|
buffer(): void;
|
|
@@ -123,6 +123,7 @@ export declare const makeRegistrationSocket: (config: SocketConfig) => {
|
|
|
123
123
|
onUnexpectedError: (err: Error | import("@hapi/boom").Boom<any>, msg: string) => void;
|
|
124
124
|
uploadPreKeys: (count?: number) => Promise<void>;
|
|
125
125
|
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
|
126
|
+
requestPairingCode: (phoneNumber: string) => Promise<string>;
|
|
126
127
|
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number | undefined) => Promise<void>;
|
|
127
128
|
};
|
|
128
129
|
export interface RegistrationData {
|
|
@@ -155,7 +156,7 @@ export interface RegistrationOptions {
|
|
|
155
156
|
*/
|
|
156
157
|
method?: 'sms' | 'voice';
|
|
157
158
|
}
|
|
158
|
-
export
|
|
159
|
+
export type RegistrationParams = RegistrationData & RegistrationOptions;
|
|
159
160
|
export declare function registrationParams(params: RegistrationParams): {
|
|
160
161
|
cc: string;
|
|
161
162
|
in: string;
|
package/lib/Socket/socket.d.ts
CHANGED
|
@@ -26,17 +26,18 @@ export declare const makeSocket: (config: SocketConfig) => {
|
|
|
26
26
|
signalRepository: import("../Types").SignalRepository;
|
|
27
27
|
readonly user: import("../Types").Contact | undefined;
|
|
28
28
|
generateMessageTag: () => string;
|
|
29
|
-
query: (node: BinaryNode, timeoutMs?: number
|
|
29
|
+
query: (node: BinaryNode, timeoutMs?: number) => Promise<BinaryNode>;
|
|
30
30
|
waitForMessage: <T_1>(msgId: string, timeoutMs?: number | undefined) => Promise<T_1>;
|
|
31
31
|
waitForSocketOpen: () => Promise<void>;
|
|
32
32
|
sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
|
|
33
33
|
sendNode: (frame: BinaryNode) => Promise<void>;
|
|
34
|
-
logout: (msg?: string
|
|
34
|
+
logout: (msg?: string) => Promise<void>;
|
|
35
35
|
end: (error: Error | undefined) => void;
|
|
36
36
|
onUnexpectedError: (err: Error | Boom, msg: string) => void;
|
|
37
37
|
uploadPreKeys: (count?: number) => Promise<void>;
|
|
38
38
|
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
|
39
|
+
requestPairingCode: (phoneNumber: string) => Promise<string>;
|
|
39
40
|
/** Waits for the connection to WA to reach a state */
|
|
40
41
|
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number | undefined) => Promise<void>;
|
|
41
42
|
};
|
|
42
|
-
export
|
|
43
|
+
export type Socket = ReturnType<typeof makeSocket>;
|
package/lib/Socket/socket.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.makeSocket = void 0;
|
|
4
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
5
4
|
const boom_1 = require("@hapi/boom");
|
|
5
|
+
const crypto_1 = require("crypto");
|
|
6
6
|
const url_1 = require("url");
|
|
7
7
|
const util_1 = require("util");
|
|
8
8
|
const WAProto_1 = require("../../WAProto");
|
|
9
9
|
const Defaults_1 = require("../Defaults");
|
|
10
10
|
const Types_1 = require("../Types");
|
|
11
11
|
const Utils_1 = require("../Utils");
|
|
12
|
-
const event_buffer_1 = require("../Utils/event-buffer");
|
|
13
12
|
const WABinary_1 = require("../WABinary");
|
|
14
13
|
const Client_1 = require("./Client");
|
|
15
14
|
/**
|
|
@@ -19,16 +18,15 @@ const Client_1 = require("./Client");
|
|
|
19
18
|
* - query phone connection
|
|
20
19
|
*/
|
|
21
20
|
const makeSocket = (config) => {
|
|
22
|
-
var _a, _b;
|
|
23
21
|
const { waWebSocketUrl, connectTimeoutMs, logger, keepAliveIntervalMs, browser, auth: authState, printQRInTerminal, defaultQueryTimeoutMs, transactionOpts, qrTimeout, makeSignalRepository, } = config;
|
|
24
22
|
let url = typeof waWebSocketUrl === 'string' ? new url_1.URL(waWebSocketUrl) : waWebSocketUrl;
|
|
25
|
-
config.mobile = config.mobile ||
|
|
23
|
+
config.mobile = config.mobile || url.protocol === 'tcp:';
|
|
26
24
|
if (config.mobile && url.protocol !== 'tcp:') {
|
|
27
25
|
url = new url_1.URL(`tcp://${Defaults_1.MOBILE_ENDPOINT}:${Defaults_1.MOBILE_PORT}`);
|
|
28
26
|
}
|
|
29
27
|
const ws = config.mobile ? new Client_1.MobileSocketClient(url, config) : new Client_1.WebSocketClient(url, config);
|
|
30
28
|
ws.connect();
|
|
31
|
-
const ev = (0,
|
|
29
|
+
const ev = (0, Utils_1.makeEventBuffer)(logger);
|
|
32
30
|
/** ephemeral key pair used to encrypt/decrypt communication. Unique for each connection */
|
|
33
31
|
const ephemeralKeyPair = Utils_1.Curve.generateKeyPair();
|
|
34
32
|
/** WA noise protocol wrapper */
|
|
@@ -106,15 +104,14 @@ const makeSocket = (config) => {
|
|
|
106
104
|
};
|
|
107
105
|
/**
|
|
108
106
|
* Wait for a message with a certain tag to be received
|
|
109
|
-
* @param
|
|
110
|
-
* @param json query that was sent
|
|
107
|
+
* @param msgId the message tag to await
|
|
111
108
|
* @param timeoutMs timeout after which the promise will reject
|
|
112
109
|
*/
|
|
113
110
|
const waitForMessage = async (msgId, timeoutMs = defaultQueryTimeoutMs) => {
|
|
114
111
|
let onRecv;
|
|
115
112
|
let onErr;
|
|
116
113
|
try {
|
|
117
|
-
|
|
114
|
+
return await (0, Utils_1.promiseTimeout)(timeoutMs, (resolve, reject) => {
|
|
118
115
|
onRecv = resolve;
|
|
119
116
|
onErr = err => {
|
|
120
117
|
reject(err || new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed }));
|
|
@@ -123,7 +120,6 @@ const makeSocket = (config) => {
|
|
|
123
120
|
ws.on('close', onErr); // if the socket closes, you'll never receive the message
|
|
124
121
|
ws.off('error', onErr);
|
|
125
122
|
});
|
|
126
|
-
return result;
|
|
127
123
|
}
|
|
128
124
|
finally {
|
|
129
125
|
ws.off(`TAG:${msgId}`, onRecv);
|
|
@@ -364,6 +360,69 @@ const makeSocket = (config) => {
|
|
|
364
360
|
}
|
|
365
361
|
end(new boom_1.Boom(msg || 'Intentional Logout', { statusCode: Types_1.DisconnectReason.loggedOut }));
|
|
366
362
|
};
|
|
363
|
+
const requestPairingCode = async (phoneNumber) => {
|
|
364
|
+
authState.creds.pairingCode = (0, Utils_1.bytesToCrockford)((0, crypto_1.randomBytes)(5));
|
|
365
|
+
authState.creds.me = {
|
|
366
|
+
id: (0, WABinary_1.jidEncode)(phoneNumber, 's.whatsapp.net'),
|
|
367
|
+
name: '~'
|
|
368
|
+
};
|
|
369
|
+
ev.emit('creds.update', authState.creds);
|
|
370
|
+
await sendNode({
|
|
371
|
+
tag: 'iq',
|
|
372
|
+
attrs: {
|
|
373
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
374
|
+
type: 'set',
|
|
375
|
+
id: generateMessageTag(),
|
|
376
|
+
xmlns: 'md'
|
|
377
|
+
},
|
|
378
|
+
content: [
|
|
379
|
+
{
|
|
380
|
+
tag: 'link_code_companion_reg',
|
|
381
|
+
attrs: {
|
|
382
|
+
jid: authState.creds.me.id,
|
|
383
|
+
stage: 'companion_hello',
|
|
384
|
+
// eslint-disable-next-line camelcase
|
|
385
|
+
should_show_push_notification: 'true'
|
|
386
|
+
},
|
|
387
|
+
content: [
|
|
388
|
+
{
|
|
389
|
+
tag: 'link_code_pairing_wrapped_companion_ephemeral_pub',
|
|
390
|
+
attrs: {},
|
|
391
|
+
content: await generatePairingKey()
|
|
392
|
+
},
|
|
393
|
+
{
|
|
394
|
+
tag: 'companion_server_auth_key_pub',
|
|
395
|
+
attrs: {},
|
|
396
|
+
content: authState.creds.noiseKey.public
|
|
397
|
+
},
|
|
398
|
+
{
|
|
399
|
+
tag: 'companion_platform_id',
|
|
400
|
+
attrs: {},
|
|
401
|
+
content: '49' // Chrome
|
|
402
|
+
},
|
|
403
|
+
{
|
|
404
|
+
tag: 'companion_platform_display',
|
|
405
|
+
attrs: {},
|
|
406
|
+
content: config.browser[0]
|
|
407
|
+
},
|
|
408
|
+
{
|
|
409
|
+
tag: 'link_code_pairing_nonce',
|
|
410
|
+
attrs: {},
|
|
411
|
+
content: '0'
|
|
412
|
+
}
|
|
413
|
+
]
|
|
414
|
+
}
|
|
415
|
+
]
|
|
416
|
+
});
|
|
417
|
+
return authState.creds.pairingCode;
|
|
418
|
+
};
|
|
419
|
+
async function generatePairingKey() {
|
|
420
|
+
const salt = (0, crypto_1.randomBytes)(32);
|
|
421
|
+
const randomIv = (0, crypto_1.randomBytes)(16);
|
|
422
|
+
const key = (0, Utils_1.derivePairingCodeKey)(authState.creds.pairingCode, salt);
|
|
423
|
+
const ciphered = (0, Utils_1.aesEncryptCTR)(authState.creds.pairingEphemeralKeyPair.public, key, randomIv);
|
|
424
|
+
return Buffer.concat([salt, randomIv, ciphered]);
|
|
425
|
+
}
|
|
367
426
|
ws.on('message', onMessageRecieved);
|
|
368
427
|
ws.on('open', async () => {
|
|
369
428
|
try {
|
|
@@ -511,6 +570,7 @@ const makeSocket = (config) => {
|
|
|
511
570
|
onUnexpectedError,
|
|
512
571
|
uploadPreKeys,
|
|
513
572
|
uploadPreKeysToServerIfRequired,
|
|
573
|
+
requestPairingCode,
|
|
514
574
|
/** Waits for the connection to WA to reach a state */
|
|
515
575
|
waitForConnectionUpdate: (0, Utils_1.bindWaitForConnectionUpdate)(ev),
|
|
516
576
|
};
|