@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.
@@ -119,6 +119,25 @@ var init_error_utils = __esm({
119
119
  }
120
120
  });
121
121
 
122
+ // src/utils/lazy-import.ts
123
+ function lazyImport(importFn) {
124
+ let cached = null;
125
+ return () => {
126
+ if (!cached) {
127
+ cached = importFn().catch((err) => {
128
+ cached = null;
129
+ throw new Error("Failed to load module", { cause: err });
130
+ });
131
+ }
132
+ return cached;
133
+ };
134
+ }
135
+ var init_lazy_import = __esm({
136
+ "src/utils/lazy-import.ts"() {
137
+ "use strict";
138
+ }
139
+ });
140
+
122
141
  // src/utils/ipfs.ts
123
142
  var ipfs_exports = {};
124
143
  __export(ipfs_exports, {
@@ -232,20 +251,21 @@ __export(browser_exports, {
232
251
  BrowserPlatformAdapter: () => BrowserPlatformAdapter,
233
252
  browserPlatformAdapter: () => browserPlatformAdapter
234
253
  });
235
- var openpgp2, BrowserCryptoAdapter, BrowserPGPAdapter, BrowserHttpAdapter, BrowserCacheAdapter, BrowserPlatformAdapter, browserPlatformAdapter;
254
+ var getOpenPGP2, BrowserCryptoAdapter, BrowserPGPAdapter, BrowserHttpAdapter, BrowserCacheAdapter, BrowserPlatformAdapter, browserPlatformAdapter;
236
255
  var init_browser = __esm({
237
256
  "src/platform/browser.ts"() {
238
257
  "use strict";
239
- openpgp2 = __toESM(require("openpgp"), 1);
240
258
  init_crypto_utils();
241
259
  init_pgp_utils();
242
260
  init_error_utils();
261
+ init_lazy_import();
262
+ getOpenPGP2 = lazyImport(() => import("openpgp"));
243
263
  BrowserCryptoAdapter = class {
244
264
  async encryptWithPublicKey(data, publicKeyHex) {
245
265
  try {
246
- const eccrypto2 = await import("eccrypto-js");
266
+ const eccrypto = await import("eccrypto-js");
247
267
  const publicKeyBuffer = Buffer.from(publicKeyHex, "hex");
248
- const encrypted = await eccrypto2.encrypt(
268
+ const encrypted = await eccrypto.encrypt(
249
269
  publicKeyBuffer,
250
270
  Buffer.from(data, "utf8")
251
271
  );
@@ -262,12 +282,12 @@ var init_browser = __esm({
262
282
  }
263
283
  async decryptWithPrivateKey(encryptedData, privateKeyHex) {
264
284
  try {
265
- const eccrypto2 = await import("eccrypto-js");
285
+ const eccrypto = await import("eccrypto-js");
266
286
  const privateKeyBuffer = processWalletPrivateKey(privateKeyHex);
267
287
  const encryptedBuffer = Buffer.from(encryptedData, "hex");
268
288
  const { iv, ephemPublicKey, ciphertext, mac } = parseEncryptedDataBuffer(encryptedBuffer);
269
289
  const encryptedObj = { iv, ephemPublicKey, ciphertext, mac };
270
- const decryptedBuffer = await eccrypto2.decrypt(
290
+ const decryptedBuffer = await eccrypto.decrypt(
271
291
  privateKeyBuffer,
272
292
  encryptedObj
273
293
  );
@@ -278,11 +298,11 @@ var init_browser = __esm({
278
298
  }
279
299
  async generateKeyPair() {
280
300
  try {
281
- const eccrypto2 = await import("eccrypto-js");
301
+ const eccrypto = await import("eccrypto-js");
282
302
  const privateKeyBytes = new Uint8Array(32);
283
303
  crypto.getRandomValues(privateKeyBytes);
284
304
  const privateKey = Buffer.from(privateKeyBytes);
285
- const publicKey = eccrypto2.getPublicCompressed(privateKey);
305
+ const publicKey = eccrypto.getPublicCompressed(privateKey);
286
306
  return {
287
307
  privateKey: privateKey.toString("hex"),
288
308
  publicKey: publicKey.toString("hex")
@@ -293,9 +313,9 @@ var init_browser = __esm({
293
313
  }
294
314
  async encryptWithWalletPublicKey(data, publicKey) {
295
315
  try {
296
- const eccrypto2 = await import("eccrypto-js");
316
+ const eccrypto = await import("eccrypto-js");
297
317
  const uncompressedKey = processWalletPublicKey(publicKey);
298
- const encryptedBuffer = await eccrypto2.encrypt(
318
+ const encryptedBuffer = await eccrypto.encrypt(
299
319
  uncompressedKey,
300
320
  Buffer.from(data)
301
321
  );
@@ -312,12 +332,12 @@ var init_browser = __esm({
312
332
  }
313
333
  async decryptWithWalletPrivateKey(encryptedData, privateKey) {
314
334
  try {
315
- const eccrypto2 = await import("eccrypto-js");
335
+ const eccrypto = await import("eccrypto-js");
316
336
  const privateKeyBuffer = processWalletPrivateKey(privateKey);
317
337
  const encryptedBuffer = Buffer.from(encryptedData, "hex");
318
338
  const { iv, ephemPublicKey, ciphertext, mac } = parseEncryptedDataBuffer(encryptedBuffer);
319
339
  const encryptedObj = { iv, ephemPublicKey, ciphertext, mac };
320
- const decryptedBuffer = await eccrypto2.decrypt(
340
+ const decryptedBuffer = await eccrypto.decrypt(
321
341
  privateKeyBuffer,
322
342
  encryptedObj
323
343
  );
@@ -328,11 +348,11 @@ var init_browser = __esm({
328
348
  }
329
349
  async encryptWithPassword(data, password) {
330
350
  try {
331
- const openpgp3 = await import("openpgp");
332
- const message = await openpgp3.createMessage({
351
+ const openpgp = await getOpenPGP2();
352
+ const message = await openpgp.createMessage({
333
353
  binary: data
334
354
  });
335
- const encrypted = await openpgp3.encrypt({
355
+ const encrypted = await openpgp.encrypt({
336
356
  message,
337
357
  passwords: [password],
338
358
  format: "binary"
@@ -346,11 +366,11 @@ var init_browser = __esm({
346
366
  }
347
367
  async decryptWithPassword(encryptedData, password) {
348
368
  try {
349
- const openpgp3 = await import("openpgp");
350
- const message = await openpgp3.readMessage({
369
+ const openpgp = await getOpenPGP2();
370
+ const message = await openpgp.readMessage({
351
371
  binaryMessage: encryptedData
352
372
  });
353
- const { data: decrypted } = await openpgp3.decrypt({
373
+ const { data: decrypted } = await openpgp.decrypt({
354
374
  message,
355
375
  passwords: [password],
356
376
  format: "binary"
@@ -364,12 +384,13 @@ var init_browser = __esm({
364
384
  BrowserPGPAdapter = class {
365
385
  async encrypt(data, publicKeyArmored) {
366
386
  try {
367
- const publicKey = await openpgp2.readKey({ armoredKey: publicKeyArmored });
368
- const encrypted = await openpgp2.encrypt({
369
- message: await openpgp2.createMessage({ text: data }),
387
+ const openpgp = await getOpenPGP2();
388
+ const publicKey = await openpgp.readKey({ armoredKey: publicKeyArmored });
389
+ const encrypted = await openpgp.encrypt({
390
+ message: await openpgp.createMessage({ text: data }),
370
391
  encryptionKeys: publicKey,
371
392
  config: {
372
- preferredCompressionAlgorithm: openpgp2.enums.compression.zlib
393
+ preferredCompressionAlgorithm: openpgp.enums.compression.zlib
373
394
  }
374
395
  });
375
396
  return encrypted;
@@ -379,13 +400,14 @@ var init_browser = __esm({
379
400
  }
380
401
  async decrypt(encryptedData, privateKeyArmored) {
381
402
  try {
382
- const privateKey = await openpgp2.readPrivateKey({
403
+ const openpgp = await getOpenPGP2();
404
+ const privateKey = await openpgp.readPrivateKey({
383
405
  armoredKey: privateKeyArmored
384
406
  });
385
- const message = await openpgp2.readMessage({
407
+ const message = await openpgp.readMessage({
386
408
  armoredMessage: encryptedData
387
409
  });
388
- const { data: decrypted } = await openpgp2.decrypt({
410
+ const { data: decrypted } = await openpgp.decrypt({
389
411
  message,
390
412
  decryptionKeys: privateKey
391
413
  });
@@ -396,8 +418,9 @@ var init_browser = __esm({
396
418
  }
397
419
  async generateKeyPair(options) {
398
420
  try {
421
+ const openpgp = await getOpenPGP2();
399
422
  const keyGenParams = getPGPKeyGenParams(options);
400
- const { privateKey, publicKey } = await openpgp2.generateKey(keyGenParams);
423
+ const { privateKey, publicKey } = await openpgp.generateKey(keyGenParams);
401
424
  return { publicKey, privateKey };
402
425
  } catch (error) {
403
426
  throw wrapCryptoError("PGP key generation", error);
@@ -597,8 +620,6 @@ __export(index_node_exports, {
597
620
  module.exports = __toCommonJS(index_node_exports);
598
621
 
599
622
  // src/platform/node.ts
600
- var import_crypto = require("crypto");
601
- var openpgp = __toESM(require("openpgp"), 1);
602
623
  init_crypto_utils();
603
624
  init_pgp_utils();
604
625
  init_error_utils();
@@ -627,29 +648,16 @@ async function streamToUint8Array(stream) {
627
648
  }
628
649
 
629
650
  // src/platform/node.ts
630
- var eccrypto = null;
631
- async function getEccrypto() {
632
- if (!eccrypto) {
633
- try {
634
- const eccryptoLib = await import("eccrypto");
635
- eccrypto = {
636
- encrypt: eccryptoLib.encrypt,
637
- decrypt: eccryptoLib.decrypt,
638
- getPublicCompressed: eccryptoLib.getPublicCompressed
639
- };
640
- } catch (error) {
641
- throw new Error(`Failed to load eccrypto library: ${error}`);
642
- }
643
- }
644
- return eccrypto;
645
- }
651
+ init_lazy_import();
652
+ var getOpenPGP = lazyImport(() => import("openpgp"));
653
+ var getEccrypto = lazyImport(() => import("eccrypto"));
646
654
  var NodeCryptoAdapter = class {
647
655
  async encryptWithPublicKey(data, publicKeyHex) {
648
656
  try {
649
- const eccryptoLib = await getEccrypto();
657
+ const eccrypto = await getEccrypto();
650
658
  const publicKey = Buffer.from(publicKeyHex, "hex");
651
659
  const message = Buffer.from(data, "utf8");
652
- const encrypted = await eccryptoLib.encrypt(publicKey, message);
660
+ const encrypted = await eccrypto.encrypt(publicKey, message);
653
661
  const result = Buffer.concat([
654
662
  encrypted.iv,
655
663
  encrypted.ephemPublicKey,
@@ -663,15 +671,12 @@ var NodeCryptoAdapter = class {
663
671
  }
664
672
  async decryptWithPrivateKey(encryptedData, privateKeyHex) {
665
673
  try {
666
- const eccryptoLib = await getEccrypto();
674
+ const eccrypto = await getEccrypto();
667
675
  const privateKeyBuffer = processWalletPrivateKey(privateKeyHex);
668
676
  const encryptedBuffer = Buffer.from(encryptedData, "hex");
669
677
  const { iv, ephemPublicKey, ciphertext, mac } = parseEncryptedDataBuffer(encryptedBuffer);
670
678
  const encryptedObj = { iv, ephemPublicKey, ciphertext, mac };
671
- const decrypted = await eccryptoLib.decrypt(
672
- privateKeyBuffer,
673
- encryptedObj
674
- );
679
+ const decrypted = await eccrypto.decrypt(privateKeyBuffer, encryptedObj);
675
680
  return decrypted.toString("utf8");
676
681
  } catch (error) {
677
682
  throw new Error(`Decryption failed: ${error}`);
@@ -679,9 +684,9 @@ var NodeCryptoAdapter = class {
679
684
  }
680
685
  async generateKeyPair() {
681
686
  try {
682
- const eccryptoLib = await getEccrypto();
683
- const privateKey = (0, import_crypto.randomBytes)(32);
684
- const publicKey = eccryptoLib.getPublicCompressed(privateKey);
687
+ const eccrypto = await getEccrypto();
688
+ const privateKey = eccrypto.generatePrivate();
689
+ const publicKey = eccrypto.getPublicCompressed(privateKey);
685
690
  return {
686
691
  privateKey: privateKey.toString("hex"),
687
692
  publicKey: publicKey.toString("hex")
@@ -692,9 +697,9 @@ var NodeCryptoAdapter = class {
692
697
  }
693
698
  async encryptWithWalletPublicKey(data, publicKey) {
694
699
  try {
695
- const eccryptoLib = await getEccrypto();
700
+ const eccrypto = await getEccrypto();
696
701
  const uncompressedKey = processWalletPublicKey(publicKey);
697
- const encrypted = await eccryptoLib.encrypt(
702
+ const encrypted = await eccrypto.encrypt(
698
703
  uncompressedKey,
699
704
  Buffer.from(data)
700
705
  );
@@ -711,12 +716,12 @@ var NodeCryptoAdapter = class {
711
716
  }
712
717
  async decryptWithWalletPrivateKey(encryptedData, privateKey) {
713
718
  try {
714
- const eccryptoLib = await getEccrypto();
719
+ const eccrypto = await getEccrypto();
715
720
  const privateKeyBuffer = processWalletPrivateKey(privateKey);
716
721
  const encryptedBuffer = Buffer.from(encryptedData, "hex");
717
722
  const { iv, ephemPublicKey, ciphertext, mac } = parseEncryptedDataBuffer(encryptedBuffer);
718
723
  const encryptedObj = { iv, ephemPublicKey, ciphertext, mac };
719
- const decryptedBuffer = await eccryptoLib.decrypt(
724
+ const decryptedBuffer = await eccrypto.decrypt(
720
725
  privateKeyBuffer,
721
726
  encryptedObj
722
727
  );
@@ -727,6 +732,7 @@ var NodeCryptoAdapter = class {
727
732
  }
728
733
  async encryptWithPassword(data, password) {
729
734
  try {
735
+ const openpgp = await getOpenPGP();
730
736
  const message = await openpgp.createMessage({
731
737
  binary: data
732
738
  });
@@ -750,6 +756,7 @@ var NodeCryptoAdapter = class {
750
756
  }
751
757
  async decryptWithPassword(encryptedData, password) {
752
758
  try {
759
+ const openpgp = await getOpenPGP();
753
760
  const message = await openpgp.readMessage({
754
761
  binaryMessage: encryptedData
755
762
  });
@@ -767,6 +774,7 @@ var NodeCryptoAdapter = class {
767
774
  var NodePGPAdapter = class {
768
775
  async encrypt(data, publicKeyArmored) {
769
776
  try {
777
+ const openpgp = await getOpenPGP();
770
778
  const publicKey = await openpgp.readKey({ armoredKey: publicKeyArmored });
771
779
  const encrypted = await openpgp.encrypt({
772
780
  message: await openpgp.createMessage({ text: data }),
@@ -782,6 +790,7 @@ var NodePGPAdapter = class {
782
790
  }
783
791
  async decrypt(encryptedData, privateKeyArmored) {
784
792
  try {
793
+ const openpgp = await getOpenPGP();
785
794
  const privateKey = await openpgp.readPrivateKey({
786
795
  armoredKey: privateKeyArmored
787
796
  });
@@ -799,6 +808,7 @@ var NodePGPAdapter = class {
799
808
  }
800
809
  async generateKeyPair(options) {
801
810
  try {
811
+ const openpgp = await getOpenPGP();
802
812
  const keyGenParams = getPGPKeyGenParams(options);
803
813
  const { privateKey, publicKey } = await openpgp.generateKey(keyGenParams);
804
814
  return { publicKey, privateKey };
@@ -1282,11 +1292,11 @@ var import_viem = require("viem");
1282
1292
  var EVENT_MAPPINGS = {
1283
1293
  // Permission operations
1284
1294
  grant: {
1285
- contract: "DataPermissions",
1295
+ contract: "DataPortabilityPermissions",
1286
1296
  event: "PermissionAdded"
1287
1297
  },
1288
1298
  revoke: {
1289
- contract: "DataPermissions",
1299
+ contract: "DataPortabilityPermissions",
1290
1300
  event: "PermissionRevoked"
1291
1301
  },
1292
1302
  trustServer: {
@@ -6500,6 +6510,22 @@ var DataPortabilityPermissionsABI = [
6500
6510
  name: "InvalidNonce",
6501
6511
  type: "error"
6502
6512
  },
6513
+ {
6514
+ inputs: [
6515
+ {
6516
+ internalType: "uint256",
6517
+ name: "filesLength",
6518
+ type: "uint256"
6519
+ },
6520
+ {
6521
+ internalType: "uint256",
6522
+ name: "permissionsLength",
6523
+ type: "uint256"
6524
+ }
6525
+ ],
6526
+ name: "InvalidPermissionsLength",
6527
+ type: "error"
6528
+ },
6503
6529
  {
6504
6530
  inputs: [],
6505
6531
  name: "InvalidSignature",
@@ -6831,6 +6857,84 @@ var DataPortabilityPermissionsABI = [
6831
6857
  stateMutability: "nonpayable",
6832
6858
  type: "function"
6833
6859
  },
6860
+ {
6861
+ inputs: [
6862
+ {
6863
+ components: [
6864
+ {
6865
+ internalType: "uint256",
6866
+ name: "nonce",
6867
+ type: "uint256"
6868
+ },
6869
+ {
6870
+ internalType: "uint256",
6871
+ name: "granteeId",
6872
+ type: "uint256"
6873
+ },
6874
+ {
6875
+ internalType: "string",
6876
+ name: "grant",
6877
+ type: "string"
6878
+ },
6879
+ {
6880
+ internalType: "string[]",
6881
+ name: "fileUrls",
6882
+ type: "string[]"
6883
+ },
6884
+ {
6885
+ internalType: "address",
6886
+ name: "serverAddress",
6887
+ type: "address"
6888
+ },
6889
+ {
6890
+ internalType: "string",
6891
+ name: "serverUrl",
6892
+ type: "string"
6893
+ },
6894
+ {
6895
+ internalType: "string",
6896
+ name: "serverPublicKey",
6897
+ type: "string"
6898
+ },
6899
+ {
6900
+ components: [
6901
+ {
6902
+ internalType: "address",
6903
+ name: "account",
6904
+ type: "address"
6905
+ },
6906
+ {
6907
+ internalType: "string",
6908
+ name: "key",
6909
+ type: "string"
6910
+ }
6911
+ ],
6912
+ internalType: "struct IDataRegistry.Permission[][]",
6913
+ name: "filePermissions",
6914
+ type: "tuple[][]"
6915
+ }
6916
+ ],
6917
+ internalType: "struct IDataPortabilityPermissions.ServerFilesAndPermissionInput",
6918
+ name: "serverFilesAndPermissionInput",
6919
+ type: "tuple"
6920
+ },
6921
+ {
6922
+ internalType: "bytes",
6923
+ name: "signature",
6924
+ type: "bytes"
6925
+ }
6926
+ ],
6927
+ name: "addServerFilesAndPermissions",
6928
+ outputs: [
6929
+ {
6930
+ internalType: "uint256",
6931
+ name: "",
6932
+ type: "uint256"
6933
+ }
6934
+ ],
6935
+ stateMutability: "nonpayable",
6936
+ type: "function"
6937
+ },
6834
6938
  {
6835
6939
  inputs: [],
6836
6940
  name: "dataPortabilityGrantees",
@@ -7045,25 +7149,6 @@ var DataPortabilityPermissionsABI = [
7045
7149
  stateMutability: "nonpayable",
7046
7150
  type: "function"
7047
7151
  },
7048
- {
7049
- inputs: [
7050
- {
7051
- internalType: "uint256",
7052
- name: "permissionId",
7053
- type: "uint256"
7054
- }
7055
- ],
7056
- name: "isActivePermission",
7057
- outputs: [
7058
- {
7059
- internalType: "bool",
7060
- name: "",
7061
- type: "bool"
7062
- }
7063
- ],
7064
- stateMutability: "view",
7065
- type: "function"
7066
- },
7067
7152
  {
7068
7153
  inputs: [
7069
7154
  {
@@ -7178,11 +7263,6 @@ var DataPortabilityPermissionsABI = [
7178
7263
  name: "grant",
7179
7264
  type: "string"
7180
7265
  },
7181
- {
7182
- internalType: "bytes",
7183
- name: "signature",
7184
- type: "bytes"
7185
- },
7186
7266
  {
7187
7267
  internalType: "uint256",
7188
7268
  name: "startBlock",
@@ -7900,9 +7980,9 @@ var DataPortabilityServersABI = [
7900
7980
  },
7901
7981
  {
7902
7982
  indexed: false,
7903
- internalType: "bytes",
7983
+ internalType: "string",
7904
7984
  name: "publicKey",
7905
- type: "bytes"
7985
+ type: "string"
7906
7986
  },
7907
7987
  {
7908
7988
  indexed: false,
@@ -8023,6 +8103,19 @@ var DataPortabilityServersABI = [
8023
8103
  stateMutability: "view",
8024
8104
  type: "function"
8025
8105
  },
8106
+ {
8107
+ inputs: [],
8108
+ name: "PERMISSION_MANAGER_ROLE",
8109
+ outputs: [
8110
+ {
8111
+ internalType: "bytes32",
8112
+ name: "",
8113
+ type: "bytes32"
8114
+ }
8115
+ ],
8116
+ stateMutability: "view",
8117
+ type: "function"
8118
+ },
8026
8119
  {
8027
8120
  inputs: [],
8028
8121
  name: "UPGRADE_INTERFACE_VERSION",
@@ -8038,22 +8131,22 @@ var DataPortabilityServersABI = [
8038
8131
  },
8039
8132
  {
8040
8133
  inputs: [
8134
+ {
8135
+ internalType: "address",
8136
+ name: "ownerAddress",
8137
+ type: "address"
8138
+ },
8041
8139
  {
8042
8140
  components: [
8043
- {
8044
- internalType: "address",
8045
- name: "owner",
8046
- type: "address"
8047
- },
8048
8141
  {
8049
8142
  internalType: "address",
8050
8143
  name: "serverAddress",
8051
8144
  type: "address"
8052
8145
  },
8053
8146
  {
8054
- internalType: "bytes",
8147
+ internalType: "string",
8055
8148
  name: "publicKey",
8056
- type: "bytes"
8149
+ type: "string"
8057
8150
  },
8058
8151
  {
8059
8152
  internalType: "string",
@@ -8062,11 +8155,11 @@ var DataPortabilityServersABI = [
8062
8155
  }
8063
8156
  ],
8064
8157
  internalType: "struct IDataPortabilityServers.AddServerInput",
8065
- name: "addAndTrustServerInput",
8158
+ name: "addServerInput",
8066
8159
  type: "tuple"
8067
8160
  }
8068
8161
  ],
8069
- name: "addAndTrustServer",
8162
+ name: "addAndTrustServerOnBehalf",
8070
8163
  outputs: [],
8071
8164
  stateMutability: "nonpayable",
8072
8165
  type: "function"
@@ -8080,20 +8173,15 @@ var DataPortabilityServersABI = [
8080
8173
  name: "nonce",
8081
8174
  type: "uint256"
8082
8175
  },
8083
- {
8084
- internalType: "address",
8085
- name: "owner",
8086
- type: "address"
8087
- },
8088
8176
  {
8089
8177
  internalType: "address",
8090
8178
  name: "serverAddress",
8091
8179
  type: "address"
8092
8180
  },
8093
8181
  {
8094
- internalType: "bytes",
8182
+ internalType: "string",
8095
8183
  name: "publicKey",
8096
- type: "bytes"
8184
+ type: "string"
8097
8185
  },
8098
8186
  {
8099
8187
  internalType: "string",
@@ -8101,8 +8189,8 @@ var DataPortabilityServersABI = [
8101
8189
  type: "string"
8102
8190
  }
8103
8191
  ],
8104
- internalType: "struct IDataPortabilityServers.AddAndTrustServerInput",
8105
- name: "addAndTrustServerInput",
8192
+ internalType: "struct IDataPortabilityServers.AddServerWithSignatureInput",
8193
+ name: "addServerInput",
8106
8194
  type: "tuple"
8107
8195
  },
8108
8196
  {
@@ -8121,9 +8209,9 @@ var DataPortabilityServersABI = [
8121
8209
  {
8122
8210
  components: [
8123
8211
  {
8124
- internalType: "address",
8125
- name: "owner",
8126
- type: "address"
8212
+ internalType: "uint256",
8213
+ name: "nonce",
8214
+ type: "uint256"
8127
8215
  },
8128
8216
  {
8129
8217
  internalType: "address",
@@ -8131,9 +8219,9 @@ var DataPortabilityServersABI = [
8131
8219
  type: "address"
8132
8220
  },
8133
8221
  {
8134
- internalType: "bytes",
8222
+ internalType: "string",
8135
8223
  name: "publicKey",
8136
- type: "bytes"
8224
+ type: "string"
8137
8225
  },
8138
8226
  {
8139
8227
  internalType: "string",
@@ -8141,12 +8229,17 @@ var DataPortabilityServersABI = [
8141
8229
  type: "string"
8142
8230
  }
8143
8231
  ],
8144
- internalType: "struct IDataPortabilityServers.AddServerInput",
8232
+ internalType: "struct IDataPortabilityServers.AddServerWithSignatureInput",
8145
8233
  name: "addServerInput",
8146
8234
  type: "tuple"
8235
+ },
8236
+ {
8237
+ internalType: "bytes",
8238
+ name: "signature",
8239
+ type: "bytes"
8147
8240
  }
8148
8241
  ],
8149
- name: "addServer",
8242
+ name: "addServerWithSignature",
8150
8243
  outputs: [],
8151
8244
  stateMutability: "nonpayable",
8152
8245
  type: "function"
@@ -8273,49 +8366,6 @@ var DataPortabilityServersABI = [
8273
8366
  stateMutability: "nonpayable",
8274
8367
  type: "function"
8275
8368
  },
8276
- {
8277
- inputs: [
8278
- {
8279
- internalType: "uint256",
8280
- name: "serverId",
8281
- type: "uint256"
8282
- }
8283
- ],
8284
- name: "isActiveServer",
8285
- outputs: [
8286
- {
8287
- internalType: "bool",
8288
- name: "",
8289
- type: "bool"
8290
- }
8291
- ],
8292
- stateMutability: "view",
8293
- type: "function"
8294
- },
8295
- {
8296
- inputs: [
8297
- {
8298
- internalType: "address",
8299
- name: "userAddress",
8300
- type: "address"
8301
- },
8302
- {
8303
- internalType: "uint256",
8304
- name: "serverId",
8305
- type: "uint256"
8306
- }
8307
- ],
8308
- name: "isActiveServerForUser",
8309
- outputs: [
8310
- {
8311
- internalType: "bool",
8312
- name: "",
8313
- type: "bool"
8314
- }
8315
- ],
8316
- stateMutability: "view",
8317
- type: "function"
8318
- },
8319
8369
  {
8320
8370
  inputs: [
8321
8371
  {
@@ -8470,9 +8520,9 @@ var DataPortabilityServersABI = [
8470
8520
  type: "address"
8471
8521
  },
8472
8522
  {
8473
- internalType: "bytes",
8523
+ internalType: "string",
8474
8524
  name: "publicKey",
8475
- type: "bytes"
8525
+ type: "string"
8476
8526
  },
8477
8527
  {
8478
8528
  internalType: "string",
@@ -8516,9 +8566,9 @@ var DataPortabilityServersABI = [
8516
8566
  type: "address"
8517
8567
  },
8518
8568
  {
8519
- internalType: "bytes",
8569
+ internalType: "string",
8520
8570
  name: "publicKey",
8521
- type: "bytes"
8571
+ type: "string"
8522
8572
  },
8523
8573
  {
8524
8574
  internalType: "string",
@@ -8838,6 +8888,123 @@ var DataPortabilityServersABI = [
8838
8888
  stateMutability: "view",
8839
8889
  type: "function"
8840
8890
  },
8891
+ {
8892
+ inputs: [
8893
+ {
8894
+ internalType: "address",
8895
+ name: "userAddress",
8896
+ type: "address"
8897
+ }
8898
+ ],
8899
+ name: "userServerValues",
8900
+ outputs: [
8901
+ {
8902
+ components: [
8903
+ {
8904
+ internalType: "uint256",
8905
+ name: "id",
8906
+ type: "uint256"
8907
+ },
8908
+ {
8909
+ internalType: "address",
8910
+ name: "owner",
8911
+ type: "address"
8912
+ },
8913
+ {
8914
+ internalType: "address",
8915
+ name: "serverAddress",
8916
+ type: "address"
8917
+ },
8918
+ {
8919
+ internalType: "string",
8920
+ name: "publicKey",
8921
+ type: "string"
8922
+ },
8923
+ {
8924
+ internalType: "string",
8925
+ name: "url",
8926
+ type: "string"
8927
+ },
8928
+ {
8929
+ internalType: "uint256",
8930
+ name: "startBlock",
8931
+ type: "uint256"
8932
+ },
8933
+ {
8934
+ internalType: "uint256",
8935
+ name: "endBlock",
8936
+ type: "uint256"
8937
+ }
8938
+ ],
8939
+ internalType: "struct IDataPortabilityServers.TrustedServerInfo[]",
8940
+ name: "serversInfo",
8941
+ type: "tuple[]"
8942
+ }
8943
+ ],
8944
+ stateMutability: "view",
8945
+ type: "function"
8946
+ },
8947
+ {
8948
+ inputs: [
8949
+ {
8950
+ internalType: "address",
8951
+ name: "userAddress",
8952
+ type: "address"
8953
+ },
8954
+ {
8955
+ internalType: "uint256",
8956
+ name: "serverId",
8957
+ type: "uint256"
8958
+ }
8959
+ ],
8960
+ name: "userServers",
8961
+ outputs: [
8962
+ {
8963
+ components: [
8964
+ {
8965
+ internalType: "uint256",
8966
+ name: "id",
8967
+ type: "uint256"
8968
+ },
8969
+ {
8970
+ internalType: "address",
8971
+ name: "owner",
8972
+ type: "address"
8973
+ },
8974
+ {
8975
+ internalType: "address",
8976
+ name: "serverAddress",
8977
+ type: "address"
8978
+ },
8979
+ {
8980
+ internalType: "string",
8981
+ name: "publicKey",
8982
+ type: "string"
8983
+ },
8984
+ {
8985
+ internalType: "string",
8986
+ name: "url",
8987
+ type: "string"
8988
+ },
8989
+ {
8990
+ internalType: "uint256",
8991
+ name: "startBlock",
8992
+ type: "uint256"
8993
+ },
8994
+ {
8995
+ internalType: "uint256",
8996
+ name: "endBlock",
8997
+ type: "uint256"
8998
+ }
8999
+ ],
9000
+ internalType: "struct IDataPortabilityServers.TrustedServerInfo",
9001
+ name: "",
9002
+ type: "tuple"
9003
+ }
9004
+ ],
9005
+ stateMutability: "view",
9006
+ type: "function"
9007
+ },
8841
9008
  {
8842
9009
  inputs: [
8843
9010
  {
@@ -35399,7 +35566,6 @@ var DATVotesABI = [
35399
35566
 
35400
35567
  // src/abi/index.ts
35401
35568
  var contractAbis = {
35402
- DataPermissions: DataPortabilityPermissionsABI,
35403
35569
  DataPortabilityPermissions: DataPortabilityPermissionsABI,
35404
35570
  DataPortabilityServers: DataPortabilityServersABI,
35405
35571
  DataPortabilityGrantees: DataPortabilityGranteesABI,
@@ -35507,13 +35673,6 @@ async function parseTransactionResult(context, hash, operation) {
35507
35673
  // src/config/addresses.ts
35508
35674
  var CONTRACTS = {
35509
35675
  // Data Portability Contracts (New Architecture)
35510
- DataPermissions: {
35511
- addresses: {
35512
- 14800: "0xD54523048AdD05b4d734aFaE7C68324Ebb7373eF",
35513
- // Points to DataPortabilityPermissions for backwards compatibility
35514
- 1480: "0xD54523048AdD05b4d734aFaE7C68324Ebb7373eF"
35515
- }
35516
- },
35517
35676
  DataPortabilityPermissions: {
35518
35677
  addresses: {
35519
35678
  14800: "0xD54523048AdD05b4d734aFaE7C68324Ebb7373eF",
@@ -36348,6 +36507,42 @@ async function withSignatureCache(cache, walletAddress, typedData, signFn, ttlHo
36348
36507
  return signature;
36349
36508
  }
36350
36509
 
36510
+ // src/utils/signatureFormatter.ts
36511
+ var V_OFFSET_FOR_ETHEREUM = 27;
36512
+ function formatSignatureForContract(signature) {
36513
+ const cleanSig = signature.startsWith("0x") ? signature.slice(2) : signature;
36514
+ if (cleanSig.length !== 130) {
36515
+ return signature;
36516
+ }
36517
+ const vHex = cleanSig.slice(128, 130);
36518
+ const v = parseInt(vHex, 16);
36519
+ if (isNaN(v)) {
36520
+ return signature;
36521
+ }
36522
+ if (v < 27) {
36523
+ const adjustedV = (v + V_OFFSET_FOR_ETHEREUM).toString(16).padStart(2, "0");
36524
+ return `0x${cleanSig.slice(0, 128)}${adjustedV}`;
36525
+ }
36526
+ return signature;
36527
+ }
36528
+
36529
+ // src/utils/typedDataConverter.ts
36530
+ function toViemTypedDataDefinition(typedData) {
36531
+ const viemTypes = {};
36532
+ for (const [typeName, typeArray] of Object.entries(typedData.types)) {
36533
+ viemTypes[typeName] = typeArray.map((field) => ({
36534
+ name: field.name,
36535
+ type: field.type
36536
+ }));
36537
+ }
36538
+ return {
36539
+ domain: typedData.domain,
36540
+ types: viemTypes,
36541
+ primaryType: typedData.primaryType,
36542
+ message: typedData.message
36543
+ };
36544
+ }
36545
+
36351
36546
  // src/controllers/permissions.ts
36352
36547
  var PermissionsController = class {
36353
36548
  constructor(context) {
@@ -36507,7 +36702,7 @@ var PermissionsController = class {
36507
36702
  throw new Error("Failed to store grant file - no URL returned");
36508
36703
  }
36509
36704
  }
36510
- const nonce = await this.getUserNonce();
36705
+ const nonce = await this.getPermissionsUserNonce();
36511
36706
  console.debug(
36512
36707
  "\u{1F50D} Debug - Final grant URL being passed to compose:",
36513
36708
  grantUrl
@@ -36600,7 +36795,7 @@ var PermissionsController = class {
36600
36795
  throw new Error("Failed to store grant file - no URL returned");
36601
36796
  }
36602
36797
  }
36603
- const nonce = await this.getUserNonce();
36798
+ const nonce = await this.getPermissionsUserNonce();
36604
36799
  console.debug(
36605
36800
  "\u{1F50D} Debug - Final grant URL being passed to compose:",
36606
36801
  grantUrl
@@ -36665,14 +36860,8 @@ var PermissionsController = class {
36665
36860
  )
36666
36861
  );
36667
36862
  if (this.context.relayerCallbacks?.submitPermissionGrant) {
36668
- const jsonSafeTypedData = JSON.parse(
36669
- JSON.stringify(
36670
- typedData,
36671
- (_key, value) => typeof value === "bigint" ? value.toString() : value
36672
- )
36673
- );
36674
36863
  return await this.context.relayerCallbacks.submitPermissionGrant(
36675
- jsonSafeTypedData,
36864
+ typedData,
36676
36865
  signature
36677
36866
  );
36678
36867
  } else {
@@ -36742,7 +36931,6 @@ var PermissionsController = class {
36742
36931
  try {
36743
36932
  const addAndTrustServerInput = {
36744
36933
  nonce: BigInt(typedData.message.nonce),
36745
- owner: typedData.message.owner,
36746
36934
  serverAddress: typedData.message.serverAddress,
36747
36935
  serverUrl: typedData.message.serverUrl,
36748
36936
  publicKey: typedData.message.publicKey
@@ -36756,7 +36944,7 @@ var PermissionsController = class {
36756
36944
  throw error;
36757
36945
  }
36758
36946
  throw new BlockchainError(
36759
- `Add and trust server submission failed: ${error instanceof Error ? error.message : "Unknown error"}`,
36947
+ `Add and trust server submission failed444444: ${error instanceof Error ? error.message : "Unknown error"}`,
36760
36948
  error
36761
36949
  );
36762
36950
  }
@@ -36772,14 +36960,8 @@ var PermissionsController = class {
36772
36960
  async submitSignedRevoke(typedData, signature) {
36773
36961
  try {
36774
36962
  if (this.context.relayerCallbacks?.submitPermissionRevoke) {
36775
- const jsonSafeTypedData = JSON.parse(
36776
- JSON.stringify(
36777
- typedData,
36778
- (_key, value) => typeof value === "bigint" ? value.toString() : value
36779
- )
36780
- );
36781
36963
  return await this.context.relayerCallbacks.submitPermissionRevoke(
36782
- jsonSafeTypedData,
36964
+ typedData,
36783
36965
  signature
36784
36966
  );
36785
36967
  } else {
@@ -36832,11 +37014,11 @@ var PermissionsController = class {
36832
37014
  */
36833
37015
  async submitDirectTransaction(typedData, signature) {
36834
37016
  const chainId = await this.context.walletClient.getChainId();
36835
- const DataPermissionsAddress = getContractAddress(
37017
+ const DataPortabilityPermissionsAddress = getContractAddress(
36836
37018
  chainId,
36837
- "DataPermissions"
37019
+ "DataPortabilityPermissions"
36838
37020
  );
36839
- const DataPermissionsAbi = getAbi("DataPermissions");
37021
+ const DataPortabilityPermissionsAbi = getAbi("DataPortabilityPermissions");
36840
37022
  const permissionInput = {
36841
37023
  nonce: typedData.message.nonce,
36842
37024
  granteeId: typedData.message.granteeId,
@@ -36853,11 +37035,12 @@ var PermissionsController = class {
36853
37035
  "\u{1F50D} Debug - Grant field length:",
36854
37036
  typedData.message.grant?.length || 0
36855
37037
  );
37038
+ const formattedSignature = formatSignatureForContract(signature);
36856
37039
  const txHash = await this.context.walletClient.writeContract({
36857
- address: DataPermissionsAddress,
36858
- abi: DataPermissionsAbi,
37040
+ address: DataPortabilityPermissionsAddress,
37041
+ abi: DataPortabilityPermissionsAbi,
36859
37042
  functionName: "addPermission",
36860
- args: [permissionInput, signature],
37043
+ args: [permissionInput, formattedSignature],
36861
37044
  account: this.context.walletClient.account || await this.getUserAddress(),
36862
37045
  chain: this.context.walletClient.chain || null
36863
37046
  });
@@ -36916,14 +37099,16 @@ var PermissionsController = class {
36916
37099
  throw new BlockchainError("Chain ID not available");
36917
37100
  }
36918
37101
  const chainId = await this.context.walletClient.getChainId();
36919
- const DataPermissionsAddress = getContractAddress(
37102
+ const DataPortabilityPermissionsAddress = getContractAddress(
36920
37103
  chainId,
36921
- "DataPermissions"
37104
+ "DataPortabilityPermissions"
37105
+ );
37106
+ const DataPortabilityPermissionsAbi = getAbi(
37107
+ "DataPortabilityPermissions"
36922
37108
  );
36923
- const DataPermissionsAbi = getAbi("DataPermissions");
36924
37109
  const txHash = await this.context.walletClient.writeContract({
36925
- address: DataPermissionsAddress,
36926
- abi: DataPermissionsAbi,
37110
+ address: DataPortabilityPermissionsAddress,
37111
+ abi: DataPortabilityPermissionsAbi,
36927
37112
  functionName: "revokePermission",
36928
37113
  args: [params.permissionId],
36929
37114
  account: this.context.walletClient.account || await this.getUserAddress(),
@@ -36954,12 +37139,12 @@ var PermissionsController = class {
36954
37139
  * @throws {RelayerError} When gasless submission fails
36955
37140
  * @throws {PermissionError} When revocation fails for any other reason
36956
37141
  */
36957
- async revokeWithSignature(params) {
37142
+ async submitRevokeWithSignature(params) {
36958
37143
  try {
36959
37144
  if (!this.context.walletClient.chain?.id) {
36960
37145
  throw new BlockchainError("Chain ID not available");
36961
37146
  }
36962
- const nonce = await this.getUserNonce();
37147
+ const nonce = await this.getPermissionsUserNonce();
36963
37148
  const revokePermissionInput = {
36964
37149
  nonce,
36965
37150
  permissionId: params.permissionId
@@ -36992,7 +37177,10 @@ var PermissionsController = class {
36992
37177
  }
36993
37178
  }
36994
37179
  /**
37180
+ * @deprecated Use getPermissionsUserNonce() for permission operations or getServersUserNonce() for server operations
37181
+ *
36995
37182
  * Retrieves the user's current nonce from the DataPortabilityServers contract.
37183
+ * This method is deprecated in favor of more specific nonce methods.
36996
37184
  *
36997
37185
  * The nonce is used to prevent replay attacks in signed transactions and must
36998
37186
  * be incremented with each transaction to maintain security.
@@ -37004,22 +37192,26 @@ var PermissionsController = class {
37004
37192
  * @private
37005
37193
  * @example
37006
37194
  * ```typescript
37195
+ * // Deprecated - use specific methods instead
37007
37196
  * const nonce = await this.getUserNonce();
37008
- * console.log(`Current nonce: ${nonce}`);
37197
+ *
37198
+ * // Use these instead:
37199
+ * const permissionsNonce = await this.getPermissionsUserNonce();
37200
+ * const serversNonce = await this.getServersUserNonce();
37009
37201
  * ```
37010
37202
  */
37011
37203
  async getUserNonce() {
37012
37204
  try {
37013
37205
  const userAddress = await this.getUserAddress();
37014
37206
  const chainId = await this.context.walletClient.getChainId();
37015
- const DataPermissionsAddress = getContractAddress(
37207
+ const DataPortabilityServersAddress = getContractAddress(
37016
37208
  chainId,
37017
- "DataPermissions"
37209
+ "DataPortabilityServers"
37018
37210
  );
37019
- const DataPermissionsAbi = getAbi("DataPermissions");
37211
+ const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
37020
37212
  const nonce = await this.context.publicClient.readContract({
37021
- address: DataPermissionsAddress,
37022
- abi: DataPermissionsAbi,
37213
+ address: DataPortabilityServersAddress,
37214
+ abi: DataPortabilityServersAbi,
37023
37215
  functionName: "userNonce",
37024
37216
  args: [userAddress]
37025
37217
  });
@@ -37030,6 +37222,80 @@ var PermissionsController = class {
37030
37222
  );
37031
37223
  }
37032
37224
  }
37225
+ /**
37226
+ * Retrieves the user's current nonce from the DataPortabilityServers contract.
37227
+ * This nonce is used for server-related operations (AddAndTrustServer, TrustServer, UntrustServer).
37228
+ *
37229
+ * @returns Promise resolving to the current servers nonce
37230
+ * @throws {NonceError} When reading nonce from contract fails
37231
+ * @private
37232
+ *
37233
+ * @example
37234
+ * ```typescript
37235
+ * const nonce = await this.getServersUserNonce();
37236
+ * console.log(`Current servers nonce: ${nonce}`);
37237
+ * ```
37238
+ */
37239
+ async getServersUserNonce() {
37240
+ try {
37241
+ const userAddress = await this.getUserAddress();
37242
+ const chainId = await this.context.walletClient.getChainId();
37243
+ const DataPortabilityServersAddress = getContractAddress(
37244
+ chainId,
37245
+ "DataPortabilityServers"
37246
+ );
37247
+ const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
37248
+ const [nonce] = await this.context.publicClient.readContract({
37249
+ address: DataPortabilityServersAddress,
37250
+ abi: DataPortabilityServersAbi,
37251
+ functionName: "users",
37252
+ args: [userAddress]
37253
+ });
37254
+ return nonce;
37255
+ } catch (error) {
37256
+ throw new NonceError(
37257
+ `Failed to retrieve server nonce: ${error instanceof Error ? error.message : "Unknown error"}`
37258
+ );
37259
+ }
37260
+ }
37261
+ /**
37262
+ * Retrieves the user's current nonce from the DataPortabilityPermissions contract.
37263
+ * This nonce is used for permission-related operations (addPermission, addServerFilesAndPermissions).
37264
+ *
37265
+ * @returns Promise resolving to the current permissions nonce
37266
+ * @throws {NonceError} When reading nonce from contract fails
37267
+ * @private
37268
+ *
37269
+ * @example
37270
+ * ```typescript
37271
+ * const nonce = await this.getPermissionsUserNonce();
37272
+ * console.log(`Current permissions nonce: ${nonce}`);
37273
+ * ```
37274
+ */
37275
+ async getPermissionsUserNonce() {
37276
+ try {
37277
+ const userAddress = await this.getUserAddress();
37278
+ const chainId = await this.context.walletClient.getChainId();
37279
+ const DataPortabilityPermissionsAddress = getContractAddress(
37280
+ chainId,
37281
+ "DataPortabilityPermissions"
37282
+ );
37283
+ const DataPortabilityPermissionsAbi = getAbi(
37284
+ "DataPortabilityPermissions"
37285
+ );
37286
+ const nonce = await this.context.publicClient.readContract({
37287
+ address: DataPortabilityPermissionsAddress,
37288
+ abi: DataPortabilityPermissionsAbi,
37289
+ functionName: "userNonce",
37290
+ args: [userAddress]
37291
+ });
37292
+ return nonce;
37293
+ } catch (error) {
37294
+ throw new NonceError(
37295
+ `Failed to retrieve permissions nonce: ${error instanceof Error ? error.message : "Unknown error"}`
37296
+ );
37297
+ }
37298
+ }
37033
37299
  /**
37034
37300
  * Composes the EIP-712 typed data for PermissionGrant (new simplified format).
37035
37301
  *
@@ -37088,6 +37354,66 @@ var PermissionsController = class {
37088
37354
  }
37089
37355
  };
37090
37356
  }
37357
+ /**
37358
+ * Creates EIP-712 typed data structure for server files and permissions.
37359
+ *
37360
+ * @param params - Parameters for the server files and permissions message
37361
+ * @param params.granteeId - Grantee ID
37362
+ * @param params.grant - Grant URL or grant data
37363
+ * @param params.fileUrls - Array of file URLs
37364
+ * @param params.serverAddress - Server address
37365
+ * @param params.serverUrl - Server URL
37366
+ * @param params.serverPublicKey - Server public key
37367
+ * @param params.filePermissions - File permissions array
37368
+ * @param params.nonce - Unique number to prevent replay attacks
37369
+ * @returns Promise resolving to the typed data structure
37370
+ */
37371
+ async composeServerFilesAndPermissionMessage(params) {
37372
+ const domain = await this.getPermissionDomain();
37373
+ console.debug(
37374
+ "\u{1F50D} Debug - Composing server files and permission message with grant:",
37375
+ params.grant
37376
+ );
37377
+ if (!params.grant.startsWith("ipfs://") && params.grant.includes("/ipfs/")) {
37378
+ const { extractIpfsHash: extractIpfsHash2 } = await Promise.resolve().then(() => (init_ipfs(), ipfs_exports));
37379
+ const hash = extractIpfsHash2(params.grant);
37380
+ if (hash) {
37381
+ console.warn(
37382
+ `\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.`
37383
+ );
37384
+ }
37385
+ }
37386
+ return {
37387
+ domain,
37388
+ types: {
37389
+ Permission: [
37390
+ { name: "account", type: "address" },
37391
+ { name: "key", type: "string" }
37392
+ ],
37393
+ ServerFilesAndPermission: [
37394
+ { name: "nonce", type: "uint256" },
37395
+ { name: "granteeId", type: "uint256" },
37396
+ { name: "grant", type: "string" },
37397
+ { name: "fileUrls", type: "string[]" },
37398
+ { name: "serverAddress", type: "address" },
37399
+ { name: "serverUrl", type: "string" },
37400
+ { name: "serverPublicKey", type: "string" },
37401
+ { name: "filePermissions", type: "Permission[][]" }
37402
+ ]
37403
+ },
37404
+ primaryType: "ServerFilesAndPermission",
37405
+ message: {
37406
+ nonce: params.nonce,
37407
+ granteeId: params.granteeId,
37408
+ grant: params.grant,
37409
+ fileUrls: params.fileUrls,
37410
+ serverAddress: params.serverAddress,
37411
+ serverUrl: params.serverUrl,
37412
+ serverPublicKey: params.serverPublicKey,
37413
+ filePermissions: params.filePermissions
37414
+ }
37415
+ };
37416
+ }
37091
37417
  /**
37092
37418
  * Gets the EIP-712 domain for PermissionGrant signatures.
37093
37419
  *
@@ -37095,15 +37421,15 @@ var PermissionsController = class {
37095
37421
  */
37096
37422
  async getPermissionDomain() {
37097
37423
  const chainId = await this.context.walletClient.getChainId();
37098
- const DataPermissionsAddress = getContractAddress(
37424
+ const DataPortabilityPermissionsAddress = getContractAddress(
37099
37425
  chainId,
37100
- "DataPermissions"
37426
+ "DataPortabilityPermissions"
37101
37427
  );
37102
37428
  return {
37103
37429
  name: "VanaDataPortabilityPermissions",
37104
37430
  version: "1",
37105
37431
  chainId,
37106
- verifyingContract: DataPermissionsAddress
37432
+ verifyingContract: DataPortabilityPermissionsAddress
37107
37433
  };
37108
37434
  }
37109
37435
  /**
@@ -37120,9 +37446,13 @@ var PermissionsController = class {
37120
37446
  walletAddress,
37121
37447
  typedData,
37122
37448
  async () => {
37123
- return await this.context.walletClient.signTypedData(
37124
- typedData
37125
- );
37449
+ const viemCompatibleTypedData = toViemTypedDataDefinition(typedData);
37450
+ return await this.context.walletClient.signTypedData({
37451
+ ...viemCompatibleTypedData,
37452
+ // Non-null assertion is safe here because getUserAddress() above ensures account exists
37453
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
37454
+ account: this.context.walletClient.account
37455
+ });
37126
37456
  }
37127
37457
  );
37128
37458
  } catch (error) {
@@ -37269,122 +37599,6 @@ var PermissionsController = class {
37269
37599
  );
37270
37600
  }
37271
37601
  }
37272
- /**
37273
- * Gets all permission IDs for a specific file.
37274
- *
37275
- * @param fileId - The file ID to query permissions for
37276
- * @returns Promise resolving to array of permission IDs
37277
- * @throws {BlockchainError} When reading from contract fails or chain is unavailable
37278
- */
37279
- async getFilePermissionIds(fileId) {
37280
- try {
37281
- const chainId = await this.context.walletClient.getChainId();
37282
- const DataPermissionsAddress = getContractAddress(
37283
- chainId,
37284
- "DataPermissions"
37285
- );
37286
- const DataPermissionsAbi = getAbi("DataPermissions");
37287
- const permissionIds = await this.context.publicClient.readContract({
37288
- address: DataPermissionsAddress,
37289
- abi: DataPermissionsAbi,
37290
- functionName: "filePermissionIds",
37291
- args: [fileId]
37292
- });
37293
- return permissionIds;
37294
- } catch (error) {
37295
- throw new BlockchainError(
37296
- `Failed to get file permission IDs: ${error instanceof Error ? error.message : "Unknown error"}`,
37297
- error
37298
- );
37299
- }
37300
- }
37301
- /**
37302
- * Gets all file IDs associated with a permission.
37303
- *
37304
- * @param permissionId - The permission ID to query files for
37305
- * @returns Promise resolving to array of file IDs
37306
- * @throws {BlockchainError} When reading from contract fails or chain is unavailable
37307
- */
37308
- async getPermissionFileIds(permissionId) {
37309
- try {
37310
- const chainId = await this.context.walletClient.getChainId();
37311
- const DataPermissionsAddress = getContractAddress(
37312
- chainId,
37313
- "DataPermissions"
37314
- );
37315
- const DataPermissionsAbi = getAbi("DataPermissions");
37316
- const fileIds = await this.context.publicClient.readContract({
37317
- address: DataPermissionsAddress,
37318
- abi: DataPermissionsAbi,
37319
- functionName: "permissionFileIds",
37320
- args: [permissionId]
37321
- });
37322
- return fileIds;
37323
- } catch (error) {
37324
- throw new BlockchainError(
37325
- `Failed to get permission file IDs: ${error instanceof Error ? error.message : "Unknown error"}`,
37326
- error
37327
- );
37328
- }
37329
- }
37330
- /**
37331
- * Checks if a permission is active.
37332
- *
37333
- * @param permissionId - The permission ID to check
37334
- * @returns Promise resolving to boolean indicating if permission is active
37335
- * @throws {BlockchainError} When reading from contract fails or chain is unavailable
37336
- */
37337
- async isActivePermission(permissionId) {
37338
- try {
37339
- const chainId = await this.context.walletClient.getChainId();
37340
- const DataPermissionsAddress = getContractAddress(
37341
- chainId,
37342
- "DataPermissions"
37343
- );
37344
- const DataPermissionsAbi = getAbi("DataPermissions");
37345
- const isActive = await this.context.publicClient.readContract({
37346
- address: DataPermissionsAddress,
37347
- abi: DataPermissionsAbi,
37348
- functionName: "isActivePermission",
37349
- args: [permissionId]
37350
- });
37351
- return isActive;
37352
- } catch (error) {
37353
- throw new BlockchainError(
37354
- `Failed to check permission status: ${error instanceof Error ? error.message : "Unknown error"}`,
37355
- error
37356
- );
37357
- }
37358
- }
37359
- /**
37360
- * Gets permission details from the contract.
37361
- *
37362
- * @param permissionId - The permission ID to query
37363
- * @returns Promise resolving to permission info
37364
- * @throws {BlockchainError} When reading from contract fails or chain is unavailable
37365
- */
37366
- async getPermissionInfo(permissionId) {
37367
- try {
37368
- const chainId = await this.context.walletClient.getChainId();
37369
- const DataPermissionsAddress = getContractAddress(
37370
- chainId,
37371
- "DataPermissions"
37372
- );
37373
- const DataPermissionsAbi = getAbi("DataPermissions");
37374
- const permissionInfo = await this.context.publicClient.readContract({
37375
- address: DataPermissionsAddress,
37376
- abi: DataPermissionsAbi,
37377
- functionName: "permissions",
37378
- args: [permissionId]
37379
- });
37380
- return permissionInfo;
37381
- } catch (error) {
37382
- throw new BlockchainError(
37383
- `Failed to get permission info: ${error instanceof Error ? error.message : "Unknown error"}`,
37384
- error
37385
- );
37386
- }
37387
- }
37388
37602
  /**
37389
37603
  * Normalizes grant ID to hex format.
37390
37604
  * Handles conversion from permission ID (bigint/number/string) to proper hex hash format.
@@ -37447,13 +37661,14 @@ var PermissionsController = class {
37447
37661
  "DataPortabilityServers"
37448
37662
  );
37449
37663
  const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
37664
+ const userAddress = this.context.walletClient.account?.address || await this.getUserAddress();
37450
37665
  const txHash = await this.context.walletClient.writeContract({
37451
37666
  address: DataPortabilityServersAddress,
37452
37667
  abi: DataPortabilityServersAbi,
37453
- functionName: "addAndTrustServer",
37668
+ functionName: "addAndTrustServerOnBehalf",
37454
37669
  args: [
37670
+ userAddress,
37455
37671
  {
37456
- owner: params.owner,
37457
37672
  serverAddress: params.serverAddress,
37458
37673
  serverUrl: params.serverUrl,
37459
37674
  publicKey: params.publicKey
@@ -37480,7 +37695,7 @@ var PermissionsController = class {
37480
37695
  * @returns Promise resolving to transaction hash
37481
37696
  * @deprecated Use addAndTrustServer instead
37482
37697
  */
37483
- async trustServer(params) {
37698
+ async submitTrustServer(params) {
37484
37699
  try {
37485
37700
  const chainId = await this.context.walletClient.getChainId();
37486
37701
  const DataPortabilityServersAddress = getContractAddress(
@@ -37513,12 +37728,11 @@ var PermissionsController = class {
37513
37728
  * @param params - Parameters for adding and trusting the server
37514
37729
  * @returns Promise resolving to transaction hash
37515
37730
  */
37516
- async addAndTrustServerWithSignature(params) {
37731
+ async submitAddAndTrustServerWithSignature(params) {
37517
37732
  try {
37518
- const nonce = await this.getUserNonce();
37733
+ const nonce = await this.getServersUserNonce();
37519
37734
  const addAndTrustServerInput = {
37520
37735
  nonce,
37521
- owner: params.owner,
37522
37736
  serverAddress: params.serverAddress,
37523
37737
  publicKey: params.publicKey,
37524
37738
  serverUrl: params.serverUrl
@@ -37528,16 +37742,13 @@ var PermissionsController = class {
37528
37742
  );
37529
37743
  console.debug("\u{1F50D} AddAndTrustServer Debug Info:", {
37530
37744
  nonce: nonce.toString(),
37531
- owner: params.owner,
37532
37745
  serverAddress: params.serverAddress,
37533
37746
  publicKey: params.publicKey,
37534
37747
  serverUrl: params.serverUrl,
37535
37748
  domain: typedData.domain,
37536
37749
  typedDataMessage: typedData.message
37537
37750
  });
37538
- const signature = await this.signTypedData(
37539
- typedData
37540
- );
37751
+ const signature = await this.signTypedData(typedData);
37541
37752
  console.debug("\u{1F50D} Generated signature:", signature);
37542
37753
  if (this.context.relayerCallbacks?.submitAddAndTrustServer) {
37543
37754
  return await this.context.relayerCallbacks.submitAddAndTrustServer(
@@ -37578,17 +37789,15 @@ var PermissionsController = class {
37578
37789
  * @throws {ServerUrlMismatchError} When server URL doesn't match existing registration
37579
37790
  * @throws {BlockchainError} When trust operation fails for any other reason
37580
37791
  */
37581
- async trustServerWithSignature(params) {
37792
+ async submitTrustServerWithSignature(params) {
37582
37793
  try {
37583
- const nonce = await this.getUserNonce();
37794
+ const nonce = await this.getServersUserNonce();
37584
37795
  const trustServerInput = {
37585
37796
  nonce,
37586
37797
  serverId: params.serverId
37587
37798
  };
37588
37799
  const typedData = await this.composeTrustServerMessage(trustServerInput);
37589
- const signature = await this.signTypedData(
37590
- typedData
37591
- );
37800
+ const signature = await this.signTypedData(typedData);
37592
37801
  if (this.context.relayerCallbacks?.submitTrustServer) {
37593
37802
  return await this.context.relayerCallbacks.submitTrustServer(
37594
37803
  typedData,
@@ -37674,8 +37883,8 @@ var PermissionsController = class {
37674
37883
  * console.log('Still trusting servers:', trustedServers);
37675
37884
  * ```
37676
37885
  */
37677
- async untrustServer(params) {
37678
- const nonce = await this.getUserNonce();
37886
+ async submitUntrustServer(params) {
37887
+ const nonce = await this.getServersUserNonce();
37679
37888
  const untrustServerInput = {
37680
37889
  nonce,
37681
37890
  serverId: params.serverId
@@ -37694,27 +37903,22 @@ var PermissionsController = class {
37694
37903
  * @throws {RelayerError} When gasless submission fails
37695
37904
  * @throws {BlockchainError} When untrust transaction fails
37696
37905
  */
37697
- async untrustServerWithSignature(params) {
37906
+ async submitUntrustServerWithSignature(params) {
37698
37907
  try {
37699
- const nonce = await this.getUserNonce();
37908
+ const nonce = await this.getServersUserNonce();
37700
37909
  const untrustServerInput = {
37701
37910
  nonce,
37702
37911
  serverId: params.serverId
37703
37912
  };
37704
37913
  const typedData = await this.composeUntrustServerMessage(untrustServerInput);
37705
- const signature = await this.signTypedData(
37706
- typedData
37707
- );
37914
+ const signature = await this.signTypedData(typedData);
37708
37915
  if (this.context.relayerCallbacks?.submitUntrustServer) {
37709
37916
  return await this.context.relayerCallbacks.submitUntrustServer(
37710
37917
  typedData,
37711
37918
  signature
37712
37919
  );
37713
37920
  } else {
37714
- return await this.submitSignedUntrustTransaction(
37715
- typedData,
37716
- signature
37717
- );
37921
+ return await this.submitSignedUntrustTransaction(typedData, signature);
37718
37922
  }
37719
37923
  } catch (error) {
37720
37924
  if (error instanceof Error) {
@@ -37774,131 +37978,6 @@ var PermissionsController = class {
37774
37978
  );
37775
37979
  }
37776
37980
  }
37777
- /**
37778
- * Retrieves detailed information about a specific server from the DataPortabilityServers contract.
37779
- *
37780
- * Returns complete server information including owner, address, public key, and URL.
37781
- * This information is used to establish secure connections and verify server identity.
37782
- *
37783
- * @param serverId - The unique numeric ID of the server to query
37784
- * @returns Promise resolving to complete server information
37785
- * @throws {BlockchainError} When reading from contract fails or chain is unavailable
37786
- * @throws {NetworkError} When unable to connect to the blockchain network
37787
- * @throws {ServerNotFoundError} When the server ID does not exist
37788
- *
37789
- * @example
37790
- * ```typescript
37791
- * const server = await vana.permissions.getServerInfo(1);
37792
- *
37793
- * console.log(`Server ${server.id}:`);
37794
- * console.log(` Owner: ${server.owner}`);
37795
- * console.log(` Address: ${server.serverAddress}`);
37796
- * console.log(` URL: ${server.url}`);
37797
- * console.log(` Public Key: ${server.publicKey}`);
37798
- * ```
37799
- */
37800
- async getServerInfo(serverId) {
37801
- try {
37802
- const chainId = await this.context.walletClient.getChainId();
37803
- const DataPortabilityServersAddress = getContractAddress(
37804
- chainId,
37805
- "DataPortabilityServers"
37806
- );
37807
- const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
37808
- const serverInfo = await this.context.publicClient.readContract({
37809
- address: DataPortabilityServersAddress,
37810
- abi: DataPortabilityServersAbi,
37811
- functionName: "servers",
37812
- args: [BigInt(serverId)]
37813
- });
37814
- return {
37815
- id: Number(serverInfo.id),
37816
- owner: serverInfo.owner,
37817
- url: serverInfo.url,
37818
- serverAddress: serverInfo.serverAddress,
37819
- publicKey: serverInfo.publicKey
37820
- };
37821
- } catch (error) {
37822
- throw new BlockchainError(
37823
- `Failed to get server info: ${error instanceof Error ? error.message : "Unknown error"}`,
37824
- error
37825
- );
37826
- }
37827
- }
37828
- /**
37829
- * Checks if a specific server is active in the DataPortabilityServers contract.
37830
- *
37831
- * An active server is one that is properly registered and operational, meaning
37832
- * it can receive and process data portability requests from users.
37833
- *
37834
- * @param serverId - The unique numeric ID of the server to check
37835
- * @returns Promise resolving to true if server is active, false otherwise
37836
- * @throws {BlockchainError} When reading from contract fails or chain is unavailable
37837
- * @throws {NetworkError} When unable to connect to the blockchain network
37838
- *
37839
- * @example
37840
- * ```typescript
37841
- * const isActive = await vana.permissions.isActiveServer(1);
37842
- *
37843
- * if (isActive) {
37844
- * console.log('Server 1 is active and ready to process requests');
37845
- * } else {
37846
- * console.log('Server 1 is inactive or not found');
37847
- * }
37848
- * ```
37849
- */
37850
- async isActiveServer(serverId) {
37851
- try {
37852
- const chainId = await this.context.walletClient.getChainId();
37853
- const DataPortabilityServersAddress = getContractAddress(
37854
- chainId,
37855
- "DataPortabilityServers"
37856
- );
37857
- const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
37858
- const isActive = await this.context.publicClient.readContract({
37859
- address: DataPortabilityServersAddress,
37860
- abi: DataPortabilityServersAbi,
37861
- functionName: "isActiveServer",
37862
- args: [BigInt(serverId)]
37863
- });
37864
- return isActive;
37865
- } catch (error) {
37866
- throw new BlockchainError(
37867
- `Failed to check server status: ${error instanceof Error ? error.message : "Unknown error"}`,
37868
- error
37869
- );
37870
- }
37871
- }
37872
- /**
37873
- * Checks if a server is active for a specific user.
37874
- *
37875
- * @param serverId - Server ID (numeric)
37876
- * @param userAddress - Optional user address (defaults to current user)
37877
- * @returns Promise resolving to boolean indicating if server is active for the user
37878
- */
37879
- async isActiveServerForUser(serverId, userAddress) {
37880
- try {
37881
- const user = userAddress || await this.getUserAddress();
37882
- const chainId = await this.context.walletClient.getChainId();
37883
- const DataPortabilityServersAddress = getContractAddress(
37884
- chainId,
37885
- "DataPortabilityServers"
37886
- );
37887
- const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
37888
- const isActive = await this.context.publicClient.readContract({
37889
- address: DataPortabilityServersAddress,
37890
- abi: DataPortabilityServersAbi,
37891
- functionName: "isActiveServerForUser",
37892
- args: [user, BigInt(serverId)]
37893
- });
37894
- return isActive;
37895
- } catch (error) {
37896
- throw new BlockchainError(
37897
- `Failed to check server status for user: ${error instanceof Error ? error.message : "Unknown error"}`,
37898
- error
37899
- );
37900
- }
37901
- }
37902
37981
  /**
37903
37982
  * Gets the total count of trusted servers for a user.
37904
37983
  *
@@ -38001,27 +38080,29 @@ var PermissionsController = class {
38001
38080
  try {
38002
38081
  const paginatedResult = await this.getTrustedServersPaginated(options);
38003
38082
  const serverInfoPromises = paginatedResult.servers.map(
38004
- async (serverId, index) => {
38083
+ async (serverId, _index) => {
38005
38084
  try {
38006
- const serverInfo = await this.getServerInfo(serverId);
38085
+ const serverInfo = await this.getServerInfo(BigInt(serverId));
38007
38086
  return {
38008
- serverId,
38087
+ id: BigInt(serverId),
38009
38088
  owner: serverInfo.owner,
38010
- url: serverInfo.url,
38011
38089
  serverAddress: serverInfo.serverAddress,
38012
38090
  publicKey: serverInfo.publicKey,
38013
- isTrusted: true,
38014
- trustIndex: options.offset ? options.offset + index : index
38091
+ url: serverInfo.url,
38092
+ startBlock: 0n,
38093
+ // We don't have this info from the old method structure
38094
+ endBlock: 0n
38095
+ // 0 means still active
38015
38096
  };
38016
38097
  } catch {
38017
38098
  return {
38018
- serverId,
38099
+ id: BigInt(serverId),
38019
38100
  owner: "0x0000000000000000000000000000000000000000",
38020
- url: "",
38021
38101
  serverAddress: "0x0000000000000000000000000000000000000000",
38022
38102
  publicKey: "",
38023
- isTrusted: true,
38024
- trustIndex: options.offset ? options.offset + index : index
38103
+ url: "",
38104
+ startBlock: 0n,
38105
+ endBlock: 0n
38025
38106
  };
38026
38107
  }
38027
38108
  }
@@ -38127,18 +38208,18 @@ var PermissionsController = class {
38127
38208
  */
38128
38209
  async composeAddAndTrustServerMessage(input) {
38129
38210
  const domain = await this.getServersDomain();
38211
+ console.debug(domain);
38130
38212
  return {
38131
38213
  domain,
38132
38214
  types: {
38133
- AddAndTrustServer: [
38215
+ AddServer: [
38134
38216
  { name: "nonce", type: "uint256" },
38135
- { name: "owner", type: "address" },
38136
38217
  { name: "serverAddress", type: "address" },
38137
- { name: "publicKey", type: "bytes" },
38218
+ { name: "publicKey", type: "string" },
38138
38219
  { name: "serverUrl", type: "string" }
38139
38220
  ]
38140
38221
  },
38141
- primaryType: "AddAndTrustServer",
38222
+ primaryType: "AddServer",
38142
38223
  message: input
38143
38224
  };
38144
38225
  }
@@ -38219,13 +38300,13 @@ var PermissionsController = class {
38219
38300
  contractAddress: DataPortabilityServersAddress,
38220
38301
  input: {
38221
38302
  nonce: addAndTrustServerInput.nonce.toString(),
38222
- owner: addAndTrustServerInput.owner,
38223
38303
  serverAddress: addAndTrustServerInput.serverAddress,
38224
38304
  publicKey: addAndTrustServerInput.publicKey,
38225
38305
  serverUrl: addAndTrustServerInput.serverUrl
38226
38306
  },
38227
38307
  signature
38228
38308
  });
38309
+ const formattedSignature = formatSignatureForContract(signature);
38229
38310
  const txHash = await this.context.walletClient.writeContract({
38230
38311
  address: DataPortabilityServersAddress,
38231
38312
  abi: DataPortabilityServersAbi,
@@ -38233,12 +38314,11 @@ var PermissionsController = class {
38233
38314
  args: [
38234
38315
  {
38235
38316
  nonce: addAndTrustServerInput.nonce,
38236
- owner: addAndTrustServerInput.owner,
38237
38317
  serverAddress: addAndTrustServerInput.serverAddress,
38238
38318
  publicKey: addAndTrustServerInput.publicKey,
38239
38319
  serverUrl: addAndTrustServerInput.serverUrl
38240
38320
  },
38241
- signature
38321
+ formattedSignature
38242
38322
  ],
38243
38323
  account: this.context.walletClient.account || await this.getUserAddress(),
38244
38324
  chain: this.context.walletClient.chain || null
@@ -38259,6 +38339,7 @@ var PermissionsController = class {
38259
38339
  "DataPortabilityServers"
38260
38340
  );
38261
38341
  const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
38342
+ const formattedSignature = formatSignatureForContract(signature);
38262
38343
  const txHash = await this.context.walletClient.writeContract({
38263
38344
  address: DataPortabilityServersAddress,
38264
38345
  abi: DataPortabilityServersAbi,
@@ -38268,7 +38349,7 @@ var PermissionsController = class {
38268
38349
  nonce: trustServerInput.nonce,
38269
38350
  serverId: BigInt(trustServerInput.serverId)
38270
38351
  },
38271
- signature
38352
+ formattedSignature
38272
38353
  ],
38273
38354
  account: this.context.walletClient.account || await this.getUserAddress(),
38274
38355
  chain: this.context.walletClient.chain || null
@@ -38284,17 +38365,18 @@ var PermissionsController = class {
38284
38365
  */
38285
38366
  async submitDirectRevokeTransaction(typedData, signature) {
38286
38367
  const chainId = await this.context.walletClient.getChainId();
38287
- const DataPermissionsAddress = getContractAddress(
38368
+ const DataPortabilityPermissionsAddress = getContractAddress(
38288
38369
  chainId,
38289
- "DataPermissions"
38370
+ "DataPortabilityPermissions"
38290
38371
  );
38291
- const DataPermissionsAbi = getAbi("DataPermissions");
38372
+ const DataPortabilityPermissionsAbi = getAbi("DataPortabilityPermissions");
38373
+ const formattedSignature = formatSignatureForContract(signature);
38292
38374
  const txHash = await this.context.walletClient.writeContract({
38293
- address: DataPermissionsAddress,
38294
- abi: DataPermissionsAbi,
38375
+ address: DataPortabilityPermissionsAddress,
38376
+ abi: DataPortabilityPermissionsAbi,
38295
38377
  functionName: "revokePermissionWithSignature",
38296
38378
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
38297
- args: [typedData.message, signature],
38379
+ args: [typedData.message, formattedSignature],
38298
38380
  account: this.context.walletClient.account || await this.getUserAddress(),
38299
38381
  chain: this.context.walletClient.chain || null
38300
38382
  });
@@ -38314,12 +38396,13 @@ var PermissionsController = class {
38314
38396
  "DataPortabilityServers"
38315
38397
  );
38316
38398
  const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
38399
+ const formattedSignature = formatSignatureForContract(signature);
38317
38400
  const txHash = await this.context.walletClient.writeContract({
38318
38401
  address: DataPortabilityServersAddress,
38319
38402
  abi: DataPortabilityServersAbi,
38320
38403
  functionName: "untrustServerWithSignature",
38321
38404
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
38322
- args: [typedData.message, signature],
38405
+ args: [typedData.message, formattedSignature],
38323
38406
  account: this.context.walletClient.account || await this.getUserAddress(),
38324
38407
  chain: this.context.walletClient.chain || null
38325
38408
  });
@@ -38353,7 +38436,7 @@ var PermissionsController = class {
38353
38436
  * console.log(`Grantee registered in transaction: ${txHash}`);
38354
38437
  * ```
38355
38438
  */
38356
- async registerGrantee(params) {
38439
+ async submitRegisterGrantee(params) {
38357
38440
  const chainId = await this.context.walletClient.getChainId();
38358
38441
  const DataPortabilityGranteesAddress = getContractAddress(
38359
38442
  chainId,
@@ -38385,8 +38468,8 @@ var PermissionsController = class {
38385
38468
  * });
38386
38469
  * ```
38387
38470
  */
38388
- async registerGranteeWithSignature(params) {
38389
- const nonce = await this.getUserNonce();
38471
+ async submitRegisterGranteeWithSignature(params) {
38472
+ const nonce = await this.getServersUserNonce();
38390
38473
  const registerGranteeInput = {
38391
38474
  nonce,
38392
38475
  owner: params.owner,
@@ -38659,10 +38742,1192 @@ var PermissionsController = class {
38659
38742
  });
38660
38743
  return txHash;
38661
38744
  }
38745
+ // ===========================
38746
+ // DATA PORTABILITY SERVERS HELPER METHODS
38747
+ // ===========================
38748
+ /**
38749
+ * Get all trusted server IDs for a user
38750
+ *
38751
+ * @param userAddress - User address to query (defaults to current user)
38752
+ * @returns Promise resolving to array of server IDs
38753
+ */
38754
+ async getUserServerIds(userAddress) {
38755
+ try {
38756
+ const targetAddress = userAddress || await this.getUserAddress();
38757
+ const chainId = await this.context.publicClient.getChainId();
38758
+ const DataPortabilityServersAddress = getContractAddress(
38759
+ chainId,
38760
+ "DataPortabilityServers"
38761
+ );
38762
+ const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
38763
+ const serverIds = await this.context.publicClient.readContract({
38764
+ address: DataPortabilityServersAddress,
38765
+ abi: DataPortabilityServersAbi,
38766
+ functionName: "userServerIdsValues",
38767
+ args: [targetAddress]
38768
+ });
38769
+ return [...serverIds];
38770
+ } catch (error) {
38771
+ throw new BlockchainError(
38772
+ `Failed to get user server IDs: ${error instanceof Error ? error.message : "Unknown error"}`,
38773
+ error
38774
+ );
38775
+ }
38776
+ }
38777
+ /**
38778
+ * Get server ID at specific index for a user
38779
+ *
38780
+ * @param userAddress - User address to query
38781
+ * @param serverIndex - Index in the user's server list
38782
+ * @returns Promise resolving to server ID
38783
+ */
38784
+ async getUserServerIdAt(userAddress, serverIndex) {
38785
+ try {
38786
+ const chainId = await this.context.publicClient.getChainId();
38787
+ const DataPortabilityServersAddress = getContractAddress(
38788
+ chainId,
38789
+ "DataPortabilityServers"
38790
+ );
38791
+ const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
38792
+ const serverId = await this.context.publicClient.readContract({
38793
+ address: DataPortabilityServersAddress,
38794
+ abi: DataPortabilityServersAbi,
38795
+ functionName: "userServerIdsAt",
38796
+ args: [userAddress, serverIndex]
38797
+ });
38798
+ return serverId;
38799
+ } catch (error) {
38800
+ throw new BlockchainError(
38801
+ `Failed to get user server ID at index: ${error instanceof Error ? error.message : "Unknown error"}`,
38802
+ error
38803
+ );
38804
+ }
38805
+ }
38806
+ /**
38807
+ * Get the number of trusted servers for a user
38808
+ *
38809
+ * @param userAddress - User address to query (defaults to current user)
38810
+ * @returns Promise resolving to number of trusted servers
38811
+ */
38812
+ async getUserServerCount(userAddress) {
38813
+ try {
38814
+ const targetAddress = userAddress || await this.getUserAddress();
38815
+ const chainId = await this.context.publicClient.getChainId();
38816
+ const DataPortabilityServersAddress = getContractAddress(
38817
+ chainId,
38818
+ "DataPortabilityServers"
38819
+ );
38820
+ const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
38821
+ const count = await this.context.publicClient.readContract({
38822
+ address: DataPortabilityServersAddress,
38823
+ abi: DataPortabilityServersAbi,
38824
+ functionName: "userServerIdsLength",
38825
+ args: [targetAddress]
38826
+ });
38827
+ return count;
38828
+ } catch (error) {
38829
+ throw new BlockchainError(
38830
+ `Failed to get user server count: ${error instanceof Error ? error.message : "Unknown error"}`,
38831
+ error
38832
+ );
38833
+ }
38834
+ }
38835
+ /**
38836
+ * Get detailed information about trusted servers for a user
38837
+ *
38838
+ * @param userAddress - User address to query (defaults to current user)
38839
+ * @returns Promise resolving to array of trusted server info
38840
+ */
38841
+ async getUserTrustedServers(userAddress) {
38842
+ try {
38843
+ const targetAddress = userAddress || await this.getUserAddress();
38844
+ const chainId = await this.context.publicClient.getChainId();
38845
+ const DataPortabilityServersAddress = getContractAddress(
38846
+ chainId,
38847
+ "DataPortabilityServers"
38848
+ );
38849
+ const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
38850
+ const servers = await this.context.publicClient.readContract({
38851
+ address: DataPortabilityServersAddress,
38852
+ abi: DataPortabilityServersAbi,
38853
+ functionName: "userServerValues",
38854
+ args: [targetAddress]
38855
+ });
38856
+ return [...servers];
38857
+ } catch (error) {
38858
+ throw new BlockchainError(
38859
+ `Failed to get user trusted servers: ${error instanceof Error ? error.message : "Unknown error"}`,
38860
+ error
38861
+ );
38862
+ }
38863
+ }
38864
+ /**
38865
+ * Get trusted server info for a specific server ID and user
38866
+ *
38867
+ * @param userAddress - User address to query
38868
+ * @param serverId - Server ID to get info for
38869
+ * @returns Promise resolving to trusted server info
38870
+ */
38871
+ async getUserTrustedServer(userAddress, serverId) {
38872
+ try {
38873
+ const chainId = await this.context.publicClient.getChainId();
38874
+ const DataPortabilityServersAddress = getContractAddress(
38875
+ chainId,
38876
+ "DataPortabilityServers"
38877
+ );
38878
+ const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
38879
+ const serverInfo = await this.context.publicClient.readContract({
38880
+ address: DataPortabilityServersAddress,
38881
+ abi: DataPortabilityServersAbi,
38882
+ functionName: "userServers",
38883
+ args: [userAddress, serverId]
38884
+ });
38885
+ return serverInfo;
38886
+ } catch (error) {
38887
+ throw new BlockchainError(
38888
+ `Failed to get user trusted server: ${error instanceof Error ? error.message : "Unknown error"}`,
38889
+ error
38890
+ );
38891
+ }
38892
+ }
38893
+ /**
38894
+ * Get server information by server ID
38895
+ *
38896
+ * @param serverId - Server ID to get info for
38897
+ * @returns Promise resolving to server info
38898
+ */
38899
+ async getServerInfo(serverId) {
38900
+ try {
38901
+ const chainId = await this.context.publicClient.getChainId();
38902
+ const DataPortabilityServersAddress = getContractAddress(
38903
+ chainId,
38904
+ "DataPortabilityServers"
38905
+ );
38906
+ const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
38907
+ const serverInfo = await this.context.publicClient.readContract({
38908
+ address: DataPortabilityServersAddress,
38909
+ abi: DataPortabilityServersAbi,
38910
+ functionName: "servers",
38911
+ args: [serverId]
38912
+ });
38913
+ return serverInfo;
38914
+ } catch (error) {
38915
+ throw new BlockchainError(
38916
+ `Failed to get server info: ${error instanceof Error ? error.message : "Unknown error"}`,
38917
+ error
38918
+ );
38919
+ }
38920
+ }
38921
+ /**
38922
+ * Get server information by server address
38923
+ *
38924
+ * @param serverAddress - Server address to get info for
38925
+ * @returns Promise resolving to server info
38926
+ */
38927
+ async getServerInfoByAddress(serverAddress) {
38928
+ try {
38929
+ const chainId = await this.context.publicClient.getChainId();
38930
+ const DataPortabilityServersAddress = getContractAddress(
38931
+ chainId,
38932
+ "DataPortabilityServers"
38933
+ );
38934
+ const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
38935
+ const serverInfo = await this.context.publicClient.readContract({
38936
+ address: DataPortabilityServersAddress,
38937
+ abi: DataPortabilityServersAbi,
38938
+ functionName: "serverByAddress",
38939
+ args: [serverAddress]
38940
+ });
38941
+ return serverInfo;
38942
+ } catch (error) {
38943
+ throw new BlockchainError(
38944
+ `Failed to get server info by address: ${error instanceof Error ? error.message : "Unknown error"}`,
38945
+ error
38946
+ );
38947
+ }
38948
+ }
38949
+ // ===========================
38950
+ // DATA PORTABILITY PERMISSIONS HELPER METHODS
38951
+ // ===========================
38952
+ /**
38953
+ * Get all permission IDs for a user
38954
+ *
38955
+ * @param userAddress - User address to query (defaults to current user)
38956
+ * @returns Promise resolving to array of permission IDs
38957
+ */
38958
+ async getUserPermissionIds(userAddress) {
38959
+ try {
38960
+ const targetAddress = userAddress || await this.getUserAddress();
38961
+ const chainId = await this.context.publicClient.getChainId();
38962
+ const DataPortabilityPermissionsAddress = getContractAddress(
38963
+ chainId,
38964
+ "DataPortabilityPermissions"
38965
+ );
38966
+ const DataPortabilityPermissionsAbi = getAbi(
38967
+ "DataPortabilityPermissions"
38968
+ );
38969
+ const permissionIds = await this.context.publicClient.readContract({
38970
+ address: DataPortabilityPermissionsAddress,
38971
+ abi: DataPortabilityPermissionsAbi,
38972
+ functionName: "userPermissionIdsValues",
38973
+ args: [targetAddress]
38974
+ });
38975
+ return [...permissionIds];
38976
+ } catch (error) {
38977
+ throw new BlockchainError(
38978
+ `Failed to get user permission IDs: ${error instanceof Error ? error.message : "Unknown error"}`,
38979
+ error
38980
+ );
38981
+ }
38982
+ }
38983
+ /**
38984
+ * Get permission ID at specific index for a user
38985
+ *
38986
+ * @param userAddress - User address to query
38987
+ * @param permissionIndex - Index in the user's permission list
38988
+ * @returns Promise resolving to permission ID
38989
+ */
38990
+ async getUserPermissionIdAt(userAddress, permissionIndex) {
38991
+ try {
38992
+ const chainId = await this.context.publicClient.getChainId();
38993
+ const DataPortabilityPermissionsAddress = getContractAddress(
38994
+ chainId,
38995
+ "DataPortabilityPermissions"
38996
+ );
38997
+ const DataPortabilityPermissionsAbi = getAbi(
38998
+ "DataPortabilityPermissions"
38999
+ );
39000
+ const permissionId = await this.context.publicClient.readContract({
39001
+ address: DataPortabilityPermissionsAddress,
39002
+ abi: DataPortabilityPermissionsAbi,
39003
+ functionName: "userPermissionIdsAt",
39004
+ args: [userAddress, permissionIndex]
39005
+ });
39006
+ return permissionId;
39007
+ } catch (error) {
39008
+ throw new BlockchainError(
39009
+ `Failed to get user permission ID at index: ${error instanceof Error ? error.message : "Unknown error"}`,
39010
+ error
39011
+ );
39012
+ }
39013
+ }
39014
+ /**
39015
+ * Get the number of permissions for a user
39016
+ *
39017
+ * @param userAddress - User address to query (defaults to current user)
39018
+ * @returns Promise resolving to number of permissions
39019
+ */
39020
+ async getUserPermissionCount(userAddress) {
39021
+ try {
39022
+ const targetAddress = userAddress || await this.getUserAddress();
39023
+ const chainId = await this.context.publicClient.getChainId();
39024
+ const DataPortabilityPermissionsAddress = getContractAddress(
39025
+ chainId,
39026
+ "DataPortabilityPermissions"
39027
+ );
39028
+ const DataPortabilityPermissionsAbi = getAbi(
39029
+ "DataPortabilityPermissions"
39030
+ );
39031
+ const count = await this.context.publicClient.readContract({
39032
+ address: DataPortabilityPermissionsAddress,
39033
+ abi: DataPortabilityPermissionsAbi,
39034
+ functionName: "userPermissionIdsLength",
39035
+ args: [targetAddress]
39036
+ });
39037
+ return count;
39038
+ } catch (error) {
39039
+ throw new BlockchainError(
39040
+ `Failed to get user permission count: ${error instanceof Error ? error.message : "Unknown error"}`,
39041
+ error
39042
+ );
39043
+ }
39044
+ }
39045
+ /**
39046
+ * Get detailed permission information by permission ID
39047
+ *
39048
+ * @param permissionId - Permission ID to get info for
39049
+ * @returns Promise resolving to permission info
39050
+ */
39051
+ async getPermissionInfo(permissionId) {
39052
+ try {
39053
+ const chainId = await this.context.publicClient.getChainId();
39054
+ const DataPortabilityPermissionsAddress = getContractAddress(
39055
+ chainId,
39056
+ "DataPortabilityPermissions"
39057
+ );
39058
+ const DataPortabilityPermissionsAbi = getAbi(
39059
+ "DataPortabilityPermissions"
39060
+ );
39061
+ const permissionInfo = await this.context.publicClient.readContract({
39062
+ address: DataPortabilityPermissionsAddress,
39063
+ abi: DataPortabilityPermissionsAbi,
39064
+ functionName: "permissions",
39065
+ args: [permissionId]
39066
+ });
39067
+ return permissionInfo;
39068
+ } catch (error) {
39069
+ throw new BlockchainError(
39070
+ `Failed to get permission info: ${error instanceof Error ? error.message : "Unknown error"}`,
39071
+ error
39072
+ );
39073
+ }
39074
+ }
39075
+ /**
39076
+ * Get all permission IDs for a specific file
39077
+ *
39078
+ * @param fileId - File ID to get permissions for
39079
+ * @returns Promise resolving to array of permission IDs
39080
+ */
39081
+ async getFilePermissionIds(fileId) {
39082
+ try {
39083
+ const chainId = await this.context.publicClient.getChainId();
39084
+ const DataPortabilityPermissionsAddress = getContractAddress(
39085
+ chainId,
39086
+ "DataPortabilityPermissions"
39087
+ );
39088
+ const DataPortabilityPermissionsAbi = getAbi(
39089
+ "DataPortabilityPermissions"
39090
+ );
39091
+ const permissionIds = await this.context.publicClient.readContract({
39092
+ address: DataPortabilityPermissionsAddress,
39093
+ abi: DataPortabilityPermissionsAbi,
39094
+ functionName: "filePermissionIds",
39095
+ args: [fileId]
39096
+ });
39097
+ return [...permissionIds];
39098
+ } catch (error) {
39099
+ throw new BlockchainError(
39100
+ `Failed to get file permission IDs: ${error instanceof Error ? error.message : "Unknown error"}`,
39101
+ error
39102
+ );
39103
+ }
39104
+ }
39105
+ /**
39106
+ * Get all file IDs for a specific permission
39107
+ *
39108
+ * @param permissionId - Permission ID to get files for
39109
+ * @returns Promise resolving to array of file IDs
39110
+ */
39111
+ async getPermissionFileIds(permissionId) {
39112
+ try {
39113
+ const chainId = await this.context.publicClient.getChainId();
39114
+ const DataPortabilityPermissionsAddress = getContractAddress(
39115
+ chainId,
39116
+ "DataPortabilityPermissions"
39117
+ );
39118
+ const DataPortabilityPermissionsAbi = getAbi(
39119
+ "DataPortabilityPermissions"
39120
+ );
39121
+ const fileIds = await this.context.publicClient.readContract({
39122
+ address: DataPortabilityPermissionsAddress,
39123
+ abi: DataPortabilityPermissionsAbi,
39124
+ functionName: "permissionFileIds",
39125
+ args: [permissionId]
39126
+ });
39127
+ return [...fileIds];
39128
+ } catch (error) {
39129
+ throw new BlockchainError(
39130
+ `Failed to get permission file IDs: ${error instanceof Error ? error.message : "Unknown error"}`,
39131
+ error
39132
+ );
39133
+ }
39134
+ }
39135
+ /**
39136
+ * Get all permissions for a specific file (alias for getFilePermissionIds)
39137
+ *
39138
+ * @param fileId - File ID to get permissions for
39139
+ * @returns Promise resolving to array of permission IDs
39140
+ */
39141
+ async getFilePermissions(fileId) {
39142
+ const chainId = await this.context.publicClient.getChainId();
39143
+ const DataPortabilityPermissionsAddress = getContractAddress(
39144
+ chainId,
39145
+ "DataPortabilityPermissions"
39146
+ );
39147
+ const DataPortabilityPermissionsAbi = getAbi("DataPortabilityPermissions");
39148
+ const permissions = await this.context.publicClient.readContract({
39149
+ address: DataPortabilityPermissionsAddress,
39150
+ abi: DataPortabilityPermissionsAbi,
39151
+ functionName: "filePermissions",
39152
+ args: [fileId]
39153
+ });
39154
+ return [...permissions];
39155
+ }
39156
+ // ===========================
39157
+ // DATA PORTABILITY GRANTEES HELPER METHODS
39158
+ // ===========================
39159
+ /**
39160
+ * Get grantee information by grantee ID
39161
+ *
39162
+ * @param granteeId - Grantee ID to get info for
39163
+ * @returns Promise resolving to grantee info
39164
+ */
39165
+ async getGranteeInfo(granteeId) {
39166
+ try {
39167
+ const chainId = await this.context.publicClient.getChainId();
39168
+ const DataPortabilityGranteesAddress = getContractAddress(
39169
+ chainId,
39170
+ "DataPortabilityGrantees"
39171
+ );
39172
+ const DataPortabilityGranteesAbi = getAbi("DataPortabilityGrantees");
39173
+ const granteeInfo = await this.context.publicClient.readContract({
39174
+ address: DataPortabilityGranteesAddress,
39175
+ abi: DataPortabilityGranteesAbi,
39176
+ functionName: "granteeInfo",
39177
+ args: [granteeId]
39178
+ });
39179
+ return granteeInfo;
39180
+ } catch (error) {
39181
+ throw new BlockchainError(
39182
+ `Failed to get grantee info: ${error instanceof Error ? error.message : "Unknown error"}`,
39183
+ error
39184
+ );
39185
+ }
39186
+ }
39187
+ /**
39188
+ * Get grantee information by grantee address
39189
+ *
39190
+ * @param granteeAddress - Grantee address to get info for
39191
+ * @returns Promise resolving to grantee info
39192
+ */
39193
+ async getGranteeInfoByAddress(granteeAddress) {
39194
+ try {
39195
+ const chainId = await this.context.publicClient.getChainId();
39196
+ const DataPortabilityGranteesAddress = getContractAddress(
39197
+ chainId,
39198
+ "DataPortabilityGrantees"
39199
+ );
39200
+ const DataPortabilityGranteesAbi = getAbi("DataPortabilityGrantees");
39201
+ const granteeInfo = await this.context.publicClient.readContract({
39202
+ address: DataPortabilityGranteesAddress,
39203
+ abi: DataPortabilityGranteesAbi,
39204
+ functionName: "granteeByAddress",
39205
+ args: [granteeAddress]
39206
+ });
39207
+ return granteeInfo;
39208
+ } catch (error) {
39209
+ throw new BlockchainError(
39210
+ `Failed to get grantee info by address: ${error instanceof Error ? error.message : "Unknown error"}`,
39211
+ error
39212
+ );
39213
+ }
39214
+ }
39215
+ /**
39216
+ * Get all permission IDs for a specific grantee
39217
+ *
39218
+ * @param granteeId - Grantee ID to get permissions for
39219
+ * @returns Promise resolving to array of permission IDs
39220
+ */
39221
+ async getGranteePermissionIds(granteeId) {
39222
+ try {
39223
+ const chainId = await this.context.publicClient.getChainId();
39224
+ const DataPortabilityGranteesAddress = getContractAddress(
39225
+ chainId,
39226
+ "DataPortabilityGrantees"
39227
+ );
39228
+ const DataPortabilityGranteesAbi = getAbi("DataPortabilityGrantees");
39229
+ const permissionIds = await this.context.publicClient.readContract({
39230
+ address: DataPortabilityGranteesAddress,
39231
+ abi: DataPortabilityGranteesAbi,
39232
+ functionName: "granteePermissionIds",
39233
+ args: [granteeId]
39234
+ });
39235
+ return [...permissionIds];
39236
+ } catch (error) {
39237
+ throw new BlockchainError(
39238
+ `Failed to get grantee permission IDs: ${error instanceof Error ? error.message : "Unknown error"}`,
39239
+ error
39240
+ );
39241
+ }
39242
+ }
39243
+ /**
39244
+ * Get all permissions for a specific grantee (alias for getGranteePermissionIds)
39245
+ *
39246
+ * @param granteeId - Grantee ID to get permissions for
39247
+ * @returns Promise resolving to array of permission IDs
39248
+ */
39249
+ async getGranteePermissions(granteeId) {
39250
+ try {
39251
+ const chainId = await this.context.publicClient.getChainId();
39252
+ const DataPortabilityGranteesAddress = getContractAddress(
39253
+ chainId,
39254
+ "DataPortabilityGrantees"
39255
+ );
39256
+ const DataPortabilityGranteesAbi = getAbi("DataPortabilityGrantees");
39257
+ const permissions = await this.context.publicClient.readContract({
39258
+ address: DataPortabilityGranteesAddress,
39259
+ abi: DataPortabilityGranteesAbi,
39260
+ functionName: "granteePermissions",
39261
+ args: [granteeId]
39262
+ });
39263
+ return [...permissions];
39264
+ } catch (error) {
39265
+ throw new BlockchainError(
39266
+ `Failed to get grantee permissions: ${error instanceof Error ? error.message : "Unknown error"}`,
39267
+ error
39268
+ );
39269
+ }
39270
+ }
39271
+ // ===== DataPortabilityServersImplementation Methods =====
39272
+ /**
39273
+ * Get all server IDs for a user
39274
+ *
39275
+ * @param userAddress - User address to get server IDs for
39276
+ * @returns Promise resolving to array of server IDs
39277
+ */
39278
+ async getUserServerIdsValues(userAddress) {
39279
+ try {
39280
+ const chainId = await this.context.publicClient.getChainId();
39281
+ const DataPortabilityServersAddress = getContractAddress(
39282
+ chainId,
39283
+ "DataPortabilityServers"
39284
+ );
39285
+ const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
39286
+ const serverIds = await this.context.publicClient.readContract({
39287
+ address: DataPortabilityServersAddress,
39288
+ abi: DataPortabilityServersAbi,
39289
+ functionName: "userServerIdsValues",
39290
+ args: [userAddress]
39291
+ });
39292
+ return [...serverIds];
39293
+ } catch (error) {
39294
+ throw new BlockchainError(
39295
+ `Failed to get user server IDs: ${error instanceof Error ? error.message : "Unknown error"}`,
39296
+ error
39297
+ );
39298
+ }
39299
+ }
39300
+ /**
39301
+ * Get server ID at specific index for a user
39302
+ *
39303
+ * @param userAddress - User address
39304
+ * @param serverIndex - Index of the server ID
39305
+ * @returns Promise resolving to server ID
39306
+ */
39307
+ async getUserServerIdsAt(userAddress, serverIndex) {
39308
+ try {
39309
+ const chainId = await this.context.publicClient.getChainId();
39310
+ const DataPortabilityServersAddress = getContractAddress(
39311
+ chainId,
39312
+ "DataPortabilityServers"
39313
+ );
39314
+ const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
39315
+ const serverId = await this.context.publicClient.readContract({
39316
+ address: DataPortabilityServersAddress,
39317
+ abi: DataPortabilityServersAbi,
39318
+ functionName: "userServerIdsAt",
39319
+ args: [userAddress, serverIndex]
39320
+ });
39321
+ return serverId;
39322
+ } catch (error) {
39323
+ throw new BlockchainError(
39324
+ `Failed to get user server ID at index: ${error instanceof Error ? error.message : "Unknown error"}`,
39325
+ error
39326
+ );
39327
+ }
39328
+ }
39329
+ /**
39330
+ * Get the number of servers a user has
39331
+ *
39332
+ * @param userAddress - User address
39333
+ * @returns Promise resolving to number of servers
39334
+ */
39335
+ async getUserServerIdsLength(userAddress) {
39336
+ try {
39337
+ const chainId = await this.context.publicClient.getChainId();
39338
+ const DataPortabilityServersAddress = getContractAddress(
39339
+ chainId,
39340
+ "DataPortabilityServers"
39341
+ );
39342
+ const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
39343
+ const length = await this.context.publicClient.readContract({
39344
+ address: DataPortabilityServersAddress,
39345
+ abi: DataPortabilityServersAbi,
39346
+ functionName: "userServerIdsLength",
39347
+ args: [userAddress]
39348
+ });
39349
+ return length;
39350
+ } catch (error) {
39351
+ throw new BlockchainError(
39352
+ `Failed to get user server IDs length: ${error instanceof Error ? error.message : "Unknown error"}`,
39353
+ error
39354
+ );
39355
+ }
39356
+ }
39357
+ /**
39358
+ * Get trusted server info for a specific user and server ID
39359
+ *
39360
+ * @param userAddress - User address
39361
+ * @param serverId - Server ID
39362
+ * @returns Promise resolving to trusted server info
39363
+ */
39364
+ async getUserServers(userAddress, serverId) {
39365
+ try {
39366
+ const chainId = await this.context.publicClient.getChainId();
39367
+ const DataPortabilityServersAddress = getContractAddress(
39368
+ chainId,
39369
+ "DataPortabilityServers"
39370
+ );
39371
+ const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
39372
+ const serverInfo = await this.context.publicClient.readContract({
39373
+ address: DataPortabilityServersAddress,
39374
+ abi: DataPortabilityServersAbi,
39375
+ functionName: "userServers",
39376
+ args: [userAddress, serverId]
39377
+ });
39378
+ return {
39379
+ id: serverInfo.id,
39380
+ owner: serverInfo.owner,
39381
+ serverAddress: serverInfo.serverAddress,
39382
+ publicKey: serverInfo.publicKey,
39383
+ url: serverInfo.url,
39384
+ startBlock: serverInfo.startBlock,
39385
+ endBlock: serverInfo.endBlock
39386
+ };
39387
+ } catch (error) {
39388
+ throw new BlockchainError(
39389
+ `Failed to get user server info: ${error instanceof Error ? error.message : "Unknown error"}`,
39390
+ error
39391
+ );
39392
+ }
39393
+ }
39394
+ /**
39395
+ * Get server info by server ID
39396
+ *
39397
+ * @param serverId - Server ID
39398
+ * @returns Promise resolving to server info
39399
+ */
39400
+ async getServers(serverId) {
39401
+ try {
39402
+ const chainId = await this.context.publicClient.getChainId();
39403
+ const DataPortabilityServersAddress = getContractAddress(
39404
+ chainId,
39405
+ "DataPortabilityServers"
39406
+ );
39407
+ const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
39408
+ const serverInfo = await this.context.publicClient.readContract({
39409
+ address: DataPortabilityServersAddress,
39410
+ abi: DataPortabilityServersAbi,
39411
+ functionName: "servers",
39412
+ args: [serverId]
39413
+ });
39414
+ return {
39415
+ id: serverInfo.id,
39416
+ owner: serverInfo.owner,
39417
+ serverAddress: serverInfo.serverAddress,
39418
+ publicKey: serverInfo.publicKey,
39419
+ url: serverInfo.url
39420
+ };
39421
+ } catch (error) {
39422
+ throw new BlockchainError(
39423
+ `Failed to get server info: ${error instanceof Error ? error.message : "Unknown error"}`,
39424
+ error
39425
+ );
39426
+ }
39427
+ }
39428
+ /**
39429
+ * Get user info including nonce and trusted server IDs
39430
+ *
39431
+ * @param userAddress - User address
39432
+ * @returns Promise resolving to user info
39433
+ */
39434
+ async getUsers(userAddress) {
39435
+ try {
39436
+ const chainId = await this.context.publicClient.getChainId();
39437
+ const DataPortabilityServersAddress = getContractAddress(
39438
+ chainId,
39439
+ "DataPortabilityServers"
39440
+ );
39441
+ const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
39442
+ const userInfo = await this.context.publicClient.readContract({
39443
+ address: DataPortabilityServersAddress,
39444
+ abi: DataPortabilityServersAbi,
39445
+ functionName: "users",
39446
+ args: [userAddress]
39447
+ });
39448
+ return {
39449
+ nonce: userInfo[0],
39450
+ trustedServerIds: [...userInfo[1]]
39451
+ };
39452
+ } catch (error) {
39453
+ throw new BlockchainError(
39454
+ `Failed to get user info: ${error instanceof Error ? error.message : "Unknown error"}`,
39455
+ error
39456
+ );
39457
+ }
39458
+ }
39459
+ /**
39460
+ * Update server URL
39461
+ *
39462
+ * @param serverId - Server ID to update
39463
+ * @param url - New URL for the server
39464
+ * @returns Promise resolving to transaction hash
39465
+ */
39466
+ async submitUpdateServer(serverId, url) {
39467
+ try {
39468
+ const chainId = await this.context.walletClient.getChainId();
39469
+ const DataPortabilityServersAddress = getContractAddress(
39470
+ chainId,
39471
+ "DataPortabilityServers"
39472
+ );
39473
+ const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
39474
+ const hash = await this.context.walletClient.writeContract({
39475
+ address: DataPortabilityServersAddress,
39476
+ abi: DataPortabilityServersAbi,
39477
+ functionName: "updateServer",
39478
+ args: [serverId, url],
39479
+ chain: this.context.walletClient.chain,
39480
+ account: this.context.walletClient.account || null
39481
+ });
39482
+ return hash;
39483
+ } catch (error) {
39484
+ throw new BlockchainError(
39485
+ `Failed to update server: ${error instanceof Error ? error.message : "Unknown error"}`,
39486
+ error
39487
+ );
39488
+ }
39489
+ }
39490
+ // ===== DataPortabilityPermissionsImplementation Methods =====
39491
+ /**
39492
+ * Get all permission IDs for a user
39493
+ *
39494
+ * @param userAddress - User address to get permission IDs for
39495
+ * @returns Promise resolving to array of permission IDs
39496
+ */
39497
+ async getUserPermissionIdsValues(userAddress) {
39498
+ try {
39499
+ const chainId = await this.context.publicClient.getChainId();
39500
+ const DataPortabilityPermissionsAddress = getContractAddress(
39501
+ chainId,
39502
+ "DataPortabilityPermissions"
39503
+ );
39504
+ const DataPortabilityPermissionsAbi = getAbi(
39505
+ "DataPortabilityPermissions"
39506
+ );
39507
+ const permissionIds = await this.context.publicClient.readContract({
39508
+ address: DataPortabilityPermissionsAddress,
39509
+ abi: DataPortabilityPermissionsAbi,
39510
+ functionName: "userPermissionIdsValues",
39511
+ args: [userAddress]
39512
+ });
39513
+ return [...permissionIds];
39514
+ } catch (error) {
39515
+ throw new BlockchainError(
39516
+ `Failed to get user permission IDs: ${error instanceof Error ? error.message : "Unknown error"}`,
39517
+ error
39518
+ );
39519
+ }
39520
+ }
39521
+ /**
39522
+ * Get permission ID at specific index for a user
39523
+ *
39524
+ * @param userAddress - User address
39525
+ * @param permissionIndex - Index of the permission ID
39526
+ * @returns Promise resolving to permission ID
39527
+ */
39528
+ async getUserPermissionIdsAt(userAddress, permissionIndex) {
39529
+ try {
39530
+ const chainId = await this.context.publicClient.getChainId();
39531
+ const DataPortabilityPermissionsAddress = getContractAddress(
39532
+ chainId,
39533
+ "DataPortabilityPermissions"
39534
+ );
39535
+ const DataPortabilityPermissionsAbi = getAbi(
39536
+ "DataPortabilityPermissions"
39537
+ );
39538
+ const permissionId = await this.context.publicClient.readContract({
39539
+ address: DataPortabilityPermissionsAddress,
39540
+ abi: DataPortabilityPermissionsAbi,
39541
+ functionName: "userPermissionIdsAt",
39542
+ args: [userAddress, permissionIndex]
39543
+ });
39544
+ return permissionId;
39545
+ } catch (error) {
39546
+ throw new BlockchainError(
39547
+ `Failed to get user permission ID at index: ${error instanceof Error ? error.message : "Unknown error"}`,
39548
+ error
39549
+ );
39550
+ }
39551
+ }
39552
+ /**
39553
+ * Get the number of permissions a user has
39554
+ *
39555
+ * @param userAddress - User address
39556
+ * @returns Promise resolving to number of permissions
39557
+ */
39558
+ async getUserPermissionIdsLength(userAddress) {
39559
+ try {
39560
+ const chainId = await this.context.publicClient.getChainId();
39561
+ const DataPortabilityPermissionsAddress = getContractAddress(
39562
+ chainId,
39563
+ "DataPortabilityPermissions"
39564
+ );
39565
+ const DataPortabilityPermissionsAbi = getAbi(
39566
+ "DataPortabilityPermissions"
39567
+ );
39568
+ const length = await this.context.publicClient.readContract({
39569
+ address: DataPortabilityPermissionsAddress,
39570
+ abi: DataPortabilityPermissionsAbi,
39571
+ functionName: "userPermissionIdsLength",
39572
+ args: [userAddress]
39573
+ });
39574
+ return length;
39575
+ } catch (error) {
39576
+ throw new BlockchainError(
39577
+ `Failed to get user permission IDs length: ${error instanceof Error ? error.message : "Unknown error"}`,
39578
+ error
39579
+ );
39580
+ }
39581
+ }
39582
+ /**
39583
+ * Get permission info by permission ID
39584
+ *
39585
+ * @param permissionId - Permission ID
39586
+ * @returns Promise resolving to permission info
39587
+ */
39588
+ async getPermissions(permissionId) {
39589
+ try {
39590
+ const chainId = await this.context.publicClient.getChainId();
39591
+ const DataPortabilityPermissionsAddress = getContractAddress(
39592
+ chainId,
39593
+ "DataPortabilityPermissions"
39594
+ );
39595
+ const DataPortabilityPermissionsAbi = getAbi(
39596
+ "DataPortabilityPermissions"
39597
+ );
39598
+ const permissionInfo = await this.context.publicClient.readContract({
39599
+ address: DataPortabilityPermissionsAddress,
39600
+ abi: DataPortabilityPermissionsAbi,
39601
+ functionName: "permissions",
39602
+ args: [permissionId]
39603
+ });
39604
+ return {
39605
+ id: permissionInfo.id,
39606
+ grantor: permissionInfo.grantor,
39607
+ nonce: permissionInfo.nonce,
39608
+ granteeId: permissionInfo.granteeId,
39609
+ grant: permissionInfo.grant,
39610
+ startBlock: permissionInfo.startBlock,
39611
+ endBlock: permissionInfo.endBlock,
39612
+ fileIds: [...permissionInfo.fileIds]
39613
+ };
39614
+ } catch (error) {
39615
+ throw new BlockchainError(
39616
+ `Failed to get permission info: ${error instanceof Error ? error.message : "Unknown error"}`,
39617
+ error
39618
+ );
39619
+ }
39620
+ }
39621
+ /**
39622
+ * Submit permission with signature to the blockchain (supports gasless transactions)
39623
+ *
39624
+ * @param params - Parameters for adding permission
39625
+ * @returns Promise resolving to transaction hash
39626
+ * @throws {RelayerError} When gasless transaction submission fails
39627
+ * @throws {SignatureError} When user rejects the signature request
39628
+ * @throws {BlockchainError} When permission addition fails
39629
+ * @throws {NetworkError} When network communication fails
39630
+ */
39631
+ async submitAddPermission(params) {
39632
+ try {
39633
+ const nonce = await this.getPermissionsUserNonce();
39634
+ const addPermissionInput = {
39635
+ nonce,
39636
+ granteeId: params.granteeId,
39637
+ grant: params.grant,
39638
+ fileUrls: params.fileUrls,
39639
+ serverAddress: params.serverAddress,
39640
+ serverUrl: params.serverUrl,
39641
+ serverPublicKey: params.serverPublicKey,
39642
+ filePermissions: params.filePermissions
39643
+ };
39644
+ const typedData = await this.composeServerFilesAndPermissionMessage(addPermissionInput);
39645
+ const signature = await this.signTypedData(typedData);
39646
+ return await this.submitSignedAddPermission(typedData, signature);
39647
+ } catch (error) {
39648
+ if (error instanceof RelayerError || error instanceof UserRejectedRequestError || error instanceof SerializationError || error instanceof SignatureError || error instanceof NetworkError || error instanceof NonceError) {
39649
+ throw error;
39650
+ }
39651
+ throw new BlockchainError(
39652
+ `Failed to add permission: ${error instanceof Error ? error.message : "Unknown error"}`,
39653
+ error
39654
+ );
39655
+ }
39656
+ }
39657
+ /**
39658
+ * Submits an already-signed add permission transaction to the blockchain.
39659
+ * This method supports both relayer-based gasless transactions and direct transactions.
39660
+ *
39661
+ * @param typedData - The EIP-712 typed data for AddPermission
39662
+ * @param signature - The user's signature
39663
+ * @returns Promise resolving to the transaction hash
39664
+ * @throws {RelayerError} When gasless transaction submission fails
39665
+ * @throws {BlockchainError} When permission addition fails
39666
+ * @throws {NetworkError} When network communication fails
39667
+ */
39668
+ async submitSignedAddPermission(typedData, signature) {
39669
+ try {
39670
+ if (this.context.relayerCallbacks?.submitAddPermission) {
39671
+ return await this.context.relayerCallbacks.submitAddPermission(
39672
+ typedData,
39673
+ signature
39674
+ );
39675
+ } else {
39676
+ return await this.submitDirectAddPermissionTransaction(
39677
+ typedData,
39678
+ signature
39679
+ );
39680
+ }
39681
+ } catch (error) {
39682
+ if (error instanceof RelayerError || error instanceof NetworkError || error instanceof UserRejectedRequestError || error instanceof SignatureError || error instanceof NonceError) {
39683
+ throw error;
39684
+ }
39685
+ throw new BlockchainError(
39686
+ `Add permission submission failed: ${error instanceof Error ? error.message : "Unknown error"}`,
39687
+ error
39688
+ );
39689
+ }
39690
+ }
39691
+ /**
39692
+ * Submit server files and permissions with signature to the blockchain (supports gasless transactions)
39693
+ *
39694
+ * @param params - Parameters for adding server files and permissions
39695
+ * @returns Promise resolving to transaction hash
39696
+ * @throws {RelayerError} When gasless transaction submission fails
39697
+ * @throws {SignatureError} When user rejects the signature request
39698
+ * @throws {BlockchainError} When server files and permissions addition fails
39699
+ * @throws {NetworkError} When network communication fails
39700
+ */
39701
+ async submitAddServerFilesAndPermissions(params) {
39702
+ try {
39703
+ const nonce = await this.getPermissionsUserNonce();
39704
+ const serverFilesAndPermissionInput = {
39705
+ nonce,
39706
+ granteeId: params.granteeId,
39707
+ grant: params.grant,
39708
+ fileUrls: params.fileUrls,
39709
+ serverAddress: params.serverAddress,
39710
+ serverUrl: params.serverUrl,
39711
+ serverPublicKey: params.serverPublicKey,
39712
+ filePermissions: params.filePermissions
39713
+ };
39714
+ const typedData = await this.composeServerFilesAndPermissionMessage(
39715
+ serverFilesAndPermissionInput
39716
+ );
39717
+ const signature = await this.signTypedData(typedData);
39718
+ return await this.submitSignedAddServerFilesAndPermissions(
39719
+ typedData,
39720
+ signature
39721
+ );
39722
+ } catch (error) {
39723
+ if (error instanceof RelayerError || error instanceof UserRejectedRequestError || error instanceof SerializationError || error instanceof SignatureError || error instanceof NetworkError || error instanceof NonceError) {
39724
+ throw error;
39725
+ }
39726
+ throw new BlockchainError(
39727
+ `Failed to add server files and permissions: ${error instanceof Error ? error.message : "Unknown error"}`,
39728
+ error
39729
+ );
39730
+ }
39731
+ }
39732
+ /**
39733
+ * Submits an already-signed add server files and permissions transaction to the blockchain.
39734
+ * This method supports both relayer-based gasless transactions and direct transactions.
39735
+ *
39736
+ * @param typedData - The EIP-712 typed data for AddServerFilesAndPermissions
39737
+ * @param signature - The user's signature
39738
+ * @returns Promise resolving to the transaction hash
39739
+ * @throws {RelayerError} When gasless transaction submission fails
39740
+ * @throws {BlockchainError} When server files and permissions addition fails
39741
+ * @throws {NetworkError} When network communication fails
39742
+ */
39743
+ async submitSignedAddServerFilesAndPermissions(typedData, signature) {
39744
+ try {
39745
+ console.debug("\u{1F50D} submitSignedAddServerFilesAndPermissions Debug Info:", {
39746
+ hasRelayerCallbacks: !!this.context.relayerCallbacks,
39747
+ hasSubmitMethod: !!this.context.relayerCallbacks?.submitAddServerFilesAndPermissions,
39748
+ availableRelayerMethods: this.context.relayerCallbacks ? Object.keys(this.context.relayerCallbacks) : []
39749
+ });
39750
+ if (this.context.relayerCallbacks?.submitAddServerFilesAndPermissions) {
39751
+ console.debug(
39752
+ "\u{1F680} Using relayer for submitAddServerFilesAndPermissions"
39753
+ );
39754
+ return await this.context.relayerCallbacks.submitAddServerFilesAndPermissions(
39755
+ typedData,
39756
+ signature
39757
+ );
39758
+ } else {
39759
+ console.debug(
39760
+ "\u{1F4DD} Using direct transaction for submitAddServerFilesAndPermissions"
39761
+ );
39762
+ return await this.submitDirectAddServerFilesAndPermissionsTransaction(
39763
+ typedData,
39764
+ signature
39765
+ );
39766
+ }
39767
+ } catch (error) {
39768
+ if (error instanceof RelayerError || error instanceof NetworkError || error instanceof UserRejectedRequestError || error instanceof SignatureError || error instanceof NonceError) {
39769
+ throw error;
39770
+ }
39771
+ throw new BlockchainError(
39772
+ `Add server files and permissions submission failed: ${error instanceof Error ? error.message : "Unknown error"}`,
39773
+ error
39774
+ );
39775
+ }
39776
+ }
39777
+ /**
39778
+ * Submit permission revocation with signature to the blockchain
39779
+ *
39780
+ * @param permissionId - Permission ID to revoke
39781
+ * @returns Promise resolving to transaction hash
39782
+ */
39783
+ async submitRevokePermission(permissionId) {
39784
+ try {
39785
+ const chainId = await this.context.walletClient.getChainId();
39786
+ const DataPortabilityPermissionsAddress = getContractAddress(
39787
+ chainId,
39788
+ "DataPortabilityPermissions"
39789
+ );
39790
+ const DataPortabilityPermissionsAbi = getAbi(
39791
+ "DataPortabilityPermissions"
39792
+ );
39793
+ const hash = await this.context.walletClient.writeContract({
39794
+ address: DataPortabilityPermissionsAddress,
39795
+ abi: DataPortabilityPermissionsAbi,
39796
+ functionName: "revokePermission",
39797
+ args: [permissionId],
39798
+ chain: this.context.walletClient.chain,
39799
+ account: this.context.walletClient.account || null
39800
+ });
39801
+ return hash;
39802
+ } catch (error) {
39803
+ throw new BlockchainError(
39804
+ `Failed to revoke permission: ${error instanceof Error ? error.message : "Unknown error"}`,
39805
+ error
39806
+ );
39807
+ }
39808
+ }
39809
+ /**
39810
+ * Submits a signed add permission transaction directly to the blockchain.
39811
+ *
39812
+ * @param typedData - The typed data structure for the permission addition
39813
+ * @param signature - The cryptographic signature authorizing the transaction
39814
+ * @returns Promise resolving to the transaction hash
39815
+ */
39816
+ async submitDirectAddPermissionTransaction(typedData, signature) {
39817
+ const chainId = await this.context.walletClient.getChainId();
39818
+ const DataPortabilityPermissionsAddress = getContractAddress(
39819
+ chainId,
39820
+ "DataPortabilityPermissions"
39821
+ );
39822
+ const DataPortabilityPermissionsAbi = getAbi("DataPortabilityPermissions");
39823
+ const permissionInput = {
39824
+ nonce: typedData.message.nonce,
39825
+ granteeId: typedData.message.granteeId,
39826
+ grant: typedData.message.grant,
39827
+ fileIds: typedData.message.fileIds || []
39828
+ };
39829
+ const formattedSignature = formatSignatureForContract(signature);
39830
+ const hash = await this.context.walletClient.writeContract({
39831
+ address: DataPortabilityPermissionsAddress,
39832
+ abi: DataPortabilityPermissionsAbi,
39833
+ functionName: "addPermission",
39834
+ args: [permissionInput, formattedSignature],
39835
+ account: this.context.walletClient.account || await this.getUserAddress(),
39836
+ chain: this.context.walletClient.chain || null
39837
+ });
39838
+ return hash;
39839
+ }
39840
+ /**
39841
+ * Submits a signed add server files and permissions transaction directly to the blockchain.
39842
+ *
39843
+ * @param typedData - The typed data structure for the server files and permissions addition
39844
+ * @param signature - The cryptographic signature authorizing the transaction
39845
+ * @returns Promise resolving to the transaction hash
39846
+ */
39847
+ async submitDirectAddServerFilesAndPermissionsTransaction(typedData, signature) {
39848
+ const chainId = await this.context.walletClient.getChainId();
39849
+ const DataPortabilityPermissionsAddress = getContractAddress(
39850
+ chainId,
39851
+ "DataPortabilityPermissions"
39852
+ );
39853
+ const DataPortabilityPermissionsAbi = getAbi("DataPortabilityPermissions");
39854
+ const serverFilesAndPermissionInput = {
39855
+ nonce: typedData.message.nonce,
39856
+ granteeId: typedData.message.granteeId,
39857
+ grant: typedData.message.grant,
39858
+ fileUrls: typedData.message.fileUrls,
39859
+ serverAddress: typedData.message.serverAddress,
39860
+ serverUrl: typedData.message.serverUrl,
39861
+ serverPublicKey: typedData.message.serverPublicKey,
39862
+ filePermissions: typedData.message.filePermissions
39863
+ };
39864
+ const formattedSignature = formatSignatureForContract(signature);
39865
+ const hash = await this.context.walletClient.writeContract({
39866
+ address: DataPortabilityPermissionsAddress,
39867
+ abi: DataPortabilityPermissionsAbi,
39868
+ functionName: "addServerFilesAndPermissions",
39869
+ // @ts-expect-error - Complex nested array types cause compatibility issues with viem's generated types
39870
+ args: [serverFilesAndPermissionInput, formattedSignature],
39871
+ account: this.context.walletClient.account || await this.getUserAddress(),
39872
+ chain: this.context.walletClient.chain || null
39873
+ });
39874
+ return hash;
39875
+ }
38662
39876
  };
38663
39877
 
38664
39878
  // src/controllers/data.ts
39879
+ var import_viem4 = require("viem");
39880
+
39881
+ // src/utils/blockchain/registry.ts
38665
39882
  var import_viem3 = require("viem");
39883
+ async function fetchSchemaFromChain(context, schemaId) {
39884
+ const chainId = context.walletClient.chain?.id;
39885
+ if (!chainId) {
39886
+ throw new Error("Chain ID not available");
39887
+ }
39888
+ const dataRefinerRegistryAddress = getContractAddress(
39889
+ chainId,
39890
+ "DataRefinerRegistry"
39891
+ );
39892
+ const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
39893
+ const dataRefinerRegistry = (0, import_viem3.getContract)({
39894
+ address: dataRefinerRegistryAddress,
39895
+ abi: dataRefinerRegistryAbi,
39896
+ client: context.publicClient
39897
+ });
39898
+ const schemaData = await dataRefinerRegistry.read.schemas([BigInt(schemaId)]);
39899
+ if (!schemaData) {
39900
+ throw new Error(`Schema with ID ${schemaId} not found`);
39901
+ }
39902
+ const schemaObj = schemaData;
39903
+ if (!schemaObj.name || !schemaObj.typ || !schemaObj.definitionUrl) {
39904
+ throw new Error("Incomplete schema data");
39905
+ }
39906
+ return {
39907
+ id: schemaId,
39908
+ name: schemaObj.name,
39909
+ type: schemaObj.typ,
39910
+ definitionUrl: schemaObj.definitionUrl
39911
+ };
39912
+ }
39913
+ async function fetchSchemaCountFromChain(context) {
39914
+ const chainId = context.walletClient.chain?.id;
39915
+ if (!chainId) {
39916
+ throw new Error("Chain ID not available");
39917
+ }
39918
+ const dataRefinerRegistryAddress = getContractAddress(
39919
+ chainId,
39920
+ "DataRefinerRegistry"
39921
+ );
39922
+ const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
39923
+ const dataRefinerRegistry = (0, import_viem3.getContract)({
39924
+ address: dataRefinerRegistryAddress,
39925
+ abi: dataRefinerRegistryAbi,
39926
+ client: context.publicClient
39927
+ });
39928
+ const count = await dataRefinerRegistry.read.schemasCount();
39929
+ return Number(count);
39930
+ }
38666
39931
 
38667
39932
  // src/utils/encryption.ts
38668
39933
  var DEFAULT_ENCRYPTION_SEED = "Please sign to retrieve your encryption key";
@@ -38744,7 +40009,11 @@ async function encryptBlobWithSignedKey(data, key, platformAdapter) {
38744
40009
  dataArray,
38745
40010
  key
38746
40011
  );
38747
- return new Blob([encrypted], {
40012
+ const encryptedArrayBuffer = encrypted.buffer.slice(
40013
+ encrypted.byteOffset,
40014
+ encrypted.byteOffset + encrypted.byteLength
40015
+ );
40016
+ return new Blob([encryptedArrayBuffer], {
38748
40017
  type: "application/octet-stream"
38749
40018
  });
38750
40019
  } catch (error) {
@@ -38773,7 +40042,11 @@ async function decryptBlobWithSignedKey(encryptedData, key, platformAdapter) {
38773
40042
  encryptedArray,
38774
40043
  key
38775
40044
  );
38776
- return new Blob([decrypted], { type: "text/plain" });
40045
+ const decryptedArrayBuffer = decrypted.buffer.slice(
40046
+ decrypted.byteOffset,
40047
+ decrypted.byteOffset + decrypted.byteLength
40048
+ );
40049
+ return new Blob([decryptedArrayBuffer], { type: "text/plain" });
38777
40050
  } catch (error) {
38778
40051
  throw new Error(`Failed to decrypt data: ${error}`);
38779
40052
  }
@@ -38790,28 +40063,16 @@ var DataController = class {
38790
40063
  filename,
38791
40064
  schemaId,
38792
40065
  permissions = [],
38793
- encrypt: encrypt3 = true,
40066
+ encrypt = true,
38794
40067
  providerName,
38795
40068
  owner
38796
40069
  } = params;
38797
40070
  try {
38798
- let blob;
38799
- if (content instanceof Blob) {
38800
- blob = content;
38801
- } else if (typeof content === "string") {
38802
- blob = new Blob([content], { type: "text/plain" });
38803
- } else if (content instanceof Buffer) {
38804
- blob = new Blob([content], { type: "application/octet-stream" });
38805
- } else {
38806
- blob = new Blob([JSON.stringify(content)], {
38807
- type: "application/json"
38808
- });
38809
- }
38810
40071
  let isValid = true;
38811
40072
  let validationErrors = [];
38812
40073
  if (schemaId !== void 0) {
38813
40074
  try {
38814
- const schema = await this.getSchema(schemaId);
40075
+ const schema = await fetchSchemaFromChain(this.context, schemaId);
38815
40076
  const response = await fetch(schema.definitionUrl);
38816
40077
  if (!response.ok) {
38817
40078
  throw new Error(
@@ -38843,37 +40104,15 @@ var DataController = class {
38843
40104
  ];
38844
40105
  }
38845
40106
  }
38846
- let finalBlob = blob;
38847
- if (encrypt3) {
38848
- const encryptionKey = await generateEncryptionKey(
38849
- this.context.walletClient,
38850
- this.context.platform,
38851
- DEFAULT_ENCRYPTION_SEED
38852
- );
38853
- finalBlob = await encryptBlobWithSignedKey(
38854
- blob,
38855
- encryptionKey,
38856
- this.context.platform
38857
- );
38858
- }
38859
- if (!this.context.storageManager) {
38860
- if (this.context.validateStorageRequired) {
38861
- this.context.validateStorageRequired();
38862
- throw new Error("Storage validation failed");
38863
- } else {
38864
- throw new Error(
38865
- "Storage manager not configured. Please provide storage providers in VanaConfig."
38866
- );
38867
- }
38868
- }
38869
- const uploadResult = await this.context.storageManager.upload(
38870
- finalBlob,
40107
+ const uploadResult = await this.uploadToStorage(
40108
+ content,
38871
40109
  filename,
40110
+ encrypt,
38872
40111
  providerName
38873
40112
  );
38874
40113
  const userAddress = owner || await this.getUserAddress();
38875
40114
  let encryptedPermissions = [];
38876
- if (permissions.length > 0) {
40115
+ if (permissions.length > 0 && encrypt) {
38877
40116
  const userEncryptionKey = await generateEncryptionKey(
38878
40117
  this.context.walletClient,
38879
40118
  this.context.platform,
@@ -39591,7 +40830,7 @@ var DataController = class {
39591
40830
  }
39592
40831
  const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
39593
40832
  const dataRegistryAbi = getAbi("DataRegistry");
39594
- const dataRegistry = (0, import_viem3.getContract)({
40833
+ const dataRegistry = (0, import_viem4.getContract)({
39595
40834
  address: dataRegistryAddress,
39596
40835
  abi: dataRegistryAbi,
39597
40836
  client: this.context.walletClient
@@ -39642,7 +40881,7 @@ var DataController = class {
39642
40881
  }
39643
40882
  const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
39644
40883
  const dataRegistryAbi = getAbi("DataRegistry");
39645
- const dataRegistry = (0, import_viem3.getContract)({
40884
+ const dataRegistry = (0, import_viem4.getContract)({
39646
40885
  address: dataRegistryAddress,
39647
40886
  abi: dataRegistryAbi,
39648
40887
  client: this.context.walletClient
@@ -39680,205 +40919,6 @@ var DataController = class {
39680
40919
  );
39681
40920
  }
39682
40921
  }
39683
- /**
39684
- * Uploads an encrypted file to storage and registers it on the blockchain.
39685
- *
39686
- * @deprecated Since v2.0.0 - Use vana.data.upload() instead for the high-level API with automatic encryption
39687
- *
39688
- * Migration guide:
39689
- * ```typescript
39690
- * // Old way (deprecated):
39691
- * const encrypted = await encryptBlob(data, key);
39692
- * const result = await vana.data.uploadEncryptedFile(encrypted, filename);
39693
- *
39694
- * // New way:
39695
- * const result = await vana.data.upload({
39696
- * content: data,
39697
- * filename: filename,
39698
- * encrypt: true // Handles encryption automatically
39699
- * });
39700
- * ```
39701
- * @param encryptedFile - The encrypted file blob to upload
39702
- * @param filename - Optional filename for the upload
39703
- * @param providerName - Optional storage provider to use
39704
- * @returns Promise resolving to upload result with file ID and storage URL
39705
- *
39706
- * This method handles the complete flow of:
39707
- * 1. Uploading the encrypted file to the specified storage provider
39708
- * 2. Registering the file URL on the DataRegistry contract via relayer
39709
- * 3. Returning the assigned file ID and storage URL
39710
- */
39711
- async uploadEncryptedFile(encryptedFile, filename, providerName) {
39712
- try {
39713
- if (!this.context.storageManager) {
39714
- throw new Error(
39715
- "Storage manager not configured. Please provide storage providers in VanaConfig."
39716
- );
39717
- }
39718
- const uploadResult = await this.context.storageManager.upload(
39719
- encryptedFile,
39720
- filename,
39721
- providerName
39722
- );
39723
- const userAddress = await this.getUserAddress();
39724
- if (this.context.relayerCallbacks?.submitFileAddition) {
39725
- const result = await this.context.relayerCallbacks.submitFileAddition(
39726
- uploadResult.url,
39727
- userAddress
39728
- );
39729
- return {
39730
- fileId: result.fileId,
39731
- url: uploadResult.url,
39732
- size: uploadResult.size,
39733
- transactionHash: result.transactionHash
39734
- };
39735
- } else {
39736
- const chainId = this.context.walletClient.chain?.id;
39737
- if (!chainId) {
39738
- throw new Error("Chain ID not available");
39739
- }
39740
- const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
39741
- const dataRegistryAbi = getAbi("DataRegistry");
39742
- const txHash = await this.context.walletClient.writeContract({
39743
- address: dataRegistryAddress,
39744
- abi: dataRegistryAbi,
39745
- functionName: "addFile",
39746
- args: [uploadResult.url],
39747
- account: this.context.walletClient.account || userAddress,
39748
- chain: this.context.walletClient.chain || null
39749
- });
39750
- const receipt = await this.context.publicClient.waitForTransactionReceipt({
39751
- hash: txHash,
39752
- timeout: 3e4
39753
- // 30 seconds timeout
39754
- });
39755
- let fileId = 0;
39756
- for (const log of receipt.logs) {
39757
- try {
39758
- const decoded = (0, import_viem3.decodeEventLog)({
39759
- abi: dataRegistryAbi,
39760
- data: log.data,
39761
- topics: log.topics
39762
- });
39763
- if (decoded.eventName === "FileAdded") {
39764
- fileId = Number(decoded.args.fileId);
39765
- break;
39766
- }
39767
- } catch {
39768
- continue;
39769
- }
39770
- }
39771
- return {
39772
- fileId,
39773
- url: uploadResult.url,
39774
- size: uploadResult.size,
39775
- transactionHash: txHash
39776
- };
39777
- }
39778
- } catch (error) {
39779
- console.error("Failed to upload encrypted file:", error);
39780
- throw new Error(
39781
- `Upload failed: ${error instanceof Error ? error.message : "Unknown error"}`
39782
- );
39783
- }
39784
- }
39785
- /**
39786
- * Uploads an encrypted file to storage and registers it on the blockchain with a schema.
39787
- *
39788
- * @deprecated Since v2.0.0 - Use vana.data.upload() instead for the high-level API with automatic encryption and schema validation
39789
- *
39790
- * Migration guide:
39791
- * ```typescript
39792
- * // Old way (deprecated):
39793
- * const encrypted = await encryptBlob(data, key);
39794
- * const result = await vana.data.uploadEncryptedFileWithSchema(encrypted, schemaId, filename);
39795
- *
39796
- * // New way:
39797
- * const result = await vana.data.upload({
39798
- * content: data,
39799
- * filename: filename,
39800
- * schemaId: schemaId, // Automatic validation
39801
- * encrypt: true
39802
- * });
39803
- * ```
39804
- * @param encryptedFile - The encrypted file blob to upload
39805
- * @param schemaId - The schema ID to associate with the file
39806
- * @param filename - Optional filename for the upload
39807
- * @param providerName - Optional storage provider to use
39808
- * @returns Promise resolving to upload result with file ID and storage URL
39809
- *
39810
- * This method handles the complete flow of:
39811
- * 1. Uploading the encrypted file to the specified storage provider
39812
- * 2. Registering the file URL on the DataRegistry contract with a schema ID
39813
- * 3. Returning the assigned file ID and storage URL
39814
- */
39815
- async uploadEncryptedFileWithSchema(encryptedFile, schemaId, filename, providerName) {
39816
- try {
39817
- if (!this.context.storageManager) {
39818
- throw new Error(
39819
- "Storage manager not configured. Please provide storage providers in VanaConfig."
39820
- );
39821
- }
39822
- const uploadResult = await this.context.storageManager.upload(
39823
- encryptedFile,
39824
- filename,
39825
- providerName
39826
- );
39827
- const userAddress = await this.getUserAddress();
39828
- if (this.context.relayerCallbacks?.submitFileAddition) {
39829
- throw new Error(
39830
- "Relayer does not yet support uploading files with schema. Please use direct transaction mode."
39831
- );
39832
- } else {
39833
- const chainId = this.context.walletClient.chain?.id;
39834
- if (!chainId) {
39835
- throw new Error("Chain ID not available");
39836
- }
39837
- const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
39838
- const dataRegistryAbi = getAbi("DataRegistry");
39839
- const txHash = await this.context.walletClient.writeContract({
39840
- address: dataRegistryAddress,
39841
- abi: dataRegistryAbi,
39842
- functionName: "addFileWithSchema",
39843
- args: [uploadResult.url, BigInt(schemaId)],
39844
- account: this.context.walletClient.account || userAddress,
39845
- chain: this.context.walletClient.chain || null
39846
- });
39847
- const receipt = await this.context.publicClient.waitForTransactionReceipt({
39848
- hash: txHash,
39849
- timeout: 3e4
39850
- // 30 seconds timeout
39851
- });
39852
- let fileId = 0;
39853
- for (const log of receipt.logs) {
39854
- try {
39855
- const decoded = (0, import_viem3.decodeEventLog)({
39856
- abi: dataRegistryAbi,
39857
- data: log.data,
39858
- topics: log.topics
39859
- });
39860
- if (decoded.eventName === "FileAdded") {
39861
- fileId = Number(decoded.args.fileId);
39862
- break;
39863
- }
39864
- } catch {
39865
- continue;
39866
- }
39867
- }
39868
- return {
39869
- fileId,
39870
- url: uploadResult.url,
39871
- size: uploadResult.size,
39872
- transactionHash: txHash
39873
- };
39874
- }
39875
- } catch (error) {
39876
- console.error("Failed to upload encrypted file with schema:", error);
39877
- throw new Error(
39878
- `Upload failed: ${error instanceof Error ? error.message : "Unknown error"}`
39879
- );
39880
- }
39881
- }
39882
40922
  /**
39883
40923
  * Registers a file URL directly on the blockchain with a schema ID.
39884
40924
  *
@@ -39915,7 +40955,7 @@ var DataController = class {
39915
40955
  let fileId = 0;
39916
40956
  for (const log of receipt.logs) {
39917
40957
  try {
39918
- const decoded = (0, import_viem3.decodeEventLog)({
40958
+ const decoded = (0, import_viem4.decodeEventLog)({
39919
40959
  abi: dataRegistryAbi,
39920
40960
  data: log.data,
39921
40961
  topics: log.topics
@@ -39994,7 +41034,7 @@ var DataController = class {
39994
41034
  let fileId = 0;
39995
41035
  for (const log of receipt.logs) {
39996
41036
  try {
39997
- const decoded = (0, import_viem3.decodeEventLog)({
41037
+ const decoded = (0, import_viem4.decodeEventLog)({
39998
41038
  abi: dataRegistryAbi,
39999
41039
  data: log.data,
40000
41040
  topics: log.topics
@@ -40058,7 +41098,7 @@ var DataController = class {
40058
41098
  let fileId = 0;
40059
41099
  for (const log of receipt.logs) {
40060
41100
  try {
40061
- const decoded = (0, import_viem3.decodeEventLog)({
41101
+ const decoded = (0, import_viem4.decodeEventLog)({
40062
41102
  abi: dataRegistryAbi,
40063
41103
  data: log.data,
40064
41104
  topics: log.topics
@@ -40082,175 +41122,6 @@ var DataController = class {
40082
41122
  );
40083
41123
  }
40084
41124
  }
40085
- /**
40086
- * Adds a new schema to the DataRefinerRegistry.
40087
- *
40088
- * @deprecated Since v2.0.0 - Use vana.schemas.create() instead for the high-level API with automatic IPFS upload
40089
- *
40090
- * Migration guide:
40091
- * ```typescript
40092
- * // Old way (deprecated):
40093
- * const result = await vana.data.addSchema({
40094
- * name: "UserProfile",
40095
- * type: "JSON",
40096
- * definitionUrl: "ipfs://..."
40097
- * });
40098
- *
40099
- * // New way:
40100
- * const result = await vana.schemas.create({
40101
- * name: "UserProfile",
40102
- * type: "JSON",
40103
- * definition: schemaObject // Automatically uploads to IPFS
40104
- * });
40105
- * ```
40106
- * @param params - Schema parameters including name, type, and definition URL
40107
- * @returns Promise resolving to the new schema ID and transaction hash
40108
- */
40109
- async addSchema(params) {
40110
- try {
40111
- const chainId = this.context.walletClient.chain?.id;
40112
- if (!chainId) {
40113
- throw new Error("Chain ID not available");
40114
- }
40115
- const dataRefinerRegistryAddress = getContractAddress(
40116
- chainId,
40117
- "DataRefinerRegistry"
40118
- );
40119
- const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
40120
- const txHash = await this.context.walletClient.writeContract({
40121
- address: dataRefinerRegistryAddress,
40122
- abi: dataRefinerRegistryAbi,
40123
- functionName: "addSchema",
40124
- args: [params.name, params.type, params.definitionUrl],
40125
- account: this.context.walletClient.account || await this.getUserAddress(),
40126
- chain: this.context.walletClient.chain || null
40127
- });
40128
- const receipt = await this.context.publicClient.waitForTransactionReceipt(
40129
- {
40130
- hash: txHash,
40131
- timeout: 3e4
40132
- }
40133
- );
40134
- let schemaId = 0;
40135
- for (const log of receipt.logs) {
40136
- try {
40137
- const decoded = (0, import_viem3.decodeEventLog)({
40138
- abi: dataRefinerRegistryAbi,
40139
- data: log.data,
40140
- topics: log.topics
40141
- });
40142
- if (decoded.eventName === "SchemaAdded") {
40143
- schemaId = Number(decoded.args.schemaId);
40144
- break;
40145
- }
40146
- } catch {
40147
- continue;
40148
- }
40149
- }
40150
- return {
40151
- schemaId,
40152
- transactionHash: txHash
40153
- };
40154
- } catch (error) {
40155
- console.error("Failed to add schema:", error);
40156
- throw new Error(
40157
- `Failed to add schema: ${error instanceof Error ? error.message : "Unknown error"}`
40158
- );
40159
- }
40160
- }
40161
- /**
40162
- * Retrieves a schema by its ID.
40163
- *
40164
- * @deprecated Since v2.0.0 - Use vana.schemas.get() instead
40165
- *
40166
- * Migration guide:
40167
- * ```typescript
40168
- * // Old way (deprecated):
40169
- * const schema = await vana.data.getSchema(schemaId);
40170
- *
40171
- * // New way:
40172
- * const schema = await vana.schemas.get(schemaId);
40173
- * ```
40174
- * @param schemaId - The schema ID to retrieve
40175
- * @returns Promise resolving to the schema information
40176
- */
40177
- async getSchema(schemaId) {
40178
- try {
40179
- const chainId = this.context.walletClient.chain?.id;
40180
- if (!chainId) {
40181
- throw new Error("Chain ID not available");
40182
- }
40183
- const dataRefinerRegistryAddress = getContractAddress(
40184
- chainId,
40185
- "DataRefinerRegistry"
40186
- );
40187
- const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
40188
- const dataRefinerRegistry = (0, import_viem3.getContract)({
40189
- address: dataRefinerRegistryAddress,
40190
- abi: dataRefinerRegistryAbi,
40191
- client: this.context.walletClient
40192
- });
40193
- const schemaData = await dataRefinerRegistry.read.schemas([
40194
- BigInt(schemaId)
40195
- ]);
40196
- if (!schemaData) {
40197
- throw new Error("Schema not found");
40198
- }
40199
- const schemaObj = schemaData;
40200
- if (!schemaObj.name || !schemaObj.typ || !schemaObj.definitionUrl) {
40201
- throw new Error("Incomplete schema data");
40202
- }
40203
- return {
40204
- id: schemaId,
40205
- name: schemaObj.name,
40206
- type: schemaObj.typ,
40207
- definitionUrl: schemaObj.definitionUrl
40208
- };
40209
- } catch (error) {
40210
- console.error("Failed to get schema:", error);
40211
- throw new Error(
40212
- `Failed to get schema ${schemaId}: ${error instanceof Error ? error.message : "Unknown error"}`
40213
- );
40214
- }
40215
- }
40216
- /**
40217
- * Gets the total number of schemas in the registry.
40218
- *
40219
- * @deprecated Since v2.0.0 - Use vana.schemas.count() instead
40220
- *
40221
- * Migration guide:
40222
- * ```typescript
40223
- * // Old way (deprecated):
40224
- * const count = await vana.data.getSchemasCount();
40225
- *
40226
- * // New way:
40227
- * const count = await vana.schemas.count();
40228
- * ```
40229
- * @returns Promise resolving to the total schema count
40230
- */
40231
- async getSchemasCount() {
40232
- try {
40233
- const chainId = this.context.walletClient.chain?.id;
40234
- if (!chainId) {
40235
- throw new Error("Chain ID not available");
40236
- }
40237
- const dataRefinerRegistryAddress = getContractAddress(
40238
- chainId,
40239
- "DataRefinerRegistry"
40240
- );
40241
- const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
40242
- const dataRefinerRegistry = (0, import_viem3.getContract)({
40243
- address: dataRefinerRegistryAddress,
40244
- abi: dataRefinerRegistryAbi,
40245
- client: this.context.walletClient
40246
- });
40247
- const count = await dataRefinerRegistry.read.schemasCount();
40248
- return Number(count);
40249
- } catch (error) {
40250
- console.error("Failed to get schemas count:", error);
40251
- return 0;
40252
- }
40253
- }
40254
41125
  /**
40255
41126
  * Adds a new refiner to the DataRefinerRegistry.
40256
41127
  *
@@ -40290,7 +41161,7 @@ var DataController = class {
40290
41161
  let refinerId = 0;
40291
41162
  for (const log of receipt.logs) {
40292
41163
  try {
40293
- const decoded = (0, import_viem3.decodeEventLog)({
41164
+ const decoded = (0, import_viem4.decodeEventLog)({
40294
41165
  abi: dataRefinerRegistryAbi,
40295
41166
  data: log.data,
40296
41167
  topics: log.topics
@@ -40331,7 +41202,7 @@ var DataController = class {
40331
41202
  "DataRefinerRegistry"
40332
41203
  );
40333
41204
  const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
40334
- const dataRefinerRegistry = (0, import_viem3.getContract)({
41205
+ const dataRefinerRegistry = (0, import_viem4.getContract)({
40335
41206
  address: dataRefinerRegistryAddress,
40336
41207
  abi: dataRefinerRegistryAbi,
40337
41208
  client: this.context.walletClient
@@ -40374,7 +41245,7 @@ var DataController = class {
40374
41245
  "DataRefinerRegistry"
40375
41246
  );
40376
41247
  const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
40377
- const dataRefinerRegistry = (0, import_viem3.getContract)({
41248
+ const dataRefinerRegistry = (0, import_viem4.getContract)({
40378
41249
  address: dataRefinerRegistryAddress,
40379
41250
  abi: dataRefinerRegistryAbi,
40380
41251
  client: this.context.walletClient
@@ -40404,7 +41275,7 @@ var DataController = class {
40404
41275
  "DataRefinerRegistry"
40405
41276
  );
40406
41277
  const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
40407
- const dataRefinerRegistry = (0, import_viem3.getContract)({
41278
+ const dataRefinerRegistry = (0, import_viem4.getContract)({
40408
41279
  address: dataRefinerRegistryAddress,
40409
41280
  abi: dataRefinerRegistryAbi,
40410
41281
  client: this.context.walletClient
@@ -40472,27 +41343,19 @@ var DataController = class {
40472
41343
  */
40473
41344
  async uploadFileWithPermissions(data, permissions, filename, providerName) {
40474
41345
  try {
40475
- const userEncryptionKey = await generateEncryptionKey(
40476
- this.context.walletClient,
40477
- this.context.platform,
40478
- DEFAULT_ENCRYPTION_SEED
40479
- );
40480
- const encryptedData = await encryptBlobWithSignedKey(
41346
+ const uploadResult = await this.uploadToStorage(
40481
41347
  data,
40482
- userEncryptionKey,
40483
- this.context.platform
40484
- );
40485
- if (!this.context.storageManager) {
40486
- throw new Error(
40487
- "Storage manager not configured. Please provide storage providers in VanaConfig."
40488
- );
40489
- }
40490
- const uploadResult = await this.context.storageManager.upload(
40491
- encryptedData,
40492
41348
  filename,
41349
+ true,
41350
+ // Always encrypt for uploadFileWithPermissions
40493
41351
  providerName
40494
41352
  );
40495
41353
  const userAddress = await this.getUserAddress();
41354
+ const userEncryptionKey = await generateEncryptionKey(
41355
+ this.context.walletClient,
41356
+ this.context.platform,
41357
+ DEFAULT_ENCRYPTION_SEED
41358
+ );
40496
41359
  const encryptedPermissions = await Promise.all(
40497
41360
  permissions.map(async (permission) => {
40498
41361
  const encryptedKey = await encryptWithWalletPublicKey(
@@ -40533,6 +41396,70 @@ var DataController = class {
40533
41396
  );
40534
41397
  }
40535
41398
  }
41399
+ /**
41400
+ * Uploads content to storage without registering it on the blockchain.
41401
+ * This method only handles the storage upload and returns the file URL.
41402
+ *
41403
+ * @param content - The content to upload (string, Blob, Buffer, or object - objects will be JSON stringified)
41404
+ * @param filename - Optional filename for the uploaded file (defaults to timestamp-based name)
41405
+ * @param encrypt - Optional flag to encrypt the content before upload
41406
+ * @param providerName - Optional specific storage provider to use
41407
+ * @returns Promise resolving to the storage upload result with url, size, and contentType
41408
+ */
41409
+ async uploadToStorage(content, filename, encrypt = false, providerName) {
41410
+ try {
41411
+ let blob;
41412
+ if (content instanceof Blob) {
41413
+ blob = content;
41414
+ } else if (typeof content === "string") {
41415
+ blob = new Blob([content], { type: "text/plain" });
41416
+ } else if (content instanceof Buffer) {
41417
+ const arrayBuffer = content.buffer.slice(
41418
+ content.byteOffset,
41419
+ content.byteOffset + content.byteLength
41420
+ );
41421
+ blob = new Blob([arrayBuffer], { type: "application/octet-stream" });
41422
+ } else {
41423
+ blob = new Blob([JSON.stringify(content)], {
41424
+ type: "application/json"
41425
+ });
41426
+ }
41427
+ let finalBlob = blob;
41428
+ if (encrypt) {
41429
+ const encryptionKey = await generateEncryptionKey(
41430
+ this.context.walletClient,
41431
+ this.context.platform,
41432
+ DEFAULT_ENCRYPTION_SEED
41433
+ );
41434
+ finalBlob = await encryptBlobWithSignedKey(
41435
+ blob,
41436
+ encryptionKey,
41437
+ this.context.platform
41438
+ );
41439
+ }
41440
+ if (!this.context.storageManager) {
41441
+ if (this.context.validateStorageRequired) {
41442
+ this.context.validateStorageRequired();
41443
+ throw new Error("Storage validation failed");
41444
+ } else {
41445
+ throw new Error(
41446
+ "Storage manager not configured. Please provide storage providers in VanaConfig."
41447
+ );
41448
+ }
41449
+ }
41450
+ const finalFilename = filename || `upload-${Date.now()}.dat`;
41451
+ const uploadResult = await this.context.storageManager.upload(
41452
+ finalBlob,
41453
+ finalFilename,
41454
+ providerName
41455
+ );
41456
+ return uploadResult;
41457
+ } catch (error) {
41458
+ throw new Error(
41459
+ `Upload failed: ${error instanceof Error ? error.message : "Unknown error"}`
41460
+ );
41461
+ }
41462
+ }
40536
41463
  /**
40537
41464
  * Adds a permission for a party to access an existing file.
40538
41465
  *
@@ -40628,7 +41555,7 @@ var DataController = class {
40628
41555
  }
40629
41556
  const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
40630
41557
  const dataRegistryAbi = getAbi("DataRegistry");
40631
- const dataRegistry = (0, import_viem3.getContract)({
41558
+ const dataRegistry = (0, import_viem4.getContract)({
40632
41559
  address: dataRegistryAddress,
40633
41560
  abi: dataRegistryAbi,
40634
41561
  client: this.context.walletClient
@@ -40952,7 +41879,7 @@ var DataController = class {
40952
41879
  */
40953
41880
  async getValidatedSchema(schemaId) {
40954
41881
  try {
40955
- const schema = await this.getSchema(schemaId);
41882
+ const schema = await fetchSchemaFromChain(this.context, schemaId);
40956
41883
  const dataSchema = await this.fetchAndValidateSchema(
40957
41884
  schema.definitionUrl
40958
41885
  );
@@ -40977,7 +41904,7 @@ var DataController = class {
40977
41904
  };
40978
41905
 
40979
41906
  // src/controllers/schemas.ts
40980
- var import_viem4 = require("viem");
41907
+ var import_viem5 = require("viem");
40981
41908
  var SchemaController = class {
40982
41909
  constructor(context) {
40983
41910
  this.context = context;
@@ -41089,7 +42016,7 @@ var SchemaController = class {
41089
42016
  let schemaId = 0;
41090
42017
  for (const log of receipt.logs) {
41091
42018
  try {
41092
- const decoded = (0, import_viem4.decodeEventLog)({
42019
+ const decoded = (0, import_viem5.decodeEventLog)({
41093
42020
  abi: dataRefinerRegistryAbi,
41094
42021
  data: log.data,
41095
42022
  topics: log.topics
@@ -41129,36 +42056,7 @@ var SchemaController = class {
41129
42056
  */
41130
42057
  async get(schemaId) {
41131
42058
  try {
41132
- const chainId = this.context.walletClient.chain?.id;
41133
- if (!chainId) {
41134
- throw new Error("Chain ID not available");
41135
- }
41136
- const dataRefinerRegistryAddress = getContractAddress(
41137
- chainId,
41138
- "DataRefinerRegistry"
41139
- );
41140
- const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
41141
- const dataRefinerRegistry = (0, import_viem4.getContract)({
41142
- address: dataRefinerRegistryAddress,
41143
- abi: dataRefinerRegistryAbi,
41144
- client: this.context.publicClient
41145
- });
41146
- const schemaData = await dataRefinerRegistry.read.schemas([
41147
- BigInt(schemaId)
41148
- ]);
41149
- if (!schemaData) {
41150
- throw new Error(`Schema with ID ${schemaId} not found`);
41151
- }
41152
- const schemaObj = schemaData;
41153
- if (!schemaObj.name || !schemaObj.typ || !schemaObj.definitionUrl) {
41154
- throw new Error("Incomplete schema data");
41155
- }
41156
- return {
41157
- id: schemaId,
41158
- name: schemaObj.name,
41159
- type: schemaObj.typ,
41160
- definitionUrl: schemaObj.definitionUrl
41161
- };
42059
+ return await fetchSchemaFromChain(this.context, schemaId);
41162
42060
  } catch (error) {
41163
42061
  throw new Error(
41164
42062
  `Failed to get schema: ${error instanceof Error ? error.message : "Unknown error"}`
@@ -41178,22 +42076,7 @@ var SchemaController = class {
41178
42076
  */
41179
42077
  async count() {
41180
42078
  try {
41181
- const chainId = this.context.walletClient.chain?.id;
41182
- if (!chainId) {
41183
- throw new Error("Chain ID not available");
41184
- }
41185
- const dataRefinerRegistryAddress = getContractAddress(
41186
- chainId,
41187
- "DataRefinerRegistry"
41188
- );
41189
- const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
41190
- const dataRefinerRegistry = (0, import_viem4.getContract)({
41191
- address: dataRefinerRegistryAddress,
41192
- abi: dataRefinerRegistryAbi,
41193
- client: this.context.publicClient
41194
- });
41195
- const count = await dataRefinerRegistry.read.schemasCount();
41196
- return Number(count);
42079
+ return await fetchSchemaCountFromChain(this.context);
41197
42080
  } catch (error) {
41198
42081
  throw new Error(
41199
42082
  `Failed to get schemas count: ${error instanceof Error ? error.message : "Unknown error"}`
@@ -41641,14 +42524,14 @@ var ServerController = class {
41641
42524
  };
41642
42525
 
41643
42526
  // src/contracts/contractController.ts
41644
- var import_viem7 = require("viem");
42527
+ var import_viem8 = require("viem");
41645
42528
 
41646
42529
  // src/core/client.ts
41647
- var import_viem6 = require("viem");
42530
+ var import_viem7 = require("viem");
41648
42531
 
41649
42532
  // src/config/chains.ts
41650
- var import_viem5 = require("viem");
41651
- var mokshaTestnet = (0, import_viem5.defineChain)({
42533
+ var import_viem6 = require("viem");
42534
+ var mokshaTestnet = (0, import_viem6.defineChain)({
41652
42535
  id: 14800,
41653
42536
  caipNetworkId: "eip155:14800",
41654
42537
  chainNamespace: "eip155",
@@ -41676,7 +42559,7 @@ var mokshaTestnet = (0, import_viem5.defineChain)({
41676
42559
  contracts: {},
41677
42560
  abis: {}
41678
42561
  });
41679
- var vanaMainnet = (0, import_viem5.defineChain)({
42562
+ var vanaMainnet = (0, import_viem6.defineChain)({
41680
42563
  id: 1480,
41681
42564
  caipNetworkId: "eip155:1480",
41682
42565
  chainNamespace: "eip155",
@@ -41718,9 +42601,9 @@ var createClient = (chainId = mokshaTestnet.id) => {
41718
42601
  if (!chain) {
41719
42602
  throw new Error(`Chain ${chainId} not found`);
41720
42603
  }
41721
- _client = (0, import_viem6.createPublicClient)({
42604
+ _client = (0, import_viem7.createPublicClient)({
41722
42605
  chain,
41723
- transport: (0, import_viem6.http)()
42606
+ transport: (0, import_viem7.http)()
41724
42607
  });
41725
42608
  }
41726
42609
  return _client;
@@ -41737,7 +42620,7 @@ function getContractController(contract, client = createClient()) {
41737
42620
  const cacheKey = createCacheKey(contract, chainId);
41738
42621
  let controller = contractCache.get(cacheKey);
41739
42622
  if (!controller) {
41740
- controller = (0, import_viem7.getContract)({
42623
+ controller = (0, import_viem8.getContract)({
41741
42624
  address: getContractAddress(chainId, contract),
41742
42625
  abi: getAbi(contract),
41743
42626
  client
@@ -43333,7 +44216,7 @@ var StorageManager = class {
43333
44216
  };
43334
44217
 
43335
44218
  // src/core.ts
43336
- var import_viem8 = require("viem");
44219
+ var import_viem9 = require("viem");
43337
44220
 
43338
44221
  // src/chains/definitions.ts
43339
44222
  var vanaMainnet2 = {
@@ -43511,9 +44394,9 @@ var VanaCore = class {
43511
44394
  `Unsupported chain ID: ${config.chainId}`
43512
44395
  );
43513
44396
  }
43514
- walletClient = (0, import_viem8.createWalletClient)({
44397
+ walletClient = (0, import_viem9.createWalletClient)({
43515
44398
  chain,
43516
- transport: (0, import_viem8.http)(config.rpcUrl || chain.rpcUrls.default.http[0]),
44399
+ transport: (0, import_viem9.http)(config.rpcUrl || chain.rpcUrls.default.http[0]),
43517
44400
  account: config.account
43518
44401
  });
43519
44402
  } else {
@@ -43521,9 +44404,9 @@ var VanaCore = class {
43521
44404
  "Invalid configuration: must be either WalletConfig or ChainConfig"
43522
44405
  );
43523
44406
  }
43524
- const publicClient = (0, import_viem8.createPublicClient)({
44407
+ const publicClient = (0, import_viem9.createPublicClient)({
43525
44408
  chain: walletClient.chain,
43526
- transport: (0, import_viem8.http)()
44409
+ transport: (0, import_viem9.http)()
43527
44410
  });
43528
44411
  const chainConfig = getChainConfig(walletClient.chain.id);
43529
44412
  const subgraphUrl = config.subgraphUrl || chainConfig?.subgraphUrl;
@@ -43883,15 +44766,15 @@ var VanaCore = class {
43883
44766
  };
43884
44767
 
43885
44768
  // src/utils/formatters.ts
43886
- var import_viem9 = require("viem");
44769
+ var import_viem10 = require("viem");
43887
44770
  function formatNumber(value) {
43888
44771
  return Number(value);
43889
44772
  }
43890
44773
  function formatEth(wei, decimals = 4) {
43891
- return (0, import_viem9.formatEther)(BigInt(wei.toString())).slice(0, decimals + 2);
44774
+ return (0, import_viem10.formatEther)(BigInt(wei.toString())).slice(0, decimals + 2);
43892
44775
  }
43893
44776
  function formatToken(amount, decimals = 18, displayDecimals = 4) {
43894
- const value = (0, import_viem9.formatUnits)(BigInt(amount.toString()), decimals);
44777
+ const value = (0, import_viem10.formatUnits)(BigInt(amount.toString()), decimals);
43895
44778
  const parts = value.split(".");
43896
44779
  if (parts.length === 1) {
43897
44780
  return parts[0];
@@ -44323,10 +45206,17 @@ var CircuitBreaker = class {
44323
45206
  };
44324
45207
 
44325
45208
  // src/server/handler.ts
44326
- var import_viem10 = require("viem");
45209
+ var import_viem11 = require("viem");
44327
45210
  async function handleRelayerRequest(sdk, payload) {
44328
45211
  const { typedData, signature, expectedUserAddress } = payload;
44329
- const signerAddress = await (0, import_viem10.recoverTypedDataAddress)({
45212
+ console.debug({
45213
+ domain: typedData.domain,
45214
+ types: typedData.types,
45215
+ primaryType: typedData.primaryType,
45216
+ message: typedData.message,
45217
+ signature
45218
+ });
45219
+ const signerAddress = await (0, import_viem11.recoverTypedDataAddress)({
44330
45220
  domain: typedData.domain,
44331
45221
  types: typedData.types,
44332
45222
  primaryType: typedData.primaryType,
@@ -44363,7 +45253,7 @@ async function handleRelayerRequest(sdk, payload) {
44363
45253
  typedData,
44364
45254
  signature
44365
45255
  );
44366
- case "AddAndTrustServer":
45256
+ case "AddServer":
44367
45257
  return await sdk.permissions.submitSignedAddAndTrustServer(
44368
45258
  typedData,
44369
45259
  signature
@@ -44378,6 +45268,11 @@ async function handleRelayerRequest(sdk, payload) {
44378
45268
  typedData,
44379
45269
  signature
44380
45270
  );
45271
+ case "ServerFilesAndPermission":
45272
+ return await sdk.permissions.submitSignedAddServerFilesAndPermissions(
45273
+ typedData,
45274
+ signature
45275
+ );
44381
45276
  default:
44382
45277
  throw new Error(`Unsupported operation type: ${typedData.primaryType}`);
44383
45278
  }