@opendatalabs/vana-sdk 3.5.1 → 3.6.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.
Files changed (116) hide show
  1. package/README.md +116 -0
  2. package/dist/direct/access-request-client.cjs +104 -0
  3. package/dist/direct/access-request-client.cjs.map +1 -0
  4. package/dist/direct/access-request-client.d.ts +51 -0
  5. package/dist/direct/access-request-client.js +79 -0
  6. package/dist/direct/access-request-client.js.map +1 -0
  7. package/dist/direct/access-request-client.test.d.ts +1 -0
  8. package/dist/direct/connect-flow.cjs +152 -0
  9. package/dist/direct/connect-flow.cjs.map +1 -0
  10. package/dist/direct/connect-flow.d.ts +85 -0
  11. package/dist/direct/connect-flow.js +128 -0
  12. package/dist/direct/connect-flow.js.map +1 -0
  13. package/dist/direct/connect-flow.test.d.ts +1 -0
  14. package/dist/direct/controller.cjs +129 -0
  15. package/dist/direct/controller.cjs.map +1 -0
  16. package/dist/direct/controller.d.ts +152 -0
  17. package/dist/direct/controller.js +109 -0
  18. package/dist/direct/controller.js.map +1 -0
  19. package/dist/direct/controller.test.d.ts +1 -0
  20. package/dist/direct/endpoints.cjs +45 -0
  21. package/dist/direct/endpoints.cjs.map +1 -0
  22. package/dist/direct/endpoints.d.ts +22 -0
  23. package/dist/direct/endpoints.js +19 -0
  24. package/dist/direct/endpoints.js.map +1 -0
  25. package/dist/direct/errors.cjs +65 -0
  26. package/dist/direct/errors.cjs.map +1 -0
  27. package/dist/direct/errors.d.ts +44 -0
  28. package/dist/direct/errors.js +38 -0
  29. package/dist/direct/errors.js.map +1 -0
  30. package/dist/direct/escrow-payment.cjs +96 -0
  31. package/dist/direct/escrow-payment.cjs.map +1 -0
  32. package/dist/direct/escrow-payment.d.ts +81 -0
  33. package/dist/direct/escrow-payment.js +72 -0
  34. package/dist/direct/escrow-payment.js.map +1 -0
  35. package/dist/direct/escrow-payment.test.d.ts +1 -0
  36. package/dist/direct/personal-server-read.cjs +149 -0
  37. package/dist/direct/personal-server-read.cjs.map +1 -0
  38. package/dist/direct/personal-server-read.d.ts +103 -0
  39. package/dist/direct/personal-server-read.js +124 -0
  40. package/dist/direct/personal-server-read.js.map +1 -0
  41. package/dist/direct/personal-server-read.test.d.ts +1 -0
  42. package/dist/direct/types.cjs +35 -0
  43. package/dist/direct/types.cjs.map +1 -0
  44. package/dist/direct/types.d.ts +205 -0
  45. package/dist/direct/types.js +11 -0
  46. package/dist/direct/types.js.map +1 -0
  47. package/dist/direct/use-direct-vana-connect.cjs +68 -0
  48. package/dist/direct/use-direct-vana-connect.cjs.map +1 -0
  49. package/dist/direct/use-direct-vana-connect.d.ts +45 -0
  50. package/dist/direct/use-direct-vana-connect.js +46 -0
  51. package/dist/direct/use-direct-vana-connect.js.map +1 -0
  52. package/dist/index.browser.d.ts +7 -3
  53. package/dist/index.browser.js +438 -157
  54. package/dist/index.browser.js.map +4 -4
  55. package/dist/index.node.cjs +461 -162
  56. package/dist/index.node.cjs.map +4 -4
  57. package/dist/index.node.d.ts +7 -3
  58. package/dist/index.node.js +438 -157
  59. package/dist/index.node.js.map +4 -4
  60. package/dist/protocol/data-point-status.cjs +80 -0
  61. package/dist/protocol/data-point-status.cjs.map +1 -0
  62. package/dist/protocol/data-point-status.d.ts +34 -0
  63. package/dist/protocol/data-point-status.js +51 -0
  64. package/dist/protocol/data-point-status.js.map +1 -0
  65. package/dist/protocol/data-point-status.test.d.ts +1 -0
  66. package/dist/protocol/eip712.cjs +53 -31
  67. package/dist/protocol/eip712.cjs.map +1 -1
  68. package/dist/protocol/eip712.d.ts +98 -43
  69. package/dist/protocol/eip712.js +47 -27
  70. package/dist/protocol/eip712.js.map +1 -1
  71. package/dist/protocol/escrow-deposit.cjs +89 -0
  72. package/dist/protocol/escrow-deposit.cjs.map +1 -0
  73. package/dist/protocol/escrow-deposit.d.ts +47 -0
  74. package/dist/protocol/escrow-deposit.js +60 -0
  75. package/dist/protocol/escrow-deposit.js.map +1 -0
  76. package/dist/protocol/escrow-deposit.test.d.ts +1 -0
  77. package/dist/protocol/escrow-flow.test.d.ts +21 -0
  78. package/dist/protocol/fee-registry.cjs +116 -0
  79. package/dist/protocol/fee-registry.cjs.map +1 -0
  80. package/dist/protocol/fee-registry.d.ts +151 -0
  81. package/dist/protocol/fee-registry.js +89 -0
  82. package/dist/protocol/fee-registry.js.map +1 -0
  83. package/dist/protocol/fee-registry.test.d.ts +1 -0
  84. package/dist/protocol/gateway.cjs +107 -37
  85. package/dist/protocol/gateway.cjs.map +1 -1
  86. package/dist/protocol/gateway.d.ts +223 -57
  87. package/dist/protocol/gateway.js +107 -37
  88. package/dist/protocol/gateway.js.map +1 -1
  89. package/dist/protocol/grants.cjs +27 -64
  90. package/dist/protocol/grants.cjs.map +1 -1
  91. package/dist/protocol/grants.d.ts +6 -13
  92. package/dist/protocol/grants.js +27 -63
  93. package/dist/protocol/grants.js.map +1 -1
  94. package/dist/protocol/personal-server-data.cjs +71 -0
  95. package/dist/protocol/personal-server-data.cjs.map +1 -0
  96. package/dist/protocol/personal-server-data.d.ts +16 -0
  97. package/dist/protocol/personal-server-data.js +47 -0
  98. package/dist/protocol/personal-server-data.js.map +1 -0
  99. package/dist/protocol/personal-server-data.test.d.ts +1 -0
  100. package/dist/protocol/personal-server-lite-owner-binding.cjs +93 -0
  101. package/dist/protocol/personal-server-lite-owner-binding.cjs.map +1 -0
  102. package/dist/protocol/personal-server-lite-owner-binding.d.ts +44 -0
  103. package/dist/protocol/personal-server-lite-owner-binding.js +65 -0
  104. package/dist/protocol/personal-server-lite-owner-binding.js.map +1 -0
  105. package/dist/protocol/personal-server-lite-owner-binding.test.d.ts +1 -0
  106. package/dist/react.cjs +32 -0
  107. package/dist/react.cjs.map +1 -0
  108. package/dist/react.d.ts +33 -0
  109. package/dist/react.js +11 -0
  110. package/dist/react.js.map +1 -0
  111. package/dist/server.cjs +73 -0
  112. package/dist/server.cjs.map +1 -0
  113. package/dist/server.d.ts +32 -0
  114. package/dist/server.js +55 -0
  115. package/dist/server.js.map +1 -0
  116. package/package.json +20 -1
@@ -32567,6 +32567,7 @@ function formatOAuthError(body, status) {
32567
32567
  // src/protocol/eip712.ts
32568
32568
  var DOMAIN_NAME = "Vana Data Portability";
32569
32569
  var DOMAIN_VERSION = "1";
32570
+ var NATIVE_VANA_ASSET = "0x0000000000000000000000000000000000000000";
32570
32571
  function buildDomain(chainId, verifyingContract) {
32571
32572
  return {
32572
32573
  name: DOMAIN_NAME,
@@ -32575,13 +32576,7 @@ function buildDomain(chainId, verifyingContract) {
32575
32576
  verifyingContract
32576
32577
  };
32577
32578
  }
32578
- function fileRegistrationDomain(config) {
32579
- return buildDomain(
32580
- config.chainId,
32581
- config.contracts.dataRegistry
32582
- );
32583
- }
32584
- function fileDeletionDomain(config) {
32579
+ function dataRegistryDomain(config) {
32585
32580
  return buildDomain(
32586
32581
  config.chainId,
32587
32582
  config.contracts.dataRegistry
@@ -32611,31 +32606,26 @@ function builderRegistrationDomain(config) {
32611
32606
  config.contracts.dataPortabilityGrantees
32612
32607
  );
32613
32608
  }
32614
- var FILE_REGISTRATION_TYPES = {
32615
- FileRegistration: [
32616
- { name: "ownerAddress", type: "address" },
32617
- { name: "url", type: "string" },
32618
- { name: "schemaId", type: "bytes32" }
32619
- ]
32620
- };
32621
- var FILE_DELETION_TYPES = {
32622
- FileDeletion: [
32623
- { name: "ownerAddress", type: "address" },
32624
- { name: "fileId", type: "bytes32" }
32625
- ]
32626
- };
32609
+ function escrowPaymentDomain(config) {
32610
+ return buildDomain(
32611
+ config.chainId,
32612
+ config.contracts.dataPortabilityEscrow
32613
+ );
32614
+ }
32627
32615
  var GRANT_REGISTRATION_TYPES = {
32628
32616
  GrantRegistration: [
32629
32617
  { name: "grantorAddress", type: "address" },
32630
32618
  { name: "granteeId", type: "bytes32" },
32631
- { name: "grant", type: "string" },
32632
- { name: "fileIds", type: "uint256[]" }
32619
+ { name: "scopes", type: "string[]" },
32620
+ { name: "grantVersion", type: "uint256" },
32621
+ { name: "expiresAt", type: "uint256" }
32633
32622
  ]
32634
32623
  };
32635
32624
  var GRANT_REVOCATION_TYPES = {
32636
32625
  GrantRevocation: [
32637
32626
  { name: "grantorAddress", type: "address" },
32638
- { name: "grantId", type: "bytes32" }
32627
+ { name: "grantId", type: "bytes32" },
32628
+ { name: "grantVersion", type: "uint256" }
32639
32629
  ]
32640
32630
  };
32641
32631
  var SERVER_REGISTRATION_TYPES = {
@@ -32654,6 +32644,24 @@ var BUILDER_REGISTRATION_TYPES = {
32654
32644
  { name: "appUrl", type: "string" }
32655
32645
  ]
32656
32646
  };
32647
+ var ADD_DATA_TYPES = {
32648
+ AddData: [
32649
+ { name: "ownerAddress", type: "address" },
32650
+ { name: "scope", type: "string" },
32651
+ { name: "dataHash", type: "bytes32" },
32652
+ { name: "metadataHash", type: "bytes32" },
32653
+ { name: "expectedVersion", type: "uint256" }
32654
+ ]
32655
+ };
32656
+ var RECORD_DATA_ACCESS_TYPES = {
32657
+ RecordDataAccess: [
32658
+ { name: "ownerAddress", type: "address" },
32659
+ { name: "scope", type: "string" },
32660
+ { name: "version", type: "uint256" },
32661
+ { name: "accessor", type: "address" },
32662
+ { name: "recordId", type: "bytes32" }
32663
+ ]
32664
+ };
32657
32665
 
32658
32666
  // src/protocol/personal-server-registration.ts
32659
32667
  import {
@@ -33105,67 +33113,34 @@ function isDataPortabilityGatewayConfig(value) {
33105
33113
  return false;
33106
33114
  }
33107
33115
  const c = contracts;
33108
- return isHexString(c["dataRegistry"]) && isHexString(c["dataPortabilityPermissions"]) && isHexString(c["dataPortabilityServer"]) && isHexString(c["dataPortabilityGrantees"]);
33109
- }
33110
- function parseGrantRegistrationPayload(grant) {
33111
- let parsed;
33112
- try {
33113
- parsed = JSON.parse(grant);
33114
- } catch {
33115
- return null;
33116
- }
33117
- if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
33118
- return null;
33119
- }
33120
- const value = parsed;
33121
- if (!Array.isArray(value["scopes"]) || value["scopes"].length === 0) {
33122
- return null;
33123
- }
33124
- if (!value["scopes"].every((scope) => typeof scope === "string")) {
33125
- return null;
33126
- }
33127
- if (typeof value["expiresAt"] !== "number" || !Number.isFinite(value["expiresAt"])) {
33128
- return null;
33129
- }
33130
- if (value["user"] !== void 0 && !isHexString(value["user"])) {
33131
- return null;
33132
- }
33133
- if (value["builder"] !== void 0 && !isHexString(value["builder"])) {
33134
- return null;
33135
- }
33136
- if (value["nonce"] !== void 0 && (typeof value["nonce"] !== "number" || !Number.isFinite(value["nonce"]))) {
33137
- return null;
33138
- }
33139
- return {
33140
- user: value["user"],
33141
- builder: value["builder"],
33142
- scopes: value["scopes"],
33143
- expiresAt: value["expiresAt"],
33144
- nonce: value["nonce"]
33145
- };
33116
+ return isHexString(c["dataRegistry"]) && isHexString(c["dataPortabilityPermissions"]) && isHexString(c["dataPortabilityServer"]) && isHexString(c["dataPortabilityGrantees"]) && isHexString(c["dataPortabilityEscrow"]) && isHexString(c["feeRegistry"]);
33146
33117
  }
33147
- function parseFileIds(fileIds) {
33118
+ function toUint256(value) {
33148
33119
  try {
33149
- const values = (fileIds ?? []).map((fileId) => BigInt(fileId));
33150
- return {
33151
- values,
33152
- display: values.map((fileId) => fileId.toString())
33153
- };
33120
+ if (typeof value === "number" && !Number.isSafeInteger(value)) {
33121
+ return null;
33122
+ }
33123
+ const big = typeof value === "bigint" ? value : BigInt(value);
33124
+ if (big < 0n) return null;
33125
+ return big;
33154
33126
  } catch {
33155
33127
  return null;
33156
33128
  }
33157
33129
  }
33158
33130
  async function verifyGrantRegistration(input) {
33159
- const payload = parseGrantRegistrationPayload(input.grant);
33160
- if (!payload) {
33161
- return {
33162
- valid: false,
33163
- error: "Grant must be JSON with scopes and expiresAt"
33164
- };
33131
+ if (!Array.isArray(input.scopes) || input.scopes.length === 0) {
33132
+ return { valid: false, error: "scopes must be a non-empty array" };
33133
+ }
33134
+ if (!input.scopes.every((scope) => typeof scope === "string")) {
33135
+ return { valid: false, error: "scopes must contain only strings" };
33165
33136
  }
33166
- const fileIds = parseFileIds(input.fileIds);
33167
- if (!fileIds) {
33168
- return { valid: false, error: "fileIds must contain integer values" };
33137
+ const grantVersion = toUint256(input.grantVersion);
33138
+ if (grantVersion === null || grantVersion < 1n) {
33139
+ return { valid: false, error: "grantVersion must be a uint256 >= 1" };
33140
+ }
33141
+ const expiresAt = toUint256(input.expiresAt);
33142
+ if (expiresAt === null) {
33143
+ return { valid: false, error: "expiresAt must be a non-negative uint256" };
33169
33144
  }
33170
33145
  let valid;
33171
33146
  try {
@@ -33177,8 +33152,9 @@ async function verifyGrantRegistration(input) {
33177
33152
  message: {
33178
33153
  grantorAddress: input.grantorAddress,
33179
33154
  granteeId: input.granteeId,
33180
- grant: input.grant,
33181
- fileIds: fileIds.values
33155
+ scopes: input.scopes,
33156
+ grantVersion,
33157
+ expiresAt
33182
33158
  },
33183
33159
  signature: input.signature
33184
33160
  });
@@ -33189,26 +33165,269 @@ async function verifyGrantRegistration(input) {
33189
33165
  return { valid: false, error: "Grant signature does not match grantor" };
33190
33166
  }
33191
33167
  const nowSeconds = input.nowSeconds ?? Math.floor(Date.now() / 1e3);
33192
- if (payload.expiresAt > 0 && payload.expiresAt < nowSeconds) {
33168
+ if (expiresAt > 0n && expiresAt < BigInt(nowSeconds)) {
33193
33169
  return { valid: false, error: "Grant has expired" };
33194
33170
  }
33195
- if (payload.user !== void 0 && payload.user.toLowerCase() !== input.grantorAddress.toLowerCase()) {
33196
- return { valid: false, error: "Grant user does not match grantorAddress" };
33197
- }
33198
33171
  return {
33199
33172
  valid: true,
33200
33173
  grantorAddress: input.grantorAddress,
33201
33174
  granteeId: input.granteeId,
33202
- grant: input.grant,
33203
- payload,
33204
- fileIds: fileIds.display
33175
+ scopes: input.scopes,
33176
+ grantVersion: grantVersion.toString(),
33177
+ expiresAt: expiresAt.toString()
33205
33178
  };
33206
33179
  }
33207
33180
 
33208
- // src/protocol/scopes.ts
33181
+ // src/protocol/fee-registry.ts
33182
+ import { parseAbi } from "viem";
33183
+ var FEE_REGISTRY_ABI = parseAbi([
33184
+ "struct Fee { uint256 amount; address asset; address payee; bool enabled; }",
33185
+ "function fees(bytes32 operation) view returns (Fee)",
33186
+ "function operationKey(string name) pure returns (bytes32)"
33187
+ ]);
33188
+ var REGISTRATION_KIND_FOR_OP = {
33189
+ grant: "grant_registration",
33190
+ data: "data_registration",
33191
+ server: "server_registration",
33192
+ builder: "builder_registration"
33193
+ };
33194
+ function operationNameFor(kind, opts) {
33195
+ switch (kind) {
33196
+ case "grant_registration":
33197
+ return opts?.grantRegistrationOpName ?? "grant_registration";
33198
+ case "data_access":
33199
+ return opts?.dataAccessOpName ?? "data_access";
33200
+ case "data_registration":
33201
+ return opts?.dataRegistrationOpName ?? "data_registration";
33202
+ case "server_registration":
33203
+ return opts?.serverRegistrationOpName ?? "server_registration";
33204
+ case "builder_registration":
33205
+ return opts?.builderRegistrationOpName ?? "builder_registration";
33206
+ }
33207
+ }
33208
+ var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
33209
+ async function getFee(client, config, kind, opts) {
33210
+ const address = config.contracts.feeRegistry;
33211
+ const opName = operationNameFor(kind, opts);
33212
+ const opKey = await client.readContract({
33213
+ address,
33214
+ abi: FEE_REGISTRY_ABI,
33215
+ functionName: "operationKey",
33216
+ args: [opName]
33217
+ });
33218
+ const fee = await client.readContract({
33219
+ address,
33220
+ abi: FEE_REGISTRY_ABI,
33221
+ functionName: "fees",
33222
+ args: [opKey]
33223
+ });
33224
+ if (fee.enabled && fee.payee === ZERO_ADDRESS) {
33225
+ throw new Error(
33226
+ `FeeRegistry: enabled operation "${opName}" has zero-address payee \u2014 contract pre-flight rejects payouts to 0x0`
33227
+ );
33228
+ }
33229
+ return fee;
33230
+ }
33231
+ async function getOpFee(client, config, opType, opts) {
33232
+ const registrationKind = REGISTRATION_KIND_FOR_OP[opType];
33233
+ if (!registrationKind) {
33234
+ throw new Error(
33235
+ `getOpFee: unknown opType "${opType}" \u2014 supported types are ${Object.keys(REGISTRATION_KIND_FOR_OP).join(", ")}`
33236
+ );
33237
+ }
33238
+ const includeDataAccess = opType === "grant";
33239
+ const [registration, dataAccess] = await Promise.all([
33240
+ getFee(client, config, registrationKind, opts),
33241
+ includeDataAccess ? getFee(client, config, "data_access", opts) : Promise.resolve({
33242
+ amount: 0n,
33243
+ asset: ZERO_ADDRESS,
33244
+ payee: ZERO_ADDRESS,
33245
+ enabled: false
33246
+ })
33247
+ ]);
33248
+ if (registration.enabled && dataAccess.enabled && registration.asset.toLowerCase() !== dataAccess.asset.toLowerCase()) {
33249
+ throw new Error(
33250
+ `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.`
33251
+ );
33252
+ }
33253
+ const asset = registration.enabled ? registration.asset : dataAccess.enabled ? dataAccess.asset : ZERO_ADDRESS;
33254
+ return {
33255
+ asset,
33256
+ registrationFee: registration.enabled ? registration.amount : 0n,
33257
+ dataAccessFee: dataAccess.enabled ? dataAccess.amount : 0n,
33258
+ registrationEnabled: registration.enabled,
33259
+ dataAccessEnabled: dataAccess.enabled,
33260
+ registrationPayee: registration.enabled ? registration.payee : ZERO_ADDRESS,
33261
+ dataAccessPayee: dataAccess.enabled ? dataAccess.payee : ZERO_ADDRESS
33262
+ };
33263
+ }
33264
+
33265
+ // src/protocol/escrow-deposit.ts
33266
+ import { encodeFunctionData } from "viem";
33267
+ var ESCROW_DEPOSIT_ABI = [
33268
+ {
33269
+ type: "function",
33270
+ name: "depositNative",
33271
+ stateMutability: "payable",
33272
+ inputs: [{ name: "account", type: "address" }],
33273
+ outputs: []
33274
+ },
33275
+ {
33276
+ type: "function",
33277
+ name: "depositToken",
33278
+ stateMutability: "nonpayable",
33279
+ inputs: [
33280
+ { name: "account", type: "address" },
33281
+ { name: "token", type: "address" },
33282
+ { name: "amount", type: "uint256" }
33283
+ ],
33284
+ outputs: []
33285
+ }
33286
+ ];
33287
+ function escrowContractAddress(config) {
33288
+ return config.contracts.dataPortabilityEscrow;
33289
+ }
33290
+ function encodeDepositNativeData(input) {
33291
+ return encodeFunctionData({
33292
+ abi: ESCROW_DEPOSIT_ABI,
33293
+ functionName: "depositNative",
33294
+ args: [input.account]
33295
+ });
33296
+ }
33297
+ function encodeDepositTokenData(input) {
33298
+ return encodeFunctionData({
33299
+ abi: ESCROW_DEPOSIT_ABI,
33300
+ functionName: "depositToken",
33301
+ args: [input.account, input.token, input.amount]
33302
+ });
33303
+ }
33304
+ function buildDepositNativeRequest(config, input) {
33305
+ return {
33306
+ to: escrowContractAddress(config),
33307
+ data: encodeDepositNativeData({ account: input.account }),
33308
+ value: input.amount
33309
+ };
33310
+ }
33311
+ function buildDepositTokenRequest(config, input) {
33312
+ return {
33313
+ to: escrowContractAddress(config),
33314
+ data: encodeDepositTokenData(input)
33315
+ };
33316
+ }
33317
+
33318
+ // src/protocol/data-point-status.ts
33319
+ import { encodeFunctionData as encodeFunctionData2 } from "viem";
33320
+ var DataPointStatus = /* @__PURE__ */ ((DataPointStatus2) => {
33321
+ DataPointStatus2[DataPointStatus2["None"] = 0] = "None";
33322
+ DataPointStatus2[DataPointStatus2["Active"] = 1] = "Active";
33323
+ DataPointStatus2[DataPointStatus2["Inactive"] = 2] = "Inactive";
33324
+ DataPointStatus2[DataPointStatus2["Unavailable"] = 3] = "Unavailable";
33325
+ return DataPointStatus2;
33326
+ })(DataPointStatus || {});
33327
+ var DATA_REGISTRY_STATUS_ABI = [
33328
+ {
33329
+ type: "function",
33330
+ name: "setStatus",
33331
+ stateMutability: "nonpayable",
33332
+ inputs: [
33333
+ { name: "scope", type: "string" },
33334
+ { name: "newStatus", type: "uint8" }
33335
+ ],
33336
+ outputs: []
33337
+ }
33338
+ ];
33339
+ function dataRegistryContractAddress(config) {
33340
+ return config.contracts.dataRegistry;
33341
+ }
33342
+ function encodeSetDataPointStatusData(input) {
33343
+ return encodeFunctionData2({
33344
+ abi: DATA_REGISTRY_STATUS_ABI,
33345
+ functionName: "setStatus",
33346
+ args: [input.scope, input.status]
33347
+ });
33348
+ }
33349
+ function buildSetDataPointStatusRequest(config, input) {
33350
+ return {
33351
+ to: dataRegistryContractAddress(config),
33352
+ data: encodeSetDataPointStatusData(input)
33353
+ };
33354
+ }
33355
+ function buildMarkDataPointUnavailableRequest(config, input) {
33356
+ return buildSetDataPointStatusRequest(config, {
33357
+ scope: input.scope,
33358
+ status: 3 /* Unavailable */
33359
+ });
33360
+ }
33361
+
33362
+ // src/protocol/data-file.ts
33209
33363
  import { z } from "zod";
33364
+ var DataFileEnvelopeSchema = z.object({
33365
+ $schema: z.string().url().optional(),
33366
+ version: z.literal("1.0"),
33367
+ scope: z.string(),
33368
+ schemaId: z.string().optional(),
33369
+ collectedAt: z.string().datetime(),
33370
+ data: z.record(z.string(), z.unknown())
33371
+ });
33372
+ function createDataFileEnvelope(scope, collectedAt, data, schemaUrl, schemaId) {
33373
+ return {
33374
+ ...schemaUrl !== void 0 && { $schema: schemaUrl },
33375
+ ...schemaId !== void 0 && { schemaId },
33376
+ version: "1.0",
33377
+ scope,
33378
+ collectedAt,
33379
+ data
33380
+ };
33381
+ }
33382
+ var IngestResponseSchema = z.object({
33383
+ scope: z.string(),
33384
+ collectedAt: z.string().datetime(),
33385
+ status: z.enum(["stored", "syncing"])
33386
+ });
33387
+
33388
+ // src/protocol/personal-server-data.ts
33389
+ function personalServerDataReadPath(scope) {
33390
+ return `/v1/data/${encodeURIComponent(scope)}`;
33391
+ }
33392
+ async function buildPersonalServerDataReadRequest(params) {
33393
+ const path = personalServerDataReadPath(params.scope);
33394
+ const baseUrl = params.personalServerUrl.replace(/\/+$/, "");
33395
+ const audience = params.audience ?? baseUrl;
33396
+ const headers = new Headers(params.headers);
33397
+ headers.set(
33398
+ "Authorization",
33399
+ await buildWeb3SignedHeader({
33400
+ aud: audience,
33401
+ grantId: params.grantId,
33402
+ method: "GET",
33403
+ signMessage: params.signMessage,
33404
+ uri: path
33405
+ })
33406
+ );
33407
+ return new Request(`${baseUrl}${path}`, {
33408
+ headers,
33409
+ method: "GET"
33410
+ });
33411
+ }
33412
+ async function readPersonalServerData(params) {
33413
+ const fetchFn = params.fetch ?? globalThis.fetch;
33414
+ if (fetchFn === void 0) {
33415
+ throw new Error("No fetch implementation available");
33416
+ }
33417
+ const request = await buildPersonalServerDataReadRequest(params);
33418
+ const response = await fetchFn(request);
33419
+ if (!response.ok) {
33420
+ throw new Error(
33421
+ `Personal Server data read failed: ${response.status} ${response.statusText}`
33422
+ );
33423
+ }
33424
+ return DataFileEnvelopeSchema.parse(await response.json());
33425
+ }
33426
+
33427
+ // src/protocol/scopes.ts
33428
+ import { z as z2 } from "zod";
33210
33429
  var SEGMENT_RE = /^[a-z0-9][a-z0-9_]*$/;
33211
- var ScopeSchema = z.string().refine(
33430
+ var ScopeSchema = z2.string().refine(
33212
33431
  (scope) => {
33213
33432
  const parts = scope.split(".");
33214
33433
  return parts.length >= 2 && parts.length <= 3 && parts.every((part) => SEGMENT_RE.test(part));
@@ -33249,32 +33468,6 @@ function scopeCoveredByGrant(requestedScope, grantedScopes) {
33249
33468
  );
33250
33469
  }
33251
33470
 
33252
- // src/protocol/data-file.ts
33253
- import { z as z2 } from "zod";
33254
- var DataFileEnvelopeSchema = z2.object({
33255
- $schema: z2.string().url().optional(),
33256
- version: z2.literal("1.0"),
33257
- scope: z2.string(),
33258
- schemaId: z2.string().optional(),
33259
- collectedAt: z2.string().datetime(),
33260
- data: z2.record(z2.string(), z2.unknown())
33261
- });
33262
- function createDataFileEnvelope(scope, collectedAt, data, schemaUrl, schemaId) {
33263
- return {
33264
- ...schemaUrl !== void 0 && { $schema: schemaUrl },
33265
- ...schemaId !== void 0 && { schemaId },
33266
- version: "1.0",
33267
- scope,
33268
- collectedAt,
33269
- data
33270
- };
33271
- }
33272
- var IngestResponseSchema = z2.object({
33273
- scope: z2.string(),
33274
- collectedAt: z2.string().datetime(),
33275
- status: z2.enum(["stored", "syncing"])
33276
- });
33277
-
33278
33471
  // src/protocol/gateway.ts
33279
33472
  function createGatewayClient(baseUrl) {
33280
33473
  const base = baseUrl.replace(/\/+$/, "");
@@ -33282,16 +33475,6 @@ function createGatewayClient(baseUrl) {
33282
33475
  const envelope = await res.json();
33283
33476
  return envelope.data;
33284
33477
  }
33285
- function normalizeFileRecord(record) {
33286
- return {
33287
- fileId: record.fileId ?? record.id ?? "",
33288
- owner: record.owner ?? record.ownerAddress ?? "",
33289
- url: record.url,
33290
- schemaId: record.schemaId,
33291
- createdAt: record.createdAt ?? record.addedAt ?? "",
33292
- deletedAt: record.deletedAt ?? null
33293
- };
33294
- }
33295
33478
  function getMutationId(body, key) {
33296
33479
  const value = body[key] ?? body["id"];
33297
33480
  return typeof value === "string" ? value : void 0;
@@ -33341,31 +33524,33 @@ function createGatewayClient(baseUrl) {
33341
33524
  }
33342
33525
  return unwrapEnvelope(res);
33343
33526
  },
33344
- async getFile(fileId) {
33345
- const res = await fetch(`${base}/v1/files/${fileId}`);
33527
+ async getDataPoint(dataPointId) {
33528
+ const res = await fetch(`${base}/v1/data/${dataPointId}`);
33346
33529
  if (res.status === 404) return null;
33347
33530
  if (!res.ok) {
33348
33531
  throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
33349
33532
  }
33350
- return normalizeFileRecord(await unwrapEnvelope(res));
33533
+ return unwrapEnvelope(res);
33351
33534
  },
33352
- async listFilesSince(owner, cursor, options) {
33535
+ async listDataPointsByOwner(owner, cursor, options) {
33353
33536
  const params = new URLSearchParams({ user: owner });
33354
33537
  if (cursor !== null) {
33355
33538
  params.set("cursor", cursor);
33356
33539
  }
33357
- if (options?.includeDeleted) {
33358
- params.set("includeDeleted", "true");
33540
+ if (options?.since) {
33541
+ params.set("since", options.since);
33542
+ }
33543
+ if (options?.limit !== void 0) {
33544
+ params.set("limit", String(options.limit));
33359
33545
  }
33360
- const res = await fetch(`${base}/v1/files?${params.toString()}`);
33546
+ const res = await fetch(`${base}/v1/data?${params.toString()}`);
33361
33547
  if (!res.ok) {
33362
33548
  throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
33363
33549
  }
33364
33550
  const envelope = await res.json();
33365
- const { pagination } = envelope;
33366
- const nextCursor = pagination?.hasMore === false ? null : pagination?.nextCursor ?? envelope.data.cursor ?? null;
33551
+ const nextCursor = envelope.pagination?.hasMore === false ? null : envelope.pagination?.nextCursor ?? null;
33367
33552
  return {
33368
- files: envelope.data.files.map(normalizeFileRecord),
33553
+ dataPoints: envelope.data.dataPoints,
33369
33554
  cursor: nextCursor
33370
33555
  };
33371
33556
  },
@@ -33407,8 +33592,8 @@ function createGatewayClient(baseUrl) {
33407
33592
  alreadyRegistered: false
33408
33593
  };
33409
33594
  },
33410
- async registerFile(params) {
33411
- const res = await fetch(`${base}/v1/files`, {
33595
+ async registerBuilder(params) {
33596
+ const res = await fetch(`${base}/v1/builders`, {
33412
33597
  method: "POST",
33413
33598
  headers: {
33414
33599
  "Content-Type": "application/json",
@@ -33416,22 +33601,57 @@ function createGatewayClient(baseUrl) {
33416
33601
  },
33417
33602
  body: JSON.stringify({
33418
33603
  ownerAddress: params.ownerAddress,
33419
- url: params.url,
33420
- schemaId: params.schemaId
33604
+ granteeAddress: params.granteeAddress,
33605
+ publicKey: params.publicKey,
33606
+ appUrl: params.appUrl
33421
33607
  })
33422
33608
  });
33423
33609
  if (res.status === 409) {
33424
33610
  const body2 = await res.json().catch(() => ({}));
33425
33611
  return {
33426
- fileId: getMutationId(body2, "fileId")
33612
+ builderId: getMutationId(
33613
+ body2,
33614
+ "builderId"
33615
+ ),
33616
+ alreadyRegistered: true
33427
33617
  };
33428
33618
  }
33429
33619
  if (!res.ok) {
33430
33620
  throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
33431
33621
  }
33432
- const body = await res.json();
33622
+ const body = await res.json().catch(() => ({}));
33623
+ return {
33624
+ builderId: getMutationId(body, "builderId"),
33625
+ alreadyRegistered: false
33626
+ };
33627
+ },
33628
+ async registerDataPoint(params) {
33629
+ const res = await fetch(`${base}/v1/data`, {
33630
+ method: "POST",
33631
+ headers: {
33632
+ "Content-Type": "application/json",
33633
+ Authorization: `Web3Signed ${params.signature}`
33634
+ },
33635
+ body: JSON.stringify({
33636
+ ownerAddress: params.ownerAddress,
33637
+ scope: params.scope,
33638
+ dataHash: params.dataHash,
33639
+ metadataHash: params.metadataHash,
33640
+ expectedVersion: params.expectedVersion
33641
+ })
33642
+ });
33643
+ if (!res.ok) {
33644
+ const body2 = await res.json().catch(() => ({}));
33645
+ const detail = body2.error ?? res.statusText;
33646
+ throw new Error(`Gateway error: ${res.status} ${detail}`);
33647
+ }
33648
+ const body = await res.json().catch(() => ({}));
33433
33649
  return {
33434
- fileId: getMutationId(body, "fileId")
33650
+ dataPointId: getMutationId(
33651
+ body,
33652
+ "dataPointId"
33653
+ ),
33654
+ expectedVersion: body.expectedVersion
33435
33655
  };
33436
33656
  },
33437
33657
  async createGrant(params) {
@@ -33444,8 +33664,9 @@ function createGatewayClient(baseUrl) {
33444
33664
  body: JSON.stringify({
33445
33665
  grantorAddress: params.grantorAddress,
33446
33666
  granteeId: params.granteeId,
33447
- grant: params.grant,
33448
- fileIds: params.fileIds
33667
+ scopes: params.scopes,
33668
+ grantVersion: params.grantVersion,
33669
+ expiresAt: params.expiresAt
33449
33670
  })
33450
33671
  });
33451
33672
  if (res.status === 409) {
@@ -33470,7 +33691,8 @@ function createGatewayClient(baseUrl) {
33470
33691
  Authorization: `Web3Signed ${params.signature}`
33471
33692
  },
33472
33693
  body: JSON.stringify({
33473
- grantorAddress: params.grantorAddress
33694
+ grantorAddress: params.grantorAddress,
33695
+ grantVersion: params.grantVersion
33474
33696
  })
33475
33697
  });
33476
33698
  if (res.status === 409) return;
@@ -33478,21 +33700,62 @@ function createGatewayClient(baseUrl) {
33478
33700
  throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
33479
33701
  }
33480
33702
  },
33481
- async deleteFile(params) {
33482
- const res = await fetch(`${base}/v1/files/${params.fileId}`, {
33483
- method: "DELETE",
33703
+ async getEscrowBalance(account) {
33704
+ const res = await fetch(`${base}/v1/escrow/balance?account=${account}`);
33705
+ if (!res.ok) {
33706
+ throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
33707
+ }
33708
+ return await res.json();
33709
+ },
33710
+ async submitEscrowDeposit(params) {
33711
+ const res = await fetch(`${base}/v1/escrow/deposit`, {
33712
+ method: "POST",
33713
+ headers: { "Content-Type": "application/json" },
33714
+ body: JSON.stringify({ txHash: params.txHash })
33715
+ });
33716
+ if (res.status !== 200 && res.status !== 202) {
33717
+ throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
33718
+ }
33719
+ return await res.json();
33720
+ },
33721
+ async payForOperation(params) {
33722
+ const body = {
33723
+ payerAddress: params.payerAddress,
33724
+ opType: params.opType,
33725
+ opId: params.opId,
33726
+ asset: params.asset,
33727
+ amount: params.amount,
33728
+ paymentNonce: params.paymentNonce
33729
+ };
33730
+ if (params.accessRecord) {
33731
+ body["accessRecord"] = params.accessRecord;
33732
+ }
33733
+ const res = await fetch(`${base}/v1/escrow/pay`, {
33734
+ method: "POST",
33484
33735
  headers: {
33485
33736
  "Content-Type": "application/json",
33486
33737
  Authorization: `Web3Signed ${params.signature}`
33487
33738
  },
33488
- body: JSON.stringify({
33489
- ownerAddress: params.ownerAddress
33490
- })
33739
+ body: JSON.stringify(body)
33491
33740
  });
33492
- if (res.status === 409) return;
33493
33741
  if (!res.ok) {
33494
33742
  throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
33495
33743
  }
33744
+ return await res.json();
33745
+ },
33746
+ async settle(params) {
33747
+ const res = await fetch(`${base}/v1/settle`, {
33748
+ method: "POST",
33749
+ headers: { "Content-Type": "application/json" },
33750
+ // The gateway accepts an empty body; only `limit` is recognised.
33751
+ // Always send a JSON body so the gateway's req.body shape parse
33752
+ // doesn't have to deal with an undefined.
33753
+ body: JSON.stringify(params ?? {})
33754
+ });
33755
+ if (!res.ok) {
33756
+ throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
33757
+ }
33758
+ return await res.json();
33496
33759
  }
33497
33760
  };
33498
33761
  }
@@ -33516,7 +33779,7 @@ function genericPaymentDomain(chainId, escrowContract) {
33516
33779
  verifyingContract: escrowContract
33517
33780
  };
33518
33781
  }
33519
- var ESCROW_DEPOSIT_ABI = [
33782
+ var ESCROW_DEPOSIT_ABI2 = [
33520
33783
  {
33521
33784
  type: "function",
33522
33785
  name: "depositNative",
@@ -33673,6 +33936,7 @@ async function parsePSError(response) {
33673
33936
  }
33674
33937
  export {
33675
33938
  ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT,
33939
+ ADD_DATA_TYPES,
33676
33940
  AccountPersonalServerLiteOwnerBindingError,
33677
33941
  AccountPersonalServerRegistrationError,
33678
33942
  BUILDER_REGISTRATION_TYPES,
@@ -33682,13 +33946,14 @@ export {
33682
33946
  CallbackStorage,
33683
33947
  ContractFactory,
33684
33948
  ContractNotFoundError,
33949
+ DATA_REGISTRY_STATUS_ABI,
33685
33950
  DataFileEnvelopeSchema,
33951
+ DataPointStatus,
33686
33952
  DropboxStorage,
33687
33953
  ECIESError,
33688
- ESCROW_DEPOSIT_ABI,
33954
+ ESCROW_DEPOSIT_ABI2 as ESCROW_DEPOSIT_ABI,
33689
33955
  ExpiredTokenError,
33690
- FILE_DELETION_TYPES,
33691
- FILE_REGISTRATION_TYPES,
33956
+ FEE_REGISTRY_ABI,
33692
33957
  GENERIC_PAYMENT_TYPES,
33693
33958
  GRANT_REGISTRATION_TYPES,
33694
33959
  GRANT_REVOCATION_TYPES,
@@ -33701,6 +33966,7 @@ export {
33701
33966
  MASTER_KEY_MESSAGE,
33702
33967
  MissingAuthError,
33703
33968
  NATIVE_ASSET_ADDRESS,
33969
+ NATIVE_VANA_ASSET,
33704
33970
  NetworkError,
33705
33971
  NodeECIESUint8Provider as NodeECIESProvider,
33706
33972
  NodePlatformAdapter,
@@ -33718,6 +33984,8 @@ export {
33718
33984
  PersonalServerError,
33719
33985
  PinataStorage,
33720
33986
  R2Storage,
33987
+ RECORD_DATA_ACCESS_TYPES,
33988
+ REGISTRATION_KIND_FOR_OP,
33721
33989
  ReadOnlyError,
33722
33990
  RelayerError,
33723
33991
  SERVER_REGISTRATION_TYPES,
@@ -33732,10 +34000,15 @@ export {
33732
34000
  VanaError,
33733
34001
  VanaStorage,
33734
34002
  assertValidPkceVerifier,
34003
+ buildDepositNativeRequest,
34004
+ buildDepositTokenRequest,
34005
+ buildMarkDataPointUnavailableRequest,
34006
+ buildPersonalServerDataReadRequest,
33735
34007
  buildPersonalServerLiteOwnerBindingMessage,
33736
34008
  buildPersonalServerLiteOwnerBindingSignature,
33737
34009
  buildPersonalServerRegistrationSignature,
33738
34010
  buildPersonalServerRegistrationTypedData,
34011
+ buildSetDataPointStatusRequest,
33739
34012
  buildWeb3SignedHeader,
33740
34013
  builderRegistrationDomain,
33741
34014
  chains,
@@ -33754,14 +34027,19 @@ export {
33754
34027
  createVanaStorageProvider,
33755
34028
  createViemPersonalServerLiteOwnerBindingSigner,
33756
34029
  createViemPersonalServerRegistrationSigner,
34030
+ dataRegistryContractAddress,
34031
+ dataRegistryDomain,
33757
34032
  decryptWithPassword,
33758
34033
  deriveMasterKey,
33759
34034
  deriveScopeKey,
33760
34035
  deserializeECIES,
33761
34036
  detectPlatform,
34037
+ encodeDepositNativeData,
34038
+ encodeDepositTokenData,
34039
+ encodeSetDataPointStatusData,
33762
34040
  encryptWithPassword,
33763
- fileDeletionDomain,
33764
- fileRegistrationDomain,
34041
+ escrowContractAddress,
34042
+ escrowPaymentDomain,
33765
34043
  generatePkceVerifier,
33766
34044
  genericPaymentDomain,
33767
34045
  getAbi,
@@ -33770,6 +34048,8 @@ export {
33770
34048
  getContractAddress,
33771
34049
  getContractController,
33772
34050
  getContractInfo,
34051
+ getFee,
34052
+ getOpFee,
33773
34053
  getPlatformCapabilities,
33774
34054
  getServiceEndpoints,
33775
34055
  grantRegistrationDomain,
@@ -33781,11 +34061,12 @@ export {
33781
34061
  moksha,
33782
34062
  mokshaServices,
33783
34063
  mokshaTestnet2 as mokshaTestnet,
33784
- parseGrantRegistrationPayload,
33785
34064
  parsePSError,
33786
34065
  parseScope,
33787
34066
  parseWeb3SignedHeader,
34067
+ personalServerDataReadPath,
33788
34068
  personalServerRegistrationDomain,
34069
+ readPersonalServerData,
33789
34070
  recoverServerOwner,
33790
34071
  registerPersonalServerSignature,
33791
34072
  scopeCoveredByGrant,