Files
discord-decomp/sources/modules/remote_auth/useAuthWebsocket.tsx
T
2026-07-27 16:20:00 +03:00

473 lines
20 KiB
TypeScript

/* Metro module 14347; source: modules/remote_auth/useAuthWebsocket.tsx; dependencies: [5, 57, 31, 661, 3, 14346, 561, 8994, 12494, 14348, 1239, 507, 5076, 14350, 2] */
function _fun108566(global, require, importDefault, importAll, module, exports, dependencyMap) { // fn#108566, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:14544:6, offset: 0x02325ff8, size: 225 bytes, params: 8, frame: 19
const env0_0 = require;
const Object = global.Object;
Object.defineProperty(exports, '__esModule', {value: true});
const env0_3 = importDefault(5) /* metro dependency 5 */;
const env0_4 = importDefault(57) /* metro dependency 57 */;
const env0_5 = importAll(31) /* metro dependency 31 */;
let value = require(661) /* metro dependency 661: Constants */;
const env0_6 = value.ComponentActions;
const env0_7 = value.Endpoints;
value = importDefault(3) /* metro dependency 3: Logger */;
value = new value('useAuthWebsocket');
(require(2) /* metro dependency 2 */).fileFinishedImporting('modules/remote_auth/useAuthWebsocket.tsx');
exports.useAuthWebsocket = useAuthWebsocket;
}
function useAuthWebsocket(a0, a1) { // fn#108567, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:14544:308, offset: 0x023260d9, size: 424 bytes, params: 3, frame: 28
let value = a2;
const env0_0 = a0;
const env0_1 = a1;
const r6 = value !== undefined ? value : false;
const env0_4 = undefined;
const env0_5 = undefined;
const binding = env0_5;
let useState = binding.useState;
const value2 = Reflect.apply(useState, binding, [0]);
const binding2 = env0_4;
const value3 = binding2(value2, 2);
const property = value3[0];
const env0_3 = value3[1];
useState = binding.useState;
const value4 = binding2(Reflect.apply(useState, binding, [false]), 2);
const property2 = value4[0];
const property3 = value4[1];
useState = binding.useState;
const RemoteAuthStep = (require(14346) /* metro dependency 14346: typing */).RemoteAuthStep;
const INITIALIZING = RemoteAuthStep.INITIALIZING;
const value5 = binding2(Reflect.apply(useState, binding, [{step: INITIALIZING}]), 2);
const property4 = value5[0];
const env0_7 = value5[1];
const env0_8 = binding.useRef(null);
const value6 = binding.useMemo(_fun108568, []);
value = importDefault(8994) /* metro dependency 8994: useStableCallback */;
value = value(_fun108569);
const value7 = binding.useCallback(_fun108571, [value, value6]);
binding.useEffect(_fun108572, [property4, a1, property2, property3]);
binding.useEffect(_fun108574, [value, a0, property, value6, value7, r6]);
return {state: property4, cancel: value};
}
function _fun108568() { // fn#108568, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:14544:537, offset: 0x02326281, size: 59 bytes, params: 1, frame: 13
let value = environment.__proto__;
value = importDefault(561) /* metro dependency 561: Backoff */;
const value2 = Object.create(value.prototype, {constructor: {value: value}});
value = new value(1500, 30000);
return value instanceof Object ? value : value2;
}
function _fun108569() { // fn#108569, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:14544:582, offset: 0x023262bc, size: 117 bytes, params: 1, frame: 15
const binding = env0_7;
const RemoteAuthStep = (require(14346) /* metro dependency 14346: typing */).RemoteAuthStep;
const INITIALIZING = RemoteAuthStep.INITIALIZING;
binding({step: INITIALIZING});
if (require) {
env0_3(function(a0) {
return a0 + 1;
});
} else {
env1_8.info('document is not visible, will defer reconnection when document becomes visible.');
env0_5(true);
}
}
function _fun108571() { // fn#108571, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:14544:765, offset: 0x02326331, size: 110 bytes, params: 1, frame: 14
let binding = env1_8;
binding.error('Could not complete Remote Auth login, trying to restart with a new Remote Auth session.');
binding = env0_7;
const RemoteAuthStep = (require(14346) /* metro dependency 14346: typing */).RemoteAuthStep;
const INITIALIZING = RemoteAuthStep.INITIALIZING;
binding({step: INITIALIZING});
if (!env0_9.pending) {
env0_9.fail(env0_10);
}
}
function _fun108572() { // fn#108572, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:14544:965, offset: 0x0232639f, size: 130 bytes, params: 1, frame: 14
var environment;
var binding;
var value4;
if (require && env0_4 && env0_6.step === (require(14346) /* metro dependency 14346: typing */).RemoteAuthStep.INITIALIZING) {
value4 = environment.__proto__;
binding = env1_8;
binding.info('reconnecting, now that document is visible');
env0_5(false);
binding = env0_3;
binding(function(a0) {
return a0 + 1;
});
}
}
function _fun108574() { // fn#108574, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:14544:1121, offset: 0x02326421, size: 377 bytes, params: 1, frame: 17
var environment;
const Date = global.Date;
const env0_0 = Date.now();
const GLOBAL_ENV = global.window.GLOBAL_ENV;
const REMOTE_AUTH_ENDPOINT = GLOBAL_ENV.REMOTE_AUTH_ENDPOINT;
let value = '' + REMOTE_AUTH_ENDPOINT + '/?v=2';
const r7 = value.startsWith('//') ? 'wss:' + value : value;
value = environment.__proto__;
const value2 = (importDefault(12494) /* metro dependency 12494: createWebSocketAndroid */)(r7);
env1_8.info('[0ms] connecting to ' + r7);
value = _fun108579();
const value3 = _fun108589();
const closure = onclose;
const closure2 = onerror_108594;
value2.addEventListener('open', value3);
value2.addEventListener('message', value);
value2.addEventListener('close', closure);
value2.addEventListener('error', closure2);
return _fun108595;
}
function getKeyPair() { // fn#108575, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:14544:1381, offset: 0x0232659a, size: 55 bytes, params: 1, frame: 12
if (env0_4 != null) {
return env0_4;
}
const Error = global.Error;
throw new Error('No key pair set');
}
function _fmt(a0) { // fn#108576, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:14544:1148, offset: 0x023265d1, size: 69 bytes, params: 2, frame: 15
const Date = global.Date;
let value = Date.now();
value -= env0_0;
return '[' + (value + 'ms') + '] ' + a0;
}
function info_108577(a0) { // fn#108577, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:14544:1186, offset: 0x02326616, size: 37 bytes, params: 2, frame: 13
const binding = env2_8;
return binding.info(_fmt(a0));
}
function doHeartbeat() { // fn#108578, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:14544:1474, offset: 0x0232663b, size: 108 bytes, params: 1, frame: 14
var binding;
var send;
var JSON;
if (env0_8) {
binding = env0_3;
send = binding.send;
JSON = global.JSON;
Reflect.apply(send, binding, [JSON.stringify({op: 'heartbeat'})]);
} else {
info_108577('heartbeat timeout, reconnecting.');
env0_3.close();
value = environment.__proto__;
env1_11();
}
}
function _fun108579() { // fn#108579, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:14544:1589, offset: 0x023266a7, size: 36 bytes, params: 1, frame: 12
const env0_0 = env2_3(_fun108581);
return _fun108588;
}
function _fun108589() { // fn#108589, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:14544:3489, offset: 0x02326cc7, size: 36 bytes, params: 1, frame: 12
const env0_0 = env2_3(_fun108591);
return _fun108592;
}
function onclose({code, reason}) { // fn#108593, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:14544:3830, offset: 0x02326e0c, size: 73 bytes, params: 2, frame: 16
info_108577('disconnected, code: ' + code + ' ' + reason);
value = environment.__proto__;
env1_11();
}
function onerror_108594(a0) { // fn#108594, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:14544:3897, offset: 0x02326e55, size: 71 bytes, params: 2, frame: 13
const info_108577Binding = info_108577;
const JSON = global.JSON;
let value = JSON.stringify(a0);
value = 'disconnected, error: ' + value;
info_108577Binding(value);
value = environment.__proto__;
env1_11();
}
function _fun108595() { // fn#108595, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:14544:4096, offset: 0x02326e9c, size: 241 bytes, params: 1, frame: 15
info_108577('cleaning up');
let binding = env0_3;
binding.removeEventListener('open', env0_11);
env0_3.removeEventListener('message', env0_10);
binding = env0_3;
binding.removeEventListener('close', onclose);
binding = env0_3;
binding.removeEventListener('error', onerror_108594);
env0_3.close(1000);
env1_9.cancel();
(importDefault(14348) /* metro dependency 14348: RemoteAuthCryptoAndroid */).release();
if (env0_7 != null) {
global.clearTimeout(env0_7);
}
if (env0_6 != null) {
global.clearInterval(env0_6);
}
}
async function _fun108581({data}) { // fn#108581, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:14544:1609, offset: 0x023266df, size: 1134 bytes, params: 2, frame: 24
var environment;
var binding;
var value4;
var heartbeat_interval;
var setTimeout;
var Math;
var floor;
var Math2;
var value5;
var binding2;
var ComponentDispatch;
var value6;
var encrypted_user_payload;
var value8;
var object2;
var ticket;
var binding3;
var value9;
var value10;
var binding4;
var value11;
var publicKeyFingerprint;
var value12;
var value13;
var Error;
var encrypted_nonce;
var decryptNonce;
var value16;
var send;
if (true) {
await undefined;
if (false) {
return undefined;
}
var JSON = global.JSON;
var op = JSON.parse(data).op;
if (op === 'nonce_proof') {
encrypted_nonce = value.encrypted_nonce;
value = environment.__proto__.__proto__.__proto__.__proto__;
binding = env4_1;
value = binding(env4_2[9]);
decryptNonce = value.decryptNonce;
value16 = environment.__proto__.__proto__;
await Reflect.apply(decryptNonce, value, [env2_14(), encrypted_nonce]);
value = undefined;
if (false) {
return value;
}
env2_2('computed nonce proof');
binding = env2_3;
send = binding.send;
JSON = global.JSON;
Reflect.apply(send, binding, [JSON.stringify({op: 'nonce_proof', nonce: value})]);
} else {
if (op === 'pending_remote_init') {
value9 = environment.__proto__.__proto__.__proto__;
binding = env3_9;
binding.succeed();
value10 = environment.__proto__.__proto__.__proto__.__proto__;
binding = env4_0;
binding4 = env4_2;
ComponentDispatch = binding(binding4[10]).ComponentDispatch;
ComponentDispatch.dispatch(env4_6.WAVE_EMPHASIZE);
binding = env4_1;
value11 = binding(binding4[9]);
publicKeyFingerprint = value11.publicKeyFingerprint;
value12 = environment.__proto__.__proto__;
await Reflect.apply(publicKeyFingerprint, value11, [env2_14()]);
value13 = undefined;
if (false) {
return value13;
}
if (value13 !== value.fingerprint) {
Error = global.Error;
value = 'bad fingerprint ' + value13 + ' !== ' + value.fingerprint;
throw new Error(value);
}
env2_2('handshake complete awaiting remote auth.');
object2 = {};
binding = env4_0;
object2.step = binding(env4_2[5]).RemoteAuthStep.PENDING_REMOTE_INIT;
object2.fingerprint = value13;
Endpoints(object2);
return undefined;
}
if (op === 'pending_login') {
ticket = value.ticket;
if (ticket == null) {
value = environment.__proto__.__proto__.__proto__;
env3_11();
} else {
value = environment.__proto__.__proto__.__proto__;
object2 = {};
value = environment.__proto__.__proto__.__proto__.__proto__;
binding = env4_0;
binding3 = env4_2;
object2.step = binding(binding3[5]).RemoteAuthStep.PENDING_LOGIN;
object2.ticket = ticket;
Endpoints(object2);
value = binding(binding3[11]).HTTP.post({url: env4_7.REMOTE_AUTH_LOGIN, body: {ticket: ticket},
oldFormErrors: true,
rejectWithError: true});
value = value.then(_fun108582());
value.catch(_fun108586);
}
return undefined;
}
if (op === 'pending_ticket') {
value5 = environment.__proto__.__proto__.__proto__.__proto__;
binding = env4_0;
binding2 = env4_2;
ComponentDispatch = binding(binding2[10]).ComponentDispatch;
ComponentDispatch.dispatch(env4_6.WAVE_EMPHASIZE);
value6 = environment.__proto__.__proto__;
env2_2('remote auth handshake started, awaiting ticket/cancel.');
encrypted_user_payload = value.encrypted_user_payload;
value = binding(binding2[13]);
await value.decodeEncodedUserRecord(env2_14(), encrypted_user_payload);
value = undefined;
if (false) {
return value;
}
value8 = environment.__proto__.__proto__.__proto__;
object2 = {};
binding = env4_0;
object2.step = binding(env4_2[5]).RemoteAuthStep.PENDING_TICKET;
object2.user = value;
Endpoints(object2);
return undefined;
}
if (op === 'cancel') {
value = environment.__proto__.__proto__;
env2_2('remote auth handshake cancelled.');
value = environment.__proto__.__proto__.__proto__;
env3_10();
return undefined;
}
if (op === 'hello') {
value4 = environment.__proto__.__proto__;
env2_2('got hello, auth timeout=' + value.timeout_ms + 'ms');
heartbeat_interval = value.heartbeat_interval;
setTimeout = global.setTimeout;
Math = global.Math;
floor = Math.floor;
Math2 = global.Math;
value = Reflect.apply(floor, Math, [heartbeat_interval * Math2.random()]);
env2_7 = setTimeout(_fun108587, value);
return undefined;
}
if (op === 'heartbeat_ack') {
value = environment.__proto__.__proto__;
return undefined;
}
value = environment.__proto__.__proto__.__proto__.__proto__;
binding = env4_8;
var warn = binding.warn;
value = environment.__proto__.__proto__;
Reflect.apply(warn, binding, [require('received unsupported message')]);
}
}
}
function* _fun108591() { // fn#108591, original name: ?anon_0_, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:14544:3509, offset: 0x02326cf6, size: 278 bytes, params: 1, frame: 20
if (true) {
value = environment.__proto__.__proto__.__proto__.__proto__;
var binding = env4_1;
var value3 = binding(env4_2[9]);
yield value3.generateRsaKeyPair();
var value4 = undefined;
if (false) {
return value4;
}
env2_4 = value4;
var value7 = env4_1(env4_2[9]);
yield value7.serializePublicKey(env2_4);
var value8 = undefined;
if (false) {
return value8;
}
env2_5 = value8;
value = env4_1(env4_2[9]);
yield value.publicKeyFingerprint(env2_4);
value = undefined;
if (false) {
return value;
}
env2_2('connected, handshaking with fingerprint: ' + value);
binding = env2_3;
var send = binding.send;
var JSON = global.JSON;
Reflect.apply(send, binding, [JSON.stringify({op: 'init', encoded_public_key: env2_5})]);
value = environment.__proto__.__proto__.__proto__;
env3_8.current = env2_4;
}
}
function _fun108582() { // fn#108582, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:14544:2426, offset: 0x02326b4d, size: 36 bytes, params: 1, frame: 12
const env0_0 = env5_3(_fun108584);
return _fun108585;
}
function _fun108586() { // fn#108586, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:14544:2759, offset: 0x02326c86, size: 15 bytes, params: 1, frame: 9
return env4_11();
}
function _fun108587() { // fn#108587, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:14544:3248, offset: 0x02326c95, size: 50 bytes, params: 1, frame: 14
env3_9();
env3_6 = global.setInterval(env3_9, heartbeat_interval);
}
function* _fun108584(a0) { // fn#108584, original name: ?anon_0_, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:14544:2446, offset: 0x02326b7c, size: 266 bytes, params: 2, frame: 18
var value3;
var binding;
var value4;
var decryptEncodedCiphertext;
var value5;
var value7;
var publicKeyFingerprint;
var value8;
var value10;
if (true) {
value = environment.__proto__.__proto__.__proto__.__proto__.__proto__.__proto__;
var current = env6_8.current;
if (current != null) {
value3 = environment.__proto__.__proto__.__proto__.__proto__.__proto__.__proto__.__proto__;
binding = env7_1;
value4 = binding(env7_2[9]);
decryptEncodedCiphertext = value4.decryptEncodedCiphertext;
current = env6_8.current;
yield Reflect.apply(decryptEncodedCiphertext, value4, [current, a0.body.encrypted_token]);
value5 = undefined;
if (false) {
return value5;
}
binding = env7_1;
value7 = binding(env7_2[9]);
publicKeyFingerprint = value7.publicKeyFingerprint;
current = env6_8.current;
yield Reflect.apply(publicKeyFingerprint, value7, [current]);
value8 = undefined;
if (false) {
return value8;
}
binding = env6_2;
value10 = env7_1(env7_2[12]);
if (binding) {
yield value10.switchAccountToken(value5);
if (false) {
return undefined;
}
env6_0(value8);
return undefined;
}
yield value10.loginToken(value5, false);
if (false) {
return undefined;
}
env6_0(value8);
} else {
env6_11();
}
}
}