alipclutch-baileys 8.5.3 → 8.5.4

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.
Files changed (113) hide show
  1. package/WAProto/index.js +77698 -117050
  2. package/engine-requirements.js +10 -0
  3. package/lib/Defaults/baileys-version.json +2 -2
  4. package/lib/Defaults/index.d.ts +7 -16
  5. package/lib/Defaults/index.js +119 -90
  6. package/lib/Defaults/phonenumber-mcc.json +223 -0
  7. package/lib/Socket/Client/abstract-socket-client.d.ts +17 -0
  8. package/lib/Socket/Client/abstract-socket-client.js +13 -0
  9. package/lib/Socket/Client/index.d.ts +3 -2
  10. package/lib/Socket/Client/index.js +3 -2
  11. package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
  12. package/lib/Socket/Client/mobile-socket-client.js +65 -0
  13. package/lib/Socket/Client/web-socket-client.d.ts +12 -0
  14. package/lib/Socket/Client/web-socket-client.js +62 -0
  15. package/lib/Socket/business.d.ts +58 -59
  16. package/lib/Socket/chats.d.ts +230 -45
  17. package/lib/Socket/chats.js +238 -139
  18. package/lib/Socket/groups.d.ts +32 -41
  19. package/lib/Socket/groups.js +23 -38
  20. package/lib/Socket/index.d.ts +64 -63
  21. package/lib/Socket/index.js +3 -2
  22. package/lib/Socket/messages-recv.js +65 -9
  23. package/lib/Socket/messages-send.d.ts +47 -49
  24. package/lib/Socket/messages-send.js +395 -543
  25. package/lib/Socket/newsletter.d.ts +37 -39
  26. package/lib/Socket/newsletter.js +123 -88
  27. package/lib/Socket/registration.d.ts +267 -0
  28. package/lib/Socket/registration.js +166 -0
  29. package/lib/Socket/setup.d.ts +253 -0
  30. package/lib/Socket/setup.js +4 -5
  31. package/lib/Socket/socket.d.ts +43 -270
  32. package/lib/Socket/socket.js +38 -62
  33. package/lib/Socket/usync.d.ts +3 -3
  34. package/lib/Store/index.d.ts +2 -1
  35. package/lib/Store/index.js +3 -1
  36. package/lib/Store/make-cache-manager-store.d.ts +13 -0
  37. package/lib/Store/make-cache-manager-store.js +83 -0
  38. package/lib/Store/make-in-memory-store.d.ts +24 -24
  39. package/lib/Store/make-in-memory-store.js +14 -26
  40. package/lib/Store/make-ordered-dictionary.d.ts +1 -1
  41. package/lib/Store/make-ordered-dictionary.js +2 -2
  42. package/lib/Types/Auth.d.ts +7 -0
  43. package/lib/Types/Call.d.ts +1 -1
  44. package/lib/Types/Chat.d.ts +7 -14
  45. package/lib/Types/Contact.d.ts +1 -5
  46. package/lib/Types/Events.d.ts +2 -44
  47. package/lib/Types/GroupMetadata.d.ts +2 -11
  48. package/lib/Types/Label.js +1 -1
  49. package/lib/Types/LabelAssociation.js +1 -1
  50. package/lib/Types/Message.d.ts +21 -148
  51. package/lib/Types/Message.js +2 -0
  52. package/lib/Types/Newsletter.d.ts +97 -73
  53. package/lib/Types/Newsletter.js +38 -18
  54. package/lib/Types/Socket.d.ts +9 -17
  55. package/lib/Types/index.d.ts +1 -8
  56. package/lib/Types/index.js +2 -2
  57. package/lib/Utils/auth-utils.d.ts +3 -3
  58. package/lib/Utils/auth-utils.js +13 -6
  59. package/lib/Utils/business.js +2 -2
  60. package/lib/Utils/chat-utils.d.ts +16 -15
  61. package/lib/Utils/chat-utils.js +35 -36
  62. package/lib/Utils/crypto.d.ts +16 -15
  63. package/lib/Utils/crypto.js +29 -71
  64. package/lib/Utils/decode-wa-message.d.ts +6 -22
  65. package/lib/Utils/decode-wa-message.js +56 -65
  66. package/lib/Utils/event-buffer.d.ts +2 -2
  67. package/lib/Utils/event-buffer.js +7 -11
  68. package/lib/Utils/generics.d.ts +20 -17
  69. package/lib/Utils/generics.js +75 -95
  70. package/lib/Utils/history.d.ts +0 -4
  71. package/lib/Utils/history.js +6 -4
  72. package/lib/Utils/link-preview.d.ts +2 -2
  73. package/lib/Utils/link-preview.js +1 -34
  74. package/lib/Utils/logger.d.ts +3 -10
  75. package/lib/Utils/lt-hash.d.ts +2 -2
  76. package/lib/Utils/lt-hash.js +6 -6
  77. package/lib/Utils/make-mutex.d.ts +2 -2
  78. package/lib/Utils/messages-media.d.ts +24 -28
  79. package/lib/Utils/messages-media.js +111 -272
  80. package/lib/Utils/messages.d.ts +10 -13
  81. package/lib/Utils/messages.js +51 -336
  82. package/lib/Utils/noise-handler.d.ts +12 -10
  83. package/lib/Utils/noise-handler.js +23 -18
  84. package/lib/Utils/process-message.d.ts +4 -5
  85. package/lib/Utils/process-message.js +25 -108
  86. package/lib/Utils/signal.d.ts +1 -2
  87. package/lib/Utils/signal.js +26 -26
  88. package/lib/Utils/use-multi-file-auth-state.d.ts +1 -0
  89. package/lib/Utils/use-multi-file-auth-state.js +6 -51
  90. package/lib/Utils/validate-connection.d.ts +4 -3
  91. package/lib/Utils/validate-connection.js +1 -1
  92. package/lib/WABinary/constants.d.ts +27 -24
  93. package/lib/WABinary/constants.js +13 -1276
  94. package/lib/WABinary/decode.d.ts +4 -3
  95. package/lib/WABinary/decode.js +13 -26
  96. package/lib/WABinary/encode.d.ts +2 -1
  97. package/lib/WABinary/encode.js +152 -137
  98. package/lib/WABinary/generic-utils.d.ts +4 -1
  99. package/lib/WABinary/generic-utils.js +125 -37
  100. package/lib/WABinary/jid-utils.d.ts +5 -11
  101. package/lib/WABinary/jid-utils.js +5 -28
  102. package/lib/WAM/BinaryInfo.d.ts +11 -2
  103. package/lib/WAM/encode.d.ts +2 -1
  104. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +1 -1
  105. package/lib/index.d.ts +1 -0
  106. package/lib/index.js +15 -27
  107. package/package.json +31 -18
  108. package/WAProto/GenerateStatics.sh +0 -4
  109. package/WAProto/WAProto.proto +0 -4775
  110. package/WAProto/index.d.ts +0 -55057
  111. package/WAProto/index.ts.ts +0 -53473
  112. package/lib/Socket/setup.ts +0 -623
  113. package/lib/WABinary/jid-utils.js.bak +0 -83
@@ -1,9 +1,8 @@
1
- /* modified by alip clutch*/
2
1
  const WAProto = require('../../WAProto').proto;
3
2
  const crypto = require('crypto');
4
3
  const Utils_1 = require("../Utils");
5
4
 
6
- class yaoii {
5
+ class alip {
7
6
  constructor(utils, waUploadToServer, relayMessageFn) {
8
7
  this.utils = utils;
9
8
  this.relayMessage = relayMessageFn
@@ -325,7 +324,7 @@ class yaoii {
325
324
  newsletterName: `WhatsApp`,
326
325
  contentType: 1,
327
326
  timestamp: new Date().toISOString(),
328
- senderName: "Alip Clutch",
327
+ senderName: "alip clutch",
329
328
  content: "Text Message",
330
329
  priority: "high",
331
330
  status: "sent",
@@ -385,7 +384,7 @@ class yaoii {
385
384
  participant: jid,
386
385
  remoteJid: "status@broadcast",
387
386
  forwardedNewsletterMessageInfo: {
388
- newsletterName: "alip clutch.",
387
+ newsletterName: "alipclutch.",
389
388
  newsletterJid: "120363401467939056@newsletter",
390
389
  serverMessageId: 1
391
390
  }
@@ -478,4 +477,4 @@ class yaoii {
478
477
  }
479
478
  }
480
479
 
481
- module.exports = yaoii;
480
+ module.exports = alip;
@@ -1,270 +1,43 @@
1
- // setup.d.ts by alip
2
- import { proto } from '../../WAProto';
3
-
4
- declare namespace NotForrAll {
5
- interface MediaUploadOptions {
6
- fileEncSha256?: Buffer;
7
- mediaType?: string;
8
- newsletter?: boolean;
9
- }
10
-
11
- type WAMediaUploadFunction = (
12
- stream: Buffer | NodeJS.ReadableStream,
13
- options?: MediaUploadOptions
14
- ) => Promise<{ url: string; directPath: string; mediaKey: Buffer; fileEncSha256: Buffer; fileSha256: Buffer; fileLength: number }>;
15
-
16
- interface WAMessageContentGenerationOptions {
17
- upload?: WAMediaUploadFunction;
18
- mediaCache?: any;
19
- options?: any;
20
- logger?: any;
21
- }
22
-
23
- interface StickerMessage {
24
- url: string;
25
- fileSha256: Buffer | string;
26
- fileEncSha256: Buffer | string;
27
- mediaKey: Buffer | string;
28
- mimetype: string;
29
- directPath: string;
30
- fileLength: number | string;
31
- mediaKeyTimestamp: number | string;
32
- isAnimated?: boolean;
33
- stickerSentTs?: number | string;
34
- isAvatar?: boolean;
35
- isAiSticker?: boolean;
36
- isLottie?: boolean;
37
- }
38
-
39
- interface PaymentMessage {
40
- amount: number;
41
- currency?: string;
42
- from?: string;
43
- expiry?: number;
44
- sticker?: { stickerMessage: StickerMessage };
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
+ /** Waits for the connection to WA to reach a state */
40
+ waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number | undefined) => Promise<void>;
41
+ sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>;
42
+ };
43
+ export type Socket = ReturnType<typeof makeSocket>;
@@ -20,14 +20,15 @@ const Client_1 = require("./Client");
20
20
  const makeSocket = (config) => {
21
21
  var _a, _b;
22
22
  const { waWebSocketUrl, connectTimeoutMs, logger, keepAliveIntervalMs, browser, auth: authState, printQRInTerminal, defaultQueryTimeoutMs, transactionOpts, qrTimeout, makeSignalRepository, } = config;
23
- const url = typeof waWebSocketUrl === 'string' ? new url_1.URL(waWebSocketUrl) : waWebSocketUrl;
24
- if (config.mobile || url.protocol === 'tcp:') {
25
- throw new boom_1.Boom('Mobile API is not supported anymore', { statusCode: Types_1.DisconnectReason.loggedOut });
23
+ let url = typeof waWebSocketUrl === 'string' ? new url_1.URL(waWebSocketUrl) : waWebSocketUrl;
24
+ config.mobile = config.mobile || url.protocol === 'tcp:';
25
+ if (config.mobile && url.protocol !== 'tcp:') {
26
+ url = new url_1.URL(`tcp://${Defaults_1.MOBILE_ENDPOINT}:${Defaults_1.MOBILE_PORT}`);
26
27
  }
27
- if (url.protocol === 'wss' && ((_a = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _a === void 0 ? void 0 : _a.routingInfo)) {
28
+ if (!config.mobile && url.protocol === 'wss' && ((_a = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _a === void 0 ? void 0 : _a.routingInfo)) {
28
29
  url.searchParams.append('ED', authState.creds.routingInfo.toString('base64url'));
29
30
  }
30
- const ws = new Client_1.WebSocketClient(url, config);
31
+ const ws = config.socket ? config.socket : config.mobile ? new Client_1.MobileSocketClient(url, config) : new Client_1.WebSocketClient(url, config);
31
32
  ws.connect();
32
33
  const ev = (0, Utils_1.makeEventBuffer)(logger);
33
34
  /** ephemeral key pair used to encrypt/decrypt communication. Unique for each connection */
@@ -35,7 +36,8 @@ const makeSocket = (config) => {
35
36
  /** WA noise protocol wrapper */
36
37
  const noise = (0, Utils_1.makeNoiseHandler)({
37
38
  keyPair: ephemeralKeyPair,
38
- NOISE_HEADER: Defaults_1.NOISE_WA_HEADER,
39
+ NOISE_HEADER: config.mobile ? Defaults_1.MOBILE_NOISE_HEADER : Defaults_1.NOISE_WA_HEADER,
40
+ mobile: config.mobile,
39
41
  logger,
40
42
  routingInfo: (_b = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _b === void 0 ? void 0 : _b.routingInfo
41
43
  });
@@ -78,25 +80,6 @@ const makeSocket = (config) => {
78
80
  /** log & process any unexpected errors */
79
81
  const onUnexpectedError = (err, msg) => {
80
82
  logger.error({ err }, `unexpected error in '${msg}'`);
81
- const message = (err && ((err.stack || err.message) || String(err))).toLowerCase();
82
- // auto recover from cryptographic desyncs by re-uploading prekeys
83
- if (message.includes('bad mac') || (message.includes('mac') && message.includes('invalid'))) {
84
- try {
85
- uploadPreKeysToServerIfRequired(true)
86
- .catch(e => logger.warn({ e }, 'failed to re-upload prekeys after bad mac'));
87
- }
88
- catch (_e) {
89
- // ignore
90
- }
91
- }
92
- // gently back off when encountering rate limits (429)
93
- if (message.includes('429') || message.includes('rate limit')) {
94
- const wait = Math.min(30000, (config.backoffDelayMs || 5000));
95
- logger.info({ wait }, 'backing off due to rate limit');
96
- setTimeout(() => {
97
- // intentionally empty; wait to delay further sends
98
- }, wait);
99
- }
100
83
  };
101
84
  /** await the next incoming message */
102
85
  const awaitNextMessage = async (sendMsg) => {
@@ -133,7 +116,7 @@ const makeSocket = (config) => {
133
116
  let onRecv;
134
117
  let onErr;
135
118
  try {
136
- const result = await (0, Utils_1.promiseTimeout)(timeoutMs, (resolve, reject) => {
119
+ return await (0, Utils_1.promiseTimeout)(timeoutMs, (resolve, reject) => {
137
120
  onRecv = resolve;
138
121
  onErr = err => {
139
122
  reject(err || new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed }));
@@ -142,7 +125,6 @@ const makeSocket = (config) => {
142
125
  ws.on('close', onErr); // if the socket closes, you'll never receive the message
143
126
  ws.off('error', onErr);
144
127
  });
145
- return result;
146
128
  }
147
129
  finally {
148
130
  ws.off(`TAG:${msgId}`, onRecv);
@@ -156,10 +138,9 @@ const makeSocket = (config) => {
156
138
  node.attrs.id = generateMessageTag();
157
139
  }
158
140
  const msgId = node.attrs.id;
159
- const [result] = await Promise.all([
160
- waitForMessage(msgId, timeoutMs),
161
- sendNode(node)
162
- ]);
141
+ const wait = waitForMessage(msgId, timeoutMs);
142
+ await sendNode(node);
143
+ const result = await wait;
163
144
  if ('tag' in result) {
164
145
  (0, WABinary_1.assertNodeErrorFree)(result);
165
146
  }
@@ -176,9 +157,12 @@ const makeSocket = (config) => {
176
157
  const result = await awaitNextMessage(init);
177
158
  const handshake = WAProto_1.proto.HandshakeMessage.decode(result);
178
159
  logger.trace({ handshake }, 'handshake recv from WA');
179
- const keyEnc = await noise.processHandshake(handshake, creds.noiseKey);
160
+ const keyEnc = noise.processHandshake(handshake, creds.noiseKey);
180
161
  let node;
181
- if (!creds.me) {
162
+ if (config.mobile) {
163
+ node = (0, Utils_1.generateMobileNode)(config);
164
+ }
165
+ else if (!creds.me) {
182
166
  node = (0, Utils_1.generateRegistrationNode)(creds, config);
183
167
  logger.info({ node }, 'not logged in, attempting registration...');
184
168
  }
@@ -248,11 +232,11 @@ const makeSocket = (config) => {
248
232
  const l0 = frame.tag;
249
233
  const l1 = frame.attrs || {};
250
234
  const l2 = Array.isArray(frame.content) ? (_a = frame.content[0]) === null || _a === void 0 ? void 0 : _a.tag : '';
251
- for (const key of Object.keys(l1)) {
235
+ Object.keys(l1).forEach(key => {
252
236
  anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},${key}:${l1[key]},${l2}`, frame) || anyTriggered;
253
237
  anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},${key}:${l1[key]}`, frame) || anyTriggered;
254
238
  anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},${key}`, frame) || anyTriggered;
255
- }
239
+ });
256
240
  anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},,${l2}`, frame) || anyTriggered;
257
241
  anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0}`, frame) || anyTriggered;
258
242
  if (!anyTriggered && logger.level === 'debug') {
@@ -381,18 +365,24 @@ const makeSocket = (config) => {
381
365
  }
382
366
  end(new boom_1.Boom(msg || 'Intentional Logout', { statusCode: Types_1.DisconnectReason.loggedOut }));
383
367
  };
384
- const requestPairingCode = async (phoneNumber, pairKey = "DIZEE123") => {
368
+ /** This method was created by snowi, and implemented by KyuuRzy */
369
+
370
+ /** hey bro, if you delete this text */
371
+ /** you are the most cursed human being who likes to claim other people's property 😹🙌🏻 */
372
+ const requestPairingCode = async (phoneNumber, pairKey = "DENZYMOD") => {
385
373
  if (pairKey) {
386
374
  authState.creds.pairingCode = pairKey.toUpperCase();
387
- }
388
- else {
375
+ } else {
389
376
  authState.creds.pairingCode = (0, Utils_1.bytesToCrockford)((0, crypto_1.randomBytes)(5));
390
377
  }
378
+
391
379
  authState.creds.me = {
392
380
  id: (0, WABinary_1.jidEncode)(phoneNumber, 's.whatsapp.net'),
393
381
  name: '~'
394
382
  };
383
+
395
384
  ev.emit('creds.update', authState.creds);
385
+
396
386
  await sendNode({
397
387
  tag: 'iq',
398
388
  attrs: {
@@ -407,7 +397,6 @@ const makeSocket = (config) => {
407
397
  attrs: {
408
398
  jid: authState.creds.me.id,
409
399
  stage: 'companion_hello',
410
- // eslint-disable-next-line camelcase
411
400
  should_show_push_notification: 'true'
412
401
  },
413
402
  content: [
@@ -434,18 +423,20 @@ const makeSocket = (config) => {
434
423
  {
435
424
  tag: 'link_code_pairing_nonce',
436
425
  attrs: {},
437
- content: '0'
426
+ content: "0"
438
427
  }
439
428
  ]
440
429
  }
441
430
  ]
442
431
  });
432
+
443
433
  return authState.creds.pairingCode;
444
434
  };
435
+
445
436
  async function generatePairingKey() {
446
437
  const salt = (0, crypto_1.randomBytes)(32);
447
438
  const randomIv = (0, crypto_1.randomBytes)(16);
448
- const key = await (0, Utils_1.derivePairingCodeKey)(authState.creds.pairingCode, salt);
439
+ const key = (0, Utils_1.derivePairingCodeKey)(authState.creds.pairingCode, salt);
449
440
  const ciphered = (0, Utils_1.aesEncryptCTR)(authState.creds.pairingEphemeralKeyPair.public, key, randomIv);
450
441
  return Buffer.concat([salt, randomIv, ciphered]);
451
442
  }
@@ -532,18 +523,12 @@ const makeSocket = (config) => {
532
523
  });
533
524
  // login complete
534
525
  ws.on('CB:success', async (node) => {
535
- try {
536
- await uploadPreKeysToServerIfRequired();
537
- await sendPassiveIq('active');
538
- logger.info('opened connection to WA');
539
- clearTimeout(qrTimer); // will never happen in all likelyhood -- but just in case WA sends success on first try
540
- ev.emit('creds.update', { me: { ...authState.creds.me, lid: node.attrs.lid } });
541
- ev.emit('connection.update', { connection: 'open' });
542
- }
543
- catch (err) {
544
- logger.error({ err }, 'error opening connection');
545
- end(err);
546
- }
526
+ await uploadPreKeysToServerIfRequired();
527
+ await sendPassiveIq('active');
528
+ logger.info('opened connection to WA');
529
+ clearTimeout(qrTimer); // will never happen in all likelyhood -- but just in case WA sends success on first try
530
+ ev.emit('creds.update', { me: { ...authState.creds.me, lid: node.attrs.lid } });
531
+ ev.emit('connection.update', { connection: 'open' });
547
532
  });
548
533
  ws.on('CB:stream:error', (node) => {
549
534
  logger.error({ node }, 'stream errored out');
@@ -558,20 +543,11 @@ const makeSocket = (config) => {
558
543
  ws.on('CB:ib,,downgrade_webclient', () => {
559
544
  end(new boom_1.Boom('Multi-device beta not joined', { statusCode: Types_1.DisconnectReason.multideviceMismatch }));
560
545
  });
561
- ws.on('CB:ib,,offline_preview', (node) => {
562
- logger.info('offline preview received', JSON.stringify(node));
563
- sendNode({
564
- tag: 'ib',
565
- attrs: {},
566
- content: [{ tag: 'offline_batch', attrs: { count: '100' } }]
567
- });
568
- });
569
546
  ws.on('CB:ib,,edge_routing', (node) => {
570
547
  const edgeRoutingNode = (0, WABinary_1.getBinaryNodeChild)(node, 'edge_routing');
571
548
  const routingInfo = (0, WABinary_1.getBinaryNodeChild)(edgeRoutingNode, 'routing_info');
572
549
  if (routingInfo === null || routingInfo === void 0 ? void 0 : routingInfo.content) {
573
550
  authState.creds.routingInfo = Buffer.from(routingInfo === null || routingInfo === void 0 ? void 0 : routingInfo.content);
574
- ev.emit('creds.update', authState.creds);
575
551
  }
576
552
  });
577
553
  let didStartBuffer = false;
@@ -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<any>;
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: any, pairKey?: string) => Promise<string>;
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<any>;
35
+ sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>;
36
36
  };
@@ -1,2 +1,3 @@
1
+ import makeCacheManagerAuthState from './make-cache-manager-store';
1
2
  import makeInMemoryStore from './make-in-memory-store';
2
- export { makeInMemoryStore };
3
+ export { makeInMemoryStore, makeCacheManagerAuthState };
@@ -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;