@vinzsocket/baileys 2.8.10 → 2.8.20

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 (83) hide show
  1. package/lib/Defaults/index.js +75 -73
  2. package/lib/Signal/Group/ciphertext-message.js +9 -9
  3. package/lib/Signal/Group/group-session-builder.js +21 -21
  4. package/lib/Signal/Group/group_cipher.js +79 -81
  5. package/lib/Signal/Group/index.js +2 -2
  6. package/lib/Signal/Group/keyhelper.js +9 -9
  7. package/lib/Signal/Group/queue-job.js +43 -46
  8. package/lib/Signal/Group/sender-chain-key.js +24 -25
  9. package/lib/Signal/Group/sender-key-distribution-message.js +50 -58
  10. package/lib/Signal/Group/sender-key-message.js +55 -60
  11. package/lib/Signal/Group/sender-key-name.js +38 -39
  12. package/lib/Signal/Group/sender-key-record.js +39 -41
  13. package/lib/Signal/Group/sender-key-state.js +85 -89
  14. package/lib/Signal/Group/sender-message-key.js +22 -22
  15. package/lib/Signal/libsignal.js +387 -292
  16. package/lib/Signal/lid-mapping.js +98 -93
  17. package/lib/Socket/Client/types.js +6 -6
  18. package/lib/Socket/Client/websocket.js +44 -44
  19. package/lib/Socket/business.js +350 -365
  20. package/lib/Socket/chats.js +1019 -914
  21. package/lib/Socket/communities.js +454 -376
  22. package/lib/Socket/groups.js +378 -310
  23. package/lib/Socket/index.js +11 -11
  24. package/lib/Socket/messages-recv.js +1355 -1182
  25. package/lib/Socket/messages-send.js +1224 -1081
  26. package/lib/Socket/mex.js +40 -34
  27. package/lib/Socket/newsletter.js +212 -169
  28. package/lib/Socket/socket.js +896 -757
  29. package/lib/Store/index.js +1 -1
  30. package/lib/Store/make-cache-manager-store.js +75 -79
  31. package/lib/Store/make-in-memory-store.js +450 -389
  32. package/lib/Store/make-ordered-dictionary.js +73 -76
  33. package/lib/Store/object-repository.js +24 -22
  34. package/lib/Types/Chat.js +1 -7
  35. package/lib/Types/Label.js +20 -20
  36. package/lib/Types/LabelAssociation.js +2 -2
  37. package/lib/Types/Message.js +2 -2
  38. package/lib/Types/Newsletter.js +24 -24
  39. package/lib/Types/Socket.js +1 -1
  40. package/lib/Types/State.js +8 -8
  41. package/lib/Types/index.js +10 -10
  42. package/lib/Utils/auth-utils.js +408 -401
  43. package/lib/Utils/baileys-event-stream.js +44 -35
  44. package/lib/Utils/business.js +200 -197
  45. package/lib/Utils/chat-utils.js +775 -708
  46. package/lib/Utils/crypto.js +97 -85
  47. package/lib/Utils/decode-wa-message.js +240 -227
  48. package/lib/Utils/event-buffer.js +547 -518
  49. package/lib/Utils/extended-messages.js +250 -203
  50. package/lib/Utils/generics.js +300 -289
  51. package/lib/Utils/history.js +76 -69
  52. package/lib/Utils/lid-resolver.js +47 -42
  53. package/lib/Utils/link-preview.js +75 -65
  54. package/lib/Utils/logger.js +3 -1
  55. package/lib/Utils/lt-hash.js +38 -34
  56. package/lib/Utils/make-mutex.js +32 -34
  57. package/lib/Utils/mention.js +79 -86
  58. package/lib/Utils/message-retry-manager.js +148 -136
  59. package/lib/Utils/messages-media.js +652 -562
  60. package/lib/Utils/messages.js +753 -707
  61. package/lib/Utils/noise-handler.js +156 -135
  62. package/lib/Utils/process-message.js +404 -341
  63. package/lib/Utils/signal.js +180 -118
  64. package/lib/Utils/use-multi-file-auth-state.js +87 -91
  65. package/lib/Utils/validate-connection.js +167 -142
  66. package/lib/WABinary/constants.js +28 -1293
  67. package/lib/WABinary/decode.js +220 -218
  68. package/lib/WABinary/encode.js +199 -201
  69. package/lib/WABinary/generic-utils.js +80 -77
  70. package/lib/WABinary/jid-utils.js +41 -35
  71. package/lib/WAM/BinaryInfo.js +7 -7
  72. package/lib/WAM/constants.js +1 -15241
  73. package/lib/WAM/encode.js +124 -131
  74. package/lib/WAUSync/Protocols/USyncContactProtocol.js +23 -23
  75. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +51 -47
  76. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +22 -22
  77. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +30 -32
  78. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +19 -19
  79. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -43
  80. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +17 -17
  81. package/lib/WAUSync/USyncQuery.js +82 -84
  82. package/lib/WAUSync/USyncUser.js +20 -20
  83. package/package.json +5 -2
@@ -6,160 +6,185 @@ import { getBinaryNodeChild, jidDecode, S_WHATSAPP_NET } from '../WABinary/index
6
6
  import { Curve, hmacSign } from './crypto.js';
7
7
  import { encodeBigEndian } from './generics.js';
8
8
  import { createSignalIdentity } from './signal.js';
9
- const getUserAgent = (config) => {
10
- return {
11
- appVersion: {
12
- primary: config.version[0],
13
- secondary: config.version[1],
14
- tertiary: config.version[2]
15
- },
16
- platform: proto.ClientPayload.UserAgent.Platform.WEB,
17
- releaseChannel: proto.ClientPayload.UserAgent.ReleaseChannel.RELEASE,
18
- osVersion: '0.1',
19
- device: 'Desktop',
20
- osBuildNumber: '0.1',
21
- localeLanguageIso6391: 'en',
22
- mnc: '000',
23
- mcc: '000',
24
- localeCountryIso31661Alpha2: config.countryCode
25
- };
9
+ const getUserAgent = config => {
10
+ return {
11
+ appVersion: {
12
+ primary: config.version[0],
13
+ secondary: config.version[1],
14
+ tertiary: config.version[2]
15
+ },
16
+ platform: proto.ClientPayload.UserAgent.Platform.WEB,
17
+ releaseChannel: proto.ClientPayload.UserAgent.ReleaseChannel.RELEASE,
18
+ osVersion: '0.1',
19
+ device: 'Desktop',
20
+ osBuildNumber: '0.1',
21
+ localeLanguageIso6391: 'en',
22
+ mnc: '000',
23
+ mcc: '000',
24
+ localeCountryIso31661Alpha2: config.countryCode
25
+ };
26
26
  };
27
27
  const PLATFORM_MAP = {
28
- 'Mac OS': proto.ClientPayload.WebInfo.WebSubPlatform.DARWIN,
29
- Windows: proto.ClientPayload.WebInfo.WebSubPlatform.WIN32
28
+ 'Mac OS': proto.ClientPayload.WebInfo.WebSubPlatform.DARWIN,
29
+ Windows: proto.ClientPayload.WebInfo.WebSubPlatform.WIN32
30
30
  };
31
- const getWebInfo = (config) => {
32
- let webSubPlatform = proto.ClientPayload.WebInfo.WebSubPlatform.WEB_BROWSER;
33
- if (config.syncFullHistory && PLATFORM_MAP[config.browser[0]]) {
34
- webSubPlatform = PLATFORM_MAP[config.browser[0]];
35
- }
36
- return { webSubPlatform };
31
+ const getWebInfo = config => {
32
+ let webSubPlatform = proto.ClientPayload.WebInfo.WebSubPlatform.WEB_BROWSER;
33
+ if (config.syncFullHistory && PLATFORM_MAP[config.browser[0]]) {
34
+ webSubPlatform = PLATFORM_MAP[config.browser[0]];
35
+ }
36
+ return {
37
+ webSubPlatform
38
+ };
37
39
  };
38
- const getClientPayload = (config) => {
39
- const payload = {
40
- connectType: proto.ClientPayload.ConnectType.WIFI_UNKNOWN,
41
- connectReason: proto.ClientPayload.ConnectReason.USER_ACTIVATED,
42
- userAgent: getUserAgent(config)
43
- };
44
- payload.webInfo = getWebInfo(config);
45
- return payload;
40
+ const getClientPayload = config => {
41
+ const payload = {
42
+ connectType: proto.ClientPayload.ConnectType.WIFI_UNKNOWN,
43
+ connectReason: proto.ClientPayload.ConnectReason.USER_ACTIVATED,
44
+ userAgent: getUserAgent(config)
45
+ };
46
+ payload.webInfo = getWebInfo(config);
47
+ return payload;
46
48
  };
47
49
  export const generateLoginNode = (userJid, config) => {
48
- const { user, device } = jidDecode(userJid);
49
- const payload = {
50
- ...getClientPayload(config),
51
- passive: false,
52
- pull: true,
53
- username: +user,
54
- device: device
55
- };
56
- return proto.ClientPayload.create(payload);
50
+ const {
51
+ user,
52
+ device
53
+ } = jidDecode(userJid);
54
+ const payload = {
55
+ ...getClientPayload(config),
56
+ passive: false,
57
+ pull: true,
58
+ username: +user,
59
+ device: device
60
+ };
61
+ return proto.ClientPayload.create(payload);
57
62
  };
58
- const getPlatformType = (platform) => {
59
- const platformType = platform.toUpperCase();
60
- return (proto.DeviceProps.PlatformType[platformType] ||
61
- proto.DeviceProps.PlatformType.DESKTOP);
63
+ const getPlatformType = platform => {
64
+ const platformType = platform.toUpperCase();
65
+ return proto.DeviceProps.PlatformType[platformType] || proto.DeviceProps.PlatformType.DESKTOP;
62
66
  };
63
- export const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentityKey }, config) => {
64
- // the app version needs to be md5 hashed
65
- // and passed in
66
- const appVersionBuf = createHash('md5')
67
- .update(config.version.join('.')) // join as string
68
- .digest();
69
- const companion = {
70
- os: config.browser[0],
71
- platformType: getPlatformType(config.browser[1]),
72
- requireFullSync: config.syncFullHistory
73
- };
74
- const companionProto = proto.DeviceProps.encode(companion).finish();
75
- const registerPayload = {
76
- ...getClientPayload(config),
77
- passive: false,
78
- pull: false,
79
- devicePairingData: {
80
- buildHash: appVersionBuf,
81
- deviceProps: companionProto,
82
- eRegid: encodeBigEndian(registrationId),
83
- eKeytype: KEY_BUNDLE_TYPE,
84
- eIdent: signedIdentityKey.public,
85
- eSkeyId: encodeBigEndian(signedPreKey.keyId, 3),
86
- eSkeyVal: signedPreKey.keyPair.public,
87
- eSkeySig: signedPreKey.signature
88
- }
89
- };
90
- return proto.ClientPayload.create(registerPayload);
91
- };
92
- export const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, signalIdentities }) => {
93
- const msgId = stanza.attrs.id;
94
- const pairSuccessNode = getBinaryNodeChild(stanza, 'pair-success');
95
- const deviceIdentityNode = getBinaryNodeChild(pairSuccessNode, 'device-identity');
96
- const platformNode = getBinaryNodeChild(pairSuccessNode, 'platform');
97
- const deviceNode = getBinaryNodeChild(pairSuccessNode, 'device');
98
- const businessNode = getBinaryNodeChild(pairSuccessNode, 'biz');
99
- if (!deviceIdentityNode || !deviceNode) {
100
- throw new Boom('Missing device-identity or device in pair success node', { data: stanza });
101
- }
102
- const bizName = businessNode?.attrs.name;
103
- const jid = deviceNode.attrs.jid;
104
- const lid = deviceNode.attrs.lid;
105
- const { details, hmac, accountType } = proto.ADVSignedDeviceIdentityHMAC.decode(deviceIdentityNode.content);
106
- const isHostedAccount = accountType !== undefined && accountType === proto.ADVEncryptionType.HOSTED;
107
- const hmacPrefix = isHostedAccount ? Buffer.from([6, 5]) : Buffer.alloc(0);
108
- const advSign = hmacSign(Buffer.concat([hmacPrefix, details]), Buffer.from(advSecretKey, 'base64'));
109
- if (Buffer.compare(hmac, advSign) !== 0) {
110
- throw new Boom('Invalid account signature');
67
+ export const generateRegistrationNode = ({
68
+ registrationId,
69
+ signedPreKey,
70
+ signedIdentityKey
71
+ }, config) => {
72
+ // the app version needs to be md5 hashed
73
+ // and passed in
74
+ const appVersionBuf = createHash('md5').update(config.version.join('.')) // join as string
75
+ .digest();
76
+ const companion = {
77
+ os: config.browser[0],
78
+ platformType: getPlatformType(config.browser[1]),
79
+ requireFullSync: config.syncFullHistory
80
+ };
81
+ const companionProto = proto.DeviceProps.encode(companion).finish();
82
+ const registerPayload = {
83
+ ...getClientPayload(config),
84
+ passive: false,
85
+ pull: false,
86
+ devicePairingData: {
87
+ buildHash: appVersionBuf,
88
+ deviceProps: companionProto,
89
+ eRegid: encodeBigEndian(registrationId),
90
+ eKeytype: KEY_BUNDLE_TYPE,
91
+ eIdent: signedIdentityKey.public,
92
+ eSkeyId: encodeBigEndian(signedPreKey.keyId, 3),
93
+ eSkeyVal: signedPreKey.keyPair.public,
94
+ eSkeySig: signedPreKey.signature
111
95
  }
112
- const account = proto.ADVSignedDeviceIdentity.decode(details);
113
- const { accountSignatureKey, accountSignature, details: deviceDetails } = account;
114
- const accountMsg = Buffer.concat([Buffer.from([6, 0]), deviceDetails, signedIdentityKey.public]);
115
- if (!Curve.verify(accountSignatureKey, accountMsg, accountSignature)) {
116
- throw new Boom('Failed to verify account signature');
117
- }
118
- const devicePrefix = isHostedAccount ? Buffer.from([6, 6]) : Buffer.from([6, 1]);
119
- const deviceMsg = Buffer.concat([devicePrefix, deviceDetails, signedIdentityKey.public, accountSignatureKey]);
120
- account.deviceSignature = Curve.sign(signedIdentityKey.private, deviceMsg);
121
- const identity = createSignalIdentity(lid, accountSignatureKey);
122
- const accountEnc = encodeSignedDeviceIdentity(account, false);
123
- const deviceIdentity = proto.ADVDeviceIdentity.decode(account.details);
124
- const reply = {
125
- tag: 'iq',
96
+ };
97
+ return proto.ClientPayload.create(registerPayload);
98
+ };
99
+ export const configureSuccessfulPairing = (stanza, {
100
+ advSecretKey,
101
+ signedIdentityKey,
102
+ signalIdentities
103
+ }) => {
104
+ const msgId = stanza.attrs.id;
105
+ const pairSuccessNode = getBinaryNodeChild(stanza, 'pair-success');
106
+ const deviceIdentityNode = getBinaryNodeChild(pairSuccessNode, 'device-identity');
107
+ const platformNode = getBinaryNodeChild(pairSuccessNode, 'platform');
108
+ const deviceNode = getBinaryNodeChild(pairSuccessNode, 'device');
109
+ const businessNode = getBinaryNodeChild(pairSuccessNode, 'biz');
110
+ if (!deviceIdentityNode || !deviceNode) {
111
+ throw new Boom('Missing device-identity or device in pair success node', {
112
+ data: stanza
113
+ });
114
+ }
115
+ const bizName = businessNode?.attrs.name;
116
+ const jid = deviceNode.attrs.jid;
117
+ const lid = deviceNode.attrs.lid;
118
+ const {
119
+ details,
120
+ hmac,
121
+ accountType
122
+ } = proto.ADVSignedDeviceIdentityHMAC.decode(deviceIdentityNode.content);
123
+ const isHostedAccount = accountType !== undefined && accountType === proto.ADVEncryptionType.HOSTED;
124
+ const hmacPrefix = isHostedAccount ? Buffer.from([6, 5]) : Buffer.alloc(0);
125
+ const advSign = hmacSign(Buffer.concat([hmacPrefix, details]), Buffer.from(advSecretKey, 'base64'));
126
+ if (Buffer.compare(hmac, advSign) !== 0) {
127
+ throw new Boom('Invalid account signature');
128
+ }
129
+ const account = proto.ADVSignedDeviceIdentity.decode(details);
130
+ const {
131
+ accountSignatureKey,
132
+ accountSignature,
133
+ details: deviceDetails
134
+ } = account;
135
+ const accountMsg = Buffer.concat([Buffer.from([6, 0]), deviceDetails, signedIdentityKey.public]);
136
+ if (!Curve.verify(accountSignatureKey, accountMsg, accountSignature)) {
137
+ throw new Boom('Failed to verify account signature');
138
+ }
139
+ const devicePrefix = isHostedAccount ? Buffer.from([6, 6]) : Buffer.from([6, 1]);
140
+ const deviceMsg = Buffer.concat([devicePrefix, deviceDetails, signedIdentityKey.public, accountSignatureKey]);
141
+ account.deviceSignature = Curve.sign(signedIdentityKey.private, deviceMsg);
142
+ const identity = createSignalIdentity(lid, accountSignatureKey);
143
+ const accountEnc = encodeSignedDeviceIdentity(account, false);
144
+ const deviceIdentity = proto.ADVDeviceIdentity.decode(account.details);
145
+ const reply = {
146
+ tag: 'iq',
147
+ attrs: {
148
+ to: S_WHATSAPP_NET,
149
+ type: 'result',
150
+ id: msgId
151
+ },
152
+ content: [{
153
+ tag: 'pair-device-sign',
154
+ attrs: {},
155
+ content: [{
156
+ tag: 'device-identity',
126
157
  attrs: {
127
- to: S_WHATSAPP_NET,
128
- type: 'result',
129
- id: msgId
158
+ 'key-index': deviceIdentity.keyIndex.toString()
130
159
  },
131
- content: [
132
- {
133
- tag: 'pair-device-sign',
134
- attrs: {},
135
- content: [
136
- {
137
- tag: 'device-identity',
138
- attrs: { 'key-index': deviceIdentity.keyIndex.toString() },
139
- content: accountEnc
140
- }
141
- ]
142
- }
143
- ]
144
- };
145
- const authUpdate = {
146
- account,
147
- me: { id: jid, name: bizName, lid },
148
- signalIdentities: [...(signalIdentities || []), identity],
149
- platform: platformNode?.attrs.name
150
- };
151
- return {
152
- creds: authUpdate,
153
- reply
154
- };
160
+ content: accountEnc
161
+ }]
162
+ }]
163
+ };
164
+ const authUpdate = {
165
+ account,
166
+ me: {
167
+ id: jid,
168
+ name: bizName,
169
+ lid
170
+ },
171
+ signalIdentities: [...(signalIdentities || []), identity],
172
+ platform: platformNode?.attrs.name
173
+ };
174
+ return {
175
+ creds: authUpdate,
176
+ reply
177
+ };
155
178
  };
156
179
  export const encodeSignedDeviceIdentity = (account, includeSignatureKey) => {
157
- account = { ...account };
158
- // set to null if we are not to include the signature key
159
- // or if we are including the signature key but it is empty
160
- if (!includeSignatureKey || !account.accountSignatureKey?.length) {
161
- account.accountSignatureKey = null;
162
- }
163
- return proto.ADVSignedDeviceIdentity.encode(account).finish();
180
+ account = {
181
+ ...account
182
+ };
183
+ // set to null if we are not to include the signature key
184
+ // or if we are including the signature key but it is empty
185
+ if (!includeSignatureKey || !account.accountSignatureKey?.length) {
186
+ account.accountSignatureKey = null;
187
+ }
188
+ return proto.ADVSignedDeviceIdentity.encode(account).finish();
164
189
  };
165
190
  //# sourceMappingURL=validate-connection.js.map