@opendatalabs/vana-sdk 3.3.0 → 3.4.1-canary.3957547

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.
Files changed (49) hide show
  1. package/dist/index.browser.d.ts +7 -3
  2. package/dist/index.browser.js +424 -125
  3. package/dist/index.browser.js.map +4 -4
  4. package/dist/index.node.cjs +449 -130
  5. package/dist/index.node.cjs.map +4 -4
  6. package/dist/index.node.d.ts +7 -3
  7. package/dist/index.node.js +424 -125
  8. package/dist/index.node.js.map +4 -4
  9. package/dist/protocol/data-point-status.cjs +80 -0
  10. package/dist/protocol/data-point-status.cjs.map +1 -0
  11. package/dist/protocol/data-point-status.d.ts +34 -0
  12. package/dist/protocol/data-point-status.js +51 -0
  13. package/dist/protocol/data-point-status.js.map +1 -0
  14. package/dist/protocol/data-point-status.test.d.ts +1 -0
  15. package/dist/protocol/eip712.cjs +53 -31
  16. package/dist/protocol/eip712.cjs.map +1 -1
  17. package/dist/protocol/eip712.d.ts +98 -43
  18. package/dist/protocol/eip712.js +47 -27
  19. package/dist/protocol/eip712.js.map +1 -1
  20. package/dist/protocol/escrow-deposit.cjs +89 -0
  21. package/dist/protocol/escrow-deposit.cjs.map +1 -0
  22. package/dist/protocol/escrow-deposit.d.ts +47 -0
  23. package/dist/protocol/escrow-deposit.js +60 -0
  24. package/dist/protocol/escrow-deposit.js.map +1 -0
  25. package/dist/protocol/escrow-deposit.test.d.ts +1 -0
  26. package/dist/protocol/escrow-flow.test.d.ts +21 -0
  27. package/dist/protocol/fee-registry.cjs +116 -0
  28. package/dist/protocol/fee-registry.cjs.map +1 -0
  29. package/dist/protocol/fee-registry.d.ts +151 -0
  30. package/dist/protocol/fee-registry.js +89 -0
  31. package/dist/protocol/fee-registry.js.map +1 -0
  32. package/dist/protocol/fee-registry.test.d.ts +1 -0
  33. package/dist/protocol/gateway.cjs +111 -35
  34. package/dist/protocol/gateway.cjs.map +1 -1
  35. package/dist/protocol/gateway.d.ts +240 -45
  36. package/dist/protocol/gateway.js +111 -35
  37. package/dist/protocol/gateway.js.map +1 -1
  38. package/dist/protocol/grants.cjs +27 -64
  39. package/dist/protocol/grants.cjs.map +1 -1
  40. package/dist/protocol/grants.d.ts +6 -13
  41. package/dist/protocol/grants.js +27 -63
  42. package/dist/protocol/grants.js.map +1 -1
  43. package/dist/protocol/personal-server-data.cjs +71 -0
  44. package/dist/protocol/personal-server-data.cjs.map +1 -0
  45. package/dist/protocol/personal-server-data.d.ts +16 -0
  46. package/dist/protocol/personal-server-data.js +47 -0
  47. package/dist/protocol/personal-server-data.js.map +1 -0
  48. package/dist/protocol/personal-server-data.test.d.ts +1 -0
  49. package/package.json +3 -2
@@ -32509,6 +32509,7 @@ function formatOAuthError(body, status) {
32509
32509
  // src/protocol/eip712.ts
32510
32510
  var DOMAIN_NAME = "Vana Data Portability";
32511
32511
  var DOMAIN_VERSION = "1";
32512
+ var NATIVE_VANA_ASSET = "0x0000000000000000000000000000000000000000";
32512
32513
  function buildDomain(chainId, verifyingContract) {
32513
32514
  return {
32514
32515
  name: DOMAIN_NAME,
@@ -32517,13 +32518,7 @@ function buildDomain(chainId, verifyingContract) {
32517
32518
  verifyingContract
32518
32519
  };
32519
32520
  }
32520
- function fileRegistrationDomain(config) {
32521
- return buildDomain(
32522
- config.chainId,
32523
- config.contracts.dataRegistry
32524
- );
32525
- }
32526
- function fileDeletionDomain(config) {
32521
+ function dataRegistryDomain(config) {
32527
32522
  return buildDomain(
32528
32523
  config.chainId,
32529
32524
  config.contracts.dataRegistry
@@ -32553,31 +32548,26 @@ function builderRegistrationDomain(config) {
32553
32548
  config.contracts.dataPortabilityGrantees
32554
32549
  );
32555
32550
  }
32556
- var FILE_REGISTRATION_TYPES = {
32557
- FileRegistration: [
32558
- { name: "ownerAddress", type: "address" },
32559
- { name: "url", type: "string" },
32560
- { name: "schemaId", type: "bytes32" }
32561
- ]
32562
- };
32563
- var FILE_DELETION_TYPES = {
32564
- FileDeletion: [
32565
- { name: "ownerAddress", type: "address" },
32566
- { name: "fileId", type: "bytes32" }
32567
- ]
32568
- };
32551
+ function escrowPaymentDomain(config) {
32552
+ return buildDomain(
32553
+ config.chainId,
32554
+ config.contracts.dataPortabilityEscrow
32555
+ );
32556
+ }
32569
32557
  var GRANT_REGISTRATION_TYPES = {
32570
32558
  GrantRegistration: [
32571
32559
  { name: "grantorAddress", type: "address" },
32572
32560
  { name: "granteeId", type: "bytes32" },
32573
- { name: "grant", type: "string" },
32574
- { name: "fileIds", type: "uint256[]" }
32561
+ { name: "scopes", type: "string[]" },
32562
+ { name: "grantVersion", type: "uint256" },
32563
+ { name: "expiresAt", type: "uint256" }
32575
32564
  ]
32576
32565
  };
32577
32566
  var GRANT_REVOCATION_TYPES = {
32578
32567
  GrantRevocation: [
32579
32568
  { name: "grantorAddress", type: "address" },
32580
- { name: "grantId", type: "bytes32" }
32569
+ { name: "grantId", type: "bytes32" },
32570
+ { name: "grantVersion", type: "uint256" }
32581
32571
  ]
32582
32572
  };
32583
32573
  var SERVER_REGISTRATION_TYPES = {
@@ -32596,6 +32586,34 @@ var BUILDER_REGISTRATION_TYPES = {
32596
32586
  { name: "appUrl", type: "string" }
32597
32587
  ]
32598
32588
  };
32589
+ var GENERIC_PAYMENT_TYPES = {
32590
+ GenericPayment: [
32591
+ { name: "payerAddress", type: "address" },
32592
+ { name: "opType", type: "string" },
32593
+ { name: "opId", type: "bytes32" },
32594
+ { name: "asset", type: "address" },
32595
+ { name: "amount", type: "uint256" },
32596
+ { name: "paymentNonce", type: "uint256" }
32597
+ ]
32598
+ };
32599
+ var ADD_DATA_TYPES = {
32600
+ AddData: [
32601
+ { name: "ownerAddress", type: "address" },
32602
+ { name: "scope", type: "string" },
32603
+ { name: "dataHash", type: "bytes32" },
32604
+ { name: "metadataHash", type: "bytes32" },
32605
+ { name: "expectedVersion", type: "uint256" }
32606
+ ]
32607
+ };
32608
+ var RECORD_DATA_ACCESS_TYPES = {
32609
+ RecordDataAccess: [
32610
+ { name: "ownerAddress", type: "address" },
32611
+ { name: "scope", type: "string" },
32612
+ { name: "version", type: "uint256" },
32613
+ { name: "accessor", type: "address" },
32614
+ { name: "recordId", type: "bytes32" }
32615
+ ]
32616
+ };
32599
32617
 
32600
32618
  // src/protocol/personal-server-registration.ts
32601
32619
  import {
@@ -33037,67 +33055,34 @@ function isDataPortabilityGatewayConfig(value) {
33037
33055
  return false;
33038
33056
  }
33039
33057
  const c = contracts;
33040
- return isHexString(c["dataRegistry"]) && isHexString(c["dataPortabilityPermissions"]) && isHexString(c["dataPortabilityServer"]) && isHexString(c["dataPortabilityGrantees"]);
33041
- }
33042
- function parseGrantRegistrationPayload(grant) {
33043
- let parsed;
33044
- try {
33045
- parsed = JSON.parse(grant);
33046
- } catch {
33047
- return null;
33048
- }
33049
- if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
33050
- return null;
33051
- }
33052
- const value = parsed;
33053
- if (!Array.isArray(value["scopes"]) || value["scopes"].length === 0) {
33054
- return null;
33055
- }
33056
- if (!value["scopes"].every((scope) => typeof scope === "string")) {
33057
- return null;
33058
- }
33059
- if (typeof value["expiresAt"] !== "number" || !Number.isFinite(value["expiresAt"])) {
33060
- return null;
33061
- }
33062
- if (value["user"] !== void 0 && !isHexString(value["user"])) {
33063
- return null;
33064
- }
33065
- if (value["builder"] !== void 0 && !isHexString(value["builder"])) {
33066
- return null;
33067
- }
33068
- if (value["nonce"] !== void 0 && (typeof value["nonce"] !== "number" || !Number.isFinite(value["nonce"]))) {
33069
- return null;
33070
- }
33071
- return {
33072
- user: value["user"],
33073
- builder: value["builder"],
33074
- scopes: value["scopes"],
33075
- expiresAt: value["expiresAt"],
33076
- nonce: value["nonce"]
33077
- };
33058
+ return isHexString(c["dataRegistry"]) && isHexString(c["dataPortabilityPermissions"]) && isHexString(c["dataPortabilityServer"]) && isHexString(c["dataPortabilityGrantees"]) && isHexString(c["dataPortabilityEscrow"]) && isHexString(c["feeRegistry"]);
33078
33059
  }
33079
- function parseFileIds(fileIds) {
33060
+ function toUint256(value) {
33080
33061
  try {
33081
- const values = (fileIds ?? []).map((fileId) => BigInt(fileId));
33082
- return {
33083
- values,
33084
- display: values.map((fileId) => fileId.toString())
33085
- };
33062
+ if (typeof value === "number" && !Number.isSafeInteger(value)) {
33063
+ return null;
33064
+ }
33065
+ const big = typeof value === "bigint" ? value : BigInt(value);
33066
+ if (big < 0n) return null;
33067
+ return big;
33086
33068
  } catch {
33087
33069
  return null;
33088
33070
  }
33089
33071
  }
33090
33072
  async function verifyGrantRegistration(input) {
33091
- const payload = parseGrantRegistrationPayload(input.grant);
33092
- if (!payload) {
33093
- return {
33094
- valid: false,
33095
- error: "Grant must be JSON with scopes and expiresAt"
33096
- };
33073
+ if (!Array.isArray(input.scopes) || input.scopes.length === 0) {
33074
+ return { valid: false, error: "scopes must be a non-empty array" };
33097
33075
  }
33098
- const fileIds = parseFileIds(input.fileIds);
33099
- if (!fileIds) {
33100
- return { valid: false, error: "fileIds must contain integer values" };
33076
+ if (!input.scopes.every((scope) => typeof scope === "string")) {
33077
+ return { valid: false, error: "scopes must contain only strings" };
33078
+ }
33079
+ const grantVersion = toUint256(input.grantVersion);
33080
+ if (grantVersion === null || grantVersion < 1n) {
33081
+ return { valid: false, error: "grantVersion must be a uint256 >= 1" };
33082
+ }
33083
+ const expiresAt = toUint256(input.expiresAt);
33084
+ if (expiresAt === null) {
33085
+ return { valid: false, error: "expiresAt must be a non-negative uint256" };
33101
33086
  }
33102
33087
  let valid;
33103
33088
  try {
@@ -33109,8 +33094,9 @@ async function verifyGrantRegistration(input) {
33109
33094
  message: {
33110
33095
  grantorAddress: input.grantorAddress,
33111
33096
  granteeId: input.granteeId,
33112
- grant: input.grant,
33113
- fileIds: fileIds.values
33097
+ scopes: input.scopes,
33098
+ grantVersion,
33099
+ expiresAt
33114
33100
  },
33115
33101
  signature: input.signature
33116
33102
  });
@@ -33121,19 +33107,197 @@ async function verifyGrantRegistration(input) {
33121
33107
  return { valid: false, error: "Grant signature does not match grantor" };
33122
33108
  }
33123
33109
  const nowSeconds = input.nowSeconds ?? Math.floor(Date.now() / 1e3);
33124
- if (payload.expiresAt > 0 && payload.expiresAt < nowSeconds) {
33110
+ if (expiresAt > 0n && expiresAt < BigInt(nowSeconds)) {
33125
33111
  return { valid: false, error: "Grant has expired" };
33126
33112
  }
33127
- if (payload.user !== void 0 && payload.user.toLowerCase() !== input.grantorAddress.toLowerCase()) {
33128
- return { valid: false, error: "Grant user does not match grantorAddress" };
33129
- }
33130
33113
  return {
33131
33114
  valid: true,
33132
33115
  grantorAddress: input.grantorAddress,
33133
33116
  granteeId: input.granteeId,
33134
- grant: input.grant,
33135
- payload,
33136
- fileIds: fileIds.display
33117
+ scopes: input.scopes,
33118
+ grantVersion: grantVersion.toString(),
33119
+ expiresAt: expiresAt.toString()
33120
+ };
33121
+ }
33122
+
33123
+ // src/protocol/escrow-deposit.ts
33124
+ import { encodeFunctionData } from "viem";
33125
+ var ESCROW_DEPOSIT_ABI = [
33126
+ {
33127
+ type: "function",
33128
+ name: "depositNative",
33129
+ stateMutability: "payable",
33130
+ inputs: [{ name: "account", type: "address" }],
33131
+ outputs: []
33132
+ },
33133
+ {
33134
+ type: "function",
33135
+ name: "depositToken",
33136
+ stateMutability: "nonpayable",
33137
+ inputs: [
33138
+ { name: "account", type: "address" },
33139
+ { name: "token", type: "address" },
33140
+ { name: "amount", type: "uint256" }
33141
+ ],
33142
+ outputs: []
33143
+ }
33144
+ ];
33145
+ function escrowContractAddress(config) {
33146
+ return config.contracts.dataPortabilityEscrow;
33147
+ }
33148
+ function encodeDepositNativeData(input) {
33149
+ return encodeFunctionData({
33150
+ abi: ESCROW_DEPOSIT_ABI,
33151
+ functionName: "depositNative",
33152
+ args: [input.account]
33153
+ });
33154
+ }
33155
+ function encodeDepositTokenData(input) {
33156
+ return encodeFunctionData({
33157
+ abi: ESCROW_DEPOSIT_ABI,
33158
+ functionName: "depositToken",
33159
+ args: [input.account, input.token, input.amount]
33160
+ });
33161
+ }
33162
+ function buildDepositNativeRequest(config, input) {
33163
+ return {
33164
+ to: escrowContractAddress(config),
33165
+ data: encodeDepositNativeData({ account: input.account }),
33166
+ value: input.amount
33167
+ };
33168
+ }
33169
+ function buildDepositTokenRequest(config, input) {
33170
+ return {
33171
+ to: escrowContractAddress(config),
33172
+ data: encodeDepositTokenData(input)
33173
+ };
33174
+ }
33175
+
33176
+ // src/protocol/data-point-status.ts
33177
+ import { encodeFunctionData as encodeFunctionData2 } from "viem";
33178
+ var DataPointStatus = /* @__PURE__ */ ((DataPointStatus2) => {
33179
+ DataPointStatus2[DataPointStatus2["None"] = 0] = "None";
33180
+ DataPointStatus2[DataPointStatus2["Active"] = 1] = "Active";
33181
+ DataPointStatus2[DataPointStatus2["Inactive"] = 2] = "Inactive";
33182
+ DataPointStatus2[DataPointStatus2["Unavailable"] = 3] = "Unavailable";
33183
+ return DataPointStatus2;
33184
+ })(DataPointStatus || {});
33185
+ var DATA_REGISTRY_STATUS_ABI = [
33186
+ {
33187
+ type: "function",
33188
+ name: "setStatus",
33189
+ stateMutability: "nonpayable",
33190
+ inputs: [
33191
+ { name: "scope", type: "string" },
33192
+ { name: "newStatus", type: "uint8" }
33193
+ ],
33194
+ outputs: []
33195
+ }
33196
+ ];
33197
+ function dataRegistryContractAddress(config) {
33198
+ return config.contracts.dataRegistry;
33199
+ }
33200
+ function encodeSetDataPointStatusData(input) {
33201
+ return encodeFunctionData2({
33202
+ abi: DATA_REGISTRY_STATUS_ABI,
33203
+ functionName: "setStatus",
33204
+ args: [input.scope, input.status]
33205
+ });
33206
+ }
33207
+ function buildSetDataPointStatusRequest(config, input) {
33208
+ return {
33209
+ to: dataRegistryContractAddress(config),
33210
+ data: encodeSetDataPointStatusData(input)
33211
+ };
33212
+ }
33213
+ function buildMarkDataPointUnavailableRequest(config, input) {
33214
+ return buildSetDataPointStatusRequest(config, {
33215
+ scope: input.scope,
33216
+ status: 3 /* Unavailable */
33217
+ });
33218
+ }
33219
+
33220
+ // src/protocol/fee-registry.ts
33221
+ import { parseAbi } from "viem";
33222
+ var FEE_REGISTRY_ABI = parseAbi([
33223
+ "struct Fee { uint256 amount; address asset; address payee; bool enabled; }",
33224
+ "function fees(bytes32 operation) view returns (Fee)",
33225
+ "function operationKey(string name) pure returns (bytes32)"
33226
+ ]);
33227
+ var REGISTRATION_KIND_FOR_OP = {
33228
+ grant: "grant_registration",
33229
+ data: "data_registration",
33230
+ server: "server_registration",
33231
+ builder: "builder_registration"
33232
+ };
33233
+ function operationNameFor(kind, opts) {
33234
+ switch (kind) {
33235
+ case "grant_registration":
33236
+ return opts?.grantRegistrationOpName ?? "grant_registration";
33237
+ case "data_access":
33238
+ return opts?.dataAccessOpName ?? "data_access";
33239
+ case "data_registration":
33240
+ return opts?.dataRegistrationOpName ?? "data_registration";
33241
+ case "server_registration":
33242
+ return opts?.serverRegistrationOpName ?? "server_registration";
33243
+ case "builder_registration":
33244
+ return opts?.builderRegistrationOpName ?? "builder_registration";
33245
+ }
33246
+ }
33247
+ var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
33248
+ async function getFee(client, config, kind, opts) {
33249
+ const address = config.contracts.feeRegistry;
33250
+ const opName = operationNameFor(kind, opts);
33251
+ const opKey = await client.readContract({
33252
+ address,
33253
+ abi: FEE_REGISTRY_ABI,
33254
+ functionName: "operationKey",
33255
+ args: [opName]
33256
+ });
33257
+ const fee = await client.readContract({
33258
+ address,
33259
+ abi: FEE_REGISTRY_ABI,
33260
+ functionName: "fees",
33261
+ args: [opKey]
33262
+ });
33263
+ if (fee.enabled && fee.payee === ZERO_ADDRESS) {
33264
+ throw new Error(
33265
+ `FeeRegistry: enabled operation "${opName}" has zero-address payee \u2014 contract pre-flight rejects payouts to 0x0`
33266
+ );
33267
+ }
33268
+ return fee;
33269
+ }
33270
+ async function getOpFee(client, config, opType, opts) {
33271
+ const registrationKind = REGISTRATION_KIND_FOR_OP[opType];
33272
+ if (!registrationKind) {
33273
+ throw new Error(
33274
+ `getOpFee: unknown opType "${opType}" \u2014 supported types are ${Object.keys(REGISTRATION_KIND_FOR_OP).join(", ")}`
33275
+ );
33276
+ }
33277
+ const includeDataAccess = opType === "grant";
33278
+ const [registration, dataAccess] = await Promise.all([
33279
+ getFee(client, config, registrationKind, opts),
33280
+ includeDataAccess ? getFee(client, config, "data_access", opts) : Promise.resolve({
33281
+ amount: 0n,
33282
+ asset: ZERO_ADDRESS,
33283
+ payee: ZERO_ADDRESS,
33284
+ enabled: false
33285
+ })
33286
+ ]);
33287
+ if (registration.enabled && dataAccess.enabled && registration.asset.toLowerCase() !== dataAccess.asset.toLowerCase()) {
33288
+ throw new Error(
33289
+ `FeeRegistry asset mismatch for "${opType}": registration=${registration.asset} vs data_access=${dataAccess.asset}. The gateway requires both kinds to settle in the same asset when both are enabled.`
33290
+ );
33291
+ }
33292
+ const asset = registration.enabled ? registration.asset : dataAccess.enabled ? dataAccess.asset : ZERO_ADDRESS;
33293
+ return {
33294
+ asset,
33295
+ registrationFee: registration.enabled ? registration.amount : 0n,
33296
+ dataAccessFee: dataAccess.enabled ? dataAccess.amount : 0n,
33297
+ registrationEnabled: registration.enabled,
33298
+ dataAccessEnabled: dataAccess.enabled,
33299
+ registrationPayee: registration.enabled ? registration.payee : ZERO_ADDRESS,
33300
+ dataAccessPayee: dataAccess.enabled ? dataAccess.payee : ZERO_ADDRESS
33137
33301
  };
33138
33302
  }
33139
33303
 
@@ -33207,6 +33371,45 @@ var IngestResponseSchema = z2.object({
33207
33371
  status: z2.enum(["stored", "syncing"])
33208
33372
  });
33209
33373
 
33374
+ // src/protocol/personal-server-data.ts
33375
+ function personalServerDataReadPath(scope) {
33376
+ return `/v1/data/${encodeURIComponent(scope)}`;
33377
+ }
33378
+ async function buildPersonalServerDataReadRequest(params) {
33379
+ const path = personalServerDataReadPath(params.scope);
33380
+ const baseUrl = params.personalServerUrl.replace(/\/+$/, "");
33381
+ const audience = params.audience ?? baseUrl;
33382
+ const headers = new Headers(params.headers);
33383
+ headers.set(
33384
+ "Authorization",
33385
+ await buildWeb3SignedHeader({
33386
+ aud: audience,
33387
+ grantId: params.grantId,
33388
+ method: "GET",
33389
+ signMessage: params.signMessage,
33390
+ uri: path
33391
+ })
33392
+ );
33393
+ return new Request(`${baseUrl}${path}`, {
33394
+ headers,
33395
+ method: "GET"
33396
+ });
33397
+ }
33398
+ async function readPersonalServerData(params) {
33399
+ const fetchFn = params.fetch ?? globalThis.fetch;
33400
+ if (fetchFn === void 0) {
33401
+ throw new Error("No fetch implementation available");
33402
+ }
33403
+ const request = await buildPersonalServerDataReadRequest(params);
33404
+ const response = await fetchFn(request);
33405
+ if (!response.ok) {
33406
+ throw new Error(
33407
+ `Personal Server data read failed: ${response.status} ${response.statusText}`
33408
+ );
33409
+ }
33410
+ return DataFileEnvelopeSchema.parse(await response.json());
33411
+ }
33412
+
33210
33413
  // src/protocol/gateway.ts
33211
33414
  function createGatewayClient(baseUrl) {
33212
33415
  const base = baseUrl.replace(/\/+$/, "");
@@ -33214,15 +33417,6 @@ function createGatewayClient(baseUrl) {
33214
33417
  const envelope = await res.json();
33215
33418
  return envelope.data;
33216
33419
  }
33217
- function normalizeFileRecord(record) {
33218
- return {
33219
- fileId: record.fileId ?? record.id ?? "",
33220
- owner: record.owner ?? record.ownerAddress ?? "",
33221
- url: record.url,
33222
- schemaId: record.schemaId,
33223
- createdAt: record.createdAt ?? record.addedAt ?? ""
33224
- };
33225
- }
33226
33420
  function getMutationId(body, key) {
33227
33421
  const value = body[key] ?? body["id"];
33228
33422
  return typeof value === "string" ? value : void 0;
@@ -33272,27 +33466,34 @@ function createGatewayClient(baseUrl) {
33272
33466
  }
33273
33467
  return unwrapEnvelope(res);
33274
33468
  },
33275
- async getFile(fileId) {
33276
- const res = await fetch(`${base}/v1/files/${fileId}`);
33469
+ async getDataPoint(dataPointId) {
33470
+ const res = await fetch(`${base}/v1/data/${dataPointId}`);
33277
33471
  if (res.status === 404) return null;
33278
33472
  if (!res.ok) {
33279
33473
  throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
33280
33474
  }
33281
- return normalizeFileRecord(await unwrapEnvelope(res));
33475
+ return unwrapEnvelope(res);
33282
33476
  },
33283
- async listFilesSince(owner, cursor) {
33477
+ async listDataPointsByOwner(owner, cursor, options) {
33284
33478
  const params = new URLSearchParams({ user: owner });
33285
33479
  if (cursor !== null) {
33286
- params.set("since", cursor);
33480
+ params.set("cursor", cursor);
33481
+ }
33482
+ if (options?.since) {
33483
+ params.set("since", options.since);
33287
33484
  }
33288
- const res = await fetch(`${base}/v1/files?${params.toString()}`);
33485
+ if (options?.limit !== void 0) {
33486
+ params.set("limit", String(options.limit));
33487
+ }
33488
+ const res = await fetch(`${base}/v1/data?${params.toString()}`);
33289
33489
  if (!res.ok) {
33290
33490
  throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
33291
33491
  }
33292
- const data = await unwrapEnvelope(res);
33492
+ const envelope = await res.json();
33493
+ const nextCursor = envelope.pagination?.hasMore === false ? null : envelope.pagination?.nextCursor ?? null;
33293
33494
  return {
33294
- files: data.files.map(normalizeFileRecord),
33295
- cursor: data.cursor
33495
+ dataPoints: envelope.data.dataPoints,
33496
+ cursor: nextCursor
33296
33497
  };
33297
33498
  },
33298
33499
  async getSchema(schemaId) {
@@ -33333,8 +33534,8 @@ function createGatewayClient(baseUrl) {
33333
33534
  alreadyRegistered: false
33334
33535
  };
33335
33536
  },
33336
- async registerFile(params) {
33337
- const res = await fetch(`${base}/v1/files`, {
33537
+ async registerBuilder(params) {
33538
+ const res = await fetch(`${base}/v1/builders`, {
33338
33539
  method: "POST",
33339
33540
  headers: {
33340
33541
  "Content-Type": "application/json",
@@ -33342,22 +33543,57 @@ function createGatewayClient(baseUrl) {
33342
33543
  },
33343
33544
  body: JSON.stringify({
33344
33545
  ownerAddress: params.ownerAddress,
33345
- url: params.url,
33346
- schemaId: params.schemaId
33546
+ granteeAddress: params.granteeAddress,
33547
+ publicKey: params.publicKey,
33548
+ appUrl: params.appUrl
33347
33549
  })
33348
33550
  });
33349
33551
  if (res.status === 409) {
33350
33552
  const body2 = await res.json().catch(() => ({}));
33351
33553
  return {
33352
- fileId: getMutationId(body2, "fileId")
33554
+ builderId: getMutationId(
33555
+ body2,
33556
+ "builderId"
33557
+ ),
33558
+ alreadyRegistered: true
33353
33559
  };
33354
33560
  }
33355
33561
  if (!res.ok) {
33356
33562
  throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
33357
33563
  }
33358
- const body = await res.json();
33564
+ const body = await res.json().catch(() => ({}));
33565
+ return {
33566
+ builderId: getMutationId(body, "builderId"),
33567
+ alreadyRegistered: false
33568
+ };
33569
+ },
33570
+ async registerDataPoint(params) {
33571
+ const res = await fetch(`${base}/v1/data`, {
33572
+ method: "POST",
33573
+ headers: {
33574
+ "Content-Type": "application/json",
33575
+ Authorization: `Web3Signed ${params.signature}`
33576
+ },
33577
+ body: JSON.stringify({
33578
+ ownerAddress: params.ownerAddress,
33579
+ scope: params.scope,
33580
+ dataHash: params.dataHash,
33581
+ metadataHash: params.metadataHash,
33582
+ expectedVersion: params.expectedVersion
33583
+ })
33584
+ });
33585
+ if (!res.ok) {
33586
+ const body2 = await res.json().catch(() => ({}));
33587
+ const detail = body2.error ?? res.statusText;
33588
+ throw new Error(`Gateway error: ${res.status} ${detail}`);
33589
+ }
33590
+ const body = await res.json().catch(() => ({}));
33359
33591
  return {
33360
- fileId: getMutationId(body, "fileId")
33592
+ dataPointId: getMutationId(
33593
+ body,
33594
+ "dataPointId"
33595
+ ),
33596
+ expectedVersion: body.expectedVersion
33361
33597
  };
33362
33598
  },
33363
33599
  async createGrant(params) {
@@ -33370,8 +33606,9 @@ function createGatewayClient(baseUrl) {
33370
33606
  body: JSON.stringify({
33371
33607
  grantorAddress: params.grantorAddress,
33372
33608
  granteeId: params.granteeId,
33373
- grant: params.grant,
33374
- fileIds: params.fileIds
33609
+ scopes: params.scopes,
33610
+ grantVersion: params.grantVersion,
33611
+ expiresAt: params.expiresAt
33375
33612
  })
33376
33613
  });
33377
33614
  if (res.status === 409) {
@@ -33396,7 +33633,8 @@ function createGatewayClient(baseUrl) {
33396
33633
  Authorization: `Web3Signed ${params.signature}`
33397
33634
  },
33398
33635
  body: JSON.stringify({
33399
- grantorAddress: params.grantorAddress
33636
+ grantorAddress: params.grantorAddress,
33637
+ grantVersion: params.grantVersion
33400
33638
  })
33401
33639
  });
33402
33640
  if (res.status === 409) return;
@@ -33404,21 +33642,62 @@ function createGatewayClient(baseUrl) {
33404
33642
  throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
33405
33643
  }
33406
33644
  },
33407
- async deleteFile(params) {
33408
- const res = await fetch(`${base}/v1/files/${params.fileId}`, {
33409
- method: "DELETE",
33645
+ async getEscrowBalance(account) {
33646
+ const res = await fetch(`${base}/v1/escrow/balance?account=${account}`);
33647
+ if (!res.ok) {
33648
+ throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
33649
+ }
33650
+ return await res.json();
33651
+ },
33652
+ async submitEscrowDeposit(params) {
33653
+ const res = await fetch(`${base}/v1/escrow/deposit`, {
33654
+ method: "POST",
33655
+ headers: { "Content-Type": "application/json" },
33656
+ body: JSON.stringify({ txHash: params.txHash })
33657
+ });
33658
+ if (res.status !== 200 && res.status !== 202) {
33659
+ throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
33660
+ }
33661
+ return await res.json();
33662
+ },
33663
+ async payForOperation(params) {
33664
+ const body = {
33665
+ payerAddress: params.payerAddress,
33666
+ opType: params.opType,
33667
+ opId: params.opId,
33668
+ asset: params.asset,
33669
+ amount: params.amount,
33670
+ paymentNonce: params.paymentNonce
33671
+ };
33672
+ if (params.accessRecord) {
33673
+ body["accessRecord"] = params.accessRecord;
33674
+ }
33675
+ const res = await fetch(`${base}/v1/escrow/pay`, {
33676
+ method: "POST",
33410
33677
  headers: {
33411
33678
  "Content-Type": "application/json",
33412
33679
  Authorization: `Web3Signed ${params.signature}`
33413
33680
  },
33414
- body: JSON.stringify({
33415
- ownerAddress: params.ownerAddress
33416
- })
33681
+ body: JSON.stringify(body)
33682
+ });
33683
+ if (!res.ok) {
33684
+ throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
33685
+ }
33686
+ return await res.json();
33687
+ },
33688
+ async settle(params) {
33689
+ const res = await fetch(`${base}/v1/settle`, {
33690
+ method: "POST",
33691
+ headers: { "Content-Type": "application/json" },
33692
+ // The gateway accepts an empty body; only `limit` is recognised.
33693
+ // Always send a JSON body so the gateway's req.body shape parse
33694
+ // doesn't have to deal with an undefined.
33695
+ body: JSON.stringify(params ?? {})
33417
33696
  });
33418
- if (res.status === 409) return;
33419
33697
  if (!res.ok) {
33420
33698
  throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
33421
33699
  }
33700
+ return await res.json();
33422
33701
  }
33423
33702
  };
33424
33703
  }
@@ -33487,6 +33766,7 @@ async function parsePSError(response) {
33487
33766
  }
33488
33767
  export {
33489
33768
  ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT,
33769
+ ADD_DATA_TYPES,
33490
33770
  AccountPersonalServerLiteOwnerBindingError,
33491
33771
  AccountPersonalServerRegistrationError,
33492
33772
  BUILDER_REGISTRATION_TYPES,
@@ -33496,12 +33776,15 @@ export {
33496
33776
  CallbackStorage,
33497
33777
  ContractFactory,
33498
33778
  ContractNotFoundError,
33779
+ DATA_REGISTRY_STATUS_ABI,
33499
33780
  DataFileEnvelopeSchema,
33781
+ DataPointStatus,
33500
33782
  DropboxStorage,
33501
33783
  ECIESError,
33784
+ ESCROW_DEPOSIT_ABI,
33502
33785
  ExpiredTokenError,
33503
- FILE_DELETION_TYPES,
33504
- FILE_REGISTRATION_TYPES,
33786
+ FEE_REGISTRY_ABI,
33787
+ GENERIC_PAYMENT_TYPES,
33505
33788
  GRANT_REGISTRATION_TYPES,
33506
33789
  GRANT_REVOCATION_TYPES,
33507
33790
  GoogleDriveStorage,
@@ -33512,6 +33795,7 @@ export {
33512
33795
  IpfsStorage,
33513
33796
  MASTER_KEY_MESSAGE,
33514
33797
  MissingAuthError,
33798
+ NATIVE_VANA_ASSET,
33515
33799
  NetworkError,
33516
33800
  NodeECIESUint8Provider as NodeECIESProvider,
33517
33801
  NodePlatformAdapter,
@@ -33529,6 +33813,8 @@ export {
33529
33813
  PersonalServerError,
33530
33814
  PinataStorage,
33531
33815
  R2Storage,
33816
+ RECORD_DATA_ACCESS_TYPES,
33817
+ REGISTRATION_KIND_FOR_OP,
33532
33818
  ReadOnlyError,
33533
33819
  RelayerError,
33534
33820
  SERVER_REGISTRATION_TYPES,
@@ -33543,10 +33829,15 @@ export {
33543
33829
  VanaError,
33544
33830
  VanaStorage,
33545
33831
  assertValidPkceVerifier,
33832
+ buildDepositNativeRequest,
33833
+ buildDepositTokenRequest,
33834
+ buildMarkDataPointUnavailableRequest,
33835
+ buildPersonalServerDataReadRequest,
33546
33836
  buildPersonalServerLiteOwnerBindingMessage,
33547
33837
  buildPersonalServerLiteOwnerBindingSignature,
33548
33838
  buildPersonalServerRegistrationSignature,
33549
33839
  buildPersonalServerRegistrationTypedData,
33840
+ buildSetDataPointStatusRequest,
33550
33841
  buildWeb3SignedHeader,
33551
33842
  builderRegistrationDomain,
33552
33843
  chains,
@@ -33564,14 +33855,19 @@ export {
33564
33855
  createVanaStorageProvider,
33565
33856
  createViemPersonalServerLiteOwnerBindingSigner,
33566
33857
  createViemPersonalServerRegistrationSigner,
33858
+ dataRegistryContractAddress,
33859
+ dataRegistryDomain,
33567
33860
  decryptWithPassword,
33568
33861
  deriveMasterKey,
33569
33862
  deriveScopeKey,
33570
33863
  deserializeECIES,
33571
33864
  detectPlatform,
33865
+ encodeDepositNativeData,
33866
+ encodeDepositTokenData,
33867
+ encodeSetDataPointStatusData,
33572
33868
  encryptWithPassword,
33573
- fileDeletionDomain,
33574
- fileRegistrationDomain,
33869
+ escrowContractAddress,
33870
+ escrowPaymentDomain,
33575
33871
  generatePkceVerifier,
33576
33872
  getAbi,
33577
33873
  getAllChains,
@@ -33579,6 +33875,8 @@ export {
33579
33875
  getContractAddress,
33580
33876
  getContractController,
33581
33877
  getContractInfo,
33878
+ getFee,
33879
+ getOpFee,
33582
33880
  getPlatformCapabilities,
33583
33881
  getServiceEndpoints,
33584
33882
  grantRegistrationDomain,
@@ -33590,11 +33888,12 @@ export {
33590
33888
  moksha,
33591
33889
  mokshaServices,
33592
33890
  mokshaTestnet2 as mokshaTestnet,
33593
- parseGrantRegistrationPayload,
33594
33891
  parsePSError,
33595
33892
  parseScope,
33596
33893
  parseWeb3SignedHeader,
33894
+ personalServerDataReadPath,
33597
33895
  personalServerRegistrationDomain,
33896
+ readPersonalServerData,
33598
33897
  recoverServerOwner,
33599
33898
  registerPersonalServerSignature,
33600
33899
  scopeCoveredByGrant,