@opendatalabs/vana-sdk 3.0.1 → 3.2.0-canary.88d802d

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 (110) hide show
  1. package/README.md +2 -1
  2. package/dist/__tests__/interop-personal-server.test.d.ts +1 -0
  3. package/dist/account/personal-server-lite-owner-binding.cjs +81 -0
  4. package/dist/account/personal-server-lite-owner-binding.cjs.map +1 -0
  5. package/dist/account/personal-server-lite-owner-binding.d.ts +30 -0
  6. package/dist/account/personal-server-lite-owner-binding.js +59 -0
  7. package/dist/account/personal-server-lite-owner-binding.js.map +1 -0
  8. package/dist/account/personal-server-lite-owner-binding.test.d.ts +1 -0
  9. package/dist/account/personal-server-registration.cjs +263 -0
  10. package/dist/account/personal-server-registration.cjs.map +1 -0
  11. package/dist/account/personal-server-registration.d.ts +66 -0
  12. package/dist/account/personal-server-registration.js +240 -0
  13. package/dist/account/personal-server-registration.js.map +1 -0
  14. package/dist/account/personal-server-registration.test.d.ts +1 -0
  15. package/dist/auth/errors.js +1 -1
  16. package/dist/auth/oauth-client.cjs +250 -0
  17. package/dist/auth/oauth-client.cjs.map +1 -0
  18. package/dist/auth/oauth-client.d.ts +90 -0
  19. package/dist/auth/oauth-client.js +228 -0
  20. package/dist/auth/oauth-client.js.map +1 -0
  21. package/dist/auth/oauth-client.test.d.ts +1 -0
  22. package/dist/auth/web3-signed-builder.js +1 -1
  23. package/dist/auth/web3-signed.js +3 -3
  24. package/dist/browser.js +1 -1
  25. package/dist/chains/definitions.js +1 -1
  26. package/dist/chains/index.js +1 -1
  27. package/dist/chains.browser.js +1 -1
  28. package/dist/chains.js +1 -1
  29. package/dist/chains.node.js +1 -1
  30. package/dist/contracts/contractController.js +4 -4
  31. package/dist/core/client.js +1 -1
  32. package/dist/crypto/ecies/base.js +3 -3
  33. package/dist/crypto/ecies/browser.js +1 -1
  34. package/dist/crypto/ecies/index.js +1 -1
  35. package/dist/crypto/ecies/interface.js +1 -1
  36. package/dist/crypto/ecies/node.js +1 -1
  37. package/dist/crypto/services/WalletKeyEncryptionService.js +1 -1
  38. package/dist/generated/abi/index.js +26 -26
  39. package/dist/index.browser.d.ts +9 -3
  40. package/dist/index.browser.js +930 -73
  41. package/dist/index.browser.js.map +4 -4
  42. package/dist/index.node.cjs +958 -74
  43. package/dist/index.node.cjs.map +4 -4
  44. package/dist/index.node.d.ts +9 -3
  45. package/dist/index.node.js +930 -73
  46. package/dist/index.node.js.map +4 -4
  47. package/dist/node.js +1 -1
  48. package/dist/platform/browser-only.js +1 -1
  49. package/dist/platform/browser-safe.js +1 -1
  50. package/dist/platform/browser.js +6 -6
  51. package/dist/platform/index.js +4 -4
  52. package/dist/platform/node.js +8 -8
  53. package/dist/platform/utils.js +2 -2
  54. package/dist/platform.browser.js +3 -3
  55. package/dist/platform.js +4 -4
  56. package/dist/platform.node.js +4 -4
  57. package/dist/protocol/eip712.cjs +58 -3
  58. package/dist/protocol/eip712.cjs.map +1 -1
  59. package/dist/protocol/eip712.d.ts +98 -7
  60. package/dist/protocol/eip712.js +52 -3
  61. package/dist/protocol/eip712.js.map +1 -1
  62. package/dist/protocol/escrow-deposit.cjs +89 -0
  63. package/dist/protocol/escrow-deposit.cjs.map +1 -0
  64. package/dist/protocol/escrow-deposit.d.ts +47 -0
  65. package/dist/protocol/escrow-deposit.js +60 -0
  66. package/dist/protocol/escrow-deposit.js.map +1 -0
  67. package/dist/protocol/escrow-deposit.test.d.ts +1 -0
  68. package/dist/protocol/escrow-flow.test.d.ts +21 -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.cjs.map +1 -1
  93. package/dist/storage/index.d.ts +1 -1
  94. package/dist/storage/index.js +10 -10
  95. package/dist/storage/index.js.map +1 -1
  96. package/dist/storage/manager.js +1 -1
  97. package/dist/storage/providers/callback-storage.js +1 -1
  98. package/dist/storage/providers/dropbox.js +1 -1
  99. package/dist/storage/providers/google-drive.js +1 -1
  100. package/dist/storage/providers/ipfs.js +2 -2
  101. package/dist/storage/providers/pinata.js +1 -1
  102. package/dist/storage/providers/r2.js +1 -1
  103. package/dist/storage/providers/vana-storage.cjs +1 -1
  104. package/dist/storage/providers/vana-storage.cjs.map +1 -1
  105. package/dist/storage/providers/vana-storage.d.ts +2 -2
  106. package/dist/storage/providers/vana-storage.js +3 -3
  107. package/dist/storage/providers/vana-storage.js.map +1 -1
  108. package/dist/types/index.js +2 -2
  109. package/dist/types.js +1 -1
  110. package/package.json +7 -3
@@ -29015,7 +29015,7 @@ async function buildWeb3SignedHeader(params) {
29015
29015
  }
29016
29016
 
29017
29017
  // src/storage/providers/vana-storage.ts
29018
- var DEFAULT_ENDPOINT = "https://storage.vana.com";
29018
+ var DEFAULT_ENDPOINT = "https://storage.vana.org";
29019
29019
  var BLOB_PATH_PREFIX = "/v1/blobs";
29020
29020
  var DEFAULT_TOKEN_TTL_SECONDS = 300;
29021
29021
  var VanaStorage = class {
@@ -32284,9 +32284,232 @@ var InMemoryTokenStore = class {
32284
32284
  }
32285
32285
  };
32286
32286
 
32287
+ // src/auth/oauth-client.ts
32288
+ var VERIFIER_TTL_SECONDS = 600;
32289
+ var RESERVED_AUTHORIZE_PARAMS = /* @__PURE__ */ new Set([
32290
+ "response_type",
32291
+ "client_id",
32292
+ "redirect_uri",
32293
+ "scope",
32294
+ "state",
32295
+ "code_challenge",
32296
+ "code_challenge_method"
32297
+ ]);
32298
+ var OAuthClient = class {
32299
+ #config;
32300
+ constructor(config) {
32301
+ const fetchImpl = config.fetchImpl ?? globalThis.fetch;
32302
+ if (typeof fetchImpl !== "function") {
32303
+ throw new TypeError(
32304
+ "OAuthClient requires a global `fetch` or an explicit `fetchImpl`"
32305
+ );
32306
+ }
32307
+ this.#config = {
32308
+ authorizationEndpoint: config.authorizationEndpoint,
32309
+ tokenEndpoint: config.tokenEndpoint,
32310
+ clientId: config.clientId,
32311
+ redirectUri: config.redirectUri,
32312
+ scope: config.scope,
32313
+ tokenStore: config.tokenStore ?? new InMemoryTokenStore(),
32314
+ fetchImpl,
32315
+ generateState: config.generateState ?? defaultGenerateState
32316
+ };
32317
+ }
32318
+ /** Build the authorize URL and persist the PKCE verifier keyed by `state`. */
32319
+ async buildAuthorizationUrl(opts = {}) {
32320
+ const state = opts.state ?? this.#config.generateState();
32321
+ const scope = opts.scope ?? this.#config.scope;
32322
+ const verifier = generatePkceVerifier();
32323
+ const challenge = await computePkceChallenge(verifier);
32324
+ await this.#config.tokenStore.set(this.#verifierKey(state), {
32325
+ token: verifier,
32326
+ expiresAt: Math.floor(Date.now() / 1e3) + VERIFIER_TTL_SECONDS
32327
+ });
32328
+ const params = new URLSearchParams();
32329
+ params.set("response_type", "code");
32330
+ params.set("client_id", this.#config.clientId);
32331
+ params.set("redirect_uri", this.#config.redirectUri);
32332
+ if (scope !== void 0 && scope.length > 0) {
32333
+ params.set("scope", scope);
32334
+ }
32335
+ params.set("state", state);
32336
+ params.set("code_challenge", challenge);
32337
+ params.set("code_challenge_method", "S256");
32338
+ if (opts.extraParams !== void 0) {
32339
+ for (const k of Object.keys(opts.extraParams)) {
32340
+ if (RESERVED_AUTHORIZE_PARAMS.has(k)) {
32341
+ throw new Error(
32342
+ `extraParams may not override the reserved OAuth/PKCE parameter "${k}"`
32343
+ );
32344
+ }
32345
+ }
32346
+ for (const [k, v] of Object.entries(opts.extraParams)) {
32347
+ params.set(k, v);
32348
+ }
32349
+ }
32350
+ const sep = this.#config.authorizationEndpoint.includes("?") ? "&" : "?";
32351
+ const url = `${this.#config.authorizationEndpoint}${sep}${params.toString()}`;
32352
+ return { url, state };
32353
+ }
32354
+ /**
32355
+ * Handle the redirect-callback URL. Validates `state`, retrieves the saved
32356
+ * verifier, exchanges the authorization code + verifier for tokens, and
32357
+ * persists them. Returns the access {@link TokenRecord}.
32358
+ */
32359
+ async handleCallback(callbackUrl) {
32360
+ const parsed = new URL(callbackUrl);
32361
+ const params = parsed.searchParams;
32362
+ const errorCode = params.get("error");
32363
+ if (errorCode !== null) {
32364
+ throw new Error(
32365
+ formatOAuthError({
32366
+ error: errorCode,
32367
+ error_description: params.get("error_description") ?? void 0
32368
+ })
32369
+ );
32370
+ }
32371
+ const code = params.get("code");
32372
+ const state = params.get("state");
32373
+ if (code === null || state === null) {
32374
+ throw new Error("OAuth callback is missing `code` or `state`");
32375
+ }
32376
+ const verifierRecord = await this.#config.tokenStore.get(
32377
+ this.#verifierKey(state)
32378
+ );
32379
+ if (verifierRecord === null) {
32380
+ throw new Error(
32381
+ "OAuth callback state does not match any in-flight verifier (possible CSRF or expired flow)"
32382
+ );
32383
+ }
32384
+ const body = new URLSearchParams();
32385
+ body.set("grant_type", "authorization_code");
32386
+ body.set("code", code);
32387
+ body.set("redirect_uri", this.#config.redirectUri);
32388
+ body.set("client_id", this.#config.clientId);
32389
+ body.set("code_verifier", verifierRecord.token);
32390
+ let tokens;
32391
+ try {
32392
+ tokens = await this.#tokenRequest(body);
32393
+ } finally {
32394
+ await this.#config.tokenStore.delete(this.#verifierKey(state));
32395
+ }
32396
+ return this.#persistTokens(tokens);
32397
+ }
32398
+ /**
32399
+ * Exchange a stored refresh token for a fresh access token. Throws if no
32400
+ * refresh token is available.
32401
+ */
32402
+ async refresh() {
32403
+ const refreshRecord = await this.#config.tokenStore.get(this.#refreshKey());
32404
+ if (refreshRecord === null) {
32405
+ throw new Error("OAuth refresh failed: no refresh token stored");
32406
+ }
32407
+ const body = new URLSearchParams();
32408
+ body.set("grant_type", "refresh_token");
32409
+ body.set("refresh_token", refreshRecord.token);
32410
+ body.set("client_id", this.#config.clientId);
32411
+ const tokens = await this.#tokenRequest(body);
32412
+ return this.#persistTokens(tokens, refreshRecord.token);
32413
+ }
32414
+ /**
32415
+ * Get the current access token if valid (refreshing first if expired and a
32416
+ * refresh token is available). Returns `null` when no usable token exists.
32417
+ */
32418
+ async getAccessToken() {
32419
+ const stored = await this.#config.tokenStore.get(this.#accessKey());
32420
+ if (stored !== null) return stored.token;
32421
+ const refresh = await this.#config.tokenStore.get(this.#refreshKey());
32422
+ if (refresh === null) return null;
32423
+ try {
32424
+ const refreshed = await this.refresh();
32425
+ return refreshed.token;
32426
+ } catch {
32427
+ return null;
32428
+ }
32429
+ }
32430
+ /** Forget tokens (logout). Does NOT call any remote revocation endpoint. */
32431
+ async signOut() {
32432
+ await this.#config.tokenStore.delete(this.#accessKey());
32433
+ await this.#config.tokenStore.delete(this.#refreshKey());
32434
+ }
32435
+ #accessKey() {
32436
+ return `oauth:tokens:${this.#config.clientId}`;
32437
+ }
32438
+ #refreshKey() {
32439
+ return `oauth:refresh:${this.#config.clientId}`;
32440
+ }
32441
+ #verifierKey(state) {
32442
+ return `oauth:verifier:${state}`;
32443
+ }
32444
+ async #tokenRequest(body) {
32445
+ const response = await this.#config.fetchImpl(this.#config.tokenEndpoint, {
32446
+ method: "POST",
32447
+ headers: {
32448
+ "Content-Type": "application/x-www-form-urlencoded",
32449
+ Accept: "application/json"
32450
+ },
32451
+ body: body.toString()
32452
+ });
32453
+ const text = await response.text();
32454
+ const parsed = parseJsonBody(text);
32455
+ if (!response.ok) {
32456
+ throw new Error(formatOAuthError(parsed ?? {}, response.status));
32457
+ }
32458
+ if (parsed === null || typeof parsed !== "object" || typeof parsed.access_token !== "string") {
32459
+ throw new Error(
32460
+ "OAuth token endpoint returned a response without an `access_token` string"
32461
+ );
32462
+ }
32463
+ return parsed;
32464
+ }
32465
+ async #persistTokens(tokens, previousRefreshToken) {
32466
+ const record = { token: tokens.access_token };
32467
+ if (typeof tokens.expires_in === "number" && tokens.expires_in > 0) {
32468
+ record.expiresAt = Math.floor(Date.now() / 1e3) + tokens.expires_in;
32469
+ }
32470
+ await this.#config.tokenStore.set(this.#accessKey(), record);
32471
+ const newRefresh = tokens.refresh_token ?? previousRefreshToken;
32472
+ if (newRefresh !== void 0) {
32473
+ await this.#config.tokenStore.set(this.#refreshKey(), {
32474
+ token: newRefresh
32475
+ });
32476
+ }
32477
+ return record;
32478
+ }
32479
+ };
32480
+ function defaultGenerateState() {
32481
+ const bytes = new Uint8Array(24);
32482
+ crypto.getRandomValues(bytes);
32483
+ let binary = "";
32484
+ for (let i = 0; i < bytes.length; i++) {
32485
+ binary += String.fromCharCode(bytes[i]);
32486
+ }
32487
+ return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
32488
+ }
32489
+ function parseJsonBody(text) {
32490
+ if (text.length === 0) return null;
32491
+ try {
32492
+ return JSON.parse(text);
32493
+ } catch {
32494
+ return null;
32495
+ }
32496
+ }
32497
+ function formatOAuthError(body, status) {
32498
+ const parts = ["OAuth token request failed"];
32499
+ if (status !== void 0) parts.push(`(HTTP ${String(status)})`);
32500
+ if (body.error !== void 0 && body.error.length > 0) {
32501
+ parts.push(`: ${body.error}`);
32502
+ if (body.error_description !== void 0 && body.error_description.length > 0) {
32503
+ parts.push(`- ${body.error_description}`);
32504
+ }
32505
+ }
32506
+ return parts.join(" ").replace(" : ", ": ").replace(" - ", " - ");
32507
+ }
32508
+
32287
32509
  // src/protocol/eip712.ts
32288
32510
  var DOMAIN_NAME = "Vana Data Portability";
32289
32511
  var DOMAIN_VERSION = "1";
32512
+ var NATIVE_VANA_ASSET = "0x0000000000000000000000000000000000000000";
32290
32513
  function buildDomain(chainId, verifyingContract) {
32291
32514
  return {
32292
32515
  name: DOMAIN_NAME,
@@ -32301,6 +32524,12 @@ function fileRegistrationDomain(config) {
32301
32524
  config.contracts.dataRegistry
32302
32525
  );
32303
32526
  }
32527
+ function dataRegistryDomain(config) {
32528
+ return buildDomain(
32529
+ config.chainId,
32530
+ config.contracts.dataRegistry
32531
+ );
32532
+ }
32304
32533
  function grantRegistrationDomain(config) {
32305
32534
  return buildDomain(
32306
32535
  config.chainId,
@@ -32325,6 +32554,12 @@ function builderRegistrationDomain(config) {
32325
32554
  config.contracts.dataPortabilityGrantees
32326
32555
  );
32327
32556
  }
32557
+ function escrowPaymentDomain(config) {
32558
+ return buildDomain(
32559
+ config.chainId,
32560
+ config.contracts.dataPortabilityEscrow
32561
+ );
32562
+ }
32328
32563
  var FILE_REGISTRATION_TYPES = {
32329
32564
  FileRegistration: [
32330
32565
  { name: "ownerAddress", type: "address" },
@@ -32336,14 +32571,16 @@ var GRANT_REGISTRATION_TYPES = {
32336
32571
  GrantRegistration: [
32337
32572
  { name: "grantorAddress", type: "address" },
32338
32573
  { name: "granteeId", type: "bytes32" },
32339
- { name: "grant", type: "string" },
32340
- { name: "fileIds", type: "uint256[]" }
32574
+ { name: "scopes", type: "string[]" },
32575
+ { name: "grantVersion", type: "uint256" },
32576
+ { name: "expiresAt", type: "uint256" }
32341
32577
  ]
32342
32578
  };
32343
32579
  var GRANT_REVOCATION_TYPES = {
32344
32580
  GrantRevocation: [
32345
32581
  { name: "grantorAddress", type: "address" },
32346
- { name: "grantId", type: "bytes32" }
32582
+ { name: "grantId", type: "bytes32" },
32583
+ { name: "grantVersion", type: "uint256" }
32347
32584
  ]
32348
32585
  };
32349
32586
  var SERVER_REGISTRATION_TYPES = {
@@ -32362,83 +32599,500 @@ var BUILDER_REGISTRATION_TYPES = {
32362
32599
  { name: "appUrl", type: "string" }
32363
32600
  ]
32364
32601
  };
32602
+ var GENERIC_PAYMENT_TYPES = {
32603
+ GenericPayment: [
32604
+ { name: "payerAddress", type: "address" },
32605
+ { name: "opType", type: "string" },
32606
+ { name: "opId", type: "bytes32" },
32607
+ { name: "asset", type: "address" },
32608
+ { name: "amount", type: "uint256" },
32609
+ { name: "paymentNonce", type: "uint256" }
32610
+ ]
32611
+ };
32612
+ var ADD_DATA_TYPES = {
32613
+ AddData: [
32614
+ { name: "ownerAddress", type: "address" },
32615
+ { name: "scope", type: "string" },
32616
+ { name: "dataHash", type: "bytes32" },
32617
+ { name: "metadataHash", type: "bytes32" },
32618
+ { name: "expectedVersion", type: "uint256" }
32619
+ ]
32620
+ };
32621
+ var RECORD_DATA_ACCESS_TYPES = {
32622
+ RecordDataAccess: [
32623
+ { name: "ownerAddress", type: "address" },
32624
+ { name: "scope", type: "string" },
32625
+ { name: "version", type: "uint256" },
32626
+ { name: "accessor", type: "address" },
32627
+ { name: "recordId", type: "bytes32" }
32628
+ ]
32629
+ };
32365
32630
 
32366
- // src/protocol/grants.ts
32367
- import { verifyTypedData } from "viem";
32368
- function isHexString(value) {
32369
- return typeof value === "string" && value.startsWith("0x");
32631
+ // src/protocol/personal-server-registration.ts
32632
+ import {
32633
+ isAddress
32634
+ } from "viem";
32635
+ var PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID = 1480;
32636
+ var PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT = "0x1483B1F634DBA75AeaE60da7f01A679aabd5ee2c";
32637
+ function assertAddress(value, name) {
32638
+ if (!isAddress(value)) {
32639
+ throw new Error(`${name} must be a valid EVM address`);
32640
+ }
32370
32641
  }
32371
- function isDataPortabilityGatewayConfig(value) {
32372
- if (value === null || typeof value !== "object" || Array.isArray(value)) {
32373
- return false;
32642
+ function getAccountAddress(account) {
32643
+ if (!account) {
32644
+ return void 0;
32374
32645
  }
32375
- const config = value;
32376
- const contracts = config["contracts"];
32377
- if (typeof config["chainId"] !== "number" || !Number.isInteger(config["chainId"]) || config["chainId"] <= 0 || contracts === null || typeof contracts !== "object" || Array.isArray(contracts)) {
32378
- return false;
32646
+ return typeof account === "string" ? account : account.address;
32647
+ }
32648
+ function isPersonalServerRegistrationSigner(source) {
32649
+ return "address" in source && typeof source.signTypedData === "function";
32650
+ }
32651
+ function createViemPersonalServerRegistrationSigner(source, options = {}) {
32652
+ if (isPersonalServerRegistrationSigner(source)) {
32653
+ return source;
32379
32654
  }
32380
- const c = contracts;
32381
- return isHexString(c["dataRegistry"]) && isHexString(c["dataPortabilityPermissions"]) && isHexString(c["dataPortabilityServer"]) && isHexString(c["dataPortabilityGrantees"]);
32655
+ const accountAddress = getAccountAddress(options.account) ?? getAccountAddress(source.account);
32656
+ if (accountAddress) {
32657
+ return {
32658
+ address: accountAddress,
32659
+ signTypedData: (typedData) => source.signTypedData({
32660
+ ...typedData,
32661
+ account: options.account ?? source.account ?? accountAddress
32662
+ })
32663
+ };
32664
+ }
32665
+ throw new Error(
32666
+ "Viem wallet client requires an account option or account property"
32667
+ );
32382
32668
  }
32383
- function parseGrantRegistrationPayload(grant) {
32384
- let parsed;
32385
- try {
32386
- parsed = JSON.parse(grant);
32387
- } catch {
32388
- return null;
32669
+ function personalServerRegistrationDomain(input = {}) {
32670
+ if (input.config) {
32671
+ return serverRegistrationDomain(input.config);
32389
32672
  }
32390
- if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
32391
- return null;
32673
+ const verifyingContract = input.verifyingContract ?? PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT;
32674
+ assertAddress(verifyingContract, "verifyingContract");
32675
+ return {
32676
+ name: "Vana Data Portability",
32677
+ version: "1",
32678
+ chainId: input.chainId ?? PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID,
32679
+ verifyingContract
32680
+ };
32681
+ }
32682
+ function buildPersonalServerRegistrationTypedData(input) {
32683
+ assertAddress(input.ownerAddress, "ownerAddress");
32684
+ assertAddress(input.serverAddress, "serverAddress");
32685
+ return {
32686
+ domain: personalServerRegistrationDomain(input),
32687
+ types: SERVER_REGISTRATION_TYPES,
32688
+ primaryType: "ServerRegistration",
32689
+ message: {
32690
+ ownerAddress: input.ownerAddress,
32691
+ serverAddress: input.serverAddress,
32692
+ publicKey: input.serverPublicKey,
32693
+ serverUrl: input.serverUrl
32694
+ }
32695
+ };
32696
+ }
32697
+ async function buildPersonalServerRegistrationSignature(input) {
32698
+ const typedData = buildPersonalServerRegistrationTypedData({
32699
+ ownerAddress: input.signer.address,
32700
+ serverAddress: input.serverAddress,
32701
+ serverPublicKey: input.serverPublicKey,
32702
+ serverUrl: input.serverUrl,
32703
+ config: input.config,
32704
+ chainId: input.chainId,
32705
+ verifyingContract: input.verifyingContract
32706
+ });
32707
+ const signature = await input.signer.signTypedData(typedData);
32708
+ return {
32709
+ signature,
32710
+ signerAddress: input.signer.address,
32711
+ typedData
32712
+ };
32713
+ }
32714
+ var registerPersonalServerSignature = buildPersonalServerRegistrationSignature;
32715
+
32716
+ // src/protocol/personal-server-lite-owner-binding.ts
32717
+ import {
32718
+ isAddress as isAddress2
32719
+ } from "viem";
32720
+ var PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION = "vana.account.v1";
32721
+ var PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE = "ps-lite-owner";
32722
+ var PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX = `${PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION}:${PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE}:`;
32723
+ function assertAddress2(value, name) {
32724
+ if (!isAddress2(value)) {
32725
+ throw new Error(`${name} must be a valid EVM address`);
32392
32726
  }
32393
- const value = parsed;
32394
- if (!Array.isArray(value["scopes"]) || value["scopes"].length === 0) {
32395
- return null;
32727
+ }
32728
+ function getAccountAddress2(account) {
32729
+ if (!account) {
32730
+ return void 0;
32396
32731
  }
32397
- if (!value["scopes"].every((scope) => typeof scope === "string")) {
32398
- return null;
32732
+ return typeof account === "string" ? account : account.address;
32733
+ }
32734
+ function isPersonalServerLiteOwnerBindingSigner(source) {
32735
+ return "address" in source && typeof source.signMessage === "function";
32736
+ }
32737
+ function buildPersonalServerLiteOwnerBindingMessage(ownerAddress) {
32738
+ assertAddress2(ownerAddress, "ownerAddress");
32739
+ return `${PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX}${ownerAddress.toLowerCase()}`;
32740
+ }
32741
+ function createViemPersonalServerLiteOwnerBindingSigner(source, options = {}) {
32742
+ if (isPersonalServerLiteOwnerBindingSigner(source)) {
32743
+ return source;
32399
32744
  }
32400
- if (typeof value["expiresAt"] !== "number" || !Number.isFinite(value["expiresAt"])) {
32401
- return null;
32745
+ const accountAddress = getAccountAddress2(options.account) ?? getAccountAddress2(source.account);
32746
+ if (accountAddress) {
32747
+ return {
32748
+ address: accountAddress,
32749
+ signMessage: ({ message }) => source.signMessage({
32750
+ account: options.account ?? source.account ?? accountAddress,
32751
+ message
32752
+ })
32753
+ };
32402
32754
  }
32403
- if (value["user"] !== void 0 && !isHexString(value["user"])) {
32404
- return null;
32755
+ throw new Error(
32756
+ "Viem wallet client requires an account option or account property"
32757
+ );
32758
+ }
32759
+ async function buildPersonalServerLiteOwnerBindingSignature(input) {
32760
+ const message = buildPersonalServerLiteOwnerBindingMessage(
32761
+ input.signer.address
32762
+ );
32763
+ const signature = await input.signer.signMessage({ message });
32764
+ return {
32765
+ signature,
32766
+ signerAddress: input.signer.address,
32767
+ message,
32768
+ purpose: PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE
32769
+ };
32770
+ }
32771
+ var signPersonalServerLiteOwnerBinding = buildPersonalServerLiteOwnerBindingSignature;
32772
+
32773
+ // src/account/personal-server-registration.ts
32774
+ import { isAddress as isAddress3 } from "viem";
32775
+ var ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT = "personal_server.server_registration.v1";
32776
+ var AccountPersonalServerRegistrationError = class extends Error {
32777
+ status;
32778
+ code;
32779
+ details;
32780
+ constructor(input) {
32781
+ super(input.message);
32782
+ this.name = "AccountPersonalServerRegistrationError";
32783
+ this.status = input.status;
32784
+ this.code = input.code;
32785
+ this.details = input.details;
32405
32786
  }
32406
- if (value["builder"] !== void 0 && !isHexString(value["builder"])) {
32407
- return null;
32787
+ };
32788
+ var DEFAULT_ACCOUNT_PS_REGISTRATION_PATH = "/api/v1/intents/personal-server-registration/sign";
32789
+ function trimTrailingSlash(value) {
32790
+ return value.replace(/\/+$/, "");
32791
+ }
32792
+ function assertAddress3(value, name) {
32793
+ if (!isAddress3(value)) {
32794
+ throw new Error(`${name} must be a valid EVM address`);
32408
32795
  }
32409
- if (value["nonce"] !== void 0 && (typeof value["nonce"] !== "number" || !Number.isFinite(value["nonce"]))) {
32410
- return null;
32796
+ }
32797
+ async function parseAccountResponse(response) {
32798
+ const body = await response.json().catch(() => void 0);
32799
+ if (!response.ok) {
32800
+ throw new AccountPersonalServerRegistrationError({
32801
+ status: response.status,
32802
+ code: accountErrorCode(body),
32803
+ message: accountErrorMessage(response.status, body),
32804
+ details: body
32805
+ });
32806
+ }
32807
+ return body;
32808
+ }
32809
+ function accountErrorMessage(status, body) {
32810
+ const nestedMessage = nestedAccountErrorField(body, "message");
32811
+ if (nestedMessage) {
32812
+ return nestedMessage;
32813
+ }
32814
+ if (isRecord(body) && typeof body.message === "string") {
32815
+ return body.message;
32816
+ }
32817
+ const code = accountErrorCode(body);
32818
+ if (code) {
32819
+ return `Account PS registration signing failed: ${code}`;
32820
+ }
32821
+ return `Account PS registration signing failed: ${status}`;
32822
+ }
32823
+ function accountErrorCode(body) {
32824
+ const nestedCode = nestedAccountErrorField(body, "code");
32825
+ if (nestedCode) {
32826
+ return nestedCode;
32827
+ }
32828
+ if (isRecord(body)) {
32829
+ if (typeof body.code === "string") {
32830
+ return body.code;
32831
+ }
32832
+ if (typeof body.error === "string") {
32833
+ return body.error;
32834
+ }
32835
+ }
32836
+ return void 0;
32837
+ }
32838
+ function nestedAccountErrorField(body, field) {
32839
+ if (!isRecord(body) || !isRecord(body.error)) {
32840
+ return void 0;
32841
+ }
32842
+ const value = body.error[field];
32843
+ return typeof value === "string" ? value : void 0;
32844
+ }
32845
+ function isRecord(value) {
32846
+ return typeof value === "object" && value !== null;
32847
+ }
32848
+ function normalizeAccountResponse(response) {
32849
+ return {
32850
+ ...response,
32851
+ status: response.status === "fallback_required" ? "confirmation_required" : response.status,
32852
+ signerAddress: response.signerAddress ?? response.signer?.address,
32853
+ typedData: response.typedData ?? response.typed_data
32854
+ };
32855
+ }
32856
+ function buildSignedResult(response, request) {
32857
+ assertAddress3(response.signerAddress, "signerAddress");
32858
+ if (response.typedData) {
32859
+ assertTypedDataMatchesRequest(
32860
+ response.typedData,
32861
+ request,
32862
+ response.signerAddress
32863
+ );
32411
32864
  }
32412
32865
  return {
32413
- user: value["user"],
32414
- builder: value["builder"],
32415
- scopes: value["scopes"],
32416
- expiresAt: value["expiresAt"],
32417
- nonce: value["nonce"]
32866
+ signature: response.signature,
32867
+ signerAddress: response.signerAddress,
32868
+ typedData: response.typedData ?? buildPersonalServerRegistrationTypedData({
32869
+ ownerAddress: response.signerAddress,
32870
+ ...request
32871
+ }),
32872
+ intent: ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT
32418
32873
  };
32419
32874
  }
32420
- function parseFileIds(fileIds) {
32421
- try {
32422
- const values = (fileIds ?? []).map((fileId) => BigInt(fileId));
32875
+ function assertTypedDataMatchesRequest(typedData, request, expectedSignerAddress) {
32876
+ assertAddress3(
32877
+ typedData.message.ownerAddress,
32878
+ "typedData.message.ownerAddress"
32879
+ );
32880
+ assertAddress3(
32881
+ typedData.message.serverAddress,
32882
+ "typedData.message.serverAddress"
32883
+ );
32884
+ if (expectedSignerAddress && !sameAddress(typedData.message.ownerAddress, expectedSignerAddress)) {
32885
+ throw new Error(
32886
+ "Account typedData ownerAddress must match the expected signer address"
32887
+ );
32888
+ }
32889
+ if (!sameAddress(typedData.message.serverAddress, request.serverAddress)) {
32890
+ throw new Error(
32891
+ "Account typedData serverAddress must match the requested serverAddress"
32892
+ );
32893
+ }
32894
+ if (typedData.message.publicKey !== request.serverPublicKey) {
32895
+ throw new Error(
32896
+ "Account typedData publicKey must match the requested serverPublicKey"
32897
+ );
32898
+ }
32899
+ if (typedData.message.serverUrl !== request.serverUrl) {
32900
+ throw new Error(
32901
+ "Account typedData serverUrl must match the requested serverUrl"
32902
+ );
32903
+ }
32904
+ if (typedData.primaryType !== "ServerRegistration") {
32905
+ throw new Error("Account typedData primaryType must be ServerRegistration");
32906
+ }
32907
+ if (JSON.stringify(typedData.types) !== JSON.stringify(SERVER_REGISTRATION_TYPES)) {
32908
+ throw new Error("Account typedData types must be ServerRegistration types");
32909
+ }
32910
+ const expectedDomain = personalServerRegistrationDomain({
32911
+ config: request.config,
32912
+ chainId: request.chainId,
32913
+ verifyingContract: request.verifyingContract
32914
+ });
32915
+ if (!domainsEqual(typedData.domain, expectedDomain)) {
32916
+ throw new Error("Account typedData domain must match the requested domain");
32917
+ }
32918
+ }
32919
+ function sameAddress(a, b) {
32920
+ return a.toLowerCase() === b.toLowerCase();
32921
+ }
32922
+ function domainsEqual(a, b) {
32923
+ if (!a || !b) {
32924
+ return false;
32925
+ }
32926
+ 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;
32927
+ }
32928
+ async function signPersonalServerRegistrationWithAccount(config, request) {
32929
+ assertAddress3(request.serverAddress, "serverAddress");
32930
+ const fetchImpl = config.fetchImpl ?? globalThis.fetch.bind(globalThis);
32931
+ const endpoint = new URL(
32932
+ config.endpointPath ?? DEFAULT_ACCOUNT_PS_REGISTRATION_PATH,
32933
+ `${trimTrailingSlash(config.accountOrigin)}/`
32934
+ );
32935
+ const response = await fetchImpl(endpoint, {
32936
+ method: "POST",
32937
+ headers: { "content-type": "application/json" },
32938
+ credentials: "include",
32939
+ body: JSON.stringify({
32940
+ intent: ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT,
32941
+ serverAddress: request.serverAddress,
32942
+ serverPublicKey: request.serverPublicKey,
32943
+ serverUrl: request.serverUrl,
32944
+ config: request.config,
32945
+ chainId: request.chainId,
32946
+ verifyingContract: request.verifyingContract
32947
+ })
32948
+ });
32949
+ const body = normalizeAccountResponse(await parseAccountResponse(response));
32950
+ if (body.status === "signed") {
32951
+ if (!body.signature || !body.signerAddress) {
32952
+ throw new Error(
32953
+ "Account signed response must include signature and signerAddress"
32954
+ );
32955
+ }
32956
+ return {
32957
+ status: "signed",
32958
+ result: buildSignedResult(
32959
+ {
32960
+ signature: body.signature,
32961
+ signerAddress: body.signerAddress,
32962
+ typedData: body.typedData
32963
+ },
32964
+ request
32965
+ )
32966
+ };
32967
+ }
32968
+ if (body.status === "confirmation_required") {
32969
+ if (!body.typedData) {
32970
+ throw new Error(
32971
+ "Account confirmation_required response must include typedData"
32972
+ );
32973
+ }
32974
+ assertTypedDataMatchesRequest(body.typedData, request, body.signerAddress);
32975
+ if (!config.fallbackSigner) {
32976
+ return {
32977
+ status: "confirmation_required",
32978
+ typedData: body.typedData,
32979
+ signerAddress: body.signerAddress
32980
+ };
32981
+ }
32982
+ assertTypedDataMatchesRequest(
32983
+ body.typedData,
32984
+ request,
32985
+ config.fallbackSigner.address
32986
+ );
32987
+ const signature = await config.fallbackSigner.signTypedData(body.typedData);
32423
32988
  return {
32424
- values,
32425
- display: values.map((fileId) => fileId.toString())
32989
+ status: "fallback_signed",
32990
+ accountStatus: "confirmation_required",
32991
+ result: {
32992
+ signature,
32993
+ signerAddress: config.fallbackSigner.address,
32994
+ typedData: body.typedData,
32995
+ intent: ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT
32996
+ }
32426
32997
  };
32998
+ }
32999
+ throw new Error(
33000
+ `Unsupported Account PS registration signing status: ${String(body.status)}`
33001
+ );
33002
+ }
33003
+
33004
+ // src/account/personal-server-lite-owner-binding.ts
33005
+ var AccountPersonalServerLiteOwnerBindingError = class extends Error {
33006
+ code;
33007
+ details;
33008
+ constructor(input) {
33009
+ super(input.message);
33010
+ this.name = "AccountPersonalServerLiteOwnerBindingError";
33011
+ this.code = input.code;
33012
+ this.details = input.details;
33013
+ }
33014
+ };
33015
+ async function signPersonalServerLiteOwnerBindingWithAccountClient(config) {
33016
+ let address;
33017
+ try {
33018
+ address = await config.client.getAddress();
33019
+ } catch (error) {
33020
+ throw accountOwnerBindingError(error);
33021
+ }
33022
+ if (!address) {
33023
+ throw new AccountPersonalServerLiteOwnerBindingError({
33024
+ message: "Account did not return a wallet address",
33025
+ code: "account_address_required"
33026
+ });
33027
+ }
33028
+ const message = buildPersonalServerLiteOwnerBindingMessage(address);
33029
+ let signature;
33030
+ try {
33031
+ signature = await config.client.signMessage({ message });
33032
+ } catch (error) {
33033
+ throw accountOwnerBindingError(error);
33034
+ }
33035
+ return {
33036
+ signature,
33037
+ signerAddress: address,
33038
+ message,
33039
+ purpose: PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE
33040
+ };
33041
+ }
33042
+ function accountOwnerBindingError(error) {
33043
+ if (error instanceof AccountPersonalServerLiteOwnerBindingError) {
33044
+ return error;
33045
+ }
33046
+ const rpcError = error;
33047
+ const code = rpcError?.code;
33048
+ const message = typeof rpcError?.message === "string" && rpcError.message.length > 0 ? rpcError.message : "Account PS Lite owner-binding signature failed";
33049
+ return new AccountPersonalServerLiteOwnerBindingError({
33050
+ message,
33051
+ code,
33052
+ details: error
33053
+ });
33054
+ }
33055
+
33056
+ // src/protocol/grants.ts
33057
+ import { verifyTypedData } from "viem";
33058
+ function isHexString(value) {
33059
+ return typeof value === "string" && value.startsWith("0x");
33060
+ }
33061
+ function isDataPortabilityGatewayConfig(value) {
33062
+ if (value === null || typeof value !== "object" || Array.isArray(value)) {
33063
+ return false;
33064
+ }
33065
+ const config = value;
33066
+ const contracts = config["contracts"];
33067
+ if (typeof config["chainId"] !== "number" || !Number.isInteger(config["chainId"]) || config["chainId"] <= 0 || contracts === null || typeof contracts !== "object" || Array.isArray(contracts)) {
33068
+ return false;
33069
+ }
33070
+ const c = contracts;
33071
+ return isHexString(c["dataRegistry"]) && isHexString(c["dataPortabilityPermissions"]) && isHexString(c["dataPortabilityServer"]) && isHexString(c["dataPortabilityGrantees"]) && isHexString(c["dataPortabilityEscrow"]);
33072
+ }
33073
+ function toUint256(value) {
33074
+ try {
33075
+ const big = typeof value === "bigint" ? value : BigInt(value);
33076
+ if (big < 0n) return null;
33077
+ return big;
32427
33078
  } catch {
32428
33079
  return null;
32429
33080
  }
32430
33081
  }
32431
33082
  async function verifyGrantRegistration(input) {
32432
- const payload = parseGrantRegistrationPayload(input.grant);
32433
- if (!payload) {
32434
- return {
32435
- valid: false,
32436
- error: "Grant must be JSON with scopes and expiresAt"
32437
- };
33083
+ if (!Array.isArray(input.scopes) || input.scopes.length === 0) {
33084
+ return { valid: false, error: "scopes must be a non-empty array" };
32438
33085
  }
32439
- const fileIds = parseFileIds(input.fileIds);
32440
- if (!fileIds) {
32441
- return { valid: false, error: "fileIds must contain integer values" };
33086
+ if (!input.scopes.every((scope) => typeof scope === "string")) {
33087
+ return { valid: false, error: "scopes must contain only strings" };
33088
+ }
33089
+ const grantVersion = toUint256(input.grantVersion);
33090
+ if (grantVersion === null || grantVersion < 1n) {
33091
+ return { valid: false, error: "grantVersion must be a uint256 >= 1" };
33092
+ }
33093
+ const expiresAt = toUint256(input.expiresAt);
33094
+ if (expiresAt === null) {
33095
+ return { valid: false, error: "expiresAt must be a non-negative uint256" };
32442
33096
  }
32443
33097
  let valid;
32444
33098
  try {
@@ -32450,8 +33104,9 @@ async function verifyGrantRegistration(input) {
32450
33104
  message: {
32451
33105
  grantorAddress: input.grantorAddress,
32452
33106
  granteeId: input.granteeId,
32453
- grant: input.grant,
32454
- fileIds: fileIds.values
33107
+ scopes: input.scopes,
33108
+ grantVersion,
33109
+ expiresAt
32455
33110
  },
32456
33111
  signature: input.signature
32457
33112
  });
@@ -32462,19 +33117,69 @@ async function verifyGrantRegistration(input) {
32462
33117
  return { valid: false, error: "Grant signature does not match grantor" };
32463
33118
  }
32464
33119
  const nowSeconds = input.nowSeconds ?? Math.floor(Date.now() / 1e3);
32465
- if (payload.expiresAt > 0 && payload.expiresAt < nowSeconds) {
33120
+ if (expiresAt > 0n && expiresAt < BigInt(nowSeconds)) {
32466
33121
  return { valid: false, error: "Grant has expired" };
32467
33122
  }
32468
- if (payload.user !== void 0 && payload.user.toLowerCase() !== input.grantorAddress.toLowerCase()) {
32469
- return { valid: false, error: "Grant user does not match grantorAddress" };
32470
- }
32471
33123
  return {
32472
33124
  valid: true,
32473
33125
  grantorAddress: input.grantorAddress,
32474
33126
  granteeId: input.granteeId,
32475
- grant: input.grant,
32476
- payload,
32477
- fileIds: fileIds.display
33127
+ scopes: input.scopes,
33128
+ grantVersion: grantVersion.toString(),
33129
+ expiresAt: expiresAt.toString()
33130
+ };
33131
+ }
33132
+
33133
+ // src/protocol/escrow-deposit.ts
33134
+ import { encodeFunctionData } from "viem";
33135
+ var ESCROW_DEPOSIT_ABI = [
33136
+ {
33137
+ type: "function",
33138
+ name: "depositNative",
33139
+ stateMutability: "payable",
33140
+ inputs: [{ name: "account", type: "address" }],
33141
+ outputs: []
33142
+ },
33143
+ {
33144
+ type: "function",
33145
+ name: "depositToken",
33146
+ stateMutability: "nonpayable",
33147
+ inputs: [
33148
+ { name: "account", type: "address" },
33149
+ { name: "token", type: "address" },
33150
+ { name: "amount", type: "uint256" }
33151
+ ],
33152
+ outputs: []
33153
+ }
33154
+ ];
33155
+ function escrowContractAddress(config) {
33156
+ return config.contracts.dataPortabilityEscrow;
33157
+ }
33158
+ function encodeDepositNativeData(input) {
33159
+ return encodeFunctionData({
33160
+ abi: ESCROW_DEPOSIT_ABI,
33161
+ functionName: "depositNative",
33162
+ args: [input.account]
33163
+ });
33164
+ }
33165
+ function encodeDepositTokenData(input) {
33166
+ return encodeFunctionData({
33167
+ abi: ESCROW_DEPOSIT_ABI,
33168
+ functionName: "depositToken",
33169
+ args: [input.account, input.token, input.amount]
33170
+ });
33171
+ }
33172
+ function buildDepositNativeRequest(config, input) {
33173
+ return {
33174
+ to: escrowContractAddress(config),
33175
+ data: encodeDepositNativeData({ account: input.account }),
33176
+ value: input.amount
33177
+ };
33178
+ }
33179
+ function buildDepositTokenRequest(config, input) {
33180
+ return {
33181
+ to: escrowContractAddress(config),
33182
+ data: encodeDepositTokenData(input)
32478
33183
  };
32479
33184
  }
32480
33185
 
@@ -32674,6 +33379,68 @@ function createGatewayClient(baseUrl) {
32674
33379
  alreadyRegistered: false
32675
33380
  };
32676
33381
  },
33382
+ async registerBuilder(params) {
33383
+ const res = await fetch(`${base}/v1/builders`, {
33384
+ method: "POST",
33385
+ headers: {
33386
+ "Content-Type": "application/json",
33387
+ Authorization: `Web3Signed ${params.signature}`
33388
+ },
33389
+ body: JSON.stringify({
33390
+ ownerAddress: params.ownerAddress,
33391
+ granteeAddress: params.granteeAddress,
33392
+ publicKey: params.publicKey,
33393
+ appUrl: params.appUrl
33394
+ })
33395
+ });
33396
+ if (res.status === 409) {
33397
+ const body2 = await res.json().catch(() => ({}));
33398
+ return {
33399
+ builderId: getMutationId(
33400
+ body2,
33401
+ "builderId"
33402
+ ),
33403
+ alreadyRegistered: true
33404
+ };
33405
+ }
33406
+ if (!res.ok) {
33407
+ throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
33408
+ }
33409
+ const body = await res.json().catch(() => ({}));
33410
+ return {
33411
+ builderId: getMutationId(body, "builderId"),
33412
+ alreadyRegistered: false
33413
+ };
33414
+ },
33415
+ async registerDataPoint(params) {
33416
+ const res = await fetch(`${base}/v1/data`, {
33417
+ method: "POST",
33418
+ headers: {
33419
+ "Content-Type": "application/json",
33420
+ Authorization: `Web3Signed ${params.signature}`
33421
+ },
33422
+ body: JSON.stringify({
33423
+ ownerAddress: params.ownerAddress,
33424
+ scope: params.scope,
33425
+ dataHash: params.dataHash,
33426
+ metadataHash: params.metadataHash,
33427
+ expectedVersion: params.expectedVersion
33428
+ })
33429
+ });
33430
+ if (!res.ok) {
33431
+ const body2 = await res.json().catch(() => ({}));
33432
+ const detail = body2.error ?? res.statusText;
33433
+ throw new Error(`Gateway error: ${res.status} ${detail}`);
33434
+ }
33435
+ const body = await res.json().catch(() => ({}));
33436
+ return {
33437
+ dataPointId: getMutationId(
33438
+ body,
33439
+ "dataPointId"
33440
+ ),
33441
+ expectedVersion: body.expectedVersion
33442
+ };
33443
+ },
32677
33444
  async registerFile(params) {
32678
33445
  const res = await fetch(`${base}/v1/files`, {
32679
33446
  method: "POST",
@@ -32711,8 +33478,9 @@ function createGatewayClient(baseUrl) {
32711
33478
  body: JSON.stringify({
32712
33479
  grantorAddress: params.grantorAddress,
32713
33480
  granteeId: params.granteeId,
32714
- grant: params.grant,
32715
- fileIds: params.fileIds
33481
+ scopes: params.scopes,
33482
+ grantVersion: params.grantVersion,
33483
+ expiresAt: params.expiresAt
32716
33484
  })
32717
33485
  });
32718
33486
  if (res.status === 409) {
@@ -32737,13 +33505,71 @@ function createGatewayClient(baseUrl) {
32737
33505
  Authorization: `Web3Signed ${params.signature}`
32738
33506
  },
32739
33507
  body: JSON.stringify({
32740
- grantorAddress: params.grantorAddress
33508
+ grantorAddress: params.grantorAddress,
33509
+ grantVersion: params.grantVersion
32741
33510
  })
32742
33511
  });
32743
33512
  if (res.status === 409) return;
32744
33513
  if (!res.ok) {
32745
33514
  throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
32746
33515
  }
33516
+ },
33517
+ async getEscrowBalance(account) {
33518
+ const res = await fetch(`${base}/v1/escrow/balance?account=${account}`);
33519
+ if (!res.ok) {
33520
+ throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
33521
+ }
33522
+ return await res.json();
33523
+ },
33524
+ async submitEscrowDeposit(params) {
33525
+ const res = await fetch(`${base}/v1/escrow/deposit`, {
33526
+ method: "POST",
33527
+ headers: { "Content-Type": "application/json" },
33528
+ body: JSON.stringify({ txHash: params.txHash })
33529
+ });
33530
+ if (res.status !== 200 && res.status !== 202) {
33531
+ throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
33532
+ }
33533
+ return await res.json();
33534
+ },
33535
+ async payForOperation(params) {
33536
+ const body = {
33537
+ payerAddress: params.payerAddress,
33538
+ opType: params.opType,
33539
+ opId: params.opId,
33540
+ asset: params.asset,
33541
+ amount: params.amount,
33542
+ paymentNonce: params.paymentNonce
33543
+ };
33544
+ if (params.accessRecord) {
33545
+ body["accessRecord"] = params.accessRecord;
33546
+ }
33547
+ const res = await fetch(`${base}/v1/escrow/pay`, {
33548
+ method: "POST",
33549
+ headers: {
33550
+ "Content-Type": "application/json",
33551
+ Authorization: `Web3Signed ${params.signature}`
33552
+ },
33553
+ body: JSON.stringify(body)
33554
+ });
33555
+ if (!res.ok) {
33556
+ throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
33557
+ }
33558
+ return await res.json();
33559
+ },
33560
+ async settle(params) {
33561
+ const res = await fetch(`${base}/v1/settle`, {
33562
+ method: "POST",
33563
+ headers: { "Content-Type": "application/json" },
33564
+ // The gateway accepts an empty body; only `limit` is recognised.
33565
+ // Always send a JSON body so the gateway's req.body shape parse
33566
+ // doesn't have to deal with an undefined.
33567
+ body: JSON.stringify(params ?? {})
33568
+ });
33569
+ if (!res.ok) {
33570
+ throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
33571
+ }
33572
+ return await res.json();
32747
33573
  }
32748
33574
  };
32749
33575
  }
@@ -32773,7 +33599,7 @@ var KNOWN_CODES = /* @__PURE__ */ new Set([
32773
33599
  "server_not_configured",
32774
33600
  "content_too_large"
32775
33601
  ]);
32776
- function isRecord(value) {
33602
+ function isRecord2(value) {
32777
33603
  return value !== null && typeof value === "object" && !Array.isArray(value);
32778
33604
  }
32779
33605
  function normalizeCode(value) {
@@ -32784,10 +33610,10 @@ function normalizeCode(value) {
32784
33610
  return KNOWN_CODES.has(code) ? code : null;
32785
33611
  }
32786
33612
  function extractPSErrorBody(body) {
32787
- if (!isRecord(body)) {
33613
+ if (!isRecord2(body)) {
32788
33614
  return null;
32789
33615
  }
32790
- const nested = isRecord(body.error) ? body.error : null;
33616
+ const nested = isRecord2(body.error) ? body.error : null;
32791
33617
  const code = normalizeCode(
32792
33618
  nested?.errorCode ?? nested?.code ?? body.errorCode ?? body.code
32793
33619
  );
@@ -32811,6 +33637,10 @@ async function parsePSError(response) {
32811
33637
  return errorBody ? new PSError(errorBody.code, errorBody.message) : null;
32812
33638
  }
32813
33639
  export {
33640
+ ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT,
33641
+ ADD_DATA_TYPES,
33642
+ AccountPersonalServerLiteOwnerBindingError,
33643
+ AccountPersonalServerRegistrationError,
32814
33644
  BUILDER_REGISTRATION_TYPES,
32815
33645
  BlockchainError,
32816
33646
  BrowserPlatformAdapter,
@@ -32821,8 +33651,10 @@ export {
32821
33651
  DataFileEnvelopeSchema,
32822
33652
  DropboxStorage,
32823
33653
  ECIESError,
33654
+ ESCROW_DEPOSIT_ABI,
32824
33655
  ExpiredTokenError,
32825
33656
  FILE_REGISTRATION_TYPES,
33657
+ GENERIC_PAYMENT_TYPES,
32826
33658
  GRANT_REGISTRATION_TYPES,
32827
33659
  GRANT_REVOCATION_TYPES,
32828
33660
  GoogleDriveStorage,
@@ -32833,10 +33665,17 @@ export {
32833
33665
  IpfsStorage,
32834
33666
  MASTER_KEY_MESSAGE,
32835
33667
  MissingAuthError,
33668
+ NATIVE_VANA_ASSET,
32836
33669
  NetworkError,
32837
33670
  NodeECIESUint8Provider as NodeECIESProvider,
32838
33671
  NodePlatformAdapter,
32839
33672
  NonceError,
33673
+ OAuthClient,
33674
+ PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX,
33675
+ PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE,
33676
+ PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION,
33677
+ PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID,
33678
+ PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT,
32840
33679
  PKCE_CHALLENGE_PATTERN,
32841
33680
  PKCE_VERIFIER_PATTERN,
32842
33681
  PSError,
@@ -32844,6 +33683,7 @@ export {
32844
33683
  PersonalServerError,
32845
33684
  PinataStorage,
32846
33685
  R2Storage,
33686
+ RECORD_DATA_ACCESS_TYPES,
32847
33687
  ReadOnlyError,
32848
33688
  RelayerError,
32849
33689
  SERVER_REGISTRATION_TYPES,
@@ -32858,6 +33698,12 @@ export {
32858
33698
  VanaError,
32859
33699
  VanaStorage,
32860
33700
  assertValidPkceVerifier,
33701
+ buildDepositNativeRequest,
33702
+ buildDepositTokenRequest,
33703
+ buildPersonalServerLiteOwnerBindingMessage,
33704
+ buildPersonalServerLiteOwnerBindingSignature,
33705
+ buildPersonalServerRegistrationSignature,
33706
+ buildPersonalServerRegistrationTypedData,
32861
33707
  buildWeb3SignedHeader,
32862
33708
  builderRegistrationDomain,
32863
33709
  chains,
@@ -32873,12 +33719,19 @@ export {
32873
33719
  createPlatformAdapterFor,
32874
33720
  createPlatformAdapterSafe,
32875
33721
  createVanaStorageProvider,
33722
+ createViemPersonalServerLiteOwnerBindingSigner,
33723
+ createViemPersonalServerRegistrationSigner,
33724
+ dataRegistryDomain,
32876
33725
  decryptWithPassword,
32877
33726
  deriveMasterKey,
32878
33727
  deriveScopeKey,
32879
33728
  deserializeECIES,
32880
33729
  detectPlatform,
33730
+ encodeDepositNativeData,
33731
+ encodeDepositTokenData,
32881
33732
  encryptWithPassword,
33733
+ escrowContractAddress,
33734
+ escrowPaymentDomain,
32882
33735
  fileRegistrationDomain,
32883
33736
  generatePkceVerifier,
32884
33737
  getAbi,
@@ -32898,16 +33751,20 @@ export {
32898
33751
  moksha,
32899
33752
  mokshaServices,
32900
33753
  mokshaTestnet2 as mokshaTestnet,
32901
- parseGrantRegistrationPayload,
32902
33754
  parsePSError,
32903
33755
  parseScope,
32904
33756
  parseWeb3SignedHeader,
33757
+ personalServerRegistrationDomain,
32905
33758
  recoverServerOwner,
33759
+ registerPersonalServerSignature,
32906
33760
  scopeCoveredByGrant,
32907
33761
  scopeMatchesPattern,
32908
33762
  scopeToPathSegments,
32909
33763
  serializeECIES,
32910
33764
  serverRegistrationDomain,
33765
+ signPersonalServerLiteOwnerBinding,
33766
+ signPersonalServerLiteOwnerBindingWithAccountClient,
33767
+ signPersonalServerRegistrationWithAccount,
32911
33768
  vanaMainnet2 as vanaMainnet,
32912
33769
  verifyGrantRegistration,
32913
33770
  verifyPkceChallenge,