@opendatalabs/vana-sdk 3.4.1 → 3.5.1-pr.159.12a6f39

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 (136) hide show
  1. package/README.md +116 -0
  2. package/dist/account/personal-server-lite-owner-binding.cjs +3 -3
  3. package/dist/account/personal-server-lite-owner-binding.cjs.map +1 -1
  4. package/dist/account/personal-server-lite-owner-binding.d.ts +2 -2
  5. package/dist/account/personal-server-lite-owner-binding.js +1 -1
  6. package/dist/account/personal-server-lite-owner-binding.js.map +1 -1
  7. package/dist/direct/access-request-client.cjs +104 -0
  8. package/dist/direct/access-request-client.cjs.map +1 -0
  9. package/dist/direct/access-request-client.d.ts +51 -0
  10. package/dist/direct/access-request-client.js +79 -0
  11. package/dist/direct/access-request-client.js.map +1 -0
  12. package/dist/direct/access-request-client.test.d.ts +1 -0
  13. package/dist/direct/connect-flow.cjs +152 -0
  14. package/dist/direct/connect-flow.cjs.map +1 -0
  15. package/dist/direct/connect-flow.d.ts +85 -0
  16. package/dist/direct/connect-flow.js +128 -0
  17. package/dist/direct/connect-flow.js.map +1 -0
  18. package/dist/direct/connect-flow.test.d.ts +1 -0
  19. package/dist/direct/controller.cjs +129 -0
  20. package/dist/direct/controller.cjs.map +1 -0
  21. package/dist/direct/controller.d.ts +152 -0
  22. package/dist/direct/controller.js +109 -0
  23. package/dist/direct/controller.js.map +1 -0
  24. package/dist/direct/controller.test.d.ts +1 -0
  25. package/dist/direct/endpoints.cjs +45 -0
  26. package/dist/direct/endpoints.cjs.map +1 -0
  27. package/dist/direct/endpoints.d.ts +22 -0
  28. package/dist/direct/endpoints.js +19 -0
  29. package/dist/direct/endpoints.js.map +1 -0
  30. package/dist/direct/errors.cjs +65 -0
  31. package/dist/direct/errors.cjs.map +1 -0
  32. package/dist/direct/errors.d.ts +44 -0
  33. package/dist/direct/errors.js +38 -0
  34. package/dist/direct/errors.js.map +1 -0
  35. package/dist/direct/escrow-payment.cjs +96 -0
  36. package/dist/direct/escrow-payment.cjs.map +1 -0
  37. package/dist/direct/escrow-payment.d.ts +81 -0
  38. package/dist/direct/escrow-payment.js +72 -0
  39. package/dist/direct/escrow-payment.js.map +1 -0
  40. package/dist/direct/escrow-payment.test.d.ts +1 -0
  41. package/dist/direct/personal-server-read.cjs +149 -0
  42. package/dist/direct/personal-server-read.cjs.map +1 -0
  43. package/dist/direct/personal-server-read.d.ts +103 -0
  44. package/dist/direct/personal-server-read.js +124 -0
  45. package/dist/direct/personal-server-read.js.map +1 -0
  46. package/dist/direct/personal-server-read.test.d.ts +1 -0
  47. package/dist/direct/types.cjs +35 -0
  48. package/dist/direct/types.cjs.map +1 -0
  49. package/dist/direct/types.d.ts +205 -0
  50. package/dist/direct/types.js +11 -0
  51. package/dist/direct/types.js.map +1 -0
  52. package/dist/direct/use-direct-vana-connect.cjs +68 -0
  53. package/dist/direct/use-direct-vana-connect.cjs.map +1 -0
  54. package/dist/direct/use-direct-vana-connect.d.ts +45 -0
  55. package/dist/direct/use-direct-vana-connect.js +46 -0
  56. package/dist/direct/use-direct-vana-connect.js.map +1 -0
  57. package/dist/index.browser.d.ts +9 -4
  58. package/dist/index.browser.js +644 -178
  59. package/dist/index.browser.js.map +4 -4
  60. package/dist/index.node.cjs +672 -183
  61. package/dist/index.node.cjs.map +4 -4
  62. package/dist/index.node.d.ts +9 -4
  63. package/dist/index.node.js +644 -178
  64. package/dist/index.node.js.map +4 -4
  65. package/dist/personal-server-lite/owner-binding.cjs +93 -0
  66. package/dist/personal-server-lite/owner-binding.cjs.map +1 -0
  67. package/dist/personal-server-lite/owner-binding.d.ts +44 -0
  68. package/dist/personal-server-lite/owner-binding.js +65 -0
  69. package/dist/personal-server-lite/owner-binding.js.map +1 -0
  70. package/dist/personal-server-lite/owner-binding.test.d.ts +1 -0
  71. package/dist/protocol/data-point-status.cjs +80 -0
  72. package/dist/protocol/data-point-status.cjs.map +1 -0
  73. package/dist/protocol/data-point-status.d.ts +34 -0
  74. package/dist/protocol/data-point-status.js +51 -0
  75. package/dist/protocol/data-point-status.js.map +1 -0
  76. package/dist/protocol/data-point-status.test.d.ts +1 -0
  77. package/dist/protocol/eip712.cjs +53 -31
  78. package/dist/protocol/eip712.cjs.map +1 -1
  79. package/dist/protocol/eip712.d.ts +98 -43
  80. package/dist/protocol/eip712.js +47 -27
  81. package/dist/protocol/eip712.js.map +1 -1
  82. package/dist/protocol/escrow-deposit.cjs +89 -0
  83. package/dist/protocol/escrow-deposit.cjs.map +1 -0
  84. package/dist/protocol/escrow-deposit.d.ts +47 -0
  85. package/dist/protocol/escrow-deposit.js +60 -0
  86. package/dist/protocol/escrow-deposit.js.map +1 -0
  87. package/dist/protocol/escrow-deposit.test.d.ts +1 -0
  88. package/dist/protocol/escrow-flow.test.d.ts +21 -0
  89. package/dist/protocol/escrow.cjs +146 -0
  90. package/dist/protocol/escrow.cjs.map +1 -0
  91. package/dist/protocol/escrow.d.ts +336 -0
  92. package/dist/protocol/escrow.js +118 -0
  93. package/dist/protocol/escrow.js.map +1 -0
  94. package/dist/protocol/escrow.test.d.ts +1 -0
  95. package/dist/protocol/fee-registry.cjs +116 -0
  96. package/dist/protocol/fee-registry.cjs.map +1 -0
  97. package/dist/protocol/fee-registry.d.ts +151 -0
  98. package/dist/protocol/fee-registry.js +89 -0
  99. package/dist/protocol/fee-registry.js.map +1 -0
  100. package/dist/protocol/fee-registry.test.d.ts +1 -0
  101. package/dist/protocol/gateway.cjs +107 -37
  102. package/dist/protocol/gateway.cjs.map +1 -1
  103. package/dist/protocol/gateway.d.ts +223 -57
  104. package/dist/protocol/gateway.js +107 -37
  105. package/dist/protocol/gateway.js.map +1 -1
  106. package/dist/protocol/grants.cjs +27 -64
  107. package/dist/protocol/grants.cjs.map +1 -1
  108. package/dist/protocol/grants.d.ts +6 -13
  109. package/dist/protocol/grants.js +27 -63
  110. package/dist/protocol/grants.js.map +1 -1
  111. package/dist/protocol/personal-server-data.cjs +71 -0
  112. package/dist/protocol/personal-server-data.cjs.map +1 -0
  113. package/dist/protocol/personal-server-data.d.ts +16 -0
  114. package/dist/protocol/personal-server-data.js +47 -0
  115. package/dist/protocol/personal-server-data.js.map +1 -0
  116. package/dist/protocol/personal-server-data.test.d.ts +1 -0
  117. package/dist/protocol/personal-server-registration.cjs +16 -4
  118. package/dist/protocol/personal-server-registration.cjs.map +1 -1
  119. package/dist/protocol/personal-server-registration.d.ts +5 -2
  120. package/dist/protocol/personal-server-registration.js +16 -4
  121. package/dist/protocol/personal-server-registration.js.map +1 -1
  122. package/dist/react.cjs +32 -0
  123. package/dist/react.cjs.map +1 -0
  124. package/dist/react.d.ts +33 -0
  125. package/dist/react.js +11 -0
  126. package/dist/react.js.map +1 -0
  127. package/dist/server.cjs +73 -0
  128. package/dist/server.cjs.map +1 -0
  129. package/dist/server.d.ts +32 -0
  130. package/dist/server.js +55 -0
  131. package/dist/server.js.map +1 -0
  132. package/dist/storage/providers/vana-storage.cjs +75 -17
  133. package/dist/storage/providers/vana-storage.cjs.map +1 -1
  134. package/dist/storage/providers/vana-storage.js +75 -17
  135. package/dist/storage/providers/vana-storage.js.map +1 -1
  136. package/package.json +20 -1
@@ -1174,6 +1174,7 @@ var init_browser2 = __esm({
1174
1174
  var index_node_exports = {};
1175
1175
  __export(index_node_exports, {
1176
1176
  ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT: () => ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT,
1177
+ ADD_DATA_TYPES: () => ADD_DATA_TYPES,
1177
1178
  AccountPersonalServerLiteOwnerBindingError: () => AccountPersonalServerLiteOwnerBindingError,
1178
1179
  AccountPersonalServerRegistrationError: () => AccountPersonalServerRegistrationError,
1179
1180
  BUILDER_REGISTRATION_TYPES: () => BUILDER_REGISTRATION_TYPES,
@@ -1183,12 +1184,15 @@ __export(index_node_exports, {
1183
1184
  CallbackStorage: () => CallbackStorage,
1184
1185
  ContractFactory: () => ContractFactory,
1185
1186
  ContractNotFoundError: () => ContractNotFoundError,
1187
+ DATA_REGISTRY_STATUS_ABI: () => DATA_REGISTRY_STATUS_ABI,
1186
1188
  DataFileEnvelopeSchema: () => DataFileEnvelopeSchema,
1189
+ DataPointStatus: () => DataPointStatus,
1187
1190
  DropboxStorage: () => DropboxStorage,
1188
1191
  ECIESError: () => ECIESError,
1192
+ ESCROW_DEPOSIT_ABI: () => ESCROW_DEPOSIT_ABI2,
1189
1193
  ExpiredTokenError: () => ExpiredTokenError,
1190
- FILE_DELETION_TYPES: () => FILE_DELETION_TYPES,
1191
- FILE_REGISTRATION_TYPES: () => FILE_REGISTRATION_TYPES,
1194
+ FEE_REGISTRY_ABI: () => FEE_REGISTRY_ABI,
1195
+ GENERIC_PAYMENT_TYPES: () => GENERIC_PAYMENT_TYPES,
1192
1196
  GRANT_REGISTRATION_TYPES: () => GRANT_REGISTRATION_TYPES,
1193
1197
  GRANT_REVOCATION_TYPES: () => GRANT_REVOCATION_TYPES,
1194
1198
  GoogleDriveStorage: () => GoogleDriveStorage,
@@ -1199,6 +1203,8 @@ __export(index_node_exports, {
1199
1203
  IpfsStorage: () => IpfsStorage,
1200
1204
  MASTER_KEY_MESSAGE: () => MASTER_KEY_MESSAGE,
1201
1205
  MissingAuthError: () => MissingAuthError,
1206
+ NATIVE_ASSET_ADDRESS: () => NATIVE_ASSET_ADDRESS,
1207
+ NATIVE_VANA_ASSET: () => NATIVE_VANA_ASSET,
1202
1208
  NetworkError: () => NetworkError,
1203
1209
  NodeECIESProvider: () => NodeECIESUint8Provider,
1204
1210
  NodePlatformAdapter: () => NodePlatformAdapter,
@@ -1216,6 +1222,8 @@ __export(index_node_exports, {
1216
1222
  PersonalServerError: () => PersonalServerError,
1217
1223
  PinataStorage: () => PinataStorage,
1218
1224
  R2Storage: () => R2Storage,
1225
+ RECORD_DATA_ACCESS_TYPES: () => RECORD_DATA_ACCESS_TYPES,
1226
+ REGISTRATION_KIND_FOR_OP: () => REGISTRATION_KIND_FOR_OP,
1219
1227
  ReadOnlyError: () => ReadOnlyError,
1220
1228
  RelayerError: () => RelayerError,
1221
1229
  SERVER_REGISTRATION_TYPES: () => SERVER_REGISTRATION_TYPES,
@@ -1230,10 +1238,15 @@ __export(index_node_exports, {
1230
1238
  VanaError: () => VanaError,
1231
1239
  VanaStorage: () => VanaStorage,
1232
1240
  assertValidPkceVerifier: () => assertValidPkceVerifier,
1241
+ buildDepositNativeRequest: () => buildDepositNativeRequest,
1242
+ buildDepositTokenRequest: () => buildDepositTokenRequest,
1243
+ buildMarkDataPointUnavailableRequest: () => buildMarkDataPointUnavailableRequest,
1244
+ buildPersonalServerDataReadRequest: () => buildPersonalServerDataReadRequest,
1233
1245
  buildPersonalServerLiteOwnerBindingMessage: () => buildPersonalServerLiteOwnerBindingMessage,
1234
1246
  buildPersonalServerLiteOwnerBindingSignature: () => buildPersonalServerLiteOwnerBindingSignature,
1235
1247
  buildPersonalServerRegistrationSignature: () => buildPersonalServerRegistrationSignature,
1236
1248
  buildPersonalServerRegistrationTypedData: () => buildPersonalServerRegistrationTypedData,
1249
+ buildSetDataPointStatusRequest: () => buildSetDataPointStatusRequest,
1237
1250
  buildWeb3SignedHeader: () => buildWeb3SignedHeader,
1238
1251
  builderRegistrationDomain: () => builderRegistrationDomain,
1239
1252
  chains: () => chains,
@@ -1243,6 +1256,7 @@ __export(index_node_exports, {
1243
1256
  contractCacheForTesting: () => contractCacheForTesting,
1244
1257
  createBrowserPlatformAdapter: () => createBrowserPlatformAdapter,
1245
1258
  createDataFileEnvelope: () => createDataFileEnvelope,
1259
+ createEscrowGatewayClient: () => createEscrowGatewayClient,
1246
1260
  createGatewayClient: () => createGatewayClient,
1247
1261
  createNodePlatformAdapter: () => createNodePlatformAdapter,
1248
1262
  createPlatformAdapter: () => createPlatformAdapter,
@@ -1251,21 +1265,29 @@ __export(index_node_exports, {
1251
1265
  createVanaStorageProvider: () => createVanaStorageProvider,
1252
1266
  createViemPersonalServerLiteOwnerBindingSigner: () => createViemPersonalServerLiteOwnerBindingSigner,
1253
1267
  createViemPersonalServerRegistrationSigner: () => createViemPersonalServerRegistrationSigner,
1268
+ dataRegistryContractAddress: () => dataRegistryContractAddress,
1269
+ dataRegistryDomain: () => dataRegistryDomain,
1254
1270
  decryptWithPassword: () => decryptWithPassword,
1255
1271
  deriveMasterKey: () => deriveMasterKey,
1256
1272
  deriveScopeKey: () => deriveScopeKey,
1257
1273
  deserializeECIES: () => deserializeECIES,
1258
1274
  detectPlatform: () => detectPlatform,
1275
+ encodeDepositNativeData: () => encodeDepositNativeData,
1276
+ encodeDepositTokenData: () => encodeDepositTokenData,
1277
+ encodeSetDataPointStatusData: () => encodeSetDataPointStatusData,
1259
1278
  encryptWithPassword: () => encryptWithPassword,
1260
- fileDeletionDomain: () => fileDeletionDomain,
1261
- fileRegistrationDomain: () => fileRegistrationDomain,
1279
+ escrowContractAddress: () => escrowContractAddress,
1280
+ escrowPaymentDomain: () => escrowPaymentDomain,
1262
1281
  generatePkceVerifier: () => generatePkceVerifier,
1282
+ genericPaymentDomain: () => genericPaymentDomain,
1263
1283
  getAbi: () => getAbi,
1264
1284
  getAllChains: () => getAllChains,
1265
1285
  getChainConfig: () => getChainConfig,
1266
1286
  getContractAddress: () => getContractAddress,
1267
1287
  getContractController: () => getContractController,
1268
1288
  getContractInfo: () => getContractInfo,
1289
+ getFee: () => getFee,
1290
+ getOpFee: () => getOpFee,
1269
1291
  getPlatformCapabilities: () => getPlatformCapabilities,
1270
1292
  getServiceEndpoints: () => getServiceEndpoints,
1271
1293
  grantRegistrationDomain: () => grantRegistrationDomain,
@@ -1277,11 +1299,12 @@ __export(index_node_exports, {
1277
1299
  moksha: () => moksha,
1278
1300
  mokshaServices: () => mokshaServices,
1279
1301
  mokshaTestnet: () => mokshaTestnet2,
1280
- parseGrantRegistrationPayload: () => parseGrantRegistrationPayload,
1281
1302
  parsePSError: () => parsePSError,
1282
1303
  parseScope: () => parseScope,
1283
1304
  parseWeb3SignedHeader: () => parseWeb3SignedHeader,
1305
+ personalServerDataReadPath: () => personalServerDataReadPath,
1284
1306
  personalServerRegistrationDomain: () => personalServerRegistrationDomain,
1307
+ readPersonalServerData: () => readPersonalServerData,
1285
1308
  recoverServerOwner: () => recoverServerOwner,
1286
1309
  registerPersonalServerSignature: () => registerPersonalServerSignature,
1287
1310
  scopeCoveredByGrant: () => scopeCoveredByGrant,
@@ -29164,6 +29187,8 @@ async function buildWeb3SignedHeader(params) {
29164
29187
  var DEFAULT_ENDPOINT = "https://storage.vana.org";
29165
29188
  var BLOB_PATH_PREFIX = "/v1/blobs";
29166
29189
  var DEFAULT_TOKEN_TTL_SECONDS = 300;
29190
+ var MAX_UPLOAD_ATTEMPTS = 4;
29191
+ var MAX_RATE_LIMIT_DELAY_MS = 3e4;
29167
29192
  var VanaStorage = class {
29168
29193
  endpoint;
29169
29194
  signer;
@@ -29202,27 +29227,46 @@ var VanaStorage = class {
29202
29227
  const body = new Uint8Array(await file.arrayBuffer());
29203
29228
  const contentType = file.type !== "" ? file.type : "application/octet-stream";
29204
29229
  const header = await this.signRequest("PUT", path, body);
29205
- let response;
29206
- try {
29207
- response = await this.fetchImpl(`${this.endpoint}${path}`, {
29208
- method: "PUT",
29209
- headers: {
29210
- authorization: header,
29211
- "content-type": contentType
29212
- },
29213
- body
29214
- });
29215
- } catch (cause) {
29230
+ let response = null;
29231
+ let responseText = "";
29232
+ for (let attempt = 1; attempt <= MAX_UPLOAD_ATTEMPTS; attempt++) {
29233
+ try {
29234
+ response = await this.fetchImpl(`${this.endpoint}${path}`, {
29235
+ method: "PUT",
29236
+ headers: {
29237
+ authorization: header,
29238
+ "content-type": contentType
29239
+ },
29240
+ body
29241
+ });
29242
+ } catch (cause) {
29243
+ throw new StorageError(
29244
+ `vana-storage upload network error: ${describe(cause)}`,
29245
+ "UPLOAD_ERROR",
29246
+ "vana-storage",
29247
+ { cause: cause instanceof Error ? cause : void 0 }
29248
+ );
29249
+ }
29250
+ if (response.ok) {
29251
+ break;
29252
+ }
29253
+ responseText = await safeText(response);
29254
+ if (response.status === 429 && attempt < MAX_UPLOAD_ATTEMPTS) {
29255
+ const delayMs = retryDelayMs(response, responseText);
29256
+ if (delayMs > 0) {
29257
+ await sleep(delayMs);
29258
+ }
29259
+ continue;
29260
+ }
29216
29261
  throw new StorageError(
29217
- `vana-storage upload network error: ${describe(cause)}`,
29218
- "UPLOAD_ERROR",
29219
- "vana-storage",
29220
- { cause: cause instanceof Error ? cause : void 0 }
29262
+ `vana-storage upload failed: ${response.status} ${response.statusText} - ${responseText}`,
29263
+ "UPLOAD_FAILED",
29264
+ "vana-storage"
29221
29265
  );
29222
29266
  }
29223
- if (!response.ok) {
29267
+ if (!response?.ok) {
29224
29268
  throw new StorageError(
29225
- `vana-storage upload failed: ${response.status} ${response.statusText} - ${await safeText(response)}`,
29269
+ `vana-storage upload failed after ${MAX_UPLOAD_ATTEMPTS} attempts - ${responseText}`,
29226
29270
  "UPLOAD_FAILED",
29227
29271
  "vana-storage"
29228
29272
  );
@@ -29375,6 +29419,43 @@ function describe(value) {
29375
29419
  if (value instanceof Error) return value.message;
29376
29420
  return String(value);
29377
29421
  }
29422
+ function retryDelayMs(response, responseText) {
29423
+ const headerDelayMs = parseRetryAfterHeaderMs(
29424
+ response.headers.get("retry-after")
29425
+ );
29426
+ if (headerDelayMs !== null) {
29427
+ return clampRateLimitDelay(headerDelayMs);
29428
+ }
29429
+ return clampRateLimitDelay(parseRetryAfterBodyMs(responseText) ?? 0);
29430
+ }
29431
+ function parseRetryAfterHeaderMs(value) {
29432
+ if (!value) return null;
29433
+ const seconds = Number(value);
29434
+ if (Number.isFinite(seconds)) {
29435
+ return seconds * 1e3;
29436
+ }
29437
+ const dateMs = Date.parse(value);
29438
+ if (Number.isFinite(dateMs)) {
29439
+ return Math.max(0, dateMs - Date.now());
29440
+ }
29441
+ return null;
29442
+ }
29443
+ function parseRetryAfterBodyMs(responseText) {
29444
+ if (!responseText) return null;
29445
+ try {
29446
+ const parsed = JSON.parse(responseText);
29447
+ const seconds = Number(parsed.retryAfter);
29448
+ return Number.isFinite(seconds) ? seconds * 1e3 : null;
29449
+ } catch {
29450
+ return null;
29451
+ }
29452
+ }
29453
+ function clampRateLimitDelay(delayMs) {
29454
+ return Math.min(Math.max(0, delayMs), MAX_RATE_LIMIT_DELAY_MS);
29455
+ }
29456
+ function sleep(ms) {
29457
+ return new Promise((resolve) => setTimeout(resolve, ms));
29458
+ }
29378
29459
  async function safeText(response) {
29379
29460
  try {
29380
29461
  return await response.text();
@@ -32649,6 +32730,7 @@ function formatOAuthError(body, status) {
32649
32730
  // src/protocol/eip712.ts
32650
32731
  var DOMAIN_NAME = "Vana Data Portability";
32651
32732
  var DOMAIN_VERSION = "1";
32733
+ var NATIVE_VANA_ASSET = "0x0000000000000000000000000000000000000000";
32652
32734
  function buildDomain(chainId, verifyingContract) {
32653
32735
  return {
32654
32736
  name: DOMAIN_NAME,
@@ -32657,13 +32739,7 @@ function buildDomain(chainId, verifyingContract) {
32657
32739
  verifyingContract
32658
32740
  };
32659
32741
  }
32660
- function fileRegistrationDomain(config) {
32661
- return buildDomain(
32662
- config.chainId,
32663
- config.contracts.dataRegistry
32664
- );
32665
- }
32666
- function fileDeletionDomain(config) {
32742
+ function dataRegistryDomain(config) {
32667
32743
  return buildDomain(
32668
32744
  config.chainId,
32669
32745
  config.contracts.dataRegistry
@@ -32693,31 +32769,26 @@ function builderRegistrationDomain(config) {
32693
32769
  config.contracts.dataPortabilityGrantees
32694
32770
  );
32695
32771
  }
32696
- var FILE_REGISTRATION_TYPES = {
32697
- FileRegistration: [
32698
- { name: "ownerAddress", type: "address" },
32699
- { name: "url", type: "string" },
32700
- { name: "schemaId", type: "bytes32" }
32701
- ]
32702
- };
32703
- var FILE_DELETION_TYPES = {
32704
- FileDeletion: [
32705
- { name: "ownerAddress", type: "address" },
32706
- { name: "fileId", type: "bytes32" }
32707
- ]
32708
- };
32772
+ function escrowPaymentDomain(config) {
32773
+ return buildDomain(
32774
+ config.chainId,
32775
+ config.contracts.dataPortabilityEscrow
32776
+ );
32777
+ }
32709
32778
  var GRANT_REGISTRATION_TYPES = {
32710
32779
  GrantRegistration: [
32711
32780
  { name: "grantorAddress", type: "address" },
32712
32781
  { name: "granteeId", type: "bytes32" },
32713
- { name: "grant", type: "string" },
32714
- { name: "fileIds", type: "uint256[]" }
32782
+ { name: "scopes", type: "string[]" },
32783
+ { name: "grantVersion", type: "uint256" },
32784
+ { name: "expiresAt", type: "uint256" }
32715
32785
  ]
32716
32786
  };
32717
32787
  var GRANT_REVOCATION_TYPES = {
32718
32788
  GrantRevocation: [
32719
32789
  { name: "grantorAddress", type: "address" },
32720
- { name: "grantId", type: "bytes32" }
32790
+ { name: "grantId", type: "bytes32" },
32791
+ { name: "grantVersion", type: "uint256" }
32721
32792
  ]
32722
32793
  };
32723
32794
  var SERVER_REGISTRATION_TYPES = {
@@ -32736,11 +32807,32 @@ var BUILDER_REGISTRATION_TYPES = {
32736
32807
  { name: "appUrl", type: "string" }
32737
32808
  ]
32738
32809
  };
32810
+ var ADD_DATA_TYPES = {
32811
+ AddData: [
32812
+ { name: "ownerAddress", type: "address" },
32813
+ { name: "scope", type: "string" },
32814
+ { name: "dataHash", type: "bytes32" },
32815
+ { name: "metadataHash", type: "bytes32" },
32816
+ { name: "expectedVersion", type: "uint256" }
32817
+ ]
32818
+ };
32819
+ var RECORD_DATA_ACCESS_TYPES = {
32820
+ RecordDataAccess: [
32821
+ { name: "ownerAddress", type: "address" },
32822
+ { name: "scope", type: "string" },
32823
+ { name: "version", type: "uint256" },
32824
+ { name: "accessor", type: "address" },
32825
+ { name: "recordId", type: "bytes32" }
32826
+ ]
32827
+ };
32739
32828
 
32740
32829
  // src/protocol/personal-server-registration.ts
32741
32830
  var import_viem14 = require("viem");
32742
- var PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID = 1480;
32743
- var PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT = "0x1483B1F634DBA75AeaE60da7f01A679aabd5ee2c";
32831
+ var PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID = vanaMainnet2.id;
32832
+ var PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT = getContractAddress(
32833
+ PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID,
32834
+ "DataPortabilityServers"
32835
+ );
32744
32836
  function assertAddress(value, name) {
32745
32837
  if (!(0, import_viem14.isAddress)(value)) {
32746
32838
  throw new Error(`${name} must be a valid EVM address`);
@@ -32755,6 +32847,12 @@ function getAccountAddress(account) {
32755
32847
  function isPersonalServerRegistrationSigner(source) {
32756
32848
  return "address" in source && typeof source.signTypedData === "function";
32757
32849
  }
32850
+ function getDefaultServerRegistrationContract(chainId) {
32851
+ return getContractAddress(
32852
+ chainId,
32853
+ "DataPortabilityServers"
32854
+ );
32855
+ }
32758
32856
  function createViemPersonalServerRegistrationSigner(source, options = {}) {
32759
32857
  if (isPersonalServerRegistrationSigner(source)) {
32760
32858
  return source;
@@ -32777,12 +32875,13 @@ function personalServerRegistrationDomain(input = {}) {
32777
32875
  if (input.config) {
32778
32876
  return serverRegistrationDomain(input.config);
32779
32877
  }
32780
- const verifyingContract = input.verifyingContract ?? PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT;
32878
+ const chainId = input.chainId ?? PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID;
32879
+ const verifyingContract = input.verifyingContract ?? getDefaultServerRegistrationContract(chainId);
32781
32880
  assertAddress(verifyingContract, "verifyingContract");
32782
32881
  return {
32783
32882
  name: "Vana Data Portability",
32784
32883
  version: "1",
32785
- chainId: input.chainId ?? PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID,
32884
+ chainId,
32786
32885
  verifyingContract
32787
32886
  };
32788
32887
  }
@@ -32820,9 +32919,9 @@ async function buildPersonalServerRegistrationSignature(input) {
32820
32919
  }
32821
32920
  var registerPersonalServerSignature = buildPersonalServerRegistrationSignature;
32822
32921
 
32823
- // src/protocol/personal-server-lite-owner-binding.ts
32922
+ // src/personal-server-lite/owner-binding.ts
32824
32923
  var import_viem15 = require("viem");
32825
- var PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION = "vana.account.v1";
32924
+ var PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION = "vana.ps-lite.owner-binding.v1";
32826
32925
  var PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE = "ps-lite-owner";
32827
32926
  var PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX = `${PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION}:${PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE}:`;
32828
32927
  function assertAddress2(value, name) {
@@ -33173,67 +33272,34 @@ function isDataPortabilityGatewayConfig(value) {
33173
33272
  return false;
33174
33273
  }
33175
33274
  const c = contracts;
33176
- return isHexString(c["dataRegistry"]) && isHexString(c["dataPortabilityPermissions"]) && isHexString(c["dataPortabilityServer"]) && isHexString(c["dataPortabilityGrantees"]);
33275
+ return isHexString(c["dataRegistry"]) && isHexString(c["dataPortabilityPermissions"]) && isHexString(c["dataPortabilityServer"]) && isHexString(c["dataPortabilityGrantees"]) && isHexString(c["dataPortabilityEscrow"]) && isHexString(c["feeRegistry"]);
33177
33276
  }
33178
- function parseGrantRegistrationPayload(grant) {
33179
- let parsed;
33277
+ function toUint256(value) {
33180
33278
  try {
33181
- parsed = JSON.parse(grant);
33182
- } catch {
33183
- return null;
33184
- }
33185
- if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
33186
- return null;
33187
- }
33188
- const value = parsed;
33189
- if (!Array.isArray(value["scopes"]) || value["scopes"].length === 0) {
33190
- return null;
33191
- }
33192
- if (!value["scopes"].every((scope) => typeof scope === "string")) {
33193
- return null;
33194
- }
33195
- if (typeof value["expiresAt"] !== "number" || !Number.isFinite(value["expiresAt"])) {
33196
- return null;
33197
- }
33198
- if (value["user"] !== void 0 && !isHexString(value["user"])) {
33199
- return null;
33200
- }
33201
- if (value["builder"] !== void 0 && !isHexString(value["builder"])) {
33202
- return null;
33203
- }
33204
- if (value["nonce"] !== void 0 && (typeof value["nonce"] !== "number" || !Number.isFinite(value["nonce"]))) {
33205
- return null;
33206
- }
33207
- return {
33208
- user: value["user"],
33209
- builder: value["builder"],
33210
- scopes: value["scopes"],
33211
- expiresAt: value["expiresAt"],
33212
- nonce: value["nonce"]
33213
- };
33214
- }
33215
- function parseFileIds(fileIds) {
33216
- try {
33217
- const values = (fileIds ?? []).map((fileId) => BigInt(fileId));
33218
- return {
33219
- values,
33220
- display: values.map((fileId) => fileId.toString())
33221
- };
33279
+ if (typeof value === "number" && !Number.isSafeInteger(value)) {
33280
+ return null;
33281
+ }
33282
+ const big = typeof value === "bigint" ? value : BigInt(value);
33283
+ if (big < 0n) return null;
33284
+ return big;
33222
33285
  } catch {
33223
33286
  return null;
33224
33287
  }
33225
33288
  }
33226
33289
  async function verifyGrantRegistration(input) {
33227
- const payload = parseGrantRegistrationPayload(input.grant);
33228
- if (!payload) {
33229
- return {
33230
- valid: false,
33231
- error: "Grant must be JSON with scopes and expiresAt"
33232
- };
33290
+ if (!Array.isArray(input.scopes) || input.scopes.length === 0) {
33291
+ return { valid: false, error: "scopes must be a non-empty array" };
33292
+ }
33293
+ if (!input.scopes.every((scope) => typeof scope === "string")) {
33294
+ return { valid: false, error: "scopes must contain only strings" };
33233
33295
  }
33234
- const fileIds = parseFileIds(input.fileIds);
33235
- if (!fileIds) {
33236
- return { valid: false, error: "fileIds must contain integer values" };
33296
+ const grantVersion = toUint256(input.grantVersion);
33297
+ if (grantVersion === null || grantVersion < 1n) {
33298
+ return { valid: false, error: "grantVersion must be a uint256 >= 1" };
33299
+ }
33300
+ const expiresAt = toUint256(input.expiresAt);
33301
+ if (expiresAt === null) {
33302
+ return { valid: false, error: "expiresAt must be a non-negative uint256" };
33237
33303
  }
33238
33304
  let valid;
33239
33305
  try {
@@ -33245,8 +33311,9 @@ async function verifyGrantRegistration(input) {
33245
33311
  message: {
33246
33312
  grantorAddress: input.grantorAddress,
33247
33313
  granteeId: input.granteeId,
33248
- grant: input.grant,
33249
- fileIds: fileIds.values
33314
+ scopes: input.scopes,
33315
+ grantVersion,
33316
+ expiresAt
33250
33317
  },
33251
33318
  signature: input.signature
33252
33319
  });
@@ -33257,26 +33324,269 @@ async function verifyGrantRegistration(input) {
33257
33324
  return { valid: false, error: "Grant signature does not match grantor" };
33258
33325
  }
33259
33326
  const nowSeconds = input.nowSeconds ?? Math.floor(Date.now() / 1e3);
33260
- if (payload.expiresAt > 0 && payload.expiresAt < nowSeconds) {
33327
+ if (expiresAt > 0n && expiresAt < BigInt(nowSeconds)) {
33261
33328
  return { valid: false, error: "Grant has expired" };
33262
33329
  }
33263
- if (payload.user !== void 0 && payload.user.toLowerCase() !== input.grantorAddress.toLowerCase()) {
33264
- return { valid: false, error: "Grant user does not match grantorAddress" };
33265
- }
33266
33330
  return {
33267
33331
  valid: true,
33268
33332
  grantorAddress: input.grantorAddress,
33269
33333
  granteeId: input.granteeId,
33270
- grant: input.grant,
33271
- payload,
33272
- fileIds: fileIds.display
33334
+ scopes: input.scopes,
33335
+ grantVersion: grantVersion.toString(),
33336
+ expiresAt: expiresAt.toString()
33273
33337
  };
33274
33338
  }
33275
33339
 
33276
- // src/protocol/scopes.ts
33340
+ // src/protocol/fee-registry.ts
33341
+ var import_viem18 = require("viem");
33342
+ var FEE_REGISTRY_ABI = (0, import_viem18.parseAbi)([
33343
+ "struct Fee { uint256 amount; address asset; address payee; bool enabled; }",
33344
+ "function fees(bytes32 operation) view returns (Fee)",
33345
+ "function operationKey(string name) pure returns (bytes32)"
33346
+ ]);
33347
+ var REGISTRATION_KIND_FOR_OP = {
33348
+ grant: "grant_registration",
33349
+ data: "data_registration",
33350
+ server: "server_registration",
33351
+ builder: "builder_registration"
33352
+ };
33353
+ function operationNameFor(kind, opts) {
33354
+ switch (kind) {
33355
+ case "grant_registration":
33356
+ return opts?.grantRegistrationOpName ?? "grant_registration";
33357
+ case "data_access":
33358
+ return opts?.dataAccessOpName ?? "data_access";
33359
+ case "data_registration":
33360
+ return opts?.dataRegistrationOpName ?? "data_registration";
33361
+ case "server_registration":
33362
+ return opts?.serverRegistrationOpName ?? "server_registration";
33363
+ case "builder_registration":
33364
+ return opts?.builderRegistrationOpName ?? "builder_registration";
33365
+ }
33366
+ }
33367
+ var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
33368
+ async function getFee(client, config, kind, opts) {
33369
+ const address = config.contracts.feeRegistry;
33370
+ const opName = operationNameFor(kind, opts);
33371
+ const opKey = await client.readContract({
33372
+ address,
33373
+ abi: FEE_REGISTRY_ABI,
33374
+ functionName: "operationKey",
33375
+ args: [opName]
33376
+ });
33377
+ const fee = await client.readContract({
33378
+ address,
33379
+ abi: FEE_REGISTRY_ABI,
33380
+ functionName: "fees",
33381
+ args: [opKey]
33382
+ });
33383
+ if (fee.enabled && fee.payee === ZERO_ADDRESS) {
33384
+ throw new Error(
33385
+ `FeeRegistry: enabled operation "${opName}" has zero-address payee \u2014 contract pre-flight rejects payouts to 0x0`
33386
+ );
33387
+ }
33388
+ return fee;
33389
+ }
33390
+ async function getOpFee(client, config, opType, opts) {
33391
+ const registrationKind = REGISTRATION_KIND_FOR_OP[opType];
33392
+ if (!registrationKind) {
33393
+ throw new Error(
33394
+ `getOpFee: unknown opType "${opType}" \u2014 supported types are ${Object.keys(REGISTRATION_KIND_FOR_OP).join(", ")}`
33395
+ );
33396
+ }
33397
+ const includeDataAccess = opType === "grant";
33398
+ const [registration, dataAccess] = await Promise.all([
33399
+ getFee(client, config, registrationKind, opts),
33400
+ includeDataAccess ? getFee(client, config, "data_access", opts) : Promise.resolve({
33401
+ amount: 0n,
33402
+ asset: ZERO_ADDRESS,
33403
+ payee: ZERO_ADDRESS,
33404
+ enabled: false
33405
+ })
33406
+ ]);
33407
+ if (registration.enabled && dataAccess.enabled && registration.asset.toLowerCase() !== dataAccess.asset.toLowerCase()) {
33408
+ throw new Error(
33409
+ `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.`
33410
+ );
33411
+ }
33412
+ const asset = registration.enabled ? registration.asset : dataAccess.enabled ? dataAccess.asset : ZERO_ADDRESS;
33413
+ return {
33414
+ asset,
33415
+ registrationFee: registration.enabled ? registration.amount : 0n,
33416
+ dataAccessFee: dataAccess.enabled ? dataAccess.amount : 0n,
33417
+ registrationEnabled: registration.enabled,
33418
+ dataAccessEnabled: dataAccess.enabled,
33419
+ registrationPayee: registration.enabled ? registration.payee : ZERO_ADDRESS,
33420
+ dataAccessPayee: dataAccess.enabled ? dataAccess.payee : ZERO_ADDRESS
33421
+ };
33422
+ }
33423
+
33424
+ // src/protocol/escrow-deposit.ts
33425
+ var import_viem19 = require("viem");
33426
+ var ESCROW_DEPOSIT_ABI = [
33427
+ {
33428
+ type: "function",
33429
+ name: "depositNative",
33430
+ stateMutability: "payable",
33431
+ inputs: [{ name: "account", type: "address" }],
33432
+ outputs: []
33433
+ },
33434
+ {
33435
+ type: "function",
33436
+ name: "depositToken",
33437
+ stateMutability: "nonpayable",
33438
+ inputs: [
33439
+ { name: "account", type: "address" },
33440
+ { name: "token", type: "address" },
33441
+ { name: "amount", type: "uint256" }
33442
+ ],
33443
+ outputs: []
33444
+ }
33445
+ ];
33446
+ function escrowContractAddress(config) {
33447
+ return config.contracts.dataPortabilityEscrow;
33448
+ }
33449
+ function encodeDepositNativeData(input) {
33450
+ return (0, import_viem19.encodeFunctionData)({
33451
+ abi: ESCROW_DEPOSIT_ABI,
33452
+ functionName: "depositNative",
33453
+ args: [input.account]
33454
+ });
33455
+ }
33456
+ function encodeDepositTokenData(input) {
33457
+ return (0, import_viem19.encodeFunctionData)({
33458
+ abi: ESCROW_DEPOSIT_ABI,
33459
+ functionName: "depositToken",
33460
+ args: [input.account, input.token, input.amount]
33461
+ });
33462
+ }
33463
+ function buildDepositNativeRequest(config, input) {
33464
+ return {
33465
+ to: escrowContractAddress(config),
33466
+ data: encodeDepositNativeData({ account: input.account }),
33467
+ value: input.amount
33468
+ };
33469
+ }
33470
+ function buildDepositTokenRequest(config, input) {
33471
+ return {
33472
+ to: escrowContractAddress(config),
33473
+ data: encodeDepositTokenData(input)
33474
+ };
33475
+ }
33476
+
33477
+ // src/protocol/data-point-status.ts
33478
+ var import_viem20 = require("viem");
33479
+ var DataPointStatus = /* @__PURE__ */ ((DataPointStatus2) => {
33480
+ DataPointStatus2[DataPointStatus2["None"] = 0] = "None";
33481
+ DataPointStatus2[DataPointStatus2["Active"] = 1] = "Active";
33482
+ DataPointStatus2[DataPointStatus2["Inactive"] = 2] = "Inactive";
33483
+ DataPointStatus2[DataPointStatus2["Unavailable"] = 3] = "Unavailable";
33484
+ return DataPointStatus2;
33485
+ })(DataPointStatus || {});
33486
+ var DATA_REGISTRY_STATUS_ABI = [
33487
+ {
33488
+ type: "function",
33489
+ name: "setStatus",
33490
+ stateMutability: "nonpayable",
33491
+ inputs: [
33492
+ { name: "scope", type: "string" },
33493
+ { name: "newStatus", type: "uint8" }
33494
+ ],
33495
+ outputs: []
33496
+ }
33497
+ ];
33498
+ function dataRegistryContractAddress(config) {
33499
+ return config.contracts.dataRegistry;
33500
+ }
33501
+ function encodeSetDataPointStatusData(input) {
33502
+ return (0, import_viem20.encodeFunctionData)({
33503
+ abi: DATA_REGISTRY_STATUS_ABI,
33504
+ functionName: "setStatus",
33505
+ args: [input.scope, input.status]
33506
+ });
33507
+ }
33508
+ function buildSetDataPointStatusRequest(config, input) {
33509
+ return {
33510
+ to: dataRegistryContractAddress(config),
33511
+ data: encodeSetDataPointStatusData(input)
33512
+ };
33513
+ }
33514
+ function buildMarkDataPointUnavailableRequest(config, input) {
33515
+ return buildSetDataPointStatusRequest(config, {
33516
+ scope: input.scope,
33517
+ status: 3 /* Unavailable */
33518
+ });
33519
+ }
33520
+
33521
+ // src/protocol/data-file.ts
33277
33522
  var import_zod = require("zod");
33523
+ var DataFileEnvelopeSchema = import_zod.z.object({
33524
+ $schema: import_zod.z.string().url().optional(),
33525
+ version: import_zod.z.literal("1.0"),
33526
+ scope: import_zod.z.string(),
33527
+ schemaId: import_zod.z.string().optional(),
33528
+ collectedAt: import_zod.z.string().datetime(),
33529
+ data: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown())
33530
+ });
33531
+ function createDataFileEnvelope(scope, collectedAt, data, schemaUrl, schemaId) {
33532
+ return {
33533
+ ...schemaUrl !== void 0 && { $schema: schemaUrl },
33534
+ ...schemaId !== void 0 && { schemaId },
33535
+ version: "1.0",
33536
+ scope,
33537
+ collectedAt,
33538
+ data
33539
+ };
33540
+ }
33541
+ var IngestResponseSchema = import_zod.z.object({
33542
+ scope: import_zod.z.string(),
33543
+ collectedAt: import_zod.z.string().datetime(),
33544
+ status: import_zod.z.enum(["stored", "syncing"])
33545
+ });
33546
+
33547
+ // src/protocol/personal-server-data.ts
33548
+ function personalServerDataReadPath(scope) {
33549
+ return `/v1/data/${encodeURIComponent(scope)}`;
33550
+ }
33551
+ async function buildPersonalServerDataReadRequest(params) {
33552
+ const path = personalServerDataReadPath(params.scope);
33553
+ const baseUrl = params.personalServerUrl.replace(/\/+$/, "");
33554
+ const audience = params.audience ?? baseUrl;
33555
+ const headers = new Headers(params.headers);
33556
+ headers.set(
33557
+ "Authorization",
33558
+ await buildWeb3SignedHeader({
33559
+ aud: audience,
33560
+ grantId: params.grantId,
33561
+ method: "GET",
33562
+ signMessage: params.signMessage,
33563
+ uri: path
33564
+ })
33565
+ );
33566
+ return new Request(`${baseUrl}${path}`, {
33567
+ headers,
33568
+ method: "GET"
33569
+ });
33570
+ }
33571
+ async function readPersonalServerData(params) {
33572
+ const fetchFn = params.fetch ?? globalThis.fetch;
33573
+ if (fetchFn === void 0) {
33574
+ throw new Error("No fetch implementation available");
33575
+ }
33576
+ const request = await buildPersonalServerDataReadRequest(params);
33577
+ const response = await fetchFn(request);
33578
+ if (!response.ok) {
33579
+ throw new Error(
33580
+ `Personal Server data read failed: ${response.status} ${response.statusText}`
33581
+ );
33582
+ }
33583
+ return DataFileEnvelopeSchema.parse(await response.json());
33584
+ }
33585
+
33586
+ // src/protocol/scopes.ts
33587
+ var import_zod2 = require("zod");
33278
33588
  var SEGMENT_RE = /^[a-z0-9][a-z0-9_]*$/;
33279
- var ScopeSchema = import_zod.z.string().refine(
33589
+ var ScopeSchema = import_zod2.z.string().refine(
33280
33590
  (scope) => {
33281
33591
  const parts = scope.split(".");
33282
33592
  return parts.length >= 2 && parts.length <= 3 && parts.every((part) => SEGMENT_RE.test(part));
@@ -33317,32 +33627,6 @@ function scopeCoveredByGrant(requestedScope, grantedScopes) {
33317
33627
  );
33318
33628
  }
33319
33629
 
33320
- // src/protocol/data-file.ts
33321
- var import_zod2 = require("zod");
33322
- var DataFileEnvelopeSchema = import_zod2.z.object({
33323
- $schema: import_zod2.z.string().url().optional(),
33324
- version: import_zod2.z.literal("1.0"),
33325
- scope: import_zod2.z.string(),
33326
- schemaId: import_zod2.z.string().optional(),
33327
- collectedAt: import_zod2.z.string().datetime(),
33328
- data: import_zod2.z.record(import_zod2.z.string(), import_zod2.z.unknown())
33329
- });
33330
- function createDataFileEnvelope(scope, collectedAt, data, schemaUrl, schemaId) {
33331
- return {
33332
- ...schemaUrl !== void 0 && { $schema: schemaUrl },
33333
- ...schemaId !== void 0 && { schemaId },
33334
- version: "1.0",
33335
- scope,
33336
- collectedAt,
33337
- data
33338
- };
33339
- }
33340
- var IngestResponseSchema = import_zod2.z.object({
33341
- scope: import_zod2.z.string(),
33342
- collectedAt: import_zod2.z.string().datetime(),
33343
- status: import_zod2.z.enum(["stored", "syncing"])
33344
- });
33345
-
33346
33630
  // src/protocol/gateway.ts
33347
33631
  function createGatewayClient(baseUrl) {
33348
33632
  const base = baseUrl.replace(/\/+$/, "");
@@ -33350,16 +33634,6 @@ function createGatewayClient(baseUrl) {
33350
33634
  const envelope = await res.json();
33351
33635
  return envelope.data;
33352
33636
  }
33353
- function normalizeFileRecord(record) {
33354
- return {
33355
- fileId: record.fileId ?? record.id ?? "",
33356
- owner: record.owner ?? record.ownerAddress ?? "",
33357
- url: record.url,
33358
- schemaId: record.schemaId,
33359
- createdAt: record.createdAt ?? record.addedAt ?? "",
33360
- deletedAt: record.deletedAt ?? null
33361
- };
33362
- }
33363
33637
  function getMutationId(body, key) {
33364
33638
  const value = body[key] ?? body["id"];
33365
33639
  return typeof value === "string" ? value : void 0;
@@ -33409,31 +33683,33 @@ function createGatewayClient(baseUrl) {
33409
33683
  }
33410
33684
  return unwrapEnvelope(res);
33411
33685
  },
33412
- async getFile(fileId) {
33413
- const res = await fetch(`${base}/v1/files/${fileId}`);
33686
+ async getDataPoint(dataPointId) {
33687
+ const res = await fetch(`${base}/v1/data/${dataPointId}`);
33414
33688
  if (res.status === 404) return null;
33415
33689
  if (!res.ok) {
33416
33690
  throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
33417
33691
  }
33418
- return normalizeFileRecord(await unwrapEnvelope(res));
33692
+ return unwrapEnvelope(res);
33419
33693
  },
33420
- async listFilesSince(owner, cursor, options) {
33694
+ async listDataPointsByOwner(owner, cursor, options) {
33421
33695
  const params = new URLSearchParams({ user: owner });
33422
33696
  if (cursor !== null) {
33423
33697
  params.set("cursor", cursor);
33424
33698
  }
33425
- if (options?.includeDeleted) {
33426
- params.set("includeDeleted", "true");
33699
+ if (options?.since) {
33700
+ params.set("since", options.since);
33427
33701
  }
33428
- const res = await fetch(`${base}/v1/files?${params.toString()}`);
33702
+ if (options?.limit !== void 0) {
33703
+ params.set("limit", String(options.limit));
33704
+ }
33705
+ const res = await fetch(`${base}/v1/data?${params.toString()}`);
33429
33706
  if (!res.ok) {
33430
33707
  throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
33431
33708
  }
33432
33709
  const envelope = await res.json();
33433
- const { pagination } = envelope;
33434
- const nextCursor = pagination?.hasMore === false ? null : pagination?.nextCursor ?? envelope.data.cursor ?? null;
33710
+ const nextCursor = envelope.pagination?.hasMore === false ? null : envelope.pagination?.nextCursor ?? null;
33435
33711
  return {
33436
- files: envelope.data.files.map(normalizeFileRecord),
33712
+ dataPoints: envelope.data.dataPoints,
33437
33713
  cursor: nextCursor
33438
33714
  };
33439
33715
  },
@@ -33475,8 +33751,8 @@ function createGatewayClient(baseUrl) {
33475
33751
  alreadyRegistered: false
33476
33752
  };
33477
33753
  },
33478
- async registerFile(params) {
33479
- const res = await fetch(`${base}/v1/files`, {
33754
+ async registerBuilder(params) {
33755
+ const res = await fetch(`${base}/v1/builders`, {
33480
33756
  method: "POST",
33481
33757
  headers: {
33482
33758
  "Content-Type": "application/json",
@@ -33484,22 +33760,57 @@ function createGatewayClient(baseUrl) {
33484
33760
  },
33485
33761
  body: JSON.stringify({
33486
33762
  ownerAddress: params.ownerAddress,
33487
- url: params.url,
33488
- schemaId: params.schemaId
33763
+ granteeAddress: params.granteeAddress,
33764
+ publicKey: params.publicKey,
33765
+ appUrl: params.appUrl
33489
33766
  })
33490
33767
  });
33491
33768
  if (res.status === 409) {
33492
33769
  const body2 = await res.json().catch(() => ({}));
33493
33770
  return {
33494
- fileId: getMutationId(body2, "fileId")
33771
+ builderId: getMutationId(
33772
+ body2,
33773
+ "builderId"
33774
+ ),
33775
+ alreadyRegistered: true
33495
33776
  };
33496
33777
  }
33497
33778
  if (!res.ok) {
33498
33779
  throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
33499
33780
  }
33500
- const body = await res.json();
33781
+ const body = await res.json().catch(() => ({}));
33782
+ return {
33783
+ builderId: getMutationId(body, "builderId"),
33784
+ alreadyRegistered: false
33785
+ };
33786
+ },
33787
+ async registerDataPoint(params) {
33788
+ const res = await fetch(`${base}/v1/data`, {
33789
+ method: "POST",
33790
+ headers: {
33791
+ "Content-Type": "application/json",
33792
+ Authorization: `Web3Signed ${params.signature}`
33793
+ },
33794
+ body: JSON.stringify({
33795
+ ownerAddress: params.ownerAddress,
33796
+ scope: params.scope,
33797
+ dataHash: params.dataHash,
33798
+ metadataHash: params.metadataHash,
33799
+ expectedVersion: params.expectedVersion
33800
+ })
33801
+ });
33802
+ if (!res.ok) {
33803
+ const body2 = await res.json().catch(() => ({}));
33804
+ const detail = body2.error ?? res.statusText;
33805
+ throw new Error(`Gateway error: ${res.status} ${detail}`);
33806
+ }
33807
+ const body = await res.json().catch(() => ({}));
33501
33808
  return {
33502
- fileId: getMutationId(body, "fileId")
33809
+ dataPointId: getMutationId(
33810
+ body,
33811
+ "dataPointId"
33812
+ ),
33813
+ expectedVersion: body.expectedVersion
33503
33814
  };
33504
33815
  },
33505
33816
  async createGrant(params) {
@@ -33512,8 +33823,9 @@ function createGatewayClient(baseUrl) {
33512
33823
  body: JSON.stringify({
33513
33824
  grantorAddress: params.grantorAddress,
33514
33825
  granteeId: params.granteeId,
33515
- grant: params.grant,
33516
- fileIds: params.fileIds
33826
+ scopes: params.scopes,
33827
+ grantVersion: params.grantVersion,
33828
+ expiresAt: params.expiresAt
33517
33829
  })
33518
33830
  });
33519
33831
  if (res.status === 409) {
@@ -33538,7 +33850,8 @@ function createGatewayClient(baseUrl) {
33538
33850
  Authorization: `Web3Signed ${params.signature}`
33539
33851
  },
33540
33852
  body: JSON.stringify({
33541
- grantorAddress: params.grantorAddress
33853
+ grantorAddress: params.grantorAddress,
33854
+ grantVersion: params.grantVersion
33542
33855
  })
33543
33856
  });
33544
33857
  if (res.status === 409) return;
@@ -33546,21 +33859,174 @@ function createGatewayClient(baseUrl) {
33546
33859
  throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
33547
33860
  }
33548
33861
  },
33549
- async deleteFile(params) {
33550
- const res = await fetch(`${base}/v1/files/${params.fileId}`, {
33551
- method: "DELETE",
33862
+ async getEscrowBalance(account) {
33863
+ const res = await fetch(`${base}/v1/escrow/balance?account=${account}`);
33864
+ if (!res.ok) {
33865
+ throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
33866
+ }
33867
+ return await res.json();
33868
+ },
33869
+ async submitEscrowDeposit(params) {
33870
+ const res = await fetch(`${base}/v1/escrow/deposit`, {
33871
+ method: "POST",
33872
+ headers: { "Content-Type": "application/json" },
33873
+ body: JSON.stringify({ txHash: params.txHash })
33874
+ });
33875
+ if (res.status !== 200 && res.status !== 202) {
33876
+ throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
33877
+ }
33878
+ return await res.json();
33879
+ },
33880
+ async payForOperation(params) {
33881
+ const body = {
33882
+ payerAddress: params.payerAddress,
33883
+ opType: params.opType,
33884
+ opId: params.opId,
33885
+ asset: params.asset,
33886
+ amount: params.amount,
33887
+ paymentNonce: params.paymentNonce
33888
+ };
33889
+ if (params.accessRecord) {
33890
+ body["accessRecord"] = params.accessRecord;
33891
+ }
33892
+ const res = await fetch(`${base}/v1/escrow/pay`, {
33893
+ method: "POST",
33552
33894
  headers: {
33553
33895
  "Content-Type": "application/json",
33554
33896
  Authorization: `Web3Signed ${params.signature}`
33555
33897
  },
33556
- body: JSON.stringify({
33557
- ownerAddress: params.ownerAddress
33558
- })
33898
+ body: JSON.stringify(body)
33899
+ });
33900
+ if (!res.ok) {
33901
+ throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
33902
+ }
33903
+ return await res.json();
33904
+ },
33905
+ async settle(params) {
33906
+ const res = await fetch(`${base}/v1/settle`, {
33907
+ method: "POST",
33908
+ headers: { "Content-Type": "application/json" },
33909
+ // The gateway accepts an empty body; only `limit` is recognised.
33910
+ // Always send a JSON body so the gateway's req.body shape parse
33911
+ // doesn't have to deal with an undefined.
33912
+ body: JSON.stringify(params ?? {})
33559
33913
  });
33560
- if (res.status === 409) return;
33561
33914
  if (!res.ok) {
33562
33915
  throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
33563
33916
  }
33917
+ return await res.json();
33918
+ }
33919
+ };
33920
+ }
33921
+
33922
+ // src/protocol/escrow.ts
33923
+ var GENERIC_PAYMENT_TYPES = {
33924
+ GenericPayment: [
33925
+ { name: "payerAddress", type: "address" },
33926
+ { name: "opType", type: "string" },
33927
+ { name: "opId", type: "bytes32" },
33928
+ { name: "asset", type: "address" },
33929
+ { name: "amount", type: "uint256" },
33930
+ { name: "paymentNonce", type: "uint256" }
33931
+ ]
33932
+ };
33933
+ function genericPaymentDomain(chainId, escrowContract) {
33934
+ return {
33935
+ name: "Vana Data Portability",
33936
+ version: "1",
33937
+ chainId,
33938
+ verifyingContract: escrowContract
33939
+ };
33940
+ }
33941
+ var ESCROW_DEPOSIT_ABI2 = [
33942
+ {
33943
+ type: "function",
33944
+ name: "depositNative",
33945
+ stateMutability: "payable",
33946
+ inputs: [{ name: "account", type: "address" }],
33947
+ outputs: []
33948
+ },
33949
+ {
33950
+ type: "function",
33951
+ name: "depositToken",
33952
+ stateMutability: "nonpayable",
33953
+ inputs: [
33954
+ { name: "account", type: "address" },
33955
+ { name: "token", type: "address" },
33956
+ { name: "amount", type: "uint256" }
33957
+ ],
33958
+ outputs: []
33959
+ }
33960
+ ];
33961
+ var NATIVE_ASSET_ADDRESS = "0x0000000000000000000000000000000000000000";
33962
+ function createEscrowGatewayClient(baseUrl) {
33963
+ const base = baseUrl.replace(/\/+$/, "");
33964
+ async function throwOnError(res, context) {
33965
+ if (!res.ok) {
33966
+ let detail = "";
33967
+ try {
33968
+ const body = await res.json();
33969
+ if (body.error) detail = `: ${body.error}`;
33970
+ } catch {
33971
+ }
33972
+ throw new Error(
33973
+ `Escrow gateway error (${context}): ${res.status} ${res.statusText}${detail}`
33974
+ );
33975
+ }
33976
+ }
33977
+ return {
33978
+ async submitDeposit({ txHash }) {
33979
+ const res = await fetch(`${base}/v1/escrow/deposit`, {
33980
+ method: "POST",
33981
+ headers: { "Content-Type": "application/json" },
33982
+ body: JSON.stringify({ txHash })
33983
+ });
33984
+ if (res.status !== 200 && res.status !== 202) {
33985
+ await throwOnError(res, "POST /v1/escrow/deposit");
33986
+ }
33987
+ return res.json();
33988
+ },
33989
+ async getEscrowBalance(account) {
33990
+ const res = await fetch(
33991
+ `${base}/v1/escrow/balance?account=${encodeURIComponent(account)}`
33992
+ );
33993
+ await throwOnError(res, "GET /v1/escrow/balance");
33994
+ return res.json();
33995
+ },
33996
+ async syncEscrowBalance(account) {
33997
+ const res = await fetch(
33998
+ `${base}/v1/escrow/balance/sync?account=${encodeURIComponent(account)}`,
33999
+ { method: "POST" }
34000
+ );
34001
+ await throwOnError(res, "POST /v1/escrow/balance/sync");
34002
+ return res.json();
34003
+ },
34004
+ async payForOp({
34005
+ payerAddress,
34006
+ opType,
34007
+ opId,
34008
+ asset,
34009
+ amount,
34010
+ paymentNonce,
34011
+ signature
34012
+ }) {
34013
+ const res = await fetch(`${base}/v1/escrow/pay`, {
34014
+ method: "POST",
34015
+ headers: {
34016
+ "Content-Type": "application/json",
34017
+ Authorization: `Web3Signed ${signature}`
34018
+ },
34019
+ body: JSON.stringify({
34020
+ payerAddress,
34021
+ opType,
34022
+ opId,
34023
+ asset,
34024
+ amount,
34025
+ paymentNonce
34026
+ })
34027
+ });
34028
+ await throwOnError(res, "POST /v1/escrow/pay");
34029
+ return res.json();
33564
34030
  }
33565
34031
  };
33566
34032
  }
@@ -33630,6 +34096,7 @@ async function parsePSError(response) {
33630
34096
  // Annotate the CommonJS export names for ESM import in node:
33631
34097
  0 && (module.exports = {
33632
34098
  ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT,
34099
+ ADD_DATA_TYPES,
33633
34100
  AccountPersonalServerLiteOwnerBindingError,
33634
34101
  AccountPersonalServerRegistrationError,
33635
34102
  BUILDER_REGISTRATION_TYPES,
@@ -33639,12 +34106,15 @@ async function parsePSError(response) {
33639
34106
  CallbackStorage,
33640
34107
  ContractFactory,
33641
34108
  ContractNotFoundError,
34109
+ DATA_REGISTRY_STATUS_ABI,
33642
34110
  DataFileEnvelopeSchema,
34111
+ DataPointStatus,
33643
34112
  DropboxStorage,
33644
34113
  ECIESError,
34114
+ ESCROW_DEPOSIT_ABI,
33645
34115
  ExpiredTokenError,
33646
- FILE_DELETION_TYPES,
33647
- FILE_REGISTRATION_TYPES,
34116
+ FEE_REGISTRY_ABI,
34117
+ GENERIC_PAYMENT_TYPES,
33648
34118
  GRANT_REGISTRATION_TYPES,
33649
34119
  GRANT_REVOCATION_TYPES,
33650
34120
  GoogleDriveStorage,
@@ -33655,6 +34125,8 @@ async function parsePSError(response) {
33655
34125
  IpfsStorage,
33656
34126
  MASTER_KEY_MESSAGE,
33657
34127
  MissingAuthError,
34128
+ NATIVE_ASSET_ADDRESS,
34129
+ NATIVE_VANA_ASSET,
33658
34130
  NetworkError,
33659
34131
  NodeECIESProvider,
33660
34132
  NodePlatformAdapter,
@@ -33672,6 +34144,8 @@ async function parsePSError(response) {
33672
34144
  PersonalServerError,
33673
34145
  PinataStorage,
33674
34146
  R2Storage,
34147
+ RECORD_DATA_ACCESS_TYPES,
34148
+ REGISTRATION_KIND_FOR_OP,
33675
34149
  ReadOnlyError,
33676
34150
  RelayerError,
33677
34151
  SERVER_REGISTRATION_TYPES,
@@ -33686,10 +34160,15 @@ async function parsePSError(response) {
33686
34160
  VanaError,
33687
34161
  VanaStorage,
33688
34162
  assertValidPkceVerifier,
34163
+ buildDepositNativeRequest,
34164
+ buildDepositTokenRequest,
34165
+ buildMarkDataPointUnavailableRequest,
34166
+ buildPersonalServerDataReadRequest,
33689
34167
  buildPersonalServerLiteOwnerBindingMessage,
33690
34168
  buildPersonalServerLiteOwnerBindingSignature,
33691
34169
  buildPersonalServerRegistrationSignature,
33692
34170
  buildPersonalServerRegistrationTypedData,
34171
+ buildSetDataPointStatusRequest,
33693
34172
  buildWeb3SignedHeader,
33694
34173
  builderRegistrationDomain,
33695
34174
  chains,
@@ -33699,6 +34178,7 @@ async function parsePSError(response) {
33699
34178
  contractCacheForTesting,
33700
34179
  createBrowserPlatformAdapter,
33701
34180
  createDataFileEnvelope,
34181
+ createEscrowGatewayClient,
33702
34182
  createGatewayClient,
33703
34183
  createNodePlatformAdapter,
33704
34184
  createPlatformAdapter,
@@ -33707,21 +34187,29 @@ async function parsePSError(response) {
33707
34187
  createVanaStorageProvider,
33708
34188
  createViemPersonalServerLiteOwnerBindingSigner,
33709
34189
  createViemPersonalServerRegistrationSigner,
34190
+ dataRegistryContractAddress,
34191
+ dataRegistryDomain,
33710
34192
  decryptWithPassword,
33711
34193
  deriveMasterKey,
33712
34194
  deriveScopeKey,
33713
34195
  deserializeECIES,
33714
34196
  detectPlatform,
34197
+ encodeDepositNativeData,
34198
+ encodeDepositTokenData,
34199
+ encodeSetDataPointStatusData,
33715
34200
  encryptWithPassword,
33716
- fileDeletionDomain,
33717
- fileRegistrationDomain,
34201
+ escrowContractAddress,
34202
+ escrowPaymentDomain,
33718
34203
  generatePkceVerifier,
34204
+ genericPaymentDomain,
33719
34205
  getAbi,
33720
34206
  getAllChains,
33721
34207
  getChainConfig,
33722
34208
  getContractAddress,
33723
34209
  getContractController,
33724
34210
  getContractInfo,
34211
+ getFee,
34212
+ getOpFee,
33725
34213
  getPlatformCapabilities,
33726
34214
  getServiceEndpoints,
33727
34215
  grantRegistrationDomain,
@@ -33733,11 +34221,12 @@ async function parsePSError(response) {
33733
34221
  moksha,
33734
34222
  mokshaServices,
33735
34223
  mokshaTestnet,
33736
- parseGrantRegistrationPayload,
33737
34224
  parsePSError,
33738
34225
  parseScope,
33739
34226
  parseWeb3SignedHeader,
34227
+ personalServerDataReadPath,
33740
34228
  personalServerRegistrationDomain,
34229
+ readPersonalServerData,
33741
34230
  recoverServerOwner,
33742
34231
  registerPersonalServerSignature,
33743
34232
  scopeCoveredByGrant,