@opendatalabs/vana-sdk 3.13.0 → 3.13.1

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.
@@ -29035,6 +29035,21 @@ async function buildWeb3SignedHeader(params) {
29035
29035
  return `Web3Signed ${payloadBase64}.${signature}`;
29036
29036
  }
29037
29037
 
29038
+ // src/protocol/networks.ts
29039
+ var PROTOCOL_NETWORK_CHAIN_IDS = {
29040
+ mainnet: 1480,
29041
+ moksha: 14800
29042
+ };
29043
+ function isProtocolNetwork(value) {
29044
+ return typeof value === "string" && Object.hasOwn(PROTOCOL_NETWORK_CHAIN_IDS, value);
29045
+ }
29046
+ function getProtocolNetworkChainId(network) {
29047
+ if (!isProtocolNetwork(network)) {
29048
+ throw new Error(`Unsupported Vana protocol network: ${String(network)}`);
29049
+ }
29050
+ return PROTOCOL_NETWORK_CHAIN_IDS[network];
29051
+ }
29052
+
29038
29053
  // src/storage/providers/vana-storage.ts
29039
29054
  var DEFAULT_ENDPOINT = "https://storage.vana.org";
29040
29055
  var LEGACY_BLOB_PATH_PREFIX = "/v1/blobs";
@@ -29043,6 +29058,7 @@ var MAX_UPLOAD_ATTEMPTS = 4;
29043
29058
  var MAX_RATE_LIMIT_DELAY_MS = 3e4;
29044
29059
  var VanaStorage = class {
29045
29060
  endpoint;
29061
+ network;
29046
29062
  chainId;
29047
29063
  blobPathPrefix;
29048
29064
  signer;
@@ -29057,14 +29073,9 @@ var VanaStorage = class {
29057
29073
  );
29058
29074
  }
29059
29075
  this.endpoint = (config.endpoint ?? DEFAULT_ENDPOINT).replace(/\/+$/, "");
29060
- if (config.chainId !== void 0 && !isValidChainId(config.chainId)) {
29061
- throw new StorageError(
29062
- `Unsupported vana-storage chainId '${String(config.chainId)}'`,
29063
- "INVALID_CHAIN_ID",
29064
- "vana-storage"
29065
- );
29066
- }
29067
- this.chainId = config.chainId;
29076
+ const resolved = resolveStorageNamespace(config);
29077
+ this.network = resolved.network;
29078
+ this.chainId = resolved.chainId;
29068
29079
  this.blobPathPrefix = this.chainId !== void 0 ? `/v1/chains/${this.chainId}/blobs` : LEGACY_BLOB_PATH_PREFIX;
29069
29080
  this.signer = config.signer;
29070
29081
  this.ownerAddress = (config.ownerAddress ?? config.signer.address).toLowerCase();
@@ -29264,17 +29275,51 @@ var VanaStorage = class {
29264
29275
  }
29265
29276
  if (route.chainId !== this.chainId) {
29266
29277
  throw new StorageError(
29267
- `URL chainId '${route.chainId ?? "legacy"}' does not match provider chainId '${this.chainId ?? "legacy"}'`,
29278
+ `URL chainId '${route.chainId ?? "legacy"}' does not match provider namespace '${this.namespaceDescription()}'`,
29268
29279
  "INVALID_URL",
29269
29280
  "vana-storage"
29270
29281
  );
29271
29282
  }
29272
29283
  return parsed.pathname;
29273
29284
  }
29285
+ namespaceDescription() {
29286
+ if (this.network !== void 0) {
29287
+ return `${this.network} (${this.chainId})`;
29288
+ }
29289
+ return this.chainId === void 0 ? "legacy" : String(this.chainId);
29290
+ }
29274
29291
  };
29275
29292
  function isValidChainId(value) {
29276
29293
  return typeof value === "number" && Number.isInteger(value) && value > 0;
29277
29294
  }
29295
+ function resolveStorageNamespace(config) {
29296
+ if (config.network !== void 0 && !isProtocolNetwork(config.network)) {
29297
+ throw new StorageError(
29298
+ `Unsupported vana-storage network '${String(config.network)}'`,
29299
+ "INVALID_NETWORK",
29300
+ "vana-storage"
29301
+ );
29302
+ }
29303
+ if (config.chainId !== void 0 && !isValidChainId(config.chainId)) {
29304
+ throw new StorageError(
29305
+ `Unsupported vana-storage chainId '${String(config.chainId)}'`,
29306
+ "INVALID_CHAIN_ID",
29307
+ "vana-storage"
29308
+ );
29309
+ }
29310
+ if (config.network === void 0) {
29311
+ return { chainId: config.chainId };
29312
+ }
29313
+ const networkChainId = getProtocolNetworkChainId(config.network);
29314
+ if (config.chainId !== void 0 && config.chainId !== networkChainId) {
29315
+ throw new StorageError(
29316
+ `vana-storage network '${config.network}' resolves to chainId '${networkChainId}', not '${config.chainId}'`,
29317
+ "INVALID_CHAIN_ID",
29318
+ "vana-storage"
29319
+ );
29320
+ }
29321
+ return { chainId: networkChainId, network: config.network };
29322
+ }
29278
29323
  function parseBlobPath(pathname) {
29279
29324
  const segments = pathname.split("/").filter((s) => s.length > 0);
29280
29325
  const isTraversal = (s) => s === "." || s === "..";