From dbacc497566e583d1f89348bb6e4d4ed135c7f59 Mon Sep 17 00:00:00 2001 From: Matix-Media Date: Fri, 24 Mar 2023 12:31:21 +0100 Subject: [PATCH 1/3] refactor: :pencil2: updated types and classes to uppercase --- package.json | 2 +- src/assets.ts | 144 ++++++++++++++-------------- src/auth/auth.ts | 216 +++++++++++++++++++++++------------------- src/auth/minecraft.ts | 161 ++++++++++++++++++------------- src/auth/social.ts | 37 ++++---- src/auth/xbox.ts | 117 ++++++++++++----------- src/gui/electron.ts | 22 +++-- src/gui/nwjs.ts | 19 ++-- src/gui/raw.ts | 167 ++++++++++++++++++++------------ src/index.ts | 16 ++-- 10 files changed, 497 insertions(+), 404 deletions(-) diff --git a/package.json b/package.json index 774a2de..66a994d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "msmc", - "version": "4.0.6", + "version": "4.1.0", "description": "A bare bones login library for Minecraft based projects to authenticate individuals with a Microsoft account.", "license": "MIT", "exports": { diff --git a/src/assets.ts b/src/assets.ts index 81c4834..053a64b 100644 --- a/src/assets.ts +++ b/src/assets.ts @@ -1,31 +1,34 @@ import { readFileSync } from "fs"; -import type { Response } from "node-fetch" +import type { Response } from "node-fetch"; import { join } from "path"; -import { mcToken } from "./auth/minecraft"; +import { MCToken } from "./auth/minecraft"; /** * A copy of the user object mclc uses */ -export type mclcUser = { +export type MclcUser = { access_token: string; client_token?: string; uuid: string; name?: string; meta?: { - refresh: string; exp?: number, type: "mojang" | "msa" | "legacy", xuid?: string, demo?: boolean + refresh: string; + exp?: number; + type: "mojang" | "msa" | "legacy"; + xuid?: string; + demo?: boolean; }; user_properties?: Partial; -} - +}; /** - * If the exact code isn't founnd. The lexicon string is split up and shaved down till it finds a description for the code. - * - * For example; error.auth.microsoft will be shortend to error.auth if error.auth.microsoft isn't found + * If the exact code isn't founnd. The lexicon string is split up and shaved down till it finds a description for the code. + * + * For example; error.auth.microsoft will be shortend to error.auth if error.auth.microsoft isn't found */ export let lexicon = { //Error - "error": "An unknown error has occurred", + error: "An unknown error has occurred", "error.auth": "An unknown authentication error has occurred", "error.auth.microsoft": "Failed to login to Microsoft account", "error.auth.xboxLive": "Failed to login to Xbox Live", @@ -50,7 +53,7 @@ export let lexicon = { "error.state.invalid.redirect": "[Internal]: The token must have a redirect starting with 'http://localhost/' for this function to work!", "error.state.invalid.electron": "[Internal]: It seems you're attempting to load electron on the frontend. A critical function is missing!", //Load events - "load": "Generic load event", + load: "Generic load event", "load.auth": "Generic authentication load event", "load.auth.microsoft": "Logging into Microsoft account", "load.auth.xboxLive": "Logging into Xbox Live", @@ -63,42 +66,43 @@ export let lexicon = { "load.auth.minecraft.profile": "Fetching player profile", "load.auth.minecraft.gamepass": "[experimental!] Checking if a user has gamepass", //Gui components - "gui": "Gui component", + gui: "Gui component", "gui.title": "Sign in to your account", - "gui.market": "en-US" -} + "gui.market": "en-US", +}; -export type lexcodes = keyof typeof lexicon; +export type Lexcodes = keyof typeof lexicon; -export function lst(lexcodes: lexcodes) { +export function lst(lexcodes: Lexcodes) { const lex = lexcodes.split("."); do { - const l = lex.join('.'); - if (l in lexicon) { return lexicon[l]; } + const l = lex.join("."); + if (l in lexicon) { + return lexicon[l]; + } lex.pop(); - } while (lex.length > 0) + } while (lex.length > 0); return lexcodes; } -export interface exptOpts { - ts: lexcodes; +export interface ExptOpts { + ts: Lexcodes; response: Response; } -export function err(ts: lexcodes) { +export function err(ts: Lexcodes) { throw ts; } -export function errResponse(response: Response, ts: lexcodes) { - if (!response.ok) throw { response, ts } +export function errResponse(response: Response, ts: Lexcodes) { + if (!response.ok) throw { response, ts }; } -export function wrapError(code: string | exptOpts | any) { - let name: lexcodes; - let opt: exptOpts | null; - if (typeof code == 'string') { - name = code as lexcodes; - } - else { +export function wrapError(code: string | ExptOpts | any) { + let name: Lexcodes; + let opt: ExptOpts | null; + if (typeof code == "string") { + name = code as Lexcodes; + } else { opt = code; name = opt.ts; } @@ -109,64 +113,60 @@ export function wrapError(code: string | exptOpts | any) { /** * Used by graphical Electron and NW.js integrations to set the properties of the generated pop-up */ -export interface windowProperties { - width: number, - height: number, +export interface WindowProperties { + width: number; + height: number; /**Raw ignores this property!*/ - resizable?: boolean, + resizable?: boolean; /**Raw only: Stops MSMC from passing through the browser console log*/ - suppress?: boolean, - [key: string]: any + suppress?: boolean; + [key: string]: any; } -export interface mcProfile { - id: string, - name: string, - skins?: Array< - { - id: string, - state: 'ACTIVE', - url: string, - variant: 'SLIM' | 'CLASSIC' - } - >, - capes?: Array< - { - id: string, - state: 'ACTIVE', - url: string, - alias: string - } - >, - demo?: boolean +export interface MCProfile { + id: string; + name: string; + skins?: Array<{ + id: string; + state: "ACTIVE"; + url: string; + variant: "SLIM" | "CLASSIC"; + }>; + capes?: Array<{ + id: string; + state: "ACTIVE"; + url: string; + alias: string; + }>; + demo?: boolean; } -export interface gmllUser { +export interface GmllUser { profile: { - id: string, - name: string, - xuid?: string, - type?: "mojang" | "msa" | "legacy", - demo?: boolean, + id: string; + name: string; + xuid?: string; + type?: "mojang" | "msa" | "legacy"; + demo?: boolean; properties?: { //We're still reverse engineering what this property is used for... //This likely does not work anymore... - twitch_access_token: string - } - }, - access_token?: string + twitch_access_token: string; + }; + }; + access_token?: string; } -export function getDefaultWinProperties(): windowProperties { +export function getDefaultWinProperties(): WindowProperties { return { width: 500, height: 650, resizable: false, - title: lst("gui.title") + title: lst("gui.title"), }; } export function loadLexiPack(...file: string[]): typeof lexicon { const pack: typeof lexicon = JSON.parse(readFileSync(join(...file)).toString()); - lexicon = pack - return pack -} \ No newline at end of file + lexicon = pack; + return pack; +} diff --git a/src/auth/auth.ts b/src/auth/auth.ts index dc99358..f4b4b1d 100644 --- a/src/auth/auth.ts +++ b/src/auth/auth.ts @@ -1,83 +1,82 @@ import EventEmitter from "events"; import fetch from "node-fetch"; -import { lexcodes, windowProperties, lst, errResponse, err } from "../assets.js"; -import type xbox from "./xbox.js"; -import type { Server } from "http" +import { Lexcodes, WindowProperties, lst, errResponse, err } from "../assets.js"; +import type Xbox from "./xbox.js"; +import type { Server } from "http"; /** - * This library's supported gui frameworks. + * This library's supported gui frameworks. * (Raw requires no extra dependencies, use it if you're using some unknown framework!) */ -export type framework = "electron" | "nwjs" | "raw"; +export type Framework = "electron" | "nwjs" | "raw"; /** * For more information. Check out Microsoft's support page: https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow#request-an-authorization-code
- * + * * Basically this is the prompt value in the request sent to Microsoft. This should only be important if you're using either the fastLaunch or launch functions under either Electron or NW.js */ -export type prompt = "login" | "none" | "consent" | "select_account"; +export type Prompt = "login" | "none" | "consent" | "select_account"; /** - * The Oauth2 details needed to log you in. - * + * The Oauth2 details needed to log you in. + * * Resources * 1) https://docs.microsoft.com/en-us/graph/auth-register-app-v2 * 2) https://docs.microsoft.com/en-us/graph/auth-v2-user#1-register-your-app * 3) https://portal.azure.com/#blade/Microsoft_AAD_IAM/ActiveDirectoryMenuBlade/RegisteredApps - * + * */ -export interface MStoken { - client_id: string, - redirect: string, - clientSecret?: string, - prompt?: prompt +export interface MSToken { + client_id: string; + redirect: string; + clientSecret?: string; + prompt?: Prompt; } -export interface msAuthToken { - token_type: string, - expires_in: number, - scope: string, - access_token: string, - refresh_token: string, - user_id: string, - foci: string +export interface MSAuthToken { + token_type: string; + expires_in: number; + scope: string; + access_token: string; + refresh_token: string; + user_id: string; + foci: string; } - -function mojangAuthToken(prompt?: prompt) { +function mojangAuthToken(prompt?: Prompt) { const token = { client_id: "00000000402b5328", redirect: "https://login.live.com/oauth20_desktop.srf", - prompt: prompt - } + prompt: prompt, + }; return token; } -export class loader { - auth: auth - constructor(auth: auth) { +export class Loader { + auth: Auth; + constructor(auth: Auth) { this.auth = auth; } - load(code: lexcodes) { + load(code: Lexcodes) { this.auth.emit("load", code); } } -export declare interface auth extends EventEmitter { - on(event: "load", listener: (asset: lexcodes, message: string) => void): this - once(event: "load", listener: (asset: lexcodes, message: string) => void): this - emit(event: "load", asset: lexcodes): boolean; +export declare interface Auth extends EventEmitter { + on(event: "load", listener: (asset: Lexcodes, message: string) => void): this; + once(event: "load", listener: (asset: Lexcodes, message: string) => void): this; + emit(event: "load", asset: Lexcodes): boolean; } -export class auth extends EventEmitter { - token: MStoken; +export class Auth extends EventEmitter { + token: MSToken; private app: Server; - constructor(prompt?: prompt) - constructor(token: MStoken) - constructor(token?: MStoken | prompt) { + constructor(prompt?: Prompt); + constructor(token: MSToken); + constructor(token?: MSToken | Prompt) { super(); if (!token) - console.warn("[MSMC]: Just a note. No prompt variable was specified. Assuming value to be 'login' to remain consistent with older releases") - this.token = (!token || typeof token == "string") ? mojangAuthToken(token as prompt || "login") : token; - - + console.warn( + "[MSMC]: Just a note. No prompt variable was specified. Assuming value to be 'login' to remain consistent with older releases", + ); + this.token = !token || typeof token == "string" ? mojangAuthToken((token as Prompt) || "login") : token; } createLink(redirect?: string) { return ( @@ -85,133 +84,150 @@ export class auth extends EventEmitter { "?client_id=" + this.token.client_id + "&response_type=code" + - "&redirect_uri=" + encodeURIComponent(redirect ? redirect : this.token.redirect) + + "&redirect_uri=" + + encodeURIComponent(redirect ? redirect : this.token.redirect) + "&scope=XboxLive.signin%20offline_access" + (this.token.prompt ? "&prompt=" + this.token.prompt : "") + - "&mkt=" + lst('gui.market') + "&mkt=" + + lst("gui.market") ); } emit(eventName: string | symbol, ...args: any[]): boolean { - return super.emit(eventName, args[0], lst(args[0])) + return super.emit(eventName, args[0], lst(args[0])); } - load(code: lexcodes) { + load(code: Lexcodes) { this.emit("load", code); } login(code: string, redirect?: string) { - const body = ( - "client_id=" + this.token.client_id + + const body = + "client_id=" + + this.token.client_id + (this.token.clientSecret ? "&client_secret=" + this.token.clientSecret : "") + - "&code=" + code + + "&code=" + + code + "&grant_type=authorization_code" + - "&redirect_uri=" + (redirect ? redirect : this.token.redirect)) + "&redirect_uri=" + + (redirect ? redirect : this.token.redirect); return this._get(body); } - refresh(MS: msAuthToken): Promise - refresh(refreshToken: string): Promise - refresh(MS: msAuthToken | string) { - const refresh = typeof MS == 'string' ? MS : MS.refresh_token; - const body = ( - "client_id=" + this.token.client_id + + refresh(MS: MSAuthToken): Promise; + refresh(refreshToken: string): Promise; + refresh(MS: MSAuthToken | string) { + const refresh = typeof MS == "string" ? MS : MS.refresh_token; + const body = + "client_id=" + + this.token.client_id + (this.token.clientSecret ? "&client_secret=" + this.token.clientSecret : "") + - "&refresh_token=" + refresh + - "&grant_type=refresh_token") - return this._get(body) + "&refresh_token=" + + refresh + + "&grant_type=refresh_token"; + return this._get(body); } - async launch(framework: framework, windowProperties?: windowProperties) { + async launch(framework: Framework, windowProperties?: WindowProperties) { switch (framework) { case "raw": - return await this.login(await (require("../gui/raw.js")).default(this, windowProperties)) + return await this.login(await require("../gui/raw.js").default(this, windowProperties)); case "nwjs": - return await this.login(await (require("../gui/nwjs.js")).default(this, windowProperties)) + return await this.login(await require("../gui/nwjs.js").default(this, windowProperties)); case "electron": - return await this.login(await (require("../gui/electron.js")).default(this, windowProperties)) + return await this.login(await require("../gui/electron.js").default(this, windowProperties)); default: - err('error.state.invalid.gui') + err("error.state.invalid.gui"); } } /** - * Used for a console like login experience. - * @param callback - * @param port - * @returns + * Used for a console like login experience. + * @param callback + * @param port + * @returns */ - setServer(callback: (xbox: xbox) => void, redirect: string = "Thank you!", port = 0): Promise<{ link: string, port: number, server: Server, auth: auth }> { - if (typeof redirect == "number") - port = redirect; + setServer( + callback: (xbox: Xbox) => void, + redirect: string = "Thank you!", + port = 0, + ): Promise<{ link: string; port: number; server: Server; auth: Auth }> { + if (typeof redirect == "number") port = redirect; return new Promise(async (suc, err) => { let http: typeof import("http"); - try { http = await import("http"); } - catch (er) { err("error.state.invalid.http"); } - if (this.token.redirect.startsWith('http://localhost/')) err("error.state.invalid.redirect"); - try { if (this.app) { this.app.close(); } } catch { /*Ignore*/ } + try { + http = await import("http"); + } catch (er) { + err("error.state.invalid.http"); + } + if (this.token.redirect.startsWith("http://localhost/")) err("error.state.invalid.redirect"); + try { + if (this.app) { + this.app.close(); + } + } catch { + /*Ignore*/ + } this.app = http.createServer(async (req, res) => { const lnk = `http://localhost:${req.socket.localPort}`; if (req.url.startsWith(`/link`)) { res.writeHead(302, { - 'Location': this.createLink(lnk) + Location: this.createLink(lnk), }); return res.end(); } if (typeof redirect == "string" && redirect.startsWith("http")) { - res.writeHead(302, { "Location": redirect }); + res.writeHead(302, { Location: redirect }); res.end(); - } - else { + } else { res.writeHead(200, { "Content-Type": "text/plain" }); res.end("Thank you!"); } if (req.url.includes("?")) { const code = new URLSearchParams(req.url.substr(req.url.indexOf("?") + 1)).get("code"); - console.log(code) + console.log(code); try { callback(await this.login(code, lnk)); } catch (e) { - console.error(e) + console.error(e); } } }); this.app.on("listening", () => { let f: { port: number } | string = this.app.address(); if (typeof f == "string") f = { port }; - console.log(`Use 'http://localhost:${f.port || port}/link' to automatically get redirected`) - suc({ link: `http://localhost:${f.port || port}/link`, port: f.port || port, server: this.app, auth: this }) - - }) + console.log(`Use 'http://localhost:${f.port || port}/link' to automatically get redirected`); + suc({ link: `http://localhost:${f.port || port}/link`, port: f.port || port, server: this.app, auth: this }); + }); this.app.listen(port); - }) + }); } - private async _get(body: string): Promise { - this.load('load.auth.microsoft') + private async _get(body: string): Promise { + this.load("load.auth.microsoft"); var MS_Raw = await fetch("https://login.live.com/oauth20_token.srf", { - method: "post", body: body, headers: { "Content-Type": "application/x-www-form-urlencoded" } - }) + method: "post", + body: body, + headers: { "Content-Type": "application/x-www-form-urlencoded" }, + }); // console.log(await MS_Raw.text()) - errResponse(MS_Raw, "error.auth.microsoft") + errResponse(MS_Raw, "error.auth.microsoft"); var MS = await MS_Raw.json(); - this.load('load.auth.xboxLive.1') + this.load("load.auth.xboxLive.1"); var rxboxlive = await fetch("https://user.auth.xboxlive.com/user/authenticate", { method: "post", body: JSON.stringify({ Properties: { AuthMethod: "RPS", SiteName: "user.auth.xboxlive.com", - RpsTicket: `d=${MS.access_token}` // your access token from step 2 here + RpsTicket: `d=${MS.access_token}`, // your access token from step 2 here }, RelyingParty: "http://auth.xboxlive.com", - TokenType: "JWT" + TokenType: "JWT", }), headers: { "Content-Type": "application/json", Accept: "application/json" }, }); - errResponse(rxboxlive, "error.auth.xboxLive") + errResponse(rxboxlive, "error.auth.xboxLive"); var token = await rxboxlive.json(); return new (require("./xbox.js").default)(this, MS, token); } } -export default auth; - - +export default Auth; diff --git a/src/auth/minecraft.ts b/src/auth/minecraft.ts index 8c47fc2..6f12338 100644 --- a/src/auth/minecraft.ts +++ b/src/auth/minecraft.ts @@ -1,79 +1,103 @@ import fetch from "node-fetch"; -import { errResponse, gmllUser, mclcUser, mcProfile } from "../assets.js"; -import xbox from "./xbox.js"; -import { auth } from "./auth.js" -export interface mcJWTDecoded { xuid: string, agg: string, sub: string, nbf: number, auth: string, roles: [], iss: string, exp: number, iat: number, platform: string, yuid: string } -export type entitlements = "game_minecraft" | "game_minecraft_bedrock" | "game_dungeons" | "product_minecraft" | "product_minecraft_bedrock" | "product_dungeons" -export interface mcToken { +import { errResponse, GmllUser, MclcUser, MCProfile } from "../assets.js"; +import Xbox from "./xbox.js"; +import { Auth } from "./auth.js"; +export interface MCJWTDecoded { + xuid: string; + agg: string; + sub: string; + nbf: number; + auth: string; + roles: []; + iss: string; + exp: number; + iat: number; + platform: string; + yuid: string; +} +export type Entitlements = + | "game_minecraft" + | "game_minecraft_bedrock" + | "game_dungeons" + | "product_minecraft" + | "product_minecraft_bedrock" + | "product_dungeons"; +export interface MCToken { refresh?: string; mcToken: string; - profile: mcProfile; + profile: MCProfile; xuid: string; exp: number; } /**Validates MC tokens to check if they're valid. */ -export function validate(token: mcToken | minecraft | mclcUser) { - if ("exp" in token) - return (typeof token.exp == "number" && token.exp > Date.now()); - else if ("meta" in token && "exp" in token.meta) - return (typeof token.meta.exp == "number" && token.meta.exp > Date.now()); +export function validate(token: MCToken | Minecraft | MclcUser) { + if ("exp" in token) return typeof token.exp == "number" && token.exp > Date.now(); + else if ("meta" in token && "exp" in token.meta) return typeof token.meta.exp == "number" && token.meta.exp > Date.now(); return false; } /** - * Gets a minecraft token from a saved mcToken. + * Gets a minecraft token from a saved mcToken. * @param auth A new instance of the auth object * @param token The mcToken * @param refresh Set to true if we should try refreshing the token - * @returns A newly serialized minecraft Token. - * + * @returns A newly serialized minecraft Token. + * * @warning The xbox object may not be restored using this method! */ -export function fromToken(auth: auth, token: mcToken): null | minecraft -export function fromToken(auth: auth, token: mcToken, refresh?: boolean): Promise -export function fromToken(auth: auth, token: mcToken, refresh?: boolean): null | minecraft | Promise { +export function fromToken(auth: Auth, token: MCToken): null | Minecraft; +export function fromToken(auth: Auth, token: MCToken, refresh?: boolean): Promise; +export function fromToken(auth: Auth, token: MCToken, refresh?: boolean): null | Minecraft | Promise { if (validate(token) && refresh) - return new Promise(async done => { + return new Promise(async (done) => { const xbl = await auth.refresh(token.refresh); - done(await xbl.getMinecraft()) - }) - let mc = new minecraft(token.mcToken, token.profile, auth, token.refresh, token.exp ); + done(await xbl.getMinecraft()); + }); + let mc = new Minecraft(token.mcToken, token.profile, auth, token.refresh, token.exp); return mc; } /** - * Gets a minecraft token from a saved mcToken. + * Gets a minecraft token from a saved mcToken. * @param auth A new instance of the auth object * @param token The mcToken - * @returns A newly serialized minecraft Token. - * + * @returns A newly serialized minecraft Token. + * * @warning The xbox object may not be restored using this method! */ -export function fromMclcToken(auth: auth, token: mclcUser, refresh?: boolean): null | minecraft | Promise { - return fromToken(auth, { mcToken: token.access_token, refresh: token.meta?.refresh, exp: token.meta?.exp, profile: { id: token.uuid, name: token.name }, xuid: token.meta?.xuid }, refresh) +export function fromMclcToken(auth: Auth, token: MclcUser, refresh?: boolean): null | Minecraft | Promise { + return fromToken( + auth, + { + mcToken: token.access_token, + refresh: token.meta?.refresh, + exp: token.meta?.exp, + profile: { id: token.uuid, name: token.name }, + xuid: token.meta?.xuid, + }, + refresh, + ); } -export default class minecraft { - +export default class Minecraft { readonly mcToken: string; - readonly profile: mcProfile | undefined; - readonly parent: xbox | auth; + readonly profile: MCProfile | undefined; + readonly parent: Xbox | Auth; readonly xuid: string; readonly exp: number; refreshTkn: string; - getToken(full: boolean): mcToken { + getToken(full: boolean): MCToken { return { - refresh: (this.parent instanceof auth) ? this.refreshTkn : this.parent?.msToken?.refresh_token, + refresh: this.parent instanceof Auth ? this.refreshTkn : this.parent?.msToken?.refresh_token, mcToken: this.mcToken, profile: full ? this.profile : { name: this.profile.name, id: this.profile.id, demo: this.profile.demo }, xuid: this.xuid, - exp: this.exp - } - + exp: this.exp, + }; } - constructor(mcToken: string, profile: mcProfile, parent: xbox) - constructor(mcToken: string, profile: mcProfile, parent: auth, refreshTkn: string, exp: number) - constructor(mcToken: string, profile: mcProfile, parent: xbox | auth, refreshTkn?: string, exp = new Date().getTime() + (1000 * 60 * 60 * 23)) { + constructor(mcToken: string, profile: MCProfile, parent: Xbox); + constructor(mcToken: string, profile: MCProfile, parent: Auth, refreshTkn: string, exp: number); + constructor(mcToken: string, profile: MCProfile, parent: Xbox | Auth, refreshTkn?: string, exp = new Date().getTime() + 1000 * 60 * 60 * 23) { this.parent = parent; this.mcToken = mcToken; this.profile = profile; @@ -90,21 +114,21 @@ export default class minecraft { }, }); errResponse(r998, "error.auth.minecraft.entitlements"); - const json = await r998.json() as { items: [{ name: entitlements, signature: string }] } - const r: entitlements[] = []; - json.items.forEach(e => { - r.push(e.name) - }) + const json = (await r998.json()) as { items: [{ name: Entitlements; signature: string }] }; + const r: Entitlements[] = []; + json.items.forEach((e) => { + r.push(e.name); + }); return r; } isDemo() { return this.profile.demo; } /** - * A MCLC user object for launching minecraft + * A MCLC user object for launching minecraft * @param refreshable Should we embed some metadata for refreshable tokens? * @returns returns an MCLC user token - * + * */ mclc(refreshable?: boolean) { return { @@ -117,12 +141,12 @@ export default class minecraft { type: "msa", demo: this.profile.demo, exp: this.exp, - refresh: refreshable ? ((this.parent instanceof auth) ? this.refreshTkn : this.parent.msToken.refresh_token) : undefined + refresh: refreshable ? (this.parent instanceof Auth ? this.refreshTkn : this.parent.msToken.refresh_token) : undefined, }, - user_properties: {} - } as mclcUser + user_properties: {}, + } as MclcUser; } - gmll(): gmllUser { + gmll(): GmllUser { return { profile: { id: this.profile.id, @@ -131,39 +155,44 @@ export default class minecraft { type: "msa", demo: this.profile.demo, }, - access_token: this.mcToken - } + access_token: this.mcToken, + }; } async refresh(force?: boolean) { - //@ts-ignore - this.parent = (this.parent instanceof auth) ? await this.parent.refresh(this.refreshTkn) : await this.parent.refresh(force); - if (this.validate() && !force) return this + this.parent = this.parent instanceof Auth ? await this.parent.refresh(this.refreshTkn) : await this.parent.refresh(force); + if (this.validate() && !force) return this; let tkn = await this.parent.getMinecraft(); //Copy back objects - Object.keys(tkn).forEach(e => { + Object.keys(tkn).forEach((e) => { this[e] = tkn[e]; - }) + }); return this; } validate() { return validate(this); } _parseLoginToken() { - var base64Url = this.mcToken.split('.')[1]; - var base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/'); - var jsonPayload = decodeURIComponent(Buffer.from(base64, "base64").toString("utf8").split('').map(function (c) { - return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); - }).join('')); - return JSON.parse(jsonPayload) as mcJWTDecoded; + var base64Url = this.mcToken.split(".")[1]; + var base64 = base64Url.replace(/-/g, "+").replace(/_/g, "/"); + var jsonPayload = decodeURIComponent( + Buffer.from(base64, "base64") + .toString("utf8") + .split("") + .map(function (c) { + return "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2); + }) + .join(""), + ); + return JSON.parse(jsonPayload) as MCJWTDecoded; } } function getUUID() { - var result = "" + var result = ""; for (var i = 0; i <= 4; i++) { result += (Math.floor(Math.random() * 16777216) + 1048576).toString(16); - if (i < 4) result += "-" + if (i < 4) result += "-"; } return result; -} \ No newline at end of file +} diff --git a/src/auth/social.ts b/src/auth/social.ts index 2bbb010..8663c69 100644 --- a/src/auth/social.ts +++ b/src/auth/social.ts @@ -1,36 +1,37 @@ import fetch from "node-fetch"; -export class xplayer { - auth: social; +export class XPlayer { + auth: Social; score: number; xuid: string; gamerTag: string; name: string; profilePictureURL: string; - constructor(user: { id: string; settings: any[]; }, auth: social) { + constructor(user: { id: string; settings: any[] }, auth: Social) { this.xuid = user.id; - this.gamerTag = user.settings.find(s => s.id == "Gamertag")?.value; - this.name = user.settings.find(s => s.id == "GameDisplayName")?.value; - this.profilePictureURL = user.settings.find(s => s.id == "GameDisplayPicRaw").value; - this.score = user.settings.find(s => s.id == "Gamerscore").value; + this.gamerTag = user.settings.find((s) => s.id == "Gamertag")?.value; + this.name = user.settings.find((s) => s.id == "GameDisplayName")?.value; + this.profilePictureURL = user.settings.find((s) => s.id == "GameDisplayPicRaw").value; + this.score = user.settings.find((s) => s.id == "Gamerscore").value; this.auth = auth; } - getFriends() { return this.auth.getFriends(this.xuid) } + getFriends() { + return this.auth.getFriends(this.xuid); + } } -export default class social { - +export default class Social { auth: string; constructor(auth: string) { this.auth = auth; } async getProfile(xuid?: string) { const profile = await this.xGet("/profile/settings?settings=GameDisplayName,GameDisplayPicRaw,Gamerscore,Gamertag", xuid); - return new xplayer(profile.profileUsers[0], this); + return new XPlayer(profile.profileUsers[0], this); } async getFriends(xuid?: string) { - const friends = await this.xGet("/profile/settings/people/people?settings=GameDisplayName,GameDisplayPicRaw,Gamerscore,Gamertag", xuid) - let R: xplayer[] = []; - friends.profileUsers.forEach((element: { id: string; settings: any[]; }) => { - R.push(new xplayer(element, this)); + const friends = await this.xGet("/profile/settings/people/people?settings=GameDisplayName,GameDisplayPicRaw,Gamerscore,Gamertag", xuid); + let R: XPlayer[] = []; + friends.profileUsers.forEach((element: { id: string; settings: any[] }) => { + R.push(new XPlayer(element, this)); }); return R; } @@ -39,10 +40,10 @@ export default class social { let profileRaw = await fetch(`https://profile.xboxlive.com/users/${target}/${endpoint}`, { headers: { "Content-Type": "application/json", - "x-xbl-contract-version": '2', + "x-xbl-contract-version": "2", Authorization: this.auth, - } + }, }); return await profileRaw.json(); } -} \ No newline at end of file +} diff --git a/src/auth/xbox.ts b/src/auth/xbox.ts index 950ce13..fe1ef73 100644 --- a/src/auth/xbox.ts +++ b/src/auth/xbox.ts @@ -1,42 +1,42 @@ -import { err, errResponse, lexcodes, mcProfile } from "../assets.js"; -import { auth, msAuthToken } from "./auth.js"; +import { err, errResponse, Lexcodes, MCProfile } from "../assets.js"; +import { Auth, MSAuthToken } from "./auth.js"; import fetch from "node-fetch"; -import social from "./social.js"; -import minecraft from "./minecraft.js"; +import Social from "./social.js"; +import Minecraft from "./minecraft.js"; -export interface mcAuthToken { - username: string, - roles: [], - access_token: string - token_type: string, - expires_in: number +export interface MCAuthToken { + username: string; + roles: []; + access_token: string; + token_type: string; + expires_in: number; } -export interface xblAuthToken { - IssueInstant?: string - NotAfter?: string - Token: string - DisplayClaims?: { xui: [{ uhs: string }] } +export interface XblAuthToken { + IssueInstant?: string; + NotAfter?: string; + Token: string; + DisplayClaims?: { xui: [{ uhs: string }] }; } -export default class xbox { - readonly parent: auth; - readonly msToken: msAuthToken; - readonly xblToken: xblAuthToken; +export default class Xbox { + readonly parent: Auth; + readonly msToken: MSAuthToken; + readonly xblToken: XblAuthToken; readonly exp: number; - constructor(parent: auth, MStoken: msAuthToken, xblToken: xblAuthToken) { + constructor(parent: Auth, MStoken: MSAuthToken, xblToken: XblAuthToken) { this.parent = parent; this.msToken = MStoken; this.xblToken = xblToken; - this.exp = new Date().getTime() + (60 * 60 * 1000) - 1000; + this.exp = new Date().getTime() + 60 * 60 * 1000 - 1000; } - load(code: lexcodes) { + load(code: Lexcodes) { this.parent.emit("load", code); } async xAuth(RelyingParty = "http://xboxlive.com") { - this.load('load.auth.xsts'); + this.load("load.auth.xsts"); let rxsts = await fetch("https://xsts.auth.xboxlive.com/xsts/authorize", { method: "post", body: JSON.stringify({ @@ -49,52 +49,57 @@ export default class xbox { var XSTS = await rxsts.json(); if (XSTS.XErr) { - var ts = "error.auth.xsts" as lexcodes; + var ts = "error.auth.xsts" as Lexcodes; switch (XSTS.XErr) { - case 2148916233: ts = "error.auth.xsts.userNotFound"; break; - case 2148916235: ts = "error.auth.xsts.bannedCountry"; break; + case 2148916233: + ts = "error.auth.xsts.userNotFound"; + break; + case 2148916235: + ts = "error.auth.xsts.bannedCountry"; + break; case 2148916236: - case 2148916237: ts = "error.auth.xsts.child.SK"; break; - case 2148916238: ts = "error.auth.xsts.child"; break; + case 2148916237: + ts = "error.auth.xsts.child.SK"; + break; + case 2148916238: + ts = "error.auth.xsts.child"; + break; } err(ts); } - console.log(XSTS.DisplayClaims) - return `XBL3.0 x=${XSTS.DisplayClaims.xui[0].uhs};${XSTS.Token}` + console.log(XSTS.DisplayClaims); + return `XBL3.0 x=${XSTS.DisplayClaims.xui[0].uhs};${XSTS.Token}`; } //infxbox async refresh(force?: boolean) { - if (this.validate() && !force) return this + if (this.validate() && !force) return this; let tkn = await this.parent.refresh(this.msToken); //Copy back objects - Object.keys(tkn).forEach(e => { + Object.keys(tkn).forEach((e) => { this[e] = tkn[e]; - }) + }); return this; } async getSocial() { const header = await this.xAuth(); - const _social = new social(header) + const _social = new Social(header); return _social; } async getMinecraft() { const auth = await this.xAuth("rp://api.minecraftservices.com/"); - this.load('load.auth.minecraft.login') - var rlogin_with_xbox = await fetch( - "https://api.minecraftservices.com/authentication/login_with_xbox", - { - method: "post", - body: JSON.stringify({ - identityToken: auth - }), - headers: { "Content-Type": "application/json", Accept: "application/json" }, - } - ); - errResponse(rlogin_with_xbox, "error.auth.minecraft.login") - var MCauth = await rlogin_with_xbox.json() as mcAuthToken; - this.load('load.auth.minecraft.profile') + this.load("load.auth.minecraft.login"); + var rlogin_with_xbox = await fetch("https://api.minecraftservices.com/authentication/login_with_xbox", { + method: "post", + body: JSON.stringify({ + identityToken: auth, + }), + headers: { "Content-Type": "application/json", Accept: "application/json" }, + }); + errResponse(rlogin_with_xbox, "error.auth.minecraft.login"); + var MCauth = (await rlogin_with_xbox.json()) as MCAuthToken; + this.load("load.auth.minecraft.profile"); var r998 = await fetch("https://api.minecraftservices.com/minecraft/profile", { headers: { "Content-Type": "application/json", @@ -102,19 +107,19 @@ export default class xbox { Authorization: `Bearer ${MCauth.access_token}`, }, }); - errResponse(r998, "error.auth.minecraft.profile") - var MCprofile = await r998.json() as mcProfile & { error?: string }; + errResponse(r998, "error.auth.minecraft.profile"); + var MCprofile = (await r998.json()) as MCProfile & { error?: string }; const profile = MCprofile.error ? { id: MCauth.username, capes: [], skins: [], name: "player", demo: true } : MCprofile; - let mc = new minecraft(MCauth.access_token, profile, this); + let mc = new Minecraft(MCauth.access_token, profile, this); if (mc.isDemo()) { - this.load('load.auth.minecraft.gamepass'); - const entitlements = await mc.entitlements() + this.load("load.auth.minecraft.gamepass"); + const entitlements = await mc.entitlements(); if (entitlements.includes("game_minecraft") || entitlements.includes("product_minecraft")) { const social = await (await this.getSocial()).getProfile(); - mc = new minecraft(MCauth.access_token, { id: MCauth.username, capes: [], skins: [], name: social.gamerTag }, this); + mc = new Minecraft(MCauth.access_token, { id: MCauth.username, capes: [], skins: [], name: social.gamerTag }, this); } } - return mc + return mc; } validate() { return this.exp > Date.now(); @@ -126,4 +131,4 @@ export default class xbox { save() { return this.msToken.refresh_token; } -} \ No newline at end of file +} diff --git a/src/gui/electron.ts b/src/gui/electron.ts index 581cb4c..cfe2a07 100644 --- a/src/gui/electron.ts +++ b/src/gui/electron.ts @@ -1,19 +1,19 @@ -// @ts-nocheck Electron misbehaved in the dev dependencies. -import { err, getDefaultWinProperties, lexcodes } from "../assets.js"; -import { auth } from "../auth/auth.js"; +// @ts-nocheck Electron misbehaved in the dev dependencies. +import { err, getDefaultWinProperties, Lexcodes } from "../assets.js"; +import { Auth } from "../auth/auth.js"; -import type { BrowserWindow as TBrowser } from 'electron'; +import type { BrowserWindow as TBrowser } from "electron"; const dynReq = (typeof __webpack_require__ === "function" ? __non_webpack_require__ : require) as NodeRequire; const BrowserWindow = dynReq("electron").BrowserWindow; -if (!BrowserWindow){ - err("error.state.invalid.electron") +if (!BrowserWindow) { + err("error.state.invalid.electron"); } -export default (auth: auth, Windowproperties = getDefaultWinProperties()) => { - return new Promise((resolve, reject: (e: lexcodes) => void) => { +export default (auth: Auth, Windowproperties = getDefaultWinProperties()) => { + return new Promise((resolve, reject: (e: Lexcodes) => void) => { var redirect = auth.createLink(); const mainWindow: TBrowser = new BrowserWindow(Windowproperties); mainWindow.setMenu(null); @@ -21,7 +21,9 @@ export default (auth: auth, Windowproperties = getDefaultWinProperties()) => { const contents = mainWindow.webContents; var loading = false; mainWindow.on("close", () => { - if (!loading) { reject("error.gui.closed") }; + if (!loading) { + reject("error.gui.closed"); + } }); contents.on("did-finish-load", () => { const loc = contents.getURL(); @@ -36,7 +38,7 @@ export default (auth: auth, Windowproperties = getDefaultWinProperties()) => { } catch { console.error("[MSMC]: Failed to close window!"); } - }; + } }); }); }; diff --git a/src/gui/nwjs.ts b/src/gui/nwjs.ts index f8fcc9f..0211cd9 100644 --- a/src/gui/nwjs.ts +++ b/src/gui/nwjs.ts @@ -1,23 +1,23 @@ -import { getDefaultWinProperties, lexcodes } from "../assets.js"; -import { auth } from "../auth/auth.js"; +import { getDefaultWinProperties, Lexcodes } from "../assets.js"; +import { Auth } from "../auth/auth.js"; -export default (auth: auth, Windowproperties = getDefaultWinProperties()) => { - return new Promise((resolve, rejects: (e: lexcodes) => void) => { +export default (auth: Auth, Windowproperties = getDefaultWinProperties()) => { + return new Promise((resolve, rejects: (e: Lexcodes) => void) => { var redirect = auth.createLink(); //@ts-ignore nw.Window.open(redirect, Windowproperties, function (new_win) { - new_win.on('close', function () { - rejects('error.gui.closed') + new_win.on("close", function () { + rejects("error.gui.closed"); new_win.close(true); }); - new_win.on('loaded', function () { + new_win.on("loaded", function () { const loc = new_win.window.location.href; if (loc.startsWith(auth.token.redirect)) { const urlParams = new URLSearchParams(loc.substr(loc.indexOf("?") + 1)).get("code"); if (urlParams) { resolve(urlParams); } else { - rejects('error.gui.closed'); + rejects("error.gui.closed"); } try { new_win.close(true); @@ -30,5 +30,4 @@ export default (auth: auth, Windowproperties = getDefaultWinProperties()) => { }); }); }); -} - +}; diff --git a/src/gui/raw.ts b/src/gui/raw.ts index 5ab7881..133fa4f 100644 --- a/src/gui/raw.ts +++ b/src/gui/raw.ts @@ -1,71 +1,97 @@ - -import path from 'path'; -import fs from 'fs'; +import path from "path"; +import fs from "fs"; import os from "os"; const temp = path.join(os.tmpdir(), "msmc"); -import { spawn, execSync as exec, ChildProcessWithoutNullStreams } from 'child_process'; -import { err, getDefaultWinProperties, lexcodes } from '../assets.js'; -import auth from '../auth/auth'; -import fetch from 'node-fetch'; +import { spawn, execSync as exec, ChildProcessWithoutNullStreams } from "child_process"; +import { err, getDefaultWinProperties, Lexcodes } from "../assets.js"; +import Auth from "../auth/auth"; +import fetch from "node-fetch"; var firefox = false; -var start: string +var start: string; console.log("[MSMC]: OS Type => " + os.type()); switch (os.type()) { - case 'Windows_NT': - const pathsW = ["HKEY_LOCAL_MACHINE", "HKEY_CURRENT_USER"] - const compatibleW = ["chrome.exe", "vivaldi.exe", "brave.exe", "blisk.exe", "msedge.exe"] + case "Windows_NT": + const pathsW = ["HKEY_LOCAL_MACHINE", "HKEY_CURRENT_USER"]; + const compatibleW = ["chrome.exe", "vivaldi.exe", "brave.exe", "blisk.exe", "msedge.exe"]; WE: { for (var i2 = 0; i2 < compatibleW.length; i2++) { for (var i = 0; i < pathsW.length; i++) { - const locW = pathsW[i] + "\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\" + const locW = pathsW[i] + "\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\"; try { - console.log("reg query \"" + locW + compatibleW[i2] + "\"") - var out = exec("\"C:\\Windows\\System32\\reg.exe\" query \"" + locW + compatibleW[i2] + "\"").toString(); + console.log('reg query "' + locW + compatibleW[i2] + '"'); + var out = exec('"C:\\Windows\\System32\\reg.exe" query "' + locW + compatibleW[i2] + '"').toString(); if (!out.startsWith("ERROR")) { out = out.substring(out.indexOf("REG_SZ") + "REG_SZ".length).trim(); - if (out.indexOf("\n") > 0) - out = out.substring(0, out.indexOf("\n") - 1); - if (fs.existsSync(out)) { start = out; break WE; } - else console.log("[MSMC]: cannot find " + out) + if (out.indexOf("\n") > 0) out = out.substring(0, out.indexOf("\n") - 1); + if (fs.existsSync(out)) { + start = out; + break WE; + } else console.log("[MSMC]: cannot find " + out); } - } catch { }; + } catch {} } } - console.error("[MSMC]: No Chromium browser was found") + console.error("[MSMC]: No Chromium browser was found"); } break; - case 'Darwin': - const locD = "/Applications/{0}.app/Contents/MacOS/{0}" - const compatibleD = ["Google\\ Chrome", "Google Chrome", "Microsoft\\ Edge", "Microsoft Edge", "Vivaldi", "Blisk", "Brave\\ Browser", "Brave Browser", "Yandex"] + case "Darwin": + const locD = "/Applications/{0}.app/Contents/MacOS/{0}"; + const compatibleD = [ + "Google\\ Chrome", + "Google Chrome", + "Microsoft\\ Edge", + "Microsoft Edge", + "Vivaldi", + "Blisk", + "Brave\\ Browser", + "Brave Browser", + "Yandex", + ]; for (var i2 = 0; i2 < compatibleD.length; i2++) { - const s = locD.replace(/\{0\}/g, compatibleD[i2]) - if (fs.existsSync(s)) { start = s; break; } + const s = locD.replace(/\{0\}/g, compatibleD[i2]); + if (fs.existsSync(s)) { + start = s; + break; + } } if (start) break; - case 'Linux': + case "Linux": default: const pathsL = process.env.PATH.split(":"); - const edd = ["", "-stable", "-beta", "-dev", "-g4","-browser"]; - const compatibleL = ["chromium", "google-chrome", "microsoft-edge", "vivaldi", "brave-browser", "blisk-browser", "yandex-browser", "waterfox", "firefox"] - const ffox = ["firefox", "waterfox"] + const edd = ["", "-stable", "-beta", "-dev", "-g4", "-browser"]; + const compatibleL = [ + "chromium", + "google-chrome", + "microsoft-edge", + "vivaldi", + "brave-browser", + "blisk-browser", + "yandex-browser", + "waterfox", + "firefox", + ]; + const ffox = ["firefox", "waterfox"]; LE: { for (var i2 = 0; i2 < compatibleL.length; i2++) { for (var i3 = 0; i3 < edd.length; i3++) { for (var i = 0; i < pathsL.length; i++) { const s = path.join(pathsL[i], compatibleL[i2] + edd[i3]); - if (fs.existsSync(s)) { start = s; firefox = (ffox.includes(compatibleL[i2])); break LE; } + if (fs.existsSync(s)) { + start = s; + firefox = ffox.includes(compatibleL[i2]); + break LE; + } } } } - console.error("[MSMC]: No compatible browser was found") + console.error("[MSMC]: No compatible browser was found"); } } -function browserLoop(auth: auth, port: string, browser: ChildProcessWithoutNullStreams) { - - return new Promise((resolve, error: (e: lexcodes) => void) => { +function browserLoop(auth: Auth, port: string, browser: ChildProcessWithoutNullStreams) { + return new Promise((resolve, error: (e: Lexcodes) => void) => { const call = () => { try { clearInterval(f3); @@ -79,61 +105,76 @@ function browserLoop(auth: auth, port: string, browser: ChildProcessWithoutNullS } catch { console.error("[MSMC]: Failed to close window!"); } - } - process.on("exit", call) + }; + process.on("exit", call); const f3 = setInterval(() => { - fetch("http://127.0.0.1:" + port + "/json/list").then(r => r.json()).then(out => { - for (var i = 0; i < out.length; i++) { - const loc = out[i].url; - if (loc && loc.startsWith(auth.token.redirect)) { - const urlParams = new URLSearchParams(loc.substr(loc.indexOf("?") + 1)).get("code"); - if (urlParams) - resolve(urlParams); - else - error("error.gui.closed"); - call(); + fetch("http://127.0.0.1:" + port + "/json/list") + .then((r) => r.json()) + .then((out) => { + for (var i = 0; i < out.length; i++) { + const loc = out[i].url; + if (loc && loc.startsWith(auth.token.redirect)) { + const urlParams = new URLSearchParams(loc.substr(loc.indexOf("?") + 1)).get("code"); + if (urlParams) resolve(urlParams); + else error("error.gui.closed"); + call(); + } } - } - }).catch((err) => { - call(); - console.error("[msmc]: " + err) - error("error.gui.closed"); - }) + }) + .catch((err) => { + call(); + console.error("[msmc]: " + err); + error("error.gui.closed"); + }); }, 500); }); } -export default (auth: auth, Windowproperties = getDefaultWinProperties()) => { +export default (auth: Auth, Windowproperties = getDefaultWinProperties()) => { const cmd = Windowproperties.browserCMD ? Windowproperties.browserCMD : start; if (!cmd) { err("error.gui.raw.noBrowser"); } - console.log("[MSMC]: Using \"" + cmd + "\""); + console.log('[MSMC]: Using "' + cmd + '"'); var redirect = auth.createLink(); return new Promise((resolve, error) => { var browser: ChildProcessWithoutNullStreams; if (firefox || Windowproperties.firefox) { console.log("[MSMC]: Using firefox fallback {Linux only!}"); - if (fs.existsSync(temp)) exec("rm -R " + temp); fs.mkdirSync(temp); + if (fs.existsSync(temp)) exec("rm -R " + temp); + fs.mkdirSync(temp); browser = spawn(cmd, ["--profile", temp, "-kiosk", redirect, "--remote-debugging-port=0", "--new-instance"]); - } else browser = spawn(cmd, ["--disable-restore-session-state", "--disable-first-run-ui", "--disable-component-extensions-with-background-pages", "--no-first-run", "--disable-extensions", "--window-size=" + Windowproperties.width + "," + Windowproperties.height, "--remote-debugging-port=0", "--no-default-browser-check", "--user-data-dir=" + temp, "--force-app-mode", "--app=" + redirect]); + } else + browser = spawn(cmd, [ + "--disable-restore-session-state", + "--disable-first-run-ui", + "--disable-component-extensions-with-background-pages", + "--no-first-run", + "--disable-extensions", + "--window-size=" + Windowproperties.width + "," + Windowproperties.height, + "--remote-debugging-port=0", + "--no-default-browser-check", + "--user-data-dir=" + temp, + "--force-app-mode", + "--app=" + redirect, + ]); var firstrun = true; - const ouput = (out: { toString: () => any; }) => { + const ouput = (out: { toString: () => any }) => { const cout = String(out.toString()).toLocaleLowerCase().trim(); - console.log("[MSMC][Browser]: " + cout) + console.log("[MSMC][Browser]: " + cout); if (firstrun && cout.startsWith("devtools listening on ws://")) { firstrun = false; var data = cout.substring("devtools listening on ws://".length); const n = data.indexOf(":") + 1; const port = data.substring(n, data.indexOf("/")); console.log("[MSMC]: Debug hook => http://127.0.0.1:" + port); - browserLoop(auth, port, browser).then(resolve).catch(error) + browserLoop(auth, port, browser).then(resolve).catch(error); } - } + }; if (!Windowproperties.suppress) { - browser.stdout.on('data', ouput) - browser.stderr.on('data', ouput) + browser.stdout.on("data", ouput); + browser.stderr.on("data", ouput); } }); -} \ No newline at end of file +}; diff --git a/src/index.ts b/src/index.ts index 4c837db..b89bce3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,13 +1,13 @@ -import auth from "./auth/auth.js"; +import Auth from "./auth/auth.js"; import * as assets from "./assets.js"; import { wrapError, lst } from "./assets.js"; -import social from "./auth/social"; -import type xbox from "./auth/xbox.js"; -import type minecraft from "./auth/minecraft.js"; -import { fromToken, fromMclcToken, validate, mcToken } from "./auth/minecraft.js"; +import Social from "./auth/social"; +import type Xbox from "./auth/xbox.js"; +import type Minecraft from "./auth/minecraft.js"; +import { fromToken, fromMclcToken, validate, MCToken } from "./auth/minecraft.js"; -export { social, auth, assets, wrapError, lst }; -export const mcTokenToolbox = {fromToken, fromMclcToken, validate} -export type { xbox, minecraft, mcToken }; \ No newline at end of file +export { Social, Auth, assets, wrapError, lst }; +export const mcTokenToolbox = { fromToken, fromMclcToken, validate }; +export type { Xbox, Minecraft, MCToken }; From e4d95b9d244b43702f0c652d7cd77fe6a10d7a30 Mon Sep 17 00:00:00 2001 From: Matix-Media Date: Fri, 24 Mar 2023 13:05:14 +0100 Subject: [PATCH 2/3] refactor: :pencil2: Updated tests to use renamed classes --- tests/console/index.mjs | 2 +- tests/nwjs/index.js | 2 +- tests/raw/test2.mjs | 2 +- tests/raw/tests.mjs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/console/index.mjs b/tests/console/index.mjs index 171256f..569e58b 100644 --- a/tests/console/index.mjs +++ b/tests/console/index.mjs @@ -1,6 +1,6 @@ import msmc from "msmc"; console.log(msmc) -const auth = new msmc.auth({ +const auth = new msmc.Auth({ "client_id":"9263b99c-b7c7-4c98-ac73-3dd90bc1fa2e", "redirect":"http://localhost" }); diff --git a/tests/nwjs/index.js b/tests/nwjs/index.js index f3eb6bc..d09e137 100755 --- a/tests/nwjs/index.js +++ b/tests/nwjs/index.js @@ -4,7 +4,7 @@ const { assets } = require("msmc"); assets.loadLexiPack("../../lexipacks/french.json") console.log("Testing NWJS. This should test most of the underlying code") -new auth('select_account').on('load', console.log).launch('nwjs').then(async e => { +new Auth('select_account').on('load', console.log).launch('nwjs').then(async e => { const t = await e.getMinecraft() console.log(t.mclc()) const a = await t.refresh(true) diff --git a/tests/raw/test2.mjs b/tests/raw/test2.mjs index 9d5afde..ca1703f 100644 --- a/tests/raw/test2.mjs +++ b/tests/raw/test2.mjs @@ -3,7 +3,7 @@ const launcher = new Client(); //Import the auth class import msmc from "msmc"; //Create a new auth manager -const authManager = new msmc.auth("select_account"); +const authManager = new msmc.Auth("select_account"); //Launch using the 'raw' gui framework (can be 'electron' or 'nwjs') const xboxManager = await authManager.launch("raw") //Generate the minecraft login token diff --git a/tests/raw/tests.mjs b/tests/raw/tests.mjs index 9a033e3..5603479 100644 --- a/tests/raw/tests.mjs +++ b/tests/raw/tests.mjs @@ -1,6 +1,6 @@ import msmc, { wrapError,assets } from "msmc"; console.log(msmc) -const auth = new msmc.auth(); +const auth = new msmc.Auth(); //assets.loadLexiPack("..","..","lexipacks","afrikaans.json") console.log(auth.createLink()) auth.on('load', console.log).launch('raw').then(async e => { From eed4e1fd4a7222526bcaa0addb6d24141219be14 Mon Sep 17 00:00:00 2001 From: Matix-Media Date: Fri, 24 Mar 2023 13:05:51 +0100 Subject: [PATCH 3/3] fix: :bug: added tests into workspace --- package.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/package.json b/package.json index 66a994d..e95738d 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,12 @@ "test:electron": "cd ./tests/electron\nnpm i\nnpm run start", "test:console": "cd ./tests/console\nnpm i\nnpm run start" }, + "workspaces": [ + "tests/console", + "tests/electron", + "tests/nwjs", + "tests/raw" + ], "keywords": [ "msmc", "microsoft",