@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.
@@ -97,6 +97,25 @@ var init_error_utils = __esm({
97
97
  }
98
98
  });
99
99
 
100
+ // src/utils/lazy-import.ts
101
+ function lazyImport(importFn) {
102
+ let cached = null;
103
+ return () => {
104
+ if (!cached) {
105
+ cached = importFn().catch((err) => {
106
+ cached = null;
107
+ throw new Error("Failed to load module", { cause: err });
108
+ });
109
+ }
110
+ return cached;
111
+ };
112
+ }
113
+ var init_lazy_import = __esm({
114
+ "src/utils/lazy-import.ts"() {
115
+ "use strict";
116
+ }
117
+ });
118
+
100
119
  // src/utils/ipfs.ts
101
120
  var ipfs_exports = {};
102
121
  __export(ipfs_exports, {
@@ -210,20 +229,21 @@ __export(browser_exports, {
210
229
  BrowserPlatformAdapter: () => BrowserPlatformAdapter,
211
230
  browserPlatformAdapter: () => browserPlatformAdapter
212
231
  });
213
- import * as openpgp2 from "openpgp";
214
- var BrowserCryptoAdapter, BrowserPGPAdapter, BrowserHttpAdapter, BrowserCacheAdapter, BrowserPlatformAdapter, browserPlatformAdapter;
232
+ var getOpenPGP2, BrowserCryptoAdapter, BrowserPGPAdapter, BrowserHttpAdapter, BrowserCacheAdapter, BrowserPlatformAdapter, browserPlatformAdapter;
215
233
  var init_browser = __esm({
216
234
  "src/platform/browser.ts"() {
217
235
  "use strict";
218
236
  init_crypto_utils();
219
237
  init_pgp_utils();
220
238
  init_error_utils();
239
+ init_lazy_import();
240
+ getOpenPGP2 = lazyImport(() => import("openpgp"));
221
241
  BrowserCryptoAdapter = class {
222
242
  async encryptWithPublicKey(data, publicKeyHex) {
223
243
  try {
224
- const eccrypto2 = await import("eccrypto-js");
244
+ const eccrypto = await import("eccrypto-js");
225
245
  const publicKeyBuffer = Buffer.from(publicKeyHex, "hex");
226
- const encrypted = await eccrypto2.encrypt(
246
+ const encrypted = await eccrypto.encrypt(
227
247
  publicKeyBuffer,
228
248
  Buffer.from(data, "utf8")
229
249
  );
@@ -240,12 +260,12 @@ var init_browser = __esm({
240
260
  }
241
261
  async decryptWithPrivateKey(encryptedData, privateKeyHex) {
242
262
  try {
243
- const eccrypto2 = await import("eccrypto-js");
263
+ const eccrypto = await import("eccrypto-js");
244
264
  const privateKeyBuffer = processWalletPrivateKey(privateKeyHex);
245
265
  const encryptedBuffer = Buffer.from(encryptedData, "hex");
246
266
  const { iv, ephemPublicKey, ciphertext, mac } = parseEncryptedDataBuffer(encryptedBuffer);
247
267
  const encryptedObj = { iv, ephemPublicKey, ciphertext, mac };
248
- const decryptedBuffer = await eccrypto2.decrypt(
268
+ const decryptedBuffer = await eccrypto.decrypt(
249
269
  privateKeyBuffer,
250
270
  encryptedObj
251
271
  );
@@ -256,11 +276,11 @@ var init_browser = __esm({
256
276
  }
257
277
  async generateKeyPair() {
258
278
  try {
259
- const eccrypto2 = await import("eccrypto-js");
279
+ const eccrypto = await import("eccrypto-js");
260
280
  const privateKeyBytes = new Uint8Array(32);
261
281
  crypto.getRandomValues(privateKeyBytes);
262
282
  const privateKey = Buffer.from(privateKeyBytes);
263
- const publicKey = eccrypto2.getPublicCompressed(privateKey);
283
+ const publicKey = eccrypto.getPublicCompressed(privateKey);
264
284
  return {
265
285
  privateKey: privateKey.toString("hex"),
266
286
  publicKey: publicKey.toString("hex")
@@ -271,9 +291,9 @@ var init_browser = __esm({
271
291
  }
272
292
  async encryptWithWalletPublicKey(data, publicKey) {
273
293
  try {
274
- const eccrypto2 = await import("eccrypto-js");
294
+ const eccrypto = await import("eccrypto-js");
275
295
  const uncompressedKey = processWalletPublicKey(publicKey);
276
- const encryptedBuffer = await eccrypto2.encrypt(
296
+ const encryptedBuffer = await eccrypto.encrypt(
277
297
  uncompressedKey,
278
298
  Buffer.from(data)
279
299
  );
@@ -290,12 +310,12 @@ var init_browser = __esm({
290
310
  }
291
311
  async decryptWithWalletPrivateKey(encryptedData, privateKey) {
292
312
  try {
293
- const eccrypto2 = await import("eccrypto-js");
313
+ const eccrypto = await import("eccrypto-js");
294
314
  const privateKeyBuffer = processWalletPrivateKey(privateKey);
295
315
  const encryptedBuffer = Buffer.from(encryptedData, "hex");
296
316
  const { iv, ephemPublicKey, ciphertext, mac } = parseEncryptedDataBuffer(encryptedBuffer);
297
317
  const encryptedObj = { iv, ephemPublicKey, ciphertext, mac };
298
- const decryptedBuffer = await eccrypto2.decrypt(
318
+ const decryptedBuffer = await eccrypto.decrypt(
299
319
  privateKeyBuffer,
300
320
  encryptedObj
301
321
  );
@@ -306,11 +326,11 @@ var init_browser = __esm({
306
326
  }
307
327
  async encryptWithPassword(data, password) {
308
328
  try {
309
- const openpgp3 = await import("openpgp");
310
- const message = await openpgp3.createMessage({
329
+ const openpgp = await getOpenPGP2();
330
+ const message = await openpgp.createMessage({
311
331
  binary: data
312
332
  });
313
- const encrypted = await openpgp3.encrypt({
333
+ const encrypted = await openpgp.encrypt({
314
334
  message,
315
335
  passwords: [password],
316
336
  format: "binary"
@@ -324,11 +344,11 @@ var init_browser = __esm({
324
344
  }
325
345
  async decryptWithPassword(encryptedData, password) {
326
346
  try {
327
- const openpgp3 = await import("openpgp");
328
- const message = await openpgp3.readMessage({
347
+ const openpgp = await getOpenPGP2();
348
+ const message = await openpgp.readMessage({
329
349
  binaryMessage: encryptedData
330
350
  });
331
- const { data: decrypted } = await openpgp3.decrypt({
351
+ const { data: decrypted } = await openpgp.decrypt({
332
352
  message,
333
353
  passwords: [password],
334
354
  format: "binary"
@@ -342,12 +362,13 @@ var init_browser = __esm({
342
362
  BrowserPGPAdapter = class {
343
363
  async encrypt(data, publicKeyArmored) {
344
364
  try {
345
- const publicKey = await openpgp2.readKey({ armoredKey: publicKeyArmored });
346
- const encrypted = await openpgp2.encrypt({
347
- message: await openpgp2.createMessage({ text: data }),
365
+ const openpgp = await getOpenPGP2();
366
+ const publicKey = await openpgp.readKey({ armoredKey: publicKeyArmored });
367
+ const encrypted = await openpgp.encrypt({
368
+ message: await openpgp.createMessage({ text: data }),
348
369
  encryptionKeys: publicKey,
349
370
  config: {
350
- preferredCompressionAlgorithm: openpgp2.enums.compression.zlib
371
+ preferredCompressionAlgorithm: openpgp.enums.compression.zlib
351
372
  }
352
373
  });
353
374
  return encrypted;
@@ -357,13 +378,14 @@ var init_browser = __esm({
357
378
  }
358
379
  async decrypt(encryptedData, privateKeyArmored) {
359
380
  try {
360
- const privateKey = await openpgp2.readPrivateKey({
381
+ const openpgp = await getOpenPGP2();
382
+ const privateKey = await openpgp.readPrivateKey({
361
383
  armoredKey: privateKeyArmored
362
384
  });
363
- const message = await openpgp2.readMessage({
385
+ const message = await openpgp.readMessage({
364
386
  armoredMessage: encryptedData
365
387
  });
366
- const { data: decrypted } = await openpgp2.decrypt({
388
+ const { data: decrypted } = await openpgp.decrypt({
367
389
  message,
368
390
  decryptionKeys: privateKey
369
391
  });
@@ -374,8 +396,9 @@ var init_browser = __esm({
374
396
  }
375
397
  async generateKeyPair(options) {
376
398
  try {
399
+ const openpgp = await getOpenPGP2();
377
400
  const keyGenParams = getPGPKeyGenParams(options);
378
- const { privateKey, publicKey } = await openpgp2.generateKey(keyGenParams);
401
+ const { privateKey, publicKey } = await openpgp.generateKey(keyGenParams);
379
402
  return { publicKey, privateKey };
380
403
  } catch (error) {
381
404
  throw wrapCryptoError("PGP key generation", error);
@@ -454,8 +477,6 @@ var init_browser = __esm({
454
477
  init_crypto_utils();
455
478
  init_pgp_utils();
456
479
  init_error_utils();
457
- import { randomBytes } from "crypto";
458
- import * as openpgp from "openpgp";
459
480
 
460
481
  // src/platform/shared/stream-utils.ts
461
482
  async function streamToUint8Array(stream) {
@@ -481,29 +502,16 @@ async function streamToUint8Array(stream) {
481
502
  }
482
503
 
483
504
  // src/platform/node.ts
484
- var eccrypto = null;
485
- async function getEccrypto() {
486
- if (!eccrypto) {
487
- try {
488
- const eccryptoLib = await import("eccrypto");
489
- eccrypto = {
490
- encrypt: eccryptoLib.encrypt,
491
- decrypt: eccryptoLib.decrypt,
492
- getPublicCompressed: eccryptoLib.getPublicCompressed
493
- };
494
- } catch (error) {
495
- throw new Error(`Failed to load eccrypto library: ${error}`);
496
- }
497
- }
498
- return eccrypto;
499
- }
505
+ init_lazy_import();
506
+ var getOpenPGP = lazyImport(() => import("openpgp"));
507
+ var getEccrypto = lazyImport(() => import("eccrypto"));
500
508
  var NodeCryptoAdapter = class {
501
509
  async encryptWithPublicKey(data, publicKeyHex) {
502
510
  try {
503
- const eccryptoLib = await getEccrypto();
511
+ const eccrypto = await getEccrypto();
504
512
  const publicKey = Buffer.from(publicKeyHex, "hex");
505
513
  const message = Buffer.from(data, "utf8");
506
- const encrypted = await eccryptoLib.encrypt(publicKey, message);
514
+ const encrypted = await eccrypto.encrypt(publicKey, message);
507
515
  const result = Buffer.concat([
508
516
  encrypted.iv,
509
517
  encrypted.ephemPublicKey,
@@ -517,15 +525,12 @@ var NodeCryptoAdapter = class {
517
525
  }
518
526
  async decryptWithPrivateKey(encryptedData, privateKeyHex) {
519
527
  try {
520
- const eccryptoLib = await getEccrypto();
528
+ const eccrypto = await getEccrypto();
521
529
  const privateKeyBuffer = processWalletPrivateKey(privateKeyHex);
522
530
  const encryptedBuffer = Buffer.from(encryptedData, "hex");
523
531
  const { iv, ephemPublicKey, ciphertext, mac } = parseEncryptedDataBuffer(encryptedBuffer);
524
532
  const encryptedObj = { iv, ephemPublicKey, ciphertext, mac };
525
- const decrypted = await eccryptoLib.decrypt(
526
- privateKeyBuffer,
527
- encryptedObj
528
- );
533
+ const decrypted = await eccrypto.decrypt(privateKeyBuffer, encryptedObj);
529
534
  return decrypted.toString("utf8");
530
535
  } catch (error) {
531
536
  throw new Error(`Decryption failed: ${error}`);
@@ -533,9 +538,9 @@ var NodeCryptoAdapter = class {
533
538
  }
534
539
  async generateKeyPair() {
535
540
  try {
536
- const eccryptoLib = await getEccrypto();
537
- const privateKey = randomBytes(32);
538
- const publicKey = eccryptoLib.getPublicCompressed(privateKey);
541
+ const eccrypto = await getEccrypto();
542
+ const privateKey = eccrypto.generatePrivate();
543
+ const publicKey = eccrypto.getPublicCompressed(privateKey);
539
544
  return {
540
545
  privateKey: privateKey.toString("hex"),
541
546
  publicKey: publicKey.toString("hex")
@@ -546,9 +551,9 @@ var NodeCryptoAdapter = class {
546
551
  }
547
552
  async encryptWithWalletPublicKey(data, publicKey) {
548
553
  try {
549
- const eccryptoLib = await getEccrypto();
554
+ const eccrypto = await getEccrypto();
550
555
  const uncompressedKey = processWalletPublicKey(publicKey);
551
- const encrypted = await eccryptoLib.encrypt(
556
+ const encrypted = await eccrypto.encrypt(
552
557
  uncompressedKey,
553
558
  Buffer.from(data)
554
559
  );
@@ -565,12 +570,12 @@ var NodeCryptoAdapter = class {
565
570
  }
566
571
  async decryptWithWalletPrivateKey(encryptedData, privateKey) {
567
572
  try {
568
- const eccryptoLib = await getEccrypto();
573
+ const eccrypto = await getEccrypto();
569
574
  const privateKeyBuffer = processWalletPrivateKey(privateKey);
570
575
  const encryptedBuffer = Buffer.from(encryptedData, "hex");
571
576
  const { iv, ephemPublicKey, ciphertext, mac } = parseEncryptedDataBuffer(encryptedBuffer);
572
577
  const encryptedObj = { iv, ephemPublicKey, ciphertext, mac };
573
- const decryptedBuffer = await eccryptoLib.decrypt(
578
+ const decryptedBuffer = await eccrypto.decrypt(
574
579
  privateKeyBuffer,
575
580
  encryptedObj
576
581
  );
@@ -581,6 +586,7 @@ var NodeCryptoAdapter = class {
581
586
  }
582
587
  async encryptWithPassword(data, password) {
583
588
  try {
589
+ const openpgp = await getOpenPGP();
584
590
  const message = await openpgp.createMessage({
585
591
  binary: data
586
592
  });
@@ -604,6 +610,7 @@ var NodeCryptoAdapter = class {
604
610
  }
605
611
  async decryptWithPassword(encryptedData, password) {
606
612
  try {
613
+ const openpgp = await getOpenPGP();
607
614
  const message = await openpgp.readMessage({
608
615
  binaryMessage: encryptedData
609
616
  });
@@ -621,6 +628,7 @@ var NodeCryptoAdapter = class {
621
628
  var NodePGPAdapter = class {
622
629
  async encrypt(data, publicKeyArmored) {
623
630
  try {
631
+ const openpgp = await getOpenPGP();
624
632
  const publicKey = await openpgp.readKey({ armoredKey: publicKeyArmored });
625
633
  const encrypted = await openpgp.encrypt({
626
634
  message: await openpgp.createMessage({ text: data }),
@@ -636,6 +644,7 @@ var NodePGPAdapter = class {
636
644
  }
637
645
  async decrypt(encryptedData, privateKeyArmored) {
638
646
  try {
647
+ const openpgp = await getOpenPGP();
639
648
  const privateKey = await openpgp.readPrivateKey({
640
649
  armoredKey: privateKeyArmored
641
650
  });
@@ -653,6 +662,7 @@ var NodePGPAdapter = class {
653
662
  }
654
663
  async generateKeyPair(options) {
655
664
  try {
665
+ const openpgp = await getOpenPGP();
656
666
  const keyGenParams = getPGPKeyGenParams(options);
657
667
  const { privateKey, publicKey } = await openpgp.generateKey(keyGenParams);
658
668
  return { publicKey, privateKey };
@@ -1136,11 +1146,11 @@ import { parseEventLogs } from "viem";
1136
1146
  var EVENT_MAPPINGS = {
1137
1147
  // Permission operations
1138
1148
  grant: {
1139
- contract: "DataPermissions",
1149
+ contract: "DataPortabilityPermissions",
1140
1150
  event: "PermissionAdded"
1141
1151
  },
1142
1152
  revoke: {
1143
- contract: "DataPermissions",
1153
+ contract: "DataPortabilityPermissions",
1144
1154
  event: "PermissionRevoked"
1145
1155
  },
1146
1156
  trustServer: {
@@ -6354,6 +6364,22 @@ var DataPortabilityPermissionsABI = [
6354
6364
  name: "InvalidNonce",
6355
6365
  type: "error"
6356
6366
  },
6367
+ {
6368
+ inputs: [
6369
+ {
6370
+ internalType: "uint256",
6371
+ name: "filesLength",
6372
+ type: "uint256"
6373
+ },
6374
+ {
6375
+ internalType: "uint256",
6376
+ name: "permissionsLength",
6377
+ type: "uint256"
6378
+ }
6379
+ ],
6380
+ name: "InvalidPermissionsLength",
6381
+ type: "error"
6382
+ },
6357
6383
  {
6358
6384
  inputs: [],
6359
6385
  name: "InvalidSignature",
@@ -6685,6 +6711,84 @@ var DataPortabilityPermissionsABI = [
6685
6711
  stateMutability: "nonpayable",
6686
6712
  type: "function"
6687
6713
  },
6714
+ {
6715
+ inputs: [
6716
+ {
6717
+ components: [
6718
+ {
6719
+ internalType: "uint256",
6720
+ name: "nonce",
6721
+ type: "uint256"
6722
+ },
6723
+ {
6724
+ internalType: "uint256",
6725
+ name: "granteeId",
6726
+ type: "uint256"
6727
+ },
6728
+ {
6729
+ internalType: "string",
6730
+ name: "grant",
6731
+ type: "string"
6732
+ },
6733
+ {
6734
+ internalType: "string[]",
6735
+ name: "fileUrls",
6736
+ type: "string[]"
6737
+ },
6738
+ {
6739
+ internalType: "address",
6740
+ name: "serverAddress",
6741
+ type: "address"
6742
+ },
6743
+ {
6744
+ internalType: "string",
6745
+ name: "serverUrl",
6746
+ type: "string"
6747
+ },
6748
+ {
6749
+ internalType: "string",
6750
+ name: "serverPublicKey",
6751
+ type: "string"
6752
+ },
6753
+ {
6754
+ components: [
6755
+ {
6756
+ internalType: "address",
6757
+ name: "account",
6758
+ type: "address"
6759
+ },
6760
+ {
6761
+ internalType: "string",
6762
+ name: "key",
6763
+ type: "string"
6764
+ }
6765
+ ],
6766
+ internalType: "struct IDataRegistry.Permission[][]",
6767
+ name: "filePermissions",
6768
+ type: "tuple[][]"
6769
+ }
6770
+ ],
6771
+ internalType: "struct IDataPortabilityPermissions.ServerFilesAndPermissionInput",
6772
+ name: "serverFilesAndPermissionInput",
6773
+ type: "tuple"
6774
+ },
6775
+ {
6776
+ internalType: "bytes",
6777
+ name: "signature",
6778
+ type: "bytes"
6779
+ }
6780
+ ],
6781
+ name: "addServerFilesAndPermissions",
6782
+ outputs: [
6783
+ {
6784
+ internalType: "uint256",
6785
+ name: "",
6786
+ type: "uint256"
6787
+ }
6788
+ ],
6789
+ stateMutability: "nonpayable",
6790
+ type: "function"
6791
+ },
6688
6792
  {
6689
6793
  inputs: [],
6690
6794
  name: "dataPortabilityGrantees",
@@ -6899,25 +7003,6 @@ var DataPortabilityPermissionsABI = [
6899
7003
  stateMutability: "nonpayable",
6900
7004
  type: "function"
6901
7005
  },
6902
- {
6903
- inputs: [
6904
- {
6905
- internalType: "uint256",
6906
- name: "permissionId",
6907
- type: "uint256"
6908
- }
6909
- ],
6910
- name: "isActivePermission",
6911
- outputs: [
6912
- {
6913
- internalType: "bool",
6914
- name: "",
6915
- type: "bool"
6916
- }
6917
- ],
6918
- stateMutability: "view",
6919
- type: "function"
6920
- },
6921
7006
  {
6922
7007
  inputs: [
6923
7008
  {
@@ -7032,11 +7117,6 @@ var DataPortabilityPermissionsABI = [
7032
7117
  name: "grant",
7033
7118
  type: "string"
7034
7119
  },
7035
- {
7036
- internalType: "bytes",
7037
- name: "signature",
7038
- type: "bytes"
7039
- },
7040
7120
  {
7041
7121
  internalType: "uint256",
7042
7122
  name: "startBlock",
@@ -7754,9 +7834,9 @@ var DataPortabilityServersABI = [
7754
7834
  },
7755
7835
  {
7756
7836
  indexed: false,
7757
- internalType: "bytes",
7837
+ internalType: "string",
7758
7838
  name: "publicKey",
7759
- type: "bytes"
7839
+ type: "string"
7760
7840
  },
7761
7841
  {
7762
7842
  indexed: false,
@@ -7877,6 +7957,19 @@ var DataPortabilityServersABI = [
7877
7957
  stateMutability: "view",
7878
7958
  type: "function"
7879
7959
  },
7960
+ {
7961
+ inputs: [],
7962
+ name: "PERMISSION_MANAGER_ROLE",
7963
+ outputs: [
7964
+ {
7965
+ internalType: "bytes32",
7966
+ name: "",
7967
+ type: "bytes32"
7968
+ }
7969
+ ],
7970
+ stateMutability: "view",
7971
+ type: "function"
7972
+ },
7880
7973
  {
7881
7974
  inputs: [],
7882
7975
  name: "UPGRADE_INTERFACE_VERSION",
@@ -7892,22 +7985,22 @@ var DataPortabilityServersABI = [
7892
7985
  },
7893
7986
  {
7894
7987
  inputs: [
7988
+ {
7989
+ internalType: "address",
7990
+ name: "ownerAddress",
7991
+ type: "address"
7992
+ },
7895
7993
  {
7896
7994
  components: [
7897
- {
7898
- internalType: "address",
7899
- name: "owner",
7900
- type: "address"
7901
- },
7902
7995
  {
7903
7996
  internalType: "address",
7904
7997
  name: "serverAddress",
7905
7998
  type: "address"
7906
7999
  },
7907
8000
  {
7908
- internalType: "bytes",
8001
+ internalType: "string",
7909
8002
  name: "publicKey",
7910
- type: "bytes"
8003
+ type: "string"
7911
8004
  },
7912
8005
  {
7913
8006
  internalType: "string",
@@ -7916,11 +8009,11 @@ var DataPortabilityServersABI = [
7916
8009
  }
7917
8010
  ],
7918
8011
  internalType: "struct IDataPortabilityServers.AddServerInput",
7919
- name: "addAndTrustServerInput",
8012
+ name: "addServerInput",
7920
8013
  type: "tuple"
7921
8014
  }
7922
8015
  ],
7923
- name: "addAndTrustServer",
8016
+ name: "addAndTrustServerOnBehalf",
7924
8017
  outputs: [],
7925
8018
  stateMutability: "nonpayable",
7926
8019
  type: "function"
@@ -7934,20 +8027,15 @@ var DataPortabilityServersABI = [
7934
8027
  name: "nonce",
7935
8028
  type: "uint256"
7936
8029
  },
7937
- {
7938
- internalType: "address",
7939
- name: "owner",
7940
- type: "address"
7941
- },
7942
8030
  {
7943
8031
  internalType: "address",
7944
8032
  name: "serverAddress",
7945
8033
  type: "address"
7946
8034
  },
7947
8035
  {
7948
- internalType: "bytes",
8036
+ internalType: "string",
7949
8037
  name: "publicKey",
7950
- type: "bytes"
8038
+ type: "string"
7951
8039
  },
7952
8040
  {
7953
8041
  internalType: "string",
@@ -7955,8 +8043,8 @@ var DataPortabilityServersABI = [
7955
8043
  type: "string"
7956
8044
  }
7957
8045
  ],
7958
- internalType: "struct IDataPortabilityServers.AddAndTrustServerInput",
7959
- name: "addAndTrustServerInput",
8046
+ internalType: "struct IDataPortabilityServers.AddServerWithSignatureInput",
8047
+ name: "addServerInput",
7960
8048
  type: "tuple"
7961
8049
  },
7962
8050
  {
@@ -7975,9 +8063,9 @@ var DataPortabilityServersABI = [
7975
8063
  {
7976
8064
  components: [
7977
8065
  {
7978
- internalType: "address",
7979
- name: "owner",
7980
- type: "address"
8066
+ internalType: "uint256",
8067
+ name: "nonce",
8068
+ type: "uint256"
7981
8069
  },
7982
8070
  {
7983
8071
  internalType: "address",
@@ -7985,9 +8073,9 @@ var DataPortabilityServersABI = [
7985
8073
  type: "address"
7986
8074
  },
7987
8075
  {
7988
- internalType: "bytes",
8076
+ internalType: "string",
7989
8077
  name: "publicKey",
7990
- type: "bytes"
8078
+ type: "string"
7991
8079
  },
7992
8080
  {
7993
8081
  internalType: "string",
@@ -7995,12 +8083,17 @@ var DataPortabilityServersABI = [
7995
8083
  type: "string"
7996
8084
  }
7997
8085
  ],
7998
- internalType: "struct IDataPortabilityServers.AddServerInput",
8086
+ internalType: "struct IDataPortabilityServers.AddServerWithSignatureInput",
7999
8087
  name: "addServerInput",
8000
8088
  type: "tuple"
8089
+ },
8090
+ {
8091
+ internalType: "bytes",
8092
+ name: "signature",
8093
+ type: "bytes"
8001
8094
  }
8002
8095
  ],
8003
- name: "addServer",
8096
+ name: "addServerWithSignature",
8004
8097
  outputs: [],
8005
8098
  stateMutability: "nonpayable",
8006
8099
  type: "function"
@@ -8127,49 +8220,6 @@ var DataPortabilityServersABI = [
8127
8220
  stateMutability: "nonpayable",
8128
8221
  type: "function"
8129
8222
  },
8130
- {
8131
- inputs: [
8132
- {
8133
- internalType: "uint256",
8134
- name: "serverId",
8135
- type: "uint256"
8136
- }
8137
- ],
8138
- name: "isActiveServer",
8139
- outputs: [
8140
- {
8141
- internalType: "bool",
8142
- name: "",
8143
- type: "bool"
8144
- }
8145
- ],
8146
- stateMutability: "view",
8147
- type: "function"
8148
- },
8149
- {
8150
- inputs: [
8151
- {
8152
- internalType: "address",
8153
- name: "userAddress",
8154
- type: "address"
8155
- },
8156
- {
8157
- internalType: "uint256",
8158
- name: "serverId",
8159
- type: "uint256"
8160
- }
8161
- ],
8162
- name: "isActiveServerForUser",
8163
- outputs: [
8164
- {
8165
- internalType: "bool",
8166
- name: "",
8167
- type: "bool"
8168
- }
8169
- ],
8170
- stateMutability: "view",
8171
- type: "function"
8172
- },
8173
8223
  {
8174
8224
  inputs: [
8175
8225
  {
@@ -8324,9 +8374,9 @@ var DataPortabilityServersABI = [
8324
8374
  type: "address"
8325
8375
  },
8326
8376
  {
8327
- internalType: "bytes",
8377
+ internalType: "string",
8328
8378
  name: "publicKey",
8329
- type: "bytes"
8379
+ type: "string"
8330
8380
  },
8331
8381
  {
8332
8382
  internalType: "string",
@@ -8370,9 +8420,9 @@ var DataPortabilityServersABI = [
8370
8420
  type: "address"
8371
8421
  },
8372
8422
  {
8373
- internalType: "bytes",
8423
+ internalType: "string",
8374
8424
  name: "publicKey",
8375
- type: "bytes"
8425
+ type: "string"
8376
8426
  },
8377
8427
  {
8378
8428
  internalType: "string",
@@ -8692,6 +8742,123 @@ var DataPortabilityServersABI = [
8692
8742
  stateMutability: "view",
8693
8743
  type: "function"
8694
8744
  },
8745
+ {
8746
+ inputs: [
8747
+ {
8748
+ internalType: "address",
8749
+ name: "userAddress",
8750
+ type: "address"
8751
+ }
8752
+ ],
8753
+ name: "userServerValues",
8754
+ outputs: [
8755
+ {
8756
+ components: [
8757
+ {
8758
+ internalType: "uint256",
8759
+ name: "id",
8760
+ type: "uint256"
8761
+ },
8762
+ {
8763
+ internalType: "address",
8764
+ name: "owner",
8765
+ type: "address"
8766
+ },
8767
+ {
8768
+ internalType: "address",
8769
+ name: "serverAddress",
8770
+ type: "address"
8771
+ },
8772
+ {
8773
+ internalType: "string",
8774
+ name: "publicKey",
8775
+ type: "string"
8776
+ },
8777
+ {
8778
+ internalType: "string",
8779
+ name: "url",
8780
+ type: "string"
8781
+ },
8782
+ {
8783
+ internalType: "uint256",
8784
+ name: "startBlock",
8785
+ type: "uint256"
8786
+ },
8787
+ {
8788
+ internalType: "uint256",
8789
+ name: "endBlock",
8790
+ type: "uint256"
8791
+ }
8792
+ ],
8793
+ internalType: "struct IDataPortabilityServers.TrustedServerInfo[]",
8794
+ name: "serversInfo",
8795
+ type: "tuple[]"
8796
+ }
8797
+ ],
8798
+ stateMutability: "view",
8799
+ type: "function"
8800
+ },
8801
+ {
8802
+ inputs: [
8803
+ {
8804
+ internalType: "address",
8805
+ name: "userAddress",
8806
+ type: "address"
8807
+ },
8808
+ {
8809
+ internalType: "uint256",
8810
+ name: "serverId",
8811
+ type: "uint256"
8812
+ }
8813
+ ],
8814
+ name: "userServers",
8815
+ outputs: [
8816
+ {
8817
+ components: [
8818
+ {
8819
+ internalType: "uint256",
8820
+ name: "id",
8821
+ type: "uint256"
8822
+ },
8823
+ {
8824
+ internalType: "address",
8825
+ name: "owner",
8826
+ type: "address"
8827
+ },
8828
+ {
8829
+ internalType: "address",
8830
+ name: "serverAddress",
8831
+ type: "address"
8832
+ },
8833
+ {
8834
+ internalType: "string",
8835
+ name: "publicKey",
8836
+ type: "string"
8837
+ },
8838
+ {
8839
+ internalType: "string",
8840
+ name: "url",
8841
+ type: "string"
8842
+ },
8843
+ {
8844
+ internalType: "uint256",
8845
+ name: "startBlock",
8846
+ type: "uint256"
8847
+ },
8848
+ {
8849
+ internalType: "uint256",
8850
+ name: "endBlock",
8851
+ type: "uint256"
8852
+ }
8853
+ ],
8854
+ internalType: "struct IDataPortabilityServers.TrustedServerInfo",
8855
+ name: "",
8856
+ type: "tuple"
8857
+ }
8858
+ ],
8859
+ stateMutability: "view",
8860
+ type: "function"
8861
+ },
8695
8862
  {
8696
8863
  inputs: [
8697
8864
  {
@@ -35253,7 +35420,6 @@ var DATVotesABI = [
35253
35420
 
35254
35421
  // src/abi/index.ts
35255
35422
  var contractAbis = {
35256
- DataPermissions: DataPortabilityPermissionsABI,
35257
35423
  DataPortabilityPermissions: DataPortabilityPermissionsABI,
35258
35424
  DataPortabilityServers: DataPortabilityServersABI,
35259
35425
  DataPortabilityGrantees: DataPortabilityGranteesABI,
@@ -35361,13 +35527,6 @@ async function parseTransactionResult(context, hash, operation) {
35361
35527
  // src/config/addresses.ts
35362
35528
  var CONTRACTS = {
35363
35529
  // Data Portability Contracts (New Architecture)
35364
- DataPermissions: {
35365
- addresses: {
35366
- 14800: "0xD54523048AdD05b4d734aFaE7C68324Ebb7373eF",
35367
- // Points to DataPortabilityPermissions for backwards compatibility
35368
- 1480: "0xD54523048AdD05b4d734aFaE7C68324Ebb7373eF"
35369
- }
35370
- },
35371
35530
  DataPortabilityPermissions: {
35372
35531
  addresses: {
35373
35532
  14800: "0xD54523048AdD05b4d734aFaE7C68324Ebb7373eF",
@@ -36202,6 +36361,42 @@ async function withSignatureCache(cache, walletAddress, typedData, signFn, ttlHo
36202
36361
  return signature;
36203
36362
  }
36204
36363
 
36364
+ // src/utils/signatureFormatter.ts
36365
+ var V_OFFSET_FOR_ETHEREUM = 27;
36366
+ function formatSignatureForContract(signature) {
36367
+ const cleanSig = signature.startsWith("0x") ? signature.slice(2) : signature;
36368
+ if (cleanSig.length !== 130) {
36369
+ return signature;
36370
+ }
36371
+ const vHex = cleanSig.slice(128, 130);
36372
+ const v = parseInt(vHex, 16);
36373
+ if (isNaN(v)) {
36374
+ return signature;
36375
+ }
36376
+ if (v < 27) {
36377
+ const adjustedV = (v + V_OFFSET_FOR_ETHEREUM).toString(16).padStart(2, "0");
36378
+ return `0x${cleanSig.slice(0, 128)}${adjustedV}`;
36379
+ }
36380
+ return signature;
36381
+ }
36382
+
36383
+ // src/utils/typedDataConverter.ts
36384
+ function toViemTypedDataDefinition(typedData) {
36385
+ const viemTypes = {};
36386
+ for (const [typeName, typeArray] of Object.entries(typedData.types)) {
36387
+ viemTypes[typeName] = typeArray.map((field) => ({
36388
+ name: field.name,
36389
+ type: field.type
36390
+ }));
36391
+ }
36392
+ return {
36393
+ domain: typedData.domain,
36394
+ types: viemTypes,
36395
+ primaryType: typedData.primaryType,
36396
+ message: typedData.message
36397
+ };
36398
+ }
36399
+
36205
36400
  // src/controllers/permissions.ts
36206
36401
  var PermissionsController = class {
36207
36402
  constructor(context) {
@@ -36361,7 +36556,7 @@ var PermissionsController = class {
36361
36556
  throw new Error("Failed to store grant file - no URL returned");
36362
36557
  }
36363
36558
  }
36364
- const nonce = await this.getUserNonce();
36559
+ const nonce = await this.getPermissionsUserNonce();
36365
36560
  console.debug(
36366
36561
  "\u{1F50D} Debug - Final grant URL being passed to compose:",
36367
36562
  grantUrl
@@ -36454,7 +36649,7 @@ var PermissionsController = class {
36454
36649
  throw new Error("Failed to store grant file - no URL returned");
36455
36650
  }
36456
36651
  }
36457
- const nonce = await this.getUserNonce();
36652
+ const nonce = await this.getPermissionsUserNonce();
36458
36653
  console.debug(
36459
36654
  "\u{1F50D} Debug - Final grant URL being passed to compose:",
36460
36655
  grantUrl
@@ -36519,14 +36714,8 @@ var PermissionsController = class {
36519
36714
  )
36520
36715
  );
36521
36716
  if (this.context.relayerCallbacks?.submitPermissionGrant) {
36522
- const jsonSafeTypedData = JSON.parse(
36523
- JSON.stringify(
36524
- typedData,
36525
- (_key, value) => typeof value === "bigint" ? value.toString() : value
36526
- )
36527
- );
36528
36717
  return await this.context.relayerCallbacks.submitPermissionGrant(
36529
- jsonSafeTypedData,
36718
+ typedData,
36530
36719
  signature
36531
36720
  );
36532
36721
  } else {
@@ -36596,7 +36785,6 @@ var PermissionsController = class {
36596
36785
  try {
36597
36786
  const addAndTrustServerInput = {
36598
36787
  nonce: BigInt(typedData.message.nonce),
36599
- owner: typedData.message.owner,
36600
36788
  serverAddress: typedData.message.serverAddress,
36601
36789
  serverUrl: typedData.message.serverUrl,
36602
36790
  publicKey: typedData.message.publicKey
@@ -36610,7 +36798,7 @@ var PermissionsController = class {
36610
36798
  throw error;
36611
36799
  }
36612
36800
  throw new BlockchainError(
36613
- `Add and trust server submission failed: ${error instanceof Error ? error.message : "Unknown error"}`,
36801
+ `Add and trust server submission failed444444: ${error instanceof Error ? error.message : "Unknown error"}`,
36614
36802
  error
36615
36803
  );
36616
36804
  }
@@ -36626,14 +36814,8 @@ var PermissionsController = class {
36626
36814
  async submitSignedRevoke(typedData, signature) {
36627
36815
  try {
36628
36816
  if (this.context.relayerCallbacks?.submitPermissionRevoke) {
36629
- const jsonSafeTypedData = JSON.parse(
36630
- JSON.stringify(
36631
- typedData,
36632
- (_key, value) => typeof value === "bigint" ? value.toString() : value
36633
- )
36634
- );
36635
36817
  return await this.context.relayerCallbacks.submitPermissionRevoke(
36636
- jsonSafeTypedData,
36818
+ typedData,
36637
36819
  signature
36638
36820
  );
36639
36821
  } else {
@@ -36686,11 +36868,11 @@ var PermissionsController = class {
36686
36868
  */
36687
36869
  async submitDirectTransaction(typedData, signature) {
36688
36870
  const chainId = await this.context.walletClient.getChainId();
36689
- const DataPermissionsAddress = getContractAddress(
36871
+ const DataPortabilityPermissionsAddress = getContractAddress(
36690
36872
  chainId,
36691
- "DataPermissions"
36873
+ "DataPortabilityPermissions"
36692
36874
  );
36693
- const DataPermissionsAbi = getAbi("DataPermissions");
36875
+ const DataPortabilityPermissionsAbi = getAbi("DataPortabilityPermissions");
36694
36876
  const permissionInput = {
36695
36877
  nonce: typedData.message.nonce,
36696
36878
  granteeId: typedData.message.granteeId,
@@ -36707,11 +36889,12 @@ var PermissionsController = class {
36707
36889
  "\u{1F50D} Debug - Grant field length:",
36708
36890
  typedData.message.grant?.length || 0
36709
36891
  );
36892
+ const formattedSignature = formatSignatureForContract(signature);
36710
36893
  const txHash = await this.context.walletClient.writeContract({
36711
- address: DataPermissionsAddress,
36712
- abi: DataPermissionsAbi,
36894
+ address: DataPortabilityPermissionsAddress,
36895
+ abi: DataPortabilityPermissionsAbi,
36713
36896
  functionName: "addPermission",
36714
- args: [permissionInput, signature],
36897
+ args: [permissionInput, formattedSignature],
36715
36898
  account: this.context.walletClient.account || await this.getUserAddress(),
36716
36899
  chain: this.context.walletClient.chain || null
36717
36900
  });
@@ -36770,14 +36953,16 @@ var PermissionsController = class {
36770
36953
  throw new BlockchainError("Chain ID not available");
36771
36954
  }
36772
36955
  const chainId = await this.context.walletClient.getChainId();
36773
- const DataPermissionsAddress = getContractAddress(
36956
+ const DataPortabilityPermissionsAddress = getContractAddress(
36774
36957
  chainId,
36775
- "DataPermissions"
36958
+ "DataPortabilityPermissions"
36959
+ );
36960
+ const DataPortabilityPermissionsAbi = getAbi(
36961
+ "DataPortabilityPermissions"
36776
36962
  );
36777
- const DataPermissionsAbi = getAbi("DataPermissions");
36778
36963
  const txHash = await this.context.walletClient.writeContract({
36779
- address: DataPermissionsAddress,
36780
- abi: DataPermissionsAbi,
36964
+ address: DataPortabilityPermissionsAddress,
36965
+ abi: DataPortabilityPermissionsAbi,
36781
36966
  functionName: "revokePermission",
36782
36967
  args: [params.permissionId],
36783
36968
  account: this.context.walletClient.account || await this.getUserAddress(),
@@ -36808,12 +36993,12 @@ var PermissionsController = class {
36808
36993
  * @throws {RelayerError} When gasless submission fails
36809
36994
  * @throws {PermissionError} When revocation fails for any other reason
36810
36995
  */
36811
- async revokeWithSignature(params) {
36996
+ async submitRevokeWithSignature(params) {
36812
36997
  try {
36813
36998
  if (!this.context.walletClient.chain?.id) {
36814
36999
  throw new BlockchainError("Chain ID not available");
36815
37000
  }
36816
- const nonce = await this.getUserNonce();
37001
+ const nonce = await this.getPermissionsUserNonce();
36817
37002
  const revokePermissionInput = {
36818
37003
  nonce,
36819
37004
  permissionId: params.permissionId
@@ -36846,7 +37031,10 @@ var PermissionsController = class {
36846
37031
  }
36847
37032
  }
36848
37033
  /**
37034
+ * @deprecated Use getPermissionsUserNonce() for permission operations or getServersUserNonce() for server operations
37035
+ *
36849
37036
  * Retrieves the user's current nonce from the DataPortabilityServers contract.
37037
+ * This method is deprecated in favor of more specific nonce methods.
36850
37038
  *
36851
37039
  * The nonce is used to prevent replay attacks in signed transactions and must
36852
37040
  * be incremented with each transaction to maintain security.
@@ -36858,22 +37046,26 @@ var PermissionsController = class {
36858
37046
  * @private
36859
37047
  * @example
36860
37048
  * ```typescript
37049
+ * // Deprecated - use specific methods instead
36861
37050
  * const nonce = await this.getUserNonce();
36862
- * console.log(`Current nonce: ${nonce}`);
37051
+ *
37052
+ * // Use these instead:
37053
+ * const permissionsNonce = await this.getPermissionsUserNonce();
37054
+ * const serversNonce = await this.getServersUserNonce();
36863
37055
  * ```
36864
37056
  */
36865
37057
  async getUserNonce() {
36866
37058
  try {
36867
37059
  const userAddress = await this.getUserAddress();
36868
37060
  const chainId = await this.context.walletClient.getChainId();
36869
- const DataPermissionsAddress = getContractAddress(
37061
+ const DataPortabilityServersAddress = getContractAddress(
36870
37062
  chainId,
36871
- "DataPermissions"
37063
+ "DataPortabilityServers"
36872
37064
  );
36873
- const DataPermissionsAbi = getAbi("DataPermissions");
37065
+ const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
36874
37066
  const nonce = await this.context.publicClient.readContract({
36875
- address: DataPermissionsAddress,
36876
- abi: DataPermissionsAbi,
37067
+ address: DataPortabilityServersAddress,
37068
+ abi: DataPortabilityServersAbi,
36877
37069
  functionName: "userNonce",
36878
37070
  args: [userAddress]
36879
37071
  });
@@ -36884,6 +37076,80 @@ var PermissionsController = class {
36884
37076
  );
36885
37077
  }
36886
37078
  }
37079
+ /**
37080
+ * Retrieves the user's current nonce from the DataPortabilityServers contract.
37081
+ * This nonce is used for server-related operations (AddAndTrustServer, TrustServer, UntrustServer).
37082
+ *
37083
+ * @returns Promise resolving to the current servers nonce
37084
+ * @throws {NonceError} When reading nonce from contract fails
37085
+ * @private
37086
+ *
37087
+ * @example
37088
+ * ```typescript
37089
+ * const nonce = await this.getServersUserNonce();
37090
+ * console.log(`Current servers nonce: ${nonce}`);
37091
+ * ```
37092
+ */
37093
+ async getServersUserNonce() {
37094
+ try {
37095
+ const userAddress = await this.getUserAddress();
37096
+ const chainId = await this.context.walletClient.getChainId();
37097
+ const DataPortabilityServersAddress = getContractAddress(
37098
+ chainId,
37099
+ "DataPortabilityServers"
37100
+ );
37101
+ const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
37102
+ const [nonce] = await this.context.publicClient.readContract({
37103
+ address: DataPortabilityServersAddress,
37104
+ abi: DataPortabilityServersAbi,
37105
+ functionName: "users",
37106
+ args: [userAddress]
37107
+ });
37108
+ return nonce;
37109
+ } catch (error) {
37110
+ throw new NonceError(
37111
+ `Failed to retrieve server nonce: ${error instanceof Error ? error.message : "Unknown error"}`
37112
+ );
37113
+ }
37114
+ }
37115
+ /**
37116
+ * Retrieves the user's current nonce from the DataPortabilityPermissions contract.
37117
+ * This nonce is used for permission-related operations (addPermission, addServerFilesAndPermissions).
37118
+ *
37119
+ * @returns Promise resolving to the current permissions nonce
37120
+ * @throws {NonceError} When reading nonce from contract fails
37121
+ * @private
37122
+ *
37123
+ * @example
37124
+ * ```typescript
37125
+ * const nonce = await this.getPermissionsUserNonce();
37126
+ * console.log(`Current permissions nonce: ${nonce}`);
37127
+ * ```
37128
+ */
37129
+ async getPermissionsUserNonce() {
37130
+ try {
37131
+ const userAddress = await this.getUserAddress();
37132
+ const chainId = await this.context.walletClient.getChainId();
37133
+ const DataPortabilityPermissionsAddress = getContractAddress(
37134
+ chainId,
37135
+ "DataPortabilityPermissions"
37136
+ );
37137
+ const DataPortabilityPermissionsAbi = getAbi(
37138
+ "DataPortabilityPermissions"
37139
+ );
37140
+ const nonce = await this.context.publicClient.readContract({
37141
+ address: DataPortabilityPermissionsAddress,
37142
+ abi: DataPortabilityPermissionsAbi,
37143
+ functionName: "userNonce",
37144
+ args: [userAddress]
37145
+ });
37146
+ return nonce;
37147
+ } catch (error) {
37148
+ throw new NonceError(
37149
+ `Failed to retrieve permissions nonce: ${error instanceof Error ? error.message : "Unknown error"}`
37150
+ );
37151
+ }
37152
+ }
36887
37153
  /**
36888
37154
  * Composes the EIP-712 typed data for PermissionGrant (new simplified format).
36889
37155
  *
@@ -36942,6 +37208,66 @@ var PermissionsController = class {
36942
37208
  }
36943
37209
  };
36944
37210
  }
37211
+ /**
37212
+ * Creates EIP-712 typed data structure for server files and permissions.
37213
+ *
37214
+ * @param params - Parameters for the server files and permissions message
37215
+ * @param params.granteeId - Grantee ID
37216
+ * @param params.grant - Grant URL or grant data
37217
+ * @param params.fileUrls - Array of file URLs
37218
+ * @param params.serverAddress - Server address
37219
+ * @param params.serverUrl - Server URL
37220
+ * @param params.serverPublicKey - Server public key
37221
+ * @param params.filePermissions - File permissions array
37222
+ * @param params.nonce - Unique number to prevent replay attacks
37223
+ * @returns Promise resolving to the typed data structure
37224
+ */
37225
+ async composeServerFilesAndPermissionMessage(params) {
37226
+ const domain = await this.getPermissionDomain();
37227
+ console.debug(
37228
+ "\u{1F50D} Debug - Composing server files and permission message with grant:",
37229
+ params.grant
37230
+ );
37231
+ if (!params.grant.startsWith("ipfs://") && params.grant.includes("/ipfs/")) {
37232
+ const { extractIpfsHash: extractIpfsHash2 } = await Promise.resolve().then(() => (init_ipfs(), ipfs_exports));
37233
+ const hash = extractIpfsHash2(params.grant);
37234
+ if (hash) {
37235
+ console.warn(
37236
+ `\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.`
37237
+ );
37238
+ }
37239
+ }
37240
+ return {
37241
+ domain,
37242
+ types: {
37243
+ Permission: [
37244
+ { name: "account", type: "address" },
37245
+ { name: "key", type: "string" }
37246
+ ],
37247
+ ServerFilesAndPermission: [
37248
+ { name: "nonce", type: "uint256" },
37249
+ { name: "granteeId", type: "uint256" },
37250
+ { name: "grant", type: "string" },
37251
+ { name: "fileUrls", type: "string[]" },
37252
+ { name: "serverAddress", type: "address" },
37253
+ { name: "serverUrl", type: "string" },
37254
+ { name: "serverPublicKey", type: "string" },
37255
+ { name: "filePermissions", type: "Permission[][]" }
37256
+ ]
37257
+ },
37258
+ primaryType: "ServerFilesAndPermission",
37259
+ message: {
37260
+ nonce: params.nonce,
37261
+ granteeId: params.granteeId,
37262
+ grant: params.grant,
37263
+ fileUrls: params.fileUrls,
37264
+ serverAddress: params.serverAddress,
37265
+ serverUrl: params.serverUrl,
37266
+ serverPublicKey: params.serverPublicKey,
37267
+ filePermissions: params.filePermissions
37268
+ }
37269
+ };
37270
+ }
36945
37271
  /**
36946
37272
  * Gets the EIP-712 domain for PermissionGrant signatures.
36947
37273
  *
@@ -36949,15 +37275,15 @@ var PermissionsController = class {
36949
37275
  */
36950
37276
  async getPermissionDomain() {
36951
37277
  const chainId = await this.context.walletClient.getChainId();
36952
- const DataPermissionsAddress = getContractAddress(
37278
+ const DataPortabilityPermissionsAddress = getContractAddress(
36953
37279
  chainId,
36954
- "DataPermissions"
37280
+ "DataPortabilityPermissions"
36955
37281
  );
36956
37282
  return {
36957
37283
  name: "VanaDataPortabilityPermissions",
36958
37284
  version: "1",
36959
37285
  chainId,
36960
- verifyingContract: DataPermissionsAddress
37286
+ verifyingContract: DataPortabilityPermissionsAddress
36961
37287
  };
36962
37288
  }
36963
37289
  /**
@@ -36974,9 +37300,13 @@ var PermissionsController = class {
36974
37300
  walletAddress,
36975
37301
  typedData,
36976
37302
  async () => {
36977
- return await this.context.walletClient.signTypedData(
36978
- typedData
36979
- );
37303
+ const viemCompatibleTypedData = toViemTypedDataDefinition(typedData);
37304
+ return await this.context.walletClient.signTypedData({
37305
+ ...viemCompatibleTypedData,
37306
+ // Non-null assertion is safe here because getUserAddress() above ensures account exists
37307
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
37308
+ account: this.context.walletClient.account
37309
+ });
36980
37310
  }
36981
37311
  );
36982
37312
  } catch (error) {
@@ -37123,122 +37453,6 @@ var PermissionsController = class {
37123
37453
  );
37124
37454
  }
37125
37455
  }
37126
- /**
37127
- * Gets all permission IDs for a specific file.
37128
- *
37129
- * @param fileId - The file ID to query permissions for
37130
- * @returns Promise resolving to array of permission IDs
37131
- * @throws {BlockchainError} When reading from contract fails or chain is unavailable
37132
- */
37133
- async getFilePermissionIds(fileId) {
37134
- try {
37135
- const chainId = await this.context.walletClient.getChainId();
37136
- const DataPermissionsAddress = getContractAddress(
37137
- chainId,
37138
- "DataPermissions"
37139
- );
37140
- const DataPermissionsAbi = getAbi("DataPermissions");
37141
- const permissionIds = await this.context.publicClient.readContract({
37142
- address: DataPermissionsAddress,
37143
- abi: DataPermissionsAbi,
37144
- functionName: "filePermissionIds",
37145
- args: [fileId]
37146
- });
37147
- return permissionIds;
37148
- } catch (error) {
37149
- throw new BlockchainError(
37150
- `Failed to get file permission IDs: ${error instanceof Error ? error.message : "Unknown error"}`,
37151
- error
37152
- );
37153
- }
37154
- }
37155
- /**
37156
- * Gets all file IDs associated with a permission.
37157
- *
37158
- * @param permissionId - The permission ID to query files for
37159
- * @returns Promise resolving to array of file IDs
37160
- * @throws {BlockchainError} When reading from contract fails or chain is unavailable
37161
- */
37162
- async getPermissionFileIds(permissionId) {
37163
- try {
37164
- const chainId = await this.context.walletClient.getChainId();
37165
- const DataPermissionsAddress = getContractAddress(
37166
- chainId,
37167
- "DataPermissions"
37168
- );
37169
- const DataPermissionsAbi = getAbi("DataPermissions");
37170
- const fileIds = await this.context.publicClient.readContract({
37171
- address: DataPermissionsAddress,
37172
- abi: DataPermissionsAbi,
37173
- functionName: "permissionFileIds",
37174
- args: [permissionId]
37175
- });
37176
- return fileIds;
37177
- } catch (error) {
37178
- throw new BlockchainError(
37179
- `Failed to get permission file IDs: ${error instanceof Error ? error.message : "Unknown error"}`,
37180
- error
37181
- );
37182
- }
37183
- }
37184
- /**
37185
- * Checks if a permission is active.
37186
- *
37187
- * @param permissionId - The permission ID to check
37188
- * @returns Promise resolving to boolean indicating if permission is active
37189
- * @throws {BlockchainError} When reading from contract fails or chain is unavailable
37190
- */
37191
- async isActivePermission(permissionId) {
37192
- try {
37193
- const chainId = await this.context.walletClient.getChainId();
37194
- const DataPermissionsAddress = getContractAddress(
37195
- chainId,
37196
- "DataPermissions"
37197
- );
37198
- const DataPermissionsAbi = getAbi("DataPermissions");
37199
- const isActive = await this.context.publicClient.readContract({
37200
- address: DataPermissionsAddress,
37201
- abi: DataPermissionsAbi,
37202
- functionName: "isActivePermission",
37203
- args: [permissionId]
37204
- });
37205
- return isActive;
37206
- } catch (error) {
37207
- throw new BlockchainError(
37208
- `Failed to check permission status: ${error instanceof Error ? error.message : "Unknown error"}`,
37209
- error
37210
- );
37211
- }
37212
- }
37213
- /**
37214
- * Gets permission details from the contract.
37215
- *
37216
- * @param permissionId - The permission ID to query
37217
- * @returns Promise resolving to permission info
37218
- * @throws {BlockchainError} When reading from contract fails or chain is unavailable
37219
- */
37220
- async getPermissionInfo(permissionId) {
37221
- try {
37222
- const chainId = await this.context.walletClient.getChainId();
37223
- const DataPermissionsAddress = getContractAddress(
37224
- chainId,
37225
- "DataPermissions"
37226
- );
37227
- const DataPermissionsAbi = getAbi("DataPermissions");
37228
- const permissionInfo = await this.context.publicClient.readContract({
37229
- address: DataPermissionsAddress,
37230
- abi: DataPermissionsAbi,
37231
- functionName: "permissions",
37232
- args: [permissionId]
37233
- });
37234
- return permissionInfo;
37235
- } catch (error) {
37236
- throw new BlockchainError(
37237
- `Failed to get permission info: ${error instanceof Error ? error.message : "Unknown error"}`,
37238
- error
37239
- );
37240
- }
37241
- }
37242
37456
  /**
37243
37457
  * Normalizes grant ID to hex format.
37244
37458
  * Handles conversion from permission ID (bigint/number/string) to proper hex hash format.
@@ -37301,13 +37515,14 @@ var PermissionsController = class {
37301
37515
  "DataPortabilityServers"
37302
37516
  );
37303
37517
  const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
37518
+ const userAddress = this.context.walletClient.account?.address || await this.getUserAddress();
37304
37519
  const txHash = await this.context.walletClient.writeContract({
37305
37520
  address: DataPortabilityServersAddress,
37306
37521
  abi: DataPortabilityServersAbi,
37307
- functionName: "addAndTrustServer",
37522
+ functionName: "addAndTrustServerOnBehalf",
37308
37523
  args: [
37524
+ userAddress,
37309
37525
  {
37310
- owner: params.owner,
37311
37526
  serverAddress: params.serverAddress,
37312
37527
  serverUrl: params.serverUrl,
37313
37528
  publicKey: params.publicKey
@@ -37334,7 +37549,7 @@ var PermissionsController = class {
37334
37549
  * @returns Promise resolving to transaction hash
37335
37550
  * @deprecated Use addAndTrustServer instead
37336
37551
  */
37337
- async trustServer(params) {
37552
+ async submitTrustServer(params) {
37338
37553
  try {
37339
37554
  const chainId = await this.context.walletClient.getChainId();
37340
37555
  const DataPortabilityServersAddress = getContractAddress(
@@ -37367,12 +37582,11 @@ var PermissionsController = class {
37367
37582
  * @param params - Parameters for adding and trusting the server
37368
37583
  * @returns Promise resolving to transaction hash
37369
37584
  */
37370
- async addAndTrustServerWithSignature(params) {
37585
+ async submitAddAndTrustServerWithSignature(params) {
37371
37586
  try {
37372
- const nonce = await this.getUserNonce();
37587
+ const nonce = await this.getServersUserNonce();
37373
37588
  const addAndTrustServerInput = {
37374
37589
  nonce,
37375
- owner: params.owner,
37376
37590
  serverAddress: params.serverAddress,
37377
37591
  publicKey: params.publicKey,
37378
37592
  serverUrl: params.serverUrl
@@ -37382,16 +37596,13 @@ var PermissionsController = class {
37382
37596
  );
37383
37597
  console.debug("\u{1F50D} AddAndTrustServer Debug Info:", {
37384
37598
  nonce: nonce.toString(),
37385
- owner: params.owner,
37386
37599
  serverAddress: params.serverAddress,
37387
37600
  publicKey: params.publicKey,
37388
37601
  serverUrl: params.serverUrl,
37389
37602
  domain: typedData.domain,
37390
37603
  typedDataMessage: typedData.message
37391
37604
  });
37392
- const signature = await this.signTypedData(
37393
- typedData
37394
- );
37605
+ const signature = await this.signTypedData(typedData);
37395
37606
  console.debug("\u{1F50D} Generated signature:", signature);
37396
37607
  if (this.context.relayerCallbacks?.submitAddAndTrustServer) {
37397
37608
  return await this.context.relayerCallbacks.submitAddAndTrustServer(
@@ -37432,17 +37643,15 @@ var PermissionsController = class {
37432
37643
  * @throws {ServerUrlMismatchError} When server URL doesn't match existing registration
37433
37644
  * @throws {BlockchainError} When trust operation fails for any other reason
37434
37645
  */
37435
- async trustServerWithSignature(params) {
37646
+ async submitTrustServerWithSignature(params) {
37436
37647
  try {
37437
- const nonce = await this.getUserNonce();
37648
+ const nonce = await this.getServersUserNonce();
37438
37649
  const trustServerInput = {
37439
37650
  nonce,
37440
37651
  serverId: params.serverId
37441
37652
  };
37442
37653
  const typedData = await this.composeTrustServerMessage(trustServerInput);
37443
- const signature = await this.signTypedData(
37444
- typedData
37445
- );
37654
+ const signature = await this.signTypedData(typedData);
37446
37655
  if (this.context.relayerCallbacks?.submitTrustServer) {
37447
37656
  return await this.context.relayerCallbacks.submitTrustServer(
37448
37657
  typedData,
@@ -37528,8 +37737,8 @@ var PermissionsController = class {
37528
37737
  * console.log('Still trusting servers:', trustedServers);
37529
37738
  * ```
37530
37739
  */
37531
- async untrustServer(params) {
37532
- const nonce = await this.getUserNonce();
37740
+ async submitUntrustServer(params) {
37741
+ const nonce = await this.getServersUserNonce();
37533
37742
  const untrustServerInput = {
37534
37743
  nonce,
37535
37744
  serverId: params.serverId
@@ -37548,27 +37757,22 @@ var PermissionsController = class {
37548
37757
  * @throws {RelayerError} When gasless submission fails
37549
37758
  * @throws {BlockchainError} When untrust transaction fails
37550
37759
  */
37551
- async untrustServerWithSignature(params) {
37760
+ async submitUntrustServerWithSignature(params) {
37552
37761
  try {
37553
- const nonce = await this.getUserNonce();
37762
+ const nonce = await this.getServersUserNonce();
37554
37763
  const untrustServerInput = {
37555
37764
  nonce,
37556
37765
  serverId: params.serverId
37557
37766
  };
37558
37767
  const typedData = await this.composeUntrustServerMessage(untrustServerInput);
37559
- const signature = await this.signTypedData(
37560
- typedData
37561
- );
37768
+ const signature = await this.signTypedData(typedData);
37562
37769
  if (this.context.relayerCallbacks?.submitUntrustServer) {
37563
37770
  return await this.context.relayerCallbacks.submitUntrustServer(
37564
37771
  typedData,
37565
37772
  signature
37566
37773
  );
37567
37774
  } else {
37568
- return await this.submitSignedUntrustTransaction(
37569
- typedData,
37570
- signature
37571
- );
37775
+ return await this.submitSignedUntrustTransaction(typedData, signature);
37572
37776
  }
37573
37777
  } catch (error) {
37574
37778
  if (error instanceof Error) {
@@ -37628,131 +37832,6 @@ var PermissionsController = class {
37628
37832
  );
37629
37833
  }
37630
37834
  }
37631
- /**
37632
- * Retrieves detailed information about a specific server from the DataPortabilityServers contract.
37633
- *
37634
- * Returns complete server information including owner, address, public key, and URL.
37635
- * This information is used to establish secure connections and verify server identity.
37636
- *
37637
- * @param serverId - The unique numeric ID of the server to query
37638
- * @returns Promise resolving to complete server information
37639
- * @throws {BlockchainError} When reading from contract fails or chain is unavailable
37640
- * @throws {NetworkError} When unable to connect to the blockchain network
37641
- * @throws {ServerNotFoundError} When the server ID does not exist
37642
- *
37643
- * @example
37644
- * ```typescript
37645
- * const server = await vana.permissions.getServerInfo(1);
37646
- *
37647
- * console.log(`Server ${server.id}:`);
37648
- * console.log(` Owner: ${server.owner}`);
37649
- * console.log(` Address: ${server.serverAddress}`);
37650
- * console.log(` URL: ${server.url}`);
37651
- * console.log(` Public Key: ${server.publicKey}`);
37652
- * ```
37653
- */
37654
- async getServerInfo(serverId) {
37655
- try {
37656
- const chainId = await this.context.walletClient.getChainId();
37657
- const DataPortabilityServersAddress = getContractAddress(
37658
- chainId,
37659
- "DataPortabilityServers"
37660
- );
37661
- const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
37662
- const serverInfo = await this.context.publicClient.readContract({
37663
- address: DataPortabilityServersAddress,
37664
- abi: DataPortabilityServersAbi,
37665
- functionName: "servers",
37666
- args: [BigInt(serverId)]
37667
- });
37668
- return {
37669
- id: Number(serverInfo.id),
37670
- owner: serverInfo.owner,
37671
- url: serverInfo.url,
37672
- serverAddress: serverInfo.serverAddress,
37673
- publicKey: serverInfo.publicKey
37674
- };
37675
- } catch (error) {
37676
- throw new BlockchainError(
37677
- `Failed to get server info: ${error instanceof Error ? error.message : "Unknown error"}`,
37678
- error
37679
- );
37680
- }
37681
- }
37682
- /**
37683
- * Checks if a specific server is active in the DataPortabilityServers contract.
37684
- *
37685
- * An active server is one that is properly registered and operational, meaning
37686
- * it can receive and process data portability requests from users.
37687
- *
37688
- * @param serverId - The unique numeric ID of the server to check
37689
- * @returns Promise resolving to true if server is active, false otherwise
37690
- * @throws {BlockchainError} When reading from contract fails or chain is unavailable
37691
- * @throws {NetworkError} When unable to connect to the blockchain network
37692
- *
37693
- * @example
37694
- * ```typescript
37695
- * const isActive = await vana.permissions.isActiveServer(1);
37696
- *
37697
- * if (isActive) {
37698
- * console.log('Server 1 is active and ready to process requests');
37699
- * } else {
37700
- * console.log('Server 1 is inactive or not found');
37701
- * }
37702
- * ```
37703
- */
37704
- async isActiveServer(serverId) {
37705
- try {
37706
- const chainId = await this.context.walletClient.getChainId();
37707
- const DataPortabilityServersAddress = getContractAddress(
37708
- chainId,
37709
- "DataPortabilityServers"
37710
- );
37711
- const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
37712
- const isActive = await this.context.publicClient.readContract({
37713
- address: DataPortabilityServersAddress,
37714
- abi: DataPortabilityServersAbi,
37715
- functionName: "isActiveServer",
37716
- args: [BigInt(serverId)]
37717
- });
37718
- return isActive;
37719
- } catch (error) {
37720
- throw new BlockchainError(
37721
- `Failed to check server status: ${error instanceof Error ? error.message : "Unknown error"}`,
37722
- error
37723
- );
37724
- }
37725
- }
37726
- /**
37727
- * Checks if a server is active for a specific user.
37728
- *
37729
- * @param serverId - Server ID (numeric)
37730
- * @param userAddress - Optional user address (defaults to current user)
37731
- * @returns Promise resolving to boolean indicating if server is active for the user
37732
- */
37733
- async isActiveServerForUser(serverId, userAddress) {
37734
- try {
37735
- const user = userAddress || await this.getUserAddress();
37736
- const chainId = await this.context.walletClient.getChainId();
37737
- const DataPortabilityServersAddress = getContractAddress(
37738
- chainId,
37739
- "DataPortabilityServers"
37740
- );
37741
- const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
37742
- const isActive = await this.context.publicClient.readContract({
37743
- address: DataPortabilityServersAddress,
37744
- abi: DataPortabilityServersAbi,
37745
- functionName: "isActiveServerForUser",
37746
- args: [user, BigInt(serverId)]
37747
- });
37748
- return isActive;
37749
- } catch (error) {
37750
- throw new BlockchainError(
37751
- `Failed to check server status for user: ${error instanceof Error ? error.message : "Unknown error"}`,
37752
- error
37753
- );
37754
- }
37755
- }
37756
37835
  /**
37757
37836
  * Gets the total count of trusted servers for a user.
37758
37837
  *
@@ -37855,27 +37934,29 @@ var PermissionsController = class {
37855
37934
  try {
37856
37935
  const paginatedResult = await this.getTrustedServersPaginated(options);
37857
37936
  const serverInfoPromises = paginatedResult.servers.map(
37858
- async (serverId, index) => {
37937
+ async (serverId, _index) => {
37859
37938
  try {
37860
- const serverInfo = await this.getServerInfo(serverId);
37939
+ const serverInfo = await this.getServerInfo(BigInt(serverId));
37861
37940
  return {
37862
- serverId,
37941
+ id: BigInt(serverId),
37863
37942
  owner: serverInfo.owner,
37864
- url: serverInfo.url,
37865
37943
  serverAddress: serverInfo.serverAddress,
37866
37944
  publicKey: serverInfo.publicKey,
37867
- isTrusted: true,
37868
- trustIndex: options.offset ? options.offset + index : index
37945
+ url: serverInfo.url,
37946
+ startBlock: 0n,
37947
+ // We don't have this info from the old method structure
37948
+ endBlock: 0n
37949
+ // 0 means still active
37869
37950
  };
37870
37951
  } catch {
37871
37952
  return {
37872
- serverId,
37953
+ id: BigInt(serverId),
37873
37954
  owner: "0x0000000000000000000000000000000000000000",
37874
- url: "",
37875
37955
  serverAddress: "0x0000000000000000000000000000000000000000",
37876
37956
  publicKey: "",
37877
- isTrusted: true,
37878
- trustIndex: options.offset ? options.offset + index : index
37957
+ url: "",
37958
+ startBlock: 0n,
37959
+ endBlock: 0n
37879
37960
  };
37880
37961
  }
37881
37962
  }
@@ -37981,18 +38062,18 @@ var PermissionsController = class {
37981
38062
  */
37982
38063
  async composeAddAndTrustServerMessage(input) {
37983
38064
  const domain = await this.getServersDomain();
38065
+ console.debug(domain);
37984
38066
  return {
37985
38067
  domain,
37986
38068
  types: {
37987
- AddAndTrustServer: [
38069
+ AddServer: [
37988
38070
  { name: "nonce", type: "uint256" },
37989
- { name: "owner", type: "address" },
37990
38071
  { name: "serverAddress", type: "address" },
37991
- { name: "publicKey", type: "bytes" },
38072
+ { name: "publicKey", type: "string" },
37992
38073
  { name: "serverUrl", type: "string" }
37993
38074
  ]
37994
38075
  },
37995
- primaryType: "AddAndTrustServer",
38076
+ primaryType: "AddServer",
37996
38077
  message: input
37997
38078
  };
37998
38079
  }
@@ -38073,13 +38154,13 @@ var PermissionsController = class {
38073
38154
  contractAddress: DataPortabilityServersAddress,
38074
38155
  input: {
38075
38156
  nonce: addAndTrustServerInput.nonce.toString(),
38076
- owner: addAndTrustServerInput.owner,
38077
38157
  serverAddress: addAndTrustServerInput.serverAddress,
38078
38158
  publicKey: addAndTrustServerInput.publicKey,
38079
38159
  serverUrl: addAndTrustServerInput.serverUrl
38080
38160
  },
38081
38161
  signature
38082
38162
  });
38163
+ const formattedSignature = formatSignatureForContract(signature);
38083
38164
  const txHash = await this.context.walletClient.writeContract({
38084
38165
  address: DataPortabilityServersAddress,
38085
38166
  abi: DataPortabilityServersAbi,
@@ -38087,12 +38168,11 @@ var PermissionsController = class {
38087
38168
  args: [
38088
38169
  {
38089
38170
  nonce: addAndTrustServerInput.nonce,
38090
- owner: addAndTrustServerInput.owner,
38091
38171
  serverAddress: addAndTrustServerInput.serverAddress,
38092
38172
  publicKey: addAndTrustServerInput.publicKey,
38093
38173
  serverUrl: addAndTrustServerInput.serverUrl
38094
38174
  },
38095
- signature
38175
+ formattedSignature
38096
38176
  ],
38097
38177
  account: this.context.walletClient.account || await this.getUserAddress(),
38098
38178
  chain: this.context.walletClient.chain || null
@@ -38113,6 +38193,7 @@ var PermissionsController = class {
38113
38193
  "DataPortabilityServers"
38114
38194
  );
38115
38195
  const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
38196
+ const formattedSignature = formatSignatureForContract(signature);
38116
38197
  const txHash = await this.context.walletClient.writeContract({
38117
38198
  address: DataPortabilityServersAddress,
38118
38199
  abi: DataPortabilityServersAbi,
@@ -38122,7 +38203,7 @@ var PermissionsController = class {
38122
38203
  nonce: trustServerInput.nonce,
38123
38204
  serverId: BigInt(trustServerInput.serverId)
38124
38205
  },
38125
- signature
38206
+ formattedSignature
38126
38207
  ],
38127
38208
  account: this.context.walletClient.account || await this.getUserAddress(),
38128
38209
  chain: this.context.walletClient.chain || null
@@ -38138,17 +38219,18 @@ var PermissionsController = class {
38138
38219
  */
38139
38220
  async submitDirectRevokeTransaction(typedData, signature) {
38140
38221
  const chainId = await this.context.walletClient.getChainId();
38141
- const DataPermissionsAddress = getContractAddress(
38222
+ const DataPortabilityPermissionsAddress = getContractAddress(
38142
38223
  chainId,
38143
- "DataPermissions"
38224
+ "DataPortabilityPermissions"
38144
38225
  );
38145
- const DataPermissionsAbi = getAbi("DataPermissions");
38226
+ const DataPortabilityPermissionsAbi = getAbi("DataPortabilityPermissions");
38227
+ const formattedSignature = formatSignatureForContract(signature);
38146
38228
  const txHash = await this.context.walletClient.writeContract({
38147
- address: DataPermissionsAddress,
38148
- abi: DataPermissionsAbi,
38229
+ address: DataPortabilityPermissionsAddress,
38230
+ abi: DataPortabilityPermissionsAbi,
38149
38231
  functionName: "revokePermissionWithSignature",
38150
38232
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
38151
- args: [typedData.message, signature],
38233
+ args: [typedData.message, formattedSignature],
38152
38234
  account: this.context.walletClient.account || await this.getUserAddress(),
38153
38235
  chain: this.context.walletClient.chain || null
38154
38236
  });
@@ -38168,12 +38250,13 @@ var PermissionsController = class {
38168
38250
  "DataPortabilityServers"
38169
38251
  );
38170
38252
  const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
38253
+ const formattedSignature = formatSignatureForContract(signature);
38171
38254
  const txHash = await this.context.walletClient.writeContract({
38172
38255
  address: DataPortabilityServersAddress,
38173
38256
  abi: DataPortabilityServersAbi,
38174
38257
  functionName: "untrustServerWithSignature",
38175
38258
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
38176
- args: [typedData.message, signature],
38259
+ args: [typedData.message, formattedSignature],
38177
38260
  account: this.context.walletClient.account || await this.getUserAddress(),
38178
38261
  chain: this.context.walletClient.chain || null
38179
38262
  });
@@ -38207,7 +38290,7 @@ var PermissionsController = class {
38207
38290
  * console.log(`Grantee registered in transaction: ${txHash}`);
38208
38291
  * ```
38209
38292
  */
38210
- async registerGrantee(params) {
38293
+ async submitRegisterGrantee(params) {
38211
38294
  const chainId = await this.context.walletClient.getChainId();
38212
38295
  const DataPortabilityGranteesAddress = getContractAddress(
38213
38296
  chainId,
@@ -38239,8 +38322,8 @@ var PermissionsController = class {
38239
38322
  * });
38240
38323
  * ```
38241
38324
  */
38242
- async registerGranteeWithSignature(params) {
38243
- const nonce = await this.getUserNonce();
38325
+ async submitRegisterGranteeWithSignature(params) {
38326
+ const nonce = await this.getServersUserNonce();
38244
38327
  const registerGranteeInput = {
38245
38328
  nonce,
38246
38329
  owner: params.owner,
@@ -38513,10 +38596,1192 @@ var PermissionsController = class {
38513
38596
  });
38514
38597
  return txHash;
38515
38598
  }
38599
+ // ===========================
38600
+ // DATA PORTABILITY SERVERS HELPER METHODS
38601
+ // ===========================
38602
+ /**
38603
+ * Get all trusted server IDs for a user
38604
+ *
38605
+ * @param userAddress - User address to query (defaults to current user)
38606
+ * @returns Promise resolving to array of server IDs
38607
+ */
38608
+ async getUserServerIds(userAddress) {
38609
+ try {
38610
+ const targetAddress = userAddress || await this.getUserAddress();
38611
+ const chainId = await this.context.publicClient.getChainId();
38612
+ const DataPortabilityServersAddress = getContractAddress(
38613
+ chainId,
38614
+ "DataPortabilityServers"
38615
+ );
38616
+ const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
38617
+ const serverIds = await this.context.publicClient.readContract({
38618
+ address: DataPortabilityServersAddress,
38619
+ abi: DataPortabilityServersAbi,
38620
+ functionName: "userServerIdsValues",
38621
+ args: [targetAddress]
38622
+ });
38623
+ return [...serverIds];
38624
+ } catch (error) {
38625
+ throw new BlockchainError(
38626
+ `Failed to get user server IDs: ${error instanceof Error ? error.message : "Unknown error"}`,
38627
+ error
38628
+ );
38629
+ }
38630
+ }
38631
+ /**
38632
+ * Get server ID at specific index for a user
38633
+ *
38634
+ * @param userAddress - User address to query
38635
+ * @param serverIndex - Index in the user's server list
38636
+ * @returns Promise resolving to server ID
38637
+ */
38638
+ async getUserServerIdAt(userAddress, serverIndex) {
38639
+ try {
38640
+ const chainId = await this.context.publicClient.getChainId();
38641
+ const DataPortabilityServersAddress = getContractAddress(
38642
+ chainId,
38643
+ "DataPortabilityServers"
38644
+ );
38645
+ const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
38646
+ const serverId = await this.context.publicClient.readContract({
38647
+ address: DataPortabilityServersAddress,
38648
+ abi: DataPortabilityServersAbi,
38649
+ functionName: "userServerIdsAt",
38650
+ args: [userAddress, serverIndex]
38651
+ });
38652
+ return serverId;
38653
+ } catch (error) {
38654
+ throw new BlockchainError(
38655
+ `Failed to get user server ID at index: ${error instanceof Error ? error.message : "Unknown error"}`,
38656
+ error
38657
+ );
38658
+ }
38659
+ }
38660
+ /**
38661
+ * Get the number of trusted servers for a user
38662
+ *
38663
+ * @param userAddress - User address to query (defaults to current user)
38664
+ * @returns Promise resolving to number of trusted servers
38665
+ */
38666
+ async getUserServerCount(userAddress) {
38667
+ try {
38668
+ const targetAddress = userAddress || await this.getUserAddress();
38669
+ const chainId = await this.context.publicClient.getChainId();
38670
+ const DataPortabilityServersAddress = getContractAddress(
38671
+ chainId,
38672
+ "DataPortabilityServers"
38673
+ );
38674
+ const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
38675
+ const count = await this.context.publicClient.readContract({
38676
+ address: DataPortabilityServersAddress,
38677
+ abi: DataPortabilityServersAbi,
38678
+ functionName: "userServerIdsLength",
38679
+ args: [targetAddress]
38680
+ });
38681
+ return count;
38682
+ } catch (error) {
38683
+ throw new BlockchainError(
38684
+ `Failed to get user server count: ${error instanceof Error ? error.message : "Unknown error"}`,
38685
+ error
38686
+ );
38687
+ }
38688
+ }
38689
+ /**
38690
+ * Get detailed information about trusted servers for a user
38691
+ *
38692
+ * @param userAddress - User address to query (defaults to current user)
38693
+ * @returns Promise resolving to array of trusted server info
38694
+ */
38695
+ async getUserTrustedServers(userAddress) {
38696
+ try {
38697
+ const targetAddress = userAddress || await this.getUserAddress();
38698
+ const chainId = await this.context.publicClient.getChainId();
38699
+ const DataPortabilityServersAddress = getContractAddress(
38700
+ chainId,
38701
+ "DataPortabilityServers"
38702
+ );
38703
+ const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
38704
+ const servers = await this.context.publicClient.readContract({
38705
+ address: DataPortabilityServersAddress,
38706
+ abi: DataPortabilityServersAbi,
38707
+ functionName: "userServerValues",
38708
+ args: [targetAddress]
38709
+ });
38710
+ return [...servers];
38711
+ } catch (error) {
38712
+ throw new BlockchainError(
38713
+ `Failed to get user trusted servers: ${error instanceof Error ? error.message : "Unknown error"}`,
38714
+ error
38715
+ );
38716
+ }
38717
+ }
38718
+ /**
38719
+ * Get trusted server info for a specific server ID and user
38720
+ *
38721
+ * @param userAddress - User address to query
38722
+ * @param serverId - Server ID to get info for
38723
+ * @returns Promise resolving to trusted server info
38724
+ */
38725
+ async getUserTrustedServer(userAddress, serverId) {
38726
+ try {
38727
+ const chainId = await this.context.publicClient.getChainId();
38728
+ const DataPortabilityServersAddress = getContractAddress(
38729
+ chainId,
38730
+ "DataPortabilityServers"
38731
+ );
38732
+ const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
38733
+ const serverInfo = await this.context.publicClient.readContract({
38734
+ address: DataPortabilityServersAddress,
38735
+ abi: DataPortabilityServersAbi,
38736
+ functionName: "userServers",
38737
+ args: [userAddress, serverId]
38738
+ });
38739
+ return serverInfo;
38740
+ } catch (error) {
38741
+ throw new BlockchainError(
38742
+ `Failed to get user trusted server: ${error instanceof Error ? error.message : "Unknown error"}`,
38743
+ error
38744
+ );
38745
+ }
38746
+ }
38747
+ /**
38748
+ * Get server information by server ID
38749
+ *
38750
+ * @param serverId - Server ID to get info for
38751
+ * @returns Promise resolving to server info
38752
+ */
38753
+ async getServerInfo(serverId) {
38754
+ try {
38755
+ const chainId = await this.context.publicClient.getChainId();
38756
+ const DataPortabilityServersAddress = getContractAddress(
38757
+ chainId,
38758
+ "DataPortabilityServers"
38759
+ );
38760
+ const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
38761
+ const serverInfo = await this.context.publicClient.readContract({
38762
+ address: DataPortabilityServersAddress,
38763
+ abi: DataPortabilityServersAbi,
38764
+ functionName: "servers",
38765
+ args: [serverId]
38766
+ });
38767
+ return serverInfo;
38768
+ } catch (error) {
38769
+ throw new BlockchainError(
38770
+ `Failed to get server info: ${error instanceof Error ? error.message : "Unknown error"}`,
38771
+ error
38772
+ );
38773
+ }
38774
+ }
38775
+ /**
38776
+ * Get server information by server address
38777
+ *
38778
+ * @param serverAddress - Server address to get info for
38779
+ * @returns Promise resolving to server info
38780
+ */
38781
+ async getServerInfoByAddress(serverAddress) {
38782
+ try {
38783
+ const chainId = await this.context.publicClient.getChainId();
38784
+ const DataPortabilityServersAddress = getContractAddress(
38785
+ chainId,
38786
+ "DataPortabilityServers"
38787
+ );
38788
+ const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
38789
+ const serverInfo = await this.context.publicClient.readContract({
38790
+ address: DataPortabilityServersAddress,
38791
+ abi: DataPortabilityServersAbi,
38792
+ functionName: "serverByAddress",
38793
+ args: [serverAddress]
38794
+ });
38795
+ return serverInfo;
38796
+ } catch (error) {
38797
+ throw new BlockchainError(
38798
+ `Failed to get server info by address: ${error instanceof Error ? error.message : "Unknown error"}`,
38799
+ error
38800
+ );
38801
+ }
38802
+ }
38803
+ // ===========================
38804
+ // DATA PORTABILITY PERMISSIONS HELPER METHODS
38805
+ // ===========================
38806
+ /**
38807
+ * Get all permission IDs for a user
38808
+ *
38809
+ * @param userAddress - User address to query (defaults to current user)
38810
+ * @returns Promise resolving to array of permission IDs
38811
+ */
38812
+ async getUserPermissionIds(userAddress) {
38813
+ try {
38814
+ const targetAddress = userAddress || await this.getUserAddress();
38815
+ const chainId = await this.context.publicClient.getChainId();
38816
+ const DataPortabilityPermissionsAddress = getContractAddress(
38817
+ chainId,
38818
+ "DataPortabilityPermissions"
38819
+ );
38820
+ const DataPortabilityPermissionsAbi = getAbi(
38821
+ "DataPortabilityPermissions"
38822
+ );
38823
+ const permissionIds = await this.context.publicClient.readContract({
38824
+ address: DataPortabilityPermissionsAddress,
38825
+ abi: DataPortabilityPermissionsAbi,
38826
+ functionName: "userPermissionIdsValues",
38827
+ args: [targetAddress]
38828
+ });
38829
+ return [...permissionIds];
38830
+ } catch (error) {
38831
+ throw new BlockchainError(
38832
+ `Failed to get user permission IDs: ${error instanceof Error ? error.message : "Unknown error"}`,
38833
+ error
38834
+ );
38835
+ }
38836
+ }
38837
+ /**
38838
+ * Get permission ID at specific index for a user
38839
+ *
38840
+ * @param userAddress - User address to query
38841
+ * @param permissionIndex - Index in the user's permission list
38842
+ * @returns Promise resolving to permission ID
38843
+ */
38844
+ async getUserPermissionIdAt(userAddress, permissionIndex) {
38845
+ try {
38846
+ const chainId = await this.context.publicClient.getChainId();
38847
+ const DataPortabilityPermissionsAddress = getContractAddress(
38848
+ chainId,
38849
+ "DataPortabilityPermissions"
38850
+ );
38851
+ const DataPortabilityPermissionsAbi = getAbi(
38852
+ "DataPortabilityPermissions"
38853
+ );
38854
+ const permissionId = await this.context.publicClient.readContract({
38855
+ address: DataPortabilityPermissionsAddress,
38856
+ abi: DataPortabilityPermissionsAbi,
38857
+ functionName: "userPermissionIdsAt",
38858
+ args: [userAddress, permissionIndex]
38859
+ });
38860
+ return permissionId;
38861
+ } catch (error) {
38862
+ throw new BlockchainError(
38863
+ `Failed to get user permission ID at index: ${error instanceof Error ? error.message : "Unknown error"}`,
38864
+ error
38865
+ );
38866
+ }
38867
+ }
38868
+ /**
38869
+ * Get the number of permissions for a user
38870
+ *
38871
+ * @param userAddress - User address to query (defaults to current user)
38872
+ * @returns Promise resolving to number of permissions
38873
+ */
38874
+ async getUserPermissionCount(userAddress) {
38875
+ try {
38876
+ const targetAddress = userAddress || await this.getUserAddress();
38877
+ const chainId = await this.context.publicClient.getChainId();
38878
+ const DataPortabilityPermissionsAddress = getContractAddress(
38879
+ chainId,
38880
+ "DataPortabilityPermissions"
38881
+ );
38882
+ const DataPortabilityPermissionsAbi = getAbi(
38883
+ "DataPortabilityPermissions"
38884
+ );
38885
+ const count = await this.context.publicClient.readContract({
38886
+ address: DataPortabilityPermissionsAddress,
38887
+ abi: DataPortabilityPermissionsAbi,
38888
+ functionName: "userPermissionIdsLength",
38889
+ args: [targetAddress]
38890
+ });
38891
+ return count;
38892
+ } catch (error) {
38893
+ throw new BlockchainError(
38894
+ `Failed to get user permission count: ${error instanceof Error ? error.message : "Unknown error"}`,
38895
+ error
38896
+ );
38897
+ }
38898
+ }
38899
+ /**
38900
+ * Get detailed permission information by permission ID
38901
+ *
38902
+ * @param permissionId - Permission ID to get info for
38903
+ * @returns Promise resolving to permission info
38904
+ */
38905
+ async getPermissionInfo(permissionId) {
38906
+ try {
38907
+ const chainId = await this.context.publicClient.getChainId();
38908
+ const DataPortabilityPermissionsAddress = getContractAddress(
38909
+ chainId,
38910
+ "DataPortabilityPermissions"
38911
+ );
38912
+ const DataPortabilityPermissionsAbi = getAbi(
38913
+ "DataPortabilityPermissions"
38914
+ );
38915
+ const permissionInfo = await this.context.publicClient.readContract({
38916
+ address: DataPortabilityPermissionsAddress,
38917
+ abi: DataPortabilityPermissionsAbi,
38918
+ functionName: "permissions",
38919
+ args: [permissionId]
38920
+ });
38921
+ return permissionInfo;
38922
+ } catch (error) {
38923
+ throw new BlockchainError(
38924
+ `Failed to get permission info: ${error instanceof Error ? error.message : "Unknown error"}`,
38925
+ error
38926
+ );
38927
+ }
38928
+ }
38929
+ /**
38930
+ * Get all permission IDs for a specific file
38931
+ *
38932
+ * @param fileId - File ID to get permissions for
38933
+ * @returns Promise resolving to array of permission IDs
38934
+ */
38935
+ async getFilePermissionIds(fileId) {
38936
+ try {
38937
+ const chainId = await this.context.publicClient.getChainId();
38938
+ const DataPortabilityPermissionsAddress = getContractAddress(
38939
+ chainId,
38940
+ "DataPortabilityPermissions"
38941
+ );
38942
+ const DataPortabilityPermissionsAbi = getAbi(
38943
+ "DataPortabilityPermissions"
38944
+ );
38945
+ const permissionIds = await this.context.publicClient.readContract({
38946
+ address: DataPortabilityPermissionsAddress,
38947
+ abi: DataPortabilityPermissionsAbi,
38948
+ functionName: "filePermissionIds",
38949
+ args: [fileId]
38950
+ });
38951
+ return [...permissionIds];
38952
+ } catch (error) {
38953
+ throw new BlockchainError(
38954
+ `Failed to get file permission IDs: ${error instanceof Error ? error.message : "Unknown error"}`,
38955
+ error
38956
+ );
38957
+ }
38958
+ }
38959
+ /**
38960
+ * Get all file IDs for a specific permission
38961
+ *
38962
+ * @param permissionId - Permission ID to get files for
38963
+ * @returns Promise resolving to array of file IDs
38964
+ */
38965
+ async getPermissionFileIds(permissionId) {
38966
+ try {
38967
+ const chainId = await this.context.publicClient.getChainId();
38968
+ const DataPortabilityPermissionsAddress = getContractAddress(
38969
+ chainId,
38970
+ "DataPortabilityPermissions"
38971
+ );
38972
+ const DataPortabilityPermissionsAbi = getAbi(
38973
+ "DataPortabilityPermissions"
38974
+ );
38975
+ const fileIds = await this.context.publicClient.readContract({
38976
+ address: DataPortabilityPermissionsAddress,
38977
+ abi: DataPortabilityPermissionsAbi,
38978
+ functionName: "permissionFileIds",
38979
+ args: [permissionId]
38980
+ });
38981
+ return [...fileIds];
38982
+ } catch (error) {
38983
+ throw new BlockchainError(
38984
+ `Failed to get permission file IDs: ${error instanceof Error ? error.message : "Unknown error"}`,
38985
+ error
38986
+ );
38987
+ }
38988
+ }
38989
+ /**
38990
+ * Get all permissions for a specific file (alias for getFilePermissionIds)
38991
+ *
38992
+ * @param fileId - File ID to get permissions for
38993
+ * @returns Promise resolving to array of permission IDs
38994
+ */
38995
+ async getFilePermissions(fileId) {
38996
+ const chainId = await this.context.publicClient.getChainId();
38997
+ const DataPortabilityPermissionsAddress = getContractAddress(
38998
+ chainId,
38999
+ "DataPortabilityPermissions"
39000
+ );
39001
+ const DataPortabilityPermissionsAbi = getAbi("DataPortabilityPermissions");
39002
+ const permissions = await this.context.publicClient.readContract({
39003
+ address: DataPortabilityPermissionsAddress,
39004
+ abi: DataPortabilityPermissionsAbi,
39005
+ functionName: "filePermissions",
39006
+ args: [fileId]
39007
+ });
39008
+ return [...permissions];
39009
+ }
39010
+ // ===========================
39011
+ // DATA PORTABILITY GRANTEES HELPER METHODS
39012
+ // ===========================
39013
+ /**
39014
+ * Get grantee information by grantee ID
39015
+ *
39016
+ * @param granteeId - Grantee ID to get info for
39017
+ * @returns Promise resolving to grantee info
39018
+ */
39019
+ async getGranteeInfo(granteeId) {
39020
+ try {
39021
+ const chainId = await this.context.publicClient.getChainId();
39022
+ const DataPortabilityGranteesAddress = getContractAddress(
39023
+ chainId,
39024
+ "DataPortabilityGrantees"
39025
+ );
39026
+ const DataPortabilityGranteesAbi = getAbi("DataPortabilityGrantees");
39027
+ const granteeInfo = await this.context.publicClient.readContract({
39028
+ address: DataPortabilityGranteesAddress,
39029
+ abi: DataPortabilityGranteesAbi,
39030
+ functionName: "granteeInfo",
39031
+ args: [granteeId]
39032
+ });
39033
+ return granteeInfo;
39034
+ } catch (error) {
39035
+ throw new BlockchainError(
39036
+ `Failed to get grantee info: ${error instanceof Error ? error.message : "Unknown error"}`,
39037
+ error
39038
+ );
39039
+ }
39040
+ }
39041
+ /**
39042
+ * Get grantee information by grantee address
39043
+ *
39044
+ * @param granteeAddress - Grantee address to get info for
39045
+ * @returns Promise resolving to grantee info
39046
+ */
39047
+ async getGranteeInfoByAddress(granteeAddress) {
39048
+ try {
39049
+ const chainId = await this.context.publicClient.getChainId();
39050
+ const DataPortabilityGranteesAddress = getContractAddress(
39051
+ chainId,
39052
+ "DataPortabilityGrantees"
39053
+ );
39054
+ const DataPortabilityGranteesAbi = getAbi("DataPortabilityGrantees");
39055
+ const granteeInfo = await this.context.publicClient.readContract({
39056
+ address: DataPortabilityGranteesAddress,
39057
+ abi: DataPortabilityGranteesAbi,
39058
+ functionName: "granteeByAddress",
39059
+ args: [granteeAddress]
39060
+ });
39061
+ return granteeInfo;
39062
+ } catch (error) {
39063
+ throw new BlockchainError(
39064
+ `Failed to get grantee info by address: ${error instanceof Error ? error.message : "Unknown error"}`,
39065
+ error
39066
+ );
39067
+ }
39068
+ }
39069
+ /**
39070
+ * Get all permission IDs for a specific grantee
39071
+ *
39072
+ * @param granteeId - Grantee ID to get permissions for
39073
+ * @returns Promise resolving to array of permission IDs
39074
+ */
39075
+ async getGranteePermissionIds(granteeId) {
39076
+ try {
39077
+ const chainId = await this.context.publicClient.getChainId();
39078
+ const DataPortabilityGranteesAddress = getContractAddress(
39079
+ chainId,
39080
+ "DataPortabilityGrantees"
39081
+ );
39082
+ const DataPortabilityGranteesAbi = getAbi("DataPortabilityGrantees");
39083
+ const permissionIds = await this.context.publicClient.readContract({
39084
+ address: DataPortabilityGranteesAddress,
39085
+ abi: DataPortabilityGranteesAbi,
39086
+ functionName: "granteePermissionIds",
39087
+ args: [granteeId]
39088
+ });
39089
+ return [...permissionIds];
39090
+ } catch (error) {
39091
+ throw new BlockchainError(
39092
+ `Failed to get grantee permission IDs: ${error instanceof Error ? error.message : "Unknown error"}`,
39093
+ error
39094
+ );
39095
+ }
39096
+ }
39097
+ /**
39098
+ * Get all permissions for a specific grantee (alias for getGranteePermissionIds)
39099
+ *
39100
+ * @param granteeId - Grantee ID to get permissions for
39101
+ * @returns Promise resolving to array of permission IDs
39102
+ */
39103
+ async getGranteePermissions(granteeId) {
39104
+ try {
39105
+ const chainId = await this.context.publicClient.getChainId();
39106
+ const DataPortabilityGranteesAddress = getContractAddress(
39107
+ chainId,
39108
+ "DataPortabilityGrantees"
39109
+ );
39110
+ const DataPortabilityGranteesAbi = getAbi("DataPortabilityGrantees");
39111
+ const permissions = await this.context.publicClient.readContract({
39112
+ address: DataPortabilityGranteesAddress,
39113
+ abi: DataPortabilityGranteesAbi,
39114
+ functionName: "granteePermissions",
39115
+ args: [granteeId]
39116
+ });
39117
+ return [...permissions];
39118
+ } catch (error) {
39119
+ throw new BlockchainError(
39120
+ `Failed to get grantee permissions: ${error instanceof Error ? error.message : "Unknown error"}`,
39121
+ error
39122
+ );
39123
+ }
39124
+ }
39125
+ // ===== DataPortabilityServersImplementation Methods =====
39126
+ /**
39127
+ * Get all server IDs for a user
39128
+ *
39129
+ * @param userAddress - User address to get server IDs for
39130
+ * @returns Promise resolving to array of server IDs
39131
+ */
39132
+ async getUserServerIdsValues(userAddress) {
39133
+ try {
39134
+ const chainId = await this.context.publicClient.getChainId();
39135
+ const DataPortabilityServersAddress = getContractAddress(
39136
+ chainId,
39137
+ "DataPortabilityServers"
39138
+ );
39139
+ const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
39140
+ const serverIds = await this.context.publicClient.readContract({
39141
+ address: DataPortabilityServersAddress,
39142
+ abi: DataPortabilityServersAbi,
39143
+ functionName: "userServerIdsValues",
39144
+ args: [userAddress]
39145
+ });
39146
+ return [...serverIds];
39147
+ } catch (error) {
39148
+ throw new BlockchainError(
39149
+ `Failed to get user server IDs: ${error instanceof Error ? error.message : "Unknown error"}`,
39150
+ error
39151
+ );
39152
+ }
39153
+ }
39154
+ /**
39155
+ * Get server ID at specific index for a user
39156
+ *
39157
+ * @param userAddress - User address
39158
+ * @param serverIndex - Index of the server ID
39159
+ * @returns Promise resolving to server ID
39160
+ */
39161
+ async getUserServerIdsAt(userAddress, serverIndex) {
39162
+ try {
39163
+ const chainId = await this.context.publicClient.getChainId();
39164
+ const DataPortabilityServersAddress = getContractAddress(
39165
+ chainId,
39166
+ "DataPortabilityServers"
39167
+ );
39168
+ const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
39169
+ const serverId = await this.context.publicClient.readContract({
39170
+ address: DataPortabilityServersAddress,
39171
+ abi: DataPortabilityServersAbi,
39172
+ functionName: "userServerIdsAt",
39173
+ args: [userAddress, serverIndex]
39174
+ });
39175
+ return serverId;
39176
+ } catch (error) {
39177
+ throw new BlockchainError(
39178
+ `Failed to get user server ID at index: ${error instanceof Error ? error.message : "Unknown error"}`,
39179
+ error
39180
+ );
39181
+ }
39182
+ }
39183
+ /**
39184
+ * Get the number of servers a user has
39185
+ *
39186
+ * @param userAddress - User address
39187
+ * @returns Promise resolving to number of servers
39188
+ */
39189
+ async getUserServerIdsLength(userAddress) {
39190
+ try {
39191
+ const chainId = await this.context.publicClient.getChainId();
39192
+ const DataPortabilityServersAddress = getContractAddress(
39193
+ chainId,
39194
+ "DataPortabilityServers"
39195
+ );
39196
+ const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
39197
+ const length = await this.context.publicClient.readContract({
39198
+ address: DataPortabilityServersAddress,
39199
+ abi: DataPortabilityServersAbi,
39200
+ functionName: "userServerIdsLength",
39201
+ args: [userAddress]
39202
+ });
39203
+ return length;
39204
+ } catch (error) {
39205
+ throw new BlockchainError(
39206
+ `Failed to get user server IDs length: ${error instanceof Error ? error.message : "Unknown error"}`,
39207
+ error
39208
+ );
39209
+ }
39210
+ }
39211
+ /**
39212
+ * Get trusted server info for a specific user and server ID
39213
+ *
39214
+ * @param userAddress - User address
39215
+ * @param serverId - Server ID
39216
+ * @returns Promise resolving to trusted server info
39217
+ */
39218
+ async getUserServers(userAddress, serverId) {
39219
+ try {
39220
+ const chainId = await this.context.publicClient.getChainId();
39221
+ const DataPortabilityServersAddress = getContractAddress(
39222
+ chainId,
39223
+ "DataPortabilityServers"
39224
+ );
39225
+ const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
39226
+ const serverInfo = await this.context.publicClient.readContract({
39227
+ address: DataPortabilityServersAddress,
39228
+ abi: DataPortabilityServersAbi,
39229
+ functionName: "userServers",
39230
+ args: [userAddress, serverId]
39231
+ });
39232
+ return {
39233
+ id: serverInfo.id,
39234
+ owner: serverInfo.owner,
39235
+ serverAddress: serverInfo.serverAddress,
39236
+ publicKey: serverInfo.publicKey,
39237
+ url: serverInfo.url,
39238
+ startBlock: serverInfo.startBlock,
39239
+ endBlock: serverInfo.endBlock
39240
+ };
39241
+ } catch (error) {
39242
+ throw new BlockchainError(
39243
+ `Failed to get user server info: ${error instanceof Error ? error.message : "Unknown error"}`,
39244
+ error
39245
+ );
39246
+ }
39247
+ }
39248
+ /**
39249
+ * Get server info by server ID
39250
+ *
39251
+ * @param serverId - Server ID
39252
+ * @returns Promise resolving to server info
39253
+ */
39254
+ async getServers(serverId) {
39255
+ try {
39256
+ const chainId = await this.context.publicClient.getChainId();
39257
+ const DataPortabilityServersAddress = getContractAddress(
39258
+ chainId,
39259
+ "DataPortabilityServers"
39260
+ );
39261
+ const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
39262
+ const serverInfo = await this.context.publicClient.readContract({
39263
+ address: DataPortabilityServersAddress,
39264
+ abi: DataPortabilityServersAbi,
39265
+ functionName: "servers",
39266
+ args: [serverId]
39267
+ });
39268
+ return {
39269
+ id: serverInfo.id,
39270
+ owner: serverInfo.owner,
39271
+ serverAddress: serverInfo.serverAddress,
39272
+ publicKey: serverInfo.publicKey,
39273
+ url: serverInfo.url
39274
+ };
39275
+ } catch (error) {
39276
+ throw new BlockchainError(
39277
+ `Failed to get server info: ${error instanceof Error ? error.message : "Unknown error"}`,
39278
+ error
39279
+ );
39280
+ }
39281
+ }
39282
+ /**
39283
+ * Get user info including nonce and trusted server IDs
39284
+ *
39285
+ * @param userAddress - User address
39286
+ * @returns Promise resolving to user info
39287
+ */
39288
+ async getUsers(userAddress) {
39289
+ try {
39290
+ const chainId = await this.context.publicClient.getChainId();
39291
+ const DataPortabilityServersAddress = getContractAddress(
39292
+ chainId,
39293
+ "DataPortabilityServers"
39294
+ );
39295
+ const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
39296
+ const userInfo = await this.context.publicClient.readContract({
39297
+ address: DataPortabilityServersAddress,
39298
+ abi: DataPortabilityServersAbi,
39299
+ functionName: "users",
39300
+ args: [userAddress]
39301
+ });
39302
+ return {
39303
+ nonce: userInfo[0],
39304
+ trustedServerIds: [...userInfo[1]]
39305
+ };
39306
+ } catch (error) {
39307
+ throw new BlockchainError(
39308
+ `Failed to get user info: ${error instanceof Error ? error.message : "Unknown error"}`,
39309
+ error
39310
+ );
39311
+ }
39312
+ }
39313
+ /**
39314
+ * Update server URL
39315
+ *
39316
+ * @param serverId - Server ID to update
39317
+ * @param url - New URL for the server
39318
+ * @returns Promise resolving to transaction hash
39319
+ */
39320
+ async submitUpdateServer(serverId, url) {
39321
+ try {
39322
+ const chainId = await this.context.walletClient.getChainId();
39323
+ const DataPortabilityServersAddress = getContractAddress(
39324
+ chainId,
39325
+ "DataPortabilityServers"
39326
+ );
39327
+ const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
39328
+ const hash = await this.context.walletClient.writeContract({
39329
+ address: DataPortabilityServersAddress,
39330
+ abi: DataPortabilityServersAbi,
39331
+ functionName: "updateServer",
39332
+ args: [serverId, url],
39333
+ chain: this.context.walletClient.chain,
39334
+ account: this.context.walletClient.account || null
39335
+ });
39336
+ return hash;
39337
+ } catch (error) {
39338
+ throw new BlockchainError(
39339
+ `Failed to update server: ${error instanceof Error ? error.message : "Unknown error"}`,
39340
+ error
39341
+ );
39342
+ }
39343
+ }
39344
+ // ===== DataPortabilityPermissionsImplementation Methods =====
39345
+ /**
39346
+ * Get all permission IDs for a user
39347
+ *
39348
+ * @param userAddress - User address to get permission IDs for
39349
+ * @returns Promise resolving to array of permission IDs
39350
+ */
39351
+ async getUserPermissionIdsValues(userAddress) {
39352
+ try {
39353
+ const chainId = await this.context.publicClient.getChainId();
39354
+ const DataPortabilityPermissionsAddress = getContractAddress(
39355
+ chainId,
39356
+ "DataPortabilityPermissions"
39357
+ );
39358
+ const DataPortabilityPermissionsAbi = getAbi(
39359
+ "DataPortabilityPermissions"
39360
+ );
39361
+ const permissionIds = await this.context.publicClient.readContract({
39362
+ address: DataPortabilityPermissionsAddress,
39363
+ abi: DataPortabilityPermissionsAbi,
39364
+ functionName: "userPermissionIdsValues",
39365
+ args: [userAddress]
39366
+ });
39367
+ return [...permissionIds];
39368
+ } catch (error) {
39369
+ throw new BlockchainError(
39370
+ `Failed to get user permission IDs: ${error instanceof Error ? error.message : "Unknown error"}`,
39371
+ error
39372
+ );
39373
+ }
39374
+ }
39375
+ /**
39376
+ * Get permission ID at specific index for a user
39377
+ *
39378
+ * @param userAddress - User address
39379
+ * @param permissionIndex - Index of the permission ID
39380
+ * @returns Promise resolving to permission ID
39381
+ */
39382
+ async getUserPermissionIdsAt(userAddress, permissionIndex) {
39383
+ try {
39384
+ const chainId = await this.context.publicClient.getChainId();
39385
+ const DataPortabilityPermissionsAddress = getContractAddress(
39386
+ chainId,
39387
+ "DataPortabilityPermissions"
39388
+ );
39389
+ const DataPortabilityPermissionsAbi = getAbi(
39390
+ "DataPortabilityPermissions"
39391
+ );
39392
+ const permissionId = await this.context.publicClient.readContract({
39393
+ address: DataPortabilityPermissionsAddress,
39394
+ abi: DataPortabilityPermissionsAbi,
39395
+ functionName: "userPermissionIdsAt",
39396
+ args: [userAddress, permissionIndex]
39397
+ });
39398
+ return permissionId;
39399
+ } catch (error) {
39400
+ throw new BlockchainError(
39401
+ `Failed to get user permission ID at index: ${error instanceof Error ? error.message : "Unknown error"}`,
39402
+ error
39403
+ );
39404
+ }
39405
+ }
39406
+ /**
39407
+ * Get the number of permissions a user has
39408
+ *
39409
+ * @param userAddress - User address
39410
+ * @returns Promise resolving to number of permissions
39411
+ */
39412
+ async getUserPermissionIdsLength(userAddress) {
39413
+ try {
39414
+ const chainId = await this.context.publicClient.getChainId();
39415
+ const DataPortabilityPermissionsAddress = getContractAddress(
39416
+ chainId,
39417
+ "DataPortabilityPermissions"
39418
+ );
39419
+ const DataPortabilityPermissionsAbi = getAbi(
39420
+ "DataPortabilityPermissions"
39421
+ );
39422
+ const length = await this.context.publicClient.readContract({
39423
+ address: DataPortabilityPermissionsAddress,
39424
+ abi: DataPortabilityPermissionsAbi,
39425
+ functionName: "userPermissionIdsLength",
39426
+ args: [userAddress]
39427
+ });
39428
+ return length;
39429
+ } catch (error) {
39430
+ throw new BlockchainError(
39431
+ `Failed to get user permission IDs length: ${error instanceof Error ? error.message : "Unknown error"}`,
39432
+ error
39433
+ );
39434
+ }
39435
+ }
39436
+ /**
39437
+ * Get permission info by permission ID
39438
+ *
39439
+ * @param permissionId - Permission ID
39440
+ * @returns Promise resolving to permission info
39441
+ */
39442
+ async getPermissions(permissionId) {
39443
+ try {
39444
+ const chainId = await this.context.publicClient.getChainId();
39445
+ const DataPortabilityPermissionsAddress = getContractAddress(
39446
+ chainId,
39447
+ "DataPortabilityPermissions"
39448
+ );
39449
+ const DataPortabilityPermissionsAbi = getAbi(
39450
+ "DataPortabilityPermissions"
39451
+ );
39452
+ const permissionInfo = await this.context.publicClient.readContract({
39453
+ address: DataPortabilityPermissionsAddress,
39454
+ abi: DataPortabilityPermissionsAbi,
39455
+ functionName: "permissions",
39456
+ args: [permissionId]
39457
+ });
39458
+ return {
39459
+ id: permissionInfo.id,
39460
+ grantor: permissionInfo.grantor,
39461
+ nonce: permissionInfo.nonce,
39462
+ granteeId: permissionInfo.granteeId,
39463
+ grant: permissionInfo.grant,
39464
+ startBlock: permissionInfo.startBlock,
39465
+ endBlock: permissionInfo.endBlock,
39466
+ fileIds: [...permissionInfo.fileIds]
39467
+ };
39468
+ } catch (error) {
39469
+ throw new BlockchainError(
39470
+ `Failed to get permission info: ${error instanceof Error ? error.message : "Unknown error"}`,
39471
+ error
39472
+ );
39473
+ }
39474
+ }
39475
+ /**
39476
+ * Submit permission with signature to the blockchain (supports gasless transactions)
39477
+ *
39478
+ * @param params - Parameters for adding permission
39479
+ * @returns Promise resolving to transaction hash
39480
+ * @throws {RelayerError} When gasless transaction submission fails
39481
+ * @throws {SignatureError} When user rejects the signature request
39482
+ * @throws {BlockchainError} When permission addition fails
39483
+ * @throws {NetworkError} When network communication fails
39484
+ */
39485
+ async submitAddPermission(params) {
39486
+ try {
39487
+ const nonce = await this.getPermissionsUserNonce();
39488
+ const addPermissionInput = {
39489
+ nonce,
39490
+ granteeId: params.granteeId,
39491
+ grant: params.grant,
39492
+ fileUrls: params.fileUrls,
39493
+ serverAddress: params.serverAddress,
39494
+ serverUrl: params.serverUrl,
39495
+ serverPublicKey: params.serverPublicKey,
39496
+ filePermissions: params.filePermissions
39497
+ };
39498
+ const typedData = await this.composeServerFilesAndPermissionMessage(addPermissionInput);
39499
+ const signature = await this.signTypedData(typedData);
39500
+ return await this.submitSignedAddPermission(typedData, signature);
39501
+ } catch (error) {
39502
+ if (error instanceof RelayerError || error instanceof UserRejectedRequestError || error instanceof SerializationError || error instanceof SignatureError || error instanceof NetworkError || error instanceof NonceError) {
39503
+ throw error;
39504
+ }
39505
+ throw new BlockchainError(
39506
+ `Failed to add permission: ${error instanceof Error ? error.message : "Unknown error"}`,
39507
+ error
39508
+ );
39509
+ }
39510
+ }
39511
+ /**
39512
+ * Submits an already-signed add permission transaction to the blockchain.
39513
+ * This method supports both relayer-based gasless transactions and direct transactions.
39514
+ *
39515
+ * @param typedData - The EIP-712 typed data for AddPermission
39516
+ * @param signature - The user's signature
39517
+ * @returns Promise resolving to the transaction hash
39518
+ * @throws {RelayerError} When gasless transaction submission fails
39519
+ * @throws {BlockchainError} When permission addition fails
39520
+ * @throws {NetworkError} When network communication fails
39521
+ */
39522
+ async submitSignedAddPermission(typedData, signature) {
39523
+ try {
39524
+ if (this.context.relayerCallbacks?.submitAddPermission) {
39525
+ return await this.context.relayerCallbacks.submitAddPermission(
39526
+ typedData,
39527
+ signature
39528
+ );
39529
+ } else {
39530
+ return await this.submitDirectAddPermissionTransaction(
39531
+ typedData,
39532
+ signature
39533
+ );
39534
+ }
39535
+ } catch (error) {
39536
+ if (error instanceof RelayerError || error instanceof NetworkError || error instanceof UserRejectedRequestError || error instanceof SignatureError || error instanceof NonceError) {
39537
+ throw error;
39538
+ }
39539
+ throw new BlockchainError(
39540
+ `Add permission submission failed: ${error instanceof Error ? error.message : "Unknown error"}`,
39541
+ error
39542
+ );
39543
+ }
39544
+ }
39545
+ /**
39546
+ * Submit server files and permissions with signature to the blockchain (supports gasless transactions)
39547
+ *
39548
+ * @param params - Parameters for adding server files and permissions
39549
+ * @returns Promise resolving to transaction hash
39550
+ * @throws {RelayerError} When gasless transaction submission fails
39551
+ * @throws {SignatureError} When user rejects the signature request
39552
+ * @throws {BlockchainError} When server files and permissions addition fails
39553
+ * @throws {NetworkError} When network communication fails
39554
+ */
39555
+ async submitAddServerFilesAndPermissions(params) {
39556
+ try {
39557
+ const nonce = await this.getPermissionsUserNonce();
39558
+ const serverFilesAndPermissionInput = {
39559
+ nonce,
39560
+ granteeId: params.granteeId,
39561
+ grant: params.grant,
39562
+ fileUrls: params.fileUrls,
39563
+ serverAddress: params.serverAddress,
39564
+ serverUrl: params.serverUrl,
39565
+ serverPublicKey: params.serverPublicKey,
39566
+ filePermissions: params.filePermissions
39567
+ };
39568
+ const typedData = await this.composeServerFilesAndPermissionMessage(
39569
+ serverFilesAndPermissionInput
39570
+ );
39571
+ const signature = await this.signTypedData(typedData);
39572
+ return await this.submitSignedAddServerFilesAndPermissions(
39573
+ typedData,
39574
+ signature
39575
+ );
39576
+ } catch (error) {
39577
+ if (error instanceof RelayerError || error instanceof UserRejectedRequestError || error instanceof SerializationError || error instanceof SignatureError || error instanceof NetworkError || error instanceof NonceError) {
39578
+ throw error;
39579
+ }
39580
+ throw new BlockchainError(
39581
+ `Failed to add server files and permissions: ${error instanceof Error ? error.message : "Unknown error"}`,
39582
+ error
39583
+ );
39584
+ }
39585
+ }
39586
+ /**
39587
+ * Submits an already-signed add server files and permissions transaction to the blockchain.
39588
+ * This method supports both relayer-based gasless transactions and direct transactions.
39589
+ *
39590
+ * @param typedData - The EIP-712 typed data for AddServerFilesAndPermissions
39591
+ * @param signature - The user's signature
39592
+ * @returns Promise resolving to the transaction hash
39593
+ * @throws {RelayerError} When gasless transaction submission fails
39594
+ * @throws {BlockchainError} When server files and permissions addition fails
39595
+ * @throws {NetworkError} When network communication fails
39596
+ */
39597
+ async submitSignedAddServerFilesAndPermissions(typedData, signature) {
39598
+ try {
39599
+ console.debug("\u{1F50D} submitSignedAddServerFilesAndPermissions Debug Info:", {
39600
+ hasRelayerCallbacks: !!this.context.relayerCallbacks,
39601
+ hasSubmitMethod: !!this.context.relayerCallbacks?.submitAddServerFilesAndPermissions,
39602
+ availableRelayerMethods: this.context.relayerCallbacks ? Object.keys(this.context.relayerCallbacks) : []
39603
+ });
39604
+ if (this.context.relayerCallbacks?.submitAddServerFilesAndPermissions) {
39605
+ console.debug(
39606
+ "\u{1F680} Using relayer for submitAddServerFilesAndPermissions"
39607
+ );
39608
+ return await this.context.relayerCallbacks.submitAddServerFilesAndPermissions(
39609
+ typedData,
39610
+ signature
39611
+ );
39612
+ } else {
39613
+ console.debug(
39614
+ "\u{1F4DD} Using direct transaction for submitAddServerFilesAndPermissions"
39615
+ );
39616
+ return await this.submitDirectAddServerFilesAndPermissionsTransaction(
39617
+ typedData,
39618
+ signature
39619
+ );
39620
+ }
39621
+ } catch (error) {
39622
+ if (error instanceof RelayerError || error instanceof NetworkError || error instanceof UserRejectedRequestError || error instanceof SignatureError || error instanceof NonceError) {
39623
+ throw error;
39624
+ }
39625
+ throw new BlockchainError(
39626
+ `Add server files and permissions submission failed: ${error instanceof Error ? error.message : "Unknown error"}`,
39627
+ error
39628
+ );
39629
+ }
39630
+ }
39631
+ /**
39632
+ * Submit permission revocation with signature to the blockchain
39633
+ *
39634
+ * @param permissionId - Permission ID to revoke
39635
+ * @returns Promise resolving to transaction hash
39636
+ */
39637
+ async submitRevokePermission(permissionId) {
39638
+ try {
39639
+ const chainId = await this.context.walletClient.getChainId();
39640
+ const DataPortabilityPermissionsAddress = getContractAddress(
39641
+ chainId,
39642
+ "DataPortabilityPermissions"
39643
+ );
39644
+ const DataPortabilityPermissionsAbi = getAbi(
39645
+ "DataPortabilityPermissions"
39646
+ );
39647
+ const hash = await this.context.walletClient.writeContract({
39648
+ address: DataPortabilityPermissionsAddress,
39649
+ abi: DataPortabilityPermissionsAbi,
39650
+ functionName: "revokePermission",
39651
+ args: [permissionId],
39652
+ chain: this.context.walletClient.chain,
39653
+ account: this.context.walletClient.account || null
39654
+ });
39655
+ return hash;
39656
+ } catch (error) {
39657
+ throw new BlockchainError(
39658
+ `Failed to revoke permission: ${error instanceof Error ? error.message : "Unknown error"}`,
39659
+ error
39660
+ );
39661
+ }
39662
+ }
39663
+ /**
39664
+ * Submits a signed add permission transaction directly to the blockchain.
39665
+ *
39666
+ * @param typedData - The typed data structure for the permission addition
39667
+ * @param signature - The cryptographic signature authorizing the transaction
39668
+ * @returns Promise resolving to the transaction hash
39669
+ */
39670
+ async submitDirectAddPermissionTransaction(typedData, signature) {
39671
+ const chainId = await this.context.walletClient.getChainId();
39672
+ const DataPortabilityPermissionsAddress = getContractAddress(
39673
+ chainId,
39674
+ "DataPortabilityPermissions"
39675
+ );
39676
+ const DataPortabilityPermissionsAbi = getAbi("DataPortabilityPermissions");
39677
+ const permissionInput = {
39678
+ nonce: typedData.message.nonce,
39679
+ granteeId: typedData.message.granteeId,
39680
+ grant: typedData.message.grant,
39681
+ fileIds: typedData.message.fileIds || []
39682
+ };
39683
+ const formattedSignature = formatSignatureForContract(signature);
39684
+ const hash = await this.context.walletClient.writeContract({
39685
+ address: DataPortabilityPermissionsAddress,
39686
+ abi: DataPortabilityPermissionsAbi,
39687
+ functionName: "addPermission",
39688
+ args: [permissionInput, formattedSignature],
39689
+ account: this.context.walletClient.account || await this.getUserAddress(),
39690
+ chain: this.context.walletClient.chain || null
39691
+ });
39692
+ return hash;
39693
+ }
39694
+ /**
39695
+ * Submits a signed add server files and permissions transaction directly to the blockchain.
39696
+ *
39697
+ * @param typedData - The typed data structure for the server files and permissions addition
39698
+ * @param signature - The cryptographic signature authorizing the transaction
39699
+ * @returns Promise resolving to the transaction hash
39700
+ */
39701
+ async submitDirectAddServerFilesAndPermissionsTransaction(typedData, signature) {
39702
+ const chainId = await this.context.walletClient.getChainId();
39703
+ const DataPortabilityPermissionsAddress = getContractAddress(
39704
+ chainId,
39705
+ "DataPortabilityPermissions"
39706
+ );
39707
+ const DataPortabilityPermissionsAbi = getAbi("DataPortabilityPermissions");
39708
+ const serverFilesAndPermissionInput = {
39709
+ nonce: typedData.message.nonce,
39710
+ granteeId: typedData.message.granteeId,
39711
+ grant: typedData.message.grant,
39712
+ fileUrls: typedData.message.fileUrls,
39713
+ serverAddress: typedData.message.serverAddress,
39714
+ serverUrl: typedData.message.serverUrl,
39715
+ serverPublicKey: typedData.message.serverPublicKey,
39716
+ filePermissions: typedData.message.filePermissions
39717
+ };
39718
+ const formattedSignature = formatSignatureForContract(signature);
39719
+ const hash = await this.context.walletClient.writeContract({
39720
+ address: DataPortabilityPermissionsAddress,
39721
+ abi: DataPortabilityPermissionsAbi,
39722
+ functionName: "addServerFilesAndPermissions",
39723
+ // @ts-expect-error - Complex nested array types cause compatibility issues with viem's generated types
39724
+ args: [serverFilesAndPermissionInput, formattedSignature],
39725
+ account: this.context.walletClient.account || await this.getUserAddress(),
39726
+ chain: this.context.walletClient.chain || null
39727
+ });
39728
+ return hash;
39729
+ }
38516
39730
  };
38517
39731
 
38518
39732
  // src/controllers/data.ts
38519
- import { getContract, decodeEventLog } from "viem";
39733
+ import { getContract as getContract2, decodeEventLog } from "viem";
39734
+
39735
+ // src/utils/blockchain/registry.ts
39736
+ import { getContract } from "viem";
39737
+ async function fetchSchemaFromChain(context, schemaId) {
39738
+ const chainId = context.walletClient.chain?.id;
39739
+ if (!chainId) {
39740
+ throw new Error("Chain ID not available");
39741
+ }
39742
+ const dataRefinerRegistryAddress = getContractAddress(
39743
+ chainId,
39744
+ "DataRefinerRegistry"
39745
+ );
39746
+ const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
39747
+ const dataRefinerRegistry = getContract({
39748
+ address: dataRefinerRegistryAddress,
39749
+ abi: dataRefinerRegistryAbi,
39750
+ client: context.publicClient
39751
+ });
39752
+ const schemaData = await dataRefinerRegistry.read.schemas([BigInt(schemaId)]);
39753
+ if (!schemaData) {
39754
+ throw new Error(`Schema with ID ${schemaId} not found`);
39755
+ }
39756
+ const schemaObj = schemaData;
39757
+ if (!schemaObj.name || !schemaObj.typ || !schemaObj.definitionUrl) {
39758
+ throw new Error("Incomplete schema data");
39759
+ }
39760
+ return {
39761
+ id: schemaId,
39762
+ name: schemaObj.name,
39763
+ type: schemaObj.typ,
39764
+ definitionUrl: schemaObj.definitionUrl
39765
+ };
39766
+ }
39767
+ async function fetchSchemaCountFromChain(context) {
39768
+ const chainId = context.walletClient.chain?.id;
39769
+ if (!chainId) {
39770
+ throw new Error("Chain ID not available");
39771
+ }
39772
+ const dataRefinerRegistryAddress = getContractAddress(
39773
+ chainId,
39774
+ "DataRefinerRegistry"
39775
+ );
39776
+ const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
39777
+ const dataRefinerRegistry = getContract({
39778
+ address: dataRefinerRegistryAddress,
39779
+ abi: dataRefinerRegistryAbi,
39780
+ client: context.publicClient
39781
+ });
39782
+ const count = await dataRefinerRegistry.read.schemasCount();
39783
+ return Number(count);
39784
+ }
38520
39785
 
38521
39786
  // src/utils/encryption.ts
38522
39787
  var DEFAULT_ENCRYPTION_SEED = "Please sign to retrieve your encryption key";
@@ -38598,7 +39863,11 @@ async function encryptBlobWithSignedKey(data, key, platformAdapter) {
38598
39863
  dataArray,
38599
39864
  key
38600
39865
  );
38601
- return new Blob([encrypted], {
39866
+ const encryptedArrayBuffer = encrypted.buffer.slice(
39867
+ encrypted.byteOffset,
39868
+ encrypted.byteOffset + encrypted.byteLength
39869
+ );
39870
+ return new Blob([encryptedArrayBuffer], {
38602
39871
  type: "application/octet-stream"
38603
39872
  });
38604
39873
  } catch (error) {
@@ -38627,7 +39896,11 @@ async function decryptBlobWithSignedKey(encryptedData, key, platformAdapter) {
38627
39896
  encryptedArray,
38628
39897
  key
38629
39898
  );
38630
- return new Blob([decrypted], { type: "text/plain" });
39899
+ const decryptedArrayBuffer = decrypted.buffer.slice(
39900
+ decrypted.byteOffset,
39901
+ decrypted.byteOffset + decrypted.byteLength
39902
+ );
39903
+ return new Blob([decryptedArrayBuffer], { type: "text/plain" });
38631
39904
  } catch (error) {
38632
39905
  throw new Error(`Failed to decrypt data: ${error}`);
38633
39906
  }
@@ -38644,28 +39917,16 @@ var DataController = class {
38644
39917
  filename,
38645
39918
  schemaId,
38646
39919
  permissions = [],
38647
- encrypt: encrypt3 = true,
39920
+ encrypt = true,
38648
39921
  providerName,
38649
39922
  owner
38650
39923
  } = params;
38651
39924
  try {
38652
- let blob;
38653
- if (content instanceof Blob) {
38654
- blob = content;
38655
- } else if (typeof content === "string") {
38656
- blob = new Blob([content], { type: "text/plain" });
38657
- } else if (content instanceof Buffer) {
38658
- blob = new Blob([content], { type: "application/octet-stream" });
38659
- } else {
38660
- blob = new Blob([JSON.stringify(content)], {
38661
- type: "application/json"
38662
- });
38663
- }
38664
39925
  let isValid = true;
38665
39926
  let validationErrors = [];
38666
39927
  if (schemaId !== void 0) {
38667
39928
  try {
38668
- const schema = await this.getSchema(schemaId);
39929
+ const schema = await fetchSchemaFromChain(this.context, schemaId);
38669
39930
  const response = await fetch(schema.definitionUrl);
38670
39931
  if (!response.ok) {
38671
39932
  throw new Error(
@@ -38697,37 +39958,15 @@ var DataController = class {
38697
39958
  ];
38698
39959
  }
38699
39960
  }
38700
- let finalBlob = blob;
38701
- if (encrypt3) {
38702
- const encryptionKey = await generateEncryptionKey(
38703
- this.context.walletClient,
38704
- this.context.platform,
38705
- DEFAULT_ENCRYPTION_SEED
38706
- );
38707
- finalBlob = await encryptBlobWithSignedKey(
38708
- blob,
38709
- encryptionKey,
38710
- this.context.platform
38711
- );
38712
- }
38713
- if (!this.context.storageManager) {
38714
- if (this.context.validateStorageRequired) {
38715
- this.context.validateStorageRequired();
38716
- throw new Error("Storage validation failed");
38717
- } else {
38718
- throw new Error(
38719
- "Storage manager not configured. Please provide storage providers in VanaConfig."
38720
- );
38721
- }
38722
- }
38723
- const uploadResult = await this.context.storageManager.upload(
38724
- finalBlob,
39961
+ const uploadResult = await this.uploadToStorage(
39962
+ content,
38725
39963
  filename,
39964
+ encrypt,
38726
39965
  providerName
38727
39966
  );
38728
39967
  const userAddress = owner || await this.getUserAddress();
38729
39968
  let encryptedPermissions = [];
38730
- if (permissions.length > 0) {
39969
+ if (permissions.length > 0 && encrypt) {
38731
39970
  const userEncryptionKey = await generateEncryptionKey(
38732
39971
  this.context.walletClient,
38733
39972
  this.context.platform,
@@ -39445,7 +40684,7 @@ var DataController = class {
39445
40684
  }
39446
40685
  const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
39447
40686
  const dataRegistryAbi = getAbi("DataRegistry");
39448
- const dataRegistry = getContract({
40687
+ const dataRegistry = getContract2({
39449
40688
  address: dataRegistryAddress,
39450
40689
  abi: dataRegistryAbi,
39451
40690
  client: this.context.walletClient
@@ -39496,7 +40735,7 @@ var DataController = class {
39496
40735
  }
39497
40736
  const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
39498
40737
  const dataRegistryAbi = getAbi("DataRegistry");
39499
- const dataRegistry = getContract({
40738
+ const dataRegistry = getContract2({
39500
40739
  address: dataRegistryAddress,
39501
40740
  abi: dataRegistryAbi,
39502
40741
  client: this.context.walletClient
@@ -39534,205 +40773,6 @@ var DataController = class {
39534
40773
  );
39535
40774
  }
39536
40775
  }
39537
- /**
39538
- * Uploads an encrypted file to storage and registers it on the blockchain.
39539
- *
39540
- * @deprecated Since v2.0.0 - Use vana.data.upload() instead for the high-level API with automatic encryption
39541
- *
39542
- * Migration guide:
39543
- * ```typescript
39544
- * // Old way (deprecated):
39545
- * const encrypted = await encryptBlob(data, key);
39546
- * const result = await vana.data.uploadEncryptedFile(encrypted, filename);
39547
- *
39548
- * // New way:
39549
- * const result = await vana.data.upload({
39550
- * content: data,
39551
- * filename: filename,
39552
- * encrypt: true // Handles encryption automatically
39553
- * });
39554
- * ```
39555
- * @param encryptedFile - The encrypted file blob to upload
39556
- * @param filename - Optional filename for the upload
39557
- * @param providerName - Optional storage provider to use
39558
- * @returns Promise resolving to upload result with file ID and storage URL
39559
- *
39560
- * This method handles the complete flow of:
39561
- * 1. Uploading the encrypted file to the specified storage provider
39562
- * 2. Registering the file URL on the DataRegistry contract via relayer
39563
- * 3. Returning the assigned file ID and storage URL
39564
- */
39565
- async uploadEncryptedFile(encryptedFile, filename, providerName) {
39566
- try {
39567
- if (!this.context.storageManager) {
39568
- throw new Error(
39569
- "Storage manager not configured. Please provide storage providers in VanaConfig."
39570
- );
39571
- }
39572
- const uploadResult = await this.context.storageManager.upload(
39573
- encryptedFile,
39574
- filename,
39575
- providerName
39576
- );
39577
- const userAddress = await this.getUserAddress();
39578
- if (this.context.relayerCallbacks?.submitFileAddition) {
39579
- const result = await this.context.relayerCallbacks.submitFileAddition(
39580
- uploadResult.url,
39581
- userAddress
39582
- );
39583
- return {
39584
- fileId: result.fileId,
39585
- url: uploadResult.url,
39586
- size: uploadResult.size,
39587
- transactionHash: result.transactionHash
39588
- };
39589
- } else {
39590
- const chainId = this.context.walletClient.chain?.id;
39591
- if (!chainId) {
39592
- throw new Error("Chain ID not available");
39593
- }
39594
- const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
39595
- const dataRegistryAbi = getAbi("DataRegistry");
39596
- const txHash = await this.context.walletClient.writeContract({
39597
- address: dataRegistryAddress,
39598
- abi: dataRegistryAbi,
39599
- functionName: "addFile",
39600
- args: [uploadResult.url],
39601
- account: this.context.walletClient.account || userAddress,
39602
- chain: this.context.walletClient.chain || null
39603
- });
39604
- const receipt = await this.context.publicClient.waitForTransactionReceipt({
39605
- hash: txHash,
39606
- timeout: 3e4
39607
- // 30 seconds timeout
39608
- });
39609
- let fileId = 0;
39610
- for (const log of receipt.logs) {
39611
- try {
39612
- const decoded = decodeEventLog({
39613
- abi: dataRegistryAbi,
39614
- data: log.data,
39615
- topics: log.topics
39616
- });
39617
- if (decoded.eventName === "FileAdded") {
39618
- fileId = Number(decoded.args.fileId);
39619
- break;
39620
- }
39621
- } catch {
39622
- continue;
39623
- }
39624
- }
39625
- return {
39626
- fileId,
39627
- url: uploadResult.url,
39628
- size: uploadResult.size,
39629
- transactionHash: txHash
39630
- };
39631
- }
39632
- } catch (error) {
39633
- console.error("Failed to upload encrypted file:", error);
39634
- throw new Error(
39635
- `Upload failed: ${error instanceof Error ? error.message : "Unknown error"}`
39636
- );
39637
- }
39638
- }
39639
- /**
39640
- * Uploads an encrypted file to storage and registers it on the blockchain with a schema.
39641
- *
39642
- * @deprecated Since v2.0.0 - Use vana.data.upload() instead for the high-level API with automatic encryption and schema validation
39643
- *
39644
- * Migration guide:
39645
- * ```typescript
39646
- * // Old way (deprecated):
39647
- * const encrypted = await encryptBlob(data, key);
39648
- * const result = await vana.data.uploadEncryptedFileWithSchema(encrypted, schemaId, filename);
39649
- *
39650
- * // New way:
39651
- * const result = await vana.data.upload({
39652
- * content: data,
39653
- * filename: filename,
39654
- * schemaId: schemaId, // Automatic validation
39655
- * encrypt: true
39656
- * });
39657
- * ```
39658
- * @param encryptedFile - The encrypted file blob to upload
39659
- * @param schemaId - The schema ID to associate with the file
39660
- * @param filename - Optional filename for the upload
39661
- * @param providerName - Optional storage provider to use
39662
- * @returns Promise resolving to upload result with file ID and storage URL
39663
- *
39664
- * This method handles the complete flow of:
39665
- * 1. Uploading the encrypted file to the specified storage provider
39666
- * 2. Registering the file URL on the DataRegistry contract with a schema ID
39667
- * 3. Returning the assigned file ID and storage URL
39668
- */
39669
- async uploadEncryptedFileWithSchema(encryptedFile, schemaId, filename, providerName) {
39670
- try {
39671
- if (!this.context.storageManager) {
39672
- throw new Error(
39673
- "Storage manager not configured. Please provide storage providers in VanaConfig."
39674
- );
39675
- }
39676
- const uploadResult = await this.context.storageManager.upload(
39677
- encryptedFile,
39678
- filename,
39679
- providerName
39680
- );
39681
- const userAddress = await this.getUserAddress();
39682
- if (this.context.relayerCallbacks?.submitFileAddition) {
39683
- throw new Error(
39684
- "Relayer does not yet support uploading files with schema. Please use direct transaction mode."
39685
- );
39686
- } else {
39687
- const chainId = this.context.walletClient.chain?.id;
39688
- if (!chainId) {
39689
- throw new Error("Chain ID not available");
39690
- }
39691
- const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
39692
- const dataRegistryAbi = getAbi("DataRegistry");
39693
- const txHash = await this.context.walletClient.writeContract({
39694
- address: dataRegistryAddress,
39695
- abi: dataRegistryAbi,
39696
- functionName: "addFileWithSchema",
39697
- args: [uploadResult.url, BigInt(schemaId)],
39698
- account: this.context.walletClient.account || userAddress,
39699
- chain: this.context.walletClient.chain || null
39700
- });
39701
- const receipt = await this.context.publicClient.waitForTransactionReceipt({
39702
- hash: txHash,
39703
- timeout: 3e4
39704
- // 30 seconds timeout
39705
- });
39706
- let fileId = 0;
39707
- for (const log of receipt.logs) {
39708
- try {
39709
- const decoded = decodeEventLog({
39710
- abi: dataRegistryAbi,
39711
- data: log.data,
39712
- topics: log.topics
39713
- });
39714
- if (decoded.eventName === "FileAdded") {
39715
- fileId = Number(decoded.args.fileId);
39716
- break;
39717
- }
39718
- } catch {
39719
- continue;
39720
- }
39721
- }
39722
- return {
39723
- fileId,
39724
- url: uploadResult.url,
39725
- size: uploadResult.size,
39726
- transactionHash: txHash
39727
- };
39728
- }
39729
- } catch (error) {
39730
- console.error("Failed to upload encrypted file with schema:", error);
39731
- throw new Error(
39732
- `Upload failed: ${error instanceof Error ? error.message : "Unknown error"}`
39733
- );
39734
- }
39735
- }
39736
40776
  /**
39737
40777
  * Registers a file URL directly on the blockchain with a schema ID.
39738
40778
  *
@@ -39787,106 +40827,42 @@ var DataController = class {
39787
40827
  transactionHash: txHash
39788
40828
  };
39789
40829
  } catch (error) {
39790
- console.error("Failed to register file with schema:", error);
39791
- throw new Error(
39792
- `Registration failed: ${error instanceof Error ? error.message : "Unknown error"}`
39793
- );
39794
- }
39795
- }
39796
- /**
39797
- * Gets the user's address from the wallet client.
39798
- *
39799
- * @returns Promise resolving to the user's wallet address
39800
- * @throws {Error} When no addresses are available in wallet client
39801
- */
39802
- async getUserAddress() {
39803
- const addresses = await this.context.walletClient.getAddresses();
39804
- if (addresses.length === 0) {
39805
- throw new Error("No addresses available in wallet client");
39806
- }
39807
- return addresses[0];
39808
- }
39809
- /**
39810
- * Adds a file with permissions to the DataRegistry contract.
39811
- *
39812
- * @param url - The file URL to register
39813
- * @param ownerAddress - The address of the file owner
39814
- * @param permissions - Array of permissions to set for the file
39815
- * @returns Promise resolving to file ID and transaction hash
39816
- * @throws {Error} When chain ID is not available
39817
- * @throws {ContractError} When contract execution fails
39818
- * @throws {Error} When transaction receipt is not available
39819
- * @throws {Error} When FileAdded event cannot be parsed
39820
- *
39821
- * This method handles the core logic of registering a file
39822
- * with specific permissions on the DataRegistry contract. It can be used
39823
- * by both direct transactions and relayer services.
39824
- */
39825
- async addFileWithPermissions(url, ownerAddress, permissions = []) {
39826
- try {
39827
- const chainId = this.context.walletClient.chain?.id;
39828
- if (!chainId) {
39829
- throw new Error("Chain ID not available");
39830
- }
39831
- const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
39832
- const dataRegistryAbi = getAbi("DataRegistry");
39833
- const txHash = await this.context.walletClient.writeContract({
39834
- address: dataRegistryAddress,
39835
- abi: dataRegistryAbi,
39836
- functionName: "addFileWithPermissions",
39837
- args: [url, ownerAddress, permissions],
39838
- account: this.context.walletClient.account || ownerAddress,
39839
- chain: this.context.walletClient.chain || null
39840
- });
39841
- const receipt = await this.context.publicClient.waitForTransactionReceipt(
39842
- {
39843
- hash: txHash,
39844
- timeout: 3e4
39845
- // 30 seconds timeout
39846
- }
39847
- );
39848
- let fileId = 0;
39849
- for (const log of receipt.logs) {
39850
- try {
39851
- const decoded = decodeEventLog({
39852
- abi: dataRegistryAbi,
39853
- data: log.data,
39854
- topics: log.topics
39855
- });
39856
- if (decoded.eventName === "FileAdded") {
39857
- fileId = Number(decoded.args.fileId);
39858
- break;
39859
- }
39860
- } catch {
39861
- continue;
39862
- }
39863
- }
39864
- return {
39865
- fileId,
39866
- transactionHash: txHash
39867
- };
39868
- } catch (error) {
39869
- console.error("Failed to add file with permissions:", error);
40830
+ console.error("Failed to register file with schema:", error);
39870
40831
  throw new Error(
39871
- `Failed to add file with permissions: ${error instanceof Error ? error.message : "Unknown error"}`
40832
+ `Registration failed: ${error instanceof Error ? error.message : "Unknown error"}`
39872
40833
  );
39873
40834
  }
39874
40835
  }
39875
40836
  /**
39876
- * Adds a file to the registry with permissions and schema.
39877
- * This combines the functionality of addFileWithPermissions and schema validation.
40837
+ * Gets the user's address from the wallet client.
39878
40838
  *
39879
- * @param url - The URL of the file to register
40839
+ * @returns Promise resolving to the user's wallet address
40840
+ * @throws {Error} When no addresses are available in wallet client
40841
+ */
40842
+ async getUserAddress() {
40843
+ const addresses = await this.context.walletClient.getAddresses();
40844
+ if (addresses.length === 0) {
40845
+ throw new Error("No addresses available in wallet client");
40846
+ }
40847
+ return addresses[0];
40848
+ }
40849
+ /**
40850
+ * Adds a file with permissions to the DataRegistry contract.
40851
+ *
40852
+ * @param url - The file URL to register
39880
40853
  * @param ownerAddress - The address of the file owner
39881
- * @param permissions - Array of permissions to grant (account and encrypted key)
39882
- * @param schemaId - The schema ID to associate with the file (0 for no schema)
39883
- * @returns Promise resolving to object with fileId and transactionHash
40854
+ * @param permissions - Array of permissions to set for the file
40855
+ * @returns Promise resolving to file ID and transaction hash
39884
40856
  * @throws {Error} When chain ID is not available
39885
40857
  * @throws {ContractError} When contract execution fails
39886
40858
  * @throws {Error} When transaction receipt is not available
39887
40859
  * @throws {Error} When FileAdded event cannot be parsed
40860
+ *
40861
+ * This method handles the core logic of registering a file
40862
+ * with specific permissions on the DataRegistry contract. It can be used
40863
+ * by both direct transactions and relayer services.
39888
40864
  */
39889
- async addFileWithPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0) {
40865
+ async addFileWithPermissions(url, ownerAddress, permissions = []) {
39890
40866
  try {
39891
40867
  const chainId = this.context.walletClient.chain?.id;
39892
40868
  if (!chainId) {
@@ -39897,8 +40873,8 @@ var DataController = class {
39897
40873
  const txHash = await this.context.walletClient.writeContract({
39898
40874
  address: dataRegistryAddress,
39899
40875
  abi: dataRegistryAbi,
39900
- functionName: "addFileWithPermissionsAndSchema",
39901
- args: [url, ownerAddress, permissions, BigInt(schemaId)],
40876
+ functionName: "addFileWithPermissions",
40877
+ args: [url, ownerAddress, permissions],
39902
40878
  account: this.context.walletClient.account || ownerAddress,
39903
40879
  chain: this.context.walletClient.chain || null
39904
40880
  });
@@ -39930,71 +40906,59 @@ var DataController = class {
39930
40906
  transactionHash: txHash
39931
40907
  };
39932
40908
  } catch (error) {
39933
- console.error("Failed to add file with permissions and schema:", error);
40909
+ console.error("Failed to add file with permissions:", error);
39934
40910
  throw new Error(
39935
- `Failed to add file with permissions and schema: ${error instanceof Error ? error.message : "Unknown error"}`
40911
+ `Failed to add file with permissions: ${error instanceof Error ? error.message : "Unknown error"}`
39936
40912
  );
39937
40913
  }
39938
40914
  }
39939
40915
  /**
39940
- * Adds a new schema to the DataRefinerRegistry.
39941
- *
39942
- * @deprecated Since v2.0.0 - Use vana.schemas.create() instead for the high-level API with automatic IPFS upload
39943
- *
39944
- * Migration guide:
39945
- * ```typescript
39946
- * // Old way (deprecated):
39947
- * const result = await vana.data.addSchema({
39948
- * name: "UserProfile",
39949
- * type: "JSON",
39950
- * definitionUrl: "ipfs://..."
39951
- * });
40916
+ * Adds a file to the registry with permissions and schema.
40917
+ * This combines the functionality of addFileWithPermissions and schema validation.
39952
40918
  *
39953
- * // New way:
39954
- * const result = await vana.schemas.create({
39955
- * name: "UserProfile",
39956
- * type: "JSON",
39957
- * definition: schemaObject // Automatically uploads to IPFS
39958
- * });
39959
- * ```
39960
- * @param params - Schema parameters including name, type, and definition URL
39961
- * @returns Promise resolving to the new schema ID and transaction hash
40919
+ * @param url - The URL of the file to register
40920
+ * @param ownerAddress - The address of the file owner
40921
+ * @param permissions - Array of permissions to grant (account and encrypted key)
40922
+ * @param schemaId - The schema ID to associate with the file (0 for no schema)
40923
+ * @returns Promise resolving to object with fileId and transactionHash
40924
+ * @throws {Error} When chain ID is not available
40925
+ * @throws {ContractError} When contract execution fails
40926
+ * @throws {Error} When transaction receipt is not available
40927
+ * @throws {Error} When FileAdded event cannot be parsed
39962
40928
  */
39963
- async addSchema(params) {
40929
+ async addFileWithPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0) {
39964
40930
  try {
39965
40931
  const chainId = this.context.walletClient.chain?.id;
39966
40932
  if (!chainId) {
39967
40933
  throw new Error("Chain ID not available");
39968
40934
  }
39969
- const dataRefinerRegistryAddress = getContractAddress(
39970
- chainId,
39971
- "DataRefinerRegistry"
39972
- );
39973
- const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
40935
+ const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
40936
+ const dataRegistryAbi = getAbi("DataRegistry");
39974
40937
  const txHash = await this.context.walletClient.writeContract({
39975
- address: dataRefinerRegistryAddress,
39976
- abi: dataRefinerRegistryAbi,
39977
- functionName: "addSchema",
39978
- args: [params.name, params.type, params.definitionUrl],
39979
- account: this.context.walletClient.account || await this.getUserAddress(),
40938
+ address: dataRegistryAddress,
40939
+ abi: dataRegistryAbi,
40940
+ functionName: "addFileWithPermissionsAndSchema",
40941
+ args: [url, ownerAddress, permissions, BigInt(schemaId)],
40942
+ account: this.context.walletClient.account || ownerAddress,
39980
40943
  chain: this.context.walletClient.chain || null
39981
40944
  });
39982
40945
  const receipt = await this.context.publicClient.waitForTransactionReceipt(
39983
40946
  {
39984
40947
  hash: txHash,
39985
40948
  timeout: 3e4
40949
+ // 30 seconds timeout
39986
40950
  }
39987
40951
  );
39988
- let schemaId = 0;
40952
+ let fileId = 0;
39989
40953
  for (const log of receipt.logs) {
39990
40954
  try {
39991
40955
  const decoded = decodeEventLog({
39992
- abi: dataRefinerRegistryAbi,
40956
+ abi: dataRegistryAbi,
39993
40957
  data: log.data,
39994
40958
  topics: log.topics
39995
40959
  });
39996
- if (decoded.eventName === "SchemaAdded") {
39997
- schemaId = Number(decoded.args.schemaId);
40960
+ if (decoded.eventName === "FileAdded") {
40961
+ fileId = Number(decoded.args.fileId);
39998
40962
  break;
39999
40963
  }
40000
40964
  } catch {
@@ -40002,107 +40966,14 @@ var DataController = class {
40002
40966
  }
40003
40967
  }
40004
40968
  return {
40005
- schemaId,
40969
+ fileId,
40006
40970
  transactionHash: txHash
40007
40971
  };
40008
40972
  } catch (error) {
40009
- console.error("Failed to add schema:", error);
40010
- throw new Error(
40011
- `Failed to add schema: ${error instanceof Error ? error.message : "Unknown error"}`
40012
- );
40013
- }
40014
- }
40015
- /**
40016
- * Retrieves a schema by its ID.
40017
- *
40018
- * @deprecated Since v2.0.0 - Use vana.schemas.get() instead
40019
- *
40020
- * Migration guide:
40021
- * ```typescript
40022
- * // Old way (deprecated):
40023
- * const schema = await vana.data.getSchema(schemaId);
40024
- *
40025
- * // New way:
40026
- * const schema = await vana.schemas.get(schemaId);
40027
- * ```
40028
- * @param schemaId - The schema ID to retrieve
40029
- * @returns Promise resolving to the schema information
40030
- */
40031
- async getSchema(schemaId) {
40032
- try {
40033
- const chainId = this.context.walletClient.chain?.id;
40034
- if (!chainId) {
40035
- throw new Error("Chain ID not available");
40036
- }
40037
- const dataRefinerRegistryAddress = getContractAddress(
40038
- chainId,
40039
- "DataRefinerRegistry"
40040
- );
40041
- const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
40042
- const dataRefinerRegistry = getContract({
40043
- address: dataRefinerRegistryAddress,
40044
- abi: dataRefinerRegistryAbi,
40045
- client: this.context.walletClient
40046
- });
40047
- const schemaData = await dataRefinerRegistry.read.schemas([
40048
- BigInt(schemaId)
40049
- ]);
40050
- if (!schemaData) {
40051
- throw new Error("Schema not found");
40052
- }
40053
- const schemaObj = schemaData;
40054
- if (!schemaObj.name || !schemaObj.typ || !schemaObj.definitionUrl) {
40055
- throw new Error("Incomplete schema data");
40056
- }
40057
- return {
40058
- id: schemaId,
40059
- name: schemaObj.name,
40060
- type: schemaObj.typ,
40061
- definitionUrl: schemaObj.definitionUrl
40062
- };
40063
- } catch (error) {
40064
- console.error("Failed to get schema:", error);
40973
+ console.error("Failed to add file with permissions and schema:", error);
40065
40974
  throw new Error(
40066
- `Failed to get schema ${schemaId}: ${error instanceof Error ? error.message : "Unknown error"}`
40067
- );
40068
- }
40069
- }
40070
- /**
40071
- * Gets the total number of schemas in the registry.
40072
- *
40073
- * @deprecated Since v2.0.0 - Use vana.schemas.count() instead
40074
- *
40075
- * Migration guide:
40076
- * ```typescript
40077
- * // Old way (deprecated):
40078
- * const count = await vana.data.getSchemasCount();
40079
- *
40080
- * // New way:
40081
- * const count = await vana.schemas.count();
40082
- * ```
40083
- * @returns Promise resolving to the total schema count
40084
- */
40085
- async getSchemasCount() {
40086
- try {
40087
- const chainId = this.context.walletClient.chain?.id;
40088
- if (!chainId) {
40089
- throw new Error("Chain ID not available");
40090
- }
40091
- const dataRefinerRegistryAddress = getContractAddress(
40092
- chainId,
40093
- "DataRefinerRegistry"
40975
+ `Failed to add file with permissions and schema: ${error instanceof Error ? error.message : "Unknown error"}`
40094
40976
  );
40095
- const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
40096
- const dataRefinerRegistry = getContract({
40097
- address: dataRefinerRegistryAddress,
40098
- abi: dataRefinerRegistryAbi,
40099
- client: this.context.walletClient
40100
- });
40101
- const count = await dataRefinerRegistry.read.schemasCount();
40102
- return Number(count);
40103
- } catch (error) {
40104
- console.error("Failed to get schemas count:", error);
40105
- return 0;
40106
40977
  }
40107
40978
  }
40108
40979
  /**
@@ -40185,7 +41056,7 @@ var DataController = class {
40185
41056
  "DataRefinerRegistry"
40186
41057
  );
40187
41058
  const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
40188
- const dataRefinerRegistry = getContract({
41059
+ const dataRefinerRegistry = getContract2({
40189
41060
  address: dataRefinerRegistryAddress,
40190
41061
  abi: dataRefinerRegistryAbi,
40191
41062
  client: this.context.walletClient
@@ -40228,7 +41099,7 @@ var DataController = class {
40228
41099
  "DataRefinerRegistry"
40229
41100
  );
40230
41101
  const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
40231
- const dataRefinerRegistry = getContract({
41102
+ const dataRefinerRegistry = getContract2({
40232
41103
  address: dataRefinerRegistryAddress,
40233
41104
  abi: dataRefinerRegistryAbi,
40234
41105
  client: this.context.walletClient
@@ -40258,7 +41129,7 @@ var DataController = class {
40258
41129
  "DataRefinerRegistry"
40259
41130
  );
40260
41131
  const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
40261
- const dataRefinerRegistry = getContract({
41132
+ const dataRefinerRegistry = getContract2({
40262
41133
  address: dataRefinerRegistryAddress,
40263
41134
  abi: dataRefinerRegistryAbi,
40264
41135
  client: this.context.walletClient
@@ -40326,27 +41197,19 @@ var DataController = class {
40326
41197
  */
40327
41198
  async uploadFileWithPermissions(data, permissions, filename, providerName) {
40328
41199
  try {
40329
- const userEncryptionKey = await generateEncryptionKey(
40330
- this.context.walletClient,
40331
- this.context.platform,
40332
- DEFAULT_ENCRYPTION_SEED
40333
- );
40334
- const encryptedData = await encryptBlobWithSignedKey(
41200
+ const uploadResult = await this.uploadToStorage(
40335
41201
  data,
40336
- userEncryptionKey,
40337
- this.context.platform
40338
- );
40339
- if (!this.context.storageManager) {
40340
- throw new Error(
40341
- "Storage manager not configured. Please provide storage providers in VanaConfig."
40342
- );
40343
- }
40344
- const uploadResult = await this.context.storageManager.upload(
40345
- encryptedData,
40346
41202
  filename,
41203
+ true,
41204
+ // Always encrypt for uploadFileWithPermissions
40347
41205
  providerName
40348
41206
  );
40349
41207
  const userAddress = await this.getUserAddress();
41208
+ const userEncryptionKey = await generateEncryptionKey(
41209
+ this.context.walletClient,
41210
+ this.context.platform,
41211
+ DEFAULT_ENCRYPTION_SEED
41212
+ );
40350
41213
  const encryptedPermissions = await Promise.all(
40351
41214
  permissions.map(async (permission) => {
40352
41215
  const encryptedKey = await encryptWithWalletPublicKey(
@@ -40387,6 +41250,70 @@ var DataController = class {
40387
41250
  );
40388
41251
  }
40389
41252
  }
41253
+ /**
41254
+ * Uploads content to storage without registering it on the blockchain.
41255
+ * This method only handles the storage upload and returns the file URL.
41256
+ *
41257
+ * @param content - The content to upload (string, Blob, Buffer, or object - objects will be JSON stringified)
41258
+ * @param filename - Optional filename for the uploaded file (defaults to timestamp-based name)
41259
+ * @param encrypt - Optional flag to encrypt the content before upload
41260
+ * @param providerName - Optional specific storage provider to use
41261
+ * @returns Promise resolving to the storage upload result with url, size, and contentType
41262
+ */
41263
+ async uploadToStorage(content, filename, encrypt = false, providerName) {
41264
+ try {
41265
+ let blob;
41266
+ if (content instanceof Blob) {
41267
+ blob = content;
41268
+ } else if (typeof content === "string") {
41269
+ blob = new Blob([content], { type: "text/plain" });
41270
+ } else if (content instanceof Buffer) {
41271
+ const arrayBuffer = content.buffer.slice(
41272
+ content.byteOffset,
41273
+ content.byteOffset + content.byteLength
41274
+ );
41275
+ blob = new Blob([arrayBuffer], { type: "application/octet-stream" });
41276
+ } else {
41277
+ blob = new Blob([JSON.stringify(content)], {
41278
+ type: "application/json"
41279
+ });
41280
+ }
41281
+ let finalBlob = blob;
41282
+ if (encrypt) {
41283
+ const encryptionKey = await generateEncryptionKey(
41284
+ this.context.walletClient,
41285
+ this.context.platform,
41286
+ DEFAULT_ENCRYPTION_SEED
41287
+ );
41288
+ finalBlob = await encryptBlobWithSignedKey(
41289
+ blob,
41290
+ encryptionKey,
41291
+ this.context.platform
41292
+ );
41293
+ }
41294
+ if (!this.context.storageManager) {
41295
+ if (this.context.validateStorageRequired) {
41296
+ this.context.validateStorageRequired();
41297
+ throw new Error("Storage validation failed");
41298
+ } else {
41299
+ throw new Error(
41300
+ "Storage manager not configured. Please provide storage providers in VanaConfig."
41301
+ );
41302
+ }
41303
+ }
41304
+ const finalFilename = filename || `upload-${Date.now()}.dat`;
41305
+ const uploadResult = await this.context.storageManager.upload(
41306
+ finalBlob,
41307
+ finalFilename,
41308
+ providerName
41309
+ );
41310
+ return uploadResult;
41311
+ } catch (error) {
41312
+ throw new Error(
41313
+ `Upload failed: ${error instanceof Error ? error.message : "Unknown error"}`
41314
+ );
41315
+ }
41316
+ }
40390
41317
  /**
40391
41318
  * Adds a permission for a party to access an existing file.
40392
41319
  *
@@ -40482,7 +41409,7 @@ var DataController = class {
40482
41409
  }
40483
41410
  const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
40484
41411
  const dataRegistryAbi = getAbi("DataRegistry");
40485
- const dataRegistry = getContract({
41412
+ const dataRegistry = getContract2({
40486
41413
  address: dataRegistryAddress,
40487
41414
  abi: dataRegistryAbi,
40488
41415
  client: this.context.walletClient
@@ -40806,7 +41733,7 @@ var DataController = class {
40806
41733
  */
40807
41734
  async getValidatedSchema(schemaId) {
40808
41735
  try {
40809
- const schema = await this.getSchema(schemaId);
41736
+ const schema = await fetchSchemaFromChain(this.context, schemaId);
40810
41737
  const dataSchema = await this.fetchAndValidateSchema(
40811
41738
  schema.definitionUrl
40812
41739
  );
@@ -40831,7 +41758,7 @@ var DataController = class {
40831
41758
  };
40832
41759
 
40833
41760
  // src/controllers/schemas.ts
40834
- import { getContract as getContract2, decodeEventLog as decodeEventLog2 } from "viem";
41761
+ import { decodeEventLog as decodeEventLog2 } from "viem";
40835
41762
  var SchemaController = class {
40836
41763
  constructor(context) {
40837
41764
  this.context = context;
@@ -40983,36 +41910,7 @@ var SchemaController = class {
40983
41910
  */
40984
41911
  async get(schemaId) {
40985
41912
  try {
40986
- const chainId = this.context.walletClient.chain?.id;
40987
- if (!chainId) {
40988
- throw new Error("Chain ID not available");
40989
- }
40990
- const dataRefinerRegistryAddress = getContractAddress(
40991
- chainId,
40992
- "DataRefinerRegistry"
40993
- );
40994
- const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
40995
- const dataRefinerRegistry = getContract2({
40996
- address: dataRefinerRegistryAddress,
40997
- abi: dataRefinerRegistryAbi,
40998
- client: this.context.publicClient
40999
- });
41000
- const schemaData = await dataRefinerRegistry.read.schemas([
41001
- BigInt(schemaId)
41002
- ]);
41003
- if (!schemaData) {
41004
- throw new Error(`Schema with ID ${schemaId} not found`);
41005
- }
41006
- const schemaObj = schemaData;
41007
- if (!schemaObj.name || !schemaObj.typ || !schemaObj.definitionUrl) {
41008
- throw new Error("Incomplete schema data");
41009
- }
41010
- return {
41011
- id: schemaId,
41012
- name: schemaObj.name,
41013
- type: schemaObj.typ,
41014
- definitionUrl: schemaObj.definitionUrl
41015
- };
41913
+ return await fetchSchemaFromChain(this.context, schemaId);
41016
41914
  } catch (error) {
41017
41915
  throw new Error(
41018
41916
  `Failed to get schema: ${error instanceof Error ? error.message : "Unknown error"}`
@@ -41032,22 +41930,7 @@ var SchemaController = class {
41032
41930
  */
41033
41931
  async count() {
41034
41932
  try {
41035
- const chainId = this.context.walletClient.chain?.id;
41036
- if (!chainId) {
41037
- throw new Error("Chain ID not available");
41038
- }
41039
- const dataRefinerRegistryAddress = getContractAddress(
41040
- chainId,
41041
- "DataRefinerRegistry"
41042
- );
41043
- const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
41044
- const dataRefinerRegistry = getContract2({
41045
- address: dataRefinerRegistryAddress,
41046
- abi: dataRefinerRegistryAbi,
41047
- client: this.context.publicClient
41048
- });
41049
- const count = await dataRefinerRegistry.read.schemasCount();
41050
- return Number(count);
41933
+ return await fetchSchemaCountFromChain(this.context);
41051
41934
  } catch (error) {
41052
41935
  throw new Error(
41053
41936
  `Failed to get schemas count: ${error instanceof Error ? error.message : "Unknown error"}`
@@ -44186,6 +45069,13 @@ var CircuitBreaker = class {
44186
45069
  import { recoverTypedDataAddress } from "viem";
44187
45070
  async function handleRelayerRequest(sdk, payload) {
44188
45071
  const { typedData, signature, expectedUserAddress } = payload;
45072
+ console.debug({
45073
+ domain: typedData.domain,
45074
+ types: typedData.types,
45075
+ primaryType: typedData.primaryType,
45076
+ message: typedData.message,
45077
+ signature
45078
+ });
44189
45079
  const signerAddress = await recoverTypedDataAddress({
44190
45080
  domain: typedData.domain,
44191
45081
  types: typedData.types,
@@ -44223,7 +45113,7 @@ async function handleRelayerRequest(sdk, payload) {
44223
45113
  typedData,
44224
45114
  signature
44225
45115
  );
44226
- case "AddAndTrustServer":
45116
+ case "AddServer":
44227
45117
  return await sdk.permissions.submitSignedAddAndTrustServer(
44228
45118
  typedData,
44229
45119
  signature
@@ -44238,6 +45128,11 @@ async function handleRelayerRequest(sdk, payload) {
44238
45128
  typedData,
44239
45129
  signature
44240
45130
  );
45131
+ case "ServerFilesAndPermission":
45132
+ return await sdk.permissions.submitSignedAddServerFilesAndPermissions(
45133
+ typedData,
45134
+ signature
45135
+ );
44241
45136
  default:
44242
45137
  throw new Error(`Unsupported operation type: ${typedData.primaryType}`);
44243
45138
  }