@lightninglabs/lnc-web
Version:
Lightning Node Connect npm module for web
95 lines • 3.71 kB
TypeScript
import { SessionConfig } from '../types/lightningNodeConnect';
import { SessionCredentials } from './types';
/**
* Manages encrypted passwordless sessions backed by device and origin key
* wrapping. Credentials are encrypted with a one-time DEK, which is wrapped
* independently by a device-derived key (from browser fingerprint) and an
* origin-bound key (from IndexedDB), then persisted in sessionStorage.
*/
export default class SessionManager {
private encrypter;
private keyWrapper;
private deviceBinder;
private originKeyManager;
private storage;
private namespace;
private isRefreshing;
private refreshPromise?;
readonly config: Readonly<Required<SessionConfig>>;
constructor(namespace: string, config?: SessionConfig);
/**
* Check if auto-restore is available
*/
get canAutoRestore(): boolean;
/**
* Get time until session expiry in milliseconds
*/
get sessionTimeRemaining(): number;
/**
* Check if there's an active session
*/
get hasActiveSession(): boolean;
/**
* Get the namespace for this session manager
*/
getNamespace(): string;
/**
* Clear the current session
*/
clearSession(): void;
/**
* Check if there's a valid session by attempting to restore it
*/
hasValidSession(): Promise<boolean>;
/**
* Create a new password-less session
*/
createSession(credentials: SessionCredentials): Promise<void>;
/**
* Restore a session without password. Returns undefined when the session
* cannot be restored (missing, expired, or infrastructure failure). Errors
* are caught and logged so callers do not need try/catch.
*
* Storage is intentionally cleared on any error (including transient ones)
* because a failed restore implies the session is unrecoverable from the
* user's perspective — the device fingerprint or origin key is wrong,
* corrupt, or inaccessible. Storage is also cleared when the session is
* expired or missing, since stale data should not persist indefinitely.
*
* The {@link refreshSessionInternal} path uses {@link restoreSessionOrThrow}
* instead, which preserves storage so the circuit breaker can retry on
* genuinely transient failures.
*/
restoreSession(): Promise<SessionCredentials | undefined>;
/**
* Refresh the current session. Guards against concurrent calls so
* overlapping callers do not produce stale read-modify-write cycles.
*
* When a refresh is already in flight, concurrent callers receive the
* same promise rather than an optimistic `true`. This ensures the
* circuit breaker in SessionRefreshManager sees the real outcome of
* the in-flight operation and can count failures accurately.
*/
refreshSession(): Promise<boolean>;
/**
* Internal refresh logic, called by the re-entrancy-guarded public method.
*/
private refreshSessionInternal;
/**
* Internal restore that lets infrastructure errors (crypto, storage, key
* wrapping) propagate. Used by {@link refreshSession} so the caller can
* distinguish "nothing to refresh" from real failures.
*/
private restoreSessionOrThrow;
/**
* Generate a cryptographically secure session ID
*/
private generateSecureSessionId;
/**
* Merge caller-supplied config with defaults and validate the result.
* Undefined values in the input are filtered out so they do not overwrite
* defaults (e.g. when a caller passes { sessionDurationMs: undefined }).
*/
private validateConfig;
}
//# sourceMappingURL=sessionManager.d.ts.map