@opendatalabs/vana-sdk 3.4.0 → 3.4.1-canary.ba2cfd7

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 (37) hide show
  1. package/dist/index.browser.d.ts +5 -3
  2. package/dist/index.browser.js +353 -73
  3. package/dist/index.browser.js.map +3 -3
  4. package/dist/index.node.cjs +369 -74
  5. package/dist/index.node.cjs.map +4 -4
  6. package/dist/index.node.d.ts +5 -3
  7. package/dist/index.node.js +353 -73
  8. package/dist/index.node.js.map +3 -3
  9. package/dist/protocol/eip712.cjs +58 -3
  10. package/dist/protocol/eip712.cjs.map +1 -1
  11. package/dist/protocol/eip712.d.ts +98 -6
  12. package/dist/protocol/eip712.js +52 -3
  13. package/dist/protocol/eip712.js.map +1 -1
  14. package/dist/protocol/escrow-deposit.cjs +89 -0
  15. package/dist/protocol/escrow-deposit.cjs.map +1 -0
  16. package/dist/protocol/escrow-deposit.d.ts +47 -0
  17. package/dist/protocol/escrow-deposit.js +60 -0
  18. package/dist/protocol/escrow-deposit.js.map +1 -0
  19. package/dist/protocol/escrow-deposit.test.d.ts +1 -0
  20. package/dist/protocol/escrow-flow.test.d.ts +21 -0
  21. package/dist/protocol/fee-registry.cjs +116 -0
  22. package/dist/protocol/fee-registry.cjs.map +1 -0
  23. package/dist/protocol/fee-registry.d.ts +151 -0
  24. package/dist/protocol/fee-registry.js +89 -0
  25. package/dist/protocol/fee-registry.js.map +1 -0
  26. package/dist/protocol/fee-registry.test.d.ts +1 -0
  27. package/dist/protocol/gateway.cjs +130 -7
  28. package/dist/protocol/gateway.cjs.map +1 -1
  29. package/dist/protocol/gateway.d.ts +213 -16
  30. package/dist/protocol/gateway.js +130 -7
  31. package/dist/protocol/gateway.js.map +1 -1
  32. package/dist/protocol/grants.cjs +24 -64
  33. package/dist/protocol/grants.cjs.map +1 -1
  34. package/dist/protocol/grants.d.ts +6 -13
  35. package/dist/protocol/grants.js +24 -63
  36. package/dist/protocol/grants.js.map +1 -1
  37. package/package.json +3 -2
@@ -35,13 +35,15 @@ export { encryptWithPassword, decryptWithPassword, } from "./crypto/envelope/ope
35
35
  export { parseWeb3SignedHeader, verifyWeb3Signed, type Web3SignedPayload, type VerifiedAuth, } from "./auth/web3-signed";
36
36
  export { buildWeb3SignedHeader, computeBodyHash, type Web3SignedSignFn, } from "./auth/web3-signed-builder";
37
37
  export { MissingAuthError, InvalidSignatureError, ExpiredTokenError, } from "./auth/errors";
38
- export { fileRegistrationDomain, fileDeletionDomain, grantRegistrationDomain, grantRevocationDomain, serverRegistrationDomain, builderRegistrationDomain, FILE_REGISTRATION_TYPES, FILE_DELETION_TYPES, GRANT_REGISTRATION_TYPES, GRANT_REVOCATION_TYPES, SERVER_REGISTRATION_TYPES, BUILDER_REGISTRATION_TYPES, type DataPortabilityContracts, type DataPortabilityGatewayConfig, type FileRegistrationMessage, type FileDeletionMessage, type GrantRegistrationMessage, type GrantRevocationMessage, type ServerRegistrationMessage, type BuilderRegistrationMessage, } from "./protocol/eip712";
38
+ export { fileRegistrationDomain, fileDeletionDomain, grantRegistrationDomain, grantRevocationDomain, serverRegistrationDomain, builderRegistrationDomain, escrowPaymentDomain, dataRegistryDomain, FILE_REGISTRATION_TYPES, FILE_DELETION_TYPES, GRANT_REGISTRATION_TYPES, GRANT_REVOCATION_TYPES, SERVER_REGISTRATION_TYPES, BUILDER_REGISTRATION_TYPES, GENERIC_PAYMENT_TYPES, ADD_DATA_TYPES, RECORD_DATA_ACCESS_TYPES, NATIVE_VANA_ASSET, type DataPortabilityContracts, type DataPortabilityGatewayConfig, type FileRegistrationMessage, type FileDeletionMessage, type GrantRegistrationMessage, type GrantRevocationMessage, type ServerRegistrationMessage, type BuilderRegistrationMessage, type GenericPaymentMessage, type AddDataMessage, type RecordDataAccessMessage, } from "./protocol/eip712";
39
39
  export { PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID, PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT, personalServerRegistrationDomain, createViemPersonalServerRegistrationSigner, buildPersonalServerRegistrationTypedData, buildPersonalServerRegistrationSignature, registerPersonalServerSignature, type PersonalServerRegistrationTypedData, type PersonalServerRegistrationSigner, type PersonalServerRegistrationDomainInput, type ViemPersonalServerRegistrationWalletClient, type ViemPersonalServerRegistrationSignerSource, type BuildPersonalServerRegistrationTypedDataInput, type BuildPersonalServerRegistrationSignatureInput, type PersonalServerRegistrationSignature, } from "./protocol/personal-server-registration";
40
40
  export { PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION, PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE, PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX, buildPersonalServerLiteOwnerBindingMessage, createViemPersonalServerLiteOwnerBindingSigner, buildPersonalServerLiteOwnerBindingSignature, signPersonalServerLiteOwnerBinding, type PersonalServerLiteOwnerBindingPurpose, type PersonalServerLiteOwnerBindingMessage, type PersonalServerLiteOwnerBindingSigner, type ViemPersonalServerLiteOwnerBindingWalletClient, type ViemPersonalServerLiteOwnerBindingSignerSource, type BuildPersonalServerLiteOwnerBindingSignatureInput, type PersonalServerLiteOwnerBindingSignature, } from "./protocol/personal-server-lite-owner-binding";
41
41
  export { ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT, AccountPersonalServerRegistrationError, signPersonalServerRegistrationWithAccount, type AccountPersonalServerRegistrationIntent, type AccountPersonalServerRegistrationSignature, type AccountPersonalServerRegistrationStatus, type AccountPersonalServerRegistrationRequest, type AccountPersonalServerRegistrationConfig, type AccountSignedPersonalServerRegistration, type AccountConfirmationRequiredPersonalServerRegistration, type AccountFallbackSignedPersonalServerRegistration, type AccountPersonalServerRegistrationResult, } from "./account/personal-server-registration";
42
42
  export { AccountPersonalServerLiteOwnerBindingError, signPersonalServerLiteOwnerBindingWithAccountClient, type AccountPersonalServerLiteOwnerBindingClient, type SignPersonalServerLiteOwnerBindingWithAccountClientConfig, } from "./account/personal-server-lite-owner-binding";
43
- export { isDataPortabilityGatewayConfig, parseGrantRegistrationPayload, verifyGrantRegistration, type DataPortabilityGrantPayload, type VerifyGrantRegistrationInput, type VerifyGrantRegistrationResult, } from "./protocol/grants";
43
+ export { isDataPortabilityGatewayConfig, verifyGrantRegistration, type VerifyGrantRegistrationInput, type VerifyGrantRegistrationResult, } from "./protocol/grants";
44
+ export { ESCROW_DEPOSIT_ABI, escrowContractAddress, encodeDepositNativeData, encodeDepositTokenData, buildDepositNativeRequest, buildDepositTokenRequest, type DepositNativeInput, type DepositTokenInput, type DepositTransactionRequest, } from "./protocol/escrow-deposit";
45
+ export { FEE_REGISTRY_ABI, REGISTRATION_KIND_FOR_OP, getFee, getOpFee, type FeeKind, type FeeEntry, type OpFee, type FeeRegistryOptions, } from "./protocol/fee-registry";
44
46
  export { ScopeSchema, parseScope, scopeToPathSegments, scopeMatchesPattern, scopeCoveredByGrant, type Scope, type ParsedScope, } from "./protocol/scopes";
45
47
  export { DataFileEnvelopeSchema, createDataFileEnvelope, IngestResponseSchema, type DataFileEnvelope, type IngestResponse, } from "./protocol/data-file";
46
- export { createGatewayClient, type GatewayEnvelope, type GatewayProof, type Builder, type Schema, type ServerInfo, type GatewayGrantResponse, type GrantListItem, type FileRecord, type FileListResult, type ListFilesOptions, type RegisterServerParams, type RegisterServerResult, type RegisterFileParams, type CreateGrantParams, type RevokeGrantParams, type DeleteFileParams, type GatewayClient, } from "./protocol/gateway";
48
+ export { createGatewayClient, type GatewayEnvelope, type GatewayProof, type Builder, type Schema, type ServerInfo, type GatewayGrantResponse, type GatewayGrantStatus, type GatewayGrantFee, type GrantListItem, type FileRecord, type FileListResult, type ListFilesOptions, type RegisterServerParams, type RegisterServerResult, type RegisterFileParams, type RegisterBuilderParams, type RegisterBuilderResult, type RegisterDataPointParams, type RegisterDataPointResult, type CreateGrantParams, type RevokeGrantParams, type PayForOperationParams, type PayForOperationResult, type AccessRecord, type SettleOpType, type SettleItem, type SettlePromoteResult, type SettleReconcileItem, type SettleParams, type SettleResult, type SubmitDepositParams, type DepositState, type EscrowBalance, type EscrowBalanceEntry, type EscrowDepositSubmitted, type EscrowDepositFinalized, type EscrowDepositFailed, type DeleteFileParams, type GatewayClient, } from "./protocol/gateway";
47
49
  export { PSError, parsePSError, type PSErrorCode } from "./types/ps-errors";
@@ -31882,6 +31882,7 @@ 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";
31885
31886
  function buildDomain(chainId, verifyingContract) {
31886
31887
  return {
31887
31888
  name: DOMAIN_NAME,
@@ -31896,6 +31897,12 @@ function fileRegistrationDomain(config) {
31896
31897
  config.contracts.dataRegistry
31897
31898
  );
31898
31899
  }
31900
+ function dataRegistryDomain(config) {
31901
+ return buildDomain(
31902
+ config.chainId,
31903
+ config.contracts.dataRegistry
31904
+ );
31905
+ }
31899
31906
  function fileDeletionDomain(config) {
31900
31907
  return buildDomain(
31901
31908
  config.chainId,
@@ -31926,6 +31933,12 @@ function builderRegistrationDomain(config) {
31926
31933
  config.contracts.dataPortabilityGrantees
31927
31934
  );
31928
31935
  }
31936
+ function escrowPaymentDomain(config) {
31937
+ return buildDomain(
31938
+ config.chainId,
31939
+ config.contracts.dataPortabilityEscrow
31940
+ );
31941
+ }
31929
31942
  var FILE_REGISTRATION_TYPES = {
31930
31943
  FileRegistration: [
31931
31944
  { name: "ownerAddress", type: "address" },
@@ -31943,14 +31956,16 @@ var GRANT_REGISTRATION_TYPES = {
31943
31956
  GrantRegistration: [
31944
31957
  { name: "grantorAddress", type: "address" },
31945
31958
  { name: "granteeId", type: "bytes32" },
31946
- { name: "grant", type: "string" },
31947
- { name: "fileIds", type: "uint256[]" }
31959
+ { name: "scopes", type: "string[]" },
31960
+ { name: "grantVersion", type: "uint256" },
31961
+ { name: "expiresAt", type: "uint256" }
31948
31962
  ]
31949
31963
  };
31950
31964
  var GRANT_REVOCATION_TYPES = {
31951
31965
  GrantRevocation: [
31952
31966
  { name: "grantorAddress", type: "address" },
31953
- { name: "grantId", type: "bytes32" }
31967
+ { name: "grantId", type: "bytes32" },
31968
+ { name: "grantVersion", type: "uint256" }
31954
31969
  ]
31955
31970
  };
31956
31971
  var SERVER_REGISTRATION_TYPES = {
@@ -31969,6 +31984,34 @@ var BUILDER_REGISTRATION_TYPES = {
31969
31984
  { name: "appUrl", type: "string" }
31970
31985
  ]
31971
31986
  };
31987
+ var GENERIC_PAYMENT_TYPES = {
31988
+ GenericPayment: [
31989
+ { name: "payerAddress", type: "address" },
31990
+ { name: "opType", type: "string" },
31991
+ { name: "opId", type: "bytes32" },
31992
+ { name: "asset", type: "address" },
31993
+ { name: "amount", type: "uint256" },
31994
+ { name: "paymentNonce", type: "uint256" }
31995
+ ]
31996
+ };
31997
+ var ADD_DATA_TYPES = {
31998
+ AddData: [
31999
+ { name: "ownerAddress", type: "address" },
32000
+ { name: "scope", type: "string" },
32001
+ { name: "dataHash", type: "bytes32" },
32002
+ { name: "metadataHash", type: "bytes32" },
32003
+ { name: "expectedVersion", type: "uint256" }
32004
+ ]
32005
+ };
32006
+ var RECORD_DATA_ACCESS_TYPES = {
32007
+ RecordDataAccess: [
32008
+ { name: "ownerAddress", type: "address" },
32009
+ { name: "scope", type: "string" },
32010
+ { name: "version", type: "uint256" },
32011
+ { name: "accessor", type: "address" },
32012
+ { name: "recordId", type: "bytes32" }
32013
+ ]
32014
+ };
31972
32015
 
31973
32016
  // src/protocol/personal-server-registration.ts
31974
32017
  import {
@@ -32410,67 +32453,31 @@ function isDataPortabilityGatewayConfig(value) {
32410
32453
  return false;
32411
32454
  }
32412
32455
  const c = contracts;
32413
- return isHexString(c["dataRegistry"]) && isHexString(c["dataPortabilityPermissions"]) && isHexString(c["dataPortabilityServer"]) && isHexString(c["dataPortabilityGrantees"]);
32456
+ return isHexString(c["dataRegistry"]) && isHexString(c["dataPortabilityPermissions"]) && isHexString(c["dataPortabilityServer"]) && isHexString(c["dataPortabilityGrantees"]) && isHexString(c["dataPortabilityEscrow"]) && isHexString(c["feeRegistry"]);
32414
32457
  }
32415
- function parseGrantRegistrationPayload(grant) {
32416
- let parsed;
32458
+ function toUint256(value) {
32417
32459
  try {
32418
- parsed = JSON.parse(grant);
32419
- } catch {
32420
- return null;
32421
- }
32422
- if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
32423
- return null;
32424
- }
32425
- const value = parsed;
32426
- if (!Array.isArray(value["scopes"]) || value["scopes"].length === 0) {
32427
- return null;
32428
- }
32429
- if (!value["scopes"].every((scope) => typeof scope === "string")) {
32430
- return null;
32431
- }
32432
- if (typeof value["expiresAt"] !== "number" || !Number.isFinite(value["expiresAt"])) {
32433
- return null;
32434
- }
32435
- if (value["user"] !== void 0 && !isHexString(value["user"])) {
32436
- return null;
32437
- }
32438
- if (value["builder"] !== void 0 && !isHexString(value["builder"])) {
32439
- return null;
32440
- }
32441
- if (value["nonce"] !== void 0 && (typeof value["nonce"] !== "number" || !Number.isFinite(value["nonce"]))) {
32442
- return null;
32443
- }
32444
- return {
32445
- user: value["user"],
32446
- builder: value["builder"],
32447
- scopes: value["scopes"],
32448
- expiresAt: value["expiresAt"],
32449
- nonce: value["nonce"]
32450
- };
32451
- }
32452
- function parseFileIds(fileIds) {
32453
- try {
32454
- const values = (fileIds ?? []).map((fileId) => BigInt(fileId));
32455
- return {
32456
- values,
32457
- display: values.map((fileId) => fileId.toString())
32458
- };
32460
+ const big = typeof value === "bigint" ? value : BigInt(value);
32461
+ if (big < 0n) return null;
32462
+ return big;
32459
32463
  } catch {
32460
32464
  return null;
32461
32465
  }
32462
32466
  }
32463
32467
  async function verifyGrantRegistration(input) {
32464
- const payload = parseGrantRegistrationPayload(input.grant);
32465
- if (!payload) {
32466
- return {
32467
- valid: false,
32468
- error: "Grant must be JSON with scopes and expiresAt"
32469
- };
32468
+ if (!Array.isArray(input.scopes) || input.scopes.length === 0) {
32469
+ return { valid: false, error: "scopes must be a non-empty array" };
32470
+ }
32471
+ if (!input.scopes.every((scope) => typeof scope === "string")) {
32472
+ return { valid: false, error: "scopes must contain only strings" };
32473
+ }
32474
+ const grantVersion = toUint256(input.grantVersion);
32475
+ if (grantVersion === null || grantVersion < 1n) {
32476
+ return { valid: false, error: "grantVersion must be a uint256 >= 1" };
32470
32477
  }
32471
- const fileIds = parseFileIds(input.fileIds);
32472
- if (!fileIds) {
32473
- return { valid: false, error: "fileIds must contain integer values" };
32478
+ const expiresAt = toUint256(input.expiresAt);
32479
+ if (expiresAt === null) {
32480
+ return { valid: false, error: "expiresAt must be a non-negative uint256" };
32474
32481
  }
32475
32482
  let valid;
32476
32483
  try {
@@ -32482,8 +32489,9 @@ async function verifyGrantRegistration(input) {
32482
32489
  message: {
32483
32490
  grantorAddress: input.grantorAddress,
32484
32491
  granteeId: input.granteeId,
32485
- grant: input.grant,
32486
- fileIds: fileIds.values
32492
+ scopes: input.scopes,
32493
+ grantVersion,
32494
+ expiresAt
32487
32495
  },
32488
32496
  signature: input.signature
32489
32497
  });
@@ -32494,19 +32502,153 @@ async function verifyGrantRegistration(input) {
32494
32502
  return { valid: false, error: "Grant signature does not match grantor" };
32495
32503
  }
32496
32504
  const nowSeconds = input.nowSeconds ?? Math.floor(Date.now() / 1e3);
32497
- if (payload.expiresAt > 0 && payload.expiresAt < nowSeconds) {
32505
+ if (expiresAt > 0n && expiresAt < BigInt(nowSeconds)) {
32498
32506
  return { valid: false, error: "Grant has expired" };
32499
32507
  }
32500
- if (payload.user !== void 0 && payload.user.toLowerCase() !== input.grantorAddress.toLowerCase()) {
32501
- return { valid: false, error: "Grant user does not match grantorAddress" };
32502
- }
32503
32508
  return {
32504
32509
  valid: true,
32505
32510
  grantorAddress: input.grantorAddress,
32506
32511
  granteeId: input.granteeId,
32507
- grant: input.grant,
32508
- payload,
32509
- fileIds: fileIds.display
32512
+ scopes: input.scopes,
32513
+ grantVersion: grantVersion.toString(),
32514
+ expiresAt: expiresAt.toString()
32515
+ };
32516
+ }
32517
+
32518
+ // src/protocol/escrow-deposit.ts
32519
+ import { encodeFunctionData } from "viem";
32520
+ var ESCROW_DEPOSIT_ABI = [
32521
+ {
32522
+ type: "function",
32523
+ name: "depositNative",
32524
+ stateMutability: "payable",
32525
+ inputs: [{ name: "account", type: "address" }],
32526
+ outputs: []
32527
+ },
32528
+ {
32529
+ type: "function",
32530
+ name: "depositToken",
32531
+ stateMutability: "nonpayable",
32532
+ inputs: [
32533
+ { name: "account", type: "address" },
32534
+ { name: "token", type: "address" },
32535
+ { name: "amount", type: "uint256" }
32536
+ ],
32537
+ outputs: []
32538
+ }
32539
+ ];
32540
+ function escrowContractAddress(config) {
32541
+ return config.contracts.dataPortabilityEscrow;
32542
+ }
32543
+ function encodeDepositNativeData(input) {
32544
+ return encodeFunctionData({
32545
+ abi: ESCROW_DEPOSIT_ABI,
32546
+ functionName: "depositNative",
32547
+ args: [input.account]
32548
+ });
32549
+ }
32550
+ function encodeDepositTokenData(input) {
32551
+ return encodeFunctionData({
32552
+ abi: ESCROW_DEPOSIT_ABI,
32553
+ functionName: "depositToken",
32554
+ args: [input.account, input.token, input.amount]
32555
+ });
32556
+ }
32557
+ function buildDepositNativeRequest(config, input) {
32558
+ return {
32559
+ to: escrowContractAddress(config),
32560
+ data: encodeDepositNativeData({ account: input.account }),
32561
+ value: input.amount
32562
+ };
32563
+ }
32564
+ function buildDepositTokenRequest(config, input) {
32565
+ return {
32566
+ to: escrowContractAddress(config),
32567
+ data: encodeDepositTokenData(input)
32568
+ };
32569
+ }
32570
+
32571
+ // src/protocol/fee-registry.ts
32572
+ import { parseAbi } from "viem";
32573
+ var FEE_REGISTRY_ABI = parseAbi([
32574
+ "struct Fee { uint256 amount; address asset; address payee; bool enabled; }",
32575
+ "function fees(bytes32 operation) view returns (Fee)",
32576
+ "function operationKey(string name) pure returns (bytes32)"
32577
+ ]);
32578
+ var REGISTRATION_KIND_FOR_OP = {
32579
+ grant: "grant_registration",
32580
+ data: "data_registration",
32581
+ server: "server_registration",
32582
+ builder: "builder_registration"
32583
+ };
32584
+ function operationNameFor(kind, opts) {
32585
+ switch (kind) {
32586
+ case "grant_registration":
32587
+ return opts?.grantRegistrationOpName ?? "grant_registration";
32588
+ case "data_access":
32589
+ return opts?.dataAccessOpName ?? "data_access";
32590
+ case "data_registration":
32591
+ return opts?.dataRegistrationOpName ?? "data_registration";
32592
+ case "server_registration":
32593
+ return opts?.serverRegistrationOpName ?? "server_registration";
32594
+ case "builder_registration":
32595
+ return opts?.builderRegistrationOpName ?? "builder_registration";
32596
+ }
32597
+ }
32598
+ var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
32599
+ async function getFee(client, config, kind, opts) {
32600
+ const address = config.contracts.feeRegistry;
32601
+ const opName = operationNameFor(kind, opts);
32602
+ const opKey = await client.readContract({
32603
+ address,
32604
+ abi: FEE_REGISTRY_ABI,
32605
+ functionName: "operationKey",
32606
+ args: [opName]
32607
+ });
32608
+ const fee = await client.readContract({
32609
+ address,
32610
+ abi: FEE_REGISTRY_ABI,
32611
+ functionName: "fees",
32612
+ args: [opKey]
32613
+ });
32614
+ if (fee.enabled && fee.payee === ZERO_ADDRESS) {
32615
+ throw new Error(
32616
+ `FeeRegistry: enabled operation "${opName}" has zero-address payee \u2014 contract pre-flight rejects payouts to 0x0`
32617
+ );
32618
+ }
32619
+ return fee;
32620
+ }
32621
+ async function getOpFee(client, config, opType, opts) {
32622
+ const registrationKind = REGISTRATION_KIND_FOR_OP[opType];
32623
+ if (!registrationKind) {
32624
+ throw new Error(
32625
+ `getOpFee: unknown opType "${opType}" \u2014 supported types are ${Object.keys(REGISTRATION_KIND_FOR_OP).join(", ")}`
32626
+ );
32627
+ }
32628
+ const includeDataAccess = opType === "grant";
32629
+ const [registration, dataAccess] = await Promise.all([
32630
+ getFee(client, config, registrationKind, opts),
32631
+ includeDataAccess ? getFee(client, config, "data_access", opts) : Promise.resolve({
32632
+ amount: 0n,
32633
+ asset: ZERO_ADDRESS,
32634
+ payee: ZERO_ADDRESS,
32635
+ enabled: false
32636
+ })
32637
+ ]);
32638
+ if (registration.enabled && dataAccess.enabled && registration.asset.toLowerCase() !== dataAccess.asset.toLowerCase()) {
32639
+ throw new Error(
32640
+ `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.`
32641
+ );
32642
+ }
32643
+ const asset = registration.enabled ? registration.asset : dataAccess.enabled ? dataAccess.asset : ZERO_ADDRESS;
32644
+ return {
32645
+ asset,
32646
+ registrationFee: registration.enabled ? registration.amount : 0n,
32647
+ dataAccessFee: dataAccess.enabled ? dataAccess.amount : 0n,
32648
+ registrationEnabled: registration.enabled,
32649
+ dataAccessEnabled: dataAccess.enabled,
32650
+ registrationPayee: registration.enabled ? registration.payee : ZERO_ADDRESS,
32651
+ dataAccessPayee: dataAccess.enabled ? dataAccess.payee : ZERO_ADDRESS
32510
32652
  };
32511
32653
  }
32512
32654
 
@@ -32657,7 +32799,7 @@ function createGatewayClient(baseUrl) {
32657
32799
  async listFilesSince(owner, cursor, options) {
32658
32800
  const params = new URLSearchParams({ user: owner });
32659
32801
  if (cursor !== null) {
32660
- params.set("since", cursor);
32802
+ params.set("cursor", cursor);
32661
32803
  }
32662
32804
  if (options?.includeDeleted) {
32663
32805
  params.set("includeDeleted", "true");
@@ -32666,10 +32808,12 @@ function createGatewayClient(baseUrl) {
32666
32808
  if (!res.ok) {
32667
32809
  throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
32668
32810
  }
32669
- const data = await unwrapEnvelope(res);
32811
+ const envelope = await res.json();
32812
+ const { pagination } = envelope;
32813
+ const nextCursor = pagination?.hasMore === false ? null : pagination?.nextCursor ?? envelope.data.cursor ?? null;
32670
32814
  return {
32671
- files: data.files.map(normalizeFileRecord),
32672
- cursor: data.cursor
32815
+ files: envelope.data.files.map(normalizeFileRecord),
32816
+ cursor: nextCursor
32673
32817
  };
32674
32818
  },
32675
32819
  async getSchema(schemaId) {
@@ -32710,6 +32854,68 @@ function createGatewayClient(baseUrl) {
32710
32854
  alreadyRegistered: false
32711
32855
  };
32712
32856
  },
32857
+ async registerBuilder(params) {
32858
+ const res = await fetch(`${base}/v1/builders`, {
32859
+ method: "POST",
32860
+ headers: {
32861
+ "Content-Type": "application/json",
32862
+ Authorization: `Web3Signed ${params.signature}`
32863
+ },
32864
+ body: JSON.stringify({
32865
+ ownerAddress: params.ownerAddress,
32866
+ granteeAddress: params.granteeAddress,
32867
+ publicKey: params.publicKey,
32868
+ appUrl: params.appUrl
32869
+ })
32870
+ });
32871
+ if (res.status === 409) {
32872
+ const body2 = await res.json().catch(() => ({}));
32873
+ return {
32874
+ builderId: getMutationId(
32875
+ body2,
32876
+ "builderId"
32877
+ ),
32878
+ alreadyRegistered: true
32879
+ };
32880
+ }
32881
+ if (!res.ok) {
32882
+ throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
32883
+ }
32884
+ const body = await res.json().catch(() => ({}));
32885
+ return {
32886
+ builderId: getMutationId(body, "builderId"),
32887
+ alreadyRegistered: false
32888
+ };
32889
+ },
32890
+ async registerDataPoint(params) {
32891
+ const res = await fetch(`${base}/v1/data`, {
32892
+ method: "POST",
32893
+ headers: {
32894
+ "Content-Type": "application/json",
32895
+ Authorization: `Web3Signed ${params.signature}`
32896
+ },
32897
+ body: JSON.stringify({
32898
+ ownerAddress: params.ownerAddress,
32899
+ scope: params.scope,
32900
+ dataHash: params.dataHash,
32901
+ metadataHash: params.metadataHash,
32902
+ expectedVersion: params.expectedVersion
32903
+ })
32904
+ });
32905
+ if (!res.ok) {
32906
+ const body2 = await res.json().catch(() => ({}));
32907
+ const detail = body2.error ?? res.statusText;
32908
+ throw new Error(`Gateway error: ${res.status} ${detail}`);
32909
+ }
32910
+ const body = await res.json().catch(() => ({}));
32911
+ return {
32912
+ dataPointId: getMutationId(
32913
+ body,
32914
+ "dataPointId"
32915
+ ),
32916
+ expectedVersion: body.expectedVersion
32917
+ };
32918
+ },
32713
32919
  async registerFile(params) {
32714
32920
  const res = await fetch(`${base}/v1/files`, {
32715
32921
  method: "POST",
@@ -32747,8 +32953,9 @@ function createGatewayClient(baseUrl) {
32747
32953
  body: JSON.stringify({
32748
32954
  grantorAddress: params.grantorAddress,
32749
32955
  granteeId: params.granteeId,
32750
- grant: params.grant,
32751
- fileIds: params.fileIds
32956
+ scopes: params.scopes,
32957
+ grantVersion: params.grantVersion,
32958
+ expiresAt: params.expiresAt
32752
32959
  })
32753
32960
  });
32754
32961
  if (res.status === 409) {
@@ -32773,7 +32980,8 @@ function createGatewayClient(baseUrl) {
32773
32980
  Authorization: `Web3Signed ${params.signature}`
32774
32981
  },
32775
32982
  body: JSON.stringify({
32776
- grantorAddress: params.grantorAddress
32983
+ grantorAddress: params.grantorAddress,
32984
+ grantVersion: params.grantVersion
32777
32985
  })
32778
32986
  });
32779
32987
  if (res.status === 409) return;
@@ -32781,6 +32989,63 @@ function createGatewayClient(baseUrl) {
32781
32989
  throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
32782
32990
  }
32783
32991
  },
32992
+ async getEscrowBalance(account) {
32993
+ const res = await fetch(`${base}/v1/escrow/balance?account=${account}`);
32994
+ if (!res.ok) {
32995
+ throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
32996
+ }
32997
+ return await res.json();
32998
+ },
32999
+ async submitEscrowDeposit(params) {
33000
+ const res = await fetch(`${base}/v1/escrow/deposit`, {
33001
+ method: "POST",
33002
+ headers: { "Content-Type": "application/json" },
33003
+ body: JSON.stringify({ txHash: params.txHash })
33004
+ });
33005
+ if (res.status !== 200 && res.status !== 202) {
33006
+ throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
33007
+ }
33008
+ return await res.json();
33009
+ },
33010
+ async payForOperation(params) {
33011
+ const body = {
33012
+ payerAddress: params.payerAddress,
33013
+ opType: params.opType,
33014
+ opId: params.opId,
33015
+ asset: params.asset,
33016
+ amount: params.amount,
33017
+ paymentNonce: params.paymentNonce
33018
+ };
33019
+ if (params.accessRecord) {
33020
+ body["accessRecord"] = params.accessRecord;
33021
+ }
33022
+ const res = await fetch(`${base}/v1/escrow/pay`, {
33023
+ method: "POST",
33024
+ headers: {
33025
+ "Content-Type": "application/json",
33026
+ Authorization: `Web3Signed ${params.signature}`
33027
+ },
33028
+ body: JSON.stringify(body)
33029
+ });
33030
+ if (!res.ok) {
33031
+ throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
33032
+ }
33033
+ return await res.json();
33034
+ },
33035
+ async settle(params) {
33036
+ const res = await fetch(`${base}/v1/settle`, {
33037
+ method: "POST",
33038
+ headers: { "Content-Type": "application/json" },
33039
+ // The gateway accepts an empty body; only `limit` is recognised.
33040
+ // Always send a JSON body so the gateway's req.body shape parse
33041
+ // doesn't have to deal with an undefined.
33042
+ body: JSON.stringify(params ?? {})
33043
+ });
33044
+ if (!res.ok) {
33045
+ throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
33046
+ }
33047
+ return await res.json();
33048
+ },
32784
33049
  async deleteFile(params) {
32785
33050
  const res = await fetch(`${base}/v1/files/${params.fileId}`, {
32786
33051
  method: "DELETE",
@@ -32864,6 +33129,7 @@ async function parsePSError(response) {
32864
33129
  }
32865
33130
  export {
32866
33131
  ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT,
33132
+ ADD_DATA_TYPES,
32867
33133
  AccountPersonalServerLiteOwnerBindingError,
32868
33134
  AccountPersonalServerRegistrationError,
32869
33135
  BUILDER_REGISTRATION_TYPES,
@@ -32877,9 +33143,12 @@ export {
32877
33143
  DataFileEnvelopeSchema,
32878
33144
  DropboxStorage,
32879
33145
  ECIESError,
33146
+ ESCROW_DEPOSIT_ABI,
32880
33147
  ExpiredTokenError,
33148
+ FEE_REGISTRY_ABI,
32881
33149
  FILE_DELETION_TYPES,
32882
33150
  FILE_REGISTRATION_TYPES,
33151
+ GENERIC_PAYMENT_TYPES,
32883
33152
  GRANT_REGISTRATION_TYPES,
32884
33153
  GRANT_REVOCATION_TYPES,
32885
33154
  GoogleDriveStorage,
@@ -32890,6 +33159,7 @@ export {
32890
33159
  IpfsStorage,
32891
33160
  MASTER_KEY_MESSAGE,
32892
33161
  MissingAuthError,
33162
+ NATIVE_VANA_ASSET,
32893
33163
  NetworkError,
32894
33164
  NonceError,
32895
33165
  OAuthClient,
@@ -32905,6 +33175,8 @@ export {
32905
33175
  PersonalServerError,
32906
33176
  PinataStorage,
32907
33177
  R2Storage,
33178
+ RECORD_DATA_ACCESS_TYPES,
33179
+ REGISTRATION_KIND_FOR_OP,
32908
33180
  ReadOnlyError,
32909
33181
  RelayerError,
32910
33182
  SERVER_REGISTRATION_TYPES,
@@ -32919,6 +33191,8 @@ export {
32919
33191
  VanaError,
32920
33192
  VanaStorage,
32921
33193
  assertValidPkceVerifier,
33194
+ buildDepositNativeRequest,
33195
+ buildDepositTokenRequest,
32922
33196
  buildPersonalServerLiteOwnerBindingMessage,
32923
33197
  buildPersonalServerLiteOwnerBindingSignature,
32924
33198
  buildPersonalServerRegistrationSignature,
@@ -32937,12 +33211,17 @@ export {
32937
33211
  createVanaStorageProvider,
32938
33212
  createViemPersonalServerLiteOwnerBindingSigner,
32939
33213
  createViemPersonalServerRegistrationSigner,
33214
+ dataRegistryDomain,
32940
33215
  decryptWithPassword,
32941
33216
  deriveMasterKey,
32942
33217
  deriveScopeKey,
32943
33218
  deserializeECIES,
32944
33219
  detectPlatform,
33220
+ encodeDepositNativeData,
33221
+ encodeDepositTokenData,
32945
33222
  encryptWithPassword,
33223
+ escrowContractAddress,
33224
+ escrowPaymentDomain,
32946
33225
  fileDeletionDomain,
32947
33226
  fileRegistrationDomain,
32948
33227
  generatePkceVerifier,
@@ -32952,6 +33231,8 @@ export {
32952
33231
  getContractAddress,
32953
33232
  getContractController,
32954
33233
  getContractInfo,
33234
+ getFee,
33235
+ getOpFee,
32955
33236
  getPlatformCapabilities,
32956
33237
  getServiceEndpoints,
32957
33238
  grantRegistrationDomain,
@@ -32963,7 +33244,6 @@ export {
32963
33244
  moksha,
32964
33245
  mokshaServices,
32965
33246
  mokshaTestnet2 as mokshaTestnet,
32966
- parseGrantRegistrationPayload,
32967
33247
  parsePSError,
32968
33248
  parseScope,
32969
33249
  parseWeb3SignedHeader,