baileys-mood 0.4.2 → 0.5.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 (156) hide show
  1. package/engine-requirements.js +1 -1
  2. package/lib/Defaults/baileys-version.json +3 -0
  3. package/lib/Defaults/index.d.ts +53 -0
  4. package/lib/Defaults/index.js +125 -96
  5. package/lib/Defaults/phonenumber-mcc.json +223 -0
  6. package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
  7. package/lib/Signal/Group/group-session-builder.d.ts +14 -0
  8. package/lib/Signal/Group/group_cipher.d.ts +17 -0
  9. package/lib/Signal/Group/index.d.ts +11 -0
  10. package/lib/Signal/Group/keyhelper.d.ts +10 -0
  11. package/lib/Signal/Group/queue-job.d.ts +1 -0
  12. package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
  13. package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
  14. package/lib/Signal/Group/sender-key-message.d.ts +18 -0
  15. package/lib/Signal/Group/sender-key-name.d.ts +17 -0
  16. package/lib/Signal/Group/sender-key-record.d.ts +30 -0
  17. package/lib/Signal/Group/sender-key-state.d.ts +38 -0
  18. package/lib/Signal/Group/sender-message-key.d.ts +11 -0
  19. package/lib/Signal/libsignal.d.ts +3 -0
  20. package/lib/Socket/Client/abstract-socket-client.d.ts +17 -0
  21. package/lib/Socket/Client/index.d.ts +3 -0
  22. package/lib/Socket/Client/index.js +3 -2
  23. package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
  24. package/lib/Socket/Client/mobile-socket-client.js +65 -0
  25. package/lib/Socket/Client/web-socket-client.d.ts +12 -0
  26. package/lib/Socket/Client/{websocket.js → web-socket-client.js} +5 -54
  27. package/lib/Socket/business.d.ts +171 -0
  28. package/lib/Socket/chats.d.ts +267 -0
  29. package/lib/Socket/chats.js +320 -265
  30. package/lib/Socket/dugong.d.ts +254 -0
  31. package/lib/Socket/dugong.js +484 -0
  32. package/lib/Socket/groups.d.ts +115 -0
  33. package/lib/Socket/groups.js +23 -38
  34. package/lib/Socket/index.d.ts +173 -0
  35. package/lib/Socket/index.js +3 -2
  36. package/lib/Socket/messages-recv.d.ts +161 -0
  37. package/lib/Socket/messages-recv.js +66 -10
  38. package/lib/Socket/messages-send.d.ts +149 -0
  39. package/lib/Socket/messages-send.js +419 -382
  40. package/lib/Socket/newsletter.d.ts +134 -0
  41. package/lib/Socket/newsletter.js +210 -72
  42. package/lib/Socket/registration.d.ts +267 -0
  43. package/lib/Socket/registration.js +166 -0
  44. package/lib/Socket/socket.d.ts +43 -0
  45. package/lib/Socket/socket.js +34 -8
  46. package/lib/Socket/usync.d.ts +36 -0
  47. package/lib/Store/index.d.ts +3 -0
  48. package/lib/Store/index.js +3 -1
  49. package/lib/Store/make-cache-manager-store.d.ts +13 -0
  50. package/lib/Store/make-cache-manager-store.js +83 -0
  51. package/lib/Store/make-in-memory-store.d.ts +118 -0
  52. package/lib/Store/make-in-memory-store.js +15 -27
  53. package/lib/Store/make-ordered-dictionary.d.ts +13 -0
  54. package/lib/Store/make-ordered-dictionary.js +2 -2
  55. package/lib/Store/object-repository.d.ts +10 -0
  56. package/lib/Types/Auth.d.ts +110 -0
  57. package/lib/Types/Call.d.ts +13 -0
  58. package/lib/Types/Chat.d.ts +102 -0
  59. package/lib/Types/Contact.d.ts +19 -0
  60. package/lib/Types/Events.d.ts +157 -0
  61. package/lib/Types/GroupMetadata.d.ts +55 -0
  62. package/lib/Types/Label.d.ts +35 -0
  63. package/lib/Types/Label.js +1 -1
  64. package/lib/Types/LabelAssociation.d.ts +29 -0
  65. package/lib/Types/LabelAssociation.js +1 -1
  66. package/lib/Types/Message.d.ts +273 -0
  67. package/lib/Types/Message.js +2 -0
  68. package/lib/Types/Newsletter.d.ts +103 -0
  69. package/lib/Types/Newsletter.js +38 -18
  70. package/lib/Types/Product.d.ts +78 -0
  71. package/lib/Types/Signal.d.ts +57 -0
  72. package/lib/Types/Socket.d.ts +111 -0
  73. package/lib/Types/State.d.ts +27 -0
  74. package/lib/Types/USync.d.ts +25 -0
  75. package/lib/Types/index.d.ts +57 -0
  76. package/lib/Types/index.js +2 -2
  77. package/lib/Utils/auth-utils.d.ts +18 -0
  78. package/lib/Utils/auth-utils.js +13 -6
  79. package/lib/Utils/baileys-event-stream.d.ts +16 -0
  80. package/lib/Utils/{wileys-event-stream.js → baileys-event-stream.js} +1 -1
  81. package/lib/Utils/business.d.ts +22 -0
  82. package/lib/Utils/business.js +2 -2
  83. package/lib/Utils/chat-utils.d.ts +71 -0
  84. package/lib/Utils/chat-utils.js +35 -36
  85. package/lib/Utils/crypto.d.ts +41 -0
  86. package/lib/Utils/crypto.js +29 -71
  87. package/lib/Utils/decode-wa-message.d.ts +19 -0
  88. package/lib/Utils/decode-wa-message.js +56 -65
  89. package/lib/Utils/event-buffer.d.ts +35 -0
  90. package/lib/Utils/event-buffer.js +9 -13
  91. package/lib/Utils/generics.d.ts +92 -0
  92. package/lib/Utils/generics.js +86 -125
  93. package/lib/Utils/generics.js.bak +433 -0
  94. package/lib/Utils/history.d.ts +15 -0
  95. package/lib/Utils/history.js +6 -4
  96. package/lib/Utils/index.d.ts +17 -0
  97. package/lib/Utils/index.js +1 -3
  98. package/lib/Utils/link-preview.d.ts +21 -0
  99. package/lib/Utils/link-preview.js +1 -34
  100. package/lib/Utils/logger.d.ts +4 -0
  101. package/lib/Utils/lt-hash.d.ts +12 -0
  102. package/lib/Utils/lt-hash.js +6 -6
  103. package/lib/Utils/make-mutex.d.ts +7 -0
  104. package/lib/Utils/messages-media.d.ts +116 -0
  105. package/lib/Utils/messages-media.js +236 -296
  106. package/lib/Utils/messages.d.ts +77 -0
  107. package/lib/Utils/messages.js +92 -325
  108. package/lib/Utils/noise-handler.d.ts +21 -0
  109. package/lib/Utils/noise-handler.js +23 -18
  110. package/lib/Utils/process-message.d.ts +41 -0
  111. package/lib/Utils/process-message.js +25 -108
  112. package/lib/Utils/signal.d.ts +32 -0
  113. package/lib/Utils/signal.js +26 -26
  114. package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
  115. package/lib/Utils/use-multi-file-auth-state.js +0 -6
  116. package/lib/Utils/validate-connection.d.ts +11 -0
  117. package/lib/Utils/validate-connection.js +3 -1
  118. package/lib/Utils/validate-connection.js.bak +237 -0
  119. package/lib/WABinary/constants.d.ts +30 -0
  120. package/lib/WABinary/constants.js +13 -1276
  121. package/lib/WABinary/decode.d.ts +7 -0
  122. package/lib/WABinary/decode.js +13 -26
  123. package/lib/WABinary/encode.d.ts +3 -0
  124. package/lib/WABinary/encode.js +152 -137
  125. package/lib/WABinary/generic-utils.d.ts +17 -0
  126. package/lib/WABinary/generic-utils.js +125 -37
  127. package/lib/WABinary/index.d.ts +5 -0
  128. package/lib/WABinary/jid-utils.d.ts +31 -0
  129. package/lib/WABinary/jid-utils.js +5 -28
  130. package/lib/WABinary/types.d.ts +18 -0
  131. package/lib/WAM/BinaryInfo.d.ts +17 -0
  132. package/lib/WAM/constants.d.ts +38 -0
  133. package/lib/WAM/encode.d.ts +3 -0
  134. package/lib/WAM/index.d.ts +3 -0
  135. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
  136. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
  137. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
  138. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +1 -1
  139. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
  140. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +25 -0
  141. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +8 -0
  142. package/lib/WAUSync/Protocols/index.d.ts +4 -0
  143. package/lib/WAUSync/USyncQuery.d.ts +28 -0
  144. package/lib/WAUSync/USyncUser.d.ts +12 -0
  145. package/lib/WAUSync/index.d.ts +3 -0
  146. package/lib/index.d.ts +12 -0
  147. package/lib/index.js +7 -19
  148. package/package.json +100 -105
  149. package/LICENSE +0 -21
  150. package/WAProto/GenerateStatics.sh +0 -4
  151. package/WAProto/WAProto.proto +0 -4775
  152. package/WAProto/p.html +0 -1
  153. package/lib/Defaults/wileys-version.json +0 -3
  154. package/lib/Utils/browser-utils.js +0 -35
  155. package/lib/Utils/message-retry-manager.js +0 -128
  156. /package/lib/Socket/Client/{types.js → abstract-socket-client.js} +0 -0
@@ -0,0 +1,237 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.encodeSignedDeviceIdentity = exports.configureSuccessfulPairing = exports.generateRegistrationNode = exports.generateLoginNode = void 0;
4
+ const boom_1 = require("@hapi/boom");
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
+
13
+ const getUserAgent = (config) => {
14
+ return {
15
+ appVersion: {
16
+ primary: config.version[0],
17
+ secondary: config.version[1],
18
+ tertiary: config.version[2],
19
+ },
20
+ platform: WAProto_1.proto.ClientPayload.UserAgent.Platform.WEB,
21
+ releaseChannel: WAProto_1.proto.ClientPayload.UserAgent.ReleaseChannel.RELEASE,
22
+ osVersion: '0.1',
23
+ device: 'Desktop',
24
+ osBuildNumber: '0.1',
25
+ localeLanguageIso6391: 'en',
26
+ mnc: '000',
27
+ mcc: '000',
28
+ localeCountryIso31661Alpha2: config.countryCode || 'US'
29
+ };
30
+ };
31
+
32
+ exports.Browsers = {
33
+ iOS: (browser) => ["ios", browser, "18.2"],
34
+ ubuntu: (browser) => ['Ubuntu', browser, '22.04.4'],
35
+ macOS: (browser) => ['Mac OS', browser, '14.4.1'],
36
+ baileys: (browser) => ['Baileys', browser, '6.5.0'],
37
+ windows: (browser) => ['Windows', browser, '10.0.22631']
38
+ };
39
+
40
+ const PLATFORM_MAP = {
41
+ 'Mac OS': WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.DARWIN,
42
+ 'Windows': WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.WIN32
43
+ };
44
+
45
+ const getWebInfo = (config) => {
46
+ let webSubPlatform = WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.WEB_BROWSER;
47
+ if (config.syncFullHistory && PLATFORM_MAP[config.browser[0]] && config.browser[1] === 'Desktop') {
48
+ webSubPlatform = PLATFORM_MAP[config.browser[0]];
49
+ }
50
+ return { webSubPlatform };
51
+ };
52
+
53
+ const getClientPayload = (config) => {
54
+ const payload = {
55
+ connectType: WAProto_1.proto.ClientPayload.ConnectType.WIFI_UNKNOWN,
56
+ connectReason: WAProto_1.proto.ClientPayload.ConnectReason.USER_ACTIVATED,
57
+ userAgent: getUserAgent(config),
58
+ };
59
+ payload.webInfo = getWebInfo(config);
60
+ return payload;
61
+ };
62
+
63
+ const generateLoginNode = (userJid, config) => {
64
+ const { user, device } = (0, WABinary_1.jidDecode)(userJid);
65
+ const payload = {
66
+ ...getClientPayload(config),
67
+ passive: true,
68
+ pull: true,
69
+ username: +user,
70
+ device: device,
71
+ lidDbMigrated: false
72
+ };
73
+ return WAProto_1.proto.ClientPayload.fromObject(payload);
74
+ };
75
+ exports.generateLoginNode = generateLoginNode;
76
+
77
+ const getPlatformType = (platform) => {
78
+ const platformType = platform.toUpperCase();
79
+ return WAProto_1.proto.DeviceProps.PlatformType[platformType] || WAProto_1.proto.DeviceProps.PlatformType.CHROME;
80
+ };
81
+
82
+ const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentityKey }, config) => {
83
+ const appVersionBuf = (0, crypto_1.createHash)('md5')
84
+ .update(config.version.join('.'))
85
+ .digest();
86
+
87
+ const companion = {
88
+ os: config.browser[0],
89
+ platformType: getPlatformType(config.browser[1]),
90
+ requireFullSync: config.syncFullHistory,
91
+ historySyncConfig: {
92
+ storageQuotaMb: 10240,
93
+ inlineInitialPayloadInE2EeMsg: true,
94
+ recentSyncDaysLimit: undefined,
95
+ supportCallLogHistory: false,
96
+ supportBotUserAgentChatHistory: true,
97
+ supportCagReactionsAndPolls: true,
98
+ supportBizHostedMsg: true,
99
+ supportRecentSyncChunkMessageCountTuning: true,
100
+ supportHostedGroupMsg: true,
101
+ supportFbidBotChatHistory: true,
102
+ supportAddOnHistorySyncMigration: undefined,
103
+ supportMessageAssociation: true,
104
+ supportGroupHistory: false,
105
+ onDemandReady: undefined,
106
+ supportGuestChat: undefined
107
+ },
108
+ version: {
109
+ primary: 10,
110
+ secondary: 15,
111
+ tertiary: 7
112
+ }
113
+ };
114
+
115
+ const companionProto = WAProto_1.proto.DeviceProps.encode(companion).finish();
116
+
117
+ const registerPayload = {
118
+ ...getClientPayload(config),
119
+ passive: false,
120
+ pull: false,
121
+ devicePairingData: {
122
+ buildHash: appVersionBuf,
123
+ deviceProps: companionProto,
124
+ eRegid: (0, generics_1.encodeBigEndian)(registrationId),
125
+ eKeytype: Defaults_1.KEY_BUNDLE_TYPE,
126
+ eIdent: signedIdentityKey.public,
127
+ eSkeyId: (0, generics_1.encodeBigEndian)(signedPreKey.keyId, 3),
128
+ eSkeyVal: signedPreKey.keyPair.public,
129
+ eSkeySig: signedPreKey.signature,
130
+ },
131
+ };
132
+ return WAProto_1.proto.ClientPayload.fromObject(registerPayload);
133
+ };
134
+ exports.generateRegistrationNode = generateRegistrationNode;
135
+
136
+ const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, signalIdentities }) => {
137
+ const msgId = stanza.attrs.id;
138
+ const pairSuccessNode = (0, WABinary_1.getBinaryNodeChild)(stanza, 'pair-success');
139
+ const deviceIdentityNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'device-identity');
140
+ const platformNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'platform');
141
+ const deviceNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'device');
142
+ const businessNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'biz');
143
+
144
+ if (!deviceIdentityNode || !deviceNode) {
145
+ throw new boom_1.Boom('Missing device-identity or device in pair success node', { data: stanza });
146
+ }
147
+
148
+ const bizName = businessNode?.attrs.name;
149
+ const jid = deviceNode.attrs.jid;
150
+ const lid = deviceNode.attrs.lid;
151
+
152
+ const { details, hmac, accountType } = WAProto_1.proto.ADVSignedDeviceIdentityHMAC.decode(deviceIdentityNode.content);
153
+
154
+ let hmacPrefix = Buffer.from([]);
155
+ if (accountType !== undefined && accountType === WAProto_1.proto.ADVEncryptionType.HOSTED) {
156
+ hmacPrefix = Buffer.from([0x06, 0x05]);
157
+ }
158
+
159
+ const advSign = (0, crypto_2.hmacSign)(Buffer.concat([hmacPrefix, details]), Buffer.from(advSecretKey, 'base64'));
160
+ if (Buffer.compare(hmac, advSign) !== 0) {
161
+ throw new boom_1.Boom('Invalid account signature');
162
+ }
163
+
164
+ const account = WAProto_1.proto.ADVSignedDeviceIdentity.decode(details);
165
+ const { accountSignatureKey, accountSignature, details: deviceDetails } = account;
166
+
167
+ const deviceIdentity = WAProto_1.proto.ADVDeviceIdentity.decode(deviceDetails);
168
+
169
+ const accountSignaturePrefix = deviceIdentity.deviceType === WAProto_1.proto.ADVEncryptionType.HOSTED
170
+ ? Buffer.from([0x06, 0x05])
171
+ : Buffer.from([0x06, 0x00]);
172
+ const accountMsg = Buffer.concat([accountSignaturePrefix, deviceDetails, signedIdentityKey.public]);
173
+
174
+ if (!crypto_2.Curve.verify(accountSignatureKey, accountMsg, accountSignature)) {
175
+ throw new boom_1.Boom('Failed to verify account signature');
176
+ }
177
+
178
+ const deviceMsg = Buffer.concat([
179
+ Buffer.from([0x06, 0x01]),
180
+ deviceDetails,
181
+ signedIdentityKey.public,
182
+ accountSignatureKey
183
+ ]);
184
+ account.deviceSignature = crypto_2.Curve.sign(signedIdentityKey.private, deviceMsg);
185
+
186
+ const identity = (0, signal_1.createSignalIdentity)(jid, accountSignatureKey);
187
+ const accountEnc = (0, exports.encodeSignedDeviceIdentity)(account, false);
188
+
189
+ const reply = {
190
+ tag: 'iq',
191
+ attrs: {
192
+ to: WABinary_1.S_WHATSAPP_NET,
193
+ type: 'result',
194
+ id: msgId,
195
+ },
196
+ content: [
197
+ {
198
+ tag: 'pair-device-sign',
199
+ attrs: {},
200
+ content: [
201
+ {
202
+ tag: 'device-identity',
203
+ attrs: { 'key-index': deviceIdentity.keyIndex.toString() },
204
+ content: accountEnc
205
+ }
206
+ ]
207
+ }
208
+ ]
209
+ };
210
+
211
+ const authUpdate = {
212
+ account,
213
+ me: { id: jid, name: bizName, lid },
214
+ signalIdentities: [
215
+ ...(signalIdentities || []),
216
+ identity
217
+ ],
218
+ platform: platformNode?.attrs.name
219
+ };
220
+
221
+ return {
222
+ creds: authUpdate,
223
+ reply
224
+ };
225
+ };
226
+ exports.configureSuccessfulPairing = configureSuccessfulPairing;
227
+
228
+ const encodeSignedDeviceIdentity = (account, includeSignatureKey) => {
229
+ account = { ...account };
230
+ if (!includeSignatureKey || !account.accountSignatureKey?.length) {
231
+ account.accountSignatureKey = null;
232
+ }
233
+ return WAProto_1.proto.ADVSignedDeviceIdentity
234
+ .encode(account)
235
+ .finish();
236
+ };
237
+ exports.encodeSignedDeviceIdentity = encodeSignedDeviceIdentity;
@@ -0,0 +1,30 @@
1
+ export declare const TAGS: {
2
+ LIST_EMPTY: number
3
+ DICTIONARY_0: number
4
+ DICTIONARY_1: number
5
+ DICTIONARY_2: number
6
+ DICTIONARY_3: number
7
+ INTEROP_JID: number
8
+ FB_JID: number
9
+ AD_JID: number
10
+ LIST_8: number
11
+ LIST_16: number
12
+ JID_PAIR: number
13
+ HEX_8: number
14
+ BINARY_8: number
15
+ BINARY_20: number
16
+ BINARY_32: number
17
+ NIBBLE_8: number
18
+ PACKED_MAX: number
19
+ }
20
+
21
+ export declare const DOUBLE_BYTE_TOKENS: string[][]
22
+
23
+ export declare const SINGLE_BYTE_TOKENS: (string | null)[]
24
+
25
+ export declare const TOKEN_MAP: {
26
+ [token: string]: {
27
+ dict?: number
28
+ index: number
29
+ }
30
+ }