@opendatalabs/vana-sdk 0.1.0-alpha.f2de4f7 → 0.1.0-alpha.f35bb9c

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 (165) hide show
  1. package/dist/browser.cjs.map +1 -1
  2. package/dist/browser.d.ts +33 -1
  3. package/dist/browser.js.map +1 -1
  4. package/dist/chains/index.cjs.map +1 -1
  5. package/dist/chains/index.d.ts +30 -1
  6. package/dist/chains/index.js.map +1 -1
  7. package/dist/config/chains.cjs.map +1 -1
  8. package/dist/config/chains.d.ts +99 -0
  9. package/dist/config/chains.js.map +1 -1
  10. package/dist/contracts/contractController.cjs.map +1 -1
  11. package/dist/contracts/contractController.d.ts +66 -10
  12. package/dist/contracts/contractController.js.map +1 -1
  13. package/dist/controllers/data.cjs +173 -141
  14. package/dist/controllers/data.cjs.map +1 -1
  15. package/dist/controllers/data.d.ts +213 -175
  16. package/dist/controllers/data.js +173 -141
  17. package/dist/controllers/data.js.map +1 -1
  18. package/dist/controllers/permissions.cjs +185 -191
  19. package/dist/controllers/permissions.cjs.map +1 -1
  20. package/dist/controllers/permissions.d.ts +29 -73
  21. package/dist/controllers/permissions.js +185 -191
  22. package/dist/controllers/permissions.js.map +1 -1
  23. package/dist/controllers/protocol.cjs.map +1 -1
  24. package/dist/controllers/protocol.d.ts +27 -28
  25. package/dist/controllers/protocol.js.map +1 -1
  26. package/dist/controllers/schemas.cjs +23 -21
  27. package/dist/controllers/schemas.cjs.map +1 -1
  28. package/dist/controllers/schemas.d.ts +47 -40
  29. package/dist/controllers/schemas.js +23 -21
  30. package/dist/controllers/schemas.js.map +1 -1
  31. package/dist/controllers/server.cjs +17 -15
  32. package/dist/controllers/server.cjs.map +1 -1
  33. package/dist/controllers/server.d.ts +46 -38
  34. package/dist/controllers/server.js +17 -15
  35. package/dist/controllers/server.js.map +1 -1
  36. package/dist/core/apiClient.cjs +53 -3
  37. package/dist/core/apiClient.cjs.map +1 -1
  38. package/dist/core/apiClient.d.ts +132 -7
  39. package/dist/core/apiClient.js +53 -3
  40. package/dist/core/apiClient.js.map +1 -1
  41. package/dist/core/generics.cjs +30 -3
  42. package/dist/core/generics.cjs.map +1 -1
  43. package/dist/core/generics.d.ts +95 -6
  44. package/dist/core/generics.js +30 -3
  45. package/dist/core/generics.js.map +1 -1
  46. package/dist/core.cjs +29 -12
  47. package/dist/core.cjs.map +1 -1
  48. package/dist/core.d.ts +2 -1
  49. package/dist/core.js +29 -12
  50. package/dist/core.js.map +1 -1
  51. package/dist/index.cjs.map +1 -1
  52. package/dist/index.js.map +1 -1
  53. package/dist/index.node.cjs +3 -3
  54. package/dist/index.node.cjs.map +1 -1
  55. package/dist/index.node.d.ts +8 -9
  56. package/dist/index.node.js +2 -2
  57. package/dist/index.node.js.map +1 -1
  58. package/dist/node.cjs.map +1 -1
  59. package/dist/node.d.ts +39 -1
  60. package/dist/node.js.map +1 -1
  61. package/dist/platform/browser.cjs +160 -2
  62. package/dist/platform/browser.cjs.map +1 -1
  63. package/dist/platform/browser.d.ts +232 -12
  64. package/dist/platform/browser.js +160 -2
  65. package/dist/platform/browser.js.map +1 -1
  66. package/dist/platform/interface.cjs.map +1 -1
  67. package/dist/platform/interface.d.ts +283 -90
  68. package/dist/platform/node.cjs +163 -2
  69. package/dist/platform/node.cjs.map +1 -1
  70. package/dist/platform/node.d.ts +69 -6
  71. package/dist/platform/node.js +163 -2
  72. package/dist/platform/node.js.map +1 -1
  73. package/dist/server/relayerHandler.cjs +214 -0
  74. package/dist/server/relayerHandler.cjs.map +1 -0
  75. package/dist/server/relayerHandler.d.ts +36 -0
  76. package/dist/server/relayerHandler.js +190 -0
  77. package/dist/server/relayerHandler.js.map +1 -0
  78. package/dist/storage/manager.cjs +108 -25
  79. package/dist/storage/manager.cjs.map +1 -1
  80. package/dist/storage/manager.d.ts +119 -25
  81. package/dist/storage/manager.js +108 -25
  82. package/dist/storage/manager.js.map +1 -1
  83. package/dist/storage/providers/callback-storage.cjs +86 -15
  84. package/dist/storage/providers/callback-storage.cjs.map +1 -1
  85. package/dist/storage/providers/callback-storage.d.ts +109 -20
  86. package/dist/storage/providers/callback-storage.js +86 -15
  87. package/dist/storage/providers/callback-storage.js.map +1 -1
  88. package/dist/storage/providers/pinata.cjs.map +1 -1
  89. package/dist/storage/providers/pinata.d.ts +12 -14
  90. package/dist/storage/providers/pinata.js.map +1 -1
  91. package/dist/tests/factories/mockFactory.d.ts +2 -2
  92. package/dist/tests/relayer-integration.test.d.ts +1 -0
  93. package/dist/tests/relayer-unified.test.d.ts +1 -0
  94. package/dist/tests/server-relayer-handler.test.d.ts +1 -0
  95. package/dist/types/blockchain.cjs.map +1 -1
  96. package/dist/types/blockchain.d.ts +39 -11
  97. package/dist/types/chains.cjs.map +1 -1
  98. package/dist/types/chains.d.ts +74 -7
  99. package/dist/types/chains.js.map +1 -1
  100. package/dist/types/config.cjs.map +1 -1
  101. package/dist/types/config.d.ts +46 -191
  102. package/dist/types/config.js.map +1 -1
  103. package/dist/types/contracts.cjs.map +1 -1
  104. package/dist/types/contracts.d.ts +71 -7
  105. package/dist/types/controller-context.cjs.map +1 -1
  106. package/dist/types/controller-context.d.ts +3 -2
  107. package/dist/types/data.cjs.map +1 -1
  108. package/dist/types/data.d.ts +4 -6
  109. package/dist/types/generics.cjs.map +1 -1
  110. package/dist/types/generics.d.ts +80 -9
  111. package/dist/types/index.cjs.map +1 -1
  112. package/dist/types/index.d.ts +27 -2
  113. package/dist/types/index.js.map +1 -1
  114. package/dist/types/operations.cjs.map +1 -1
  115. package/dist/types/operations.d.ts +132 -15
  116. package/dist/types/operations.js.map +1 -1
  117. package/dist/types/permissions.cjs.map +1 -1
  118. package/dist/types/permissions.d.ts +15 -20
  119. package/dist/types/personal.cjs.map +1 -1
  120. package/dist/types/personal.d.ts +131 -14
  121. package/dist/types/relayer.cjs.map +1 -1
  122. package/dist/types/relayer.d.ts +262 -35
  123. package/dist/types/storage.cjs.map +1 -1
  124. package/dist/types/storage.d.ts +9 -21
  125. package/dist/types/storage.js.map +1 -1
  126. package/dist/utils/grantFiles.cjs.map +1 -1
  127. package/dist/utils/grantFiles.d.ts +10 -20
  128. package/dist/utils/grantFiles.js.map +1 -1
  129. package/dist/utils/grantValidation.cjs.map +1 -1
  130. package/dist/utils/grantValidation.d.ts +95 -16
  131. package/dist/utils/grantValidation.js.map +1 -1
  132. package/dist/utils/grants.cjs.map +1 -1
  133. package/dist/utils/grants.d.ts +93 -12
  134. package/dist/utils/grants.js.map +1 -1
  135. package/dist/utils/lazy-import.cjs.map +1 -1
  136. package/dist/utils/lazy-import.d.ts +32 -7
  137. package/dist/utils/lazy-import.js.map +1 -1
  138. package/dist/utils/signatureCache.cjs +8 -2
  139. package/dist/utils/signatureCache.cjs.map +1 -1
  140. package/dist/utils/signatureCache.d.ts +49 -8
  141. package/dist/utils/signatureCache.js +8 -2
  142. package/dist/utils/signatureCache.js.map +1 -1
  143. package/dist/utils/transactionHelpers.cjs.map +1 -1
  144. package/dist/utils/transactionHelpers.d.ts +12 -12
  145. package/dist/utils/transactionHelpers.js.map +1 -1
  146. package/dist/utils/typedDataConverter.cjs.map +1 -1
  147. package/dist/utils/typedDataConverter.d.ts +39 -3
  148. package/dist/utils/typedDataConverter.js.map +1 -1
  149. package/dist/utils/urlResolver.cjs +7 -0
  150. package/dist/utils/urlResolver.cjs.map +1 -1
  151. package/dist/utils/urlResolver.d.ts +22 -4
  152. package/dist/utils/urlResolver.js +7 -0
  153. package/dist/utils/urlResolver.js.map +1 -1
  154. package/dist/utils/wallet.cjs +2 -1
  155. package/dist/utils/wallet.cjs.map +1 -1
  156. package/dist/utils/wallet.d.ts +78 -16
  157. package/dist/utils/wallet.js +2 -1
  158. package/dist/utils/wallet.js.map +1 -1
  159. package/package.json +1 -1
  160. package/dist/server/handler.cjs +0 -101
  161. package/dist/server/handler.cjs.map +0 -1
  162. package/dist/server/handler.d.ts +0 -87
  163. package/dist/server/handler.js +0 -77
  164. package/dist/server/handler.js.map +0 -1
  165. /package/dist/tests/{server-handler.test.d.ts → permissions-revoke-relayer.test.d.ts} +0 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/types/relayer.ts"],"sourcesContent":["import type { Hash } from \"viem\";\nimport type { GrantFile, PermissionGrantTypedData } from \"./permissions\";\n\n/**\n * Response from the relayer service for grant file storage\n *\n * @category Advanced\n */\nexport interface RelayerStorageResponse {\n /** The IPFS URL where the grant file is stored */\n grantUrl: string;\n /** Success status */\n success: boolean;\n /** Optional error message */\n error?: string;\n /** Storage metadata */\n metadata?: {\n /** IPFS hash */\n ipfsHash: string;\n /** File size in bytes */\n size: number;\n /** Upload timestamp */\n timestamp: number;\n };\n}\n\n/**\n * Response from the relayer service for transaction submission\n *\n * @category Advanced\n */\nexport interface RelayerTransactionResponse {\n /** The transaction hash of the submitted transaction */\n transactionHash: Hash;\n /** Success status */\n success: boolean;\n /** Optional error message */\n error?: string;\n /** Transaction metadata */\n metadata?: {\n /** Gas used */\n gasUsed?: bigint;\n /** Gas price */\n gasPrice?: bigint;\n /** Block number */\n blockNumber?: bigint;\n /** Transaction status */\n status?: \"pending\" | \"confirmed\" | \"failed\";\n };\n}\n\n/**\n * Parameters for storing a grant file via relayer\n *\n * @category Advanced\n */\nexport interface RelayerStoreParams {\n /** The grant file to store */\n grantFile: GrantFile;\n /** Optional storage options */\n options?: {\n /** IPFS pin duration in seconds */\n pinDuration?: number;\n /** Whether to use encryption */\n encrypt?: boolean;\n /** Custom metadata */\n metadata?: Record<string, unknown>;\n };\n}\n\n/**\n * Parameters for submitting a transaction via relayer\n *\n * @category Advanced\n */\nexport interface RelayerSubmitParams {\n /** The signed typed data */\n typedData: PermissionGrantTypedData;\n /** The signature */\n signature: string;\n /** Optional transaction options */\n options?: {\n /** Gas limit */\n gasLimit?: bigint;\n /** Priority level */\n priority?: \"low\" | \"medium\" | \"high\";\n /** Whether to wait for confirmation */\n waitForConfirmation?: boolean;\n };\n}\n\n/**\n * Relayer service status\n *\n * @category Advanced\n */\nexport interface RelayerStatus {\n /** Whether the relayer is online */\n online: boolean;\n /** Service version */\n version: string;\n /** Supported chains */\n supportedChains: number[];\n /** Current chain status */\n chainStatus: Record<\n number,\n {\n /** Whether the chain is supported */\n supported: boolean;\n /** Current block number */\n currentBlock: bigint;\n /** Gas price estimation */\n gasPrice: bigint;\n /** Queue size */\n queueSize: number;\n }\n >;\n /** Rate limit information */\n rateLimits: {\n /** Requests per minute */\n requestsPerMinute: number;\n /** Storage requests per hour */\n storageRequestsPerHour: number;\n /** Transaction requests per hour */\n transactionRequestsPerHour: number;\n };\n}\n\n/**\n * Relayer configuration\n *\n * @category Advanced\n */\nexport interface RelayerConfig {\n /** Relayer service URL */\n url: string;\n /** API key for authentication */\n apiKey?: string;\n /** Timeout for requests in milliseconds */\n timeout?: number;\n /** Retry configuration */\n retry?: {\n /** Number of retry attempts */\n attempts: number;\n /** Delay between retries in milliseconds */\n delay: number;\n };\n /** Whether to use HTTPS */\n useHttps?: boolean;\n}\n\n/**\n * Relayer request options\n *\n * @category Advanced\n */\nexport interface RelayerRequestOptions {\n /** Request timeout in milliseconds */\n timeout?: number;\n /** Whether to retry on failure */\n retry?: boolean;\n /** Custom headers */\n headers?: Record<string, string>;\n /** Request priority */\n priority?: \"low\" | \"medium\" | \"high\";\n}\n\n/**\n * Relayer error response\n *\n * @category Advanced\n */\nexport interface RelayerErrorResponse {\n /** Error code */\n code: string;\n /** Error message */\n message: string;\n /** Additional error details */\n details?: Record<string, unknown>;\n /** Request ID for debugging */\n requestId?: string;\n /** Timestamp of error */\n timestamp: number;\n}\n\n/**\n * Relayer queue information\n *\n * @category Advanced\n */\nexport interface RelayerQueueInfo {\n /** Current queue size */\n size: number;\n /** Estimated processing time in seconds */\n estimatedProcessingTime: number;\n /** Queue position for a specific request */\n position?: number;\n /** Processing statistics */\n stats: {\n /** Average processing time in seconds */\n averageProcessingTime: number;\n /** Requests processed in last hour */\n requestsProcessedHour: number;\n /** Success rate percentage */\n successRate: number;\n };\n}\n\n/**\n * Relayer transaction status\n *\n * @category Advanced\n */\nexport interface RelayerTransactionStatus {\n /** Transaction hash */\n transactionHash: Hash;\n /** Current status */\n status: \"pending\" | \"confirmed\" | \"failed\";\n /** Block number if confirmed */\n blockNumber?: bigint;\n /** Gas used */\n gasUsed?: bigint;\n /** Error message if failed */\n error?: string;\n /** Status checks performed */\n checks: Array<{\n /** Check timestamp */\n timestamp: number;\n /** Status at time of check */\n status: string;\n /** Block number at time of check */\n blockNumber: bigint;\n }>;\n}\n\n/**\n * Relayer metrics\n *\n * @category Advanced\n */\nexport interface RelayerMetrics {\n /** Total transactions processed */\n totalTransactions: number;\n /** Successful transactions */\n successfulTransactions: number;\n /** Failed transactions */\n failedTransactions: number;\n /** Average processing time in seconds */\n averageProcessingTime: number;\n /** Current queue size */\n queueSize: number;\n /** Uptime percentage */\n uptime: number;\n /** Last 24 hour statistics */\n last24Hours: {\n /** Transactions processed */\n transactions: number;\n /** Success rate */\n successRate: number;\n /** Average response time */\n averageResponseTime: number;\n };\n}\n\n/**\n * Relayer webhook configuration\n *\n * @category Advanced\n */\nexport interface RelayerWebhookConfig {\n /** Webhook URL */\n url: string;\n /** Events to subscribe to */\n events: Array<\n \"transaction_confirmed\" | \"transaction_failed\" | \"storage_complete\"\n >;\n /** Webhook secret for signature verification */\n secret?: string;\n /** Whether webhook is active */\n active: boolean;\n}\n\n/**\n * Relayer webhook payload\n *\n * @category Advanced\n */\nexport interface RelayerWebhookPayload {\n /** Event type */\n event: string;\n /** Event data */\n data: Record<string, unknown>;\n /** Timestamp */\n timestamp: number;\n /** Webhook ID */\n webhookId: string;\n /** Signature for verification */\n signature: string;\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
1
+ {"version":3,"sources":["../../src/types/relayer.ts"],"sourcesContent":["/**\n * Defines types for gasless transaction relayers and server operations.\n *\n * @remarks\n * This module provides comprehensive type definitions for interacting with\n * relayer services that enable gasless transactions and auxiliary operations.\n * It includes both legacy v1 types and the simplified v2 unified interface.\n *\n * @category Types\n * @module types/relayer\n */\n\nimport type { Hash, Address } from \"viem\";\nimport type {\n GrantFile,\n PermissionGrantTypedData,\n GenericTypedData,\n} from \"./permissions\";\n\n/**\n * Represents the response from storing grant files via relayer.\n *\n * @remarks\n * Contains storage location, metadata, and error information for\n * grant file upload operations.\n *\n * @category Advanced\n */\nexport interface RelayerStorageResponse {\n /** The IPFS URL where the grant file is stored */\n grantUrl: string;\n /** Success status */\n success: boolean;\n /** Optional error message */\n error?: string;\n /** Storage metadata */\n metadata?: {\n /** IPFS hash */\n ipfsHash: string;\n /** File size in bytes */\n size: number;\n /** Upload timestamp */\n timestamp: number;\n };\n}\n\n/**\n * Represents the response from submitting transactions via relayer.\n *\n * @remarks\n * Contains transaction hash, status, and metadata for gasless\n * transaction submissions.\n *\n * @category Advanced\n */\nexport interface RelayerTransactionResponse {\n /** The transaction hash of the submitted transaction */\n transactionHash: Hash;\n /** Success status */\n success: boolean;\n /** Optional error message */\n error?: string;\n /** Transaction metadata */\n metadata?: {\n /** Gas used */\n gasUsed?: bigint;\n /** Gas price */\n gasPrice?: bigint;\n /** Block number */\n blockNumber?: bigint;\n /** Transaction status */\n status?: \"pending\" | \"confirmed\" | \"failed\";\n };\n}\n\n/**\n * Specifies parameters for storing grant files via relayer.\n *\n * @remarks\n * Includes the grant file and optional storage configuration\n * such as encryption and pinning duration.\n *\n * @category Advanced\n */\nexport interface RelayerStoreParams {\n /** The grant file to store */\n grantFile: GrantFile;\n /** Optional storage options */\n options?: {\n /** IPFS pin duration in seconds */\n pinDuration?: number;\n /** Whether to use encryption */\n encrypt?: boolean;\n /** Custom metadata */\n metadata?: Record<string, unknown>;\n };\n}\n\n/**\n * Specifies parameters for submitting gasless transactions.\n *\n * @remarks\n * Contains signed typed data and transaction configuration options\n * for relayer submission.\n *\n * @category Advanced\n */\nexport interface RelayerSubmitParams {\n /** The signed typed data */\n typedData: PermissionGrantTypedData;\n /** The signature */\n signature: string;\n /** Optional transaction options */\n options?: {\n /** Gas limit */\n gasLimit?: bigint;\n /** Priority level */\n priority?: \"low\" | \"medium\" | \"high\";\n /** Whether to wait for confirmation */\n waitForConfirmation?: boolean;\n };\n}\n\n/**\n * Represents the current status and capabilities of a relayer service.\n *\n * @remarks\n * Provides information about supported chains, rate limits, and\n * current operational status for monitoring and decision-making.\n *\n * @category Advanced\n */\nexport interface RelayerStatus {\n /** Whether the relayer is online */\n online: boolean;\n /** Service version */\n version: string;\n /** Supported chains */\n supportedChains: number[];\n /** Current chain status */\n chainStatus: Record<\n number,\n {\n /** Whether the chain is supported */\n supported: boolean;\n /** Current block number */\n currentBlock: bigint;\n /** Gas price estimation */\n gasPrice: bigint;\n /** Queue size */\n queueSize: number;\n }\n >;\n /** Rate limit information */\n rateLimits: {\n /** Requests per minute */\n requestsPerMinute: number;\n /** Storage requests per hour */\n storageRequestsPerHour: number;\n /** Transaction requests per hour */\n transactionRequestsPerHour: number;\n };\n}\n\n/**\n * Configures behavior for relayer requests.\n *\n * @remarks\n * Controls timeout, retry logic, headers, and priority for\n * relayer operation requests.\n *\n * @category Advanced\n */\nexport interface RelayerRequestOptions {\n /** Request timeout in milliseconds */\n timeout?: number;\n /** Whether to retry on failure */\n retry?: boolean;\n /** Custom headers */\n headers?: Record<string, string>;\n /** Request priority */\n priority?: \"low\" | \"medium\" | \"high\";\n}\n\n/**\n * Represents an error response from the relayer service.\n *\n * @remarks\n * Provides structured error information including codes, messages,\n * and debugging details for error handling and recovery.\n *\n * @category Advanced\n */\nexport interface RelayerErrorResponse {\n /** Error code */\n code: string;\n /** Error message */\n message: string;\n /** Additional error details */\n details?: Record<string, unknown>;\n /** Request ID for debugging */\n requestId?: string;\n /** Timestamp of error */\n timestamp: number;\n}\n\n/**\n * Provides information about the relayer's processing queue.\n *\n * @remarks\n * Includes queue size, position, estimated processing time, and\n * performance statistics for queue monitoring.\n *\n * @category Advanced\n */\nexport interface RelayerQueueInfo {\n /** Current queue size */\n size: number;\n /** Estimated processing time in seconds */\n estimatedProcessingTime: number;\n /** Queue position for a specific request */\n position?: number;\n /** Processing statistics */\n stats: {\n /** Average processing time in seconds */\n averageProcessingTime: number;\n /** Requests processed in last hour */\n requestsProcessedHour: number;\n /** Success rate percentage */\n successRate: number;\n };\n}\n\n/**\n * Tracks the status of a transaction submitted via relayer.\n *\n * @remarks\n * Provides detailed tracking information including confirmation status,\n * gas usage, and historical status checks.\n *\n * @category Advanced\n */\nexport interface RelayerTransactionStatus {\n /** Transaction hash */\n transactionHash: Hash;\n /** Current status */\n status: \"pending\" | \"confirmed\" | \"failed\";\n /** Block number if confirmed */\n blockNumber?: bigint;\n /** Gas used */\n gasUsed?: bigint;\n /** Error message if failed */\n error?: string;\n /** Status checks performed */\n checks: Array<{\n /** Check timestamp */\n timestamp: number;\n /** Status at time of check */\n status: string;\n /** Block number at time of check */\n blockNumber: bigint;\n }>;\n}\n\n/**\n * Provides performance metrics for the relayer service.\n *\n * @remarks\n * Includes transaction statistics, success rates, processing times,\n * and uptime information for monitoring and optimization.\n *\n * @category Advanced\n */\nexport interface RelayerMetrics {\n /** Total transactions processed */\n totalTransactions: number;\n /** Successful transactions */\n successfulTransactions: number;\n /** Failed transactions */\n failedTransactions: number;\n /** Average processing time in seconds */\n averageProcessingTime: number;\n /** Current queue size */\n queueSize: number;\n /** Uptime percentage */\n uptime: number;\n /** Last 24 hour statistics */\n last24Hours: {\n /** Transactions processed */\n transactions: number;\n /** Success rate */\n successRate: number;\n /** Average response time */\n averageResponseTime: number;\n };\n}\n\n/**\n * Configures webhook notifications for relayer events.\n *\n * @remarks\n * Enables asynchronous notifications for transaction confirmations,\n * failures, and storage completions.\n *\n * @category Advanced\n */\nexport interface RelayerWebhookConfig {\n /** Webhook URL */\n url: string;\n /** Events to subscribe to */\n events: Array<\n \"transaction_confirmed\" | \"transaction_failed\" | \"storage_complete\"\n >;\n /** Webhook secret for signature verification */\n secret?: string;\n /** Whether webhook is active */\n active: boolean;\n}\n\n/**\n * Represents a webhook event payload from the relayer.\n *\n * @remarks\n * Contains event data, timestamp, and signature for verification\n * of webhook authenticity.\n *\n * @category Advanced\n */\nexport interface RelayerWebhookPayload {\n /** Event type */\n event: string;\n /** Event data */\n data: Record<string, unknown>;\n /** Timestamp */\n timestamp: number;\n /** Webhook ID */\n webhookId: string;\n /** Signature for verification */\n signature: string;\n}\n\n// ===== NEW SIMPLIFIED RELAYER TYPES (v2) =====\n\n/**\n * Handles both EIP-712 signed operations and direct server operations through a single interface.\n *\n * @remarks\n * This discriminated union provides type safety through TypeScript's narrowing.\n * The `type` field determines which operation variant is being used.\n * Signed operations require blockchain transactions, while direct operations\n * handle auxiliary tasks like file storage.\n *\n * @category Relayer\n * @see {@link https://docs.vana.org/docs/gasless-transactions | Gasless Transactions Guide}\n */\nexport type UnifiedRelayerRequest = SignedRelayerRequest | DirectRelayerRequest;\n\n/**\n * Represents an EIP-712 signed operation for gasless transaction submission.\n *\n * @remarks\n * Signed requests contain typed data and signatures that are verified\n * on-chain by smart contracts. The relayer pays gas fees on behalf of users.\n *\n * @category Relayer\n */\nexport interface SignedRelayerRequest {\n /** Discriminator field identifying this as a signed operation */\n type: \"signed\";\n /** Operation identifier for routing (e.g., 'submitAddPermission') */\n operation: SignedOperationType;\n /** EIP-712 typed data structure for the operation */\n typedData: GenericTypedData;\n /** User's signature of the typed data */\n signature: Hash;\n /** Optional address for additional signer verification */\n expectedUserAddress?: Address;\n}\n\n/**\n * Enumerates supported EIP-712 signed operation types.\n *\n * @remarks\n * Each operation type corresponds to a specific smart contract\n * function that accepts gasless transactions.\n *\n * @category Relayer\n */\nexport type SignedOperationType =\n | \"submitAddPermission\"\n | \"submitPermissionRevoke\"\n | \"submitTrustServer\"\n | \"submitAddAndTrustServer\"\n | \"submitUntrustServer\"\n | \"submitAddServerFilesAndPermissions\"\n | \"submitRegisterGrantee\";\n\n/**\n * Represents direct server operations that don't require blockchain signatures.\n *\n * @remarks\n * Direct requests handle auxiliary operations like file uploads and grant storage.\n * These operations may still result in blockchain transactions but don't require\n * user signatures for gasless submission.\n *\n * @category Relayer\n */\nexport type DirectRelayerRequest =\n | {\n type: \"direct\";\n operation: \"submitFileAddition\";\n params: {\n url: string;\n userAddress: Address;\n };\n }\n | {\n type: \"direct\";\n operation: \"submitFileAdditionWithPermissions\";\n params: {\n url: string;\n userAddress: Address;\n permissions: Array<{ account: Address; key: string }>;\n };\n }\n | {\n type: \"direct\";\n operation: \"submitFileAdditionComplete\";\n params: {\n url: string;\n userAddress: Address;\n permissions: Array<{ account: Address; key: string }>;\n schemaId: number;\n ownerAddress?: Address;\n };\n }\n | {\n type: \"direct\";\n operation: \"storeGrantFile\";\n params: GrantFile;\n };\n\n/**\n * Provides type-safe responses for all relayer operations.\n *\n * @remarks\n * The discriminated union ensures proper error handling and result typing.\n * Check the `type` field to determine success or failure before accessing results.\n *\n * @category Relayer\n */\nexport type UnifiedRelayerResponse =\n | {\n type: \"signed\";\n hash: Hash;\n }\n | {\n type: \"direct\";\n result: { fileId: number; transactionHash: Hash } | { url: string } | any;\n }\n | {\n type: \"error\";\n error: string;\n };\n\n/**\n * Simplified relayer configuration.\n * Can be a URL string for convenience, or a callback for full control.\n *\n * @category Configuration\n * @example\n * ```typescript\n * // Option 1: Simple URL (SDK handles the transport)\n * const vana = Vana({\n * walletClient,\n * relayer: '/api/relay'\n * });\n *\n * // Option 2: Full control with callback\n * const vana = Vana({\n * walletClient,\n * relayer: async (request) => {\n * const response = await fetch('/api/relay', {\n * method: 'POST',\n * body: JSON.stringify(request)\n * });\n * return response.json();\n * }\n * });\n * ```\n */\nexport type RelayerConfig =\n | string\n | ((request: UnifiedRelayerRequest) => Promise<UnifiedRelayerResponse>);\n\n/**\n * Simplified relayer callbacks interface (v2).\n * A single callback handles all relayer operations.\n *\n * @category Configuration\n * @example\n * ```typescript\n * const relayerCallbacks: RelayerCallbacksV2 = {\n * submit: async (request) => {\n * // Send to your server endpoint\n * const response = await fetch('/api/relay', {\n * method: 'POST',\n * headers: { 'Content-Type': 'application/json' },\n * body: JSON.stringify(request)\n * });\n * return response.json();\n * }\n * };\n * ```\n */\nexport interface RelayerCallbacksV2 {\n /**\n * Submits any relayer operation to the server.\n *\n * @remarks\n * This single callback handles all operations:\n * - EIP-712 signed operations (permissions, server trust, etc.)\n * - Direct operations (file additions, grant storage)\n *\n * On your server, pass the entire request object to the SDK's\n * `handleRelayerOperation` helper function.\n *\n * @param request - The unified request object.\n * Check `type` field to determine operation variant.\n * @returns Promise resolving to operation-specific response\n *\n * @example\n * ```typescript\n * async submit(request) {\n * const response = await fetch('/api/relay', {\n * method: 'POST',\n * body: JSON.stringify(request)\n * });\n * return response.json();\n * }\n * ```\n */\n submit: (request: UnifiedRelayerRequest) => Promise<UnifiedRelayerResponse>;\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -1,7 +1,22 @@
1
- import type { Hash } from "viem";
2
- import type { GrantFile, PermissionGrantTypedData } from "./permissions";
3
1
  /**
4
- * Response from the relayer service for grant file storage
2
+ * Defines types for gasless transaction relayers and server operations.
3
+ *
4
+ * @remarks
5
+ * This module provides comprehensive type definitions for interacting with
6
+ * relayer services that enable gasless transactions and auxiliary operations.
7
+ * It includes both legacy v1 types and the simplified v2 unified interface.
8
+ *
9
+ * @category Types
10
+ * @module types/relayer
11
+ */
12
+ import type { Hash, Address } from "viem";
13
+ import type { GrantFile, PermissionGrantTypedData, GenericTypedData } from "./permissions";
14
+ /**
15
+ * Represents the response from storing grant files via relayer.
16
+ *
17
+ * @remarks
18
+ * Contains storage location, metadata, and error information for
19
+ * grant file upload operations.
5
20
  *
6
21
  * @category Advanced
7
22
  */
@@ -23,7 +38,11 @@ export interface RelayerStorageResponse {
23
38
  };
24
39
  }
25
40
  /**
26
- * Response from the relayer service for transaction submission
41
+ * Represents the response from submitting transactions via relayer.
42
+ *
43
+ * @remarks
44
+ * Contains transaction hash, status, and metadata for gasless
45
+ * transaction submissions.
27
46
  *
28
47
  * @category Advanced
29
48
  */
@@ -47,7 +66,11 @@ export interface RelayerTransactionResponse {
47
66
  };
48
67
  }
49
68
  /**
50
- * Parameters for storing a grant file via relayer
69
+ * Specifies parameters for storing grant files via relayer.
70
+ *
71
+ * @remarks
72
+ * Includes the grant file and optional storage configuration
73
+ * such as encryption and pinning duration.
51
74
  *
52
75
  * @category Advanced
53
76
  */
@@ -65,7 +88,11 @@ export interface RelayerStoreParams {
65
88
  };
66
89
  }
67
90
  /**
68
- * Parameters for submitting a transaction via relayer
91
+ * Specifies parameters for submitting gasless transactions.
92
+ *
93
+ * @remarks
94
+ * Contains signed typed data and transaction configuration options
95
+ * for relayer submission.
69
96
  *
70
97
  * @category Advanced
71
98
  */
@@ -85,7 +112,11 @@ export interface RelayerSubmitParams {
85
112
  };
86
113
  }
87
114
  /**
88
- * Relayer service status
115
+ * Represents the current status and capabilities of a relayer service.
116
+ *
117
+ * @remarks
118
+ * Provides information about supported chains, rate limits, and
119
+ * current operational status for monitoring and decision-making.
89
120
  *
90
121
  * @category Advanced
91
122
  */
@@ -118,29 +149,11 @@ export interface RelayerStatus {
118
149
  };
119
150
  }
120
151
  /**
121
- * Relayer configuration
152
+ * Configures behavior for relayer requests.
122
153
  *
123
- * @category Advanced
124
- */
125
- export interface RelayerConfig {
126
- /** Relayer service URL */
127
- url: string;
128
- /** API key for authentication */
129
- apiKey?: string;
130
- /** Timeout for requests in milliseconds */
131
- timeout?: number;
132
- /** Retry configuration */
133
- retry?: {
134
- /** Number of retry attempts */
135
- attempts: number;
136
- /** Delay between retries in milliseconds */
137
- delay: number;
138
- };
139
- /** Whether to use HTTPS */
140
- useHttps?: boolean;
141
- }
142
- /**
143
- * Relayer request options
154
+ * @remarks
155
+ * Controls timeout, retry logic, headers, and priority for
156
+ * relayer operation requests.
144
157
  *
145
158
  * @category Advanced
146
159
  */
@@ -155,7 +168,11 @@ export interface RelayerRequestOptions {
155
168
  priority?: "low" | "medium" | "high";
156
169
  }
157
170
  /**
158
- * Relayer error response
171
+ * Represents an error response from the relayer service.
172
+ *
173
+ * @remarks
174
+ * Provides structured error information including codes, messages,
175
+ * and debugging details for error handling and recovery.
159
176
  *
160
177
  * @category Advanced
161
178
  */
@@ -172,7 +189,11 @@ export interface RelayerErrorResponse {
172
189
  timestamp: number;
173
190
  }
174
191
  /**
175
- * Relayer queue information
192
+ * Provides information about the relayer's processing queue.
193
+ *
194
+ * @remarks
195
+ * Includes queue size, position, estimated processing time, and
196
+ * performance statistics for queue monitoring.
176
197
  *
177
198
  * @category Advanced
178
199
  */
@@ -194,7 +215,11 @@ export interface RelayerQueueInfo {
194
215
  };
195
216
  }
196
217
  /**
197
- * Relayer transaction status
218
+ * Tracks the status of a transaction submitted via relayer.
219
+ *
220
+ * @remarks
221
+ * Provides detailed tracking information including confirmation status,
222
+ * gas usage, and historical status checks.
198
223
  *
199
224
  * @category Advanced
200
225
  */
@@ -220,7 +245,11 @@ export interface RelayerTransactionStatus {
220
245
  }>;
221
246
  }
222
247
  /**
223
- * Relayer metrics
248
+ * Provides performance metrics for the relayer service.
249
+ *
250
+ * @remarks
251
+ * Includes transaction statistics, success rates, processing times,
252
+ * and uptime information for monitoring and optimization.
224
253
  *
225
254
  * @category Advanced
226
255
  */
@@ -248,7 +277,11 @@ export interface RelayerMetrics {
248
277
  };
249
278
  }
250
279
  /**
251
- * Relayer webhook configuration
280
+ * Configures webhook notifications for relayer events.
281
+ *
282
+ * @remarks
283
+ * Enables asynchronous notifications for transaction confirmations,
284
+ * failures, and storage completions.
252
285
  *
253
286
  * @category Advanced
254
287
  */
@@ -263,7 +296,11 @@ export interface RelayerWebhookConfig {
263
296
  active: boolean;
264
297
  }
265
298
  /**
266
- * Relayer webhook payload
299
+ * Represents a webhook event payload from the relayer.
300
+ *
301
+ * @remarks
302
+ * Contains event data, timestamp, and signature for verification
303
+ * of webhook authenticity.
267
304
  *
268
305
  * @category Advanced
269
306
  */
@@ -279,3 +316,193 @@ export interface RelayerWebhookPayload {
279
316
  /** Signature for verification */
280
317
  signature: string;
281
318
  }
319
+ /**
320
+ * Handles both EIP-712 signed operations and direct server operations through a single interface.
321
+ *
322
+ * @remarks
323
+ * This discriminated union provides type safety through TypeScript's narrowing.
324
+ * The `type` field determines which operation variant is being used.
325
+ * Signed operations require blockchain transactions, while direct operations
326
+ * handle auxiliary tasks like file storage.
327
+ *
328
+ * @category Relayer
329
+ * @see {@link https://docs.vana.org/docs/gasless-transactions | Gasless Transactions Guide}
330
+ */
331
+ export type UnifiedRelayerRequest = SignedRelayerRequest | DirectRelayerRequest;
332
+ /**
333
+ * Represents an EIP-712 signed operation for gasless transaction submission.
334
+ *
335
+ * @remarks
336
+ * Signed requests contain typed data and signatures that are verified
337
+ * on-chain by smart contracts. The relayer pays gas fees on behalf of users.
338
+ *
339
+ * @category Relayer
340
+ */
341
+ export interface SignedRelayerRequest {
342
+ /** Discriminator field identifying this as a signed operation */
343
+ type: "signed";
344
+ /** Operation identifier for routing (e.g., 'submitAddPermission') */
345
+ operation: SignedOperationType;
346
+ /** EIP-712 typed data structure for the operation */
347
+ typedData: GenericTypedData;
348
+ /** User's signature of the typed data */
349
+ signature: Hash;
350
+ /** Optional address for additional signer verification */
351
+ expectedUserAddress?: Address;
352
+ }
353
+ /**
354
+ * Enumerates supported EIP-712 signed operation types.
355
+ *
356
+ * @remarks
357
+ * Each operation type corresponds to a specific smart contract
358
+ * function that accepts gasless transactions.
359
+ *
360
+ * @category Relayer
361
+ */
362
+ export type SignedOperationType = "submitAddPermission" | "submitPermissionRevoke" | "submitTrustServer" | "submitAddAndTrustServer" | "submitUntrustServer" | "submitAddServerFilesAndPermissions" | "submitRegisterGrantee";
363
+ /**
364
+ * Represents direct server operations that don't require blockchain signatures.
365
+ *
366
+ * @remarks
367
+ * Direct requests handle auxiliary operations like file uploads and grant storage.
368
+ * These operations may still result in blockchain transactions but don't require
369
+ * user signatures for gasless submission.
370
+ *
371
+ * @category Relayer
372
+ */
373
+ export type DirectRelayerRequest = {
374
+ type: "direct";
375
+ operation: "submitFileAddition";
376
+ params: {
377
+ url: string;
378
+ userAddress: Address;
379
+ };
380
+ } | {
381
+ type: "direct";
382
+ operation: "submitFileAdditionWithPermissions";
383
+ params: {
384
+ url: string;
385
+ userAddress: Address;
386
+ permissions: Array<{
387
+ account: Address;
388
+ key: string;
389
+ }>;
390
+ };
391
+ } | {
392
+ type: "direct";
393
+ operation: "submitFileAdditionComplete";
394
+ params: {
395
+ url: string;
396
+ userAddress: Address;
397
+ permissions: Array<{
398
+ account: Address;
399
+ key: string;
400
+ }>;
401
+ schemaId: number;
402
+ ownerAddress?: Address;
403
+ };
404
+ } | {
405
+ type: "direct";
406
+ operation: "storeGrantFile";
407
+ params: GrantFile;
408
+ };
409
+ /**
410
+ * Provides type-safe responses for all relayer operations.
411
+ *
412
+ * @remarks
413
+ * The discriminated union ensures proper error handling and result typing.
414
+ * Check the `type` field to determine success or failure before accessing results.
415
+ *
416
+ * @category Relayer
417
+ */
418
+ export type UnifiedRelayerResponse = {
419
+ type: "signed";
420
+ hash: Hash;
421
+ } | {
422
+ type: "direct";
423
+ result: {
424
+ fileId: number;
425
+ transactionHash: Hash;
426
+ } | {
427
+ url: string;
428
+ } | any;
429
+ } | {
430
+ type: "error";
431
+ error: string;
432
+ };
433
+ /**
434
+ * Simplified relayer configuration.
435
+ * Can be a URL string for convenience, or a callback for full control.
436
+ *
437
+ * @category Configuration
438
+ * @example
439
+ * ```typescript
440
+ * // Option 1: Simple URL (SDK handles the transport)
441
+ * const vana = Vana({
442
+ * walletClient,
443
+ * relayer: '/api/relay'
444
+ * });
445
+ *
446
+ * // Option 2: Full control with callback
447
+ * const vana = Vana({
448
+ * walletClient,
449
+ * relayer: async (request) => {
450
+ * const response = await fetch('/api/relay', {
451
+ * method: 'POST',
452
+ * body: JSON.stringify(request)
453
+ * });
454
+ * return response.json();
455
+ * }
456
+ * });
457
+ * ```
458
+ */
459
+ export type RelayerConfig = string | ((request: UnifiedRelayerRequest) => Promise<UnifiedRelayerResponse>);
460
+ /**
461
+ * Simplified relayer callbacks interface (v2).
462
+ * A single callback handles all relayer operations.
463
+ *
464
+ * @category Configuration
465
+ * @example
466
+ * ```typescript
467
+ * const relayerCallbacks: RelayerCallbacksV2 = {
468
+ * submit: async (request) => {
469
+ * // Send to your server endpoint
470
+ * const response = await fetch('/api/relay', {
471
+ * method: 'POST',
472
+ * headers: { 'Content-Type': 'application/json' },
473
+ * body: JSON.stringify(request)
474
+ * });
475
+ * return response.json();
476
+ * }
477
+ * };
478
+ * ```
479
+ */
480
+ export interface RelayerCallbacksV2 {
481
+ /**
482
+ * Submits any relayer operation to the server.
483
+ *
484
+ * @remarks
485
+ * This single callback handles all operations:
486
+ * - EIP-712 signed operations (permissions, server trust, etc.)
487
+ * - Direct operations (file additions, grant storage)
488
+ *
489
+ * On your server, pass the entire request object to the SDK's
490
+ * `handleRelayerOperation` helper function.
491
+ *
492
+ * @param request - The unified request object.
493
+ * Check `type` field to determine operation variant.
494
+ * @returns Promise resolving to operation-specific response
495
+ *
496
+ * @example
497
+ * ```typescript
498
+ * async submit(request) {
499
+ * const response = await fetch('/api/relay', {
500
+ * method: 'POST',
501
+ * body: JSON.stringify(request)
502
+ * });
503
+ * return response.json();
504
+ * }
505
+ * ```
506
+ */
507
+ submit: (request: UnifiedRelayerRequest) => Promise<UnifiedRelayerResponse>;
508
+ }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/types/storage.ts"],"sourcesContent":["/**\n * Interface for storage providers that handle file upload, download, and management operations.\n *\n * Storage providers abstract different storage backends (IPFS, Google Drive, Pinata, etc.)\n * behind a common interface. The SDK uses these providers to store encrypted user data\n * and permission grants in a decentralized manner.\n *\n * @category Storage\n * @example\n * ```typescript\n * // Implement a custom storage provider\n * class MyStorageProvider implements StorageProvider {\n * async upload(file: Blob, filename?: string): Promise<StorageUploadResult> {\n * // Custom upload logic\n * return { url: 'https://my-storage.com/file.dat', size: file.size };\n * }\n *\n * async download(url: string): Promise<Blob> {\n * // Custom download logic\n * const response = await fetch(url);\n * return response.blob();\n * }\n *\n * async list(options?: StorageListOptions): Promise<StorageFile[]> {\n * // Return list of files\n * return [];\n * }\n *\n * async delete(url: string): Promise<void> {\n * // Delete file implementation\n * }\n * }\n * ```\n */\nexport interface StorageProvider {\n /**\n * Upload a file to the storage provider\n *\n * @param file - The file to upload\n * @param filename - Optional custom filename\n * @returns Promise with storage URL and metadata\n */\n upload(file: Blob, filename?: string): Promise<StorageUploadResult>;\n\n /**\n * Download a file from the storage provider\n *\n * @param url - The storage URL\n * @returns Promise with file blob\n */\n download(url: string): Promise<Blob>;\n\n /**\n * List files from the storage provider\n *\n * @param options - Optional filtering and pagination\n * @returns Promise with file list\n */\n list(options?: StorageListOptions): Promise<StorageFile[]>;\n\n /**\n * Delete a file from the storage provider\n *\n * @param url - The storage URL\n * @returns Promise with success status\n */\n delete(url: string): Promise<boolean>;\n\n /**\n * Get provider-specific configuration\n *\n * @returns Provider configuration object\n */\n getConfig(): StorageProviderConfig;\n}\n\nexport interface StorageUploadResult {\n /** Public URL to access the file */\n url: string;\n /** File size in bytes */\n size: number;\n /** Content type/MIME type */\n contentType: string;\n /** Provider-specific metadata */\n metadata?: Record<string, unknown>;\n}\n\nexport interface StorageFile {\n /** File identifier */\n id: string;\n /** File name */\n name: string;\n /** Public URL to access the file */\n url: string;\n /** File size in bytes */\n size: number;\n /** Content type/MIME type */\n contentType: string;\n /** Upload timestamp */\n createdAt: Date;\n /** Provider-specific metadata */\n metadata?: Record<string, unknown>;\n}\n\nexport interface StorageListOptions {\n /** Maximum number of files to return */\n limit?: number;\n /** Pagination cursor/offset */\n offset?: string | number;\n /** Filter by file name pattern */\n namePattern?: string;\n /** Filter by content type */\n contentType?: string;\n}\n\nexport interface StorageProviderConfig {\n /** Provider name */\n name: string;\n /** Provider type */\n type: string;\n /** Whether authentication is required */\n requiresAuth: boolean;\n /** Supported features */\n features: {\n upload: boolean;\n download: boolean;\n list: boolean;\n delete: boolean;\n };\n}\n\nexport class StorageError extends Error {\n public readonly code: string;\n public readonly provider: string;\n // The 'cause' property is now inherited from the base Error class\n\n constructor(\n message: string,\n code: string,\n provider: string,\n options?: { cause?: Error },\n ) {\n // Pass the options object with 'cause' to the super constructor\n super(message, options);\n this.name = \"StorageError\";\n this.code = code;\n this.provider = provider;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAmIO,MAAM,qBAAqB,MAAM;AAAA,EACtB;AAAA,EACA;AAAA;AAAA,EAGhB,YACE,SACA,MACA,UACA,SACA;AAEA,UAAM,SAAS,OAAO;AACtB,SAAK,OAAO;AACZ,SAAK,OAAO;AACZ,SAAK,WAAW;AAAA,EAClB;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/types/storage.ts"],"sourcesContent":["/**\n * Defines interface for storage provider implementations.\n *\n * @remarks\n * Abstracts storage backends (IPFS, Google Drive, Pinata) behind\n * common interface for encrypted file operations.\n *\n * @category Storage\n * @example\n * ```typescript\n * class MyStorage implements StorageProvider {\n * async upload(file: Blob): Promise<StorageUploadResult> {\n * const url = await uploadToService(file);\n * return { url, size: file.size, contentType: file.type };\n * }\n *\n * async download(url: string): Promise<Blob> {\n * return fetch(url).then(r => r.blob());\n * }\n * }\n * ```\n */\nexport interface StorageProvider {\n /**\n * Upload a file to the storage provider\n *\n * @param file - The file to upload\n * @param filename - Optional custom filename\n * @returns Promise with storage URL and metadata\n */\n upload(file: Blob, filename?: string): Promise<StorageUploadResult>;\n\n /**\n * Download a file from the storage provider\n *\n * @param url - The storage URL\n * @returns Promise with file blob\n */\n download(url: string): Promise<Blob>;\n\n /**\n * List files from the storage provider\n *\n * @param options - Optional filtering and pagination\n * @returns Promise with file list\n */\n list(options?: StorageListOptions): Promise<StorageFile[]>;\n\n /**\n * Delete a file from the storage provider\n *\n * @param url - The storage URL\n * @returns Promise with success status\n */\n delete(url: string): Promise<boolean>;\n\n /**\n * Get provider-specific configuration\n *\n * @returns Provider configuration object\n */\n getConfig(): StorageProviderConfig;\n}\n\nexport interface StorageUploadResult {\n /** Public URL to access the file */\n url: string;\n /** File size in bytes */\n size: number;\n /** Content type/MIME type */\n contentType: string;\n /** Provider-specific metadata */\n metadata?: Record<string, unknown>;\n}\n\nexport interface StorageFile {\n /** File identifier */\n id: string;\n /** File name */\n name: string;\n /** Public URL to access the file */\n url: string;\n /** File size in bytes */\n size: number;\n /** Content type/MIME type */\n contentType: string;\n /** Upload timestamp */\n createdAt: Date;\n /** Provider-specific metadata */\n metadata?: Record<string, unknown>;\n}\n\nexport interface StorageListOptions {\n /** Maximum number of files to return */\n limit?: number;\n /** Pagination cursor/offset */\n offset?: string | number;\n /** Filter by file name pattern */\n namePattern?: string;\n /** Filter by content type */\n contentType?: string;\n}\n\nexport interface StorageProviderConfig {\n /** Provider name */\n name: string;\n /** Provider type */\n type: string;\n /** Whether authentication is required */\n requiresAuth: boolean;\n /** Supported features */\n features: {\n upload: boolean;\n download: boolean;\n list: boolean;\n delete: boolean;\n };\n}\n\nexport class StorageError extends Error {\n public readonly code: string;\n public readonly provider: string;\n // The 'cause' property is now inherited from the base Error class\n\n constructor(\n message: string,\n code: string,\n provider: string,\n options?: { cause?: Error },\n ) {\n // Pass the options object with 'cause' to the super constructor\n super(message, options);\n this.name = \"StorageError\";\n this.code = code;\n this.provider = provider;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAuHO,MAAM,qBAAqB,MAAM;AAAA,EACtB;AAAA,EACA;AAAA;AAAA,EAGhB,YACE,SACA,MACA,UACA,SACA;AAEA,UAAM,SAAS,OAAO;AACtB,SAAK,OAAO;AACZ,SAAK,OAAO;AACZ,SAAK,WAAW;AAAA,EAClB;AACF;","names":[]}
@@ -1,33 +1,21 @@
1
1
  /**
2
- * Interface for storage providers that handle file upload, download, and management operations.
2
+ * Defines interface for storage provider implementations.
3
3
  *
4
- * Storage providers abstract different storage backends (IPFS, Google Drive, Pinata, etc.)
5
- * behind a common interface. The SDK uses these providers to store encrypted user data
6
- * and permission grants in a decentralized manner.
4
+ * @remarks
5
+ * Abstracts storage backends (IPFS, Google Drive, Pinata) behind
6
+ * common interface for encrypted file operations.
7
7
  *
8
8
  * @category Storage
9
9
  * @example
10
10
  * ```typescript
11
- * // Implement a custom storage provider
12
- * class MyStorageProvider implements StorageProvider {
13
- * async upload(file: Blob, filename?: string): Promise<StorageUploadResult> {
14
- * // Custom upload logic
15
- * return { url: 'https://my-storage.com/file.dat', size: file.size };
11
+ * class MyStorage implements StorageProvider {
12
+ * async upload(file: Blob): Promise<StorageUploadResult> {
13
+ * const url = await uploadToService(file);
14
+ * return { url, size: file.size, contentType: file.type };
16
15
  * }
17
16
  *
18
17
  * async download(url: string): Promise<Blob> {
19
- * // Custom download logic
20
- * const response = await fetch(url);
21
- * return response.blob();
22
- * }
23
- *
24
- * async list(options?: StorageListOptions): Promise<StorageFile[]> {
25
- * // Return list of files
26
- * return [];
27
- * }
28
- *
29
- * async delete(url: string): Promise<void> {
30
- * // Delete file implementation
18
+ * return fetch(url).then(r => r.blob());
31
19
  * }
32
20
  * }
33
21
  * ```
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/types/storage.ts"],"sourcesContent":["/**\n * Interface for storage providers that handle file upload, download, and management operations.\n *\n * Storage providers abstract different storage backends (IPFS, Google Drive, Pinata, etc.)\n * behind a common interface. The SDK uses these providers to store encrypted user data\n * and permission grants in a decentralized manner.\n *\n * @category Storage\n * @example\n * ```typescript\n * // Implement a custom storage provider\n * class MyStorageProvider implements StorageProvider {\n * async upload(file: Blob, filename?: string): Promise<StorageUploadResult> {\n * // Custom upload logic\n * return { url: 'https://my-storage.com/file.dat', size: file.size };\n * }\n *\n * async download(url: string): Promise<Blob> {\n * // Custom download logic\n * const response = await fetch(url);\n * return response.blob();\n * }\n *\n * async list(options?: StorageListOptions): Promise<StorageFile[]> {\n * // Return list of files\n * return [];\n * }\n *\n * async delete(url: string): Promise<void> {\n * // Delete file implementation\n * }\n * }\n * ```\n */\nexport interface StorageProvider {\n /**\n * Upload a file to the storage provider\n *\n * @param file - The file to upload\n * @param filename - Optional custom filename\n * @returns Promise with storage URL and metadata\n */\n upload(file: Blob, filename?: string): Promise<StorageUploadResult>;\n\n /**\n * Download a file from the storage provider\n *\n * @param url - The storage URL\n * @returns Promise with file blob\n */\n download(url: string): Promise<Blob>;\n\n /**\n * List files from the storage provider\n *\n * @param options - Optional filtering and pagination\n * @returns Promise with file list\n */\n list(options?: StorageListOptions): Promise<StorageFile[]>;\n\n /**\n * Delete a file from the storage provider\n *\n * @param url - The storage URL\n * @returns Promise with success status\n */\n delete(url: string): Promise<boolean>;\n\n /**\n * Get provider-specific configuration\n *\n * @returns Provider configuration object\n */\n getConfig(): StorageProviderConfig;\n}\n\nexport interface StorageUploadResult {\n /** Public URL to access the file */\n url: string;\n /** File size in bytes */\n size: number;\n /** Content type/MIME type */\n contentType: string;\n /** Provider-specific metadata */\n metadata?: Record<string, unknown>;\n}\n\nexport interface StorageFile {\n /** File identifier */\n id: string;\n /** File name */\n name: string;\n /** Public URL to access the file */\n url: string;\n /** File size in bytes */\n size: number;\n /** Content type/MIME type */\n contentType: string;\n /** Upload timestamp */\n createdAt: Date;\n /** Provider-specific metadata */\n metadata?: Record<string, unknown>;\n}\n\nexport interface StorageListOptions {\n /** Maximum number of files to return */\n limit?: number;\n /** Pagination cursor/offset */\n offset?: string | number;\n /** Filter by file name pattern */\n namePattern?: string;\n /** Filter by content type */\n contentType?: string;\n}\n\nexport interface StorageProviderConfig {\n /** Provider name */\n name: string;\n /** Provider type */\n type: string;\n /** Whether authentication is required */\n requiresAuth: boolean;\n /** Supported features */\n features: {\n upload: boolean;\n download: boolean;\n list: boolean;\n delete: boolean;\n };\n}\n\nexport class StorageError extends Error {\n public readonly code: string;\n public readonly provider: string;\n // The 'cause' property is now inherited from the base Error class\n\n constructor(\n message: string,\n code: string,\n provider: string,\n options?: { cause?: Error },\n ) {\n // Pass the options object with 'cause' to the super constructor\n super(message, options);\n this.name = \"StorageError\";\n this.code = code;\n this.provider = provider;\n }\n}\n"],"mappings":"AAmIO,MAAM,qBAAqB,MAAM;AAAA,EACtB;AAAA,EACA;AAAA;AAAA,EAGhB,YACE,SACA,MACA,UACA,SACA;AAEA,UAAM,SAAS,OAAO;AACtB,SAAK,OAAO;AACZ,SAAK,OAAO;AACZ,SAAK,WAAW;AAAA,EAClB;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/types/storage.ts"],"sourcesContent":["/**\n * Defines interface for storage provider implementations.\n *\n * @remarks\n * Abstracts storage backends (IPFS, Google Drive, Pinata) behind\n * common interface for encrypted file operations.\n *\n * @category Storage\n * @example\n * ```typescript\n * class MyStorage implements StorageProvider {\n * async upload(file: Blob): Promise<StorageUploadResult> {\n * const url = await uploadToService(file);\n * return { url, size: file.size, contentType: file.type };\n * }\n *\n * async download(url: string): Promise<Blob> {\n * return fetch(url).then(r => r.blob());\n * }\n * }\n * ```\n */\nexport interface StorageProvider {\n /**\n * Upload a file to the storage provider\n *\n * @param file - The file to upload\n * @param filename - Optional custom filename\n * @returns Promise with storage URL and metadata\n */\n upload(file: Blob, filename?: string): Promise<StorageUploadResult>;\n\n /**\n * Download a file from the storage provider\n *\n * @param url - The storage URL\n * @returns Promise with file blob\n */\n download(url: string): Promise<Blob>;\n\n /**\n * List files from the storage provider\n *\n * @param options - Optional filtering and pagination\n * @returns Promise with file list\n */\n list(options?: StorageListOptions): Promise<StorageFile[]>;\n\n /**\n * Delete a file from the storage provider\n *\n * @param url - The storage URL\n * @returns Promise with success status\n */\n delete(url: string): Promise<boolean>;\n\n /**\n * Get provider-specific configuration\n *\n * @returns Provider configuration object\n */\n getConfig(): StorageProviderConfig;\n}\n\nexport interface StorageUploadResult {\n /** Public URL to access the file */\n url: string;\n /** File size in bytes */\n size: number;\n /** Content type/MIME type */\n contentType: string;\n /** Provider-specific metadata */\n metadata?: Record<string, unknown>;\n}\n\nexport interface StorageFile {\n /** File identifier */\n id: string;\n /** File name */\n name: string;\n /** Public URL to access the file */\n url: string;\n /** File size in bytes */\n size: number;\n /** Content type/MIME type */\n contentType: string;\n /** Upload timestamp */\n createdAt: Date;\n /** Provider-specific metadata */\n metadata?: Record<string, unknown>;\n}\n\nexport interface StorageListOptions {\n /** Maximum number of files to return */\n limit?: number;\n /** Pagination cursor/offset */\n offset?: string | number;\n /** Filter by file name pattern */\n namePattern?: string;\n /** Filter by content type */\n contentType?: string;\n}\n\nexport interface StorageProviderConfig {\n /** Provider name */\n name: string;\n /** Provider type */\n type: string;\n /** Whether authentication is required */\n requiresAuth: boolean;\n /** Supported features */\n features: {\n upload: boolean;\n download: boolean;\n list: boolean;\n delete: boolean;\n };\n}\n\nexport class StorageError extends Error {\n public readonly code: string;\n public readonly provider: string;\n // The 'cause' property is now inherited from the base Error class\n\n constructor(\n message: string,\n code: string,\n provider: string,\n options?: { cause?: Error },\n ) {\n // Pass the options object with 'cause' to the super constructor\n super(message, options);\n this.name = \"StorageError\";\n this.code = code;\n this.provider = provider;\n }\n}\n"],"mappings":"AAuHO,MAAM,qBAAqB,MAAM;AAAA,EACtB;AAAA,EACA;AAAA;AAAA,EAGhB,YACE,SACA,MACA,UACA,SACA;AAEA,UAAM,SAAS,OAAO;AACtB,SAAK,OAAO;AACZ,SAAK,OAAO;AACZ,SAAK,WAAW;AAAA,EAClB;AACF;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/grantFiles.ts"],"sourcesContent":["import { keccak256, toHex } from \"viem\";\nimport type { GrantFile, GrantPermissionParams } from \"../types/permissions\";\nimport { SerializationError, NetworkError } from \"../errors\";\n\ninterface GrantFileStorageResponse {\n success: boolean;\n error?: string;\n url?: string;\n}\n\n/**\n * Creates a grant file structure from permission parameters.\n *\n * @remarks\n * This function constructs the JSON structure that represents a permission grant\n * in the Vana protocol. The grant file contains all necessary information for\n * a grantee to perform operations on behalf of the grantor.\n *\n * @param params - The permission parameters to create the grant file from\n * @returns The constructed grant file object\n * @example\n * ```typescript\n * const grantFile = createGrantFile({\n * grantee: '0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36',\n * operation: 'llm_inference',\n * parameters: {\n * model: 'gpt-4',\n * maxTokens: 1000\n * },\n * expiresAt: Date.now() + 86400000 // 24 hours\n * });\n *\n * console.log(grantFile);\n * // {\n * // grantee: '0x742d...',\n * // operation: 'llm_inference',\n * // parameters: { model: 'gpt-4', maxTokens: 1000 },\n * // expires: 1234567890\n * // }\n * ```\n */\nexport function createGrantFile(params: GrantPermissionParams): GrantFile {\n const grantFile: GrantFile = {\n grantee: params.grantee,\n operation: params.operation,\n parameters: params.parameters,\n };\n\n // Add expiration if provided\n if (params.expiresAt) {\n grantFile.expires = params.expiresAt;\n }\n\n return grantFile;\n}\n\n/**\n * Stores a grant file in IPFS via the relayer service.\n *\n * @remarks\n * This function uploads the grant file to IPFS through the relayer's upload endpoint.\n * The returned URL can be stored on-chain as part of the permission grant, allowing\n * anyone to retrieve the detailed permission parameters later.\n *\n * @param grantFile - The grant file to store\n * @param relayerUrl - URL of the relayer service\n * @returns Promise resolving to the IPFS URL\n * @throws {NetworkError} When the upload fails or relayer is unavailable\n * @example\n * ```typescript\n * const grantFile = createGrantFile(params);\n *\n * try {\n * const ipfsUrl = await storeGrantFile(grantFile, 'https://relayer.vana.com');\n * console.log(`Grant file stored at: ${ipfsUrl}`);\n * // ipfsUrl: \"ipfs://QmHash123...\"\n * } catch (error) {\n * console.error('Failed to store grant file:', error);\n * }\n * ```\n */\nexport async function storeGrantFile(\n grantFile: GrantFile,\n relayerUrl: string,\n): Promise<string> {\n try {\n // Convert grant file to blob and use IPFS upload endpoint\n const grantFileBlob = new Blob([JSON.stringify(grantFile, null, 2)], {\n type: \"application/json\",\n });\n\n const formData = new FormData();\n formData.append(\"file\", grantFileBlob, \"grant-file.json\");\n\n const response = await fetch(`${relayerUrl}/api/ipfs/upload`, {\n method: \"POST\",\n body: formData,\n });\n\n if (!response.ok) {\n throw new NetworkError(\n `Failed to store grant file: ${response.statusText}`,\n new Error(`HTTP ${response.status}`),\n );\n }\n\n const responseData: unknown = await response.json();\n const data = responseData as GrantFileStorageResponse;\n\n if (!data.success) {\n throw new NetworkError(data.error ?? \"Failed to store grant file\");\n }\n\n if (!data.url) {\n throw new NetworkError(\"Upload succeeded but no URL was returned\");\n }\n return data.url; // The IPFS URL from the upload response\n } catch (error) {\n if (error instanceof NetworkError) {\n throw error;\n }\n throw new NetworkError(\n `Network error while storing grant file: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n error as Error,\n );\n }\n}\n\n/**\n * Retrieves detailed grant file data from IPFS or HTTP storage.\n *\n * @remarks\n * **This is Step 2 of the performant two-step permission API.**\n *\n * Use this method to resolve detailed permission data (operation, parameters, etc.)\n * for specific grants after first getting the fast on-chain data using\n * `getUserPermissionGrantsOnChain()`. This design eliminates N+1 query problems\n * by allowing selective lazy-loading of expensive off-chain data.\n *\n * **Performance**: Single network request per grant file (typically 100-500ms).\n * **Reliability**: Tries multiple IPFS gateways as fallbacks if primary URL fails.\n *\n * @param grantUrl - The grant file URL from OnChainPermissionGrant.grantUrl\n * @param _relayerUrl - URL of the relayer service (optional, unused)\n * @param downloadRelayer - Optional download relayer for proxying CORS-restricted downloads\n * @param downloadRelayer.proxyDownload - Function to proxy download requests through application server\n * @returns Promise resolving to the complete grant file with operation details\n * @throws {NetworkError} When all retrieval attempts fail\n * @throws {SerializationError} When grant file format is invalid\n * @example\n * ```typescript\n * // Step 1: Fast on-chain data (no N+1 queries)\n * const grants = await vana.permissions.getUserPermissionGrantsOnChain();\n *\n * // Step 2: Lazy-load details for specific grant when needed\n * const grantFile = await retrieveGrantFile(grants[0].grantUrl);\n *\n * console.log(`Operation: ${grantFile.operation}`);\n * console.log(`Grantee: ${grantFile.grantee}`);\n * console.log(`Parameters:`, grantFile.parameters);\n *\n * // Only fetch details for grants user actually wants to see\n * for (const grant of selectedGrants) {\n * const details = await retrieveGrantFile(grant.grantUrl);\n * displayGrantDetails(details);\n * }\n * ```\n */\nexport async function retrieveGrantFile(\n grantUrl: string,\n _relayerUrl?: string,\n downloadRelayer?: { proxyDownload: (url: string) => Promise<Blob> },\n): Promise<GrantFile> {\n try {\n // Check if the URL is a gateway URL instead of ipfs:// protocol\n if (grantUrl.startsWith(\"http\") && grantUrl.includes(\"/ipfs/\")) {\n console.warn(\n `⚠️ Grant URL uses HTTP gateway format instead of ipfs:// protocol. ` +\n `Found: ${grantUrl}. ` +\n `Consider using ipfs:// format for better protocol-agnostic storage.`,\n );\n }\n\n // Use the unified download utility\n const { universalFetch } = await import(\"./download\");\n const response = await universalFetch(grantUrl, downloadRelayer);\n\n if (!response.ok) {\n throw new NetworkError(\n `Failed to retrieve grant file: HTTP ${response.status}`,\n );\n }\n\n const text = await response.text();\n const grantFile = JSON.parse(text);\n\n if (!validateGrantFile(grantFile)) {\n throw new NetworkError(`Invalid grant file format from ${grantUrl}`);\n }\n\n return grantFile;\n } catch (error) {\n if (error instanceof NetworkError) {\n throw error;\n }\n throw new NetworkError(\n `Error retrieving grant file: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n error as Error,\n );\n }\n}\n\n/**\n * Generates a content hash for a grant file.\n * This can be used for integrity verification.\n *\n * @remarks\n * Creates a deterministic keccak256 hash of the grant file by first sorting\n * all object keys recursively to ensure consistent hashing regardless of\n * property order. This hash can be used to verify grant file integrity\n * or as a unique identifier.\n *\n * @param grantFile - The grant file to generate a hash for\n * @returns The keccak256 hash of the grant file as a hex string\n * @throws {SerializationError} When the grant file cannot be serialized\n * @example\n * ```typescript\n * const grantFile = {\n * grantee: '0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36',\n * operation: 'read',\n * parameters: { version: '1.0', mode: 'full' }\n * };\n *\n * const hash = getGrantFileHash(grantFile);\n * console.log(`Grant file hash: ${hash}`);\n * // \"0x1234567890abcdef...\"\n *\n * // Same grant file with different property order produces same hash\n * const grantFile2 = {\n * operation: 'read',\n * parameters: { mode: 'full', version: '1.0' },\n * grantee: '0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36'\n * };\n *\n * const hash2 = getGrantFileHash(grantFile2);\n * console.log(hash === hash2); // true\n * ```\n */\nexport function getGrantFileHash(grantFile: GrantFile): string {\n try {\n // Create a stable JSON representation\n const sortedFile: GrantFile = {\n grantee: grantFile.grantee,\n operation: grantFile.operation,\n parameters: sortObjectKeys(grantFile.parameters) as Record<\n string,\n unknown\n >,\n };\n\n // Add expires if present\n if (grantFile.expires !== undefined) {\n sortedFile.expires = grantFile.expires;\n }\n\n const jsonString = JSON.stringify(sortedFile);\n console.info(`Hash: ${keccak256(toHex(jsonString))}`);\n return keccak256(toHex(jsonString));\n } catch (error) {\n throw new SerializationError(\n `Failed to generate grant file hash: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n}\n\n/**\n * Recursively sorts object keys for stable serialization.\n *\n * @param obj - The object to sort keys recursively\n * @returns The object with all keys sorted recursively\n */\nfunction sortObjectKeys(obj: unknown): unknown {\n if (obj === null || typeof obj !== \"object\") {\n return obj;\n }\n\n if (Array.isArray(obj)) {\n return obj.map((item) => sortObjectKeys(item));\n }\n\n const sortedObj: Record<string, unknown> = {};\n Object.keys(obj as Record<string, unknown>)\n .sort()\n .forEach((key) => {\n sortedObj[key] = sortObjectKeys((obj as Record<string, unknown>)[key]);\n });\n\n return sortedObj;\n}\n\n/**\n * Validates that a grant file has the required structure.\n *\n * @remarks\n * Performs runtime validation to ensure data conforms to the GrantFile interface.\n * Checks for required fields (grantee, operation, parameters) and validates their\n * types and formats. This is a type guard function that enables TypeScript to\n * narrow the type when it returns true.\n *\n * @param data - The data to validate as a grant file\n * @returns True if the data is a valid grant file, false otherwise\n * @example\n * ```typescript\n * const unknownData = await fetch(url).then(r => r.json());\n *\n * if (validateGrantFile(unknownData)) {\n * // TypeScript now knows unknownData is a GrantFile\n * console.log(`Grant for operation: ${unknownData.operation}`);\n * console.log(`Grantee: ${unknownData.grantee}`);\n * } else {\n * throw new Error('Invalid grant file format');\n * }\n *\n * // Validation examples:\n * validateGrantFile({\n * grantee: '0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36',\n * operation: 'read',\n * parameters: {}\n * }); // true\n *\n * validateGrantFile({\n * grantee: 'invalid-address',\n * operation: 'read',\n * parameters: {}\n * }); // false (invalid address format)\n *\n * validateGrantFile({\n * operation: 'read',\n * parameters: {}\n * }); // false (missing grantee)\n * ```\n */\nexport function validateGrantFile(data: unknown): data is GrantFile {\n if (!data || typeof data !== \"object\") {\n return false;\n }\n\n const obj = data as Record<string, unknown>;\n\n // Validate required fields\n // Validate grantee address\n if (\n typeof obj.grantee !== \"string\" ||\n !obj.grantee.match(/^0x[a-fA-F0-9]{40}$/)\n ) {\n return false;\n }\n\n if (typeof obj.operation !== \"string\" || obj.operation.length === 0) {\n return false;\n }\n\n // Files are no longer stored in grant files - they're tracked in the contract\n\n if (!obj.parameters || typeof obj.parameters !== \"object\") {\n return false;\n }\n\n // Validate optional expires field\n if (obj.expires !== undefined) {\n if (\n typeof obj.expires !== \"number\" ||\n obj.expires < 0 ||\n !Number.isInteger(obj.expires)\n ) {\n return false;\n }\n }\n\n return true;\n}\n"],"mappings":"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","names":[]}
1
+ {"version":3,"sources":["../../src/utils/grantFiles.ts"],"sourcesContent":["import { keccak256, toHex } from \"viem\";\nimport type { GrantFile, GrantPermissionParams } from \"../types/permissions\";\nimport { SerializationError, NetworkError } from \"../errors\";\n\ninterface GrantFileStorageResponse {\n success: boolean;\n error?: string;\n url?: string;\n}\n\n/**\n * Creates grant file structure for permission storage.\n *\n * @remarks\n * Constructs JSON structure that represents a permission grant\n * in the Vana protocol. The grant file contains all necessary information\n * for a grantee to perform operations on behalf of the grantor.\n *\n * @param params - Permission parameters to create the grant file from\n * @returns Grant file object for IPFS storage\n *\n * @example\n * ```typescript\n * const grant = createGrantFile({\n * grantee: '0x742d35Cc...',\n * operation: 'llm_inference',\n * parameters: { model: 'gpt-4' },\n * expiresAt: Date.now() + 86400000 // 24 hours\n * });\n * ```\n */\nexport function createGrantFile(params: GrantPermissionParams): GrantFile {\n const grantFile: GrantFile = {\n grantee: params.grantee,\n operation: params.operation,\n parameters: params.parameters,\n };\n\n // Add expiration if provided\n if (params.expiresAt) {\n grantFile.expires = params.expiresAt;\n }\n\n return grantFile;\n}\n\n/**\n * Stores a grant file in IPFS via the relayer service.\n *\n * @remarks\n * This function uploads the grant file to IPFS through the relayer's upload endpoint.\n * The returned URL can be stored on-chain as part of the permission grant, allowing\n * anyone to retrieve the detailed permission parameters later.\n *\n * @param grantFile - The grant file to store\n * @param relayerUrl - URL of the relayer service\n * @returns Promise resolving to the IPFS URL\n * @throws {NetworkError} When the upload fails or relayer is unavailable\n * @example\n * ```typescript\n * const grantFile = createGrantFile(params);\n *\n * try {\n * const ipfsUrl = await storeGrantFile(grantFile, 'https://relayer.vana.com');\n * console.log(`Grant file stored at: ${ipfsUrl}`);\n * // ipfsUrl: \"ipfs://QmHash123...\"\n * } catch (error) {\n * console.error('Failed to store grant file:', error);\n * }\n * ```\n */\nexport async function storeGrantFile(\n grantFile: GrantFile,\n relayerUrl: string,\n): Promise<string> {\n try {\n // Convert grant file to blob and use IPFS upload endpoint\n const grantFileBlob = new Blob([JSON.stringify(grantFile, null, 2)], {\n type: \"application/json\",\n });\n\n const formData = new FormData();\n formData.append(\"file\", grantFileBlob, \"grant-file.json\");\n\n const response = await fetch(`${relayerUrl}/api/ipfs/upload`, {\n method: \"POST\",\n body: formData,\n });\n\n if (!response.ok) {\n throw new NetworkError(\n `Failed to store grant file: ${response.statusText}`,\n new Error(`HTTP ${response.status}`),\n );\n }\n\n const responseData: unknown = await response.json();\n const data = responseData as GrantFileStorageResponse;\n\n if (!data.success) {\n throw new NetworkError(data.error ?? \"Failed to store grant file\");\n }\n\n if (!data.url) {\n throw new NetworkError(\"Upload succeeded but no URL was returned\");\n }\n return data.url; // The IPFS URL from the upload response\n } catch (error) {\n if (error instanceof NetworkError) {\n throw error;\n }\n throw new NetworkError(\n `Network error while storing grant file: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n error as Error,\n );\n }\n}\n\n/**\n * Retrieves detailed grant file data from IPFS or HTTP storage.\n *\n * @remarks\n * **This is Step 2 of the performant two-step permission API.**\n *\n * Use this method to resolve detailed permission data (operation, parameters, etc.)\n * for specific grants after first getting the fast on-chain data using\n * `getUserPermissionGrantsOnChain()`. This design eliminates N+1 query problems\n * by allowing selective lazy-loading of expensive off-chain data.\n *\n * **Performance**: Single network request per grant file (typically 100-500ms).\n * **Reliability**: Tries multiple IPFS gateways as fallbacks if primary URL fails.\n *\n * @param grantUrl - The grant file URL from OnChainPermissionGrant.grantUrl\n * @param _relayerUrl - URL of the relayer service (optional, unused)\n * @param downloadRelayer - Optional download relayer for proxying CORS-restricted downloads\n * @param downloadRelayer.proxyDownload - Function to proxy download requests through application server\n * @returns Promise resolving to the complete grant file with operation details\n * @throws {NetworkError} When all retrieval attempts fail\n * @throws {SerializationError} When grant file format is invalid\n * @example\n * ```typescript\n * // Step 1: Fast on-chain data (no N+1 queries)\n * const grants = await vana.permissions.getUserPermissionGrantsOnChain();\n *\n * // Step 2: Lazy-load details for specific grant when needed\n * const grantFile = await retrieveGrantFile(grants[0].grantUrl);\n *\n * console.log(`Operation: ${grantFile.operation}`);\n * console.log(`Grantee: ${grantFile.grantee}`);\n * console.log(`Parameters:`, grantFile.parameters);\n *\n * // Only fetch details for grants user actually wants to see\n * for (const grant of selectedGrants) {\n * const details = await retrieveGrantFile(grant.grantUrl);\n * displayGrantDetails(details);\n * }\n * ```\n */\nexport async function retrieveGrantFile(\n grantUrl: string,\n _relayerUrl?: string,\n downloadRelayer?: { proxyDownload: (url: string) => Promise<Blob> },\n): Promise<GrantFile> {\n try {\n // Check if the URL is a gateway URL instead of ipfs:// protocol\n if (grantUrl.startsWith(\"http\") && grantUrl.includes(\"/ipfs/\")) {\n console.warn(\n `⚠️ Grant URL uses HTTP gateway format instead of ipfs:// protocol. ` +\n `Found: ${grantUrl}. ` +\n `Consider using ipfs:// format for better protocol-agnostic storage.`,\n );\n }\n\n // Use the unified download utility\n const { universalFetch } = await import(\"./download\");\n const response = await universalFetch(grantUrl, downloadRelayer);\n\n if (!response.ok) {\n throw new NetworkError(\n `Failed to retrieve grant file: HTTP ${response.status}`,\n );\n }\n\n const text = await response.text();\n const grantFile = JSON.parse(text);\n\n if (!validateGrantFile(grantFile)) {\n throw new NetworkError(`Invalid grant file format from ${grantUrl}`);\n }\n\n return grantFile;\n } catch (error) {\n if (error instanceof NetworkError) {\n throw error;\n }\n throw new NetworkError(\n `Error retrieving grant file: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n error as Error,\n );\n }\n}\n\n/**\n * Generates a content hash for a grant file.\n * This can be used for integrity verification.\n *\n * @remarks\n * Creates a deterministic keccak256 hash of the grant file by first sorting\n * all object keys recursively to ensure consistent hashing regardless of\n * property order. This hash can be used to verify grant file integrity\n * or as a unique identifier.\n *\n * @param grantFile - The grant file to generate a hash for\n * @returns The keccak256 hash of the grant file as a hex string\n * @throws {SerializationError} When the grant file cannot be serialized\n * @example\n * ```typescript\n * const grantFile = {\n * grantee: '0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36',\n * operation: 'read',\n * parameters: { version: '1.0', mode: 'full' }\n * };\n *\n * const hash = getGrantFileHash(grantFile);\n * console.log(`Grant file hash: ${hash}`);\n * // \"0x1234567890abcdef...\"\n *\n * // Same grant file with different property order produces same hash\n * const grantFile2 = {\n * operation: 'read',\n * parameters: { mode: 'full', version: '1.0' },\n * grantee: '0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36'\n * };\n *\n * const hash2 = getGrantFileHash(grantFile2);\n * console.log(hash === hash2); // true\n * ```\n */\nexport function getGrantFileHash(grantFile: GrantFile): string {\n try {\n // Create a stable JSON representation\n const sortedFile: GrantFile = {\n grantee: grantFile.grantee,\n operation: grantFile.operation,\n parameters: sortObjectKeys(grantFile.parameters) as Record<\n string,\n unknown\n >,\n };\n\n // Add expires if present\n if (grantFile.expires !== undefined) {\n sortedFile.expires = grantFile.expires;\n }\n\n const jsonString = JSON.stringify(sortedFile);\n console.info(`Hash: ${keccak256(toHex(jsonString))}`);\n return keccak256(toHex(jsonString));\n } catch (error) {\n throw new SerializationError(\n `Failed to generate grant file hash: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n}\n\n/**\n * Recursively sorts object keys for stable serialization.\n *\n * @param obj - The object to sort keys recursively\n * @returns The object with all keys sorted recursively\n */\nfunction sortObjectKeys(obj: unknown): unknown {\n if (obj === null || typeof obj !== \"object\") {\n return obj;\n }\n\n if (Array.isArray(obj)) {\n return obj.map((item) => sortObjectKeys(item));\n }\n\n const sortedObj: Record<string, unknown> = {};\n Object.keys(obj as Record<string, unknown>)\n .sort()\n .forEach((key) => {\n sortedObj[key] = sortObjectKeys((obj as Record<string, unknown>)[key]);\n });\n\n return sortedObj;\n}\n\n/**\n * Validates that a grant file has the required structure.\n *\n * @remarks\n * Performs runtime validation to ensure data conforms to the GrantFile interface.\n * Checks for required fields (grantee, operation, parameters) and validates their\n * types and formats. This is a type guard function that enables TypeScript to\n * narrow the type when it returns true.\n *\n * @param data - The data to validate as a grant file\n * @returns True if the data is a valid grant file, false otherwise\n * @example\n * ```typescript\n * const unknownData = await fetch(url).then(r => r.json());\n *\n * if (validateGrantFile(unknownData)) {\n * // TypeScript now knows unknownData is a GrantFile\n * console.log(`Grant for operation: ${unknownData.operation}`);\n * console.log(`Grantee: ${unknownData.grantee}`);\n * } else {\n * throw new Error('Invalid grant file format');\n * }\n *\n * // Validation examples:\n * validateGrantFile({\n * grantee: '0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36',\n * operation: 'read',\n * parameters: {}\n * }); // true\n *\n * validateGrantFile({\n * grantee: 'invalid-address',\n * operation: 'read',\n * parameters: {}\n * }); // false (invalid address format)\n *\n * validateGrantFile({\n * operation: 'read',\n * parameters: {}\n * }); // false (missing grantee)\n * ```\n */\nexport function validateGrantFile(data: unknown): data is GrantFile {\n if (!data || typeof data !== \"object\") {\n return false;\n }\n\n const obj = data as Record<string, unknown>;\n\n // Validate required fields\n // Validate grantee address\n if (\n typeof obj.grantee !== \"string\" ||\n !obj.grantee.match(/^0x[a-fA-F0-9]{40}$/)\n ) {\n return false;\n }\n\n if (typeof obj.operation !== \"string\" || obj.operation.length === 0) {\n return false;\n }\n\n // Files are no longer stored in grant files - they're tracked in the contract\n\n if (!obj.parameters || typeof obj.parameters !== \"object\") {\n return false;\n }\n\n // Validate optional expires field\n if (obj.expires !== undefined) {\n if (\n typeof obj.expires !== \"number\" ||\n obj.expires < 0 ||\n !Number.isInteger(obj.expires)\n ) {\n return false;\n }\n }\n\n return true;\n}\n"],"mappings":"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","names":[]}
@@ -1,33 +1,23 @@
1
1
  import type { GrantFile, GrantPermissionParams } from "../types/permissions";
2
2
  /**
3
- * Creates a grant file structure from permission parameters.
3
+ * Creates grant file structure for permission storage.
4
4
  *
5
5
  * @remarks
6
- * This function constructs the JSON structure that represents a permission grant
7
- * in the Vana protocol. The grant file contains all necessary information for
8
- * a grantee to perform operations on behalf of the grantor.
6
+ * Constructs JSON structure that represents a permission grant
7
+ * in the Vana protocol. The grant file contains all necessary information
8
+ * for a grantee to perform operations on behalf of the grantor.
9
+ *
10
+ * @param params - Permission parameters to create the grant file from
11
+ * @returns Grant file object for IPFS storage
9
12
  *
10
- * @param params - The permission parameters to create the grant file from
11
- * @returns The constructed grant file object
12
13
  * @example
13
14
  * ```typescript
14
- * const grantFile = createGrantFile({
15
- * grantee: '0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36',
15
+ * const grant = createGrantFile({
16
+ * grantee: '0x742d35Cc...',
16
17
  * operation: 'llm_inference',
17
- * parameters: {
18
- * model: 'gpt-4',
19
- * maxTokens: 1000
20
- * },
18
+ * parameters: { model: 'gpt-4' },
21
19
  * expiresAt: Date.now() + 86400000 // 24 hours
22
20
  * });
23
- *
24
- * console.log(grantFile);
25
- * // {
26
- * // grantee: '0x742d...',
27
- * // operation: 'llm_inference',
28
- * // parameters: { model: 'gpt-4', maxTokens: 1000 },
29
- * // expires: 1234567890
30
- * // }
31
21
  * ```
32
22
  */
33
23
  export declare function createGrantFile(params: GrantPermissionParams): GrantFile;