@opendatalabs/vana-sdk 0.1.0-alpha.05db05d

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 (58) hide show
  1. package/LICENSE +15 -0
  2. package/README.md +417 -0
  3. package/dist/browser-DY8XDblx.d.ts +241 -0
  4. package/dist/browser.d.ts +1 -0
  5. package/dist/browser.js +309 -0
  6. package/dist/browser.js.map +1 -0
  7. package/dist/chains.browser.cjs +96 -0
  8. package/dist/chains.browser.cjs.map +1 -0
  9. package/dist/chains.browser.d.cts +53 -0
  10. package/dist/chains.browser.d.ts +53 -0
  11. package/dist/chains.browser.js +65 -0
  12. package/dist/chains.browser.js.map +1 -0
  13. package/dist/chains.cjs +96 -0
  14. package/dist/chains.cjs.map +1 -0
  15. package/dist/chains.d.cts +2 -0
  16. package/dist/chains.d.ts +2 -0
  17. package/dist/chains.js +65 -0
  18. package/dist/chains.js.map +1 -0
  19. package/dist/chains.node.cjs +96 -0
  20. package/dist/chains.node.cjs.map +1 -0
  21. package/dist/chains.node.d.cts +2 -0
  22. package/dist/chains.node.d.ts +2 -0
  23. package/dist/chains.node.js +65 -0
  24. package/dist/chains.node.js.map +1 -0
  25. package/dist/index.browser.d.ts +36732 -0
  26. package/dist/index.browser.js +45952 -0
  27. package/dist/index.browser.js.map +1 -0
  28. package/dist/index.d.cts +2 -0
  29. package/dist/index.node.cjs +46471 -0
  30. package/dist/index.node.cjs.map +1 -0
  31. package/dist/index.node.d.cts +36870 -0
  32. package/dist/index.node.d.ts +36870 -0
  33. package/dist/index.node.js +46331 -0
  34. package/dist/index.node.js.map +1 -0
  35. package/dist/node-D9-F9uEP.d.cts +238 -0
  36. package/dist/node-D9-F9uEP.d.ts +238 -0
  37. package/dist/node.cjs +348 -0
  38. package/dist/node.cjs.map +1 -0
  39. package/dist/node.d.cts +1 -0
  40. package/dist/node.d.ts +1 -0
  41. package/dist/node.js +311 -0
  42. package/dist/node.js.map +1 -0
  43. package/dist/platform.browser.d.ts +60 -0
  44. package/dist/platform.browser.js +388 -0
  45. package/dist/platform.browser.js.map +1 -0
  46. package/dist/platform.cjs +744 -0
  47. package/dist/platform.cjs.map +1 -0
  48. package/dist/platform.d.cts +2 -0
  49. package/dist/platform.d.ts +2 -0
  50. package/dist/platform.js +707 -0
  51. package/dist/platform.js.map +1 -0
  52. package/dist/platform.node.cjs +744 -0
  53. package/dist/platform.node.cjs.map +1 -0
  54. package/dist/platform.node.d.cts +105 -0
  55. package/dist/platform.node.d.ts +105 -0
  56. package/dist/platform.node.js +707 -0
  57. package/dist/platform.node.js.map +1 -0
  58. package/package.json +135 -0
package/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ ISC License
2
+
3
+ Copyright (c) 2025, Vana
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,417 @@
1
+ # Vana SDK
2
+
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.
8
+
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)
12
+ [![TypeScript](https://img.shields.io/badge/TypeScript-Ready-blue)](https://www.typescriptlang.org/)
13
+ [![License: ISC](https://img.shields.io/badge/License-ISC-green.svg)](https://opensource.org/licenses/ISC)
14
+
15
+ [API Documentation](https://vana-com.github.io/vana-sdk) • [Examples](#examples) • [Configuration](#configuration)
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ npm install @opendatalabs/vana-sdk
21
+ ```
22
+
23
+ **Peer Dependencies:**
24
+
25
+ ```bash
26
+ npm install viem@^2.31.7
27
+ ```
28
+
29
+ ## Quick Start
30
+
31
+ The Vana SDK supports both browser and Node.js environments with explicit entry points:
32
+
33
+ ### Browser Applications (React, Vue, etc.)
34
+
35
+ ```typescript
36
+ // For browser-based applications (React, Vue, etc.)
37
+ import { Vana, mokshaTestnet } from "@opendatalabs/vana-sdk/browser";
38
+ import { createWalletClient, http } from "viem";
39
+ import { privateKeyToAccount } from "viem/accounts";
40
+
41
+ // Create wallet client
42
+ const account = privateKeyToAccount("0x...");
43
+ const walletClient = createWalletClient({
44
+ account,
45
+ chain: mokshaTestnet,
46
+ transport: http("https://rpc.moksha.vana.org"),
47
+ });
48
+
49
+ // Initialize SDK
50
+ const vana = Vana({
51
+ walletClient,
52
+ relayerUrl: "https://relayer.moksha.vana.org",
53
+ });
54
+ ```
55
+
56
+ ### Server-side Applications (Next.js API routes, Express)
57
+
58
+ ```typescript
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
79
+ const txHash = await vana.permissions.grant({
80
+ grantee: "0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36",
81
+ operation: "llm_inference",
82
+ parameters: {
83
+ prompt: "Analyze my data for insights",
84
+ maxTokens: 1000,
85
+ },
86
+ expiresAt: Math.floor(Date.now() / 1000) + 86400, // 24 hours
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.
95
+
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
+ });
107
+ ```
108
+
109
+ ### Encrypted Data Management
110
+
111
+ Upload, query, and manage encrypted user data files with built-in schema validation.
112
+
113
+ ```typescript
114
+ // Query user files
115
+ const files = await vana.data.getUserFiles({
116
+ owner: "0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36",
117
+ });
118
+
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
+ ],
130
+ });
131
+ ```
132
+
133
+ ### Flexible Storage
134
+
135
+ Abstract storage layer supporting IPFS, Google Drive, and custom providers.
136
+
137
+ ```typescript
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";
142
+
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,
149
+ }),
150
+ );
151
+ ```
152
+
153
+ ## Architecture
154
+
155
+ The SDK provides four main controllers:
156
+
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()` |
163
+
164
+ ## Configuration
165
+
166
+ ```typescript
167
+ const vana = Vana({
168
+ walletClient,
169
+
170
+ // Gasless transaction relay
171
+ relayerUrl: "https://relayer.moksha.vana.org",
172
+
173
+ // Custom relay callbacks
174
+ relayerCallbacks: {
175
+ submitPermissionGrant: async (typedData, signature) => {
176
+ return await customRelayer.submit(typedData, signature);
177
+ },
178
+ },
179
+
180
+ // Storage configuration
181
+ storageManager: new StorageManager({
182
+ defaultProvider: "ipfs",
183
+ providers: {
184
+ ipfs: new PinataStorage({ apiKey: "...", secretKey: "..." }),
185
+ },
186
+ }),
187
+
188
+ // Subgraph for efficient queries
189
+ subgraphUrl: "https://api.thegraph.com/subgraphs/name/vana/moksha",
190
+ });
191
+ ```
192
+
193
+ ## Error Handling
194
+
195
+ The SDK provides specific error types for different failure scenarios:
196
+
197
+ ```typescript
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";
206
+
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
+ }
218
+ ```
219
+
220
+ ## Supported Networks
221
+
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
230
+
231
+ ```typescript
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
+ });
252
+
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
+ }
266
+ ```
267
+
268
+ ### Schema Validation
269
+
270
+ ```typescript
271
+ // Define data schema
272
+ const schema = {
273
+ name: "Social Media Export",
274
+ version: "1.0.0",
275
+ dialect: "json",
276
+ schema: {
277
+ type: "object",
278
+ properties: {
279
+ posts: { type: "array" },
280
+ profile: { type: "object" },
281
+ },
282
+ required: ["profile"],
283
+ },
284
+ };
285
+
286
+ // Validate schema
287
+ vana.data.validateDataSchema(schema);
288
+
289
+ // Validate user data
290
+ const userData = {
291
+ profile: { username: "alice" },
292
+ posts: [],
293
+ };
294
+ vana.data.validateDataAgainstSchema(userData, schema);
295
+ ```
296
+
297
+ ## API Reference
298
+
299
+ ### Permissions
300
+
301
+ ```typescript
302
+ // Grant operation permission
303
+ await vana.permissions.grant({
304
+ grantee: Address,
305
+ fileIds: bigint[],
306
+ operation: string,
307
+ parameters: object,
308
+ expiresAt?: number
309
+ }): Promise<PermissionGrantResult>
310
+
311
+ // Revoke permission
312
+ await vana.permissions.revoke({
313
+ grantId: string
314
+ }): Promise<Hash>
315
+
316
+ // Get user permissions
317
+ await vana.permissions.getUserPermissions({
318
+ owner: Address
319
+ }): Promise<GrantedPermission[]>
320
+ ```
321
+
322
+ ### Data
323
+
324
+ ```typescript
325
+ // Get user files
326
+ await vana.data.getUserFiles({
327
+ owner: Address
328
+ }): Promise<UserFile[]>
329
+
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
344
+
345
+ // Validate data against schema
346
+ vana.data.validateDataAgainstSchema(data: unknown, schema: DataSchema): void
347
+ ```
348
+
349
+ ## Documentation
350
+
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
356
+
357
+ ## Support
358
+
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)
362
+
363
+ ## Generated Code
364
+
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**.
366
+
367
+ ### Code Generation Scripts
368
+
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` |
374
+
375
+ ### Network-Specific Generation
376
+
377
+ Some generation scripts support different networks:
378
+
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
383
+
384
+ # Generate ABIs for different networks
385
+ npm run fetch-abis moksha # Moksha testnet (default)
386
+ npm run fetch-abis mainnet # Vana mainnet
387
+ ```
388
+
389
+ ### Development Workflow
390
+
391
+ When working with the SDK:
392
+
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
397
+
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
403
+ ```
404
+
405
+ ## Development
406
+
407
+ ```bash
408
+ git clone https://github.com/vana-com/vana-sdk.git
409
+ cd vana-sdk
410
+ npm install
411
+ npm run build
412
+ npm test
413
+ ```
414
+
415
+ ## License
416
+
417
+ [ISC License](LICENSE) © Vana Foundation
@@ -0,0 +1,241 @@
1
+ /**
2
+ * Platform Adapter interface for environment-specific implementations
3
+ *
4
+ * This interface abstracts all environment-specific dependencies to ensure
5
+ * the SDK works seamlessly across Node.js and browser/SSR environments.
6
+ *
7
+ * **Implementation Context:**
8
+ * - Node.js: Uses native crypto modules and full OpenPGP support
9
+ * - Browser: Uses Web Crypto API and browser-compatible libraries
10
+ * - SSR: Automatically selects appropriate implementation based on runtime
11
+ *
12
+ * **Usage Notes:**
13
+ * Platform adapters are automatically selected by the SDK. Direct usage is only
14
+ * needed for custom implementations or testing.
15
+ */
16
+ /**
17
+ * Platform type identifier
18
+ */
19
+ type PlatformType = "node" | "browser";
20
+ /**
21
+ * Encryption operations that require different implementations per platform
22
+ */
23
+ interface VanaCryptoAdapter {
24
+ /**
25
+ * Encrypt data with a public key using asymmetric cryptography
26
+ *
27
+ * **Usage Context:**
28
+ * - Used internally for file encryption before storage
29
+ * - Public key format: Armored PGP public key string
30
+ * - Returns base64-encoded encrypted data
31
+ *
32
+ * @param data The data to encrypt
33
+ * @param publicKey The public key for encryption
34
+ * @returns Promise resolving to encrypted data
35
+ */
36
+ encryptWithPublicKey(data: string, publicKey: string): Promise<string>;
37
+ /**
38
+ * Decrypt data with a private key using asymmetric cryptography
39
+ *
40
+ * @param encryptedData The encrypted data
41
+ * @param privateKey The private key for decryption
42
+ * @returns Promise resolving to decrypted data
43
+ */
44
+ decryptWithPrivateKey(encryptedData: string, privateKey: string): Promise<string>;
45
+ /**
46
+ * Generate a new key pair for asymmetric cryptography
47
+ *
48
+ * @returns Promise resolving to public and private key pair
49
+ */
50
+ generateKeyPair(): Promise<{
51
+ publicKey: string;
52
+ privateKey: string;
53
+ }>;
54
+ /**
55
+ * Encrypt data with a wallet's public key using ECDH cryptography
56
+ * Uses platform-appropriate ECDH implementation (eccrypto vs eccrypto-js)
57
+ *
58
+ * **Usage Context:**
59
+ * - Used for sharing encryption keys with permission recipients
60
+ * - Public key format: Compressed or uncompressed secp256k1 hex string
61
+ * - Compatible with Ethereum wallet public keys
62
+ *
63
+ * @param data The data to encrypt (string)
64
+ * @param publicKey The wallet's public key (secp256k1)
65
+ * @returns Promise resolving to encrypted data as hex string
66
+ */
67
+ encryptWithWalletPublicKey(data: string, publicKey: string): Promise<string>;
68
+ /**
69
+ * Decrypt data with a wallet's private key using ECDH cryptography
70
+ * Uses platform-appropriate ECDH implementation (eccrypto vs eccrypto-js)
71
+ *
72
+ * @param encryptedData The encrypted data as hex string
73
+ * @param privateKey The wallet's private key (secp256k1)
74
+ * @returns Promise resolving to decrypted data as string
75
+ */
76
+ decryptWithWalletPrivateKey(encryptedData: string, privateKey: string): Promise<string>;
77
+ /**
78
+ * Encrypt data with a password using PGP password-based encryption
79
+ * Uses platform-appropriate OpenPGP implementation with consistent format
80
+ *
81
+ * @param data The data to encrypt as Uint8Array
82
+ * @param password The password for encryption (typically wallet signature)
83
+ * @returns Promise resolving to encrypted data as Uint8Array
84
+ */
85
+ encryptWithPassword(data: Uint8Array, password: string): Promise<Uint8Array>;
86
+ /**
87
+ * Decrypt data with a password using PGP password-based decryption
88
+ * Uses platform-appropriate OpenPGP implementation with consistent format
89
+ *
90
+ * @param encryptedData The encrypted data as Uint8Array
91
+ * @param password The password for decryption (typically wallet signature)
92
+ * @returns Promise resolving to decrypted data as Uint8Array
93
+ */
94
+ decryptWithPassword(encryptedData: Uint8Array, password: string): Promise<Uint8Array>;
95
+ }
96
+ /**
97
+ * PGP operations that require different configurations per platform
98
+ */
99
+ interface VanaPGPAdapter {
100
+ /**
101
+ * Encrypt data using PGP with proper platform configuration
102
+ *
103
+ * @param data The data to encrypt
104
+ * @param publicKey The PGP public key
105
+ * @returns Promise resolving to encrypted data
106
+ */
107
+ encrypt(data: string, publicKey: string): Promise<string>;
108
+ /**
109
+ * Decrypt data using PGP with proper platform configuration
110
+ *
111
+ * @param encryptedData The encrypted data
112
+ * @param privateKey The PGP private key
113
+ * @returns Promise resolving to decrypted data
114
+ */
115
+ decrypt(encryptedData: string, privateKey: string): Promise<string>;
116
+ /**
117
+ * Generate a new PGP key pair with platform-appropriate configuration
118
+ *
119
+ * @param options - Key generation options
120
+ * @param options.name - The name for the PGP key
121
+ * @param options.email - The email for the PGP key
122
+ * @param options.passphrase - Optional passphrase to protect the private key
123
+ * @returns Promise resolving to public and private key pair
124
+ */
125
+ generateKeyPair(options?: {
126
+ name?: string;
127
+ email?: string;
128
+ passphrase?: string;
129
+ }): Promise<{
130
+ publicKey: string;
131
+ privateKey: string;
132
+ }>;
133
+ }
134
+ /**
135
+ * HTTP operations that need consistent API across platforms
136
+ */
137
+ interface VanaHttpAdapter {
138
+ /**
139
+ * Perform HTTP request with platform-appropriate fetch implementation
140
+ *
141
+ * @param url The URL to request
142
+ * @param options Request options
143
+ * @returns Promise resolving to response
144
+ */
145
+ fetch(url: string, options?: RequestInit): Promise<Response>;
146
+ }
147
+ /**
148
+ * Simple cache operations that work across platforms
149
+ */
150
+ interface VanaCacheAdapter {
151
+ /**
152
+ * Get a value from the cache
153
+ *
154
+ * @param key The cache key
155
+ * @returns The cached value or null if not found/expired
156
+ */
157
+ get(key: string): string | null;
158
+ /**
159
+ * Set a value in the cache
160
+ *
161
+ * @param key The cache key
162
+ * @param value The value to cache
163
+ */
164
+ set(key: string, value: string): void;
165
+ /**
166
+ * Delete a value from the cache
167
+ *
168
+ * @param key The cache key
169
+ */
170
+ delete(key: string): void;
171
+ /**
172
+ * Clear all values from the cache
173
+ */
174
+ clear(): void;
175
+ }
176
+ /**
177
+ * Main platform adapter interface that combines all platform-specific functionality
178
+ *
179
+ * **Implementation Guidelines:**
180
+ * 1. All methods must maintain consistent behavior across platforms
181
+ * 2. Error types and messages should be unified
182
+ * 3. Data formats (encoding, serialization) must be identical
183
+ * 4. Performance characteristics can vary but API must be consistent
184
+ *
185
+ * **Custom Implementation Example:**
186
+ * ```typescript
187
+ * class CustomPlatformAdapter implements VanaPlatformAdapter {
188
+ * crypto = new CustomCryptoAdapter();
189
+ * pgp = new CustomPGPAdapter();
190
+ * http = new CustomHttpAdapter();
191
+ * platform = 'browser' as const;
192
+ * }
193
+ * ```
194
+ */
195
+ interface VanaPlatformAdapter {
196
+ /**
197
+ * Crypto operations adapter
198
+ */
199
+ crypto: VanaCryptoAdapter;
200
+ /**
201
+ * PGP operations adapter
202
+ */
203
+ pgp: VanaPGPAdapter;
204
+ /**
205
+ * HTTP operations adapter
206
+ */
207
+ http: VanaHttpAdapter;
208
+ /**
209
+ * Cache operations adapter
210
+ */
211
+ cache: VanaCacheAdapter;
212
+ /**
213
+ * Platform identifier for debugging/telemetry
214
+ */
215
+ readonly platform: PlatformType;
216
+ }
217
+
218
+ /**
219
+ * Browser implementation of the Vana Platform Adapter
220
+ *
221
+ * This implementation uses browser-compatible libraries and configurations
222
+ * to provide crypto, PGP, and HTTP functionality without Node.js dependencies.
223
+ *
224
+ * WARNING: Dependencies that access globals during init
225
+ * MUST be dynamically imported to support Turbopack.
226
+ * See: https://github.com/vercel/next.js/issues/82632
227
+ */
228
+
229
+ /**
230
+ * Complete browser platform adapter implementation
231
+ */
232
+ declare class BrowserPlatformAdapter implements VanaPlatformAdapter {
233
+ crypto: VanaCryptoAdapter;
234
+ pgp: VanaPGPAdapter;
235
+ http: VanaHttpAdapter;
236
+ cache: VanaCacheAdapter;
237
+ platform: "browser";
238
+ constructor();
239
+ }
240
+
241
+ export { BrowserPlatformAdapter as B, type PlatformType as P, type VanaPlatformAdapter as V };
@@ -0,0 +1 @@
1
+ export { B as BrowserPlatformAdapter } from './browser-DY8XDblx.js';