nodejs-insta-private-api-mqt 1.3.85 → 1.3.87
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.
- package/dist/dist/constants/constants.d.ts +1 -0
- package/dist/dist/constants/index.d.ts +25 -0
- package/dist/dist/core/client.d.ts +106 -0
- package/dist/dist/core/nav-chain.d.ts +77 -0
- package/dist/dist/core/repository.d.ts +3 -0
- package/dist/dist/core/request.d.ts +76 -0
- package/dist/dist/core/state.d.ts +605 -0
- package/dist/dist/core/utils.d.ts +129 -0
- package/dist/dist/downloadMedia.d.ts +106 -0
- package/{dist-ts → dist}/dist/downloadMedia.js +19 -20
- package/dist/dist/errors/index.d.ts +18 -0
- package/dist/dist/extend.d.ts +20 -0
- package/dist/dist/fbns/fbns.client.d.ts +43 -0
- package/dist/dist/fbns/fbns.client.events.d.ts +0 -0
- package/{dist-ts → dist}/dist/fbns/fbns.client.js +4 -5
- package/dist/dist/fbns/fbns.device-auth.d.ts +9 -0
- package/{src-ts/dist/fbns/fbns.device-auth.ts → dist/dist/fbns/fbns.device-auth.js} +6 -3
- package/dist/dist/fbns/fbns.types.d.ts +0 -0
- package/dist/dist/fbns/fbns.utilities.d.ts +4 -0
- package/dist/dist/fbns/index.d.ts +2 -0
- package/dist/dist/index.d.ts +49 -0
- package/dist/dist/mqtt-shim.d.ts +1 -0
- package/dist/dist/mqttot/index.d.ts +2 -0
- package/dist/dist/mqttot/mqttot.client.d.ts +77 -0
- package/{dist-ts → dist}/dist/mqttot/mqttot.client.js +10 -10
- package/dist/dist/mqttot/mqttot.connect.request.packet.d.ts +1 -0
- package/dist/dist/mqttot/mqttot.connect.response.packet.d.ts +5 -0
- package/dist/dist/mqttot/mqttot.connection.d.ts +6 -0
- package/dist/dist/realtime/commands/commands.d.ts +19 -0
- package/dist/dist/realtime/commands/direct.commands.d.ts +142 -0
- package/dist/dist/realtime/commands/enhanced.direct.commands.d.ts +425 -0
- package/{dist-ts → dist}/dist/realtime/commands/enhanced.direct.commands.js +8 -10
- package/dist/dist/realtime/commands/index.d.ts +2 -0
- package/dist/dist/realtime/delta-sync.manager.d.ts +82 -0
- package/{dist-ts → dist}/dist/realtime/delta-sync.manager.js +7 -10
- package/dist/dist/realtime/features/dm-sender.d.ts +20 -0
- package/{src-ts/dist/realtime/features/dm-sender.ts → dist/dist/realtime/features/dm-sender.js} +6 -3
- package/dist/dist/realtime/features/error-handler.d.ts +33 -0
- package/{dist-ts → dist}/dist/realtime/features/error-handler.js +4 -4
- package/dist/dist/realtime/features/gap-handler.d.ts +19 -0
- package/dist/dist/realtime/features/persistent-logger.d.ts +28 -0
- package/{dist-ts → dist}/dist/realtime/features/persistent-logger.js +3 -3
- package/dist/dist/realtime/features/presence.manager.d.ts +24 -0
- package/{src-ts/dist/realtime/features/presence.manager.ts → dist/dist/realtime/features/presence.manager.js} +2 -1
- package/dist/dist/realtime/features/session-health-monitor.d.ts +93 -0
- package/{src-ts/dist/realtime/features/session-health-monitor.ts → dist/dist/realtime/features/session-health-monitor.js} +45 -65
- package/dist/dist/realtime/index.d.ts +9 -0
- package/dist/dist/realtime/messages/app-presence.event.d.ts +0 -0
- package/dist/dist/realtime/messages/index.d.ts +2 -0
- package/dist/dist/realtime/messages/message-sync.message.d.ts +1 -0
- package/dist/dist/realtime/messages/realtime-sub.direct.data.d.ts +0 -0
- package/dist/dist/realtime/messages/thread-update.message.d.ts +0 -0
- package/dist/dist/realtime/mixins/index.d.ts +2 -0
- package/dist/dist/realtime/mixins/message-sync.mixin.d.ts +38 -0
- package/{dist-ts → dist}/dist/realtime/mixins/message-sync.mixin.js +16 -18
- package/dist/dist/realtime/mixins/mixin.d.ts +4 -0
- package/dist/dist/realtime/mixins/presence-typing.mixin.d.ts +9 -0
- package/dist/dist/realtime/mixins/realtime-sub.mixin.d.ts +37 -0
- package/{dist-ts → dist}/dist/realtime/mixins/realtime-sub.mixin.js +4 -5
- package/dist/dist/realtime/parsers/graphql-parser.d.ts +18 -0
- package/dist/dist/realtime/parsers/graphql.parser.d.ts +10 -0
- package/{src-ts/dist/realtime/parsers/graphql.parser.ts → dist/dist/realtime/parsers/graphql.parser.js} +0 -1
- package/dist/dist/realtime/parsers/index.d.ts +2 -0
- package/dist/dist/realtime/parsers/iris-parser.d.ts +18 -0
- package/dist/dist/realtime/parsers/iris.parser.d.ts +3 -0
- package/dist/dist/realtime/parsers/json-parser.d.ts +18 -0
- package/dist/dist/realtime/parsers/json.parser.d.ts +6 -0
- package/dist/dist/realtime/parsers/parser.d.ts +0 -0
- package/dist/dist/realtime/parsers/region-hint-parser.d.ts +18 -0
- package/dist/dist/realtime/parsers/region-hint.parser.d.ts +4 -0
- package/dist/dist/realtime/parsers/skywalker-parser.d.ts +18 -0
- package/dist/dist/realtime/parsers/skywalker.parser.d.ts +7 -0
- package/dist/dist/realtime/parsers-advanced.d.ts +93 -0
- package/{dist-ts → dist}/dist/realtime/parsers-advanced.js +5 -8
- package/dist/dist/realtime/proto-parser.d.ts +27 -0
- package/{dist-ts → dist}/dist/realtime/proto-parser.js +1 -2
- package/dist/dist/realtime/protocols/iris.handshake.d.ts +41 -0
- package/dist/dist/realtime/protocols/proto-definitions.d.ts +0 -0
- package/dist/dist/realtime/protocols/skywalker.protocol.d.ts +20 -0
- package/{src-ts/dist/realtime/protocols/skywalker.protocol.ts → dist/dist/realtime/protocols/skywalker.protocol.js} +8 -5
- package/dist/dist/realtime/realtime.client.d.ts +169 -0
- package/dist/dist/realtime/realtime.client.events.d.ts +0 -0
- package/{dist-ts → dist}/dist/realtime/realtime.client.js +75 -86
- package/dist/dist/realtime/realtime.service.d.ts +109 -0
- package/dist/dist/realtime/reconnect.manager.d.ts +15 -0
- package/dist/dist/realtime/session.manager.d.ts +25 -0
- package/dist/dist/realtime/subscriptions/graphql.subscription.d.ts +4 -0
- package/dist/dist/realtime/subscriptions/index.d.ts +2 -0
- package/dist/dist/realtime/subscriptions/skywalker.subscription.d.ts +4 -0
- package/dist/dist/realtime/topic-map.d.ts +97 -0
- package/dist/dist/realtime/topic.d.ts +71 -0
- package/dist/dist/repositories/account.repository.d.ts +72 -0
- package/{dist-ts → dist}/dist/repositories/account.repository.js +828 -214
- package/dist/dist/repositories/bloks.repository.d.ts +6 -0
- package/dist/dist/repositories/captcha.repository.d.ts +6 -0
- package/dist/dist/repositories/challenge.repository.d.ts +12 -0
- package/{dist-ts → dist}/dist/repositories/challenge.repository.js +1 -2
- package/dist/dist/repositories/clip.repository.d.ts +10 -0
- package/dist/dist/repositories/close-friends.repository.d.ts +8 -0
- package/dist/dist/repositories/collection.repository.d.ts +8 -0
- package/dist/dist/repositories/direct-thread.repository.d.ts +88 -0
- package/{dist-ts → dist}/dist/repositories/direct-thread.repository.js +7 -9
- package/dist/dist/repositories/direct.repository.d.ts +22 -0
- package/{dist-ts → dist}/dist/repositories/direct.repository.js +4 -5
- package/dist/dist/repositories/explore.repository.d.ts +7 -0
- package/dist/dist/repositories/fbsearch.repository.d.ts +14 -0
- package/dist/dist/repositories/feed.repository.d.ts +19 -0
- package/dist/dist/repositories/friendship.repository.d.ts +26 -0
- package/dist/dist/repositories/fundraiser.repository.d.ts +6 -0
- package/dist/dist/repositories/hashtag.repository.d.ts +11 -0
- package/dist/dist/repositories/highlights.repository.d.ts +11 -0
- package/dist/dist/repositories/insights.repository.d.ts +8 -0
- package/dist/dist/repositories/location.repository.d.ts +9 -0
- package/dist/dist/repositories/media.repository.d.ts +41 -0
- package/{dist-ts → dist}/dist/repositories/media.repository.js +1 -2
- package/dist/dist/repositories/multiple-accounts.repository.d.ts +7 -0
- package/dist/dist/repositories/news.repository.d.ts +6 -0
- package/dist/dist/repositories/note.repository.d.ts +8 -0
- package/dist/dist/repositories/notification.repository.d.ts +33 -0
- package/{dist-ts → dist}/dist/repositories/notification.repository.js +1 -1
- package/dist/dist/repositories/share.repository.d.ts +12 -0
- package/dist/dist/repositories/signup.repository.d.ts +19 -0
- package/dist/dist/repositories/story.repository.d.ts +23 -0
- package/{dist-ts → dist}/dist/repositories/story.repository.js +1 -2
- package/dist/dist/repositories/timeline.repository.d.ts +7 -0
- package/dist/dist/repositories/totp.repository.d.ts +14 -0
- package/dist/dist/repositories/track.repository.d.ts +7 -0
- package/{dist-ts → dist}/dist/repositories/track.repository.js +1 -2
- package/dist/dist/repositories/upload.repository.d.ts +30 -0
- package/{dist-ts → dist}/dist/repositories/upload.repository.js +4 -5
- package/dist/dist/repositories/user.repository.d.ts +52 -0
- package/dist/dist/sendmedia/index.d.ts +12 -0
- package/dist/dist/sendmedia/sendFile.d.ts +8 -0
- package/dist/dist/sendmedia/sendPhoto.d.ts +26 -0
- package/dist/dist/sendmedia/sendRavenPhoto.d.ts +14 -0
- package/{dist-ts → dist}/dist/sendmedia/sendRavenPhoto.js +4 -5
- package/dist/dist/sendmedia/sendRavenVideo.d.ts +15 -0
- package/{dist-ts → dist}/dist/sendmedia/sendRavenVideo.js +4 -5
- package/dist/dist/sendmedia/uploadPhoto.d.ts +8 -0
- package/dist/dist/sendmedia/uploadfFile.d.ts +13 -0
- package/{dist-ts → dist}/dist/sendmedia/uploadfFile.js +3 -4
- package/dist/dist/services/live.service.d.ts +13 -0
- package/dist/dist/services/search.service.d.ts +11 -0
- package/dist/dist/shared/index.d.ts +4 -0
- package/{src-ts/dist/shared/index.ts → dist/dist/shared/index.js} +14 -13
- package/dist/dist/shared/shared.d.ts +15 -0
- package/dist/dist/thrift/index.d.ts +2 -0
- package/dist/dist/thrift/thrift.d.ts +11 -0
- package/dist/dist/thrift/thrift.reading.d.ts +49 -0
- package/{dist-ts → dist}/dist/thrift/thrift.reading.js +3 -5
- package/dist/dist/thrift/thrift.writing.d.ts +49 -0
- package/{dist-ts → dist}/dist/thrift/thrift.writing.js +2 -4
- package/dist/dist/types/index.d.ts +28 -0
- package/dist/dist/useMultiFileAuthState.d.ts +267 -0
- package/{dist-ts → dist}/dist/useMultiFileAuthState.js +47 -61
- package/dist/dist/utils/helper-1.d.ts +0 -0
- package/dist/dist/utils/helper-10.d.ts +0 -0
- package/dist/dist/utils/helper-11.d.ts +0 -0
- package/dist/dist/utils/helper-12.d.ts +0 -0
- package/dist/dist/utils/helper-13.d.ts +0 -0
- package/dist/dist/utils/helper-14.d.ts +0 -0
- package/dist/dist/utils/helper-15.d.ts +0 -0
- package/dist/dist/utils/helper-16.d.ts +0 -0
- package/dist/dist/utils/helper-17.d.ts +0 -0
- package/dist/dist/utils/helper-18.d.ts +0 -0
- package/dist/dist/utils/helper-19.d.ts +0 -0
- package/dist/dist/utils/helper-2.d.ts +0 -0
- package/dist/dist/utils/helper-20.d.ts +0 -0
- package/dist/dist/utils/helper-21.d.ts +0 -0
- package/dist/dist/utils/helper-22.d.ts +0 -0
- package/dist/dist/utils/helper-23.d.ts +0 -0
- package/dist/dist/utils/helper-24.d.ts +0 -0
- package/dist/dist/utils/helper-25.d.ts +0 -0
- package/dist/dist/utils/helper-26.d.ts +0 -0
- package/dist/dist/utils/helper-27.d.ts +0 -0
- package/dist/dist/utils/helper-28.d.ts +0 -0
- package/dist/dist/utils/helper-29.d.ts +0 -0
- package/dist/dist/utils/helper-3.d.ts +0 -0
- package/dist/dist/utils/helper-30.d.ts +0 -0
- package/dist/dist/utils/helper-4.d.ts +0 -0
- package/dist/dist/utils/helper-5.d.ts +0 -0
- package/dist/dist/utils/helper-6.d.ts +0 -0
- package/dist/dist/utils/helper-7.d.ts +0 -0
- package/dist/dist/utils/helper-8.d.ts +0 -0
- package/dist/dist/utils/helper-9.d.ts +0 -0
- package/dist/dist/utils/index.d.ts +56 -0
- package/{dist-ts → dist}/dist/utils/index.js +1 -2
- package/dist/dist/utils/insta-mqtt-helper.d.ts +30 -0
- package/dist/examples/listen-to-messages.d.ts +4 -0
- package/{dist-ts → dist}/examples/listen-to-messages.js +1 -2
- package/package.json +37 -42
- package/dist-ts/dist/fbns/fbns.device-auth.js +0 -59
- package/dist-ts/dist/realtime/features/dm-sender.js +0 -94
- package/dist-ts/dist/realtime/features/presence.manager.js +0 -68
- package/dist-ts/dist/realtime/features/session-health-monitor.js +0 -327
- package/dist-ts/dist/realtime/parsers/graphql.parser.js +0 -22
- package/dist-ts/dist/realtime/protocols/skywalker.protocol.js +0 -96
- package/dist-ts/dist/shared/index.js +0 -98
- package/examples/listen-to-messages.js +0 -86
- package/src-ts/dist/constants/constants.ts +0 -342
- package/src-ts/dist/constants/index.ts +0 -58
- package/src-ts/dist/core/client.ts +0 -419
- package/src-ts/dist/core/nav-chain.ts +0 -282
- package/src-ts/dist/core/repository.ts +0 -7
- package/src-ts/dist/core/request.ts +0 -395
- package/src-ts/dist/core/state.ts +0 -1484
- package/src-ts/dist/core/utils.ts +0 -786
- package/src-ts/dist/downloadMedia.ts +0 -381
- package/src-ts/dist/errors/index.ts +0 -38
- package/src-ts/dist/extend.ts +0 -167
- package/src-ts/dist/fbns/fbns.client.events.ts +0 -3
- package/src-ts/dist/fbns/fbns.client.ts +0 -252
- package/src-ts/dist/fbns/fbns.types.ts +0 -3
- package/src-ts/dist/fbns/fbns.utilities.ts +0 -79
- package/src-ts/dist/fbns/index.ts +0 -21
- package/src-ts/dist/index.ts +0 -139
- package/src-ts/dist/mqtt-shim.ts +0 -15
- package/src-ts/dist/mqttot/index.ts +0 -21
- package/src-ts/dist/mqttot/mqttot.client.ts +0 -318
- package/src-ts/dist/mqttot/mqttot.connect.request.packet.ts +0 -9
- package/src-ts/dist/mqttot/mqttot.connect.response.packet.ts +0 -24
- package/src-ts/dist/mqttot/mqttot.connection.ts +0 -77
- package/src-ts/dist/realtime/commands/commands.ts +0 -71
- package/src-ts/dist/realtime/commands/direct.commands.ts +0 -417
- package/src-ts/dist/realtime/commands/enhanced.direct.commands.ts +0 -1731
- package/src-ts/dist/realtime/commands/index.ts +0 -20
- package/src-ts/dist/realtime/delta-sync.manager.ts +0 -293
- package/src-ts/dist/realtime/features/error-handler.ts +0 -185
- package/src-ts/dist/realtime/features/gap-handler.ts +0 -61
- package/src-ts/dist/realtime/features/persistent-logger.ts +0 -186
- package/src-ts/dist/realtime/index.ts +0 -30
- package/src-ts/dist/realtime/messages/app-presence.event.ts +0 -3
- package/src-ts/dist/realtime/messages/index.ts +0 -20
- package/src-ts/dist/realtime/messages/message-sync.message.ts +0 -43
- package/src-ts/dist/realtime/messages/realtime-sub.direct.data.ts +0 -3
- package/src-ts/dist/realtime/messages/thread-update.message.ts +0 -3
- package/src-ts/dist/realtime/mixins/index.ts +0 -20
- package/src-ts/dist/realtime/mixins/message-sync.mixin.ts +0 -596
- package/src-ts/dist/realtime/mixins/mixin.ts +0 -41
- package/src-ts/dist/realtime/mixins/presence-typing.mixin.ts +0 -33
- package/src-ts/dist/realtime/mixins/realtime-sub.mixin.ts +0 -181
- package/src-ts/dist/realtime/parsers/graphql-parser.ts +0 -43
- package/src-ts/dist/realtime/parsers/index.ts +0 -23
- package/src-ts/dist/realtime/parsers/iris-parser.ts +0 -43
- package/src-ts/dist/realtime/parsers/iris.parser.ts +0 -10
- package/src-ts/dist/realtime/parsers/json-parser.ts +0 -43
- package/src-ts/dist/realtime/parsers/json.parser.ts +0 -10
- package/src-ts/dist/realtime/parsers/parser.ts +0 -3
- package/src-ts/dist/realtime/parsers/region-hint-parser.ts +0 -43
- package/src-ts/dist/realtime/parsers/region-hint.parser.ts +0 -15
- package/src-ts/dist/realtime/parsers/skywalker-parser.ts +0 -43
- package/src-ts/dist/realtime/parsers/skywalker.parser.ts +0 -15
- package/src-ts/dist/realtime/parsers-advanced.ts +0 -158
- package/src-ts/dist/realtime/proto-parser.ts +0 -195
- package/src-ts/dist/realtime/protocols/iris.handshake.ts +0 -74
- package/src-ts/dist/realtime/protocols/proto-definitions.ts +0 -80
- package/src-ts/dist/realtime/realtime.client.events.ts +0 -3
- package/src-ts/dist/realtime/realtime.client.ts +0 -1996
- package/src-ts/dist/realtime/realtime.service.ts +0 -462
- package/src-ts/dist/realtime/reconnect.manager.ts +0 -88
- package/src-ts/dist/realtime/session.manager.ts +0 -121
- package/src-ts/dist/realtime/subscriptions/graphql.subscription.ts +0 -99
- package/src-ts/dist/realtime/subscriptions/index.ts +0 -19
- package/src-ts/dist/realtime/subscriptions/skywalker.subscription.ts +0 -13
- package/src-ts/dist/realtime/topic-map.ts +0 -71
- package/src-ts/dist/realtime/topic.ts +0 -80
- package/src-ts/dist/repositories/account.repository.ts +0 -1384
- package/src-ts/dist/repositories/bloks.repository.ts +0 -70
- package/src-ts/dist/repositories/captcha.repository.ts +0 -44
- package/src-ts/dist/repositories/challenge.repository.ts +0 -120
- package/src-ts/dist/repositories/clip.repository.ts +0 -165
- package/src-ts/dist/repositories/close-friends.repository.ts +0 -46
- package/src-ts/dist/repositories/collection.repository.ts +0 -68
- package/src-ts/dist/repositories/direct-thread.repository.ts +0 -446
- package/src-ts/dist/repositories/direct.repository.ts +0 -266
- package/src-ts/dist/repositories/explore.repository.ts +0 -70
- package/src-ts/dist/repositories/fbsearch.repository.ts +0 -140
- package/src-ts/dist/repositories/feed.repository.ts +0 -245
- package/src-ts/dist/repositories/friendship.repository.ts +0 -296
- package/src-ts/dist/repositories/fundraiser.repository.ts +0 -49
- package/src-ts/dist/repositories/hashtag.repository.ts +0 -99
- package/src-ts/dist/repositories/highlights.repository.ts +0 -121
- package/src-ts/dist/repositories/insights.repository.ts +0 -82
- package/src-ts/dist/repositories/location.repository.ts +0 -84
- package/src-ts/dist/repositories/media.repository.ts +0 -395
- package/src-ts/dist/repositories/multiple-accounts.repository.ts +0 -41
- package/src-ts/dist/repositories/news.repository.ts +0 -35
- package/src-ts/dist/repositories/note.repository.ts +0 -57
- package/src-ts/dist/repositories/notification.repository.ts +0 -79
- package/src-ts/dist/repositories/share.repository.ts +0 -35
- package/src-ts/dist/repositories/signup.repository.ts +0 -218
- package/src-ts/dist/repositories/story.repository.ts +0 -290
- package/src-ts/dist/repositories/timeline.repository.ts +0 -60
- package/src-ts/dist/repositories/totp.repository.ts +0 -139
- package/src-ts/dist/repositories/track.repository.ts +0 -53
- package/src-ts/dist/repositories/upload.repository.ts +0 -204
- package/src-ts/dist/repositories/user.repository.ts +0 -360
- package/src-ts/dist/sendmedia/index.ts +0 -27
- package/src-ts/dist/sendmedia/sendFile.ts +0 -72
- package/src-ts/dist/sendmedia/sendPhoto.ts +0 -142
- package/src-ts/dist/sendmedia/sendRavenPhoto.ts +0 -153
- package/src-ts/dist/sendmedia/sendRavenVideo.ts +0 -158
- package/src-ts/dist/sendmedia/uploadPhoto.ts +0 -107
- package/src-ts/dist/sendmedia/uploadfFile.ts +0 -130
- package/src-ts/dist/services/live.service.ts +0 -139
- package/src-ts/dist/services/search.service.ts +0 -115
- package/src-ts/dist/shared/shared.ts +0 -86
- package/src-ts/dist/thrift/index.ts +0 -20
- package/src-ts/dist/thrift/thrift.reading.ts +0 -368
- package/src-ts/dist/thrift/thrift.ts +0 -111
- package/src-ts/dist/thrift/thrift.writing.ts +0 -396
- package/src-ts/dist/types/index.ts +0 -285
- package/src-ts/dist/useMultiFileAuthState.ts +0 -1800
- package/src-ts/dist/utils/helper-1.ts +0 -1
- package/src-ts/dist/utils/helper-10.ts +0 -1
- package/src-ts/dist/utils/helper-11.ts +0 -1
- package/src-ts/dist/utils/helper-12.ts +0 -1
- package/src-ts/dist/utils/helper-13.ts +0 -1
- package/src-ts/dist/utils/helper-14.ts +0 -1
- package/src-ts/dist/utils/helper-15.ts +0 -1
- package/src-ts/dist/utils/helper-16.ts +0 -1
- package/src-ts/dist/utils/helper-17.ts +0 -1
- package/src-ts/dist/utils/helper-18.ts +0 -1
- package/src-ts/dist/utils/helper-19.ts +0 -1
- package/src-ts/dist/utils/helper-2.ts +0 -1
- package/src-ts/dist/utils/helper-20.ts +0 -1
- package/src-ts/dist/utils/helper-21.ts +0 -1
- package/src-ts/dist/utils/helper-22.ts +0 -1
- package/src-ts/dist/utils/helper-23.ts +0 -1
- package/src-ts/dist/utils/helper-24.ts +0 -1
- package/src-ts/dist/utils/helper-25.ts +0 -1
- package/src-ts/dist/utils/helper-26.ts +0 -1
- package/src-ts/dist/utils/helper-27.ts +0 -1
- package/src-ts/dist/utils/helper-28.ts +0 -1
- package/src-ts/dist/utils/helper-29.ts +0 -1
- package/src-ts/dist/utils/helper-3.ts +0 -1
- package/src-ts/dist/utils/helper-30.ts +0 -1
- package/src-ts/dist/utils/helper-4.ts +0 -1
- package/src-ts/dist/utils/helper-5.ts +0 -1
- package/src-ts/dist/utils/helper-6.ts +0 -1
- package/src-ts/dist/utils/helper-7.ts +0 -1
- package/src-ts/dist/utils/helper-8.ts +0 -1
- package/src-ts/dist/utils/helper-9.ts +0 -1
- package/src-ts/dist/utils/index.ts +0 -280
- package/src-ts/dist/utils/insta-mqtt-helper.ts +0 -128
- package/src-ts/examples/listen-to-messages.ts +0 -86
- /package/{dist-ts → dist}/dist/constants/constants.js +0 -0
- /package/{dist-ts → dist}/dist/constants/index.js +0 -0
- /package/{dist-ts → dist}/dist/core/client.js +0 -0
- /package/{dist-ts → dist}/dist/core/nav-chain.js +0 -0
- /package/{dist-ts → dist}/dist/core/repository.js +0 -0
- /package/{dist-ts → dist}/dist/core/request.js +0 -0
- /package/{dist-ts → dist}/dist/core/state.js +0 -0
- /package/{dist-ts → dist}/dist/core/utils.js +0 -0
- /package/{dist-ts → dist}/dist/errors/index.js +0 -0
- /package/{dist-ts → dist}/dist/extend.js +0 -0
- /package/{dist-ts → dist}/dist/fbns/fbns.client.events.js +0 -0
- /package/{dist-ts → dist}/dist/fbns/fbns.types.js +0 -0
- /package/{dist-ts → dist}/dist/fbns/fbns.utilities.js +0 -0
- /package/{dist-ts → dist}/dist/fbns/index.js +0 -0
- /package/{dist-ts → dist}/dist/index.js +0 -0
- /package/{dist-ts → dist}/dist/mqtt-shim.js +0 -0
- /package/{dist-ts → dist}/dist/mqttot/index.js +0 -0
- /package/{dist-ts → dist}/dist/mqttot/mqttot.connect.request.packet.js +0 -0
- /package/{dist-ts → dist}/dist/mqttot/mqttot.connect.response.packet.js +0 -0
- /package/{dist-ts → dist}/dist/mqttot/mqttot.connection.js +0 -0
- /package/{dist-ts → dist}/dist/realtime/commands/commands.js +0 -0
- /package/{dist-ts → dist}/dist/realtime/commands/direct.commands.js +0 -0
- /package/{dist-ts → dist}/dist/realtime/commands/index.js +0 -0
- /package/{dist-ts → dist}/dist/realtime/features/gap-handler.js +0 -0
- /package/{dist-ts → dist}/dist/realtime/index.js +0 -0
- /package/{dist-ts → dist}/dist/realtime/messages/app-presence.event.js +0 -0
- /package/{dist-ts → dist}/dist/realtime/messages/index.js +0 -0
- /package/{dist-ts → dist}/dist/realtime/messages/message-sync.message.js +0 -0
- /package/{dist-ts → dist}/dist/realtime/messages/realtime-sub.direct.data.js +0 -0
- /package/{dist-ts → dist}/dist/realtime/messages/thread-update.message.js +0 -0
- /package/{dist-ts → dist}/dist/realtime/mixins/index.js +0 -0
- /package/{dist-ts → dist}/dist/realtime/mixins/mixin.js +0 -0
- /package/{dist-ts → dist}/dist/realtime/mixins/presence-typing.mixin.js +0 -0
- /package/{dist-ts → dist}/dist/realtime/parsers/graphql-parser.js +0 -0
- /package/{dist-ts → dist}/dist/realtime/parsers/index.js +0 -0
- /package/{dist-ts → dist}/dist/realtime/parsers/iris-parser.js +0 -0
- /package/{dist-ts → dist}/dist/realtime/parsers/iris.parser.js +0 -0
- /package/{dist-ts → dist}/dist/realtime/parsers/json-parser.js +0 -0
- /package/{dist-ts → dist}/dist/realtime/parsers/json.parser.js +0 -0
- /package/{dist-ts → dist}/dist/realtime/parsers/parser.js +0 -0
- /package/{dist-ts → dist}/dist/realtime/parsers/region-hint-parser.js +0 -0
- /package/{dist-ts → dist}/dist/realtime/parsers/region-hint.parser.js +0 -0
- /package/{dist-ts → dist}/dist/realtime/parsers/skywalker-parser.js +0 -0
- /package/{dist-ts → dist}/dist/realtime/parsers/skywalker.parser.js +0 -0
- /package/{dist-ts → dist}/dist/realtime/protocols/iris.handshake.js +0 -0
- /package/{dist-ts → dist}/dist/realtime/protocols/proto-definitions.js +0 -0
- /package/{dist-ts → dist}/dist/realtime/realtime.client.events.js +0 -0
- /package/{dist-ts → dist}/dist/realtime/realtime.service.js +0 -0
- /package/{dist-ts → dist}/dist/realtime/reconnect.manager.js +0 -0
- /package/{dist-ts → dist}/dist/realtime/session.manager.js +0 -0
- /package/{dist-ts → dist}/dist/realtime/subscriptions/graphql.subscription.js +0 -0
- /package/{dist-ts → dist}/dist/realtime/subscriptions/index.js +0 -0
- /package/{dist-ts → dist}/dist/realtime/subscriptions/skywalker.subscription.js +0 -0
- /package/{dist-ts → dist}/dist/realtime/topic-map.js +0 -0
- /package/{dist-ts → dist}/dist/realtime/topic.js +0 -0
- /package/{dist-ts → dist}/dist/repositories/bloks.repository.js +0 -0
- /package/{dist-ts → dist}/dist/repositories/captcha.repository.js +0 -0
- /package/{dist-ts → dist}/dist/repositories/clip.repository.js +0 -0
- /package/{dist-ts → dist}/dist/repositories/close-friends.repository.js +0 -0
- /package/{dist-ts → dist}/dist/repositories/collection.repository.js +0 -0
- /package/{dist-ts → dist}/dist/repositories/explore.repository.js +0 -0
- /package/{dist-ts → dist}/dist/repositories/fbsearch.repository.js +0 -0
- /package/{dist-ts → dist}/dist/repositories/feed.repository.js +0 -0
- /package/{dist-ts → dist}/dist/repositories/friendship.repository.js +0 -0
- /package/{dist-ts → dist}/dist/repositories/fundraiser.repository.js +0 -0
- /package/{dist-ts → dist}/dist/repositories/hashtag.repository.js +0 -0
- /package/{dist-ts → dist}/dist/repositories/highlights.repository.js +0 -0
- /package/{dist-ts → dist}/dist/repositories/insights.repository.js +0 -0
- /package/{dist-ts → dist}/dist/repositories/location.repository.js +0 -0
- /package/{dist-ts → dist}/dist/repositories/multiple-accounts.repository.js +0 -0
- /package/{dist-ts → dist}/dist/repositories/news.repository.js +0 -0
- /package/{dist-ts → dist}/dist/repositories/note.repository.js +0 -0
- /package/{dist-ts → dist}/dist/repositories/share.repository.js +0 -0
- /package/{dist-ts → dist}/dist/repositories/signup.repository.js +0 -0
- /package/{dist-ts → dist}/dist/repositories/timeline.repository.js +0 -0
- /package/{dist-ts → dist}/dist/repositories/totp.repository.js +0 -0
- /package/{dist-ts → dist}/dist/repositories/user.repository.js +0 -0
- /package/{dist-ts → dist}/dist/sendmedia/index.js +0 -0
- /package/{dist-ts → dist}/dist/sendmedia/sendFile.js +0 -0
- /package/{dist-ts → dist}/dist/sendmedia/sendPhoto.js +0 -0
- /package/{dist-ts → dist}/dist/sendmedia/uploadPhoto.js +0 -0
- /package/{dist-ts → dist}/dist/services/live.service.js +0 -0
- /package/{dist-ts → dist}/dist/services/search.service.js +0 -0
- /package/{dist-ts → dist}/dist/shared/shared.js +0 -0
- /package/{dist-ts → dist}/dist/thrift/index.js +0 -0
- /package/{dist-ts → dist}/dist/thrift/thrift.js +0 -0
- /package/{dist-ts → dist}/dist/types/index.js +0 -0
- /package/{dist-ts → dist}/dist/utils/helper-1.js +0 -0
- /package/{dist-ts → dist}/dist/utils/helper-10.js +0 -0
- /package/{dist-ts → dist}/dist/utils/helper-11.js +0 -0
- /package/{dist-ts → dist}/dist/utils/helper-12.js +0 -0
- /package/{dist-ts → dist}/dist/utils/helper-13.js +0 -0
- /package/{dist-ts → dist}/dist/utils/helper-14.js +0 -0
- /package/{dist-ts → dist}/dist/utils/helper-15.js +0 -0
- /package/{dist-ts → dist}/dist/utils/helper-16.js +0 -0
- /package/{dist-ts → dist}/dist/utils/helper-17.js +0 -0
- /package/{dist-ts → dist}/dist/utils/helper-18.js +0 -0
- /package/{dist-ts → dist}/dist/utils/helper-19.js +0 -0
- /package/{dist-ts → dist}/dist/utils/helper-2.js +0 -0
- /package/{dist-ts → dist}/dist/utils/helper-20.js +0 -0
- /package/{dist-ts → dist}/dist/utils/helper-21.js +0 -0
- /package/{dist-ts → dist}/dist/utils/helper-22.js +0 -0
- /package/{dist-ts → dist}/dist/utils/helper-23.js +0 -0
- /package/{dist-ts → dist}/dist/utils/helper-24.js +0 -0
- /package/{dist-ts → dist}/dist/utils/helper-25.js +0 -0
- /package/{dist-ts → dist}/dist/utils/helper-26.js +0 -0
- /package/{dist-ts → dist}/dist/utils/helper-27.js +0 -0
- /package/{dist-ts → dist}/dist/utils/helper-28.js +0 -0
- /package/{dist-ts → dist}/dist/utils/helper-29.js +0 -0
- /package/{dist-ts → dist}/dist/utils/helper-3.js +0 -0
- /package/{dist-ts → dist}/dist/utils/helper-30.js +0 -0
- /package/{dist-ts → dist}/dist/utils/helper-4.js +0 -0
- /package/{dist-ts → dist}/dist/utils/helper-5.js +0 -0
- /package/{dist-ts → dist}/dist/utils/helper-6.js +0 -0
- /package/{dist-ts → dist}/dist/utils/helper-7.js +0 -0
- /package/{dist-ts → dist}/dist/utils/helper-8.js +0 -0
- /package/{dist-ts → dist}/dist/utils/helper-9.js +0 -0
- /package/{dist-ts → dist}/dist/utils/insta-mqtt-helper.js +0 -0
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
const Repository = require('../core/repository');
|
|
2
2
|
const crypto = require('crypto');
|
|
3
|
+
|
|
3
4
|
class AccountRepository extends Repository {
|
|
4
5
|
constructor(client) {
|
|
5
6
|
super(client);
|
|
6
7
|
this.maxRetries = 3;
|
|
7
8
|
}
|
|
9
|
+
|
|
8
10
|
async requestWithRetry(requestFn, retries = 0) {
|
|
9
|
-
var _a, _b;
|
|
10
11
|
try {
|
|
11
12
|
const result = await requestFn();
|
|
12
13
|
return result;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
} catch (error) {
|
|
15
|
+
const shouldRetry =
|
|
16
|
+
(error.data?.error_type === 'server_error' ||
|
|
17
|
+
error.data?.error_type === 'rate_limited') &&
|
|
17
18
|
retries < this.maxRetries;
|
|
18
19
|
if (shouldRetry) {
|
|
19
20
|
const delay = 1000 * (retries + 1);
|
|
@@ -23,6 +24,7 @@ class AccountRepository extends Repository {
|
|
|
23
24
|
throw error;
|
|
24
25
|
}
|
|
25
26
|
}
|
|
27
|
+
|
|
26
28
|
/**
|
|
27
29
|
* Helper: try to extract an IGT bearer token from various sources:
|
|
28
30
|
* - response.headers (IG-Set-Authorization or ig-set-authorization)
|
|
@@ -33,9 +35,8 @@ class AccountRepository extends Repository {
|
|
|
33
35
|
* When found, sets this.client.state.authorization and calls updateAuthorization().
|
|
34
36
|
*/
|
|
35
37
|
_extractAndSaveAuthorization(response) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return null;
|
|
38
|
+
if (!response) return null;
|
|
39
|
+
|
|
39
40
|
// Normalize headers (case-insensitive)
|
|
40
41
|
const headers = {};
|
|
41
42
|
if (response.headers && typeof response.headers === 'object') {
|
|
@@ -43,19 +44,19 @@ class AccountRepository extends Repository {
|
|
|
43
44
|
headers[k.toLowerCase()] = response.headers[k];
|
|
44
45
|
}
|
|
45
46
|
}
|
|
47
|
+
|
|
46
48
|
// Simpler: look for any header that contains ig-set-authorization
|
|
47
49
|
for (const key of Object.keys(headers)) {
|
|
48
50
|
const val = headers[key];
|
|
49
|
-
if (!val)
|
|
50
|
-
|
|
51
|
+
if (!val) continue;
|
|
52
|
+
|
|
51
53
|
if (key.includes('ig-set-authorization')) {
|
|
52
54
|
const token = this._normalizeTokenString(val);
|
|
53
55
|
if (token) {
|
|
54
56
|
this.client.state.authorization = token;
|
|
55
57
|
try {
|
|
56
58
|
this.client.state.updateAuthorization();
|
|
57
|
-
}
|
|
58
|
-
catch (e) { }
|
|
59
|
+
} catch (e) {}
|
|
59
60
|
return token;
|
|
60
61
|
}
|
|
61
62
|
}
|
|
@@ -66,14 +67,15 @@ class AccountRepository extends Repository {
|
|
|
66
67
|
this.client.state.authorization = token;
|
|
67
68
|
try {
|
|
68
69
|
this.client.state.updateAuthorization();
|
|
69
|
-
}
|
|
70
|
-
catch (e) { }
|
|
70
|
+
} catch (e) {}
|
|
71
71
|
return token;
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
|
+
|
|
75
76
|
// Extract IG-U headers (user id, region, claim) when present
|
|
76
|
-
const dsUserIdHeader =
|
|
77
|
+
const dsUserIdHeader =
|
|
78
|
+
headers['ig-set-ig-u-ds-user-id'] ||
|
|
77
79
|
headers['ig-u-ds-user-id'] ||
|
|
78
80
|
headers['x-ig-set-ig-u-ds-user-id'];
|
|
79
81
|
if (dsUserIdHeader) {
|
|
@@ -84,7 +86,9 @@ class AccountRepository extends Repository {
|
|
|
84
86
|
this.client.state._userId = uid;
|
|
85
87
|
}
|
|
86
88
|
}
|
|
87
|
-
|
|
89
|
+
|
|
90
|
+
const rurHeader =
|
|
91
|
+
headers['ig-set-ig-u-rur'] ||
|
|
88
92
|
headers['ig-u-rur'] ||
|
|
89
93
|
headers['x-ig-set-ig-u-rur'];
|
|
90
94
|
if (rurHeader) {
|
|
@@ -93,7 +97,9 @@ class AccountRepository extends Repository {
|
|
|
93
97
|
this.client.state.igURur = rur;
|
|
94
98
|
}
|
|
95
99
|
}
|
|
96
|
-
|
|
100
|
+
|
|
101
|
+
const wwwClaimHeader =
|
|
102
|
+
headers['x-ig-set-www-claim'] ||
|
|
97
103
|
headers['ig-set-www-claim'] ||
|
|
98
104
|
headers['ig-u-www-claim'];
|
|
99
105
|
if (wwwClaimHeader) {
|
|
@@ -102,7 +108,9 @@ class AccountRepository extends Repository {
|
|
|
102
108
|
this.client.state.igWWWClaim = claim;
|
|
103
109
|
}
|
|
104
110
|
}
|
|
105
|
-
|
|
111
|
+
|
|
112
|
+
const midHeader =
|
|
113
|
+
headers['ig-set-x-mid'] ||
|
|
106
114
|
headers['x-mid'] ||
|
|
107
115
|
headers['ig-set-mid'];
|
|
108
116
|
if (midHeader) {
|
|
@@ -111,6 +119,7 @@ class AccountRepository extends Repository {
|
|
|
111
119
|
this.client.state.mid = mid;
|
|
112
120
|
}
|
|
113
121
|
}
|
|
122
|
+
|
|
114
123
|
// 2) Check response.body for common fields
|
|
115
124
|
const body = response.body;
|
|
116
125
|
if (body) {
|
|
@@ -121,21 +130,22 @@ class AccountRepository extends Repository {
|
|
|
121
130
|
this.client.state.authorization = token;
|
|
122
131
|
try {
|
|
123
132
|
this.client.state.updateAuthorization();
|
|
124
|
-
}
|
|
125
|
-
catch (e) { }
|
|
133
|
+
} catch (e) {}
|
|
126
134
|
return token;
|
|
127
135
|
}
|
|
128
136
|
}
|
|
137
|
+
|
|
129
138
|
// If body contains a layout object or string, stringify and search it
|
|
130
139
|
try {
|
|
131
140
|
let layoutStr = null;
|
|
132
141
|
if (body.layout) {
|
|
133
|
-
layoutStr =
|
|
134
|
-
|
|
135
|
-
|
|
142
|
+
layoutStr =
|
|
143
|
+
typeof body.layout === 'string'
|
|
144
|
+
? body.layout
|
|
145
|
+
: JSON.stringify(body.layout);
|
|
146
|
+
} else if (body?.layout?.bloks_payload) {
|
|
136
147
|
layoutStr = JSON.stringify(body.layout.bloks_payload);
|
|
137
|
-
}
|
|
138
|
-
else if (body === null || body === void 0 ? void 0 : body.bloks_payload) {
|
|
148
|
+
} else if (body?.bloks_payload) {
|
|
139
149
|
layoutStr = JSON.stringify(body.bloks_payload);
|
|
140
150
|
}
|
|
141
151
|
if (!layoutStr && typeof body === 'string') {
|
|
@@ -147,49 +157,72 @@ class AccountRepository extends Repository {
|
|
|
147
157
|
this.client.state.authorization = token;
|
|
148
158
|
try {
|
|
149
159
|
this.client.state.updateAuthorization();
|
|
150
|
-
}
|
|
151
|
-
catch (e) { }
|
|
160
|
+
} catch (e) {}
|
|
152
161
|
return token;
|
|
153
162
|
}
|
|
163
|
+
|
|
154
164
|
// Some responses embed a login_response JSON string inside layout; try to extract it
|
|
155
|
-
const loginResponseMatch = layoutStr.match(
|
|
165
|
+
const loginResponseMatch = layoutStr.match(
|
|
166
|
+
/"login_response"\s*:\s*"(\\?{.*?\\?})"/s
|
|
167
|
+
);
|
|
156
168
|
if (loginResponseMatch) {
|
|
157
169
|
// Unescape JSON string
|
|
158
170
|
let jsonStr = loginResponseMatch[1];
|
|
159
171
|
try {
|
|
160
|
-
jsonStr = jsonStr
|
|
172
|
+
jsonStr = jsonStr
|
|
173
|
+
.replace(/\\"/g, '"')
|
|
174
|
+
.replace(/\\n/g, '');
|
|
161
175
|
const parsed = JSON.parse(jsonStr);
|
|
162
176
|
if (parsed && parsed.headers) {
|
|
163
|
-
const token = this._findBearerInString(
|
|
177
|
+
const token = this._findBearerInString(
|
|
178
|
+
parsed.headers
|
|
179
|
+
);
|
|
164
180
|
if (token) {
|
|
165
181
|
this.client.state.authorization = token;
|
|
166
182
|
try {
|
|
167
183
|
this.client.state.updateAuthorization();
|
|
168
|
-
}
|
|
169
|
-
catch (e) { }
|
|
184
|
+
} catch (e) {}
|
|
170
185
|
return token;
|
|
171
186
|
}
|
|
172
187
|
}
|
|
173
|
-
}
|
|
174
|
-
catch (e) {
|
|
188
|
+
} catch (e) {
|
|
175
189
|
// ignore parse errors
|
|
176
190
|
}
|
|
177
191
|
}
|
|
192
|
+
|
|
178
193
|
// Also try to find IG-Set-Password-Encryption headers (not token but useful)
|
|
179
|
-
const encKeyIdMatch =
|
|
180
|
-
layoutStr.match(
|
|
194
|
+
const encKeyIdMatch =
|
|
195
|
+
layoutStr.match(
|
|
196
|
+
/IG-Set-Password-Encryption-Key-Id[\\"\s:]+(\d+)/i
|
|
197
|
+
) ||
|
|
198
|
+
layoutStr.match(
|
|
199
|
+
/password.encryption.key.id[\\"\s:]+(\d+)/i
|
|
200
|
+
);
|
|
181
201
|
if (encKeyIdMatch) {
|
|
182
|
-
this.client.state.passwordEncryptionKeyId =
|
|
202
|
+
this.client.state.passwordEncryptionKeyId =
|
|
203
|
+
parseInt(encKeyIdMatch[1]);
|
|
183
204
|
}
|
|
184
|
-
const encPubKeyMatch =
|
|
185
|
-
layoutStr.match(
|
|
205
|
+
const encPubKeyMatch =
|
|
206
|
+
layoutStr.match(
|
|
207
|
+
/IG-Set-Password-Encryption-Pub-Key[\\"\s:]+([A-Za-z0-9+\/=]+)/i
|
|
208
|
+
) ||
|
|
209
|
+
layoutStr.match(
|
|
210
|
+
/password.encryption.pub.key[\\"\s:]+([A-Za-z0-9+\/=]+)/i
|
|
211
|
+
);
|
|
186
212
|
if (encPubKeyMatch) {
|
|
187
|
-
this.client.state.passwordEncryptionPubKey =
|
|
213
|
+
this.client.state.passwordEncryptionPubKey =
|
|
214
|
+
encPubKeyMatch[1];
|
|
188
215
|
}
|
|
216
|
+
|
|
189
217
|
// Extract user/account identifiers from layout string
|
|
190
|
-
const dsIdMatch =
|
|
218
|
+
const dsIdMatch =
|
|
219
|
+
layoutStr.match(
|
|
220
|
+
/ig-set-ig-u-ds-user-id[\\"\s:]+(\d+)/i
|
|
221
|
+
) ||
|
|
191
222
|
layoutStr.match(/ig-u-ds-user-id[\\"\s:]+(\d+)/i) ||
|
|
192
|
-
layoutStr.match(
|
|
223
|
+
layoutStr.match(
|
|
224
|
+
/"strong_id__"\s*:\s*"(\d+)"/i
|
|
225
|
+
) ||
|
|
193
226
|
layoutStr.match(/"pk_id"\s*:\s*"(\d+)"/i) ||
|
|
194
227
|
layoutStr.match(/"pk"\s*:\s*(\d+)/i);
|
|
195
228
|
if (dsIdMatch) {
|
|
@@ -197,56 +230,71 @@ class AccountRepository extends Repository {
|
|
|
197
230
|
this.client.state.cookieUserId = uid;
|
|
198
231
|
this.client.state._userId = uid;
|
|
199
232
|
}
|
|
200
|
-
|
|
233
|
+
|
|
234
|
+
const rurMatch =
|
|
235
|
+
layoutStr.match(
|
|
236
|
+
/ig-set-ig-u-rur[\\"\s:]+"([^"\\]+)/i
|
|
237
|
+
) ||
|
|
201
238
|
layoutStr.match(/ig-u-rur[\\"\s:]+"([^"\\]+)/i);
|
|
202
239
|
if (rurMatch) {
|
|
203
240
|
this.client.state.igURur = rurMatch[1];
|
|
204
241
|
}
|
|
205
|
-
|
|
242
|
+
|
|
243
|
+
const wwwClaimMatch = layoutStr.match(
|
|
244
|
+
/x-ig-set-www-claim[\\"\s:]+"([^"\\]+)/i
|
|
245
|
+
);
|
|
206
246
|
if (wwwClaimMatch) {
|
|
207
247
|
this.client.state.igWWWClaim = wwwClaimMatch[1];
|
|
208
248
|
}
|
|
209
|
-
|
|
249
|
+
|
|
250
|
+
const midMatch = layoutStr.match(
|
|
251
|
+
/"mid"\s*:\s*"([^"\\]+)"/i
|
|
252
|
+
);
|
|
210
253
|
if (midMatch) {
|
|
211
254
|
this.client.state.mid = midMatch[1];
|
|
212
255
|
}
|
|
213
256
|
}
|
|
214
|
-
}
|
|
215
|
-
catch (e) {
|
|
257
|
+
} catch (e) {
|
|
216
258
|
// ignore
|
|
217
259
|
}
|
|
260
|
+
|
|
218
261
|
// 3) If body.logged_in_user exists and we have authorization already, return it
|
|
219
262
|
if (body.logged_in_user && this.client.state.authorization) {
|
|
220
263
|
return this.client.state.authorization;
|
|
221
264
|
}
|
|
222
265
|
}
|
|
266
|
+
|
|
223
267
|
return null;
|
|
224
268
|
}
|
|
269
|
+
|
|
225
270
|
// Normalize token string: accept either raw token or "Bearer IGT:2:..." and return trimmed token string
|
|
226
271
|
_normalizeTokenString(val) {
|
|
227
|
-
if (!val || typeof val !== 'string')
|
|
228
|
-
|
|
272
|
+
if (!val || typeof val !== 'string') return null;
|
|
273
|
+
|
|
229
274
|
// If header already contains "Bearer IGT:2:..."
|
|
230
275
|
const bearer = this._findBearerInString(val);
|
|
231
|
-
if (bearer)
|
|
232
|
-
|
|
276
|
+
if (bearer) return bearer;
|
|
277
|
+
|
|
233
278
|
// If header contains JSON with IG-Set-Authorization field
|
|
234
279
|
try {
|
|
235
280
|
const maybeJson = JSON.parse(val);
|
|
236
281
|
if (maybeJson['IG-Set-Authorization']) {
|
|
237
|
-
return this._findBearerInString(
|
|
282
|
+
return this._findBearerInString(
|
|
283
|
+
maybeJson['IG-Set-Authorization']
|
|
284
|
+
);
|
|
238
285
|
}
|
|
239
|
-
}
|
|
240
|
-
catch (e) {
|
|
286
|
+
} catch (e) {
|
|
241
287
|
// not JSON
|
|
242
288
|
}
|
|
289
|
+
|
|
243
290
|
// fallback: return trimmed value
|
|
244
291
|
return val.trim();
|
|
245
292
|
}
|
|
293
|
+
|
|
246
294
|
// Find bearer token in arbitrary string using multiple patterns
|
|
247
295
|
_findBearerInString(str) {
|
|
248
|
-
if (!str || typeof str !== 'string')
|
|
249
|
-
|
|
296
|
+
if (!str || typeof str !== 'string') return null;
|
|
297
|
+
|
|
250
298
|
// Patterns to match the Bearer token in many possible encodings/escapes
|
|
251
299
|
const bearerPatterns = [
|
|
252
300
|
/Bearer IGT:2:[A-Za-z0-9+\/=]+/,
|
|
@@ -257,98 +305,372 @@ class AccountRepository extends Repository {
|
|
|
257
305
|
/IG-Set-Authorization[\s:]+(Bearer IGT:2:[A-Za-z0-9+\/=]+)/i,
|
|
258
306
|
/Bearer IGT:2:([A-Za-z0-9+\/=]+)/,
|
|
259
307
|
];
|
|
308
|
+
|
|
260
309
|
for (const pattern of bearerPatterns) {
|
|
261
310
|
const m = str.match(pattern);
|
|
262
311
|
if (m) {
|
|
263
312
|
// If capturing group present, prefer it
|
|
264
313
|
if (m[1]) {
|
|
265
|
-
const token = m[1].includes('Bearer IGT:2:')
|
|
314
|
+
const token = m[1].includes('Bearer IGT:2:')
|
|
315
|
+
? m[1]
|
|
316
|
+
: `Bearer IGT:2:${m[1]}`;
|
|
266
317
|
return token.replace(/\?"/g, '').trim();
|
|
267
318
|
}
|
|
268
319
|
// Otherwise m[0] contains the full token
|
|
269
320
|
return m[0].replace(/\?"/g, '').trim();
|
|
270
321
|
}
|
|
271
322
|
}
|
|
323
|
+
|
|
272
324
|
return null;
|
|
273
325
|
}
|
|
326
|
+
|
|
274
327
|
// Ensure we have a valid csrftoken cookie (and mid) before sensitive endpoints.
|
|
275
328
|
// Instagram typically sets csrftoken via /api/v1/si/fetch_headers/.
|
|
276
329
|
async ensureCsrfToken() {
|
|
277
330
|
const cookieToken = this.client.state.cookieCsrfToken;
|
|
278
|
-
if (
|
|
331
|
+
if (
|
|
332
|
+
cookieToken &&
|
|
333
|
+
cookieToken !== 'missing' &&
|
|
334
|
+
cookieToken !== 'pending'
|
|
335
|
+
) {
|
|
279
336
|
try {
|
|
280
337
|
this.client.state.csrfToken = cookieToken;
|
|
281
|
-
}
|
|
282
|
-
catch { }
|
|
338
|
+
} catch {}
|
|
283
339
|
return cookieToken;
|
|
284
340
|
}
|
|
341
|
+
|
|
285
342
|
// Warmup endpoint that returns/set cookies (csrftoken, mid, etc.)
|
|
286
343
|
try {
|
|
287
344
|
await this.client.request.send({
|
|
288
345
|
method: 'GET',
|
|
289
346
|
url: `/api/v1/si/fetch_headers/?challenge_type=signup&guid=${this.client.state.uuid}`,
|
|
290
347
|
});
|
|
291
|
-
}
|
|
292
|
-
catch (e) {
|
|
348
|
+
} catch (e) {
|
|
293
349
|
// ignore warmup failures
|
|
294
350
|
}
|
|
351
|
+
|
|
295
352
|
const token = this.client.state.cookieCsrfToken;
|
|
296
|
-
if (
|
|
353
|
+
if (
|
|
354
|
+
token &&
|
|
355
|
+
token !== 'missing' &&
|
|
356
|
+
token !== 'pending'
|
|
357
|
+
) {
|
|
297
358
|
try {
|
|
298
359
|
this.client.state.csrfToken = token;
|
|
299
|
-
}
|
|
300
|
-
catch { }
|
|
360
|
+
} catch {}
|
|
301
361
|
return token;
|
|
302
362
|
}
|
|
363
|
+
|
|
303
364
|
return null;
|
|
304
365
|
}
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* Internal: perform the Bloks OAuth token fetch step that the official app does
|
|
369
|
+
* just before password login (com.bloks.www.caa.login.oauth.token.fetch.async).
|
|
370
|
+
* This is best-effort only and never throws to the caller.
|
|
371
|
+
*/
|
|
372
|
+
async _prefetchOauthTokenForLogin(username) {
|
|
373
|
+
if (!username) return null;
|
|
374
|
+
|
|
375
|
+
try {
|
|
376
|
+
const nowSec = Math.floor(Date.now() / 1000);
|
|
377
|
+
|
|
378
|
+
// Device identifiers – keep them consistent with the main login flow
|
|
379
|
+
const androidDeviceId =
|
|
380
|
+
this.client.state.androidDeviceId ||
|
|
381
|
+
this.client.state.deviceId ||
|
|
382
|
+
`android-${crypto.randomBytes(8).toString('hex')}`;
|
|
383
|
+
|
|
384
|
+
const familyDeviceId =
|
|
385
|
+
this.client.state.phoneId ||
|
|
386
|
+
this.client.state.familyDeviceId ||
|
|
387
|
+
(crypto.randomUUID
|
|
388
|
+
? crypto.randomUUID()
|
|
389
|
+
: require('uuid').v4());
|
|
390
|
+
|
|
391
|
+
const qeDeviceId =
|
|
392
|
+
this.client.state.deviceId ||
|
|
393
|
+
this.client.state.qeDeviceId ||
|
|
394
|
+
(crypto.randomUUID
|
|
395
|
+
? crypto.randomUUID()
|
|
396
|
+
: require('uuid').v4());
|
|
397
|
+
|
|
398
|
+
const waterfallId = crypto.randomUUID
|
|
399
|
+
? crypto.randomUUID()
|
|
400
|
+
: require('uuid').v4();
|
|
401
|
+
|
|
402
|
+
const latencyMarkerId = 36707139;
|
|
403
|
+
const latencyInstanceId = Number(
|
|
404
|
+
`${Date.now()}${Math.floor(Math.random() * 1000)}`
|
|
405
|
+
);
|
|
406
|
+
|
|
407
|
+
// AAC object as seen in real traffic: timestamp + UUID + random token
|
|
408
|
+
const aacInitTimestamp =
|
|
409
|
+
nowSec - Math.floor(Math.random() * 50);
|
|
410
|
+
const aacjid = crypto.randomUUID
|
|
411
|
+
? crypto.randomUUID()
|
|
412
|
+
: require('uuid').v4();
|
|
413
|
+
const aaccs = crypto
|
|
414
|
+
.randomBytes(32)
|
|
415
|
+
.toString('base64')
|
|
416
|
+
.replace(/=/g, '');
|
|
417
|
+
|
|
418
|
+
const clientInputParams = {
|
|
419
|
+
username_input: username,
|
|
420
|
+
aac: JSON.stringify({
|
|
421
|
+
aac_init_timestamp: aacInitTimestamp,
|
|
422
|
+
aacjid,
|
|
423
|
+
aaccs,
|
|
424
|
+
}),
|
|
425
|
+
lois_settings: { lois_token: '' },
|
|
426
|
+
cloud_trust_token: null,
|
|
427
|
+
zero_balance_state: '',
|
|
428
|
+
network_bssid: null,
|
|
429
|
+
};
|
|
430
|
+
|
|
431
|
+
const serverParams = {
|
|
432
|
+
is_from_logged_out: 0,
|
|
433
|
+
layered_homepage_experiment_group: null,
|
|
434
|
+
device_id: androidDeviceId,
|
|
435
|
+
login_surface: 'switcher',
|
|
436
|
+
waterfall_id: waterfallId,
|
|
437
|
+
INTERNAL__latency_qpl_instance_id: latencyInstanceId,
|
|
438
|
+
is_platform_login: 0,
|
|
439
|
+
INTERNAL__latency_qpl_marker_id: latencyMarkerId,
|
|
440
|
+
family_device_id: familyDeviceId,
|
|
441
|
+
offline_experiment_group: 'caa_iteration_v3_perf_ig_4',
|
|
442
|
+
access_flow_version: 'pre_mt_behavior',
|
|
443
|
+
is_from_logged_in_switcher: 1,
|
|
444
|
+
qe_device_id: qeDeviceId,
|
|
445
|
+
};
|
|
446
|
+
|
|
447
|
+
const paramsJson = JSON.stringify({
|
|
448
|
+
client_input_params: clientInputParams,
|
|
449
|
+
server_params: serverParams,
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
const bloksVersionId =
|
|
453
|
+
this.client.state.bloksVersionId ||
|
|
454
|
+
'5e47baf35c5a270b44c8906c8b99063564b30ef69779f3dee0b828bee2e4ef5b';
|
|
455
|
+
|
|
456
|
+
const bkClientContext = JSON.stringify({
|
|
457
|
+
bloks_version: bloksVersionId,
|
|
458
|
+
styles_id: 'instagram',
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
const lang = this.client.state.language || 'ro_RO';
|
|
462
|
+
const acceptLanguage = `${lang.replace('_', '-')}, en-US`;
|
|
463
|
+
const userAgent =
|
|
464
|
+
this.client.state.userAgent ||
|
|
465
|
+
'Instagram 371.0.0.0.23 Android (30/11; 320dpi; 720x1449; Xiaomi/Redmi; M2006C3MNG; angelican; mt6765; ro_RO; 703217507)';
|
|
466
|
+
|
|
467
|
+
const timezoneOffset =
|
|
468
|
+
typeof this.client.state.timezoneOffset === 'number'
|
|
469
|
+
? this.client.state.timezoneOffset
|
|
470
|
+
: 7200;
|
|
471
|
+
|
|
472
|
+
const bloksHeaders = {
|
|
473
|
+
'accept-language': acceptLanguage,
|
|
474
|
+
'content-type':
|
|
475
|
+
'application/x-www-form-urlencoded; charset=UTF-8',
|
|
476
|
+
'ig-intended-user-id': '0',
|
|
477
|
+
// Critical: matches the captured request header
|
|
478
|
+
priority: 'u=3',
|
|
479
|
+
|
|
480
|
+
'x-bloks-is-layout-rtl': 'false',
|
|
481
|
+
'x-bloks-prism-ax-base-colors-enabled': 'false',
|
|
482
|
+
'x-bloks-prism-button-version': 'CONTROL',
|
|
483
|
+
'x-bloks-prism-colors-enabled': 'true',
|
|
484
|
+
'x-bloks-prism-font-enabled': 'false',
|
|
485
|
+
'x-bloks-prism-indigo-link-version': '0',
|
|
486
|
+
'x-bloks-version-id': bloksVersionId,
|
|
487
|
+
|
|
488
|
+
'x-ig-android-id': androidDeviceId,
|
|
489
|
+
'x-ig-device-id': qeDeviceId,
|
|
490
|
+
'x-ig-family-device-id': familyDeviceId,
|
|
491
|
+
'x-ig-timezone-offset': String(timezoneOffset),
|
|
492
|
+
'x-ig-app-id': String(
|
|
493
|
+
this.client.state.fbAnalyticsApplicationId ||
|
|
494
|
+
'567067343352427'
|
|
495
|
+
),
|
|
496
|
+
'x-ig-app-locale': lang,
|
|
497
|
+
'x-ig-device-locale': lang,
|
|
498
|
+
'x-ig-mapped-locale': lang,
|
|
499
|
+
|
|
500
|
+
'x-ig-client-endpoint':
|
|
501
|
+
'com.bloks.www.caa.login.login_homepage',
|
|
502
|
+
'x-ig-nav-chain':
|
|
503
|
+
'com.bloks.www.caa.login.login_homepage:com.bloks.www.caa.login.login_homepage:1:button:0:::0',
|
|
504
|
+
|
|
505
|
+
'x-ig-connection-type': 'WIFI',
|
|
506
|
+
'x-ig-capabilities': '3brTv10=',
|
|
507
|
+
'x-ig-www-claim': this.client.state.igWWWClaim || '0',
|
|
508
|
+
|
|
509
|
+
'x-pigeon-rawclienttime': `${nowSec}.${Math.floor(
|
|
510
|
+
Math.random() * 1000
|
|
511
|
+
)
|
|
512
|
+
.toString()
|
|
513
|
+
.padStart(3, '0')}`,
|
|
514
|
+
'x-pigeon-session-id':
|
|
515
|
+
this.client.state.pigeonSessionId ||
|
|
516
|
+
`UFS-${crypto.randomBytes(16).toString('hex')}-2`,
|
|
517
|
+
|
|
518
|
+
'x-mid':
|
|
519
|
+
this.client.state.mid ||
|
|
520
|
+
`aZ${crypto.randomBytes(8).toString('hex')}`,
|
|
521
|
+
'x-tigon-is-retry': 'False',
|
|
522
|
+
|
|
523
|
+
'x-fb-client-ip': 'True',
|
|
524
|
+
'x-fb-connection-type': 'WIFI',
|
|
525
|
+
'x-fb-server-cluster': 'True',
|
|
526
|
+
'x-fb-network-properties':
|
|
527
|
+
'VPN;Validated;LocalAddrs=/10.0.0.2,;',
|
|
528
|
+
'x-fb-request-analytics-tags': JSON.stringify({
|
|
529
|
+
network_tags: {
|
|
530
|
+
product: String(
|
|
531
|
+
this.client.state.fbAnalyticsApplicationId ||
|
|
532
|
+
'567067343352427'
|
|
533
|
+
),
|
|
534
|
+
purpose: 'fetch',
|
|
535
|
+
surface: 'undefined',
|
|
536
|
+
request_category: 'api',
|
|
537
|
+
retry_attempt: '0',
|
|
538
|
+
},
|
|
539
|
+
}),
|
|
540
|
+
'x-fb-friendly-name':
|
|
541
|
+
'IgApi: bloks/async_action/com.bloks.www.caa.login.oauth.token.fetch.async/',
|
|
542
|
+
'x-fb-http-engine': 'MNS/TCP',
|
|
543
|
+
'x-fb-rmd': 'state=URL_ELIGIBLE',
|
|
544
|
+
|
|
545
|
+
'user-agent': userAgent,
|
|
546
|
+
};
|
|
547
|
+
|
|
548
|
+
const response = await this.client.request.send({
|
|
549
|
+
method: 'POST',
|
|
550
|
+
url: '/api/v1/bloks/async_action/com.bloks.www.caa.login.oauth.token.fetch.async/',
|
|
551
|
+
form: {
|
|
552
|
+
params: paramsJson,
|
|
553
|
+
bk_client_context: bkClientContext,
|
|
554
|
+
bloks_versioning_id: bloksVersionId,
|
|
555
|
+
},
|
|
556
|
+
headers: bloksHeaders,
|
|
557
|
+
});
|
|
558
|
+
|
|
559
|
+
// Optional debug dump so you can inspect the exact server response.
|
|
560
|
+
try {
|
|
561
|
+
const fs = require('fs');
|
|
562
|
+
const path = require('path');
|
|
563
|
+
const debugDir = path.join(
|
|
564
|
+
process.cwd(),
|
|
565
|
+
'authinfo_instagram'
|
|
566
|
+
);
|
|
567
|
+
const debugFile = path.join(
|
|
568
|
+
debugDir,
|
|
569
|
+
'oauth-token-debug.json'
|
|
570
|
+
);
|
|
571
|
+
try {
|
|
572
|
+
fs.mkdirSync(debugDir, { recursive: true });
|
|
573
|
+
} catch (e) {}
|
|
574
|
+
|
|
575
|
+
const debugPayload = {
|
|
576
|
+
at: new Date().toISOString(),
|
|
577
|
+
statusCode:
|
|
578
|
+
response.statusCode || response.status || null,
|
|
579
|
+
headers: response.headers || null,
|
|
580
|
+
body: response.body || null,
|
|
581
|
+
};
|
|
582
|
+
fs.writeFileSync(
|
|
583
|
+
debugFile,
|
|
584
|
+
JSON.stringify(debugPayload, null, 2),
|
|
585
|
+
'utf8'
|
|
586
|
+
);
|
|
587
|
+
} catch (e) {
|
|
588
|
+
// Never break login on debug error
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
return response.body;
|
|
592
|
+
} catch (e) {
|
|
593
|
+
// Completely swallow any errors; this step should never break login.
|
|
594
|
+
return null;
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
|
|
305
598
|
async login(credentialsOrUsername, passwordArg) {
|
|
306
599
|
let username, password;
|
|
307
|
-
if (
|
|
600
|
+
if (
|
|
601
|
+
typeof credentialsOrUsername === 'object' &&
|
|
602
|
+
credentialsOrUsername !== null
|
|
603
|
+
) {
|
|
308
604
|
username = credentialsOrUsername.username;
|
|
309
605
|
password = credentialsOrUsername.password;
|
|
310
|
-
}
|
|
311
|
-
else {
|
|
606
|
+
} else {
|
|
312
607
|
username = credentialsOrUsername;
|
|
313
608
|
password = passwordArg;
|
|
314
609
|
}
|
|
610
|
+
|
|
315
611
|
if (!username || !password) {
|
|
316
612
|
throw new Error('Username and password are required');
|
|
317
613
|
}
|
|
614
|
+
|
|
318
615
|
if (!this.client.state.passwordEncryptionPubKey) {
|
|
319
616
|
await this.syncLoginExperiments();
|
|
320
617
|
}
|
|
618
|
+
|
|
321
619
|
const { encrypted, time } = this.encryptPassword(password);
|
|
620
|
+
|
|
322
621
|
// optional CSRF warmup (like app does before login)
|
|
323
622
|
await this.ensureCsrfToken();
|
|
623
|
+
|
|
624
|
+
// Pre-login Bloks OAuth token fetch (mirrors captured request).
|
|
625
|
+
// This helps the flow look closer to the real app, but is best-effort only.
|
|
626
|
+
try {
|
|
627
|
+
await this._prefetchOauthTokenForLogin(username);
|
|
628
|
+
} catch (e) {
|
|
629
|
+
// Ignore any errors from the prefetch step.
|
|
630
|
+
}
|
|
631
|
+
|
|
324
632
|
return this.requestWithRetry(async () => {
|
|
325
|
-
// ====== client_input_params (
|
|
633
|
+
// ====== client_input_params (mirror of real traffic with password) ======
|
|
326
634
|
const nowSec = Math.floor(Date.now() / 1000);
|
|
327
|
-
const aacInitTimestamp =
|
|
328
|
-
|
|
329
|
-
const
|
|
330
|
-
|
|
635
|
+
const aacInitTimestamp =
|
|
636
|
+
nowSec - Math.floor(Math.random() * 50);
|
|
637
|
+
const aacjid = crypto.randomUUID
|
|
638
|
+
? crypto.randomUUID()
|
|
639
|
+
: require('uuid').v4();
|
|
640
|
+
const aaccs = crypto
|
|
641
|
+
.randomBytes(32)
|
|
642
|
+
.toString('base64')
|
|
643
|
+
.replace(/=/g, '');
|
|
644
|
+
|
|
645
|
+
const androidDeviceId =
|
|
646
|
+
this.client.state.androidDeviceId ||
|
|
331
647
|
this.client.state.deviceId ||
|
|
332
648
|
`android-${crypto.randomBytes(8).toString('hex')}`;
|
|
333
|
-
const machineId =
|
|
649
|
+
const machineId =
|
|
650
|
+
this.client.state.mid ||
|
|
334
651
|
this.client.state.machineId ||
|
|
335
652
|
`aZ${crypto.randomBytes(8).toString('hex')}`;
|
|
336
|
-
const familyDeviceId =
|
|
653
|
+
const familyDeviceId =
|
|
654
|
+
this.client.state.phoneId ||
|
|
337
655
|
this.client.state.familyDeviceId ||
|
|
338
|
-
crypto.randomUUID
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
const qeDeviceId =
|
|
656
|
+
(crypto.randomUUID
|
|
657
|
+
? crypto.randomUUID()
|
|
658
|
+
: require('uuid').v4());
|
|
659
|
+
const qeDeviceId =
|
|
660
|
+
this.client.state.deviceId ||
|
|
342
661
|
this.client.state.qeDeviceId ||
|
|
343
|
-
crypto.randomUUID
|
|
344
|
-
|
|
345
|
-
|
|
662
|
+
(crypto.randomUUID
|
|
663
|
+
? crypto.randomUUID()
|
|
664
|
+
: require('uuid').v4());
|
|
665
|
+
|
|
346
666
|
const accountsList = this.client.state.accountsList || [];
|
|
667
|
+
|
|
347
668
|
const flashCallPermissionStatus = {
|
|
348
669
|
READ_PHONE_STATE: 'GRANTED',
|
|
349
670
|
READ_CALL_LOG: 'GRANTED',
|
|
350
671
|
ANSWER_PHONE_CALLS: 'GRANTED',
|
|
351
672
|
};
|
|
673
|
+
|
|
352
674
|
const clientInputParams = {
|
|
353
675
|
aac: JSON.stringify({
|
|
354
676
|
aac_init_timestamp: aacInitTimestamp,
|
|
@@ -382,7 +704,8 @@ class AccountRepository extends Repository {
|
|
|
382
704
|
machine_id: machineId,
|
|
383
705
|
flash_call_permission_status: flashCallPermissionStatus,
|
|
384
706
|
accounts_list: accountsList,
|
|
385
|
-
gms_incoming_call_retriever_eligibility:
|
|
707
|
+
gms_incoming_call_retriever_eligibility:
|
|
708
|
+
'client_not_supported',
|
|
386
709
|
family_device_id: familyDeviceId,
|
|
387
710
|
fb_ig_device_id: [],
|
|
388
711
|
device_emails: [],
|
|
@@ -393,10 +716,16 @@ class AccountRepository extends Repository {
|
|
|
393
716
|
openid_tokens: {},
|
|
394
717
|
contact_point: username,
|
|
395
718
|
};
|
|
396
|
-
|
|
397
|
-
|
|
719
|
+
|
|
720
|
+
// ====== server_params (mirror after reverse engineering) ======
|
|
721
|
+
const waterfallId = crypto.randomUUID
|
|
722
|
+
? crypto.randomUUID()
|
|
723
|
+
: require('uuid').v4();
|
|
398
724
|
const latencyMarkerId = 36707139;
|
|
399
|
-
const latencyInstanceId = Number(
|
|
725
|
+
const latencyInstanceId = Number(
|
|
726
|
+
`${Date.now()}${Math.floor(Math.random() * 1000)}`
|
|
727
|
+
);
|
|
728
|
+
|
|
400
729
|
const serverParams = {
|
|
401
730
|
should_trigger_override_login_2fa_action: 0,
|
|
402
731
|
is_vanilla_password_page_empty_password: 0,
|
|
@@ -410,7 +739,8 @@ class AccountRepository extends Repository {
|
|
|
410
739
|
is_platform_login: 0,
|
|
411
740
|
INTERNAL__latency_qpl_marker_id: latencyMarkerId,
|
|
412
741
|
is_from_aymh: 0,
|
|
413
|
-
offline_experiment_group:
|
|
742
|
+
offline_experiment_group:
|
|
743
|
+
'caa_iteration_v3_perf_ig_4',
|
|
414
744
|
is_from_landing_page: 0,
|
|
415
745
|
left_nav_button_action: 'NONE',
|
|
416
746
|
password_text_input_id: 'z0jejq:194',
|
|
@@ -423,7 +753,8 @@ class AccountRepository extends Repository {
|
|
|
423
753
|
device_id: androidDeviceId,
|
|
424
754
|
login_surface: 'switcher',
|
|
425
755
|
INTERNAL__latency_qpl_instance_id: latencyInstanceId,
|
|
426
|
-
reg_flow_source:
|
|
756
|
+
reg_flow_source:
|
|
757
|
+
'login_home_native_integration_point',
|
|
427
758
|
is_caa_perf_enabled: 1,
|
|
428
759
|
credential_type: 'password',
|
|
429
760
|
is_from_password_entry_page: 0,
|
|
@@ -433,39 +764,59 @@ class AccountRepository extends Repository {
|
|
|
433
764
|
access_flow_version: 'pre_mt_behavior',
|
|
434
765
|
is_from_logged_in_switcher: 1,
|
|
435
766
|
};
|
|
767
|
+
|
|
436
768
|
const paramsJson = JSON.stringify({
|
|
437
769
|
client_input_params: clientInputParams,
|
|
438
770
|
server_params: serverParams,
|
|
439
771
|
});
|
|
440
|
-
|
|
772
|
+
|
|
773
|
+
const attestParams =
|
|
774
|
+
AccountRepository.generateAttestParams(
|
|
775
|
+
this.client.state
|
|
776
|
+
);
|
|
777
|
+
const bloksVersionId =
|
|
778
|
+
this.client.state.bloksVersionId ||
|
|
779
|
+
'5e47baf35c5a270b44c8906c8b99063564b30ef69779f3dee0b828bee2e4ef5b';
|
|
780
|
+
|
|
441
781
|
const bkClientContext = JSON.stringify({
|
|
442
|
-
bloks_version:
|
|
782
|
+
bloks_version: bloksVersionId,
|
|
443
783
|
styles_id: 'instagram',
|
|
444
784
|
});
|
|
445
|
-
|
|
446
|
-
|
|
785
|
+
|
|
786
|
+
// ====== HEADERS – modelled after real traffic ======
|
|
787
|
+
const lang = this.client.state.language || 'ro_RO';
|
|
447
788
|
const acceptLanguage = `${lang.replace('_', '-')}, en-US`;
|
|
448
|
-
const userAgent =
|
|
789
|
+
const userAgent =
|
|
790
|
+
this.client.state.userAgent ||
|
|
449
791
|
'Instagram 371.0.0.0.23 Android (30/11; 320dpi; 720x1449; Xiaomi/Redmi; M2006C3MNG; angelican; mt6765; ro_RO; 703217507)';
|
|
792
|
+
|
|
450
793
|
const bloksHeaders = {
|
|
451
794
|
'accept-language': acceptLanguage,
|
|
452
|
-
'content-type':
|
|
795
|
+
'content-type':
|
|
796
|
+
'application/x-www-form-urlencoded; charset=UTF-8',
|
|
453
797
|
'ig-intended-user-id': '0',
|
|
454
|
-
|
|
798
|
+
priority: 'u=3',
|
|
799
|
+
|
|
455
800
|
'x-bloks-is-layout-rtl': 'false',
|
|
456
801
|
'x-bloks-prism-ax-base-colors-enabled': 'false',
|
|
457
802
|
'x-bloks-prism-button-version': 'CONTROL',
|
|
458
803
|
'x-bloks-prism-colors-enabled': 'true',
|
|
459
804
|
'x-bloks-prism-font-enabled': 'false',
|
|
460
805
|
'x-bloks-prism-indigo-link-version': '0',
|
|
461
|
-
'x-bloks-version-id':
|
|
806
|
+
'x-bloks-version-id': bloksVersionId,
|
|
807
|
+
|
|
462
808
|
'x-fb-client-ip': 'True',
|
|
463
809
|
'x-fb-connection-type': 'WIFI',
|
|
464
|
-
'x-fb-friendly-name':
|
|
465
|
-
|
|
810
|
+
'x-fb-friendly-name':
|
|
811
|
+
'IgApi: bloks/async_action/com.bloks.www.bloks.caa.login.async.send_login_request/',
|
|
812
|
+
'x-fb-network-properties':
|
|
813
|
+
'VPN;Validated;LocalAddrs=/10.0.0.2,;',
|
|
466
814
|
'x-fb-request-analytics-tags': JSON.stringify({
|
|
467
815
|
network_tags: {
|
|
468
|
-
product: String(
|
|
816
|
+
product: String(
|
|
817
|
+
this.client.state.fbAnalyticsApplicationId ||
|
|
818
|
+
'567067343352427'
|
|
819
|
+
),
|
|
469
820
|
purpose: 'fetch',
|
|
470
821
|
surface: 'undefined',
|
|
471
822
|
request_category: 'api',
|
|
@@ -473,78 +824,111 @@ class AccountRepository extends Repository {
|
|
|
473
824
|
},
|
|
474
825
|
}),
|
|
475
826
|
'x-fb-server-cluster': 'True',
|
|
827
|
+
|
|
476
828
|
'x-ig-android-id': androidDeviceId,
|
|
477
|
-
'x-ig-app-id': String(
|
|
829
|
+
'x-ig-app-id': String(
|
|
830
|
+
this.client.state.fbAnalyticsApplicationId ||
|
|
831
|
+
'567067343352427'
|
|
832
|
+
),
|
|
478
833
|
'x-ig-app-locale': lang,
|
|
479
834
|
'x-ig-attest-params': JSON.stringify(attestParams),
|
|
480
|
-
'x-ig-bandwidth-speed-kbps': (
|
|
835
|
+
'x-ig-bandwidth-speed-kbps': (
|
|
836
|
+
Math.random() * 1500 +
|
|
837
|
+
800
|
|
838
|
+
).toFixed(3),
|
|
481
839
|
'x-ig-bandwidth-totalbytes-b': '0',
|
|
482
840
|
'x-ig-bandwidth-totaltime-ms': '0',
|
|
483
|
-
'x-ig-client-endpoint':
|
|
841
|
+
'x-ig-client-endpoint':
|
|
842
|
+
'com.bloks.www.caa.login.aymh_single_profile_screen_entry',
|
|
484
843
|
'x-ig-capabilities': '3brTv10=',
|
|
485
844
|
'x-ig-connection-type': 'WIFI',
|
|
486
845
|
'x-ig-device-id': qeDeviceId,
|
|
487
846
|
'x-ig-device-locale': lang,
|
|
488
847
|
'x-ig-family-device-id': familyDeviceId,
|
|
489
848
|
'x-ig-mapped-locale': lang,
|
|
490
|
-
'x-ig-nav-chain':
|
|
491
|
-
'com.bloks.www.caa.login.aymh_single_profile_screen_entry:com.bloks.www.caa.login.aymh_single_profile_screen_entry:14:button:0:::0',
|
|
492
|
-
'x-ig-timezone-offset': String(
|
|
493
|
-
|
|
494
|
-
|
|
849
|
+
'x-ig-nav-chain':
|
|
850
|
+
'LockoutFragment:dogfooding_lockout:1:cold_start:...,com.bloks.www.caa.login.aymh_single_profile_screen_entry:com.bloks.www.caa.login.aymh_single_profile_screen_entry:14:button:0:::0',
|
|
851
|
+
'x-ig-timezone-offset': String(
|
|
852
|
+
typeof this.client.state.timezoneOffset ===
|
|
853
|
+
'number'
|
|
854
|
+
? this.client.state.timezoneOffset
|
|
855
|
+
: 7200
|
|
856
|
+
),
|
|
495
857
|
'x-ig-www-claim': this.client.state.igWWWClaim || '0',
|
|
496
858
|
'x-mid': machineId,
|
|
497
|
-
'x-pigeon-rawclienttime': `${nowSec}.${Math.floor(
|
|
859
|
+
'x-pigeon-rawclienttime': `${nowSec}.${Math.floor(
|
|
860
|
+
Math.random() * 1000
|
|
861
|
+
)
|
|
498
862
|
.toString()
|
|
499
863
|
.padStart(3, '0')}`,
|
|
500
|
-
'x-pigeon-session-id':
|
|
501
|
-
|
|
864
|
+
'x-pigeon-session-id':
|
|
865
|
+
this.client.state.pigeonSessionId ||
|
|
866
|
+
`UFS-${crypto.randomBytes(16).toString(
|
|
867
|
+
'hex'
|
|
868
|
+
)}-1`,
|
|
502
869
|
'x-tigon-is-retry': 'False',
|
|
503
|
-
|
|
870
|
+
|
|
504
871
|
'accept-encoding': 'gzip, deflate, br',
|
|
505
|
-
// ...
|
|
506
872
|
'user-agent': userAgent,
|
|
507
|
-
'x-fb-conn-uuid-client':
|
|
873
|
+
'x-fb-conn-uuid-client':
|
|
874
|
+
crypto.randomBytes(16).toString('hex'),
|
|
508
875
|
'x-fb-http-engine': 'MNS/TCP',
|
|
509
876
|
'x-fb-rmd': 'state=URL_ELIGIBLE',
|
|
510
877
|
};
|
|
878
|
+
|
|
511
879
|
const response = await this.client.request.send({
|
|
512
880
|
method: 'POST',
|
|
513
881
|
url: '/api/v1/bloks/async_action/com.bloks.www.bloks.caa.login.async.send_login_request/',
|
|
514
882
|
form: {
|
|
515
883
|
params: paramsJson,
|
|
516
884
|
bk_client_context: bkClientContext,
|
|
517
|
-
bloks_versioning_id:
|
|
885
|
+
bloks_versioning_id: bloksVersionId,
|
|
518
886
|
},
|
|
519
887
|
headers: bloksHeaders,
|
|
520
888
|
});
|
|
521
|
-
|
|
889
|
+
|
|
890
|
+
// === DEBUG LOGIN: save response for offline analysis ===
|
|
522
891
|
try {
|
|
523
892
|
const fs = require('fs');
|
|
524
893
|
const path = require('path');
|
|
525
|
-
const debugDir = path.join(
|
|
526
|
-
|
|
894
|
+
const debugDir = path.join(
|
|
895
|
+
process.cwd(),
|
|
896
|
+
'authinfo_instagram'
|
|
897
|
+
);
|
|
898
|
+
const debugFile = path.join(
|
|
899
|
+
debugDir,
|
|
900
|
+
'login-debug.json'
|
|
901
|
+
);
|
|
527
902
|
try {
|
|
528
903
|
fs.mkdirSync(debugDir, { recursive: true });
|
|
529
|
-
}
|
|
530
|
-
|
|
904
|
+
} catch (e) {}
|
|
905
|
+
|
|
531
906
|
const debugPayload = {
|
|
532
907
|
at: new Date().toISOString(),
|
|
533
|
-
statusCode:
|
|
908
|
+
statusCode:
|
|
909
|
+
response.statusCode || response.status || null,
|
|
534
910
|
headers: response.headers || null,
|
|
535
911
|
body: response.body || null,
|
|
536
912
|
};
|
|
537
|
-
fs.writeFileSync(
|
|
913
|
+
fs.writeFileSync(
|
|
914
|
+
debugFile,
|
|
915
|
+
JSON.stringify(debugPayload, null, 2),
|
|
916
|
+
'utf8'
|
|
917
|
+
);
|
|
918
|
+
} catch (e) {
|
|
919
|
+
// don't break login on debug failure
|
|
538
920
|
}
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
}
|
|
542
|
-
// === SFÂRȘIT DEBUG LOGIN ===
|
|
921
|
+
// === END DEBUG LOGIN ===
|
|
922
|
+
|
|
543
923
|
const body = response.body;
|
|
924
|
+
|
|
544
925
|
// Immediately attempt to extract and save authorization token from the response
|
|
545
926
|
this._extractAndSaveAuthorization(response);
|
|
927
|
+
|
|
546
928
|
if (body && body.two_factor_required) {
|
|
547
|
-
const err = new Error(
|
|
929
|
+
const err = new Error(
|
|
930
|
+
'Two factor authentication required'
|
|
931
|
+
);
|
|
548
932
|
err.name = 'IgLoginTwoFactorRequiredError';
|
|
549
933
|
err.twoFactorInfo = body.two_factor_info;
|
|
550
934
|
throw err;
|
|
@@ -565,28 +949,46 @@ class AccountRepository extends Repository {
|
|
|
565
949
|
err.challengeInfo = body.challenge;
|
|
566
950
|
throw err;
|
|
567
951
|
}
|
|
952
|
+
|
|
568
953
|
if (body && body.layout) {
|
|
569
|
-
const layoutStr =
|
|
954
|
+
const layoutStr =
|
|
955
|
+
typeof body.layout === 'string'
|
|
956
|
+
? body.layout
|
|
957
|
+
: JSON.stringify(body.layout);
|
|
958
|
+
|
|
570
959
|
// If layout contains two-factor markers, parse and throw
|
|
571
|
-
if (
|
|
960
|
+
if (
|
|
961
|
+
layoutStr.includes('two_factor_required') ||
|
|
962
|
+
layoutStr.includes('"two_factor_info"')
|
|
963
|
+
) {
|
|
572
964
|
let twoFactorInfo = null;
|
|
573
965
|
try {
|
|
574
|
-
const match = layoutStr.match(
|
|
966
|
+
const match = layoutStr.match(
|
|
967
|
+
/"two_factor_info"\s*:\s*(\{[^}]+\})/
|
|
968
|
+
);
|
|
575
969
|
if (match)
|
|
576
970
|
twoFactorInfo = JSON.parse(match[1]);
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
|
|
971
|
+
} catch (e) {}
|
|
972
|
+
const err = new Error(
|
|
973
|
+
'Two factor authentication required'
|
|
974
|
+
);
|
|
580
975
|
err.name = 'IgLoginTwoFactorRequiredError';
|
|
581
976
|
err.twoFactorInfo = twoFactorInfo;
|
|
582
977
|
throw err;
|
|
583
978
|
}
|
|
584
|
-
|
|
979
|
+
|
|
980
|
+
if (
|
|
981
|
+
layoutStr.includes('bad_password') ||
|
|
982
|
+
layoutStr.includes('incorrect_password')
|
|
983
|
+
) {
|
|
585
984
|
const err = new Error('Bad password');
|
|
586
985
|
err.name = 'IgLoginBadPasswordError';
|
|
587
986
|
throw err;
|
|
588
987
|
}
|
|
589
|
-
if (
|
|
988
|
+
if (
|
|
989
|
+
layoutStr.includes('invalid_user') ||
|
|
990
|
+
layoutStr.includes('user_not_found')
|
|
991
|
+
) {
|
|
590
992
|
const err = new Error('Invalid user');
|
|
591
993
|
err.name = 'IgLoginInvalidUserError';
|
|
592
994
|
throw err;
|
|
@@ -597,15 +999,18 @@ class AccountRepository extends Repository {
|
|
|
597
999
|
err.challengeInfo = body.challenge || null;
|
|
598
1000
|
throw err;
|
|
599
1001
|
}
|
|
600
|
-
|
|
601
|
-
|
|
1002
|
+
|
|
1003
|
+
// Additional attempt to extract token from layout string
|
|
1004
|
+
const tokenFromLayout =
|
|
1005
|
+
this._findBearerInString(layoutStr);
|
|
602
1006
|
if (tokenFromLayout) {
|
|
603
|
-
this.client.state.authorization =
|
|
1007
|
+
this.client.state.authorization =
|
|
1008
|
+
tokenFromLayout;
|
|
604
1009
|
try {
|
|
605
1010
|
this.client.state.updateAuthorization();
|
|
606
|
-
}
|
|
607
|
-
catch (e) { }
|
|
1011
|
+
} catch (e) {}
|
|
608
1012
|
}
|
|
1013
|
+
|
|
609
1014
|
// Extract pk (user id) from layout if present
|
|
610
1015
|
const pkPatterns = [
|
|
611
1016
|
/\\"pk\\":\s*(\d+)/,
|
|
@@ -620,11 +1025,13 @@ class AccountRepository extends Repository {
|
|
|
620
1025
|
const pkMatch = layoutStr.match(pattern);
|
|
621
1026
|
if (pkMatch) {
|
|
622
1027
|
extractedPk = pkMatch[1];
|
|
623
|
-
this.client.state.cookieUserId =
|
|
1028
|
+
this.client.state.cookieUserId =
|
|
1029
|
+
extractedPk;
|
|
624
1030
|
this.client.state._userId = extractedPk;
|
|
625
1031
|
break;
|
|
626
1032
|
}
|
|
627
1033
|
}
|
|
1034
|
+
|
|
628
1035
|
// Extract IG-Set-WWW-Claim if present
|
|
629
1036
|
const wwwClaimPatterns = [
|
|
630
1037
|
/IG-Set-WWW-Claim[\\"\s:]+([a-f0-9]+)/i,
|
|
@@ -635,26 +1042,48 @@ class AccountRepository extends Repository {
|
|
|
635
1042
|
for (const pattern of wwwClaimPatterns) {
|
|
636
1043
|
const wwwClaimMatch = layoutStr.match(pattern);
|
|
637
1044
|
if (wwwClaimMatch) {
|
|
638
|
-
this.client.state.igWWWClaim =
|
|
1045
|
+
this.client.state.igWWWClaim =
|
|
1046
|
+
wwwClaimMatch[1];
|
|
639
1047
|
break;
|
|
640
1048
|
}
|
|
641
1049
|
}
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
1050
|
+
|
|
1051
|
+
// Extract encryption key id and pub key (already attempted earlier)
|
|
1052
|
+
const encKeyIdMatch =
|
|
1053
|
+
layoutStr.match(
|
|
1054
|
+
/IG-Set-Password-Encryption-Key-Id[\\"\s:]+(\d+)/i
|
|
1055
|
+
) ||
|
|
1056
|
+
layoutStr.match(
|
|
1057
|
+
/password.encryption.key.id[\\"\s:]+(\d+)/i
|
|
1058
|
+
);
|
|
645
1059
|
if (encKeyIdMatch) {
|
|
646
|
-
this.client.state.passwordEncryptionKeyId =
|
|
1060
|
+
this.client.state.passwordEncryptionKeyId =
|
|
1061
|
+
parseInt(encKeyIdMatch[1]);
|
|
647
1062
|
}
|
|
648
|
-
|
|
649
|
-
|
|
1063
|
+
|
|
1064
|
+
const encPubKeyMatch =
|
|
1065
|
+
layoutStr.match(
|
|
1066
|
+
/IG-Set-Password-Encryption-Pub-Key[\\"\s:]+([A-Za-z0-9+\/=]+)/i
|
|
1067
|
+
) ||
|
|
1068
|
+
layoutStr.match(
|
|
1069
|
+
/password.encryption.pub.key[\\"\s:]+([A-Za-z0-9+\/=]+)/i
|
|
1070
|
+
);
|
|
650
1071
|
if (encPubKeyMatch) {
|
|
651
|
-
this.client.state.passwordEncryptionPubKey =
|
|
1072
|
+
this.client.state.passwordEncryptionPubKey =
|
|
1073
|
+
encPubKeyMatch[1];
|
|
652
1074
|
}
|
|
653
|
-
|
|
654
|
-
|
|
1075
|
+
|
|
1076
|
+
const midMatch =
|
|
1077
|
+
layoutStr.match(
|
|
1078
|
+
/ig-set-x-mid[\\"\s:]+([A-Za-z0-9+\/=_-]+)/i
|
|
1079
|
+
) ||
|
|
1080
|
+
layoutStr.match(
|
|
1081
|
+
/\\"x-mid\\"[\\"\s:]+([A-Za-z0-9+\/=_-]+)/i
|
|
1082
|
+
);
|
|
655
1083
|
if (midMatch) {
|
|
656
1084
|
this.client.state.mid = midMatch[1];
|
|
657
1085
|
}
|
|
1086
|
+
|
|
658
1087
|
// If layout contains a direct logged_in_user JSON, extract and return it
|
|
659
1088
|
const loginResponsePatterns = [
|
|
660
1089
|
/\\"logged_in_user\\":\{[^}]*\\"pk\\":(\d+)[^}]*\\"username\\":\\"([^"\\]+)\\"/,
|
|
@@ -662,10 +1091,13 @@ class AccountRepository extends Repository {
|
|
|
662
1091
|
/\\"logged_in_user\\".*?\\"pk\\":\s*(\d+).*?\\"username\\":\s*\\"([^"\\]+)\\"/s,
|
|
663
1092
|
];
|
|
664
1093
|
for (const pattern of loginResponsePatterns) {
|
|
665
|
-
const loginResponseMatch =
|
|
1094
|
+
const loginResponseMatch =
|
|
1095
|
+
layoutStr.match(pattern);
|
|
666
1096
|
if (loginResponseMatch) {
|
|
667
|
-
this.client.state.cookieUserId =
|
|
668
|
-
|
|
1097
|
+
this.client.state.cookieUserId =
|
|
1098
|
+
loginResponseMatch[1];
|
|
1099
|
+
this.client.state._userId =
|
|
1100
|
+
loginResponseMatch[1];
|
|
669
1101
|
return {
|
|
670
1102
|
pk: parseInt(loginResponseMatch[1]),
|
|
671
1103
|
pk_id: loginResponseMatch[1],
|
|
@@ -673,22 +1105,31 @@ class AccountRepository extends Repository {
|
|
|
673
1105
|
};
|
|
674
1106
|
}
|
|
675
1107
|
}
|
|
1108
|
+
|
|
676
1109
|
// If we have extracted a pk and we also have authorization, try to fetch current user
|
|
677
|
-
if (
|
|
1110
|
+
if (
|
|
1111
|
+
extractedPk &&
|
|
1112
|
+
this.client.state.authorization
|
|
1113
|
+
) {
|
|
678
1114
|
try {
|
|
679
1115
|
const userInfo = await this.currentUser();
|
|
680
1116
|
const user = userInfo.user || userInfo;
|
|
681
1117
|
if (user && user.pk) {
|
|
682
|
-
this.client.state.cookieUserId =
|
|
683
|
-
|
|
1118
|
+
this.client.state.cookieUserId =
|
|
1119
|
+
String(user.pk);
|
|
1120
|
+
this.client.state._userId =
|
|
1121
|
+
String(user.pk);
|
|
684
1122
|
}
|
|
685
1123
|
return user;
|
|
686
|
-
}
|
|
687
|
-
|
|
688
|
-
|
|
1124
|
+
} catch (e) {
|
|
1125
|
+
return {
|
|
1126
|
+
pk: parseInt(extractedPk),
|
|
1127
|
+
pk_id: extractedPk,
|
|
1128
|
+
};
|
|
689
1129
|
}
|
|
690
1130
|
}
|
|
691
1131
|
}
|
|
1132
|
+
|
|
692
1133
|
// If server returned logged_in_user directly in body
|
|
693
1134
|
if (body && body.logged_in_user) {
|
|
694
1135
|
const lu = body.logged_in_user;
|
|
@@ -700,26 +1141,34 @@ class AccountRepository extends Repository {
|
|
|
700
1141
|
this._extractAndSaveAuthorization(response);
|
|
701
1142
|
return lu;
|
|
702
1143
|
}
|
|
1144
|
+
|
|
703
1145
|
// If we already have authorization, try to fetch current user to populate state
|
|
704
1146
|
if (this.client.state.authorization) {
|
|
705
1147
|
try {
|
|
706
1148
|
const userInfo = await this.currentUser();
|
|
707
1149
|
const user = userInfo.user || userInfo;
|
|
708
1150
|
if (user && user.pk) {
|
|
709
|
-
this.client.state.cookieUserId =
|
|
1151
|
+
this.client.state.cookieUserId =
|
|
1152
|
+
String(user.pk);
|
|
710
1153
|
this.client.state._userId = String(user.pk);
|
|
711
1154
|
}
|
|
712
1155
|
return user;
|
|
713
|
-
}
|
|
714
|
-
catch (e) {
|
|
1156
|
+
} catch (e) {
|
|
715
1157
|
// fallback: return raw body
|
|
716
1158
|
return body;
|
|
717
1159
|
}
|
|
718
1160
|
}
|
|
1161
|
+
|
|
719
1162
|
return body;
|
|
720
1163
|
});
|
|
721
1164
|
}
|
|
722
|
-
|
|
1165
|
+
|
|
1166
|
+
async twoFactorLogin(
|
|
1167
|
+
username,
|
|
1168
|
+
verificationCode,
|
|
1169
|
+
twoFactorIdentifier,
|
|
1170
|
+
verificationMethod = '1'
|
|
1171
|
+
) {
|
|
723
1172
|
return this.requestWithRetry(async () => {
|
|
724
1173
|
const response = await this.client.request.send({
|
|
725
1174
|
method: 'POST',
|
|
@@ -740,6 +1189,7 @@ class AccountRepository extends Repository {
|
|
|
740
1189
|
return response.body;
|
|
741
1190
|
});
|
|
742
1191
|
}
|
|
1192
|
+
|
|
743
1193
|
async logout() {
|
|
744
1194
|
return this.requestWithRetry(async () => {
|
|
745
1195
|
const response = await this.client.request.send({
|
|
@@ -752,6 +1202,7 @@ class AccountRepository extends Repository {
|
|
|
752
1202
|
return response.body;
|
|
753
1203
|
});
|
|
754
1204
|
}
|
|
1205
|
+
|
|
755
1206
|
async currentUser() {
|
|
756
1207
|
return this.requestWithRetry(async () => {
|
|
757
1208
|
const response = await this.client.request.send({
|
|
@@ -762,10 +1213,19 @@ class AccountRepository extends Repository {
|
|
|
762
1213
|
return response.body;
|
|
763
1214
|
});
|
|
764
1215
|
}
|
|
1216
|
+
|
|
765
1217
|
async accountInfo() {
|
|
766
1218
|
return this.currentUser();
|
|
767
1219
|
}
|
|
768
|
-
|
|
1220
|
+
|
|
1221
|
+
async editProfile({
|
|
1222
|
+
externalUrl,
|
|
1223
|
+
phoneNumber,
|
|
1224
|
+
username,
|
|
1225
|
+
fullName,
|
|
1226
|
+
biography,
|
|
1227
|
+
email,
|
|
1228
|
+
} = {}) {
|
|
769
1229
|
return this.requestWithRetry(async () => {
|
|
770
1230
|
const current = await this.currentUser();
|
|
771
1231
|
const user = current.user || current;
|
|
@@ -774,26 +1234,48 @@ class AccountRepository extends Repository {
|
|
|
774
1234
|
url: '/api/v1/accounts/edit_profile/',
|
|
775
1235
|
form: this.client.request.sign({
|
|
776
1236
|
_uuid: this.client.state.uuid,
|
|
777
|
-
external_url:
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
1237
|
+
external_url:
|
|
1238
|
+
externalUrl !== undefined
|
|
1239
|
+
? externalUrl
|
|
1240
|
+
: user.external_url || '',
|
|
1241
|
+
phone_number:
|
|
1242
|
+
phoneNumber !== undefined
|
|
1243
|
+
? phoneNumber
|
|
1244
|
+
: user.phone_number || '',
|
|
1245
|
+
username:
|
|
1246
|
+
username !== undefined
|
|
1247
|
+
? username
|
|
1248
|
+
: user.username,
|
|
1249
|
+
full_name:
|
|
1250
|
+
fullName !== undefined
|
|
1251
|
+
? fullName
|
|
1252
|
+
: user.full_name || '',
|
|
1253
|
+
biography:
|
|
1254
|
+
biography !== undefined
|
|
1255
|
+
? biography
|
|
1256
|
+
: user.biography || '',
|
|
1257
|
+
email:
|
|
1258
|
+
email !== undefined
|
|
1259
|
+
? email
|
|
1260
|
+
: user.email || '',
|
|
783
1261
|
}),
|
|
784
1262
|
});
|
|
785
1263
|
return response.body;
|
|
786
1264
|
});
|
|
787
1265
|
}
|
|
1266
|
+
|
|
788
1267
|
async setBiography(biography) {
|
|
789
1268
|
return this.editProfile({ biography });
|
|
790
1269
|
}
|
|
1270
|
+
|
|
791
1271
|
async setExternalUrl(url) {
|
|
792
1272
|
return this.editProfile({ externalUrl: url });
|
|
793
1273
|
}
|
|
1274
|
+
|
|
794
1275
|
async removeBioLinks() {
|
|
795
1276
|
return this.editProfile({ externalUrl: '' });
|
|
796
1277
|
}
|
|
1278
|
+
|
|
797
1279
|
async setGender(gender) {
|
|
798
1280
|
return this.requestWithRetry(async () => {
|
|
799
1281
|
const response = await this.client.request.send({
|
|
@@ -807,6 +1289,7 @@ class AccountRepository extends Repository {
|
|
|
807
1289
|
return response.body;
|
|
808
1290
|
});
|
|
809
1291
|
}
|
|
1292
|
+
|
|
810
1293
|
async setPrivate() {
|
|
811
1294
|
return this.requestWithRetry(async () => {
|
|
812
1295
|
const response = await this.client.request.send({
|
|
@@ -819,6 +1302,7 @@ class AccountRepository extends Repository {
|
|
|
819
1302
|
return response.body;
|
|
820
1303
|
});
|
|
821
1304
|
}
|
|
1305
|
+
|
|
822
1306
|
async setPublic() {
|
|
823
1307
|
return this.requestWithRetry(async () => {
|
|
824
1308
|
const response = await this.client.request.send({
|
|
@@ -831,6 +1315,7 @@ class AccountRepository extends Repository {
|
|
|
831
1315
|
return response.body;
|
|
832
1316
|
});
|
|
833
1317
|
}
|
|
1318
|
+
|
|
834
1319
|
async changePassword(oldPassword, newPassword) {
|
|
835
1320
|
const oldEnc = this.encryptPassword(oldPassword);
|
|
836
1321
|
const newEnc = this.encryptPassword(newPassword);
|
|
@@ -848,6 +1333,7 @@ class AccountRepository extends Repository {
|
|
|
848
1333
|
return response.body;
|
|
849
1334
|
});
|
|
850
1335
|
}
|
|
1336
|
+
|
|
851
1337
|
async sendConfirmEmail() {
|
|
852
1338
|
return this.requestWithRetry(async () => {
|
|
853
1339
|
const response = await this.client.request.send({
|
|
@@ -861,6 +1347,7 @@ class AccountRepository extends Repository {
|
|
|
861
1347
|
return response.body;
|
|
862
1348
|
});
|
|
863
1349
|
}
|
|
1350
|
+
|
|
864
1351
|
async sendConfirmPhoneNumber(phoneNumber) {
|
|
865
1352
|
return this.requestWithRetry(async () => {
|
|
866
1353
|
const response = await this.client.request.send({
|
|
@@ -874,6 +1361,7 @@ class AccountRepository extends Repository {
|
|
|
874
1361
|
return response.body;
|
|
875
1362
|
});
|
|
876
1363
|
}
|
|
1364
|
+
|
|
877
1365
|
async profilePictureChange(uploadId) {
|
|
878
1366
|
return this.requestWithRetry(async () => {
|
|
879
1367
|
const response = await this.client.request.send({
|
|
@@ -888,6 +1376,7 @@ class AccountRepository extends Repository {
|
|
|
888
1376
|
return response.body;
|
|
889
1377
|
});
|
|
890
1378
|
}
|
|
1379
|
+
|
|
891
1380
|
async profilePictureRemove() {
|
|
892
1381
|
return this.requestWithRetry(async () => {
|
|
893
1382
|
const response = await this.client.request.send({
|
|
@@ -900,6 +1389,7 @@ class AccountRepository extends Repository {
|
|
|
900
1389
|
return response.body;
|
|
901
1390
|
});
|
|
902
1391
|
}
|
|
1392
|
+
|
|
903
1393
|
async newsInbox() {
|
|
904
1394
|
return this.requestWithRetry(async () => {
|
|
905
1395
|
const response = await this.client.request.send({
|
|
@@ -909,6 +1399,7 @@ class AccountRepository extends Repository {
|
|
|
909
1399
|
return response.body;
|
|
910
1400
|
});
|
|
911
1401
|
}
|
|
1402
|
+
|
|
912
1403
|
async syncLoginExperiments() {
|
|
913
1404
|
return this.requestWithRetry(async () => {
|
|
914
1405
|
const response = await this.client.request.send({
|
|
@@ -917,20 +1408,23 @@ class AccountRepository extends Repository {
|
|
|
917
1408
|
form: this.client.request.sign({
|
|
918
1409
|
id: this.client.state.uuid,
|
|
919
1410
|
server_config_retrieval: '1',
|
|
920
|
-
experiments:
|
|
1411
|
+
experiments:
|
|
1412
|
+
this.client.state.constants
|
|
1413
|
+
.LOGIN_EXPERIMENTS,
|
|
921
1414
|
}),
|
|
922
1415
|
});
|
|
923
1416
|
return response.body;
|
|
924
1417
|
});
|
|
925
1418
|
}
|
|
1419
|
+
|
|
926
1420
|
async syncPostLoginExperiments() {
|
|
927
1421
|
let userId;
|
|
928
1422
|
try {
|
|
929
1423
|
userId = this.client.state.cookieUserId;
|
|
930
|
-
}
|
|
931
|
-
catch {
|
|
1424
|
+
} catch {
|
|
932
1425
|
userId = '0';
|
|
933
1426
|
}
|
|
1427
|
+
|
|
934
1428
|
return this.requestWithRetry(async () => {
|
|
935
1429
|
const response = await this.client.request.send({
|
|
936
1430
|
method: 'POST',
|
|
@@ -940,12 +1434,14 @@ class AccountRepository extends Repository {
|
|
|
940
1434
|
_uid: userId,
|
|
941
1435
|
_uuid: this.client.state.uuid,
|
|
942
1436
|
server_config_retrieval: '1',
|
|
943
|
-
experiments:
|
|
1437
|
+
experiments:
|
|
1438
|
+
this.client.state.constants.EXPERIMENTS,
|
|
944
1439
|
}),
|
|
945
1440
|
});
|
|
946
1441
|
return response.body;
|
|
947
1442
|
});
|
|
948
1443
|
}
|
|
1444
|
+
|
|
949
1445
|
async syncLauncher(preLogin = true) {
|
|
950
1446
|
const data = {
|
|
951
1447
|
id: this.client.state.uuid,
|
|
@@ -955,9 +1451,9 @@ class AccountRepository extends Repository {
|
|
|
955
1451
|
try {
|
|
956
1452
|
data._uid = this.client.state.cookieUserId;
|
|
957
1453
|
data._uuid = this.client.state.uuid;
|
|
958
|
-
}
|
|
959
|
-
catch { }
|
|
1454
|
+
} catch {}
|
|
960
1455
|
}
|
|
1456
|
+
|
|
961
1457
|
return this.requestWithRetry(async () => {
|
|
962
1458
|
const response = await this.client.request.send({
|
|
963
1459
|
method: 'POST',
|
|
@@ -967,6 +1463,7 @@ class AccountRepository extends Repository {
|
|
|
967
1463
|
return response.body;
|
|
968
1464
|
});
|
|
969
1465
|
}
|
|
1466
|
+
|
|
970
1467
|
async syncDeviceFeatures() {
|
|
971
1468
|
return this.requestWithRetry(async () => {
|
|
972
1469
|
const response = await this.client.request.send({
|
|
@@ -980,6 +1477,7 @@ class AccountRepository extends Repository {
|
|
|
980
1477
|
return response.body;
|
|
981
1478
|
});
|
|
982
1479
|
}
|
|
1480
|
+
|
|
983
1481
|
async getPrefillCandidates() {
|
|
984
1482
|
return this.requestWithRetry(async () => {
|
|
985
1483
|
const response = await this.client.request.send({
|
|
@@ -995,6 +1493,7 @@ class AccountRepository extends Repository {
|
|
|
995
1493
|
return response.body;
|
|
996
1494
|
});
|
|
997
1495
|
}
|
|
1496
|
+
|
|
998
1497
|
async contactPointPrefill(usage = 'prefill') {
|
|
999
1498
|
return this.requestWithRetry(async () => {
|
|
1000
1499
|
const response = await this.client.request.send({
|
|
@@ -1008,6 +1507,7 @@ class AccountRepository extends Repository {
|
|
|
1008
1507
|
return response.body;
|
|
1009
1508
|
});
|
|
1010
1509
|
}
|
|
1510
|
+
|
|
1011
1511
|
async getZrToken(params = {}) {
|
|
1012
1512
|
return this.requestWithRetry(async () => {
|
|
1013
1513
|
const response = await this.client.request.send({
|
|
@@ -1024,6 +1524,7 @@ class AccountRepository extends Repository {
|
|
|
1024
1524
|
return response.body;
|
|
1025
1525
|
});
|
|
1026
1526
|
}
|
|
1527
|
+
|
|
1027
1528
|
async getConsentSignupConfig() {
|
|
1028
1529
|
return this.requestWithRetry(async () => {
|
|
1029
1530
|
const response = await this.client.request.send({
|
|
@@ -1037,6 +1538,7 @@ class AccountRepository extends Repository {
|
|
|
1037
1538
|
return response.body;
|
|
1038
1539
|
});
|
|
1039
1540
|
}
|
|
1541
|
+
|
|
1040
1542
|
async sendRecoveryFlowEmail(query) {
|
|
1041
1543
|
return this.requestWithRetry(async () => {
|
|
1042
1544
|
const response = await this.client.request.send({
|
|
@@ -1052,6 +1554,7 @@ class AccountRepository extends Repository {
|
|
|
1052
1554
|
return response.body;
|
|
1053
1555
|
});
|
|
1054
1556
|
}
|
|
1557
|
+
|
|
1055
1558
|
async sendRecoveryFlowSms(query) {
|
|
1056
1559
|
return this.requestWithRetry(async () => {
|
|
1057
1560
|
const response = await this.client.request.send({
|
|
@@ -1067,6 +1570,7 @@ class AccountRepository extends Repository {
|
|
|
1067
1570
|
return response.body;
|
|
1068
1571
|
});
|
|
1069
1572
|
}
|
|
1573
|
+
|
|
1070
1574
|
static generateAttestParams(state) {
|
|
1071
1575
|
// Emulate Instagram's keystore attestation as closely as possible:
|
|
1072
1576
|
// - version: 2
|
|
@@ -1079,28 +1583,65 @@ class AccountRepository extends Repository {
|
|
|
1079
1583
|
//
|
|
1080
1584
|
// NOTE: This is *not* a real hardware-backed attestation chain, but it mirrors
|
|
1081
1585
|
// the structure of the official app very closely so the server sees the same
|
|
1082
|
-
// shape: a single attestation object with a 4
|
|
1083
|
-
const challengeNonce = crypto
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
}
|
|
1586
|
+
// shape: a single attestation object with a 4-certificate chain.
|
|
1587
|
+
const challengeNonce = crypto
|
|
1588
|
+
.randomBytes(24)
|
|
1589
|
+
.toString('base64url');
|
|
1590
|
+
const { privateKey, publicKey } = crypto.generateKeyPairSync(
|
|
1591
|
+
'ec',
|
|
1592
|
+
{
|
|
1593
|
+
namedCurve: 'prime256v1',
|
|
1594
|
+
}
|
|
1595
|
+
);
|
|
1087
1596
|
// Sign the challenge nonce with the private key (simulating TEE signing).
|
|
1088
|
-
const signedData = crypto.sign(
|
|
1597
|
+
const signedData = crypto.sign(
|
|
1598
|
+
null,
|
|
1599
|
+
Buffer.from(challengeNonce),
|
|
1600
|
+
privateKey
|
|
1601
|
+
);
|
|
1089
1602
|
const signedNonce = signedData.toString('base64');
|
|
1090
|
-
const publicKeyDer = publicKey.export({
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
const
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1603
|
+
const publicKeyDer = publicKey.export({
|
|
1604
|
+
type: 'spki',
|
|
1605
|
+
format: 'der',
|
|
1606
|
+
});
|
|
1607
|
+
const keyHash = crypto
|
|
1608
|
+
.createHash('sha256')
|
|
1609
|
+
.update(publicKeyDer)
|
|
1610
|
+
.digest('hex');
|
|
1611
|
+
|
|
1612
|
+
// Build a 4-certificate chain (leaf + 2 intermediates + root)
|
|
1613
|
+
const leafCertPem =
|
|
1614
|
+
AccountRepository._generateSelfSignedCert(
|
|
1615
|
+
privateKey,
|
|
1616
|
+
publicKey,
|
|
1617
|
+
'Android Keystore Key'
|
|
1618
|
+
);
|
|
1619
|
+
const intermediate1Pem =
|
|
1620
|
+
AccountRepository._generateSelfSignedCert(
|
|
1621
|
+
privateKey,
|
|
1622
|
+
publicKey,
|
|
1623
|
+
'Android Keystore Key Attestation'
|
|
1624
|
+
);
|
|
1625
|
+
const intermediate2Pem =
|
|
1626
|
+
AccountRepository._generateSelfSignedCert(
|
|
1627
|
+
privateKey,
|
|
1628
|
+
publicKey,
|
|
1629
|
+
'Android Hardware Keystore'
|
|
1630
|
+
);
|
|
1631
|
+
const rootCertPem =
|
|
1632
|
+
AccountRepository._generateSelfSignedCert(
|
|
1633
|
+
privateKey,
|
|
1634
|
+
publicKey,
|
|
1635
|
+
'Android Keystore Root'
|
|
1636
|
+
);
|
|
1637
|
+
|
|
1098
1638
|
const certificateChain = [
|
|
1099
1639
|
leafCertPem,
|
|
1100
1640
|
intermediate1Pem,
|
|
1101
1641
|
intermediate2Pem,
|
|
1102
1642
|
rootCertPem,
|
|
1103
1643
|
].join('\n');
|
|
1644
|
+
|
|
1104
1645
|
return {
|
|
1105
1646
|
attestation: [
|
|
1106
1647
|
{
|
|
@@ -1115,12 +1656,20 @@ class AccountRepository extends Repository {
|
|
|
1115
1656
|
],
|
|
1116
1657
|
};
|
|
1117
1658
|
}
|
|
1659
|
+
|
|
1118
1660
|
static _generateSelfSignedCert(privateKey, publicKey, cn) {
|
|
1119
|
-
const publicKeyDer = publicKey.export({
|
|
1661
|
+
const publicKeyDer = publicKey.export({
|
|
1662
|
+
type: 'spki',
|
|
1663
|
+
format: 'der',
|
|
1664
|
+
});
|
|
1120
1665
|
const serialNumber = crypto.randomBytes(8);
|
|
1121
1666
|
const now = new Date();
|
|
1122
|
-
const notBefore = new Date(
|
|
1123
|
-
|
|
1667
|
+
const notBefore = new Date(
|
|
1668
|
+
now.getTime() - 365 * 24 * 60 * 60 * 1000
|
|
1669
|
+
);
|
|
1670
|
+
const notAfter = new Date(
|
|
1671
|
+
now.getTime() + 10 * 365 * 24 * 60 * 60 * 1000
|
|
1672
|
+
);
|
|
1124
1673
|
const cnBytes = Buffer.from(cn, 'utf8');
|
|
1125
1674
|
const cnSeq = Buffer.concat([
|
|
1126
1675
|
Buffer.from([0x30, cnBytes.length + 13]),
|
|
@@ -1130,39 +1679,75 @@ class AccountRepository extends Repository {
|
|
|
1130
1679
|
Buffer.from([0x0c, cnBytes.length]),
|
|
1131
1680
|
cnBytes,
|
|
1132
1681
|
]);
|
|
1682
|
+
|
|
1133
1683
|
function encodeTime(date) {
|
|
1134
|
-
const str =
|
|
1135
|
-
|
|
1684
|
+
const str =
|
|
1685
|
+
date
|
|
1686
|
+
.toISOString()
|
|
1687
|
+
.replace(/[-:T]/g, '')
|
|
1688
|
+
.slice(2, 14) + 'Z';
|
|
1689
|
+
return Buffer.concat([
|
|
1690
|
+
Buffer.from([0x17, str.length]),
|
|
1691
|
+
Buffer.from(str),
|
|
1692
|
+
]);
|
|
1136
1693
|
}
|
|
1694
|
+
|
|
1137
1695
|
const validityBuf = Buffer.concat([
|
|
1138
1696
|
encodeTime(notBefore),
|
|
1139
1697
|
encodeTime(notAfter),
|
|
1140
1698
|
]);
|
|
1141
|
-
const validity = Buffer.concat([
|
|
1699
|
+
const validity = Buffer.concat([
|
|
1700
|
+
Buffer.from([0x30, validityBuf.length]),
|
|
1701
|
+
validityBuf,
|
|
1702
|
+
]);
|
|
1703
|
+
|
|
1142
1704
|
const tbs = Buffer.concat([
|
|
1143
1705
|
Buffer.from([0xa0, 0x03, 0x02, 0x01, 0x02]),
|
|
1144
|
-
Buffer.from([0x02, serialNumber.length]),
|
|
1145
|
-
|
|
1706
|
+
Buffer.from([0x02, serialNumber.length]),
|
|
1707
|
+
serialNumber,
|
|
1708
|
+
Buffer.from([
|
|
1709
|
+
0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d,
|
|
1710
|
+
0x04, 0x03, 0x02,
|
|
1711
|
+
]),
|
|
1146
1712
|
cnSeq,
|
|
1147
1713
|
validity,
|
|
1148
1714
|
cnSeq,
|
|
1149
1715
|
publicKeyDer,
|
|
1150
1716
|
]);
|
|
1151
|
-
|
|
1717
|
+
|
|
1718
|
+
const tbsSeq = Buffer.concat([
|
|
1719
|
+
Buffer.from([0x30, 0x82]),
|
|
1720
|
+
Buffer.alloc(2),
|
|
1721
|
+
tbs,
|
|
1722
|
+
]);
|
|
1152
1723
|
tbsSeq.writeUInt16BE(tbs.length, 2);
|
|
1724
|
+
|
|
1153
1725
|
const signature = crypto.sign(null, tbsSeq, privateKey);
|
|
1154
1726
|
const sigBitString = Buffer.concat([
|
|
1155
1727
|
Buffer.from([0x03, signature.length + 1, 0x00]),
|
|
1156
1728
|
signature,
|
|
1157
1729
|
]);
|
|
1158
|
-
const algId = Buffer.from([
|
|
1730
|
+
const algId = Buffer.from([
|
|
1731
|
+
0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d,
|
|
1732
|
+
0x04, 0x03, 0x02,
|
|
1733
|
+
]);
|
|
1159
1734
|
const certBody = Buffer.concat([tbsSeq, algId, sigBitString]);
|
|
1160
|
-
const cert = Buffer.concat([
|
|
1735
|
+
const cert = Buffer.concat([
|
|
1736
|
+
Buffer.from([0x30, 0x82]),
|
|
1737
|
+
Buffer.alloc(2),
|
|
1738
|
+
certBody,
|
|
1739
|
+
]);
|
|
1161
1740
|
cert.writeUInt16BE(certBody.length, 2);
|
|
1741
|
+
|
|
1162
1742
|
const b64 = cert.toString('base64');
|
|
1163
1743
|
const lines = b64.match(/.{1,76}/g) || [b64];
|
|
1164
|
-
return
|
|
1744
|
+
return (
|
|
1745
|
+
'-----BEGIN CERTIFICATE-----\n' +
|
|
1746
|
+
lines.join('\n') +
|
|
1747
|
+
'\n-----END CERTIFICATE-----'
|
|
1748
|
+
);
|
|
1165
1749
|
}
|
|
1750
|
+
|
|
1166
1751
|
static createJazoest(input) {
|
|
1167
1752
|
const buf = Buffer.from(input || '', 'ascii');
|
|
1168
1753
|
let sum = 0;
|
|
@@ -1171,45 +1756,70 @@ class AccountRepository extends Repository {
|
|
|
1171
1756
|
}
|
|
1172
1757
|
return `2${sum}`;
|
|
1173
1758
|
}
|
|
1759
|
+
|
|
1174
1760
|
encryptPassword(password) {
|
|
1175
1761
|
if (!this.client.state.passwordEncryptionPubKey) {
|
|
1176
|
-
return {
|
|
1762
|
+
return {
|
|
1763
|
+
time: Math.floor(Date.now() / 1000).toString(),
|
|
1764
|
+
encrypted: password,
|
|
1765
|
+
};
|
|
1177
1766
|
}
|
|
1178
1767
|
const randKey = crypto.randomBytes(32);
|
|
1179
1768
|
const iv = crypto.randomBytes(12);
|
|
1180
|
-
const rsaEncrypted = crypto.publicEncrypt(
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1769
|
+
const rsaEncrypted = crypto.publicEncrypt(
|
|
1770
|
+
{
|
|
1771
|
+
key: Buffer.from(
|
|
1772
|
+
this.client.state.passwordEncryptionPubKey,
|
|
1773
|
+
'base64'
|
|
1774
|
+
).toString(),
|
|
1775
|
+
padding: crypto.constants.RSA_PKCS1_PADDING,
|
|
1776
|
+
},
|
|
1777
|
+
randKey
|
|
1778
|
+
);
|
|
1779
|
+
const cipher = crypto.createCipheriv(
|
|
1780
|
+
'aes-256-gcm',
|
|
1781
|
+
randKey,
|
|
1782
|
+
iv
|
|
1783
|
+
);
|
|
1185
1784
|
const time = Math.floor(Date.now() / 1000).toString();
|
|
1186
1785
|
cipher.setAAD(Buffer.from(time));
|
|
1187
|
-
const aesEncrypted = Buffer.concat([
|
|
1786
|
+
const aesEncrypted = Buffer.concat([
|
|
1787
|
+
cipher.update(password, 'utf8'),
|
|
1788
|
+
cipher.final(),
|
|
1789
|
+
]);
|
|
1188
1790
|
const sizeBuffer = Buffer.alloc(2, 0);
|
|
1189
1791
|
sizeBuffer.writeInt16LE(rsaEncrypted.byteLength, 0);
|
|
1190
1792
|
const authTag = cipher.getAuthTag();
|
|
1191
1793
|
return {
|
|
1192
1794
|
time,
|
|
1193
1795
|
encrypted: Buffer.concat([
|
|
1194
|
-
Buffer.from([
|
|
1796
|
+
Buffer.from([
|
|
1797
|
+
1,
|
|
1798
|
+
this.client.state.passwordEncryptionKeyId || 0,
|
|
1799
|
+
]),
|
|
1195
1800
|
iv,
|
|
1196
1801
|
sizeBuffer,
|
|
1197
1802
|
rsaEncrypted,
|
|
1198
1803
|
authTag,
|
|
1199
|
-
aesEncrypted
|
|
1200
|
-
]).toString('base64')
|
|
1804
|
+
aesEncrypted,
|
|
1805
|
+
]).toString('base64'),
|
|
1201
1806
|
};
|
|
1202
1807
|
}
|
|
1808
|
+
|
|
1203
1809
|
async passwordPublicKeys() {
|
|
1204
1810
|
const response = await this.client.request.send({
|
|
1205
1811
|
method: 'GET',
|
|
1206
1812
|
url: '/api/v1/qe/sync/',
|
|
1207
1813
|
});
|
|
1208
1814
|
const headers = response.headers || {};
|
|
1209
|
-
const keyId = parseInt(
|
|
1210
|
-
|
|
1815
|
+
const keyId = parseInt(
|
|
1816
|
+
headers['ig-set-password-encryption-key-id'] || '0'
|
|
1817
|
+
);
|
|
1818
|
+
const pubKey =
|
|
1819
|
+
headers['ig-set-password-encryption-pub-key'] || '';
|
|
1211
1820
|
return { keyId, pubKey };
|
|
1212
1821
|
}
|
|
1822
|
+
|
|
1213
1823
|
async setPresenceDisabled(disabled = true) {
|
|
1214
1824
|
return this.requestWithRetry(async () => {
|
|
1215
1825
|
const response = await this.client.request.send({
|
|
@@ -1223,6 +1833,7 @@ class AccountRepository extends Repository {
|
|
|
1223
1833
|
return response.body;
|
|
1224
1834
|
});
|
|
1225
1835
|
}
|
|
1836
|
+
|
|
1226
1837
|
async getCommentFilter() {
|
|
1227
1838
|
return this.requestWithRetry(async () => {
|
|
1228
1839
|
const response = await this.client.request.send({
|
|
@@ -1232,6 +1843,7 @@ class AccountRepository extends Repository {
|
|
|
1232
1843
|
return response.body;
|
|
1233
1844
|
});
|
|
1234
1845
|
}
|
|
1846
|
+
|
|
1235
1847
|
async setCommentFilter(configValue = 0) {
|
|
1236
1848
|
return this.requestWithRetry(async () => {
|
|
1237
1849
|
const response = await this.client.request.send({
|
|
@@ -1245,6 +1857,7 @@ class AccountRepository extends Repository {
|
|
|
1245
1857
|
return response.body;
|
|
1246
1858
|
});
|
|
1247
1859
|
}
|
|
1860
|
+
|
|
1248
1861
|
async pushPreferences(preferences = 'default') {
|
|
1249
1862
|
return this.requestWithRetry(async () => {
|
|
1250
1863
|
const response = await this.client.request.send({
|
|
@@ -1264,4 +1877,5 @@ class AccountRepository extends Repository {
|
|
|
1264
1877
|
});
|
|
1265
1878
|
}
|
|
1266
1879
|
}
|
|
1880
|
+
|
|
1267
1881
|
module.exports = AccountRepository;
|