@opendatalabs/vana-sdk 3.10.1 → 3.12.0

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.
@@ -29037,12 +29037,14 @@ async function buildWeb3SignedHeader(params) {
29037
29037
 
29038
29038
  // src/storage/providers/vana-storage.ts
29039
29039
  var DEFAULT_ENDPOINT = "https://storage.vana.org";
29040
- var BLOB_PATH_PREFIX = "/v1/blobs";
29040
+ var LEGACY_BLOB_PATH_PREFIX = "/v1/blobs";
29041
29041
  var DEFAULT_TOKEN_TTL_SECONDS = 300;
29042
29042
  var MAX_UPLOAD_ATTEMPTS = 4;
29043
29043
  var MAX_RATE_LIMIT_DELAY_MS = 3e4;
29044
29044
  var VanaStorage = class {
29045
29045
  endpoint;
29046
+ network;
29047
+ blobPathPrefix;
29046
29048
  signer;
29047
29049
  ownerAddress;
29048
29050
  fetchImpl;
@@ -29055,6 +29057,15 @@ var VanaStorage = class {
29055
29057
  );
29056
29058
  }
29057
29059
  this.endpoint = (config.endpoint ?? DEFAULT_ENDPOINT).replace(/\/+$/, "");
29060
+ if (config.network !== void 0 && !isProtocolNetwork(config.network)) {
29061
+ throw new StorageError(
29062
+ `Unsupported vana-storage network '${String(config.network)}'`,
29063
+ "INVALID_NETWORK",
29064
+ "vana-storage"
29065
+ );
29066
+ }
29067
+ this.network = config.network;
29068
+ this.blobPathPrefix = this.network ? `/v1/networks/${this.network}/blobs` : LEGACY_BLOB_PATH_PREFIX;
29058
29069
  this.signer = config.signer;
29059
29070
  this.ownerAddress = (config.ownerAddress ?? config.signer.address).toLowerCase();
29060
29071
  this.fetchImpl = config.fetchImpl ?? globalThis.fetch.bind(globalThis);
@@ -29075,7 +29086,7 @@ var VanaStorage = class {
29075
29086
  );
29076
29087
  }
29077
29088
  const subpath = encodeRelativePath(filename);
29078
- const path = `${BLOB_PATH_PREFIX}/${this.ownerAddress}/${subpath}`;
29089
+ const path = `${this.blobPathPrefix}/${this.ownerAddress}/${subpath}`;
29079
29090
  const body = new Uint8Array(await file.arrayBuffer());
29080
29091
  const contentType = file.type !== "" ? file.type : "application/octet-stream";
29081
29092
  const header = await this.signRequest("PUT", path, body);
@@ -29243,12 +29254,18 @@ var VanaStorage = class {
29243
29254
  "vana-storage"
29244
29255
  );
29245
29256
  }
29246
- const segments = parsed.pathname.split("/").filter((s) => s.length > 0);
29247
- const isTraversal = (s) => s === "." || s === "..";
29248
- const valid = segments.length === 5 && segments[0] === "v1" && segments[1] === "blobs" && segments[2]?.toLowerCase() === this.ownerAddress && segments[3] !== void 0 && !isTraversal(segments[3]) && segments[4] !== void 0 && !isTraversal(segments[4]);
29249
- if (!valid) {
29257
+ const route = parseBlobPath(parsed.pathname);
29258
+ if (!route || route.owner.toLowerCase() !== this.ownerAddress) {
29250
29259
  throw new StorageError(
29251
- `URL path '${parsed.pathname}' must be /v1/blobs/${this.ownerAddress}/{scope}/{collectedAt}`,
29260
+ `URL path '${parsed.pathname}' must be ${this.blobPathPrefix}/${this.ownerAddress}/{scope}/{collectedAt}`,
29261
+ "INVALID_URL",
29262
+ "vana-storage"
29263
+ );
29264
+ }
29265
+ const crossNetwork = this.network ? route.network !== void 0 && route.network !== this.network : route.network !== void 0;
29266
+ if (crossNetwork) {
29267
+ throw new StorageError(
29268
+ `URL network '${route.network ?? "legacy"}' does not match provider network '${this.network ?? "legacy"}'`,
29252
29269
  "INVALID_URL",
29253
29270
  "vana-storage"
29254
29271
  );
@@ -29256,6 +29273,26 @@ var VanaStorage = class {
29256
29273
  return parsed.pathname;
29257
29274
  }
29258
29275
  };
29276
+ var PROTOCOL_NETWORKS = ["mainnet", "moksha"];
29277
+ function isProtocolNetwork(value) {
29278
+ return typeof value === "string" && PROTOCOL_NETWORKS.includes(value);
29279
+ }
29280
+ function parseBlobPath(pathname) {
29281
+ const segments = pathname.split("/").filter((s) => s.length > 0);
29282
+ const isTraversal = (s) => s === "." || s === "..";
29283
+ if (segments.length === 5 && segments[0] === "v1" && segments[1] === "blobs") {
29284
+ const [, , owner, scope, collectedAt] = segments;
29285
+ if (isTraversal(scope) || isTraversal(collectedAt)) return null;
29286
+ return { owner, scope, collectedAt };
29287
+ }
29288
+ if (segments.length === 7 && segments[0] === "v1" && segments[1] === "networks" && segments[3] === "blobs") {
29289
+ const [, , network, , owner, scope, collectedAt] = segments;
29290
+ if (!isProtocolNetwork(network)) return null;
29291
+ if (isTraversal(scope) || isTraversal(collectedAt)) return null;
29292
+ return { network, owner, scope, collectedAt };
29293
+ }
29294
+ return null;
29295
+ }
29259
29296
  function encodeRelativePath(filename) {
29260
29297
  const parts = filename.split("/");
29261
29298
  if (parts.length !== 2 || parts.some((p) => p.length === 0 || p === "." || p === "..")) {