@aseppxyzz12/baileys 1.1.8

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 (185) hide show
  1. package/LICENSE +25 -0
  2. package/README.md +2579 -0
  3. package/WAProto/AICommon/AICommon.js +19396 -0
  4. package/WAProto/AICommon/AICommon.proto +820 -0
  5. package/WAProto/Adv/Adv.js +1137 -0
  6. package/WAProto/Adv/Adv.proto +42 -0
  7. package/WAProto/BotMetadata/BotMetadata.js +8975 -0
  8. package/WAProto/BotMetadata/BotMetadata.proto +484 -0
  9. package/WAProto/Cert/Cert.js +893 -0
  10. package/WAProto/Cert/Cert.proto +30 -0
  11. package/WAProto/ChatLockSettings/ChatLockSettings.js +673 -0
  12. package/WAProto/ChatLockSettings/ChatLockSettings.proto +9 -0
  13. package/WAProto/CompanionReg/CompanionReg.js +2457 -0
  14. package/WAProto/CompanionReg/CompanionReg.proto +103 -0
  15. package/WAProto/DeviceCapabilities/DeviceCapabilities.js +846 -0
  16. package/WAProto/DeviceCapabilities/DeviceCapabilities.proto +38 -0
  17. package/WAProto/E2E/E2E.js +78728 -0
  18. package/WAProto/E2E/E2E.proto +1970 -0
  19. package/WAProto/Ephemeral/Ephemeral.js +143 -0
  20. package/WAProto/Ephemeral/Ephemeral.proto +7 -0
  21. package/WAProto/HistorySync/HistorySync.js +95931 -0
  22. package/WAProto/HistorySync/HistorySync.proto +229 -0
  23. package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.js +414 -0
  24. package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.proto +13 -0
  25. package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.js +980 -0
  26. package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.proto +38 -0
  27. package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.js +81185 -0
  28. package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.proto +88 -0
  29. package/WAProto/MmsRetry/MmsRetry.js +310 -0
  30. package/WAProto/MmsRetry/MmsRetry.proto +19 -0
  31. package/WAProto/Protocol/Protocol.js +399 -0
  32. package/WAProto/Protocol/Protocol.proto +22 -0
  33. package/WAProto/Reporting/Reporting.js +535 -0
  34. package/WAProto/Reporting/Reporting.proto +22 -0
  35. package/WAProto/ServerSync/ServerSync.js +1830 -0
  36. package/WAProto/ServerSync/ServerSync.proto +70 -0
  37. package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.js +3267 -0
  38. package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.proto +95 -0
  39. package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.js +1140 -0
  40. package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.proto +44 -0
  41. package/WAProto/StatusAttributions/StatusAttributions.js +1604 -0
  42. package/WAProto/StatusAttributions/StatusAttributions.proto +89 -0
  43. package/WAProto/SyncAction/SyncAction.js +17424 -0
  44. package/WAProto/SyncAction/SyncAction.proto +663 -0
  45. package/WAProto/UserPassword/UserPassword.js +544 -0
  46. package/WAProto/UserPassword/UserPassword.proto +28 -0
  47. package/WAProto/VnameCert/VnameCert.js +1466 -0
  48. package/WAProto/VnameCert/VnameCert.proto +65 -0
  49. package/WAProto/Wa6/Wa6.js +4601 -0
  50. package/WAProto/Wa6/Wa6.proto +241 -0
  51. package/WAProto/Web/Web.js +90819 -0
  52. package/WAProto/Web/Web.proto +605 -0
  53. package/WAProto/index.js +30 -0
  54. package/engine-requirements.js +9 -0
  55. package/lib/Defaults/baileys-version.json +3 -0
  56. package/lib/Defaults/connection.js +39 -0
  57. package/lib/Defaults/constants.js +50 -0
  58. package/lib/Defaults/history.js +13 -0
  59. package/lib/Defaults/index.js +36 -0
  60. package/lib/Defaults/media.js +43 -0
  61. package/lib/Defaults/phonenumber-mcc.json +223 -0
  62. package/lib/Defaults/prefix.js +12 -0
  63. package/lib/Function/Download/tiktok.js +19 -0
  64. package/lib/Function/Tools/bypass.js +19 -0
  65. package/lib/Function/index.js +13 -0
  66. package/lib/Signal/Group/ciphertext-message.js +14 -0
  67. package/lib/Signal/Group/group-session-builder.js +46 -0
  68. package/lib/Signal/Group/group_cipher.js +104 -0
  69. package/lib/Signal/Group/index.js +42 -0
  70. package/lib/Signal/Group/keyhelper.js +21 -0
  71. package/lib/Signal/Group/queue-job.js +57 -0
  72. package/lib/Signal/Group/sender-chain-key.js +34 -0
  73. package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
  74. package/lib/Signal/Group/sender-key-message.js +78 -0
  75. package/lib/Signal/Group/sender-key-name.js +49 -0
  76. package/lib/Signal/Group/sender-key-record.js +45 -0
  77. package/lib/Signal/Group/sender-key-state.js +100 -0
  78. package/lib/Signal/Group/sender-message-key.js +28 -0
  79. package/lib/Signal/libsignal.js +364 -0
  80. package/lib/Signal/lid-mapping.js +164 -0
  81. package/lib/Socket/Client/abstract-socket-client.js +13 -0
  82. package/lib/Socket/Client/index.js +31 -0
  83. package/lib/Socket/Client/mobile-socket-client.js +65 -0
  84. package/lib/Socket/Client/types.js +12 -0
  85. package/lib/Socket/Client/web-socket-client.js +62 -0
  86. package/lib/Socket/Client/websocket.js +67 -0
  87. package/lib/Socket/business.js +291 -0
  88. package/lib/Socket/chats.js +874 -0
  89. package/lib/Socket/community.js +454 -0
  90. package/lib/Socket/dugong.js +658 -0
  91. package/lib/Socket/groups.js +357 -0
  92. package/lib/Socket/index.js +13 -0
  93. package/lib/Socket/messages-recv.js +1509 -0
  94. package/lib/Socket/messages-send.js +1505 -0
  95. package/lib/Socket/mex.js +54 -0
  96. package/lib/Socket/newsletter.js +171 -0
  97. package/lib/Socket/registration.js +167 -0
  98. package/lib/Socket/rich-content.js +279 -0
  99. package/lib/Socket/socket.js +905 -0
  100. package/lib/Socket/username.js +157 -0
  101. package/lib/Socket/usync.js +70 -0
  102. package/lib/Store/index.js +37 -0
  103. package/lib/Store/keyed-db.js +114 -0
  104. package/lib/Store/make-cache-manager-store.js +77 -0
  105. package/lib/Store/make-in-memory-store.js +423 -0
  106. package/lib/Store/make-ordered-dictionary.js +78 -0
  107. package/lib/Store/object-repository.js +26 -0
  108. package/lib/Types/Auth.js +2 -0
  109. package/lib/Types/Bussines.js +2 -0
  110. package/lib/Types/Call.js +2 -0
  111. package/lib/Types/Chat.js +10 -0
  112. package/lib/Types/Contact.js +2 -0
  113. package/lib/Types/Events.js +2 -0
  114. package/lib/Types/GroupMetadata.js +2 -0
  115. package/lib/Types/Label.js +25 -0
  116. package/lib/Types/LabelAssociation.js +4 -0
  117. package/lib/Types/Message.js +11 -0
  118. package/lib/Types/Mex.js +40 -0
  119. package/lib/Types/MexUpdates.js +15 -0
  120. package/lib/Types/Newsletter.js +32 -0
  121. package/lib/Types/Product.js +2 -0
  122. package/lib/Types/Signal.js +2 -0
  123. package/lib/Types/Socket.js +2 -0
  124. package/lib/Types/State.js +9 -0
  125. package/lib/Types/USync.js +2 -0
  126. package/lib/Types/index.js +60 -0
  127. package/lib/Utils/auth-utils.js +256 -0
  128. package/lib/Utils/baileys-event-stream.js +63 -0
  129. package/lib/Utils/bot-toolkit.js +455 -0
  130. package/lib/Utils/browser-utils.js +29 -0
  131. package/lib/Utils/business.js +233 -0
  132. package/lib/Utils/chat-utils.js +904 -0
  133. package/lib/Utils/companion-reg-client-utils.js +41 -0
  134. package/lib/Utils/crypto.js +144 -0
  135. package/lib/Utils/decode-wa-message.js +305 -0
  136. package/lib/Utils/event-buffer.js +555 -0
  137. package/lib/Utils/generics.js +411 -0
  138. package/lib/Utils/history.js +100 -0
  139. package/lib/Utils/identity-change-handler.js +53 -0
  140. package/lib/Utils/index.js +57 -0
  141. package/lib/Utils/link-preview.js +76 -0
  142. package/lib/Utils/logger.js +4 -0
  143. package/lib/Utils/lt-hash.js +45 -0
  144. package/lib/Utils/make-mutex.js +33 -0
  145. package/lib/Utils/message-composer.js +289 -0
  146. package/lib/Utils/message-retry-manager.js +134 -0
  147. package/lib/Utils/messages-media.js +806 -0
  148. package/lib/Utils/messages.js +1908 -0
  149. package/lib/Utils/noise-handler.js +157 -0
  150. package/lib/Utils/offline-node-processor.js +42 -0
  151. package/lib/Utils/pre-key-manager.js +86 -0
  152. package/lib/Utils/process-message.js +814 -0
  153. package/lib/Utils/reporting-utils.js +264 -0
  154. package/lib/Utils/signal.js +183 -0
  155. package/lib/Utils/stanza-ack.js +36 -0
  156. package/lib/Utils/sync-action-utils.js +52 -0
  157. package/lib/Utils/tc-token-utils.js +167 -0
  158. package/lib/Utils/use-multi-file-auth-state.js +104 -0
  159. package/lib/Utils/validate-connection.js +229 -0
  160. package/lib/Utils/vialeys-event-stream.js +41 -0
  161. package/lib/WABinary/constants.js +1308 -0
  162. package/lib/WABinary/decode.js +233 -0
  163. package/lib/WABinary/encode.js +212 -0
  164. package/lib/WABinary/generic-utils.js +124 -0
  165. package/lib/WABinary/index.js +36 -0
  166. package/lib/WABinary/jid-utils.js +101 -0
  167. package/lib/WABinary/types.js +2 -0
  168. package/lib/WAM/BinaryInfo.js +12 -0
  169. package/lib/WAM/constants.js +20491 -0
  170. package/lib/WAM/encode.js +148 -0
  171. package/lib/WAM/index.js +34 -0
  172. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +62 -0
  173. package/lib/WAUSync/Protocols/USyncContactProtocol.js +38 -0
  174. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +50 -0
  175. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +25 -0
  176. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +24 -0
  177. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +32 -0
  178. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +24 -0
  179. package/lib/WAUSync/Protocols/index.js +38 -0
  180. package/lib/WAUSync/USyncQuery.js +97 -0
  181. package/lib/WAUSync/USyncUser.js +33 -0
  182. package/lib/WAUSync/index.js +34 -0
  183. package/lib/index.js +113 -0
  184. package/lib/messages-send.js +1496 -0
  185. package/package.json +100 -0
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const { Mutex: Mutex } = require("async-mutex");
4
+ const { promises: promises } = require("fs");
5
+ const { join: join } = require("path");
6
+ const { proto: proto } = require("../../WAProto");
7
+ const { initAuthCreds: initAuthCreds } = require("./auth-utils");
8
+ const { BufferJSON: BufferJSON } = require("./generics");
9
+ const fileLocks = new Map();
10
+ const getFileLock = (path) => {
11
+ let mutex = fileLocks.get(path);
12
+ if (!mutex) {
13
+ mutex = new Mutex();
14
+ fileLocks.set(path, mutex);
15
+ }
16
+ return mutex;
17
+ };
18
+ const useMultiFileAuthState = async (folder) => {
19
+ const writeData = async (data, file) => {
20
+ const filePath = join(folder, fixFileName(file));
21
+ const mutex = getFileLock(filePath);
22
+ return mutex.acquire().then(async (release) => {
23
+ try {
24
+ await promises.writeFile(filePath, JSON.stringify(data, BufferJSON.replacer));
25
+ } finally {
26
+ release();
27
+ }
28
+ });
29
+ };
30
+ const readData = async (file) => {
31
+ try {
32
+ const filePath = join(folder, fixFileName(file));
33
+ const mutex = getFileLock(filePath);
34
+ const data = await mutex.acquire().then(async (release) => {
35
+ try {
36
+ return await promises.readFile(filePath, { encoding: "utf-8" });
37
+ } finally {
38
+ release();
39
+ }
40
+ });
41
+ return JSON.parse(data, BufferJSON.reviver);
42
+ } catch (error) {
43
+ return null;
44
+ }
45
+ };
46
+ const removeData = async (file) => {
47
+ try {
48
+ const filePath = join(folder, fixFileName(file));
49
+ const mutex = getFileLock(filePath);
50
+ await mutex.acquire().then(async (release) => {
51
+ try {
52
+ await promises.unlink(filePath);
53
+ } finally {
54
+ release();
55
+ }
56
+ });
57
+ } catch {}
58
+ };
59
+ const folderInfo = await promises.stat(folder).catch(() => {});
60
+ if (folderInfo) {
61
+ if (!folderInfo.isDirectory()) {
62
+ throw new Error(
63
+ `found something that is not a directory at ${folder}, either delete it or specify a different location`
64
+ );
65
+ }
66
+ } else {
67
+ await promises.mkdir(folder, { recursive: true });
68
+ }
69
+ const fixFileName = (file) => file?.replace(/\//g, "__")?.replace(/:/g, "-");
70
+ const creds = (await readData("creds.json")) || initAuthCreds();
71
+ return {
72
+ state: {
73
+ creds: creds,
74
+ keys: {
75
+ get: async (type, ids) => {
76
+ const data = {};
77
+ await Promise.all(
78
+ ids.map(async (id) => {
79
+ let value = await readData(`${type}-${id}.json`);
80
+ if (type === "app-state-sync-key" && value) {
81
+ value = proto.Message.AppStateSyncKeyData.fromObject(value);
82
+ }
83
+ data[id] = value;
84
+ })
85
+ );
86
+ return data;
87
+ },
88
+ set: async (data) => {
89
+ const tasks = [];
90
+ for (const category in data) {
91
+ for (const id in data[category]) {
92
+ const value = data[category][id];
93
+ const file = `${category}-${id}.json`;
94
+ tasks.push(value ? writeData(value, file) : removeData(file));
95
+ }
96
+ }
97
+ await Promise.all(tasks);
98
+ },
99
+ },
100
+ },
101
+ saveCreds: async () => writeData(creds, "creds.json"),
102
+ };
103
+ };
104
+ module.exports = { useMultiFileAuthState: useMultiFileAuthState };
@@ -0,0 +1,229 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const { Boom: Boom } = require("@hapi/boom");
4
+ const { createHash: createHash } = require("crypto");
5
+ const { proto: proto } = require("../../WAProto");
6
+ const {
7
+ KEY_BUNDLE_TYPE: KEY_BUNDLE_TYPE,
8
+ WA_ADV_ACCOUNT_SIG_PREFIX: WA_ADV_ACCOUNT_SIG_PREFIX,
9
+ WA_ADV_DEVICE_SIG_PREFIX: WA_ADV_DEVICE_SIG_PREFIX,
10
+ WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX: WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX,
11
+ } = require("../Defaults/constants");
12
+ const {
13
+ jidDecode: jidDecode,
14
+ getBinaryNodeChild: getBinaryNodeChild,
15
+ S_WHATSAPP_NET: S_WHATSAPP_NET,
16
+ } = require("../WABinary");
17
+ const { Curve: Curve, hmacSign: hmacSign } = require("./crypto");
18
+ const { encodeBigEndian: encodeBigEndian } = require("./generics");
19
+ const { createSignalIdentity: createSignalIdentity } = require("./signal");
20
+ const getUserAgent = (config) => ({
21
+ appVersion: {
22
+ primary: config.version[0],
23
+ secondary: config.version[1],
24
+ tertiary: config.version[2],
25
+ },
26
+ platform: proto.ClientPayload.UserAgent.Platform.WEB,
27
+ releaseChannel: proto.ClientPayload.UserAgent.ReleaseChannel.RELEASE,
28
+ osVersion: "0.1",
29
+ device: "Desktop",
30
+ osBuildNumber: "0.1",
31
+ localeLanguageIso6391: "en",
32
+ mnc: "000",
33
+ mcc: "000",
34
+ localeCountryIso31661Alpha2: config.countryCode,
35
+ });
36
+ const PLATFORM_MAP = {
37
+ "Mac OS": proto.ClientPayload.WebInfo.WebSubPlatform.DARWIN,
38
+ Windows: proto.ClientPayload.WebInfo.WebSubPlatform.WIN32,
39
+ };
40
+ const getWebInfo = (config) => {
41
+ let webSubPlatform = proto.ClientPayload.WebInfo.WebSubPlatform.WEB_BROWSER;
42
+ if (
43
+ config.syncFullHistory &&
44
+ PLATFORM_MAP[config.browser[0]] &&
45
+ config.browser[1] === "Desktop"
46
+ ) {
47
+ webSubPlatform = PLATFORM_MAP[config.browser[0]];
48
+ }
49
+ return { webSubPlatform: webSubPlatform };
50
+ };
51
+ const getClientPayload = (config) => {
52
+ const payload = {
53
+ connectType: proto.ClientPayload.ConnectType.WIFI_UNKNOWN,
54
+ connectReason: proto.ClientPayload.ConnectReason.USER_ACTIVATED,
55
+ userAgent: getUserAgent(config),
56
+ };
57
+ payload.webInfo = getWebInfo(config);
58
+ return payload;
59
+ };
60
+ const generateLoginNode = (userJid, config) => {
61
+ const { user: user, device: device } = jidDecode(userJid);
62
+ const payload = {
63
+ ...getClientPayload(config),
64
+ passive: true,
65
+ pull: true,
66
+ username: +user,
67
+ device: device,
68
+ lidDbMigrated: false,
69
+ };
70
+ return proto.ClientPayload.fromObject(payload);
71
+ };
72
+ const getPlatformType = (platform) => {
73
+ const platformType = platform.toUpperCase();
74
+ return proto.DeviceProps.PlatformType[platformType] || proto.DeviceProps.PlatformType.CHROME;
75
+ };
76
+ const generateRegistrationNode = (
77
+ {
78
+ registrationId: registrationId,
79
+ signedPreKey: signedPreKey,
80
+ signedIdentityKey: signedIdentityKey,
81
+ },
82
+ config
83
+ ) => {
84
+ const appVersionBuf = createHash("md5").update(config.version.join(".")).digest();
85
+ const companion = {
86
+ os: config.browser[0],
87
+ platformType: getPlatformType(config.browser[1]),
88
+ requireFullSync: config.syncFullHistory,
89
+ historySyncConfig: {
90
+ storageQuotaMb: 10240,
91
+ inlineInitialPayloadInE2EeMsg: true,
92
+ recentSyncDaysLimit: undefined,
93
+ supportCallLogHistory: false,
94
+ supportBotUserAgentChatHistory: true,
95
+ supportCagReactionsAndPolls: true,
96
+ supportBizHostedMsg: true,
97
+ supportRecentSyncChunkMessageCountTuning: true,
98
+ supportHostedGroupMsg: true,
99
+ supportFbidBotChatHistory: true,
100
+ supportAddOnHistorySyncMigration: undefined,
101
+ supportMessageAssociation: true,
102
+ supportGroupHistory: false,
103
+ onDemandReady: undefined,
104
+ supportGuestChat: undefined,
105
+ },
106
+ version: { primary: 10, secondary: 15, tertiary: 7 },
107
+ };
108
+ const companionProto = proto.DeviceProps.encode(companion).finish();
109
+ const registerPayload = {
110
+ ...getClientPayload(config),
111
+ passive: false,
112
+ pull: false,
113
+ devicePairingData: {
114
+ buildHash: appVersionBuf,
115
+ deviceProps: companionProto,
116
+ eRegid: encodeBigEndian(registrationId),
117
+ eKeytype: KEY_BUNDLE_TYPE,
118
+ eIdent: signedIdentityKey.public,
119
+ eSkeyId: encodeBigEndian(signedPreKey.keyId, 3),
120
+ eSkeyVal: signedPreKey.keyPair.public,
121
+ eSkeySig: signedPreKey.signature,
122
+ },
123
+ };
124
+ return proto.ClientPayload.fromObject(registerPayload);
125
+ };
126
+ const configureSuccessfulPairing = (
127
+ stanza,
128
+ {
129
+ advSecretKey: advSecretKey,
130
+ signedIdentityKey: signedIdentityKey,
131
+ signalIdentities: signalIdentities,
132
+ }
133
+ ) => {
134
+ const msgId = stanza.attrs.id;
135
+ const pairSuccessNode = getBinaryNodeChild(stanza, "pair-success");
136
+ const deviceIdentityNode = getBinaryNodeChild(pairSuccessNode, "device-identity");
137
+ const platformNode = getBinaryNodeChild(pairSuccessNode, "platform");
138
+ const deviceNode = getBinaryNodeChild(pairSuccessNode, "device");
139
+ const businessNode = getBinaryNodeChild(pairSuccessNode, "biz");
140
+ if (!deviceIdentityNode || !deviceNode) {
141
+ throw new Boom("Missing device-identity or device in pair success node", {
142
+ data: stanza,
143
+ });
144
+ }
145
+ const bizName = businessNode?.attrs.name;
146
+ const jid = deviceNode.attrs.jid;
147
+ const lid = deviceNode.attrs.lid;
148
+ const {
149
+ details: details,
150
+ hmac: hmac,
151
+ accountType: accountType,
152
+ } = proto.ADVSignedDeviceIdentityHMAC.decode(deviceIdentityNode.content);
153
+ let hmacPrefix = Buffer.from([]);
154
+ if (accountType !== undefined && accountType === proto.ADVEncryptionType.HOSTED) {
155
+ hmacPrefix = WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX;
156
+ }
157
+ const advSign = hmacSign(
158
+ Buffer.concat([hmacPrefix, details]),
159
+ Buffer.from(advSecretKey, "base64")
160
+ );
161
+ if (Buffer.compare(hmac, advSign) !== 0) {
162
+ throw new Boom("Invalid account signature");
163
+ }
164
+ const account = proto.ADVSignedDeviceIdentity.decode(details);
165
+ const {
166
+ accountSignatureKey: accountSignatureKey,
167
+ accountSignature: accountSignature,
168
+ details: deviceDetails,
169
+ } = account;
170
+ const deviceIdentity = proto.ADVDeviceIdentity.decode(deviceDetails);
171
+ const accountSignaturePrefix =
172
+ deviceIdentity.deviceType === proto.ADVEncryptionType.HOSTED
173
+ ? WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX
174
+ : WA_ADV_ACCOUNT_SIG_PREFIX;
175
+ const accountMsg = Buffer.concat([
176
+ accountSignaturePrefix,
177
+ deviceDetails,
178
+ signedIdentityKey.public,
179
+ ]);
180
+ if (!Curve.verify(accountSignatureKey, accountMsg, accountSignature)) {
181
+ throw new Boom("Failed to verify account signature");
182
+ }
183
+ const deviceMsg = Buffer.concat([
184
+ WA_ADV_DEVICE_SIG_PREFIX,
185
+ deviceDetails,
186
+ signedIdentityKey.public,
187
+ accountSignatureKey,
188
+ ]);
189
+ account.deviceSignature = Curve.sign(signedIdentityKey.private, deviceMsg);
190
+ const identity = createSignalIdentity(lid, accountSignatureKey);
191
+ const accountEnc = encodeSignedDeviceIdentity(account, false);
192
+ const reply = {
193
+ tag: "iq",
194
+ attrs: { to: S_WHATSAPP_NET, type: "result", id: msgId },
195
+ content: [
196
+ {
197
+ tag: "pair-device-sign",
198
+ attrs: {},
199
+ content: [
200
+ {
201
+ tag: "device-identity",
202
+ attrs: { "key-index": deviceIdentity.keyIndex.toString() },
203
+ content: accountEnc,
204
+ },
205
+ ],
206
+ },
207
+ ],
208
+ };
209
+ const authUpdate = {
210
+ account: account,
211
+ me: { id: jid, name: bizName, lid: lid },
212
+ signalIdentities: [...(signalIdentities || []), identity],
213
+ platform: platformNode?.attrs.name,
214
+ };
215
+ return { creds: authUpdate, reply: reply };
216
+ };
217
+ const encodeSignedDeviceIdentity = (account, includeSignatureKey) => {
218
+ account = { ...account };
219
+ if (!includeSignatureKey || !account.accountSignatureKey?.length) {
220
+ account.accountSignatureKey = null;
221
+ }
222
+ return proto.ADVSignedDeviceIdentity.encode(account).finish();
223
+ };
224
+ module.exports = {
225
+ generateLoginNode: generateLoginNode,
226
+ generateRegistrationNode: generateRegistrationNode,
227
+ configureSuccessfulPairing: configureSuccessfulPairing,
228
+ encodeSignedDeviceIdentity: encodeSignedDeviceIdentity,
229
+ };
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const Events = require("events");
4
+ const { promises: promises, createReadStream: createReadStream } = require("fs");
5
+ const { writeFile: writeFile } = require("fs/promises");
6
+ const { createInterface: createInterface } = require("readline");
7
+ const { delay: delay } = require("./generics");
8
+ const { makeMutex: makeMutex } = require("./make-mutex");
9
+ const captureEventStream = (ev, filename) => {
10
+ const oldEmit = ev.emit;
11
+ const writeMutex = makeMutex();
12
+ ev.emit = function (...args) {
13
+ const content =
14
+ JSON.stringify({ timestamp: Date.now(), event: args[0], data: args[1] }) + "\n";
15
+ const result = oldEmit.apply(ev, args);
16
+ writeMutex.mutex(async () => {
17
+ await promises.writeFile(filename, content, { flag: "a" });
18
+ });
19
+ return result;
20
+ };
21
+ };
22
+ const readAndEmitEventStream = (filename, delayIntervalMs = 0) => {
23
+ const ev = new Events();
24
+ const fireEvents = async () => {
25
+ const fileStream = createReadStream(filename);
26
+ const rl = createInterface({ input: fileStream, crlfDelay: Infinity });
27
+ for await (const line of rl) {
28
+ if (line) {
29
+ const { event: event, data: data } = JSON.parse(line);
30
+ ev.emit(event, data);
31
+ delayIntervalMs && (await delay(delayIntervalMs));
32
+ }
33
+ }
34
+ fileStream.close();
35
+ };
36
+ return { ev: ev, task: fireEvents() };
37
+ };
38
+ module.exports = {
39
+ captureEventStream: captureEventStream,
40
+ readAndEmitEventStream: readAndEmitEventStream,
41
+ };