@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,7 +1,7 @@
1
- import type { WalletClient, PublicClient, Account, Hash, Address, Chain } from "viem";
1
+ import type { WalletClient, PublicClient, Account, Address, Chain } from "viem";
2
2
  import type { VanaChainId, VanaChain } from "./chains";
3
3
  import type { StorageProvider, StorageUploadResult, StorageListOptions } from "./storage";
4
- import type { PermissionGrantTypedData, TrustServerTypedData, UntrustServerTypedData, AddAndTrustServerTypedData, GenericTypedData, GrantFile, ServerFilesAndPermissionTypedData } from "./permissions";
4
+ import type { RelayerConfig } from "./relayer";
5
5
  /**
6
6
  * Marker interface to indicate that a Vana instance has storage configured.
7
7
  * Used for compile-time type safety to ensure storage-dependent methods
@@ -13,10 +13,12 @@ export interface StorageRequiredMarker {
13
13
  readonly __storageRequired: true;
14
14
  }
15
15
  /**
16
- * Configuration for storage providers used by the SDK.
16
+ * Configures storage providers for SDK file operations.
17
17
  *
18
- * Allows you to configure multiple storage backends (IPFS, Pinata, Google Drive, etc.)
19
- * and specify which one to use by default for file operations.
18
+ * @remarks
19
+ * Supports multiple backends with automatic fallback.
20
+ * IPFS for decentralization, Pinata for reliability,
21
+ * Google Drive for development, custom for flexibility.
20
22
  *
21
23
  * **Provider Selection:**
22
24
  * - IPFS: Decentralized, permanent storage ideal for production
@@ -30,7 +32,7 @@ export interface StorageRequiredMarker {
30
32
  * const storage: StorageConfig = {
31
33
  * providers: {
32
34
  * ipfs: new IPFSStorage({ gateway: 'https://gateway.pinata.cloud' }),
33
- * pinata: new PinataStorage({ apiKey: 'your-key', secretKey: 'your-secret' })
35
+ * pinata: new PinataStorage({ apiKey: 'key', secretKey: 'secret' })
34
36
  * },
35
37
  * defaultProvider: 'ipfs'
36
38
  * };
@@ -128,183 +130,6 @@ export interface DownloadRelayerCallbacks {
128
130
  */
129
131
  proxyDownload: (url: string) => Promise<Blob>;
130
132
  }
131
- /**
132
- * Relayer callback functions for handling gasless transactions.
133
- *
134
- * Instead of hardcoding HTTP/REST API calls, users can provide custom callback
135
- * functions to handle transaction relay in any way they choose (HTTP, WebSocket,
136
- * direct blockchain submission, etc.).
137
- *
138
- * @category Configuration
139
- * @example
140
- * ```typescript
141
- * const relayerCallbacks: RelayerCallbacks = {
142
- * async submitPermissionGrant(typedData, signature) {
143
- * // Custom implementation - could be HTTP, WebSocket, etc.
144
- * const response = await fetch('https://my-relayer.com/api/grant', {
145
- * method: 'POST',
146
- * headers: { 'Content-Type': 'application/json' },
147
- * body: JSON.stringify({ typedData, signature })
148
- * });
149
- * const result = await response.json();
150
- * return result.transactionHash;
151
- * },
152
- *
153
- * async submitFileAddition(url, userAddress) {
154
- * // Custom relay implementation
155
- * return await myCustomRelayer.addFile(url, userAddress);
156
- * }
157
- * };
158
- * ```
159
- */
160
- export interface RelayerCallbacks {
161
- /**
162
- * Submit a signed permission grant transaction for relay
163
- *
164
- * @param typedData - The EIP-712 typed data that was signed
165
- * @param signature - The user's signature
166
- * @returns Promise resolving to the transaction hash
167
- */
168
- submitPermissionGrant?: (typedData: PermissionGrantTypedData, signature: Hash) => Promise<Hash>;
169
- /**
170
- * Submit a signed permission revocation transaction for relay
171
- *
172
- * @param typedData - The EIP-712 typed data that was signed
173
- * @param signature - The user's signature
174
- * @returns Promise resolving to the transaction hash
175
- */
176
- submitPermissionRevoke?: (typedData: GenericTypedData, signature: Hash) => Promise<Hash>;
177
- /**
178
- * Submit a signed trust server transaction for relay
179
- *
180
- * @param typedData - The EIP-712 typed data that was signed
181
- * @param signature - The user's signature
182
- * @returns Promise resolving to the transaction hash
183
- */
184
- submitTrustServer?: (typedData: TrustServerTypedData, signature: Hash) => Promise<Hash>;
185
- /**
186
- * Submit a signed untrust server transaction for relay
187
- *
188
- * @param typedData - The EIP-712 typed data that was signed
189
- * @param signature - The user's signature
190
- * @returns Promise resolving to the transaction hash
191
- */
192
- submitUntrustServer?: (typedData: UntrustServerTypedData, signature: Hash) => Promise<Hash>;
193
- /**
194
- * Submit a signed add and trust server transaction for relay
195
- *
196
- * @param typedData - The EIP-712 typed data that was signed
197
- * @param signature - The user's signature
198
- * @returns Promise resolving to the transaction hash
199
- */
200
- submitAddAndTrustServer?: (typedData: AddAndTrustServerTypedData, signature: Hash) => Promise<Hash>;
201
- /**
202
- * Submit a signed permission addition transaction for relay
203
- *
204
- * @param typedData - The EIP-712 typed data that was signed
205
- * @param signature - The user's signature
206
- * @returns Promise resolving to the transaction hash
207
- */
208
- submitAddPermission?: (typedData: GenericTypedData, signature: Hash) => Promise<Hash>;
209
- /**
210
- * Submit a signed server files and permissions transaction for relay
211
- *
212
- * @param typedData - The EIP-712 typed data that was signed
213
- * @param signature - The user's signature
214
- * @returns Promise resolving to the transaction hash
215
- */
216
- submitAddServerFilesAndPermissions?: (typedData: ServerFilesAndPermissionTypedData, signature: Hash) => Promise<Hash>;
217
- /**
218
- * Submit a file addition for relay
219
- *
220
- * @deprecated Since v2.0.0 - Use submitFileAdditionComplete() instead for full support.
221
- * Will be removed in v3.0.0.
222
- *
223
- * Migration guide:
224
- * ```typescript
225
- * // Old:
226
- * await submitFileAddition(url, userAddress);
227
- *
228
- * // New:
229
- * await submitFileAdditionComplete({
230
- * url,
231
- * userAddress,
232
- * permissions: [] // Optional
233
- * });
234
- * ```
235
- * @param url - The file URL to register
236
- * @param userAddress - The user's address
237
- * @returns Promise resolving to object with fileId and transactionHash
238
- */
239
- submitFileAddition?: (url: string, userAddress: string) => Promise<{
240
- fileId: number;
241
- transactionHash: Hash;
242
- }>;
243
- /**
244
- * Submit a file addition with permissions for relay
245
- *
246
- * @deprecated Since v2.0.0 - Use submitFileAdditionComplete() instead for full support.
247
- * Will be removed in v3.0.0.
248
- *
249
- * Migration guide:
250
- * ```typescript
251
- * // Old:
252
- * await submitFileAdditionWithPermissions(url, userAddress, permissions);
253
- *
254
- * // New:
255
- * await submitFileAdditionComplete({
256
- * url,
257
- * userAddress,
258
- * permissions
259
- * });
260
- * ```
261
- * @param url - The file URL to register
262
- * @param userAddress - The user's address
263
- * @param permissions - Array of encrypted permissions
264
- * @returns Promise resolving to object with fileId and transactionHash
265
- */
266
- submitFileAdditionWithPermissions?: (url: string, userAddress: string, permissions: Array<{
267
- account: string;
268
- key: string;
269
- }>) => Promise<{
270
- fileId: number;
271
- transactionHash: Hash;
272
- }>;
273
- /**
274
- * Submit a comprehensive file addition with optional schema and permissions for relay
275
- *
276
- * This is the preferred callback that supports all file addition scenarios.
277
- * It can handle files with schemas, permissions, or both.
278
- *
279
- * @param params - Complete parameters for file addition
280
- * @param params.url - The file URL to register
281
- * @param params.userAddress - The user's address (defaults to connected wallet if not specified)
282
- * @param params.permissions - Array of encrypted permissions (empty array if none)
283
- * @param params.schemaId - Schema ID for validation (0 if none)
284
- * @param params.ownerAddress - Optional owner address (defaults to userAddress if not specified)
285
- * @returns Promise resolving to object with fileId and transactionHash
286
- */
287
- submitFileAdditionComplete?: (params: {
288
- url: string;
289
- userAddress: Address;
290
- permissions: Array<{
291
- account: Address;
292
- key: string;
293
- }>;
294
- schemaId: number;
295
- ownerAddress?: Address;
296
- }) => Promise<{
297
- fileId: number;
298
- transactionHash: Hash;
299
- }>;
300
- /**
301
- * Store a grant file for relay (e.g., upload to IPFS)
302
- *
303
- * @param grantData - The grant file data
304
- * @returns Promise resolving to the storage URL
305
- */
306
- storeGrantFile?: (grantData: GrantFile) => Promise<string>;
307
- }
308
133
  /**
309
134
  * Storage callback functions for flexible storage operations.
310
135
  *
@@ -427,10 +252,25 @@ export interface StorageListResult {
427
252
  */
428
253
  export interface BaseConfig {
429
254
  /**
430
- * Optional relayer callback functions for handling gasless transactions.
431
- * Provides flexible relay mechanism - can use HTTP, WebSocket, or any custom implementation.
255
+ * Optional relayer configuration for handling gasless transactions.
256
+ * Can be a URL string for convenience, or a callback for full control.
257
+ *
258
+ * @example
259
+ * ```typescript
260
+ * // Simple URL (SDK handles transport)
261
+ * relayer: '/api/relay'
262
+ *
263
+ * // Full control with callback
264
+ * relayer: async (request) => {
265
+ * const response = await fetch('/api/relay', {
266
+ * method: 'POST',
267
+ * body: JSON.stringify(request)
268
+ * });
269
+ * return response.json();
270
+ * }
271
+ * ```
432
272
  */
433
- relayerCallbacks?: RelayerCallbacks;
273
+ relayer?: RelayerConfig;
434
274
  /**
435
275
  * Optional download relayer for proxying CORS-restricted downloads.
436
276
  * Provides a proxy mechanism for files stored on servers with CORS restrictions.
@@ -473,10 +313,25 @@ export interface BaseConfig {
473
313
  */
474
314
  export interface BaseConfigWithStorage {
475
315
  /**
476
- * Optional relayer callback functions for handling gasless transactions.
477
- * Provides flexible relay mechanism - can use HTTP, WebSocket, or any custom implementation.
316
+ * Optional relayer configuration for handling gasless transactions.
317
+ * Can be a URL string for convenience, or a callback for full control.
318
+ *
319
+ * @example
320
+ * ```typescript
321
+ * // Simple URL (SDK handles transport)
322
+ * relayer: '/api/relay'
323
+ *
324
+ * // Full control with callback
325
+ * relayer: async (request) => {
326
+ * const response = await fetch('/api/relay', {
327
+ * method: 'POST',
328
+ * body: JSON.stringify(request)
329
+ * });
330
+ * return response.json();
331
+ * }
332
+ * ```
478
333
  */
479
- relayerCallbacks?: RelayerCallbacks;
334
+ relayer?: RelayerConfig;
480
335
  /**
481
336
  * Optional download relayer for proxying CORS-restricted downloads.
482
337
  * Provides a proxy mechanism for files stored on servers with CORS restrictions.
@@ -729,8 +584,8 @@ export interface RuntimeConfig {
729
584
  storageProviders: string[];
730
585
  /** Default storage provider */
731
586
  defaultStorageProvider?: string;
732
- /** Current relayer callbacks configuration */
733
- relayerCallbacks?: RelayerCallbacks;
587
+ /** Current relayer configuration */
588
+ relayerConfig?: RelayerConfig;
734
589
  }
735
590
  /**
736
591
  * Validates whether a configuration object has a wallet client (any wallet-based config).
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/types/config.ts"],"sourcesContent":["import type {\n WalletClient,\n PublicClient,\n Account,\n Hash,\n Address,\n Chain,\n} from \"viem\";\nimport type { VanaChainId, VanaChain } from \"./chains\";\nimport type {\n StorageProvider,\n StorageUploadResult,\n StorageListOptions,\n} from \"./storage\";\nimport type {\n PermissionGrantTypedData,\n TrustServerTypedData,\n UntrustServerTypedData,\n AddAndTrustServerTypedData,\n GenericTypedData,\n GrantFile,\n ServerFilesAndPermissionTypedData,\n} from \"./permissions\";\n\n/**\n * Marker interface to indicate that a Vana instance has storage configured.\n * Used for compile-time type safety to ensure storage-dependent methods\n * are only called on properly configured instances.\n *\n * @category Configuration\n */\nexport interface StorageRequiredMarker {\n readonly __storageRequired: true;\n}\n\n/**\n * Configuration for storage providers used by the SDK.\n *\n * Allows you to configure multiple storage backends (IPFS, Pinata, Google Drive, etc.)\n * and specify which one to use by default for file operations.\n *\n * **Provider Selection:**\n * - IPFS: Decentralized, permanent storage ideal for production\n * - Pinata: Managed IPFS with guaranteed availability\n * - Google Drive: Centralized, suitable for development/testing\n * - Custom providers: Implement StorageProvider interface\n *\n * @category Configuration\n * @example\n * ```typescript\n * const storage: StorageConfig = {\n * providers: {\n * ipfs: new IPFSStorage({ gateway: 'https://gateway.pinata.cloud' }),\n * pinata: new PinataStorage({ apiKey: 'your-key', secretKey: 'your-secret' })\n * },\n * defaultProvider: 'ipfs'\n * };\n * ```\n */\nexport interface StorageConfig {\n /**\n * Map of provider name to storage provider instance.\n * Common provider names: \"ipfs\", \"pinata\", \"googledrive\", \"s3\".\n * Custom names allowed for custom provider implementations.\n */\n providers: Record<string, StorageProvider>;\n /**\n * Default provider name to use when none specified.\n * Must match a key in the providers map. Falls back to first provider if not specified.\n */\n defaultProvider?: string;\n}\n\n/**\n * Download relayer callbacks for proxying CORS-restricted downloads.\n *\n * Provides a callback to proxy download requests through your application server\n * when direct browser access fails due to CORS restrictions (e.g., Google Drive).\n *\n * IMPORTANT SECURITY REQUIREMENTS for your proxy endpoint:\n * 1. MUST block requests to private/internal IPs (SSRF protection)\n * 2. SHOULD NOT restrict domains (files can be hosted anywhere)\n *\n * @category Configuration\n * @example Client-side implementation:\n * ```typescript\n * const downloadRelayer: DownloadRelayerCallbacks = {\n * async proxyDownload(url) {\n * const response = await fetch('/api/proxy', {\n * method: 'POST',\n * headers: { 'Content-Type': 'application/json' },\n * body: JSON.stringify({ url })\n * });\n * return response.blob();\n * }\n * };\n * ```\n *\n * @example Server-side proxy endpoint (Next.js):\n * ```typescript\n * // /api/proxy/route.ts\n * import { promises as dns } from 'dns';\n * import { isIPv4 } from 'net';\n *\n * async function handleProxy(url: string) {\n * const { hostname } = new URL(url);\n *\n * // Resolve hostname to IP (handle localhost specially)\n * const ip = hostname === 'localhost' ? '127.0.0.1' :\n * isIPv4(hostname) ? hostname :\n * await dns.lookup(hostname).then(r => r.address);\n *\n * // SSRF Protection: Block private/internal IPs\n * if (isIPv4(ip)) {\n * const [a, b] = ip.split('.').map(Number);\n * if (a === 10 || a === 127 || a === 0 ||\n * (a === 172 && b >= 16 && b <= 31) ||\n * (a === 192 && b === 168) ||\n * (a === 169 && b === 254) ||\n * a >= 224) { // Also block multicast/reserved\n * return new Response('Private/internal addresses not allowed', { status: 403 });\n * }\n * }\n *\n * // Proxy the request\n * const response = await fetch(url, { redirect: 'manual' });\n *\n * // Handle redirects (with recursion limit)\n * if (response.status >= 301 && response.status <= 308) {\n * const location = response.headers.get('location');\n * if (location) return handleProxy(new URL(location, url).href);\n * }\n *\n * const data = await response.arrayBuffer();\n * return new Response(data, {\n * headers: {\n * 'Content-Type': response.headers.get('content-type') || 'application/octet-stream',\n * 'Access-Control-Allow-Origin': '*'\n * }\n * });\n * }\n * ```\n */\nexport interface DownloadRelayerCallbacks {\n /**\n * Proxy a download request through your application server\n *\n * @param url - The URL to download from\n * @returns Promise resolving to the downloaded content as a Blob\n */\n proxyDownload: (url: string) => Promise<Blob>;\n}\n\n/**\n * Relayer callback functions for handling gasless transactions.\n *\n * Instead of hardcoding HTTP/REST API calls, users can provide custom callback\n * functions to handle transaction relay in any way they choose (HTTP, WebSocket,\n * direct blockchain submission, etc.).\n *\n * @category Configuration\n * @example\n * ```typescript\n * const relayerCallbacks: RelayerCallbacks = {\n * async submitPermissionGrant(typedData, signature) {\n * // Custom implementation - could be HTTP, WebSocket, etc.\n * const response = await fetch('https://my-relayer.com/api/grant', {\n * method: 'POST',\n * headers: { 'Content-Type': 'application/json' },\n * body: JSON.stringify({ typedData, signature })\n * });\n * const result = await response.json();\n * return result.transactionHash;\n * },\n *\n * async submitFileAddition(url, userAddress) {\n * // Custom relay implementation\n * return await myCustomRelayer.addFile(url, userAddress);\n * }\n * };\n * ```\n */\nexport interface RelayerCallbacks {\n /**\n * Submit a signed permission grant transaction for relay\n *\n * @param typedData - The EIP-712 typed data that was signed\n * @param signature - The user's signature\n * @returns Promise resolving to the transaction hash\n */\n submitPermissionGrant?: (\n typedData: PermissionGrantTypedData,\n signature: Hash,\n ) => Promise<Hash>;\n\n /**\n * Submit a signed permission revocation transaction for relay\n *\n * @param typedData - The EIP-712 typed data that was signed\n * @param signature - The user's signature\n * @returns Promise resolving to the transaction hash\n */\n submitPermissionRevoke?: (\n typedData: GenericTypedData,\n signature: Hash,\n ) => Promise<Hash>;\n\n /**\n * Submit a signed trust server transaction for relay\n *\n * @param typedData - The EIP-712 typed data that was signed\n * @param signature - The user's signature\n * @returns Promise resolving to the transaction hash\n */\n submitTrustServer?: (\n typedData: TrustServerTypedData,\n signature: Hash,\n ) => Promise<Hash>;\n\n /**\n * Submit a signed untrust server transaction for relay\n *\n * @param typedData - The EIP-712 typed data that was signed\n * @param signature - The user's signature\n * @returns Promise resolving to the transaction hash\n */\n submitUntrustServer?: (\n typedData: UntrustServerTypedData,\n signature: Hash,\n ) => Promise<Hash>;\n\n /**\n * Submit a signed add and trust server transaction for relay\n *\n * @param typedData - The EIP-712 typed data that was signed\n * @param signature - The user's signature\n * @returns Promise resolving to the transaction hash\n */\n submitAddAndTrustServer?: (\n typedData: AddAndTrustServerTypedData,\n signature: Hash,\n ) => Promise<Hash>;\n\n /**\n * Submit a signed permission addition transaction for relay\n *\n * @param typedData - The EIP-712 typed data that was signed\n * @param signature - The user's signature\n * @returns Promise resolving to the transaction hash\n */\n submitAddPermission?: (\n typedData: GenericTypedData,\n signature: Hash,\n ) => Promise<Hash>;\n\n /**\n * Submit a signed server files and permissions transaction for relay\n *\n * @param typedData - The EIP-712 typed data that was signed\n * @param signature - The user's signature\n * @returns Promise resolving to the transaction hash\n */\n submitAddServerFilesAndPermissions?: (\n typedData: ServerFilesAndPermissionTypedData,\n signature: Hash,\n ) => Promise<Hash>;\n\n /**\n * Submit a file addition for relay\n *\n * @deprecated Since v2.0.0 - Use submitFileAdditionComplete() instead for full support.\n * Will be removed in v3.0.0.\n *\n * Migration guide:\n * ```typescript\n * // Old:\n * await submitFileAddition(url, userAddress);\n *\n * // New:\n * await submitFileAdditionComplete({\n * url,\n * userAddress,\n * permissions: [] // Optional\n * });\n * ```\n * @param url - The file URL to register\n * @param userAddress - The user's address\n * @returns Promise resolving to object with fileId and transactionHash\n */\n submitFileAddition?: (\n url: string,\n userAddress: string,\n ) => Promise<{ fileId: number; transactionHash: Hash }>;\n\n /**\n * Submit a file addition with permissions for relay\n *\n * @deprecated Since v2.0.0 - Use submitFileAdditionComplete() instead for full support.\n * Will be removed in v3.0.0.\n *\n * Migration guide:\n * ```typescript\n * // Old:\n * await submitFileAdditionWithPermissions(url, userAddress, permissions);\n *\n * // New:\n * await submitFileAdditionComplete({\n * url,\n * userAddress,\n * permissions\n * });\n * ```\n * @param url - The file URL to register\n * @param userAddress - The user's address\n * @param permissions - Array of encrypted permissions\n * @returns Promise resolving to object with fileId and transactionHash\n */\n submitFileAdditionWithPermissions?: (\n url: string,\n userAddress: string,\n permissions: Array<{ account: string; key: string }>,\n ) => Promise<{ fileId: number; transactionHash: Hash }>;\n\n /**\n * Submit a comprehensive file addition with optional schema and permissions for relay\n *\n * This is the preferred callback that supports all file addition scenarios.\n * It can handle files with schemas, permissions, or both.\n *\n * @param params - Complete parameters for file addition\n * @param params.url - The file URL to register\n * @param params.userAddress - The user's address (defaults to connected wallet if not specified)\n * @param params.permissions - Array of encrypted permissions (empty array if none)\n * @param params.schemaId - Schema ID for validation (0 if none)\n * @param params.ownerAddress - Optional owner address (defaults to userAddress if not specified)\n * @returns Promise resolving to object with fileId and transactionHash\n */\n submitFileAdditionComplete?: (params: {\n url: string;\n userAddress: Address;\n permissions: Array<{ account: Address; key: string }>;\n schemaId: number;\n ownerAddress?: Address;\n }) => Promise<{ fileId: number; transactionHash: Hash }>;\n\n /**\n * Store a grant file for relay (e.g., upload to IPFS)\n *\n * @param grantData - The grant file data\n * @returns Promise resolving to the storage URL\n */\n storeGrantFile?: (grantData: GrantFile) => Promise<string>;\n}\n\n/**\n * Storage callback functions for flexible storage operations.\n *\n * Instead of hardcoding storage behavior (HTTP endpoints, etc.), users can provide\n * custom callback functions to handle storage operations in any way they choose.\n * This pattern matches the relayer callbacks approach, providing maximum flexibility.\n *\n * @category Configuration\n * @example\n * ```typescript\n * const storageCallbacks: StorageCallbacks = {\n * async upload(blob, filename, metadata) {\n * // Custom implementation - could be HTTP, S3, local filesystem, etc.\n * const formData = new FormData();\n * formData.append('file', blob, filename);\n * const response = await fetch('/api/storage/upload', {\n * method: 'POST',\n * body: formData\n * });\n * const data = await response.json();\n * return {\n * url: data.url,\n * size: blob.size,\n * contentType: blob.type,\n * metadata: data.metadata\n * };\n * },\n *\n * async download(identifier) {\n * const response = await fetch(`/api/storage/download/${identifier}`);\n * return response.blob();\n * }\n * };\n * ```\n */\nexport interface StorageCallbacks {\n /**\n * Upload a blob to storage\n *\n * @param blob - The data to upload\n * @param filename - Optional filename hint\n * @param metadata - Optional metadata for the upload\n * @returns Upload result with identifier and metadata\n */\n upload: (\n blob: Blob,\n filename?: string,\n metadata?: Record<string, unknown>,\n ) => Promise<StorageUploadResult>;\n\n /**\n * Download data from storage\n *\n * @param identifier - The storage identifier (could be URL, hash, path, or any unique ID)\n * @param options - Optional download options\n * @returns The downloaded data as a Blob\n */\n download: (\n identifier: string,\n options?: StorageDownloadOptions,\n ) => Promise<Blob>;\n\n /**\n * List stored items (optional)\n *\n * @param prefix - Optional prefix to filter results\n * @param options - Optional listing options\n * @returns Array of storage items with metadata\n */\n list?: (\n prefix?: string,\n options?: StorageListOptions,\n ) => Promise<StorageListResult>;\n\n /**\n * Delete a stored item (optional)\n *\n * @param identifier - The storage identifier to delete\n * @returns Promise that resolves to true if deletion succeeded\n */\n delete?: (identifier: string) => Promise<boolean>;\n\n /**\n * Extract identifier from a URL or return as-is (optional)\n * Used for backward compatibility with URL-based systems\n *\n * @param url - The URL to extract from\n * @returns The extracted identifier\n */\n extractIdentifier?: (url: string) => string;\n}\n\n/**\n * Options for storage download operations\n *\n * @category Configuration\n */\nexport interface StorageDownloadOptions {\n /** Optional HTTP headers */\n headers?: Record<string, string>;\n /** Optional abort signal for cancellation */\n signal?: AbortSignal;\n /** Optional byte range for partial downloads */\n range?: { start?: number; end?: number };\n}\n\n/**\n * Result from storage list operations\n *\n * @category Configuration\n */\nexport interface StorageListResult {\n /** Array of storage items */\n items: Array<{\n /** Item identifier */\n identifier: string;\n /** Item size in bytes */\n size?: number;\n /** Last modified timestamp */\n lastModified?: Date;\n /** Item metadata */\n metadata?: Record<string, unknown>;\n }>;\n /** Continuation token for pagination */\n continuationToken?: string;\n /** Whether more results are available */\n hasMore?: boolean;\n}\n\n/**\n * Base configuration interface without storage requirements\n *\n * @category Configuration\n */\nexport interface BaseConfig {\n /**\n * Optional relayer callback functions for handling gasless transactions.\n * Provides flexible relay mechanism - can use HTTP, WebSocket, or any custom implementation.\n */\n relayerCallbacks?: RelayerCallbacks;\n\n /**\n * Optional download relayer for proxying CORS-restricted downloads.\n * Provides a proxy mechanism for files stored on servers with CORS restrictions.\n */\n downloadRelayer?: DownloadRelayerCallbacks;\n\n /**\n * Optional storage providers configuration for file upload/download.\n * Required for: upload(), grant() without pre-stored URLs, schema operations.\n * See StorageConfig for provider selection guidance.\n */\n storage?: StorageConfig;\n /**\n * Optional subgraph URL for querying user files and permissions.\n * If not provided, defaults to the built-in subgraph URL for the current chain.\n * Can be overridden per method call if needed.\n * Obtain chain-specific URLs from Vana documentation or deployment info.\n */\n subgraphUrl?: string;\n /**\n * Optional default IPFS gateways to use for fetching files.\n * These gateways will be used by default in fetchFromIPFS unless overridden per-call.\n * If not provided, the SDK will use public gateways.\n * Order matters: first successful gateway is used.\n *\n * @example ['https://gateway.pinata.cloud', 'https://ipfs.io']\n */\n ipfsGateways?: string[];\n /**\n * Default personal server base URL for server operations.\n * Required for ServerController methods like getIdentity(), createOperation(), etc.\n *\n * @example 'https://my-personal-server.example.com'\n */\n defaultPersonalServerUrl?: string;\n}\n\n/**\n * Base configuration interface that requires storage for storage-dependent operations\n *\n * @category Configuration\n */\nexport interface BaseConfigWithStorage {\n /**\n * Optional relayer callback functions for handling gasless transactions.\n * Provides flexible relay mechanism - can use HTTP, WebSocket, or any custom implementation.\n */\n relayerCallbacks?: RelayerCallbacks;\n\n /**\n * Optional download relayer for proxying CORS-restricted downloads.\n * Provides a proxy mechanism for files stored on servers with CORS restrictions.\n */\n downloadRelayer?: DownloadRelayerCallbacks;\n\n /** Required storage providers configuration for file upload/download */\n storage: StorageConfig;\n /**\n * Optional subgraph URL for querying user files and permissions.\n * If not provided, defaults to the built-in subgraph URL for the current chain.\n * Can be overridden per method call if needed.\n */\n subgraphUrl?: string;\n /**\n * Optional default IPFS gateways to use for fetching files.\n * These gateways will be used by default in fetchFromIPFS unless overridden per-call.\n * If not provided, the SDK will use public gateways.\n *\n * @example ['https://gateway.pinata.cloud', 'https://ipfs.io']\n */\n ipfsGateways?: string[];\n /**\n * Default personal server base URL for server operations.\n * Required for ServerController methods like getIdentity(), createOperation(), etc.\n *\n * @example 'https://my-personal-server.example.com'\n */\n defaultPersonalServerUrl?: string;\n}\n\n/**\n * Configuration with wallet client\n *\n * @category Configuration\n */\nexport interface WalletConfig extends BaseConfig {\n /** The viem WalletClient instance used for signing transactions */\n walletClient: WalletClient & {\n chain: VanaChain;\n };\n}\n\n/**\n * Configuration with wallet client that requires storage\n *\n * @category Configuration\n */\nexport interface WalletConfigWithStorage extends BaseConfigWithStorage {\n /** The viem WalletClient instance used for signing transactions */\n walletClient: WalletClient & {\n chain: VanaChain;\n };\n}\n\n/**\n * Configuration with chain and account details\n *\n * @category Configuration\n */\nexport interface ChainConfig extends BaseConfig {\n /**\n * The chain ID for Vana network.\n * Supported: 14800 (Vana Mainnet), 14801 (Moksha Testnet), 31337 (Local Development).\n * Use chain constants from '@vana/sdk' for type safety.\n */\n chainId: VanaChainId;\n /**\n * RPC URL for the chain (optional, will use default for the chain if not provided).\n * Default URLs: mainnet (https://rpc.vana.org), testnet (https://rpc.moksha.vana.org).\n * Override for custom nodes or local development.\n */\n rpcUrl?: string;\n /**\n * Optional account for signing transactions.\n * Can be: privateKeyToAccount(), mnemonicToAccount(), or custom Account implementation.\n * Required for write operations; read-only operations work without account.\n */\n account?: Account;\n}\n\n/**\n * Configuration with chain and account details that requires storage\n *\n * @category Configuration\n */\nexport interface ChainConfigWithStorage extends BaseConfigWithStorage {\n /** The chain ID for Vana network */\n chainId: VanaChainId;\n /** RPC URL for the chain (optional, will use default for the chain if not provided) */\n rpcUrl?: string;\n /** Optional account for signing transactions */\n account?: Account;\n}\n\n/**\n * Configuration with wallet client and optional public client\n *\n * @category Configuration\n */\nexport interface VanaConfigWithWallet extends BaseConfig {\n /** The viem WalletClient instance used for signing transactions */\n walletClient: WalletClient;\n /** Optional PublicClient for read operations (derived from wallet if not provided) */\n publicClient?: PublicClient;\n}\n\n/**\n * Configuration for read-only operations with public client and address\n *\n * @category Configuration\n */\nexport interface VanaConfigReadOnly extends BaseConfig {\n /** The viem PublicClient instance for read operations */\n publicClient: PublicClient;\n /** The user's address for read operations */\n address: Address;\n}\n\n/**\n * Configuration for minimal read-only operations with just an address\n *\n * @category Configuration\n */\nexport interface VanaConfigAddressOnly extends BaseConfig {\n /** The user's address for read operations */\n address: Address;\n /** Optional chain configuration (will use default if not provided) */\n chain?: Chain;\n}\n\n/**\n * Configuration with wallet client and optional public client that requires storage\n *\n * @category Configuration\n */\nexport interface VanaConfigWithWalletWithStorage extends BaseConfigWithStorage {\n /** The viem WalletClient instance used for signing transactions */\n walletClient: WalletClient;\n /** Optional PublicClient for read operations (derived from wallet if not provided) */\n publicClient?: PublicClient;\n}\n\n/**\n * Configuration for read-only operations with public client and address that requires storage\n *\n * @category Configuration\n */\nexport interface VanaConfigReadOnlyWithStorage extends BaseConfigWithStorage {\n /** The viem PublicClient instance for read operations */\n publicClient: PublicClient;\n /** The user's address for read operations */\n address: Address;\n}\n\n/**\n * Configuration for minimal read-only operations with just an address that requires storage\n *\n * @category Configuration\n */\nexport interface VanaConfigAddressOnlyWithStorage\n extends BaseConfigWithStorage {\n /** The user's address for read operations */\n address: Address;\n /** Optional chain configuration (will use default if not provided) */\n chain?: Chain;\n}\n\n/**\n * Main configuration interface for initializing the Vana SDK.\n *\n * The SDK supports three initialization modes:\n * 1. Full mode with wallet client for signing transactions\n * 2. Read-only mode with public client and address for read operations\n * 3. Minimal mode with just an address and optional chain\n *\n * @category Configuration\n * @example\n * ```typescript\n * // Mode 1: Full configuration with wallet client\n * const configWithWallet: VanaConfig = {\n * walletClient: createWalletClient({\n * account: privateKeyToAccount('0x...'),\n * chain: moksha,\n * transport: http()\n * }),\n * publicClient: createPublicClient({\n * chain: moksha,\n * transport: http()\n * })\n * };\n *\n * // Mode 2: Read-only with public client and address\n * const configReadOnly: VanaConfig = {\n * publicClient: createPublicClient({\n * chain: moksha,\n * transport: http()\n * }),\n * address: '0x1234...'\n * };\n *\n * // Mode 3: Minimal with just address\n * const configMinimal: VanaConfig = {\n * address: '0x1234...',\n * chain: moksha // optional\n * };\n * ```\n */\nexport type VanaConfig =\n | VanaConfigWithWallet\n | VanaConfigReadOnly\n | VanaConfigAddressOnly\n | WalletConfig\n | ChainConfig;\n\n/**\n * Configuration interface for Vana SDK that requires storage providers.\n *\n * Use this type when you need to ensure storage is configured for operations\n * like file uploads, permission grants without pre-stored URLs, or schema creation.\n * Supports all three initialization modes with required storage.\n *\n * @category Configuration\n * @example\n * ```typescript\n * // Full configuration with wallet client and storage\n * const configWithWallet: VanaConfigWithStorage = {\n * walletClient: createWalletClient({\n * account: privateKeyToAccount('0x...'),\n * chain: moksha,\n * transport: http()\n * }),\n * storage: {\n * providers: {\n * ipfs: new IPFSStorage({ gateway: 'https://gateway.pinata.cloud' })\n * },\n * defaultProvider: 'ipfs'\n * }\n * };\n *\n * // Read-only configuration with storage\n * const configReadOnly: VanaConfigWithStorage = {\n * publicClient: createPublicClient({\n * chain: moksha,\n * transport: http()\n * }),\n * address: '0x1234...',\n * storage: {\n * providers: {\n * ipfs: new IPFSStorage({ gateway: 'https://gateway.pinata.cloud' })\n * },\n * defaultProvider: 'ipfs'\n * }\n * };\n * ```\n */\nexport type VanaConfigWithStorage =\n | VanaConfigWithWalletWithStorage\n | VanaConfigReadOnlyWithStorage\n | VanaConfigAddressOnlyWithStorage\n | WalletConfigWithStorage\n | ChainConfigWithStorage;\n\n/**\n * Runtime configuration information\n *\n * @category Configuration\n */\nexport interface RuntimeConfig {\n /** Current chain ID */\n chainId: VanaChainId;\n /** Current chain name */\n chainName: string;\n /** Available storage providers */\n storageProviders: string[];\n /** Default storage provider */\n defaultStorageProvider?: string;\n /** Current relayer callbacks configuration */\n relayerCallbacks?: RelayerCallbacks;\n}\n\n/**\n * Validates whether a configuration object has a wallet client (any wallet-based config).\n *\n * @param config - The configuration object to check\n * @returns True if the config contains a walletClient\n * @example\n * ```typescript\n * if (isWalletConfig(config)) {\n * console.log('Using wallet client:', config.walletClient.account?.address);\n * } else {\n * console.log('Read-only or chain config');\n * }\n * ```\n */\nexport function isWalletConfig(\n config: VanaConfig,\n): config is VanaConfigWithWallet | WalletConfig {\n return \"walletClient\" in config;\n}\n\n/**\n * Validates whether a configuration object is a read-only config with public client.\n *\n * @param config - The configuration object to check\n * @returns True if the config has publicClient and address but no walletClient\n * @example\n * ```typescript\n * if (isReadOnlyConfig(config)) {\n * console.log('Read-only mode with address:', config.address);\n * }\n * ```\n */\nexport function isReadOnlyConfig(\n config: VanaConfig,\n): config is VanaConfigReadOnly {\n return (\n \"publicClient\" in config &&\n \"address\" in config &&\n !(\"walletClient\" in config)\n );\n}\n\n/**\n * Validates whether a configuration object is an address-only config.\n *\n * @param config - The configuration object to check\n * @returns True if the config has only address (and optionally chain) but no clients\n * @example\n * ```typescript\n * if (isAddressOnlyConfig(config)) {\n * console.log('Address-only mode:', config.address);\n * }\n * ```\n */\nexport function isAddressOnlyConfig(\n config: VanaConfig,\n): config is VanaConfigAddressOnly {\n return (\n \"address\" in config &&\n !(\"publicClient\" in config) &&\n !(\"walletClient\" in config) &&\n !(\"chainId\" in config)\n );\n}\n\n/**\n * Validates whether a configuration object is a ChainConfig.\n *\n * @param config - The configuration object to check\n * @returns True if the config is a ChainConfig (contains chainId but not walletClient)\n * @example\n * ```typescript\n * if (isChainConfig(config)) {\n * console.log('Chain ID:', config.chainId);\n * console.log('RPC URL:', config.rpcUrl);\n * } else {\n * console.log('Using pre-configured wallet client');\n * }\n * ```\n */\nexport function isChainConfig(config: VanaConfig): config is ChainConfig {\n return \"chainId\" in config && !(\"walletClient\" in config);\n}\n\n/**\n * Validates whether a configuration has required storage providers.\n *\n * @param config - The configuration object to check\n * @returns True if the config has storage providers configured\n * @example\n * ```typescript\n * if (hasStorageConfig(config)) {\n * // Safe to use storage-dependent operations\n * await vana.data.uploadFile(file);\n * } else {\n * console.log('Storage not configured - some operations may fail');\n * }\n * ```\n */\nexport function hasStorageConfig(\n config: VanaConfig,\n): config is VanaConfigWithStorage {\n return (\n config.storage?.providers !== undefined &&\n Object.keys(config.storage.providers).length > 0\n );\n}\n\n/**\n * Configuration validation options\n *\n * @category Configuration\n */\nexport interface ConfigValidationOptions {\n /** Whether to validate storage providers */\n validateStorage?: boolean;\n /** Whether to validate relayer URL */\n validateRelayer?: boolean;\n /** Whether to validate chain configuration */\n validateChain?: boolean;\n}\n\n/**\n * Configuration validation result\n *\n * @category Configuration\n */\nexport interface ConfigValidationResult {\n /** Whether the configuration is valid */\n valid: boolean;\n /** List of validation errors */\n errors: string[];\n /** List of validation warnings */\n warnings: string[];\n}\n"],"mappings":"AAu0BO,SAAS,eACd,QAC+C;AAC/C,SAAO,kBAAkB;AAC3B;AAcO,SAAS,iBACd,QAC8B;AAC9B,SACE,kBAAkB,UAClB,aAAa,UACb,EAAE,kBAAkB;AAExB;AAcO,SAAS,oBACd,QACiC;AACjC,SACE,aAAa,UACb,EAAE,kBAAkB,WACpB,EAAE,kBAAkB,WACpB,EAAE,aAAa;AAEnB;AAiBO,SAAS,cAAc,QAA2C;AACvE,SAAO,aAAa,UAAU,EAAE,kBAAkB;AACpD;AAiBO,SAAS,iBACd,QACiC;AACjC,SACE,OAAO,SAAS,cAAc,UAC9B,OAAO,KAAK,OAAO,QAAQ,SAAS,EAAE,SAAS;AAEnD;","names":[]}
1
+ {"version":3,"sources":["../../src/types/config.ts"],"sourcesContent":["import type { WalletClient, PublicClient, Account, Address, Chain } from \"viem\";\nimport type { VanaChainId, VanaChain } from \"./chains\";\nimport type {\n StorageProvider,\n StorageUploadResult,\n StorageListOptions,\n} from \"./storage\";\n\nimport type { RelayerConfig } from \"./relayer\";\n\n/**\n * Marker interface to indicate that a Vana instance has storage configured.\n * Used for compile-time type safety to ensure storage-dependent methods\n * are only called on properly configured instances.\n *\n * @category Configuration\n */\nexport interface StorageRequiredMarker {\n readonly __storageRequired: true;\n}\n\n/**\n * Configures storage providers for SDK file operations.\n *\n * @remarks\n * Supports multiple backends with automatic fallback.\n * IPFS for decentralization, Pinata for reliability,\n * Google Drive for development, custom for flexibility.\n *\n * **Provider Selection:**\n * - IPFS: Decentralized, permanent storage ideal for production\n * - Pinata: Managed IPFS with guaranteed availability\n * - Google Drive: Centralized, suitable for development/testing\n * - Custom providers: Implement StorageProvider interface\n *\n * @category Configuration\n * @example\n * ```typescript\n * const storage: StorageConfig = {\n * providers: {\n * ipfs: new IPFSStorage({ gateway: 'https://gateway.pinata.cloud' }),\n * pinata: new PinataStorage({ apiKey: 'key', secretKey: 'secret' })\n * },\n * defaultProvider: 'ipfs'\n * };\n * ```\n */\nexport interface StorageConfig {\n /**\n * Map of provider name to storage provider instance.\n * Common provider names: \"ipfs\", \"pinata\", \"googledrive\", \"s3\".\n * Custom names allowed for custom provider implementations.\n */\n providers: Record<string, StorageProvider>;\n /**\n * Default provider name to use when none specified.\n * Must match a key in the providers map. Falls back to first provider if not specified.\n */\n defaultProvider?: string;\n}\n\n/**\n * Download relayer callbacks for proxying CORS-restricted downloads.\n *\n * Provides a callback to proxy download requests through your application server\n * when direct browser access fails due to CORS restrictions (e.g., Google Drive).\n *\n * IMPORTANT SECURITY REQUIREMENTS for your proxy endpoint:\n * 1. MUST block requests to private/internal IPs (SSRF protection)\n * 2. SHOULD NOT restrict domains (files can be hosted anywhere)\n *\n * @category Configuration\n * @example Client-side implementation:\n * ```typescript\n * const downloadRelayer: DownloadRelayerCallbacks = {\n * async proxyDownload(url) {\n * const response = await fetch('/api/proxy', {\n * method: 'POST',\n * headers: { 'Content-Type': 'application/json' },\n * body: JSON.stringify({ url })\n * });\n * return response.blob();\n * }\n * };\n * ```\n *\n * @example Server-side proxy endpoint (Next.js):\n * ```typescript\n * // /api/proxy/route.ts\n * import { promises as dns } from 'dns';\n * import { isIPv4 } from 'net';\n *\n * async function handleProxy(url: string) {\n * const { hostname } = new URL(url);\n *\n * // Resolve hostname to IP (handle localhost specially)\n * const ip = hostname === 'localhost' ? '127.0.0.1' :\n * isIPv4(hostname) ? hostname :\n * await dns.lookup(hostname).then(r => r.address);\n *\n * // SSRF Protection: Block private/internal IPs\n * if (isIPv4(ip)) {\n * const [a, b] = ip.split('.').map(Number);\n * if (a === 10 || a === 127 || a === 0 ||\n * (a === 172 && b >= 16 && b <= 31) ||\n * (a === 192 && b === 168) ||\n * (a === 169 && b === 254) ||\n * a >= 224) { // Also block multicast/reserved\n * return new Response('Private/internal addresses not allowed', { status: 403 });\n * }\n * }\n *\n * // Proxy the request\n * const response = await fetch(url, { redirect: 'manual' });\n *\n * // Handle redirects (with recursion limit)\n * if (response.status >= 301 && response.status <= 308) {\n * const location = response.headers.get('location');\n * if (location) return handleProxy(new URL(location, url).href);\n * }\n *\n * const data = await response.arrayBuffer();\n * return new Response(data, {\n * headers: {\n * 'Content-Type': response.headers.get('content-type') || 'application/octet-stream',\n * 'Access-Control-Allow-Origin': '*'\n * }\n * });\n * }\n * ```\n */\nexport interface DownloadRelayerCallbacks {\n /**\n * Proxy a download request through your application server\n *\n * @param url - The URL to download from\n * @returns Promise resolving to the downloaded content as a Blob\n */\n proxyDownload: (url: string) => Promise<Blob>;\n}\n\n/**\n * Storage callback functions for flexible storage operations.\n *\n * Instead of hardcoding storage behavior (HTTP endpoints, etc.), users can provide\n * custom callback functions to handle storage operations in any way they choose.\n * This pattern matches the relayer callbacks approach, providing maximum flexibility.\n *\n * @category Configuration\n * @example\n * ```typescript\n * const storageCallbacks: StorageCallbacks = {\n * async upload(blob, filename, metadata) {\n * // Custom implementation - could be HTTP, S3, local filesystem, etc.\n * const formData = new FormData();\n * formData.append('file', blob, filename);\n * const response = await fetch('/api/storage/upload', {\n * method: 'POST',\n * body: formData\n * });\n * const data = await response.json();\n * return {\n * url: data.url,\n * size: blob.size,\n * contentType: blob.type,\n * metadata: data.metadata\n * };\n * },\n *\n * async download(identifier) {\n * const response = await fetch(`/api/storage/download/${identifier}`);\n * return response.blob();\n * }\n * };\n * ```\n */\nexport interface StorageCallbacks {\n /**\n * Upload a blob to storage\n *\n * @param blob - The data to upload\n * @param filename - Optional filename hint\n * @param metadata - Optional metadata for the upload\n * @returns Upload result with identifier and metadata\n */\n upload: (\n blob: Blob,\n filename?: string,\n metadata?: Record<string, unknown>,\n ) => Promise<StorageUploadResult>;\n\n /**\n * Download data from storage\n *\n * @param identifier - The storage identifier (could be URL, hash, path, or any unique ID)\n * @param options - Optional download options\n * @returns The downloaded data as a Blob\n */\n download: (\n identifier: string,\n options?: StorageDownloadOptions,\n ) => Promise<Blob>;\n\n /**\n * List stored items (optional)\n *\n * @param prefix - Optional prefix to filter results\n * @param options - Optional listing options\n * @returns Array of storage items with metadata\n */\n list?: (\n prefix?: string,\n options?: StorageListOptions,\n ) => Promise<StorageListResult>;\n\n /**\n * Delete a stored item (optional)\n *\n * @param identifier - The storage identifier to delete\n * @returns Promise that resolves to true if deletion succeeded\n */\n delete?: (identifier: string) => Promise<boolean>;\n\n /**\n * Extract identifier from a URL or return as-is (optional)\n * Used for backward compatibility with URL-based systems\n *\n * @param url - The URL to extract from\n * @returns The extracted identifier\n */\n extractIdentifier?: (url: string) => string;\n}\n\n/**\n * Options for storage download operations\n *\n * @category Configuration\n */\nexport interface StorageDownloadOptions {\n /** Optional HTTP headers */\n headers?: Record<string, string>;\n /** Optional abort signal for cancellation */\n signal?: AbortSignal;\n /** Optional byte range for partial downloads */\n range?: { start?: number; end?: number };\n}\n\n/**\n * Result from storage list operations\n *\n * @category Configuration\n */\nexport interface StorageListResult {\n /** Array of storage items */\n items: Array<{\n /** Item identifier */\n identifier: string;\n /** Item size in bytes */\n size?: number;\n /** Last modified timestamp */\n lastModified?: Date;\n /** Item metadata */\n metadata?: Record<string, unknown>;\n }>;\n /** Continuation token for pagination */\n continuationToken?: string;\n /** Whether more results are available */\n hasMore?: boolean;\n}\n\n/**\n * Base configuration interface without storage requirements\n *\n * @category Configuration\n */\nexport interface BaseConfig {\n /**\n * Optional relayer configuration for handling gasless transactions.\n * Can be a URL string for convenience, or a callback for full control.\n *\n * @example\n * ```typescript\n * // Simple URL (SDK handles transport)\n * relayer: '/api/relay'\n *\n * // Full control with callback\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 relayer?: RelayerConfig;\n\n /**\n * Optional download relayer for proxying CORS-restricted downloads.\n * Provides a proxy mechanism for files stored on servers with CORS restrictions.\n */\n downloadRelayer?: DownloadRelayerCallbacks;\n\n /**\n * Optional storage providers configuration for file upload/download.\n * Required for: upload(), grant() without pre-stored URLs, schema operations.\n * See StorageConfig for provider selection guidance.\n */\n storage?: StorageConfig;\n /**\n * Optional subgraph URL for querying user files and permissions.\n * If not provided, defaults to the built-in subgraph URL for the current chain.\n * Can be overridden per method call if needed.\n * Obtain chain-specific URLs from Vana documentation or deployment info.\n */\n subgraphUrl?: string;\n /**\n * Optional default IPFS gateways to use for fetching files.\n * These gateways will be used by default in fetchFromIPFS unless overridden per-call.\n * If not provided, the SDK will use public gateways.\n * Order matters: first successful gateway is used.\n *\n * @example ['https://gateway.pinata.cloud', 'https://ipfs.io']\n */\n ipfsGateways?: string[];\n /**\n * Default personal server base URL for server operations.\n * Required for ServerController methods like getIdentity(), createOperation(), etc.\n *\n * @example 'https://my-personal-server.example.com'\n */\n defaultPersonalServerUrl?: string;\n}\n\n/**\n * Base configuration interface that requires storage for storage-dependent operations\n *\n * @category Configuration\n */\nexport interface BaseConfigWithStorage {\n /**\n * Optional relayer configuration for handling gasless transactions.\n * Can be a URL string for convenience, or a callback for full control.\n *\n * @example\n * ```typescript\n * // Simple URL (SDK handles transport)\n * relayer: '/api/relay'\n *\n * // Full control with callback\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 relayer?: RelayerConfig;\n\n /**\n * Optional download relayer for proxying CORS-restricted downloads.\n * Provides a proxy mechanism for files stored on servers with CORS restrictions.\n */\n downloadRelayer?: DownloadRelayerCallbacks;\n\n /** Required storage providers configuration for file upload/download */\n storage: StorageConfig;\n /**\n * Optional subgraph URL for querying user files and permissions.\n * If not provided, defaults to the built-in subgraph URL for the current chain.\n * Can be overridden per method call if needed.\n */\n subgraphUrl?: string;\n /**\n * Optional default IPFS gateways to use for fetching files.\n * These gateways will be used by default in fetchFromIPFS unless overridden per-call.\n * If not provided, the SDK will use public gateways.\n *\n * @example ['https://gateway.pinata.cloud', 'https://ipfs.io']\n */\n ipfsGateways?: string[];\n /**\n * Default personal server base URL for server operations.\n * Required for ServerController methods like getIdentity(), createOperation(), etc.\n *\n * @example 'https://my-personal-server.example.com'\n */\n defaultPersonalServerUrl?: string;\n}\n\n/**\n * Configuration with wallet client\n *\n * @category Configuration\n */\nexport interface WalletConfig extends BaseConfig {\n /** The viem WalletClient instance used for signing transactions */\n walletClient: WalletClient & {\n chain: VanaChain;\n };\n}\n\n/**\n * Configuration with wallet client that requires storage\n *\n * @category Configuration\n */\nexport interface WalletConfigWithStorage extends BaseConfigWithStorage {\n /** The viem WalletClient instance used for signing transactions */\n walletClient: WalletClient & {\n chain: VanaChain;\n };\n}\n\n/**\n * Configuration with chain and account details\n *\n * @category Configuration\n */\nexport interface ChainConfig extends BaseConfig {\n /**\n * The chain ID for Vana network.\n * Supported: 14800 (Vana Mainnet), 14801 (Moksha Testnet), 31337 (Local Development).\n * Use chain constants from '@vana/sdk' for type safety.\n */\n chainId: VanaChainId;\n /**\n * RPC URL for the chain (optional, will use default for the chain if not provided).\n * Default URLs: mainnet (https://rpc.vana.org), testnet (https://rpc.moksha.vana.org).\n * Override for custom nodes or local development.\n */\n rpcUrl?: string;\n /**\n * Optional account for signing transactions.\n * Can be: privateKeyToAccount(), mnemonicToAccount(), or custom Account implementation.\n * Required for write operations; read-only operations work without account.\n */\n account?: Account;\n}\n\n/**\n * Configuration with chain and account details that requires storage\n *\n * @category Configuration\n */\nexport interface ChainConfigWithStorage extends BaseConfigWithStorage {\n /** The chain ID for Vana network */\n chainId: VanaChainId;\n /** RPC URL for the chain (optional, will use default for the chain if not provided) */\n rpcUrl?: string;\n /** Optional account for signing transactions */\n account?: Account;\n}\n\n/**\n * Configuration with wallet client and optional public client\n *\n * @category Configuration\n */\nexport interface VanaConfigWithWallet extends BaseConfig {\n /** The viem WalletClient instance used for signing transactions */\n walletClient: WalletClient;\n /** Optional PublicClient for read operations (derived from wallet if not provided) */\n publicClient?: PublicClient;\n}\n\n/**\n * Configuration for read-only operations with public client and address\n *\n * @category Configuration\n */\nexport interface VanaConfigReadOnly extends BaseConfig {\n /** The viem PublicClient instance for read operations */\n publicClient: PublicClient;\n /** The user's address for read operations */\n address: Address;\n}\n\n/**\n * Configuration for minimal read-only operations with just an address\n *\n * @category Configuration\n */\nexport interface VanaConfigAddressOnly extends BaseConfig {\n /** The user's address for read operations */\n address: Address;\n /** Optional chain configuration (will use default if not provided) */\n chain?: Chain;\n}\n\n/**\n * Configuration with wallet client and optional public client that requires storage\n *\n * @category Configuration\n */\nexport interface VanaConfigWithWalletWithStorage extends BaseConfigWithStorage {\n /** The viem WalletClient instance used for signing transactions */\n walletClient: WalletClient;\n /** Optional PublicClient for read operations (derived from wallet if not provided) */\n publicClient?: PublicClient;\n}\n\n/**\n * Configuration for read-only operations with public client and address that requires storage\n *\n * @category Configuration\n */\nexport interface VanaConfigReadOnlyWithStorage extends BaseConfigWithStorage {\n /** The viem PublicClient instance for read operations */\n publicClient: PublicClient;\n /** The user's address for read operations */\n address: Address;\n}\n\n/**\n * Configuration for minimal read-only operations with just an address that requires storage\n *\n * @category Configuration\n */\nexport interface VanaConfigAddressOnlyWithStorage\n extends BaseConfigWithStorage {\n /** The user's address for read operations */\n address: Address;\n /** Optional chain configuration (will use default if not provided) */\n chain?: Chain;\n}\n\n/**\n * Main configuration interface for initializing the Vana SDK.\n *\n * The SDK supports three initialization modes:\n * 1. Full mode with wallet client for signing transactions\n * 2. Read-only mode with public client and address for read operations\n * 3. Minimal mode with just an address and optional chain\n *\n * @category Configuration\n * @example\n * ```typescript\n * // Mode 1: Full configuration with wallet client\n * const configWithWallet: VanaConfig = {\n * walletClient: createWalletClient({\n * account: privateKeyToAccount('0x...'),\n * chain: moksha,\n * transport: http()\n * }),\n * publicClient: createPublicClient({\n * chain: moksha,\n * transport: http()\n * })\n * };\n *\n * // Mode 2: Read-only with public client and address\n * const configReadOnly: VanaConfig = {\n * publicClient: createPublicClient({\n * chain: moksha,\n * transport: http()\n * }),\n * address: '0x1234...'\n * };\n *\n * // Mode 3: Minimal with just address\n * const configMinimal: VanaConfig = {\n * address: '0x1234...',\n * chain: moksha // optional\n * };\n * ```\n */\nexport type VanaConfig =\n | VanaConfigWithWallet\n | VanaConfigReadOnly\n | VanaConfigAddressOnly\n | WalletConfig\n | ChainConfig;\n\n/**\n * Configuration interface for Vana SDK that requires storage providers.\n *\n * Use this type when you need to ensure storage is configured for operations\n * like file uploads, permission grants without pre-stored URLs, or schema creation.\n * Supports all three initialization modes with required storage.\n *\n * @category Configuration\n * @example\n * ```typescript\n * // Full configuration with wallet client and storage\n * const configWithWallet: VanaConfigWithStorage = {\n * walletClient: createWalletClient({\n * account: privateKeyToAccount('0x...'),\n * chain: moksha,\n * transport: http()\n * }),\n * storage: {\n * providers: {\n * ipfs: new IPFSStorage({ gateway: 'https://gateway.pinata.cloud' })\n * },\n * defaultProvider: 'ipfs'\n * }\n * };\n *\n * // Read-only configuration with storage\n * const configReadOnly: VanaConfigWithStorage = {\n * publicClient: createPublicClient({\n * chain: moksha,\n * transport: http()\n * }),\n * address: '0x1234...',\n * storage: {\n * providers: {\n * ipfs: new IPFSStorage({ gateway: 'https://gateway.pinata.cloud' })\n * },\n * defaultProvider: 'ipfs'\n * }\n * };\n * ```\n */\nexport type VanaConfigWithStorage =\n | VanaConfigWithWalletWithStorage\n | VanaConfigReadOnlyWithStorage\n | VanaConfigAddressOnlyWithStorage\n | WalletConfigWithStorage\n | ChainConfigWithStorage;\n\n/**\n * Runtime configuration information\n *\n * @category Configuration\n */\nexport interface RuntimeConfig {\n /** Current chain ID */\n chainId: VanaChainId;\n /** Current chain name */\n chainName: string;\n /** Available storage providers */\n storageProviders: string[];\n /** Default storage provider */\n defaultStorageProvider?: string;\n /** Current relayer configuration */\n relayerConfig?: RelayerConfig;\n}\n\n/**\n * Validates whether a configuration object has a wallet client (any wallet-based config).\n *\n * @param config - The configuration object to check\n * @returns True if the config contains a walletClient\n * @example\n * ```typescript\n * if (isWalletConfig(config)) {\n * console.log('Using wallet client:', config.walletClient.account?.address);\n * } else {\n * console.log('Read-only or chain config');\n * }\n * ```\n */\nexport function isWalletConfig(\n config: VanaConfig,\n): config is VanaConfigWithWallet | WalletConfig {\n return \"walletClient\" in config;\n}\n\n/**\n * Validates whether a configuration object is a read-only config with public client.\n *\n * @param config - The configuration object to check\n * @returns True if the config has publicClient and address but no walletClient\n * @example\n * ```typescript\n * if (isReadOnlyConfig(config)) {\n * console.log('Read-only mode with address:', config.address);\n * }\n * ```\n */\nexport function isReadOnlyConfig(\n config: VanaConfig,\n): config is VanaConfigReadOnly {\n return (\n \"publicClient\" in config &&\n \"address\" in config &&\n !(\"walletClient\" in config)\n );\n}\n\n/**\n * Validates whether a configuration object is an address-only config.\n *\n * @param config - The configuration object to check\n * @returns True if the config has only address (and optionally chain) but no clients\n * @example\n * ```typescript\n * if (isAddressOnlyConfig(config)) {\n * console.log('Address-only mode:', config.address);\n * }\n * ```\n */\nexport function isAddressOnlyConfig(\n config: VanaConfig,\n): config is VanaConfigAddressOnly {\n return (\n \"address\" in config &&\n !(\"publicClient\" in config) &&\n !(\"walletClient\" in config) &&\n !(\"chainId\" in config)\n );\n}\n\n/**\n * Validates whether a configuration object is a ChainConfig.\n *\n * @param config - The configuration object to check\n * @returns True if the config is a ChainConfig (contains chainId but not walletClient)\n * @example\n * ```typescript\n * if (isChainConfig(config)) {\n * console.log('Chain ID:', config.chainId);\n * console.log('RPC URL:', config.rpcUrl);\n * } else {\n * console.log('Using pre-configured wallet client');\n * }\n * ```\n */\nexport function isChainConfig(config: VanaConfig): config is ChainConfig {\n return \"chainId\" in config && !(\"walletClient\" in config);\n}\n\n/**\n * Validates whether a configuration has required storage providers.\n *\n * @param config - The configuration object to check\n * @returns True if the config has storage providers configured\n * @example\n * ```typescript\n * if (hasStorageConfig(config)) {\n * // Safe to use storage-dependent operations\n * await vana.data.uploadFile(file);\n * } else {\n * console.log('Storage not configured - some operations may fail');\n * }\n * ```\n */\nexport function hasStorageConfig(\n config: VanaConfig,\n): config is VanaConfigWithStorage {\n return (\n config.storage?.providers !== undefined &&\n Object.keys(config.storage.providers).length > 0\n );\n}\n\n/**\n * Configuration validation options\n *\n * @category Configuration\n */\nexport interface ConfigValidationOptions {\n /** Whether to validate storage providers */\n validateStorage?: boolean;\n /** Whether to validate relayer URL */\n validateRelayer?: boolean;\n /** Whether to validate chain configuration */\n validateChain?: boolean;\n}\n\n/**\n * Configuration validation result\n *\n * @category Configuration\n */\nexport interface ConfigValidationResult {\n /** Whether the configuration is valid */\n valid: boolean;\n /** List of validation errors */\n errors: string[];\n /** List of validation warnings */\n warnings: string[];\n}\n"],"mappings":"AAgpBO,SAAS,eACd,QAC+C;AAC/C,SAAO,kBAAkB;AAC3B;AAcO,SAAS,iBACd,QAC8B;AAC9B,SACE,kBAAkB,UAClB,aAAa,UACb,EAAE,kBAAkB;AAExB;AAcO,SAAS,oBACd,QACiC;AACjC,SACE,aAAa,UACb,EAAE,kBAAkB,WACpB,EAAE,kBAAkB,WACpB,EAAE,aAAa;AAEnB;AAiBO,SAAS,cAAc,QAA2C;AACvE,SAAO,aAAa,UAAU,EAAE,kBAAkB;AACpD;AAiBO,SAAS,iBACd,QACiC;AACjC,SACE,OAAO,SAAS,cAAc,UAC9B,OAAO,KAAK,OAAO,QAAQ,SAAS,EAAE,SAAS;AAEnD;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/types/contracts.ts"],"sourcesContent":["import type { Abi, Address, Hash, GetContractReturnType } from \"viem\";\n\n/**\n * Union type of all canonical Vana contract names\n */\nexport type VanaContractName =\n | \"DataPortabilityPermissions\"\n | \"DataPortabilityServers\"\n | \"DataPortabilityGrantees\"\n | \"DataRegistry\"\n | \"TeePool\"\n | \"ComputeEngine\"\n | \"TeePoolPhala\"\n | \"DataRefinerRegistry\"\n | \"QueryEngine\"\n | \"ComputeInstructionRegistry\"\n | \"TeePoolEphemeralStandard\"\n | \"TeePoolPersistentStandard\"\n | \"TeePoolPersistentGpu\"\n | \"TeePoolDedicatedStandard\"\n | \"TeePoolDedicatedGpu\"\n | \"VanaEpoch\"\n | \"DLPRegistry\"\n | \"DLPRegistryTreasury\"\n | \"DLPPerformance\"\n | \"DLPRewardDeployer\"\n | \"DLPRewardDeployerTreasury\"\n | \"DLPRewardSwap\"\n | \"SwapHelper\"\n | \"VanaPoolStaking\"\n | \"VanaPoolEntity\"\n | \"VanaPoolTreasury\"\n | \"DAT\"\n | \"DATFactory\"\n | \"DATPausable\"\n | \"DATVotes\"\n | \"DataLiquidityPool\"\n | \"DLPRoot\";\n\n/**\n * Contract information with typed address and ABI\n */\nexport interface ContractInfo<TAbi extends Abi = Abi> {\n /** The contract's deployed address */\n address: Address;\n /** The contract's ABI */\n abi: TAbi;\n}\n\n/**\n * Contract deployment information\n */\nexport interface ContractDeployment {\n /** The contract's deployed address */\n address: Address;\n /** Block number where contract was deployed */\n blockNumber: bigint;\n /** Transaction hash of deployment */\n transactionHash: Hash;\n}\n\n/**\n * Typed contract instance\n */\nexport type VanaContractInstance<TAbi extends Abi = Abi> =\n GetContractReturnType<TAbi>;\n\n/**\n * Contract addresses mapping by chain and contract name\n */\nexport type ContractAddresses = {\n [chainId: number]: {\n [contractName in VanaContractName]?: Address;\n };\n};\n\n/**\n * Contract method parameters for typed interactions\n */\nexport type ContractMethodParams<\n TAbi extends Abi,\n TFunctionName extends string,\n> = TAbi extends readonly unknown[]\n ? TAbi[number] extends {\n name: TFunctionName;\n type: \"function\";\n inputs: infer TInputs;\n }\n ? TInputs extends readonly unknown[]\n ? {\n [K in keyof TInputs]: TInputs[K] extends {\n name: infer TName;\n type: infer TType;\n }\n ? TName extends string\n ? TType extends \"address\"\n ? Address\n : TType extends \"uint256\"\n ? bigint\n : TType extends \"string\"\n ? string\n : TType extends \"bool\"\n ? boolean\n : TType extends \"bytes32\"\n ? Hash\n : unknown\n : never\n : never;\n }\n : never\n : never\n : never;\n\n/**\n * Contract method return type for typed interactions\n */\nexport type ContractMethodReturnType<\n TAbi extends Abi,\n TFunctionName extends string,\n> = TAbi extends readonly unknown[]\n ? TAbi[number] extends {\n name: TFunctionName;\n type: \"function\";\n outputs: infer TOutputs;\n }\n ? TOutputs extends readonly unknown[]\n ? TOutputs[\"length\"] extends 1\n ? TOutputs[0] extends { type: infer TType }\n ? TType extends \"address\"\n ? Address\n : TType extends \"uint256\"\n ? bigint\n : TType extends \"string\"\n ? string\n : TType extends \"bool\"\n ? boolean\n : TType extends \"bytes32\"\n ? Hash\n : unknown\n : unknown\n : {\n [K in keyof TOutputs]: TOutputs[K] extends {\n name: infer TName;\n type: infer TType;\n }\n ? TName extends string\n ? TType extends \"address\"\n ? Address\n : TType extends \"uint256\"\n ? bigint\n : TType extends \"string\"\n ? string\n : TType extends \"bool\"\n ? boolean\n : TType extends \"bytes32\"\n ? Hash\n : unknown\n : never\n : never;\n }\n : never\n : never\n : never;\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
1
+ {"version":3,"sources":["../../src/types/contracts.ts"],"sourcesContent":["/**\n * Defines types for smart contract interactions.\n *\n * @remarks\n * This module provides comprehensive type definitions for Vana protocol\n * smart contracts including contract names, deployment information, and\n * advanced TypeScript utility types for type-safe contract interactions.\n *\n * @category Types\n * @module types/contracts\n */\n\nimport type { Abi, Address, Hash, GetContractReturnType } from \"viem\";\n\n/**\n * Enumerates all supported Vana protocol contract names.\n *\n * @remarks\n * Use these names with `getContractController()` to get typed contract\n * instances. Each name corresponds to a specific protocol contract with\n * its own ABI and functionality.\n *\n * @category Contracts\n */\nexport type VanaContractName =\n | \"DataPortabilityPermissions\"\n | \"DataPortabilityServers\"\n | \"DataPortabilityGrantees\"\n | \"DataRegistry\"\n | \"TeePool\"\n | \"ComputeEngine\"\n | \"TeePoolPhala\"\n | \"DataRefinerRegistry\"\n | \"QueryEngine\"\n | \"ComputeInstructionRegistry\"\n | \"TeePoolEphemeralStandard\"\n | \"TeePoolPersistentStandard\"\n | \"TeePoolPersistentGpu\"\n | \"TeePoolDedicatedStandard\"\n | \"TeePoolDedicatedGpu\"\n | \"VanaEpoch\"\n | \"DLPRegistry\"\n | \"DLPRegistryTreasury\"\n | \"DLPPerformance\"\n | \"DLPRewardDeployer\"\n | \"DLPRewardDeployerTreasury\"\n | \"DLPRewardSwap\"\n | \"SwapHelper\"\n | \"VanaPoolStaking\"\n | \"VanaPoolEntity\"\n | \"VanaPoolTreasury\"\n | \"DAT\"\n | \"DATFactory\"\n | \"DATPausable\"\n | \"DATVotes\"\n | \"DataLiquidityPool\"\n | \"DLPRoot\";\n\n/**\n * Provides contract deployment information with typed ABI.\n *\n * @remarks\n * Contains the minimum information needed to interact with a\n * deployed contract: its address and ABI.\n *\n * @typeParam TAbi - The contract's ABI type for full type safety\n *\n * @category Contracts\n */\nexport interface ContractInfo<TAbi extends Abi = Abi> {\n /** The contract's deployed address */\n address: Address;\n /** The contract's ABI */\n abi: TAbi;\n}\n\n/**\n * Tracks contract deployment metadata.\n *\n * @remarks\n * Records when and how a contract was deployed to the blockchain,\n * useful for verification and debugging.\n *\n * @category Contracts\n */\nexport interface ContractDeployment {\n /** The contract's deployed address */\n address: Address;\n /** Block number where contract was deployed */\n blockNumber: bigint;\n /** Transaction hash of deployment */\n transactionHash: Hash;\n}\n\n/**\n * Represents a fully typed contract instance.\n *\n * @remarks\n * Alias for viem's GetContractReturnType, providing a contract\n * instance with all methods fully typed based on the ABI.\n *\n * @typeParam TAbi - The contract's ABI type\n *\n * @category Contracts\n */\nexport type VanaContractInstance<TAbi extends Abi = Abi> =\n GetContractReturnType<TAbi>;\n\n/**\n * Maps contract addresses by chain ID and contract name.\n *\n * @remarks\n * Hierarchical mapping structure for multi-chain contract deployments.\n * Used internally for address resolution across different networks.\n *\n * @category Contracts\n */\nexport type ContractAddresses = {\n [chainId: number]: {\n [contractName in VanaContractName]?: Address;\n };\n};\n\n/**\n * Extracts typed parameters for a contract method from its ABI.\n *\n * @remarks\n * Advanced utility type that provides type-safe parameter extraction\n * from contract ABIs. Maps Solidity types to TypeScript types automatically.\n *\n * @typeParam TAbi - The contract's ABI type\n * @typeParam TFunctionName - The name of the function to extract parameters for\n *\n * @internal\n */\nexport type ContractMethodParams<\n TAbi extends Abi,\n TFunctionName extends string,\n> = TAbi extends readonly unknown[]\n ? TAbi[number] extends {\n name: TFunctionName;\n type: \"function\";\n inputs: infer TInputs;\n }\n ? TInputs extends readonly unknown[]\n ? {\n [K in keyof TInputs]: TInputs[K] extends {\n name: infer TName;\n type: infer TType;\n }\n ? TName extends string\n ? TType extends \"address\"\n ? Address\n : TType extends \"uint256\"\n ? bigint\n : TType extends \"string\"\n ? string\n : TType extends \"bool\"\n ? boolean\n : TType extends \"bytes32\"\n ? Hash\n : unknown\n : never\n : never;\n }\n : never\n : never\n : never;\n\n/**\n * Extracts typed return values for a contract method from its ABI.\n *\n * @remarks\n * Advanced utility type that provides type-safe return type extraction\n * from contract ABIs. Handles single values and tuples appropriately.\n *\n * @typeParam TAbi - The contract's ABI type\n * @typeParam TFunctionName - The name of the function to extract return type for\n *\n * @internal\n */\nexport type ContractMethodReturnType<\n TAbi extends Abi,\n TFunctionName extends string,\n> = TAbi extends readonly unknown[]\n ? TAbi[number] extends {\n name: TFunctionName;\n type: \"function\";\n outputs: infer TOutputs;\n }\n ? TOutputs extends readonly unknown[]\n ? TOutputs[\"length\"] extends 1\n ? TOutputs[0] extends { type: infer TType }\n ? TType extends \"address\"\n ? Address\n : TType extends \"uint256\"\n ? bigint\n : TType extends \"string\"\n ? string\n : TType extends \"bool\"\n ? boolean\n : TType extends \"bytes32\"\n ? Hash\n : unknown\n : unknown\n : {\n [K in keyof TOutputs]: TOutputs[K] extends {\n name: infer TName;\n type: infer TType;\n }\n ? TName extends string\n ? TType extends \"address\"\n ? Address\n : TType extends \"uint256\"\n ? bigint\n : TType extends \"string\"\n ? string\n : TType extends \"bool\"\n ? boolean\n : TType extends \"bytes32\"\n ? Hash\n : unknown\n : never\n : never;\n }\n : never\n : never\n : never;\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -1,10 +1,36 @@
1
+ /**
2
+ * Defines types for smart contract interactions.
3
+ *
4
+ * @remarks
5
+ * This module provides comprehensive type definitions for Vana protocol
6
+ * smart contracts including contract names, deployment information, and
7
+ * advanced TypeScript utility types for type-safe contract interactions.
8
+ *
9
+ * @category Types
10
+ * @module types/contracts
11
+ */
1
12
  import type { Abi, Address, Hash, GetContractReturnType } from "viem";
2
13
  /**
3
- * Union type of all canonical Vana contract names
14
+ * Enumerates all supported Vana protocol contract names.
15
+ *
16
+ * @remarks
17
+ * Use these names with `getContractController()` to get typed contract
18
+ * instances. Each name corresponds to a specific protocol contract with
19
+ * its own ABI and functionality.
20
+ *
21
+ * @category Contracts
4
22
  */
5
23
  export type VanaContractName = "DataPortabilityPermissions" | "DataPortabilityServers" | "DataPortabilityGrantees" | "DataRegistry" | "TeePool" | "ComputeEngine" | "TeePoolPhala" | "DataRefinerRegistry" | "QueryEngine" | "ComputeInstructionRegistry" | "TeePoolEphemeralStandard" | "TeePoolPersistentStandard" | "TeePoolPersistentGpu" | "TeePoolDedicatedStandard" | "TeePoolDedicatedGpu" | "VanaEpoch" | "DLPRegistry" | "DLPRegistryTreasury" | "DLPPerformance" | "DLPRewardDeployer" | "DLPRewardDeployerTreasury" | "DLPRewardSwap" | "SwapHelper" | "VanaPoolStaking" | "VanaPoolEntity" | "VanaPoolTreasury" | "DAT" | "DATFactory" | "DATPausable" | "DATVotes" | "DataLiquidityPool" | "DLPRoot";
6
24
  /**
7
- * Contract information with typed address and ABI
25
+ * Provides contract deployment information with typed ABI.
26
+ *
27
+ * @remarks
28
+ * Contains the minimum information needed to interact with a
29
+ * deployed contract: its address and ABI.
30
+ *
31
+ * @typeParam TAbi - The contract's ABI type for full type safety
32
+ *
33
+ * @category Contracts
8
34
  */
9
35
  export interface ContractInfo<TAbi extends Abi = Abi> {
10
36
  /** The contract's deployed address */
@@ -13,7 +39,13 @@ export interface ContractInfo<TAbi extends Abi = Abi> {
13
39
  abi: TAbi;
14
40
  }
15
41
  /**
16
- * Contract deployment information
42
+ * Tracks contract deployment metadata.
43
+ *
44
+ * @remarks
45
+ * Records when and how a contract was deployed to the blockchain,
46
+ * useful for verification and debugging.
47
+ *
48
+ * @category Contracts
17
49
  */
18
50
  export interface ContractDeployment {
19
51
  /** The contract's deployed address */
@@ -24,11 +56,25 @@ export interface ContractDeployment {
24
56
  transactionHash: Hash;
25
57
  }
26
58
  /**
27
- * Typed contract instance
59
+ * Represents a fully typed contract instance.
60
+ *
61
+ * @remarks
62
+ * Alias for viem's GetContractReturnType, providing a contract
63
+ * instance with all methods fully typed based on the ABI.
64
+ *
65
+ * @typeParam TAbi - The contract's ABI type
66
+ *
67
+ * @category Contracts
28
68
  */
29
69
  export type VanaContractInstance<TAbi extends Abi = Abi> = GetContractReturnType<TAbi>;
30
70
  /**
31
- * Contract addresses mapping by chain and contract name
71
+ * Maps contract addresses by chain ID and contract name.
72
+ *
73
+ * @remarks
74
+ * Hierarchical mapping structure for multi-chain contract deployments.
75
+ * Used internally for address resolution across different networks.
76
+ *
77
+ * @category Contracts
32
78
  */
33
79
  export type ContractAddresses = {
34
80
  [chainId: number]: {
@@ -36,7 +82,16 @@ export type ContractAddresses = {
36
82
  };
37
83
  };
38
84
  /**
39
- * Contract method parameters for typed interactions
85
+ * Extracts typed parameters for a contract method from its ABI.
86
+ *
87
+ * @remarks
88
+ * Advanced utility type that provides type-safe parameter extraction
89
+ * from contract ABIs. Maps Solidity types to TypeScript types automatically.
90
+ *
91
+ * @typeParam TAbi - The contract's ABI type
92
+ * @typeParam TFunctionName - The name of the function to extract parameters for
93
+ *
94
+ * @internal
40
95
  */
41
96
  export type ContractMethodParams<TAbi extends Abi, TFunctionName extends string> = TAbi extends readonly unknown[] ? TAbi[number] extends {
42
97
  name: TFunctionName;
@@ -49,7 +104,16 @@ export type ContractMethodParams<TAbi extends Abi, TFunctionName extends string>
49
104
  } ? TName extends string ? TType extends "address" ? Address : TType extends "uint256" ? bigint : TType extends "string" ? string : TType extends "bool" ? boolean : TType extends "bytes32" ? Hash : unknown : never : never;
50
105
  } : never : never : never;
51
106
  /**
52
- * Contract method return type for typed interactions
107
+ * Extracts typed return values for a contract method from its ABI.
108
+ *
109
+ * @remarks
110
+ * Advanced utility type that provides type-safe return type extraction
111
+ * from contract ABIs. Handles single values and tuples appropriately.
112
+ *
113
+ * @typeParam TAbi - The contract's ABI type
114
+ * @typeParam TFunctionName - The name of the function to extract return type for
115
+ *
116
+ * @internal
53
117
  */
54
118
  export type ContractMethodReturnType<TAbi extends Abi, TFunctionName extends string> = TAbi extends readonly unknown[] ? TAbi[number] extends {
55
119
  name: TFunctionName;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/types/controller-context.ts"],"sourcesContent":["/**\n * Shared type definitions for controller contexts.\n *\n * @remarks\n * These types ensure consistency across all controllers and prevent drift.\n * Single source of truth following Rich Hickey's principles.\n */\n\nimport type { WalletClient, PublicClient, Address } from \"viem\";\nimport type { VanaPlatformAdapter } from \"../platform/interface\";\nimport type { StorageManager } from \"../storage\";\nimport type { RelayerCallbacks, DownloadRelayerCallbacks } from \"./config\";\nimport type {\n TransactionResult,\n TransactionWaitOptions,\n Operation,\n PollingOptions,\n} from \"./operations\";\nimport type {\n Contract,\n Fn,\n TypedTransactionResult,\n} from \"../generated/event-types\";\n\n/**\n * Type definition for waitForTransactionEvents function.\n *\n * @remarks\n * This is THE single definition used everywhere to prevent drift.\n * If you need to change the signature, change it here.\n */\nexport type WaitForTransactionEventsFn = <C extends Contract, F extends Fn<C>>(\n transaction: TransactionResult<C, F>,\n options?: TransactionWaitOptions,\n) => Promise<TypedTransactionResult<C, F>>;\n\n/**\n * Type definition for waitForOperation function.\n */\nexport type WaitForOperationFn = <T = unknown>(\n opOrId: Operation<T> | string,\n options?: PollingOptions,\n) => Promise<Operation<T>>;\n\n/**\n * Shared controller context interface.\n *\n * @remarks\n * This is the contract that all controllers depend on.\n * Changing this interface is a breaking change.\n */\nexport interface ControllerContext {\n /** Signs transactions and messages using the user's private key. Optional to support read-only mode. */\n walletClient?: WalletClient;\n /** Queries blockchain state and smart contracts without signing. */\n publicClient: PublicClient;\n /** Address of the user for operations requiring user identification in read-only mode. */\n userAddress: Address;\n /** Signs application-specific operations when different from primary wallet. */\n applicationClient?: WalletClient;\n /** Handles gasless transaction submission through relayer services. */\n relayerCallbacks?: RelayerCallbacks;\n /** Proxies CORS-restricted downloads through application server. */\n downloadRelayer?: DownloadRelayerCallbacks;\n /** Manages file upload and download operations across storage providers. */\n storageManager?: StorageManager;\n /** Provides subgraph endpoint for querying indexed blockchain data. */\n subgraphUrl?: string;\n /** Adapts SDK functionality to the current runtime environment. */\n platform: VanaPlatformAdapter;\n /** Validates that storage is available for storage-dependent operations. */\n validateStorageRequired?: () => void;\n /** Checks whether storage is configured without throwing an error. */\n hasStorage?: () => boolean;\n /** Default IPFS gateways to use for fetching files. */\n ipfsGateways?: string[];\n /** Default personal server base URL for server operations. */\n defaultPersonalServerUrl?: string;\n /** Waits for transaction confirmation and parses typed events. */\n waitForTransactionEvents?: WaitForTransactionEventsFn;\n /** Waits for an operation to complete with polling. */\n waitForOperation?: WaitForOperationFn;\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
1
+ {"version":3,"sources":["../../src/types/controller-context.ts"],"sourcesContent":["/**\n * Shared type definitions for controller contexts.\n *\n * @remarks\n * These types ensure consistency across all controllers and prevent drift.\n * Single source of truth following Rich Hickey's principles.\n */\n\nimport type { WalletClient, PublicClient, Address } from \"viem\";\nimport type { VanaPlatformAdapter } from \"../platform/interface\";\nimport type { StorageManager } from \"../storage\";\nimport type { DownloadRelayerCallbacks } from \"./config\";\nimport type { UnifiedRelayerRequest, UnifiedRelayerResponse } from \"./relayer\";\nimport type {\n TransactionResult,\n TransactionWaitOptions,\n Operation,\n PollingOptions,\n} from \"./operations\";\nimport type {\n Contract,\n Fn,\n TypedTransactionResult,\n} from \"../generated/event-types\";\n\n/**\n * Type definition for waitForTransactionEvents function.\n *\n * @remarks\n * This is THE single definition used everywhere to prevent drift.\n * If you need to change the signature, change it here.\n */\nexport type WaitForTransactionEventsFn = <C extends Contract, F extends Fn<C>>(\n transaction: TransactionResult<C, F>,\n options?: TransactionWaitOptions,\n) => Promise<TypedTransactionResult<C, F>>;\n\n/**\n * Type definition for waitForOperation function.\n */\nexport type WaitForOperationFn = <T = unknown>(\n opOrId: Operation<T> | string,\n options?: PollingOptions,\n) => Promise<Operation<T>>;\n\n/**\n * Shared controller context interface.\n *\n * @remarks\n * This is the contract that all controllers depend on.\n * Changing this interface is a breaking change.\n */\nexport interface ControllerContext {\n /** Signs transactions and messages using the user's private key. Optional to support read-only mode. */\n walletClient?: WalletClient;\n /** Queries blockchain state and smart contracts without signing. */\n publicClient: PublicClient;\n /** Address of the user for operations requiring user identification in read-only mode. */\n userAddress: Address;\n /** Signs application-specific operations when different from primary wallet. */\n applicationClient?: WalletClient;\n /** Handles gasless transaction submission through relayer services. */\n relayer?: (request: UnifiedRelayerRequest) => Promise<UnifiedRelayerResponse>;\n /** Proxies CORS-restricted downloads through application server. */\n downloadRelayer?: DownloadRelayerCallbacks;\n /** Manages file upload and download operations across storage providers. */\n storageManager?: StorageManager;\n /** Provides subgraph endpoint for querying indexed blockchain data. */\n subgraphUrl?: string;\n /** Adapts SDK functionality to the current runtime environment. */\n platform: VanaPlatformAdapter;\n /** Validates that storage is available for storage-dependent operations. */\n validateStorageRequired?: () => void;\n /** Checks whether storage is configured without throwing an error. */\n hasStorage?: () => boolean;\n /** Default IPFS gateways to use for fetching files. */\n ipfsGateways?: string[];\n /** Default personal server base URL for server operations. */\n defaultPersonalServerUrl?: string;\n /** Waits for transaction confirmation and parses typed events. */\n waitForTransactionEvents?: WaitForTransactionEventsFn;\n /** Waits for an operation to complete with polling. */\n waitForOperation?: WaitForOperationFn;\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -8,7 +8,8 @@
8
8
  import type { WalletClient, PublicClient, Address } from "viem";
9
9
  import type { VanaPlatformAdapter } from "../platform/interface";
10
10
  import type { StorageManager } from "../storage";
11
- import type { RelayerCallbacks, DownloadRelayerCallbacks } from "./config";
11
+ import type { DownloadRelayerCallbacks } from "./config";
12
+ import type { UnifiedRelayerRequest, UnifiedRelayerResponse } from "./relayer";
12
13
  import type { TransactionResult, TransactionWaitOptions, Operation, PollingOptions } from "./operations";
13
14
  import type { Contract, Fn, TypedTransactionResult } from "../generated/event-types";
14
15
  /**
@@ -40,7 +41,7 @@ export interface ControllerContext {
40
41
  /** Signs application-specific operations when different from primary wallet. */
41
42
  applicationClient?: WalletClient;
42
43
  /** Handles gasless transaction submission through relayer services. */
43
- relayerCallbacks?: RelayerCallbacks;
44
+ relayer?: (request: UnifiedRelayerRequest) => Promise<UnifiedRelayerResponse>;
44
45
  /** Proxies CORS-restricted downloads through application server. */
45
46
  downloadRelayer?: DownloadRelayerCallbacks;
46
47
  /** Manages file upload and download operations across storage providers. */