@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.
@@ -492,10 +492,26 @@ var IndexedDBTokenStorageProvider = class {
492
492
  return meta !== null;
493
493
  }
494
494
  async clear() {
495
- if (!this.db) return false;
495
+ if (this.db) {
496
+ this.db.close();
497
+ this.db = null;
498
+ }
499
+ this.status = "disconnected";
500
+ const deleteDb = (name) => new Promise((resolve) => {
501
+ const req = indexedDB.deleteDatabase(name);
502
+ req.onsuccess = () => resolve();
503
+ req.onerror = () => resolve();
504
+ req.onblocked = () => resolve();
505
+ });
496
506
  try {
497
- await this.clearStore(STORE_TOKENS);
498
- await this.clearStore(STORE_META);
507
+ if (typeof indexedDB.databases === "function") {
508
+ const dbs = await indexedDB.databases();
509
+ await Promise.all(
510
+ dbs.filter((db) => db.name?.startsWith(this.dbNamePrefix)).map((db) => deleteDb(db.name))
511
+ );
512
+ } else {
513
+ await deleteDb(this.dbName);
514
+ }
499
515
  return true;
500
516
  } catch {
501
517
  return false;
@@ -1629,7 +1645,7 @@ var NostrTransportProvider = class {
1629
1645
  return this.resolveNametagInfo(identifier);
1630
1646
  }
1631
1647
  async resolveNametag(nametag) {
1632
- this.ensureReady();
1648
+ this.ensureConnected();
1633
1649
  const hashedNametag = hashNametag(nametag);
1634
1650
  let events = await this.queryEvents({
1635
1651
  kinds: [EVENT_KINDS.NAMETAG_BINDING],
@@ -1653,7 +1669,7 @@ var NostrTransportProvider = class {
1653
1669
  return null;
1654
1670
  }
1655
1671
  async resolveNametagInfo(nametag) {
1656
- this.ensureReady();
1672
+ this.ensureConnected();
1657
1673
  const hashedNametag = hashNametag(nametag);
1658
1674
  let events = await this.queryEvents({
1659
1675
  kinds: [EVENT_KINDS.NAMETAG_BINDING],
@@ -1730,7 +1746,7 @@ var NostrTransportProvider = class {
1730
1746
  * Works with both new identity binding events and legacy nametag binding events.
1731
1747
  */
1732
1748
  async resolveAddressInfo(address) {
1733
- this.ensureReady();
1749
+ this.ensureConnected();
1734
1750
  const addressHash = hashAddressForTag(address);
1735
1751
  const events = await this.queryEvents({
1736
1752
  kinds: [EVENT_KINDS.NAMETAG_BINDING],
@@ -1765,7 +1781,7 @@ var NostrTransportProvider = class {
1765
1781
  * Queries binding events authored by the given pubkey.
1766
1782
  */
1767
1783
  async resolveTransportPubkeyInfo(transportPubkey) {
1768
- this.ensureReady();
1784
+ this.ensureConnected();
1769
1785
  const events = await this.queryEvents({
1770
1786
  kinds: [EVENT_KINDS.NAMETAG_BINDING],
1771
1787
  authors: [transportPubkey],
@@ -2383,10 +2399,13 @@ var NostrTransportProvider = class {
2383
2399
  // ===========================================================================
2384
2400
  // Private: Helpers
2385
2401
  // ===========================================================================
2386
- ensureReady() {
2402
+ ensureConnected() {
2387
2403
  if (!this.isConnected()) {
2388
2404
  throw new Error("NostrTransportProvider not connected");
2389
2405
  }
2406
+ }
2407
+ ensureReady() {
2408
+ this.ensureConnected();
2390
2409
  if (!this.identity) {
2391
2410
  throw new Error("Identity not set");
2392
2411
  }