@mrlegendbot/baileys 1.2.5 → 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 (214) hide show
  1. package/WAProto/GenerateStatics.sh +3 -0
  2. package/WAProto/fix-imports.js +85 -0
  3. package/WAProto/index.d.ts +14017 -0
  4. package/WAProto/index.js +97691 -2
  5. package/lib/Defaults/index.d.ts +75 -0
  6. package/lib/Defaults/index.js +92 -89
  7. package/lib/Menu/index.d.ts +42 -0
  8. package/lib/Menu/index.js +283 -0
  9. package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
  10. package/lib/Signal/Group/ciphertext-message.js +10 -9
  11. package/lib/Signal/Group/group-session-builder.d.ts +15 -0
  12. package/lib/Signal/Group/group-session-builder.js +22 -21
  13. package/lib/Signal/Group/group_cipher.d.ts +17 -0
  14. package/lib/Signal/Group/group_cipher.js +69 -75
  15. package/lib/Signal/Group/index.d.ts +12 -0
  16. package/lib/Signal/Group/index.js +1 -0
  17. package/lib/Signal/Group/keyhelper.d.ts +11 -0
  18. package/lib/Signal/Group/keyhelper.js +10 -9
  19. package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
  20. package/lib/Signal/Group/sender-chain-key.js +22 -21
  21. package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
  22. package/lib/Signal/Group/sender-key-distribution-message.js +60 -51
  23. package/lib/Signal/Group/sender-key-message.d.ts +19 -0
  24. package/lib/Signal/Group/sender-key-message.js +62 -56
  25. package/lib/Signal/Group/sender-key-name.d.ts +18 -0
  26. package/lib/Signal/Group/sender-key-name.js +40 -38
  27. package/lib/Signal/Group/sender-key-record.d.ts +31 -0
  28. package/lib/Signal/Group/sender-key-record.js +34 -33
  29. package/lib/Signal/Group/sender-key-state.d.ts +39 -0
  30. package/lib/Signal/Group/sender-key-state.js +76 -72
  31. package/lib/Signal/Group/sender-message-key.d.ts +12 -0
  32. package/lib/Signal/Group/sender-message-key.js +23 -22
  33. package/lib/Signal/libsignal.d.ts +5 -0
  34. package/lib/Signal/libsignal.js +405 -506
  35. package/lib/Signal/lid-mapping.d.ts +23 -0
  36. package/lib/Signal/lid-mapping.js +258 -276
  37. package/lib/Socket/Client/index.d.ts +3 -0
  38. package/lib/Socket/Client/index.js +1 -0
  39. package/lib/Socket/Client/types.d.ts +16 -0
  40. package/lib/Socket/Client/types.js +7 -6
  41. package/lib/Socket/Client/websocket.d.ts +13 -0
  42. package/lib/Socket/Client/websocket.js +49 -48
  43. package/lib/Socket/business.d.ts +217 -0
  44. package/lib/Socket/business.js +369 -349
  45. package/lib/Socket/chats.d.ts +125 -0
  46. package/lib/Socket/chats.js +1148 -1172
  47. package/lib/Socket/communities.d.ts +273 -0
  48. package/lib/Socket/communities.js +413 -473
  49. package/lib/Socket/groups.d.ts +161 -0
  50. package/lib/Socket/groups.js +331 -387
  51. package/lib/Socket/index.d.ts +267 -0
  52. package/lib/Socket/index.js +19 -6
  53. package/lib/Socket/messages-recv.d.ts +203 -0
  54. package/lib/Socket/messages-recv.js +1719 -1782
  55. package/lib/Socket/messages-send.d.ts +199 -0
  56. package/lib/Socket/messages-send.js +2451 -1555
  57. package/lib/Socket/mex.d.ts +3 -0
  58. package/lib/Socket/mex.js +35 -40
  59. package/lib/Socket/newsletter.d.ts +170 -0
  60. package/lib/Socket/newsletter.js +191 -239
  61. package/lib/Socket/socket.d.ts +59 -0
  62. package/lib/Socket/socket.js +923 -992
  63. package/lib/Types/Auth.d.ts +117 -0
  64. package/lib/Types/Auth.js +1 -0
  65. package/lib/Types/Bussines.d.ts +25 -0
  66. package/lib/Types/Bussines.js +1 -0
  67. package/lib/Types/Call.d.ts +15 -0
  68. package/lib/Types/Call.js +1 -0
  69. package/lib/Types/Chat.d.ts +124 -0
  70. package/lib/Types/Chat.js +8 -1
  71. package/lib/Types/Contact.d.ts +26 -0
  72. package/lib/Types/Contact.js +1 -0
  73. package/lib/Types/Events.d.ts +256 -0
  74. package/lib/Types/Events.js +2 -1
  75. package/lib/Types/GroupMetadata.d.ts +71 -0
  76. package/lib/Types/GroupMetadata.js +1 -0
  77. package/lib/Types/Label.d.ts +47 -0
  78. package/lib/Types/Label.js +22 -20
  79. package/lib/Types/LabelAssociation.d.ts +30 -0
  80. package/lib/Types/LabelAssociation.js +4 -2
  81. package/lib/Types/Message.d.ts +320 -0
  82. package/lib/Types/Message.js +5 -3
  83. package/lib/Types/Mex.d.ts +141 -0
  84. package/lib/Types/Mex.js +31 -26
  85. package/lib/Types/Product.d.ts +79 -0
  86. package/lib/Types/Product.js +1 -0
  87. package/lib/Types/Signal.d.ts +87 -0
  88. package/lib/Types/Signal.js +2 -1
  89. package/lib/Types/Socket.d.ts +136 -0
  90. package/lib/Types/Socket.js +3 -2
  91. package/lib/Types/State.d.ts +97 -0
  92. package/lib/Types/State.js +52 -4
  93. package/lib/Types/USync.d.ts +26 -0
  94. package/lib/Types/USync.js +1 -0
  95. package/lib/Types/index.d.ts +66 -0
  96. package/lib/Types/index.js +11 -10
  97. package/lib/Utils/auth-utils.d.ts +24 -0
  98. package/lib/Utils/auth-utils.js +277 -240
  99. package/lib/Utils/browser-utils.d.ts +4 -0
  100. package/lib/Utils/browser-utils.js +23 -20
  101. package/lib/Utils/business.d.ts +23 -0
  102. package/lib/Utils/business.js +204 -200
  103. package/lib/Utils/chat-utils.d.ts +100 -0
  104. package/lib/Utils/chat-utils.js +810 -836
  105. package/lib/Utils/companion-reg-client-utils.d.ts +17 -0
  106. package/lib/Utils/companion-reg-client-utils.js +25 -23
  107. package/lib/Utils/crypto.d.ts +37 -0
  108. package/lib/Utils/crypto.js +86 -70
  109. package/lib/Utils/decode-wa-message.d.ts +66 -0
  110. package/lib/Utils/decode-wa-message.js +284 -277
  111. package/lib/Utils/event-buffer.d.ts +36 -0
  112. package/lib/Utils/event-buffer.js +595 -592
  113. package/lib/Utils/generics.d.ts +92 -0
  114. package/lib/Utils/generics.js +335 -312
  115. package/lib/Utils/history.d.ts +24 -0
  116. package/lib/Utils/history.js +115 -123
  117. package/lib/Utils/identity-change-handler.d.ts +44 -0
  118. package/lib/Utils/identity-change-handler.js +50 -0
  119. package/lib/Utils/index.d.ts +22 -0
  120. package/lib/Utils/index.js +2 -1
  121. package/lib/Utils/link-preview.d.ts +21 -0
  122. package/lib/Utils/link-preview.js +73 -74
  123. package/lib/Utils/logger.d.ts +12 -0
  124. package/lib/Utils/logger.js +2 -3
  125. package/lib/Utils/lt-hash.d.ts +8 -0
  126. package/lib/Utils/lt-hash.js +6 -0
  127. package/lib/Utils/make-mutex.d.ts +9 -0
  128. package/lib/Utils/make-mutex.js +27 -27
  129. package/lib/Utils/message-retry-manager.d.ts +115 -0
  130. package/lib/Utils/message-retry-manager.js +254 -213
  131. package/lib/Utils/messages-media.d.ts +133 -0
  132. package/lib/Utils/messages-media.js +715 -741
  133. package/lib/Utils/messages.d.ts +91 -0
  134. package/lib/Utils/messages.js +827 -791
  135. package/lib/Utils/noise-handler.d.ts +20 -0
  136. package/lib/Utils/noise-handler.js +187 -215
  137. package/lib/Utils/offline-node-processor.d.ts +17 -0
  138. package/lib/Utils/offline-node-processor.js +40 -0
  139. package/lib/Utils/pre-key-manager.d.ts +28 -0
  140. package/lib/Utils/pre-key-manager.js +98 -69
  141. package/lib/Utils/process-message.d.ts +60 -0
  142. package/lib/Utils/process-message.js +586 -617
  143. package/lib/Utils/reporting-utils.d.ts +11 -0
  144. package/lib/Utils/reporting-utils.js +234 -553
  145. package/lib/Utils/signal.d.ts +47 -0
  146. package/lib/Utils/signal.js +170 -217
  147. package/lib/Utils/stanza-ack.d.ts +11 -0
  148. package/lib/Utils/stanza-ack.js +35 -27
  149. package/lib/Utils/sync-action-utils.d.ts +19 -0
  150. package/lib/Utils/sync-action-utils.js +41 -37
  151. package/lib/Utils/tc-token-utils.d.ts +37 -0
  152. package/lib/Utils/tc-token-utils.js +141 -120
  153. package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
  154. package/lib/Utils/use-multi-file-auth-state.js +105 -87
  155. package/lib/Utils/validate-connection.d.ts +11 -0
  156. package/lib/Utils/validate-connection.js +188 -190
  157. package/lib/WABinary/constants.d.ts +28 -0
  158. package/lib/WABinary/constants.js +1294 -28
  159. package/lib/WABinary/decode.d.ts +7 -0
  160. package/lib/WABinary/decode.js +249 -245
  161. package/lib/WABinary/encode.d.ts +3 -0
  162. package/lib/WABinary/encode.js +206 -201
  163. package/lib/WABinary/generic-utils.d.ts +15 -0
  164. package/lib/WABinary/generic-utils.js +89 -86
  165. package/lib/WABinary/index.d.ts +6 -0
  166. package/lib/WABinary/index.js +1 -0
  167. package/lib/WABinary/jid-utils.d.ts +48 -0
  168. package/lib/WABinary/jid-utils.js +77 -68
  169. package/lib/WABinary/types.d.ts +19 -0
  170. package/lib/WABinary/types.js +1 -0
  171. package/lib/WAM/BinaryInfo.d.ts +9 -0
  172. package/lib/WAM/BinaryInfo.js +8 -7
  173. package/lib/WAM/constants.d.ts +40 -0
  174. package/lib/WAM/constants.js +22853 -19892
  175. package/lib/WAM/encode.d.ts +3 -0
  176. package/lib/WAM/encode.js +132 -121
  177. package/lib/WAM/index.d.ts +4 -0
  178. package/lib/WAM/index.js +1 -0
  179. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
  180. package/lib/WAUSync/Protocols/USyncContactProtocol.js +43 -46
  181. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
  182. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +48 -47
  183. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
  184. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +23 -22
  185. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
  186. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +33 -30
  187. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +10 -0
  188. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +20 -19
  189. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
  190. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +44 -53
  191. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
  192. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -24
  193. package/lib/WAUSync/Protocols/index.d.ts +6 -0
  194. package/lib/WAUSync/Protocols/index.js +1 -0
  195. package/lib/WAUSync/USyncQuery.d.ts +30 -0
  196. package/lib/WAUSync/USyncQuery.js +88 -79
  197. package/lib/WAUSync/USyncUser.d.ts +17 -0
  198. package/lib/WAUSync/USyncUser.js +29 -28
  199. package/lib/WAUSync/index.d.ts +4 -0
  200. package/lib/WAUSync/index.js +1 -0
  201. package/lib/index.d.ts +12 -0
  202. package/lib/index.js +2 -2
  203. package/package.json +86 -22
  204. package/README.upstream.md +0 -1312
  205. package/WAProto/WAProto.json +0 -1
  206. package/WAProto/WAProto.proto +0 -6275
  207. package/WAProto/compiler.js +0 -550
  208. package/lib/Store/index.js +0 -8
  209. package/lib/Store/keyed-db.js +0 -108
  210. package/lib/Store/make-cache-manager-store.js +0 -70
  211. package/lib/Store/make-in-memory-store.js +0 -417
  212. package/lib/Store/make-ordered-dictionary.js +0 -69
  213. package/lib/Store/object-repository.js +0 -27
  214. package/lib/Utils/use-sqlite-auth-state.js +0 -162
@@ -1,212 +1,210 @@
1
1
  import { Boom } from '@hapi/boom';
2
2
  import { createHash } from 'crypto';
3
- import { proto } from '../../WAProto/compiler.js';
3
+ import { proto } from '../../WAProto/index.js';
4
4
  import { KEY_BUNDLE_TYPE, WA_ADV_ACCOUNT_SIG_PREFIX, WA_ADV_DEVICE_SIG_PREFIX, WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX } from '../Defaults/index.js';
5
5
  import { getBinaryNodeChild, jidDecode, S_WHATSAPP_NET } from '../WABinary/index.js';
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: config.browser[1].toLocaleLowerCase().includes('android')
17
+ ? proto.ClientPayload.UserAgent.Platform.ANDROID
18
+ : proto.ClientPayload.UserAgent.Platform.WEB,
19
+ releaseChannel: proto.ClientPayload.UserAgent.ReleaseChannel.RELEASE,
20
+ osVersion: '0.1',
21
+ device: 'Desktop',
22
+ osBuildNumber: '0.1',
23
+ localeLanguageIso6391: 'en',
24
+ mnc: '000',
25
+ mcc: '000',
26
+ localeCountryIso31661Alpha2: config.countryCode
27
+ };
26
28
  };
27
29
  const PLATFORM_MAP = {
28
- 'Mac OS': proto.ClientPayload.WebInfo.WebSubPlatform.DARWIN,
29
- Windows: proto.ClientPayload.WebInfo.WebSubPlatform.WIN32
30
+ 'Mac OS': proto.ClientPayload.WebInfo.WebSubPlatform.DARWIN,
31
+ Windows: proto.ClientPayload.WebInfo.WebSubPlatform.WIN32
30
32
  };
31
- const getWebInfo = config => {
32
- let webSubPlatform = proto.ClientPayload.WebInfo.WebSubPlatform.WEB_BROWSER;
33
- if (config.syncFullHistory && PLATFORM_MAP[config.browser[0]] && config.browser[1] === 'Desktop') {
34
- webSubPlatform = PLATFORM_MAP[config.browser[0]];
35
- }
36
- return {
37
- webSubPlatform
38
- };
33
+ const getWebInfo = (config) => {
34
+ let webSubPlatform = proto.ClientPayload.WebInfo.WebSubPlatform.WEB_BROWSER;
35
+ if (config.syncFullHistory &&
36
+ PLATFORM_MAP[config.browser[0]] &&
37
+ config.browser[1] === 'Desktop') {
38
+ webSubPlatform = PLATFORM_MAP[config.browser[0]];
39
+ }
40
+ return { webSubPlatform };
39
41
  };
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
- if (config.pushName) {
48
- payload.pushName = config.pushName;
49
- }
50
- return payload;
42
+ const getClientPayload = (config) => {
43
+ const payload = {
44
+ connectType: proto.ClientPayload.ConnectType.WIFI_UNKNOWN,
45
+ connectReason: proto.ClientPayload.ConnectReason.USER_ACTIVATED,
46
+ userAgent: getUserAgent(config)
47
+ };
48
+ if (!config.browser[1].toLocaleLowerCase().includes('android')) {
49
+ payload.webInfo = getWebInfo(config);
50
+ }
51
+ if (config.pushName) {
52
+ payload.pushName = config.pushName;
53
+ }
54
+ return payload;
51
55
  };
52
56
  export const generateLoginNode = (userJid, config) => {
53
- const {
54
- user,
55
- device
56
- } = jidDecode(userJid);
57
- const payload = {
58
- ...getClientPayload(config),
59
- passive: true,
60
- pull: true,
61
- username: +user,
62
- device: device,
63
- lidDbMigrated: false
64
- };
65
- return proto.ClientPayload.fromObject(payload);
57
+ const { user, device } = jidDecode(userJid);
58
+ const payload = {
59
+ ...getClientPayload(config),
60
+ passive: true,
61
+ pull: true,
62
+ username: +user,
63
+ device: device,
64
+ // TODO: investigate (hard set as false atm)
65
+ lidDbMigrated: false
66
+ };
67
+ return proto.ClientPayload.fromObject(payload);
66
68
  };
67
- const getPlatformType = platform => {
68
- const platformType = platform.toUpperCase();
69
- return proto.DeviceProps.PlatformType[platformType] || proto.DeviceProps.PlatformType.CHROME;
69
+ const getPlatformType = (platform) => {
70
+ const platformType = platform.toUpperCase();
71
+ if (platformType === 'ANDROID') {
72
+ return proto.DeviceProps.PlatformType.ANDROID_PHONE;
73
+ }
74
+ return (proto.DeviceProps.PlatformType[platformType] ||
75
+ proto.DeviceProps.PlatformType.CHROME);
70
76
  };
71
- export const generateRegistrationNode = ({
72
- registrationId,
73
- signedPreKey,
74
- signedIdentityKey
75
- }, config) => {
76
- const appVersionBuf = createHash('md5').update(config.version.join('.')).digest();
77
- const companion = {
78
- os: config.browser[0],
79
- platformType: getPlatformType(config.browser[1]),
80
- requireFullSync: config.syncFullHistory,
81
- historySyncConfig: {
82
- storageQuotaMb: 10240,
83
- inlineInitialPayloadInE2EeMsg: true,
84
- recentSyncDaysLimit: undefined,
85
- supportCallLogHistory: false,
86
- supportBotUserAgentChatHistory: true,
87
- supportCagReactionsAndPolls: true,
88
- supportBizHostedMsg: true,
89
- supportRecentSyncChunkMessageCountTuning: true,
90
- supportHostedGroupMsg: true,
91
- supportFbidBotChatHistory: true,
92
- supportAddOnHistorySyncMigration: undefined,
93
- supportMessageAssociation: true,
94
- supportGroupHistory: false,
95
- onDemandReady: undefined,
96
- supportGuestChat: undefined
97
- },
98
- version: {
99
- primary: 10,
100
- secondary: 15,
101
- tertiary: 7
77
+ export const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentityKey }, config) => {
78
+ // the app version needs to be md5 hashed
79
+ // and passed in
80
+ const appVersionBuf = createHash('md5')
81
+ .update(config.version.join('.')) // join as string
82
+ .digest();
83
+ const companion = {
84
+ os: config.browser[0],
85
+ platformType: getPlatformType(config.browser[1]),
86
+ requireFullSync: config.syncFullHistory,
87
+ historySyncConfig: {
88
+ storageQuotaMb: 10240,
89
+ inlineInitialPayloadInE2EeMsg: true,
90
+ recentSyncDaysLimit: undefined,
91
+ supportCallLogHistory: false,
92
+ supportBotUserAgentChatHistory: true,
93
+ supportCagReactionsAndPolls: true,
94
+ supportBizHostedMsg: true,
95
+ supportRecentSyncChunkMessageCountTuning: true,
96
+ supportHostedGroupMsg: true,
97
+ supportFbidBotChatHistory: true,
98
+ supportAddOnHistorySyncMigration: undefined,
99
+ supportMessageAssociation: true,
100
+ supportGroupHistory: false,
101
+ onDemandReady: undefined,
102
+ supportGuestChat: undefined
103
+ },
104
+ version: {
105
+ primary: 10,
106
+ secondary: 15,
107
+ tertiary: 7
108
+ }
109
+ };
110
+ const companionProto = proto.DeviceProps.encode(companion).finish();
111
+ const registerPayload = {
112
+ ...getClientPayload(config),
113
+ passive: false,
114
+ pull: false,
115
+ devicePairingData: {
116
+ buildHash: appVersionBuf,
117
+ deviceProps: companionProto,
118
+ eRegid: encodeBigEndian(registrationId),
119
+ eKeytype: KEY_BUNDLE_TYPE,
120
+ eIdent: signedIdentityKey.public,
121
+ eSkeyId: encodeBigEndian(signedPreKey.keyId, 3),
122
+ eSkeyVal: signedPreKey.keyPair.public,
123
+ eSkeySig: signedPreKey.signature
124
+ }
125
+ };
126
+ return proto.ClientPayload.fromObject(registerPayload);
127
+ };
128
+ export const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, signalIdentities }) => {
129
+ const msgId = stanza.attrs.id;
130
+ const pairSuccessNode = getBinaryNodeChild(stanza, 'pair-success');
131
+ const deviceIdentityNode = getBinaryNodeChild(pairSuccessNode, 'device-identity');
132
+ const platformNode = getBinaryNodeChild(pairSuccessNode, 'platform');
133
+ const deviceNode = getBinaryNodeChild(pairSuccessNode, 'device');
134
+ const businessNode = getBinaryNodeChild(pairSuccessNode, 'biz');
135
+ if (!deviceIdentityNode || !deviceNode) {
136
+ throw new Boom('Missing device-identity or device in pair success node', { data: stanza });
102
137
  }
103
- };
104
- const companionProto = proto.DeviceProps.encode(companion).finish();
105
- const registerPayload = {
106
- ...getClientPayload(config),
107
- passive: false,
108
- pull: false,
109
- devicePairingData: {
110
- buildHash: appVersionBuf,
111
- deviceProps: companionProto,
112
- eRegid: encodeBigEndian(registrationId),
113
- eKeytype: KEY_BUNDLE_TYPE,
114
- eIdent: signedIdentityKey.public,
115
- eSkeyId: encodeBigEndian(signedPreKey.keyId, 3),
116
- eSkeyVal: signedPreKey.keyPair.public,
117
- eSkeySig: signedPreKey.signature
138
+ const bizName = businessNode?.attrs.name;
139
+ const jid = deviceNode.attrs.jid;
140
+ const lid = deviceNode.attrs.lid;
141
+ const { details, hmac, accountType } = proto.ADVSignedDeviceIdentityHMAC.decode(deviceIdentityNode.content);
142
+ let hmacPrefix = Buffer.from([]);
143
+ if (accountType !== undefined && accountType === proto.ADVEncryptionType.HOSTED) {
144
+ hmacPrefix = WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX;
118
145
  }
119
- };
120
- return proto.ClientPayload.fromObject(registerPayload);
121
- };
122
- export const configureSuccessfulPairing = (stanza, {
123
- advSecretKey,
124
- signedIdentityKey,
125
- signalIdentities
126
- }) => {
127
- const msgId = stanza.attrs.id;
128
- const pairSuccessNode = getBinaryNodeChild(stanza, 'pair-success');
129
- const deviceIdentityNode = getBinaryNodeChild(pairSuccessNode, 'device-identity');
130
- const platformNode = getBinaryNodeChild(pairSuccessNode, 'platform');
131
- const deviceNode = getBinaryNodeChild(pairSuccessNode, 'device');
132
- const businessNode = getBinaryNodeChild(pairSuccessNode, 'biz');
133
- if (!deviceIdentityNode || !deviceNode) {
134
- throw new Boom('Missing device-identity or device in pair success node', {
135
- data: stanza
136
- });
137
- }
138
- const bizName = businessNode?.attrs.name;
139
- const jid = deviceNode.attrs.jid;
140
- const lid = deviceNode.attrs.lid;
141
- const {
142
- details,
143
- hmac,
144
- accountType
145
- } = proto.ADVSignedDeviceIdentityHMAC.decode(deviceIdentityNode.content);
146
- let hmacPrefix = Buffer.from([]);
147
- if (accountType !== undefined && accountType === proto.ADVEncryptionType.HOSTED) {
148
- hmacPrefix = WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX;
149
- }
150
- const advSign = hmacSign(Buffer.concat([hmacPrefix, details]), Buffer.from(advSecretKey, 'base64'));
151
- if (Buffer.compare(hmac, advSign) !== 0) {
152
- throw new Boom('Invalid account signature');
153
- }
154
- const account = proto.ADVSignedDeviceIdentity.decode(details);
155
- const {
156
- accountSignatureKey,
157
- accountSignature,
158
- details: deviceDetails
159
- } = account;
160
- const deviceIdentity = proto.ADVDeviceIdentity.decode(deviceDetails);
161
- const accountSignaturePrefix = deviceIdentity.deviceType === proto.ADVEncryptionType.HOSTED ? WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX : WA_ADV_ACCOUNT_SIG_PREFIX;
162
- const accountMsg = Buffer.concat([accountSignaturePrefix, deviceDetails, signedIdentityKey.public]);
163
- if (!Curve.verify(accountSignatureKey, accountMsg, accountSignature)) {
164
- throw new Boom('Failed to verify account signature');
165
- }
166
- const deviceMsg = Buffer.concat([WA_ADV_DEVICE_SIG_PREFIX, deviceDetails, signedIdentityKey.public, accountSignatureKey]);
167
- account.deviceSignature = Curve.sign(signedIdentityKey.private, deviceMsg);
168
- const identity = createSignalIdentity(lid, accountSignatureKey);
169
- const accountEnc = encodeSignedDeviceIdentity(account, false);
170
- const reply = {
171
- tag: 'iq',
172
- attrs: {
173
- to: S_WHATSAPP_NET,
174
- type: 'result',
175
- id: msgId
176
- },
177
- content: [{
178
- tag: 'pair-device-sign',
179
- attrs: {},
180
- content: [{
181
- tag: 'device-identity',
146
+ const advSign = hmacSign(Buffer.concat([hmacPrefix, details]), Buffer.from(advSecretKey, 'base64'));
147
+ if (Buffer.compare(hmac, advSign) !== 0) {
148
+ throw new Boom('Invalid account signature');
149
+ }
150
+ const account = proto.ADVSignedDeviceIdentity.decode(details);
151
+ const { accountSignatureKey, accountSignature, details: deviceDetails } = account;
152
+ const deviceIdentity = proto.ADVDeviceIdentity.decode(deviceDetails);
153
+ const accountSignaturePrefix = deviceIdentity.deviceType === proto.ADVEncryptionType.HOSTED
154
+ ? WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX
155
+ : WA_ADV_ACCOUNT_SIG_PREFIX;
156
+ const accountMsg = Buffer.concat([accountSignaturePrefix, deviceDetails, signedIdentityKey.public]);
157
+ if (!Curve.verify(accountSignatureKey, accountMsg, accountSignature)) {
158
+ throw new Boom('Failed to verify account signature');
159
+ }
160
+ const deviceMsg = Buffer.concat([
161
+ WA_ADV_DEVICE_SIG_PREFIX,
162
+ deviceDetails,
163
+ signedIdentityKey.public,
164
+ accountSignatureKey
165
+ ]);
166
+ account.deviceSignature = Curve.sign(signedIdentityKey.private, deviceMsg);
167
+ const identity = createSignalIdentity(lid, accountSignatureKey);
168
+ const accountEnc = encodeSignedDeviceIdentity(account, false);
169
+ const reply = {
170
+ tag: 'iq',
182
171
  attrs: {
183
- 'key-index': deviceIdentity.keyIndex.toString()
172
+ to: S_WHATSAPP_NET,
173
+ type: 'result',
174
+ id: msgId
184
175
  },
185
- content: accountEnc
186
- }]
187
- }]
188
- };
189
- const authUpdate = {
190
- account,
191
- me: {
192
- id: jid,
193
- name: bizName,
194
- lid
195
- },
196
- signalIdentities: [...(signalIdentities || []), identity],
197
- platform: platformNode?.attrs.name
198
- };
199
- return {
200
- creds: authUpdate,
201
- reply
202
- };
176
+ content: [
177
+ {
178
+ tag: 'pair-device-sign',
179
+ attrs: {},
180
+ content: [
181
+ {
182
+ tag: 'device-identity',
183
+ attrs: { 'key-index': deviceIdentity.keyIndex.toString() },
184
+ content: accountEnc
185
+ }
186
+ ]
187
+ }
188
+ ]
189
+ };
190
+ const authUpdate = {
191
+ account,
192
+ me: { id: jid, name: bizName, lid },
193
+ signalIdentities: [...(signalIdentities || []), identity],
194
+ platform: platformNode?.attrs.name
195
+ };
196
+ return {
197
+ creds: authUpdate,
198
+ reply
199
+ };
203
200
  };
204
201
  export const encodeSignedDeviceIdentity = (account, includeSignatureKey) => {
205
- account = {
206
- ...account
207
- };
208
- if (!includeSignatureKey || !account.accountSignatureKey?.length) {
209
- account.accountSignatureKey = null;
210
- }
211
- return proto.ADVSignedDeviceIdentity.encode(account).finish();
202
+ account = { ...account };
203
+ // set to null if we are not to include the signature key
204
+ // or if we are including the signature key but it is empty
205
+ if (!includeSignatureKey || !account.accountSignatureKey?.length) {
206
+ account.accountSignatureKey = null;
207
+ }
208
+ return proto.ADVSignedDeviceIdentity.encode(account).finish();
212
209
  };
210
+ //# sourceMappingURL=validate-connection.js.map
@@ -0,0 +1,28 @@
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
+ export declare const DOUBLE_BYTE_TOKENS: readonly [readonly ["read-self", "active", "fbns", "protocol", "reaction", "screen_width", "heartbeat", "deviceid", "2:47DEQpj8", "uploadfieldstat", "voip_settings", "retry", "priority", "longitude", "conflict", "false", "ig_professional", "replaced", "preaccept", "cover_photo", "uncompressed", "encopt", "ppic", "04", "passive", "status-revoke-drop", "keygen", "540", "offer", "rate", "opus", "latitude", "w:gp2", "ver", "4", "business_profile", "medium", "sender", "prev_v_id", "email", "website", "invited", "sign_credential", "05", "transport", "skey", "reason", "peer_abtest_bucket", "America/Sao_Paulo", "appid", "refresh", "100", "06", "404", "101", "104", "107", "102", "109", "103", "member_add_mode", "105", "transaction-id", "110", "106", "outgoing", "108", "111", "tokens", "followers", "ig_handle", "self_pid", "tue", "dec", "thu", "joinable", "peer_pid", "mon", "features", "wed", "peer_device_presence", "pn", "delete", "07", "fri", "audio_duration", "admin", "connected", "delta", "rcat", "disable", "collection", "08", "480", "sat", "phash", "all", "invite", "accept", "critical_unblock_low", "group_update", "signed_credential", "blinded_credential", "eph_setting", "net", "09", "background_location", "refresh_id", "Asia/Kolkata", "privacy_mode_ts", "account_sync", "voip_payload_type", "service_areas", "acs_public_key", "v_id", "0a", "fallback_class", "relay", "actual_actors", "metadata", "w:biz", "5", "connected-limit", "notice", "0b", "host_storage", "fb_page", "subject", "privatestats", "invis", "groupadd", "010", "note.m4r", "uuid", "0c", "8000", "sun", "372", "1020", "stage", "1200", "720", "canonical", "fb", "011", "video_duration", "0d", "1140", "superadmin", "012", "Opening.m4r", "keystore_attestation", "dleq_proof", "013", "timestamp", "ab_key", "w:sync:app:state", "0e", "vertical", "600", "p_v_id", "6", "likes", "014", "500", "1260", "creator", "0f", "rte", "destination", "group", "group_info", "syncd_anti_tampering_fatal_exception_enabled", "015", "dl_bw", "Asia/Jakarta", "vp8/h.264", "online", "1320", "fb:multiway", "10", "timeout", "016", "nse_retry", "urn:xmpp:whatsapp:dirty", "017", "a_v_id", "web_shops_chat_header_button_enabled", "nse_call", "inactive-upgrade", "none", "web", "groups", "2250", "mms_hot_content_timespan_in_seconds", "contact_blacklist", "nse_read", "suspended_group_deletion_notification", "binary_version", "018", "https://www.whatsapp.com/otp/copy/", "reg_push", "shops_hide_catalog_attachment_entrypoint", "server_sync", ".", "ephemeral_messages_allowed_values", "019", "mms_vcache_aggregation_enabled", "iphone", "America/Argentina/Buenos_Aires", "01a", "mms_vcard_autodownload_size_kb", "nse_ver", "shops_header_dropdown_menu_item", "dhash", "catalog_status", "communities_mvp_new_iqs_serverprop", "blocklist", "default", "11", "ephemeral_messages_enabled", "01b", "original_dimensions", "8", "mms4_media_retry_notification_encryption_enabled", "mms4_server_error_receipt_encryption_enabled", "original_image_url", "sync", "multiway", "420", "companion_enc_static", "shops_profile_drawer_entrypoint", "01c", "vcard_as_document_size_kb", "status_video_max_duration", "request_image_url", "01d", "regular_high", "s_t", "abt", "share_ext_min_preliminary_image_quality", "01e", "32", "syncd_key_rotation_enabled", "data_namespace", "md_downgrade_read_receipts2", "patch", "polltype", "ephemeral_messages_setting", "userrate", "15", "partial_pjpeg_bw_threshold", "played-self", "catalog_exists", "01f", "mute_v2"], readonly ["reject", "dirty", "announcement", "020", "13", "9", "status_video_max_bitrate", "fb:thrift_iq", "offline_batch", "022", "full", "ctwa_first_business_reply_logging", "h.264", "smax_id", "group_description_length", "https://www.whatsapp.com/otp/code", "status_image_max_edge", "smb_upsell_business_profile_enabled", "021", "web_upgrade_to_md_modal", "14", "023", "s_o", "smaller_video_thumbs_status_enabled", "media_max_autodownload", "960", "blocking_status", "peer_msg", "joinable_group_call_client_version", "group_call_video_maximization_enabled", "return_snapshot", "high", "America/Mexico_City", "entry_point_block_logging_enabled", "pop", "024", "1050", "16", "1380", "one_tap_calling_in_group_chat_size", "regular_low", "inline_joinable_education_enabled", "hq_image_max_edge", "locked", "America/Bogota", "smb_biztools_deeplink_enabled", "status_image_quality", "1088", "025", "payments_upi_intent_transaction_limit", "voip", "w:g2", "027", "md_pin_chat_enabled", "026", "multi_scan_pjpeg_download_enabled", "shops_product_grid", "transaction_id", "ctwa_context_enabled", "20", "fna", "hq_image_quality", "alt_jpeg_doc_detection_quality", "group_call_max_participants", "pkey", "America/Belem", "image_max_kbytes", "web_cart_v1_1_order_message_changes_enabled", "ctwa_context_enterprise_enabled", "urn:xmpp:whatsapp:account", "840", "Asia/Kuala_Lumpur", "max_participants", "video_remux_after_repair_enabled", "stella_addressbook_restriction_type", "660", "900", "780", "context_menu_ios13_enabled", "mute-state", "ref", "payments_request_messages", "029", "frskmsg", "vcard_max_size_kb", "sample_buffer_gif_player_enabled", "match_last_seen", "510", "4983", "video_max_bitrate", "028", "w:comms:chat", "17", "frequently_forwarded_max", "groups_privacy_blacklist", "Asia/Karachi", "02a", "web_download_document_thumb_mms_enabled", "02b", "hist_sync", "biz_block_reasons_version", "1024", "18", "web_is_direct_connection_for_plm_transparent", "view_once_write", "file_max_size", "paid_convo_id", "online_privacy_setting", "video_max_edge", "view_once_read", "enhanced_storage_management", "multi_scan_pjpeg_encoding_enabled", "ctwa_context_forward_enabled", "video_transcode_downgrade_enable", "template_doc_mime_types", "hq_image_bw_threshold", "30", "body", "u_aud_limit_sil_restarts_ctrl", "other", "participating", "w:biz:directory", "1110", "vp8", "4018", "meta", "doc_detection_image_max_edge", "image_quality", "1170", "02c", "smb_upsell_chat_banner_enabled", "key_expiry_time_second", "pid", "stella_interop_enabled", "19", "linked_device_max_count", "md_device_sync_enabled", "02d", "02e", "360", "enhanced_block_enabled", "ephemeral_icon_in_forwarding", "paid_convo_status", "gif_provider", "project_name", "server-error", "canonical_url_validation_enabled", "wallpapers_v2", "syncd_clear_chat_delete_chat_enabled", "medianotify", "02f", "shops_required_tos_version", "vote", "reset_skey_on_id_change", "030", "image_max_edge", "multicast_limit_global", "ul_bw", "21", "25", "5000", "poll", "570", "22", "031", "1280", "WhatsApp", "032", "bloks_shops_enabled", "50", "upload_host_switching_enabled", "web_ctwa_context_compose_enabled", "ptt_forwarded_features_enabled", "unblocked", "partial_pjpeg_enabled", "fbid:devices", "height", "ephemeral_group_query_ts", "group_join_permissions", "order", "033", "alt_jpeg_status_quality", "migrate", "popular-bank", "win_uwp_deprecation_killswitch_enabled", "web_download_status_thumb_mms_enabled", "blocking", "url_text", "035", "web_forwarding_limit_to_groups", "1600", "val", "1000", "syncd_msg_date_enabled", "bank-ref-id", "max_subject", "payments_web_enabled", "web_upload_document_thumb_mms_enabled", "size", "request", "ephemeral", "24", "receipt_agg", "ptt_remember_play_position", "sampling_weight", "enc_rekey", "mute_always", "037", "034", "23", "036", "action", "click_to_chat_qr_enabled", "width", "disabled", "038", "md_blocklist_v2", "played_self_enabled", "web_buttons_message_enabled", "flow_id", "clear", "450", "fbid:thread", "bloks_session_state", "America/Lima", "attachment_picker_refresh", "download_host_switching_enabled", "1792", "u_aud_limit_sil_restarts_test2", "custom_urls", "device_fanout", "optimistic_upload", "2000", "key_cipher_suite", "web_smb_upsell_in_biz_profile_enabled", "e", "039", "siri_post_status_shortcut", "pair-device", "lg", "lc", "stream_attribution_url", "model", "mspjpeg_phash_gen", "catalog_send_all", "new_multi_vcards_ui", "share_biz_vcard_enabled", "-", "clean", "200", "md_blocklist_v2_server", "03b", "03a", "web_md_migration_experience", "ptt_conversation_waveform", "u_aud_limit_sil_restarts_test1"], readonly ["64", "ptt_playback_speed_enabled", "web_product_list_message_enabled", "paid_convo_ts", "27", "manufacturer", "psp-routing", "grp_uii_cleanup", "ptt_draft_enabled", "03c", "business_initiated", "web_catalog_products_onoff", "web_upload_link_thumb_mms_enabled", "03e", "mediaretry", "35", "hfm_string_changes", "28", "America/Fortaleza", "max_keys", "md_mhfs_days", "streaming_upload_chunk_size", "5541", "040", "03d", "2675", "03f", "...", "512", "mute", "48", "041", "alt_jpeg_quality", "60", "042", "md_smb_quick_reply", "5183", "c", "1343", "40", "1230", "043", "044", "mms_cat_v1_forward_hot_override_enabled", "user_notice", "ptt_waveform_send", "047", "Asia/Calcutta", "250", "md_privacy_v2", "31", "29", "128", "md_messaging_enabled", "046", "crypto", "690", "045", "enc_iv", "75", "failure", "ptt_oot_playback", "AIzaSyDR5yfaG7OG8sMTUj8kfQEb8T9pN8BM6Lk", "w", "048", "2201", "web_large_files_ui", "Asia/Makassar", "812", "status_collapse_muted", "1334", "257", "2HP4dm", "049", "patches", "1290", "43cY6T", "America/Caracas", "web_sticker_maker", "campaign", "ptt_pausable_enabled", "33", "42", "attestation", "biz", "04b", "query_linked", "s", "125", "04a", "810", "availability", "1411", "responsiveness_v2_m1", "catalog_not_created", "34", "America/Santiago", "1465", "enc_p", "04d", "status_info", "04f", "key_version", "..", "04c", "04e", "md_group_notification", "1598", "1215", "web_cart_enabled", "37", "630", "1920", "2394", "-1", "vcard", "38", "elapsed", "36", "828", "peer", "pricing_category", "1245", "invalid", "stella_ios_enabled", "2687", "45", "1528", "39", "u_is_redial_audio_1104_ctrl", "1025", "1455", "58", "2524", "2603", "054", "bsp_system_message_enabled", "web_pip_redesign", "051", "verify_apps", "1974", "1272", "1322", "1755", "052", "70", "050", "1063", "1135", "1361", "80", "1096", "1828", "1851", "1251", "1921", "key_config_id", "1254", "1566", "1252", "2525", "critical_block", "1669", "max_available", "w:auth:backup:token", "product", "2530", "870", "1022", "participant_uuid", "web_cart_on_off", "1255", "1432", "1867", "41", "1415", "1440", "240", "1204", "1608", "1690", "1846", "1483", "1687", "1749", "69", "url_number", "053", "1325", "1040", "365", "59", "Asia/Riyadh", "1177", "test_recommended", "057", "1612", "43", "1061", "1518", "1635", "055", "1034", "1375", "750", "1430", "event_code", "1682", "503", "55", "865", "78", "1309", "1365", "44", "America/Guayaquil", "535", "LIMITED", "1377", "1613", "1420", "1599", "1822", "05a", "1681", "password", "1111", "1214", "1376", "1478", "47", "1082", "4282", "Europe/Istanbul", "1307", "46", "058", "1124", "256", "rate-overlimit", "retail", "u_a_socket_err_fix_succ_test", "1292", "1370", "1388", "520", "861", "psa", "regular", "1181", "1766", "05b", "1183", "1213", "1304", "1537"], readonly ["1724", "profile_picture", "1071", "1314", "1605", "407", "990", "1710", "746", "pricing_model", "056", "059", "061", "1119", "6027", "65", "877", "1607", "05d", "917", "seen", "1516", "49", "470", "973", "1037", "1350", "1394", "1480", "1796", "keys", "794", "1536", "1594", "2378", "1333", "1524", "1825", "116", "309", "52", "808", "827", "909", "495", "1660", "361", "957", "google", "1357", "1565", "1967", "996", "1775", "586", "736", "1052", "1670", "bank", "177", "1416", "2194", "2222", "1454", "1839", "1275", "53", "997", "1629", "6028", "smba", "1378", "1410", "05c", "1849", "727", "create", "1559", "536", "1106", "1310", "1944", "670", "1297", "1316", "1762", "en", "1148", "1295", "1551", "1853", "1890", "1208", "1784", "7200", "05f", "178", "1283", "1332", "381", "643", "1056", "1238", "2024", "2387", "179", "981", "1547", "1705", "05e", "290", "903", "1069", "1285", "2436", "062", "251", "560", "582", "719", "56", "1700", "2321", "325", "448", "613", "777", "791", "51", "488", "902", "Asia/Almaty", "is_hidden", "1398", "1527", "1893", "1999", "2367", "2642", "237", "busy", "065", "067", "233", "590", "993", "1511", "54", "723", "860", "363", "487", "522", "605", "995", "1321", "1691", "1865", "2447", "2462", "NON_TRANSACTIONAL", "433", "871", "432", "1004", "1207", "2032", "2050", "2379", "2446", "279", "636", "703", "904", "248", "370", "691", "700", "1068", "1655", "2334", "060", "063", "364", "533", "534", "567", "1191", "1210", "1473", "1827", "069", "701", "2531", "514", "prev_dhash", "064", "496", "790", "1046", "1139", "1505", "1521", "1108", "207", "544", "637", "final", "1173", "1293", "1694", "1939", "1951", "1993", "2353", "2515", "504", "601", "857", "modify", "spam_request", "p_121_aa_1101_test4", "866", "1427", "1502", "1638", "1744", "2153", "068", "382", "725", "1704", "1864", "1990", "2003", "Asia/Dubai", "508", "531", "1387", "1474", "1632", "2307", "2386", "819", "2014", "066", "387", "1468", "1706", "2186", "2261", "471", "728", "1147", "1372", "1961"]];
21
+ export declare const SINGLE_BYTE_TOKENS: string[];
22
+ export declare const TOKEN_MAP: {
23
+ [token: string]: {
24
+ dict?: number;
25
+ index: number;
26
+ };
27
+ };
28
+ //# sourceMappingURL=constants.d.ts.map