@opendatalabs/vana-sdk 0.1.0-alpha.3bc04d8 → 0.1.0-alpha.3cd7595

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.
@@ -425,17 +425,178 @@ var init_dataSchema_schema = __esm({
425
425
  }
426
426
  });
427
427
 
428
+ // src/utils/ipfs.ts
429
+ var ipfs_exports = {};
430
+ __export(ipfs_exports, {
431
+ DEFAULT_IPFS_GATEWAY: () => DEFAULT_IPFS_GATEWAY,
432
+ IPFS_GATEWAYS: () => IPFS_GATEWAYS,
433
+ convertIpfsUrl: () => convertIpfsUrl,
434
+ convertIpfsUrlWithFallbacks: () => convertIpfsUrlWithFallbacks,
435
+ extractIpfsHash: () => extractIpfsHash,
436
+ fetchWithFallbacks: () => fetchWithFallbacks,
437
+ getGatewayUrls: () => getGatewayUrls,
438
+ isIpfsUrl: () => isIpfsUrl
439
+ });
440
+ function isIpfsUrl(url) {
441
+ return url.startsWith("ipfs://");
442
+ }
443
+ function convertIpfsUrl(url, gateway = DEFAULT_IPFS_GATEWAY) {
444
+ if (isIpfsUrl(url)) {
445
+ const hash = url.replace("ipfs://", "");
446
+ return `${gateway}${hash}`;
447
+ }
448
+ return url;
449
+ }
450
+ function extractIpfsHash(url) {
451
+ const patterns = [
452
+ /ipfs\/([a-zA-Z0-9]+)/,
453
+ // https://gateway.pinata.cloud/ipfs/HASH
454
+ /^ipfs:\/\/([a-zA-Z0-9]+)$/,
455
+ // ipfs://HASH
456
+ /^([a-zA-Z0-9]{46,})$/
457
+ // Just the hash (46+ chars for IPFS hashes)
458
+ ];
459
+ for (const pattern of patterns) {
460
+ const match = url.match(pattern);
461
+ if (match) {
462
+ return match[1];
463
+ }
464
+ }
465
+ return null;
466
+ }
467
+ function getGatewayUrls(hash) {
468
+ return IPFS_GATEWAYS.map((gateway) => `${gateway}${hash}`);
469
+ }
470
+ function convertIpfsUrlWithFallbacks(url) {
471
+ const hash = extractIpfsHash(url);
472
+ if (hash) {
473
+ return getGatewayUrls(hash);
474
+ }
475
+ return [url];
476
+ }
477
+ async function fetchWithFallbacks(url, options) {
478
+ const hash = extractIpfsHash(url);
479
+ if (!hash) {
480
+ return fetch(url, options);
481
+ }
482
+ const gatewayUrls = getGatewayUrls(hash);
483
+ let lastError = null;
484
+ for (let i = 0; i < gatewayUrls.length; i++) {
485
+ const gatewayUrl = gatewayUrls[i];
486
+ try {
487
+ const response = await fetch(gatewayUrl, {
488
+ ...options,
489
+ // Add timeout to avoid hanging on slow gateways
490
+ signal: AbortSignal.timeout(1e4)
491
+ // 10 second timeout
492
+ });
493
+ if (response.ok) {
494
+ return response;
495
+ }
496
+ if (response.status === 429) {
497
+ lastError = new Error(`Gateway rate limited: ${gatewayUrl}`);
498
+ continue;
499
+ }
500
+ lastError = new Error(`Gateway error ${response.status}: ${gatewayUrl}`);
501
+ } catch (error) {
502
+ lastError = error instanceof Error ? error : new Error(String(error));
503
+ if (lastError.message.includes("429") || lastError.name === "TimeoutError") {
504
+ continue;
505
+ }
506
+ }
507
+ if (i < gatewayUrls.length - 1) {
508
+ await new Promise((resolve) => setTimeout(resolve, 1e3 * (i + 1)));
509
+ }
510
+ }
511
+ throw new Error(
512
+ `All IPFS gateways failed for hash ${hash}. Last error: ${lastError?.message}`
513
+ );
514
+ }
515
+ var DEFAULT_IPFS_GATEWAY, IPFS_GATEWAYS;
516
+ var init_ipfs = __esm({
517
+ "src/utils/ipfs.ts"() {
518
+ "use strict";
519
+ DEFAULT_IPFS_GATEWAY = "https://dweb.link/ipfs/";
520
+ IPFS_GATEWAYS = [
521
+ "https://dweb.link/ipfs/",
522
+ // Interplanetary Shipyard - highly reliable
523
+ "https://ipfs.io/ipfs/",
524
+ // IPFS Foundation - reliable
525
+ "https://cloudflare-ipfs.com/ipfs/",
526
+ // Cloudflare - good performance
527
+ "https://gateway.pinata.cloud/ipfs/",
528
+ // Pinata - backup option (has rate limits)
529
+ "https://ipfs.filebase.io/ipfs/"
530
+ // Filebase - emerging reliable option
531
+ ];
532
+ }
533
+ });
534
+
535
+ // src/utils/download.ts
536
+ var download_exports = {};
537
+ __export(download_exports, {
538
+ fetchWithRelayer: () => fetchWithRelayer
539
+ });
540
+ async function fetchWithRelayer(url, downloadRelayer) {
541
+ let processedUrl = url;
542
+ if (url.startsWith("ar://")) {
543
+ const txId = url.replace("ar://", "");
544
+ processedUrl = `https://arweave.net/${txId}`;
545
+ }
546
+ const ipfsHash = extractIpfsHash(processedUrl);
547
+ if (ipfsHash) {
548
+ try {
549
+ return await fetchWithFallbacks(url);
550
+ } catch (ipfsError) {
551
+ if (downloadRelayer) {
552
+ try {
553
+ const gatewayUrl = `https://gateway.pinata.cloud/ipfs/${ipfsHash}`;
554
+ const blob = await downloadRelayer.proxyDownload(gatewayUrl);
555
+ return new Response(blob);
556
+ } catch {
557
+ throw ipfsError;
558
+ }
559
+ }
560
+ throw ipfsError;
561
+ }
562
+ }
563
+ try {
564
+ const response = await fetch(processedUrl);
565
+ return response;
566
+ } catch (error) {
567
+ if (downloadRelayer) {
568
+ try {
569
+ const blob = await downloadRelayer.proxyDownload(processedUrl);
570
+ return new Response(blob);
571
+ } catch {
572
+ throw error;
573
+ }
574
+ }
575
+ throw new Error(
576
+ `Failed to fetch from ${processedUrl}: ${error instanceof Error ? error.message : "Unknown error"}`
577
+ );
578
+ }
579
+ }
580
+ var init_download = __esm({
581
+ "src/utils/download.ts"() {
582
+ "use strict";
583
+ init_ipfs();
584
+ }
585
+ });
586
+
428
587
  // src/utils/schemaValidation.ts
429
588
  import Ajv from "ajv";
430
589
  import addFormats from "ajv-formats";
431
- function validateDataSchema(schema) {
432
- return schemaValidator.validateDataSchema(schema);
590
+ function validateDataSchemaAgainstMetaSchema(schema) {
591
+ const validator = schemaValidator;
592
+ validator.validateDataSchemaAgainstMetaSchema(schema);
593
+ return schema;
433
594
  }
434
595
  function validateDataAgainstSchema(data, schema) {
435
596
  return schemaValidator.validateDataAgainstSchema(data, schema);
436
597
  }
437
- function fetchAndValidateSchema(url) {
438
- return schemaValidator.fetchAndValidateSchema(url);
598
+ function fetchAndValidateSchema(url, downloadRelayer) {
599
+ return schemaValidator.fetchAndValidateSchema(url, downloadRelayer);
439
600
  }
440
601
  var SchemaValidationError, SchemaValidator, schemaValidator;
441
602
  var init_schemaValidation = __esm({
@@ -462,9 +623,9 @@ var init_schemaValidation = __esm({
462
623
  this.dataSchemaValidator = this.ajv.compile(dataSchema_schema_default);
463
624
  }
464
625
  /**
465
- * Validates a data schema against the Vana meta-schema
626
+ * Validates a data schema definition against the Vana meta-schema
466
627
  *
467
- * @param schema - The data schema to validate
628
+ * @param schema - The data schema definition to validate
468
629
  * @throws SchemaValidationError if invalid
469
630
  * @example
470
631
  * ```typescript
@@ -483,10 +644,10 @@ var init_schemaValidation = __esm({
483
644
  * }
484
645
  * };
485
646
  *
486
- * validator.validateDataSchema(schema); // throws if invalid
647
+ * validator.validateDataSchemaAgainstMetaSchema(schema); // throws if invalid
487
648
  * ```
488
649
  */
489
- validateDataSchema(schema) {
650
+ validateDataSchemaAgainstMetaSchema(schema) {
490
651
  const isValid = this.dataSchemaValidator(schema);
491
652
  if (!isValid) {
492
653
  const errors = this.dataSchemaValidator.errors || [];
@@ -506,10 +667,10 @@ var init_schemaValidation = __esm({
506
667
  }
507
668
  }
508
669
  /**
509
- * Validates data against a JSON Schema from a schema
670
+ * Validates data against a JSON Schema
510
671
  *
511
672
  * @param data - The data to validate
512
- * @param schema - The schema containing the validation rules (DataSchema or Schema)
673
+ * @param schema - The schema containing the validation rules (must have been validated or fetched from chain)
513
674
  * @throws SchemaValidationError if invalid
514
675
  * @example
515
676
  * ```typescript
@@ -519,25 +680,22 @@ var init_schemaValidation = __esm({
519
680
  * const schema = await vana.schemas.get(1);
520
681
  * validator.validateDataAgainstSchema(userData, schema);
521
682
  *
522
- * // Also works with DataSchema object
523
- * const dataSchema: DataSchema = {
683
+ * // Also works with pre-validated DataSchema object
684
+ * const dataSchema = validator.validateDataSchemaAgainstMetaSchema({
524
685
  * name: "User Profile",
525
686
  * version: "1.0.0",
526
687
  * dialect: "json",
527
688
  * schema: { type: "object", properties: { name: { type: "string" } } }
528
- * };
689
+ * });
529
690
  * validator.validateDataAgainstSchema(userData, dataSchema);
530
691
  * ```
531
692
  */
532
693
  validateDataAgainstSchema(data, schema) {
533
- if (!("id" in schema)) {
534
- this.validateDataSchema(schema);
535
- }
536
694
  if (schema.dialect !== "json") {
537
- throw new SchemaValidationError(
538
- `Data validation only supported for JSON dialect, got: ${schema.dialect}`,
539
- []
695
+ console.warn(
696
+ `[SchemaValidator] Data validation skipped: dialect '${schema.dialect}' does not support data validation. Only JSON schemas can validate data structure.`
540
697
  );
698
+ return;
541
699
  }
542
700
  if (typeof schema.schema !== "object") {
543
701
  throw new SchemaValidationError(
@@ -603,9 +761,11 @@ var init_schemaValidation = __esm({
603
761
  }
604
762
  }
605
763
  /**
606
- * Fetches and validates a schema from a URL
764
+ * Fetches and validates a data schema from a URL
607
765
  *
608
- * @param url - The URL to fetch the schema from
766
+ * @param url - The URL to fetch the data schema from
767
+ * @param downloadRelayer - Optional download relayer for CORS bypass
768
+ * @param downloadRelayer.proxyDownload - Function to proxy downloads through application server
609
769
  * @returns The validated data schema
610
770
  * @throws SchemaValidationError if invalid or fetch fails
611
771
  * @example
@@ -614,14 +774,15 @@ var init_schemaValidation = __esm({
614
774
  * const schema = await validator.fetchAndValidateSchema("https://example.com/schema.json");
615
775
  * ```
616
776
  */
617
- async fetchAndValidateSchema(url) {
777
+ async fetchAndValidateSchema(url, downloadRelayer) {
618
778
  try {
619
- const response = await fetch(url);
779
+ const { fetchWithRelayer: fetchWithRelayer2 } = await Promise.resolve().then(() => (init_download(), download_exports));
780
+ const response = await fetchWithRelayer2(url, downloadRelayer);
620
781
  if (!response.ok) {
621
782
  throw new Error(`HTTP ${response.status}: ${response.statusText}`);
622
783
  }
623
784
  const schema = await response.json();
624
- this.validateDataSchema(schema);
785
+ this.validateDataSchemaAgainstMetaSchema(schema);
625
786
  if (schema.dialect === "sqlite" && typeof schema.schema === "string") {
626
787
  this.validateSQLiteDDL(schema.schema, schema.dialectVersion);
627
788
  }
@@ -3039,6 +3200,19 @@ var init_DataRegistryImplementation = __esm({
3039
3200
  name: "Upgraded",
3040
3201
  type: "event"
3041
3202
  },
3203
+ {
3204
+ inputs: [],
3205
+ name: "DATA_PORTABILITY_ROLE",
3206
+ outputs: [
3207
+ {
3208
+ internalType: "bytes32",
3209
+ name: "",
3210
+ type: "bytes32"
3211
+ }
3212
+ ],
3213
+ stateMutability: "view",
3214
+ type: "function"
3215
+ },
3042
3216
  {
3043
3217
  inputs: [],
3044
3218
  name: "DEFAULT_ADMIN_ROLE",
@@ -3136,14 +3310,9 @@ var init_DataRegistryImplementation = __esm({
3136
3310
  {
3137
3311
  inputs: [
3138
3312
  {
3139
- internalType: "string",
3140
- name: "url",
3141
- type: "string"
3142
- },
3143
- {
3144
- internalType: "address",
3145
- name: "ownerAddress",
3146
- type: "address"
3313
+ internalType: "uint256",
3314
+ name: "fileId",
3315
+ type: "uint256"
3147
3316
  },
3148
3317
  {
3149
3318
  components: [
@@ -3161,16 +3330,15 @@ var init_DataRegistryImplementation = __esm({
3161
3330
  internalType: "struct IDataRegistry.Permission[]",
3162
3331
  name: "permissions",
3163
3332
  type: "tuple[]"
3164
- }
3165
- ],
3166
- name: "addFileWithPermissions",
3167
- outputs: [
3333
+ },
3168
3334
  {
3169
3335
  internalType: "uint256",
3170
- name: "",
3336
+ name: "schemaId",
3171
3337
  type: "uint256"
3172
3338
  }
3173
3339
  ],
3340
+ name: "addFilePermissionsAndSchema",
3341
+ outputs: [],
3174
3342
  stateMutability: "nonpayable",
3175
3343
  type: "function"
3176
3344
  },
@@ -3202,14 +3370,9 @@ var init_DataRegistryImplementation = __esm({
3202
3370
  internalType: "struct IDataRegistry.Permission[]",
3203
3371
  name: "permissions",
3204
3372
  type: "tuple[]"
3205
- },
3206
- {
3207
- internalType: "uint256",
3208
- name: "schemaId",
3209
- type: "uint256"
3210
3373
  }
3211
3374
  ],
3212
- name: "addFileWithPermissionsAndSchema",
3375
+ name: "addFileWithPermissions",
3213
3376
  outputs: [
3214
3377
  {
3215
3378
  internalType: "uint256",
@@ -3228,136 +3391,42 @@ var init_DataRegistryImplementation = __esm({
3228
3391
  type: "string"
3229
3392
  },
3230
3393
  {
3231
- internalType: "uint256",
3232
- name: "schemaId",
3233
- type: "uint256"
3234
- }
3235
- ],
3236
- name: "addFileWithSchema",
3237
- outputs: [
3238
- {
3239
- internalType: "uint256",
3240
- name: "",
3241
- type: "uint256"
3242
- }
3243
- ],
3244
- stateMutability: "nonpayable",
3245
- type: "function"
3246
- },
3247
- {
3248
- inputs: [
3249
- {
3250
- internalType: "uint256",
3251
- name: "fileId",
3252
- type: "uint256"
3394
+ internalType: "address",
3395
+ name: "ownerAddress",
3396
+ type: "address"
3253
3397
  },
3254
3398
  {
3255
3399
  components: [
3256
3400
  {
3257
- internalType: "bytes",
3258
- name: "signature",
3259
- type: "bytes"
3401
+ internalType: "address",
3402
+ name: "account",
3403
+ type: "address"
3260
3404
  },
3261
3405
  {
3262
- components: [
3263
- {
3264
- internalType: "uint256",
3265
- name: "score",
3266
- type: "uint256"
3267
- },
3268
- {
3269
- internalType: "uint256",
3270
- name: "dlpId",
3271
- type: "uint256"
3272
- },
3273
- {
3274
- internalType: "string",
3275
- name: "metadata",
3276
- type: "string"
3277
- },
3278
- {
3279
- internalType: "string",
3280
- name: "proofUrl",
3281
- type: "string"
3282
- },
3283
- {
3284
- internalType: "string",
3285
- name: "instruction",
3286
- type: "string"
3287
- }
3288
- ],
3289
- internalType: "struct IDataRegistry.ProofData",
3290
- name: "data",
3291
- type: "tuple"
3406
+ internalType: "string",
3407
+ name: "key",
3408
+ type: "string"
3292
3409
  }
3293
3410
  ],
3294
- internalType: "struct IDataRegistry.Proof",
3295
- name: "proof",
3296
- type: "tuple"
3297
- }
3298
- ],
3299
- name: "addProof",
3300
- outputs: [],
3301
- stateMutability: "nonpayable",
3302
- type: "function"
3303
- },
3304
- {
3305
- inputs: [
3306
- {
3307
- internalType: "uint256",
3308
- name: "fileId",
3309
- type: "uint256"
3411
+ internalType: "struct IDataRegistry.Permission[]",
3412
+ name: "permissions",
3413
+ type: "tuple[]"
3310
3414
  },
3311
3415
  {
3312
3416
  internalType: "uint256",
3313
- name: "refinerId",
3417
+ name: "schemaId",
3314
3418
  type: "uint256"
3315
- },
3316
- {
3317
- internalType: "string",
3318
- name: "url",
3319
- type: "string"
3320
- },
3321
- {
3322
- internalType: "address",
3323
- name: "account",
3324
- type: "address"
3325
- },
3326
- {
3327
- internalType: "string",
3328
- name: "key",
3329
- type: "string"
3330
3419
  }
3331
3420
  ],
3332
- name: "addRefinementWithPermission",
3333
- outputs: [],
3334
- stateMutability: "nonpayable",
3335
- type: "function"
3336
- },
3337
- {
3338
- inputs: [],
3339
- name: "dataRefinerRegistry",
3340
- outputs: [
3341
- {
3342
- internalType: "contract IDataRefinerRegistry",
3343
- name: "",
3344
- type: "address"
3345
- }
3346
- ],
3347
- stateMutability: "view",
3348
- type: "function"
3349
- },
3350
- {
3351
- inputs: [],
3352
- name: "emitLegacyEvents",
3421
+ name: "addFileWithPermissionsAndSchema",
3353
3422
  outputs: [
3354
3423
  {
3355
- internalType: "bool",
3424
+ internalType: "uint256",
3356
3425
  name: "",
3357
- type: "bool"
3426
+ type: "uint256"
3358
3427
  }
3359
3428
  ],
3360
- stateMutability: "view",
3429
+ stateMutability: "nonpayable",
3361
3430
  type: "function"
3362
3431
  },
3363
3432
  {
@@ -3366,41 +3435,22 @@ var init_DataRegistryImplementation = __esm({
3366
3435
  internalType: "string",
3367
3436
  name: "url",
3368
3437
  type: "string"
3369
- }
3370
- ],
3371
- name: "fileIdByUrl",
3372
- outputs: [
3438
+ },
3373
3439
  {
3374
3440
  internalType: "uint256",
3375
- name: "",
3441
+ name: "schemaId",
3376
3442
  type: "uint256"
3377
3443
  }
3378
3444
  ],
3379
- stateMutability: "view",
3380
- type: "function"
3381
- },
3382
- {
3383
- inputs: [
3384
- {
3385
- internalType: "uint256",
3386
- name: "fileId",
3387
- type: "uint256"
3388
- },
3389
- {
3390
- internalType: "address",
3391
- name: "account",
3392
- type: "address"
3393
- }
3394
- ],
3395
- name: "filePermissions",
3445
+ name: "addFileWithSchema",
3396
3446
  outputs: [
3397
3447
  {
3398
- internalType: "string",
3448
+ internalType: "uint256",
3399
3449
  name: "",
3400
- type: "string"
3450
+ type: "uint256"
3401
3451
  }
3402
3452
  ],
3403
- stateMutability: "view",
3453
+ stateMutability: "nonpayable",
3404
3454
  type: "function"
3405
3455
  },
3406
3456
  {
@@ -3410,14 +3460,173 @@ var init_DataRegistryImplementation = __esm({
3410
3460
  name: "fileId",
3411
3461
  type: "uint256"
3412
3462
  },
3413
- {
3414
- internalType: "uint256",
3415
- name: "index",
3416
- type: "uint256"
3417
- }
3418
- ],
3419
- name: "fileProofs",
3420
- outputs: [
3463
+ {
3464
+ components: [
3465
+ {
3466
+ internalType: "bytes",
3467
+ name: "signature",
3468
+ type: "bytes"
3469
+ },
3470
+ {
3471
+ components: [
3472
+ {
3473
+ internalType: "uint256",
3474
+ name: "score",
3475
+ type: "uint256"
3476
+ },
3477
+ {
3478
+ internalType: "uint256",
3479
+ name: "dlpId",
3480
+ type: "uint256"
3481
+ },
3482
+ {
3483
+ internalType: "string",
3484
+ name: "metadata",
3485
+ type: "string"
3486
+ },
3487
+ {
3488
+ internalType: "string",
3489
+ name: "proofUrl",
3490
+ type: "string"
3491
+ },
3492
+ {
3493
+ internalType: "string",
3494
+ name: "instruction",
3495
+ type: "string"
3496
+ }
3497
+ ],
3498
+ internalType: "struct IDataRegistry.ProofData",
3499
+ name: "data",
3500
+ type: "tuple"
3501
+ }
3502
+ ],
3503
+ internalType: "struct IDataRegistry.Proof",
3504
+ name: "proof",
3505
+ type: "tuple"
3506
+ }
3507
+ ],
3508
+ name: "addProof",
3509
+ outputs: [],
3510
+ stateMutability: "nonpayable",
3511
+ type: "function"
3512
+ },
3513
+ {
3514
+ inputs: [
3515
+ {
3516
+ internalType: "uint256",
3517
+ name: "fileId",
3518
+ type: "uint256"
3519
+ },
3520
+ {
3521
+ internalType: "uint256",
3522
+ name: "refinerId",
3523
+ type: "uint256"
3524
+ },
3525
+ {
3526
+ internalType: "string",
3527
+ name: "url",
3528
+ type: "string"
3529
+ },
3530
+ {
3531
+ internalType: "address",
3532
+ name: "account",
3533
+ type: "address"
3534
+ },
3535
+ {
3536
+ internalType: "string",
3537
+ name: "key",
3538
+ type: "string"
3539
+ }
3540
+ ],
3541
+ name: "addRefinementWithPermission",
3542
+ outputs: [],
3543
+ stateMutability: "nonpayable",
3544
+ type: "function"
3545
+ },
3546
+ {
3547
+ inputs: [],
3548
+ name: "dataRefinerRegistry",
3549
+ outputs: [
3550
+ {
3551
+ internalType: "contract IDataRefinerRegistry",
3552
+ name: "",
3553
+ type: "address"
3554
+ }
3555
+ ],
3556
+ stateMutability: "view",
3557
+ type: "function"
3558
+ },
3559
+ {
3560
+ inputs: [],
3561
+ name: "emitLegacyEvents",
3562
+ outputs: [
3563
+ {
3564
+ internalType: "bool",
3565
+ name: "",
3566
+ type: "bool"
3567
+ }
3568
+ ],
3569
+ stateMutability: "view",
3570
+ type: "function"
3571
+ },
3572
+ {
3573
+ inputs: [
3574
+ {
3575
+ internalType: "string",
3576
+ name: "url",
3577
+ type: "string"
3578
+ }
3579
+ ],
3580
+ name: "fileIdByUrl",
3581
+ outputs: [
3582
+ {
3583
+ internalType: "uint256",
3584
+ name: "",
3585
+ type: "uint256"
3586
+ }
3587
+ ],
3588
+ stateMutability: "view",
3589
+ type: "function"
3590
+ },
3591
+ {
3592
+ inputs: [
3593
+ {
3594
+ internalType: "uint256",
3595
+ name: "fileId",
3596
+ type: "uint256"
3597
+ },
3598
+ {
3599
+ internalType: "address",
3600
+ name: "account",
3601
+ type: "address"
3602
+ }
3603
+ ],
3604
+ name: "filePermissions",
3605
+ outputs: [
3606
+ {
3607
+ internalType: "string",
3608
+ name: "",
3609
+ type: "string"
3610
+ }
3611
+ ],
3612
+ stateMutability: "view",
3613
+ type: "function"
3614
+ },
3615
+ {
3616
+ inputs: [
3617
+ {
3618
+ internalType: "uint256",
3619
+ name: "fileId",
3620
+ type: "uint256"
3621
+ },
3622
+ {
3623
+ internalType: "uint256",
3624
+ name: "index",
3625
+ type: "uint256"
3626
+ }
3627
+ ],
3628
+ name: "fileProofs",
3629
+ outputs: [
3421
3630
  {
3422
3631
  components: [
3423
3632
  {
@@ -36110,110 +36319,644 @@ var init_transactionHandle = __esm({
36110
36319
  }
36111
36320
  });
36112
36321
 
36113
- // src/utils/ipfs.ts
36114
- var ipfs_exports = {};
36115
- __export(ipfs_exports, {
36116
- DEFAULT_IPFS_GATEWAY: () => DEFAULT_IPFS_GATEWAY,
36117
- IPFS_GATEWAYS: () => IPFS_GATEWAYS,
36118
- convertIpfsUrl: () => convertIpfsUrl,
36119
- convertIpfsUrlWithFallbacks: () => convertIpfsUrlWithFallbacks,
36120
- extractIpfsHash: () => extractIpfsHash,
36121
- fetchWithFallbacks: () => fetchWithFallbacks,
36122
- getGatewayUrls: () => getGatewayUrls,
36123
- isIpfsUrl: () => isIpfsUrl
36124
- });
36125
- function isIpfsUrl(url) {
36126
- return url.startsWith("ipfs://");
36127
- }
36128
- function convertIpfsUrl(url, gateway = DEFAULT_IPFS_GATEWAY) {
36129
- if (isIpfsUrl(url)) {
36130
- const hash = url.replace("ipfs://", "");
36131
- return `${gateway}${hash}`;
36132
- }
36133
- return url;
36134
- }
36135
- function extractIpfsHash(url) {
36136
- const patterns = [
36137
- /ipfs\/([a-zA-Z0-9]+)/,
36138
- // https://gateway.pinata.cloud/ipfs/HASH
36139
- /^ipfs:\/\/([a-zA-Z0-9]+)$/,
36140
- // ipfs://HASH
36141
- /^([a-zA-Z0-9]{46,})$/
36142
- // Just the hash (46+ chars for IPFS hashes)
36143
- ];
36144
- for (const pattern of patterns) {
36145
- const match = url.match(pattern);
36146
- if (match) {
36147
- return match[1];
36148
- }
36149
- }
36150
- return null;
36151
- }
36152
- function getGatewayUrls(hash) {
36153
- return IPFS_GATEWAYS.map((gateway) => `${gateway}${hash}`);
36154
- }
36155
- function convertIpfsUrlWithFallbacks(url) {
36156
- const hash = extractIpfsHash(url);
36157
- if (hash) {
36158
- return getGatewayUrls(hash);
36159
- }
36160
- return [url];
36161
- }
36162
- async function fetchWithFallbacks(url, options) {
36163
- const hash = extractIpfsHash(url);
36164
- if (!hash) {
36165
- return fetch(url, options);
36166
- }
36167
- const gatewayUrls = getGatewayUrls(hash);
36168
- let lastError = null;
36169
- for (let i = 0; i < gatewayUrls.length; i++) {
36170
- const gatewayUrl = gatewayUrls[i];
36171
- try {
36172
- const response = await fetch(gatewayUrl, {
36173
- ...options,
36174
- // Add timeout to avoid hanging on slow gateways
36175
- signal: AbortSignal.timeout(1e4)
36176
- // 10 second timeout
36177
- });
36178
- if (response.ok) {
36179
- return response;
36180
- }
36181
- if (response.status === 429) {
36182
- lastError = new Error(`Gateway rate limited: ${gatewayUrl}`);
36183
- continue;
36184
- }
36185
- lastError = new Error(`Gateway error ${response.status}: ${gatewayUrl}`);
36186
- } catch (error) {
36187
- lastError = error instanceof Error ? error : new Error(String(error));
36188
- if (lastError.message.includes("429") || lastError.name === "TimeoutError") {
36189
- continue;
36190
- }
36191
- }
36192
- if (i < gatewayUrls.length - 1) {
36193
- await new Promise((resolve) => setTimeout(resolve, 1e3 * (i + 1)));
36194
- }
36195
- }
36196
- throw new Error(
36197
- `All IPFS gateways failed for hash ${hash}. Last error: ${lastError?.message}`
36198
- );
36199
- }
36200
- var DEFAULT_IPFS_GATEWAY, IPFS_GATEWAYS;
36201
- var init_ipfs = __esm({
36202
- "src/utils/ipfs.ts"() {
36322
+ // src/generated/subgraph.ts
36323
+ var GetUserPermissionsDocument, GetUserTrustedServersDocument, GetUserFilesDocument, GetFileProofsDocument, GetDlpDocument, GetSchemaDocument, ListSchemasDocument, CountSchemasDocument;
36324
+ var init_subgraph = __esm({
36325
+ "src/generated/subgraph.ts"() {
36203
36326
  "use strict";
36204
- DEFAULT_IPFS_GATEWAY = "https://dweb.link/ipfs/";
36205
- IPFS_GATEWAYS = [
36206
- "https://dweb.link/ipfs/",
36207
- // Interplanetary Shipyard - highly reliable
36208
- "https://ipfs.io/ipfs/",
36209
- // IPFS Foundation - reliable
36210
- "https://cloudflare-ipfs.com/ipfs/",
36211
- // Cloudflare - good performance
36212
- "https://gateway.pinata.cloud/ipfs/",
36213
- // Pinata - backup option (has rate limits)
36214
- "https://ipfs.filebase.io/ipfs/"
36215
- // Filebase - emerging reliable option
36216
- ];
36327
+ GetUserPermissionsDocument = {
36328
+ kind: "Document",
36329
+ definitions: [
36330
+ {
36331
+ kind: "OperationDefinition",
36332
+ operation: "query",
36333
+ name: { kind: "Name", value: "GetUserPermissions" },
36334
+ variableDefinitions: [
36335
+ {
36336
+ kind: "VariableDefinition",
36337
+ variable: {
36338
+ kind: "Variable",
36339
+ name: { kind: "Name", value: "userId" }
36340
+ },
36341
+ type: {
36342
+ kind: "NonNullType",
36343
+ type: { kind: "NamedType", name: { kind: "Name", value: "ID" } }
36344
+ }
36345
+ }
36346
+ ],
36347
+ selectionSet: {
36348
+ kind: "SelectionSet",
36349
+ selections: [
36350
+ {
36351
+ kind: "Field",
36352
+ name: { kind: "Name", value: "user" },
36353
+ arguments: [
36354
+ {
36355
+ kind: "Argument",
36356
+ name: { kind: "Name", value: "id" },
36357
+ value: {
36358
+ kind: "Variable",
36359
+ name: { kind: "Name", value: "userId" }
36360
+ }
36361
+ }
36362
+ ],
36363
+ selectionSet: {
36364
+ kind: "SelectionSet",
36365
+ selections: [
36366
+ { kind: "Field", name: { kind: "Name", value: "id" } },
36367
+ {
36368
+ kind: "Field",
36369
+ name: { kind: "Name", value: "permissions" },
36370
+ selectionSet: {
36371
+ kind: "SelectionSet",
36372
+ selections: [
36373
+ { kind: "Field", name: { kind: "Name", value: "id" } },
36374
+ { kind: "Field", name: { kind: "Name", value: "grant" } },
36375
+ { kind: "Field", name: { kind: "Name", value: "nonce" } },
36376
+ {
36377
+ kind: "Field",
36378
+ name: { kind: "Name", value: "signature" }
36379
+ },
36380
+ {
36381
+ kind: "Field",
36382
+ name: { kind: "Name", value: "startBlock" }
36383
+ },
36384
+ {
36385
+ kind: "Field",
36386
+ name: { kind: "Name", value: "endBlock" }
36387
+ },
36388
+ {
36389
+ kind: "Field",
36390
+ name: { kind: "Name", value: "addedAtBlock" }
36391
+ },
36392
+ {
36393
+ kind: "Field",
36394
+ name: { kind: "Name", value: "addedAtTimestamp" }
36395
+ },
36396
+ {
36397
+ kind: "Field",
36398
+ name: { kind: "Name", value: "transactionHash" }
36399
+ },
36400
+ {
36401
+ kind: "Field",
36402
+ name: { kind: "Name", value: "grantee" },
36403
+ selectionSet: {
36404
+ kind: "SelectionSet",
36405
+ selections: [
36406
+ {
36407
+ kind: "Field",
36408
+ name: { kind: "Name", value: "id" }
36409
+ },
36410
+ {
36411
+ kind: "Field",
36412
+ name: { kind: "Name", value: "address" }
36413
+ }
36414
+ ]
36415
+ }
36416
+ },
36417
+ {
36418
+ kind: "Field",
36419
+ name: { kind: "Name", value: "filePermissions" },
36420
+ selectionSet: {
36421
+ kind: "SelectionSet",
36422
+ selections: [
36423
+ {
36424
+ kind: "Field",
36425
+ name: { kind: "Name", value: "file" },
36426
+ selectionSet: {
36427
+ kind: "SelectionSet",
36428
+ selections: [
36429
+ {
36430
+ kind: "Field",
36431
+ name: { kind: "Name", value: "id" }
36432
+ },
36433
+ {
36434
+ kind: "Field",
36435
+ name: { kind: "Name", value: "url" }
36436
+ }
36437
+ ]
36438
+ }
36439
+ }
36440
+ ]
36441
+ }
36442
+ }
36443
+ ]
36444
+ }
36445
+ }
36446
+ ]
36447
+ }
36448
+ }
36449
+ ]
36450
+ }
36451
+ }
36452
+ ]
36453
+ };
36454
+ GetUserTrustedServersDocument = {
36455
+ kind: "Document",
36456
+ definitions: [
36457
+ {
36458
+ kind: "OperationDefinition",
36459
+ operation: "query",
36460
+ name: { kind: "Name", value: "GetUserTrustedServers" },
36461
+ variableDefinitions: [
36462
+ {
36463
+ kind: "VariableDefinition",
36464
+ variable: {
36465
+ kind: "Variable",
36466
+ name: { kind: "Name", value: "userId" }
36467
+ },
36468
+ type: {
36469
+ kind: "NonNullType",
36470
+ type: { kind: "NamedType", name: { kind: "Name", value: "ID" } }
36471
+ }
36472
+ }
36473
+ ],
36474
+ selectionSet: {
36475
+ kind: "SelectionSet",
36476
+ selections: [
36477
+ {
36478
+ kind: "Field",
36479
+ name: { kind: "Name", value: "user" },
36480
+ arguments: [
36481
+ {
36482
+ kind: "Argument",
36483
+ name: { kind: "Name", value: "id" },
36484
+ value: {
36485
+ kind: "Variable",
36486
+ name: { kind: "Name", value: "userId" }
36487
+ }
36488
+ }
36489
+ ],
36490
+ selectionSet: {
36491
+ kind: "SelectionSet",
36492
+ selections: [
36493
+ { kind: "Field", name: { kind: "Name", value: "id" } },
36494
+ {
36495
+ kind: "Field",
36496
+ name: { kind: "Name", value: "serverTrusts" },
36497
+ selectionSet: {
36498
+ kind: "SelectionSet",
36499
+ selections: [
36500
+ { kind: "Field", name: { kind: "Name", value: "id" } },
36501
+ {
36502
+ kind: "Field",
36503
+ name: { kind: "Name", value: "server" },
36504
+ selectionSet: {
36505
+ kind: "SelectionSet",
36506
+ selections: [
36507
+ {
36508
+ kind: "Field",
36509
+ name: { kind: "Name", value: "id" }
36510
+ },
36511
+ {
36512
+ kind: "Field",
36513
+ name: { kind: "Name", value: "serverAddress" }
36514
+ },
36515
+ {
36516
+ kind: "Field",
36517
+ name: { kind: "Name", value: "url" }
36518
+ },
36519
+ {
36520
+ kind: "Field",
36521
+ name: { kind: "Name", value: "publicKey" }
36522
+ }
36523
+ ]
36524
+ }
36525
+ },
36526
+ {
36527
+ kind: "Field",
36528
+ name: { kind: "Name", value: "trustedAt" }
36529
+ },
36530
+ {
36531
+ kind: "Field",
36532
+ name: { kind: "Name", value: "trustedAtBlock" }
36533
+ },
36534
+ {
36535
+ kind: "Field",
36536
+ name: { kind: "Name", value: "untrustedAtBlock" }
36537
+ },
36538
+ {
36539
+ kind: "Field",
36540
+ name: { kind: "Name", value: "transactionHash" }
36541
+ }
36542
+ ]
36543
+ }
36544
+ }
36545
+ ]
36546
+ }
36547
+ }
36548
+ ]
36549
+ }
36550
+ }
36551
+ ]
36552
+ };
36553
+ GetUserFilesDocument = {
36554
+ kind: "Document",
36555
+ definitions: [
36556
+ {
36557
+ kind: "OperationDefinition",
36558
+ operation: "query",
36559
+ name: { kind: "Name", value: "GetUserFiles" },
36560
+ variableDefinitions: [
36561
+ {
36562
+ kind: "VariableDefinition",
36563
+ variable: {
36564
+ kind: "Variable",
36565
+ name: { kind: "Name", value: "userId" }
36566
+ },
36567
+ type: {
36568
+ kind: "NonNullType",
36569
+ type: { kind: "NamedType", name: { kind: "Name", value: "ID" } }
36570
+ }
36571
+ }
36572
+ ],
36573
+ selectionSet: {
36574
+ kind: "SelectionSet",
36575
+ selections: [
36576
+ {
36577
+ kind: "Field",
36578
+ name: { kind: "Name", value: "user" },
36579
+ arguments: [
36580
+ {
36581
+ kind: "Argument",
36582
+ name: { kind: "Name", value: "id" },
36583
+ value: {
36584
+ kind: "Variable",
36585
+ name: { kind: "Name", value: "userId" }
36586
+ }
36587
+ }
36588
+ ],
36589
+ selectionSet: {
36590
+ kind: "SelectionSet",
36591
+ selections: [
36592
+ { kind: "Field", name: { kind: "Name", value: "id" } },
36593
+ {
36594
+ kind: "Field",
36595
+ name: { kind: "Name", value: "files" },
36596
+ selectionSet: {
36597
+ kind: "SelectionSet",
36598
+ selections: [
36599
+ { kind: "Field", name: { kind: "Name", value: "id" } },
36600
+ { kind: "Field", name: { kind: "Name", value: "url" } },
36601
+ {
36602
+ kind: "Field",
36603
+ name: { kind: "Name", value: "schemaId" }
36604
+ },
36605
+ {
36606
+ kind: "Field",
36607
+ name: { kind: "Name", value: "addedAtBlock" }
36608
+ },
36609
+ {
36610
+ kind: "Field",
36611
+ name: { kind: "Name", value: "addedAtTimestamp" }
36612
+ },
36613
+ {
36614
+ kind: "Field",
36615
+ name: { kind: "Name", value: "transactionHash" }
36616
+ },
36617
+ {
36618
+ kind: "Field",
36619
+ name: { kind: "Name", value: "owner" },
36620
+ selectionSet: {
36621
+ kind: "SelectionSet",
36622
+ selections: [
36623
+ {
36624
+ kind: "Field",
36625
+ name: { kind: "Name", value: "id" }
36626
+ }
36627
+ ]
36628
+ }
36629
+ }
36630
+ ]
36631
+ }
36632
+ }
36633
+ ]
36634
+ }
36635
+ }
36636
+ ]
36637
+ }
36638
+ }
36639
+ ]
36640
+ };
36641
+ GetFileProofsDocument = {
36642
+ kind: "Document",
36643
+ definitions: [
36644
+ {
36645
+ kind: "OperationDefinition",
36646
+ operation: "query",
36647
+ name: { kind: "Name", value: "GetFileProofs" },
36648
+ variableDefinitions: [
36649
+ {
36650
+ kind: "VariableDefinition",
36651
+ variable: {
36652
+ kind: "Variable",
36653
+ name: { kind: "Name", value: "fileIds" }
36654
+ },
36655
+ type: {
36656
+ kind: "NonNullType",
36657
+ type: {
36658
+ kind: "ListType",
36659
+ type: {
36660
+ kind: "NonNullType",
36661
+ type: {
36662
+ kind: "NamedType",
36663
+ name: { kind: "Name", value: "BigInt" }
36664
+ }
36665
+ }
36666
+ }
36667
+ }
36668
+ }
36669
+ ],
36670
+ selectionSet: {
36671
+ kind: "SelectionSet",
36672
+ selections: [
36673
+ {
36674
+ kind: "Field",
36675
+ name: { kind: "Name", value: "dataRegistryProofs" },
36676
+ arguments: [
36677
+ {
36678
+ kind: "Argument",
36679
+ name: { kind: "Name", value: "where" },
36680
+ value: {
36681
+ kind: "ObjectValue",
36682
+ fields: [
36683
+ {
36684
+ kind: "ObjectField",
36685
+ name: { kind: "Name", value: "fileId_in" },
36686
+ value: {
36687
+ kind: "Variable",
36688
+ name: { kind: "Name", value: "fileIds" }
36689
+ }
36690
+ }
36691
+ ]
36692
+ }
36693
+ }
36694
+ ],
36695
+ selectionSet: {
36696
+ kind: "SelectionSet",
36697
+ selections: [
36698
+ { kind: "Field", name: { kind: "Name", value: "fileId" } },
36699
+ {
36700
+ kind: "Field",
36701
+ name: { kind: "Name", value: "dlp" },
36702
+ selectionSet: {
36703
+ kind: "SelectionSet",
36704
+ selections: [
36705
+ { kind: "Field", name: { kind: "Name", value: "id" } }
36706
+ ]
36707
+ }
36708
+ }
36709
+ ]
36710
+ }
36711
+ }
36712
+ ]
36713
+ }
36714
+ }
36715
+ ]
36716
+ };
36717
+ GetDlpDocument = {
36718
+ kind: "Document",
36719
+ definitions: [
36720
+ {
36721
+ kind: "OperationDefinition",
36722
+ operation: "query",
36723
+ name: { kind: "Name", value: "GetDLP" },
36724
+ variableDefinitions: [
36725
+ {
36726
+ kind: "VariableDefinition",
36727
+ variable: { kind: "Variable", name: { kind: "Name", value: "id" } },
36728
+ type: {
36729
+ kind: "NonNullType",
36730
+ type: { kind: "NamedType", name: { kind: "Name", value: "ID" } }
36731
+ }
36732
+ }
36733
+ ],
36734
+ selectionSet: {
36735
+ kind: "SelectionSet",
36736
+ selections: [
36737
+ {
36738
+ kind: "Field",
36739
+ name: { kind: "Name", value: "dlp" },
36740
+ arguments: [
36741
+ {
36742
+ kind: "Argument",
36743
+ name: { kind: "Name", value: "id" },
36744
+ value: {
36745
+ kind: "Variable",
36746
+ name: { kind: "Name", value: "id" }
36747
+ }
36748
+ }
36749
+ ],
36750
+ selectionSet: {
36751
+ kind: "SelectionSet",
36752
+ selections: [
36753
+ { kind: "Field", name: { kind: "Name", value: "id" } },
36754
+ { kind: "Field", name: { kind: "Name", value: "name" } },
36755
+ { kind: "Field", name: { kind: "Name", value: "metadata" } },
36756
+ { kind: "Field", name: { kind: "Name", value: "status" } },
36757
+ { kind: "Field", name: { kind: "Name", value: "address" } },
36758
+ { kind: "Field", name: { kind: "Name", value: "owner" } }
36759
+ ]
36760
+ }
36761
+ }
36762
+ ]
36763
+ }
36764
+ }
36765
+ ]
36766
+ };
36767
+ GetSchemaDocument = {
36768
+ kind: "Document",
36769
+ definitions: [
36770
+ {
36771
+ kind: "OperationDefinition",
36772
+ operation: "query",
36773
+ name: { kind: "Name", value: "GetSchema" },
36774
+ variableDefinitions: [
36775
+ {
36776
+ kind: "VariableDefinition",
36777
+ variable: { kind: "Variable", name: { kind: "Name", value: "id" } },
36778
+ type: {
36779
+ kind: "NonNullType",
36780
+ type: { kind: "NamedType", name: { kind: "Name", value: "ID" } }
36781
+ }
36782
+ }
36783
+ ],
36784
+ selectionSet: {
36785
+ kind: "SelectionSet",
36786
+ selections: [
36787
+ {
36788
+ kind: "Field",
36789
+ name: { kind: "Name", value: "schema" },
36790
+ arguments: [
36791
+ {
36792
+ kind: "Argument",
36793
+ name: { kind: "Name", value: "id" },
36794
+ value: {
36795
+ kind: "Variable",
36796
+ name: { kind: "Name", value: "id" }
36797
+ }
36798
+ }
36799
+ ],
36800
+ selectionSet: {
36801
+ kind: "SelectionSet",
36802
+ selections: [
36803
+ { kind: "Field", name: { kind: "Name", value: "id" } },
36804
+ { kind: "Field", name: { kind: "Name", value: "name" } },
36805
+ { kind: "Field", name: { kind: "Name", value: "dialect" } },
36806
+ {
36807
+ kind: "Field",
36808
+ name: { kind: "Name", value: "definitionUrl" }
36809
+ },
36810
+ { kind: "Field", name: { kind: "Name", value: "createdAt" } },
36811
+ {
36812
+ kind: "Field",
36813
+ name: { kind: "Name", value: "createdAtBlock" }
36814
+ },
36815
+ {
36816
+ kind: "Field",
36817
+ name: { kind: "Name", value: "createdTxHash" }
36818
+ },
36819
+ {
36820
+ kind: "Field",
36821
+ name: { kind: "Name", value: "refiners" },
36822
+ selectionSet: {
36823
+ kind: "SelectionSet",
36824
+ selections: [
36825
+ { kind: "Field", name: { kind: "Name", value: "id" } },
36826
+ { kind: "Field", name: { kind: "Name", value: "name" } },
36827
+ { kind: "Field", name: { kind: "Name", value: "owner" } }
36828
+ ]
36829
+ }
36830
+ }
36831
+ ]
36832
+ }
36833
+ }
36834
+ ]
36835
+ }
36836
+ }
36837
+ ]
36838
+ };
36839
+ ListSchemasDocument = {
36840
+ kind: "Document",
36841
+ definitions: [
36842
+ {
36843
+ kind: "OperationDefinition",
36844
+ operation: "query",
36845
+ name: { kind: "Name", value: "ListSchemas" },
36846
+ variableDefinitions: [
36847
+ {
36848
+ kind: "VariableDefinition",
36849
+ variable: {
36850
+ kind: "Variable",
36851
+ name: { kind: "Name", value: "first" }
36852
+ },
36853
+ type: {
36854
+ kind: "NonNullType",
36855
+ type: { kind: "NamedType", name: { kind: "Name", value: "Int" } }
36856
+ }
36857
+ },
36858
+ {
36859
+ kind: "VariableDefinition",
36860
+ variable: { kind: "Variable", name: { kind: "Name", value: "skip" } },
36861
+ type: {
36862
+ kind: "NonNullType",
36863
+ type: { kind: "NamedType", name: { kind: "Name", value: "Int" } }
36864
+ }
36865
+ }
36866
+ ],
36867
+ selectionSet: {
36868
+ kind: "SelectionSet",
36869
+ selections: [
36870
+ {
36871
+ kind: "Field",
36872
+ name: { kind: "Name", value: "schemas" },
36873
+ arguments: [
36874
+ {
36875
+ kind: "Argument",
36876
+ name: { kind: "Name", value: "first" },
36877
+ value: {
36878
+ kind: "Variable",
36879
+ name: { kind: "Name", value: "first" }
36880
+ }
36881
+ },
36882
+ {
36883
+ kind: "Argument",
36884
+ name: { kind: "Name", value: "skip" },
36885
+ value: {
36886
+ kind: "Variable",
36887
+ name: { kind: "Name", value: "skip" }
36888
+ }
36889
+ },
36890
+ {
36891
+ kind: "Argument",
36892
+ name: { kind: "Name", value: "orderBy" },
36893
+ value: { kind: "EnumValue", value: "createdAt" }
36894
+ },
36895
+ {
36896
+ kind: "Argument",
36897
+ name: { kind: "Name", value: "orderDirection" },
36898
+ value: { kind: "EnumValue", value: "desc" }
36899
+ }
36900
+ ],
36901
+ selectionSet: {
36902
+ kind: "SelectionSet",
36903
+ selections: [
36904
+ { kind: "Field", name: { kind: "Name", value: "id" } },
36905
+ { kind: "Field", name: { kind: "Name", value: "name" } },
36906
+ { kind: "Field", name: { kind: "Name", value: "dialect" } },
36907
+ {
36908
+ kind: "Field",
36909
+ name: { kind: "Name", value: "definitionUrl" }
36910
+ },
36911
+ { kind: "Field", name: { kind: "Name", value: "createdAt" } },
36912
+ {
36913
+ kind: "Field",
36914
+ name: { kind: "Name", value: "createdAtBlock" }
36915
+ },
36916
+ {
36917
+ kind: "Field",
36918
+ name: { kind: "Name", value: "createdTxHash" }
36919
+ }
36920
+ ]
36921
+ }
36922
+ }
36923
+ ]
36924
+ }
36925
+ }
36926
+ ]
36927
+ };
36928
+ CountSchemasDocument = {
36929
+ kind: "Document",
36930
+ definitions: [
36931
+ {
36932
+ kind: "OperationDefinition",
36933
+ operation: "query",
36934
+ name: { kind: "Name", value: "CountSchemas" },
36935
+ selectionSet: {
36936
+ kind: "SelectionSet",
36937
+ selections: [
36938
+ {
36939
+ kind: "Field",
36940
+ name: { kind: "Name", value: "schemas" },
36941
+ arguments: [
36942
+ {
36943
+ kind: "Argument",
36944
+ name: { kind: "Name", value: "first" },
36945
+ value: { kind: "IntValue", value: "1000" }
36946
+ }
36947
+ ],
36948
+ selectionSet: {
36949
+ kind: "SelectionSet",
36950
+ selections: [
36951
+ { kind: "Field", name: { kind: "Name", value: "id" } }
36952
+ ]
36953
+ }
36954
+ }
36955
+ ]
36956
+ }
36957
+ }
36958
+ ]
36959
+ };
36217
36960
  }
36218
36961
  });
36219
36962
 
@@ -36275,212 +37018,10 @@ var init_registry = __esm({
36275
37018
  }
36276
37019
  });
36277
37020
 
36278
- // src/generated/subgraph.ts
36279
- var GetSchemaDocument, ListSchemasDocument, CountSchemasDocument;
36280
- var init_subgraph = __esm({
36281
- "src/generated/subgraph.ts"() {
36282
- "use strict";
36283
- GetSchemaDocument = {
36284
- kind: "Document",
36285
- definitions: [
36286
- {
36287
- kind: "OperationDefinition",
36288
- operation: "query",
36289
- name: { kind: "Name", value: "GetSchema" },
36290
- variableDefinitions: [
36291
- {
36292
- kind: "VariableDefinition",
36293
- variable: { kind: "Variable", name: { kind: "Name", value: "id" } },
36294
- type: {
36295
- kind: "NonNullType",
36296
- type: { kind: "NamedType", name: { kind: "Name", value: "ID" } }
36297
- }
36298
- }
36299
- ],
36300
- selectionSet: {
36301
- kind: "SelectionSet",
36302
- selections: [
36303
- {
36304
- kind: "Field",
36305
- name: { kind: "Name", value: "schema" },
36306
- arguments: [
36307
- {
36308
- kind: "Argument",
36309
- name: { kind: "Name", value: "id" },
36310
- value: {
36311
- kind: "Variable",
36312
- name: { kind: "Name", value: "id" }
36313
- }
36314
- }
36315
- ],
36316
- selectionSet: {
36317
- kind: "SelectionSet",
36318
- selections: [
36319
- { kind: "Field", name: { kind: "Name", value: "id" } },
36320
- { kind: "Field", name: { kind: "Name", value: "name" } },
36321
- { kind: "Field", name: { kind: "Name", value: "dialect" } },
36322
- {
36323
- kind: "Field",
36324
- name: { kind: "Name", value: "definitionUrl" }
36325
- },
36326
- { kind: "Field", name: { kind: "Name", value: "createdAt" } },
36327
- {
36328
- kind: "Field",
36329
- name: { kind: "Name", value: "createdAtBlock" }
36330
- },
36331
- {
36332
- kind: "Field",
36333
- name: { kind: "Name", value: "createdTxHash" }
36334
- },
36335
- {
36336
- kind: "Field",
36337
- name: { kind: "Name", value: "refiners" },
36338
- selectionSet: {
36339
- kind: "SelectionSet",
36340
- selections: [
36341
- { kind: "Field", name: { kind: "Name", value: "id" } },
36342
- { kind: "Field", name: { kind: "Name", value: "name" } },
36343
- { kind: "Field", name: { kind: "Name", value: "owner" } }
36344
- ]
36345
- }
36346
- }
36347
- ]
36348
- }
36349
- }
36350
- ]
36351
- }
36352
- }
36353
- ]
36354
- };
36355
- ListSchemasDocument = {
36356
- kind: "Document",
36357
- definitions: [
36358
- {
36359
- kind: "OperationDefinition",
36360
- operation: "query",
36361
- name: { kind: "Name", value: "ListSchemas" },
36362
- variableDefinitions: [
36363
- {
36364
- kind: "VariableDefinition",
36365
- variable: {
36366
- kind: "Variable",
36367
- name: { kind: "Name", value: "first" }
36368
- },
36369
- type: {
36370
- kind: "NonNullType",
36371
- type: { kind: "NamedType", name: { kind: "Name", value: "Int" } }
36372
- }
36373
- },
36374
- {
36375
- kind: "VariableDefinition",
36376
- variable: { kind: "Variable", name: { kind: "Name", value: "skip" } },
36377
- type: {
36378
- kind: "NonNullType",
36379
- type: { kind: "NamedType", name: { kind: "Name", value: "Int" } }
36380
- }
36381
- }
36382
- ],
36383
- selectionSet: {
36384
- kind: "SelectionSet",
36385
- selections: [
36386
- {
36387
- kind: "Field",
36388
- name: { kind: "Name", value: "schemas" },
36389
- arguments: [
36390
- {
36391
- kind: "Argument",
36392
- name: { kind: "Name", value: "first" },
36393
- value: {
36394
- kind: "Variable",
36395
- name: { kind: "Name", value: "first" }
36396
- }
36397
- },
36398
- {
36399
- kind: "Argument",
36400
- name: { kind: "Name", value: "skip" },
36401
- value: {
36402
- kind: "Variable",
36403
- name: { kind: "Name", value: "skip" }
36404
- }
36405
- },
36406
- {
36407
- kind: "Argument",
36408
- name: { kind: "Name", value: "orderBy" },
36409
- value: { kind: "EnumValue", value: "createdAt" }
36410
- },
36411
- {
36412
- kind: "Argument",
36413
- name: { kind: "Name", value: "orderDirection" },
36414
- value: { kind: "EnumValue", value: "desc" }
36415
- }
36416
- ],
36417
- selectionSet: {
36418
- kind: "SelectionSet",
36419
- selections: [
36420
- { kind: "Field", name: { kind: "Name", value: "id" } },
36421
- { kind: "Field", name: { kind: "Name", value: "name" } },
36422
- { kind: "Field", name: { kind: "Name", value: "dialect" } },
36423
- {
36424
- kind: "Field",
36425
- name: { kind: "Name", value: "definitionUrl" }
36426
- },
36427
- { kind: "Field", name: { kind: "Name", value: "createdAt" } },
36428
- {
36429
- kind: "Field",
36430
- name: { kind: "Name", value: "createdAtBlock" }
36431
- },
36432
- {
36433
- kind: "Field",
36434
- name: { kind: "Name", value: "createdTxHash" }
36435
- }
36436
- ]
36437
- }
36438
- }
36439
- ]
36440
- }
36441
- }
36442
- ]
36443
- };
36444
- CountSchemasDocument = {
36445
- kind: "Document",
36446
- definitions: [
36447
- {
36448
- kind: "OperationDefinition",
36449
- operation: "query",
36450
- name: { kind: "Name", value: "CountSchemas" },
36451
- selectionSet: {
36452
- kind: "SelectionSet",
36453
- selections: [
36454
- {
36455
- kind: "Field",
36456
- name: { kind: "Name", value: "schemas" },
36457
- arguments: [
36458
- {
36459
- kind: "Argument",
36460
- name: { kind: "Name", value: "first" },
36461
- value: { kind: "IntValue", value: "1000" }
36462
- }
36463
- ],
36464
- selectionSet: {
36465
- kind: "SelectionSet",
36466
- selections: [
36467
- { kind: "Field", name: { kind: "Name", value: "id" } }
36468
- ]
36469
- }
36470
- }
36471
- ]
36472
- }
36473
- }
36474
- ]
36475
- };
36476
- }
36477
- });
36478
-
36479
37021
  // src/utils/urlResolver.ts
36480
- async function fetchFromUrl(url) {
37022
+ async function fetchFromUrl(url, downloadRelayer) {
36481
37023
  try {
36482
- const httpUrl = resolveToHttp(url);
36483
- const response = await fetchWithRetry(httpUrl, url);
37024
+ const response = await fetchWithRelayer(url, downloadRelayer);
36484
37025
  if (!response.ok) {
36485
37026
  throw new Error(`HTTP ${response.status}: ${response.statusText}`);
36486
37027
  }
@@ -36494,43 +37035,11 @@ async function fetchFromUrl(url) {
36494
37035
  );
36495
37036
  }
36496
37037
  }
36497
- function resolveToHttp(url) {
36498
- if (url.startsWith("ipfs://")) {
36499
- return convertIpfsUrl(url);
36500
- }
36501
- if (url.startsWith("ar://")) {
36502
- const txId = url.replace("ar://", "");
36503
- return `https://arweave.net/${txId}`;
36504
- }
36505
- if (url.startsWith("https://") || url.startsWith("http://")) {
36506
- return url;
36507
- }
36508
- throw new Error(`Unsupported protocol in URL: ${url}`);
36509
- }
36510
- async function fetchWithRetry(httpUrl, originalUrl) {
36511
- try {
36512
- const response = await fetch(httpUrl);
36513
- if (response.ok) return response;
36514
- } catch {
36515
- }
36516
- if (originalUrl.startsWith("ipfs://")) {
36517
- for (const gateway of IPFS_GATEWAYS) {
36518
- try {
36519
- const alternativeUrl = convertIpfsUrl(originalUrl, gateway);
36520
- if (alternativeUrl === httpUrl) continue;
36521
- const response = await fetch(alternativeUrl);
36522
- if (response.ok) return response;
36523
- } catch {
36524
- }
36525
- }
36526
- }
36527
- return fetch(httpUrl);
36528
- }
36529
37038
  var UrlResolutionError;
36530
37039
  var init_urlResolver = __esm({
36531
37040
  "src/utils/urlResolver.ts"() {
36532
37041
  "use strict";
36533
- init_ipfs();
37042
+ init_download();
36534
37043
  UrlResolutionError = class extends Error {
36535
37044
  constructor(message, url, cause) {
36536
37045
  super(message);
@@ -36623,7 +37132,7 @@ var init_schemas = __esm({
36623
37132
  dialect,
36624
37133
  schema: schemaDefinition
36625
37134
  };
36626
- validateDataSchema(dataSchema);
37135
+ validateDataSchemaAgainstMetaSchema(dataSchema);
36627
37136
  if (!this.context.storageManager) {
36628
37137
  if (this.context.validateStorageRequired) {
36629
37138
  this.context.validateStorageRequired();
@@ -36726,13 +37235,16 @@ var init_schemas = __esm({
36726
37235
  );
36727
37236
  }
36728
37237
  }
36729
- const definition = await fetchFromUrl(metadata.definitionUrl);
37238
+ const definition = await fetchFromUrl(
37239
+ metadata.definitionUrl,
37240
+ this.context.downloadRelayer
37241
+ );
36730
37242
  if (!definition || typeof definition !== "object") {
36731
37243
  throw new Error(
36732
37244
  `Invalid schema definition format for schema ${schemaId}`
36733
37245
  );
36734
37246
  }
36735
- validateDataSchema(definition);
37247
+ validateDataSchemaAgainstMetaSchema(definition);
36736
37248
  const dataSchema = definition;
36737
37249
  if (dataSchema.name !== metadata.name) {
36738
37250
  throw new Error(
@@ -37065,9 +37577,12 @@ var init_schemas = __esm({
37065
37577
  schemas.map(async (schema) => {
37066
37578
  if (!schema.definitionUrl) return;
37067
37579
  try {
37068
- const definition = await fetchFromUrl(schema.definitionUrl);
37580
+ const definition = await fetchFromUrl(
37581
+ schema.definitionUrl,
37582
+ this.context.downloadRelayer
37583
+ );
37069
37584
  if (definition && typeof definition === "object") {
37070
- validateDataSchema(definition);
37585
+ validateDataSchemaAgainstMetaSchema(definition);
37071
37586
  const dataSchema = definition;
37072
37587
  schema.version = dataSchema.version;
37073
37588
  schema.description = dataSchema.description;
@@ -37159,6 +37674,7 @@ init_transactionHandle();
37159
37674
  init_errors();
37160
37675
  init_addresses();
37161
37676
  init_abi();
37677
+ import { getAddress as getAddress3 } from "viem";
37162
37678
 
37163
37679
  // src/utils/grantFiles.ts
37164
37680
  init_errors();
@@ -37207,63 +37723,26 @@ async function storeGrantFile(grantFile, relayerUrl) {
37207
37723
  );
37208
37724
  }
37209
37725
  }
37210
- async function retrieveGrantFile(grantUrl, _relayerUrl) {
37726
+ async function retrieveGrantFile(grantUrl, _relayerUrl, downloadRelayer) {
37211
37727
  try {
37212
37728
  if (grantUrl.startsWith("http") && grantUrl.includes("/ipfs/")) {
37213
37729
  console.warn(
37214
37730
  `\u26A0\uFE0F Grant URL uses HTTP gateway format instead of ipfs:// protocol. Found: ${grantUrl}. Consider using ipfs:// format for better protocol-agnostic storage.`
37215
37731
  );
37216
37732
  }
37217
- if (grantUrl.startsWith("http")) {
37218
- try {
37219
- const timeoutPromise = new Promise((_, reject) => {
37220
- setTimeout(() => reject(new Error("Request timeout")), 1e4);
37221
- });
37222
- const response = await Promise.race([fetch(grantUrl), timeoutPromise]);
37223
- if (response.ok) {
37224
- const text = await response.text();
37225
- const grantFile = JSON.parse(text);
37226
- if (validateGrantFile(grantFile)) {
37227
- return grantFile;
37228
- }
37229
- }
37230
- } catch (directFetchError) {
37231
- console.warn(`Direct fetch failed for ${grantUrl}:`, directFetchError);
37232
- }
37733
+ const { fetchWithRelayer: fetchWithRelayer2 } = await Promise.resolve().then(() => (init_download(), download_exports));
37734
+ const response = await fetchWithRelayer2(grantUrl, downloadRelayer);
37735
+ if (!response.ok) {
37736
+ throw new NetworkError(
37737
+ `Failed to retrieve grant file: HTTP ${response.status}`
37738
+ );
37233
37739
  }
37234
- const { extractIpfsHash: extractIpfsHash2 } = await Promise.resolve().then(() => (init_ipfs(), ipfs_exports));
37235
- const ipfsHash = extractIpfsHash2(grantUrl);
37236
- if (ipfsHash) {
37237
- const gateways = [
37238
- `https://gateway.pinata.cloud/ipfs/${ipfsHash}`,
37239
- `https://ipfs.io/ipfs/${ipfsHash}`,
37240
- `https://dweb.link/ipfs/${ipfsHash}`
37241
- ];
37242
- for (const gatewayUrl of gateways) {
37243
- try {
37244
- const timeoutPromise = new Promise((_, reject) => {
37245
- setTimeout(() => reject(new Error("Request timeout")), 1e4);
37246
- });
37247
- const response = await Promise.race([
37248
- fetch(gatewayUrl),
37249
- timeoutPromise
37250
- ]);
37251
- if (response.ok) {
37252
- const text = await response.text();
37253
- const grantFile = JSON.parse(text);
37254
- if (validateGrantFile(grantFile)) {
37255
- return grantFile;
37256
- }
37257
- }
37258
- } catch (gatewayError) {
37259
- console.warn(`Gateway ${gatewayUrl} failed:`, gatewayError);
37260
- continue;
37261
- }
37262
- }
37740
+ const text = await response.text();
37741
+ const grantFile = JSON.parse(text);
37742
+ if (!validateGrantFile(grantFile)) {
37743
+ throw new NetworkError(`Invalid grant file format from ${grantUrl}`);
37263
37744
  }
37264
- throw new NetworkError(
37265
- `Failed to retrieve grant file from ${grantUrl}. Tried direct fetch${ipfsHash ? " and IPFS gateways" : ""}.`
37266
- );
37745
+ return grantFile;
37267
37746
  } catch (error) {
37268
37747
  if (error instanceof NetworkError) {
37269
37748
  throw error;
@@ -37329,6 +37808,7 @@ function validateGrantFile(data) {
37329
37808
  }
37330
37809
 
37331
37810
  // src/utils/grantValidation.ts
37811
+ import { getAddress } from "viem";
37332
37812
  import Ajv2 from "ajv";
37333
37813
  import addFormats2 from "ajv-formats";
37334
37814
 
@@ -37532,7 +38012,9 @@ function extractFieldFromBusinessError(error) {
37532
38012
  return void 0;
37533
38013
  }
37534
38014
  function validateGranteeAccess(grantFile, requestingAddress) {
37535
- if (grantFile.grantee.toLowerCase() !== requestingAddress.toLowerCase()) {
38015
+ const normalizedGrantee = getAddress(grantFile.grantee);
38016
+ const normalizedRequesting = getAddress(requestingAddress);
38017
+ if (normalizedGrantee !== normalizedRequesting) {
37536
38018
  throw new GranteeMismatchError(
37537
38019
  "Permission denied: requesting address does not match grantee",
37538
38020
  grantFile.grantee,
@@ -37564,6 +38046,7 @@ function validateOperationAccess(grantFile, requestedOperation) {
37564
38046
 
37565
38047
  // src/utils/signatureCache.ts
37566
38048
  init_crypto_utils();
38049
+ import { getAddress as getAddress2 } from "viem";
37567
38050
  var SignatureCache = class {
37568
38051
  /**
37569
38052
  * Get a cached signature if it exists and hasn't expired
@@ -37654,7 +38137,7 @@ var SignatureCache = class {
37654
38137
  }
37655
38138
  }
37656
38139
  static getCacheKey(walletAddress, messageHash) {
37657
- return `${this.PREFIX}${walletAddress.toLowerCase()}:${messageHash}`;
38140
+ return `${this.PREFIX}${getAddress2(walletAddress)}:${messageHash}`;
37658
38141
  }
37659
38142
  /**
37660
38143
  * Generate a deterministic hash of a message object for cache key generation
@@ -38929,20 +39412,22 @@ var PermissionsController = class {
38929
39412
  if (!userData || !userData.permissions?.length) {
38930
39413
  return [];
38931
39414
  }
38932
- const onChainGrants = userData.permissions.slice(0, limit).map((permission) => ({
38933
- id: BigInt(permission.id),
38934
- grantUrl: permission.grant,
38935
- grantSignature: permission.signature,
38936
- grantHash: "",
38937
- // Not available in new schema, compute if needed
38938
- nonce: BigInt(permission.nonce),
38939
- addedAtBlock: BigInt(permission.addedAtBlock),
38940
- addedAtTimestamp: BigInt(permission.addedAtTimestamp || "0"),
38941
- transactionHash: permission.transactionHash || "",
38942
- grantor: userAddress,
38943
- active: !permission.endBlock || BigInt(permission.endBlock) === 0n
38944
- // Active if no end block or end block is 0
38945
- }));
39415
+ const onChainGrants = userData.permissions.slice(0, limit).map(
39416
+ (permission) => ({
39417
+ id: BigInt(permission.id),
39418
+ grantUrl: permission.grant,
39419
+ grantSignature: permission.signature,
39420
+ nonce: BigInt(permission.nonce),
39421
+ startBlock: BigInt(permission.startBlock),
39422
+ addedAtBlock: BigInt(permission.addedAtBlock),
39423
+ addedAtTimestamp: BigInt(permission.addedAtTimestamp || "0"),
39424
+ transactionHash: permission.transactionHash || "",
39425
+ grantor: userAddress,
39426
+ grantee: permission.grantee,
39427
+ active: !permission.endBlock || BigInt(permission.endBlock) === 0n
39428
+ // Active if no end block or end block is 0
39429
+ })
39430
+ );
38946
39431
  return onChainGrants.sort((a, b) => {
38947
39432
  if (a.id < b.id) return 1;
38948
39433
  if (a.id > b.id) return -1;
@@ -39020,14 +39505,16 @@ var PermissionsController = class {
39020
39505
  );
39021
39506
  const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
39022
39507
  const userAddress = this.context.walletClient.account?.address || await this.getUserAddress();
39508
+ const normalizedUserAddress = getAddress3(userAddress);
39509
+ const normalizedServerAddress = getAddress3(params.serverAddress);
39023
39510
  const txHash = await this.context.walletClient.writeContract({
39024
39511
  address: DataPortabilityServersAddress,
39025
39512
  abi: DataPortabilityServersAbi,
39026
39513
  functionName: "addAndTrustServerByManager",
39027
39514
  args: [
39028
- userAddress,
39515
+ normalizedUserAddress,
39029
39516
  {
39030
- serverAddress: params.serverAddress,
39517
+ serverAddress: normalizedServerAddress,
39031
39518
  serverUrl: params.serverUrl,
39032
39519
  publicKey: params.publicKey
39033
39520
  }
@@ -39097,9 +39584,10 @@ var PermissionsController = class {
39097
39584
  async submitAddAndTrustServerWithSignature(params) {
39098
39585
  try {
39099
39586
  const nonce = await this.getServersUserNonce();
39587
+ const serverAddress = getAddress3(params.serverAddress);
39100
39588
  const addAndTrustServerInput = {
39101
39589
  nonce,
39102
- serverAddress: params.serverAddress,
39590
+ serverAddress,
39103
39591
  publicKey: params.publicKey,
39104
39592
  serverUrl: params.serverUrl
39105
39593
  };
@@ -39904,11 +40392,13 @@ var PermissionsController = class {
39904
40392
  "DataPortabilityGrantees"
39905
40393
  );
39906
40394
  const DataPortabilityGranteesAbi = getAbi("DataPortabilityGrantees");
40395
+ const ownerAddress = getAddress3(params.owner);
40396
+ const granteeAddress = getAddress3(params.granteeAddress);
39907
40397
  const txHash = await this.context.walletClient.writeContract({
39908
40398
  address: DataPortabilityGranteesAddress,
39909
40399
  abi: DataPortabilityGranteesAbi,
39910
40400
  functionName: "registerGrantee",
39911
- args: [params.owner, params.granteeAddress, params.publicKey],
40401
+ args: [ownerAddress, granteeAddress, params.publicKey],
39912
40402
  account: this.context.walletClient.account || await this.getUserAddress(),
39913
40403
  chain: this.context.walletClient.chain || null
39914
40404
  });
@@ -39935,10 +40425,12 @@ var PermissionsController = class {
39935
40425
  */
39936
40426
  async submitRegisterGranteeWithSignature(params) {
39937
40427
  const nonce = await this.getServersUserNonce();
40428
+ const owner = getAddress3(params.owner);
40429
+ const granteeAddress = getAddress3(params.granteeAddress);
39938
40430
  const registerGranteeInput = {
39939
40431
  nonce,
39940
- owner: params.owner,
39941
- granteeAddress: params.granteeAddress,
40432
+ owner,
40433
+ granteeAddress,
39942
40434
  publicKey: params.publicKey
39943
40435
  };
39944
40436
  const typedData = await this.buildRegisterGranteeTypedData(registerGranteeInput);
@@ -41449,7 +41941,9 @@ var PermissionsController = class {
41449
41941
  init_transactionHandle();
41450
41942
  init_addresses();
41451
41943
  init_abi();
41944
+ init_subgraph();
41452
41945
  import { getContract as getContract2 } from "viem";
41946
+ import { print as print2 } from "graphql";
41453
41947
 
41454
41948
  // src/utils/encryption.ts
41455
41949
  var DEFAULT_ENCRYPTION_SEED = "Please sign to retrieve your encryption key";
@@ -41873,34 +42367,16 @@ var DataController = class {
41873
42367
  );
41874
42368
  }
41875
42369
  try {
41876
- const query = `
41877
- query GetUserFiles($userId: ID!) {
41878
- user(id: $userId) {
41879
- id
41880
- files {
41881
- id
41882
- url
41883
- schemaId
41884
- addedAtBlock
41885
- addedAtTimestamp
41886
- transactionHash
41887
- owner {
41888
- id
41889
- }
41890
- }
41891
- }
41892
- }
41893
- `;
41894
42370
  const response = await fetch(endpoint, {
41895
42371
  method: "POST",
41896
42372
  headers: {
41897
42373
  "Content-Type": "application/json"
41898
42374
  },
41899
42375
  body: JSON.stringify({
41900
- query,
42376
+ query: print2(GetUserFilesDocument),
41901
42377
  variables: {
41902
42378
  userId: owner.toLowerCase()
41903
- // Subgraph stores addresses in lowercase
42379
+ // Subgraph requires lowercase addresses
41904
42380
  }
41905
42381
  })
41906
42382
  });
@@ -41947,7 +42423,10 @@ var DataController = class {
41947
42423
  try {
41948
42424
  proofMap = await this._fetchProofsFromSubgraph(fileIds, endpoint);
41949
42425
  } catch (subgraphError) {
41950
- console.debug("Failed to fetch proofs from subgraph, trying chain:", subgraphError);
42426
+ console.debug(
42427
+ "Failed to fetch proofs from subgraph, trying chain:",
42428
+ subgraphError
42429
+ );
41951
42430
  proofMap = await this._fetchProofsFromChain(fileIds);
41952
42431
  }
41953
42432
  for (const file of userFiles) {
@@ -41970,30 +42449,20 @@ var DataController = class {
41970
42449
  }
41971
42450
  /**
41972
42451
  * Fetches proof data for multiple files from the subgraph.
41973
- *
42452
+ *
41974
42453
  * @private
41975
42454
  * @param fileIds - Array of file IDs to fetch proofs for
41976
42455
  * @param subgraphUrl - The subgraph endpoint URL
41977
42456
  * @returns Map of file IDs to their associated DLP IDs
41978
42457
  */
41979
42458
  async _fetchProofsFromSubgraph(fileIds, subgraphUrl) {
41980
- const query = `
41981
- query GetFileProofs($fileIds: [BigInt!]!) {
41982
- dataRegistryProofs(where: { fileId_in: $fileIds }) {
41983
- fileId
41984
- dlp {
41985
- id
41986
- }
41987
- }
41988
- }
41989
- `;
41990
42459
  const response = await fetch(subgraphUrl, {
41991
42460
  method: "POST",
41992
42461
  headers: {
41993
42462
  "Content-Type": "application/json"
41994
42463
  },
41995
42464
  body: JSON.stringify({
41996
- query,
42465
+ query: print2(GetFileProofsDocument),
41997
42466
  variables: {
41998
42467
  fileIds: fileIds.map((id) => id.toString())
41999
42468
  }
@@ -42031,7 +42500,7 @@ var DataController = class {
42031
42500
  /**
42032
42501
  * Fetches proof data for multiple files from the blockchain.
42033
42502
  * Falls back to this when subgraph is unavailable.
42034
- *
42503
+ *
42035
42504
  * @private
42036
42505
  * @param fileIds - Array of file IDs to fetch proofs for
42037
42506
  * @returns Map of file IDs to their associated DLP IDs
@@ -42097,25 +42566,13 @@ var DataController = class {
42097
42566
  const subgraphUrl = options.subgraphUrl || this.context.subgraphUrl;
42098
42567
  if (subgraphUrl) {
42099
42568
  try {
42100
- const query = `
42101
- query GetDLP($id: ID!) {
42102
- dlp(id: $id) {
42103
- id
42104
- name
42105
- metadata
42106
- status
42107
- address
42108
- owner
42109
- }
42110
- }
42111
- `;
42112
42569
  const response = await fetch(subgraphUrl, {
42113
42570
  method: "POST",
42114
42571
  headers: {
42115
42572
  "Content-Type": "application/json"
42116
42573
  },
42117
42574
  body: JSON.stringify({
42118
- query,
42575
+ query: print2(GetDlpDocument),
42119
42576
  variables: {
42120
42577
  id: dlpId.toString()
42121
42578
  }
@@ -42138,7 +42595,7 @@ var DataController = class {
42138
42595
  return {
42139
42596
  id: parseInt(result.data.dlp.id),
42140
42597
  name: result.data.dlp.name || "",
42141
- metadata: result.data.dlp.metadata,
42598
+ metadata: result.data.dlp.metadata || void 0,
42142
42599
  status: result.data.dlp.status ? parseInt(result.data.dlp.status) : void 0,
42143
42600
  address: result.data.dlp.address,
42144
42601
  owner: result.data.dlp.owner
@@ -42195,7 +42652,7 @@ var DataController = class {
42195
42652
  * // Get first 10 DLPs
42196
42653
  * const dlps = await vana.data.listDLPs({ limit: 10 });
42197
42654
  * dlps.forEach(dlp => console.log(`${dlp.id}: ${dlp.name}`));
42198
- *
42655
+ *
42199
42656
  * // Get next page
42200
42657
  * const nextPage = await vana.data.listDLPs({ limit: 10, offset: 10 });
42201
42658
  * ```
@@ -42352,32 +42809,13 @@ var DataController = class {
42352
42809
  async _getUserPermissionsViaSubgraph(params) {
42353
42810
  const { user, subgraphUrl } = params;
42354
42811
  try {
42355
- const query = `
42356
- query GetUserPermissions($userId: ID!) {
42357
- user(id: $userId) {
42358
- id
42359
- permissions {
42360
- id
42361
- grant
42362
- nonce
42363
- signature
42364
- addedAtBlock
42365
- addedAtTimestamp
42366
- transactionHash
42367
- user {
42368
- id
42369
- }
42370
- }
42371
- }
42372
- }
42373
- `;
42374
42812
  const response = await fetch(subgraphUrl, {
42375
42813
  method: "POST",
42376
42814
  headers: {
42377
42815
  "Content-Type": "application/json"
42378
42816
  },
42379
42817
  body: JSON.stringify({
42380
- query,
42818
+ query: print2(GetUserPermissionsDocument),
42381
42819
  variables: {
42382
42820
  userId: user.toLowerCase()
42383
42821
  }
@@ -42406,7 +42844,7 @@ var DataController = class {
42406
42844
  addedAtBlock: BigInt(permission.addedAtBlock),
42407
42845
  addedAtTimestamp: BigInt(permission.addedAtTimestamp),
42408
42846
  transactionHash: permission.transactionHash,
42409
- user: permission.user.id
42847
+ user
42410
42848
  })).sort((a, b) => Number(b.addedAtTimestamp - a.addedAtTimestamp));
42411
42849
  } catch (error) {
42412
42850
  console.error("Failed to query user permissions from subgraph:", error);
@@ -42578,36 +43016,16 @@ var DataController = class {
42578
43016
  );
42579
43017
  }
42580
43018
  try {
42581
- const query = `
42582
- query GetUserTrustedServers($userId: ID!) {
42583
- user(id: $userId) {
42584
- id
42585
- serverTrusts {
42586
- id
42587
- server {
42588
- id
42589
- serverAddress
42590
- url
42591
- publicKey
42592
- }
42593
- trustedAt
42594
- trustedAtBlock
42595
- untrustedAtBlock
42596
- transactionHash
42597
- }
42598
- }
42599
- }
42600
- `;
42601
43019
  const response = await fetch(graphqlEndpoint, {
42602
43020
  method: "POST",
42603
43021
  headers: {
42604
43022
  "Content-Type": "application/json"
42605
43023
  },
42606
43024
  body: JSON.stringify({
42607
- query,
43025
+ query: print2(GetUserTrustedServersDocument),
42608
43026
  variables: {
42609
43027
  userId: user.toLowerCase()
42610
- // Subgraph stores addresses in lowercase
43028
+ // Subgraph requires lowercase addresses
42611
43029
  }
42612
43030
  })
42613
43031
  });
@@ -43441,19 +43859,31 @@ var DataController = class {
43441
43859
  return await this.submitFilePermission(fileId, account, publicKey);
43442
43860
  }
43443
43861
  /**
43444
- * Submits a file permission transaction and returns the transaction hash immediately.
43862
+ * Submits a file permission transaction to the blockchain.
43445
43863
  *
43446
- * This is the lower-level method that provides maximum control over transaction timing.
43864
+ * @remarks
43865
+ * This method supports gasless transactions via relayer callbacks when configured.
43866
+ * It encrypts the user's encryption key with the recipient's public key before submission.
43447
43867
  * Use this when you want to handle transaction confirmation and event parsing separately.
43448
43868
  *
43449
- * @param fileId - The ID of the file to add permissions for
43450
- * @param account - The address of the account to grant permission to
43451
- * @param publicKey - The public key to encrypt the user's encryption key with
43452
- * @returns Promise resolving to the transaction hash
43869
+ * @param fileId - The ID of the file to grant permission for
43870
+ * @param account - The recipient's wallet address that will access the file
43871
+ * @param publicKey - The recipient's public key for encryption.
43872
+ * Obtain via `vana.server.getIdentity(account).public_key`
43873
+ * @returns Promise resolving to TransactionHandle for tracking the transaction
43874
+ * @throws {Error} When chain ID is not available
43875
+ * @throws {Error} When encryption key generation fails
43876
+ * @throws {Error} When public key encryption fails
43877
+ *
43453
43878
  * @example
43454
43879
  * ```typescript
43455
- * const txHash = await vana.data.submitFilePermission(fileId, account, publicKey);
43456
- * console.log(`Transaction submitted: ${txHash}`);
43880
+ * const tx = await vana.data.submitFilePermission(
43881
+ * fileId,
43882
+ * "0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36",
43883
+ * recipientPublicKey
43884
+ * );
43885
+ * const result = await tx.waitForEvents();
43886
+ * console.log(`Permission granted with ID: ${result.permissionId}`);
43457
43887
  * ```
43458
43888
  */
43459
43889
  async submitFilePermission(fileId, account, publicKey) {
@@ -43605,7 +44035,11 @@ var DataController = class {
43605
44035
  */
43606
44036
  async fetch(url) {
43607
44037
  try {
43608
- const response = await fetch(url);
44038
+ const { fetchWithRelayer: fetchWithRelayer2 } = await Promise.resolve().then(() => (init_download(), download_exports));
44039
+ const response = await fetchWithRelayer2(
44040
+ url,
44041
+ this.context.downloadRelayer
44042
+ );
43609
44043
  if (!response.ok) {
43610
44044
  throw new Error(
43611
44045
  `HTTP error! status: ${response.status} ${response.statusText}`
@@ -43671,12 +44105,9 @@ var DataController = class {
43671
44105
  "https://ipfs.io/ipfs/"
43672
44106
  ];
43673
44107
  const gateways = options?.gateways || this.context.ipfsGateways || defaultGateways;
43674
- let cid;
43675
- if (url.startsWith("ipfs://")) {
43676
- cid = url.replace("ipfs://", "");
43677
- } else if (url.startsWith("Qm") || url.startsWith("bafy")) {
43678
- cid = url;
43679
- } else {
44108
+ const { extractIpfsHash: extractIpfsHash2 } = await Promise.resolve().then(() => (init_ipfs(), ipfs_exports));
44109
+ const cid = extractIpfsHash2(url);
44110
+ if (!cid) {
43680
44111
  throw new Error(
43681
44112
  `Invalid IPFS URL format. Expected ipfs://... or a raw CID, got: ${url}`
43682
44113
  );
@@ -43730,6 +44161,17 @@ var DataController = class {
43730
44161
  });
43731
44162
  }
43732
44163
  }
44164
+ if (this.context.downloadRelayer && gateways.length > 0) {
44165
+ try {
44166
+ const relayerUrl = gateways[0].endsWith("/") ? `${gateways[0]}${cid}` : `${gateways[0]}/${cid}`;
44167
+ return await this.context.downloadRelayer.proxyDownload(relayerUrl);
44168
+ } catch (relayerError) {
44169
+ errors.push({
44170
+ gateway: "download-relayer",
44171
+ error: `Proxy failed: ${relayerError instanceof Error ? relayerError.message : "Unknown error"}`
44172
+ });
44173
+ }
44174
+ }
43733
44175
  const errorDetails = errors.map((e) => `${e.gateway}: ${e.error}`).join("\n ");
43734
44176
  throw new Error(
43735
44177
  `Failed to fetch IPFS content ${cid} from all gateways:
@@ -43737,10 +44179,10 @@ var DataController = class {
43737
44179
  );
43738
44180
  }
43739
44181
  /**
43740
- * Validates a data schema against the Vana meta-schema.
44182
+ * Validates a data schema definition against the Vana meta-schema.
43741
44183
  *
43742
- * @param schema - The data schema to validate
43743
- * @returns Assertion that schema is valid (throws if invalid)
44184
+ * @param schema - The data schema definition to validate
44185
+ * @returns The validated DataSchema
43744
44186
  * @throws SchemaValidationError if invalid
43745
44187
  * @example
43746
44188
  * ```typescript
@@ -43757,11 +44199,11 @@ var DataController = class {
43757
44199
  * }
43758
44200
  * };
43759
44201
  *
43760
- * vana.data.validateDataSchema(schema);
44202
+ * const validatedSchema = vana.data.validateDataSchemaAgainstMetaSchema(schema);
43761
44203
  * ```
43762
44204
  */
43763
- validateDataSchema(schema) {
43764
- return validateDataSchema(schema);
44205
+ validateDataSchemaAgainstMetaSchema(schema) {
44206
+ return validateDataSchemaAgainstMetaSchema(schema);
43765
44207
  }
43766
44208
  /**
43767
44209
  * Validates data against a JSON Schema from a data schema.
@@ -43794,9 +44236,9 @@ var DataController = class {
43794
44236
  return validateDataAgainstSchema(data, schema);
43795
44237
  }
43796
44238
  /**
43797
- * Fetches and validates a schema from a URL, then returns the parsed data schema.
44239
+ * Fetches and validates a data schema from a URL, then returns the parsed data schema.
43798
44240
  *
43799
- * @param url - The URL to fetch the schema from
44241
+ * @param url - The URL to fetch the data schema from
43800
44242
  * @returns The validated data schema
43801
44243
  * @throws SchemaValidationError if invalid or fetch fails
43802
44244
  * @example
@@ -43821,6 +44263,73 @@ init_schemas();
43821
44263
 
43822
44264
  // src/controllers/server.ts
43823
44265
  init_errors();
44266
+
44267
+ // src/utils/operationHandle.ts
44268
+ init_errors();
44269
+ var OperationHandle = class {
44270
+ constructor(controller, id) {
44271
+ this.controller = controller;
44272
+ this.id = id;
44273
+ __publicField(this, "_resultPromise");
44274
+ }
44275
+ /**
44276
+ * Waits for the operation to complete and returns the result.
44277
+ *
44278
+ * @remarks
44279
+ * Results are memoized - multiple calls return the same promise.
44280
+ * The method polls the server at regular intervals until the operation
44281
+ * succeeds, fails, or times out. Returns the raw string result from the
44282
+ * server - callers are responsible for parsing if needed.
44283
+ *
44284
+ * @param options - Optional polling configuration
44285
+ * @returns The operation result as a string when completed
44286
+ * @throws {PersonalServerError} When the operation fails or times out
44287
+ * @example
44288
+ * ```typescript
44289
+ * const result = await handle.waitForResult({
44290
+ * timeout: 60000,
44291
+ * pollingInterval: 500
44292
+ * });
44293
+ * // If expecting JSON, parse it:
44294
+ * const data = JSON.parse(result);
44295
+ * ```
44296
+ */
44297
+ async waitForResult(options) {
44298
+ if (!this._resultPromise) {
44299
+ this._resultPromise = this.pollForCompletion(options);
44300
+ }
44301
+ return this._resultPromise;
44302
+ }
44303
+ async pollForCompletion(options) {
44304
+ const startTime = Date.now();
44305
+ const timeout = options?.timeout ?? 3e4;
44306
+ const interval = options?.pollingInterval ?? 500;
44307
+ while (true) {
44308
+ const result = await this.controller.getOperation(
44309
+ this.id
44310
+ );
44311
+ if (result.status === "succeeded") {
44312
+ if (result.result) {
44313
+ return result.result;
44314
+ }
44315
+ throw new PersonalServerError(
44316
+ "Operation succeeded but returned no result"
44317
+ );
44318
+ }
44319
+ if (result.status === "failed") {
44320
+ throw new PersonalServerError(
44321
+ `Operation ${result.status}: ${result.result || "Unknown error"}`
44322
+ );
44323
+ }
44324
+ if (Date.now() - startTime > timeout) {
44325
+ throw new PersonalServerError(`Operation timed out after ${timeout}ms`);
44326
+ }
44327
+ await new Promise((resolve) => setTimeout(resolve, interval));
44328
+ }
44329
+ }
44330
+ };
44331
+
44332
+ // src/controllers/server.ts
43824
44333
  var ServerController = class {
43825
44334
  constructor(context) {
43826
44335
  this.context = context;
@@ -43902,26 +44411,29 @@ var ServerController = class {
43902
44411
  }
43903
44412
  }
43904
44413
  /**
43905
- * Creates an operation via the personal server API.
44414
+ * Creates a server operation and returns a handle for lifecycle management.
43906
44415
  *
43907
44416
  * @remarks
43908
- * This method submits a computation request to the personal server API.
43909
- * The response includes the operation ID.
43910
- * @param params - The request parameters object
44417
+ * This method submits a computation request to the personal server and returns
44418
+ * an OperationHandle that provides Promise-based methods for waiting on results.
44419
+ * The handle pattern matches TransactionHandle for consistency across async operations.
44420
+ *
44421
+ * @param params - The operation request parameters
43911
44422
  * @param params.permissionId - The permission ID authorizing this operation.
43912
- * Obtain from granted permissions via `vana.permissions.getUserPermissionGrantsOnChain()`.
43913
- * @returns A Promise that resolves to an operation response with status and control URLs
43914
- * @throws {PersonalServerError} When server request fails or parameters are invalid.
43915
- * Verify permissionId exists and is active for the target server.
43916
- * @throws {NetworkError} When personal server API communication fails.
43917
- * Check server URL configuration and network connectivity.
44423
+ * Obtain via `vana.permissions.getUserPermissionGrantsOnChain()`.
44424
+ * @returns An OperationHandle providing access to the operation ID and result methods
44425
+ * @throws {PersonalServerError} When the server request fails or parameters are invalid
44426
+ * @throws {NetworkError} When personal server API communication fails
43918
44427
  * @example
43919
44428
  * ```typescript
43920
- * const response = await vana.server.createOperation({
43921
- * permissionId: 123,
44429
+ * const operation = await vana.server.createOperation({
44430
+ * permissionId: 123
43922
44431
  * });
43923
- *
43924
- * console.log(`Operation created: ${response.id}`);
44432
+ * console.log(`Operation ID: ${operation.id}`);
44433
+ *
44434
+ * // Wait for completion
44435
+ * const result = await operation.waitForResult();
44436
+ * console.log("Result:", result);
43925
44437
  * ```
43926
44438
  */
43927
44439
  async createOperation(params) {
@@ -43937,7 +44449,7 @@ var ServerController = class {
43937
44449
  };
43938
44450
  console.debug("\u{1F50D} Debug - createOperation requestBody", requestBody);
43939
44451
  const response = await this.makeRequest(requestBody);
43940
- return response;
44452
+ return new OperationHandle(this, response.id);
43941
44453
  } catch (error) {
43942
44454
  if (error instanceof Error) {
43943
44455
  if (error instanceof NetworkError || error instanceof SerializationError || error instanceof SignatureError || error instanceof PersonalServerError) {
@@ -43954,30 +44466,20 @@ var ServerController = class {
43954
44466
  }
43955
44467
  }
43956
44468
  /**
43957
- * Polls the status of a computation request for updates and results.
44469
+ * Retrieves the current status and result of a server operation.
43958
44470
  *
43959
44471
  * @remarks
43960
- * This method checks the current status of a computation request by querying
43961
- * the personal server API using the provided operation ID. It returns the current
43962
- * status, any available output, and error information. The method can be
43963
- * called periodically until the operation completes or fails.
43964
- *
43965
- * Common status values include: `starting`, `processing`, `succeeded`, `failed`, `canceled`.
43966
- * @param operationId - The operation ID returned from the initial request submission
43967
- * @returns A Promise that resolves to the current operation response with status and results
43968
- * @throws {NetworkError} When the polling request fails or returns invalid data
44472
+ * Common status values: `starting`, `running`, `succeeded`, `failed`, `canceled`.
44473
+ * When status is `succeeded`, the result field contains the operation output.
44474
+ *
44475
+ * @param operationId - The ID of the operation to query
44476
+ * @returns The operation response containing status, result, and metadata
44477
+ * @throws {NetworkError} When the API request fails or returns invalid data
43969
44478
  * @example
43970
44479
  * ```typescript
43971
- * // Poll until completion
43972
- * let result = await vana.server.getOperation(response.id);
43973
- *
43974
- * while (result.status === "processing") {
43975
- * await new Promise(resolve => setTimeout(resolve, 1000));
43976
- * result = await vana.server.getOperation(response.id);
43977
- * }
43978
- *
43979
- * if (result.status === "succeeded") {
43980
- * console.log("Computation completed:", result.output);
44480
+ * const status = await vana.server.getOperation(operationId);
44481
+ * if (status.status === 'succeeded') {
44482
+ * console.log('Result:', JSON.parse(status.result));
43981
44483
  * }
43982
44484
  * ```
43983
44485
  */
@@ -46013,6 +46515,7 @@ var VanaCore = class {
46013
46515
  /** Handles environment-specific operations like encryption and file systems. */
46014
46516
  __publicField(this, "platform");
46015
46517
  __publicField(this, "relayerCallbacks");
46518
+ __publicField(this, "downloadRelayer");
46016
46519
  __publicField(this, "storageManager");
46017
46520
  __publicField(this, "hasRequiredStorage");
46018
46521
  __publicField(this, "ipfsGateways");
@@ -46020,6 +46523,7 @@ var VanaCore = class {
46020
46523
  this.platform = platform;
46021
46524
  this.validateConfig(config);
46022
46525
  this.relayerCallbacks = config.relayerCallbacks;
46526
+ this.downloadRelayer = config.downloadRelayer;
46023
46527
  this.ipfsGateways = config.ipfsGateways;
46024
46528
  this.defaultPersonalServerUrl = config.defaultPersonalServerUrl;
46025
46529
  this.hasRequiredStorage = hasStorageConfig(config);
@@ -46075,6 +46579,7 @@ var VanaCore = class {
46075
46579
  applicationClient: walletClient,
46076
46580
  // Using same wallet for now
46077
46581
  relayerCallbacks: this.relayerCallbacks,
46582
+ downloadRelayer: this.downloadRelayer,
46078
46583
  storageManager: this.storageManager,
46079
46584
  subgraphUrl,
46080
46585
  platform: this.platform,
@@ -47330,7 +47835,7 @@ export {
47330
47835
  storeGrantFile,
47331
47836
  summarizeGrant,
47332
47837
  validateDataAgainstSchema,
47333
- validateDataSchema,
47838
+ validateDataSchemaAgainstMetaSchema,
47334
47839
  validateGrant,
47335
47840
  validateGrantExpiry,
47336
47841
  validateGrantFile,