nodejs-insta-private-api-mqt 1.3.70

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 (240) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +3677 -0
  3. package/dist/constants/constants.js +342 -0
  4. package/dist/constants/index.js +58 -0
  5. package/dist/core/client.js +419 -0
  6. package/dist/core/nav-chain.js +282 -0
  7. package/dist/core/repository.js +7 -0
  8. package/dist/core/request.js +390 -0
  9. package/dist/core/state.js +1473 -0
  10. package/dist/core/utils.js +786 -0
  11. package/dist/downloadMedia.js +381 -0
  12. package/dist/errors/index.d.ts +16 -0
  13. package/dist/errors/index.js +38 -0
  14. package/dist/errors/index.js.map +1 -0
  15. package/dist/extend.js +167 -0
  16. package/dist/fbns/fbns.client.d.ts +32 -0
  17. package/dist/fbns/fbns.client.events.d.ts +41 -0
  18. package/dist/fbns/fbns.client.events.js +3 -0
  19. package/dist/fbns/fbns.client.events.js.map +1 -0
  20. package/dist/fbns/fbns.client.js +252 -0
  21. package/dist/fbns/fbns.client.js.map +1 -0
  22. package/dist/fbns/fbns.device-auth.d.ts +17 -0
  23. package/dist/fbns/fbns.device-auth.js +54 -0
  24. package/dist/fbns/fbns.device-auth.js.map +1 -0
  25. package/dist/fbns/fbns.types.d.ts +83 -0
  26. package/dist/fbns/fbns.types.js +3 -0
  27. package/dist/fbns/fbns.types.js.map +1 -0
  28. package/dist/fbns/fbns.utilities.d.ts +2 -0
  29. package/dist/fbns/fbns.utilities.js +79 -0
  30. package/dist/fbns/fbns.utilities.js.map +1 -0
  31. package/dist/fbns/index.d.ts +4 -0
  32. package/dist/fbns/index.js +21 -0
  33. package/dist/fbns/index.js.map +1 -0
  34. package/dist/index.js +139 -0
  35. package/dist/mqtt-shim.d.ts +96 -0
  36. package/dist/mqtt-shim.js +15 -0
  37. package/dist/mqttot/index.d.ts +4 -0
  38. package/dist/mqttot/index.js +21 -0
  39. package/dist/mqttot/index.js.map +1 -0
  40. package/dist/mqttot/mqttot.client.d.ts +39 -0
  41. package/dist/mqttot/mqttot.client.js +318 -0
  42. package/dist/mqttot/mqttot.client.js.map +1 -0
  43. package/dist/mqttot/mqttot.connect.request.packet.d.ts +7 -0
  44. package/dist/mqttot/mqttot.connect.request.packet.js +9 -0
  45. package/dist/mqttot/mqttot.connect.request.packet.js.map +1 -0
  46. package/dist/mqttot/mqttot.connect.response.packet.d.ts +7 -0
  47. package/dist/mqttot/mqttot.connect.response.packet.js +24 -0
  48. package/dist/mqttot/mqttot.connect.response.packet.js.map +1 -0
  49. package/dist/mqttot/mqttot.connection.d.ts +57 -0
  50. package/dist/mqttot/mqttot.connection.js +79 -0
  51. package/dist/mqttot/mqttot.connection.js.map +1 -0
  52. package/dist/package.json +59 -0
  53. package/dist/realtime/commands/commands.d.ts +15 -0
  54. package/dist/realtime/commands/commands.js +71 -0
  55. package/dist/realtime/commands/commands.js.map +1 -0
  56. package/dist/realtime/commands/direct.commands.d.ts +75 -0
  57. package/dist/realtime/commands/direct.commands.js +417 -0
  58. package/dist/realtime/commands/direct.commands.js.map +1 -0
  59. package/dist/realtime/commands/enhanced.direct.commands.js +1731 -0
  60. package/dist/realtime/commands/enhanced.direct.commands.js.bak +967 -0
  61. package/dist/realtime/commands/index.d.ts +2 -0
  62. package/dist/realtime/commands/index.js +20 -0
  63. package/dist/realtime/commands/index.js.map +1 -0
  64. package/dist/realtime/delta-sync.manager.js +293 -0
  65. package/dist/realtime/features/dm-sender.js +88 -0
  66. package/dist/realtime/features/error-handler.js +185 -0
  67. package/dist/realtime/features/gap-handler.js +61 -0
  68. package/dist/realtime/features/persistent-logger.js +186 -0
  69. package/dist/realtime/features/presence.manager.js +66 -0
  70. package/dist/realtime/features/session-health-monitor.js +345 -0
  71. package/dist/realtime/index.js +30 -0
  72. package/dist/realtime/messages/app-presence.event.d.ts +9 -0
  73. package/dist/realtime/messages/app-presence.event.js +3 -0
  74. package/dist/realtime/messages/app-presence.event.js.map +1 -0
  75. package/dist/realtime/messages/index.d.ts +3 -0
  76. package/dist/realtime/messages/index.js +20 -0
  77. package/dist/realtime/messages/index.js.map +1 -0
  78. package/dist/realtime/messages/message-sync.message.d.ts +222 -0
  79. package/dist/realtime/messages/message-sync.message.js +43 -0
  80. package/dist/realtime/messages/message-sync.message.js.map +1 -0
  81. package/dist/realtime/messages/realtime-sub.direct.data.d.ts +11 -0
  82. package/dist/realtime/messages/realtime-sub.direct.data.js +3 -0
  83. package/dist/realtime/messages/realtime-sub.direct.data.js.map +1 -0
  84. package/dist/realtime/messages/thread-update.message.d.ts +68 -0
  85. package/dist/realtime/messages/thread-update.message.js +3 -0
  86. package/dist/realtime/messages/thread-update.message.js.map +1 -0
  87. package/dist/realtime/mixins/index.d.ts +3 -0
  88. package/dist/realtime/mixins/index.js +20 -0
  89. package/dist/realtime/mixins/index.js.map +1 -0
  90. package/dist/realtime/mixins/message-sync.mixin.d.ts +8 -0
  91. package/dist/realtime/mixins/message-sync.mixin.js +596 -0
  92. package/dist/realtime/mixins/message-sync.mixin.js.map +1 -0
  93. package/dist/realtime/mixins/mixin.d.ts +19 -0
  94. package/dist/realtime/mixins/mixin.js +41 -0
  95. package/dist/realtime/mixins/mixin.js.map +1 -0
  96. package/dist/realtime/mixins/presence-typing.mixin.js +33 -0
  97. package/dist/realtime/mixins/realtime-sub.mixin.d.ts +8 -0
  98. package/dist/realtime/mixins/realtime-sub.mixin.js +181 -0
  99. package/dist/realtime/mixins/realtime-sub.mixin.js.map +1 -0
  100. package/dist/realtime/parsers/graphql-parser.js +43 -0
  101. package/dist/realtime/parsers/graphql.parser.d.ts +15 -0
  102. package/dist/realtime/parsers/graphql.parser.js +22 -0
  103. package/dist/realtime/parsers/graphql.parser.js.map +1 -0
  104. package/dist/realtime/parsers/index.d.ts +6 -0
  105. package/dist/realtime/parsers/index.js +23 -0
  106. package/dist/realtime/parsers/index.js.map +1 -0
  107. package/dist/realtime/parsers/iris-parser.js +43 -0
  108. package/dist/realtime/parsers/iris.parser.d.ts +17 -0
  109. package/dist/realtime/parsers/iris.parser.js +10 -0
  110. package/dist/realtime/parsers/iris.parser.js.map +1 -0
  111. package/dist/realtime/parsers/json-parser.js +43 -0
  112. package/dist/realtime/parsers/json.parser.d.ts +6 -0
  113. package/dist/realtime/parsers/json.parser.js +10 -0
  114. package/dist/realtime/parsers/json.parser.js.map +1 -0
  115. package/dist/realtime/parsers/parser.d.ts +9 -0
  116. package/dist/realtime/parsers/parser.js +3 -0
  117. package/dist/realtime/parsers/parser.js.map +1 -0
  118. package/dist/realtime/parsers/region-hint-parser.js +43 -0
  119. package/dist/realtime/parsers/region-hint.parser.d.ts +12 -0
  120. package/dist/realtime/parsers/region-hint.parser.js +15 -0
  121. package/dist/realtime/parsers/region-hint.parser.js.map +1 -0
  122. package/dist/realtime/parsers/skywalker-parser.js +43 -0
  123. package/dist/realtime/parsers/skywalker.parser.d.ts +12 -0
  124. package/dist/realtime/parsers/skywalker.parser.js +15 -0
  125. package/dist/realtime/parsers/skywalker.parser.js.map +1 -0
  126. package/dist/realtime/parsers-advanced.js +158 -0
  127. package/dist/realtime/proto/common.proto +38 -0
  128. package/dist/realtime/proto/direct.proto +65 -0
  129. package/dist/realtime/proto/ig-messages.proto +83 -0
  130. package/dist/realtime/proto/iris.proto +188 -0
  131. package/dist/realtime/proto-parser.js +195 -0
  132. package/dist/realtime/protocols/iris.handshake.js +74 -0
  133. package/dist/realtime/protocols/proto-definitions.js +80 -0
  134. package/dist/realtime/protocols/skywalker.protocol.js +91 -0
  135. package/dist/realtime/realtime.client.events.js +3 -0
  136. package/dist/realtime/realtime.client.js +1915 -0
  137. package/dist/realtime/realtime.service.js +462 -0
  138. package/dist/realtime/reconnect.manager.js +88 -0
  139. package/dist/realtime/session.manager.js +121 -0
  140. package/dist/realtime/subscriptions/graphql.subscription.d.ts +47 -0
  141. package/dist/realtime/subscriptions/graphql.subscription.js +99 -0
  142. package/dist/realtime/subscriptions/graphql.subscription.js.map +1 -0
  143. package/dist/realtime/subscriptions/index.d.ts +2 -0
  144. package/dist/realtime/subscriptions/index.js +19 -0
  145. package/dist/realtime/subscriptions/index.js.map +1 -0
  146. package/dist/realtime/subscriptions/skywalker.subscription.d.ts +4 -0
  147. package/dist/realtime/subscriptions/skywalker.subscription.js +13 -0
  148. package/dist/realtime/subscriptions/skywalker.subscription.js.map +1 -0
  149. package/dist/realtime/topic-map.js +71 -0
  150. package/dist/realtime/topic.js +80 -0
  151. package/dist/repositories/account.repository.js +575 -0
  152. package/dist/repositories/bloks.repository.js +70 -0
  153. package/dist/repositories/captcha.repository.js +44 -0
  154. package/dist/repositories/challenge.repository.js +120 -0
  155. package/dist/repositories/clip.repository.js +165 -0
  156. package/dist/repositories/close-friends.repository.js +46 -0
  157. package/dist/repositories/collection.repository.js +68 -0
  158. package/dist/repositories/direct-thread.repository.js +446 -0
  159. package/dist/repositories/direct.repository.js +232 -0
  160. package/dist/repositories/explore.repository.js +70 -0
  161. package/dist/repositories/fbsearch.repository.js +140 -0
  162. package/dist/repositories/feed.repository.js +245 -0
  163. package/dist/repositories/friendship.repository.js +296 -0
  164. package/dist/repositories/fundraiser.repository.js +49 -0
  165. package/dist/repositories/hashtag.repository.js +99 -0
  166. package/dist/repositories/highlights.repository.js +121 -0
  167. package/dist/repositories/insights.repository.js +82 -0
  168. package/dist/repositories/location.repository.js +84 -0
  169. package/dist/repositories/media.repository.js +395 -0
  170. package/dist/repositories/multiple-accounts.repository.js +41 -0
  171. package/dist/repositories/news.repository.js +35 -0
  172. package/dist/repositories/note.repository.js +57 -0
  173. package/dist/repositories/notification.repository.js +79 -0
  174. package/dist/repositories/share.repository.js +35 -0
  175. package/dist/repositories/signup.repository.js +218 -0
  176. package/dist/repositories/story.repository.js +290 -0
  177. package/dist/repositories/timeline.repository.js +60 -0
  178. package/dist/repositories/totp.repository.js +139 -0
  179. package/dist/repositories/track.repository.js +53 -0
  180. package/dist/repositories/upload.repository.js +204 -0
  181. package/dist/repositories/user.repository.js +360 -0
  182. package/dist/sendmedia/index.js +27 -0
  183. package/dist/sendmedia/sendFile.js +72 -0
  184. package/dist/sendmedia/sendPhoto.js +142 -0
  185. package/dist/sendmedia/sendRavenPhoto.js +153 -0
  186. package/dist/sendmedia/sendRavenVideo.js +158 -0
  187. package/dist/sendmedia/uploadPhoto.js +107 -0
  188. package/dist/sendmedia/uploadfFile.js +130 -0
  189. package/dist/services/live.service.js +139 -0
  190. package/dist/services/search.service.js +115 -0
  191. package/dist/shared/index.js +96 -0
  192. package/dist/shared/shared.js +86 -0
  193. package/dist/thrift/index.d.ts +3 -0
  194. package/dist/thrift/index.js +20 -0
  195. package/dist/thrift/index.js.map +1 -0
  196. package/dist/thrift/thrift.d.ts +59 -0
  197. package/dist/thrift/thrift.js +101 -0
  198. package/dist/thrift/thrift.js.map +1 -0
  199. package/dist/thrift/thrift.reading.d.ts +41 -0
  200. package/dist/thrift/thrift.reading.js +327 -0
  201. package/dist/thrift/thrift.reading.js.map +1 -0
  202. package/dist/thrift/thrift.writing.d.ts +44 -0
  203. package/dist/thrift/thrift.writing.js +342 -0
  204. package/dist/thrift/thrift.writing.js.map +1 -0
  205. package/dist/types/index.js +285 -0
  206. package/dist/useMultiFileAuthState.js +1768 -0
  207. package/dist/utils/helper-1.js +1 -0
  208. package/dist/utils/helper-10.js +1 -0
  209. package/dist/utils/helper-11.js +1 -0
  210. package/dist/utils/helper-12.js +1 -0
  211. package/dist/utils/helper-13.js +1 -0
  212. package/dist/utils/helper-14.js +1 -0
  213. package/dist/utils/helper-15.js +1 -0
  214. package/dist/utils/helper-16.js +1 -0
  215. package/dist/utils/helper-17.js +1 -0
  216. package/dist/utils/helper-18.js +1 -0
  217. package/dist/utils/helper-19.js +1 -0
  218. package/dist/utils/helper-2.js +1 -0
  219. package/dist/utils/helper-20.js +1 -0
  220. package/dist/utils/helper-21.js +1 -0
  221. package/dist/utils/helper-22.js +1 -0
  222. package/dist/utils/helper-23.js +1 -0
  223. package/dist/utils/helper-24.js +1 -0
  224. package/dist/utils/helper-25.js +1 -0
  225. package/dist/utils/helper-26.js +1 -0
  226. package/dist/utils/helper-27.js +1 -0
  227. package/dist/utils/helper-28.js +1 -0
  228. package/dist/utils/helper-29.js +1 -0
  229. package/dist/utils/helper-3.js +1 -0
  230. package/dist/utils/helper-30.js +1 -0
  231. package/dist/utils/helper-4.js +1 -0
  232. package/dist/utils/helper-5.js +1 -0
  233. package/dist/utils/helper-6.js +1 -0
  234. package/dist/utils/helper-7.js +1 -0
  235. package/dist/utils/helper-8.js +1 -0
  236. package/dist/utils/helper-9.js +1 -0
  237. package/dist/utils/index.js +280 -0
  238. package/dist/utils/insta-mqtt-helper.js +128 -0
  239. package/examples/listen-to-messages.js +86 -0
  240. package/package.json +82 -0
@@ -0,0 +1,575 @@
1
+ const Repository = require('../core/repository');
2
+ const crypto = require('crypto');
3
+
4
+ class AccountRepository extends Repository {
5
+ constructor(client) {
6
+ super(client);
7
+ this.maxRetries = 3;
8
+ }
9
+
10
+ async requestWithRetry(requestFn, retries = 0) {
11
+ try {
12
+ const result = await requestFn();
13
+ return result;
14
+ } catch (error) {
15
+ const shouldRetry =
16
+ (error.data?.error_type === 'server_error' ||
17
+ error.data?.error_type === 'rate_limited') &&
18
+ retries < this.maxRetries;
19
+ if (shouldRetry) {
20
+ const delay = 1000 * (retries + 1);
21
+ await new Promise(resolve => setTimeout(resolve, delay));
22
+ return this.requestWithRetry(requestFn, retries + 1);
23
+ }
24
+ throw error;
25
+ }
26
+ }
27
+
28
+ async login(credentialsOrUsername, passwordArg) {
29
+ let username, password;
30
+ if (typeof credentialsOrUsername === 'object' && credentialsOrUsername !== null) {
31
+ username = credentialsOrUsername.username;
32
+ password = credentialsOrUsername.password;
33
+ } else {
34
+ username = credentialsOrUsername;
35
+ password = passwordArg;
36
+ }
37
+ if (!username || !password) {
38
+ throw new Error('Username and password are required');
39
+ }
40
+
41
+ if (!this.client.state.passwordEncryptionPubKey) {
42
+ await this.syncLoginExperiments();
43
+ }
44
+
45
+ const { encrypted, time } = this.encryptPassword(password);
46
+
47
+ return this.requestWithRetry(async () => {
48
+ const countryCode = this.client.state.countryCode || 1;
49
+ const response = await this.client.request.send({
50
+ method: 'POST',
51
+ url: '/api/v1/accounts/login/',
52
+ form: this.client.request.sign({
53
+ jazoest: AccountRepository.createJazoest(this.client.state.phoneId),
54
+ country_codes: JSON.stringify([{ country_code: String(countryCode), source: ['default'] }]),
55
+ phone_id: this.client.state.phoneId,
56
+ enc_password: `#PWD_INSTAGRAM:4:${time}:${encrypted}`,
57
+ username,
58
+ adid: this.client.state.adid,
59
+ guid: this.client.state.uuid,
60
+ device_id: this.client.state.deviceId,
61
+ google_tokens: '[]',
62
+ login_attempt_count: '0',
63
+ }),
64
+ });
65
+
66
+ const body = response.body;
67
+
68
+ if (body.two_factor_required) {
69
+ const err = new Error('Two factor authentication required');
70
+ err.name = 'IgLoginTwoFactorRequiredError';
71
+ err.twoFactorInfo = body.two_factor_info;
72
+ throw err;
73
+ }
74
+ if (body.error_type === 'bad_password') {
75
+ const err = new Error('Bad password');
76
+ err.name = 'IgLoginBadPasswordError';
77
+ throw err;
78
+ }
79
+ if (body.error_type === 'invalid_user') {
80
+ const err = new Error('Invalid user');
81
+ err.name = 'IgLoginInvalidUserError';
82
+ throw err;
83
+ }
84
+ if (body.message === 'challenge_required') {
85
+ const err = new Error('Challenge required');
86
+ err.name = 'IgCheckpointError';
87
+ err.challengeInfo = body.challenge;
88
+ throw err;
89
+ }
90
+
91
+ return body.logged_in_user;
92
+ });
93
+ }
94
+
95
+ async twoFactorLogin(username, verificationCode, twoFactorIdentifier, verificationMethod = '1') {
96
+ return this.requestWithRetry(async () => {
97
+ const response = await this.client.request.send({
98
+ method: 'POST',
99
+ url: '/api/v1/accounts/two_factor_login/',
100
+ form: this.client.request.sign({
101
+ username,
102
+ verification_code: verificationCode,
103
+ two_factor_identifier: twoFactorIdentifier,
104
+ verification_method: verificationMethod,
105
+ trust_this_device: '1',
106
+ guid: this.client.state.uuid,
107
+ device_id: this.client.state.deviceId,
108
+ phone_id: this.client.state.phoneId,
109
+ }),
110
+ });
111
+ return response.body;
112
+ });
113
+ }
114
+
115
+ async logout() {
116
+ return this.requestWithRetry(async () => {
117
+ const response = await this.client.request.send({
118
+ method: 'POST',
119
+ url: '/api/v1/accounts/logout/',
120
+ form: this.client.request.sign({
121
+ _uuid: this.client.state.uuid,
122
+ }),
123
+ });
124
+ return response.body;
125
+ });
126
+ }
127
+
128
+ async currentUser() {
129
+ return this.requestWithRetry(async () => {
130
+ const response = await this.client.request.send({
131
+ method: 'GET',
132
+ url: '/api/v1/accounts/current_user/',
133
+ qs: { edit: true },
134
+ });
135
+ return response.body;
136
+ });
137
+ }
138
+
139
+ async accountInfo() {
140
+ return this.currentUser();
141
+ }
142
+
143
+ async editProfile({ externalUrl, phoneNumber, username, fullName, biography, email } = {}) {
144
+ return this.requestWithRetry(async () => {
145
+ const current = await this.currentUser();
146
+ const user = current.user || current;
147
+ const response = await this.client.request.send({
148
+ method: 'POST',
149
+ url: '/api/v1/accounts/edit_profile/',
150
+ form: this.client.request.sign({
151
+ _uuid: this.client.state.uuid,
152
+ external_url: externalUrl !== undefined ? externalUrl : (user.external_url || ''),
153
+ phone_number: phoneNumber !== undefined ? phoneNumber : (user.phone_number || ''),
154
+ username: username !== undefined ? username : user.username,
155
+ full_name: fullName !== undefined ? fullName : (user.full_name || ''),
156
+ biography: biography !== undefined ? biography : (user.biography || ''),
157
+ email: email !== undefined ? email : (user.email || ''),
158
+ }),
159
+ });
160
+ return response.body;
161
+ });
162
+ }
163
+
164
+ async setBiography(biography) {
165
+ return this.editProfile({ biography });
166
+ }
167
+
168
+ async setExternalUrl(url) {
169
+ return this.editProfile({ externalUrl: url });
170
+ }
171
+
172
+ async removeBioLinks() {
173
+ return this.editProfile({ externalUrl: '' });
174
+ }
175
+
176
+ async setGender(gender) {
177
+ return this.requestWithRetry(async () => {
178
+ const response = await this.client.request.send({
179
+ method: 'POST',
180
+ url: '/api/v1/accounts/set_gender/',
181
+ form: this.client.request.sign({
182
+ _uuid: this.client.state.uuid,
183
+ gender,
184
+ }),
185
+ });
186
+ return response.body;
187
+ });
188
+ }
189
+
190
+ async setPrivate() {
191
+ return this.requestWithRetry(async () => {
192
+ const response = await this.client.request.send({
193
+ method: 'POST',
194
+ url: '/api/v1/accounts/set_private/',
195
+ form: this.client.request.sign({
196
+ _uuid: this.client.state.uuid,
197
+ }),
198
+ });
199
+ return response.body;
200
+ });
201
+ }
202
+
203
+ async setPublic() {
204
+ return this.requestWithRetry(async () => {
205
+ const response = await this.client.request.send({
206
+ method: 'POST',
207
+ url: '/api/v1/accounts/set_public/',
208
+ form: this.client.request.sign({
209
+ _uuid: this.client.state.uuid,
210
+ }),
211
+ });
212
+ return response.body;
213
+ });
214
+ }
215
+
216
+ async changePassword(oldPassword, newPassword) {
217
+ const oldEnc = this.encryptPassword(oldPassword);
218
+ const newEnc = this.encryptPassword(newPassword);
219
+ return this.requestWithRetry(async () => {
220
+ const response = await this.client.request.send({
221
+ method: 'POST',
222
+ url: '/api/v1/accounts/change_password/',
223
+ form: this.client.request.sign({
224
+ _uuid: this.client.state.uuid,
225
+ enc_old_password: `#PWD_INSTAGRAM:4:${oldEnc.time}:${oldEnc.encrypted}`,
226
+ enc_new_password1: `#PWD_INSTAGRAM:4:${newEnc.time}:${newEnc.encrypted}`,
227
+ enc_new_password2: `#PWD_INSTAGRAM:4:${newEnc.time}:${newEnc.encrypted}`,
228
+ }),
229
+ });
230
+ return response.body;
231
+ });
232
+ }
233
+
234
+ async sendConfirmEmail() {
235
+ return this.requestWithRetry(async () => {
236
+ const response = await this.client.request.send({
237
+ method: 'POST',
238
+ url: '/api/v1/accounts/send_confirm_email/',
239
+ form: this.client.request.sign({
240
+ _uuid: this.client.state.uuid,
241
+ send_source: 'edit_profile',
242
+ }),
243
+ });
244
+ return response.body;
245
+ });
246
+ }
247
+
248
+ async sendConfirmPhoneNumber(phoneNumber) {
249
+ return this.requestWithRetry(async () => {
250
+ const response = await this.client.request.send({
251
+ method: 'POST',
252
+ url: '/api/v1/accounts/send_confirm_phone_number/',
253
+ form: this.client.request.sign({
254
+ _uuid: this.client.state.uuid,
255
+ phone_number: phoneNumber,
256
+ }),
257
+ });
258
+ return response.body;
259
+ });
260
+ }
261
+
262
+ async profilePictureChange(uploadId) {
263
+ return this.requestWithRetry(async () => {
264
+ const response = await this.client.request.send({
265
+ method: 'POST',
266
+ url: '/api/v1/accounts/change_profile_picture/',
267
+ form: this.client.request.sign({
268
+ _uuid: this.client.state.uuid,
269
+ use_fbuploader: 'true',
270
+ upload_id: uploadId,
271
+ }),
272
+ });
273
+ return response.body;
274
+ });
275
+ }
276
+
277
+ async profilePictureRemove() {
278
+ return this.requestWithRetry(async () => {
279
+ const response = await this.client.request.send({
280
+ method: 'POST',
281
+ url: '/api/v1/accounts/remove_profile_picture/',
282
+ form: this.client.request.sign({
283
+ _uuid: this.client.state.uuid,
284
+ }),
285
+ });
286
+ return response.body;
287
+ });
288
+ }
289
+
290
+ async newsInbox() {
291
+ return this.requestWithRetry(async () => {
292
+ const response = await this.client.request.send({
293
+ method: 'GET',
294
+ url: '/api/v1/news/inbox/',
295
+ });
296
+ return response.body;
297
+ });
298
+ }
299
+
300
+ async syncLoginExperiments() {
301
+ return this.requestWithRetry(async () => {
302
+ const response = await this.client.request.send({
303
+ method: 'POST',
304
+ url: '/api/v1/qe/sync/',
305
+ form: this.client.request.sign({
306
+ id: this.client.state.uuid,
307
+ server_config_retrieval: '1',
308
+ experiments: this.client.state.constants.LOGIN_EXPERIMENTS,
309
+ }),
310
+ });
311
+ return response.body;
312
+ });
313
+ }
314
+
315
+ async syncPostLoginExperiments() {
316
+ let userId;
317
+ try { userId = this.client.state.cookieUserId; } catch { userId = '0'; }
318
+ return this.requestWithRetry(async () => {
319
+ const response = await this.client.request.send({
320
+ method: 'POST',
321
+ url: '/api/v1/qe/sync/',
322
+ form: this.client.request.sign({
323
+ id: userId,
324
+ _uid: userId,
325
+ _uuid: this.client.state.uuid,
326
+ server_config_retrieval: '1',
327
+ experiments: this.client.state.constants.EXPERIMENTS,
328
+ }),
329
+ });
330
+ return response.body;
331
+ });
332
+ }
333
+
334
+ async syncLauncher(preLogin = true) {
335
+ const data = {
336
+ id: this.client.state.uuid,
337
+ server_config_retrieval: '1',
338
+ };
339
+ if (!preLogin) {
340
+ try {
341
+ data._uid = this.client.state.cookieUserId;
342
+ data._uuid = this.client.state.uuid;
343
+ } catch {}
344
+ }
345
+ return this.requestWithRetry(async () => {
346
+ const response = await this.client.request.send({
347
+ method: 'POST',
348
+ url: '/api/v1/launcher/sync/',
349
+ form: this.client.request.sign(data),
350
+ });
351
+ return response.body;
352
+ });
353
+ }
354
+
355
+ async syncDeviceFeatures() {
356
+ return this.requestWithRetry(async () => {
357
+ const response = await this.client.request.send({
358
+ method: 'POST',
359
+ url: '/api/v1/devices/sync/',
360
+ form: this.client.request.sign({
361
+ id: this.client.state.uuid,
362
+ server_config_retrieval: '1',
363
+ }),
364
+ });
365
+ return response.body;
366
+ });
367
+ }
368
+
369
+ async getPrefillCandidates() {
370
+ return this.requestWithRetry(async () => {
371
+ const response = await this.client.request.send({
372
+ method: 'POST',
373
+ url: '/api/v1/accounts/get_prefill_candidates/',
374
+ form: this.client.request.sign({
375
+ android_device_id: this.client.state.deviceId,
376
+ phone_id: this.client.state.phoneId,
377
+ usages: '["account_recovery_omnibox"]',
378
+ device_id: this.client.state.uuid,
379
+ }),
380
+ });
381
+ return response.body;
382
+ });
383
+ }
384
+
385
+ async contactPointPrefill(usage = 'prefill') {
386
+ return this.requestWithRetry(async () => {
387
+ const response = await this.client.request.send({
388
+ method: 'POST',
389
+ url: '/api/v1/accounts/contact_point_prefill/',
390
+ form: this.client.request.sign({
391
+ phone_id: this.client.state.phoneId,
392
+ usage,
393
+ }),
394
+ });
395
+ return response.body;
396
+ });
397
+ }
398
+
399
+ async getZrToken(params = {}) {
400
+ return this.requestWithRetry(async () => {
401
+ const response = await this.client.request.send({
402
+ method: 'GET',
403
+ url: '/api/v1/zr/token/result/',
404
+ qs: {
405
+ device_id: this.client.state.deviceId,
406
+ custom_device_id: this.client.state.uuid,
407
+ fetch_reason: 'token_expired',
408
+ token_hash: '',
409
+ ...params,
410
+ },
411
+ });
412
+ return response.body;
413
+ });
414
+ }
415
+
416
+ async getConsentSignupConfig() {
417
+ return this.requestWithRetry(async () => {
418
+ const response = await this.client.request.send({
419
+ method: 'GET',
420
+ url: '/api/v1/consent/get_signup_config/',
421
+ qs: {
422
+ guid: this.client.state.uuid,
423
+ main_account_selected: false,
424
+ },
425
+ });
426
+ return response.body;
427
+ });
428
+ }
429
+
430
+ async sendRecoveryFlowEmail(query) {
431
+ return this.requestWithRetry(async () => {
432
+ const response = await this.client.request.send({
433
+ url: '/api/v1/accounts/send_recovery_flow_email/',
434
+ method: 'POST',
435
+ form: this.client.request.sign({
436
+ adid: '',
437
+ guid: this.client.state.uuid,
438
+ device_id: this.client.state.deviceId,
439
+ query,
440
+ }),
441
+ });
442
+ return response.body;
443
+ });
444
+ }
445
+
446
+ async sendRecoveryFlowSms(query) {
447
+ return this.requestWithRetry(async () => {
448
+ const response = await this.client.request.send({
449
+ url: '/api/v1/accounts/send_recovery_flow_sms/',
450
+ method: 'POST',
451
+ form: this.client.request.sign({
452
+ adid: '',
453
+ guid: this.client.state.uuid,
454
+ device_id: this.client.state.deviceId,
455
+ query,
456
+ }),
457
+ });
458
+ return response.body;
459
+ });
460
+ }
461
+
462
+ static createJazoest(input) {
463
+ const buf = Buffer.from(input, 'ascii');
464
+ let sum = 0;
465
+ for (let i = 0; i < buf.byteLength; i++) {
466
+ sum += buf.readUInt8(i);
467
+ }
468
+ return `2${sum}`;
469
+ }
470
+
471
+ encryptPassword(password) {
472
+ if (!this.client.state.passwordEncryptionPubKey) {
473
+ return { time: Math.floor(Date.now() / 1000).toString(), encrypted: password };
474
+ }
475
+
476
+ const randKey = crypto.randomBytes(32);
477
+ const iv = crypto.randomBytes(12);
478
+
479
+ const rsaEncrypted = crypto.publicEncrypt({
480
+ key: Buffer.from(this.client.state.passwordEncryptionPubKey, 'base64').toString(),
481
+ padding: crypto.constants.RSA_PKCS1_PADDING,
482
+ }, randKey);
483
+
484
+ const cipher = crypto.createCipheriv('aes-256-gcm', randKey, iv);
485
+ const time = Math.floor(Date.now() / 1000).toString();
486
+ cipher.setAAD(Buffer.from(time));
487
+
488
+ const aesEncrypted = Buffer.concat([cipher.update(password, 'utf8'), cipher.final()]);
489
+ const sizeBuffer = Buffer.alloc(2, 0);
490
+ sizeBuffer.writeInt16LE(rsaEncrypted.byteLength, 0);
491
+ const authTag = cipher.getAuthTag();
492
+
493
+ return {
494
+ time,
495
+ encrypted: Buffer.concat([
496
+ Buffer.from([1, this.client.state.passwordEncryptionKeyId || 0]),
497
+ iv,
498
+ sizeBuffer,
499
+ rsaEncrypted,
500
+ authTag,
501
+ aesEncrypted
502
+ ]).toString('base64')
503
+ };
504
+ }
505
+
506
+ async passwordPublicKeys() {
507
+ const response = await this.client.request.send({
508
+ method: 'GET',
509
+ url: '/api/v1/qe/sync/',
510
+ });
511
+ const headers = response.headers || {};
512
+ const keyId = parseInt(headers['ig-set-password-encryption-key-id'] || '0');
513
+ const pubKey = headers['ig-set-password-encryption-pub-key'] || '';
514
+ return { keyId, pubKey };
515
+ }
516
+
517
+ async setPresenceDisabled(disabled = true) {
518
+ return this.requestWithRetry(async () => {
519
+ const response = await this.client.request.send({
520
+ method: 'POST',
521
+ url: '/api/v1/accounts/set_presence_disabled/',
522
+ form: this.client.request.sign({
523
+ _uuid: this.client.state.uuid,
524
+ disabled: disabled ? '1' : '0',
525
+ }),
526
+ });
527
+ return response.body;
528
+ });
529
+ }
530
+
531
+ async getCommentFilter() {
532
+ return this.requestWithRetry(async () => {
533
+ const response = await this.client.request.send({
534
+ method: 'GET',
535
+ url: '/api/v1/accounts/get_comment_filter/',
536
+ });
537
+ return response.body;
538
+ });
539
+ }
540
+
541
+ async setCommentFilter(configValue = 0) {
542
+ return this.requestWithRetry(async () => {
543
+ const response = await this.client.request.send({
544
+ method: 'POST',
545
+ url: '/api/v1/accounts/set_comment_filter/',
546
+ form: this.client.request.sign({
547
+ _uuid: this.client.state.uuid,
548
+ config_value: String(configValue),
549
+ }),
550
+ });
551
+ return response.body;
552
+ });
553
+ }
554
+
555
+ async pushPreferences(preferences = 'default') {
556
+ return this.requestWithRetry(async () => {
557
+ const response = await this.client.request.send({
558
+ method: 'POST',
559
+ url: '/api/v1/push/register/',
560
+ form: this.client.request.sign({
561
+ _uuid: this.client.state.uuid,
562
+ device_type: 'android_mqtt',
563
+ is_main_push_channel: 'true',
564
+ phone_id: this.client.state.phoneId,
565
+ device_token: '',
566
+ guid: this.client.state.uuid,
567
+ users: preferences,
568
+ }),
569
+ });
570
+ return response.body;
571
+ });
572
+ }
573
+ }
574
+
575
+ module.exports = AccountRepository;
@@ -0,0 +1,70 @@
1
+ const Repository = require('../core/repository');
2
+
3
+ class BloksRepository extends Repository {
4
+ async action(params = {}) {
5
+ const {
6
+ actionName,
7
+ actionParams = {},
8
+ extraData = {},
9
+ } = params;
10
+
11
+ let userId;
12
+ try { userId = this.client.state.cookieUserId; } catch { userId = '0'; }
13
+
14
+ const data = {
15
+ _uuid: this.client.state.uuid,
16
+ _uid: userId,
17
+ action: actionName,
18
+ bk_client_context: JSON.stringify({
19
+ bloks_version: this.client.state.bloksVersionId,
20
+ styles_id: 'instagram',
21
+ }),
22
+ params: JSON.stringify(actionParams),
23
+ ...extraData,
24
+ };
25
+
26
+ const response = await this.client.request.send({
27
+ method: 'POST',
28
+ url: '/api/v1/bloks/apps/com.bloks.www.bloks.caa.login.async.send_login_request/',
29
+ form: this.client.request.sign(data),
30
+ });
31
+ return response.body;
32
+ }
33
+
34
+ async changePassword(oldPassword, newPassword) {
35
+ const oldEnc = this.client.account.encryptPassword(oldPassword);
36
+ const newEnc = this.client.account.encryptPassword(newPassword);
37
+
38
+ let userId;
39
+ try { userId = this.client.state.cookieUserId; } catch { userId = '0'; }
40
+
41
+ const data = {
42
+ _uuid: this.client.state.uuid,
43
+ _uid: userId,
44
+ enc_old_password: `#PWD_INSTAGRAM:4:${oldEnc.time}:${oldEnc.encrypted}`,
45
+ enc_new_password1: `#PWD_INSTAGRAM:4:${newEnc.time}:${newEnc.encrypted}`,
46
+ enc_new_password2: `#PWD_INSTAGRAM:4:${newEnc.time}:${newEnc.encrypted}`,
47
+ };
48
+
49
+ const response = await this.client.request.send({
50
+ method: 'POST',
51
+ url: '/api/v1/bloks/apps/com.instagram.challenge.navigation.take_challenge/',
52
+ form: this.client.request.sign(data),
53
+ });
54
+ return response.body;
55
+ }
56
+
57
+ async getLayoutData(params = {}) {
58
+ const response = await this.client.request.send({
59
+ method: 'POST',
60
+ url: '/api/v1/bloks/get_layout/',
61
+ form: this.client.request.sign({
62
+ _uuid: this.client.state.uuid,
63
+ ...params,
64
+ }),
65
+ });
66
+ return response.body;
67
+ }
68
+ }
69
+
70
+ module.exports = BloksRepository;
@@ -0,0 +1,44 @@
1
+ const Repository = require('../core/repository');
2
+
3
+ class CaptchaRepository extends Repository {
4
+ async getChallengeForm(apiPath) {
5
+ const url = apiPath.startsWith('/') ? apiPath : `/${apiPath}`;
6
+ const response = await this.client.request.send({
7
+ method: 'GET',
8
+ url,
9
+ qs: {
10
+ guid: this.client.state.uuid,
11
+ device_id: this.client.state.deviceId,
12
+ },
13
+ });
14
+ return response.body;
15
+ }
16
+
17
+ async submitRecaptchaResponse(apiPath, gRecaptchaResponse) {
18
+ const url = apiPath.startsWith('/') ? apiPath : `/${apiPath}`;
19
+ const response = await this.client.request.send({
20
+ method: 'POST',
21
+ url,
22
+ form: this.client.request.sign({
23
+ _uuid: this.client.state.uuid,
24
+ g_recaptcha_response: gRecaptchaResponse,
25
+ }),
26
+ });
27
+ return response.body;
28
+ }
29
+
30
+ async submitHCaptchaResponse(apiPath, hCaptchaResponse) {
31
+ const url = apiPath.startsWith('/') ? apiPath : `/${apiPath}`;
32
+ const response = await this.client.request.send({
33
+ method: 'POST',
34
+ url,
35
+ form: this.client.request.sign({
36
+ _uuid: this.client.state.uuid,
37
+ h_captcha_response: hCaptchaResponse,
38
+ }),
39
+ });
40
+ return response.body;
41
+ }
42
+ }
43
+
44
+ module.exports = CaptchaRepository;