@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.
@@ -26900,7 +26900,7 @@ function getEmbeddedTrustBase(network) {
26900
26900
  case "dev":
26901
26901
  return TRUSTBASE_DEV;
26902
26902
  default:
26903
- return TRUSTBASE_TESTNET;
26903
+ throw new SphereError(`getEmbeddedTrustBase: unknown network "${network}"`, "INVALID_CONFIG");
26904
26904
  }
26905
26905
  }
26906
26906
  var BaseTrustBaseLoader = class {
@@ -26920,11 +26920,23 @@ var BaseTrustBaseLoader = class {
26920
26920
  // impl/nodejs/oracle/index.ts
26921
26921
  var NodeTrustBaseLoader = class extends BaseTrustBaseLoader {
26922
26922
  filePath;
26923
- constructor(filePathOrNetwork) {
26923
+ /**
26924
+ * @param filePathOrNetwork - a NetworkType, or a file path to load the trust base from
26925
+ * @param fallbackNetwork - network used for the embedded fallback when a file path is
26926
+ * supplied (and the file is missing/unreadable). Required when filePathOrNetwork is a
26927
+ * path — we must never silently fall back to testnet on a different network.
26928
+ */
26929
+ constructor(filePathOrNetwork, fallbackNetwork) {
26924
26930
  if (!filePathOrNetwork) {
26925
- super("testnet");
26931
+ throw new SphereError("NodeTrustBaseLoader: network or trustBasePath is required.", "INVALID_CONFIG");
26926
26932
  } else if (filePathOrNetwork.includes("/") || filePathOrNetwork.includes(".")) {
26927
- super("testnet");
26933
+ if (!fallbackNetwork) {
26934
+ throw new SphereError(
26935
+ "NodeTrustBaseLoader: fallbackNetwork is required when a trustBasePath is supplied.",
26936
+ "INVALID_CONFIG"
26937
+ );
26938
+ }
26939
+ super(fallbackNetwork);
26928
26940
  this.filePath = filePathOrNetwork;
26929
26941
  } else {
26930
26942
  super(filePathOrNetwork);
@@ -26942,14 +26954,21 @@ var NodeTrustBaseLoader = class extends BaseTrustBaseLoader {
26942
26954
  return null;
26943
26955
  }
26944
26956
  };
26945
- function createNodeTrustBaseLoader(filePathOrNetwork) {
26946
- return new NodeTrustBaseLoader(filePathOrNetwork);
26957
+ function createNodeTrustBaseLoader(filePathOrNetwork, fallbackNetwork) {
26958
+ return new NodeTrustBaseLoader(filePathOrNetwork, fallbackNetwork);
26947
26959
  }
26948
26960
  function createUnicityAggregatorProvider(config) {
26949
26961
  const { trustBasePath, network, ...restConfig } = config;
26962
+ if (!trustBasePath && !network) {
26963
+ throw new SphereError(
26964
+ "createUnicityAggregatorProvider: network or trustBaseUrl required.",
26965
+ "INVALID_CONFIG"
26966
+ );
26967
+ }
26950
26968
  return new UnicityAggregatorProvider({
26951
26969
  ...restConfig,
26952
- trustBaseLoader: createNodeTrustBaseLoader(trustBasePath ?? network ?? "testnet")
26970
+ // When a path is supplied, `network` (if any) is the embedded-fallback network.
26971
+ trustBaseLoader: createNodeTrustBaseLoader(trustBasePath ?? network, network)
26953
26972
  });
26954
26973
  }
26955
26974
  var createUnicityOracleProvider = createUnicityAggregatorProvider;
@@ -29328,6 +29347,19 @@ var TokenRegistry = class _TokenRegistry {
29328
29347
  // ===========================================================================
29329
29348
  // Cache (StorageProvider)
29330
29349
  // ===========================================================================
29350
+ /**
29351
+ * Per-network cache keys. The registry cache MUST be namespaced by remoteUrl:
29352
+ * testnet and testnet2 ship DIFFERENT coinIds for the same symbol, so a single
29353
+ * global key let a stale testnet snapshot be served for a testnet2 request —
29354
+ * wrong/missing icons AND self-mint resolving the wrong-network coinId. Keying
29355
+ * by remoteUrl isolates the snapshots so a network can never read another's.
29356
+ */
29357
+ cacheKeys() {
29358
+ const base = STORAGE_KEYS_GLOBAL.TOKEN_REGISTRY_CACHE;
29359
+ const baseTs = STORAGE_KEYS_GLOBAL.TOKEN_REGISTRY_CACHE_TS;
29360
+ if (!this.remoteUrl) return { data: base, ts: baseTs };
29361
+ return { data: `${base}:${this.remoteUrl}`, ts: `${baseTs}:${this.remoteUrl}` };
29362
+ }
29331
29363
  /**
29332
29364
  * Load definitions from StorageProvider cache.
29333
29365
  * Only applies if cache exists and is fresh (within refreshIntervalMs).
@@ -29335,9 +29367,10 @@ var TokenRegistry = class _TokenRegistry {
29335
29367
  async loadFromCache() {
29336
29368
  if (!this.storage) return false;
29337
29369
  try {
29370
+ const { data: dataKey, ts: tsKey } = this.cacheKeys();
29338
29371
  const [cached, cachedTs] = await Promise.all([
29339
- this.storage.get(STORAGE_KEYS_GLOBAL.TOKEN_REGISTRY_CACHE),
29340
- this.storage.get(STORAGE_KEYS_GLOBAL.TOKEN_REGISTRY_CACHE_TS)
29372
+ this.storage.get(dataKey),
29373
+ this.storage.get(tsKey)
29341
29374
  ]);
29342
29375
  if (!cached || !cachedTs) return false;
29343
29376
  const ts = parseInt(cachedTs, 10);
@@ -29360,9 +29393,10 @@ var TokenRegistry = class _TokenRegistry {
29360
29393
  async saveToCache(definitions) {
29361
29394
  if (!this.storage) return;
29362
29395
  try {
29396
+ const { data: dataKey, ts: tsKey } = this.cacheKeys();
29363
29397
  await Promise.all([
29364
- this.storage.set(STORAGE_KEYS_GLOBAL.TOKEN_REGISTRY_CACHE, JSON.stringify(definitions)),
29365
- this.storage.set(STORAGE_KEYS_GLOBAL.TOKEN_REGISTRY_CACHE_TS, String(Date.now()))
29398
+ this.storage.set(dataKey, JSON.stringify(definitions)),
29399
+ this.storage.set(tsKey, String(Date.now()))
29366
29400
  ]);
29367
29401
  } catch {
29368
29402
  }
@@ -29701,7 +29735,10 @@ function createNodeProviders(config) {
29701
29735
  );
29702
29736
  }
29703
29737
  }
29704
- const network = config?.network ?? "mainnet";
29738
+ if (!config?.network) {
29739
+ throw new SphereError("createNodeProviders: config.network is required.", "INVALID_CONFIG");
29740
+ }
29741
+ const network = config.network;
29705
29742
  const globalDebug = config?.debug ?? false;
29706
29743
  logger.configure({ debug: globalDebug });
29707
29744
  if (config?.transport?.debug) logger.setTagDebug("Nostr", true);