@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,259 +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
- * Browser-only exports for platform adapters
205
- *
206
- * This file provides browser-only exports that completely avoid Node.js imports
207
- * when bundling for browser environments. This is used by the browser entry point.
208
- */
209
-
210
- /**
211
- * Creates a BrowserPlatformAdapter instance
212
- *
213
- * @returns A BrowserPlatformAdapter instance
214
- */
215
- declare function createBrowserPlatformAdapter(): VanaPlatformAdapter;
216
- /**
217
- * Browser-only platform adapter factory
218
- * This version does not include Node.js imports at all
219
- *
220
- * @returns A BrowserPlatformAdapter instance
221
- */
222
- declare function createPlatformAdapterSafe(): VanaPlatformAdapter;
223
-
224
- /**
225
- * Platform detection and adapter utilities
226
- *
227
- * This module provides utilities for detecting the current runtime environment
228
- * and creating appropriate platform adapters automatically.
229
- */
230
-
231
- /**
232
- * Detects the current runtime environment
233
- *
234
- * @returns The detected platform type
235
- */
236
- declare function detectPlatform(): PlatformType;
237
- /**
238
- * Checks if the current environment supports the given platform adapter
239
- *
240
- * @param platformType - The platform type to check
241
- * @returns True if the platform is supported, false otherwise
242
- */
243
- declare function isPlatformSupported(platformType: PlatformType): boolean;
244
- /**
245
- * Gets platform-specific capabilities
246
- *
247
- * @returns Object describing available platform capabilities
248
- */
249
- declare function getPlatformCapabilities(): {
250
- platform: PlatformType;
251
- crypto: {
252
- webCrypto: false | SubtleCrypto;
253
- nodeCrypto: string | false;
254
- };
255
- fetch: boolean;
256
- streams: boolean;
257
- };
258
-
259
- export { BrowserPlatformAdapter, type VanaPlatformAdapter, createBrowserPlatformAdapter, createPlatformAdapterSafe, detectPlatform, getPlatformCapabilities, isPlatformSupported };
@@ -1,318 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropNames = Object.getOwnPropertyNames;
3
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4
- var __esm = (fn, res) => function __init() {
5
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
6
- };
7
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
8
-
9
- // src/platform/shared/crypto-utils.ts
10
- function processWalletPublicKey(publicKey) {
11
- const publicKeyHex = publicKey.startsWith("0x") ? publicKey.slice(2) : publicKey;
12
- const publicKeyBytes = Buffer.from(publicKeyHex, "hex");
13
- return publicKeyBytes.length === 64 ? Buffer.concat([Buffer.from([4]), publicKeyBytes]) : publicKeyBytes;
14
- }
15
- function processWalletPrivateKey(privateKey) {
16
- const privateKeyHex = privateKey.startsWith("0x") ? privateKey.slice(2) : privateKey;
17
- return Buffer.from(privateKeyHex, "hex");
18
- }
19
- function parseEncryptedDataBuffer(encryptedBuffer) {
20
- return {
21
- iv: encryptedBuffer.slice(0, 16),
22
- ephemPublicKey: encryptedBuffer.slice(16, 81),
23
- // 65 bytes for uncompressed public key
24
- ciphertext: encryptedBuffer.slice(81, -32),
25
- mac: encryptedBuffer.slice(-32)
26
- };
27
- }
28
- var init_crypto_utils = __esm({
29
- "src/platform/shared/crypto-utils.ts"() {
30
- "use strict";
31
- }
32
- });
33
-
34
- // src/platform/shared/pgp-utils.ts
35
- function processPGPKeyOptions(options) {
36
- return {
37
- name: options?.name || "Vana User",
38
- email: options?.email || "user@vana.org",
39
- passphrase: options?.passphrase
40
- };
41
- }
42
- function getPGPKeyGenParams(options) {
43
- const { name, email, passphrase } = processPGPKeyOptions(options);
44
- return {
45
- type: "rsa",
46
- rsaBits: 2048,
47
- userIDs: [{ name, email }],
48
- passphrase,
49
- config: STANDARD_PGP_CONFIG
50
- };
51
- }
52
- var STANDARD_PGP_CONFIG;
53
- var init_pgp_utils = __esm({
54
- "src/platform/shared/pgp-utils.ts"() {
55
- "use strict";
56
- STANDARD_PGP_CONFIG = {
57
- preferredCompressionAlgorithm: 2,
58
- // zlib (openpgp.enums.compression.zlib)
59
- preferredSymmetricAlgorithm: 7
60
- // aes256 (openpgp.enums.symmetric.aes256)
61
- };
62
- }
63
- });
64
-
65
- // src/platform/shared/error-utils.ts
66
- function wrapCryptoError(operation, error) {
67
- const message = error instanceof Error ? error.message : "Unknown error";
68
- return new Error(`${operation} failed: ${message}`);
69
- }
70
- var init_error_utils = __esm({
71
- "src/platform/shared/error-utils.ts"() {
72
- "use strict";
73
- }
74
- });
75
-
76
- // src/platform/browser.ts
77
- import * as openpgp from "openpgp";
78
- var BrowserCryptoAdapter, BrowserPGPAdapter, BrowserHttpAdapter, BrowserPlatformAdapter, browserPlatformAdapter;
79
- var init_browser = __esm({
80
- "src/platform/browser.ts"() {
81
- "use strict";
82
- init_crypto_utils();
83
- init_pgp_utils();
84
- init_error_utils();
85
- BrowserCryptoAdapter = class {
86
- async encryptWithPublicKey(data, publicKeyHex) {
87
- try {
88
- const eccrypto = await import("eccrypto-js");
89
- const publicKeyBuffer = Buffer.from(publicKeyHex, "hex");
90
- const encrypted = await eccrypto.encrypt(
91
- publicKeyBuffer,
92
- Buffer.from(data, "utf8")
93
- );
94
- const result = Buffer.concat([
95
- encrypted.iv,
96
- encrypted.ephemPublicKey,
97
- encrypted.ciphertext,
98
- encrypted.mac
99
- ]);
100
- return result.toString("hex");
101
- } catch (error) {
102
- throw new Error(`Encryption failed: ${error}`);
103
- }
104
- }
105
- async decryptWithPrivateKey(encryptedData, privateKeyHex) {
106
- try {
107
- const eccrypto = await import("eccrypto-js");
108
- const privateKeyBuffer = processWalletPrivateKey(privateKeyHex);
109
- const encryptedBuffer = Buffer.from(encryptedData, "hex");
110
- const { iv, ephemPublicKey, ciphertext, mac } = parseEncryptedDataBuffer(encryptedBuffer);
111
- const encryptedObj = { iv, ephemPublicKey, ciphertext, mac };
112
- const decryptedBuffer = await eccrypto.decrypt(
113
- privateKeyBuffer,
114
- encryptedObj
115
- );
116
- return decryptedBuffer.toString("utf8");
117
- } catch (error) {
118
- throw new Error(`Decryption failed: ${error}`);
119
- }
120
- }
121
- async generateKeyPair() {
122
- try {
123
- const eccrypto = await import("eccrypto-js");
124
- const privateKeyBytes = new Uint8Array(32);
125
- crypto.getRandomValues(privateKeyBytes);
126
- const privateKey = Buffer.from(privateKeyBytes);
127
- const publicKey = eccrypto.getPublicCompressed(privateKey);
128
- return {
129
- privateKey: privateKey.toString("hex"),
130
- publicKey: publicKey.toString("hex")
131
- };
132
- } catch (error) {
133
- throw wrapCryptoError("key generation", error);
134
- }
135
- }
136
- async encryptWithWalletPublicKey(data, publicKey) {
137
- try {
138
- const eccrypto = await import("eccrypto-js");
139
- const uncompressedKey = processWalletPublicKey(publicKey);
140
- const encryptedBuffer = await eccrypto.encrypt(
141
- uncompressedKey,
142
- Buffer.from(data)
143
- );
144
- const result = Buffer.concat([
145
- encryptedBuffer.iv,
146
- encryptedBuffer.ephemPublicKey,
147
- encryptedBuffer.ciphertext,
148
- encryptedBuffer.mac
149
- ]);
150
- return result.toString("hex");
151
- } catch (error) {
152
- throw wrapCryptoError("encrypt with wallet public key", error);
153
- }
154
- }
155
- async decryptWithWalletPrivateKey(encryptedData, privateKey) {
156
- try {
157
- const eccrypto = await import("eccrypto-js");
158
- const privateKeyBuffer = processWalletPrivateKey(privateKey);
159
- const encryptedBuffer = Buffer.from(encryptedData, "hex");
160
- const { iv, ephemPublicKey, ciphertext, mac } = parseEncryptedDataBuffer(encryptedBuffer);
161
- const encryptedObj = { iv, ephemPublicKey, ciphertext, mac };
162
- const decryptedBuffer = await eccrypto.decrypt(
163
- privateKeyBuffer,
164
- encryptedObj
165
- );
166
- return decryptedBuffer.toString("utf8");
167
- } catch (error) {
168
- throw wrapCryptoError("decrypt with wallet private key", error);
169
- }
170
- }
171
- async encryptWithPassword(data, password) {
172
- try {
173
- const openpgp2 = await import("openpgp");
174
- const message = await openpgp2.createMessage({
175
- binary: data
176
- });
177
- const encrypted = await openpgp2.encrypt({
178
- message,
179
- passwords: [password],
180
- format: "binary"
181
- });
182
- const response = new Response(encrypted);
183
- const arrayBuffer = await response.arrayBuffer();
184
- return new Uint8Array(arrayBuffer);
185
- } catch (error) {
186
- throw new Error(`Failed to encrypt with password: ${error}`);
187
- }
188
- }
189
- async decryptWithPassword(encryptedData, password) {
190
- try {
191
- const openpgp2 = await import("openpgp");
192
- const message = await openpgp2.readMessage({
193
- binaryMessage: encryptedData
194
- });
195
- const { data: decrypted } = await openpgp2.decrypt({
196
- message,
197
- passwords: [password],
198
- format: "binary"
199
- });
200
- return new Uint8Array(decrypted);
201
- } catch (error) {
202
- throw new Error(`Failed to decrypt with password: ${error}`);
203
- }
204
- }
205
- };
206
- BrowserPGPAdapter = class {
207
- async encrypt(data, publicKeyArmored) {
208
- try {
209
- const publicKey = await openpgp.readKey({ armoredKey: publicKeyArmored });
210
- const encrypted = await openpgp.encrypt({
211
- message: await openpgp.createMessage({ text: data }),
212
- encryptionKeys: publicKey,
213
- config: {
214
- preferredCompressionAlgorithm: openpgp.enums.compression.zlib
215
- }
216
- });
217
- return encrypted;
218
- } catch (error) {
219
- throw new Error(`PGP encryption failed: ${error}`);
220
- }
221
- }
222
- async decrypt(encryptedData, privateKeyArmored) {
223
- try {
224
- const privateKey = await openpgp.readPrivateKey({
225
- armoredKey: privateKeyArmored
226
- });
227
- const message = await openpgp.readMessage({
228
- armoredMessage: encryptedData
229
- });
230
- const { data: decrypted } = await openpgp.decrypt({
231
- message,
232
- decryptionKeys: privateKey
233
- });
234
- return decrypted;
235
- } catch (error) {
236
- throw new Error(`PGP decryption failed: ${error}`);
237
- }
238
- }
239
- async generateKeyPair(options) {
240
- try {
241
- const keyGenParams = getPGPKeyGenParams(options);
242
- const { privateKey, publicKey } = await openpgp.generateKey(keyGenParams);
243
- return { publicKey, privateKey };
244
- } catch (error) {
245
- throw wrapCryptoError("PGP key generation", error);
246
- }
247
- }
248
- };
249
- BrowserHttpAdapter = class {
250
- async fetch(url, options) {
251
- if (typeof fetch === "undefined") {
252
- throw new Error("Fetch API not available in this browser environment");
253
- }
254
- return fetch(url, options);
255
- }
256
- };
257
- BrowserPlatformAdapter = class {
258
- constructor() {
259
- __publicField(this, "crypto");
260
- __publicField(this, "pgp");
261
- __publicField(this, "http");
262
- __publicField(this, "platform", "browser");
263
- this.crypto = new BrowserCryptoAdapter();
264
- this.pgp = new BrowserPGPAdapter();
265
- this.http = new BrowserHttpAdapter();
266
- }
267
- };
268
- browserPlatformAdapter = new BrowserPlatformAdapter();
269
- }
270
- });
271
-
272
- // src/platform.browser.ts
273
- init_browser();
274
-
275
- // src/platform/browser-only.ts
276
- init_browser();
277
- function createBrowserPlatformAdapter() {
278
- return new BrowserPlatformAdapter();
279
- }
280
- function createPlatformAdapterSafe() {
281
- return createBrowserPlatformAdapter();
282
- }
283
-
284
- // src/platform/utils.ts
285
- function detectPlatform() {
286
- if (typeof process !== "undefined" && process.versions && process.versions.node) {
287
- return "node";
288
- }
289
- if (typeof window !== "undefined" && typeof document !== "undefined") {
290
- return "browser";
291
- }
292
- return "node";
293
- }
294
- function isPlatformSupported(platformType) {
295
- const currentPlatform = detectPlatform();
296
- return currentPlatform === platformType;
297
- }
298
- function getPlatformCapabilities() {
299
- const platform = detectPlatform();
300
- return {
301
- platform,
302
- crypto: {
303
- webCrypto: typeof crypto !== "undefined" && crypto.subtle,
304
- nodeCrypto: typeof process !== "undefined" && process.versions && process.versions.node
305
- },
306
- fetch: typeof fetch !== "undefined" || typeof globalThis.fetch !== "undefined",
307
- streams: typeof ReadableStream !== "undefined"
308
- };
309
- }
310
- export {
311
- BrowserPlatformAdapter,
312
- createBrowserPlatformAdapter,
313
- createPlatformAdapterSafe,
314
- detectPlatform,
315
- getPlatformCapabilities,
316
- isPlatformSupported
317
- };
318
- //# sourceMappingURL=platform.browser.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/platform/shared/crypto-utils.ts","../src/platform/shared/pgp-utils.ts","../src/platform/shared/error-utils.ts","../src/platform/browser.ts","../src/platform.browser.ts","../src/platform/browser-only.ts","../src/platform/utils.ts"],"sourcesContent":["/**\n * Shared crypto utilities for platform adapters\n *\n * IMPORTANT: This module contains NO IMPORTS to avoid affecting bundle loading.\n * All functions are pure utilities that can be safely shared across platforms.\n */\n\n/**\n * Process wallet public key for encryption operations\n * Removes 0x prefix and ensures uncompressed format (65 bytes with 0x04 prefix)\n *\n * @param publicKey The public key (with or without 0x prefix)\n * @returns Buffer containing uncompressed public key\n */\nexport function processWalletPublicKey(publicKey: string): Buffer {\n const publicKeyHex = publicKey.startsWith(\"0x\")\n ? publicKey.slice(2)\n : publicKey;\n const publicKeyBytes = Buffer.from(publicKeyHex, \"hex\");\n\n // Ensure public key is in uncompressed format (65 bytes with 0x04 prefix)\n // If it's 64 bytes, add the 0x04 prefix; if already 65 bytes, use as-is\n return publicKeyBytes.length === 64\n ? Buffer.concat([Buffer.from([4]), publicKeyBytes])\n : publicKeyBytes;\n}\n\n/**\n * Process wallet private key for decryption operations\n * Removes 0x prefix and converts to Buffer\n *\n * @param privateKey The private key (with or without 0x prefix)\n * @returns Buffer containing private key\n */\nexport function processWalletPrivateKey(privateKey: string): Buffer {\n const privateKeyHex = privateKey.startsWith(\"0x\")\n ? privateKey.slice(2)\n : privateKey;\n return Buffer.from(privateKeyHex, \"hex\");\n}\n\n/**\n * Parse encrypted data buffer into components\n * Extracts IV, ephemeral public key, ciphertext, and MAC from a concatenated buffer\n *\n * @param encryptedBuffer The buffer containing encrypted data\n * @returns Object with parsed components\n */\nexport function parseEncryptedDataBuffer(encryptedBuffer: Buffer) {\n return {\n iv: encryptedBuffer.slice(0, 16),\n ephemPublicKey: encryptedBuffer.slice(16, 81), // 65 bytes for uncompressed public key\n ciphertext: encryptedBuffer.slice(81, -32),\n mac: encryptedBuffer.slice(-32),\n };\n}\n\n/**\n * Convert hex string to Uint8Array\n *\n * @param hex The hex string to convert\n * @returns Uint8Array representation\n */\nexport function hexToUint8Array(hex: string): Uint8Array {\n const result = new Uint8Array(hex.length / 2);\n for (let i = 0; i < hex.length; i += 2) {\n result[i / 2] = parseInt(hex.substr(i, 2), 16);\n }\n return result;\n}\n\n/**\n * Convert Uint8Array to hex string\n *\n * @param array The Uint8Array to convert\n * @returns Hex string representation\n */\nexport function uint8ArrayToHex(array: Uint8Array): string {\n return Array.from(array, (byte) => byte.toString(16).padStart(2, \"0\")).join(\n \"\",\n );\n}\n","/**\n * Shared PGP utilities for platform adapters\n *\n * IMPORTANT: This module contains NO IMPORTS to avoid affecting bundle loading.\n * All functions are pure utilities that can be safely shared across platforms.\n */\n\n/**\n * Standard OpenPGP configuration for consistent behavior across platforms\n * Uses enum values instead of importing openpgp to avoid loading issues\n */\nexport const STANDARD_PGP_CONFIG = {\n preferredCompressionAlgorithm: 2, // zlib (openpgp.enums.compression.zlib)\n preferredSymmetricAlgorithm: 7, // aes256 (openpgp.enums.symmetric.aes256)\n} as const;\n\n/**\n * Process PGP key generation options with sensible defaults\n *\n * @param options - Optional key generation parameters\n * @param options.name - The name for the PGP key (defaults to \"Vana User\")\n * @param options.email - The email for the PGP key (defaults to \"user@vana.org\")\n * @param options.passphrase - Optional passphrase to protect the private key\n * @returns Processed options with defaults applied\n */\nexport function processPGPKeyOptions(options?: {\n name?: string;\n email?: string;\n passphrase?: string;\n}) {\n return {\n name: options?.name || \"Vana User\",\n email: options?.email || \"user@vana.org\",\n passphrase: options?.passphrase,\n };\n}\n\n/**\n * Get standard PGP key generation parameters\n * Combines default values with standard configuration\n *\n * @param options - Optional key generation parameters\n * @param options.name - The name for the PGP key (defaults to \"Vana User\")\n * @param options.email - The email for the PGP key (defaults to \"user@vana.org\")\n * @param options.passphrase - Optional passphrase to protect the private key\n * @returns Complete key generation parameters object\n */\nexport function getPGPKeyGenParams(options?: {\n name?: string;\n email?: string;\n passphrase?: string;\n}) {\n const { name, email, passphrase } = processPGPKeyOptions(options);\n\n return {\n type: \"rsa\" as const,\n rsaBits: 2048,\n userIDs: [{ name, email }],\n passphrase,\n config: STANDARD_PGP_CONFIG,\n };\n}\n","/**\n * Shared error utilities for platform adapters\n *\n * IMPORTANT: This module contains NO IMPORTS to avoid affecting bundle loading.\n * All functions are pure utilities that can be safely shared across platforms.\n */\n\n/**\n * Wrap platform-specific errors with consistent messaging\n * Provides consistent error formatting across all crypto operations\n *\n * @param operation The operation that failed (e.g., \"encryption\", \"decryption\")\n * @param error The original error that occurred\n * @returns Wrapped error with consistent format\n */\nexport function wrapCryptoError(operation: string, error: unknown): Error {\n const message = error instanceof Error ? error.message : \"Unknown error\";\n return new Error(`${operation} failed: ${message}`);\n}\n\n/**\n * Validate encrypted data structure has required fields\n * Ensures encrypted data objects contain the expected properties\n *\n * @param data The data structure to validate\n * @throws Error if data structure is invalid\n */\nexport function validateEncryptedDataStructure(data: unknown): void {\n if (!data || typeof data !== \"object\") {\n throw new Error(\"Invalid encrypted data format\");\n }\n\n const obj = data as Record<string, unknown>;\n if (!obj.encrypted || !obj.iv || !obj.ephemeralPublicKey) {\n throw new Error(\"Invalid encrypted data format\");\n }\n}\n","/**\n * Browser implementation of the Vana Platform Adapter\n *\n * This implementation uses browser-compatible libraries and configurations\n * to provide crypto, PGP, and HTTP functionality without Node.js dependencies.\n */\n\nimport * as openpgp from \"openpgp\";\nimport {\n VanaPlatformAdapter,\n VanaCryptoAdapter,\n VanaPGPAdapter,\n VanaHttpAdapter,\n} from \"./interface\";\nimport {\n processWalletPublicKey,\n processWalletPrivateKey,\n parseEncryptedDataBuffer,\n} from \"./shared/crypto-utils\";\nimport { getPGPKeyGenParams } from \"./shared/pgp-utils\";\nimport { wrapCryptoError } from \"./shared/error-utils\";\n\n/**\n * Browser implementation of crypto operations using eccrypto-js\n */\nclass BrowserCryptoAdapter implements VanaCryptoAdapter {\n async encryptWithPublicKey(\n data: string,\n publicKeyHex: string,\n ): Promise<string> {\n try {\n // Import eccrypto-js for secp256k1 encryption\n const eccrypto = await import(\"eccrypto-js\");\n\n // Convert hex public key to Buffer\n const publicKeyBuffer = Buffer.from(publicKeyHex, \"hex\");\n\n // Encrypt data using secp256k1 ECDH\n const encrypted = await eccrypto.encrypt(\n publicKeyBuffer,\n Buffer.from(data, \"utf8\"),\n );\n\n // Concatenate all components and return as hex string for API consistency\n const result = Buffer.concat([\n encrypted.iv,\n encrypted.ephemPublicKey,\n encrypted.ciphertext,\n encrypted.mac,\n ]);\n\n return result.toString(\"hex\");\n } catch (error) {\n throw new Error(`Encryption failed: ${error}`);\n }\n }\n\n async decryptWithPrivateKey(\n encryptedData: string,\n privateKeyHex: string,\n ): Promise<string> {\n try {\n // Import eccrypto-js for secp256k1 decryption\n const eccrypto = await import(\"eccrypto-js\");\n\n // Use shared utilities to process keys and parse data\n const privateKeyBuffer = processWalletPrivateKey(privateKeyHex);\n const encryptedBuffer = Buffer.from(encryptedData, \"hex\");\n const { iv, ephemPublicKey, ciphertext, mac } =\n parseEncryptedDataBuffer(encryptedBuffer);\n\n // Reconstruct the encrypted data structure for eccrypto\n const encryptedObj = { iv, ephemPublicKey, ciphertext, mac };\n\n // Decrypt using secp256k1 ECDH\n const decryptedBuffer = await eccrypto.decrypt(\n privateKeyBuffer,\n encryptedObj,\n );\n\n return decryptedBuffer.toString(\"utf8\");\n } catch (error) {\n throw new Error(`Decryption failed: ${error}`);\n }\n }\n\n async generateKeyPair(): Promise<{ publicKey: string; privateKey: string }> {\n try {\n // Import eccrypto-js for secp256k1 key generation (browser-compatible)\n const eccrypto = await import(\"eccrypto-js\");\n\n // Generate a random 32-byte private key for secp256k1\n const privateKeyBytes = new Uint8Array(32);\n crypto.getRandomValues(privateKeyBytes);\n const privateKey = Buffer.from(privateKeyBytes);\n\n // Generate the corresponding compressed public key\n const publicKey = eccrypto.getPublicCompressed(privateKey);\n\n return {\n privateKey: privateKey.toString(\"hex\"),\n publicKey: publicKey.toString(\"hex\"),\n };\n } catch (error) {\n throw wrapCryptoError(\"key generation\", error);\n }\n }\n\n async encryptWithWalletPublicKey(\n data: string,\n publicKey: string,\n ): Promise<string> {\n try {\n // Import eccrypto for ECDH encryption\n const eccrypto = await import(\"eccrypto-js\");\n\n // Use shared utility to process public key\n const uncompressedKey = processWalletPublicKey(publicKey);\n\n // Encrypt using ECDH with randomly generated parameters\n const encryptedBuffer = await eccrypto.encrypt(\n uncompressedKey,\n Buffer.from(data),\n );\n\n // Concatenate all components and return as hex\n const result = Buffer.concat([\n encryptedBuffer.iv,\n encryptedBuffer.ephemPublicKey,\n encryptedBuffer.ciphertext,\n encryptedBuffer.mac,\n ]);\n\n return result.toString(\"hex\");\n } catch (error) {\n throw wrapCryptoError(\"encrypt with wallet public key\", error);\n }\n }\n\n async decryptWithWalletPrivateKey(\n encryptedData: string,\n privateKey: string,\n ): Promise<string> {\n try {\n // Import eccrypto for ECDH decryption\n const eccrypto = await import(\"eccrypto-js\");\n\n // Use shared utilities to process keys and parse data\n const privateKeyBuffer = processWalletPrivateKey(privateKey);\n const encryptedBuffer = Buffer.from(encryptedData, \"hex\");\n const { iv, ephemPublicKey, ciphertext, mac } =\n parseEncryptedDataBuffer(encryptedBuffer);\n\n // Reconstruct the encrypted data structure for eccrypto\n const encryptedObj = { iv, ephemPublicKey, ciphertext, mac };\n\n // Decrypt using ECDH\n const decryptedBuffer = await eccrypto.decrypt(\n privateKeyBuffer,\n encryptedObj,\n );\n\n return decryptedBuffer.toString(\"utf8\");\n } catch (error) {\n throw wrapCryptoError(\"decrypt with wallet private key\", error);\n }\n }\n\n async encryptWithPassword(\n data: Uint8Array,\n password: string,\n ): Promise<Uint8Array> {\n try {\n // Import openpgp for password-based encryption\n const openpgp = await import(\"openpgp\");\n\n const message = await openpgp.createMessage({\n binary: data,\n });\n\n // Use password-based encryption with wallet signature as password\n // Note: For deterministic encryption, we would need to control the salt\n // This implementation is secure but not deterministic due to OpenPGP's design\n const encrypted = await openpgp.encrypt({\n message,\n passwords: [password],\n format: \"binary\",\n });\n\n // Convert WebStream<Uint8Array> to Uint8Array\n const response = new Response(encrypted as ReadableStream<Uint8Array>);\n const arrayBuffer = await response.arrayBuffer();\n return new Uint8Array(arrayBuffer);\n } catch (error) {\n throw new Error(`Failed to encrypt with password: ${error}`);\n }\n }\n\n async decryptWithPassword(\n encryptedData: Uint8Array,\n password: string,\n ): Promise<Uint8Array> {\n try {\n // Import openpgp for password-based decryption\n const openpgp = await import(\"openpgp\");\n\n const message = await openpgp.readMessage({\n binaryMessage: encryptedData,\n });\n\n // Use password-based decryption with wallet signature as password\n const { data: decrypted } = await openpgp.decrypt({\n message,\n passwords: [password],\n format: \"binary\",\n });\n\n // Convert decrypted data back to Uint8Array\n return new Uint8Array(decrypted as ArrayBuffer);\n } catch (error) {\n throw new Error(`Failed to decrypt with password: ${error}`);\n }\n }\n}\n\n/**\n * Browser implementation of PGP operations using openpgp with browser-specific configuration\n */\nclass BrowserPGPAdapter implements VanaPGPAdapter {\n async encrypt(data: string, publicKeyArmored: string): Promise<string> {\n try {\n const publicKey = await openpgp.readKey({ armoredKey: publicKeyArmored });\n\n const encrypted = await openpgp.encrypt({\n message: await openpgp.createMessage({ text: data }),\n encryptionKeys: publicKey,\n config: {\n preferredCompressionAlgorithm: openpgp.enums.compression.zlib,\n },\n });\n\n return encrypted as string;\n } catch (error) {\n throw new Error(`PGP encryption failed: ${error}`);\n }\n }\n\n async decrypt(\n encryptedData: string,\n privateKeyArmored: string,\n ): Promise<string> {\n try {\n const privateKey = await openpgp.readPrivateKey({\n armoredKey: privateKeyArmored,\n });\n const message = await openpgp.readMessage({\n armoredMessage: encryptedData,\n });\n\n const { data: decrypted } = await openpgp.decrypt({\n message,\n decryptionKeys: privateKey,\n });\n\n return decrypted as string;\n } catch (error) {\n throw new Error(`PGP decryption failed: ${error}`);\n }\n }\n\n async generateKeyPair(options?: {\n name?: string;\n email?: string;\n passphrase?: string;\n }): Promise<{ publicKey: string; privateKey: string }> {\n try {\n // Use shared utility to get standardized parameters\n const keyGenParams = getPGPKeyGenParams(options);\n\n const { privateKey, publicKey } = await openpgp.generateKey(keyGenParams);\n\n return { publicKey, privateKey };\n } catch (error) {\n throw wrapCryptoError(\"PGP key generation\", error);\n }\n }\n}\n\n/**\n * Browser implementation of HTTP operations using fetch API\n */\nclass BrowserHttpAdapter implements VanaHttpAdapter {\n async fetch(url: string, options?: RequestInit): Promise<Response> {\n if (typeof fetch === \"undefined\") {\n throw new Error(\"Fetch API not available in this browser environment\");\n }\n\n return fetch(url, options);\n }\n}\n\n/**\n * Complete browser platform adapter implementation\n */\nexport class BrowserPlatformAdapter implements VanaPlatformAdapter {\n crypto: VanaCryptoAdapter;\n pgp: VanaPGPAdapter;\n http: VanaHttpAdapter;\n platform: \"browser\" = \"browser\" as const;\n\n constructor() {\n this.crypto = new BrowserCryptoAdapter();\n this.pgp = new BrowserPGPAdapter();\n this.http = new BrowserHttpAdapter();\n }\n}\n\n/**\n * Default instance export for backwards compatibility\n */\nexport const browserPlatformAdapter: VanaPlatformAdapter =\n new BrowserPlatformAdapter();\n","/**\n * Browser-specific platform adapters entry point\n *\n * This module provides browser-safe platform utilities without Node.js dependencies.\n */\n\n// Export browser platform adapter\nexport { BrowserPlatformAdapter } from \"./platform/browser\";\n\n// Export platform interface\nexport type { VanaPlatformAdapter } from \"./platform/interface\";\n\n// Export browser-safe utilities only\nexport {\n createBrowserPlatformAdapter,\n createPlatformAdapterSafe,\n} from \"./platform/browser-only\";\n\n// Export safe platform utilities (no Node.js imports)\nexport {\n detectPlatform,\n isPlatformSupported,\n getPlatformCapabilities,\n} from \"./platform/utils\";\n","/**\n * Browser-only exports for platform adapters\n *\n * This file provides browser-only exports that completely avoid Node.js imports\n * when bundling for browser environments. This is used by the browser entry point.\n */\n\nimport type { VanaPlatformAdapter } from \"./interface\";\nimport { BrowserPlatformAdapter } from \"./browser\";\n\n/**\n * Creates a BrowserPlatformAdapter instance\n *\n * @returns A BrowserPlatformAdapter instance\n */\nexport function createBrowserPlatformAdapter(): VanaPlatformAdapter {\n return new BrowserPlatformAdapter();\n}\n\n/**\n * Browser-only platform adapter factory\n * This version does not include Node.js imports at all\n *\n * @returns A BrowserPlatformAdapter instance\n */\nexport function createPlatformAdapterSafe(): VanaPlatformAdapter {\n // Always return browser adapter in browser environments\n return createBrowserPlatformAdapter();\n}\n\n// Export types\nexport type { VanaPlatformAdapter } from \"./interface\";\nexport type { BrowserPlatformAdapter } from \"./browser\";\n","/**\n * Platform detection and adapter utilities\n *\n * This module provides utilities for detecting the current runtime environment\n * and creating appropriate platform adapters automatically.\n */\n\nimport type { VanaPlatformAdapter, PlatformType } from \"./interface\";\n\n/**\n * Detects the current runtime environment\n *\n * @returns The detected platform type\n */\nexport function detectPlatform(): PlatformType {\n // Check for Node.js environment\n if (\n typeof process !== \"undefined\" &&\n process.versions &&\n process.versions.node\n ) {\n return \"node\";\n }\n\n // Check for browser environment\n if (typeof window !== \"undefined\" && typeof document !== \"undefined\") {\n return \"browser\";\n }\n\n // Default to Node.js if we can't determine (e.g., SSR environments)\n return \"node\";\n}\n\n/**\n * Creates the appropriate platform adapter based on the current environment\n *\n * @returns A platform adapter instance for the current environment\n * @throws {Error} If platform adapters cannot be imported or created\n */\nexport async function createPlatformAdapter(): Promise<VanaPlatformAdapter> {\n const platform = detectPlatform();\n\n try {\n if (platform === \"node\") {\n // Check if we're in a browser environment\n if (typeof window !== \"undefined\") {\n throw new Error(\n \"NodePlatformAdapter is not available in browser environments. Use BrowserPlatformAdapter instead.\",\n );\n }\n\n // Use string concatenation to avoid static analysis\n const moduleName = \"./node\";\n const { NodePlatformAdapter } = await import(moduleName);\n return new NodePlatformAdapter();\n } else {\n const { BrowserPlatformAdapter } = await import(\"./browser\");\n return new BrowserPlatformAdapter();\n }\n } catch (error) {\n throw new Error(\n `Failed to create platform adapter for ${platform}: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n}\n\n/**\n * Creates a platform adapter for a specific platform type\n *\n * @param platformType - The platform type to create an adapter for\n * @returns A platform adapter instance for the specified platform\n * @throws {Error} If platform adapters cannot be imported or created\n */\nexport async function createPlatformAdapterFor(\n platformType: PlatformType,\n): Promise<VanaPlatformAdapter> {\n try {\n if (platformType === \"node\") {\n // Check if we're in a browser environment\n if (typeof window !== \"undefined\") {\n throw new Error(\n \"NodePlatformAdapter is not available in browser environments. Use BrowserPlatformAdapter instead.\",\n );\n }\n\n // Use string concatenation to avoid static analysis\n const moduleName = \"./node\";\n const { NodePlatformAdapter } = await import(moduleName);\n return new NodePlatformAdapter();\n } else {\n const { BrowserPlatformAdapter } = await import(\"./browser\");\n return new BrowserPlatformAdapter();\n }\n } catch (error) {\n throw new Error(\n `Failed to create platform adapter for ${platformType}: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n}\n\n/**\n * Checks if the current environment supports the given platform adapter\n *\n * @param platformType - The platform type to check\n * @returns True if the platform is supported, false otherwise\n */\nexport function isPlatformSupported(platformType: PlatformType): boolean {\n const currentPlatform = detectPlatform();\n return currentPlatform === platformType;\n}\n\n/**\n * Gets platform-specific capabilities\n *\n * @returns Object describing available platform capabilities\n */\nexport function getPlatformCapabilities() {\n const platform = detectPlatform();\n\n return {\n platform,\n crypto: {\n webCrypto: typeof crypto !== \"undefined\" && crypto.subtle,\n nodeCrypto:\n typeof process !== \"undefined\" &&\n process.versions &&\n process.versions.node,\n },\n fetch:\n typeof fetch !== \"undefined\" || typeof globalThis.fetch !== \"undefined\",\n streams: typeof ReadableStream !== \"undefined\",\n };\n}\n"],"mappings":";;;;;;;;;AAcO,SAAS,uBAAuB,WAA2B;AAChE,QAAM,eAAe,UAAU,WAAW,IAAI,IAC1C,UAAU,MAAM,CAAC,IACjB;AACJ,QAAM,iBAAiB,OAAO,KAAK,cAAc,KAAK;AAItD,SAAO,eAAe,WAAW,KAC7B,OAAO,OAAO,CAAC,OAAO,KAAK,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,IAChD;AACN;AASO,SAAS,wBAAwB,YAA4B;AAClE,QAAM,gBAAgB,WAAW,WAAW,IAAI,IAC5C,WAAW,MAAM,CAAC,IAClB;AACJ,SAAO,OAAO,KAAK,eAAe,KAAK;AACzC;AASO,S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