@opendatalabs/vana-sdk 3.11.0 → 3.13.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.
@@ -29206,12 +29206,14 @@ async function buildWeb3SignedHeader(params) {
29206
29206
 
29207
29207
  // src/storage/providers/vana-storage.ts
29208
29208
  var DEFAULT_ENDPOINT = "https://storage.vana.org";
29209
- var BLOB_PATH_PREFIX = "/v1/blobs";
29209
+ var LEGACY_BLOB_PATH_PREFIX = "/v1/blobs";
29210
29210
  var DEFAULT_TOKEN_TTL_SECONDS = 300;
29211
29211
  var MAX_UPLOAD_ATTEMPTS = 4;
29212
29212
  var MAX_RATE_LIMIT_DELAY_MS = 3e4;
29213
29213
  var VanaStorage = class {
29214
29214
  endpoint;
29215
+ chainId;
29216
+ blobPathPrefix;
29215
29217
  signer;
29216
29218
  ownerAddress;
29217
29219
  fetchImpl;
@@ -29224,6 +29226,15 @@ var VanaStorage = class {
29224
29226
  );
29225
29227
  }
29226
29228
  this.endpoint = (config.endpoint ?? DEFAULT_ENDPOINT).replace(/\/+$/, "");
29229
+ if (config.chainId !== void 0 && !isValidChainId(config.chainId)) {
29230
+ throw new StorageError(
29231
+ `Unsupported vana-storage chainId '${String(config.chainId)}'`,
29232
+ "INVALID_CHAIN_ID",
29233
+ "vana-storage"
29234
+ );
29235
+ }
29236
+ this.chainId = config.chainId;
29237
+ this.blobPathPrefix = this.chainId !== void 0 ? `/v1/chains/${this.chainId}/blobs` : LEGACY_BLOB_PATH_PREFIX;
29227
29238
  this.signer = config.signer;
29228
29239
  this.ownerAddress = (config.ownerAddress ?? config.signer.address).toLowerCase();
29229
29240
  this.fetchImpl = config.fetchImpl ?? globalThis.fetch.bind(globalThis);
@@ -29244,7 +29255,7 @@ var VanaStorage = class {
29244
29255
  );
29245
29256
  }
29246
29257
  const subpath = encodeRelativePath(filename);
29247
- const path = `${BLOB_PATH_PREFIX}/${this.ownerAddress}/${subpath}`;
29258
+ const path = `${this.blobPathPrefix}/${this.ownerAddress}/${subpath}`;
29248
29259
  const body = new Uint8Array(await file.arrayBuffer());
29249
29260
  const contentType = file.type !== "" ? file.type : "application/octet-stream";
29250
29261
  const header = await this.signRequest("PUT", path, body);
@@ -29412,12 +29423,17 @@ var VanaStorage = class {
29412
29423
  "vana-storage"
29413
29424
  );
29414
29425
  }
29415
- const segments = parsed.pathname.split("/").filter((s) => s.length > 0);
29416
- const isTraversal = (s) => s === "." || s === "..";
29417
- 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]);
29418
- if (!valid) {
29426
+ const route = parseBlobPath(parsed.pathname);
29427
+ if (!route || route.owner.toLowerCase() !== this.ownerAddress) {
29428
+ throw new StorageError(
29429
+ `URL path '${parsed.pathname}' must be ${this.blobPathPrefix}/${this.ownerAddress}/{scope}/{collectedAt}`,
29430
+ "INVALID_URL",
29431
+ "vana-storage"
29432
+ );
29433
+ }
29434
+ if (route.chainId !== this.chainId) {
29419
29435
  throw new StorageError(
29420
- `URL path '${parsed.pathname}' must be /v1/blobs/${this.ownerAddress}/{scope}/{collectedAt}`,
29436
+ `URL chainId '${route.chainId ?? "legacy"}' does not match provider chainId '${this.chainId ?? "legacy"}'`,
29421
29437
  "INVALID_URL",
29422
29438
  "vana-storage"
29423
29439
  );
@@ -29425,6 +29441,27 @@ var VanaStorage = class {
29425
29441
  return parsed.pathname;
29426
29442
  }
29427
29443
  };
29444
+ function isValidChainId(value) {
29445
+ return typeof value === "number" && Number.isInteger(value) && value > 0;
29446
+ }
29447
+ function parseBlobPath(pathname) {
29448
+ const segments = pathname.split("/").filter((s) => s.length > 0);
29449
+ const isTraversal = (s) => s === "." || s === "..";
29450
+ if (segments.length === 5 && segments[0] === "v1" && segments[1] === "blobs") {
29451
+ const [, , owner, scope, collectedAt] = segments;
29452
+ if (isTraversal(scope) || isTraversal(collectedAt)) return null;
29453
+ return { owner, scope, collectedAt };
29454
+ }
29455
+ if (segments.length === 7 && segments[0] === "v1" && segments[1] === "chains" && segments[3] === "blobs") {
29456
+ const [, , chainIdSegment, , owner, scope, collectedAt] = segments;
29457
+ if (!/^[0-9]+$/.test(chainIdSegment)) return null;
29458
+ const chainId = Number(chainIdSegment);
29459
+ if (!isValidChainId(chainId)) return null;
29460
+ if (isTraversal(scope) || isTraversal(collectedAt)) return null;
29461
+ return { chainId, owner, scope, collectedAt };
29462
+ }
29463
+ return null;
29464
+ }
29428
29465
  function encodeRelativePath(filename) {
29429
29466
  const parts = filename.split("/");
29430
29467
  if (parts.length !== 2 || parts.some((p) => p.length === 0 || p === "." || p === "..")) {