@opendatalabs/vana-sdk 3.1.0 → 3.2.0-canary.255a8bf

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 (103) hide show
  1. package/README.md +2 -1
  2. package/dist/account/personal-server-lite-owner-binding.cjs +81 -0
  3. package/dist/account/personal-server-lite-owner-binding.cjs.map +1 -0
  4. package/dist/account/personal-server-lite-owner-binding.d.ts +30 -0
  5. package/dist/account/personal-server-lite-owner-binding.js +59 -0
  6. package/dist/account/personal-server-lite-owner-binding.js.map +1 -0
  7. package/dist/account/personal-server-lite-owner-binding.test.d.ts +1 -0
  8. package/dist/account/personal-server-registration.cjs +263 -0
  9. package/dist/account/personal-server-registration.cjs.map +1 -0
  10. package/dist/account/personal-server-registration.d.ts +66 -0
  11. package/dist/account/personal-server-registration.js +240 -0
  12. package/dist/account/personal-server-registration.js.map +1 -0
  13. package/dist/account/personal-server-registration.test.d.ts +1 -0
  14. package/dist/auth/errors.js +1 -1
  15. package/dist/auth/oauth-client.js +2 -2
  16. package/dist/auth/web3-signed-builder.js +1 -1
  17. package/dist/auth/web3-signed.js +3 -3
  18. package/dist/browser.js +1 -1
  19. package/dist/chains/definitions.js +1 -1
  20. package/dist/chains/index.js +1 -1
  21. package/dist/chains.browser.js +1 -1
  22. package/dist/chains.js +1 -1
  23. package/dist/chains.node.js +1 -1
  24. package/dist/contracts/contractController.js +4 -4
  25. package/dist/core/client.js +1 -1
  26. package/dist/crypto/ecies/base.js +3 -3
  27. package/dist/crypto/ecies/browser.js +1 -1
  28. package/dist/crypto/ecies/index.js +1 -1
  29. package/dist/crypto/ecies/interface.js +1 -1
  30. package/dist/crypto/ecies/node.js +1 -1
  31. package/dist/crypto/services/WalletKeyEncryptionService.js +1 -1
  32. package/dist/generated/abi/index.js +26 -26
  33. package/dist/index.browser.d.ts +9 -3
  34. package/dist/index.browser.js +768 -72
  35. package/dist/index.browser.js.map +4 -4
  36. package/dist/index.node.cjs +798 -73
  37. package/dist/index.node.cjs.map +4 -4
  38. package/dist/index.node.d.ts +9 -3
  39. package/dist/index.node.js +768 -72
  40. package/dist/index.node.js.map +4 -4
  41. package/dist/node.js +1 -1
  42. package/dist/platform/browser-only.js +1 -1
  43. package/dist/platform/browser-safe.js +1 -1
  44. package/dist/platform/browser.js +6 -6
  45. package/dist/platform/index.js +4 -4
  46. package/dist/platform/node.js +8 -8
  47. package/dist/platform/utils.js +2 -2
  48. package/dist/platform.browser.js +3 -3
  49. package/dist/platform.js +4 -4
  50. package/dist/platform.node.js +4 -4
  51. package/dist/protocol/eip712.cjs +58 -3
  52. package/dist/protocol/eip712.cjs.map +1 -1
  53. package/dist/protocol/eip712.d.ts +99 -7
  54. package/dist/protocol/eip712.js +52 -3
  55. package/dist/protocol/eip712.js.map +1 -1
  56. package/dist/protocol/escrow-deposit.cjs +89 -0
  57. package/dist/protocol/escrow-deposit.cjs.map +1 -0
  58. package/dist/protocol/escrow-deposit.d.ts +47 -0
  59. package/dist/protocol/escrow-deposit.js +60 -0
  60. package/dist/protocol/escrow-deposit.js.map +1 -0
  61. package/dist/protocol/escrow-deposit.test.d.ts +1 -0
  62. package/dist/protocol/escrow-flow.test.d.ts +21 -0
  63. package/dist/protocol/fee-registry.cjs +89 -0
  64. package/dist/protocol/fee-registry.cjs.map +1 -0
  65. package/dist/protocol/fee-registry.d.ts +105 -0
  66. package/dist/protocol/fee-registry.js +63 -0
  67. package/dist/protocol/fee-registry.js.map +1 -0
  68. package/dist/protocol/fee-registry.test.d.ts +1 -0
  69. package/dist/protocol/gateway.cjs +124 -3
  70. package/dist/protocol/gateway.cjs.map +1 -1
  71. package/dist/protocol/gateway.d.ts +196 -16
  72. package/dist/protocol/gateway.js +124 -3
  73. package/dist/protocol/gateway.js.map +1 -1
  74. package/dist/protocol/grants.cjs +24 -64
  75. package/dist/protocol/grants.cjs.map +1 -1
  76. package/dist/protocol/grants.d.ts +6 -13
  77. package/dist/protocol/grants.js +25 -64
  78. package/dist/protocol/grants.js.map +1 -1
  79. package/dist/protocol/personal-server-lite-owner-binding.cjs +93 -0
  80. package/dist/protocol/personal-server-lite-owner-binding.cjs.map +1 -0
  81. package/dist/protocol/personal-server-lite-owner-binding.d.ts +44 -0
  82. package/dist/protocol/personal-server-lite-owner-binding.js +65 -0
  83. package/dist/protocol/personal-server-lite-owner-binding.js.map +1 -0
  84. package/dist/protocol/personal-server-lite-owner-binding.test.d.ts +1 -0
  85. package/dist/protocol/personal-server-registration.cjs +122 -0
  86. package/dist/protocol/personal-server-registration.cjs.map +1 -0
  87. package/dist/protocol/personal-server-registration.d.ts +62 -0
  88. package/dist/protocol/personal-server-registration.js +97 -0
  89. package/dist/protocol/personal-server-registration.js.map +1 -0
  90. package/dist/protocol/personal-server-registration.test.d.ts +1 -0
  91. package/dist/storage/default.js +1 -1
  92. package/dist/storage/index.js +10 -10
  93. package/dist/storage/manager.js +1 -1
  94. package/dist/storage/providers/callback-storage.js +1 -1
  95. package/dist/storage/providers/dropbox.js +1 -1
  96. package/dist/storage/providers/google-drive.js +1 -1
  97. package/dist/storage/providers/ipfs.js +2 -2
  98. package/dist/storage/providers/pinata.js +1 -1
  99. package/dist/storage/providers/r2.js +1 -1
  100. package/dist/storage/providers/vana-storage.js +2 -2
  101. package/dist/types/index.js +2 -2
  102. package/dist/types.js +1 -1
  103. package/package.json +6 -3
@@ -1173,6 +1173,10 @@ var init_browser2 = __esm({
1173
1173
  // src/index.node.ts
1174
1174
  var index_node_exports = {};
1175
1175
  __export(index_node_exports, {
1176
+ ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT: () => ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT,
1177
+ ADD_DATA_TYPES: () => ADD_DATA_TYPES,
1178
+ AccountPersonalServerLiteOwnerBindingError: () => AccountPersonalServerLiteOwnerBindingError,
1179
+ AccountPersonalServerRegistrationError: () => AccountPersonalServerRegistrationError,
1176
1180
  BUILDER_REGISTRATION_TYPES: () => BUILDER_REGISTRATION_TYPES,
1177
1181
  BlockchainError: () => BlockchainError,
1178
1182
  BrowserPlatformAdapter: () => BrowserPlatformAdapter,
@@ -1183,8 +1187,11 @@ __export(index_node_exports, {
1183
1187
  DataFileEnvelopeSchema: () => DataFileEnvelopeSchema,
1184
1188
  DropboxStorage: () => DropboxStorage,
1185
1189
  ECIESError: () => ECIESError,
1190
+ ESCROW_DEPOSIT_ABI: () => ESCROW_DEPOSIT_ABI,
1186
1191
  ExpiredTokenError: () => ExpiredTokenError,
1192
+ FEE_REGISTRY_ABI: () => FEE_REGISTRY_ABI,
1187
1193
  FILE_REGISTRATION_TYPES: () => FILE_REGISTRATION_TYPES,
1194
+ GENERIC_PAYMENT_TYPES: () => GENERIC_PAYMENT_TYPES,
1188
1195
  GRANT_REGISTRATION_TYPES: () => GRANT_REGISTRATION_TYPES,
1189
1196
  GRANT_REVOCATION_TYPES: () => GRANT_REVOCATION_TYPES,
1190
1197
  GoogleDriveStorage: () => GoogleDriveStorage,
@@ -1195,11 +1202,17 @@ __export(index_node_exports, {
1195
1202
  IpfsStorage: () => IpfsStorage,
1196
1203
  MASTER_KEY_MESSAGE: () => MASTER_KEY_MESSAGE,
1197
1204
  MissingAuthError: () => MissingAuthError,
1205
+ NATIVE_VANA_ASSET: () => NATIVE_VANA_ASSET,
1198
1206
  NetworkError: () => NetworkError,
1199
1207
  NodeECIESProvider: () => NodeECIESUint8Provider,
1200
1208
  NodePlatformAdapter: () => NodePlatformAdapter,
1201
1209
  NonceError: () => NonceError,
1202
1210
  OAuthClient: () => OAuthClient,
1211
+ PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX: () => PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX,
1212
+ PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE: () => PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE,
1213
+ PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION: () => PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION,
1214
+ PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID: () => PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID,
1215
+ PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT: () => PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT,
1203
1216
  PKCE_CHALLENGE_PATTERN: () => PKCE_CHALLENGE_PATTERN,
1204
1217
  PKCE_VERIFIER_PATTERN: () => PKCE_VERIFIER_PATTERN,
1205
1218
  PSError: () => PSError,
@@ -1207,6 +1220,7 @@ __export(index_node_exports, {
1207
1220
  PersonalServerError: () => PersonalServerError,
1208
1221
  PinataStorage: () => PinataStorage,
1209
1222
  R2Storage: () => R2Storage,
1223
+ RECORD_DATA_ACCESS_TYPES: () => RECORD_DATA_ACCESS_TYPES,
1210
1224
  ReadOnlyError: () => ReadOnlyError,
1211
1225
  RelayerError: () => RelayerError,
1212
1226
  SERVER_REGISTRATION_TYPES: () => SERVER_REGISTRATION_TYPES,
@@ -1221,6 +1235,12 @@ __export(index_node_exports, {
1221
1235
  VanaError: () => VanaError,
1222
1236
  VanaStorage: () => VanaStorage,
1223
1237
  assertValidPkceVerifier: () => assertValidPkceVerifier,
1238
+ buildDepositNativeRequest: () => buildDepositNativeRequest,
1239
+ buildDepositTokenRequest: () => buildDepositTokenRequest,
1240
+ buildPersonalServerLiteOwnerBindingMessage: () => buildPersonalServerLiteOwnerBindingMessage,
1241
+ buildPersonalServerLiteOwnerBindingSignature: () => buildPersonalServerLiteOwnerBindingSignature,
1242
+ buildPersonalServerRegistrationSignature: () => buildPersonalServerRegistrationSignature,
1243
+ buildPersonalServerRegistrationTypedData: () => buildPersonalServerRegistrationTypedData,
1224
1244
  buildWeb3SignedHeader: () => buildWeb3SignedHeader,
1225
1245
  builderRegistrationDomain: () => builderRegistrationDomain,
1226
1246
  chains: () => chains,
@@ -1236,12 +1256,19 @@ __export(index_node_exports, {
1236
1256
  createPlatformAdapterFor: () => createPlatformAdapterFor,
1237
1257
  createPlatformAdapterSafe: () => createPlatformAdapterSafe,
1238
1258
  createVanaStorageProvider: () => createVanaStorageProvider,
1259
+ createViemPersonalServerLiteOwnerBindingSigner: () => createViemPersonalServerLiteOwnerBindingSigner,
1260
+ createViemPersonalServerRegistrationSigner: () => createViemPersonalServerRegistrationSigner,
1261
+ dataRegistryDomain: () => dataRegistryDomain,
1239
1262
  decryptWithPassword: () => decryptWithPassword,
1240
1263
  deriveMasterKey: () => deriveMasterKey,
1241
1264
  deriveScopeKey: () => deriveScopeKey,
1242
1265
  deserializeECIES: () => deserializeECIES,
1243
1266
  detectPlatform: () => detectPlatform,
1267
+ encodeDepositNativeData: () => encodeDepositNativeData,
1268
+ encodeDepositTokenData: () => encodeDepositTokenData,
1244
1269
  encryptWithPassword: () => encryptWithPassword,
1270
+ escrowContractAddress: () => escrowContractAddress,
1271
+ escrowPaymentDomain: () => escrowPaymentDomain,
1245
1272
  fileRegistrationDomain: () => fileRegistrationDomain,
1246
1273
  generatePkceVerifier: () => generatePkceVerifier,
1247
1274
  getAbi: () => getAbi,
@@ -1250,6 +1277,8 @@ __export(index_node_exports, {
1250
1277
  getContractAddress: () => getContractAddress,
1251
1278
  getContractController: () => getContractController,
1252
1279
  getContractInfo: () => getContractInfo,
1280
+ getFee: () => getFee,
1281
+ getOpFee: () => getOpFee,
1253
1282
  getPlatformCapabilities: () => getPlatformCapabilities,
1254
1283
  getServiceEndpoints: () => getServiceEndpoints,
1255
1284
  grantRegistrationDomain: () => grantRegistrationDomain,
@@ -1261,16 +1290,20 @@ __export(index_node_exports, {
1261
1290
  moksha: () => moksha,
1262
1291
  mokshaServices: () => mokshaServices,
1263
1292
  mokshaTestnet: () => mokshaTestnet2,
1264
- parseGrantRegistrationPayload: () => parseGrantRegistrationPayload,
1265
1293
  parsePSError: () => parsePSError,
1266
1294
  parseScope: () => parseScope,
1267
1295
  parseWeb3SignedHeader: () => parseWeb3SignedHeader,
1296
+ personalServerRegistrationDomain: () => personalServerRegistrationDomain,
1268
1297
  recoverServerOwner: () => recoverServerOwner,
1298
+ registerPersonalServerSignature: () => registerPersonalServerSignature,
1269
1299
  scopeCoveredByGrant: () => scopeCoveredByGrant,
1270
1300
  scopeMatchesPattern: () => scopeMatchesPattern,
1271
1301
  scopeToPathSegments: () => scopeToPathSegments,
1272
1302
  serializeECIES: () => serializeECIES,
1273
1303
  serverRegistrationDomain: () => serverRegistrationDomain,
1304
+ signPersonalServerLiteOwnerBinding: () => signPersonalServerLiteOwnerBinding,
1305
+ signPersonalServerLiteOwnerBindingWithAccountClient: () => signPersonalServerLiteOwnerBindingWithAccountClient,
1306
+ signPersonalServerRegistrationWithAccount: () => signPersonalServerRegistrationWithAccount,
1274
1307
  vanaMainnet: () => vanaMainnet2,
1275
1308
  verifyGrantRegistration: () => verifyGrantRegistration,
1276
1309
  verifyPkceChallenge: () => verifyPkceChallenge,
@@ -32628,6 +32661,7 @@ function formatOAuthError(body, status) {
32628
32661
  // src/protocol/eip712.ts
32629
32662
  var DOMAIN_NAME = "Vana Data Portability";
32630
32663
  var DOMAIN_VERSION = "1";
32664
+ var NATIVE_VANA_ASSET = "0x0000000000000000000000000000000000000000";
32631
32665
  function buildDomain(chainId, verifyingContract) {
32632
32666
  return {
32633
32667
  name: DOMAIN_NAME,
@@ -32642,6 +32676,12 @@ function fileRegistrationDomain(config) {
32642
32676
  config.contracts.dataRegistry
32643
32677
  );
32644
32678
  }
32679
+ function dataRegistryDomain(config) {
32680
+ return buildDomain(
32681
+ config.chainId,
32682
+ config.contracts.dataRegistry
32683
+ );
32684
+ }
32645
32685
  function grantRegistrationDomain(config) {
32646
32686
  return buildDomain(
32647
32687
  config.chainId,
@@ -32666,6 +32706,12 @@ function builderRegistrationDomain(config) {
32666
32706
  config.contracts.dataPortabilityGrantees
32667
32707
  );
32668
32708
  }
32709
+ function escrowPaymentDomain(config) {
32710
+ return buildDomain(
32711
+ config.chainId,
32712
+ config.contracts.dataPortabilityEscrow
32713
+ );
32714
+ }
32669
32715
  var FILE_REGISTRATION_TYPES = {
32670
32716
  FileRegistration: [
32671
32717
  { name: "ownerAddress", type: "address" },
@@ -32677,14 +32723,16 @@ var GRANT_REGISTRATION_TYPES = {
32677
32723
  GrantRegistration: [
32678
32724
  { name: "grantorAddress", type: "address" },
32679
32725
  { name: "granteeId", type: "bytes32" },
32680
- { name: "grant", type: "string" },
32681
- { name: "fileIds", type: "uint256[]" }
32726
+ { name: "scopes", type: "string[]" },
32727
+ { name: "grantVersion", type: "uint256" },
32728
+ { name: "expiresAt", type: "uint256" }
32682
32729
  ]
32683
32730
  };
32684
32731
  var GRANT_REVOCATION_TYPES = {
32685
32732
  GrantRevocation: [
32686
32733
  { name: "grantorAddress", type: "address" },
32687
- { name: "grantId", type: "bytes32" }
32734
+ { name: "grantId", type: "bytes32" },
32735
+ { name: "grantVersion", type: "uint256" }
32688
32736
  ]
32689
32737
  };
32690
32738
  var SERVER_REGISTRATION_TYPES = {
@@ -32703,87 +32751,500 @@ var BUILDER_REGISTRATION_TYPES = {
32703
32751
  { name: "appUrl", type: "string" }
32704
32752
  ]
32705
32753
  };
32754
+ var GENERIC_PAYMENT_TYPES = {
32755
+ GenericPayment: [
32756
+ { name: "payerAddress", type: "address" },
32757
+ { name: "opType", type: "string" },
32758
+ { name: "opId", type: "bytes32" },
32759
+ { name: "asset", type: "address" },
32760
+ { name: "amount", type: "uint256" },
32761
+ { name: "paymentNonce", type: "uint256" }
32762
+ ]
32763
+ };
32764
+ var ADD_DATA_TYPES = {
32765
+ AddData: [
32766
+ { name: "ownerAddress", type: "address" },
32767
+ { name: "scope", type: "string" },
32768
+ { name: "dataHash", type: "bytes32" },
32769
+ { name: "metadataHash", type: "bytes32" },
32770
+ { name: "expectedVersion", type: "uint256" }
32771
+ ]
32772
+ };
32773
+ var RECORD_DATA_ACCESS_TYPES = {
32774
+ RecordDataAccess: [
32775
+ { name: "ownerAddress", type: "address" },
32776
+ { name: "scope", type: "string" },
32777
+ { name: "version", type: "uint256" },
32778
+ { name: "accessor", type: "address" },
32779
+ { name: "recordId", type: "bytes32" }
32780
+ ]
32781
+ };
32706
32782
 
32707
- // src/protocol/grants.ts
32783
+ // src/protocol/personal-server-registration.ts
32708
32784
  var import_viem14 = require("viem");
32709
- function isHexString(value) {
32710
- return typeof value === "string" && value.startsWith("0x");
32785
+ var PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID = 1480;
32786
+ var PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT = "0x1483B1F634DBA75AeaE60da7f01A679aabd5ee2c";
32787
+ function assertAddress(value, name) {
32788
+ if (!(0, import_viem14.isAddress)(value)) {
32789
+ throw new Error(`${name} must be a valid EVM address`);
32790
+ }
32711
32791
  }
32712
- function isDataPortabilityGatewayConfig(value) {
32713
- if (value === null || typeof value !== "object" || Array.isArray(value)) {
32714
- return false;
32792
+ function getAccountAddress(account) {
32793
+ if (!account) {
32794
+ return void 0;
32715
32795
  }
32716
- const config = value;
32717
- const contracts = config["contracts"];
32718
- if (typeof config["chainId"] !== "number" || !Number.isInteger(config["chainId"]) || config["chainId"] <= 0 || contracts === null || typeof contracts !== "object" || Array.isArray(contracts)) {
32719
- return false;
32796
+ return typeof account === "string" ? account : account.address;
32797
+ }
32798
+ function isPersonalServerRegistrationSigner(source) {
32799
+ return "address" in source && typeof source.signTypedData === "function";
32800
+ }
32801
+ function createViemPersonalServerRegistrationSigner(source, options = {}) {
32802
+ if (isPersonalServerRegistrationSigner(source)) {
32803
+ return source;
32720
32804
  }
32721
- const c = contracts;
32722
- return isHexString(c["dataRegistry"]) && isHexString(c["dataPortabilityPermissions"]) && isHexString(c["dataPortabilityServer"]) && isHexString(c["dataPortabilityGrantees"]);
32805
+ const accountAddress = getAccountAddress(options.account) ?? getAccountAddress(source.account);
32806
+ if (accountAddress) {
32807
+ return {
32808
+ address: accountAddress,
32809
+ signTypedData: (typedData) => source.signTypedData({
32810
+ ...typedData,
32811
+ account: options.account ?? source.account ?? accountAddress
32812
+ })
32813
+ };
32814
+ }
32815
+ throw new Error(
32816
+ "Viem wallet client requires an account option or account property"
32817
+ );
32723
32818
  }
32724
- function parseGrantRegistrationPayload(grant) {
32725
- let parsed;
32726
- try {
32727
- parsed = JSON.parse(grant);
32728
- } catch {
32729
- return null;
32819
+ function personalServerRegistrationDomain(input = {}) {
32820
+ if (input.config) {
32821
+ return serverRegistrationDomain(input.config);
32730
32822
  }
32731
- if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
32732
- return null;
32823
+ const verifyingContract = input.verifyingContract ?? PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT;
32824
+ assertAddress(verifyingContract, "verifyingContract");
32825
+ return {
32826
+ name: "Vana Data Portability",
32827
+ version: "1",
32828
+ chainId: input.chainId ?? PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID,
32829
+ verifyingContract
32830
+ };
32831
+ }
32832
+ function buildPersonalServerRegistrationTypedData(input) {
32833
+ assertAddress(input.ownerAddress, "ownerAddress");
32834
+ assertAddress(input.serverAddress, "serverAddress");
32835
+ return {
32836
+ domain: personalServerRegistrationDomain(input),
32837
+ types: SERVER_REGISTRATION_TYPES,
32838
+ primaryType: "ServerRegistration",
32839
+ message: {
32840
+ ownerAddress: input.ownerAddress,
32841
+ serverAddress: input.serverAddress,
32842
+ publicKey: input.serverPublicKey,
32843
+ serverUrl: input.serverUrl
32844
+ }
32845
+ };
32846
+ }
32847
+ async function buildPersonalServerRegistrationSignature(input) {
32848
+ const typedData = buildPersonalServerRegistrationTypedData({
32849
+ ownerAddress: input.signer.address,
32850
+ serverAddress: input.serverAddress,
32851
+ serverPublicKey: input.serverPublicKey,
32852
+ serverUrl: input.serverUrl,
32853
+ config: input.config,
32854
+ chainId: input.chainId,
32855
+ verifyingContract: input.verifyingContract
32856
+ });
32857
+ const signature = await input.signer.signTypedData(typedData);
32858
+ return {
32859
+ signature,
32860
+ signerAddress: input.signer.address,
32861
+ typedData
32862
+ };
32863
+ }
32864
+ var registerPersonalServerSignature = buildPersonalServerRegistrationSignature;
32865
+
32866
+ // src/protocol/personal-server-lite-owner-binding.ts
32867
+ var import_viem15 = require("viem");
32868
+ var PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION = "vana.account.v1";
32869
+ var PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE = "ps-lite-owner";
32870
+ var PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX = `${PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION}:${PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE}:`;
32871
+ function assertAddress2(value, name) {
32872
+ if (!(0, import_viem15.isAddress)(value)) {
32873
+ throw new Error(`${name} must be a valid EVM address`);
32733
32874
  }
32734
- const value = parsed;
32735
- if (!Array.isArray(value["scopes"]) || value["scopes"].length === 0) {
32736
- return null;
32875
+ }
32876
+ function getAccountAddress2(account) {
32877
+ if (!account) {
32878
+ return void 0;
32737
32879
  }
32738
- if (!value["scopes"].every((scope) => typeof scope === "string")) {
32739
- return null;
32880
+ return typeof account === "string" ? account : account.address;
32881
+ }
32882
+ function isPersonalServerLiteOwnerBindingSigner(source) {
32883
+ return "address" in source && typeof source.signMessage === "function";
32884
+ }
32885
+ function buildPersonalServerLiteOwnerBindingMessage(ownerAddress) {
32886
+ assertAddress2(ownerAddress, "ownerAddress");
32887
+ return `${PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX}${ownerAddress.toLowerCase()}`;
32888
+ }
32889
+ function createViemPersonalServerLiteOwnerBindingSigner(source, options = {}) {
32890
+ if (isPersonalServerLiteOwnerBindingSigner(source)) {
32891
+ return source;
32740
32892
  }
32741
- if (typeof value["expiresAt"] !== "number" || !Number.isFinite(value["expiresAt"])) {
32742
- return null;
32893
+ const accountAddress = getAccountAddress2(options.account) ?? getAccountAddress2(source.account);
32894
+ if (accountAddress) {
32895
+ return {
32896
+ address: accountAddress,
32897
+ signMessage: ({ message }) => source.signMessage({
32898
+ account: options.account ?? source.account ?? accountAddress,
32899
+ message
32900
+ })
32901
+ };
32743
32902
  }
32744
- if (value["user"] !== void 0 && !isHexString(value["user"])) {
32745
- return null;
32903
+ throw new Error(
32904
+ "Viem wallet client requires an account option or account property"
32905
+ );
32906
+ }
32907
+ async function buildPersonalServerLiteOwnerBindingSignature(input) {
32908
+ const message = buildPersonalServerLiteOwnerBindingMessage(
32909
+ input.signer.address
32910
+ );
32911
+ const signature = await input.signer.signMessage({ message });
32912
+ return {
32913
+ signature,
32914
+ signerAddress: input.signer.address,
32915
+ message,
32916
+ purpose: PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE
32917
+ };
32918
+ }
32919
+ var signPersonalServerLiteOwnerBinding = buildPersonalServerLiteOwnerBindingSignature;
32920
+
32921
+ // src/account/personal-server-registration.ts
32922
+ var import_viem16 = require("viem");
32923
+ var ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT = "personal_server.server_registration.v1";
32924
+ var AccountPersonalServerRegistrationError = class extends Error {
32925
+ status;
32926
+ code;
32927
+ details;
32928
+ constructor(input) {
32929
+ super(input.message);
32930
+ this.name = "AccountPersonalServerRegistrationError";
32931
+ this.status = input.status;
32932
+ this.code = input.code;
32933
+ this.details = input.details;
32746
32934
  }
32747
- if (value["builder"] !== void 0 && !isHexString(value["builder"])) {
32748
- return null;
32935
+ };
32936
+ var DEFAULT_ACCOUNT_PS_REGISTRATION_PATH = "/api/v1/intents/personal-server-registration/sign";
32937
+ function trimTrailingSlash(value) {
32938
+ return value.replace(/\/+$/, "");
32939
+ }
32940
+ function assertAddress3(value, name) {
32941
+ if (!(0, import_viem16.isAddress)(value)) {
32942
+ throw new Error(`${name} must be a valid EVM address`);
32749
32943
  }
32750
- if (value["nonce"] !== void 0 && (typeof value["nonce"] !== "number" || !Number.isFinite(value["nonce"]))) {
32751
- return null;
32944
+ }
32945
+ async function parseAccountResponse(response) {
32946
+ const body = await response.json().catch(() => void 0);
32947
+ if (!response.ok) {
32948
+ throw new AccountPersonalServerRegistrationError({
32949
+ status: response.status,
32950
+ code: accountErrorCode(body),
32951
+ message: accountErrorMessage(response.status, body),
32952
+ details: body
32953
+ });
32954
+ }
32955
+ return body;
32956
+ }
32957
+ function accountErrorMessage(status, body) {
32958
+ const nestedMessage = nestedAccountErrorField(body, "message");
32959
+ if (nestedMessage) {
32960
+ return nestedMessage;
32961
+ }
32962
+ if (isRecord(body) && typeof body.message === "string") {
32963
+ return body.message;
32964
+ }
32965
+ const code = accountErrorCode(body);
32966
+ if (code) {
32967
+ return `Account PS registration signing failed: ${code}`;
32752
32968
  }
32969
+ return `Account PS registration signing failed: ${status}`;
32970
+ }
32971
+ function accountErrorCode(body) {
32972
+ const nestedCode = nestedAccountErrorField(body, "code");
32973
+ if (nestedCode) {
32974
+ return nestedCode;
32975
+ }
32976
+ if (isRecord(body)) {
32977
+ if (typeof body.code === "string") {
32978
+ return body.code;
32979
+ }
32980
+ if (typeof body.error === "string") {
32981
+ return body.error;
32982
+ }
32983
+ }
32984
+ return void 0;
32985
+ }
32986
+ function nestedAccountErrorField(body, field) {
32987
+ if (!isRecord(body) || !isRecord(body.error)) {
32988
+ return void 0;
32989
+ }
32990
+ const value = body.error[field];
32991
+ return typeof value === "string" ? value : void 0;
32992
+ }
32993
+ function isRecord(value) {
32994
+ return typeof value === "object" && value !== null;
32995
+ }
32996
+ function normalizeAccountResponse(response) {
32753
32997
  return {
32754
- user: value["user"],
32755
- builder: value["builder"],
32756
- scopes: value["scopes"],
32757
- expiresAt: value["expiresAt"],
32758
- nonce: value["nonce"]
32998
+ ...response,
32999
+ status: response.status === "fallback_required" ? "confirmation_required" : response.status,
33000
+ signerAddress: response.signerAddress ?? response.signer?.address,
33001
+ typedData: response.typedData ?? response.typed_data
32759
33002
  };
32760
33003
  }
32761
- function parseFileIds(fileIds) {
32762
- try {
32763
- const values = (fileIds ?? []).map((fileId) => BigInt(fileId));
33004
+ function buildSignedResult(response, request) {
33005
+ assertAddress3(response.signerAddress, "signerAddress");
33006
+ if (response.typedData) {
33007
+ assertTypedDataMatchesRequest(
33008
+ response.typedData,
33009
+ request,
33010
+ response.signerAddress
33011
+ );
33012
+ }
33013
+ return {
33014
+ signature: response.signature,
33015
+ signerAddress: response.signerAddress,
33016
+ typedData: response.typedData ?? buildPersonalServerRegistrationTypedData({
33017
+ ownerAddress: response.signerAddress,
33018
+ ...request
33019
+ }),
33020
+ intent: ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT
33021
+ };
33022
+ }
33023
+ function assertTypedDataMatchesRequest(typedData, request, expectedSignerAddress) {
33024
+ assertAddress3(
33025
+ typedData.message.ownerAddress,
33026
+ "typedData.message.ownerAddress"
33027
+ );
33028
+ assertAddress3(
33029
+ typedData.message.serverAddress,
33030
+ "typedData.message.serverAddress"
33031
+ );
33032
+ if (expectedSignerAddress && !sameAddress(typedData.message.ownerAddress, expectedSignerAddress)) {
33033
+ throw new Error(
33034
+ "Account typedData ownerAddress must match the expected signer address"
33035
+ );
33036
+ }
33037
+ if (!sameAddress(typedData.message.serverAddress, request.serverAddress)) {
33038
+ throw new Error(
33039
+ "Account typedData serverAddress must match the requested serverAddress"
33040
+ );
33041
+ }
33042
+ if (typedData.message.publicKey !== request.serverPublicKey) {
33043
+ throw new Error(
33044
+ "Account typedData publicKey must match the requested serverPublicKey"
33045
+ );
33046
+ }
33047
+ if (typedData.message.serverUrl !== request.serverUrl) {
33048
+ throw new Error(
33049
+ "Account typedData serverUrl must match the requested serverUrl"
33050
+ );
33051
+ }
33052
+ if (typedData.primaryType !== "ServerRegistration") {
33053
+ throw new Error("Account typedData primaryType must be ServerRegistration");
33054
+ }
33055
+ if (JSON.stringify(typedData.types) !== JSON.stringify(SERVER_REGISTRATION_TYPES)) {
33056
+ throw new Error("Account typedData types must be ServerRegistration types");
33057
+ }
33058
+ const expectedDomain = personalServerRegistrationDomain({
33059
+ config: request.config,
33060
+ chainId: request.chainId,
33061
+ verifyingContract: request.verifyingContract
33062
+ });
33063
+ if (!domainsEqual(typedData.domain, expectedDomain)) {
33064
+ throw new Error("Account typedData domain must match the requested domain");
33065
+ }
33066
+ }
33067
+ function sameAddress(a, b) {
33068
+ return a.toLowerCase() === b.toLowerCase();
33069
+ }
33070
+ function domainsEqual(a, b) {
33071
+ if (!a || !b) {
33072
+ return false;
33073
+ }
33074
+ return a.name === b.name && a.version === b.version && Number(a.chainId) === Number(b.chainId) && String(a.verifyingContract ?? "").toLowerCase() === String(b.verifyingContract ?? "").toLowerCase() && a.salt === b.salt;
33075
+ }
33076
+ async function signPersonalServerRegistrationWithAccount(config, request) {
33077
+ assertAddress3(request.serverAddress, "serverAddress");
33078
+ const fetchImpl = config.fetchImpl ?? globalThis.fetch.bind(globalThis);
33079
+ const endpoint = new URL(
33080
+ config.endpointPath ?? DEFAULT_ACCOUNT_PS_REGISTRATION_PATH,
33081
+ `${trimTrailingSlash(config.accountOrigin)}/`
33082
+ );
33083
+ const response = await fetchImpl(endpoint, {
33084
+ method: "POST",
33085
+ headers: { "content-type": "application/json" },
33086
+ credentials: "include",
33087
+ body: JSON.stringify({
33088
+ intent: ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT,
33089
+ serverAddress: request.serverAddress,
33090
+ serverPublicKey: request.serverPublicKey,
33091
+ serverUrl: request.serverUrl,
33092
+ config: request.config,
33093
+ chainId: request.chainId,
33094
+ verifyingContract: request.verifyingContract
33095
+ })
33096
+ });
33097
+ const body = normalizeAccountResponse(await parseAccountResponse(response));
33098
+ if (body.status === "signed") {
33099
+ if (!body.signature || !body.signerAddress) {
33100
+ throw new Error(
33101
+ "Account signed response must include signature and signerAddress"
33102
+ );
33103
+ }
32764
33104
  return {
32765
- values,
32766
- display: values.map((fileId) => fileId.toString())
33105
+ status: "signed",
33106
+ result: buildSignedResult(
33107
+ {
33108
+ signature: body.signature,
33109
+ signerAddress: body.signerAddress,
33110
+ typedData: body.typedData
33111
+ },
33112
+ request
33113
+ )
32767
33114
  };
33115
+ }
33116
+ if (body.status === "confirmation_required") {
33117
+ if (!body.typedData) {
33118
+ throw new Error(
33119
+ "Account confirmation_required response must include typedData"
33120
+ );
33121
+ }
33122
+ assertTypedDataMatchesRequest(body.typedData, request, body.signerAddress);
33123
+ if (!config.fallbackSigner) {
33124
+ return {
33125
+ status: "confirmation_required",
33126
+ typedData: body.typedData,
33127
+ signerAddress: body.signerAddress
33128
+ };
33129
+ }
33130
+ assertTypedDataMatchesRequest(
33131
+ body.typedData,
33132
+ request,
33133
+ config.fallbackSigner.address
33134
+ );
33135
+ const signature = await config.fallbackSigner.signTypedData(body.typedData);
33136
+ return {
33137
+ status: "fallback_signed",
33138
+ accountStatus: "confirmation_required",
33139
+ result: {
33140
+ signature,
33141
+ signerAddress: config.fallbackSigner.address,
33142
+ typedData: body.typedData,
33143
+ intent: ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT
33144
+ }
33145
+ };
33146
+ }
33147
+ throw new Error(
33148
+ `Unsupported Account PS registration signing status: ${String(body.status)}`
33149
+ );
33150
+ }
33151
+
33152
+ // src/account/personal-server-lite-owner-binding.ts
33153
+ var AccountPersonalServerLiteOwnerBindingError = class extends Error {
33154
+ code;
33155
+ details;
33156
+ constructor(input) {
33157
+ super(input.message);
33158
+ this.name = "AccountPersonalServerLiteOwnerBindingError";
33159
+ this.code = input.code;
33160
+ this.details = input.details;
33161
+ }
33162
+ };
33163
+ async function signPersonalServerLiteOwnerBindingWithAccountClient(config) {
33164
+ let address;
33165
+ try {
33166
+ address = await config.client.getAddress();
33167
+ } catch (error) {
33168
+ throw accountOwnerBindingError(error);
33169
+ }
33170
+ if (!address) {
33171
+ throw new AccountPersonalServerLiteOwnerBindingError({
33172
+ message: "Account did not return a wallet address",
33173
+ code: "account_address_required"
33174
+ });
33175
+ }
33176
+ const message = buildPersonalServerLiteOwnerBindingMessage(address);
33177
+ let signature;
33178
+ try {
33179
+ signature = await config.client.signMessage({ message });
33180
+ } catch (error) {
33181
+ throw accountOwnerBindingError(error);
33182
+ }
33183
+ return {
33184
+ signature,
33185
+ signerAddress: address,
33186
+ message,
33187
+ purpose: PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE
33188
+ };
33189
+ }
33190
+ function accountOwnerBindingError(error) {
33191
+ if (error instanceof AccountPersonalServerLiteOwnerBindingError) {
33192
+ return error;
33193
+ }
33194
+ const rpcError = error;
33195
+ const code = rpcError?.code;
33196
+ const message = typeof rpcError?.message === "string" && rpcError.message.length > 0 ? rpcError.message : "Account PS Lite owner-binding signature failed";
33197
+ return new AccountPersonalServerLiteOwnerBindingError({
33198
+ message,
33199
+ code,
33200
+ details: error
33201
+ });
33202
+ }
33203
+
33204
+ // src/protocol/grants.ts
33205
+ var import_viem17 = require("viem");
33206
+ function isHexString(value) {
33207
+ return typeof value === "string" && value.startsWith("0x");
33208
+ }
33209
+ function isDataPortabilityGatewayConfig(value) {
33210
+ if (value === null || typeof value !== "object" || Array.isArray(value)) {
33211
+ return false;
33212
+ }
33213
+ const config = value;
33214
+ const contracts = config["contracts"];
33215
+ if (typeof config["chainId"] !== "number" || !Number.isInteger(config["chainId"]) || config["chainId"] <= 0 || contracts === null || typeof contracts !== "object" || Array.isArray(contracts)) {
33216
+ return false;
33217
+ }
33218
+ const c = contracts;
33219
+ return isHexString(c["dataRegistry"]) && isHexString(c["dataPortabilityPermissions"]) && isHexString(c["dataPortabilityServer"]) && isHexString(c["dataPortabilityGrantees"]) && isHexString(c["dataPortabilityEscrow"]) && isHexString(c["feeRegistry"]);
33220
+ }
33221
+ function toUint256(value) {
33222
+ try {
33223
+ const big = typeof value === "bigint" ? value : BigInt(value);
33224
+ if (big < 0n) return null;
33225
+ return big;
32768
33226
  } catch {
32769
33227
  return null;
32770
33228
  }
32771
33229
  }
32772
33230
  async function verifyGrantRegistration(input) {
32773
- const payload = parseGrantRegistrationPayload(input.grant);
32774
- if (!payload) {
32775
- return {
32776
- valid: false,
32777
- error: "Grant must be JSON with scopes and expiresAt"
32778
- };
33231
+ if (!Array.isArray(input.scopes) || input.scopes.length === 0) {
33232
+ return { valid: false, error: "scopes must be a non-empty array" };
33233
+ }
33234
+ if (!input.scopes.every((scope) => typeof scope === "string")) {
33235
+ return { valid: false, error: "scopes must contain only strings" };
33236
+ }
33237
+ const grantVersion = toUint256(input.grantVersion);
33238
+ if (grantVersion === null || grantVersion < 1n) {
33239
+ return { valid: false, error: "grantVersion must be a uint256 >= 1" };
32779
33240
  }
32780
- const fileIds = parseFileIds(input.fileIds);
32781
- if (!fileIds) {
32782
- return { valid: false, error: "fileIds must contain integer values" };
33241
+ const expiresAt = toUint256(input.expiresAt);
33242
+ if (expiresAt === null) {
33243
+ return { valid: false, error: "expiresAt must be a non-negative uint256" };
32783
33244
  }
32784
33245
  let valid;
32785
33246
  try {
32786
- valid = await (0, import_viem14.verifyTypedData)({
33247
+ valid = await (0, import_viem17.verifyTypedData)({
32787
33248
  address: input.grantorAddress,
32788
33249
  domain: grantRegistrationDomain(input.gatewayConfig),
32789
33250
  types: GRANT_REGISTRATION_TYPES,
@@ -32791,8 +33252,9 @@ async function verifyGrantRegistration(input) {
32791
33252
  message: {
32792
33253
  grantorAddress: input.grantorAddress,
32793
33254
  granteeId: input.granteeId,
32794
- grant: input.grant,
32795
- fileIds: fileIds.values
33255
+ scopes: input.scopes,
33256
+ grantVersion,
33257
+ expiresAt
32796
33258
  },
32797
33259
  signature: input.signature
32798
33260
  });
@@ -32803,19 +33265,128 @@ async function verifyGrantRegistration(input) {
32803
33265
  return { valid: false, error: "Grant signature does not match grantor" };
32804
33266
  }
32805
33267
  const nowSeconds = input.nowSeconds ?? Math.floor(Date.now() / 1e3);
32806
- if (payload.expiresAt > 0 && payload.expiresAt < nowSeconds) {
33268
+ if (expiresAt > 0n && expiresAt < BigInt(nowSeconds)) {
32807
33269
  return { valid: false, error: "Grant has expired" };
32808
33270
  }
32809
- if (payload.user !== void 0 && payload.user.toLowerCase() !== input.grantorAddress.toLowerCase()) {
32810
- return { valid: false, error: "Grant user does not match grantorAddress" };
32811
- }
32812
33271
  return {
32813
33272
  valid: true,
32814
33273
  grantorAddress: input.grantorAddress,
32815
33274
  granteeId: input.granteeId,
32816
- grant: input.grant,
32817
- payload,
32818
- fileIds: fileIds.display
33275
+ scopes: input.scopes,
33276
+ grantVersion: grantVersion.toString(),
33277
+ expiresAt: expiresAt.toString()
33278
+ };
33279
+ }
33280
+
33281
+ // src/protocol/escrow-deposit.ts
33282
+ var import_viem18 = require("viem");
33283
+ var ESCROW_DEPOSIT_ABI = [
33284
+ {
33285
+ type: "function",
33286
+ name: "depositNative",
33287
+ stateMutability: "payable",
33288
+ inputs: [{ name: "account", type: "address" }],
33289
+ outputs: []
33290
+ },
33291
+ {
33292
+ type: "function",
33293
+ name: "depositToken",
33294
+ stateMutability: "nonpayable",
33295
+ inputs: [
33296
+ { name: "account", type: "address" },
33297
+ { name: "token", type: "address" },
33298
+ { name: "amount", type: "uint256" }
33299
+ ],
33300
+ outputs: []
33301
+ }
33302
+ ];
33303
+ function escrowContractAddress(config) {
33304
+ return config.contracts.dataPortabilityEscrow;
33305
+ }
33306
+ function encodeDepositNativeData(input) {
33307
+ return (0, import_viem18.encodeFunctionData)({
33308
+ abi: ESCROW_DEPOSIT_ABI,
33309
+ functionName: "depositNative",
33310
+ args: [input.account]
33311
+ });
33312
+ }
33313
+ function encodeDepositTokenData(input) {
33314
+ return (0, import_viem18.encodeFunctionData)({
33315
+ abi: ESCROW_DEPOSIT_ABI,
33316
+ functionName: "depositToken",
33317
+ args: [input.account, input.token, input.amount]
33318
+ });
33319
+ }
33320
+ function buildDepositNativeRequest(config, input) {
33321
+ return {
33322
+ to: escrowContractAddress(config),
33323
+ data: encodeDepositNativeData({ account: input.account }),
33324
+ value: input.amount
33325
+ };
33326
+ }
33327
+ function buildDepositTokenRequest(config, input) {
33328
+ return {
33329
+ to: escrowContractAddress(config),
33330
+ data: encodeDepositTokenData(input)
33331
+ };
33332
+ }
33333
+
33334
+ // src/protocol/fee-registry.ts
33335
+ var import_viem19 = require("viem");
33336
+ var FEE_REGISTRY_ABI = (0, import_viem19.parseAbi)([
33337
+ "struct Fee { uint256 amount; address asset; address payee; bool enabled; }",
33338
+ "function fees(bytes32 operation) view returns (Fee)",
33339
+ "function operationKey(string name) pure returns (bytes32)"
33340
+ ]);
33341
+ function operationNameFor(kind, opts) {
33342
+ if (kind === "registration") {
33343
+ return opts?.registrationOpName ?? "registration";
33344
+ }
33345
+ return opts?.dataAccessOpName ?? "data_access";
33346
+ }
33347
+ async function getFee(client, config, kind, opts) {
33348
+ const address = config.contracts.feeRegistry;
33349
+ const opName = operationNameFor(kind, opts);
33350
+ const opKey = await client.readContract({
33351
+ address,
33352
+ abi: FEE_REGISTRY_ABI,
33353
+ functionName: "operationKey",
33354
+ args: [opName]
33355
+ });
33356
+ const fee = await client.readContract({
33357
+ address,
33358
+ abi: FEE_REGISTRY_ABI,
33359
+ functionName: "fees",
33360
+ args: [opKey]
33361
+ });
33362
+ if (!fee.enabled) {
33363
+ throw new Error(
33364
+ `FeeRegistry: operation "${opName}" (kind=${kind}) is not enabled \u2014 operator must call setFeeByName before payments will validate`
33365
+ );
33366
+ }
33367
+ if (fee.payee === "0x0000000000000000000000000000000000000000") {
33368
+ throw new Error(
33369
+ `FeeRegistry: operation "${opName}" has zero-address payee \u2014 contract pre-flight rejects payouts to 0x0`
33370
+ );
33371
+ }
33372
+ return fee;
33373
+ }
33374
+ async function getOpFee(client, config, opts) {
33375
+ const [registration, dataAccess] = await Promise.all([
33376
+ getFee(client, config, "registration", opts),
33377
+ getFee(client, config, "data_access", opts)
33378
+ ]);
33379
+ if (registration.asset.toLowerCase() !== dataAccess.asset.toLowerCase()) {
33380
+ throw new Error(
33381
+ `FeeRegistry asset mismatch: registration=${registration.asset} vs data_access=${dataAccess.asset}. The gateway requires both fees to settle in the same asset.`
33382
+ );
33383
+ }
33384
+ return {
33385
+ asset: registration.asset,
33386
+ registrationFee: registration.amount,
33387
+ dataAccessFee: dataAccess.amount,
33388
+ registrationPayee: registration.payee,
33389
+ dataAccessPayee: dataAccess.payee
32819
33390
  };
32820
33391
  }
32821
33392
 
@@ -33015,6 +33586,68 @@ function createGatewayClient(baseUrl) {
33015
33586
  alreadyRegistered: false
33016
33587
  };
33017
33588
  },
33589
+ async registerBuilder(params) {
33590
+ const res = await fetch(`${base}/v1/builders`, {
33591
+ method: "POST",
33592
+ headers: {
33593
+ "Content-Type": "application/json",
33594
+ Authorization: `Web3Signed ${params.signature}`
33595
+ },
33596
+ body: JSON.stringify({
33597
+ ownerAddress: params.ownerAddress,
33598
+ granteeAddress: params.granteeAddress,
33599
+ publicKey: params.publicKey,
33600
+ appUrl: params.appUrl
33601
+ })
33602
+ });
33603
+ if (res.status === 409) {
33604
+ const body2 = await res.json().catch(() => ({}));
33605
+ return {
33606
+ builderId: getMutationId(
33607
+ body2,
33608
+ "builderId"
33609
+ ),
33610
+ alreadyRegistered: true
33611
+ };
33612
+ }
33613
+ if (!res.ok) {
33614
+ throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
33615
+ }
33616
+ const body = await res.json().catch(() => ({}));
33617
+ return {
33618
+ builderId: getMutationId(body, "builderId"),
33619
+ alreadyRegistered: false
33620
+ };
33621
+ },
33622
+ async registerDataPoint(params) {
33623
+ const res = await fetch(`${base}/v1/data`, {
33624
+ method: "POST",
33625
+ headers: {
33626
+ "Content-Type": "application/json",
33627
+ Authorization: `Web3Signed ${params.signature}`
33628
+ },
33629
+ body: JSON.stringify({
33630
+ ownerAddress: params.ownerAddress,
33631
+ scope: params.scope,
33632
+ dataHash: params.dataHash,
33633
+ metadataHash: params.metadataHash,
33634
+ expectedVersion: params.expectedVersion
33635
+ })
33636
+ });
33637
+ if (!res.ok) {
33638
+ const body2 = await res.json().catch(() => ({}));
33639
+ const detail = body2.error ?? res.statusText;
33640
+ throw new Error(`Gateway error: ${res.status} ${detail}`);
33641
+ }
33642
+ const body = await res.json().catch(() => ({}));
33643
+ return {
33644
+ dataPointId: getMutationId(
33645
+ body,
33646
+ "dataPointId"
33647
+ ),
33648
+ expectedVersion: body.expectedVersion
33649
+ };
33650
+ },
33018
33651
  async registerFile(params) {
33019
33652
  const res = await fetch(`${base}/v1/files`, {
33020
33653
  method: "POST",
@@ -33052,8 +33685,9 @@ function createGatewayClient(baseUrl) {
33052
33685
  body: JSON.stringify({
33053
33686
  grantorAddress: params.grantorAddress,
33054
33687
  granteeId: params.granteeId,
33055
- grant: params.grant,
33056
- fileIds: params.fileIds
33688
+ scopes: params.scopes,
33689
+ grantVersion: params.grantVersion,
33690
+ expiresAt: params.expiresAt
33057
33691
  })
33058
33692
  });
33059
33693
  if (res.status === 409) {
@@ -33078,13 +33712,71 @@ function createGatewayClient(baseUrl) {
33078
33712
  Authorization: `Web3Signed ${params.signature}`
33079
33713
  },
33080
33714
  body: JSON.stringify({
33081
- grantorAddress: params.grantorAddress
33715
+ grantorAddress: params.grantorAddress,
33716
+ grantVersion: params.grantVersion
33082
33717
  })
33083
33718
  });
33084
33719
  if (res.status === 409) return;
33085
33720
  if (!res.ok) {
33086
33721
  throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
33087
33722
  }
33723
+ },
33724
+ async getEscrowBalance(account) {
33725
+ const res = await fetch(`${base}/v1/escrow/balance?account=${account}`);
33726
+ if (!res.ok) {
33727
+ throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
33728
+ }
33729
+ return await res.json();
33730
+ },
33731
+ async submitEscrowDeposit(params) {
33732
+ const res = await fetch(`${base}/v1/escrow/deposit`, {
33733
+ method: "POST",
33734
+ headers: { "Content-Type": "application/json" },
33735
+ body: JSON.stringify({ txHash: params.txHash })
33736
+ });
33737
+ if (res.status !== 200 && res.status !== 202) {
33738
+ throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
33739
+ }
33740
+ return await res.json();
33741
+ },
33742
+ async payForOperation(params) {
33743
+ const body = {
33744
+ payerAddress: params.payerAddress,
33745
+ opType: params.opType,
33746
+ opId: params.opId,
33747
+ asset: params.asset,
33748
+ amount: params.amount,
33749
+ paymentNonce: params.paymentNonce
33750
+ };
33751
+ if (params.accessRecord) {
33752
+ body["accessRecord"] = params.accessRecord;
33753
+ }
33754
+ const res = await fetch(`${base}/v1/escrow/pay`, {
33755
+ method: "POST",
33756
+ headers: {
33757
+ "Content-Type": "application/json",
33758
+ Authorization: `Web3Signed ${params.signature}`
33759
+ },
33760
+ body: JSON.stringify(body)
33761
+ });
33762
+ if (!res.ok) {
33763
+ throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
33764
+ }
33765
+ return await res.json();
33766
+ },
33767
+ async settle(params) {
33768
+ const res = await fetch(`${base}/v1/settle`, {
33769
+ method: "POST",
33770
+ headers: { "Content-Type": "application/json" },
33771
+ // The gateway accepts an empty body; only `limit` is recognised.
33772
+ // Always send a JSON body so the gateway's req.body shape parse
33773
+ // doesn't have to deal with an undefined.
33774
+ body: JSON.stringify(params ?? {})
33775
+ });
33776
+ if (!res.ok) {
33777
+ throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
33778
+ }
33779
+ return await res.json();
33088
33780
  }
33089
33781
  };
33090
33782
  }
@@ -33114,7 +33806,7 @@ var KNOWN_CODES = /* @__PURE__ */ new Set([
33114
33806
  "server_not_configured",
33115
33807
  "content_too_large"
33116
33808
  ]);
33117
- function isRecord(value) {
33809
+ function isRecord2(value) {
33118
33810
  return value !== null && typeof value === "object" && !Array.isArray(value);
33119
33811
  }
33120
33812
  function normalizeCode(value) {
@@ -33125,10 +33817,10 @@ function normalizeCode(value) {
33125
33817
  return KNOWN_CODES.has(code) ? code : null;
33126
33818
  }
33127
33819
  function extractPSErrorBody(body) {
33128
- if (!isRecord(body)) {
33820
+ if (!isRecord2(body)) {
33129
33821
  return null;
33130
33822
  }
33131
- const nested = isRecord(body.error) ? body.error : null;
33823
+ const nested = isRecord2(body.error) ? body.error : null;
33132
33824
  const code = normalizeCode(
33133
33825
  nested?.errorCode ?? nested?.code ?? body.errorCode ?? body.code
33134
33826
  );
@@ -33153,6 +33845,10 @@ async function parsePSError(response) {
33153
33845
  }
33154
33846
  // Annotate the CommonJS export names for ESM import in node:
33155
33847
  0 && (module.exports = {
33848
+ ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT,
33849
+ ADD_DATA_TYPES,
33850
+ AccountPersonalServerLiteOwnerBindingError,
33851
+ AccountPersonalServerRegistrationError,
33156
33852
  BUILDER_REGISTRATION_TYPES,
33157
33853
  BlockchainError,
33158
33854
  BrowserPlatformAdapter,
@@ -33163,8 +33859,11 @@ async function parsePSError(response) {
33163
33859
  DataFileEnvelopeSchema,
33164
33860
  DropboxStorage,
33165
33861
  ECIESError,
33862
+ ESCROW_DEPOSIT_ABI,
33166
33863
  ExpiredTokenError,
33864
+ FEE_REGISTRY_ABI,
33167
33865
  FILE_REGISTRATION_TYPES,
33866
+ GENERIC_PAYMENT_TYPES,
33168
33867
  GRANT_REGISTRATION_TYPES,
33169
33868
  GRANT_REVOCATION_TYPES,
33170
33869
  GoogleDriveStorage,
@@ -33175,11 +33874,17 @@ async function parsePSError(response) {
33175
33874
  IpfsStorage,
33176
33875
  MASTER_KEY_MESSAGE,
33177
33876
  MissingAuthError,
33877
+ NATIVE_VANA_ASSET,
33178
33878
  NetworkError,
33179
33879
  NodeECIESProvider,
33180
33880
  NodePlatformAdapter,
33181
33881
  NonceError,
33182
33882
  OAuthClient,
33883
+ PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX,
33884
+ PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE,
33885
+ PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION,
33886
+ PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID,
33887
+ PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT,
33183
33888
  PKCE_CHALLENGE_PATTERN,
33184
33889
  PKCE_VERIFIER_PATTERN,
33185
33890
  PSError,
@@ -33187,6 +33892,7 @@ async function parsePSError(response) {
33187
33892
  PersonalServerError,
33188
33893
  PinataStorage,
33189
33894
  R2Storage,
33895
+ RECORD_DATA_ACCESS_TYPES,
33190
33896
  ReadOnlyError,
33191
33897
  RelayerError,
33192
33898
  SERVER_REGISTRATION_TYPES,
@@ -33201,6 +33907,12 @@ async function parsePSError(response) {
33201
33907
  VanaError,
33202
33908
  VanaStorage,
33203
33909
  assertValidPkceVerifier,
33910
+ buildDepositNativeRequest,
33911
+ buildDepositTokenRequest,
33912
+ buildPersonalServerLiteOwnerBindingMessage,
33913
+ buildPersonalServerLiteOwnerBindingSignature,
33914
+ buildPersonalServerRegistrationSignature,
33915
+ buildPersonalServerRegistrationTypedData,
33204
33916
  buildWeb3SignedHeader,
33205
33917
  builderRegistrationDomain,
33206
33918
  chains,
@@ -33216,12 +33928,19 @@ async function parsePSError(response) {
33216
33928
  createPlatformAdapterFor,
33217
33929
  createPlatformAdapterSafe,
33218
33930
  createVanaStorageProvider,
33931
+ createViemPersonalServerLiteOwnerBindingSigner,
33932
+ createViemPersonalServerRegistrationSigner,
33933
+ dataRegistryDomain,
33219
33934
  decryptWithPassword,
33220
33935
  deriveMasterKey,
33221
33936
  deriveScopeKey,
33222
33937
  deserializeECIES,
33223
33938
  detectPlatform,
33939
+ encodeDepositNativeData,
33940
+ encodeDepositTokenData,
33224
33941
  encryptWithPassword,
33942
+ escrowContractAddress,
33943
+ escrowPaymentDomain,
33225
33944
  fileRegistrationDomain,
33226
33945
  generatePkceVerifier,
33227
33946
  getAbi,
@@ -33230,6 +33949,8 @@ async function parsePSError(response) {
33230
33949
  getContractAddress,
33231
33950
  getContractController,
33232
33951
  getContractInfo,
33952
+ getFee,
33953
+ getOpFee,
33233
33954
  getPlatformCapabilities,
33234
33955
  getServiceEndpoints,
33235
33956
  grantRegistrationDomain,
@@ -33241,16 +33962,20 @@ async function parsePSError(response) {
33241
33962
  moksha,
33242
33963
  mokshaServices,
33243
33964
  mokshaTestnet,
33244
- parseGrantRegistrationPayload,
33245
33965
  parsePSError,
33246
33966
  parseScope,
33247
33967
  parseWeb3SignedHeader,
33968
+ personalServerRegistrationDomain,
33248
33969
  recoverServerOwner,
33970
+ registerPersonalServerSignature,
33249
33971
  scopeCoveredByGrant,
33250
33972
  scopeMatchesPattern,
33251
33973
  scopeToPathSegments,
33252
33974
  serializeECIES,
33253
33975
  serverRegistrationDomain,
33976
+ signPersonalServerLiteOwnerBinding,
33977
+ signPersonalServerLiteOwnerBindingWithAccountClient,
33978
+ signPersonalServerRegistrationWithAccount,
33254
33979
  vanaMainnet,
33255
33980
  verifyGrantRegistration,
33256
33981
  verifyPkceChallenge,