{"version":3,"file":"validation.cjs","names":["#dbName","#dbVersion","#storeName","#db","#dbPromise","#withTransaction","#getDB","z","ConfigurationError"],"sources":["../../src/storage/indexeddb-storage.ts","../../src/validation.ts"],"sourcesContent":["\"use client\";\n\nimport type { GenericStorage } from \"../types\";\n\n/**\n * IndexedDB-backed {@link GenericStorage}.\n *\n * Stores keypair and permit objects keyed by a hashed wallet address. The\n * SDK delegates security to the storage backend — values are persisted\n * verbatim with no SDK-layer encryption.\n */\nexport class IndexedDBStorage implements GenericStorage {\n  #db: IDBDatabase | null = null;\n  #dbPromise: Promise<IDBDatabase> | null = null;\n  #dbName: string;\n  #dbVersion: number;\n  #storeName: string;\n\n  constructor(dbName = \"CredentialStore\", dbVersion = 1, storeName = \"credentials\") {\n    this.#dbName = dbName;\n    this.#dbVersion = dbVersion;\n    this.#storeName = storeName;\n  }\n\n  #getDB(): Promise<IDBDatabase> {\n    if (this.#db) {\n      return Promise.resolve(this.#db);\n    }\n    if (this.#dbPromise) {\n      return this.#dbPromise;\n    }\n\n    this.#dbPromise = new Promise((resolve, reject) => {\n      const request = indexedDB.open(this.#dbName, this.#dbVersion);\n\n      request.onupgradeneeded = () => {\n        const db = request.result;\n        if (!db.objectStoreNames.contains(this.#storeName)) {\n          db.createObjectStore(this.#storeName, { keyPath: \"key\" });\n        }\n      };\n\n      request.onsuccess = () => {\n        this.#db = request.result;\n        this.#dbPromise = null;\n        this.#db.onversionchange = () => {\n          // Another tab upgraded the DB; close our handle so it can proceed.\n          // Informational only and self-healing, so emit nothing to the console.\n          this.#db?.close();\n          this.#db = null;\n          this.#dbPromise = null;\n        };\n        this.#db.onclose = () => {\n          this.#db = null;\n          this.#dbPromise = null;\n        };\n        resolve(this.#db);\n      };\n\n      request.onerror = () => {\n        this.#db = null;\n        this.#dbPromise = null;\n        reject(request.error);\n      };\n    });\n\n    return this.#dbPromise;\n  }\n\n  async #withTransaction<T>(\n    mode: IDBTransactionMode,\n    fn: (store: IDBObjectStore) => IDBRequest,\n  ): Promise<T> {\n    const db = await this.#getDB();\n    return new Promise((resolve, reject) => {\n      const tx = db.transaction(this.#storeName, mode);\n      tx.onabort = () => reject(tx.error ?? new Error(\"Transaction aborted\"));\n      const request = fn(tx.objectStore(this.#storeName));\n      if (mode === \"readonly\") {\n        request.onsuccess = () => resolve(request.result);\n      } else {\n        tx.oncomplete = () => resolve(request.result);\n      }\n      request.onerror = () => reject(request.error);\n    });\n  }\n\n  async get<T = unknown>(key: string): Promise<T | null> {\n    const result = await this.#withTransaction<{ value: T } | undefined>(\"readonly\", (store) =>\n      store.get(key),\n    );\n    return result?.value ?? null;\n  }\n\n  async set<T = unknown>(key: string, value: T): Promise<void> {\n    await this.#withTransaction<void>(\"readwrite\", (store) => store.put({ key, value }));\n  }\n\n  async delete(key: string): Promise<void> {\n    await this.#withTransaction<void>(\"readwrite\", (store) => store.delete(key));\n  }\n\n  async clear(): Promise<void> {\n    await this.#withTransaction<void>(\"readwrite\", (store) => store.clear());\n  }\n}\n\n/** Default singleton for application-wide use. */\nexport const indexedDBStorage = new IndexedDBStorage();\n","import { z } from \"zod/mini\";\nimport { ConfigurationError } from \"./errors\";\n\nexport function parseConfiguration<T>(schema: z.core.$ZodType<T>, value: unknown): T {\n  const parsed = z.safeParse(schema, value);\n  if (parsed.success) {\n    return parsed.data;\n  }\n  throw new ConfigurationError(z.prettifyError(parsed.error), { cause: parsed.error });\n}\n"],"mappings":"2DAWA,IAAa,EAAb,KAAwD,CACtD,GAA0B,KAC1B,GAA0C,KAC1C,GACA,GACA,GAEA,YAAY,EAAS,kBAAmB,EAAY,EAAG,EAAY,cAAe,CAChF,KAAKA,GAAU,EACf,KAAKC,GAAa,EAClB,KAAKC,GAAa,CACpB,CAEA,IAA+B,CA0C7B,OAzCI,KAAKC,GACA,QAAQ,QAAQ,KAAKA,EAAG,GAE7B,AAIJ,KAAKC,KAAa,IAAI,SAAS,EAAS,IAAW,CACjD,IAAM,EAAU,UAAU,KAAK,KAAKJ,GAAS,KAAK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