@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
@@ -29006,7 +29006,7 @@ async function buildWeb3SignedHeader(params) {
29006
29006
  }
29007
29007
 
29008
29008
  // src/storage/providers/vana-storage.ts
29009
- var DEFAULT_ENDPOINT = "https://storage.vana.com";
29009
+ var DEFAULT_ENDPOINT = "https://storage.vana.org";
29010
29010
  var BLOB_PATH_PREFIX = "/v1/blobs";
29011
29011
  var DEFAULT_TOKEN_TTL_SECONDS = 300;
29012
29012
  var VanaStorage = class {
@@ -31432,6 +31432,228 @@ var InMemoryTokenStore = class {
31432
31432
  }
31433
31433
  };
31434
31434
 
31435
+ // src/auth/oauth-client.ts
31436
+ var VERIFIER_TTL_SECONDS = 600;
31437
+ var RESERVED_AUTHORIZE_PARAMS = /* @__PURE__ */ new Set([
31438
+ "response_type",
31439
+ "client_id",
31440
+ "redirect_uri",
31441
+ "scope",
31442
+ "state",
31443
+ "code_challenge",
31444
+ "code_challenge_method"
31445
+ ]);
31446
+ var OAuthClient = class {
31447
+ #config;
31448
+ constructor(config) {
31449
+ const fetchImpl = config.fetchImpl ?? globalThis.fetch;
31450
+ if (typeof fetchImpl !== "function") {
31451
+ throw new TypeError(
31452
+ "OAuthClient requires a global `fetch` or an explicit `fetchImpl`"
31453
+ );
31454
+ }
31455
+ this.#config = {
31456
+ authorizationEndpoint: config.authorizationEndpoint,
31457
+ tokenEndpoint: config.tokenEndpoint,
31458
+ clientId: config.clientId,
31459
+ redirectUri: config.redirectUri,
31460
+ scope: config.scope,
31461
+ tokenStore: config.tokenStore ?? new InMemoryTokenStore(),
31462
+ fetchImpl,
31463
+ generateState: config.generateState ?? defaultGenerateState
31464
+ };
31465
+ }
31466
+ /** Build the authorize URL and persist the PKCE verifier keyed by `state`. */
31467
+ async buildAuthorizationUrl(opts = {}) {
31468
+ const state = opts.state ?? this.#config.generateState();
31469
+ const scope = opts.scope ?? this.#config.scope;
31470
+ const verifier = generatePkceVerifier();
31471
+ const challenge = await computePkceChallenge(verifier);
31472
+ await this.#config.tokenStore.set(this.#verifierKey(state), {
31473
+ token: verifier,
31474
+ expiresAt: Math.floor(Date.now() / 1e3) + VERIFIER_TTL_SECONDS
31475
+ });
31476
+ const params = new URLSearchParams();
31477
+ params.set("response_type", "code");
31478
+ params.set("client_id", this.#config.clientId);
31479
+ params.set("redirect_uri", this.#config.redirectUri);
31480
+ if (scope !== void 0 && scope.length > 0) {
31481
+ params.set("scope", scope);
31482
+ }
31483
+ params.set("state", state);
31484
+ params.set("code_challenge", challenge);
31485
+ params.set("code_challenge_method", "S256");
31486
+ if (opts.extraParams !== void 0) {
31487
+ for (const k of Object.keys(opts.extraParams)) {
31488
+ if (RESERVED_AUTHORIZE_PARAMS.has(k)) {
31489
+ throw new Error(
31490
+ `extraParams may not override the reserved OAuth/PKCE parameter "${k}"`
31491
+ );
31492
+ }
31493
+ }
31494
+ for (const [k, v] of Object.entries(opts.extraParams)) {
31495
+ params.set(k, v);
31496
+ }
31497
+ }
31498
+ const sep = this.#config.authorizationEndpoint.includes("?") ? "&" : "?";
31499
+ const url = `${this.#config.authorizationEndpoint}${sep}${params.toString()}`;
31500
+ return { url, state };
31501
+ }
31502
+ /**
31503
+ * Handle the redirect-callback URL. Validates `state`, retrieves the saved
31504
+ * verifier, exchanges the authorization code + verifier for tokens, and
31505
+ * persists them. Returns the access {@link TokenRecord}.
31506
+ */
31507
+ async handleCallback(callbackUrl) {
31508
+ const parsed = new URL(callbackUrl);
31509
+ const params = parsed.searchParams;
31510
+ const errorCode = params.get("error");
31511
+ if (errorCode !== null) {
31512
+ throw new Error(
31513
+ formatOAuthError({
31514
+ error: errorCode,
31515
+ error_description: params.get("error_description") ?? void 0
31516
+ })
31517
+ );
31518
+ }
31519
+ const code = params.get("code");
31520
+ const state = params.get("state");
31521
+ if (code === null || state === null) {
31522
+ throw new Error("OAuth callback is missing `code` or `state`");
31523
+ }
31524
+ const verifierRecord = await this.#config.tokenStore.get(
31525
+ this.#verifierKey(state)
31526
+ );
31527
+ if (verifierRecord === null) {
31528
+ throw new Error(
31529
+ "OAuth callback state does not match any in-flight verifier (possible CSRF or expired flow)"
31530
+ );
31531
+ }
31532
+ const body = new URLSearchParams();
31533
+ body.set("grant_type", "authorization_code");
31534
+ body.set("code", code);
31535
+ body.set("redirect_uri", this.#config.redirectUri);
31536
+ body.set("client_id", this.#config.clientId);
31537
+ body.set("code_verifier", verifierRecord.token);
31538
+ let tokens;
31539
+ try {
31540
+ tokens = await this.#tokenRequest(body);
31541
+ } finally {
31542
+ await this.#config.tokenStore.delete(this.#verifierKey(state));
31543
+ }
31544
+ return this.#persistTokens(tokens);
31545
+ }
31546
+ /**
31547
+ * Exchange a stored refresh token for a fresh access token. Throws if no
31548
+ * refresh token is available.
31549
+ */
31550
+ async refresh() {
31551
+ const refreshRecord = await this.#config.tokenStore.get(this.#refreshKey());
31552
+ if (refreshRecord === null) {
31553
+ throw new Error("OAuth refresh failed: no refresh token stored");
31554
+ }
31555
+ const body = new URLSearchParams();
31556
+ body.set("grant_type", "refresh_token");
31557
+ body.set("refresh_token", refreshRecord.token);
31558
+ body.set("client_id", this.#config.clientId);
31559
+ const tokens = await this.#tokenRequest(body);
31560
+ return this.#persistTokens(tokens, refreshRecord.token);
31561
+ }
31562
+ /**
31563
+ * Get the current access token if valid (refreshing first if expired and a
31564
+ * refresh token is available). Returns `null` when no usable token exists.
31565
+ */
31566
+ async getAccessToken() {
31567
+ const stored = await this.#config.tokenStore.get(this.#accessKey());
31568
+ if (stored !== null) return stored.token;
31569
+ const refresh = await this.#config.tokenStore.get(this.#refreshKey());
31570
+ if (refresh === null) return null;
31571
+ try {
31572
+ const refreshed = await this.refresh();
31573
+ return refreshed.token;
31574
+ } catch {
31575
+ return null;
31576
+ }
31577
+ }
31578
+ /** Forget tokens (logout). Does NOT call any remote revocation endpoint. */
31579
+ async signOut() {
31580
+ await this.#config.tokenStore.delete(this.#accessKey());
31581
+ await this.#config.tokenStore.delete(this.#refreshKey());
31582
+ }
31583
+ #accessKey() {
31584
+ return `oauth:tokens:${this.#config.clientId}`;
31585
+ }
31586
+ #refreshKey() {
31587
+ return `oauth:refresh:${this.#config.clientId}`;
31588
+ }
31589
+ #verifierKey(state) {
31590
+ return `oauth:verifier:${state}`;
31591
+ }
31592
+ async #tokenRequest(body) {
31593
+ const response = await this.#config.fetchImpl(this.#config.tokenEndpoint, {
31594
+ method: "POST",
31595
+ headers: {
31596
+ "Content-Type": "application/x-www-form-urlencoded",
31597
+ Accept: "application/json"
31598
+ },
31599
+ body: body.toString()
31600
+ });
31601
+ const text = await response.text();
31602
+ const parsed = parseJsonBody(text);
31603
+ if (!response.ok) {
31604
+ throw new Error(formatOAuthError(parsed ?? {}, response.status));
31605
+ }
31606
+ if (parsed === null || typeof parsed !== "object" || typeof parsed.access_token !== "string") {
31607
+ throw new Error(
31608
+ "OAuth token endpoint returned a response without an `access_token` string"
31609
+ );
31610
+ }
31611
+ return parsed;
31612
+ }
31613
+ async #persistTokens(tokens, previousRefreshToken) {
31614
+ const record = { token: tokens.access_token };
31615
+ if (typeof tokens.expires_in === "number" && tokens.expires_in > 0) {
31616
+ record.expiresAt = Math.floor(Date.now() / 1e3) + tokens.expires_in;
31617
+ }
31618
+ await this.#config.tokenStore.set(this.#accessKey(), record);
31619
+ const newRefresh = tokens.refresh_token ?? previousRefreshToken;
31620
+ if (newRefresh !== void 0) {
31621
+ await this.#config.tokenStore.set(this.#refreshKey(), {
31622
+ token: newRefresh
31623
+ });
31624
+ }
31625
+ return record;
31626
+ }
31627
+ };
31628
+ function defaultGenerateState() {
31629
+ const bytes = new Uint8Array(24);
31630
+ crypto.getRandomValues(bytes);
31631
+ let binary = "";
31632
+ for (let i = 0; i < bytes.length; i++) {
31633
+ binary += String.fromCharCode(bytes[i]);
31634
+ }
31635
+ return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
31636
+ }
31637
+ function parseJsonBody(text) {
31638
+ if (text.length === 0) return null;
31639
+ try {
31640
+ return JSON.parse(text);
31641
+ } catch {
31642
+ return null;
31643
+ }
31644
+ }
31645
+ function formatOAuthError(body, status) {
31646
+ const parts = ["OAuth token request failed"];
31647
+ if (status !== void 0) parts.push(`(HTTP ${String(status)})`);
31648
+ if (body.error !== void 0 && body.error.length > 0) {
31649
+ parts.push(`: ${body.error}`);
31650
+ if (body.error_description !== void 0 && body.error_description.length > 0) {
31651
+ parts.push(`- ${body.error_description}`);
31652
+ }
31653
+ }
31654
+ return parts.join(" ").replace(" : ", ": ").replace(" - ", " - ");
31655
+ }
31656
+
31435
31657
  // src/platform/utils.ts
31436
31658
  function detectPlatform() {
31437
31659
  if (typeof process !== "undefined" && process.versions && process.versions.node) {
@@ -31736,6 +31958,431 @@ var BUILDER_REGISTRATION_TYPES = {
31736
31958
  ]
31737
31959
  };
31738
31960
 
31961
+ // src/protocol/personal-server-registration.ts
31962
+ import {
31963
+ isAddress
31964
+ } from "viem";
31965
+ var PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID = 1480;
31966
+ var PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT = "0x1483B1F634DBA75AeaE60da7f01A679aabd5ee2c";
31967
+ function assertAddress(value, name) {
31968
+ if (!isAddress(value)) {
31969
+ throw new Error(`${name} must be a valid EVM address`);
31970
+ }
31971
+ }
31972
+ function getAccountAddress(account) {
31973
+ if (!account) {
31974
+ return void 0;
31975
+ }
31976
+ return typeof account === "string" ? account : account.address;
31977
+ }
31978
+ function isPersonalServerRegistrationSigner(source) {
31979
+ return "address" in source && typeof source.signTypedData === "function";
31980
+ }
31981
+ function createViemPersonalServerRegistrationSigner(source, options = {}) {
31982
+ if (isPersonalServerRegistrationSigner(source)) {
31983
+ return source;
31984
+ }
31985
+ const accountAddress = getAccountAddress(options.account) ?? getAccountAddress(source.account);
31986
+ if (accountAddress) {
31987
+ return {
31988
+ address: accountAddress,
31989
+ signTypedData: (typedData) => source.signTypedData({
31990
+ ...typedData,
31991
+ account: options.account ?? source.account ?? accountAddress
31992
+ })
31993
+ };
31994
+ }
31995
+ throw new Error(
31996
+ "Viem wallet client requires an account option or account property"
31997
+ );
31998
+ }
31999
+ function personalServerRegistrationDomain(input = {}) {
32000
+ if (input.config) {
32001
+ return serverRegistrationDomain(input.config);
32002
+ }
32003
+ const verifyingContract = input.verifyingContract ?? PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT;
32004
+ assertAddress(verifyingContract, "verifyingContract");
32005
+ return {
32006
+ name: "Vana Data Portability",
32007
+ version: "1",
32008
+ chainId: input.chainId ?? PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID,
32009
+ verifyingContract
32010
+ };
32011
+ }
32012
+ function buildPersonalServerRegistrationTypedData(input) {
32013
+ assertAddress(input.ownerAddress, "ownerAddress");
32014
+ assertAddress(input.serverAddress, "serverAddress");
32015
+ return {
32016
+ domain: personalServerRegistrationDomain(input),
32017
+ types: SERVER_REGISTRATION_TYPES,
32018
+ primaryType: "ServerRegistration",
32019
+ message: {
32020
+ ownerAddress: input.ownerAddress,
32021
+ serverAddress: input.serverAddress,
32022
+ publicKey: input.serverPublicKey,
32023
+ serverUrl: input.serverUrl
32024
+ }
32025
+ };
32026
+ }
32027
+ async function buildPersonalServerRegistrationSignature(input) {
32028
+ const typedData = buildPersonalServerRegistrationTypedData({
32029
+ ownerAddress: input.signer.address,
32030
+ serverAddress: input.serverAddress,
32031
+ serverPublicKey: input.serverPublicKey,
32032
+ serverUrl: input.serverUrl,
32033
+ config: input.config,
32034
+ chainId: input.chainId,
32035
+ verifyingContract: input.verifyingContract
32036
+ });
32037
+ const signature = await input.signer.signTypedData(typedData);
32038
+ return {
32039
+ signature,
32040
+ signerAddress: input.signer.address,
32041
+ typedData
32042
+ };
32043
+ }
32044
+ var registerPersonalServerSignature = buildPersonalServerRegistrationSignature;
32045
+
32046
+ // src/protocol/personal-server-lite-owner-binding.ts
32047
+ import {
32048
+ isAddress as isAddress2
32049
+ } from "viem";
32050
+ var PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION = "vana.account.v1";
32051
+ var PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE = "ps-lite-owner";
32052
+ var PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX = `${PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION}:${PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE}:`;
32053
+ function assertAddress2(value, name) {
32054
+ if (!isAddress2(value)) {
32055
+ throw new Error(`${name} must be a valid EVM address`);
32056
+ }
32057
+ }
32058
+ function getAccountAddress2(account) {
32059
+ if (!account) {
32060
+ return void 0;
32061
+ }
32062
+ return typeof account === "string" ? account : account.address;
32063
+ }
32064
+ function isPersonalServerLiteOwnerBindingSigner(source) {
32065
+ return "address" in source && typeof source.signMessage === "function";
32066
+ }
32067
+ function buildPersonalServerLiteOwnerBindingMessage(ownerAddress) {
32068
+ assertAddress2(ownerAddress, "ownerAddress");
32069
+ return `${PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX}${ownerAddress.toLowerCase()}`;
32070
+ }
32071
+ function createViemPersonalServerLiteOwnerBindingSigner(source, options = {}) {
32072
+ if (isPersonalServerLiteOwnerBindingSigner(source)) {
32073
+ return source;
32074
+ }
32075
+ const accountAddress = getAccountAddress2(options.account) ?? getAccountAddress2(source.account);
32076
+ if (accountAddress) {
32077
+ return {
32078
+ address: accountAddress,
32079
+ signMessage: ({ message }) => source.signMessage({
32080
+ account: options.account ?? source.account ?? accountAddress,
32081
+ message
32082
+ })
32083
+ };
32084
+ }
32085
+ throw new Error(
32086
+ "Viem wallet client requires an account option or account property"
32087
+ );
32088
+ }
32089
+ async function buildPersonalServerLiteOwnerBindingSignature(input) {
32090
+ const message = buildPersonalServerLiteOwnerBindingMessage(
32091
+ input.signer.address
32092
+ );
32093
+ const signature = await input.signer.signMessage({ message });
32094
+ return {
32095
+ signature,
32096
+ signerAddress: input.signer.address,
32097
+ message,
32098
+ purpose: PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE
32099
+ };
32100
+ }
32101
+ var signPersonalServerLiteOwnerBinding = buildPersonalServerLiteOwnerBindingSignature;
32102
+
32103
+ // src/account/personal-server-registration.ts
32104
+ import { isAddress as isAddress3 } from "viem";
32105
+ var ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT = "personal_server.server_registration.v1";
32106
+ var AccountPersonalServerRegistrationError = class extends Error {
32107
+ status;
32108
+ code;
32109
+ details;
32110
+ constructor(input) {
32111
+ super(input.message);
32112
+ this.name = "AccountPersonalServerRegistrationError";
32113
+ this.status = input.status;
32114
+ this.code = input.code;
32115
+ this.details = input.details;
32116
+ }
32117
+ };
32118
+ var DEFAULT_ACCOUNT_PS_REGISTRATION_PATH = "/api/v1/intents/personal-server-registration/sign";
32119
+ function trimTrailingSlash(value) {
32120
+ return value.replace(/\/+$/, "");
32121
+ }
32122
+ function assertAddress3(value, name) {
32123
+ if (!isAddress3(value)) {
32124
+ throw new Error(`${name} must be a valid EVM address`);
32125
+ }
32126
+ }
32127
+ async function parseAccountResponse(response) {
32128
+ const body = await response.json().catch(() => void 0);
32129
+ if (!response.ok) {
32130
+ throw new AccountPersonalServerRegistrationError({
32131
+ status: response.status,
32132
+ code: accountErrorCode(body),
32133
+ message: accountErrorMessage(response.status, body),
32134
+ details: body
32135
+ });
32136
+ }
32137
+ return body;
32138
+ }
32139
+ function accountErrorMessage(status, body) {
32140
+ const nestedMessage = nestedAccountErrorField(body, "message");
32141
+ if (nestedMessage) {
32142
+ return nestedMessage;
32143
+ }
32144
+ if (isRecord(body) && typeof body.message === "string") {
32145
+ return body.message;
32146
+ }
32147
+ const code = accountErrorCode(body);
32148
+ if (code) {
32149
+ return `Account PS registration signing failed: ${code}`;
32150
+ }
32151
+ return `Account PS registration signing failed: ${status}`;
32152
+ }
32153
+ function accountErrorCode(body) {
32154
+ const nestedCode = nestedAccountErrorField(body, "code");
32155
+ if (nestedCode) {
32156
+ return nestedCode;
32157
+ }
32158
+ if (isRecord(body)) {
32159
+ if (typeof body.code === "string") {
32160
+ return body.code;
32161
+ }
32162
+ if (typeof body.error === "string") {
32163
+ return body.error;
32164
+ }
32165
+ }
32166
+ return void 0;
32167
+ }
32168
+ function nestedAccountErrorField(body, field) {
32169
+ if (!isRecord(body) || !isRecord(body.error)) {
32170
+ return void 0;
32171
+ }
32172
+ const value = body.error[field];
32173
+ return typeof value === "string" ? value : void 0;
32174
+ }
32175
+ function isRecord(value) {
32176
+ return typeof value === "object" && value !== null;
32177
+ }
32178
+ function normalizeAccountResponse(response) {
32179
+ return {
32180
+ ...response,
32181
+ status: response.status === "fallback_required" ? "confirmation_required" : response.status,
32182
+ signerAddress: response.signerAddress ?? response.signer?.address,
32183
+ typedData: response.typedData ?? response.typed_data
32184
+ };
32185
+ }
32186
+ function buildSignedResult(response, request) {
32187
+ assertAddress3(response.signerAddress, "signerAddress");
32188
+ if (response.typedData) {
32189
+ assertTypedDataMatchesRequest(
32190
+ response.typedData,
32191
+ request,
32192
+ response.signerAddress
32193
+ );
32194
+ }
32195
+ return {
32196
+ signature: response.signature,
32197
+ signerAddress: response.signerAddress,
32198
+ typedData: response.typedData ?? buildPersonalServerRegistrationTypedData({
32199
+ ownerAddress: response.signerAddress,
32200
+ ...request
32201
+ }),
32202
+ intent: ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT
32203
+ };
32204
+ }
32205
+ function assertTypedDataMatchesRequest(typedData, request, expectedSignerAddress) {
32206
+ assertAddress3(
32207
+ typedData.message.ownerAddress,
32208
+ "typedData.message.ownerAddress"
32209
+ );
32210
+ assertAddress3(
32211
+ typedData.message.serverAddress,
32212
+ "typedData.message.serverAddress"
32213
+ );
32214
+ if (expectedSignerAddress && !sameAddress(typedData.message.ownerAddress, expectedSignerAddress)) {
32215
+ throw new Error(
32216
+ "Account typedData ownerAddress must match the expected signer address"
32217
+ );
32218
+ }
32219
+ if (!sameAddress(typedData.message.serverAddress, request.serverAddress)) {
32220
+ throw new Error(
32221
+ "Account typedData serverAddress must match the requested serverAddress"
32222
+ );
32223
+ }
32224
+ if (typedData.message.publicKey !== request.serverPublicKey) {
32225
+ throw new Error(
32226
+ "Account typedData publicKey must match the requested serverPublicKey"
32227
+ );
32228
+ }
32229
+ if (typedData.message.serverUrl !== request.serverUrl) {
32230
+ throw new Error(
32231
+ "Account typedData serverUrl must match the requested serverUrl"
32232
+ );
32233
+ }
32234
+ if (typedData.primaryType !== "ServerRegistration") {
32235
+ throw new Error("Account typedData primaryType must be ServerRegistration");
32236
+ }
32237
+ if (JSON.stringify(typedData.types) !== JSON.stringify(SERVER_REGISTRATION_TYPES)) {
32238
+ throw new Error("Account typedData types must be ServerRegistration types");
32239
+ }
32240
+ const expectedDomain = personalServerRegistrationDomain({
32241
+ config: request.config,
32242
+ chainId: request.chainId,
32243
+ verifyingContract: request.verifyingContract
32244
+ });
32245
+ if (!domainsEqual(typedData.domain, expectedDomain)) {
32246
+ throw new Error("Account typedData domain must match the requested domain");
32247
+ }
32248
+ }
32249
+ function sameAddress(a, b) {
32250
+ return a.toLowerCase() === b.toLowerCase();
32251
+ }
32252
+ function domainsEqual(a, b) {
32253
+ if (!a || !b) {
32254
+ return false;
32255
+ }
32256
+ 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;
32257
+ }
32258
+ async function signPersonalServerRegistrationWithAccount(config, request) {
32259
+ assertAddress3(request.serverAddress, "serverAddress");
32260
+ const fetchImpl = config.fetchImpl ?? globalThis.fetch.bind(globalThis);
32261
+ const endpoint = new URL(
32262
+ config.endpointPath ?? DEFAULT_ACCOUNT_PS_REGISTRATION_PATH,
32263
+ `${trimTrailingSlash(config.accountOrigin)}/`
32264
+ );
32265
+ const response = await fetchImpl(endpoint, {
32266
+ method: "POST",
32267
+ headers: { "content-type": "application/json" },
32268
+ credentials: "include",
32269
+ body: JSON.stringify({
32270
+ intent: ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT,
32271
+ serverAddress: request.serverAddress,
32272
+ serverPublicKey: request.serverPublicKey,
32273
+ serverUrl: request.serverUrl,
32274
+ config: request.config,
32275
+ chainId: request.chainId,
32276
+ verifyingContract: request.verifyingContract
32277
+ })
32278
+ });
32279
+ const body = normalizeAccountResponse(await parseAccountResponse(response));
32280
+ if (body.status === "signed") {
32281
+ if (!body.signature || !body.signerAddress) {
32282
+ throw new Error(
32283
+ "Account signed response must include signature and signerAddress"
32284
+ );
32285
+ }
32286
+ return {
32287
+ status: "signed",
32288
+ result: buildSignedResult(
32289
+ {
32290
+ signature: body.signature,
32291
+ signerAddress: body.signerAddress,
32292
+ typedData: body.typedData
32293
+ },
32294
+ request
32295
+ )
32296
+ };
32297
+ }
32298
+ if (body.status === "confirmation_required") {
32299
+ if (!body.typedData) {
32300
+ throw new Error(
32301
+ "Account confirmation_required response must include typedData"
32302
+ );
32303
+ }
32304
+ assertTypedDataMatchesRequest(body.typedData, request, body.signerAddress);
32305
+ if (!config.fallbackSigner) {
32306
+ return {
32307
+ status: "confirmation_required",
32308
+ typedData: body.typedData,
32309
+ signerAddress: body.signerAddress
32310
+ };
32311
+ }
32312
+ assertTypedDataMatchesRequest(
32313
+ body.typedData,
32314
+ request,
32315
+ config.fallbackSigner.address
32316
+ );
32317
+ const signature = await config.fallbackSigner.signTypedData(body.typedData);
32318
+ return {
32319
+ status: "fallback_signed",
32320
+ accountStatus: "confirmation_required",
32321
+ result: {
32322
+ signature,
32323
+ signerAddress: config.fallbackSigner.address,
32324
+ typedData: body.typedData,
32325
+ intent: ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT
32326
+ }
32327
+ };
32328
+ }
32329
+ throw new Error(
32330
+ `Unsupported Account PS registration signing status: ${String(body.status)}`
32331
+ );
32332
+ }
32333
+
32334
+ // src/account/personal-server-lite-owner-binding.ts
32335
+ var AccountPersonalServerLiteOwnerBindingError = class extends Error {
32336
+ code;
32337
+ details;
32338
+ constructor(input) {
32339
+ super(input.message);
32340
+ this.name = "AccountPersonalServerLiteOwnerBindingError";
32341
+ this.code = input.code;
32342
+ this.details = input.details;
32343
+ }
32344
+ };
32345
+ async function signPersonalServerLiteOwnerBindingWithAccountClient(config) {
32346
+ let address;
32347
+ try {
32348
+ address = await config.client.getAddress();
32349
+ } catch (error) {
32350
+ throw accountOwnerBindingError(error);
32351
+ }
32352
+ if (!address) {
32353
+ throw new AccountPersonalServerLiteOwnerBindingError({
32354
+ message: "Account did not return a wallet address",
32355
+ code: "account_address_required"
32356
+ });
32357
+ }
32358
+ const message = buildPersonalServerLiteOwnerBindingMessage(address);
32359
+ let signature;
32360
+ try {
32361
+ signature = await config.client.signMessage({ message });
32362
+ } catch (error) {
32363
+ throw accountOwnerBindingError(error);
32364
+ }
32365
+ return {
32366
+ signature,
32367
+ signerAddress: address,
32368
+ message,
32369
+ purpose: PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE
32370
+ };
32371
+ }
32372
+ function accountOwnerBindingError(error) {
32373
+ if (error instanceof AccountPersonalServerLiteOwnerBindingError) {
32374
+ return error;
32375
+ }
32376
+ const rpcError = error;
32377
+ const code = rpcError?.code;
32378
+ const message = typeof rpcError?.message === "string" && rpcError.message.length > 0 ? rpcError.message : "Account PS Lite owner-binding signature failed";
32379
+ return new AccountPersonalServerLiteOwnerBindingError({
32380
+ message,
32381
+ code,
32382
+ details: error
32383
+ });
32384
+ }
32385
+
31739
32386
  // src/protocol/grants.ts
31740
32387
  import { verifyTypedData } from "viem";
31741
32388
  function isHexString(value) {
@@ -32146,7 +32793,7 @@ var KNOWN_CODES = /* @__PURE__ */ new Set([
32146
32793
  "server_not_configured",
32147
32794
  "content_too_large"
32148
32795
  ]);
32149
- function isRecord(value) {
32796
+ function isRecord2(value) {
32150
32797
  return value !== null && typeof value === "object" && !Array.isArray(value);
32151
32798
  }
32152
32799
  function normalizeCode(value) {
@@ -32157,10 +32804,10 @@ function normalizeCode(value) {
32157
32804
  return KNOWN_CODES.has(code) ? code : null;
32158
32805
  }
32159
32806
  function extractPSErrorBody(body) {
32160
- if (!isRecord(body)) {
32807
+ if (!isRecord2(body)) {
32161
32808
  return null;
32162
32809
  }
32163
- const nested = isRecord(body.error) ? body.error : null;
32810
+ const nested = isRecord2(body.error) ? body.error : null;
32164
32811
  const code = normalizeCode(
32165
32812
  nested?.errorCode ?? nested?.code ?? body.errorCode ?? body.code
32166
32813
  );
@@ -32184,6 +32831,9 @@ async function parsePSError(response) {
32184
32831
  return errorBody ? new PSError(errorBody.code, errorBody.message) : null;
32185
32832
  }
32186
32833
  export {
32834
+ ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT,
32835
+ AccountPersonalServerLiteOwnerBindingError,
32836
+ AccountPersonalServerRegistrationError,
32187
32837
  BUILDER_REGISTRATION_TYPES,
32188
32838
  BlockchainError,
32189
32839
  BrowserECIESUint8Provider as BrowserECIESProvider,
@@ -32209,6 +32859,12 @@ export {
32209
32859
  MissingAuthError,
32210
32860
  NetworkError,
32211
32861
  NonceError,
32862
+ OAuthClient,
32863
+ PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX,
32864
+ PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE,
32865
+ PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION,
32866
+ PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID,
32867
+ PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT,
32212
32868
  PKCE_CHALLENGE_PATTERN,
32213
32869
  PKCE_VERIFIER_PATTERN,
32214
32870
  PSError,
@@ -32230,6 +32886,10 @@ export {
32230
32886
  VanaError,
32231
32887
  VanaStorage,
32232
32888
  assertValidPkceVerifier,
32889
+ buildPersonalServerLiteOwnerBindingMessage,
32890
+ buildPersonalServerLiteOwnerBindingSignature,
32891
+ buildPersonalServerRegistrationSignature,
32892
+ buildPersonalServerRegistrationTypedData,
32233
32893
  buildWeb3SignedHeader,
32234
32894
  builderRegistrationDomain,
32235
32895
  chains,
@@ -32242,6 +32902,8 @@ export {
32242
32902
  createGatewayClient,
32243
32903
  createPlatformAdapterSafe,
32244
32904
  createVanaStorageProvider,
32905
+ createViemPersonalServerLiteOwnerBindingSigner,
32906
+ createViemPersonalServerRegistrationSigner,
32245
32907
  decryptWithPassword,
32246
32908
  deriveMasterKey,
32247
32909
  deriveScopeKey,
@@ -32271,12 +32933,17 @@ export {
32271
32933
  parsePSError,
32272
32934
  parseScope,
32273
32935
  parseWeb3SignedHeader,
32936
+ personalServerRegistrationDomain,
32274
32937
  recoverServerOwner,
32938
+ registerPersonalServerSignature,
32275
32939
  scopeCoveredByGrant,
32276
32940
  scopeMatchesPattern,
32277
32941
  scopeToPathSegments,
32278
32942
  serializeECIES,
32279
32943
  serverRegistrationDomain,
32944
+ signPersonalServerLiteOwnerBinding,
32945
+ signPersonalServerLiteOwnerBindingWithAccountClient,
32946
+ signPersonalServerRegistrationWithAccount,
32280
32947
  vanaMainnet2 as vanaMainnet,
32281
32948
  verifyGrantRegistration,
32282
32949
  verifyPkceChallenge,