@unicitylabs/sphere-sdk 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -550,10 +550,26 @@ var IndexedDBTokenStorageProvider = class {
550
550
  return meta !== null;
551
551
  }
552
552
  async clear() {
553
- if (!this.db) return false;
553
+ if (this.db) {
554
+ this.db.close();
555
+ this.db = null;
556
+ }
557
+ this.status = "disconnected";
558
+ const deleteDb = (name) => new Promise((resolve) => {
559
+ const req = indexedDB.deleteDatabase(name);
560
+ req.onsuccess = () => resolve();
561
+ req.onerror = () => resolve();
562
+ req.onblocked = () => resolve();
563
+ });
554
564
  try {
555
- await this.clearStore(STORE_TOKENS);
556
- await this.clearStore(STORE_META);
565
+ if (typeof indexedDB.databases === "function") {
566
+ const dbs = await indexedDB.databases();
567
+ await Promise.all(
568
+ dbs.filter((db) => db.name?.startsWith(this.dbNamePrefix)).map((db) => deleteDb(db.name))
569
+ );
570
+ } else {
571
+ await deleteDb(this.dbName);
572
+ }
557
573
  return true;
558
574
  } catch {
559
575
  return false;
@@ -1678,7 +1694,7 @@ var NostrTransportProvider = class {
1678
1694
  return this.resolveNametagInfo(identifier);
1679
1695
  }
1680
1696
  async resolveNametag(nametag) {
1681
- this.ensureReady();
1697
+ this.ensureConnected();
1682
1698
  const hashedNametag = (0, import_nostr_js_sdk.hashNametag)(nametag);
1683
1699
  let events = await this.queryEvents({
1684
1700
  kinds: [EVENT_KINDS.NAMETAG_BINDING],
@@ -1702,7 +1718,7 @@ var NostrTransportProvider = class {
1702
1718
  return null;
1703
1719
  }
1704
1720
  async resolveNametagInfo(nametag) {
1705
- this.ensureReady();
1721
+ this.ensureConnected();
1706
1722
  const hashedNametag = (0, import_nostr_js_sdk.hashNametag)(nametag);
1707
1723
  let events = await this.queryEvents({
1708
1724
  kinds: [EVENT_KINDS.NAMETAG_BINDING],
@@ -1779,7 +1795,7 @@ var NostrTransportProvider = class {
1779
1795
  * Works with both new identity binding events and legacy nametag binding events.
1780
1796
  */
1781
1797
  async resolveAddressInfo(address) {
1782
- this.ensureReady();
1798
+ this.ensureConnected();
1783
1799
  const addressHash = hashAddressForTag(address);
1784
1800
  const events = await this.queryEvents({
1785
1801
  kinds: [EVENT_KINDS.NAMETAG_BINDING],
@@ -1814,7 +1830,7 @@ var NostrTransportProvider = class {
1814
1830
  * Queries binding events authored by the given pubkey.
1815
1831
  */
1816
1832
  async resolveTransportPubkeyInfo(transportPubkey) {
1817
- this.ensureReady();
1833
+ this.ensureConnected();
1818
1834
  const events = await this.queryEvents({
1819
1835
  kinds: [EVENT_KINDS.NAMETAG_BINDING],
1820
1836
  authors: [transportPubkey],
@@ -2432,10 +2448,13 @@ var NostrTransportProvider = class {
2432
2448
  // ===========================================================================
2433
2449
  // Private: Helpers
2434
2450
  // ===========================================================================
2435
- ensureReady() {
2451
+ ensureConnected() {
2436
2452
  if (!this.isConnected()) {
2437
2453
  throw new Error("NostrTransportProvider not connected");
2438
2454
  }
2455
+ }
2456
+ ensureReady() {
2457
+ this.ensureConnected();
2439
2458
  if (!this.identity) {
2440
2459
  throw new Error("Identity not set");
2441
2460
  }