@opendatalabs/vana-sdk 3.12.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.
package/README.md CHANGED
@@ -108,41 +108,32 @@ const result = await storage.upload(myBlob, "report.json");
108
108
  console.log(result.url);
109
109
  ```
110
110
 
111
- ### Scope Vana storage to a protocol network
111
+ ### Scope Vana storage by chain ID
112
112
 
113
- `VanaStorage` has two independent axes. `endpoint` is the **product host**
114
- (e.g. `https://storage.vana.org` for production, `https://storage-dev.vana.org`
115
- for internal staging). `network` is the **protocol network** (`mainnet` or
116
- `moksha`) that scopes the blob path. They are not synonyms — `storage-dev` is a
117
- staging host, not a stand-in for Moksha.
113
+ Set `chainId` when writing to Vana Storage for a specific chain (e.g. `1480` for
114
+ Vana mainnet, `14800` for Moksha). Uploads then use chain-scoped routes
115
+ (`/v1/chains/{chainId}/blobs/...`) so data for different chains never collides.
118
116
 
119
117
  ```typescript
120
118
  import { createVanaStorageProvider } from "@opendatalabs/vana-sdk/node";
121
119
 
122
120
  const storage = createVanaStorageProvider({
123
- endpoint: "https://storage.vana.org", // product host
124
- network: "moksha", // protocol namespace within that host
121
+ endpoint: "https://storage.vana.org",
122
+ chainId: 14800,
125
123
  signer: {
126
124
  address: account.address,
127
125
  signMessage: (msg) => account.signMessage({ message: msg }),
128
126
  },
129
127
  });
130
128
 
131
- // Uploads to /v1/networks/moksha/blobs/{owner}/{scope}/{collectedAt}
132
129
  const result = await storage.upload(
133
130
  myBlob,
134
131
  "instagram.profile/2026-05-08T20:00:00.000Z",
135
132
  );
136
133
  ```
137
134
 
138
- When `network` is omitted, `VanaStorage` uses the legacy `/v1/blobs/...` routes,
139
- preserving backward compatibility. The Web3Signed audience is always the
140
- endpoint origin, never the network.
141
-
142
- A network-configured provider still accepts legacy same-endpoint
143
- `/v1/blobs/...` URLs so it can read or delete objects written before the opt-in,
144
- but it rejects URLs scoped to a _different_ explicit network — a Moksha provider
145
- won't act on a `mainnet`-scoped URL, and vice versa.
135
+ Chain-configured providers reject legacy blob URLs and URLs scoped to a
136
+ different explicit chain ID.
146
137
 
147
138
  ## Build a Vana app
148
139
 
@@ -29034,7 +29034,7 @@ var MAX_UPLOAD_ATTEMPTS = 4;
29034
29034
  var MAX_RATE_LIMIT_DELAY_MS = 3e4;
29035
29035
  var VanaStorage = class {
29036
29036
  endpoint;
29037
- network;
29037
+ chainId;
29038
29038
  blobPathPrefix;
29039
29039
  signer;
29040
29040
  ownerAddress;
@@ -29048,15 +29048,15 @@ var VanaStorage = class {
29048
29048
  );
29049
29049
  }
29050
29050
  this.endpoint = (config.endpoint ?? DEFAULT_ENDPOINT).replace(/\/+$/, "");
29051
- if (config.network !== void 0 && !isProtocolNetwork(config.network)) {
29051
+ if (config.chainId !== void 0 && !isValidChainId(config.chainId)) {
29052
29052
  throw new StorageError(
29053
- `Unsupported vana-storage network '${String(config.network)}'`,
29054
- "INVALID_NETWORK",
29053
+ `Unsupported vana-storage chainId '${String(config.chainId)}'`,
29054
+ "INVALID_CHAIN_ID",
29055
29055
  "vana-storage"
29056
29056
  );
29057
29057
  }
29058
- this.network = config.network;
29059
- this.blobPathPrefix = this.network ? `/v1/networks/${this.network}/blobs` : LEGACY_BLOB_PATH_PREFIX;
29058
+ this.chainId = config.chainId;
29059
+ this.blobPathPrefix = this.chainId !== void 0 ? `/v1/chains/${this.chainId}/blobs` : LEGACY_BLOB_PATH_PREFIX;
29060
29060
  this.signer = config.signer;
29061
29061
  this.ownerAddress = (config.ownerAddress ?? config.signer.address).toLowerCase();
29062
29062
  this.fetchImpl = config.fetchImpl ?? globalThis.fetch.bind(globalThis);
@@ -29253,10 +29253,9 @@ var VanaStorage = class {
29253
29253
  "vana-storage"
29254
29254
  );
29255
29255
  }
29256
- const crossNetwork = this.network ? route.network !== void 0 && route.network !== this.network : route.network !== void 0;
29257
- if (crossNetwork) {
29256
+ if (route.chainId !== this.chainId) {
29258
29257
  throw new StorageError(
29259
- `URL network '${route.network ?? "legacy"}' does not match provider network '${this.network ?? "legacy"}'`,
29258
+ `URL chainId '${route.chainId ?? "legacy"}' does not match provider chainId '${this.chainId ?? "legacy"}'`,
29260
29259
  "INVALID_URL",
29261
29260
  "vana-storage"
29262
29261
  );
@@ -29264,9 +29263,8 @@ var VanaStorage = class {
29264
29263
  return parsed.pathname;
29265
29264
  }
29266
29265
  };
29267
- var PROTOCOL_NETWORKS = ["mainnet", "moksha"];
29268
- function isProtocolNetwork(value) {
29269
- return typeof value === "string" && PROTOCOL_NETWORKS.includes(value);
29266
+ function isValidChainId(value) {
29267
+ return typeof value === "number" && Number.isInteger(value) && value > 0;
29270
29268
  }
29271
29269
  function parseBlobPath(pathname) {
29272
29270
  const segments = pathname.split("/").filter((s) => s.length > 0);
@@ -29276,11 +29274,13 @@ function parseBlobPath(pathname) {
29276
29274
  if (isTraversal(scope) || isTraversal(collectedAt)) return null;
29277
29275
  return { owner, scope, collectedAt };
29278
29276
  }
29279
- if (segments.length === 7 && segments[0] === "v1" && segments[1] === "networks" && segments[3] === "blobs") {
29280
- const [, , network, , owner, scope, collectedAt] = segments;
29281
- if (!isProtocolNetwork(network)) return null;
29277
+ if (segments.length === 7 && segments[0] === "v1" && segments[1] === "chains" && segments[3] === "blobs") {
29278
+ const [, , chainIdSegment, , owner, scope, collectedAt] = segments;
29279
+ if (!/^[0-9]+$/.test(chainIdSegment)) return null;
29280
+ const chainId = Number(chainIdSegment);
29281
+ if (!isValidChainId(chainId)) return null;
29282
29282
  if (isTraversal(scope) || isTraversal(collectedAt)) return null;
29283
- return { network, owner, scope, collectedAt };
29283
+ return { chainId, owner, scope, collectedAt };
29284
29284
  }
29285
29285
  return null;
29286
29286
  }