@unicitylabs/sphere-sdk 0.8.0-dev.3 → 0.8.0-dev.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.
@@ -7280,6 +7280,19 @@ var TokenRegistry = class _TokenRegistry {
7280
7280
  // ===========================================================================
7281
7281
  // Cache (StorageProvider)
7282
7282
  // ===========================================================================
7283
+ /**
7284
+ * Per-network cache keys. The registry cache MUST be namespaced by remoteUrl:
7285
+ * testnet and testnet2 ship DIFFERENT coinIds for the same symbol, so a single
7286
+ * global key let a stale testnet snapshot be served for a testnet2 request —
7287
+ * wrong/missing icons AND self-mint resolving the wrong-network coinId. Keying
7288
+ * by remoteUrl isolates the snapshots so a network can never read another's.
7289
+ */
7290
+ cacheKeys() {
7291
+ const base = STORAGE_KEYS_GLOBAL.TOKEN_REGISTRY_CACHE;
7292
+ const baseTs = STORAGE_KEYS_GLOBAL.TOKEN_REGISTRY_CACHE_TS;
7293
+ if (!this.remoteUrl) return { data: base, ts: baseTs };
7294
+ return { data: `${base}:${this.remoteUrl}`, ts: `${baseTs}:${this.remoteUrl}` };
7295
+ }
7283
7296
  /**
7284
7297
  * Load definitions from StorageProvider cache.
7285
7298
  * Only applies if cache exists and is fresh (within refreshIntervalMs).
@@ -7287,9 +7300,10 @@ var TokenRegistry = class _TokenRegistry {
7287
7300
  async loadFromCache() {
7288
7301
  if (!this.storage) return false;
7289
7302
  try {
7303
+ const { data: dataKey, ts: tsKey } = this.cacheKeys();
7290
7304
  const [cached, cachedTs] = await Promise.all([
7291
- this.storage.get(STORAGE_KEYS_GLOBAL.TOKEN_REGISTRY_CACHE),
7292
- this.storage.get(STORAGE_KEYS_GLOBAL.TOKEN_REGISTRY_CACHE_TS)
7305
+ this.storage.get(dataKey),
7306
+ this.storage.get(tsKey)
7293
7307
  ]);
7294
7308
  if (!cached || !cachedTs) return false;
7295
7309
  const ts = parseInt(cachedTs, 10);
@@ -7312,9 +7326,10 @@ var TokenRegistry = class _TokenRegistry {
7312
7326
  async saveToCache(definitions) {
7313
7327
  if (!this.storage) return;
7314
7328
  try {
7329
+ const { data: dataKey, ts: tsKey } = this.cacheKeys();
7315
7330
  await Promise.all([
7316
- this.storage.set(STORAGE_KEYS_GLOBAL.TOKEN_REGISTRY_CACHE, JSON.stringify(definitions)),
7317
- this.storage.set(STORAGE_KEYS_GLOBAL.TOKEN_REGISTRY_CACHE_TS, String(Date.now()))
7331
+ this.storage.set(dataKey, JSON.stringify(definitions)),
7332
+ this.storage.set(tsKey, String(Date.now()))
7318
7333
  ]);
7319
7334
  } catch {
7320
7335
  }
@@ -28061,6 +28076,8 @@ var Sphere = class _Sphere {
28061
28076
  const walletExists = await _Sphere.exists(options.storage);
28062
28077
  if (walletExists) {
28063
28078
  const sphere2 = await _Sphere.load({
28079
+ network: options.network,
28080
+ // forward network so load's configureTokenRegistry uses it (not the testnet default)
28064
28081
  storage: options.storage,
28065
28082
  transport: options.transport,
28066
28083
  oracle: options.oracle,
@@ -28095,6 +28112,8 @@ var Sphere = class _Sphere {
28095
28112
  }
28096
28113
  const sphere = await _Sphere.create({
28097
28114
  mnemonic,
28115
+ network: options.network,
28116
+ // forward network so create's configureTokenRegistry uses it (not the testnet default)
28098
28117
  storage: options.storage,
28099
28118
  transport: options.transport,
28100
28119
  oracle: options.oracle,
@@ -28129,13 +28148,14 @@ var Sphere = class _Sphere {
28129
28148
  */
28130
28149
  static resolveGroupChatConfig(config, network) {
28131
28150
  if (!config) return void 0;
28151
+ if (!network) {
28152
+ throw new SphereError("network is required to resolve group chat relays.", "INVALID_CONFIG");
28153
+ }
28132
28154
  if (config === true) {
28133
- const netConfig = network ? NETWORKS[network] : NETWORKS.mainnet;
28134
- return { relays: [...netConfig.groupRelays] };
28155
+ return { relays: [...NETWORKS[network].groupRelays] };
28135
28156
  }
28136
28157
  if (!config.relays || config.relays.length === 0) {
28137
- const netConfig = network ? NETWORKS[network] : NETWORKS.mainnet;
28138
- return { ...config, relays: [...netConfig.groupRelays] };
28158
+ return { ...config, relays: [...NETWORKS[network].groupRelays] };
28139
28159
  }
28140
28160
  return config;
28141
28161
  }
@@ -28182,8 +28202,13 @@ var Sphere = class _Sphere {
28182
28202
  * This method ensures the main bundle's TokenRegistry is properly configured.
28183
28203
  */
28184
28204
  static configureTokenRegistry(storage, network) {
28185
- const netConfig = network ? NETWORKS[network] : NETWORKS.testnet;
28186
- TokenRegistry.configure({ remoteUrl: netConfig.tokenRegistryUrl, storage });
28205
+ if (!network) {
28206
+ throw new SphereError(
28207
+ "network is required to configure the TokenRegistry. Every Sphere entry point must forward options.network.",
28208
+ "INVALID_CONFIG"
28209
+ );
28210
+ }
28211
+ TokenRegistry.configure({ remoteUrl: NETWORKS[network].tokenRegistryUrl, storage });
28187
28212
  }
28188
28213
  /**
28189
28214
  * Create new wallet with mnemonic
@@ -28333,7 +28358,8 @@ var Sphere = class _Sphere {
28333
28358
  await options.storage.connect();
28334
28359
  logger.debug("Sphere", "Storage reconnected");
28335
28360
  }
28336
- const groupChatConfig = _Sphere.resolveGroupChatConfig(options.groupChat);
28361
+ _Sphere.configureTokenRegistry(options.storage, options.network);
28362
+ const groupChatConfig = _Sphere.resolveGroupChatConfig(options.groupChat, options.network);
28337
28363
  const marketConfig = _Sphere.resolveMarketConfig(options.market);
28338
28364
  const accountingConfig = _Sphere.resolveAccountingConfig(options.accounting);
28339
28365
  const swapConfig = _Sphere.resolveSwapConfig(options.swap);