/** * session/manager.ts — x402 V2 session lifecycle management. * * This module implements the "wallet-based access & reusable sessions" concept * introduced in x402 V2. Agents pay once to establish a cryptographically * authenticated session, then make N subsequent calls without additional * on-chain transactions. * * Non-custodial design: * - Session tokens are signed locally by the agent's private key * - No third party holds or validates keys * - Servers receive a self-contained signed token they can independently verify * - The SessionManager has zero knowledge of private keys; it only receives * a signMessage callback injected at creation time * * Token format: * X-Session-Token: . * Compatible with x402 V2 SIGN-IN-WITH-X (SIWx) header pattern * Servers can ecrecover the wallet address without any external service */ import type { SessionRecord, SessionTokenPayload, CreateSessionOptions, SessionLookupResult } from './types.js'; /** * HTTP header name for session tokens. * x402 V2 uses modernised header names (no X- prefix per IETF conventions * for new standard headers). We use PAYMENT-SESSION for the session token * and retain X-Session-Token as an alias for broad compatibility. */ export declare const SESSION_TOKEN_HEADER = "X-Session-Token"; export declare const SESSION_WALLET_HEADER = "X-Session-Wallet"; export declare const PAYMENT_SESSION_HEADER = "PAYMENT-SESSION"; /** * Create a new session after a successful x402 payment. * * Signs a canonical token payload with the agent's private key, creating * a self-verifiable session token that servers can use to grant access * without requiring a new on-chain payment. */ export declare function createSession(opts: CreateSessionOptions): Promise; /** * Look up a session by ID. * Returns the record and whether it has expired. */ export declare function lookupSession(sessionId: string): SessionLookupResult; /** * Record a call made within a session. * Updates callCount and lastUsedAt in-place. */ export declare function recordSessionCall(sessionId: string): void; /** * Explicitly end a session (mark as expired by setting expiresAt to past). * Returns true if the session was found and ended. */ export declare function endSession(sessionId: string): boolean; /** * List all active (non-expired) sessions. */ export declare function listActiveSessions(): SessionRecord[]; /** * List all sessions (including expired). */ export declare function listAllSessions(): SessionRecord[]; /** * Find the best matching active session for a given URL. * Prefers exact-scope matches over prefix-scope. * Used to auto-attach a session to x402_pay when available. */ export declare function findSessionForUrl(url: string): SessionRecord | undefined; /** * Build the HTTP headers to include in a session-authenticated request. * These headers are inspired by x402 V2's SIGN-IN-WITH-X (SIWx) pattern * and the PAYMENT-SESSION header spec. */ export declare function buildSessionHeaders(session: SessionRecord): Record; /** * Decode a session token string into its payload and signature. * Useful for display / debugging purposes. */ export declare function decodeSessionToken(token: string): { payload: SessionTokenPayload; signature: string; } | null; /** * Get total sessions count (active + expired). */ export declare function getStoreSize(): number; /** * Clear all sessions — for testing only. */ export declare function _clearAllSessions(): void; //# sourceMappingURL=manager.d.ts.map