import { P as PublicSession, W as Web3Chain } from '../auth-c1d7Eji2.js'; import { UserUtilsConfig, BillingPlan, Subscription, UsageSummary, PrepaidVerifyResult, BillingRecord, ProfileScope, UserProfile, ProfileUpdateInput } from '../types/index.js'; /** * Hook to read the public session cookie for UI state. * Never exposes the JWT — only the public projection (userId, address, expiresAt). */ declare function useSession(): { session: PublicSession | null; loading: boolean; isAuthenticated: boolean; refresh: (apiBaseUrl?: string) => Promise; readSession: () => void; }; /** * Hook to read the CSRF token cookie. * Returns the token and a headers object to include in mutation requests. */ declare function useCSRFToken(cookieName?: string, headerName?: string): { token: string | null; headers: Record; }; interface WalletState { connected: boolean; address: string | null; chain: Web3Chain | null; provider: 'phantom' | 'solflare' | 'metamask' | null; } /** * Hook for connecting Web3 wallets (Phantom, Solflare, MetaMask). * Handles wallet detection, connection, and message signing. */ declare function useWeb3Wallet(): { wallet: WalletState; error: string | null; connectSolana: (provider?: "phantom" | "solflare") => Promise; connectEVM: () => Promise; signMessage: (message: string, opts?: { chain?: Web3Chain; provider?: string; address?: string; }) => Promise; disconnect: () => void; }; interface BridgeIdentity { address: string; chain: Web3Chain; method: string | null; stackCount: number; } /** * Hook for cross-domain auth state sharing via iframe bridge. * * Embeds an invisible iframe from stacknet.magma-rpc.com that stores * auth preferences (which wallet/chain the user used) in its localStorage. * When the user visits a different stack app, the bridge reports the * preferred wallet so the app can auto-connect. * * NEVER transmits JWTs. Only shares: address, chain, method, stackId. */ declare function useAuthBridge(opts?: { /** Override bridge URL (default: https://stacknet.magma-rpc.com/auth/bridge) */ bridgeUrl?: string; /** Disable the bridge entirely */ disabled?: boolean; }): { reportConnected: (params: { address: string; chain: Web3Chain; method?: string; stackId?: string; }) => void; reportDisconnected: (params: { address: string; chain: Web3Chain; stackId?: string; }) => void; clearAll: () => void; refresh: () => void; ready: boolean; known: boolean; identity: BridgeIdentity | null; identityCount: number; /** The stackId last used from this domain (resolved from bridge) */ resolvedStackId: string | null; }; /** * Master auth hook — combines wallet connection, challenge/sign/verify, * OTP, and session management. All auth state flows through server routes * (HttpOnly cookies), never touches localStorage or document.cookie directly. * * When `autoConnect` is true, uses the cross-domain iframe bridge to detect * if the user has previously authenticated on another stack and auto-triggers * the wallet connect flow. */ declare function useStackAuth(config?: UserUtilsConfig & { /** Auto-connect using bridge identity if available (default: false) */ autoConnect?: boolean; /** Stack ID for bridge tracking */ stackId?: string; }): { session: PublicSession | null; isAuthenticated: boolean; wallet: WalletState; loading: boolean; error: string | null; authenticateSolana: (provider?: "phantom" | "solflare") => Promise; authenticateEVM: () => Promise; authenticateOTP: (code: string) => Promise; authenticateOAuth: (provider: string, callbackUrl?: string) => Promise; authenticateOAuthCallback: (provider: string, code: string, state: string) => Promise; logout: () => Promise; refresh: () => Promise; /** Effective stack ID (explicit config > bridge-resolved > empty) */ stackId: string; /** Bridge state — known identities from other stacks */ bridge: { ready: boolean; known: boolean; identity: BridgeIdentity | null; identityCount: number; resolvedStackId: string | null; }; }; interface StackPublicConfig { id: string; name: string; displayName: string; description?: string; logoUrl?: string; webPageUrl?: string; allowedChains: string[]; features?: { web3Auth: boolean; oauthAuth: boolean; apiKeyAuth: boolean; billing: boolean; }; stripeProvider?: { provider: string; publishableKey: string; enabled: boolean; mode: string; }; oauthProviders?: Array<{ provider: string; clientId?: string; enabled: boolean; }>; } /** * Fetch public stack configuration from StackNet. * Returns identity providers, Stripe public key, logo, etc. * This endpoint is public (no auth required) — it only returns non-secret config. */ declare function useStackConfig(stackId: string | null, stacknetUrl?: string): { config: StackPublicConfig | null; loading: boolean; error: string | null; identityProviders: { type: "wallet" | "otp" | "oauth"; id: string; name: string; chain?: string; }[]; fetchConfig: (id: string) => Promise; }; declare function usePlans(apiBaseUrl?: string): { plans: BillingPlan[]; loading: boolean; error: string | null; refresh: () => Promise; }; declare function useSubscription(apiBaseUrl?: string): { subscription: Subscription | null; loading: boolean; error: string | null; refresh: () => Promise; subscribe: (planId: string) => Promise; cancel: () => Promise; }; declare function useUsage(apiBaseUrl?: string): { usage: UsageSummary | null; loading: boolean; error: string | null; refresh: () => Promise; }; declare function usePrepaidCheckout(apiBaseUrl?: string): { purchase: (amountCents: number) => Promise; verifySession: (sessionId: string) => Promise; loading: boolean; error: string | null; }; declare function useBillingHistory(apiBaseUrl?: string, opts?: { limit?: number; offset?: number; }): { records: BillingRecord[]; loading: boolean; error: string | null; refresh: () => Promise; }; /** * Hook for reading and updating user profiles. * * Supports two scopes: * - `'global'` (default): network-wide profile at `/user/profile/:mid` * - `{ stackId: 'stk_...' }`: stack-scoped profile at `/api/v2/stacks/:stackId/members/:mid/profile` * * Profile updates are metered at 100M tokens per change. */ declare function useProfile(mid: string | null, opts?: { apiBaseUrl?: string; scope?: ProfileScope; }): { profile: UserProfile | null; loading: boolean; saving: boolean; error: string | null; updateProfile: (input: ProfileUpdateInput) => Promise; refresh: () => Promise; }; interface GoogleOneTapConfig { /** Stack ID to check for Google OAuth configuration */ stackId: string; /** StackNet URL (default: https://stacknet.magma-rpc.com) */ stacknetUrl?: string; /** API base URL for the callback endpoint (default: '') */ apiBaseUrl?: string; /** Auto-prompt on mount if Google is configured and user is not authenticated (default: true) */ autoPrompt?: boolean; /** Cancel the prompt if the user clicks outside (default: true) */ cancelOnTapOutside?: boolean; /** Called after successful authentication */ onSuccess?: () => void; /** Called on error */ onError?: (error: string) => void; /** Disable the hook entirely */ disabled?: boolean; } declare global { interface Window { google?: { accounts: { id: { initialize: (config: any) => void; prompt: (callback?: (notification: any) => void) => void; cancel: () => void; renderButton: (element: HTMLElement, config: any) => void; disableAutoSelect: () => void; }; }; }; } } /** * Hook that shows Google One Tap sign-in prompt when: * 1. The stack has Google OAuth configured (clientId available) * 2. The user is not already authenticated * * On success, sends the Google credential (JWT) to the server * which exchanges it for a StackNet session. */ declare function useGoogleOneTap({ stackId, stacknetUrl, apiBaseUrl, autoPrompt, cancelOnTapOutside, onSuccess, onError, disabled, }: GoogleOneTapConfig): { /** Whether Google One Tap is available for this stack */ available: boolean; /** Whether the GIS script has loaded */ ready: boolean; /** Whether authentication is in progress */ loading: boolean; /** Error message if authentication failed */ error: string | null; /** Manually trigger the One Tap prompt */ prompt: () => void; /** Render a Google Sign-In button into a container element */ renderButton: (element: HTMLElement | null, options?: { theme?: "outline" | "filled_blue" | "filled_black"; size?: "large" | "medium" | "small"; text?: string; width?: number; }) => void; /** The Google client ID from stack config (null if not configured) */ clientId: string | null; }; /** * useJoinCode — fetch (and lazy-mint) the signed-in user's affiliate code. * * The code is the user's stable invite identifier — backed by stacknet's * `user_join_codes` table. A new user who signs up via `?ref=` in * the URL has `POST /user/join` called once during auth (see * `use-stack-auth.ts`), binding them permanently to the referring user * and awarding the referrer 20 social points (decayed per the schedule). * * This hook is a thin client over `GET /social/join-code` (read-only) and * `POST /social/join-code` (fetch-or-mint). On first call we POST so the * code exists; subsequent renders read from cached state. `copyShareLink` * composes a full invite URL using the configured `stacknetUrl` host. */ interface UseJoinCodeResult { /** The code string (e.g. 'aB3xK9pQ'), or null while loading / when signed out. */ code: string | null; /** Full URL including `?ref=`, suitable for sharing. */ shareUrl: string | null; /** True while the initial fetch/mint is in flight. */ loading: boolean; /** Last error from the fetch/mint call, if any. */ error: string | null; /** Manually re-fetch (usually unnecessary — the code is stable). */ refresh: () => Promise; /** * Copy the share URL to the clipboard. Returns true on success. A no-op * (returning false) when the browser doesn't support the clipboard API * — the caller can fall back to showing the URL inline. */ copyShareLink: () => Promise; } interface UseJoinCodeConfig { /** * Base URL of the consumer app. The share link is `${shareBaseUrl}/?ref=` * so the landing page hands the code to stacknet via `POST /user/join` * on the new user's first auth. Defaults to `window.location.origin` * (the page the hook runs on), which is the right choice for most apps. */ shareBaseUrl?: string; /** * If false, the hook only reads the existing code (GET) and won't mint * one if absent. Useful when you want to show the invite section only * after the user has explicitly asked for their code. Default: true. */ autoMint?: boolean; } declare function useJoinCode(config?: UseJoinCodeConfig): UseJoinCodeResult; /** * useInvites — fetch the signed-in user's full set of invite codes * and let them mint new single-use codes (up to the per-owner cap). * * Backed by `/api/social/invites` (GET to list, POST to mint). Each * code is single-use across the whole network: once redeemed via * `?ref=` on signup, the corresponding entry's `consumedByMid` * + `consumedAt` are populated and the code can no longer be used. * * Use this in the new multi-slot invite UI. The legacy `useJoinCode` * single-code hook still works for back-compat (it returns the user's * first available code, minting one if none). */ interface InviteCode { code: string; ownerMid: string; createdAt: number; timesUsed: number; lastUsedAt: number | null; consumedByMid: string | null; consumedAt: number | null; } interface UseInvitesResult { /** All of the user's codes (consumed + available), oldest first. */ codes: InviteCode[]; /** Per-owner cap from the server (e.g. 10). Null until first load. */ limit: number | null; /** Slots still available to mint (limit - codes.length). */ remaining: number | null; /** True while the initial list fetch is in flight. */ loading: boolean; /** True while a mint POST is in flight. */ minting: boolean; /** Last error (load or mint), if any. */ error: string | null; /** Re-fetch the code list from the server. */ refresh: () => Promise; /** Mint a fresh single-use code. Throws on cap-reached / network error. */ mint: () => Promise; /** * Build the share URL for a given code. Defaults to * `${origin}/?ref=`. Returns null in non-browser contexts when * `shareBaseUrl` isn't supplied. */ buildShareUrl: (code: string) => string | null; /** Copy the share URL for a given code to the clipboard. */ copyShareLink: (code: string) => Promise; } interface UseInvitesConfig { /** Override the share-URL origin. Defaults to `window.location.origin`. */ shareBaseUrl?: string; } declare function useInvites(config?: UseInvitesConfig): UseInvitesResult; export { type BridgeIdentity, type GoogleOneTapConfig, type InviteCode, type StackPublicConfig, type UseInvitesConfig, type UseInvitesResult, type UseJoinCodeConfig, type UseJoinCodeResult, type WalletState, useAuthBridge, useBillingHistory, useCSRFToken, useGoogleOneTap, useInvites, useJoinCode, usePlans, usePrepaidCheckout, useProfile, useSession, useStackAuth, useStackConfig, useSubscription, useUsage, useWeb3Wallet };