cuki-bailx 1.2.4 → 1.2.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 (157) hide show
  1. package/LICENSE +21 -0
  2. package/WAProto/GenerateStatics.sh +4 -0
  3. package/WAProto/WAProto.proto +4775 -0
  4. package/WAProto/index.js +56886 -17506
  5. package/engine-requirements.js +1 -1
  6. package/lib/Defaults/index.js +98 -108
  7. package/lib/Defaults/vyzen-baileysx-version.json +3 -0
  8. package/lib/Signal/libsignal.js +2 -0
  9. package/lib/Socket/Client/index.js +2 -3
  10. package/lib/Socket/Client/{web-socket-client.js → websocket.js} +54 -5
  11. package/lib/Socket/chats.js +224 -173
  12. package/lib/Socket/groups.js +20 -5
  13. package/lib/Socket/index.js +2 -2
  14. package/lib/Socket/messages-recv.js +10 -66
  15. package/lib/Socket/messages-send.js +379 -312
  16. package/lib/Socket/newsletter.js +54 -40
  17. package/lib/Socket/socket.js +58 -32
  18. package/lib/Store/index.js +1 -3
  19. package/lib/Store/make-in-memory-store.js +27 -15
  20. package/lib/Store/make-ordered-dictionary.js +2 -2
  21. package/lib/Types/Label.js +1 -1
  22. package/lib/Types/LabelAssociation.js +1 -1
  23. package/lib/Types/Message.js +0 -2
  24. package/lib/Types/Newsletter.js +3 -17
  25. package/lib/Types/index.js +2 -2
  26. package/lib/Utils/auth-utils.js +6 -13
  27. package/lib/Utils/baileys-event-stream.js +1 -1
  28. package/lib/Utils/browser-utils.js +35 -0
  29. package/lib/Utils/business.js +2 -2
  30. package/lib/Utils/chat-utils.js +36 -35
  31. package/lib/Utils/crypto.js +71 -29
  32. package/lib/Utils/decode-wa-message.js +65 -56
  33. package/lib/Utils/event-buffer.js +13 -9
  34. package/lib/Utils/generics.js +107 -29
  35. package/lib/Utils/history.js +4 -6
  36. package/lib/Utils/index.js +2 -0
  37. package/lib/Utils/link-preview.js +34 -1
  38. package/lib/Utils/lt-hash.js +6 -6
  39. package/lib/Utils/message-retry-manager.js +128 -0
  40. package/lib/Utils/messages-media.js +263 -115
  41. package/lib/Utils/messages.js +500 -93
  42. package/lib/Utils/noise-handler.js +18 -23
  43. package/lib/Utils/process-message.js +108 -25
  44. package/lib/Utils/signal.js +37 -35
  45. package/lib/Utils/use-multi-file-auth-state.js +51 -6
  46. package/lib/Utils/validate-connection.js +90 -66
  47. package/lib/WABinary/constants.js +1276 -13
  48. package/lib/WABinary/decode.js +26 -13
  49. package/lib/WABinary/encode.js +39 -17
  50. package/lib/WABinary/generic-utils.js +2 -85
  51. package/lib/WABinary/jid-utils.js +28 -5
  52. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +1 -1
  53. package/lib/index.js +18 -5
  54. package/package.json +109 -104
  55. package/lib/Defaults/baileys-version.json +0 -3
  56. package/lib/Defaults/index.d.ts +0 -53
  57. package/lib/Defaults/phonenumber-mcc.json +0 -223
  58. package/lib/Signal/Group/ciphertext-message.d.ts +0 -9
  59. package/lib/Signal/Group/group-session-builder.d.ts +0 -14
  60. package/lib/Signal/Group/group_cipher.d.ts +0 -17
  61. package/lib/Signal/Group/index.d.ts +0 -11
  62. package/lib/Signal/Group/keyhelper.d.ts +0 -10
  63. package/lib/Signal/Group/queue-job.d.ts +0 -1
  64. package/lib/Signal/Group/sender-chain-key.d.ts +0 -13
  65. package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -16
  66. package/lib/Signal/Group/sender-key-message.d.ts +0 -18
  67. package/lib/Signal/Group/sender-key-name.d.ts +0 -17
  68. package/lib/Signal/Group/sender-key-record.d.ts +0 -30
  69. package/lib/Signal/Group/sender-key-state.d.ts +0 -38
  70. package/lib/Signal/Group/sender-message-key.d.ts +0 -11
  71. package/lib/Signal/libsignal.d.ts +0 -3
  72. package/lib/Socket/Client/abstract-socket-client.d.ts +0 -17
  73. package/lib/Socket/Client/index.d.ts +0 -3
  74. package/lib/Socket/Client/mobile-socket-client.d.ts +0 -13
  75. package/lib/Socket/Client/mobile-socket-client.js +0 -65
  76. package/lib/Socket/Client/web-socket-client.d.ts +0 -12
  77. package/lib/Socket/business.d.ts +0 -171
  78. package/lib/Socket/chats.d.ts +0 -80
  79. package/lib/Socket/dugong.d.ts +0 -219
  80. package/lib/Socket/dugong.js +0 -441
  81. package/lib/Socket/groups.d.ts +0 -115
  82. package/lib/Socket/index.d.ts +0 -173
  83. package/lib/Socket/messages-recv.d.ts +0 -161
  84. package/lib/Socket/messages-send.d.ts +0 -149
  85. package/lib/Socket/newsletter.d.ts +0 -134
  86. package/lib/Socket/registration.d.ts +0 -267
  87. package/lib/Socket/registration.js +0 -166
  88. package/lib/Socket/socket.d.ts +0 -43
  89. package/lib/Socket/socket.js.bak +0 -630
  90. package/lib/Socket/usync.d.ts +0 -36
  91. package/lib/Store/index.d.ts +0 -3
  92. package/lib/Store/make-cache-manager-store.d.ts +0 -13
  93. package/lib/Store/make-cache-manager-store.js +0 -83
  94. package/lib/Store/make-in-memory-store.d.ts +0 -118
  95. package/lib/Store/make-ordered-dictionary.d.ts +0 -13
  96. package/lib/Store/object-repository.d.ts +0 -10
  97. package/lib/Types/Auth.d.ts +0 -110
  98. package/lib/Types/Call.d.ts +0 -13
  99. package/lib/Types/Chat.d.ts +0 -102
  100. package/lib/Types/Contact.d.ts +0 -19
  101. package/lib/Types/Events.d.ts +0 -157
  102. package/lib/Types/GroupMetadata.d.ts +0 -55
  103. package/lib/Types/Label.d.ts +0 -35
  104. package/lib/Types/LabelAssociation.d.ts +0 -29
  105. package/lib/Types/Message.d.ts +0 -273
  106. package/lib/Types/Newsletter.d.ts +0 -92
  107. package/lib/Types/Product.d.ts +0 -78
  108. package/lib/Types/Signal.d.ts +0 -57
  109. package/lib/Types/Socket.d.ts +0 -111
  110. package/lib/Types/State.d.ts +0 -27
  111. package/lib/Types/USync.d.ts +0 -25
  112. package/lib/Types/index.d.ts +0 -57
  113. package/lib/Utils/auth-utils.d.ts +0 -18
  114. package/lib/Utils/baileys-event-stream.d.ts +0 -16
  115. package/lib/Utils/business.d.ts +0 -22
  116. package/lib/Utils/chat-utils.d.ts +0 -71
  117. package/lib/Utils/crypto.d.ts +0 -41
  118. package/lib/Utils/decode-wa-message.d.ts +0 -19
  119. package/lib/Utils/event-buffer.d.ts +0 -35
  120. package/lib/Utils/generics.d.ts +0 -92
  121. package/lib/Utils/history.d.ts +0 -15
  122. package/lib/Utils/index.d.ts +0 -17
  123. package/lib/Utils/link-preview.d.ts +0 -21
  124. package/lib/Utils/logger.d.ts +0 -4
  125. package/lib/Utils/lt-hash.d.ts +0 -12
  126. package/lib/Utils/make-mutex.d.ts +0 -7
  127. package/lib/Utils/messages-media.d.ts +0 -116
  128. package/lib/Utils/messages.d.ts +0 -77
  129. package/lib/Utils/noise-handler.d.ts +0 -21
  130. package/lib/Utils/process-message.d.ts +0 -41
  131. package/lib/Utils/signal.d.ts +0 -32
  132. package/lib/Utils/use-multi-file-auth-state.d.ts +0 -13
  133. package/lib/Utils/validate-connection.d.ts +0 -11
  134. package/lib/WABinary/constants.d.ts +0 -27
  135. package/lib/WABinary/decode.d.ts +0 -7
  136. package/lib/WABinary/encode.d.ts +0 -3
  137. package/lib/WABinary/generic-utils.d.ts +0 -16
  138. package/lib/WABinary/index.d.ts +0 -5
  139. package/lib/WABinary/jid-utils.d.ts +0 -31
  140. package/lib/WABinary/types.d.ts +0 -18
  141. package/lib/WAM/BinaryInfo.d.ts +0 -17
  142. package/lib/WAM/constants.d.ts +0 -38
  143. package/lib/WAM/encode.d.ts +0 -3
  144. package/lib/WAM/index.d.ts +0 -3
  145. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -9
  146. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -22
  147. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -12
  148. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -12
  149. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +0 -25
  150. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +0 -8
  151. package/lib/WAUSync/Protocols/index.d.ts +0 -4
  152. package/lib/WAUSync/USyncQuery.d.ts +0 -28
  153. package/lib/WAUSync/USyncUser.d.ts +0 -12
  154. package/lib/WAUSync/index.d.ts +0 -3
  155. package/lib/index.d.ts +0 -12
  156. package/lib/index.js.bak +0 -48
  157. /package/lib/Socket/Client/{abstract-socket-client.js → types.js} +0 -0
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.encodeSignedDeviceIdentity = exports.configureSuccessfulPairing = exports.generateRegistrationNode = exports.generateLoginNode = exports.generateMobileNode = void 0;
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
6
  const WAProto_1 = require("../../WAProto");
@@ -8,107 +8,108 @@ const Defaults_1 = require("../Defaults");
8
8
  const WABinary_1 = require("../WABinary");
9
9
  const crypto_2 = require("./crypto");
10
10
  const generics_1 = require("./generics");
11
- const signal_1 = require("./signal");
11
+ const signal_1 = require("./signal");
12
+
12
13
  const getUserAgent = (config) => {
13
- var _a, _b;
14
- const osVersion = config.mobile ? '15.3.1' : '0.1';
15
- const version = config.mobile ? [2, 24, 6] : config.version;
16
- const device = config.mobile ? 'iPhone_7' : 'Desktop';
17
- const manufacturer = config.mobile ? 'Apple' : '';
18
- const platform = config.mobile ? WAProto_1.proto.ClientPayload.UserAgent.Platform.IOS : WAProto_1.proto.ClientPayload.UserAgent.Platform.WEB;
19
- const phoneId = config.mobile ? { phoneId: config.auth.creds.phoneId } : {};
20
14
  return {
21
15
  appVersion: {
22
- primary: version[0],
23
- secondary: version[1],
24
- tertiary: version[2],
16
+ primary: config.version[0],
17
+ secondary: config.version[1],
18
+ tertiary: config.version[2],
25
19
  },
26
- platform,
20
+ platform: WAProto_1.proto.ClientPayload.UserAgent.Platform.WEB,
27
21
  releaseChannel: WAProto_1.proto.ClientPayload.UserAgent.ReleaseChannel.RELEASE,
28
- mcc: ((_a = config.auth.creds.registration) === null || _a === void 0 ? void 0 : _a.phoneNumberMobileCountryCode) || '000',
29
- mnc: ((_b = config.auth.creds.registration) === null || _b === void 0 ? void 0 : _b.phoneNumberMobileNetworkCode) || '000',
30
- osVersion: osVersion,
31
- manufacturer,
32
- device,
33
- osBuildNumber: osVersion,
22
+ osVersion: '0.1',
23
+ device: 'Desktop',
24
+ osBuildNumber: '0.1',
34
25
  localeLanguageIso6391: 'en',
35
- localeCountryIso31661Alpha2: 'US',
36
- ...phoneId
26
+ mnc: '000',
27
+ mcc: '000',
28
+ localeCountryIso31661Alpha2: config.countryCode || 'US'
37
29
  };
38
30
  };
31
+
39
32
  const PLATFORM_MAP = {
40
33
  'Mac OS': WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.DARWIN,
41
34
  'Windows': WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.WIN32
42
35
  };
36
+
43
37
  const getWebInfo = (config) => {
44
38
  let webSubPlatform = WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.WEB_BROWSER;
45
- if (config.syncFullHistory && PLATFORM_MAP[config.browser[0]]) {
39
+ if (config.syncFullHistory && PLATFORM_MAP[config.browser[0]] && config.browser[1] === 'Desktop') {
46
40
  webSubPlatform = PLATFORM_MAP[config.browser[0]];
47
41
  }
48
42
  return { webSubPlatform };
49
43
  };
44
+
50
45
  const getClientPayload = (config) => {
51
46
  const payload = {
52
47
  connectType: WAProto_1.proto.ClientPayload.ConnectType.WIFI_UNKNOWN,
53
48
  connectReason: WAProto_1.proto.ClientPayload.ConnectReason.USER_ACTIVATED,
54
49
  userAgent: getUserAgent(config),
55
50
  };
56
- if (!config.mobile) {
57
- payload.webInfo = getWebInfo(config);
58
- }
51
+ payload.webInfo = getWebInfo(config);
59
52
  return payload;
60
53
  };
61
- const generateMobileNode = (config) => {
62
- if (!config.auth.creds) {
63
- throw new boom_1.Boom('No registration data found', { data: config });
64
- }
65
- const payload = {
66
- ...getClientPayload(config),
67
- sessionId: Math.floor(Math.random() * 999999999 + 1),
68
- shortConnect: true,
69
- connectAttemptCount: 0,
70
- device: 0,
71
- dnsSource: {
72
- appCached: false,
73
- dnsMethod: WAProto_1.proto.ClientPayload.DNSSource.DNSResolutionMethod.SYSTEM,
74
- },
75
- passive: false,
76
- pushName: 'test',
77
- username: Number(`${config.auth.creds.registration.phoneNumberCountryCode}${config.auth.creds.registration.phoneNumberNationalNumber}`),
78
- };
79
- return WAProto_1.proto.ClientPayload.fromObject(payload);
80
- };
81
- exports.generateMobileNode = generateMobileNode;
54
+
82
55
  const generateLoginNode = (userJid, config) => {
83
56
  const { user, device } = (0, WABinary_1.jidDecode)(userJid);
84
57
  const payload = {
85
58
  ...getClientPayload(config),
86
59
  passive: true,
60
+ pull: true,
87
61
  username: +user,
88
62
  device: device,
63
+ lidDbMigrated: false
89
64
  };
90
65
  return WAProto_1.proto.ClientPayload.fromObject(payload);
91
66
  };
92
67
  exports.generateLoginNode = generateLoginNode;
68
+
93
69
  const getPlatformType = (platform) => {
94
70
  const platformType = platform.toUpperCase();
95
- return WAProto_1.proto.DeviceProps.PlatformType[platformType] || WAProto_1.proto.DeviceProps.PlatformType.DESKTOP;
71
+ return WAProto_1.proto.DeviceProps.PlatformType[platformType] || WAProto_1.proto.DeviceProps.PlatformType.CHROME;
96
72
  };
73
+
97
74
  const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentityKey }, config) => {
98
- // the app version needs to be md5 hashed
99
- // and passed in
100
75
  const appVersionBuf = (0, crypto_1.createHash)('md5')
101
- .update(config.version.join('.')) // join as string
76
+ .update(config.version.join('.'))
102
77
  .digest();
78
+
103
79
  const companion = {
104
80
  os: config.browser[0],
105
81
  platformType: getPlatformType(config.browser[1]),
106
82
  requireFullSync: config.syncFullHistory,
83
+ historySyncConfig: {
84
+ storageQuotaMb: 10240,
85
+ inlineInitialPayloadInE2EeMsg: true,
86
+ recentSyncDaysLimit: undefined,
87
+ supportCallLogHistory: false,
88
+ supportBotUserAgentChatHistory: true,
89
+ supportCagReactionsAndPolls: true,
90
+ supportBizHostedMsg: true,
91
+ supportRecentSyncChunkMessageCountTuning: true,
92
+ supportHostedGroupMsg: true,
93
+ supportFbidBotChatHistory: true,
94
+ supportAddOnHistorySyncMigration: undefined,
95
+ supportMessageAssociation: true,
96
+ supportGroupHistory: false,
97
+ onDemandReady: undefined,
98
+ supportGuestChat: undefined
99
+ },
100
+ version: {
101
+ primary: 10,
102
+ secondary: 15,
103
+ tertiary: 7
104
+ }
107
105
  };
106
+
108
107
  const companionProto = WAProto_1.proto.DeviceProps.encode(companion).finish();
108
+
109
109
  const registerPayload = {
110
110
  ...getClientPayload(config),
111
111
  passive: false,
112
+ pull: false,
112
113
  devicePairingData: {
113
114
  buildHash: appVersionBuf,
114
115
  deviceProps: companionProto,
@@ -123,6 +124,7 @@ const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentity
123
124
  return WAProto_1.proto.ClientPayload.fromObject(registerPayload);
124
125
  };
125
126
  exports.generateRegistrationNode = generateRegistrationNode;
127
+
126
128
  const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, signalIdentities }) => {
127
129
  const msgId = stanza.attrs.id;
128
130
  const pairSuccessNode = (0, WABinary_1.getBinaryNodeChild)(stanza, 'pair-success');
@@ -130,30 +132,52 @@ const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, s
130
132
  const platformNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'platform');
131
133
  const deviceNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'device');
132
134
  const businessNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'biz');
135
+
133
136
  if (!deviceIdentityNode || !deviceNode) {
134
137
  throw new boom_1.Boom('Missing device-identity or device in pair success node', { data: stanza });
135
138
  }
136
- const bizName = businessNode === null || businessNode === void 0 ? void 0 : businessNode.attrs.name;
139
+
140
+ const bizName = businessNode?.attrs.name;
137
141
  const jid = deviceNode.attrs.jid;
138
- const { details, hmac } = WAProto_1.proto.ADVSignedDeviceIdentityHMAC.decode(deviceIdentityNode.content);
139
- // check HMAC matches
140
- const advSign = (0, crypto_2.hmacSign)(details, Buffer.from(advSecretKey, 'base64'));
142
+ const lid = deviceNode.attrs.lid;
143
+
144
+ const { details, hmac, accountType } = WAProto_1.proto.ADVSignedDeviceIdentityHMAC.decode(deviceIdentityNode.content);
145
+
146
+ let hmacPrefix = Buffer.from([]);
147
+ if (accountType !== undefined && accountType === WAProto_1.proto.ADVEncryptionType.HOSTED) {
148
+ hmacPrefix = Buffer.from([0x06, 0x05]);
149
+ }
150
+
151
+ const advSign = (0, crypto_2.hmacSign)(Buffer.concat([hmacPrefix, details]), Buffer.from(advSecretKey, 'base64'));
141
152
  if (Buffer.compare(hmac, advSign) !== 0) {
142
153
  throw new boom_1.Boom('Invalid account signature');
143
154
  }
155
+
144
156
  const account = WAProto_1.proto.ADVSignedDeviceIdentity.decode(details);
145
157
  const { accountSignatureKey, accountSignature, details: deviceDetails } = account;
146
- // verify the device signature matches
147
- const accountMsg = Buffer.concat([Buffer.from([6, 0]), deviceDetails, signedIdentityKey.public]);
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]);
164
+ const accountMsg = Buffer.concat([accountSignaturePrefix, deviceDetails, signedIdentityKey.public]);
165
+
148
166
  if (!crypto_2.Curve.verify(accountSignatureKey, accountMsg, accountSignature)) {
149
167
  throw new boom_1.Boom('Failed to verify account signature');
150
168
  }
151
- // sign the details with our identity key
152
- const deviceMsg = Buffer.concat([Buffer.from([6, 1]), deviceDetails, signedIdentityKey.public, accountSignatureKey]);
169
+
170
+ const deviceMsg = Buffer.concat([
171
+ Buffer.from([0x06, 0x01]),
172
+ deviceDetails,
173
+ signedIdentityKey.public,
174
+ accountSignatureKey
175
+ ]);
153
176
  account.deviceSignature = crypto_2.Curve.sign(signedIdentityKey.private, deviceMsg);
177
+
154
178
  const identity = (0, signal_1.createSignalIdentity)(jid, accountSignatureKey);
155
179
  const accountEnc = (0, exports.encodeSignedDeviceIdentity)(account, false);
156
- const deviceIdentity = WAProto_1.proto.ADVDeviceIdentity.decode(account.details);
180
+
157
181
  const reply = {
158
182
  tag: 'iq',
159
183
  attrs: {
@@ -175,31 +199,31 @@ const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, s
175
199
  }
176
200
  ]
177
201
  };
202
+
178
203
  const authUpdate = {
179
204
  account,
180
- me: { id: jid, name: bizName },
205
+ me: { id: jid, name: bizName, lid },
181
206
  signalIdentities: [
182
207
  ...(signalIdentities || []),
183
208
  identity
184
209
  ],
185
- platform: platformNode === null || platformNode === void 0 ? void 0 : platformNode.attrs.name
210
+ platform: platformNode?.attrs.name
186
211
  };
212
+
187
213
  return {
188
214
  creds: authUpdate,
189
215
  reply
190
216
  };
191
217
  };
192
218
  exports.configureSuccessfulPairing = configureSuccessfulPairing;
219
+
193
220
  const encodeSignedDeviceIdentity = (account, includeSignatureKey) => {
194
- var _a;
195
221
  account = { ...account };
196
- // set to null if we are not to include the signature key
197
- // or if we are including the signature key but it is empty
198
- if (!includeSignatureKey || !((_a = account.accountSignatureKey) === null || _a === void 0 ? void 0 : _a.length)) {
222
+ if (!includeSignatureKey || !account.accountSignatureKey?.length) {
199
223
  account.accountSignatureKey = null;
200
224
  }
201
225
  return WAProto_1.proto.ADVSignedDeviceIdentity
202
226
  .encode(account)
203
227
  .finish();
204
228
  };
205
- exports.encodeSignedDeviceIdentity = encodeSignedDeviceIdentity;
229
+ exports.encodeSignedDeviceIdentity = encodeSignedDeviceIdentity;