@opendatalabs/vana-sdk 0.1.0-alpha.d6bebb0 → 0.1.0-alpha.e0e85d7
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.
- package/README.md +98 -36
- package/dist/browser-Bb8gLWHp.d.ts +288 -0
- package/dist/browser.d.ts +1 -0
- package/dist/browser.js +822 -0
- package/dist/browser.js.map +1 -0
- package/dist/chains.browser.cjs +2 -2
- package/dist/chains.browser.cjs.map +1 -1
- package/dist/chains.browser.js +2 -2
- package/dist/chains.browser.js.map +1 -1
- package/dist/chains.cjs +2 -2
- package/dist/chains.cjs.map +1 -1
- package/dist/chains.js +2 -2
- package/dist/chains.js.map +1 -1
- package/dist/chains.node.cjs +2 -2
- package/dist/chains.node.cjs.map +1 -1
- package/dist/chains.node.js +2 -2
- package/dist/chains.node.js.map +1 -1
- package/dist/index.browser.d.ts +9806 -5202
- package/dist/index.browser.js +39099 -32782
- package/dist/index.browser.js.map +1 -1
- package/dist/index.node.cjs +39904 -33436
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.d.cts +9603 -5214
- package/dist/index.node.d.ts +9603 -5214
- package/dist/index.node.js +39459 -32980
- package/dist/index.node.js.map +1 -1
- package/dist/node-D9-F9uEP.d.cts +238 -0
- package/dist/node-D9-F9uEP.d.ts +238 -0
- package/dist/node.cjs +896 -0
- package/dist/node.cjs.map +1 -0
- package/dist/node.d.cts +1 -0
- package/dist/node.d.ts +1 -0
- package/dist/node.js +872 -0
- package/dist/node.js.map +1 -0
- package/dist/platform.browser.d.ts +3 -202
- package/dist/platform.browser.js +732 -111
- package/dist/platform.browser.js.map +1 -1
- package/dist/platform.cjs +926 -176
- package/dist/platform.cjs.map +1 -1
- package/dist/platform.d.cts +2 -1
- package/dist/platform.d.ts +2 -1
- package/dist/platform.js +937 -176
- package/dist/platform.js.map +1 -1
- package/dist/platform.node.cjs +926 -176
- package/dist/platform.node.cjs.map +1 -1
- package/dist/platform.node.d.cts +38 -185
- package/dist/platform.node.d.ts +38 -185
- package/dist/platform.node.js +937 -176
- package/dist/platform.node.js.map +1 -1
- package/package.json +45 -24
package/README.md
CHANGED
|
@@ -28,12 +28,19 @@ npm install viem@^2.31.7
|
|
|
28
28
|
|
|
29
29
|
## Quick Start
|
|
30
30
|
|
|
31
|
-
The Vana SDK
|
|
31
|
+
The Vana SDK provides optimized builds for different environments:
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
| Build | Use Case | Crypto Implementation | Configuration |
|
|
34
|
+
| -------------- | --------------------------------- | ---------------------------------- | ----------------- |
|
|
35
|
+
| **`/browser`** | Browser apps (React, Vue) | Pure JavaScript (@noble/secp256k1) | **Zero config** ✓ |
|
|
36
|
+
| **`/node`** | Server-side (Node.js, API routes) | Native bindings (secp256k1) | Zero config ✓ |
|
|
37
|
+
|
|
38
|
+
### Browser Applications
|
|
39
|
+
|
|
40
|
+
The browser build uses pure JavaScript cryptography and requires **no special configuration**:
|
|
34
41
|
|
|
35
42
|
```typescript
|
|
36
|
-
//
|
|
43
|
+
// Browser build - works out of the box with any bundler
|
|
37
44
|
import { Vana, mokshaTestnet } from "@opendatalabs/vana-sdk/browser";
|
|
38
45
|
import { createWalletClient, http } from "viem";
|
|
39
46
|
import { privateKeyToAccount } from "viem/accounts";
|
|
@@ -53,7 +60,9 @@ const vana = Vana({
|
|
|
53
60
|
});
|
|
54
61
|
```
|
|
55
62
|
|
|
56
|
-
### Server-side Applications (
|
|
63
|
+
### Server-side Applications (Node.js)
|
|
64
|
+
|
|
65
|
+
The Node.js build uses native secp256k1 bindings for optimal performance:
|
|
57
66
|
|
|
58
67
|
```typescript
|
|
59
68
|
// For server-side applications (Next.js API routes, Express)
|
|
@@ -116,11 +125,17 @@ const files = await vana.data.getUserFiles({
|
|
|
116
125
|
owner: "0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36",
|
|
117
126
|
});
|
|
118
127
|
|
|
119
|
-
// Upload encrypted file
|
|
120
|
-
const result = await vana.data.
|
|
121
|
-
|
|
122
|
-
schemaId: 123,
|
|
128
|
+
// Upload encrypted file with decryption permissions
|
|
129
|
+
const result = await vana.data.upload({
|
|
130
|
+
content: "Sensitive user data",
|
|
123
131
|
filename: "user-data.json",
|
|
132
|
+
schemaId: 123,
|
|
133
|
+
permissions: [
|
|
134
|
+
{
|
|
135
|
+
account: "0xServerAddress...", // Who can decrypt
|
|
136
|
+
publicKey: "0x04ServerKey...", // Their public key
|
|
137
|
+
},
|
|
138
|
+
],
|
|
124
139
|
});
|
|
125
140
|
```
|
|
126
141
|
|
|
@@ -220,43 +235,42 @@ try {
|
|
|
220
235
|
|
|
221
236
|
## Examples
|
|
222
237
|
|
|
223
|
-
### Complete
|
|
238
|
+
### Complete Data Sharing Flow
|
|
224
239
|
|
|
225
240
|
```typescript
|
|
226
|
-
import {
|
|
227
|
-
Vana,
|
|
228
|
-
generateEncryptionKey,
|
|
229
|
-
encryptBlobWithSignedKey,
|
|
230
|
-
} from "@opendatalabs/vana-sdk/browser";
|
|
241
|
+
import { Vana } from "@opendatalabs/vana-sdk/browser";
|
|
231
242
|
// OR for server-side applications
|
|
232
243
|
// } from "@opendatalabs/vana-sdk/node";
|
|
233
244
|
|
|
234
|
-
async function
|
|
245
|
+
async function shareDataWithServer() {
|
|
235
246
|
const vana = Vana({ walletClient });
|
|
236
247
|
|
|
237
|
-
// 1
|
|
238
|
-
const
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
// 2. Upload encrypted file
|
|
243
|
-
const uploadResult = await vana.data.uploadEncryptedFile({
|
|
244
|
-
data: encryptedData,
|
|
248
|
+
// Step 1: Upload encrypted file with decryption permissions
|
|
249
|
+
const uploadResult = await vana.data.upload({
|
|
250
|
+
content: { data: "sensitive medical records" },
|
|
251
|
+
filename: "health-data.json",
|
|
245
252
|
schemaId: 123,
|
|
246
|
-
|
|
253
|
+
permissions: [
|
|
254
|
+
{
|
|
255
|
+
// Grant decryption access to the AI server
|
|
256
|
+
account: "0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36",
|
|
257
|
+
publicKey: "0x04abc...", // Server's public key for encryption
|
|
258
|
+
},
|
|
259
|
+
],
|
|
247
260
|
});
|
|
248
261
|
|
|
249
|
-
//
|
|
250
|
-
const
|
|
262
|
+
// Step 2: Grant operation permissions for what the server can do
|
|
263
|
+
const permissionResult = await vana.permissions.grant({
|
|
251
264
|
grantee: "0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36",
|
|
252
|
-
|
|
265
|
+
fileIds: [BigInt(uploadResult.fileId)],
|
|
266
|
+
operation: "medical_analysis",
|
|
253
267
|
parameters: {
|
|
254
|
-
|
|
255
|
-
|
|
268
|
+
model: "medical-ai-v2",
|
|
269
|
+
analysisType: "comprehensive",
|
|
256
270
|
},
|
|
257
271
|
});
|
|
258
272
|
|
|
259
|
-
return
|
|
273
|
+
return { uploadResult, permissionResult };
|
|
260
274
|
}
|
|
261
275
|
```
|
|
262
276
|
|
|
@@ -294,13 +308,14 @@ vana.data.validateDataAgainstSchema(userData, schema);
|
|
|
294
308
|
### Permissions
|
|
295
309
|
|
|
296
310
|
```typescript
|
|
297
|
-
// Grant permission
|
|
311
|
+
// Grant operation permission
|
|
298
312
|
await vana.permissions.grant({
|
|
299
313
|
grantee: Address,
|
|
314
|
+
fileIds: bigint[],
|
|
300
315
|
operation: string,
|
|
301
316
|
parameters: object,
|
|
302
317
|
expiresAt?: number
|
|
303
|
-
}): Promise<
|
|
318
|
+
}): Promise<PermissionGrantResult>
|
|
304
319
|
|
|
305
320
|
// Revoke permission
|
|
306
321
|
await vana.permissions.revoke({
|
|
@@ -321,11 +336,16 @@ await vana.data.getUserFiles({
|
|
|
321
336
|
owner: Address
|
|
322
337
|
}): Promise<UserFile[]>
|
|
323
338
|
|
|
324
|
-
// Upload
|
|
325
|
-
await vana.data.
|
|
326
|
-
|
|
339
|
+
// Upload data with automatic encryption
|
|
340
|
+
await vana.data.upload({
|
|
341
|
+
content: string | Blob | Buffer,
|
|
342
|
+
filename?: string,
|
|
327
343
|
schemaId?: number,
|
|
328
|
-
|
|
344
|
+
permissions?: Array<{
|
|
345
|
+
account: Address, // Who can decrypt
|
|
346
|
+
publicKey: string // Their public key
|
|
347
|
+
}>,
|
|
348
|
+
encrypt?: boolean // Default: true
|
|
329
349
|
}): Promise<UploadResult>
|
|
330
350
|
|
|
331
351
|
// Validate schema
|
|
@@ -349,6 +369,48 @@ vana.data.validateDataAgainstSchema(data: unknown, schema: DataSchema): void
|
|
|
349
369
|
- **Issues**: [GitHub Issues](https://github.com/vana-com/vana-sdk/issues)
|
|
350
370
|
- **Discord**: [Join our community](https://discord.gg/vanabuilders)
|
|
351
371
|
|
|
372
|
+
## Generated Code
|
|
373
|
+
|
|
374
|
+
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**.
|
|
375
|
+
|
|
376
|
+
### Code Generation Scripts
|
|
377
|
+
|
|
378
|
+
| Script | Purpose | Generated Files |
|
|
379
|
+
| ---------------------------- | -------------------------------------- | --------------------------- |
|
|
380
|
+
| `npm run fetch-abis` | Smart contract ABIs from blockchain | `src/generated/abi/*.ts` |
|
|
381
|
+
| `npm run fetch-server-types` | Personal server API types from OpenAPI | `src/generated/server/*.ts` |
|
|
382
|
+
| `npm run codegen:subgraph` | GraphQL types from subgraph schema | `src/generated/subgraph.ts` |
|
|
383
|
+
|
|
384
|
+
### Network-Specific Generation
|
|
385
|
+
|
|
386
|
+
Some generation scripts support different networks:
|
|
387
|
+
|
|
388
|
+
```bash
|
|
389
|
+
# Generate subgraph types for different networks
|
|
390
|
+
npm run codegen:subgraph:moksha # Moksha testnet (default)
|
|
391
|
+
npm run codegen:subgraph:mainnet # Vana mainnet
|
|
392
|
+
|
|
393
|
+
# Generate ABIs for different networks
|
|
394
|
+
npm run fetch-abis moksha # Moksha testnet (default)
|
|
395
|
+
npm run fetch-abis mainnet # Vana mainnet
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
### Development Workflow
|
|
399
|
+
|
|
400
|
+
When working with the SDK:
|
|
401
|
+
|
|
402
|
+
1. **Never edit generated files** - They are overwritten on regeneration
|
|
403
|
+
2. **Regenerate after schema changes** - Run generation scripts when external schemas change
|
|
404
|
+
3. **Generated files are committed** - They're included in version control for consistency
|
|
405
|
+
4. **ESLint ignores generated code** - Style rules don't apply to generated files
|
|
406
|
+
|
|
407
|
+
```bash
|
|
408
|
+
# Regenerate all code after schema updates
|
|
409
|
+
npm run fetch-abis
|
|
410
|
+
npm run fetch-server-types
|
|
411
|
+
npm run codegen:subgraph
|
|
412
|
+
```
|
|
413
|
+
|
|
352
414
|
## Development
|
|
353
415
|
|
|
354
416
|
```bash
|
|
@@ -0,0 +1,288 @@
|
|
|
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 using Uint8Array
|
|
220
|
+
*
|
|
221
|
+
* This implementation uses browser-compatible libraries and native APIs
|
|
222
|
+
* without requiring Buffer or other Node.js polyfills.
|
|
223
|
+
*/
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Browser implementation of crypto operations using Uint8Array
|
|
227
|
+
*/
|
|
228
|
+
declare class BrowserCryptoAdapter implements VanaCryptoAdapter {
|
|
229
|
+
private eciesProvider;
|
|
230
|
+
private walletKeyEncryptionService;
|
|
231
|
+
encryptWithPublicKey(data: string, publicKeyHex: string): Promise<string>;
|
|
232
|
+
decryptWithPrivateKey(encryptedData: string, privateKeyHex: string): Promise<string>;
|
|
233
|
+
encryptWithWalletPublicKey(data: string, publicKey: string): Promise<string>;
|
|
234
|
+
decryptWithWalletPrivateKey(encryptedData: string, privateKey: string): Promise<string>;
|
|
235
|
+
generateKeyPair(): Promise<{
|
|
236
|
+
privateKey: string;
|
|
237
|
+
publicKey: string;
|
|
238
|
+
}>;
|
|
239
|
+
encryptWithPassword(data: Uint8Array, password: string): Promise<Uint8Array>;
|
|
240
|
+
decryptWithPassword(encryptedData: Uint8Array, password: string): Promise<Uint8Array>;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Browser implementation of PGP operations
|
|
244
|
+
*/
|
|
245
|
+
declare class BrowserPGPAdapter implements VanaPGPAdapter {
|
|
246
|
+
encrypt(data: string, publicKeyArmored: string): Promise<string>;
|
|
247
|
+
decrypt(encryptedData: string, privateKeyArmored: string): Promise<string>;
|
|
248
|
+
generateKeyPair(options?: {
|
|
249
|
+
name?: string;
|
|
250
|
+
email?: string;
|
|
251
|
+
passphrase?: string;
|
|
252
|
+
}): Promise<{
|
|
253
|
+
publicKey: string;
|
|
254
|
+
privateKey: string;
|
|
255
|
+
}>;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Browser implementation of HTTP operations using Fetch API
|
|
259
|
+
*/
|
|
260
|
+
declare class BrowserHttpAdapter implements VanaHttpAdapter {
|
|
261
|
+
fetch(url: string, options?: RequestInit): Promise<Response>;
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Browser implementation of caching using sessionStorage for security
|
|
265
|
+
* SessionStorage is cleared when the tab closes, making it more secure for signature caching
|
|
266
|
+
*/
|
|
267
|
+
declare class BrowserCacheAdapter implements VanaCacheAdapter {
|
|
268
|
+
private readonly prefix;
|
|
269
|
+
get(key: string): string | null;
|
|
270
|
+
set(key: string, value: string): void;
|
|
271
|
+
delete(key: string): void;
|
|
272
|
+
clear(): void;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Browser implementation of the Vana Platform Adapter
|
|
276
|
+
*
|
|
277
|
+
* This adapter provides all platform-specific functionality for browser environments
|
|
278
|
+
* without requiring any Node.js polyfills.
|
|
279
|
+
*/
|
|
280
|
+
declare class BrowserPlatformAdapter implements VanaPlatformAdapter {
|
|
281
|
+
readonly crypto: BrowserCryptoAdapter;
|
|
282
|
+
readonly pgp: BrowserPGPAdapter;
|
|
283
|
+
readonly http: BrowserHttpAdapter;
|
|
284
|
+
readonly cache: BrowserCacheAdapter;
|
|
285
|
+
readonly platform: "browser";
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
export { BrowserPlatformAdapter as B, type PlatformType as P, type VanaPlatformAdapter as V };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { B as BrowserPlatformAdapter } from './browser-Bb8gLWHp.js';
|