@xmcl/user
Version:
Minecraft user related functions, including Yggdrasil authenticator, player skin fetcher, and Mojang security API
161 lines • 5.06 kB
TypeScript
import { GameProfile, GameProfileWithProperties } from './gameProfile';
/**
* The auth response format.
*
* Please refer https://wiki.vg/Authentication
*/
export interface YggrasilAuthentication {
/**
* hexadecimal or JSON-Web-Token (unconfirmed) [The normal accessToken can be found in the payload of the JWT (second by '.' separated part as Base64 encoded JSON object), in key "yggt"]
*/
accessToken: string;
/**
* identical to the one received
*/
clientToken: string;
/**
* only present if the agent field was received
*/
availableProfiles: GameProfile[];
/**
* only present if the agent field was received
*/
selectedProfile: GameProfile;
/**
* only present if requestUser was true in the request payload
*/
user?: {
id: string;
username: string;
email?: string;
registerIp?: string;
migratedFrom?: string;
migratedAt?: number;
registeredAt?: number;
passwordChangedAt?: number;
dateOfBirth?: number;
suspended?: boolean;
blocked?: boolean;
secured?: boolean;
migrated?: boolean;
emailVerified?: boolean;
legacyUser?: boolean;
verifiedByParent?: boolean;
properties?: object[];
};
}
export interface YggdrasilClientOptions {
headers?: Record<string, string>;
fetch?: typeof fetch;
FormData?: typeof FormData;
File?: typeof File;
}
export interface ProfileLookupException {
/**
* - statusCode=204 -> error="NoPlayerFound"
* - statusCode=400 -> error="IllegalArgumentException" (parsed from body)
* - statusCode=other -> error=statusCode.toString()
*/
error: 'NoPlayerFoundException' | 'IllegalArgumentException' | 'GeneralException';
errorMessage?: string | 'Invalid timestamp.';
statusCode?: number;
statusMessage?: string;
}
export interface SetTextureOption {
accessToken: string;
uuid: string;
type: 'skin' | 'cape' | 'elytra';
texture?: {
url: string;
metadata?: {
model?: 'slim' | 'steve';
[key: string]: any;
};
} | {
data: Uint8Array;
metadata?: {
model?: 'slim' | 'steve';
[key: string]: any;
};
};
}
export declare class YggdrasilError extends Error {
readonly statusCode: number;
error: string;
errorMessage: string;
cause?: string;
constructor(statusCode: number, message: string, o?: any);
}
export declare class YggdrasilClient {
api: string;
protected headers: Record<string, string>;
protected fetch: typeof fetch;
protected FormData: typeof FormData;
protected File: typeof File;
/**
* Create client for official-like api endpoint
* @param api The official-like api endpoint
*/
constructor(api: string, options?: YggdrasilClientOptions);
validate(accessToken: string, clientToken: string, signal?: AbortSignal): Promise<boolean>;
invalidate(accessToken: string, clientToken: string, signal?: AbortSignal): Promise<boolean>;
login({ username, password, clientToken, requestUser }: {
username: string;
password: string;
clientToken: string;
requestUser?: boolean;
}, signal?: AbortSignal): Promise<YggrasilAuthentication>;
refresh({ accessToken, requestUser, clientToken }: {
accessToken: string;
clientToken: string;
requestUser?: boolean;
}, signal?: AbortSignal): Promise<YggrasilAuthentication>;
}
/**
* The texture structure for yggdrasil API
*/
export interface YggdrasilTexturesInfo {
/**
* java time in ms
*/
timestamp: number;
/**
* player name
*/
profileName: string;
/**
* player id
*/
profileId: string;
textures: {
SKIN?: YggdrasilTexture;
CAPE?: YggdrasilTexture;
ELYTRA?: YggdrasilTexture;
};
}
/**
* The data structure that hold the texture
*/
export interface YggdrasilTexture {
url: string;
metadata?: {
model?: 'slim' | 'steve';
[key: string]: any;
};
}
export declare function isTextureSlim(o: YggdrasilTexture): boolean;
export declare function getTextureType(o: YggdrasilTexture): "slim" | "steve";
export declare class YggdrasilThirdPartyClient extends YggdrasilClient {
profileApi: string;
textureApi: string;
/**
* Create thirdparty (authlib-injector) style client
* @param api The api url following https://github.com/yushijinhun/authlib-injector/wiki/Yggdrasil-%E6%9C%8D%E5%8A%A1%E7%AB%AF%E6%8A%80%E6%9C%AF%E8%A7%84%E8%8C%83
* @param clientToken
* @param dispatcher
*/
constructor(api: string, options?: YggdrasilClientOptions);
lookup(uuid: string, unsigned?: boolean, signal?: AbortSignal): Promise<GameProfileWithProperties>;
setTexture(options: SetTextureOption, signal?: AbortSignal): Promise<void>;
}
//# sourceMappingURL=yggdrasil.d.ts.map