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W,GACvB,EAAQ,QAAQ,EAClB,EAEI,EAAQ,aAEL,EAAQ,eAMX,EAAG,KAAM,EAAQ,cAAc,GAL/B,EAAW,SAAS,EAAQ,aAAa,aAAa,SAAU,GACzD,GAAK,EAAG,KAAM,EAAQ,aAC7B,IAOF,EAAW,KACT,CACE,IAAK,EAAQ,SACb,KAAM,EAAQ,KACd,YAEF,EAGN,MAEE,EAAO,SAAW,EAAQ,SAC1B,EAAO,KAAO,KAAK,oBAAoB,EAAO,UAC9C,EAAQ,KAAO,UACf,EAAQ,QAAQ,EAEpB,CACF","file":"/npm/mineflayer-alt-auth@1.0.0/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.37.0.\n * Original file: /npm/mineflayer-alt-auth@1.0.0/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","const authenticator = require(\"./auth/Client\");\r\nconst fs = require(\"fs\");\r\nconst uuid = require(\"./auth/uuid\");\r\nconst path = require(\"path\");\r\n\r\nmodule.exports = function authFlow({\r\n  cache = false,\r\n  cacheFile = path.join(process.cwd(), \"./cache.json\"),\r\n  provider,\r\n}) {\r\n  return async function (client, options) {\r\n    // If the cache option is enabled, and the cache is available, load the cache.\r\n    if (cache === true && fs.existsSync(cacheFile)) {\r\n      try {\r\n        options.cacheSession = JSON.parse(fs.readFileSync(cacheFile, \"utf8\"));\r\n      } catch (err) {\r\n        fs.writeFileSync(cacheFile, \"[]\", \"utf-8\");\r\n        options.cacheSession = [];\r\n      }\r\n    }\r\n\r\n    // Assign host and session server based on the provider.\r\n    let host;\r\n    if (provider === \"easymc\") {\r\n      host = \"https://api.easymc.io/v1/token\";\r\n      options.sessionServer = \"https://sessionserver.easymc.io\";\r\n    } else if (provider === \"thealtening\") {\r\n      host = \"http://authserver.thealtening.com\";\r\n      options.sessionServer = \"http://sessionserver.thealtening.com\";\r\n    } else {\r\n      throw new Error(`Provider \"${provider}\" is not supported.`);\r\n    }\r\n\r\n    const authClient = authenticator({ agent: options.agent, host: host });\r\n    options.haveCredentials = !!options.username;\r\n\r\n    if (options.haveCredentials) {\r\n      // make a request to get the case-correct username before connecting.\r\n      const cb = function (err, response, skipWrite) {\r\n        if (err) return client.emit(\"error\", err);\r\n\r\n        // Determine if the response has a selected profile\r\n        const hasSelectedProfile = !!response?.selectedProfile;\r\n\r\n        // Use existing response as session if selectedProfile exists, otherwise create a new session\r\n        const session = hasSelectedProfile\r\n          ? response\r\n          : {\r\n              accessToken: response.session,\r\n              selectedProfile: {\r\n                id: response.uuid.replaceAll(\"-\", \"\"),\r\n                name: response.mcName,\r\n              },\r\n              availableProfile: [\r\n                {\r\n                  id: response.uuid.replaceAll(\"-\", \"\"),\r\n                  name: response.mcName,\r\n                },\r\n              ],\r\n            };\r\n\r\n        if (cache === true && response && !skipWrite) {\r\n          fs.writeFileSync(\r\n            cacheFile,\r\n            JSON.stringify({ ...session, alt: options.username }, null, 4),\r\n            \"utf-8\"\r\n          );\r\n        }\r\n\r\n        // Set client and options properties\r\n        client.session = session;\r\n        client.username = session.selectedProfile.name;\r\n        options.accessToken = session.accessToken;\r\n\r\n        client.emit(\"session\", session);\r\n        options.connect(client);\r\n      };\r\n\r\n      if (options.cacheSession) {\r\n        // If session was cached, validate the session\r\n        if (!options.skipValidation) {\r\n          authClient.validate(options.cacheSession.accessToken, function (err) {\r\n            if (!err) cb(null, options.cacheSession);\r\n          });\r\n        } else {\r\n          // trust that the provided session is a working one\r\n          cb(null, options.cacheSession, true);\r\n        }\r\n      } else {\r\n        //If session was not cached, authenticate the user\r\n        authClient.auth(\r\n          {\r\n            alt: options.username,\r\n            auth: options.auth,\r\n            provider,\r\n          },\r\n          cb\r\n        );\r\n      }\r\n    } else {\r\n      // assume the server is in offline mode and just go for it.\r\n      client.username = options.username;\r\n      client.uuid = uuid.nameToMcOfflineUUID(client.username);\r\n      options.auth = \"offline\";\r\n      options.connect(client);\r\n    }\r\n  };\r\n};\r\n"]}