@neelegirl/baileys 1.5.2 → 1.5.3

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 (193) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +195 -187
  3. package/WAProto/WAProto.proto +537 -236
  4. package/WAProto/index.d.ts +5971 -2388
  5. package/WAProto/index.js +17298 -6513
  6. package/lib/Defaults/baileys-version.json +3 -3
  7. package/lib/Defaults/index.d.ts +77 -67
  8. package/lib/Defaults/index.js +148 -136
  9. package/lib/Defaults/phonenumber-mcc.json +223 -223
  10. package/lib/Signal/WASignalGroup/GroupProtocol.js +1908 -1908
  11. package/lib/Signal/WASignalGroup/ciphertext-message.d.ts +9 -0
  12. package/lib/Signal/WASignalGroup/ciphertext-message.js +19 -0
  13. package/lib/Signal/WASignalGroup/ciphertext_message.js +15 -15
  14. package/lib/Signal/WASignalGroup/group-session-builder.d.ts +17 -0
  15. package/lib/Signal/WASignalGroup/group-session-builder.js +72 -0
  16. package/lib/Signal/WASignalGroup/group.proto +41 -41
  17. package/lib/Signal/WASignalGroup/group_cipher.d.ts +19 -0
  18. package/lib/Signal/WASignalGroup/group_cipher.js +101 -110
  19. package/lib/Signal/WASignalGroup/group_session_builder.js +45 -45
  20. package/lib/Signal/WASignalGroup/index.d.ts +11 -0
  21. package/lib/Signal/WASignalGroup/index.js +61 -6
  22. package/lib/Signal/WASignalGroup/keyhelper.d.ts +16 -0
  23. package/lib/Signal/WASignalGroup/keyhelper.js +58 -13
  24. package/lib/Signal/WASignalGroup/protobufs.js +2 -2
  25. package/lib/Signal/WASignalGroup/queue_job.js +68 -68
  26. package/lib/Signal/WASignalGroup/readme.md +5 -5
  27. package/lib/Signal/WASignalGroup/sender-chain-key.d.ts +14 -0
  28. package/lib/Signal/WASignalGroup/sender-chain-key.js +47 -0
  29. package/lib/Signal/WASignalGroup/sender-key-distribution-message.d.ts +17 -0
  30. package/lib/Signal/WASignalGroup/sender-key-distribution-message.js +71 -0
  31. package/lib/Signal/WASignalGroup/sender-key-message.d.ts +19 -0
  32. package/lib/Signal/WASignalGroup/sender-key-message.js +73 -0
  33. package/lib/Signal/WASignalGroup/sender-key-name.d.ts +19 -0
  34. package/lib/Signal/WASignalGroup/sender-key-name.js +59 -0
  35. package/lib/Signal/WASignalGroup/sender-key-record.d.ts +32 -0
  36. package/lib/Signal/WASignalGroup/sender-key-record.js +58 -0
  37. package/lib/Signal/WASignalGroup/sender-key-state.d.ts +44 -0
  38. package/lib/Signal/WASignalGroup/sender-key-state.js +147 -0
  39. package/lib/Signal/WASignalGroup/sender-message-key.d.ts +11 -0
  40. package/lib/Signal/WASignalGroup/sender-message-key.js +33 -0
  41. package/lib/Signal/WASignalGroup/sender_chain_key.js +49 -49
  42. package/lib/Signal/WASignalGroup/sender_key_distribution_message.js +77 -77
  43. package/lib/Signal/WASignalGroup/sender_key_message.js +91 -91
  44. package/lib/Signal/WASignalGroup/sender_key_name.js +69 -69
  45. package/lib/Signal/WASignalGroup/sender_key_record.js +55 -55
  46. package/lib/Signal/WASignalGroup/sender_key_state.js +128 -128
  47. package/lib/Signal/WASignalGroup/sender_message_key.js +38 -38
  48. package/lib/Signal/libsignal.d.ts +5 -1
  49. package/lib/Signal/libsignal.js +390 -161
  50. package/lib/Signal/lid-mapping.d.ts +28 -0
  51. package/lib/Signal/lid-mapping.js +184 -0
  52. package/lib/Socket/Client/abstract-socket-client.d.ts +15 -15
  53. package/lib/Socket/Client/abstract-socket-client.js +13 -13
  54. package/lib/Socket/Client/index.d.ts +2 -2
  55. package/lib/Socket/Client/mobile-socket-client.d.ts +12 -12
  56. package/lib/Socket/Client/mobile-socket-client.js +65 -65
  57. package/lib/Socket/Client/types.d.ts +1 -1
  58. package/lib/Socket/Client/websocket.d.ts +1 -1
  59. package/lib/Socket/business.d.ts +6 -6
  60. package/lib/Socket/business.js +152 -5
  61. package/lib/Socket/chats.d.ts +3 -4
  62. package/lib/Socket/chats.js +31 -26
  63. package/lib/Socket/communities.d.ts +223 -223
  64. package/lib/Socket/communities.js +432 -432
  65. package/lib/Socket/groups.d.ts +2 -4
  66. package/lib/Socket/groups.js +22 -14
  67. package/lib/Socket/index.d.ts +69 -69
  68. package/lib/Socket/index.js +3 -2
  69. package/lib/Socket/messages-recv.d.ts +3 -6
  70. package/lib/Socket/messages-recv.js +1449 -1707
  71. package/lib/Socket/messages-send.d.ts +2 -4
  72. package/lib/Socket/messages-send.js +617 -126
  73. package/lib/Socket/mex.d.ts +2 -2
  74. package/lib/Socket/mex.js +46 -46
  75. package/lib/Socket/newsletter.d.ts +2 -4
  76. package/lib/Socket/newsletter.js +294 -285
  77. package/lib/Socket/socket.js +318 -132
  78. package/lib/Socket/usync.js +3 -3
  79. package/lib/Store/index.d.ts +4 -4
  80. package/lib/Store/index.js +23 -23
  81. package/lib/Store/make-cache-manager-store.d.ts +13 -13
  82. package/lib/Store/make-cache-manager-store.js +89 -89
  83. package/lib/Store/make-in-memory-store.d.ts +122 -122
  84. package/lib/Store/make-in-memory-store.js +428 -428
  85. package/lib/Store/make-ordered-dictionary.d.ts +11 -11
  86. package/lib/Store/make-ordered-dictionary.js +85 -85
  87. package/lib/Store/object-repository.d.ts +9 -9
  88. package/lib/Store/object-repository.js +30 -30
  89. package/lib/Types/Auth.d.ts +5 -4
  90. package/lib/Types/Bussines.js +3 -0
  91. package/lib/Types/Bussiness.d.ts +28 -0
  92. package/lib/Types/Chat.d.ts +13 -8
  93. package/lib/Types/Contact.d.ts +4 -1
  94. package/lib/Types/Events.d.ts +13 -16
  95. package/lib/Types/GroupMetadata.d.ts +1 -1
  96. package/lib/Types/Message.d.ts +18 -7
  97. package/lib/Types/Message.js +7 -1
  98. package/lib/Types/MexUpdates.d.ts +8 -8
  99. package/lib/Types/MexUpdates.js +17 -17
  100. package/lib/Types/Newsletter.d.ts +1 -1
  101. package/lib/Types/Product.d.ts +1 -1
  102. package/lib/Types/Signal.d.ts +31 -1
  103. package/lib/Types/Socket.d.ts +34 -13
  104. package/lib/Types/State.d.ts +1 -1
  105. package/lib/Types/USync.d.ts +2 -2
  106. package/lib/Types/index.d.ts +16 -15
  107. package/lib/Types/index.js +4 -2
  108. package/lib/Utils/auth-utils.d.ts +20 -20
  109. package/lib/Utils/auth-utils.js +527 -204
  110. package/lib/Utils/baileys-event-stream.d.ts +17 -17
  111. package/lib/Utils/baileys-event-stream.js +69 -69
  112. package/lib/Utils/business.d.ts +28 -28
  113. package/lib/Utils/business.js +254 -254
  114. package/lib/Utils/chat-utils.d.ts +81 -81
  115. package/lib/Utils/chat-utils.js +808 -780
  116. package/lib/Utils/crypto.d.ts +55 -55
  117. package/lib/Utils/crypto.js +188 -178
  118. package/lib/Utils/decode-wa-message.d.ts +52 -40
  119. package/lib/Utils/decode-wa-message.js +322 -252
  120. package/lib/Utils/event-buffer.d.ts +38 -38
  121. package/lib/Utils/event-buffer.js +594 -564
  122. package/lib/Utils/generics.d.ts +131 -129
  123. package/lib/Utils/generics.js +629 -623
  124. package/lib/Utils/history.d.ts +22 -22
  125. package/lib/Utils/history.js +103 -109
  126. package/lib/Utils/index.d.ts +20 -19
  127. package/lib/Utils/index.js +39 -38
  128. package/lib/Utils/link-preview.d.ts +22 -22
  129. package/lib/Utils/link-preview.js +119 -119
  130. package/lib/Utils/logger.d.ts +13 -13
  131. package/lib/Utils/logger.js +7 -7
  132. package/lib/Utils/lt-hash.d.ts +13 -13
  133. package/lib/Utils/lt-hash.js +57 -57
  134. package/lib/Utils/make-mutex.d.ts +8 -8
  135. package/lib/Utils/make-mutex.js +48 -48
  136. package/lib/Utils/message-retry-manager.d.ts +88 -0
  137. package/lib/Utils/message-retry-manager.js +160 -0
  138. package/lib/Utils/messages-media.d.ts +134 -128
  139. package/lib/Utils/messages-media.js +868 -805
  140. package/lib/Utils/messages.d.ts +104 -102
  141. package/lib/Utils/messages.js +1744 -1578
  142. package/lib/Utils/noise-handler.d.ts +20 -19
  143. package/lib/Utils/noise-handler.js +164 -154
  144. package/lib/Utils/process-message.d.ts +48 -48
  145. package/lib/Utils/process-message.js +427 -428
  146. package/lib/Utils/signal.d.ts +41 -41
  147. package/lib/Utils/signal.js +165 -165
  148. package/lib/Utils/use-mongo-file-auth-state.d.ts +5 -5
  149. package/lib/Utils/use-mongo-file-auth-state.js +83 -83
  150. package/lib/Utils/use-multi-file-auth-state.d.ts +17 -17
  151. package/lib/Utils/use-multi-file-auth-state.js +237 -237
  152. package/lib/Utils/use-single-file-auth-state.d.ts +12 -12
  153. package/lib/Utils/use-single-file-auth-state.js +79 -79
  154. package/lib/Utils/validate-connection.d.ts +12 -12
  155. package/lib/Utils/validate-connection.js +219 -186
  156. package/lib/WABinary/constants.d.ts +29 -29
  157. package/lib/WABinary/constants.js +1315 -1315
  158. package/lib/WABinary/decode.d.ts +8 -8
  159. package/lib/WABinary/decode.js +287 -287
  160. package/lib/WABinary/encode.d.ts +2 -2
  161. package/lib/WABinary/encode.js +264 -264
  162. package/lib/WABinary/generic-utils.d.ts +27 -27
  163. package/lib/WABinary/generic-utils.js +141 -141
  164. package/lib/WABinary/index.d.ts +5 -5
  165. package/lib/WABinary/index.js +24 -24
  166. package/lib/WABinary/jid-utils.d.ts +58 -53
  167. package/lib/WABinary/jid-utils.js +103 -91
  168. package/lib/WABinary/types.d.ts +21 -21
  169. package/lib/WABinary/types.js +2 -2
  170. package/lib/WAM/BinaryInfo.d.ts +15 -15
  171. package/lib/WAM/BinaryInfo.js +16 -16
  172. package/lib/WAM/constants.d.ts +46 -46
  173. package/lib/WAM/constants.js +15370 -15370
  174. package/lib/WAM/encode.d.ts +2 -2
  175. package/lib/WAM/encode.js +163 -164
  176. package/lib/WAM/index.d.ts +3 -3
  177. package/lib/WAM/index.js +22 -22
  178. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.d.ts +27 -27
  179. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +68 -68
  180. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +3 -3
  181. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +2 -2
  182. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +2 -2
  183. package/lib/WAUSync/Protocols/USyncLIDProtocol.d.ts +9 -8
  184. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +37 -29
  185. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +2 -2
  186. package/lib/WAUSync/Protocols/index.d.ts +6 -6
  187. package/lib/WAUSync/USyncQuery.d.ts +3 -3
  188. package/lib/WAUSync/index.d.ts +3 -3
  189. package/lib/index.d.ts +13 -13
  190. package/lib/index.js +33 -33
  191. package/package.json +96 -94
  192. package/lib/Socket/registration.d.ts +0 -266
  193. package/lib/Socket/registration.js +0 -166
@@ -1,13 +1,13 @@
1
- import { proto } from '../../WAProto'
2
- import type { AuthenticationCreds, SignalCreds, SocketConfig } from '../Types'
3
- import { BinaryNode } from '../WABinary'
4
-
5
- export declare const generateLoginNode: (userJid: string, config: SocketConfig) => proto.IClientPayload
6
-
7
- export declare const generateRegistrationNode: ({ registrationId, signedPreKey, signedIdentityKey }: SignalCreds, config: SocketConfig) => proto.ClientPayload
8
-
9
- export declare const configureSuccessfulPairing: (stanza: BinaryNode, { advSecretKey, signedIdentityKey, signalIdentities }: Pick<AuthenticationCreds, 'advSecretKey' | 'signedIdentityKey' | 'signalIdentities'>) => {
10
- creds: Partial<AuthenticationCreds>
11
- reply: BinaryNode
12
- }
1
+ import { proto } from '@neelegirl/baileys/WAProto'
2
+ import type { AuthenticationCreds, SignalCreds, SocketConfig } from '@neelegirl/baileys/lib/Types'
3
+ import { BinaryNode } from '@neelegirl/baileys/lib/WABinary'
4
+
5
+ export declare const generateLoginNode: (userJid: string, config: SocketConfig) => proto.IClientPayload
6
+ export declare const generateMobileNode: (config: SocketConfig) => proto.IClientPayload
7
+ export declare const generateRegistrationNode: ({ registrationId, signedPreKey, signedIdentityKey }: SignalCreds, config: SocketConfig) => proto.ClientPayload
8
+
9
+ export declare const configureSuccessfulPairing: (stanza: BinaryNode, { advSecretKey, signedIdentityKey, signalIdentities }: Pick<AuthenticationCreds, 'advSecretKey' | 'signedIdentityKey' | 'signalIdentities'>) => {
10
+ creds: Partial<AuthenticationCreds>
11
+ reply: BinaryNode
12
+ }
13
13
  export declare const encodeSignedDeviceIdentity: (account: proto.IADVSignedDeviceIdentity, includeSignatureKey: boolean) => Uint8Array
@@ -1,187 +1,220 @@
1
- "use strict"
2
-
3
- Object.defineProperty(exports, "__esModule", { value: true })
4
-
5
- const boom_1 = require("@hapi/boom")
6
- const crypto_1 = require("crypto")
7
- const WAProto_1 = require("../../WAProto")
8
- const Defaults_1 = require("../Defaults")
9
- const WABinary_1 = require("../WABinary")
10
- const crypto_2 = require("./crypto")
11
- const generics_1 = require("./generics")
12
- const signal_1 = require("./signal")
13
-
14
- const getUserAgent = (config) => {
15
- return {
16
- appVersion: {
17
- primary: config.version[0],
18
- secondary: config.version[1],
19
- tertiary: config.version[2],
20
- },
21
- platform: WAProto_1.proto.ClientPayload.UserAgent.Platform.WEB,
22
- releaseChannel: WAProto_1.proto.ClientPayload.UserAgent.ReleaseChannel.BETA,
23
- osVersion: '0.1',
24
- device: 'Desktop',
25
- deviceType: WAProto_1.proto.ClientPayload.UserAgent.DeviceType.DESKTOP,
26
- osBuildNumber: '0.1',
27
- localeLanguageIso6391: 'en',
28
- mnc: '000',
29
- mcc: '000',
30
- localeCountryIso31661Alpha2: config.countryCode,
31
- }
32
- }
33
-
34
- const PLATFORM_MAP = {
35
- 'Mac OS': WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.DARWIN,
36
- 'Windows': WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.WIN32,
37
- 'Android': WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.WIN_HYBRID
38
- }
39
-
40
- const getWebInfo = (config) => {
41
- let webSubPlatform = WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.WEB_BROWSER
42
- if (config.syncFullHistory && PLATFORM_MAP[config.browser[0]]) {
43
- webSubPlatform = PLATFORM_MAP[config.browser[0]]
44
- }
45
- return { webSubPlatform }
46
- }
47
-
48
- const getClientPayload = (config) => {
49
- const payload = {
50
- connectType: WAProto_1.proto.ClientPayload.ConnectType.WIFI_UNKNOWN,
51
- connectReason: WAProto_1.proto.ClientPayload.ConnectReason.USER_ACTIVATED,
52
- userAgent: getUserAgent(config),
53
- }
54
- payload.webInfo = getWebInfo(config)
55
- return payload
56
- }
57
-
58
- const generateLoginNode = (userJid, config) => {
59
- const { user, device } = WABinary_1.jidDecode(userJid)
60
- const payload = {
61
- ...getClientPayload(config),
62
- passive: false,
63
- pull: true,
64
- username: +user,
65
- device: device,
66
- }
67
- return WAProto_1.proto.ClientPayload.fromObject(payload)
68
- }
69
-
70
- const getPlatformType = (platform) => {
71
- const platformType = platform.toUpperCase()
72
- return WAProto_1.proto.DeviceProps.PlatformType[platformType] || WAProto_1.proto.DeviceProps.PlatformType.DESKTOP
73
- }
74
-
75
- const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentityKey }, config) => {
76
- // the app version needs to be md5 hashed
77
- // and passed in
78
- const appVersionBuf = crypto_1.createHash('md5')
79
- .update(config.version.join('.')) // join as string
80
- .digest()
81
- const companion = {
82
- os: config.browser[0],
83
- platformType: getPlatformType(config.browser[1]),
84
- requireFullSync: config.syncFullHistory,
85
- }
86
- const companionProto = WAProto_1.proto.DeviceProps.encode(companion).finish()
87
- const registerPayload = {
88
- ...getClientPayload(config),
89
- passive: false,
90
- pull: false,
91
- devicePairingData: {
92
- buildHash: appVersionBuf,
93
- deviceProps: companionProto,
94
- eRegid: generics_1.encodeBigEndian(registrationId),
95
- eKeytype: Defaults_1.KEY_BUNDLE_TYPE,
96
- eIdent: signedIdentityKey.public,
97
- eSkeyId: generics_1.encodeBigEndian(signedPreKey.keyId, 3),
98
- eSkeyVal: signedPreKey.keyPair.public,
99
- eSkeySig: signedPreKey.signature,
100
- },
101
- }
102
- return WAProto_1.proto.ClientPayload.fromObject(registerPayload)
103
- }
104
-
105
- const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, signalIdentities }) => {
106
- const msgId = stanza.attrs.id
107
- const pairSuccessNode = WABinary_1.getBinaryNodeChild(stanza, 'pair-success')
108
- const deviceIdentityNode = WABinary_1.getBinaryNodeChild(pairSuccessNode, 'device-identity')
109
- const platformNode = WABinary_1.getBinaryNodeChild(pairSuccessNode, 'platform')
110
- const deviceNode = WABinary_1.getBinaryNodeChild(pairSuccessNode, 'device')
111
- const businessNode = WABinary_1.getBinaryNodeChild(pairSuccessNode, 'biz')
112
- if (!deviceIdentityNode || !deviceNode) {
113
- throw new boom_1.Boom('Missing device-identity or device in pair success node', { data: stanza })
114
- }
115
- const bizName = businessNode?.attrs?.name
116
- const jid = deviceNode.attrs.jid
117
- const { details, hmac, accountType } = WAProto_1.proto.ADVSignedDeviceIdentityHMAC.decode(deviceIdentityNode.content)
118
- const isHostedAccount = accountType !== undefined && accountType === WAProto_1.proto.ADVEncryptionType.HOSTED
119
- const hmacPrefix = isHostedAccount ? Buffer.from([6, 5]) : Buffer.alloc(0)
120
- const advSign = crypto_2.hmacSign(Buffer.concat([hmacPrefix, details]), Buffer.from(advSecretKey, 'base64'))
121
- if (Buffer.compare(hmac, advSign) !== 0) {
122
- throw new boom_1.Boom('Invalid account signature')
123
- }
124
- const account = WAProto_1.proto.ADVSignedDeviceIdentity.decode(details)
125
- const { accountSignatureKey, accountSignature, details: deviceDetails } = account
126
- const accountMsg = Buffer.concat([Buffer.from([6, 0]), deviceDetails, signedIdentityKey.public])
127
- if (!crypto_2.Curve.verify(accountSignatureKey, accountMsg, accountSignature)) {
128
- throw new boom_1.Boom('Failed to verify account signature')
129
- }
130
- const devicePrefix = isHostedAccount ? Buffer.from([6, 6]) : Buffer.from([6, 1])
131
- const deviceMsg = Buffer.concat([devicePrefix, deviceDetails, signedIdentityKey.public, accountSignatureKey])
132
- account.deviceSignature = crypto_2.Curve.sign(signedIdentityKey.private, deviceMsg)
133
- const identity = signal_1.createSignalIdentity(jid, accountSignatureKey)
134
- const accountEnc = encodeSignedDeviceIdentity(account, false)
135
- const deviceIdentity = WAProto_1.proto.ADVDeviceIdentity.decode(account.details)
136
- const reply = {
137
- tag: 'iq',
138
- attrs: {
139
- to: WABinary_1.S_WHATSAPP_NET,
140
- type: 'result',
141
- id: msgId,
142
- },
143
- content: [
144
- {
145
- tag: 'pair-device-sign',
146
- attrs: {},
147
- content: [
148
- {
149
- tag: 'device-identity',
150
- attrs: { 'key-index': deviceIdentity.keyIndex.toString() },
151
- content: accountEnc
152
- }
153
- ]
154
- }
155
- ]
156
- }
157
- const authUpdate = {
158
- account,
159
- me: { id: jid, name: bizName },
160
- signalIdentities: [
161
- ...(signalIdentities || []),
162
- identity
163
- ],
164
- platform: platformNode?.attrs?.name
165
- }
166
- return {
167
- creds: authUpdate,
168
- reply
169
- }
170
- }
171
-
172
- const encodeSignedDeviceIdentity = (account, includeSignatureKey) => {
173
- account = { ...account }
174
- // set to null if we are not to include the signature key
175
- // or if we are including the signature key but it is empty
176
- if (!includeSignatureKey || !account.accountSignatureKey?.length) {
177
- account.accountSignatureKey = null
178
- }
179
- return WAProto_1.proto.ADVSignedDeviceIdentity.encode(account).finish()
180
- }
181
-
182
- module.exports = {
183
- generateLoginNode,
184
- generateRegistrationNode,
185
- configureSuccessfulPairing,
186
- encodeSignedDeviceIdentity
1
+ "use strict"
2
+
3
+ Object.defineProperty(exports, "__esModule", { value: true })
4
+
5
+ const boom_1 = require("@hapi/boom")
6
+ const crypto_1 = require("crypto")
7
+ const WAProto_1 = require("../../WAProto")
8
+ const Defaults_1 = require("../Defaults")
9
+ const WABinary_1 = require("../WABinary")
10
+ const crypto_2 = require("./crypto")
11
+ const generics_1 = require("./generics")
12
+ const signal_1 = require("./signal")
13
+
14
+ const getUserAgent = (config) => {
15
+ var _a, _b;
16
+
17
+ const osVersion = config.mobile ? '16.7.10' : '0.1';
18
+ const version = config.mobile ? [2, 25, 15, 75] : config.version;
19
+ const device = config.mobile ? 'iPhone_X' : 'Desktop';
20
+ const manufacturer = config.mobile ? 'Apple' : '';
21
+ const platform = config.mobile ? WAProto_1.proto.ClientPayload.UserAgent.Platform.IOS : WAProto_1.proto.ClientPayload.UserAgent.Platform.WEB;
22
+ const phoneId = config.mobile ? { phoneId: config.auth.creds.phoneId } : {};
23
+
24
+ return {
25
+ appVersion: {
26
+ primary: version[0],
27
+ secondary: version[1],
28
+ tertiary: version[2],
29
+ },
30
+ platform,
31
+ releaseChannel: WAProto_1.proto.ClientPayload.UserAgent.ReleaseChannel.RELEASE,
32
+ osVersion: osVersion,
33
+ manufacturer,
34
+ device,
35
+ deviceType: WAProto_1.proto.ClientPayload.UserAgent.DeviceType.DESKTOP,
36
+ osBuildNumber: '0.1',
37
+ localeLanguageIso6391: 'en',
38
+ mcc: ((_a = config.auth.creds.registration) === null || _a === void 0 ? void 0 : _a.phoneNumberMobileCountryCode) || '000',
39
+ mnc: ((_b = config.auth.creds.registration) === null || _b === void 0 ? void 0 : _b.phoneNumberMobileNetworkCode) || '000',
40
+ localeCountryIso31661Alpha2: config.countryCode,
41
+ ...phoneId
42
+ }
43
+ }
44
+
45
+ const PLATFORM_MAP = {
46
+ 'Mac OS': WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.DARWIN,
47
+ 'Windows': WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.WIN32,
48
+ 'Android': WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.WIN_HYBRID
49
+ }
50
+
51
+ const getWebInfo = (config) => {
52
+ let webSubPlatform = WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.WEB_BROWSER
53
+ if (config.syncFullHistory && PLATFORM_MAP[config.browser[0]]) {
54
+ webSubPlatform = PLATFORM_MAP[config.browser[0]]
55
+ }
56
+ return { webSubPlatform }
57
+ }
58
+
59
+ const getClientPayload = (config) => {
60
+ const payload = {
61
+ connectType: WAProto_1.proto.ClientPayload.ConnectType.WIFI_UNKNOWN,
62
+ connectReason: WAProto_1.proto.ClientPayload.ConnectReason.USER_ACTIVATED,
63
+ userAgent: getUserAgent(config),
64
+ }
65
+ if (!config.mobile) {
66
+ payload.webInfo = getWebInfo(config);
67
+ }
68
+ return payload
69
+ }
70
+ const generateMobileNode = (config) => {
71
+ if (!config.auth.creds) {
72
+ throw new boom_1.Boom('No registration data found', { data: config });
73
+ }
74
+ const payload = {
75
+ ...getClientPayload(config),
76
+ sessionId: Math.floor(Math.random() * 999999999 + 1),
77
+ shortConnect: true,
78
+ connectAttemptCount: 0,
79
+ device: 0,
80
+ dnsSource: {
81
+ appCached: false,
82
+ dnsMethod: WAProto_1.proto.ClientPayload.DNSSource.DNSResolutionMethod.SYSTEM,
83
+ },
84
+ passive: false,
85
+ pushName: 'test',
86
+ username: Number(`${config.auth.creds.registration.phoneNumberCountryCode}${config.auth.creds.registration.phoneNumberNationalNumber}`),
87
+ };
88
+ return WAProto_1.proto.ClientPayload.fromObject(payload);
89
+ };
90
+ const generateLoginNode = (userJid, config) => {
91
+ const { user, device } = WABinary_1.jidDecode(userJid)
92
+ const payload = {
93
+ ...getClientPayload(config),
94
+ passive: false,
95
+ pull: true,
96
+ username: +user,
97
+ device: device,
98
+ }
99
+ return WAProto_1.proto.ClientPayload.fromObject(payload)
100
+ }
101
+
102
+ const getPlatformType = (platform) => {
103
+ const platformType = platform.toUpperCase()
104
+ return WAProto_1.proto.DeviceProps.PlatformType[platformType] || WAProto_1.proto.DeviceProps.PlatformType.DESKTOP
105
+ }
106
+
107
+ const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentityKey }, config) => {
108
+ // the app version needs to be md5 hashed
109
+ // and passed in
110
+ const appVersionBuf = crypto_1.createHash('md5')
111
+ .update(config.version.join('.')) // join as string
112
+ .digest()
113
+ const companion = {
114
+ os: config.browser[0],
115
+ platformType: getPlatformType(config.browser[1]),
116
+ requireFullSync: config.syncFullHistory,
117
+ }
118
+ const companionProto = WAProto_1.proto.DeviceProps.encode(companion).finish()
119
+ const registerPayload = {
120
+ ...getClientPayload(config),
121
+ passive: false,
122
+ pull: false,
123
+ devicePairingData: {
124
+ buildHash: appVersionBuf,
125
+ deviceProps: companionProto,
126
+ eRegid: generics_1.encodeBigEndian(registrationId),
127
+ eKeytype: Defaults_1.KEY_BUNDLE_TYPE,
128
+ eIdent: signedIdentityKey.public,
129
+ eSkeyId: generics_1.encodeBigEndian(signedPreKey.keyId, 3),
130
+ eSkeyVal: signedPreKey.keyPair.public,
131
+ eSkeySig: signedPreKey.signature,
132
+ },
133
+ }
134
+ return WAProto_1.proto.ClientPayload.fromObject(registerPayload)
135
+ }
136
+
137
+ const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, signalIdentities }) => {
138
+ const msgId = stanza.attrs.id
139
+ const pairSuccessNode = WABinary_1.getBinaryNodeChild(stanza, 'pair-success')
140
+ const deviceIdentityNode = WABinary_1.getBinaryNodeChild(pairSuccessNode, 'device-identity')
141
+ const platformNode = WABinary_1.getBinaryNodeChild(pairSuccessNode, 'platform')
142
+ const deviceNode = WABinary_1.getBinaryNodeChild(pairSuccessNode, 'device')
143
+ const businessNode = WABinary_1.getBinaryNodeChild(pairSuccessNode, 'biz')
144
+ if (!deviceIdentityNode || !deviceNode) {
145
+ throw new boom_1.Boom('Missing device-identity or device in pair success node', { data: stanza })
146
+ }
147
+ const bizName = businessNode?.attrs?.name
148
+ const jid = deviceNode.attrs.jid
149
+ const { details, hmac, accountType } = WAProto_1.proto.ADVSignedDeviceIdentityHMAC.decode(deviceIdentityNode.content)
150
+ const isHostedAccount = accountType !== undefined && accountType === WAProto_1.proto.ADVEncryptionType.HOSTED
151
+ const hmacPrefix = isHostedAccount ? Buffer.from([6, 5]) : Buffer.alloc(0)
152
+ const advSign = crypto_2.hmacSign(Buffer.concat([hmacPrefix, details]), Buffer.from(advSecretKey, 'base64'))
153
+ if (Buffer.compare(hmac, advSign) !== 0) {
154
+ throw new boom_1.Boom('Invalid account signature')
155
+ }
156
+ const account = WAProto_1.proto.ADVSignedDeviceIdentity.decode(details)
157
+ const { accountSignatureKey, accountSignature, details: deviceDetails } = account
158
+ const accountMsg = Buffer.concat([Buffer.from([6, 0]), deviceDetails, signedIdentityKey.public])
159
+ if (!crypto_2.Curve.verify(accountSignatureKey, accountMsg, accountSignature)) {
160
+ throw new boom_1.Boom('Failed to verify account signature')
161
+ }
162
+ const devicePrefix = isHostedAccount ? Buffer.from([6, 6]) : Buffer.from([6, 1])
163
+ const deviceMsg = Buffer.concat([devicePrefix, deviceDetails, signedIdentityKey.public, accountSignatureKey])
164
+ account.deviceSignature = crypto_2.Curve.sign(signedIdentityKey.private, deviceMsg)
165
+ const identity = signal_1.createSignalIdentity(jid, accountSignatureKey)
166
+ const accountEnc = encodeSignedDeviceIdentity(account, false)
167
+ const deviceIdentity = WAProto_1.proto.ADVDeviceIdentity.decode(account.details)
168
+ const reply = {
169
+ tag: 'iq',
170
+ attrs: {
171
+ to: WABinary_1.S_WHATSAPP_NET,
172
+ type: 'result',
173
+ id: msgId,
174
+ },
175
+ content: [
176
+ {
177
+ tag: 'pair-device-sign',
178
+ attrs: {},
179
+ content: [
180
+ {
181
+ tag: 'device-identity',
182
+ attrs: { 'key-index': deviceIdentity.keyIndex.toString() },
183
+ content: accountEnc
184
+ }
185
+ ]
186
+ }
187
+ ]
188
+ }
189
+ const authUpdate = {
190
+ account,
191
+ me: { id: jid, name: bizName },
192
+ signalIdentities: [
193
+ ...(signalIdentities || []),
194
+ identity
195
+ ],
196
+ platform: platformNode?.attrs?.name
197
+ }
198
+ return {
199
+ creds: authUpdate,
200
+ reply
201
+ }
202
+ }
203
+
204
+ const encodeSignedDeviceIdentity = (account, includeSignatureKey) => {
205
+ account = { ...account }
206
+ // set to null if we are not to include the signature key
207
+ // or if we are including the signature key but it is empty
208
+ if (!includeSignatureKey || !account.accountSignatureKey?.length) {
209
+ account.accountSignatureKey = null
210
+ }
211
+ return WAProto_1.proto.ADVSignedDeviceIdentity.encode(account).finish()
212
+ }
213
+
214
+ module.exports = {
215
+ generateLoginNode,
216
+ generateRegistrationNode,
217
+ configureSuccessfulPairing,
218
+ encodeSignedDeviceIdentity,
219
+ generateMobileNode
187
220
  }
@@ -1,30 +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
- }
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
30
  }