@opendatalabs/vana-sdk 3.4.1-canary.e9d0aad → 3.5.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 (72) hide show
  1. package/dist/account/personal-server-lite-owner-binding.cjs +3 -3
  2. package/dist/account/personal-server-lite-owner-binding.cjs.map +1 -1
  3. package/dist/account/personal-server-lite-owner-binding.d.ts +2 -2
  4. package/dist/account/personal-server-lite-owner-binding.js +1 -1
  5. package/dist/account/personal-server-lite-owner-binding.js.map +1 -1
  6. package/dist/index.browser.d.ts +5 -8
  7. package/dist/index.browser.js +250 -416
  8. package/dist/index.browser.js.map +4 -4
  9. package/dist/index.node.cjs +258 -439
  10. package/dist/index.node.cjs.map +4 -4
  11. package/dist/index.node.d.ts +5 -8
  12. package/dist/index.node.js +250 -416
  13. package/dist/index.node.js.map +4 -4
  14. package/dist/{protocol/personal-server-lite-owner-binding.cjs → personal-server-lite/owner-binding.cjs} +5 -5
  15. package/dist/personal-server-lite/owner-binding.cjs.map +1 -0
  16. package/dist/{protocol/personal-server-lite-owner-binding.d.ts → personal-server-lite/owner-binding.d.ts} +3 -3
  17. package/dist/{protocol/personal-server-lite-owner-binding.js → personal-server-lite/owner-binding.js} +2 -2
  18. package/dist/personal-server-lite/owner-binding.js.map +1 -0
  19. package/dist/protocol/eip712.cjs +31 -53
  20. package/dist/protocol/eip712.cjs.map +1 -1
  21. package/dist/protocol/eip712.d.ts +43 -98
  22. package/dist/protocol/eip712.js +27 -47
  23. package/dist/protocol/eip712.js.map +1 -1
  24. package/dist/protocol/escrow.cjs +146 -0
  25. package/dist/protocol/escrow.cjs.map +1 -0
  26. package/dist/protocol/escrow.d.ts +336 -0
  27. package/dist/protocol/escrow.js +118 -0
  28. package/dist/protocol/escrow.js.map +1 -0
  29. package/dist/protocol/gateway.cjs +37 -107
  30. package/dist/protocol/gateway.cjs.map +1 -1
  31. package/dist/protocol/gateway.d.ts +57 -223
  32. package/dist/protocol/gateway.js +37 -107
  33. package/dist/protocol/gateway.js.map +1 -1
  34. package/dist/protocol/grants.cjs +64 -27
  35. package/dist/protocol/grants.cjs.map +1 -1
  36. package/dist/protocol/grants.d.ts +13 -6
  37. package/dist/protocol/grants.js +63 -27
  38. package/dist/protocol/grants.js.map +1 -1
  39. package/dist/protocol/personal-server-registration.cjs +16 -4
  40. package/dist/protocol/personal-server-registration.cjs.map +1 -1
  41. package/dist/protocol/personal-server-registration.d.ts +5 -2
  42. package/dist/protocol/personal-server-registration.js +16 -4
  43. package/dist/protocol/personal-server-registration.js.map +1 -1
  44. package/package.json +2 -3
  45. package/dist/protocol/data-point-status.cjs +0 -80
  46. package/dist/protocol/data-point-status.cjs.map +0 -1
  47. package/dist/protocol/data-point-status.d.ts +0 -34
  48. package/dist/protocol/data-point-status.js +0 -51
  49. package/dist/protocol/data-point-status.js.map +0 -1
  50. package/dist/protocol/escrow-deposit.cjs +0 -89
  51. package/dist/protocol/escrow-deposit.cjs.map +0 -1
  52. package/dist/protocol/escrow-deposit.d.ts +0 -47
  53. package/dist/protocol/escrow-deposit.js +0 -60
  54. package/dist/protocol/escrow-deposit.js.map +0 -1
  55. package/dist/protocol/escrow-flow.test.d.ts +0 -21
  56. package/dist/protocol/fee-registry.cjs +0 -116
  57. package/dist/protocol/fee-registry.cjs.map +0 -1
  58. package/dist/protocol/fee-registry.d.ts +0 -151
  59. package/dist/protocol/fee-registry.js +0 -89
  60. package/dist/protocol/fee-registry.js.map +0 -1
  61. package/dist/protocol/fee-registry.test.d.ts +0 -1
  62. package/dist/protocol/personal-server-data.cjs +0 -71
  63. package/dist/protocol/personal-server-data.cjs.map +0 -1
  64. package/dist/protocol/personal-server-data.d.ts +0 -16
  65. package/dist/protocol/personal-server-data.js +0 -47
  66. package/dist/protocol/personal-server-data.js.map +0 -1
  67. package/dist/protocol/personal-server-data.test.d.ts +0 -1
  68. package/dist/protocol/personal-server-lite-owner-binding.cjs.map +0 -1
  69. package/dist/protocol/personal-server-lite-owner-binding.js.map +0 -1
  70. package/dist/protocol/personal-server-lite-owner-binding.test.d.ts +0 -1
  71. /package/dist/{protocol/data-point-status.test.d.ts → personal-server-lite/owner-binding.test.d.ts} +0 -0
  72. /package/dist/protocol/{escrow-deposit.test.d.ts → escrow.test.d.ts} +0 -0
@@ -31882,7 +31882,6 @@ async function verifyWeb3Signed(params) {
31882
31882
  // src/protocol/eip712.ts
31883
31883
  var DOMAIN_NAME = "Vana Data Portability";
31884
31884
  var DOMAIN_VERSION = "1";
31885
- var NATIVE_VANA_ASSET = "0x0000000000000000000000000000000000000000";
31886
31885
  function buildDomain(chainId, verifyingContract) {
31887
31886
  return {
31888
31887
  name: DOMAIN_NAME,
@@ -31891,7 +31890,13 @@ function buildDomain(chainId, verifyingContract) {
31891
31890
  verifyingContract
31892
31891
  };
31893
31892
  }
31894
- function dataRegistryDomain(config) {
31893
+ function fileRegistrationDomain(config) {
31894
+ return buildDomain(
31895
+ config.chainId,
31896
+ config.contracts.dataRegistry
31897
+ );
31898
+ }
31899
+ function fileDeletionDomain(config) {
31895
31900
  return buildDomain(
31896
31901
  config.chainId,
31897
31902
  config.contracts.dataRegistry
@@ -31921,26 +31926,31 @@ function builderRegistrationDomain(config) {
31921
31926
  config.contracts.dataPortabilityGrantees
31922
31927
  );
31923
31928
  }
31924
- function escrowPaymentDomain(config) {
31925
- return buildDomain(
31926
- config.chainId,
31927
- config.contracts.dataPortabilityEscrow
31928
- );
31929
- }
31929
+ var FILE_REGISTRATION_TYPES = {
31930
+ FileRegistration: [
31931
+ { name: "ownerAddress", type: "address" },
31932
+ { name: "url", type: "string" },
31933
+ { name: "schemaId", type: "bytes32" }
31934
+ ]
31935
+ };
31936
+ var FILE_DELETION_TYPES = {
31937
+ FileDeletion: [
31938
+ { name: "ownerAddress", type: "address" },
31939
+ { name: "fileId", type: "bytes32" }
31940
+ ]
31941
+ };
31930
31942
  var GRANT_REGISTRATION_TYPES = {
31931
31943
  GrantRegistration: [
31932
31944
  { name: "grantorAddress", type: "address" },
31933
31945
  { name: "granteeId", type: "bytes32" },
31934
- { name: "scopes", type: "string[]" },
31935
- { name: "grantVersion", type: "uint256" },
31936
- { name: "expiresAt", type: "uint256" }
31946
+ { name: "grant", type: "string" },
31947
+ { name: "fileIds", type: "uint256[]" }
31937
31948
  ]
31938
31949
  };
31939
31950
  var GRANT_REVOCATION_TYPES = {
31940
31951
  GrantRevocation: [
31941
31952
  { name: "grantorAddress", type: "address" },
31942
- { name: "grantId", type: "bytes32" },
31943
- { name: "grantVersion", type: "uint256" }
31953
+ { name: "grantId", type: "bytes32" }
31944
31954
  ]
31945
31955
  };
31946
31956
  var SERVER_REGISTRATION_TYPES = {
@@ -31959,41 +31969,16 @@ var BUILDER_REGISTRATION_TYPES = {
31959
31969
  { name: "appUrl", type: "string" }
31960
31970
  ]
31961
31971
  };
31962
- var GENERIC_PAYMENT_TYPES = {
31963
- GenericPayment: [
31964
- { name: "payerAddress", type: "address" },
31965
- { name: "opType", type: "string" },
31966
- { name: "opId", type: "bytes32" },
31967
- { name: "asset", type: "address" },
31968
- { name: "amount", type: "uint256" },
31969
- { name: "paymentNonce", type: "uint256" }
31970
- ]
31971
- };
31972
- var ADD_DATA_TYPES = {
31973
- AddData: [
31974
- { name: "ownerAddress", type: "address" },
31975
- { name: "scope", type: "string" },
31976
- { name: "dataHash", type: "bytes32" },
31977
- { name: "metadataHash", type: "bytes32" },
31978
- { name: "expectedVersion", type: "uint256" }
31979
- ]
31980
- };
31981
- var RECORD_DATA_ACCESS_TYPES = {
31982
- RecordDataAccess: [
31983
- { name: "ownerAddress", type: "address" },
31984
- { name: "scope", type: "string" },
31985
- { name: "version", type: "uint256" },
31986
- { name: "accessor", type: "address" },
31987
- { name: "recordId", type: "bytes32" }
31988
- ]
31989
- };
31990
31972
 
31991
31973
  // src/protocol/personal-server-registration.ts
31992
31974
  import {
31993
31975
  isAddress
31994
31976
  } from "viem";
31995
- var PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID = 1480;
31996
- var PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT = "0x1483B1F634DBA75AeaE60da7f01A679aabd5ee2c";
31977
+ var PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID = vanaMainnet2.id;
31978
+ var PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT = getContractAddress(
31979
+ PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID,
31980
+ "DataPortabilityServers"
31981
+ );
31997
31982
  function assertAddress(value, name) {
31998
31983
  if (!isAddress(value)) {
31999
31984
  throw new Error(`${name} must be a valid EVM address`);
@@ -32008,6 +31993,12 @@ function getAccountAddress(account) {
32008
31993
  function isPersonalServerRegistrationSigner(source) {
32009
31994
  return "address" in source && typeof source.signTypedData === "function";
32010
31995
  }
31996
+ function getDefaultServerRegistrationContract(chainId) {
31997
+ return getContractAddress(
31998
+ chainId,
31999
+ "DataPortabilityServers"
32000
+ );
32001
+ }
32011
32002
  function createViemPersonalServerRegistrationSigner(source, options = {}) {
32012
32003
  if (isPersonalServerRegistrationSigner(source)) {
32013
32004
  return source;
@@ -32030,12 +32021,13 @@ function personalServerRegistrationDomain(input = {}) {
32030
32021
  if (input.config) {
32031
32022
  return serverRegistrationDomain(input.config);
32032
32023
  }
32033
- const verifyingContract = input.verifyingContract ?? PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT;
32024
+ const chainId = input.chainId ?? PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID;
32025
+ const verifyingContract = input.verifyingContract ?? getDefaultServerRegistrationContract(chainId);
32034
32026
  assertAddress(verifyingContract, "verifyingContract");
32035
32027
  return {
32036
32028
  name: "Vana Data Portability",
32037
32029
  version: "1",
32038
- chainId: input.chainId ?? PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID,
32030
+ chainId,
32039
32031
  verifyingContract
32040
32032
  };
32041
32033
  }
@@ -32073,11 +32065,11 @@ async function buildPersonalServerRegistrationSignature(input) {
32073
32065
  }
32074
32066
  var registerPersonalServerSignature = buildPersonalServerRegistrationSignature;
32075
32067
 
32076
- // src/protocol/personal-server-lite-owner-binding.ts
32068
+ // src/personal-server-lite/owner-binding.ts
32077
32069
  import {
32078
32070
  isAddress as isAddress2
32079
32071
  } from "viem";
32080
- var PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION = "vana.account.v1";
32072
+ var PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION = "vana.ps-lite.owner-binding.v1";
32081
32073
  var PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE = "ps-lite-owner";
32082
32074
  var PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX = `${PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION}:${PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE}:`;
32083
32075
  function assertAddress2(value, name) {
@@ -32428,34 +32420,67 @@ function isDataPortabilityGatewayConfig(value) {
32428
32420
  return false;
32429
32421
  }
32430
32422
  const c = contracts;
32431
- return isHexString(c["dataRegistry"]) && isHexString(c["dataPortabilityPermissions"]) && isHexString(c["dataPortabilityServer"]) && isHexString(c["dataPortabilityGrantees"]) && isHexString(c["dataPortabilityEscrow"]) && isHexString(c["feeRegistry"]);
32423
+ return isHexString(c["dataRegistry"]) && isHexString(c["dataPortabilityPermissions"]) && isHexString(c["dataPortabilityServer"]) && isHexString(c["dataPortabilityGrantees"]);
32432
32424
  }
32433
- function toUint256(value) {
32425
+ function parseGrantRegistrationPayload(grant) {
32426
+ let parsed;
32434
32427
  try {
32435
- if (typeof value === "number" && !Number.isSafeInteger(value)) {
32436
- return null;
32437
- }
32438
- const big = typeof value === "bigint" ? value : BigInt(value);
32439
- if (big < 0n) return null;
32440
- return big;
32428
+ parsed = JSON.parse(grant);
32441
32429
  } catch {
32442
32430
  return null;
32443
32431
  }
32444
- }
32445
- async function verifyGrantRegistration(input) {
32446
- if (!Array.isArray(input.scopes) || input.scopes.length === 0) {
32447
- return { valid: false, error: "scopes must be a non-empty array" };
32432
+ if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
32433
+ return null;
32434
+ }
32435
+ const value = parsed;
32436
+ if (!Array.isArray(value["scopes"]) || value["scopes"].length === 0) {
32437
+ return null;
32438
+ }
32439
+ if (!value["scopes"].every((scope) => typeof scope === "string")) {
32440
+ return null;
32441
+ }
32442
+ if (typeof value["expiresAt"] !== "number" || !Number.isFinite(value["expiresAt"])) {
32443
+ return null;
32444
+ }
32445
+ if (value["user"] !== void 0 && !isHexString(value["user"])) {
32446
+ return null;
32447
+ }
32448
+ if (value["builder"] !== void 0 && !isHexString(value["builder"])) {
32449
+ return null;
32448
32450
  }
32449
- if (!input.scopes.every((scope) => typeof scope === "string")) {
32450
- return { valid: false, error: "scopes must contain only strings" };
32451
+ if (value["nonce"] !== void 0 && (typeof value["nonce"] !== "number" || !Number.isFinite(value["nonce"]))) {
32452
+ return null;
32451
32453
  }
32452
- const grantVersion = toUint256(input.grantVersion);
32453
- if (grantVersion === null || grantVersion < 1n) {
32454
- return { valid: false, error: "grantVersion must be a uint256 >= 1" };
32454
+ return {
32455
+ user: value["user"],
32456
+ builder: value["builder"],
32457
+ scopes: value["scopes"],
32458
+ expiresAt: value["expiresAt"],
32459
+ nonce: value["nonce"]
32460
+ };
32461
+ }
32462
+ function parseFileIds(fileIds) {
32463
+ try {
32464
+ const values = (fileIds ?? []).map((fileId) => BigInt(fileId));
32465
+ return {
32466
+ values,
32467
+ display: values.map((fileId) => fileId.toString())
32468
+ };
32469
+ } catch {
32470
+ return null;
32455
32471
  }
32456
- const expiresAt = toUint256(input.expiresAt);
32457
- if (expiresAt === null) {
32458
- return { valid: false, error: "expiresAt must be a non-negative uint256" };
32472
+ }
32473
+ async function verifyGrantRegistration(input) {
32474
+ const payload = parseGrantRegistrationPayload(input.grant);
32475
+ if (!payload) {
32476
+ return {
32477
+ valid: false,
32478
+ error: "Grant must be JSON with scopes and expiresAt"
32479
+ };
32480
+ }
32481
+ const fileIds = parseFileIds(input.fileIds);
32482
+ if (!fileIds) {
32483
+ return { valid: false, error: "fileIds must contain integer values" };
32459
32484
  }
32460
32485
  let valid;
32461
32486
  try {
@@ -32467,9 +32492,8 @@ async function verifyGrantRegistration(input) {
32467
32492
  message: {
32468
32493
  grantorAddress: input.grantorAddress,
32469
32494
  granteeId: input.granteeId,
32470
- scopes: input.scopes,
32471
- grantVersion,
32472
- expiresAt
32495
+ grant: input.grant,
32496
+ fileIds: fileIds.values
32473
32497
  },
32474
32498
  signature: input.signature
32475
32499
  });
@@ -32480,197 +32504,19 @@ async function verifyGrantRegistration(input) {
32480
32504
  return { valid: false, error: "Grant signature does not match grantor" };
32481
32505
  }
32482
32506
  const nowSeconds = input.nowSeconds ?? Math.floor(Date.now() / 1e3);
32483
- if (expiresAt > 0n && expiresAt < BigInt(nowSeconds)) {
32507
+ if (payload.expiresAt > 0 && payload.expiresAt < nowSeconds) {
32484
32508
  return { valid: false, error: "Grant has expired" };
32485
32509
  }
32510
+ if (payload.user !== void 0 && payload.user.toLowerCase() !== input.grantorAddress.toLowerCase()) {
32511
+ return { valid: false, error: "Grant user does not match grantorAddress" };
32512
+ }
32486
32513
  return {
32487
32514
  valid: true,
32488
32515
  grantorAddress: input.grantorAddress,
32489
32516
  granteeId: input.granteeId,
32490
- scopes: input.scopes,
32491
- grantVersion: grantVersion.toString(),
32492
- expiresAt: expiresAt.toString()
32493
- };
32494
- }
32495
-
32496
- // src/protocol/escrow-deposit.ts
32497
- import { encodeFunctionData } from "viem";
32498
- var ESCROW_DEPOSIT_ABI = [
32499
- {
32500
- type: "function",
32501
- name: "depositNative",
32502
- stateMutability: "payable",
32503
- inputs: [{ name: "account", type: "address" }],
32504
- outputs: []
32505
- },
32506
- {
32507
- type: "function",
32508
- name: "depositToken",
32509
- stateMutability: "nonpayable",
32510
- inputs: [
32511
- { name: "account", type: "address" },
32512
- { name: "token", type: "address" },
32513
- { name: "amount", type: "uint256" }
32514
- ],
32515
- outputs: []
32516
- }
32517
- ];
32518
- function escrowContractAddress(config) {
32519
- return config.contracts.dataPortabilityEscrow;
32520
- }
32521
- function encodeDepositNativeData(input) {
32522
- return encodeFunctionData({
32523
- abi: ESCROW_DEPOSIT_ABI,
32524
- functionName: "depositNative",
32525
- args: [input.account]
32526
- });
32527
- }
32528
- function encodeDepositTokenData(input) {
32529
- return encodeFunctionData({
32530
- abi: ESCROW_DEPOSIT_ABI,
32531
- functionName: "depositToken",
32532
- args: [input.account, input.token, input.amount]
32533
- });
32534
- }
32535
- function buildDepositNativeRequest(config, input) {
32536
- return {
32537
- to: escrowContractAddress(config),
32538
- data: encodeDepositNativeData({ account: input.account }),
32539
- value: input.amount
32540
- };
32541
- }
32542
- function buildDepositTokenRequest(config, input) {
32543
- return {
32544
- to: escrowContractAddress(config),
32545
- data: encodeDepositTokenData(input)
32546
- };
32547
- }
32548
-
32549
- // src/protocol/data-point-status.ts
32550
- import { encodeFunctionData as encodeFunctionData2 } from "viem";
32551
- var DataPointStatus = /* @__PURE__ */ ((DataPointStatus2) => {
32552
- DataPointStatus2[DataPointStatus2["None"] = 0] = "None";
32553
- DataPointStatus2[DataPointStatus2["Active"] = 1] = "Active";
32554
- DataPointStatus2[DataPointStatus2["Inactive"] = 2] = "Inactive";
32555
- DataPointStatus2[DataPointStatus2["Unavailable"] = 3] = "Unavailable";
32556
- return DataPointStatus2;
32557
- })(DataPointStatus || {});
32558
- var DATA_REGISTRY_STATUS_ABI = [
32559
- {
32560
- type: "function",
32561
- name: "setStatus",
32562
- stateMutability: "nonpayable",
32563
- inputs: [
32564
- { name: "scope", type: "string" },
32565
- { name: "newStatus", type: "uint8" }
32566
- ],
32567
- outputs: []
32568
- }
32569
- ];
32570
- function dataRegistryContractAddress(config) {
32571
- return config.contracts.dataRegistry;
32572
- }
32573
- function encodeSetDataPointStatusData(input) {
32574
- return encodeFunctionData2({
32575
- abi: DATA_REGISTRY_STATUS_ABI,
32576
- functionName: "setStatus",
32577
- args: [input.scope, input.status]
32578
- });
32579
- }
32580
- function buildSetDataPointStatusRequest(config, input) {
32581
- return {
32582
- to: dataRegistryContractAddress(config),
32583
- data: encodeSetDataPointStatusData(input)
32584
- };
32585
- }
32586
- function buildMarkDataPointUnavailableRequest(config, input) {
32587
- return buildSetDataPointStatusRequest(config, {
32588
- scope: input.scope,
32589
- status: 3 /* Unavailable */
32590
- });
32591
- }
32592
-
32593
- // src/protocol/fee-registry.ts
32594
- import { parseAbi } from "viem";
32595
- var FEE_REGISTRY_ABI = parseAbi([
32596
- "struct Fee { uint256 amount; address asset; address payee; bool enabled; }",
32597
- "function fees(bytes32 operation) view returns (Fee)",
32598
- "function operationKey(string name) pure returns (bytes32)"
32599
- ]);
32600
- var REGISTRATION_KIND_FOR_OP = {
32601
- grant: "grant_registration",
32602
- data: "data_registration",
32603
- server: "server_registration",
32604
- builder: "builder_registration"
32605
- };
32606
- function operationNameFor(kind, opts) {
32607
- switch (kind) {
32608
- case "grant_registration":
32609
- return opts?.grantRegistrationOpName ?? "grant_registration";
32610
- case "data_access":
32611
- return opts?.dataAccessOpName ?? "data_access";
32612
- case "data_registration":
32613
- return opts?.dataRegistrationOpName ?? "data_registration";
32614
- case "server_registration":
32615
- return opts?.serverRegistrationOpName ?? "server_registration";
32616
- case "builder_registration":
32617
- return opts?.builderRegistrationOpName ?? "builder_registration";
32618
- }
32619
- }
32620
- var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
32621
- async function getFee(client, config, kind, opts) {
32622
- const address = config.contracts.feeRegistry;
32623
- const opName = operationNameFor(kind, opts);
32624
- const opKey = await client.readContract({
32625
- address,
32626
- abi: FEE_REGISTRY_ABI,
32627
- functionName: "operationKey",
32628
- args: [opName]
32629
- });
32630
- const fee = await client.readContract({
32631
- address,
32632
- abi: FEE_REGISTRY_ABI,
32633
- functionName: "fees",
32634
- args: [opKey]
32635
- });
32636
- if (fee.enabled && fee.payee === ZERO_ADDRESS) {
32637
- throw new Error(
32638
- `FeeRegistry: enabled operation "${opName}" has zero-address payee \u2014 contract pre-flight rejects payouts to 0x0`
32639
- );
32640
- }
32641
- return fee;
32642
- }
32643
- async function getOpFee(client, config, opType, opts) {
32644
- const registrationKind = REGISTRATION_KIND_FOR_OP[opType];
32645
- if (!registrationKind) {
32646
- throw new Error(
32647
- `getOpFee: unknown opType "${opType}" \u2014 supported types are ${Object.keys(REGISTRATION_KIND_FOR_OP).join(", ")}`
32648
- );
32649
- }
32650
- const includeDataAccess = opType === "grant";
32651
- const [registration, dataAccess] = await Promise.all([
32652
- getFee(client, config, registrationKind, opts),
32653
- includeDataAccess ? getFee(client, config, "data_access", opts) : Promise.resolve({
32654
- amount: 0n,
32655
- asset: ZERO_ADDRESS,
32656
- payee: ZERO_ADDRESS,
32657
- enabled: false
32658
- })
32659
- ]);
32660
- if (registration.enabled && dataAccess.enabled && registration.asset.toLowerCase() !== dataAccess.asset.toLowerCase()) {
32661
- throw new Error(
32662
- `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.`
32663
- );
32664
- }
32665
- const asset = registration.enabled ? registration.asset : dataAccess.enabled ? dataAccess.asset : ZERO_ADDRESS;
32666
- return {
32667
- asset,
32668
- registrationFee: registration.enabled ? registration.amount : 0n,
32669
- dataAccessFee: dataAccess.enabled ? dataAccess.amount : 0n,
32670
- registrationEnabled: registration.enabled,
32671
- dataAccessEnabled: dataAccess.enabled,
32672
- registrationPayee: registration.enabled ? registration.payee : ZERO_ADDRESS,
32673
- dataAccessPayee: dataAccess.enabled ? dataAccess.payee : ZERO_ADDRESS
32517
+ grant: input.grant,
32518
+ payload,
32519
+ fileIds: fileIds.display
32674
32520
  };
32675
32521
  }
32676
32522
 
@@ -32744,45 +32590,6 @@ var IngestResponseSchema = z2.object({
32744
32590
  status: z2.enum(["stored", "syncing"])
32745
32591
  });
32746
32592
 
32747
- // src/protocol/personal-server-data.ts
32748
- function personalServerDataReadPath(scope) {
32749
- return `/v1/data/${encodeURIComponent(scope)}`;
32750
- }
32751
- async function buildPersonalServerDataReadRequest(params) {
32752
- const path = personalServerDataReadPath(params.scope);
32753
- const baseUrl = params.personalServerUrl.replace(/\/+$/, "");
32754
- const audience = params.audience ?? baseUrl;
32755
- const headers = new Headers(params.headers);
32756
- headers.set(
32757
- "Authorization",
32758
- await buildWeb3SignedHeader({
32759
- aud: audience,
32760
- grantId: params.grantId,
32761
- method: "GET",
32762
- signMessage: params.signMessage,
32763
- uri: path
32764
- })
32765
- );
32766
- return new Request(`${baseUrl}${path}`, {
32767
- headers,
32768
- method: "GET"
32769
- });
32770
- }
32771
- async function readPersonalServerData(params) {
32772
- const fetchFn = params.fetch ?? globalThis.fetch;
32773
- if (fetchFn === void 0) {
32774
- throw new Error("No fetch implementation available");
32775
- }
32776
- const request = await buildPersonalServerDataReadRequest(params);
32777
- const response = await fetchFn(request);
32778
- if (!response.ok) {
32779
- throw new Error(
32780
- `Personal Server data read failed: ${response.status} ${response.statusText}`
32781
- );
32782
- }
32783
- return DataFileEnvelopeSchema.parse(await response.json());
32784
- }
32785
-
32786
32593
  // src/protocol/gateway.ts
32787
32594
  function createGatewayClient(baseUrl) {
32788
32595
  const base = baseUrl.replace(/\/+$/, "");
@@ -32790,6 +32597,16 @@ function createGatewayClient(baseUrl) {
32790
32597
  const envelope = await res.json();
32791
32598
  return envelope.data;
32792
32599
  }
32600
+ function normalizeFileRecord(record) {
32601
+ return {
32602
+ fileId: record.fileId ?? record.id ?? "",
32603
+ owner: record.owner ?? record.ownerAddress ?? "",
32604
+ url: record.url,
32605
+ schemaId: record.schemaId,
32606
+ createdAt: record.createdAt ?? record.addedAt ?? "",
32607
+ deletedAt: record.deletedAt ?? null
32608
+ };
32609
+ }
32793
32610
  function getMutationId(body, key) {
32794
32611
  const value = body[key] ?? body["id"];
32795
32612
  return typeof value === "string" ? value : void 0;
@@ -32839,33 +32656,31 @@ function createGatewayClient(baseUrl) {
32839
32656
  }
32840
32657
  return unwrapEnvelope(res);
32841
32658
  },
32842
- async getDataPoint(dataPointId) {
32843
- const res = await fetch(`${base}/v1/data/${dataPointId}`);
32659
+ async getFile(fileId) {
32660
+ const res = await fetch(`${base}/v1/files/${fileId}`);
32844
32661
  if (res.status === 404) return null;
32845
32662
  if (!res.ok) {
32846
32663
  throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
32847
32664
  }
32848
- return unwrapEnvelope(res);
32665
+ return normalizeFileRecord(await unwrapEnvelope(res));
32849
32666
  },
32850
- async listDataPointsByOwner(owner, cursor, options) {
32667
+ async listFilesSince(owner, cursor, options) {
32851
32668
  const params = new URLSearchParams({ user: owner });
32852
32669
  if (cursor !== null) {
32853
32670
  params.set("cursor", cursor);
32854
32671
  }
32855
- if (options?.since) {
32856
- params.set("since", options.since);
32672
+ if (options?.includeDeleted) {
32673
+ params.set("includeDeleted", "true");
32857
32674
  }
32858
- if (options?.limit !== void 0) {
32859
- params.set("limit", String(options.limit));
32860
- }
32861
- const res = await fetch(`${base}/v1/data?${params.toString()}`);
32675
+ const res = await fetch(`${base}/v1/files?${params.toString()}`);
32862
32676
  if (!res.ok) {
32863
32677
  throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
32864
32678
  }
32865
32679
  const envelope = await res.json();
32866
- const nextCursor = envelope.pagination?.hasMore === false ? null : envelope.pagination?.nextCursor ?? null;
32680
+ const { pagination } = envelope;
32681
+ const nextCursor = pagination?.hasMore === false ? null : pagination?.nextCursor ?? envelope.data.cursor ?? null;
32867
32682
  return {
32868
- dataPoints: envelope.data.dataPoints,
32683
+ files: envelope.data.files.map(normalizeFileRecord),
32869
32684
  cursor: nextCursor
32870
32685
  };
32871
32686
  },
@@ -32907,8 +32722,8 @@ function createGatewayClient(baseUrl) {
32907
32722
  alreadyRegistered: false
32908
32723
  };
32909
32724
  },
32910
- async registerBuilder(params) {
32911
- const res = await fetch(`${base}/v1/builders`, {
32725
+ async registerFile(params) {
32726
+ const res = await fetch(`${base}/v1/files`, {
32912
32727
  method: "POST",
32913
32728
  headers: {
32914
32729
  "Content-Type": "application/json",
@@ -32916,57 +32731,22 @@ function createGatewayClient(baseUrl) {
32916
32731
  },
32917
32732
  body: JSON.stringify({
32918
32733
  ownerAddress: params.ownerAddress,
32919
- granteeAddress: params.granteeAddress,
32920
- publicKey: params.publicKey,
32921
- appUrl: params.appUrl
32734
+ url: params.url,
32735
+ schemaId: params.schemaId
32922
32736
  })
32923
32737
  });
32924
32738
  if (res.status === 409) {
32925
32739
  const body2 = await res.json().catch(() => ({}));
32926
32740
  return {
32927
- builderId: getMutationId(
32928
- body2,
32929
- "builderId"
32930
- ),
32931
- alreadyRegistered: true
32741
+ fileId: getMutationId(body2, "fileId")
32932
32742
  };
32933
32743
  }
32934
32744
  if (!res.ok) {
32935
32745
  throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
32936
32746
  }
32937
- const body = await res.json().catch(() => ({}));
32938
- return {
32939
- builderId: getMutationId(body, "builderId"),
32940
- alreadyRegistered: false
32941
- };
32942
- },
32943
- async registerDataPoint(params) {
32944
- const res = await fetch(`${base}/v1/data`, {
32945
- method: "POST",
32946
- headers: {
32947
- "Content-Type": "application/json",
32948
- Authorization: `Web3Signed ${params.signature}`
32949
- },
32950
- body: JSON.stringify({
32951
- ownerAddress: params.ownerAddress,
32952
- scope: params.scope,
32953
- dataHash: params.dataHash,
32954
- metadataHash: params.metadataHash,
32955
- expectedVersion: params.expectedVersion
32956
- })
32957
- });
32958
- if (!res.ok) {
32959
- const body2 = await res.json().catch(() => ({}));
32960
- const detail = body2.error ?? res.statusText;
32961
- throw new Error(`Gateway error: ${res.status} ${detail}`);
32962
- }
32963
- const body = await res.json().catch(() => ({}));
32747
+ const body = await res.json();
32964
32748
  return {
32965
- dataPointId: getMutationId(
32966
- body,
32967
- "dataPointId"
32968
- ),
32969
- expectedVersion: body.expectedVersion
32749
+ fileId: getMutationId(body, "fileId")
32970
32750
  };
32971
32751
  },
32972
32752
  async createGrant(params) {
@@ -32979,9 +32759,8 @@ function createGatewayClient(baseUrl) {
32979
32759
  body: JSON.stringify({
32980
32760
  grantorAddress: params.grantorAddress,
32981
32761
  granteeId: params.granteeId,
32982
- scopes: params.scopes,
32983
- grantVersion: params.grantVersion,
32984
- expiresAt: params.expiresAt
32762
+ grant: params.grant,
32763
+ fileIds: params.fileIds
32985
32764
  })
32986
32765
  });
32987
32766
  if (res.status === 409) {
@@ -33006,8 +32785,7 @@ function createGatewayClient(baseUrl) {
33006
32785
  Authorization: `Web3Signed ${params.signature}`
33007
32786
  },
33008
32787
  body: JSON.stringify({
33009
- grantorAddress: params.grantorAddress,
33010
- grantVersion: params.grantVersion
32788
+ grantorAddress: params.grantorAddress
33011
32789
  })
33012
32790
  });
33013
32791
  if (res.status === 409) return;
@@ -33015,62 +32793,133 @@ function createGatewayClient(baseUrl) {
33015
32793
  throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
33016
32794
  }
33017
32795
  },
33018
- async getEscrowBalance(account) {
33019
- const res = await fetch(`${base}/v1/escrow/balance?account=${account}`);
32796
+ async deleteFile(params) {
32797
+ const res = await fetch(`${base}/v1/files/${params.fileId}`, {
32798
+ method: "DELETE",
32799
+ headers: {
32800
+ "Content-Type": "application/json",
32801
+ Authorization: `Web3Signed ${params.signature}`
32802
+ },
32803
+ body: JSON.stringify({
32804
+ ownerAddress: params.ownerAddress
32805
+ })
32806
+ });
32807
+ if (res.status === 409) return;
33020
32808
  if (!res.ok) {
33021
32809
  throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
33022
32810
  }
33023
- return await res.json();
33024
- },
33025
- async submitEscrowDeposit(params) {
32811
+ }
32812
+ };
32813
+ }
32814
+
32815
+ // src/protocol/escrow.ts
32816
+ var GENERIC_PAYMENT_TYPES = {
32817
+ GenericPayment: [
32818
+ { name: "payerAddress", type: "address" },
32819
+ { name: "opType", type: "string" },
32820
+ { name: "opId", type: "bytes32" },
32821
+ { name: "asset", type: "address" },
32822
+ { name: "amount", type: "uint256" },
32823
+ { name: "paymentNonce", type: "uint256" }
32824
+ ]
32825
+ };
32826
+ function genericPaymentDomain(chainId, escrowContract) {
32827
+ return {
32828
+ name: "Vana Data Portability",
32829
+ version: "1",
32830
+ chainId,
32831
+ verifyingContract: escrowContract
32832
+ };
32833
+ }
32834
+ var ESCROW_DEPOSIT_ABI = [
32835
+ {
32836
+ type: "function",
32837
+ name: "depositNative",
32838
+ stateMutability: "payable",
32839
+ inputs: [{ name: "account", type: "address" }],
32840
+ outputs: []
32841
+ },
32842
+ {
32843
+ type: "function",
32844
+ name: "depositToken",
32845
+ stateMutability: "nonpayable",
32846
+ inputs: [
32847
+ { name: "account", type: "address" },
32848
+ { name: "token", type: "address" },
32849
+ { name: "amount", type: "uint256" }
32850
+ ],
32851
+ outputs: []
32852
+ }
32853
+ ];
32854
+ var NATIVE_ASSET_ADDRESS = "0x0000000000000000000000000000000000000000";
32855
+ function createEscrowGatewayClient(baseUrl) {
32856
+ const base = baseUrl.replace(/\/+$/, "");
32857
+ async function throwOnError(res, context) {
32858
+ if (!res.ok) {
32859
+ let detail = "";
32860
+ try {
32861
+ const body = await res.json();
32862
+ if (body.error) detail = `: ${body.error}`;
32863
+ } catch {
32864
+ }
32865
+ throw new Error(
32866
+ `Escrow gateway error (${context}): ${res.status} ${res.statusText}${detail}`
32867
+ );
32868
+ }
32869
+ }
32870
+ return {
32871
+ async submitDeposit({ txHash }) {
33026
32872
  const res = await fetch(`${base}/v1/escrow/deposit`, {
33027
32873
  method: "POST",
33028
32874
  headers: { "Content-Type": "application/json" },
33029
- body: JSON.stringify({ txHash: params.txHash })
32875
+ body: JSON.stringify({ txHash })
33030
32876
  });
33031
32877
  if (res.status !== 200 && res.status !== 202) {
33032
- throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
32878
+ await throwOnError(res, "POST /v1/escrow/deposit");
33033
32879
  }
33034
- return await res.json();
32880
+ return res.json();
33035
32881
  },
33036
- async payForOperation(params) {
33037
- const body = {
33038
- payerAddress: params.payerAddress,
33039
- opType: params.opType,
33040
- opId: params.opId,
33041
- asset: params.asset,
33042
- amount: params.amount,
33043
- paymentNonce: params.paymentNonce
33044
- };
33045
- if (params.accessRecord) {
33046
- body["accessRecord"] = params.accessRecord;
33047
- }
32882
+ async getEscrowBalance(account) {
32883
+ const res = await fetch(
32884
+ `${base}/v1/escrow/balance?account=${encodeURIComponent(account)}`
32885
+ );
32886
+ await throwOnError(res, "GET /v1/escrow/balance");
32887
+ return res.json();
32888
+ },
32889
+ async syncEscrowBalance(account) {
32890
+ const res = await fetch(
32891
+ `${base}/v1/escrow/balance/sync?account=${encodeURIComponent(account)}`,
32892
+ { method: "POST" }
32893
+ );
32894
+ await throwOnError(res, "POST /v1/escrow/balance/sync");
32895
+ return res.json();
32896
+ },
32897
+ async payForOp({
32898
+ payerAddress,
32899
+ opType,
32900
+ opId,
32901
+ asset,
32902
+ amount,
32903
+ paymentNonce,
32904
+ signature
32905
+ }) {
33048
32906
  const res = await fetch(`${base}/v1/escrow/pay`, {
33049
32907
  method: "POST",
33050
32908
  headers: {
33051
32909
  "Content-Type": "application/json",
33052
- Authorization: `Web3Signed ${params.signature}`
32910
+ Authorization: `Web3Signed ${signature}`
33053
32911
  },
33054
- body: JSON.stringify(body)
33055
- });
33056
- if (!res.ok) {
33057
- throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
33058
- }
33059
- return await res.json();
33060
- },
33061
- async settle(params) {
33062
- const res = await fetch(`${base}/v1/settle`, {
33063
- method: "POST",
33064
- headers: { "Content-Type": "application/json" },
33065
- // The gateway accepts an empty body; only `limit` is recognised.
33066
- // Always send a JSON body so the gateway's req.body shape parse
33067
- // doesn't have to deal with an undefined.
33068
- body: JSON.stringify(params ?? {})
32912
+ body: JSON.stringify({
32913
+ payerAddress,
32914
+ opType,
32915
+ opId,
32916
+ asset,
32917
+ amount,
32918
+ paymentNonce
32919
+ })
33069
32920
  });
33070
- if (!res.ok) {
33071
- throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
33072
- }
33073
- return await res.json();
32921
+ await throwOnError(res, "POST /v1/escrow/pay");
32922
+ return res.json();
33074
32923
  }
33075
32924
  };
33076
32925
  }
@@ -33139,7 +32988,6 @@ async function parsePSError(response) {
33139
32988
  }
33140
32989
  export {
33141
32990
  ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT,
33142
- ADD_DATA_TYPES,
33143
32991
  AccountPersonalServerLiteOwnerBindingError,
33144
32992
  AccountPersonalServerRegistrationError,
33145
32993
  BUILDER_REGISTRATION_TYPES,
@@ -33150,14 +32998,13 @@ export {
33150
32998
  CallbackStorage,
33151
32999
  ContractFactory,
33152
33000
  ContractNotFoundError,
33153
- DATA_REGISTRY_STATUS_ABI,
33154
33001
  DataFileEnvelopeSchema,
33155
- DataPointStatus,
33156
33002
  DropboxStorage,
33157
33003
  ECIESError,
33158
33004
  ESCROW_DEPOSIT_ABI,
33159
33005
  ExpiredTokenError,
33160
- FEE_REGISTRY_ABI,
33006
+ FILE_DELETION_TYPES,
33007
+ FILE_REGISTRATION_TYPES,
33161
33008
  GENERIC_PAYMENT_TYPES,
33162
33009
  GRANT_REGISTRATION_TYPES,
33163
33010
  GRANT_REVOCATION_TYPES,
@@ -33169,7 +33016,7 @@ export {
33169
33016
  IpfsStorage,
33170
33017
  MASTER_KEY_MESSAGE,
33171
33018
  MissingAuthError,
33172
- NATIVE_VANA_ASSET,
33019
+ NATIVE_ASSET_ADDRESS,
33173
33020
  NetworkError,
33174
33021
  NonceError,
33175
33022
  OAuthClient,
@@ -33185,8 +33032,6 @@ export {
33185
33032
  PersonalServerError,
33186
33033
  PinataStorage,
33187
33034
  R2Storage,
33188
- RECORD_DATA_ACCESS_TYPES,
33189
- REGISTRATION_KIND_FOR_OP,
33190
33035
  ReadOnlyError,
33191
33036
  RelayerError,
33192
33037
  SERVER_REGISTRATION_TYPES,
@@ -33201,15 +33046,10 @@ export {
33201
33046
  VanaError,
33202
33047
  VanaStorage,
33203
33048
  assertValidPkceVerifier,
33204
- buildDepositNativeRequest,
33205
- buildDepositTokenRequest,
33206
- buildMarkDataPointUnavailableRequest,
33207
- buildPersonalServerDataReadRequest,
33208
33049
  buildPersonalServerLiteOwnerBindingMessage,
33209
33050
  buildPersonalServerLiteOwnerBindingSignature,
33210
33051
  buildPersonalServerRegistrationSignature,
33211
33052
  buildPersonalServerRegistrationTypedData,
33212
- buildSetDataPointStatusRequest,
33213
33053
  buildWeb3SignedHeader,
33214
33054
  builderRegistrationDomain,
33215
33055
  chains,
@@ -33219,33 +33059,28 @@ export {
33219
33059
  contractCacheForTesting,
33220
33060
  createBrowserPlatformAdapter,
33221
33061
  createDataFileEnvelope,
33062
+ createEscrowGatewayClient,
33222
33063
  createGatewayClient,
33223
33064
  createPlatformAdapterSafe,
33224
33065
  createVanaStorageProvider,
33225
33066
  createViemPersonalServerLiteOwnerBindingSigner,
33226
33067
  createViemPersonalServerRegistrationSigner,
33227
- dataRegistryContractAddress,
33228
- dataRegistryDomain,
33229
33068
  decryptWithPassword,
33230
33069
  deriveMasterKey,
33231
33070
  deriveScopeKey,
33232
33071
  deserializeECIES,
33233
33072
  detectPlatform,
33234
- encodeDepositNativeData,
33235
- encodeDepositTokenData,
33236
- encodeSetDataPointStatusData,
33237
33073
  encryptWithPassword,
33238
- escrowContractAddress,
33239
- escrowPaymentDomain,
33074
+ fileDeletionDomain,
33075
+ fileRegistrationDomain,
33240
33076
  generatePkceVerifier,
33077
+ genericPaymentDomain,
33241
33078
  getAbi,
33242
33079
  getAllChains,
33243
33080
  getChainConfig,
33244
33081
  getContractAddress,
33245
33082
  getContractController,
33246
33083
  getContractInfo,
33247
- getFee,
33248
- getOpFee,
33249
33084
  getPlatformCapabilities,
33250
33085
  getServiceEndpoints,
33251
33086
  grantRegistrationDomain,
@@ -33257,12 +33092,11 @@ export {
33257
33092
  moksha,
33258
33093
  mokshaServices,
33259
33094
  mokshaTestnet2 as mokshaTestnet,
33095
+ parseGrantRegistrationPayload,
33260
33096
  parsePSError,
33261
33097
  parseScope,
33262
33098
  parseWeb3SignedHeader,
33263
- personalServerDataReadPath,
33264
33099
  personalServerRegistrationDomain,
33265
- readPersonalServerData,
33266
33100
  recoverServerOwner,
33267
33101
  registerPersonalServerSignature,
33268
33102
  scopeCoveredByGrant,