import type { AgentSecret, LocalNode } from "cojson"; import type { Account, AnonymousJazzAgent, ID } from "./internal.js"; export type { SyncWhen } from "cojson"; export type AuthCredentials = { accountID: ID; secretSeed?: Uint8Array; accountSecret: AgentSecret; provider?: "anonymous" | "clerk" | "demo" | "passkey" | "passphrase" | string; }; /** * Authenticates the user with the given credentials * @param credentials - The credentials to authenticate with * @param forceContextCreation - If true, the context will be created even if the same account is already authenticated * @returns A promise that resolves when the authentication is complete */ export type AuthenticateAccountFunction = ( credentials: AuthCredentials, forceContextCreation?: boolean, ) => Promise; export type RegisterAccountFunction = ( accountSecret: AgentSecret, creationProps: { name: string }, ) => Promise>; /** @category Context Creation */ export type JazzAuthContext = { me: Acc; node: LocalNode; authenticate: AuthenticateAccountFunction; register: RegisterAccountFunction; logOut: () => Promise; done: () => void; isAuthenticated?: boolean; addConnectionListener: (listener: (connected: boolean) => void) => () => void; connected: () => boolean; }; export type JazzGuestContext = { guest: AnonymousJazzAgent; node: LocalNode; authenticate: AuthenticateAccountFunction; register: RegisterAccountFunction; logOut: () => void; done: () => void; isAuthenticated?: boolean; addConnectionListener: (listener: (connected: boolean) => void) => () => void; connected: () => boolean; }; export type JazzContextType = | JazzAuthContext | JazzGuestContext; export type NewAccountProps = { secret?: AgentSecret; creationProps?: { name: string }; }; export type SyncConfig = | { peer: `wss://${string}` | `ws://${string}`; when?: "always" | "signedUp"; } | { peer?: `wss://${string}` | `ws://${string}`; when: "never"; };