@opendatalabs/vana-sdk 0.1.0-alpha.a7bcbd6 → 0.1.0-alpha.aa3959e

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.
@@ -99,15 +99,35 @@ var init_error_utils = __esm({
99
99
  }
100
100
  });
101
101
 
102
+ // src/utils/lazy-import.ts
103
+ function lazyImport(importFn) {
104
+ let cached = null;
105
+ return () => {
106
+ if (!cached) {
107
+ cached = importFn().catch((err) => {
108
+ cached = null;
109
+ throw new Error("Failed to load module", { cause: err });
110
+ });
111
+ }
112
+ return cached;
113
+ };
114
+ }
115
+ var init_lazy_import = __esm({
116
+ "src/utils/lazy-import.ts"() {
117
+ "use strict";
118
+ }
119
+ });
120
+
102
121
  // src/platform/browser.ts
103
- import * as openpgp from "openpgp";
104
- var BrowserCryptoAdapter, BrowserPGPAdapter, BrowserHttpAdapter, BrowserCacheAdapter, BrowserPlatformAdapter, browserPlatformAdapter;
122
+ var getOpenPGP, BrowserCryptoAdapter, BrowserPGPAdapter, BrowserHttpAdapter, BrowserCacheAdapter, BrowserPlatformAdapter, browserPlatformAdapter;
105
123
  var init_browser = __esm({
106
124
  "src/platform/browser.ts"() {
107
125
  "use strict";
108
126
  init_crypto_utils();
109
127
  init_pgp_utils();
110
128
  init_error_utils();
129
+ init_lazy_import();
130
+ getOpenPGP = lazyImport(() => import("openpgp"));
111
131
  BrowserCryptoAdapter = class {
112
132
  async encryptWithPublicKey(data, publicKeyHex) {
113
133
  try {
@@ -196,11 +216,11 @@ var init_browser = __esm({
196
216
  }
197
217
  async encryptWithPassword(data, password) {
198
218
  try {
199
- const openpgp2 = await import("openpgp");
200
- const message = await openpgp2.createMessage({
219
+ const openpgp = await getOpenPGP();
220
+ const message = await openpgp.createMessage({
201
221
  binary: data
202
222
  });
203
- const encrypted = await openpgp2.encrypt({
223
+ const encrypted = await openpgp.encrypt({
204
224
  message,
205
225
  passwords: [password],
206
226
  format: "binary"
@@ -214,11 +234,11 @@ var init_browser = __esm({
214
234
  }
215
235
  async decryptWithPassword(encryptedData, password) {
216
236
  try {
217
- const openpgp2 = await import("openpgp");
218
- const message = await openpgp2.readMessage({
237
+ const openpgp = await getOpenPGP();
238
+ const message = await openpgp.readMessage({
219
239
  binaryMessage: encryptedData
220
240
  });
221
- const { data: decrypted } = await openpgp2.decrypt({
241
+ const { data: decrypted } = await openpgp.decrypt({
222
242
  message,
223
243
  passwords: [password],
224
244
  format: "binary"
@@ -232,6 +252,7 @@ var init_browser = __esm({
232
252
  BrowserPGPAdapter = class {
233
253
  async encrypt(data, publicKeyArmored) {
234
254
  try {
255
+ const openpgp = await getOpenPGP();
235
256
  const publicKey = await openpgp.readKey({ armoredKey: publicKeyArmored });
236
257
  const encrypted = await openpgp.encrypt({
237
258
  message: await openpgp.createMessage({ text: data }),
@@ -247,6 +268,7 @@ var init_browser = __esm({
247
268
  }
248
269
  async decrypt(encryptedData, privateKeyArmored) {
249
270
  try {
271
+ const openpgp = await getOpenPGP();
250
272
  const privateKey = await openpgp.readPrivateKey({
251
273
  armoredKey: privateKeyArmored
252
274
  });
@@ -264,6 +286,7 @@ var init_browser = __esm({
264
286
  }
265
287
  async generateKeyPair(options) {
266
288
  try {
289
+ const openpgp = await getOpenPGP();
267
290
  const keyGenParams = getPGPKeyGenParams(options);
268
291
  const { privateKey, publicKey } = await openpgp.generateKey(keyGenParams);
269
292
  return { publicKey, privateKey };
@@ -876,11 +899,11 @@ import { parseEventLogs } from "viem";
876
899
  var EVENT_MAPPINGS = {
877
900
  // Permission operations
878
901
  grant: {
879
- contract: "DataPermissions",
902
+ contract: "DataPortabilityPermissions",
880
903
  event: "PermissionAdded"
881
904
  },
882
905
  revoke: {
883
- contract: "DataPermissions",
906
+ contract: "DataPortabilityPermissions",
884
907
  event: "PermissionRevoked"
885
908
  },
886
909
  trustServer: {
@@ -6094,6 +6117,22 @@ var DataPortabilityPermissionsABI = [
6094
6117
  name: "InvalidNonce",
6095
6118
  type: "error"
6096
6119
  },
6120
+ {
6121
+ inputs: [
6122
+ {
6123
+ internalType: "uint256",
6124
+ name: "filesLength",
6125
+ type: "uint256"
6126
+ },
6127
+ {
6128
+ internalType: "uint256",
6129
+ name: "permissionsLength",
6130
+ type: "uint256"
6131
+ }
6132
+ ],
6133
+ name: "InvalidPermissionsLength",
6134
+ type: "error"
6135
+ },
6097
6136
  {
6098
6137
  inputs: [],
6099
6138
  name: "InvalidSignature",
@@ -6425,6 +6464,84 @@ var DataPortabilityPermissionsABI = [
6425
6464
  stateMutability: "nonpayable",
6426
6465
  type: "function"
6427
6466
  },
6467
+ {
6468
+ inputs: [
6469
+ {
6470
+ components: [
6471
+ {
6472
+ internalType: "uint256",
6473
+ name: "nonce",
6474
+ type: "uint256"
6475
+ },
6476
+ {
6477
+ internalType: "uint256",
6478
+ name: "granteeId",
6479
+ type: "uint256"
6480
+ },
6481
+ {
6482
+ internalType: "string",
6483
+ name: "grant",
6484
+ type: "string"
6485
+ },
6486
+ {
6487
+ internalType: "string[]",
6488
+ name: "fileUrls",
6489
+ type: "string[]"
6490
+ },
6491
+ {
6492
+ internalType: "address",
6493
+ name: "serverAddress",
6494
+ type: "address"
6495
+ },
6496
+ {
6497
+ internalType: "string",
6498
+ name: "serverUrl",
6499
+ type: "string"
6500
+ },
6501
+ {
6502
+ internalType: "string",
6503
+ name: "serverPublicKey",
6504
+ type: "string"
6505
+ },
6506
+ {
6507
+ components: [
6508
+ {
6509
+ internalType: "address",
6510
+ name: "account",
6511
+ type: "address"
6512
+ },
6513
+ {
6514
+ internalType: "string",
6515
+ name: "key",
6516
+ type: "string"
6517
+ }
6518
+ ],
6519
+ internalType: "struct IDataRegistry.Permission[][]",
6520
+ name: "filePermissions",
6521
+ type: "tuple[][]"
6522
+ }
6523
+ ],
6524
+ internalType: "struct IDataPortabilityPermissions.ServerFilesAndPermissionInput",
6525
+ name: "serverFilesAndPermissionInput",
6526
+ type: "tuple"
6527
+ },
6528
+ {
6529
+ internalType: "bytes",
6530
+ name: "signature",
6531
+ type: "bytes"
6532
+ }
6533
+ ],
6534
+ name: "addServerFilesAndPermissions",
6535
+ outputs: [
6536
+ {
6537
+ internalType: "uint256",
6538
+ name: "",
6539
+ type: "uint256"
6540
+ }
6541
+ ],
6542
+ stateMutability: "nonpayable",
6543
+ type: "function"
6544
+ },
6428
6545
  {
6429
6546
  inputs: [],
6430
6547
  name: "dataPortabilityGrantees",
@@ -6639,25 +6756,6 @@ var DataPortabilityPermissionsABI = [
6639
6756
  stateMutability: "nonpayable",
6640
6757
  type: "function"
6641
6758
  },
6642
- {
6643
- inputs: [
6644
- {
6645
- internalType: "uint256",
6646
- name: "permissionId",
6647
- type: "uint256"
6648
- }
6649
- ],
6650
- name: "isActivePermission",
6651
- outputs: [
6652
- {
6653
- internalType: "bool",
6654
- name: "",
6655
- type: "bool"
6656
- }
6657
- ],
6658
- stateMutability: "view",
6659
- type: "function"
6660
- },
6661
6759
  {
6662
6760
  inputs: [
6663
6761
  {
@@ -6772,11 +6870,6 @@ var DataPortabilityPermissionsABI = [
6772
6870
  name: "grant",
6773
6871
  type: "string"
6774
6872
  },
6775
- {
6776
- internalType: "bytes",
6777
- name: "signature",
6778
- type: "bytes"
6779
- },
6780
6873
  {
6781
6874
  internalType: "uint256",
6782
6875
  name: "startBlock",
@@ -7494,9 +7587,9 @@ var DataPortabilityServersABI = [
7494
7587
  },
7495
7588
  {
7496
7589
  indexed: false,
7497
- internalType: "bytes",
7590
+ internalType: "string",
7498
7591
  name: "publicKey",
7499
- type: "bytes"
7592
+ type: "string"
7500
7593
  },
7501
7594
  {
7502
7595
  indexed: false,
@@ -7617,6 +7710,19 @@ var DataPortabilityServersABI = [
7617
7710
  stateMutability: "view",
7618
7711
  type: "function"
7619
7712
  },
7713
+ {
7714
+ inputs: [],
7715
+ name: "PERMISSION_MANAGER_ROLE",
7716
+ outputs: [
7717
+ {
7718
+ internalType: "bytes32",
7719
+ name: "",
7720
+ type: "bytes32"
7721
+ }
7722
+ ],
7723
+ stateMutability: "view",
7724
+ type: "function"
7725
+ },
7620
7726
  {
7621
7727
  inputs: [],
7622
7728
  name: "UPGRADE_INTERFACE_VERSION",
@@ -7632,22 +7738,22 @@ var DataPortabilityServersABI = [
7632
7738
  },
7633
7739
  {
7634
7740
  inputs: [
7741
+ {
7742
+ internalType: "address",
7743
+ name: "ownerAddress",
7744
+ type: "address"
7745
+ },
7635
7746
  {
7636
7747
  components: [
7637
- {
7638
- internalType: "address",
7639
- name: "owner",
7640
- type: "address"
7641
- },
7642
7748
  {
7643
7749
  internalType: "address",
7644
7750
  name: "serverAddress",
7645
7751
  type: "address"
7646
7752
  },
7647
7753
  {
7648
- internalType: "bytes",
7754
+ internalType: "string",
7649
7755
  name: "publicKey",
7650
- type: "bytes"
7756
+ type: "string"
7651
7757
  },
7652
7758
  {
7653
7759
  internalType: "string",
@@ -7656,11 +7762,11 @@ var DataPortabilityServersABI = [
7656
7762
  }
7657
7763
  ],
7658
7764
  internalType: "struct IDataPortabilityServers.AddServerInput",
7659
- name: "addAndTrustServerInput",
7765
+ name: "addServerInput",
7660
7766
  type: "tuple"
7661
7767
  }
7662
7768
  ],
7663
- name: "addAndTrustServer",
7769
+ name: "addAndTrustServerOnBehalf",
7664
7770
  outputs: [],
7665
7771
  stateMutability: "nonpayable",
7666
7772
  type: "function"
@@ -7674,20 +7780,15 @@ var DataPortabilityServersABI = [
7674
7780
  name: "nonce",
7675
7781
  type: "uint256"
7676
7782
  },
7677
- {
7678
- internalType: "address",
7679
- name: "owner",
7680
- type: "address"
7681
- },
7682
7783
  {
7683
7784
  internalType: "address",
7684
7785
  name: "serverAddress",
7685
7786
  type: "address"
7686
7787
  },
7687
7788
  {
7688
- internalType: "bytes",
7789
+ internalType: "string",
7689
7790
  name: "publicKey",
7690
- type: "bytes"
7791
+ type: "string"
7691
7792
  },
7692
7793
  {
7693
7794
  internalType: "string",
@@ -7695,8 +7796,8 @@ var DataPortabilityServersABI = [
7695
7796
  type: "string"
7696
7797
  }
7697
7798
  ],
7698
- internalType: "struct IDataPortabilityServers.AddAndTrustServerInput",
7699
- name: "addAndTrustServerInput",
7799
+ internalType: "struct IDataPortabilityServers.AddServerWithSignatureInput",
7800
+ name: "addServerInput",
7700
7801
  type: "tuple"
7701
7802
  },
7702
7803
  {
@@ -7715,9 +7816,9 @@ var DataPortabilityServersABI = [
7715
7816
  {
7716
7817
  components: [
7717
7818
  {
7718
- internalType: "address",
7719
- name: "owner",
7720
- type: "address"
7819
+ internalType: "uint256",
7820
+ name: "nonce",
7821
+ type: "uint256"
7721
7822
  },
7722
7823
  {
7723
7824
  internalType: "address",
@@ -7725,9 +7826,9 @@ var DataPortabilityServersABI = [
7725
7826
  type: "address"
7726
7827
  },
7727
7828
  {
7728
- internalType: "bytes",
7829
+ internalType: "string",
7729
7830
  name: "publicKey",
7730
- type: "bytes"
7831
+ type: "string"
7731
7832
  },
7732
7833
  {
7733
7834
  internalType: "string",
@@ -7735,12 +7836,17 @@ var DataPortabilityServersABI = [
7735
7836
  type: "string"
7736
7837
  }
7737
7838
  ],
7738
- internalType: "struct IDataPortabilityServers.AddServerInput",
7839
+ internalType: "struct IDataPortabilityServers.AddServerWithSignatureInput",
7739
7840
  name: "addServerInput",
7740
7841
  type: "tuple"
7842
+ },
7843
+ {
7844
+ internalType: "bytes",
7845
+ name: "signature",
7846
+ type: "bytes"
7741
7847
  }
7742
7848
  ],
7743
- name: "addServer",
7849
+ name: "addServerWithSignature",
7744
7850
  outputs: [],
7745
7851
  stateMutability: "nonpayable",
7746
7852
  type: "function"
@@ -7867,49 +7973,6 @@ var DataPortabilityServersABI = [
7867
7973
  stateMutability: "nonpayable",
7868
7974
  type: "function"
7869
7975
  },
7870
- {
7871
- inputs: [
7872
- {
7873
- internalType: "uint256",
7874
- name: "serverId",
7875
- type: "uint256"
7876
- }
7877
- ],
7878
- name: "isActiveServer",
7879
- outputs: [
7880
- {
7881
- internalType: "bool",
7882
- name: "",
7883
- type: "bool"
7884
- }
7885
- ],
7886
- stateMutability: "view",
7887
- type: "function"
7888
- },
7889
- {
7890
- inputs: [
7891
- {
7892
- internalType: "address",
7893
- name: "userAddress",
7894
- type: "address"
7895
- },
7896
- {
7897
- internalType: "uint256",
7898
- name: "serverId",
7899
- type: "uint256"
7900
- }
7901
- ],
7902
- name: "isActiveServerForUser",
7903
- outputs: [
7904
- {
7905
- internalType: "bool",
7906
- name: "",
7907
- type: "bool"
7908
- }
7909
- ],
7910
- stateMutability: "view",
7911
- type: "function"
7912
- },
7913
7976
  {
7914
7977
  inputs: [
7915
7978
  {
@@ -8064,9 +8127,9 @@ var DataPortabilityServersABI = [
8064
8127
  type: "address"
8065
8128
  },
8066
8129
  {
8067
- internalType: "bytes",
8130
+ internalType: "string",
8068
8131
  name: "publicKey",
8069
- type: "bytes"
8132
+ type: "string"
8070
8133
  },
8071
8134
  {
8072
8135
  internalType: "string",
@@ -8110,9 +8173,9 @@ var DataPortabilityServersABI = [
8110
8173
  type: "address"
8111
8174
  },
8112
8175
  {
8113
- internalType: "bytes",
8176
+ internalType: "string",
8114
8177
  name: "publicKey",
8115
- type: "bytes"
8178
+ type: "string"
8116
8179
  },
8117
8180
  {
8118
8181
  internalType: "string",
@@ -8432,6 +8495,123 @@ var DataPortabilityServersABI = [
8432
8495
  stateMutability: "view",
8433
8496
  type: "function"
8434
8497
  },
8498
+ {
8499
+ inputs: [
8500
+ {
8501
+ internalType: "address",
8502
+ name: "userAddress",
8503
+ type: "address"
8504
+ }
8505
+ ],
8506
+ name: "userServerValues",
8507
+ outputs: [
8508
+ {
8509
+ components: [
8510
+ {
8511
+ internalType: "uint256",
8512
+ name: "id",
8513
+ type: "uint256"
8514
+ },
8515
+ {
8516
+ internalType: "address",
8517
+ name: "owner",
8518
+ type: "address"
8519
+ },
8520
+ {
8521
+ internalType: "address",
8522
+ name: "serverAddress",
8523
+ type: "address"
8524
+ },
8525
+ {
8526
+ internalType: "string",
8527
+ name: "publicKey",
8528
+ type: "string"
8529
+ },
8530
+ {
8531
+ internalType: "string",
8532
+ name: "url",
8533
+ type: "string"
8534
+ },
8535
+ {
8536
+ internalType: "uint256",
8537
+ name: "startBlock",
8538
+ type: "uint256"
8539
+ },
8540
+ {
8541
+ internalType: "uint256",
8542
+ name: "endBlock",
8543
+ type: "uint256"
8544
+ }
8545
+ ],
8546
+ internalType: "struct IDataPortabilityServers.TrustedServerInfo[]",
8547
+ name: "serversInfo",
8548
+ type: "tuple[]"
8549
+ }
8550
+ ],
8551
+ stateMutability: "view",
8552
+ type: "function"
8553
+ },
8554
+ {
8555
+ inputs: [
8556
+ {
8557
+ internalType: "address",
8558
+ name: "userAddress",
8559
+ type: "address"
8560
+ },
8561
+ {
8562
+ internalType: "uint256",
8563
+ name: "serverId",
8564
+ type: "uint256"
8565
+ }
8566
+ ],
8567
+ name: "userServers",
8568
+ outputs: [
8569
+ {
8570
+ components: [
8571
+ {
8572
+ internalType: "uint256",
8573
+ name: "id",
8574
+ type: "uint256"
8575
+ },
8576
+ {
8577
+ internalType: "address",
8578
+ name: "owner",
8579
+ type: "address"
8580
+ },
8581
+ {
8582
+ internalType: "address",
8583
+ name: "serverAddress",
8584
+ type: "address"
8585
+ },
8586
+ {
8587
+ internalType: "string",
8588
+ name: "publicKey",
8589
+ type: "string"
8590
+ },
8591
+ {
8592
+ internalType: "string",
8593
+ name: "url",
8594
+ type: "string"
8595
+ },
8596
+ {
8597
+ internalType: "uint256",
8598
+ name: "startBlock",
8599
+ type: "uint256"
8600
+ },
8601
+ {
8602
+ internalType: "uint256",
8603
+ name: "endBlock",
8604
+ type: "uint256"
8605
+ }
8606
+ ],
8607
+ internalType: "struct IDataPortabilityServers.TrustedServerInfo",
8608
+ name: "",
8609
+ type: "tuple"
8610
+ }
8611
+ ],
8612
+ stateMutability: "view",
8613
+ type: "function"
8614
+ },
8435
8615
  {
8436
8616
  inputs: [
8437
8617
  {
@@ -34993,7 +35173,6 @@ var DATVotesABI = [
34993
35173
 
34994
35174
  // src/abi/index.ts
34995
35175
  var contractAbis = {
34996
- DataPermissions: DataPortabilityPermissionsABI,
34997
35176
  DataPortabilityPermissions: DataPortabilityPermissionsABI,
34998
35177
  DataPortabilityServers: DataPortabilityServersABI,
34999
35178
  DataPortabilityGrantees: DataPortabilityGranteesABI,
@@ -35101,13 +35280,6 @@ async function parseTransactionResult(context, hash, operation) {
35101
35280
  // src/config/addresses.ts
35102
35281
  var CONTRACTS = {
35103
35282
  // Data Portability Contracts (New Architecture)
35104
- DataPermissions: {
35105
- addresses: {
35106
- 14800: "0xD54523048AdD05b4d734aFaE7C68324Ebb7373eF",
35107
- // Points to DataPortabilityPermissions for backwards compatibility
35108
- 1480: "0xD54523048AdD05b4d734aFaE7C68324Ebb7373eF"
35109
- }
35110
- },
35111
35283
  DataPortabilityPermissions: {
35112
35284
  addresses: {
35113
35285
  14800: "0xD54523048AdD05b4d734aFaE7C68324Ebb7373eF",
@@ -35942,6 +36114,42 @@ async function withSignatureCache(cache, walletAddress, typedData, signFn, ttlHo
35942
36114
  return signature;
35943
36115
  }
35944
36116
 
36117
+ // src/utils/signatureFormatter.ts
36118
+ var V_OFFSET_FOR_ETHEREUM = 27;
36119
+ function formatSignatureForContract(signature) {
36120
+ const cleanSig = signature.startsWith("0x") ? signature.slice(2) : signature;
36121
+ if (cleanSig.length !== 130) {
36122
+ return signature;
36123
+ }
36124
+ const vHex = cleanSig.slice(128, 130);
36125
+ const v = parseInt(vHex, 16);
36126
+ if (isNaN(v)) {
36127
+ return signature;
36128
+ }
36129
+ if (v < 27) {
36130
+ const adjustedV = (v + V_OFFSET_FOR_ETHEREUM).toString(16).padStart(2, "0");
36131
+ return `0x${cleanSig.slice(0, 128)}${adjustedV}`;
36132
+ }
36133
+ return signature;
36134
+ }
36135
+
36136
+ // src/utils/typedDataConverter.ts
36137
+ function toViemTypedDataDefinition(typedData) {
36138
+ const viemTypes = {};
36139
+ for (const [typeName, typeArray] of Object.entries(typedData.types)) {
36140
+ viemTypes[typeName] = typeArray.map((field) => ({
36141
+ name: field.name,
36142
+ type: field.type
36143
+ }));
36144
+ }
36145
+ return {
36146
+ domain: typedData.domain,
36147
+ types: viemTypes,
36148
+ primaryType: typedData.primaryType,
36149
+ message: typedData.message
36150
+ };
36151
+ }
36152
+
35945
36153
  // src/controllers/permissions.ts
35946
36154
  var PermissionsController = class {
35947
36155
  constructor(context) {
@@ -36101,7 +36309,7 @@ var PermissionsController = class {
36101
36309
  throw new Error("Failed to store grant file - no URL returned");
36102
36310
  }
36103
36311
  }
36104
- const nonce = await this.getUserNonce();
36312
+ const nonce = await this.getPermissionsUserNonce();
36105
36313
  console.debug(
36106
36314
  "\u{1F50D} Debug - Final grant URL being passed to compose:",
36107
36315
  grantUrl
@@ -36194,7 +36402,7 @@ var PermissionsController = class {
36194
36402
  throw new Error("Failed to store grant file - no URL returned");
36195
36403
  }
36196
36404
  }
36197
- const nonce = await this.getUserNonce();
36405
+ const nonce = await this.getPermissionsUserNonce();
36198
36406
  console.debug(
36199
36407
  "\u{1F50D} Debug - Final grant URL being passed to compose:",
36200
36408
  grantUrl
@@ -36259,14 +36467,8 @@ var PermissionsController = class {
36259
36467
  )
36260
36468
  );
36261
36469
  if (this.context.relayerCallbacks?.submitPermissionGrant) {
36262
- const jsonSafeTypedData = JSON.parse(
36263
- JSON.stringify(
36264
- typedData,
36265
- (_key, value) => typeof value === "bigint" ? value.toString() : value
36266
- )
36267
- );
36268
36470
  return await this.context.relayerCallbacks.submitPermissionGrant(
36269
- jsonSafeTypedData,
36471
+ typedData,
36270
36472
  signature
36271
36473
  );
36272
36474
  } else {
@@ -36336,7 +36538,6 @@ var PermissionsController = class {
36336
36538
  try {
36337
36539
  const addAndTrustServerInput = {
36338
36540
  nonce: BigInt(typedData.message.nonce),
36339
- owner: typedData.message.owner,
36340
36541
  serverAddress: typedData.message.serverAddress,
36341
36542
  serverUrl: typedData.message.serverUrl,
36342
36543
  publicKey: typedData.message.publicKey
@@ -36350,7 +36551,7 @@ var PermissionsController = class {
36350
36551
  throw error;
36351
36552
  }
36352
36553
  throw new BlockchainError(
36353
- `Add and trust server submission failed: ${error instanceof Error ? error.message : "Unknown error"}`,
36554
+ `Add and trust server submission failed444444: ${error instanceof Error ? error.message : "Unknown error"}`,
36354
36555
  error
36355
36556
  );
36356
36557
  }
@@ -36366,14 +36567,8 @@ var PermissionsController = class {
36366
36567
  async submitSignedRevoke(typedData, signature) {
36367
36568
  try {
36368
36569
  if (this.context.relayerCallbacks?.submitPermissionRevoke) {
36369
- const jsonSafeTypedData = JSON.parse(
36370
- JSON.stringify(
36371
- typedData,
36372
- (_key, value) => typeof value === "bigint" ? value.toString() : value
36373
- )
36374
- );
36375
36570
  return await this.context.relayerCallbacks.submitPermissionRevoke(
36376
- jsonSafeTypedData,
36571
+ typedData,
36377
36572
  signature
36378
36573
  );
36379
36574
  } else {
@@ -36426,11 +36621,11 @@ var PermissionsController = class {
36426
36621
  */
36427
36622
  async submitDirectTransaction(typedData, signature) {
36428
36623
  const chainId = await this.context.walletClient.getChainId();
36429
- const DataPermissionsAddress = getContractAddress(
36624
+ const DataPortabilityPermissionsAddress = getContractAddress(
36430
36625
  chainId,
36431
- "DataPermissions"
36626
+ "DataPortabilityPermissions"
36432
36627
  );
36433
- const DataPermissionsAbi = getAbi("DataPermissions");
36628
+ const DataPortabilityPermissionsAbi = getAbi("DataPortabilityPermissions");
36434
36629
  const permissionInput = {
36435
36630
  nonce: typedData.message.nonce,
36436
36631
  granteeId: typedData.message.granteeId,
@@ -36447,11 +36642,12 @@ var PermissionsController = class {
36447
36642
  "\u{1F50D} Debug - Grant field length:",
36448
36643
  typedData.message.grant?.length || 0
36449
36644
  );
36645
+ const formattedSignature = formatSignatureForContract(signature);
36450
36646
  const txHash = await this.context.walletClient.writeContract({
36451
- address: DataPermissionsAddress,
36452
- abi: DataPermissionsAbi,
36647
+ address: DataPortabilityPermissionsAddress,
36648
+ abi: DataPortabilityPermissionsAbi,
36453
36649
  functionName: "addPermission",
36454
- args: [permissionInput, signature],
36650
+ args: [permissionInput, formattedSignature],
36455
36651
  account: this.context.walletClient.account || await this.getUserAddress(),
36456
36652
  chain: this.context.walletClient.chain || null
36457
36653
  });
@@ -36510,14 +36706,16 @@ var PermissionsController = class {
36510
36706
  throw new BlockchainError("Chain ID not available");
36511
36707
  }
36512
36708
  const chainId = await this.context.walletClient.getChainId();
36513
- const DataPermissionsAddress = getContractAddress(
36709
+ const DataPortabilityPermissionsAddress = getContractAddress(
36514
36710
  chainId,
36515
- "DataPermissions"
36711
+ "DataPortabilityPermissions"
36712
+ );
36713
+ const DataPortabilityPermissionsAbi = getAbi(
36714
+ "DataPortabilityPermissions"
36516
36715
  );
36517
- const DataPermissionsAbi = getAbi("DataPermissions");
36518
36716
  const txHash = await this.context.walletClient.writeContract({
36519
- address: DataPermissionsAddress,
36520
- abi: DataPermissionsAbi,
36717
+ address: DataPortabilityPermissionsAddress,
36718
+ abi: DataPortabilityPermissionsAbi,
36521
36719
  functionName: "revokePermission",
36522
36720
  args: [params.permissionId],
36523
36721
  account: this.context.walletClient.account || await this.getUserAddress(),
@@ -36548,12 +36746,12 @@ var PermissionsController = class {
36548
36746
  * @throws {RelayerError} When gasless submission fails
36549
36747
  * @throws {PermissionError} When revocation fails for any other reason
36550
36748
  */
36551
- async revokeWithSignature(params) {
36749
+ async submitRevokeWithSignature(params) {
36552
36750
  try {
36553
36751
  if (!this.context.walletClient.chain?.id) {
36554
36752
  throw new BlockchainError("Chain ID not available");
36555
36753
  }
36556
- const nonce = await this.getUserNonce();
36754
+ const nonce = await this.getPermissionsUserNonce();
36557
36755
  const revokePermissionInput = {
36558
36756
  nonce,
36559
36757
  permissionId: params.permissionId
@@ -36586,7 +36784,10 @@ var PermissionsController = class {
36586
36784
  }
36587
36785
  }
36588
36786
  /**
36787
+ * @deprecated Use getPermissionsUserNonce() for permission operations or getServersUserNonce() for server operations
36788
+ *
36589
36789
  * Retrieves the user's current nonce from the DataPortabilityServers contract.
36790
+ * This method is deprecated in favor of more specific nonce methods.
36590
36791
  *
36591
36792
  * The nonce is used to prevent replay attacks in signed transactions and must
36592
36793
  * be incremented with each transaction to maintain security.
@@ -36598,22 +36799,26 @@ var PermissionsController = class {
36598
36799
  * @private
36599
36800
  * @example
36600
36801
  * ```typescript
36802
+ * // Deprecated - use specific methods instead
36601
36803
  * const nonce = await this.getUserNonce();
36602
- * console.log(`Current nonce: ${nonce}`);
36804
+ *
36805
+ * // Use these instead:
36806
+ * const permissionsNonce = await this.getPermissionsUserNonce();
36807
+ * const serversNonce = await this.getServersUserNonce();
36603
36808
  * ```
36604
36809
  */
36605
36810
  async getUserNonce() {
36606
36811
  try {
36607
36812
  const userAddress = await this.getUserAddress();
36608
36813
  const chainId = await this.context.walletClient.getChainId();
36609
- const DataPermissionsAddress = getContractAddress(
36814
+ const DataPortabilityServersAddress = getContractAddress(
36610
36815
  chainId,
36611
- "DataPermissions"
36816
+ "DataPortabilityServers"
36612
36817
  );
36613
- const DataPermissionsAbi = getAbi("DataPermissions");
36818
+ const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
36614
36819
  const nonce = await this.context.publicClient.readContract({
36615
- address: DataPermissionsAddress,
36616
- abi: DataPermissionsAbi,
36820
+ address: DataPortabilityServersAddress,
36821
+ abi: DataPortabilityServersAbi,
36617
36822
  functionName: "userNonce",
36618
36823
  args: [userAddress]
36619
36824
  });
@@ -36624,6 +36829,80 @@ var PermissionsController = class {
36624
36829
  );
36625
36830
  }
36626
36831
  }
36832
+ /**
36833
+ * Retrieves the user's current nonce from the DataPortabilityServers contract.
36834
+ * This nonce is used for server-related operations (AddAndTrustServer, TrustServer, UntrustServer).
36835
+ *
36836
+ * @returns Promise resolving to the current servers nonce
36837
+ * @throws {NonceError} When reading nonce from contract fails
36838
+ * @private
36839
+ *
36840
+ * @example
36841
+ * ```typescript
36842
+ * const nonce = await this.getServersUserNonce();
36843
+ * console.log(`Current servers nonce: ${nonce}`);
36844
+ * ```
36845
+ */
36846
+ async getServersUserNonce() {
36847
+ try {
36848
+ const userAddress = await this.getUserAddress();
36849
+ const chainId = await this.context.walletClient.getChainId();
36850
+ const DataPortabilityServersAddress = getContractAddress(
36851
+ chainId,
36852
+ "DataPortabilityServers"
36853
+ );
36854
+ const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
36855
+ const [nonce] = await this.context.publicClient.readContract({
36856
+ address: DataPortabilityServersAddress,
36857
+ abi: DataPortabilityServersAbi,
36858
+ functionName: "users",
36859
+ args: [userAddress]
36860
+ });
36861
+ return nonce;
36862
+ } catch (error) {
36863
+ throw new NonceError(
36864
+ `Failed to retrieve server nonce: ${error instanceof Error ? error.message : "Unknown error"}`
36865
+ );
36866
+ }
36867
+ }
36868
+ /**
36869
+ * Retrieves the user's current nonce from the DataPortabilityPermissions contract.
36870
+ * This nonce is used for permission-related operations (addPermission, addServerFilesAndPermissions).
36871
+ *
36872
+ * @returns Promise resolving to the current permissions nonce
36873
+ * @throws {NonceError} When reading nonce from contract fails
36874
+ * @private
36875
+ *
36876
+ * @example
36877
+ * ```typescript
36878
+ * const nonce = await this.getPermissionsUserNonce();
36879
+ * console.log(`Current permissions nonce: ${nonce}`);
36880
+ * ```
36881
+ */
36882
+ async getPermissionsUserNonce() {
36883
+ try {
36884
+ const userAddress = await this.getUserAddress();
36885
+ const chainId = await this.context.walletClient.getChainId();
36886
+ const DataPortabilityPermissionsAddress = getContractAddress(
36887
+ chainId,
36888
+ "DataPortabilityPermissions"
36889
+ );
36890
+ const DataPortabilityPermissionsAbi = getAbi(
36891
+ "DataPortabilityPermissions"
36892
+ );
36893
+ const nonce = await this.context.publicClient.readContract({
36894
+ address: DataPortabilityPermissionsAddress,
36895
+ abi: DataPortabilityPermissionsAbi,
36896
+ functionName: "userNonce",
36897
+ args: [userAddress]
36898
+ });
36899
+ return nonce;
36900
+ } catch (error) {
36901
+ throw new NonceError(
36902
+ `Failed to retrieve permissions nonce: ${error instanceof Error ? error.message : "Unknown error"}`
36903
+ );
36904
+ }
36905
+ }
36627
36906
  /**
36628
36907
  * Composes the EIP-712 typed data for PermissionGrant (new simplified format).
36629
36908
  *
@@ -36682,6 +36961,66 @@ var PermissionsController = class {
36682
36961
  }
36683
36962
  };
36684
36963
  }
36964
+ /**
36965
+ * Creates EIP-712 typed data structure for server files and permissions.
36966
+ *
36967
+ * @param params - Parameters for the server files and permissions message
36968
+ * @param params.granteeId - Grantee ID
36969
+ * @param params.grant - Grant URL or grant data
36970
+ * @param params.fileUrls - Array of file URLs
36971
+ * @param params.serverAddress - Server address
36972
+ * @param params.serverUrl - Server URL
36973
+ * @param params.serverPublicKey - Server public key
36974
+ * @param params.filePermissions - File permissions array
36975
+ * @param params.nonce - Unique number to prevent replay attacks
36976
+ * @returns Promise resolving to the typed data structure
36977
+ */
36978
+ async composeServerFilesAndPermissionMessage(params) {
36979
+ const domain = await this.getPermissionDomain();
36980
+ console.debug(
36981
+ "\u{1F50D} Debug - Composing server files and permission message with grant:",
36982
+ params.grant
36983
+ );
36984
+ if (!params.grant.startsWith("ipfs://") && params.grant.includes("/ipfs/")) {
36985
+ const { extractIpfsHash: extractIpfsHash2 } = await Promise.resolve().then(() => (init_ipfs(), ipfs_exports));
36986
+ const hash = extractIpfsHash2(params.grant);
36987
+ if (hash) {
36988
+ console.warn(
36989
+ `\u26A0\uFE0F Storing HTTP gateway URL on-chain instead of ipfs:// protocol. Found: ${params.grant}. Consider using ipfs://${hash} for better protocol-agnostic on-chain storage.`
36990
+ );
36991
+ }
36992
+ }
36993
+ return {
36994
+ domain,
36995
+ types: {
36996
+ Permission: [
36997
+ { name: "account", type: "address" },
36998
+ { name: "key", type: "string" }
36999
+ ],
37000
+ ServerFilesAndPermission: [
37001
+ { name: "nonce", type: "uint256" },
37002
+ { name: "granteeId", type: "uint256" },
37003
+ { name: "grant", type: "string" },
37004
+ { name: "fileUrls", type: "string[]" },
37005
+ { name: "serverAddress", type: "address" },
37006
+ { name: "serverUrl", type: "string" },
37007
+ { name: "serverPublicKey", type: "string" },
37008
+ { name: "filePermissions", type: "Permission[][]" }
37009
+ ]
37010
+ },
37011
+ primaryType: "ServerFilesAndPermission",
37012
+ message: {
37013
+ nonce: params.nonce,
37014
+ granteeId: params.granteeId,
37015
+ grant: params.grant,
37016
+ fileUrls: params.fileUrls,
37017
+ serverAddress: params.serverAddress,
37018
+ serverUrl: params.serverUrl,
37019
+ serverPublicKey: params.serverPublicKey,
37020
+ filePermissions: params.filePermissions
37021
+ }
37022
+ };
37023
+ }
36685
37024
  /**
36686
37025
  * Gets the EIP-712 domain for PermissionGrant signatures.
36687
37026
  *
@@ -36689,15 +37028,15 @@ var PermissionsController = class {
36689
37028
  */
36690
37029
  async getPermissionDomain() {
36691
37030
  const chainId = await this.context.walletClient.getChainId();
36692
- const DataPermissionsAddress = getContractAddress(
37031
+ const DataPortabilityPermissionsAddress = getContractAddress(
36693
37032
  chainId,
36694
- "DataPermissions"
37033
+ "DataPortabilityPermissions"
36695
37034
  );
36696
37035
  return {
36697
37036
  name: "VanaDataPortabilityPermissions",
36698
37037
  version: "1",
36699
37038
  chainId,
36700
- verifyingContract: DataPermissionsAddress
37039
+ verifyingContract: DataPortabilityPermissionsAddress
36701
37040
  };
36702
37041
  }
36703
37042
  /**
@@ -36714,9 +37053,13 @@ var PermissionsController = class {
36714
37053
  walletAddress,
36715
37054
  typedData,
36716
37055
  async () => {
36717
- return await this.context.walletClient.signTypedData(
36718
- typedData
36719
- );
37056
+ const viemCompatibleTypedData = toViemTypedDataDefinition(typedData);
37057
+ return await this.context.walletClient.signTypedData({
37058
+ ...viemCompatibleTypedData,
37059
+ // Non-null assertion is safe here because getUserAddress() above ensures account exists
37060
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
37061
+ account: this.context.walletClient.account
37062
+ });
36720
37063
  }
36721
37064
  );
36722
37065
  } catch (error) {
@@ -36863,122 +37206,6 @@ var PermissionsController = class {
36863
37206
  );
36864
37207
  }
36865
37208
  }
36866
- /**
36867
- * Gets all permission IDs for a specific file.
36868
- *
36869
- * @param fileId - The file ID to query permissions for
36870
- * @returns Promise resolving to array of permission IDs
36871
- * @throws {BlockchainError} When reading from contract fails or chain is unavailable
36872
- */
36873
- async getFilePermissionIds(fileId) {
36874
- try {
36875
- const chainId = await this.context.walletClient.getChainId();
36876
- const DataPermissionsAddress = getContractAddress(
36877
- chainId,
36878
- "DataPermissions"
36879
- );
36880
- const DataPermissionsAbi = getAbi("DataPermissions");
36881
- const permissionIds = await this.context.publicClient.readContract({
36882
- address: DataPermissionsAddress,
36883
- abi: DataPermissionsAbi,
36884
- functionName: "filePermissionIds",
36885
- args: [fileId]
36886
- });
36887
- return permissionIds;
36888
- } catch (error) {
36889
- throw new BlockchainError(
36890
- `Failed to get file permission IDs: ${error instanceof Error ? error.message : "Unknown error"}`,
36891
- error
36892
- );
36893
- }
36894
- }
36895
- /**
36896
- * Gets all file IDs associated with a permission.
36897
- *
36898
- * @param permissionId - The permission ID to query files for
36899
- * @returns Promise resolving to array of file IDs
36900
- * @throws {BlockchainError} When reading from contract fails or chain is unavailable
36901
- */
36902
- async getPermissionFileIds(permissionId) {
36903
- try {
36904
- const chainId = await this.context.walletClient.getChainId();
36905
- const DataPermissionsAddress = getContractAddress(
36906
- chainId,
36907
- "DataPermissions"
36908
- );
36909
- const DataPermissionsAbi = getAbi("DataPermissions");
36910
- const fileIds = await this.context.publicClient.readContract({
36911
- address: DataPermissionsAddress,
36912
- abi: DataPermissionsAbi,
36913
- functionName: "permissionFileIds",
36914
- args: [permissionId]
36915
- });
36916
- return fileIds;
36917
- } catch (error) {
36918
- throw new BlockchainError(
36919
- `Failed to get permission file IDs: ${error instanceof Error ? error.message : "Unknown error"}`,
36920
- error
36921
- );
36922
- }
36923
- }
36924
- /**
36925
- * Checks if a permission is active.
36926
- *
36927
- * @param permissionId - The permission ID to check
36928
- * @returns Promise resolving to boolean indicating if permission is active
36929
- * @throws {BlockchainError} When reading from contract fails or chain is unavailable
36930
- */
36931
- async isActivePermission(permissionId) {
36932
- try {
36933
- const chainId = await this.context.walletClient.getChainId();
36934
- const DataPermissionsAddress = getContractAddress(
36935
- chainId,
36936
- "DataPermissions"
36937
- );
36938
- const DataPermissionsAbi = getAbi("DataPermissions");
36939
- const isActive = await this.context.publicClient.readContract({
36940
- address: DataPermissionsAddress,
36941
- abi: DataPermissionsAbi,
36942
- functionName: "isActivePermission",
36943
- args: [permissionId]
36944
- });
36945
- return isActive;
36946
- } catch (error) {
36947
- throw new BlockchainError(
36948
- `Failed to check permission status: ${error instanceof Error ? error.message : "Unknown error"}`,
36949
- error
36950
- );
36951
- }
36952
- }
36953
- /**
36954
- * Gets permission details from the contract.
36955
- *
36956
- * @param permissionId - The permission ID to query
36957
- * @returns Promise resolving to permission info
36958
- * @throws {BlockchainError} When reading from contract fails or chain is unavailable
36959
- */
36960
- async getPermissionInfo(permissionId) {
36961
- try {
36962
- const chainId = await this.context.walletClient.getChainId();
36963
- const DataPermissionsAddress = getContractAddress(
36964
- chainId,
36965
- "DataPermissions"
36966
- );
36967
- const DataPermissionsAbi = getAbi("DataPermissions");
36968
- const permissionInfo = await this.context.publicClient.readContract({
36969
- address: DataPermissionsAddress,
36970
- abi: DataPermissionsAbi,
36971
- functionName: "permissions",
36972
- args: [permissionId]
36973
- });
36974
- return permissionInfo;
36975
- } catch (error) {
36976
- throw new BlockchainError(
36977
- `Failed to get permission info: ${error instanceof Error ? error.message : "Unknown error"}`,
36978
- error
36979
- );
36980
- }
36981
- }
36982
37209
  /**
36983
37210
  * Normalizes grant ID to hex format.
36984
37211
  * Handles conversion from permission ID (bigint/number/string) to proper hex hash format.
@@ -37041,13 +37268,14 @@ var PermissionsController = class {
37041
37268
  "DataPortabilityServers"
37042
37269
  );
37043
37270
  const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
37271
+ const userAddress = this.context.walletClient.account?.address || await this.getUserAddress();
37044
37272
  const txHash = await this.context.walletClient.writeContract({
37045
37273
  address: DataPortabilityServersAddress,
37046
37274
  abi: DataPortabilityServersAbi,
37047
- functionName: "addAndTrustServer",
37275
+ functionName: "addAndTrustServerOnBehalf",
37048
37276
  args: [
37277
+ userAddress,
37049
37278
  {
37050
- owner: params.owner,
37051
37279
  serverAddress: params.serverAddress,
37052
37280
  serverUrl: params.serverUrl,
37053
37281
  publicKey: params.publicKey
@@ -37074,7 +37302,7 @@ var PermissionsController = class {
37074
37302
  * @returns Promise resolving to transaction hash
37075
37303
  * @deprecated Use addAndTrustServer instead
37076
37304
  */
37077
- async trustServer(params) {
37305
+ async submitTrustServer(params) {
37078
37306
  try {
37079
37307
  const chainId = await this.context.walletClient.getChainId();
37080
37308
  const DataPortabilityServersAddress = getContractAddress(
@@ -37107,12 +37335,11 @@ var PermissionsController = class {
37107
37335
  * @param params - Parameters for adding and trusting the server
37108
37336
  * @returns Promise resolving to transaction hash
37109
37337
  */
37110
- async addAndTrustServerWithSignature(params) {
37338
+ async submitAddAndTrustServerWithSignature(params) {
37111
37339
  try {
37112
- const nonce = await this.getUserNonce();
37340
+ const nonce = await this.getServersUserNonce();
37113
37341
  const addAndTrustServerInput = {
37114
37342
  nonce,
37115
- owner: params.owner,
37116
37343
  serverAddress: params.serverAddress,
37117
37344
  publicKey: params.publicKey,
37118
37345
  serverUrl: params.serverUrl
@@ -37122,16 +37349,13 @@ var PermissionsController = class {
37122
37349
  );
37123
37350
  console.debug("\u{1F50D} AddAndTrustServer Debug Info:", {
37124
37351
  nonce: nonce.toString(),
37125
- owner: params.owner,
37126
37352
  serverAddress: params.serverAddress,
37127
37353
  publicKey: params.publicKey,
37128
37354
  serverUrl: params.serverUrl,
37129
37355
  domain: typedData.domain,
37130
37356
  typedDataMessage: typedData.message
37131
37357
  });
37132
- const signature = await this.signTypedData(
37133
- typedData
37134
- );
37358
+ const signature = await this.signTypedData(typedData);
37135
37359
  console.debug("\u{1F50D} Generated signature:", signature);
37136
37360
  if (this.context.relayerCallbacks?.submitAddAndTrustServer) {
37137
37361
  return await this.context.relayerCallbacks.submitAddAndTrustServer(
@@ -37172,17 +37396,15 @@ var PermissionsController = class {
37172
37396
  * @throws {ServerUrlMismatchError} When server URL doesn't match existing registration
37173
37397
  * @throws {BlockchainError} When trust operation fails for any other reason
37174
37398
  */
37175
- async trustServerWithSignature(params) {
37399
+ async submitTrustServerWithSignature(params) {
37176
37400
  try {
37177
- const nonce = await this.getUserNonce();
37401
+ const nonce = await this.getServersUserNonce();
37178
37402
  const trustServerInput = {
37179
37403
  nonce,
37180
37404
  serverId: params.serverId
37181
37405
  };
37182
37406
  const typedData = await this.composeTrustServerMessage(trustServerInput);
37183
- const signature = await this.signTypedData(
37184
- typedData
37185
- );
37407
+ const signature = await this.signTypedData(typedData);
37186
37408
  if (this.context.relayerCallbacks?.submitTrustServer) {
37187
37409
  return await this.context.relayerCallbacks.submitTrustServer(
37188
37410
  typedData,
@@ -37268,8 +37490,8 @@ var PermissionsController = class {
37268
37490
  * console.log('Still trusting servers:', trustedServers);
37269
37491
  * ```
37270
37492
  */
37271
- async untrustServer(params) {
37272
- const nonce = await this.getUserNonce();
37493
+ async submitUntrustServer(params) {
37494
+ const nonce = await this.getServersUserNonce();
37273
37495
  const untrustServerInput = {
37274
37496
  nonce,
37275
37497
  serverId: params.serverId
@@ -37288,27 +37510,22 @@ var PermissionsController = class {
37288
37510
  * @throws {RelayerError} When gasless submission fails
37289
37511
  * @throws {BlockchainError} When untrust transaction fails
37290
37512
  */
37291
- async untrustServerWithSignature(params) {
37513
+ async submitUntrustServerWithSignature(params) {
37292
37514
  try {
37293
- const nonce = await this.getUserNonce();
37515
+ const nonce = await this.getServersUserNonce();
37294
37516
  const untrustServerInput = {
37295
37517
  nonce,
37296
37518
  serverId: params.serverId
37297
37519
  };
37298
37520
  const typedData = await this.composeUntrustServerMessage(untrustServerInput);
37299
- const signature = await this.signTypedData(
37300
- typedData
37301
- );
37521
+ const signature = await this.signTypedData(typedData);
37302
37522
  if (this.context.relayerCallbacks?.submitUntrustServer) {
37303
37523
  return await this.context.relayerCallbacks.submitUntrustServer(
37304
37524
  typedData,
37305
37525
  signature
37306
37526
  );
37307
37527
  } else {
37308
- return await this.submitSignedUntrustTransaction(
37309
- typedData,
37310
- signature
37311
- );
37528
+ return await this.submitSignedUntrustTransaction(typedData, signature);
37312
37529
  }
37313
37530
  } catch (error) {
37314
37531
  if (error instanceof Error) {
@@ -37368,131 +37585,6 @@ var PermissionsController = class {
37368
37585
  );
37369
37586
  }
37370
37587
  }
37371
- /**
37372
- * Retrieves detailed information about a specific server from the DataPortabilityServers contract.
37373
- *
37374
- * Returns complete server information including owner, address, public key, and URL.
37375
- * This information is used to establish secure connections and verify server identity.
37376
- *
37377
- * @param serverId - The unique numeric ID of the server to query
37378
- * @returns Promise resolving to complete server information
37379
- * @throws {BlockchainError} When reading from contract fails or chain is unavailable
37380
- * @throws {NetworkError} When unable to connect to the blockchain network
37381
- * @throws {ServerNotFoundError} When the server ID does not exist
37382
- *
37383
- * @example
37384
- * ```typescript
37385
- * const server = await vana.permissions.getServerInfo(1);
37386
- *
37387
- * console.log(`Server ${server.id}:`);
37388
- * console.log(` Owner: ${server.owner}`);
37389
- * console.log(` Address: ${server.serverAddress}`);
37390
- * console.log(` URL: ${server.url}`);
37391
- * console.log(` Public Key: ${server.publicKey}`);
37392
- * ```
37393
- */
37394
- async getServerInfo(serverId) {
37395
- try {
37396
- const chainId = await this.context.walletClient.getChainId();
37397
- const DataPortabilityServersAddress = getContractAddress(
37398
- chainId,
37399
- "DataPortabilityServers"
37400
- );
37401
- const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
37402
- const serverInfo = await this.context.publicClient.readContract({
37403
- address: DataPortabilityServersAddress,
37404
- abi: DataPortabilityServersAbi,
37405
- functionName: "servers",
37406
- args: [BigInt(serverId)]
37407
- });
37408
- return {
37409
- id: Number(serverInfo.id),
37410
- owner: serverInfo.owner,
37411
- url: serverInfo.url,
37412
- serverAddress: serverInfo.serverAddress,
37413
- publicKey: serverInfo.publicKey
37414
- };
37415
- } catch (error) {
37416
- throw new BlockchainError(
37417
- `Failed to get server info: ${error instanceof Error ? error.message : "Unknown error"}`,
37418
- error
37419
- );
37420
- }
37421
- }
37422
- /**
37423
- * Checks if a specific server is active in the DataPortabilityServers contract.
37424
- *
37425
- * An active server is one that is properly registered and operational, meaning
37426
- * it can receive and process data portability requests from users.
37427
- *
37428
- * @param serverId - The unique numeric ID of the server to check
37429
- * @returns Promise resolving to true if server is active, false otherwise
37430
- * @throws {BlockchainError} When reading from contract fails or chain is unavailable
37431
- * @throws {NetworkError} When unable to connect to the blockchain network
37432
- *
37433
- * @example
37434
- * ```typescript
37435
- * const isActive = await vana.permissions.isActiveServer(1);
37436
- *
37437
- * if (isActive) {
37438
- * console.log('Server 1 is active and ready to process requests');
37439
- * } else {
37440
- * console.log('Server 1 is inactive or not found');
37441
- * }
37442
- * ```
37443
- */
37444
- async isActiveServer(serverId) {
37445
- try {
37446
- const chainId = await this.context.walletClient.getChainId();
37447
- const DataPortabilityServersAddress = getContractAddress(
37448
- chainId,
37449
- "DataPortabilityServers"
37450
- );
37451
- const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
37452
- const isActive = await this.context.publicClient.readContract({
37453
- address: DataPortabilityServersAddress,
37454
- abi: DataPortabilityServersAbi,
37455
- functionName: "isActiveServer",
37456
- args: [BigInt(serverId)]
37457
- });
37458
- return isActive;
37459
- } catch (error) {
37460
- throw new BlockchainError(
37461
- `Failed to check server status: ${error instanceof Error ? error.message : "Unknown error"}`,
37462
- error
37463
- );
37464
- }
37465
- }
37466
- /**
37467
- * Checks if a server is active for a specific user.
37468
- *
37469
- * @param serverId - Server ID (numeric)
37470
- * @param userAddress - Optional user address (defaults to current user)
37471
- * @returns Promise resolving to boolean indicating if server is active for the user
37472
- */
37473
- async isActiveServerForUser(serverId, userAddress) {
37474
- try {
37475
- const user = userAddress || await this.getUserAddress();
37476
- const chainId = await this.context.walletClient.getChainId();
37477
- const DataPortabilityServersAddress = getContractAddress(
37478
- chainId,
37479
- "DataPortabilityServers"
37480
- );
37481
- const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
37482
- const isActive = await this.context.publicClient.readContract({
37483
- address: DataPortabilityServersAddress,
37484
- abi: DataPortabilityServersAbi,
37485
- functionName: "isActiveServerForUser",
37486
- args: [user, BigInt(serverId)]
37487
- });
37488
- return isActive;
37489
- } catch (error) {
37490
- throw new BlockchainError(
37491
- `Failed to check server status for user: ${error instanceof Error ? error.message : "Unknown error"}`,
37492
- error
37493
- );
37494
- }
37495
- }
37496
37588
  /**
37497
37589
  * Gets the total count of trusted servers for a user.
37498
37590
  *
@@ -37595,27 +37687,29 @@ var PermissionsController = class {
37595
37687
  try {
37596
37688
  const paginatedResult = await this.getTrustedServersPaginated(options);
37597
37689
  const serverInfoPromises = paginatedResult.servers.map(
37598
- async (serverId, index) => {
37690
+ async (serverId, _index) => {
37599
37691
  try {
37600
- const serverInfo = await this.getServerInfo(serverId);
37692
+ const serverInfo = await this.getServerInfo(BigInt(serverId));
37601
37693
  return {
37602
- serverId,
37694
+ id: BigInt(serverId),
37603
37695
  owner: serverInfo.owner,
37604
- url: serverInfo.url,
37605
37696
  serverAddress: serverInfo.serverAddress,
37606
37697
  publicKey: serverInfo.publicKey,
37607
- isTrusted: true,
37608
- trustIndex: options.offset ? options.offset + index : index
37698
+ url: serverInfo.url,
37699
+ startBlock: 0n,
37700
+ // We don't have this info from the old method structure
37701
+ endBlock: 0n
37702
+ // 0 means still active
37609
37703
  };
37610
37704
  } catch {
37611
37705
  return {
37612
- serverId,
37706
+ id: BigInt(serverId),
37613
37707
  owner: "0x0000000000000000000000000000000000000000",
37614
- url: "",
37615
37708
  serverAddress: "0x0000000000000000000000000000000000000000",
37616
37709
  publicKey: "",
37617
- isTrusted: true,
37618
- trustIndex: options.offset ? options.offset + index : index
37710
+ url: "",
37711
+ startBlock: 0n,
37712
+ endBlock: 0n
37619
37713
  };
37620
37714
  }
37621
37715
  }
@@ -37721,18 +37815,18 @@ var PermissionsController = class {
37721
37815
  */
37722
37816
  async composeAddAndTrustServerMessage(input) {
37723
37817
  const domain = await this.getServersDomain();
37818
+ console.debug(domain);
37724
37819
  return {
37725
37820
  domain,
37726
37821
  types: {
37727
- AddAndTrustServer: [
37822
+ AddServer: [
37728
37823
  { name: "nonce", type: "uint256" },
37729
- { name: "owner", type: "address" },
37730
37824
  { name: "serverAddress", type: "address" },
37731
- { name: "publicKey", type: "bytes" },
37825
+ { name: "publicKey", type: "string" },
37732
37826
  { name: "serverUrl", type: "string" }
37733
37827
  ]
37734
37828
  },
37735
- primaryType: "AddAndTrustServer",
37829
+ primaryType: "AddServer",
37736
37830
  message: input
37737
37831
  };
37738
37832
  }
@@ -37813,13 +37907,13 @@ var PermissionsController = class {
37813
37907
  contractAddress: DataPortabilityServersAddress,
37814
37908
  input: {
37815
37909
  nonce: addAndTrustServerInput.nonce.toString(),
37816
- owner: addAndTrustServerInput.owner,
37817
37910
  serverAddress: addAndTrustServerInput.serverAddress,
37818
37911
  publicKey: addAndTrustServerInput.publicKey,
37819
37912
  serverUrl: addAndTrustServerInput.serverUrl
37820
37913
  },
37821
37914
  signature
37822
37915
  });
37916
+ const formattedSignature = formatSignatureForContract(signature);
37823
37917
  const txHash = await this.context.walletClient.writeContract({
37824
37918
  address: DataPortabilityServersAddress,
37825
37919
  abi: DataPortabilityServersAbi,
@@ -37827,12 +37921,11 @@ var PermissionsController = class {
37827
37921
  args: [
37828
37922
  {
37829
37923
  nonce: addAndTrustServerInput.nonce,
37830
- owner: addAndTrustServerInput.owner,
37831
37924
  serverAddress: addAndTrustServerInput.serverAddress,
37832
37925
  publicKey: addAndTrustServerInput.publicKey,
37833
37926
  serverUrl: addAndTrustServerInput.serverUrl
37834
37927
  },
37835
- signature
37928
+ formattedSignature
37836
37929
  ],
37837
37930
  account: this.context.walletClient.account || await this.getUserAddress(),
37838
37931
  chain: this.context.walletClient.chain || null
@@ -37853,6 +37946,7 @@ var PermissionsController = class {
37853
37946
  "DataPortabilityServers"
37854
37947
  );
37855
37948
  const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
37949
+ const formattedSignature = formatSignatureForContract(signature);
37856
37950
  const txHash = await this.context.walletClient.writeContract({
37857
37951
  address: DataPortabilityServersAddress,
37858
37952
  abi: DataPortabilityServersAbi,
@@ -37862,7 +37956,7 @@ var PermissionsController = class {
37862
37956
  nonce: trustServerInput.nonce,
37863
37957
  serverId: BigInt(trustServerInput.serverId)
37864
37958
  },
37865
- signature
37959
+ formattedSignature
37866
37960
  ],
37867
37961
  account: this.context.walletClient.account || await this.getUserAddress(),
37868
37962
  chain: this.context.walletClient.chain || null
@@ -37878,17 +37972,18 @@ var PermissionsController = class {
37878
37972
  */
37879
37973
  async submitDirectRevokeTransaction(typedData, signature) {
37880
37974
  const chainId = await this.context.walletClient.getChainId();
37881
- const DataPermissionsAddress = getContractAddress(
37975
+ const DataPortabilityPermissionsAddress = getContractAddress(
37882
37976
  chainId,
37883
- "DataPermissions"
37977
+ "DataPortabilityPermissions"
37884
37978
  );
37885
- const DataPermissionsAbi = getAbi("DataPermissions");
37979
+ const DataPortabilityPermissionsAbi = getAbi("DataPortabilityPermissions");
37980
+ const formattedSignature = formatSignatureForContract(signature);
37886
37981
  const txHash = await this.context.walletClient.writeContract({
37887
- address: DataPermissionsAddress,
37888
- abi: DataPermissionsAbi,
37982
+ address: DataPortabilityPermissionsAddress,
37983
+ abi: DataPortabilityPermissionsAbi,
37889
37984
  functionName: "revokePermissionWithSignature",
37890
37985
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
37891
- args: [typedData.message, signature],
37986
+ args: [typedData.message, formattedSignature],
37892
37987
  account: this.context.walletClient.account || await this.getUserAddress(),
37893
37988
  chain: this.context.walletClient.chain || null
37894
37989
  });
@@ -37908,12 +38003,13 @@ var PermissionsController = class {
37908
38003
  "DataPortabilityServers"
37909
38004
  );
37910
38005
  const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
38006
+ const formattedSignature = formatSignatureForContract(signature);
37911
38007
  const txHash = await this.context.walletClient.writeContract({
37912
38008
  address: DataPortabilityServersAddress,
37913
38009
  abi: DataPortabilityServersAbi,
37914
38010
  functionName: "untrustServerWithSignature",
37915
38011
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
37916
- args: [typedData.message, signature],
38012
+ args: [typedData.message, formattedSignature],
37917
38013
  account: this.context.walletClient.account || await this.getUserAddress(),
37918
38014
  chain: this.context.walletClient.chain || null
37919
38015
  });
@@ -37947,7 +38043,7 @@ var PermissionsController = class {
37947
38043
  * console.log(`Grantee registered in transaction: ${txHash}`);
37948
38044
  * ```
37949
38045
  */
37950
- async registerGrantee(params) {
38046
+ async submitRegisterGrantee(params) {
37951
38047
  const chainId = await this.context.walletClient.getChainId();
37952
38048
  const DataPortabilityGranteesAddress = getContractAddress(
37953
38049
  chainId,
@@ -37979,8 +38075,8 @@ var PermissionsController = class {
37979
38075
  * });
37980
38076
  * ```
37981
38077
  */
37982
- async registerGranteeWithSignature(params) {
37983
- const nonce = await this.getUserNonce();
38078
+ async submitRegisterGranteeWithSignature(params) {
38079
+ const nonce = await this.getServersUserNonce();
37984
38080
  const registerGranteeInput = {
37985
38081
  nonce,
37986
38082
  owner: params.owner,
@@ -38253,10 +38349,1192 @@ var PermissionsController = class {
38253
38349
  });
38254
38350
  return txHash;
38255
38351
  }
38352
+ // ===========================
38353
+ // DATA PORTABILITY SERVERS HELPER METHODS
38354
+ // ===========================
38355
+ /**
38356
+ * Get all trusted server IDs for a user
38357
+ *
38358
+ * @param userAddress - User address to query (defaults to current user)
38359
+ * @returns Promise resolving to array of server IDs
38360
+ */
38361
+ async getUserServerIds(userAddress) {
38362
+ try {
38363
+ const targetAddress = userAddress || await this.getUserAddress();
38364
+ const chainId = await this.context.publicClient.getChainId();
38365
+ const DataPortabilityServersAddress = getContractAddress(
38366
+ chainId,
38367
+ "DataPortabilityServers"
38368
+ );
38369
+ const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
38370
+ const serverIds = await this.context.publicClient.readContract({
38371
+ address: DataPortabilityServersAddress,
38372
+ abi: DataPortabilityServersAbi,
38373
+ functionName: "userServerIdsValues",
38374
+ args: [targetAddress]
38375
+ });
38376
+ return [...serverIds];
38377
+ } catch (error) {
38378
+ throw new BlockchainError(
38379
+ `Failed to get user server IDs: ${error instanceof Error ? error.message : "Unknown error"}`,
38380
+ error
38381
+ );
38382
+ }
38383
+ }
38384
+ /**
38385
+ * Get server ID at specific index for a user
38386
+ *
38387
+ * @param userAddress - User address to query
38388
+ * @param serverIndex - Index in the user's server list
38389
+ * @returns Promise resolving to server ID
38390
+ */
38391
+ async getUserServerIdAt(userAddress, serverIndex) {
38392
+ try {
38393
+ const chainId = await this.context.publicClient.getChainId();
38394
+ const DataPortabilityServersAddress = getContractAddress(
38395
+ chainId,
38396
+ "DataPortabilityServers"
38397
+ );
38398
+ const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
38399
+ const serverId = await this.context.publicClient.readContract({
38400
+ address: DataPortabilityServersAddress,
38401
+ abi: DataPortabilityServersAbi,
38402
+ functionName: "userServerIdsAt",
38403
+ args: [userAddress, serverIndex]
38404
+ });
38405
+ return serverId;
38406
+ } catch (error) {
38407
+ throw new BlockchainError(
38408
+ `Failed to get user server ID at index: ${error instanceof Error ? error.message : "Unknown error"}`,
38409
+ error
38410
+ );
38411
+ }
38412
+ }
38413
+ /**
38414
+ * Get the number of trusted servers for a user
38415
+ *
38416
+ * @param userAddress - User address to query (defaults to current user)
38417
+ * @returns Promise resolving to number of trusted servers
38418
+ */
38419
+ async getUserServerCount(userAddress) {
38420
+ try {
38421
+ const targetAddress = userAddress || await this.getUserAddress();
38422
+ const chainId = await this.context.publicClient.getChainId();
38423
+ const DataPortabilityServersAddress = getContractAddress(
38424
+ chainId,
38425
+ "DataPortabilityServers"
38426
+ );
38427
+ const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
38428
+ const count = await this.context.publicClient.readContract({
38429
+ address: DataPortabilityServersAddress,
38430
+ abi: DataPortabilityServersAbi,
38431
+ functionName: "userServerIdsLength",
38432
+ args: [targetAddress]
38433
+ });
38434
+ return count;
38435
+ } catch (error) {
38436
+ throw new BlockchainError(
38437
+ `Failed to get user server count: ${error instanceof Error ? error.message : "Unknown error"}`,
38438
+ error
38439
+ );
38440
+ }
38441
+ }
38442
+ /**
38443
+ * Get detailed information about trusted servers for a user
38444
+ *
38445
+ * @param userAddress - User address to query (defaults to current user)
38446
+ * @returns Promise resolving to array of trusted server info
38447
+ */
38448
+ async getUserTrustedServers(userAddress) {
38449
+ try {
38450
+ const targetAddress = userAddress || await this.getUserAddress();
38451
+ const chainId = await this.context.publicClient.getChainId();
38452
+ const DataPortabilityServersAddress = getContractAddress(
38453
+ chainId,
38454
+ "DataPortabilityServers"
38455
+ );
38456
+ const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
38457
+ const servers = await this.context.publicClient.readContract({
38458
+ address: DataPortabilityServersAddress,
38459
+ abi: DataPortabilityServersAbi,
38460
+ functionName: "userServerValues",
38461
+ args: [targetAddress]
38462
+ });
38463
+ return [...servers];
38464
+ } catch (error) {
38465
+ throw new BlockchainError(
38466
+ `Failed to get user trusted servers: ${error instanceof Error ? error.message : "Unknown error"}`,
38467
+ error
38468
+ );
38469
+ }
38470
+ }
38471
+ /**
38472
+ * Get trusted server info for a specific server ID and user
38473
+ *
38474
+ * @param userAddress - User address to query
38475
+ * @param serverId - Server ID to get info for
38476
+ * @returns Promise resolving to trusted server info
38477
+ */
38478
+ async getUserTrustedServer(userAddress, serverId) {
38479
+ try {
38480
+ const chainId = await this.context.publicClient.getChainId();
38481
+ const DataPortabilityServersAddress = getContractAddress(
38482
+ chainId,
38483
+ "DataPortabilityServers"
38484
+ );
38485
+ const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
38486
+ const serverInfo = await this.context.publicClient.readContract({
38487
+ address: DataPortabilityServersAddress,
38488
+ abi: DataPortabilityServersAbi,
38489
+ functionName: "userServers",
38490
+ args: [userAddress, serverId]
38491
+ });
38492
+ return serverInfo;
38493
+ } catch (error) {
38494
+ throw new BlockchainError(
38495
+ `Failed to get user trusted server: ${error instanceof Error ? error.message : "Unknown error"}`,
38496
+ error
38497
+ );
38498
+ }
38499
+ }
38500
+ /**
38501
+ * Get server information by server ID
38502
+ *
38503
+ * @param serverId - Server ID to get info for
38504
+ * @returns Promise resolving to server info
38505
+ */
38506
+ async getServerInfo(serverId) {
38507
+ try {
38508
+ const chainId = await this.context.publicClient.getChainId();
38509
+ const DataPortabilityServersAddress = getContractAddress(
38510
+ chainId,
38511
+ "DataPortabilityServers"
38512
+ );
38513
+ const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
38514
+ const serverInfo = await this.context.publicClient.readContract({
38515
+ address: DataPortabilityServersAddress,
38516
+ abi: DataPortabilityServersAbi,
38517
+ functionName: "servers",
38518
+ args: [serverId]
38519
+ });
38520
+ return serverInfo;
38521
+ } catch (error) {
38522
+ throw new BlockchainError(
38523
+ `Failed to get server info: ${error instanceof Error ? error.message : "Unknown error"}`,
38524
+ error
38525
+ );
38526
+ }
38527
+ }
38528
+ /**
38529
+ * Get server information by server address
38530
+ *
38531
+ * @param serverAddress - Server address to get info for
38532
+ * @returns Promise resolving to server info
38533
+ */
38534
+ async getServerInfoByAddress(serverAddress) {
38535
+ try {
38536
+ const chainId = await this.context.publicClient.getChainId();
38537
+ const DataPortabilityServersAddress = getContractAddress(
38538
+ chainId,
38539
+ "DataPortabilityServers"
38540
+ );
38541
+ const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
38542
+ const serverInfo = await this.context.publicClient.readContract({
38543
+ address: DataPortabilityServersAddress,
38544
+ abi: DataPortabilityServersAbi,
38545
+ functionName: "serverByAddress",
38546
+ args: [serverAddress]
38547
+ });
38548
+ return serverInfo;
38549
+ } catch (error) {
38550
+ throw new BlockchainError(
38551
+ `Failed to get server info by address: ${error instanceof Error ? error.message : "Unknown error"}`,
38552
+ error
38553
+ );
38554
+ }
38555
+ }
38556
+ // ===========================
38557
+ // DATA PORTABILITY PERMISSIONS HELPER METHODS
38558
+ // ===========================
38559
+ /**
38560
+ * Get all permission IDs for a user
38561
+ *
38562
+ * @param userAddress - User address to query (defaults to current user)
38563
+ * @returns Promise resolving to array of permission IDs
38564
+ */
38565
+ async getUserPermissionIds(userAddress) {
38566
+ try {
38567
+ const targetAddress = userAddress || await this.getUserAddress();
38568
+ const chainId = await this.context.publicClient.getChainId();
38569
+ const DataPortabilityPermissionsAddress = getContractAddress(
38570
+ chainId,
38571
+ "DataPortabilityPermissions"
38572
+ );
38573
+ const DataPortabilityPermissionsAbi = getAbi(
38574
+ "DataPortabilityPermissions"
38575
+ );
38576
+ const permissionIds = await this.context.publicClient.readContract({
38577
+ address: DataPortabilityPermissionsAddress,
38578
+ abi: DataPortabilityPermissionsAbi,
38579
+ functionName: "userPermissionIdsValues",
38580
+ args: [targetAddress]
38581
+ });
38582
+ return [...permissionIds];
38583
+ } catch (error) {
38584
+ throw new BlockchainError(
38585
+ `Failed to get user permission IDs: ${error instanceof Error ? error.message : "Unknown error"}`,
38586
+ error
38587
+ );
38588
+ }
38589
+ }
38590
+ /**
38591
+ * Get permission ID at specific index for a user
38592
+ *
38593
+ * @param userAddress - User address to query
38594
+ * @param permissionIndex - Index in the user's permission list
38595
+ * @returns Promise resolving to permission ID
38596
+ */
38597
+ async getUserPermissionIdAt(userAddress, permissionIndex) {
38598
+ try {
38599
+ const chainId = await this.context.publicClient.getChainId();
38600
+ const DataPortabilityPermissionsAddress = getContractAddress(
38601
+ chainId,
38602
+ "DataPortabilityPermissions"
38603
+ );
38604
+ const DataPortabilityPermissionsAbi = getAbi(
38605
+ "DataPortabilityPermissions"
38606
+ );
38607
+ const permissionId = await this.context.publicClient.readContract({
38608
+ address: DataPortabilityPermissionsAddress,
38609
+ abi: DataPortabilityPermissionsAbi,
38610
+ functionName: "userPermissionIdsAt",
38611
+ args: [userAddress, permissionIndex]
38612
+ });
38613
+ return permissionId;
38614
+ } catch (error) {
38615
+ throw new BlockchainError(
38616
+ `Failed to get user permission ID at index: ${error instanceof Error ? error.message : "Unknown error"}`,
38617
+ error
38618
+ );
38619
+ }
38620
+ }
38621
+ /**
38622
+ * Get the number of permissions for a user
38623
+ *
38624
+ * @param userAddress - User address to query (defaults to current user)
38625
+ * @returns Promise resolving to number of permissions
38626
+ */
38627
+ async getUserPermissionCount(userAddress) {
38628
+ try {
38629
+ const targetAddress = userAddress || await this.getUserAddress();
38630
+ const chainId = await this.context.publicClient.getChainId();
38631
+ const DataPortabilityPermissionsAddress = getContractAddress(
38632
+ chainId,
38633
+ "DataPortabilityPermissions"
38634
+ );
38635
+ const DataPortabilityPermissionsAbi = getAbi(
38636
+ "DataPortabilityPermissions"
38637
+ );
38638
+ const count = await this.context.publicClient.readContract({
38639
+ address: DataPortabilityPermissionsAddress,
38640
+ abi: DataPortabilityPermissionsAbi,
38641
+ functionName: "userPermissionIdsLength",
38642
+ args: [targetAddress]
38643
+ });
38644
+ return count;
38645
+ } catch (error) {
38646
+ throw new BlockchainError(
38647
+ `Failed to get user permission count: ${error instanceof Error ? error.message : "Unknown error"}`,
38648
+ error
38649
+ );
38650
+ }
38651
+ }
38652
+ /**
38653
+ * Get detailed permission information by permission ID
38654
+ *
38655
+ * @param permissionId - Permission ID to get info for
38656
+ * @returns Promise resolving to permission info
38657
+ */
38658
+ async getPermissionInfo(permissionId) {
38659
+ try {
38660
+ const chainId = await this.context.publicClient.getChainId();
38661
+ const DataPortabilityPermissionsAddress = getContractAddress(
38662
+ chainId,
38663
+ "DataPortabilityPermissions"
38664
+ );
38665
+ const DataPortabilityPermissionsAbi = getAbi(
38666
+ "DataPortabilityPermissions"
38667
+ );
38668
+ const permissionInfo = await this.context.publicClient.readContract({
38669
+ address: DataPortabilityPermissionsAddress,
38670
+ abi: DataPortabilityPermissionsAbi,
38671
+ functionName: "permissions",
38672
+ args: [permissionId]
38673
+ });
38674
+ return permissionInfo;
38675
+ } catch (error) {
38676
+ throw new BlockchainError(
38677
+ `Failed to get permission info: ${error instanceof Error ? error.message : "Unknown error"}`,
38678
+ error
38679
+ );
38680
+ }
38681
+ }
38682
+ /**
38683
+ * Get all permission IDs for a specific file
38684
+ *
38685
+ * @param fileId - File ID to get permissions for
38686
+ * @returns Promise resolving to array of permission IDs
38687
+ */
38688
+ async getFilePermissionIds(fileId) {
38689
+ try {
38690
+ const chainId = await this.context.publicClient.getChainId();
38691
+ const DataPortabilityPermissionsAddress = getContractAddress(
38692
+ chainId,
38693
+ "DataPortabilityPermissions"
38694
+ );
38695
+ const DataPortabilityPermissionsAbi = getAbi(
38696
+ "DataPortabilityPermissions"
38697
+ );
38698
+ const permissionIds = await this.context.publicClient.readContract({
38699
+ address: DataPortabilityPermissionsAddress,
38700
+ abi: DataPortabilityPermissionsAbi,
38701
+ functionName: "filePermissionIds",
38702
+ args: [fileId]
38703
+ });
38704
+ return [...permissionIds];
38705
+ } catch (error) {
38706
+ throw new BlockchainError(
38707
+ `Failed to get file permission IDs: ${error instanceof Error ? error.message : "Unknown error"}`,
38708
+ error
38709
+ );
38710
+ }
38711
+ }
38712
+ /**
38713
+ * Get all file IDs for a specific permission
38714
+ *
38715
+ * @param permissionId - Permission ID to get files for
38716
+ * @returns Promise resolving to array of file IDs
38717
+ */
38718
+ async getPermissionFileIds(permissionId) {
38719
+ try {
38720
+ const chainId = await this.context.publicClient.getChainId();
38721
+ const DataPortabilityPermissionsAddress = getContractAddress(
38722
+ chainId,
38723
+ "DataPortabilityPermissions"
38724
+ );
38725
+ const DataPortabilityPermissionsAbi = getAbi(
38726
+ "DataPortabilityPermissions"
38727
+ );
38728
+ const fileIds = await this.context.publicClient.readContract({
38729
+ address: DataPortabilityPermissionsAddress,
38730
+ abi: DataPortabilityPermissionsAbi,
38731
+ functionName: "permissionFileIds",
38732
+ args: [permissionId]
38733
+ });
38734
+ return [...fileIds];
38735
+ } catch (error) {
38736
+ throw new BlockchainError(
38737
+ `Failed to get permission file IDs: ${error instanceof Error ? error.message : "Unknown error"}`,
38738
+ error
38739
+ );
38740
+ }
38741
+ }
38742
+ /**
38743
+ * Get all permissions for a specific file (alias for getFilePermissionIds)
38744
+ *
38745
+ * @param fileId - File ID to get permissions for
38746
+ * @returns Promise resolving to array of permission IDs
38747
+ */
38748
+ async getFilePermissions(fileId) {
38749
+ const chainId = await this.context.publicClient.getChainId();
38750
+ const DataPortabilityPermissionsAddress = getContractAddress(
38751
+ chainId,
38752
+ "DataPortabilityPermissions"
38753
+ );
38754
+ const DataPortabilityPermissionsAbi = getAbi("DataPortabilityPermissions");
38755
+ const permissions = await this.context.publicClient.readContract({
38756
+ address: DataPortabilityPermissionsAddress,
38757
+ abi: DataPortabilityPermissionsAbi,
38758
+ functionName: "filePermissions",
38759
+ args: [fileId]
38760
+ });
38761
+ return [...permissions];
38762
+ }
38763
+ // ===========================
38764
+ // DATA PORTABILITY GRANTEES HELPER METHODS
38765
+ // ===========================
38766
+ /**
38767
+ * Get grantee information by grantee ID
38768
+ *
38769
+ * @param granteeId - Grantee ID to get info for
38770
+ * @returns Promise resolving to grantee info
38771
+ */
38772
+ async getGranteeInfo(granteeId) {
38773
+ try {
38774
+ const chainId = await this.context.publicClient.getChainId();
38775
+ const DataPortabilityGranteesAddress = getContractAddress(
38776
+ chainId,
38777
+ "DataPortabilityGrantees"
38778
+ );
38779
+ const DataPortabilityGranteesAbi = getAbi("DataPortabilityGrantees");
38780
+ const granteeInfo = await this.context.publicClient.readContract({
38781
+ address: DataPortabilityGranteesAddress,
38782
+ abi: DataPortabilityGranteesAbi,
38783
+ functionName: "granteeInfo",
38784
+ args: [granteeId]
38785
+ });
38786
+ return granteeInfo;
38787
+ } catch (error) {
38788
+ throw new BlockchainError(
38789
+ `Failed to get grantee info: ${error instanceof Error ? error.message : "Unknown error"}`,
38790
+ error
38791
+ );
38792
+ }
38793
+ }
38794
+ /**
38795
+ * Get grantee information by grantee address
38796
+ *
38797
+ * @param granteeAddress - Grantee address to get info for
38798
+ * @returns Promise resolving to grantee info
38799
+ */
38800
+ async getGranteeInfoByAddress(granteeAddress) {
38801
+ try {
38802
+ const chainId = await this.context.publicClient.getChainId();
38803
+ const DataPortabilityGranteesAddress = getContractAddress(
38804
+ chainId,
38805
+ "DataPortabilityGrantees"
38806
+ );
38807
+ const DataPortabilityGranteesAbi = getAbi("DataPortabilityGrantees");
38808
+ const granteeInfo = await this.context.publicClient.readContract({
38809
+ address: DataPortabilityGranteesAddress,
38810
+ abi: DataPortabilityGranteesAbi,
38811
+ functionName: "granteeByAddress",
38812
+ args: [granteeAddress]
38813
+ });
38814
+ return granteeInfo;
38815
+ } catch (error) {
38816
+ throw new BlockchainError(
38817
+ `Failed to get grantee info by address: ${error instanceof Error ? error.message : "Unknown error"}`,
38818
+ error
38819
+ );
38820
+ }
38821
+ }
38822
+ /**
38823
+ * Get all permission IDs for a specific grantee
38824
+ *
38825
+ * @param granteeId - Grantee ID to get permissions for
38826
+ * @returns Promise resolving to array of permission IDs
38827
+ */
38828
+ async getGranteePermissionIds(granteeId) {
38829
+ try {
38830
+ const chainId = await this.context.publicClient.getChainId();
38831
+ const DataPortabilityGranteesAddress = getContractAddress(
38832
+ chainId,
38833
+ "DataPortabilityGrantees"
38834
+ );
38835
+ const DataPortabilityGranteesAbi = getAbi("DataPortabilityGrantees");
38836
+ const permissionIds = await this.context.publicClient.readContract({
38837
+ address: DataPortabilityGranteesAddress,
38838
+ abi: DataPortabilityGranteesAbi,
38839
+ functionName: "granteePermissionIds",
38840
+ args: [granteeId]
38841
+ });
38842
+ return [...permissionIds];
38843
+ } catch (error) {
38844
+ throw new BlockchainError(
38845
+ `Failed to get grantee permission IDs: ${error instanceof Error ? error.message : "Unknown error"}`,
38846
+ error
38847
+ );
38848
+ }
38849
+ }
38850
+ /**
38851
+ * Get all permissions for a specific grantee (alias for getGranteePermissionIds)
38852
+ *
38853
+ * @param granteeId - Grantee ID to get permissions for
38854
+ * @returns Promise resolving to array of permission IDs
38855
+ */
38856
+ async getGranteePermissions(granteeId) {
38857
+ try {
38858
+ const chainId = await this.context.publicClient.getChainId();
38859
+ const DataPortabilityGranteesAddress = getContractAddress(
38860
+ chainId,
38861
+ "DataPortabilityGrantees"
38862
+ );
38863
+ const DataPortabilityGranteesAbi = getAbi("DataPortabilityGrantees");
38864
+ const permissions = await this.context.publicClient.readContract({
38865
+ address: DataPortabilityGranteesAddress,
38866
+ abi: DataPortabilityGranteesAbi,
38867
+ functionName: "granteePermissions",
38868
+ args: [granteeId]
38869
+ });
38870
+ return [...permissions];
38871
+ } catch (error) {
38872
+ throw new BlockchainError(
38873
+ `Failed to get grantee permissions: ${error instanceof Error ? error.message : "Unknown error"}`,
38874
+ error
38875
+ );
38876
+ }
38877
+ }
38878
+ // ===== DataPortabilityServersImplementation Methods =====
38879
+ /**
38880
+ * Get all server IDs for a user
38881
+ *
38882
+ * @param userAddress - User address to get server IDs for
38883
+ * @returns Promise resolving to array of server IDs
38884
+ */
38885
+ async getUserServerIdsValues(userAddress) {
38886
+ try {
38887
+ const chainId = await this.context.publicClient.getChainId();
38888
+ const DataPortabilityServersAddress = getContractAddress(
38889
+ chainId,
38890
+ "DataPortabilityServers"
38891
+ );
38892
+ const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
38893
+ const serverIds = await this.context.publicClient.readContract({
38894
+ address: DataPortabilityServersAddress,
38895
+ abi: DataPortabilityServersAbi,
38896
+ functionName: "userServerIdsValues",
38897
+ args: [userAddress]
38898
+ });
38899
+ return [...serverIds];
38900
+ } catch (error) {
38901
+ throw new BlockchainError(
38902
+ `Failed to get user server IDs: ${error instanceof Error ? error.message : "Unknown error"}`,
38903
+ error
38904
+ );
38905
+ }
38906
+ }
38907
+ /**
38908
+ * Get server ID at specific index for a user
38909
+ *
38910
+ * @param userAddress - User address
38911
+ * @param serverIndex - Index of the server ID
38912
+ * @returns Promise resolving to server ID
38913
+ */
38914
+ async getUserServerIdsAt(userAddress, serverIndex) {
38915
+ try {
38916
+ const chainId = await this.context.publicClient.getChainId();
38917
+ const DataPortabilityServersAddress = getContractAddress(
38918
+ chainId,
38919
+ "DataPortabilityServers"
38920
+ );
38921
+ const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
38922
+ const serverId = await this.context.publicClient.readContract({
38923
+ address: DataPortabilityServersAddress,
38924
+ abi: DataPortabilityServersAbi,
38925
+ functionName: "userServerIdsAt",
38926
+ args: [userAddress, serverIndex]
38927
+ });
38928
+ return serverId;
38929
+ } catch (error) {
38930
+ throw new BlockchainError(
38931
+ `Failed to get user server ID at index: ${error instanceof Error ? error.message : "Unknown error"}`,
38932
+ error
38933
+ );
38934
+ }
38935
+ }
38936
+ /**
38937
+ * Get the number of servers a user has
38938
+ *
38939
+ * @param userAddress - User address
38940
+ * @returns Promise resolving to number of servers
38941
+ */
38942
+ async getUserServerIdsLength(userAddress) {
38943
+ try {
38944
+ const chainId = await this.context.publicClient.getChainId();
38945
+ const DataPortabilityServersAddress = getContractAddress(
38946
+ chainId,
38947
+ "DataPortabilityServers"
38948
+ );
38949
+ const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
38950
+ const length = await this.context.publicClient.readContract({
38951
+ address: DataPortabilityServersAddress,
38952
+ abi: DataPortabilityServersAbi,
38953
+ functionName: "userServerIdsLength",
38954
+ args: [userAddress]
38955
+ });
38956
+ return length;
38957
+ } catch (error) {
38958
+ throw new BlockchainError(
38959
+ `Failed to get user server IDs length: ${error instanceof Error ? error.message : "Unknown error"}`,
38960
+ error
38961
+ );
38962
+ }
38963
+ }
38964
+ /**
38965
+ * Get trusted server info for a specific user and server ID
38966
+ *
38967
+ * @param userAddress - User address
38968
+ * @param serverId - Server ID
38969
+ * @returns Promise resolving to trusted server info
38970
+ */
38971
+ async getUserServers(userAddress, serverId) {
38972
+ try {
38973
+ const chainId = await this.context.publicClient.getChainId();
38974
+ const DataPortabilityServersAddress = getContractAddress(
38975
+ chainId,
38976
+ "DataPortabilityServers"
38977
+ );
38978
+ const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
38979
+ const serverInfo = await this.context.publicClient.readContract({
38980
+ address: DataPortabilityServersAddress,
38981
+ abi: DataPortabilityServersAbi,
38982
+ functionName: "userServers",
38983
+ args: [userAddress, serverId]
38984
+ });
38985
+ return {
38986
+ id: serverInfo.id,
38987
+ owner: serverInfo.owner,
38988
+ serverAddress: serverInfo.serverAddress,
38989
+ publicKey: serverInfo.publicKey,
38990
+ url: serverInfo.url,
38991
+ startBlock: serverInfo.startBlock,
38992
+ endBlock: serverInfo.endBlock
38993
+ };
38994
+ } catch (error) {
38995
+ throw new BlockchainError(
38996
+ `Failed to get user server info: ${error instanceof Error ? error.message : "Unknown error"}`,
38997
+ error
38998
+ );
38999
+ }
39000
+ }
39001
+ /**
39002
+ * Get server info by server ID
39003
+ *
39004
+ * @param serverId - Server ID
39005
+ * @returns Promise resolving to server info
39006
+ */
39007
+ async getServers(serverId) {
39008
+ try {
39009
+ const chainId = await this.context.publicClient.getChainId();
39010
+ const DataPortabilityServersAddress = getContractAddress(
39011
+ chainId,
39012
+ "DataPortabilityServers"
39013
+ );
39014
+ const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
39015
+ const serverInfo = await this.context.publicClient.readContract({
39016
+ address: DataPortabilityServersAddress,
39017
+ abi: DataPortabilityServersAbi,
39018
+ functionName: "servers",
39019
+ args: [serverId]
39020
+ });
39021
+ return {
39022
+ id: serverInfo.id,
39023
+ owner: serverInfo.owner,
39024
+ serverAddress: serverInfo.serverAddress,
39025
+ publicKey: serverInfo.publicKey,
39026
+ url: serverInfo.url
39027
+ };
39028
+ } catch (error) {
39029
+ throw new BlockchainError(
39030
+ `Failed to get server info: ${error instanceof Error ? error.message : "Unknown error"}`,
39031
+ error
39032
+ );
39033
+ }
39034
+ }
39035
+ /**
39036
+ * Get user info including nonce and trusted server IDs
39037
+ *
39038
+ * @param userAddress - User address
39039
+ * @returns Promise resolving to user info
39040
+ */
39041
+ async getUsers(userAddress) {
39042
+ try {
39043
+ const chainId = await this.context.publicClient.getChainId();
39044
+ const DataPortabilityServersAddress = getContractAddress(
39045
+ chainId,
39046
+ "DataPortabilityServers"
39047
+ );
39048
+ const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
39049
+ const userInfo = await this.context.publicClient.readContract({
39050
+ address: DataPortabilityServersAddress,
39051
+ abi: DataPortabilityServersAbi,
39052
+ functionName: "users",
39053
+ args: [userAddress]
39054
+ });
39055
+ return {
39056
+ nonce: userInfo[0],
39057
+ trustedServerIds: [...userInfo[1]]
39058
+ };
39059
+ } catch (error) {
39060
+ throw new BlockchainError(
39061
+ `Failed to get user info: ${error instanceof Error ? error.message : "Unknown error"}`,
39062
+ error
39063
+ );
39064
+ }
39065
+ }
39066
+ /**
39067
+ * Update server URL
39068
+ *
39069
+ * @param serverId - Server ID to update
39070
+ * @param url - New URL for the server
39071
+ * @returns Promise resolving to transaction hash
39072
+ */
39073
+ async submitUpdateServer(serverId, url) {
39074
+ try {
39075
+ const chainId = await this.context.walletClient.getChainId();
39076
+ const DataPortabilityServersAddress = getContractAddress(
39077
+ chainId,
39078
+ "DataPortabilityServers"
39079
+ );
39080
+ const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
39081
+ const hash = await this.context.walletClient.writeContract({
39082
+ address: DataPortabilityServersAddress,
39083
+ abi: DataPortabilityServersAbi,
39084
+ functionName: "updateServer",
39085
+ args: [serverId, url],
39086
+ chain: this.context.walletClient.chain,
39087
+ account: this.context.walletClient.account || null
39088
+ });
39089
+ return hash;
39090
+ } catch (error) {
39091
+ throw new BlockchainError(
39092
+ `Failed to update server: ${error instanceof Error ? error.message : "Unknown error"}`,
39093
+ error
39094
+ );
39095
+ }
39096
+ }
39097
+ // ===== DataPortabilityPermissionsImplementation Methods =====
39098
+ /**
39099
+ * Get all permission IDs for a user
39100
+ *
39101
+ * @param userAddress - User address to get permission IDs for
39102
+ * @returns Promise resolving to array of permission IDs
39103
+ */
39104
+ async getUserPermissionIdsValues(userAddress) {
39105
+ try {
39106
+ const chainId = await this.context.publicClient.getChainId();
39107
+ const DataPortabilityPermissionsAddress = getContractAddress(
39108
+ chainId,
39109
+ "DataPortabilityPermissions"
39110
+ );
39111
+ const DataPortabilityPermissionsAbi = getAbi(
39112
+ "DataPortabilityPermissions"
39113
+ );
39114
+ const permissionIds = await this.context.publicClient.readContract({
39115
+ address: DataPortabilityPermissionsAddress,
39116
+ abi: DataPortabilityPermissionsAbi,
39117
+ functionName: "userPermissionIdsValues",
39118
+ args: [userAddress]
39119
+ });
39120
+ return [...permissionIds];
39121
+ } catch (error) {
39122
+ throw new BlockchainError(
39123
+ `Failed to get user permission IDs: ${error instanceof Error ? error.message : "Unknown error"}`,
39124
+ error
39125
+ );
39126
+ }
39127
+ }
39128
+ /**
39129
+ * Get permission ID at specific index for a user
39130
+ *
39131
+ * @param userAddress - User address
39132
+ * @param permissionIndex - Index of the permission ID
39133
+ * @returns Promise resolving to permission ID
39134
+ */
39135
+ async getUserPermissionIdsAt(userAddress, permissionIndex) {
39136
+ try {
39137
+ const chainId = await this.context.publicClient.getChainId();
39138
+ const DataPortabilityPermissionsAddress = getContractAddress(
39139
+ chainId,
39140
+ "DataPortabilityPermissions"
39141
+ );
39142
+ const DataPortabilityPermissionsAbi = getAbi(
39143
+ "DataPortabilityPermissions"
39144
+ );
39145
+ const permissionId = await this.context.publicClient.readContract({
39146
+ address: DataPortabilityPermissionsAddress,
39147
+ abi: DataPortabilityPermissionsAbi,
39148
+ functionName: "userPermissionIdsAt",
39149
+ args: [userAddress, permissionIndex]
39150
+ });
39151
+ return permissionId;
39152
+ } catch (error) {
39153
+ throw new BlockchainError(
39154
+ `Failed to get user permission ID at index: ${error instanceof Error ? error.message : "Unknown error"}`,
39155
+ error
39156
+ );
39157
+ }
39158
+ }
39159
+ /**
39160
+ * Get the number of permissions a user has
39161
+ *
39162
+ * @param userAddress - User address
39163
+ * @returns Promise resolving to number of permissions
39164
+ */
39165
+ async getUserPermissionIdsLength(userAddress) {
39166
+ try {
39167
+ const chainId = await this.context.publicClient.getChainId();
39168
+ const DataPortabilityPermissionsAddress = getContractAddress(
39169
+ chainId,
39170
+ "DataPortabilityPermissions"
39171
+ );
39172
+ const DataPortabilityPermissionsAbi = getAbi(
39173
+ "DataPortabilityPermissions"
39174
+ );
39175
+ const length = await this.context.publicClient.readContract({
39176
+ address: DataPortabilityPermissionsAddress,
39177
+ abi: DataPortabilityPermissionsAbi,
39178
+ functionName: "userPermissionIdsLength",
39179
+ args: [userAddress]
39180
+ });
39181
+ return length;
39182
+ } catch (error) {
39183
+ throw new BlockchainError(
39184
+ `Failed to get user permission IDs length: ${error instanceof Error ? error.message : "Unknown error"}`,
39185
+ error
39186
+ );
39187
+ }
39188
+ }
39189
+ /**
39190
+ * Get permission info by permission ID
39191
+ *
39192
+ * @param permissionId - Permission ID
39193
+ * @returns Promise resolving to permission info
39194
+ */
39195
+ async getPermissions(permissionId) {
39196
+ try {
39197
+ const chainId = await this.context.publicClient.getChainId();
39198
+ const DataPortabilityPermissionsAddress = getContractAddress(
39199
+ chainId,
39200
+ "DataPortabilityPermissions"
39201
+ );
39202
+ const DataPortabilityPermissionsAbi = getAbi(
39203
+ "DataPortabilityPermissions"
39204
+ );
39205
+ const permissionInfo = await this.context.publicClient.readContract({
39206
+ address: DataPortabilityPermissionsAddress,
39207
+ abi: DataPortabilityPermissionsAbi,
39208
+ functionName: "permissions",
39209
+ args: [permissionId]
39210
+ });
39211
+ return {
39212
+ id: permissionInfo.id,
39213
+ grantor: permissionInfo.grantor,
39214
+ nonce: permissionInfo.nonce,
39215
+ granteeId: permissionInfo.granteeId,
39216
+ grant: permissionInfo.grant,
39217
+ startBlock: permissionInfo.startBlock,
39218
+ endBlock: permissionInfo.endBlock,
39219
+ fileIds: [...permissionInfo.fileIds]
39220
+ };
39221
+ } catch (error) {
39222
+ throw new BlockchainError(
39223
+ `Failed to get permission info: ${error instanceof Error ? error.message : "Unknown error"}`,
39224
+ error
39225
+ );
39226
+ }
39227
+ }
39228
+ /**
39229
+ * Submit permission with signature to the blockchain (supports gasless transactions)
39230
+ *
39231
+ * @param params - Parameters for adding permission
39232
+ * @returns Promise resolving to transaction hash
39233
+ * @throws {RelayerError} When gasless transaction submission fails
39234
+ * @throws {SignatureError} When user rejects the signature request
39235
+ * @throws {BlockchainError} When permission addition fails
39236
+ * @throws {NetworkError} When network communication fails
39237
+ */
39238
+ async submitAddPermission(params) {
39239
+ try {
39240
+ const nonce = await this.getPermissionsUserNonce();
39241
+ const addPermissionInput = {
39242
+ nonce,
39243
+ granteeId: params.granteeId,
39244
+ grant: params.grant,
39245
+ fileUrls: params.fileUrls,
39246
+ serverAddress: params.serverAddress,
39247
+ serverUrl: params.serverUrl,
39248
+ serverPublicKey: params.serverPublicKey,
39249
+ filePermissions: params.filePermissions
39250
+ };
39251
+ const typedData = await this.composeServerFilesAndPermissionMessage(addPermissionInput);
39252
+ const signature = await this.signTypedData(typedData);
39253
+ return await this.submitSignedAddPermission(typedData, signature);
39254
+ } catch (error) {
39255
+ if (error instanceof RelayerError || error instanceof UserRejectedRequestError || error instanceof SerializationError || error instanceof SignatureError || error instanceof NetworkError || error instanceof NonceError) {
39256
+ throw error;
39257
+ }
39258
+ throw new BlockchainError(
39259
+ `Failed to add permission: ${error instanceof Error ? error.message : "Unknown error"}`,
39260
+ error
39261
+ );
39262
+ }
39263
+ }
39264
+ /**
39265
+ * Submits an already-signed add permission transaction to the blockchain.
39266
+ * This method supports both relayer-based gasless transactions and direct transactions.
39267
+ *
39268
+ * @param typedData - The EIP-712 typed data for AddPermission
39269
+ * @param signature - The user's signature
39270
+ * @returns Promise resolving to the transaction hash
39271
+ * @throws {RelayerError} When gasless transaction submission fails
39272
+ * @throws {BlockchainError} When permission addition fails
39273
+ * @throws {NetworkError} When network communication fails
39274
+ */
39275
+ async submitSignedAddPermission(typedData, signature) {
39276
+ try {
39277
+ if (this.context.relayerCallbacks?.submitAddPermission) {
39278
+ return await this.context.relayerCallbacks.submitAddPermission(
39279
+ typedData,
39280
+ signature
39281
+ );
39282
+ } else {
39283
+ return await this.submitDirectAddPermissionTransaction(
39284
+ typedData,
39285
+ signature
39286
+ );
39287
+ }
39288
+ } catch (error) {
39289
+ if (error instanceof RelayerError || error instanceof NetworkError || error instanceof UserRejectedRequestError || error instanceof SignatureError || error instanceof NonceError) {
39290
+ throw error;
39291
+ }
39292
+ throw new BlockchainError(
39293
+ `Add permission submission failed: ${error instanceof Error ? error.message : "Unknown error"}`,
39294
+ error
39295
+ );
39296
+ }
39297
+ }
39298
+ /**
39299
+ * Submit server files and permissions with signature to the blockchain (supports gasless transactions)
39300
+ *
39301
+ * @param params - Parameters for adding server files and permissions
39302
+ * @returns Promise resolving to transaction hash
39303
+ * @throws {RelayerError} When gasless transaction submission fails
39304
+ * @throws {SignatureError} When user rejects the signature request
39305
+ * @throws {BlockchainError} When server files and permissions addition fails
39306
+ * @throws {NetworkError} When network communication fails
39307
+ */
39308
+ async submitAddServerFilesAndPermissions(params) {
39309
+ try {
39310
+ const nonce = await this.getPermissionsUserNonce();
39311
+ const serverFilesAndPermissionInput = {
39312
+ nonce,
39313
+ granteeId: params.granteeId,
39314
+ grant: params.grant,
39315
+ fileUrls: params.fileUrls,
39316
+ serverAddress: params.serverAddress,
39317
+ serverUrl: params.serverUrl,
39318
+ serverPublicKey: params.serverPublicKey,
39319
+ filePermissions: params.filePermissions
39320
+ };
39321
+ const typedData = await this.composeServerFilesAndPermissionMessage(
39322
+ serverFilesAndPermissionInput
39323
+ );
39324
+ const signature = await this.signTypedData(typedData);
39325
+ return await this.submitSignedAddServerFilesAndPermissions(
39326
+ typedData,
39327
+ signature
39328
+ );
39329
+ } catch (error) {
39330
+ if (error instanceof RelayerError || error instanceof UserRejectedRequestError || error instanceof SerializationError || error instanceof SignatureError || error instanceof NetworkError || error instanceof NonceError) {
39331
+ throw error;
39332
+ }
39333
+ throw new BlockchainError(
39334
+ `Failed to add server files and permissions: ${error instanceof Error ? error.message : "Unknown error"}`,
39335
+ error
39336
+ );
39337
+ }
39338
+ }
39339
+ /**
39340
+ * Submits an already-signed add server files and permissions transaction to the blockchain.
39341
+ * This method supports both relayer-based gasless transactions and direct transactions.
39342
+ *
39343
+ * @param typedData - The EIP-712 typed data for AddServerFilesAndPermissions
39344
+ * @param signature - The user's signature
39345
+ * @returns Promise resolving to the transaction hash
39346
+ * @throws {RelayerError} When gasless transaction submission fails
39347
+ * @throws {BlockchainError} When server files and permissions addition fails
39348
+ * @throws {NetworkError} When network communication fails
39349
+ */
39350
+ async submitSignedAddServerFilesAndPermissions(typedData, signature) {
39351
+ try {
39352
+ console.debug("\u{1F50D} submitSignedAddServerFilesAndPermissions Debug Info:", {
39353
+ hasRelayerCallbacks: !!this.context.relayerCallbacks,
39354
+ hasSubmitMethod: !!this.context.relayerCallbacks?.submitAddServerFilesAndPermissions,
39355
+ availableRelayerMethods: this.context.relayerCallbacks ? Object.keys(this.context.relayerCallbacks) : []
39356
+ });
39357
+ if (this.context.relayerCallbacks?.submitAddServerFilesAndPermissions) {
39358
+ console.debug(
39359
+ "\u{1F680} Using relayer for submitAddServerFilesAndPermissions"
39360
+ );
39361
+ return await this.context.relayerCallbacks.submitAddServerFilesAndPermissions(
39362
+ typedData,
39363
+ signature
39364
+ );
39365
+ } else {
39366
+ console.debug(
39367
+ "\u{1F4DD} Using direct transaction for submitAddServerFilesAndPermissions"
39368
+ );
39369
+ return await this.submitDirectAddServerFilesAndPermissionsTransaction(
39370
+ typedData,
39371
+ signature
39372
+ );
39373
+ }
39374
+ } catch (error) {
39375
+ if (error instanceof RelayerError || error instanceof NetworkError || error instanceof UserRejectedRequestError || error instanceof SignatureError || error instanceof NonceError) {
39376
+ throw error;
39377
+ }
39378
+ throw new BlockchainError(
39379
+ `Add server files and permissions submission failed: ${error instanceof Error ? error.message : "Unknown error"}`,
39380
+ error
39381
+ );
39382
+ }
39383
+ }
39384
+ /**
39385
+ * Submit permission revocation with signature to the blockchain
39386
+ *
39387
+ * @param permissionId - Permission ID to revoke
39388
+ * @returns Promise resolving to transaction hash
39389
+ */
39390
+ async submitRevokePermission(permissionId) {
39391
+ try {
39392
+ const chainId = await this.context.walletClient.getChainId();
39393
+ const DataPortabilityPermissionsAddress = getContractAddress(
39394
+ chainId,
39395
+ "DataPortabilityPermissions"
39396
+ );
39397
+ const DataPortabilityPermissionsAbi = getAbi(
39398
+ "DataPortabilityPermissions"
39399
+ );
39400
+ const hash = await this.context.walletClient.writeContract({
39401
+ address: DataPortabilityPermissionsAddress,
39402
+ abi: DataPortabilityPermissionsAbi,
39403
+ functionName: "revokePermission",
39404
+ args: [permissionId],
39405
+ chain: this.context.walletClient.chain,
39406
+ account: this.context.walletClient.account || null
39407
+ });
39408
+ return hash;
39409
+ } catch (error) {
39410
+ throw new BlockchainError(
39411
+ `Failed to revoke permission: ${error instanceof Error ? error.message : "Unknown error"}`,
39412
+ error
39413
+ );
39414
+ }
39415
+ }
39416
+ /**
39417
+ * Submits a signed add permission transaction directly to the blockchain.
39418
+ *
39419
+ * @param typedData - The typed data structure for the permission addition
39420
+ * @param signature - The cryptographic signature authorizing the transaction
39421
+ * @returns Promise resolving to the transaction hash
39422
+ */
39423
+ async submitDirectAddPermissionTransaction(typedData, signature) {
39424
+ const chainId = await this.context.walletClient.getChainId();
39425
+ const DataPortabilityPermissionsAddress = getContractAddress(
39426
+ chainId,
39427
+ "DataPortabilityPermissions"
39428
+ );
39429
+ const DataPortabilityPermissionsAbi = getAbi("DataPortabilityPermissions");
39430
+ const permissionInput = {
39431
+ nonce: typedData.message.nonce,
39432
+ granteeId: typedData.message.granteeId,
39433
+ grant: typedData.message.grant,
39434
+ fileIds: typedData.message.fileIds || []
39435
+ };
39436
+ const formattedSignature = formatSignatureForContract(signature);
39437
+ const hash = await this.context.walletClient.writeContract({
39438
+ address: DataPortabilityPermissionsAddress,
39439
+ abi: DataPortabilityPermissionsAbi,
39440
+ functionName: "addPermission",
39441
+ args: [permissionInput, formattedSignature],
39442
+ account: this.context.walletClient.account || await this.getUserAddress(),
39443
+ chain: this.context.walletClient.chain || null
39444
+ });
39445
+ return hash;
39446
+ }
39447
+ /**
39448
+ * Submits a signed add server files and permissions transaction directly to the blockchain.
39449
+ *
39450
+ * @param typedData - The typed data structure for the server files and permissions addition
39451
+ * @param signature - The cryptographic signature authorizing the transaction
39452
+ * @returns Promise resolving to the transaction hash
39453
+ */
39454
+ async submitDirectAddServerFilesAndPermissionsTransaction(typedData, signature) {
39455
+ const chainId = await this.context.walletClient.getChainId();
39456
+ const DataPortabilityPermissionsAddress = getContractAddress(
39457
+ chainId,
39458
+ "DataPortabilityPermissions"
39459
+ );
39460
+ const DataPortabilityPermissionsAbi = getAbi("DataPortabilityPermissions");
39461
+ const serverFilesAndPermissionInput = {
39462
+ nonce: typedData.message.nonce,
39463
+ granteeId: typedData.message.granteeId,
39464
+ grant: typedData.message.grant,
39465
+ fileUrls: typedData.message.fileUrls,
39466
+ serverAddress: typedData.message.serverAddress,
39467
+ serverUrl: typedData.message.serverUrl,
39468
+ serverPublicKey: typedData.message.serverPublicKey,
39469
+ filePermissions: typedData.message.filePermissions
39470
+ };
39471
+ const formattedSignature = formatSignatureForContract(signature);
39472
+ const hash = await this.context.walletClient.writeContract({
39473
+ address: DataPortabilityPermissionsAddress,
39474
+ abi: DataPortabilityPermissionsAbi,
39475
+ functionName: "addServerFilesAndPermissions",
39476
+ // @ts-expect-error - Complex nested array types cause compatibility issues with viem's generated types
39477
+ args: [serverFilesAndPermissionInput, formattedSignature],
39478
+ account: this.context.walletClient.account || await this.getUserAddress(),
39479
+ chain: this.context.walletClient.chain || null
39480
+ });
39481
+ return hash;
39482
+ }
38256
39483
  };
38257
39484
 
38258
39485
  // src/controllers/data.ts
38259
- import { getContract, decodeEventLog } from "viem";
39486
+ import { getContract as getContract2, decodeEventLog } from "viem";
39487
+
39488
+ // src/utils/blockchain/registry.ts
39489
+ import { getContract } from "viem";
39490
+ async function fetchSchemaFromChain(context, schemaId) {
39491
+ const chainId = context.walletClient.chain?.id;
39492
+ if (!chainId) {
39493
+ throw new Error("Chain ID not available");
39494
+ }
39495
+ const dataRefinerRegistryAddress = getContractAddress(
39496
+ chainId,
39497
+ "DataRefinerRegistry"
39498
+ );
39499
+ const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
39500
+ const dataRefinerRegistry = getContract({
39501
+ address: dataRefinerRegistryAddress,
39502
+ abi: dataRefinerRegistryAbi,
39503
+ client: context.publicClient
39504
+ });
39505
+ const schemaData = await dataRefinerRegistry.read.schemas([BigInt(schemaId)]);
39506
+ if (!schemaData) {
39507
+ throw new Error(`Schema with ID ${schemaId} not found`);
39508
+ }
39509
+ const schemaObj = schemaData;
39510
+ if (!schemaObj.name || !schemaObj.typ || !schemaObj.definitionUrl) {
39511
+ throw new Error("Incomplete schema data");
39512
+ }
39513
+ return {
39514
+ id: schemaId,
39515
+ name: schemaObj.name,
39516
+ type: schemaObj.typ,
39517
+ definitionUrl: schemaObj.definitionUrl
39518
+ };
39519
+ }
39520
+ async function fetchSchemaCountFromChain(context) {
39521
+ const chainId = context.walletClient.chain?.id;
39522
+ if (!chainId) {
39523
+ throw new Error("Chain ID not available");
39524
+ }
39525
+ const dataRefinerRegistryAddress = getContractAddress(
39526
+ chainId,
39527
+ "DataRefinerRegistry"
39528
+ );
39529
+ const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
39530
+ const dataRefinerRegistry = getContract({
39531
+ address: dataRefinerRegistryAddress,
39532
+ abi: dataRefinerRegistryAbi,
39533
+ client: context.publicClient
39534
+ });
39535
+ const count = await dataRefinerRegistry.read.schemasCount();
39536
+ return Number(count);
39537
+ }
38260
39538
 
38261
39539
  // src/utils/encryption.ts
38262
39540
  var DEFAULT_ENCRYPTION_SEED = "Please sign to retrieve your encryption key";
@@ -38338,7 +39616,11 @@ async function encryptBlobWithSignedKey(data, key, platformAdapter) {
38338
39616
  dataArray,
38339
39617
  key
38340
39618
  );
38341
- return new Blob([encrypted], {
39619
+ const encryptedArrayBuffer = encrypted.buffer.slice(
39620
+ encrypted.byteOffset,
39621
+ encrypted.byteOffset + encrypted.byteLength
39622
+ );
39623
+ return new Blob([encryptedArrayBuffer], {
38342
39624
  type: "application/octet-stream"
38343
39625
  });
38344
39626
  } catch (error) {
@@ -38367,7 +39649,11 @@ async function decryptBlobWithSignedKey(encryptedData, key, platformAdapter) {
38367
39649
  encryptedArray,
38368
39650
  key
38369
39651
  );
38370
- return new Blob([decrypted], { type: "text/plain" });
39652
+ const decryptedArrayBuffer = decrypted.buffer.slice(
39653
+ decrypted.byteOffset,
39654
+ decrypted.byteOffset + decrypted.byteLength
39655
+ );
39656
+ return new Blob([decryptedArrayBuffer], { type: "text/plain" });
38371
39657
  } catch (error) {
38372
39658
  throw new Error(`Failed to decrypt data: ${error}`);
38373
39659
  }
@@ -38384,28 +39670,16 @@ var DataController = class {
38384
39670
  filename,
38385
39671
  schemaId,
38386
39672
  permissions = [],
38387
- encrypt: encrypt2 = true,
39673
+ encrypt = true,
38388
39674
  providerName,
38389
39675
  owner
38390
39676
  } = params;
38391
39677
  try {
38392
- let blob;
38393
- if (content instanceof Blob) {
38394
- blob = content;
38395
- } else if (typeof content === "string") {
38396
- blob = new Blob([content], { type: "text/plain" });
38397
- } else if (content instanceof Buffer) {
38398
- blob = new Blob([content], { type: "application/octet-stream" });
38399
- } else {
38400
- blob = new Blob([JSON.stringify(content)], {
38401
- type: "application/json"
38402
- });
38403
- }
38404
39678
  let isValid = true;
38405
39679
  let validationErrors = [];
38406
39680
  if (schemaId !== void 0) {
38407
39681
  try {
38408
- const schema = await this.getSchema(schemaId);
39682
+ const schema = await fetchSchemaFromChain(this.context, schemaId);
38409
39683
  const response = await fetch(schema.definitionUrl);
38410
39684
  if (!response.ok) {
38411
39685
  throw new Error(
@@ -38437,37 +39711,15 @@ var DataController = class {
38437
39711
  ];
38438
39712
  }
38439
39713
  }
38440
- let finalBlob = blob;
38441
- if (encrypt2) {
38442
- const encryptionKey = await generateEncryptionKey(
38443
- this.context.walletClient,
38444
- this.context.platform,
38445
- DEFAULT_ENCRYPTION_SEED
38446
- );
38447
- finalBlob = await encryptBlobWithSignedKey(
38448
- blob,
38449
- encryptionKey,
38450
- this.context.platform
38451
- );
38452
- }
38453
- if (!this.context.storageManager) {
38454
- if (this.context.validateStorageRequired) {
38455
- this.context.validateStorageRequired();
38456
- throw new Error("Storage validation failed");
38457
- } else {
38458
- throw new Error(
38459
- "Storage manager not configured. Please provide storage providers in VanaConfig."
38460
- );
38461
- }
38462
- }
38463
- const uploadResult = await this.context.storageManager.upload(
38464
- finalBlob,
39714
+ const uploadResult = await this.uploadToStorage(
39715
+ content,
38465
39716
  filename,
39717
+ encrypt,
38466
39718
  providerName
38467
39719
  );
38468
39720
  const userAddress = owner || await this.getUserAddress();
38469
39721
  let encryptedPermissions = [];
38470
- if (permissions.length > 0) {
39722
+ if (permissions.length > 0 && encrypt) {
38471
39723
  const userEncryptionKey = await generateEncryptionKey(
38472
39724
  this.context.walletClient,
38473
39725
  this.context.platform,
@@ -39185,7 +40437,7 @@ var DataController = class {
39185
40437
  }
39186
40438
  const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
39187
40439
  const dataRegistryAbi = getAbi("DataRegistry");
39188
- const dataRegistry = getContract({
40440
+ const dataRegistry = getContract2({
39189
40441
  address: dataRegistryAddress,
39190
40442
  abi: dataRegistryAbi,
39191
40443
  client: this.context.walletClient
@@ -39236,7 +40488,7 @@ var DataController = class {
39236
40488
  }
39237
40489
  const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
39238
40490
  const dataRegistryAbi = getAbi("DataRegistry");
39239
- const dataRegistry = getContract({
40491
+ const dataRegistry = getContract2({
39240
40492
  address: dataRegistryAddress,
39241
40493
  abi: dataRegistryAbi,
39242
40494
  client: this.context.walletClient
@@ -39274,205 +40526,6 @@ var DataController = class {
39274
40526
  );
39275
40527
  }
39276
40528
  }
39277
- /**
39278
- * Uploads an encrypted file to storage and registers it on the blockchain.
39279
- *
39280
- * @deprecated Since v2.0.0 - Use vana.data.upload() instead for the high-level API with automatic encryption
39281
- *
39282
- * Migration guide:
39283
- * ```typescript
39284
- * // Old way (deprecated):
39285
- * const encrypted = await encryptBlob(data, key);
39286
- * const result = await vana.data.uploadEncryptedFile(encrypted, filename);
39287
- *
39288
- * // New way:
39289
- * const result = await vana.data.upload({
39290
- * content: data,
39291
- * filename: filename,
39292
- * encrypt: true // Handles encryption automatically
39293
- * });
39294
- * ```
39295
- * @param encryptedFile - The encrypted file blob to upload
39296
- * @param filename - Optional filename for the upload
39297
- * @param providerName - Optional storage provider to use
39298
- * @returns Promise resolving to upload result with file ID and storage URL
39299
- *
39300
- * This method handles the complete flow of:
39301
- * 1. Uploading the encrypted file to the specified storage provider
39302
- * 2. Registering the file URL on the DataRegistry contract via relayer
39303
- * 3. Returning the assigned file ID and storage URL
39304
- */
39305
- async uploadEncryptedFile(encryptedFile, filename, providerName) {
39306
- try {
39307
- if (!this.context.storageManager) {
39308
- throw new Error(
39309
- "Storage manager not configured. Please provide storage providers in VanaConfig."
39310
- );
39311
- }
39312
- const uploadResult = await this.context.storageManager.upload(
39313
- encryptedFile,
39314
- filename,
39315
- providerName
39316
- );
39317
- const userAddress = await this.getUserAddress();
39318
- if (this.context.relayerCallbacks?.submitFileAddition) {
39319
- const result = await this.context.relayerCallbacks.submitFileAddition(
39320
- uploadResult.url,
39321
- userAddress
39322
- );
39323
- return {
39324
- fileId: result.fileId,
39325
- url: uploadResult.url,
39326
- size: uploadResult.size,
39327
- transactionHash: result.transactionHash
39328
- };
39329
- } else {
39330
- const chainId = this.context.walletClient.chain?.id;
39331
- if (!chainId) {
39332
- throw new Error("Chain ID not available");
39333
- }
39334
- const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
39335
- const dataRegistryAbi = getAbi("DataRegistry");
39336
- const txHash = await this.context.walletClient.writeContract({
39337
- address: dataRegistryAddress,
39338
- abi: dataRegistryAbi,
39339
- functionName: "addFile",
39340
- args: [uploadResult.url],
39341
- account: this.context.walletClient.account || userAddress,
39342
- chain: this.context.walletClient.chain || null
39343
- });
39344
- const receipt = await this.context.publicClient.waitForTransactionReceipt({
39345
- hash: txHash,
39346
- timeout: 3e4
39347
- // 30 seconds timeout
39348
- });
39349
- let fileId = 0;
39350
- for (const log of receipt.logs) {
39351
- try {
39352
- const decoded = decodeEventLog({
39353
- abi: dataRegistryAbi,
39354
- data: log.data,
39355
- topics: log.topics
39356
- });
39357
- if (decoded.eventName === "FileAdded") {
39358
- fileId = Number(decoded.args.fileId);
39359
- break;
39360
- }
39361
- } catch {
39362
- continue;
39363
- }
39364
- }
39365
- return {
39366
- fileId,
39367
- url: uploadResult.url,
39368
- size: uploadResult.size,
39369
- transactionHash: txHash
39370
- };
39371
- }
39372
- } catch (error) {
39373
- console.error("Failed to upload encrypted file:", error);
39374
- throw new Error(
39375
- `Upload failed: ${error instanceof Error ? error.message : "Unknown error"}`
39376
- );
39377
- }
39378
- }
39379
- /**
39380
- * Uploads an encrypted file to storage and registers it on the blockchain with a schema.
39381
- *
39382
- * @deprecated Since v2.0.0 - Use vana.data.upload() instead for the high-level API with automatic encryption and schema validation
39383
- *
39384
- * Migration guide:
39385
- * ```typescript
39386
- * // Old way (deprecated):
39387
- * const encrypted = await encryptBlob(data, key);
39388
- * const result = await vana.data.uploadEncryptedFileWithSchema(encrypted, schemaId, filename);
39389
- *
39390
- * // New way:
39391
- * const result = await vana.data.upload({
39392
- * content: data,
39393
- * filename: filename,
39394
- * schemaId: schemaId, // Automatic validation
39395
- * encrypt: true
39396
- * });
39397
- * ```
39398
- * @param encryptedFile - The encrypted file blob to upload
39399
- * @param schemaId - The schema ID to associate with the file
39400
- * @param filename - Optional filename for the upload
39401
- * @param providerName - Optional storage provider to use
39402
- * @returns Promise resolving to upload result with file ID and storage URL
39403
- *
39404
- * This method handles the complete flow of:
39405
- * 1. Uploading the encrypted file to the specified storage provider
39406
- * 2. Registering the file URL on the DataRegistry contract with a schema ID
39407
- * 3. Returning the assigned file ID and storage URL
39408
- */
39409
- async uploadEncryptedFileWithSchema(encryptedFile, schemaId, filename, providerName) {
39410
- try {
39411
- if (!this.context.storageManager) {
39412
- throw new Error(
39413
- "Storage manager not configured. Please provide storage providers in VanaConfig."
39414
- );
39415
- }
39416
- const uploadResult = await this.context.storageManager.upload(
39417
- encryptedFile,
39418
- filename,
39419
- providerName
39420
- );
39421
- const userAddress = await this.getUserAddress();
39422
- if (this.context.relayerCallbacks?.submitFileAddition) {
39423
- throw new Error(
39424
- "Relayer does not yet support uploading files with schema. Please use direct transaction mode."
39425
- );
39426
- } else {
39427
- const chainId = this.context.walletClient.chain?.id;
39428
- if (!chainId) {
39429
- throw new Error("Chain ID not available");
39430
- }
39431
- const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
39432
- const dataRegistryAbi = getAbi("DataRegistry");
39433
- const txHash = await this.context.walletClient.writeContract({
39434
- address: dataRegistryAddress,
39435
- abi: dataRegistryAbi,
39436
- functionName: "addFileWithSchema",
39437
- args: [uploadResult.url, BigInt(schemaId)],
39438
- account: this.context.walletClient.account || userAddress,
39439
- chain: this.context.walletClient.chain || null
39440
- });
39441
- const receipt = await this.context.publicClient.waitForTransactionReceipt({
39442
- hash: txHash,
39443
- timeout: 3e4
39444
- // 30 seconds timeout
39445
- });
39446
- let fileId = 0;
39447
- for (const log of receipt.logs) {
39448
- try {
39449
- const decoded = decodeEventLog({
39450
- abi: dataRegistryAbi,
39451
- data: log.data,
39452
- topics: log.topics
39453
- });
39454
- if (decoded.eventName === "FileAdded") {
39455
- fileId = Number(decoded.args.fileId);
39456
- break;
39457
- }
39458
- } catch {
39459
- continue;
39460
- }
39461
- }
39462
- return {
39463
- fileId,
39464
- url: uploadResult.url,
39465
- size: uploadResult.size,
39466
- transactionHash: txHash
39467
- };
39468
- }
39469
- } catch (error) {
39470
- console.error("Failed to upload encrypted file with schema:", error);
39471
- throw new Error(
39472
- `Upload failed: ${error instanceof Error ? error.message : "Unknown error"}`
39473
- );
39474
- }
39475
- }
39476
40529
  /**
39477
40530
  * Registers a file URL directly on the blockchain with a schema ID.
39478
40531
  *
@@ -39527,214 +40580,74 @@ var DataController = class {
39527
40580
  transactionHash: txHash
39528
40581
  };
39529
40582
  } catch (error) {
39530
- console.error("Failed to register file with schema:", error);
39531
- throw new Error(
39532
- `Registration failed: ${error instanceof Error ? error.message : "Unknown error"}`
39533
- );
39534
- }
39535
- }
39536
- /**
39537
- * Gets the user's address from the wallet client.
39538
- *
39539
- * @returns Promise resolving to the user's wallet address
39540
- * @throws {Error} When no addresses are available in wallet client
39541
- */
39542
- async getUserAddress() {
39543
- const addresses = await this.context.walletClient.getAddresses();
39544
- if (addresses.length === 0) {
39545
- throw new Error("No addresses available in wallet client");
39546
- }
39547
- return addresses[0];
39548
- }
39549
- /**
39550
- * Adds a file with permissions to the DataRegistry contract.
39551
- *
39552
- * @param url - The file URL to register
39553
- * @param ownerAddress - The address of the file owner
39554
- * @param permissions - Array of permissions to set for the file
39555
- * @returns Promise resolving to file ID and transaction hash
39556
- * @throws {Error} When chain ID is not available
39557
- * @throws {ContractError} When contract execution fails
39558
- * @throws {Error} When transaction receipt is not available
39559
- * @throws {Error} When FileAdded event cannot be parsed
39560
- *
39561
- * This method handles the core logic of registering a file
39562
- * with specific permissions on the DataRegistry contract. It can be used
39563
- * by both direct transactions and relayer services.
39564
- */
39565
- async addFileWithPermissions(url, ownerAddress, permissions = []) {
39566
- try {
39567
- const chainId = this.context.walletClient.chain?.id;
39568
- if (!chainId) {
39569
- throw new Error("Chain ID not available");
39570
- }
39571
- const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
39572
- const dataRegistryAbi = getAbi("DataRegistry");
39573
- const txHash = await this.context.walletClient.writeContract({
39574
- address: dataRegistryAddress,
39575
- abi: dataRegistryAbi,
39576
- functionName: "addFileWithPermissions",
39577
- args: [url, ownerAddress, permissions],
39578
- account: this.context.walletClient.account || ownerAddress,
39579
- chain: this.context.walletClient.chain || null
39580
- });
39581
- const receipt = await this.context.publicClient.waitForTransactionReceipt(
39582
- {
39583
- hash: txHash,
39584
- timeout: 3e4
39585
- // 30 seconds timeout
39586
- }
39587
- );
39588
- let fileId = 0;
39589
- for (const log of receipt.logs) {
39590
- try {
39591
- const decoded = decodeEventLog({
39592
- abi: dataRegistryAbi,
39593
- data: log.data,
39594
- topics: log.topics
39595
- });
39596
- if (decoded.eventName === "FileAdded") {
39597
- fileId = Number(decoded.args.fileId);
39598
- break;
39599
- }
39600
- } catch {
39601
- continue;
39602
- }
39603
- }
39604
- return {
39605
- fileId,
39606
- transactionHash: txHash
39607
- };
39608
- } catch (error) {
39609
- console.error("Failed to add file with permissions:", error);
39610
- throw new Error(
39611
- `Failed to add file with permissions: ${error instanceof Error ? error.message : "Unknown error"}`
39612
- );
39613
- }
39614
- }
39615
- /**
39616
- * Adds a file to the registry with permissions and schema.
39617
- * This combines the functionality of addFileWithPermissions and schema validation.
39618
- *
39619
- * @param url - The URL of the file to register
39620
- * @param ownerAddress - The address of the file owner
39621
- * @param permissions - Array of permissions to grant (account and encrypted key)
39622
- * @param schemaId - The schema ID to associate with the file (0 for no schema)
39623
- * @returns Promise resolving to object with fileId and transactionHash
39624
- * @throws {Error} When chain ID is not available
39625
- * @throws {ContractError} When contract execution fails
39626
- * @throws {Error} When transaction receipt is not available
39627
- * @throws {Error} When FileAdded event cannot be parsed
39628
- */
39629
- async addFileWithPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0) {
39630
- try {
39631
- const chainId = this.context.walletClient.chain?.id;
39632
- if (!chainId) {
39633
- throw new Error("Chain ID not available");
39634
- }
39635
- const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
39636
- const dataRegistryAbi = getAbi("DataRegistry");
39637
- const txHash = await this.context.walletClient.writeContract({
39638
- address: dataRegistryAddress,
39639
- abi: dataRegistryAbi,
39640
- functionName: "addFileWithPermissionsAndSchema",
39641
- args: [url, ownerAddress, permissions, BigInt(schemaId)],
39642
- account: this.context.walletClient.account || ownerAddress,
39643
- chain: this.context.walletClient.chain || null
39644
- });
39645
- const receipt = await this.context.publicClient.waitForTransactionReceipt(
39646
- {
39647
- hash: txHash,
39648
- timeout: 3e4
39649
- // 30 seconds timeout
39650
- }
39651
- );
39652
- let fileId = 0;
39653
- for (const log of receipt.logs) {
39654
- try {
39655
- const decoded = decodeEventLog({
39656
- abi: dataRegistryAbi,
39657
- data: log.data,
39658
- topics: log.topics
39659
- });
39660
- if (decoded.eventName === "FileAdded") {
39661
- fileId = Number(decoded.args.fileId);
39662
- break;
39663
- }
39664
- } catch {
39665
- continue;
39666
- }
39667
- }
39668
- return {
39669
- fileId,
39670
- transactionHash: txHash
39671
- };
39672
- } catch (error) {
39673
- console.error("Failed to add file with permissions and schema:", error);
40583
+ console.error("Failed to register file with schema:", error);
39674
40584
  throw new Error(
39675
- `Failed to add file with permissions and schema: ${error instanceof Error ? error.message : "Unknown error"}`
40585
+ `Registration failed: ${error instanceof Error ? error.message : "Unknown error"}`
39676
40586
  );
39677
40587
  }
39678
40588
  }
39679
40589
  /**
39680
- * Adds a new schema to the DataRefinerRegistry.
40590
+ * Gets the user's address from the wallet client.
39681
40591
  *
39682
- * @deprecated Since v2.0.0 - Use vana.schemas.create() instead for the high-level API with automatic IPFS upload
40592
+ * @returns Promise resolving to the user's wallet address
40593
+ * @throws {Error} When no addresses are available in wallet client
40594
+ */
40595
+ async getUserAddress() {
40596
+ const addresses = await this.context.walletClient.getAddresses();
40597
+ if (addresses.length === 0) {
40598
+ throw new Error("No addresses available in wallet client");
40599
+ }
40600
+ return addresses[0];
40601
+ }
40602
+ /**
40603
+ * Adds a file with permissions to the DataRegistry contract.
39683
40604
  *
39684
- * Migration guide:
39685
- * ```typescript
39686
- * // Old way (deprecated):
39687
- * const result = await vana.data.addSchema({
39688
- * name: "UserProfile",
39689
- * type: "JSON",
39690
- * definitionUrl: "ipfs://..."
39691
- * });
40605
+ * @param url - The file URL to register
40606
+ * @param ownerAddress - The address of the file owner
40607
+ * @param permissions - Array of permissions to set for the file
40608
+ * @returns Promise resolving to file ID and transaction hash
40609
+ * @throws {Error} When chain ID is not available
40610
+ * @throws {ContractError} When contract execution fails
40611
+ * @throws {Error} When transaction receipt is not available
40612
+ * @throws {Error} When FileAdded event cannot be parsed
39692
40613
  *
39693
- * // New way:
39694
- * const result = await vana.schemas.create({
39695
- * name: "UserProfile",
39696
- * type: "JSON",
39697
- * definition: schemaObject // Automatically uploads to IPFS
39698
- * });
39699
- * ```
39700
- * @param params - Schema parameters including name, type, and definition URL
39701
- * @returns Promise resolving to the new schema ID and transaction hash
40614
+ * This method handles the core logic of registering a file
40615
+ * with specific permissions on the DataRegistry contract. It can be used
40616
+ * by both direct transactions and relayer services.
39702
40617
  */
39703
- async addSchema(params) {
40618
+ async addFileWithPermissions(url, ownerAddress, permissions = []) {
39704
40619
  try {
39705
40620
  const chainId = this.context.walletClient.chain?.id;
39706
40621
  if (!chainId) {
39707
40622
  throw new Error("Chain ID not available");
39708
40623
  }
39709
- const dataRefinerRegistryAddress = getContractAddress(
39710
- chainId,
39711
- "DataRefinerRegistry"
39712
- );
39713
- const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
40624
+ const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
40625
+ const dataRegistryAbi = getAbi("DataRegistry");
39714
40626
  const txHash = await this.context.walletClient.writeContract({
39715
- address: dataRefinerRegistryAddress,
39716
- abi: dataRefinerRegistryAbi,
39717
- functionName: "addSchema",
39718
- args: [params.name, params.type, params.definitionUrl],
39719
- account: this.context.walletClient.account || await this.getUserAddress(),
40627
+ address: dataRegistryAddress,
40628
+ abi: dataRegistryAbi,
40629
+ functionName: "addFileWithPermissions",
40630
+ args: [url, ownerAddress, permissions],
40631
+ account: this.context.walletClient.account || ownerAddress,
39720
40632
  chain: this.context.walletClient.chain || null
39721
40633
  });
39722
40634
  const receipt = await this.context.publicClient.waitForTransactionReceipt(
39723
40635
  {
39724
40636
  hash: txHash,
39725
40637
  timeout: 3e4
40638
+ // 30 seconds timeout
39726
40639
  }
39727
40640
  );
39728
- let schemaId = 0;
40641
+ let fileId = 0;
39729
40642
  for (const log of receipt.logs) {
39730
40643
  try {
39731
40644
  const decoded = decodeEventLog({
39732
- abi: dataRefinerRegistryAbi,
40645
+ abi: dataRegistryAbi,
39733
40646
  data: log.data,
39734
40647
  topics: log.topics
39735
40648
  });
39736
- if (decoded.eventName === "SchemaAdded") {
39737
- schemaId = Number(decoded.args.schemaId);
40649
+ if (decoded.eventName === "FileAdded") {
40650
+ fileId = Number(decoded.args.fileId);
39738
40651
  break;
39739
40652
  }
39740
40653
  } catch {
@@ -39742,107 +40655,78 @@ var DataController = class {
39742
40655
  }
39743
40656
  }
39744
40657
  return {
39745
- schemaId,
40658
+ fileId,
39746
40659
  transactionHash: txHash
39747
40660
  };
39748
40661
  } catch (error) {
39749
- console.error("Failed to add schema:", error);
40662
+ console.error("Failed to add file with permissions:", error);
39750
40663
  throw new Error(
39751
- `Failed to add schema: ${error instanceof Error ? error.message : "Unknown error"}`
40664
+ `Failed to add file with permissions: ${error instanceof Error ? error.message : "Unknown error"}`
39752
40665
  );
39753
40666
  }
39754
40667
  }
39755
40668
  /**
39756
- * Retrieves a schema by its ID.
39757
- *
39758
- * @deprecated Since v2.0.0 - Use vana.schemas.get() instead
39759
- *
39760
- * Migration guide:
39761
- * ```typescript
39762
- * // Old way (deprecated):
39763
- * const schema = await vana.data.getSchema(schemaId);
40669
+ * Adds a file to the registry with permissions and schema.
40670
+ * This combines the functionality of addFileWithPermissions and schema validation.
39764
40671
  *
39765
- * // New way:
39766
- * const schema = await vana.schemas.get(schemaId);
39767
- * ```
39768
- * @param schemaId - The schema ID to retrieve
39769
- * @returns Promise resolving to the schema information
40672
+ * @param url - The URL of the file to register
40673
+ * @param ownerAddress - The address of the file owner
40674
+ * @param permissions - Array of permissions to grant (account and encrypted key)
40675
+ * @param schemaId - The schema ID to associate with the file (0 for no schema)
40676
+ * @returns Promise resolving to object with fileId and transactionHash
40677
+ * @throws {Error} When chain ID is not available
40678
+ * @throws {ContractError} When contract execution fails
40679
+ * @throws {Error} When transaction receipt is not available
40680
+ * @throws {Error} When FileAdded event cannot be parsed
39770
40681
  */
39771
- async getSchema(schemaId) {
40682
+ async addFileWithPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0) {
39772
40683
  try {
39773
40684
  const chainId = this.context.walletClient.chain?.id;
39774
40685
  if (!chainId) {
39775
40686
  throw new Error("Chain ID not available");
39776
40687
  }
39777
- const dataRefinerRegistryAddress = getContractAddress(
39778
- chainId,
39779
- "DataRefinerRegistry"
39780
- );
39781
- const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
39782
- const dataRefinerRegistry = getContract({
39783
- address: dataRefinerRegistryAddress,
39784
- abi: dataRefinerRegistryAbi,
39785
- client: this.context.walletClient
40688
+ const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
40689
+ const dataRegistryAbi = getAbi("DataRegistry");
40690
+ const txHash = await this.context.walletClient.writeContract({
40691
+ address: dataRegistryAddress,
40692
+ abi: dataRegistryAbi,
40693
+ functionName: "addFileWithPermissionsAndSchema",
40694
+ args: [url, ownerAddress, permissions, BigInt(schemaId)],
40695
+ account: this.context.walletClient.account || ownerAddress,
40696
+ chain: this.context.walletClient.chain || null
39786
40697
  });
39787
- const schemaData = await dataRefinerRegistry.read.schemas([
39788
- BigInt(schemaId)
39789
- ]);
39790
- if (!schemaData) {
39791
- throw new Error("Schema not found");
39792
- }
39793
- const schemaObj = schemaData;
39794
- if (!schemaObj.name || !schemaObj.typ || !schemaObj.definitionUrl) {
39795
- throw new Error("Incomplete schema data");
40698
+ const receipt = await this.context.publicClient.waitForTransactionReceipt(
40699
+ {
40700
+ hash: txHash,
40701
+ timeout: 3e4
40702
+ // 30 seconds timeout
40703
+ }
40704
+ );
40705
+ let fileId = 0;
40706
+ for (const log of receipt.logs) {
40707
+ try {
40708
+ const decoded = decodeEventLog({
40709
+ abi: dataRegistryAbi,
40710
+ data: log.data,
40711
+ topics: log.topics
40712
+ });
40713
+ if (decoded.eventName === "FileAdded") {
40714
+ fileId = Number(decoded.args.fileId);
40715
+ break;
40716
+ }
40717
+ } catch {
40718
+ continue;
40719
+ }
39796
40720
  }
39797
40721
  return {
39798
- id: schemaId,
39799
- name: schemaObj.name,
39800
- type: schemaObj.typ,
39801
- definitionUrl: schemaObj.definitionUrl
40722
+ fileId,
40723
+ transactionHash: txHash
39802
40724
  };
39803
40725
  } catch (error) {
39804
- console.error("Failed to get schema:", error);
40726
+ console.error("Failed to add file with permissions and schema:", error);
39805
40727
  throw new Error(
39806
- `Failed to get schema ${schemaId}: ${error instanceof Error ? error.message : "Unknown error"}`
39807
- );
39808
- }
39809
- }
39810
- /**
39811
- * Gets the total number of schemas in the registry.
39812
- *
39813
- * @deprecated Since v2.0.0 - Use vana.schemas.count() instead
39814
- *
39815
- * Migration guide:
39816
- * ```typescript
39817
- * // Old way (deprecated):
39818
- * const count = await vana.data.getSchemasCount();
39819
- *
39820
- * // New way:
39821
- * const count = await vana.schemas.count();
39822
- * ```
39823
- * @returns Promise resolving to the total schema count
39824
- */
39825
- async getSchemasCount() {
39826
- try {
39827
- const chainId = this.context.walletClient.chain?.id;
39828
- if (!chainId) {
39829
- throw new Error("Chain ID not available");
39830
- }
39831
- const dataRefinerRegistryAddress = getContractAddress(
39832
- chainId,
39833
- "DataRefinerRegistry"
40728
+ `Failed to add file with permissions and schema: ${error instanceof Error ? error.message : "Unknown error"}`
39834
40729
  );
39835
- const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
39836
- const dataRefinerRegistry = getContract({
39837
- address: dataRefinerRegistryAddress,
39838
- abi: dataRefinerRegistryAbi,
39839
- client: this.context.walletClient
39840
- });
39841
- const count = await dataRefinerRegistry.read.schemasCount();
39842
- return Number(count);
39843
- } catch (error) {
39844
- console.error("Failed to get schemas count:", error);
39845
- return 0;
39846
40730
  }
39847
40731
  }
39848
40732
  /**
@@ -39925,7 +40809,7 @@ var DataController = class {
39925
40809
  "DataRefinerRegistry"
39926
40810
  );
39927
40811
  const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
39928
- const dataRefinerRegistry = getContract({
40812
+ const dataRefinerRegistry = getContract2({
39929
40813
  address: dataRefinerRegistryAddress,
39930
40814
  abi: dataRefinerRegistryAbi,
39931
40815
  client: this.context.walletClient
@@ -39968,7 +40852,7 @@ var DataController = class {
39968
40852
  "DataRefinerRegistry"
39969
40853
  );
39970
40854
  const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
39971
- const dataRefinerRegistry = getContract({
40855
+ const dataRefinerRegistry = getContract2({
39972
40856
  address: dataRefinerRegistryAddress,
39973
40857
  abi: dataRefinerRegistryAbi,
39974
40858
  client: this.context.walletClient
@@ -39998,7 +40882,7 @@ var DataController = class {
39998
40882
  "DataRefinerRegistry"
39999
40883
  );
40000
40884
  const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
40001
- const dataRefinerRegistry = getContract({
40885
+ const dataRefinerRegistry = getContract2({
40002
40886
  address: dataRefinerRegistryAddress,
40003
40887
  abi: dataRefinerRegistryAbi,
40004
40888
  client: this.context.walletClient
@@ -40066,27 +40950,19 @@ var DataController = class {
40066
40950
  */
40067
40951
  async uploadFileWithPermissions(data, permissions, filename, providerName) {
40068
40952
  try {
40069
- const userEncryptionKey = await generateEncryptionKey(
40070
- this.context.walletClient,
40071
- this.context.platform,
40072
- DEFAULT_ENCRYPTION_SEED
40073
- );
40074
- const encryptedData = await encryptBlobWithSignedKey(
40953
+ const uploadResult = await this.uploadToStorage(
40075
40954
  data,
40076
- userEncryptionKey,
40077
- this.context.platform
40078
- );
40079
- if (!this.context.storageManager) {
40080
- throw new Error(
40081
- "Storage manager not configured. Please provide storage providers in VanaConfig."
40082
- );
40083
- }
40084
- const uploadResult = await this.context.storageManager.upload(
40085
- encryptedData,
40086
40955
  filename,
40956
+ true,
40957
+ // Always encrypt for uploadFileWithPermissions
40087
40958
  providerName
40088
40959
  );
40089
40960
  const userAddress = await this.getUserAddress();
40961
+ const userEncryptionKey = await generateEncryptionKey(
40962
+ this.context.walletClient,
40963
+ this.context.platform,
40964
+ DEFAULT_ENCRYPTION_SEED
40965
+ );
40090
40966
  const encryptedPermissions = await Promise.all(
40091
40967
  permissions.map(async (permission) => {
40092
40968
  const encryptedKey = await encryptWithWalletPublicKey(
@@ -40127,6 +41003,70 @@ var DataController = class {
40127
41003
  );
40128
41004
  }
40129
41005
  }
41006
+ /**
41007
+ * Uploads content to storage without registering it on the blockchain.
41008
+ * This method only handles the storage upload and returns the file URL.
41009
+ *
41010
+ * @param content - The content to upload (string, Blob, Buffer, or object - objects will be JSON stringified)
41011
+ * @param filename - Optional filename for the uploaded file (defaults to timestamp-based name)
41012
+ * @param encrypt - Optional flag to encrypt the content before upload
41013
+ * @param providerName - Optional specific storage provider to use
41014
+ * @returns Promise resolving to the storage upload result with url, size, and contentType
41015
+ */
41016
+ async uploadToStorage(content, filename, encrypt = false, providerName) {
41017
+ try {
41018
+ let blob;
41019
+ if (content instanceof Blob) {
41020
+ blob = content;
41021
+ } else if (typeof content === "string") {
41022
+ blob = new Blob([content], { type: "text/plain" });
41023
+ } else if (content instanceof Buffer) {
41024
+ const arrayBuffer = content.buffer.slice(
41025
+ content.byteOffset,
41026
+ content.byteOffset + content.byteLength
41027
+ );
41028
+ blob = new Blob([arrayBuffer], { type: "application/octet-stream" });
41029
+ } else {
41030
+ blob = new Blob([JSON.stringify(content)], {
41031
+ type: "application/json"
41032
+ });
41033
+ }
41034
+ let finalBlob = blob;
41035
+ if (encrypt) {
41036
+ const encryptionKey = await generateEncryptionKey(
41037
+ this.context.walletClient,
41038
+ this.context.platform,
41039
+ DEFAULT_ENCRYPTION_SEED
41040
+ );
41041
+ finalBlob = await encryptBlobWithSignedKey(
41042
+ blob,
41043
+ encryptionKey,
41044
+ this.context.platform
41045
+ );
41046
+ }
41047
+ if (!this.context.storageManager) {
41048
+ if (this.context.validateStorageRequired) {
41049
+ this.context.validateStorageRequired();
41050
+ throw new Error("Storage validation failed");
41051
+ } else {
41052
+ throw new Error(
41053
+ "Storage manager not configured. Please provide storage providers in VanaConfig."
41054
+ );
41055
+ }
41056
+ }
41057
+ const finalFilename = filename || `upload-${Date.now()}.dat`;
41058
+ const uploadResult = await this.context.storageManager.upload(
41059
+ finalBlob,
41060
+ finalFilename,
41061
+ providerName
41062
+ );
41063
+ return uploadResult;
41064
+ } catch (error) {
41065
+ throw new Error(
41066
+ `Upload failed: ${error instanceof Error ? error.message : "Unknown error"}`
41067
+ );
41068
+ }
41069
+ }
40130
41070
  /**
40131
41071
  * Adds a permission for a party to access an existing file.
40132
41072
  *
@@ -40222,7 +41162,7 @@ var DataController = class {
40222
41162
  }
40223
41163
  const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
40224
41164
  const dataRegistryAbi = getAbi("DataRegistry");
40225
- const dataRegistry = getContract({
41165
+ const dataRegistry = getContract2({
40226
41166
  address: dataRegistryAddress,
40227
41167
  abi: dataRegistryAbi,
40228
41168
  client: this.context.walletClient
@@ -40546,7 +41486,7 @@ var DataController = class {
40546
41486
  */
40547
41487
  async getValidatedSchema(schemaId) {
40548
41488
  try {
40549
- const schema = await this.getSchema(schemaId);
41489
+ const schema = await fetchSchemaFromChain(this.context, schemaId);
40550
41490
  const dataSchema = await this.fetchAndValidateSchema(
40551
41491
  schema.definitionUrl
40552
41492
  );
@@ -40571,7 +41511,7 @@ var DataController = class {
40571
41511
  };
40572
41512
 
40573
41513
  // src/controllers/schemas.ts
40574
- import { getContract as getContract2, decodeEventLog as decodeEventLog2 } from "viem";
41514
+ import { decodeEventLog as decodeEventLog2 } from "viem";
40575
41515
  var SchemaController = class {
40576
41516
  constructor(context) {
40577
41517
  this.context = context;
@@ -40723,36 +41663,7 @@ var SchemaController = class {
40723
41663
  */
40724
41664
  async get(schemaId) {
40725
41665
  try {
40726
- const chainId = this.context.walletClient.chain?.id;
40727
- if (!chainId) {
40728
- throw new Error("Chain ID not available");
40729
- }
40730
- const dataRefinerRegistryAddress = getContractAddress(
40731
- chainId,
40732
- "DataRefinerRegistry"
40733
- );
40734
- const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
40735
- const dataRefinerRegistry = getContract2({
40736
- address: dataRefinerRegistryAddress,
40737
- abi: dataRefinerRegistryAbi,
40738
- client: this.context.publicClient
40739
- });
40740
- const schemaData = await dataRefinerRegistry.read.schemas([
40741
- BigInt(schemaId)
40742
- ]);
40743
- if (!schemaData) {
40744
- throw new Error(`Schema with ID ${schemaId} not found`);
40745
- }
40746
- const schemaObj = schemaData;
40747
- if (!schemaObj.name || !schemaObj.typ || !schemaObj.definitionUrl) {
40748
- throw new Error("Incomplete schema data");
40749
- }
40750
- return {
40751
- id: schemaId,
40752
- name: schemaObj.name,
40753
- type: schemaObj.typ,
40754
- definitionUrl: schemaObj.definitionUrl
40755
- };
41666
+ return await fetchSchemaFromChain(this.context, schemaId);
40756
41667
  } catch (error) {
40757
41668
  throw new Error(
40758
41669
  `Failed to get schema: ${error instanceof Error ? error.message : "Unknown error"}`
@@ -40772,22 +41683,7 @@ var SchemaController = class {
40772
41683
  */
40773
41684
  async count() {
40774
41685
  try {
40775
- const chainId = this.context.walletClient.chain?.id;
40776
- if (!chainId) {
40777
- throw new Error("Chain ID not available");
40778
- }
40779
- const dataRefinerRegistryAddress = getContractAddress(
40780
- chainId,
40781
- "DataRefinerRegistry"
40782
- );
40783
- const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
40784
- const dataRefinerRegistry = getContract2({
40785
- address: dataRefinerRegistryAddress,
40786
- abi: dataRefinerRegistryAbi,
40787
- client: this.context.publicClient
40788
- });
40789
- const count = await dataRefinerRegistry.read.schemasCount();
40790
- return Number(count);
41686
+ return await fetchSchemaCountFromChain(this.context);
40791
41687
  } catch (error) {
40792
41688
  throw new Error(
40793
41689
  `Failed to get schemas count: ${error instanceof Error ? error.message : "Unknown error"}`