@opendatalabs/vana-sdk 3.1.0 → 3.2.0-canary.a8087c5

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 (97) hide show
  1. package/README.md +2 -1
  2. package/dist/account/personal-server-lite-owner-binding.cjs +81 -0
  3. package/dist/account/personal-server-lite-owner-binding.cjs.map +1 -0
  4. package/dist/account/personal-server-lite-owner-binding.d.ts +30 -0
  5. package/dist/account/personal-server-lite-owner-binding.js +59 -0
  6. package/dist/account/personal-server-lite-owner-binding.js.map +1 -0
  7. package/dist/account/personal-server-lite-owner-binding.test.d.ts +1 -0
  8. package/dist/account/personal-server-registration.cjs +263 -0
  9. package/dist/account/personal-server-registration.cjs.map +1 -0
  10. package/dist/account/personal-server-registration.d.ts +66 -0
  11. package/dist/account/personal-server-registration.js +240 -0
  12. package/dist/account/personal-server-registration.js.map +1 -0
  13. package/dist/account/personal-server-registration.test.d.ts +1 -0
  14. package/dist/auth/errors.js +1 -1
  15. package/dist/auth/oauth-client.js +2 -2
  16. package/dist/auth/web3-signed-builder.js +1 -1
  17. package/dist/auth/web3-signed.js +3 -3
  18. package/dist/browser.js +1 -1
  19. package/dist/chains/definitions.js +1 -1
  20. package/dist/chains/index.js +1 -1
  21. package/dist/chains.browser.js +1 -1
  22. package/dist/chains.js +1 -1
  23. package/dist/chains.node.js +1 -1
  24. package/dist/contracts/contractController.js +4 -4
  25. package/dist/core/client.js +1 -1
  26. package/dist/crypto/ecies/base.js +3 -3
  27. package/dist/crypto/ecies/browser.js +1 -1
  28. package/dist/crypto/ecies/index.js +1 -1
  29. package/dist/crypto/ecies/interface.js +1 -1
  30. package/dist/crypto/ecies/node.js +1 -1
  31. package/dist/crypto/services/WalletKeyEncryptionService.js +1 -1
  32. package/dist/generated/abi/index.js +26 -26
  33. package/dist/index.browser.d.ts +8 -3
  34. package/dist/index.browser.js +706 -72
  35. package/dist/index.browser.js.map +4 -4
  36. package/dist/index.node.cjs +733 -73
  37. package/dist/index.node.cjs.map +4 -4
  38. package/dist/index.node.d.ts +8 -3
  39. package/dist/index.node.js +706 -72
  40. package/dist/index.node.js.map +4 -4
  41. package/dist/node.js +1 -1
  42. package/dist/platform/browser-only.js +1 -1
  43. package/dist/platform/browser-safe.js +1 -1
  44. package/dist/platform/browser.js +6 -6
  45. package/dist/platform/index.js +4 -4
  46. package/dist/platform/node.js +8 -8
  47. package/dist/platform/utils.js +2 -2
  48. package/dist/platform.browser.js +3 -3
  49. package/dist/platform.js +4 -4
  50. package/dist/platform.node.js +4 -4
  51. package/dist/protocol/eip712.cjs +58 -3
  52. package/dist/protocol/eip712.cjs.map +1 -1
  53. package/dist/protocol/eip712.d.ts +98 -7
  54. package/dist/protocol/eip712.js +52 -3
  55. package/dist/protocol/eip712.js.map +1 -1
  56. package/dist/protocol/escrow-deposit.cjs +89 -0
  57. package/dist/protocol/escrow-deposit.cjs.map +1 -0
  58. package/dist/protocol/escrow-deposit.d.ts +47 -0
  59. package/dist/protocol/escrow-deposit.js +60 -0
  60. package/dist/protocol/escrow-deposit.js.map +1 -0
  61. package/dist/protocol/escrow-deposit.test.d.ts +1 -0
  62. package/dist/protocol/escrow-flow.test.d.ts +21 -0
  63. package/dist/protocol/gateway.cjs +124 -3
  64. package/dist/protocol/gateway.cjs.map +1 -1
  65. package/dist/protocol/gateway.d.ts +196 -16
  66. package/dist/protocol/gateway.js +124 -3
  67. package/dist/protocol/gateway.js.map +1 -1
  68. package/dist/protocol/grants.cjs +24 -64
  69. package/dist/protocol/grants.cjs.map +1 -1
  70. package/dist/protocol/grants.d.ts +6 -13
  71. package/dist/protocol/grants.js +25 -64
  72. package/dist/protocol/grants.js.map +1 -1
  73. package/dist/protocol/personal-server-lite-owner-binding.cjs +93 -0
  74. package/dist/protocol/personal-server-lite-owner-binding.cjs.map +1 -0
  75. package/dist/protocol/personal-server-lite-owner-binding.d.ts +44 -0
  76. package/dist/protocol/personal-server-lite-owner-binding.js +65 -0
  77. package/dist/protocol/personal-server-lite-owner-binding.js.map +1 -0
  78. package/dist/protocol/personal-server-lite-owner-binding.test.d.ts +1 -0
  79. package/dist/protocol/personal-server-registration.cjs +122 -0
  80. package/dist/protocol/personal-server-registration.cjs.map +1 -0
  81. package/dist/protocol/personal-server-registration.d.ts +62 -0
  82. package/dist/protocol/personal-server-registration.js +97 -0
  83. package/dist/protocol/personal-server-registration.js.map +1 -0
  84. package/dist/protocol/personal-server-registration.test.d.ts +1 -0
  85. package/dist/storage/default.js +1 -1
  86. package/dist/storage/index.js +10 -10
  87. package/dist/storage/manager.js +1 -1
  88. package/dist/storage/providers/callback-storage.js +1 -1
  89. package/dist/storage/providers/dropbox.js +1 -1
  90. package/dist/storage/providers/google-drive.js +1 -1
  91. package/dist/storage/providers/ipfs.js +2 -2
  92. package/dist/storage/providers/pinata.js +1 -1
  93. package/dist/storage/providers/r2.js +1 -1
  94. package/dist/storage/providers/vana-storage.js +2 -2
  95. package/dist/types/index.js +2 -2
  96. package/dist/types.js +1 -1
  97. package/package.json +6 -3
@@ -31882,6 +31882,7 @@ async function verifyWeb3Signed(params) {
31882
31882
  // src/protocol/eip712.ts
31883
31883
  var DOMAIN_NAME = "Vana Data Portability";
31884
31884
  var DOMAIN_VERSION = "1";
31885
+ var NATIVE_VANA_ASSET = "0x0000000000000000000000000000000000000000";
31885
31886
  function buildDomain(chainId, verifyingContract) {
31886
31887
  return {
31887
31888
  name: DOMAIN_NAME,
@@ -31896,6 +31897,12 @@ function fileRegistrationDomain(config) {
31896
31897
  config.contracts.dataRegistry
31897
31898
  );
31898
31899
  }
31900
+ function dataRegistryDomain(config) {
31901
+ return buildDomain(
31902
+ config.chainId,
31903
+ config.contracts.dataRegistry
31904
+ );
31905
+ }
31899
31906
  function grantRegistrationDomain(config) {
31900
31907
  return buildDomain(
31901
31908
  config.chainId,
@@ -31920,6 +31927,12 @@ function builderRegistrationDomain(config) {
31920
31927
  config.contracts.dataPortabilityGrantees
31921
31928
  );
31922
31929
  }
31930
+ function escrowPaymentDomain(config) {
31931
+ return buildDomain(
31932
+ config.chainId,
31933
+ config.contracts.dataPortabilityEscrow
31934
+ );
31935
+ }
31923
31936
  var FILE_REGISTRATION_TYPES = {
31924
31937
  FileRegistration: [
31925
31938
  { name: "ownerAddress", type: "address" },
@@ -31931,14 +31944,16 @@ var GRANT_REGISTRATION_TYPES = {
31931
31944
  GrantRegistration: [
31932
31945
  { name: "grantorAddress", type: "address" },
31933
31946
  { name: "granteeId", type: "bytes32" },
31934
- { name: "grant", type: "string" },
31935
- { name: "fileIds", type: "uint256[]" }
31947
+ { name: "scopes", type: "string[]" },
31948
+ { name: "grantVersion", type: "uint256" },
31949
+ { name: "expiresAt", type: "uint256" }
31936
31950
  ]
31937
31951
  };
31938
31952
  var GRANT_REVOCATION_TYPES = {
31939
31953
  GrantRevocation: [
31940
31954
  { name: "grantorAddress", type: "address" },
31941
- { name: "grantId", type: "bytes32" }
31955
+ { name: "grantId", type: "bytes32" },
31956
+ { name: "grantVersion", type: "uint256" }
31942
31957
  ]
31943
31958
  };
31944
31959
  var SERVER_REGISTRATION_TYPES = {
@@ -31957,83 +31972,500 @@ var BUILDER_REGISTRATION_TYPES = {
31957
31972
  { name: "appUrl", type: "string" }
31958
31973
  ]
31959
31974
  };
31975
+ var GENERIC_PAYMENT_TYPES = {
31976
+ GenericPayment: [
31977
+ { name: "payerAddress", type: "address" },
31978
+ { name: "opType", type: "string" },
31979
+ { name: "opId", type: "bytes32" },
31980
+ { name: "asset", type: "address" },
31981
+ { name: "amount", type: "uint256" },
31982
+ { name: "paymentNonce", type: "uint256" }
31983
+ ]
31984
+ };
31985
+ var ADD_DATA_TYPES = {
31986
+ AddData: [
31987
+ { name: "ownerAddress", type: "address" },
31988
+ { name: "scope", type: "string" },
31989
+ { name: "dataHash", type: "bytes32" },
31990
+ { name: "metadataHash", type: "bytes32" },
31991
+ { name: "expectedVersion", type: "uint256" }
31992
+ ]
31993
+ };
31994
+ var RECORD_DATA_ACCESS_TYPES = {
31995
+ RecordDataAccess: [
31996
+ { name: "ownerAddress", type: "address" },
31997
+ { name: "scope", type: "string" },
31998
+ { name: "version", type: "uint256" },
31999
+ { name: "accessor", type: "address" },
32000
+ { name: "recordId", type: "bytes32" }
32001
+ ]
32002
+ };
31960
32003
 
31961
- // src/protocol/grants.ts
31962
- import { verifyTypedData } from "viem";
31963
- function isHexString(value) {
31964
- return typeof value === "string" && value.startsWith("0x");
32004
+ // src/protocol/personal-server-registration.ts
32005
+ import {
32006
+ isAddress
32007
+ } from "viem";
32008
+ var PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID = 1480;
32009
+ var PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT = "0x1483B1F634DBA75AeaE60da7f01A679aabd5ee2c";
32010
+ function assertAddress(value, name) {
32011
+ if (!isAddress(value)) {
32012
+ throw new Error(`${name} must be a valid EVM address`);
32013
+ }
31965
32014
  }
31966
- function isDataPortabilityGatewayConfig(value) {
31967
- if (value === null || typeof value !== "object" || Array.isArray(value)) {
31968
- return false;
32015
+ function getAccountAddress(account) {
32016
+ if (!account) {
32017
+ return void 0;
31969
32018
  }
31970
- const config = value;
31971
- const contracts = config["contracts"];
31972
- if (typeof config["chainId"] !== "number" || !Number.isInteger(config["chainId"]) || config["chainId"] <= 0 || contracts === null || typeof contracts !== "object" || Array.isArray(contracts)) {
31973
- return false;
32019
+ return typeof account === "string" ? account : account.address;
32020
+ }
32021
+ function isPersonalServerRegistrationSigner(source) {
32022
+ return "address" in source && typeof source.signTypedData === "function";
32023
+ }
32024
+ function createViemPersonalServerRegistrationSigner(source, options = {}) {
32025
+ if (isPersonalServerRegistrationSigner(source)) {
32026
+ return source;
31974
32027
  }
31975
- const c = contracts;
31976
- return isHexString(c["dataRegistry"]) && isHexString(c["dataPortabilityPermissions"]) && isHexString(c["dataPortabilityServer"]) && isHexString(c["dataPortabilityGrantees"]);
32028
+ const accountAddress = getAccountAddress(options.account) ?? getAccountAddress(source.account);
32029
+ if (accountAddress) {
32030
+ return {
32031
+ address: accountAddress,
32032
+ signTypedData: (typedData) => source.signTypedData({
32033
+ ...typedData,
32034
+ account: options.account ?? source.account ?? accountAddress
32035
+ })
32036
+ };
32037
+ }
32038
+ throw new Error(
32039
+ "Viem wallet client requires an account option or account property"
32040
+ );
31977
32041
  }
31978
- function parseGrantRegistrationPayload(grant) {
31979
- let parsed;
31980
- try {
31981
- parsed = JSON.parse(grant);
31982
- } catch {
31983
- return null;
32042
+ function personalServerRegistrationDomain(input = {}) {
32043
+ if (input.config) {
32044
+ return serverRegistrationDomain(input.config);
31984
32045
  }
31985
- if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
31986
- return null;
32046
+ const verifyingContract = input.verifyingContract ?? PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT;
32047
+ assertAddress(verifyingContract, "verifyingContract");
32048
+ return {
32049
+ name: "Vana Data Portability",
32050
+ version: "1",
32051
+ chainId: input.chainId ?? PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID,
32052
+ verifyingContract
32053
+ };
32054
+ }
32055
+ function buildPersonalServerRegistrationTypedData(input) {
32056
+ assertAddress(input.ownerAddress, "ownerAddress");
32057
+ assertAddress(input.serverAddress, "serverAddress");
32058
+ return {
32059
+ domain: personalServerRegistrationDomain(input),
32060
+ types: SERVER_REGISTRATION_TYPES,
32061
+ primaryType: "ServerRegistration",
32062
+ message: {
32063
+ ownerAddress: input.ownerAddress,
32064
+ serverAddress: input.serverAddress,
32065
+ publicKey: input.serverPublicKey,
32066
+ serverUrl: input.serverUrl
32067
+ }
32068
+ };
32069
+ }
32070
+ async function buildPersonalServerRegistrationSignature(input) {
32071
+ const typedData = buildPersonalServerRegistrationTypedData({
32072
+ ownerAddress: input.signer.address,
32073
+ serverAddress: input.serverAddress,
32074
+ serverPublicKey: input.serverPublicKey,
32075
+ serverUrl: input.serverUrl,
32076
+ config: input.config,
32077
+ chainId: input.chainId,
32078
+ verifyingContract: input.verifyingContract
32079
+ });
32080
+ const signature = await input.signer.signTypedData(typedData);
32081
+ return {
32082
+ signature,
32083
+ signerAddress: input.signer.address,
32084
+ typedData
32085
+ };
32086
+ }
32087
+ var registerPersonalServerSignature = buildPersonalServerRegistrationSignature;
32088
+
32089
+ // src/protocol/personal-server-lite-owner-binding.ts
32090
+ import {
32091
+ isAddress as isAddress2
32092
+ } from "viem";
32093
+ var PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION = "vana.account.v1";
32094
+ var PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE = "ps-lite-owner";
32095
+ var PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX = `${PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION}:${PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE}:`;
32096
+ function assertAddress2(value, name) {
32097
+ if (!isAddress2(value)) {
32098
+ throw new Error(`${name} must be a valid EVM address`);
31987
32099
  }
31988
- const value = parsed;
31989
- if (!Array.isArray(value["scopes"]) || value["scopes"].length === 0) {
31990
- return null;
32100
+ }
32101
+ function getAccountAddress2(account) {
32102
+ if (!account) {
32103
+ return void 0;
31991
32104
  }
31992
- if (!value["scopes"].every((scope) => typeof scope === "string")) {
31993
- return null;
32105
+ return typeof account === "string" ? account : account.address;
32106
+ }
32107
+ function isPersonalServerLiteOwnerBindingSigner(source) {
32108
+ return "address" in source && typeof source.signMessage === "function";
32109
+ }
32110
+ function buildPersonalServerLiteOwnerBindingMessage(ownerAddress) {
32111
+ assertAddress2(ownerAddress, "ownerAddress");
32112
+ return `${PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX}${ownerAddress.toLowerCase()}`;
32113
+ }
32114
+ function createViemPersonalServerLiteOwnerBindingSigner(source, options = {}) {
32115
+ if (isPersonalServerLiteOwnerBindingSigner(source)) {
32116
+ return source;
31994
32117
  }
31995
- if (typeof value["expiresAt"] !== "number" || !Number.isFinite(value["expiresAt"])) {
31996
- return null;
32118
+ const accountAddress = getAccountAddress2(options.account) ?? getAccountAddress2(source.account);
32119
+ if (accountAddress) {
32120
+ return {
32121
+ address: accountAddress,
32122
+ signMessage: ({ message }) => source.signMessage({
32123
+ account: options.account ?? source.account ?? accountAddress,
32124
+ message
32125
+ })
32126
+ };
31997
32127
  }
31998
- if (value["user"] !== void 0 && !isHexString(value["user"])) {
31999
- return null;
32128
+ throw new Error(
32129
+ "Viem wallet client requires an account option or account property"
32130
+ );
32131
+ }
32132
+ async function buildPersonalServerLiteOwnerBindingSignature(input) {
32133
+ const message = buildPersonalServerLiteOwnerBindingMessage(
32134
+ input.signer.address
32135
+ );
32136
+ const signature = await input.signer.signMessage({ message });
32137
+ return {
32138
+ signature,
32139
+ signerAddress: input.signer.address,
32140
+ message,
32141
+ purpose: PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE
32142
+ };
32143
+ }
32144
+ var signPersonalServerLiteOwnerBinding = buildPersonalServerLiteOwnerBindingSignature;
32145
+
32146
+ // src/account/personal-server-registration.ts
32147
+ import { isAddress as isAddress3 } from "viem";
32148
+ var ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT = "personal_server.server_registration.v1";
32149
+ var AccountPersonalServerRegistrationError = class extends Error {
32150
+ status;
32151
+ code;
32152
+ details;
32153
+ constructor(input) {
32154
+ super(input.message);
32155
+ this.name = "AccountPersonalServerRegistrationError";
32156
+ this.status = input.status;
32157
+ this.code = input.code;
32158
+ this.details = input.details;
32000
32159
  }
32001
- if (value["builder"] !== void 0 && !isHexString(value["builder"])) {
32002
- return null;
32160
+ };
32161
+ var DEFAULT_ACCOUNT_PS_REGISTRATION_PATH = "/api/v1/intents/personal-server-registration/sign";
32162
+ function trimTrailingSlash(value) {
32163
+ return value.replace(/\/+$/, "");
32164
+ }
32165
+ function assertAddress3(value, name) {
32166
+ if (!isAddress3(value)) {
32167
+ throw new Error(`${name} must be a valid EVM address`);
32003
32168
  }
32004
- if (value["nonce"] !== void 0 && (typeof value["nonce"] !== "number" || !Number.isFinite(value["nonce"]))) {
32005
- return null;
32169
+ }
32170
+ async function parseAccountResponse(response) {
32171
+ const body = await response.json().catch(() => void 0);
32172
+ if (!response.ok) {
32173
+ throw new AccountPersonalServerRegistrationError({
32174
+ status: response.status,
32175
+ code: accountErrorCode(body),
32176
+ message: accountErrorMessage(response.status, body),
32177
+ details: body
32178
+ });
32179
+ }
32180
+ return body;
32181
+ }
32182
+ function accountErrorMessage(status, body) {
32183
+ const nestedMessage = nestedAccountErrorField(body, "message");
32184
+ if (nestedMessage) {
32185
+ return nestedMessage;
32186
+ }
32187
+ if (isRecord(body) && typeof body.message === "string") {
32188
+ return body.message;
32189
+ }
32190
+ const code = accountErrorCode(body);
32191
+ if (code) {
32192
+ return `Account PS registration signing failed: ${code}`;
32193
+ }
32194
+ return `Account PS registration signing failed: ${status}`;
32195
+ }
32196
+ function accountErrorCode(body) {
32197
+ const nestedCode = nestedAccountErrorField(body, "code");
32198
+ if (nestedCode) {
32199
+ return nestedCode;
32006
32200
  }
32201
+ if (isRecord(body)) {
32202
+ if (typeof body.code === "string") {
32203
+ return body.code;
32204
+ }
32205
+ if (typeof body.error === "string") {
32206
+ return body.error;
32207
+ }
32208
+ }
32209
+ return void 0;
32210
+ }
32211
+ function nestedAccountErrorField(body, field) {
32212
+ if (!isRecord(body) || !isRecord(body.error)) {
32213
+ return void 0;
32214
+ }
32215
+ const value = body.error[field];
32216
+ return typeof value === "string" ? value : void 0;
32217
+ }
32218
+ function isRecord(value) {
32219
+ return typeof value === "object" && value !== null;
32220
+ }
32221
+ function normalizeAccountResponse(response) {
32007
32222
  return {
32008
- user: value["user"],
32009
- builder: value["builder"],
32010
- scopes: value["scopes"],
32011
- expiresAt: value["expiresAt"],
32012
- nonce: value["nonce"]
32223
+ ...response,
32224
+ status: response.status === "fallback_required" ? "confirmation_required" : response.status,
32225
+ signerAddress: response.signerAddress ?? response.signer?.address,
32226
+ typedData: response.typedData ?? response.typed_data
32013
32227
  };
32014
32228
  }
32015
- function parseFileIds(fileIds) {
32016
- try {
32017
- const values = (fileIds ?? []).map((fileId) => BigInt(fileId));
32229
+ function buildSignedResult(response, request) {
32230
+ assertAddress3(response.signerAddress, "signerAddress");
32231
+ if (response.typedData) {
32232
+ assertTypedDataMatchesRequest(
32233
+ response.typedData,
32234
+ request,
32235
+ response.signerAddress
32236
+ );
32237
+ }
32238
+ return {
32239
+ signature: response.signature,
32240
+ signerAddress: response.signerAddress,
32241
+ typedData: response.typedData ?? buildPersonalServerRegistrationTypedData({
32242
+ ownerAddress: response.signerAddress,
32243
+ ...request
32244
+ }),
32245
+ intent: ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT
32246
+ };
32247
+ }
32248
+ function assertTypedDataMatchesRequest(typedData, request, expectedSignerAddress) {
32249
+ assertAddress3(
32250
+ typedData.message.ownerAddress,
32251
+ "typedData.message.ownerAddress"
32252
+ );
32253
+ assertAddress3(
32254
+ typedData.message.serverAddress,
32255
+ "typedData.message.serverAddress"
32256
+ );
32257
+ if (expectedSignerAddress && !sameAddress(typedData.message.ownerAddress, expectedSignerAddress)) {
32258
+ throw new Error(
32259
+ "Account typedData ownerAddress must match the expected signer address"
32260
+ );
32261
+ }
32262
+ if (!sameAddress(typedData.message.serverAddress, request.serverAddress)) {
32263
+ throw new Error(
32264
+ "Account typedData serverAddress must match the requested serverAddress"
32265
+ );
32266
+ }
32267
+ if (typedData.message.publicKey !== request.serverPublicKey) {
32268
+ throw new Error(
32269
+ "Account typedData publicKey must match the requested serverPublicKey"
32270
+ );
32271
+ }
32272
+ if (typedData.message.serverUrl !== request.serverUrl) {
32273
+ throw new Error(
32274
+ "Account typedData serverUrl must match the requested serverUrl"
32275
+ );
32276
+ }
32277
+ if (typedData.primaryType !== "ServerRegistration") {
32278
+ throw new Error("Account typedData primaryType must be ServerRegistration");
32279
+ }
32280
+ if (JSON.stringify(typedData.types) !== JSON.stringify(SERVER_REGISTRATION_TYPES)) {
32281
+ throw new Error("Account typedData types must be ServerRegistration types");
32282
+ }
32283
+ const expectedDomain = personalServerRegistrationDomain({
32284
+ config: request.config,
32285
+ chainId: request.chainId,
32286
+ verifyingContract: request.verifyingContract
32287
+ });
32288
+ if (!domainsEqual(typedData.domain, expectedDomain)) {
32289
+ throw new Error("Account typedData domain must match the requested domain");
32290
+ }
32291
+ }
32292
+ function sameAddress(a, b) {
32293
+ return a.toLowerCase() === b.toLowerCase();
32294
+ }
32295
+ function domainsEqual(a, b) {
32296
+ if (!a || !b) {
32297
+ return false;
32298
+ }
32299
+ 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;
32300
+ }
32301
+ async function signPersonalServerRegistrationWithAccount(config, request) {
32302
+ assertAddress3(request.serverAddress, "serverAddress");
32303
+ const fetchImpl = config.fetchImpl ?? globalThis.fetch.bind(globalThis);
32304
+ const endpoint = new URL(
32305
+ config.endpointPath ?? DEFAULT_ACCOUNT_PS_REGISTRATION_PATH,
32306
+ `${trimTrailingSlash(config.accountOrigin)}/`
32307
+ );
32308
+ const response = await fetchImpl(endpoint, {
32309
+ method: "POST",
32310
+ headers: { "content-type": "application/json" },
32311
+ credentials: "include",
32312
+ body: JSON.stringify({
32313
+ intent: ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT,
32314
+ serverAddress: request.serverAddress,
32315
+ serverPublicKey: request.serverPublicKey,
32316
+ serverUrl: request.serverUrl,
32317
+ config: request.config,
32318
+ chainId: request.chainId,
32319
+ verifyingContract: request.verifyingContract
32320
+ })
32321
+ });
32322
+ const body = normalizeAccountResponse(await parseAccountResponse(response));
32323
+ if (body.status === "signed") {
32324
+ if (!body.signature || !body.signerAddress) {
32325
+ throw new Error(
32326
+ "Account signed response must include signature and signerAddress"
32327
+ );
32328
+ }
32329
+ return {
32330
+ status: "signed",
32331
+ result: buildSignedResult(
32332
+ {
32333
+ signature: body.signature,
32334
+ signerAddress: body.signerAddress,
32335
+ typedData: body.typedData
32336
+ },
32337
+ request
32338
+ )
32339
+ };
32340
+ }
32341
+ if (body.status === "confirmation_required") {
32342
+ if (!body.typedData) {
32343
+ throw new Error(
32344
+ "Account confirmation_required response must include typedData"
32345
+ );
32346
+ }
32347
+ assertTypedDataMatchesRequest(body.typedData, request, body.signerAddress);
32348
+ if (!config.fallbackSigner) {
32349
+ return {
32350
+ status: "confirmation_required",
32351
+ typedData: body.typedData,
32352
+ signerAddress: body.signerAddress
32353
+ };
32354
+ }
32355
+ assertTypedDataMatchesRequest(
32356
+ body.typedData,
32357
+ request,
32358
+ config.fallbackSigner.address
32359
+ );
32360
+ const signature = await config.fallbackSigner.signTypedData(body.typedData);
32018
32361
  return {
32019
- values,
32020
- display: values.map((fileId) => fileId.toString())
32362
+ status: "fallback_signed",
32363
+ accountStatus: "confirmation_required",
32364
+ result: {
32365
+ signature,
32366
+ signerAddress: config.fallbackSigner.address,
32367
+ typedData: body.typedData,
32368
+ intent: ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT
32369
+ }
32021
32370
  };
32371
+ }
32372
+ throw new Error(
32373
+ `Unsupported Account PS registration signing status: ${String(body.status)}`
32374
+ );
32375
+ }
32376
+
32377
+ // src/account/personal-server-lite-owner-binding.ts
32378
+ var AccountPersonalServerLiteOwnerBindingError = class extends Error {
32379
+ code;
32380
+ details;
32381
+ constructor(input) {
32382
+ super(input.message);
32383
+ this.name = "AccountPersonalServerLiteOwnerBindingError";
32384
+ this.code = input.code;
32385
+ this.details = input.details;
32386
+ }
32387
+ };
32388
+ async function signPersonalServerLiteOwnerBindingWithAccountClient(config) {
32389
+ let address;
32390
+ try {
32391
+ address = await config.client.getAddress();
32392
+ } catch (error) {
32393
+ throw accountOwnerBindingError(error);
32394
+ }
32395
+ if (!address) {
32396
+ throw new AccountPersonalServerLiteOwnerBindingError({
32397
+ message: "Account did not return a wallet address",
32398
+ code: "account_address_required"
32399
+ });
32400
+ }
32401
+ const message = buildPersonalServerLiteOwnerBindingMessage(address);
32402
+ let signature;
32403
+ try {
32404
+ signature = await config.client.signMessage({ message });
32405
+ } catch (error) {
32406
+ throw accountOwnerBindingError(error);
32407
+ }
32408
+ return {
32409
+ signature,
32410
+ signerAddress: address,
32411
+ message,
32412
+ purpose: PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE
32413
+ };
32414
+ }
32415
+ function accountOwnerBindingError(error) {
32416
+ if (error instanceof AccountPersonalServerLiteOwnerBindingError) {
32417
+ return error;
32418
+ }
32419
+ const rpcError = error;
32420
+ const code = rpcError?.code;
32421
+ const message = typeof rpcError?.message === "string" && rpcError.message.length > 0 ? rpcError.message : "Account PS Lite owner-binding signature failed";
32422
+ return new AccountPersonalServerLiteOwnerBindingError({
32423
+ message,
32424
+ code,
32425
+ details: error
32426
+ });
32427
+ }
32428
+
32429
+ // src/protocol/grants.ts
32430
+ import { verifyTypedData } from "viem";
32431
+ function isHexString(value) {
32432
+ return typeof value === "string" && value.startsWith("0x");
32433
+ }
32434
+ function isDataPortabilityGatewayConfig(value) {
32435
+ if (value === null || typeof value !== "object" || Array.isArray(value)) {
32436
+ return false;
32437
+ }
32438
+ const config = value;
32439
+ const contracts = config["contracts"];
32440
+ if (typeof config["chainId"] !== "number" || !Number.isInteger(config["chainId"]) || config["chainId"] <= 0 || contracts === null || typeof contracts !== "object" || Array.isArray(contracts)) {
32441
+ return false;
32442
+ }
32443
+ const c = contracts;
32444
+ return isHexString(c["dataRegistry"]) && isHexString(c["dataPortabilityPermissions"]) && isHexString(c["dataPortabilityServer"]) && isHexString(c["dataPortabilityGrantees"]) && isHexString(c["dataPortabilityEscrow"]);
32445
+ }
32446
+ function toUint256(value) {
32447
+ try {
32448
+ const big = typeof value === "bigint" ? value : BigInt(value);
32449
+ if (big < 0n) return null;
32450
+ return big;
32022
32451
  } catch {
32023
32452
  return null;
32024
32453
  }
32025
32454
  }
32026
32455
  async function verifyGrantRegistration(input) {
32027
- const payload = parseGrantRegistrationPayload(input.grant);
32028
- if (!payload) {
32029
- return {
32030
- valid: false,
32031
- error: "Grant must be JSON with scopes and expiresAt"
32032
- };
32456
+ if (!Array.isArray(input.scopes) || input.scopes.length === 0) {
32457
+ return { valid: false, error: "scopes must be a non-empty array" };
32458
+ }
32459
+ if (!input.scopes.every((scope) => typeof scope === "string")) {
32460
+ return { valid: false, error: "scopes must contain only strings" };
32033
32461
  }
32034
- const fileIds = parseFileIds(input.fileIds);
32035
- if (!fileIds) {
32036
- return { valid: false, error: "fileIds must contain integer values" };
32462
+ const grantVersion = toUint256(input.grantVersion);
32463
+ if (grantVersion === null || grantVersion < 1n) {
32464
+ return { valid: false, error: "grantVersion must be a uint256 >= 1" };
32465
+ }
32466
+ const expiresAt = toUint256(input.expiresAt);
32467
+ if (expiresAt === null) {
32468
+ return { valid: false, error: "expiresAt must be a non-negative uint256" };
32037
32469
  }
32038
32470
  let valid;
32039
32471
  try {
@@ -32045,8 +32477,9 @@ async function verifyGrantRegistration(input) {
32045
32477
  message: {
32046
32478
  grantorAddress: input.grantorAddress,
32047
32479
  granteeId: input.granteeId,
32048
- grant: input.grant,
32049
- fileIds: fileIds.values
32480
+ scopes: input.scopes,
32481
+ grantVersion,
32482
+ expiresAt
32050
32483
  },
32051
32484
  signature: input.signature
32052
32485
  });
@@ -32057,19 +32490,69 @@ async function verifyGrantRegistration(input) {
32057
32490
  return { valid: false, error: "Grant signature does not match grantor" };
32058
32491
  }
32059
32492
  const nowSeconds = input.nowSeconds ?? Math.floor(Date.now() / 1e3);
32060
- if (payload.expiresAt > 0 && payload.expiresAt < nowSeconds) {
32493
+ if (expiresAt > 0n && expiresAt < BigInt(nowSeconds)) {
32061
32494
  return { valid: false, error: "Grant has expired" };
32062
32495
  }
32063
- if (payload.user !== void 0 && payload.user.toLowerCase() !== input.grantorAddress.toLowerCase()) {
32064
- return { valid: false, error: "Grant user does not match grantorAddress" };
32065
- }
32066
32496
  return {
32067
32497
  valid: true,
32068
32498
  grantorAddress: input.grantorAddress,
32069
32499
  granteeId: input.granteeId,
32070
- grant: input.grant,
32071
- payload,
32072
- fileIds: fileIds.display
32500
+ scopes: input.scopes,
32501
+ grantVersion: grantVersion.toString(),
32502
+ expiresAt: expiresAt.toString()
32503
+ };
32504
+ }
32505
+
32506
+ // src/protocol/escrow-deposit.ts
32507
+ import { encodeFunctionData } from "viem";
32508
+ var ESCROW_DEPOSIT_ABI = [
32509
+ {
32510
+ type: "function",
32511
+ name: "depositNative",
32512
+ stateMutability: "payable",
32513
+ inputs: [{ name: "account", type: "address" }],
32514
+ outputs: []
32515
+ },
32516
+ {
32517
+ type: "function",
32518
+ name: "depositToken",
32519
+ stateMutability: "nonpayable",
32520
+ inputs: [
32521
+ { name: "account", type: "address" },
32522
+ { name: "token", type: "address" },
32523
+ { name: "amount", type: "uint256" }
32524
+ ],
32525
+ outputs: []
32526
+ }
32527
+ ];
32528
+ function escrowContractAddress(config) {
32529
+ return config.contracts.dataPortabilityEscrow;
32530
+ }
32531
+ function encodeDepositNativeData(input) {
32532
+ return encodeFunctionData({
32533
+ abi: ESCROW_DEPOSIT_ABI,
32534
+ functionName: "depositNative",
32535
+ args: [input.account]
32536
+ });
32537
+ }
32538
+ function encodeDepositTokenData(input) {
32539
+ return encodeFunctionData({
32540
+ abi: ESCROW_DEPOSIT_ABI,
32541
+ functionName: "depositToken",
32542
+ args: [input.account, input.token, input.amount]
32543
+ });
32544
+ }
32545
+ function buildDepositNativeRequest(config, input) {
32546
+ return {
32547
+ to: escrowContractAddress(config),
32548
+ data: encodeDepositNativeData({ account: input.account }),
32549
+ value: input.amount
32550
+ };
32551
+ }
32552
+ function buildDepositTokenRequest(config, input) {
32553
+ return {
32554
+ to: escrowContractAddress(config),
32555
+ data: encodeDepositTokenData(input)
32073
32556
  };
32074
32557
  }
32075
32558
 
@@ -32269,6 +32752,68 @@ function createGatewayClient(baseUrl) {
32269
32752
  alreadyRegistered: false
32270
32753
  };
32271
32754
  },
32755
+ async registerBuilder(params) {
32756
+ const res = await fetch(`${base}/v1/builders`, {
32757
+ method: "POST",
32758
+ headers: {
32759
+ "Content-Type": "application/json",
32760
+ Authorization: `Web3Signed ${params.signature}`
32761
+ },
32762
+ body: JSON.stringify({
32763
+ ownerAddress: params.ownerAddress,
32764
+ granteeAddress: params.granteeAddress,
32765
+ publicKey: params.publicKey,
32766
+ appUrl: params.appUrl
32767
+ })
32768
+ });
32769
+ if (res.status === 409) {
32770
+ const body2 = await res.json().catch(() => ({}));
32771
+ return {
32772
+ builderId: getMutationId(
32773
+ body2,
32774
+ "builderId"
32775
+ ),
32776
+ alreadyRegistered: true
32777
+ };
32778
+ }
32779
+ if (!res.ok) {
32780
+ throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
32781
+ }
32782
+ const body = await res.json().catch(() => ({}));
32783
+ return {
32784
+ builderId: getMutationId(body, "builderId"),
32785
+ alreadyRegistered: false
32786
+ };
32787
+ },
32788
+ async registerDataPoint(params) {
32789
+ const res = await fetch(`${base}/v1/data`, {
32790
+ method: "POST",
32791
+ headers: {
32792
+ "Content-Type": "application/json",
32793
+ Authorization: `Web3Signed ${params.signature}`
32794
+ },
32795
+ body: JSON.stringify({
32796
+ ownerAddress: params.ownerAddress,
32797
+ scope: params.scope,
32798
+ dataHash: params.dataHash,
32799
+ metadataHash: params.metadataHash,
32800
+ expectedVersion: params.expectedVersion
32801
+ })
32802
+ });
32803
+ if (!res.ok) {
32804
+ const body2 = await res.json().catch(() => ({}));
32805
+ const detail = body2.error ?? res.statusText;
32806
+ throw new Error(`Gateway error: ${res.status} ${detail}`);
32807
+ }
32808
+ const body = await res.json().catch(() => ({}));
32809
+ return {
32810
+ dataPointId: getMutationId(
32811
+ body,
32812
+ "dataPointId"
32813
+ ),
32814
+ expectedVersion: body.expectedVersion
32815
+ };
32816
+ },
32272
32817
  async registerFile(params) {
32273
32818
  const res = await fetch(`${base}/v1/files`, {
32274
32819
  method: "POST",
@@ -32306,8 +32851,9 @@ function createGatewayClient(baseUrl) {
32306
32851
  body: JSON.stringify({
32307
32852
  grantorAddress: params.grantorAddress,
32308
32853
  granteeId: params.granteeId,
32309
- grant: params.grant,
32310
- fileIds: params.fileIds
32854
+ scopes: params.scopes,
32855
+ grantVersion: params.grantVersion,
32856
+ expiresAt: params.expiresAt
32311
32857
  })
32312
32858
  });
32313
32859
  if (res.status === 409) {
@@ -32332,13 +32878,71 @@ function createGatewayClient(baseUrl) {
32332
32878
  Authorization: `Web3Signed ${params.signature}`
32333
32879
  },
32334
32880
  body: JSON.stringify({
32335
- grantorAddress: params.grantorAddress
32881
+ grantorAddress: params.grantorAddress,
32882
+ grantVersion: params.grantVersion
32336
32883
  })
32337
32884
  });
32338
32885
  if (res.status === 409) return;
32339
32886
  if (!res.ok) {
32340
32887
  throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
32341
32888
  }
32889
+ },
32890
+ async getEscrowBalance(account) {
32891
+ const res = await fetch(`${base}/v1/escrow/balance?account=${account}`);
32892
+ if (!res.ok) {
32893
+ throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
32894
+ }
32895
+ return await res.json();
32896
+ },
32897
+ async submitEscrowDeposit(params) {
32898
+ const res = await fetch(`${base}/v1/escrow/deposit`, {
32899
+ method: "POST",
32900
+ headers: { "Content-Type": "application/json" },
32901
+ body: JSON.stringify({ txHash: params.txHash })
32902
+ });
32903
+ if (res.status !== 200 && res.status !== 202) {
32904
+ throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
32905
+ }
32906
+ return await res.json();
32907
+ },
32908
+ async payForOperation(params) {
32909
+ const body = {
32910
+ payerAddress: params.payerAddress,
32911
+ opType: params.opType,
32912
+ opId: params.opId,
32913
+ asset: params.asset,
32914
+ amount: params.amount,
32915
+ paymentNonce: params.paymentNonce
32916
+ };
32917
+ if (params.accessRecord) {
32918
+ body["accessRecord"] = params.accessRecord;
32919
+ }
32920
+ const res = await fetch(`${base}/v1/escrow/pay`, {
32921
+ method: "POST",
32922
+ headers: {
32923
+ "Content-Type": "application/json",
32924
+ Authorization: `Web3Signed ${params.signature}`
32925
+ },
32926
+ body: JSON.stringify(body)
32927
+ });
32928
+ if (!res.ok) {
32929
+ throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
32930
+ }
32931
+ return await res.json();
32932
+ },
32933
+ async settle(params) {
32934
+ const res = await fetch(`${base}/v1/settle`, {
32935
+ method: "POST",
32936
+ headers: { "Content-Type": "application/json" },
32937
+ // The gateway accepts an empty body; only `limit` is recognised.
32938
+ // Always send a JSON body so the gateway's req.body shape parse
32939
+ // doesn't have to deal with an undefined.
32940
+ body: JSON.stringify(params ?? {})
32941
+ });
32942
+ if (!res.ok) {
32943
+ throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
32944
+ }
32945
+ return await res.json();
32342
32946
  }
32343
32947
  };
32344
32948
  }
@@ -32368,7 +32972,7 @@ var KNOWN_CODES = /* @__PURE__ */ new Set([
32368
32972
  "server_not_configured",
32369
32973
  "content_too_large"
32370
32974
  ]);
32371
- function isRecord(value) {
32975
+ function isRecord2(value) {
32372
32976
  return value !== null && typeof value === "object" && !Array.isArray(value);
32373
32977
  }
32374
32978
  function normalizeCode(value) {
@@ -32379,10 +32983,10 @@ function normalizeCode(value) {
32379
32983
  return KNOWN_CODES.has(code) ? code : null;
32380
32984
  }
32381
32985
  function extractPSErrorBody(body) {
32382
- if (!isRecord(body)) {
32986
+ if (!isRecord2(body)) {
32383
32987
  return null;
32384
32988
  }
32385
- const nested = isRecord(body.error) ? body.error : null;
32989
+ const nested = isRecord2(body.error) ? body.error : null;
32386
32990
  const code = normalizeCode(
32387
32991
  nested?.errorCode ?? nested?.code ?? body.errorCode ?? body.code
32388
32992
  );
@@ -32406,6 +33010,10 @@ async function parsePSError(response) {
32406
33010
  return errorBody ? new PSError(errorBody.code, errorBody.message) : null;
32407
33011
  }
32408
33012
  export {
33013
+ ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT,
33014
+ ADD_DATA_TYPES,
33015
+ AccountPersonalServerLiteOwnerBindingError,
33016
+ AccountPersonalServerRegistrationError,
32409
33017
  BUILDER_REGISTRATION_TYPES,
32410
33018
  BlockchainError,
32411
33019
  BrowserECIESUint8Provider as BrowserECIESProvider,
@@ -32417,8 +33025,10 @@ export {
32417
33025
  DataFileEnvelopeSchema,
32418
33026
  DropboxStorage,
32419
33027
  ECIESError,
33028
+ ESCROW_DEPOSIT_ABI,
32420
33029
  ExpiredTokenError,
32421
33030
  FILE_REGISTRATION_TYPES,
33031
+ GENERIC_PAYMENT_TYPES,
32422
33032
  GRANT_REGISTRATION_TYPES,
32423
33033
  GRANT_REVOCATION_TYPES,
32424
33034
  GoogleDriveStorage,
@@ -32429,9 +33039,15 @@ export {
32429
33039
  IpfsStorage,
32430
33040
  MASTER_KEY_MESSAGE,
32431
33041
  MissingAuthError,
33042
+ NATIVE_VANA_ASSET,
32432
33043
  NetworkError,
32433
33044
  NonceError,
32434
33045
  OAuthClient,
33046
+ PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX,
33047
+ PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE,
33048
+ PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION,
33049
+ PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID,
33050
+ PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT,
32435
33051
  PKCE_CHALLENGE_PATTERN,
32436
33052
  PKCE_VERIFIER_PATTERN,
32437
33053
  PSError,
@@ -32439,6 +33055,7 @@ export {
32439
33055
  PersonalServerError,
32440
33056
  PinataStorage,
32441
33057
  R2Storage,
33058
+ RECORD_DATA_ACCESS_TYPES,
32442
33059
  ReadOnlyError,
32443
33060
  RelayerError,
32444
33061
  SERVER_REGISTRATION_TYPES,
@@ -32453,6 +33070,12 @@ export {
32453
33070
  VanaError,
32454
33071
  VanaStorage,
32455
33072
  assertValidPkceVerifier,
33073
+ buildDepositNativeRequest,
33074
+ buildDepositTokenRequest,
33075
+ buildPersonalServerLiteOwnerBindingMessage,
33076
+ buildPersonalServerLiteOwnerBindingSignature,
33077
+ buildPersonalServerRegistrationSignature,
33078
+ buildPersonalServerRegistrationTypedData,
32456
33079
  buildWeb3SignedHeader,
32457
33080
  builderRegistrationDomain,
32458
33081
  chains,
@@ -32465,12 +33088,19 @@ export {
32465
33088
  createGatewayClient,
32466
33089
  createPlatformAdapterSafe,
32467
33090
  createVanaStorageProvider,
33091
+ createViemPersonalServerLiteOwnerBindingSigner,
33092
+ createViemPersonalServerRegistrationSigner,
33093
+ dataRegistryDomain,
32468
33094
  decryptWithPassword,
32469
33095
  deriveMasterKey,
32470
33096
  deriveScopeKey,
32471
33097
  deserializeECIES,
32472
33098
  detectPlatform,
33099
+ encodeDepositNativeData,
33100
+ encodeDepositTokenData,
32473
33101
  encryptWithPassword,
33102
+ escrowContractAddress,
33103
+ escrowPaymentDomain,
32474
33104
  fileRegistrationDomain,
32475
33105
  generatePkceVerifier,
32476
33106
  getAbi,
@@ -32490,16 +33120,20 @@ export {
32490
33120
  moksha,
32491
33121
  mokshaServices,
32492
33122
  mokshaTestnet2 as mokshaTestnet,
32493
- parseGrantRegistrationPayload,
32494
33123
  parsePSError,
32495
33124
  parseScope,
32496
33125
  parseWeb3SignedHeader,
33126
+ personalServerRegistrationDomain,
32497
33127
  recoverServerOwner,
33128
+ registerPersonalServerSignature,
32498
33129
  scopeCoveredByGrant,
32499
33130
  scopeMatchesPattern,
32500
33131
  scopeToPathSegments,
32501
33132
  serializeECIES,
32502
33133
  serverRegistrationDomain,
33134
+ signPersonalServerLiteOwnerBinding,
33135
+ signPersonalServerLiteOwnerBindingWithAccountClient,
33136
+ signPersonalServerRegistrationWithAccount,
32503
33137
  vanaMainnet2 as vanaMainnet,
32504
33138
  verifyGrantRegistration,
32505
33139
  verifyPkceChallenge,