@opendatalabs/vana-sdk 0.1.0-alpha.d6bebb0 → 0.1.0-alpha.db07fe1

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 (45) hide show
  1. package/README.md +98 -36
  2. package/package.json +45 -24
  3. package/dist/chains.browser.cjs +0 -96
  4. package/dist/chains.browser.cjs.map +0 -1
  5. package/dist/chains.browser.d.cts +0 -53
  6. package/dist/chains.browser.d.ts +0 -53
  7. package/dist/chains.browser.js +0 -65
  8. package/dist/chains.browser.js.map +0 -1
  9. package/dist/chains.cjs +0 -96
  10. package/dist/chains.cjs.map +0 -1
  11. package/dist/chains.d.cts +0 -2
  12. package/dist/chains.d.ts +0 -2
  13. package/dist/chains.js +0 -65
  14. package/dist/chains.js.map +0 -1
  15. package/dist/chains.node.cjs +0 -96
  16. package/dist/chains.node.cjs.map +0 -1
  17. package/dist/chains.node.d.cts +0 -2
  18. package/dist/chains.node.d.ts +0 -2
  19. package/dist/chains.node.js +0 -65
  20. package/dist/chains.node.js.map +0 -1
  21. package/dist/index.browser.d.ts +0 -33182
  22. package/dist/index.browser.js +0 -41154
  23. package/dist/index.browser.js.map +0 -1
  24. package/dist/index.d.cts +0 -2
  25. package/dist/index.node.cjs +0 -41634
  26. package/dist/index.node.cjs.map +0 -1
  27. package/dist/index.node.d.cts +0 -33315
  28. package/dist/index.node.d.ts +0 -33315
  29. package/dist/index.node.js +0 -41496
  30. package/dist/index.node.js.map +0 -1
  31. package/dist/platform.browser.d.ts +0 -259
  32. package/dist/platform.browser.js +0 -318
  33. package/dist/platform.browser.js.map +0 -1
  34. package/dist/platform.cjs +0 -659
  35. package/dist/platform.cjs.map +0 -1
  36. package/dist/platform.d.cts +0 -1
  37. package/dist/platform.d.ts +0 -1
  38. package/dist/platform.js +0 -622
  39. package/dist/platform.js.map +0 -1
  40. package/dist/platform.node.cjs +0 -659
  41. package/dist/platform.node.cjs.map +0 -1
  42. package/dist/platform.node.d.cts +0 -299
  43. package/dist/platform.node.d.ts +0 -299
  44. package/dist/platform.node.js +0 -622
  45. package/dist/platform.node.js.map +0 -1
@@ -1,299 +0,0 @@
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
- * Main platform adapter interface that combines all platform-specific functionality
149
- *
150
- * **Implementation Guidelines:**
151
- * 1. All methods must maintain consistent behavior across platforms
152
- * 2. Error types and messages should be unified
153
- * 3. Data formats (encoding, serialization) must be identical
154
- * 4. Performance characteristics can vary but API must be consistent
155
- *
156
- * **Custom Implementation Example:**
157
- * ```typescript
158
- * class CustomPlatformAdapter implements VanaPlatformAdapter {
159
- * crypto = new CustomCryptoAdapter();
160
- * pgp = new CustomPGPAdapter();
161
- * http = new CustomHttpAdapter();
162
- * platform = 'browser' as const;
163
- * }
164
- * ```
165
- */
166
- interface VanaPlatformAdapter {
167
- /**
168
- * Crypto operations adapter
169
- */
170
- crypto: VanaCryptoAdapter;
171
- /**
172
- * PGP operations adapter
173
- */
174
- pgp: VanaPGPAdapter;
175
- /**
176
- * HTTP operations adapter
177
- */
178
- http: VanaHttpAdapter;
179
- /**
180
- * Platform identifier for debugging/telemetry
181
- */
182
- readonly platform: PlatformType;
183
- }
184
-
185
- /**
186
- * Browser implementation of the Vana Platform Adapter
187
- *
188
- * This implementation uses browser-compatible libraries and configurations
189
- * to provide crypto, PGP, and HTTP functionality without Node.js dependencies.
190
- */
191
-
192
- /**
193
- * Complete browser platform adapter implementation
194
- */
195
- declare class BrowserPlatformAdapter implements VanaPlatformAdapter {
196
- crypto: VanaCryptoAdapter;
197
- pgp: VanaPGPAdapter;
198
- http: VanaHttpAdapter;
199
- platform: "browser";
200
- constructor();
201
- }
202
-
203
- /**
204
- * Node.js implementation of the Vana Platform Adapter
205
- *
206
- * This implementation uses Node.js-specific libraries and configurations
207
- * to provide crypto, PGP, and HTTP functionality.
208
- */
209
-
210
- /**
211
- * Complete Node.js platform adapter implementation
212
- */
213
- declare class NodePlatformAdapter implements VanaPlatformAdapter {
214
- crypto: VanaCryptoAdapter;
215
- pgp: VanaPGPAdapter;
216
- http: VanaHttpAdapter;
217
- platform: "node";
218
- constructor();
219
- }
220
-
221
- /**
222
- * Platform detection and adapter utilities
223
- *
224
- * This module provides utilities for detecting the current runtime environment
225
- * and creating appropriate platform adapters automatically.
226
- */
227
-
228
- /**
229
- * Detects the current runtime environment
230
- *
231
- * @returns The detected platform type
232
- */
233
- declare function detectPlatform(): PlatformType;
234
- /**
235
- * Creates the appropriate platform adapter based on the current environment
236
- *
237
- * @returns A platform adapter instance for the current environment
238
- * @throws {Error} If platform adapters cannot be imported or created
239
- */
240
- declare function createPlatformAdapter(): Promise<VanaPlatformAdapter>;
241
- /**
242
- * Creates a platform adapter for a specific platform type
243
- *
244
- * @param platformType - The platform type to create an adapter for
245
- * @returns A platform adapter instance for the specified platform
246
- * @throws {Error} If platform adapters cannot be imported or created
247
- */
248
- declare function createPlatformAdapterFor(platformType: PlatformType): Promise<VanaPlatformAdapter>;
249
- /**
250
- * Checks if the current environment supports the given platform adapter
251
- *
252
- * @param platformType - The platform type to check
253
- * @returns True if the platform is supported, false otherwise
254
- */
255
- declare function isPlatformSupported(platformType: PlatformType): boolean;
256
- /**
257
- * Gets platform-specific capabilities
258
- *
259
- * @returns Object describing available platform capabilities
260
- */
261
- declare function getPlatformCapabilities(): {
262
- platform: PlatformType;
263
- crypto: {
264
- webCrypto: false | SubtleCrypto;
265
- nodeCrypto: string | false;
266
- };
267
- fetch: boolean;
268
- streams: boolean;
269
- };
270
-
271
- /**
272
- * Browser-safe exports for platform adapters
273
- *
274
- * This file provides browser-safe exports that avoid importing Node.js dependencies
275
- * when bundling for browser environments.
276
- */
277
-
278
- /**
279
- * Dynamically imports the NodePlatformAdapter only when needed
280
- * This prevents Node.js modules from being bundled in browser builds
281
- *
282
- * @returns Promise resolving to a NodePlatformAdapter instance
283
- * @throws {Error} If running in a browser environment
284
- */
285
- declare function createNodePlatformAdapter(): Promise<VanaPlatformAdapter>;
286
- /**
287
- * Creates a BrowserPlatformAdapter instance
288
- *
289
- * @returns A BrowserPlatformAdapter instance
290
- */
291
- declare function createBrowserPlatformAdapter(): VanaPlatformAdapter;
292
- /**
293
- * Browser-safe platform adapter factory
294
- *
295
- * @returns Promise resolving to the appropriate platform adapter
296
- */
297
- declare function createPlatformAdapterSafe(): Promise<VanaPlatformAdapter>;
298
-
299
- export { BrowserPlatformAdapter, NodePlatformAdapter, type VanaPlatformAdapter, createBrowserPlatformAdapter, createNodePlatformAdapter, createPlatformAdapter, createPlatformAdapterFor, createPlatformAdapterSafe, detectPlatform, getPlatformCapabilities, isPlatformSupported };