@unicitylabs/sphere-sdk 0.4.3 → 0.4.5

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.
Files changed (41) hide show
  1. package/dist/connect/index.cjs +10 -10
  2. package/dist/connect/index.cjs.map +1 -1
  3. package/dist/connect/index.js +10 -10
  4. package/dist/connect/index.js.map +1 -1
  5. package/dist/core/index.cjs +76 -28
  6. package/dist/core/index.cjs.map +1 -1
  7. package/dist/core/index.d.cts +6 -0
  8. package/dist/core/index.d.ts +6 -0
  9. package/dist/core/index.js +76 -28
  10. package/dist/core/index.js.map +1 -1
  11. package/dist/impl/browser/connect/index.cjs +10 -10
  12. package/dist/impl/browser/connect/index.cjs.map +1 -1
  13. package/dist/impl/browser/connect/index.js +10 -10
  14. package/dist/impl/browser/connect/index.js.map +1 -1
  15. package/dist/impl/browser/index.cjs +173 -108
  16. package/dist/impl/browser/index.cjs.map +1 -1
  17. package/dist/impl/browser/index.js +173 -108
  18. package/dist/impl/browser/index.js.map +1 -1
  19. package/dist/impl/browser/ipfs.cjs +10 -10
  20. package/dist/impl/browser/ipfs.cjs.map +1 -1
  21. package/dist/impl/browser/ipfs.js +10 -10
  22. package/dist/impl/browser/ipfs.js.map +1 -1
  23. package/dist/impl/nodejs/connect/index.cjs +10 -10
  24. package/dist/impl/nodejs/connect/index.cjs.map +1 -1
  25. package/dist/impl/nodejs/connect/index.js +10 -10
  26. package/dist/impl/nodejs/connect/index.js.map +1 -1
  27. package/dist/impl/nodejs/index.cjs +10 -10
  28. package/dist/impl/nodejs/index.cjs.map +1 -1
  29. package/dist/impl/nodejs/index.js +10 -10
  30. package/dist/impl/nodejs/index.js.map +1 -1
  31. package/dist/index.cjs +76 -28
  32. package/dist/index.cjs.map +1 -1
  33. package/dist/index.d.cts +24 -18
  34. package/dist/index.d.ts +24 -18
  35. package/dist/index.js +76 -28
  36. package/dist/index.js.map +1 -1
  37. package/dist/l1/index.cjs +21 -3
  38. package/dist/l1/index.cjs.map +1 -1
  39. package/dist/l1/index.js +21 -3
  40. package/dist/l1/index.js.map +1 -1
  41. package/package.json +1 -1
package/dist/index.d.cts CHANGED
@@ -3266,6 +3266,7 @@ declare class CommunicationsModule {
3266
3266
  private dmHandlers;
3267
3267
  private composingHandlers;
3268
3268
  private broadcastHandlers;
3269
+ private initializedAt;
3269
3270
  constructor(config?: CommunicationsModuleConfig);
3270
3271
  /**
3271
3272
  * Initialize module with dependencies
@@ -3394,6 +3395,11 @@ declare class GroupChatModule {
3394
3395
  private destroyConnection;
3395
3396
  connect(): Promise<void>;
3396
3397
  getConnectionStatus(): boolean;
3398
+ /**
3399
+ * Refresh subscriptions after load() switched to a different address.
3400
+ * Clears old subscriptions, restores groups if needed, and re-subscribes.
3401
+ */
3402
+ private refreshSubscriptions;
3397
3403
  private doConnect;
3398
3404
  private scheduleReconnect;
3399
3405
  private subscribeToJoinedGroups;
@@ -3661,15 +3667,7 @@ declare const STORAGE_KEYS_GLOBAL: {
3661
3667
  readonly TRACKED_ADDRESSES: "tracked_addresses";
3662
3668
  /** Last processed Nostr wallet event timestamp (unix seconds), keyed per pubkey */
3663
3669
  readonly LAST_WALLET_EVENT_TS: "last_wallet_event_ts";
3664
- /** Group chat: joined groups */
3665
- readonly GROUP_CHAT_GROUPS: "group_chat_groups";
3666
- /** Group chat: messages */
3667
- readonly GROUP_CHAT_MESSAGES: "group_chat_messages";
3668
- /** Group chat: members */
3669
- readonly GROUP_CHAT_MEMBERS: "group_chat_members";
3670
- /** Group chat: processed event IDs for deduplication */
3671
- readonly GROUP_CHAT_PROCESSED_EVENTS: "group_chat_processed_events";
3672
- /** Group chat: last used relay URL (stale data detection) */
3670
+ /** Group chat: last used relay URL (stale data detection) — global, same relay for all addresses */
3673
3671
  readonly GROUP_CHAT_RELAY_URL: "group_chat_relay_url";
3674
3672
  /** Cached token registry JSON (fetched from remote) */
3675
3673
  readonly TOKEN_REGISTRY_CACHE: "token_registry_cache";
@@ -3701,6 +3699,14 @@ declare const STORAGE_KEYS_ADDRESS: {
3701
3699
  readonly TRANSACTION_HISTORY: "transaction_history";
3702
3700
  /** Pending V5 finalization tokens (unconfirmed instant split tokens) */
3703
3701
  readonly PENDING_V5_TOKENS: "pending_v5_tokens";
3702
+ /** Group chat: joined groups for this address */
3703
+ readonly GROUP_CHAT_GROUPS: "group_chat_groups";
3704
+ /** Group chat: messages for this address */
3705
+ readonly GROUP_CHAT_MESSAGES: "group_chat_messages";
3706
+ /** Group chat: members for this address */
3707
+ readonly GROUP_CHAT_MEMBERS: "group_chat_members";
3708
+ /** Group chat: processed event IDs for deduplication */
3709
+ readonly GROUP_CHAT_PROCESSED_EVENTS: "group_chat_processed_events";
3704
3710
  };
3705
3711
  /** @deprecated Use STORAGE_KEYS_GLOBAL and STORAGE_KEYS_ADDRESS instead */
3706
3712
  declare const STORAGE_KEYS: {
@@ -3716,6 +3722,14 @@ declare const STORAGE_KEYS: {
3716
3722
  readonly TRANSACTION_HISTORY: "transaction_history";
3717
3723
  /** Pending V5 finalization tokens (unconfirmed instant split tokens) */
3718
3724
  readonly PENDING_V5_TOKENS: "pending_v5_tokens";
3725
+ /** Group chat: joined groups for this address */
3726
+ readonly GROUP_CHAT_GROUPS: "group_chat_groups";
3727
+ /** Group chat: messages for this address */
3728
+ readonly GROUP_CHAT_MESSAGES: "group_chat_messages";
3729
+ /** Group chat: members for this address */
3730
+ readonly GROUP_CHAT_MEMBERS: "group_chat_members";
3731
+ /** Group chat: processed event IDs for deduplication */
3732
+ readonly GROUP_CHAT_PROCESSED_EVENTS: "group_chat_processed_events";
3719
3733
  /** Encrypted BIP39 mnemonic */
3720
3734
  readonly MNEMONIC: "mnemonic";
3721
3735
  /** Encrypted master private key */
@@ -3740,15 +3754,7 @@ declare const STORAGE_KEYS: {
3740
3754
  readonly TRACKED_ADDRESSES: "tracked_addresses";
3741
3755
  /** Last processed Nostr wallet event timestamp (unix seconds), keyed per pubkey */
3742
3756
  readonly LAST_WALLET_EVENT_TS: "last_wallet_event_ts";
3743
- /** Group chat: joined groups */
3744
- readonly GROUP_CHAT_GROUPS: "group_chat_groups";
3745
- /** Group chat: messages */
3746
- readonly GROUP_CHAT_MESSAGES: "group_chat_messages";
3747
- /** Group chat: members */
3748
- readonly GROUP_CHAT_MEMBERS: "group_chat_members";
3749
- /** Group chat: processed event IDs for deduplication */
3750
- readonly GROUP_CHAT_PROCESSED_EVENTS: "group_chat_processed_events";
3751
- /** Group chat: last used relay URL (stale data detection) */
3757
+ /** Group chat: last used relay URL (stale data detection) — global, same relay for all addresses */
3752
3758
  readonly GROUP_CHAT_RELAY_URL: "group_chat_relay_url";
3753
3759
  /** Cached token registry JSON (fetched from remote) */
3754
3760
  readonly TOKEN_REGISTRY_CACHE: "token_registry_cache";
package/dist/index.d.ts CHANGED
@@ -3266,6 +3266,7 @@ declare class CommunicationsModule {
3266
3266
  private dmHandlers;
3267
3267
  private composingHandlers;
3268
3268
  private broadcastHandlers;
3269
+ private initializedAt;
3269
3270
  constructor(config?: CommunicationsModuleConfig);
3270
3271
  /**
3271
3272
  * Initialize module with dependencies
@@ -3394,6 +3395,11 @@ declare class GroupChatModule {
3394
3395
  private destroyConnection;
3395
3396
  connect(): Promise<void>;
3396
3397
  getConnectionStatus(): boolean;
3398
+ /**
3399
+ * Refresh subscriptions after load() switched to a different address.
3400
+ * Clears old subscriptions, restores groups if needed, and re-subscribes.
3401
+ */
3402
+ private refreshSubscriptions;
3397
3403
  private doConnect;
3398
3404
  private scheduleReconnect;
3399
3405
  private subscribeToJoinedGroups;
@@ -3661,15 +3667,7 @@ declare const STORAGE_KEYS_GLOBAL: {
3661
3667
  readonly TRACKED_ADDRESSES: "tracked_addresses";
3662
3668
  /** Last processed Nostr wallet event timestamp (unix seconds), keyed per pubkey */
3663
3669
  readonly LAST_WALLET_EVENT_TS: "last_wallet_event_ts";
3664
- /** Group chat: joined groups */
3665
- readonly GROUP_CHAT_GROUPS: "group_chat_groups";
3666
- /** Group chat: messages */
3667
- readonly GROUP_CHAT_MESSAGES: "group_chat_messages";
3668
- /** Group chat: members */
3669
- readonly GROUP_CHAT_MEMBERS: "group_chat_members";
3670
- /** Group chat: processed event IDs for deduplication */
3671
- readonly GROUP_CHAT_PROCESSED_EVENTS: "group_chat_processed_events";
3672
- /** Group chat: last used relay URL (stale data detection) */
3670
+ /** Group chat: last used relay URL (stale data detection) — global, same relay for all addresses */
3673
3671
  readonly GROUP_CHAT_RELAY_URL: "group_chat_relay_url";
3674
3672
  /** Cached token registry JSON (fetched from remote) */
3675
3673
  readonly TOKEN_REGISTRY_CACHE: "token_registry_cache";
@@ -3701,6 +3699,14 @@ declare const STORAGE_KEYS_ADDRESS: {
3701
3699
  readonly TRANSACTION_HISTORY: "transaction_history";
3702
3700
  /** Pending V5 finalization tokens (unconfirmed instant split tokens) */
3703
3701
  readonly PENDING_V5_TOKENS: "pending_v5_tokens";
3702
+ /** Group chat: joined groups for this address */
3703
+ readonly GROUP_CHAT_GROUPS: "group_chat_groups";
3704
+ /** Group chat: messages for this address */
3705
+ readonly GROUP_CHAT_MESSAGES: "group_chat_messages";
3706
+ /** Group chat: members for this address */
3707
+ readonly GROUP_CHAT_MEMBERS: "group_chat_members";
3708
+ /** Group chat: processed event IDs for deduplication */
3709
+ readonly GROUP_CHAT_PROCESSED_EVENTS: "group_chat_processed_events";
3704
3710
  };
3705
3711
  /** @deprecated Use STORAGE_KEYS_GLOBAL and STORAGE_KEYS_ADDRESS instead */
3706
3712
  declare const STORAGE_KEYS: {
@@ -3716,6 +3722,14 @@ declare const STORAGE_KEYS: {
3716
3722
  readonly TRANSACTION_HISTORY: "transaction_history";
3717
3723
  /** Pending V5 finalization tokens (unconfirmed instant split tokens) */
3718
3724
  readonly PENDING_V5_TOKENS: "pending_v5_tokens";
3725
+ /** Group chat: joined groups for this address */
3726
+ readonly GROUP_CHAT_GROUPS: "group_chat_groups";
3727
+ /** Group chat: messages for this address */
3728
+ readonly GROUP_CHAT_MESSAGES: "group_chat_messages";
3729
+ /** Group chat: members for this address */
3730
+ readonly GROUP_CHAT_MEMBERS: "group_chat_members";
3731
+ /** Group chat: processed event IDs for deduplication */
3732
+ readonly GROUP_CHAT_PROCESSED_EVENTS: "group_chat_processed_events";
3719
3733
  /** Encrypted BIP39 mnemonic */
3720
3734
  readonly MNEMONIC: "mnemonic";
3721
3735
  /** Encrypted master private key */
@@ -3740,15 +3754,7 @@ declare const STORAGE_KEYS: {
3740
3754
  readonly TRACKED_ADDRESSES: "tracked_addresses";
3741
3755
  /** Last processed Nostr wallet event timestamp (unix seconds), keyed per pubkey */
3742
3756
  readonly LAST_WALLET_EVENT_TS: "last_wallet_event_ts";
3743
- /** Group chat: joined groups */
3744
- readonly GROUP_CHAT_GROUPS: "group_chat_groups";
3745
- /** Group chat: messages */
3746
- readonly GROUP_CHAT_MESSAGES: "group_chat_messages";
3747
- /** Group chat: members */
3748
- readonly GROUP_CHAT_MEMBERS: "group_chat_members";
3749
- /** Group chat: processed event IDs for deduplication */
3750
- readonly GROUP_CHAT_PROCESSED_EVENTS: "group_chat_processed_events";
3751
- /** Group chat: last used relay URL (stale data detection) */
3757
+ /** Group chat: last used relay URL (stale data detection) — global, same relay for all addresses */
3752
3758
  readonly GROUP_CHAT_RELAY_URL: "group_chat_relay_url";
3753
3759
  /** Cached token registry JSON (fetched from remote) */
3754
3760
  readonly TOKEN_REGISTRY_CACHE: "token_registry_cache";
package/dist/index.js CHANGED
@@ -850,6 +850,12 @@ var VestingClassifier = class {
850
850
  };
851
851
  request.onsuccess = (event) => {
852
852
  this.db = event.target.result;
853
+ this.db.onversionchange = () => {
854
+ if (this.db) {
855
+ this.db.close();
856
+ this.db = null;
857
+ }
858
+ };
853
859
  resolve();
854
860
  };
855
861
  request.onerror = () => reject(request.error);
@@ -1058,9 +1064,21 @@ var VestingClassifier = class {
1058
1064
  if (typeof indexedDB !== "undefined") {
1059
1065
  await new Promise((resolve) => {
1060
1066
  const req = indexedDB.deleteDatabase(this.dbName);
1061
- req.onsuccess = () => resolve();
1062
- req.onerror = () => resolve();
1063
- req.onblocked = () => resolve();
1067
+ const timer = setTimeout(() => {
1068
+ console.warn(`[VestingClassifier] destroy: deleteDatabase timed out for ${this.dbName}`);
1069
+ resolve();
1070
+ }, 3e3);
1071
+ req.onsuccess = () => {
1072
+ clearTimeout(timer);
1073
+ resolve();
1074
+ };
1075
+ req.onerror = () => {
1076
+ clearTimeout(timer);
1077
+ resolve();
1078
+ };
1079
+ req.onblocked = () => {
1080
+ console.warn(`[VestingClassifier] destroy: deleteDatabase blocked for ${this.dbName}, waiting...`);
1081
+ };
1064
1082
  });
1065
1083
  }
1066
1084
  }
@@ -2485,15 +2503,7 @@ var STORAGE_KEYS_GLOBAL = {
2485
2503
  TRACKED_ADDRESSES: "tracked_addresses",
2486
2504
  /** Last processed Nostr wallet event timestamp (unix seconds), keyed per pubkey */
2487
2505
  LAST_WALLET_EVENT_TS: "last_wallet_event_ts",
2488
- /** Group chat: joined groups */
2489
- GROUP_CHAT_GROUPS: "group_chat_groups",
2490
- /** Group chat: messages */
2491
- GROUP_CHAT_MESSAGES: "group_chat_messages",
2492
- /** Group chat: members */
2493
- GROUP_CHAT_MEMBERS: "group_chat_members",
2494
- /** Group chat: processed event IDs for deduplication */
2495
- GROUP_CHAT_PROCESSED_EVENTS: "group_chat_processed_events",
2496
- /** Group chat: last used relay URL (stale data detection) */
2506
+ /** Group chat: last used relay URL (stale data detection) — global, same relay for all addresses */
2497
2507
  GROUP_CHAT_RELAY_URL: "group_chat_relay_url",
2498
2508
  /** Cached token registry JSON (fetched from remote) */
2499
2509
  TOKEN_REGISTRY_CACHE: "token_registry_cache",
@@ -2516,7 +2526,15 @@ var STORAGE_KEYS_ADDRESS = {
2516
2526
  /** Transaction history for this address */
2517
2527
  TRANSACTION_HISTORY: "transaction_history",
2518
2528
  /** Pending V5 finalization tokens (unconfirmed instant split tokens) */
2519
- PENDING_V5_TOKENS: "pending_v5_tokens"
2529
+ PENDING_V5_TOKENS: "pending_v5_tokens",
2530
+ /** Group chat: joined groups for this address */
2531
+ GROUP_CHAT_GROUPS: "group_chat_groups",
2532
+ /** Group chat: messages for this address */
2533
+ GROUP_CHAT_MESSAGES: "group_chat_messages",
2534
+ /** Group chat: members for this address */
2535
+ GROUP_CHAT_MEMBERS: "group_chat_members",
2536
+ /** Group chat: processed event IDs for deduplication */
2537
+ GROUP_CHAT_PROCESSED_EVENTS: "group_chat_processed_events"
2520
2538
  };
2521
2539
  var STORAGE_KEYS = {
2522
2540
  ...STORAGE_KEYS_GLOBAL,
@@ -7627,6 +7645,8 @@ var CommunicationsModule = class {
7627
7645
  dmHandlers = /* @__PURE__ */ new Set();
7628
7646
  composingHandlers = /* @__PURE__ */ new Set();
7629
7647
  broadcastHandlers = /* @__PURE__ */ new Set();
7648
+ // Timestamp of module initialization — messages older than this are historical
7649
+ initializedAt = 0;
7630
7650
  constructor(config) {
7631
7651
  this.config = {
7632
7652
  autoSave: config?.autoSave ?? true,
@@ -7645,6 +7665,7 @@ var CommunicationsModule = class {
7645
7665
  this.unsubscribeMessages?.();
7646
7666
  this.unsubscribeComposing?.();
7647
7667
  this.deps = deps;
7668
+ this.initializedAt = Date.now();
7648
7669
  this.unsubscribeMessages = deps.transport.onMessage((msg) => {
7649
7670
  this.handleIncomingMessage(msg);
7650
7671
  });
@@ -7936,6 +7957,7 @@ var CommunicationsModule = class {
7936
7957
  // Private: Message Handling
7937
7958
  // ===========================================================================
7938
7959
  handleIncomingMessage(msg) {
7960
+ const isHistorical = msg.timestamp < this.initializedAt;
7939
7961
  if (msg.isSelfWrap && msg.recipientTransportPubkey) {
7940
7962
  if (this.messages.has(msg.id)) return;
7941
7963
  const message2 = {
@@ -7945,7 +7967,7 @@ var CommunicationsModule = class {
7945
7967
  recipientPubkey: msg.recipientTransportPubkey,
7946
7968
  content: msg.content,
7947
7969
  timestamp: msg.timestamp,
7948
- isRead: false
7970
+ isRead: isHistorical
7949
7971
  };
7950
7972
  this.messages.set(message2.id, message2);
7951
7973
  this.deps.emitEvent("message:dm", message2);
@@ -7963,7 +7985,7 @@ var CommunicationsModule = class {
7963
7985
  recipientPubkey: this.deps.identity.chainPubkey,
7964
7986
  content: msg.content,
7965
7987
  timestamp: msg.timestamp,
7966
- isRead: false
7988
+ isRead: isHistorical
7967
7989
  };
7968
7990
  this.messages.set(message.id, message);
7969
7991
  this.deps.emitEvent("message:dm", message);
@@ -8139,22 +8161,24 @@ var GroupChatModule = class {
8139
8161
  async load() {
8140
8162
  this.ensureInitialized();
8141
8163
  const storage = this.deps.storage;
8142
- const groupsJson = await storage.get(STORAGE_KEYS_GLOBAL.GROUP_CHAT_GROUPS);
8164
+ this.groups.clear();
8165
+ this.messages.clear();
8166
+ this.members.clear();
8167
+ this.processedEventIds.clear();
8168
+ const groupsJson = await storage.get(STORAGE_KEYS_ADDRESS.GROUP_CHAT_GROUPS);
8143
8169
  if (groupsJson) {
8144
8170
  try {
8145
8171
  const parsed = JSON.parse(groupsJson);
8146
- this.groups.clear();
8147
8172
  for (const g of parsed) {
8148
8173
  this.groups.set(g.id, g);
8149
8174
  }
8150
8175
  } catch {
8151
8176
  }
8152
8177
  }
8153
- const messagesJson = await storage.get(STORAGE_KEYS_GLOBAL.GROUP_CHAT_MESSAGES);
8178
+ const messagesJson = await storage.get(STORAGE_KEYS_ADDRESS.GROUP_CHAT_MESSAGES);
8154
8179
  if (messagesJson) {
8155
8180
  try {
8156
8181
  const parsed = JSON.parse(messagesJson);
8157
- this.messages.clear();
8158
8182
  for (const m of parsed) {
8159
8183
  const groupId = m.groupId;
8160
8184
  if (!this.messages.has(groupId)) {
@@ -8165,11 +8189,10 @@ var GroupChatModule = class {
8165
8189
  } catch {
8166
8190
  }
8167
8191
  }
8168
- const membersJson = await storage.get(STORAGE_KEYS_GLOBAL.GROUP_CHAT_MEMBERS);
8192
+ const membersJson = await storage.get(STORAGE_KEYS_ADDRESS.GROUP_CHAT_MEMBERS);
8169
8193
  if (membersJson) {
8170
8194
  try {
8171
8195
  const parsed = JSON.parse(membersJson);
8172
- this.members.clear();
8173
8196
  for (const m of parsed) {
8174
8197
  const groupId = m.groupId;
8175
8198
  if (!this.members.has(groupId)) {
@@ -8180,7 +8203,7 @@ var GroupChatModule = class {
8180
8203
  } catch {
8181
8204
  }
8182
8205
  }
8183
- const processedJson = await storage.get(STORAGE_KEYS_GLOBAL.GROUP_CHAT_PROCESSED_EVENTS);
8206
+ const processedJson = await storage.get(STORAGE_KEYS_ADDRESS.GROUP_CHAT_PROCESSED_EVENTS);
8184
8207
  if (processedJson) {
8185
8208
  try {
8186
8209
  const parsed = JSON.parse(processedJson);
@@ -8234,7 +8257,10 @@ var GroupChatModule = class {
8234
8257
  // Connection
8235
8258
  // ===========================================================================
8236
8259
  async connect() {
8237
- if (this.connected) return;
8260
+ if (this.connected) {
8261
+ await this.refreshSubscriptions();
8262
+ return;
8263
+ }
8238
8264
  if (this.connectPromise) {
8239
8265
  return this.connectPromise;
8240
8266
  }
@@ -8248,6 +8274,28 @@ var GroupChatModule = class {
8248
8274
  getConnectionStatus() {
8249
8275
  return this.connected;
8250
8276
  }
8277
+ /**
8278
+ * Refresh subscriptions after load() switched to a different address.
8279
+ * Clears old subscriptions, restores groups if needed, and re-subscribes.
8280
+ */
8281
+ async refreshSubscriptions() {
8282
+ if (!this.client) return;
8283
+ for (const subId of this.subscriptionIds) {
8284
+ try {
8285
+ this.client.unsubscribe(subId);
8286
+ } catch {
8287
+ }
8288
+ }
8289
+ this.subscriptionIds = [];
8290
+ const secretKey = Buffer.from(this.deps.identity.privateKey, "hex");
8291
+ this.keyManager = NostrKeyManager.fromPrivateKey(secretKey);
8292
+ if (this.groups.size === 0) {
8293
+ await this.restoreJoinedGroups();
8294
+ } else {
8295
+ await this.subscribeToJoinedGroups();
8296
+ }
8297
+ this.deps.emitEvent("groupchat:connection", { connected: true });
8298
+ }
8251
8299
  async doConnect() {
8252
8300
  this.ensureInitialized();
8253
8301
  if (!this.keyManager) {
@@ -8263,12 +8311,12 @@ var GroupChatModule = class {
8263
8311
  await this.client.connect(...this.config.relays);
8264
8312
  this.connected = true;
8265
8313
  this.reconnectAttempts = 0;
8266
- this.deps.emitEvent("groupchat:connection", { connected: true });
8267
8314
  if (this.groups.size === 0) {
8268
8315
  await this.restoreJoinedGroups();
8269
8316
  } else {
8270
8317
  await this.subscribeToJoinedGroups();
8271
8318
  }
8319
+ this.deps.emitEvent("groupchat:connection", { connected: true });
8272
8320
  } catch (error) {
8273
8321
  console.error("[GroupChat] Failed to connect to relays", error);
8274
8322
  this.deps.emitEvent("groupchat:connection", { connected: false });
@@ -9251,7 +9299,7 @@ var GroupChatModule = class {
9251
9299
  async persistGroups() {
9252
9300
  if (!this.deps) return;
9253
9301
  const data = Array.from(this.groups.values());
9254
- await this.deps.storage.set(STORAGE_KEYS_GLOBAL.GROUP_CHAT_GROUPS, JSON.stringify(data));
9302
+ await this.deps.storage.set(STORAGE_KEYS_ADDRESS.GROUP_CHAT_GROUPS, JSON.stringify(data));
9255
9303
  }
9256
9304
  async persistMessages() {
9257
9305
  if (!this.deps) return;
@@ -9259,7 +9307,7 @@ var GroupChatModule = class {
9259
9307
  for (const msgs of this.messages.values()) {
9260
9308
  allMessages.push(...msgs);
9261
9309
  }
9262
- await this.deps.storage.set(STORAGE_KEYS_GLOBAL.GROUP_CHAT_MESSAGES, JSON.stringify(allMessages));
9310
+ await this.deps.storage.set(STORAGE_KEYS_ADDRESS.GROUP_CHAT_MESSAGES, JSON.stringify(allMessages));
9263
9311
  }
9264
9312
  async persistMembers() {
9265
9313
  if (!this.deps) return;
@@ -9267,12 +9315,12 @@ var GroupChatModule = class {
9267
9315
  for (const mems of this.members.values()) {
9268
9316
  allMembers.push(...mems);
9269
9317
  }
9270
- await this.deps.storage.set(STORAGE_KEYS_GLOBAL.GROUP_CHAT_MEMBERS, JSON.stringify(allMembers));
9318
+ await this.deps.storage.set(STORAGE_KEYS_ADDRESS.GROUP_CHAT_MEMBERS, JSON.stringify(allMembers));
9271
9319
  }
9272
9320
  async persistProcessedEvents() {
9273
9321
  if (!this.deps) return;
9274
9322
  const arr = Array.from(this.processedEventIds);
9275
- await this.deps.storage.set(STORAGE_KEYS_GLOBAL.GROUP_CHAT_PROCESSED_EVENTS, JSON.stringify(arr));
9323
+ await this.deps.storage.set(STORAGE_KEYS_ADDRESS.GROUP_CHAT_PROCESSED_EVENTS, JSON.stringify(arr));
9276
9324
  }
9277
9325
  // ===========================================================================
9278
9326
  // Private — Relay URL Change Detection