87 lines
3.5 KiB
TypeScript
87 lines
3.5 KiB
TypeScript
import { type TransportClient, READY_STATE } from "@tensamin/ttp-core";
|
|
import { createSchema } from "./schema";
|
|
import type { z, ZodObject } from "zod";
|
|
/**
|
|
* @param identifier Your app's domain.
|
|
* @param redirectUrl The URL should point to the TAuth HTTP Server at http://hostname:port/callback
|
|
* @param frontendUrl The URL of the frontend the user interacts with. Only used in development.
|
|
* @param appData A Zod schema defining the shape of the app data you want to load/save for each user.
|
|
* @param saveSession A function that saves the session ID for a given user ID. This is called after a successful authentication.
|
|
* @param httpServer Optional configuration for the TAuth HTTP Server. Defaults to { port: 7878, hostname: "localhost" }.
|
|
* @param htmlSuccessPage Optional HTML string or path to an HTML file to be served upon successful authentication.
|
|
*/
|
|
export declare class TAuthClient {
|
|
frontendUrl: string;
|
|
identifier: string;
|
|
privateKey: string;
|
|
publicKey: string;
|
|
saveSession: (userId: number, sessionId: number) => Promise<void> | void;
|
|
redirectUrl: URL;
|
|
schema: ReturnType<typeof createSchema>;
|
|
httpServer: {
|
|
port: number;
|
|
hostname: string;
|
|
};
|
|
clientMap: Map<string, TransportClient<{
|
|
identification: {
|
|
request: z.ZodObject<{
|
|
app_identifier: z.ZodString;
|
|
app_session_id: z.ZodNumber;
|
|
app_public_key: z.ZodString;
|
|
user_id: z.ZodNumber;
|
|
}, z.core.$strip>;
|
|
response: z.ZodObject<{
|
|
challenge: z.ZodBase64;
|
|
public_key: z.ZodBase64;
|
|
}, z.core.$strip>;
|
|
};
|
|
challenge_response: {
|
|
request: z.ZodObject<{
|
|
challenge: z.ZodBase64;
|
|
}, z.core.$strip>;
|
|
response: z.ZodObject<{}, z.core.$strip>;
|
|
};
|
|
load_app_data: {
|
|
request: z.ZodObject<{}, z.core.$strip>;
|
|
response: z.ZodObject<{
|
|
app_data: z.ZodString;
|
|
}, z.core.$strip>;
|
|
};
|
|
save_app_data: {
|
|
request: z.ZodObject<{
|
|
app_data: z.ZodString;
|
|
}, z.core.$strip>;
|
|
response: z.ZodObject<{}, z.core.$strip>;
|
|
};
|
|
}>>;
|
|
private appData;
|
|
constructor({ frontendUrl, identifier, privateKey, publicKey, saveSession, redirectUrl, appData, httpServer, htmlSuccessPage, }: {
|
|
frontendUrl: string;
|
|
identifier: string;
|
|
privateKey: string;
|
|
publicKey: string;
|
|
saveSession: (userId: number, sessionId: number) => Promise<void> | void;
|
|
redirectUrl: string;
|
|
appData: ZodObject;
|
|
httpServer?: {
|
|
port: number;
|
|
hostname: string;
|
|
};
|
|
htmlSuccessPage?: string;
|
|
});
|
|
generateChallenge(userId: number): Promise<string>;
|
|
solveChallenge(userId: number, challenge: string): Promise<string>;
|
|
createTTP(userId: number, sessionId: number, omikronUrl: string): Promise<TransportClient<typeof this.schema>>;
|
|
loadData(userId: number, sessionId: number): Promise<Record<string, unknown>>;
|
|
saveData(userId: number, sessionId: number, data: any): Promise<void>;
|
|
private createTemporaryTTPConnection;
|
|
generateLink(challenge?: string): string;
|
|
}
|
|
export declare function getFriendlyReadyState(stateIndex: number): keyof typeof READY_STATE;
|
|
export declare function generateKeyPair(): {
|
|
private: string;
|
|
public: string;
|
|
};
|
|
export * from "./crypto";
|
|
export * from "./schema";
|
|
export * from "./user";
|