{"version":3,"file":"connectionsStorage-CkvX06QD.mjs","names":[],"sources":["../src/connectionsStorage/index.ts"],"sourcesContent":["import { ccc } from \"@ckb-ccc/core\";\n\n/**\n * Persisted NIP-07 connection information.\n * @public\n */\nexport interface Connection {\n  publicKey: ccc.Hex;\n}\n\n/**\n * Repository used to restore a NIP-07 connection without contacting the wallet.\n * @public\n */\nexport interface ConnectionsRepo {\n  get(): Promise<Connection | undefined>;\n  set(connection: Connection | undefined): Promise<void>;\n}\n\n/**\n * Local storage based NIP-07 connection repository.\n * @public\n */\nexport class ConnectionsRepoLocalStorage implements ConnectionsRepo {\n  constructor(private readonly storageKey = \"ccc-nip07-signer\") {}\n\n  async get(): Promise<Connection | undefined> {\n    let stored: string | null;\n    try {\n      stored = window.localStorage.getItem(this.storageKey);\n    } catch {\n      return;\n    }\n    if (!stored) {\n      return;\n    }\n\n    try {\n      const connection = JSON.parse(stored) as Partial<Connection>;\n      if (typeof connection.publicKey !== \"string\") {\n        throw new Error(\"Invalid persisted NIP-07 connection\");\n      }\n\n      return {\n        publicKey: ccc.hexFrom(connection.publicKey),\n      };\n    } catch {\n      try {\n        window.localStorage.removeItem(this.storageKey);\n      } catch {\n        // Ignore storage cleanup failures.\n      }\n      return;\n    }\n  }\n\n  async set(connection: Connection | undefined): Promise<void> {\n    try {\n      if (!connection) {\n        window.localStorage.removeItem(this.storageKey);\n        return;\n      }\n\n      window.localStorage.setItem(\n        this.storageKey,\n        JSON.stringify({\n          publicKey: connection.publicKey,\n        }),\n      );\n    } catch {\n      // Persistence is best-effort; keep the signer's in-memory connection.\n    }\n  }\n}\n"],"mappings":"oCAuBA,IAAa,EAAb,KAAoE,CAClE,YAAY,EAA8B,mBAAoB,CAAjC,KAAA,WAAA,CAAkC,CAE/D,MAAM,KAAuC,CAC3C,IAAI,EACJ,GAAI,CACF,EAAS,OAAO,aAAa,QAAQ,KAAK,UAAU,CACtD,MAAQ,CACN,MACF,CACK,KAIL,GAAI,CACF,IAAM,EAAa,KAAK,MAAM,CAAM,EACpC,GAAI,OAAO,EAAW,WAAc,SAClC,MAAU,MAAM,qCAAqC,EAGvD,MAAO,CACL,UAAW,EAAI,QAAQ,EAAW,SAAS,CAC7C,CACF,MAAQ,CACN,GAAI,CACF,OAAO,aAAa,WAAW,KAAK,UAAU,CAChD,MAAQ,CAER,CACA,MACF,CACF,CAEA,MAAM,IAAI,EAAmD,CAC3D,GAAI,CACF,GAAI,CAAC,EAAY,CACf,OAAO,aAAa,WAAW,KAAK,UAAU,EAC9C,MACF,CAEA,OAAO,aAAa,QAClB,KAAK,WACL,KAAK,UAAU,CACb,UAAW,EAAW,SACxB,CAAC,CACH,CACF,MAAQ,CAER,CACF,CACF"}