@opendatalabs/vana-sdk 3.0.1 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) 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 +5 -0
  40. package/dist/index.browser.js +671 -4
  41. package/dist/index.browser.js.map +4 -4
  42. package/dist/index.node.cjs +689 -6
  43. package/dist/index.node.cjs.map +4 -4
  44. package/dist/index.node.d.ts +5 -0
  45. package/dist/index.node.js +671 -4
  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.map +1 -1
  58. package/dist/protocol/eip712.d.ts +1 -1
  59. package/dist/protocol/eip712.js.map +1 -1
  60. package/dist/protocol/grants.js +1 -1
  61. package/dist/protocol/personal-server-lite-owner-binding.cjs +93 -0
  62. package/dist/protocol/personal-server-lite-owner-binding.cjs.map +1 -0
  63. package/dist/protocol/personal-server-lite-owner-binding.d.ts +44 -0
  64. package/dist/protocol/personal-server-lite-owner-binding.js +65 -0
  65. package/dist/protocol/personal-server-lite-owner-binding.js.map +1 -0
  66. package/dist/protocol/personal-server-lite-owner-binding.test.d.ts +1 -0
  67. package/dist/protocol/personal-server-registration.cjs +122 -0
  68. package/dist/protocol/personal-server-registration.cjs.map +1 -0
  69. package/dist/protocol/personal-server-registration.d.ts +62 -0
  70. package/dist/protocol/personal-server-registration.js +97 -0
  71. package/dist/protocol/personal-server-registration.js.map +1 -0
  72. package/dist/protocol/personal-server-registration.test.d.ts +1 -0
  73. package/dist/storage/default.js +1 -1
  74. package/dist/storage/index.cjs.map +1 -1
  75. package/dist/storage/index.d.ts +1 -1
  76. package/dist/storage/index.js +10 -10
  77. package/dist/storage/index.js.map +1 -1
  78. package/dist/storage/manager.js +1 -1
  79. package/dist/storage/providers/callback-storage.js +1 -1
  80. package/dist/storage/providers/dropbox.js +1 -1
  81. package/dist/storage/providers/google-drive.js +1 -1
  82. package/dist/storage/providers/ipfs.js +2 -2
  83. package/dist/storage/providers/pinata.js +1 -1
  84. package/dist/storage/providers/r2.js +1 -1
  85. package/dist/storage/providers/vana-storage.cjs +1 -1
  86. package/dist/storage/providers/vana-storage.cjs.map +1 -1
  87. package/dist/storage/providers/vana-storage.d.ts +2 -2
  88. package/dist/storage/providers/vana-storage.js +3 -3
  89. package/dist/storage/providers/vana-storage.js.map +1 -1
  90. package/dist/types/index.js +2 -2
  91. package/dist/types.js +1 -1
  92. package/package.json +5 -2
@@ -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,6 +32284,228 @@ 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";
@@ -32363,6 +32585,431 @@ var BUILDER_REGISTRATION_TYPES = {
32363
32585
  ]
32364
32586
  };
32365
32587
 
32588
+ // src/protocol/personal-server-registration.ts
32589
+ import {
32590
+ isAddress
32591
+ } from "viem";
32592
+ var PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID = 1480;
32593
+ var PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT = "0x1483B1F634DBA75AeaE60da7f01A679aabd5ee2c";
32594
+ function assertAddress(value, name) {
32595
+ if (!isAddress(value)) {
32596
+ throw new Error(`${name} must be a valid EVM address`);
32597
+ }
32598
+ }
32599
+ function getAccountAddress(account) {
32600
+ if (!account) {
32601
+ return void 0;
32602
+ }
32603
+ return typeof account === "string" ? account : account.address;
32604
+ }
32605
+ function isPersonalServerRegistrationSigner(source) {
32606
+ return "address" in source && typeof source.signTypedData === "function";
32607
+ }
32608
+ function createViemPersonalServerRegistrationSigner(source, options = {}) {
32609
+ if (isPersonalServerRegistrationSigner(source)) {
32610
+ return source;
32611
+ }
32612
+ const accountAddress = getAccountAddress(options.account) ?? getAccountAddress(source.account);
32613
+ if (accountAddress) {
32614
+ return {
32615
+ address: accountAddress,
32616
+ signTypedData: (typedData) => source.signTypedData({
32617
+ ...typedData,
32618
+ account: options.account ?? source.account ?? accountAddress
32619
+ })
32620
+ };
32621
+ }
32622
+ throw new Error(
32623
+ "Viem wallet client requires an account option or account property"
32624
+ );
32625
+ }
32626
+ function personalServerRegistrationDomain(input = {}) {
32627
+ if (input.config) {
32628
+ return serverRegistrationDomain(input.config);
32629
+ }
32630
+ const verifyingContract = input.verifyingContract ?? PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT;
32631
+ assertAddress(verifyingContract, "verifyingContract");
32632
+ return {
32633
+ name: "Vana Data Portability",
32634
+ version: "1",
32635
+ chainId: input.chainId ?? PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID,
32636
+ verifyingContract
32637
+ };
32638
+ }
32639
+ function buildPersonalServerRegistrationTypedData(input) {
32640
+ assertAddress(input.ownerAddress, "ownerAddress");
32641
+ assertAddress(input.serverAddress, "serverAddress");
32642
+ return {
32643
+ domain: personalServerRegistrationDomain(input),
32644
+ types: SERVER_REGISTRATION_TYPES,
32645
+ primaryType: "ServerRegistration",
32646
+ message: {
32647
+ ownerAddress: input.ownerAddress,
32648
+ serverAddress: input.serverAddress,
32649
+ publicKey: input.serverPublicKey,
32650
+ serverUrl: input.serverUrl
32651
+ }
32652
+ };
32653
+ }
32654
+ async function buildPersonalServerRegistrationSignature(input) {
32655
+ const typedData = buildPersonalServerRegistrationTypedData({
32656
+ ownerAddress: input.signer.address,
32657
+ serverAddress: input.serverAddress,
32658
+ serverPublicKey: input.serverPublicKey,
32659
+ serverUrl: input.serverUrl,
32660
+ config: input.config,
32661
+ chainId: input.chainId,
32662
+ verifyingContract: input.verifyingContract
32663
+ });
32664
+ const signature = await input.signer.signTypedData(typedData);
32665
+ return {
32666
+ signature,
32667
+ signerAddress: input.signer.address,
32668
+ typedData
32669
+ };
32670
+ }
32671
+ var registerPersonalServerSignature = buildPersonalServerRegistrationSignature;
32672
+
32673
+ // src/protocol/personal-server-lite-owner-binding.ts
32674
+ import {
32675
+ isAddress as isAddress2
32676
+ } from "viem";
32677
+ var PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION = "vana.account.v1";
32678
+ var PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE = "ps-lite-owner";
32679
+ var PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX = `${PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION}:${PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE}:`;
32680
+ function assertAddress2(value, name) {
32681
+ if (!isAddress2(value)) {
32682
+ throw new Error(`${name} must be a valid EVM address`);
32683
+ }
32684
+ }
32685
+ function getAccountAddress2(account) {
32686
+ if (!account) {
32687
+ return void 0;
32688
+ }
32689
+ return typeof account === "string" ? account : account.address;
32690
+ }
32691
+ function isPersonalServerLiteOwnerBindingSigner(source) {
32692
+ return "address" in source && typeof source.signMessage === "function";
32693
+ }
32694
+ function buildPersonalServerLiteOwnerBindingMessage(ownerAddress) {
32695
+ assertAddress2(ownerAddress, "ownerAddress");
32696
+ return `${PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX}${ownerAddress.toLowerCase()}`;
32697
+ }
32698
+ function createViemPersonalServerLiteOwnerBindingSigner(source, options = {}) {
32699
+ if (isPersonalServerLiteOwnerBindingSigner(source)) {
32700
+ return source;
32701
+ }
32702
+ const accountAddress = getAccountAddress2(options.account) ?? getAccountAddress2(source.account);
32703
+ if (accountAddress) {
32704
+ return {
32705
+ address: accountAddress,
32706
+ signMessage: ({ message }) => source.signMessage({
32707
+ account: options.account ?? source.account ?? accountAddress,
32708
+ message
32709
+ })
32710
+ };
32711
+ }
32712
+ throw new Error(
32713
+ "Viem wallet client requires an account option or account property"
32714
+ );
32715
+ }
32716
+ async function buildPersonalServerLiteOwnerBindingSignature(input) {
32717
+ const message = buildPersonalServerLiteOwnerBindingMessage(
32718
+ input.signer.address
32719
+ );
32720
+ const signature = await input.signer.signMessage({ message });
32721
+ return {
32722
+ signature,
32723
+ signerAddress: input.signer.address,
32724
+ message,
32725
+ purpose: PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE
32726
+ };
32727
+ }
32728
+ var signPersonalServerLiteOwnerBinding = buildPersonalServerLiteOwnerBindingSignature;
32729
+
32730
+ // src/account/personal-server-registration.ts
32731
+ import { isAddress as isAddress3 } from "viem";
32732
+ var ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT = "personal_server.server_registration.v1";
32733
+ var AccountPersonalServerRegistrationError = class extends Error {
32734
+ status;
32735
+ code;
32736
+ details;
32737
+ constructor(input) {
32738
+ super(input.message);
32739
+ this.name = "AccountPersonalServerRegistrationError";
32740
+ this.status = input.status;
32741
+ this.code = input.code;
32742
+ this.details = input.details;
32743
+ }
32744
+ };
32745
+ var DEFAULT_ACCOUNT_PS_REGISTRATION_PATH = "/api/v1/intents/personal-server-registration/sign";
32746
+ function trimTrailingSlash(value) {
32747
+ return value.replace(/\/+$/, "");
32748
+ }
32749
+ function assertAddress3(value, name) {
32750
+ if (!isAddress3(value)) {
32751
+ throw new Error(`${name} must be a valid EVM address`);
32752
+ }
32753
+ }
32754
+ async function parseAccountResponse(response) {
32755
+ const body = await response.json().catch(() => void 0);
32756
+ if (!response.ok) {
32757
+ throw new AccountPersonalServerRegistrationError({
32758
+ status: response.status,
32759
+ code: accountErrorCode(body),
32760
+ message: accountErrorMessage(response.status, body),
32761
+ details: body
32762
+ });
32763
+ }
32764
+ return body;
32765
+ }
32766
+ function accountErrorMessage(status, body) {
32767
+ const nestedMessage = nestedAccountErrorField(body, "message");
32768
+ if (nestedMessage) {
32769
+ return nestedMessage;
32770
+ }
32771
+ if (isRecord(body) && typeof body.message === "string") {
32772
+ return body.message;
32773
+ }
32774
+ const code = accountErrorCode(body);
32775
+ if (code) {
32776
+ return `Account PS registration signing failed: ${code}`;
32777
+ }
32778
+ return `Account PS registration signing failed: ${status}`;
32779
+ }
32780
+ function accountErrorCode(body) {
32781
+ const nestedCode = nestedAccountErrorField(body, "code");
32782
+ if (nestedCode) {
32783
+ return nestedCode;
32784
+ }
32785
+ if (isRecord(body)) {
32786
+ if (typeof body.code === "string") {
32787
+ return body.code;
32788
+ }
32789
+ if (typeof body.error === "string") {
32790
+ return body.error;
32791
+ }
32792
+ }
32793
+ return void 0;
32794
+ }
32795
+ function nestedAccountErrorField(body, field) {
32796
+ if (!isRecord(body) || !isRecord(body.error)) {
32797
+ return void 0;
32798
+ }
32799
+ const value = body.error[field];
32800
+ return typeof value === "string" ? value : void 0;
32801
+ }
32802
+ function isRecord(value) {
32803
+ return typeof value === "object" && value !== null;
32804
+ }
32805
+ function normalizeAccountResponse(response) {
32806
+ return {
32807
+ ...response,
32808
+ status: response.status === "fallback_required" ? "confirmation_required" : response.status,
32809
+ signerAddress: response.signerAddress ?? response.signer?.address,
32810
+ typedData: response.typedData ?? response.typed_data
32811
+ };
32812
+ }
32813
+ function buildSignedResult(response, request) {
32814
+ assertAddress3(response.signerAddress, "signerAddress");
32815
+ if (response.typedData) {
32816
+ assertTypedDataMatchesRequest(
32817
+ response.typedData,
32818
+ request,
32819
+ response.signerAddress
32820
+ );
32821
+ }
32822
+ return {
32823
+ signature: response.signature,
32824
+ signerAddress: response.signerAddress,
32825
+ typedData: response.typedData ?? buildPersonalServerRegistrationTypedData({
32826
+ ownerAddress: response.signerAddress,
32827
+ ...request
32828
+ }),
32829
+ intent: ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT
32830
+ };
32831
+ }
32832
+ function assertTypedDataMatchesRequest(typedData, request, expectedSignerAddress) {
32833
+ assertAddress3(
32834
+ typedData.message.ownerAddress,
32835
+ "typedData.message.ownerAddress"
32836
+ );
32837
+ assertAddress3(
32838
+ typedData.message.serverAddress,
32839
+ "typedData.message.serverAddress"
32840
+ );
32841
+ if (expectedSignerAddress && !sameAddress(typedData.message.ownerAddress, expectedSignerAddress)) {
32842
+ throw new Error(
32843
+ "Account typedData ownerAddress must match the expected signer address"
32844
+ );
32845
+ }
32846
+ if (!sameAddress(typedData.message.serverAddress, request.serverAddress)) {
32847
+ throw new Error(
32848
+ "Account typedData serverAddress must match the requested serverAddress"
32849
+ );
32850
+ }
32851
+ if (typedData.message.publicKey !== request.serverPublicKey) {
32852
+ throw new Error(
32853
+ "Account typedData publicKey must match the requested serverPublicKey"
32854
+ );
32855
+ }
32856
+ if (typedData.message.serverUrl !== request.serverUrl) {
32857
+ throw new Error(
32858
+ "Account typedData serverUrl must match the requested serverUrl"
32859
+ );
32860
+ }
32861
+ if (typedData.primaryType !== "ServerRegistration") {
32862
+ throw new Error("Account typedData primaryType must be ServerRegistration");
32863
+ }
32864
+ if (JSON.stringify(typedData.types) !== JSON.stringify(SERVER_REGISTRATION_TYPES)) {
32865
+ throw new Error("Account typedData types must be ServerRegistration types");
32866
+ }
32867
+ const expectedDomain = personalServerRegistrationDomain({
32868
+ config: request.config,
32869
+ chainId: request.chainId,
32870
+ verifyingContract: request.verifyingContract
32871
+ });
32872
+ if (!domainsEqual(typedData.domain, expectedDomain)) {
32873
+ throw new Error("Account typedData domain must match the requested domain");
32874
+ }
32875
+ }
32876
+ function sameAddress(a, b) {
32877
+ return a.toLowerCase() === b.toLowerCase();
32878
+ }
32879
+ function domainsEqual(a, b) {
32880
+ if (!a || !b) {
32881
+ return false;
32882
+ }
32883
+ 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;
32884
+ }
32885
+ async function signPersonalServerRegistrationWithAccount(config, request) {
32886
+ assertAddress3(request.serverAddress, "serverAddress");
32887
+ const fetchImpl = config.fetchImpl ?? globalThis.fetch.bind(globalThis);
32888
+ const endpoint = new URL(
32889
+ config.endpointPath ?? DEFAULT_ACCOUNT_PS_REGISTRATION_PATH,
32890
+ `${trimTrailingSlash(config.accountOrigin)}/`
32891
+ );
32892
+ const response = await fetchImpl(endpoint, {
32893
+ method: "POST",
32894
+ headers: { "content-type": "application/json" },
32895
+ credentials: "include",
32896
+ body: JSON.stringify({
32897
+ intent: ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT,
32898
+ serverAddress: request.serverAddress,
32899
+ serverPublicKey: request.serverPublicKey,
32900
+ serverUrl: request.serverUrl,
32901
+ config: request.config,
32902
+ chainId: request.chainId,
32903
+ verifyingContract: request.verifyingContract
32904
+ })
32905
+ });
32906
+ const body = normalizeAccountResponse(await parseAccountResponse(response));
32907
+ if (body.status === "signed") {
32908
+ if (!body.signature || !body.signerAddress) {
32909
+ throw new Error(
32910
+ "Account signed response must include signature and signerAddress"
32911
+ );
32912
+ }
32913
+ return {
32914
+ status: "signed",
32915
+ result: buildSignedResult(
32916
+ {
32917
+ signature: body.signature,
32918
+ signerAddress: body.signerAddress,
32919
+ typedData: body.typedData
32920
+ },
32921
+ request
32922
+ )
32923
+ };
32924
+ }
32925
+ if (body.status === "confirmation_required") {
32926
+ if (!body.typedData) {
32927
+ throw new Error(
32928
+ "Account confirmation_required response must include typedData"
32929
+ );
32930
+ }
32931
+ assertTypedDataMatchesRequest(body.typedData, request, body.signerAddress);
32932
+ if (!config.fallbackSigner) {
32933
+ return {
32934
+ status: "confirmation_required",
32935
+ typedData: body.typedData,
32936
+ signerAddress: body.signerAddress
32937
+ };
32938
+ }
32939
+ assertTypedDataMatchesRequest(
32940
+ body.typedData,
32941
+ request,
32942
+ config.fallbackSigner.address
32943
+ );
32944
+ const signature = await config.fallbackSigner.signTypedData(body.typedData);
32945
+ return {
32946
+ status: "fallback_signed",
32947
+ accountStatus: "confirmation_required",
32948
+ result: {
32949
+ signature,
32950
+ signerAddress: config.fallbackSigner.address,
32951
+ typedData: body.typedData,
32952
+ intent: ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT
32953
+ }
32954
+ };
32955
+ }
32956
+ throw new Error(
32957
+ `Unsupported Account PS registration signing status: ${String(body.status)}`
32958
+ );
32959
+ }
32960
+
32961
+ // src/account/personal-server-lite-owner-binding.ts
32962
+ var AccountPersonalServerLiteOwnerBindingError = class extends Error {
32963
+ code;
32964
+ details;
32965
+ constructor(input) {
32966
+ super(input.message);
32967
+ this.name = "AccountPersonalServerLiteOwnerBindingError";
32968
+ this.code = input.code;
32969
+ this.details = input.details;
32970
+ }
32971
+ };
32972
+ async function signPersonalServerLiteOwnerBindingWithAccountClient(config) {
32973
+ let address;
32974
+ try {
32975
+ address = await config.client.getAddress();
32976
+ } catch (error) {
32977
+ throw accountOwnerBindingError(error);
32978
+ }
32979
+ if (!address) {
32980
+ throw new AccountPersonalServerLiteOwnerBindingError({
32981
+ message: "Account did not return a wallet address",
32982
+ code: "account_address_required"
32983
+ });
32984
+ }
32985
+ const message = buildPersonalServerLiteOwnerBindingMessage(address);
32986
+ let signature;
32987
+ try {
32988
+ signature = await config.client.signMessage({ message });
32989
+ } catch (error) {
32990
+ throw accountOwnerBindingError(error);
32991
+ }
32992
+ return {
32993
+ signature,
32994
+ signerAddress: address,
32995
+ message,
32996
+ purpose: PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE
32997
+ };
32998
+ }
32999
+ function accountOwnerBindingError(error) {
33000
+ if (error instanceof AccountPersonalServerLiteOwnerBindingError) {
33001
+ return error;
33002
+ }
33003
+ const rpcError = error;
33004
+ const code = rpcError?.code;
33005
+ const message = typeof rpcError?.message === "string" && rpcError.message.length > 0 ? rpcError.message : "Account PS Lite owner-binding signature failed";
33006
+ return new AccountPersonalServerLiteOwnerBindingError({
33007
+ message,
33008
+ code,
33009
+ details: error
33010
+ });
33011
+ }
33012
+
32366
33013
  // src/protocol/grants.ts
32367
33014
  import { verifyTypedData } from "viem";
32368
33015
  function isHexString(value) {
@@ -32773,7 +33420,7 @@ var KNOWN_CODES = /* @__PURE__ */ new Set([
32773
33420
  "server_not_configured",
32774
33421
  "content_too_large"
32775
33422
  ]);
32776
- function isRecord(value) {
33423
+ function isRecord2(value) {
32777
33424
  return value !== null && typeof value === "object" && !Array.isArray(value);
32778
33425
  }
32779
33426
  function normalizeCode(value) {
@@ -32784,10 +33431,10 @@ function normalizeCode(value) {
32784
33431
  return KNOWN_CODES.has(code) ? code : null;
32785
33432
  }
32786
33433
  function extractPSErrorBody(body) {
32787
- if (!isRecord(body)) {
33434
+ if (!isRecord2(body)) {
32788
33435
  return null;
32789
33436
  }
32790
- const nested = isRecord(body.error) ? body.error : null;
33437
+ const nested = isRecord2(body.error) ? body.error : null;
32791
33438
  const code = normalizeCode(
32792
33439
  nested?.errorCode ?? nested?.code ?? body.errorCode ?? body.code
32793
33440
  );
@@ -32811,6 +33458,9 @@ async function parsePSError(response) {
32811
33458
  return errorBody ? new PSError(errorBody.code, errorBody.message) : null;
32812
33459
  }
32813
33460
  export {
33461
+ ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT,
33462
+ AccountPersonalServerLiteOwnerBindingError,
33463
+ AccountPersonalServerRegistrationError,
32814
33464
  BUILDER_REGISTRATION_TYPES,
32815
33465
  BlockchainError,
32816
33466
  BrowserPlatformAdapter,
@@ -32837,6 +33487,12 @@ export {
32837
33487
  NodeECIESUint8Provider as NodeECIESProvider,
32838
33488
  NodePlatformAdapter,
32839
33489
  NonceError,
33490
+ OAuthClient,
33491
+ PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX,
33492
+ PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE,
33493
+ PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION,
33494
+ PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID,
33495
+ PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT,
32840
33496
  PKCE_CHALLENGE_PATTERN,
32841
33497
  PKCE_VERIFIER_PATTERN,
32842
33498
  PSError,
@@ -32858,6 +33514,10 @@ export {
32858
33514
  VanaError,
32859
33515
  VanaStorage,
32860
33516
  assertValidPkceVerifier,
33517
+ buildPersonalServerLiteOwnerBindingMessage,
33518
+ buildPersonalServerLiteOwnerBindingSignature,
33519
+ buildPersonalServerRegistrationSignature,
33520
+ buildPersonalServerRegistrationTypedData,
32861
33521
  buildWeb3SignedHeader,
32862
33522
  builderRegistrationDomain,
32863
33523
  chains,
@@ -32873,6 +33533,8 @@ export {
32873
33533
  createPlatformAdapterFor,
32874
33534
  createPlatformAdapterSafe,
32875
33535
  createVanaStorageProvider,
33536
+ createViemPersonalServerLiteOwnerBindingSigner,
33537
+ createViemPersonalServerRegistrationSigner,
32876
33538
  decryptWithPassword,
32877
33539
  deriveMasterKey,
32878
33540
  deriveScopeKey,
@@ -32902,12 +33564,17 @@ export {
32902
33564
  parsePSError,
32903
33565
  parseScope,
32904
33566
  parseWeb3SignedHeader,
33567
+ personalServerRegistrationDomain,
32905
33568
  recoverServerOwner,
33569
+ registerPersonalServerSignature,
32906
33570
  scopeCoveredByGrant,
32907
33571
  scopeMatchesPattern,
32908
33572
  scopeToPathSegments,
32909
33573
  serializeECIES,
32910
33574
  serverRegistrationDomain,
33575
+ signPersonalServerLiteOwnerBinding,
33576
+ signPersonalServerLiteOwnerBindingWithAccountClient,
33577
+ signPersonalServerRegistrationWithAccount,
32911
33578
  vanaMainnet2 as vanaMainnet,
32912
33579
  verifyGrantRegistration,
32913
33580
  verifyPkceChallenge,