@pontalabs/baileys 1.0.11 → 1.1.0

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 (119) hide show
  1. package/README.md +96 -85
  2. package/lib/Defaults/connection.js +39 -0
  3. package/lib/Defaults/constants.js +50 -0
  4. package/lib/Defaults/history.js +13 -0
  5. package/lib/Defaults/index.js +36 -151
  6. package/lib/Defaults/media.js +43 -0
  7. package/lib/Defaults/phonenumber-mcc.json +221 -221
  8. package/lib/Defaults/prefix.js +12 -0
  9. package/lib/Defaults/vialeys-version.json +7 -0
  10. package/lib/Signal/Group/ciphertext-message.js +10 -15
  11. package/lib/Signal/Group/group-session-builder.js +34 -60
  12. package/lib/Signal/Group/group_cipher.js +69 -76
  13. package/lib/Signal/Group/index.js +41 -60
  14. package/lib/Signal/Group/keyhelper.js +12 -57
  15. package/lib/Signal/Group/sender-chain-key.js +20 -33
  16. package/lib/Signal/Group/sender-key-distribution-message.js +43 -48
  17. package/lib/Signal/Group/sender-key-message.js +58 -53
  18. package/lib/Signal/Group/sender-key-name.js +21 -31
  19. package/lib/Signal/Group/sender-key-record.js +21 -34
  20. package/lib/Signal/Group/sender-key-state.js +59 -106
  21. package/lib/Signal/Group/sender-message-key.js +16 -21
  22. package/lib/Signal/libsignal.js +282 -203
  23. package/lib/Signal/lid-mapping.js +164 -184
  24. package/lib/Socket/Client/index.js +31 -22
  25. package/lib/Socket/Client/types.js +9 -15
  26. package/lib/Socket/Client/websocket.js +42 -37
  27. package/lib/Socket/business.js +212 -336
  28. package/lib/Socket/chats.js +696 -940
  29. package/lib/Socket/community.js +454 -369
  30. package/lib/Socket/groups.js +278 -280
  31. package/lib/Socket/index.js +9 -21
  32. package/lib/Socket/messages-recv.js +1027 -1570
  33. package/lib/Socket/messages-send.js +1180 -1136
  34. package/lib/Socket/mex.js +59 -0
  35. package/lib/Socket/newsletter.js +193 -251
  36. package/lib/Socket/socket.js +758 -898
  37. package/lib/Store/index.js +35 -24
  38. package/lib/Store/make-cache-manager-store.js +53 -66
  39. package/lib/Store/make-in-memory-store.js +319 -325
  40. package/lib/Store/make-ordered-dictionary.js +49 -57
  41. package/lib/Store/object-repository.js +10 -15
  42. package/lib/Types/Auth.js +2 -3
  43. package/lib/Types/Bussines.js +2 -3
  44. package/lib/Types/Call.js +2 -3
  45. package/lib/Types/Chat.js +10 -9
  46. package/lib/Types/Contact.js +2 -3
  47. package/lib/Types/Events.js +2 -3
  48. package/lib/Types/GroupMetadata.js +2 -3
  49. package/lib/Types/Label.js +6 -12
  50. package/lib/Types/LabelAssociation.js +4 -13
  51. package/lib/Types/Message.js +10 -18
  52. package/lib/Types/MexUpdates.js +15 -18
  53. package/lib/Types/Newsletter.js +26 -34
  54. package/lib/Types/Product.js +2 -3
  55. package/lib/Types/Signal.js +2 -3
  56. package/lib/Types/Socket.js +2 -3
  57. package/lib/Types/State.js +8 -13
  58. package/lib/Types/USync.js +2 -3
  59. package/lib/Types/index.js +49 -40
  60. package/lib/Utils/auth-utils.js +190 -495
  61. package/lib/Utils/browser-utils.js +29 -0
  62. package/lib/Utils/business.js +177 -199
  63. package/lib/Utils/chat-utils.js +711 -624
  64. package/lib/Utils/crypto.js +116 -161
  65. package/lib/Utils/decode-wa-message.js +225 -321
  66. package/lib/Utils/event-buffer.js +363 -405
  67. package/lib/Utils/generics.js +318 -472
  68. package/lib/Utils/history.js +72 -76
  69. package/lib/Utils/index.js +49 -41
  70. package/lib/Utils/link-preview.js +59 -103
  71. package/lib/Utils/logger.js +4 -7
  72. package/lib/Utils/lt-hash.js +29 -42
  73. package/lib/Utils/make-mutex.js +26 -42
  74. package/lib/Utils/message-retry-manager.js +134 -160
  75. package/lib/Utils/messages-media.js +665 -731
  76. package/lib/Utils/messages.js +518 -1
  77. package/lib/Utils/noise-handler.js +127 -125
  78. package/lib/Utils/pre-key-manager.js +86 -0
  79. package/lib/Utils/process-message.js +739 -351
  80. package/lib/Utils/signal.js +146 -129
  81. package/lib/Utils/use-multi-file-auth-state.js +68 -135
  82. package/lib/Utils/validate-connection.js +183 -142
  83. package/lib/Utils/vialeys-event-stream.js +41 -0
  84. package/lib/WABinary/constants.js +1281 -1289
  85. package/lib/WABinary/decode.js +145 -200
  86. package/lib/WABinary/encode.js +149 -202
  87. package/lib/WABinary/generic-utils.js +79 -97
  88. package/lib/WABinary/index.js +36 -25
  89. package/lib/WABinary/jid-utils.js +91 -123
  90. package/lib/WABinary/types.js +2 -3
  91. package/lib/WAM/BinaryInfo.js +8 -13
  92. package/lib/WAM/constants.js +16584 -11464
  93. package/lib/WAM/encode.js +117 -133
  94. package/lib/WAM/index.js +34 -23
  95. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +62 -69
  96. package/lib/WAUSync/Protocols/USyncContactProtocol.js +11 -25
  97. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +32 -44
  98. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +13 -23
  99. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +24 -38
  100. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +17 -31
  101. package/lib/WAUSync/Protocols/index.js +37 -26
  102. package/lib/WAUSync/USyncQuery.js +66 -66
  103. package/lib/WAUSync/USyncUser.js +13 -18
  104. package/lib/WAUSync/index.js +34 -23
  105. package/lib/index.js +95 -28
  106. package/package.json +2 -1
  107. package/lib/Defaults/baileys-version.json +0 -3
  108. package/lib/Signal/Group/queue-job.d.ts +0 -1
  109. package/lib/Signal/Group/queue-job.js +0 -57
  110. package/lib/Socket/usync.d.ts +0 -37
  111. package/lib/Socket/usync.js +0 -83
  112. package/lib/Utils/baileys-event-stream.d.ts +0 -18
  113. package/lib/Utils/baileys-event-stream.js +0 -70
  114. package/lib/Utils/signal-housekeeping.d.ts +0 -19
  115. package/lib/Utils/signal-housekeeping.js +0 -73
  116. package/lib/Utils/use-mongo-file-auth-state.d.ts +0 -6
  117. package/lib/Utils/use-mongo-file-auth-state.js +0 -84
  118. package/lib/Utils/use-single-file-auth-state.d.ts +0 -13
  119. package/lib/Utils/use-single-file-auth-state.js +0 -80
@@ -1,88 +1,111 @@
1
- "use strict"
2
-
3
- Object.defineProperty(exports, "__esModule", { value: true })
4
-
5
- const boom_1 = require("@hapi/boom")
6
- const crypto_1 = require("crypto")
7
- const WAProto_1 = require("../../WAProto")
8
- const Defaults_1 = require("../Defaults")
9
- const WABinary_1 = require("../WABinary")
10
- const crypto_2 = require("./crypto")
11
- const generics_1 = require("./generics")
12
- const signal_1 = require("./signal")
13
-
14
- const getUserAgent = (config) => {
15
- return {
16
- appVersion: {
17
- primary: config.version[0],
18
- secondary: config.version[1],
19
- tertiary: config.version[2],
20
- },
21
- platform: WAProto_1.proto.ClientPayload.UserAgent.Platform.WEB,
22
- releaseChannel: WAProto_1.proto.ClientPayload.UserAgent.ReleaseChannel.RELEASE,
23
- osVersion: '0.1',
24
- device: 'Desktop',
25
- osBuildNumber: '0.1',
26
- localeLanguageIso6391: 'en',
27
- mnc: '000',
28
- mcc: '000',
29
- localeCountryIso31661Alpha2: config.countryCode
30
- }
31
- }
32
-
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
+ });
33
36
  const PLATFORM_MAP = {
34
- 'Mac OS': WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.DARWIN,
35
- 'Windows': WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.WIN32,
36
- 'Android': WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.WIN_HYBRID
37
- }
38
-
37
+ "Mac OS": proto.ClientPayload.WebInfo.WebSubPlatform.DARWIN,
38
+ Windows: proto.ClientPayload.WebInfo.WebSubPlatform.WIN32,
39
+ };
39
40
  const getWebInfo = (config) => {
40
- let webSubPlatform = WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.WEB_BROWSER
41
- if (config.syncFullHistory && PLATFORM_MAP[config.browser[0]]) {
42
- webSubPlatform = PLATFORM_MAP[config.browser[0]]
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]];
43
48
  }
44
- return { webSubPlatform }
45
- }
46
-
49
+ return { webSubPlatform: webSubPlatform };
50
+ };
47
51
  const getClientPayload = (config) => {
48
52
  const payload = {
49
- connectType: WAProto_1.proto.ClientPayload.ConnectType.WIFI_UNKNOWN,
50
- connectReason: WAProto_1.proto.ClientPayload.ConnectReason.USER_ACTIVATED,
53
+ connectType: proto.ClientPayload.ConnectType.WIFI_UNKNOWN,
54
+ connectReason: proto.ClientPayload.ConnectReason.USER_ACTIVATED,
51
55
  userAgent: getUserAgent(config),
52
- }
53
- payload.webInfo = getWebInfo(config)
54
- return payload
55
- }
56
-
56
+ };
57
+ payload.webInfo = getWebInfo(config);
58
+ return payload;
59
+ };
57
60
  const generateLoginNode = (userJid, config) => {
58
- const { user, device } = WABinary_1.jidDecode(userJid)
61
+ const { user: user, device: device } = jidDecode(userJid);
59
62
  const payload = {
60
63
  ...getClientPayload(config),
61
64
  passive: true,
62
65
  pull: true,
63
66
  username: +user,
64
67
  device: device,
65
- }
66
- return WAProto_1.proto.ClientPayload.fromObject(payload)
67
- }
68
-
68
+ lidDbMigrated: false,
69
+ };
70
+ return proto.ClientPayload.fromObject(payload);
71
+ };
69
72
  const getPlatformType = (platform) => {
70
- const platformType = platform.toUpperCase()
71
- return WAProto_1.proto.DeviceProps.PlatformType[platformType] || WAProto_1.proto.DeviceProps.PlatformType.DESKTOP
72
- }
73
-
74
- const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentityKey }, config) => {
75
- // the app version needs to be md5 hashed
76
- // and passed in
77
- const appVersionBuf = crypto_1.createHash('md5')
78
- .update(config.version.join('.')) // join as string
79
- .digest()
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();
80
85
  const companion = {
81
86
  os: config.browser[0],
82
87
  platformType: getPlatformType(config.browser[1]),
83
88
  requireFullSync: config.syncFullHistory,
84
- }
85
- const companionProto = WAProto_1.proto.DeviceProps.encode(companion).finish()
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();
86
109
  const registerPayload = {
87
110
  ...getClientPayload(config),
88
111
  passive: false,
@@ -90,99 +113,117 @@ const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentity
90
113
  devicePairingData: {
91
114
  buildHash: appVersionBuf,
92
115
  deviceProps: companionProto,
93
- eRegid: generics_1.encodeBigEndian(registrationId),
94
- eKeytype: Defaults_1.KEY_BUNDLE_TYPE,
116
+ eRegid: encodeBigEndian(registrationId),
117
+ eKeytype: KEY_BUNDLE_TYPE,
95
118
  eIdent: signedIdentityKey.public,
96
- eSkeyId: generics_1.encodeBigEndian(signedPreKey.keyId, 3),
119
+ eSkeyId: encodeBigEndian(signedPreKey.keyId, 3),
97
120
  eSkeyVal: signedPreKey.keyPair.public,
98
121
  eSkeySig: signedPreKey.signature,
99
122
  },
123
+ };
124
+ return proto.ClientPayload.fromObject(registerPayload);
125
+ };
126
+ const configureSuccessfulPairing = (
127
+ stanza,
128
+ {
129
+ advSecretKey: advSecretKey,
130
+ signedIdentityKey: signedIdentityKey,
131
+ signalIdentities: signalIdentities,
100
132
  }
101
- return WAProto_1.proto.ClientPayload.fromObject(registerPayload)
102
- }
103
-
104
- const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, signalIdentities }) => {
105
- const msgId = stanza.attrs.id
106
- const pairSuccessNode = WABinary_1.getBinaryNodeChild(stanza, 'pair-success')
107
- const deviceIdentityNode = WABinary_1.getBinaryNodeChild(pairSuccessNode, 'device-identity')
108
- const platformNode = WABinary_1.getBinaryNodeChild(pairSuccessNode, 'platform')
109
- const deviceNode = WABinary_1.getBinaryNodeChild(pairSuccessNode, 'device')
110
- const businessNode = WABinary_1.getBinaryNodeChild(pairSuccessNode, 'biz')
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");
111
140
  if (!deviceIdentityNode || !deviceNode) {
112
- throw new boom_1.Boom('Missing device-identity or device in pair success node', { data: stanza })
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;
113
156
  }
114
- const bizName = businessNode?.attrs?.name
115
- const jid = deviceNode.attrs.jid
116
- const lid = deviceNode.attrs.lid
117
- const { details, hmac, accountType } = WAProto_1.proto.ADVSignedDeviceIdentityHMAC.decode(deviceIdentityNode.content)
118
- const isHostedAccount = accountType !== undefined && accountType === WAProto_1.proto.ADVEncryptionType.HOSTED
119
- const hmacPrefix = isHostedAccount ? Buffer.from([6, 5]) : Buffer.alloc(0)
120
- const advSign = crypto_2.hmacSign(Buffer.concat([hmacPrefix, details]), Buffer.from(advSecretKey, 'base64'))
157
+ const advSign = hmacSign(
158
+ Buffer.concat([hmacPrefix, details]),
159
+ Buffer.from(advSecretKey, "base64")
160
+ );
121
161
  if (Buffer.compare(hmac, advSign) !== 0) {
122
- throw new boom_1.Boom('Invalid account signature')
162
+ throw new Boom("Invalid account signature");
123
163
  }
124
- const account = WAProto_1.proto.ADVSignedDeviceIdentity.decode(details)
125
- const { accountSignatureKey, accountSignature, details: deviceDetails } = account
126
- const accountMsg = Buffer.concat([Buffer.from([6, 0]), deviceDetails, signedIdentityKey.public])
127
- if (!crypto_2.Curve.verify(accountSignatureKey, accountMsg, accountSignature)) {
128
- throw new boom_1.Boom('Failed to verify account signature')
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");
129
182
  }
130
-
131
- const devicePrefix = isHostedAccount ? Buffer.from([6, 6]) : Buffer.from([6, 1])
132
- const deviceMsg = Buffer.concat([devicePrefix, deviceDetails, signedIdentityKey.public, accountSignatureKey])
133
- account.deviceSignature = crypto_2.Curve.sign(signedIdentityKey.private, deviceMsg)
134
- const identity = signal_1.createSignalIdentity(lid, accountSignatureKey)
135
- const accountEnc = encodeSignedDeviceIdentity(account, false)
136
- const deviceIdentity = WAProto_1.proto.ADVDeviceIdentity.decode(account.details)
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);
137
192
  const reply = {
138
- tag: 'iq',
139
- attrs: {
140
- to: WABinary_1.S_WHATSAPP_NET,
141
- type: 'result',
142
- id: msgId,
143
- },
193
+ tag: "iq",
194
+ attrs: { to: S_WHATSAPP_NET, type: "result", id: msgId },
144
195
  content: [
145
196
  {
146
- tag: 'pair-device-sign',
197
+ tag: "pair-device-sign",
147
198
  attrs: {},
148
199
  content: [
149
200
  {
150
- tag: 'device-identity',
151
- attrs: { 'key-index': deviceIdentity.keyIndex.toString() },
152
- content: accountEnc
153
- }
154
- ]
155
- }
156
- ]
157
- }
158
- const authUpdate = {
159
- account,
160
- me: { id: jid, name: bizName, lid },
161
- signalIdentities: [
162
- ...(signalIdentities || []),
163
- identity
201
+ tag: "device-identity",
202
+ attrs: { "key-index": deviceIdentity.keyIndex.toString() },
203
+ content: accountEnc,
204
+ },
205
+ ],
206
+ },
164
207
  ],
165
- platform: platformNode?.attrs?.name
166
- }
167
- return {
168
- creds: authUpdate,
169
- reply
170
- }
171
- }
172
-
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
+ };
173
217
  const encodeSignedDeviceIdentity = (account, includeSignatureKey) => {
174
- account = { ...account }
175
- // set to null if we are not to include the signature key
176
- // or if we are including the signature key but it is empty
218
+ account = { ...account };
177
219
  if (!includeSignatureKey || !account.accountSignatureKey?.length) {
178
- account.accountSignatureKey = null
220
+ account.accountSignatureKey = null;
179
221
  }
180
- return WAProto_1.proto.ADVSignedDeviceIdentity.encode(account).finish()
181
- }
182
-
222
+ return proto.ADVSignedDeviceIdentity.encode(account).finish();
223
+ };
183
224
  module.exports = {
184
- generateLoginNode,
185
- generateRegistrationNode,
186
- configureSuccessfulPairing,
187
- encodeSignedDeviceIdentity
188
- }
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
+ };