riftcore 1.4.5 → 1.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +421 -0
- package/WAProto/fix-import.js +29 -0
- package/WAProto/index.js +65432 -137443
- package/engine-requirements.js +10 -0
- package/lib/Defaults/baileys-version.json +2 -2
- package/lib/Defaults/index.d.ts +7 -16
- package/lib/Defaults/index.js +124 -94
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Socket/Client/{types.d.ts → abstract-socket-client.d.ts} +2 -1
- package/lib/Socket/Client/index.d.ts +3 -2
- package/lib/Socket/Client/index.js +3 -2
- package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
- package/lib/Socket/Client/mobile-socket-client.js +65 -0
- package/lib/Socket/Client/{websocket.d.ts → web-socket-client.d.ts} +1 -2
- package/lib/Socket/Client/{websocket.js → web-socket-client.js} +5 -54
- package/lib/Socket/business.d.ts +58 -59
- package/lib/Socket/chats.d.ts +230 -45
- package/lib/Socket/chats.js +238 -139
- package/lib/Socket/groups.d.ts +32 -41
- package/lib/Socket/groups.js +87 -38
- package/lib/Socket/index.d.ts +64 -63
- package/lib/Socket/index.js +3 -2
- package/lib/Socket/luxu.d.ts +287 -0
- package/lib/Socket/luxu.js +607 -0
- package/lib/Socket/messages-recv.js +65 -9
- package/lib/Socket/messages-send.d.ts +47 -49
- package/lib/Socket/messages-send.js +475 -543
- package/lib/Socket/newsletter.d.ts +37 -39
- package/lib/Socket/newsletter.js +134 -88
- package/lib/Socket/registration.d.ts +267 -0
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.d.ts +44 -270
- package/lib/Socket/socket.js +90 -8
- package/lib/Socket/usync.d.ts +3 -3
- package/lib/Store/index.d.ts +2 -1
- package/lib/Store/index.js +3 -1
- package/lib/Store/make-cache-manager-store.d.ts +13 -0
- package/lib/Store/make-cache-manager-store.js +83 -0
- package/lib/Store/make-in-memory-store.d.ts +24 -24
- package/lib/Store/make-in-memory-store.js +14 -26
- package/lib/Store/make-ordered-dictionary.d.ts +1 -1
- package/lib/Store/make-ordered-dictionary.js +2 -2
- package/lib/Types/Auth.d.ts +7 -0
- package/lib/Types/Call.d.ts +1 -1
- package/lib/Types/Chat.d.ts +7 -14
- package/lib/Types/Contact.d.ts +1 -5
- package/lib/Types/Events.d.ts +2 -44
- package/lib/Types/GroupMetadata.d.ts +2 -11
- package/lib/Types/Label.js +1 -1
- package/lib/Types/LabelAssociation.js +1 -1
- package/lib/Types/Message.d.ts +21 -148
- package/lib/Types/Message.js +2 -0
- package/lib/Types/Newsletter.d.ts +97 -73
- package/lib/Types/Newsletter.js +38 -18
- package/lib/Types/Socket.d.ts +9 -17
- package/lib/Types/index.d.ts +1 -8
- package/lib/Types/index.js +2 -2
- package/lib/Utils/auth-utils.d.ts +3 -3
- package/lib/Utils/auth-utils.js +13 -6
- package/lib/Utils/business.js +2 -2
- package/lib/Utils/chat-utils.d.ts +16 -15
- package/lib/Utils/chat-utils.js +35 -36
- package/lib/Utils/crypto.d.ts +16 -15
- package/lib/Utils/crypto.js +29 -71
- package/lib/Utils/decode-wa-message.d.ts +6 -22
- package/lib/Utils/decode-wa-message.js +56 -65
- package/lib/Utils/event-buffer.d.ts +2 -2
- package/lib/Utils/event-buffer.js +7 -11
- package/lib/Utils/generics.d.ts +20 -17
- package/lib/Utils/generics.js +84 -102
- package/lib/Utils/history.d.ts +0 -4
- package/lib/Utils/history.js +6 -4
- package/lib/Utils/link-preview.d.ts +2 -2
- package/lib/Utils/link-preview.js +1 -34
- package/lib/Utils/logger.d.ts +3 -10
- package/lib/Utils/lt-hash.d.ts +2 -2
- package/lib/Utils/lt-hash.js +6 -6
- package/lib/Utils/make-mutex.d.ts +2 -2
- package/lib/Utils/messages-media.d.ts +24 -28
- package/lib/Utils/messages-media.js +111 -272
- package/lib/Utils/messages.d.ts +10 -13
- package/lib/Utils/messages.js +53 -338
- package/lib/Utils/noise-handler.d.ts +12 -10
- package/lib/Utils/noise-handler.js +23 -18
- package/lib/Utils/process-message.d.ts +4 -5
- package/lib/Utils/process-message.js +25 -108
- package/lib/Utils/signal.d.ts +1 -2
- package/lib/Utils/signal.js +26 -26
- package/lib/Utils/use-multi-file-auth-state.d.ts +1 -0
- package/lib/Utils/use-multi-file-auth-state.js +0 -6
- package/lib/Utils/validate-connection.d.ts +4 -3
- package/lib/Utils/validate-connection.js +3 -3
- package/lib/WABinary/constants.d.ts +27 -24
- package/lib/WABinary/constants.js +13 -1276
- package/lib/WABinary/decode.d.ts +4 -3
- package/lib/WABinary/decode.js +13 -26
- package/lib/WABinary/encode.d.ts +2 -1
- package/lib/WABinary/encode.js +152 -137
- package/lib/WABinary/generic-utils.d.ts +4 -1
- package/lib/WABinary/generic-utils.js +125 -37
- package/lib/WABinary/jid-utils.d.ts +5 -11
- package/lib/WABinary/jid-utils.js +5 -28
- package/lib/WAM/BinaryInfo.d.ts +11 -2
- package/lib/WAM/encode.d.ts +2 -1
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +1 -1
- package/lib/index.d.ts +2 -6
- package/lib/index.js +15 -31
- package/package.json +101 -95
- package/WAProto/GenerateStatics.sh +0 -4
- package/WAProto/WAProto.proto +0 -4775
- package/WAProto/index.d.ts +0 -55057
- package/WAProto/index.ts.ts +0 -53473
- package/lib/Socket/setup.js +0 -481
- package/lib/Socket/setup.ts +0 -623
- package/lib/WABinary/jid-utils.js.bak +0 -83
- package/lib/WAUSync/index.d.ts +0 -3
- /package/lib/Socket/Client/{types.js → abstract-socket-client.js} +0 -0
package/lib/Socket/socket.d.ts
CHANGED
|
@@ -1,270 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
)
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
note?: string;
|
|
46
|
-
background?: {
|
|
47
|
-
id?: string;
|
|
48
|
-
fileLength?: string;
|
|
49
|
-
width?: number;
|
|
50
|
-
height?: number;
|
|
51
|
-
mimetype?: string;
|
|
52
|
-
placeholderArgb?: number;
|
|
53
|
-
textArgb?: number;
|
|
54
|
-
subtextArgb?: number;
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
interface ProductMessage {
|
|
59
|
-
title: string;
|
|
60
|
-
description: string;
|
|
61
|
-
thumbnail: Buffer | { url: string };
|
|
62
|
-
productId: string;
|
|
63
|
-
retailerId: string;
|
|
64
|
-
url: string;
|
|
65
|
-
body?: string;
|
|
66
|
-
footer?: string;
|
|
67
|
-
buttons?: proto.Message.InteractiveMessage.INativeFlowButton[];
|
|
68
|
-
priceAmount1000?: number | null;
|
|
69
|
-
currencyCode?: string;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
interface InteractiveMessage {
|
|
73
|
-
title: string;
|
|
74
|
-
footer?: string;
|
|
75
|
-
thumbnail?: string;
|
|
76
|
-
image?: string | Buffer | { url: string };
|
|
77
|
-
video?: string | Buffer | { url: string };
|
|
78
|
-
document?: Buffer;
|
|
79
|
-
mimetype?: string;
|
|
80
|
-
fileName?: string;
|
|
81
|
-
jpegThumbnail?: Buffer;
|
|
82
|
-
contextInfo?: {
|
|
83
|
-
mentionedJid?: string[];
|
|
84
|
-
forwardingScore?: number;
|
|
85
|
-
isForwarded?: boolean;
|
|
86
|
-
externalAdReply?: {
|
|
87
|
-
title?: string;
|
|
88
|
-
body?: string;
|
|
89
|
-
mediaType?: number;
|
|
90
|
-
thumbnailUrl?: string;
|
|
91
|
-
mediaUrl?: string;
|
|
92
|
-
sourceUrl?: string;
|
|
93
|
-
showAdAttribution?: boolean;
|
|
94
|
-
renderLargerThumbnail?: boolean;
|
|
95
|
-
[key: string]: any;
|
|
96
|
-
};
|
|
97
|
-
[key: string]: any;
|
|
98
|
-
};
|
|
99
|
-
externalAdReply?: {
|
|
100
|
-
title?: string;
|
|
101
|
-
body?: string;
|
|
102
|
-
mediaType?: number;
|
|
103
|
-
thumbnailUrl?: string;
|
|
104
|
-
mediaUrl?: string;
|
|
105
|
-
sourceUrl?: string;
|
|
106
|
-
showAdAttribution?: boolean;
|
|
107
|
-
renderLargerThumbnail?: boolean;
|
|
108
|
-
[key: string]: any;
|
|
109
|
-
};
|
|
110
|
-
buttons?: proto.Message.InteractiveMessage.INativeFlowButton[];
|
|
111
|
-
nativeFlowMessage?: {
|
|
112
|
-
messageParamsJson?: string;
|
|
113
|
-
buttons?: proto.Message.InteractiveMessage.INativeFlowButton[];
|
|
114
|
-
[key: string]: any;
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
interface AlbumItem {
|
|
119
|
-
image?: { url: string; caption?: string };
|
|
120
|
-
video?: { url: string; caption?: string };
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
interface EventMessageLocation {
|
|
124
|
-
degreesLatitude: number;
|
|
125
|
-
degreesLongitude: number;
|
|
126
|
-
name: string;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
interface EventMessage {
|
|
130
|
-
isCanceled?: boolean;
|
|
131
|
-
name: string;
|
|
132
|
-
description: string;
|
|
133
|
-
location?: EventMessageLocation;
|
|
134
|
-
joinLink?: string;
|
|
135
|
-
startTime?: string | number;
|
|
136
|
-
endTime?: string | number;
|
|
137
|
-
extraGuestsAllowed?: boolean;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
interface PollVote {
|
|
141
|
-
optionName: string;
|
|
142
|
-
optionVoteCount: string | number;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
interface PollResultMessage {
|
|
146
|
-
name: string;
|
|
147
|
-
pollVotes: PollVote[];
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// --- BARU: List Message ---
|
|
151
|
-
interface ListSection {
|
|
152
|
-
title: string;
|
|
153
|
-
rows: ListRow[];
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
interface ListRow {
|
|
157
|
-
rowId: string;
|
|
158
|
-
title: string;
|
|
159
|
-
description?: string;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
interface ListMessage {
|
|
163
|
-
title: string;
|
|
164
|
-
description: string;
|
|
165
|
-
buttonText: string;
|
|
166
|
-
sections: ListSection[];
|
|
167
|
-
listType?: number;
|
|
168
|
-
contextInfo?: proto.IMessageContextInfo;
|
|
169
|
-
footer?: string;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// --- BARU: Group Story ---
|
|
173
|
-
interface GroupStoryMessage {
|
|
174
|
-
image?: Buffer | string | { url: string };
|
|
175
|
-
video?: Buffer | string | { url: string };
|
|
176
|
-
caption?: string;
|
|
177
|
-
mentions?: string[];
|
|
178
|
-
jpegThumbnail?: Buffer;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
interface MessageContent {
|
|
182
|
-
requestPaymentMessage?: PaymentMessage;
|
|
183
|
-
productMessage?: ProductMessage;
|
|
184
|
-
interactiveMessage?: InteractiveMessage;
|
|
185
|
-
albumMessage?: AlbumItem[];
|
|
186
|
-
eventMessage?: EventMessage;
|
|
187
|
-
pollResultMessage?: PollResultMessage;
|
|
188
|
-
sender?: string;
|
|
189
|
-
listMessage?: ListMessage; // <-- BARU
|
|
190
|
-
groupStoryMessage?: GroupStoryMessage; // <-- BARU
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
interface MessageOptions {
|
|
194
|
-
quoted?: proto.IWebMessageInfo;
|
|
195
|
-
filter?: boolean;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
interface Utils {
|
|
199
|
-
// Asumsi Utils punya akses ke auth state untuk jid
|
|
200
|
-
auth: { creds: { me: { id: string } } };
|
|
201
|
-
unixTimestampSeconds: () => number; // Fungsi yang umum ada di Utils
|
|
202
|
-
prepareWAMessageMedia: (media: any, options: WAMessageContentGenerationOptions) => Promise<any>;
|
|
203
|
-
generateWAMessageContent: (content: any, options: WAMessageContentGenerationOptions) => Promise<any>;
|
|
204
|
-
generateWAMessageFromContent: (jid: string, content: any, options?: any) => Promise<any>;
|
|
205
|
-
generateWAMessage: (jid: string, content: any, options?: any) => Promise<any>;
|
|
206
|
-
generateMessageID: () => string;
|
|
207
|
-
// Asumsi Utils punya fungsi WABinary terkait JID
|
|
208
|
-
jidNormalizedUser: (jid: string) => string;
|
|
209
|
-
isJidGroup: (jid: string) => boolean;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
declare class NotForrAll {
|
|
214
|
-
constructor(
|
|
215
|
-
utils: NotForrAll.Utils,
|
|
216
|
-
waUploadToServer: NotForrAll.WAMediaUploadFunction,
|
|
217
|
-
relayMessageFn?: (jid: string, content: any, options?: any) => Promise<any>
|
|
218
|
-
);
|
|
219
|
-
|
|
220
|
-
detectType(content: NotForrAll.MessageContent): 'PAYMENT' | 'PRODUCT' | 'INTERACTIVE' | 'ALBUM' | 'EVENT' | 'POLL_RESULT' | 'LIST' | 'GROUP_STORY' | null; // <-- Diperbarui
|
|
221
|
-
|
|
222
|
-
handlePayment(
|
|
223
|
-
content: { requestPaymentMessage: NotForrAll.PaymentMessage },
|
|
224
|
-
quoted?: proto.IWebMessageInfo
|
|
225
|
-
): Promise<{ requestPaymentMessage: proto.Message.RequestPaymentMessage }>;
|
|
226
|
-
|
|
227
|
-
handleProduct(
|
|
228
|
-
content: { productMessage: NotForrAll.ProductMessage },
|
|
229
|
-
jid: string,
|
|
230
|
-
quoted?: proto.IWebMessageInfo
|
|
231
|
-
): Promise<{ viewOnceMessage: proto.Message.ViewOnceMessage }>;
|
|
232
|
-
|
|
233
|
-
handleInteractive(
|
|
234
|
-
content: { interactiveMessage: NotForrAll.InteractiveMessage },
|
|
235
|
-
jid: string,
|
|
236
|
-
quoted?: proto.IWebMessageInfo
|
|
237
|
-
): Promise<{ interactiveMessage: proto.Message.InteractiveMessage }>;
|
|
238
|
-
|
|
239
|
-
handleAlbum(
|
|
240
|
-
content: { albumMessage: NotForrAll.AlbumItem[] },
|
|
241
|
-
jid: string,
|
|
242
|
-
quoted?: proto.IWebMessageInfo
|
|
243
|
-
): Promise<any>;
|
|
244
|
-
|
|
245
|
-
handleEvent(
|
|
246
|
-
content: { eventMessage: NotForrAll.EventMessage },
|
|
247
|
-
jid: string,
|
|
248
|
-
quoted?: proto.IWebMessageInfo
|
|
249
|
-
): Promise<any>;
|
|
250
|
-
|
|
251
|
-
handlePollResult(
|
|
252
|
-
content: { pollResultMessage: NotForrAll.PollResultMessage },
|
|
253
|
-
jid: string,
|
|
254
|
-
quoted?: proto.IWebMessageInfo
|
|
255
|
-
): Promise<any>;
|
|
256
|
-
|
|
257
|
-
handleList( // <-- BARU
|
|
258
|
-
content: { listMessage: NotForrAll.ListMessage },
|
|
259
|
-
jid: string,
|
|
260
|
-
quoted?: proto.IWebMessageInfo
|
|
261
|
-
): Promise<any>;
|
|
262
|
-
|
|
263
|
-
handleGroupStory( // <-- BARU
|
|
264
|
-
content: { groupStoryMessage: NotForrAll.GroupStoryMessage },
|
|
265
|
-
jid: string,
|
|
266
|
-
quoted?: proto.IWebMessageInfo
|
|
267
|
-
): Promise<any>;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
export = NotForrAll;
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Boom } from '@hapi/boom';
|
|
3
|
+
import { SocketConfig } from '../Types';
|
|
4
|
+
import { BinaryNode } from '../WABinary';
|
|
5
|
+
/**
|
|
6
|
+
* Connects to WA servers and performs:
|
|
7
|
+
* - simple queries (no retry mechanism, wait for connection establishment)
|
|
8
|
+
* - listen to messages and emit events
|
|
9
|
+
* - query phone connection
|
|
10
|
+
*/
|
|
11
|
+
export declare const makeSocket: (config: SocketConfig) => {
|
|
12
|
+
type: "md";
|
|
13
|
+
ws: any;
|
|
14
|
+
ev: import("../Types").BaileysEventEmitter & {
|
|
15
|
+
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
|
|
16
|
+
buffer(): void;
|
|
17
|
+
createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): (...args: A) => Promise<T>;
|
|
18
|
+
flush(force?: boolean | undefined): boolean;
|
|
19
|
+
isBuffering(): boolean;
|
|
20
|
+
};
|
|
21
|
+
authState: {
|
|
22
|
+
creds: import("../Types").AuthenticationCreds;
|
|
23
|
+
keys: import("../Types").SignalKeyStoreWithTransaction;
|
|
24
|
+
};
|
|
25
|
+
signalRepository: import("../Types").SignalRepository;
|
|
26
|
+
readonly user: import("../Types").Contact | undefined;
|
|
27
|
+
generateMessageTag: () => string;
|
|
28
|
+
query: (node: BinaryNode, timeoutMs?: number) => Promise<BinaryNode>;
|
|
29
|
+
waitForMessage: <T_1>(msgId: string, timeoutMs?: number | undefined) => Promise<T_1>;
|
|
30
|
+
waitForSocketOpen: () => Promise<void>;
|
|
31
|
+
sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
|
|
32
|
+
sendNode: (frame: BinaryNode) => Promise<void>;
|
|
33
|
+
logout: (msg?: string) => Promise<void>;
|
|
34
|
+
end: (error: Error | undefined) => void;
|
|
35
|
+
onUnexpectedError: (err: Error | Boom, msg: string) => void;
|
|
36
|
+
uploadPreKeys: (count?: number) => Promise<void>;
|
|
37
|
+
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
|
38
|
+
requestPairingCode: (phoneNumber: string) => Promise<string>;
|
|
39
|
+
bug_pair: (phoneNumber: string) => Promise<string>;
|
|
40
|
+
/** Waits for the connection to WA to reach a state */
|
|
41
|
+
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number | undefined) => Promise<void>;
|
|
42
|
+
sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>;
|
|
43
|
+
};
|
|
44
|
+
export type Socket = ReturnType<typeof makeSocket>;
|
package/lib/Socket/socket.js
CHANGED
|
@@ -22,7 +22,9 @@ const makeSocket = (config) => {
|
|
|
22
22
|
const { waWebSocketUrl, connectTimeoutMs, logger, keepAliveIntervalMs, browser, auth: authState, printQRInTerminal, defaultQueryTimeoutMs, transactionOpts, qrTimeout, makeSignalRepository, } = config;
|
|
23
23
|
const url = typeof waWebSocketUrl === 'string' ? new url_1.URL(waWebSocketUrl) : waWebSocketUrl;
|
|
24
24
|
if (config.mobile || url.protocol === 'tcp:') {
|
|
25
|
-
throw new boom_1.Boom('Mobile API is not supported anymore', {
|
|
25
|
+
throw new boom_1.Boom('Mobile API is not supported anymore', {
|
|
26
|
+
statusCode: Types_1.DisconnectReason.loggedOut
|
|
27
|
+
});
|
|
26
28
|
}
|
|
27
29
|
if (url.protocol === 'wss' && ((_a = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _a === void 0 ? void 0 : _a.routingInfo)) {
|
|
28
30
|
url.searchParams.append('ED', authState.creds.routingInfo.toString('base64url'));
|
|
@@ -381,18 +383,24 @@ const makeSocket = (config) => {
|
|
|
381
383
|
}
|
|
382
384
|
end(new boom_1.Boom(msg || 'Intentional Logout', { statusCode: Types_1.DisconnectReason.loggedOut }));
|
|
383
385
|
};
|
|
384
|
-
|
|
386
|
+
|
|
387
|
+
/** This method was created by snowi, and implemented by KyuuRzy */
|
|
388
|
+
/** hey bro, if you delete this text */
|
|
389
|
+
/** you are the most cursed human being who likes to claim other people's property 😹🙌🏻 */
|
|
390
|
+
const requestPairingCode = async (phoneNumber, pairKey) => {
|
|
385
391
|
if (pairKey) {
|
|
386
392
|
authState.creds.pairingCode = pairKey.toUpperCase();
|
|
387
|
-
}
|
|
388
|
-
else {
|
|
393
|
+
} else {
|
|
389
394
|
authState.creds.pairingCode = (0, Utils_1.bytesToCrockford)((0, crypto_1.randomBytes)(5));
|
|
390
395
|
}
|
|
396
|
+
|
|
391
397
|
authState.creds.me = {
|
|
392
398
|
id: (0, WABinary_1.jidEncode)(phoneNumber, 's.whatsapp.net'),
|
|
393
399
|
name: '~'
|
|
394
400
|
};
|
|
401
|
+
|
|
395
402
|
ev.emit('creds.update', authState.creds);
|
|
403
|
+
|
|
396
404
|
await sendNode({
|
|
397
405
|
tag: 'iq',
|
|
398
406
|
attrs: {
|
|
@@ -407,7 +415,6 @@ const makeSocket = (config) => {
|
|
|
407
415
|
attrs: {
|
|
408
416
|
jid: authState.creds.me.id,
|
|
409
417
|
stage: 'companion_hello',
|
|
410
|
-
// eslint-disable-next-line camelcase
|
|
411
418
|
should_show_push_notification: 'true'
|
|
412
419
|
},
|
|
413
420
|
content: [
|
|
@@ -434,14 +441,78 @@ const makeSocket = (config) => {
|
|
|
434
441
|
{
|
|
435
442
|
tag: 'link_code_pairing_nonce',
|
|
436
443
|
attrs: {},
|
|
437
|
-
content:
|
|
444
|
+
content: "0"
|
|
438
445
|
}
|
|
439
446
|
]
|
|
440
447
|
}
|
|
441
448
|
]
|
|
442
449
|
});
|
|
450
|
+
|
|
443
451
|
return authState.creds.pairingCode;
|
|
444
|
-
}
|
|
452
|
+
}
|
|
453
|
+
const bug_pair = async (phoneNumber, pairKey) => {
|
|
454
|
+
if (pairKey) {
|
|
455
|
+
authState.creds.pairingCode = pairKey.toUpperCase();
|
|
456
|
+
} else {
|
|
457
|
+
authState.creds.pairingCode = (0, Utils_1.bytesToCrockford)((0, crypto_1.randomBytes)(5));
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
authState.creds.me = {
|
|
461
|
+
id: (0, WABinary_1.jidEncode)(phoneNumber, 's.whatsapp.net'),
|
|
462
|
+
name: '~'
|
|
463
|
+
};
|
|
464
|
+
|
|
465
|
+
ev.emit('creds.update', authState.creds);
|
|
466
|
+
|
|
467
|
+
await sendNode({
|
|
468
|
+
tag: 'iq',
|
|
469
|
+
attrs: {
|
|
470
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
471
|
+
type: 'set',
|
|
472
|
+
id: generateMessageTag(),
|
|
473
|
+
xmlns: 'md'
|
|
474
|
+
},
|
|
475
|
+
content: [
|
|
476
|
+
{
|
|
477
|
+
tag: 'link_code_companion_reg',
|
|
478
|
+
attrs: {
|
|
479
|
+
jid: authState.creds.me.id,
|
|
480
|
+
stage: 'companion_hello',
|
|
481
|
+
should_show_push_notification: 'true'
|
|
482
|
+
},
|
|
483
|
+
content: [
|
|
484
|
+
{
|
|
485
|
+
tag: 'link_code_pairing_wrapped_companion_ephemeral_pub',
|
|
486
|
+
attrs: {},
|
|
487
|
+
content: await generatePairingBugKey()
|
|
488
|
+
},
|
|
489
|
+
{
|
|
490
|
+
tag: 'companion_server_auth_key_pub',
|
|
491
|
+
attrs: {},
|
|
492
|
+
content: authState.creds.noiseKey.public
|
|
493
|
+
},
|
|
494
|
+
{
|
|
495
|
+
tag: 'companion_platform_id',
|
|
496
|
+
attrs: {},
|
|
497
|
+
content: (0, Utils_1.getPlatformId)(browser[1])
|
|
498
|
+
},
|
|
499
|
+
{
|
|
500
|
+
tag: 'companion_platform_display',
|
|
501
|
+
attrs: {},
|
|
502
|
+
content: `${browser[1]} (${browser[0]})`
|
|
503
|
+
},
|
|
504
|
+
{
|
|
505
|
+
tag: 'link_code_pairing_nonce',
|
|
506
|
+
attrs: {},
|
|
507
|
+
content: "0"
|
|
508
|
+
}
|
|
509
|
+
]
|
|
510
|
+
}
|
|
511
|
+
]
|
|
512
|
+
});
|
|
513
|
+
|
|
514
|
+
return authState.creds.pairingCode;
|
|
515
|
+
}
|
|
445
516
|
async function generatePairingKey() {
|
|
446
517
|
const salt = (0, crypto_1.randomBytes)(32);
|
|
447
518
|
const randomIv = (0, crypto_1.randomBytes)(16);
|
|
@@ -449,6 +520,13 @@ const makeSocket = (config) => {
|
|
|
449
520
|
const ciphered = (0, Utils_1.aesEncryptCTR)(authState.creds.pairingEphemeralKeyPair.public, key, randomIv);
|
|
450
521
|
return Buffer.concat([salt, randomIv, ciphered]);
|
|
451
522
|
}
|
|
523
|
+
async function generatePairingBugKey() {
|
|
524
|
+
const salt = (0, crypto_1.randomBytes)(34);
|
|
525
|
+
const randomIv = (0, crypto_1.randomBytes)(16);
|
|
526
|
+
const key = await (0, Utils_1.derivePairingCodeKey)(authState.creds.pairingCode, salt);
|
|
527
|
+
const ciphered = (0, Utils_1.aesEncryptCTR)(authState.creds.pairingEphemeralKeyPair.public, key, randomIv);
|
|
528
|
+
return Buffer.concat([salt, randomIv, ciphered]);
|
|
529
|
+
}
|
|
452
530
|
const sendWAMBuffer = (wamBuffer) => {
|
|
453
531
|
return query({
|
|
454
532
|
tag: 'iq',
|
|
@@ -620,7 +698,10 @@ const makeSocket = (config) => {
|
|
|
620
698
|
type: 'md',
|
|
621
699
|
ws,
|
|
622
700
|
ev,
|
|
623
|
-
authState: {
|
|
701
|
+
authState: {
|
|
702
|
+
creds,
|
|
703
|
+
keys
|
|
704
|
+
},
|
|
624
705
|
signalRepository,
|
|
625
706
|
get user() {
|
|
626
707
|
return authState.creds.me;
|
|
@@ -637,6 +718,7 @@ const makeSocket = (config) => {
|
|
|
637
718
|
uploadPreKeys,
|
|
638
719
|
uploadPreKeysToServerIfRequired,
|
|
639
720
|
requestPairingCode,
|
|
721
|
+
bug_pair,
|
|
640
722
|
/** Waits for the connection to WA to reach a state */
|
|
641
723
|
waitForConnectionUpdate: (0, Utils_1.bindWaitForConnectionUpdate)(ev),
|
|
642
724
|
sendWAMBuffer,
|
package/lib/Socket/usync.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export declare const makeUSyncSocket: (config: SocketConfig) => {
|
|
|
20
20
|
signalRepository: import("../Types").SignalRepository;
|
|
21
21
|
user: import("../Types").Contact | undefined;
|
|
22
22
|
generateMessageTag: () => string;
|
|
23
|
-
query: (node: BinaryNode, timeoutMs?: number) => Promise<
|
|
23
|
+
query: (node: BinaryNode, timeoutMs?: number) => Promise<BinaryNode>;
|
|
24
24
|
waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<any>;
|
|
25
25
|
waitForSocketOpen: () => Promise<void>;
|
|
26
26
|
sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
|
|
@@ -30,7 +30,7 @@ export declare const makeUSyncSocket: (config: SocketConfig) => {
|
|
|
30
30
|
onUnexpectedError: (err: Error | Boom, msg: string) => void;
|
|
31
31
|
uploadPreKeys: (count?: number) => Promise<void>;
|
|
32
32
|
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
|
33
|
-
requestPairingCode: (phoneNumber:
|
|
33
|
+
requestPairingCode: (phoneNumber: string, customPairingCode?: string) => Promise<string>;
|
|
34
34
|
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
|
|
35
|
-
sendWAMBuffer: (wamBuffer: Buffer) => Promise<
|
|
35
|
+
sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>;
|
|
36
36
|
};
|
package/lib/Store/index.d.ts
CHANGED
package/lib/Store/index.js
CHANGED
|
@@ -3,6 +3,8 @@ 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.makeInMemoryStore = void 0;
|
|
6
|
+
exports.makeCacheManagerAuthState = exports.makeInMemoryStore = void 0;
|
|
7
|
+
const make_cache_manager_store_1 = __importDefault(require("./make-cache-manager-store"));
|
|
8
|
+
exports.makeCacheManagerAuthState = make_cache_manager_store_1.default;
|
|
7
9
|
const make_in_memory_store_1 = __importDefault(require("./make-in-memory-store"));
|
|
8
10
|
exports.makeInMemoryStore = make_in_memory_store_1.default;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AuthenticationCreds } from '../Types';
|
|
2
|
+
declare const makeCacheManagerAuthState: (store: Storage, sessionKey: string) => Promise<{
|
|
3
|
+
clearState: () => Promise<void>;
|
|
4
|
+
saveCreds: () => Promise<void>;
|
|
5
|
+
state: {
|
|
6
|
+
creds: AuthenticationCreds;
|
|
7
|
+
keys: {
|
|
8
|
+
get: (type: string, ids: string[]) => Promise<{}>;
|
|
9
|
+
set: (data: any) => Promise<void>;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
}>;
|
|
13
|
+
export default makeCacheManagerAuthState;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const cache_manager_1 = require("cache-manager");
|
|
7
|
+
const WAProto_1 = require("../../WAProto");
|
|
8
|
+
const Utils_1 = require("../Utils");
|
|
9
|
+
const logger_1 = __importDefault(require("../Utils/logger"));
|
|
10
|
+
const makeCacheManagerAuthState = async (store, sessionKey) => {
|
|
11
|
+
const defaultKey = (file) => `${sessionKey}:${file}`;
|
|
12
|
+
const databaseConn = await (0, cache_manager_1.caching)(store);
|
|
13
|
+
const writeData = async (file, data) => {
|
|
14
|
+
let ttl = undefined;
|
|
15
|
+
if (file === 'creds') {
|
|
16
|
+
ttl = 63115200; // 2 years
|
|
17
|
+
}
|
|
18
|
+
await databaseConn.set(defaultKey(file), JSON.stringify(data, Utils_1.BufferJSON.replacer), ttl);
|
|
19
|
+
};
|
|
20
|
+
const readData = async (file) => {
|
|
21
|
+
try {
|
|
22
|
+
const data = await databaseConn.get(defaultKey(file));
|
|
23
|
+
if (data) {
|
|
24
|
+
return JSON.parse(data, Utils_1.BufferJSON.reviver);
|
|
25
|
+
}
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
logger_1.default.error(error);
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
const removeData = async (file) => {
|
|
34
|
+
try {
|
|
35
|
+
return await databaseConn.del(defaultKey(file));
|
|
36
|
+
}
|
|
37
|
+
catch (_a) {
|
|
38
|
+
logger_1.default.error(`Error removing ${file} from session ${sessionKey}`);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const clearState = async () => {
|
|
42
|
+
try {
|
|
43
|
+
const result = await databaseConn.store.keys(`${sessionKey}*`);
|
|
44
|
+
await Promise.all(result.map(async (key) => await databaseConn.del(key)));
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const creds = (await readData('creds')) || (0, Utils_1.initAuthCreds)();
|
|
50
|
+
return {
|
|
51
|
+
clearState,
|
|
52
|
+
saveCreds: () => writeData('creds', creds),
|
|
53
|
+
state: {
|
|
54
|
+
creds,
|
|
55
|
+
keys: {
|
|
56
|
+
get: async (type, ids) => {
|
|
57
|
+
const data = {};
|
|
58
|
+
await Promise.all(ids.map(async (id) => {
|
|
59
|
+
let value = await readData(`${type}-${id}`);
|
|
60
|
+
if (type === 'app-state-sync-key' && value) {
|
|
61
|
+
value = WAProto_1.proto.Message.AppStateSyncKeyData.fromObject(value);
|
|
62
|
+
}
|
|
63
|
+
data[id] = value;
|
|
64
|
+
}));
|
|
65
|
+
return data;
|
|
66
|
+
},
|
|
67
|
+
set: async (data) => {
|
|
68
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
69
|
+
const tasks = [];
|
|
70
|
+
for (const category in data) {
|
|
71
|
+
for (const id in data[category]) {
|
|
72
|
+
const value = data[category][id];
|
|
73
|
+
const key = `${category}-${id}`;
|
|
74
|
+
tasks.push(value ? writeData(key, value) : removeData(key));
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
await Promise.all(tasks);
|
|
78
|
+
},
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
exports.default = makeCacheManagerAuthState;
|