@bsv/sdk
Version:
BSV Blockchain Software Development Kit
60 lines • 2.34 kB
TypeScript
import { PeerSession } from './types.js';
/**
* Manages sessions for peers, allowing multiple concurrent sessions
* per identity key. Primary lookup is always by `sessionNonce`.
*/
export declare class SessionManager {
/**
* Maps sessionNonce -> PeerSession
*/
private readonly sessionNonceToSession;
/**
* Maps identityKey -> Set of sessionNonces
*/
private readonly identityKeyToNonces;
constructor();
/**
* Adds a session to the manager, associating it with its sessionNonce,
* and also with its peerIdentityKey (if any).
*
* This does NOT overwrite existing sessions for the same peerIdentityKey,
* allowing multiple concurrent sessions for the same peer.
*
* @param {PeerSession} session - The peer session to add.
*/
addSession(session: PeerSession): void;
/**
* Updates a session in the manager (primarily by re-adding it),
* ensuring we record the latest data (e.g., isAuthenticated, lastUpdate, etc.).
*
* @param {PeerSession} session - The peer session to update.
*/
updateSession(session: PeerSession): void;
/**
* Retrieves a session based on a given identifier, which can be:
* - A sessionNonce, or
* - A peerIdentityKey.
*
* If it is a `sessionNonce`, returns that exact session.
* If it is a `peerIdentityKey`, returns the "best" (e.g. most recently updated,
* authenticated) session associated with that peer, if any.
*
* @param {string} identifier - The identifier for the session (sessionNonce or peerIdentityKey).
* @returns {PeerSession | undefined} - The matching peer session, or undefined if not found.
*/
getSession(identifier: string): PeerSession | undefined;
/**
* Removes a session from the manager by clearing all associated identifiers.
*
* @param {PeerSession} session - The peer session to remove.
*/
removeSession(session: PeerSession): void;
/**
* Checks if a session exists for a given identifier (either sessionNonce or identityKey).
*
* @param {string} identifier - The identifier to check.
* @returns {boolean} - True if the session exists, false otherwise.
*/
hasSession(identifier: string): boolean;
}
//# sourceMappingURL=SessionManager.d.ts.map