/** * In-memory credential store. For tests and ephemeral CLI sessions. */ import type { CredentialStore, Did, PublisherSession } from "./types.js"; export class MemoryCredentialStore implements CredentialStore { #sessions = new Map(); #currentDid: Did | null = null; async current(): Promise { if (!this.#currentDid) return null; return this.#sessions.get(this.#currentDid) ?? null; } async get(did: Did): Promise { return this.#sessions.get(did) ?? null; } async list(): Promise { return [...this.#sessions.values()]; } async put(session: PublisherSession): Promise { this.#sessions.set(session.did, { ...session }); if (!this.#currentDid) this.#currentDid = session.did; } async setCurrent(did: Did): Promise { if (!this.#sessions.has(did)) { throw new Error(`no stored session for ${did}`); } this.#currentDid = did; } async remove(did: Did): Promise { this.#sessions.delete(did); if (this.#currentDid === did) this.#currentDid = null; } }