@opendatalabs/vana-sdk 2.1.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. package/dist/config/contracts.config.cjs +352 -0
  2. package/dist/config/contracts.config.cjs.map +1 -0
  3. package/dist/config/contracts.config.d.ts +90 -0
  4. package/dist/config/contracts.config.js +327 -0
  5. package/dist/config/contracts.config.js.map +1 -0
  6. package/dist/contracts/contractController.cjs +1 -1
  7. package/dist/contracts/contractController.cjs.map +1 -1
  8. package/dist/contracts/contractController.js +1 -1
  9. package/dist/contracts/contractController.js.map +1 -1
  10. package/dist/controllers/data.cjs +1 -1
  11. package/dist/controllers/data.cjs.map +1 -1
  12. package/dist/controllers/data.js +1 -1
  13. package/dist/controllers/data.js.map +1 -1
  14. package/dist/controllers/permissions.cjs +1 -1
  15. package/dist/controllers/permissions.cjs.map +1 -1
  16. package/dist/controllers/permissions.js +1 -1
  17. package/dist/controllers/permissions.js.map +1 -1
  18. package/dist/controllers/schemas.cjs +1 -1
  19. package/dist/controllers/schemas.cjs.map +1 -1
  20. package/dist/controllers/schemas.js +1 -1
  21. package/dist/controllers/schemas.js.map +1 -1
  22. package/dist/crypto/ecies/__tests__/interface.test.d.ts +1 -0
  23. package/dist/crypto/ecies/__tests__/utils.test.d.ts +1 -0
  24. package/dist/generated/abi/ComputeEngineImplementation.cjs.map +1 -1
  25. package/dist/generated/abi/ComputeEngineImplementation.js.map +1 -1
  26. package/dist/generated/abi/ComputeEngineTreasuryImplementation.cjs +536 -0
  27. package/dist/generated/abi/ComputeEngineTreasuryImplementation.cjs.map +1 -0
  28. package/dist/generated/abi/ComputeEngineTreasuryImplementation.d.ts +393 -0
  29. package/dist/generated/abi/ComputeEngineTreasuryImplementation.js +512 -0
  30. package/dist/generated/abi/ComputeEngineTreasuryImplementation.js.map +1 -0
  31. package/dist/generated/abi/ComputeInstructionRegistryImplementation.cjs.map +1 -1
  32. package/dist/generated/abi/ComputeInstructionRegistryImplementation.js.map +1 -1
  33. package/dist/generated/abi/DATFactoryImplementation.cjs.map +1 -1
  34. package/dist/generated/abi/DATFactoryImplementation.js.map +1 -1
  35. package/dist/generated/abi/DATImplementation.cjs.map +1 -1
  36. package/dist/generated/abi/DATImplementation.js.map +1 -1
  37. package/dist/generated/abi/DATPausableImplementation.cjs.map +1 -1
  38. package/dist/generated/abi/DATPausableImplementation.js.map +1 -1
  39. package/dist/generated/abi/DATVotesImplementation.cjs.map +1 -1
  40. package/dist/generated/abi/DATVotesImplementation.js.map +1 -1
  41. package/dist/generated/abi/DLPPerformanceImplementation.cjs.map +1 -1
  42. package/dist/generated/abi/DLPPerformanceImplementation.js.map +1 -1
  43. package/dist/generated/abi/DLPRegistryImplementation.cjs.map +1 -1
  44. package/dist/generated/abi/DLPRegistryImplementation.js.map +1 -1
  45. package/dist/generated/abi/DLPRegistryTreasuryImplementation.cjs.map +1 -1
  46. package/dist/generated/abi/DLPRegistryTreasuryImplementation.js.map +1 -1
  47. package/dist/generated/abi/DLPRewardDeployerImplementation.cjs.map +1 -1
  48. package/dist/generated/abi/DLPRewardDeployerImplementation.js.map +1 -1
  49. package/dist/generated/abi/DLPRewardSwapImplementation.cjs.map +1 -1
  50. package/dist/generated/abi/DLPRewardSwapImplementation.js.map +1 -1
  51. package/dist/generated/abi/DataPortabilityGranteesImplementation.cjs.map +1 -1
  52. package/dist/generated/abi/DataPortabilityGranteesImplementation.js.map +1 -1
  53. package/dist/generated/abi/DataPortabilityPermissionsImplementation.cjs.map +1 -1
  54. package/dist/generated/abi/DataPortabilityPermissionsImplementation.js.map +1 -1
  55. package/dist/generated/abi/DataPortabilityServersImplementation.cjs.map +1 -1
  56. package/dist/generated/abi/DataPortabilityServersImplementation.js.map +1 -1
  57. package/dist/generated/abi/DataRefinerRegistryImplementation.cjs.map +1 -1
  58. package/dist/generated/abi/DataRefinerRegistryImplementation.js.map +1 -1
  59. package/dist/generated/abi/DataRegistryImplementation.cjs.map +1 -1
  60. package/dist/generated/abi/DataRegistryImplementation.js.map +1 -1
  61. package/dist/generated/abi/QueryEngineImplementation.cjs.map +1 -1
  62. package/dist/generated/abi/QueryEngineImplementation.js.map +1 -1
  63. package/dist/generated/abi/SwapHelperImplementation.cjs.map +1 -1
  64. package/dist/generated/abi/SwapHelperImplementation.js.map +1 -1
  65. package/dist/generated/abi/TeePoolDedicatedGpuImplementation.cjs.map +1 -1
  66. package/dist/generated/abi/TeePoolDedicatedGpuImplementation.js.map +1 -1
  67. package/dist/generated/abi/TeePoolDedicatedStandardImplementation.cjs.map +1 -1
  68. package/dist/generated/abi/TeePoolDedicatedStandardImplementation.js.map +1 -1
  69. package/dist/generated/abi/TeePoolEphemeralStandardImplementation.cjs.map +1 -1
  70. package/dist/generated/abi/TeePoolEphemeralStandardImplementation.js.map +1 -1
  71. package/dist/generated/abi/TeePoolPersistentGpuImplementation.cjs.map +1 -1
  72. package/dist/generated/abi/TeePoolPersistentGpuImplementation.js.map +1 -1
  73. package/dist/generated/abi/TeePoolPersistentStandardImplementation.cjs.map +1 -1
  74. package/dist/generated/abi/TeePoolPersistentStandardImplementation.js.map +1 -1
  75. package/dist/generated/abi/TeePoolPhalaImplementation.cjs.map +1 -1
  76. package/dist/generated/abi/TeePoolPhalaImplementation.js.map +1 -1
  77. package/dist/generated/abi/UniswapV3QuoterV2Implementation.cjs +297 -0
  78. package/dist/generated/abi/UniswapV3QuoterV2Implementation.cjs.map +1 -0
  79. package/dist/generated/abi/UniswapV3QuoterV2Implementation.d.ts +206 -0
  80. package/dist/generated/abi/UniswapV3QuoterV2Implementation.js +273 -0
  81. package/dist/generated/abi/UniswapV3QuoterV2Implementation.js.map +1 -0
  82. package/dist/generated/abi/VanaEpochImplementation.cjs.map +1 -1
  83. package/dist/generated/abi/VanaEpochImplementation.js.map +1 -1
  84. package/dist/generated/abi/VanaPoolEntityImplementation.cjs.map +1 -1
  85. package/dist/generated/abi/VanaPoolEntityImplementation.js.map +1 -1
  86. package/dist/generated/abi/VanaPoolStakingImplementation.cjs.map +1 -1
  87. package/dist/generated/abi/VanaPoolStakingImplementation.js.map +1 -1
  88. package/dist/generated/abi/VanaPoolTreasuryImplementation.cjs.map +1 -1
  89. package/dist/generated/abi/VanaPoolTreasuryImplementation.js.map +1 -1
  90. package/dist/generated/abi/VanaTreasuryImplementation.cjs +536 -0
  91. package/dist/generated/abi/VanaTreasuryImplementation.cjs.map +1 -0
  92. package/dist/generated/abi/VanaTreasuryImplementation.d.ts +393 -0
  93. package/dist/generated/abi/VanaTreasuryImplementation.js +512 -0
  94. package/dist/generated/abi/VanaTreasuryImplementation.js.map +1 -0
  95. package/dist/generated/abi/WVANAImplementation.cjs +339 -0
  96. package/dist/generated/abi/WVANAImplementation.cjs.map +1 -0
  97. package/dist/generated/abi/WVANAImplementation.d.ts +244 -0
  98. package/dist/generated/abi/WVANAImplementation.js +315 -0
  99. package/dist/generated/abi/WVANAImplementation.js.map +1 -0
  100. package/dist/generated/abi/index.cjs +2 -0
  101. package/dist/generated/abi/index.cjs.map +1 -1
  102. package/dist/generated/abi/index.d.ts +392 -0
  103. package/dist/generated/abi/index.js +2 -0
  104. package/dist/generated/abi/index.js.map +1 -1
  105. package/dist/{config → generated}/addresses.cjs +126 -69
  106. package/dist/generated/addresses.cjs.map +1 -0
  107. package/dist/{config → generated}/addresses.d.ts +127 -160
  108. package/dist/{config → generated}/addresses.js +126 -69
  109. package/dist/generated/addresses.js.map +1 -0
  110. package/dist/generated/event-types.cjs.map +1 -1
  111. package/dist/generated/event-types.d.ts +338 -389
  112. package/dist/generated/eventRegistry.cjs +1666 -571
  113. package/dist/generated/eventRegistry.cjs.map +1 -1
  114. package/dist/generated/eventRegistry.d.ts +2 -2
  115. package/dist/generated/eventRegistry.js +1666 -571
  116. package/dist/generated/eventRegistry.js.map +1 -1
  117. package/dist/index.browser.d.ts +1 -1
  118. package/dist/index.browser.js +2 -1
  119. package/dist/index.browser.js.map +1 -1
  120. package/dist/index.node.cjs +3 -1
  121. package/dist/index.node.cjs.map +1 -1
  122. package/dist/index.node.d.ts +1 -1
  123. package/dist/index.node.js +2 -1
  124. package/dist/index.node.js.map +1 -1
  125. package/dist/utils/blockchain/registry.cjs +1 -1
  126. package/dist/utils/blockchain/registry.cjs.map +1 -1
  127. package/dist/utils/blockchain/registry.js +1 -1
  128. package/dist/utils/blockchain/registry.js.map +1 -1
  129. package/dist/utils/multicall.cjs +1 -1
  130. package/dist/utils/multicall.cjs.map +1 -1
  131. package/dist/utils/multicall.js +1 -1
  132. package/dist/utils/multicall.js.map +1 -1
  133. package/package.json +3 -2
  134. package/dist/config/addresses.cjs.map +0 -1
  135. package/dist/config/addresses.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/controllers/data.ts"],"sourcesContent":["import type { Address, Hash } from \"viem\";\nimport { getContract } from \"viem\";\nimport type {\n TransactionOptions,\n TransactionResult,\n} from \"../types/operations\";\n\nimport type { StorageUploadResult } from \"../types/storage\";\n\nimport type {\n UserFile,\n UploadParams,\n UploadResult,\n UploadEncryptedFileResult,\n Refiner,\n AddRefinerParams,\n AddRefinerResult,\n UpdateSchemaIdParams,\n UpdateSchemaIdResult,\n TrustedServer,\n GetUserTrustedServersParams,\n EncryptedUploadParams,\n UnencryptedUploadParams,\n EncryptFileOptions,\n EncryptFileResult,\n DecryptFileOptions,\n UploadFileWithPermissionsParams,\n AddFilePermissionParams,\n DecryptFileWithPermissionOptions,\n} from \"../types/index\";\n// import { FilePermissionResult } from \"../types/transactionResults\";\nimport type { UnifiedRelayerRequest } from \"../types/relayer\";\nimport type { ControllerContext } from \"./permissions\";\nimport { PollingManager } from \"../core/pollingManager\";\nimport { BaseController } from \"./base\";\nimport { getContractAddress } from \"../config/addresses\";\nimport { getAbi } from \"../generated/abi\";\nimport { InvalidConfigurationError } from \"../errors\";\nimport type {\n GetUserFilesPaginatedQuery,\n GetFileProofsQuery,\n GetDlpQuery,\n GetUserPermissionsPaginatedQuery,\n GetUserTrustedServersPaginatedQuery,\n File_OrderBy as File_OrderByType,\n Permission_OrderBy as Permission_OrderByType,\n UserServer_OrderBy as UserServer_OrderByType,\n} from \"../generated/subgraph\";\nimport {\n GetUserFilesPaginatedDocument,\n GetFileProofsDocument,\n GetDlpDocument,\n GetUserPermissionsPaginatedDocument,\n GetUserTrustedServersPaginatedDocument,\n} from \"../generated/subgraph\";\nimport { print } from \"graphql\";\nimport type { ConsistencyOptions, PaginationOptions } from \"../types/options\";\nimport {\n checkSubgraphConsistency,\n fetchSubgraphMeta,\n} from \"../utils/subgraphConsistency\";\nimport {\n executePaginatedQuery,\n mapOrderByToEnum,\n mapOrderDirection,\n} from \"../utils/subgraphPagination\";\nimport {\n getUserFilesFromChain,\n determineDataSource,\n} from \"../utils/chainQuery\";\nimport {\n generateEncryptionKey,\n decryptBlobWithSignedKey,\n DEFAULT_ENCRYPTION_SEED,\n encryptBlobWithSignedKey,\n encryptWithWalletPublicKey,\n decryptWithWalletPrivateKey,\n} from \"../utils/encryption\";\nimport {\n validateDataSchemaAgainstMetaSchema,\n validateDataAgainstSchema,\n fetchAndValidateSchema,\n type DataSchema,\n} from \"../utils/schemaValidation\";\nimport { gasAwareMulticall } from \"../utils/multicall\";\n\n/**\n * Subgraph response wrapper type for error handling\n */\ntype SubgraphResponse<T> = {\n data?: T;\n errors?: Array<{ message: string }>;\n};\n\n/**\n * Manages encrypted user data files and blockchain registration on the Vana network.\n *\n * @remarks\n * The DataController provides comprehensive file lifecycle management from encrypted upload\n * through blockchain registration to decryption. Client-side encryption ensures data privacy\n * before transmission. The controller integrates with multiple storage providers (IPFS, Pinata,\n * Google Drive) and supports both gasless transactions via relayers and direct blockchain interaction.\n *\n * **Architecture:**\n * Files use dual storage: encrypted content on decentralized storage (IPFS/Pinata/Google Drive),\n * metadata and permissions on blockchain. This design minimizes on-chain data while maintaining\n * decentralization and access control.\n *\n * **Method Selection:**\n * - `upload()` - Complete workflow: encryption, storage, blockchain registration\n * - `getUserFiles()` - Query file metadata from blockchain/subgraph\n * - `decryptFile()` - Decrypt files you have permission to access\n * - `getFileById()` - Retrieve specific file metadata by ID\n *\n * **Storage Requirements:**\n * - Methods requiring storage: `upload()`, `encryptFile()`\n * - Methods working without storage: `getUserFiles()`, `decryptFile()`, `getFileById()`\n *\n * **Permission Model:**\n * - File permissions (decryption access) are handled during upload\n * - Operation permissions (what can be done with data) use `vana.permissions.grant()`\n *\n * @example\n * ```typescript\n * // Upload encrypted file with schema validation\n * const result = await vana.data.upload({\n * content: { name: \"Alice\", age: 30 },\n * filename: \"profile.json\",\n * schemaId: 1\n * });\n * console.log(`File uploaded: ID ${result.fileId}, URL ${result.url}`);\n *\n * // Query user's files\n * const files = await vana.data.getUserFiles({\n * owner: \"0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36\"\n * });\n * files.forEach(file => console.log(`File ${file.id}: ${file.url}`));\n *\n * // Decrypt accessible file\n * const decryptedData = await vana.data.decryptFile(files[0]);\n * console.log(\"Decrypted content:\", decryptedData);\n * ```\n *\n * @category Data Management\n * @see For conceptual overview, visit {@link https://docs.vana.org/docs/data-registry}\n */\nexport class DataController extends BaseController {\n constructor(context: ControllerContext) {\n super(context);\n }\n\n /**\n * Uploads data with automatic encryption and blockchain registration.\n *\n * @remarks\n * Primary method for uploading data to Vana. Handles complete workflow:\n * content normalization, schema validation, encryption, storage upload,\n * permission granting, and blockchain registration.\n *\n * **Automatic Processing:**\n * - Normalizes content to Blob format\n * - Validates against schema if provided\n * - Generates encryption keys\n * - Uploads to configured storage\n * - Grants decryption permissions\n * - Registers on blockchain\n *\n * **TypeScript Overloads:**\n * - `EncryptedUploadParams`: When `encrypt: true` (default), permissions require `publicKey`\n * - `UnencryptedUploadParams`: When `encrypt: false`, permissions optional\n * - `UploadParams`: General signature for runtime determination\n *\n * **Permission Separation:**\n * - File permissions (here): Decryption access only\n * - Operation permissions: Use `vana.permissions.grant()` separately\n *\n * **Owner/Encryption Constraint:**\n * When encryption is enabled (default), the `owner` parameter must match\n * the connected wallet address. This ensures only the wallet that performs\n * encryption can decrypt the file. For delegation scenarios where the owner\n * differs from the connected wallet, set `encrypt: false`.\n *\n * @param params - Upload configuration object\n * @param params.content - Data to upload (string, object, or Blob)\n * @param params.filename - Name for the uploaded file\n * @param params.permissions - Decryption access grants.\n * Each requires `account` and `publicKey` for encryption.\n * @param params.schemaId - Schema for validation.\n * Obtain via `vana.schemas.list()`.\n * @param params.owner - Owner address for blockchain registration.\n * Must match connected wallet when encryption is enabled.\n * For delegation scenarios, disable encryption with `encrypt: false`.\n * Defaults to connected wallet address.\n * @param params.encrypt - Enable encryption (default: `true`)\n * @param params.providerName - Storage provider override\n *\n * @returns Upload result with file ID, URL, and transaction hash\n *\n * @throws {InvalidConfigurationError} When encryption is enabled and owner differs from wallet.\n * Set `encrypt: false` for delegation scenarios, or omit `owner` to use connected wallet.\n * @throws {Error} Storage not configured.\n * Configure storage providers in `VanaConfig`.\n * @throws {Error} No wallet addresses available.\n * Ensure wallet is connected.\n * @throws {SchemaValidationError} Data doesn't match schema.\n * Verify data structure matches schema from `vana.schemas.get(schemaId)`.\n * @throws {Error} Upload failed with specific error message.\n *\n * @example\n * ```typescript\n * // Basic file upload\n * const result = await vana.data.upload({\n * content: \"My personal data\",\n * filename: \"diary.txt\"\n * });\n *\n * // Upload with schema validation\n * const result = await vana.data.upload({\n * content: { name: \"John\", age: 30 },\n * filename: \"profile.json\",\n * schemaId: 1\n * });\n *\n * // Upload with file permissions (for decryption access)\n * const result = await vana.data.upload({\n * content: \"Data for AI analysis\",\n * filename: \"analysis.txt\",\n * permissions: [{\n * account: \"0x1234...\", // Server address that can decrypt\n * publicKey: \"0x04...\" // Server's public key for encryption\n * }]\n * });\n *\n * // After upload, grant operation permissions separately:\n * // await vana.permissions.grant({\n * // grantee: \"0x1234...\",\n * // fileIds: [result.fileId],\n * // operation: \"llm_inference\",\n * // parameters: { model: \"gpt-4\" }\n * // });\n *\n * // Upload without encryption (public data)\n * // Note: Cast to UnencryptedUploadParams for TypeScript\n * const result = await vana.data.upload({\n * content: \"Public data\",\n * filename: \"public.txt\",\n * encrypt: false\n * } as const); // 'as const' ensures TypeScript infers encrypt: false literally\n *\n * // Upload on behalf of another user (delegation without encryption)\n * const result = await vana.data.upload({\n * content: \"User's data\",\n * filename: \"delegated.txt\",\n * owner: \"0x5678...\", // Different from connected wallet\n * encrypt: false // Required when owner differs from wallet\n * });\n * ```\n */\n async upload(params: EncryptedUploadParams): Promise<UploadResult>;\n async upload(params: UnencryptedUploadParams): Promise<UploadResult>;\n async upload(params: UploadParams): Promise<UploadResult>;\n async upload(params: UploadParams): Promise<UploadResult> {\n this.assertWallet();\n\n const {\n content,\n filename,\n schemaId,\n permissions = [],\n encrypt = true,\n providerName,\n owner,\n schemaValidation = \"strict\",\n } = params;\n\n // Validate that if encryption is enabled and owner is specified,\n // the owner must match the connected wallet address\n if (\n encrypt &&\n owner &&\n owner.toLowerCase() !== this.context.userAddress.toLowerCase()\n ) {\n throw new InvalidConfigurationError(\n \"The 'owner' parameter cannot be different from the connected wallet's address when encryption is enabled. \" +\n \"This would create an un-decryptable file.\",\n );\n }\n\n try {\n let isValid = true;\n let validationErrors: string[] = [];\n\n // Step 1: Schema validation if provided\n if (schemaId !== undefined && schemaValidation !== \"skip\") {\n try {\n // Use SchemaController to get complete schema with definition\n const { SchemaController } = await import(\"./schemas\");\n const schemaController = new SchemaController(this.context);\n const schema = await schemaController.get(schemaId);\n\n // Parse content for validation\n let parsedContent;\n if (typeof content === \"string\") {\n try {\n parsedContent = JSON.parse(content);\n } catch {\n parsedContent = content;\n }\n } else if (content instanceof Blob) {\n // For Blob content, read it as text for validation\n const text = await content.text();\n try {\n parsedContent = JSON.parse(text);\n } catch {\n parsedContent = text;\n }\n } else {\n parsedContent = content;\n }\n\n // Validate against schema (Schema is compatible with DataSchema)\n validateDataAgainstSchema(parsedContent, schema);\n } catch (error) {\n // Handle validation failure based on mode\n if (schemaValidation === \"strict\") {\n // Re-throw the error to maintain backward compatibility\n throw error;\n } else if (schemaValidation === \"warn\") {\n // Log warning and continue\n console.warn(\n '[Vana SDK] Schema validation failed, but continuing due to validation mode \"warn\"',\n );\n if (error instanceof Error) {\n console.warn(\" Validation error:\", error.message);\n // Check if it's a SchemaValidationError with details\n if (\n typeof error === \"object\" &&\n \"errors\" in error &&\n Array.isArray(error.errors)\n ) {\n console.warn(\" Detailed errors:\", error.errors);\n }\n }\n // Mark as invalid but don't block upload\n isValid = false;\n validationErrors =\n error instanceof Error\n ? [error.message]\n : [\"Schema validation failed\"];\n }\n }\n }\n\n // Step 2: Upload to storage using the centralized method\n const uploadResult = await this.uploadToStorage(\n content,\n filename,\n encrypt,\n providerName,\n );\n\n // Step 3: Register on blockchain\n const userAddress = owner ?? this.context.userAddress;\n\n // Prepare encrypted permissions if provided\n let encryptedPermissions: Array<{ account: Address; key: string }> = [];\n if (permissions.length > 0 && encrypt) {\n this.assertWallet();\n const userEncryptionKey = await generateEncryptionKey(\n this.context.walletClient,\n this.context.platform,\n DEFAULT_ENCRYPTION_SEED,\n );\n\n encryptedPermissions = await Promise.all(\n permissions.map(async (permission) => {\n const encryptedKey = await encryptWithWalletPublicKey(\n userEncryptionKey,\n permission.publicKey,\n this.context.platform,\n );\n\n return {\n account: permission.account,\n key: encryptedKey,\n };\n }),\n );\n }\n\n // Determine which registration method to use\n let result;\n\n // Use unified relayer callback if it exists\n if (this.context.relayer) {\n const request: UnifiedRelayerRequest = {\n type: \"direct\",\n operation: \"submitFileAdditionComplete\",\n params: {\n url: uploadResult.url,\n userAddress,\n permissions: encryptedPermissions,\n schemaId: schemaId ?? 0,\n ownerAddress: owner,\n },\n };\n const response = await this.context.relayer(request);\n if (response.type === \"error\") {\n throw new Error(response.error);\n }\n\n // Handle pending response (stateful relayer)\n if (response.type === \"pending\") {\n result = await this.pollRelayerForConfirmation(\n response.operationId,\n undefined, // TODO: Add TransactionOptions to upload method signature\n );\n } else if (\n response.type === \"direct\" &&\n typeof response.result === \"object\" &&\n response.result !== null &&\n \"fileId\" in response.result\n ) {\n result = response.result as { fileId: number; transactionHash: Hash };\n } else {\n throw new Error(\"Invalid response from relayer\");\n }\n\n // Fallback: No relay support, use a direct transaction\n } else {\n // Use the method directly since we already have encrypted permissions\n const txResult = await this.addFileWithEncryptedPermissionsAndSchema(\n uploadResult.url,\n userAddress,\n encryptedPermissions,\n schemaId ?? 0,\n );\n\n // Wait for transaction events to get the actual fileId\n if (!this.context.waitForTransactionEvents) {\n throw new Error(\n \"Cannot upload without relay: waitForTransactionEvents not configured\",\n );\n }\n\n const eventResult =\n await this.context.waitForTransactionEvents(txResult);\n const fileAddedEvent = eventResult.expectedEvents.FileAdded;\n if (!fileAddedEvent) {\n throw new Error(\"FileAdded event not found in transaction\");\n }\n\n result = {\n fileId: Number(fileAddedEvent.fileId),\n transactionHash: txResult.hash,\n };\n }\n\n return {\n fileId: result.fileId,\n url: uploadResult.url,\n transactionHash: result.transactionHash,\n size: uploadResult.size,\n isValid,\n validationErrors:\n validationErrors.length > 0 ? validationErrors : undefined,\n };\n } catch (error) {\n throw new Error(\n `Upload failed: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Encrypts data using wallet-derived encryption.\n *\n * @remarks\n * This method provides secure, wallet-based encryption for data before uploading\n * to the Vana network. It's the counterpart to decryptFile for preparing data\n * for secure storage.\n *\n * The method automatically:\n * - Generates an encryption key from the user's wallet signature\n * - Converts the input data to a Blob if necessary\n * - Encrypts the data using the generated key\n * - Returns both the encrypted data and the encryption key\n *\n * The encryption key returned can be stored and later used for decryption,\n * or shared with others to grant them decryption access.\n *\n * @param data - The data to encrypt (Blob, string, or object)\n * @param options - Optional encryption configuration\n * @returns Promise resolving to encrypted data and the encryption key used\n * @throws {Error} When wallet is not connected or encryption fails\n * @example\n * ```typescript\n * // Encrypt a string\n * const { encryptedData, encryptionKey } = await vana.data.encryptFile(\n * \"My secret data\"\n * );\n *\n * // Encrypt JSON with custom MIME type\n * const { encryptedData, encryptionKey } = await vana.data.encryptFile(\n * { name: \"Alice\", age: 30 },\n * { mimeType: \"application/json\" }\n * );\n *\n * // With custom encryption seed\n * const { encryptedData, encryptionKey } = await vana.data.encryptFile(\n * \"Secret message\",\n * { seed: \"My custom encryption seed\" }\n * );\n *\n * // Upload the encrypted data\n * const result = await vana.data.uploadToStorage(encryptedData);\n * ```\n */\n async encryptFile(\n data: Blob | string | object,\n options?: EncryptFileOptions,\n ): Promise<EncryptFileResult> {\n this.assertWallet();\n\n try {\n // Generate encryption key from wallet\n const encryptionKey = await generateEncryptionKey(\n this.context.walletClient,\n this.context.platform,\n options?.seed ?? DEFAULT_ENCRYPTION_SEED,\n );\n\n // Convert data to Blob if necessary\n let blob: Blob;\n if (data instanceof Blob) {\n blob = data;\n } else if (typeof data === \"string\") {\n blob = new Blob([data], { type: options?.mimeType ?? \"text/plain\" });\n } else {\n // Handle objects by JSON stringifying them\n blob = new Blob([JSON.stringify(data)], {\n type: options?.mimeType ?? \"application/json\",\n });\n }\n\n // Encrypt the blob\n const encryptedData = await encryptBlobWithSignedKey(\n blob,\n encryptionKey,\n this.context.platform,\n );\n\n return {\n encryptedData,\n encryptionKey,\n };\n } catch (error) {\n throw new Error(\n `Failed to encrypt file: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Decrypts a file using wallet-derived decryption key.\n *\n * @remarks\n * Counterpart to `upload()` for decrypting user files. Automatically\n * generates decryption key from wallet, fetches encrypted content,\n * and decrypts. Supports IPFS (with gateway fallback) and HTTP URLs.\n *\n * @param file - UserFile object from `getUserFiles()`\n * @param options - Decryption options\n * @param options.seed - Custom encryption seed.\n * Defaults to standard Vana seed.\n *\n * @returns Decrypted content as Blob\n *\n * @throws {Error} No wallet connected.\n * Connect wallet before decrypting.\n * @throws {Error} Network error accessing file.\n * Check CORS settings or server availability.\n * @throws {Error} File not found (404).\n * File no longer available at stored URL.\n * @throws {Error} Access denied (403).\n * No permission to access file.\n * @throws {Error} Invalid file format.\n * File not encrypted with Vana protocol.\n * @throws {Error} Wrong encryption key.\n * Verify seed matches upload or use default.\n *\n * @example\n * ```typescript\n * // Basic file decryption\n * const files = await vana.data.getUserFiles({ owner: userAddress });\n * const decryptedBlob = await vana.data.decryptFile(files[0]);\n *\n * // Convert to text\n * const text = await decryptedBlob.text();\n * console.log('Decrypted content:', text);\n *\n * // Convert to JSON\n * const json = JSON.parse(await decryptedBlob.text());\n * console.log('Decrypted data:', json);\n *\n * // With custom encryption seed\n * const decryptedBlob = await vana.data.decryptFile(\n * files[0],\n * \"My custom encryption seed\"\n * );\n *\n * // Save to file (in Node.js)\n * const buffer = await decryptedBlob.arrayBuffer();\n * fs.writeFileSync('decrypted-file.txt', Buffer.from(buffer));\n * ```\n */\n async decryptFile(\n file: UserFile,\n options?: DecryptFileOptions,\n ): Promise<Blob> {\n this.assertWallet();\n\n try {\n this.assertWallet();\n // Step 1: Generate the decryption key from wallet signature\n const encryptionKey = await generateEncryptionKey(\n this.context.walletClient,\n this.context.platform,\n options?.seed ?? DEFAULT_ENCRYPTION_SEED,\n );\n\n // Step 2: Determine the protocol and fetch the encrypted content\n let encryptedBlob: Blob;\n\n try {\n if (file.url.startsWith(\"ipfs://\")) {\n // Use IPFS fetcher with gateway fallback for reliability\n encryptedBlob = await this.fetchFromIPFS(file.url);\n } else {\n // Use standard fetch for HTTP/HTTPS URLs\n encryptedBlob = await this.fetch(file.url);\n }\n } catch (fetchError) {\n // Handle network errors\n const errorMessage =\n fetchError instanceof Error ? fetchError.message : \"Unknown error\";\n\n // Check for specific error types\n if (\n errorMessage.includes(\"Failed to fetch IPFS content\") &&\n errorMessage.includes(\"from all gateways\")\n ) {\n // IPFS gateway failures - treat as network error\n throw new Error(\n \"Network error: Cannot access the file URL. The file may be stored on a server that's not accessible or has CORS restrictions.\",\n );\n } else if (errorMessage.includes(\"Empty response\")) {\n throw new Error(\"File is empty or could not be retrieved\");\n } else if (\n errorMessage.includes(\"Network error:\") ||\n errorMessage.includes(\"Failed to fetch\")\n ) {\n throw new Error(\n \"Network error: Cannot access the file URL. The file may be stored on a server that's not accessible or has CORS restrictions.\",\n );\n } else if (errorMessage.includes(\"HTTP error!\")) {\n const statusMatch = errorMessage.match(/status: (\\d+)/);\n const status = statusMatch ? statusMatch[1] : \"unknown\";\n\n if (status === \"500\") {\n throw new Error(\n \"Network error: Cannot access the file URL. The file may be stored on a server that's not accessible or has CORS restrictions.\",\n );\n } else if (status === \"403\") {\n throw new Error(\n \"Access denied. You may not have permission to access this file\",\n );\n } else if (status === \"404\") {\n throw new Error(\n \"File not found: The encrypted file is no longer available at the stored URL.\",\n );\n } else {\n throw new Error(\n \"Network error: Cannot access the file URL. The file may be stored on a server that's not accessible or has CORS restrictions.\",\n );\n }\n }\n\n // Re-throw other errors\n throw fetchError;\n }\n\n // Check if blob is empty\n if (encryptedBlob.size === 0) {\n throw new Error(\"File is empty or could not be retrieved\");\n }\n\n // Step 3: Decrypt the blob using the low-level primitive\n let decryptedBlob: Blob;\n try {\n decryptedBlob = await decryptBlobWithSignedKey(\n encryptedBlob,\n encryptionKey,\n this.context.platform,\n );\n } catch (decryptError) {\n const errorMessage =\n decryptError instanceof Error\n ? decryptError.message\n : \"Unknown error\";\n\n // Map decryption errors to user-friendly messages\n if (errorMessage.includes(\"not a valid OpenPGP message\")) {\n throw new Error(\n \"Invalid file format: This file doesn't appear to be encrypted with the Vana protocol\",\n );\n } else if (errorMessage.includes(\"Session key decryption failed\")) {\n throw new Error(\"Wrong encryption key\");\n } else if (errorMessage.includes(\"Error decrypting message\")) {\n throw new Error(\"Wrong encryption key\");\n } else if (errorMessage.includes(\"File not found\")) {\n throw new Error(\n \"File not found: The encrypted file is no longer available\",\n );\n } else {\n // Re-throw the original error for other cases\n throw decryptError;\n }\n }\n\n return decryptedBlob;\n } catch (error) {\n // If it's already one of our formatted errors, re-throw it\n if (\n error instanceof Error &&\n (error.message.includes(\"Network error:\") ||\n error.message.includes(\"Invalid file format:\") ||\n error.message.includes(\"Wrong encryption key\") ||\n error.message.includes(\"Access denied\") ||\n error.message.includes(\"File not found:\") ||\n error.message.includes(\"File is empty\"))\n ) {\n throw error;\n }\n\n // Otherwise, wrap it\n throw new Error(\n `Failed to decrypt file: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Retrieves all files owned by a specific user address.\n *\n * @remarks\n * Queries the Vana subgraph for files owned by the specified address.\n * Automatically deduplicates by file ID, keeping the latest version\n * when duplicates exist from re-indexing or chain reorganizations.\n * Enriches results with DLP proof data when available.\n *\n * @param params - Query configuration\n * @param params.owner - Wallet address of the file owner\n * @param params.subgraphUrl - Subgraph endpoint override.\n * Defaults to context configuration.\n *\n * @returns Array of UserFile objects sorted by timestamp (newest first)\n *\n * @throws {Error} Subgraph URL not configured.\n * Provide `subgraphUrl` parameter or configure in Vana constructor.\n * @throws {Error} Subgraph request failed.\n * Check network connectivity and subgraph availability.\n * @throws {Error} Subgraph returned errors.\n * Review query parameters and subgraph logs.\n *\n * @example\n * ```typescript\n * const files = await vana.data.getUserFiles({\n * owner: \"0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36\"\n * });\n *\n * files.forEach(file => {\n * console.log(`File ${file.id}: ${file.url}`);\n * console.log(` Schema: ${file.schemaId}`);\n * console.log(` DLPs: ${file.dlpIds?.join(\", \") || \"none\"}`);\n * });\n * ```\n */\n async getUserFiles(\n params: {\n owner: Address;\n subgraphUrl?: string;\n },\n options?: ConsistencyOptions & PaginationOptions,\n ): Promise<UserFile[]> {\n const { owner, subgraphUrl } = params;\n\n // Determine data source based on options\n let dataSource: \"subgraph\" | \"chain\" =\n options?.source === \"chain\" ? \"chain\" : \"subgraph\";\n\n // If auto mode, determine based on staleness\n if (options?.source === \"auto\" || (!options?.source && options?.minBlock)) {\n const endpoint = subgraphUrl ?? this.context.subgraphUrl;\n\n // Get current chain block\n const currentBlock = await this.context.publicClient.getBlockNumber();\n\n // Get subgraph block if using subgraph\n let subgraphBlock: number | undefined;\n if (endpoint) {\n try {\n const meta = await fetchSubgraphMeta(endpoint);\n subgraphBlock = meta.blockNumber;\n } catch {\n // If subgraph is unavailable, fall back to chain\n subgraphBlock = undefined;\n }\n }\n\n dataSource = determineDataSource(\n options?.source,\n options?.minBlock,\n currentBlock,\n subgraphBlock,\n );\n }\n\n // Use chain query if selected\n if (dataSource === \"chain\") {\n const publicClient = this.context.publicClient;\n const chainId = await publicClient.getChainId();\n const contractAddress = getContractAddress(chainId, \"DataRegistry\");\n\n // Query directly from chain\n const files = await getUserFilesFromChain(\n publicClient,\n contractAddress,\n owner,\n options?.minBlock ? BigInt(options.minBlock) : undefined,\n );\n\n // Apply pagination if needed (chain query returns all, so we paginate in memory)\n const limit = options?.fetchAll ? files.length : (options?.limit ?? 100);\n const offset = options?.offset ?? 0;\n\n return files.slice(offset, offset + limit);\n }\n\n // Use subgraph query (existing logic)\n const endpoint = subgraphUrl ?? this.context.subgraphUrl;\n\n if (!endpoint) {\n throw new Error(\n \"subgraphUrl is required. Please provide a valid subgraph endpoint or configure it in Vana constructor.\",\n );\n }\n\n // Check consistency requirements before querying\n if (options?.minBlock || options?.waitForSync) {\n await checkSubgraphConsistency(endpoint, options);\n }\n\n try {\n // Map orderBy string to GraphQL enum values (string literals)\n const orderByMap: Record<string, File_OrderByType> = {\n id: \"id\",\n addedAtBlock: \"addedAtBlock\",\n addedAtTimestamp: \"addedAtTimestamp\",\n url: \"url\",\n schemaId: \"schemaId\",\n };\n\n // Define the raw file type from the GraphQL response\n type RawFile = NonNullable<\n GetUserFilesPaginatedQuery[\"user\"]\n >[\"files\"][0];\n\n // Use the generic pagination utility\n const allFiles = await executePaginatedQuery<\n GetUserFilesPaginatedQuery,\n UserFile,\n RawFile\n >({\n endpoint,\n document: GetUserFilesPaginatedDocument,\n baseVariables: {\n userId: owner.toLowerCase(), // Subgraph requires lowercase addresses\n orderBy: mapOrderByToEnum(\n options?.orderBy,\n orderByMap,\n \"addedAtBlock\",\n ),\n orderDirection: mapOrderDirection(\n options?.orderDirection,\n \"asc\",\n \"desc\",\n ),\n },\n options,\n extractItems: (data) => data?.user?.files,\n transformItem: (file) => ({\n id: parseInt(file.id),\n url: file.url,\n ownerAddress: file.owner.id as Address,\n addedAtBlock: BigInt(file.addedAtBlock),\n schemaId: parseInt(file.schemaId),\n addedAtTimestamp: BigInt(file.addedAtTimestamp),\n transactionHash: file.transactionHash as Hash,\n }),\n });\n\n // Fetch proofs for all files to get DLP associations\n if (allFiles.length > 0) {\n try {\n const fileIds = allFiles.map((f) => f.id);\n let proofMap: Map<number, number[]>;\n\n try {\n // Try subgraph first\n proofMap = await this._fetchProofsFromSubgraph(fileIds, endpoint);\n } catch (subgraphError) {\n console.debug(\n \"Failed to fetch proofs from subgraph, trying chain:\",\n subgraphError,\n );\n // Fall back to chain\n proofMap = await this._fetchProofsFromChain(fileIds);\n }\n\n // Add dlpIds to each file\n for (const file of allFiles) {\n const dlpIds = proofMap.get(file.id);\n if (dlpIds && dlpIds.length > 0) {\n file.dlpIds = dlpIds;\n }\n }\n } catch (error) {\n // Log but don't fail - files are still useful without proof data\n console.warn(\"Failed to fetch proof data for files:\", error);\n }\n }\n\n // Successfully retrieved user files (already paginated and sorted by GraphQL)\n return allFiles;\n } catch (error) {\n console.error(\"Failed to fetch user files from subgraph:\", error);\n throw new Error(\n `Failed to fetch user files from subgraph: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Fetches proof data for multiple files from the subgraph.\n *\n * @private\n * @param fileIds - Array of file IDs to fetch proofs for\n * @param subgraphUrl - The subgraph endpoint URL\n * @returns Map of file IDs to their associated DLP IDs\n */\n private async _fetchProofsFromSubgraph(\n fileIds: number[],\n subgraphUrl: string,\n ): Promise<Map<number, number[]>> {\n const response = await fetch(subgraphUrl, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify({\n query: print(GetFileProofsDocument),\n variables: {\n fileIds: fileIds.map((id) => id.toString()),\n },\n }),\n });\n\n if (!response.ok) {\n throw new Error(\n `Subgraph request failed: ${response.status} ${response.statusText}`,\n );\n }\n\n const result =\n (await response.json()) as SubgraphResponse<GetFileProofsQuery>;\n\n if (result.errors) {\n throw new Error(\n `Subgraph errors: ${result.errors.map((e) => e.message).join(\", \")}`,\n );\n }\n\n // Build map of fileId -> dlpIds\n const proofMap = new Map<number, number[]>();\n\n if (result.data?.dataRegistryProofs) {\n for (const proof of result.data.dataRegistryProofs) {\n if (proof.dlp?.id) {\n const fileId = parseInt(proof.fileId);\n const dlpId = parseInt(proof.dlp.id);\n\n let dlpIds = proofMap.get(fileId);\n if (!dlpIds) {\n dlpIds = [];\n proofMap.set(fileId, dlpIds);\n }\n\n if (!dlpIds.includes(dlpId)) {\n dlpIds.push(dlpId);\n }\n }\n }\n }\n\n return proofMap;\n }\n\n /**\n * Fetches proof data for multiple files from the blockchain.\n * Falls back to this when subgraph is unavailable.\n *\n * @private\n * @param fileIds - Array of file IDs to fetch proofs for\n * @returns Map of file IDs to their associated DLP IDs\n */\n private async _fetchProofsFromChain(\n fileIds: number[],\n ): Promise<Map<number, number[]>> {\n const chainId = this.context.publicClient.chain?.id;\n if (!chainId) {\n throw new Error(\"Chain ID not available\");\n }\n\n const dataRegistryAddress = getContractAddress(chainId, \"DataRegistry\");\n const dataRegistryAbi = getAbi(\"DataRegistry\");\n\n const proofMap = new Map<number, number[]>();\n\n // For each file, fetch proofs by incrementing index until revert\n for (const fileId of fileIds) {\n const dlpIds: number[] = [];\n let proofIndex = 0;\n let hasMoreProofs = true;\n\n while (hasMoreProofs) {\n try {\n const proof = (await this.context.publicClient.readContract({\n address: dataRegistryAddress,\n abi: dataRegistryAbi,\n functionName: \"fileProofs\",\n args: [BigInt(fileId), BigInt(proofIndex)],\n })) as {\n signature: `0x${string}`;\n data: {\n score: bigint;\n dlpId: bigint;\n metadata: string;\n proofUrl: string;\n instruction: string;\n };\n };\n\n if (proof?.data?.dlpId) {\n const dlpId = Number(proof.data.dlpId);\n if (!dlpIds.includes(dlpId)) {\n dlpIds.push(dlpId);\n }\n }\n\n proofIndex++;\n } catch {\n // No more proofs for this file\n hasMoreProofs = false;\n }\n }\n\n if (dlpIds.length > 0) {\n proofMap.set(fileId, dlpIds);\n }\n }\n\n return proofMap;\n }\n\n /**\n * Retrieves information about a specific Data Liquidity Pool (DLP).\n *\n * @remarks\n * DLPs are entities that process and verify data files in the Vana network.\n * This method fetches DLP metadata including name, status, and performance rating.\n * Uses subgraph first for efficiency, falls back to chain if unavailable.\n *\n * @param dlpId - The unique identifier of the DLP\n * @param options - Optional parameters\n * @param options.subgraphUrl - Custom subgraph URL to override default\n * @returns Promise resolving to DLP information\n * @throws {Error} When DLP cannot be found - \"DLP not found: {dlpId}\"\n * @throws {Error} When query fails - \"Failed to fetch DLP: {error}\"\n * @example\n * ```typescript\n * const dlp = await vana.data.getDLP(26);\n * console.log(`DLP ${dlp.name}: ${dlp.status}`);\n * ```\n */\n async getDLP(\n dlpId: number,\n options: {\n subgraphUrl?: string;\n minBlock?: number;\n waitForSync?: number;\n } = {},\n ): Promise<{\n id: number;\n name: string;\n metadata?: string;\n status?: number;\n address?: Address;\n owner?: Address;\n }> {\n const subgraphUrl = options.subgraphUrl ?? this.context.subgraphUrl;\n\n // Check consistency requirements if using subgraph\n if (subgraphUrl && (options.minBlock || options.waitForSync)) {\n await checkSubgraphConsistency(subgraphUrl, options);\n }\n\n // Try subgraph first if available\n if (subgraphUrl) {\n try {\n const response = await fetch(subgraphUrl, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify({\n query: print(GetDlpDocument),\n variables: {\n id: dlpId.toString(),\n },\n }),\n });\n\n if (!response.ok) {\n throw new Error(\n `Subgraph request failed: ${response.status} ${response.statusText}`,\n );\n }\n\n const result = (await response.json()) as SubgraphResponse<GetDlpQuery>;\n\n if (result.errors) {\n throw new Error(\n `Subgraph errors: ${result.errors.map((e) => e.message).join(\", \")}`,\n );\n }\n\n if (!result.data?.dlp) {\n throw new Error(`DLP not found: ${dlpId}`);\n }\n\n return {\n id: parseInt(result.data.dlp.id),\n name: result.data.dlp.name ?? \"\",\n metadata: result.data.dlp.metadata ?? undefined,\n status: result.data.dlp.status\n ? parseInt(result.data.dlp.status)\n : undefined,\n address: result.data.dlp.address\n ? (result.data.dlp.address as Address)\n : undefined,\n owner: result.data.dlp.owner\n ? (result.data.dlp.owner as Address)\n : undefined,\n };\n } catch (error) {\n console.debug(\"Subgraph query failed, falling back to chain:\", error);\n // Fall through to chain query\n }\n }\n\n // Chain fallback - read from DLP Registry contract\n try {\n const chainId = this.context.publicClient.chain?.id;\n if (!chainId) {\n throw new Error(\"Chain ID not available\");\n }\n\n const dlpRegistryAddress = getContractAddress(chainId, \"DLPRegistry\");\n const dlpRegistryAbi = getAbi(\"DLPRegistry\");\n\n const dlpData = (await this.context.publicClient.readContract({\n address: dlpRegistryAddress,\n abi: dlpRegistryAbi,\n functionName: \"dlps\",\n args: [BigInt(dlpId)],\n })) as {\n id: bigint;\n dlpAddress: Address;\n ownerAddress: Address;\n tokenAddress: Address;\n treasuryAddress: Address;\n name: string;\n iconUrl: string;\n website: string;\n metadata: string;\n registrationBlockNumber: bigint;\n depositAmount: bigint;\n status: number;\n lpTokenId: bigint;\n verificationBlockNumber: bigint;\n };\n\n if (!dlpData?.name) {\n throw new Error(`DLP not found: ${dlpId}`);\n }\n\n return {\n id: dlpId,\n name: dlpData.name,\n metadata: dlpData.metadata,\n status: dlpData.status,\n address: dlpData.dlpAddress,\n owner: dlpData.ownerAddress,\n };\n } catch (error) {\n throw new Error(\n `Failed to fetch DLP: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Lists all Data Liquidity Pools (DLPs) with optional pagination.\n *\n * @remarks\n * Fetches a paginated list of all DLPs registered in the network.\n * Uses subgraph for efficient querying with fallback to chain multicall.\n *\n * @param options - Optional parameters for pagination and filtering\n * @param options.limit - Maximum number of DLPs to return (default: 100)\n * @param options.offset - Number of DLPs to skip (default: 0)\n * @param options.subgraphUrl - Custom subgraph URL to override default\n * @returns Promise resolving to array of DLP information\n * @throws {Error} When query fails - \"Failed to list DLPs: {error}\"\n * @example\n * ```typescript\n * // Get first 10 DLPs\n * const dlps = await vana.data.listDLPs({ limit: 10 });\n * dlps.forEach(dlp => console.log(`${dlp.id}: ${dlp.name}`));\n *\n * // Get next page\n * const nextPage = await vana.data.listDLPs({ limit: 10, offset: 10 });\n * ```\n */\n async listDLPs(\n options: {\n limit?: number;\n offset?: number;\n subgraphUrl?: string;\n } = {},\n ): Promise<\n Array<{\n id: number;\n name: string;\n metadata?: string;\n status?: number;\n address?: Address;\n owner?: Address;\n }>\n > {\n const { limit = 100, offset = 0 } = options;\n const subgraphUrl = options.subgraphUrl ?? this.context.subgraphUrl;\n\n // Try subgraph first if available\n if (subgraphUrl) {\n try {\n const query = `\n query ListDLPs($first: Int!, $skip: Int!) {\n dlps(first: $first, skip: $skip, orderBy: id) {\n id\n name\n metadata\n status\n address\n owner\n }\n }\n `;\n\n const response = await fetch(subgraphUrl, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify({\n query,\n variables: {\n first: limit,\n skip: offset,\n },\n }),\n });\n\n if (!response.ok) {\n throw new Error(\n `Subgraph request failed: ${response.status} ${response.statusText}`,\n );\n }\n\n const result = (await response.json()) as {\n data?: {\n dlps?: Array<{\n id: string;\n name?: string;\n metadata?: string;\n status?: string;\n address?: string;\n owner?: string;\n }>;\n };\n errors?: Array<{ message: string }>;\n };\n\n if (result.errors) {\n throw new Error(\n `Subgraph errors: ${result.errors.map((e) => e.message).join(\", \")}`,\n );\n }\n\n const dlps = result.data?.dlps ?? [];\n\n return dlps.map((dlp) => ({\n id: parseInt(dlp.id),\n name: dlp.name ?? \"\",\n metadata: dlp.metadata,\n status: dlp.status ? parseInt(dlp.status) : undefined,\n address: dlp.address ? (dlp.address as Address) : undefined,\n owner: dlp.owner ? (dlp.owner as Address) : undefined,\n }));\n } catch (error) {\n console.debug(\"Subgraph query failed, falling back to chain:\", error);\n // Fall through to chain query\n }\n }\n\n // Chain fallback - use multicall to batch read DLPs\n try {\n const chainId = this.context.publicClient.chain?.id;\n if (!chainId) {\n throw new Error(\"Chain ID not available\");\n }\n\n const dlpRegistryAddress = getContractAddress(chainId, \"DLPRegistry\");\n const dlpRegistryAbi = getAbi(\"DLPRegistry\");\n\n // First get the total count\n const dlpCount = await this.context.publicClient.readContract({\n address: dlpRegistryAddress,\n abi: dlpRegistryAbi,\n functionName: \"dlpsCount\",\n args: [],\n });\n\n const totalCount = Number(dlpCount);\n const start = offset;\n const end = Math.min(start + limit, totalCount);\n\n if (end <= start) {\n return [];\n }\n\n // Build multicall for fetching DLP data\n const calls = [];\n for (let i = start + 1; i <= end; i++) {\n // DLP IDs typically start at 1\n calls.push({\n address: dlpRegistryAddress,\n abi: dlpRegistryAbi,\n functionName: \"dlps\",\n args: [BigInt(i)],\n } as const);\n }\n\n const results = await gasAwareMulticall<\n typeof calls,\n true // Allow failures\n >(this.context.publicClient, {\n contracts: calls,\n allowFailure: true,\n batchSize: 50,\n });\n\n const dlps = [];\n for (let i = 0; i < results.length; i++) {\n const result = results[i];\n if (result.status === \"success\" && result.result) {\n const dlpData = result.result as {\n id: bigint;\n dlpAddress: Address;\n ownerAddress: Address;\n tokenAddress: Address;\n treasuryAddress: Address;\n name: string;\n iconUrl: string;\n website: string;\n metadata: string;\n registrationBlockNumber: bigint;\n depositAmount: bigint;\n status: number;\n lpTokenId: bigint;\n verificationBlockNumber: bigint;\n };\n\n if (dlpData.name) {\n // Only include valid DLPs\n dlps.push({\n id: start + i + 1,\n name: dlpData.name,\n metadata: dlpData.metadata,\n status: dlpData.status,\n address: dlpData.dlpAddress,\n owner: dlpData.ownerAddress,\n });\n }\n }\n }\n\n return dlps;\n } catch (error) {\n throw new Error(\n `Failed to list DLPs: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Retrieves a list of permissions granted by a user.\n *\n * This method supports automatic fallback between subgraph and RPC modes:\n * - If subgraph URL is available, tries subgraph query first\n * - Falls back to direct contract queries via RPC if subgraph fails\n * - RPC mode uses gasAwareMulticall for efficient batch queries\n *\n * @param params - Object containing the user address and optional subgraph URL\n * @param params.user - The wallet address of the user to query permissions for\n * @param params.subgraphUrl - Optional subgraph URL to override the default\n * @returns Promise resolving to an array of permission objects\n * @throws Error if both subgraph and RPC queries fail\n */\n async getUserPermissions(\n params: {\n user: Address;\n subgraphUrl?: string;\n },\n options?: ConsistencyOptions & PaginationOptions,\n ): Promise<\n Array<{\n id: string;\n grant: string;\n nonce: bigint;\n signature: string;\n addedAtBlock: bigint;\n addedAtTimestamp: bigint;\n transactionHash: Address;\n user: Address;\n }>\n > {\n const { user, subgraphUrl } = params;\n const endpoint = subgraphUrl ?? this.context.subgraphUrl;\n\n // Check consistency requirements if using subgraph\n if (endpoint && (options?.minBlock || options?.waitForSync)) {\n await checkSubgraphConsistency(endpoint, options);\n }\n\n // Try subgraph first if available\n if (endpoint) {\n try {\n const permissions = await this._getUserPermissionsViaSubgraph(\n {\n user,\n subgraphUrl: endpoint,\n },\n options,\n );\n\n return permissions;\n } catch (error) {\n console.warn(\"Subgraph query failed, falling back to RPC:\", error);\n // Fall through to RPC\n }\n }\n\n // Use RPC (as fallback or primary method)\n // Note: RPC doesn't support pagination, so we get all and slice\n const allPermissions = await this._getUserPermissionsViaRpc({ user });\n\n // Apply pagination to RPC results if needed\n if (options && !options.fetchAll) {\n const limit = options.limit ?? 100;\n const offset = options.offset ?? 0;\n return allPermissions.slice(offset, offset + limit);\n }\n\n return allPermissions;\n }\n\n /**\n * Internal method: Query user permissions via subgraph\n *\n * @param params - Query parameters object\n * @param params.user - The user address to query permissions for\n * @param params.subgraphUrl - The subgraph URL endpoint to query\n * @returns Promise resolving to an array of permission objects\n */\n private async _getUserPermissionsViaSubgraph(\n params: {\n user: Address;\n subgraphUrl: string;\n },\n options?: PaginationOptions,\n ): Promise<\n Array<{\n id: string;\n grant: string;\n nonce: bigint;\n signature: string;\n addedAtBlock: bigint;\n addedAtTimestamp: bigint;\n transactionHash: Address;\n user: Address;\n }>\n > {\n const { user, subgraphUrl } = params;\n\n try {\n // Map orderBy string to GraphQL enum values\n const orderByMap: Record<string, Permission_OrderByType> = {\n id: \"id\",\n addedAtBlock: \"addedAtBlock\",\n addedAtTimestamp: \"addedAtTimestamp\",\n grant: \"grant\",\n nonce: \"nonce\",\n startBlock: \"startBlock\",\n endBlock: \"endBlock\",\n };\n\n // Define the raw permission type from the GraphQL response\n type RawPermission = NonNullable<\n GetUserPermissionsPaginatedQuery[\"user\"]\n >[\"permissions\"][0];\n\n // Use the generic pagination utility\n const permissions = await executePaginatedQuery<\n GetUserPermissionsPaginatedQuery,\n {\n id: string;\n grant: string;\n nonce: bigint;\n signature: string;\n addedAtBlock: bigint;\n addedAtTimestamp: bigint;\n transactionHash: Address;\n user: Address;\n },\n RawPermission\n >({\n endpoint: subgraphUrl,\n document: GetUserPermissionsPaginatedDocument,\n baseVariables: {\n userId: user.toLowerCase(),\n orderBy: mapOrderByToEnum(\n options?.orderBy,\n orderByMap,\n \"addedAtTimestamp\",\n ),\n orderDirection: mapOrderDirection(\n options?.orderDirection,\n \"desc\",\n \"asc\",\n ),\n },\n options,\n extractItems: (data) => data?.user?.permissions,\n transformItem: (permission) => ({\n id: permission.id,\n grant: permission.grant,\n nonce: BigInt(permission.nonce),\n signature: permission.signature,\n addedAtBlock: BigInt(permission.addedAtBlock),\n addedAtTimestamp: BigInt(permission.addedAtTimestamp),\n transactionHash: permission.transactionHash as Hash,\n user,\n }),\n });\n\n return permissions;\n } catch (error) {\n console.error(\"Failed to query user permissions from subgraph:\", error);\n throw error;\n }\n }\n\n /**\n * Internal method: Query user permissions via direct RPC\n *\n * @param params - Query parameters object\n * @param params.user - The user address to query permissions for\n * @returns Promise resolving to an array of permission objects\n */\n private async _getUserPermissionsViaRpc(params: { user: Address }): Promise<\n Array<{\n id: string;\n grant: string;\n nonce: bigint;\n signature: string;\n addedAtBlock: bigint;\n addedAtTimestamp: bigint;\n transactionHash: Address;\n user: Address;\n }>\n > {\n const { user } = params;\n\n try {\n const chainId = this.context.publicClient.chain?.id;\n if (!chainId) {\n throw new Error(\"Chain ID not available\");\n }\n\n const permissionsAddress = getContractAddress(\n chainId,\n \"DataPortabilityPermissions\",\n );\n const permissionsAbi = getAbi(\"DataPortabilityPermissions\");\n\n // Get total count of user permission IDs\n const totalCount = await this.context.publicClient.readContract({\n address: permissionsAddress,\n abi: permissionsAbi,\n functionName: \"userPermissionIdsLength\",\n args: [user],\n });\n\n const total = Number(totalCount);\n\n if (total === 0) {\n return [];\n }\n\n // Fetch permission IDs using gasAwareMulticall\n const permissionIdCalls = [];\n for (let i = 0; i < total; i++) {\n permissionIdCalls.push({\n address: permissionsAddress,\n abi: permissionsAbi,\n functionName: \"userPermissionIdsAt\",\n args: [user, BigInt(i)],\n });\n }\n\n const permissionIdResults = await gasAwareMulticall<\n typeof permissionIdCalls,\n false\n >(this.context.publicClient, {\n contracts: permissionIdCalls,\n });\n\n // Extract permission IDs from results\n const permissionIds = permissionIdResults\n .map((result) => result as bigint)\n .filter((id) => id && id > 0n);\n\n // Build permission info calls for multicall\n const permissionInfoCalls = permissionIds.map(\n (permissionId) =>\n ({\n address: permissionsAddress,\n abi: permissionsAbi,\n functionName: \"permissions\",\n args: [permissionId],\n }) as const,\n );\n\n // Fetch all permission info in a single multicall\n const permissionInfoResults = await gasAwareMulticall<\n typeof permissionInfoCalls,\n true // Allow failures for individual permission lookups\n >(this.context.publicClient, {\n contracts: permissionInfoCalls,\n allowFailure: true,\n });\n\n // Process results\n const permissions = permissionInfoResults\n .map((result, index) => {\n const permissionId = permissionIds[index];\n\n if (result.status === \"success\" && result.result) {\n const permissionInfo = result.result as {\n id: bigint;\n grantor: Address;\n nonce: bigint;\n granteeId: bigint;\n grant: string;\n startBlock: bigint;\n endBlock: bigint;\n fileIds: bigint[];\n };\n\n return {\n id: permissionId.toString(),\n grant: permissionInfo.grant,\n nonce: permissionInfo.nonce,\n signature: \"\", // Not available from RPC, will be empty\n addedAtBlock: permissionInfo.startBlock,\n addedAtTimestamp: BigInt(0), // Not available from RPC\n transactionHash:\n \"0x0000000000000000000000000000000000000000\" as `0x${string}`, // Not available from RPC\n user,\n };\n } else {\n // If permission info fails, return basic info\n return {\n id: permissionId.toString(),\n grant: \"\",\n nonce: BigInt(0),\n signature: \"\",\n addedAtBlock: BigInt(0),\n addedAtTimestamp: BigInt(0),\n transactionHash:\n \"0x0000000000000000000000000000000000000000\" as `0x${string}`,\n user,\n };\n }\n })\n .filter((permission) => permission.grant !== \"\"); // Remove failed lookups\n\n return permissions;\n } catch (error) {\n throw new Error(\n `RPC query failed: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Retrieves a list of trusted servers for a user.\n *\n * This method supports automatic fallback between subgraph and RPC modes:\n * - If subgraph URL is available, tries subgraph query first for fast results\n * - Falls back to direct contract queries via RPC if subgraph fails\n * - RPC mode uses gasAwareMulticall for efficient batch queries\n *\n * @param params - Query parameters including user address and optional pagination\n * @param params.user - The wallet address of the user to query trusted servers for\n * @param params.subgraphUrl - Optional subgraph URL to override the default\n * @param params.limit - Maximum number of results to return (default: 50)\n * @param params.offset - Number of results to skip for pagination (default: 0)\n * @returns Promise resolving to an array of trusted server objects\n * @throws Error if both subgraph and RPC queries fail\n * @example\n * ```typescript\n * // Basic usage with automatic fallback\n * const servers = await vana.data.getUserTrustedServers({\n * user: '0x...'\n * });\n *\n * // With pagination\n * const servers = await vana.data.getUserTrustedServers({\n * user: '0x...',\n * limit: 10,\n * offset: 20\n * });\n *\n * // With custom subgraph URL\n * const servers = await vana.data.getUserTrustedServers({\n * user: '0x...',\n * subgraphUrl: 'https://custom-subgraph.com/graphql'\n * });\n * ```\n */\n async getUserTrustedServers(\n params: GetUserTrustedServersParams,\n options?: ConsistencyOptions & PaginationOptions,\n ): Promise<TrustedServer[]> {\n const { user } = params;\n const subgraphUrl = params.subgraphUrl ?? this.context.subgraphUrl;\n\n // Check consistency requirements if using subgraph\n if (subgraphUrl && (options?.minBlock || options?.waitForSync)) {\n await checkSubgraphConsistency(subgraphUrl, options);\n }\n\n // Try subgraph first if available\n if (subgraphUrl) {\n try {\n const servers = await this._getUserTrustedServersViaSubgraph(\n {\n user,\n subgraphUrl,\n },\n options,\n );\n\n return servers;\n } catch (error) {\n console.warn(\"Subgraph query failed, falling back to RPC:\", error);\n // Fall through to RPC\n }\n }\n\n // Use RPC (as fallback or primary method)\n // Note: RPC doesn't support consistency options, so we just paginate\n const limit = options?.fetchAll\n ? Number.MAX_SAFE_INTEGER\n : (options?.limit ?? 100);\n const offset = options?.offset ?? 0;\n\n const rpcResult = await this._getUserTrustedServersViaRpc({\n user,\n limit,\n offset,\n });\n\n return rpcResult.servers;\n }\n\n /**\n * Internal method: Query trusted servers via subgraph\n *\n * @param params - Query parameters object\n * @param params.user - The user address to query trusted servers for\n * @param params.subgraphUrl - The subgraph URL endpoint to query\n * @returns Promise resolving to an array of trusted server objects\n */\n private async _getUserTrustedServersViaSubgraph(\n params: {\n user: Address;\n subgraphUrl?: string;\n },\n options?: PaginationOptions,\n ): Promise<TrustedServer[]> {\n const { user, subgraphUrl } = params;\n\n const graphqlEndpoint = subgraphUrl;\n if (!graphqlEndpoint) {\n throw new Error(\n \"subgraphUrl is required for subgraph mode. Please provide a valid subgraph endpoint or configure it in Vana constructor.\",\n );\n }\n\n try {\n // Map orderBy string to GraphQL enum values\n const orderByMap: Record<string, UserServer_OrderByType> = {\n id: \"id\",\n trustedAt: \"trustedAt\",\n trustedAtBlock: \"trustedAtBlock\",\n server: \"server\",\n user: \"user\",\n };\n\n // Define the raw server trust type from the GraphQL response\n type RawServerTrust = NonNullable<\n GetUserTrustedServersPaginatedQuery[\"user\"]\n >[\"serverTrusts\"][0];\n\n // Use the generic pagination utility\n const serverTrusts = await executePaginatedQuery<\n GetUserTrustedServersPaginatedQuery,\n TrustedServer,\n RawServerTrust\n >({\n endpoint: graphqlEndpoint,\n document: GetUserTrustedServersPaginatedDocument,\n baseVariables: {\n userId: user.toLowerCase(), // Subgraph requires lowercase addresses\n orderBy: mapOrderByToEnum(\n options?.orderBy,\n orderByMap,\n \"trustedAtBlock\",\n ),\n orderDirection: mapOrderDirection(\n options?.orderDirection,\n \"desc\",\n \"asc\",\n ),\n },\n options,\n extractItems: (data) => {\n // Filter out untrusted servers at extraction time\n const trusts = data?.user?.serverTrusts ?? [];\n return trusts.filter((trust) => !trust.untrustedAtBlock);\n },\n transformItem: (trust) => ({\n id: trust.server.id,\n serverAddress: trust.server.serverAddress as Address,\n serverUrl: trust.server.url,\n trustedAt: BigInt(trust.trustedAt),\n user,\n name: \"\", // Not available in new schema, will be empty\n }),\n });\n\n return serverTrusts;\n } catch (error) {\n console.error(\"Failed to query trusted servers from subgraph:\", error);\n throw error;\n }\n }\n\n /**\n * Internal method: Query trusted servers via direct RPC\n *\n * @param params - Query parameters object\n * @param params.user - The user address to query trusted servers for\n * @param params.limit - Maximum number of results to return\n * @param params.offset - Number of results to skip for pagination\n * @returns Promise resolving to pagination result with servers, total count, and hasMore flag\n */\n private async _getUserTrustedServersViaRpc(params: {\n user: Address;\n limit: number;\n offset: number;\n }): Promise<{\n servers: TrustedServer[];\n total: number;\n hasMore: boolean;\n }> {\n const { user, limit, offset } = params;\n\n try {\n const chainId = this.context.publicClient.chain?.id;\n if (!chainId) {\n throw new Error(\"Chain ID not available\");\n }\n\n const DataPortabilityServersAddress = getContractAddress(\n chainId,\n \"DataPortabilityServers\",\n );\n const DataPortabilityServersAbi = getAbi(\"DataPortabilityServers\");\n\n // Get total count first\n const totalCount = await this.context.publicClient.readContract({\n address: DataPortabilityServersAddress,\n abi: DataPortabilityServersAbi,\n functionName: \"userServerIdsLength\",\n args: [user],\n });\n\n const total = Number(totalCount);\n\n if (total === 0 || offset >= total) {\n return {\n servers: [],\n total,\n hasMore: false,\n };\n }\n\n // Calculate pagination\n const endIndex = Math.min(offset + limit, total);\n\n // Fetch server IDs using gasAwareMulticall\n const serverIdCalls = [];\n for (let i = offset; i < endIndex; i++) {\n serverIdCalls.push({\n address: DataPortabilityServersAddress,\n abi: DataPortabilityServersAbi,\n functionName: \"userServerIdsAt\",\n args: [user, BigInt(i)],\n });\n }\n\n const serverIdResults = await gasAwareMulticall<\n typeof serverIdCalls,\n false\n >(this.context.publicClient, {\n contracts: serverIdCalls,\n });\n\n // Extract server IDs from results\n const serverIds = serverIdResults\n .map((result) => result as bigint)\n .filter((id) => id && id > 0n);\n\n // Build server info calls for multicall\n const serverInfoCalls = serverIds.map(\n (serverId) =>\n ({\n address: DataPortabilityServersAddress,\n abi: DataPortabilityServersAbi,\n functionName: \"servers\",\n args: [serverId],\n }) as const,\n );\n\n // Fetch all server info in a single multicall\n const serverInfoResults = await gasAwareMulticall<\n typeof serverInfoCalls,\n true // Allow failures for individual server lookups\n >(this.context.publicClient, {\n contracts: serverInfoCalls,\n allowFailure: true,\n });\n\n // Process results\n const servers = serverInfoResults.map((result, index) => {\n const serverId = serverIds[index];\n\n if (result.status === \"success\" && result.result) {\n const serverInfo = result.result as {\n id: bigint;\n owner: Address;\n serverAddress: Address;\n publicKey: string;\n url: string;\n };\n\n return {\n id: `${user.toLowerCase()}-${serverId.toString()}`,\n serverAddress: serverInfo.serverAddress,\n serverUrl: serverInfo.url,\n trustedAt: BigInt(Date.now()),\n user,\n trustIndex: offset + index,\n };\n } else {\n // If server info fails, return basic info\n return {\n id: `${user.toLowerCase()}-${serverId.toString()}`,\n serverAddress:\n \"0x0000000000000000000000000000000000000000\" as Address,\n serverUrl: \"\",\n trustedAt: BigInt(Date.now()),\n user,\n trustIndex: offset + index,\n };\n }\n });\n\n return {\n servers,\n total,\n hasMore: offset + limit < total,\n };\n } catch (error) {\n throw new Error(\n `RPC query failed: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Retrieves total file count from Data Registry.\n *\n * @remarks\n * Queries blockchain for complete file count across all users.\n * Useful for pagination and network statistics.\n *\n * @returns Total number of registered files\n *\n * @throws {Error} Chain ID not available.\n * Ensure network connection.\n * @throws {Error} Contract read failed.\n * Check RPC availability.\n *\n * @example\n * ```typescript\n * const total = await vana.data.getTotalFilesCount();\n * console.log(`Total files: ${total}`);\n *\n * // Calculate pagination\n * const pages = Math.ceil(total / 20);\n * ```\n */\n async getTotalFilesCount(): Promise<number> {\n try {\n const chainId = this.context.publicClient.chain?.id;\n if (!chainId) {\n throw new Error(\"Chain ID not available\");\n }\n\n const dataRegistryAddress = getContractAddress(chainId, \"DataRegistry\");\n const dataRegistryAbi = getAbi(\"DataRegistry\");\n\n const dataRegistry = getContract({\n address: dataRegistryAddress,\n abi: dataRegistryAbi,\n client: this.context.publicClient,\n });\n\n const count = await dataRegistry.read.filesCount();\n return Number(count);\n } catch (error) {\n // Re-throw validation errors (like missing chain ID)\n if (\n error instanceof Error &&\n error.message === \"Chain ID not available\"\n ) {\n throw error;\n }\n\n // Return 0 for contract errors\n console.error(\"Failed to fetch total files count:\", error);\n return 0;\n }\n }\n\n /**\n * Retrieves file metadata by ID from the blockchain.\n *\n * @remarks\n * Queries DataRegistry contract directly for file details.\n * Works for any file ID regardless of ownership, enabling\n * cross-user file discovery and verification.\n *\n * @param fileId - Numeric file ID to retrieve\n *\n * @returns UserFile object with metadata\n *\n * @throws {Error} Chain ID not available.\n * Ensure proper network connection.\n * @throws {Error} File not found.\n * Verify file ID exists on-chain.\n * @throws {Error} Contract call failed.\n * Check network and RPC availability.\n *\n * @example\n * ```typescript\n * const file = await vana.data.getFileById(123);\n * console.log(`File ${file.id}:`);\n * console.log(` URL: ${file.url}`);\n * console.log(` Owner: ${file.ownerAddress}`);\n * console.log(` Block: ${file.addedAtBlock}`);\n * ```\n */\n async getFileById(fileId: number): Promise<UserFile> {\n try {\n const chainId = this.context.publicClient.chain?.id;\n if (!chainId) {\n throw new Error(\"Chain ID not available\");\n }\n\n const dataRegistryAddress = getContractAddress(chainId, \"DataRegistry\");\n const dataRegistryAbi = getAbi(\"DataRegistry\");\n\n const dataRegistry = getContract({\n address: dataRegistryAddress,\n abi: dataRegistryAbi,\n client: this.context.publicClient,\n });\n\n const fileDetails = await dataRegistry.read.files([BigInt(fileId)]);\n\n if (!fileDetails) {\n throw new Error(\"File not found\");\n }\n\n // Handle both array format (from contracts) and object format\n if (Array.isArray(fileDetails)) {\n const [id, url, ownerAddress, addedAtBlock] =\n fileDetails as unknown as [bigint, string, Address, bigint];\n if (id === BigInt(0)) {\n throw new Error(\"File not found\");\n }\n return {\n id: Number(id),\n url,\n ownerAddress,\n addedAtBlock: BigInt(addedAtBlock),\n };\n } else {\n // Object format\n if (!fileDetails.id || fileDetails.id === BigInt(0)) {\n throw new Error(\"File not found\");\n }\n return {\n id: Number(fileDetails.id),\n ownerAddress: fileDetails.ownerAddress,\n url: fileDetails.url,\n addedAtBlock: BigInt(fileDetails.addedAtBlock),\n };\n }\n } catch (error) {\n console.error(\"Failed to fetch file by ID:\", error);\n throw new Error(\n `Failed to fetch file ${fileId}: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Registers a file URL directly on the blockchain with a schema ID.\n *\n * @remarks\n * This method registers an existing file URL on the DataRegistry contract\n * with a schema ID, without uploading any data. Useful when you have already\n * uploaded content to storage and just need to register it on-chain.\n *\n * @param url - The URL of the file to register (IPFS or HTTP/HTTPS)\n * @param schemaId - The schema ID to associate with the file\n * @returns Promise resolving to the file ID and transaction hash\n * @throws {Error} When chain ID is not available - \"Chain ID not available\"\n * @throws {Error} When wallet address is unavailable - \"No addresses available\"\n * @throws {Error} When transaction fails - \"Failed to register file with schema\"\n * @example\n * ```typescript\n * const { fileId, transactionHash } = await vana.data.registerFileWithSchema(\n * \"ipfs://QmXxx...\",\n * 1\n * );\n * console.log(`File ${fileId} registered with schema in tx ${transactionHash}`);\n * ```\n */\n async registerFileWithSchema(\n url: string,\n schemaId: number,\n options?: TransactionOptions,\n ): Promise<TransactionResult<\"DataRegistry\", \"addFileWithSchema\">> {\n this.assertWallet();\n\n try {\n const chainId = this.context.publicClient.chain?.id;\n if (!chainId) {\n throw new Error(\"Chain ID not available\");\n }\n\n this.assertWallet();\n const dataRegistryAddress = getContractAddress(chainId, \"DataRegistry\");\n const dataRegistryAbi = getAbi(\"DataRegistry\");\n const account =\n this.context.walletClient.account ?? this.context.userAddress;\n const from = typeof account === \"string\" ? account : account.address;\n\n const hash = await this.context.walletClient.writeContract({\n address: dataRegistryAddress,\n abi: dataRegistryAbi,\n functionName: \"addFileWithSchema\",\n args: [url, BigInt(schemaId)],\n account,\n chain: this.context.walletClient.chain ?? null,\n ...this.spreadTransactionOptions(options),\n });\n\n const { tx } = await import(\"../utils/transactionHelpers\");\n return tx({\n hash,\n from,\n contract: \"DataRegistry\",\n fn: \"addFileWithSchema\",\n });\n } catch (error) {\n console.error(\"Failed to register file with schema:\", error);\n throw new Error(\n `Registration failed: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Gets the user's address from the wallet client.\n *\n * @returns Promise resolving to the user's wallet address\n * @throws {Error} When no addresses are available in wallet client\n */\n\n /**\n * Adds a file with permissions to the DataRegistry contract.\n *\n * @param url - The file URL to register\n * @param ownerAddress - The address of the file owner\n * @param permissions - Array of permissions to set for the file\n * @returns Promise resolving to file ID and transaction hash\n * @throws {Error} When chain ID is not available\n * @throws {ContractError} When contract execution fails\n * @throws {Error} When transaction receipt is not available\n * @throws {Error} When FileAdded event cannot be parsed\n *\n * This method handles the core logic of registering a file\n * with specific permissions on the DataRegistry contract. It can be used\n * by both direct transactions and relayer services.\n */\n async addFileWithPermissions(\n url: string,\n ownerAddress: Address,\n permissions: Array<{ account: Address; key: string }> = [],\n options?: TransactionOptions,\n ): Promise<TransactionResult<\"DataRegistry\", \"addFileWithPermissions\">> {\n this.assertWallet();\n\n try {\n const chainId = this.context.publicClient.chain?.id;\n if (!chainId) {\n throw new Error(\"Chain ID not available\");\n }\n\n this.assertWallet();\n const dataRegistryAddress = getContractAddress(chainId, \"DataRegistry\");\n const dataRegistryAbi = getAbi(\"DataRegistry\");\n const account = this.context.walletClient.account ?? ownerAddress;\n const from = typeof account === \"string\" ? account : account.address;\n\n // Execute the transaction using the wallet client\n const hash = await this.context.walletClient.writeContract({\n address: dataRegistryAddress,\n abi: dataRegistryAbi,\n functionName: \"addFileWithPermissions\",\n args: [url, ownerAddress, permissions],\n account,\n chain: this.context.walletClient.chain ?? null,\n ...this.spreadTransactionOptions(options),\n });\n\n const { tx } = await import(\"../utils/transactionHelpers\");\n return tx({\n hash,\n from,\n contract: \"DataRegistry\",\n fn: \"addFileWithPermissions\",\n });\n } catch (error) {\n console.error(\"Failed to add file with permissions:\", error);\n throw new Error(\n `Failed to add file with permissions: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Adds a file to the registry with permissions and schema.\n * This combines the functionality of addFileWithPermissions and schema validation.\n *\n * @remarks\n * This method automatically encrypts permissions when a publicKey is provided.\n * It generates the user's encryption key and encrypts it with each recipient's\n * public key before registering on the blockchain.\n *\n * @param url - The URL of the file to register\n * @param ownerAddress - The address of the file owner\n * @param permissions - Array of permissions to grant, each with account and publicKey properties\n * @param schemaId - The schema ID to associate with the file (0 for no schema)\n * @returns Promise resolving to TransactionResult with fileId and transactionHash\n * @throws {Error} \"Chain ID not available\" - When wallet chain is not configured\n * @throws {Error} \"Failed to generate encryption key\" - When encryption key generation fails\n * @throws {Error} \"Permission for {account} must include 'publicKey'\" - When publicKey is missing\n * @throws {Error} \"Failed to add file with permissions and schema: {error}\" - When transaction fails\n * @example\n * ```typescript\n * // Get server's public key\n * const serverIdentity = await vana.server.getIdentity({\n * userAddress: \"0x...\"\n * });\n *\n * // Add file with permissions and schema\n * const result = await vana.data.addFileWithPermissionsAndSchema(\n * \"ipfs://QmXxx...\",\n * ownerAddress,\n * [{\n * account: serverIdentity.address,\n * publicKey: serverIdentity.publicKey\n * }],\n * schemaId\n * );\n *\n * console.log(`File ${result.fileId} registered in tx ${result.hash}`);\n * ```\n */\n async addFileWithPermissionsAndSchema(\n url: string,\n ownerAddress: Address,\n permissions: Array<{ account: Address; publicKey: string }> = [],\n schemaId: number = 0,\n options?: TransactionOptions,\n ): Promise<\n TransactionResult<\"DataRegistry\", \"addFileWithPermissionsAndSchema\">\n > {\n this.assertWallet();\n\n try {\n // Process permissions - always encrypt with publicKey\n let encryptedPermissions: Array<{ account: Address; key: string }> = [];\n\n if (permissions.length > 0) {\n this.assertWallet();\n // Generate user's encryption key\n const userEncryptionKey = await generateEncryptionKey(\n this.context.walletClient,\n this.context.platform,\n DEFAULT_ENCRYPTION_SEED,\n );\n\n encryptedPermissions = await Promise.all(\n permissions.map(async (permission) => {\n if (!permission.publicKey) {\n throw new Error(\n `Permission for ${permission.account} must include 'publicKey'`,\n );\n }\n\n const encryptedKey = await encryptWithWalletPublicKey(\n userEncryptionKey,\n permission.publicKey,\n this.context.platform,\n );\n\n return {\n account: permission.account,\n key: encryptedKey,\n };\n }),\n );\n }\n\n // Call the method with encrypted permissions\n return await this.addFileWithEncryptedPermissionsAndSchema(\n url,\n ownerAddress,\n encryptedPermissions,\n schemaId,\n options,\n );\n } catch (error) {\n console.error(\"Failed to add file with permissions and schema:\", error);\n throw new Error(\n `Failed to add file with permissions and schema: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Adds a file with pre-encrypted permissions and schema to the DataRegistry.\n *\n * @remarks\n * This method is designed for relay services and advanced use cases where permissions\n * have already been encrypted client-side. Unlike `addFileWithPermissionsAndSchema()`,\n * this method expects permissions in the encrypted format with a 'key' field instead\n * of 'publicKey'.\n *\n * This is typically used by relay endpoints that receive pre-encrypted data from\n * the client SDK's `upload()` method, avoiding double encryption.\n *\n * @param url - The storage URL of the file (e.g., IPFS URL)\n * @param ownerAddress - The address that will own this file\n * @param permissions - Array of pre-encrypted permissions with 'account' and 'key' fields\n * @param schemaId - Optional schema ID for data validation (defaults to 0)\n * @returns Promise resolving to transaction result with hash and contract details\n * @throws {Error} When chain ID is not available\n * @throws {Error} When wallet is not connected\n * @throws {Error} When transaction fails\n * @example\n * ```typescript\n * // In a relay endpoint that receives pre-encrypted permissions\n * const result = await vana.data.addFileWithEncryptedPermissionsAndSchema(\n * \"ipfs://QmXxx...\",\n * ownerAddress,\n * [\n * {\n * account: \"0xServerAddress...\",\n * key: \"encrypted_key_string\" // Already encrypted by client\n * }\n * ],\n * schemaId\n * );\n *\n * console.log(`File registered in tx ${result.hash}`);\n * ```\n */\n async addFileWithEncryptedPermissionsAndSchema(\n url: string,\n ownerAddress: Address,\n permissions: Array<{ account: Address; key: string }> = [],\n schemaId: number = 0,\n options?: TransactionOptions,\n ): Promise<\n TransactionResult<\"DataRegistry\", \"addFileWithPermissionsAndSchema\">\n > {\n try {\n const chainId = this.context.publicClient.chain?.id;\n if (!chainId) {\n throw new Error(\"Chain ID not available\");\n }\n\n this.assertWallet();\n const dataRegistryAddress = getContractAddress(chainId, \"DataRegistry\");\n const dataRegistryAbi = getAbi(\"DataRegistry\");\n const account = this.context.walletClient.account ?? ownerAddress;\n const from = typeof account === \"string\" ? account : account.address;\n\n // Execute the transaction using the wallet client\n const hash = await this.context.walletClient.writeContract({\n address: dataRegistryAddress,\n abi: dataRegistryAbi,\n functionName: \"addFileWithPermissionsAndSchema\",\n args: [url, ownerAddress, permissions, BigInt(schemaId)],\n account,\n chain: this.context.walletClient.chain ?? null,\n ...this.spreadTransactionOptions(options),\n });\n\n const { tx } = await import(\"../utils/transactionHelpers\");\n return tx({\n hash,\n from,\n contract: \"DataRegistry\",\n fn: \"addFileWithPermissionsAndSchema\",\n });\n } catch (error) {\n console.error(\"Failed to add file with permissions and schema:\", error);\n throw new Error(\n `Failed to add file with permissions and schema: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Registers a data refiner for processing templates.\n *\n * @remarks\n * Refiners define data transformation rules for DLPs.\n * Associates schema, instructions, and processing logic.\n *\n * @param params - Refiner configuration\n * @param params.dlpId - Data Liquidity Pool ID\n * @param params.name - Refiner display name\n * @param params.schemaId - Output schema ID.\n * Obtain via `vana.schemas.list()`.\n * @param params.refinementInstructionUrl - Processing instructions URL\n *\n * @returns Refiner ID and transaction hash\n *\n * @throws {Error} Chain ID not available.\n * Ensure network connection.\n * @throws {Error} Transaction failed.\n * Check wallet balance and network status.\n *\n * @example\n * ```typescript\n * const result = await vana.data.addRefiner({\n * dlpId: 1,\n * name: \"Sentiment Analyzer\",\n * schemaId: 42,\n * refinementInstructionUrl: \"ipfs://QmXxx...\"\n * });\n * console.log(`Refiner ${result.refinerId} created`);\n * ```\n */\n async addRefiner(\n params: AddRefinerParams,\n options?: TransactionOptions,\n ): Promise<AddRefinerResult> {\n this.assertWallet();\n\n try {\n const chainId = this.context.publicClient.chain?.id;\n if (!chainId) {\n throw new Error(\"Chain ID not available\");\n }\n\n const dataRefinerRegistryAddress = getContractAddress(\n chainId,\n \"DataRefinerRegistry\",\n );\n const dataRefinerRegistryAbi = getAbi(\"DataRefinerRegistry\");\n this.assertWallet();\n const account =\n this.context.walletClient.account ?? this.context.userAddress;\n const from = typeof account === \"string\" ? account : account.address;\n\n const hash = await this.context.walletClient.writeContract({\n address: dataRefinerRegistryAddress,\n abi: dataRefinerRegistryAbi,\n functionName: \"addRefinerWithSchemaId\",\n args: [\n BigInt(params.dlpId),\n params.name,\n BigInt(params.schemaId),\n params.refinementInstructionUrl,\n ],\n account,\n chain: this.context.walletClient.chain ?? null,\n ...this.spreadTransactionOptions(options),\n });\n\n // Create TransactionResult POJO\n const { tx } = await import(\"../utils/transactionHelpers\");\n const txResult = tx({\n hash,\n from,\n contract: \"DataRefinerRegistry\",\n fn: \"addRefinerWithSchemaId\",\n });\n\n // Wait for events and extract domain data\n if (!this.context.waitForTransactionEvents) {\n throw new Error(\"waitForTransactionEvents not configured\");\n }\n\n const result = await this.context.waitForTransactionEvents(txResult);\n const event = result.expectedEvents.RefinerAdded;\n if (!event) {\n throw new Error(\"RefinerAdded event not found in transaction\");\n }\n\n return {\n refinerId: Number(event.refinerId),\n transactionHash: hash,\n };\n } catch (error) {\n console.error(\"Failed to add refiner:\", error);\n throw new Error(\n `Failed to add refiner: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Retrieves refiner configuration by ID.\n *\n * @remarks\n * Queries DataRefinerRegistry for refiner details.\n * Returns DLP association, schema, and processing instructions.\n *\n * @param refinerId - Numeric refiner ID\n *\n * @returns Refiner configuration object\n *\n * @throws {Error} Chain ID not available.\n * Ensure network connection.\n * @throws {Error} Refiner not found.\n * Verify refiner ID exists.\n * @throws {Error} Contract read failed.\n * Check network and RPC status.\n *\n * @example\n * ```typescript\n * const refiner = await vana.data.getRefiner(1);\n * console.log(`Refiner: ${refiner.name}`);\n * console.log(`DLP: ${refiner.dlpId}`);\n * console.log(`Schema: ${refiner.schemaId}`);\n * ```\n */\n async getRefiner(refinerId: number): Promise<Refiner> {\n try {\n const chainId = this.context.publicClient.chain?.id;\n if (!chainId) {\n throw new Error(\"Chain ID not available\");\n }\n\n const dataRefinerRegistryAddress = getContractAddress(\n chainId,\n \"DataRefinerRegistry\",\n );\n const dataRefinerRegistryAbi = getAbi(\"DataRefinerRegistry\");\n\n const dataRefinerRegistry = getContract({\n address: dataRefinerRegistryAddress,\n abi: dataRefinerRegistryAbi,\n client: this.context.publicClient,\n });\n\n const refinerData = await dataRefinerRegistry.read.refiners([\n BigInt(refinerId),\n ]);\n\n if (!refinerData) {\n throw new Error(\"Refiner not found\");\n }\n\n return {\n id: refinerId,\n dlpId: Number(refinerData.dlpId),\n owner: refinerData.owner,\n name: refinerData.name,\n schemaId: Number(refinerData.schemaId),\n refinementInstructionUrl: refinerData.refinementInstructionUrl,\n };\n } catch (error) {\n console.error(\"Failed to get refiner:\", error);\n throw new Error(\n `Failed to get refiner ${refinerId}: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Validates schema ID existence.\n *\n * @remarks\n * Verifies schema registration in DataRegistry.\n * Check before using schemas for uploads.\n *\n * @param schemaId - Numeric schema ID to validate\n *\n * @returns True if schema exists, false otherwise\n *\n * @throws {Error} Chain ID not available.\n * Ensure network connection.\n * @throws {Error} Contract read failed.\n * Check RPC availability.\n *\n * @example\n * ```typescript\n * const valid = await vana.data.isValidSchemaId(42);\n * if (valid) {\n * // Safe to use schema 42\n * await vana.data.upload({ schemaId: 42, ... });\n * }\n * ```\n */\n async isValidSchemaId(schemaId: number): Promise<boolean> {\n try {\n const chainId = this.context.publicClient.chain?.id;\n if (!chainId) {\n throw new Error(\"Chain ID not available\");\n }\n\n const dataRefinerRegistryAddress = getContractAddress(\n chainId,\n \"DataRefinerRegistry\",\n );\n const dataRefinerRegistryAbi = getAbi(\"DataRefinerRegistry\");\n\n const dataRefinerRegistry = getContract({\n address: dataRefinerRegistryAddress,\n abi: dataRefinerRegistryAbi,\n client: this.context.publicClient,\n });\n\n const isValid = await dataRefinerRegistry.read.isValidSchemaId([\n BigInt(schemaId),\n ]);\n return isValid;\n } catch (error) {\n console.error(\"Failed to validate schema ID:\", error);\n return false;\n }\n }\n\n /**\n * Gets the total number of refiners in the registry.\n *\n * @remarks\n * Queries the DataRefinerRegistry contract to get the total count of all\n * registered refiners across all DLPs.\n *\n * @returns Promise resolving to the total refiner count\n * @example\n * ```typescript\n * const count = await vana.data.getRefinersCount();\n * console.log(`Total refiners registered: ${count}`);\n * ```\n */\n async getRefinersCount(): Promise<number> {\n try {\n const chainId = this.context.publicClient.chain?.id;\n if (!chainId) {\n throw new Error(\"Chain ID not available\");\n }\n\n const dataRefinerRegistryAddress = getContractAddress(\n chainId,\n \"DataRefinerRegistry\",\n );\n const dataRefinerRegistryAbi = getAbi(\"DataRefinerRegistry\");\n\n const dataRefinerRegistry = getContract({\n address: dataRefinerRegistryAddress,\n abi: dataRefinerRegistryAbi,\n client: this.context.publicClient,\n });\n\n const count = await dataRefinerRegistry.read.refinersCount();\n return Number(count);\n } catch (error) {\n console.error(\"Failed to get refiners count:\", error);\n return 0;\n }\n }\n\n /**\n * Updates the schema ID for an existing refiner.\n *\n * @remarks\n * Allows the owner of a refiner to update its associated schema ID.\n * This is useful when refiner output format needs to change.\n *\n * @param params - Update parameters\n * @param params.refinerId - The refiner ID to update\n * @param params.newSchemaId - The new schema ID to set\n * @returns Promise resolving to the transaction hash\n * @throws {Error} When chain ID is not available - \"Chain ID not available\"\n * @throws {Error} When transaction fails - \"Failed to update schema ID: {error}\"\n * @example\n * ```typescript\n * const result = await vana.data.updateSchemaId({\n * refinerId: 1,\n * newSchemaId: 55\n * });\n * console.log(`Schema updated in tx ${result.transactionHash}`);\n * ```\n */\n async updateSchemaId(\n params: UpdateSchemaIdParams,\n options?: TransactionOptions,\n ): Promise<UpdateSchemaIdResult> {\n this.assertWallet();\n\n try {\n const chainId = this.context.publicClient.chain?.id;\n if (!chainId) {\n throw new Error(\"Chain ID not available\");\n }\n\n const dataRefinerRegistryAddress = getContractAddress(\n chainId,\n \"DataRefinerRegistry\",\n );\n const dataRefinerRegistryAbi = getAbi(\"DataRefinerRegistry\");\n this.assertWallet();\n const account =\n this.context.walletClient.account ?? this.context.userAddress;\n\n const hash = await this.context.walletClient.writeContract({\n address: dataRefinerRegistryAddress,\n abi: dataRefinerRegistryAbi,\n functionName: \"updateSchemaId\",\n args: [BigInt(params.refinerId), BigInt(params.newSchemaId)],\n account,\n chain: this.context.walletClient.chain ?? null,\n ...this.spreadTransactionOptions(options),\n });\n\n // Wait for transaction confirmation\n await this.context.publicClient.waitForTransactionReceipt({ hash });\n\n // Return simple domain result\n return {\n transactionHash: hash,\n };\n } catch (error) {\n console.error(\"Failed to update schema ID:\", error);\n throw new Error(\n `Failed to update schema ID: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Uploads an encrypted file and grants permission to a party with a public key.\n *\n * This method handles the complete workflow:\n * 1. Encrypts the file with the user's encryption key\n * 2. Uploads the encrypted file to storage\n * 3. Encrypts the user's encryption key with the provided public key\n * 4. Registers the file with permissions\n *\n * @param params - Upload parameters including data, permissions, and options\n * @returns Promise resolving to upload result with file ID and storage URL\n */\n async uploadFileWithPermissions(\n params: UploadFileWithPermissionsParams,\n ): Promise<UploadEncryptedFileResult> {\n this.assertWallet();\n\n const { data, permissions, filename, providerName } = params;\n\n try {\n // 1. Upload the file with encryption using the centralized method\n const uploadResult = await this.uploadToStorage(\n data,\n filename,\n true, // Always encrypt for uploadFileWithPermissions\n providerName,\n );\n\n // 2. Get user address\n const userAddress = this.context.userAddress;\n\n // 3. Generate user's encryption key (same as used in uploadToStorage)\n const userEncryptionKey = await generateEncryptionKey(\n this.context.walletClient,\n this.context.platform,\n DEFAULT_ENCRYPTION_SEED,\n );\n\n // 4. Encrypt user's encryption key for each permission\n const encryptedPermissions = await Promise.all(\n permissions.map(async (permission) => {\n const encryptedKey = await encryptWithWalletPublicKey(\n userEncryptionKey,\n permission.publicKey,\n this.context.platform,\n );\n return {\n account: permission.account,\n key: encryptedKey,\n };\n }),\n );\n\n // 5. Register file with permissions (either via relayer or direct)\n if (this.context.relayer) {\n // Use unified relayer callback for file addition with permissions\n const request: UnifiedRelayerRequest = {\n type: \"direct\",\n operation: \"submitFileAdditionWithPermissions\",\n params: {\n url: uploadResult.url,\n userAddress,\n permissions: encryptedPermissions,\n },\n };\n const response = await this.context.relayer(request);\n if (response.type === \"error\") {\n throw new Error(response.error);\n }\n\n // Handle pending response (stateful relayer)\n let result: { fileId: number; transactionHash: Hash };\n if (response.type === \"pending\") {\n result = await this.pollRelayerForConfirmation(\n response.operationId,\n undefined, // TODO: Add TransactionOptions to upload method signature\n );\n } else if (\n response.type === \"direct\" &&\n typeof response.result === \"object\" &&\n response.result !== null &&\n \"fileId\" in response.result\n ) {\n result = response.result as {\n fileId: number;\n transactionHash: Hash;\n };\n } else {\n throw new Error(\"Invalid response from relayer\");\n }\n return {\n fileId: result.fileId,\n url: uploadResult.url,\n size: uploadResult.size,\n transactionHash: result.transactionHash,\n };\n } else {\n // Direct transaction - returns TransactionResult POJO\n const txResult = await this.addFileWithPermissions(\n uploadResult.url,\n userAddress,\n encryptedPermissions,\n );\n\n // Wait for transaction events to get the actual fileId\n if (!this.context.waitForTransactionEvents) {\n throw new Error(\n \"Cannot upload without relay: waitForTransactionEvents not configured\",\n );\n }\n\n const eventResult =\n await this.context.waitForTransactionEvents(txResult);\n const fileAddedEvent = eventResult.expectedEvents.FileAdded;\n if (!fileAddedEvent) {\n throw new Error(\"FileAdded event not found in transaction\");\n }\n\n return {\n fileId: Number(fileAddedEvent.fileId),\n url: uploadResult.url,\n size: uploadResult.size,\n transactionHash: txResult.hash,\n };\n }\n } catch (error) {\n console.error(\"Failed to upload file with permissions:\", error);\n throw new Error(\n `Failed to upload file with permissions: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Uploads content to storage without registering it on the blockchain.\n * This method only handles the storage upload and returns the file URL.\n *\n * @param content - The content to upload (string, Blob, Buffer, or object - objects will be JSON stringified)\n * @param filename - Optional filename for the uploaded file (defaults to timestamp-based name)\n * @param encrypt - Optional flag to encrypt the content before upload\n * @param providerName - Optional specific storage provider to use\n * @returns Promise resolving to the storage upload result with url, size, and contentType\n */\n async uploadToStorage(\n content: string | Blob | Buffer | object,\n filename?: string,\n encrypt: boolean = false,\n providerName?: string,\n ): Promise<StorageUploadResult> {\n try {\n // Step 1: Normalize content to Blob\n let blob: Blob;\n if (content instanceof Blob) {\n blob = content;\n } else if (typeof content === \"string\") {\n blob = new Blob([content], { type: \"text/plain\" });\n } else if (content instanceof Buffer) {\n // Convert Buffer to ArrayBuffer for BlobPart compatibility in browser typings\n const arrayBuffer = content.buffer.slice(\n content.byteOffset,\n content.byteOffset + content.byteLength,\n ) as ArrayBuffer;\n blob = new Blob([arrayBuffer], { type: \"application/octet-stream\" });\n } else {\n // Handle objects by JSON stringifying them\n blob = new Blob([JSON.stringify(content)], {\n type: \"application/json\",\n });\n }\n\n // Step 3: Handle encryption\n let finalBlob = blob;\n if (encrypt) {\n this.assertWallet();\n\n // Generate encryption key\n const encryptionKey = await generateEncryptionKey(\n this.context.walletClient,\n this.context.platform,\n DEFAULT_ENCRYPTION_SEED,\n );\n\n // Encrypt the data\n finalBlob = await encryptBlobWithSignedKey(\n blob,\n encryptionKey,\n this.context.platform,\n );\n }\n\n // Step 4: Upload to storage\n if (!this.context.storageManager) {\n // Use centralized validation if available, otherwise fall back to old behavior\n if (this.context.validateStorageRequired) {\n this.context.validateStorageRequired();\n // The validateStorageRequired method throws, so this line should never be reached\n // but TypeScript doesn't know that, so we need this fallback\n throw new Error(\"Storage validation failed\");\n } else {\n throw new Error(\n \"Storage manager not configured. Please provide storage providers in VanaConfig.\",\n );\n }\n }\n\n // Determine final filename with proper .enc extension handling\n const finalFilename = (() => {\n if (filename) {\n // If encrypting and filename doesn't already have .enc extension, add it\n if (encrypt && !filename.endsWith(\".enc\")) {\n return `${filename}.enc`;\n }\n // Otherwise use filename as provided\n return filename;\n }\n // No filename provided - generate one based on encryption status\n return encrypt\n ? `upload-${Date.now()}.enc`\n : `upload-${Date.now()}.dat`;\n })();\n\n const uploadResult = await this.context.storageManager.upload(\n finalBlob,\n finalFilename,\n providerName,\n );\n\n return uploadResult;\n } catch (error) {\n throw new Error(\n `Upload failed: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Adds a permission for a party to access an existing file.\n *\n * This method handles the complete workflow:\n * 1. Gets the user's encryption key\n * 2. Encrypts the user's encryption key with the provided public key\n * 3. Adds the permission to the file\n * 4. Returns the permission data from the blockchain event\n *\n * For advanced users who need more control over transaction timing,\n * use `submitFilePermission()` instead.\n *\n * @param params - Parameters for adding file permission\n * @param params.fileId - The ID of the file to grant permission for\n * @param params.account - The recipient's wallet address that will access the file\n * @param params.publicKey - The recipient's public key for encryption.\n * Obtain via `vana.server.getIdentity(account).publicKey`\n * @returns Promise resolving to permission data from PermissionGranted event\n * @throws {Error} \"No addresses available in wallet client\" - When wallet is not connected\n * @throws {Error} \"Chain ID not available\" - When wallet chain is not configured\n * @throws {Error} \"Failed to add permission to file: {error}\" - When transaction fails or user doesn't own file\n * @example\n * ```typescript\n * const result = await vana.data.addPermissionToFile({\n * fileId: 123,\n * account: \"0xRecipientAddress...\",\n * publicKey: \"0xRecipientPublicKey...\"\n * });\n * console.log(`Permission granted to ${result.account} for file ${result.fileId}`);\n * console.log(`Transaction: ${result.transactionHash}`);\n * ```\n */\n async addPermissionToFile(\n params: AddFilePermissionParams,\n options?: TransactionOptions,\n ): Promise<TransactionResult<\"DataRegistry\", \"addFilePermission\">> {\n this.assertWallet();\n\n const { fileId, account, publicKey } = params;\n return await this.submitFilePermission(fileId, account, publicKey, options);\n }\n\n /**\n * Submits a file permission transaction to the blockchain.\n *\n * @remarks\n * This method supports gasless transactions via relayer callbacks when configured.\n * It encrypts the user's encryption key with the recipient's public key before submission.\n * Use this when you want to handle transaction confirmation and event parsing separately.\n *\n * @param fileId - The ID of the file to grant permission for\n * @param account - The recipient's wallet address that will access the file\n * @param publicKey - The recipient's public key for encryption.\n * Obtain via `vana.server.getIdentity(account).publicKey`\n * @returns Promise resolving to TransactionResult for tracking the transaction\n * @throws {Error} When chain ID is not available\n * @throws {Error} When encryption key generation fails\n * @throws {Error} When public key encryption fails\n *\n * @example\n * ```typescript\n * const tx = await vana.data.submitFilePermission(\n * fileId,\n * \"0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36\",\n * recipientPublicKey\n * );\n * const result = await tx.waitForEvents();\n * console.log(`Permission granted with ID: ${result.permissionId}`);\n * ```\n */\n async submitFilePermission(\n fileId: number,\n account: Address,\n publicKey: string,\n options?: TransactionOptions,\n ): Promise<TransactionResult<\"DataRegistry\", \"addFilePermission\">> {\n this.assertWallet();\n\n try {\n // 1. Generate user's encryption key\n const userEncryptionKey = await generateEncryptionKey(\n this.context.walletClient,\n this.context.platform,\n DEFAULT_ENCRYPTION_SEED,\n );\n\n // 2. Encrypt user's encryption key with provided public key\n const encryptedKey = await encryptWithWalletPublicKey(\n userEncryptionKey,\n publicKey,\n this.context.platform,\n );\n\n // 3. Submit directly to the blockchain\n const chainId = this.context.publicClient.chain?.id;\n if (!chainId) {\n throw new Error(\"Chain ID not available\");\n }\n\n const dataRegistryAddress = getContractAddress(chainId, \"DataRegistry\");\n const dataRegistryAbi = getAbi(\"DataRegistry\");\n\n this.assertWallet();\n const walletAccount =\n this.context.walletClient.account ?? this.context.userAddress;\n\n const txHash = await this.context.walletClient.writeContract({\n address: dataRegistryAddress,\n abi: dataRegistryAbi,\n functionName: \"addFilePermission\",\n args: [BigInt(fileId), account, encryptedKey],\n account: walletAccount,\n chain: this.context.walletClient.chain ?? null,\n ...this.spreadTransactionOptions(options),\n });\n\n const { tx } = await import(\"../utils/transactionHelpers\");\n return tx({\n hash: txHash,\n from:\n typeof walletAccount === \"string\"\n ? walletAccount\n : walletAccount.address,\n contract: \"DataRegistry\",\n fn: \"addFilePermission\",\n });\n } catch (error) {\n console.error(\"Failed to add permission to file:\", error);\n throw new Error(\n `Failed to add permission to file: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Gets the encrypted key for a specific account's permission to access a file.\n *\n * @param fileId - The ID of the file\n * @param account - The account address to get the permission for\n * @returns Promise resolving to the encrypted key for that account\n */\n async getFilePermission(fileId: number, account: Address): Promise<string> {\n try {\n const chainId = this.context.publicClient.chain?.id;\n if (!chainId) {\n throw new Error(\"Chain ID not available\");\n }\n\n const dataRegistryAddress = getContractAddress(chainId, \"DataRegistry\");\n const dataRegistryAbi = getAbi(\"DataRegistry\");\n\n const dataRegistry = getContract({\n address: dataRegistryAddress,\n abi: dataRegistryAbi,\n client: this.context.publicClient,\n });\n\n const encryptedKey = await dataRegistry.read.filePermissions([\n BigInt(fileId),\n account,\n ]);\n\n return encryptedKey;\n } catch (error) {\n console.error(\"Failed to get file permission:\", error);\n throw new Error(\n `Failed to get file permission: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Decrypts a file that the user has permission to access using their private key.\n *\n * This method handles the complete workflow for servers or other permitted parties:\n * 1. Gets the encrypted encryption key from file permissions\n * 2. Decrypts the encryption key using the provided private key\n * 3. Downloads and decrypts the file data\n *\n * @param file - The file to decrypt\n * @param privateKey - The private key to decrypt the user's encryption key\n * @param options - Optional decryption configuration\n * @param options.account - The account address that has permission (defaults to current wallet account)\n * @returns Promise resolving to the decrypted file data\n */\n async decryptFileWithPermission(\n file: UserFile,\n privateKey: string,\n options?: DecryptFileWithPermissionOptions,\n ): Promise<Blob> {\n try {\n // Use provided account or get current wallet account\n const permissionAccount = options?.account ?? this.context.userAddress;\n\n // 1. Get the encrypted encryption key from file permissions\n const encryptedKey = await this.getFilePermission(\n file.id,\n permissionAccount,\n );\n\n if (!encryptedKey) {\n throw new Error(\n `No permission found for account ${permissionAccount} to access file ${file.id}`,\n );\n }\n\n // 2. Decrypt the encryption key using the private key\n const userEncryptionKey = await decryptWithWalletPrivateKey(\n encryptedKey,\n privateKey,\n this.context.platform,\n );\n\n // 3. Download the encrypted file\n // Use fetchFromIPFS for IPFS URLs, otherwise use regular fetch\n let encryptedData: Blob;\n if (file.url.startsWith(\"ipfs://\")) {\n encryptedData = await this.fetchFromIPFS(file.url);\n } else {\n encryptedData = await this.fetch(file.url);\n }\n\n // 4. Decrypt the file data using the user's encryption key\n const decryptedData = await decryptBlobWithSignedKey(\n encryptedData,\n userEncryptionKey,\n this.context.platform,\n );\n\n return decryptedData;\n } catch (error) {\n console.error(\"Failed to decrypt file with permission:\", error);\n throw new Error(\n `Failed to decrypt file with permission: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Simple network-agnostic fetch utility for retrieving file content.\n *\n * @remarks\n * This is a thin wrapper around the global fetch API that returns the response as a Blob.\n * It provides a consistent interface for fetching encrypted content before decryption.\n * For IPFS URLs, consider using fetchFromIPFS for better reliability.\n *\n * @param url - The URL to fetch content from\n * @returns Promise resolving to the fetched content as a Blob\n * @throws {Error} \"HTTP error! status: {status} {statusText}\" - When server returns error status\n * @throws {Error} \"Empty response\" - When server returns no content\n * @throws {Error} \"Network error: Failed to fetch from {url}\" - When network request fails\n *\n * @example\n * ```typescript\n * // Fetch and decrypt a file\n * const encryptionKey = await generateEncryptionKey(walletClient);\n * const encryptedBlob = await vana.data.fetch(file.url);\n * const decryptedBlob = await decryptBlob(encryptedBlob, encryptionKey, platform);\n *\n * // With custom headers for authentication\n * const response = await fetch(file.url, {\n * headers: { 'Authorization': 'Bearer token' }\n * });\n * const encryptedBlob = await response.blob();\n * ```\n */\n async fetch(url: string): Promise<Blob> {\n try {\n const { universalFetch } = await import(\"../utils/download\");\n const response = await universalFetch(url, this.context.downloadRelayer);\n\n if (!response.ok) {\n throw new Error(\n `HTTP error! status: ${response.status} ${response.statusText}`,\n );\n }\n\n const blob = await response.blob();\n\n // Check if blob is empty\n if (blob.size === 0) {\n throw new Error(\"Empty response\");\n }\n\n return blob;\n } catch (error) {\n if (error instanceof TypeError && error.message.includes(\"fetch\")) {\n throw new Error(\n `Network error: Failed to fetch from ${url}. The URL may be invalid or the server may not be accessible.`,\n );\n }\n throw error;\n }\n }\n\n /**\n * Specialized IPFS fetcher with gateway fallback mechanism.\n *\n * @remarks\n * This method provides robust IPFS content fetching by trying multiple gateways\n * in sequence until one succeeds. It supports both ipfs:// URLs and raw CIDs.\n *\n * The default gateway list includes public gateways, but you should provide\n * your own gateways for production use to ensure reliability and privacy.\n *\n * @param url - The IPFS URL (ipfs://...) or CID to fetch\n * @param options - Optional configuration\n * @param options.gateways - Array of IPFS gateway URLs to try (must end with /)\n * @returns Promise resolving to the fetched content as a Blob\n * @throws {Error} \"Invalid IPFS URL format\" - When URL is not ipfs:// or valid CID\n * @throws {Error} \"Empty response\" - When gateway returns no content\n * @throws {Error} \"HTTP error! status: {status}\" - When gateway returns error status\n * @throws {Error} \"Failed to fetch IPFS content {cid} from all gateways\" - When all gateways fail\n *\n * @example\n * ```typescript\n * // Fetch from IPFS with custom gateways\n * const encryptedBlob = await vana.data.fetchFromIPFS(file.url, {\n * gateways: [\n * 'https://my-private-gateway.com/ipfs/',\n * 'https://dweb.link/ipfs/',\n * 'https://ipfs.io/ipfs/'\n * ]\n * });\n *\n * // Decrypt the fetched content\n * const encryptionKey = await generateEncryptionKey(walletClient);\n * const decryptedBlob = await decryptBlob(encryptedBlob, encryptionKey, platform);\n *\n * // With raw CID\n * const blob = await vana.data.fetchFromIPFS('QmXxx...', {\n * gateways: ['https://ipfs.io/ipfs/']\n * });\n * ```\n */\n async fetchFromIPFS(\n url: string,\n options?: { gateways?: string[] },\n ): Promise<Blob> {\n // Default public gateways (in order of preference)\n const defaultGateways = [\n \"https://dweb.link/ipfs/\",\n \"https://ipfs.io/ipfs/\",\n ];\n\n // Use per-call gateways if provided, otherwise use app-wide gateways, otherwise use defaults\n const gateways =\n options?.gateways ?? this.context.ipfsGateways ?? defaultGateways;\n\n // Use ipfs utilities to extract hash\n const { extractIpfsHash } = await import(\"../utils/ipfs\");\n const cid = extractIpfsHash(url);\n\n if (!cid) {\n throw new Error(\n `Invalid IPFS URL format. Expected ipfs://... or a raw CID, got: ${url}`,\n );\n }\n\n const errors: Array<{ gateway: string; error: string }> = [];\n\n // Try each gateway in sequence\n for (let i = 0; i < gateways.length; i++) {\n const gateway = gateways[i];\n const isLastGateway = i === gateways.length - 1;\n const gatewayUrl = gateway.endsWith(\"/\")\n ? `${gateway}${cid}`\n : `${gateway}/${cid}`;\n\n try {\n console.debug(`Trying IPFS gateway: ${gatewayUrl}`);\n\n const response = await fetch(gatewayUrl);\n\n if (response.ok) {\n const blob = await response.blob();\n\n // Verify we got actual content\n if (blob.size > 0) {\n console.debug(`Successfully fetched from gateway: ${gateway}`);\n return blob;\n } else {\n // If this is the last gateway and we got an empty response, throw specific error\n if (isLastGateway) {\n throw new Error(\"Empty response\");\n }\n errors.push({\n gateway,\n error: \"Empty response\",\n });\n }\n } else {\n // Handle specific HTTP errors on last gateway attempt\n if (isLastGateway) {\n if (response.status === 403) {\n throw new Error(`HTTP error! status: 403 ${response.statusText}`);\n } else if (response.status === 404) {\n throw new Error(`HTTP error! status: 404 ${response.statusText}`);\n } else {\n throw new Error(\n `HTTP error! status: ${response.status} ${response.statusText}`,\n );\n }\n }\n errors.push({\n gateway,\n error: `HTTP ${response.status} ${response.statusText}`,\n });\n }\n } catch (error) {\n // Re-throw on last gateway if it's a specific error we want to preserve\n if (\n isLastGateway &&\n error instanceof Error &&\n (error.message.includes(\"Empty response\") ||\n error.message.includes(\"HTTP error!\"))\n ) {\n throw error;\n }\n errors.push({\n gateway,\n error: error instanceof Error ? error.message : \"Unknown error\",\n });\n }\n }\n\n // All gateways failed\n // Try download relayer as final fallback if configured\n if (this.context.downloadRelayer && gateways.length > 0) {\n try {\n // Try with the first gateway URL format\n const relayerUrl = gateways[0].endsWith(\"/\")\n ? `${gateways[0]}${cid}`\n : `${gateways[0]}/${cid}`;\n return await this.context.downloadRelayer.proxyDownload(relayerUrl);\n } catch (relayerError) {\n errors.push({\n gateway: \"download-relayer\",\n error: `Proxy failed: ${relayerError instanceof Error ? relayerError.message : \"Unknown error\"}`,\n });\n }\n }\n\n const errorDetails = errors\n .map((e) => `${e.gateway}: ${e.error}`)\n .join(\"\\n \");\n\n throw new Error(\n `Failed to fetch IPFS content ${cid} from all gateways:\\n ${errorDetails}`,\n );\n }\n\n /**\n * Validates a data schema definition against the Vana meta-schema.\n *\n * @param schema - The data schema definition to validate\n * @returns The validated DataSchema\n * @throws SchemaValidationError if invalid\n * @example\n * ```typescript\n * const schema = {\n * name: \"User Profile\",\n * version: \"1.0.0\",\n * dialect: \"json\",\n * schema: {\n * type: \"object\",\n * properties: {\n * name: { type: \"string\" },\n * age: { type: \"number\" }\n * }\n * }\n * };\n *\n * const validatedSchema = vana.data.validateDataSchemaAgainstMetaSchema(schema);\n * ```\n */\n validateDataSchemaAgainstMetaSchema(schema: unknown): DataSchema {\n return validateDataSchemaAgainstMetaSchema(schema);\n }\n\n /**\n * Validates data against a JSON Schema from a data schema.\n *\n * @param data - The data to validate\n * @param schema - The data schema containing the schema\n * @returns Void (throws if validation fails)\n * @throws SchemaValidationError if invalid\n * @example\n * ```typescript\n * const schema = {\n * name: \"User Profile\",\n * version: \"1.0.0\",\n * dialect: \"json\",\n * schema: {\n * type: \"object\",\n * properties: {\n * name: { type: \"string\" },\n * age: { type: \"number\" }\n * },\n * required: [\"name\"]\n * }\n * };\n *\n * const userData = { name: \"Alice\", age: 30 };\n * vana.data.validateDataAgainstSchema(userData, schema);\n * ```\n */\n validateDataAgainstSchema(data: unknown, schema: DataSchema): void {\n validateDataAgainstSchema(data, schema);\n }\n\n /**\n * Fetches and validates a data schema from a URL, then returns the parsed data schema.\n *\n * @param url - The URL to fetch the data schema from\n * @returns The validated data schema\n * @throws SchemaValidationError if invalid or fetch fails\n * @example\n * ```typescript\n * // Fetch and validate a schema from IPFS or HTTP\n * const schema = await vana.data.fetchAndValidateSchema(\"https://example.com/schema.json\");\n * console.log(schema.name, schema.dialect);\n *\n * // Use the schema to validate user data\n * if (schema.dialect === \"json\") {\n * vana.data.validateDataAgainstSchema(userData, schema);\n * }\n * ```\n */\n async fetchAndValidateSchema(url: string): Promise<DataSchema> {\n return fetchAndValidateSchema(url);\n }\n\n /**\n * Polls for confirmation of a relayer operation.\n * @internal\n */\n private async pollRelayerForConfirmation(\n operationId: string,\n options?: TransactionOptions,\n ): Promise<{ fileId: number; transactionHash: Hash }> {\n if (!this.context.relayer) {\n throw new Error(\"Relayer not configured for polling\");\n }\n\n const pollingManager = new PollingManager(this.context.relayer);\n\n const result = await pollingManager.startPolling(operationId, {\n signal: options?.signal,\n onStatusUpdate: options?.onStatusUpdate,\n ...options?.pollingOptions,\n });\n\n // For data operations, we need to extract the fileId from the transaction\n // This would typically come from parsing transaction logs\n // For now, we'll return a placeholder that would need proper implementation\n return {\n fileId: 0, // This would need to be extracted from transaction events\n transactionHash: result.hash,\n };\n }\n}\n"],"mappings":"AACA,SAAS,mBAAmB;AAgC5B,SAAS,sBAAsB;AAC/B,SAAS,sBAAsB;AAC/B,SAAS,0BAA0B;AACnC,SAAS,cAAc;AACvB,SAAS,iCAAiC;AAW1C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,aAAa;AAEtB;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,yBAAyB;AA8D3B,MAAM,uBAAuB,eAAe;AAAA,EACjD,YAAY,SAA4B;AACtC,UAAM,OAAO;AAAA,EACf;AAAA,EAgHA,MAAM,OAAO,QAA6C;AACxD,SAAK,aAAa;AAElB,UAAM;AAAA,MACJ;AAAA,MACA;AAAA,MACA;AAAA,MACA,cAAc,CAAC;AAAA,MACf,UAAU;AAAA,MACV;AAAA,MACA;AAAA,MACA,mBAAmB;AAAA,IACrB,IAAI;AAIJ,QACE,WACA,SACA,MAAM,YAAY,MAAM,KAAK,QAAQ,YAAY,YAAY,GAC7D;AACA,YAAM,IAAI;AAAA,QACR;AAAA,MAEF;AAAA,IACF;AAEA,QAAI;AACF,UAAI,UAAU;AACd,UAAI,mBAA6B,CAAC;AAGlC,UAAI,aAAa,UAAa,qBAAqB,QAAQ;AACzD,YAAI;AAEF,gBAAM,EAAE,iBAAiB,IAAI,MAAM,OAAO,WAAW;AACrD,gBAAM,mBAAmB,IAAI,iBAAiB,KAAK,OAAO;AAC1D,gBAAM,SAAS,MAAM,iBAAiB,IAAI,QAAQ;AAGlD,cAAI;AACJ,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C/D,WAAO,oCAAoC,MAAM;AAAA,EACnD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA6BA,0BAA0B,MAAe,QAA0B;AACjE,8BAA0B,MAAM,MAAM;AAAA,EACxC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAoBA,MAAM,uBAAuB,KAAkC;AAC7D,WAAO,uBAAuB,GAAG;AAAA,EACnC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAc,2BACZ,aACA,SACoD;AACpD,QAAI,CAAC,KAAK,QAAQ,SAAS;AACzB,YAAM,IAAI,MAAM,oCAAoC;AAAA,IACtD;AAEA,UAAM,iBAAiB,IAAI,eAAe,KAAK,QAAQ,OAAO;AAE9D,UAAM,SAAS,MAAM,eAAe,aAAa,aAAa;AAAA,MAC5D,QAAQ,SAAS;AAAA,MACjB,gBAAgB,SAAS;AAAA,MACzB,GAAG,SAAS;AAAA,IACd,CAAC;AAKD,WAAO;AAAA,MACL,QAAQ;AAAA;AAAA,MACR,iBAAiB,OAAO;AAAA,IAC1B;AAAA,EACF;AACF;","names":["endpoint"]}
1
+ {"version":3,"sources":["../../src/controllers/data.ts"],"sourcesContent":["import type { Address, Hash } from \"viem\";\nimport { getContract } from \"viem\";\nimport type {\n TransactionOptions,\n TransactionResult,\n} from \"../types/operations\";\n\nimport type { StorageUploadResult } from \"../types/storage\";\n\nimport type {\n UserFile,\n UploadParams,\n UploadResult,\n UploadEncryptedFileResult,\n Refiner,\n AddRefinerParams,\n AddRefinerResult,\n UpdateSchemaIdParams,\n UpdateSchemaIdResult,\n TrustedServer,\n GetUserTrustedServersParams,\n EncryptedUploadParams,\n UnencryptedUploadParams,\n EncryptFileOptions,\n EncryptFileResult,\n DecryptFileOptions,\n UploadFileWithPermissionsParams,\n AddFilePermissionParams,\n DecryptFileWithPermissionOptions,\n} from \"../types/index\";\n// import { FilePermissionResult } from \"../types/transactionResults\";\nimport type { UnifiedRelayerRequest } from \"../types/relayer\";\nimport type { ControllerContext } from \"./permissions\";\nimport { PollingManager } from \"../core/pollingManager\";\nimport { BaseController } from \"./base\";\nimport { getContractAddress } from \"../generated/addresses\";\nimport { getAbi } from \"../generated/abi\";\nimport { InvalidConfigurationError } from \"../errors\";\nimport type {\n GetUserFilesPaginatedQuery,\n GetFileProofsQuery,\n GetDlpQuery,\n GetUserPermissionsPaginatedQuery,\n GetUserTrustedServersPaginatedQuery,\n File_OrderBy as File_OrderByType,\n Permission_OrderBy as Permission_OrderByType,\n UserServer_OrderBy as UserServer_OrderByType,\n} from \"../generated/subgraph\";\nimport {\n GetUserFilesPaginatedDocument,\n GetFileProofsDocument,\n GetDlpDocument,\n GetUserPermissionsPaginatedDocument,\n GetUserTrustedServersPaginatedDocument,\n} from \"../generated/subgraph\";\nimport { print } from \"graphql\";\nimport type { ConsistencyOptions, PaginationOptions } from \"../types/options\";\nimport {\n checkSubgraphConsistency,\n fetchSubgraphMeta,\n} from \"../utils/subgraphConsistency\";\nimport {\n executePaginatedQuery,\n mapOrderByToEnum,\n mapOrderDirection,\n} from \"../utils/subgraphPagination\";\nimport {\n getUserFilesFromChain,\n determineDataSource,\n} from \"../utils/chainQuery\";\nimport {\n generateEncryptionKey,\n decryptBlobWithSignedKey,\n DEFAULT_ENCRYPTION_SEED,\n encryptBlobWithSignedKey,\n encryptWithWalletPublicKey,\n decryptWithWalletPrivateKey,\n} from \"../utils/encryption\";\nimport {\n validateDataSchemaAgainstMetaSchema,\n validateDataAgainstSchema,\n fetchAndValidateSchema,\n type DataSchema,\n} from \"../utils/schemaValidation\";\nimport { gasAwareMulticall } from \"../utils/multicall\";\n\n/**\n * Subgraph response wrapper type for error handling\n */\ntype SubgraphResponse<T> = {\n data?: T;\n errors?: Array<{ message: string }>;\n};\n\n/**\n * Manages encrypted user data files and blockchain registration on the Vana network.\n *\n * @remarks\n * The DataController provides comprehensive file lifecycle management from encrypted upload\n * through blockchain registration to decryption. Client-side encryption ensures data privacy\n * before transmission. The controller integrates with multiple storage providers (IPFS, Pinata,\n * Google Drive) and supports both gasless transactions via relayers and direct blockchain interaction.\n *\n * **Architecture:**\n * Files use dual storage: encrypted content on decentralized storage (IPFS/Pinata/Google Drive),\n * metadata and permissions on blockchain. This design minimizes on-chain data while maintaining\n * decentralization and access control.\n *\n * **Method Selection:**\n * - `upload()` - Complete workflow: encryption, storage, blockchain registration\n * - `getUserFiles()` - Query file metadata from blockchain/subgraph\n * - `decryptFile()` - Decrypt files you have permission to access\n * - `getFileById()` - Retrieve specific file metadata by ID\n *\n * **Storage Requirements:**\n * - Methods requiring storage: `upload()`, `encryptFile()`\n * - Methods working without storage: `getUserFiles()`, `decryptFile()`, `getFileById()`\n *\n * **Permission Model:**\n * - File permissions (decryption access) are handled during upload\n * - Operation permissions (what can be done with data) use `vana.permissions.grant()`\n *\n * @example\n * ```typescript\n * // Upload encrypted file with schema validation\n * const result = await vana.data.upload({\n * content: { name: \"Alice\", age: 30 },\n * filename: \"profile.json\",\n * schemaId: 1\n * });\n * console.log(`File uploaded: ID ${result.fileId}, URL ${result.url}`);\n *\n * // Query user's files\n * const files = await vana.data.getUserFiles({\n * owner: \"0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36\"\n * });\n * files.forEach(file => console.log(`File ${file.id}: ${file.url}`));\n *\n * // Decrypt accessible file\n * const decryptedData = await vana.data.decryptFile(files[0]);\n * console.log(\"Decrypted content:\", decryptedData);\n * ```\n *\n * @category Data Management\n * @see For conceptual overview, visit {@link https://docs.vana.org/docs/data-registry}\n */\nexport class DataController extends BaseController {\n constructor(context: ControllerContext) {\n super(context);\n }\n\n /**\n * Uploads data with automatic encryption and blockchain registration.\n *\n * @remarks\n * Primary method for uploading data to Vana. Handles complete workflow:\n * content normalization, schema validation, encryption, storage upload,\n * permission granting, and blockchain registration.\n *\n * **Automatic Processing:**\n * - Normalizes content to Blob format\n * - Validates against schema if provided\n * - Generates encryption keys\n * - Uploads to configured storage\n * - Grants decryption permissions\n * - Registers on blockchain\n *\n * **TypeScript Overloads:**\n * - `EncryptedUploadParams`: When `encrypt: true` (default), permissions require `publicKey`\n * - `UnencryptedUploadParams`: When `encrypt: false`, permissions optional\n * - `UploadParams`: General signature for runtime determination\n *\n * **Permission Separation:**\n * - File permissions (here): Decryption access only\n * - Operation permissions: Use `vana.permissions.grant()` separately\n *\n * **Owner/Encryption Constraint:**\n * When encryption is enabled (default), the `owner` parameter must match\n * the connected wallet address. This ensures only the wallet that performs\n * encryption can decrypt the file. For delegation scenarios where the owner\n * differs from the connected wallet, set `encrypt: false`.\n *\n * @param params - Upload configuration object\n * @param params.content - Data to upload (string, object, or Blob)\n * @param params.filename - Name for the uploaded file\n * @param params.permissions - Decryption access grants.\n * Each requires `account` and `publicKey` for encryption.\n * @param params.schemaId - Schema for validation.\n * Obtain via `vana.schemas.list()`.\n * @param params.owner - Owner address for blockchain registration.\n * Must match connected wallet when encryption is enabled.\n * For delegation scenarios, disable encryption with `encrypt: false`.\n * Defaults to connected wallet address.\n * @param params.encrypt - Enable encryption (default: `true`)\n * @param params.providerName - Storage provider override\n *\n * @returns Upload result with file ID, URL, and transaction hash\n *\n * @throws {InvalidConfigurationError} When encryption is enabled and owner differs from wallet.\n * Set `encrypt: false` for delegation scenarios, or omit `owner` to use connected wallet.\n * @throws {Error} Storage not configured.\n * Configure storage providers in `VanaConfig`.\n * @throws {Error} No wallet addresses available.\n * Ensure wallet is connected.\n * @throws {SchemaValidationError} Data doesn't match schema.\n * Verify data structure matches schema from `vana.schemas.get(schemaId)`.\n * @throws {Error} Upload failed with specific error message.\n *\n * @example\n * ```typescript\n * // Basic file upload\n * const result = await vana.data.upload({\n * content: \"My personal data\",\n * filename: \"diary.txt\"\n * });\n *\n * // Upload with schema validation\n * const result = await vana.data.upload({\n * content: { name: \"John\", age: 30 },\n * filename: \"profile.json\",\n * schemaId: 1\n * });\n *\n * // Upload with file permissions (for decryption access)\n * const result = await vana.data.upload({\n * content: \"Data for AI analysis\",\n * filename: \"analysis.txt\",\n * permissions: [{\n * account: \"0x1234...\", // Server address that can decrypt\n * publicKey: \"0x04...\" // Server's public key for encryption\n * }]\n * });\n *\n * // After upload, grant operation permissions separately:\n * // await vana.permissions.grant({\n * // grantee: \"0x1234...\",\n * // fileIds: [result.fileId],\n * // operation: \"llm_inference\",\n * // parameters: { model: \"gpt-4\" }\n * // });\n *\n * // Upload without encryption (public data)\n * // Note: Cast to UnencryptedUploadParams for TypeScript\n * const result = await vana.data.upload({\n * content: \"Public data\",\n * filename: \"public.txt\",\n * encrypt: false\n * } as const); // 'as const' ensures TypeScript infers encrypt: false literally\n *\n * // Upload on behalf of another user (delegation without encryption)\n * const result = await vana.data.upload({\n * content: \"User's data\",\n * filename: \"delegated.txt\",\n * owner: \"0x5678...\", // Different from connected wallet\n * encrypt: false // Required when owner differs from wallet\n * });\n * ```\n */\n async upload(params: EncryptedUploadParams): Promise<UploadResult>;\n async upload(params: UnencryptedUploadParams): Promise<UploadResult>;\n async upload(params: UploadParams): Promise<UploadResult>;\n async upload(params: UploadParams): Promise<UploadResult> {\n this.assertWallet();\n\n const {\n content,\n filename,\n schemaId,\n permissions = [],\n encrypt = true,\n providerName,\n owner,\n schemaValidation = \"strict\",\n } = params;\n\n // Validate that if encryption is enabled and owner is specified,\n // the owner must match the connected wallet address\n if (\n encrypt &&\n owner &&\n owner.toLowerCase() !== this.context.userAddress.toLowerCase()\n ) {\n throw new InvalidConfigurationError(\n \"The 'owner' parameter cannot be different from the connected wallet's address when encryption is enabled. \" +\n \"This would create an un-decryptable file.\",\n );\n }\n\n try {\n let isValid = true;\n let validationErrors: string[] = [];\n\n // Step 1: Schema validation if provided\n if (schemaId !== undefined && schemaValidation !== \"skip\") {\n try {\n // Use SchemaController to get complete schema with definition\n const { SchemaController } = await import(\"./schemas\");\n const schemaController = new SchemaController(this.context);\n const schema = await schemaController.get(schemaId);\n\n // Parse content for validation\n let parsedContent;\n if (typeof content === \"string\") {\n try {\n parsedContent = JSON.parse(content);\n } catch {\n parsedContent = content;\n }\n } else if (content instanceof Blob) {\n // For Blob content, read it as text for validation\n const text = await content.text();\n try {\n parsedContent = JSON.parse(text);\n } catch {\n parsedContent = text;\n }\n } else {\n parsedContent = content;\n }\n\n // Validate against schema (Schema is compatible with DataSchema)\n validateDataAgainstSchema(parsedContent, schema);\n } catch (error) {\n // Handle validation failure based on mode\n if (schemaValidation === \"strict\") {\n // Re-throw the error to maintain backward compatibility\n throw error;\n } else if (schemaValidation === \"warn\") {\n // Log warning and continue\n console.warn(\n '[Vana SDK] Schema validation failed, but continuing due to validation mode \"warn\"',\n );\n if (error instanceof Error) {\n console.warn(\" Validation error:\", error.message);\n // Check if it's a SchemaValidationError with details\n if (\n typeof error === \"object\" &&\n \"errors\" in error &&\n Array.isArray(error.errors)\n ) {\n console.warn(\" Detailed errors:\", error.errors);\n }\n }\n // Mark as invalid but don't block upload\n isValid = false;\n validationErrors =\n error instanceof Error\n ? [error.message]\n : [\"Schema validation failed\"];\n }\n }\n }\n\n // Step 2: Upload to storage using the centralized method\n const uploadResult = await this.uploadToStorage(\n content,\n filename,\n encrypt,\n providerName,\n );\n\n // Step 3: Register on blockchain\n const userAddress = owner ?? this.context.userAddress;\n\n // Prepare encrypted permissions if provided\n let encryptedPermissions: Array<{ account: Address; key: string }> = [];\n if (permissions.length > 0 && encrypt) {\n this.assertWallet();\n const userEncryptionKey = await generateEncryptionKey(\n this.context.walletClient,\n this.context.platform,\n DEFAULT_ENCRYPTION_SEED,\n );\n\n encryptedPermissions = await Promise.all(\n permissions.map(async (permission) => {\n const encryptedKey = await encryptWithWalletPublicKey(\n userEncryptionKey,\n permission.publicKey,\n this.context.platform,\n );\n\n return {\n account: permission.account,\n key: encryptedKey,\n };\n }),\n );\n }\n\n // Determine which registration method to use\n let result;\n\n // Use unified relayer callback if it exists\n if (this.context.relayer) {\n const request: UnifiedRelayerRequest = {\n type: \"direct\",\n operation: \"submitFileAdditionComplete\",\n params: {\n url: uploadResult.url,\n userAddress,\n permissions: encryptedPermissions,\n schemaId: schemaId ?? 0,\n ownerAddress: owner,\n },\n };\n const response = await this.context.relayer(request);\n if (response.type === \"error\") {\n throw new Error(response.error);\n }\n\n // Handle pending response (stateful relayer)\n if (response.type === \"pending\") {\n result = await this.pollRelayerForConfirmation(\n response.operationId,\n undefined, // TODO: Add TransactionOptions to upload method signature\n );\n } else if (\n response.type === \"direct\" &&\n typeof response.result === \"object\" &&\n response.result !== null &&\n \"fileId\" in response.result\n ) {\n result = response.result as { fileId: number; transactionHash: Hash };\n } else {\n throw new Error(\"Invalid response from relayer\");\n }\n\n // Fallback: No relay support, use a direct transaction\n } else {\n // Use the method directly since we already have encrypted permissions\n const txResult = await this.addFileWithEncryptedPermissionsAndSchema(\n uploadResult.url,\n userAddress,\n encryptedPermissions,\n schemaId ?? 0,\n );\n\n // Wait for transaction events to get the actual fileId\n if (!this.context.waitForTransactionEvents) {\n throw new Error(\n \"Cannot upload without relay: waitForTransactionEvents not configured\",\n );\n }\n\n const eventResult =\n await this.context.waitForTransactionEvents(txResult);\n const fileAddedEvent = eventResult.expectedEvents.FileAdded;\n if (!fileAddedEvent) {\n throw new Error(\"FileAdded event not found in transaction\");\n }\n\n result = {\n fileId: Number(fileAddedEvent.fileId),\n transactionHash: txResult.hash,\n };\n }\n\n return {\n fileId: result.fileId,\n url: uploadResult.url,\n transactionHash: result.transactionHash,\n size: uploadResult.size,\n isValid,\n validationErrors:\n validationErrors.length > 0 ? validationErrors : undefined,\n };\n } catch (error) {\n throw new Error(\n `Upload failed: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Encrypts data using wallet-derived encryption.\n *\n * @remarks\n * This method provides secure, wallet-based encryption for data before uploading\n * to the Vana network. It's the counterpart to decryptFile for preparing data\n * for secure storage.\n *\n * The method automatically:\n * - Generates an encryption key from the user's wallet signature\n * - Converts the input data to a Blob if necessary\n * - Encrypts the data using the generated key\n * - Returns both the encrypted data and the encryption key\n *\n * The encryption key returned can be stored and later used for decryption,\n * or shared with others to grant them decryption access.\n *\n * @param data - The data to encrypt (Blob, string, or object)\n * @param options - Optional encryption configuration\n * @returns Promise resolving to encrypted data and the encryption key used\n * @throws {Error} When wallet is not connected or encryption fails\n * @example\n * ```typescript\n * // Encrypt a string\n * const { encryptedData, encryptionKey } = await vana.data.encryptFile(\n * \"My secret data\"\n * );\n *\n * // Encrypt JSON with custom MIME type\n * const { encryptedData, encryptionKey } = await vana.data.encryptFile(\n * { name: \"Alice\", age: 30 },\n * { mimeType: \"application/json\" }\n * );\n *\n * // With custom encryption seed\n * const { encryptedData, encryptionKey } = await vana.data.encryptFile(\n * \"Secret message\",\n * { seed: \"My custom encryption seed\" }\n * );\n *\n * // Upload the encrypted data\n * const result = await vana.data.uploadToStorage(encryptedData);\n * ```\n */\n async encryptFile(\n data: Blob | string | object,\n options?: EncryptFileOptions,\n ): Promise<EncryptFileResult> {\n this.assertWallet();\n\n try {\n // Generate encryption key from wallet\n const encryptionKey = await generateEncryptionKey(\n this.context.walletClient,\n this.context.platform,\n options?.seed ?? DEFAULT_ENCRYPTION_SEED,\n );\n\n // Convert data to Blob if necessary\n let blob: Blob;\n if (data instanceof Blob) {\n blob = data;\n } else if (typeof data === \"string\") {\n blob = new Blob([data], { type: options?.mimeType ?? \"text/plain\" });\n } else {\n // Handle objects by JSON stringifying them\n blob = new Blob([JSON.stringify(data)], {\n type: options?.mimeType ?? \"application/json\",\n });\n }\n\n // Encrypt the blob\n const encryptedData = await encryptBlobWithSignedKey(\n blob,\n encryptionKey,\n this.context.platform,\n );\n\n return {\n encryptedData,\n encryptionKey,\n };\n } catch (error) {\n throw new Error(\n `Failed to encrypt file: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Decrypts a file using wallet-derived decryption key.\n *\n * @remarks\n * Counterpart to `upload()` for decrypting user files. Automatically\n * generates decryption key from wallet, fetches encrypted content,\n * and decrypts. Supports IPFS (with gateway fallback) and HTTP URLs.\n *\n * @param file - UserFile object from `getUserFiles()`\n * @param options - Decryption options\n * @param options.seed - Custom encryption seed.\n * Defaults to standard Vana seed.\n *\n * @returns Decrypted content as Blob\n *\n * @throws {Error} No wallet connected.\n * Connect wallet before decrypting.\n * @throws {Error} Network error accessing file.\n * Check CORS settings or server availability.\n * @throws {Error} File not found (404).\n * File no longer available at stored URL.\n * @throws {Error} Access denied (403).\n * No permission to access file.\n * @throws {Error} Invalid file format.\n * File not encrypted with Vana protocol.\n * @throws {Error} Wrong encryption key.\n * Verify seed matches upload or use default.\n *\n * @example\n * ```typescript\n * // Basic file decryption\n * const files = await vana.data.getUserFiles({ owner: userAddress });\n * const decryptedBlob = await vana.data.decryptFile(files[0]);\n *\n * // Convert to text\n * const text = await decryptedBlob.text();\n * console.log('Decrypted content:', text);\n *\n * // Convert to JSON\n * const json = JSON.parse(await decryptedBlob.text());\n * console.log('Decrypted data:', json);\n *\n * // With custom encryption seed\n * const decryptedBlob = await vana.data.decryptFile(\n * files[0],\n * \"My custom encryption seed\"\n * );\n *\n * // Save to file (in Node.js)\n * const buffer = await decryptedBlob.arrayBuffer();\n * fs.writeFileSync('decrypted-file.txt', Buffer.from(buffer));\n * ```\n */\n async decryptFile(\n file: UserFile,\n options?: DecryptFileOptions,\n ): Promise<Blob> {\n this.assertWallet();\n\n try {\n this.assertWallet();\n // Step 1: Generate the decryption key from wallet signature\n const encryptionKey = await generateEncryptionKey(\n this.context.walletClient,\n this.context.platform,\n options?.seed ?? DEFAULT_ENCRYPTION_SEED,\n );\n\n // Step 2: Determine the protocol and fetch the encrypted content\n let encryptedBlob: Blob;\n\n try {\n if (file.url.startsWith(\"ipfs://\")) {\n // Use IPFS fetcher with gateway fallback for reliability\n encryptedBlob = await this.fetchFromIPFS(file.url);\n } else {\n // Use standard fetch for HTTP/HTTPS URLs\n encryptedBlob = await this.fetch(file.url);\n }\n } catch (fetchError) {\n // Handle network errors\n const errorMessage =\n fetchError instanceof Error ? fetchError.message : \"Unknown error\";\n\n // Check for specific error types\n if (\n errorMessage.includes(\"Failed to fetch IPFS content\") &&\n errorMessage.includes(\"from all gateways\")\n ) {\n // IPFS gateway failures - treat as network error\n throw new Error(\n \"Network error: Cannot access the file URL. The file may be stored on a server that's not accessible or has CORS restrictions.\",\n );\n } else if (errorMessage.includes(\"Empty response\")) {\n throw new Error(\"File is empty or could not be retrieved\");\n } else if (\n errorMessage.includes(\"Network error:\") ||\n errorMessage.includes(\"Failed to fetch\")\n ) {\n throw new Error(\n \"Network error: Cannot access the file URL. The file may be stored on a server that's not accessible or has CORS restrictions.\",\n );\n } else if (errorMessage.includes(\"HTTP error!\")) {\n const statusMatch = errorMessage.match(/status: (\\d+)/);\n const status = statusMatch ? statusMatch[1] : \"unknown\";\n\n if (status === \"500\") {\n throw new Error(\n \"Network error: Cannot access the file URL. The file may be stored on a server that's not accessible or has CORS restrictions.\",\n );\n } else if (status === \"403\") {\n throw new Error(\n \"Access denied. You may not have permission to access this file\",\n );\n } else if (status === \"404\") {\n throw new Error(\n \"File not found: The encrypted file is no longer available at the stored URL.\",\n );\n } else {\n throw new Error(\n \"Network error: Cannot access the file URL. The file may be stored on a server that's not accessible or has CORS restrictions.\",\n );\n }\n }\n\n // Re-throw other errors\n throw fetchError;\n }\n\n // Check if blob is empty\n if (encryptedBlob.size === 0) {\n throw new Error(\"File is empty or could not be retrieved\");\n }\n\n // Step 3: Decrypt the blob using the low-level primitive\n let decryptedBlob: Blob;\n try {\n decryptedBlob = await decryptBlobWithSignedKey(\n encryptedBlob,\n encryptionKey,\n this.context.platform,\n );\n } catch (decryptError) {\n const errorMessage =\n decryptError instanceof Error\n ? decryptError.message\n : \"Unknown error\";\n\n // Map decryption errors to user-friendly messages\n if (errorMessage.includes(\"not a valid OpenPGP message\")) {\n throw new Error(\n \"Invalid file format: This file doesn't appear to be encrypted with the Vana protocol\",\n );\n } else if (errorMessage.includes(\"Session key decryption failed\")) {\n throw new Error(\"Wrong encryption key\");\n } else if (errorMessage.includes(\"Error decrypting message\")) {\n throw new Error(\"Wrong encryption key\");\n } else if (errorMessage.includes(\"File not found\")) {\n throw new Error(\n \"File not found: The encrypted file is no longer available\",\n );\n } else {\n // Re-throw the original error for other cases\n throw decryptError;\n }\n }\n\n return decryptedBlob;\n } catch (error) {\n // If it's already one of our formatted errors, re-throw it\n if (\n error instanceof Error &&\n (error.message.includes(\"Network error:\") ||\n error.message.includes(\"Invalid file format:\") ||\n error.message.includes(\"Wrong encryption key\") ||\n error.message.includes(\"Access denied\") ||\n error.message.includes(\"File not found:\") ||\n error.message.includes(\"File is empty\"))\n ) {\n throw error;\n }\n\n // Otherwise, wrap it\n throw new Error(\n `Failed to decrypt file: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Retrieves all files owned by a specific user address.\n *\n * @remarks\n * Queries the Vana subgraph for files owned by the specified address.\n * Automatically deduplicates by file ID, keeping the latest version\n * when duplicates exist from re-indexing or chain reorganizations.\n * Enriches results with DLP proof data when available.\n *\n * @param params - Query configuration\n * @param params.owner - Wallet address of the file owner\n * @param params.subgraphUrl - Subgraph endpoint override.\n * Defaults to context configuration.\n *\n * @returns Array of UserFile objects sorted by timestamp (newest first)\n *\n * @throws {Error} Subgraph URL not configured.\n * Provide `subgraphUrl` parameter or configure in Vana constructor.\n * @throws {Error} Subgraph request failed.\n * Check network connectivity and subgraph availability.\n * @throws {Error} Subgraph returned errors.\n * Review query parameters and subgraph logs.\n *\n * @example\n * ```typescript\n * const files = await vana.data.getUserFiles({\n * owner: \"0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36\"\n * });\n *\n * files.forEach(file => {\n * console.log(`File ${file.id}: ${file.url}`);\n * console.log(` Schema: ${file.schemaId}`);\n * console.log(` DLPs: ${file.dlpIds?.join(\", \") || \"none\"}`);\n * });\n * ```\n */\n async getUserFiles(\n params: {\n owner: Address;\n subgraphUrl?: string;\n },\n options?: ConsistencyOptions & PaginationOptions,\n ): Promise<UserFile[]> {\n const { owner, subgraphUrl } = params;\n\n // Determine data source based on options\n let dataSource: \"subgraph\" | \"chain\" =\n options?.source === \"chain\" ? \"chain\" : \"subgraph\";\n\n // If auto mode, determine based on staleness\n if (options?.source === \"auto\" || (!options?.source && options?.minBlock)) {\n const endpoint = subgraphUrl ?? this.context.subgraphUrl;\n\n // Get current chain block\n const currentBlock = await this.context.publicClient.getBlockNumber();\n\n // Get subgraph block if using subgraph\n let subgraphBlock: number | undefined;\n if (endpoint) {\n try {\n const meta = await fetchSubgraphMeta(endpoint);\n subgraphBlock = meta.blockNumber;\n } catch {\n // If subgraph is unavailable, fall back to chain\n subgraphBlock = undefined;\n }\n }\n\n dataSource = determineDataSource(\n options?.source,\n options?.minBlock,\n currentBlock,\n subgraphBlock,\n );\n }\n\n // Use chain query if selected\n if (dataSource === \"chain\") {\n const publicClient = this.context.publicClient;\n const chainId = await publicClient.getChainId();\n const contractAddress = getContractAddress(chainId, \"DataRegistry\");\n\n // Query directly from chain\n const files = await getUserFilesFromChain(\n publicClient,\n contractAddress,\n owner,\n options?.minBlock ? BigInt(options.minBlock) : undefined,\n );\n\n // Apply pagination if needed (chain query returns all, so we paginate in memory)\n const limit = options?.fetchAll ? files.length : (options?.limit ?? 100);\n const offset = options?.offset ?? 0;\n\n return files.slice(offset, offset + limit);\n }\n\n // Use subgraph query (existing logic)\n const endpoint = subgraphUrl ?? this.context.subgraphUrl;\n\n if (!endpoint) {\n throw new Error(\n \"subgraphUrl is required. Please provide a valid subgraph endpoint or configure it in Vana constructor.\",\n );\n }\n\n // Check consistency requirements before querying\n if (options?.minBlock || options?.waitForSync) {\n await checkSubgraphConsistency(endpoint, options);\n }\n\n try {\n // Map orderBy string to GraphQL enum values (string literals)\n const orderByMap: Record<string, File_OrderByType> = {\n id: \"id\",\n addedAtBlock: \"addedAtBlock\",\n addedAtTimestamp: \"addedAtTimestamp\",\n url: \"url\",\n schemaId: \"schemaId\",\n };\n\n // Define the raw file type from the GraphQL response\n type RawFile = NonNullable<\n GetUserFilesPaginatedQuery[\"user\"]\n >[\"files\"][0];\n\n // Use the generic pagination utility\n const allFiles = await executePaginatedQuery<\n GetUserFilesPaginatedQuery,\n UserFile,\n RawFile\n >({\n endpoint,\n document: GetUserFilesPaginatedDocument,\n baseVariables: {\n userId: owner.toLowerCase(), // Subgraph requires lowercase addresses\n orderBy: mapOrderByToEnum(\n options?.orderBy,\n orderByMap,\n \"addedAtBlock\",\n ),\n orderDirection: mapOrderDirection(\n options?.orderDirection,\n \"asc\",\n \"desc\",\n ),\n },\n options,\n extractItems: (data) => data?.user?.files,\n transformItem: (file) => ({\n id: parseInt(file.id),\n url: file.url,\n ownerAddress: file.owner.id as Address,\n addedAtBlock: BigInt(file.addedAtBlock),\n schemaId: parseInt(file.schemaId),\n addedAtTimestamp: BigInt(file.addedAtTimestamp),\n transactionHash: file.transactionHash as Hash,\n }),\n });\n\n // Fetch proofs for all files to get DLP associations\n if (allFiles.length > 0) {\n try {\n const fileIds = allFiles.map((f) => f.id);\n let proofMap: Map<number, number[]>;\n\n try {\n // Try subgraph first\n proofMap = await this._fetchProofsFromSubgraph(fileIds, endpoint);\n } catch (subgraphError) {\n console.debug(\n \"Failed to fetch proofs from subgraph, trying chain:\",\n subgraphError,\n );\n // Fall back to chain\n proofMap = await this._fetchProofsFromChain(fileIds);\n }\n\n // Add dlpIds to each file\n for (const file of allFiles) {\n const dlpIds = proofMap.get(file.id);\n if (dlpIds && dlpIds.length > 0) {\n file.dlpIds = dlpIds;\n }\n }\n } catch (error) {\n // Log but don't fail - files are still useful without proof data\n console.warn(\"Failed to fetch proof data for files:\", error);\n }\n }\n\n // Successfully retrieved user files (already paginated and sorted by GraphQL)\n return allFiles;\n } catch (error) {\n console.error(\"Failed to fetch user files from subgraph:\", error);\n throw new Error(\n `Failed to fetch user files from subgraph: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Fetches proof data for multiple files from the subgraph.\n *\n * @private\n * @param fileIds - Array of file IDs to fetch proofs for\n * @param subgraphUrl - The subgraph endpoint URL\n * @returns Map of file IDs to their associated DLP IDs\n */\n private async _fetchProofsFromSubgraph(\n fileIds: number[],\n subgraphUrl: string,\n ): Promise<Map<number, number[]>> {\n const response = await fetch(subgraphUrl, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify({\n query: print(GetFileProofsDocument),\n variables: {\n fileIds: fileIds.map((id) => id.toString()),\n },\n }),\n });\n\n if (!response.ok) {\n throw new Error(\n `Subgraph request failed: ${response.status} ${response.statusText}`,\n );\n }\n\n const result =\n (await response.json()) as SubgraphResponse<GetFileProofsQuery>;\n\n if (result.errors) {\n throw new Error(\n `Subgraph errors: ${result.errors.map((e) => e.message).join(\", \")}`,\n );\n }\n\n // Build map of fileId -> dlpIds\n const proofMap = new Map<number, number[]>();\n\n if (result.data?.dataRegistryProofs) {\n for (const proof of result.data.dataRegistryProofs) {\n if (proof.dlp?.id) {\n const fileId = parseInt(proof.fileId);\n const dlpId = parseInt(proof.dlp.id);\n\n let dlpIds = proofMap.get(fileId);\n if (!dlpIds) {\n dlpIds = [];\n proofMap.set(fileId, dlpIds);\n }\n\n if (!dlpIds.includes(dlpId)) {\n dlpIds.push(dlpId);\n }\n }\n }\n }\n\n return proofMap;\n }\n\n /**\n * Fetches proof data for multiple files from the blockchain.\n * Falls back to this when subgraph is unavailable.\n *\n * @private\n * @param fileIds - Array of file IDs to fetch proofs for\n * @returns Map of file IDs to their associated DLP IDs\n */\n private async _fetchProofsFromChain(\n fileIds: number[],\n ): Promise<Map<number, number[]>> {\n const chainId = this.context.publicClient.chain?.id;\n if (!chainId) {\n throw new Error(\"Chain ID not available\");\n }\n\n const dataRegistryAddress = getContractAddress(chainId, \"DataRegistry\");\n const dataRegistryAbi = getAbi(\"DataRegistry\");\n\n const proofMap = new Map<number, number[]>();\n\n // For each file, fetch proofs by incrementing index until revert\n for (const fileId of fileIds) {\n const dlpIds: number[] = [];\n let proofIndex = 0;\n let hasMoreProofs = true;\n\n while (hasMoreProofs) {\n try {\n const proof = (await this.context.publicClient.readContract({\n address: dataRegistryAddress,\n abi: dataRegistryAbi,\n functionName: \"fileProofs\",\n args: [BigInt(fileId), BigInt(proofIndex)],\n })) as {\n signature: `0x${string}`;\n data: {\n score: bigint;\n dlpId: bigint;\n metadata: string;\n proofUrl: string;\n instruction: string;\n };\n };\n\n if (proof?.data?.dlpId) {\n const dlpId = Number(proof.data.dlpId);\n if (!dlpIds.includes(dlpId)) {\n dlpIds.push(dlpId);\n }\n }\n\n proofIndex++;\n } catch {\n // No more proofs for this file\n hasMoreProofs = false;\n }\n }\n\n if (dlpIds.length > 0) {\n proofMap.set(fileId, dlpIds);\n }\n }\n\n return proofMap;\n }\n\n /**\n * Retrieves information about a specific Data Liquidity Pool (DLP).\n *\n * @remarks\n * DLPs are entities that process and verify data files in the Vana network.\n * This method fetches DLP metadata including name, status, and performance rating.\n * Uses subgraph first for efficiency, falls back to chain if unavailable.\n *\n * @param dlpId - The unique identifier of the DLP\n * @param options - Optional parameters\n * @param options.subgraphUrl - Custom subgraph URL to override default\n * @returns Promise resolving to DLP information\n * @throws {Error} When DLP cannot be found - \"DLP not found: {dlpId}\"\n * @throws {Error} When query fails - \"Failed to fetch DLP: {error}\"\n * @example\n * ```typescript\n * const dlp = await vana.data.getDLP(26);\n * console.log(`DLP ${dlp.name}: ${dlp.status}`);\n * ```\n */\n async getDLP(\n dlpId: number,\n options: {\n subgraphUrl?: string;\n minBlock?: number;\n waitForSync?: number;\n } = {},\n ): Promise<{\n id: number;\n name: string;\n metadata?: string;\n status?: number;\n address?: Address;\n owner?: Address;\n }> {\n const subgraphUrl = options.subgraphUrl ?? this.context.subgraphUrl;\n\n // Check consistency requirements if using subgraph\n if (subgraphUrl && (options.minBlock || options.waitForSync)) {\n await checkSubgraphConsistency(subgraphUrl, options);\n }\n\n // Try subgraph first if available\n if (subgraphUrl) {\n try {\n const response = await fetch(subgraphUrl, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify({\n query: print(GetDlpDocument),\n variables: {\n id: dlpId.toString(),\n },\n }),\n });\n\n if (!response.ok) {\n throw new Error(\n `Subgraph request failed: ${response.status} ${response.statusText}`,\n );\n }\n\n const result = (await response.json()) as SubgraphResponse<GetDlpQuery>;\n\n if (result.errors) {\n throw new Error(\n `Subgraph errors: ${result.errors.map((e) => e.message).join(\", \")}`,\n );\n }\n\n if (!result.data?.dlp) {\n throw new Error(`DLP not found: ${dlpId}`);\n }\n\n return {\n id: parseInt(result.data.dlp.id),\n name: result.data.dlp.name ?? \"\",\n metadata: result.data.dlp.metadata ?? undefined,\n status: result.data.dlp.status\n ? parseInt(result.data.dlp.status)\n : undefined,\n address: result.data.dlp.address\n ? (result.data.dlp.address as Address)\n : undefined,\n owner: result.data.dlp.owner\n ? (result.data.dlp.owner as Address)\n : undefined,\n };\n } catch (error) {\n console.debug(\"Subgraph query failed, falling back to chain:\", error);\n // Fall through to chain query\n }\n }\n\n // Chain fallback - read from DLP Registry contract\n try {\n const chainId = this.context.publicClient.chain?.id;\n if (!chainId) {\n throw new Error(\"Chain ID not available\");\n }\n\n const dlpRegistryAddress = getContractAddress(chainId, \"DLPRegistry\");\n const dlpRegistryAbi = getAbi(\"DLPRegistry\");\n\n const dlpData = (await this.context.publicClient.readContract({\n address: dlpRegistryAddress,\n abi: dlpRegistryAbi,\n functionName: \"dlps\",\n args: [BigInt(dlpId)],\n })) as {\n id: bigint;\n dlpAddress: Address;\n ownerAddress: Address;\n tokenAddress: Address;\n treasuryAddress: Address;\n name: string;\n iconUrl: string;\n website: string;\n metadata: string;\n registrationBlockNumber: bigint;\n depositAmount: bigint;\n status: number;\n lpTokenId: bigint;\n verificationBlockNumber: bigint;\n };\n\n if (!dlpData?.name) {\n throw new Error(`DLP not found: ${dlpId}`);\n }\n\n return {\n id: dlpId,\n name: dlpData.name,\n metadata: dlpData.metadata,\n status: dlpData.status,\n address: dlpData.dlpAddress,\n owner: dlpData.ownerAddress,\n };\n } catch (error) {\n throw new Error(\n `Failed to fetch DLP: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Lists all Data Liquidity Pools (DLPs) with optional pagination.\n *\n * @remarks\n * Fetches a paginated list of all DLPs registered in the network.\n * Uses subgraph for efficient querying with fallback to chain multicall.\n *\n * @param options - Optional parameters for pagination and filtering\n * @param options.limit - Maximum number of DLPs to return (default: 100)\n * @param options.offset - Number of DLPs to skip (default: 0)\n * @param options.subgraphUrl - Custom subgraph URL to override default\n * @returns Promise resolving to array of DLP information\n * @throws {Error} When query fails - \"Failed to list DLPs: {error}\"\n * @example\n * ```typescript\n * // Get first 10 DLPs\n * const dlps = await vana.data.listDLPs({ limit: 10 });\n * dlps.forEach(dlp => console.log(`${dlp.id}: ${dlp.name}`));\n *\n * // Get next page\n * const nextPage = await vana.data.listDLPs({ limit: 10, offset: 10 });\n * ```\n */\n async listDLPs(\n options: {\n limit?: number;\n offset?: number;\n subgraphUrl?: string;\n } = {},\n ): Promise<\n Array<{\n id: number;\n name: string;\n metadata?: string;\n status?: number;\n address?: Address;\n owner?: Address;\n }>\n > {\n const { limit = 100, offset = 0 } = options;\n const subgraphUrl = options.subgraphUrl ?? this.context.subgraphUrl;\n\n // Try subgraph first if available\n if (subgraphUrl) {\n try {\n const query = `\n query ListDLPs($first: Int!, $skip: Int!) {\n dlps(first: $first, skip: $skip, orderBy: id) {\n id\n name\n metadata\n status\n address\n owner\n }\n }\n `;\n\n const response = await fetch(subgraphUrl, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify({\n query,\n variables: {\n first: limit,\n skip: offset,\n },\n }),\n });\n\n if (!response.ok) {\n throw new Error(\n `Subgraph request failed: ${response.status} ${response.statusText}`,\n );\n }\n\n const result = (await response.json()) as {\n data?: {\n dlps?: Array<{\n id: string;\n name?: string;\n metadata?: string;\n status?: string;\n address?: string;\n owner?: string;\n }>;\n };\n errors?: Array<{ message: string }>;\n };\n\n if (result.errors) {\n throw new Error(\n `Subgraph errors: ${result.errors.map((e) => e.message).join(\", \")}`,\n );\n }\n\n const dlps = result.data?.dlps ?? [];\n\n return dlps.map((dlp) => ({\n id: parseInt(dlp.id),\n name: dlp.name ?? \"\",\n metadata: dlp.metadata,\n status: dlp.status ? parseInt(dlp.status) : undefined,\n address: dlp.address ? (dlp.address as Address) : undefined,\n owner: dlp.owner ? (dlp.owner as Address) : undefined,\n }));\n } catch (error) {\n console.debug(\"Subgraph query failed, falling back to chain:\", error);\n // Fall through to chain query\n }\n }\n\n // Chain fallback - use multicall to batch read DLPs\n try {\n const chainId = this.context.publicClient.chain?.id;\n if (!chainId) {\n throw new Error(\"Chain ID not available\");\n }\n\n const dlpRegistryAddress = getContractAddress(chainId, \"DLPRegistry\");\n const dlpRegistryAbi = getAbi(\"DLPRegistry\");\n\n // First get the total count\n const dlpCount = await this.context.publicClient.readContract({\n address: dlpRegistryAddress,\n abi: dlpRegistryAbi,\n functionName: \"dlpsCount\",\n args: [],\n });\n\n const totalCount = Number(dlpCount);\n const start = offset;\n const end = Math.min(start + limit, totalCount);\n\n if (end <= start) {\n return [];\n }\n\n // Build multicall for fetching DLP data\n const calls = [];\n for (let i = start + 1; i <= end; i++) {\n // DLP IDs typically start at 1\n calls.push({\n address: dlpRegistryAddress,\n abi: dlpRegistryAbi,\n functionName: \"dlps\",\n args: [BigInt(i)],\n } as const);\n }\n\n const results = await gasAwareMulticall<\n typeof calls,\n true // Allow failures\n >(this.context.publicClient, {\n contracts: calls,\n allowFailure: true,\n batchSize: 50,\n });\n\n const dlps = [];\n for (let i = 0; i < results.length; i++) {\n const result = results[i];\n if (result.status === \"success\" && result.result) {\n const dlpData = result.result as {\n id: bigint;\n dlpAddress: Address;\n ownerAddress: Address;\n tokenAddress: Address;\n treasuryAddress: Address;\n name: string;\n iconUrl: string;\n website: string;\n metadata: string;\n registrationBlockNumber: bigint;\n depositAmount: bigint;\n status: number;\n lpTokenId: bigint;\n verificationBlockNumber: bigint;\n };\n\n if (dlpData.name) {\n // Only include valid DLPs\n dlps.push({\n id: start + i + 1,\n name: dlpData.name,\n metadata: dlpData.metadata,\n status: dlpData.status,\n address: dlpData.dlpAddress,\n owner: dlpData.ownerAddress,\n });\n }\n }\n }\n\n return dlps;\n } catch (error) {\n throw new Error(\n `Failed to list DLPs: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Retrieves a list of permissions granted by a user.\n *\n * This method supports automatic fallback between subgraph and RPC modes:\n * - If subgraph URL is available, tries subgraph query first\n * - Falls back to direct contract queries via RPC if subgraph fails\n * - RPC mode uses gasAwareMulticall for efficient batch queries\n *\n * @param params - Object containing the user address and optional subgraph URL\n * @param params.user - The wallet address of the user to query permissions for\n * @param params.subgraphUrl - Optional subgraph URL to override the default\n * @returns Promise resolving to an array of permission objects\n * @throws Error if both subgraph and RPC queries fail\n */\n async getUserPermissions(\n params: {\n user: Address;\n subgraphUrl?: string;\n },\n options?: ConsistencyOptions & PaginationOptions,\n ): Promise<\n Array<{\n id: string;\n grant: string;\n nonce: bigint;\n signature: string;\n addedAtBlock: bigint;\n addedAtTimestamp: bigint;\n transactionHash: Address;\n user: Address;\n }>\n > {\n const { user, subgraphUrl } = params;\n const endpoint = subgraphUrl ?? this.context.subgraphUrl;\n\n // Check consistency requirements if using subgraph\n if (endpoint && (options?.minBlock || options?.waitForSync)) {\n await checkSubgraphConsistency(endpoint, options);\n }\n\n // Try subgraph first if available\n if (endpoint) {\n try {\n const permissions = await this._getUserPermissionsViaSubgraph(\n {\n user,\n subgraphUrl: endpoint,\n },\n options,\n );\n\n return permissions;\n } catch (error) {\n console.warn(\"Subgraph query failed, falling back to RPC:\", error);\n // Fall through to RPC\n }\n }\n\n // Use RPC (as fallback or primary method)\n // Note: RPC doesn't support pagination, so we get all and slice\n const allPermissions = await this._getUserPermissionsViaRpc({ user });\n\n // Apply pagination to RPC results if needed\n if (options && !options.fetchAll) {\n const limit = options.limit ?? 100;\n const offset = options.offset ?? 0;\n return allPermissions.slice(offset, offset + limit);\n }\n\n return allPermissions;\n }\n\n /**\n * Internal method: Query user permissions via subgraph\n *\n * @param params - Query parameters object\n * @param params.user - The user address to query permissions for\n * @param params.subgraphUrl - The subgraph URL endpoint to query\n * @returns Promise resolving to an array of permission objects\n */\n private async _getUserPermissionsViaSubgraph(\n params: {\n user: Address;\n subgraphUrl: string;\n },\n options?: PaginationOptions,\n ): Promise<\n Array<{\n id: string;\n grant: string;\n nonce: bigint;\n signature: string;\n addedAtBlock: bigint;\n addedAtTimestamp: bigint;\n transactionHash: Address;\n user: Address;\n }>\n > {\n const { user, subgraphUrl } = params;\n\n try {\n // Map orderBy string to GraphQL enum values\n const orderByMap: Record<string, Permission_OrderByType> = {\n id: \"id\",\n addedAtBlock: \"addedAtBlock\",\n addedAtTimestamp: \"addedAtTimestamp\",\n grant: \"grant\",\n nonce: \"nonce\",\n startBlock: \"startBlock\",\n endBlock: \"endBlock\",\n };\n\n // Define the raw permission type from the GraphQL response\n type RawPermission = NonNullable<\n GetUserPermissionsPaginatedQuery[\"user\"]\n >[\"permissions\"][0];\n\n // Use the generic pagination utility\n const permissions = await executePaginatedQuery<\n GetUserPermissionsPaginatedQuery,\n {\n id: string;\n grant: string;\n nonce: bigint;\n signature: string;\n addedAtBlock: bigint;\n addedAtTimestamp: bigint;\n transactionHash: Address;\n user: Address;\n },\n RawPermission\n >({\n endpoint: subgraphUrl,\n document: GetUserPermissionsPaginatedDocument,\n baseVariables: {\n userId: user.toLowerCase(),\n orderBy: mapOrderByToEnum(\n options?.orderBy,\n orderByMap,\n \"addedAtTimestamp\",\n ),\n orderDirection: mapOrderDirection(\n options?.orderDirection,\n \"desc\",\n \"asc\",\n ),\n },\n options,\n extractItems: (data) => data?.user?.permissions,\n transformItem: (permission) => ({\n id: permission.id,\n grant: permission.grant,\n nonce: BigInt(permission.nonce),\n signature: permission.signature,\n addedAtBlock: BigInt(permission.addedAtBlock),\n addedAtTimestamp: BigInt(permission.addedAtTimestamp),\n transactionHash: permission.transactionHash as Hash,\n user,\n }),\n });\n\n return permissions;\n } catch (error) {\n console.error(\"Failed to query user permissions from subgraph:\", error);\n throw error;\n }\n }\n\n /**\n * Internal method: Query user permissions via direct RPC\n *\n * @param params - Query parameters object\n * @param params.user - The user address to query permissions for\n * @returns Promise resolving to an array of permission objects\n */\n private async _getUserPermissionsViaRpc(params: { user: Address }): Promise<\n Array<{\n id: string;\n grant: string;\n nonce: bigint;\n signature: string;\n addedAtBlock: bigint;\n addedAtTimestamp: bigint;\n transactionHash: Address;\n user: Address;\n }>\n > {\n const { user } = params;\n\n try {\n const chainId = this.context.publicClient.chain?.id;\n if (!chainId) {\n throw new Error(\"Chain ID not available\");\n }\n\n const permissionsAddress = getContractAddress(\n chainId,\n \"DataPortabilityPermissions\",\n );\n const permissionsAbi = getAbi(\"DataPortabilityPermissions\");\n\n // Get total count of user permission IDs\n const totalCount = await this.context.publicClient.readContract({\n address: permissionsAddress,\n abi: permissionsAbi,\n functionName: \"userPermissionIdsLength\",\n args: [user],\n });\n\n const total = Number(totalCount);\n\n if (total === 0) {\n return [];\n }\n\n // Fetch permission IDs using gasAwareMulticall\n const permissionIdCalls = [];\n for (let i = 0; i < total; i++) {\n permissionIdCalls.push({\n address: permissionsAddress,\n abi: permissionsAbi,\n functionName: \"userPermissionIdsAt\",\n args: [user, BigInt(i)],\n });\n }\n\n const permissionIdResults = await gasAwareMulticall<\n typeof permissionIdCalls,\n false\n >(this.context.publicClient, {\n contracts: permissionIdCalls,\n });\n\n // Extract permission IDs from results\n const permissionIds = permissionIdResults\n .map((result) => result as bigint)\n .filter((id) => id && id > 0n);\n\n // Build permission info calls for multicall\n const permissionInfoCalls = permissionIds.map(\n (permissionId) =>\n ({\n address: permissionsAddress,\n abi: permissionsAbi,\n functionName: \"permissions\",\n args: [permissionId],\n }) as const,\n );\n\n // Fetch all permission info in a single multicall\n const permissionInfoResults = await gasAwareMulticall<\n typeof permissionInfoCalls,\n true // Allow failures for individual permission lookups\n >(this.context.publicClient, {\n contracts: permissionInfoCalls,\n allowFailure: true,\n });\n\n // Process results\n const permissions = permissionInfoResults\n .map((result, index) => {\n const permissionId = permissionIds[index];\n\n if (result.status === \"success\" && result.result) {\n const permissionInfo = result.result as {\n id: bigint;\n grantor: Address;\n nonce: bigint;\n granteeId: bigint;\n grant: string;\n startBlock: bigint;\n endBlock: bigint;\n fileIds: bigint[];\n };\n\n return {\n id: permissionId.toString(),\n grant: permissionInfo.grant,\n nonce: permissionInfo.nonce,\n signature: \"\", // Not available from RPC, will be empty\n addedAtBlock: permissionInfo.startBlock,\n addedAtTimestamp: BigInt(0), // Not available from RPC\n transactionHash:\n \"0x0000000000000000000000000000000000000000\" as `0x${string}`, // Not available from RPC\n user,\n };\n } else {\n // If permission info fails, return basic info\n return {\n id: permissionId.toString(),\n grant: \"\",\n nonce: BigInt(0),\n signature: \"\",\n addedAtBlock: BigInt(0),\n addedAtTimestamp: BigInt(0),\n transactionHash:\n \"0x0000000000000000000000000000000000000000\" as `0x${string}`,\n user,\n };\n }\n })\n .filter((permission) => permission.grant !== \"\"); // Remove failed lookups\n\n return permissions;\n } catch (error) {\n throw new Error(\n `RPC query failed: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Retrieves a list of trusted servers for a user.\n *\n * This method supports automatic fallback between subgraph and RPC modes:\n * - If subgraph URL is available, tries subgraph query first for fast results\n * - Falls back to direct contract queries via RPC if subgraph fails\n * - RPC mode uses gasAwareMulticall for efficient batch queries\n *\n * @param params - Query parameters including user address and optional pagination\n * @param params.user - The wallet address of the user to query trusted servers for\n * @param params.subgraphUrl - Optional subgraph URL to override the default\n * @param params.limit - Maximum number of results to return (default: 50)\n * @param params.offset - Number of results to skip for pagination (default: 0)\n * @returns Promise resolving to an array of trusted server objects\n * @throws Error if both subgraph and RPC queries fail\n * @example\n * ```typescript\n * // Basic usage with automatic fallback\n * const servers = await vana.data.getUserTrustedServers({\n * user: '0x...'\n * });\n *\n * // With pagination\n * const servers = await vana.data.getUserTrustedServers({\n * user: '0x...',\n * limit: 10,\n * offset: 20\n * });\n *\n * // With custom subgraph URL\n * const servers = await vana.data.getUserTrustedServers({\n * user: '0x...',\n * subgraphUrl: 'https://custom-subgraph.com/graphql'\n * });\n * ```\n */\n async getUserTrustedServers(\n params: GetUserTrustedServersParams,\n options?: ConsistencyOptions & PaginationOptions,\n ): Promise<TrustedServer[]> {\n const { user } = params;\n const subgraphUrl = params.subgraphUrl ?? this.context.subgraphUrl;\n\n // Check consistency requirements if using subgraph\n if (subgraphUrl && (options?.minBlock || options?.waitForSync)) {\n await checkSubgraphConsistency(subgraphUrl, options);\n }\n\n // Try subgraph first if available\n if (subgraphUrl) {\n try {\n const servers = await this._getUserTrustedServersViaSubgraph(\n {\n user,\n subgraphUrl,\n },\n options,\n );\n\n return servers;\n } catch (error) {\n console.warn(\"Subgraph query failed, falling back to RPC:\", error);\n // Fall through to RPC\n }\n }\n\n // Use RPC (as fallback or primary method)\n // Note: RPC doesn't support consistency options, so we just paginate\n const limit = options?.fetchAll\n ? Number.MAX_SAFE_INTEGER\n : (options?.limit ?? 100);\n const offset = options?.offset ?? 0;\n\n const rpcResult = await this._getUserTrustedServersViaRpc({\n user,\n limit,\n offset,\n });\n\n return rpcResult.servers;\n }\n\n /**\n * Internal method: Query trusted servers via subgraph\n *\n * @param params - Query parameters object\n * @param params.user - The user address to query trusted servers for\n * @param params.subgraphUrl - The subgraph URL endpoint to query\n * @returns Promise resolving to an array of trusted server objects\n */\n private async _getUserTrustedServersViaSubgraph(\n params: {\n user: Address;\n subgraphUrl?: string;\n },\n options?: PaginationOptions,\n ): Promise<TrustedServer[]> {\n const { user, subgraphUrl } = params;\n\n const graphqlEndpoint = subgraphUrl;\n if (!graphqlEndpoint) {\n throw new Error(\n \"subgraphUrl is required for subgraph mode. Please provide a valid subgraph endpoint or configure it in Vana constructor.\",\n );\n }\n\n try {\n // Map orderBy string to GraphQL enum values\n const orderByMap: Record<string, UserServer_OrderByType> = {\n id: \"id\",\n trustedAt: \"trustedAt\",\n trustedAtBlock: \"trustedAtBlock\",\n server: \"server\",\n user: \"user\",\n };\n\n // Define the raw server trust type from the GraphQL response\n type RawServerTrust = NonNullable<\n GetUserTrustedServersPaginatedQuery[\"user\"]\n >[\"serverTrusts\"][0];\n\n // Use the generic pagination utility\n const serverTrusts = await executePaginatedQuery<\n GetUserTrustedServersPaginatedQuery,\n TrustedServer,\n RawServerTrust\n >({\n endpoint: graphqlEndpoint,\n document: GetUserTrustedServersPaginatedDocument,\n baseVariables: {\n userId: user.toLowerCase(), // Subgraph requires lowercase addresses\n orderBy: mapOrderByToEnum(\n options?.orderBy,\n orderByMap,\n \"trustedAtBlock\",\n ),\n orderDirection: mapOrderDirection(\n options?.orderDirection,\n \"desc\",\n \"asc\",\n ),\n },\n options,\n extractItems: (data) => {\n // Filter out untrusted servers at extraction time\n const trusts = data?.user?.serverTrusts ?? [];\n return trusts.filter((trust) => !trust.untrustedAtBlock);\n },\n transformItem: (trust) => ({\n id: trust.server.id,\n serverAddress: trust.server.serverAddress as Address,\n serverUrl: trust.server.url,\n trustedAt: BigInt(trust.trustedAt),\n user,\n name: \"\", // Not available in new schema, will be empty\n }),\n });\n\n return serverTrusts;\n } catch (error) {\n console.error(\"Failed to query trusted servers from subgraph:\", error);\n throw error;\n }\n }\n\n /**\n * Internal method: Query trusted servers via direct RPC\n *\n * @param params - Query parameters object\n * @param params.user - The user address to query trusted servers for\n * @param params.limit - Maximum number of results to return\n * @param params.offset - Number of results to skip for pagination\n * @returns Promise resolving to pagination result with servers, total count, and hasMore flag\n */\n private async _getUserTrustedServersViaRpc(params: {\n user: Address;\n limit: number;\n offset: number;\n }): Promise<{\n servers: TrustedServer[];\n total: number;\n hasMore: boolean;\n }> {\n const { user, limit, offset } = params;\n\n try {\n const chainId = this.context.publicClient.chain?.id;\n if (!chainId) {\n throw new Error(\"Chain ID not available\");\n }\n\n const DataPortabilityServersAddress = getContractAddress(\n chainId,\n \"DataPortabilityServers\",\n );\n const DataPortabilityServersAbi = getAbi(\"DataPortabilityServers\");\n\n // Get total count first\n const totalCount = await this.context.publicClient.readContract({\n address: DataPortabilityServersAddress,\n abi: DataPortabilityServersAbi,\n functionName: \"userServerIdsLength\",\n args: [user],\n });\n\n const total = Number(totalCount);\n\n if (total === 0 || offset >= total) {\n return {\n servers: [],\n total,\n hasMore: false,\n };\n }\n\n // Calculate pagination\n const endIndex = Math.min(offset + limit, total);\n\n // Fetch server IDs using gasAwareMulticall\n const serverIdCalls = [];\n for (let i = offset; i < endIndex; i++) {\n serverIdCalls.push({\n address: DataPortabilityServersAddress,\n abi: DataPortabilityServersAbi,\n functionName: \"userServerIdsAt\",\n args: [user, BigInt(i)],\n });\n }\n\n const serverIdResults = await gasAwareMulticall<\n typeof serverIdCalls,\n false\n >(this.context.publicClient, {\n contracts: serverIdCalls,\n });\n\n // Extract server IDs from results\n const serverIds = serverIdResults\n .map((result) => result as bigint)\n .filter((id) => id && id > 0n);\n\n // Build server info calls for multicall\n const serverInfoCalls = serverIds.map(\n (serverId) =>\n ({\n address: DataPortabilityServersAddress,\n abi: DataPortabilityServersAbi,\n functionName: \"servers\",\n args: [serverId],\n }) as const,\n );\n\n // Fetch all server info in a single multicall\n const serverInfoResults = await gasAwareMulticall<\n typeof serverInfoCalls,\n true // Allow failures for individual server lookups\n >(this.context.publicClient, {\n contracts: serverInfoCalls,\n allowFailure: true,\n });\n\n // Process results\n const servers = serverInfoResults.map((result, index) => {\n const serverId = serverIds[index];\n\n if (result.status === \"success\" && result.result) {\n const serverInfo = result.result as {\n id: bigint;\n owner: Address;\n serverAddress: Address;\n publicKey: string;\n url: string;\n };\n\n return {\n id: `${user.toLowerCase()}-${serverId.toString()}`,\n serverAddress: serverInfo.serverAddress,\n serverUrl: serverInfo.url,\n trustedAt: BigInt(Date.now()),\n user,\n trustIndex: offset + index,\n };\n } else {\n // If server info fails, return basic info\n return {\n id: `${user.toLowerCase()}-${serverId.toString()}`,\n serverAddress:\n \"0x0000000000000000000000000000000000000000\" as Address,\n serverUrl: \"\",\n trustedAt: BigInt(Date.now()),\n user,\n trustIndex: offset + index,\n };\n }\n });\n\n return {\n servers,\n total,\n hasMore: offset + limit < total,\n };\n } catch (error) {\n throw new Error(\n `RPC query failed: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Retrieves total file count from Data Registry.\n *\n * @remarks\n * Queries blockchain for complete file count across all users.\n * Useful for pagination and network statistics.\n *\n * @returns Total number of registered files\n *\n * @throws {Error} Chain ID not available.\n * Ensure network connection.\n * @throws {Error} Contract read failed.\n * Check RPC availability.\n *\n * @example\n * ```typescript\n * const total = await vana.data.getTotalFilesCount();\n * console.log(`Total files: ${total}`);\n *\n * // Calculate pagination\n * const pages = Math.ceil(total / 20);\n * ```\n */\n async getTotalFilesCount(): Promise<number> {\n try {\n const chainId = this.context.publicClient.chain?.id;\n if (!chainId) {\n throw new Error(\"Chain ID not available\");\n }\n\n const dataRegistryAddress = getContractAddress(chainId, \"DataRegistry\");\n const dataRegistryAbi = getAbi(\"DataRegistry\");\n\n const dataRegistry = getContract({\n address: dataRegistryAddress,\n abi: dataRegistryAbi,\n client: this.context.publicClient,\n });\n\n const count = await dataRegistry.read.filesCount();\n return Number(count);\n } catch (error) {\n // Re-throw validation errors (like missing chain ID)\n if (\n error instanceof Error &&\n error.message === \"Chain ID not available\"\n ) {\n throw error;\n }\n\n // Return 0 for contract errors\n console.error(\"Failed to fetch total files count:\", error);\n return 0;\n }\n }\n\n /**\n * Retrieves file metadata by ID from the blockchain.\n *\n * @remarks\n * Queries DataRegistry contract directly for file details.\n * Works for any file ID regardless of ownership, enabling\n * cross-user file discovery and verification.\n *\n * @param fileId - Numeric file ID to retrieve\n *\n * @returns UserFile object with metadata\n *\n * @throws {Error} Chain ID not available.\n * Ensure proper network connection.\n * @throws {Error} File not found.\n * Verify file ID exists on-chain.\n * @throws {Error} Contract call failed.\n * Check network and RPC availability.\n *\n * @example\n * ```typescript\n * const file = await vana.data.getFileById(123);\n * console.log(`File ${file.id}:`);\n * console.log(` URL: ${file.url}`);\n * console.log(` Owner: ${file.ownerAddress}`);\n * console.log(` Block: ${file.addedAtBlock}`);\n * ```\n */\n async getFileById(fileId: number): Promise<UserFile> {\n try {\n const chainId = this.context.publicClient.chain?.id;\n if (!chainId) {\n throw new Error(\"Chain ID not available\");\n }\n\n const dataRegistryAddress = getContractAddress(chainId, \"DataRegistry\");\n const dataRegistryAbi = getAbi(\"DataRegistry\");\n\n const dataRegistry = getContract({\n address: dataRegistryAddress,\n abi: dataRegistryAbi,\n client: this.context.publicClient,\n });\n\n const fileDetails = await dataRegistry.read.files([BigInt(fileId)]);\n\n if (!fileDetails) {\n throw new Error(\"File not found\");\n }\n\n // Handle both array format (from contracts) and object format\n if (Array.isArray(fileDetails)) {\n const [id, url, ownerAddress, addedAtBlock] =\n fileDetails as unknown as [bigint, string, Address, bigint];\n if (id === BigInt(0)) {\n throw new Error(\"File not found\");\n }\n return {\n id: Number(id),\n url,\n ownerAddress,\n addedAtBlock: BigInt(addedAtBlock),\n };\n } else {\n // Object format\n if (!fileDetails.id || fileDetails.id === BigInt(0)) {\n throw new Error(\"File not found\");\n }\n return {\n id: Number(fileDetails.id),\n ownerAddress: fileDetails.ownerAddress,\n url: fileDetails.url,\n addedAtBlock: BigInt(fileDetails.addedAtBlock),\n };\n }\n } catch (error) {\n console.error(\"Failed to fetch file by ID:\", error);\n throw new Error(\n `Failed to fetch file ${fileId}: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Registers a file URL directly on the blockchain with a schema ID.\n *\n * @remarks\n * This method registers an existing file URL on the DataRegistry contract\n * with a schema ID, without uploading any data. Useful when you have already\n * uploaded content to storage and just need to register it on-chain.\n *\n * @param url - The URL of the file to register (IPFS or HTTP/HTTPS)\n * @param schemaId - The schema ID to associate with the file\n * @returns Promise resolving to the file ID and transaction hash\n * @throws {Error} When chain ID is not available - \"Chain ID not available\"\n * @throws {Error} When wallet address is unavailable - \"No addresses available\"\n * @throws {Error} When transaction fails - \"Failed to register file with schema\"\n * @example\n * ```typescript\n * const { fileId, transactionHash } = await vana.data.registerFileWithSchema(\n * \"ipfs://QmXxx...\",\n * 1\n * );\n * console.log(`File ${fileId} registered with schema in tx ${transactionHash}`);\n * ```\n */\n async registerFileWithSchema(\n url: string,\n schemaId: number,\n options?: TransactionOptions,\n ): Promise<TransactionResult<\"DataRegistry\", \"addFileWithSchema\">> {\n this.assertWallet();\n\n try {\n const chainId = this.context.publicClient.chain?.id;\n if (!chainId) {\n throw new Error(\"Chain ID not available\");\n }\n\n this.assertWallet();\n const dataRegistryAddress = getContractAddress(chainId, \"DataRegistry\");\n const dataRegistryAbi = getAbi(\"DataRegistry\");\n const account =\n this.context.walletClient.account ?? this.context.userAddress;\n const from = typeof account === \"string\" ? account : account.address;\n\n const hash = await this.context.walletClient.writeContract({\n address: dataRegistryAddress,\n abi: dataRegistryAbi,\n functionName: \"addFileWithSchema\",\n args: [url, BigInt(schemaId)],\n account,\n chain: this.context.walletClient.chain ?? null,\n ...this.spreadTransactionOptions(options),\n });\n\n const { tx } = await import(\"../utils/transactionHelpers\");\n return tx({\n hash,\n from,\n contract: \"DataRegistry\",\n fn: \"addFileWithSchema\",\n });\n } catch (error) {\n console.error(\"Failed to register file with schema:\", error);\n throw new Error(\n `Registration failed: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Gets the user's address from the wallet client.\n *\n * @returns Promise resolving to the user's wallet address\n * @throws {Error} When no addresses are available in wallet client\n */\n\n /**\n * Adds a file with permissions to the DataRegistry contract.\n *\n * @param url - The file URL to register\n * @param ownerAddress - The address of the file owner\n * @param permissions - Array of permissions to set for the file\n * @returns Promise resolving to file ID and transaction hash\n * @throws {Error} When chain ID is not available\n * @throws {ContractError} When contract execution fails\n * @throws {Error} When transaction receipt is not available\n * @throws {Error} When FileAdded event cannot be parsed\n *\n * This method handles the core logic of registering a file\n * with specific permissions on the DataRegistry contract. It can be used\n * by both direct transactions and relayer services.\n */\n async addFileWithPermissions(\n url: string,\n ownerAddress: Address,\n permissions: Array<{ account: Address; key: string }> = [],\n options?: TransactionOptions,\n ): Promise<TransactionResult<\"DataRegistry\", \"addFileWithPermissions\">> {\n this.assertWallet();\n\n try {\n const chainId = this.context.publicClient.chain?.id;\n if (!chainId) {\n throw new Error(\"Chain ID not available\");\n }\n\n this.assertWallet();\n const dataRegistryAddress = getContractAddress(chainId, \"DataRegistry\");\n const dataRegistryAbi = getAbi(\"DataRegistry\");\n const account = this.context.walletClient.account ?? ownerAddress;\n const from = typeof account === \"string\" ? account : account.address;\n\n // Execute the transaction using the wallet client\n const hash = await this.context.walletClient.writeContract({\n address: dataRegistryAddress,\n abi: dataRegistryAbi,\n functionName: \"addFileWithPermissions\",\n args: [url, ownerAddress, permissions],\n account,\n chain: this.context.walletClient.chain ?? null,\n ...this.spreadTransactionOptions(options),\n });\n\n const { tx } = await import(\"../utils/transactionHelpers\");\n return tx({\n hash,\n from,\n contract: \"DataRegistry\",\n fn: \"addFileWithPermissions\",\n });\n } catch (error) {\n console.error(\"Failed to add file with permissions:\", error);\n throw new Error(\n `Failed to add file with permissions: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Adds a file to the registry with permissions and schema.\n * This combines the functionality of addFileWithPermissions and schema validation.\n *\n * @remarks\n * This method automatically encrypts permissions when a publicKey is provided.\n * It generates the user's encryption key and encrypts it with each recipient's\n * public key before registering on the blockchain.\n *\n * @param url - The URL of the file to register\n * @param ownerAddress - The address of the file owner\n * @param permissions - Array of permissions to grant, each with account and publicKey properties\n * @param schemaId - The schema ID to associate with the file (0 for no schema)\n * @returns Promise resolving to TransactionResult with fileId and transactionHash\n * @throws {Error} \"Chain ID not available\" - When wallet chain is not configured\n * @throws {Error} \"Failed to generate encryption key\" - When encryption key generation fails\n * @throws {Error} \"Permission for {account} must include 'publicKey'\" - When publicKey is missing\n * @throws {Error} \"Failed to add file with permissions and schema: {error}\" - When transaction fails\n * @example\n * ```typescript\n * // Get server's public key\n * const serverIdentity = await vana.server.getIdentity({\n * userAddress: \"0x...\"\n * });\n *\n * // Add file with permissions and schema\n * const result = await vana.data.addFileWithPermissionsAndSchema(\n * \"ipfs://QmXxx...\",\n * ownerAddress,\n * [{\n * account: serverIdentity.address,\n * publicKey: serverIdentity.publicKey\n * }],\n * schemaId\n * );\n *\n * console.log(`File ${result.fileId} registered in tx ${result.hash}`);\n * ```\n */\n async addFileWithPermissionsAndSchema(\n url: string,\n ownerAddress: Address,\n permissions: Array<{ account: Address; publicKey: string }> = [],\n schemaId: number = 0,\n options?: TransactionOptions,\n ): Promise<\n TransactionResult<\"DataRegistry\", \"addFileWithPermissionsAndSchema\">\n > {\n this.assertWallet();\n\n try {\n // Process permissions - always encrypt with publicKey\n let encryptedPermissions: Array<{ account: Address; key: string }> = [];\n\n if (permissions.length > 0) {\n this.assertWallet();\n // Generate user's encryption key\n const userEncryptionKey = await generateEncryptionKey(\n this.context.walletClient,\n this.context.platform,\n DEFAULT_ENCRYPTION_SEED,\n );\n\n encryptedPermissions = await Promise.all(\n permissions.map(async (permission) => {\n if (!permission.publicKey) {\n throw new Error(\n `Permission for ${permission.account} must include 'publicKey'`,\n );\n }\n\n const encryptedKey = await encryptWithWalletPublicKey(\n userEncryptionKey,\n permission.publicKey,\n this.context.platform,\n );\n\n return {\n account: permission.account,\n key: encryptedKey,\n };\n }),\n );\n }\n\n // Call the method with encrypted permissions\n return await this.addFileWithEncryptedPermissionsAndSchema(\n url,\n ownerAddress,\n encryptedPermissions,\n schemaId,\n options,\n );\n } catch (error) {\n console.error(\"Failed to add file with permissions and schema:\", error);\n throw new Error(\n `Failed to add file with permissions and schema: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Adds a file with pre-encrypted permissions and schema to the DataRegistry.\n *\n * @remarks\n * This method is designed for relay services and advanced use cases where permissions\n * have already been encrypted client-side. Unlike `addFileWithPermissionsAndSchema()`,\n * this method expects permissions in the encrypted format with a 'key' field instead\n * of 'publicKey'.\n *\n * This is typically used by relay endpoints that receive pre-encrypted data from\n * the client SDK's `upload()` method, avoiding double encryption.\n *\n * @param url - The storage URL of the file (e.g., IPFS URL)\n * @param ownerAddress - The address that will own this file\n * @param permissions - Array of pre-encrypted permissions with 'account' and 'key' fields\n * @param schemaId - Optional schema ID for data validation (defaults to 0)\n * @returns Promise resolving to transaction result with hash and contract details\n * @throws {Error} When chain ID is not available\n * @throws {Error} When wallet is not connected\n * @throws {Error} When transaction fails\n * @example\n * ```typescript\n * // In a relay endpoint that receives pre-encrypted permissions\n * const result = await vana.data.addFileWithEncryptedPermissionsAndSchema(\n * \"ipfs://QmXxx...\",\n * ownerAddress,\n * [\n * {\n * account: \"0xServerAddress...\",\n * key: \"encrypted_key_string\" // Already encrypted by client\n * }\n * ],\n * schemaId\n * );\n *\n * console.log(`File registered in tx ${result.hash}`);\n * ```\n */\n async addFileWithEncryptedPermissionsAndSchema(\n url: string,\n ownerAddress: Address,\n permissions: Array<{ account: Address; key: string }> = [],\n schemaId: number = 0,\n options?: TransactionOptions,\n ): Promise<\n TransactionResult<\"DataRegistry\", \"addFileWithPermissionsAndSchema\">\n > {\n try {\n const chainId = this.context.publicClient.chain?.id;\n if (!chainId) {\n throw new Error(\"Chain ID not available\");\n }\n\n this.assertWallet();\n const dataRegistryAddress = getContractAddress(chainId, \"DataRegistry\");\n const dataRegistryAbi = getAbi(\"DataRegistry\");\n const account = this.context.walletClient.account ?? ownerAddress;\n const from = typeof account === \"string\" ? account : account.address;\n\n // Execute the transaction using the wallet client\n const hash = await this.context.walletClient.writeContract({\n address: dataRegistryAddress,\n abi: dataRegistryAbi,\n functionName: \"addFileWithPermissionsAndSchema\",\n args: [url, ownerAddress, permissions, BigInt(schemaId)],\n account,\n chain: this.context.walletClient.chain ?? null,\n ...this.spreadTransactionOptions(options),\n });\n\n const { tx } = await import(\"../utils/transactionHelpers\");\n return tx({\n hash,\n from,\n contract: \"DataRegistry\",\n fn: \"addFileWithPermissionsAndSchema\",\n });\n } catch (error) {\n console.error(\"Failed to add file with permissions and schema:\", error);\n throw new Error(\n `Failed to add file with permissions and schema: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Registers a data refiner for processing templates.\n *\n * @remarks\n * Refiners define data transformation rules for DLPs.\n * Associates schema, instructions, and processing logic.\n *\n * @param params - Refiner configuration\n * @param params.dlpId - Data Liquidity Pool ID\n * @param params.name - Refiner display name\n * @param params.schemaId - Output schema ID.\n * Obtain via `vana.schemas.list()`.\n * @param params.refinementInstructionUrl - Processing instructions URL\n *\n * @returns Refiner ID and transaction hash\n *\n * @throws {Error} Chain ID not available.\n * Ensure network connection.\n * @throws {Error} Transaction failed.\n * Check wallet balance and network status.\n *\n * @example\n * ```typescript\n * const result = await vana.data.addRefiner({\n * dlpId: 1,\n * name: \"Sentiment Analyzer\",\n * schemaId: 42,\n * refinementInstructionUrl: \"ipfs://QmXxx...\"\n * });\n * console.log(`Refiner ${result.refinerId} created`);\n * ```\n */\n async addRefiner(\n params: AddRefinerParams,\n options?: TransactionOptions,\n ): Promise<AddRefinerResult> {\n this.assertWallet();\n\n try {\n const chainId = this.context.publicClient.chain?.id;\n if (!chainId) {\n throw new Error(\"Chain ID not available\");\n }\n\n const dataRefinerRegistryAddress = getContractAddress(\n chainId,\n \"DataRefinerRegistry\",\n );\n const dataRefinerRegistryAbi = getAbi(\"DataRefinerRegistry\");\n this.assertWallet();\n const account =\n this.context.walletClient.account ?? this.context.userAddress;\n const from = typeof account === \"string\" ? account : account.address;\n\n const hash = await this.context.walletClient.writeContract({\n address: dataRefinerRegistryAddress,\n abi: dataRefinerRegistryAbi,\n functionName: \"addRefinerWithSchemaId\",\n args: [\n BigInt(params.dlpId),\n params.name,\n BigInt(params.schemaId),\n params.refinementInstructionUrl,\n ],\n account,\n chain: this.context.walletClient.chain ?? null,\n ...this.spreadTransactionOptions(options),\n });\n\n // Create TransactionResult POJO\n const { tx } = await import(\"../utils/transactionHelpers\");\n const txResult = tx({\n hash,\n from,\n contract: \"DataRefinerRegistry\",\n fn: \"addRefinerWithSchemaId\",\n });\n\n // Wait for events and extract domain data\n if (!this.context.waitForTransactionEvents) {\n throw new Error(\"waitForTransactionEvents not configured\");\n }\n\n const result = await this.context.waitForTransactionEvents(txResult);\n const event = result.expectedEvents.RefinerAdded;\n if (!event) {\n throw new Error(\"RefinerAdded event not found in transaction\");\n }\n\n return {\n refinerId: Number(event.refinerId),\n transactionHash: hash,\n };\n } catch (error) {\n console.error(\"Failed to add refiner:\", error);\n throw new Error(\n `Failed to add refiner: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Retrieves refiner configuration by ID.\n *\n * @remarks\n * Queries DataRefinerRegistry for refiner details.\n * Returns DLP association, schema, and processing instructions.\n *\n * @param refinerId - Numeric refiner ID\n *\n * @returns Refiner configuration object\n *\n * @throws {Error} Chain ID not available.\n * Ensure network connection.\n * @throws {Error} Refiner not found.\n * Verify refiner ID exists.\n * @throws {Error} Contract read failed.\n * Check network and RPC status.\n *\n * @example\n * ```typescript\n * const refiner = await vana.data.getRefiner(1);\n * console.log(`Refiner: ${refiner.name}`);\n * console.log(`DLP: ${refiner.dlpId}`);\n * console.log(`Schema: ${refiner.schemaId}`);\n * ```\n */\n async getRefiner(refinerId: number): Promise<Refiner> {\n try {\n const chainId = this.context.publicClient.chain?.id;\n if (!chainId) {\n throw new Error(\"Chain ID not available\");\n }\n\n const dataRefinerRegistryAddress = getContractAddress(\n chainId,\n \"DataRefinerRegistry\",\n );\n const dataRefinerRegistryAbi = getAbi(\"DataRefinerRegistry\");\n\n const dataRefinerRegistry = getContract({\n address: dataRefinerRegistryAddress,\n abi: dataRefinerRegistryAbi,\n client: this.context.publicClient,\n });\n\n const refinerData = await dataRefinerRegistry.read.refiners([\n BigInt(refinerId),\n ]);\n\n if (!refinerData) {\n throw new Error(\"Refiner not found\");\n }\n\n return {\n id: refinerId,\n dlpId: Number(refinerData.dlpId),\n owner: refinerData.owner,\n name: refinerData.name,\n schemaId: Number(refinerData.schemaId),\n refinementInstructionUrl: refinerData.refinementInstructionUrl,\n };\n } catch (error) {\n console.error(\"Failed to get refiner:\", error);\n throw new Error(\n `Failed to get refiner ${refinerId}: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Validates schema ID existence.\n *\n * @remarks\n * Verifies schema registration in DataRegistry.\n * Check before using schemas for uploads.\n *\n * @param schemaId - Numeric schema ID to validate\n *\n * @returns True if schema exists, false otherwise\n *\n * @throws {Error} Chain ID not available.\n * Ensure network connection.\n * @throws {Error} Contract read failed.\n * Check RPC availability.\n *\n * @example\n * ```typescript\n * const valid = await vana.data.isValidSchemaId(42);\n * if (valid) {\n * // Safe to use schema 42\n * await vana.data.upload({ schemaId: 42, ... });\n * }\n * ```\n */\n async isValidSchemaId(schemaId: number): Promise<boolean> {\n try {\n const chainId = this.context.publicClient.chain?.id;\n if (!chainId) {\n throw new Error(\"Chain ID not available\");\n }\n\n const dataRefinerRegistryAddress = getContractAddress(\n chainId,\n \"DataRefinerRegistry\",\n );\n const dataRefinerRegistryAbi = getAbi(\"DataRefinerRegistry\");\n\n const dataRefinerRegistry = getContract({\n address: dataRefinerRegistryAddress,\n abi: dataRefinerRegistryAbi,\n client: this.context.publicClient,\n });\n\n const isValid = await dataRefinerRegistry.read.isValidSchemaId([\n BigInt(schemaId),\n ]);\n return isValid;\n } catch (error) {\n console.error(\"Failed to validate schema ID:\", error);\n return false;\n }\n }\n\n /**\n * Gets the total number of refiners in the registry.\n *\n * @remarks\n * Queries the DataRefinerRegistry contract to get the total count of all\n * registered refiners across all DLPs.\n *\n * @returns Promise resolving to the total refiner count\n * @example\n * ```typescript\n * const count = await vana.data.getRefinersCount();\n * console.log(`Total refiners registered: ${count}`);\n * ```\n */\n async getRefinersCount(): Promise<number> {\n try {\n const chainId = this.context.publicClient.chain?.id;\n if (!chainId) {\n throw new Error(\"Chain ID not available\");\n }\n\n const dataRefinerRegistryAddress = getContractAddress(\n chainId,\n \"DataRefinerRegistry\",\n );\n const dataRefinerRegistryAbi = getAbi(\"DataRefinerRegistry\");\n\n const dataRefinerRegistry = getContract({\n address: dataRefinerRegistryAddress,\n abi: dataRefinerRegistryAbi,\n client: this.context.publicClient,\n });\n\n const count = await dataRefinerRegistry.read.refinersCount();\n return Number(count);\n } catch (error) {\n console.error(\"Failed to get refiners count:\", error);\n return 0;\n }\n }\n\n /**\n * Updates the schema ID for an existing refiner.\n *\n * @remarks\n * Allows the owner of a refiner to update its associated schema ID.\n * This is useful when refiner output format needs to change.\n *\n * @param params - Update parameters\n * @param params.refinerId - The refiner ID to update\n * @param params.newSchemaId - The new schema ID to set\n * @returns Promise resolving to the transaction hash\n * @throws {Error} When chain ID is not available - \"Chain ID not available\"\n * @throws {Error} When transaction fails - \"Failed to update schema ID: {error}\"\n * @example\n * ```typescript\n * const result = await vana.data.updateSchemaId({\n * refinerId: 1,\n * newSchemaId: 55\n * });\n * console.log(`Schema updated in tx ${result.transactionHash}`);\n * ```\n */\n async updateSchemaId(\n params: UpdateSchemaIdParams,\n options?: TransactionOptions,\n ): Promise<UpdateSchemaIdResult> {\n this.assertWallet();\n\n try {\n const chainId = this.context.publicClient.chain?.id;\n if (!chainId) {\n throw new Error(\"Chain ID not available\");\n }\n\n const dataRefinerRegistryAddress = getContractAddress(\n chainId,\n \"DataRefinerRegistry\",\n );\n const dataRefinerRegistryAbi = getAbi(\"DataRefinerRegistry\");\n this.assertWallet();\n const account =\n this.context.walletClient.account ?? this.context.userAddress;\n\n const hash = await this.context.walletClient.writeContract({\n address: dataRefinerRegistryAddress,\n abi: dataRefinerRegistryAbi,\n functionName: \"updateSchemaId\",\n args: [BigInt(params.refinerId), BigInt(params.newSchemaId)],\n account,\n chain: this.context.walletClient.chain ?? null,\n ...this.spreadTransactionOptions(options),\n });\n\n // Wait for transaction confirmation\n await this.context.publicClient.waitForTransactionReceipt({ hash });\n\n // Return simple domain result\n return {\n transactionHash: hash,\n };\n } catch (error) {\n console.error(\"Failed to update schema ID:\", error);\n throw new Error(\n `Failed to update schema ID: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Uploads an encrypted file and grants permission to a party with a public key.\n *\n * This method handles the complete workflow:\n * 1. Encrypts the file with the user's encryption key\n * 2. Uploads the encrypted file to storage\n * 3. Encrypts the user's encryption key with the provided public key\n * 4. Registers the file with permissions\n *\n * @param params - Upload parameters including data, permissions, and options\n * @returns Promise resolving to upload result with file ID and storage URL\n */\n async uploadFileWithPermissions(\n params: UploadFileWithPermissionsParams,\n ): Promise<UploadEncryptedFileResult> {\n this.assertWallet();\n\n const { data, permissions, filename, providerName } = params;\n\n try {\n // 1. Upload the file with encryption using the centralized method\n const uploadResult = await this.uploadToStorage(\n data,\n filename,\n true, // Always encrypt for uploadFileWithPermissions\n providerName,\n );\n\n // 2. Get user address\n const userAddress = this.context.userAddress;\n\n // 3. Generate user's encryption key (same as used in uploadToStorage)\n const userEncryptionKey = await generateEncryptionKey(\n this.context.walletClient,\n this.context.platform,\n DEFAULT_ENCRYPTION_SEED,\n );\n\n // 4. Encrypt user's encryption key for each permission\n const encryptedPermissions = await Promise.all(\n permissions.map(async (permission) => {\n const encryptedKey = await encryptWithWalletPublicKey(\n userEncryptionKey,\n permission.publicKey,\n this.context.platform,\n );\n return {\n account: permission.account,\n key: encryptedKey,\n };\n }),\n );\n\n // 5. Register file with permissions (either via relayer or direct)\n if (this.context.relayer) {\n // Use unified relayer callback for file addition with permissions\n const request: UnifiedRelayerRequest = {\n type: \"direct\",\n operation: \"submitFileAdditionWithPermissions\",\n params: {\n url: uploadResult.url,\n userAddress,\n permissions: encryptedPermissions,\n },\n };\n const response = await this.context.relayer(request);\n if (response.type === \"error\") {\n throw new Error(response.error);\n }\n\n // Handle pending response (stateful relayer)\n let result: { fileId: number; transactionHash: Hash };\n if (response.type === \"pending\") {\n result = await this.pollRelayerForConfirmation(\n response.operationId,\n undefined, // TODO: Add TransactionOptions to upload method signature\n );\n } else if (\n response.type === \"direct\" &&\n typeof response.result === \"object\" &&\n response.result !== null &&\n \"fileId\" in response.result\n ) {\n result = response.result as {\n fileId: number;\n transactionHash: Hash;\n };\n } else {\n throw new Error(\"Invalid response from relayer\");\n }\n return {\n fileId: result.fileId,\n url: uploadResult.url,\n size: uploadResult.size,\n transactionHash: result.transactionHash,\n };\n } else {\n // Direct transaction - returns TransactionResult POJO\n const txResult = await this.addFileWithPermissions(\n uploadResult.url,\n userAddress,\n encryptedPermissions,\n );\n\n // Wait for transaction events to get the actual fileId\n if (!this.context.waitForTransactionEvents) {\n throw new Error(\n \"Cannot upload without relay: waitForTransactionEvents not configured\",\n );\n }\n\n const eventResult =\n await this.context.waitForTransactionEvents(txResult);\n const fileAddedEvent = eventResult.expectedEvents.FileAdded;\n if (!fileAddedEvent) {\n throw new Error(\"FileAdded event not found in transaction\");\n }\n\n return {\n fileId: Number(fileAddedEvent.fileId),\n url: uploadResult.url,\n size: uploadResult.size,\n transactionHash: txResult.hash,\n };\n }\n } catch (error) {\n console.error(\"Failed to upload file with permissions:\", error);\n throw new Error(\n `Failed to upload file with permissions: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Uploads content to storage without registering it on the blockchain.\n * This method only handles the storage upload and returns the file URL.\n *\n * @param content - The content to upload (string, Blob, Buffer, or object - objects will be JSON stringified)\n * @param filename - Optional filename for the uploaded file (defaults to timestamp-based name)\n * @param encrypt - Optional flag to encrypt the content before upload\n * @param providerName - Optional specific storage provider to use\n * @returns Promise resolving to the storage upload result with url, size, and contentType\n */\n async uploadToStorage(\n content: string | Blob | Buffer | object,\n filename?: string,\n encrypt: boolean = false,\n providerName?: string,\n ): Promise<StorageUploadResult> {\n try {\n // Step 1: Normalize content to Blob\n let blob: Blob;\n if (content instanceof Blob) {\n blob = content;\n } else if (typeof content === \"string\") {\n blob = new Blob([content], { type: \"text/plain\" });\n } else if (content instanceof Buffer) {\n // Convert Buffer to ArrayBuffer for BlobPart compatibility in browser typings\n const arrayBuffer = content.buffer.slice(\n content.byteOffset,\n content.byteOffset + content.byteLength,\n ) as ArrayBuffer;\n blob = new Blob([arrayBuffer], { type: \"application/octet-stream\" });\n } else {\n // Handle objects by JSON stringifying them\n blob = new Blob([JSON.stringify(content)], {\n type: \"application/json\",\n });\n }\n\n // Step 3: Handle encryption\n let finalBlob = blob;\n if (encrypt) {\n this.assertWallet();\n\n // Generate encryption key\n const encryptionKey = await generateEncryptionKey(\n this.context.walletClient,\n this.context.platform,\n DEFAULT_ENCRYPTION_SEED,\n );\n\n // Encrypt the data\n finalBlob = await encryptBlobWithSignedKey(\n blob,\n encryptionKey,\n this.context.platform,\n );\n }\n\n // Step 4: Upload to storage\n if (!this.context.storageManager) {\n // Use centralized validation if available, otherwise fall back to old behavior\n if (this.context.validateStorageRequired) {\n this.context.validateStorageRequired();\n // The validateStorageRequired method throws, so this line should never be reached\n // but TypeScript doesn't know that, so we need this fallback\n throw new Error(\"Storage validation failed\");\n } else {\n throw new Error(\n \"Storage manager not configured. Please provide storage providers in VanaConfig.\",\n );\n }\n }\n\n // Determine final filename with proper .enc extension handling\n const finalFilename = (() => {\n if (filename) {\n // If encrypting and filename doesn't already have .enc extension, add it\n if (encrypt && !filename.endsWith(\".enc\")) {\n return `${filename}.enc`;\n }\n // Otherwise use filename as provided\n return filename;\n }\n // No filename provided - generate one based on encryption status\n return encrypt\n ? `upload-${Date.now()}.enc`\n : `upload-${Date.now()}.dat`;\n })();\n\n const uploadResult = await this.context.storageManager.upload(\n finalBlob,\n finalFilename,\n providerName,\n );\n\n return uploadResult;\n } catch (error) {\n throw new Error(\n `Upload failed: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Adds a permission for a party to access an existing file.\n *\n * This method handles the complete workflow:\n * 1. Gets the user's encryption key\n * 2. Encrypts the user's encryption key with the provided public key\n * 3. Adds the permission to the file\n * 4. Returns the permission data from the blockchain event\n *\n * For advanced users who need more control over transaction timing,\n * use `submitFilePermission()` instead.\n *\n * @param params - Parameters for adding file permission\n * @param params.fileId - The ID of the file to grant permission for\n * @param params.account - The recipient's wallet address that will access the file\n * @param params.publicKey - The recipient's public key for encryption.\n * Obtain via `vana.server.getIdentity(account).publicKey`\n * @returns Promise resolving to permission data from PermissionGranted event\n * @throws {Error} \"No addresses available in wallet client\" - When wallet is not connected\n * @throws {Error} \"Chain ID not available\" - When wallet chain is not configured\n * @throws {Error} \"Failed to add permission to file: {error}\" - When transaction fails or user doesn't own file\n * @example\n * ```typescript\n * const result = await vana.data.addPermissionToFile({\n * fileId: 123,\n * account: \"0xRecipientAddress...\",\n * publicKey: \"0xRecipientPublicKey...\"\n * });\n * console.log(`Permission granted to ${result.account} for file ${result.fileId}`);\n * console.log(`Transaction: ${result.transactionHash}`);\n * ```\n */\n async addPermissionToFile(\n params: AddFilePermissionParams,\n options?: TransactionOptions,\n ): Promise<TransactionResult<\"DataRegistry\", \"addFilePermission\">> {\n this.assertWallet();\n\n const { fileId, account, publicKey } = params;\n return await this.submitFilePermission(fileId, account, publicKey, options);\n }\n\n /**\n * Submits a file permission transaction to the blockchain.\n *\n * @remarks\n * This method supports gasless transactions via relayer callbacks when configured.\n * It encrypts the user's encryption key with the recipient's public key before submission.\n * Use this when you want to handle transaction confirmation and event parsing separately.\n *\n * @param fileId - The ID of the file to grant permission for\n * @param account - The recipient's wallet address that will access the file\n * @param publicKey - The recipient's public key for encryption.\n * Obtain via `vana.server.getIdentity(account).publicKey`\n * @returns Promise resolving to TransactionResult for tracking the transaction\n * @throws {Error} When chain ID is not available\n * @throws {Error} When encryption key generation fails\n * @throws {Error} When public key encryption fails\n *\n * @example\n * ```typescript\n * const tx = await vana.data.submitFilePermission(\n * fileId,\n * \"0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36\",\n * recipientPublicKey\n * );\n * const result = await tx.waitForEvents();\n * console.log(`Permission granted with ID: ${result.permissionId}`);\n * ```\n */\n async submitFilePermission(\n fileId: number,\n account: Address,\n publicKey: string,\n options?: TransactionOptions,\n ): Promise<TransactionResult<\"DataRegistry\", \"addFilePermission\">> {\n this.assertWallet();\n\n try {\n // 1. Generate user's encryption key\n const userEncryptionKey = await generateEncryptionKey(\n this.context.walletClient,\n this.context.platform,\n DEFAULT_ENCRYPTION_SEED,\n );\n\n // 2. Encrypt user's encryption key with provided public key\n const encryptedKey = await encryptWithWalletPublicKey(\n userEncryptionKey,\n publicKey,\n this.context.platform,\n );\n\n // 3. Submit directly to the blockchain\n const chainId = this.context.publicClient.chain?.id;\n if (!chainId) {\n throw new Error(\"Chain ID not available\");\n }\n\n const dataRegistryAddress = getContractAddress(chainId, \"DataRegistry\");\n const dataRegistryAbi = getAbi(\"DataRegistry\");\n\n this.assertWallet();\n const walletAccount =\n this.context.walletClient.account ?? this.context.userAddress;\n\n const txHash = await this.context.walletClient.writeContract({\n address: dataRegistryAddress,\n abi: dataRegistryAbi,\n functionName: \"addFilePermission\",\n args: [BigInt(fileId), account, encryptedKey],\n account: walletAccount,\n chain: this.context.walletClient.chain ?? null,\n ...this.spreadTransactionOptions(options),\n });\n\n const { tx } = await import(\"../utils/transactionHelpers\");\n return tx({\n hash: txHash,\n from:\n typeof walletAccount === \"string\"\n ? walletAccount\n : walletAccount.address,\n contract: \"DataRegistry\",\n fn: \"addFilePermission\",\n });\n } catch (error) {\n console.error(\"Failed to add permission to file:\", error);\n throw new Error(\n `Failed to add permission to file: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Gets the encrypted key for a specific account's permission to access a file.\n *\n * @param fileId - The ID of the file\n * @param account - The account address to get the permission for\n * @returns Promise resolving to the encrypted key for that account\n */\n async getFilePermission(fileId: number, account: Address): Promise<string> {\n try {\n const chainId = this.context.publicClient.chain?.id;\n if (!chainId) {\n throw new Error(\"Chain ID not available\");\n }\n\n const dataRegistryAddress = getContractAddress(chainId, \"DataRegistry\");\n const dataRegistryAbi = getAbi(\"DataRegistry\");\n\n const dataRegistry = getContract({\n address: dataRegistryAddress,\n abi: dataRegistryAbi,\n client: this.context.publicClient,\n });\n\n const encryptedKey = await dataRegistry.read.filePermissions([\n BigInt(fileId),\n account,\n ]);\n\n return encryptedKey;\n } catch (error) {\n console.error(\"Failed to get file permission:\", error);\n throw new Error(\n `Failed to get file permission: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Decrypts a file that the user has permission to access using their private key.\n *\n * This method handles the complete workflow for servers or other permitted parties:\n * 1. Gets the encrypted encryption key from file permissions\n * 2. Decrypts the encryption key using the provided private key\n * 3. Downloads and decrypts the file data\n *\n * @param file - The file to decrypt\n * @param privateKey - The private key to decrypt the user's encryption key\n * @param options - Optional decryption configuration\n * @param options.account - The account address that has permission (defaults to current wallet account)\n * @returns Promise resolving to the decrypted file data\n */\n async decryptFileWithPermission(\n file: UserFile,\n privateKey: string,\n options?: DecryptFileWithPermissionOptions,\n ): Promise<Blob> {\n try {\n // Use provided account or get current wallet account\n const permissionAccount = options?.account ?? this.context.userAddress;\n\n // 1. Get the encrypted encryption key from file permissions\n const encryptedKey = await this.getFilePermission(\n file.id,\n permissionAccount,\n );\n\n if (!encryptedKey) {\n throw new Error(\n `No permission found for account ${permissionAccount} to access file ${file.id}`,\n );\n }\n\n // 2. Decrypt the encryption key using the private key\n const userEncryptionKey = await decryptWithWalletPrivateKey(\n encryptedKey,\n privateKey,\n this.context.platform,\n );\n\n // 3. Download the encrypted file\n // Use fetchFromIPFS for IPFS URLs, otherwise use regular fetch\n let encryptedData: Blob;\n if (file.url.startsWith(\"ipfs://\")) {\n encryptedData = await this.fetchFromIPFS(file.url);\n } else {\n encryptedData = await this.fetch(file.url);\n }\n\n // 4. Decrypt the file data using the user's encryption key\n const decryptedData = await decryptBlobWithSignedKey(\n encryptedData,\n userEncryptionKey,\n this.context.platform,\n );\n\n return decryptedData;\n } catch (error) {\n console.error(\"Failed to decrypt file with permission:\", error);\n throw new Error(\n `Failed to decrypt file with permission: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Simple network-agnostic fetch utility for retrieving file content.\n *\n * @remarks\n * This is a thin wrapper around the global fetch API that returns the response as a Blob.\n * It provides a consistent interface for fetching encrypted content before decryption.\n * For IPFS URLs, consider using fetchFromIPFS for better reliability.\n *\n * @param url - The URL to fetch content from\n * @returns Promise resolving to the fetched content as a Blob\n * @throws {Error} \"HTTP error! status: {status} {statusText}\" - When server returns error status\n * @throws {Error} \"Empty response\" - When server returns no content\n * @throws {Error} \"Network error: Failed to fetch from {url}\" - When network request fails\n *\n * @example\n * ```typescript\n * // Fetch and decrypt a file\n * const encryptionKey = await generateEncryptionKey(walletClient);\n * const encryptedBlob = await vana.data.fetch(file.url);\n * const decryptedBlob = await decryptBlob(encryptedBlob, encryptionKey, platform);\n *\n * // With custom headers for authentication\n * const response = await fetch(file.url, {\n * headers: { 'Authorization': 'Bearer token' }\n * });\n * const encryptedBlob = await response.blob();\n * ```\n */\n async fetch(url: string): Promise<Blob> {\n try {\n const { universalFetch } = await import(\"../utils/download\");\n const response = await universalFetch(url, this.context.downloadRelayer);\n\n if (!response.ok) {\n throw new Error(\n `HTTP error! status: ${response.status} ${response.statusText}`,\n );\n }\n\n const blob = await response.blob();\n\n // Check if blob is empty\n if (blob.size === 0) {\n throw new Error(\"Empty response\");\n }\n\n return blob;\n } catch (error) {\n if (error instanceof TypeError && error.message.includes(\"fetch\")) {\n throw new Error(\n `Network error: Failed to fetch from ${url}. The URL may be invalid or the server may not be accessible.`,\n );\n }\n throw error;\n }\n }\n\n /**\n * Specialized IPFS fetcher with gateway fallback mechanism.\n *\n * @remarks\n * This method provides robust IPFS content fetching by trying multiple gateways\n * in sequence until one succeeds. It supports both ipfs:// URLs and raw CIDs.\n *\n * The default gateway list includes public gateways, but you should provide\n * your own gateways for production use to ensure reliability and privacy.\n *\n * @param url - The IPFS URL (ipfs://...) or CID to fetch\n * @param options - Optional configuration\n * @param options.gateways - Array of IPFS gateway URLs to try (must end with /)\n * @returns Promise resolving to the fetched content as a Blob\n * @throws {Error} \"Invalid IPFS URL format\" - When URL is not ipfs:// or valid CID\n * @throws {Error} \"Empty response\" - When gateway returns no content\n * @throws {Error} \"HTTP error! status: {status}\" - When gateway returns error status\n * @throws {Error} \"Failed to fetch IPFS content {cid} from all gateways\" - When all gateways fail\n *\n * @example\n * ```typescript\n * // Fetch from IPFS with custom gateways\n * const encryptedBlob = await vana.data.fetchFromIPFS(file.url, {\n * gateways: [\n * 'https://my-private-gateway.com/ipfs/',\n * 'https://dweb.link/ipfs/',\n * 'https://ipfs.io/ipfs/'\n * ]\n * });\n *\n * // Decrypt the fetched content\n * const encryptionKey = await generateEncryptionKey(walletClient);\n * const decryptedBlob = await decryptBlob(encryptedBlob, encryptionKey, platform);\n *\n * // With raw CID\n * const blob = await vana.data.fetchFromIPFS('QmXxx...', {\n * gateways: ['https://ipfs.io/ipfs/']\n * });\n * ```\n */\n async fetchFromIPFS(\n url: string,\n options?: { gateways?: string[] },\n ): Promise<Blob> {\n // Default public gateways (in order of preference)\n const defaultGateways = [\n \"https://dweb.link/ipfs/\",\n \"https://ipfs.io/ipfs/\",\n ];\n\n // Use per-call gateways if provided, otherwise use app-wide gateways, otherwise use defaults\n const gateways =\n options?.gateways ?? this.context.ipfsGateways ?? defaultGateways;\n\n // Use ipfs utilities to extract hash\n const { extractIpfsHash } = await import(\"../utils/ipfs\");\n const cid = extractIpfsHash(url);\n\n if (!cid) {\n throw new Error(\n `Invalid IPFS URL format. Expected ipfs://... or a raw CID, got: ${url}`,\n );\n }\n\n const errors: Array<{ gateway: string; error: string }> = [];\n\n // Try each gateway in sequence\n for (let i = 0; i < gateways.length; i++) {\n const gateway = gateways[i];\n const isLastGateway = i === gateways.length - 1;\n const gatewayUrl = gateway.endsWith(\"/\")\n ? `${gateway}${cid}`\n : `${gateway}/${cid}`;\n\n try {\n console.debug(`Trying IPFS gateway: ${gatewayUrl}`);\n\n const response = await fetch(gatewayUrl);\n\n if (response.ok) {\n const blob = await response.blob();\n\n // Verify we got actual content\n if (blob.size > 0) {\n console.debug(`Successfully fetched from gateway: ${gateway}`);\n return blob;\n } else {\n // If this is the last gateway and we got an empty response, throw specific error\n if (isLastGateway) {\n throw new Error(\"Empty response\");\n }\n errors.push({\n gateway,\n error: \"Empty response\",\n });\n }\n } else {\n // Handle specific HTTP errors on last gateway attempt\n if (isLastGateway) {\n if (response.status === 403) {\n throw new Error(`HTTP error! status: 403 ${response.statusText}`);\n } else if (response.status === 404) {\n throw new Error(`HTTP error! status: 404 ${response.statusText}`);\n } else {\n throw new Error(\n `HTTP error! status: ${response.status} ${response.statusText}`,\n );\n }\n }\n errors.push({\n gateway,\n error: `HTTP ${response.status} ${response.statusText}`,\n });\n }\n } catch (error) {\n // Re-throw on last gateway if it's a specific error we want to preserve\n if (\n isLastGateway &&\n error instanceof Error &&\n (error.message.includes(\"Empty response\") ||\n error.message.includes(\"HTTP error!\"))\n ) {\n throw error;\n }\n errors.push({\n gateway,\n error: error instanceof Error ? error.message : \"Unknown error\",\n });\n }\n }\n\n // All gateways failed\n // Try download relayer as final fallback if configured\n if (this.context.downloadRelayer && gateways.length > 0) {\n try {\n // Try with the first gateway URL format\n const relayerUrl = gateways[0].endsWith(\"/\")\n ? `${gateways[0]}${cid}`\n : `${gateways[0]}/${cid}`;\n return await this.context.downloadRelayer.proxyDownload(relayerUrl);\n } catch (relayerError) {\n errors.push({\n gateway: \"download-relayer\",\n error: `Proxy failed: ${relayerError instanceof Error ? relayerError.message : \"Unknown error\"}`,\n });\n }\n }\n\n const errorDetails = errors\n .map((e) => `${e.gateway}: ${e.error}`)\n .join(\"\\n \");\n\n throw new Error(\n `Failed to fetch IPFS content ${cid} from all gateways:\\n ${errorDetails}`,\n );\n }\n\n /**\n * Validates a data schema definition against the Vana meta-schema.\n *\n * @param schema - The data schema definition to validate\n * @returns The validated DataSchema\n * @throws SchemaValidationError if invalid\n * @example\n * ```typescript\n * const schema = {\n * name: \"User Profile\",\n * version: \"1.0.0\",\n * dialect: \"json\",\n * schema: {\n * type: \"object\",\n * properties: {\n * name: { type: \"string\" },\n * age: { type: \"number\" }\n * }\n * }\n * };\n *\n * const validatedSchema = vana.data.validateDataSchemaAgainstMetaSchema(schema);\n * ```\n */\n validateDataSchemaAgainstMetaSchema(schema: unknown): DataSchema {\n return validateDataSchemaAgainstMetaSchema(schema);\n }\n\n /**\n * Validates data against a JSON Schema from a data schema.\n *\n * @param data - The data to validate\n * @param schema - The data schema containing the schema\n * @returns Void (throws if validation fails)\n * @throws SchemaValidationError if invalid\n * @example\n * ```typescript\n * const schema = {\n * name: \"User Profile\",\n * version: \"1.0.0\",\n * dialect: \"json\",\n * schema: {\n * type: \"object\",\n * properties: {\n * name: { type: \"string\" },\n * age: { type: \"number\" }\n * },\n * required: [\"name\"]\n * }\n * };\n *\n * const userData = { name: \"Alice\", age: 30 };\n * vana.data.validateDataAgainstSchema(userData, schema);\n * ```\n */\n validateDataAgainstSchema(data: unknown, schema: DataSchema): void {\n validateDataAgainstSchema(data, schema);\n }\n\n /**\n * Fetches and validates a data schema from a URL, then returns the parsed data schema.\n *\n * @param url - The URL to fetch the data schema from\n * @returns The validated data schema\n * @throws SchemaValidationError if invalid or fetch fails\n * @example\n * ```typescript\n * // Fetch and validate a schema from IPFS or HTTP\n * const schema = await vana.data.fetchAndValidateSchema(\"https://example.com/schema.json\");\n * console.log(schema.name, schema.dialect);\n *\n * // Use the schema to validate user data\n * if (schema.dialect === \"json\") {\n * vana.data.validateDataAgainstSchema(userData, schema);\n * }\n * ```\n */\n async fetchAndValidateSchema(url: string): Promise<DataSchema> {\n return fetchAndValidateSchema(url);\n }\n\n /**\n * Polls for confirmation of a relayer operation.\n * @internal\n */\n private async pollRelayerForConfirmation(\n operationId: string,\n options?: TransactionOptions,\n ): Promise<{ fileId: number; transactionHash: Hash }> {\n if (!this.context.relayer) {\n throw new Error(\"Relayer not configured for polling\");\n }\n\n const pollingManager = new PollingManager(this.context.relayer);\n\n const result = await pollingManager.startPolling(operationId, {\n signal: options?.signal,\n onStatusUpdate: options?.onStatusUpdate,\n ...options?.pollingOptions,\n });\n\n // For data operations, we need to extract the fileId from the transaction\n // This would typically come from parsing transaction logs\n // For now, we'll return a placeholder that would need proper implementation\n return {\n fileId: 0, // This would need to be extracted from transaction events\n transactionHash: result.hash,\n };\n }\n}\n"],"mappings":"AACA,SAAS,mBAAmB;AAgC5B,SAAS,sBAAsB;AAC/B,SAAS,sBAAsB;AAC/B,SAAS,0BAA0B;AACnC,SAAS,cAAc;AACvB,SAAS,iCAAiC;AAW1C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,aAAa;AAEtB;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,yBAAyB;AA8D3B,MAAM,uBAAuB,eAAe;AAAA,EACjD,YAAY,SAA4B;AACtC,UAAM,OAAO;AAAA,EACf;AAAA,EAgHA,MAAM,OAAO,QAA6C;AACxD,SAAK,aAAa;AAElB,UAAM;AAAA,MACJ;AAAA,MACA;AAAA,MACA;AAAA,MACA,cAAc,CAAC;AAAA,MACf,UAAU;AAAA,MACV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