jagproject 26.3.22 → 26.3.25

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 (206) hide show
  1. package/WAProto/GenerateStatics.sh +3 -4
  2. package/WAProto/WAProto.proto +1215 -511
  3. package/WAProto/fix-imports.js +73 -0
  4. package/WAProto/index.d.ts +14017 -0
  5. package/WAProto/index.js +64857 -145167
  6. package/engine-requirements.js +4 -7
  7. package/lib/Defaults/index.d.ts +74 -0
  8. package/lib/Defaults/index.js +51 -33
  9. package/lib/Defaults/phonenumber-mcc.json +223 -0
  10. package/lib/Defaults/wileys-version.json +2 -2
  11. package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
  12. package/lib/Signal/Group/group-session-builder.d.ts +15 -0
  13. package/lib/Signal/Group/group-session-builder.js +5 -3
  14. package/lib/Signal/Group/group_cipher.d.ts +17 -0
  15. package/lib/Signal/Group/group_cipher.js +35 -46
  16. package/lib/Signal/Group/index.d.ts +12 -0
  17. package/lib/Signal/Group/index.js +21 -21
  18. package/lib/Signal/Group/keyhelper.d.ts +11 -0
  19. package/lib/Signal/Group/keyhelper.js +2 -2
  20. package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
  21. package/lib/Signal/Group/sender-chain-key.js +5 -10
  22. package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
  23. package/lib/Signal/Group/sender-key-distribution-message.js +7 -7
  24. package/lib/Signal/Group/sender-key-message.d.ts +19 -0
  25. package/lib/Signal/Group/sender-key-message.js +8 -8
  26. package/lib/Signal/Group/sender-key-name.d.ts +18 -0
  27. package/lib/Signal/Group/sender-key-record.d.ts +31 -0
  28. package/lib/Signal/Group/sender-key-record.js +7 -16
  29. package/lib/Signal/Group/sender-key-state.d.ts +39 -0
  30. package/lib/Signal/Group/sender-key-state.js +25 -37
  31. package/lib/Signal/Group/sender-message-key.d.ts +12 -0
  32. package/lib/Signal/Group/sender-message-key.js +2 -2
  33. package/lib/Signal/libsignal.d.ts +5 -0
  34. package/lib/Signal/libsignal.js +358 -54
  35. package/lib/Signal/lid-mapping.d.ts +19 -0
  36. package/lib/Signal/lid-mapping.js +274 -0
  37. package/lib/Socket/Client/index.d.ts +3 -0
  38. package/lib/Socket/Client/index.js +2 -2
  39. package/lib/Socket/Client/types.d.ts +16 -0
  40. package/lib/Socket/Client/types.js +1 -0
  41. package/lib/Socket/Client/websocket.d.ts +13 -0
  42. package/lib/Socket/Client/websocket.js +18 -30
  43. package/lib/Socket/business.d.ts +202 -0
  44. package/lib/Socket/business.js +160 -38
  45. package/lib/Socket/chats.d.ts +111 -0
  46. package/lib/Socket/chats.js +497 -314
  47. package/lib/Socket/communities.d.ts +258 -0
  48. package/lib/Socket/communities.js +438 -0
  49. package/lib/Socket/community.js +333 -0
  50. package/lib/Socket/groups.d.ts +150 -0
  51. package/lib/Socket/groups.js +229 -91
  52. package/lib/Socket/index.d.ts +245 -0
  53. package/lib/Socket/index.js +9 -6
  54. package/lib/Socket/messages-recv.d.ts +187 -0
  55. package/lib/Socket/messages-recv.js +1105 -501
  56. package/lib/Socket/messages-send.d.ts +183 -0
  57. package/lib/Socket/messages-send.js +1184 -501
  58. package/lib/Socket/mex.d.ts +3 -0
  59. package/lib/Socket/mex.js +45 -0
  60. package/lib/Socket/newsletter.d.ts +160 -0
  61. package/lib/Socket/newsletter.js +227 -200
  62. package/lib/Socket/socket.d.ts +55 -0
  63. package/lib/Socket/socket.js +507 -206
  64. package/lib/Socket/usync.js +6 -6
  65. package/lib/Store/index.js +17 -5
  66. package/lib/Store/make-cache-manager-store.js +83 -0
  67. package/lib/Store/make-in-memory-store.js +48 -89
  68. package/lib/Store/make-ordered-dictionary.js +1 -1
  69. package/lib/Types/Auth.d.ts +116 -0
  70. package/lib/Types/Bussines.d.ts +25 -0
  71. package/lib/Types/Bussines.js +2 -0
  72. package/lib/Types/Call.d.ts +15 -0
  73. package/lib/Types/Chat.d.ts +123 -0
  74. package/lib/Types/Chat.js +7 -1
  75. package/lib/Types/Contact.d.ts +24 -0
  76. package/lib/Types/Events.d.ts +237 -0
  77. package/lib/Types/Events.js +1 -0
  78. package/lib/Types/GroupMetadata.d.ts +67 -0
  79. package/lib/Types/Label.d.ts +47 -0
  80. package/lib/Types/Label.js +1 -3
  81. package/lib/Types/LabelAssociation.d.ts +30 -0
  82. package/lib/Types/LabelAssociation.js +1 -3
  83. package/lib/Types/Message.d.ts +305 -0
  84. package/lib/Types/Message.js +9 -5
  85. package/lib/Types/MexUpdates.js +11 -0
  86. package/lib/Types/Newsletter.d.ts +135 -0
  87. package/lib/Types/Newsletter.js +36 -11
  88. package/lib/Types/Product.d.ts +79 -0
  89. package/lib/Types/Signal.d.ts +76 -0
  90. package/lib/Types/Signal.js +1 -0
  91. package/lib/Types/Socket.d.ts +133 -0
  92. package/lib/Types/Socket.js +1 -0
  93. package/lib/Types/State.d.ts +39 -0
  94. package/lib/Types/State.js +12 -0
  95. package/lib/Types/USync.d.ts +26 -0
  96. package/lib/Types/USync.js +1 -0
  97. package/lib/Types/index.d.ts +65 -0
  98. package/lib/Types/index.js +14 -14
  99. package/lib/Utils/audioToBuffer.js +31 -0
  100. package/lib/Utils/auth-utils.d.ts +19 -0
  101. package/lib/Utils/auth-utils.js +222 -123
  102. package/lib/Utils/baileys-event-stream.js +60 -0
  103. package/lib/Utils/browser-utils.d.ts +4 -0
  104. package/lib/Utils/browser-utils.js +38 -29
  105. package/lib/Utils/business.d.ts +23 -0
  106. package/lib/Utils/business.js +54 -48
  107. package/lib/Utils/chat-utils.d.ts +70 -0
  108. package/lib/Utils/chat-utils.js +284 -189
  109. package/lib/Utils/crypto.d.ts +37 -0
  110. package/lib/Utils/crypto.js +16 -41
  111. package/lib/Utils/decode-wa-message.d.ts +48 -0
  112. package/lib/Utils/decode-wa-message.js +128 -48
  113. package/lib/Utils/event-buffer.d.ts +34 -0
  114. package/lib/Utils/event-buffer.js +124 -62
  115. package/lib/Utils/generics.d.ts +91 -0
  116. package/lib/Utils/generics.js +154 -138
  117. package/lib/Utils/history.d.ts +22 -0
  118. package/lib/Utils/history.js +77 -34
  119. package/lib/Utils/identity-change-handler.d.ts +37 -0
  120. package/lib/Utils/identity-change-handler.js +54 -0
  121. package/lib/Utils/index.d.ts +22 -0
  122. package/lib/Utils/index.js +32 -19
  123. package/lib/Utils/link-preview.d.ts +21 -0
  124. package/lib/Utils/link-preview.js +12 -17
  125. package/lib/Utils/logger.d.ts +13 -0
  126. package/lib/Utils/lt-hash.d.ts +8 -0
  127. package/lib/Utils/lt-hash.js +2 -43
  128. package/lib/Utils/make-mutex.d.ts +9 -0
  129. package/lib/Utils/make-mutex.js +21 -27
  130. package/lib/Utils/message-retry-manager.d.ts +110 -0
  131. package/lib/Utils/message-retry-manager.js +143 -45
  132. package/lib/Utils/messages-media.d.ts +130 -0
  133. package/lib/Utils/messages-media.js +429 -502
  134. package/lib/Utils/messages-newsletter.d.ts +84 -0
  135. package/lib/Utils/messages-newsletter.js +295 -0
  136. package/lib/Utils/messages.d.ts +92 -0
  137. package/lib/Utils/messages.js +1099 -400
  138. package/lib/Utils/noise-handler.d.ts +20 -0
  139. package/lib/Utils/noise-handler.js +145 -91
  140. package/lib/Utils/pre-key-manager.d.ts +28 -0
  141. package/lib/Utils/pre-key-manager.js +112 -0
  142. package/lib/Utils/process-message.d.ts +60 -0
  143. package/lib/Utils/process-message.js +316 -184
  144. package/lib/Utils/reporting-utils.d.ts +11 -0
  145. package/lib/Utils/reporting-utils.js +262 -0
  146. package/lib/Utils/resolve-jid.d.ts +43 -0
  147. package/lib/Utils/resolve-jid.js +95 -0
  148. package/lib/Utils/serial-task-queue.js +29 -0
  149. package/lib/Utils/signal.d.ts +34 -0
  150. package/lib/Utils/signal.js +56 -39
  151. package/lib/Utils/streamToBuffer.js +17 -0
  152. package/lib/Utils/sync-action-utils.d.ts +19 -0
  153. package/lib/Utils/sync-action-utils.js +52 -0
  154. package/lib/Utils/tc-token-utils.d.ts +12 -0
  155. package/lib/Utils/tc-token-utils.js +20 -0
  156. package/lib/Utils/use-mongo-file-auth-state.js +71 -0
  157. package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
  158. package/lib/Utils/use-multi-file-auth-state.js +11 -12
  159. package/lib/Utils/use-single-file-auth-state.js +73 -0
  160. package/lib/Utils/validate-connection.d.ts +11 -0
  161. package/lib/Utils/validate-connection.js +59 -82
  162. package/lib/Utils/wileys-event-stream.js +1 -61
  163. package/lib/WABinary/constants.d.ts +28 -0
  164. package/lib/WABinary/decode.d.ts +7 -0
  165. package/lib/WABinary/decode.js +39 -4
  166. package/lib/WABinary/encode.d.ts +3 -0
  167. package/lib/WABinary/encode.js +17 -11
  168. package/lib/WABinary/generic-utils.d.ts +15 -0
  169. package/lib/WABinary/generic-utils.js +46 -18
  170. package/lib/WABinary/index.d.ts +6 -0
  171. package/lib/WABinary/index.js +9 -5
  172. package/lib/WABinary/jid-utils.d.ts +48 -0
  173. package/lib/WABinary/jid-utils.js +67 -37
  174. package/lib/WABinary/types.d.ts +19 -0
  175. package/lib/WABinary/types.js +34 -0
  176. package/lib/WAM/BinaryInfo.d.ts +9 -0
  177. package/lib/WAM/constants.d.ts +40 -0
  178. package/lib/WAM/constants.js +19183 -11678
  179. package/lib/WAM/encode.d.ts +3 -0
  180. package/lib/WAM/encode.js +15 -17
  181. package/lib/WAM/index.d.ts +4 -0
  182. package/lib/WAM/index.js +3 -3
  183. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
  184. package/lib/WAUSync/Protocols/USyncContactProtocol.js +6 -6
  185. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
  186. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +9 -9
  187. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
  188. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +6 -6
  189. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
  190. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +7 -8
  191. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
  192. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +18 -17
  193. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
  194. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +11 -3
  195. package/lib/WAUSync/Protocols/index.d.ts +5 -0
  196. package/lib/WAUSync/Protocols/index.js +6 -4
  197. package/lib/WAUSync/USyncQuery.d.ts +29 -0
  198. package/lib/WAUSync/USyncQuery.js +38 -30
  199. package/lib/WAUSync/USyncUser.d.ts +13 -0
  200. package/lib/WAUSync/index.d.ts +4 -0
  201. package/lib/WAUSync/index.js +3 -3
  202. package/lib/index.d.ts +12 -0
  203. package/lib/index.js +3 -5
  204. package/package.json +10 -6
  205. package/readme.md +97 -0
  206. package/LICENSE +0 -21
@@ -0,0 +1,19 @@
1
+ import { proto } from '../../WAProto/index.js';
2
+ import type { BaileysEventEmitter, BaileysEventMap, Contact } from '../Types/index.js';
3
+ import type { ILogger } from './logger.js';
4
+ export type ContactsUpsertResult = {
5
+ event: 'contacts.upsert';
6
+ data: Contact[];
7
+ };
8
+ export type LidMappingUpdateResult = {
9
+ event: 'lid-mapping.update';
10
+ data: BaileysEventMap['lid-mapping.update'];
11
+ };
12
+ export type SyncActionResult = ContactsUpsertResult | LidMappingUpdateResult;
13
+ /**
14
+ * Process contactAction and return events to emit.
15
+ * Pure function - no side effects.
16
+ */
17
+ export declare const processContactAction: (action: proto.SyncActionValue.IContactAction, id: string | undefined, logger?: ILogger) => SyncActionResult[];
18
+ export declare const emitSyncActionResults: (ev: BaileysEventEmitter, results: SyncActionResult[]) => void;
19
+ //# sourceMappingURL=sync-action-utils.d.ts.map
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.emitSyncActionResults = exports.processContactAction = void 0;
4
+ const index_js_1 = require("../../WAProto/index.js");
5
+ const index_js_2 = require("../WABinary/index.js");
6
+ /**
7
+ * Process contactAction and return events to emit.
8
+ * Pure function - no side effects.
9
+ */
10
+ const processContactAction = (action, id, logger) => {
11
+ const results = [];
12
+ if (!id) {
13
+ logger?.warn({ hasFullName: !!action.fullName, hasLidJid: !!action.lidJid, hasPnJid: !!action.pnJid }, 'contactAction sync: missing id in index');
14
+ return results;
15
+ }
16
+ const lidJid = action.lidJid;
17
+ const idIsPn = (0, index_js_2.isPnUser)(id);
18
+ // PN is in index[1], not in contactAction.pnJid which is usually null
19
+ const phoneNumber = idIsPn ? id : action.pnJid || undefined;
20
+ // Always emit contacts.upsert
21
+ results.push({
22
+ event: 'contacts.upsert',
23
+ data: [
24
+ {
25
+ id,
26
+ name: action.fullName || action.firstName || action.username || undefined,
27
+ lid: lidJid || undefined,
28
+ phoneNumber
29
+ }
30
+ ]
31
+ });
32
+ // Emit lid-mapping.update if we have valid LID-PN pair
33
+ if (lidJid && (0, index_js_2.isLidUser)(lidJid) && idIsPn) {
34
+ results.push({
35
+ event: 'lid-mapping.update',
36
+ data: { lid: lidJid, pn: id }
37
+ });
38
+ }
39
+ return results;
40
+ };
41
+ exports.processContactAction = processContactAction;
42
+ const emitSyncActionResults = (ev, results) => {
43
+ for (const result of results) {
44
+ if (result.event === 'contacts.upsert') {
45
+ ev.emit('contacts.upsert', result.data);
46
+ }
47
+ else {
48
+ ev.emit('lid-mapping.update', result.data);
49
+ }
50
+ }
51
+ };
52
+ exports.emitSyncActionResults = emitSyncActionResults;
@@ -0,0 +1,12 @@
1
+ import type { SignalKeyStoreWithTransaction } from '../Types/index.js';
2
+ import type { BinaryNode } from '../WABinary/index.js';
3
+ type TcTokenParams = {
4
+ jid: string;
5
+ baseContent?: BinaryNode[];
6
+ authState: {
7
+ keys: SignalKeyStoreWithTransaction;
8
+ };
9
+ };
10
+ export declare function buildTcTokenFromJid({ authState, jid, baseContent }: TcTokenParams): Promise<BinaryNode[] | undefined>;
11
+ export {};
12
+ //# sourceMappingURL=tc-token-utils.d.ts.map
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildTcTokenFromJid = buildTcTokenFromJid;
4
+ async function buildTcTokenFromJid({ authState, jid, baseContent = [] }) {
5
+ try {
6
+ const tcTokenData = await authState.keys.get('tctoken', [jid]);
7
+ const tcTokenBuffer = tcTokenData?.[jid]?.token;
8
+ if (!tcTokenBuffer)
9
+ return baseContent.length > 0 ? baseContent : undefined;
10
+ baseContent.push({
11
+ tag: 'tctoken',
12
+ attrs: {},
13
+ content: tcTokenBuffer
14
+ });
15
+ return baseContent;
16
+ }
17
+ catch (error) {
18
+ return baseContent.length > 0 ? baseContent : undefined;
19
+ }
20
+ }
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useMongoFileAuthState = void 0;
4
+ const index_js_1 = require("../../WAProto/index.js");
5
+ const auth_utils_js_1 = require("./auth-utils.js");
6
+ const generics_js_1 = require("./generics.js");
7
+ /*
8
+ code from amiruldev readjusted by @irull2nd, don't delete WM!
9
+ */
10
+ const useMongoFileAuthState = async (collection) => {
11
+ const writeData = (data, id) => {
12
+ const informationToStore = JSON.parse(JSON.stringify(data, generics_js_1.BufferJSON.replacer));
13
+ const update = {
14
+ $set: {
15
+ ...informationToStore,
16
+ },
17
+ };
18
+ return collection.updateOne({ _id: id }, update, { upsert: true });
19
+ };
20
+ const readData = async (id) => {
21
+ try {
22
+ const data = JSON.stringify(await collection.findOne({ _id: id }));
23
+ return JSON.parse(data, generics_js_1.BufferJSON.reviver);
24
+ }
25
+ catch (err) {
26
+ console.log(err);
27
+ }
28
+ };
29
+ const removeData = async (id) => {
30
+ try {
31
+ await collection.deleteOne({ _id: id });
32
+ }
33
+ catch (err) {
34
+ console.log('error', err);
35
+ }
36
+ };
37
+ const creds = (await readData('creds')) || (0, auth_utils_js_1.initAuthCreds)();
38
+ return {
39
+ state: {
40
+ creds,
41
+ keys: {
42
+ get: async (type, ids) => {
43
+ const data = {};
44
+ await Promise.all(ids.map(async (id) => {
45
+ let value = await readData(`${type}-${id}`);
46
+ if (type === 'app-state-sync-key') {
47
+ value = index_js_1.proto.Message.AppStateSyncKeyData.fromObject(data);
48
+ }
49
+ data[id] = value;
50
+ }));
51
+ return data;
52
+ },
53
+ set: async (data) => {
54
+ const tasks = [];
55
+ for (const category of Object.keys(data)) {
56
+ for (const id of Object.keys(data[category])) {
57
+ const value = data[category][id];
58
+ const key = `${category}-${id}`;
59
+ tasks.push(value ? writeData(value, key) : removeData(key));
60
+ }
61
+ }
62
+ await Promise.all(tasks);
63
+ },
64
+ },
65
+ },
66
+ saveCreds: () => {
67
+ return writeData(creds, 'creds');
68
+ }
69
+ };
70
+ };
71
+ exports.useMongoFileAuthState = useMongoFileAuthState;
@@ -0,0 +1,13 @@
1
+ import type { AuthenticationState } from '../Types/index.js';
2
+ /**
3
+ * stores the full authentication state in a single folder.
4
+ * Far more efficient than singlefileauthstate
5
+ *
6
+ * Again, I wouldn't endorse this for any production level use other than perhaps a bot.
7
+ * Would recommend writing an auth state for use with a proper SQL or No-SQL DB
8
+ * */
9
+ export declare const useMultiFileAuthState: (folder: string) => Promise<{
10
+ state: AuthenticationState;
11
+ saveCreds: () => Promise<void>;
12
+ }>;
13
+ //# sourceMappingURL=use-multi-file-auth-state.d.ts.map
@@ -4,11 +4,11 @@ exports.useMultiFileAuthState = void 0;
4
4
  const async_mutex_1 = require("async-mutex");
5
5
  const promises_1 = require("fs/promises");
6
6
  const path_1 = require("path");
7
- const WAProto_1 = require("../../WAProto");
8
- const auth_utils_1 = require("./auth-utils");
9
- const generics_1 = require("./generics");
7
+ const index_js_1 = require("../../WAProto/index.js");
8
+ const auth_utils_js_1 = require("./auth-utils.js");
9
+ const generics_js_1 = require("./generics.js");
10
10
  // We need to lock files due to the fact that we are using async functions to read and write files
11
- // https://github.com/WhiskeySockets/Wileys/issues/794
11
+ // https://github.com/WhiskeySockets/Baileys/issues/794
12
12
  // https://github.com/nodejs/node/issues/26338
13
13
  // Use a Map to store mutexes for each file path
14
14
  const fileLocks = new Map();
@@ -35,7 +35,7 @@ const useMultiFileAuthState = async (folder) => {
35
35
  const mutex = getFileLock(filePath);
36
36
  return mutex.acquire().then(async (release) => {
37
37
  try {
38
- await (0, promises_1.writeFile)(filePath, JSON.stringify(data, generics_1.BufferJSON.replacer));
38
+ await (0, promises_1.writeFile)(filePath, JSON.stringify(data, generics_js_1.BufferJSON.replacer));
39
39
  }
40
40
  finally {
41
41
  release();
@@ -49,7 +49,7 @@ const useMultiFileAuthState = async (folder) => {
49
49
  return await mutex.acquire().then(async (release) => {
50
50
  try {
51
51
  const data = await (0, promises_1.readFile)(filePath, { encoding: 'utf-8' });
52
- return JSON.parse(data, generics_1.BufferJSON.reviver);
52
+ return JSON.parse(data, generics_js_1.BufferJSON.reviver);
53
53
  }
54
54
  finally {
55
55
  release();
@@ -68,15 +68,14 @@ const useMultiFileAuthState = async (folder) => {
68
68
  try {
69
69
  await (0, promises_1.unlink)(filePath);
70
70
  }
71
- catch (_a) {
71
+ catch {
72
72
  }
73
73
  finally {
74
74
  release();
75
75
  }
76
76
  });
77
77
  }
78
- catch (_a) {
79
- }
78
+ catch { }
80
79
  };
81
80
  const folderInfo = await (0, promises_1.stat)(folder).catch(() => { });
82
81
  if (folderInfo) {
@@ -87,8 +86,8 @@ const useMultiFileAuthState = async (folder) => {
87
86
  else {
88
87
  await (0, promises_1.mkdir)(folder, { recursive: true });
89
88
  }
90
- const fixFileName = (file) => { var _a; return (_a = file === null || file === void 0 ? void 0 : file.replace(/\//g, '__')) === null || _a === void 0 ? void 0 : _a.replace(/:/g, '-'); };
91
- const creds = await readData('creds.json') || (0, auth_utils_1.initAuthCreds)();
89
+ const fixFileName = (file) => file?.replace(/\//g, '__')?.replace(/:/g, '-');
90
+ const creds = (await readData('creds.json')) || (0, auth_utils_js_1.initAuthCreds)();
92
91
  return {
93
92
  state: {
94
93
  creds,
@@ -98,7 +97,7 @@ const useMultiFileAuthState = async (folder) => {
98
97
  await Promise.all(ids.map(async (id) => {
99
98
  let value = await readData(`${type}-${id}.json`);
100
99
  if (type === 'app-state-sync-key' && value) {
101
- value = WAProto_1.proto.Message.AppStateSyncKeyData.fromObject(value);
100
+ value = index_js_1.proto.Message.AppStateSyncKeyData.fromObject(value);
102
101
  }
103
102
  data[id] = value;
104
103
  }));
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useSingleFileAuthState = void 0;
4
+ const index_js_1 = require("../../WAProto/index.js");
5
+ const auth_utils_js_1 = require("./auth-utils.js");
6
+ const generics_js_1 = require("./generics.js");
7
+ // useless key map only there to maintain backwards compatibility
8
+ // do not use in your own systems please
9
+ const KEY_MAP = {
10
+ 'pre-key': 'preKeys',
11
+ 'session': 'sessions',
12
+ 'sender-key': 'senderKeys',
13
+ 'app-state-sync-key': 'appStateSyncKeys',
14
+ 'app-state-sync-version': 'appStateVersions',
15
+ 'sender-key-memory': 'senderKeyMemory'
16
+ };
17
+ /**
18
+ * @deprecated use multi file auth state instead please
19
+ * stores the full authentication state in a single JSON file
20
+ *
21
+ * DO NOT USE IN A PROD ENVIRONMENT, only meant to serve as an example
22
+ * */
23
+ const useSingleFileAuthState = (filename, logger) => {
24
+ const { readFileSync, writeFileSync, existsSync } = require('fs');
25
+ let creds;
26
+ let keys = {};
27
+ // save the authentication state to a file
28
+ const saveState = () => {
29
+ logger && logger.trace('saving auth state');
30
+ writeFileSync(filename,
31
+ // BufferJSON replacer utility saves buffers nicely
32
+ JSON.stringify({ creds, keys }, generics_js_1.BufferJSON.replacer, 2));
33
+ };
34
+ if (existsSync(filename)) {
35
+ const result = JSON.parse(readFileSync(filename, { encoding: 'utf-8' }), generics_js_1.BufferJSON.reviver);
36
+ creds = result.creds;
37
+ keys = result.keys;
38
+ }
39
+ else {
40
+ creds = (0, auth_utils_js_1.initAuthCreds)();
41
+ keys = {};
42
+ }
43
+ return {
44
+ state: {
45
+ creds,
46
+ keys: {
47
+ get: (type, ids) => {
48
+ const key = KEY_MAP[type];
49
+ return ids.reduce((dict, id) => {
50
+ let value = keys[key]?.[id];
51
+ if (value) {
52
+ if (type === 'app-state-sync-key') {
53
+ value = index_js_1.proto.Message.AppStateSyncKeyData.fromObject(value);
54
+ }
55
+ dict[id] = value;
56
+ }
57
+ return dict;
58
+ }, {});
59
+ },
60
+ set: (data) => {
61
+ for (const _key in data) {
62
+ const key = KEY_MAP[_key];
63
+ keys[key] = keys[key] || {};
64
+ Object.assign(keys[key], data[_key]);
65
+ }
66
+ saveState();
67
+ }
68
+ }
69
+ },
70
+ saveState
71
+ };
72
+ };
73
+ exports.useSingleFileAuthState = useSingleFileAuthState;
@@ -0,0 +1,11 @@
1
+ import { proto } from '../../WAProto/index.js';
2
+ import type { AuthenticationCreds, SignalCreds, SocketConfig } from '../Types/index.js';
3
+ import { type BinaryNode } from '../WABinary/index.js';
4
+ export declare const generateLoginNode: (userJid: string, config: SocketConfig) => proto.IClientPayload;
5
+ export declare const generateRegistrationNode: ({ registrationId, signedPreKey, signedIdentityKey }: SignalCreds, config: SocketConfig) => proto.ClientPayload;
6
+ export declare const configureSuccessfulPairing: (stanza: BinaryNode, { advSecretKey, signedIdentityKey, signalIdentities }: Pick<AuthenticationCreds, "advSecretKey" | "signedIdentityKey" | "signalIdentities">) => {
7
+ creds: Partial<AuthenticationCreds>;
8
+ reply: BinaryNode;
9
+ };
10
+ export declare const encodeSignedDeviceIdentity: (account: proto.IADVSignedDeviceIdentity, includeSignatureKey: boolean) => Uint8Array<ArrayBufferLike>;
11
+ //# sourceMappingURL=validate-connection.d.ts.map
@@ -3,79 +3,77 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.encodeSignedDeviceIdentity = exports.configureSuccessfulPairing = exports.generateRegistrationNode = exports.generateLoginNode = void 0;
4
4
  const boom_1 = require("@hapi/boom");
5
5
  const crypto_1 = require("crypto");
6
- const WAProto_1 = require("../../WAProto");
7
- const Defaults_1 = require("../Defaults");
8
- const WABinary_1 = require("../WABinary");
9
- const crypto_2 = require("./crypto");
10
- const generics_1 = require("./generics");
11
- const signal_1 = require("./signal");
12
-
6
+ const index_js_1 = require("../../WAProto/index.js");
7
+ const index_js_2 = require("../Defaults/index.js");
8
+ const index_js_3 = require("../WABinary/index.js");
9
+ const crypto_js_1 = require("./crypto.js");
10
+ const generics_js_1 = require("./generics.js");
11
+ const signal_js_1 = require("./signal.js");
13
12
  const getUserAgent = (config) => {
14
13
  return {
15
14
  appVersion: {
16
15
  primary: config.version[0],
17
16
  secondary: config.version[1],
18
- tertiary: config.version[2],
17
+ tertiary: config.version[2]
19
18
  },
20
- platform: WAProto_1.proto.ClientPayload.UserAgent.Platform.WEB,
21
- releaseChannel: WAProto_1.proto.ClientPayload.UserAgent.ReleaseChannel.RELEASE,
19
+ platform: index_js_1.proto.ClientPayload.UserAgent.Platform.WEB,
20
+ releaseChannel: index_js_1.proto.ClientPayload.UserAgent.ReleaseChannel.RELEASE,
22
21
  osVersion: '0.1',
23
22
  device: 'Desktop',
24
23
  osBuildNumber: '0.1',
25
24
  localeLanguageIso6391: 'en',
26
25
  mnc: '000',
27
26
  mcc: '000',
28
- localeCountryIso31661Alpha2: config.countryCode || 'US'
27
+ localeCountryIso31661Alpha2: config.countryCode
29
28
  };
30
29
  };
31
-
32
30
  const PLATFORM_MAP = {
33
- 'Mac OS': WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.DARWIN,
34
- 'Windows': WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.WIN32
31
+ 'Mac OS': index_js_1.proto.ClientPayload.WebInfo.WebSubPlatform.DARWIN,
32
+ Windows: index_js_1.proto.ClientPayload.WebInfo.WebSubPlatform.WIN32
35
33
  };
36
-
37
34
  const getWebInfo = (config) => {
38
- let webSubPlatform = WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.WEB_BROWSER;
39
- if (config.syncFullHistory && PLATFORM_MAP[config.browser[0]] && config.browser[1] === 'Desktop') {
35
+ let webSubPlatform = index_js_1.proto.ClientPayload.WebInfo.WebSubPlatform.WEB_BROWSER;
36
+ if (config.syncFullHistory &&
37
+ PLATFORM_MAP[config.browser[0]] &&
38
+ config.browser[1] === 'Desktop') {
40
39
  webSubPlatform = PLATFORM_MAP[config.browser[0]];
41
40
  }
42
41
  return { webSubPlatform };
43
42
  };
44
-
45
43
  const getClientPayload = (config) => {
46
44
  const payload = {
47
- connectType: WAProto_1.proto.ClientPayload.ConnectType.WIFI_UNKNOWN,
48
- connectReason: WAProto_1.proto.ClientPayload.ConnectReason.USER_ACTIVATED,
49
- userAgent: getUserAgent(config),
45
+ connectType: index_js_1.proto.ClientPayload.ConnectType.WIFI_UNKNOWN,
46
+ connectReason: index_js_1.proto.ClientPayload.ConnectReason.USER_ACTIVATED,
47
+ userAgent: getUserAgent(config)
50
48
  };
51
49
  payload.webInfo = getWebInfo(config);
52
50
  return payload;
53
51
  };
54
-
55
52
  const generateLoginNode = (userJid, config) => {
56
- const { user, device } = (0, WABinary_1.jidDecode)(userJid);
53
+ const { user, device } = (0, index_js_3.jidDecode)(userJid);
57
54
  const payload = {
58
55
  ...getClientPayload(config),
59
56
  passive: true,
60
57
  pull: true,
61
58
  username: +user,
62
59
  device: device,
60
+ // TODO: investigate (hard set as false atm)
63
61
  lidDbMigrated: false
64
62
  };
65
- return WAProto_1.proto.ClientPayload.fromObject(payload);
63
+ return index_js_1.proto.ClientPayload.fromObject(payload);
66
64
  };
67
65
  exports.generateLoginNode = generateLoginNode;
68
-
69
66
  const getPlatformType = (platform) => {
70
67
  const platformType = platform.toUpperCase();
71
- return WAProto_1.proto.DeviceProps.PlatformType[platformType] || WAProto_1.proto.DeviceProps.PlatformType.CHROME;
68
+ return (index_js_1.proto.DeviceProps.PlatformType[platformType] ||
69
+ index_js_1.proto.DeviceProps.PlatformType.CHROME);
72
70
  };
73
-
74
71
  const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentityKey }, config) => {
72
+ // the app version needs to be md5 hashed
73
+ // and passed in
75
74
  const appVersionBuf = (0, crypto_1.createHash)('md5')
76
- .update(config.version.join('.'))
75
+ .update(config.version.join('.')) // join as string
77
76
  .digest();
78
-
79
77
  const companion = {
80
78
  os: config.browser[0],
81
79
  platformType: getPlatformType(config.browser[1]),
@@ -103,9 +101,7 @@ const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentity
103
101
  tertiary: 7
104
102
  }
105
103
  };
106
-
107
- const companionProto = WAProto_1.proto.DeviceProps.encode(companion).finish();
108
-
104
+ const companionProto = index_js_1.proto.DeviceProps.encode(companion).finish();
109
105
  const registerPayload = {
110
106
  ...getClientPayload(config),
111
107
  passive: false,
@@ -113,77 +109,64 @@ const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentity
113
109
  devicePairingData: {
114
110
  buildHash: appVersionBuf,
115
111
  deviceProps: companionProto,
116
- eRegid: (0, generics_1.encodeBigEndian)(registrationId),
117
- eKeytype: Defaults_1.KEY_BUNDLE_TYPE,
112
+ eRegid: (0, generics_js_1.encodeBigEndian)(registrationId),
113
+ eKeytype: index_js_2.KEY_BUNDLE_TYPE,
118
114
  eIdent: signedIdentityKey.public,
119
- eSkeyId: (0, generics_1.encodeBigEndian)(signedPreKey.keyId, 3),
115
+ eSkeyId: (0, generics_js_1.encodeBigEndian)(signedPreKey.keyId, 3),
120
116
  eSkeyVal: signedPreKey.keyPair.public,
121
- eSkeySig: signedPreKey.signature,
122
- },
117
+ eSkeySig: signedPreKey.signature
118
+ }
123
119
  };
124
- return WAProto_1.proto.ClientPayload.fromObject(registerPayload);
120
+ return index_js_1.proto.ClientPayload.fromObject(registerPayload);
125
121
  };
126
122
  exports.generateRegistrationNode = generateRegistrationNode;
127
-
128
123
  const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, signalIdentities }) => {
129
124
  const msgId = stanza.attrs.id;
130
- const pairSuccessNode = (0, WABinary_1.getBinaryNodeChild)(stanza, 'pair-success');
131
- const deviceIdentityNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'device-identity');
132
- const platformNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'platform');
133
- const deviceNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'device');
134
- const businessNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'biz');
135
-
125
+ const pairSuccessNode = (0, index_js_3.getBinaryNodeChild)(stanza, 'pair-success');
126
+ const deviceIdentityNode = (0, index_js_3.getBinaryNodeChild)(pairSuccessNode, 'device-identity');
127
+ const platformNode = (0, index_js_3.getBinaryNodeChild)(pairSuccessNode, 'platform');
128
+ const deviceNode = (0, index_js_3.getBinaryNodeChild)(pairSuccessNode, 'device');
129
+ const businessNode = (0, index_js_3.getBinaryNodeChild)(pairSuccessNode, 'biz');
136
130
  if (!deviceIdentityNode || !deviceNode) {
137
131
  throw new boom_1.Boom('Missing device-identity or device in pair success node', { data: stanza });
138
132
  }
139
-
140
133
  const bizName = businessNode?.attrs.name;
141
134
  const jid = deviceNode.attrs.jid;
142
135
  const lid = deviceNode.attrs.lid;
143
-
144
- const { details, hmac, accountType } = WAProto_1.proto.ADVSignedDeviceIdentityHMAC.decode(deviceIdentityNode.content);
145
-
136
+ const { details, hmac, accountType } = index_js_1.proto.ADVSignedDeviceIdentityHMAC.decode(deviceIdentityNode.content);
146
137
  let hmacPrefix = Buffer.from([]);
147
- if (accountType !== undefined && accountType === WAProto_1.proto.ADVEncryptionType.HOSTED) {
148
- hmacPrefix = Buffer.from([0x06, 0x05]);
138
+ if (accountType !== undefined && accountType === index_js_1.proto.ADVEncryptionType.HOSTED) {
139
+ hmacPrefix = index_js_2.WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX;
149
140
  }
150
-
151
- const advSign = (0, crypto_2.hmacSign)(Buffer.concat([hmacPrefix, details]), Buffer.from(advSecretKey, 'base64'));
141
+ const advSign = (0, crypto_js_1.hmacSign)(Buffer.concat([hmacPrefix, details]), Buffer.from(advSecretKey, 'base64'));
152
142
  if (Buffer.compare(hmac, advSign) !== 0) {
153
143
  throw new boom_1.Boom('Invalid account signature');
154
144
  }
155
-
156
- const account = WAProto_1.proto.ADVSignedDeviceIdentity.decode(details);
145
+ const account = index_js_1.proto.ADVSignedDeviceIdentity.decode(details);
157
146
  const { accountSignatureKey, accountSignature, details: deviceDetails } = account;
158
-
159
- const deviceIdentity = WAProto_1.proto.ADVDeviceIdentity.decode(deviceDetails);
160
-
161
- const accountSignaturePrefix = deviceIdentity.deviceType === WAProto_1.proto.ADVEncryptionType.HOSTED
162
- ? Buffer.from([0x06, 0x05])
163
- : Buffer.from([0x06, 0x00]);
147
+ const deviceIdentity = index_js_1.proto.ADVDeviceIdentity.decode(deviceDetails);
148
+ const accountSignaturePrefix = deviceIdentity.deviceType === index_js_1.proto.ADVEncryptionType.HOSTED
149
+ ? index_js_2.WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX
150
+ : index_js_2.WA_ADV_ACCOUNT_SIG_PREFIX;
164
151
  const accountMsg = Buffer.concat([accountSignaturePrefix, deviceDetails, signedIdentityKey.public]);
165
-
166
- if (!crypto_2.Curve.verify(accountSignatureKey, accountMsg, accountSignature)) {
152
+ if (!crypto_js_1.Curve.verify(accountSignatureKey, accountMsg, accountSignature)) {
167
153
  throw new boom_1.Boom('Failed to verify account signature');
168
154
  }
169
-
170
155
  const deviceMsg = Buffer.concat([
171
- Buffer.from([0x06, 0x01]),
156
+ index_js_2.WA_ADV_DEVICE_SIG_PREFIX,
172
157
  deviceDetails,
173
158
  signedIdentityKey.public,
174
159
  accountSignatureKey
175
160
  ]);
176
- account.deviceSignature = crypto_2.Curve.sign(signedIdentityKey.private, deviceMsg);
177
-
178
- const identity = (0, signal_1.createSignalIdentity)(jid, accountSignatureKey);
161
+ account.deviceSignature = crypto_js_1.Curve.sign(signedIdentityKey.private, deviceMsg);
162
+ const identity = (0, signal_js_1.createSignalIdentity)(lid, accountSignatureKey);
179
163
  const accountEnc = (0, exports.encodeSignedDeviceIdentity)(account, false);
180
-
181
164
  const reply = {
182
165
  tag: 'iq',
183
166
  attrs: {
184
- to: WABinary_1.S_WHATSAPP_NET,
167
+ to: index_js_3.S_WHATSAPP_NET,
185
168
  type: 'result',
186
- id: msgId,
169
+ id: msgId
187
170
  },
188
171
  content: [
189
172
  {
@@ -199,31 +182,25 @@ const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, s
199
182
  }
200
183
  ]
201
184
  };
202
-
203
185
  const authUpdate = {
204
186
  account,
205
187
  me: { id: jid, name: bizName, lid },
206
- signalIdentities: [
207
- ...(signalIdentities || []),
208
- identity
209
- ],
188
+ signalIdentities: [...(signalIdentities || []), identity],
210
189
  platform: platformNode?.attrs.name
211
190
  };
212
-
213
191
  return {
214
192
  creds: authUpdate,
215
193
  reply
216
194
  };
217
195
  };
218
196
  exports.configureSuccessfulPairing = configureSuccessfulPairing;
219
-
220
197
  const encodeSignedDeviceIdentity = (account, includeSignatureKey) => {
221
198
  account = { ...account };
199
+ // set to null if we are not to include the signature key
200
+ // or if we are including the signature key but it is empty
222
201
  if (!includeSignatureKey || !account.accountSignatureKey?.length) {
223
202
  account.accountSignatureKey = null;
224
203
  }
225
- return WAProto_1.proto.ADVSignedDeviceIdentity
226
- .encode(account)
227
- .finish();
204
+ return index_js_1.proto.ADVSignedDeviceIdentity.encode(account).finish();
228
205
  };
229
- exports.encodeSignedDeviceIdentity = encodeSignedDeviceIdentity;
206
+ exports.encodeSignedDeviceIdentity = encodeSignedDeviceIdentity;