@opendatalabs/vana-sdk 0.1.0-alpha.c17525f → 0.1.0-alpha.c209e6c

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 (57) hide show
  1. package/README.md +244 -427
  2. package/dist/browser-DY8XDblx.d.ts +241 -0
  3. package/dist/browser.d.ts +1 -0
  4. package/dist/browser.js +309 -0
  5. package/dist/browser.js.map +1 -0
  6. package/dist/chains.browser.cjs +5 -2
  7. package/dist/chains.browser.cjs.map +1 -1
  8. package/dist/chains.browser.d.cts +2 -1
  9. package/dist/chains.browser.d.ts +2 -1
  10. package/dist/chains.browser.js +4 -2
  11. package/dist/chains.browser.js.map +1 -1
  12. package/dist/chains.cjs +5 -2
  13. package/dist/chains.cjs.map +1 -1
  14. package/dist/chains.d.cts +1 -1
  15. package/dist/chains.d.ts +1 -1
  16. package/dist/chains.js +4 -2
  17. package/dist/chains.js.map +1 -1
  18. package/dist/chains.node.cjs +5 -2
  19. package/dist/chains.node.cjs.map +1 -1
  20. package/dist/chains.node.d.cts +1 -1
  21. package/dist/chains.node.d.ts +1 -1
  22. package/dist/chains.node.js +4 -2
  23. package/dist/chains.node.js.map +1 -1
  24. package/dist/index.browser.d.ts +10235 -4446
  25. package/dist/index.browser.js +19284 -13490
  26. package/dist/index.browser.js.map +1 -1
  27. package/dist/index.d.cts +1 -31179
  28. package/dist/index.node.cjs +19669 -13836
  29. package/dist/index.node.cjs.map +1 -1
  30. package/dist/index.node.d.cts +10289 -4445
  31. package/dist/index.node.d.ts +10289 -4445
  32. package/dist/index.node.js +19663 -13833
  33. package/dist/index.node.js.map +1 -1
  34. package/dist/node-D9-F9uEP.d.cts +238 -0
  35. package/dist/node-D9-F9uEP.d.ts +238 -0
  36. package/dist/node.cjs +348 -0
  37. package/dist/node.cjs.map +1 -0
  38. package/dist/node.d.cts +1 -0
  39. package/dist/node.d.ts +1 -0
  40. package/dist/node.js +311 -0
  41. package/dist/node.js.map +1 -0
  42. package/dist/platform.browser.d.ts +3 -167
  43. package/dist/platform.browser.js +109 -188
  44. package/dist/platform.browser.js.map +1 -1
  45. package/dist/platform.cjs +183 -248
  46. package/dist/platform.cjs.map +1 -1
  47. package/dist/platform.d.cts +2 -1
  48. package/dist/platform.d.ts +2 -1
  49. package/dist/platform.js +183 -248
  50. package/dist/platform.js.map +1 -1
  51. package/dist/platform.node.cjs +183 -248
  52. package/dist/platform.node.cjs.map +1 -1
  53. package/dist/platform.node.d.cts +8 -167
  54. package/dist/platform.node.d.ts +8 -167
  55. package/dist/platform.node.js +183 -248
  56. package/dist/platform.node.js.map +1 -1
  57. package/package.json +29 -18
package/README.md CHANGED
@@ -1,33 +1,23 @@
1
1
  # Vana SDK
2
2
 
3
- The Vana SDK is a comprehensive TypeScript library for building applications on the Vana Network. It provides simple, powerful APIs for gasless data permissions, file management, and secure data portability.
3
+ > **⚠️ ALPHA SOFTWARE - EXPERIMENTAL USE ONLY**
4
+ >
5
+ > This SDK is in early alpha development and is **NOT SUITABLE FOR PRODUCTION USE**.
6
+ > Features may change without notice, and data loss or unexpected behavior may occur.
7
+ > Use at your own risk and avoid using with mainnet assets or critical operations.
4
8
 
5
- [![npm version](https://img.shields.io/npm/v/vana-sdk)](https://www.npmjs.com/package/vana-sdk)
9
+ A TypeScript SDK for building data-driven applications on the Vana Network. Enable users to grant gasless permissions, manage encrypted data, and interact with privacy-preserving infrastructure.
10
+
11
+ [![npm version](https://img.shields.io/npm/v/@opendatalabs/vana-sdk)](https://www.npmjs.com/package/@opendatalabs/vana-sdk)
6
12
  [![TypeScript](https://img.shields.io/badge/TypeScript-Ready-blue)](https://www.typescriptlang.org/)
7
13
  [![License: ISC](https://img.shields.io/badge/License-ISC-green.svg)](https://opensource.org/licenses/ISC)
8
14
 
9
- [Documentation](https://vana-com.github.io/vana-sdk) • [Examples](#examples) • [API Reference](https://vana-com.github.io/vana-sdk)
10
-
11
- ## Why Vana SDK?
12
-
13
- - **🔐 Gasless Permissions**: EIP-712 based permission system with zero gas fees for users
14
- - **📁 Data Management**: Query, upload, and manage encrypted user data files
15
- - **🔄 Flexible Relaying**: Callback-based relay system supporting any gasless transaction infrastructure
16
- - **📊 Schema Validation**: Built-in JSON Schema and SQLite schema validation with AJV
17
- - **🔧 Type-Safe**: Full TypeScript support with comprehensive type definitions
18
- - **🎯 Production Ready**: Battle-tested with comprehensive error handling and retry mechanisms
15
+ [API Documentation](https://vana-com.github.io/vana-sdk) • [Examples](#examples) • [Configuration](#configuration)
19
16
 
20
17
  ## Installation
21
18
 
22
19
  ```bash
23
- # npm
24
- npm install vana-sdk
25
-
26
- # yarn
27
- yarn add vana-sdk
28
-
29
- # pnpm
30
- pnpm add vana-sdk
20
+ npm install @opendatalabs/vana-sdk
31
21
  ```
32
22
 
33
23
  **Peer Dependencies:**
@@ -38,13 +28,15 @@ npm install viem@^2.31.7
38
28
 
39
29
  ## Quick Start
40
30
 
41
- ### Basic Setup
31
+ The Vana SDK supports both browser and Node.js environments with explicit entry points:
32
+
33
+ ### Browser Applications (React, Vue, etc.)
42
34
 
43
35
  ```typescript
44
- import { Vana } from "vana-sdk";
36
+ // For browser-based applications (React, Vue, etc.)
37
+ import { Vana, mokshaTestnet } from "@opendatalabs/vana-sdk/browser";
45
38
  import { createWalletClient, http } from "viem";
46
39
  import { privateKeyToAccount } from "viem/accounts";
47
- import { mokshaTestnet } from "vana-sdk";
48
40
 
49
41
  // Create wallet client
50
42
  const account = privateKeyToAccount("0x...");
@@ -54,104 +46,138 @@ const walletClient = createWalletClient({
54
46
  transport: http("https://rpc.moksha.vana.org"),
55
47
  });
56
48
 
57
- // Initialize Vana SDK
58
- const vana = new Vana({
49
+ // Initialize SDK
50
+ const vana = Vana({
59
51
  walletClient,
60
- // Optional: configure gasless relayer
61
52
  relayerUrl: "https://relayer.moksha.vana.org",
62
53
  });
63
54
  ```
64
55
 
65
- ### Grant Data Permission (Gasless)
56
+ ### Server-side Applications (Next.js API routes, Express)
66
57
 
67
58
  ```typescript
68
- // Grant permission for an AI application to access user data
59
+ // For server-side applications (Next.js API routes, Express)
60
+ import { Vana, mokshaTestnet } from "@opendatalabs/vana-sdk/node";
61
+ import { createWalletClient, http } from "viem";
62
+ import { privateKeyToAccount } from "viem/accounts";
63
+
64
+ // Create wallet client
65
+ const account = privateKeyToAccount("0x...");
66
+ const walletClient = createWalletClient({
67
+ account,
68
+ chain: mokshaTestnet,
69
+ transport: http("https://rpc.moksha.vana.org"),
70
+ });
71
+
72
+ // Initialize SDK
73
+ const vana = Vana({
74
+ walletClient,
75
+ relayerUrl: "https://relayer.moksha.vana.org",
76
+ });
77
+
78
+ // Grant gasless permission
69
79
  const txHash = await vana.permissions.grant({
70
- to: "0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36", // Application address
80
+ grantee: "0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36",
71
81
  operation: "llm_inference",
72
82
  parameters: {
73
- prompt: "Analyze my browsing data for insights",
83
+ prompt: "Analyze my data for insights",
74
84
  maxTokens: 1000,
75
- files: [12, 15, 28], // Specific file IDs
76
- model: "gpt-4",
77
85
  },
78
- expiresAt: Math.floor(Date.now() / 1000) + 24 * 60 * 60, // 24 hours
86
+ expiresAt: Math.floor(Date.now() / 1000) + 86400, // 24 hours
79
87
  });
88
+ ```
89
+
90
+ ## Core Features
91
+
92
+ ### Gasless Permissions
93
+
94
+ Users can grant data access permissions without paying gas fees through EIP-712 signatures and relay infrastructure.
80
95
 
81
- console.log("Permission granted:", txHash);
96
+ ```typescript
97
+ // Grant permission with custom parameters
98
+ await vana.permissions.grant({
99
+ grantee: applicationAddress,
100
+ operation: "data_analysis",
101
+ parameters: {
102
+ analysisType: "sentiment",
103
+ files: [12, 15, 28],
104
+ model: "gpt-4",
105
+ },
106
+ });
82
107
  ```
83
108
 
84
- ### Query User Data Files
109
+ ### Encrypted Data Management
110
+
111
+ Upload, query, and manage encrypted user data files with built-in schema validation.
85
112
 
86
113
  ```typescript
87
- // Get all files owned by a user
114
+ // Query user files
88
115
  const files = await vana.data.getUserFiles({
89
- user: "0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36",
116
+ owner: "0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36",
90
117
  });
91
118
 
92
- files.forEach((file) => {
93
- console.log(`File ${file.id}: ${file.url}`);
94
- console.log(`Schema: ${file.schemaId}, Added: ${file.addedAtBlock}`);
119
+ // Upload encrypted file with decryption permissions
120
+ const result = await vana.data.upload({
121
+ content: "Sensitive user data",
122
+ filename: "user-data.json",
123
+ schemaId: 123,
124
+ permissions: [
125
+ {
126
+ account: "0xServerAddress...", // Who can decrypt
127
+ publicKey: "0x04ServerKey...", // Their public key
128
+ },
129
+ ],
95
130
  });
96
131
  ```
97
132
 
98
- ### Upload Encrypted File
133
+ ### Flexible Storage
134
+
135
+ Abstract storage layer supporting IPFS, Google Drive, and custom providers.
99
136
 
100
137
  ```typescript
101
- // Generate encryption key from wallet
102
- const encryptionKey = await generateEncryptionKey(walletClient);
138
+ // For browser applications
139
+ import { StorageManager, PinataStorage } from "@opendatalabs/vana-sdk/browser";
140
+ // OR for server-side applications
141
+ // import { StorageManager, PinataStorage } from "@opendatalabs/vana-sdk/node";
103
142
 
104
- // Encrypt user data
105
- const userData = new Blob([
106
- JSON.stringify({
107
- browsing_history: [{ url: "https://example.com", timestamp: Date.now() }],
143
+ const storageManager = new StorageManager();
144
+ storageManager.register(
145
+ "ipfs",
146
+ new PinataStorage({
147
+ apiKey: process.env.PINATA_API_KEY,
148
+ secretKey: process.env.PINATA_SECRET_KEY,
108
149
  }),
109
- ]);
110
-
111
- const encryptedData = await encryptUserData(userData, encryptionKey);
112
-
113
- // Upload to IPFS and register on-chain
114
- const result = await vana.data.uploadEncryptedFile({
115
- data: encryptedData,
116
- schemaId: 123, // JSON schema for browsing data
117
- filename: "browsing-data.json",
118
- });
119
-
120
- console.log("File uploaded:", result.fileId, result.url);
150
+ );
121
151
  ```
122
152
 
123
153
  ## Architecture
124
154
 
125
- The Vana SDK follows a resource-oriented architecture with five main controllers:
126
-
127
- ### Core Controllers
155
+ The SDK provides four main controllers:
128
156
 
129
- | Controller | Purpose | Key Methods |
130
- | ---------------------- | --------------------------------------- | ----------------------------------------------------------------- |
131
- | **`vana.permissions`** | Gasless permission grants & revocations | `grant()`, `revoke()`, `getUserPermissions()` |
132
- | **`vana.data`** | Data file management & encryption | `getUserFiles()`, `uploadEncryptedFile()`, `validateDataSchema()` |
133
- | **`vana.server`** | Trusted server management | `trustServer()`, `untrustServer()`, `processWithTrustedServer()` |
134
- | **`vana.protocol`** | Low-level contract access | `getContract()`, `getAvailableContracts()` |
157
+ | Controller | Purpose | Key Methods |
158
+ | ------------- | ------------------------------ | ----------------------------------------------------------------- |
159
+ | `permissions` | Gasless permission management | `grant()`, `revoke()`, `getUserPermissions()` |
160
+ | `data` | File management and validation | `getUserFiles()`, `uploadEncryptedFile()`, `validateDataSchema()` |
161
+ | `server` | Trusted server operations | `trustServer()`, `processWithTrustedServer()` |
162
+ | `protocol` | Contract interaction | `getContract()`, `getAvailableContracts()` |
135
163
 
136
- ### Configuration Options
164
+ ## Configuration
137
165
 
138
166
  ```typescript
139
- const vana = new Vana({
140
- // Required: Wallet client for signing
167
+ const vana = Vana({
141
168
  walletClient,
142
169
 
143
- // Optional: Gasless transaction relay
144
- relayerUrl: "https://custom-relayer.com",
170
+ // Gasless transaction relay
171
+ relayerUrl: "https://relayer.moksha.vana.org",
145
172
 
146
- // Optional: Custom callback-based relaying
173
+ // Custom relay callbacks
147
174
  relayerCallbacks: {
148
175
  submitPermissionGrant: async (typedData, signature) => {
149
- // Custom relay implementation
150
176
  return await customRelayer.submit(typedData, signature);
151
177
  },
152
178
  },
153
179
 
154
- // Optional: Storage configuration
180
+ // Storage configuration
155
181
  storageManager: new StorageManager({
156
182
  defaultProvider: "ipfs",
157
183
  providers: {
@@ -159,63 +185,92 @@ const vana = new Vana({
159
185
  },
160
186
  }),
161
187
 
162
- // Optional: Subgraph for efficient data queries
188
+ // Subgraph for efficient queries
163
189
  subgraphUrl: "https://api.thegraph.com/subgraphs/name/vana/moksha",
164
190
  });
165
191
  ```
166
192
 
167
- ## Core Concepts
168
-
169
- ### Gasless Permissions
193
+ ## Error Handling
170
194
 
171
- The Vana SDK enables applications to request data access permissions without users paying gas fees:
195
+ The SDK provides specific error types for different failure scenarios:
172
196
 
173
197
  ```typescript
174
- // Complete gasless permission flow
175
- const permission = await vana.permissions.grant({
176
- to: applicationAddress,
177
- operation: "data_analysis",
178
- parameters: {
179
- // Structured parameters for the operation
180
- analysisType: "sentiment",
181
- outputFormat: "json",
182
- maxDataPoints: 1000,
183
- },
184
- });
198
+ import {
199
+ RelayerError,
200
+ UserRejectedRequestError,
201
+ SchemaValidationError,
202
+ NetworkError,
203
+ } from "@opendatalabs/vana-sdk/browser";
204
+ // OR for server-side applications
205
+ // } from "@opendatalabs/vana-sdk/node";
185
206
 
186
- // The SDK handles:
187
- // 1. Parameter serialization & IPFS storage
188
- // 2. EIP-712 typed data creation
189
- // 3. User signature via wallet
190
- // 4. Relayer submission & gas payment
191
- // 5. On-chain permission registration
207
+ try {
208
+ await vana.permissions.grant(params);
209
+ } catch (error) {
210
+ if (error instanceof UserRejectedRequestError) {
211
+ // User cancelled transaction
212
+ } else if (error instanceof RelayerError) {
213
+ // Relayer service error
214
+ } else if (error instanceof SchemaValidationError) {
215
+ // Schema validation failed
216
+ }
217
+ }
192
218
  ```
193
219
 
194
- ### Data File Management
220
+ ## Supported Networks
195
221
 
196
- Query and manage encrypted user data files using the subgraph for efficiency:
222
+ | Network | Chain ID | RPC URL |
223
+ | ------------------ | -------- | ----------------------------- |
224
+ | **Vana Mainnet** | `1480` | `https://rpc.vana.org` |
225
+ | **Moksha Testnet** | `14800` | `https://rpc.moksha.vana.org` |
226
+
227
+ ## Examples
228
+
229
+ ### Complete Data Sharing Flow
197
230
 
198
231
  ```typescript
199
- // Efficiently query user files (no contract scanning)
200
- const files = await vana.data.getUserFiles({
201
- user: userAddress,
202
- // Optional: override subgraph URL
203
- subgraphUrl: "https://custom-subgraph.com/graphql",
204
- });
232
+ import { Vana } from "@opendatalabs/vana-sdk/browser";
233
+ // OR for server-side applications
234
+ // } from "@opendatalabs/vana-sdk/node";
235
+
236
+ async function shareDataWithServer() {
237
+ const vana = Vana({ walletClient });
238
+
239
+ // Step 1: Upload encrypted file with decryption permissions
240
+ const uploadResult = await vana.data.upload({
241
+ content: { data: "sensitive medical records" },
242
+ filename: "health-data.json",
243
+ schemaId: 123,
244
+ permissions: [
245
+ {
246
+ // Grant decryption access to the AI server
247
+ account: "0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36",
248
+ publicKey: "0x04abc...", // Server's public key for encryption
249
+ },
250
+ ],
251
+ });
205
252
 
206
- // Files are automatically deduplicated by ID
207
- // Latest timestamp wins for duplicate file IDs
208
- console.log(`Found ${files.length} unique files`);
253
+ // Step 2: Grant operation permissions for what the server can do
254
+ const permissionResult = await vana.permissions.grant({
255
+ grantee: "0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36",
256
+ fileIds: [BigInt(uploadResult.fileId)],
257
+ operation: "medical_analysis",
258
+ parameters: {
259
+ model: "medical-ai-v2",
260
+ analysisType: "comprehensive",
261
+ },
262
+ });
263
+
264
+ return { uploadResult, permissionResult };
265
+ }
209
266
  ```
210
267
 
211
268
  ### Schema Validation
212
269
 
213
- Built-in support for validating data schemas and user data:
214
-
215
270
  ```typescript
216
- // Validate a data schema against Vana meta-schema
271
+ // Define data schema
217
272
  const schema = {
218
- name: "Instagram Export",
273
+ name: "Social Media Export",
219
274
  version: "1.0.0",
220
275
  dialect: "json",
221
276
  schema: {
@@ -224,345 +279,130 @@ const schema = {
224
279
  posts: { type: "array" },
225
280
  profile: { type: "object" },
226
281
  },
282
+ required: ["profile"],
227
283
  },
228
284
  };
229
285
 
286
+ // Validate schema
230
287
  vana.data.validateDataSchema(schema);
231
288
 
232
- // Validate user data against the schema
233
- const userData = { posts: [], profile: { username: "alice" } };
289
+ // Validate user data
290
+ const userData = {
291
+ profile: { username: "alice" },
292
+ posts: [],
293
+ };
234
294
  vana.data.validateDataAgainstSchema(userData, schema);
235
295
  ```
236
296
 
237
- ### Flexible Relay System
238
-
239
- Configure gasless transactions using callbacks instead of fixed HTTP APIs:
240
-
241
- ```typescript
242
- const vana = new Vana({
243
- walletClient,
244
- relayerCallbacks: {
245
- // Custom permission grant relaying
246
- submitPermissionGrant: async (typedData, signature) => {
247
- const response = await fetch("/api/relay/grant", {
248
- method: "POST",
249
- body: JSON.stringify({ typedData, signature }),
250
- });
251
- const result = await response.json();
252
- return result.transactionHash;
253
- },
254
-
255
- // Custom revocation relaying
256
- submitPermissionRevoke: async (typedData, signature) => {
257
- return await myCustomRelayer.revoke(typedData, signature);
258
- },
259
- },
260
- });
261
- ```
262
-
263
297
  ## API Reference
264
298
 
265
- ### Permissions Controller
299
+ ### Permissions
266
300
 
267
301
  ```typescript
268
- // Grant permission (gasless)
302
+ // Grant operation permission
269
303
  await vana.permissions.grant({
270
- to: Address, // Application address
271
- operation: string, // Operation type
272
- parameters: object, // Operation parameters
273
- expiresAt?: number // Optional expiration timestamp
274
- }): Promise<Hash>
275
-
276
- // Revoke permission (gasless)
304
+ grantee: Address,
305
+ fileIds: bigint[],
306
+ operation: string,
307
+ parameters: object,
308
+ expiresAt?: number
309
+ }): Promise<PermissionGrantResult>
310
+
311
+ // Revoke permission
277
312
  await vana.permissions.revoke({
278
- grantId: string, // Grant ID to revoke
279
- nonce?: bigint // Optional nonce override
313
+ grantId: string
280
314
  }): Promise<Hash>
281
315
 
282
- // Query user permissions
316
+ // Get user permissions
283
317
  await vana.permissions.getUserPermissions({
284
- user: Address, // User address
285
- subgraphUrl?: string // Optional subgraph override
318
+ owner: Address
286
319
  }): Promise<GrantedPermission[]>
287
-
288
- // Trust a server
289
- await vana.permissions.trustServer({
290
- serverAddress: Address, // Server's address
291
- serverUrl: string // Server's URL
292
- }): Promise<Hash>
293
320
  ```
294
321
 
295
- ### Data Controller
322
+ ### Data
296
323
 
297
324
  ```typescript
298
325
  // Get user files
299
326
  await vana.data.getUserFiles({
300
- user: Address, // File owner address
301
- subgraphUrl?: string // Optional subgraph override
327
+ owner: Address
302
328
  }): Promise<UserFile[]>
303
329
 
304
- // Upload encrypted file
305
- await vana.data.uploadEncryptedFile({
306
- data: Blob, // Encrypted file data
307
- schemaId?: number, // Optional schema ID
308
- filename?: string // Optional filename
309
- }): Promise<UploadEncryptedFileResult>
310
-
311
- // Validate data schema
312
- vana.data.validateDataSchema(
313
- schema: unknown // Schema to validate
314
- ): asserts schema is DataSchema
330
+ // Upload data with automatic encryption
331
+ await vana.data.upload({
332
+ content: string | Blob | Buffer,
333
+ filename?: string,
334
+ schemaId?: number,
335
+ permissions?: Array<{
336
+ account: Address, // Who can decrypt
337
+ publicKey: string // Their public key
338
+ }>,
339
+ encrypt?: boolean // Default: true
340
+ }): Promise<UploadResult>
341
+
342
+ // Validate schema
343
+ vana.data.validateDataSchema(schema: unknown): void
315
344
 
316
345
  // Validate data against schema
317
- vana.data.validateDataAgainstSchema(
318
- data: unknown, // Data to validate
319
- schema: DataSchema // Data schema
320
- ): void
321
-
322
- // Fetch and validate remote schema
323
- await vana.data.fetchAndValidateSchema(
324
- url: string // Schema URL
325
- ): Promise<DataSchema>
326
- ```
327
-
328
- ### Server Controller
329
-
330
- ```typescript
331
- // Process data with trusted server
332
- await vana.server.processWithTrustedServer({
333
- serverUrl: string, // Trusted server URL
334
- operation: string, // Operation to perform
335
- parameters: object // Operation parameters
336
- }): Promise<any>
337
-
338
- // Check server trust status
339
- await vana.server.isServerTrusted({
340
- user: Address, // User address
341
- serverAddress: Address // Server address
342
- }): Promise<boolean>
343
- ```
344
-
345
- ### Protocol Controller
346
-
347
- ```typescript
348
- // Get contract information
349
- vana.protocol.getContract(
350
- contractName: VanaContract // Contract name
351
- ): ContractInfo
352
-
353
- // List available contracts
354
- vana.protocol.getAvailableContracts(): VanaContract[]
355
-
356
- // Get contract addresses for chain
357
- vana.protocol.getChainContracts(
358
- chainId: number // Chain ID
359
- ): Record<VanaContract, Address>
360
- ```
361
-
362
- ## Storage Integration
363
-
364
- The SDK includes a powerful storage abstraction supporting multiple providers:
365
-
366
- ### IPFS Storage
367
-
368
- ```typescript
369
- import { StorageManager, PinataStorage } from "vana-sdk";
370
-
371
- const storageManager = new StorageManager();
372
-
373
- // Configure Pinata IPFS
374
- const pinataStorage = new PinataStorage({
375
- apiKey: process.env.PINATA_API_KEY,
376
- secretKey: process.env.PINATA_SECRET_KEY,
377
- gatewayUrl: "https://gateway.pinata.cloud/ipfs",
378
- });
379
-
380
- storageManager.register("ipfs", pinataStorage, true); // Default provider
381
-
382
- // Upload file
383
- const result = await storageManager.upload(encryptedBlob, "encrypted-data.bin");
384
- ```
385
-
386
- ### Google Drive Storage
387
-
388
- ```typescript
389
- import { StorageManager, GoogleDriveStorage } from "vana-sdk";
390
-
391
- const googleDriveStorage = new GoogleDriveStorage({
392
- accessToken: process.env.GOOGLE_DRIVE_ACCESS_TOKEN,
393
- refreshToken: process.env.GOOGLE_DRIVE_REFRESH_TOKEN,
394
- clientId: process.env.GOOGLE_DRIVE_CLIENT_ID,
395
- clientSecret: process.env.GOOGLE_DRIVE_CLIENT_SECRET,
396
- });
397
-
398
- storageManager.register("google-drive", googleDriveStorage);
399
- ```
400
-
401
- ### Custom Storage Provider
402
-
403
- ```typescript
404
- class CustomStorage implements StorageProvider {
405
- async upload(file: Blob, filename?: string): Promise<StorageUploadResult> {
406
- // Custom upload logic
407
- return { url: "custom://uploaded-file", size: file.size };
408
- }
409
-
410
- async download(url: string): Promise<Blob> {
411
- // Custom download logic
412
- }
413
-
414
- // ... other required methods
415
- }
416
-
417
- storageManager.register("custom", new CustomStorage());
418
- ```
419
-
420
- ## Error Handling
421
-
422
- The SDK provides comprehensive error handling with specific error types:
423
-
424
- ```typescript
425
- import {
426
- RelayerError,
427
- UserRejectedRequestError,
428
- SchemaValidationError,
429
- InvalidConfigurationError,
430
- NetworkError,
431
- } from "vana-sdk";
432
-
433
- try {
434
- await vana.permissions.grant(params);
435
- } catch (error) {
436
- if (error instanceof UserRejectedRequestError) {
437
- // User rejected the signature request
438
- console.log("User cancelled transaction");
439
- } else if (error instanceof RelayerError) {
440
- // Relayer service error
441
- console.log(`Relayer error (${error.statusCode}): ${error.message}`);
442
- } else if (error instanceof SchemaValidationError) {
443
- // Schema validation failed
444
- console.log(`Schema error: ${error.message}`);
445
- } else if (error instanceof NetworkError) {
446
- // Network connectivity issue
447
- console.log(`Network error: ${error.message}`);
448
- } else {
449
- // Unexpected error
450
- console.error("Unexpected error:", error);
451
- }
452
- }
346
+ vana.data.validateDataAgainstSchema(data: unknown, schema: DataSchema): void
453
347
  ```
454
348
 
455
- ## Supported Networks
456
-
457
- | Network | Chain ID | RPC URL | Explorer |
458
- | ------------------ | -------- | ----------------------------- | ------------------------------------------------ |
459
- | **Vana Mainnet** | `1480` | `https://rpc.vana.org` | [vanascan.io](https://vanascan.io) |
460
- | **Moksha Testnet** | `14800` | `https://rpc.moksha.vana.org` | [moksha.vanascan.io](https://moksha.vanascan.io) |
349
+ ## Documentation
461
350
 
462
- ### Adding Networks to Wallet
351
+ - [API Documentation](https://vana-com.github.io/vana-sdk) - Complete TypeDoc API reference
352
+ - [Getting Started](https://vana-com.github.io/vana-sdk/getting-started) - Step-by-step setup guide
353
+ - [Architecture](https://vana-com.github.io/vana-sdk/architecture) - SDK design and patterns
354
+ - [Configuration](https://vana-com.github.io/vana-sdk/configuration) - All configuration options
355
+ - [Security](https://vana-com.github.io/vana-sdk/security) - Best practices and security
463
356
 
464
- **Moksha Testnet:**
357
+ ## Support
465
358
 
466
- ```
467
- Network Name: Vana Moksha Testnet
468
- RPC URL: https://rpc.moksha.vana.org
469
- Chain ID: 14800
470
- Currency Symbol: VANA
471
- Block Explorer: https://moksha.vanascan.io
472
- ```
359
+ - **Documentation**: [vana-com.github.io/vana-sdk](https://vana-com.github.io/vana-sdk)
360
+ - **Issues**: [GitHub Issues](https://github.com/vana-com/vana-sdk/issues)
361
+ - **Discord**: [Join our community](https://discord.gg/vanabuilders)
473
362
 
474
- ## Examples
363
+ ## Generated Code
475
364
 
476
- ### Complete Permission Flow
365
+ The SDK includes automatically generated code from various sources to provide type-safe interfaces. All generated files are located in `src/generated/` and should **never be edited manually**.
477
366
 
478
- ```typescript
479
- import { Vana, generateEncryptionKey, encryptUserData } from "vana-sdk";
367
+ ### Code Generation Scripts
480
368
 
481
- async function completePermissionFlow() {
482
- // 1. Initialize SDK
483
- const vana = new Vana({ walletClient });
369
+ | Script | Purpose | Generated Files |
370
+ | ---------------------------- | -------------------------------------- | --------------------------- |
371
+ | `npm run fetch-abis` | Smart contract ABIs from blockchain | `src/generated/abi/*.ts` |
372
+ | `npm run fetch-server-types` | Personal server API types from OpenAPI | `src/generated/server/*.ts` |
373
+ | `npm run codegen:subgraph` | GraphQL types from subgraph schema | `src/generated/subgraph.ts` |
484
374
 
485
- // 2. Encrypt user data
486
- const encryptionKey = await generateEncryptionKey(walletClient);
487
- const userData = new Blob([JSON.stringify({ data: "sensitive info" })]);
488
- const encryptedData = await encryptUserData(userData, encryptionKey);
375
+ ### Network-Specific Generation
489
376
 
490
- // 3. Upload encrypted file
491
- const uploadResult = await vana.data.uploadEncryptedFile({
492
- data: encryptedData,
493
- schemaId: 123,
494
- filename: "user-data.json",
495
- });
377
+ Some generation scripts support different networks:
496
378
 
497
- // 4. Grant permission to access the file
498
- const permissionTx = await vana.permissions.grant({
499
- to: "0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36",
500
- operation: "ai_training",
501
- parameters: {
502
- files: [uploadResult.fileId],
503
- model: "llm-v1",
504
- maxTokens: 500,
505
- },
506
- });
379
+ ```bash
380
+ # Generate subgraph types for different networks
381
+ npm run codegen:subgraph:moksha # Moksha testnet (default)
382
+ npm run codegen:subgraph:mainnet # Vana mainnet
507
383
 
508
- console.log("Permission granted:", permissionTx);
509
- }
384
+ # Generate ABIs for different networks
385
+ npm run fetch-abis moksha # Moksha testnet (default)
386
+ npm run fetch-abis mainnet # Vana mainnet
510
387
  ```
511
388
 
512
- ### Schema Validation Example
513
-
514
- ```typescript
515
- // Define a data schema
516
- const instagramSchema = {
517
- name: "Instagram Export",
518
- version: "1.0.0",
519
- description: "User's Instagram profile and posts data",
520
- dialect: "json",
521
- schema: {
522
- type: "object",
523
- properties: {
524
- profile: {
525
- type: "object",
526
- properties: {
527
- username: { type: "string" },
528
- followers: { type: "number" },
529
- verified: { type: "boolean" },
530
- },
531
- required: ["username"],
532
- },
533
- posts: {
534
- type: "array",
535
- items: {
536
- type: "object",
537
- properties: {
538
- id: { type: "string" },
539
- likes: { type: "number" },
540
- caption: { type: "string" },
541
- },
542
- },
543
- },
544
- },
545
- required: ["profile"],
546
- },
547
- };
389
+ ### Development Workflow
548
390
 
549
- // Validate the schema
550
- vana.data.validateDataSchema(instagramSchema);
391
+ When working with the SDK:
551
392
 
552
- // Validate user data against the schema
553
- const userData = {
554
- profile: { username: "alice_smith", followers: 1500, verified: false },
555
- posts: [{ id: "post_123", likes: 42, caption: "Beautiful sunset! 🌅" }],
556
- };
393
+ 1. **Never edit generated files** - They are overwritten on regeneration
394
+ 2. **Regenerate after schema changes** - Run generation scripts when external schemas change
395
+ 3. **Generated files are committed** - They're included in version control for consistency
396
+ 4. **ESLint ignores generated code** - Style rules don't apply to generated files
557
397
 
558
- vana.data.validateDataAgainstSchema(userData, instagramSchema);
398
+ ```bash
399
+ # Regenerate all code after schema updates
400
+ npm run fetch-abis
401
+ npm run fetch-server-types
402
+ npm run codegen:subgraph
559
403
  ```
560
404
 
561
- ## Contributing
562
-
563
- We welcome contributions to the Vana SDK! Please see our [Contributing Guide](../../CONTRIBUTING.md) for details.
564
-
565
- ### Development Setup
405
+ ## Development
566
406
 
567
407
  ```bash
568
408
  git clone https://github.com/vana-com/vana-sdk.git
@@ -572,29 +412,6 @@ npm run build
572
412
  npm test
573
413
  ```
574
414
 
575
- ### Running Examples
576
-
577
- ```bash
578
- cd examples/vana-sdk-demo
579
- npm install
580
- npm run dev
581
- ```
582
-
583
- ## Documentation
584
-
585
- - [📚 API Documentation](https://vana-com.github.io/vana-sdk) - Complete TypeDoc API reference
586
- - [🚀 Getting Started Guide](https://docs.vana.org/vana-sdk) - Step-by-step setup
587
- - [🏗️ Architecture Guide](https://docs.vana.org/vana-sdk/architecture) - SDK design and patterns
588
- - [🔧 Configuration Guide](https://docs.vana.org/vana-sdk/configuration) - All configuration options
589
- - [🔒 Security Guide](https://docs.vana.org/vana-sdk/security) - Best practices and security
590
-
591
- ## Support
592
-
593
- - **📖 Documentation**: [API Reference](https://vana-com.github.io/vana-sdk)
594
- - **💬 Discord**: [Join our community](https://discord.gg/vanabuilders)
595
- - **🐛 Issues**: [GitHub Issues](https://github.com/vana-com/vana-sdk/issues)
596
- - **📧 Email**: [support@vana.org](mailto:support@vana.org)
597
-
598
415
  ## License
599
416
 
600
417
  [ISC License](LICENSE) © Vana Foundation