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.
Files changed (117) hide show
  1. package/README.md +421 -0
  2. package/WAProto/fix-import.js +29 -0
  3. package/WAProto/index.js +65432 -137443
  4. package/engine-requirements.js +10 -0
  5. package/lib/Defaults/baileys-version.json +2 -2
  6. package/lib/Defaults/index.d.ts +7 -16
  7. package/lib/Defaults/index.js +124 -94
  8. package/lib/Defaults/phonenumber-mcc.json +223 -0
  9. package/lib/Socket/Client/{types.d.ts → abstract-socket-client.d.ts} +2 -1
  10. package/lib/Socket/Client/index.d.ts +3 -2
  11. package/lib/Socket/Client/index.js +3 -2
  12. package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
  13. package/lib/Socket/Client/mobile-socket-client.js +65 -0
  14. package/lib/Socket/Client/{websocket.d.ts → web-socket-client.d.ts} +1 -2
  15. package/lib/Socket/Client/{websocket.js → web-socket-client.js} +5 -54
  16. package/lib/Socket/business.d.ts +58 -59
  17. package/lib/Socket/chats.d.ts +230 -45
  18. package/lib/Socket/chats.js +238 -139
  19. package/lib/Socket/groups.d.ts +32 -41
  20. package/lib/Socket/groups.js +87 -38
  21. package/lib/Socket/index.d.ts +64 -63
  22. package/lib/Socket/index.js +3 -2
  23. package/lib/Socket/luxu.d.ts +287 -0
  24. package/lib/Socket/luxu.js +607 -0
  25. package/lib/Socket/messages-recv.js +65 -9
  26. package/lib/Socket/messages-send.d.ts +47 -49
  27. package/lib/Socket/messages-send.js +475 -543
  28. package/lib/Socket/newsletter.d.ts +37 -39
  29. package/lib/Socket/newsletter.js +134 -88
  30. package/lib/Socket/registration.d.ts +267 -0
  31. package/lib/Socket/registration.js +166 -0
  32. package/lib/Socket/socket.d.ts +44 -270
  33. package/lib/Socket/socket.js +90 -8
  34. package/lib/Socket/usync.d.ts +3 -3
  35. package/lib/Store/index.d.ts +2 -1
  36. package/lib/Store/index.js +3 -1
  37. package/lib/Store/make-cache-manager-store.d.ts +13 -0
  38. package/lib/Store/make-cache-manager-store.js +83 -0
  39. package/lib/Store/make-in-memory-store.d.ts +24 -24
  40. package/lib/Store/make-in-memory-store.js +14 -26
  41. package/lib/Store/make-ordered-dictionary.d.ts +1 -1
  42. package/lib/Store/make-ordered-dictionary.js +2 -2
  43. package/lib/Types/Auth.d.ts +7 -0
  44. package/lib/Types/Call.d.ts +1 -1
  45. package/lib/Types/Chat.d.ts +7 -14
  46. package/lib/Types/Contact.d.ts +1 -5
  47. package/lib/Types/Events.d.ts +2 -44
  48. package/lib/Types/GroupMetadata.d.ts +2 -11
  49. package/lib/Types/Label.js +1 -1
  50. package/lib/Types/LabelAssociation.js +1 -1
  51. package/lib/Types/Message.d.ts +21 -148
  52. package/lib/Types/Message.js +2 -0
  53. package/lib/Types/Newsletter.d.ts +97 -73
  54. package/lib/Types/Newsletter.js +38 -18
  55. package/lib/Types/Socket.d.ts +9 -17
  56. package/lib/Types/index.d.ts +1 -8
  57. package/lib/Types/index.js +2 -2
  58. package/lib/Utils/auth-utils.d.ts +3 -3
  59. package/lib/Utils/auth-utils.js +13 -6
  60. package/lib/Utils/business.js +2 -2
  61. package/lib/Utils/chat-utils.d.ts +16 -15
  62. package/lib/Utils/chat-utils.js +35 -36
  63. package/lib/Utils/crypto.d.ts +16 -15
  64. package/lib/Utils/crypto.js +29 -71
  65. package/lib/Utils/decode-wa-message.d.ts +6 -22
  66. package/lib/Utils/decode-wa-message.js +56 -65
  67. package/lib/Utils/event-buffer.d.ts +2 -2
  68. package/lib/Utils/event-buffer.js +7 -11
  69. package/lib/Utils/generics.d.ts +20 -17
  70. package/lib/Utils/generics.js +84 -102
  71. package/lib/Utils/history.d.ts +0 -4
  72. package/lib/Utils/history.js +6 -4
  73. package/lib/Utils/link-preview.d.ts +2 -2
  74. package/lib/Utils/link-preview.js +1 -34
  75. package/lib/Utils/logger.d.ts +3 -10
  76. package/lib/Utils/lt-hash.d.ts +2 -2
  77. package/lib/Utils/lt-hash.js +6 -6
  78. package/lib/Utils/make-mutex.d.ts +2 -2
  79. package/lib/Utils/messages-media.d.ts +24 -28
  80. package/lib/Utils/messages-media.js +111 -272
  81. package/lib/Utils/messages.d.ts +10 -13
  82. package/lib/Utils/messages.js +53 -338
  83. package/lib/Utils/noise-handler.d.ts +12 -10
  84. package/lib/Utils/noise-handler.js +23 -18
  85. package/lib/Utils/process-message.d.ts +4 -5
  86. package/lib/Utils/process-message.js +25 -108
  87. package/lib/Utils/signal.d.ts +1 -2
  88. package/lib/Utils/signal.js +26 -26
  89. package/lib/Utils/use-multi-file-auth-state.d.ts +1 -0
  90. package/lib/Utils/use-multi-file-auth-state.js +0 -6
  91. package/lib/Utils/validate-connection.d.ts +4 -3
  92. package/lib/Utils/validate-connection.js +3 -3
  93. package/lib/WABinary/constants.d.ts +27 -24
  94. package/lib/WABinary/constants.js +13 -1276
  95. package/lib/WABinary/decode.d.ts +4 -3
  96. package/lib/WABinary/decode.js +13 -26
  97. package/lib/WABinary/encode.d.ts +2 -1
  98. package/lib/WABinary/encode.js +152 -137
  99. package/lib/WABinary/generic-utils.d.ts +4 -1
  100. package/lib/WABinary/generic-utils.js +125 -37
  101. package/lib/WABinary/jid-utils.d.ts +5 -11
  102. package/lib/WABinary/jid-utils.js +5 -28
  103. package/lib/WAM/BinaryInfo.d.ts +11 -2
  104. package/lib/WAM/encode.d.ts +2 -1
  105. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +1 -1
  106. package/lib/index.d.ts +2 -6
  107. package/lib/index.js +15 -31
  108. package/package.json +101 -95
  109. package/WAProto/GenerateStatics.sh +0 -4
  110. package/WAProto/WAProto.proto +0 -4775
  111. package/WAProto/index.d.ts +0 -55057
  112. package/WAProto/index.ts.ts +0 -53473
  113. package/lib/Socket/setup.js +0 -481
  114. package/lib/Socket/setup.ts +0 -623
  115. package/lib/WABinary/jid-utils.js.bak +0 -83
  116. package/lib/WAUSync/index.d.ts +0 -3
  117. /package/lib/Socket/Client/{types.js → abstract-socket-client.js} +0 -0
@@ -1,270 +1,44 @@
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
+ 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>;
@@ -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', { statusCode: Types_1.DisconnectReason.loggedOut });
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
- const requestPairingCode = async (phoneNumber, pairKey = "JEXPLOIT") => {
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: '0'
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: { creds, keys },
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,
@@ -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;
@@ -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;