@opendatalabs/vana-sdk 3.0.0 → 3.0.1-pr.147.a4abdb1

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 (59) hide show
  1. package/dist/account/personal-server-lite-owner-binding.cjs +81 -0
  2. package/dist/account/personal-server-lite-owner-binding.cjs.map +1 -0
  3. package/dist/account/personal-server-lite-owner-binding.d.ts +30 -0
  4. package/dist/account/personal-server-lite-owner-binding.js +59 -0
  5. package/dist/account/personal-server-lite-owner-binding.js.map +1 -0
  6. package/dist/account/personal-server-lite-owner-binding.test.d.ts +1 -0
  7. package/dist/account/personal-server-registration.cjs +196 -0
  8. package/dist/account/personal-server-registration.cjs.map +1 -0
  9. package/dist/account/personal-server-registration.d.ts +66 -0
  10. package/dist/account/personal-server-registration.js +172 -0
  11. package/dist/account/personal-server-registration.js.map +1 -0
  12. package/dist/account/personal-server-registration.test.d.ts +1 -0
  13. package/dist/auth/web3-signed.cjs +28 -3
  14. package/dist/auth/web3-signed.cjs.map +1 -1
  15. package/dist/auth/web3-signed.js +28 -3
  16. package/dist/auth/web3-signed.js.map +1 -1
  17. package/dist/index.browser.d.ts +5 -0
  18. package/dist/index.browser.js +562 -16
  19. package/dist/index.browser.js.map +4 -4
  20. package/dist/index.node.cjs +580 -16
  21. package/dist/index.node.cjs.map +4 -4
  22. package/dist/index.node.d.ts +5 -0
  23. package/dist/index.node.js +562 -16
  24. package/dist/index.node.js.map +4 -4
  25. package/dist/protocol/eip712.cjs.map +1 -1
  26. package/dist/protocol/eip712.d.ts +1 -1
  27. package/dist/protocol/eip712.js.map +1 -1
  28. package/dist/protocol/grants.cjs +146 -0
  29. package/dist/protocol/grants.cjs.map +1 -0
  30. package/dist/protocol/grants.d.ts +31 -0
  31. package/dist/protocol/grants.js +123 -0
  32. package/dist/protocol/grants.js.map +1 -0
  33. package/dist/protocol/grants.test.d.ts +1 -0
  34. package/dist/protocol/personal-server-lite-owner-binding.cjs +93 -0
  35. package/dist/protocol/personal-server-lite-owner-binding.cjs.map +1 -0
  36. package/dist/protocol/personal-server-lite-owner-binding.d.ts +44 -0
  37. package/dist/protocol/personal-server-lite-owner-binding.js +65 -0
  38. package/dist/protocol/personal-server-lite-owner-binding.js.map +1 -0
  39. package/dist/protocol/personal-server-lite-owner-binding.test.d.ts +1 -0
  40. package/dist/protocol/personal-server-registration.cjs +122 -0
  41. package/dist/protocol/personal-server-registration.cjs.map +1 -0
  42. package/dist/protocol/personal-server-registration.d.ts +62 -0
  43. package/dist/protocol/personal-server-registration.js +97 -0
  44. package/dist/protocol/personal-server-registration.js.map +1 -0
  45. package/dist/protocol/personal-server-registration.test.d.ts +1 -0
  46. package/dist/storage/index.cjs.map +1 -1
  47. package/dist/storage/index.d.ts +1 -1
  48. package/dist/storage/index.js.map +1 -1
  49. package/dist/storage/providers/vana-storage.cjs +1 -1
  50. package/dist/storage/providers/vana-storage.cjs.map +1 -1
  51. package/dist/storage/providers/vana-storage.d.ts +2 -2
  52. package/dist/storage/providers/vana-storage.js +1 -1
  53. package/dist/storage/providers/vana-storage.js.map +1 -1
  54. package/dist/types/ps-errors.cjs +37 -12
  55. package/dist/types/ps-errors.cjs.map +1 -1
  56. package/dist/types/ps-errors.d.ts +7 -6
  57. package/dist/types/ps-errors.js +37 -12
  58. package/dist/types/ps-errors.js.map +1 -1
  59. package/package.json +1 -1
@@ -1173,6 +1173,9 @@ var init_browser2 = __esm({
1173
1173
  // src/index.node.ts
1174
1174
  var index_node_exports = {};
1175
1175
  __export(index_node_exports, {
1176
+ ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT: () => ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT,
1177
+ AccountPersonalServerLiteOwnerBindingError: () => AccountPersonalServerLiteOwnerBindingError,
1178
+ AccountPersonalServerRegistrationError: () => AccountPersonalServerRegistrationError,
1176
1179
  BUILDER_REGISTRATION_TYPES: () => BUILDER_REGISTRATION_TYPES,
1177
1180
  BlockchainError: () => BlockchainError,
1178
1181
  BrowserPlatformAdapter: () => BrowserPlatformAdapter,
@@ -1199,6 +1202,11 @@ __export(index_node_exports, {
1199
1202
  NodeECIESProvider: () => NodeECIESUint8Provider,
1200
1203
  NodePlatformAdapter: () => NodePlatformAdapter,
1201
1204
  NonceError: () => NonceError,
1205
+ PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX: () => PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX,
1206
+ PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE: () => PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE,
1207
+ PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION: () => PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION,
1208
+ PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID: () => PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID,
1209
+ PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT: () => PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT,
1202
1210
  PKCE_CHALLENGE_PATTERN: () => PKCE_CHALLENGE_PATTERN,
1203
1211
  PKCE_VERIFIER_PATTERN: () => PKCE_VERIFIER_PATTERN,
1204
1212
  PSError: () => PSError,
@@ -1220,6 +1228,10 @@ __export(index_node_exports, {
1220
1228
  VanaError: () => VanaError,
1221
1229
  VanaStorage: () => VanaStorage,
1222
1230
  assertValidPkceVerifier: () => assertValidPkceVerifier,
1231
+ buildPersonalServerLiteOwnerBindingMessage: () => buildPersonalServerLiteOwnerBindingMessage,
1232
+ buildPersonalServerLiteOwnerBindingSignature: () => buildPersonalServerLiteOwnerBindingSignature,
1233
+ buildPersonalServerRegistrationSignature: () => buildPersonalServerRegistrationSignature,
1234
+ buildPersonalServerRegistrationTypedData: () => buildPersonalServerRegistrationTypedData,
1223
1235
  buildWeb3SignedHeader: () => buildWeb3SignedHeader,
1224
1236
  builderRegistrationDomain: () => builderRegistrationDomain,
1225
1237
  chains: () => chains,
@@ -1235,6 +1247,8 @@ __export(index_node_exports, {
1235
1247
  createPlatformAdapterFor: () => createPlatformAdapterFor,
1236
1248
  createPlatformAdapterSafe: () => createPlatformAdapterSafe,
1237
1249
  createVanaStorageProvider: () => createVanaStorageProvider,
1250
+ createViemPersonalServerLiteOwnerBindingSigner: () => createViemPersonalServerLiteOwnerBindingSigner,
1251
+ createViemPersonalServerRegistrationSigner: () => createViemPersonalServerRegistrationSigner,
1238
1252
  decryptWithPassword: () => decryptWithPassword,
1239
1253
  deriveMasterKey: () => deriveMasterKey,
1240
1254
  deriveScopeKey: () => deriveScopeKey,
@@ -1253,22 +1267,30 @@ __export(index_node_exports, {
1253
1267
  getServiceEndpoints: () => getServiceEndpoints,
1254
1268
  grantRegistrationDomain: () => grantRegistrationDomain,
1255
1269
  grantRevocationDomain: () => grantRevocationDomain,
1270
+ isDataPortabilityGatewayConfig: () => isDataPortabilityGatewayConfig,
1256
1271
  isECIESEncrypted: () => isECIESEncrypted,
1257
1272
  isPlatformSupported: () => isPlatformSupported,
1258
1273
  mainnetServices: () => mainnetServices,
1259
1274
  moksha: () => moksha,
1260
1275
  mokshaServices: () => mokshaServices,
1261
1276
  mokshaTestnet: () => mokshaTestnet2,
1277
+ parseGrantRegistrationPayload: () => parseGrantRegistrationPayload,
1262
1278
  parsePSError: () => parsePSError,
1263
1279
  parseScope: () => parseScope,
1264
1280
  parseWeb3SignedHeader: () => parseWeb3SignedHeader,
1281
+ personalServerRegistrationDomain: () => personalServerRegistrationDomain,
1265
1282
  recoverServerOwner: () => recoverServerOwner,
1283
+ registerPersonalServerSignature: () => registerPersonalServerSignature,
1266
1284
  scopeCoveredByGrant: () => scopeCoveredByGrant,
1267
1285
  scopeMatchesPattern: () => scopeMatchesPattern,
1268
1286
  scopeToPathSegments: () => scopeToPathSegments,
1269
1287
  serializeECIES: () => serializeECIES,
1270
1288
  serverRegistrationDomain: () => serverRegistrationDomain,
1289
+ signPersonalServerLiteOwnerBinding: () => signPersonalServerLiteOwnerBinding,
1290
+ signPersonalServerLiteOwnerBindingWithAccountClient: () => signPersonalServerLiteOwnerBindingWithAccountClient,
1291
+ signPersonalServerRegistrationWithAccount: () => signPersonalServerRegistrationWithAccount,
1271
1292
  vanaMainnet: () => vanaMainnet2,
1293
+ verifyGrantRegistration: () => verifyGrantRegistration,
1272
1294
  verifyPkceChallenge: () => verifyPkceChallenge,
1273
1295
  verifyWeb3Signed: () => verifyWeb3Signed
1274
1296
  });
@@ -29136,7 +29158,7 @@ async function buildWeb3SignedHeader(params) {
29136
29158
  }
29137
29159
 
29138
29160
  // src/storage/providers/vana-storage.ts
29139
- var DEFAULT_ENDPOINT = "https://storage.vana.com";
29161
+ var DEFAULT_ENDPOINT = "https://storage.vana.org";
29140
29162
  var BLOB_PATH_PREFIX = "/v1/blobs";
29141
29163
  var DEFAULT_TOKEN_TTL_SECONDS = 300;
29142
29164
  var VanaStorage = class {
@@ -32193,6 +32215,30 @@ function base64urlDecode(input) {
32193
32215
  base64 += "=".repeat(padLength);
32194
32216
  return new TextDecoder().decode(fromBase64(base64));
32195
32217
  }
32218
+ function isFiniteNumber(value) {
32219
+ return typeof value === "number" && Number.isFinite(value);
32220
+ }
32221
+ function parsePayload(value) {
32222
+ if (value === null || typeof value !== "object" || Array.isArray(value)) {
32223
+ throw new InvalidSignatureError({ reason: "Invalid payload shape" });
32224
+ }
32225
+ const payload = value;
32226
+ if (typeof payload["aud"] !== "string" || typeof payload["method"] !== "string" || typeof payload["uri"] !== "string" || typeof payload["bodyHash"] !== "string" || !isFiniteNumber(payload["iat"]) || !isFiniteNumber(payload["exp"])) {
32227
+ throw new InvalidSignatureError({ reason: "Invalid payload claims" });
32228
+ }
32229
+ if (payload["grantId"] !== void 0 && typeof payload["grantId"] !== "string") {
32230
+ throw new InvalidSignatureError({ reason: "Invalid grantId claim" });
32231
+ }
32232
+ return {
32233
+ aud: payload["aud"],
32234
+ method: payload["method"],
32235
+ uri: payload["uri"],
32236
+ bodyHash: payload["bodyHash"],
32237
+ iat: payload["iat"],
32238
+ exp: payload["exp"],
32239
+ grantId: payload["grantId"]
32240
+ };
32241
+ }
32196
32242
  function parseWeb3SignedHeader(headerValue) {
32197
32243
  if (!headerValue) {
32198
32244
  throw new MissingAuthError();
@@ -32213,8 +32259,9 @@ function parseWeb3SignedHeader(headerValue) {
32213
32259
  let payload;
32214
32260
  try {
32215
32261
  const decoded = base64urlDecode(payloadBase64);
32216
- payload = JSON.parse(decoded);
32217
- } catch {
32262
+ payload = parsePayload(JSON.parse(decoded));
32263
+ } catch (err) {
32264
+ if (err instanceof InvalidSignatureError) throw err;
32218
32265
  throw new InvalidSignatureError({ reason: "Invalid payload encoding" });
32219
32266
  }
32220
32267
  return {
@@ -32257,7 +32304,7 @@ async function verifyWeb3Signed(params) {
32257
32304
  actual: payload.uri
32258
32305
  });
32259
32306
  }
32260
- if (params.bodyBytes !== void 0 && params.bodyBytes.length > 0) {
32307
+ if (params.bodyBytes !== void 0) {
32261
32308
  const expectedBodyHash = computeBodyHash(params.bodyBytes);
32262
32309
  if (payload.bodyHash !== expectedBodyHash) {
32263
32310
  throw new InvalidSignatureError({
@@ -32453,6 +32500,476 @@ var BUILDER_REGISTRATION_TYPES = {
32453
32500
  ]
32454
32501
  };
32455
32502
 
32503
+ // src/protocol/personal-server-registration.ts
32504
+ var import_viem14 = require("viem");
32505
+ var PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID = 1480;
32506
+ var PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT = "0x1483B1F634DBA75AeaE60da7f01A679aabd5ee2c";
32507
+ function assertAddress(value, name) {
32508
+ if (!(0, import_viem14.isAddress)(value)) {
32509
+ throw new Error(`${name} must be a valid EVM address`);
32510
+ }
32511
+ }
32512
+ function getAccountAddress(account) {
32513
+ if (!account) {
32514
+ return void 0;
32515
+ }
32516
+ return typeof account === "string" ? account : account.address;
32517
+ }
32518
+ function isPersonalServerRegistrationSigner(source) {
32519
+ return "address" in source && typeof source.signTypedData === "function";
32520
+ }
32521
+ function createViemPersonalServerRegistrationSigner(source, options = {}) {
32522
+ if (isPersonalServerRegistrationSigner(source)) {
32523
+ return source;
32524
+ }
32525
+ const accountAddress = getAccountAddress(options.account) ?? getAccountAddress(source.account);
32526
+ if (accountAddress) {
32527
+ return {
32528
+ address: accountAddress,
32529
+ signTypedData: (typedData) => source.signTypedData({
32530
+ ...typedData,
32531
+ account: options.account ?? source.account ?? accountAddress
32532
+ })
32533
+ };
32534
+ }
32535
+ throw new Error(
32536
+ "Viem wallet client requires an account option or account property"
32537
+ );
32538
+ }
32539
+ function personalServerRegistrationDomain(input = {}) {
32540
+ if (input.config) {
32541
+ return serverRegistrationDomain(input.config);
32542
+ }
32543
+ const verifyingContract = input.verifyingContract ?? PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT;
32544
+ assertAddress(verifyingContract, "verifyingContract");
32545
+ return {
32546
+ name: "Vana Data Portability",
32547
+ version: "1",
32548
+ chainId: input.chainId ?? PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID,
32549
+ verifyingContract
32550
+ };
32551
+ }
32552
+ function buildPersonalServerRegistrationTypedData(input) {
32553
+ assertAddress(input.ownerAddress, "ownerAddress");
32554
+ assertAddress(input.serverAddress, "serverAddress");
32555
+ return {
32556
+ domain: personalServerRegistrationDomain(input),
32557
+ types: SERVER_REGISTRATION_TYPES,
32558
+ primaryType: "ServerRegistration",
32559
+ message: {
32560
+ ownerAddress: input.ownerAddress,
32561
+ serverAddress: input.serverAddress,
32562
+ publicKey: input.serverPublicKey,
32563
+ serverUrl: input.serverUrl
32564
+ }
32565
+ };
32566
+ }
32567
+ async function buildPersonalServerRegistrationSignature(input) {
32568
+ const typedData = buildPersonalServerRegistrationTypedData({
32569
+ ownerAddress: input.signer.address,
32570
+ serverAddress: input.serverAddress,
32571
+ serverPublicKey: input.serverPublicKey,
32572
+ serverUrl: input.serverUrl,
32573
+ config: input.config,
32574
+ chainId: input.chainId,
32575
+ verifyingContract: input.verifyingContract
32576
+ });
32577
+ const signature = await input.signer.signTypedData(typedData);
32578
+ return {
32579
+ signature,
32580
+ signerAddress: input.signer.address,
32581
+ typedData
32582
+ };
32583
+ }
32584
+ var registerPersonalServerSignature = buildPersonalServerRegistrationSignature;
32585
+
32586
+ // src/protocol/personal-server-lite-owner-binding.ts
32587
+ var import_viem15 = require("viem");
32588
+ var PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION = "vana.account.v1";
32589
+ var PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE = "ps-lite-owner";
32590
+ var PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX = `${PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION}:${PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE}:`;
32591
+ function assertAddress2(value, name) {
32592
+ if (!(0, import_viem15.isAddress)(value)) {
32593
+ throw new Error(`${name} must be a valid EVM address`);
32594
+ }
32595
+ }
32596
+ function getAccountAddress2(account) {
32597
+ if (!account) {
32598
+ return void 0;
32599
+ }
32600
+ return typeof account === "string" ? account : account.address;
32601
+ }
32602
+ function isPersonalServerLiteOwnerBindingSigner(source) {
32603
+ return "address" in source && typeof source.signMessage === "function";
32604
+ }
32605
+ function buildPersonalServerLiteOwnerBindingMessage(ownerAddress) {
32606
+ assertAddress2(ownerAddress, "ownerAddress");
32607
+ return `${PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX}${ownerAddress.toLowerCase()}`;
32608
+ }
32609
+ function createViemPersonalServerLiteOwnerBindingSigner(source, options = {}) {
32610
+ if (isPersonalServerLiteOwnerBindingSigner(source)) {
32611
+ return source;
32612
+ }
32613
+ const accountAddress = getAccountAddress2(options.account) ?? getAccountAddress2(source.account);
32614
+ if (accountAddress) {
32615
+ return {
32616
+ address: accountAddress,
32617
+ signMessage: ({ message }) => source.signMessage({
32618
+ account: options.account ?? source.account ?? accountAddress,
32619
+ message
32620
+ })
32621
+ };
32622
+ }
32623
+ throw new Error(
32624
+ "Viem wallet client requires an account option or account property"
32625
+ );
32626
+ }
32627
+ async function buildPersonalServerLiteOwnerBindingSignature(input) {
32628
+ const message = buildPersonalServerLiteOwnerBindingMessage(
32629
+ input.signer.address
32630
+ );
32631
+ const signature = await input.signer.signMessage({ message });
32632
+ return {
32633
+ signature,
32634
+ signerAddress: input.signer.address,
32635
+ message,
32636
+ purpose: PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE
32637
+ };
32638
+ }
32639
+ var signPersonalServerLiteOwnerBinding = buildPersonalServerLiteOwnerBindingSignature;
32640
+
32641
+ // src/account/personal-server-registration.ts
32642
+ var import_viem16 = require("viem");
32643
+ var ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT = "personal_server.server_registration.v1";
32644
+ var AccountPersonalServerRegistrationError = class extends Error {
32645
+ status;
32646
+ code;
32647
+ details;
32648
+ constructor(input) {
32649
+ super(input.message);
32650
+ this.name = "AccountPersonalServerRegistrationError";
32651
+ this.status = input.status;
32652
+ this.code = input.code;
32653
+ this.details = input.details;
32654
+ }
32655
+ };
32656
+ var DEFAULT_ACCOUNT_PS_REGISTRATION_PATH = "/api/v1/intents/personal-server-registration/sign";
32657
+ function trimTrailingSlash(value) {
32658
+ return value.replace(/\/+$/, "");
32659
+ }
32660
+ function assertAddress3(value, name) {
32661
+ if (!(0, import_viem16.isAddress)(value)) {
32662
+ throw new Error(`${name} must be a valid EVM address`);
32663
+ }
32664
+ }
32665
+ async function parseAccountResponse(response) {
32666
+ const body = await response.json().catch(() => void 0);
32667
+ if (!response.ok) {
32668
+ throw new AccountPersonalServerRegistrationError({
32669
+ status: response.status,
32670
+ code: accountErrorCode(body),
32671
+ message: accountErrorMessage(response.status, body),
32672
+ details: body
32673
+ });
32674
+ }
32675
+ return body;
32676
+ }
32677
+ function accountErrorMessage(status, body) {
32678
+ const nestedMessage = nestedAccountErrorField(body, "message");
32679
+ if (nestedMessage) {
32680
+ return nestedMessage;
32681
+ }
32682
+ if (isRecord(body) && typeof body.message === "string") {
32683
+ return body.message;
32684
+ }
32685
+ const code = accountErrorCode(body);
32686
+ if (code) {
32687
+ return `Account PS registration signing failed: ${code}`;
32688
+ }
32689
+ return `Account PS registration signing failed: ${status}`;
32690
+ }
32691
+ function accountErrorCode(body) {
32692
+ const nestedCode = nestedAccountErrorField(body, "code");
32693
+ if (nestedCode) {
32694
+ return nestedCode;
32695
+ }
32696
+ if (isRecord(body)) {
32697
+ if (typeof body.code === "string") {
32698
+ return body.code;
32699
+ }
32700
+ if (typeof body.error === "string") {
32701
+ return body.error;
32702
+ }
32703
+ }
32704
+ return void 0;
32705
+ }
32706
+ function nestedAccountErrorField(body, field) {
32707
+ if (!isRecord(body) || !isRecord(body.error)) {
32708
+ return void 0;
32709
+ }
32710
+ const value = body.error[field];
32711
+ return typeof value === "string" ? value : void 0;
32712
+ }
32713
+ function isRecord(value) {
32714
+ return typeof value === "object" && value !== null;
32715
+ }
32716
+ function normalizeAccountResponse(response) {
32717
+ return {
32718
+ ...response,
32719
+ status: response.status === "fallback_required" ? "confirmation_required" : response.status,
32720
+ signerAddress: response.signerAddress ?? response.signer?.address,
32721
+ typedData: response.typedData ?? response.typed_data
32722
+ };
32723
+ }
32724
+ function buildSignedResult(response, request) {
32725
+ assertAddress3(response.signerAddress, "signerAddress");
32726
+ return {
32727
+ signature: response.signature,
32728
+ signerAddress: response.signerAddress,
32729
+ typedData: response.typedData ?? buildPersonalServerRegistrationTypedData({
32730
+ ownerAddress: response.signerAddress,
32731
+ ...request
32732
+ }),
32733
+ intent: ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT
32734
+ };
32735
+ }
32736
+ async function signPersonalServerRegistrationWithAccount(config, request) {
32737
+ assertAddress3(request.serverAddress, "serverAddress");
32738
+ const fetchImpl = config.fetchImpl ?? globalThis.fetch.bind(globalThis);
32739
+ const endpoint = new URL(
32740
+ config.endpointPath ?? DEFAULT_ACCOUNT_PS_REGISTRATION_PATH,
32741
+ `${trimTrailingSlash(config.accountOrigin)}/`
32742
+ );
32743
+ const response = await fetchImpl(endpoint, {
32744
+ method: "POST",
32745
+ headers: { "content-type": "application/json" },
32746
+ credentials: "include",
32747
+ body: JSON.stringify({
32748
+ intent: ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT,
32749
+ serverAddress: request.serverAddress,
32750
+ serverPublicKey: request.serverPublicKey,
32751
+ serverUrl: request.serverUrl,
32752
+ config: request.config,
32753
+ chainId: request.chainId,
32754
+ verifyingContract: request.verifyingContract
32755
+ })
32756
+ });
32757
+ const body = normalizeAccountResponse(await parseAccountResponse(response));
32758
+ if (body.status === "signed") {
32759
+ if (!body.signature || !body.signerAddress) {
32760
+ throw new Error(
32761
+ "Account signed response must include signature and signerAddress"
32762
+ );
32763
+ }
32764
+ return {
32765
+ status: "signed",
32766
+ result: buildSignedResult(
32767
+ {
32768
+ signature: body.signature,
32769
+ signerAddress: body.signerAddress,
32770
+ typedData: body.typedData
32771
+ },
32772
+ request
32773
+ )
32774
+ };
32775
+ }
32776
+ if (body.status === "confirmation_required") {
32777
+ if (!body.typedData) {
32778
+ throw new Error(
32779
+ "Account confirmation_required response must include typedData"
32780
+ );
32781
+ }
32782
+ if (!config.fallbackSigner) {
32783
+ return {
32784
+ status: "confirmation_required",
32785
+ typedData: body.typedData,
32786
+ signerAddress: body.signerAddress
32787
+ };
32788
+ }
32789
+ const signature = await config.fallbackSigner.signTypedData(body.typedData);
32790
+ return {
32791
+ status: "fallback_signed",
32792
+ accountStatus: "confirmation_required",
32793
+ result: {
32794
+ signature,
32795
+ signerAddress: config.fallbackSigner.address,
32796
+ typedData: body.typedData,
32797
+ intent: ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT
32798
+ }
32799
+ };
32800
+ }
32801
+ throw new Error(
32802
+ `Unsupported Account PS registration signing status: ${String(body.status)}`
32803
+ );
32804
+ }
32805
+
32806
+ // src/account/personal-server-lite-owner-binding.ts
32807
+ var AccountPersonalServerLiteOwnerBindingError = class extends Error {
32808
+ code;
32809
+ details;
32810
+ constructor(input) {
32811
+ super(input.message);
32812
+ this.name = "AccountPersonalServerLiteOwnerBindingError";
32813
+ this.code = input.code;
32814
+ this.details = input.details;
32815
+ }
32816
+ };
32817
+ async function signPersonalServerLiteOwnerBindingWithAccountClient(config) {
32818
+ let address;
32819
+ try {
32820
+ address = await config.client.getAddress();
32821
+ } catch (error) {
32822
+ throw accountOwnerBindingError(error);
32823
+ }
32824
+ if (!address) {
32825
+ throw new AccountPersonalServerLiteOwnerBindingError({
32826
+ message: "Account did not return a wallet address",
32827
+ code: "account_address_required"
32828
+ });
32829
+ }
32830
+ const message = buildPersonalServerLiteOwnerBindingMessage(address);
32831
+ let signature;
32832
+ try {
32833
+ signature = await config.client.signMessage({ message });
32834
+ } catch (error) {
32835
+ throw accountOwnerBindingError(error);
32836
+ }
32837
+ return {
32838
+ signature,
32839
+ signerAddress: address,
32840
+ message,
32841
+ purpose: PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE
32842
+ };
32843
+ }
32844
+ function accountOwnerBindingError(error) {
32845
+ if (error instanceof AccountPersonalServerLiteOwnerBindingError) {
32846
+ return error;
32847
+ }
32848
+ const rpcError = error;
32849
+ const code = rpcError?.code;
32850
+ const message = typeof rpcError?.message === "string" && rpcError.message.length > 0 ? rpcError.message : "Account PS Lite owner-binding signature failed";
32851
+ return new AccountPersonalServerLiteOwnerBindingError({
32852
+ message,
32853
+ code,
32854
+ details: error
32855
+ });
32856
+ }
32857
+
32858
+ // src/protocol/grants.ts
32859
+ var import_viem17 = require("viem");
32860
+ function isHexString(value) {
32861
+ return typeof value === "string" && value.startsWith("0x");
32862
+ }
32863
+ function isDataPortabilityGatewayConfig(value) {
32864
+ if (value === null || typeof value !== "object" || Array.isArray(value)) {
32865
+ return false;
32866
+ }
32867
+ const config = value;
32868
+ const contracts = config["contracts"];
32869
+ if (typeof config["chainId"] !== "number" || !Number.isInteger(config["chainId"]) || config["chainId"] <= 0 || contracts === null || typeof contracts !== "object" || Array.isArray(contracts)) {
32870
+ return false;
32871
+ }
32872
+ const c = contracts;
32873
+ return isHexString(c["dataRegistry"]) && isHexString(c["dataPortabilityPermissions"]) && isHexString(c["dataPortabilityServer"]) && isHexString(c["dataPortabilityGrantees"]);
32874
+ }
32875
+ function parseGrantRegistrationPayload(grant) {
32876
+ let parsed;
32877
+ try {
32878
+ parsed = JSON.parse(grant);
32879
+ } catch {
32880
+ return null;
32881
+ }
32882
+ if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
32883
+ return null;
32884
+ }
32885
+ const value = parsed;
32886
+ if (!Array.isArray(value["scopes"]) || value["scopes"].length === 0) {
32887
+ return null;
32888
+ }
32889
+ if (!value["scopes"].every((scope) => typeof scope === "string")) {
32890
+ return null;
32891
+ }
32892
+ if (typeof value["expiresAt"] !== "number" || !Number.isFinite(value["expiresAt"])) {
32893
+ return null;
32894
+ }
32895
+ if (value["user"] !== void 0 && !isHexString(value["user"])) {
32896
+ return null;
32897
+ }
32898
+ if (value["builder"] !== void 0 && !isHexString(value["builder"])) {
32899
+ return null;
32900
+ }
32901
+ if (value["nonce"] !== void 0 && (typeof value["nonce"] !== "number" || !Number.isFinite(value["nonce"]))) {
32902
+ return null;
32903
+ }
32904
+ return {
32905
+ user: value["user"],
32906
+ builder: value["builder"],
32907
+ scopes: value["scopes"],
32908
+ expiresAt: value["expiresAt"],
32909
+ nonce: value["nonce"]
32910
+ };
32911
+ }
32912
+ function parseFileIds(fileIds) {
32913
+ try {
32914
+ const values = (fileIds ?? []).map((fileId) => BigInt(fileId));
32915
+ return {
32916
+ values,
32917
+ display: values.map((fileId) => fileId.toString())
32918
+ };
32919
+ } catch {
32920
+ return null;
32921
+ }
32922
+ }
32923
+ async function verifyGrantRegistration(input) {
32924
+ const payload = parseGrantRegistrationPayload(input.grant);
32925
+ if (!payload) {
32926
+ return {
32927
+ valid: false,
32928
+ error: "Grant must be JSON with scopes and expiresAt"
32929
+ };
32930
+ }
32931
+ const fileIds = parseFileIds(input.fileIds);
32932
+ if (!fileIds) {
32933
+ return { valid: false, error: "fileIds must contain integer values" };
32934
+ }
32935
+ let valid;
32936
+ try {
32937
+ valid = await (0, import_viem17.verifyTypedData)({
32938
+ address: input.grantorAddress,
32939
+ domain: grantRegistrationDomain(input.gatewayConfig),
32940
+ types: GRANT_REGISTRATION_TYPES,
32941
+ primaryType: "GrantRegistration",
32942
+ message: {
32943
+ grantorAddress: input.grantorAddress,
32944
+ granteeId: input.granteeId,
32945
+ grant: input.grant,
32946
+ fileIds: fileIds.values
32947
+ },
32948
+ signature: input.signature
32949
+ });
32950
+ } catch {
32951
+ return { valid: false, error: "EIP-712 signature verification failed" };
32952
+ }
32953
+ if (!valid) {
32954
+ return { valid: false, error: "Grant signature does not match grantor" };
32955
+ }
32956
+ const nowSeconds = input.nowSeconds ?? Math.floor(Date.now() / 1e3);
32957
+ if (payload.expiresAt > 0 && payload.expiresAt < nowSeconds) {
32958
+ return { valid: false, error: "Grant has expired" };
32959
+ }
32960
+ if (payload.user !== void 0 && payload.user.toLowerCase() !== input.grantorAddress.toLowerCase()) {
32961
+ return { valid: false, error: "Grant user does not match grantorAddress" };
32962
+ }
32963
+ return {
32964
+ valid: true,
32965
+ grantorAddress: input.grantorAddress,
32966
+ granteeId: input.granteeId,
32967
+ grant: input.grant,
32968
+ payload,
32969
+ fileIds: fileIds.display
32970
+ };
32971
+ }
32972
+
32456
32973
  // src/protocol/scopes.ts
32457
32974
  var import_zod = require("zod");
32458
32975
  var SEGMENT_RE = /^[a-z0-9][a-z0-9_]*$/;
@@ -32733,35 +33250,63 @@ var PSError = class extends Error {
32733
33250
  code;
32734
33251
  };
32735
33252
  var KNOWN_CODES = /* @__PURE__ */ new Set([
33253
+ "missing_auth",
33254
+ "invalid_signature",
33255
+ "unregistered_builder",
33256
+ "not_owner",
33257
+ "expired_token",
32736
33258
  "grant_invalid",
33259
+ "grant_required",
33260
+ "grant_expired",
32737
33261
  "grant_revoked",
33262
+ "scope_mismatch",
32738
33263
  "fee_required",
32739
- "ps_unavailable"
33264
+ "ps_unavailable",
33265
+ "server_not_configured",
33266
+ "content_too_large"
32740
33267
  ]);
32741
- async function parsePSError(response) {
32742
- if (response.ok) {
33268
+ function isRecord2(value) {
33269
+ return value !== null && typeof value === "object" && !Array.isArray(value);
33270
+ }
33271
+ function normalizeCode(value) {
33272
+ if (typeof value !== "string") {
32743
33273
  return null;
32744
33274
  }
32745
- let body;
32746
- try {
32747
- body = await response.json();
32748
- } catch {
33275
+ const code = value.toLowerCase();
33276
+ return KNOWN_CODES.has(code) ? code : null;
33277
+ }
33278
+ function extractPSErrorBody(body) {
33279
+ if (!isRecord2(body)) {
32749
33280
  return null;
32750
33281
  }
32751
- if (typeof body !== "object" || body === null) {
33282
+ const nested = isRecord2(body.error) ? body.error : null;
33283
+ const code = normalizeCode(
33284
+ nested?.errorCode ?? nested?.code ?? body.errorCode ?? body.code
33285
+ );
33286
+ const message = nested?.message ?? body.message;
33287
+ if (!code || typeof message !== "string") {
32752
33288
  return null;
32753
33289
  }
32754
- const { code, message } = body;
32755
- if (typeof code !== "string" || typeof message !== "string") {
33290
+ return { code, message };
33291
+ }
33292
+ async function parsePSError(response) {
33293
+ if (response.ok) {
32756
33294
  return null;
32757
33295
  }
32758
- if (!KNOWN_CODES.has(code)) {
33296
+ let body;
33297
+ try {
33298
+ body = await response.json();
33299
+ } catch {
32759
33300
  return null;
32760
33301
  }
32761
- return new PSError(code, message);
33302
+ const errorBody = extractPSErrorBody(body);
33303
+ return errorBody ? new PSError(errorBody.code, errorBody.message) : null;
32762
33304
  }
32763
33305
  // Annotate the CommonJS export names for ESM import in node:
32764
33306
  0 && (module.exports = {
33307
+ ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT,
33308
+ AccountPersonalServerLiteOwnerBindingError,
33309
+ AccountPersonalServerRegistrationError,
32765
33310
  BUILDER_REGISTRATION_TYPES,
32766
33311
  BlockchainError,
32767
33312
  BrowserPlatformAdapter,
@@ -32788,6 +33333,11 @@ async function parsePSError(response) {
32788
33333
  NodeECIESProvider,
32789
33334
  NodePlatformAdapter,
32790
33335
  NonceError,
33336
+ PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX,
33337
+ PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE,
33338
+ PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION,
33339
+ PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID,
33340
+ PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT,
32791
33341
  PKCE_CHALLENGE_PATTERN,
32792
33342
  PKCE_VERIFIER_PATTERN,
32793
33343
  PSError,
@@ -32809,6 +33359,10 @@ async function parsePSError(response) {
32809
33359
  VanaError,
32810
33360
  VanaStorage,
32811
33361
  assertValidPkceVerifier,
33362
+ buildPersonalServerLiteOwnerBindingMessage,
33363
+ buildPersonalServerLiteOwnerBindingSignature,
33364
+ buildPersonalServerRegistrationSignature,
33365
+ buildPersonalServerRegistrationTypedData,
32812
33366
  buildWeb3SignedHeader,
32813
33367
  builderRegistrationDomain,
32814
33368
  chains,
@@ -32824,6 +33378,8 @@ async function parsePSError(response) {
32824
33378
  createPlatformAdapterFor,
32825
33379
  createPlatformAdapterSafe,
32826
33380
  createVanaStorageProvider,
33381
+ createViemPersonalServerLiteOwnerBindingSigner,
33382
+ createViemPersonalServerRegistrationSigner,
32827
33383
  decryptWithPassword,
32828
33384
  deriveMasterKey,
32829
33385
  deriveScopeKey,
@@ -32842,22 +33398,30 @@ async function parsePSError(response) {
32842
33398
  getServiceEndpoints,
32843
33399
  grantRegistrationDomain,
32844
33400
  grantRevocationDomain,
33401
+ isDataPortabilityGatewayConfig,
32845
33402
  isECIESEncrypted,
32846
33403
  isPlatformSupported,
32847
33404
  mainnetServices,
32848
33405
  moksha,
32849
33406
  mokshaServices,
32850
33407
  mokshaTestnet,
33408
+ parseGrantRegistrationPayload,
32851
33409
  parsePSError,
32852
33410
  parseScope,
32853
33411
  parseWeb3SignedHeader,
33412
+ personalServerRegistrationDomain,
32854
33413
  recoverServerOwner,
33414
+ registerPersonalServerSignature,
32855
33415
  scopeCoveredByGrant,
32856
33416
  scopeMatchesPattern,
32857
33417
  scopeToPathSegments,
32858
33418
  serializeECIES,
32859
33419
  serverRegistrationDomain,
33420
+ signPersonalServerLiteOwnerBinding,
33421
+ signPersonalServerLiteOwnerBindingWithAccountClient,
33422
+ signPersonalServerRegistrationWithAccount,
32860
33423
  vanaMainnet,
33424
+ verifyGrantRegistration,
32861
33425
  verifyPkceChallenge,
32862
33426
  verifyWeb3Signed
32863
33427
  });