UNPKG

ribbit-wallet-connect

Version:

Next-generation multi-chain wallet and payments app that makes crypto simple, secure, and usable in daily life.

50 lines (49 loc) 1.45 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SessionManager = void 0; const crypto_1 = require("../utils/crypto"); class SessionManager { constructor() { this.sessions = new Map(); this.currentSessionId = null; } createSession(dapp) { const sessionId = this.generateSessionId(); const session = { sessionId, active: true, dapp }; this.sessions.set(sessionId, session); this.currentSessionId = sessionId; return session; } getSession(sessionId) { return this.sessions.get(sessionId); } getCurrentSession() { if (!this.currentSessionId) return null; const session = this.getSession(this.currentSessionId); return session !== null && session !== void 0 ? session : null; } validateSession(sessionId) { const session = this.getSession(sessionId); if (!session) return false; return session.active; } disconnect(sessionId) { const session = this.getSession(sessionId); if (session) { session.active = false; } if (this.currentSessionId === sessionId) { this.currentSessionId = null; } } generateSessionId() { return crypto_1.CryptoUtils.generateSessionId(); } } exports.SessionManager = SessionManager;