@unicitylabs/sphere-sdk 0.8.0-dev.2 → 0.8.0-dev.4

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
  }
@@ -9475,7 +9490,8 @@ var PaymentsModule = class _PaymentsModule {
9475
9490
  try {
9476
9491
  const peerInfo = await this.deps.transport.resolve?.(request.recipient) ?? null;
9477
9492
  const recipientPubkey = this.resolveTransportPubkey(request.recipient, peerInfo);
9478
- const recipientAddress = await this.resolveRecipientAddress(request.recipient, request.addressMode, peerInfo);
9493
+ const willUseEngine = !!(this.deps?.tokenEngine && peerInfo?.chainPubkey);
9494
+ const recipientAddress = willUseEngine ? null : await this.resolveRecipientAddress(request.recipient, request.addressMode, peerInfo);
9479
9495
  const signingService = await this.createSigningService();
9480
9496
  const stClient = this.deps.oracle.getStateTransitionClient?.();
9481
9497
  if (!stClient) {
@@ -9599,6 +9615,7 @@ var PaymentsModule = class _PaymentsModule {
9599
9615
  splitPlan.remainderAmount,
9600
9616
  splitPlan.coinId,
9601
9617
  recipientAddress,
9618
+ // v1 path only — non-null (would have thrown in resolve otherwise)
9602
9619
  onChainMessage
9603
9620
  );
9604
9621
  committedOnChainTokenIds.add(splitPlan.tokenToSplit.uiToken.id);
@@ -9679,6 +9696,7 @@ var PaymentsModule = class _PaymentsModule {
9679
9696
  splitPlan.remainderAmount,
9680
9697
  splitPlan.coinId,
9681
9698
  recipientAddress,
9699
+ // v1 path only — non-null (would have thrown in resolve otherwise)
9682
9700
  {
9683
9701
  memo: request.memo,
9684
9702
  message: onChainMessage,
@@ -12675,7 +12693,7 @@ var PaymentsModule = class _PaymentsModule {
12675
12693
  const nametag = recipient.startsWith("@") ? recipient.slice(1) : info.nametag || recipient;
12676
12694
  if (!info.directAddress) {
12677
12695
  throw new SphereError(
12678
- `"${nametag}" has no DirectAddress \u2014 the recipient must publish a key-based identity binding.`,
12696
+ `"${nametag}" has no published identity \u2014 the recipient must register a Unicity ID (publish a key-based identity binding) before they can receive payments.`,
12679
12697
  "INVALID_RECIPIENT"
12680
12698
  );
12681
12699
  }
@@ -28058,6 +28076,8 @@ var Sphere = class _Sphere {
28058
28076
  const walletExists = await _Sphere.exists(options.storage);
28059
28077
  if (walletExists) {
28060
28078
  const sphere2 = await _Sphere.load({
28079
+ network: options.network,
28080
+ // forward network so load's configureTokenRegistry uses it (not the testnet default)
28061
28081
  storage: options.storage,
28062
28082
  transport: options.transport,
28063
28083
  oracle: options.oracle,
@@ -28092,6 +28112,8 @@ var Sphere = class _Sphere {
28092
28112
  }
28093
28113
  const sphere = await _Sphere.create({
28094
28114
  mnemonic,
28115
+ network: options.network,
28116
+ // forward network so create's configureTokenRegistry uses it (not the testnet default)
28095
28117
  storage: options.storage,
28096
28118
  transport: options.transport,
28097
28119
  oracle: options.oracle,
@@ -28179,6 +28201,12 @@ var Sphere = class _Sphere {
28179
28201
  * This method ensures the main bundle's TokenRegistry is properly configured.
28180
28202
  */
28181
28203
  static configureTokenRegistry(storage, network) {
28204
+ if (!network) {
28205
+ logger.warn(
28206
+ "Sphere",
28207
+ "configureTokenRegistry: no network provided \u2014 defaulting to testnet. Pass options.network to avoid loading the wrong-network registry."
28208
+ );
28209
+ }
28182
28210
  const netConfig = network ? NETWORKS[network] : NETWORKS.testnet;
28183
28211
  TokenRegistry.configure({ remoteUrl: netConfig.tokenRegistryUrl, storage });
28184
28212
  }
@@ -28330,7 +28358,8 @@ var Sphere = class _Sphere {
28330
28358
  await options.storage.connect();
28331
28359
  logger.debug("Sphere", "Storage reconnected");
28332
28360
  }
28333
- const groupChatConfig = _Sphere.resolveGroupChatConfig(options.groupChat);
28361
+ _Sphere.configureTokenRegistry(options.storage, options.network);
28362
+ const groupChatConfig = _Sphere.resolveGroupChatConfig(options.groupChat, options.network);
28334
28363
  const marketConfig = _Sphere.resolveMarketConfig(options.market);
28335
28364
  const accountingConfig = _Sphere.resolveAccountingConfig(options.accounting);
28336
28365
  const swapConfig = _Sphere.resolveSwapConfig(options.swap);