@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
@@ -31940,6 +31940,7 @@ async function verifyWeb3Signed(params) {
31940
31940
  // src/protocol/eip712.ts
31941
31941
  var DOMAIN_NAME = "Vana Data Portability";
31942
31942
  var DOMAIN_VERSION = "1";
31943
+ var NATIVE_VANA_ASSET = "0x0000000000000000000000000000000000000000";
31943
31944
  function buildDomain(chainId, verifyingContract) {
31944
31945
  return {
31945
31946
  name: DOMAIN_NAME,
@@ -31948,13 +31949,7 @@ function buildDomain(chainId, verifyingContract) {
31948
31949
  verifyingContract
31949
31950
  };
31950
31951
  }
31951
- function fileRegistrationDomain(config) {
31952
- return buildDomain(
31953
- config.chainId,
31954
- config.contracts.dataRegistry
31955
- );
31956
- }
31957
- function fileDeletionDomain(config) {
31952
+ function dataRegistryDomain(config) {
31958
31953
  return buildDomain(
31959
31954
  config.chainId,
31960
31955
  config.contracts.dataRegistry
@@ -31984,31 +31979,26 @@ function builderRegistrationDomain(config) {
31984
31979
  config.contracts.dataPortabilityGrantees
31985
31980
  );
31986
31981
  }
31987
- var FILE_REGISTRATION_TYPES = {
31988
- FileRegistration: [
31989
- { name: "ownerAddress", type: "address" },
31990
- { name: "url", type: "string" },
31991
- { name: "schemaId", type: "bytes32" }
31992
- ]
31993
- };
31994
- var FILE_DELETION_TYPES = {
31995
- FileDeletion: [
31996
- { name: "ownerAddress", type: "address" },
31997
- { name: "fileId", type: "bytes32" }
31998
- ]
31999
- };
31982
+ function escrowPaymentDomain(config) {
31983
+ return buildDomain(
31984
+ config.chainId,
31985
+ config.contracts.dataPortabilityEscrow
31986
+ );
31987
+ }
32000
31988
  var GRANT_REGISTRATION_TYPES = {
32001
31989
  GrantRegistration: [
32002
31990
  { name: "grantorAddress", type: "address" },
32003
31991
  { name: "granteeId", type: "bytes32" },
32004
- { name: "grant", type: "string" },
32005
- { name: "fileIds", type: "uint256[]" }
31992
+ { name: "scopes", type: "string[]" },
31993
+ { name: "grantVersion", type: "uint256" },
31994
+ { name: "expiresAt", type: "uint256" }
32006
31995
  ]
32007
31996
  };
32008
31997
  var GRANT_REVOCATION_TYPES = {
32009
31998
  GrantRevocation: [
32010
31999
  { name: "grantorAddress", type: "address" },
32011
- { name: "grantId", type: "bytes32" }
32000
+ { name: "grantId", type: "bytes32" },
32001
+ { name: "grantVersion", type: "uint256" }
32012
32002
  ]
32013
32003
  };
32014
32004
  var SERVER_REGISTRATION_TYPES = {
@@ -32027,6 +32017,24 @@ var BUILDER_REGISTRATION_TYPES = {
32027
32017
  { name: "appUrl", type: "string" }
32028
32018
  ]
32029
32019
  };
32020
+ var ADD_DATA_TYPES = {
32021
+ AddData: [
32022
+ { name: "ownerAddress", type: "address" },
32023
+ { name: "scope", type: "string" },
32024
+ { name: "dataHash", type: "bytes32" },
32025
+ { name: "metadataHash", type: "bytes32" },
32026
+ { name: "expectedVersion", type: "uint256" }
32027
+ ]
32028
+ };
32029
+ var RECORD_DATA_ACCESS_TYPES = {
32030
+ RecordDataAccess: [
32031
+ { name: "ownerAddress", type: "address" },
32032
+ { name: "scope", type: "string" },
32033
+ { name: "version", type: "uint256" },
32034
+ { name: "accessor", type: "address" },
32035
+ { name: "recordId", type: "bytes32" }
32036
+ ]
32037
+ };
32030
32038
 
32031
32039
  // src/protocol/personal-server-registration.ts
32032
32040
  import {
@@ -32478,67 +32486,34 @@ function isDataPortabilityGatewayConfig(value) {
32478
32486
  return false;
32479
32487
  }
32480
32488
  const c = contracts;
32481
- return isHexString(c["dataRegistry"]) && isHexString(c["dataPortabilityPermissions"]) && isHexString(c["dataPortabilityServer"]) && isHexString(c["dataPortabilityGrantees"]);
32482
- }
32483
- function parseGrantRegistrationPayload(grant) {
32484
- let parsed;
32485
- try {
32486
- parsed = JSON.parse(grant);
32487
- } catch {
32488
- return null;
32489
- }
32490
- if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
32491
- return null;
32492
- }
32493
- const value = parsed;
32494
- if (!Array.isArray(value["scopes"]) || value["scopes"].length === 0) {
32495
- return null;
32496
- }
32497
- if (!value["scopes"].every((scope) => typeof scope === "string")) {
32498
- return null;
32499
- }
32500
- if (typeof value["expiresAt"] !== "number" || !Number.isFinite(value["expiresAt"])) {
32501
- return null;
32502
- }
32503
- if (value["user"] !== void 0 && !isHexString(value["user"])) {
32504
- return null;
32505
- }
32506
- if (value["builder"] !== void 0 && !isHexString(value["builder"])) {
32507
- return null;
32508
- }
32509
- if (value["nonce"] !== void 0 && (typeof value["nonce"] !== "number" || !Number.isFinite(value["nonce"]))) {
32510
- return null;
32511
- }
32512
- return {
32513
- user: value["user"],
32514
- builder: value["builder"],
32515
- scopes: value["scopes"],
32516
- expiresAt: value["expiresAt"],
32517
- nonce: value["nonce"]
32518
- };
32489
+ return isHexString(c["dataRegistry"]) && isHexString(c["dataPortabilityPermissions"]) && isHexString(c["dataPortabilityServer"]) && isHexString(c["dataPortabilityGrantees"]) && isHexString(c["dataPortabilityEscrow"]) && isHexString(c["feeRegistry"]);
32519
32490
  }
32520
- function parseFileIds(fileIds) {
32491
+ function toUint256(value) {
32521
32492
  try {
32522
- const values = (fileIds ?? []).map((fileId) => BigInt(fileId));
32523
- return {
32524
- values,
32525
- display: values.map((fileId) => fileId.toString())
32526
- };
32493
+ if (typeof value === "number" && !Number.isSafeInteger(value)) {
32494
+ return null;
32495
+ }
32496
+ const big = typeof value === "bigint" ? value : BigInt(value);
32497
+ if (big < 0n) return null;
32498
+ return big;
32527
32499
  } catch {
32528
32500
  return null;
32529
32501
  }
32530
32502
  }
32531
32503
  async function verifyGrantRegistration(input) {
32532
- const payload = parseGrantRegistrationPayload(input.grant);
32533
- if (!payload) {
32534
- return {
32535
- valid: false,
32536
- error: "Grant must be JSON with scopes and expiresAt"
32537
- };
32504
+ if (!Array.isArray(input.scopes) || input.scopes.length === 0) {
32505
+ return { valid: false, error: "scopes must be a non-empty array" };
32506
+ }
32507
+ if (!input.scopes.every((scope) => typeof scope === "string")) {
32508
+ return { valid: false, error: "scopes must contain only strings" };
32538
32509
  }
32539
- const fileIds = parseFileIds(input.fileIds);
32540
- if (!fileIds) {
32541
- return { valid: false, error: "fileIds must contain integer values" };
32510
+ const grantVersion = toUint256(input.grantVersion);
32511
+ if (grantVersion === null || grantVersion < 1n) {
32512
+ return { valid: false, error: "grantVersion must be a uint256 >= 1" };
32513
+ }
32514
+ const expiresAt = toUint256(input.expiresAt);
32515
+ if (expiresAt === null) {
32516
+ return { valid: false, error: "expiresAt must be a non-negative uint256" };
32542
32517
  }
32543
32518
  let valid;
32544
32519
  try {
@@ -32550,8 +32525,9 @@ async function verifyGrantRegistration(input) {
32550
32525
  message: {
32551
32526
  grantorAddress: input.grantorAddress,
32552
32527
  granteeId: input.granteeId,
32553
- grant: input.grant,
32554
- fileIds: fileIds.values
32528
+ scopes: input.scopes,
32529
+ grantVersion,
32530
+ expiresAt
32555
32531
  },
32556
32532
  signature: input.signature
32557
32533
  });
@@ -32562,26 +32538,269 @@ async function verifyGrantRegistration(input) {
32562
32538
  return { valid: false, error: "Grant signature does not match grantor" };
32563
32539
  }
32564
32540
  const nowSeconds = input.nowSeconds ?? Math.floor(Date.now() / 1e3);
32565
- if (payload.expiresAt > 0 && payload.expiresAt < nowSeconds) {
32541
+ if (expiresAt > 0n && expiresAt < BigInt(nowSeconds)) {
32566
32542
  return { valid: false, error: "Grant has expired" };
32567
32543
  }
32568
- if (payload.user !== void 0 && payload.user.toLowerCase() !== input.grantorAddress.toLowerCase()) {
32569
- return { valid: false, error: "Grant user does not match grantorAddress" };
32570
- }
32571
32544
  return {
32572
32545
  valid: true,
32573
32546
  grantorAddress: input.grantorAddress,
32574
32547
  granteeId: input.granteeId,
32575
- grant: input.grant,
32576
- payload,
32577
- fileIds: fileIds.display
32548
+ scopes: input.scopes,
32549
+ grantVersion: grantVersion.toString(),
32550
+ expiresAt: expiresAt.toString()
32578
32551
  };
32579
32552
  }
32580
32553
 
32581
- // src/protocol/scopes.ts
32554
+ // src/protocol/fee-registry.ts
32555
+ import { parseAbi } from "viem";
32556
+ var FEE_REGISTRY_ABI = parseAbi([
32557
+ "struct Fee { uint256 amount; address asset; address payee; bool enabled; }",
32558
+ "function fees(bytes32 operation) view returns (Fee)",
32559
+ "function operationKey(string name) pure returns (bytes32)"
32560
+ ]);
32561
+ var REGISTRATION_KIND_FOR_OP = {
32562
+ grant: "grant_registration",
32563
+ data: "data_registration",
32564
+ server: "server_registration",
32565
+ builder: "builder_registration"
32566
+ };
32567
+ function operationNameFor(kind, opts) {
32568
+ switch (kind) {
32569
+ case "grant_registration":
32570
+ return opts?.grantRegistrationOpName ?? "grant_registration";
32571
+ case "data_access":
32572
+ return opts?.dataAccessOpName ?? "data_access";
32573
+ case "data_registration":
32574
+ return opts?.dataRegistrationOpName ?? "data_registration";
32575
+ case "server_registration":
32576
+ return opts?.serverRegistrationOpName ?? "server_registration";
32577
+ case "builder_registration":
32578
+ return opts?.builderRegistrationOpName ?? "builder_registration";
32579
+ }
32580
+ }
32581
+ var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
32582
+ async function getFee(client, config, kind, opts) {
32583
+ const address = config.contracts.feeRegistry;
32584
+ const opName = operationNameFor(kind, opts);
32585
+ const opKey = await client.readContract({
32586
+ address,
32587
+ abi: FEE_REGISTRY_ABI,
32588
+ functionName: "operationKey",
32589
+ args: [opName]
32590
+ });
32591
+ const fee = await client.readContract({
32592
+ address,
32593
+ abi: FEE_REGISTRY_ABI,
32594
+ functionName: "fees",
32595
+ args: [opKey]
32596
+ });
32597
+ if (fee.enabled && fee.payee === ZERO_ADDRESS) {
32598
+ throw new Error(
32599
+ `FeeRegistry: enabled operation "${opName}" has zero-address payee \u2014 contract pre-flight rejects payouts to 0x0`
32600
+ );
32601
+ }
32602
+ return fee;
32603
+ }
32604
+ async function getOpFee(client, config, opType, opts) {
32605
+ const registrationKind = REGISTRATION_KIND_FOR_OP[opType];
32606
+ if (!registrationKind) {
32607
+ throw new Error(
32608
+ `getOpFee: unknown opType "${opType}" \u2014 supported types are ${Object.keys(REGISTRATION_KIND_FOR_OP).join(", ")}`
32609
+ );
32610
+ }
32611
+ const includeDataAccess = opType === "grant";
32612
+ const [registration, dataAccess] = await Promise.all([
32613
+ getFee(client, config, registrationKind, opts),
32614
+ includeDataAccess ? getFee(client, config, "data_access", opts) : Promise.resolve({
32615
+ amount: 0n,
32616
+ asset: ZERO_ADDRESS,
32617
+ payee: ZERO_ADDRESS,
32618
+ enabled: false
32619
+ })
32620
+ ]);
32621
+ if (registration.enabled && dataAccess.enabled && registration.asset.toLowerCase() !== dataAccess.asset.toLowerCase()) {
32622
+ throw new Error(
32623
+ `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.`
32624
+ );
32625
+ }
32626
+ const asset = registration.enabled ? registration.asset : dataAccess.enabled ? dataAccess.asset : ZERO_ADDRESS;
32627
+ return {
32628
+ asset,
32629
+ registrationFee: registration.enabled ? registration.amount : 0n,
32630
+ dataAccessFee: dataAccess.enabled ? dataAccess.amount : 0n,
32631
+ registrationEnabled: registration.enabled,
32632
+ dataAccessEnabled: dataAccess.enabled,
32633
+ registrationPayee: registration.enabled ? registration.payee : ZERO_ADDRESS,
32634
+ dataAccessPayee: dataAccess.enabled ? dataAccess.payee : ZERO_ADDRESS
32635
+ };
32636
+ }
32637
+
32638
+ // src/protocol/escrow-deposit.ts
32639
+ import { encodeFunctionData } from "viem";
32640
+ var ESCROW_DEPOSIT_ABI = [
32641
+ {
32642
+ type: "function",
32643
+ name: "depositNative",
32644
+ stateMutability: "payable",
32645
+ inputs: [{ name: "account", type: "address" }],
32646
+ outputs: []
32647
+ },
32648
+ {
32649
+ type: "function",
32650
+ name: "depositToken",
32651
+ stateMutability: "nonpayable",
32652
+ inputs: [
32653
+ { name: "account", type: "address" },
32654
+ { name: "token", type: "address" },
32655
+ { name: "amount", type: "uint256" }
32656
+ ],
32657
+ outputs: []
32658
+ }
32659
+ ];
32660
+ function escrowContractAddress(config) {
32661
+ return config.contracts.dataPortabilityEscrow;
32662
+ }
32663
+ function encodeDepositNativeData(input) {
32664
+ return encodeFunctionData({
32665
+ abi: ESCROW_DEPOSIT_ABI,
32666
+ functionName: "depositNative",
32667
+ args: [input.account]
32668
+ });
32669
+ }
32670
+ function encodeDepositTokenData(input) {
32671
+ return encodeFunctionData({
32672
+ abi: ESCROW_DEPOSIT_ABI,
32673
+ functionName: "depositToken",
32674
+ args: [input.account, input.token, input.amount]
32675
+ });
32676
+ }
32677
+ function buildDepositNativeRequest(config, input) {
32678
+ return {
32679
+ to: escrowContractAddress(config),
32680
+ data: encodeDepositNativeData({ account: input.account }),
32681
+ value: input.amount
32682
+ };
32683
+ }
32684
+ function buildDepositTokenRequest(config, input) {
32685
+ return {
32686
+ to: escrowContractAddress(config),
32687
+ data: encodeDepositTokenData(input)
32688
+ };
32689
+ }
32690
+
32691
+ // src/protocol/data-point-status.ts
32692
+ import { encodeFunctionData as encodeFunctionData2 } from "viem";
32693
+ var DataPointStatus = /* @__PURE__ */ ((DataPointStatus2) => {
32694
+ DataPointStatus2[DataPointStatus2["None"] = 0] = "None";
32695
+ DataPointStatus2[DataPointStatus2["Active"] = 1] = "Active";
32696
+ DataPointStatus2[DataPointStatus2["Inactive"] = 2] = "Inactive";
32697
+ DataPointStatus2[DataPointStatus2["Unavailable"] = 3] = "Unavailable";
32698
+ return DataPointStatus2;
32699
+ })(DataPointStatus || {});
32700
+ var DATA_REGISTRY_STATUS_ABI = [
32701
+ {
32702
+ type: "function",
32703
+ name: "setStatus",
32704
+ stateMutability: "nonpayable",
32705
+ inputs: [
32706
+ { name: "scope", type: "string" },
32707
+ { name: "newStatus", type: "uint8" }
32708
+ ],
32709
+ outputs: []
32710
+ }
32711
+ ];
32712
+ function dataRegistryContractAddress(config) {
32713
+ return config.contracts.dataRegistry;
32714
+ }
32715
+ function encodeSetDataPointStatusData(input) {
32716
+ return encodeFunctionData2({
32717
+ abi: DATA_REGISTRY_STATUS_ABI,
32718
+ functionName: "setStatus",
32719
+ args: [input.scope, input.status]
32720
+ });
32721
+ }
32722
+ function buildSetDataPointStatusRequest(config, input) {
32723
+ return {
32724
+ to: dataRegistryContractAddress(config),
32725
+ data: encodeSetDataPointStatusData(input)
32726
+ };
32727
+ }
32728
+ function buildMarkDataPointUnavailableRequest(config, input) {
32729
+ return buildSetDataPointStatusRequest(config, {
32730
+ scope: input.scope,
32731
+ status: 3 /* Unavailable */
32732
+ });
32733
+ }
32734
+
32735
+ // src/protocol/data-file.ts
32582
32736
  import { z } from "zod";
32737
+ var DataFileEnvelopeSchema = z.object({
32738
+ $schema: z.string().url().optional(),
32739
+ version: z.literal("1.0"),
32740
+ scope: z.string(),
32741
+ schemaId: z.string().optional(),
32742
+ collectedAt: z.string().datetime(),
32743
+ data: z.record(z.string(), z.unknown())
32744
+ });
32745
+ function createDataFileEnvelope(scope, collectedAt, data, schemaUrl, schemaId) {
32746
+ return {
32747
+ ...schemaUrl !== void 0 && { $schema: schemaUrl },
32748
+ ...schemaId !== void 0 && { schemaId },
32749
+ version: "1.0",
32750
+ scope,
32751
+ collectedAt,
32752
+ data
32753
+ };
32754
+ }
32755
+ var IngestResponseSchema = z.object({
32756
+ scope: z.string(),
32757
+ collectedAt: z.string().datetime(),
32758
+ status: z.enum(["stored", "syncing"])
32759
+ });
32760
+
32761
+ // src/protocol/personal-server-data.ts
32762
+ function personalServerDataReadPath(scope) {
32763
+ return `/v1/data/${encodeURIComponent(scope)}`;
32764
+ }
32765
+ async function buildPersonalServerDataReadRequest(params) {
32766
+ const path = personalServerDataReadPath(params.scope);
32767
+ const baseUrl = params.personalServerUrl.replace(/\/+$/, "");
32768
+ const audience = params.audience ?? baseUrl;
32769
+ const headers = new Headers(params.headers);
32770
+ headers.set(
32771
+ "Authorization",
32772
+ await buildWeb3SignedHeader({
32773
+ aud: audience,
32774
+ grantId: params.grantId,
32775
+ method: "GET",
32776
+ signMessage: params.signMessage,
32777
+ uri: path
32778
+ })
32779
+ );
32780
+ return new Request(`${baseUrl}${path}`, {
32781
+ headers,
32782
+ method: "GET"
32783
+ });
32784
+ }
32785
+ async function readPersonalServerData(params) {
32786
+ const fetchFn = params.fetch ?? globalThis.fetch;
32787
+ if (fetchFn === void 0) {
32788
+ throw new Error("No fetch implementation available");
32789
+ }
32790
+ const request = await buildPersonalServerDataReadRequest(params);
32791
+ const response = await fetchFn(request);
32792
+ if (!response.ok) {
32793
+ throw new Error(
32794
+ `Personal Server data read failed: ${response.status} ${response.statusText}`
32795
+ );
32796
+ }
32797
+ return DataFileEnvelopeSchema.parse(await response.json());
32798
+ }
32799
+
32800
+ // src/protocol/scopes.ts
32801
+ import { z as z2 } from "zod";
32583
32802
  var SEGMENT_RE = /^[a-z0-9][a-z0-9_]*$/;
32584
- var ScopeSchema = z.string().refine(
32803
+ var ScopeSchema = z2.string().refine(
32585
32804
  (scope) => {
32586
32805
  const parts = scope.split(".");
32587
32806
  return parts.length >= 2 && parts.length <= 3 && parts.every((part) => SEGMENT_RE.test(part));
@@ -32622,32 +32841,6 @@ function scopeCoveredByGrant(requestedScope, grantedScopes) {
32622
32841
  );
32623
32842
  }
32624
32843
 
32625
- // src/protocol/data-file.ts
32626
- import { z as z2 } from "zod";
32627
- var DataFileEnvelopeSchema = z2.object({
32628
- $schema: z2.string().url().optional(),
32629
- version: z2.literal("1.0"),
32630
- scope: z2.string(),
32631
- schemaId: z2.string().optional(),
32632
- collectedAt: z2.string().datetime(),
32633
- data: z2.record(z2.string(), z2.unknown())
32634
- });
32635
- function createDataFileEnvelope(scope, collectedAt, data, schemaUrl, schemaId) {
32636
- return {
32637
- ...schemaUrl !== void 0 && { $schema: schemaUrl },
32638
- ...schemaId !== void 0 && { schemaId },
32639
- version: "1.0",
32640
- scope,
32641
- collectedAt,
32642
- data
32643
- };
32644
- }
32645
- var IngestResponseSchema = z2.object({
32646
- scope: z2.string(),
32647
- collectedAt: z2.string().datetime(),
32648
- status: z2.enum(["stored", "syncing"])
32649
- });
32650
-
32651
32844
  // src/protocol/gateway.ts
32652
32845
  function createGatewayClient(baseUrl) {
32653
32846
  const base = baseUrl.replace(/\/+$/, "");
@@ -32655,16 +32848,6 @@ function createGatewayClient(baseUrl) {
32655
32848
  const envelope = await res.json();
32656
32849
  return envelope.data;
32657
32850
  }
32658
- function normalizeFileRecord(record) {
32659
- return {
32660
- fileId: record.fileId ?? record.id ?? "",
32661
- owner: record.owner ?? record.ownerAddress ?? "",
32662
- url: record.url,
32663
- schemaId: record.schemaId,
32664
- createdAt: record.createdAt ?? record.addedAt ?? "",
32665
- deletedAt: record.deletedAt ?? null
32666
- };
32667
- }
32668
32851
  function getMutationId(body, key) {
32669
32852
  const value = body[key] ?? body["id"];
32670
32853
  return typeof value === "string" ? value : void 0;
@@ -32714,31 +32897,33 @@ function createGatewayClient(baseUrl) {
32714
32897
  }
32715
32898
  return unwrapEnvelope(res);
32716
32899
  },
32717
- async getFile(fileId) {
32718
- const res = await fetch(`${base}/v1/files/${fileId}`);
32900
+ async getDataPoint(dataPointId) {
32901
+ const res = await fetch(`${base}/v1/data/${dataPointId}`);
32719
32902
  if (res.status === 404) return null;
32720
32903
  if (!res.ok) {
32721
32904
  throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
32722
32905
  }
32723
- return normalizeFileRecord(await unwrapEnvelope(res));
32906
+ return unwrapEnvelope(res);
32724
32907
  },
32725
- async listFilesSince(owner, cursor, options) {
32908
+ async listDataPointsByOwner(owner, cursor, options) {
32726
32909
  const params = new URLSearchParams({ user: owner });
32727
32910
  if (cursor !== null) {
32728
32911
  params.set("cursor", cursor);
32729
32912
  }
32730
- if (options?.includeDeleted) {
32731
- params.set("includeDeleted", "true");
32913
+ if (options?.since) {
32914
+ params.set("since", options.since);
32915
+ }
32916
+ if (options?.limit !== void 0) {
32917
+ params.set("limit", String(options.limit));
32732
32918
  }
32733
- const res = await fetch(`${base}/v1/files?${params.toString()}`);
32919
+ const res = await fetch(`${base}/v1/data?${params.toString()}`);
32734
32920
  if (!res.ok) {
32735
32921
  throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
32736
32922
  }
32737
32923
  const envelope = await res.json();
32738
- const { pagination } = envelope;
32739
- const nextCursor = pagination?.hasMore === false ? null : pagination?.nextCursor ?? envelope.data.cursor ?? null;
32924
+ const nextCursor = envelope.pagination?.hasMore === false ? null : envelope.pagination?.nextCursor ?? null;
32740
32925
  return {
32741
- files: envelope.data.files.map(normalizeFileRecord),
32926
+ dataPoints: envelope.data.dataPoints,
32742
32927
  cursor: nextCursor
32743
32928
  };
32744
32929
  },
@@ -32780,8 +32965,8 @@ function createGatewayClient(baseUrl) {
32780
32965
  alreadyRegistered: false
32781
32966
  };
32782
32967
  },
32783
- async registerFile(params) {
32784
- const res = await fetch(`${base}/v1/files`, {
32968
+ async registerBuilder(params) {
32969
+ const res = await fetch(`${base}/v1/builders`, {
32785
32970
  method: "POST",
32786
32971
  headers: {
32787
32972
  "Content-Type": "application/json",
@@ -32789,22 +32974,57 @@ function createGatewayClient(baseUrl) {
32789
32974
  },
32790
32975
  body: JSON.stringify({
32791
32976
  ownerAddress: params.ownerAddress,
32792
- url: params.url,
32793
- schemaId: params.schemaId
32977
+ granteeAddress: params.granteeAddress,
32978
+ publicKey: params.publicKey,
32979
+ appUrl: params.appUrl
32794
32980
  })
32795
32981
  });
32796
32982
  if (res.status === 409) {
32797
32983
  const body2 = await res.json().catch(() => ({}));
32798
32984
  return {
32799
- fileId: getMutationId(body2, "fileId")
32985
+ builderId: getMutationId(
32986
+ body2,
32987
+ "builderId"
32988
+ ),
32989
+ alreadyRegistered: true
32800
32990
  };
32801
32991
  }
32802
32992
  if (!res.ok) {
32803
32993
  throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
32804
32994
  }
32805
- const body = await res.json();
32995
+ const body = await res.json().catch(() => ({}));
32996
+ return {
32997
+ builderId: getMutationId(body, "builderId"),
32998
+ alreadyRegistered: false
32999
+ };
33000
+ },
33001
+ async registerDataPoint(params) {
33002
+ const res = await fetch(`${base}/v1/data`, {
33003
+ method: "POST",
33004
+ headers: {
33005
+ "Content-Type": "application/json",
33006
+ Authorization: `Web3Signed ${params.signature}`
33007
+ },
33008
+ body: JSON.stringify({
33009
+ ownerAddress: params.ownerAddress,
33010
+ scope: params.scope,
33011
+ dataHash: params.dataHash,
33012
+ metadataHash: params.metadataHash,
33013
+ expectedVersion: params.expectedVersion
33014
+ })
33015
+ });
33016
+ if (!res.ok) {
33017
+ const body2 = await res.json().catch(() => ({}));
33018
+ const detail = body2.error ?? res.statusText;
33019
+ throw new Error(`Gateway error: ${res.status} ${detail}`);
33020
+ }
33021
+ const body = await res.json().catch(() => ({}));
32806
33022
  return {
32807
- fileId: getMutationId(body, "fileId")
33023
+ dataPointId: getMutationId(
33024
+ body,
33025
+ "dataPointId"
33026
+ ),
33027
+ expectedVersion: body.expectedVersion
32808
33028
  };
32809
33029
  },
32810
33030
  async createGrant(params) {
@@ -32817,8 +33037,9 @@ function createGatewayClient(baseUrl) {
32817
33037
  body: JSON.stringify({
32818
33038
  grantorAddress: params.grantorAddress,
32819
33039
  granteeId: params.granteeId,
32820
- grant: params.grant,
32821
- fileIds: params.fileIds
33040
+ scopes: params.scopes,
33041
+ grantVersion: params.grantVersion,
33042
+ expiresAt: params.expiresAt
32822
33043
  })
32823
33044
  });
32824
33045
  if (res.status === 409) {
@@ -32843,7 +33064,8 @@ function createGatewayClient(baseUrl) {
32843
33064
  Authorization: `Web3Signed ${params.signature}`
32844
33065
  },
32845
33066
  body: JSON.stringify({
32846
- grantorAddress: params.grantorAddress
33067
+ grantorAddress: params.grantorAddress,
33068
+ grantVersion: params.grantVersion
32847
33069
  })
32848
33070
  });
32849
33071
  if (res.status === 409) return;
@@ -32851,21 +33073,62 @@ function createGatewayClient(baseUrl) {
32851
33073
  throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
32852
33074
  }
32853
33075
  },
32854
- async deleteFile(params) {
32855
- const res = await fetch(`${base}/v1/files/${params.fileId}`, {
32856
- method: "DELETE",
33076
+ async getEscrowBalance(account) {
33077
+ const res = await fetch(`${base}/v1/escrow/balance?account=${account}`);
33078
+ if (!res.ok) {
33079
+ throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
33080
+ }
33081
+ return await res.json();
33082
+ },
33083
+ async submitEscrowDeposit(params) {
33084
+ const res = await fetch(`${base}/v1/escrow/deposit`, {
33085
+ method: "POST",
33086
+ headers: { "Content-Type": "application/json" },
33087
+ body: JSON.stringify({ txHash: params.txHash })
33088
+ });
33089
+ if (res.status !== 200 && res.status !== 202) {
33090
+ throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
33091
+ }
33092
+ return await res.json();
33093
+ },
33094
+ async payForOperation(params) {
33095
+ const body = {
33096
+ payerAddress: params.payerAddress,
33097
+ opType: params.opType,
33098
+ opId: params.opId,
33099
+ asset: params.asset,
33100
+ amount: params.amount,
33101
+ paymentNonce: params.paymentNonce
33102
+ };
33103
+ if (params.accessRecord) {
33104
+ body["accessRecord"] = params.accessRecord;
33105
+ }
33106
+ const res = await fetch(`${base}/v1/escrow/pay`, {
33107
+ method: "POST",
32857
33108
  headers: {
32858
33109
  "Content-Type": "application/json",
32859
33110
  Authorization: `Web3Signed ${params.signature}`
32860
33111
  },
32861
- body: JSON.stringify({
32862
- ownerAddress: params.ownerAddress
32863
- })
33112
+ body: JSON.stringify(body)
32864
33113
  });
32865
- if (res.status === 409) return;
32866
33114
  if (!res.ok) {
32867
33115
  throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
32868
33116
  }
33117
+ return await res.json();
33118
+ },
33119
+ async settle(params) {
33120
+ const res = await fetch(`${base}/v1/settle`, {
33121
+ method: "POST",
33122
+ headers: { "Content-Type": "application/json" },
33123
+ // The gateway accepts an empty body; only `limit` is recognised.
33124
+ // Always send a JSON body so the gateway's req.body shape parse
33125
+ // doesn't have to deal with an undefined.
33126
+ body: JSON.stringify(params ?? {})
33127
+ });
33128
+ if (!res.ok) {
33129
+ throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
33130
+ }
33131
+ return await res.json();
32869
33132
  }
32870
33133
  };
32871
33134
  }
@@ -32889,7 +33152,7 @@ function genericPaymentDomain(chainId, escrowContract) {
32889
33152
  verifyingContract: escrowContract
32890
33153
  };
32891
33154
  }
32892
- var ESCROW_DEPOSIT_ABI = [
33155
+ var ESCROW_DEPOSIT_ABI2 = [
32893
33156
  {
32894
33157
  type: "function",
32895
33158
  name: "depositNative",
@@ -33046,6 +33309,7 @@ async function parsePSError(response) {
33046
33309
  }
33047
33310
  export {
33048
33311
  ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT,
33312
+ ADD_DATA_TYPES,
33049
33313
  AccountPersonalServerLiteOwnerBindingError,
33050
33314
  AccountPersonalServerRegistrationError,
33051
33315
  BUILDER_REGISTRATION_TYPES,
@@ -33056,13 +33320,14 @@ export {
33056
33320
  CallbackStorage,
33057
33321
  ContractFactory,
33058
33322
  ContractNotFoundError,
33323
+ DATA_REGISTRY_STATUS_ABI,
33059
33324
  DataFileEnvelopeSchema,
33325
+ DataPointStatus,
33060
33326
  DropboxStorage,
33061
33327
  ECIESError,
33062
- ESCROW_DEPOSIT_ABI,
33328
+ ESCROW_DEPOSIT_ABI2 as ESCROW_DEPOSIT_ABI,
33063
33329
  ExpiredTokenError,
33064
- FILE_DELETION_TYPES,
33065
- FILE_REGISTRATION_TYPES,
33330
+ FEE_REGISTRY_ABI,
33066
33331
  GENERIC_PAYMENT_TYPES,
33067
33332
  GRANT_REGISTRATION_TYPES,
33068
33333
  GRANT_REVOCATION_TYPES,
@@ -33075,6 +33340,7 @@ export {
33075
33340
  MASTER_KEY_MESSAGE,
33076
33341
  MissingAuthError,
33077
33342
  NATIVE_ASSET_ADDRESS,
33343
+ NATIVE_VANA_ASSET,
33078
33344
  NetworkError,
33079
33345
  NonceError,
33080
33346
  OAuthClient,
@@ -33090,6 +33356,8 @@ export {
33090
33356
  PersonalServerError,
33091
33357
  PinataStorage,
33092
33358
  R2Storage,
33359
+ RECORD_DATA_ACCESS_TYPES,
33360
+ REGISTRATION_KIND_FOR_OP,
33093
33361
  ReadOnlyError,
33094
33362
  RelayerError,
33095
33363
  SERVER_REGISTRATION_TYPES,
@@ -33104,10 +33372,15 @@ export {
33104
33372
  VanaError,
33105
33373
  VanaStorage,
33106
33374
  assertValidPkceVerifier,
33375
+ buildDepositNativeRequest,
33376
+ buildDepositTokenRequest,
33377
+ buildMarkDataPointUnavailableRequest,
33378
+ buildPersonalServerDataReadRequest,
33107
33379
  buildPersonalServerLiteOwnerBindingMessage,
33108
33380
  buildPersonalServerLiteOwnerBindingSignature,
33109
33381
  buildPersonalServerRegistrationSignature,
33110
33382
  buildPersonalServerRegistrationTypedData,
33383
+ buildSetDataPointStatusRequest,
33111
33384
  buildWeb3SignedHeader,
33112
33385
  builderRegistrationDomain,
33113
33386
  chains,
@@ -33123,14 +33396,19 @@ export {
33123
33396
  createVanaStorageProvider,
33124
33397
  createViemPersonalServerLiteOwnerBindingSigner,
33125
33398
  createViemPersonalServerRegistrationSigner,
33399
+ dataRegistryContractAddress,
33400
+ dataRegistryDomain,
33126
33401
  decryptWithPassword,
33127
33402
  deriveMasterKey,
33128
33403
  deriveScopeKey,
33129
33404
  deserializeECIES,
33130
33405
  detectPlatform,
33406
+ encodeDepositNativeData,
33407
+ encodeDepositTokenData,
33408
+ encodeSetDataPointStatusData,
33131
33409
  encryptWithPassword,
33132
- fileDeletionDomain,
33133
- fileRegistrationDomain,
33410
+ escrowContractAddress,
33411
+ escrowPaymentDomain,
33134
33412
  generatePkceVerifier,
33135
33413
  genericPaymentDomain,
33136
33414
  getAbi,
@@ -33139,6 +33417,8 @@ export {
33139
33417
  getContractAddress,
33140
33418
  getContractController,
33141
33419
  getContractInfo,
33420
+ getFee,
33421
+ getOpFee,
33142
33422
  getPlatformCapabilities,
33143
33423
  getServiceEndpoints,
33144
33424
  grantRegistrationDomain,
@@ -33150,11 +33430,12 @@ export {
33150
33430
  moksha,
33151
33431
  mokshaServices,
33152
33432
  mokshaTestnet2 as mokshaTestnet,
33153
- parseGrantRegistrationPayload,
33154
33433
  parsePSError,
33155
33434
  parseScope,
33156
33435
  parseWeb3SignedHeader,
33436
+ personalServerDataReadPath,
33157
33437
  personalServerRegistrationDomain,
33438
+ readPersonalServerData,
33158
33439
  recoverServerOwner,
33159
33440
  registerPersonalServerSignature,
33160
33441
  scopeCoveredByGrant,